volatile sig_atomic_t sig_stop;
#include "gameserver.h"
-#include "highscores.c"
#include "vg/vg_opt.h"
#include "network_common.h"
#include "gameserver_db.h"
basic->sound_effects = 0;
struct gameserver_client *c0 = &gameserver.clients[client_id];
- c0->instance = frame->instance_id;
+ c0->instance = frame->flags & NETMSG_PLAYERFRAME_INSTANCE_ID;
for( int i=0; i<vg_list_size(gameserver.clients); i++ ){
if( i == client_id )
#include "vg/vg_steam_auth.h"
#include "network_msg.h"
#include "network_common.h"
-#include "highscores.h"
#include <sys/socket.h>
#define CLIENT_KNOWLEDGE_SAME_WORLD0 0x1
#include "vg/vg_mem_queue.h"
#include "network_common.h"
#include "dep/sqlite3/sqlite3.h"
-#include "highscores.h"
#include <pthread.h>
#include <unistd.h>
#define NETMSG_BOUNDARY_BIT 0x8000
#define NETMSG_GATE_BOUNDARY_BIT 0x4000
#define NETMSG_BOUNDARY_MASK (NETMSG_BOUNDARY_BIT|NETMSG_GATE_BOUNDARY_BIT)
+#define NETMSG_PLAYERFRAME_INSTANCE_ID 0x3
+#define NETMSG_PLAYERFRAME_HAVE_GLIDER 0x4
+#define NETMSG_PLAYERFRAME_GLIDER_ORPHAN 0x8
typedef struct netmsg_playerframe netmsg_playerframe;
enum{ k_inetmsg_playerframe = 200 };
f64 timestamp;
u8 client, subsystem,
- instance_id, sound_effects;
+ flags, sound_effects;
u16 boundary_hash; /* used for animating correctly through gates, teleport..
msb is a flip flop for teleporting
second msb is flip flop for gate */
#include "vg/vg_rigidbody.h"
#include "scene_rigidbody.h"
#include "shaders/model_board_view.h"
+#include "shaders/model_entity.h"
static f32 k_glide_steer = 2.0f,
k_glide_cl = 0.04f,
bitpack_qquat( ctx, animator->root_q );
}
+static void
+player_glide_remote_animator_exchange( bitpack_ctx *ctx, void *data ){
+ struct remote_glider_animator *animator = data;
+
+ bitpack_qv3f( ctx, 24, -1024.0f, 1024.0f, animator->root_co );
+ bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->s );
+ bitpack_qquat( ctx, animator->root_q );
+}
+
static void player_glide_im_gui(void){
player__debugtext( 1, "Nothing here" );
player__debugtext( 1, " lift: %.2f %.2f %.2f",
player__begin_holdout( (v3f){0,0,0} );
}
+static void render_glider_model( camera *cam, world_instance *world,
+ m4x3f mmdl, enum board_shader shader ){
+ u32 current_tex = 0xffffffff;
+ glActiveTexture( GL_TEXTURE0 );
+
+ mdl_context *mdl = &player_glide.glider;
+ mesh_bind( &player_glide.glider_mesh );
+
+ for( u32 i=0; i<mdl_arrcount(&mdl->meshs); i ++ ){
+ mdl_mesh *mesh = mdl_arritm( &mdl->meshs, i );
+
+ m4x3f mmmdl;
+ mdl_transform_m4x3( &mesh->transform, mmmdl );
+ m4x3_mul( mmdl, mmmdl, mmmdl );
+
+ if( shader == k_board_shader_player )
+ shader_model_board_view_uMdl( mmmdl );
+ else if( shader == k_board_shader_entity ){
+ m4x4f m4mmmdl;
+ m4x3_expand( mmmdl, m4mmmdl );
+ m4x4_mul( cam->mtx_prev.pv, m4mmmdl, m4mmmdl );
+
+ shader_model_entity_uMdl( mmmdl );
+ shader_model_entity_uPvmPrev( m4mmmdl );
+ }
+
+ for( u32 j=0; j<mesh->submesh_count; j ++ ){
+ mdl_submesh *sm = mdl_arritm( &mdl->submeshs, mesh->submesh_start+j );
+ if( !sm->material_id ) {
+ vg_error( "Invalid material ID 0\n" );
+ continue;
+ }
+
+ mdl_material *mat = mdl_arritm( &mdl->materials, sm->material_id-1 );
+ if( mat->tex_diffuse != current_tex ){
+ glBindTexture( GL_TEXTURE_2D,
+ player_glide.glider_textures[ mat->tex_diffuse ] );
+ current_tex = mat->tex_diffuse;
+ }
+
+ mdl_draw_submesh( sm );
+ }
+ }
+}
+
/*
* TODO: more flexible way to call
* - this depends on the current state, but we need to pass a struct in
m3x3_scale( mmdl, kf_res.s );
v3_copy( kf_res.co, mmdl[3] );
- u32 current_tex = 0xffffffff;
- glActiveTexture( GL_TEXTURE0 );
-
- mdl_context *mdl = &player_glide.glider;
- mesh_bind( &player_glide.glider_mesh );
-
- for( u32 i=0; i<mdl_arrcount(&mdl->meshs); i ++ ){
- mdl_mesh *mesh = mdl_arritm( &mdl->meshs, i );
-
- m4x3f mmmdl;
- mdl_transform_m4x3( &mesh->transform, mmmdl );
- m4x3_mul( mmdl, mmmdl, mmmdl );
-
- shader_model_board_view_uMdl( mmmdl );
+ render_glider_model( cam, world, mmdl, k_board_shader_player );
- for( u32 j=0; j<mesh->submesh_count; j ++ ){
- mdl_submesh *sm = mdl_arritm( &mdl->submeshs, mesh->submesh_start+j );
- if( !sm->material_id ) {
- vg_error( "Invalid material ID 0\n" );
- continue;
- }
-
- mdl_material *mat = mdl_arritm( &mdl->materials, sm->material_id-1 );
- if( mat->tex_diffuse != current_tex ){
- glBindTexture( GL_TEXTURE_2D,
- player_glide.glider_textures[ mat->tex_diffuse ] );
- current_tex = mat->tex_diffuse;
- }
-
- mdl_draw_submesh( sm );
- }
- }
+ /* totally FUCKED */
+ v4_copy( kf_res.q, player_glide.remote_animator.root_q );
+ v3_copy( kf_res.co, player_glide.remote_animator.root_co );
+ player_glide.remote_animator.s = kf_res.s[0];
}
#endif /* PLAYER_GLIDE_C */
}
animator;
+ /* this sucks */
+ struct remote_glider_animator {
+ v3f root_co;
+ v4f root_q;
+ f32 s;
+ }
+ remote_animator;
+
v3f info_lift,
info_slip,
info_drag;
static void player_glide_transition(void);
static bool glider_physics( v2f steer );
static void player_glide_animator_exchange( bitpack_ctx *ctx, void *data );
+static void player_glide_render( camera *cam, world_instance *world,
+ player_pose *pose );
+static void render_glider_model( camera *cam, world_instance *world,
+ m4x3f mmdl, enum board_shader shader );
+static void
+player_glide_remote_animator_exchange( bitpack_ctx *ctx, void *data );
struct player_subsystem_interface static player_subsystem_glide = {
.pre_update = player_glide_pre_update,
#include "gui.h"
#include "ent_miniworld.h"
#include "ent_region.h"
+#include "shaders/model_entity.h"
static i32 k_show_own_name = 0;
dest->active = 1;
dest->subsystem = frame->subsystem;
- dest->instance_id = frame->instance_id;
+ dest->flags = frame->flags;
bitpack_ctx ctx = {
.mode = k_bitpack_decompress,
struct player_subsystem_interface *sys =
player_subsystems[ frame->subsystem ];
- if( sys->network_animator_exchange ){
- memset( &dest->data, 0, sys->animator_size );
+ memset( &dest->data, 0, sys->animator_size );
+ if( sys->network_animator_exchange )
sys->network_animator_exchange( &ctx, &dest->data );
- }
- else {
+ else
bitpack_bytes( &ctx, sys->animator_size, sys->animator_data );
- }
/* sfx
* -------------------------------------------------------------*/
}
}
+ /* glider
+ * -------------------------------------------------------------*/
+
+ memset( &dest->data_glider, 0, sizeof(struct remote_glider_animator) );
+ if( dest->flags & (NETMSG_PLAYERFRAME_HAVE_GLIDER|
+ NETMSG_PLAYERFRAME_GLIDER_ORPHAN) ){
+ player_glide_remote_animator_exchange( &ctx, &dest->data_glider );
+ }
+
player->subsystem = frame->subsystem;
player->down_bytes += msg->m_cbSize;
}
frame->inetmsg_id = k_inetmsg_playerframe;
frame->client = 0xff;
frame->subsystem = localplayer.subsystem;
- frame->instance_id = world_static.active_instance;
+ frame->flags = world_static.active_instance;
bitpack_ctx ctx = {
.mode = k_bitpack_compress,
for( u32 i=0; i<localplayer.sfx_buffer_count; i ++ )
net_sfx_exchange( &ctx, &localplayer.sfx_buffer[i] );
+ /* glider
+ * -------------------------------------------------------------*/
+
+ if( localplayer.have_glider ||
+ (localplayer.subsystem == k_player_subsystem_glide) ) {
+ frame->flags |= NETMSG_PLAYERFRAME_HAVE_GLIDER;
+ }
+
+ if( localplayer.glider_orphan )
+ frame->flags |= NETMSG_PLAYERFRAME_GLIDER_ORPHAN;
+
+ if( frame->flags & (NETMSG_PLAYERFRAME_HAVE_GLIDER|
+ NETMSG_PLAYERFRAME_GLIDER_ORPHAN) ){
+ player_glide_remote_animator_exchange( &ctx,
+ &player_glide.remote_animator );
+ }
+
+ /* ------- */
+
u32 wire_size = base_size + ctx.bytes;
netplayers.up_bytes += wire_size;
u8 instance_id = 0;
+ f32 t = 0.0f;
+
if( f1 ){
- f32 t = (buf->t - f0->timestamp) / (f1->timestamp - f0->timestamp);
- t = vg_clampf( t, 0.0f, 1.0f );
+ t = (buf->t - f0->timestamp) / (f1->timestamp - f0->timestamp);
+ t = vg_clampf( t, 0.0f, 1.0f );
sys1 = player_subsystems[f1->subsystem];
sys1->pose( &f1->data, &pose1 );
t = 1.0f;
}
- instance_id = f1->instance_id;
+ instance_id = f1->flags & NETMSG_PLAYERFRAME_INSTANCE_ID;
lerp_player_pose( &pose0, &pose1, t, &posed );
effect_blink_apply( &player->effect_data.blink, &posed, vg.time_delta );
memcpy( board_pose, &posed.board, sizeof(*board_pose) );
}
else {
- instance_id = f0->instance_id;
+ instance_id = f0->flags & NETMSG_PLAYERFRAME_INSTANCE_ID;
effect_blink_apply( &player->effect_data.blink, &pose0, vg.time_delta );
apply_full_skeleton_pose( sk, &pose0, final_mtx );
if( sys0->effects )
memcpy( board_pose, &pose0.board, sizeof(*board_pose) );
}
+ if( f0->flags & (NETMSG_PLAYERFRAME_HAVE_GLIDER|
+ NETMSG_PLAYERFRAME_GLIDER_ORPHAN) ){
+ player->render_glider = 1;
+
+ v3f co;
+ v4f q;
+ f32 s;
+
+ if( f1 ){
+ v3_lerp( f0->data_glider.root_co, f1->data_glider.root_co, t, co );
+ q_nlerp( f0->data_glider.root_q, f1->data_glider.root_q, t, q );
+ s = vg_lerpf( f0->data_glider.s, f1->data_glider.s, t );
+ }
+ else {
+ v3_copy( f0->data_glider.root_co, co );
+ v4_copy( f0->data_glider.root_q, q );
+ s = f0->data_glider.s;
+ }
+
+ v3f *mtx = netplayers.glider_mtx[ index ];
+ q_m3x3( q, mtx );
+ m3x3_scalef( mtx, s );
+ v3_copy( co, mtx[3] );
+ }
+ else
+ player->render_glider = 0;
+
if( player->world_match[ instance_id ] )
player->active_world = &world_static.instances[ instance_id ];
}
* Draw remote players
*/
static void render_remote_players( world_instance *world, camera *cam ){
- SDL_AtomicLock( &addon_system.sl_cache_using_resources );
- struct skeleton *sk = &localplayer.skeleton;
+ u32 draw_list[ NETWORK_MAX_PLAYERS ],
+ draw_list_count = 0,
+ gliders = 0;
for( u32 i=0; i<NETWORK_MAX_PLAYERS; i ++ ){
struct network_player *player = &netplayers.list[i];
if( player->active_world != world ) continue;
if( !player->isfriend &&
(world-world_static.instances == k_world_purpose_hub)) continue;
-
- m4x3f *final_mtx = &netplayers.final_mtx[ sk->bone_count*i ];
+
+ draw_list[draw_list_count ++] = i;
+
+ if( player->render_glider )
+ gliders ++;
+ }
+
+ struct skeleton *sk = &localplayer.skeleton;
+
+ SDL_AtomicLock( &addon_system.sl_cache_using_resources );
+
+ for( u32 j=0; j<draw_list_count; j ++ ){
+ u32 index = draw_list[j];
+
+ struct network_player *player = &netplayers.list[index];
+ m4x3f *final_mtx = &netplayers.final_mtx[ sk->bone_count*index ];
struct player_model *model =
addon_cache_item_if_loaded( k_addon_type_player,
addon_cache_item_if_loaded( k_addon_type_board,
player->board_view_slot );
render_board( cam, world, board, final_mtx[localplayer.id_board],
- &netplayers.board_poses[ i ], k_board_shader_player );
+ &netplayers.board_poses[ index ], k_board_shader_player );
}
SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
+
+ if( !gliders )
+ return;
+
+ /* TODO: we really, really only need to do all this once. at some point
+ * PLEASE figure out a good place to do this once per frame!
+ */
+
+ shader_model_entity_use();
+ shader_model_entity_uTexMain( 0 );
+ shader_model_entity_uCamera( cam->transform[3] );
+ shader_model_entity_uPv( cam->mtx.pv );
+
+ WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, model_entity );
+
+ for( u32 j=0; j<draw_list_count; j ++ ){
+ u32 index = draw_list[j];
+
+ struct network_player *player = &netplayers.list[index];
+ if( !player->render_glider ) continue;
+
+ if( player->render_glider ){
+ v3f *glider_mtx = netplayers.glider_mtx[ index ];
+ render_glider_model( cam, world, glider_mtx, k_board_shader_entity );
+ }
+ }
}
static int remote_players_randomize( int argc, const char *argv[] ){
f32 down_kbs;
struct player_effects_data effect_data;
+ bool render_glider;
}
list[ NETWORK_MAX_PLAYERS ];
f64 timestamp;
enum player_subsystem subsystem;
- u8 instance_id;
+ u8 flags;
u16 boundary_hash;
union interp_animdata {
struct player_basic_info_animator __basic;
}
data;
+
+ struct remote_glider_animator data_glider;
}
frames[ NETWORK_BUFFERFRAMES ];
struct net_sfx sfx_queue[ NETWORK_SFX_QUEUE_LENGTH ];
- m4x3f *final_mtx;
+ m4x3f *final_mtx,
+ *glider_mtx;
struct player_board_pose board_poses[ NETWORK_MAX_PLAYERS ];
u32 up_bytes;
#include "network.h"
#include "player_remote.h"
+#include "player_glide.h"
static void player_load_animation_reference( const char *path ){
mdl_context *meta = &localplayer.skeleton_meta;
localplayer.final_mtx = vg_linear_alloc( vg_mem.rtmemory, mtx_size );
netplayers.final_mtx = vg_linear_alloc( vg_mem.rtmemory,
mtx_size*NETWORK_MAX_PLAYERS );
+ netplayers.glider_mtx = vg_linear_alloc( vg_mem.rtmemory,
+ sizeof(m4x3f)*NETWORK_MAX_PLAYERS );
}
/* TODO: Standard model load */