args.o: args.h
-dust.o: globals.h dust.h mt.h
+dust.o: globals.h dust.h float.h mt.h
file.o: file.h common.h
-main.o: args.h common.h dust.h file.h globals.h mt.h rocks.h score.h sprite.h sound.h
+main.o: args.h common.h dust.h file.h float.h globals.h mt.h rocks.h score.h sprite.h sound.h
mt.o: mt.h
#include "config.h"
#include "globals.h"
#include "dust.h"
+#include "float.h"
#include "mt.h"
struct dust_mote {
struct dust_mote motes[N_DUST_MOTES];
-// lower bound to ensure that we don't lose precision when wrapping.
-static float zero;
-
void
init_dust(void)
{
b = (MAX_DUST_DEPTH - motes[i].z) * 255.0 / MAX_DUST_DEPTH;
motes[i].color = SDL_MapRGB(surf_screen->format, b, b, b);
}
-
- zero = pow(-10, ceil(log10(XSIZE)) - FLT_DIG);
}
void
for(i=0; i<N_DUST_MOTES; i++) {
motes[i].x -= xscroll / (1.3 + motes[i].z);
- if(motes[i].x >= XSIZE) motes[i].x -= XSIZE;
- else if(motes[i].x < zero) motes[i].x += XSIZE;
+ motes[i].x = fwrap(motes[i].x, XSIZE);
motes[i].y -= yscroll / (1.3 + motes[i].z);
- if(motes[i].y >= YSIZE) motes[i].y -= YSIZE;
- else if(motes[i].y < zero) motes[i].y += YSIZE;
+ motes[i].y = fwrap(motes[i].y, YSIZE);
}
}
--- /dev/null
+#ifndef VOR_FLOAT_H
+#define VOR_FLOAT_H
+
+#include <math.h>
+
+static inline int
+fclip(float f, float max)
+{
+ return f < 0 || (float)f >= (float)max;
+}
+
+static inline float
+fwrap(float f, float max)
+{
+ if((float)f >= (float)max) f = (float)f - (float)max;
+ else if(f < 0) {
+ f += max;
+ if((float)f >= (float)max) f = nextafterf(f, 0);
+ }
+ return f;
+}
+
+#endif // VOR_FLOAT_H
#include "config.h"
#include "dust.h"
#include "file.h"
+#include "float.h"
#include "globals.h"
#include "mt.h"
#include "rocks.h"
// move and clip
bdot[i].x += (bdot[i].dx - screendx)*ticks;
bdot[i].y += (bdot[i].dy - screendy)*ticks;
- if(bdot[i].x < 0 || bdot[i].x >= (XSIZE - 0.000001) || bdot[i].y < 0 || bdot[i].y >= (YSIZE - 0.000001)) {
+ if(fclip(bdot[i].x, XSIZE) || fclip(bdot[i].y, YSIZE)) {
bdot[i].active = 0;
continue;
}
edot[i].x += (edot[i].dx - screendx)*ticks;
edot[i].y += (edot[i].dy - screendy)*ticks;
edot[i].life -= t_frame*3;
- if(edot[i].life < 0 || edot[i].x<0 || edot[i].x >= (XSIZE - 0.000001) || edot[i].y < 0 || edot[i].y >= (YSIZE - 0.000001)) {
+ if(edot[i].life < 0 || fclip(edot[i].x, XSIZE) || fclip(edot[i].y, YSIZE)) {
edot[i].active = 0;
continue;
}