Event handling, CApplication and switch to c++-11
- added/changed event structs and event queue in common/event.h - added event handling and some minor functions in CApplication - switched to --std=c++11 because of union in Event structdev-ui
parent
db5c6b5e45
commit
e37019943c
|
@ -13,8 +13,8 @@ find_package(SDL_image REQUIRED)
|
||||||
set(CMAKE_BUILD_TYPE debug)
|
set(CMAKE_BUILD_TYPE debug)
|
||||||
|
|
||||||
# Global compile flags
|
# Global compile flags
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
|
set(CMAKE_CXX_FLAGS_RELEASE "-std=c++11 -O2")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "-w -g -O0")
|
set(CMAKE_CXX_FLAGS_DEBUG "-std=c++11 -w -g -O0")
|
||||||
|
|
||||||
# Subdirectory with sources
|
# Subdirectory with sources
|
||||||
add_subdirectory(src bin)
|
add_subdirectory(src bin)
|
||||||
|
|
334
src/app/app.cpp
334
src/app/app.cpp
|
@ -42,14 +42,14 @@ struct ApplicationPrivate
|
||||||
//! Joystick
|
//! Joystick
|
||||||
SDL_Joystick *joystick;
|
SDL_Joystick *joystick;
|
||||||
//! Index of joystick device
|
//! Index of joystick device
|
||||||
int joystickDevice;
|
int joystickIndex;
|
||||||
|
|
||||||
ApplicationPrivate()
|
ApplicationPrivate()
|
||||||
{
|
{
|
||||||
memset(¤tEvent, 0, sizeof(SDL_Event));
|
memset(¤tEvent, 0, sizeof(SDL_Event));
|
||||||
surface = NULL;
|
surface = NULL;
|
||||||
joystick = NULL;
|
joystick = NULL;
|
||||||
joystickDevice = 0;
|
joystickIndex = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -60,21 +60,22 @@ CApplication::CApplication()
|
||||||
m_exitCode = 0;
|
m_exitCode = 0;
|
||||||
|
|
||||||
m_iMan = new CInstanceManager();
|
m_iMan = new CInstanceManager();
|
||||||
m_event = new CEvent(m_iMan);
|
|
||||||
|
|
||||||
m_engine = 0;
|
m_eventQueue = new CEventQueue(m_iMan);
|
||||||
m_robotMain = 0;
|
|
||||||
m_sound = 0;
|
m_engine = NULL;
|
||||||
|
m_robotMain = NULL;
|
||||||
|
m_sound = NULL;
|
||||||
|
|
||||||
m_keyState = 0;
|
m_keyState = 0;
|
||||||
m_axeKey = Math::Vector(0.0f, 0.0f, 0.0f);
|
m_axeKey = Math::Vector(0.0f, 0.0f, 0.0f);
|
||||||
m_axeJoy = Math::Vector(0.0f, 0.0f, 0.0f);
|
m_axeJoy = Math::Vector(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
m_vidMemTotal = 0;
|
m_active = false;
|
||||||
m_active = false;
|
m_activateApp = false;
|
||||||
m_activateApp = false;
|
m_ready = false;
|
||||||
m_ready = false;
|
m_joystickEnabled = false;
|
||||||
m_joystick = false;
|
|
||||||
m_time = 0.0f;
|
m_time = 0.0f;
|
||||||
|
|
||||||
for (int i = 0; i < 32; i++)
|
for (int i = 0; i < 32; i++)
|
||||||
|
@ -84,13 +85,8 @@ CApplication::CApplication()
|
||||||
|
|
||||||
m_windowTitle = "COLOBOT";
|
m_windowTitle = "COLOBOT";
|
||||||
|
|
||||||
m_appUseZBuffer = true;
|
|
||||||
m_appUseStereo = true;
|
|
||||||
m_showStats = false;
|
m_showStats = false;
|
||||||
m_debugMode = false;
|
m_debugMode = false;
|
||||||
m_audioState = true;
|
|
||||||
m_audioTrack = true;
|
|
||||||
m_niceMouse = false;
|
|
||||||
m_setupMode = true;
|
m_setupMode = true;
|
||||||
|
|
||||||
ResetKey();
|
ResetKey();
|
||||||
|
@ -101,6 +97,9 @@ CApplication::~CApplication()
|
||||||
delete m_private;
|
delete m_private;
|
||||||
m_private = NULL;
|
m_private = NULL;
|
||||||
|
|
||||||
|
delete m_eventQueue;
|
||||||
|
m_eventQueue = NULL;
|
||||||
|
|
||||||
delete m_iMan;
|
delete m_iMan;
|
||||||
m_iMan = NULL;
|
m_iMan = NULL;
|
||||||
}
|
}
|
||||||
|
@ -116,14 +115,6 @@ Error CApplication::ParseArguments(int argc, char *argv[])
|
||||||
m_showStats = true;
|
m_showStats = true;
|
||||||
SetDebugMode(true);
|
SetDebugMode(true);
|
||||||
}
|
}
|
||||||
else if (arg == "-audiostate")
|
|
||||||
{
|
|
||||||
m_audioState = false;
|
|
||||||
}
|
|
||||||
else if (arg == "-audiotrack")
|
|
||||||
{
|
|
||||||
m_audioTrack = false;
|
|
||||||
}
|
|
||||||
// TODO else {} report invalid argument
|
// TODO else {} report invalid argument
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,43 +123,32 @@ Error CApplication::ParseArguments(int argc, char *argv[])
|
||||||
|
|
||||||
bool CApplication::Create()
|
bool CApplication::Create()
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
TODO
|
|
||||||
Full screen by default unless in debug mode
|
|
||||||
if (! m_debugMode)
|
|
||||||
m_deviceConfig.fullScreen = true;
|
|
||||||
|
|
||||||
int full = 0;
|
|
||||||
if (GetProfileInt("Device", "FullScreen", full))
|
|
||||||
m_deviceConfig.fullScreen = full == 1;
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Temporarily -- only in windowed mode
|
// Temporarily -- only in windowed mode
|
||||||
m_deviceConfig.fullScreen = false;
|
m_deviceConfig.fullScreen = false;
|
||||||
|
|
||||||
/*
|
|
||||||
TODO
|
|
||||||
// Create the 3D engine.
|
// Create the 3D engine.
|
||||||
m_engine = new CEngine(m_iMan, this);
|
m_engine = new Gfx::CEngine(m_iMan, this);
|
||||||
|
|
||||||
|
/* TODO
|
||||||
// Initialize the app's custom scene stuff
|
// Initialize the app's custom scene stuff
|
||||||
if (! m_engine->OneTimeSceneInit())
|
if (! m_engine->OneTimeSceneInit())
|
||||||
{
|
{
|
||||||
SystemDialog(SDT_ERROR, "COLOBOT - Error", m_engine->RetError());
|
SystemDialog(SDT_ERROR, "COLOBOT - Error", m_engine->RetError());
|
||||||
return false;
|
return false;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// Create the sound instance.
|
/* // Create the sound instance.
|
||||||
m_sound = new CSound(m_iMan);
|
m_sound = new CSound(m_iMan);
|
||||||
|
|
||||||
// Create the robot application.
|
// Create the robot application.
|
||||||
m_robotMain = new CRobotMain(m_iMan);
|
m_robotMain = new CRobotMain(m_iMan); */
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
Uint32 initFlags = SDL_INIT_VIDEO;
|
|
||||||
if (m_joystick)
|
/* SDL initialization sequence */
|
||||||
initFlags |= SDL_INIT_JOYSTICK;
|
|
||||||
|
|
||||||
|
Uint32 initFlags = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;
|
||||||
|
|
||||||
if (SDL_Init(initFlags) < 0)
|
if (SDL_Init(initFlags) < 0)
|
||||||
{
|
{
|
||||||
|
@ -177,7 +157,7 @@ TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
|
const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
|
||||||
if (! videoInfo)
|
if (videoInfo == NULL)
|
||||||
{
|
{
|
||||||
SystemDialog( SDT_ERROR, "COLOBOT - Error", "SDL error while getting video info:\n " + std::string(SDL_GetError()) );
|
SystemDialog( SDT_ERROR, "COLOBOT - Error", "SDL error while getting video info:\n " + std::string(SDL_GetError()) );
|
||||||
return false;
|
return false;
|
||||||
|
@ -219,7 +199,7 @@ TODO
|
||||||
m_private->surface = SDL_SetVideoMode(m_deviceConfig.width, m_deviceConfig.height,
|
m_private->surface = SDL_SetVideoMode(m_deviceConfig.width, m_deviceConfig.height,
|
||||||
m_deviceConfig.bpp, videoFlags);
|
m_deviceConfig.bpp, videoFlags);
|
||||||
|
|
||||||
if (! m_private->surface)
|
if (m_private->surface == NULL)
|
||||||
{
|
{
|
||||||
SystemDialog( SDT_ERROR, "COLOBT - Error", std::string("SDL error while setting video mode:\n") +
|
SystemDialog( SDT_ERROR, "COLOBT - Error", std::string("SDL error while setting video mode:\n") +
|
||||||
std::string(SDL_GetError()) );
|
std::string(SDL_GetError()) );
|
||||||
|
@ -228,38 +208,19 @@ TODO
|
||||||
|
|
||||||
SDL_WM_SetCaption(m_windowTitle.c_str(), m_windowTitle.c_str());
|
SDL_WM_SetCaption(m_windowTitle.c_str(), m_windowTitle.c_str());
|
||||||
|
|
||||||
|
// Enable translating key codes of key press events to unicode chars
|
||||||
SDL_EnableUNICODE(1);
|
SDL_EnableUNICODE(1);
|
||||||
|
|
||||||
|
// Enable joystick event generation
|
||||||
|
SDL_JoystickEventState(SDL_ENABLE);
|
||||||
|
|
||||||
/*
|
|
||||||
TODO
|
|
||||||
|
|
||||||
InitJoystick();
|
// For now, enable joystick for testing
|
||||||
|
SetJoystickEnabled(true);
|
||||||
|
|
||||||
if ( !GetProfileInt("Setup", "Sound3D", b3D) )
|
// TODO ...
|
||||||
{
|
|
||||||
b3D = true;
|
|
||||||
}
|
|
||||||
m_pSound->SetDebugMode(m_bDebugMode);
|
|
||||||
m_pSound->Create(m_hWnd, b3D);
|
|
||||||
m_pSound->CacheAll();
|
|
||||||
m_pSound->SetState(m_bAudioState);
|
|
||||||
m_pSound->SetAudioTrack(m_bAudioTrack);
|
|
||||||
m_pSound->SetCDpath(m_CDpath);
|
|
||||||
|
|
||||||
// First execution?
|
|
||||||
if ( !GetProfileInt("Setup", "ObjectDirty", iValue) )
|
|
||||||
{
|
|
||||||
m_pD3DEngine->FirstExecuteAdapt(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creates the file colobot.ini at the first execution.
|
|
||||||
m_pRobotMain->CreateIni();
|
|
||||||
|
|
||||||
m_pRobotMain->ChangePhase(PHASE_WELCOME2);
|
|
||||||
|
|
||||||
m_engine->TimeInit();
|
|
||||||
*/
|
|
||||||
|
|
||||||
// The app is ready to go
|
// The app is ready to go
|
||||||
m_ready = true;
|
m_ready = true;
|
||||||
|
@ -269,6 +230,9 @@ TODO
|
||||||
|
|
||||||
void CApplication::Destroy()
|
void CApplication::Destroy()
|
||||||
{
|
{
|
||||||
|
delete m_engine;
|
||||||
|
m_engine = NULL;
|
||||||
|
|
||||||
if (m_private->joystick != NULL)
|
if (m_private->joystick != NULL)
|
||||||
{
|
{
|
||||||
SDL_JoystickClose(m_private->joystick);
|
SDL_JoystickClose(m_private->joystick);
|
||||||
|
@ -283,6 +247,19 @@ void CApplication::Destroy()
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CApplication::OpenJoystick()
|
||||||
|
{
|
||||||
|
m_private->joystick = SDL_JoystickOpen(m_private->joystickIndex);
|
||||||
|
if (m_private->joystick == NULL)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CApplication::CloseJoystick()
|
||||||
|
{
|
||||||
|
SDL_JoystickClose(m_private->joystick);
|
||||||
|
}
|
||||||
|
|
||||||
int CApplication::Run()
|
int CApplication::Run()
|
||||||
{
|
{
|
||||||
m_active = true;
|
m_active = true;
|
||||||
|
@ -312,9 +289,9 @@ int CApplication::Run()
|
||||||
if (m_active && m_ready)
|
if (m_active && m_ready)
|
||||||
{
|
{
|
||||||
Event event;
|
Event event;
|
||||||
while (m_event->GetEvent(event))
|
while (m_eventQueue->GetEvent(event))
|
||||||
{
|
{
|
||||||
if (event.event == EVENT_QUIT)
|
if (event.type == EVENT_QUIT)
|
||||||
{
|
{
|
||||||
goto end; // exit both loops
|
goto end; // exit both loops
|
||||||
}
|
}
|
||||||
|
@ -322,11 +299,6 @@ int CApplication::Run()
|
||||||
//m_robotMain->EventProcess(event);
|
//m_robotMain->EventProcess(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if ( !RetNiceMouse())
|
|
||||||
//{
|
|
||||||
// SetMouseType(m_engine->RetMouseType());
|
|
||||||
//}
|
|
||||||
|
|
||||||
// If an error occurs, push quit event to the queue
|
// If an error occurs, push quit event to the queue
|
||||||
if (! Render())
|
if (! Render())
|
||||||
{
|
{
|
||||||
|
@ -345,52 +317,135 @@ end:
|
||||||
return m_exitCode;
|
return m_exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Translates SDL press state to PressState
|
||||||
|
PressState TranslatePressState(unsigned char state)
|
||||||
|
{
|
||||||
|
if (state == SDL_PRESSED)
|
||||||
|
return STATE_PRESSED;
|
||||||
|
else
|
||||||
|
return STATE_RELEASED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Conversion of the position of the mouse to the following coordinates:
|
||||||
|
|
||||||
|
x: 0=left, 1=right
|
||||||
|
|
||||||
|
y: 0=down, 1=up
|
||||||
|
*/
|
||||||
|
Math::Point CApplication::WindowToInterfaceCoords(int x, int y)
|
||||||
|
{
|
||||||
|
return Math::Point((float)x / (float)m_deviceConfig.width,
|
||||||
|
1.0f - (float)y / (float)m_deviceConfig.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CApplication::ParseEvent()
|
void CApplication::ParseEvent()
|
||||||
{
|
{
|
||||||
/* Event event;
|
Event event;
|
||||||
|
|
||||||
if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN)
|
if ( (m_private->currentEvent.type == SDL_KEYDOWN) ||
|
||||||
|
(m_private->currentEvent.type == SDL_KEYUP) )
|
||||||
{
|
{
|
||||||
if (m_private->currentEvent.button.button == SDL_BUTTON_LEFT)
|
if (m_private->currentEvent.type == SDL_KEYDOWN)
|
||||||
event.event = EVENT_LBUTTONDOWN;
|
event.type = EVENT_KEY_DOWN;
|
||||||
else if (m_private->currentEvent.button.button == SDL_BUTTON_RIGHT)
|
else
|
||||||
event.event = EVENT_RBUTTONDOWN;
|
event.type = EVENT_KEY_UP;
|
||||||
|
|
||||||
|
event.data.key.key = m_private->currentEvent.key.keysym.sym;
|
||||||
|
event.data.key.mod = m_private->currentEvent.key.keysym.mod;
|
||||||
|
event.data.key.state = TranslatePressState(m_private->currentEvent.key.state);
|
||||||
|
event.data.key.unicode = m_private->currentEvent.key.keysym.unicode;
|
||||||
}
|
}
|
||||||
else if (m_private->currentEvent.type == SDL_MOUSEBUTTONUP)
|
else if ( (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) ||
|
||||||
|
(m_private->currentEvent.type == SDL_MOUSEBUTTONUP) )
|
||||||
{
|
{
|
||||||
if (m_private->currentEvent.button.button == SDL_BUTTON_LEFT)
|
if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN)
|
||||||
event.event = EVENT_LBUTTONUP;
|
event.type = EVENT_MOUSE_BUTTON_DOWN;
|
||||||
else if (m_private->currentEvent.button.button == SDL_BUTTON_RIGHT)
|
else
|
||||||
event.event = EVENT_RBUTTONUP;
|
event.type = EVENT_MOUSE_BUTTON_UP;
|
||||||
|
|
||||||
|
event.data.mouseButton.button = m_private->currentEvent.button.button;
|
||||||
|
event.data.mouseButton.state = TranslatePressState(m_private->currentEvent.button.state);
|
||||||
|
event.data.mouseButton.pos = WindowToInterfaceCoords(m_private->currentEvent.button.x, m_private->currentEvent.button.y);
|
||||||
}
|
}
|
||||||
else if (m_private->currentEvent.type == SDL_MOUSEMOTION)
|
else if (m_private->currentEvent.type == SDL_MOUSEMOTION)
|
||||||
{
|
{
|
||||||
event.event = EVENT_MOUSEMOVE;
|
event.type = EVENT_MOUSE_MOVE;
|
||||||
|
|
||||||
|
event.data.mouseMove.state = TranslatePressState(m_private->currentEvent.button.state);
|
||||||
|
event.data.mouseMove.pos = WindowToInterfaceCoords(m_private->currentEvent.button.x, m_private->currentEvent.button.y);
|
||||||
}
|
}
|
||||||
else if (m_private->currentEvent.type == SDL_KEYDOWN)
|
// TODO: joystick state polling instead of getting events
|
||||||
|
else if (m_private->currentEvent.type == SDL_JOYAXISMOTION)
|
||||||
{
|
{
|
||||||
event.event = EVENT_KEYDOWN;
|
event.type = EVENT_JOY_AXIS;
|
||||||
|
|
||||||
|
event.data.joyAxis.axis = m_private->currentEvent.jaxis.axis;
|
||||||
|
event.data.joyAxis.value = m_private->currentEvent.jaxis.value;
|
||||||
}
|
}
|
||||||
else if (m_private->currentEvent.type == SDL_KEYUP)
|
else if ( (m_private->currentEvent.type == SDL_JOYBUTTONDOWN) ||
|
||||||
|
(m_private->currentEvent.type == SDL_JOYBUTTONUP) )
|
||||||
{
|
{
|
||||||
event.event = EVENT_KEYUP;
|
if (m_private->currentEvent.type == SDL_JOYBUTTONDOWN)
|
||||||
|
event.type = EVENT_JOY_BUTTON_DOWN;
|
||||||
|
else
|
||||||
|
event.type = EVENT_JOY_BUTTON_UP;
|
||||||
|
|
||||||
|
event.data.joyButton.button = m_private->currentEvent.jbutton.button;
|
||||||
|
event.data.joyButton.state = TranslatePressState(m_private->currentEvent.jbutton.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_robotMain != NULL && event.event != EVENT_NULL)
|
|
||||||
|
if (m_robotMain != NULL && event.type != EVENT_NULL)
|
||||||
{
|
{
|
||||||
m_robotMain->EventProcess(event);
|
//m_robotMain->EventProcess(event);
|
||||||
}
|
|
||||||
if (m_engine != NULL)
|
|
||||||
{
|
|
||||||
m_engine->MsgProc( hWnd, uMsg, wParam, lParam );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessEvent(event);*/
|
ProcessEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CApplication::ProcessEvent(Event event)
|
void CApplication::ProcessEvent(Event event)
|
||||||
{
|
{
|
||||||
|
// Print the events in debug mode to test the code
|
||||||
|
if (m_debugMode)
|
||||||
|
{
|
||||||
|
switch (event.type)
|
||||||
|
{
|
||||||
|
case EVENT_KEY_DOWN:
|
||||||
|
case EVENT_KEY_UP:
|
||||||
|
printf("EVENT_KEY_%s:\n", (event.type == EVENT_KEY_DOWN) ? "DOWN" : "UP");
|
||||||
|
printf(" key = %4x\n", event.data.key.key);
|
||||||
|
printf(" state = %s\n", (event.data.key.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED");
|
||||||
|
printf(" mod = %4x\n", event.data.key.mod);
|
||||||
|
printf(" unicode = %4x\n", event.data.key.unicode);
|
||||||
|
break;
|
||||||
|
case EVENT_MOUSE_MOVE:
|
||||||
|
printf("EVENT_MOUSE_MOVE:\n");
|
||||||
|
printf(" state = %s\n", (event.data.mouseMove.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED");
|
||||||
|
printf(" pos = (%f, %f)\n", event.data.mouseMove.pos.x, event.data.mouseMove.pos.y);
|
||||||
|
break;
|
||||||
|
case EVENT_MOUSE_BUTTON_DOWN:
|
||||||
|
case EVENT_MOUSE_BUTTON_UP:
|
||||||
|
printf("EVENT_MOUSE_BUTTON_%s:\n", (event.type == EVENT_MOUSE_BUTTON_DOWN) ? "DOWN" : "UP");
|
||||||
|
printf(" button = %d\n", event.data.mouseButton.button);
|
||||||
|
printf(" state = %s\n", (event.data.mouseButton.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED");
|
||||||
|
printf(" pos = (%f, %f)\n", event.data.mouseButton.pos.x, event.data.mouseButton.pos.y);
|
||||||
|
break;
|
||||||
|
case EVENT_JOY_AXIS:
|
||||||
|
printf("EVENT_JOY_AXIS:\n");
|
||||||
|
printf(" axis = %d\n", event.data.joyAxis.axis);
|
||||||
|
printf(" value = %d\n", event.data.joyAxis.value);
|
||||||
|
break;
|
||||||
|
case EVENT_JOY_BUTTON_DOWN:
|
||||||
|
case EVENT_JOY_BUTTON_UP:
|
||||||
|
printf("EVENT_JOY_BUTTON_%s:\n", (event.type == EVENT_JOY_BUTTON_DOWN) ? "DOWN" : "UP");
|
||||||
|
printf(" button = %d\n", event.data.joyButton.button);
|
||||||
|
printf(" state = %s\n", (event.data.mouseButton.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CApplication::Render()
|
bool CApplication::Render()
|
||||||
|
@ -405,14 +460,27 @@ bool CApplication::Render()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called in to toggle the pause state of the app. */
|
||||||
void CApplication::Pause(bool pause)
|
void CApplication::Pause(bool pause)
|
||||||
{
|
{
|
||||||
// TODO
|
static long appPausedCount = 0L;
|
||||||
}
|
|
||||||
|
|
||||||
void CApplication::SetMousePos(Math::Point pos)
|
appPausedCount += ( pause ? +1 : -1 );
|
||||||
{
|
m_ready = appPausedCount == 0;
|
||||||
// TODO
|
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CApplication::StepSimulation(float rTime)
|
void CApplication::StepSimulation(float rTime)
|
||||||
|
@ -420,32 +488,29 @@ void CApplication::StepSimulation(float rTime)
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetShowStat(bool show)
|
void CApplication::SetShowStat(bool show)
|
||||||
{
|
{
|
||||||
// TODO
|
m_showStats = show;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CApplication::RetShowStat()
|
bool CApplication::RetShowStat()
|
||||||
{
|
{
|
||||||
// TODO
|
return m_showStats;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CApplication::SetDebugMode(bool mode)
|
void CApplication::SetDebugMode(bool mode)
|
||||||
{
|
{
|
||||||
// TODO
|
m_debugMode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CApplication::RetDebugMode()
|
bool CApplication::RetDebugMode()
|
||||||
{
|
{
|
||||||
// TODO
|
return m_debugMode;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CApplication::RetSetupMode()
|
bool CApplication::RetSetupMode()
|
||||||
{
|
{
|
||||||
// TODO
|
return m_setupMode;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CApplication::FlushPressKey()
|
void CApplication::FlushPressKey()
|
||||||
|
@ -469,35 +534,36 @@ int CApplication::RetKey(int keyRank, int option)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CApplication::SetJoystick(bool enable)
|
void CApplication::SetMousePos(Math::Point pos)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CApplication::RetJoystick()
|
void CApplication::SetMouseType(Gfx::MouseType type)
|
||||||
{
|
|
||||||
// TODO
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetMouseType(Gfx::MouseType type)
|
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNiceMouse(bool nice)
|
void CApplication::SetJoystickEnabled(bool enable)
|
||||||
{
|
{
|
||||||
// TODO
|
m_joystickEnabled = enable;
|
||||||
|
|
||||||
|
if (m_joystickEnabled)
|
||||||
|
{
|
||||||
|
if (! OpenJoystick())
|
||||||
|
{
|
||||||
|
m_joystickEnabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CloseJoystick();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CApplication::RetNiceMouse()
|
bool CApplication::RetJoystickEnabled()
|
||||||
{
|
{
|
||||||
return false;
|
return m_joystickEnabled;
|
||||||
}
|
|
||||||
|
|
||||||
bool CApplication::RetNiceMouseCap()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CApplication::WriteScreenShot(char *filename, int width, int height)
|
bool CApplication::WriteScreenShot(char *filename, int width, int height)
|
||||||
|
|
|
@ -60,6 +60,37 @@ public:
|
||||||
//! Main event loop
|
//! Main event loop
|
||||||
int Run();
|
int Run();
|
||||||
|
|
||||||
|
//! Enters the pause mode
|
||||||
|
void Pause(bool pause);
|
||||||
|
|
||||||
|
//! Updates the simulation state
|
||||||
|
void StepSimulation(float rTime);
|
||||||
|
|
||||||
|
void SetShowStat(bool show);
|
||||||
|
bool RetShowStat();
|
||||||
|
|
||||||
|
void SetDebugMode(bool mode);
|
||||||
|
bool RetDebugMode();
|
||||||
|
|
||||||
|
bool RetSetupMode();
|
||||||
|
|
||||||
|
void SetJoystickEnabled(bool enable);
|
||||||
|
bool RetJoystickEnabled();
|
||||||
|
|
||||||
|
void FlushPressKey();
|
||||||
|
void ResetKey();
|
||||||
|
void SetKey(int keyRank, int option, int key);
|
||||||
|
int RetKey(int keyRank, int option);
|
||||||
|
|
||||||
|
void SetMouseType(Gfx::MouseType type);
|
||||||
|
void SetMousePos(Math::Point pos);
|
||||||
|
|
||||||
|
//? void SetNiceMouse(bool nice);
|
||||||
|
//? bool RetNiceMouse();
|
||||||
|
//? bool RetNiceMouseCap();
|
||||||
|
|
||||||
|
bool WriteScreenShot(char *filename, int width, int height);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Cleans up before exit
|
//! Cleans up before exit
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
@ -70,34 +101,14 @@ protected:
|
||||||
//! Renders the image in window
|
//! Renders the image in window
|
||||||
bool Render();
|
bool Render();
|
||||||
|
|
||||||
public:
|
//! Opens the joystick device
|
||||||
void Pause(bool pause);
|
bool OpenJoystick();
|
||||||
void StepSimulation(float rTime);
|
//! Closes the joystick device
|
||||||
|
void CloseJoystick();
|
||||||
|
|
||||||
void SetMousePos(Math::Point pos);
|
//! Converts window coords to interface coords
|
||||||
|
Math::Point WindowToInterfaceCoords(int x, int y);
|
||||||
|
|
||||||
void SetShowStat(bool show);
|
|
||||||
bool RetShowStat();
|
|
||||||
void SetDebugMode(bool mode);
|
|
||||||
bool RetDebugMode();
|
|
||||||
bool RetSetupMode();
|
|
||||||
|
|
||||||
void FlushPressKey();
|
|
||||||
void ResetKey();
|
|
||||||
void SetKey(int keyRank, int option, int key);
|
|
||||||
int RetKey(int keyRank, int option);
|
|
||||||
|
|
||||||
void SetJoystick(bool enable);
|
|
||||||
bool RetJoystick();
|
|
||||||
|
|
||||||
void SetMouseType(Gfx::MouseType type);
|
|
||||||
void SetNiceMouse(bool nice);
|
|
||||||
bool RetNiceMouse();
|
|
||||||
bool RetNiceMouseCap();
|
|
||||||
|
|
||||||
bool WriteScreenShot(char *filename, int width, int height);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
//HRESULT ConfirmDevice( DDCAPS* pddDriverCaps, D3DDEVICEDESC7* pd3dDeviceDesc );
|
//HRESULT ConfirmDevice( DDCAPS* pddDriverCaps, D3DDEVICEDESC7* pd3dDeviceDesc );
|
||||||
//HRESULT Initialize3DEnvironment();
|
//HRESULT Initialize3DEnvironment();
|
||||||
//HRESULT Change3DEnvironment();
|
//HRESULT Change3DEnvironment();
|
||||||
|
@ -113,14 +124,20 @@ protected:
|
||||||
void OutputText(long x, long y, char* str);
|
void OutputText(long x, long y, char* str);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
CInstanceManager* m_iMan;
|
||||||
//! Private (SDL-dependent data)
|
//! Private (SDL-dependent data)
|
||||||
ApplicationPrivate* m_private;
|
ApplicationPrivate* m_private;
|
||||||
CInstanceManager* m_iMan;
|
//! Global event queue
|
||||||
|
CEventQueue* m_eventQueue;
|
||||||
|
//! Current configuration of display device
|
||||||
Gfx::DeviceConfig m_deviceConfig;
|
Gfx::DeviceConfig m_deviceConfig;
|
||||||
|
//! Graphics engine
|
||||||
Gfx::CEngine* m_engine;
|
Gfx::CEngine* m_engine;
|
||||||
CEvent* m_event;
|
//! Sound subsystem
|
||||||
CRobotMain* m_robotMain;
|
|
||||||
CSound* m_sound;
|
CSound* m_sound;
|
||||||
|
//! Main class of the proper game engine
|
||||||
|
CRobotMain* m_robotMain;
|
||||||
|
|
||||||
|
|
||||||
//! Code to return at exit
|
//! Code to return at exit
|
||||||
int m_exitCode;
|
int m_exitCode;
|
||||||
|
@ -128,19 +145,22 @@ protected:
|
||||||
bool m_active;
|
bool m_active;
|
||||||
bool m_activateApp;
|
bool m_activateApp;
|
||||||
bool m_ready;
|
bool m_ready;
|
||||||
bool m_joystick;
|
|
||||||
|
|
||||||
std::string m_windowTitle;
|
|
||||||
long m_vidMemTotal;
|
|
||||||
bool m_appUseZBuffer;
|
|
||||||
bool m_appUseStereo;
|
|
||||||
bool m_showStats;
|
bool m_showStats;
|
||||||
bool m_debugMode;
|
bool m_debugMode;
|
||||||
bool m_audioState;
|
|
||||||
bool m_audioTrack;
|
|
||||||
bool m_niceMouse;
|
|
||||||
bool m_setupMode;
|
bool m_setupMode;
|
||||||
|
|
||||||
|
bool m_joystickEnabled;
|
||||||
|
|
||||||
|
std::string m_windowTitle;
|
||||||
|
|
||||||
|
//? long m_vidMemTotal;
|
||||||
|
//? bool m_appUseZBuffer;
|
||||||
|
//? bool m_appUseStereo;
|
||||||
|
//? bool m_audioState;
|
||||||
|
//? bool m_audioTrack;
|
||||||
|
//? bool m_niceMouse;
|
||||||
|
|
||||||
int m_keyState;
|
int m_keyState;
|
||||||
Math::Vector m_axeKey;
|
Math::Vector m_axeKey;
|
||||||
Math::Vector m_axeJoy;
|
Math::Vector m_axeJoy;
|
||||||
|
|
|
@ -1,96 +1,68 @@
|
||||||
// * This file is part of the COLOBOT source code
|
// * This file is part of the COLOBOT source code
|
||||||
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
||||||
// *
|
// *
|
||||||
// * This program is free software: you can redistribute it and/or modify
|
// * 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
|
// * it under the terms of the GNU General Public License as published by
|
||||||
// * the Free Software Foundation, either version 3 of the License, or
|
// * the Free Software Foundation, either version 3 of the License, or
|
||||||
// * (at your option) any later version.
|
// * (at your option) any later version.
|
||||||
// *
|
// *
|
||||||
// * This program is distributed in the hope that it will be useful,
|
// * This program is distributed in the hope that it will be useful,
|
||||||
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// * GNU General Public License for more details.
|
// * GNU General Public License for more details.
|
||||||
// *
|
// *
|
||||||
// * You should have received a copy of the GNU General Public License
|
// * You should have received a copy of the GNU General Public License
|
||||||
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
||||||
|
|
||||||
// event.cpp
|
// event.cpp
|
||||||
|
|
||||||
#include "common/iman.h"
|
#include "common/event.h"
|
||||||
#include "common/event.h"
|
#include "common/iman.h"
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
|
CEventQueue::CEventQueue(CInstanceManager* iMan)
|
||||||
Event::Event()
|
{
|
||||||
{
|
m_iMan = iMan;
|
||||||
event = EVENT_NULL;
|
m_iMan->AddInstance(CLASS_EVENT, this);
|
||||||
param = 0;
|
|
||||||
axeX = 0.0f;
|
Flush();
|
||||||
axeY = 0.0f;
|
}
|
||||||
axeZ = 0.0f;
|
|
||||||
keyState = 0;
|
CEventQueue::~CEventQueue()
|
||||||
rTime = 0.0f;
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CEventQueue::Flush()
|
||||||
// Object's constructor.
|
{
|
||||||
|
m_head = 0;
|
||||||
CEvent::CEvent(CInstanceManager* iMan)
|
m_tail = 0;
|
||||||
{
|
m_total = 0;
|
||||||
m_iMan = iMan;
|
}
|
||||||
m_iMan->AddInstance(CLASS_EVENT, this);
|
|
||||||
|
/** If the maximum size of queue has been reached, returns \c false.
|
||||||
Flush();
|
Else, adds the event to the queue and returns \c true. */
|
||||||
}
|
bool CEventQueue::AddEvent(const Event &event)
|
||||||
|
{
|
||||||
// Object's destructor.
|
if ( m_total >= MAX_EVENT_QUEUE ) return false;
|
||||||
|
|
||||||
CEvent::~CEvent()
|
m_fifo[m_head++] = event;
|
||||||
{
|
if ( m_head >= MAX_EVENT_QUEUE ) m_head = 0;
|
||||||
}
|
m_total ++;
|
||||||
|
|
||||||
|
return true;
|
||||||
// Empty the FIFO of events.
|
}
|
||||||
|
|
||||||
void CEvent::Flush()
|
/** If the queue is empty, returns \c false.
|
||||||
{
|
Else, gets the event from the front, puts it into \a event and returns \c true. */
|
||||||
m_head = 0;
|
bool CEventQueue::GetEvent(Event &event)
|
||||||
m_tail = 0;
|
{
|
||||||
m_total = 0;
|
if ( m_head == m_tail ) return false;
|
||||||
}
|
|
||||||
|
event = m_fifo[m_tail++];
|
||||||
// Produces an event.
|
if ( m_tail >= MAX_EVENT_QUEUE ) m_tail = 0;
|
||||||
|
m_total --;
|
||||||
void CEvent::MakeEvent(Event &event, EventMsg msg)
|
|
||||||
{
|
return true;
|
||||||
memset(&event, 0, sizeof(Event));
|
}
|
||||||
event.event = msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds an event in the FIFO.
|
|
||||||
|
|
||||||
bool CEvent::AddEvent(const Event &event)
|
|
||||||
{
|
|
||||||
if ( m_total >= MAXEVENT ) return false;
|
|
||||||
|
|
||||||
m_fifo[m_head++] = event;
|
|
||||||
if ( m_head >= MAXEVENT ) m_head = 0;
|
|
||||||
m_total ++;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removes an event from the FIFO.
|
|
||||||
|
|
||||||
bool CEvent::GetEvent(Event &event)
|
|
||||||
{
|
|
||||||
if ( m_head == m_tail ) return false;
|
|
||||||
|
|
||||||
event = m_fifo[m_tail++];
|
|
||||||
if ( m_tail >= MAXEVENT ) m_tail = 0;
|
|
||||||
m_total --;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -19,40 +19,50 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include "common/key.h"
|
||||||
#include "math/point.h"
|
#include "math/point.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#if !defined (WM_XBUTTONDOWN)
|
|
||||||
#define WM_XBUTTONDOWN 0x020B
|
|
||||||
#define WM_XBUTTONUP 0x020C
|
|
||||||
#define XBUTTON1 0x0001
|
|
||||||
#define XBUTTON2 0x0002
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CInstanceManager;
|
class CInstanceManager;
|
||||||
|
|
||||||
|
/**
|
||||||
const int MAXEVENT = 100;
|
\enum EventType
|
||||||
|
\brief Type of event message
|
||||||
// Events.
|
*/
|
||||||
|
enum EventType
|
||||||
enum EventMsg
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// TODO: document the meaning of each value
|
||||||
|
|
||||||
EVENT_NULL = 0,
|
EVENT_NULL = 0,
|
||||||
|
|
||||||
EVENT_QUIT = 1,
|
//! Event sent on user or system quit request
|
||||||
EVENT_FRAME = 2,
|
EVENT_QUIT = 1,
|
||||||
EVENT_LBUTTONDOWN = 3,
|
|
||||||
EVENT_RBUTTONDOWN = 4,
|
//? EVENT_FRAME = 2,
|
||||||
EVENT_LBUTTONUP = 5,
|
|
||||||
EVENT_RBUTTONUP = 6,
|
//! Event sent after pressing a mouse button
|
||||||
EVENT_MOUSEMOVE = 7,
|
EVENT_MOUSE_BUTTON_DOWN = 3,
|
||||||
EVENT_KEYDOWN = 8,
|
//! Event sent after releasing a mouse button
|
||||||
EVENT_KEYUP = 9,
|
EVENT_MOUSE_BUTTON_UP = 4,
|
||||||
EVENT_CHAR = 10,
|
//! Event sent after moving the mouse
|
||||||
EVENT_FOCUS = 11,
|
EVENT_MOUSE_MOVE = 7,
|
||||||
|
//! Event sent after pressing a key
|
||||||
|
EVENT_KEY_DOWN = 8,
|
||||||
|
//! Event sent after releasing a key
|
||||||
|
EVENT_KEY_UP = 9,
|
||||||
|
|
||||||
|
//? EVENT_CHAR = 10,
|
||||||
|
//? EVENT_FOCUS = 11,
|
||||||
|
|
||||||
|
//! Event sent after moving joystick axes
|
||||||
|
EVENT_JOY_AXIS = 12,
|
||||||
|
//! Event sent after pressing a joystick button
|
||||||
|
EVENT_JOY_BUTTON_DOWN = 13,
|
||||||
|
//! Event sent after releasing a joystick button
|
||||||
|
EVENT_JOY_BUTTON_UP = 14,
|
||||||
|
|
||||||
EVENT_UPDINTERFACE = 20,
|
EVENT_UPDINTERFACE = 20,
|
||||||
EVENT_WIN = 30,
|
EVENT_WIN = 30,
|
||||||
|
@ -525,60 +535,151 @@ enum EventMsg
|
||||||
EVENT_STUDIO_STEP = 2053,
|
EVENT_STUDIO_STEP = 2053,
|
||||||
|
|
||||||
EVENT_USER = 10000,
|
EVENT_USER = 10000,
|
||||||
EVENT_FORCE_DWORD = 0x7fffffff
|
EVENT_FORCE_LONG = 0x7fffffff
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/** \enum PressState
|
||||||
|
\brief State of key/mouse button */
|
||||||
|
enum PressState
|
||||||
|
{
|
||||||
|
STATE_PRESSED,
|
||||||
|
STATE_RELEASED
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/** \struct KeyEventData
|
||||||
|
\brief Additional data for keyboard event */
|
||||||
|
struct KeyEventData
|
||||||
|
{
|
||||||
|
//! STATE_PRESSED or STATE_RELEASED */
|
||||||
|
PressState state;
|
||||||
|
//! Key symbol: KEY(...) macro value (from common/key.h)
|
||||||
|
unsigned int key;
|
||||||
|
//! Keyboard modifiers: a bitmask made of KEY_MOD(...) macro values (from common/key.h)
|
||||||
|
unsigned int mod;
|
||||||
|
//! Unicode character
|
||||||
|
unsigned int unicode;
|
||||||
|
|
||||||
|
KeyEventData()
|
||||||
|
: state(STATE_PRESSED), key(0), mod(0), unicode(0) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** \struct MouseMotionEventData
|
||||||
|
\brief Additional data for mouse move event */
|
||||||
|
struct MouseMoveEventData
|
||||||
|
{
|
||||||
|
//! Current button state
|
||||||
|
unsigned char state;
|
||||||
|
//! Position of mouse in normalized coordinates (0..1)
|
||||||
|
Math::Point pos;
|
||||||
|
|
||||||
|
MouseMoveEventData()
|
||||||
|
: state(STATE_PRESSED) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** \struct MouseButtonEventData
|
||||||
|
\brief Additional data mouse button event */
|
||||||
|
struct MouseButtonEventData
|
||||||
|
{
|
||||||
|
//! The mouse button index
|
||||||
|
unsigned char button;
|
||||||
|
//! STATE_PRESSED or STATE_RELEASED
|
||||||
|
PressState state;
|
||||||
|
//! Position of mouse in normalized coordinates (0..1)
|
||||||
|
Math::Point pos;
|
||||||
|
|
||||||
|
MouseButtonEventData()
|
||||||
|
: button(0), state(STATE_PRESSED) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** \struct JoyAxisEventData
|
||||||
|
\brief Additional data for joystick axis event */
|
||||||
|
struct JoyAxisEventData
|
||||||
|
{
|
||||||
|
//! The joystick axis index
|
||||||
|
unsigned char axis;
|
||||||
|
//! The axis value (range: -32768 to 32767)
|
||||||
|
int value;
|
||||||
|
|
||||||
|
JoyAxisEventData()
|
||||||
|
: axis(axis), value(value) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** \struct JoyButtonEventData
|
||||||
|
\brief Joystick button event structure */
|
||||||
|
struct JoyButtonEventData
|
||||||
|
{
|
||||||
|
//! The joystick button index
|
||||||
|
unsigned char button;
|
||||||
|
//! STATE_PRESSED or STATE_RELEASED
|
||||||
|
PressState state;
|
||||||
|
|
||||||
|
JoyButtonEventData()
|
||||||
|
: button(0), state(STATE_PRESSED) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: JoyHatEventData? JoyBallEventData?
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\struct Event
|
||||||
|
\brief Event sent by system, interface or game
|
||||||
|
|
||||||
|
Event is described by its type (EventType) and the union
|
||||||
|
\a data contains additional data about the event.
|
||||||
|
Different members of the union are filled with different event types.
|
||||||
|
With some events, nothing is filled (it's zeroed out).
|
||||||
|
The union contains roughly the same information as SDL_Event struct
|
||||||
|
but packaged to independent structs and fields.
|
||||||
|
**/
|
||||||
struct Event
|
struct Event
|
||||||
{
|
{
|
||||||
EventMsg event; // event (EVENT *)
|
//! Type of event (EVENT_*)
|
||||||
long param; // parameter
|
EventType type;
|
||||||
Math::Point pos; // mouse position (0 .. 1)
|
/**
|
||||||
float axeX; // control the X axis (-1 .. 1)
|
\union EventDataUnion
|
||||||
float axeY; // control of the Y axis (-1 .. 1)
|
\brief Additional data associated with some events
|
||||||
float axeZ; // control the Z axis (-1 .. 1)
|
|
||||||
short keyState; // state of the keyboard (KS_ *)
|
|
||||||
float rTime; // relative time
|
|
||||||
|
|
||||||
Event();
|
For the listed event, the given member is filled with data.
|
||||||
|
For other event types, it is filled with zeros.
|
||||||
|
*/
|
||||||
|
union EventDataUnion
|
||||||
|
{
|
||||||
|
//! Additional data for EVENT_KEY_DOWN and EVENT_KEY_UP
|
||||||
|
KeyEventData key;
|
||||||
|
//! Additional data for EVENT_MOUSE_BUTTON_DOWN and EVENT_MOUSE_BUTTON_UP
|
||||||
|
MouseButtonEventData mouseButton;
|
||||||
|
//! Additional data for EVENT_MOUSE_MOVE
|
||||||
|
MouseMoveEventData mouseMove;
|
||||||
|
//! Additional data for EVENT_JOY
|
||||||
|
JoyAxisEventData joyAxis;
|
||||||
|
//! Additional data for EVENT_JOY_AXIS
|
||||||
|
JoyButtonEventData joyButton;
|
||||||
|
|
||||||
|
EventDataUnion()
|
||||||
|
{ memset(this, 0, sizeof(EventDataUnion)); }
|
||||||
|
~EventDataUnion()
|
||||||
|
{}
|
||||||
|
} data;
|
||||||
|
//? long param; // parameter
|
||||||
|
//? Math::Point pos; // mouse position (0 .. 1)
|
||||||
|
//? float axeX; // control the X axis (-1 .. 1)
|
||||||
|
//? float axeY; // control of the Y axis (-1 .. 1)
|
||||||
|
//? float axeZ; // control the Z axis (-1 .. 1)
|
||||||
|
//? short keyState; // state of the keyboard (KS_ *)
|
||||||
|
//? float rTime; // relative time
|
||||||
|
|
||||||
|
Event(EventType aType = EVENT_NULL) : type(aType) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const int VK_BUTTON1 = (0x100+1); // joystick button 1
|
/**
|
||||||
const int VK_BUTTON2 = (0x100+2); // joystick button 2
|
\enum KeyRank
|
||||||
const int VK_BUTTON3 = (0x100+3); // joystick button 3
|
\brief Slots for key assignment of user controls
|
||||||
const int VK_BUTTON4 = (0x100+4); // joystick button 4
|
*/
|
||||||
const int VK_BUTTON5 = (0x100+5); // joystick button 5
|
|
||||||
const int VK_BUTTON6 = (0x100+6); // joystick button 6
|
|
||||||
const int VK_BUTTON7 = (0x100+7); // joystick button 7
|
|
||||||
const int VK_BUTTON8 = (0x100+8); // joystick button 8
|
|
||||||
const int VK_BUTTON9 = (0x100+9); // joystick button 9
|
|
||||||
const int VK_BUTTON10 = (0x100+10); // joystick button 10
|
|
||||||
const int VK_BUTTON11 = (0x100+11); // joystick button 11
|
|
||||||
const int VK_BUTTON12 = (0x100+12); // joystick button 12
|
|
||||||
const int VK_BUTTON13 = (0x100+13); // joystick button 13
|
|
||||||
const int VK_BUTTON14 = (0x100+14); // joystick button 14
|
|
||||||
const int VK_BUTTON15 = (0x100+15); // joystick button 15
|
|
||||||
const int VK_BUTTON16 = (0x100+16); // joystick button 16
|
|
||||||
const int VK_BUTTON17 = (0x100+17); // joystick button 17
|
|
||||||
const int VK_BUTTON18 = (0x100+18); // joystick button 18
|
|
||||||
const int VK_BUTTON19 = (0x100+19); // joystick button 19
|
|
||||||
const int VK_BUTTON20 = (0x100+20); // joystick button 20
|
|
||||||
const int VK_BUTTON21 = (0x100+21); // joystick button 21
|
|
||||||
const int VK_BUTTON22 = (0x100+22); // joystick button 22
|
|
||||||
const int VK_BUTTON23 = (0x100+23); // joystick button 23
|
|
||||||
const int VK_BUTTON24 = (0x100+24); // joystick button 24
|
|
||||||
const int VK_BUTTON25 = (0x100+25); // joystick button 25
|
|
||||||
const int VK_BUTTON26 = (0x100+26); // joystick button 26
|
|
||||||
const int VK_BUTTON27 = (0x100+27); // joystick button 27
|
|
||||||
const int VK_BUTTON28 = (0x100+28); // joystick button 28
|
|
||||||
const int VK_BUTTON29 = (0x100+29); // joystick button 29
|
|
||||||
const int VK_BUTTON30 = (0x100+30); // joystick button 30
|
|
||||||
const int VK_BUTTON31 = (0x100+31); // joystick button 31
|
|
||||||
const int VK_BUTTON32 = (0x100+32); // joystick button 32
|
|
||||||
|
|
||||||
const int VK_WHEELUP = (0x200+1); // Mousewheel up
|
|
||||||
const int VK_WHEELDOWN = (0x200+2); // Mousewheel down
|
|
||||||
|
|
||||||
|
// TODO: move to global.h ?
|
||||||
|
|
||||||
enum KeyRank
|
enum KeyRank
|
||||||
{
|
{
|
||||||
|
@ -609,25 +710,37 @@ enum KeyRank
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
\class CEventQueue
|
||||||
|
\brief Global event queue
|
||||||
|
|
||||||
class CEvent
|
Provides an interface to a global FIFO queue with events (both system- and user-generated).
|
||||||
|
The queue has a fixed maximum size but it should not be a problem.
|
||||||
|
*/
|
||||||
|
class CEventQueue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CEvent(CInstanceManager* iMan);
|
//! Constant maximum size of queue
|
||||||
~CEvent();
|
static const int MAX_EVENT_QUEUE = 100;
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! Object's constructor
|
||||||
|
CEventQueue(CInstanceManager* iMan);
|
||||||
|
//! Object's destructor
|
||||||
|
~CEventQueue();
|
||||||
|
|
||||||
|
//! Empties the FIFO of events
|
||||||
void Flush();
|
void Flush();
|
||||||
void MakeEvent(Event &event, EventMsg msg);
|
//! Adds an event to the queue
|
||||||
bool AddEvent(const Event &event);
|
bool AddEvent(const Event &event);
|
||||||
bool GetEvent(Event &event);
|
bool GetEvent(Event &event);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CInstanceManager* m_iMan;
|
CInstanceManager* m_iMan;
|
||||||
|
Event m_fifo[MAX_EVENT_QUEUE];
|
||||||
Event m_fifo[MAXEVENT];
|
int m_head;
|
||||||
int m_head;
|
int m_tail;
|
||||||
int m_tail;
|
int m_total;
|
||||||
int m_total;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
// * This file is part of the COLOBOT source code
|
||||||
|
// * 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/.
|
||||||
|
|
||||||
|
// key.h
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#include "SDL/SDL_keysym.h"
|
||||||
|
|
||||||
|
/* Key definitions are specially defined here so that it is clear in other parts of the code
|
||||||
|
that these are used. It is to avoid having SDL-related enum values or #defines lying around
|
||||||
|
unchecked. With this approach it will be easier to maintain the code later on. */
|
||||||
|
|
||||||
|
// Key symbol defined as concatenation to SDLK_...
|
||||||
|
// If need arises, it can be changed to custom function or anything else
|
||||||
|
#define KEY(x) SDLK_ # x
|
||||||
|
|
||||||
|
// Key modifier defined as concatenation to KMOD_...
|
||||||
|
// If need arises, it can be changed to custom function or anything else
|
||||||
|
#define KEY_MOD(x) KMOD_ # x
|
|
@ -219,7 +219,7 @@ const int KS_NUMMINUS = (1<<15);
|
||||||
|
|
||||||
// Procedures.
|
// Procedures.
|
||||||
|
|
||||||
extern EventMsg GetUniqueEventMsg();
|
extern EventType GetUniqueEventType();
|
||||||
|
|
||||||
extern char RetNoAccent(char letter);
|
extern char RetNoAccent(char letter);
|
||||||
extern char RetToUpper(char letter);
|
extern char RetToUpper(char letter);
|
||||||
|
|
|
@ -481,7 +481,7 @@ public:
|
||||||
void SetLightMode(bool present);
|
void SetLightMode(bool present);
|
||||||
bool RetLightMode();
|
bool RetLightMode();
|
||||||
|
|
||||||
void SetEditIndentMode(bool auto);
|
void SetEditIndentMode(bool autoIndent);
|
||||||
bool RetEditIndentMode();
|
bool RetEditIndentMode();
|
||||||
|
|
||||||
void SetEditIndentValue(int value);
|
void SetEditIndentValue(int value);
|
||||||
|
|
Loading…
Reference in New Issue