Skip to content

BugFix: recreate prior start stop-watch when it is created behaviour#3162

Closed
SlySven wants to merge 1 commit intoMudlet:developmentfrom
SlySven:BugFix_allowStopWatchesToStartRunningOnCreation
Closed

BugFix: recreate prior start stop-watch when it is created behaviour#3162
SlySven wants to merge 1 commit intoMudlet:developmentfrom
SlySven:BugFix_allowStopWatchesToStartRunningOnCreation

Conversation

@SlySven
Copy link
Copy Markdown
Member

@SlySven SlySven commented Oct 14, 2019

Also allow them to be created during the profile startup sequence when lua scripts are run on loading (but after a prior compilation to test for script validity has been done).

It wasn't obvious to me at the time but the old type of stopwatch had the characteristic that their mere creation was sufficient to start them running. My new design did not replicate that behaviour so it broke existing scripts that expected this. This commit restores that action IF createStopWatch() IS INVOKED WITHOUT ANY ARGUMENTS - as it would be if existing scripts used that API call. An optional boolean argument will prevent the auto-start if it is provided as a false but if a "name" for the stopwatch to be created it is assumed that the user wants the newer behaviour and then it will be created in a "stopped" and "reset" state. This may be overridden by a further boolean argument which in this case must be true to "autostart" the (named) stopwatch so created.

Signed-off-by: Stephen Lyons slysven@virginmedia.com

Also allow them to be created during the profile startup sequence when
lua scripts are run on loading (but after a prior compilation to test
for script validity has been done).

It wasn't obvious to me at the time but the old type of stopwatch had the
characteristic that their mere creation was sufficient to start them
running. My new design did not replicate that behaviour so it broke
existing scripts that expected this. This commit restores that action IF
`createStopWatch()` IS INVOKED WITHOUT ANY ARGUMENTS - as it would be if
existing scripts used that API call. An optional boolean argument will
prevent the auto-start if it is provided as a `false` but if a "name" for
the stopwatch to be created it is assumed that the user wants the newer
behaviour and then it will be created in a "stopped" and "reset" state.
This may be overridden by a further boolean argument which in this case
must be `true` to "autostart" the (named) stopwatch so created.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
@SlySven SlySven added this to the 4.2.0 milestone Oct 14, 2019
@SlySven SlySven requested a review from a team as a code owner October 14, 2019 19:11
@SlySven SlySven requested review from a team October 14, 2019 19:11
@add-deployment-links
Copy link
Copy Markdown

add-deployment-links bot commented Oct 14, 2019

Hey there! Thanks for helping Mudlet improve. 🌟

Test versions

You can directly test the changes here:

No need to install anything - just unzip and run.
Let us know if it works well, and if it doesn't, please give details.

@SlySven
Copy link
Copy Markdown
Member Author

SlySven commented Oct 14, 2019

This is needed to correct a defect found in the release-4.2.0 code - though as the squash-and-merge commit that caused the defect has been reverted that will need to be un-reverted before this can be applied to that branch...

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Oct 14, 2019

Thanks for thr fix! There is more than just this issue that I've heard - afaik new old functions accepted nil as an argument, new ones don't. There is also a difference in resetting behaviour that someone pointed out.

So the fix might be not so simple as reverting the revert and applying this, what do you think?

@SlySven
Copy link
Copy Markdown
Member Author

SlySven commented Oct 14, 2019

Old functions accepting nil as an argument but new not - what are the details?

Resetting behaviour? What are the details.

I think I recall that someone pointed out that getStopWatchTimer if used with a non-existent watchID would return -1.0 as an error indication - whereas the new one will return nil + an error message. Indeed since the new stop-watch design can return -1.0 as a valid elapsed time - one second before a preset interval has been reached - then the nil + message approach is the only sensible action now IMVHO.

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Oct 14, 2019

I don't have details. That's the problem. A lot of things are broken and the fix is not obvious.

I think we should revert the stopwatches for now and reintroduce them later once we're sure it all works. I didn't test the PR, it was huge, and it backfired...

@ndsamuelson
Copy link
Copy Markdown

ndsamuelson commented Oct 17, 2019

Well This version doesn't even allow me to log in. It force closes to desktop on login. #3161

@SlySven
Copy link
Copy Markdown
Member Author

SlySven commented Oct 17, 2019

🚨 That sounds like a serious failure - but what OS are you using - I just tried it but both Windows 10 and my Anti-virus complained and would have stopped the mudlet.exe application from running {after unzipping the whole archive file into a fresh location within my user name's part of the file-system}...

@ndsamuelson
Copy link
Copy Markdown

🚨 That sounds like a serious failure - but what OS are you using - I just tried it but both Windows 10 and my Anti-virus complained and would have stopped the mudlet.exe application from running {after unzipping the whole archive file into a fresh location within my user name's part of the file-system}...

Running windows 10, and I did disable antivirus just to see if that impacted it. It did not. I am however running an insider build if windows which could be the issue (never again will I do that. nightmare and a half).

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Oct 18, 2019

Does the force close happen on a new profile?

@SlySven
Copy link
Copy Markdown
Member Author

SlySven commented Oct 23, 2019

There was an issue in the 4.x release series involving Qt 5.13.x and maps saved in Mudlet map format 19 or above - when Qt 5.13 changed the way that QFonts are stored in map files which happens in those higher numbered map formats which were made the default in 4.1.0 and later. That would cause a crash when an existing map file was read that had been created by a version running with an older Qt version. See #3088 for the full details. It has been cured however so you should not be getting crashes from that cause in the current version.

However you say this is for a new profile which therefore will not have a map file to load AFAICT - unless, perhaps it is a profile for a MUD that has a UI and other packages including a preprepared binary map which is automagically downloaded and installed (not the IRE ones though - they use an XML format map file not Mudlet binary {.dat} file IIRC)...

SlySven added a commit to SlySven/Mudlet that referenced this pull request Nov 8, 2019
This commit is a rework of the original PR Mudlet#2516 squash-and-merged with the
bugfix that I proposed as PR Mudlet#3162 but which became difficult to apply when
the original PR was eliminated from the development branch because it has
been reverted from the 4.2.0 release and then that had been merged into
the development branch!

This PR allows stopwatches to be stopped and read at any time afterwards,
for any number of times. It also:
* allows stopwatches to be destroyed - so ID numbers WILL get reused - with
  a Lua (bool) destroyStopWatch((int) id) function.
* allows them to be marked as persistent so that they are saved with the
  profile and reloaded again - if they were running then they will continue
  to increment when the profile is not loaded so they can be used to
  real time events outside of the profile/session; this uses a new Lua function
  (bool) setStopWatchPersistence((int) id, (bool) setPersistent).
* allows them to be adjusted (even so they become negative) so can be used
  to count down as well as count up time - whether the stopwatch concerned
  is running or not.
* have error messages that conform to our current style
* have more run-time handling - most actions that produce no effect will
  advise that this is the case -  e.g. stopping a stopwatch that was NOT
  running...
* can handle periods of time longer than a day - the previous
  implementation wrapped around after 24 hours.
* should not affected by DST changes - OS permitting.
* the Lua API also gains a getStopWatches() function that returns a table
  with the id numbers as keys and values as tables of:
  * (bool) isRunning
  * (bool) isPersistent
  * (string) name
  * (table) elapsedTime - containing broken down time:
    * (bool) negative
    * (int) days
    * (int) hours (0 to 23)
    * (int) minutes (0 to 59)
    * (int) seconds (0 to 59)
    * (int) milliSeconds (0 to 999)
    * (float) decimalSeconds floating point value of whole of the time in
    seconds (can be negative!)
* allows stop watches to be named - which is useful as then they can be
  identified in scripts; this means that all the stop watch functions
  can now take a name string as well as a numeric argument. Using an empty
  string will access the first (lowest id) stopwatch that does not have a
  name and the createStopWatch() function will accept an optional string
  argument as a name.  For simplicity each name must be unique and this is
  enforced for that function and the added setStopWatchName(id or name,
  newName) function. The latter will also accept an empty string as either
  the first or second argument; in the first case it will assign the name
  to the first unnamed stopwatch and the second will clear the name of the
  specified one.
* added getStopWatchBrokenDownTime(...) which returns the same broken
  down elements in a table for a single specified timer (day count; hours;
  minutes; seconds; milliseconds and whether the time is positive or
  negative {when preset with a negative adjustment and used as a count
  down})...

During debugging I found out that the process of loading an existing
profile that contained createStopWatch() calls was creating them during
the testing/loading phase so I had to add extra code to prevent that
function from taking effect whilst (bool) ~~`Host::mIsProfileLoadingSequence`~~
*revised to use a different, new, flag: `Host::mBlockStopWatchCreation`
which is cleared earlier in the loading sequence* is true. Then, when
testing the resetProfile() function I found that the same thing was
happening AND that the non-persistent stopwatches needed to be removed as
well - which is now solved by also preventing stopwatch creation whilst
(bool) Host::mResetProfile is set and by running a new method
(void) Host::removeAllNonPersistentStopWatches()! This thus allows
stopwatches to be created during the profile startup sequence when
lua scripts are run on loading (but after a prior compilation to test
for script validity has been done).

The code in (void) stopWatch::Host::adjustMilliSeconds(const qint64)
originally used (QDateTime) QDateTime::addMSecs(qint64) incorrectly in
that I had thought it adjusted the QDateTime it was called upon whereas it
returns a reference to the adjusted value - so needed to be invoked in a
different manner which was already being done in the original PR.

QString stopWatch::getElapsedDayTimeString() const made use of int for
some intermediate local variables but on Windows platforms the int type may
be 32-bit long and thus not big enough to contain 64-bit values - and some
other locals can be much shorter because of the limits that the code places
on their values but will give compiler warnings without static_cast <T>.

Use std::chrono_literals to specify some needed time intervals rather than
large long integer literal constants.

Refactor a block of code used to generate the broken down time as a Lua
table so that two instances are handled by a single helper function.

Additional code (the bug fix) has been included to provide
backwards-compatibility for Lua startStopWatch(id) function which recreates
prior start stop-watch behaviour when it is created:

The prior form of startStopWatch(...) would reset and restart the indicated
stopwatch each time that it was called.  This is not really compatible with
the revised functionality which allows the recorded time to be adjusted
even before the stopwatch is first used.  To allow existing scripts to
continue to experience the same API this commit adds an optional second
boolean argument to the startStopWatch(...) call ONLY WHEN the first
argument is an id number and NOT a string name.  If the second argument is
omitted (as it will be when using older scripts) or is true then each time
the function is used the stopwatch will be reset and restarted. Just in
case the same behaviour ***is*** wanted with stop watch created with a
**name** then a second boolean `true` will start the stopwatch from zero.

This PR replaces (and thus will) close Mudlet#3162 .

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
SlySven added a commit to SlySven/Mudlet that referenced this pull request Nov 8, 2019
This commit is a rework of the original PR Mudlet#2516 squash-and-merged with the
bugfix that I proposed as PR Mudlet#3162 but which became difficult to apply when
the original PR was eliminated from the development branch because it has
been reverted from the 4.2.0 release and then that had been merged into
the development branch!

This PR allows stopwatches to be stopped and read at any time afterwards,
for any number of times. It also:
* allows stopwatches to be destroyed - so ID numbers WILL get reused - with
  a Lua (bool) destroyStopWatch((int) id) function.
* allows them to be marked as persistent so that they are saved with the
  profile and reloaded again - if they were running then they will continue
  to increment when the profile is not loaded so they can be used to
  real time events outside of the profile/session; this uses a new Lua function
  (bool) setStopWatchPersistence((int) id, (bool) setPersistent).
* allows them to be adjusted (even so they become negative) so can be used
  to count down as well as count up time - whether the stopwatch concerned
  is running or not.
* have error messages that conform to our current style
* have more run-time handling - most actions that produce no effect will
  advise that this is the case -  e.g. stopping a stopwatch that was NOT
  running...
* can handle periods of time longer than a day - the previous
  implementation wrapped around after 24 hours.
* should not affected by DST changes - OS permitting.
* the Lua API also gains a getStopWatches() function that returns a table
  with the id numbers as keys and values as tables of:
  * (bool) isRunning
  * (bool) isPersistent
  * (string) name
  * (table) elapsedTime - containing broken down time:
    * (bool) negative
    * (int) days
    * (int) hours (0 to 23)
    * (int) minutes (0 to 59)
    * (int) seconds (0 to 59)
    * (int) milliSeconds (0 to 999)
    * (float) decimalSeconds floating point value of whole of the time in
    seconds (can be negative!)
* allows stop watches to be named - which is useful as then they can be
  identified in scripts; this means that all the stop watch functions
  can now take a name string as well as a numeric argument. Using an empty
  string will access the first (lowest id) stopwatch that does not have a
  name and the createStopWatch() function will accept an optional string
  argument as a name.  For simplicity each name must be unique and this is
  enforced for that function and the added setStopWatchName(id or name,
  newName) function. The latter will also accept an empty string as either
  the first or second argument; in the first case it will assign the name
  to the first unnamed stopwatch and the second will clear the name of the
  specified one.
* added getStopWatchBrokenDownTime(...) which returns the same broken
  down elements in a table for a single specified timer (day count; hours;
  minutes; seconds; milliseconds and whether the time is positive or
  negative {when preset with a negative adjustment and used as a count
  down})...

During debugging I found out that the process of loading an existing
profile that contained createStopWatch() calls was creating them during
the testing/loading phase so I had to add extra code to prevent that
function from taking effect whilst (bool) ~~`Host::mIsProfileLoadingSequence`~~
*revised to use a different, new, flag: `Host::mBlockStopWatchCreation`
which is cleared earlier in the loading sequence* is true. Then, when
testing the resetProfile() function I found that the same thing was
happening AND that the non-persistent stopwatches needed to be removed as
well - which is now solved by also preventing stopwatch creation whilst
(bool) Host::mResetProfile is set and by running a new method
(void) Host::removeAllNonPersistentStopWatches()! This thus allows
stopwatches to be created during the profile startup sequence when
lua scripts are run on loading (but after a prior compilation to test
for script validity has been done).

The code in (void) stopWatch::Host::adjustMilliSeconds(const qint64)
originally used (QDateTime) QDateTime::addMSecs(qint64) incorrectly in
that I had thought it adjusted the QDateTime it was called upon whereas it
returns a reference to the adjusted value - so needed to be invoked in a
different manner which was already being done in the original PR.

QString stopWatch::getElapsedDayTimeString() const made use of int for
some intermediate local variables but on Windows platforms the int type may
be 32-bit long and thus not big enough to contain 64-bit values - and some
other locals can be much shorter because of the limits that the code places
on their values but will give compiler warnings without static_cast <T>.

Use std::chrono_literals to specify some needed time intervals rather than
large long integer literal constants.

Refactor a block of code used to generate the broken down time as a Lua
table so that two instances are handled by a single helper function.

Additional code (the bug fix) has been included to provide
backwards-compatibility for Lua startStopWatch(id) function which recreates
prior start stop-watch behaviour when it is created:

The prior form of startStopWatch(...) would reset and restart the indicated
stopwatch each time that it was called.  This is not really compatible with
the revised functionality which allows the recorded time to be adjusted
even before the stopwatch is first used.  To allow existing scripts to
continue to experience the same API this commit adds an optional second
boolean argument to the startStopWatch(...) call ONLY WHEN the first
argument is an id number and NOT a string name.  If the second argument is
omitted (as it will be when using older scripts) or is true then each time
the function is used the stopwatch will be reset and restarted. Just in
case the same behaviour ***is*** wanted with stop watch created with a
**name** then a second boolean `true` will start the stopwatch from zero.

This PR replaces (and thus will) close Mudlet#3162 .

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
@SlySven
Copy link
Copy Markdown
Member Author

SlySven commented Nov 8, 2019

This needs to be closed because the code that it was fixing has been erased from the development branch by the merge of the release-4.2 branch into it in 5f1725b and rather than reverting a reversion (which would have to be done in a different PR) and then applying this PR to the resulting code it is clearer to do it all in one in a new PR that combines the original (reverted changes AND this PR) - and that is what #3224 does...

@SlySven SlySven closed this Nov 8, 2019
@SlySven SlySven deleted the BugFix_allowStopWatchesToStartRunningOnCreation branch November 8, 2019 04:06
SlySven added a commit that referenced this pull request Nov 30, 2019
Redo_Enhance: overhaul stopwatches

This PR is a rework of the original PR #2516 squash-and-merged with the
bugfix that I proposed as PR #3162 but which became difficult to apply when
the original PR was eliminated from the development branch because it has
been reverted from the 4.2.0 release and then that had been merged into
the development branch!

This PR allows stopwatches to be stopped and read at any time afterwards,
for any number of times. It also:
* allows stopwatches to be destroyed - so ID numbers WILL get reused - with
  a Lua (bool) destroyStopWatch((int) id) function.
* allows them to be marked as persistent so that they are saved with the
  profile and reloaded again - if they were running then they will continue
  to increment when the profile is not loaded so they can be used to
  real time events outside of the profile/session; this uses a new Lua function
  (bool) setStopWatchPersistence((int) id, (bool) setPersistent).
* allows them to be adjusted (even so they become negative) so can be used
  to count down as well as count up time - whether the stopwatch concerned
  is running or not.
* have error messages that conform to our current style
* have more run-time handling - most actions that produce no effect will
  advise that this is the case -  e.g. stopping a stopwatch that was NOT
  running...
* can handle periods of time longer than a day - the previous
  implementation wrapped around after 24 hours.
* should not affected by DST changes - OS permitting.
* the Lua API also gains a getStopWatches() function that returns a table
  with the id numbers as keys and values as tables of:
  * (bool) isRunning
  * (bool) isPersistent
  * (string) name
  * (table) elapsedTime - containing broken down time:
    * (bool) negative
    * (int) days
    * (int) hours (0 to 23)
    * (int) minutes (0 to 59)
    * (int) seconds (0 to 59)
    * (int) milliSeconds (0 to 999)
    * (float) decimalSeconds floating point value of whole of the time in
    seconds (can be negative!)
* allows stop watches to be named - which is useful as then they can be
  identified in scripts; this means that all the stop watch functions
  can now take a name string as well as a numeric argument. Using an empty
  string will access the first (lowest id) stopwatch that does not have a
  name and the createStopWatch() function will accept an optional string
  argument as a name.  For simplicity each name must be unique and this is
  enforced for that function and the added setStopWatchName(id or name,
  newName) function. The latter will also accept an empty string as either
  the first or second argument; in the first case it will assign the name
  to the first unnamed stopwatch and the second will clear the name of the
  specified one.
* added getStopWatchBrokenDownTime(...) which returns the same broken
  down elements in a table for a single specified timer (day count; hours;
  minutes; seconds; milliseconds and whether the time is positive or
  negative {when preset with a negative adjustment and used as a count
  down})...

During debugging I found out that the process of loading an existing
profile that contained createStopWatch() calls was creating them during
the testing/loading phase so I had to add extra code to prevent that
function from taking effect whilst (bool) ~~`Host::mIsProfileLoadingSequence`~~
*revised to use a different, new, flag: `Host::mBlockStopWatchCreation`
which is cleared earlier in the loading sequence* is true. Then, when
testing the resetProfile() function I found that the same thing was
happening AND that the non-persistent stopwatches needed to be removed as
well - which is now solved by also preventing stopwatch creation whilst
(bool) Host::mResetProfile is set and by running a new method
(void) Host::removeAllNonPersistentStopWatches()! This thus allows
stopwatches to be created during the profile startup sequence when
lua scripts are run on loading (but after a prior compilation to test
for script validity has been done).

The code in (void) stopWatch::Host::adjustMilliSeconds(const qint64)
originally used (QDateTime) QDateTime::addMSecs(qint64) incorrectly in
that I had thought it adjusted the QDateTime it was called upon whereas it
returns a reference to the adjusted value - so needed to be invoked in a
different manner which was already being done in the original PR.

QString stopWatch::getElapsedDayTimeString() const made use of int for
some intermediate local variables but on Windows platforms the int type may
be 32-bit long and thus not big enough to contain 64-bit values - and some
other locals can be much shorter because of the limits that the code places
on their values but will give compiler warnings without static_cast <T>.

Use std::chrono_literals to specify some needed time intervals rather than
large long integer literal constants.

Refactor a block of code used to generate the broken down time as a Lua
table so that two instances are handled by a single helper function.

Additional code (the bug fix) has been included to provide
backwards-compatibility for Lua startStopWatch(id) function which recreates
prior start stop-watch behaviour when it is created:

The prior form of startStopWatch(...) would reset and restart the indicated
stopwatch each time that it was called.  This is not really compatible with
the revised functionality which allows the recorded time to be adjusted
even before the stopwatch is first used.  To allow existing scripts to
continue to experience the same API this commit adds an optional second
boolean argument to the startStopWatch(...) call ONLY WHEN the first
argument is an id number and NOT a string name.  If the second argument is
omitted (as it will be when using older scripts) or is true then each time
the function is used the stopwatch will be reset and restarted. Just in
case the same behaviour ***is*** wanted with stop watch created with a
**name** then a second boolean `true` will start the stopwatch from zero.

This PR replaces (and thus will) close #3162 .

A separate commit was appended and squashed in to reduce a code
duplication pointed out by CodeFactor:

Created a single function that is used to do the same thing in four
separate stop-watch functions.

Signed-off by: Stephen Lyons <slysven@virginmedia.com
dicene pushed a commit to dicene/Mudlet that referenced this pull request Feb 19, 2020
Redo_Enhance: overhaul stopwatches

This PR is a rework of the original PR Mudlet#2516 squash-and-merged with the
bugfix that I proposed as PR Mudlet#3162 but which became difficult to apply when
the original PR was eliminated from the development branch because it has
been reverted from the 4.2.0 release and then that had been merged into
the development branch!

This PR allows stopwatches to be stopped and read at any time afterwards,
for any number of times. It also:
* allows stopwatches to be destroyed - so ID numbers WILL get reused - with
  a Lua (bool) destroyStopWatch((int) id) function.
* allows them to be marked as persistent so that they are saved with the
  profile and reloaded again - if they were running then they will continue
  to increment when the profile is not loaded so they can be used to
  real time events outside of the profile/session; this uses a new Lua function
  (bool) setStopWatchPersistence((int) id, (bool) setPersistent).
* allows them to be adjusted (even so they become negative) so can be used
  to count down as well as count up time - whether the stopwatch concerned
  is running or not.
* have error messages that conform to our current style
* have more run-time handling - most actions that produce no effect will
  advise that this is the case -  e.g. stopping a stopwatch that was NOT
  running...
* can handle periods of time longer than a day - the previous
  implementation wrapped around after 24 hours.
* should not affected by DST changes - OS permitting.
* the Lua API also gains a getStopWatches() function that returns a table
  with the id numbers as keys and values as tables of:
  * (bool) isRunning
  * (bool) isPersistent
  * (string) name
  * (table) elapsedTime - containing broken down time:
    * (bool) negative
    * (int) days
    * (int) hours (0 to 23)
    * (int) minutes (0 to 59)
    * (int) seconds (0 to 59)
    * (int) milliSeconds (0 to 999)
    * (float) decimalSeconds floating point value of whole of the time in
    seconds (can be negative!)
* allows stop watches to be named - which is useful as then they can be
  identified in scripts; this means that all the stop watch functions
  can now take a name string as well as a numeric argument. Using an empty
  string will access the first (lowest id) stopwatch that does not have a
  name and the createStopWatch() function will accept an optional string
  argument as a name.  For simplicity each name must be unique and this is
  enforced for that function and the added setStopWatchName(id or name,
  newName) function. The latter will also accept an empty string as either
  the first or second argument; in the first case it will assign the name
  to the first unnamed stopwatch and the second will clear the name of the
  specified one.
* added getStopWatchBrokenDownTime(...) which returns the same broken
  down elements in a table for a single specified timer (day count; hours;
  minutes; seconds; milliseconds and whether the time is positive or
  negative {when preset with a negative adjustment and used as a count
  down})...

During debugging I found out that the process of loading an existing
profile that contained createStopWatch() calls was creating them during
the testing/loading phase so I had to add extra code to prevent that
function from taking effect whilst (bool) ~~`Host::mIsProfileLoadingSequence`~~
*revised to use a different, new, flag: `Host::mBlockStopWatchCreation`
which is cleared earlier in the loading sequence* is true. Then, when
testing the resetProfile() function I found that the same thing was
happening AND that the non-persistent stopwatches needed to be removed as
well - which is now solved by also preventing stopwatch creation whilst
(bool) Host::mResetProfile is set and by running a new method
(void) Host::removeAllNonPersistentStopWatches()! This thus allows
stopwatches to be created during the profile startup sequence when
lua scripts are run on loading (but after a prior compilation to test
for script validity has been done).

The code in (void) stopWatch::Host::adjustMilliSeconds(const qint64)
originally used (QDateTime) QDateTime::addMSecs(qint64) incorrectly in
that I had thought it adjusted the QDateTime it was called upon whereas it
returns a reference to the adjusted value - so needed to be invoked in a
different manner which was already being done in the original PR.

QString stopWatch::getElapsedDayTimeString() const made use of int for
some intermediate local variables but on Windows platforms the int type may
be 32-bit long and thus not big enough to contain 64-bit values - and some
other locals can be much shorter because of the limits that the code places
on their values but will give compiler warnings without static_cast <T>.

Use std::chrono_literals to specify some needed time intervals rather than
large long integer literal constants.

Refactor a block of code used to generate the broken down time as a Lua
table so that two instances are handled by a single helper function.

Additional code (the bug fix) has been included to provide
backwards-compatibility for Lua startStopWatch(id) function which recreates
prior start stop-watch behaviour when it is created:

The prior form of startStopWatch(...) would reset and restart the indicated
stopwatch each time that it was called.  This is not really compatible with
the revised functionality which allows the recorded time to be adjusted
even before the stopwatch is first used.  To allow existing scripts to
continue to experience the same API this commit adds an optional second
boolean argument to the startStopWatch(...) call ONLY WHEN the first
argument is an id number and NOT a string name.  If the second argument is
omitted (as it will be when using older scripts) or is true then each time
the function is used the stopwatch will be reset and restarted. Just in
case the same behaviour ***is*** wanted with stop watch created with a
**name** then a second boolean `true` will start the stopwatch from zero.

This PR replaces (and thus will) close Mudlet#3162 .

A separate commit was appended and squashed in to reduce a code
duplication pointed out by CodeFactor:

Created a single function that is used to do the same thing in four
separate stop-watch functions.

Signed-off by: Stephen Lyons <slysven@virginmedia.com
@SlySven SlySven restored the BugFix_allowStopWatchesToStartRunningOnCreation branch June 22, 2020 17:59
@SlySven SlySven deleted the BugFix_allowStopWatchesToStartRunningOnCreation branch June 22, 2020 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants