|
unmoving
v0.1.0
More convenient fixed-point arithmetic for the Sony PlayStation
|
Unmoving is a C++ header-only library providing more convenient fixed-point arithmetic for the Sony PlayStation ("PS1"), in the form of a C++ class that wraps the native integer type used by the console standard library for performing fixed-point calculations. This class is intended to remove much of the more tedious aspects of the boilerplate code required to handle numbers in this way. The author hopes that it is useful.
Unmoving is written in C++20 and can target the PlayStation or most desktop OSes. In all cases, you will need a recent C++ compiler in order to build C++20 code.
For getting a toolchain that can target the PlayStation and which can compile C++20 code, you will need to compile a toolchain yourself. I recommend following the instructions in PSn00bSDK (which this project is tested with) for manually compiling toolchains (https://github.com/Lameguy64/PSn00bSDK/blob/ffa679d4d24b891cb59aba10946368f2ec00c391/toolchain.txt), but choose newer versions of Binutils and GCC than are specified.
I used Binutils 2.37 and GCC 10.3.0.
Of course, as this is a header-only library, you could just head over to the releases page on Github and download the latest version of it from there and then put it in your include path to use it in your projects.
Alternatively, you can fetch the project with CMake if you like. You need CMake 3.15 or newer to do this.
A convenient way to do this is to use CPM (https://github.com/cpm-cmake/CPM.cmake) to fetch the project from Github for you:
Or if you don't want to use a third-party CMake tool, CMake's FetchContent() API can be used in a similar way instead.
You could also clone this project's source code, build and install it with CMake and then use CMake's find_package() to use it in your project. CPMFindPackage() will also use locally-installed packages if you install it this way.
You can then link your build targets to Unmoving in the typical way:
This project is licensed under the Mozilla Public License v2.0.
This is a permissive copyleft software license which applies the copyleft provisions to this project's source code only. This means you can use it in any project, whether open-source or not, without needing to disclose your source. However, if you make modifications to this project which you include in a project that you distribute (even a closed-source one), you are required to share the modifications you made to this project, but these parts only.
Basically, if you modify Unmoving and distribute it, you need to publish your modifications.
Because PSXFixed objects implicitly cast to their base integer type, it is possible to use them more or less as a drop-in replacement for "raw" integers for fixed-point maths, including being able to pass them into and out of the PSX standard library functions such as rcos() and friends.
The only thing one has to be careful about is avoiding implicit integer conversions when the intention is to convert by value rather than raw bit-pattern, as demonstrated in the sample code above. PSXFixed::from_integer() and PSXFixed::to_integer() are provided for such value-conversions.
Further reading: API reference
Unmoving has a thorough unit test suite, however this cannot be built for the PlayStation due the extensive C++ library dependencies of the test suite itself. This test suite is run in CI for Linux, macOS and Windows. You can run the tests yourself by building the project in Debug mode or with ENABLE_TESTS=ON with CMake:
The author of this software was very new to PlayStation programming at the time he wrote it, although having decent knowledge of C and C++. As such, there are no doubt going to be some oversights made on his part about the intricacies of PSX programming that haven't been considered in the project's design or implementation.
If you feel something is missing or can be improved, I would be very grateful for your input and invite you to contribute issues or pull requests at this project's page on Github: https://github.com/saxbophone/unmoving.
Big thanks to Lameguy64 for both his series of tutorials on PlayStation programming (the fixed-point arithmetic section of which was particularly helpful in the making of this software) and for his open-source PSX SDK PSn00bSDK, which this project is tested with and which I thoroughly recommend checking out. Your work inspires me, sir!
"What do you call a decimal point which sticks around in the same place?"
...
UNMOVING!