ref: 95ba852b92acfc26469e8382e101e3953241d946
parent: f3df3f65611f02d0322be2009416fc60f89da4cc
author: Jacob Moody <moody@posixcafe.org>
date: Sun Aug 27 17:25:31 EDT 2023
fix min and max usage and cleanup speedo init min and max we used were always casting to int, this caused the system to not advance ticks. just use hud_init for speedo init
--- a/src/render_software.c
+++ b/src/render_software.c
@@ -151,9 +151,9 @@
vec2i_t sc2 = vec2i(p2.x * w2 + w2, h2 - p2.y * h2);
rgba_t color = tris.vertices[0].color;
- color.as_rgba.r = min(color.as_rgba.r * 2, 255);
- color.as_rgba.g = min(color.as_rgba.g * 2, 255);
- color.as_rgba.b = min(color.as_rgba.b * 2, 255);
+ color.as_rgba.r = minint(color.as_rgba.r * 2, 255);
+ color.as_rgba.g = minint(color.as_rgba.g * 2, 255);
+ color.as_rgba.b = minint(color.as_rgba.b * 2, 255);
float _v = color.as_rgba.a * (1.0-p0.z) * FAR_PLANE * (2.0/255.0);
float _min = 0;
--- a/src/system.c
+++ b/src/system.c
@@ -33,7 +33,7 @@
double time_real_now = platform_now();
double real_delta = time_real_now - time_real;
time_real = time_real_now;
- tick_last = min(real_delta, 0.1) * time_scale;
+ tick_last = minfloat(real_delta, 0.1) * time_scale;
time_scaled += tick_last;
// FIXME: come up with a better way to wrap the cycle_time, so that it
--- a/src/utils.h
+++ b/src/utils.h
@@ -10,21 +10,31 @@
#endif
#define member_size(type, member) sizeof(((type *)0)->member)
-#ifdef __plan9__
-
static int
-max(int a, int b)
+maxint(int a, int b)
{
return a > b ? a : b;
}
static int
-min(int a, int b)
+minint(int a, int b)
{
return a < b ? a : b;
}
-#else
+static float
+maxfloat(float a, float b)
+{
+ return a > b ? a : b;
+}
+
+static float
+minfloat(float a, float b)
+{
+ return a < b ? a : b;
+}
+
+#if 0
#define max(a,b) ({ \
__typeof__ (a) _a = (a); \
--- a/src/wipeout/game.c
+++ b/src/wipeout/game.c
@@ -597,7 +597,7 @@
double frame_start_time = platform_now();
int sh = render_size().y;
- int scale = max(1, sh >= 720 ? sh / 360 : sh / 240);
+ int scale = maxint(1, sh >= 720 ? sh / 360 : sh / 240);
if (save.ui_scale && save.ui_scale < scale) {
scale = save.ui_scale;
}
--- a/src/wipeout/hud.c
+++ b/src/wipeout/hud.c
@@ -24,7 +24,7 @@
rgba_t color;
} speedo_bar_t;
-const struct {
+struct {
uint16_t width;
uint16_t skew;
speedo_bar_t bars[13];
@@ -55,6 +55,7 @@
static uint16_t speedo_facia_texture;
void hud_load() {
+ initspeedo();
speedo_facia_texture = image_get_texture("wipeout/textures/speedo.tim");
target_reticle = image_get_texture_semi_trans("wipeout/textures/target2.tim");
weapon_icon_textures = image_get_compressed_textures("wipeout/common/wicons.cmp");
@@ -155,7 +156,6 @@
}
static void hud_draw_speedo_bars(vec2i_t *pos, float f, rgba_t color_override) {
- static int donespeedoinit = 0;
if (f <= 0) {
return;
}
@@ -167,10 +167,6 @@
f = 13;
}
- if(!donespeedoinit){
- initspeedo();
- donespeedoinit = 1;
- }
int bars = f;
for (int i = 1; i < bars; i++) {
hud_draw_speedo_bar(pos, &speedo.bars[i - 1], &speedo.bars[i], 1, color_override);
@@ -223,7 +219,7 @@
}
// Current Lap
- int display_lap = max(0, ship->lap + 1);
+ int display_lap = maxint(0, ship->lap + 1);
ui_draw_text("LAP", ui_scaled(vec2i(15, 8)), UI_SIZE_8, UI_COLOR_ACCENT);
ui_draw_number(display_lap, ui_scaled(vec2i(10, 19)), UI_SIZE_16, UI_COLOR_DEFAULT);
int width = ui_char_width('0' + display_lap, UI_SIZE_16);
--- a/src/wipeout/ship_player.c
+++ b/src/wipeout/ship_player.c
@@ -460,10 +460,10 @@
// Orientation
if (self->angular_acceleration.y == 0) {
if (self->angular_velocity.y > 0) {
- self->angular_acceleration.y -= min(self->turn_rate, self->angular_velocity.y / system_tick());
+ self->angular_acceleration.y -= minfloat(self->turn_rate, self->angular_velocity.y / system_tick());
}
else if (self->angular_velocity.y < 0) {
- self->angular_acceleration.y += min(self->turn_rate, -self->angular_velocity.y / system_tick());
+ self->angular_acceleration.y += minfloat(self->turn_rate, -self->angular_velocity.y / system_tick());
}
}