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

optimize player events #1289

Merged
merged 15 commits into from
Feb 7, 2020
Merged

optimize player events #1289

merged 15 commits into from
Feb 7, 2020

Conversation

commy2
Copy link
Contributor

@commy2 commy2 commented Feb 1, 2020

When merged this pull request will:

  • A single state check to exit all frames without change immediately / replace all the assignments with a single params
  • muzzle, weaponMode and turretWeapon player events
  • pass old/new state as argument as well

@PabstMirror
Copy link
Contributor

old 0.0305623 ms
new 0.029656 ms (pretty good for also adding 2 additional stats)
new+suggestions: 0.0237248 ms

@commy2
Copy link
Contributor Author

commy2 commented Feb 2, 2020

Updated documentation with the new events and new passed arguments.

Available events

  • "unit": This event is executed when the players controlled avatar changes. This includes player-object initialization (if the event is added during preInit), remote controlling a unit via zeus and respawning. This event is essential to make a feature based around the player-object "zeus compatible".
    Parameters: [_newPlayerUnit <OBJECT>, _oldPlayerUnit <OBJECT>]
["unit", {
    params ["_newUnit", "_oldUnit"];
    systemChat str "Unit changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "weapon": This event is executed when the player changes the current active weapon. This does not include vehicles.
    Parameters: [_playerUnit <OBJECT>, _newSelectedWeapon <STRING>, _oldSelectedWeapon <STRING>]
["weapon", {
    params ["_unit", "_newWeapon", "_oldWeapon"];
    systemChat str "Weapon changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "muzzle": This event is executed when the player changes the current selected muzzle. This does include vehicles.
    Parameters: [_playerUnit <OBJECT>, _newSelectedMuzzle <STRING>, _oldSelectedMuzzle <STRING>]
["muzzle", {
    params ["_unit", "_newMuzzle", "_oldMuzzle"];
    systemChat str "Muzzle changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "weaponMode": This event is executed when the player changes the weapon mode, including when they switch the weapon. This does include vehicles.
    Parameters: [_playerUnit <OBJECT>, _newSelectedWeapon <STRING>, _oldSelectedWeapon <STRING>]
["weaponMode", {
    params ["_unit", "_newWeaponMode", "_oldWeaponMode"];
    systemChat str "Weapon Mode changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "loadout": This event is executed when the players loadout changes. It is not executed when the ammunition counter is decreased after firing a weapon.
    Parameters: [_playerUnit <OBJECT>, _oldUnitLoadout <ARRAY>, _newUnitLoadout <ARRAY>]
["loadout", {
    params ["_unit", "_oldUnitLoadout", "_newLoadout"];
    systemChat str "Inventory changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "vehicle": This event is executed when the player enters or leaves a vehicle. If the player leaves a vehicle, the player object will be passed as argument. This is different from getInMan since it also triggers if the player is moved into the vehicle via moveInDriver, zeus or similar.
    Parameters: [_playerUnit <OBJECT>, _newVehicle <OBJECT>, _oldVehicle <OBJECT>]
["vehicle", {
    params ["_unit", "_newVehicle", "_oldVehicle"];
    systemChat str "Vehicle changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "turret": This event will be executed when the player changes the turret position.
    Parameters: [_playerUnit <OBJECT>, _newTurret <ARRAY>, _oldTurret <ARRAY>]
["turret", {
    params ["_unit", "_newTurret", "_oldTurret"];
    systemChat str "Turret changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "featureCamera": This event will be executed when the active camera changes (Curator, Arsenal, Spectator etc.).
    Parameters: [_playerUnit <OBJECT>, _newCamera <ARRAY>]
["featureCamera", {
    params ["_unit", "_newCamera"];
    systemChat str "Camera changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "cameraView": This event will be executed when the player changes the camera mode. Camera modes are: "INTERNAL", "EXTERNAL", "GUNNER" and "GROUP" (commander view)
    Parameters: [_playerUnit <OBJECT>, _newCameraMode <STRING>, _oldCameraMode <STRING>]
["cameraView", {
    params ["_unit", "_newCameraMode", "_oldCameraMode"];
    systemChat str "Camera Mode changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "visionMode": This event will be executed when the player changes the vision mode. Vision modes are: 0 (day), 1 (night vision) or 2 (thermal vision)
    Parameters: [_playerUnit <OBJECT>, _newVisionMode <NUMBER>, _oldVisionMode <NUMBER>]
["visionMode", {
    params ["_unit", "_newVisionMode", "_oldVisionMode"];
    systemChat str "Vision Mode changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "visibleMap": This event will be executed when the player opens or closes the map.
    Parameters: [_playerUnit <OBJECT>, _isMapShown <BOOLEAN>]
["visibleMap", {
    params ["_unit", "_isMapShown"];
    systemChat str "Map opened or closed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "group": This event will be executed when the player's group changes.
    Parameters: [_playerUnit <OBJECT>, _oldGroup <GROUP>, _newGroup <GROUP>]
["group", {
    params ["_unit", "_oldGroup", "_newGroup"];
    systemChat str "Group changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

  • "leader": This event will be executed when the leader of the player's group changed.
    Parameters: [_playerUnit <OBJECT>, _oldLeader <OBJECT>, _newLeader <OBJECT>]
["leader", {
    params ["_unit", "_oldLeader", "_newLeader"];
    systemChat str "Group Leader changed.";
}, true] call CBA_fnc_addPlayerEventHandler;

@commy2
Copy link
Contributor Author

commy2 commented Feb 2, 2020

As talked about in the ACE Slack, the weapon mode event should also trigger on the switch from Pistol/Single -> Rifle/Single, as well as Rifle/Single -> GL/Single.

Same for the muzzle event, but it is hard to come up with an example where pistol and rifle share the same muzzle name, that is not the weapon classname/this and also the primary selected muzzle.

Some code to mess around with:

["weaponMode", {
    params ["_unit", "_newWeaponMode"];
    private _vehicle = vehicle _unit;

    private _weapon = currentWeapon _unit;
    if !(_unit call CBA_fnc_canUseWeapon) then {
        private _turret = _unit call CBA_fnc_turretPath;
        _weapon = _vehicle currentWeaponTurret _turret;
    };

    private _muzzle = currentMuzzle _unit;

    private _muzzleConfig = configfile >> "CfgWeapons" >> _weapon;
    if (_muzzle != _weapon) then {
        _muzzleConfig = _muzzleConfig >> _muzzle;
    };

    private _muzzleName = getText (_muzzleConfig >> "displayName");
    private _weaponModeName = getText (_muzzleConfig >> _newWeaponMode >> "displayName");

    systemChat format ["Switched to %1 (%2) fire mode.", _weaponModeName, _muzzleName];
}] call CBA_fnc_addPlayerEventHandler;

Best as grenadier with an empty Slammer nearby.

@commy2 commy2 removed the WIP label Feb 2, 2020
@PabstMirror
Copy link
Contributor

retested 0.0238209 ms

@commy2
Copy link
Contributor Author

commy2 commented Feb 2, 2020

Any objections to the changes otherwise? I must say that I like this way more overall.

@PabstMirror
Copy link
Contributor

adding old to event params is great

Co-Authored-By: PabstMirror <pabstmirror@gmail.com>
@commy2
Copy link
Contributor Author

commy2 commented Feb 2, 2020

adding old to event params is great

Sadly, group, leader and loadout report <unit,old,new>, while the others report <unit,new,old>. I must've fucked up sometime in the past.

@commy2
Copy link
Contributor Author

commy2 commented Feb 6, 2020

Added turretWeapon event. muzzle and weaponMode are vehicle compatible. weapon and turretWeapon are complementary for vehicle vs infantristic.

@commy2 commy2 added this to the 3.13.1 milestone Feb 6, 2020
Copy link
Member

@jonpas jonpas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@commy2 commy2 merged commit 861c966 into master Feb 7, 2020
@commy2 commy2 deleted the playerEvent-updates branch February 7, 2020 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants