GetMesh() with pointer instead of strings

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Lunacore
Posts: 18
Joined: Sun May 30, 2010 4:01 pm
Location: Berlin (Germany)

GetMesh() with pointer instead of strings

Post by Lunacore »

GetMesh() everytime uses simple paths to load meshs from the harddrive.

Code: Select all

IAnimatedMesh* Player = smgr->getMesh("./models/test.x");
I encoded my meshs and other files and saved it to my harddrive. In my game I decode them and save them in temporary files. Now the temporary files contain my original meshs, and doesn't save it to my harddrive, so it's hard to get them. Only the pointer shows to them. But how could I load my decoded meshs from my RAM with GetMesh() and these pointers?

Code: Select all

FILE* FileDecode(char Input[])
{
    FILE* tempData = tmpfile();
    ...
    return tempData;
}

int main()
{
    ...
    IAnimatedMesh* Player = smgr->getMesh(FileDecode("./models/test.x.encoded"));
    ...
}
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Use the smgr->getMesh (io::IReadFile*) method. You can create the IReadFile from a memory address using io::createMemoryReadFile
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Lunacore
Posts: 18
Joined: Sun May 30, 2010 4:01 pm
Location: Berlin (Germany)

Post by Lunacore »

Okay, I have searched for createMemoryReadFile and it really seems to be a solution. But why do I need "const path & fileName"?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

to identify the created mesh, it's like the name of the mesh... ;)
it must not be a path, just a unique name to identify the mesh... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Lunacore
Posts: 18
Joined: Sun May 30, 2010 4:01 pm
Location: Berlin (Germany)

Post by Lunacore »

By using createMemoryReadFile I get another problem with this example code:

Code: Select all

    FILE* test = fopen("./Models/Figur.ms3d","rb"); //first file on harddrive
    FILE* test2 = tmpfile(); //second file on memory
    //get filesize 
      fseek(test, 0, SEEK_END); int FileSize=ftell(test); fseek(test, 0, SEEK_SET);
    //copy first file into second file
      for(int i=0;i<FileSize;i++) fputc(fgetc(test),test2);
      fclose(test); //close first file
    
    //load second file from memory
      IReadFile* tmpModel = device->getFileSystem()->createMemoryReadFile(test2,FileSize,L"test.ms3d", false);
      IAnimatedMesh* MeshModel = smgr->getMesh(tmpModel); //here the application crashed
      IAnimatedMeshSceneNode* Mesh = smgr->addAnimatedMeshSceneNode(MeshModel); //he doesn't reach this point
The application crashed in function getMesh. How can this happened?
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Actually this sounds more like you want to use a fileArchive. check the archive interface if that would make your life simpler.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Lunacore
Posts: 18
Joined: Sun May 30, 2010 4:01 pm
Location: Berlin (Germany)

Post by Lunacore »

No, i don't want to use a FileArchive like *.zip or others. Just the single files. The code was only an example and has nothing to do with my intention.
I only try to load a file into the memory and use it from there and not from my harddrive. The code shown above should realize this, but it doesn't seem to work and I can't see, why...
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Post by Radikalizm »

Try using the interface irrlicht provides for loading files instead of using the standard C stream functions
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Lunacore wrote:No, i don't want to use a FileArchive like *.zip or others. Just the single files. The code was only an example and has nothing to do with my intention.
I only try to load a file into the memory and use it from there and not from my harddrive. The code shown above should realize this, but it doesn't seem to work and I can't see, why...
Well you are probably loading the file from the harddrive at somepoint or from a server doesn't matter.
The IArchive interface can make it seamless for you so that you don't have to do this tricky stuff when calling get mesh.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Lunacore wrote:

Code: Select all

    FILE* test2 = tmpfile(); //second file on memory
...

    //load second file from memory
      IReadFile* tmpModel = device->getFileSystem()->createMemoryReadFile(test2,FileSize,L"test.ms3d", false);
How do you expect this to work?
createMemoryReadFile() wants the data, not a pointer to a file...
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Lunacore
Posts: 18
Joined: Sun May 30, 2010 4:01 pm
Location: Berlin (Germany)

Post by Lunacore »

But the documentation of createMemoryReadFile shows
virtual IReadFile* irr::io::IFileSystem::createMemoryReadFile ( void * memory,
s32 len,
const path & fileName,
bool deleteMemoryWhenDropped = false
)
memory,: A pointer to the start of the file in memory
So I use the pointer of the temporary file from the memory. Is this wrong?
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

yeah that is wrong. FILE is a pointer to the files io. its not the file in memory its just an interface to the file. you have to load the file completly into memory to use that function.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Post Reply