On May 15, 02014, at 6:12, Daniel Friis Lindegaard <[email protected]> wrote:
> Hi,
> I'm developing a multiplayer game using Socket.io.
> Because the amount of players and other game objects can potentially be a
> lot, I want to be able to select the game objects from an area (x and y
> coordinate) of the game.
>
> A simplified version of how the gameObjects are stored inside node.js is
> below:
> var gameObjects = {
> "0": {x: 0, y: 32, name: "lol"},
> "1": {x: 0, y: 32, name: "lol2"},
> "11": {x: 0, y: 32, name: "lol3"}
> }
>
> There can be thousands of game objects at the same time..
>
> Should I create a multidimensional array (x and y) to hold references to the
> game objects? Should I just filter the gameObjects or??
> What would you think as the best practice?
You’re looking at an indexing problem. This one’s tricky, and depends greatly
on how dense your data is.
If the x and y are mostly empty space, then you’ll want something like an
adjacency list — what nodes are near other nodes (or certain grid points)
If they’re dense, you’ll probably want to use two-dimensional arrays.
How often do these searches occur? How much do things get updated?
That’ll play in as well.
Sorry there’s no easy answers, but ‘it depends’.
Aria
signature.asc
Description: Message signed with OpenPGP using GPGMail
