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

Add Timeout CBA_fnc_waitUntilAndExecute #560

Merged
merged 5 commits into from
Dec 27, 2016
Merged

Add Timeout CBA_fnc_waitUntilAndExecute #560

merged 5 commits into from
Dec 27, 2016

Conversation

654wak654
Copy link
Contributor

When merged this pull request will:

  • Title
  • Add _timeout and _timeoutCode params, put calls that use them in a new GVAR(waitUntilAndExecTimeoutArray) array to not add any overhead to the usual GVAR(waitUntilAndExecArray).

Separating the calls with timeout and without timeout into different arrays seemed like a better option then to add an overhead to everything that currently uses CBA's main PFH.

@@ -80,6 +80,22 @@ GVAR(waitUntilAndExecArray) = [];
if (_delete) then {
GVAR(waitUntilAndExecArray) = GVAR(waitUntilAndExecArray) - [objNull];
};

// Execute the waitUntilAndExecTimeout functions:
_delete = false;
Copy link
Contributor

@commy2 commy2 Nov 30, 2016

Choose a reason for hiding this comment

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

could move this line after L81, so the flag is only reset if it ever where changed to true. I think the same can be done above that once too. Minor performance improvement.


GVAR(waitUntilAndExecArray) pushBack [_condition, _statement, _args];
if (_timeout == 1E9) then {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe use isNil "_timeout" and have no default value / default value nil in params?
No one will ever use 1E9, but having a random high number seems weird. (Especially an integer above single point floating precision.)

Copy link
Contributor

Choose a reason for hiding this comment

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

How about default timeout value of -1,
and only use time if _timeout >= 0

Copy link
Contributor Author

@654wak654 654wak654 Nov 30, 2016

Choose a reason for hiding this comment

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

Could make default 0 and go for _timeout > 0, since 0 whould mean there is an immediate timeout.

if (_timeout == 1E9) then {
GVAR(waitUntilAndExecArray) pushBack [_condition, _statement, _args];
} else {
GVAR(waitUntilAndExecTimeoutArray) pushBack [_condition, _statement, _args, _timeout, _timeoutCode, time];
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we want CBA_missionTime instead of time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used time because it's to measure relative time on one machine, but I can change it.

@PabstMirror
Copy link
Contributor

Using this wrapper, we can use the existing waitUntilAndExecArray, and make no changes to init_perFrameHandler.sqf. So there would be no per-frame overhead.

if (_timeout == 1E9) then {
    GVAR(waitUntilAndExecArray) pushBack [_condition, _statement, _args];
} else {
    GVAR(waitUntilAndExecArray) pushBack [{
        params ["_condition", "_statement", "_args", "_timeout", "_timeoutCode"];

        if (CBA_missionTime > _timeout) exitWith {
            systemChat "timeout";
            _args call _timeoutCode;
            true
        };
        if (_args call _condition) exitWith {
            systemChat "condition";
            _args call _statement;
            true
        };
        false
    }, {}, [_condition, _statement, _args, _timeout, _timeoutCode, CBA_missionTime]];
};

@654wak654
Copy link
Contributor Author

The timeout condition is CBA_missionTime - _startTime > _timeout, but other than that your code works great Pabst. Also change default timeout to 0 and did that """optimization""" with _delete.

@commy2
Copy link
Contributor

commy2 commented Dec 13, 2016

lgtm

@commy2 commy2 added this to the 3.2 milestone Dec 13, 2016
@commy2 commy2 self-assigned this Dec 13, 2016
@Killswitch00 Killswitch00 merged commit e544c7d into CBATeam:master Dec 27, 2016
@654wak654 654wak654 deleted the waitAndExecTimeout branch December 27, 2016 21:07
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