Models, Harddisk and Memory
by Thomas Bang · in Torque Game Engine · 11/09/2009 (8:34 am) · 4 replies
Example: i have two different datablocks which refer to the same model (also with the same path).
Q1: How often is npc.dts loaded from the harddisk?
Q2: When is npc.dts loaded from the hardisk the first time? When the datablock is created or when the first StaticShape-Object is created which uses the datablock?
Q3: Is it possible to determine if a dts/dif is already loaded into memory or not?
Q4: How often is a model loaded from the harddisk which does not require a datablock like TSStatic and InteriorInstance? Only once?
datablock StaticShapeData(DB1)
{
shapeFile = "game/data/shapes/npc/npc.dts";
};
datablock StaticShapeData(DB2)
{
shapeFile = "game/data/shapes/npc/npc.dts";
};Q1: How often is npc.dts loaded from the harddisk?
Q2: When is npc.dts loaded from the hardisk the first time? When the datablock is created or when the first StaticShape-Object is created which uses the datablock?
Q3: Is it possible to determine if a dts/dif is already loaded into memory or not?
Q4: How often is a model loaded from the harddisk which does not require a datablock like TSStatic and InteriorInstance? Only once?
#2
Q2: The shape is loaded from disk into the Torque Resource Manager when the first datablock that refers to it calls its preload method. This occurs when the datablocks are sent to the client as part of mission loading.
For non-datablock based objects (eg. TSStatic), the model is loaded from disk when the first object that references it is instantiated.
Q3: Yes. In C++, use ResourceManager->find(filename) (see resManager.h). I don't remember if there is a console function to do this, but it would be trivial to write one if needed.
Q4: Whether datablock or not, the Torque Resource Manager ensures there is only a single instance of a model in memory at one time. So if your level contains 100 instances of a particular TSStatic model, it will only be loaded from disk once, and only a single instance of the model data will exist in memory. The Resource Manager may purge this shared copy once all instances of it are no longer in use.
11/20/2009 (3:45 pm)
Q1: See Q4.Q2: The shape is loaded from disk into the Torque Resource Manager when the first datablock that refers to it calls its preload method. This occurs when the datablocks are sent to the client as part of mission loading.
For non-datablock based objects (eg. TSStatic), the model is loaded from disk when the first object that references it is instantiated.
Q3: Yes. In C++, use ResourceManager->find(filename) (see resManager.h). I don't remember if there is a console function to do this, but it would be trivial to write one if needed.
Q4: Whether datablock or not, the Torque Resource Manager ensures there is only a single instance of a model in memory at one time. So if your level contains 100 instances of a particular TSStatic model, it will only be loaded from disk once, and only a single instance of the model data will exist in memory. The Resource Manager may purge this shared copy once all instances of it are no longer in use.
#3
11/21/2009 (3:22 am)
Thank you very much. Your explanation helped me a lot.
#4
Here is the solution:
Open your solution file in VC++ and insert this ConsoleFunction. In my case i inserted this function at the end of "core/resManager.cc".
And here is a example in TorqueScript:
11/21/2009 (5:23 am)
OK, how to find out if a dts or dif is already loaded?Here is the solution:
Open your solution file in VC++ and insert this ConsoleFunction. In my case i inserted this function at the end of "core/resManager.cc".
ConsoleFunction(dwi_isShapeLoaded,bool, 2,2,"is a dts or dif already loaded?")
{
StringTableEntry shapeName = StringTable->insert( argv[1] );
return ResourceManager->findFile(shapeName);
}And here is a example in TorqueScript:
function isShapeLoaded(%val)
{
if (%val)
{
%shape = dwi_isShapeLoaded("game/data/shapes/player/player.dts");
if (%shape == true)
{
echo("Player.dts already loaded");
}
else
{
echo("Player.dts not loaded");
}
%shape = dwi_isShapeLoaded("game/data/interiors/construct/construct.dif");
if (%shape == true)
{
echo("construct.dif already loaded");
}
else
{
echo("construct.dif not loaded");
}
%shape = dwi_isShapeLoaded("game/data/interiors/Raum/room.dif");
if (%shape == true)
{
echo("room.dif already loaded");
}
else
{
echo("room.dif not loaded");
}
}
}
Torque 3D Owner Thomas Bang