From 896af463abaf61586a30a4f95f034fe2ddc1e4da Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 23 Oct 2024 21:30:57 +1100 Subject: [PATCH] Pure classic mode: Don't allow chat scrolling --- src/Game.c | 2 ++ src/Generator.c | 21 +++++++++++---------- src/Screens.c | 1 + 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Game.c b/src/Game.c index 028f7e668..81ed15534 100644 --- a/src/Game.c +++ b/src/Game.c @@ -640,6 +640,8 @@ static CC_INLINE float ElapsedMilliseconds(cc_uint64 beg, cc_uint64 end) { cc_uint64 elapsed = Stopwatch_ElapsedMicroseconds(beg, end); if (elapsed > 5000000) elapsed = 5000000; + /* Avoid uint64 / float division, as that typically gets implemented */ + /* using a library function rather than a direct CPU instruction */ return (int)elapsed / 1000.0f; } diff --git a/src/Generator.c b/src/Generator.c index b3ccfed3d..f0bfc4a23 100644 --- a/src/Generator.c +++ b/src/Generator.c @@ -157,6 +157,13 @@ static void ImprovedNoise_Init(cc_uint8* p, RNGState* rnd) { } } +/* Normally, calculating Grad involves a function call + switch. However, the table combinations + can be directly packed into a set of bit flags (where each 2 bit combination indicates either -1, 0 1). + This avoids needing to call another function that performs branching */ +#define X_FLAGS 0x46552222 +#define Y_FLAGS 0x2222550A +#define Grad(hash, x, y) (((X_FLAGS >> (hash)) & 3) - 1) * (x) + (((Y_FLAGS >> (hash)) & 3) - 1) * (y); + static float ImprovedNoise_Calc(const cc_uint8* p, float x, float y) { int xFloor, yFloor, X, Y; float u, v; @@ -173,22 +180,16 @@ static float ImprovedNoise_Calc(const cc_uint8* p, float x, float y) { v = y * y * y * (y * (y * 6 - 15) + 10); /* Fade(y) */ A = p[X] + Y; B = p[X + 1] + Y; - /* Normally, calculating Grad involves a function call. However, we can directly pack this table - (since each value indicates either -1, 0 1) into a set of bit flags. This way we avoid needing - to call another function that performs branching */ -#define xFlags 0x46552222 -#define yFlags 0x2222550A - hash = (p[p[A]] & 0xF) << 1; - g22 = (((xFlags >> hash) & 3) - 1) * x + (((yFlags >> hash) & 3) - 1) * y; /* Grad(p[p[A], x, y) */ + g22 = Grad(hash, x, y); /* Grad(p[p[A], x, y) */ hash = (p[p[B]] & 0xF) << 1; - g12 = (((xFlags >> hash) & 3) - 1) * (x - 1) + (((yFlags >> hash) & 3) - 1) * y; /* Grad(p[p[B], x - 1, y) */ + g12 = Grad(hash, x - 1, y); /* Grad(p[p[B], x - 1, y) */ c1 = g22 + u * (g12 - g22); hash = (p[p[A + 1]] & 0xF) << 1; - g21 = (((xFlags >> hash) & 3) - 1) * x + (((yFlags >> hash) & 3) - 1) * (y - 1); /* Grad(p[p[A + 1], x, y - 1) */ + g21 = Grad(hash, x, y - 1); /* Grad(p[p[A + 1], x, y - 1) */ hash = (p[p[B + 1]] & 0xF) << 1; - g11 = (((xFlags >> hash) & 3) - 1) * (x - 1) + (((yFlags >> hash) & 3) - 1) * (y - 1); /* Grad(p[p[B + 1], x - 1, y - 1) */ + g11 = Grad(hash, x - 1, y - 1); /* Grad(p[p[B + 1], x - 1, y - 1) */ c2 = g21 + u * (g11 - g21); return c1 + v * (c2 - c1); diff --git a/src/Screens.c b/src/Screens.c index ff022e506..e27de0a64 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -1005,6 +1005,7 @@ static int ChatScreen_ClampChatIndex(int index) { static void ChatScreen_ScrollChatBy(struct ChatScreen* s, int delta) { int newIndex = ChatScreen_ClampChatIndex(s->chatIndex + delta); delta = newIndex - s->chatIndex; + if (Game_PureClassic) return; while (delta) { if (delta < 0) {