Jump to content

  • Log In with Google      Sign In   
  • Create Account


Tile data on a game level


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 zeybey1   Members   -  Reputation: 464

Like
0Likes
Like

Posted 04 June 2012 - 05:37 AM

I've been working on a tile engine for a game I'm making, but have come across a problem. I have enlargened the maps to be about as large as they will be once they are done, but the program is crashing because the arrays are too big. I've heard the max an array should generally be is about 1000, but my program is crashing only at 400. I even tried organizing the tiles into chunks, but to no avail.

How would i be able to hold the information of a level in memory without using an array? How do most people go about this?

Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 6685

Like
0Likes
Like

Posted 04 June 2012 - 06:17 AM

I've heard the max an array should generally be is about 1000, but my program is crashing only at 400

1000 or 400 what, tiles ? It depends on your data, but 1000 items for a single array shouldn't be a problem at all. Even 1000^2 (~1 mio) should not be a problem as long as you didn't put too much data into a single tile. Best to revisit the data you put into a tile data structure. Try to identify pattern and move common data into templates (i.e. forest tile template, river tile template etc.), then try to refer only a template (i.e. 16 bit index) and use extra data really sparsely.

#3 apatriarca   Crossbones+   -  Reputation: 1602

Like
0Likes
Like

Posted 04 June 2012 - 07:01 AM

In what way has your array been allocated? Why do you think the problem of your program is the array size? What kind of error are you getting? There is no constraint like "array size should be lower than N" in (C/C++?) programming.

#4 Ratslayer   Members   -  Reputation: 104

Like
0Likes
Like

Posted 04 June 2012 - 08:01 AM

I assume you are using C++. Are you initializing the array on the stack or on the heap? If you are writing something like "Tile tiles[400];" then you can get a stack overflow, depending on the size of the Tile object.
Either initialize your arrays via new (Tile[] tiles=new Tile[400]) or use a container object like std::vector (std::vector<Tile> tiles=std::vector<Tile>(1000)).

#5 zeybey1   Members   -  Reputation: 464

Like
0Likes
Like

Posted 04 June 2012 - 08:59 AM

I got it to work. I think either my tile object was too big or I was making too many(as I was dynamical making them based off the size of the room). Now I'm just using integers for each tile id, while before I had a rectangle for each one, which didn't make nearly as much sense.

It had to be size because I did a test with 100 and it worked fine, but after doubling the tile amount I got a memory allocation error.

And yes, I'm using c++. Probably should have specified that.

I'll spent more time debugging before I post a topic next time Posted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS