SFML community forums

Help => System => Topic started by: Bizarreofnature on February 05, 2018, 10:27:44 pm

Title: Easy way to load files from zip
Post by: Bizarreofnature on February 05, 2018, 10:27:44 pm
Hello!

When it comes to streams and stuff im kinda helpless.

Im searching for an easy way to load for example .tga files from a zip file.

Forgive me for being such a noob.
Ive googled hours and checked every single thread in subforum System.
Without success of course.

Thanks in advance!

Best regards,
Bizarreofnature
Title: Re: Easy way to load files from zip
Post by: FRex on February 06, 2018, 06:32:44 am
See https://icculus.org/physfs/ and https://github.com/SFML/SFML/wiki/Source:-PhysicsFS-Input-Stream

The code on wiki is mine from a few years ago and a bit bad. I might rewrite it today. Done.
Title: Re: Easy way to load files from zip
Post by: Bizarreofnature on February 08, 2018, 03:55:38 pm
Sorry for late respond and thank you very much for your help. This is awesome. So easy.

But I have a problem. I cant find this file:

Quote
#include "PhysFsStream.hpp"
Title: Re: Easy way to load files from zip
Post by: FRex on February 08, 2018, 03:58:36 pm
The wiki page has 3 files in it: PhysFsStream.hpp, PhysFsStream.cpp and example.cpp. You should create all three and copy the contents from it. You'll also need to get physfs library itself from somewhere else too (easiest is to build it yourself, since it doesn't provide prebuilt packages for a while now).
Title: Re: Easy way to load files from zip
Post by: Bizarreofnature on February 08, 2018, 07:32:38 pm
You'll also need to get physfs library itself from somewhere else too (easiest is to build it yourself, since it doesn't provide prebuilt packages for a while now).

And this is the point where im clueless again.
I downloaded CMake but i have no idea how to build these libraries.

Is there any tutorial how to build physicsfs?
Title: Re: Easy way to load files from zip
Post by: Bizarreofnature on February 08, 2018, 07:52:51 pm
Its ok i got it working.. thanks!  :)

Althoug id love to know how to create the lib files..
Title: Re: Easy way to load files from zip
Post by: FRex on February 08, 2018, 09:01:46 pm
How did you get it to work without building it?
Title: Re: Easy way to load files from zip
Post by: Bizarreofnature on February 08, 2018, 09:04:56 pm
By including all files to my project... which is ugly and noobish.
Id really like to make libs and include them the right way.
Title: Re: Easy way to load files from zip
Post by: FRex on February 08, 2018, 09:14:13 pm
Just open CMake GUI, drag CMakeLists.txt into it and then pick your compiler and generate files for it (for VS it'll be a sln with few projects).
Title: Re: Easy way to load files from zip
Post by: Bizarreofnature on February 08, 2018, 10:13:03 pm
Thank you.

So Ive created physfs.lib and included it to my project.

And now:

Quote
PHYSFS_AddToSearchPath ("Game.zip", 1);

is not defined.  :(
Title: Re: Easy way to load files from zip
Post by: FRex on February 08, 2018, 10:17:08 pm
Once you have the lib and headers the process to use them is the same as with SFML.
Title: Re: Easy way to load files from zip
Post by: Bizarreofnature on February 08, 2018, 10:26:03 pm
I know.. but for some reason it doesnt work. Let me write it down:

Quote
#include <PhysicsFS/physfs.h>

this is how i include it to my project.

Quote
PhysicsFS/lib/

the place of the lib files

Quote
PhysicsFS/include/PhysicsFS/

place of my headers

And the vs config is EXACTLY the same as the sfml one.
Title: Re: Easy way to load files from zip
Post by: FRex on February 08, 2018, 10:27:33 pm
The lib should also be added to AdditionalDependencies in linker input settings.
Title: Re: Easy way to load files from zip
Post by: Bizarreofnature on February 08, 2018, 10:37:05 pm
Yes i did, however its not working.
I wonder.. is it really only one single lib? i have a normal one and a static one.
Title: Re: Easy way to load files from zip
Post by: FRex on February 08, 2018, 10:38:52 pm
Yes, it's a single library. It just can be built as dynamic or static but you need one one of them.
Title: Re: Easy way to load files from zip
Post by: Bizarreofnature on February 08, 2018, 10:42:57 pm
Quote
C:\Users\*\Desktop\SFML32 - Space Wars\PhysicsFS\include

Quote
C:\Users\*\Desktop\SFML32 - Space Wars\PhysicsFS\lib

Quote
physfs.lib
Title: Re: Easy way to load files from zip
Post by: FRex on February 08, 2018, 10:44:23 pm
What is the actual error you are even getting?
Title: Re: Easy way to load files from zip
Post by: Bizarreofnature on February 08, 2018, 10:47:05 pm
Quote
identifier ""PHYSFS_AddToSearchPath"" is undefined

btw, for example the following works without problems:

Quote
PHYSFS_init (0);
Title: Re: Easy way to load files from zip
Post by: FRex on February 08, 2018, 10:50:15 pm
It's add, not Add. Where did you take the uppercase name from?

From this maybe? https://icculus.org/physfs/physfstut.txt
Title: Re: Easy way to load files from zip
Post by: Bizarreofnature on February 08, 2018, 10:51:34 pm
It's add, not Add. Where did you take the uppercase name from?

IT WORKS! HA! Thank you so much  ;D

I got it from the tutorial of physicsfs website.

Edit: yes
Title: Re: Easy way to load files from zip
Post by: FRex on February 08, 2018, 10:59:50 pm
I've sent Ryan Gordon an email about that typo too since it has such time wasting potential. The tutorial code on the SFML wiki is correct though.
Title: Re: Easy way to load files from zip
Post by: Bizarreofnature on February 09, 2018, 05:21:40 pm
So one more question. Since i dont understand the tutorial completely, i tried to make it on my own.

Quote
PHYSFS_init (0);

   PHYSFS_addToSearchPath ("Game.zip", 1);

   PHYSFS_file* myfile = PHYSFS_openRead ("Game/Sprites/Title.tga");

        sf::Texture tex;
   tex.loadFromStream(??);

   PHYSFS_close(myfile);

   PHYSFS_deinit ();

how do i load myfile to loadfromstream?  :(
Title: Re: Easy way to load files from zip
Post by: FRex on February 09, 2018, 05:26:17 pm
You need a https://www.sfml-dev.org/documentation/2.4.2/classsf_1_1InputStream.php

Like the one from the wiki: https://github.com/SFML/SFML/wiki/Source:-PhysicsFS-Input-Stream

Or you can load entire file into memory and then loadFromMemory.
Title: Re: Easy way to load files from zip
Post by: Bizarreofnature on February 09, 2018, 05:43:41 pm
Ok thanks. Ill try my best (looks difficult).

In fact, this is the only thing i dont understand:

Quote
tex.loadFromStream(wonderfullStream);

What exactly is returned there? An entire class + sub class?
Title: Re: Easy way to load files from zip
Post by: FRex on February 09, 2018, 05:50:38 pm
A stream that was created few lines before is passed by reference. It's a normal C++ thing with virtual methods, etc. All the load and open functions in SFML also return a bool to say if it worked or not.
Title: Re: Easy way to load files from zip
Post by: Bizarreofnature on February 13, 2018, 05:01:15 pm
Well, thank you very much. Its still a bit complicated to me and i guess i will make this at very last of my game.
I guess my c++ is not good enough yet to understand this  :(