Index: apps/plugins/superdom.c =================================================================== --- apps/plugins/superdom.c (revision 14152) +++ apps/plugins/superdom.c (working copy) @@ -132,6 +132,7 @@ void draw_cursor(void); int calc_strength(bool colour, int x, int y); void draw_board(void); +void yield_to_rb(void); struct tile{ signed int colour; /* -1 = Unset */ @@ -475,6 +476,13 @@ rb->lcd_update(); } +void yield_to_rb(void) { + if (*rb->current_tick + (5*HZ)/100 > *rb->current_tick) + rb->sleep (*rb->current_tick + (5*HZ)/100 - *rb->current_tick); + else + rb->yield (); +} + void gen_resources(void) { gen_interest(); int inccash = 0; @@ -1601,7 +1609,7 @@ board[cursor.x][cursor.y].plane = 0; board[cursor.x][cursor.y].nuke = 0; draw_board(); - rb->sleep(HZ*2); + yield_to_rb(); humanres.moves--; } else if(calc_strength(COLOUR_LIGHT, cursor.x, cursor.y)== calc_strength(COLOUR_DARK, cursor.x, cursor.y)) { @@ -1612,7 +1620,7 @@ board[cursor.x][cursor.y].plane = 0; board[cursor.x][cursor.y].nuke = 0; draw_board(); - rb->sleep(HZ*2); + yield_to_rb(); humanres.moves--; } else { rb->splash(HZ, "Your troops were unable to" @@ -1854,7 +1862,7 @@ compres.tanks++; compres.cash -= 300; draw_board(); - rb->sleep(HZ); + yield_to_rb(); } } } @@ -1878,7 +1886,7 @@ compres.tanks++; compres.cash -= 300; draw_board(); - rb->sleep(HZ); + yield_to_rb(); } } else { men_needed = (calc_strength(COLOUR_LIGHT, targets[i].x, @@ -1897,7 +1905,7 @@ compres.cash = 0; } draw_board(); - rb->sleep(HZ); + yield_to_rb(); } } } @@ -1925,13 +1933,13 @@ compres.cash -= men_needed; compres.men += men_needed; draw_board(); - rb->sleep(HZ); + yield_to_rb(); } else { board[threats[i].x][threats[i].y].men += compres.cash; compres.men += compres.cash; compres.cash = 0; draw_board(); - rb->sleep(HZ); + yield_to_rb(); } } } else if((total_str_diff+20)*15 < compres.cash) { @@ -1953,7 +1961,7 @@ board[threats[i].x][threats[i].y].men += men_needed; draw_board(); - rb->sleep(HZ); + yield_to_rb(); } } } else { @@ -1962,7 +1970,7 @@ compres.cash -= 600; compres.planes++; draw_board(); - rb->sleep(HZ); + yield_to_rb(); } } } @@ -1986,7 +1994,7 @@ board[threats[i].x][threats[i].y].men += men_needed; draw_board(); - rb->sleep(HZ); + yield_to_rb(); } } } else { @@ -1995,7 +2003,7 @@ compres.tanks++; compres.cash -= 300; draw_board(); - rb->sleep(HZ); + yield_to_rb(); } } } @@ -2058,7 +2066,7 @@ humanres.men -= board[adj.x][adj.y].men; board[adj.x][adj.y].men = 0; draw_board(); - rb->sleep(HZ); + yield_to_rb(); compres.moves--; } else { rb->splash(HZ*2, "The computer attempted" @@ -2076,7 +2084,7 @@ humanres.men -= board[adj.x][adj.y].men; board[adj.x][adj.y].men = 0; draw_board(); - rb->sleep(HZ); + yield_to_rb(); compres.moves--; } } @@ -2101,7 +2109,7 @@ board[i][j].nuke = false; board[i][j].men = 0; draw_board(); - rb->sleep(HZ); + yield_to_rb(); compres.moves--; } else { rb->splash(HZ*2, "The computer attempted to " @@ -2116,7 +2124,7 @@ board[i][j].nuke = false; board[i][j].men = 0; draw_board(); - rb->sleep(HZ); + yield_to_rb(); compres.moves--; } } @@ -2139,7 +2147,7 @@ board[i][j].nuke = false; board[i][j].men = 0; draw_board(); - rb->sleep(HZ); + yield_to_rb(); compres.moves--; } else { rb->splash(HZ*2, "The computer attempted to" @@ -2154,7 +2162,7 @@ board[i][j].nuke = false; board[i][j].men = 0; draw_board(); - rb->sleep(HZ); + yield_to_rb(); compres.moves--; } }