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 method to modify game time properly #190

Merged
merged 2 commits into from
Aug 22, 2016
Merged

Add method to modify game time properly #190

merged 2 commits into from
Aug 22, 2016

Conversation

tsjost
Copy link
Member

@tsjost tsjost commented Aug 10, 2016

...and make the time-cheaty debug keys not under/overflow the clock.

gameMinute += minutes;
gameHour += gameMinute / 60 - (backwards ? 1 : 0);

// Black mathgic? No. If the value is negative we want to wrap it around
Copy link

Choose a reason for hiding this comment

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

magic?

Copy link
Member Author

Choose a reason for hiding this comment

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

maths + magic

@tsjost
Copy link
Member Author

tsjost commented Aug 10, 2016

The unit tests require GameWorld and GameState, which are currently only available when RW_TEST_WITH_DATA is set (which it's not on the CI servers), so I've had to move the tests inside the #if -- even though they don't require any data.

@danhedron
Copy link
Member

This is good. Only 1 issue I can see: pressing [ doesn't roll the clock back an hour, it only alters the minutes. It looks like the test cases are correct and pick up this issue too.

@tsjost
Copy link
Member Author

tsjost commented Aug 10, 2016

@danhedron I don't understand what you mean. [ will move the clock back 30 minutes. If the clock is less than xx:30, the hour will be decremented. This is shown to work in the tests.

@danhedron
Copy link
Member

I get this output from the tests:

/home/dan/dev/openrw/tests/test_GameWorld.cpp(37): error in "test_offsetgametime": check 0 == gw.getHour() failed [0 != 1]
/home/dan/dev/openrw/tests/test_GameWorld.cpp(41): error in "test_offsetgametime": check 23 == gw.getHour() failed [23 != 1]
/home/dan/dev/openrw/tests/test_GameWorld.cpp(45): error in "test_offsetgametime": check 0 == gw.getHour() failed [0 != 2]
/home/dan/dev/openrw/tests/test_GameWorld.cpp(49): error in "test_offsetgametime": check 0 == gw.getHour() failed [0 != 2]
/home/dan/dev/openrw/tests/test_GameWorld.cpp(53): error in "test_offsetgametime": check 8 == gw.getHour() failed [8 != 10]
/home/dan/dev/openrw/tests/test_GameWorld.cpp(57): error in "test_offsetgametime": check 7 == gw.getHour() failed [7 != 10]
/home/dan/dev/openrw/tests/test_GameWorld.cpp(61): error in "test_offsetgametime": check 7 == gw.getHour() failed [7 != 11]
/home/dan/dev/openrw/tests/test_GameWorld.cpp(65): error in "test_offsetgametime": check 7 == gw.getHour() failed [7 != 11]
/home/dan/dev/openrw/tests/test_GameWorld.cpp(69): error in "test_offsetgametime": check 9 == gw.getHour() failed [9 != 13]
$ gcc --version                                                                                                                               Wed 10 Aug 22:12:48 BST 2016
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

@tsjost tsjost closed this Aug 10, 2016
@tsjost tsjost deleted the fix/timecheat branch August 10, 2016 21:22
@tsjost tsjost restored the fix/timecheat branch August 10, 2016 22:08
@tsjost tsjost reopened this Aug 10, 2016
@tsjost
Copy link
Member Author

tsjost commented Aug 13, 2016

@danhedron I force-pushed, please see if it works now? The previous code shouldn't have worked anywhere so I'm not sure why my tests passed.

@danhedron
Copy link
Member

Works for me. Tests are passing locally. +1

BOOST_CHECK_EQUAL(0, gw.getHour());
BOOST_CHECK_EQUAL(0, gw.getMinute());

gw.offsetGameTime(8*60 + 25);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that this is the only test case which goes forward by non-30 minute increments.
As we have 2 directions (+ and -) this is not enough to test all cases (do we know that -25 works?).

We should have more cases which give a remainder if 60 is divided by the minutes and we should have that in both directions (+ and -). I didn't think about this very much tho, so maybe it's useless.

@JayFoxRox
Copy link
Collaborator

Only found nits (see diff comments above).

Tested this locally - works fine. I'd like to have an option to reset or control the seconds too, but it'd be beyond the scope of this PR and I'm not sure how one could implement it easily either.

LGTM.

@danhedron danhedron merged commit 3a53089 into rwengine:master Aug 22, 2016
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.

4 participants