How to describe numerous objects of an unknown quantity?

Started by Krozgen, April 23, 2006, 07:17:26 PM

Previous topic - Next topic

Krozgen

(I'm pretty sure this is in the right forum...)

I'd like to create a server / client world, in which a world is stored in a text file on the server. When a client connects to the server, the server retrieves that client's location in the world (as in, say, an MMORPG) (in this case, maybe that "town" to limit the amount of data transferred), and sends back information to describe that location. In other words, the client is in the town of New Brook, so the server sends back the data on every building and person in New Brook. The end goal is to have the client render the town and people in OpenGL - though that's not what my question is about (yet :P I'm sure I'll run into problems with that soon, though I'll post that in a different section of the forums).

My question is, I have no idea how many objects will be in the town. How do I program the client, in assembly, to store all that data? I can't make it into an array of objects without predicting some insanely large number, in order to not have to worry about expansion in the future. Each "object" would most likely be one quad, which means having an x, y, and z coordinate for four points each... that's 12 points, times maybe 6 quads for a simple box is 72 points. The bits start adding up a little bit too quickly for my liking.

I'm not sure what to do. I don't want the data to stream from the server to the client - that would be waaay too chaotic, laggy, and buggy especially. Should I store the data to a file, and read it back in whenever its needed? Should I create the world of buildings once, and then store the people in an array? I really don't know what to do :eek

Assuming I took that last case, and generated the world as the data for the buildings came in, then kept all moving objects in arrays for easy access (update locations as they're sent from the server, etc.)... how would I be able to create an array to take maybe 10 people, but then once another entered New Brook, allow it to store 11? Please let me know, and I hope this post isn't in the wrong place. Thank you.

-- small edit --
I'm sorry if that was very confusing... I'm no good at describing what I'm trying to do  :(

Mark Jones

Hi Krozgen. I have not tried anything like this, so take this as an idea only. But perhaps try a dual SQL-file approach. SQL's apparently allow 255 simultanious connections and eliminate many "gotchas" involved with rolling your own DB routine. File one is an index file which only holds say, the country, city, and town data. Any number of entries can be present. Say something like:

Quote from: index.db
USA - Ohio - Akron               - User ID 1
                                         - User ID 2
                                         - User ID 3
                - Archibold          - User ID 1
                                         - User ID 2
                                         - User ID 3
       - Pennsylvania - Owens - User ID 1
                                         - User ID 2
                                         - User ID 3   ...etc...

Then in the second file, hold the user data:

Quote from: user.db
User ID 1 from Akron,Ohio,USA: "data blah blah blah..."
User ID 2 from Akron,Ohio,USA: "data blah blah blah..."
User ID 3 from Akron,Ohio,USA: "data blah blah blah..."
User ID 1 from Archibold,Ohio,USA: "data blah blah blah..."
User ID 2 from Archibold,Ohio,USA: "data blah blah blah..."
User ID 3 from Archibold,Ohio,USA: "data blah blah blah..."
User ID 1 from Owens,Pennsylvania,USA: "data blah blah blah..."
User ID 2 from Owens,Pennsylvania,USA: "data blah blah blah..."
User ID 3 from Owens,Pennsylvania,USA: "data blah blah blah..."

Each UserID would have to be a unique value. A DWORD can represent 4.29 billion people if that's enough for your goals. A user logs in, the server identifies their origin and reads the index.db to find who's nearby, then reads those DWORD pointers from the userd.db file? :U
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Krozgen

Thank you very much, Mark Jones, and that's amazingly useful for the future.

Unfortunately, it seems I didn't describe which part of the program I needed help with :red

For the moment, let's ignore the fact that I'm helplessly in over my head with the server side of the program. I need a way for the client to be able to hold the world information that the server has sent to it, in order for the client to be able to correctly render the world.

In other words, if the client KNOWS that the server has 216 rectangles (er... QUADS) which compose the "world", then the client can create a 216 length array of a struct which contains the four verticies for each quad. The issue comes when, say, a similar array is applied to the other people in the world, and another one joins. Suddenly the 5 element array which I created to hold the locations of the people in the world needs to be 6 elements long.

Thank you for the server bit, though :toothy I'm sure that will come in handy very, very soon.

Eóin

Krozgen, I think what you're looking for is dynamic memory management. Check out the HeapAlloc, HeapRealloc, etc APIs.