Sprites in huge world

Started by
23 comments, last by gerbenvv 18 years, 7 months ago
That's gonna need to much memory. i can't have an array of 1000 x 1000, but one of 50.000 x 50.0000.

What do i have to do if a sprite is 100px width? Take the center as THE point? But what if only 40px are visible?

[Edited by - gerbenvv on September 8, 2005 1:15:10 PM]
while (!asleep()) {    sheep++;}
Advertisement
Hi,
No problem.
Each object list is basically a pointer to objects with little extra info. Maybe one int to count objects in each list. Thats about 8 bytes.
8 bytes*1000 = 8kb... not much mem at all...

8*50000=400kb... average PC has way larger memory. Consider in this case your 50000*50000 map will consume at least 1 byte/entry... thats about 2.5gb memory...

Now, if you have that size of maps, dont try to load all the map in one time. Brek it into 256x256 chunks and keep 9 chunks (central and the 8 around) loaded at a time.

Now, each sprite HAS a central point. Its exactly where the sprite is located in the world. Say a tree is located in your world at position (32.3f, 24.5f). You place it in the list number 24. When you process the list, you must consider an additonal extent. If you have to process rows from 100 to 120, then consider processing rows from 90 to 130 so objects may be processed.

Consider that you are rendering 40 rows. But you are saving 960.

There are some other considerations when this is useful, particularly when processing lights and blockers for real time shadow.

My old game engine:
http://www.spritekin.com/kengine/screenshots.htm

Luck!
Guimo
I programmed my idea and it is very fast! (75 fps) So there is no need to chunk the world.

World map = 4.95Mb
1000 x 1000 tiles (tiles are 50 x 50)
10000 sprites

Now, i'm gonna do the graphics.
while (!asleep()) {    sheep++;}
Why waste memory on a tile struct? You can just have a 2D array w/ an int value to represent tile and base tile type by where it the tile is on the tileset, so you group the blocking tiles, non blocking, water, etc.

Edit: Wait, did you actually like draw the background of the map or did you work off a tileset? If you just drew it, you still don't need a tile struct, just need to store each tiles value whether its swimming blocking nonblocking etc......
I've now got an array with tile types (named tiles) and an array with the tile struct.

In the tile struct is information about its row, cell, sprites on it, pointer to first sprite, etc.
while (!asleep()) {    sheep++;}

This topic is closed to new replies.

Advertisement