Clone
5
Region Pager Base
Kayne Ruse edited this page 2016-12-15 22:16:57 +11:00

Introduction

RegionPagerBase is one of the main classes used in TurtleMap, and is the base class of RegionPagerLua. It handles a collection of region objects, which collectively form the game's map. RegionPagerBase was intentionally designed as the parent of RegionPagerLua, but is also fully functional on it's own. If you wish to use TurtleMap without any lua scripting, then RegionPagerBase will be your main interface with the map.

Methods

Region::type_t SetTile(int x, int y, int z, Region::type_t v);

This takes an x, y, and z parameter (z is zero indexed), indicating a tile in the map, and a layer. v is the new value for that tile. This function retreives a region with GetRegion, then it calls that region's SetTile.

Region::type_t GetTile(int x, int y, int z);

This takes an x, y, and z parameter (z is zero indexed), indicating a tile in the map, and a layer. It will return that Region::tile_t. This function retreives a region with GetRegion, then it calls that region's GetTile.

bool SetSolid(int x, int y, int b);

This takes an x and y parameter, indicating a tile in the map. b indicates whether it should be solid (true) or not (false). This function retreives a region with GetRegion, then it calls that region's SetSolid.

bool GetSolid(int x, int y);

This takes an x and y parameter, indicating a tile in the map. It returns whether it's solid (true) or not (false). This function retreives a region with GetRegion, then it calls that region's GetSolid.

Region* GetRegion(int x, int y);

This is the universal function for accessing a Region object. You can pass any integer value as x and y, and the correct region will be retrieved. First, it calls FindRegion. If that fails, it calls LoadRegion. Finally, if that fails, it calls CreateRegion as a last resort. Therefore, this will always return a pointer to a Region object.

Region* FindRegion(int x, int y);

x and y must be multiples of REGION_WIDTH and REGION_HEIGHT respectfully. It will retrieve any existing region with the coordiantes x and y, or it will return nullptr.

Region* PushRegion(Region* const);

This will push any Region object into the RegionPagerBase.

Region* LoadRegion(int x, int y);

This will fail, and return nullptr. It's intended for overwriting by RegionPagerLua.

Region* SaveRegion(int x, int y);

This will fail, and return nullptr. It's intended for overwriting by RegionPagerLua.

Region* CreateRegion(int x, int y);

This will create a Region object with the coordinates x and y, add it to RegionPagerBase, and return it. If an object with those coordinates already exist, it will throw an exception.

void UnloadIf(std::function<bool(Region const&)> fn);

This takes a function with the prototype bool f(Region const&) as a parameter. Each Region object that causes that function to return true will be destroyed and removed from RegionPagerBase.

void UnloadAll();

This will destroy and unload all Region objects.

void ForEach(std::function<void(Region&)> fn);

This takes a function with the prototype void f(Region&) as a parameter, and passes each Region object to it, one at a time. This is used for applying a certain function to each object inside RegionPagerBase.

std::list<Region>* GetContainer();

This is an OO-breaking utility function, allowing access to the internal container which holds the Region objects.

This method is not officially supported.