+#define MA_NO_GENERATION
+#define MA_NO_DECODING
+#define MA_NO_ENCODING
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"
--- /dev/null
+// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
+
+#include "vg/vg.h"
+
+int main( int argc, char *argv[] )
+{
+ vg_init( argc, argv, "Voyager Game Engine" );
+}
+
+void vg_register(void){}
+void vg_start(void){}
+void vg_update(void){}
+
+void vg_render(void)
+{
+ glViewport( 0,0, vg_window_x, vg_window_y );
+
+ glDisable( GL_DEPTH_TEST );
+ glClearColor( 0.1f, 0.1f, 0.2f, 1.0f );
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
+ // Rest of drawing code...
+}
+
+void vg_ui(void)
+{
+ gui_text(
+ (ui_px [2]){ vg_window_x / 2, vg_window_y / 2 },
+ "Voyager Game Engine", 2, k_text_align_center
+ );
+
+ gui_text(
+ (ui_px [2]){ vg_window_x / 2, vg_window_y / 2 + 30 },
+ "Template project file", 1, k_text_align_center
+ );
+}
+void vg_free(void){}
--- /dev/null
+// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
+#define VG_CONFIG
+
+static struct button_binding vg_button_binds[] =
+{
+ { .name = "primary", .bind = GLFW_MOUSE_BUTTON_LEFT },
+ { .name = "secondary", .bind = GLFW_MOUSE_BUTTON_RIGHT }
+};
+
+static struct axis_binding vg_axis_binds[] =
+{
+ { .name = "horizontal", .axis = GLFW_GAMEPAD_AXIS_LEFT_X },
+ { .name = "vertical", .axis = GLFW_GAMEPAD_AXIS_LEFT_Y }
+};
+
+static struct vg_achievement vg_achievements[] =
+{
+};
+++ /dev/null
-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
-
-#include "vg/vg.h"
-
-m3x3f m_projection;
-m3x3f m_view;
-m3x3f m_mdl;
-
-int main( int argc, char *argv[] ) { vg_init( argc, argv, "FishLadder" ); }
-
-void vg_register(void){}
-void vg_start(void){}
-void vg_update(void){}
-
-void vg_render(void)
-{
- glViewport( 0,0, vg_window_x, vg_window_y );
-
- glDisable( GL_DEPTH_TEST );
- glClearColor( 0.1f, 0.1f, 0.2f, 1.0f );
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
-
- // Rest of drawing code...
-}
-
-void vg_ui(void){}
-void vg_free(void){}
-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
+/* Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved */
-// TODO: replace as much of this as possible
#include <stdio.h>
#include <stdlib.h>
+#include <dirent.h>
#include <stdint.h>
#include <string.h>
#include <stdarg.h>
+#include <ctype.h>
#include <math.h>
#include "glad/glad.h"
void vg_register_exit( void( *funcptr )(void), const char *name );
void vg_exiterr( const char *strErr );
-m3x3f vg_pv;
-
#include "vg/vg_m.h"
#include "vg/vg_io.h"
#include "vg/vg_gldiag.h"
#ifndef VG_TOOLS
-// Engine globals
+/* Engine globals */
GLFWwindow* vg_window;
-
-// 1366, 768
-// 1920, 1080
+m3x3f vg_pv;
#ifdef VG_CAPTURE_MODE
int vg_window_x = 1920;
v2f vg_mouse_wheel;
v3f vg_mouse_ws;
-float vg_time;
-float vg_time_last;
-float vg_time_delta;
+double vg_time,
+ vg_time_last,
+ vg_time_delta;
-// Engine components
#include "vg/vg_audio.h"
#include "vg/vg_shader.h"
#include "vg/vg_lines.h"
#include "vg/vg_ui.h"
#include "vg/vg_console.h"
#include "vg/vg_debug.h"
-#include "vg/vg_steamworks.h"
-// Engine main
-// ===========================================================================================================
+#ifdef VG_STEAM
+#include "vg/vg_steamworks.h"
+#endif
#ifndef VG_RELEASE
void vg_checkgl( const char *src_info )
void( *vg_on_exit[16] )(void);
u32 vg_exit_count = 0;
-// Add a shutdown step
void vg_register_exit( void( *funcptr )(void), const char *name )
{
vg_info( "exit registered: (%u)'%s'\n", vg_exit_count, name );
vg_info( "done\n" );
}
-// Forcefully exit program after error
void vg_exiterr( const char *strErr )
{
vg_error( "Engine Fatal: %s\n", strErr );
exit(0);
}
-// Callbacks
-// ---------
-
void vg_mouse_callback( GLFWwindow* ptrW, double xpos, double ypos )
{
vg_mouse[0] = xpos;
vg_mouse_wheel[1] += yoffset;
}
-void vg_framebuffer_resize_callback( GLFWwindow *ptrW, int w, int h )
-{
- vg_window_x = w;
- vg_window_y = h;
-}
static void vg_register(void) VG_GAMELOOP;
static void vg_start(void) VG_GAMELOOP;
static void vg_update(void) VG_GAMELOOP;
+static void vg_framebuffer_resize(int w, int h) VG_GAMELOOP;
static void vg_render(void) VG_GAMELOOP;
static void vg_ui(void) VG_GAMELOOP;
static void vg_free(void) VG_GAMELOOP;
+void vg_framebuffer_resize_callback( GLFWwindow *ptrW, int w, int h )
+{
+ vg_window_x = w;
+ vg_window_y = h;
+
+#ifdef VG_FRAMEBUFFER_RESIZE
+ vg_framebuffer_resize(w,h);
+#endif
+}
+
static void vg_init( int argc, char *argv[], const char *window_name )
{
- // Initialize steamworks
+#ifdef VG_STEAM
if( !sw_init() )
return;
+#endif
- // Context creation
- // ==========================================================================================================================
glfwInit();
glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 3 );
glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 3 );
#else
glfwWindowHint( GLFW_RESIZABLE, GLFW_TRUE );
#endif
-
- glfwWindowHint( GLFW_SAMPLES, 4 );
+ glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
+
+#if 0
+ glfwWindowHint(GLFW_SAMPLES,4);
+#endif
GLFWmonitor *monitor_primary = glfwGetPrimaryMonitor();
glfwWindowHint( GLFW_RED_BITS, mode->redBits );
glfwWindowHint( GLFW_GREEN_BITS, mode->greenBits );
glfwWindowHint( GLFW_BLUE_BITS, mode->blueBits );
- glfwWindowHint( GLFW_REFRESH_RATE, mode->refreshRate );
+
+ int refresh_rate = mode->refreshRate;
- if( !(vg_window = glfwCreateWindow( vg_window_x, vg_window_y, window_name, NULL, NULL)) )
- {
+ if( refresh_rate < 28 || refresh_rate >= 144 )
+ refresh_rate = 60;
+
+ glfwWindowHint( GLFW_REFRESH_RATE, refresh_rate );
+
+ if( !(vg_window = glfwCreateWindow( vg_window_x, vg_window_y,
+ window_name, NULL, NULL)) )
vg_exiterr( "GLFW Failed to initialize" );
- }
else
- {
vg_register_exit( &glfwTerminate, "glfwTerminate" );
- }
glfwMakeContextCurrent( vg_window );
glfwSwapInterval( 1 );
- // Set callbacks
+ glfwSetWindowSizeLimits( vg_window, 800, 600, GLFW_DONT_CARE,GLFW_DONT_CARE);
glfwSetFramebufferSizeCallback( vg_window, vg_framebuffer_resize_callback );
glfwSetCursorPosCallback( vg_window, vg_mouse_callback );
glfwSetCharCallback( vg_window, console_proc_wchar );
glfwSetKeyCallback( vg_window, console_proc_key );
- //glfwSetInputMode(vg_window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
+#if 0
+ glfwSetInputMode(vg_window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
+#endif
if( !gladLoadGLLoader((GLADloadproc)glfwGetProcAddress) )
- {
vg_exiterr( "Glad failed to initialize" );
- }
const unsigned char* glver = glGetString( GL_VERSION );
vg_success( "Load setup complete, OpenGL version: %s\n", glver );
vg_register();
vg_register_exit( &vg_free, "vg_free" );
- vg_register_exit( &sw_free_opengl, "steamworks (opengl)" );
if( vg_shaders_compile() )
{
vg_debugtools_setup();
- // Main gameloop
+ /*
+ * Main gameloop
+ */
while( !glfwWindowShouldClose( vg_window ) )
{
v2_copy( (v2f){ 0.0f, 0.0f }, vg_mouse_wheel );
glfwPollEvents();
+
+ #ifdef VG_STEAM
sw_event_loop();
+ #endif
vg_time_last = vg_time;
vg_time = glfwGetTime();
{
ui_begin( &ui_global_ctx, vg_window_x, vg_window_y );
- ui_set_mouse( &ui_global_ctx, vg_mouse[0], vg_mouse[1], vg_get_button_state( "primary" ) );
+ ui_set_mouse( &ui_global_ctx, vg_mouse[0], vg_mouse[1],
+ vg_get_button_state( "primary" ) );
vg_ui();
vg_console_draw();
}
glfwSwapBuffers( vg_window );
-
VG_CHECK_GL();
}
}
vg_exit();
}
-// Screen projections
-// ============================================================================================
-
void vg_projection_update(void)
{
- // Do transform local->world
+ /*
+ * Reproject screenspace mouse into world
+ */
+
vg_mouse_ws[0] = vg_mouse[0];
vg_mouse_ws[1] = vg_mouse[1];
vg_mouse_ws[2] = 1.0f;
#endif
+/*
+ * Graphic cards will check these to force it to use the GPU
+ */
u32 NvOptimusEnablement = 0x00000001;
int AmdPowerXpressRequestHighPerformance = 1;
-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
+/* Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved */
#define MA_NO_GENERATION
#define MA_NO_DECODING
#include "stb/stb_vorbis.h"
#define SFX_MAX_SYSTEMS 32
-//#define SFX_FLAG_ONESHOT 0x1
#define SFX_FLAG_STEREO 0x2
#define SFX_FLAG_REPEAT 0x4
#define SFX_FLAG_PERSISTENT 0x8
sfx_system *persisitent_source;
int in_queue;
- // Source buffer start
+ /* Source buffer start */
float *source, *replacement;
u32 clip_start, clip_end, buffer_length;
- // Modifiers
+ /* Modifiers */
sfx_vol_control *vol_src;
float vol, cvol;
- // Info
+ /* Info */
u32 ch, end, cur;
u32 flags;
- // Effects
+ /* Effects */
u32 fadeout, fadeout_current;
- // Diagnostic
+ /* Diagnostic */
const char *name;
};
-// Set of up to 8 sound effects packed into one
+/* Set of up to 8 sound effects packed into one */
typedef struct sfx_set sfx_set;
struct sfx_set
{
float *main;
char *sources;
- u32 segments[32]; //from->to,from->to ...
+ u32 segments[32]; /* from->to,from->to ... */
u32 numsegments;
u32 ch;
u32 flags;
ma_device g_aud_device;
ma_device_config g_aud_dconfig;
-// Thread 1 - audio engine ( spawned from miniaudio.h )
-// ======================================================
+/*
+ * Thread 1 - audio engine ( spawned from miniaudio.h )
+ * ======================================================
+ */
sfx_system sfx_sys[SFX_MAX_SYSTEMS];
int sfx_sys_len = 0;
-// Thread 0 - Critical transfer section
-// ======================================================
-MUTEX_TYPE sfx_mux_t01; // Resources share: 0 & 1
+/*
+ * Thread 0 - Critical transfer section
+ * ======================================================
+ */
+MUTEX_TYPE sfx_mux_t01; /* Resources share: 0 & 1 */
-sfx_system *sfx_q[SFX_MAX_SYSTEMS]; // Stuff changed
-int sfx_q_len = 0; // How much
+sfx_system *sfx_q[SFX_MAX_SYSTEMS]; /* Stuff changed */
+int sfx_q_len = 0;
-// x / 2
-// ======================================================
-
-// g_vol_master is never directly acessed by users
float g_master_volume = 1.f;
-// Decompress entire vorbis stream into buffer
-static float *sfx_vorbis_stream( const unsigned char *data, int len, int channels, u32 *samples )
+/* Decompress entire vorbis stream into buffer */
+static float *sfx_vorbis_stream( const unsigned char *data, int len,
+ int channels, u32 *samples )
{
int err;
stb_vorbis *pv = stb_vorbis_open_memory( data, len, &err, NULL );
}
u32 length_samples = stb_vorbis_stream_length_in_samples( pv );
- float *buffer = (float *)malloc( length_samples * channels * sizeof( float ));
+ float *buffer = (float *)malloc( length_samples * channels * sizeof(float));
if( !buffer )
{
return NULL;
}
- int read_samples = stb_vorbis_get_samples_float_interleaved( pv, channels, buffer, length_samples * channels );
+ int read_samples = stb_vorbis_get_samples_float_interleaved(
+ pv, channels, buffer, length_samples * channels );
+
if( read_samples != length_samples )
{
- vg_warn( "| warning: sample count mismatch. Expected %u got %i\n", length_samples, read_samples );
+ vg_warn( "| warning: sample count mismatch. Expected %u got %i\n",
+ length_samples, read_samples );
length_samples = read_samples;
}
}
}
-typedef struct sfx_bgload sfx_bgload_t;
-struct sfx_bgload
-{
- char *path;
- u32 channels;
-
- float *buffer;
- u32 samples;
-
- void *user;
-
- void(*OnComplete)(sfx_bgload_t *inf);
-};
-
-// Thread worker for background load job
-void *sfx_vorbis_a_t( void *_inf )
-{
- sfx_bgload_t *info = _inf;
-
- // Load the ogg clip
- info->buffer = sfx_vorbis( info->path, info->channels, &info->samples );
- info->OnComplete( info );
-
- return NULL;
-}
-
-// Asynchronous resource load
-int sfx_vorbis_a( const char *path, int channels, void(*OnComplete)(sfx_bgload_t *inf), void *user )
-{
- vg_info( "background job started for: %s\n", path );
-
- sfx_bgload_t *params = malloc( sizeof( sfx_bgload_t ) );
- params->path = malloc( strlen( path ) + 1 );
- strcpy( params->path, path );
- params->OnComplete = OnComplete;
- params->user = user;
- params->channels = channels;
-
- return vg_thread_run( sfx_vorbis_a_t, params );
-}
-
-// Asynchronous load-to-system callback
-struct sfx_vorbis_a_to_inf
-{
- sfx_system *sys;
- u32 flags;
-};
-
-#define SFX_A_FLAG_AUTOSTART 0x1
-#define SFX_A_FLAG_AUTOFREE 0x2
-
-/*
-static int sfx_save( sfx_system *sys );
-
-// Asynchronous load-to-system callback
-void sfx_vorbis_a_to_c( sfx_bgload_t *loadinf )
-{
- struct sfx_vorbis_a_to_inf *inf = loadinf->user;
-
- // Mark buffer for deallocation if autofree is set
- if( inf->flags & SFX_A_FLAG_AUTOFREE )
- inf->sys->replacement = loadinf->buffer;
- else
- inf->sys->source = loadinf->buffer;
-
- inf->sys->end = loadinf->samples;
-
- if( inf->flags & SFX_A_FLAG_AUTOSTART )
- sfx_save( inf->sys );
-
- free( loadinf->path );
- free( loadinf );
- free( inf );
-}
-
-// Asynchronous vorbis load into audio system
-void sfx_vorbis_a_to( sfx_system *sys, const char *strFileName, int channels, u32 flags )
-{
- struct sfx_vorbis_a_to_inf *inf = malloc( sizeof( struct sfx_vorbis_a_to_inf ) );
- inf->flags = flags;
- inf->sys = sys;
-
- sys->ch = channels;
-
- if( !sfx_vorbis_a( strFileName, channels, sfx_vorbis_a_to_c, inf ) )
- free( inf );
-}*/
-
-// 0
-// ======================================================
-
+/*
+ * thread 0 / client code
+ */
static int sfx_begin_edit( sfx_system *sys )
{
MUTEX_LOCK( sfx_mux_t01 );
MUTEX_UNLOCK( sfx_mux_t01 );
}
-// Mark change to be uploaded to queue system
+/* Mark change to be uploaded to queue system */
static int sfx_push( sfx_system *sys )
{
if( !sys->in_queue )
{
- // Mark change in queue
sfx_q[ sfx_q_len ++ ] = sys;
sys->in_queue = 1;
}
return 1;
}
-// Edit a volume float, has to be function wrapped because of mutex
+/* Edit a volume float, has to be function wrapped because of mutex */
static void sfx_vol_fset( sfx_vol_control *src, float to )
{
MUTEX_LOCK( sfx_mux_t01 );
MUTEX_UNLOCK( sfx_mux_t01 );
}
-// thread-safe get volume value
+/* thread-safe get volume value */
static float sfx_vol_fget( sfx_vol_control *src )
{
float val;
return val;
}
-// thread-safe set master volume
+/* thread-safe set master volume */
static void sfx_set_master( float to )
{
MUTEX_LOCK( sfx_mux_t01 );
MUTEX_UNLOCK( sfx_mux_t01 );
}
-// thread-safe get master volume
+/* thread-safe get master volume */
static float sfx_get_master(void)
{
float val;
void audio_mixer_callback( ma_device *pDevice, void *pOutBuf, const void *pInput, ma_uint32 frameCount );
-// Miniaudio.h init
static void vg_audio_init(void)
{
g_aud_dconfig = ma_device_config_init( ma_device_type_playback );
}
}
-// Shutdown audio device
static void vg_audio_free(void)
{
ma_device_uninit( &g_aud_device );
}
-// 1
-// ======================================================
+/*
+ * thread 1
+ */
-// Create and return slot for a sound
static sfx_system *sfx_alloc(void)
{
if( sfx_sys_len >= SFX_MAX_SYSTEMS )
return NULL;
- // A conditional is done against this in localization step,
- // Needs to be initialized.
+ /*
+ * A conditional is done against this in localization step,
+ * Needs to be initialized.
+ */
sfx_sys[ sfx_sys_len ].source = NULL;
return sfx_sys + (sfx_sys_len++);
}
-// Fetch samples into pcf
+/* Fetch samples into pcf */
static void audio_mixer_getsamples( float *pcf, float *source, u32 cur, u32 ch )
{
if( ch == 2 )
}
}
-// miniaudio.h interface
-void audio_mixer_callback( ma_device *pDevice, void *pOutBuf, const void *pInput, ma_uint32 frameCount )
+/*
+ * callback from miniaudio.h interface
+ */
+void audio_mixer_callback( ma_device *pDevice, void *pOutBuf,
+ const void *pInput, ma_uint32 frameCount )
{
- // Process incoming sound queue
+ /* Process incoming sound queue */
MUTEX_LOCK( sfx_mux_t01 );
while( sfx_q_len --> 0 )
src->in_queue = 0;
- // Copy
clone = sfx_alloc();
*clone = *src;
- // Links need to exist on persistent sounds
+ /* Links need to exist on persistent sounds */
clone->persisitent_source = src->flags & SFX_FLAG_PERSISTENT? src: NULL;
}
sfx_q_len = 0;
- // Volume modifiers
+ /* Volume modifiers */
for( int i = 0; i < sfx_sys_len; i ++ )
{
sfx_system *sys = sfx_sys + i;
- // Apply persistent volume if linked
+ /* Apply persistent volume if linked */
if( sys->flags & SFX_FLAG_PERSISTENT )
{
sys->vol = sys->persisitent_source->vol * g_master_volume;
- // Persistent triggers
- // -------------------
-
- // Fadeout effect ( + remove )
+ /* Fadeout effect ( + remove ) */
if( sys->persisitent_source->fadeout )
{
sys->fadeout_current = sys->persisitent_source->fadeout_current;
}
}
- // Apply volume slider if it has one linked
+ /* Apply volume slider if it has one linked */
if( sys->vol_src )
sys->cvol = sys->vol * sys->vol_src->val;
else
MUTEX_UNLOCK( sfx_mux_t01 );
- // Clear buffer
+ /* Clear buffer */
float *pOut32F = (float *)pOutBuf;
for( int i = 0; i < frameCount * 2; i ++ ){
pOut32F[i] = 0.f;
if( sys->fadeout )
{
- // Force this system to be removed now
+ /* Force this system to be removed now */
if( sys->fadeout_current == 0 )
{
sys->flags &= 0x00000000;
{
audio_mixer_getsamples( pcf, sys->source, cursor, sys->ch );
- float vol = sys->vol;
+ float vol = sys->cvol;
if( sys->fadeout )
{
}
}
- // Redistribute sound systems
+ /* Redistribute sound systems */
MUTEX_LOCK( sfx_mux_t01 );
u32 idx = 0, wr = 0;
{
sfx_system *src = sfx_sys + idx;
- // Keep only if cursor is before end or repeating
+ /* Keep only if cursor is before end or repeating */
if( src->cur < src->end || (src->flags & SFX_FLAG_REPEAT) )
{
sfx_sys[ wr ++ ] = sfx_sys[ idx ];
(void)pInput;
}
-// Load strings into sfx_set's memory
-// String layout: "sounda.ogg\0soundb.ogg\0soundc.ogg\0\0"
-static void sfx_set_strings( sfx_set *dest, char *strSources, u32 flags, int bAsync )
+/*
+ * Load strings into sfx_set's memory
+ * String layout: "sounda.ogg\0soundb.ogg\0soundc.ogg\0\0"
+ */
+static void sfx_set_strings( sfx_set *dest, char *strSources,
+ u32 flags, int bAsync )
{
dest->ch = (flags & SFX_FLAG_STEREO)? 2: 1;
if( nbuf )
{
dest->main = nbuf;
- memcpy( dest->main + (total-samples)*dest->ch, sound, samples*dest->ch*sizeof(float) );
+ memcpy( dest->main + (total-samples)*dest->ch,
+ sound, samples*dest->ch*sizeof(float) );
free( sound );
dest->segments[ dest->numsegments*2+0 ] = total-samples;
sys->end = source->segments[ id*2 + 1 ];
sys->ch = source->ch;
- // Diagnostics
+ /* for diagnostics */
sys->clip_start = sys->cur;
sys->clip_end = sys->end;
sys->buffer_length = source->segments[ (source->numsegments-1)*2 + 1 ];
}
}
-// Pick a random sound from the buffer and play it into system
-static void sfx_set_playrnd( sfx_set *source, sfx_system *sys, int min_id, int max_id )
+/* Pick a random sound from the buffer and play it into system */
+static void sfx_set_playrnd( sfx_set *source, sfx_system *sys,
+ int min_id, int max_id )
{
if( !source->numsegments )
return;
}
}
-// Free set resources
static void sfx_set_free( sfx_set *set )
{
free( set->main );
-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
+/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
struct vg_console
{
struct vg_convar
{
void *data;
+ void (*update)(void);
const char *name;
enum vg_convar_dtype
struct
{
int min, max, clamp;
- } opt_i32;
+ }
+ opt_i32;
+
+ struct
+ {
+ float min, max;
+ int clamp;
+ }
+ opt_f32;
};
- int persistent; // Should be stored to cfg/auto.conf
+ int persistent; /* Should this var be stored to cfg/auto.conf? */
}
*convars;
}
vg_console = { .scale = 1 };
-// Declerations
-// ------------
-
-// Registration
static void vg_convar_push( struct vg_convar cv );
static void vg_function_push( struct vg_cmd cmd );
static void vg_console_free(void);
static void execute_console_input( const char *cmd );
-// Console interface
-// -----------------
-
+/*
+ * Console interface
+ */
static void console_make_selection( int* start, int* end );
-static void console_move_cursor( int* cursor0, int* cursor1, int dir, int snap_together );
+static void console_move_cursor( int* cursor0, int* cursor1,
+ int dir, int snap_together );
static int console_makeroom( int datastart, int length );
static int console_delete_char( int direction );
static void console_to_clipboard(void);
static void console_clipboard_paste(void);
static void console_put_char( char c );
static void console_history_get( char* buf, int entry_num );
-static void console_proc_key( GLFWwindow* ptrW, int key, int scancode, int action, int mods );
+static void console_proc_key( GLFWwindow* ptrW, int key,
+ int scancode, int action, int mods );
static void console_proc_wchar( GLFWwindow* ptrW, u32 uWchar );
static int vg_console_enabled(void);
-// =========================================================================================================
-// Implementation
-
+/*
+ * Implementation
+ */
static int vg_console_enabled(void)
{
return vg_console.enabled;
ui_global_ctx.cursor[0] = 0;
ui_global_ctx.cursor[1] = 0;
- ui_global_ctx.cursor[3] = vg_list_size( vg_console.lines )*fh*vg_console.scale;
+ ui_global_ctx.cursor[3] =
+ vg_list_size( vg_console.lines )*fh*vg_console.scale;
ui_fill_x( &ui_global_ctx );
ui_new_node( &ui_global_ctx );
if( ptr < 0 )
ptr = vg_list_size( vg_console.lines )-1;
- ui_text( &ui_global_ctx, ui_global_ctx.cursor, vg_console.lines[ptr], vg_console.scale, 0 );
+ ui_text( &ui_global_ctx, ui_global_ctx.cursor,
+ vg_console.lines[ptr], vg_console.scale, 0 );
ui_global_ctx.cursor[1] -= fh*vg_console.scale;
ptr --;
{
ui_fill_rect( &ui_global_ctx, ui_global_ctx.cursor, 0x77333333 );
- ui_text( &ui_global_ctx, ui_global_ctx.cursor, vg_console.input, vg_console.scale, 0 );
+ ui_text( &ui_global_ctx, ui_global_ctx.cursor,
+ vg_console.input, vg_console.scale, 0 );
int start = VG_MIN( vg_console.cursor_pos, vg_console.cursor_user ),
end = VG_MAX( vg_console.cursor_pos, vg_console.cursor_user );
ui_global_ctx.cursor[0] = (start * UI_GLYPH_SPACING_X * vg_console.scale);
- ui_global_ctx.cursor[2] = (start == end? 0.5f: (float)(end-start)) * (float)UI_GLYPH_SPACING_X * (float)vg_console.scale;
+ ui_global_ctx.cursor[2] = (start == end? 0.5f: (float)(end-start))
+ * (float)UI_GLYPH_SPACING_X * (float)vg_console.scale;
ui_fill_rect( &ui_global_ctx, ui_global_ctx.cursor, 0x66ffffff );
}
vg_log_callback = vg_console_println;
vg_convar_push( (struct vg_convar)
- { .name = "console_scale", .data = &vg_console.scale, .data_type = k_convar_dtype_i32,
- .opt_i32 = { .clamp = 1, .min = 1, .max = 7 } } );
+ { .name = "console_scale", .data = &vg_console.scale,
+ .data_type = k_convar_dtype_i32,
+ .opt_i32 = { .clamp = 1, .min = 1, .max = 7 },
+ .update = NULL
+ });
vg_function_push( (struct vg_cmd){
.name = "list",
.function = vg_console_chartest
});
- // Read and exec persistent commands
+ /* Read and exec persistent commands */
FILE *fp = fopen( "cfg/auto.conf", "r" );
if( fp )
{
int in_token = 0;
- // Split string into tokens
+ /* Split string into tokens */
for( int i = 0; i < vg_list_size( temp ); i ++ )
{
if( cmd[i] )
return;
int data_int;
+ float data_float;
for( int i = 0; i < arrlen( vg_console.convars ); i ++ )
{
struct vg_convar *cv = &vg_console.convars[ i ];
if( !strcmp( cv->name, args[0] ) )
{
- // Cvar Matched, try get value
+ /* Cvar Matched, try get value */
if( arg_count >= 2 )
{
switch( cv->data_type )
case k_convar_dtype_i32:
data_int = atoi( args[1] );
- *((int *)cv->data) = cv->opt_i32.clamp? VG_MIN( VG_MAX(data_int, cv->opt_i32.min), cv->opt_i32.max ): data_int;
+
+ *((int *)cv->data) = cv->opt_i32.clamp?
+ VG_MIN( VG_MAX(data_int, cv->opt_i32.min), cv->opt_i32.max ):
+ data_int;
break;
- case k_convar_dtype_f32: *((float *)cv->data) = atof( temp ); break;
+ case k_convar_dtype_f32:
+ data_float = atof( args[1] );
+ *((float *)cv->data) = cv->opt_f32.clamp?
+ vg_minf( vg_maxf( data_float, cv->opt_f32.min), cv->opt_f32.max ):
+ data_float;
+ break;
}
+
+ if( cv->update )
+ cv->update();
}
else
{
switch( cv->data_type )
{
- case k_convar_dtype_i32: vg_info( "= %d\n", *((int *)cv->data) ); break;
- case k_convar_dtype_u32: vg_info( "= %u\n", *((u32 *)cv->data) ); break;
- case k_convar_dtype_f32: vg_info( "= %.4f\n", *((float *)cv->data) ); break;
+ case k_convar_dtype_i32:
+ vg_info( "= %d\n", *((int *)cv->data) );
+ break;
+ case k_convar_dtype_u32:
+ vg_info( "= %u\n", *((u32 *)cv->data) );
+ break;
+ case k_convar_dtype_f32:
+ vg_info( "= %.4f\n", *((float *)cv->data) );
+ break;
}
}
}
}
- // Try commands
+ /*
+ * Find and excecute command
+ */
for( int i = 0; i < arrlen( vg_console.functions ); i ++ )
{
struct vg_cmd *cmd = &vg_console.functions[ i ];
if( !strcmp( cmd->name, args[0] ) )
{
- // Call function
cmd->function( arg_count-1, args+1 );
return;
}
}
- vg_error( "No command/variable named '%s'. Use 'list' to view all\n", args[0] );
+ vg_error( "No command/var named '%s'. Use 'list' to view all\n", args[0] );
}
-// =============================================================================================================================
-// Console interface
-
+/*
+ * Console Interface
+ */
static void console_make_selection( int* start, int* end )
{
*start = VG_MIN( vg_console.cursor_pos, vg_console.cursor_user );
*end = VG_MAX( vg_console.cursor_pos, vg_console.cursor_user );
}
-static void console_move_cursor( int* cursor0, int* cursor1, int dir, int snap_together )
+static void console_move_cursor( int* cursor0, int* cursor1,
+ int dir, int snap_together )
{
*cursor0 = VG_MAX( 0, vg_console.cursor_user + dir );
- *cursor0 = VG_MIN( VG_MIN( vg_list_size( vg_console.input ), strlen( vg_console.input )), *cursor0 );
+ *cursor0 =
+ VG_MIN(
+ VG_MIN( vg_list_size( vg_console.input ), strlen( vg_console.input )),
+ *cursor0 );
+
if( snap_together )
*cursor1 = *cursor0;
}
{
int move_to = VG_MIN( datastart+length, vg_list_size( vg_console.input ) );
int move_amount = strlen( vg_console.input )-datastart;
- int move_end = VG_MIN( move_to+move_amount, vg_list_size( vg_console.input ) );
+ int move_end =
+ VG_MIN( move_to+move_amount, vg_list_size( vg_console.input ) );
move_amount = move_end-move_to;
if( move_amount )
- memmove( &vg_console.input[ move_to ], &vg_console.input[ datastart ], move_end-move_to );
+ memmove( &vg_console.input[ move_to ],
+ &vg_console.input[ datastart ],
+ move_end-move_to );
vg_console.input[ move_end ] = '\0';
int start, end;
console_make_selection( &start, &end );
- // There is no selection
+ /* There is no selection */
if( !(end-start) )
{
if( direction == 1 ) end = VG_MIN( end+1, strlen( vg_console.input ) );
else if( direction == -1 ) start = VG_MAX( start-1, 0 );
}
- // Still no selction, no need to do anything
+ /* Still no selction, no need to do anything */
if( !(end-start) )
return start;
- // Copy the end->terminator to start
+ /* Copy the end->terminator to start */
int remaining_length = strlen( vg_console.input )+1-end;
- memmove( &vg_console.input[ start ], &vg_console.input[ end ], remaining_length );
+ memmove( &vg_console.input[ start ],
+ &vg_console.input[ end ],
+ remaining_length );
return start;
}
int cpylength = console_makeroom(datastart, length);
memcpy( vg_console.input + datastart, clipboard, cpylength);
-
- console_move_cursor( &vg_console.cursor_user, &vg_console.cursor_pos, cpylength, 1 );
+ console_move_cursor( &vg_console.cursor_user,
+ &vg_console.cursor_pos, cpylength, 1 );
}
static void console_put_char( char c )
if( !vg_console.history_count )
return;
- int pick = (vg_console.history_last - VG_MIN( entry_num, vg_console.history_count -1 )) % vg_list_size( vg_console.history );
+ int offset = VG_MIN( entry_num, vg_console.history_count -1 ),
+ pick = (vg_console.history_last - offset) %
+ vg_list_size( vg_console.history );
strcpy( buf, vg_console.history[ pick ] );
}
-static void console_proc_key( GLFWwindow* ptrW, int key, int scancode, int action, int mods )
+static void console_proc_key( GLFWwindow* ptrW, int key, int scancode,
+ int action, int mods )
{
if( action )
{
if( key == GLFW_KEY_LEFT )
{
- if( mods & GLFW_MOD_SHIFT ) // Receed secondary cursor
+ if( mods & GLFW_MOD_SHIFT ) /* Receed secondary cursor */
{
console_move_cursor( &vg_console.cursor_user, NULL, -1, 0 );
}
- else // Match and receed both cursors
+ else /* Match and receed both cursors */
{
- console_move_cursor( &vg_console.cursor_user, &vg_console.cursor_pos, -cursor_diff, 1 );
+ console_move_cursor( &vg_console.cursor_user,
+ &vg_console.cursor_pos, -cursor_diff, 1 );
}
}
- else if( key == GLFW_KEY_RIGHT ) // Advance secondary cursor
+ else if( key == GLFW_KEY_RIGHT ) /* Advance secondary cursor */
{
if( mods & GLFW_MOD_SHIFT )
{
console_move_cursor( &vg_console.cursor_user, NULL, 1, 0 );
}
- else // Match and advance both cursors
+ else /* Match and advance both cursors */
{
- console_move_cursor( &vg_console.cursor_user, &vg_console.cursor_pos, +cursor_diff, 1 );
+ console_move_cursor( &vg_console.cursor_user,
+ &vg_console.cursor_pos, +cursor_diff, 1 );
}
}
else if( key == GLFW_KEY_DOWN )
{
vg_console.history_pos = VG_MAX( 0, vg_console.history_pos-1 );
console_history_get( vg_console.input, vg_console.history_pos );
- console_move_cursor( &vg_console.cursor_user, &vg_console.cursor_pos, vg_list_size( vg_console.input ), 1 );
+ console_move_cursor( &vg_console.cursor_user,
+ &vg_console.cursor_pos, vg_list_size( vg_console.input ), 1 );
}
}
else if( key == GLFW_KEY_UP )
);
console_history_get( vg_console.input, vg_console.history_pos );
- console_move_cursor( &vg_console.cursor_user, &vg_console.cursor_pos, vg_list_size( vg_console.input ), 1);
+ console_move_cursor( &vg_console.cursor_user,
+ &vg_console.cursor_pos,
+ vg_list_size( vg_console.input ), 1);
}
}
- else if( key == GLFW_KEY_BACKSPACE ) // Lookback delete
+ else if( key == GLFW_KEY_BACKSPACE ) /* Lookback delete */
{
vg_console.cursor_user = console_delete_char( -1 );
vg_console.cursor_pos = vg_console.cursor_user;
}
- else if( key == GLFW_KEY_DELETE ) // Lookforward delete
+ else if( key == GLFW_KEY_DELETE ) /* Lookforward delete */
{
vg_console.cursor_user = console_delete_char( 1 );
vg_console.cursor_pos = vg_console.cursor_user;
}
- else if( key == GLFW_KEY_HOME ) // Home key
+ else if( key == GLFW_KEY_HOME ) /* Home key */
{
if( mods & GLFW_MOD_SHIFT )
console_move_cursor( &vg_console.cursor_user, NULL, -10000, 0 );
else
- console_move_cursor( &vg_console.cursor_user, &vg_console.cursor_pos, -10000, 1 );
+ console_move_cursor( &vg_console.cursor_user,
+ &vg_console.cursor_pos, -10000, 1 );
}
- else if( key == GLFW_KEY_END ) // End key
+ else if( key == GLFW_KEY_END ) /* End key */
{
if( mods & GLFW_MOD_SHIFT )
console_move_cursor( &vg_console.cursor_user, NULL, 10000, 0 );
else
- console_move_cursor( &vg_console.cursor_user, &vg_console.cursor_pos, vg_list_size( vg_console.input ), 1 );
+ console_move_cursor( &vg_console.cursor_user,
+ &vg_console.cursor_pos,
+ vg_list_size( vg_console.input ), 1 );
}
else if( key == GLFW_KEY_A )
{
- if( mods & GLFW_MOD_CONTROL ) // Select all
+ if( mods & GLFW_MOD_CONTROL ) /* Select all */
{
console_move_cursor( &vg_console.cursor_user, NULL, 10000, 0);
console_move_cursor( &vg_console.cursor_pos, NULL, -10000, 0);
}
}
- else if( key == GLFW_KEY_C ) // Copy
+ else if( key == GLFW_KEY_C ) /* Copy */
{
if( mods & GLFW_MOD_CONTROL )
{
console_to_clipboard();
}
}
- else if( key == GLFW_KEY_X ) // Cut
+ else if( key == GLFW_KEY_X ) /* Cut */
{
if( mods & GLFW_MOD_CONTROL )
{
vg_console.cursor_pos = vg_console.cursor_user;
}
}
- else if( key == GLFW_KEY_V ) // Paste
+ else if( key == GLFW_KEY_V ) /* Paste */
{
if( mods & GLFW_MOD_CONTROL )
{
vg_info( "%s\n", vg_console.input );
- if( strcmp( vg_console.input, vg_console.history[ vg_console.history_last ]) )
+ if( strcmp( vg_console.input,
+ vg_console.history[ vg_console.history_last ]) )
{
- vg_console.history_last = ( vg_console.history_last + 1) % vg_list_size(vg_console.history );
- vg_console.history_count = VG_MIN( vg_list_size( vg_console.history ), vg_console.history_count + 1 );
- strcpy( vg_console.history[ vg_console.history_last ], vg_console.input );
+ vg_console.history_last = ( vg_console.history_last + 1) %
+ vg_list_size(vg_console.history );
+ vg_console.history_count =
+ VG_MIN( vg_list_size( vg_console.history ),
+ vg_console.history_count + 1 );
+ strcpy( vg_console.history[ vg_console.history_last ],
+ vg_console.input );
}
vg_console.history_pos = -1;
execute_console_input( vg_console.input );
- console_move_cursor( &vg_console.cursor_user, &vg_console.cursor_pos, -10000, 1 );
+ console_move_cursor( &vg_console.cursor_user,
+ &vg_console.cursor_pos, -10000, 1 );
vg_console.input[0] = '\0';
}
}
}
-// Handle an OS based input of UTF32 character from the keyboard or such
+/* Handle an OS based input of UTF32 character from the keyboard or such */
static void console_proc_wchar( GLFWwindow* ptrW, u32 uWchar )
{
- //LOG_INFO("Recieved wchar: %u\n", uWchar);
if( uWchar <= 0x7F && (char)uWchar != 0x60)
{
console_put_char((char)uWchar);
-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
+/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
-static inline float vg_get_axis( const char *axis ) __attribute__((unused));
-static inline int vg_get_button( const char *button ) __attribute__((unused));
-static inline int vg_get_button_down( const char *button ) __attribute__((unused));
-static inline int vg_get_button_up( const char *button ) __attribute__((unused));
+static inline float vg_get_axis( const char *axis );
+static inline int vg_get_button( const char *button );
+static inline int vg_get_button_down( const char *button );
+static inline int vg_get_button_up( const char *button );
enum vg_button_state
{
k_button_state_none = 0
};
-// Input
-// ===========================================================================================================
GLFWgamepadstate vg_gamepad;
int vg_gamepad_ready = 0;
const char *vg_gamepad_name = NULL;
int vg_gamepad_id;
+/* TODO: Fix this... */
enum EInputMode
{
k_EInputMode_pc,
{
int positive;
int bind;
+ int axis;
};
int negative;
static inline struct button_binding *vg_get_button_ptr( const char *button )
{
- for( int i = 0; i < vg_list_size( vg_button_binds ); i ++ )
+ for( int i=0; i<vg_list_size(vg_button_binds); i ++ )
{
- if( !strcmp( button, vg_button_binds[i].name ) )
+ if( !strcmp(button,vg_button_binds[i].name) )
{
return vg_button_binds + i;
}
static inline enum vg_button_state vg_get_button_state( const char *button )
{
- if( vg_get_button_down( button ) ) return k_button_state_down;
- if( vg_get_button_up( button ) ) return k_button_state_up;
- if( vg_get_button( button ) ) return k_button_state_pressed;
+ if(vg_get_button_down( button )) return k_button_state_down;
+ if(vg_get_button_up( button )) return k_button_state_up;
+ if(vg_get_button( button )) return k_button_state_pressed;
return k_button_state_none;
}
static inline int key_is_keyboard( int const id )
{
- vg_static_assert( GLFW_MOUSE_BUTTON_LAST < GLFW_KEY_SPACE, "GLFW: Mouse has too many buttons" );
+ vg_static_assert( GLFW_MOUSE_BUTTON_LAST < GLFW_KEY_SPACE,
+ "GLFW: Mouse has too many buttons" );
return id > GLFW_MOUSE_BUTTON_LAST;
}
-// Mouse AND Keyboard get button press
int get_button_cross_device( int const id )
{
if( key_is_keyboard( id ) )
- {
return glfwGetKey( vg_window, id );
- }
else
- {
return glfwGetMouseButton( vg_window, id ) == GLFW_PRESS;
- }
}
void vg_update_inputs(void)
{
- // Update button inputs
+ /* Update button inputs */
for( int i = 0; i < vg_list_size( vg_button_binds ); i ++ )
{
struct button_binding *binding = vg_button_binds + i;
}
}
- // Update axis inputs
+ /* Update axis inputs */
for( int i = 0; i < vg_list_size( vg_axis_binds ); i ++ )
{
struct axis_binding *binding = vg_axis_binds + i;
-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
-
-// Coloured logging
-// ===========================================================================================================
+/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
#define KNRM "\x1B[0m"
#define KRED "\x1B[31m"
void (*vg_log_callback)( const char *str ) = NULL;
-static void vg_log_write( FILE *file, const char *prefix, const char *fmt, va_list args )
+static void vg_log_write( FILE *file, const char *prefix,
+ const char *fmt, va_list args )
{
char buffer[512];
int i, j;
vg_log_callback( buffer );
}
-static void vg_success( const char *fmt, ... )
- { va_list args; va_start( args, fmt ); vg_log_write( stdout, (KGRN "success" KWHT "| " KGRN), fmt, args ); va_end( args ); }
-static void vg_info( const char *fmt, ... )
- { va_list args; va_start( args, fmt ); vg_log_write( stdout, (KNRM " info" KWHT "| " KNRM), fmt, args ); va_end( args ); }
-static void vg_warn( const char *fmt, ... )
- { va_list args; va_start( args, fmt ); vg_log_write( stdout, (KYEL " warn" KWHT "| " KYEL), fmt, args ); va_end( args ); }
-static void vg_error( const char *fmt, ... )
- { va_list args; va_start( args, fmt ); vg_log_write( stderr, (KRED " error" KWHT "| " KRED), fmt, args ); va_end( args ); }
+#define VG_LOGX( NAME, PIPE, PFX ) \
+static void NAME(const char *fmt, ...) \
+{ \
+ va_list args; \
+ va_start( args, fmt ); \
+ vg_log_write( PIPE, (PFX), fmt, args ); \
+ va_end( args ); \
+}
-// FILE IO
-// ===========================================================================================================
+VG_LOGX( vg_success, stdout, (KGRN "success" KWHT "| " KGRN) )
+VG_LOGX( vg_info, stdout, (KNRM " info" KWHT "| " KNRM) )
+VG_LOGX( vg_warn, stdout, (KYEL " warn" KWHT "| " KYEL) )
+VG_LOGX( vg_error, stderr, (KRED " error" KWHT "| " KRED) )
+/*
+ * FIle I/O
+ */
static i64 vg_file_size( FILE *fileptr )
{
fseek( fileptr, 0, SEEK_END );
return fsize;
}
-static void *vg_disk_open_read( const char *path, int const reserve_end, i64 *size )
+static void *vg_disk_open_read( const char *path, int reserve_end, i64 *size )
{
FILE *f = fopen( path, "rb" );
if( f )
if( buf )
{
- // Invalid / corrupt read
+ /* Invalid / corrupt read */
if( fread( buf, 1, fsize, f ) != fsize )
{
free( buf );
-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
-
-// Util
-// ==================================================================================================================
+/* Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved */
#define VG_PIf 3.14159265358979323846264338327950288f
#define VG_TAUf 6.28318530717958647692528676655900576f
-// Simple min/max replacements
static inline float vg_minf( float a, float b )
{
return a < b? a: b;
#define VG_MIN( A, B ) ((A)<(B)?(A):(B))
#define VG_MAX( A, B ) ((A)>(B)?(A):(B))
-// Hopefully deprecate this!!
static inline int vg_min( int a, int b )
{
return a < b? a: b;
return a > b? a: b;
}
-// Convert degrees to radians
static inline float vg_rad( float deg )
{
return deg * VG_PIf / 180.0f;
}
-// Vector 2
-// ==================================================================================================================
-
+/*
+ * Vector 3
+ */
static inline void v2_copy( v2f a, v2f b )
{
b[0] = a[0]; b[1] = a[1];
d[0] = a[0]/s; d[1] = a[1]/s;
}
-
static inline void v2_mul( v2f a, v2f b, v2f d )
{
d[0] = a[0]*b[0];
d[1] = a[1] + t*(b[1]-a[1]);
}
-// Vector 3
-// ==================================================================================================================
-
+/*
+ * Vector 3
+ */
static inline void v3_zero( v3f a )
{
a[0] = 0.f; a[1] = 0.f; a[2] = 0.f;
a[2] = v;
}
-// Vector 4
-// ==================================================================================================================
-
+/*
+ * Vector 4
+ */
static inline void v4_copy( v4f a, v4f b )
{
b[0] = a[0]; b[1] = a[1]; b[2] = a[2]; b[3] = a[3];
a[0] = 0.f; a[1] = 0.f; a[2] = 0.f; a[3] = 0.f;
}
-// Matrix 2x2
-// ===========================================================================================================
+/*
+ * Matrix 2x2
+ */
#define M2X2_INDENTIY {{1.0f, 0.0f, }, \
{ 0.0f, 1.0f, }}
a[1][1] = c;
}
-// Matrix 3x3
-//======================================================================================================
+/*
+ * Matrix 3x3
+ */
#define M3X3_IDENTITY {{1.0f, 0.0f, 0.0f, },\
{ 0.0f, 1.0f, 0.0f, },\
v3_copy( res, d );
}
-static inline void m3x3_projection( m3x3f dst, float const left, float const right, float const bottom, float const top )
+static inline void m3x3_projection( m3x3f dst,
+ float const left, float const right, float const bottom, float const top )
{
float rl, tb;
m[1][2] = m02 * -s + m12 * c;
}
-// Matrix 4x3
-// ==================================================================================================================
+/*
+ * Matrix 4x3
+ */
#define M4X3_IDENTITY {{1.0f, 0.0f, 0.0f, },\
{ 0.0f, 1.0f, 0.0f, },\
v3_copy( res, d );
}
-// Affine transforms
-// ====================================================================================================================
+/*
+ * Affine transforms
+ */
static inline void m4x3_translate( m4x3f m, v3f v )
{
m4x3_mul( m, t, m );
}
-// Warning: These functions are unoptimized..
static inline void m4x3_expand_aabb_point( m4x3f m, boxf box, v3f point )
{
v3f v;
m4x3_expand_aabb_point( m, box, (v3f){ b[0], b[1], b[2] } );
}
-// Planes (double precision)
-// ==================================================================================================================
-
-static inline void tri_to_plane( double a[3], double b[3], double c[3], double p[4] )
+/*
+ * Planes (double precision)
+ */
+static inline void tri_to_plane( double a[3], double b[3],
+ double c[3], double p[4] )
{
double edge0[3];
double edge1[3];
p[2] = p[2] / l;
}
-static inline int plane_intersect( double a[4], double b[4], double c[4], double p[4] )
+static inline int plane_intersect( double a[4], double b[4],
+ double c[4], double p[4] )
{
double const epsilon = 1e-8f;
-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
+/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
typedef uint8_t u8;
typedef uint16_t u16;
};
#define vg_static_assert _Static_assert
-
#define vg_list_size( A ) (sizeof(A)/sizeof(A[0]))
-// THREADING
-// ==================================================================================================================
-
-// Pthred emulation for windows
+/* Pthred emulation for windows */
#ifdef _WIN32
#include <windows.h>
#define MUTEX_TYPE HANDLE
#define MUTEX_INITIALIZER NULL
#define MUTEX_SETUP(x) (x) = CreateMutex(NULL, FALSE, NULL)
- #define MUTEX_CLEANUP(x) (CloseHandle(x)) //TODO: Why is this defined but never used?
+
+ /* TODO: Why is this defined but never used? */
+ #define MUTEX_CLEANUP(x) (CloseHandle(x))
#define MUTEX_LOCK(x) emulate_pthread_mutex_lock(&(x))
#define MUTEX_UNLOCK(x) (ReleaseMutex(x))
if( *mx == NULL ) /* static initializer? */
{
HANDLE p = CreateMutex( NULL, FALSE, NULL );
- if( InterlockedCompareExchangePointer( (PVOID*)mx, (PVOID)p, NULL ) != NULL )
+ if( InterlockedCompareExchangePointer( (PVOID*)mx, (PVOID)p, NULL )
+ != NULL )
CloseHandle(p);
}
int vg_thread_run( void *pfunc, void *data )
{
#ifdef _WIN32
-
HANDLE hThread = CreateThread
(
- NULL, // Thread attributes
- 0, // Stack size (0 = use default)
- pfunc, // Thread start address
- data, // Parameter to pass to the thread
- 0, // Creation flags
- NULL // Thread id
+ NULL, /* Thread attributes */
+ 0, /* Stack size (0 = use default) */
+ pfunc, /* Thread start address */
+ data, /* Parameter to pass to the thread */
+ 0, /* Creation flags */
+ NULL /* Thread id */
);
if ( hThread == NULL )
{
- // Thread creation failed.
- // More details can be retrieved by calling GetLastError()
+ /*
+ * Thread creation failed.
+ * More details can be retrieved by calling GetLastError()
+ */
return 1;
}
else
CloseHandle( hThread );
return 0;
}
-
#else
-
pthread_t hThread;
if( pthread_create( &hThread, NULL, pfunc, data ) )
{
pthread_detach( hThread );
return 0;
}
-
#endif
}
-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
+/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
const char *vg_shader_gl_ver = "#version 330 core\n";
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type"
-static inline int static_str_index( const char *list[], int len, const char *str )
+static inline int static_str_index( const char *list[], int len,
+ const char *str )
{
for( int i = 0; i < len; i ++ )
{
#define SHADER_NAME( NAME ) (NAME##_static_shader.program)
#define SHADER_USE( NAME ) glUseProgram( NAME##_static_shader.program )
-#define SHADER_UNIFORM( NAME, U ) NAME##_shader_uniforms[ STR_STATIC_INDEX( NAME##_shader_names, U ) ]
+#define SHADER_UNIFORM( NAME, U ) \
+ NAME##_shader_uniforms[ STR_STATIC_INDEX( NAME##_shader_names, U ) ]
#define SHADER_UNIFORM_NAME( NAME, UID ) NAME##_shader_names[ UID ]
-#define STR_STATIC_INDEX( LIST, STR ) static_str_index( LIST, vg_list_size(LIST), STR )
+#define STR_STATIC_INDEX( LIST, STR ) \
+ static_str_index( LIST, vg_list_size(LIST), STR )
#define UNIFORMS(...) __VA_ARGS__
if( geo )
glDeleteShader( geo );
- // Check for link errors
+ /* Check for link errors */
char infoLog[ 512 ];
int success_link = 1;
return 0;
}
- // Complete linkeage
+ /* Complete linkeage */
for( int i = 0; i < shader->uniform_count; i ++ )
- shader->uniforms[ i ] = glGetUniformLocation( shader->program, shader->uniform_names[i] );
+ {
+ shader->uniforms[ i ] =
+ glGetUniformLocation( shader->program, shader->uniform_names[i] );
+ }
shader->status |= SHADER_STATUS_COMPILED;
return 1;
-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
+/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
#define VG_TEXTURE_NO_MIP 0x1
#define VG_TEXTURE_REPEAT 0x2
static inline void vg_tex2d_linear_mipmap(void)
{
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ GL_LINEAR_MIPMAP_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}
qoi_desc info;
u8 *tex_buffer = qoi_decode( src_data, length, &info, 4 );
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, info.width, info.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_buffer );
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, info.width, info.height,
+ 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_buffer );
free( tex_buffer );
free( src_data );
};
vg_error( "Loading texture failed (%s)\n", path );
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_err );
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 2, 2,
+ 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_err );
}
return texture_name;
-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
+/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
SHADER_DEFINE( shader_ui,
- // VERTEX
- "layout (location=0) in vec2 a_co;" // i16, i16, .. ?
- "layout (location=1) in vec2 a_uv;" // i16, i16
- "layout (location=2) in vec4 a_colour;" // u32
- "layout (location=3) in vec4 a_clip;" // i16, i16, i16, i16
+ "layout (location=0) in vec2 a_co;"
+ "layout (location=1) in vec2 a_uv;"
+ "layout (location=2) in vec4 a_colour;"
+ "layout (location=3) in vec4 a_clip;"
"uniform mat3 uPv;"
""
"out vec2 aTexCoords;"
"aClip = a_clip;"
"}",
- // FRAGMENT
+ /* Fragment */
"uniform sampler2D uTexGlyphs;"
"out vec4 FragColor;"
""
""
"void main()"
"{"
- "float clip_blend = step( aWsp.x, aClip.z ) * step( aWsp.y, aClip.w ) * step( aClip.x, aWsp.x ) * step( aClip.y, aWsp.y );"
+ "float clip_blend = step( aWsp.x, aClip.z ) *"
+ "step( aWsp.y, aClip.w ) *"
+ "step( aClip.x, aWsp.x ) *"
+ "step( aClip.y, aWsp.y ); "
+
"vec4 glyph = vec4(1.0,1.0,1.0,1.0);"
"if( aColour.a == 0.0 )"
UNIFORMS({ "uPv", "uTexGlyphs" })
)
-// Types
-// ===========================================================================================================
-
typedef i16 ui_px;
typedef u32 ui_colour;
typedef ui_px ui_rect[4];
typedef struct ui_ctx ui_ctx;
typedef struct ui_colourset ui_colourset;
-// Relative to cursor p0
+/* Relative to cursor p0 */
enum ui_text_align
{
k_text_align_left = 0,
#pragma pack(push,1)
struct ui_vert
{
- ui_px co[2]; //32 4
- u8 uv[2]; //16 2
- u32 colour; //32 4
- ui_rect clip; //64 8
+ ui_px co[2];
+ u8 uv[2];
+ u32 colour;
+ ui_rect clip;
}
*verts;
#pragma pack(pop)
u32 id_base;
int glyph_base;
- // User input
+ /* User input */
ui_px mouse[2];
- int click_state; // 0: released, 1: on down, 2: pressed, 3: on release
+ int click_state; /* 0: released, 1: on down, 2: pressed, 3: on release */
ui_colourset *colours;
int image_count;
};
-// Globals
-// ===========================================================================================================
-
#define UI_GLYPH_SPACING_X 9
static GLuint ui_glyph_texture = 0;
static ui_ctx ui_global_ctx;
-// Initialization
-// ===========================================================================================================
-
static void ui_init_context( ui_ctx *ctx, int index_buffer_size )
{
u32 vertex_buffer_size = (index_buffer_size+(index_buffer_size/2));
- // Generate the buffer we are gonna be drawing to
+ /* Generate the buffer we are gonna be drawing to */
{
glGenVertexArrays(1, &ctx->vao);
glGenBuffers( 1, &ctx->vbo );
glBindBuffer( GL_ARRAY_BUFFER, ctx->vbo );
- glBufferData( GL_ARRAY_BUFFER, vertex_buffer_size * sizeof( struct ui_vert ), NULL, GL_DYNAMIC_DRAW );
+ glBufferData( GL_ARRAY_BUFFER,
+ vertex_buffer_size * sizeof( struct ui_vert ),
+ NULL, GL_DYNAMIC_DRAW );
glBindVertexArray( ctx->vao );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ctx->ebo );
- glBufferData( GL_ELEMENT_ARRAY_BUFFER, index_buffer_size * sizeof( u16 ), NULL, GL_DYNAMIC_DRAW );
+ glBufferData( GL_ELEMENT_ARRAY_BUFFER,
+ index_buffer_size * sizeof( u16 ), NULL, GL_DYNAMIC_DRAW );
u32 const stride = sizeof( struct ui_vert );
- // XY
- glVertexAttribPointer( 0, 2, GL_SHORT, GL_FALSE, stride, (void *)offsetof( struct ui_vert, co ) );
+ /* XY */
+ glVertexAttribPointer( 0, 2, GL_SHORT, GL_FALSE,
+ stride, (void *)offsetof( struct ui_vert, co ) );
glEnableVertexAttribArray( 0 );
- // UV
- glVertexAttribPointer( 1, 2, GL_UNSIGNED_BYTE, GL_FALSE, stride, (void *)offsetof( struct ui_vert, uv ) );
+ /* UV */
+ glVertexAttribPointer( 1, 2, GL_UNSIGNED_BYTE, GL_FALSE,
+ stride, (void *)offsetof( struct ui_vert, uv ) );
glEnableVertexAttribArray( 1 );
- // COLOUR
- glVertexAttribPointer( 2, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, (void *)offsetof( struct ui_vert, colour ) );
+ /* COLOUR */
+ glVertexAttribPointer( 2, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride,
+ (void *)offsetof( struct ui_vert, colour ) );
glEnableVertexAttribArray( 2 );
- // CLIPPING
- glVertexAttribPointer( 3, 4, GL_SHORT, GL_FALSE, stride, (void *)offsetof( struct ui_vert, clip ) );
+ /* CLIPPING */
+ glVertexAttribPointer( 3, 4, GL_SHORT, GL_FALSE, stride,
+ (void *)offsetof( struct ui_vert, clip ) );
glEnableVertexAttribArray( 3 );
}
- // Initialize default context
+ /* Initialize default context */
{
- ctx->verts = (struct ui_vert *)malloc( vertex_buffer_size * sizeof(struct ui_vert) );
+ ctx->verts = (struct ui_vert *)malloc(
+ vertex_buffer_size * sizeof(struct ui_vert) );
ctx->indices = (u16*)malloc( index_buffer_size * sizeof(u16) );
if( !ctx->colours )
static void ui_default_init(void)
{
- // Load default font
+ /* Load default font */
u32 compressed[] = {
#include "vg/vg_pxfont.h"
};
glGenTextures( 1, &ui_glyph_texture );
glBindTexture( GL_TEXTURE_2D, ui_glyph_texture );
- glTexImage2D( GL_TEXTURE_2D, 0, GL_R8, 256, 256, 0, GL_RED, GL_UNSIGNED_BYTE, image );
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_R8, 256, 256, 0,
+ GL_RED, GL_UNSIGNED_BYTE, image );
vg_tex2d_clamp();
vg_tex2d_nearest();
free( image );
- // Setup OpenGL memory
SHADER_INIT( shader_ui );
ui_init_context( &ui_global_ctx, 20000 );
}
ui_context_free( &ui_global_ctx );
}
-static struct ui_vert *ui_fill_rect_uv( ui_ctx *ctx, ui_rect rect, u32 colour, ui_px uv[4] );
+static struct ui_vert *ui_fill_rect_uv( ui_ctx *ctx, ui_rect rect,
+ u32 colour, ui_px uv[4] );
+
static void ui_draw( ui_ctx *ctx, m3x3f view_override )
{
u32 num_indices_normal = ctx->num_indices;
- // Append images to back of buffer
+ /* Append images to back of buffer */
for( int i = 0; i < ctx->image_count; i ++ )
- ui_fill_rect_uv( ctx, ctx->images[i].rc, 0xffffffff, (ui_px[4]){0,0,128,128} );
+ {
+ ui_fill_rect_uv( ctx, ctx->images[i].rc,
+ 0xffffffff, (ui_px[4]){0,0,128,128} );
+ }
glBindVertexArray( ctx->vao );
glBindBuffer( GL_ARRAY_BUFFER, ctx->vbo );
- glBufferSubData( GL_ARRAY_BUFFER, 0, ctx->num_verts * sizeof( struct ui_vert ), ctx->verts );
+ glBufferSubData( GL_ARRAY_BUFFER, 0,
+ ctx->num_verts * sizeof( struct ui_vert ), ctx->verts );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ctx->ebo );
- glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, 0, ctx->num_indices * sizeof( u16 ), ctx->indices );
+ glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, 0,
+ ctx->num_indices * sizeof( u16 ), ctx->indices );
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
view_override = view;
m3x3_translate( view, (v3f){ -1.0f, 1.0f, 0.0f } );
- m3x3_scale( view, (v3f){ 1.0f/((float)vg_window_x*0.5f), -1.0f/((float)vg_window_y*0.5f), 1.0f } );
+ m3x3_scale( view, (v3f){ 1.0f/((float)vg_window_x*0.5f),
+ -1.0f/((float)vg_window_y*0.5f), 1.0f } );
}
- glUniformMatrix3fv( SHADER_UNIFORM( shader_ui, "uPv" ), 1, GL_FALSE, (float *)view_override );
+ glUniformMatrix3fv( SHADER_UNIFORM( shader_ui, "uPv" ), 1,
+ GL_FALSE, (float *)view_override );
glActiveTexture( GL_TEXTURE0 );
glBindTexture( GL_TEXTURE_2D, ui_glyph_texture );
glUniform1i( SHADER_UNIFORM( shader_ui, "uTexGlyphs" ), 0 );
- glDrawElements( GL_TRIANGLES, num_indices_normal, GL_UNSIGNED_SHORT, (void*)(0) );
+ glDrawElements( GL_TRIANGLES, num_indices_normal,
+ GL_UNSIGNED_SHORT, (void*)(0) );
- // Draw image elements
+ /* Draw image elements */
for( int i = 0; i < ctx->image_count; i ++ )
{
struct ui_image *img = &ctx->images[i];
glBindTexture( GL_TEXTURE_2D, img->image );
- glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, (void*)( (num_indices_normal + 6*i)*sizeof(u16) ) );
+ glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
+ (void*)( (num_indices_normal + 6*i)*sizeof(u16) ) );
}
glDisable(GL_BLEND);
}
-// Rect controls
-// ===========================================================================================================
-
+/*
+ * Rect controls
+ */
static void ui_rect_copy( ui_rect src, ui_rect dst )
{
dst[0] = src[0];
rect[3] -= pad*2;
}
-// Stack control
-// ===========================================================================================================
-
+/*
+ * Stack control
+ */
static struct ui_qnode *ui_current( ui_ctx *ctx )
{
return &ctx->stack[ ctx->stack_count-1 ];
if( parent->mouse_over )
{
- if( ctx->mouse[0] >= node->rect[0] && ctx->mouse[0] < node->rect[0]+node->rect[2] &&
- ctx->mouse[1] >= node->rect[1] && ctx->mouse[1] < node->rect[1]+node->rect[3] )
+ if( ctx->mouse[0] >= node->rect[0] &&
+ ctx->mouse[0] < node->rect[0]+node->rect[2] &&
+ ctx->mouse[1] >= node->rect[1] &&
+ ctx->mouse[1] < node->rect[1]+node->rect[3] )
node->mouse_over = 1;
else
node->mouse_over = 0;
ctx->cursor[2] = node->rect[2] - (ctx->cursor[0]-node->rect[0]);
}
-// Alignment: | [] | -> | []|
static void ui_align_bottom( ui_ctx *ctx )
{
struct ui_qnode *node = ui_current( ctx );
ctx->clipping[3] = 32000;
}
-// Drawing
-// ===========================================================================================================
-
-static struct ui_vert *ui_fill_rect_uv( ui_ctx *ctx, ui_rect rect, u32 colour, ui_px uv[4] )
+static struct ui_vert *ui_fill_rect_uv( ui_ctx *ctx, ui_rect rect,
+ u32 colour, ui_px uv[4] )
{
struct ui_vert *vertices = &ctx->verts[ ctx->num_verts ];
vertices[0].co[0] = rect[0];
return ui_fill_rect_uv( ctx, rect, colour, (ui_px[4]){ 4,4, 4,4 } );
}
-static ui_px ui_text_line_offset( const char *str, ui_px scale, enum ui_text_align align )
+static ui_px ui_text_line_offset( const char *str, ui_px scale,
+ enum ui_text_align align )
{
if( align == k_text_align_left )
return 0;
return (-length * scale*8) / 2;
}
-static void ui_text( ui_ctx *ctx, ui_px pos[2], const char *str, ui_px scale, enum ui_text_align align )
+static void ui_text( ui_ctx *ctx, ui_px pos[2],
+ const char *str, ui_px scale, enum ui_text_align align )
{
ui_rect text_cursor;
u32 current_colour = 0x00ffffff;
glyph_base[0] *= 8;
glyph_base[1] *= 8;
- ui_fill_rect_uv( ctx, text_cursor, current_colour, (ui_px[4]){glyph_base[0]+2,glyph_base[1]+1,glyph_base[0]+6,glyph_base[1]+8} );
+ ui_fill_rect_uv( ctx, text_cursor, current_colour, (ui_px[4])
+ {
+ glyph_base[0]+2,
+ glyph_base[1]+1,
+ glyph_base[0]+6,
+ glyph_base[1]+8
+ });
}
else if( c == '\x1B' )
{
}
}
-// API control
-// ====================================================================
-
+/*
+ * API Control
+ */
static void ui_begin( ui_ctx *ctx, ui_px res_x, ui_px res_y )
{
ctx->cursor[0] = 0;
}
}
-// User Input piping
-// ====================================================================
-
static void ui_set_mouse( ui_ctx *ctx, int x, int y, int click_state )
{
ctx->mouse[0] = x;
ctx->click_state = click_state;
}
-// High level controls
-// ====================================================================
-
+/*
+ * High level controls
+ */
struct ui_window
{
const char *title;
{
ui_capture_mouse( ctx, __COUNTER__ );
- // Drag bar
+ /* Drag bar */
ctx->cursor[3] = 25;
ui_new_node( ctx );
{
struct ui_vert *drag_bar = ui_fill_rect( ctx, ctx->cursor, 0xff555555 );
- // title..
+ /* title.. */
ctx->cursor[0] += 2;
ctx->cursor[1] += 2;
ui_text( ctx, ctx->cursor, window->title, 2, 0 );
- // Close button
+ /* Close button */
ctx->cursor[3] = 25;
ctx->cursor[2] = 25;
ui_align_right( ctx );
drag_bar[2].colour = 0xff777777;
drag_bar[3].colour = 0xff777777;
- // start drag
+ /* start drag */
if( ctx->click_state == 1 )
{
window->drag = 1;
return 1;
}
-struct ui_scrollbar
-{
- int drag;
- ui_px drag_offset;
-
- ui_px py;
- ui_px bar_height;
- ui_px view_height;
-};
-
-static void ui_scrollbar( ui_ctx *ctx, struct ui_scrollbar *scrollbar, u32 id )
-{
- scrollbar->view_height = ctx->cursor[3];
-
- if( scrollbar->drag )
- {
- scrollbar->py = ctx->mouse[1]+scrollbar->drag_offset;
- scrollbar->py = VG_MAX( scrollbar->py, 0 );
- scrollbar->py = VG_MIN( scrollbar->py, ctx->cursor[3] - scrollbar->bar_height );
-
- if( ctx->click_state == 0 || ctx->click_state == 3 )
- scrollbar->drag = 0;
- }
-
- ui_new_node( ctx );
- {
- ui_fill_rect( ctx, ctx->cursor, ctx->colours->background );
- ui_capture_mouse( ctx, id );
-
- ctx->cursor[1] += scrollbar->py;
- ctx->cursor[3] = scrollbar->bar_height;
-
- ui_new_node( ctx );
- {
- ui_capture_mouse( ctx, __COUNTER__ );
- struct ui_vert *drag_bar = ui_fill_rect( ctx, ctx->cursor, ctx->colours->bar );
-
- if( ui_hasmouse( ctx ) || scrollbar->drag )
- {
- drag_bar[0].colour = ctx->colours->bar_hover;
- drag_bar[1].colour = ctx->colours->bar_hover;
- drag_bar[2].colour = ctx->colours->bar_hover;
- drag_bar[3].colour = ctx->colours->bar_hover;
-
- // start drag
- if( ctx->click_state == 1 )
- {
- scrollbar->drag = 1;
- scrollbar->drag_offset = scrollbar->py - ctx->mouse[1];
- }
- }
- }
- ui_end_down( ctx );
- }
- ui_end( ctx );
-}
-
-static ui_px ui_calculate_content_scroll( struct ui_scrollbar *scrollbar, ui_px content )
-{
- float overlap = vg_maxf( 0.0f, (float)(content - scrollbar->view_height) );
-
- float range = scrollbar->view_height - scrollbar->bar_height;
- return ((float)scrollbar->py / range) * overlap;
-}
-
static void ui_push_image( ui_ctx *ctx, ui_rect rc, GLuint image )
{
struct ui_image *img = &ctx->images[ ctx->image_count ++ ];
img->image = image;
}
-// Shortnames
+/* Shortnames */
#define gui_draw(...) ui_draw( &ui_global_ctx, __VA_ARGS__)
#define gui_current(...) ui_current( &ui_global_ctx, __VA_ARGS__)
#define gui_new_node() ui_new_node( &ui_global_ctx )
#define gui_window(...) ui_window( &ui_global_ctx, __VA_ARGS__)
#define gui_want_mouse() ui_want_mouse( &ui_global_ctx )
#define gui_push_image(...) ui_push_image( &ui_global_ctx, __VA_ARGS__ )
-#define gui_scrollbar(...) ui_scrollbar( &ui_global_ctx, __VA_ARGS__)
#define gui_reset_colours(...) ui_reset_colours( &ui_global_ctx )
fi
}
-if [[ -f vg.conf ]]; then
- source vg.conf
-else
- error "Directory is not a VG project"
- exit 1
-fi
-
# Platforms
# ===========================================
target_os_windows(){
target_ext=".exe"
target_compiler="i686-w64-mingw32-gcc"
- target_libs="-lglfw3 -lopengl32 -lm -mwindows"
+ target_libs="-lglfw3 -lopengl32 -lm -mwindows $vg_root/dep/steam/steam_api.dll"
target_dir="build.win32"
target_steam_api="steam_api.dll"
target_miniaudio="$vg_root/dep/dr_soft/miniaudio_win32.o"
target_os_linux(){
target_ext=""
target_compiler="gcc"
- target_libs="-lGL -lglfw -lX11 -lXxf86vm -lXrandr -lm -lpthread -lXi -ldl -lsteam_api"
+ target_libs="-lGL -lglfw -lX11 -lXxf86vm -lXrandr -lm -lpthread -lXi -ldl"
+
+ if [ "$opt_steam" != "" ]; then
+ target_libs="$target_libs -lsteam_api"
+ fi
+
target_dir="build.linux"
target_steam_api="libsteam_api.so"
target_miniaudio="$vg_root/dep/dr_soft/miniaudio_linux.o"
if [ $opt_release = true ]; then
- target_opts="-O3"
+ target_opts="-O0"
else
- target_opts="-fsanitize=address -ggdb3"
+ target_opts="-O0 -fsanitize=address -ggdb3 -fno-omit-frame-pointer"
fi
}
precompile_x(){
- cmd="$target_compiler -O3 -Wall -c $1 -o $2.o"
+ cmd="$target_compiler -O3 -Wall -Wstrict-aliasing=3 -c $1 -o $2.o"
logit " $cmd"
$cmd
}
compile_x(){
- paths="-I. -L$vg_root/dep/glfw -L$vg_root/dep/steam -I$vg_root/dep -I$vg_root/src"
+ paths="-I. -L./ -L$vg_root/dep/glfw -L$vg_root/dep/steam -I$vg_root/dep -I$vg_root/src"
setup="$target_compiler $opt_gcc -Wall -Wstrict-aliasing=3 -Wno-unused-function $paths"
targets="$1 $vg_root/dep/glad/glad.c $target_miniaudio -o $2$target_ext"
final="$target_libs -Wl,-rpath=./ $opt_steam"
options=rptlwaq
-longopts=release,build-linux,build-windows,steam,play,build-tools,assets,full,miniaudio
+longopts=release,build-linux,build-windows,steam,play,build-tools,assets,full,miniaudio,template
parsed=$(getopt --options=$options --longoptions=$longopts --name "vgc" -- "$@")
if [ $? -ne 0 ]; then
;;
--steam)
opt_steam="-DVG_STEAM"
+ shift;
+ ;;
+ --template)
+
+ if [ -f "main.c" ]; then error "main.c already exists";
+ elif [ -f "vg_config.h" ]; then error "vg_config.h already exists";
+ elif [ -f "vg.conf" ]; then error "vg.conf already exists";
+ else
+ cp $vg_root/src/template/main.c main.c
+ cp $vg_root/src/template/vg_config.h vg_config.h
+ cp $vg_root/src/template/vg.conf vg.conf
+ fi
+
shift;
;;
--)
esac
done
+if [[ -f vg.conf ]]; then
+ source vg.conf
+else
+ error "Directory is not a VG project"
+ exit 1
+fi
+
detect_os(){
if [[ "$OSTYPE" != "linux-gnu"* ]]; then
host_os=win32