fwd declerations
[fishladder.git] / fishladder.c
index 81c2b82409e347fd85555dcf47bcb58c2c133193..b4c0997b0e6b6247854ef8e73b68828663d6aa65 100644 (file)
@@ -1,6 +1,6 @@
 // Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
 
-#define VG_CAPTURE_MODE
+//#define VG_CAPTURE_MODE
 #define VG_STEAM
 #define VG_STEAM_APPID 1218140U
 #include "vg/vg.h"
@@ -258,11 +258,80 @@ struct world
 // Forward declerations
 // --------------------
 
+// Utility functions
+// -----------------
+
+static void colour_code_v3( char const cc, v3f target );
+static int hash21i( v2i p, u32 umod );
+
+// Mesh functions
+// --------------
+static void init_mesh( struct mesh *m, float const *tris, u32 length );
+static void free_mesh( struct mesh *m );
+static void use_mesh( struct mesh *m );
+static void draw_mesh( int const start, int const count );
+
+// World buttons
+// -------------
+static struct cell_button *get_wbutton( enum e_world_button btn );
+static void wbutton_run( enum e_world_button btn_name, v2f btn_tex );
+static void wbutton_draw( v2i pos, v2f tex, v4f colour );
+static void level_selection_buttons(void);
+
+// Map/world interface
+// -------------------
+static void map_free(void);
+static void io_reset(void);
+static struct cell *pcell( v2i pos );
+static void map_reclassify( v2i start, v2i end, int update_texbuffer );
+static u32 gen_text_buffer( const char *str, struct sdf_font *font, v2f origin, float size, u32 start );
+static void gen_level_text( struct cmp_level *pLevel );
+static int map_load( const char *str, const char *name );
+static void map_serialize( FILE *stream );
+
+// Career
+// ------
+static void career_serialize(void);
+static void career_unlock_level( struct cmp_level *lvl );
+static void career_unlock_level( struct cmp_level *lvl );
+static void career_pass_level( struct cmp_level *lvl, int score, int upload );
+static void career_reset_level( struct cmp_level *lvl );
+static void career_load(void);
+static void clear_animation_flags(void);
+
+// Gameplay main
+// -------------
+static void simulation_stop(void);
+static void simulation_start(void);
+static int world_check_pos_ok( v2i co );
+static int cell_interactive( v2i co );
+
+void vg_update(void);
+void leaderboard_found( LeaderboardFindResult_t *pCallback );
+void leaderboard_downloaded( LeaderboardScoresDownloaded_t *pCallback );
+
+static void render_tiles( v2i start, v2i end, v4f const regular_colour, v4f const selected_colour );
+
+void vg_render(void);
+void vg_ui(void);
+
+// Leaderboard stuff
+// -----------------
+void leaderboard_set_score( struct cmp_level *cmp_level, u32 score );
+void leaderboard_dispatch_score(void);
+void leaderboard_found( LeaderboardFindResult_t *pCallback );
+void leaderboard_downloaded( LeaderboardScoresDownloaded_t *pCallback );
+void leaderboard_set_score( struct cmp_level *cmp_level, u32 score );
 static int console_credits( int argc, char const *argv[] );
 static int console_save_map( int argc, char const *argv[] );
 static int console_load_map( int argc, char const *argv[] );
 static int console_changelevel( int argc, char const *argv[] );
 
+void vg_start(void);
+void vg_free(void);
+
+int main( int argc, char *argv[] );
+
 // GLOBALS
 // ===========================================================================================================
 
@@ -275,22 +344,36 @@ struct world world;
 // UTILITY
 // ===========================================================================================================
 
+static int colour_set_id = 0;
+
 static void colour_code_v3( char const cc, v3f target )
 {
-       static v3f colour_sets[] =
-       { { 1.0f, 0.9f, 0.3f },
-         { 0.2f, 0.9f, 0.14f },
-         { 0.4f, 0.8f, 1.00f },
-         { 0.882f, 0.204f, 0.922f }
+       static v3f colour_sets[][4] =
+       {
+               { { 1.0f, 0.9f, 0.3f },                 // Yellow
+                 { 0.4f, 0.8f, 1.00f },                // Blue
+                 { 0.2f, 0.9f, 0.14f },                // Green
+                 { 0.882f, 0.204f, 0.922f }    // Pink
+               },
+               { { 1.0f, 0.9f, 0.3f },                 // Yellow
+                 { 0.4f, 0.8f, 1.00f },                // Blue
+                 { 0.85f, 0.85f, 0.85f },              // Weiss
+                 { 0.2f, 0.2f, 0.2f }                  // Black/Gray
+               },
+               { { 1.0f, 0.9f, 0.3f },                 // Yellow
+                 { 0.827f, 0.373f, 0.718f },   // Pink
+                 { 0.0f, 0.353f, 0.71f },              // Blue
+                 { 0.863f, 0.196f, 0.125f }    // Red
+               },
        };
 
        if( cc >= 'a' && cc <= 'z' )
        {
                int id = cc - 'a';
                
-               if( id < vg_list_size( colour_sets ) )
+               if( id < vg_list_size( colour_sets[0] ) )
                {
-                       v3_copy( colour_sets[ id ], target );
+                       v3_copy( colour_sets[colour_set_id][ id ], target );
                        return;
                }
        }
@@ -3032,6 +3115,13 @@ void vg_start(void)
                .function = console_credits
        });
 
+       vg_convar_push( (struct vg_convar){
+               .name = "colours",
+               .data = &colour_set_id,
+               .data_type = k_convar_dtype_i32,
+               .opt_i32 = { .min = 0, .max = 2, .clamp = 1 }
+       });
+
        // Combined quad, long quad / empty circle / filled circle mesh
        {
                float combined_mesh[6*6 + 32*6*3] = {