From 61bfb22f27f5216f989c023a5e39fad7e356d2d6 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 3 Aug 2012 23:23:13 +0200 Subject: Basic font rendering - added basic font rendering - minor refactoring & fixes --- src/app/app.cpp | 54 ++++++++++++++++++------------------------------------ src/app/app.h | 6 ------ 2 files changed, 18 insertions(+), 42 deletions(-) (limited to 'src/app') diff --git a/src/app/app.cpp b/src/app/app.cpp index d20232d..3681172 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -122,6 +122,7 @@ bool CApplication::ParseArguments(int argc, char *argv[]) { waitDataDir = false; m_dataPath = arg; + continue; } if (arg == "-debug") @@ -153,10 +154,6 @@ bool CApplication::Create() // Temporarily -- only in windowed mode m_deviceConfig.fullScreen = false; - // Create the 3D engine - m_engine = new Gfx::CEngine(m_iMan, this); - - /* // Create the sound instance. m_sound = new CSound(m_iMan); @@ -224,20 +221,15 @@ bool CApplication::Create() return false; } + // Create the 3D engine + m_engine = new Gfx::CEngine(m_iMan, this); + m_engine->SetDevice(m_device); - if (! m_engine->Create() ) - { - SystemDialog( SDT_ERROR, "COLOBT - Fatal Error", - std::string("Error in CEngine::Create() :\n") + - std::string(m_engine->GetError()) ); - m_exitCode = 1; - return false; - } - if (! m_engine->AfterDeviceSetInit() ) + if (! m_engine->Create() ) { SystemDialog( SDT_ERROR, "COLOBT - Fatal Error", - std::string("Error in CEngine::AfterDeviceSetInit() :\n") + + std::string("Error in CEngine::Init() :\n") + std::string(m_engine->GetError()) ); m_exitCode = 1; return false; @@ -315,8 +307,7 @@ void CApplication::Destroy() if (m_engine != NULL) { - if (m_engine->GetWasInit()) - m_engine->Destroy(); + m_engine->Destroy(); delete m_engine; m_engine = NULL; @@ -324,8 +315,7 @@ void CApplication::Destroy() if (m_device != NULL) { - if (m_device->GetWasInit()) - m_device->Destroy(); + m_device->Destroy(); delete m_device; m_device = NULL; @@ -616,21 +606,6 @@ PressState TranslatePressState(unsigned char state) return STATE_RELEASED; } -/** 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( static_cast(pos.x) / static_cast(m_deviceConfig.size.w), - 1.0f - static_cast(pos.y) / static_cast(m_deviceConfig.size.h) ); -} - -Math::IntPoint CApplication::InterfaceToWindowCoords(Math::Point pos) -{ - return Math::IntPoint(static_cast(pos.x * m_deviceConfig.size.w), - static_cast((1.0f - pos.y) * m_deviceConfig.size.h)); -} - /** 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() @@ -666,14 +641,16 @@ Event CApplication::ParseEvent() event.mouseButton.button = m_private->currentEvent.button.button; event.mouseButton.state = TranslatePressState(m_private->currentEvent.button.state); - event.mouseButton.pos = WindowToInterfaceCoords(Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y)); + event.mouseButton.pos = m_engine->WindowToInterfaceCoords( + Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y)); } else if (m_private->currentEvent.type == SDL_MOUSEMOTION) { event.type = EVENT_MOUSE_MOVE; event.mouseMove.state = TranslatePressState(m_private->currentEvent.button.state); - event.mouseMove.pos = WindowToInterfaceCoords(Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y)); + event.mouseMove.pos = m_engine->WindowToInterfaceCoords( + Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y)); } else if (m_private->currentEvent.type == SDL_JOYAXISMOTION) { @@ -792,6 +769,11 @@ void CApplication::StepSimulation(float rTime) // TODO } +Gfx::GLDeviceConfig CApplication::GetVideoConfig() +{ + return m_deviceConfig; +} + VideoQueryResult CApplication::GetVideoResolutionList(std::vector &resolutions, bool fullScreen, bool resizeable) { @@ -891,7 +873,7 @@ bool CApplication::GetSystemMouseVisibile() void CApplication::SetSystemMousePos(Math::Point pos) { - Math::IntPoint windowPos = InterfaceToWindowCoords(pos); + Math::IntPoint windowPos = m_engine->InterfaceToWindowCoords(pos); SDL_WarpMouse(windowPos.x, windowPos.y); m_systemMousePos = pos; } diff --git a/src/app/app.h b/src/app/app.h index 483aa55..bba55b2 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -25,7 +25,6 @@ #include "graphics/core/device.h" #include "graphics/engine/engine.h" #include "graphics/opengl/gldevice.h" -#include "math/intsize.h" #include #include @@ -206,11 +205,6 @@ protected: //! Closes the joystick device void CloseJoystick(); - //! Converts window coords to interface coords - Math::Point WindowToInterfaceCoords(Math::IntPoint pos); - //! Converts the interface coords to window coords - Math::IntPoint InterfaceToWindowCoords(Math::Point pos); - protected: //! Instance manager CInstanceManager* m_iMan; -- cgit v1.2.3-1-g7c22 From 63257034c946d40fb3ecc73a9ee3dc9d1e0a1e34 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Fri, 10 Aug 2012 23:31:42 +0200 Subject: Partial CEngine implementation - added rewritten implementation for basic modesetting in CEngine - started rewriting proper rendering and object handling in CEngine --- src/app/app.cpp | 21 ++++----------------- src/app/app.h | 2 +- 2 files changed, 5 insertions(+), 18 deletions(-) (limited to 'src/app') diff --git a/src/app/app.cpp b/src/app/app.cpp index 3681172..e116914 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -573,16 +573,7 @@ int CApplication::Run() } // Update game and render a frame during idle time (no messages are waiting) - bool ok = Render(); - - // If an error occurs, push quit event to the queue - if (! ok) - { - SDL_Event quitEvent; - memset(&quitEvent, 0, sizeof(SDL_Event)); - quitEvent.type = SDL_QUIT; - SDL_PushEvent(&quitEvent); - } + Render(); } } @@ -751,17 +742,13 @@ bool CApplication::ProcessEvent(const Event &event) return true; } -/** Renders the frame and swaps buffers as necessary. Returns \c false on error. */ -bool CApplication::Render() +/** Renders the frame and swaps buffers as necessary */ +void CApplication::Render() { - bool result = m_engine->Render(); - if (! result) - return false; + m_engine->Render(); if (m_deviceConfig.doubleBuf) SDL_GL_SwapBuffers(); - - return true; } void CApplication::StepSimulation(float rTime) diff --git a/src/app/app.h b/src/app/app.h index bba55b2..e7ffd54 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -198,7 +198,7 @@ protected: //! Handles some incoming events bool ProcessEvent(const Event &event); //! Renders the image in window - bool Render(); + void Render(); //! Opens the joystick device bool OpenJoystick(); -- cgit v1.2.3-1-g7c22 From 7f80ca297154809523cd533edf1842ab1ae391aa Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 11 Aug 2012 17:17:04 +0200 Subject: Render mode setting, refactoring - finished SetState in CEngine - refactored Size and IntSize back to Point and IntPoint - other minor changes in CEngine --- src/app/app.cpp | 6 +++--- src/app/app.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/app') diff --git a/src/app/app.cpp b/src/app/app.cpp index e116914..4f7120d 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -285,7 +285,7 @@ bool CApplication::CreateVideoSurface() if (m_deviceConfig.hardwareAccel) SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); - m_private->surface = SDL_SetVideoMode(m_deviceConfig.size.w, m_deviceConfig.size.h, + m_private->surface = SDL_SetVideoMode(m_deviceConfig.size.x, m_deviceConfig.size.y, m_deviceConfig.bpp, videoFlags); return true; @@ -761,7 +761,7 @@ Gfx::GLDeviceConfig CApplication::GetVideoConfig() return m_deviceConfig; } -VideoQueryResult CApplication::GetVideoResolutionList(std::vector &resolutions, +VideoQueryResult CApplication::GetVideoResolutionList(std::vector &resolutions, bool fullScreen, bool resizeable) { resolutions.clear(); @@ -799,7 +799,7 @@ VideoQueryResult CApplication::GetVideoResolutionList(std::vector for (int i = 0; modes[i] != NULL; ++i) - resolutions.push_back(Math::IntSize(modes[i]->w, modes[i]->h)); + resolutions.push_back(Math::IntPoint(modes[i]->w, modes[i]->h)); return VIDEO_QUERY_OK; } diff --git a/src/app/app.h b/src/app/app.h index e7ffd54..d3b1368 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -132,7 +132,7 @@ public: void Destroy(); //! Returns a list of possible video modes - VideoQueryResult GetVideoResolutionList(std::vector &resolutions, + VideoQueryResult GetVideoResolutionList(std::vector &resolutions, bool fullScreen, bool resizeable); //! Returns the current video mode -- cgit v1.2.3-1-g7c22 From 1996507fd3d4d9de90de99845b71a6bf3fbe62da Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sat, 11 Aug 2012 18:39:16 +0200 Subject: Documentation update - updated Doxyfile - added/changed file, dir and namespace descriptions - fixed some errors in doxygen tags --- src/app/README.txt | 7 ++++--- src/app/app.h | 5 ++++- src/app/main.cpp | 5 ++++- src/app/system.h | 9 ++++++--- src/app/system_linux.h | 9 ++++++--- src/app/system_other.h | 9 ++++++--- src/app/system_windows.h | 9 ++++++--- 7 files changed, 36 insertions(+), 17 deletions(-) (limited to 'src/app') diff --git a/src/app/README.txt b/src/app/README.txt index 1df1fcc..e4f69ec 100644 --- a/src/app/README.txt +++ b/src/app/README.txt @@ -1,3 +1,4 @@ -src/app - -Contains the main class of the application. +/** + * \dir app + * Main class of the application and system functions + */ diff --git a/src/app/app.h b/src/app/app.h index d3b1368..bfa8c25 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -15,7 +15,10 @@ // * 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 +/** + * \file app/app.h + * \brief CApplication class + */ #pragma once diff --git a/src/app/main.cpp b/src/app/main.cpp index dce13da..619043e 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -15,7 +15,10 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// main.cpp +/** + * \file app/main.cpp + * \brief Entry point of application - main() function + */ #include "app/app.h" #include "app/system.h" diff --git a/src/app/system.h b/src/app/system.h index 3c04760..e216842 100644 --- a/src/app/system.h +++ b/src/app/system.h @@ -15,7 +15,10 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// system.h +/** + * \file app/system.h + * \brief System functions: time stamps, info dialogs, etc. + */ #pragma once @@ -26,7 +29,7 @@ /* Dialog utils */ /** - * \enum SysDialogType + * \enum SystemDialogType * \brief Type of system dialog */ enum SystemDialogType @@ -44,7 +47,7 @@ enum SystemDialogType }; /** - * \enum SysDialogResult + * \enum SystemDialogResult * \brief Result of system dialog * * Means which button was pressed. diff --git a/src/app/system_linux.h b/src/app/system_linux.h index f58c9a1..69893de 100644 --- a/src/app/system_linux.h +++ b/src/app/system_linux.h @@ -15,10 +15,13 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// system_linux.h +/** + * \file app/system_linux.h + * \brief Linux-specific implementation of system functions + */ -/* This header contains Linux-specific code for system utils - from system.h. There is no separate .cpp module for simplicity.*/ +/* NOTE: code is contained in this header; + * there is no separate .cpp module for simplicity */ #include #include diff --git a/src/app/system_other.h b/src/app/system_other.h index 9f13ffa..eff0c8a 100644 --- a/src/app/system_other.h +++ b/src/app/system_other.h @@ -15,10 +15,13 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// system_other.h +/** + * \file app/system_other.h + * \brief Fallback code for other systems + */ -/* This header contains fallback code for other platforms for system utils - from system.h. There is no separate .cpp module for simplicity.*/ +/* NOTE: code is contained in this header; + * there is no separate .cpp module for simplicity */ #include diff --git a/src/app/system_windows.h b/src/app/system_windows.h index eb6beec..72d9f88 100644 --- a/src/app/system_windows.h +++ b/src/app/system_windows.h @@ -15,10 +15,13 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// system_windows.h +/** + * \file app/system_windows.h + * \brief Windows-specific implementation of system functions + */ -/* This header contains Windows-specific code for system utils - from system.h. There is no separate .cpp module for simplicity.*/ +/* NOTE: code is contained in this header; + * there is no separate .cpp module for simplicity */ #include -- cgit v1.2.3-1-g7c22 From b4b74c30e9aa93ae736db73df5cb0c5d508ec6ed Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 12 Aug 2012 10:45:04 +0200 Subject: Fixes & testing in CEngine - fixed bugs in settings modes, etc. - some additions and minor refactoring --- src/app/app.cpp | 19 ++++++++++++++----- src/app/app.h | 3 +++ 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src/app') diff --git a/src/app/app.cpp b/src/app/app.cpp index 4f7120d..a0518db 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -215,8 +215,7 @@ bool CApplication::Create() if (! m_device->Create() ) { SystemDialog( SDT_ERROR, "COLOBT - Fatal Error", - std::string("Error in CDevice::Create() :\n") + - std::string(m_device->GetError()) ); + std::string("Error in CDevice::Create()") ); m_exitCode = 1; return false; } @@ -229,8 +228,7 @@ bool CApplication::Create() if (! m_engine->Create() ) { SystemDialog( SDT_ERROR, "COLOBT - Fatal Error", - std::string("Error in CEngine::Init() :\n") + - std::string(m_engine->GetError()) ); + std::string("Error in CEngine::Init()") ); m_exitCode = 1; return false; } @@ -498,6 +496,14 @@ void CApplication::UpdateJoystick() } } +void CApplication::UpdateMouse() +{ + Math::IntPoint pos; + SDL_GetMouseState(&pos.x, &pos.y); + m_systemMousePos = m_engine->WindowToInterfaceCoords(pos); + m_engine->SetMousePos(m_systemMousePos); +} + int CApplication::Run() { m_active = true; @@ -572,6 +578,10 @@ int CApplication::Run() m_robotMain->ProcessEvent(event); */ } + /* Update mouse position explicitly right before rendering + * because mouse events are usually way behind */ + UpdateMouse(); + // Update game and render a frame during idle time (no messages are waiting) Render(); } @@ -857,7 +867,6 @@ bool CApplication::GetSystemMouseVisibile() return result == SDL_ENABLE; } - void CApplication::SetSystemMousePos(Math::Point pos) { Math::IntPoint windowPos = m_engine->InterfaceToWindowCoords(pos); diff --git a/src/app/app.h b/src/app/app.h index bfa8c25..0cfaad2 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -164,6 +164,9 @@ public: //! Polls the state of joystick axes and buttons void UpdateJoystick(); + //! Updates the mouse position explicitly + void UpdateMouse(); + void FlushPressKey(); void ResetKey(); void SetKey(int keyRank, int option, int key); -- cgit v1.2.3-1-g7c22