1
0
Fork 0

source/Platform/Unix: stub implementation

This commit is contained in:
Henrik Hautakoski 2019-06-01 01:13:44 +02:00
parent 4d69ff3a18
commit 6464838159
20 changed files with 498 additions and 2 deletions

View file

@ -4,6 +4,9 @@
#ifdef _WIN32
#include <Platform/Win32/Win32GLContext.h>
typedef sp::Win32GLContext ContextType;
#elif defined(__linux__) || defined(unix) || defined(__unix) || defined(__unix__)
#include <Platform/Unix/GLXContext.h>
typedef sp::GLXContext ContextType;
#else
#error "No GLContext implementation exists"
#endif

View file

@ -4,17 +4,27 @@
#include <Spectre/Game/FPSCounter.h>
#include <Spectre/Input/InputModule.h>
#include <Spectre/System/MessageHandler.h>
#include <Spectre/Game.h>
#include <Platform/PlatformMisc.h>
// TODO: move this to Application::create()
#ifdef _WIN32
#include <Platform/Win32/Win32Application.h>
#include <Spectre/Game.h>
typedef sp::Win32Application ApplicationType;
#elif defined(__linux__) || defined(unix) || defined(__unix) || defined(__unix__)
#include <Platform/Unix/UnixApplication.h>
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();

View file

@ -5,6 +5,9 @@
#ifdef _WIN32
#include <Platform/Win32/Win32Display.h>
typedef sp::Win32Display DisplayType;
#elif defined(__linux__) || defined(unix) || defined(__unix) || defined(__unix__)
#include <Platform/Unix/X11Display.h>
typedef sp::X11Display DisplayType;
#else
#error "No Display implementation exists"
#endif

View file

@ -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

View file

@ -0,0 +1,39 @@
#ifndef PLATFORM_UNIX_GLXCONTEXT_H
#define PLATFORM_UNIX_GLXCONTEXT_H
// X11 OpenGL Context (glx)
#include <Spectre/Display/GLContext.h>
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 */

View file

@ -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

View file

@ -0,0 +1,30 @@
#ifndef PLATFORM_UNIX_APPLICATION_H
#define PLATFORM_UNIX_APPLICATION_H
#include <Spectre/System/MessageQueue.h>
#include <Platform/PlatformApplication.h>
#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 */

View file

@ -0,0 +1,15 @@
#include <Platform/PlatformMisc.h>
namespace sp {
void PlatformMisc::GetDisplayModes(std::vector<DisplayMode>& modes)
{
}
DisplayMode PlatformMisc::GetDesktopMode()
{
return DisplayMode();
}
} // namespace sp

View file

@ -0,0 +1,31 @@
#include <errno.h>
#include <time.h>
#include <Spectre/System/System.h>
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

View file

@ -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

View file

@ -0,0 +1,40 @@
#ifndef PLATFORM_UNIX_X11DISPLAY_H
#define PLATFORM_UNIX_X11DISPLAY_H
#include <Platform/PlatformDisplay.h>
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 */

View file

@ -0,0 +1,11 @@
#include "X11EventQueue.h"
namespace sp {
bool X11EventQueue::poll(Event& event)
{
return false;
}
} //namespace sp

View file

@ -0,0 +1,18 @@
#ifndef PLATFORM_UNIX_X11_EVENT_QUEUE_H
#define PLATFORM_UNIX_X11_EVENT_QUEUE_H
#include <Spectre/System/Event.h>
#include <Platform/PlatformEventQueue.h>
namespace sp {
class X11EventQueue : public PlatformEventQueue
{
public :
virtual bool poll(Event& event);
};
} // namespace sp
#endif /* PLATFORM_UNIX_X11_EVENT_QUEUE_H */

View file

@ -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

View file

@ -0,0 +1,21 @@
#ifndef PLATFORM_UNIX_X11INPUT_H
#define PLATFORM_UNIX_X11INPUT_H
#include <Platform/PlatformInput.h>
namespace sp {
class X11Input : public PlatformInput
{
public :
virtual Keyboard* createKeyboard();
virtual Mouse* createMouse();
virtual void update();
};
} // namespace sp
#endif /* PLATFORM_UNIX_X11INPUT_H */

View file

@ -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

View file

@ -0,0 +1,25 @@
#ifndef PLATFORM_UNIX_X11KEYBOARD_H
#define PLATFORM_UNIX_X11KEYBOARD_H
#include <Spectre/Input/Keyboard.h>
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 */

View file

@ -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

View file

@ -0,0 +1,31 @@
#ifndef PLATFORM_UNIX_X11MOUSE_H
#define PLATFORM_UNIX_X11MOUSE_H
#include <Spectre/Input/Mouse.h>
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 */

View file

@ -4,6 +4,9 @@
#ifdef _WIN32
#include <Platform/Win32/Win32EventQueue.h>
typedef sp::Win32EventQueue ImplType;
#elif defined(__linux__) || defined(unix) || defined(__unix) || defined(__unix__)
#include <Platform/Unix/X11EventQueue.h>
typedef sp::X11EventQueue ImplType;
#else
#error "No MessageQueue implementation exists"
#endif