void kernel_shell_start() { printk("Starting LevOS debug shell...\n"); shell_tty = get_tty(0); while (1) { show_prompt(); char *in = grab_input(); parse_input(in); } }
int main(int argc, char *argv[]) { if (argc < 2) { printf("Usage: %s EVDEV\n", argv[0]); return EXIT_SUCCESS; } if (grab_input(argv[1])) return EXIT_FAILURE; return EXIT_SUCCESS; }
int main (int argc, char **argv) { char user_input[USER_INPUT_BUFFER_MAX]; proper_exec_name (argv[0]); greet (); while (true) { display_prompt (); grab_input (user_input); process_input (user_input); } return EXIT_SUCCESS; }
/* switch client to new state */ void set_state( int newstate ) { if ( client_state == newstate ) return; if ( newstate == CS_PLAY ) grab_input( 1 ); if ( client_state == CS_PLAY ) grab_input( 0 ); if ( client_state == CS_CONFIRM_WARP || client_state == CS_CONFIRM_RESTART || client_state == CS_CONFIRM_QUIT || client_state == CS_CONFIRM_CONTINUE || client_state == CS_GET_READY || client_state == CS_PAUSE || client_state == CS_FINAL_PLAYER_INFO || client_state == CS_GET_READY_FOR_NEXT_LEVEL || client_state == CS_RECV_LEVEL || client_state == CS_ROUND_RESULT || client_state == CS_RECV_STATS || client_state == CS_FATAL_ERROR ) { /* show offscreen */ if ( offscreen ) { stk_surface_blit( offscreen, 0,0,-1,-1, stk_display, 0,0 ); end_frame(); } /* do not refresh when coming from RECV_LEVEL as a GET_READY * will follow */ if ( client_state != CS_RECV_LEVEL ) if ( client_state != CS_ROUND_RESULT ) if ( client_state != CS_RECV_STATS ); stk_display_update( STK_UPDATE_ALL ); } client_state = newstate; stk_timer_reset(); }
/* modify the client and its state according to the key pressed */ static int handle_default_key( int key, int *abort ) { SDL_Surface *buffer; switch ( key ) { case SDLK_F1: case SDLK_h: if ( client_state != CS_PLAY ) break; if ( game->game_type == GT_NETWORK ) break; /* only for single player */ grab_input(0); help_run(); grab_input(1); return 1; case SDLK_q: case SDLK_ESCAPE: /* recv_stats or final_stats means we already broke up * the game so ESC will directly quit */ if ( client_state == CS_RECV_STATS || client_state == CS_FINAL_STATS ) { *abort = 1; break; } if ( client_state == CS_CONFIRM_QUIT ) break; if ( client_state == CS_PAUSE ) break; if ( players_count() == 0 ) break; set_state(CS_CONFIRM_QUIT); if ( game->game_type == GT_LOCAL && game_set != 0 /*not testing a level*/ ) display_text( font, "Quit Game? y/n#(If yes, this game may be resumed later.#No highscore entry is created yet.)" ); else display_text( font, "Quit Game? y/n" ); return 1; case SDLK_r: if ( client_state != CS_PLAY ) break; if ( game->game_type == GT_NETWORK ) break; /* only for single player */ if ( game_set == 0 ) break; /* test level */ if ( cur_player->lives < 2 ) break; set_state(CS_CONFIRM_RESTART); display_text( font, "Restart Level? y/n" ); return 1; case SDLK_d: if ( client_state != CS_PLAY ) break; if ( game->game_type == GT_NETWORK ) break; /* only for single player */ if ( !allow_disintegrate ) break; if ( game->level_type != LT_NORMAL ) break; /* not in bonus levels */ grab_input(0); game_nuke(); grab_input(1); return 1; case SDLK_f: buffer = stk_surface_create( SDL_SWSURFACE, 640, 480 ); SDL_BlitSurface( stk_display, 0, buffer, 0 ); config.fullscreen = !config.fullscreen; stk_display_apply_fullscreen( config.fullscreen ); SDL_BlitSurface( buffer, 0, stk_display, 0 ); stk_display_update( STK_UPDATE_ALL); SDL_FreeSurface( buffer ); return 1; case SDLK_s: #ifdef AUDIO_ENABLED config.sound = !config.sound; stk_audio_enable_sound( config.sound ); #endif return 1; case SDLK_a: config.anim++; if ( config.anim >= 4 ) config.anim = 0; return 1; case SDLK_TAB: stk_display_take_screenshot(); return 1; case SDLK_t: return 0; case SDLK_p: if ( client_state == CS_PLAY ) client_set_pause(1); else if (client_state==CS_PAUSE) client_set_pause(0); return 1; default: if ( client_state != CS_PLAY ) break; if ( game->game_type != GT_LOCAL ) break; if ( game->bricks_left > game->warp_limit ) break; if ( game_set == 0 ) break; /* test level */ if ( game->level_type != LT_NORMAL ) break; /* not in bonus levels */ if ( key == config.k_warp ) { set_state(CS_CONFIRM_WARP); display_text( font, "Warp to next level? y/n" ); return 1; } break; } return 0; }
/* run the state driven loop until game is broken up or finished */ void client_game_run( void ) { int ms, frame_delay = config.fps?10:1; int button_clicked, key_pressed; SDL_Event event; int abort = 0, i, j, penalty; /* frame rate */ int frames = 0; int frame_time = SDL_GetTicks(); event_clear_sdl_queue(); stk_display_fade( STK_FADE_IN, STK_FADE_DEFAULT_TIME ); stats_received = 0; stk_timer_reset(); ms = 1; while ( !abort && !stk_quit_request ) { /* check wether an event occured */ button_clicked = key_pressed = 0; if ( SDL_PollEvent( &event ) ) { if ( client_state == CS_PAUSE && game->game_type == GT_NETWORK ) gui_dispatch_event( &event, ms ); else if ( event.type == SDL_MOUSEBUTTONDOWN ) button_clicked = event.button.button; else if ( event.type == SDL_KEYDOWN ) { key_pressed = event.key.keysym.sym; if ( handle_default_key( key_pressed, &abort ) ) key_pressed = 0; } else if (event.type == SDL_ACTIVEEVENT) { if (event.active.state == SDL_APPINPUTFOCUS || event.active.state == SDL_APPACTIVE ) if (event.active.gain == 0 ) client_set_pause(1); } } else if ( client_state == CS_PAUSE && game->game_type == GT_NETWORK ) gui_dispatch_event( 0, ms ); /* check whether Shift is pressed to switch between own and highest score */ if (game->game_type == GT_LOCAL) handle_display_switch(); /* let server know we're still alive except * in CS_PLAY as we send paddle updates there */ if ( game->game_type == GT_NETWORK ) comm_send_heartbeat(); /* handle client */ switch ( client_state ) { case CS_FINAL_STATS: if ( key_pressed==SDLK_SPACE ) abort = 1; break; case CS_FATAL_ERROR: /* after game was violently broken up the server * may still send the stats of the game so far */ if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ set_state( CS_RECV_STATS ); display_text( font, "Receiving final stats..." ); } break; case CS_FINAL_TABLE: if ( button_clicked || key_pressed ) { check_highscores(); select_chart( game_set->name, 0 ); /* remove saved game */ slot_delete( 0 ); slot_update_hint( 0, item_resume_0->hint ); /* quit local game */ abort = 1; } break; case CS_SCORE_TABLE: /* show who's next player and scores in local game */ display_score_table( "Next Player: %s", cur_player->name ); set_state( CS_GET_READY ); break; case CS_BONUS_LEVEL_SCORE: /* display total score from this level for player */ display_bonus_level_score(); set_state( CS_GET_READY_FOR_NEXT_LEVEL ); break; case CS_FINAL_PLAYER_INFO: if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ set_state( CS_NEXT_PLAYER ); } break; case CS_RECV_LEVEL: comm_recv(); if ( cur_player->next_level_received ) { cur_player->next_level_received = 0; cur_player->paddle_id = cur_player->next_paddle_id; init_next_round(); } break; case CS_RECV_STATS: comm_recv(); if ( stats_received ) { set_state( CS_FINAL_STATS ); display_final_stats(); } break; case CS_ROUND_RESULT: if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ if ( game_over ) { set_state( CS_RECV_STATS ); display_text( font, "Receiving final stats..." ); } else { set_state( CS_RECV_LEVEL ); display_text( font, "Receiving level data..." ); } } break; case CS_GET_READY: if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ comm_send_short( MSG_READY ); set_state( CS_PLAY ); } break; case CS_GET_READY_FOR_NEXT_LEVEL: if ( button_clicked || key_pressed ) { SDL_Delay(250); /* give time to release button */ set_state( CS_NEXT_LEVEL ); } break; case CS_PAUSE: if ( game->game_type == GT_LOCAL ) break; /* check wether pause chatroom has been closed * either by client or remote */ comm_recv(); break; case CS_PLAY: /* hide objects */ begin_frame(); /* apply events to local paddle */ paddle_handle_events( l_paddle, ms ); /* update local objects and communicate if * comm_delay ms have passed */ update_game( ms ); /* show objects */ end_frame(); /* handle local level over */ if ( game->level_over ) { if ( game->game_type == GT_LOCAL ) { if ( game_set == 0 ) { abort = 1; /* was a test level */ grab_input(0); break; } if ( game->winner == PADDLE_BOTTOM ) { if (local_game->isBonusLevel) set_state( CS_BONUS_LEVEL_SCORE ); else set_state( CS_NEXT_LEVEL ); } else set_state( CS_LOOSE_LIFE ); } else { finalize_round(); } } break; case CS_NEXT_LEVEL: /* apply paddle stats to player */ game_set_current( local_game ); game_update_stats( PADDLE_BOTTOM, &cur_player->stats ); game_set_current( game ); /* init next level for player in local game */ cur_player->level_id++; if ( cur_player->level_id >= game_set->count ) { /* deactivate player */ cur_player->lives = 0; display_text( font, "You've cleared all levels...#Congratulations!!!" ); set_state( CS_FINAL_PLAYER_INFO ); break; } /* get snapshot for next init */ cur_player->snapshot = *game_set->levels[cur_player->level_id]; /* cycle players */ set_state( CS_NEXT_PLAYER ); break; case CS_RESTART_LEVEL: /* apply paddle stats to player */ game_set_current( local_game ); game_update_stats( PADDLE_BOTTOM, &cur_player->stats ); game_set_current( game ); /* reset level for next turn */ cur_player->snapshot = *game_set->levels[cur_player->level_id]; /* decrease lives (is checked that this wasn't the last one) */ cur_player->lives--; /* cycle players */ set_state( CS_NEXT_PLAYER ); break; case CS_LOOSE_LIFE: /* apply paddle stats to player */ game_set_current( local_game ); game_update_stats( PADDLE_BOTTOM, &cur_player->stats ); game_set_current( game ); /* remember level for next turn */ game_get_level_snapshot( &cur_player->snapshot ); /* decrease lives */ cur_player->lives--; if ( cur_player->lives == 0 ) { display_text( font, "You've lost all lives...#Do you want to buy a continue#for 100%% of your score? y/n" ); set_state( CS_CONFIRM_CONTINUE ); //set_state( CS_FINAL_PLAYER_INFO ); break; } set_state( CS_NEXT_PLAYER ); break; case CS_NEXT_PLAYER: /* game over? */ if ( players_count() == 0 ) { display_score_table( "Game Over!" ); set_state( CS_FINAL_TABLE ); break; } /* speak and fade */ play_speech(); fade_anims(); /* finalize current game context */ finalize_level(); /* set next player */ cur_player = players_get_next(); init_level( cur_player, PADDLE_BOTTOM ); if ( player_count > 1 ) set_state( CS_SCORE_TABLE ); else { set_state( CS_PLAY ); /* one player starts immediately */ stk_display_update( STK_UPDATE_ALL ); } break; case CS_CONFIRM_CONTINUE: case CS_CONFIRM_QUIT: case CS_CONFIRM_WARP: case CS_CONFIRM_RESTART: if ( key_pressed == 0 ) break; if ( key_pressed==SDLK_n||key_pressed==SDLK_ESCAPE ) { /* if denying continue... DIE!!! */ if ( client_state == CS_CONFIRM_CONTINUE ) { SDL_Delay(250); /* give time to release button */ set_state( CS_NEXT_PLAYER ); //set_state( CS_FINAL_PLAYER_INFO ); } else set_state( CS_PLAY ); break; } if ( key_pressed != SDLK_y && key_pressed != SDLK_z ) break; /* handle confirmed action */ SDL_Delay(250); /* give time to release button */ switch( client_state ) { case CS_CONFIRM_CONTINUE: /* clear score and give full lives again */ cur_player->lives = game->diff->lives; cur_player->stats.total_score = 0; set_state( CS_NEXT_PLAYER ); break; case CS_CONFIRM_QUIT: comm_send_short( MSG_QUIT_GAME ); if ( game->game_type == GT_LOCAL ) { /* apply paddle stats to player */ game_set_current( local_game ); game_update_stats( PADDLE_BOTTOM, &cur_player->stats ); game_set_current( game ); /* no higscore check anymore as game is supposed to * be resumed until normal game over */ /* testing levels don't got for * high scores *** if ( game_set ) { check_highscores(); select_chart( game_set->name, 0 ); }*/ /* save local game */ if ( game_set != 0 /*not testing a level*/ ) save_local_game( 0 ); abort = 1; } else { /* await game stats */ set_state( CS_RECV_STATS ); display_text( font, "Receiving final stats..." ); } break; case CS_CONFIRM_WARP: game->winner = -1; /* no speech */ local_game->winner = -1; /* not counted as win */ /* substract doubled score of remaining bricks */ penalty = 0; for ( i = 0; i < MAP_WIDTH; i++ ) for ( j = 0; j < MAP_HEIGHT; j++ ) if ( local_game->bricks[i][j].dur != -1 ) penalty += local_game->bricks[i][j].score; printf( "warp penalty: -%d\n", penalty ); local_game->paddles[0]->score -= penalty; set_state( CS_NEXT_LEVEL ); break; case CS_CONFIRM_RESTART: game->winner = -1; /* no speech */ local_game->winner = -1; /* not counted as win */ local_game->level_over = 1; set_state( CS_RESTART_LEVEL ); break; } break; } /* update anything that was changed */ stk_display_update( STK_UPDATE_RECTS ); /* get time since last call and delay if below frame_delay */ ms = stk_timer_get_time(); if ( ms < frame_delay ) { SDL_Delay( frame_delay - ms ); ms += stk_timer_get_time(); } frames++; } finalize_level(); client_state = CLIENT_NONE; stk_display_fade( STK_FADE_OUT, STK_FADE_DEFAULT_TIME ); if ( stk_quit_request ) comm_send_short( MSG_DISCONNECT ); else comm_send_short( MSG_UNHIDE ); /* frame rate */ frame_time = SDL_GetTicks() - frame_time; printf( "Time: %.2f, Frames: %i -> FPS: %.2f\n", (double)frame_time / 1000, frames, 1000.0*frames/frame_time ); event_clear_sdl_queue(); /* update the selected user and the user list in network as * we received ADD/REMOVE_USER messages */ gui_list_update( list_users, client_users->count ); /* re-select current entry */ if ( client_user ) { i = list_check( client_users, client_user ); if ( i != -1 ) gui_list_select( list_users, 0, i, 1 ); } }