MapLoader¶
This file is responsible for loading maps for TMap. It was made from scratch by Torwent but heavily inspired in the original TWalker by Slacky and it’s future iterations made by Olly.
Note
Most things in this file are for internal use only and you shouldn’t use them directly nor modify them if you don’t quite understand them.
const MAP_PATH¶
Default path to look for map files.
type TMapChunk¶
TMapChunk = record
Chunk: TBox;
Planes: TIntegerArray;
end;
Helper record to store chunk data with a name associated with.
type EGameMap¶
EGameMap = (NORMAL, HEIGHT, COLLISION);
Enum of map types.
type EGameMapJSON¶
EGameMapJSON = (OBJECTS, NPCS);
Enum of map json types.
type TChunkLoader¶
TChunkLoader = record(TSRLBaseRecord)
Cache: String;
end;
ChunkLoader record, this is what’s responsible for loading a “chunks” map.
TChunkLoader.Setup¶
procedure TChunkLoader.Setup(name, cache: String);
This is responsible for setting up the TChunkLoader.
Note
This is an internal method. Don’t use it if you don’t know what you are doing.
TChunkLoader.GetBitmap¶
function TChunkLoader.GetBitmap(chunk: String; plane: UInt32; map: EGameMap): TMufasaBitmap;
function TChunkLoader.GetBitmap(chunk: TPoint; plane: UInt32; map: EGameMap): TMufasaBitmap; overload;
Returns a chunk bitmap. If possible, it will be loaded from a cached .bmp file. If no cache file exists, the .png file is unzipped, loaded and saved as a .bmp for future uses. The files are cached as .bmp because .bmp is a raw format and simba loads them much faster that way.
Note
This are internal methods. Don’t use them if you don’t know what you are doing.
TChunkLoader.GetJSONFile¶
function TChunkLoader.GetJSONFile(chunk: String; plane: UInt32; jsonType: EGameMapJSON): TJSONArray;
function TChunkLoader.GetJSONFile(chunk: TPoint; plane: UInt32; jsonType: EGameMapJSON): TJSONArray; overload;
Returns a chunk json file. If possible, it will be loaded from a cached file. If no cache file exists, the file is unzipped, loaded and saved into cache for future uses.
Note
This are an internal methods. Don’t use them if you don’t know what you are doing.
TChunkLoader.GetChunks¶
function TChunkLoader.GetChunks(start, finish: TPoint): TPointArray; static;
Simple methods that will return all chunks in between a start and finish chunks.
This will also fix their order if required, as game chunks are oddly numbered from bottom to top on the Y axis.
Example:
WriteLn TChunkLoader.GetChunks([20,20], [22,22]).ToString();
//This will return:
//[[20, 20], [20, 21], [20, 22], [21, 20], [21, 21], [21, 22], [22, 20], [22, 21], [22, 22]];
TChunkLoader.GetMap¶
function TChunkLoader.GetMap(chunks: TPointArray; plane: UInt32; map: EGameMap): TMufasaBitmap;
function TChunkLoader.GetMap(start, finish: TPoint; plane: UInt32; map: EGameMap): TMufasaBitmap; overload;
This returns a bitmap of all the chunks you pass into it or start and finish plus everything inbetween.
Note
This is an internal method. Don’t use it if you don’t know what you are doing.
TChunkLoader.BuildGraph¶
function TChunkLoader._BuildGraph(map: TMufasaBitmap; white, red: TPointArray): TWebGraphV2;
function TChunkLoader.BuildGraph(name: String; map: TMufasaBitmap): TWebGraphV2;
Magically builds a webgraph for you for a given collision map passed into map.
The collision map can only have 4 colors:
white ($FFFFFF) for walkable space
black ($000000) for non walkable space
red ($0000FF) for doors (optional)
gray ($333333) for objects (optional)
Note
This is an internal method. Don’t use it if you don’t know what you are doing.
TChunkLoader.GetGraph¶
function TChunkLoader.GetGraph(name: String; plane: UInt32; map: TMufasaBitmap): TWebGraphV2;
Returns a TWebGraphV2 for the given map.
If the graph is already cached we load it from cache, otherwise we build it and save it into cache.
Note
This is an internal method. Don’t use it if you don’t know what you are doing.
TChunkLoader.GetJSON¶
function TChunkLoader.GetJSON(chunks: TPointArray; plane: UInt32; jsonType: EGameMapJSON): TJSONArray;
function TChunkLoader.GetJSON(start, finish: TPoint; level: UInt32; json: EGameMapJSON): TMufasaBitmap;
Returns a merged JSON file of all the jsons of our chunks or start and finish plus everything inbetween.
Note
This is an internal method. Don’t use it if you don’t know what you are doing.
type TLegacyMapLoader¶
TLegacyMapLoader = record(TSRLBaseRecord)
Cache: String;
end;
LegacyChunkLoader record, this is what’s responsible for loading a map from a file, same as the original TWalker by slacky.
TLegacyMapLoader.Setup¶
procedure TLegacyMapLoader.Setup(name, cache: String);
This is responsible for setting up the TLegacyMapLoader.
Note
This is an internal method. Don’t use it if you don’t know what you are doing.
TLegacyMapLoader.FindFiles¶
function TLegacyMapLoader.FindFiles(filename: String): TStringArray;
This is responsible for finding the map file to be loaded.
Will only find .png or .bmp files in MAP_PATH.
Note
This is an internal method. Don’t use it if you don’t know what you are doing.
TLegacyMapLoader.GetMap¶
function TLegacyMapLoader.GetMap(filename: String; crop: TBox = []): TMufasaBitmap;
Returns the map file from cache if it exists, if it doesn’t,
the map is loaded and saved as a .bmp cache file for next usages.
.bmp is used for caching because it’s a raw image format and Simba loads it much faster than .png.
Note
This is an internal method. Don’t use it if you don’t know what you are doing.
type TMapRegion¶
TMapRegion = record
Name: String;
Original: TBox;
Region: TBox;
Plane: UInt32;
Offset: TPoint;
end;
Map region record, responsible for storing the map region/chunk data.
Note
This is an internal type. Don’t use it if you don’t know what you are doing.
type TMapLoader¶
TMapLoader = record(TSRLBaseRecord)
Cache: String;
Map, Heightmap, Collision,
DownscaledMap: TMufasaBitmap;
MapBox: TBox;
Graph: TWebGraphV2;
Regions: array of TMapRegion;
Padding, Downscale: UInt32;
Loader: TChunkLoader;
LegacyLoader: TLegacyMapLoader;
UsingChunks, SkipGraph: Boolean;
ObjectData: TJSONArray;
NPCData: TJSONArray;
end;
TMapLoader is what’s responsible for loading a map for TMap.
It will use TChunkLoader or TLegacyMapLoader depending on what the situation requires.
Note
This is an internal type. Don’t use it if you don’t know what you are doing.