Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Decompilation] [th04/th05] Handle subpixels at the C++ type level
I've had the idea to hide this implementation detail and improve code readability for some time now, but it obviously must still all inline, to be indistinguishable from a direct assignment of the correct value… … which, amazingly, it does! Even the static_cast from float to int. The latter allows us to exclusively implement this for float, since we do have to express the occasional value smaller than 16. Who needs macros anyway. Yay, C++ in TH04 and TH05 after all! Part of P0030, funded by zorg.
- Loading branch information
Showing
5 changed files
with
60 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* ReC98 | ||
* ----- | ||
* Types shared between TH04 and TH05 | ||
*/ | ||
|
||
/// Math | ||
/// ---- | ||
class Subpixel { | ||
private: | ||
int v; | ||
|
||
public: | ||
Subpixel() {} | ||
Subpixel(float screen_v) { *this = screen_v; } | ||
|
||
Subpixel& operator =(float screen_v) { | ||
v = static_cast<int>(screen_v * 16.0f); | ||
return *this; | ||
} | ||
}; | ||
|
||
struct SPPoint { | ||
Subpixel x, y; | ||
|
||
void set(float screen_x, float screen_y) { | ||
x = screen_x; | ||
y = screen_y; | ||
} | ||
}; | ||
|
||
typedef struct { | ||
SPPoint cur; | ||
SPPoint prev; | ||
SPPoint velocity; | ||
|
||
void init(float screen_x, float screen_y) { | ||
cur.x = screen_x; | ||
prev.x = screen_x; | ||
cur.y = screen_y; | ||
prev.y = screen_y; | ||
} | ||
} motion_t; | ||
/// ---- | ||
|
||
/// Score | ||
/// ----- | ||
extern unsigned long score_delta; | ||
|
||
void pascal near score_update_and_render(void); | ||
|
||
// Adds the entire score delta at once to the current score. | ||
void pascal score_delta_commit(void); | ||
/// ----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
*/ | ||
|
||
#include "ReC98.h" | ||
#include "th04/shared.h" | ||
#include "th04/shared.hpp" | ||
/// ------ |