Mission Saving, & cleaning out the junk from the .mis file
by TerroX · in Torque Game Engine · 08/25/2006 (1:56 am) · 6 replies
How does everyone else handle your mission editor output files? (.mis files)
For the last few years we have been just cleaning out all the unnecessary entries by hand, but I am sure that this problem is common enough to warrant some kind of standard tool. I am getting pretty tired of teach every new mapper that they need to do extra work on their output fiels after hitting save.
I am talking about the triggers, skintags and all the other object tags attached to ingame objects during gameplay (different per game) - that get included in the .mis file entries at export and can cause problems if they are read back in (usually the engine is set up to clean bad stuff off just in case this happens).
For the last few years we have been just cleaning out all the unnecessary entries by hand, but I am sure that this problem is common enough to warrant some kind of standard tool. I am getting pretty tired of teach every new mapper that they need to do extra work on their output fiels after hitting save.
I am talking about the triggers, skintags and all the other object tags attached to ingame objects during gameplay (different per game) - that get included in the .mis file entries at export and can cause problems if they are read back in (usually the engine is set up to clean bad stuff off just in case this happens).
#2
09/11/2006 (8:11 am)
The only thing we have to do by hand is re-shuffle things back in order. Does get annoying when every time someone does some work on a map, and saves it, I have to open the .mis file by hand and re-structure everything. I never bothered complaining about it, just another quirk in Torque I've grown to accept.
#3
but it is a thing to watch out for when writing script code.
basically, there's two ways (i know of) stuff sneaks into your mission file and .guis:
1. creating a new top-level object and not adding it to MissionCleanup.
ie be sure you do this:
2. as you mention, creating an object (or field) and attaching it to another object.
this is a little more tricky to work-around, and in that case i use something like this:
note, gSetField()/gGetField() do not work if your sub-object is an array. If that's the case, let me know and there's another method i use which handles arrays as well.
as for getting these objects out of the mission file once they're in it,
it's more or less a job for good old hand-labour as far as i know.
maybe someone has a better method tho ?
i suppose you could write a function called like "CleanSet" or something which would take a SimSet as input and recursively walk down it removing objects of offending type, and then call CleanSet(MissionGroup) before saving the mission.
09/11/2006 (8:13 am)
In the various demos this shouldn't be happening,but it is a thing to watch out for when writing script code.
basically, there's two ways (i know of) stuff sneaks into your mission file and .guis:
1. creating a new top-level object and not adding it to MissionCleanup.
ie be sure you do this:
%foo = new ScriptObject(); if (isObject(MissionCleanup)) MissionCleanup.add(%foo);
2. as you mention, creating an object (or field) and attaching it to another object.
this is a little more tricky to work-around, and in that case i use something like this:
// use these when you want to add a field to an object in script,
// but don't want it saved out in the .mission or .gui file.
// so,
// instead of %object.fieldName = %value, use gSetField(%object, fieldName, %value)
// and instead of %value = %object.fieldName, use %value = gGetField(%object, fieldName)
function gSetField(%object, %name, %value)
{
$gGlobalFields[%object.getID(), %name] = %value;
}
function gGetField(%object, %name)
{
return $gGlobalFields[%object.getID(), %name];
}note, gSetField()/gGetField() do not work if your sub-object is an array. If that's the case, let me know and there's another method i use which handles arrays as well.
as for getting these objects out of the mission file once they're in it,
it's more or less a job for good old hand-labour as far as i know.
maybe someone has a better method tho ?
i suppose you could write a function called like "CleanSet" or something which would take a SimSet as input and recursively walk down it removing objects of offending type, and then call CleanSet(MissionGroup) before saving the mission.
#4
09/11/2006 (10:33 am)
A third work-around would be to use a separate mod for mission editing, or a flag on your current game that doesn't actually create any game-specific objects. I'd probably go for the separate mod approach.
#5
@Orion: thanks for the MissionCleanup trick, I didn't know that. How does the $gGlobalFields work? I could not find any occurrence of the string "gGlobalFields" neither in the codebase nor in the scriptbase...
09/14/2006 (1:32 am)
One thing that I found very useful is to hack function SimFieldDictionary::writeFields() so that fields are always sorted before being written. This is an operation that occurs only in the editor, so the game is unaffected by the overhead. With this trick you can finally get diffs of versioned .mis files without going crazy. The change in the code is extremely simple, because function SimFieldDictionary::printFields() just few lines below does sort! Just cut & paste from that.@Orion: thanks for the MissionCleanup trick, I didn't know that. How does the $gGlobalFields work? I could not find any occurrence of the string "gGlobalFields" neither in the codebase nor in the scriptbase...
#6
You can't find it because it doesn't exist. Orion suggested you stored custom fields in global variables (using the object's IDs for array indexing) instead of on the objects themselves. Torquescript "arrays" are actually a handy way for building dynamic variable names.
When you do this:
You're actually accessing this variable:
Numbers are appended to the "array" name, and strings are appended with underscores. So, you can use an object's ghost ID to index a global "array", and keep your object free from undesired fields.
09/14/2006 (10:47 am)
Quote:
How does the $gGlobalFields work? I could not find any occurrence of the string "gGlobalFields" neither in the codebase nor in the scriptbase...
You can't find it because it doesn't exist. Orion suggested you stored custom fields in global variables (using the object's IDs for array indexing) instead of on the objects themselves. Torquescript "arrays" are actually a handy way for building dynamic variable names.
When you do this:
$gFoo[1234, "something"] = "bar";
You're actually accessing this variable:
$gFoo1234_something = "bar";
Numbers are appended to the "array" name, and strings are appended with underscores. So, you can use an object's ghost ID to index a global "array", and keep your object free from undesired fields.
Torque Owner TerroX