refactor: Simplify by combining SafeSendControlsToScripts() from fe8e835 into SendControlsToScripts() (instead of SendControlToScripts()).

0.7.4.1
Justin Clark-Casey (justincc) 2012-04-30 17:33:08 +01:00
parent fe8e835bfc
commit d0598c63f3
1 changed files with 75 additions and 73 deletions

View File

@ -1336,7 +1336,7 @@ namespace OpenSim.Region.Framework.Scenes
PhysicsActor actor = PhysicsActor; PhysicsActor actor = PhysicsActor;
if (actor == null) if (actor == null)
{ {
SafeSendControlsToScripts(flagsForScripts); SendControlsToScripts(flagsForScripts);
return; return;
} }
@ -1513,25 +1513,12 @@ namespace OpenSim.Region.Framework.Scenes
if (update_movementflag && ParentID == 0) if (update_movementflag && ParentID == 0)
Animator.UpdateMovementAnimations(); Animator.UpdateMovementAnimations();
SafeSendControlsToScripts(flagsForScripts); SendControlsToScripts(flagsForScripts);
} }
m_scene.EventManager.TriggerOnClientMovement(this); m_scene.EventManager.TriggerOnClientMovement(this);
} }
private void SafeSendControlsToScripts(uint flagsForScripts)
{
lock (scriptedcontrols)
{
if (scriptedcontrols.Count > 0)
{
// Notify the scripts only after calling UpdateMovementAnimations(), so that if a script
// (e.g., a walking script) checks which animation is active it will be the correct animation.
SendControlToScripts(flagsForScripts);
}
}
}
/// <summary> /// <summary>
/// Calculate an update to move the presence to the set target. /// Calculate an update to move the presence to the set target.
/// </summary> /// </summary>
@ -3687,68 +3674,82 @@ namespace OpenSim.Region.Framework.Scenes
} }
} }
internal void SendControlToScripts(uint flags) private void SendControlsToScripts(uint flags)
{ {
ScriptControlled allflags = ScriptControlled.CONTROL_ZERO; // Notify the scripts only after calling UpdateMovementAnimations(), so that if a script
// (e.g., a walking script) checks which animation is active it will be the correct animation.
if (MouseDown) lock (scriptedcontrols)
{ {
allflags = LastCommands & (ScriptControlled.CONTROL_ML_LBUTTON | ScriptControlled.CONTROL_LBUTTON); if (scriptedcontrols.Count <= 0)
if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP) != 0 || (flags & unchecked((uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_UP)) != 0) return;
ScriptControlled allflags = ScriptControlled.CONTROL_ZERO;
if (MouseDown)
{ {
allflags = ScriptControlled.CONTROL_ZERO; allflags = LastCommands & (ScriptControlled.CONTROL_ML_LBUTTON | ScriptControlled.CONTROL_LBUTTON);
if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_UP) != 0 || (flags & unchecked((uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_UP)) != 0)
{
allflags = ScriptControlled.CONTROL_ZERO;
MouseDown = true;
}
}
if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN) != 0)
{
allflags |= ScriptControlled.CONTROL_ML_LBUTTON;
MouseDown = true; MouseDown = true;
} }
}
if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_ML_LBUTTON_DOWN) != 0) if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0)
{ {
allflags |= ScriptControlled.CONTROL_ML_LBUTTON; allflags |= ScriptControlled.CONTROL_LBUTTON;
MouseDown = true; MouseDown = true;
} }
if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0)
{
allflags |= ScriptControlled.CONTROL_LBUTTON;
MouseDown = true;
}
// find all activated controls, whether the scripts are interested in them or not // find all activated controls, whether the scripts are interested in them or not
if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) != 0) if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS) != 0)
{ {
allflags |= ScriptControlled.CONTROL_FWD; allflags |= ScriptControlled.CONTROL_FWD;
} }
if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) != 0)
{ if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG) != 0)
allflags |= ScriptControlled.CONTROL_BACK; {
} allflags |= ScriptControlled.CONTROL_BACK;
if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS) != 0) }
{
allflags |= ScriptControlled.CONTROL_UP; if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_POS) != 0)
} {
if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0) allflags |= ScriptControlled.CONTROL_UP;
{ }
allflags |= ScriptControlled.CONTROL_DOWN;
} if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)
if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) != 0) {
{ allflags |= ScriptControlled.CONTROL_DOWN;
allflags |= ScriptControlled.CONTROL_LEFT; }
}
if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) != 0) if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS) != 0)
{ {
allflags |= ScriptControlled.CONTROL_RIGHT; allflags |= ScriptControlled.CONTROL_LEFT;
} }
if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0)
{ if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG) != 0 || (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG) != 0)
allflags |= ScriptControlled.CONTROL_ROT_RIGHT; {
} allflags |= ScriptControlled.CONTROL_RIGHT;
if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS) != 0) }
{
allflags |= ScriptControlled.CONTROL_ROT_LEFT; if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_NEG) != 0)
} {
// optimization; we have to check per script, but if nothing is pressed and nothing changed, we can skip that allflags |= ScriptControlled.CONTROL_ROT_RIGHT;
if (allflags != ScriptControlled.CONTROL_ZERO || allflags != LastCommands) }
{
lock (scriptedcontrols) if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_YAW_POS) != 0)
{
allflags |= ScriptControlled.CONTROL_ROT_LEFT;
}
// optimization; we have to check per script, but if nothing is pressed and nothing changed, we can skip that
if (allflags != ScriptControlled.CONTROL_ZERO || allflags != LastCommands)
{ {
foreach (KeyValuePair<UUID, ScriptControllers> kvp in scriptedcontrols) foreach (KeyValuePair<UUID, ScriptControllers> kvp in scriptedcontrols)
{ {
@ -3758,6 +3759,7 @@ namespace OpenSim.Region.Framework.Scenes
ScriptControlled localHeld = allflags & scriptControlData.eventControls; // the flags interesting for us ScriptControlled localHeld = allflags & scriptControlData.eventControls; // the flags interesting for us
ScriptControlled localLast = LastCommands & scriptControlData.eventControls; // the activated controls in the last cycle ScriptControlled localLast = LastCommands & scriptControlData.eventControls; // the activated controls in the last cycle
ScriptControlled localChange = localHeld ^ localLast; // the changed bits ScriptControlled localChange = localHeld ^ localLast; // the changed bits
if (localHeld != ScriptControlled.CONTROL_ZERO || localChange != ScriptControlled.CONTROL_ZERO) if (localHeld != ScriptControlled.CONTROL_ZERO || localChange != ScriptControlled.CONTROL_ZERO)
{ {
// only send if still pressed or just changed // only send if still pressed or just changed
@ -3765,9 +3767,9 @@ namespace OpenSim.Region.Framework.Scenes
} }
} }
} }
}
LastCommands = allflags; LastCommands = allflags;
}
} }
internal static AgentManager.ControlFlags RemoveIgnoredControls(AgentManager.ControlFlags flags, ScriptControlled ignored) internal static AgentManager.ControlFlags RemoveIgnoredControls(AgentManager.ControlFlags flags, ScriptControlled ignored)