From 38d333862ae8995f7ad7f0475a6a295fe5c9b26d Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sat, 1 Jun 2019 01:13:44 +0200 Subject: [PATCH] source/Platform/Unix: stub implementation --- source/Display/GLContext.cpp | 3 ++ source/Game.cpp | 14 +++++- source/Platform/PlatformDisplay.cpp | 3 ++ source/Platform/Unix/GLXContext.cpp | 61 ++++++++++++++++++++++++ source/Platform/Unix/GLXContext.h | 39 +++++++++++++++ source/Platform/Unix/UnixApplication.cpp | 26 ++++++++++ source/Platform/Unix/UnixApplication.h | 30 ++++++++++++ source/Platform/Unix/UnixMisc.cpp | 15 ++++++ source/Platform/Unix/UnixSystem.cpp | 31 ++++++++++++ source/Platform/Unix/X11Display.cpp | 56 ++++++++++++++++++++++ source/Platform/Unix/X11Display.h | 40 ++++++++++++++++ source/Platform/Unix/X11EventQueue.cpp | 11 +++++ source/Platform/Unix/X11EventQueue.h | 18 +++++++ source/Platform/Unix/X11Input.cpp | 22 +++++++++ source/Platform/Unix/X11Input.h | 21 ++++++++ source/Platform/Unix/X11Keyboard.cpp | 20 ++++++++ source/Platform/Unix/X11Keyboard.h | 25 ++++++++++ source/Platform/Unix/X11Mouse.cpp | 31 ++++++++++++ source/Platform/Unix/X11Mouse.h | 31 ++++++++++++ source/System/MessageQueue.cpp | 3 ++ 20 files changed, 498 insertions(+), 2 deletions(-) create mode 100644 source/Platform/Unix/GLXContext.cpp create mode 100644 source/Platform/Unix/GLXContext.h create mode 100644 source/Platform/Unix/UnixApplication.cpp create mode 100644 source/Platform/Unix/UnixApplication.h create mode 100644 source/Platform/Unix/UnixMisc.cpp create mode 100644 source/Platform/Unix/UnixSystem.cpp create mode 100644 source/Platform/Unix/X11Display.cpp create mode 100644 source/Platform/Unix/X11Display.h create mode 100644 source/Platform/Unix/X11EventQueue.cpp create mode 100644 source/Platform/Unix/X11EventQueue.h create mode 100644 source/Platform/Unix/X11Input.cpp create mode 100644 source/Platform/Unix/X11Input.h create mode 100644 source/Platform/Unix/X11Keyboard.cpp create mode 100644 source/Platform/Unix/X11Keyboard.h create mode 100644 source/Platform/Unix/X11Mouse.cpp create mode 100644 source/Platform/Unix/X11Mouse.h diff --git a/source/Display/GLContext.cpp b/source/Display/GLContext.cpp index cd26ca8..912c9ff 100644 --- a/source/Display/GLContext.cpp +++ b/source/Display/GLContext.cpp @@ -4,6 +4,9 @@ #ifdef _WIN32 #include typedef sp::Win32GLContext ContextType; +#elif defined(__linux__) || defined(unix) || defined(__unix) || defined(__unix__) +#include +typedef sp::GLXContext ContextType; #else #error "No GLContext implementation exists" #endif diff --git a/source/Game.cpp b/source/Game.cpp index 5213c50..01cccc1 100644 --- a/source/Game.cpp +++ b/source/Game.cpp @@ -4,17 +4,27 @@ #include #include #include +#include #include + +// TODO: move this to Application::create() +#ifdef _WIN32 #include -#include +typedef sp::Win32Application ApplicationType; +#elif defined(__linux__) || defined(unix) || defined(__unix) || defined(__unix__) +#include +typedef sp::UnixApplication ApplicationType; +#else +#error "No Application implementation exists" +#endif namespace sp { Game::Game() : m_running(false) { - m_platform = new Win32Application(); + m_platform = new ApplicationType(); m_graphics = new Graphics(m_platform); m_input = new InputModule(&m_platform->getInput()); m_messageHandler = new MessageHandler(); diff --git a/source/Platform/PlatformDisplay.cpp b/source/Platform/PlatformDisplay.cpp index 154930e..3298b98 100644 --- a/source/Platform/PlatformDisplay.cpp +++ b/source/Platform/PlatformDisplay.cpp @@ -5,6 +5,9 @@ #ifdef _WIN32 #include typedef sp::Win32Display DisplayType; +#elif defined(__linux__) || defined(unix) || defined(__unix) || defined(__unix__) +#include +typedef sp::X11Display DisplayType; #else #error "No Display implementation exists" #endif diff --git a/source/Platform/Unix/GLXContext.cpp b/source/Platform/Unix/GLXContext.cpp new file mode 100644 index 0000000..a488bdd --- /dev/null +++ b/source/Platform/Unix/GLXContext.cpp @@ -0,0 +1,61 @@ + +#include "GLXContext.h" + +namespace sp { + +GLXContext::GLXContext() +{ + +} + +GLXContext::~GLXContext() +{ + +} + +bool GLXContext::create(const PlatformDisplay* display) +{ + return true; +} + +void GLXContext::destroy() +{ + +} + +bool GLXContext::activate() +{ + return true; +} + +bool GLXContext::deactivate() +{ + return true; +} + +bool GLXContext::isActive() const +{ + return true; +} + +bool GLXContext::setSwapInterval(int interval) +{ + return true; +} + +void GLXContext::setSize(unsigned int width, unsigned int height) +{ + +} + +void GLXContext::setSize(const Vector2u size) +{ + setSize(size.x, size.y); +} + +void GLXContext::swapBuffers() +{ + +} + +} // namespace sp diff --git a/source/Platform/Unix/GLXContext.h b/source/Platform/Unix/GLXContext.h new file mode 100644 index 0000000..3a5dcbe --- /dev/null +++ b/source/Platform/Unix/GLXContext.h @@ -0,0 +1,39 @@ + +#ifndef PLATFORM_UNIX_GLXCONTEXT_H +#define PLATFORM_UNIX_GLXCONTEXT_H + +// X11 OpenGL Context (glx) + +#include + +namespace sp { + +class GLXContext : public GLContext +{ +public : + GLXContext(); + ~GLXContext(); + + // Create a context associated with a display. + bool create(const PlatformDisplay* display); + + void destroy(); + + bool activate(); + + bool deactivate(); + + bool isActive() const; + + bool setSwapInterval(int interval); + + void setSize(unsigned int width, unsigned int height); + + void setSize(const Vector2u size); + + void swapBuffers(); +}; + +} // namespace sp + +#endif /* PLATFORM_UNIX_GLXCONTEXT_H */ diff --git a/source/Platform/Unix/UnixApplication.cpp b/source/Platform/Unix/UnixApplication.cpp new file mode 100644 index 0000000..a8925d4 --- /dev/null +++ b/source/Platform/Unix/UnixApplication.cpp @@ -0,0 +1,26 @@ + +#include "UnixApplication.h" + +namespace sp { + +void UnixApplication::init() +{ + // TODO +} + +void UnixApplication::shutdown() +{ + // TODO +} + +PlatformInput& UnixApplication::getInput() +{ + return m_input; +} + +MessageQueue& UnixApplication::getMessageQueue() +{ + return m_messageQueue; +} + +} // namespace sp diff --git a/source/Platform/Unix/UnixApplication.h b/source/Platform/Unix/UnixApplication.h new file mode 100644 index 0000000..1f5c2dc --- /dev/null +++ b/source/Platform/Unix/UnixApplication.h @@ -0,0 +1,30 @@ + +#ifndef PLATFORM_UNIX_APPLICATION_H +#define PLATFORM_UNIX_APPLICATION_H + +#include +#include +#include "X11Input.h" + +namespace sp { + +class UnixApplication : public PlatformApplication +{ +public : + virtual void init(); + + virtual void shutdown(); + + virtual PlatformInput& getInput(); + + virtual MessageQueue& getMessageQueue(); + +protected : + + X11Input m_input; + MessageQueue m_messageQueue; +}; + +} // namespace sp + +#endif /* PLATFORM_UNIX_APPLICATION_H */ diff --git a/source/Platform/Unix/UnixMisc.cpp b/source/Platform/Unix/UnixMisc.cpp new file mode 100644 index 0000000..c168588 --- /dev/null +++ b/source/Platform/Unix/UnixMisc.cpp @@ -0,0 +1,15 @@ + +#include + +namespace sp { + +void PlatformMisc::GetDisplayModes(std::vector& modes) +{ +} + +DisplayMode PlatformMisc::GetDesktopMode() +{ + return DisplayMode(); +} + +} // namespace sp diff --git a/source/Platform/Unix/UnixSystem.cpp b/source/Platform/Unix/UnixSystem.cpp new file mode 100644 index 0000000..68d5384 --- /dev/null +++ b/source/Platform/Unix/UnixSystem.cpp @@ -0,0 +1,31 @@ + +#include +#include +#include + +namespace sp { + +unsigned long system::getMilliseconds() +{ + struct timespec tv; + clock_gettime(CLOCK_REALTIME, &tv); + return (tv.tv_sec * 1000ul) + (tv.tv_nsec / 1000000ul); + +} + +void system::sleep(int milliseconds) +{ + struct timespec req, rem; + req.tv_sec = milliseconds / 1000ul; + req.tv_nsec = (milliseconds - (req.tv_sec * 1000ul)) * 1000000ul; + +_start: + // Try again if we get interrupted. + if (clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem) == EINTR) { + // Update req with remaining time. + req = rem; + goto _start; + } +} + +} // namespace sp diff --git a/source/Platform/Unix/X11Display.cpp b/source/Platform/Unix/X11Display.cpp new file mode 100644 index 0000000..eb32495 --- /dev/null +++ b/source/Platform/Unix/X11Display.cpp @@ -0,0 +1,56 @@ + +#include "X11Display.h" + +namespace sp { + +bool X11Display::create(DisplayDescription description) +{ + return true; +} + +void X11Display::destroy() +{ + +} + +bool X11Display::isValid() +{ + return true; +} + +void* X11Display::getHandle() const +{ + return NULL; +} + +void X11Display::setSize(unsigned int width, unsigned int height) +{ + m_size = Vector2u(width, height); +} + +Vector2u X11Display::getSize() const +{ + return m_size; +} + +void X11Display::setPosition(unsigned int x, unsigned int y) +{ + +} + +void X11Display::setCaption(const std::string& caption) +{ + +} + +void X11Display::setIcon(const std::string& icon) +{ + +} + +void X11Display::showCursor(bool value) +{ + +} + +} // namespace sp diff --git a/source/Platform/Unix/X11Display.h b/source/Platform/Unix/X11Display.h new file mode 100644 index 0000000..5e1724d --- /dev/null +++ b/source/Platform/Unix/X11Display.h @@ -0,0 +1,40 @@ + +#ifndef PLATFORM_UNIX_X11DISPLAY_H +#define PLATFORM_UNIX_X11DISPLAY_H + +#include + +namespace sp { + +class X11Display : public PlatformDisplay +{ +public : + + virtual bool create(DisplayDescription description); + + virtual void destroy(); + + virtual bool isValid(); + + virtual void* getHandle() const; + + virtual void setSize(unsigned int width, unsigned int height); + + virtual Vector2u getSize() const; + + virtual void setPosition(unsigned int x, unsigned int y); + + virtual void setCaption(const std::string& caption); + + virtual void setIcon(const std::string& icon); + + virtual void showCursor(bool value); + +protected : + + Vector2u m_size; +}; + +} // namespace sp + +#endif /* PLATFORM_UNIX_X11DISPLAY_H */ diff --git a/source/Platform/Unix/X11EventQueue.cpp b/source/Platform/Unix/X11EventQueue.cpp new file mode 100644 index 0000000..d71faaa --- /dev/null +++ b/source/Platform/Unix/X11EventQueue.cpp @@ -0,0 +1,11 @@ + +#include "X11EventQueue.h" + +namespace sp { + +bool X11EventQueue::poll(Event& event) +{ + return false; +} + +} //namespace sp diff --git a/source/Platform/Unix/X11EventQueue.h b/source/Platform/Unix/X11EventQueue.h new file mode 100644 index 0000000..9239694 --- /dev/null +++ b/source/Platform/Unix/X11EventQueue.h @@ -0,0 +1,18 @@ + +#ifndef PLATFORM_UNIX_X11_EVENT_QUEUE_H +#define PLATFORM_UNIX_X11_EVENT_QUEUE_H + +#include +#include + +namespace sp { + +class X11EventQueue : public PlatformEventQueue +{ +public : + virtual bool poll(Event& event); +}; + +} // namespace sp + +#endif /* PLATFORM_UNIX_X11_EVENT_QUEUE_H */ diff --git a/source/Platform/Unix/X11Input.cpp b/source/Platform/Unix/X11Input.cpp new file mode 100644 index 0000000..2af3f10 --- /dev/null +++ b/source/Platform/Unix/X11Input.cpp @@ -0,0 +1,22 @@ + +#include "X11Keyboard.h" +#include "X11Mouse.h" +#include "X11Input.h" + +namespace sp { + +Keyboard* X11Input::createKeyboard() +{ + return new X11Keyboard(); +} + +Mouse* X11Input::createMouse() +{ + return new X11Mouse(); +} + +void X11Input::update() +{ +} + +} // namespace sp diff --git a/source/Platform/Unix/X11Input.h b/source/Platform/Unix/X11Input.h new file mode 100644 index 0000000..6bb7439 --- /dev/null +++ b/source/Platform/Unix/X11Input.h @@ -0,0 +1,21 @@ + +#ifndef PLATFORM_UNIX_X11INPUT_H +#define PLATFORM_UNIX_X11INPUT_H + +#include + +namespace sp { + +class X11Input : public PlatformInput +{ +public : + virtual Keyboard* createKeyboard(); + + virtual Mouse* createMouse(); + + virtual void update(); +}; + +} // namespace sp + +#endif /* PLATFORM_UNIX_X11INPUT_H */ diff --git a/source/Platform/Unix/X11Keyboard.cpp b/source/Platform/Unix/X11Keyboard.cpp new file mode 100644 index 0000000..adc7e08 --- /dev/null +++ b/source/Platform/Unix/X11Keyboard.cpp @@ -0,0 +1,20 @@ +#include "X11Keyboard.h" + +namespace sp { + +void X11Keyboard::init() +{ + +} + +bool X11Keyboard::isKeyDown(Keyboard::Key key) +{ + return false; +} + +void X11Keyboard::update(InputModule *input) +{ + +} + +} // namespace sp diff --git a/source/Platform/Unix/X11Keyboard.h b/source/Platform/Unix/X11Keyboard.h new file mode 100644 index 0000000..7f7485c --- /dev/null +++ b/source/Platform/Unix/X11Keyboard.h @@ -0,0 +1,25 @@ + +#ifndef PLATFORM_UNIX_X11KEYBOARD_H +#define PLATFORM_UNIX_X11KEYBOARD_H + +#include + +namespace sp { + +class X11Keyboard : public Keyboard +{ +public : + virtual ~X11Keyboard() {} + + void init(); + + bool isKeyDown(Keyboard::Key key); + +protected : + + virtual void update(InputModule *input); +}; + +} // namespace sp + +#endif /* PLATFORM_UNIX_X11KEYBOARD_H */ diff --git a/source/Platform/Unix/X11Mouse.cpp b/source/Platform/Unix/X11Mouse.cpp new file mode 100644 index 0000000..48ef3bc --- /dev/null +++ b/source/Platform/Unix/X11Mouse.cpp @@ -0,0 +1,31 @@ + +#include "X11Mouse.h" + +namespace sp { + +void X11Mouse::init() +{ + +} + +Vector2f X11Mouse::getPosition() const +{ + return m_position; +} + +Vector2f X11Mouse::getAbsPosition() const +{ + return m_position; +} + +bool X11Mouse::isButtonDown(Mouse::Button button) const +{ + return false; +} + +void X11Mouse::update(InputModule *input) +{ + +} + +} // namespace sp diff --git a/source/Platform/Unix/X11Mouse.h b/source/Platform/Unix/X11Mouse.h new file mode 100644 index 0000000..55c044e --- /dev/null +++ b/source/Platform/Unix/X11Mouse.h @@ -0,0 +1,31 @@ + +#ifndef PLATFORM_UNIX_X11MOUSE_H +#define PLATFORM_UNIX_X11MOUSE_H + +#include + +namespace sp { + +class X11Mouse : public Mouse +{ +public : + virtual void init(); + + // Get mouse position + virtual Vector2f getPosition() const; + + virtual Vector2f getAbsPosition() const; + + virtual bool isButtonDown(Mouse::Button button) const; + +protected : + + virtual void update(InputModule *input); + +protected : + Vector2f m_position; +}; + +} // namespace sp + +#endif /* PLATFORM_UNIX_X11MOUSE_H */ diff --git a/source/System/MessageQueue.cpp b/source/System/MessageQueue.cpp index 8ff7a3b..3550e36 100644 --- a/source/System/MessageQueue.cpp +++ b/source/System/MessageQueue.cpp @@ -4,6 +4,9 @@ #ifdef _WIN32 #include typedef sp::Win32EventQueue ImplType; +#elif defined(__linux__) || defined(unix) || defined(__unix) || defined(__unix__) +#include +typedef sp::X11EventQueue ImplType; #else #error "No MessageQueue implementation exists" #endif