Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / loading data from .dat

Author
Message
Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 11th May 2008 01:39
okay so im having a program. im trying to do a basic tactical rpg (solid color tiles green=grass ect. circles=allys squares=bad guys) anyways i decided to work on rendering that map first. so my resolution is 640x480, and im using 25x15, 32x32 tiles. if thats not too confusing. Now i made a text file that holds all the frame data for the tileset:



And so begins my first problem. sometimes it pulls a garbage value out of there (source code below) of 53, or 64 its seeminly random i dont understand. Heres the source code im using.

"map.h"


"main.cpp"


"map.cpp"


any help would be great. now it compiles fine. but i get a black screen and nothing else. I dont know why its not drawing, or why the values arent reading in right. gah!

Your signature has been erased by a mod - please reduce it to 600x120
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 11th May 2008 02:24 Edited at: 11th May 2008 02:36
Your data file is ASCII, and I think you are assuming that when you read a "4" from a file, for example...it will equal 4. It won't. It will equal 52, which is the ASCII (American Standard Code for Information Interchange)) value for the printed value 4.

Also, in your functions in the map class it is not necessary to use the scope resolution operator, as you are within the namespace already...when you are inside of the function itself. The function implementation still needs it, but references to members of the class do not. For example, this:
map::data[x][y]=dbReadByte(1);//store data in map array
becomes:
data[x][y]=dbReadByte(1);//store data in map array
but:
int map::draw()//draw the map on the screen
does not change.

After that, I would say that you've loaded an image, opened and read a file and made a sprite...or, did you?

Start off by verifying that the file you just tried to open actually opened, and that the other things worked, too.
Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 11th May 2008 02:32
i know it opened (rand a little test to make sure, thought it was the hard way it also told me what it was really doing. so i need to save it as non ASCII. that makes sense thanks man

Your signature has been erased by a mod - please reduce it to 600x120
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 11th May 2008 05:48
Well.... I think if you stick with 0-9 on your map, you can just just subtract 48 I think and a number 0-9 .. or just use the "CHAR... that's what I'd do. You have some very clean looking code.. didn't totally analyze it.. but its nice looking.. EZ to read.

Follow JinZai's advice first to troubleshoot... my only "comment" really is that you can make that array you load into an array of char... just typecast the readbyte thing...

map::data[x][y]=(char)dbReadByte(1);

but you need to change the datatype of your array in the map class from int data... to char data...

Then your code that renders would have if statements like:
if(map::data[x][y]=='3'){RenderCircle(x*width,y*height)};

Or something.... Looks like your off to a good start.

Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 11th May 2008 18:14
hmmm thank you, but is there anyway to save a .dat without that formatting? i tried saving as Uni-Code in notepad but that didnt work either. I got it to render right now, but only if I directly feed in the data. which is not desired.

Your signature has been erased by a mod - please reduce it to 600x120
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 11th May 2008 18:22
What format you want? You like the text format right? Just need it to load correctly? Or are you trying to "lock it down" so you can't edit it with a text editor?

I like your text approach. Um... Usinf Standard C++ file io is probably worth a look... but it can give you compiler errors.. and you have to change some "project settings" to make things compile right.

However.. you should be able to use the DarkGDK fileio for this.

Let's get down to the nitty gritty...

You want to start with: ?? Text File ??

The format will be: ?? Like your first post ??

You want to store it like: ?? How? Array of int, char, what you need here??

Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 11th May 2008 18:38
heres my problem right now (image attached) all the green is the grass I made for my tile set (frame 1), all those colored blocks are errors (frames 10, and 13) I don't know why they are there. I type casted my data to a char as reccomended(until i can read my .dat files properly.) heres the data I fed in.



I feed that In and I get that, I know its not the code itself, because It works if the data is fed strait in, so it must be the .dat file.
---------------------------------
and in reply:
for now im only trying to make it read properly, preferably without typcasting as i have for my debug tileset a 10x10 tileset so typecasting is unfavorable. The answer tot he frst 2 questions is.

Yes I want to store it as a text file in .dat format.
2. Yes the format is the same
and 3 i would like it store in "int data[x][y]"

and thanks for all your help.

Your signature has been erased by a mod - please reduce it to 600x120

Attachments

Login to view attachments
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 11th May 2008 20:16
Didn't mean to steer you wrong with casting... I thought your text file was: 892347... not 4 5 6 7 3 2 3 ... (Spaces in there) LOL

Idea. Using numbers... 0-9 is not many. Using 0-9 and a-z and A-Z with give more options.

That said... Just write a test program that reads bytes (dbReadByte) and displays the #'s coming in. If you get codes that YOU KNOW are 0 thru 9, convert ... just use IF's for now until you see a pattern you can later optimize. if(bytein==48){map.data[x][y]=1;}; or whatever the codez are.

Remember in the text file... There might be ZEROS... Ignore! (TGC tends to use them ... but most text files don't have em .. there are valid reason for TGC to have them though to make some things easier for programmers just wanting to save a bunch of strings and read them back.)

Also Ignore 13, (Carriage return), if I were you, I'd make sure I didn't have tab's in my text file... Spaces are 32, 10=Linefeed... You can ignore these ones.

does this help?

Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 11th May 2008 20:53
hmm yes lol so basically im going to have to write a class/function to read in the data and convert it into a useable value.

Your signature has been erased by a mod - please reduce it to 600x120
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 11th May 2008 21:29
yeah, maybe... but ... I mentioned optimization because once you look at an ascioo code chart... you'd see that 0-9 are contiguous... so you can do things like

if(asciibyte>(unsigned char)'1' && asciibyte<(unsigned char)'0'){
value=AsciiByte-48;
};

etc. Same for a-z and A-Z.... they are contiguous..thankfully.

Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 12th May 2008 00:46
hmmm okay thank you for all your help

Your signature has been erased by a mod - please reduce it to 600x120
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 12th May 2008 09:21
You're Welcome. Post here when you get it working... or if you get stuck... me or someone will help I'm sure. (Plus I want to know when you get it working.. this is looking promising.. I Like the Tile Games!)

Vesper103
16
Years of Service
User Offline
Joined: 21st Feb 2008
Location: Beloit WI
Posted: 13th May 2008 05:04
okay will do, I decided to write my own dark GDK engine so I dont run into this problem with tile games anymore, so for now im gunna give that everything i have, im going to call it Gimmick. and it will be directly geared to top down tile_based games. I did find one thing i was doing wrong:



do you see the problem? I didnt until I was slacking off in school and planning all this out. Lets simplify by using a 3x3 grid.

Grid:

0 1 2
0
1
2

thats our grid. Now i was getting the sprite ID using X*Y so the Sprite Ids Were Layed out like this

0 1 2
0 0 0 0
1 0 1 2
2 0 2 4

now do you see it? there are 5 0 sprite id's and 2 2's. so I will fix that code with this:



see the changes? first off I added one to X&y so the array can start at 1 getting right of my 0 problem. Second I added an offset variable to get rid of repeating sprite id's this will increase each time a new row is started by the max number of x. Ill show below. so heres the new grid:

1 2 3
1 1 2 3
2 4 5 6
3 7 8 9

how does this work? If you haven't figured it out. its like this.

for the top row offset is equal to 0, and the sprite id is x+offset. so basically the sprite id is whatever the x is. 1,2, and 3. after that the offset is increased by 3. so when x=1, you add 3 to get 4! x=2+3=5 and x=3+3=6. add 3 more and you got a bottom row. as long as Offset is increased by the maximum ammount of x cells, than the code will work. Tada! took me for ever to find this error.

Your signature has been erased by a mod - please reduce it to 600x120
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 13th May 2008 18:04


Y on outside, x on side.. is how I do it all the time. However I want to point out != is less bullet proof than using <, <= >, >= Especially when using floats or code that increments values different than "1" at time... like2, or 4.5 etc.. float rounding makes the != bad because the numbers are never eact.

Just a thought.

Login to post a reply

Server time is: 2024-11-20 09:39:45
Your offset time is: 2024-11-20 09:39:45