-
Notifications
You must be signed in to change notification settings - Fork 757
Dragging - Fix corpse position desync #11396
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
Open
Dystopian
wants to merge
1
commit into
acemod:master
Choose a base branch
from
Dystopian:fix_dragging_corpse_position
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+92
−29
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| #include "..\script_component.hpp" | ||
| /* | ||
| * Author: johnb43, Dystopian | ||
| * Sets corpse position and direction and ensures synchronization in multiplayer. | ||
| * Must be executed globally. | ||
| * | ||
| * Arguments: | ||
| * 0: Corpse <OBJECT> | ||
| * 1: Direction <NUMBER> | ||
| * 2: Position ATL <ARRAY> | ||
| * | ||
| * Return Value: | ||
| * None | ||
| * | ||
| * Example: | ||
| * [cursorObject, 90, getPosATL player] call ace_dragging_fnc_moveCorpse | ||
| * | ||
| * Public: No | ||
| */ | ||
|
|
||
| #define MAX_CHECK_FRAMES 50 | ||
| #define POSITION_THRESHOLD 0.25 | ||
|
|
||
| #define STATE_POSITION_SET 0 | ||
| #define STATE_SYNC_PENDING 1 | ||
| #define STATE_VERIFY 2 | ||
|
|
||
| params ["_corpse", "_dir", "_posATL"]; | ||
| TRACE_5("moveCorpse",_dir,getDir _corpse,_posATL,getPosATL _corpse,getPosATL _corpse distance _posATL); | ||
|
|
||
| if (isNull _corpse) exitWith {}; | ||
|
|
||
| // Allow the corpse to be synced for JIP players | ||
| if (isServer) then { | ||
| GVAR(movedCorpses) pushBackUnique _corpse; | ||
| }; | ||
|
|
||
| // Sync the corpse with its position | ||
| private _fnc_syncCorpse = { | ||
| _this awake true; | ||
| [{ | ||
| _this awake false; | ||
| }, _this] call CBA_fnc_execNextFrame; | ||
| }; | ||
|
|
||
| // Check if the corpse is already close to the target | ||
| // If so, don't teleport | ||
| if (getPosATL _corpse distance _posATL < POSITION_THRESHOLD) exitWith { | ||
| [_fnc_syncCorpse, _corpse] call CBA_fnc_execNextFrame; | ||
| }; | ||
|
|
||
| // Set direction before position | ||
| _corpse setDir _dir; | ||
| _corpse setPosATL _posATL; | ||
| TRACE_3("initialMove",getDir _corpse,getPosATL _corpse,getPosATL _corpse distance _posATL); | ||
|
|
||
| if (getPosATL _corpse distance _posATL < POSITION_THRESHOLD) exitWith { | ||
| [_fnc_syncCorpse, _corpse] call CBA_fnc_execNextFrame; | ||
| }; | ||
|
|
||
| [{ | ||
| params ["_args", "_handle"]; | ||
| _args params ["_state", "_frameCounter", "_corpse", "_posATL", "_dir", "_fnc_syncCorpse"]; | ||
|
|
||
| if ( | ||
| _frameCounter > MAX_CHECK_FRAMES | ||
| || {isNull _corpse} | ||
| || {!isNull objectParent _corpse} | ||
| || {_corpse call EFUNC(common,owned)} | ||
| ) exitWith { | ||
| TRACE_3("end",_frameCounter,isNull _corpse,isNull objectParent _corpse); | ||
| _handle call CBA_fnc_removePerFrameHandler; | ||
| }; | ||
| _args set [1, _frameCounter + 1]; | ||
|
|
||
| // Wait one frame after sync | ||
| if (_state == STATE_SYNC_PENDING) exitWith {_args set [0, STATE_VERIFY]}; | ||
|
|
||
| if (getPosATL _corpse distance _posATL < POSITION_THRESHOLD) then { | ||
| if (_state == STATE_POSITION_SET) then { | ||
| _corpse call _fnc_syncCorpse; | ||
| _args set [0, STATE_SYNC_PENDING]; | ||
| }; | ||
| } else { | ||
| TRACE_4("retryMove",_frameCounter,getDir _corpse,getPosATL _corpse,getPosATL _corpse distance _posATL); | ||
| _corpse setDir _dir; | ||
| _corpse setPosATL _posATL; | ||
| _args set [0, STATE_POSITION_SET]; | ||
| }; | ||
| }, 0, [STATE_POSITION_SET, 1, _corpse, _posATL, _dir, _fnc_syncCorpse]] call CBA_fnc_addPerFrameHandler; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe be more accepting of some offset and only retry if it's really bad?
I'm not sure about this, just worried about doing
setPosATLmore than needed