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

Improve apollo loading #208

Merged
merged 3 commits into from
Oct 7, 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
12 changes: 4 additions & 8 deletions addons/apollo/XEH_postInitClient.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ if (!hasInterface) exitWith {};
};
}] call CBA_fnc_addEventHandler;

// Load player and exit if loading failed
if !([player] call FUNC(playerLoadClient)) exitWith {};

// Save on each inventory change and every 10s with a delay between each save
["loadout", FUNC(playerSaveClient)] call CBA_fnc_addPlayerEventHandler;
[FUNC(playerSaveClient), [player, [], true], SAVE_DELAY_PERIODIC] call CBA_fnc_waitAndExecute;

INFO("Client loaded successfully.");
// Load client, add inventory one frame after removing initial inventory to prevent possible inventory desync
player allowDamage false;
player setUnitLoadout [[],[],[],[],[],[],"","",[],["","","","","",""]];
[FUNC(playerLoadClient), [player]] call CBA_fnc_execNextFrame;
}] call CBA_fnc_addEventHandler;
38 changes: 17 additions & 21 deletions addons/apollo/functions/fnc_playerLoadClient.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,19 @@
* 0: Player <OBJECT>
*
* Return Value:
* Successfully Loaded <BOOL>
* None
*
* Example:
* _success = [player] call tac_apollo_fnc_playerLoadClient
* [player] call tac_apollo_fnc_playerLoadClient
*
* Public: No
*/
#include "script_component.hpp"

params ["_player"];

_player allowDamage false;

removeHeadgear _player:
removeGoggles _player;
removeVest _player;
removeBackpack _player;
removeUniform _player;
removeAllWeapons _player:
removeAllAssignedItems _player;

TRACE_1("Loading Client",_player);
private _return = false;
private _success = false;

// Don't load when UID is "_SP_PLAYER_" (singleplayer/editor)
if (getPlayerUID _player == "_SP_PLAYER_") exitWith {false};
Expand All @@ -47,7 +37,7 @@ if (_loadData == "loaded") then {
if (_loadData == "done") then {
// Initialization complete
_updateInfo = false;
_return = true;
_success = true;
} else {
_codePacket = _loadData select [17, count _loadData];
//TRACE_1("Code Packet",_codePacket);
Expand All @@ -57,16 +47,22 @@ if (_loadData == "loaded") then {
};
};

if (!_return) then {
ERROR_2("Player not successfully loaded (Name: %1 - UID: %2)!",profileName,getPlayerUID _player);
["Your connection has been terminated - Error during Chronos loading!"] call FUNC(endMissionError);
} else {
if (_success) then {
// Validate
[QGVAR(savePlayer), [_player, "validate"]] call CBA_fnc_serverEvent;

// Has to be executed where unit is local
_player allowDamage true;
// Save load time to prevent instant saving after load

// Allow saving and save load time to prevent instant saving after load
_player setVariable [QGVAR(lastSavedTime), CBA_missionTime];
};

_return
// Save on each inventory change and periodically with a delay between each save
["loadout", FUNC(playerSaveClient)] call CBA_fnc_addPlayerEventHandler;
[FUNC(playerSaveClient), [_player, [], true], SAVE_DELAY_PERIODIC] call CBA_fnc_waitAndExecute;

INFO("Client loaded successfully.");
} else {
ERROR_2("Player not successfully loaded (Name: %1 - UID: %2)!",profileName,getPlayerUID _player);
["Your connection has been terminated - Error during Chronos loading!"] call FUNC(endMissionError);
};
3 changes: 2 additions & 1 deletion addons/apollo/functions/fnc_playerSaveClient.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ if (_periodic) then {
[FUNC(playerSaveClient), [_player, [], _periodic], SAVE_DELAY_PERIODIC] call CBA_fnc_waitAndExecute;
};

// Only save if not remote controlling a unit and more than 10 seconds have passed from previous save
// Exit if delay has not passed yet
private _delay = [SAVE_DELAY_INV_CHANGE, SAVE_DELAY_PERIODIC] select _periodic;
if ((_player getVariable [QGVAR(lastSavedTime), CBA_missionTime]) + _delay > CBA_missionTime) exitWith {
TRACE_1("Save - Not Saving (Delay Running)",CBA_missionTime);
};

// Exit if remote controlling a unit or the player is still invisible
if (_player != player || {isNull _player} || {!alive _player} || {isObjectHidden _player}) exitWith {
TRACE_1("Save - Not Saving",CBA_missionTime);
};
Expand Down