Skip to content

feature(generic-binocs-target): make binocs target ui standalone - #787

Open
nltp-ashes wants to merge 7 commits into
themrdemonized:all-in-one-vs2022-wpofrom
nltp-ashes:feature/generic-binocs-target
Open

nltp-ashes wants to merge 7 commits into
themrdemonized:all-in-one-vs2022-wpofrom
nltp-ashes:feature/generic-binocs-target

Conversation

@nltp-ashes

Copy link
Copy Markdown
Contributor

Hello,

This PR make the the binoculars targeting system thing standalone, so it can be used without an item.

TL;DR : no change except bug fixes for vanilla, but now mods can show the target UI whenever they want, and don't require to have it attached to an item.

In truth, it's a slightly bigger change than that : this system used to be a simple cpp class attached by composition to CWeapon and CWeaponBinoculars. It acted as a UI (it even had a similar Update/Draw methods setup as CUIWindow) but it wasn't one.

CBinocularsVision became CUIBinocularsVision: a CUIWindow exported to Lua, moved in the sources to ui/. SBinocVisibleObj became CUIBinocularsVisionObject, also a CUIWindow.

Small modifications were done so the code actually behaves as a UI class : CBinocularsVision used to manage the lifecycle of its SBinocVisibleObj by hand, by calling create, update, draw and destroy at the appropriate times. Now, CUIBinocularsVisionObject are attached as child of CUIBinocularsVision, so part of its lifecycle is handled by CUIWindow.

I added the whole UI setup : down-casts from CUIWindow (to add to the ones I created in a previous PR), a helper method in CScriptXmlInit to setup a binoc UI from XML.

The vanilla CWeapon and CWeaponBinoculars are rewired to the new UI by using a specific constructor that reads values from an item section, as it did before. This constructor is also exposed to Lua... I don't need it but I figured it wouldn't hurt in case someone in the future would need it.

If you want more info :

  • I moved the vanilla corner textures to a new texture description file. They used to be cropped from the texture directly in the cpp code.
  • The found_snd and catch_snd sounds are now regular sounds instead of layered collections. Layered collections seems way overkill for just beep sound effects... If this ends up breaking some mods I'll re-add support for layered collections in a future PR.
  • Targets are tracked by id instead of by instance, which removes need for clean-ups. Claude says this might also have fixed a memory leak because remove_links erased entries without deleting them.
  • This PR also fix a bug caused mostly by shader based 2d scopes, which caused the targets to not be scaled to the fake zoom. Now, the targets get scaled if they are in the inner circle of the scope, and they are hidden if they are outside of the scope.
  • It also fixed a bug caused by some configs setting a crazy high value to rotation speed causing the frames to never show because they diverged off-screen. If it was a way for them to intentionally exploit a bug to "opt out" of the target system, they should either just not implement it, or use transparent textures & no sound.

This code (not this description tho, I always write those myself) was integrally written by Claude. I've reviewed every change, and cannot see any further improvements to make.

Demo : https://youtu.be/vq6H5mfWrIQ

- Made CBinocularsVision a generic UI class under the CUIBinocularsVision name;
- Added script exports for it;
- Added a new constructor and getters/setters for customizability;
- Added new texture descriptions to replace hard-coded textures in the class;
- Made SBinocVisibleObj a UI class under the CUIBinocularsVisionObject name;
- CUIBinocularsVisionObject corners are now child of the CUIBinocularsVision UI, which removes need for manual state management;
- Added CScriptXmlInit helper to instantiate a CUIBinocularsVision from an XML template;
- Fix targets being misaligned because of shader based 2d scopes;
- Detector scopes (scope_alive_detector with speed 10000) never showed frames because they diverged off-screen.
…ed 2d scope

- If shader based 2d scope is enabled, targets are now only rendered inside the scope;

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant