How to expose game data in the game without a singelton?
Posted
by
zardon
on Game Development
See other posts from Game Development
or by zardon
Published on 2012-04-16T08:00:43Z
Indexed on
2012/04/16
11:46 UTC
Read the original article
Hit count: 326
I'm quite new to cocos2d and games programming, and am currently I am writing a game that is currently in Prototype stage. Everything is going okay, but I've realized a potentially big problem and I am not sure how to solve it.
I am using a singelton to store a bunch of arrays for everything, a global list of planets, a global list of troops, a global list of products, etc. And only now I'm realizing that all of this will be in memory and this is the wrong way to do it.
I am not storing files or anything on the disk just yet, with exception to a save/load state, which is a capture of everything.
My game makes use of a map which allows you to select a planet, then it will give you a breakdown of that planets troops and resources,
Lets use this scenario:
My game has 20 planets. On which you can have 20 troops.
Straight away that's an array of 400!
This does not add the NPC, which is another 10.
So, 20x10 = 200
So, now we have 600 all in arrays inside a Singelton.
This is obviously very bad, and very wrong. Especially as the game scales in the amount of data.
But I need to expose pretty much everything, especially on the map page, and I am not sure how else to do it.
I've been told that I can use a controller for the map page which has the information I need for each planet, and other controllers for other items I require global display for.
I've also thought about storing each planet's data in a save file, using initWithCoder
however there could be a boatload of files on the user's device?
I really don't want to use a database, mainly because I would need to translate NSObjects and non-NSObjects like CGRects and CGPoints and Colors into/from SQL.
I am open to other ideas on how to store and read game data to prevent using a singelton to store everything, everywhere.
Thanks for your time.
© Game Development or respective owner