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

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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