X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=main.c;h=b46f3771b5a565abba28504e852f745fe97f5bfc;hb=4a883ac1b2506032f9dddab342712de46f2ca734;hp=b397e2e9ec759a7af26589d5df62ef540ce106c6;hpb=3f59dc191c7792947cd2d3f6588be06933fd49f0;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/main.c b/main.c index b397e2e..b46f377 100644 --- a/main.c +++ b/main.c @@ -1,86 +1,114 @@ -#define VG_3D -#include "vg/vg.h" +/* + * Copyright (C) Mount0 Software, Harry Godden - All Rights Reserved + */ + +#include "common.h" /* Resources */ vg_tex2d tex_norwey = { .path = "textures/norway_foliage.qoi" }; vg_tex2d tex_grid = { .path = "textures/grid.qoi" }; -vg_tex2d tex_road = { .path = "textures/road.qoi" }; +vg_tex2d tex_sky = { .path = "textures/sky.qoi" }; vg_tex2d tex_gradients = { .path = "textures/gradients.qoi", .flags = VG_TEXTURE_CLAMP }; -vg_tex2d *texture_list[] = -{ - &tex_norwey, - &tex_gradients, - &tex_grid, - &tex_road -}; +vg_tex2d tex_cement = { .path = "textures/cement512.qoi" }; +vg_tex2d tex_water = { .path = "textures/water.qoi" }; /* Convars */ -static int freecam = 0; static int debugview = 0; -static int debugsdf = 0; -static int debugroad = 0; +static int sv_debugcam = 0; +static int lightedit = 0; +static int sv_scene = 0; +static int cl_ui = 1; /* Components */ -#include "road.h" -#include "scene.h" +//#define SR_NETWORKED -int main( int argc, char *argv[] ) -{ - vg_init( argc, argv, "Voyager Game Engine" ); -} +/* uncomment this to run the game without any graphics being drawn */ +//#define SR_NETWORK_TEST -m4x3f world_matrix; -v3f player_pos; -v3f player_head; /* Relative to pos */ -v3f player_vel = { 0.0f, 0.0f, -0.2f }; -float player_yaw; -v2f look_dir; -v3f player_accel; +#include "steam.h" +#include "network.h" -float waves[128][128]; - -road_patch road_main; -scene test_scene; -scene world_scene; -scene player_scene; -u32 world_terrain_count, - world_road_count; +#include "model.h" +//#include "road.h" +#include "scene.h" +//#include "ik.h" +#include "audio.h" +//#include "terrain.h" +//#include "character.h" +#include "ragdoll.h" +#include "rigidbody.h" +#include "render.h" +#include "world.h" +#include "player.h" + +#include "shaders/blit.h" +#include "shaders/standard.h" +#include "shaders/unlit.h" + +#include "physics_test.h" +#include "anim_test.h" + +#include "gate.h" +#include "water.h" -static int reset_player( int argc, char const *argv[] ) +void vg_register(void) { - v3_zero( player_pos ); - v3_copy( (v3f){ 0.0f, 0.0f, -0.2f }, player_vel ); - player_yaw = 0.0f; - - return 0; + shader_blit_register(); + shader_standard_register(); + shader_vblend_register(); + shader_unlit_register(); + + world_register(); + character_register(); + water_register(); + gate_register(); } -void vg_register(void) +static void init_other(void) { - scene_register(); + player_init(); + render_init(); + gate_init(); + world_init(); + character_init(); + audio_init(); } -void vg_start(void) +vg_tex2d *texture_list[] = { - for( int y=0; y<128; y++ ) - { - for( int x=0; x<128; x++ ) - { - v2f pos = {x,y}; + &tex_norwey, + &tex_gradients, + &tex_grid, + &tex_sky, + &tex_cement, + &tex_water, + &tex_water_surf +}; - waves[x][y] = sinf( pos[0] * 0.1f ) * - cosf( pos[1] * 0.3f ) * 5.0f + x*-0.2f; - } - } +int main( int argc, char *argv[] ) +{ + vg_init( argc, argv, "Voyager Game Engine" ); +} - vg_tex2d_init( texture_list, vg_list_size( texture_list ) ); +static int playermodel( int argc, char const *argv[] ) +{ + if( argc < 1 ) return 0; - road_patch_init( &road_main ); - road_generate( &road_main ); + glmesh old_mesh = player.mdl.mesh; + + if( character_load( &player.mdl, argv[0] ) ) + mesh_free( &old_mesh ); + + return 1; +} + +void vg_start(void) +{ + steam_init(); vg_convar_push( (struct vg_convar){ - .name = "freecam", + .name = "fc", .data = &freecam, .data_type = k_convar_dtype_i32, .opt_i32 = { .min=0, .max=1, .clamp=1 }, @@ -88,597 +116,404 @@ void vg_start(void) }); vg_convar_push( (struct vg_convar){ - .name = "debugview", - .data = &debugview, + .name = "grid", + .data = &walk_grid_iterations, .data_type = k_convar_dtype_i32, .opt_i32 = { .min=0, .max=1, .clamp=0 }, .persistent = 1 }); vg_convar_push( (struct vg_convar){ - .name = "debugsdf", - .data = &debugsdf, + .name = "fcs", + .data = &fc_speed, + .data_type = k_convar_dtype_f32, + .opt_f32 = { .clamp = 0 }, + .persistent = 1 + }); + + vg_convar_push( (struct vg_convar){ + .name = "ledit", + .data = &lightedit, .data_type = k_convar_dtype_i32, .opt_i32 = { .min=0, .max=1, .clamp=1 }, .persistent = 1 }); vg_convar_push( (struct vg_convar){ - .name = "debugroad", - .data = &debugroad, + .name = "cl_ui", + .data = &cl_ui, .data_type = k_convar_dtype_i32, .opt_i32 = { .min=0, .max=1, .clamp=1 }, .persistent = 1 }); - vg_function_push( (struct vg_cmd){ - .name = "reset", - .function = reset_player - }); - - v3f lightDir = { 0.1f, 0.8f, 0.2f }; - v3_normalize( lightDir ); - - scene_init( &world_scene ); - scene_init( &test_scene ); - scene_init( &player_scene ); - model *world = vg_asset_read( "models/free_dev.mdl" ); - model *test = vg_asset_read( "models/test.mdl" ); - model *char_dev = vg_asset_read( "models/char_dev.mdl" ); - scene_add_model( &player_scene, char_dev, - submodel_get( char_dev, "joint" ), - (v3f){0.0f,0.0f,0.0f}, 0.0f, 1.0f ); - free(char_dev); - - scene_add_model( &world_scene, world, - submodel_get( world, "terrain" ), - (v3f){0.0f,0.0f,0.0f}, 0.0f, 1.0f ); - - int id_tree = submodel_get( test, "tree" ), - id_groundcover[] = - { - submodel_get( test, "bush" ), - submodel_get( test, "grass" ), - submodel_get( test, "blubber" ), - submodel_get( test, "blubber" ), - submodel_get( test, "blubber" ), - submodel_get( test, "grassthin" ) - }; - - /* Sprinkle some trees in the terrain areas */ - v3f range; - v3_sub( world_scene.bbx[1], world_scene.bbx[0], range ); - - for( int i=0; i<8000; i++ ) - { - v3f pos; + vg_convar_push( (struct vg_convar){ + .name = "walk_speed", + .data = &k_walkspeed, + .data_type = k_convar_dtype_f32, + .opt_f32 = { .clamp = 0 }, + .persistent = 1 + }); - pos[0] = vg_randf(); - pos[1] = 0.0f; - pos[2] = vg_randf(); - v3_muladd( world_scene.bbx[0], pos, range, pos ); + vg_convar_push( (struct vg_convar){ + .name = "run_speed", + .data = &k_runspeed, + .data_type = k_convar_dtype_f32, + .opt_f32 = { .clamp = 0 }, + .persistent = 1 + }); - if( sample_scene_height( &world_scene, pos ) ) - { - scene_add_model( &test_scene, test, - id_tree, - pos, vg_randf() * VG_TAUf, vg_randf() * 0.5f + 0.5f ); - } - } + vg_convar_push( (struct vg_convar){ + .name = "walk_accel", + .data = &k_walk_accel, + .data_type = k_convar_dtype_f32, + .opt_f32 = { .clamp = 0 }, + .persistent = 1 + }); - world_terrain_count = world_scene.indice_count; + vg_convar_push( (struct vg_convar){ + .name = "dt", + .data = &ktimestep, + .data_type = k_convar_dtype_f32, + .opt_f32 = { .clamp = 0 }, + .persistent = 0 + }); - scene_add_model( &world_scene, world, - submodel_get( world, "road" ), - (v3f){0.0f,0.0f,0.0f}, 0.0f, 1.0f ); - world_road_count = world_scene.indice_count-world_terrain_count; + vg_convar_push( (struct vg_convar){ + .name = "debugcam", + .data = &sv_debugcam, + .data_type = k_convar_dtype_i32, + .opt_i32 = { .min=0, .max=1, .clamp=0 }, + .persistent = 1 + }); - free( test ); - free( world ); + vg_convar_push( (struct vg_convar){ + .name = "debugview", + .data = &debugview, + .data_type = k_convar_dtype_i32, + .opt_i32 = { .min=0, .max=1, .clamp=0 }, + .persistent = 1 + }); -#if 0 - scene_compute_occlusion( &test_scene ); - scene_shadow_gradient( &test_scene, 1, 0.0f, 1.0f ); - scene_shadow_sphere( &test_scene, (v3f){ 0.0f,4.0f,0.0f}, - (v4f){1.0f, 2.0f, 0.0f, 0.0f}, lightDir ); -#endif + vg_function_push( (struct vg_cmd){ + .name = "reset", + .function = reset_player + }); - scene_upload( &player_scene ); - scene_upload( &world_scene ); - scene_upload( &test_scene ); -} + vg_tex2d_init( texture_list, vg_list_size( texture_list ) ); + + init_other(); -static float sample_terrain( v3f pos ) -{ - v3f local; - v3_muls( pos, 0.1f, local ); + /* + * If we're in physics test mode we dont need to load anything else, this + * parameter is dev only. TODO: dev only cvars that don't ship with the game + * when building in release mode. + */ - v2i ico = { local[0], local[2] }; - for( int i=0; i<2; i++ ) + if( sv_scene == 0 ) { - if( ico[i] < 0 ) ico[i] = 0; - if( ico[i] > 126 ) ico[i] = 126; - } + character_load( &player.mdl, "ch_new" ); + character_init_ragdoll( &player.mdl ); - float hse = waves[ico[0]+1][ico[1]], - hsw = waves[ico[0]][ico[1]], - hne = waves[ico[0]+1][ico[1]+1], - hnw = waves[ico[0]][ico[1]+1]; + world_load(); - v3f subcoord; - v3_floor( local, subcoord ); - v3_sub( local, subcoord, subcoord ); + reset_player( 1, (const char *[]){ "start" } ); + rb_init( &player.rb ); - float hs = vg_lerpf( hse, hsw, 1.0f-subcoord[0] ), - hn = vg_lerpf( hne, hnw, 1.0f-subcoord[0] ), - sampleh = vg_lerpf( hs, hn, subcoord[2] ); - - return sampleh*10.0f; -} - -static void draw_terrain(void) -{ - float sf = 10.0f; - - /* Draw waves - */ - for( int y=0; y<63; y++ ) + network_init(); + } + else if( sv_scene == 1 ) { - for( int x=0; x<63; x++ ) - { - v2i pos = {x*2,y*2}; - vg_line( (v3f){ pos[0]*sf, waves[pos[0]][pos[1]]*sf, pos[1]*sf }, - (v3f){ (pos[0]+2)*sf, waves[pos[0]+2][pos[1]]*sf, pos[1]*sf }, - 0xa0ffffff ); - - vg_line( (v3f){ pos[1]*sf, waves[pos[1]][pos[0]]*sf, pos[0]*sf }, - (v3f){ pos[1]*sf, waves[pos[1]][pos[0]+2]*sf, (pos[0]+2)*sf }, - 0xa0ffffff ); - } + physics_test_start(); + } + else if( sv_scene == 2 ) + { + anim_test_start(); } - } -v3f head, butt, knee_r, knee_l, foot_r, foot_l, hand_r, hand_l, - shoulder_r, shoulder_l; - +void vg_free(void) +{ + network_end(); + vg_tex2d_free( texture_list, vg_list_size(texture_list) ); + /* TODO: THE REST OF THE GOD DAMN FREEING STUFF */ + steam_end(); +} void vg_update(void) { - float timestep = 1.0f/60.0f; + steam_update(); - if( freecam ) + if( sv_scene == 0 ) { - m4x3f cam_rot; - m4x3_identity( cam_rot ); - m4x3_rotate_y( cam_rot, -look_dir[0] ); - m4x3_rotate_x( cam_rot, -look_dir[1] ); - - v3f lookdir = { 0.0f, 0.0f, -1.0f }, - sidedir = { 1.0f, 0.0f, 0.0f }; - - m4x3_mulv( cam_rot, lookdir, lookdir ); - m4x3_mulv( cam_rot, sidedir, sidedir ); - - float movespeed = 5.0f; - static v2f mouse_last, - view_vel = { 0.0f, 0.0f }; - static v3f move_vel = { 0.0f, 0.0f, 0.0f }; - - if( vg_get_button_down( "primary" ) ) + network_update(); + player_update(); + world_update(); + //traffic_visualize( world.traffic, world.traffic_count ); + // + /* TEMP */ + if( glfwGetKey( vg_window, GLFW_KEY_J )) { - v2_copy( vg_mouse, mouse_last ); + v3_copy( player.camera_pos, world.mr_ball.co ); } - else if( vg_get_button( "primary" ) ) - { - v2f delta; - v2_sub( vg_mouse, mouse_last, delta ); - v2_copy( vg_mouse, mouse_last ); - - v2_muladds( view_vel, delta, 0.005f, view_vel ); - } - - v2_muls( view_vel, 0.75f, view_vel ); - v2_add( view_vel, look_dir, look_dir ); - look_dir[1] = vg_clampf( look_dir[1], -VG_PIf*0.5f, VG_PIf*0.5f ); - - if( vg_get_button( "forward" ) ) - v3_muladds( move_vel, lookdir, timestep * movespeed, move_vel ); - if( vg_get_button( "back" ) ) - v3_muladds( move_vel, lookdir, timestep *-movespeed, move_vel ); - if( vg_get_button( "left" ) ) - v3_muladds( move_vel, sidedir, timestep *-movespeed, move_vel ); - if( vg_get_button( "right" ) ) - v3_muladds( move_vel, sidedir, timestep * movespeed, move_vel ); - - v3_muls( move_vel, 0.75f, move_vel ); - v3_add( move_vel, player_head, player_head ); - - return; } - - if( vg_get_button( "forward" ) ) + else if( sv_scene == 1 ) { - v3f accel = { sinf( player_yaw ), 0.0f, -cosf( player_yaw ) }; - v3_muladds( player_vel, accel, 5.0f * timestep, player_vel ); + physics_test_update(); } - - m4x3f player_transform, - world_to_local, local_to_world; - - m4x3_identity( player_transform ); - m4x3_translate( player_transform, player_pos ); - m4x3_rotate_y( player_transform, -player_yaw ); - - m4x3_identity( world_to_local ); - m4x3_rotate_y( world_to_local, player_yaw ); - - m4x3_identity( local_to_world ); - m4x3_rotate_y( local_to_world, -player_yaw ); - - /* Get front and back contact points */ - v3f contact_front, contact_back, fwd, fwd1, contact_norm; - - m4x3_mulv( local_to_world, (v3f){0.0f,0.0f,-1.0f}, fwd ); - m4x3_mulv( local_to_world, (v3f){0.03f,0.0f,-1.0f}, fwd1 ); - - v3_muladds( player_pos, fwd, 1.0f, contact_front ); - v3_muladds( player_pos, fwd,-1.0f, contact_back ); - v3_muladds( player_pos, fwd1, 1.0f, contact_norm ); - -#if 0 - road_patch_setplayer( &road_main, player_pos ); - sample_road_height( &road_main, contact_front ); - sample_road_height( &road_main, contact_back ); -#else - sample_scene_height( &world_scene, contact_front ); - sample_scene_height( &world_scene, contact_back ); - sample_scene_height( &world_scene, contact_norm ); -#endif - - v3f norm; - v3f v0, v1; - v3_sub( contact_back, contact_norm, v0 ); - v3_sub( contact_front, contact_norm, v1 ); - v3_cross( v1, v0, norm ); - v3_normalize( norm ); - - v3f gravity = { 0.0f, -9.6f, 0.0f }; - v3_muladds( player_vel, gravity, timestep, player_vel ); - - v3f ground_pos; - v3_copy( player_pos, ground_pos ); - sample_scene_height( &world_scene, ground_pos ); - - static int in_air = 1; - - if( in_air ) + else if( sv_scene == 2 ) { - if( ground_pos[1] > player_pos[1] ) - in_air = 0; + anim_test_update(); } +} - if( !in_air ) - { - float resistance = v3_dot( norm, player_vel ); - - if( resistance >= 0.0f ) - in_air = 1; - else - { - v3_muladds( player_vel, norm, -resistance, player_vel ); - } - } +static void vg_framebuffer_resize( int w, int h ) +{ + render_fb_resize(); + gate_fb_resize(); + water_fb_resize(); +} - /* vg_info( "%.3f | %.3f\n", player_vel[1], resistance ); */ - v3_muladds( player_pos, player_vel, timestep, player_pos ); - - float slip = 0.0f; +static void draw_origin_axis(void) +{ + vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 1.0f, 0.0f, 0.0f }, 0xffff0000 ); + vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 0.0f, 1.0f, 0.0f }, 0xff00ff00 ); + vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 0.0f, 0.0f, 1.0f }, 0xff0000ff ); +} - if( !in_air ) - { - player_pos[1] = (contact_front[1]+contact_back[1])*0.5f; +static void render_main_game(void) +{ + float speed = freecam? 0.0f: v3_length( player.rb.v ); + v3f shake = { vg_randf()-0.5f, vg_randf()-0.5f, vg_randf()-0.5f }; + v3_muls( shake, speed*0.01f, shake ); - vg_line( player_pos, contact_front, 0xff00ffff ); - vg_line( player_pos, contact_back, 0xff00ffa0 ); + m4x4f world_4x4; + m4x3_expand( player.camera_inverse, world_4x4 ); - /* Create the 'travel' vector */ - v3f travel; - v3_sub( contact_front, contact_back, travel ); - v3_normalize( travel ); + gpipeline.fov = freecam? 60.0f: 125.0f; /* 120 */ + m4x4_projection( vg_pv, gpipeline.fov, + (float)vg_window_x / (float)vg_window_y, + 0.02f, 2100.0f ); - /* Apply gravity */ -#if 0 - float gravity_conversion = -v3_dot( travel, gravity ); - vel[2] += gravity_conversion * substep; -#endif + m4x4_mul( vg_pv, world_4x4, vg_pv ); - /* Get localized (rotated) rigidbody forces - * -z - * ^ - * -|- - * | - * +z + glEnable( GL_DEPTH_TEST ); + + /* + * Draw world */ + + int draw_solid = player.is_dead | freecam; - v3f vel; - m4x3_mulv( world_to_local, player_vel, vel ); + render_world( vg_pv, player.camera ); + if( draw_solid ) + draw_player(); + render_water_texture( player.camera ); - /* Calculate local forces */ - slip = -vel[0] / vel[2]; - float substep = timestep * 0.2f; + glBindFramebuffer( GL_FRAMEBUFFER, 0 ); + render_water_surface( vg_pv, player.camera ); - if( fabsf( slip ) > 1.2f ) - { - slip = vg_signf( slip ) * 1.2f; - } + vg_tex2d_bind( &tex_water, 1 ); /*TODO: ?*/ + render_world_gates( vg_pv, player.camera ); - for( int i=0; i<5; i++ ) - { - if( fabsf(vel[2]) >= 0.02f*substep ) - vel[2] += vg_signf( vel[2] ) * -0.02f * substep; - if( fabsf(vel[0]) >= 6.0f*substep ) - vel[0] += vg_signf( vel[0] ) * -6.0f * substep; - } + /* Copy the RGB of what we have into the background buffer */ + glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 ); + glBindFramebuffer( GL_DRAW_FRAMEBUFFER, gpipeline.fb_background ); + glBlitFramebuffer( 0,0, vg_window_x, vg_window_y, + 0,0, vg_window_x, vg_window_y, + GL_COLOR_BUFFER_BIT, + GL_LINEAR ); - m4x3_mulv( local_to_world, vel, player_vel ); + /* Clear out the colour buffer, but keep depth */ + glBindFramebuffer( GL_FRAMEBUFFER, 0 ); + glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); - if( vg_get_button( "yawl" ) ) - player_yaw -= 1.6f * timestep; - if( vg_get_button( "yawr" ) ) - player_yaw += 1.6f * timestep; - - player_yaw += vg_get_axis( "horizontal" ) * 1.6f * timestep; - } + if( !player.is_dead ) + glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ); else + glClear( GL_COLOR_BUFFER_BIT ); + + if( !draw_solid ) { - player_yaw += vg_get_axis( "horizontal" ) * 3.6f * timestep; - look_dir[0] = player_yaw; + m4x4_projection( vg_pv, gpipeline.fov, + (float)vg_window_x / (float)vg_window_y, + 0.01f, 600.0f ); + m4x4_mul( vg_pv, world_4x4, vg_pv ); + draw_player(); } - look_dir[0] = atan2f( player_vel[0], -player_vel[2] ); + /* Draw back in the background + * + * TODO: need to disable alpha write in the terrain shader so this works + * again. + */ + glEnable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA); + glBlendEquation(GL_FUNC_ADD); - /* Creating a skeleton of the player dynamically */ - float kheight = 1.8f, - kleg = 0.6f; + shader_blit_use(); + shader_blit_uTexMain( 0 ); + glActiveTexture(GL_TEXTURE0); + glBindTexture( GL_TEXTURE_2D, gpipeline.rgb_background ); - v2f ac; + render_fsquad(); + glDisable(GL_BLEND); - static v3f last_vel = { 0.0f, 0.0f, 0.0f }; - static v3f bob, bob1; - - v3_sub( player_vel, last_vel, player_accel ); - v3_copy( player_vel, last_vel ); - v3_add( bob, player_accel, bob ); - - bob[0] = vg_clampf( bob[0], -0.4f, 1.0f ); - bob[1] = vg_clampf( bob[1], -0.4f, 1.3f ); - bob[2] = vg_clampf( bob[2], -0.4f, 1.0f ); - - v3_lerp( bob, (v3f){ 0.0f, 0.0f, 0.0f }, 0.1f, bob ); - v3_lerp( bob1, bob, 0.1f, bob1 ); - - /* Feet */ - foot_r[0] = 0.0f; - foot_r[1] = 0.0f; - foot_r[2] = 0.3f; - - foot_l[0] = 0.0f; - foot_l[1] = 0.0f; - foot_l[2] = -0.3f; - - /* Head */ - head[0] = (-sinf(slip)*0.9f * kheight + bob1[0]*0.6f) * 0.54f; - head[1] = cosf(slip)*0.9f * kheight +-bob1[1]*1.4f; - head[2] = 0.0f; - - /* Hips */ - butt[0] = -sinf(slip)*0.2f; - butt[1] = cosf(slip); - butt[2] = 0.0f; - v2_normalize(butt); - v2_muls( butt, -0.7f, butt ); - v2_add( head, butt, butt ); - - /* Knees */ - v2_sub( butt, (v2f){0.0f,0.0f}, ac ); - float cl = v2_length( ac ), - d = acosf( (2.0f * kleg*kleg - cl*cl) / 2.0f * kleg*kleg ), - x = atan2f( ac[0], ac[1] ), - ad = (-VG_PIf-d)/2.0f; - - v2_muladds( (v2f){0.0f,0.0f}, - (v2f){ sinf( ad+x ), cosf( ad + x ) }, - kleg, knee_l ); - knee_l[2] = -0.3f; - - v2_copy( knee_l, knee_r ); - knee_r[2] = 0.3f; - - /* shoulders */ - v3_add( (v3f){0.0f,-0.1f,-0.2f}, head, shoulder_r ); - - /* Hands */ - hand_r[0] = sinf( slip ) * 0.1f; - hand_r[1] = -cosf( slip*5.0f ) * 0.5f - 0.5f; - hand_r[2] = -sinf( fabsf(slip) * 2.4f ); - v3_add( shoulder_r, hand_r, hand_r ); - - m4x3_mulv( player_transform, head, head ); - m4x3_mulv( player_transform, butt, butt ); - m4x3_mulv( player_transform, knee_l, knee_l ); - m4x3_mulv( player_transform, knee_r, knee_r ); - m4x3_mulv( player_transform, foot_l, foot_l ); - m4x3_mulv( player_transform, foot_r, foot_r ); - m4x3_mulv( player_transform, hand_r, hand_r ); - m4x3_mulv( player_transform, shoulder_r, shoulder_r ); - - v3_copy( head, player_head ); - + /* Other shite */ + glDisable( GL_DEPTH_TEST ); + vg_lines_drawall( (float *)vg_pv ); + glViewport( 0,0, vg_window_x, vg_window_y ); } -static void debug_grid( v3f at ) +void vg_render(void) { - v3f base; - v3_floor( at, base ); + glBindFramebuffer( GL_FRAMEBUFFER, 0 ); + glViewport( 0,0, vg_window_x, vg_window_y ); - for( int y=0; y<16; y++ ) + glDisable( GL_DEPTH_TEST ); + glClearColor( 0.11f, 0.35f, 0.37f, 1.0f ); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); + +#ifndef SR_NETWORK_TEST + draw_origin_axis(); + + if( sv_scene == 0 ) { - vg_line( (v3f){ base[0] - 8, base[1], base[2]+y-8 }, - (v3f){ base[0] + 8, base[1], base[2]+y-8 }, - 0x40ffffff ); + render_main_game(); } - for( int x=0; x<16; x++ ) + else if( sv_scene == 1 ) { - vg_line( (v3f){ base[0]+x-8, base[1], base[2]-8 }, - (v3f){ base[0]+x-8, base[1], base[2]+8 }, - 0x40ffffff ); + physics_test_render(); } + else if( sv_scene == 2 ) + { + anim_test_render( &tex_characters ); + } +#endif } -void vg_render(void) +static void run_light_widget( struct light_widget *lw ) { - glViewport( 0,0, vg_window_x, vg_window_y ); - - glDisable( GL_DEPTH_TEST ); - glClearColor( 0.1f, 0.0f, 0.2f, 1.0f ); - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - - v3f pos_inv; - v3_negate( player_head, pos_inv ); + struct ui_checkbox c1 = { .data=&lw->enabled }; - float speed = v3_length( player_vel ); - v3f shake = { vg_randf()-0.5f, vg_randf()-0.5f, vg_randf()-0.5f }; - v3_muls( shake, speed*0.01f, shake ); - - m4x3_identity( world_matrix ); - m4x3_rotate_x( world_matrix, freecam? look_dir[1]: 0.3f+shake[1]*0.04f ); - m4x3_rotate_y( world_matrix, look_dir[0]+shake[0]*0.02f ); - m4x3_translate( world_matrix, pos_inv ); + ui_checkbox( &ui_global_ctx, &c1 ); - m4x4f world_4x4; - m4x3_expand( world_matrix, world_4x4 ); - - m4x4_projection( vg_pv, - freecam? 90.0f: 130.0f, - (float)vg_window_x / (float)vg_window_y, - 0.01f, 1000.0f ); - m4x4_mul( vg_pv, world_4x4, vg_pv ); - - if( debugroad ) - draw_road_patch_dev( &road_main ); + if( lw->enabled ) + { + struct ui_slider_vector + colour = { .min=0.0f, .max=2.0f, .len=3, .data=lw->colour }, + dir = { .min=-VG_PIf, .max=VG_PIf, .len=2, .data=lw->dir }; - vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 1.0f, 0.0f, 0.0f }, 0xffff0000 ); - vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 0.0f, 1.0f, 0.0f }, 0xff00ff00 ); - vg_line( (v3f){ 0.0f, 0.0f, 0.0f }, (v3f){ 0.0f, 0.0f, 1.0f }, 0xff0000ff ); + ui_slider_vector( &ui_global_ctx, &colour ); + ui_global_ctx.cursor[1] += 4; + ui_slider_vector( &ui_global_ctx, &dir ); + } +} - v3f board_fwd = { -sinf( player_yaw ), 0.0f, cosf( player_yaw ) }; - v3f board_side = { -board_fwd[2], 0.0f, board_fwd[0] }; - v3f bnw, bne, bse, bsw; +static void run_debug_info(void) +{ + char buf[40]; - v3_muladds( player_pos, board_fwd, 0.75f, bnw ); - v3_muladds( player_pos, board_fwd, -0.75f, bsw ); - v3_muladds( bnw, board_side, 0.1f, bne ); - v3_muladds( bnw, board_side, -0.1f, bnw ); - v3_muladds( bsw, board_side, 0.1f, bse ); - v3_muladds( bsw, board_side, -0.1f, bsw ); - - vg_line( bnw, bne, 0xff00ff00 ); - vg_line( bne, bse, 0xff00ff00 ); - vg_line( bse, bsw, 0xff00ff00 ); - vg_line( bsw, bnw, 0xff00ff00 ); - - glEnable( GL_DEPTH_TEST ); - - v3f leg_dr, leg_dl, leg_ar, leg_al; + snprintf( buf, 40, "%.2fm/s", v3_length( player.rb.v ) ); + gui_text( (ui_px [2]){ 0, 0 }, buf, 1, k_text_align_left ); + + snprintf( buf, 40, "%.2f %.2f %.2f m/s", + player.a[0], player.a[1], player.a[2] ); + gui_text( (ui_px [2]){ 0, 20 }, buf, 1, k_text_align_left ); - v3_sub( foot_l, butt, leg_dl ); - v3_sub( foot_r, butt, leg_dr ); - leg_dl[1] = 0.0f; - leg_dr[1] = 0.0f; - v3_normalize( leg_dl ); - v3_normalize( leg_dr ); + snprintf( buf, 40, "pos %.2f %.2f %.2f", + player.rb.co[0], player.rb.co[1], player.rb.co[2] ); + gui_text( (ui_px [2]){ 0, 40 }, buf, 1, k_text_align_left ); - v3f v0; - v3_sub( butt, knee_l, v0 ); - float leg_pl = atan2f( v0[1], v3_dot( v0, leg_dl ) ); + if( vg_gamepad_ready ) + { + for( int i=0; i<6; i++ ) + { + snprintf( buf, 40, "%.2f", vg_gamepad.axes[i] ); + gui_text( (ui_px [2]){ 0, (i+3)*20 }, buf, 1, k_text_align_left ); + } + } + else + { + gui_text( (ui_px [2]){ 0, 60 }, + "Gamepad not ready", 1, k_text_align_left ); + } +} - v3_sub( knee_l, foot_l, v0 ); - float knee_pl = atan2f( v0[1], v3_dot( v0, leg_dl ) ); +void vg_ui(void) +{ + if( lightedit ) + { + ui_global_ctx.cursor[0] = 10; + ui_global_ctx.cursor[1] = 10; + ui_global_ctx.cursor[2] = 200; + ui_global_ctx.cursor[3] = 20; - float leg_yl = -atan2f( leg_dl[2], leg_dl[0] ), - leg_yr = atan2f( leg_dr[2], leg_dr[0] ); + struct ub_world_lighting *wl = &gpipeline.ub_world_lighting; + struct ui_slider_vector + s5 = { .min=0.0f, .max=2.0f, .len=3, .data=wl->g_ambient_colour }; - SHADER_USE( shader_debug_vcol ); - m4x3f temp; - m4x4f temp1; + struct ui_slider + s8 = { .min=0.0f, .max=2.0f, .data = &gpipeline.shadow_spread }, + s9 = { .min=0.0f, .max=25.0f, .data = &gpipeline.shadow_length }; - vg_tex2d_bind( &tex_grid, 0 ); - scene_tree_sway = 0.0f; + for( int i=0; i<3; i++ ) + run_light_widget( &gpipeline.widgets[i] ); - vg_line( head, butt, 0xff0000ff ); - vg_line( butt, knee_l, 0xff0000ff ); - vg_line( butt, knee_r, 0xff0000ff ); - vg_line( foot_l, knee_l, 0xff00a0ff ); - vg_line( foot_r, knee_r, 0xff00a0ff ); - vg_line( head, shoulder_r, 0xa0ff00ff ); - vg_line( shoulder_r, hand_r, 0xffff00ff ); - m4x3_identity( temp ); + gui_text( ui_global_ctx.cursor, "Ambient", 1, 0 ); + ui_global_ctx.cursor[1] += 16; + ui_slider_vector( &ui_global_ctx, &s5 ); - m4x3_translate( temp, knee_l ); - m4x3_rotate_x( temp, knee_pl ); - m4x3_rotate_y( temp, leg_yl ); + gui_text( ui_global_ctx.cursor, "Shadows", 1, 0 ); + ui_global_ctx.cursor[1] += 16; + ui_slider( &ui_global_ctx, &s8 ); + ui_slider( &ui_global_ctx, &s9 ); - m4x3_expand( temp, temp1 ); - glUniformMatrix4fv( SHADER_UNIFORM( shader_debug_vcol, "uMdl" ), - 1, GL_FALSE, (float *)temp1 ); + gui_text( ui_global_ctx.cursor, "Misc", 1, 0 ); + ui_global_ctx.cursor[1] += 16; + struct ui_checkbox c1 = {.data = &wl->g_light_preview}; + ui_checkbox( &ui_global_ctx, &c1 ); - scene_draw( &player_scene, -1, 0 ); + render_update_lighting_ub(); + } - m4x3_identity( temp ); - m4x3_expand( temp, temp1 ); - glUniformMatrix4fv( SHADER_UNIFORM( shader_debug_vcol, "uMdl" ), - 1, GL_FALSE, (float *)temp1 ); + //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); + if( cl_ui ) + { + render_world_routes_ui(); + } + //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); - vg_tex2d_bind( &tex_norwey, 0 ); - scene_tree_sway = 0.1f; - scene_draw( &test_scene, -1, 0 ); +#if 0 + static double last_b_press = 0.0; - vg_tex2d_bind( &tex_grid, 0 ); - scene_tree_sway = 0.0f; - scene_draw( &world_scene, world_terrain_count, 0 ); + double localtime = vg_time - last_b_press; - vg_tex2d_bind( &tex_road, 0 ); - scene_draw( &world_scene, world_road_count, world_terrain_count ); + world_routes_ui_updatetime( 0, localtime ); + world_routes_ui_draw( 0, (v4f){ 1.0f,0.0f,1.0f,1.0f}, 9.0f ); - glDisable( GL_DEPTH_TEST ); -} + if( glfwGetKey(vg_window,GLFW_KEY_B) ) + world_routes_ui_notch( 0, localtime ); -void vg_ui(void) -{ - char buf[20]; + if( vg_time-last_b_press > 1.0 ) + if( glfwGetKey(vg_window,GLFW_KEY_N) ) + { + last_b_press = vg_time; + world_routes_ui_newseg( 0 ); + } - snprintf( buf, 20, "%.2fm/s", v3_length( player_vel ) ); - gui_text( (ui_px [2]){ 0, 0 }, buf, 1, k_text_align_left ); - - snprintf( buf, 20, "%.2f %.2f %.2f m/s", - player_accel[0], player_accel[1], player_accel[2] ); + static double last_m_press; + if( vg_time-last_m_press > 1.0 ) + if( glfwGetKey( vg_window, GLFW_KEY_M) ) + { + last_m_press = vg_time; - gui_text( (ui_px [2]){ 0, 20 }, buf, 1, k_text_align_left ); + vg_info( "start: %u\n",world.routes.routes[0].ui.segment_count ); + for( int i=0; i