1
0
Fork 0

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:
Henrik Hautakoski 2019-09-29 23:47:57 +02:00
parent 9da8addeb2
commit e10daeaaa6
No known key found for this signature in database
GPG key ID: 96765B12FEAC4745
120 changed files with 551 additions and 105 deletions

View file

@ -1,27 +1,30 @@
#include <iostream>
#include <Spectre/Graphics/BatchRenderer2D.h> #include <Spectre/Graphics/BatchRenderer2D.h>
#include <Spectre/Input/InputModule.h> #include <Spectre/Input/InputModule.h>
#include <Spectre/Graphics/Font.h> #include <Spectre/Graphics/Font.h>
#include <Spectre/Graphics/Text.h> #include <Spectre/Graphics/Text.h>
#include "Game.h" #include "Game.h"
Font smallFont; sp::Font smallFont;
Font myFont; sp::Font myFont;
Font fntLarge; sp::Font fntLarge;
Text myText; sp::Text myText;
Text txtLarge; sp::Text txtLarge;
Text txtKerning; sp::Text txtKerning;
Text fpsText; sp::Text fpsText;
Text txtSmall; sp::Text txtSmall;
Camera2D guiCamera; sp::Camera2D guiCamera;
BatchRenderer2D *renderer; sp::BatchRenderer2D *renderer;
void TextExample::init() void TextExample::init()
{ {
Graphics* g = getGraphics(); sp::Graphics* g = getGraphics();
std::cout << g->getVersion() << std::endl;
g->setClearColor(52.0f / 255.0f, 58.0f / 255.0f, 80.0f / 255.0f); g->setClearColor(52.0f / 255.0f, 58.0f / 255.0f, 80.0f / 255.0f);
@ -30,18 +33,18 @@ void TextExample::init()
fntLarge.loadFromFile("assets/fonts/OPTIBelwe-Medium.otf"); fntLarge.loadFromFile("assets/fonts/OPTIBelwe-Medium.otf");
myText.setFont(myFont); myText.setFont(myFont);
myText.setColor(Color::Green); myText.setColor(sp::Color::Green);
myText.setString("Hello"); myText.setString("Hello");
myText.setPosition(25.0f, 50.0f); myText.setPosition(25.0f, 50.0f);
txtLarge.setFont(myFont); txtLarge.setFont(myFont);
txtLarge.setColor(Color(200, 100, 0)); txtLarge.setColor(sp::Color(200, 100, 0));
txtLarge.setString("Large Text, Looks good?"); txtLarge.setString("Large Text, Looks good?");
txtLarge.setPosition(300.0f, 150.0f); txtLarge.setPosition(300.0f, 150.0f);
txtLarge.setScale(2.0f); txtLarge.setScale(2.0f);
txtKerning.setFont(fntLarge); txtKerning.setFont(fntLarge);
txtKerning.setColor(Color(150, 0, 230)); txtKerning.setColor(sp::Color(150, 0, 230));
txtKerning.setString("Kerning: VA Ta"); txtKerning.setString("Kerning: VA Ta");
txtKerning.setPosition(150.0f, 200.0f); txtKerning.setPosition(150.0f, 200.0f);
@ -53,23 +56,23 @@ void TextExample::init()
fpsText.setString("FPS: 0"); fpsText.setString("FPS: 0");
fpsText.setPosition(10.0f, 10.0f); fpsText.setPosition(10.0f, 10.0f);
renderer = new BatchRenderer2D(); renderer = new sp::BatchRenderer2D();
} }
void TextExample::update(double dt) void TextExample::update(double dt)
{ {
InputModule* input = getInput(); sp::InputModule* input = getInput();
input->update(); input->update();
if (getFpsCounter().update()) { if (getFpsCounter().update()) {
std::string str = "FPS: " + core::to_string(getFpsCounter().getFPS(), 0); std::string str = "FPS: " + sp::core::to_string(getFpsCounter().getFPS(), 0);
fpsText.setString(str); fpsText.setString(str);
} }
} }
void TextExample::render() void TextExample::render()
{ {
Graphics* g = getGraphics(); sp::Graphics* g = getGraphics();
g->clearBuffer(); g->clearBuffer();

View file

@ -6,7 +6,7 @@
#include <Spectre/Input/InputListener.h> #include <Spectre/Input/InputListener.h>
#include <Spectre/Game.h> #include <Spectre/Game.h>
class TextExample : public Game, public InputListener class TextExample : public sp::Game, public sp::InputListener
{ {
protected : protected :

View file

@ -2,6 +2,8 @@
#ifndef SPECTRE_CORE_NONCOPYABLE_H #ifndef SPECTRE_CORE_NONCOPYABLE_H
#define SPECTRE_CORE_NONCOPYABLE_H #define SPECTRE_CORE_NONCOPYABLE_H
namespace sp {
class NonCopyable class NonCopyable
{ {
protected : protected :
@ -15,4 +17,6 @@ private :
NonCopyable& operator =(const NonCopyable&); NonCopyable& operator =(const NonCopyable&);
}; };
} // namespace sp
#endif /* SPECTRE_CORE_NONCOPYABLE_H */ #endif /* SPECTRE_CORE_NONCOPYABLE_H */

View file

@ -6,7 +6,7 @@
#include <string> #include <string>
namespace core namespace sp { namespace core
{ {
// Convertion functions from standard c/c++ types. // Convertion functions from standard c/c++ types.
@ -15,6 +15,6 @@ namespace core
std::string to_string(float value); std::string to_string(float value);
std::string to_string(float value, unsigned int precision); std::string to_string(float value, unsigned int precision);
}; } } // namespace sp::core
#endif /* SPECTRE_CORE_STRING_H */ #endif /* SPECTRE_CORE_STRING_H */

View file

@ -8,6 +8,8 @@
#include <Spectre/System/SystemEvent.h> #include <Spectre/System/SystemEvent.h>
#include <string> #include <string>
namespace sp {
class PlatformDisplay; class PlatformDisplay;
class GLContext; class GLContext;
@ -73,4 +75,6 @@ protected :
GLContext* m_context; GLContext* m_context;
}; };
} // namepsace sp
#endif /* SPECTRE_DISPLAY_DISPLAY_H */ #endif /* SPECTRE_DISPLAY_DISPLAY_H */

View file

@ -4,6 +4,8 @@
#include "DisplayMode.h" #include "DisplayMode.h"
namespace sp {
namespace DisplayDecorate { namespace DisplayDecorate {
enum Type { enum Type {
@ -27,4 +29,6 @@ public :
unsigned int decoration; unsigned int decoration;
}; };
} // namespace sp
#endif /* SPECTRE_DISPLAY_DISPLAYDESCRIPTION_H */ #endif /* SPECTRE_DISPLAY_DISPLAYDESCRIPTION_H */

View file

@ -4,6 +4,8 @@
#include <vector> #include <vector>
namespace sp {
class DisplayMode class DisplayMode
{ {
public : public :
@ -32,4 +34,6 @@ public :
unsigned int bpp; /* Bits per pixel. */ unsigned int bpp; /* Bits per pixel. */
}; };
} // namespace sp
#endif /* SPECTRE_DISPLAY_DISPLAYMODE_H */ #endif /* SPECTRE_DISPLAY_DISPLAYMODE_H */

View file

@ -4,6 +4,8 @@
#include <Spectre/Math/Vector2.h> #include <Spectre/Math/Vector2.h>
namespace sp {
class PlatformDisplay; class PlatformDisplay;
// Platform independant interface for OpenGL Contexts. // Platform independant interface for OpenGL Contexts.
@ -43,4 +45,6 @@ public :
virtual void swapBuffers() = 0; virtual void swapBuffers() = 0;
}; };
} // namespace sp
#endif /* DISPLAY_GLCONTEXT_H */ #endif /* DISPLAY_GLCONTEXT_H */

View file

@ -11,6 +11,8 @@ class MessageQueue;
class MessageHandler; class MessageHandler;
class PlatformApplication; class PlatformApplication;
namespace sp {
class Game class Game
{ {
public : public :
@ -60,4 +62,6 @@ private :
bool m_running; bool m_running;
}; };
}
#endif /* SPECTRE_GAME_H */ #endif /* SPECTRE_GAME_H */

View file

@ -4,6 +4,8 @@
// Simple FPS counter. // Simple FPS counter.
namespace sp {
class FPSCounter class FPSCounter
{ {
public : public :
@ -40,4 +42,6 @@ private :
float m_fps; float m_fps;
}; };
} // namespace sp
#endif /* SPECTRE_FPS_COUNTER_H */ #endif /* SPECTRE_FPS_COUNTER_H */

View file

@ -2,6 +2,8 @@
#ifndef SPECTRE_GAME_TIME_H #ifndef SPECTRE_GAME_TIME_H
#define SPECTRE_GAME_TIME_H #define SPECTRE_GAME_TIME_H
namespace sp {
class GameTime class GameTime
{ {
public : public :
@ -42,4 +44,6 @@ protected :
bool m_inLoop; bool m_inLoop;
}; };
} // namespace sp
#endif /* SPECTRE_GAME_TIME_H */ #endif /* SPECTRE_GAME_TIME_H */

View file

@ -4,6 +4,8 @@
#include <Spectre/Display/Display.h> #include <Spectre/Display/Display.h>
namespace sp {
class PlatformApplication; class PlatformApplication;
class Graphics class Graphics
@ -48,4 +50,6 @@ protected :
Display *m_display; Display *m_display;
}; };
} // namespace sp
#endif /* GRAPHICS_H */ #endif /* GRAPHICS_H */

View file

@ -10,8 +10,9 @@
#include <Spectre/Math/Matrix4.h> #include <Spectre/Math/Matrix4.h>
#include <vector> #include <vector>
class ShaderProgram; namespace sp {
class ShaderProgram;
class Texture; class Texture;
class BatchRenderer2D : public Renderer2D class BatchRenderer2D : public Renderer2D
@ -70,4 +71,6 @@ protected :
ShaderProgram m_spriteShader; ShaderProgram m_spriteShader;
}; };
} // namespace
#endif /* SPECTRE_BATCH_RENDERER2D_H */ #endif /* SPECTRE_BATCH_RENDERER2D_H */

View file

@ -5,6 +5,8 @@
#include <vector> #include <vector>
#include "Renderer2D.h" #include "Renderer2D.h"
namespace sp {
class DefaultRenderer2D : public Renderer2D class DefaultRenderer2D : public Renderer2D
{ {
public : public :
@ -22,4 +24,6 @@ protected :
ShaderProgram m_shader; ShaderProgram m_shader;
}; };
} // namespace
#endif /* SPECTRE_DEFAULT_RENDERER2D_H */ #endif /* SPECTRE_DEFAULT_RENDERER2D_H */

View file

@ -10,6 +10,8 @@
#include <Spectre/Math/Vector2.h> #include <Spectre/Math/Vector2.h>
#include <Spectre/Graphics/Texture.h> #include <Spectre/Graphics/Texture.h>
namespace sp {
class FontDriver; class FontDriver;
// TODO: Fixup this api :) // TODO: Fixup this api :)
@ -73,4 +75,6 @@ protected :
std::vector<unsigned char> m_rawData; std::vector<unsigned char> m_rawData;
}; };
}
#endif /* SPECTRE_GRAPHCIS_FONT_H */ #endif /* SPECTRE_GRAPHCIS_FONT_H */

View file

@ -8,6 +8,8 @@
#include <Spectre/Math/Vector2.h> #include <Spectre/Math/Vector2.h>
#include <Spectre/Graphics/PixelFormat.h> #include <Spectre/Graphics/PixelFormat.h>
namespace sp {
class Image class Image
{ {
public : public :
@ -59,4 +61,6 @@ private :
std::vector<unsigned char> m_pixels; std::vector<unsigned char> m_pixels;
}; };
} //namespace sp
#endif /* SPECTRE_GRAPHICS_IMAGE_H */ #endif /* SPECTRE_GRAPHICS_IMAGE_H */

View file

@ -1,6 +1,8 @@
#ifndef SPECTRE_GRAPHICS_PIXELFORMAT_H #ifndef SPECTRE_GRAPHICS_PIXELFORMAT_H
#define SPECTRE_GRAPHICS_PIXELFORMAT_H #define SPECTRE_GRAPHICS_PIXELFORMAT_H
namespace sp {
enum PixelFormat enum PixelFormat
{ {
PF_Unknown = 0, PF_Unknown = 0,
@ -9,4 +11,6 @@ enum PixelFormat
PF_Alpha = 3, // 1 byte alpha channel. PF_Alpha = 3, // 1 byte alpha channel.
}; };
} // namespace
#endif /* SPECTRE_GRAPHICS_PIXELFORMAT_H */ #endif /* SPECTRE_GRAPHICS_PIXELFORMAT_H */

View file

@ -2,6 +2,8 @@
#ifndef SPECTRE_GRAPHICS_RENDERSTATE_H #ifndef SPECTRE_GRAPHICS_RENDERSTATE_H
#define SPECTRE_GRAPHICS_RENDERSTATE_H #define SPECTRE_GRAPHICS_RENDERSTATE_H
namespace sp {
class ShaderProgram; class ShaderProgram;
class Texture; class Texture;
@ -24,4 +26,6 @@ protected :
const ShaderProgram *m_shader; const ShaderProgram *m_shader;
}; };
} // namespace sp
#endif /* SPECTRE_GRAPHICS_RENDERSTATE_H */ #endif /* SPECTRE_GRAPHICS_RENDERSTATE_H */

View file

@ -8,6 +8,8 @@
#include <Spectre/Math/Vector2.h> #include <Spectre/Math/Vector2.h>
#include <vector> #include <vector>
namespace sp {
class Renderer2D; class Renderer2D;
class ShaderProgram; class ShaderProgram;
class Texture; class Texture;
@ -43,4 +45,6 @@ protected :
unsigned char m_zorder; unsigned char m_zorder;
}; };
} // namespace sp
#endif /* SPECTRE_GRAPHCIS_RENDERABLE_H */ #endif /* SPECTRE_GRAPHCIS_RENDERABLE_H */

View file

@ -6,6 +6,8 @@
#include <Spectre/Graphics/ShaderProgram.h> #include <Spectre/Graphics/ShaderProgram.h>
#include <Spectre/Scene/Camera2D.h> #include <Spectre/Scene/Camera2D.h>
namespace sp {
class Renderer2D class Renderer2D
{ {
public : public :
@ -28,4 +30,6 @@ protected :
const Camera2D* m_camera; const Camera2D* m_camera;
}; };
} // namespace sp
#endif /* SPECTRE_GRAPHICS_RENDERER2D_H */ #endif /* SPECTRE_GRAPHICS_RENDERER2D_H */

View file

@ -4,6 +4,8 @@
#include <string> #include <string>
namespace sp {
class Shader class Shader
{ {
public : public :
@ -51,4 +53,6 @@ protected :
std::string m_error; std::string m_error;
}; };
} // namespace sp
#endif /* SPECTRE_GRAPHICS_SHADER_H */ #endif /* SPECTRE_GRAPHICS_SHADER_H */

View file

@ -6,6 +6,8 @@
#include <Spectre/Math/Matrix4.h> #include <Spectre/Math/Matrix4.h>
#include "Shader.h" #include "Shader.h"
namespace sp {
struct Color; struct Color;
class ShaderProgram class ShaderProgram
@ -83,4 +85,6 @@ protected :
mutable std::string m_error; mutable std::string m_error;
}; };
} // namespace sp
#endif /* SPECTRE_GRAPHICS_SHADER_PROGRAM_H */ #endif /* SPECTRE_GRAPHICS_SHADER_PROGRAM_H */

View file

@ -6,6 +6,8 @@
#include "Vertex2D.h" #include "Vertex2D.h"
#include "Renderable.h" #include "Renderable.h"
namespace sp {
class Texture; class Texture;
class Sprite : public Renderable2D class Sprite : public Renderable2D
@ -46,4 +48,6 @@ protected :
const Texture* m_texture; const Texture* m_texture;
}; };
} // namespace sp
#endif /* SPECTRE_GRAPHICS_SPRITE_H */ #endif /* SPECTRE_GRAPHICS_SPRITE_H */

View file

@ -8,6 +8,8 @@
#include <Spectre/Graphics/Transformable.h> #include <Spectre/Graphics/Transformable.h>
#include <Spectre/Graphics/Renderable.h> #include <Spectre/Graphics/Renderable.h>
namespace sp {
class Text : public Renderable2D class Text : public Renderable2D
{ {
public : public :
@ -88,4 +90,6 @@ private :
mutable std::vector<Vertex2D> m_vertices; mutable std::vector<Vertex2D> m_vertices;
}; };
} // namespace sp
#endif /* SPECTRE_GRAPHICS_TEXT_H */ #endif /* SPECTRE_GRAPHICS_TEXT_H */

View file

@ -10,6 +10,8 @@
// Basic OpenGL Texture object. // Basic OpenGL Texture object.
namespace sp {
class Texture : public NonCopyable class Texture : public NonCopyable
{ {
public: public:
@ -88,4 +90,6 @@ protected :
PixelFormat m_format; PixelFormat m_format;
}; };
} // namespace sp
#endif /* SPECTRE_GRAPHICS_TEXTURE_H */ #endif /* SPECTRE_GRAPHICS_TEXTURE_H */

View file

@ -5,6 +5,8 @@
#include <Spectre/Math/Transform.h> #include <Spectre/Math/Transform.h>
#include <Spectre/Math/Vector2.h> #include <Spectre/Math/Vector2.h>
namespace sp {
class Transformable class Transformable
{ {
public : public :
@ -56,4 +58,6 @@ private :
mutable Transform m_transform; mutable Transform m_transform;
}; };
} // namespace sp
#endif /* SPECTRE_GRAPHICS_TRANSFORMABLE_H */ #endif /* SPECTRE_GRAPHICS_TRANSFORMABLE_H */

View file

@ -5,6 +5,8 @@
#include <Spectre/Math/Vector2.h> #include <Spectre/Math/Vector2.h>
#include <Spectre/Math/Vector4.h> #include <Spectre/Math/Vector4.h>
namespace sp {
// Based on https://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php // Based on https://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php
enum VertexAttrib enum VertexAttrib
{ {
@ -27,4 +29,6 @@ struct Vertex2D
Vertex2D(Vector2f pos, Vector4f color, Vector2f uv = 0.0f); Vertex2D(Vector2f pos, Vector4f color, Vector2f uv = 0.0f);
}; };
} // namespace sp
#endif /* SPECTRE_GRAPHICS_VERTEX2D_H */ #endif /* SPECTRE_GRAPHICS_VERTEX2D_H */

View file

@ -4,6 +4,8 @@
#include "InputModule.h" #include "InputModule.h"
namespace sp {
class InputDevice class InputDevice
{ {
friend class InputModule; friend class InputModule;
@ -18,4 +20,6 @@ protected :
virtual void update(InputModule *input) = 0; virtual void update(InputModule *input) = 0;
}; };
} // namespace sp
#endif /* SPECTRE_INTPUT_DEVICE_H */ #endif /* SPECTRE_INTPUT_DEVICE_H */

View file

@ -5,6 +5,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace sp {
namespace MouseButton { namespace MouseButton {
enum Type { enum Type {
@ -150,4 +152,6 @@ typedef struct InputEvent
} InputEvent; } InputEvent;
} // namespace sp
#endif /* SPECTRE_INPUT_EVENT_H */ #endif /* SPECTRE_INPUT_EVENT_H */

View file

@ -4,10 +4,14 @@
#include "InputEvent.h" #include "InputEvent.h"
namespace sp {
class InputListener class InputListener
{ {
public : public :
virtual void onInputEvent(const InputEvent& event); virtual void onInputEvent(const InputEvent& event);
}; };
} // namespace sp
#endif /* SPECTRE_INPUT_LISTENER_H */ #endif /* SPECTRE_INPUT_LISTENER_H */

View file

@ -8,6 +8,8 @@
#include "InputListener.h" #include "InputListener.h"
#include "InputEvent.h" #include "InputEvent.h"
namespace sp {
class Mouse; class Mouse;
class Keyboard; class Keyboard;
class InputDevice; class InputDevice;
@ -54,4 +56,6 @@ protected :
PlatformInput *m_platform; PlatformInput *m_platform;
}; };
} // namespace sp
#endif /* SPECTRE_INPUT_MODULE_H */ #endif /* SPECTRE_INPUT_MODULE_H */

View file

@ -6,6 +6,8 @@
#include "InputEvent.h" #include "InputEvent.h"
#include "InputDevice.h" #include "InputDevice.h"
namespace sp {
class Keyboard : public InputDevice class Keyboard : public InputDevice
{ {
public : public :
@ -16,4 +18,6 @@ public :
static std::string getKeyName(Key::Type key); static std::string getKeyName(Key::Type key);
}; };
} // namespace sp
#endif /* SPECTRE_INPUT_KEYBOARD_H */ #endif /* SPECTRE_INPUT_KEYBOARD_H */

View file

@ -7,6 +7,8 @@
#include "InputEvent.h" #include "InputEvent.h"
#include "InputDevice.h" #include "InputDevice.h"
namespace sp {
class Mouse : public InputDevice class Mouse : public InputDevice
{ {
public : public :
@ -22,4 +24,6 @@ public :
static std::string getButtonName(MouseButton::Type button); static std::string getButtonName(MouseButton::Type button);
}; };
} // namespace sp
#endif /* SPECTRE_INPUT_MOUSE_H */ #endif /* SPECTRE_INPUT_MOUSE_H */

View file

@ -5,6 +5,8 @@
#include "Vector3.h" #include "Vector3.h"
#include "Vector4.h" #include "Vector4.h"
namespace sp {
// Basic structure representing a color in 32bit RGBA // Basic structure representing a color in 32bit RGBA
struct Color struct Color
{ {
@ -62,4 +64,6 @@ Color operator -(const Color& a, unsigned int s);
Color operator /(const Color& a, unsigned int s); Color operator /(const Color& a, unsigned int s);
Color operator *(const Color& a, unsigned int s); Color operator *(const Color& a, unsigned int s);
} // namespace sp
#endif /* SPECTRE_MATH_COLOR_H */ #endif /* SPECTRE_MATH_COLOR_H */

View file

@ -6,7 +6,7 @@
#include "Vector2.h" #include "Vector2.h"
#include "Matrix4.h" #include "Matrix4.h"
namespace math namespace sp { namespace math
{ {
float rand(float min, float max); float rand(float min, float max);
@ -47,6 +47,7 @@ namespace math
Vector3f getUpVector(const Matrix4f matrix); Vector3f getUpVector(const Matrix4f matrix);
Vector3f getForwardVector(const Matrix4f matrix); Vector3f getForwardVector(const Matrix4f matrix);
};
} } // namespace sp
#endif /* SPECTRE_MATH_MATH_H */ #endif /* SPECTRE_MATH_MATH_H */

View file

@ -7,6 +7,8 @@
#include <iostream> #include <iostream>
#include <Spectre/Math/Vector2.h> #include <Spectre/Math/Vector2.h>
namespace sp {
template<typename T> template<typename T>
struct Matrix3 struct Matrix3
{ {
@ -77,6 +79,8 @@ typedef Matrix3<double> Matrix3d;
typedef Matrix3<int> Matrix3i; typedef Matrix3<int> Matrix3i;
typedef Matrix3<unsigned> Matrix3u; typedef Matrix3<unsigned> Matrix3u;
} // namespace sp
#include "Matrix3.inl" #include "Matrix3.inl"
#endif /* SPECTRE_MATH_MATRIX3_H */ #endif /* SPECTRE_MATH_MATRIX3_H */

View file

@ -2,6 +2,8 @@
#include <string> #include <string>
#include "Matrix3.h" #include "Matrix3.h"
namespace sp {
template <> template <>
Matrix3f Matrix3f::Identity( Matrix3f Matrix3f::Identity(
1, 0, 0, 1, 0, 0,
@ -120,3 +122,5 @@ inline std::ostream& operator<<(std::ostream &s, const Matrix3<T>& mat)
<< mat.v[1] << " " << mat.v[4] << " " << mat.v[7] << std::endl << mat.v[1] << " " << mat.v[4] << " " << mat.v[7] << std::endl
<< mat.v[2] << " " << mat.v[5] << " " << mat.v[8] << std::endl; << mat.v[2] << " " << mat.v[5] << " " << mat.v[8] << std::endl;
} }
} // namespace sp

View file

@ -9,6 +9,8 @@
#include <Spectre/Math/Vector3.h> #include <Spectre/Math/Vector3.h>
#include <Spectre/Math/Vector2.h> #include <Spectre/Math/Vector2.h>
namespace sp {
template<typename T> template<typename T>
struct Matrix4 struct Matrix4
{ {
@ -100,10 +102,11 @@ typedef Matrix4<double> mat4d;
typedef Matrix4<int> mat4i; typedef Matrix4<int> mat4i;
typedef Matrix4<unsigned> mat4u; typedef Matrix4<unsigned> mat4u;
} // namespace sp
// ---------------- // ----------------
// Implementation // Implementation
// ---------------- // ----------------
#include "Matrix4.inl" #include "Matrix4.inl"
#endif /* SPECTRE_MATH_MATRIX4_H */ #endif /* SPECTRE_MATH_MATRIX4_H */

View file

@ -4,6 +4,8 @@
#include <string.h> #include <string.h>
#include "Matrix4.h" #include "Matrix4.h"
namespace sp {
template<typename T> template<typename T>
const Matrix4<T> Matrix4<T>::Identity( const Matrix4<T> Matrix4<T>::Identity(
1, 0, 0, 0, 1, 0, 0, 0,
@ -152,3 +154,5 @@ inline std::ostream& operator<<(std::ostream &s, const Matrix4<T>& mat)
{ {
return s << mat.toString(); return s << mat.toString();
} }
} // namespace sp

View file

@ -5,6 +5,8 @@
#include "Vector2.h" #include "Vector2.h"
#include "Matrix4.h" #include "Matrix4.h"
namespace sp {
// Class representing a transformation matrix. // Class representing a transformation matrix.
class Transform class Transform
@ -75,4 +77,6 @@ Transform& operator*=(Transform& a, const Transform& b);
Vector2f operator*(const Transform& t, const Vector2f& v); Vector2f operator*(const Transform& t, const Vector2f& v);
} // namespace sp
#endif /* SPECTRE_MATH_TRANSFORM_H */ #endif /* SPECTRE_MATH_TRANSFORM_H */

View file

@ -5,6 +5,8 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
namespace sp {
template <typename T> template <typename T>
struct Vector2 struct Vector2
{ {
@ -111,7 +113,7 @@ template <typename T>
inline Vector2<T> operator+(T s, const Vector2<T>& v); inline Vector2<T> operator+(T s, const Vector2<T>& v);
template <typename T> template <typename T>
inline Vector2<T> operator-(const Vector2<T>& v,T s); inline Vector2<T> operator-(const Vector2<T>& v, T s);
template <typename T> template <typename T>
inline Vector2<T> operator-(T s, const Vector2<T>& v); inline Vector2<T> operator-(T s, const Vector2<T>& v);
@ -132,7 +134,7 @@ template <typename T>
inline Vector2<T>& operator+=(Vector2<T>& v, T s); inline Vector2<T>& operator+=(Vector2<T>& v, T s);
template <typename T> template <typename T>
inline Vector2<T>& operator-=(Vector2<T>& v,T s); inline Vector2<T>& operator-=(Vector2<T>& v, T s);
template <typename T> template <typename T>
inline Vector2<T>& operator/=(Vector2<T>& v, T s); inline Vector2<T>& operator/=(Vector2<T>& v, T s);
@ -190,6 +192,8 @@ typedef Vector2<int> vec2i;
typedef Vector2<unsigned> vec2u; typedef Vector2<unsigned> vec2u;
typedef Vector2<unsigned char> vec2b; typedef Vector2<unsigned char> vec2b;
} // namespace sp
#include "Vector2.inl" #include "Vector2.inl"
#endif /* SPECTRE_MATH_VECTOR2_H */ #endif /* SPECTRE_MATH_VECTOR2_H */

View file

@ -3,6 +3,8 @@
#include <math.h> #include <math.h>
#include "Vector2.h" #include "Vector2.h"
namespace sp {
template <typename T> template <typename T>
Vector2<T>::Vector2() Vector2<T>::Vector2()
{ {
@ -314,3 +316,5 @@ inline std::ostream& operator<<(std::ostream &s, const Vector2<T>& v)
{ {
return s << "(" << v.x << "," << v.y << ")"; return s << "(" << v.x << "," << v.y << ")";
} }
} // namespace sp

View file

@ -5,6 +5,8 @@
#include "Vector2.h" #include "Vector2.h"
#include <iostream> #include <iostream>
namespace sp {
template <typename T> template <typename T>
struct Vector3 struct Vector3
{ {
@ -167,6 +169,8 @@ typedef Vector3<int> vec3i;
typedef Vector3<unsigned> vec3u; typedef Vector3<unsigned> vec3u;
typedef Vector3<unsigned char> vec3b; typedef Vector3<unsigned char> vec3b;
} // namespace sp
#include "Vector3.inl" #include "Vector3.inl"
#endif /* SPECTRE_MATH_VECTOR3_H */ #endif /* SPECTRE_MATH_VECTOR3_H */

View file

@ -2,6 +2,8 @@
#include <math.h> #include <math.h>
#include "Vector3.h" #include "Vector3.h"
namespace sp {
template <typename T> template <typename T>
Vector3<T>::Vector3() Vector3<T>::Vector3()
{ {
@ -265,3 +267,5 @@ inline std::ostream& operator<<(std::ostream &s, const Vector3<T>& v)
{ {
return s << "(" << v.x << "," << v.y << "," << v.z << ")"; return s << "(" << v.x << "," << v.y << "," << v.z << ")";
} }
} // namespace sp

View file

@ -4,6 +4,8 @@
#include <iostream> #include <iostream>
namespace sp {
template <typename T> template <typename T>
struct Vector4 struct Vector4
{ {
@ -153,6 +155,8 @@ typedef Vector4<int> vec4i;
typedef Vector4<unsigned> vec4u; typedef Vector4<unsigned> vec4u;
typedef Vector4<unsigned char> vec4b; typedef Vector4<unsigned char> vec4b;
} // namespace sp
#include "Vector4.inl" #include "Vector4.inl"
#endif /* SPECTRE_MATH_VECTOR4_H */ #endif /* SPECTRE_MATH_VECTOR4_H */

View file

@ -2,6 +2,8 @@
#include <math.h> #include <math.h>
#include "Vector4.h" #include "Vector4.h"
namespace sp {
template <typename T> template <typename T>
Vector4<T>::Vector4() Vector4<T>::Vector4()
{ {
@ -252,3 +254,5 @@ inline std::ostream& operator<<(std::ostream &s, const Vector4<T>& v)
{ {
return s << "(" << v.x << "," << v.y << "," << v.z << "," << v.w << ")"; return s << "(" << v.x << "," << v.y << "," << v.z << "," << v.w << ")";
} }
} // namespace sp

View file

@ -13,6 +13,8 @@
// TODO: Zoom is implemented using a scale matrix. // TODO: Zoom is implemented using a scale matrix.
// It's abit weird to control. Must be a better solution. // It's abit weird to control. Must be a better solution.
namespace sp {
class Camera2D : public ICamera class Camera2D : public ICamera
{ {
public : public :
@ -80,4 +82,6 @@ protected :
mutable bool m_projViewNeedsUpdate; mutable bool m_projViewNeedsUpdate;
}; };
} // namespace sp
#endif /* SPECTRE_SCENE_CAMERA2D_H */ #endif /* SPECTRE_SCENE_CAMERA2D_H */

View file

@ -4,6 +4,8 @@
#include <Spectre/Math/Matrix4.h> #include <Spectre/Math/Matrix4.h>
namespace sp {
// Camera interface. // Camera interface.
class ICamera class ICamera
{ {
@ -17,4 +19,6 @@ public :
virtual const Matrix4f& getProjectionViewMatrix() const = 0; virtual const Matrix4f& getProjectionViewMatrix() const = 0;
}; };
} // namespace sp
#endif /* SPECTRE_SCENE_ICAMERA_H */ #endif /* SPECTRE_SCENE_ICAMERA_H */

View file

@ -5,7 +5,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
namespace File namespace sp { namespace file
{ {
std::string getBasename(const std::string& path); std::string getBasename(const std::string& path);
@ -14,6 +14,6 @@ namespace File
std::string getPathname(const std::string& path); std::string getPathname(const std::string& path);
std::vector<unsigned char> read(const std::string& path); std::vector<unsigned char> read(const std::string& path);
}; } }
#endif /* SPECTRE_SYSTEM_FILE_H */ #endif /* SPECTRE_SYSTEM_FILE_H */

View file

@ -2,6 +2,10 @@
#ifndef SYSTEM_LOG_H #ifndef SYSTEM_LOG_H
#define SYSTEM_LOG_H #define SYSTEM_LOG_H
void log(const char *fmt, ...); namespace sp {
void log(const char *fmt, ...);
} // namespace sp
#endif /* SYSTEM_LOG_H */ #endif /* SYSTEM_LOG_H */

View file

@ -4,6 +4,8 @@
#include "SystemEvent.h" #include "SystemEvent.h"
namespace sp {
class Display; class Display;
class MessageHandler class MessageHandler
@ -12,4 +14,6 @@ public :
virtual void onSizeChanged(Display* display, int width, int height); virtual void onSizeChanged(Display* display, int width, int height);
}; };
} // namespace sp
#endif /* SPECTRE_SYSTEM_MESSAGEHANDLER_H */ #endif /* SPECTRE_SYSTEM_MESSAGEHANDLER_H */

View file

@ -5,6 +5,8 @@
#include <Spectre/System/SystemEvent.h> #include <Spectre/System/SystemEvent.h>
#include <queue> #include <queue>
namespace sp {
class MessageQueue class MessageQueue
{ {
public : public :
@ -18,4 +20,6 @@ protected :
std::deque<SysEvent> m_queue; std::deque<SysEvent> m_queue;
}; };
} // namespace sp
#endif /* SPECTRE_MESSAGE_QUEUE_H */ #endif /* SPECTRE_MESSAGE_QUEUE_H */

View file

@ -2,11 +2,12 @@
#ifndef SPECTRE_SYSTEM_SYSTEM_H #ifndef SPECTRE_SYSTEM_SYSTEM_H
#define SPECTRE_SYSTEM_SYSTEM_H #define SPECTRE_SYSTEM_SYSTEM_H
namespace System namespace sp { namespace system
{ {
unsigned long getMilliseconds(); unsigned long getMilliseconds();
void sleep(int milliseconds); void sleep(int milliseconds);
};
} } // namespace sp::system
#endif /* SPECTRE_SYSTEM_SYSTEM_H */ #endif /* SPECTRE_SYSTEM_SYSTEM_H */

View file

@ -2,6 +2,8 @@
#ifndef SYSTEM_EVENT_H #ifndef SYSTEM_EVENT_H
#define SYSTEM_EVENT_H #define SYSTEM_EVENT_H
namespace sp {
class Display; class Display;
struct SysEvent struct SysEvent
@ -32,7 +34,8 @@ public :
// Helper methods // Helper methods
static SysEvent sizeEvent(Display *display, int width, int height); static SysEvent sizeEvent(Display *display, int width, int height);
}; };
} // namespace sp
#endif /* SYSTEM_EVENT_H */ #endif /* SYSTEM_EVENT_H */

View file

@ -2,6 +2,8 @@
#include <cstdio> #include <cstdio>
#include <Spectre/Core/String.h> #include <Spectre/Core/String.h>
namespace sp {
std::string core::to_string(unsigned int value) std::string core::to_string(unsigned int value)
{ {
char buf[32]; char buf[32];
@ -23,3 +25,5 @@ std::string core::to_string(float value, unsigned int precision)
sprintf(buf, format.c_str(), value); sprintf(buf, format.c_str(), value);
return std::string(buf); return std::string(buf);
} }
} // namespace sp::core

View file

@ -5,6 +5,8 @@
#include <Spectre/System/SystemEvent.h> #include <Spectre/System/SystemEvent.h>
#include <Platform/PlatformDisplay.h> #include <Platform/PlatformDisplay.h>
namespace sp {
#define CAPTION_DEFAULT "Spectre" #define CAPTION_DEFAULT "Spectre"
#define ICON_DEFAULT "./assets/app.ico" #define ICON_DEFAULT "./assets/app.ico"
@ -148,3 +150,5 @@ void Display::onReshape(int width, int height)
// Resize context if the windows resizes. // Resize context if the windows resizes.
m_context->setSize(width, height); m_context->setSize(width, height);
} }
} // namespace sp

View file

@ -1,6 +1,8 @@
#include <Spectre/Display/DisplayDescription.h> #include <Spectre/Display/DisplayDescription.h>
namespace sp {
DisplayDescription::DisplayDescription() : DisplayDescription::DisplayDescription() :
mode (), mode (),
decoration (DisplayDecorate::Default) decoration (DisplayDecorate::Default)
@ -12,3 +14,5 @@ mode (mode),
decoration (decoration) decoration (decoration)
{ {
} }
} // namespace sp

View file

@ -3,6 +3,8 @@
#include <Platform/PlatformMisc.h> #include <Platform/PlatformMisc.h>
#include <algorithm> #include <algorithm>
namespace sp {
struct DisplayModeCmp struct DisplayModeCmp
{ {
inline bool operator() (const DisplayMode& a, const DisplayMode& b) inline bool operator() (const DisplayMode& a, const DisplayMode& b)
@ -52,3 +54,5 @@ DisplayMode DisplayMode::getDesktopMode()
{ {
return PlatformMisc::GetDesktopMode(); return PlatformMisc::GetDesktopMode();
} }
} // namespace sp

View file

@ -3,11 +3,13 @@
#ifdef _WIN32 #ifdef _WIN32
#include <Platform/Win32/Win32GLContext.h> #include <Platform/Win32/Win32GLContext.h>
typedef Win32GLContext ContextType; typedef sp::Win32GLContext ContextType;
#else #else
#error "No GLContext implementation exists" #error "No GLContext implementation exists"
#endif #endif
namespace sp {
GLContext* GLContext::create() GLContext* GLContext::create()
{ {
return new ContextType(); return new ContextType();
@ -17,3 +19,5 @@ GLContext::~GLContext()
{ {
// Nothing to do. // Nothing to do.
} }
} // namespace sp

View file

@ -9,6 +9,8 @@
#include <Platform/Win32/Win32Application.h> #include <Platform/Win32/Win32Application.h>
#include <Spectre/Game.h> #include <Spectre/Game.h>
namespace sp {
Game::Game() Game::Game()
{ {
m_platform = new Win32Application(); m_platform = new Win32Application();
@ -107,3 +109,5 @@ FPSCounter& Game::getFpsCounter()
{ {
return m_fpsCounter; return m_fpsCounter;
} }
}

View file

@ -2,6 +2,8 @@
#include <Spectre/Game/FPSCounter.h> #include <Spectre/Game/FPSCounter.h>
#include <Spectre/System/System.h> #include <Spectre/System/System.h>
namespace sp {
FPSCounter::FPSCounter() : FPSCounter::FPSCounter() :
m_fps (60.0f), m_fps (60.0f),
m_updateRate (2000) m_updateRate (2000)
@ -34,7 +36,7 @@ void FPSCounter::setUpdateRate(unsigned int ups)
bool FPSCounter::update() bool FPSCounter::update()
{ {
unsigned int current = System::getMilliseconds(); unsigned int current = system::getMilliseconds();
unsigned int elapsed = current - m_time; unsigned int elapsed = current - m_time;
if (elapsed >= m_updateRate) { if (elapsed >= m_updateRate) {
@ -50,6 +52,8 @@ bool FPSCounter::update()
void FPSCounter::reset() void FPSCounter::reset()
{ {
m_time = System::getMilliseconds(); m_time = system::getMilliseconds();
m_count = 0; m_count = 0;
} }
} // namespace sp

View file

@ -3,10 +3,12 @@
#include <Spectre/Game/GameTime.h> #include <Spectre/Game/GameTime.h>
#include <Spectre/System/System.h> #include <Spectre/System/System.h>
namespace sp {
GameTime::GameTime(unsigned long updates_per_sec) GameTime::GameTime(unsigned long updates_per_sec)
{ {
m_acc = 0; m_acc = 0;
m_current = System::getMilliseconds(); m_current = system::getMilliseconds();
m_lastUpdate = m_current; m_lastUpdate = m_current;
setTimeStep(updates_per_sec); setTimeStep(updates_per_sec);
} }
@ -67,10 +69,12 @@ void GameTime::accumulateTime()
void GameTime::updateTime() void GameTime::updateTime()
{ {
m_current = System::getMilliseconds(); m_current = system::getMilliseconds();
// Just to be safe. check so we don't get a negative interval. // Just to be safe. check so we don't get a negative interval.
if (m_current < m_lastUpdate) { if (m_current < m_lastUpdate) {
m_lastUpdate = m_current; m_lastUpdate = m_current;
} }
} }
} // namespace sp

View file

@ -10,6 +10,8 @@
#include <algorithm> #include <algorithm>
namespace sp {
static bool compare_renderable(const Renderable2D* a, const Renderable2D* b) { static bool compare_renderable(const Renderable2D* a, const Renderable2D* b) {
if (a->getZOrder() != b->getZOrder()) { if (a->getZOrder() != b->getZOrder()) {
@ -257,3 +259,5 @@ void BatchRenderer2D::drawBatch(Batch& batch)
glDisable(GL_BLEND); glDisable(GL_BLEND);
} }
} }
} // namespace sp

View file

@ -4,6 +4,8 @@
#include <Spectre/Graphics/Renderable.h> #include <Spectre/Graphics/Renderable.h>
#include <Spectre/Graphics/DefaultRenderer2D.h> #include <Spectre/Graphics/DefaultRenderer2D.h>
namespace sp {
DefaultRenderer2D::DefaultRenderer2D() DefaultRenderer2D::DefaultRenderer2D()
{ {
m_shader.create(); m_shader.create();
@ -70,3 +72,5 @@ void DefaultRenderer2D::render()
m_shader.disable(); m_shader.disable();
m_queue.clear(); m_queue.clear();
} }
} // namespace sp

View file

@ -7,6 +7,8 @@
#include <Spectre/Math/Math.h> #include <Spectre/Math/Math.h>
#include "Font/FreeTypeDriver.h" #include "Font/FreeTypeDriver.h"
namespace sp {
Font::Font() : Font::Font() :
m_driver (new FreeTypeDriver()) m_driver (new FreeTypeDriver())
{ {
@ -124,3 +126,5 @@ const Texture* Font::getTexture() const
{ {
return &m_cacheTextureA.texture; return &m_cacheTextureA.texture;
} }
} // namespace sp

View file

@ -1,6 +1,8 @@
#include "FontDriver.h" #include "FontDriver.h"
namespace sp {
FontDriver::FontDriver() : FontDriver::FontDriver() :
m_hinting (true) m_hinting (true)
{ {
@ -10,3 +12,5 @@ void FontDriver::setHinting(bool value)
{ {
m_hinting = value; m_hinting = value;
} }
} // namespace sp

View file

@ -6,6 +6,8 @@
#include <Spectre/Graphics/Image.h> #include <Spectre/Graphics/Image.h>
#include <Spectre/Graphics/Font.h> #include <Spectre/Graphics/Font.h>
namespace sp {
class FontDriver class FontDriver
{ {
public : public :
@ -28,4 +30,6 @@ protected :
bool m_hinting; bool m_hinting;
}; };
} // namespace sp
#endif /* SPECTRE_GRAPHICS_FONT_FONTDRIVER_H */ #endif /* SPECTRE_GRAPHICS_FONT_FONTDRIVER_H */

View file

@ -9,6 +9,8 @@
#include "FreeTypeError.h" #include "FreeTypeError.h"
#include "FreeTypeDriver.h" #include "FreeTypeDriver.h"
namespace sp {
class LibWrapper class LibWrapper
{ {
public : public :
@ -166,3 +168,5 @@ std::string FreeTypeDriver::getName()
{ {
return m_face->family_name; return m_face->family_name;
} }
} // namespace

View file

@ -5,8 +5,11 @@
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
#include <string>
#include "FontDriver.h" #include "FontDriver.h"
namespace sp {
class FreeTypeDriver : public FontDriver class FreeTypeDriver : public FontDriver
{ {
public: public:
@ -26,4 +29,6 @@ private :
FT_Face m_face; FT_Face m_face;
}; };
} // namespace sp
#endif /* SPECTRE_GRAPHICS_FONT_FREETYPEDRIVER_H */ #endif /* SPECTRE_GRAPHICS_FONT_FREETYPEDRIVER_H */

View file

@ -4,6 +4,8 @@
#include <Spectre/Graphics/Image.h> #include <Spectre/Graphics/Image.h>
#include "ImageLoader.h" #include "ImageLoader.h"
namespace sp {
static ImageLoader _loader; static ImageLoader _loader;
Image::Image() : Image::Image() :
@ -207,3 +209,5 @@ const unsigned char* Image::getPixels() const
} }
return NULL; return NULL;
} }
} // namespace sp

View file

@ -21,6 +21,8 @@
#include <cstdio> #include <cstdio>
#include <vector> #include <vector>
namespace sp {
bool ImageLoader::loadFromFile(const char *filename, Image& img) bool ImageLoader::loadFromFile(const char *filename, Image& img)
{ {
FILE *fd = fopen(filename, "rb"); FILE *fd = fopen(filename, "rb");
@ -59,7 +61,7 @@ bool ImageLoader::loadFromMemory(const void *data, unsigned size, Image& img)
// TODO: Support more formats. // TODO: Support more formats.
bool ImageLoader::saveToFile(const Image& img, const char *filename) 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; std::vector<unsigned char> encoded_data;
if (ext == "png") { if (ext == "png") {
@ -129,3 +131,5 @@ bool ImageLoader::encodePNG(const Image& img, std::vector<unsigned char>& data)
m_error = stbi_failure_reason(); m_error = stbi_failure_reason();
return false; return false;
} }
} // namespace sp

View file

@ -6,6 +6,8 @@
#include <Spectre/Math/Vector2.h> #include <Spectre/Math/Vector2.h>
#include <vector> #include <vector>
namespace sp {
class ImageLoader class ImageLoader
{ {
public : public :
@ -30,4 +32,6 @@ protected :
std::string m_error; std::string m_error;
}; };
} // namespace sp
#endif /* SPECTRE_GRAPHICS_IMAGE_LOADER_H */ #endif /* SPECTRE_GRAPHICS_IMAGE_LOADER_H */

View file

@ -4,6 +4,8 @@
#include <Spectre/Graphics/Texture.h> #include <Spectre/Graphics/Texture.h>
#include <Spectre/Graphics/RenderState.h> #include <Spectre/Graphics/RenderState.h>
namespace sp {
RenderState::RenderState() : RenderState::RenderState() :
m_texture (0), m_texture (0),
m_shader (0) m_shader (0)
@ -46,3 +48,5 @@ void RenderState::cleanup()
m_shader->disable(); m_shader->disable();
} }
} }
} // namespace sp

View file

@ -1,6 +1,8 @@
#include <Spectre/Graphics/Renderable.h> #include <Spectre/Graphics/Renderable.h>
namespace sp {
Renderable2D::Renderable2D() : Renderable2D::Renderable2D() :
m_zorder (0) m_zorder (0)
{ {
@ -25,3 +27,5 @@ void Renderable2D::setZOrder(unsigned char value)
{ {
m_zorder = value; m_zorder = value;
} }
} // namespace sp

View file

@ -1,5 +1,7 @@
#include <Spectre/Graphics/Renderer2D.h> #include <Spectre/Graphics/Renderer2D.h>
namespace sp {
Renderer2D::Renderer2D() : Renderer2D::Renderer2D() :
m_camera (NULL) m_camera (NULL)
{ {
@ -13,3 +15,5 @@ void Renderer2D::setCamera(const Camera2D& camera)
{ {
m_camera = &camera; m_camera = &camera;
} }
} // namespace sp

View file

@ -4,6 +4,8 @@
#include <Spectre/Graphics/OpenGL.h> #include <Spectre/Graphics/OpenGL.h>
#include <Spectre/Graphics/Shader.h> #include <Spectre/Graphics/Shader.h>
namespace sp {
Shader::Shader(Type type, const std::string& name) : Shader::Shader(Type type, const std::string& name) :
m_name (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 this shader does not have a name, pick the filename.
if (m_name.length() < 1) { if (m_name.length() < 1) {
m_name = File::getBasename(file); m_name = file::getBasename(file);
} }
// Load file into memory. // Load file into memory.
@ -98,3 +100,5 @@ std::string Shader::fetchErrorLog()
return std::string(buf); return std::string(buf);
} }
} // namespace sp

View file

@ -4,6 +4,8 @@
#include <Spectre/Graphics/ShaderProgram.h> #include <Spectre/Graphics/ShaderProgram.h>
#include <Spectre/System/File.h> #include <Spectre/System/File.h>
namespace sp {
ShaderProgram::ShaderProgram() : ShaderProgram::ShaderProgram() :
m_id (0) m_id (0)
{ {
@ -36,7 +38,7 @@ void ShaderProgram::addShader(const Shader& shader)
bool ShaderProgram::loadFromFile(const std::string& filename) bool ShaderProgram::loadFromFile(const std::string& filename)
{ {
std::string extension = File::getExtension(filename); std::string extension = file::getExtension(filename);
// Meta file. load real shaders. // Meta file. load real shaders.
if (extension == "shader.glsl") { if (extension == "shader.glsl") {
@ -191,3 +193,5 @@ std::string ShaderProgram::fetchErrorLog()
return std::string(buf); return std::string(buf);
} }
} // namespace sp

View file

@ -3,6 +3,8 @@
#include <Spectre/Graphics/Texture.h> #include <Spectre/Graphics/Texture.h>
#include <Spectre/Graphics/Sprite.h> #include <Spectre/Graphics/Sprite.h>
namespace sp {
Sprite::Sprite() : Sprite::Sprite() :
m_texture (NULL) m_texture (NULL)
{ {
@ -115,3 +117,5 @@ void Sprite::render(Renderer2D& renderer) const
{ {
renderer.draw(this); renderer.draw(this);
} }
} // namespace sp

View file

@ -3,6 +3,8 @@
#include <Spectre/Graphics/Renderer2D.h> #include <Spectre/Graphics/Renderer2D.h>
#include <Spectre/Graphics/Text.h> #include <Spectre/Graphics/Text.h>
namespace sp {
Text::Text() : Text::Text() :
m_font (NULL), m_font (NULL),
m_size (22), m_size (22),
@ -174,3 +176,5 @@ void Text::render(Renderer2D& renderer) const
{ {
renderer.draw(this); renderer.draw(this);
} }
} // namespace sp

View file

@ -3,6 +3,8 @@
#include <Spectre/Graphics/OpenGL.h> #include <Spectre/Graphics/OpenGL.h>
#include <Spectre/Graphics/Texture.h> #include <Spectre/Graphics/Texture.h>
namespace sp {
namespace { namespace {
GLint pixelFormatToInternal(enum PixelFormat format) { GLint pixelFormatToInternal(enum PixelFormat format) {
@ -252,3 +254,5 @@ bool Texture::operator!=(const Texture* other) const
{ {
return m_id != other->m_id; return m_id != other->m_id;
} }
} // namespace sp

View file

@ -1,6 +1,8 @@
#include <Spectre/Graphics/Transformable.h> #include <Spectre/Graphics/Transformable.h>
namespace sp {
Transformable::Transformable() : Transformable::Transformable() :
m_position (0.0f, 0.0f), m_position (0.0f, 0.0f),
m_scale (1.0f, 1.0f), m_scale (1.0f, 1.0f),
@ -93,3 +95,5 @@ const Transform& Transformable::getTransform() const
} }
return m_transform; return m_transform;
} }
} // namespace sp

View file

@ -1,6 +1,8 @@
#include <Spectre/Graphics/Vertex2D.h> #include <Spectre/Graphics/Vertex2D.h>
namespace sp {
Vertex2D::Vertex2D() : Vertex2D::Vertex2D() :
position (0.0f), position (0.0f),
color (1.0f), color (1.0f),
@ -28,3 +30,5 @@ color (_color),
uv (_uv) uv (_uv)
{ {
} }
} // namespace sp

View file

@ -3,6 +3,8 @@
#include <Spectre/Graphics/OpenGL.h> #include <Spectre/Graphics/OpenGL.h>
#include <string> #include <string>
namespace sp {
Graphics::Graphics(PlatformApplication *platform) Graphics::Graphics(PlatformApplication *platform)
{ {
m_width = 800; m_width = 800;
@ -87,3 +89,5 @@ void Graphics::swapBuffers()
{ {
m_display->swapBuffers(); m_display->swapBuffers();
} }
} // namespace sp

View file

@ -1,6 +1,8 @@
#include <Spectre/Input/InputDevice.h> #include <Spectre/Input/InputDevice.h>
namespace sp {
InputDevice::~InputDevice() InputDevice::~InputDevice()
{ {
} }
@ -8,3 +10,5 @@ InputDevice::~InputDevice()
void InputDevice::init() void InputDevice::init()
{ {
} }
} // namespace sp

View file

@ -3,6 +3,8 @@
#include <Spectre/Input/Keyboard.h> #include <Spectre/Input/Keyboard.h>
#include <Spectre/Input/InputEvent.h> #include <Spectre/Input/InputEvent.h>
namespace sp {
InputEvent::InputEvent(Type type) : InputEvent::InputEvent(Type type) :
type (type) type (type)
{ {
@ -17,3 +19,5 @@ std::string InputEvent::MouseButtonEvent::getName() const
{ {
return Mouse::getButtonName(button); return Mouse::getButtonName(button);
} }
} // namespace sp

View file

@ -1,6 +1,10 @@
#include <Spectre/Input/InputListener.h> #include <Spectre/Input/InputListener.h>
namespace sp {
void InputListener::onInputEvent(const InputEvent& event) void InputListener::onInputEvent(const InputEvent& event)
{ {
} }
} // namespace sp

View file

@ -6,6 +6,8 @@
#include <Spectre/Input/InputDevice.h> #include <Spectre/Input/InputDevice.h>
#include <Spectre/Input/InputModule.h> #include <Spectre/Input/InputModule.h>
namespace sp {
InputModule::InputModule(PlatformInput *platform) : InputModule::InputModule(PlatformInput *platform) :
m_platform (platform) m_platform (platform)
{ {
@ -94,3 +96,5 @@ void InputModule::dispatch()
m_buffer.clear(); m_buffer.clear();
} }
} // namespace sp

View file

@ -1,6 +1,8 @@
#include <Spectre/Input/Keyboard.h> #include <Spectre/Input/Keyboard.h>
namespace sp {
struct keyentry struct keyentry
{ {
Key::Type type; Key::Type type;
@ -110,3 +112,5 @@ std::string Keyboard::getKeyName(Key::Type key)
} }
return table[key].name; return table[key].name;
} }
} // namespace sp

View file

@ -1,6 +1,8 @@
#include <Spectre/Input/Mouse.h> #include <Spectre/Input/Mouse.h>
namespace sp {
Mouse::~Mouse() Mouse::~Mouse()
{ {
} }
@ -18,3 +20,5 @@ std::string Mouse::getButtonName(MouseButton::Type button)
return "Unknown"; return "Unknown";
} }
} }
} // namespace sp

View file

@ -1,6 +1,8 @@
#include <Spectre/Math/Color.h> #include <Spectre/Math/Color.h>
namespace sp {
const Color Color::Black (0 , 0 , 0 , 255); const Color Color::Black (0 , 0 , 0 , 255);
const Color Color::White (255, 255, 255, 255); const Color Color::White (255, 255, 255, 255);
const Color Color::Red (255, 0 , 0 , 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); return Color(c.r * s, c.g * s, c.b * s, c.a * s);
} }
} // namespace sp

View file

@ -3,18 +3,18 @@
#include <cstdlib> #include <cstdlib>
#include <Spectre/Math/Math.h> #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

View file

@ -2,8 +2,8 @@
#include <cstdlib> #include <cstdlib>
#include <Spectre/Math/Math.h> #include <Spectre/Math/Math.h>
namespace math { namespace sp { namespace math
{
float rand(float min, float max) { float rand(float min, float max) {
float r = ((float) ::rand()) / RAND_MAX; float r = ((float) ::rand()) / RAND_MAX;
@ -50,8 +50,8 @@ namespace math {
Matrix4f rotation(float theta) { Matrix4f rotation(float theta) {
float r = deg2rad(theta); float r = deg2rad(theta);
float s = std::sin(r); float s = ::std::sin(r);
float c = std::cos(r); float c = ::std::cos(r);
return Matrix4f( return Matrix4f(
c, -s, 0.0f, 0.0f, c, -s, 0.0f, 0.0f,
@ -94,4 +94,5 @@ namespace math {
return Vector3f(matrix.e[8], matrix.e[9], matrix.e[10]); return Vector3f(matrix.e[8], matrix.e[9], matrix.e[10]);
} }
};
} } // namespace sp::math

View file

@ -2,6 +2,8 @@
#include <Spectre/Math/Math.h> #include <Spectre/Math/Math.h>
#include <Spectre/Math/Transform.h> #include <Spectre/Math/Transform.h>
namespace sp {
Transform::Transform() : Transform::Transform() :
m_matrix (Matrix4f::Identity) m_matrix (Matrix4f::Identity)
{ {
@ -156,3 +158,5 @@ Vector2f operator*(const Transform& transform, const Vector2f& vec)
{ {
return transform.transformPoint(vec); return transform.transformPoint(vec);
} }
} // namespace sp

View file

@ -2,6 +2,8 @@
#ifndef SPECTRE_PLATFORM_H #ifndef SPECTRE_PLATFORM_H
#define SPECTRE_PLATFORM_H #define SPECTRE_PLATFORM_H
namespace sp {
class PlatformInput; class PlatformInput;
class PlatformDisplay; class PlatformDisplay;
class MessageQueue; class MessageQueue;
@ -22,4 +24,6 @@ public :
virtual void update() = 0; virtual void update() = 0;
}; };
} // namespace sp
#endif /* SPECTRE_PLATFORM_H */ #endif /* SPECTRE_PLATFORM_H */

View file

@ -4,11 +4,13 @@
#ifdef _WIN32 #ifdef _WIN32
#include <Platform/Win32/Win32Display.h> #include <Platform/Win32/Win32Display.h>
typedef Win32Display DisplayType; typedef sp::Win32Display DisplayType;
#else #else
#error "No Display implementation exists" #error "No Display implementation exists"
#endif #endif
namespace sp {
PlatformDisplay* PlatformDisplay::make(Display* parent) PlatformDisplay* PlatformDisplay::make(Display* parent)
{ {
DisplayType* disp = new DisplayType(); DisplayType* disp = new DisplayType();
@ -30,3 +32,5 @@ void PlatformDisplay::onReshape(int width, int height)
// Forward to parent. // Forward to parent.
m_parent->onReshape(width, height); m_parent->onReshape(width, height);
} }
} // namespace sp

View file

@ -8,6 +8,8 @@
// Low-level platform dependant API. // Low-level platform dependant API.
#include <string> #include <string>
namespace sp {
class Display; class Display;
class PlatformDisplay class PlatformDisplay
@ -46,7 +48,9 @@ protected :
private : private :
Display* m_parent; Display * m_parent;
}; };
} // namespace sp
#endif /* SPECTRE_PLATFORM_DISPLAY_H */ #endif /* SPECTRE_PLATFORM_DISPLAY_H */

View file

@ -2,6 +2,8 @@
#ifndef PLATFORM_INPUT_H #ifndef PLATFORM_INPUT_H
#define PLATFORM_INPUT_H #define PLATFORM_INPUT_H
namespace sp {
class Keyboard; class Keyboard;
class Mouse; class Mouse;
@ -15,4 +17,6 @@ public :
virtual void update() = 0; virtual void update() = 0;
}; };
} // namespace sp
#endif /* PLATFORM_INPUT_H */ #endif /* PLATFORM_INPUT_H */

View file

@ -3,9 +3,10 @@
#define PLATFORM_MISC_H #define PLATFORM_MISC_H
#include <Spectre/Display/DisplayMode.h> #include <Spectre/Display/DisplayMode.h>
#include <vector> #include <vector>
namespace sp {
class DisplayMode; class DisplayMode;
class PlatformMisc class PlatformMisc
@ -16,4 +17,6 @@ public:
static DisplayMode GetDesktopMode(); static DisplayMode GetDesktopMode();
}; };
} // namespace sp
#endif /* PLATFORM_MISC_H */ #endif /* PLATFORM_MISC_H */

View file

@ -4,6 +4,8 @@
#include "Win32Mouse.h" #include "Win32Mouse.h"
#include "Win32Application.h" #include "Win32Application.h"
namespace sp {
void Win32Application::init() void Win32Application::init()
{ {
} }
@ -94,3 +96,5 @@ LRESULT Win32Application::processMessage(MSG msg)
// Message was not intercepted. Pass down to window. // Message was not intercepted. Pass down to window.
return DispatchMessage(&msg); return DispatchMessage(&msg);
} }
} // namespace sp

View file

@ -9,6 +9,8 @@
#include <Spectre/System/MessageQueue.h> #include <Spectre/System/MessageQueue.h>
#include <Platform/PlatformApplication.h> #include <Platform/PlatformApplication.h>
namespace sp {
class Win32Application : public PlatformApplication class Win32Application : public PlatformApplication
{ {
public : public :
@ -35,4 +37,6 @@ protected :
MessageQueue m_messageQueue; MessageQueue m_messageQueue;
}; };
} // namespace sp
#endif /* WIN32_PLATFORM_H */ #endif /* WIN32_PLATFORM_H */

Some files were not shown because too many files have changed in this diff Show more