Skip to content

Commit

Permalink
Merge pull request #469 from CBATeam/compile-final-all-missionnamespa…
Browse files Browse the repository at this point in the history
…ce-functions

compileFinal all missionNamespace functions
  • Loading branch information
Killswitch00 committed Aug 22, 2016
2 parents cf9e3a4 + d4cab9a commit b7be959
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 72 deletions.
1 change: 1 addition & 0 deletions addons/common/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class CfgFunctions {
F_FILEPATH(execNextFrame);
F_FILEPATH(waitAndExecute);
F_FILEPATH(waitUntilAndExecute);
F_FILEPATH(compileFinal);
};

class Ui {
Expand Down
4 changes: 2 additions & 2 deletions addons/common/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ ADDON = false;

CBA_logic = objNull;

FUNC(log) = {
[QFUNC(log), {
diag_log text _this;
_this spawn {
sleep 1;
systemChat _this;
hintC _this;
};
};
}] call CBA_fnc_compileFinal;

// FSM
GVAR(delayless) = QUOTE(PATHTOF(delayless.fsm));
Expand Down
56 changes: 28 additions & 28 deletions addons/common/backwards_comp.sqf
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@

CBA_fnc_createCenter = {
["CBA_fnc_createCenter", {
WARNING('Deprecated function used: CBA_fnc_createCenter');
params ["_side"];
_side
};
}] call CBA_fnc_compileFinal;

CBA_fnc_locked = {
["CBA_fnc_locked", {
WARNING('Deprecated function used: CBA_fnc_locked (new: locked)');
locked _this > 1
};
}] call CBA_fnc_compileFinal;

CBA_fnc_getPistol = {
["CBA_fnc_getPistol", {
WARNING('Deprecated function used: CBA_fnc_getPistol (new: handgunWeapon)');
params [["_unit", objNull, [objNull]]];
handgunWeapon _unit
};
}] call CBA_fnc_compileFinal;

CBA_fnc_systemChat = {
["CBA_fnc_systemChat", {
WARNING('Deprecated function used: CBA_fnc_systemChat (new: systemChat)');
params [["_message", "", [""]]];
systemChat _message;
};
}] call CBA_fnc_compileFinal;

CBA_fnc_defaultParam = {
["CBA_fnc_defaultParam", {
WARNING('Deprecated function used: CBA_fnc_defaultParam (new: param)');
params [["_params", []], ["_index", -1, [0]], "_defaultValue"];
if (_index < 0) exitWith {_defaultValue};
_params param [_index, _defaultValue]
};
}] call CBA_fnc_compileFinal;

CBA_fnc_addWeaponCargoGlobal = {
["CBA_fnc_addWeaponCargoGlobal", {
WARNING('Deprecated function used: CBA_fnc_addWeaponCargoGlobal (new: CBA_fnc_addWeaponCargo)');
_this call CBA_fnc_addWeaponCargo;
};
}] call CBA_fnc_compileFinal;

CBA_fnc_addMagazineCargoGlobal = {
["CBA_fnc_addMagazineCargoGlobal", {
WARNING('Deprecated function used: CBA_fnc_addMagazineCargoGlobal (new: CBA_fnc_addMagazineCargo)');
_this call CBA_fnc_addMagazineCargo;
};
}] call CBA_fnc_compileFinal;

CBA_fnc_removeWeaponCargoGlobal = {
["CBA_fnc_removeWeaponCargoGlobal", {
WARNING('Deprecated function used: CBA_fnc_removeWeaponCargoGlobal (new: CBA_fnc_removeWeaponCargo)');
_this call CBA_fnc_removeWeaponCargo;
};
}] call CBA_fnc_compileFinal;

CBA_fnc_removeMagazineCargoGlobal = {
["CBA_fnc_removeMagazineCargoGlobal", {
WARNING('Deprecated function used: CBA_fnc_removeMagazineCargoGlobal (new: CBA_fnc_removeMagazineCargo)');
_this call CBA_fnc_removeMagazineCargo;
};
}] call CBA_fnc_compileFinal;

CBA_fnc_removeItemCargoGlobal = {
["CBA_fnc_removeItemCargoGlobal", {
WARNING('Deprecated function used: CBA_fnc_removeItemCargoGlobal (new: CBA_fnc_removeItemCargo)');
_this call CBA_fnc_removeItemCargo;
};
}] call CBA_fnc_compileFinal;

CBA_fnc_removeBackpackCargoGlobal = {
["CBA_fnc_removeBackpackCargoGlobal", {
WARNING('Deprecated function used: CBA_fnc_removeBackpackCargoGlobal (new: CBA_fnc_removeBackpackCargo)');
_this call CBA_fnc_removeBackpackCargo;
};
}] call CBA_fnc_compileFinal;

FUNC(directCall) = {
[QFUNC(directCall), {
WARNING('Deprecated function used: FUNC(directCall) (new: CBA_fnc_directCall)');
params ["_params", "_code"];
[_code, _params] call CBA_fnc_directCall;
};
}] call CBA_fnc_compileFinal;

CBA_fnc_intToString = {
["CBA_fnc_intToString", {
WARNING('Deprecated function used: CBA_fnc_intToString (new: str)');
params [["_int", nil, [0]]];
if (isNil "_int") exitWith {""};
str _int
};
}] call CBA_fnc_compileFinal;

CBA_fnc_inArea = {
["CBA_fnc_inArea", {
WARNING('Deprecated function used: CBA_fnc_inArea (new: inArea)');
params ["_position", ["_zRef", objNull, ["", objNull, locationNull, []], 5]];

_position = _position call CBA_fnc_getPos;
_position inArea _zRef;
};
}] call CBA_fnc_compileFinal;
30 changes: 30 additions & 0 deletions addons/common/fnc_compileFinal.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* ----------------------------------------------------------------------------
Function: CBA_fnc_compileFinal
Description:
Defines a function in mission namespace and prevents it from being overwritten.
Parameters:
_name - Function name <STRING>
_function - A function <CODE>
Returns:
Nothing
Examples:
(begin example)
["MyFunction", {systemChat str _this}] = true call CBA_fnc_compileFinal;
(end)
Author:
commy2
---------------------------------------------------------------------------- */
#include "script_component.hpp"
SCRIPT(compileFinal);

params [["_name", "", [""]], ["_function", {}, [{}]]];

_function = str _function;
_function = _function select [1, count _function - 2];

missionNamespace setVariable [_name, compileFinal _function];
5 changes: 2 additions & 3 deletions addons/common/init_delayLess.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Generic twice-a-second loop instantiator(?)
GVAR(d) = [];

FUNC(addTriggerHandler) = {
[QFUNC(addTriggerHandler), {
private ["_c"];
// #include "script_component.hpp"
// #define DEBUG_MODE_FULL
Expand All @@ -18,9 +18,8 @@ FUNC(addTriggerHandler) = {
GVAR(d_trigger) setTriggerStatements ["{ if (count _x == 2) then { (_x select 0) call (_x select 1) } } forEach cba_common_d", "", ""];
};
_c; // return index, so can either change array parameter count, or empty?
};
}] call CBA_fnc_compileFinal;
// TODO: Cleanup functions?

// Specific twice-a-second loop
// TODO: Should be a function that creates a trigger per loop, and uses onAct, onDeact, and removes the trigger on finish?

18 changes: 8 additions & 10 deletions addons/common/init_perFrameHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GVAR(nextFrameBufferB) = [];
GVAR(waitUntilAndExecArray) = [];

// per frame handler system
FUNC(onFrame) = {
[QFUNC(onFrame), {
private _tickTime = diag_tickTime;
call FUNC(missionTimePFH);

Expand Down Expand Up @@ -80,9 +80,7 @@ FUNC(onFrame) = {
if (_delete) then {
GVAR(waitUntilAndExecArray) = GVAR(waitUntilAndExecArray) - [objNull];
};

};

}] call CBA_fnc_compileFinal;

// fix for save games. subtract last tickTime from ETA of all PFHs after mission was loaded
addMissionEventHandler ["Loaded", {
Expand All @@ -103,14 +101,14 @@ if (isMultiplayer) then {
// multiplayer - no accTime in MP
if (isServer) then {
// multiplayer server
FUNC(missionTimePFH) = {
[QFUNC(missionTimePFH), {
if (time != GVAR(lastTime)) then {
CBA_missionTime = CBA_missionTime + (_tickTime - GVAR(lastTickTime));
GVAR(lastTime) = time; // used to detect paused game
};

GVAR(lastTickTime) = _tickTime;
};
}] call CBA_fnc_compileFinal;

addMissionEventHandler ["PlayerConnected", {
(_this select 4) publicVariableClient "CBA_missionTime";
Expand All @@ -125,25 +123,25 @@ if (isMultiplayer) then {

GVAR(lastTickTime) = diag_tickTime; // prevent time skip on clients

FUNC(missionTimePFH) = {
[QFUNC(missionTimePFH), {
if (time != GVAR(lastTime)) then {
CBA_missionTime = CBA_missionTime + (_tickTime - GVAR(lastTickTime));
GVAR(lastTime) = time; // used to detect paused game
};

GVAR(lastTickTime) = _tickTime;
};
}] call CBA_fnc_compileFinal;
};
};
};
} else {
// single player
FUNC(missionTimePFH) = {
[QFUNC(missionTimePFH), {
if (time != GVAR(lastTime)) then {
CBA_missionTime = CBA_missionTime + (_tickTime - GVAR(lastTickTime)) * accTime;
GVAR(lastTime) = time; // used to detect paused game
};

GVAR(lastTickTime) = _tickTime;
};
}] call CBA_fnc_compileFinal;
};
4 changes: 2 additions & 2 deletions addons/events/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ GVAR(keyUpActiveList) = [];

GVAR(keyHoldTimers) = call CBA_fnc_createNamespace;

FUNC(handleKeyDownUp) = {
[QFUNC(handleKeyDownUp), {
private _xUp = _this select (count _this - 1);

GVAR(keyUpActiveList) deleteAt (GVAR(keyUpActiveList) find _xUp);
GVAR(keyHoldTimers) setVariable [_xUp, nil];

false
};
}] call CBA_fnc_compileFinal;
48 changes: 24 additions & 24 deletions addons/events/backwards_comp.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// imitate deprecated clientToServerEvent
CBA_fnc_addClientToServerEventhandler = {
diag_log text "[CBA]: Usage of deprecated CBA_fnc_addClientToServerEventhandler.";
["CBA_fnc_addClientToServerEventhandler", {
WARNING('Deprecated function used: CBA_fnc_addClientToServerEventhandler');
if (!isServer) exitWith {};

private _eventsVar = format [QGVAR(CTS:%1), _this select 0];
Expand All @@ -14,14 +14,14 @@ CBA_fnc_addClientToServerEventhandler = {
(missionNamespace getVariable _eventsVar) pushBack ([_eventsVar, _this select 1] call CBA_fnc_addEventHandler);

nil // no ID returned for this function
};
}] call CBA_fnc_compileFinal;

CBA_fnc_clientToServerEvent = {
["CBA_fnc_clientToServerEvent", {
[format [QGVAR(CTS:%1), _this select 0], _this select 1] call CBA_fnc_serverEvent;
};
}] call CBA_fnc_compileFinal;

CBA_fnc_removeClientToServerEvent = {
diag_log text "[CBA]: Usage of deprecated CBA_fnc_removeClientToServerEvent.";
["CBA_fnc_removeClientToServerEvent", {
WARNING('Deprecated function used: CBA_fnc_removeClientToServerEvent');
if (!isServer) exitWith {};

private _eventsVar = format [QGVAR(CTS:%1), _this];
Expand All @@ -33,11 +33,11 @@ CBA_fnc_removeClientToServerEvent = {

missionNamespace setVariable [_eventsVar, nil];
};
};
}] call CBA_fnc_compileFinal;

// imitate deprecated receiverOnlyEvent
CBA_fnc_addReceiverOnlyEventhandler = {
diag_log text "[CBA]: Usage of deprecated CBA_fnc_addReceiverOnlyEventhandler.";
["CBA_fnc_addReceiverOnlyEventhandler", {
WARNING('Usage of deprecated CBA_fnc_addReceiverOnlyEventhandler');
private _eventsVar = format [QGVAR(TOR:%1), _this select 0];

if (isNil _eventsVar) then {
Expand All @@ -48,19 +48,19 @@ CBA_fnc_addReceiverOnlyEventhandler = {
(missionNamespace getVariable _eventsVar) pushBack ([_eventsVar, _this select 1] call CBA_fnc_addEventHandler);

nil // no ID returned for this function
};
}] call CBA_fnc_compileFinal;

CBA_fnc_receiverOnlyEvent = {
["CBA_fnc_receiverOnlyEvent", {
(_this select 1) params ["_target"];

// emulate bug with this event: publicVariableServer does not trigger PVEH when called on the server - publicVariable does
if (isServer && {!local _target}) exitWith {};

[format [QGVAR(TOR:%1), _this select 0], _this select 1, _target] call CBA_fnc_targetEvent;
};
}] call CBA_fnc_compileFinal;

CBA_fnc_removeReceiverOnlyEvent = {
diag_log text "[CBA]: Usage of deprecated CBA_fnc_removeReceiverOnlyEvent.";
["CBA_fnc_removeReceiverOnlyEvent", {
WARNING('Usage of deprecated CBA_fnc_removeReceiverOnlyEvent');
private _eventsVar = format [QGVAR(TOR:%1), _this];

if (!isNil _eventsVar) then {
Expand All @@ -70,11 +70,11 @@ CBA_fnc_removeReceiverOnlyEvent = {

missionNamespace setVariable [_eventsVar, nil];
};
};
}] call CBA_fnc_compileFinal;

// imitate deprecated whereLocalEvent / remoteLocalEvent
CBA_fnc_addLocalEventHandler = {
diag_log text "[CBA]: Usage of deprecated CBA_fnc_addLocalEventHandler.";
["CBA_fnc_addLocalEventHandler", {
WARNING('Usage of deprecated CBA_fnc_addLocalEventHandler');
private _eventsVar = format [QGVAR(WL:%1), _this select 0];

if (isNil _eventsVar) then {
Expand All @@ -83,21 +83,21 @@ CBA_fnc_addLocalEventHandler = {
};

(missionNamespace getVariable _eventsVar) pushBack ([_eventsVar, _this select 1] call CBA_fnc_addEventHandler) // return handler id
};
}] call CBA_fnc_compileFinal;

CBA_fnc_whereLocalEvent = {
["CBA_fnc_whereLocalEvent", {
(_this select 1) params ["_target"];

[format [QGVAR(WL:%1), _this select 0], _this select 1, _target] call CBA_fnc_targetEvent;
};
}] call CBA_fnc_compileFinal;

// CBA_fnc_remoteLocalEvent, FUNC(remoteLocalEvent)

CBA_fnc_removeLocalEventHandler = {
diag_log text "[CBA]: Usage of deprecated CBA_fnc_removeLocalEventHandler.";
["CBA_fnc_removeLocalEventHandler", {
WARNING('Usage of deprecated CBA_fnc_removeLocalEventHandler');
private _eventsVar = format [QGVAR(WL:%1), _this select 0];

if (!isNil _eventsVar) then {
[_eventsVar, _this select 1] call CBA_fnc_removeEventHandler;
};
};
}] call CBA_fnc_compileFinal;
Loading

0 comments on commit b7be959

Please sign in to comment.