Re: Representation of objects
- From: "Ebyan \"Nolithius\" Alvarez-Buylla" <Nolithius@xxxxxxxxx>
- Date: Fri, 2 Jan 2009 14:27:04 -0500
"Gerry Quinn" <gerryq@xxxxxxxxx> wrote in message news:MPG.23bb13aa47f3c7d71e@xxxxxxxxxxxxxxxxx
In article <01317b70-8e58-417a-9221-bd172d3845c0
@p2g2000prf.googlegroups.com>, vandaeleben@xxxxxxxxx says...
Hi everyone,
I just started making a roguelike in Java, and like a fool I started
making a World class, which is composed of instances of the Map class,
which in turn is made of Tiles. Since one Map has a few thousand
tiles, and a World has quite a bit of Maps, I quickly got an out of
memory error from the JVM.
I could easily adjust the Java command-line parameters to allow more
memory usage, but it got me thinking: my solution is not really
efficient... At all. And I didn't even have Monsters or Items.
My question is, how should I/could I represent these things in Java?
The standard approach is simply to have only a single instance of the
Map class, representing the area/zone/level of the world/dungeon your
character is currently in.
Other zones can be saved to disk, or simply discarded and regenerated
when the character enters them.
Of course you could fit a large world in memory easily enough on modern
PCs.
Another standard approach, for seamlessly connected maps, is to only load the "area", or, if the whole word is seamlessly connected, to load the 8 surrounding cells (or more, depending on how large the cells are in relation to screen space).
Even though the consensus is that you shouldn't load the whole game in one shot, it would take quite a few maps to fill up more than 128mb or 256mb (whatever the default JVM memory size is, I forget)... are you using unnecessarily large members in your Tile class? If this is the case, you might want to avoid using Strings (for example) for flags or states where a Boolean or Enum will do.
--Ebyan "Nolithius" Alvarez-Buylla
.
- Prev by Date: Re: How is time usually solved?
- Next by Date: Re: XP for nuthin', magic for free
- Previous by thread: Re: How is time usually solved?
- Next by thread: Re: XP for nuthin', magic for free
- Index(es):
Relevant Pages
|