Skip to content

Commit

Permalink
Initial IR flashlight tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BaerMitUmlaut committed Sep 4, 2018
1 parent 8cd0b49 commit a2e3631
Show file tree
Hide file tree
Showing 15 changed files with 225 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/irlight/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z\ace\addons\irlight
17 changes: 17 additions & 0 deletions addons/irlight/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));
};
};

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};

class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};
6 changes: 6 additions & 0 deletions addons/irlight/CfgJointRails.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class asdg_SlotInfo;
class asdg_FrontSideRail: asdg_SlotInfo {
class compatibleItems {
ACE_acc_pointer_IR_flashlight = 1;
};
};
45 changes: 45 additions & 0 deletions addons/irlight/CfgWeapons.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
class SlotInfo;
class PointerSlot: SlotInfo {
compatibleItems[] += {
"ACE_acc_pointer_IR_flashlight"
};
};

class CfgWeapons {
class ItemCore;
class acc_pointer_IR: ItemCore {
class ItemInfo;
};
class ACE_acc_pointer_IR_flashlight: acc_pointer_IR {
author = ECSTRING(common,ACETeam);
displayName = "ACE IR flashlight"; // TODO: stringtable

class ItemInfo: ItemInfo {
class Flashlight {
color[] = {180,160,130};
ambient[] = {0.9,0.81,0.7};
intensity = 100; // Brightness
size = 1; // TODO: OwO what's this?
innerAngle = 5; // Can't really tell if there are actually two cones?
outerAngle = 10;
coneFadeCoef = 8; // Higher value = sharper outline
position = "laser pos";
direction = "laser dir";
useFlare = 1;
flareSize = 1.4;
flareMaxDistance = 100;
dayLight = 0;
scale[] = {0};

class Attentuation {
start = 0;
constant = 0.5;
linear = 0.1;
quadratic = 0.2;
hardLimitStart = 27;
hardLimitEnd = 34;
};
};
};
};
};
11 changes: 11 additions & 0 deletions addons/irlight/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ace_irlight
===================

Adds scripted IR flashlights.


## Maintainers

The people responsible for merging changes to this component or answering potential questions.

- [BaerMitUmlaut](https://github.com/BaerMitUmlaut)
3 changes: 3 additions & 0 deletions addons/irlight/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PREP(handleLoadoutChanged);
PREP(updateWeaponLights);
PREP(handleVisionModeChanged);
8 changes: 8 additions & 0 deletions addons/irlight/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "script_component.hpp"

// Make sure JIPs can see already turned on IR lights
GVAR(units) = allPlayers select {
_x getVariable [QGVAR(turnedOn), false]
};

[FUNC(updateWeaponLights), 0, []] call CBA_fnc_addPerFrameHandler;
27 changes: 27 additions & 0 deletions addons/irlight/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "script_component.hpp"

ADDON = false;

PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

// List of units with an enabled IR light
GVAR(units) = [];

[QGVAR(switchedLight), {
params ["_unit", "_lightOn"];

if (_lightOn) then {
_unit action ["GunLightOn", _unit];
GVAR(units) pushBack _unit;
} else {
_unit action ["GunLightOff", _unit];
GVAR(units) deleteAt (GVAR(units) find _unit);
};
}] call CBA_fnc_addEventHandler;

["loadout", FUNC(handleLoadoutChanged)] call CBA_fnc_addPlayerEventHandler;
["visionMode", FUNC(handleVisionModeChanged)] call CBA_fnc_addPlayerEventHandler;

ADDON = true;
3 changes: 3 additions & 0 deletions addons/irlight/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

#include "XEH_PREP.hpp"
19 changes: 19 additions & 0 deletions addons/irlight/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
name = COMPONENT_NAME;
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common"};
author = ECSTRING(common,ACETeam);
authors[] = {"BaerMitUmlaut"};
url = ECSTRING(main,URL);
VERSION_CONFIG;
};
};

#include "CfgEventHandlers.hpp"
#include "CfgJointRails.hpp"
#include "CfgWeapons.hpp"
3 changes: 3 additions & 0 deletions addons/irlight/functions/fnc_handleLoadoutChanged.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"
// TODO: save if the current weapon has an ir flashlight capable attachment
// isKindOf forEach attachment? config property?
13 changes: 13 additions & 0 deletions addons/irlight/functions/fnc_handleVisionModeChanged.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "script_component.hpp"

// Manually update weapon lights once for instant change
// TODO: Check if still necessary?
if (IN_NVGS) then {
{
_x action ["GunLightOn", _x];
} forEach GVAR(units);
} else {
{
_x action ["GunLightOff", _x];
} forEach GVAR(units);
};
51 changes: 51 additions & 0 deletions addons/irlight/functions/fnc_updateWeaponLights.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Author: BaerMitUmlaut
* Makes the IR weapon lights visible depending on wether the player wears NVGs or not.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_irlight_fnc_updateWeaponLights
*
* Public: No
*/
#include "script_component.hpp"

private _hasIRLight = "ACE_acc_pointer_IR_flashlight" in primaryWeaponItems ACE_player;
private _isLightOn = ACE_player isFlashlightOn primaryWeapon ACE_player;
private _synchedOn = ACE_player getVariable [QGVAR(turnedOn), false];
private _inNVGS = IN_NVGS;

// Detect if player switched light on or off
if (_hasIRLight) then {
if (_inNVGS) then {
// Synch weapon light state with virtual state
if !(_isLightOn isEqualTo _synchedOn) then {
[QGVAR(switchedLight), [ACE_player, _isLightOn]] call CBA_fnc_globalEvent;
ACE_player setVariable [QGVAR(turnedOn), _isLightOn, true];
};
} else {
// No NVGs, but light is on
// -> player pressed the weapon light button
// -> switch light status
if (_isLightOn) then {
[QGVAR(switchedLight), [ACE_player, !_synchedOn]] call CBA_fnc_globalEvent;
ACE_player setVariable [QGVAR(turnedOn), !_synchedOn, true];
};
};
};

// Override weapon light of all units with enabled IR light
if (_inNVGS) then {
{
_x action ["GunLightOn", _x];
} forEach GVAR(units);
} else {
{
_x action ["GunLightOff", _x];
} forEach GVAR(units);
};
1 change: 1 addition & 0 deletions addons/irlight/functions/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "\z\ace\addons\irlight\script_component.hpp"
17 changes: 17 additions & 0 deletions addons/irlight/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#define COMPONENT irlight
#define COMPONENT_BEAUTIFIED IR Light
#include "\z\ace\addons\main\script_mod.hpp"

// #define DEBUG_MODE_FULL
// #define DISABLE_COMPILE_CACHE
// #define ENABLE_PERFORMANCE_COUNTERS

#ifdef DEBUG_ENABLED_IRLIGHT
#define DEBUG_MODE_FULL
#endif

#ifdef DEBUG_SETTINGS_IRLIGHT
#define DEBUG_SETTINGS DEBUG_SETTINGS_IRLIGHT
#endif

#include "\z\ace\addons\main\script_macros.hpp"

0 comments on commit a2e3631

Please sign in to comment.