thesadrogue / TheSadRogue.Primitives

A collection of primitive data structures for working with a 2-dimensional grid.
MIT License
21 stars 6 forks source link

Add Spatial Maps from GoRogue #115

Closed Chris3606 closed 1 year ago

Chris3606 commented 1 year ago

Overview

GoRogue has the concept of "spatial maps", which are really just an efficient way of representing a "sparse" set of objects on a map (eg not every object has one position). It abstracts away concepts pertaining to placing objects on a 2d grid, such as how many objects can exist at a location at once, whether or not the concept of layers/z-indexes exists, etc. Really, this should be in the primitives library, since although it requires some utility infrastructure to function properly, the core concept works for any 2D grid.

The code is about 50% unit tested, however most of it has been functionally tested fairly extensively in GoRogue. I intend to create more tests later, I figured getting it into this repository earlier rather than later is beneficial.

There are also a number of improvements I would like to make to this API. There are optimizations that can be performed (though most it is already quite well optimized), but more importantly I think it should be possible to implement an interface that avoids manual syncing of items if they have a Position field.

These APIs (both the spatial maps and some of the utility classes) are probably quite useful for SadConsole (at least SadConsole.Extended) and in general for grid-based games; so feel free to take some time and poke through them. The transition of these APIs to the primitives library presents a good opportunity to make improvements.

Changes