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.

AppGameKit Classic Chat / Reading byte from file ?

Author
Message
Alain91
12
Years of Service
User Offline
Joined: 20th Aug 2011
Location: France
Posted: 27th Mar 2012 21:05
Hello everyone !

I would like to read a level map file from agk.

For example, the map is like this :

mapwidth (42), mapheight(28), data (51,45,25):

the file hex dump : 42 28 51 45 25

All these datas are 8bit pieces.


I have seen the readstring function, but it read 4 byte at a time

Please could you tell me how to read 8bits at a time ?
I am using tier1.

Regards,
Alain
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 27th Mar 2012 22:20 Edited at: 27th Mar 2012 22:24
AGK doesn't understand bytes in Tier1. The smallest thing it will process, in numbers, is a 4 byte integer.

Assuming the hex dump is an ascii file of strings containing pairs of hexadecimal characters, you can use ReadLine to get each line in the file (or the whole file if there are no line breaks). ReadString reads a null terminated string, so that is not what you want to use.

Then you'd manually go through the string, grab each pair of characters and convert them to an appropriate integer value. Something like this:


Not the most elegant solution, but one quickly come up with.

If you were using Tier2, there would be lots of options, and bytes would be supported.

We give up some things to use either Tier1 or Tier2.

Good Luck!

Cheers,
Ancient Lady
Alain91
12
Years of Service
User Offline
Joined: 20th Aug 2011
Location: France
Posted: 27th Mar 2012 22:28
Thanks a lot for your quick answer Ancient Lady

I will take a look at your code.

Perhaps that in 1.7 or 1.xxx the byte type variable will exist..

I stay with Tier1 in order to keep compatibility with other platforms ..

Thanks again !
Alain
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 28th Mar 2012 18:20
Glad to be of help.

Somewhere, in another thread, there was a discussion about data types and memory efficiency.

To paraphrase what I remember...

Pretty much all machines you'll be programming for use 32 or 64 bit data streams. Meaning that fetching and storing is done 32 or 64 bits at a time. So, to do a byte process would mean grabbing (at least) 32 bits and then stripping the desired byte. This actually increases processing time over just going with the default integer.

So, I doubt we'll be seeing byte handling in Tier1 at least.

Cheers,
Ancient Lady
Alain91
12
Years of Service
User Offline
Joined: 20th Aug 2011
Location: France
Posted: 28th Mar 2012 20:01
You are right, but my aim was to keep memory usage low for small machines..

Anyway thanks for your kind answer

Alain

Login to post a reply

Server time is: 2024-05-02 03:43:08
Your offset time is: 2024-05-02 03:43:08