[monkey-bubble: 51/753] gnome-score fixes, etc.
- From: Sven Herzberg <herzi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [monkey-bubble: 51/753] gnome-score fixes, etc.
- Date: Wed, 14 Jul 2010 21:59:58 +0000 (UTC)
commit 310c3a56853888bede0a13e7c84254b4fe533e17
Author: Elliot Lee <sopwith src gnome org>
Date: Tue Jan 20 21:39:31 1998 +0000
gnome-score fixes, etc.
libgnome/gnome-score.c | 54 +++++++++++++++++++++++++++--------------------
libgnome/gnome-score.h | 14 ++++++++----
2 files changed, 40 insertions(+), 28 deletions(-)
---
diff --git a/libgnome/gnome-score.c b/libgnome/gnome-score.c
index 47a578a..64818cf 100644
--- a/libgnome/gnome-score.c
+++ b/libgnome/gnome-score.c
@@ -11,8 +11,10 @@
#include "gnome-score-helper.c"
#undef GNOME_SCORE_C
-gboolean /* Returns TRUE if it was a notable (top ten) score */
-gnome_score_log(gfloat score, gchar *level, int ordering)
+gint
+gnome_score_log(gfloat score,
+ gchar *level,
+ gboolean higher_to_lower_score_order)
{
int exitstatus;
char buf[64];
@@ -23,9 +25,9 @@ gnome_score_log(gfloat score, gchar *level, int ordering)
{
/* We are the child */
snprintf(buf, sizeof(buf), "%f", score);
- snprintf(buf2, sizeof(buf2), "%d", ordering);
+ snprintf(buf2, sizeof(buf2), "%d", higher_to_lower_score_order);
execlp("gnome-score-helper", "gnome-score-helper",
- buf, level, buf2, NULL);
+ buf, level?level:"", buf2, NULL);
exit(99);
}
@@ -35,7 +37,7 @@ gnome_score_log(gfloat score, gchar *level, int ordering)
else
{
g_warning("Scorekeeping failed\n");
- return FALSE;
+ return 0;
}
}
@@ -47,6 +49,7 @@ gnome_score_get_notable(gchar *gamename,
time_t **scoretimes)
{
gchar *realname, buf[512], *buf2;
+ gchar *infile_name;
FILE *infile;
gint retval;
@@ -60,25 +63,32 @@ gnome_score_get_notable(gchar *gamename,
if(!realname)
return -1;
- snprintf(buf, sizeof(buf), "%s/%s.%s.scores", SCORE_PATH, realname, level);
+ infile_name = gnome_get_score_file_name(realname, level);
+
+ infile = fopen(infile_name, "r");
+ g_free(infile_name);
+ g_free(realname);
- infile = fopen(buf, "r");
if(infile)
{
- *names = g_malloc(NSCORES*sizeof(gchar*));
- *scores = g_malloc(NSCORES*sizeof(gfloat));
- *scoretimes = g_malloc(NSCORES*sizeof(time_t));
-
- for(retval = 0; fgets(buf, sizeof(buf), infile) && retval < NSCORES;
- retval++) {
- buf[strlen(buf)-1]=0;
- buf2 = strtok(buf, " ");
- (*scores)[retval] = atof(buf2);
- buf2 = strtok(NULL, " ");
- (*scoretimes)[retval] = atoi(buf2);
- buf2 = strtok(NULL, "\n");
- (*names)[retval] = strdup(buf2);
- }
+ *names = g_malloc((NSCORES + 1) * sizeof(gchar*));
+ *scores = g_malloc((NSCORES + 1) * sizeof(gfloat));
+ *scoretimes = g_malloc((NSCORES + 1) * sizeof(time_t));
+
+ for(retval = 0;
+ fgets(buf, sizeof(buf), infile) && retval < NSCORES;
+ retval++)
+ {
+ buf[strlen(buf)-1]=0;
+ buf2 = strtok(buf, " ");
+ (*scores)[retval] = atof(buf2);
+ buf2 = strtok(NULL, " ");
+ (*scoretimes)[retval] = atoi(buf2);
+ buf2 = strtok(NULL, "\n");
+ (*names)[retval] = g_strdup(buf2);
+ }
+ (*names)[retval] = NULL;
+ (*scores)[retval] = 0.0;
fclose(infile);
}
else
@@ -88,7 +98,5 @@ gnome_score_get_notable(gchar *gamename,
retval = 0;
}
- g_free(realname);
-
return retval;
}
diff --git a/libgnome/gnome-score.h b/libgnome/gnome-score.h
index f4bcd4d..13ed84d 100644
--- a/libgnome/gnome-score.h
+++ b/libgnome/gnome-score.h
@@ -4,11 +4,15 @@
#include <time.h>
BEGIN_GNOME_DECLS
-gboolean /* Returns the position in the top-ten starting from 1, or 0 if it isn't
- in the table */
-gnome_score_log(gfloat score,
- gchar *level,
- int ordering);
+/* Returns the position in the top-ten starting from 1, or 0 if it isn't in the table */
+gint
+gnome_score_log(gfloat score,
+ gchar *level, /* Pass in NULL unless you want to keep
+ per-level scores for the game */
+ /* Pass in TRUE if higher scores are "better"
+ in the game */
+ gboolean higher_to_lower_score_order);
+
gint /* Returns number of items in the arrays */
gnome_score_get_notable(gchar *gamename, /* Will be auto-determined if NULL */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]