Move everything from global namespace to "sp" namespace
When writing the X11 (linux) implementation there was a problem with X11 defining a "Display" type and we also have a Display class in the engine. So to fix that problem and minimize the risk for running into other name conflicts. We move everything from global namespace.
This commit is contained in:
parent
9da8addeb2
commit
e10daeaaa6
120 changed files with 551 additions and 105 deletions
|
|
@ -2,6 +2,8 @@
|
|||
#include <cstdio>
|
||||
#include <Spectre/Core/String.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
std::string core::to_string(unsigned int value)
|
||||
{
|
||||
char buf[32];
|
||||
|
|
@ -23,3 +25,5 @@ std::string core::to_string(float value, unsigned int precision)
|
|||
sprintf(buf, format.c_str(), value);
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
} // namespace sp::core
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include <Spectre/System/SystemEvent.h>
|
||||
#include <Platform/PlatformDisplay.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
#define CAPTION_DEFAULT "Spectre"
|
||||
#define ICON_DEFAULT "./assets/app.ico"
|
||||
|
||||
|
|
@ -147,4 +149,6 @@ void Display::onReshape(int width, int height)
|
|||
{
|
||||
// Resize context if the windows resizes.
|
||||
m_context->setSize(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Display/DisplayDescription.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
DisplayDescription::DisplayDescription() :
|
||||
mode (),
|
||||
decoration (DisplayDecorate::Default)
|
||||
|
|
@ -11,4 +13,6 @@ DisplayDescription::DisplayDescription(DisplayMode mode, unsigned decoration) :
|
|||
mode (mode),
|
||||
decoration (decoration)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,9 +3,11 @@
|
|||
#include <Platform/PlatformMisc.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace sp {
|
||||
|
||||
struct DisplayModeCmp
|
||||
{
|
||||
inline bool operator() (const DisplayMode& a, const DisplayMode& b)
|
||||
inline bool operator() (const DisplayMode& a, const DisplayMode& b)
|
||||
{
|
||||
if (a.bpp == b.bpp) {
|
||||
if (a.width == b.width) {
|
||||
|
|
@ -51,4 +53,6 @@ std::vector<DisplayMode> DisplayMode::getFullscreenModes()
|
|||
DisplayMode DisplayMode::getDesktopMode()
|
||||
{
|
||||
return PlatformMisc::GetDesktopMode();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,11 +3,13 @@
|
|||
|
||||
#ifdef _WIN32
|
||||
#include <Platform/Win32/Win32GLContext.h>
|
||||
typedef Win32GLContext ContextType;
|
||||
typedef sp::Win32GLContext ContextType;
|
||||
#else
|
||||
#error "No GLContext implementation exists"
|
||||
#endif
|
||||
|
||||
namespace sp {
|
||||
|
||||
GLContext* GLContext::create()
|
||||
{
|
||||
return new ContextType();
|
||||
|
|
@ -17,3 +19,5 @@ GLContext::~GLContext()
|
|||
{
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include <Platform/Win32/Win32Application.h>
|
||||
#include <Spectre/Game.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Game::Game()
|
||||
{
|
||||
m_platform = new Win32Application();
|
||||
|
|
@ -64,7 +66,7 @@ void Game::gameLoop()
|
|||
m_fpsCounter.addFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Game::processEvents()
|
||||
{
|
||||
|
|
@ -107,3 +109,5 @@ FPSCounter& Game::getFpsCounter()
|
|||
{
|
||||
return m_fpsCounter;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#include <Spectre/Game/FPSCounter.h>
|
||||
#include <Spectre/System/System.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
FPSCounter::FPSCounter() :
|
||||
m_fps (60.0f),
|
||||
m_updateRate (2000)
|
||||
|
|
@ -34,7 +36,7 @@ void FPSCounter::setUpdateRate(unsigned int ups)
|
|||
|
||||
bool FPSCounter::update()
|
||||
{
|
||||
unsigned int current = System::getMilliseconds();
|
||||
unsigned int current = system::getMilliseconds();
|
||||
unsigned int elapsed = current - m_time;
|
||||
|
||||
if (elapsed >= m_updateRate) {
|
||||
|
|
@ -50,6 +52,8 @@ bool FPSCounter::update()
|
|||
|
||||
void FPSCounter::reset()
|
||||
{
|
||||
m_time = System::getMilliseconds();
|
||||
m_time = system::getMilliseconds();
|
||||
m_count = 0;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@
|
|||
#include <Spectre/Game/GameTime.h>
|
||||
#include <Spectre/System/System.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
GameTime::GameTime(unsigned long updates_per_sec)
|
||||
{
|
||||
m_acc = 0;
|
||||
m_current = System::getMilliseconds();
|
||||
m_current = system::getMilliseconds();
|
||||
m_lastUpdate = m_current;
|
||||
setTimeStep(updates_per_sec);
|
||||
}
|
||||
|
|
@ -67,10 +69,12 @@ void GameTime::accumulateTime()
|
|||
|
||||
void GameTime::updateTime()
|
||||
{
|
||||
m_current = System::getMilliseconds();
|
||||
m_current = system::getMilliseconds();
|
||||
|
||||
// Just to be safe. check so we don't get a negative interval.
|
||||
if (m_current < m_lastUpdate) {
|
||||
m_lastUpdate = m_current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include <algorithm>
|
||||
|
||||
namespace sp {
|
||||
|
||||
static bool compare_renderable(const Renderable2D* a, const Renderable2D* b) {
|
||||
|
||||
if (a->getZOrder() != b->getZOrder()) {
|
||||
|
|
@ -256,4 +258,6 @@ void BatchRenderer2D::drawBatch(Batch& batch)
|
|||
if (batch.type == RenderType_UI) {
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#include <Spectre/Graphics/Renderable.h>
|
||||
#include <Spectre/Graphics/DefaultRenderer2D.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
DefaultRenderer2D::DefaultRenderer2D()
|
||||
{
|
||||
m_shader.create();
|
||||
|
|
@ -69,4 +71,6 @@ void DefaultRenderer2D::render()
|
|||
|
||||
m_shader.disable();
|
||||
m_queue.clear();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -7,6 +7,8 @@
|
|||
#include <Spectre/Math/Math.h>
|
||||
#include "Font/FreeTypeDriver.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
Font::Font() :
|
||||
m_driver (new FreeTypeDriver())
|
||||
{
|
||||
|
|
@ -124,3 +126,5 @@ const Texture* Font::getTexture() const
|
|||
{
|
||||
return &m_cacheTextureA.texture;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include "FontDriver.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
FontDriver::FontDriver() :
|
||||
m_hinting (true)
|
||||
{
|
||||
|
|
@ -9,4 +11,6 @@ m_hinting (true)
|
|||
void FontDriver::setHinting(bool value)
|
||||
{
|
||||
m_hinting = value;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -6,6 +6,8 @@
|
|||
#include <Spectre/Graphics/Image.h>
|
||||
#include <Spectre/Graphics/Font.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class FontDriver
|
||||
{
|
||||
public :
|
||||
|
|
@ -28,4 +30,6 @@ protected :
|
|||
bool m_hinting;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_FONT_FONTDRIVER_H */
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include "FreeTypeError.h"
|
||||
#include "FreeTypeDriver.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
class LibWrapper
|
||||
{
|
||||
public :
|
||||
|
|
@ -165,4 +167,6 @@ Font::Glyph FreeTypeDriver::loadGlyph(unsigned int codepoint, Image& img, unsign
|
|||
std::string FreeTypeDriver::getName()
|
||||
{
|
||||
return m_face->family_name;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
@ -5,8 +5,11 @@
|
|||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
#include <string>
|
||||
#include "FontDriver.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
class FreeTypeDriver : public FontDriver
|
||||
{
|
||||
public:
|
||||
|
|
@ -26,4 +29,6 @@ private :
|
|||
FT_Face m_face;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_FONT_FREETYPEDRIVER_H */
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#include <Spectre/Graphics/Image.h>
|
||||
#include "ImageLoader.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
static ImageLoader _loader;
|
||||
|
||||
Image::Image() :
|
||||
|
|
@ -207,3 +209,5 @@ const unsigned char* Image::getPixels() const
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -21,6 +21,8 @@
|
|||
#include <cstdio>
|
||||
#include <vector>
|
||||
|
||||
namespace sp {
|
||||
|
||||
bool ImageLoader::loadFromFile(const char *filename, Image& img)
|
||||
{
|
||||
FILE *fd = fopen(filename, "rb");
|
||||
|
|
@ -59,7 +61,7 @@ bool ImageLoader::loadFromMemory(const void *data, unsigned size, Image& img)
|
|||
// TODO: Support more formats.
|
||||
bool ImageLoader::saveToFile(const Image& img, const char *filename)
|
||||
{
|
||||
std::string ext = File::getExtension(filename);
|
||||
std::string ext = file::getExtension(filename);
|
||||
std::vector<unsigned char> encoded_data;
|
||||
|
||||
if (ext == "png") {
|
||||
|
|
@ -129,3 +131,5 @@ bool ImageLoader::encodePNG(const Image& img, std::vector<unsigned char>& data)
|
|||
m_error = stbi_failure_reason();
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
#include <Spectre/Math/Vector2.h>
|
||||
#include <vector>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class ImageLoader
|
||||
{
|
||||
public :
|
||||
|
|
@ -30,4 +32,6 @@ protected :
|
|||
std::string m_error;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_GRAPHICS_IMAGE_LOADER_H */
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#include <Spectre/Graphics/Texture.h>
|
||||
#include <Spectre/Graphics/RenderState.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
RenderState::RenderState() :
|
||||
m_texture (0),
|
||||
m_shader (0)
|
||||
|
|
@ -45,4 +47,6 @@ void RenderState::cleanup()
|
|||
if (m_shader) {
|
||||
m_shader->disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Graphics/Renderable.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Renderable2D::Renderable2D() :
|
||||
m_zorder (0)
|
||||
{
|
||||
|
|
@ -24,4 +26,6 @@ unsigned char Renderable2D::getZOrder() const
|
|||
void Renderable2D::setZOrder(unsigned char value)
|
||||
{
|
||||
m_zorder = value;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
#include <Spectre/Graphics/Renderer2D.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Renderer2D::Renderer2D() :
|
||||
m_camera (NULL)
|
||||
{
|
||||
|
|
@ -13,3 +15,5 @@ void Renderer2D::setCamera(const Camera2D& camera)
|
|||
{
|
||||
m_camera = &camera;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
#include <Spectre/Graphics/OpenGL.h>
|
||||
#include <Spectre/Graphics/Shader.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Shader::Shader(Type type, const std::string& name) :
|
||||
m_name (name)
|
||||
{
|
||||
|
|
@ -35,7 +37,7 @@ bool Shader::loadFromFile(const std::string& file)
|
|||
|
||||
// If this shader does not have a name, pick the filename.
|
||||
if (m_name.length() < 1) {
|
||||
m_name = File::getBasename(file);
|
||||
m_name = file::getBasename(file);
|
||||
}
|
||||
|
||||
// Load file into memory.
|
||||
|
|
@ -98,3 +100,5 @@ std::string Shader::fetchErrorLog()
|
|||
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
#include <Spectre/Graphics/ShaderProgram.h>
|
||||
#include <Spectre/System/File.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
ShaderProgram::ShaderProgram() :
|
||||
m_id (0)
|
||||
{
|
||||
|
|
@ -36,7 +38,7 @@ void ShaderProgram::addShader(const Shader& shader)
|
|||
|
||||
bool ShaderProgram::loadFromFile(const std::string& filename)
|
||||
{
|
||||
std::string extension = File::getExtension(filename);
|
||||
std::string extension = file::getExtension(filename);
|
||||
|
||||
// Meta file. load real shaders.
|
||||
if (extension == "shader.glsl") {
|
||||
|
|
@ -191,3 +193,5 @@ std::string ShaderProgram::fetchErrorLog()
|
|||
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
#include <Spectre/Graphics/Texture.h>
|
||||
#include <Spectre/Graphics/Sprite.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Sprite::Sprite() :
|
||||
m_texture (NULL)
|
||||
{
|
||||
|
|
@ -114,4 +116,6 @@ void Sprite::updateGeometry()
|
|||
void Sprite::render(Renderer2D& renderer) const
|
||||
{
|
||||
renderer.draw(this);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
#include <Spectre/Graphics/Renderer2D.h>
|
||||
#include <Spectre/Graphics/Text.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Text::Text() :
|
||||
m_font (NULL),
|
||||
m_size (22),
|
||||
|
|
@ -173,4 +175,6 @@ void Text::updateGeometry() const
|
|||
void Text::render(Renderer2D& renderer) const
|
||||
{
|
||||
renderer.draw(this);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
#include <Spectre/Graphics/OpenGL.h>
|
||||
#include <Spectre/Graphics/Texture.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
namespace {
|
||||
|
||||
GLint pixelFormatToInternal(enum PixelFormat format) {
|
||||
|
|
@ -252,3 +254,5 @@ bool Texture::operator!=(const Texture* other) const
|
|||
{
|
||||
return m_id != other->m_id;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Graphics/Transformable.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Transformable::Transformable() :
|
||||
m_position (0.0f, 0.0f),
|
||||
m_scale (1.0f, 1.0f),
|
||||
|
|
@ -92,4 +94,6 @@ const Transform& Transformable::getTransform() const
|
|||
m_transformNeedsUpdate = false;
|
||||
}
|
||||
return m_transform;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Graphics/Vertex2D.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Vertex2D::Vertex2D() :
|
||||
position (0.0f),
|
||||
color (1.0f),
|
||||
|
|
@ -28,3 +30,5 @@ color (_color),
|
|||
uv (_uv)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
#include <Spectre/Graphics/OpenGL.h>
|
||||
#include <string>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Graphics::Graphics(PlatformApplication *platform)
|
||||
{
|
||||
m_width = 800;
|
||||
|
|
@ -87,3 +89,5 @@ void Graphics::swapBuffers()
|
|||
{
|
||||
m_display->swapBuffers();
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Input/InputDevice.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
InputDevice::~InputDevice()
|
||||
{
|
||||
}
|
||||
|
|
@ -8,3 +10,5 @@ InputDevice::~InputDevice()
|
|||
void InputDevice::init()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
#include <Spectre/Input/Keyboard.h>
|
||||
#include <Spectre/Input/InputEvent.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
InputEvent::InputEvent(Type type) :
|
||||
type (type)
|
||||
{
|
||||
|
|
@ -17,3 +19,5 @@ std::string InputEvent::MouseButtonEvent::getName() const
|
|||
{
|
||||
return Mouse::getButtonName(button);
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
|
||||
#include <Spectre/Input/InputListener.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
void InputListener::onInputEvent(const InputEvent& event)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -6,6 +6,8 @@
|
|||
#include <Spectre/Input/InputDevice.h>
|
||||
#include <Spectre/Input/InputModule.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
InputModule::InputModule(PlatformInput *platform) :
|
||||
m_platform (platform)
|
||||
{
|
||||
|
|
@ -94,3 +96,5 @@ void InputModule::dispatch()
|
|||
|
||||
m_buffer.clear();
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Input/Keyboard.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
struct keyentry
|
||||
{
|
||||
Key::Type type;
|
||||
|
|
@ -110,3 +112,5 @@ std::string Keyboard::getKeyName(Key::Type key)
|
|||
}
|
||||
return table[key].name;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Input/Mouse.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Mouse::~Mouse()
|
||||
{
|
||||
}
|
||||
|
|
@ -18,3 +20,5 @@ std::string Mouse::getButtonName(MouseButton::Type button)
|
|||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/Math/Color.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
const Color Color::Black (0 , 0 , 0 , 255);
|
||||
const Color Color::White (255, 255, 255, 255);
|
||||
const Color Color::Red (255, 0 , 0 , 255);
|
||||
|
|
@ -126,3 +128,5 @@ Color operator *(const Color& c, unsigned int s)
|
|||
{
|
||||
return Color(c.r * s, c.g * s, c.b * s, c.a * s);
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,18 +3,18 @@
|
|||
#include <cstdlib>
|
||||
#include <Spectre/Math/Math.h>
|
||||
|
||||
namespace math {
|
||||
namespace sp {
|
||||
|
||||
#define LOG2INBASE10 0.30102999566f
|
||||
#define LOG2INBASE10 0.30102999566f
|
||||
|
||||
double log(double base, double value) {
|
||||
double math::log(double base, double value) {
|
||||
|
||||
return log10(value) / log10(base);
|
||||
}
|
||||
return ::log10(value) / ::log10(base);
|
||||
}
|
||||
|
||||
double log2(double value) {
|
||||
double math::log2(double value) {
|
||||
|
||||
return log10(value) / LOG2INBASE10;
|
||||
}
|
||||
return ::log10(value) / LOG2INBASE10;
|
||||
}
|
||||
|
||||
}; // namespace math
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
#include <cstdlib>
|
||||
#include <Spectre/Math/Math.h>
|
||||
|
||||
namespace math {
|
||||
|
||||
namespace sp { namespace math
|
||||
{
|
||||
float rand(float min, float max) {
|
||||
|
||||
float r = ((float) ::rand()) / RAND_MAX;
|
||||
|
|
@ -50,8 +50,8 @@ namespace math {
|
|||
Matrix4f rotation(float theta) {
|
||||
|
||||
float r = deg2rad(theta);
|
||||
float s = std::sin(r);
|
||||
float c = std::cos(r);
|
||||
float s = ::std::sin(r);
|
||||
float c = ::std::cos(r);
|
||||
|
||||
return Matrix4f(
|
||||
c, -s, 0.0f, 0.0f,
|
||||
|
|
@ -94,4 +94,5 @@ namespace math {
|
|||
|
||||
return Vector3f(matrix.e[8], matrix.e[9], matrix.e[10]);
|
||||
}
|
||||
};
|
||||
|
||||
} } // namespace sp::math
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#include <Spectre/Math/Math.h>
|
||||
#include <Spectre/Math/Transform.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Transform::Transform() :
|
||||
m_matrix (Matrix4f::Identity)
|
||||
{
|
||||
|
|
@ -155,4 +157,6 @@ Transform& operator*=(Transform& a, const Transform& other)
|
|||
Vector2f operator*(const Transform& transform, const Vector2f& vec)
|
||||
{
|
||||
return transform.transformPoint(vec);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#ifndef SPECTRE_PLATFORM_H
|
||||
#define SPECTRE_PLATFORM_H
|
||||
|
||||
namespace sp {
|
||||
|
||||
class PlatformInput;
|
||||
class PlatformDisplay;
|
||||
class MessageQueue;
|
||||
|
|
@ -22,4 +24,6 @@ public :
|
|||
virtual void update() = 0;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_PLATFORM_H */
|
||||
|
|
@ -4,11 +4,13 @@
|
|||
|
||||
#ifdef _WIN32
|
||||
#include <Platform/Win32/Win32Display.h>
|
||||
typedef Win32Display DisplayType;
|
||||
typedef sp::Win32Display DisplayType;
|
||||
#else
|
||||
#error "No Display implementation exists"
|
||||
#endif
|
||||
|
||||
namespace sp {
|
||||
|
||||
PlatformDisplay* PlatformDisplay::make(Display* parent)
|
||||
{
|
||||
DisplayType* disp = new DisplayType();
|
||||
|
|
@ -29,4 +31,6 @@ void PlatformDisplay::onReshape(int width, int height)
|
|||
{
|
||||
// Forward to parent.
|
||||
m_parent->onReshape(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -8,6 +8,8 @@
|
|||
// Low-level platform dependant API.
|
||||
#include <string>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Display;
|
||||
|
||||
class PlatformDisplay
|
||||
|
|
@ -46,7 +48,9 @@ protected :
|
|||
|
||||
private :
|
||||
|
||||
Display* m_parent;
|
||||
Display * m_parent;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* SPECTRE_PLATFORM_DISPLAY_H */
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
#ifndef PLATFORM_INPUT_H
|
||||
#define PLATFORM_INPUT_H
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Keyboard;
|
||||
class Mouse;
|
||||
|
||||
|
|
@ -15,4 +17,6 @@ public :
|
|||
virtual void update() = 0;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* PLATFORM_INPUT_H */
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@
|
|||
#define PLATFORM_MISC_H
|
||||
|
||||
#include <Spectre/Display/DisplayMode.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class DisplayMode;
|
||||
|
||||
class PlatformMisc
|
||||
|
|
@ -16,4 +17,6 @@ public:
|
|||
static DisplayMode GetDesktopMode();
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* PLATFORM_MISC_H */
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#include "Win32Mouse.h"
|
||||
#include "Win32Application.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
void Win32Application::init()
|
||||
{
|
||||
}
|
||||
|
|
@ -94,3 +96,5 @@ LRESULT Win32Application::processMessage(MSG msg)
|
|||
// Message was not intercepted. Pass down to window.
|
||||
return DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -9,6 +9,8 @@
|
|||
#include <Spectre/System/MessageQueue.h>
|
||||
#include <Platform/PlatformApplication.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Win32Application : public PlatformApplication
|
||||
{
|
||||
public :
|
||||
|
|
@ -35,4 +37,6 @@ protected :
|
|||
MessageQueue m_messageQueue;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* WIN32_PLATFORM_H */
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include "Win32Internal.h"
|
||||
#include "Win32Display.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
#define WND_CLASSNAME "SPECTRE_WIN32_WNDCLASS"
|
||||
|
||||
static bool firstTime = true;
|
||||
|
|
@ -258,3 +260,5 @@ LRESULT CALLBACK Win32Display::staticWndProc(HWND handle, UINT message, WPARAM w
|
|||
}
|
||||
return DefWindowProc(handle, message, wParam, lParam);
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -6,6 +6,8 @@
|
|||
#include <Platform/PlatformDisplay.h>
|
||||
#include <Windows.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Win32Display : public PlatformDisplay
|
||||
{
|
||||
public :
|
||||
|
|
@ -63,4 +65,6 @@ protected :
|
|||
Vector2u m_minSize;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* PLATFORM_WIN32_DISPLAY_H */
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#include "Win32Internal.h"
|
||||
#include "Win32GLContext.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
// Ensure that OpenGL extensions are loaded.
|
||||
static void ensureExtensionsLoaded(HDC dc)
|
||||
{
|
||||
|
|
@ -175,4 +177,6 @@ bool Win32GLContext::setPixelFormat()
|
|||
return ::SetPixelFormat(m_deviceContext, format, &pfd);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -7,6 +7,8 @@
|
|||
#include <Windows.h>
|
||||
#include <Spectre/Display/GLContext.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Win32GLContext : public GLContext
|
||||
{
|
||||
public :
|
||||
|
|
@ -45,4 +47,6 @@ private :
|
|||
HGLRC m_renderContext;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* PLATFORM_WIN32_GLCONTEXT_H */
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#include "Win32Mouse.h"
|
||||
#include "Win32Input.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
Win32InputMsgBuffer Win32Input::inputMsgBuffer;
|
||||
|
||||
Win32InputMsgBuffer::Win32InputMsgBuffer() :
|
||||
|
|
@ -24,4 +26,6 @@ Mouse* Win32Input::createMouse()
|
|||
|
||||
void Win32Input::update()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -5,6 +5,8 @@
|
|||
#include <Windows.h>
|
||||
#include <Platform/PlatformInput.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
#define WIN32_INPUT_BUFFER_QUEUE_MAX_SIZE 64
|
||||
|
||||
struct Win32InputMsgBuffer {
|
||||
|
|
@ -29,4 +31,6 @@ public :
|
|||
static Win32InputMsgBuffer inputMsgBuffer;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* PLATFORM_WIN32_INPUT_H */
|
||||
|
|
@ -7,6 +7,8 @@
|
|||
#include "Win32Keyboard.h"
|
||||
#include "Win32MsgBuffer.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
static Win32MsgBuffer msg_buf;
|
||||
|
||||
static const Key::Type deviceToKey[256] = {
|
||||
|
|
@ -117,3 +119,5 @@ bool Win32Keyboard::handleMessage(MSG message)
|
|||
{
|
||||
return msg_buf.postMessage(message);
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -5,6 +5,8 @@
|
|||
#include <windows.h>
|
||||
#include <Spectre/Input/Keyboard.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Win32Keyboard : public Keyboard
|
||||
{
|
||||
public :
|
||||
|
|
@ -25,4 +27,6 @@ protected :
|
|||
bool m_hasFocus;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* PLATFORM_WIN32_KEYBOARD_H */
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#include <Windows.h>
|
||||
#include <Platform/PlatformMisc.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
void PlatformMisc::GetDisplayModes(std::vector<DisplayMode>& modes)
|
||||
{
|
||||
DEVMODE dev;
|
||||
|
|
@ -20,3 +22,5 @@ DisplayMode PlatformMisc::GetDesktopMode()
|
|||
}
|
||||
return DisplayMode();
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -6,6 +6,8 @@
|
|||
#include "Win32Input.h"
|
||||
#include "Win32Mouse.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
static Win32MsgBuffer msg_buf;
|
||||
|
||||
static Vector2f _normalizePos(int x, int y, RECT area)
|
||||
|
|
@ -112,4 +114,6 @@ void Win32Mouse::update(InputModule *input)
|
|||
bool Win32Mouse::handleMessage(MSG message)
|
||||
{
|
||||
return msg_buf.postMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -5,6 +5,8 @@
|
|||
#include <Windows.h>
|
||||
#include <Spectre/Input/Mouse.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
class Win32Mouse : public Mouse
|
||||
{
|
||||
public :
|
||||
|
|
@ -31,4 +33,6 @@ protected :
|
|||
bool m_tracked;
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* PLATFORM_WIN32_MOUSE_H */
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#include <Spectre/System/Log.h>
|
||||
#include "Win32MsgBuffer.h"
|
||||
|
||||
namespace sp {
|
||||
|
||||
Win32MsgBuffer::Win32MsgBuffer() :
|
||||
index (0)
|
||||
{
|
||||
|
|
@ -15,4 +17,6 @@ bool Win32MsgBuffer::postMessage(MSG msg)
|
|||
}
|
||||
log("Win32MsgBuffer: Queue overflow\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include <Windows.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
#define WIN32_MSG_BUFFER_MAX_SIZE 64
|
||||
|
||||
struct Win32MsgBuffer {
|
||||
|
|
@ -15,4 +17,6 @@ struct Win32MsgBuffer {
|
|||
bool postMessage(MSG msg);
|
||||
};
|
||||
|
||||
} // namespace sp
|
||||
|
||||
#endif /* PLATFORM_WIN32_MSG_BUFFER_H */
|
||||
|
|
@ -9,9 +9,11 @@ static LARGE_INTEGER getFrequency() {
|
|||
return freq;
|
||||
}
|
||||
|
||||
unsigned long System::getMilliseconds()
|
||||
namespace sp {
|
||||
|
||||
unsigned long system::getMilliseconds()
|
||||
{
|
||||
static LARGE_INTEGER freq = getFrequency();
|
||||
static LARGE_INTEGER freq = ::getFrequency();
|
||||
|
||||
LARGE_INTEGER cnt;
|
||||
::QueryPerformanceCounter(&cnt);
|
||||
|
|
@ -19,10 +21,12 @@ unsigned long System::getMilliseconds()
|
|||
cnt.QuadPart *= 1000;
|
||||
cnt.QuadPart /= freq.QuadPart;
|
||||
|
||||
return (unsigned long) cnt.QuadPart;
|
||||
return (unsigned long)cnt.QuadPart;
|
||||
}
|
||||
|
||||
void System::sleep(int milliseconds)
|
||||
void system::sleep(int milliseconds)
|
||||
{
|
||||
::Sleep(milliseconds);
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
#include <Spectre/Math/Math.h>
|
||||
#include <Spectre/Scene/Camera2D.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
Camera2D::Camera2D() :
|
||||
m_position (0.0f, 0.0f),
|
||||
m_rotation (0.0f),
|
||||
|
|
@ -171,4 +173,6 @@ const Transform& Camera2D::getTransform() const
|
|||
m_viewNeedsUpdate = false;
|
||||
}
|
||||
return m_view;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
#include <stdio.h>
|
||||
#include <Spectre/System/File.h>
|
||||
|
||||
namespace File
|
||||
namespace sp { namespace file
|
||||
{
|
||||
std::string getBasename(const std::string& path) {
|
||||
|
||||
|
|
@ -37,4 +37,4 @@ namespace File
|
|||
}
|
||||
return buf;
|
||||
}
|
||||
};
|
||||
} } // namespace sp::file
|
||||
|
|
|
|||
|
|
@ -3,11 +3,14 @@
|
|||
#include <stdio.h>
|
||||
#include <Spectre/System/Log.h>
|
||||
|
||||
void log(const char *fmt, ...) {
|
||||
namespace sp
|
||||
{
|
||||
void log(const char *fmt, ...) {
|
||||
|
||||
va_list vl;
|
||||
va_list vl;
|
||||
|
||||
va_start(vl, fmt);
|
||||
vfprintf(stderr, fmt, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
va_start(vl, fmt);
|
||||
vfprintf(stderr, fmt, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -2,6 +2,10 @@
|
|||
#include <Spectre/Display/Display.h>
|
||||
#include <Spectre/System/MessageHandler.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
void MessageHandler::onSizeChanged(Display* display, int width, int height)
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <Spectre/System/MessageQueue.h>
|
||||
|
||||
namespace sp {
|
||||
|
||||
void MessageQueue::postEvent(SysEvent& event)
|
||||
{
|
||||
m_queue.push_back(event);
|
||||
|
|
@ -20,3 +22,5 @@ bool MessageQueue::isEmpty() const
|
|||
{
|
||||
return m_queue.empty();
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
|
||||
#include <Spectre/System/SystemEvent.h>
|
||||
|
||||
SysEvent::SysEvent(Type type) :
|
||||
namespace sp {
|
||||
|
||||
SysEvent::SysEvent(Type type) :
|
||||
type (type)
|
||||
{
|
||||
}
|
||||
|
|
@ -14,3 +16,5 @@ SysEvent SysEvent::sizeEvent(Display *display, int width, int height)
|
|||
event.size.height = height;
|
||||
return event;
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
Loading…
Add table
Add a link
Reference in a new issue