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 / Reading from an uncompressed file

Author
Message
F4SHAD0
13
Years of Service
User Offline
Joined: 28th Jan 2011
Location: Behind You
Posted: 6th Feb 2011 08:04
Hey guys. I was wondering. There are files that hold all media used in the game. You know how Star Wars: Empire at War have .meg files, 18 Wheels of Steel have .srs files, and Evochron Mercenaries ( made with DarkBasic ) have .evo files. I was wondering if it were possible to read media files like .png and .X files from an uncompressed file mentioned above. Not exactly like above, but I assume you get the point.

I was experimenting with this all day yesterday but to no avail. With WinRar, I tried storing the media files in a .rar and .zip file, but when I build and run the game, it says that the file can't be found. Many thanks for your help/solutions.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 6th Feb 2011 11:35 Edited at: 6th Feb 2011 11:37
are you looking for a way to create your own file format, to hold all the data you want (like "MyOwnFile.MYFORMAT", where MyOwnFile is the file name and MYFORMAT is the format )? or trying to read some other format?

if you are trying to read someone else format, you gotta do one of two:
either ask the creator of this format, how are data stored in it
or open it up (in notepad or whatever) and read it, then try to figure out how it works (most of the times you won't figure it out, unless it's a very simple, self-explained format).

but if you are trying to create your own format, then just some info you gotta keep in mind:
your own file with it's format is just a text file! but data are written in it in some way that only those who knows how can read it (well depends on what you want, might be a public format, whatever..), the purpose is to protect your media from being "easily" stolen by users (i believe there is always a way to steal media ( thats sad , but those people somehow find their ways )), so what you want to do is:
from your C++ source, create a file, for example, using C file methods:

or using fstream:


and for reading, you do the same thing, but (for C methods) use "r" instead of "w" in fopen, (fstream method) use ios::in instead of ios::out

so only reading/writing left, well it's all up to you! it could look like this: (saving an image)


thats for saving (img is an array of pixels (size = is imgWidth*imgHeight), each pixel contains 4 elements, r/g/b/a (red/green/blue/alpha), and each one got to be 1 byte (BYTE or unsigned char))

same thing with loading, you just read them (line by line or however you wrote it, then make a little parser (which is far from being complex!) and create the image with the info given

well now for the last part, how to tell GDK that our pixels form the image? well that's something im not aware of as i never tried with GDK, but it got to be possible, you can ask here on forums, someone probably knows how

of course, this is just one way, out of millions of other ways, you can just find the way that suits you

Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 6th Feb 2011 18:21 Edited at: 6th Feb 2011 18:21
I suppose you meant compressed file... Naturally the game program will not find files inside an archive, since all media are loaded by file name. If you want to package media into an archive and load from there, you would either need your own driver which creates a virtual file system, or your own functions to uncompress the files into memory and then somehow put them into the Dark GDK memory structures. Both are very difficult to do.

Your best bet may be a commercial application that already does this. For example this one. (Note that I don't know the program personally so I can't recommend it but I've seen it advertised several times on the forum and it seems to do what you are looking for.)

http://www.thegamecreators.com/?m=view_product&id=2256

http://forum.thegamecreators.com/?m=forum_view&t=156410&b=5
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 6th Feb 2011 18:45
P.S. I have to correct myself: for images and sounds, you can implement an "archive" with built-in Dark GDK commands and a little programming, since these can be converted to memblocks and from memblocks back to image/sound. You can save several memblocks to a file, or even implement your own file format, as Hassan also layed out. But when it comes to 3D models then it's not so easy.

Login to post a reply

Server time is: 2024-06-23 03:00:13
Your offset time is: 2024-06-23 03:00:13