X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=putt%2Fmain.c;h=2b08ba7b8861082b2bfb2adbb673d942db8af56d;hb=a863f290379543d092c9aafb5eb4d06080a567d8;hp=47ebd126918f3d132ffea05b21789e66ae660b06;hpb=1b21d301645c4f7af414a3140b7a6422710ee9cc;p=neverball diff --git a/putt/main.c b/putt/main.c index 47ebd12..2b08ba7 100644 --- a/putt/main.c +++ b/putt/main.c @@ -15,9 +15,6 @@ /*---------------------------------------------------------------------------*/ #include -#include -#include -#include #include #include #include @@ -33,6 +30,8 @@ #include "hole.h" #include "game.h" #include "gui.h" +#include "text.h" +#include "syswm.h" #include "st_conf.h" #include "st_all.h" @@ -44,15 +43,12 @@ static int shot(void) { static char filename[MAXSTR]; - static int num = 0; - sprintf(filename, "screen%02d.png", num++); - - image_snap(filename); + sprintf(filename, "screen%05d.png", config_screenshot()); + image_snap(config_user(filename)); return 1; } - /*---------------------------------------------------------------------------*/ static void toggle_wire(void) @@ -80,6 +76,7 @@ static int loop(void) { SDL_Event e; int d = 1; + int c; while (d && SDL_PollEvent(&e)) { @@ -104,24 +101,87 @@ static int loop(void) break; case SDL_KEYDOWN: - switch (e.key.keysym.sym) + + c = e.key.keysym.sym; + + if (config_tst_d(CONFIG_KEY_FORWARD, c)) + st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), -JOY_MAX); + + else if (config_tst_d(CONFIG_KEY_BACKWARD, c)) + st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), +JOY_MAX); + + else if (config_tst_d(CONFIG_KEY_LEFT, c)) + st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), -JOY_MAX); + + else if (config_tst_d(CONFIG_KEY_RIGHT, c)) + st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), +JOY_MAX); + + else switch (c) { case SDLK_F10: d = shot(); break; case SDLK_F9: config_tgl_d(CONFIG_FPS); break; case SDLK_F8: config_tgl_d(CONFIG_NICE); break; case SDLK_F7: toggle_wire(); break; + case SDLK_RETURN: + d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1); + break; + case SDLK_ESCAPE: + d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 1); + break; + default: d = st_keybd(e.key.keysym.sym, 1); } break; + case SDL_KEYUP: + + c = e.key.keysym.sym; + + /* gui_stick needs a non-null value, so we use 1 instead of 0. */ + + if (config_tst_d(CONFIG_KEY_FORWARD, c)) + st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1); + + else if (config_tst_d(CONFIG_KEY_BACKWARD, c)) + st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1); + + else if (config_tst_d(CONFIG_KEY_LEFT, c)) + st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1); + + else if (config_tst_d(CONFIG_KEY_RIGHT, c)) + st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1); + + else switch (c) + { + case SDLK_RETURN: + d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 0); + break; + case SDLK_ESCAPE: + d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 0); + break; + + default: + d = st_keybd(e.key.keysym.sym, 0); + } + case SDL_ACTIVEEVENT: if (e.active.state == SDL_APPINPUTFOCUS) - { - if (e.active.gain == 0) + if (e.active.gain == 0 && config_get_grab()) goto_pause(&st_over, 0); - } + break; + + case SDL_JOYAXISMOTION: + st_stick(e.jaxis.axis, e.jaxis.value); + break; + + case SDL_JOYBUTTONDOWN: + d = st_buttn(e.jbutton.button, 1); + break; + + case SDL_JOYBUTTONUP: + d = st_buttn(e.jbutton.button, 0); break; } } @@ -131,7 +191,7 @@ static int loop(void) int main(int argc, char *argv[]) { int camera = 0; - SDL_Surface *icon; + SDL_Joystick *joy = NULL; srand((int) time(NULL)); @@ -141,7 +201,7 @@ int main(int argc, char *argv[]) { if (config_user_path(NULL)) { - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == 0) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == 0) { config_init(); config_load(); @@ -150,24 +210,19 @@ int main(int argc, char *argv[]) camera = config_get_d(CONFIG_CAMERA); - /* Initialize the audio. */ + /* Initialize the joystick. */ - audio_bind(AUD_BIRDIE, 1, "snd/birdie.ogg"); - audio_bind(AUD_BOGEY, 1, "snd/bogey.ogg"); - audio_bind(AUD_BUMP, 1, "snd/bink.wav"); - audio_bind(AUD_DOUBLE, 1, "snd/double.ogg"); - audio_bind(AUD_EAGLE, 1, "snd/eagle.ogg"); - audio_bind(AUD_JUMP, 2, "snd/jump.ogg"); - audio_bind(AUD_MENU, 2, "snd/menu.wav"); - audio_bind(AUD_ONE, 1, "snd/one.ogg"); - audio_bind(AUD_PAR, 1, "snd/par.ogg"); - audio_bind(AUD_PENALTY, 1, "snd/penalty.ogg"); - audio_bind(AUD_PLAYER1, 1, "snd/player1.ogg"); - audio_bind(AUD_PLAYER2, 1, "snd/player2.ogg"); - audio_bind(AUD_PLAYER3, 1, "snd/player3.ogg"); - audio_bind(AUD_PLAYER4, 1, "snd/player4.ogg"); - audio_bind(AUD_SWITCH, 2, "snd/switch.wav"); - audio_bind(AUD_SUCCESS, 1, "snd/success.ogg"); + if (SDL_NumJoysticks() > 0) + { + joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE)); + if (joy) + { + SDL_JoystickEventState(SDL_ENABLE); + set_joystick(joy); + } + } + + /* Initialize the audio. */ audio_init(); @@ -179,15 +234,9 @@ int main(int argc, char *argv[]) SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); -#ifndef __APPLE__ - icon = IMG_Load(config_data("icon/neverputt.png")); + /* This has to happen before mode setting... */ - if (icon) - { - SDL_WM_SetIcon(icon, NULL); - SDL_FreeSurface(icon); - } -#endif /* __APPLE__ */ + set_SDL_icon("icon/neverputt.png"); /* Initialize the video. */ @@ -197,6 +246,10 @@ int main(int argc, char *argv[]) { int t1, t0 = SDL_GetTicks(); + /* ... and this has to happen after it. */ + + set_EWMH_icon("icon/neverputt.png"); + SDL_WM_SetCaption(TITLE, TITLE); /* Run the main game loop. */ @@ -208,7 +261,7 @@ int main(int argc, char *argv[]) if ((t1 = SDL_GetTicks()) > t0) { st_timer((t1 - t0) / 1000.f); - st_paint(); + st_paint(0.001f * t1); SDL_GL_SwapBuffers(); t0 = t1; @@ -228,9 +281,9 @@ int main(int argc, char *argv[]) } else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError()); } - else fprintf(stderr, _("Failure to establish config directory\n")); + else fprintf(stderr, L_("Failure to establish config directory\n")); } - else fprintf(stderr, _("Failure to establish game data directory\n")); + else fprintf(stderr, L_("Failure to establish game data directory\n")); return 0; }