Rolled back ball/set to a less exposed implementation.
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sun, 6 Jan 2008 16:31:02 +0000 (16:31 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sun, 6 Jan 2008 16:31:02 +0000 (16:31 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@1418 78b8d119-cf0a-0410-b17c-f493084dd1d7

ball/set.c
ball/set.h
ball/st_done.c
ball/st_level.c
ball/st_set.c
ball/st_start.c

index 0f2c084..a2b1e2f 100644 (file)
 
 /*---------------------------------------------------------------------------*/
 
+struct set
+{
+    char file[PATHMAX];
+
+    char *id;                  /* Internal set identifier    */
+    char *name;                /* Set name                   */
+    char *desc;                /* Set description            */
+    char *shot;                /* Set screen-shot            */
+
+    char user_scores[PATHMAX]; /* User high-score file       */
+
+    struct score time_score;   /* Challenge score            */
+    struct score coin_score;   /* Challenge score            */
+
+    /* Level stats */
+
+    unsigned int count;        /* Number of levels           */
+};
+
 static int set_state = 0;
 
 static int set;
@@ -273,25 +292,43 @@ void set_free(void)
 
 /*---------------------------------------------------------------------------*/
 
-int  set_exists(int i)
+int set_exists(int i)
 {
     return (0 <= i && i < count);
 }
 
-const struct set *get_set(int i)
+const char *set_name(int i)
 {
-    return set_exists(i) ? &set_v[i] : NULL;
+    return set_exists(i) ? _(set_v[i].name) : NULL;
 }
 
-/*---------------------------------------------------------------------------*/
+const char *set_desc(int i)
+{
+    return set_exists(i) ? _(set_v[i].desc) : NULL;
+}
 
-int set_level_exists(const struct set *s, int i)
+const char *set_shot(int i)
 {
-    return (i >= 0) && (i < s->count);
+    return set_exists(i) ? set_v[i].shot : NULL;
+}
+
+const struct score *set_time_score(int i)
+{
+    return set_exists(i) ? &set_v[i].time_score : NULL;
+}
+
+const struct score *set_coin_score(int i)
+{
+    return set_exists(i) ? &set_v[i].coin_score : NULL;
 }
 
 /*---------------------------------------------------------------------------*/
 
+int set_level_exists(int s, int i)
+{
+    return (i >= 0 && i < set_v[s].count);
+}
+
 static void set_load_levels(void)
 {
     FILE *fin;
@@ -357,9 +394,9 @@ void set_goto(int i)
     set_load_hs();
 }
 
-const struct set *curr_set(void)
+int curr_set(void)
 {
-    return &set_v[set];
+    return set;
 }
 
 const struct level *get_level(int i)
@@ -422,7 +459,7 @@ void score_change_name(struct level_game *lg, const char *player)
 
 static struct level *next_level(int i)
 {
-    return set_level_exists(&set_v[set], i + 1) ? &level_v[i + 1] : NULL;
+    return set_level_exists(set, i + 1) ? &level_v[i + 1] : NULL;
 }
 
 static struct level *next_normal_level(int i)
index 48d240c..d06676a 100644 (file)
@@ -4,54 +4,38 @@
 #include "base_config.h"
 #include "level.h"
 
-/*---------------------------------------------------------------------------*/
-
 #define SET_FILE "sets.txt"
 
 #define MAXSET 16
 #define MAXLVL 25
 
-struct set
-{
-    char file[PATHMAX];
-
-    char *id;                  /* Internal set identifier    */
-    char *name;                /* Set name                   */
-    char *desc;                /* Set description            */
-    char *shot;                /* Set screen-shot            */
-
-    char user_scores[PATHMAX]; /* User high-score file       */
-
-    struct score time_score;   /* Challenge score            */
-    struct score coin_score;   /* Challenge score            */
-
-    /* Level stats */
-
-    unsigned int count;        /* Number of levels           */
-};
-
 /*---------------------------------------------------------------------------*/
 
 int  set_init(void);
 void set_free(void);
 
+/*---------------------------------------------------------------------------*/
+
 int  set_exists(int);
+void set_goto(int);
 
-const struct set *get_set(int);
+int  curr_set(void);
 
-int set_level_exists(const struct set *, int);
+const char         *set_name(int);
+const char         *set_desc(int);
+const char         *set_shot(int);
+const struct score *set_time_score(int);
+const struct score *set_coin_score(int);
 
-void                set_goto(int i);
-const struct set *  curr_set(void);
-const struct level *get_level(int);
 
 /*---------------------------------------------------------------------------*/
 
+int set_level_exists(int, int);
+const struct level *get_level(int);
+
 void set_finish_level(struct level_game *, const char *);
 void score_change_name(struct level_game *, const char *);
 
-/*---------------------------------------------------------------------------*/
-
 void level_snap(int);
 void set_cheat(void);
 
index 5672fe5..fc5f945 100644 (file)
@@ -101,8 +101,8 @@ static int done_enter(void)
         gui_pulse(gid, 1.2f);
     }
 
-    set_best_times(&curr_set()->time_score, curr_lg()->times_rank, 0);
-    set_most_coins(&curr_set()->coin_score, curr_lg()->score_rank);
+    set_best_times(set_time_score(curr_set()), curr_lg()->times_rank, 0);
+    set_most_coins(set_coin_score(curr_set()), curr_lg()->score_rank);
 
     return id;
 }
index f523fb1..c6f7f8a 100644 (file)
@@ -48,8 +48,9 @@ static int level_enter(void)
 
             if ((kd = gui_vstack(jd)))
             {
-                gui_label(kd, _(curr_set()->name), GUI_SML,
-                          GUI_ALL, gui_wht, gui_wht);
+                gui_label(kd, set_name(curr_set()), GUI_SML, GUI_ALL,
+                          gui_wht, gui_wht);
+
                 gui_space(kd);
 
                 if ((ld = gui_hstack(kd)))
index 7f2db14..fc86e4e 100644 (file)
@@ -83,10 +83,8 @@ static int set_action(int i)
 
 static void gui_set(int id, int i)
 {
-    const struct set *s;
-
-    if ((s = get_set(i)))
-        gui_state(id, _(s->name), GUI_SML, i, 0);
+    if (set_exists(i))
+        gui_state(id, set_name(i), GUI_SML, i, 0);
     else
         gui_label(id, "", GUI_SML, GUI_ALL, 0, 0);
 }
@@ -119,8 +117,7 @@ static int set_enter(void)
 
         if ((jd = gui_harray(id)))
         {
-            shot_id = gui_image(jd, get_set(first)->shot,
-                                7 * w / 16, 7 * h / 16);
+            shot_id = gui_image(jd, set_shot(first), 7 * w / 16, 7 * h / 16);
 
             if ((kd = gui_varray(jd)))
             {
@@ -140,8 +137,8 @@ static int set_enter(void)
 
 static void set_over(int i)
 {
-    gui_set_image(shot_id, get_set(i)->shot);
-    gui_set_multi(desc_id, _(get_set(i)->desc));
+    gui_set_image(shot_id, set_shot(i));
+    gui_set_multi(desc_id, set_desc(i));
 }
 
 static void set_point(int id, int x, int y, int dx, int dy)
index 5e90fd3..ec5b582 100644 (file)
@@ -44,13 +44,11 @@ static int status_id;
 static void gui_level(int id, int i)
 {
     const GLfloat *fore, *back;
-
-    const struct set *s = curr_set();
     const struct level *l;
 
     int jd;
 
-    if (!set_level_exists(s, i))
+    if (!set_level_exists(curr_set(), i))
     {
         gui_space(id);
         return;
@@ -127,9 +125,9 @@ static void start_over(int id)
     switch (i)
     {
     case START_CHALLENGE:
-        gui_set_image(shot_id, curr_set()->shot);
-        set_most_coins(&curr_set()->coin_score, -1);
-        set_best_times(&curr_set()->time_score, -1, 0);
+        gui_set_image(shot_id, set_shot(curr_set()));
+        set_most_coins(set_coin_score(curr_set()), -1);
+        set_best_times(set_time_score(curr_set()), -1, 0);
         gui_set_label(status_id, _("Challenge all levels from the first one"));
         break;
 
@@ -220,7 +218,7 @@ static int start_enter(void)
         if ((jd = gui_hstack(id)))
         {
 
-            gui_label(jd, _(curr_set()->name), GUI_SML, GUI_ALL,
+            gui_label(jd, set_name(curr_set()), GUI_SML, GUI_ALL,
                       gui_yel, gui_red);
             gui_filler(jd);
             gui_start(jd, _("Back"),  GUI_SML, START_BACK, 0);
@@ -229,7 +227,7 @@ static int start_enter(void)
 
         if ((jd = gui_harray(id)))
         {
-            shot_id = gui_image(jd, curr_set()->shot, 7 * w / 16, 7 * h / 16);
+            shot_id = gui_image(jd, set_shot(curr_set()), 7 * w / 16, 7 * h / 16);
 
             if ((kd = gui_varray(jd)))
             {