refraction part 4
authorReto Zingg <g.d0b3rm4n@gmail.com>
Fri, 25 Dec 2009 22:55:51 +0000 (00:55 +0200)
committerReto Zingg <g.d0b3rm4n@gmail.com>
Fri, 25 Dec 2009 22:55:51 +0000 (00:55 +0200)
src/launcher/mancala-launcher.c
src/play.c

index 9bdf039..9c9624c 100644 (file)
@@ -17,10 +17,21 @@ char *argh[] = { "/usr/games/wrapper/wrapper",
 
 int main(int argc, char *argv[])
 {
-    fprintf(stderr, "mancala launcher...\n");
+    
+    FILE *pFile;
+    
+    pFile = fopen ("/home/rzingg/mancala.debug", "a");
+    if (pFile) {
+        fprintf (pFile, "app launched...\n");
+        fclose (pFile);
+    }
     
     if (execv ("/usr/games/wrapper/wrapper", argh) == -1) {
-        fprintf(stderr, "can not execute wrapper\n");
+        pFile = fopen ("/home/rzingg/mancala.debug", "a");
+        if (pFile) {
+            fprintf (pFile, "cannot execute wrapper...\n");
+            fclose (pFile);
+        }
     }
 
     return 0;
index 51b88a9..cca9800 100644 (file)
@@ -47,6 +47,16 @@ Mix_Chunk *pick = NULL;
 // the hildon-game-wrapper context
 HgwContext *hgw_context = NULL;
 
+// void rmz_debug (char *msg){
+//     FILE *pFile;
+//     
+//     pFile = fopen ("/home/rzingg/mancala.debug", "a");
+//     if (pFile) {
+//         fprintf (pFile, "rmz_debug: %s \n", msg);
+//         fclose (pFile);
+//     }
+// }
+
 void sdl_clean_up(){
         
         int i = 0;
@@ -70,12 +80,13 @@ void sdl_clean_up(){
 }
 
 int play() {
-        
+//         rmz_debug("play step 1");
         SDL_Rect board_rect, title_rect, exit_rect;
         SDL_Color font_color;
         SDL_Event event;
         SDL_Color font_color_exit;
         
+//         rmz_debug("play step 2");
         char tile_path[STRING_MAX], stone_path[STRING_MAX];
         char icon_path[STRING_MAX], title_path[STRING_MAX];
         char home_path[STRING_MAX], board_path[STRING_MAX];
@@ -84,11 +95,13 @@ int play() {
         int i, redraw_board, highlight, old_highlight, active;
         int current_move, ai_last_move, human_last_move, state;
         
+//         rmz_debug("play step 3");
         /* Set up the game board and game variables. */
         gameInit(aiBoard, humanBoard);
         current_move = 0;
         ai_last_move = human_last_move = -99;
         
+//         rmz_debug("play step 4");
         /* initialize our libraries */
         //if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO) < 0) {
        if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
@@ -98,6 +111,7 @@ int play() {
                         return 1;
        }
        
+//        rmz_debug("play step 5");
        if (TTF_Init() < 0) {
                fprintf(stderr, "Unable to initialize SDL_ttf: %s\n", 
                         SDL_GetError());
@@ -105,17 +119,19 @@ int play() {
                         return 1;
        }
        
+//        rmz_debug("play step 6");
        //Initialize SDL_mixer 
-       
        if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ) 
+       // if( Mix_OpenAudio(22050, (Uint16)AUDIO_U8, 2, 256 ) == -1 )
        {
+//            rmz_debug(g_strdup_printf("Unable to initialize Mix_OpenAudio: %s\n",SDL_GetError()));
                fprintf(stderr, "Unable to initialize Mix_OpenAudio: %s\n",
                         SDL_GetError());
                         sdl_clean_up();
                         return 1;
        }
        
-       
+//        rmz_debug("play step 7");
        /* Load our images... PNGs now, maybe XPMs later */
        sprintf(tile_path, "%s/tile.png", RES_PATH);
        if ((tile = LoadRes(tile_path)) == NULL) {
@@ -125,6 +141,7 @@ int play() {
                         return 1;
        }
        
+//        rmz_debug("play step 8");
        for (i=0; i<=STONE_MAX; i++) {
                if (sprintf(stone_path, "%s/stone%02d.png", RES_PATH, i) == 0)
                        fprintf(stderr, "Problems assembling path.\n");
@@ -136,6 +153,7 @@ int play() {
                }
        }
        
+//        rmz_debug("play step 9");
        /* Load our font(s) */
        if (sprintf(title_path, "%s/luxisr.ttf", FONT_PATH) == 0)
                fprintf(stderr, "Problems assembling path.\n");
@@ -145,6 +163,7 @@ int play() {
                return 1;
        }
        
+//        rmz_debug("play step 10");
        if (sprintf(board_path, "%s/luxisr.ttf", FONT_PATH) == 0)
                fprintf(stderr, "Problems assembling path.\n");
        if (!(board_font = TTF_OpenFont(board_path, BOARD_SIZE))) {
@@ -153,6 +172,7 @@ int play() {
                return 1;
        }
        
+//        rmz_debug("play step 11");
        if (sprintf(home_path, "%s/luxisr.ttf", FONT_PATH) == 0)
                fprintf(stderr, "Problems assembling path.\n");
        if (!(home_font = TTF_OpenFont(home_path, HOME_SIZE))) {
@@ -161,6 +181,7 @@ int play() {
                return 1;
        }
        
+//        rmz_debug("play step 12");
        /* Load sound effects */ 
        sprintf(pick_path, "%s/pick.wav", RES_PATH); 
        if ((pick = Mix_LoadWAV(pick_path)) == NULL) { 
@@ -170,6 +191,7 @@ int play() {
                         return 1; 
        }
        
+//        rmz_debug("play step 13");
        /* store the font's color */
        font_color.r = 255;
        font_color.b = 255;
@@ -189,6 +211,7 @@ int play() {
        board_rect.w = 0;
        board_rect.h = 0;
        
+//        rmz_debug("play step 14");
        /* set window properties and create it */
        SDL_WM_SetCaption("Mancala", "Mancala");
        if (sprintf(icon_path, "%s/icon.png", RES_PATH) == 0)
@@ -201,15 +224,16 @@ int play() {
                         sdl_clean_up();
                         return 1;
        }
+       SDL_ShowCursor(SDL_DISABLE);
        
-       
+//        rmz_debug("play step 15");
        /* define the font color fot the exit text */
        font_color_exit.r = 255;
        font_color_exit.r = 255;
        font_color_exit.r = 255;
        
        
-       
+//        rmz_debug("play step 16");
        if (!(exit_text = TTF_RenderText_Blended(home_font, "EXIT", 
              font_color_exit))) {
                      fprintf(stderr, "SDL_ttf: %s\n", TTF_GetError());
@@ -229,6 +253,7 @@ int play() {
        highlight = 0;
        active = 0;
        
+//        rmz_debug("play step 17");
        /* GAME LOOP */
        while (state != GAME_WON) {
                
@@ -388,10 +413,13 @@ int play() {
                                           redraw_board = 0;
                }
                
+               hgw_msg_compat_receive(hgw_context, 0);
+               
        }
        
        SDL_Delay(DELAY_AI);
        
+       
        sdl_clean_up();
        return 0;
        
@@ -399,25 +427,29 @@ int play() {
 
 
 int main(int argc, char **argv) {
-    
-    fprintf(stderr, "mancala main loop\n");
+
 //     #if HGW_FUNC
     hgw_context = hgw_context_compat_init(argc, argv);
     if (!hgw_context) {
         fprintf(stderr, "Cannot init hildon-games-startup!\n");
         return 0;
     }
+    
     hgw_compat_set_cb_exit(hgw_context, exit_callback);
     hgw_compat_set_cb_quit(hgw_context, quit_callback);
-    hgw_compat_set_cb_flush(hgw_context, flush_callback);
+    hgw_compat_set_cb_flush(hgw_context, flush_callback);    
     if(!hgw_context_compat_check(hgw_context)) return 0;
-    
+
     /* hildon-games-wrapper part */
     hgw_msg_compat_receive(hgw_context, 0);
     usleep(100);
 //     #endif
+
     // Main game
-    play();
+    
+    if ( play() > 0 ){
+//         rmz_debug("play > 1");
+    }
     
 //     #if HGW_FUNC
     hgw_context_compat_destroy_deinit(hgw_context);