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

Author Topic: Load from memory/stream help?  (Read 2166 times)

0 Members and 1 Guest are viewing this topic.

Anthony11

  • Newbie
  • *
  • Posts: 38
    • View Profile
Load from memory/stream help?
« on: July 14, 2015, 11:25:05 am »
I created a large file that contains some of the resources I use in my game. How can I load them if I have a length (in bytes) of each file and start position of each of them in a .ini file.

this is what i've got so far (ini is handled via inih plugin):
http://pastebin.com/Qs7E4MVf

example of ini:
p_file1.lua=main.pack
s_file1.lua=0
l_file1.lua=170
p_intro.png=main.pack
s_intro.png=170
l_intro.png=117
p_abc.jpg=main.pack
s_abc.jpg=287
l_abc.jpg=162

p_ = package name
s_ = start location
l_ = length (bytes)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Load from memory/stream help?
« Reply #1 on: July 14, 2015, 11:37:25 am »
Load the file into memory, move the pointer to the starting position of your file, pass in the pointer and the size to the loadFromMemory function.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Anthony11

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Load from memory/stream help?
« Reply #2 on: July 14, 2015, 11:39:40 am »
the problem is that i don't know how to do that  :(

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
AW: Load from memory/stream help?
« Reply #3 on: July 14, 2015, 11:41:35 am »
Then this is a simple C++ problem for which you'll find a lot of solutions on the web.

Try to search for "open file C++" and "pointer arithmetic".
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Anthony11

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Load from memory/stream help?
« Reply #4 on: July 14, 2015, 12:20:25 pm »
        // ......
        std::string Pack = defaultLocation;
        Pack.append(reader.Get("", x1.c_str(), "null"));
        std::string Start = reader.Get("", x2.c_str(), "null");
        std::string Length = reader.Get("", x3.c_str(), "null");
        unsigned long long StartI = ll_from_string(Start);
        unsigned long long LengthI = ll_from_string(Length);
        char *data;
        std::ifstream myfile;
        myfile.open(Pack.c_str());
        myfile.seekg(0, StartI); // here is the error
        myfile.read(&data,LengthI);
        myfile.close();

cannot convert long long int to sd::ios_base seekdir, and i don't even know if i'm doing this right
i really cant figure this out on my own
« Last Edit: July 14, 2015, 12:49:16 pm by Anthony11 »

Anthony11

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Load from memory/stream help?
« Reply #5 on: July 14, 2015, 01:19:18 pm »
Still can't find a solution

Anthony11

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Load from memory/stream help?
« Reply #6 on: July 14, 2015, 04:22:16 pm »
solved finally, no worries, can lock

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Load from memory/stream help?
« Reply #7 on: July 14, 2015, 06:10:44 pm »
solved finally, no worries, can lock

It's good internet manners to add your solution for the next person who has the same issue and finds this topic.

 

anything