diff options
Diffstat (limited to 'apps/plugins/lib/highscore.c')
-rw-r--r-- | apps/plugins/lib/highscore.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/apps/plugins/lib/highscore.c b/apps/plugins/lib/highscore.c index 9fbcdf25a3..df7a71bcdf 100644 --- a/apps/plugins/lib/highscore.c +++ b/apps/plugins/lib/highscore.c | |||
@@ -61,11 +61,12 @@ int highscore_load(char *filename, struct highscore *scores, int num_scores) | |||
61 | char *ptr; | 61 | char *ptr; |
62 | 62 | ||
63 | fd = rb->open(filename, O_RDONLY); | 63 | fd = rb->open(filename, O_RDONLY); |
64 | |||
65 | rb->memset(scores, 0, sizeof(struct highscore)*(num_scores+1)); | ||
66 | |||
64 | if(fd < 0) | 67 | if(fd < 0) |
65 | return -1; | 68 | return -1; |
66 | 69 | ||
67 | rb->memset(scores, 0, sizeof(struct highscore)*num_scores); | ||
68 | |||
69 | i = -1; | 70 | i = -1; |
70 | while(rb->read_line(fd, buf, sizeof(buf)-1) && i < num_scores) | 71 | while(rb->read_line(fd, buf, sizeof(buf)-1) && i < num_scores) |
71 | { | 72 | { |
@@ -97,3 +98,31 @@ int highscore_load(char *filename, struct highscore *scores, int num_scores) | |||
97 | } | 98 | } |
98 | return 0; | 99 | return 0; |
99 | } | 100 | } |
101 | |||
102 | int highscore_update(int score, int level, struct highscore *scores, int num_scores) | ||
103 | { | ||
104 | int i, j; | ||
105 | int new = 0; | ||
106 | |||
107 | /* look through the scores and see if this one is in the top ones */ | ||
108 | for(i = num_scores-1;i >= 0; i--) | ||
109 | { | ||
110 | if ((score > scores[i].score)) | ||
111 | { | ||
112 | /* Move the rest down one... */ | ||
113 | if (i > 0) | ||
114 | { | ||
115 | for (j=1; j<=i; j++) | ||
116 | { | ||
117 | rb->memcpy((void *)&scores[j-1], (void *)&scores[j], sizeof(struct highscore)); | ||
118 | } | ||
119 | } | ||
120 | scores[i].score = score; | ||
121 | scores[i].level = level; | ||
122 | /* Need to sort out entering a name... maybe old three letter arcade style */ | ||
123 | new = 1; | ||
124 | break; | ||
125 | } | ||
126 | } | ||
127 | return new; | ||
128 | } | ||