ResourceManager, trigger reload of resource internally?
by Clint S. Brewer · in Torque Game Engine · 07/26/2006 (9:19 am) · 2 replies
Overview: I have a custom Resource that loads its data from a text file and does stuff with it later.
Sometimes the data in the text file is incorrect and it will fail to do that stuff later.
I would like to have a console function that would tell every resource of this type to refresh its data from the changed file again after I fix the data in the file.
Problem:
I register my extension with the resource manager:
and my construct function looks something like so:
So as you see, the text is read from the stream, then used to create the Blah.
What I would like to do is have this text re-read from the stream without destroying the resource pointer if that's possible.
The reason I would like to do this is that I would like the BlahManager to be able to take care of this without having everyone who uses a Blah have to know about it.
Say that Player, ShapeBase, Item, etc all use Blahs. I would like to not have to touch them and still get the functionality of a consoleFunction
//reloadBlahs
// reinitializes the text buffer of all blash in place
reloadBlahs();
I'm not sure how to go about that, it seemed to me that after the resource is created from the stream, it doesn't track where that stream was read from so it could read it again.
I'm probably missing something obvious, and would appreciate the advice of someone experienced working with the resourcemanager.
thanks
Sometimes the data in the text file is incorrect and it will fail to do that stuff later.
I would like to have a console function that would tell every resource of this type to refresh its data from the changed file again after I fix the data in the file.
Problem:
I register my extension with the resource manager:
ResourceManager->registerExtension(".blah", constructBlah);and my construct function looks something like so:
ResourceInstance* constructBlah(Stream& stream)
{
//need to read the entire blah into a text buffer
//then use that to create the BLAH
AssertFatal(stream.hasCapability(Stream::StreamRead), "blah: non-read capable stream passed");
AssertFatal(stream.getStatus() == Stream::Ok, "blah: Error, stream in inconsistent state");
const int MAXBLAH_CHAR_LENGTH = 10000;
char* blahBuffer = new char[MAXBLAH_CHAR_LENGTH];
if(!blahBuffer )
{
Con::errorf("blah: error: Failed to allocate text buffer to read blah ");
return NULL;
}
dMemset(blahBuffer ,0, MAXBLAH_CHAR_LENGTH);
bool success = stream.read(MAXBLAH_CHAR_LENGTH, blahBuffer );
if(!success)
{
delete [] blahBuffer ;
Con::errorf("blah: error: stream.read did not succeed ");
return NULL;
}
else
{
//return the effect
BlahManager::Blah* pBlah = new BlahManager::Win32Blah(blahBuffer );
delete [] blahBuffer ;
return pBlah;
}
}So as you see, the text is read from the stream, then used to create the Blah.
What I would like to do is have this text re-read from the stream without destroying the resource pointer if that's possible.
The reason I would like to do this is that I would like the BlahManager to be able to take care of this without having everyone who uses a Blah have to know about it.
Say that Player, ShapeBase, Item, etc all use Blahs. I would like to not have to touch them and still get the functionality of a consoleFunction
//reloadBlahs
// reinitializes the text buffer of all blash in place
reloadBlahs();
I'm not sure how to go about that, it seemed to me that after the resource is created from the stream, it doesn't track where that stream was read from so it could read it again.
I'm probably missing something obvious, and would appreciate the advice of someone experienced working with the resourcemanager.
thanks
About the author
Recent Threads
#2
ResourceManager->reloadResourcesOfType("*.blah");
that would just go through and reinit all the internal resource objects of type, leaving the instances alone.
07/26/2006 (9:44 am)
In the end I'd love to have ResourceManager have a function like:ResourceManager->reloadResourcesOfType("*.blah");
that would just go through and reinit all the internal resource objects of type, leaving the instances alone.
Torque Owner Clint S. Brewer
ResourceInstance * ResManager::loadInstance (ResourceObject * obj, bool computeCRC)
so lets see, my ResourceInstance has mSourceResource which is the object I need to send in, which has the name, which was used in the call to load....
so once I have loaded a resource...with
then I could possibly later do something like:
hmm no this doesn't seem quite right, now I will be making new instances which isn't exactly what I want.
maybe I shuold have a custom reloadBlah func that does basically what resmanager does soemthing like:
Stream *stream = ResManager::openStream (mBlah.mSourceResource); if (!stream) return NULL; //LOAD THE TEXT BUFFER FROM THE STREAM HERE // POSSIBLY HAVE A RELOAD FUNCTION IN ADDITION TO A CREATE FUNCTION mBlah.reloadText( stream);