Server Side Game Map - Array or Other Object

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Gusy
Posts: 13
Joined: 07 Nov 2010, 17:57

Server Side Game Map - Array or Other Object

Postby Gusy » 04 Dec 2010, 16:04

I'm sorry this is such a vague question. I'm fairly new to game programming in general, and I'm looking for an opinion on design. I'm hoping this is the appropriate place to ask, because it deals with a data structure that will be used in my DB, in Java on the server, in Actionscript on the Client, and passed between the two by SFS2.

I have a rudimentary multiplayer game partially created, so I've gotten a little bit of experience with all four technologies over the course of a month. I want to add something complex. Right now I just have a little client side tilemap which makes up the ground that my players see. It is 2D, top down, so the map will theoretically go out a ways in both the X and Y axis.

I'd like to start storing the entire map, and make it quite large, in my MySQL database on the server side. I want to do this becuse I want to make it somewhat dynamic, allowing both player modifications and some other changes at regular intervals. The tile map is basically a 2D array of integers. every tile is square and the same size. So it is as simple as:

0,0,53
0,1,26
etc.

However, I don't want to load the whole map down to the client, I just want to load chuncks based on where the player is. I know this isn't an uncommon practce, and I think I can handle the implementation.

All of my questions are related to the best way to store the data using each of the four technologies. Since the player will only be receiving sections of the total array based on where they are, they aren't going to be getting completely populated arrays. There will be large gaps. In addition, I was thinking about some sort of basic procedural world generation that would kick in if the player walks towards a section of the map that is not yet defined in the database. This means that even the database would probably have gaps.

So I have two questions, and I'm thinking that each of the two might have different answers depending on whether I was talking about the DB, Java, Actionscript, and the SFS transfer mechanism.

1. Would arrays be the best storage mechanism for this type of data, given that they would have huge gaps? Would I be better off using some other type of collection / dictionary / hash / object? If I use arrays of integers with gaps in them, am I wasting large amounts of memory, and / or slowing down my iteration speed compared to using other structures?

2. A related question, and I'm just looking for an opinion here: Since I'll be storing this in a DB, would I be better off keeping the data in a one dimensional array with an ID created from the x and y indexes, like:

long ID = (long)(1000000 * x) + y

I could just use translate functions on the client and server, and never even bother with a 2D array, just leave it as a 1D array. Would this, in any way, give me better performance?

I've done a little DB work in my job, but I've never created a database that was indexed by two non unique columns, so I'm just trying to wrap my head around the best way to do this.

Thanks in advance for any advice / opinions you can give me.
Democre
Posts: 77
Joined: 16 Sep 2010, 17:58

Postby Democre » 05 Dec 2010, 02:49

You could use a 2 column primary key for db queries

Code: Select all

CREATE TABLE GridSpaces(
     Xordinal int,
     Yordinal int,
     SpaceState int,
     Constraint PK_GridSpaces PRIMARY KEY(Xordinal, Yordinal)
)

You could also try to find or build a 2 key map in the other languages.
For transferring between, just pack and unpack an SFSArray of SFSObject with those 3 fields.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 62 guests