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

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

View file

@ -6,7 +6,7 @@
#include <string>
namespace core
namespace sp { namespace core
{
// 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, unsigned int precision);
};
} } // namespace sp::core
#endif /* SPECTRE_CORE_STRING_H */

View file

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

View file

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

View file

@ -4,6 +4,8 @@
#include <vector>
namespace sp {
class DisplayMode
{
public :
@ -16,7 +18,7 @@ public :
inline bool operator==(const DisplayMode& other)
{
return width == other.width
return width == other.width
&& height == other.height
&& bpp == other.bpp;
}
@ -32,4 +34,6 @@ public :
unsigned int bpp; /* Bits per pixel. */
};
} // namespace sp
#endif /* SPECTRE_DISPLAY_DISPLAYMODE_H */

View file

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

View file

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

View file

@ -4,6 +4,8 @@
// Simple FPS counter.
namespace sp {
class FPSCounter
{
public :
@ -29,7 +31,7 @@ private :
// Frame counter.
unsigned int m_count;
// time (in ms)
unsigned int m_time;
@ -40,4 +42,6 @@ private :
float m_fps;
};
} // namespace sp
#endif /* SPECTRE_FPS_COUNTER_H */

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,6 +5,8 @@
#include <string>
#include <vector>
namespace sp {
namespace MouseButton {
enum Type {
@ -120,7 +122,7 @@ typedef struct InputEvent
MousePosition
};
struct KeyEvent {
struct KeyEvent {
Key::Type code;
bool pressed; /* true if pressed, false if released. */
@ -150,4 +152,6 @@ typedef struct InputEvent
} InputEvent;
} // namespace sp
#endif /* SPECTRE_INPUT_EVENT_H */

View file

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

View file

@ -8,6 +8,8 @@
#include "InputListener.h"
#include "InputEvent.h"
namespace sp {
class Mouse;
class Keyboard;
class InputDevice;
@ -38,7 +40,7 @@ public :
protected :
void dispatch();
typedef std::vector<InputDevice*> InputDeviceVec;
InputDeviceVec m_devices;
@ -54,4 +56,6 @@ protected :
PlatformInput *m_platform;
};
} // namespace sp
#endif /* SPECTRE_INPUT_MODULE_H */

View file

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

View file

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

View file

@ -5,6 +5,8 @@
#include "Vector3.h"
#include "Vector4.h"
namespace sp {
// Basic structure representing a color in 32bit RGBA
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);
} // namespace sp
#endif /* SPECTRE_MATH_COLOR_H */

View file

@ -6,7 +6,7 @@
#include "Vector2.h"
#include "Matrix4.h"
namespace math
namespace sp { namespace math
{
float rand(float min, float max);
@ -28,13 +28,13 @@ namespace math
// ------------------------------
// Create a orthographic projection matrix.
Matrix4f orthoProjection(float left, float right,
float bottom, float top,
Matrix4f orthoProjection(float left, float right,
float bottom, float top,
float zNear = -1.0f, float zFar = 1.0f);
// Create a 2D rotation matrix. (rotation around Z-axis)
Matrix4f rotation(float theta);
// Create a 2D translation matrix.
Matrix4f translate(const Vector2f& v);
@ -47,6 +47,7 @@ namespace math
Vector3f getUpVector(const Matrix4f matrix);
Vector3f getForwardVector(const Matrix4f matrix);
};
} } // namespace sp
#endif /* SPECTRE_MATH_MATH_H */

View file

@ -7,6 +7,8 @@
#include <iostream>
#include <Spectre/Math/Vector2.h>
namespace sp {
template<typename T>
struct Matrix3
{
@ -20,7 +22,7 @@ struct Matrix3
| 0 3 6 |
| 1 4 7 |
| 2 5 8 |
|_ _|
|_ _|
*/
T v[9];
};
@ -77,6 +79,8 @@ typedef Matrix3<double> Matrix3d;
typedef Matrix3<int> Matrix3i;
typedef Matrix3<unsigned> Matrix3u;
} // namespace sp
#include "Matrix3.inl"
#endif /* SPECTRE_MATH_MATRIX3_H */

View file

@ -2,6 +2,8 @@
#include <string>
#include "Matrix3.h"
namespace sp {
template <>
Matrix3f Matrix3f::Identity(
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[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/Vector2.h>
namespace sp {
template<typename T>
struct Matrix4
{
@ -100,10 +102,11 @@ typedef Matrix4<double> mat4d;
typedef Matrix4<int> mat4i;
typedef Matrix4<unsigned> mat4u;
} // namespace sp
// ----------------
// Implementation
// ----------------
#include "Matrix4.inl"
#endif /* SPECTRE_MATH_MATRIX4_H */

View file

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

View file

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

View file

@ -5,11 +5,13 @@
#include <string>
#include <iostream>
namespace sp {
template <typename T>
struct Vector2
{
union {
struct {
struct {
T x, y;
};
T v[2];
@ -111,7 +113,7 @@ template <typename T>
inline Vector2<T> operator+(T s, const Vector2<T>& v);
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>
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);
template <typename T>
inline Vector2<T>& operator-=(Vector2<T>& v,T s);
inline Vector2<T>& operator-=(Vector2<T>& v, T s);
template <typename T>
inline Vector2<T>& operator/=(Vector2<T>& v, T s);
@ -190,6 +192,8 @@ typedef Vector2<int> vec2i;
typedef Vector2<unsigned> vec2u;
typedef Vector2<unsigned char> vec2b;
} // namespace sp
#include "Vector2.inl"
#endif /* SPECTRE_MATH_VECTOR2_H */

View file

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

View file

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

View file

@ -2,6 +2,8 @@
#include <math.h>
#include "Vector3.h"
namespace sp {
template <typename T>
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 << ")";
}
} // namespace sp

View file

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

View file

@ -2,6 +2,8 @@
#include <math.h>
#include "Vector4.h"
namespace sp {
template <typename T>
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 << ")";
}
} // namespace sp

View file

@ -13,6 +13,8 @@
// TODO: Zoom is implemented using a scale matrix.
// It's abit weird to control. Must be a better solution.
namespace sp {
class Camera2D : public ICamera
{
public :
@ -29,7 +31,7 @@ public :
void move(float x, float y);
void move(const Vector2f& vec);
void moveUp(float delta);
void moveRight(float delta);
@ -80,4 +82,6 @@ protected :
mutable bool m_projViewNeedsUpdate;
};
} // namespace sp
#endif /* SPECTRE_SCENE_CAMERA2D_H */

View file

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

View file

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

View file

@ -2,6 +2,10 @@
#ifndef 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 */

View file

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

View file

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

View file

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

View file

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