Game Development Community

Adding resources during runtime

by Orion Elenzil · in Torque Game Engine · 09/17/2004 (9:20 am) · 10 replies

S'pose i want to add a brand-new DTS, interior, or just texture to the scene
while the game is running. For example say i just downloaded some nice
terrain overlay data from a real-world GIS server, and would like to display
it in a HUD without exiting the game at all.

Say just single player mode for simplicity.

Does this sound like a pretty major mod to the resource manager,
or something fairly reasonable ?

I'm hoping that Claude-Alain's binaryfile transferring resource
will have some clues in this direction! :D

#1
09/17/2004 (9:26 am)
Weren't you asking the same thing here?

Bitmaps and such will work without modifications (and thus your HUD) but interiors and objects will need modifications, I believe.
#2
09/17/2004 (9:32 am)
If the engine creates the file then the resource manager will have access to it immediatly. If the file is created outside the engine, by a text editor, graphics program.... or download, it will not be available as the resource manager takes a snapshot of the directory structure at runtime.

To get around this you can do the following.

setModPath(getModPath()); (NOTE: Check the commands as I may have left off an s [ie. setModPaths()])

after that any text, image, dts, etc. added outside the engine will now be available.
#3
09/17/2004 (9:57 am)
Posts while i was replying!

@stefan - yes, i was [trying to] ask pretty much the same thing,
but i know a bit more now and thought i'd rephrase.
thanks for the encouragement about bitmaps,
i suspect that will be the main thing we're after anyhow.

@harold - thanks! this sounds like it may do the trick.
sounds like that should be done each time there's a new file in the tree.

also, i found this, which at least didn't complain during initial trials:
resManager.add(const char* name, ResourceInstance *addInstance, bool extraLock = false)

strangely, i notice that only audio resources are currently going thru that routine in the starter.fps.
#4
05/17/2005 (6:33 pm)
This post is very old but i did a search for setModPaths and found this ;).

Here while the game is runing I put a new file (ex:DIF file) into interior folder then from console I did setModPaths(getModPath()); (did the same thing in a script and execute that script through concole) and finally I re-execute editor.cs to see if I can get the new item in interiors tree (in f11/f4 mode). But no luck...

anybody has comments or know where i'm wrong at?

regards,
#5
12/22/2005 (11:43 am)
Edit: oh, even the previous post is pretty old.
oh well, i think this is pretty useful anyhow.


You have to refresh the tree view.
The tree view is a named object, which name is "creator",

so the following does it fairly nicely:

setModPaths(getModPaths()); creator.init();

This would make a really convenient button somewhere..
#6
09/05/2007 (8:30 am)
@Orion: How you doing man. Been a long time on this thread, but did you ever implement the resManager.add(const char* name, ResourceInstance *addInstance, bool extraLock = false) function to dynamically load .dts or .dif into game?
I'm very interested in this and would love to hear from you.
#7
09/05/2007 (8:59 am)
Yo. yes actually. the following was implemented by Lateral Punk. i think it should drop right into stock TGE, but it might be relying on other mods we've made, so might need some tweaking.
resManager.cc
bool ResManager::addFile(const char *fileName)
{
   if (!fileName)
      return false;
   StringTableEntry path, file;
   getPaths (fileName, path, file);
   ResourceObject *ret = dictionary.find (path, file);
   if(!ret)
   {
      // If we couldn't find the file in the resource list (generated
      // by setting the modPaths) then try to load it directly
      if (Platform::isFile(fileName))
      {
         ret = createResource (path, file);
         dictionary.pushBehind (ret, ResourceObject::File);

         ret->flags = ResourceObject::File;
         ret->fileOffset = 0;

         S32 fileSize = Platform::getFileSize(fileName);
         ret->fileSize = fileSize;
         ret->compressedFileSize = fileSize;

         return ret;
      }
      fileIsMissing(fileName);
   }
   return (bool)ret;
}

bool ResManager::removeFile(const char *fileName)
{

   if (locateFile(fileName))
   {
      ResourceObject *resObj = find(fileName);
      if (resObj)
      {
         freeResource(resObj);
      }
      return true;
   }

   return false;
}
and later
ConsoleFunction( addFile, bool, 2, 2, "(string path) - Adds file to the Resource Manager")
{
   return ResourceManager->addFile(argv[1]);
}

ConsoleFunction( removeFile, bool, 2, 2, "(string path) - Removes file from the Resource Manager.  Not from the filesystem!")
{
   return ResourceManager->removeFile(argv[1]);
}
#8
10/08/2007 (9:40 am)
@Orion: Thanks for the code snippet. I plan on implementing it soon and will let you know. Sorry it took me so long to respond. I've been moving slow, trying to recover from too much business traveling and other projects I am trying to multi-task. I wear many hats here and get way too busy.
#9
10/10/2007 (12:10 pm)
@Orion: I am looking at the source file resManager.cc in and the header files for 1.5.2 with AFX but they have an
//------------------------------------------------------------------------------
// Add resource constructed outside the manager

bool ResManager::add (const char *name, ResourceInstance * addInstance, bool extraLock)
function already in the class and am wondering if anyone knows how it will affect this. I noticed it doesn't have a console method affiliated with it. Just wondering if anyone else ran into this because I really want to try it out but don't want to reinvent the process.
#10
10/10/2007 (1:39 pm)
I added the above code snippet to TGE 1.5.2 with AFX and only had to make 1 change in the removeFile function. The first line which reads:
if (locateFile(fileName))
needs to be replaced with:
if (find(fileName))   // searches the hash list for the filename and returns it's object if found, otherwise NULL
Now off to the testing. Just wanted to add this note while I remembered.