Swap to a normal camera in the RTS editor
by Martin "Founder" Hoover · in RTS Starter Kit · 11/15/2004 (7:54 pm) · 6 replies
My partner in crime on this project, Ralph "ZOD" DeMicco was a tad bit disgusted with having the RTSCamera in the editor, so he scripted up a way to get the normal torque editor camera in, here it is:
In file common/editor/EditorGui.cs change existing functions to these..
In file common/server/gameConnection.cs
Must add this message to function GameConnection::onConnect somewhere after all the jojn messages
In file starter.RTS/client/scripts/serverConnection.cs
At the top of the function function RTSConnection::initialControlSet(%this),
add the following lines..
Then someplace in starter.RTS/client/scripts/missionDownload.cs
add these callback handlers..
In file common/editor/EditorGui.cs change existing functions to these..
function EditorGui::onWake(%this)
{
//------------------------------------------------------------------
// Because the RTS camera is impossible to work with in the editor,
// we swap it for a standard camera here. We delete all RTS objects.
// Have to use the client ID the server assigns or this = poop
// We capture this ID via a message callback and store it in a global.
%client = $Client::MyClient;
%transform = %client.camera.getTransForm();
%client.camera.setVelocity("0 0 0");
%client.camera = new Camera() {
dataBlock = Observer;
};
MissionCleanup.add(%client.camera);
%client.camera.scopeToClient(%client);
%client.camera.getDataBlock().setMode(%client.camera, "Editor");
%client.camera.setTransform(%transform);
%client.setControlObject(%client.camera);
//------------------------------------------------------------------
MoveMap.push();
EditorMap.push();
%this.setEditor(%this.currentEditor);
}
function EditorGui::onSleep(%this)
{
error("EditorGui::onSleep(" SPC %this.getName() SPC ")");
//------------------------------------------------------------------
// Now we have to swap back to the RTS camera here. We delete the
// standard camera and the game handles the rest. Have to use the
// client ID the server assigns or this = poop
// We capture this ID via a message callback and store it in a global.
%client = $Client::MyClient;
if (isObject(%client.camera))
%client.camera.delete();
%client.camera = new RTSCamera()
{
dataBlock = RTSObserver;
};
MissionCleanup.add( %client.camera );
// Do scoping
%client.camera.scopeToClient(%client);
%client.setControlObject(%client.camera);
//------------------------------------------------------------------
%this.setPrefs();
EditorMap.pop();
MoveMap.pop();
}In file common/server/gameConnection.cs
Must add this message to function GameConnection::onConnect somewhere after all the jojn messages
// Send this player their client ID etc. messageClient(%client, 'MsgYourInfo', "", %client.name, %client);
In file starter.RTS/client/scripts/serverConnection.cs
At the top of the function function RTSConnection::initialControlSet(%this),
add the following lines..
if(isObject(EditorGui))
{
if (Canvas.getContent() == EditorGui.getId())
return;
}Then someplace in starter.RTS/client/scripts/missionDownload.cs
add these callback handlers..
addMessageCallback( 'MsgYourInfo', handleGetMyInfo );
function handleGetMyInfo(%msgType, %msgString, %clientName, %clientId)
{
$Client::MyClient = %clientId;
}
#2
Thanks for posting, it's awesome to see so much great collaboration on the pack so far.
11/16/2004 (3:53 am)
Thanks. Haven't looked at this particular imp yet, but I agree we should get the normal editor camera working. If this kills off the units and then re-spawns them, we'll probably need to fix that before we integrate it with the pack, but it's nice to have a start.Thanks for posting, it's awesome to see so much great collaboration on the pack so far.
#3
11/16/2004 (2:22 pm)
Heh, well our script base has already largely diverged from the starter kit, and this was something he put together real quick to work with the base. Anyway, I looked it over and figured out what to change to keep the units between opening and closing the editor, and edited the posts to reflect.
#4
11/16/2004 (7:36 pm)
This is on my todo list, although I'll probably be trying to solve it a little differently... I'm glad we do have at least one fix up here, though!
#5
11/18/2004 (10:41 am)
Ok, I've put a fix in. alt-c works again. :) The cam does start out under the ground, and you have to be in the editor GUI to control it (the mouse is not bound to actions in the RTS PlayGui). Arrow keys do what WASD would do. But it's working and it gave me a chance to do some other cleanup.
Torque 3D Owner Martin "Founder" Hoover
In file starter.RTS/server/scripts/core/gameConnection.cs replace functions with this..
function RTSConnection::onClientLeaveGame(%this) { if (isObject(%this.camera)) %this.camera.delete(); if (isObject(%this.selection)) %this.selection.delete(); // Delete all the player buildings and units? Sure why not. // You could also turn them over to allies or something here for( %i = 0; %i < %this.units.getCount(); %i++ ) { %unit = %this.units.getObject(%i); // Kind of hacky here RTSUnitData::onDisabled( 0, %unit, 0 ); echo( "Client has disconnected, removing unit " @ %unit ); //%unit.delete(); } // Leaving simsets layin around is not a good idea ;) if (isObject(%client.units)) %client.units.schedule($CorpseTimeoutValue, "delete"); if( isObject( %this.buildings ) ) %this.buildings.delete(); }In file starter.RTS/server/scripts/items/camera.cs wee need to add cases to the camera code
Add this case to function Observer::onTrigger(%this,%obj,%trigger,%state)..
case "Editor": // Do something or nothing, I did nothingAdd this case to function function Observer::setMode(%this,%obj,%mode,%arg1,%arg2,%arg3)..
case "Editor": // Free-flying Editor camera %obj.setFlyMode();I followed his directions and tested it, seems to work just fine. One note though, when you open the editor, it kills off all your little d00ds, then when you return it spawns a fresh set of them.