2012-06-22 14:31:55 +00:00
|
|
|
// * This file is part of the COLOBOT source code
|
|
|
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
|
|
|
// * Copyright (C) 2012, Polish Portal of Colobot (PPC)
|
|
|
|
// *
|
|
|
|
// * 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 3 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, see http://www.gnu.org/licenses/.
|
|
|
|
|
|
|
|
// app.cpp
|
|
|
|
|
|
|
|
#include "app/app.h"
|
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
#include "app/system.h"
|
2012-07-04 17:56:22 +00:00
|
|
|
#include "common/logger.h"
|
2012-06-25 17:59:17 +00:00
|
|
|
#include "common/iman.h"
|
2012-07-22 20:05:12 +00:00
|
|
|
#include "common/image.h"
|
2012-06-30 23:37:30 +00:00
|
|
|
#include "graphics/opengl/gldevice.h"
|
2012-06-22 14:31:55 +00:00
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
|
|
|
|
#include <SDL/SDL.h>
|
|
|
|
#include <SDL/SDL_image.h>
|
|
|
|
|
2012-06-30 08:16:52 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
template<> CApplication* CSingleton<CApplication>::mInstance = NULL;
|
|
|
|
|
|
|
|
|
2012-06-30 10:26:40 +00:00
|
|
|
//! Interval of timer called to update joystick state
|
|
|
|
const int JOYSTICK_TIMER_INTERVAL = 1000/30;
|
|
|
|
|
|
|
|
//! Function called by the timer
|
|
|
|
Uint32 JoystickTimerCallback(Uint32 interval, void *);
|
|
|
|
|
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
/**
|
2012-06-26 20:50:55 +00:00
|
|
|
* \struct ApplicationPrivate
|
|
|
|
* \brief Private data of CApplication class
|
2012-06-25 17:59:17 +00:00
|
|
|
*
|
|
|
|
* Contains SDL-specific variables that should not be visible outside application module.
|
|
|
|
*/
|
|
|
|
struct ApplicationPrivate
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
//! Display surface
|
|
|
|
SDL_Surface *surface;
|
|
|
|
//! Currently handled event
|
|
|
|
SDL_Event currentEvent;
|
|
|
|
//! Joystick
|
|
|
|
SDL_Joystick *joystick;
|
|
|
|
//! Index of joystick device
|
2012-06-29 22:12:04 +00:00
|
|
|
int joystickIndex;
|
2012-06-30 10:26:40 +00:00
|
|
|
//! Id of joystick timer
|
|
|
|
SDL_TimerID joystickTimer;
|
2012-06-30 23:37:30 +00:00
|
|
|
//! Current configuration of OpenGL display device
|
|
|
|
Gfx::GLDeviceConfig deviceConfig;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
ApplicationPrivate()
|
|
|
|
{
|
|
|
|
memset(¤tEvent, 0, sizeof(SDL_Event));
|
|
|
|
surface = NULL;
|
|
|
|
joystick = NULL;
|
2012-06-29 22:12:04 +00:00
|
|
|
joystickIndex = 0;
|
2012-06-30 10:26:40 +00:00
|
|
|
joystickTimer = 0;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
2012-06-25 17:59:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-06-30 10:26:40 +00:00
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
CApplication::CApplication()
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
m_private = new ApplicationPrivate();
|
|
|
|
m_exitCode = 0;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
m_iMan = new CInstanceManager();
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
m_eventQueue = new CEventQueue(m_iMan);
|
|
|
|
|
|
|
|
m_engine = NULL;
|
2012-07-01 20:59:22 +00:00
|
|
|
m_device = NULL;
|
2012-06-29 22:12:04 +00:00
|
|
|
m_robotMain = NULL;
|
|
|
|
m_sound = NULL;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
m_keyState = 0;
|
|
|
|
m_axeKey = Math::Vector(0.0f, 0.0f, 0.0f);
|
|
|
|
m_axeJoy = Math::Vector(0.0f, 0.0f, 0.0f);
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
m_active = false;
|
|
|
|
m_activateApp = false;
|
|
|
|
m_ready = false;
|
|
|
|
m_joystickEnabled = false;
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
m_time = 0.0f;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
m_windowTitle = "COLOBOT";
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
m_showStats = false;
|
|
|
|
m_debugMode = false;
|
|
|
|
m_setupMode = true;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
m_dataPath = "./data";
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
ResetKey();
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CApplication::~CApplication()
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
delete m_private;
|
|
|
|
m_private = NULL;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
delete m_eventQueue;
|
|
|
|
m_eventQueue = NULL;
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
delete m_iMan;
|
|
|
|
m_iMan = NULL;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
bool CApplication::ParseArguments(int argc, char *argv[])
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-07-22 20:05:12 +00:00
|
|
|
bool waitDataDir = false;
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
for (int i = 1; i < argc; ++i)
|
|
|
|
{
|
|
|
|
std::string arg = argv[i];
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
if (waitDataDir)
|
|
|
|
{
|
|
|
|
waitDataDir = false;
|
|
|
|
m_dataPath = arg;
|
|
|
|
}
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
if (arg == "-debug")
|
|
|
|
{
|
|
|
|
m_showStats = true;
|
|
|
|
SetDebugMode(true);
|
|
|
|
}
|
2012-07-22 20:05:12 +00:00
|
|
|
else if (arg == "-datadir")
|
|
|
|
{
|
|
|
|
waitDataDir = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_exitCode = 1;
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
// Data dir not given?
|
|
|
|
if (waitDataDir)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CApplication::Create()
|
|
|
|
{
|
2012-07-22 20:05:12 +00:00
|
|
|
// TODO: verify that data directory exists
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
// Temporarily -- only in windowed mode
|
2012-06-30 23:37:30 +00:00
|
|
|
m_private->deviceConfig.fullScreen = false;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-07-01 20:59:22 +00:00
|
|
|
// Create the 3D engine
|
2012-06-29 22:12:04 +00:00
|
|
|
m_engine = new Gfx::CEngine(m_iMan, this);
|
2012-06-25 17:59:17 +00:00
|
|
|
|
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
/* // Create the sound instance.
|
2012-06-26 20:23:05 +00:00
|
|
|
m_sound = new CSound(m_iMan);
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
// Create the robot application.
|
2012-06-29 22:12:04 +00:00
|
|
|
m_robotMain = new CRobotMain(m_iMan); */
|
2012-06-25 17:59:17 +00:00
|
|
|
|
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
|
|
|
|
/* SDL initialization sequence */
|
|
|
|
|
|
|
|
|
2012-06-30 10:26:40 +00:00
|
|
|
Uint32 initFlags = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_TIMER;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
if (SDL_Init(initFlags) < 0)
|
|
|
|
{
|
2012-07-01 20:59:22 +00:00
|
|
|
SystemDialog( SDT_ERROR, "COLOBOT - Error", "SDL initialization error:\n" +
|
|
|
|
std::string(SDL_GetError()) );
|
2012-07-04 17:56:22 +00:00
|
|
|
m_exitCode = 2;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) == 0)
|
|
|
|
{
|
|
|
|
SystemDialog( SDT_ERROR, "COLOBOT - Error", std::string("SDL_Image initialization error:\n") +
|
|
|
|
std::string(IMG_GetError()) );
|
|
|
|
m_exitCode = 3;
|
2012-06-26 20:23:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
|
2012-06-29 22:12:04 +00:00
|
|
|
if (videoInfo == NULL)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-07-01 20:59:22 +00:00
|
|
|
SystemDialog( SDT_ERROR, "COLOBOT - Error", "SDL error while getting video info:\n " +
|
|
|
|
std::string(SDL_GetError()) );
|
2012-07-04 17:56:22 +00:00
|
|
|
m_exitCode = 2;
|
2012-06-26 20:23:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
Uint32 videoFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-30 23:37:30 +00:00
|
|
|
if (m_private->deviceConfig.resizeable)
|
2012-06-26 20:23:05 +00:00
|
|
|
videoFlags |= SDL_RESIZABLE;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
// Use hardware surface if available
|
|
|
|
if (videoInfo->hw_available)
|
|
|
|
videoFlags |= SDL_HWSURFACE;
|
|
|
|
else
|
|
|
|
videoFlags |= SDL_SWSURFACE;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
// Enable hardware blit if available
|
|
|
|
if (videoInfo->blit_hw)
|
|
|
|
videoFlags |= SDL_HWACCEL;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-30 23:37:30 +00:00
|
|
|
if (m_private->deviceConfig.fullScreen)
|
2012-06-26 20:23:05 +00:00
|
|
|
videoFlags |= SDL_FULLSCREEN;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-30 23:37:30 +00:00
|
|
|
// Set OpenGL attributes
|
|
|
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, m_private->deviceConfig.redSize);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, m_private->deviceConfig.greenSize);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, m_private->deviceConfig.blueSize);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, m_private->deviceConfig.alphaSize);
|
|
|
|
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, m_private->deviceConfig.depthSize);
|
|
|
|
|
|
|
|
if (m_private->deviceConfig.doubleBuf)
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-30 23:37:30 +00:00
|
|
|
/* If hardware acceleration specifically requested, this will force the hw accel
|
|
|
|
and fail with error if not available */
|
|
|
|
if (m_private->deviceConfig.hardwareAccel)
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-30 23:37:30 +00:00
|
|
|
m_private->surface = SDL_SetVideoMode(m_private->deviceConfig.width, m_private->deviceConfig.height,
|
|
|
|
m_private->deviceConfig.bpp, videoFlags);
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
if (m_private->surface == NULL)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
SystemDialog( SDT_ERROR, "COLOBT - Error", std::string("SDL error while setting video mode:\n") +
|
|
|
|
std::string(SDL_GetError()) );
|
2012-07-04 17:56:22 +00:00
|
|
|
m_exitCode = 2;
|
2012-06-26 20:23:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
SDL_WM_SetCaption(m_windowTitle.c_str(), m_windowTitle.c_str());
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
// Enable translating key codes of key press events to unicode chars
|
2012-06-26 20:23:05 +00:00
|
|
|
SDL_EnableUNICODE(1);
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-30 10:26:40 +00:00
|
|
|
// Don't generate joystick events
|
|
|
|
SDL_JoystickEventState(SDL_IGNORE);
|
2012-06-25 17:59:17 +00:00
|
|
|
|
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
// For now, enable joystick for testing
|
|
|
|
SetJoystickEnabled(true);
|
2012-06-25 17:59:17 +00:00
|
|
|
|
|
|
|
|
2012-07-01 20:59:22 +00:00
|
|
|
// The video is ready, we can create and initalize the graphics device
|
|
|
|
m_device = new Gfx::CGLDevice();
|
|
|
|
if (! m_device->Create() )
|
|
|
|
{
|
|
|
|
SystemDialog( SDT_ERROR, "COLOBT - Error", std::string("Error in CDevice::Create() :\n") +
|
|
|
|
std::string(m_device->GetError()) );
|
2012-07-04 17:56:22 +00:00
|
|
|
m_exitCode = 1;
|
2012-07-01 20:59:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_engine->SetDevice(m_device);
|
|
|
|
if (! m_engine->Create() )
|
|
|
|
{
|
|
|
|
SystemDialog( SDT_ERROR, "COLOBT - Error", std::string("Error in CEngine::Create() :\n") +
|
|
|
|
std::string(m_engine->GetError()) );
|
2012-07-04 17:56:22 +00:00
|
|
|
m_exitCode = 1;
|
2012-07-01 20:59:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! m_engine->AfterDeviceSetInit() )
|
|
|
|
{
|
|
|
|
SystemDialog( SDT_ERROR, "COLOBT - Error", std::string("Error in CEngine::AfterDeviceSetInit() :\n") +
|
|
|
|
std::string(m_engine->GetError()) );
|
2012-07-04 17:56:22 +00:00
|
|
|
m_exitCode = 1;
|
2012-07-01 20:59:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-06-25 17:59:17 +00:00
|
|
|
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
// The app is ready to go
|
|
|
|
m_ready = true;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
return true;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CApplication::Destroy()
|
|
|
|
{
|
2012-07-01 20:59:22 +00:00
|
|
|
/*if (m_robotMain != NULL)
|
|
|
|
{
|
|
|
|
delete m_robotMain;
|
|
|
|
m_robotMain = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_sound != NULL)
|
|
|
|
{
|
|
|
|
delete m_sound;
|
|
|
|
m_sound = NULL;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
if (m_engine != NULL)
|
|
|
|
{
|
|
|
|
if (m_engine->GetWasInit())
|
|
|
|
m_engine->Destroy();
|
|
|
|
|
|
|
|
delete m_engine;
|
|
|
|
m_engine = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_device != NULL)
|
|
|
|
{
|
|
|
|
if (m_device->GetWasInit())
|
|
|
|
m_device->Destroy();
|
|
|
|
|
|
|
|
delete m_device;
|
|
|
|
m_device = NULL;
|
|
|
|
}
|
2012-06-29 22:12:04 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
if (m_private->joystick != NULL)
|
|
|
|
{
|
|
|
|
SDL_JoystickClose(m_private->joystick);
|
|
|
|
m_private->joystick = NULL;
|
|
|
|
}
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-07-01 20:59:22 +00:00
|
|
|
if (m_private->surface != NULL)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(m_private->surface);
|
|
|
|
m_private->surface = NULL;
|
|
|
|
}
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
IMG_Quit();
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
SDL_Quit();
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
bool CApplication::OpenJoystick()
|
|
|
|
{
|
|
|
|
m_private->joystick = SDL_JoystickOpen(m_private->joystickIndex);
|
|
|
|
if (m_private->joystick == NULL)
|
|
|
|
return false;
|
2012-06-30 08:16:52 +00:00
|
|
|
|
2012-06-30 10:26:40 +00:00
|
|
|
// Create the vectors with joystick axis & button states to exactly the required size
|
|
|
|
m_joyAxeState = std::vector<int>(SDL_JoystickNumAxes(m_private->joystick), 0);
|
|
|
|
m_joyButtonState = std::vector<bool>(SDL_JoystickNumButtons(m_private->joystick), false);
|
|
|
|
|
|
|
|
// Create a timer for polling joystick state
|
|
|
|
m_private->joystickTimer = SDL_AddTimer(JOYSTICK_TIMER_INTERVAL, JoystickTimerCallback, NULL);
|
|
|
|
|
2012-06-30 08:16:52 +00:00
|
|
|
return true;
|
2012-06-29 22:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CApplication::CloseJoystick()
|
|
|
|
{
|
2012-06-30 10:26:40 +00:00
|
|
|
// Timer will remove itself automatically
|
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
SDL_JoystickClose(m_private->joystick);
|
2012-06-30 10:26:40 +00:00
|
|
|
m_private->joystick = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Uint32 JoystickTimerCallback(Uint32 interval, void *)
|
|
|
|
{
|
2012-07-22 20:05:12 +00:00
|
|
|
CApplication *app = CApplication::GetInstancePointer();
|
2012-07-01 20:59:22 +00:00
|
|
|
if ((app == NULL) || (! app->GetJoystickEnabled()))
|
2012-06-30 10:26:40 +00:00
|
|
|
return 0; // don't run the timer again
|
|
|
|
|
|
|
|
app->UpdateJoystick();
|
|
|
|
|
|
|
|
return interval; // run for the same interval again
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Updates the state info in CApplication and on change, creates SDL events and pushes them to SDL event queue.
|
|
|
|
This way, the events get handled properly in the main event loop and besides, SDL_PushEvent() ensures thread-safety. */
|
|
|
|
void CApplication::UpdateJoystick()
|
|
|
|
{
|
|
|
|
if (! m_joystickEnabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SDL_JoystickUpdate();
|
|
|
|
|
|
|
|
for (int axis = 0; axis < (int) m_joyAxeState.size(); ++axis)
|
|
|
|
{
|
|
|
|
int newValue = SDL_JoystickGetAxis(m_private->joystick, axis);
|
|
|
|
|
|
|
|
if (m_joyAxeState[axis] != newValue)
|
|
|
|
{
|
|
|
|
m_joyAxeState[axis] = newValue;
|
|
|
|
|
|
|
|
SDL_Event joyAxisEvent;
|
|
|
|
|
|
|
|
joyAxisEvent.jaxis.type = SDL_JOYAXISMOTION;
|
|
|
|
joyAxisEvent.jaxis.which = 0;
|
|
|
|
joyAxisEvent.jaxis.axis = axis;
|
|
|
|
joyAxisEvent.jaxis.value = newValue;
|
|
|
|
|
|
|
|
SDL_PushEvent(&joyAxisEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int button = 0; button < (int) m_joyButtonState.size(); ++button)
|
|
|
|
{
|
|
|
|
bool newValue = SDL_JoystickGetButton(m_private->joystick, button) == 1;
|
|
|
|
|
|
|
|
if (m_joyButtonState[button] != newValue)
|
|
|
|
{
|
|
|
|
m_joyButtonState[button] = newValue;
|
|
|
|
|
|
|
|
SDL_Event joyButtonEvent;
|
|
|
|
|
|
|
|
if (newValue)
|
|
|
|
{
|
|
|
|
joyButtonEvent.jbutton.type = SDL_JOYBUTTONDOWN;
|
|
|
|
joyButtonEvent.jbutton.state = SDL_PRESSED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
joyButtonEvent.jbutton.type = SDL_JOYBUTTONUP;
|
|
|
|
joyButtonEvent.jbutton.state = SDL_RELEASED;
|
|
|
|
}
|
|
|
|
joyButtonEvent.jbutton.which = 0;
|
|
|
|
joyButtonEvent.jbutton.button = button;
|
|
|
|
|
|
|
|
SDL_PushEvent(&joyButtonEvent);
|
|
|
|
}
|
|
|
|
}
|
2012-06-29 22:12:04 +00:00
|
|
|
}
|
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
int CApplication::Run()
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
m_active = true;
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
while (true)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-07-22 20:05:12 +00:00
|
|
|
// To be sure no old event remains
|
|
|
|
m_private->currentEvent.type = SDL_NOEVENT;
|
|
|
|
|
2012-07-23 19:41:27 +00:00
|
|
|
if (m_active)
|
|
|
|
SDL_PumpEvents();
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
bool haveEvent = true;
|
|
|
|
while (haveEvent)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-07-22 20:05:12 +00:00
|
|
|
haveEvent = false;
|
|
|
|
|
2012-07-23 19:41:27 +00:00
|
|
|
int count = 0;
|
|
|
|
// Use SDL_PeepEvents() if the app is active, so we can use idle time to
|
|
|
|
// render the scene. Else, use SDL_PollEvent() to avoid eating CPU time.
|
2012-07-22 20:05:12 +00:00
|
|
|
if (m_active)
|
|
|
|
count = SDL_PeepEvents(&m_private->currentEvent, 1, SDL_GETEVENT, SDL_ALLEVENTS);
|
|
|
|
else
|
|
|
|
count = SDL_PollEvent(&m_private->currentEvent);
|
|
|
|
|
|
|
|
// If received an event
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
haveEvent = true;
|
|
|
|
|
|
|
|
Event event = ParseEvent();
|
|
|
|
|
|
|
|
if (event.type == EVENT_QUIT)
|
|
|
|
goto end; // exit the loop
|
|
|
|
|
|
|
|
if (event.type != EVENT_NULL)
|
|
|
|
{
|
|
|
|
bool passOn = ProcessEvent(event);
|
|
|
|
|
|
|
|
if (m_engine != NULL && passOn)
|
|
|
|
passOn = m_engine->ProcessEvent(event);
|
|
|
|
|
|
|
|
if (passOn)
|
|
|
|
m_eventQueue->AddEvent(event);
|
|
|
|
}
|
|
|
|
}
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
// Enter game update & frame rendering only if active
|
2012-06-26 20:23:05 +00:00
|
|
|
if (m_active && m_ready)
|
|
|
|
{
|
|
|
|
Event event;
|
2012-06-29 22:12:04 +00:00
|
|
|
while (m_eventQueue->GetEvent(event))
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
if (event.type == EVENT_QUIT)
|
2012-06-26 20:23:05 +00:00
|
|
|
goto end; // exit both loops
|
2012-07-22 20:05:12 +00:00
|
|
|
|
|
|
|
bool passOn = true;
|
|
|
|
|
|
|
|
// Skip system events (they have been processed earlier)
|
|
|
|
if (! event.systemEvent)
|
|
|
|
{
|
|
|
|
passOn = ProcessEvent(event);
|
|
|
|
|
|
|
|
if (passOn && m_engine != NULL)
|
|
|
|
passOn = m_engine->ProcessEvent(event);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
/*if (passOn && m_robotMain != NULL)
|
|
|
|
m_robotMain->ProcessEvent(event); */
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
// Update game and render a frame during idle time (no messages are waiting)
|
|
|
|
bool ok = Render();
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
// If an error occurs, push quit event to the queue
|
2012-07-22 20:05:12 +00:00
|
|
|
if (! ok)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
|
|
|
SDL_Event quitEvent;
|
|
|
|
memset(&quitEvent, 0, sizeof(SDL_Event));
|
|
|
|
quitEvent.type = SDL_QUIT;
|
|
|
|
SDL_PushEvent(&quitEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-25 17:59:17 +00:00
|
|
|
|
|
|
|
end:
|
2012-06-26 20:23:05 +00:00
|
|
|
Destroy();
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
return m_exitCode;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-04 17:56:22 +00:00
|
|
|
int CApplication::GetExitCode()
|
|
|
|
{
|
|
|
|
return m_exitCode;
|
|
|
|
}
|
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
//! Translates SDL press state to PressState
|
|
|
|
PressState TranslatePressState(unsigned char state)
|
|
|
|
{
|
|
|
|
if (state == SDL_PRESSED)
|
|
|
|
return STATE_PRESSED;
|
|
|
|
else
|
|
|
|
return STATE_RELEASED;
|
|
|
|
}
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
/** Conversion of the position of the mouse from window coords to interface coords:
|
|
|
|
- x: 0=left, 1=right
|
|
|
|
- y: 0=down, 1=up */
|
|
|
|
Math::Point CApplication::WindowToInterfaceCoords(Math::IntPoint pos)
|
|
|
|
{
|
|
|
|
return Math::Point( (float)pos.x / (float)m_private->deviceConfig.width,
|
|
|
|
1.0f - (float)pos.y / (float)m_private->deviceConfig.height);
|
|
|
|
}
|
2012-06-29 22:12:04 +00:00
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
Math::IntPoint CApplication::InterfaceToWindowCoords(Math::Point pos)
|
2012-06-29 22:12:04 +00:00
|
|
|
{
|
2012-07-22 20:05:12 +00:00
|
|
|
return Math::IntPoint((int)(pos.x * m_private->deviceConfig.width),
|
|
|
|
(int)((1.0f - pos.y) * m_private->deviceConfig.height));
|
2012-06-29 22:12:04 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
/** The SDL event parsed is stored internally.
|
|
|
|
If event is not available or is not understood, returned event is of type EVENT_NULL. */
|
|
|
|
Event CApplication::ParseEvent()
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
Event event;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
event.systemEvent = true;
|
|
|
|
|
|
|
|
if (m_private->currentEvent.type == SDL_QUIT)
|
|
|
|
{
|
|
|
|
event.type = EVENT_QUIT;
|
|
|
|
}
|
|
|
|
else if ( (m_private->currentEvent.type == SDL_KEYDOWN) ||
|
2012-06-29 22:12:04 +00:00
|
|
|
(m_private->currentEvent.type == SDL_KEYUP) )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
if (m_private->currentEvent.type == SDL_KEYDOWN)
|
|
|
|
event.type = EVENT_KEY_DOWN;
|
|
|
|
else
|
|
|
|
event.type = EVENT_KEY_UP;
|
|
|
|
|
2012-06-30 08:16:52 +00:00
|
|
|
event.key.key = m_private->currentEvent.key.keysym.sym;
|
|
|
|
event.key.mod = m_private->currentEvent.key.keysym.mod;
|
|
|
|
event.key.state = TranslatePressState(m_private->currentEvent.key.state);
|
|
|
|
event.key.unicode = m_private->currentEvent.key.keysym.unicode;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
2012-06-29 22:12:04 +00:00
|
|
|
else if ( (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) ||
|
|
|
|
(m_private->currentEvent.type == SDL_MOUSEBUTTONUP) )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN)
|
|
|
|
event.type = EVENT_MOUSE_BUTTON_DOWN;
|
|
|
|
else
|
|
|
|
event.type = EVENT_MOUSE_BUTTON_UP;
|
|
|
|
|
2012-06-30 08:16:52 +00:00
|
|
|
event.mouseButton.button = m_private->currentEvent.button.button;
|
|
|
|
event.mouseButton.state = TranslatePressState(m_private->currentEvent.button.state);
|
2012-07-22 20:05:12 +00:00
|
|
|
event.mouseButton.pos = WindowToInterfaceCoords(Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y));
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
|
|
|
else if (m_private->currentEvent.type == SDL_MOUSEMOTION)
|
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
event.type = EVENT_MOUSE_MOVE;
|
|
|
|
|
2012-06-30 08:16:52 +00:00
|
|
|
event.mouseMove.state = TranslatePressState(m_private->currentEvent.button.state);
|
2012-07-22 20:05:12 +00:00
|
|
|
event.mouseMove.pos = WindowToInterfaceCoords(Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y));
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
2012-06-29 22:12:04 +00:00
|
|
|
else if (m_private->currentEvent.type == SDL_JOYAXISMOTION)
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
event.type = EVENT_JOY_AXIS;
|
|
|
|
|
2012-06-30 08:16:52 +00:00
|
|
|
event.joyAxis.axis = m_private->currentEvent.jaxis.axis;
|
|
|
|
event.joyAxis.value = m_private->currentEvent.jaxis.value;
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
2012-06-29 22:12:04 +00:00
|
|
|
else if ( (m_private->currentEvent.type == SDL_JOYBUTTONDOWN) ||
|
|
|
|
(m_private->currentEvent.type == SDL_JOYBUTTONUP) )
|
2012-06-26 20:23:05 +00:00
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
if (m_private->currentEvent.type == SDL_JOYBUTTONDOWN)
|
|
|
|
event.type = EVENT_JOY_BUTTON_DOWN;
|
|
|
|
else
|
|
|
|
event.type = EVENT_JOY_BUTTON_UP;
|
2012-06-26 20:23:05 +00:00
|
|
|
|
2012-06-30 08:16:52 +00:00
|
|
|
event.joyButton.button = m_private->currentEvent.jbutton.button;
|
|
|
|
event.joyButton.state = TranslatePressState(m_private->currentEvent.jbutton.state);
|
2012-06-26 20:23:05 +00:00
|
|
|
}
|
2012-06-29 22:12:04 +00:00
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
return event;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
/** Processes incoming events. It is the first function called after an event is captures.
|
|
|
|
Function returns \c true if the event is to be passed on to other processing functions
|
|
|
|
or \c false if not. */
|
|
|
|
bool CApplication::ProcessEvent(const Event &event)
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-07-04 17:56:22 +00:00
|
|
|
CLogger *l = GetLogger();
|
2012-06-29 22:12:04 +00:00
|
|
|
// Print the events in debug mode to test the code
|
|
|
|
if (m_debugMode)
|
|
|
|
{
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case EVENT_KEY_DOWN:
|
|
|
|
case EVENT_KEY_UP:
|
2012-07-04 17:56:22 +00:00
|
|
|
l->Info("EVENT_KEY_%s:\n", (event.type == EVENT_KEY_DOWN) ? "DOWN" : "UP");
|
|
|
|
l->Info(" key = %4x\n", event.key.key);
|
|
|
|
l->Info(" state = %s\n", (event.key.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED");
|
|
|
|
l->Info(" mod = %4x\n", event.key.mod);
|
|
|
|
l->Info(" unicode = %4x\n", event.key.unicode);
|
2012-06-29 22:12:04 +00:00
|
|
|
break;
|
|
|
|
case EVENT_MOUSE_MOVE:
|
2012-07-04 17:56:22 +00:00
|
|
|
l->Info("EVENT_MOUSE_MOVE:\n");
|
|
|
|
l->Info(" state = %s\n", (event.mouseMove.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED");
|
|
|
|
l->Info(" pos = (%f, %f)\n", event.mouseMove.pos.x, event.mouseMove.pos.y);
|
2012-06-29 22:12:04 +00:00
|
|
|
break;
|
|
|
|
case EVENT_MOUSE_BUTTON_DOWN:
|
|
|
|
case EVENT_MOUSE_BUTTON_UP:
|
2012-07-04 17:56:22 +00:00
|
|
|
l->Info("EVENT_MOUSE_BUTTON_%s:\n", (event.type == EVENT_MOUSE_BUTTON_DOWN) ? "DOWN" : "UP");
|
|
|
|
l->Info(" button = %d\n", event.mouseButton.button);
|
|
|
|
l->Info(" state = %s\n", (event.mouseButton.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED");
|
|
|
|
l->Info(" pos = (%f, %f)\n", event.mouseButton.pos.x, event.mouseButton.pos.y);
|
2012-06-29 22:12:04 +00:00
|
|
|
break;
|
|
|
|
case EVENT_JOY_AXIS:
|
2012-07-04 17:56:22 +00:00
|
|
|
l->Info("EVENT_JOY_AXIS:\n");
|
|
|
|
l->Info(" axis = %d\n", event.joyAxis.axis);
|
|
|
|
l->Info(" value = %d\n", event.joyAxis.value);
|
2012-06-29 22:12:04 +00:00
|
|
|
break;
|
|
|
|
case EVENT_JOY_BUTTON_DOWN:
|
|
|
|
case EVENT_JOY_BUTTON_UP:
|
2012-07-04 17:56:22 +00:00
|
|
|
l->Info("EVENT_JOY_BUTTON_%s:\n", (event.type == EVENT_JOY_BUTTON_DOWN) ? "DOWN" : "UP");
|
|
|
|
l->Info(" button = %d\n", event.joyButton.button);
|
|
|
|
l->Info(" state = %s\n", (event.joyButton.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED");
|
2012-06-29 22:12:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-07-22 20:05:12 +00:00
|
|
|
|
|
|
|
// By default, pass on all events
|
|
|
|
return true;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
/** Renders the frame and swaps buffers as necessary. Returns \c false on error. */
|
2012-06-25 17:59:17 +00:00
|
|
|
bool CApplication::Render()
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
bool result = m_engine->Render();
|
|
|
|
if (! result)
|
|
|
|
return false;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-30 23:37:30 +00:00
|
|
|
if (m_private->deviceConfig.doubleBuf)
|
2012-06-26 20:23:05 +00:00
|
|
|
SDL_GL_SwapBuffers();
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
return true;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
/** Called in to toggle the pause state of the app. */
|
2012-06-25 17:59:17 +00:00
|
|
|
void CApplication::Pause(bool pause)
|
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
static long appPausedCount = 0L;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
appPausedCount += ( pause ? +1 : -1 );
|
|
|
|
m_ready = appPausedCount == 0;
|
|
|
|
|
|
|
|
// Handle the first pause request (of many, nestable pause requests)
|
|
|
|
if( pause && ( 1 == appPausedCount ) )
|
|
|
|
{
|
|
|
|
// Stop the scene from animating
|
|
|
|
//m_engine->TimeEnterGel();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Final pause request done
|
|
|
|
if (appPausedCount == 0)
|
|
|
|
{
|
|
|
|
// Restart the scene
|
|
|
|
//m_engine->TimeExitGel();
|
|
|
|
}
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CApplication::StepSimulation(float rTime)
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
// TODO
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
void CApplication::SetShowStat(bool show)
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
m_showStats = show;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-01 20:59:22 +00:00
|
|
|
bool CApplication::GetShowStat()
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
return m_showStats;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CApplication::SetDebugMode(bool mode)
|
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
m_debugMode = mode;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-01 20:59:22 +00:00
|
|
|
bool CApplication::GetDebugMode()
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
return m_debugMode;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-01 20:59:22 +00:00
|
|
|
bool CApplication::GetSetupMode()
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
return m_setupMode;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CApplication::FlushPressKey()
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
// TODO
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CApplication::ResetKey()
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
// TODO
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CApplication::SetKey(int keyRank, int option, int key)
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
// TODO
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-01 20:59:22 +00:00
|
|
|
int CApplication::GetKey(int keyRank, int option)
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
// TODO
|
|
|
|
return 0;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
void CApplication::SetGrabInput(bool grab)
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-07-22 20:05:12 +00:00
|
|
|
SDL_WM_GrabInput(grab ? SDL_GRAB_ON : SDL_GRAB_OFF);
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
bool CApplication::GetGrabInput()
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-07-22 20:05:12 +00:00
|
|
|
int result = SDL_WM_GrabInput(SDL_GRAB_QUERY);
|
|
|
|
return result == SDL_GRAB_ON;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CApplication::SetSystemMouseVisible(bool visible)
|
|
|
|
{
|
|
|
|
SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CApplication::GetSystemMouseVisibile()
|
|
|
|
{
|
|
|
|
int result = SDL_ShowCursor(SDL_QUERY);
|
|
|
|
return result == SDL_ENABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CApplication::SetSystemMousePos(Math::Point pos)
|
|
|
|
{
|
|
|
|
Math::IntPoint windowPos = InterfaceToWindowCoords(pos);
|
|
|
|
SDL_WarpMouse(windowPos.x, windowPos.y);
|
|
|
|
m_systemMousePos = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
Math::Point CApplication::GetSystemMousePos()
|
|
|
|
{
|
|
|
|
return m_systemMousePos;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
void CApplication::SetJoystickEnabled(bool enable)
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
m_joystickEnabled = enable;
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
if (m_joystickEnabled)
|
|
|
|
{
|
|
|
|
if (! OpenJoystick())
|
|
|
|
{
|
|
|
|
m_joystickEnabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CloseJoystick();
|
|
|
|
}
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-01 20:59:22 +00:00
|
|
|
bool CApplication::GetJoystickEnabled()
|
2012-06-25 17:59:17 +00:00
|
|
|
{
|
2012-06-29 22:12:04 +00:00
|
|
|
return m_joystickEnabled;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CApplication::WriteScreenShot(char *filename, int width, int height)
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
// TODO
|
2012-06-30 08:16:52 +00:00
|
|
|
return false;
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CApplication::InitText()
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
// TODO
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CApplication::DrawSuppl()
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
// TODO
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CApplication::ShowStats()
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
// TODO
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CApplication::OutputText(long x, long y, char* str)
|
|
|
|
{
|
2012-06-26 20:23:05 +00:00
|
|
|
// TODO
|
2012-06-25 17:59:17 +00:00
|
|
|
}
|
2012-07-22 20:05:12 +00:00
|
|
|
|
|
|
|
std::string CApplication::GetDataFilePath(const std::string& dirName, const std::string& fileName)
|
|
|
|
{
|
|
|
|
return m_dataPath + "/" + dirName + "/" + fileName;
|
|
|
|
}
|