Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CBA_missionTime #273

Merged
merged 1 commit into from
Feb 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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