|
From: <des...@us...> - 2004-02-24 18:48:24
|
Update of /cvsroot/copter/copter/src/system In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18927/system Added Files: system.cpp system.hpp Log Message: - added System::System class --- NEW FILE: system.cpp --- // Copter! - SimCopter clone and more // Copyright (C) 2004 by the Copter! Team // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <SDL.h> #include "system.hpp" namespace Copter { namespace System { System::System() {} System::~System() { quit(); } bool System::init() { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTTHREAD)) return false; return true; } bool System::was_init() { return (SDL_WasInit(SDL_INIT_VIDEO) && SDL_WasInit(SDL_INIT_TIMER)); } bool System::init_video(int width, int height, int depth, bool full_screen) { int sdl_video_flags = SDL_OPENGL | SDL_DOUBLEBUF; if (full_screen) sdl_video_flags |= SDL_FULLSCREEN; if (!SDL_SetVideoMode(width, height, depth, sdl_video_flags)) return false; return true; } bool System::poll_event(Event& event) { SDL_Event sdl_event; if (!SDL_PollEvent(&sdl_event)) return false; switch (sdl_event.type) { case SDL_KEYDOWN: event.key.type = EVENT_KEY; event.key.key = sdl_event.key.keysym.sym; event.key.state = KEY_PRESS; break; case SDL_KEYUP: event.key.type = EVENT_KEY; event.key.key = sdl_event.key.keysym.sym; event.key.state = KEY_RELEASE; break; default:; } return true; } void System::quit() { SDL_Quit(); } } // namespace System } // namespace Copter --- NEW FILE: system.hpp --- // Copter! - SimCopter clone and more // Copyright (C) 2004 by the Copter! Team // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef COPTER_SYSTEM_SYSTEM_HPP #define COPTER_SYSTEM_SYSTEM_HPP namespace Copter { namespace System { typedef enum { EVENT_KEY } EventType; typedef int KeyEventKey; typedef enum { KEY_PRESS, KEY_RELEASE } KeyEventState; typedef struct { EventType type; KeyEventKey key; KeyEventState state; } KeyEvent; typedef union { EventType type; KeyEvent key; } Event; class System { public: System(); ~System(); bool init(); bool was_init(); bool init_video(int width, int height, int depth, bool full_screen); bool poll_event(Event& event); void quit(); }; } // namespace System } // namespace Copter #endif |