Removed traces of old state machine

This commit is contained in:
BaerMitUmlaut 2016-11-07 23:44:33 +01:00
parent 0427814961
commit ba9fc9240c
7 changed files with 3 additions and 163 deletions

View File

@ -1,7 +1,5 @@
PREP(addStateHandler);
PREP(adjustPainLevel);
PREP(createStateMachine);
PREP(getBloodLoss);
PREP(getBloodPressure);
PREP(getBloodVolumeChange);
@ -14,8 +12,6 @@ PREP(isInMedicalVehicle);
PREP(isInStableCondition);
PREP(isMedic);
PREP(isMedicalVehicle);
PREP(stateEvent);
PREP(stateMachine);
// PREP(hasMedicalEnabled);

View File

@ -1,59 +0,0 @@
#include "script_component.hpp"
params ["_stateMachineConfig"];
private _getCode = {
params ["_config", "_attribute"];
private _value = getText (_config >> _attribute);
if (isNil {missionNamespace getVariable _value}) exitWith {
if (_value == "") then {_value = "true"};
systemChat format ["getCode (%1) is returning nil: %3", _attribute, missionnamespace getVariable _value, _value];
diag_log format ["getCode (%1) is returning nil: %3", _attribute, missionnamespace getVariable _value, _value];
compile _value;
};
missionNamespace getVariable _value;
};
private _stateMachine = call CBA_fnc_createNamespace;
private _states = [];
{
private _stateName = configName _x;
private _onState = [_x, "onState"] call _getCode;
private _onEntry = [_x, "onEntry"] call _getCode;
private _onExit = [_x, "onExit"] call _getCode;
// Collect all the transitions for the state
private _transitions = [];
{
private _transitionName = configName _x;
private _targetState = getText (_x >> "targetState");
private _events = getArray (_x >> "events") apply { toLower _x};
private _condition = [_x, "condition"] call _getCode;
private _onTransition = [_x, "onTransition"] call _getCode;
_transitions pushBack [_transitionName, _condition, _events, _onTransition, _targetState];
} forEach ("true" configClasses _x);
_states pushBack [_stateName, _onState, _onEntry, _onExit, _transitions];
} forEach ("true" configClasses _stateMachineConfig);
// Helper method for finding the desired state when linking (See below)
private _getState = {
params ["_stateName"];
private _state = ["Invalid", {}, {}, {}, []];
{
if (_stateName == (_x select 0)) exitWith {_state = _x};
} forEach _states;
_state;
};
_stateMachine setvariable [QGVAR(allStates), _states];
// Now we have collected all the states, link them in transitions so we do not have to look them up on state transitions
{
_x params ["_stateName"];
_stateMachine setvariable [_stateName, _x];
} forEach _states;
_stateMachine;

View File

@ -52,7 +52,7 @@ TRACE_3("ACE_DEBUG",_bloodLoss,_unit getVariable QGVAR(isBleeding),_unit);
if (_bloodLoss > 0) then {
_unit setVariable [QGVAR(bloodloss), _bloodLoss, _syncValues];
[_unit, "TakenInjury"] call FUNC(stateEvent);
[QGVAR(TakenInjury), _unit] call CBA_fnc_localEvent;
if !(_unit getVariable [QGVAR(isBleeding), false]) then {
_unit setVariable [QGVAR(isBleeding), true, true];

View File

@ -81,7 +81,7 @@ if (_isDead) exitWith {};
*/
[_unit, true] call EFUNC(medical_engine,setUnconsciousAnim);
[_unit, "Unconscious", []] call FUNC(stateEvent);
[QGVAR(Unconscious), _unit] call CBA_fnc_localEvent;
["ace_unconscious", [_unit, true]] call CBA_fnc_globalEvent;
// auto wake up

View File

@ -1,52 +0,0 @@
/*
* Author: Glowbal
*
*
* Arguments:
* 0: The Unit <OBJECT>
* 1: Event name <STRING>
* 2: Event Arguments
*
* ReturnValue:
* Name of the state after handling the state event <STRING>
*
* Example:
* [unit, "TakenInjury", []] call ace_medical_stateEvent;
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit", "_event", "_args"];
diag_log format["ace_medical_stateEvent: %1", _this];
_event = toLower _event;
private _unitState = _unit getVariable [QGVAR(state), [CBA_missionTime, GVAR(STATE_MACHINE) getVariable "Default"]];
_unitState params ["_lastTime", "_state"];
_state params ["_name", "_handler", "_onEntry", "_onExit", "_transitions"];
private _newStateName = _name;
{
_x params ["_transitionName", "_condition", "_events", "_onTransition", "_targetStateName"];
if (_event in _events && {[_unit, _event, _args] call _condition}) exitWith {
private _targetState = GVAR(STATE_MACHINE) getVariable _targetStateName;
_targetState params ["_targetStateName", "_targetStateHandler", "_targetStateOnEntry", "_targetStateOnExit", "_targetStateTansitions"];
_newStateName = _targetStateName;
// Handle state leaving
[_unit, _event, _args] call _onExit;
[_unit, _event, _args] call _onTransition;
// Switch the state
_unitState set [1, _targetState];
_unit setvariable [QGVAR(state), _unitState];
// Enter the state
[_unit, _event, _args] call _targetStateOnEntry;
};
} forEach _transitions;
_newStateName;

View File

@ -1,45 +0,0 @@
#include "script_component.hpp"
// Delay between state runs
#define DELAY 1
#define DEFAULT_STATE [0, "Default", {}, {}, {}, []]
GVAR(monitoredUnitsList) = [];
GVAR(monitoredUnitsListIsSorted) = false;
[{
params ["_args", "_pfhId"];
if (!GVAR(monitoredUnitsListIsSorted)) then {
GVAR(monitoredUnitsList) sort true;
GVAR(monitoredUnitsListIsSorted) = true;
};
private _delete = false;
private _exit = false;
{
_x params ["_unit"];
if (!isNull _unit && alive _unit) then {
private _unitState = _unit getVariable [QGVAR(state), [-1, DEFAULT_STATE]];
_unitState params ["_lastTime", "_state"];
if (CBA_missionTime - _lastTime < DELAY) exitWith { _exit = true; };
_state params ["_name", "_handler", "_onEntry", "_onExit", "_transitions"];
_unitState set [0, CBA_missionTime];
_unit setvariable [QGVAR(state), _unitState];
[_unit, _name, _lastTime] call _handler;
} else {
_delete = true;
GVAR(monitoredUnitsList) set [_forEachIndex, objNull];
};
if (_exit) exitWith {};
} forEach GVAR(monitoredUnitsList);
if (_delete) then {
GVAR(monitoredUnitsList) = GVAR(monitoredUnitsList) - [objNull];
};
}, 0, []] call CBA_fnc_addPerFrameHandler;

View File

@ -140,6 +140,6 @@ if ((CBA_missionTime - _startingTime) >= _minWaitingTime) exitWith {
TRACE_2("ACE_DEBUG_Unconscious_Temp knock outs",_unit, [_unit] call FUNC(getUnconsciousCondition));
if (!([_unit] call FUNC(getUnconsciousCondition))) then {
//_unit setVariable ["ACE_isUnconscious", false, true];
[_unit, "MinUnconsciousTimer", []] call FUNC(stateEvent);
[QGVAR(MinUnconsciousTimer), _unit] call CBA_fnc_localEvent;
};
};