Author Topic: Control object switch is delayed by an arbitrary time  (Read 816 times)

I've no idea why this is happening. Basically, I have a path camera set up to go between a few nodes (which it does), and after pushing all of them back, the player(s) have their control objects set to the path camera object.

The trouble is that there is a strange, irregular delay to the control object being set. This is not a hang, as nothing else in the simulation is slowed or stopped, and when the control object is finally set, the path camera has moved along its path the amount you would expect by that time. There is no point in the script where a schedule would cause this time (i tried making zero-length schedules to see if that would help; it didn't), and there is no obvious pattern to the length of the delay.

The relevant code:
Code: [Select]
function CEPathCamera::EventExecute(%this)
{
if(%this.type !$= "PathCamera" || %this.parent.viewers == 0)
return false;

%group = %this.getSpawnedObject("NodeGroup");

%cam = %this.getSpawnedObject("PathCamera");
if(isObject(%cam))
%cam.delete();

%cam = %this.PCCreateCam();

if(!isObject(%cam))
return false;

%this.PCSortNodes();
%cam.reset();
%cam.pushBack(%cam.getTransform(), 1.0, "Normal", "Linear"); //this was added to try and fix, didn't work
for(%i = 1; %i < %group.nodes; %i++)
{
%node = %group.node[%i];
%pos = getField(%node, 0);
%trans = getField(%node, 1);
%type = getField(%node, 2);
%path = getField(%node, 3);
%lastNode = %group.node[%i - 1];
if(%lastNode !$= "")
{
%lastPos = getField(%lastNode, 0);
%lastTrans = getField(%lastNode, 1);
%posA = getWords(%trans, 0, 2);
%posB = getWords(%lastTrans, 0, 2);
%sec = (%pos - %lastPos) / 1000;
%speed = getPathCamSpeed(%posA, %posB, %sec);
}
else
%speed = 1.0;
%cam.pushBack(%trans, %speed, %type, %path);
echo(%trans TAB %speed TAB %type TAB %path);
}
%this.parent.schedule(0, setControlObject, %cam);
//localClientConnection.setControlObject(%cam);
//%cam.schedule(0, setTarget, 1.0);
%cam.schedule(0, setState, "forward");
return true;
}

tl;dr: Path camera works, but the control object switch is delayed for no apparent reason with no obvious pattern to the delay length.

EDIT:
This is a more concise but fundamentally identical implementation of this that I used to test the idea. It's obviously not pretty or anything, but it worked properly.
Code: [Select]
function PathCamera::testmovie(%this, %stack, %s)
{
cancel(%stack.unhide);
%stack.HideCamShapes(1);
%ct = %stack.getCount();
%this.reset();
%this.setState("forward");
%this.pushBack(%stack.getObject(0).getTransform(), getPathCamSpeed(%this.getPosition(), %stack.getObject(0).getPosition(), 0.1), "Normal", "Linear");
for(%i = 1; %i < %ct; %i++)
%this.pushBack(%stack.getObject(%i).getTransform(), getPathCamSpeed(%this.getPosition(), %stack.getObject(%i).getPosition(), %s), "Normal", "Linear");
%len = (%ct - 1) * (%s * 1000);
%stack.unhide = %stack.schedule(%len, HideCamShapes, 0);
}
« Last Edit: January 28, 2014, 10:41:39 PM by otto-san »

%cam.scopeToClient(%this.parent);
%this.parent.setControlObject(%cam);

%cam.scopeToClient(%this.parent);
%this.parent.setControlObject(%cam);

worked great, thanks. c:

will this break if used for multiple clients?
« Last Edit: January 29, 2014, 12:09:02 PM by otto-san »

You generally shouldn't have more than one client controlling an object, even if you can hackishly get it to work with multiple for a particular object type. If you're going to do that, though, just use %cam.setScopeAlways(); instead.