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.h
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
2012-06-24 13:41:56 +00:00
|
|
|
#include "common/misc.h"
|
2012-07-22 20:05:12 +00:00
|
|
|
#include "common/singleton.h"
|
2012-07-01 20:59:22 +00:00
|
|
|
#include "graphics/common/device.h"
|
2012-06-24 13:41:56 +00:00
|
|
|
#include "graphics/common/engine.h"
|
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
#include <string>
|
2012-06-30 10:26:40 +00:00
|
|
|
#include <vector>
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-24 13:41:56 +00:00
|
|
|
|
|
|
|
class CInstanceManager;
|
|
|
|
class CEvent;
|
|
|
|
class CRobotMain;
|
|
|
|
class CSound;
|
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
struct ApplicationPrivate;
|
2012-06-24 13:41:56 +00:00
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
/**
|
2012-06-26 20:50:55 +00:00
|
|
|
* \class CApplication
|
|
|
|
* \brief Main application
|
2012-06-25 17:59:17 +00:00
|
|
|
*
|
2012-06-30 10:26:40 +00:00
|
|
|
* This class is responsible for main application execution, including creating
|
|
|
|
* and handling main application window, receiving events, etc.
|
|
|
|
*
|
|
|
|
* It is a singleton class with only one instance that can be created.
|
|
|
|
*
|
|
|
|
* Creation of other main objects
|
|
|
|
*
|
|
|
|
* The class creates the only instance of CInstanceManager, CEventQueue, CEngine,
|
|
|
|
* CRobotMain and CSound classes.
|
|
|
|
*
|
|
|
|
* Window management
|
|
|
|
*
|
|
|
|
* The class is responsible for creating app window, setting and changing the video mode,
|
|
|
|
* setting the position of mouse and changing the cursor, grabbing and writing screenshots.
|
|
|
|
*
|
|
|
|
* Events
|
|
|
|
*
|
|
|
|
* Events are taken from SDL event queue and either handled by CApplication or translated
|
|
|
|
* to common events from src/common.h and pushed to global event queue CEventQueue.
|
|
|
|
* Joystick events are generated somewhat differently, by running a separate timer,
|
|
|
|
* polling the device for changes and synthesising events on change. It avoids flooding
|
|
|
|
* the event queue with too many joystick events and the granularity of the timer can be
|
|
|
|
* adjusted.
|
|
|
|
*
|
|
|
|
* The events are further handled in CRobotMain class.
|
2012-06-25 17:59:17 +00:00
|
|
|
*
|
|
|
|
*/
|
2012-07-22 20:05:12 +00:00
|
|
|
class CApplication : public CSingleton<CApplication>
|
2012-06-22 14:31:55 +00:00
|
|
|
{
|
2012-06-24 13:41:56 +00:00
|
|
|
public:
|
2012-06-26 20:23:05 +00:00
|
|
|
//! Constructor (can only be called once!)
|
|
|
|
CApplication();
|
|
|
|
//! Destructor
|
|
|
|
~CApplication();
|
2012-06-24 13:41:56 +00:00
|
|
|
|
2012-06-25 17:59:17 +00:00
|
|
|
public:
|
2012-06-26 20:23:05 +00:00
|
|
|
//! Parses commandline arguments
|
2012-07-22 20:05:12 +00:00
|
|
|
bool ParseArguments(int argc, char *argv[]);
|
2012-06-26 20:23:05 +00:00
|
|
|
//! Initializes the application
|
|
|
|
bool Create();
|
|
|
|
//! Main event loop
|
|
|
|
int Run();
|
2012-07-04 17:56:22 +00:00
|
|
|
//! Returns the code to be returned at main() exit
|
|
|
|
int GetExitCode();
|
|
|
|
|
|
|
|
//! Cleans up before exit
|
|
|
|
void Destroy();
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
//! Enters the pause mode
|
2012-06-26 20:23:05 +00:00
|
|
|
void Pause(bool pause);
|
2012-06-25 17:59:17 +00:00
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
//! Updates the simulation state
|
|
|
|
void StepSimulation(float rTime);
|
2012-06-24 13:41:56 +00:00
|
|
|
|
2012-06-30 10:26:40 +00:00
|
|
|
//! Polls the state of joystick axes and buttons
|
2012-07-04 17:56:22 +00:00
|
|
|
void UpdateJoystick();
|
2012-06-30 10:26:40 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
void SetShowStat(bool show);
|
2012-07-01 20:59:22 +00:00
|
|
|
bool GetShowStat();
|
2012-06-29 22:12:04 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
void SetDebugMode(bool mode);
|
2012-07-01 20:59:22 +00:00
|
|
|
bool GetDebugMode();
|
2012-06-29 22:12:04 +00:00
|
|
|
|
2012-07-01 20:59:22 +00:00
|
|
|
bool GetSetupMode();
|
2012-06-24 13:41:56 +00:00
|
|
|
|
2012-06-29 22:12:04 +00:00
|
|
|
void SetJoystickEnabled(bool enable);
|
2012-07-01 20:59:22 +00:00
|
|
|
bool GetJoystickEnabled();
|
2012-06-29 22:12:04 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
void FlushPressKey();
|
|
|
|
void ResetKey();
|
|
|
|
void SetKey(int keyRank, int option, int key);
|
2012-07-01 20:59:22 +00:00
|
|
|
int GetKey(int keyRank, int option);
|
2012-06-24 13:41:56 +00:00
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
//! Sets the grab mode for input (keyboard & mouse)
|
|
|
|
void SetGrabInput(bool grab);
|
|
|
|
//! Returns the grab mode
|
|
|
|
bool GetGrabInput();
|
|
|
|
|
|
|
|
//! Sets the visiblity of system mouse cursor
|
|
|
|
void SetSystemMouseVisible(bool visible);
|
|
|
|
//! Returns the visiblity of system mouse cursor
|
|
|
|
bool GetSystemMouseVisibile();
|
2012-06-29 22:12:04 +00:00
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
//! Sets the position of system mouse cursor (in interface coords)
|
|
|
|
void SetSystemMousePos(Math::Point pos);
|
|
|
|
//! Returns the position of system mouse cursor (in interface coords)
|
|
|
|
Math::Point GetSystemMousePos();
|
2012-06-24 13:41:56 +00:00
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
bool WriteScreenShot(char *filename, int width, int height);
|
2012-06-24 13:41:56 +00:00
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
//! Returns the full path to a file in data directory
|
|
|
|
std::string GetDataFilePath(const std::string &dirName, const std::string &fileName);
|
|
|
|
|
2012-06-24 13:41:56 +00:00
|
|
|
protected:
|
2012-07-22 20:05:12 +00:00
|
|
|
//! Processes the captured SDL event to Event struct
|
|
|
|
Event ParseEvent();
|
2012-06-29 22:12:04 +00:00
|
|
|
//! Handles some incoming events
|
2012-07-22 20:05:12 +00:00
|
|
|
bool ProcessEvent(const Event &event);
|
2012-06-29 22:12:04 +00:00
|
|
|
//! Renders the image in window
|
|
|
|
bool Render();
|
|
|
|
|
|
|
|
//! Opens the joystick device
|
|
|
|
bool OpenJoystick();
|
|
|
|
//! Closes the joystick device
|
|
|
|
void CloseJoystick();
|
|
|
|
|
|
|
|
//! Converts window coords to interface coords
|
2012-07-22 20:05:12 +00:00
|
|
|
Math::Point WindowToInterfaceCoords(Math::IntPoint pos);
|
|
|
|
//! Converts the interface coords to window coords
|
|
|
|
Math::IntPoint InterfaceToWindowCoords(Math::Point pos);
|
2012-06-26 20:23:05 +00:00
|
|
|
|
|
|
|
void InitText();
|
|
|
|
void DrawSuppl();
|
|
|
|
void ShowStats();
|
|
|
|
void OutputText(long x, long y, char* str);
|
2012-06-24 13:41:56 +00:00
|
|
|
|
|
|
|
protected:
|
2012-06-30 10:26:40 +00:00
|
|
|
//! Instance manager
|
2012-06-29 22:12:04 +00:00
|
|
|
CInstanceManager* m_iMan;
|
2012-06-26 20:23:05 +00:00
|
|
|
//! Private (SDL-dependent data)
|
|
|
|
ApplicationPrivate* m_private;
|
2012-06-29 22:12:04 +00:00
|
|
|
//! Global event queue
|
|
|
|
CEventQueue* m_eventQueue;
|
|
|
|
//! Graphics engine
|
2012-06-26 20:23:05 +00:00
|
|
|
Gfx::CEngine* m_engine;
|
2012-07-01 20:59:22 +00:00
|
|
|
//! Graphics device
|
|
|
|
Gfx::CDevice* m_device;
|
2012-06-29 22:12:04 +00:00
|
|
|
//! Sound subsystem
|
2012-06-26 20:23:05 +00:00
|
|
|
CSound* m_sound;
|
2012-06-29 22:12:04 +00:00
|
|
|
//! Main class of the proper game engine
|
|
|
|
CRobotMain* m_robotMain;
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
//! Code to return at exit
|
|
|
|
int m_exitCode;
|
|
|
|
|
|
|
|
bool m_active;
|
|
|
|
bool m_activateApp;
|
|
|
|
bool m_ready;
|
|
|
|
|
|
|
|
bool m_showStats;
|
|
|
|
bool m_debugMode;
|
|
|
|
bool m_setupMode;
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
//! Whether joystick is enabled
|
2012-06-29 22:12:04 +00:00
|
|
|
bool m_joystickEnabled;
|
|
|
|
|
2012-07-22 20:05:12 +00:00
|
|
|
//! Text set as window title
|
2012-06-29 22:12:04 +00:00
|
|
|
std::string m_windowTitle;
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
int m_keyState;
|
|
|
|
Math::Vector m_axeKey;
|
|
|
|
Math::Vector m_axeJoy;
|
2012-07-22 20:05:12 +00:00
|
|
|
Math::Point m_systemMousePos;
|
2012-06-26 20:23:05 +00:00
|
|
|
long m_mouseWheel;
|
|
|
|
|
2012-06-30 10:26:40 +00:00
|
|
|
//! Current state of joystick axes; may be updated from another thread
|
|
|
|
std::vector<int> m_joyAxeState;
|
|
|
|
//! Current state of joystick buttons; may be updated from another thread
|
|
|
|
std::vector<bool> m_joyButtonState;
|
|
|
|
|
2012-06-26 20:23:05 +00:00
|
|
|
float m_time;
|
|
|
|
long m_key[50][2];
|
2012-07-22 20:05:12 +00:00
|
|
|
|
|
|
|
//! Path to directory with data files
|
|
|
|
std::string m_dataPath;
|
2012-06-22 14:31:55 +00:00
|
|
|
};
|
|
|
|
|