mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-21 11:31:23 +01:00
Updated Object Model (markdown)
parent
0667d99f26
commit
d89785567d
1 changed files with 29 additions and 1 deletions
|
|
@ -1 +1,29 @@
|
|||
**[Object model](https://en.wikipedia.org/wiki/Object_model)** in FMG is poorly defined, inconsistent and not documented in the codebase. This page is the first and the only try to document it somehow. Once everything is documented, it can be used for building a new consistent model.
|
||||
**[Object model](https://en.wikipedia.org/wiki/Object_model)** in FMG is poorly defined, inconsistent and not documented in the codebase. This page is the first and the only try to document it somehow. Once everything is documented, it can be used for building a new consistent model.
|
||||
|
||||
FMG exposes all its basic data to the global namespace. The global namespace is getting polluted and it can cause conflicts with 3rd party extensions. But it allows much faster debugging and allows users to run custom JS code to alter the behavior and perform custom changes. So it allows dev console to be used by end-users.
|
||||
|
||||
## Basic structure
|
||||
FMG has two meta-objects storing most of the map data:
|
||||
* `grid` contains map data before _repacking_
|
||||
* `pack` contains map data after _repacking_
|
||||
|
||||
Repacking is a process of amending an initial [voronoi diagram](https://en.wikipedia.org/wiki/Voronoi_diagram), that is based on a jittered square grid of points, into a voronoi diagram optimized for the current landmass (see [my old blog post](https://azgaar.wordpress.com/2017/10/05/templates) for the details). So the `pack` object is used for most of the data, but data optimized for square grid is available only via the `grid` object.
|
||||
|
||||
## Voronoi data
|
||||
Both `grid` and `pack` objects include data representing voronoi diagrams and their inner connections. Both initial and repacked voronoi can be build from the initial set of points, so this data is stored in memory only. It does not included into the .map file and getting calculated on map load.
|
||||
|
||||
### Grid object
|
||||
|
||||
* `grid.spacing`: `number` - spacing between points before jirrering
|
||||
* `grid.cellsY`: `number` - number of cells in column
|
||||
* `grid.cellsX`: `number` - number of cells in row
|
||||
* `grid.points`: `number[][]` - initial coordinates `[x, y]` based on jittered square grid. Numbers are rounded to 2 decimals
|
||||
* `grid.cells`: `{}` - cells data object, including voronoi data:
|
||||
* * `grid.cells.i`: `number[]` - cell indexes `Uint16Array` or `Uint32Array` (depending on cells number)
|
||||
* * `grid.cells.c`: `number[][]` - indexes of cells adjacent to each cell (neighboring cells)
|
||||
* * `grid.cells.v`: `number[][]` - indexes of vertices of each cell
|
||||
|
||||
* `grid.vertices`: `{}` - vertices data object, contains only voronoi data:
|
||||
* * `grid.vertices.p`: `number[][]` - vertices coordinates `[x, y]`, integers
|
||||
* * `grid.vertices.c`: `number[][]` - indexes of cells adjacent to each vertex, each vertex has 3 adjacent cells
|
||||
* * `grid.vertices.v`: `number[][]` - indexes of vertices adjacent to each vertex. Most vertices have 3 neighboring vertices, bordering vertices has only 2, while the third is still added to the data as `-1`
|
||||
Loading…
Add table
Add a link
Reference in a new issue