From: hgn Date: Tue, 18 Oct 2022 19:44:31 +0000 (+0100) Subject: achievements and stuff X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;ds=inline;h=d5405f24a854aff8b76bb126492f2c18bc874270;p=carveJwlIkooP6JGAAIwe30JlM.git achievements and stuff --- diff --git a/blender_export.py b/blender_export.py index 86b6541..3cff63d 100644 --- a/blender_export.py +++ b/blender_export.py @@ -161,6 +161,10 @@ class classtype_bone(Structure): ("angle_limits",(c_float*3)*2), ("hitbox",(c_float*3)*2)] +class classtype_achievement_box(Structure): + _pack_ = 1 + _fields_ = [("pstr_name",c_uint32)] + # Exporter # ============================================================================== @@ -321,7 +325,11 @@ def write_model(collection_name): _extendb( tree, b, d+1 ) for obj1 in n.children: - _extend( tree, obj1, d+1 ) + nonlocal collection + for c1 in obj1.users_collection: + if c1 == collection: + _extend( tree, obj1, d+1 ) + break p["children"] += [tree] graph_lookup[n] = tree @@ -808,6 +816,14 @@ def write_model(collection_name): block.bbx[1][2] = -source.v0[1] entdata_buffer += [block] + elif classtype == 'k_classtype_achievement_box': + node.classtype = 13 + + entdata_length += sizeof( classtype_achievement_box ) + ach = classtype_achievement_box() + ach.pstr_name = emplace_string( obj.cv_data.strp ) + entdata_buffer += [ach] + elif classtype == 'k_classtype_spawn': node.classtype = 3 @@ -1151,6 +1167,29 @@ def cv_draw(): obj.matrix_world.to_quaternion() @ Vector((0,0,-6+1.5)) drawbline( obj.location, p1, sw,sw2 ) + elif obj.cv_data.classtype == 'k_classtype_achievement_box': + a = Vector((-1,-1,-1)) + b = Vector((1,1,1)) + + vs = [None]*8 + vs[0] = obj.matrix_world @ Vector((a[0], a[1], a[2])) + vs[1] = obj.matrix_world @ Vector((a[0], b[1], a[2])) + vs[2] = obj.matrix_world @ Vector((b[0], b[1], a[2])) + vs[3] = obj.matrix_world @ Vector((b[0], a[1], a[2])) + vs[4] = obj.matrix_world @ Vector((a[0], a[1], b[2])) + vs[5] = obj.matrix_world @ Vector((a[0], b[1], b[2])) + vs[6] = obj.matrix_world @ Vector((b[0], b[1], b[2])) + vs[7] = obj.matrix_world @ Vector((b[0], a[1], b[2])) + + indices = [(0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),\ + (0,4),(1,5),(2,6),(3,7)] + + for l in indices: + v0 = vs[l[0]] + v1 = vs[l[1]] + verts += [(v0[0],v0[1],v0[2])] + verts += [(v1[0],v1[1],v1[2])] + colours += [(0,1,0,1),(0,1,0,1)] elif obj.cv_data.classtype == 'k_classtype_block': a = obj.data.cv_data.v0 @@ -1329,6 +1368,8 @@ class CV_MESH_SETTINGS(bpy.types.PropertyGroup): class CV_OBJ_SETTINGS(bpy.types.PropertyGroup): uid: bpy.props.IntProperty( name="" ) + strp: bpy.props.StringProperty(name="string") + target: bpy.props.PointerProperty( type=bpy.types.Object, name="target", \ poll=cv_poll_target ) target1: bpy.props.PointerProperty( type=bpy.types.Object, name="target1", \ @@ -1352,7 +1393,8 @@ class CV_OBJ_SETTINGS(bpy.types.PropertyGroup): ('k_classtype_route', "k_classtype_route", "", 9 ), ('k_classtype_bone',"k_classtype_bone","",10), ('k_classtype_SKELETON', "","", 11 ), - ('k_classtype_SKIN',"","",12) + ('k_classtype_SKIN',"","",12), + ('k_classtype_achievement_box',"k_classtype_achievement_box","",13), ]) class CV_BONE_SETTINGS(bpy.types.PropertyGroup): @@ -1430,6 +1472,8 @@ class CV_OBJ_PANEL(bpy.types.Panel): mesh = active_object.data _.layout.label( text=F"(i) Data is stored in {mesh.name}" ) _.layout.prop( mesh.cv_data, "v0" ) + elif active_object.cv_data.classtype == 'k_classtype_achievement_box': + _.layout.prop( active_object.cv_data, "strp" ) class CV_INTERFACE(bpy.types.Panel): bl_idname = "VIEW3D_PT_carve" diff --git a/build.sh b/build.sh index 5c72dd3..8920806 100755 --- a/build.sh +++ b/build.sh @@ -57,7 +57,7 @@ compile_miniaudio(){ # TODO run_game(){ cd $_linux_folder - ./skaterift + ./skaterift --samples=4 cd ./../ } diff --git a/common.h b/common.h index 0abe446..c0a5f35 100644 --- a/common.h +++ b/common.h @@ -34,12 +34,6 @@ static u32 utf8_byte0_byte_count( u8 char0 ) static void str_utf8_collapse( const char *str, char *buf, u32 length ) { - if( length == 0 ) - { - strncpy( buf, "User", length ); - return; - } - u8 *ustr = (u8 *)str; u32 utf32_code = 0x00000000; u32 i=0, j=0, utf32_byte_ct=0; diff --git a/highscores.h b/highscores.h index 494cd83..f19f93a 100644 --- a/highscores.h +++ b/highscores.h @@ -389,7 +389,7 @@ static aatree_ptr highscores_push_record( highscore_record *record ) return index; } -static aatree_ptr highscore_set_user_nickname( u64 steamid, char nick[10] ) +static aatree_ptr highscore_set_user_nickname( u64 steamid, char nick[16] ) { char name[17]; for( int i=0; i<16; i++ ) diff --git a/main.c b/main.c index 2ac5e20..5cce721 100644 --- a/main.c +++ b/main.c @@ -92,7 +92,7 @@ void vg_load(void) static void vg_start(void) { - player_load_model( "ch_new" ); + player_load_model( "ch_outlaw" ); reset_player( 1, (const char *[]){ "start" } ); } diff --git a/model.h b/model.h index c84f0fe..d067b8f 100644 --- a/model.h +++ b/model.h @@ -39,7 +39,8 @@ enum classtype k_classtype_route = 9, k_classtype_bone = 10, k_classtype_skeleton = 11, - k_classtype_skin = 12 + k_classtype_skin = 12, + k_classtype_achievement_box = 13 }; @@ -194,6 +195,11 @@ struct classtype_skin u32 skeleton; }; +struct classtype_achievement_box +{ + u32 pstr_name; +}; + #pragma pack(pop) /* diff --git a/models_src/alter.mdl b/models_src/alter.mdl index f782230..b5b0798 100644 Binary files a/models_src/alter.mdl and b/models_src/alter.mdl differ diff --git a/models_src/ch_jordan.mdl b/models_src/ch_jordan.mdl new file mode 100644 index 0000000..a191251 Binary files /dev/null and b/models_src/ch_jordan.mdl differ diff --git a/models_src/ch_outlaw.mdl b/models_src/ch_outlaw.mdl index 25d55ad..eb2aa3c 100644 Binary files a/models_src/ch_outlaw.mdl and b/models_src/ch_outlaw.mdl differ diff --git a/models_src/mp_dev.mdl b/models_src/mp_dev.mdl index d59953b..3447ab4 100644 Binary files a/models_src/mp_dev.mdl and b/models_src/mp_dev.mdl differ diff --git a/network.h b/network.h index b12d884..e06027a 100644 --- a/network.h +++ b/network.h @@ -172,7 +172,7 @@ static void send_nickname(void) nick.inetmsg_id = k_inetmsg_set_nickname; memset( nick.nickname, 0, 16 ); - strncpy( nick.nickname, steam_username_at_startup, 16 ); + vg_strncpy( steam_username_at_startup, nick.nickname, 16 ); SteamAPI_ISteamNetworkingSockets_SendMessageToConnection( hSteamNetworkingSockets, cremote, &nick, sizeof(netmsg_set_nickname), diff --git a/player.h b/player.h index 82381c2..0d77338 100644 --- a/player.h +++ b/player.h @@ -17,7 +17,8 @@ static float k_board_radius = 0.3f, k_board_length = 0.45f, k_board_allowance = 0.04f, - k_friction_lat = 8.8f, + //k_friction_lat = 8.8f, + k_friction_lat = 12.0f, k_friction_resistance = 0.01f, k_max_push_speed = 16.0f, k_push_accel = 10.0f, diff --git a/shaders/scoretext.h b/shaders/scoretext.h index 4f1dc8f..eea32ee 100644 --- a/shaders/scoretext.h +++ b/shaders/scoretext.h @@ -36,7 +36,7 @@ static struct vg_shader _shader_scoretext = { " float s = -sin(w*0.2);\n" " float r = 0.2;\n" "\n" -" float w1 = clamp( w*4.0 - a_co.y*10.0, -1.0, 1.0 ) * (3.14159265*2.5);\n" +" float w1 = clamp( w*4.0 - a_co.y*10.0, -1.0, 1.0 ) * (3.14159265*0.5);\n" " float c1 = cos(w1);\n" " float s1 = sin(w1);\n" "\n" diff --git a/shaders/viewchar.fs b/shaders/viewchar.fs index fedd3e1..9c46328 100644 --- a/shaders/viewchar.fs +++ b/shaders/viewchar.fs @@ -22,12 +22,11 @@ void main() vec3 qnorm = normalize(floor(aNorm*2.0)*0.5) + vec3(0.001,0.0,0.0); - vfrag = do_light_diffuse( vfrag, qnorm ); - vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 ); + vfrag = mix( vfrag, do_light_diffuse( vfrag, qnorm ), 0.5 ); + //vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 ); vfrag = do_light_shadowing( vfrag ); vfrag = apply_fog( vfrag, fdist ); float opacity = clamp( fdist, 0.1, 1.0 ); - FragColor = vec4(vfrag,opacity); } diff --git a/shaders/viewchar.h b/shaders/viewchar.h index 00dc353..8e6b8fc 100644 --- a/shaders/viewchar.h +++ b/shaders/viewchar.h @@ -174,13 +174,12 @@ static struct vg_shader _shader_viewchar = { "\n" " vec3 qnorm = normalize(floor(aNorm*2.0)*0.5) + vec3(0.001,0.0,0.0);\n" "\n" -" vfrag = do_light_diffuse( vfrag, qnorm );\n" -" vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );\n" +" vfrag = mix( vfrag, do_light_diffuse( vfrag, qnorm ), 0.5 );\n" +" //vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );\n" " vfrag = do_light_shadowing( vfrag );\n" " vfrag = apply_fog( vfrag, fdist );\n" "\n" " float opacity = clamp( fdist, 0.1, 1.0 );\n" -"\n" " FragColor = vec4(vfrag,opacity);\n" "}\n" ""}, diff --git a/steam.h b/steam.h index fbb4f8a..a213222 100644 --- a/steam.h +++ b/steam.h @@ -53,7 +53,10 @@ static const char *steam_achievement_names[] = static void steam_store_achievements(void) { - SteamAPI_ISteamUserStats_StoreStats( hSteamUserStats ); + if( steam_ready && steam_stats_ready ) + { + SteamAPI_ISteamUserStats_StoreStats( hSteamUserStats ); + } } static void steam_set_achievement( const char *name ) diff --git a/world.h b/world.h index bf81595..7f8432a 100644 --- a/world.h +++ b/world.h @@ -58,6 +58,17 @@ static struct gworld spawns[32]; u32 spawn_count; + struct achievement_zone + { + m4x3f transform, inv_transform; + char name[32]; + int triggered; + } + * achievement_zones; + + u32 achievement_zones_count, + achievement_zones_cap; + struct subworld_routes { struct route_node @@ -288,6 +299,7 @@ static void world_free( void *_ ) { mesh_free( &world.cars ); mesh_free( &world.skydome ); + vg_free( world.achievement_zones ); } static void world_update( v3f pos ) @@ -331,6 +343,30 @@ static void world_update( v3f pos ) } } } + + for( int i=0; itriggered ) + continue; + + v3f local; + m4x3_mulv( zone->inv_transform, pos, local ); + + if( (fabsf(local[0]) <= 1.0f) && + (fabsf(local[1]) <= 1.0f) && + (fabsf(local[2]) <= 1.0f) ) + { + zone->triggered = 1; + steam_set_achievement( zone->name ); + steam_store_achievements(); + } + + vg_line_boxf_transformed( zone->transform, (boxf){{-1.0f,-1.0f,-1.0f}, + { 1.0f, 1.0f, 1.0f}}, + 0xff00ff00 ); + } sfd_update( &world.sfd.tester ); } diff --git a/world_gen.h b/world_gen.h index 49ea495..54857f5 100644 --- a/world_gen.h +++ b/world_gen.h @@ -208,6 +208,26 @@ static void world_load(void) } } } + else if( pnode->classtype == k_classtype_achievement_box ) + { + world.achievement_zones = + buffer_reserve( world.achievement_zones, + world.achievement_zones_count, + &world.achievement_zones_cap, 1, + sizeof(struct achievement_zone) ); + + struct achievement_zone *zone = &world.achievement_zones[ + world.achievement_zones_count ++ ]; + + + struct classtype_achievement_box *box = mdl_get_entdata(mworld,pnode); + + mdl_node_transform( pnode, zone->transform ); + m4x3_invert_full( zone->transform, zone->inv_transform ); + vg_strncpy( mdl_pstr(mworld, box->pstr_name), zone->name, 31 ); + zone->name[31] = 0x00; + zone->triggered = 0; + } } world.instance_cache = buffer_fix( world.instance_cache,