SFML community forums
Help => General => Topic started by: newn on August 24, 2010, 09:50:08 am
-
Hi everyone. I would like to ask, that if there any way to make and use such thing, as a one big data file, with all the data inside, instead of small data files - images, sounds? And if there is, how can i use such a thing? Overall, there would be only one file, so i bet, i should define it different too.
-
There's a tutorial with source code about this stuff on the wiki ;)
-
Ummm, a lesson - don't post, when talking with a group of people trough skype, lol...
Okay, well, i don't see any similar stuff on http://www.sfml-dev.org/wiki/en/tutorials. :/ There's tutorials for windows, screens, images folder and fps without a font...
-
Indeed, the tutorial I was talking about is in the french part of the wiki :?
At least you can still get the source code:
http://www.sfml-dev.org/wiki/fr/tutoriels/formatdat
You also have this one, for loading files from a zip archive:
http://www.sfml-dev.org/wiki/en/sources/ziploader
-
Ah, thanks. I'll try to figure it out in half an hour or an hour, have to do something.
And trough a quick look trough the code, it seems something a little bit similar to Allegro's buffers and .dat files... Except it's .zip over here, if i'm correct. Kinda strange though, using a .zip file for images, hehe. If i'm correct again- haven't investigated that much yet, i'm in a hurry... Kinda.
Anyway, i'll post something, if i have much trouble, thanks for help. :)
-
I did the one without the .zip thing (all ressources in one big .DAT file) in French, I can translate it in English (in fact I had to somedays, but I certainly forgot). If you have any question, ask questions ;)
-
Ah, yes, i found the .dat file. It's better, i've used them in Allegro. Better, that users won't be able to access the images and sounds so easily. ;)
Anyway, i've read the source code, but i definently don't understand something (don't forget that i'm a newbie. :/):
Seems like i need to modify parts of the code from the upper snippets, somehow, and add them as functions to the int main() given at the bottom. I think, that i need to create a buffer somehow, but the code's a little bit confusing for my knowledge. Because accessing the buffer is quite easy, just like images or sounds, except with little bit more stuff, which isn't hard to figure out.
Anyway, could you give some... advice, on how to create the buffer, or something like that? Because i'm really confused at the moment, on how to do that...
Thanks.
-
Well... I didn't really understand what you are not understanding :D
By the Way, I translated the tuto in english (bad english for sure). Give me some feedback ;)
-
Hmmm, i cannot still find it in english wiki page.
Anyway, i understand how to open the images, but i don't understand how to declare the buffer.
I understand this in other words:
//Let's read the image file
buffer = read_test.GetFile("test7b.bmp");
if (buffer==NULL)
{
//simple error catch
std::cout<<"Read error"<<std::endl;
return EXIT_FAILURE;
}
//Ok, now we can load the image by using memory instead of a file
i1.LoadFromMemory(buffer, read_test.GetFileSize("test7b.bmp"));
//SFML instructions
s1.SetImage(i1);
Which is the image loading code.
But i do not understand some of the code above, as how to declare the buffer, create it.
As i understand is, that buffer is a chars array, in which the images are stored. But how to make that - i don't know.
Here's what i have:
A program, which allows me to put images into a datafile file and create header file according to that.
So i would basically need to access that with buffer, and load the images to the buffer, and then read the images from the buffer.
Anyway, i don't quite understand how to do all this, even with the code... Don't forget, that i'm still a newbie to programming, compared. ;)
-
Ok, I created the page (http://www.sfml-dev.org/wiki/en/tutorials/formatdat), but not the link to it (http://www.sfml-dev.org/wiki/en/tutorials). It's ok now :)
For your information, buffer is just a pointer : it contains nothing, it is pointing on a certain adress in memory. m_buffer (the buffer of the object) is a pointer too and this one is pointing on nothing (NULL) or on a file (after a call to GetFile). So when you call the GetFile function, your pointer called buffer is just pointing somewhere in the memoy, at the beginning of the file : it is not containing anything !
This is why we have to grab the size of the file too (with the GetSize function) in order to be able to read n bytes from the beginning (buffer) to the end of the fle (buffer + size of the file).
Is it better ? :)
-
Okay, as i understand another part from this place:
At the moment, you must use the Create function to create the .DAT file. This is not very useful, but you don't have to reate one every time once your files are packed. For the tuto, we are not modifying this method.
all these functions above this place is to create the .dat file itself?
And below this:
Good, now we have a .DAT file, we can try to read it. Next functions will be the ones used in your final app.
All functions are for reading the created .dat file, right?
But without modifying it, to have it working, i must do that anyway, and put all that into a header file. And after that "we have a .dat file", put everything into main.cpp, and then just load the images from the datafile.
Am i right about this?
And nice tutorial. ;) I liked it, seems pretty explainful, but still - i lack of knowledge in the c++ overall, so yea.
And i don't know what a vector is yet, lol. I'll google it after i post this messange.
-
A vector is an array (quick and dirt explanation ^^)...
Well my object is containing all the functions needed in order to use it (create OR read). But while creating it you'll have only to use the Create function, if you want to use it (in an other application so), you'll have to use the other functions of the same object.
I thought it was better to put all useful functions in the same object, but the Create function will be useless in your final application, that's sure.
-
Again - i probably do not understand something... Here's quite a bunch of errors i get, when i try to compile the program... I just inserted the .h file and the functions into the .cpp file... Also, when it failed with my code, i've copied the main() code from the tutorial, to check if it's my fault. Didn't worked:
1> Creating "Debug\Ping Pong.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> main.cpp
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(47): error C2079: 'file' uses undefined class 'std::basic_ifstream<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(49): error C2079: 'datfile' uses undefined class 'std::basic_ofstream<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(66): error C2228: left of '.open' must have class/struct/union
1> type is 'int'
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(66): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(66): error C2065: 'in' : undeclared identifier
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(66): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(66): error C2065: 'binary' : undeclared identifier
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(67): error C2228: left of '.is_open' must have class/struct/union
1> type is 'int'
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(74): error C2228: left of '.seekg' must have class/struct/union
1> type is 'int'
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(75): error C2228: left of '.tellg' must have class/struct/union
1> type is 'int'
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(79): error C2228: left of '.close' must have class/struct/union
1> type is 'int'
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(87): error C2039: 'cout' : is not a member of 'std'
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(87): error C2065: 'cout' : undeclared identifier
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(103): error C2228: left of '.open' must have class/struct/union
1> type is 'int'
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(103): error C2027: use of undefined type 'std::basic_ofstream<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(103): error C2065: 'out' : undeclared identifier
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(103): error C2027: use of undefined type 'std::basic_ofstream<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(103): error C2065: 'binary' : undeclared identifier
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(106): error C2228: left of '.write' must have class/struct/union
1> type is 'int'
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(111): error C2228: left of '.write' must have class/struct/union
1> type is 'int'
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(117): error C2228: left of '.open' must have class/struct/union
1> type is 'int'
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(117): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(117): error C2065: 'in' : undeclared identifier
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(117): error C2027: use of undefined type 'std::basic_ifstream<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(117): error C2065: 'binary' : undeclared identifier
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(118): error C2228: left of '.is_open' must have class/struct/union
1> type is 'int'
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(120): error C2228: left of '.seekg' must have class/struct/union
1> type is 'int'
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(121): error C2228: left of '.read' must have class/struct/union
1> type is 'int'
1>d:\development\games\ping pong - console application\ping pong\datafileh.h(121): fatal error C1903: unable to recover from previous error(s); stopping compilation
In the end, i've created a new project, copied functions into datafileh.h file, and then copied other functions and int main() into main.cpp file, included linker stuff and added:
#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>
#include <stdio.h>
#include <time.h>
#include "datafileh.h"
#include <fstream>
#include <iostream>
Then ran, and got the same errors. Hm...
-
Ok, it seems you have some problems :
- file seems to not be accepted by your compiler (try to change the name into fileHandler for example)
- the include are wrong, I use those ones :
Main.cpp
#include <iostream>
#include <vector>
#include "datapack.hpp"
Datapack.hpp
#include <string>
#include <vector>
Datapack.cpp
#include <fstream>
#include <iostream>
#include <string.h>
#include "datapack.hpp"
You shouldn't have the stdio.h nor the time.h, it's old C includes.
-
I've put the code to datafileh.h file and main.cpp files only... No .hpp or two .cpp files. Could you tell me, which part of code i should put where?
P.S. isn't .hpp similar to .h? Just wondering.
-
.C is for C
.cpp is for C++
.h is for C or C++
.hpp could be for C++
BTW, all the code can be in the .h, apart the last code which is for the main.cpp
So, the main.cpp you've got the includes
For the .h you need all the other includes I gave (apart the .h itself for sure)
-
Played a little bit with includes, made the example working.
After that, I've made it working on the main code, and even modified a little bit. The main problem was includes, it seems. :/
Thanks for the great tutorial and explanation. ;) I'll probably will be releasing some version of my game. Of course there's a lot of things to do still, but well, maybe someone will try it and give me some comments on it. :)
So if anyone's interested - check out my blog. ;) Link's in my profile, not sure, if i can post a link in my signature or my posts.
-
Although, i had a little problem loading music files. They've no buffer, and buffer eats memory. Is there any way to put these inside and load them properly, with no intense, HIGH memory and cpu usage?