Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2002:
[Freeciv-Dev] switching tilesets at runtime
Home

[Freeciv-Dev] switching tilesets at runtime

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev <freeciv-dev@xxxxxxxxxxx>
Subject: [Freeciv-Dev] switching tilesets at runtime
From: Jason Short <vze2zq63@xxxxxxxxxxx>
Date: Sun, 13 Jan 2002 04:23:28 -0500
Reply-to: jdorje@xxxxxxxxxxxx

Here's a preliminary (buggy and incomplete) patch to allow switching tilesets at runtime.

It implements a new function, tilespec_reread, in tilespec.[ch]. When invoked this function should destroy the old tileset data and load the given new tileset.

This is explained in more detail in the patch, but the details are pretty tricky. Loading a tileset consists of three parts:

1.  The top level tileset data is read from the specfile.
2.  All images are loaded and placed into a hash.
3. When we receive ruleset data from the server, the sprite structure is initialized to setup that sprite to point to the appropriate picture.

Step #3 is pretty difficult to mimic. I basically iterate over all valid ID's for each element and setup the sprite for that ID. Hopefully (and this seems to work) if the ID is invalid the sprite will just be initialized to NULL (and won't be used anyway).


That said, there are three bugs that I know of:

1. Rampant memory leaks. Fixing these will probably require writing a new function to free the images. However, the memory leaks as they are don't seem to make the system unusable - memory use doesn't grow linearly; it gives the appearance that each tileset is cached by the loader so switching repeatedly doesn't result in quickly unbounded memory growth.

2. The city dialog view is not properly resized in GTK. This is a GUI-specific issue, so it's probably best to create a new gui-specific function to be called at the end of the reload.

3. The mapview is offcenter after the conversion, because map_view_x0/map_view_y0 remain the same while the tile size and orientation may change. This is easily fixed.


I've also added some demo code to gui-gtk: an extra item in the "view" menu to toggle between trident, engels, and hires tilesets. Once the tileset switching becomes more mature GUI programmers will no doubt want to write frontends for tileset selection.

jason



[Prev in Thread] Current Thread [Next in Thread]