more common code cleanup

This commit is contained in:
commy2 2015-09-21 18:37:19 +02:00
parent 1a4ebdac51
commit 8503d15c9b
8 changed files with 159 additions and 127 deletions

View File

@ -215,25 +215,12 @@ if (!hasInterface) exitWith {};
// Set up mouse wheel eventhandler
//////////////////////////////////////////////////
call COMPILE_FILE(scripts\assignedItemFix);/////////////
call COMPILE_FILE(scripts\initScrollWheel);/////////////
DFUNC(mouseZHandler) = {
waitUntil {!isNull (findDisplay 46)}; sleep 0.1;
findDisplay 46 displayAddEventHandler ["MouseZChanged", QUOTE( _this call GVAR(onScrollWheel) )];
[false] call FUNC(disableUserInput);
};
addMissionEventHandler ["Loaded", {[] spawn FUNC(mouseZHandler)}];
[] spawn FUNC(mouseZHandler);
/*
call FUNC(assignedItemFix);
GVAR(ScrollWheelFrame) = diag_frameno;
addMissionEventHandler ["Loaded", {call FUNC(mouseZHandler)}];
call FUNC(mouseZHandler);
*/
addMissionEventHandler ["Loaded", {call FUNC(handleScrollWheelInit)}];
call FUNC(handleScrollWheelInit);
// @todo remove?
enableCamShake true;
@ -417,14 +404,20 @@ if (!isNil QGVAR(PreInit_playerChanged_PFHID)) then {
{_unit != _target && {vehicle _unit == vehicle _target}}
}] call FUNC(addCanInteractWithCondition);
//////////////////////////////////////////////////
// Set up PlayerJIP eventhandler
//////////////////////////////////////////////////
// Lastly, do JIP events
// JIP Detection and event trigger. Run this at the very end, just in case anything uses it
// Note: usage of player is most likely on purpose
if (didJip) then {
// We are jipping! Get ready and wait, and throw the event
[{
if((!(isNull player)) && GVAR(settingsInitFinished)) then {
["PlayerJip", [player] ] call FUNC(localEvent);
[(_this select 1)] call CBA_fnc_removePerFrameHandler;
if(!isNull player && GVAR(settingsInitFinished)) then {
["PlayerJip", [player]] call FUNC(localEvent);
[_this select 1] call CBA_fnc_removePerFrameHandler;
};
}, 0, []] call CBA_fnc_addPerFrameHandler;
};

View File

@ -1,16 +1,13 @@
// by commy2
#include "script_component.hpp"
//IGNORE_PRIVATE_WARNING("_handleNetEvent", "_handleRequestAllSyncedEvents", "_handleRequestSyncedEvent", "_handleSyncedEvent");
ADDON = false;
// ACE Common Function
PREP(addCanInteractWithCondition);
PREP(addLineToDebugDraw);
PREP(addSetting);
PREP(addToInventory);
PREP(assignedItemFix);
PREP(assignObjectsInList);
PREP(ambientBrightness);
PREP(applyForceWalkStatus);
@ -82,14 +79,6 @@ PREP(getTargetAzimuthAndInclination);
PREP(getTargetDistance);
PREP(getTargetObject);
PREP(getTurnedOnLights);
PREP(getTurretCommander);
PREP(getTurretConfigPath);
PREP(getTurretCopilot);
PREP(getTurretGunner);
PREP(getTurretIndex);
PREP(getTurrets);
PREP(getTurretsFFV);
PREP(getTurretsOther);
PREP(getTurretDirection);
PREP(getUavControlPosition);
PREP(getVehicleCargo);
@ -102,6 +91,8 @@ PREP(getWindDirection);
PREP(getZoom);
PREP(goKneeling);
PREP(hadamardProduct);
PREP(handleScrollWheel);
PREP(handleScrollWheelInit);
PREP(hasItem);
PREP(hasMagazine);
PREP(headBugFix);
@ -251,6 +242,17 @@ PREP(localEvent);
PREP(removeEventHandler);
PREP(removeAlLEventHandlers);
// Synchronized Events
PREP(syncedEventPFH);
PREP(addSyncedEventHandler);
PREP(removeSyncedEventHandler);
PREP(requestSyncedEvent);
PREP(syncedEvent);
PREP(_handleSyncedEvent);
PREP(_handleRequestSyncedEvent);
PREP(_handleRequestAllSyncedEvents);
// other eventhandlers
PREP(addActionEventHandler);
PREP(addActionMenuEventHandler);
@ -274,17 +276,6 @@ PREP(hashListSelect);
PREP(hashListSet);
PREP(hashListPush);
// Synchronized Events
PREP(syncedEventPFH);
PREP(addSyncedEventHandler);
PREP(removeSyncedEventHandler);
PREP(requestSyncedEvent);
PREP(syncedEvent);
PREP(_handleSyncedEvent);
PREP(_handleRequestSyncedEvent);
PREP(_handleRequestAllSyncedEvents);
GVAR(syncedEvents) = HASH_CREATE;
//GVARS for execNextFrame and waitAndExec
@ -296,7 +287,7 @@ GVAR(nextFrameBufferB) = [];
GVAR(settingsInitFinished) = false;
GVAR(runAtSettingsInitialized) = [];
// @TODO: Generic local-managed global-synced objects (createVehicleLocal)
// @todo: Generic local-managed global-synced objects (createVehicleLocal)
//Debug
ACE_COUNTERS = [];
@ -306,8 +297,15 @@ if (isServer) then {
call FUNC(loadSettingsOnServer);
};
ACE_player = objNull;
//////////////////////////////////////////////////
// Set up PlayerChanged eventhandler for pre init
//////////////////////////////////////////////////
ACE_player = objNull;
uiNamespace setVariable ["ACE_player", objNull];
// @todo check if this can be removed
if (hasInterface) then {
// PFH to update the ACE_player variable
GVAR(PreInit_playerChanged_PFHID) = [{
@ -324,7 +322,11 @@ if (hasInterface) then {
}, 0, []] call CBA_fnc_addPerFrameHandler;
};
//////////////////////////////////////////////////
// Time handling
//////////////////////////////////////////////////
ACE_time = diag_tickTime;
ACE_realTime = diag_tickTime;
ACE_virtualTime = diag_tickTime;
@ -339,6 +341,8 @@ PREP(timePFH);
// Init toHex
[0] call FUNC(toHex);
ADDON = true;
isHC = !hasInterface && !isDedicated; // deprecated because no tag
missionNamespace setVariable ["ACE_isHC", ACE_isHC];
uiNamespace setVariable ["ACE_isHC", ACE_isHC];
isHC = !(hasInterface || isDedicated);
ADDON = true;

View File

@ -0,0 +1,73 @@
/*
* Author: commy2
* Initialized the assigned item fix.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Public : No
*/
#include "script_component.hpp"
private "_config";
ACE_isMapEnabled = call {_config = missionConfigFile >> "showMap"; !isNumber _config || {getNumber _config == 1}}; // default value is 1, so do isNumber check first
ACE_isCompassEnabled = call {_config = missionConfigFile >> "showCompass"; !isNumber _config || {getNumber _config == 1}};
ACE_isWatchEnabled = call {_config = missionConfigFile >> "showWatch"; !isNumber _config || {getNumber _config == 1}};
ACE_isRadioEnabled = call {_config = missionConfigFile >> "showRadio"; !isNumber _config || {getNumber _config == 1}};
ACE_isGPSEnabled = call {_config = missionConfigFile >> "showGPS"; !isNumber _config || {getNumber _config == 1}};
GVAR(AssignedItems) = [];
GVAR(AssignedItemsInfo) = [];
GVAR(AssignedItemsShownItems) = [
ACE_isMapEnabled,
ACE_isCompassEnabled,
ACE_isWatchEnabled,
ACE_isRadioEnabled,
ACE_isGPSEnabled
];
["playerInventoryChanged", {
params ["_unit", "_assignedItems"];
_assignedItems = _assignedItems select 17;
{
if !(_x in GVAR(AssignedItems)) then {
GVAR(AssignedItems) pushBack _x;
GVAR(AssignedItemsInfo) pushBack toLower getText (configFile >> "CfgWeapons" >> _x >> "ACE_hideItemType");
};
switch (GVAR(AssignedItemsInfo) select (GVAR(AssignedItems) find _x)) do {
case ("map"): {
GVAR(AssignedItemsShownItems) set [0, false];
};
case ("compass"): {
GVAR(AssignedItemsShownItems) set [1, false];
};
case ("watch"): {
GVAR(AssignedItemsShownItems) set [2, false];
};
case ("radio"): {
GVAR(AssignedItemsShownItems) set [3, false];
};
case ("gps"): {
GVAR(AssignedItemsShownItems) set [4, false];
};
};
false
} count _assignedItems;
//systemChat str GVAR(AssignedItemsShownItems);
GVAR(AssignedItemsShownItems) params ["_showMap", "_showCompass", "_showWatch", "_showRadio", "_showGPS"];
showMap _showMap;
showCompass _showCompass;
showWatch _showWatch;
showRadio _showRadio;
showGPS (_showGPS || {cameraOn == getConnectedUAV _unit}); //If player is activly controling a UAV, showGPS controls showing the map (m key)
}] call FUNC(addEventHandler);

View File

@ -0,0 +1,25 @@
/*
* Author: commy2
* Handles MouseZChanged event.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Public : No
*/
#include "script_component.hpp"
// prevents a bug that causes the MouseZChanged to trigger N-times, where N is the number of times you consecutively pressed "Restart" instead of "Preview" in the editor
if (GVAR(ScrollWheelFrame) == diag_frameno) exitWith {};
GVAR(ScrollWheelFrame) = diag_frameno;
{
[_this select 1] call _x;
false
} count ((missionNamespace getVariable ["ACE_EventHandler_ScrollWheel", [-1, [], []]]) select 2);
nil

View File

@ -0,0 +1,15 @@
/*
* Author: commy2
* Initializes the MouseZChanged eventhandler.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Public : No
*/
#include "script_component.hpp"
(findDisplay 46) displayAddEventHandler ["MouseZChanged", QUOTE(_this call FUNC(handleScrollWheel))];

View File

@ -1,64 +0,0 @@
// by commy2
#include "script_component.hpp"
private ["_config"];
ACE_isMapEnabled = call {_config = missionConfigFile >> "showMap"; !isNumber _config || {getNumber _config == 1}}; // default value is 1, so do isNumber check first
ACE_isCompassEnabled = call {_config = missionConfigFile >> "showCompass"; !isNumber _config || {getNumber _config == 1}};
ACE_isWatchEnabled = call {_config = missionConfigFile >> "showWatch"; !isNumber _config || {getNumber _config == 1}};
ACE_isRadioEnabled = call {_config = missionConfigFile >> "showRadio"; !isNumber _config || {getNumber _config == 1}};
ACE_isGPSEnabled = call {_config = missionConfigFile >> "showGPS"; !isNumber _config || {getNumber _config == 1}};
GVAR(AssignedItems) = [];
GVAR(AssignedItemsInfo) = [];
["playerInventoryChanged", {
private ["_unit", "_assignedItems", "_shownItems"];
_unit = _this select 0;
_assignedItems = _this select 1 select 17;
_shownItems = [
ACE_isMapEnabled,
ACE_isCompassEnabled,
ACE_isWatchEnabled,
ACE_isRadioEnabled,
ACE_isGPSEnabled
];
{
if !(_x in GVAR(AssignedItems)) then {
GVAR(AssignedItems) pushBack _x;
GVAR(AssignedItemsInfo) pushBack toLower getText (configFile >> "CfgWeapons" >> _x >> "ACE_hideItemType")
};
private "_hideItemType";
_hideItemType = GVAR(AssignedItemsInfo) select (GVAR(AssignedItems) find _x);
switch (_hideItemType) do {
case ("map"): {
_shownItems set [0, false];
};
case ("compass"): {
_shownItems set [1, false];
};
case ("watch"): {
_shownItems set [2, false];
};
case ("radio"): {
_shownItems set [3, false];
};
case ("gps"): {
_shownItems set [4, false];
};
};
} forEach _assignedItems;
//systemChat str _shownItems;
showMap (_shownItems select 0);
showCompass (_shownItems select 1);
showWatch (_shownItems select 2);
showRadio (_shownItems select 3);
showGPS (_shownItems select 4 || {cameraOn == getConnectedUAV _unit}); //If player is activly controling a UAV, showGPS controls showing the map (m key)
}] call FUNC(addEventHandler);

View File

@ -1,16 +0,0 @@
// by commy2
#include "script_component.hpp"
GVAR(ScrollWheelFrame) = diag_frameno;
GVAR(onScrollWheel) = {
private ["_scroll"];
_scroll = _this select 1;
if (GVAR(ScrollWheelFrame) == diag_frameno) exitWith {};
GVAR(ScrollWheelFrame) = diag_frameno;
{
[_scroll] call _x;
} count ((missionNamespace getVariable ["ACE_EventHandler_ScrollWheel", [-1, [], []]]) select 2);
};

View File

@ -97,6 +97,8 @@
// Time functions for accuracy per frame
#define ACE_tickTime (ACE_time + (diag_tickTime - ACE_diagTime))
#define ACE_isHC (!hasInterface && !isDedicated)
#define ACE_LOG(module,level,message) diag_log text ACE_LOGFORMAT(module,level,message)
#define ACE_LOGFORMAT(module,level,message) FORMAT_2(QUOTE([ACE] (module) %1: %2),level,message)