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

Toggling 2D and 3D on optics doesn't consistently work unless you hit both applicable keybinds at once. #1626

Open
PetMudstone opened this issue Nov 16, 2023 · 5 comments
Labels

Comments

@PetMudstone
Copy link

PetMudstone commented Nov 16, 2023

Mods (complete and add to the following information):

  • Arma 3: 2.14.150957 [e.g. 1.00 stable, rc, dev]
  • CBA: v3.16.1.231025 (Public Workshop Release)

Description:
When attempting to toggle optics state on a CUP optic that supports toggling of 2D and 3D modes, hitting the relevant keybinds will not actually change your optics' state unless you hit both the "Next optics state" and "Prev optics state" keybinds at the same time. Strangely, attempting to toggle 2D scopes normally will keep them 2D but attempting to toggle 3D scopes normally will turn them 2D.

Notably, other optics with different kinds of toggleable states (such as the flippable sight on the M68 CCO + AimM, adjustable reticle on the EKP-8-02 and Kobra, or filter on the 1P63) work completely fine.

Steps to reproduce:

  • Make sure that you have CUP Weapons loaded.
  • Open the arsenal, vanilla or ACE.
  • Use a CUP optic that has toggle-able 3D and 2D modes (for example, the Elcan SpecterDR 1x/4x series)
  • Attempt to toggle optic state using either the "Next optics state" or "Prev optics state" keybinds.
  • Afterwards, attempt to toggle optics state using both "Next optics state" and "Prev optics state" keybinds at the same time.

Expected behavior:
I expected the various CUP optics to be properly able to switch 2D and 3D modes without hitting both applicable keybinds at once, and for other kinds of adjustable optics to be broken as well.

Where did the issue occur?

  • Singleplayer, Dedicated Server, Self-Hosted Multiplayer. Any time that I was using a scope with toggleable 2D and 3D modes.

Log Files:

Additional context:
I should note that I haven't tested other mods with adjustable optics courtesy of CBA. This is simply because I do not know of any other mods with relevant adjustable optics.

Screenshots:
Below I demonstrate the inconsistency of toggling 2D and 3D.

2023-11-15.23-56-26.1.mp4
@10Dozen
Copy link
Contributor

10Dozen commented Jan 4, 2024

I can reproduce, but don't know why this happens. CUP Weapons didn't update from Dec 2021.

For optics that supports both 2d and 3d MRT Switch scheme is the same bi-directional 2D <-> 3D and one-directional PIP -> 3D (2D switches to PIP variant by CBA logic).

Configs related to M145 scopes (2d (default), PIP and 3D variant):

// 2D variant (default)
class CUP_optic_ElcanM145: ItemCore
{
	scope = 2;
	weaponInfoType = "CBA_ScriptedOptic";
	class CBA_ScriptedOptic
	{
		reticleTexture = "\CUP\Weapons\CUP_Weapons_West_Attachments\Elcan_M145\data\elcan_m145w_reticle_ca.paa";
		reticleTextureNight = "\CUP\Weapons\CUP_Weapons_West_Attachments\Elcan_M145\data\elcan_m145w_reticle_n_ca.paa";
		reticleTextureSize = 1;
		manualReticleNightSwitch = 1;
		bodyTexture = "\CUP\Weapons\CUP_Weapons_West_Attachments\Elcan_M145\data\body\elcan_m145w_body_ca.paa";
		bodyTextureNight = "\CUP\Weapons\CUP_Weapons_West_Attachments\Elcan_M145\data\body\elcan_m145w_body_night_ca.paa";
		bodyTextureSize = 1.95;
	};
	MRT_SwitchItemNextClass = "CUP_optic_ElcanM145_3D";
	MRT_SwitchItemPrevClass = "CUP_optic_ElcanM145_3D";
	MRT_switchItemHintText = "$STR_CUP_dn_OpticsMode_2D";
};

// PIP variant
class CUP_optic_ElcanM145_PIP: CUP_optic_ElcanM145
{
	author = "$STR_CUP_AUTHOR_STRING";
	scope = 1;
	class ItemInfo: ItemInfo
	{
		modelOptics = "\x\cba\addons\optics\cba_optic_big_pip.p3d";
	};
	MRT_SwitchItemNextClass = "CUP_optic_ElcanM145_3D";
	MRT_SwitchItemPrevClass = "CUP_optic_ElcanM145_3D";
	MRT_switchItemHintText = "$STR_CUP_dn_OpticsMode_2D";
};

// 3D variant
class CUP_optic_ElcanM145_3D: ItemCore
{
	author = "$STR_CUP_AUTHOR_STRING";
	dlc = "CUP_Weapons";
	scope = 1;
	inertia = 0.1;
	MRT_SwitchItemNextClass = "CUP_optic_ElcanM145";
	MRT_SwitchItemPrevClass = "CUP_optic_ElcanM145";
	MRT_switchItemHintText = "$STR_CUP_dn_OpticsMode_3D";
};

@10Dozen
Copy link
Contributor

10Dozen commented Jan 5, 2024

After some testing:

  • When 'Use PIP optics' option is disabled - 2D -> 3D switch works fine.

  • When PIP optics enabled - direct call of actual switch code works perfectly fine:

    [{
    params ["_unit", "", "_switchItem"];
    _unit addPrimaryWeaponItem _switchItem;
    ["CBA_attachmentSwitched", _this] call CBA_fnc_localEvent;
    }, [_unit, _currItem, _switchItem, _currWeaponType]] call CBA_fnc_execNextFrame;
    )

  • But direct call of [2, "next"] call CBA_accessory_fnc_switchAttachment; is buggy for some reason. However if exec call twice - in current and next frame - it works:

[2, "next"] call CBA_accessory_fnc_switchAttachment;
[{ [2, "next"] call CBA_accessory_fnc_switchAttachment; }] call CBA_fnc_execNextFrame;

Looks like there was a change in accessory functions in #1595.

Tried older version of the CBA_accessory_fnc_switchAttachment - https://raw.githubusercontent.com/CBATeam/CBA_A3/953cdfe1ff97c17c6e2fbcfa4a98dfaf81fdbf8e/addons/accessory/fnc_switchAttachment.sqf - and it works good, but i can't tell why :)

@10Dozen
Copy link
Contributor

10Dozen commented Jan 5, 2024

Something is wrong with this part:

if (_configs isEqualTo []) then {
_testItem = "";
} else {
_testItem = getText (_configs select 0);
if (_testItem == "") exitWith {};
if (_testItem == _currItem) exitWith { _testItem = ""; }; // same as start (full loop)
private _usageArray = GVAR(usageHash) getOrDefault [_testItem, []];
if ((_usageArray findIf {([_testItem] call _x) isEqualTo false}) == -1) then { // none returned false
_switchItem = _testItem;
};
};

TBH I don't quite understand what is the purpose of entire loop, but in this specific case the next happens:

  1. On first step it finds target class successfully, but as _testItem is not "" - iteration continues
Test item: CUP_optic_ElcanM145_PIP.
Configs found: [bin\config.bin/CfgWeapons/CUP_optic_ElcanM145_PIP/MRT_SwitchItemNextClass].
Configs not empty, test item class: CUP_optic_ElcanM145_3D,
Test against UsageArray passed.
_switchItem = CUP_optic_ElcanM145_3D.
  1. Tests found 3D item and successfully finds 'next' class for it. But again - _testItem is not empty and loop continues
Test item: CUP_optic_ElcanM145_3D.
Configs: [bin\config.bin/CfgWeapons/CUP_optic_ElcanM145_3D/MRT_SwitchItemNextClass].
Configs not empty, test item class: CUP_optic_ElcanM145.
Test against UsageArray passed.,
_switchItem = CUP_optic_ElcanM145.

Due to cyclic scheme of MRT Switch used for CUP scopes - loop continues until reaches execution limit (10000 iterations)

  1. Loop is terminated. Resulting in _switchItem to be "CUP_optic_ElcanM145". After switching, optics handlers replaces 2d scope to PIP variant. From player's perspective nothing was changed at all - the very same scope reamined.

When user is spamming switch button, i guess, sometimes script starts when 2D variant is added, but not yet replaced with PIP variant by optics. So in this case on loop termination - 3D variant is the last one and switch works.

When PIP optics is disabled, the loop is only 2 step -- on step 1 in 2D class config reference to 3D is found, on step 2 in 3D class config reference to 2D is found, and as reference is equal to original 2d variant class - loop breaks.

Previously no while loop was used, so _switchItem was picked from MRT_SwitchItemNextClass property and no additional checks were made.

@PabstMirror Could you, please, tell - is it possible to fix on CBA side or should CUP use diffrent MRT-switch scheme (and what scheme should be used)?

@Mike-MF
Copy link
Contributor

Mike-MF commented Apr 6, 2024

This is something I think I fixed.

Caused in CUP by having only a next cycle being Regular > 3D > PIP. Would be nice to have some people confirm this is no longer an issue before closing.

@10Dozen
Copy link
Contributor

10Dozen commented Apr 8, 2024

This is something I think I fixed.

Caused in CUP by having only a next cycle being Regular > 3D > PIP. Would be nice to have some people confirm this is no longer an issue before closing.

Works fine for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants