Search code examples
actionscript-3haxeopenfl

Haxe - best way for storing large amount of objects at runtime


I am developing a massive multiplayer online 2D game in Haxe/OpenFL, where world is divided into two-dimensional grid of sectors, therefore each sector acts as one object. On server, these sector objects may or may not exist in memory (depending on whether players are currently in them or not) and I need to access these sector objects via their x and y coordinate. Theoretically there can be several thousands of these objects at any given time.

My question is, what is the best (fastest, most efficient) way of storing and accessing these objects. I tried to use two-dimensional arrays with x and y as indexes, but my implementation was extremely slow.


Solution

  • In server side you may use a hashmap data structure to save the sectors,the key would be x_y.Check the memory after You initialize all the sectors when server startup, if it cost two much, you may initialize some main sectors at first and another sector should be initialized only when it's actually been accessed.