Jump to content
  • Advertisement
Sign in to follow this  
kingpinzs

Need help working through a parsing issue

This topic is 3394 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

what whould be the best way to parse the fallowing file? right now I am trying to use a combination of getline and istringstream
//
[MAP]
{width,height}
{amountoflayers}
//
[Background]
{imagename,maskname}
{width,height}
{x,y}
//
[Background2]
{imagename,maskname}
{width,height}
{x,y}
//
[Playerground]
<Player>
{imagename,maskname}
{width,height}
{x,y}
<enemy1>
{imagename,maskname}
{width,height}
{x,y}
<enemy2>
{imagename,maskname}
{width,height}
{x,y}
<enemy3>
{imagename,maskname}
{width,height}
{x,y}
<NPC1>
{imagename,maskname}
{width,height}
{x,y}
<NPC2>
{imagename,maskname}
{width,height}
{x,y}
<NPC3>
{imagename,maskname}
{width,height}
{x,y}
//
[Forground]
{imagename,maskname}
{width,height}
{x,y}

How I want this to work when it comes to the token [MAP] I want it to fill out the struct for map with data below it then go to the next token and do the same thing. I want lines that begin width // or are empty to be skipped. I am using c/c++

Share this post


Link to post
Share on other sites
Advertisement
Are the tokens like 'width' and 'height' actual tokens, or are they placeholders for the 'real' data? If the latter, can you post an example of what the real file would like?

Share this post


Link to post
Share on other sites
First you need to parse [tokens]
When you encounter a '[', read everything until ']'. That gives you the "type" of what you're going to parse. Then read up to the next '[', that gives you the data to be parsed.

Feed that data into an appropriate sub-parser based on the type.

I think you get the idea.

Also, if you can, change the comment token to be a single char like '#' for example. Having to parse two characters makes it more complicated, maybe for nothing?

I find many languages to be far better suited for text parsing than C++ (python, for example) If possible, use another language to convert (or "pre-process") your text file into something more easily readable from a C++ program.

(Edit: ... or make use C++ as higher level language by using a libriary as suggested below)

[Edited by - janta on April 20, 2009 12:45:04 AM]

Share this post


Link to post
Share on other sites
Here is the actule file to be parsed.
It should make a smiple breakout clone game.
once I get it to load then I am going to add collition info into the file



//
[MAP]
//width,height
{ 800 ,600}
//Number of layers
{2}
//
[Background]
{background.bmp,backgroundMask.bmp}
{800,600}
{0,0}
//
[Playerground]
{blocks.bmp,blocksmask.bmp}
//image width and height
{50,30}
//image x and y and tile id
{84,71,1}
{161,83,2}
{84,119,3}
{157,121,4}
//
[PLAYER]
{paddle.bmp,paddlemask.bmp}
//image width and height
{100,50}
//start x and y no need for tile ID
{400,500}
//
[OBJECT1]
{ball.bmp,ballmask.bmp}
//width and height
{40,40}
//start x and y no need for tile ID
{440,540}




Share this post


Link to post
Share on other sites
1) How do you know which objects need a tile ID and which don't?
2) When a tile ID is needed, how do you know how big the tiles are?

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
1) How do you know which objects need a tile ID and which don't?
2) When a tile ID is needed, how do you know how big the tiles are?


1) I only need tile IDs is when I use a single bitmap with multiple tiles in it
2) right now all the tiles are the same size. I have not figured out a way to find collition detection on irregular size tiles

Share this post


Link to post
Share on other sites
Quote:
Original post by kingpinzs
1) I only need tile IDs is when I use a single bitmap with multiple tiles in it


How do you know which bitmaps have multiple tiles in them?

Share this post


Link to post
Share on other sites
does any one have good way to do this in just c++?

Or does any one know any good tutorails for parsing a text file?

[Edited by - kingpinzs on April 26, 2009 12:19:24 PM]

Share this post


Link to post
Share on other sites
How would I use istringstream for this issue?

I can not figure out how to get it to find the [values]
then read in everything tell the next [values].

Is there a way to do that with istringstream or am I going about it the wrong way.

Or should I use something differnt? Like getline or something?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!