leaderboard seems to have segfault. fixed typos
[fishladder.git] / fishladder.c
index d7b887d2f602bc62b0a7a2f03cb9af134a8e0cd6..8b64ffc0053183621c0ab84bfb6c127656a80dd7 100644 (file)
@@ -5,6 +5,8 @@
 #include "vg/vg.h"
 #include "fishladder_resources.h"
 
+// #define STEAM_LEADERBOARDS
+
 // CONSTANTS
 // ===========================================================================================================
 
@@ -1250,7 +1252,7 @@ void vg_update(void)
                        
                        if( vg_get_button_up("secondary") && world.id_drag_from == world.selected )
                        {
-                               u32 link_id = local_x > 0.5f? 1: 0;
+                               u32 link_id = cell_ptr->links[ 0 ]? 0: 1;
                                
                                // break existing connection off
                                if( cell_ptr->links[ link_id ] )
@@ -1268,7 +1270,7 @@ void vg_update(void)
                                world.id_drag_from = 0;
                        }
                        
-                       if( world.id_drag_from && (cell_ptr->state & FLAG_CANAL) && (cell_ptr->config == k_cell_type_split) )
+                       else if( world.id_drag_from && (cell_ptr->state & FLAG_CANAL) && (cell_ptr->config == k_cell_type_split) )
                        {
                                world.drag_to_co[0] = (float)world.tile_x + (local_x > 0.5f? 0.75f: 0.25f);
                                world.drag_to_co[1] = (float)world.tile_y + 0.25f;
@@ -2014,6 +2016,9 @@ void vg_render(void)
        int const empty_start = circle_base+32;
        int const empty_count = circle_base+32*2;
        
+       if( !world.initialzed )
+               return;
+       
        // BACKGROUND
        // ========================================================================================================
        use_mesh( &world.shapes );
@@ -2823,6 +2828,7 @@ void vg_ui(void)
 
 void leaderboard_dispatch_score(void)
 {
+#if STEAM_LEADERBOARDS
        sw_upload_leaderboard_score( 
                ui_data.upload_request.level->steam_leaderboard, 
                k_ELeaderboardUploadScoreMethodKeepBest,
@@ -2834,10 +2840,12 @@ void leaderboard_dispatch_score(void)
        ui_data.upload_request.is_waiting = 0;
        
        vg_success( "Dispatched leaderboard score\n" );
+#endif
 }
 
 void leaderboard_found( LeaderboardFindResult_t *pCallback )
 {
+#ifdef STEAM_LEADERBOARDS
        if( !pCallback->m_bLeaderboardFound )
        {
                vg_error( "Leaderboard could not be found\n" );
@@ -2867,10 +2875,12 @@ void leaderboard_found( LeaderboardFindResult_t *pCallback )
                        }
                }
        }
+#endif
 }
 
 void leaderboard_downloaded( LeaderboardScoresDownloaded_t *pCallback )
 {
+#ifdef STEAM_LEADERBOARDS
        // Update UI if this leaderboard matches what we currently have in view
        if( ui_data.level_selected->steam_leaderboard == pCallback->m_hSteamLeaderboard )
        {
@@ -2905,10 +2915,12 @@ void leaderboard_downloaded( LeaderboardScoresDownloaded_t *pCallback )
                        ui_data.leaderboard_show = 0;
        }
        else vg_warn( "Downloaded leaderboard does not match requested!\n" );
+#endif
 }
 
 void leaderboard_set_score( struct cmp_level *cmp_level, u32 score )
 {
+#ifdef STEAM_LEADERBOARDS
        if( ui_data.upload_request.is_waiting )
                vg_warn( "You are uploading leaderboard entries too quickly!\n" );
                
@@ -2921,6 +2933,7 @@ void leaderboard_set_score( struct cmp_level *cmp_level, u32 score )
                leaderboard_dispatch_score();
        else
                sw_find_leaderboard( cmp_level->map_name );
+#endif
 }
 
 // CONSOLE COMMANDS
@@ -3044,8 +3057,10 @@ static int console_changelevel( int argc, char const *argv[] )
 void vg_start(void)
 {
        // Steamworks callbacks
+       #ifdef STEAM_LEADERBOARDS
        sw_leaderboard_found = &leaderboard_found;
        sw_leaderboard_downloaded = &leaderboard_downloaded;
+       #endif
 
        vg_function_push( (struct vg_cmd){
                .name = "_map_write",