k_audio_sprite_type_water
};
-/*
- * Trace out a random point, near the player to try and determine water areas
- */
-VG_STATIC enum audio_sprite_type audio_sample_sprite_random( v3f origin,
- v3f output )
-{
- v3f chance = { (vg_randf()-0.5f) * 30.0f,
- 8.0f,
- (vg_randf()-0.5f) * 30.0f };
-
- v3f pos;
- v3_add( chance, origin, pos );
-
- ray_hit contact;
- contact.dist = vg_minf( 16.0f, pos[1] );
-
- world_instance *world = get_active_world();
-
- if( ray_world( world, pos, (v3f){0.0f,-1.0f,0.0f}, &contact ) ){
- struct world_surface *mat = ray_hit_surface( world, &contact );
-
- if( mat->info.surface_prop == k_surface_prop_grass){
- v3_copy( contact.pos, output );
- return k_audio_sprite_type_grass;
- }
- else{
-#if 0
- vg_line( pos, contact.pos, 0xff0000ff );
- vg_line_pt3( contact.pos, 0.3f, 0xff0000ff );
-#endif
- return k_audio_sprite_type_none;
- }
- }
-
- output[0] = pos[0];
- output[1] = 0.0f;
- output[2] = pos[2];
-
- float dist = fabsf(output[1] - origin[1]);
-
- if( world->water.enabled && dist<=40.0f )
- return k_audio_sprite_type_water;
- else
- return k_audio_sprite_type_none;
-}
-
VG_STATIC void audio_ambient_sprite_play( v3f co, audio_clip *clip )
{
audio_lock();
v3f sprite_pos;
enum audio_sprite_type sprite_type =
- audio_sample_sprite_random( co, sprite_pos );
+ world_audio_sample_sprite_random( co, sprite_pos );
if( sprite_type != k_audio_sprite_type_none ){
if( sprite_type == k_audio_sprite_type_grass ){
#define VG_TIMESTEP_FIXED (1.0/60.0)
#define VG_3D
#define VG_GAME
-//#define VG_STATIC static
-#define VG_STATIC
-#define VG_FRAMEBUFFER_RESIZE 1
-#include "vg/vg.h"
-#include "submodules/anyascii/impl/c/anyascii.c"
-
-enum menu_controller_type{
- k_menu_controller_type_keyboard,
- k_menu_controller_type_xbox,
- k_menu_controller_type_playstation,
- k_menu_controller_type_steam,
- k_menu_controller_type_steam_deck
-};
-
-VG_STATIC enum menu_controller_type menu_display_controller;
+#include "vg/vg.h"
#endif /* COMMON_H */
VG_STATIC int menu_controller( struct menu_btn_userdata ud )
{
if( (game_menu.page & (k_menu_page_main|k_menu_page_settings))
- && (ud.i == menu_display_controller) )
+ && (ud.i == steam_display_controller) )
return 1;
return 0;
}
VG_STATIC int menu_controller_inf( struct menu_btn_userdata ud )
{
if( (game_menu.page & k_menu_page_settings)
- && (ud.i == menu_display_controller) )
+ && (ud.i == steam_display_controller) )
return 1;
return 0;
}
{
"res_info", menu_vis, {k_menu_page_settings},
},
-{ "ctr_xbox", menu_controller_inf, {k_menu_controller_type_xbox}},
-{ "ctr_xbox_text", menu_controller_inf, {k_menu_controller_type_xbox}},
-{ "ctr_steam", menu_controller_inf, {k_menu_controller_type_steam}},
-{ "ctr_steam_text", menu_controller_inf, {k_menu_controller_type_steam}},
-{ "ctr_deck", menu_controller_inf, {k_menu_controller_type_steam_deck}},
-{ "ctr_deck_text", menu_controller_inf, {k_menu_controller_type_steam_deck}},
-{ "ctr_ps", menu_controller_inf, {k_menu_controller_type_playstation}},
-{ "ctr_ps_text", menu_controller_inf, {k_menu_controller_type_playstation}},
-{ "ctr_kbm", menu_controller_inf, {k_menu_controller_type_keyboard}},
-{ "ctr_kbm_text", menu_controller_inf, {k_menu_controller_type_keyboard}},
+{ "ctr_xbox", menu_controller_inf, {k_steam_controller_type_xbox}},
+{ "ctr_xbox_text", menu_controller_inf, {k_steam_controller_type_xbox}},
+{ "ctr_steam", menu_controller_inf, {k_steam_controller_type_steam}},
+{ "ctr_steam_text", menu_controller_inf, {k_steam_controller_type_steam}},
+{ "ctr_deck", menu_controller_inf, {k_steam_controller_type_steam_deck}},
+{ "ctr_deck_text", menu_controller_inf, {k_steam_controller_type_steam_deck}},
+{ "ctr_ps", menu_controller_inf, {k_steam_controller_type_playstation}},
+{ "ctr_ps_text", menu_controller_inf, {k_steam_controller_type_playstation}},
+{ "ctr_kbm", menu_controller_inf, {k_steam_controller_type_keyboard}},
+{ "ctr_kbm_text", menu_controller_inf, {k_steam_controller_type_keyboard}},
{
"text_paused", menu_vis, {k_menu_page_main}
},
return 0;
}
-VG_STATIC int __respawn( int argc, const char *argv[] );
VG_STATIC void menu_btn_reset( int event )
{
- __respawn(0,NULL);
+ localplayer_cmd_respawn( 0, NULL );
cl_menu_go_away = 1;
game_menu.page = 0;
}
}
}
-player_instance *tmp_localplayer(void);
-
VG_STATIC void menu_update(void)
{
vg_input_update( 1, &input_menu_h );
/* Base */
{
- player_instance *player = tmp_localplayer();
+ player_instance *player = &localplayer;
struct player_avatar *av = player->playeravatar;
v3f center_rough;
#include "camera.h"
#include "player_model.h"
+VG_STATIC int localplayer_cmd_respawn( int argc, const char *argv[] )
+{
+ ent_spawn *rp = NULL, *r;
+ world_instance *world = localplayer.viewable_world;
+
+ if( argc == 1 ){
+ rp = world_find_spawn_by_name( world, argv[0] );
+ }
+ else if( argc == 0 ){
+ rp = world_find_closest_spawn( world, localplayer.rb.co );
+ }
+
+ if( !rp )
+ return 0;
+
+ player__spawn( &localplayer, rp );
+ return 1;
+}
+
+VG_STATIC void player_init(void)
+{
+ for( u32 i=0; i<vg_list_size(_player_system_register); i++ ){
+ if( _player_system_register[i] )
+ _player_system_register[i]();
+ }
+
+ vg_console_reg_cmd( "respawn", localplayer_cmd_respawn, NULL );
+}
+
PLAYER_API
void player__debugtext( int size, const char *fmt, ... )
{
}
else{
if( player->subsystem == k_player_subsystem_dead ){
- __respawn( 0, NULL );
+ localplayer_cmd_respawn( 0, NULL );
}
else{
/* cant do that */
shader_model_character_view_uTexMain( 0 );
shader_model_character_view_uCamera( cam->transform[3] );
shader_model_character_view_uPv( cam->mtx.pv );
+ shader_model_character_view_uTexSceneDepth( 1 );
+ render_fb_bind_texture( gpipeline.fb_main, 2, 1 );
+ v3f inverse;
+ render_fb_inverse_ratio( gpipeline.fb_main, inverse );
+ inverse[2] = main_camera.farz-main_camera.nearz;
+
+ shader_model_character_view_uInverseRatioDepth( inverse );
+ render_fb_inverse_ratio( NULL, inverse );
+ inverse[2] = cam->farz-cam->nearz;
+ shader_model_character_view_uInverseRatioMain( inverse );
world_instance *world = get_active_world();
world_link_lighting_ub( world, _shader_model_character_view.id );
m3x3_identity( player->invbasis );
player->subsystem = k_player_subsystem_walk;
- player->viewable_world = get_active_world();
player->gate_waiting = NULL;
if( _player_reset[ player->subsystem ] )
struct player_walk _walk;
struct player_dead _dead;
struct player_drive _drive;
-};
+}
+static localplayer;
/*
* Gameloop tables
NULL
};
-VG_STATIC void player_init(void)
-{
- for( u32 i=0; i<vg_list_size(_player_system_register); i++ ){
- if( _player_system_register[i] )
- _player_system_register[i]();
- }
-}
-
/* implementation */
#include "player.c"
manifold_len += l;
- debug_capsule( mtx, capsule.radius, capsule.height, VG__WHITE );
+ if( vg_lines.draw )
+ debug_capsule( mtx, capsule.radius, capsule.height, VG__WHITE );
/* add limits */
if( s->state.activity >= k_skate_activity_grind_any ){
.attachment = GL_COLOR_ATTACHMENT1
},
{
+#if 0
"depth_stencil", k_framebuffer_attachment_type_renderbuffer,
.internalformat = GL_DEPTH24_STENCIL8,
+#else
+ "depth_stencil", k_framebuffer_attachment_type_colour,
+ .internalformat = GL_DEPTH24_STENCIL8,
+ .format = GL_DEPTH_STENCIL,
+ .type = GL_UNSIGNED_INT_24_8,
+#endif
.attachment = GL_DEPTH_STENCIL_ATTACHMENT
}
}
VG_STATIC void render_fb_inverse_ratio( framebuffer *fb, v2f inverse )
{
- int x, y;
- render_fb_get_current_res( fb, &x, &y );
+ if( fb ){
+ int x, y;
+ render_fb_get_current_res( fb, &x, &y );
- v2f render = { fb->render_w, fb->render_h },
- original = { x, y };
+ v2f render = { fb->render_w, fb->render_h },
+ original = { x, y };
- v2_div( render, original, inverse );
+ v2_div( render, original, inverse );
+ }
+ else{
+ v2_div( (v2f){1.0f,1.0f}, (v2f){ vg.window_x, vg.window_y }, inverse );
+ }
}
/*
if( a->purpose == k_framebuffer_attachment_type_renderbuffer ){
glBindRenderbuffer( GL_RENDERBUFFER, a->id );
- glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, rx, ry );
+ glRenderbufferStorage( GL_RENDERBUFFER, a->internalformat, rx, ry );
}
else if( a->purpose == k_framebuffer_attachment_type_colour ){
glBindTexture( GL_TEXTURE_2D, a->id );
uniform sampler2D uTexMain;
+uniform sampler2D uTexSceneDepth;
uniform vec3 uCamera;
+uniform vec3 uInverseRatioDepth;
+uniform vec3 uInverseRatioMain;
in vec4 aColour;
in vec2 aUv;
#include "common_world.glsl"
#include "motion_vectors_fs.glsl"
+float linear_depth( float depth, float near, float far )
+{
+ float z = depth * 2.0 - 1.0;
+ return (2.0 * near * far) / (far + near - z * (far - near));
+}
+
void main()
{
compute_motion_vectors();
float dist = distance( aWorldCo, uCamera ) - 0.08;
float opacity = clamp( dist*dist, 0.0, 1.0 );
+ vec2 back_coord = gl_FragCoord.xy*uInverseRatioMain.xy*uInverseRatioDepth.xy;
+ float back_depth = texture( uTexSceneDepth, back_coord ).r;
+ float front_depth = gl_FragCoord.z/gl_FragCoord.w;
+
+ back_depth = linear_depth( back_depth, 0.1, 2100.0 );
+ float diff = back_depth - front_depth;
+
+ vec2 ssuv = gl_FragCoord.xy;
+ vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );
+ float dither = fract( vDither.g / 71.0 ) - 0.5;
+
+ if( step(0.0,diff)+dither<0.3 )
+ discard;
+
oColour = vec4( composite, opacity );
}
.orig_file = "shaders/model_character_view.fs",
.static_src =
"uniform sampler2D uTexMain;\n"
+"uniform sampler2D uTexSceneDepth;\n"
"uniform vec3 uCamera;\n"
+"uniform vec3 uInverseRatioDepth;\n"
+"uniform vec3 uInverseRatioMain;\n"
"\n"
"in vec4 aColour;\n"
"in vec2 aUv;\n"
" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
"}\n"
"\n"
-"#line 11 0 \n"
+"#line 14 0 \n"
"#line 1 2 \n"
"const float k_motion_lerp_amount = 0.01;\n"
"\n"
" oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
"}\n"
"\n"
-"#line 12 0 \n"
+"#line 15 0 \n"
+"\n"
+"float linear_depth( float depth, float near, float far ) \n"
+"{\n"
+" float z = depth * 2.0 - 1.0;\n"
+" return (2.0 * near * far) / (far + near - z * (far - near)); \n"
+"}\n"
"\n"
"void main()\n"
"{\n"
" float dist = distance( aWorldCo, uCamera ) - 0.08;\n"
" float opacity = clamp( dist*dist, 0.0, 1.0 );\n"
"\n"
+" vec2 back_coord = gl_FragCoord.xy*uInverseRatioMain.xy*uInverseRatioDepth.xy;\n"
+" float back_depth = texture( uTexSceneDepth, back_coord ).r;\n"
+" float front_depth = gl_FragCoord.z/gl_FragCoord.w;\n"
+"\n"
+" back_depth = linear_depth( back_depth, 0.1, 2100.0 );\n"
+" float diff = back_depth - front_depth;\n"
+"\n"
+" vec2 ssuv = gl_FragCoord.xy;\n"
+" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
+" float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
+"\n"
+" if( step(0.0,diff)+dither<0.3 )\n"
+" discard;\n"
+"\n"
" oColour = vec4( composite, opacity );\n"
+" //oColour = vec4( vec3(back_depth), 1.0 );\n"
"}\n"
""},
};
static GLuint _uniform_model_character_view_uPv;
static GLuint _uniform_model_character_view_uTransforms;
static GLuint _uniform_model_character_view_uTexMain;
+static GLuint _uniform_model_character_view_uTexSceneDepth;
static GLuint _uniform_model_character_view_uCamera;
+static GLuint _uniform_model_character_view_uInverseRatioDepth;
+static GLuint _uniform_model_character_view_uInverseRatioMain;
static GLuint _uniform_model_character_view_g_world_depth;
static GLuint _uniform_model_character_view_uLightsArray;
static GLuint _uniform_model_character_view_uLightsIndex;
static void shader_model_character_view_uTexMain(int i){
glUniform1i(_uniform_model_character_view_uTexMain,i);
}
+static void shader_model_character_view_uTexSceneDepth(int i){
+ glUniform1i(_uniform_model_character_view_uTexSceneDepth,i);
+}
static void shader_model_character_view_uCamera(v3f v){
glUniform3fv(_uniform_model_character_view_uCamera,1,v);
}
+static void shader_model_character_view_uInverseRatioDepth(v3f v){
+ glUniform3fv(_uniform_model_character_view_uInverseRatioDepth,1,v);
+}
+static void shader_model_character_view_uInverseRatioMain(v3f v){
+ glUniform3fv(_uniform_model_character_view_uInverseRatioMain,1,v);
+}
static void shader_model_character_view_g_world_depth(int i){
glUniform1i(_uniform_model_character_view_g_world_depth,i);
}
_uniform_model_character_view_uPv = glGetUniformLocation( _shader_model_character_view.id, "uPv" );
_uniform_model_character_view_uTransforms = glGetUniformLocation( _shader_model_character_view.id, "uTransforms" );
_uniform_model_character_view_uTexMain = glGetUniformLocation( _shader_model_character_view.id, "uTexMain" );
+ _uniform_model_character_view_uTexSceneDepth = glGetUniformLocation( _shader_model_character_view.id, "uTexSceneDepth" );
_uniform_model_character_view_uCamera = glGetUniformLocation( _shader_model_character_view.id, "uCamera" );
+ _uniform_model_character_view_uInverseRatioDepth = glGetUniformLocation( _shader_model_character_view.id, "uInverseRatioDepth" );
+ _uniform_model_character_view_uInverseRatioMain = glGetUniformLocation( _shader_model_character_view.id, "uInverseRatioMain" );
_uniform_model_character_view_g_world_depth = glGetUniformLocation( _shader_model_character_view.id, "g_world_depth" );
_uniform_model_character_view_uLightsArray = glGetUniformLocation( _shader_model_character_view.id, "uLightsArray" );
_uniform_model_character_view_uLightsIndex = glGetUniformLocation( _shader_model_character_view.id, "uLightsIndex" );
}
// Lighting
- vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );
- oColour = vec4(vfrag, 1.0);
+ oColour = vec4( scene_compute_lighting( vfrag, qnorm, aWorldCo ), 1.0 );
}
" }\n"
"\n"
" // Lighting\n"
-" vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
-" oColour = vec4(vfrag, 1.0);\n"
+" oColour = vec4( scene_compute_lighting( vfrag, qnorm, aWorldCo ), 1.0 );\n"
"}\n"
""},
};
#include "font.h"
#include "player.h"
-static player_instance localplayer;
VG_STATIC struct player_avatar localplayer_avatar;
VG_STATIC glmesh localplayer_meshes[3];
vg_tex2d localplayer_texture = { .path = "textures/ch_gradient.qoi" };
-player_instance *tmp_localplayer(void)
-{
- return &localplayer;
-}
-
#include "network.h"
#include "menu.h"
#include "vehicle.h"
VG_STATIC void vg_launch_opt(void)
{
-
-}
-
-VG_STATIC int __kill( int argc, const char *argv[] )
-{
-#if 0
- player_use_device( &localplayer, &player_device_dead, &localplayer_dead );
-#endif
- return 0;
-}
-
-VG_STATIC int __respawn( int argc, const char *argv[] )
-{
- ent_spawn *rp = NULL, *r;
- world_instance *world = get_active_world();
-
- if( argc == 1 ){
- for( u32 i=0; i<mdl_arrcount(&world->ent_spawn); i++ ){
- r = mdl_arritm( &world->ent_spawn, i );
- if( !strcmp( mdl_pstr(&world->meta, r->pstr_name),argv[0] ) ){
- rp = r;
- break;
- }
- }
-
- if( !rp )
- vg_warn( "No spawn named '%s'\n", argv[0] );
- }
-
- if( !rp ){
- float min_dist = INFINITY;
-
- for( u32 i=0; i<mdl_arrcount(&world->ent_spawn); i++ ){
- r = mdl_arritm( &world->ent_spawn, i );
- float d = v3_dist2( r->transform.co, localplayer.rb.co );
-
- if( d < min_dist ){
- min_dist = d;
- rp = r;
- }
- }
- }
-
- if( !rp ){
- vg_error( "No spawn found\n" );
-
- if( !mdl_arrcount(&world->ent_spawn) )
- return 0;
-
- rp = mdl_arritm( &world->ent_spawn, 0 );
- }
-
- player__spawn( &localplayer, rp );
- return 1;
}
VG_STATIC void vg_preload(void)
{
g_conf_init();
- vg_console_reg_cmd( "respawn", __respawn, NULL );
- vg_console_reg_cmd( "ded", __kill, NULL );
-
vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" );
-vg_info(" 2021-2022 |\\ /| | / | | | | /| \n" );
+vg_info(" 2021-2023 |\\ /| | / | | | | /| \n" );
vg_info(" | \\ / | +-- / +----- +---' | / | \n" );
vg_info(" | \\ / | | / | | \\ | / | \n" );
vg_info(" | \\/ | | / | | \\ | / | \n" );
/* 'systems' are completely loaded now */
/* load home world */
- world_load( &world_global.worlds[0], "maps/mp_gridmap.mdl" );
- //world_load( &world_global.worlds[0], "maps/mp_mtzero.mdl" );
+ //world_load( &world_global.worlds[0], "maps/mp_gridmap.mdl" );
+ world_load( &world_global.worlds[0], "maps/mp_mtzero.mdl" );
#if 0
world_load( &world_global.worlds[1], "maps/mp_gridmap.mdl" );
VG_STATIC void vg_start(void)
{
- __respawn( 1, (const char *[]){ "start" } );
+ localplayer.viewable_world = get_active_world();
+ localplayer_cmd_respawn( 1, (const char *[]){ "start" } );
}
VG_STATIC void draw_origin_axis(void)
{
if( vg.is_loaded ){
player__post_update( &localplayer );
-
- float inr3 = 0.57735027,
- inr2 = 0.70710678118;
-
- v3f sample_directions[] = {
- { -1.0f, 0.0f, 0.0f },
- { 1.0f, 0.0f, 0.0f },
- { 0.0f, 0.0f, 1.0f },
- { 0.0f, 0.0f, -1.0f },
- { 0.0f, 1.0f, 0.0f },
- { 0.0f, -1.0f, 0.0f },
- { -inr3, inr3, inr3 },
- { inr3, inr3, inr3 },
- { -inr3, inr3, -inr3 },
- { inr3, inr3, -inr3 },
- { -inr2, 0.0f, inr2 },
- { inr2, 0.0f, inr2 },
- { -inr2, 0.0f, -inr2 },
- { inr2, 0.0f, -inr2 },
- };
-
- static int si = 0;
- static float distances[16];
-
- ray_hit ray;
- ray.dist = 5.0f;
-
- v3f rc, rd, ro;
- v3_copy( sample_directions[ si ], rd );
- v3_add( localplayer.rb.co, (v3f){0.0f,1.5f,0.0f}, ro );
- v3_copy( ro, rc );
-
- float dist = 200.0f;
-
- for( int i=0; i<10; i++ ){
- if( ray_world( get_active_world(), rc, rd, &ray ) ){
- dist = (float)i*5.0f + ray.dist;
- break;
- }
- else{
- v3_muladds( rc, rd, ray.dist, rc );
- }
- }
-
- distances[si] = dist;
-
-
- for( int i=0; i<14; i++ ){
- if( distances[i] != 200.0f ){
- u32 colours[] = { VG__RED, VG__BLUE, VG__GREEN,
- VG__CYAN, VG__YELOW, VG__PINK,
- VG__WHITE };
- u32 colour = colours[i%7];
+ float dist;
+ int sample_index;
+ world_audio_sample_distances( localplayer.rb.co, &sample_index, &dist );
- v3f p1;
- v3_muladds( ro, sample_directions[i], distances[i], p1 );
- vg_line( ro, p1, colour );
- vg_line_pt3( p1, 0.1f, colour );
- }
- }
-
- si ++;
- if( si >= 14 )
- si = 0;
-
- /* FIXME: TEMP */
audio_lock();
- vg_dsp.echo_distances[si] = dist;
+ vg_dsp.echo_distances[sample_index] = dist;
v3f ears = { 1.0f,0.0f,0.0f };
m3x3_mulv( main_camera.transform, ears, ears );
v3_copy( ears, vg_audio.external_listener_ears );
v3_copy( main_camera.transform[3], vg_audio.external_listener_pos );
- /* TODO: this is transformed back and fourth twice. */
if( localplayer.gate_waiting ){
m4x3_mulv( localplayer.gate_waiting->transport,
vg_audio.external_listener_pos,
render_water_texture( view_world, &main_camera, 0 );
render_fb_bind( gpipeline.fb_main, 1 );
render_water_surface( view_world, &main_camera );
+}
+
+VG_STATIC void render_scene_gate_subview(void)
+{
+ render_fb_bind( gpipeline.fb_main, 1 );
+ world_instance *view_world = localplayer.viewable_world;
int depth = 1;
if( localplayer.gate_waiting ) depth = 0;
render_world_gates( view_world, &main_camera, depth );
-
- if( !cl_menu )
- render_player_transparent();
}
VG_STATIC void render_main_game(void)
render_scene();
if( cl_menu ) {
- glClear( GL_DEPTH_BUFFER_BIT );
+ //glClear( GL_DEPTH_BUFFER_BIT );
menu_render_bg();
glEnable( GL_DEPTH_TEST );
- render_player_transparent();
}
+ render_player_transparent();
+ render_scene_gate_subview();
+
present_view_with_post_processing();
if( cl_menu )
/*
- * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
+ * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved
* All trademarks are property of their respective owners
*/
#include "vg/vg_steam_http.h"
#include "vg/vg_steam_friends.h"
#include "vg/vg_steam_user_stats.h"
+#include "submodules/anyascii/impl/c/anyascii.c"
+
+enum steam_controller_type{
+ k_steam_controller_type_keyboard,
+ k_steam_controller_type_xbox,
+ k_steam_controller_type_playstation,
+ k_steam_controller_type_steam,
+ k_steam_controller_type_steam_deck
+};
+
+VG_STATIC enum steam_controller_type steam_display_controller;
/*
* We only want to use steamworks if building for the networked version,
if( type == k_ESteamInputType_SteamController ){
vg_input.controller_should_use_trackpad_look = 1;
- menu_display_controller = k_menu_controller_type_steam;
+ steam_display_controller = k_steam_controller_type_steam;
}
else if( type == k_ESteamInputType_SteamDeckController ){
- menu_display_controller = k_menu_controller_type_steam_deck;
+ steam_display_controller = k_steam_controller_type_steam_deck;
}
else if( type == k_ESteamInputType_PS3Controller ||
type == k_ESteamInputType_PS4Controller ||
type == k_ESteamInputType_PS5Controller )
{
- menu_display_controller = k_menu_controller_type_playstation;
+ steam_display_controller = k_steam_controller_type_playstation;
}
else if( type == k_ESteamInputType_XBox360Controller ||
type == k_ESteamInputType_XBoxOneController )
{
- menu_display_controller = k_menu_controller_type_xbox;
+ steam_display_controller = k_steam_controller_type_xbox;
}
else{
/* currently unsupported controller */
- menu_display_controller = k_menu_controller_type_xbox;
+ steam_display_controller = k_steam_controller_type_xbox;
}
}
else
- menu_display_controller = k_menu_controller_type_keyboard;
+ steam_display_controller = k_steam_controller_type_keyboard;
}
}
}
}
}
-player_instance *tmp_localplayer(void);
VG_STATIC void vehicle_update_fixed(void)
{
if( !gzoomer.alive )
VG_STATIC
int ray_world( world_instance *world, v3f pos, v3f dir, ray_hit *hit );
+VG_STATIC
+ent_spawn *world_find_closest_spawn( world_instance *world, v3f position )
+{
+ ent_spawn *rp = NULL, *r;
+ float min_dist = INFINITY;
+
+ for( u32 i=0; i<mdl_arrcount(&world->ent_spawn); i++ ){
+ r = mdl_arritm( &world->ent_spawn, i );
+ float d = v3_dist2( r->transform.co, position );
+
+ if( d < min_dist ){
+ min_dist = d;
+ rp = r;
+ }
+ }
+
+ if( !rp ){
+ if( mdl_arrcount(&world->ent_spawn) ){
+ vg_warn( "Invalid distances to spawns.. defaulting to first one.\n" );
+ return mdl_arritm( &world->ent_spawn, 0 );
+ }
+ else{
+ vg_error( "There are no spawns in the level!\n" );
+ }
+ }
+
+ return rp;
+}
+
+VG_STATIC
+ent_spawn *world_find_spawn_by_name( world_instance *world, const char *name )
+{
+ ent_spawn *rp = NULL, *r;
+ for( u32 i=0; i<mdl_arrcount(&world->ent_spawn); i++ ){
+ r = mdl_arritm( &world->ent_spawn, i );
+ if( !strcmp( mdl_pstr(&world->meta, r->pstr_name), name ) ){
+ rp = r;
+ break;
+ }
+ }
+
+ if( !rp )
+ vg_warn( "No spawn named '%s'\n", name );
+
+ return rp;
+}
+
/*
* Submodules
*/
}
#endif
-
-#if 0
-
- /* process soundscape transactions */
- audio_lock();
- for( int i=0; i<world->soundscape_count; i++ )
- {
- struct soundscape *s = &world->soundscapes[i];
- s->usage_count = 0;
-
- for( int j=0; j<s->max_instances; j++ )
- {
- if( s->channels[j] )
- {
- if( audio_channel_finished(s->channels[j]) )
- s->channels[j] = audio_relinquish_channel( s->channels[j] );
- else
- s->usage_count ++;
- }
- }
- }
- audio_unlock();
-#endif
}
/*
return world_tri_index_surface( world, hit->tri[0] );
}
+/*
+ * -----------------------------------------------------------------------------
+ * Audio sampling
+ * -----------------------------------------------------------------------------
+ */
+
+VG_STATIC
+enum audio_sprite_type world_audio_sample_sprite_random(v3f origin, v3f output);
+VG_STATIC void world_audio_sample_distances( v3f co, int *index, float *value );
+
+#include "audio.h"
+
+/*
+ * Trace out a random point, near the player to try and determine water areas
+ */
+VG_STATIC
+enum audio_sprite_type world_audio_sample_sprite_random(v3f origin, v3f output)
+{
+ v3f chance = { (vg_randf()-0.5f) * 30.0f,
+ 8.0f,
+ (vg_randf()-0.5f) * 30.0f };
+
+ v3f pos;
+ v3_add( chance, origin, pos );
+
+ ray_hit contact;
+ contact.dist = vg_minf( 16.0f, pos[1] );
+
+ world_instance *world = get_active_world();
+
+ if( ray_world( world, pos, (v3f){0.0f,-1.0f,0.0f}, &contact ) ){
+ struct world_surface *mat = ray_hit_surface( world, &contact );
+
+ if( mat->info.surface_prop == k_surface_prop_grass){
+ v3_copy( contact.pos, output );
+ return k_audio_sprite_type_grass;
+ }
+ else{
+ return k_audio_sprite_type_none;
+ }
+ }
+
+ output[0] = pos[0];
+ output[1] = 0.0f;
+ output[2] = pos[2];
+
+ float dist = fabsf(output[1] - origin[1]);
+
+ if( world->water.enabled && dist<=40.0f )
+ return k_audio_sprite_type_water;
+ else
+ return k_audio_sprite_type_none;
+}
+
+VG_STATIC void world_audio_sample_distances( v3f co, int *index, float *value )
+{
+ float inr3 = 0.57735027,
+ inr2 = 0.70710678118;
+
+ v3f sample_directions[] = {
+ { -1.0f, 0.0f, 0.0f },
+ { 1.0f, 0.0f, 0.0f },
+ { 0.0f, 0.0f, 1.0f },
+ { 0.0f, 0.0f, -1.0f },
+ { 0.0f, 1.0f, 0.0f },
+ { 0.0f, -1.0f, 0.0f },
+ { -inr3, inr3, inr3 },
+ { inr3, inr3, inr3 },
+ { -inr3, inr3, -inr3 },
+ { inr3, inr3, -inr3 },
+ { -inr2, 0.0f, inr2 },
+ { inr2, 0.0f, inr2 },
+ { -inr2, 0.0f, -inr2 },
+ { inr2, 0.0f, -inr2 },
+ };
+
+ static int si = 0;
+ static float distances[16];
+
+ ray_hit ray;
+ ray.dist = 5.0f;
+
+ v3f rc, rd, ro;
+ v3_copy( sample_directions[ si ], rd );
+ v3_add( co, (v3f){0.0f,1.5f,0.0f}, ro );
+ v3_copy( ro, rc );
+
+ float dist = 200.0f;
+
+ for( int i=0; i<10; i++ ){
+ if( ray_world( get_active_world(), rc, rd, &ray ) ){
+ dist = (float)i*5.0f + ray.dist;
+ break;
+ }
+ else{
+ v3_muladds( rc, rd, ray.dist, rc );
+ }
+ }
+
+ distances[si] = dist;
+
+ if( vg_lines.draw ){
+ for( int i=0; i<14; i++ ){
+ if( distances[i] != 200.0f ){
+ u32 colours[] = { VG__RED, VG__BLUE, VG__GREEN,
+ VG__CYAN, VG__YELOW, VG__PINK,
+ VG__WHITE };
+
+ u32 colour = colours[i%7];
+
+ v3f p1;
+ v3_muladds( ro, sample_directions[i], distances[i], p1 );
+ vg_line( ro, p1, colour );
+ vg_line_pt3( p1, 0.1f, colour );
+ }
+ }
+ }
+
+ *index = si;
+ *value = dist;
+
+ si ++;
+ if( si >= 14 )
+ si = 0;
+}
+
#endif /* WORLD_H */