Pure classic mode: Don't allow chat scrolling

This commit is contained in:
UnknownShadow200 2024-10-23 21:30:57 +11:00
parent 9ebf3fec6d
commit 896af463ab
3 changed files with 14 additions and 10 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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) {