https://sjbaker.org/wiki/index.php?title=GameTools_loadMap&feed=atom&action=historyGameTools loadMap - Revision history2024-03-29T10:07:57ZRevision history for this page on the wikiMediaWiki 1.24.4https://sjbaker.org/wiki/index.php?title=GameTools_loadMap&diff=94&oldid=prevSteveBaker: New page: This library loads GameTools level files and provides means to query and modify them at runtime: == class TileObject == A ''TileObject'' is a single 3D model (typically a terrain til...2007-10-24T04:46:25Z<p>New page: This library loads <a href="/wiki/index.php?title=GameTools_level_files" title="GameTools level files">GameTools level files</a> and provides means to query and modify them at runtime: == class TileObject == A ''TileObject'' is a single 3D model (typically a terrain til...</p>
<p><b>New page</b></p><div>This library loads [[GameTools level files]] and provides means to query and modify them at runtime:<br />
<br />
== class TileObject ==<br />
<br />
A ''TileObject'' is a single 3D model (typically a terrain tile) with an identifier and some bounding box data. All ''TileObject''s are are maintained in a global linked list rooted at the global object ''TileObject *tileList'' (which is NULL when there are no TileObjects loaded:<br />
<br />
class TileObject<br />
{<br />
TileObject ( const char *_name, ssgBranch *_root ) ;<br />
float getOptimumViewDistance () ;<br />
const sgBox *getBbox () ;<br />
const sgBox *getSnappedBbox () ;<br />
const char *getName () ;<br />
ssgBranch *getModel () ;<br />
TileObject *getNext () ;<br />
int getIdent () ;<br />
int getNumVertices () ;<br />
void overrideBbox ( const sgBox *newBox ) ;<br />
ssgBranch *find ( const char *nm ) ;<br />
} ;<br />
<br />
The constructor function is given the name of an object along with a pointer to its [[PLIB]] scene graph - it computes the bounding box and a 'snapped' bounding box that's snapped to the current grid size. It also adds it into the ''tileList''.<br />
<br />
== Utility Functions ==<br />
<br />
Snap a number to the nearest grid step:<br />
<br />
void gridSnap ( float gridstep, float *value )<br />
<br />
These utility functions query the global tileList:<br />
<br />
int getNumTiles () ;<br />
int findTile ( const char *name ) ;<br />
ssgBranch *findTileModel ( const char *name ) ;<br />
ssgBranch *findTileModel ( int which ) ;<br />
const char *findTileName ( int which ) ;<br />
TileObject *findTileObject ( int which ) ;<br />
TileObject *findTileObjectFromIdent ( int ident ) ;<br />
<br />
== class MapFlag ==<br />
<br />
Certain game features make use of invisible 'flags' that can be planted into the level using the [[tiled]] program (or manually entered into the XML level file).<br />
<br />
Flags have 'colours' (for ease of identification and classification) - as well as names.<br />
<br />
The colours are defined as simple integers: FLAG_RED, FLAG_GREEN, FLAG_BLUE, FLAG_CYAN, FLAG_MAGENTA, FLAG_YELLOW, FLAG_BLACK, FLAG_WHITE, FLAG_ORANGE and FLAG_GREY<br />
<br />
class MapFlag<br />
{<br />
MapFlag () ;<br />
~MapFlag () ;<br />
void setPosition ( sgCoord *crd ) ;<br />
void setColour ( int col ) ;<br />
void setName ( const char *newname ) ;<br />
float getX () { return x ; }<br />
float getY () { return y ; }<br />
float getZ () { return z ; }<br />
float getH () { return h ; }<br />
int getColour () ;<br />
const char *getName () ;<br />
const char *getColourString () ;<br />
const char *getColourFlagString () ;<br />
} ;<br />
<br />
== class Map ==<br />
<br />
The ''Map'' class is set up to represent a grid of terrain tiles - plus some number of MapFlags. The constructor function is told the size of the grid (in 'grid cells') and the various static ''set'' and ''get'' functions allow you to set the size of each grid cell for object placement and display (although the 'showGrid' applies only to the [[tiled]] program).<br />
<br />
Once constructed, you can call ''Map::load'' and ''Map::save'' to load and save the map as an XML level file you can add either tiles or maps by giving the TileObject or MapFlag along with its location. You can also remove the TileObject that's at a particular location - or a specific MapFlag.<br />
<br />
Finally, there are ''get'' functions to convert a grid cell number into a 3D coordinate, to get the ''MapEntry'' for the object at a particular 3D position, find the number of MapFlag objects - and the nearest one to any given location. You can also search for MapFlags by name or by a simple consecutive integer enumerator. ''getMapColour'' returns the ASCII colour name for a map given a colour number (eg FLAG_RED ==> "Red"),<br />
<br />
class Map<br />
{<br />
Map ( int maxGridX, int maxGridY ) ;<br />
bool remove ( sgVec2 loc ) ;<br />
bool remove ( MapFlag *mf ) ;<br />
bool add ( TileObject *to, sgCoord *loc, ssgBranch *br ) ;<br />
bool add ( MapFlag *mf, sgCoord *loc ) ;<br />
bool save ( const char *fname ) ;<br />
bool load ( const char *fname, ssgBranch *parent ) ;<br />
static void setGridParams ( float _showGridXY , float _showGridZ,<br />
float _placeGridXY, float _placeGridZ ) ;<br />
static float getShowGridXY () ;<br />
static float getShowGridZ () ;<br />
static float getPlaceGridXY () ;<br />
static float getPlaceGridZ () ;<br />
void getCoordFromMapLoc ( sgCoord *loc, float x, float y, float z, float h ) ;<br />
MapEntry *getMapEntry ( sgVec2 loc ) ;<br />
int getNumMapFlags () { return flagList . getNumEntities () ; }<br />
MapFlag *getNearestMapFlag ( float x, float y, float z,<br />
float maxrange, int colormatch = -1 ) ;<br />
MapFlag *getMapFlag ( const char *name ) ;<br />
MapFlag *getMapFlag ( int i ) ;<br />
const char *getMapFlagColour ( int c ) ;<br />
} ;<br />
<br />
== class MapEntry ==<br />
<br />
Whilst a TileObject represents a particular terrain tile, that tile may appear at multiple locations within the same map. ''class MapEntry'' stores a specific instance of that tile - the ''TileObject'' and it's location.<br />
<br />
class MapEntry<br />
{<br />
MapEntry ( TileObject *_to, int _x, int _y, int _z, int _h )<br />
MapEntry ( TileObject *_to, float _x, float _y, float _z, float _h )<br />
~MapEntry ()<br />
float getMapX () ;<br />
float getMapY () ;<br />
float getMapZ () ;<br />
float getMapH () ;<br />
void addModel ( ssgBranch *_gr ) ;<br />
TileObject *getTileObject () ;<br />
const sgBox *getSnappedBbox () ;<br />
} ;<br />
<br />
{{gameTools}}<br />
{{LoL}}</div>SteveBaker