Re: Representation of objects



"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

.



Relevant Pages

  • Re: fps modding
    ... > Yeah the memory usage used to be really high for no reason - but they've ... hl2 without it bothering to log in and such. ... one can't expect new games to load as ... >> rebuild and load a map. ...
    (comp.games.development.programming.misc)
  • Re: How do you make a group level in Java?
    ... In my experience all languages are moving away from the concept of matching data structures to memory images. ... It's to the point now where languages like Java don't even bother to provide support for overlays, or whatever this would be called. ... Java has several nice ways to read data, including built-in parsers for XML, XSL, the Scanner class, several types of Buffer classes, frameworks for mapping objects to databases, even a memory mapped class for files. ... But there's no way to directly map that to objects on the heap that I know of. ...
    (comp.lang.java.help)
  • Re: example of excessive memory use (shootout)
    ... Java is a whole virtual computer inside the physical one. ... You have to have memory for the JVM itself, for the classes that it loads, many of which are needed no matter what programs it might run, for the various heap generations, and for the program itself. ... It has to load a whole bytecode interpreter, the Hotspot compiler, various heap structures and some fundamental classes before it can even begin to load the application. ...
    (comp.lang.java.programmer)
  • Re: deleting ONLY java variables from memory
    ... i want to load file into memory to perform operations on. ... large, so i load it in a piece at a time, using a java function for speed. ...
    (comp.soft-sys.matlab)
  • Re: shlwapi.dll
    ... > isn't in memory by default. ... You have to load and map it to your ... > application's memory by using LoadLibraryor LoadLibraryEx() before ...
    (microsoft.public.vb.winapi)