MapLoader

This file is responsible for loading maps for TRSMap. It was made from scratch by Torwent but heavily inspired in the original TRSWalker 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 RSMAP_PATH

Default path to look for map files.


type TRSMapChunk

TRSMapChunk = record
  Chunk: TBox;
  Planes: TIntegerArray;
end;

Helper record to store chunk data with a name associated with.


type ERSMap

ERSMap = (NORMAL, HEIGHT, COLLISION);

Enum of map types.


type ERSMapJSON

ERSMapJSON = (OBJECTS, NPCS);

Enum of map json types.


type TRSChunkLoader

TRSChunkLoader = record(TSRLBaseRecord)
  Cache: String;
end;

ChunkLoader record, this is what’s responsible for loading a “chunks” map.


TRSChunkLoader.Setup

procedure TRSChunkLoader.Setup(name, cache: String);

This is responsible for setting up the TRSChunkLoader.

Note

This is an internal method. Don’t use it if you don’t know what you are doing.


TRSChunkLoader.GetBitmap

function TRSChunkLoader.GetBitmap(chunk: String; plane: UInt32; map: ERSMap): TMufasaBitmap;
function TRSChunkLoader.GetBitmap(chunk: TPoint; plane: UInt32; map: ERSMap): 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.


TRSChunkLoader.GetJSONFile

function TRSChunkLoader.GetJSONFile(chunk: String; plane: UInt32; jsonType: ERSMapJSON): TJSONArray;
function TRSChunkLoader.GetJSONFile(chunk: TPoint; plane: UInt32; jsonType: ERSMapJSON): 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.


TRSChunkLoader.GetChunks

function TRSChunkLoader.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 osrs chunks are oddly numbered from bottom to top on the Y axis.

Example:

WriteLn TRSChunkLoader.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]];

TRSChunkLoader.GetMap

function TRSChunkLoader.GetMap(chunks: TPointArray; plane: UInt32; map: ERSMap): TMufasaBitmap;
function TRSChunkLoader.GetMap(start, finish: TPoint; plane: UInt32; map: ERSMap): 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.


TRSChunkLoader.BuildGraph

function TRSChunkLoader._BuildGraph(map: TMufasaBitmap; white, red: TPointArray): TWebGraphV2;
function TRSChunkLoader.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.


TRSChunkLoader.GetGraph

function TRSChunkLoader.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.


TRSChunkLoader.GetJSON

function TRSChunkLoader.GetJSON(chunks: TPointArray; plane: UInt32; jsonType: ERSMapJSON): TJSONArray;
function TRSChunkLoader.GetJSON(start, finish: TPoint; level: UInt32; json: ERSMapJSON): 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 TRSLegacyMapLoader

TRSLegacyMapLoader = record(TSRLBaseRecord)
  Cache: String;
end;

LegacyChunkLoader record, this is what’s responsible for loading a map from a file, same as the original TRSWalker by slacky.


TRSLegacyMapLoader.Setup

procedure TRSLegacyMapLoader.Setup(name, cache: String);

This is responsible for setting up the TRSLegacyMapLoader.

Note

This is an internal method. Don’t use it if you don’t know what you are doing.


TRSLegacyMapLoader.FindFiles

function TRSLegacyMapLoader.FindFiles(filename: String): TStringArray;

This is responsible for finding the map file to be loaded. Will only find .png or .bmp files in RSMAP_PATH.

Note

This is an internal method. Don’t use it if you don’t know what you are doing.


TRSLegacyMapLoader.GetMap

function TRSLegacyMapLoader.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 TRSMapRegion

TRSMapRegion = 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 TRSMapLoader

TRSMapLoader = record(TSRLBaseRecord)
  Cache: String;

  Map, Heightmap, Collision,
  DownscaledMap: TMufasaBitmap;

  MapBox: TBox;
  Graph: TWebGraphV2;

  Regions: array of TRSMapRegion;

  Padding, Downscale: UInt32;

  Loader: TRSChunkLoader;
  LegacyLoader: TRSLegacyMapLoader;

  UsingChunks, SkipGraph: Boolean;

  ObjectData: TJSONArray;
  NPCData: TJSONArray;
end;

TRSMapLoader is what’s responsible for loading a map for TRSMap.

It will use TRSChunkLoader or TRSLegacyMapLoader 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.