Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (575)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  some questions about game development  (Read 3981 times)
0 Members and 1 Guest are viewing this topic.
Offline SpiritWolf

Senior Newbie




Java games rock!


« Posted 2005-05-11 09:38:32 »

Hi. I've been trying to develop a 2D game. But I'm having trouble deciding how I should store data like maps and sprites. When I save a map 3x128x128 (foreground, background, and roof) to disk as xml using a xml encoder it
saves a map that's 8 megabytes large! when I save using object serialization it's 500 kilobytes, so I'm trying to make a decision between flexibility and space. For example, if I were to use object serialization, what if I add more information to the map, such as triggers and npcs, etc.. as I add these things won't previous class files become outdated and cause me to lose maps I've made?

I wonder if it's how I store the layers, they look like this

class TileLayer {
  LinkedList<Tile>[][] layer;
}

I used a linked list thinking I could conserve space, is this incorrect?

One last question about game development is how should I deal with guis in fullscreen exclusive mode using java 2D?

Any help would be greatly apprechiated as always.
Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2005-05-11 10:00:40 »

Storing raw data in XML is pointless. I'd elaborate, but I need to run.. just don't do it Wink

EDIT:

Ok, tiles.. if you're only going to have a certain set of tiles (i.e. a few for grass, a few for rocks etc..) just assign each one a number and store this in the file.

Is your map going to be changing size during game play? If not, just use an array, it'll be faster and easier to manage.

128x128x3 = 49152, assuming you're going to have no more than 65k tiles, you could store each tile index as a short giving you approx 100k a file?

Kev

Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #2 - Posted 2005-05-11 10:52:38 »

GUI's in fullscreen mode shouldn't be an issue, just use them like normal. However, if you're using accelerated graphics mode it gets a little more tricky since you'll have to turn repaint off on each component (i.e. setIgnoreRepaint(true)) and actively draw each component yourself.

Kev

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cfmdobbie

Senior Duke


Medals: 1


Who, me?


« Reply #3 - Posted 2005-05-11 12:18:20 »

Personally, I'd use XML to store the map data, and have a utility that turns map data into a serialized object.

Write the resource loader to accept either .xml or .ser, and you can effectively ignore the problem until you're ready to ship, as long as you keep the Serialization code up to date.

Hellomynameis Charlie Dobbie.
Offline princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2005-05-11 12:39:27 »

XML for maps? Whatever next? Computers for pets? Robot friends?

Cas Smiley

Offline Markus_Persson

JGO Wizard


Medals: 16
Projects: 19


Mojang Specifications


« Reply #5 - Posted 2005-05-11 18:48:27 »

XML is evil. Very, very evil.

Play Minecraft!
Offline SpiritWolf

Senior Newbie




Java games rock!


« Reply #6 - Posted 2005-05-11 20:35:09 »

Thanks for all the feed back!  

I've made a prototype of a map with shorts and without the linked list, and serialized it, what I found is it's only around 175 kb! thanks kevglass.

I was thinking about what you said about the tilesets. I had the idea to serialize an arraylist along with the map, containing the paths to images that the serialized map indexes. When the map is loaded in the game all the images will be resolved from this extra serialized object and the game can index this array using the map file to obtain the correct tiles.

I decided that I would just get the program up and running with serialized objects and each time I update a class just record that class and label it with a version in case I want to convert some legacy maps to a newer version. It might be a lot of book keeping, but I don't know another way to do it other than parsing a text file which seems to be a lot of work or xml (which seems to not be very popular from what most of you are saying).

So I think I shouldn't worry to much about file formats and just serialize everything until I get it up and running.
I'll worry about it when I actually start making maps and sprites.

Thanks again for all the feedback.
Offline cfmdobbie

Senior Duke


Medals: 1


Who, me?


« Reply #7 - Posted 2005-05-11 22:01:06 »

Meh.  Ignore the heretics. Grin

XML is great for storing user-edited resources.  I don't recommend writing XML of the form <cell x="3" y="5" contents="grass" ... />, but as a way of getting hand-tuned slightly-structured Strings into an application without having to write your own parser, it's fine.

Note that I don't condone the use of XML for non-human editable data, nor do I condone shipping data to the client still in XML form, unless they'll be editing it as well.

Remember kids, friends don't let friends process XML documents in speed-critical, resource-starved environments.

Hellomynameis Charlie Dobbie.
Offline princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #8 - Posted 2005-05-11 23:29:49 »

XML is great for what it's supposed to do Smiley
Storing maps definitely isn't one of those things!

<edit>However: using XML to store metadata about maps, and even the map data itself as a CDATA section is not a bad thing, provided one remembers to use SAX to parse it which is much more lightweight than DOM.

Cas Smiley

Offline SpiritWolf

Senior Newbie




Java games rock!


« Reply #9 - Posted 2005-05-12 00:12:53 »

I don't know a lot about xml. But I've seen sax requires a lot of setting up compared to dom. So maybe for small metadata files it would be okay to use dom? For example to use dom for the paths to tiles referenced by the map.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Markus_Persson

JGO Wizard


Medals: 16
Projects: 19


Mojang Specifications


« Reply #10 - Posted 2005-05-12 05:44:04 »

Very very offtopic:

Could someone explain to me why the industry seemingly blindly decided to go with a format that requires each tag name to be entered twice even when there's no chance of conflict?

Eg instead of "<long_tag_name data="wooo">contents</long_tag_name>", why not use "<long_tag_name data="wooo">contents</>", or even prettier "long_tag_name(data="woo"){contents}"

XML seems designed to waste as many bytes as possible.

Play Minecraft!
Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #11 - Posted 2005-05-12 07:01:01 »

Its about human readabilty, while it'd be easier enough write a bit of code to close bracket count it'd be hard to see what close was linked to with the naked eye.

Kev

Offline cfmdobbie

Senior Duke


Medals: 1


Who, me?


« Reply #12 - Posted 2005-05-12 07:08:20 »

And on top of that, XML is a subset of SGML, which was not designed with brevity in mind.

Edit: But hey, it's a text file.  Repeated sections in text files compress really well.

Hellomynameis Charlie Dobbie.
Offline Markus_Persson

JGO Wizard


Medals: 16
Projects: 19


Mojang Specifications


« Reply #13 - Posted 2005-05-12 07:18:21 »

Kevglass: Are you having problems seeing where blocks start and end in java?

1  
2  
3  
4  
5  
6  
<printHelloWorld>
  <while condition="keepgoing">
    System.out.println("Hello world!");
    keepgoing = false;
  </while>
</printHelloWorld>


1  
2  
3  
4  
5  
6  
7  
8  
void printHelloWorld()
{
  while(keepgoing)
  {
    System.out.println("Hello world!");
    keepgoing = false;
  }
}


I don't know about you, but to me it seems that the last one is far more readable, has less chance of being wrong (only one place to typo "printHelloWorld"), and takes up far less space.


Oh, and XML being based on SGML is exactly WHY it is evil in the first place. Wink

Play Minecraft!
Online kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #14 - Posted 2005-05-12 07:21:50 »

Markus = developer, used to blocked structured languages

XML Reader = not always a developer or even a particular technical person.

Its an aid to readability, look at old/scripting languages that have constructs like "while" "endwhile".

Kev

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #15 - Posted 2005-05-12 07:24:15 »

Quote
I don't know a lot about xml. But I've seen sax requires a lot of setting up compared to dom.


Yeah, I've seen that the earth is flat, too. I mean, it never looked curved to *me* Tongue.

Be careful about random things you see/hear; spend 20 minutes following tutorials for each and make your own conclusions. With a proper IDE it takes around 30 seconds to get all the setup code for SAX done. And there's zero runtime setup cost.

SAX reads and parses XML directly, streaming it into your app just like an InputStream, whereas DOM reads the whole file in one method call AND parses the whole file (which could easily take millions of milliseconds) and then - eventually - lets you start interacting with it.

malloc will be first against the wall when the revolution comes...
Offline Markus_Persson

JGO Wizard


Medals: 16
Projects: 19


Mojang Specifications


« Reply #16 - Posted 2005-05-12 07:29:40 »

another example:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
<?xml version="1.0" encoding="UTF-8"?>
<Recipe name="bread" prep_time="5 mins" cook_time="3 hours">
  <title>Basic bread</title>
  <ingredient amount="3" unit="cups">Flour</ingredient>
  <ingredient amount="0.25" unit="ounce">Yeast</ingredient>
  <ingredient amount="1.5" unit="cups">Warm Water</ingredient>
  <ingredient amount="1" unit="teaspoon">Salt</ingredient>
  <Instructions>
   <step>Mix all ingredients together, and knead thoroughly.</step>
   <step>Cover with a cloth, and leave for one hour in warm room.</step>
   <step>Knead again, place in a tin, and then bake in the oven.</step>
  </Instructions>
</Recipe>


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
?bml(version="1.0",encoding="UTF-8")?
Recipe(name="bread",prep_time="5 mins",cook_time="3 hours")
{
  title{Basic bread}
  ingredient(amount="3",unit="cups"){Flour}
  ingredient(amount="0.25",unit="ounce"){Yeast}
  ingredient(amount="1.5",unit="cups"){Warm Water}
  ingredient(amount="1",unit="teaspoon"){Salt}
  Instructions
  {
   step{Mix all ingredients together, and knead thoroughly.}
   step{Cover with a cloth, and leave for one hour in warm room.}
   step{Knead again, place in a tin, and then bake in the oven.}
  }
}


("bml" being, of course, "better markup language" Grin)

Play Minecraft!
Offline Markus_Persson

JGO Wizard


Medals: 16
Projects: 19


Mojang Specifications


« Reply #17 - Posted 2005-05-12 07:55:20 »

btw, I'm not terribly serious with this. Wink

xml is good enough for what it was designed for. It's not perfect, of course, but I recognize that that is almost a religious issue, so my opinions are just that.. opinions.

Play Minecraft!
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #18 - Posted 2005-05-12 22:13:07 »

Those verbose closing tags aren't that bad,  consider how well XML compresses, the ending tag in the compressed format is at worst a back reference to the full text of the starting tag.  Usually the tags are repeated enough that most instances compress optimally.

Also, your examples are all fitting on one page.  I do have problems matching braces in Java for large methods that don't fit on one screen with heavily nested blocks.  Ignore for the moment the argument that such methods are "too big" ;-). You often see people putting comments by the closing brace just for the purpose of identifying what it goes with.

Anyway XML is a heck of  a lot better than some of those icky unix shell things where 'case' blocks are closed off with 'esac'  or some other silliness. :-)


Offline Raghar

Junior Duke




Ue ni taete 'ru hitomi ni kono mi wa dou utsuru


« Reply #19 - Posted 2005-05-16 19:28:33 »

Quote
Very very offtopic:
Could someone explain to me why the industry seemingly blindly decided to go with a format that requires each tag name to be entered twice even when there's no chance of conflict?


Easy to parse with parsebots. Easy for creating a excerpts from lots of a completely unknown data, thus create meningless databases. Improvements, and rigidization of HTML. Rigidization is for some math brains nice things, I don't think so. Simplification of a unclosed tag problem. Hype. Buzzword. And other reason somewhat similar to UML reasons.

What if you'd like to have a nice block of tags plugged into each other? If you'd have a simple programmer convention for closing braces it might be impossible.
Offline Raghar

Junior Duke




Ue ni taete 'ru hitomi ni kono mi wa dou utsuru


« Reply #20 - Posted 2005-05-16 19:35:18 »

Quote
Also, your examples are all fitting on one page.  I do have problems matching braces in Java for large methods that don't fit on one screen with heavily nested blocks.  Ignore for the moment the argument that such methods are "too big" ;-). You often see people putting comments by the closing brace just for the purpose of identifying what it goes with.


I use jEdit, so I can have braces highlighting, and a nice comment created from opening brace in the status bar.
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #21 - Posted 2005-05-16 22:12:05 »

LOL.

BML is great Grin

弾幕 ☆ @mahonnaiseblog
Offline Markus_Persson

JGO Wizard


Medals: 16
Projects: 19


Mojang Specifications


« Reply #22 - Posted 2005-05-17 07:00:46 »

Help spread the word. Wink

Play Minecraft!
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #23 - Posted 2005-05-17 07:07:19 »

Another issue with using "something better" is that most games developers using java aren't capable of using a parser-generator. If you are, cool, you have no probs making custom formats like this. But for the poor souls who haven't worked out the arcane and usually poorly documented systems ("its sort of like yacc but different. Someone should write some docs". Oh. Thanks. Throw us a frickin bone here!) then having to write your own parser is too much of a waste of time.

PS: BML - you have a chance to correct the biggest bug in SGML: the forced use of shift for lots of your keypresses Grin. Use [ ] not { } and I'll use it Wink. Much faster to type and easier on fingers.

edit: all tongue-in-cheek, of course

malloc will be first against the wall when the revolution comes...
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #24 - Posted 2005-05-17 09:11:48 »

Quote
PS: BML - you have a chance to correct the biggest bug in SGML: the forced use of shift for lots of your keypresses Grin. Use [ ] not { } and I'll use it Wink. Much faster to type and easier on fingers.
Excepth thats ALt Gr all the time for me - there are other people in the world that don't have an UK keyboard layout Wink

Offline cfmdobbie

Senior Duke


Medals: 1


Who, me?


« Reply #25 - Posted 2005-05-17 10:03:47 »

Quote
there are other people in the world that don't have an UK keyboard layout Wink


Then they shall be educated Grin

Hellomynameis Charlie Dobbie.
Offline Markus_Persson

JGO Wizard


Medals: 16
Projects: 19


Mojang Specifications


« Reply #26 - Posted 2005-05-17 10:42:07 »

For me, { and [ are the same number of keypresses (altgr + 7 and 8). < is just one keypress, but > is two (shift + <).
I chose {} mostly because that's what java and c++ (et al) use, so it'd be familiar at least to programmers.


I'd volunteer to write a bml sax parser if someone else agrees to write the dom parser. ;)

Then we'll send an email to w3c saying "we appreciate you put a lot of effort into xml, but we thought it'd be a good idea to change to something better before it gets too much momentum"


Still not being serious, btw. ;)
I'm afraid xml already has far too much momentum.

Play Minecraft!
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #27 - Posted 2005-05-17 17:50:43 »

>For me, { and [ are the same number of keypresses

Same here.

Shouldn't this line:
?bml(version="1.0",encoding="UTF-8")?

look like...
bml(version="1.0",encoding="UTF-8")
(no {}=empty body Wink)

hmm...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
<?xml version="1.0" encoding="UTF-8"?>
<Recipe name="bread" prep_time="5 mins" cook_time="3 hours">
      <title>Basic bread</title>
      <ingredient amount="3" unit="cups">Flour</ingredient>
      <ingredient amount="0.25" unit="ounce">Yeast</ingredient>
      <ingredient amount="1.5" unit="cups">Warm Water</ingredient>
      <ingredient amount="1" unit="teaspoon">Salt</ingredient>
      <Instructions>
            <step>Mix all ingredients together, and knead thoroughly.</step>
            <step>Cover with a cloth, and leave for one hour in warm room.</step>
            <step>Knead again, place in a tin, and then bake in the oven.</step>
      </Instructions>
</Recipe>


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
bml(version="1.0",encoding="UTF-8")
Recipe(name="bread",prep_time="5 mins",cook_time="3 hours")
{
      title{Basic bread}
      ingredient(amount="3",unit="cups"){Flour}
      ingredient(amount="0.25",unit="ounce"){Yeast}
      ingredient(amount="1.5",unit="cups"){Warm Water}
      ingredient(amount="1",unit="teaspoon"){Salt}
      Instructions
      {
            step{Mix all ingredients together, and knead thoroughly.}
            step{Cover with a cloth, and leave for one hour in warm room.}
            step{Knead again, place in a tin, and then bake in the oven.}
      }
}


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
iml version="1.0" encoding="UTF-8"
Recipe name="bread" prep_time="5 mins" cook_time="3 hours":
      title: Basic bread
      ingredient amount="3" unit="cups": Flour
      ingredient amount="0.25" unit="ounce": Yeast
      ingredient amount="1.5" unit="cups": Warm Water
      ingredient amount="1" unit="teaspoon": Salt
      Instructions:
            step: Mix all ingredients together, and knead thoroughly.
            step: Cover with a cloth, and leave for one hour in warm room.
            step: Knead again, place in a tin, and then bake in the oven.


xml: 626 bytes
bml: 528 bytes
iml: 510 bytes

The 'i' obviously stands for "indention", which is part of the syntax (as seen in python). Of course it's fundamentally flawed. Heh. But it looks quite nice Wink

弾幕 ☆ @mahonnaiseblog
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #28 - Posted 2005-05-17 18:55:19 »

Why not use FML why we are about it.  In particular FML IV (aka FML-66), rather than FML-77 or FML-90  Grin

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
      PROGRAM BREAD
c
c      FML VERSION IV
c
        INTEGER*4 RECIPE(3), UNIT(4)
        REAL AMOUNT
        DATA RECIPE/'BRED','5MIN','3HRS'/
        DATA AMOUNT/3.0/1.5/1/
        DATA UNIT/'CUPS'/'OUNC'/'CUPS'/'TEAS'/

      WRITE(6,10)
 10      FORMAT(51HMIX ALL INGREDIENTS TOGETHER, AND KNEAD THOROUGHLY.)
      WRITE(6,20)
 20      FORMAT(56HCOVER WITH A CLOTH, AND LEAVE FOR ONE HOUR IN WARM ROOM.)
      WRITE(6,30)
 30      FORMAT(55HKNEAD AGAIN, PLACE IN A TIN, AND THEN BAKE IN THE OVEN.)

      STOP
      END


Alan

Time flies like a bird. Fruit flies like a banana.
Offline Aramaz

Junior Duke




Java Games Rock!


« Reply #29 - Posted 2005-05-20 15:35:58 »

write your own parser and be happy...  Smiley

Play XSW: www.xsw.se
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (35 views)
2014-10-17 03:59:02

Norakomi (25 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (26 views)
2014-10-15 16:18:58

TehJavaDev (50 views)
2014-10-14 00:39:48

TehJavaDev (50 views)
2014-10-14 00:35:47

TehJavaDev (40 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (74 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!