De-namespaced a class, to make it less verbose.

This commit is contained in:
Alex Szpakowski
2015-01-24 04:09:56 -04:00
parent e662fbdf80
commit cf60cf89fc
17 changed files with 88 additions and 115 deletions
+60 -87
View File
@@ -72,93 +72,6 @@ public:
**/
virtual void release();
/**
* Meant to be used as a temporary object. Facilitates safer and cleaner
* code to release objects by doing so when the AutoRelease object is
* destroyed (e.g. goes out of scope.)
**/
class AutoRelease
{
public:
AutoRelease(Object *obj)
: object(obj)
{
}
~AutoRelease()
{
if (object)
object->release();
}
private:
AutoRelease() {}
Object *object;
}; // AutoRelease
/**
* Partial re-implementation + specialization of std::shared_ptr. We can't
* use C++11's stdlib yet...
**/
template <typename T>
class StrongRef
{
public:
StrongRef()
: object(nullptr)
{
}
StrongRef(T *obj)
: object(obj)
{
if (object) object->retain();
}
StrongRef(const StrongRef &other)
: object(other.get())
{
if (object) object->retain();
}
~StrongRef()
{
if (object) object->release();
}
StrongRef &operator = (const StrongRef &other)
{
set(other.get());
return *this;
}
T *operator->() const
{
return object;
}
void set(T *obj)
{
if (obj) obj->retain();
if (object) object->release();
object = obj;
}
T *get() const
{
return object;
}
private:
T *object;
}; // StrongRef
private:
// The reference count.
@@ -166,6 +79,66 @@ private:
}; // Object
/**
* Partial re-implementation + specialization of std::shared_ptr. We can't
* use C++11's stdlib yet...
**/
template <typename T>
class StrongRef
{
public:
StrongRef()
: object(nullptr)
{
}
StrongRef(T *obj)
: object(obj)
{
if (object) object->retain();
}
StrongRef(const StrongRef &other)
: object(other.get())
{
if (object) object->retain();
}
~StrongRef()
{
if (object) object->release();
}
StrongRef &operator = (const StrongRef &other)
{
set(other.get());
return *this;
}
T *operator->() const
{
return object;
}
void set(T *obj)
{
if (obj) obj->retain();
if (object) object->release();
object = obj;
}
T *get() const
{
return object;
}
private:
T *object;
}; // StrongRef
} // love
#endif // LOVE_OBJECT_H
+2 -2
View File
@@ -148,7 +148,7 @@ private:
static const unsigned int MAX_BUFFERS = 8;
ALuint streamBuffers[MAX_BUFFERS];
Object::StrongRef<StaticDataBuffer> staticBuffer;
StrongRef<StaticDataBuffer> staticBuffer;
float pitch;
float volume;
@@ -183,7 +183,7 @@ private:
int sampleRate;
int channels;
Object::StrongRef<love::sound::Decoder> decoder;
StrongRef<love::sound::Decoder> decoder;
unsigned int toLoop;
+1 -1
View File
@@ -53,7 +53,7 @@ private:
void load();
// The image data
Object::StrongRef<love::image::ImageData> imageData;
StrongRef<love::image::ImageData> imageData;
// The glyphs in the font
uint32 *glyphs;
@@ -58,7 +58,7 @@ private:
FT_Face face;
// File data
Object::StrongRef<Data> data;
StrongRef<Data> data;
}; // FreetypeRasterizer
} // freetype
+1 -1
View File
@@ -185,7 +185,7 @@ private:
Glyph *addGlyph(uint32 glyph);
Glyph *findGlyph(uint32 glyph);
Object::StrongRef<love::font::Rasterizer> rasterizer;
StrongRef<love::font::Rasterizer> rasterizer;
int height;
float lineHeight;
+7 -7
View File
@@ -173,7 +173,7 @@ void Graphics::setViewportSize(int width, int height)
// We want to affect the main screen, not any Canvas that's currently active
// (not that any *should* be active when this is called.)
std::vector<Object::StrongRef<Canvas>> canvases = states.back().canvases;
std::vector<StrongRef<Canvas>> canvases = states.back().canvases;
setCanvas();
// Set the viewport to top-left corner.
@@ -662,7 +662,7 @@ void Graphics::setCanvas(Canvas *canvas)
canvas->startGrab();
std::vector<Object::StrongRef<Canvas>> canvasref;
std::vector<StrongRef<Canvas>> canvasref;
canvasref.push_back(canvas);
std::swap(state.canvases, canvasref);
@@ -680,7 +680,7 @@ void Graphics::setCanvas(const std::vector<Canvas *> &canvases)
auto attachments = std::vector<Canvas *>(canvases.begin() + 1, canvases.end());
canvases[0]->startGrab(attachments);
std::vector<Object::StrongRef<Canvas>> canvasrefs;
std::vector<StrongRef<Canvas>> canvasrefs;
canvasrefs.reserve(canvases.size());
for (Canvas *c : canvases)
@@ -689,12 +689,12 @@ void Graphics::setCanvas(const std::vector<Canvas *> &canvases)
std::swap(state.canvases, canvasrefs);
}
void Graphics::setCanvas(const std::vector<Object::StrongRef<Canvas>> &canvases)
void Graphics::setCanvas(const std::vector<StrongRef<Canvas>> &canvases)
{
std::vector<Canvas *> canvaslist;
canvaslist.reserve(canvases.size());
for (const Object::StrongRef<Canvas> &c : canvases)
for (const StrongRef<Canvas> &c : canvases)
canvaslist.push_back(c.get());
return setCanvas(canvaslist);
@@ -715,7 +715,7 @@ std::vector<Canvas *> Graphics::getCanvas() const
std::vector<Canvas *> canvases;
canvases.reserve(states.back().canvases.size());
for (const Object::StrongRef<Canvas> &c : states.back().canvases)
for (const StrongRef<Canvas> &c : states.back().canvases)
canvases.push_back(c.get());
return canvases;
@@ -1091,7 +1091,7 @@ love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool
{
// Temporarily unbind the currently active canvas (glReadPixels reads the
// active framebuffer, not the main one.)
std::vector<Object::StrongRef<Canvas>> canvases = states.back().canvases;
std::vector<StrongRef<Canvas>> canvases = states.back().canvases;
setCanvas();
int w = getWidth();
+4 -4
View File
@@ -207,7 +207,7 @@ public:
void setCanvas(Canvas *canvas);
void setCanvas(const std::vector<Canvas *> &canvases);
void setCanvas(const std::vector<Object::StrongRef<Canvas>> &canvases);
void setCanvas(const std::vector<StrongRef<Canvas>> &canvases);
void setCanvas();
std::vector<Canvas *> getCanvas() const;
@@ -458,10 +458,10 @@ private:
bool scissor;
OpenGL::Viewport scissorBox;
Object::StrongRef<Font> font;
Object::StrongRef<Shader> shader;
StrongRef<Font> font;
StrongRef<Shader> shader;
std::vector<Object::StrongRef<Canvas>> canvases;
std::vector<StrongRef<Canvas>> canvases;
ColorMask colorMask;
+2 -2
View File
@@ -158,11 +158,11 @@ private:
// The ImageData from which the texture is created. May be null if
// Compressed image data was used to create the texture.
Object::StrongRef<love::image::ImageData> data;
StrongRef<love::image::ImageData> data;
// Or the Compressed Image Data from which the texture is created. May be
// null if raw ImageData was used to create the texture.
Object::StrongRef<love::image::CompressedData> cdata;
StrongRef<love::image::CompressedData> cdata;
// Real dimensions of the texture, if it was auto-padded to POT size.
int paddedWidth, paddedHeight;
+1 -1
View File
@@ -178,7 +178,7 @@ private:
int range_min;
int range_max;
Object::StrongRef<Texture> texture;
StrongRef<Texture> texture;
// Whether the per-vertex colors are used when drawing.
bool colors_enabled;
@@ -739,7 +739,7 @@ std::vector<Quad *> ParticleSystem::getQuads() const
std::vector<Quad *> quadlist;
quadlist.reserve(quads.size());
for (const Object::StrongRef<Quad> &q : quads)
for (const StrongRef<Quad> &q : quads)
quadlist.push_back(q.get());
return quadlist;
+2 -2
View File
@@ -576,7 +576,7 @@ protected:
Vertex *particleVerts;
// The texture to be drawn.
Object::StrongRef<Texture> texture;
StrongRef<Texture> texture;
// Whether the particle emitter is active.
bool active;
@@ -656,7 +656,7 @@ protected:
std::vector<Colorf> colors;
// Quads.
std::vector<Object::StrongRef<Quad>> quads;
std::vector<StrongRef<Quad>> quads;
bool relativeRotation;
+1 -1
View File
@@ -124,7 +124,7 @@ private:
*/
void setColorv(Vertex *v, const Color &color);
Object::StrongRef<Texture> texture;
StrongRef<Texture> texture;
// Max number of sprites in the batch.
int size;
+1 -1
View File
@@ -69,7 +69,7 @@ public:
private:
Object::StrongRef<love::mouse::Cursor> curCursor;
StrongRef<love::mouse::Cursor> curCursor;
std::map<Cursor::SystemCursor, Cursor *> systemCursors;
+1 -1
View File
@@ -441,7 +441,7 @@ private:
//
// This ensures that a World only can be destroyed
// once all bodies have been destroyed too.
Object::StrongRef<World> world;
StrongRef<World> world;
bodyudata *udata;
+1 -1
View File
@@ -53,7 +53,7 @@ protected:
// The encoded data. This should be replaced with buffered file
// reads in the future.
Object::StrongRef<Data> data;
StrongRef<Data> data;
// File extension.
std::string ext;
+1 -1
View File
@@ -50,7 +50,7 @@ private:
void onError();
Object::StrongRef<love::Data> code;
StrongRef<love::Data> code;
std::string name;
std::string error;
+1 -1
View File
@@ -123,7 +123,7 @@ private:
int width;
int height;
WindowSettings settings;
Object::StrongRef<love::image::ImageData> icon;
StrongRef<love::image::ImageData> icon;
} curMode;