Game Data Storage
Hi. I am currently writing a smallish java game - a kind of populous clone - where an isometric world will be populated with various entities moving around independantly.
In order to do this I have a main class which uses an array of a class 'Entity' which is around 4-500 in size. I also hold the game map in a multidimensional array of class Tile around 450 x 300.
The main class loops with a while statement and updates an identical 'entity' array and map array in the graphics engine and a seperate thread - entity_engine' updates the entity array in the main class every 0.5 seconds. Data is read through using For loops on each array
My problem is - this seems a very resource wasteful way to handle the in game data - ie there are identical arrays in both the main class and the graphics engine. Is there anyway I can reference the array in the main class and refer only to that array in my graphics engine. I don't know if i have explained that clearly.
Also, is it a stupid idea memory-wise to create arrays of classes?
[1065 byte] By [
cstpgg123a] at [2007-11-26 13:05:12]

# 1
>My problem is - this seems a very resource wasteful way to handle the in game data
If you haven't experienced any memory issues than it only "seems" to be a problem. Do some math to determine if its a problem.
An object reference take 4 bytes. An array of objects therefore takes 4 bytes per entry plus some nominal overhead. If you kept all of your objects in a single dimensioned array of size 135000 (450*300) then the storage requirements per array are (135000 * 4 / 1024) Kb = 527k.
>Is there anyway I can reference the array in the main class and refer only to that array in my graphics engine
Yes. Pass the reference to the graphics engine.
>Also, is it a stupid idea memory-wise to create arrays of classes?
No stupider than creating an array of ints.
# 2
> >My problem is - this seems a very resource wasteful
> way to handle the in game data
>
> If you haven't experienced any memory issues than it
> only "seems" to be a problem. Do some math to
> determine if its a problem.
> An object reference take 4 bytes. An array of objects
> therefore takes 4 bytes per entry plus some nominal
> overhead. If you kept all of your objects in a single
> dimensioned array of size 135000 (450*300) then the
> storage requirements per array are (135000 * 4 /
> 1024) Kb = 527k.
>
Thanks. The reason I think there is a memory issue is that my CPU works at 100% with a relatively - I think - small map (450 x 350) and only 40 'entities' - (I was planning a maximum population of up to 2000).
I didn't think I had any over-elaborate algorithms because the in game characters don't have any behaviours done yet but the whole thing chugs along at 10 - 12 fps in an empty area and 1-2 fps where there is 'land'.