Incbin data. How?
BlitzMax Forums/BlitzMax Programming/Incbin data. How?
| ||
I want to save my game data (all the level data etc.) in a form available to be included inside the .EXE, like incbin with graphics and sound. I can't incbin and reload the data files like I can with images and sound (or can I?), but is there another way to store the data that can be used like incbin? BTW The data is loaded into arrays when needed, so it's not all loaded into memory in one go. The data isn't very big (40x25 bits of data) at most. A (very) simple way of doing the above would be appreciated. |
| ||
Why can't you incbin the data? |
| ||
You can incbin data. But if you change it, you cannot write it back into the file with during runtime. Incbin is read only in your final exe. |
| ||
I don't need to change it at all. It's read only, for levels. I have incbin'd the data, but I've not been able to re-read it. Probably a path issue or something - I'll keep playing. Cheers chaps. |
| ||
Are you opening the file with OpenFile? Because that won't work (since you can write to a stream opened that way). Use ReadFile instead. |
| ||
No - I am using Readfile. Here's my cut-down code - I'm sure it's something obvious. Bit braindead at the moment. Graphics 640,480 incbin "data/lvl1.dat" Global map[50,50] data_test() End ' Data test Function data_test() filename$="incbin::data/lvl1.dat" filein=ReadFile(filename$) For y=0 To 24 For x=0 To 39 map[x,y]=ReadByte(filein) Next Next CloseFile filein EndFunction [EDIT] D'oh! Just realised why it wasn't working. I was using a Framework, which removed the data streaming. Works fine now :) |
| ||
Isn't there an IncBinPtr to get the base pointer of the included data, and why couldn't you use that to modify it at runtime? |
| ||
I was using a Framework, which removed the data streaming. Yep. Just add : Import BRL.RAMStream :-) |
| ||
Isn't there an IncBinPtr to get the base pointer of the included data Yes, there is. and why couldn't you use that to modify it at runtime? Because, at least on Windows, the Operating System does not permit you to modify the executable while it is running. |
| ||
Yeah Brucey, I did that after I realised what my problem was. :) |
| ||
Yo might be able to manage to change it as long as your changes are bit for bit. But you wouldn't be able to add or remove any data. You could erase something and make it zero, or change some values. But there is no way you could grow the file or shrink it. |