Skip to content

Commit

Permalink
Merge pull request #273 from CBATeam/cba_missiontime
Browse files Browse the repository at this point in the history
add CBA_missionTime
  • Loading branch information
Killswitch00 committed Feb 24, 2016
2 parents 7529c11 + 41e20aa commit 35e85b5
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
64 changes: 61 additions & 3 deletions addons/common/init_perFrameHandler.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
GVAR(perFrameHandlerArray) = [];
GVAR(fpsCount) = 0;
GVAR(lastCount) = -1;
GVAR(lastFrameRender) = 0;
GVAR(lastTickTime) = 0;
GVAR(lastFrameRender) = diag_frameNo;
GVAR(lastTickTime) = diag_tickTime;

PREP(perFrameEngine);

Expand Down Expand Up @@ -129,7 +129,9 @@ FUNC(monitorFrameRender) = {
FUNC(onFrame) = {
TRACE_1("Executing onFrame",nil);
GVAR(lastFrameRender) = diag_frameNo;
GVAR(lastTickTime) = diag_tickTime;

private _tickTime = diag_tickTime;
call FUNC(missionTimePFH);

{
_x params ["_function", "_delay", "_delta", "", "_args", "_handle"];
Expand All @@ -147,4 +149,60 @@ addMissionEventHandler ["Loaded", {
{
_x set [2, (_x select 2) - GVAR(lastTickTime) + diag_tickTime];
} forEach GVAR(perFrameHandlerArray);

GVAR(lastFrameRender) = diag_frameNo; // reset these for new session
GVAR(lastTickTime) = diag_tickTime;
}];

CBA_missionTime = 0;
GVAR(lastTime) = time;

// increase CBA_missionTime variable every frame
if (isMultiplayer) then {
// multiplayer - no accTime in MP
if (isServer) then {
// multiplayer server
FUNC(missionTimePFH) = {
if (time != GVAR(lastTime)) then {
CBA_missionTime = CBA_missionTime + (_tickTime - GVAR(lastTickTime));
GVAR(lastTime) = time; // used to detect paused game
};

GVAR(lastTickTime) = _tickTime;
};

["CBA_SynchMissionTime", "onPlayerConnected", {
_owner publicVariableClient "CBA_missionTime";
}] call BIS_fnc_addStackedEventHandler;
} else {
CBA_missionTime = -1;

// multiplayer client
0 spawn {
"CBA_missionTime" addPublicVariableEventHandler {
CBA_missionTime = _this select 1;

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

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

GVAR(lastTickTime) = _tickTime;
};
};
};
};
} else {
// single player
FUNC(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;
};
};
5 changes: 5 additions & 0 deletions addons/xeh/fnc_postInit_unscheduled.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ Author:

XEH_LOG("XEH: PostInit started.");

// fix CBA_missionTime being -1 on (non-JIP) clients at mission start.
if (CBA_missionTime == -1) then {
CBA_missionTime = 0;
};

// call PostInit events
{
if (_x select 1 == "postInit") then {
Expand Down

0 comments on commit 35e85b5

Please sign in to comment.