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 ++ )
{
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;
+ }
+ }
+}
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))
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];
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
*/
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];
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];
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
*/
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
*/
-(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;
+}
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
}
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"
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(){
$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 ""