Implement game state interpolation (WIP)
[neverball] / ball / game_common.h
index 3dcb01d..174c4a9 100644 (file)
@@ -2,6 +2,7 @@
 #define GAME_COMMON_H
 
 #include "lang.h"
+#include "solid_vary.h"
 
 /*---------------------------------------------------------------------------*/
 
@@ -59,6 +60,9 @@ const char *view_to_str(int);
 
 /*---------------------------------------------------------------------------*/
 
+extern const float GRAVITY_UP[];
+extern const float GRAVITY_DN[];
+
 struct game_tilt
 {
     float x[3], rx;
@@ -71,4 +75,46 @@ void game_tilt_grav(float h[3], const float g[3], const struct game_tilt *);
 
 /*---------------------------------------------------------------------------*/
 
+struct game_view
+{
+    float dc;                           /* Ideal view distance above ball    */
+    float dp;                           /* Ideal view distance above ball    */
+    float dz;                           /* Ideal view distance behind ball   */
+
+    float c[3];                         /* Current view center               */
+    float p[3];                         /* Current view position             */
+    float e[3][3];                      /* Current view reference frame      */
+
+    float a;                            /* Ideal view rotation about Y axis  */
+};
+
+void game_view_init(struct game_view *);
+void game_view_fly(struct game_view *, const struct s_vary *, float);
+
+/*---------------------------------------------------------------------------*/
+
+#define UPS 90
+#define DT  (1.0f / (float) UPS)
+
+/*
+ * Simple fixed time step scheme.
+ */
+
+struct lockstep
+{
+    void (*step)(float);
+
+    float dt;                           /* Time step length                  */
+    float at;                           /* Accumulator                       */
+    float ts;                           /* Time scale factor                 */
+};
+
+void lockstep_clr(struct lockstep *);
+void lockstep_run(struct lockstep *, float);
+void lockstep_scl(struct lockstep *, float);
+
+#define lockstep_blend(ls) ((ls)->at / (ls)->dt)
+
+/*---------------------------------------------------------------------------*/
+
 #endif