*/
#include <hildon/hildon.h>
+#include <hgw/hgw.h>
+#include <unistd.h>
#include "SDL_mixer.h"
#include "SDL.h"
#include "SDL_image.h"
#include "SDL_ttf.h"
+#include "SDL_getenv.h"
#include "graphics.h"
#include "mancala.h"
#include "sounds.h"
#include "play.h"
+#include "callbacks.h"
+
// the surfaces
SDL_Surface *screen, *board, *title_text, *tile, *stone[STONE_MAX+1], *exit_text;
// the fonts
TTF_Font *title_font, *home_font, *board_font;
// The sound effects that will be used
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;
+//
+// pFile = fopen ("/home/rzingg/mancala.debug", "a");
+// if (pFile) {
+// fprintf (pFile, "rmz_debug: %s \n", msg);
+// fclose (pFile);
+// }
+// }
void sdl_clean_up(){
}
int play() {
+
+ // 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;
/* initialize our libraries */
//if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO) < 0) {
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
- fprintf(stderr, "Unable to initialize SDL: %s\n",
+ printf("Unable to initialize SDL: %s\n",
SDL_GetError());
sdl_clean_up();
return 1;
}
if (TTF_Init() < 0) {
- fprintf(stderr, "Unable to initialize SDL_ttf: %s\n",
+ printf("Unable to initialize SDL_ttf: %s\n",
SDL_GetError());
sdl_clean_up();
return 1;
}
//Initialize SDL_mixer
-
if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 )
+ // if( Mix_OpenAudio(22050, (Uint16)AUDIO_U8, 2, 256 ) == -1 )
{
- fprintf(stderr, "Unable to initialize Mix_OpenAudio: %s\n",
+ printf("Unable to initialize Mix_OpenAudio: %s\n",
SDL_GetError());
sdl_clean_up();
return 1;
}
-
/* Load our images... PNGs now, maybe XPMs later */
sprintf(tile_path, "%s/tile.png", RES_PATH);
if ((tile = LoadRes(tile_path)) == NULL) {
- fprintf(stderr, "Unable to load resource: %s\n",
+ printf("Unable to load resource: %s\n",
SDL_GetError());
sdl_clean_up();
return 1;
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");
+ printf("Problems assembling path.\n");
if (!(stone[i] = LoadRes(stone_path))) {
- fprintf(stderr, "Unable to load resource: %s\n",
+ printf("Unable to load resource: %s\n",
SDL_GetError());
sdl_clean_up();
return 1;
/* Load our font(s) */
if (sprintf(title_path, "%s/luxisr.ttf", FONT_PATH) == 0)
- fprintf(stderr, "Problems assembling path.\n");
+ printf("Problems assembling path.\n");
if (!(title_font = TTF_OpenFont(title_path, TITLE_SIZE))) {
- fprintf(stderr, "Could not load font: %s\n", TTF_GetError());
+ printf("Could not load font: %s\n", TTF_GetError());
sdl_clean_up();
return 1;
}
if (sprintf(board_path, "%s/luxisr.ttf", FONT_PATH) == 0)
- fprintf(stderr, "Problems assembling path.\n");
+ printf("Problems assembling path.\n");
if (!(board_font = TTF_OpenFont(board_path, BOARD_SIZE))) {
- fprintf(stderr, "Could not load font: %s\n", TTF_GetError());
+ printf("Could not load font: %s\n", TTF_GetError());
sdl_clean_up();
return 1;
}
if (sprintf(home_path, "%s/luxisr.ttf", FONT_PATH) == 0)
- fprintf(stderr, "Problems assembling path.\n");
+ printf("Problems assembling path.\n");
if (!(home_font = TTF_OpenFont(home_path, HOME_SIZE))) {
- fprintf(stderr, "Could not load font: %s\n", TTF_GetError());
+ printf("Could not load font: %s\n", TTF_GetError());
sdl_clean_up();
return 1;
}
/* Load sound effects */
sprintf(pick_path, "%s/pick.wav", RES_PATH);
if ((pick = Mix_LoadWAV(pick_path)) == NULL) {
- fprintf(stderr, "Unable to load sound: %s\n",
+ printf("Unable to load sound: %s\n",
SDL_GetError());
sdl_clean_up();
return 1;
/* set window properties and create it */
SDL_WM_SetCaption("Mancala", "Mancala");
if (sprintf(icon_path, "%s/icon.png", RES_PATH) == 0)
- fprintf(stderr, "Problems assembling icon path.\n");
+ printf("Problems assembling icon path.\n");
SDL_WM_SetIcon(LoadRes(icon_path), NULL);
if ((screen = SDL_SetVideoMode(tile->w*8, (tile->h*2) + Y_OFFSET, 16, SDL_FULLSCREEN))
== NULL) {
- fprintf(stderr, "Unable to set %dx%d video: %s", tile->w*8,
+ printf("Unable to set %dx%d video: %s", tile->w*8,
tile->h*2, SDL_GetError());
sdl_clean_up();
return 1;
}
-
+ SDL_ShowCursor(SDL_DISABLE);
/* define the font color fot the exit text */
font_color_exit.r = 255;
font_color_exit.r = 255;
font_color_exit.r = 255;
-
-
if (!(exit_text = TTF_RenderText_Blended(home_font, "EXIT",
font_color_exit))) {
- fprintf(stderr, "SDL_ttf: %s\n", TTF_GetError());
+ printf("SDL_ttf: %s\n", TTF_GetError());
return 1;
}
while (SDL_PollEvent(&event)) {
/* BAIL OUT! BAIL OUT! */
if (event.type == SDL_KEYDOWN){
- fprintf(stderr, "event SDL_KEYDOWN found....\n");
+ printf("event SDL_KEYDOWN found....\n");
if ( event.key.keysym.sym == SDLK_q )
{
- fprintf(stderr, "event SDLK_q found....\n");
+ printf("event SDLK_q found....\n");
SDL_Event quit_event;
quit_event.type = SDL_QUIT;
SDL_PushEvent(&quit_event);
if (event.type == SDL_MOUSEBUTTONDOWN) {
if ((event.button.button = 1) &&
(event.button.y < Y_OFFSET)) {
- fprintf(stderr, "clicked out side the board in exit area...\n");
+ printf("clicked out side the board in exit area...\n");
SDL_Event quit_event;
quit_event.type = SDL_QUIT;
SDL_PushEvent(&quit_event);
}
if (event.type == SDL_QUIT) {
- fprintf(stderr, "event SDL_QUIT found....\n");
+ printf("event SDL_QUIT found....\n");
sdl_clean_up();
return 0;
}
// pitch 0 and 7 are the homebases which you can't play
if ( pitch == 0 || pitch == 7 ){
- fprintf(stderr, "clicked out side the board...\n");
+ printf("clicked out side the board...\n");
}
else{
current_move = pitch;
if (aiBoard[0] > humanBoard[0]) {
if (!(title_text = TTF_RenderText_Blended(title_font,
"Computer Wins!", font_color)))
- fprintf(stderr, "TTF: %s\n", TTF_GetError());
+ printf("TTF: %s\n", TTF_GetError());
}
else {
if (!(title_text = TTF_RenderText_Blended(title_font,
"Human Wins!", font_color)))
- fprintf(stderr, "TTF: %s\n", TTF_GetError());
+ printf("TTF: %s\n", TTF_GetError());
}
redraw_board = 1;
break;
home_font, tile, stone, active,
highlight);
if (!board) {
- fprintf(stderr, "Could not draw the board.\n");
+ printf("Could not draw the board.\n");
}
else {
// board_rect = SurfaceToRect(board);
redraw_board = 0;
}
+ hgw_msg_compat_receive(hgw_context, 0);
+
}
SDL_Delay(DELAY_AI);
+
sdl_clean_up();
return 0;
}
+
+int main(int argc, char **argv) {
+
+ hgw_context = hgw_context_compat_init(argc, argv);
+ if (!hgw_context) {
+ printf("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);
+ if(!hgw_context_compat_check(hgw_context)) return 0;
+
+ /* hildon-games-wrapper part */
+ hgw_msg_compat_receive(hgw_context, 0);
+ usleep(100);
+
+ // Main game
+ play();
+
+ // hgw_context_compat_destroy_deinit(hgw_context);
+ // hgw_context_compat_destroy_quit(hgw_context);
+ hgw_context_destroy(hgw_context);
+
+ return 0;
+}
+