X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_model.h;h=f2b375aa19988ba7391f5042cb67880ae8aa1ddf;hb=c33e4f46d864b2fde0c5938bf5a9388b1e8b5c04;hp=95b5a7624de95832f4ce58b242f925a8e54d9238;hpb=46643f969b12c2144a5f15ac5509610f18b467e4;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_model.h b/player_model.h index 95b5a76..f2b375a 100644 --- a/player_model.h +++ b/player_model.h @@ -1,50 +1,36 @@ -#ifndef CHARACTER_H +/* + * Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved + */ + +#ifndef CHARACTER_H #define CHARACTER_H -#include "common.h" -#include "model.h" -#include "rigidbody.h" -#include "render.h" -#include "skeleton.h" -#include "skeleton_animator.h" +#include "player.h" +#include "player_ragdoll.h" #include "shaders/viewchar.h" vg_tex2d tex_characters = { .path = "textures/ch_gradient.qoi" }; -static void character_register(void) +static void player_model_init(void) { shader_viewchar_register(); + vg_acquire_thread_sync(); + { + vg_tex2d_init( (vg_tex2d *[]){ &tex_characters }, 1 ); + } + vg_release_thread_sync(); } -static void character_init(void) +static void player_model_free(void *_) { - vg_tex2d_init( (vg_tex2d *[]){ &tex_characters }, 1 ); + mesh_free( &player.mdl.mesh ); + vg_tex2d_free( (vg_tex2d *[]){ &tex_characters }, 1 ); } -struct character -{ - glmesh mesh; - struct skeleton sk; - struct skeleton_anim *anim_stand, - *anim_highg, - *anim_slide, - *anim_air, - *anim_push, *anim_push_reverse, - *anim_ollie; - - u32 id_hip, - id_ik_hand_l, - id_ik_hand_r, - id_ik_elbow_l, - id_ik_elbow_r, - id_head; - - v3f cam_pos; - - int shoes[2]; -}; - -static int character_load( struct character *ch, const char *name ) +/* + * Load model from file (.mdl) + */ +static void player_load_model( const char *name ) { char buf[64]; @@ -52,41 +38,88 @@ static int character_load( struct character *ch, const char *name ) mdl_header *src = mdl_load( buf ); if( !src ) - return 0; + { + vg_error( "Could not load model\n" ); + return; + } + + struct player_model temp; + + mdl_unpack_glmesh( src, &temp.mesh ); + skeleton_setup( &temp.sk, src ); + + /* + * Link animations + */ + struct _load_anim + { + const char *name; + struct skeleton_anim **anim; + } + anims[] = { + { "pose_stand", &temp.anim_stand }, + { "pose_highg", &temp.anim_highg }, + { "pose_slide", &temp.anim_slide }, + { "pose_air", &temp.anim_air }, + { "push", &temp.anim_push }, + { "push_reverse", &temp.anim_push_reverse }, + { "ollie", &temp.anim_ollie }, + { "ollie_reverse",&temp.anim_ollie_reverse }, + { "grabs", &temp.anim_grabs }, + { "walk", &temp.anim_walk }, + { "run", &temp.anim_run }, + { "idle_cycle", &temp.anim_idle }, + { "jump", &temp.anim_jump } + }; - int error_count = 0; - mdl_unpack_glmesh( src, &ch->mesh ); - - if( !error_count ) - vg_success( "Loaded character file '%s' with no errors\n", name ); - - skeleton_setup( &ch->sk, src ); - ch->anim_stand = skeleton_get_anim( &ch->sk, "pose_stand" ); - ch->anim_highg = skeleton_get_anim( &ch->sk, "pose_highg" ); - ch->anim_slide = skeleton_get_anim( &ch->sk, "pose_slide" ); - ch->anim_air = skeleton_get_anim( &ch->sk, "pose_air" ); - ch->anim_push = skeleton_get_anim( &ch->sk, "push" ); - ch->anim_push_reverse = skeleton_get_anim( &ch->sk, "push_reverse" ); - ch->anim_ollie = skeleton_get_anim( &ch->sk, "ollie" ); - - ch->id_hip = skeleton_bone_id( &ch->sk, "hips" ); - ch->id_ik_hand_l = skeleton_bone_id( &ch->sk, "hand.IK.L" ); - ch->id_ik_hand_r = skeleton_bone_id( &ch->sk, "hand.IK.R" ); - ch->id_ik_elbow_l = skeleton_bone_id( &ch->sk, "elbow.L" ); - ch->id_ik_elbow_r = skeleton_bone_id( &ch->sk, "elbow.R" ); - ch->id_head = skeleton_bone_id( &ch->sk, "head" ); - - free( src ); - return 1; + for( int i=0; i