forked from len0rd/rockbox
Save some more space by not allocating arrays large enough to hold more than NUM_BOGUS (defined at compile-time) elements.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15029 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
2b2c536895
commit
59f523ce66
1 changed files with 32 additions and 29 deletions
|
@ -152,18 +152,22 @@ static void play_game(void);
|
||||||
static void process_input(int);
|
static void process_input(int);
|
||||||
|
|
||||||
/*Helper functions*/
|
/*Helper functions*/
|
||||||
|
static void pause(void);
|
||||||
static int validchar(char);
|
static int validchar(char);
|
||||||
|
|
||||||
static void play_animation(int);
|
static void play_animation(int);
|
||||||
|
|
||||||
/*Global variables. Bite me, it's fun.*/
|
/*Global variables. Bite me, it's fun.*/
|
||||||
screen_object robot;
|
screen_object robot;
|
||||||
screen_object kitten;
|
screen_object kitten;
|
||||||
|
|
||||||
int num_bogus;
|
#if X_MAX*Y_MAX < 200
|
||||||
screen_object bogus[MESSAGES];
|
#define NUM_BOGUS 15
|
||||||
int bogus_messages[MESSAGES];
|
#else
|
||||||
int used_messages[MESSAGES];
|
#define NUM_BOGUS 20
|
||||||
|
#endif
|
||||||
|
screen_object bogus[NUM_BOGUS];
|
||||||
|
unsigned short bogus_messages[NUM_BOGUS];
|
||||||
|
bool used_messages[MESSAGES];
|
||||||
|
|
||||||
bool exit_rfk;
|
bool exit_rfk;
|
||||||
|
|
||||||
|
@ -263,9 +267,6 @@ static void play_game()
|
||||||
*/
|
*/
|
||||||
static void process_input(int input)
|
static void process_input(int input)
|
||||||
{
|
{
|
||||||
#ifdef __PLUGINLIB_ACTIONS_H__
|
|
||||||
const struct button_mapping *plugin_contexts[] = {generic_directions, generic_actions};
|
|
||||||
#endif
|
|
||||||
int check_x = robot.x;
|
int check_x = robot.x;
|
||||||
int check_y = robot.y;
|
int check_y = robot.y;
|
||||||
|
|
||||||
|
@ -313,12 +314,7 @@ static void process_input(int input)
|
||||||
case KITTEN: /*Found it!*/
|
case KITTEN: /*Found it!*/
|
||||||
play_animation(input);
|
play_animation(input);
|
||||||
/* Wait for the user to click something */
|
/* Wait for the user to click something */
|
||||||
rb->button_clear_queue();
|
pause();
|
||||||
#ifdef __PLUGINLIB_ACTIONS_H__
|
|
||||||
input = pluginlib_getaction(rb, TIMEOUT_BLOCK, plugin_contexts, 2);
|
|
||||||
#else
|
|
||||||
input = rb->button_get(true);
|
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
default: /*We hit a bogus object; print its message.*/
|
default: /*We hit a bogus object; print its message.*/
|
||||||
message(messages[bogus_messages[screen[check_x][check_y]-2]]);
|
message(messages[bogus_messages[screen[check_x][check_y]-2]]);
|
||||||
|
@ -346,6 +342,16 @@ static void finish(int sig)
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
static void pause()
|
||||||
|
{
|
||||||
|
int button;
|
||||||
|
rb->lcd_update();
|
||||||
|
do
|
||||||
|
button = rb->button_get(true);
|
||||||
|
while( ( button == BUTTON_NONE )
|
||||||
|
|| ( button & (BUTTON_REL|BUTTON_REPEAT) ) );
|
||||||
|
}
|
||||||
|
|
||||||
static int validchar(char a)
|
static int validchar(char a)
|
||||||
{
|
{
|
||||||
switch(a)
|
switch(a)
|
||||||
|
@ -460,7 +466,10 @@ static void initialize_arrays()
|
||||||
/*Initialize the other arrays.*/
|
/*Initialize the other arrays.*/
|
||||||
for (counter = 0; counter < MESSAGES; counter++)
|
for (counter = 0; counter < MESSAGES; counter++)
|
||||||
{
|
{
|
||||||
used_messages[counter] = 0;
|
used_messages[counter] = false;
|
||||||
|
}
|
||||||
|
for (counter = 0; counter < NUM_BOGUS; counter++)
|
||||||
|
{
|
||||||
bogus_messages[counter] = 0;
|
bogus_messages[counter] = 0;
|
||||||
bogus[counter] = empty;
|
bogus[counter] = empty;
|
||||||
}
|
}
|
||||||
|
@ -503,7 +512,7 @@ static void initialize_kitten()
|
||||||
static void initialize_bogus()
|
static void initialize_bogus()
|
||||||
{
|
{
|
||||||
int counter, index;
|
int counter, index;
|
||||||
for (counter = 0; counter < num_bogus; counter++)
|
for (counter = 0; counter < NUM_BOGUS; counter++)
|
||||||
{
|
{
|
||||||
/*Give it a color.*/
|
/*Give it a color.*/
|
||||||
bogus[counter].color = colors[randcolor()];
|
bogus[counter].color = colors[randcolor()];
|
||||||
|
@ -526,9 +535,9 @@ static void initialize_bogus()
|
||||||
/*Find a message for this object.*/
|
/*Find a message for this object.*/
|
||||||
do {
|
do {
|
||||||
index = rb->rand() % MESSAGES;
|
index = rb->rand() % MESSAGES;
|
||||||
} while (used_messages[index] != 0);
|
} while (used_messages[index] != false);
|
||||||
bogus_messages[counter] = index;
|
bogus_messages[counter] = index;
|
||||||
used_messages[index] = 1;
|
used_messages[index] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -566,7 +575,7 @@ static void initialize_screen()
|
||||||
/*
|
/*
|
||||||
*Draw all the objects on the playing field.
|
*Draw all the objects on the playing field.
|
||||||
*/
|
*/
|
||||||
for (counter = 0; counter < num_bogus; counter++)
|
for (counter = 0; counter < NUM_BOGUS; counter++)
|
||||||
{
|
{
|
||||||
draw(bogus[counter]);
|
draw(bogus[counter]);
|
||||||
}
|
}
|
||||||
|
@ -584,12 +593,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
(void)parameter;
|
(void)parameter;
|
||||||
rb = api;
|
rb = api;
|
||||||
|
|
||||||
/* Get a number of non-kitten objects */
|
|
||||||
#if X_MAX*Y_MAX < 200
|
|
||||||
num_bogus = 15;
|
|
||||||
#else
|
|
||||||
num_bogus = 20;
|
|
||||||
#endif
|
|
||||||
exit_rfk = false;
|
exit_rfk = false;
|
||||||
|
|
||||||
rb->srand(*rb->current_tick);
|
rb->srand(*rb->current_tick);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue