Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Is there any way to make some files with imgs/snds inside?  (Read 5844 times)

0 Members and 1 Guest are viewing this topic.

newn

  • Guest
Is there any way to make some files with imgs/snds inside?
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Is there any way to make some files with imgs/snds inside?
« Reply #1 on: August 24, 2010, 11:51:25 am »
There's a tutorial with source code about this stuff on the wiki ;)
Laurent Gomila - SFML developer

newn

  • Guest
Is there any way to make some files with imgs/snds inside?
« Reply #2 on: August 24, 2010, 12:37:54 pm »
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...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Is there any way to make some files with imgs/snds inside?
« Reply #3 on: August 24, 2010, 12:43:07 pm »
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
Laurent Gomila - SFML developer

newn

  • Guest
Is there any way to make some files with imgs/snds inside?
« Reply #4 on: August 24, 2010, 12:49:22 pm »
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. :)

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Is there any way to make some files with imgs/snds inside?
« Reply #5 on: August 24, 2010, 01:58:40 pm »
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 ;)
Mindiell
----

newn

  • Guest
Is there any way to make some files with imgs/snds inside?
« Reply #6 on: August 24, 2010, 10:07:45 pm »
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.

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Is there any way to make some files with imgs/snds inside?
« Reply #7 on: August 25, 2010, 09:58:03 am »
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 ;)
Mindiell
----

newn

  • Guest
Is there any way to make some files with imgs/snds inside?
« Reply #8 on: August 25, 2010, 01:01:33 pm »
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:

Code: [Select]

    //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. ;)

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Is there any way to make some files with imgs/snds inside?
« Reply #9 on: August 25, 2010, 01:56:42 pm »
Ok, I created the page, but not the link to it. 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 ? :)
Mindiell
----

newn

  • Guest
Is there any way to make some files with imgs/snds inside?
« Reply #10 on: August 25, 2010, 02:31:35 pm »
Okay, as i understand another part from this place:

Quote
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:

Quote
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.

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Is there any way to make some files with imgs/snds inside?
« Reply #11 on: August 25, 2010, 03:48:01 pm »
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.
Mindiell
----

newn

  • Guest
Is there any way to make some files with imgs/snds inside?
« Reply #12 on: August 25, 2010, 04:33:42 pm »
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:

Quote
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:

Code: [Select]
#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...

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Is there any way to make some files with imgs/snds inside?
« Reply #13 on: August 26, 2010, 06:13:09 am »
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
Code: [Select]
#include <iostream>
#include <vector>
#include "datapack.hpp"


Datapack.hpp
Code: [Select]
#include <string>
#include <vector>


Datapack.cpp
Code: [Select]
#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.
Mindiell
----

newn

  • Guest
Is there any way to make some files with imgs/snds inside?
« Reply #14 on: August 26, 2010, 11:54:37 am »
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.

 

anything