refraction part 5 refraction-works
authorReto Zingg <g.d0b3rm4n@gmail.com>
Sat, 26 Dec 2009 12:42:19 +0000 (14:42 +0200)
committerReto Zingg <g.d0b3rm4n@gmail.com>
Sat, 26 Dec 2009 12:42:19 +0000 (14:42 +0200)
debian/control
src/callbacks.c
src/play.c

index 813e783..b1b10f9 100644 (file)
@@ -9,7 +9,7 @@ Homepage: http://mancala.garage.maemo.org/
 Package: mancala
 Architecture: any
 Section: user/games
-Depends: ${shlibs:Depends}, ${misc:Depends}, osso-games-startup
+Depends: ${shlibs:Depends}, ${misc:Depends}, osso-games-startup, hildon-games-wrapper0
 Description: Mancala, the ancient African game of skill!
  Maemo version of mancala from http://cmancala.sourceforge.net/
  Please file bugs here for this maemo version:
index 70215ed..3b38a9b 100644 (file)
@@ -38,7 +38,7 @@ int exit_callback(int errcode) {
 //             fwrite(car, sizeof(struct CAR), cars, han);
 //             fclose(han);
 //     }
-    fprintf(stderr, "exit_callback called...\n");
+    fprintf("exit_callback called...\n");
 
        return 0;
 }
@@ -46,13 +46,13 @@ int exit_callback(int errcode) {
 // Quit game
 int quit_callback(int errcode) {
 //     remove("/tmp/.crazyparking-save");
-    fprintf(stderr, "quit_callback called...\n");
+    fprintf("quit_callback called...\n");
        hgw_context_compat_destroy_quit(hgw_context);
        return 0;
 }
 
 int flush_callback(int errcode) {
 //     remove("/tmp/.crazyparking-save");
-    fprintf(stderr, "quit_callback called...\n");
+    fprintf("quit_callback called...\n");
        return 0;
 }
index cca9800..fc81a95 100644 (file)
@@ -29,6 +29,7 @@
 #include "SDL.h"
 #include "SDL_image.h"
 #include "SDL_ttf.h"
+#include "SDL_getenv.h"
 
 #include "graphics.h"
 #include "mancala.h"
@@ -47,6 +48,12 @@ Mix_Chunk *pick = NULL;
 // the hildon-game-wrapper context
 HgwContext *hgw_context = NULL;
 
+// for debugging, example:
+
+// rmz_debug(g_strdup_printf("play step 2: SDL_AUDIODRIVER: %s",
+//                            my_sdl_audiodrv)
+//                          );
+
 // void rmz_debug (char *msg){
 //     FILE *pFile;
 //     
@@ -80,13 +87,17 @@ void sdl_clean_up(){
 }
 
 int play() {
-//         rmz_debug("play step 1");
+
+// Scratchbox needs different SDL_AudiDriver env
+        #if __i386__
+        putenv("SDL_AUDIODRIVER=alsa") ;
+        #endif /* __i386__ */
+        
         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];
@@ -95,13 +106,11 @@ 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) {
@@ -111,7 +120,6 @@ int play() {
                         return 1;
        }
        
-//        rmz_debug("play step 5");
        if (TTF_Init() < 0) {
                fprintf(stderr, "Unable to initialize SDL_ttf: %s\n", 
                         SDL_GetError());
@@ -119,19 +127,16 @@ 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) {
@@ -141,7 +146,6 @@ 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");
@@ -153,7 +157,6 @@ 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");
@@ -163,7 +166,6 @@ 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))) {
@@ -172,7 +174,6 @@ 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))) {
@@ -181,7 +182,6 @@ 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) { 
@@ -191,7 +191,6 @@ int play() {
                         return 1; 
        }
        
-//        rmz_debug("play step 13");
        /* store the font's color */
        font_color.r = 255;
        font_color.b = 255;
@@ -211,7 +210,6 @@ 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)
@@ -226,14 +224,11 @@ int play() {
        }
        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());
@@ -253,7 +248,6 @@ int play() {
        highlight = 0;
        active = 0;
        
-//        rmz_debug("play step 17");
        /* GAME LOOP */
        while (state != GAME_WON) {
                
@@ -428,7 +422,6 @@ int play() {
 
 int main(int argc, char **argv) {
 
-//     #if HGW_FUNC
     hgw_context = hgw_context_compat_init(argc, argv);
     if (!hgw_context) {
         fprintf(stderr, "Cannot init hildon-games-startup!\n");
@@ -443,17 +436,12 @@ int main(int argc, char **argv) {
     /* 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);
-//     #endif
+    hgw_context_destroy(hgw_context);
     
     return 0;
 }