changes from carve
authorhgn <hgodden00@gmail.com>
Sat, 28 May 2022 23:56:10 +0000 (00:56 +0100)
committerhgn <hgodden00@gmail.com>
Sat, 28 May 2022 23:56:10 +0000 (00:56 +0100)
src/vg/vg.h
src/vg/vg_input.h
src/vg/vg_lines.h
src/vg/vg_m.h
vg_compiler.sh

index ad508fb7a2457a0ce907ac20d1ba6484555d1872..681930af4cd2f7c32140c891adf9c6ae9edd6a38 100644 (file)
@@ -211,20 +211,7 @@ static void vg_init( int argc, char *argv[], const char *window_name )
    
    vg_run_gfx_diagnostics();
    
-   for( int id = 0; id <= GLFW_JOYSTICK_LAST; id ++ )
-   {
-      if( glfwJoystickIsGamepad( id ) )
-      {
-         vg_gamepad_name = glfwGetGamepadName( id );
-         vg_success( "Gamepad with mapping registered: %s\n", vg_gamepad_name );
-         
-         vg_gamepad_ready = 1;
-         vg_gamepad_id = id;
-         
-         break;
-      }
-   }
-   
+   vg_gamepad_init();
    vg_lines_init();
    vg_register_exit( &vg_lines_free, "vg_lines_free" );
    ui_default_init();
index 4818d52ab099c3aa10813e93104522cdc00f7eb9..bbc2f84dad13c5dc43e86586044eb1eaa7d7c169 100644 (file)
@@ -122,6 +122,12 @@ int get_button_cross_device( int const id )
 
 void vg_update_inputs(void)
 {
+   if( !glfwGetGamepadState( GLFW_JOYSTICK_1, &vg_gamepad) )
+   {
+      vg_gamepad_ready = 0;
+   }
+   
+
        /* Update button inputs */
        for( int i = 0; i < vg_list_size( vg_button_binds ); i ++ )
        {
@@ -142,15 +148,28 @@ void vg_update_inputs(void)
        for( int i = 0; i < vg_list_size( vg_axis_binds ); i ++ )
        {
                struct axis_binding *binding = vg_axis_binds + i;
-               
-               if( vg_input_mode == k_EInputMode_pc )
-               {
-                       binding->value  = get_button_cross_device( binding->positive );
-                       binding->value -= get_button_cross_device( binding->negative );
-               }
-               else
-               {
-                       binding->value = vg_gamepad.axes[ binding->bind ];
-               }
+      binding->value = vg_gamepad.axes[ binding->bind ];
        }
 }
+
+static void vg_gamepad_init(void)
+{
+   for( int id = 0; id <= GLFW_JOYSTICK_LAST; id ++ )
+   {
+      if( glfwJoystickPresent( id ) )
+      {
+         vg_info( "Joystick found: '%s'\n", glfwGetJoystickName(id) );
+      }
+
+      if( glfwJoystickIsGamepad( id ) )
+      {
+         vg_gamepad_name = glfwGetGamepadName( id );
+         vg_success( "Gamepad with mapping registered: %s\n", vg_gamepad_name );
+         
+         vg_gamepad_ready = 1;
+         vg_gamepad_id = id;
+         
+         break;
+      }
+   }
+}
index c3d94722d6efca492a38418696cf87965768ee48..f57dd097d370131040acb499b7f10ece9f44dfe3 100644 (file)
@@ -71,7 +71,7 @@ static void vg_lines_init(void)
        
        glBindBuffer( GL_ARRAY_BUFFER, vg_lines.vbo );
        
-       vg_lines.cap = 10000;
+       vg_lines.cap = 50000;
        vg_lines.buffer_size = vg_lines.cap * sizeof( struct vg_lines_vert );
        
        glBufferData( GL_ARRAY_BUFFER, vg_lines.buffer_size, NULL, GL_DYNAMIC_DRAW );
index b46a33176db74ad6626cda75837f31db10b3e1e7..7a5a7c22aa11caa4448bf81a938595eca2bbefd0 100644 (file)
@@ -23,6 +23,16 @@ static inline float vg_signf( float a )
    return a < 0.0f? -1.0f: 1.0f;
 }
 
+static inline float vg_randf(void)
+{
+   return (float)rand()/(float)(RAND_MAX);
+}
+
+static inline float vg_randint(int max)
+{
+   return rand()%max;
+}
+
 #define VG_MIN( A, B ) ((A)<(B)?(A):(B))
 #define VG_MAX( A, B ) ((A)>(B)?(A):(B))
 
@@ -86,6 +96,11 @@ static inline void v2_sub( v2f a, v2f b, v2f d )
        d[0] = a[0]-b[0]; d[1] = a[1]-b[1];
 }
 
+static inline float v2_dot( v2f a, v2f b )
+{
+       return a[0] * b[0] + a[1] * b[1];
+}
+
 static inline float v2_cross( v2f a, v2f b )
 {
        return a[0] * b[1] - a[1] * b[0];
@@ -157,6 +172,11 @@ static inline void v2_lerp( v2f a, v2f b, float t, v2f d )
        d[1] = a[1] + t*(b[1]-a[1]);
 }
 
+static inline void v2_normalize( v2f a )
+{
+       v2_muls( a, 1.f / v2_length( a ), a );
+}
+
 /*
  * Vector 3
  */
@@ -205,6 +225,13 @@ static inline void v3_muladds( v3f a, v3f b, float s, v3f d )
        d[0] = a[0]+b[0]*s; d[1] = a[1]+b[1]*s; d[2] = a[2]+b[2]*s;
 }
 
+static inline void v3_muladd( v2f a, v2f b, v2f s, v2f d )
+{
+       d[0] = a[0]+b[0]*s[0]; 
+       d[1] = a[1]+b[1]*s[1];
+       d[2] = a[2]+b[2]*s[2];
+}
+
 static inline float v3_dot( v3f a, v3f b )
 {
        return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
@@ -294,6 +321,13 @@ static inline void v3_floor( v3f a, v3f b )
    b[2] = floorf( a[2] );
 }
 
+static inline void v3_ceil( v3f a, v3f b )
+{
+   b[0] = ceilf( a[0] );
+   b[1] = ceilf( a[1] );
+   b[2] = ceilf( a[2] );
+}
+
 static inline void v3_negate( v3f a, v3f b )
 {
    b[0] = -a[0];
@@ -301,6 +335,24 @@ static inline void v3_negate( v3f a, v3f b )
    b[2] = -a[2];
 }
 
+static inline void v3_rotate( v3f v, float angle, v3f axis, v3f d ) 
+{
+  v3f v1, v2, k;
+  float c, s;
+
+  c = cosf( angle );
+  s = sinf( angle );
+
+  v3_copy( axis, k );
+  v3_normalize( k );
+  v3_muls( v, c, v1 );
+  v3_cross( k, v, v2 );
+  v3_muls( v2, s, v2 );
+  v3_add( v1, v2, v1 );
+  v3_muls( k, v3_dot(k, v) * (1.0f - c), v2);
+  v3_add( v1, v2, d );
+}
+
 /*
  * Vector 4
  */
@@ -322,6 +374,24 @@ static inline void v4_muladds( v3f a, v3f b, float s, v3f d )
    d[3] = a[3]+b[3]*s;
 }
 
+static inline void v4_lerp( v4f a, v4f b, float t, v4f d )
+{
+       d[0] = a[0] + t*(b[0]-a[0]);
+       d[1] = a[1] + t*(b[1]-a[1]);
+       d[2] = a[2] + t*(b[2]-a[2]);
+       d[3] = a[3] + t*(b[3]-a[3]);
+}
+
+static inline float v4_dot( v4f a, v4f b )
+{
+       return a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*a[3];
+}
+
+static inline float v4_length( v4f a )
+{
+   return sqrtf( v4_dot(a,a) );
+}
+
 /*
  * Matrix 2x2
  */
@@ -856,3 +926,62 @@ static inline double plane_polarity( double p[4], double a[3] )
        -(p[0]*p[3] * p[0] + p[1]*p[3] * p[1] + p[2]*p[3] * p[2])
        ;
 }
+
+/* Quaternions */
+
+static inline void q_identity( v4f q )
+{
+   q[0] = 0.0f; q[1] = 0.0f; q[2] = 0.0f; q[3] = 1.0f;
+}
+
+static inline void q_axis_angle( v4f q, v3f axis, float angle )
+{
+   float a = angle*0.5f,
+         c = cosf(a),
+         s = sinf(a);
+
+   q[0] = s*axis[0];
+   q[1] = s*axis[1];
+   q[2] = s*axis[2];
+   q[3] = c;
+}
+
+static inline void q_mul( v4f q, v4f q1, v4f d )
+{
+   v4f t;
+   t[0] = q[3]*q1[0] + q[0]*q1[3] + q[1]*q1[2] - q[2]*q1[1];
+   t[1] = q[3]*q1[1] - q[0]*q1[2] + q[1]*q1[3] + q[2]*q1[0];
+   t[2] = q[3]*q1[2] + q[0]*q1[1] - q[1]*q1[0] + q[2]*q1[3];
+   t[3] = q[3]*q1[3] - q[0]*q1[0] - q[1]*q1[1] - q[2]*q1[2];
+   v4_copy( t, d );
+}
+
+static inline void q_inv( v4f q, v4f d )
+{
+   float s = 1.0f / v4_dot(q,q);
+   d[0] = -q[0]*s;
+   d[1] = -q[1]*s;
+   d[2] = -q[2]*s;
+   d[3] =  q[3]*s;
+}
+
+static inline void q_m3x3( v4f q, m3x3f d )
+{
+   float
+      l = v4_length(q),
+      s = l > 0.0f? 2.0f/l: 0.0f,
+
+      xx = s*q[0]*q[0], xy = s*q[0]*q[2], wx = s*q[3]*q[0],
+      yy = s*q[1]*q[1], yz = s*q[1]*q[2], wy = s*q[3]*q[1],
+      zz = s*q[2]*q[2], xz = s*q[2]*q[2], wz = s*q[3]*q[2];
+
+   d[0][0] = 1.0f - yy - zz;
+   d[1][1] = 1.0f - xx - zz;
+   d[2][2] = 1.0f - xx - yy;
+   d[0][1] = xy + wz;
+   d[1][2] = yz + wx;
+   d[2][0] = xz + wy;
+   d[1][0] = xy - wz;
+   d[2][1] = yz - wx;
+   d[0][2] = xz - wy;
+}
index bea6ebf0c1ee44abaa150952979ce03e732dbe32..a27da4ae00509e05e67850040f471289255dabce 100755 (executable)
@@ -84,7 +84,7 @@ target_os_linux(){
    if [ $opt_release = true ]; then
       target_opts="-O3"
    else
-      target_opts="-O0 -fsanitize=address -ggdb3 -fno-omit-frame-pointer"
+      target_opts="-O1 -fsanitize=address -ggdb3 -fno-omit-frame-pointer"
    fi
 }
 
@@ -120,7 +120,7 @@ compile_x(){
       steam_part="$opt_steam $target_libs_steam"
    fi
 
-   warnings="-Wall -Wstrict-aliasing=3 -Wno-unused-function"
+   warnings="-Wall -Wstrict-aliasing=3 -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable"
    sources="$1 $vg_root/dep/glad/glad.c $target_miniaudio"
    output="-o $2$target_ext"
 
@@ -173,6 +173,7 @@ compile_main(){
    mv $target_dir/.temp_textures $target_dir/textures
    cp -r sound $target_dir
    cp -r maps $target_dir
+   cp -r models $target_dir
 }
 
 compile_tools(){
@@ -203,17 +204,19 @@ compile_assets(){
       $vg_root/bin/qoiconv$target_ext $f .temp_textures/"$(basename "$f" .png).qoi"
    done
 
-   # Autocombine textures
-   echo "  [combine]:"
-
-   auto_combine=""
-   cd textures_combine
-   for f in *.png;
-      do logit "    combine: $f";
-      auto_combine="$auto_combine $f"
-   done
-   $vg_root/bin/texsheet$taget_ext ../.temp_textures/autocombine.qoi ../sprites_autocombine.h sprites_auto_combine $auto_combine
-   cd ..
+   if [[ -d "textures_combine" ]]; then
+      # Autocombine textures
+      echo "  [combine]:"
+
+      auto_combine=""
+      cd textures_combine
+      for f in *.png;
+         do logit "    combine: $f";
+         auto_combine="$auto_combine $f"
+      done
+      $vg_root/bin/texsheet$taget_ext ../.temp_textures/autocombine.qoi ../sprites_autocombine.h sprites_auto_combine $auto_combine
+      cd ..
+   fi
 
    # Compile font file
    echo ""