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
Refactor Velocity Literals to use _mph
#14010
Comments
|
Hi Can I have a go at this issue? |
|
Sure go ahead. |
|
@duncanspumpkin which file should I add string literal code to? I can't find a file similar to Types.hpp |
|
https://github.com/OpenRCT2/OpenRCT2/blob/develop/src/openrct2/common.h would probably be the best location. We have placed the money equivalents of this in there. Tbh we could probably do with changing the money macros to use a literal like this as well. |
|
@michiboo i did a bit more experimenting and i think my code can be slightly improved to provide higher precession. Might be useful for some literals that are harder to represent like 0.33333. |
|
@duncanspumpkin I have some problem trying to build it on ubuntu , is there a build guide somewhere? |
|
https://github.com/OpenRCT2/OpenRCT2/wiki/Building-OpenRCT2-on-Linux is our guide. @janisozaur can help you out if you provide information on what the issue is but please follow the guide first. |
|
@janisozaur Hi i got this error when trying make I had tried sudo apt install nlohmann-json-dev already. Can you please help? |
|
You're probably using outdated version of the package. We require at least 3.6 (if memory serves me right) |
|
Can I give it a try for this issue ? |
|
Sure. OpenLoco has a great example of this https://github.com/OpenLoco/OpenLoco/blob/master/src/OpenLoco/Speed.hpp we've been using it for quite a while now with no noticable issues. Strongly suggest pretty much copying Speed.hpp and modifying it to follow the coding style of OpenRCT2. |
|
Replacing Should the |
|
If you look at my final code for OpenLoco I made it a signed value for speed. |
In our sister project I introduced the
_mphliteral for speeds OpenLoco/OpenLoco#736I'm almost definitely the underlying units are the same in OpenRCT2. Therefore we should bring in the same changes. First add the string literal code. Then find all of the velocity literals in the vehicle code.
Its quite easy to do just convert the literal to hex so
393216=0x60000in hex then you drop the 40's to get0x6which is the speed in6.0_mphhttps://github.com/OpenRCT2/OpenRCT2/blob/develop/src/openrct2/ride/Vehicle.cpp#L5651
becomes
You can use static_asserts to confirm that the values are identical
static_assert(2.75_mph == 0x2C000);The text was updated successfully, but these errors were encountered: