Remove gp2x-specific code from trunk.

This commit is contained in:
Karol Nowak 2007-02-18 01:09:16 +00:00
parent f3aca1ad07
commit 971198b79e
8 changed files with 1 additions and 379 deletions

View File

@ -21,7 +21,6 @@
#include "display.hpp"
#include "events.hpp"
#include "gettext.hpp"
#include "gp2x.hpp"
#include "help.hpp"
#include "hotkeys.hpp"
#include "image.hpp"
@ -611,10 +610,6 @@ int dialog::process(dialog_process_info &info)
int mousex, mousey;
int mouse_flags = SDL_GetMouseState(&mousex,&mousey);
#ifdef GP2X
mouse_flags |= gp2x::get_joystick_state(&mousex, &mousey);
#endif
const bool new_right_button = (mouse_flags&SDL_BUTTON_RMASK) != 0;
const bool new_left_button = (mouse_flags&SDL_BUTTON_LMASK) != 0;
const bool new_key_down = info.key[SDLK_SPACE] || info.key[SDLK_RETURN] ||

View File

@ -16,7 +16,6 @@
#include "clipboard.hpp"
#include "cursor.hpp"
#include "events.hpp"
#include "gp2x.hpp"
#include "log.hpp"
#include "preferences_display.hpp"
#include "sound.hpp"
@ -269,10 +268,6 @@ void pump()
static int last_mouse_down = -1;
static int last_click_x = -1, last_click_y = -1;
#ifdef GP2X
gp2x::makeup_events();
#endif
SDL_Event event;
while(SDL_PollEvent(&event)) {
@ -313,13 +308,6 @@ void pump()
break;
}
#ifdef GP2X
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
gp2x::handle_joystick(reinterpret_cast<SDL_JoyButtonEvent *>(&event));
break;
#endif
case SDL_MOUSEMOTION: {
//always make sure a cursor is displayed if the
//mouse moves or if the user clicks

View File

@ -27,7 +27,6 @@
#include "game_errors.hpp"
#include "gamestatus.hpp"
#include "gettext.hpp"
#include "gp2x.hpp"
#include "help.hpp"
#include "hotkeys.hpp"
#include "intro.hpp"
@ -1904,15 +1903,6 @@ int main(int argc, char** argv)
}
#endif
#ifdef GP2X
atexit(gp2x::return_to_menu);
if(gp2x::init_joystick() < 0) {
fprintf(stderr, "Couldn't initialize joystick: %s\n", SDL_GetError());
return 1;
}
#endif
try {
std::cerr << "Battle for Wesnoth v" << VERSION << "\n";
time_t t = time(NULL);
@ -1941,13 +1931,6 @@ int main(int argc, char** argv)
std::cerr << "Ran out of memory. Aborted.\n";
}
#ifdef GP2X
// We want this in gp2x so that users don't have to power-cycle
// their consoles on unhandled exception
catch(...) {
std::cerr << "Unhandled exception. Exiting\n";
}
#endif
filesystem_close();
return 0;

View File

@ -36,7 +36,7 @@ namespace game_config
int lobby_refresh = 2000;
const std::string version = VERSION;
bool debug = false, editor = false, ignore_replay_errors = false, mp_debug = false, exit_at_end = false, no_delay = false, disable_autosave = false;
std::string game_icon = "wesnoth-icon.png", game_title, game_logo, title_music, anonymous_music,
victory_music, defeat_music;
int title_logo_x = 0, title_logo_y = 0, title_buttons_x = 0, title_buttons_y = 0, title_buttons_padding = 0,

View File

@ -1,298 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2006 by Karol Nowak <grzywacz@sul.uni.lodz.pl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifdef GP2X
#include <iostream>
#include <unistd.h> // for chdir() and execl()
#include "SDL.h"
#include "gp2x.hpp"
#include "preferences.hpp"
#include "util.hpp"
namespace gp2x {
namespace {
/*
* GP2X joystick mapping from gp2x wiki
*/
#define GP2X_BUTTON_UP (0)
#define GP2X_BUTTON_DOWN (4)
#define GP2X_BUTTON_LEFT (2)
#define GP2X_BUTTON_RIGHT (6)
#define GP2X_BUTTON_UPLEFT (1)
#define GP2X_BUTTON_UPRIGHT (7)
#define GP2X_BUTTON_DOWNLEFT (3)
#define GP2X_BUTTON_DOWNRIGHT (5)
#define GP2X_BUTTON_CLICK (18)
#define GP2X_BUTTON_A (12)
#define GP2X_BUTTON_B (13)
#define GP2X_BUTTON_X (14)
#define GP2X_BUTTON_Y (15)
#define GP2X_BUTTON_L (10)
#define GP2X_BUTTON_R (11)
#define GP2X_BUTTON_START (8)
#define GP2X_BUTTON_SELECT (9)
#define GP2X_BUTTON_VOLUP (16)
#define GP2X_BUTTON_VOLDOWN (17)
enum MouseDirection {
UP = 1 << 0,
DOWN = 1 << 1,
LEFT = 1 << 2,
RIGHT = 1 << 3,
DOWNLEFT = DOWN | LEFT,
DOWNRIGHT = DOWN | RIGHT,
UPLEFT = UP | LEFT,
UPRIGHT = UP | RIGHT
};
/**
* Current mouse position, valid only with emulated mouse
*/
struct mousepos {
unsigned int x;
unsigned int y;
} mouse_position_;
/**
* Initialisaed joystick
*/
SDL_Joystick *joystick_;
void movemouse(MouseDirection dir)
{
#define MOTION_SPEED (4)
if(dir & UP) {
mouse_position_.y -= MOTION_SPEED;
mouse_position_.y = maximum<int>(mouse_position_.y, 0);
}
if(dir & DOWN) {
mouse_position_.y += MOTION_SPEED;
mouse_position_.y = minimum<int>(mouse_position_.y, 240 - 1); // FIXME
}
if(dir & LEFT) {
mouse_position_.x -= MOTION_SPEED;
mouse_position_.x = maximum<int>(mouse_position_.x, 0);
}
if(dir & RIGHT) {
mouse_position_.x += MOTION_SPEED;
mouse_position_.x = minimum<int>(mouse_position_.x, 320 - 1); // FIXME
}
/*
* Move mouse cursor and generate MOUSEMOTION event
*/
SDL_WarpMouse(mouse_position_.x, mouse_position_.y);
}
void handle_joybutton(int button, bool down)
{
static SDL_KeyboardEvent keyevent;
static SDL_MouseButtonEvent mouseevent;
if(button == GP2X_BUTTON_VOLDOWN && down) {
preferences::set_music_volume( maximum<int>(preferences::music_volume() - 10, 0) );
preferences::set_sound_volume( maximum<int>(preferences::sound_volume() - 10, 0) );
preferences::set_bell_volume( maximum<int>(preferences::bell_volume() - 10, 0) );
}
else if(button == GP2X_BUTTON_VOLUP && down) {
preferences::set_music_volume(minimum<int>(preferences::music_volume() + 10, 100));
preferences::set_sound_volume(minimum<int>(preferences::sound_volume() + 10, 100));
preferences::set_bell_volume(minimum<int>(preferences::bell_volume() + 10, 100));
}
else if(button == GP2X_BUTTON_A || button == GP2X_BUTTON_B) {
if(down) {
mouseevent.type = SDL_MOUSEBUTTONDOWN;
mouseevent.state = SDL_PRESSED;
} else {
mouseevent.type = SDL_MOUSEBUTTONUP;
mouseevent.state = SDL_RELEASED;
}
mouseevent.button = (button == GP2X_BUTTON_A ? SDL_BUTTON_LEFT : SDL_BUTTON_RIGHT);
mouseevent.x = mouse_position_.x;
mouseevent.y = mouse_position_.y;
SDL_PushEvent( (SDL_Event *) &mouseevent);
}
else {
keyevent.which = 0;
if(down) {
keyevent.type = SDL_KEYDOWN;
keyevent.state = SDL_PRESSED;
} else {
keyevent.type = SDL_KEYUP;
keyevent.state = SDL_RELEASED;
}
switch(button) {
case GP2X_BUTTON_R:
keyevent.keysym.sym = SDLK_n; // this is a default hotkey for "next unit"
keyevent.keysym.unicode = 'n'; // ???
keyevent.keysym.mod = KMOD_NONE;
break;
case GP2X_BUTTON_L:
keyevent.keysym.sym = SDLK_n; // this is a default hotkey for "previous unit"
keyevent.keysym.unicode = 'N'; // ???
keyevent.keysym.mod = KMOD_LSHIFT;
break;
case GP2X_BUTTON_X:
keyevent.keysym.sym = SDLK_l; // this is a default hotkey for "go to leader"
keyevent.keysym.unicode = 'l'; // ???
keyevent.keysym.mod = KMOD_NONE;
break;
case GP2X_BUTTON_Y:
keyevent.keysym.sym = SDLK_v; // this is a default hotkey for "show enemy moves"
keyevent.keysym.unicode = 'v'; // ???
keyevent.keysym.mod = KMOD_LCTRL;
break;
case GP2X_BUTTON_CLICK:
keyevent.keysym.sym = SDLK_u; // this is a default hotkey for "undo"
keyevent.keysym.unicode = 'u'; // ???
keyevent.keysym.mod = KMOD_NONE;
break;
case GP2X_BUTTON_START:
keyevent.keysym.sym = SDLK_a; // this is a default hotkey for "accelerated"
keyevent.keysym.unicode = 'a'; // ???
keyevent.keysym.mod = KMOD_LCTRL;
break;
case GP2X_BUTTON_SELECT:
keyevent.keysym.sym = SDLK_r; // this is a default hotkey for "recruit"
keyevent.keysym.unicode = 'r'; // ???
keyevent.keysym.mod = KMOD_LCTRL;
break;
default:
return; // huh?
}
SDL_PushEvent((SDL_Event *) &keyevent);
}
}
} // namespace $$
int init_joystick()
{
std::cerr << "Initializing joystick...\n";
if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) >= 0) {
if((joystick_ = SDL_JoystickOpen(0)) != NULL)
return 0;
}
return -1;
}
void handle_joystick(SDL_JoyButtonEvent *ev)
{
SDL_JoyButtonEvent e = *ev;
bool down = (e.type == SDL_JOYBUTTONDOWN ? true : false);
if(e.button == GP2X_BUTTON_UP && down)
movemouse(UP);
else if(e.button == GP2X_BUTTON_DOWN && down)
movemouse(DOWN);
else if(e.button == GP2X_BUTTON_LEFT && down)
movemouse(LEFT);
else if(e.button == GP2X_BUTTON_RIGHT && down)
movemouse(RIGHT);
else if(e.button == GP2X_BUTTON_UPLEFT && down)
movemouse(UPLEFT);
else if(e.button == GP2X_BUTTON_DOWNLEFT && down)
movemouse(DOWNLEFT);
else if(e.button == GP2X_BUTTON_UPRIGHT && down)
movemouse(UPRIGHT);
else if(e.button == GP2X_BUTTON_DOWNRIGHT && down)
movemouse(DOWNRIGHT);
else
handle_joybutton(e.button, down);
}
// We try to emulate SDL_GetMouseState() here
Uint8 get_joystick_state(int *x, int *y)
{
Uint8 result = 0;
if(x)
*x = mouse_position_.x;
if(y)
*y = mouse_position_.y;
if(SDL_JoystickGetButton(joystick_, GP2X_BUTTON_A) == SDL_PRESSED)
result |= SDL_BUTTON_LEFT;
if(SDL_JoystickGetButton(joystick_, GP2X_BUTTON_B) == SDL_PRESSED)
result |= SDL_BUTTON_RIGHT;
return result;
}
/**
* Pushes mouse motion events into the queue when joystick directional
* buttons are pressed
*/
void makeup_events()
{
static Uint32 last_time;
Uint32 time = SDL_GetTicks();
if(time - last_time >= 50) {
last_time = time;
if(SDL_JoystickGetButton(joystick_, GP2X_BUTTON_LEFT) == SDL_PRESSED)
movemouse(LEFT);
else if(SDL_JoystickGetButton(joystick_, GP2X_BUTTON_RIGHT) == SDL_PRESSED)
movemouse(RIGHT);
else if(SDL_JoystickGetButton(joystick_, GP2X_BUTTON_UP) == SDL_PRESSED)
movemouse(UP);
else if(SDL_JoystickGetButton(joystick_, GP2X_BUTTON_DOWN) == SDL_PRESSED)
movemouse(DOWN);
else if(SDL_JoystickGetButton(joystick_, GP2X_BUTTON_UPLEFT) == SDL_PRESSED)
movemouse(UPLEFT);
else if(SDL_JoystickGetButton(joystick_, GP2X_BUTTON_UPRIGHT) == SDL_PRESSED)
movemouse(UPRIGHT);
else if(SDL_JoystickGetButton(joystick_, GP2X_BUTTON_DOWNLEFT) == SDL_PRESSED)
movemouse(DOWNLEFT);
else if(SDL_JoystickGetButton(joystick_, GP2X_BUTTON_DOWNRIGHT) == SDL_PRESSED)
movemouse(DOWNRIGHT);
}
}
/**
* Return to gp2x menu
*/
void return_to_menu()
{
chdir("/usr/gp2x");
execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", 0);
}
} // namespace gp2x
#endif
/* vim: set ts=4 sw=4: */

View File

@ -1,35 +0,0 @@
/* $Id$ */
/*
Copyright (C) 2003-6 by David White <davidnwhite@verizon.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifdef GP2X
#ifndef GP2X_HPP_INCLUDED
#define GP2X_HPP_INCLUDED
#include "SDL.h"
namespace gp2x {
int init_joystick();
void handle_joystick(SDL_JoyButtonEvent *);
void makeup_events();
Uint8 get_joystick_state(int *x, int *y);
void return_to_menu();
}
#endif
#endif
/* vim: set ts=4 sw=4: */

View File

@ -15,7 +15,6 @@
#include "dialogs.hpp"
#include "config_adapter.hpp"
#include "gettext.hpp"
#include "gp2x.hpp"
#include "log.hpp"
#include "replay.hpp"
#include "sound.hpp"
@ -664,13 +663,7 @@ void play_controller::play_slice()
}
int mousex, mousey;
#ifdef GP2X
gp2x::get_joystick_state(&mousex, &mousey);
#else
SDL_GetMouseState(&mousex,&mousey);
#endif
tooltips::process(mousex, mousey);
const int scroll_threshold = (preferences::mouse_scroll_enabled()) ? 5 : 0;

View File

@ -223,8 +223,6 @@ size_t sound_buffer_size()
//but this seems to cause crashes on other systems...
#ifdef WIN32
const size_t buf_size = 4096;
#elif GP2X
const size_t buf_size = 512;
#else
const size_t buf_size = 1024;
#endif
@ -236,8 +234,6 @@ void save_sound_buffer_size(const size_t size)
{
#ifdef WIN32
const char* buf_size = "4096";
#elif GP2X
const char* buf_size = "512";
#else
const char* buf_size = "1024";
#endif