Permalink
Browse files

Remove auto-ref template bloat and pass by value

  • Loading branch information...
Dgame committed May 20, 2015
1 parent 5b3c17e commit 6488a686e81124173785490ad2b2690b0fb6f3eb
@@ -97,7 +97,7 @@ struct Color4b {
* Expect that every component is in range 0.0 .. 1.0
*/
@nogc
this()(auto ref const Color4f col) pure nothrow
this(const Color4f col) pure nothrow
in {
assert(col.red >= 0f && col.red <= 1f);
assert(col.green >= 0f && col.green <= 1f);
@@ -219,7 +219,7 @@ struct Color4f {
* CTor
*/
@nogc
this()(auto ref const Color4b col) pure nothrow {
this(ref const Color4b col) pure nothrow {
this(col.red, col.green, col.blue, col.alpha);
}
@@ -131,7 +131,7 @@ final:
/**
* CTor for circles
*/
this()(size_t radius, auto ref const Vector2f center, size_t vecNum = 30) pure nothrow {
this(size_t radius, const Vector2f center, size_t vecNum = 30) pure nothrow {
import std.math : PI, cos, sin;
assert(vecNum >= 10, "Too few edges for a circle");
@@ -164,7 +164,7 @@ final:
/**
* Stores a Vertex
*/
void append()(auto ref const Vertex vertex) pure nothrow {
void append(const Vertex vertex) pure nothrow {
_vertices ~= vertex;
}
@@ -191,7 +191,7 @@ final:
* and adapt the specific entries.
*/
@nogc
void setColor()(auto ref const Color4b col) pure nothrow {
void setColor(const Color4b col) pure nothrow {
foreach (ref Vertex v; _vertices) {
v.color = Color4f(col);
}
@@ -211,11 +211,11 @@ final:
* Set (or reset) a Texture and set the corresponding Rect
*/
@nogc
void setTexture()(Texture* texture, auto ref const Rect rect) pure nothrow {
void setTexture(Texture* texture, const Rect rect) pure nothrow {
_texture = texture;
if (texture)
this.setTextureArea(rect);
this.setTextureRect(rect);
}
/**
@@ -230,7 +230,7 @@ final:
* Set the corresponding Texture Rect
*/
@nogc
void setTextureRect()(auto ref const Rect rect) pure nothrow {
void setTextureRect(const Rect rect) pure nothrow {
assert(_texture, "No texture defined");
const Rect clip = this.getVertexRect();
@@ -103,7 +103,7 @@ final:
* CTor
*/
@nogc
this()(ref Texture tex, auto ref const Vector2f pos) pure nothrow {
this(ref Texture tex, const Vector2f pos) pure nothrow {
this(tex);
super.setPosition(pos);
@@ -134,7 +134,7 @@ final:
* Set a Color for the Sprite which is painted over the displayed Texture.
*/
@nogc
void setColor()(auto ref const Color4b col) pure nothrow {
void setColor(const Color4b col) pure nothrow {
foreach (ref Vertex v; _vertices) {
v.color = Color4f(col);
}
@@ -145,7 +145,7 @@ final:
* so that only this specific view will be drawn.
*/
@nogc
void setTextureRect()(auto ref const Rect texRect) {
void setTextureRect(const Rect texRect) pure nothrow {
_texRect = texRect;
_updateVertices();
}
@@ -69,7 +69,7 @@ final:
* CTor
*/
@nogc
this()(ref Texture tex, auto ref const Rect texRect) pure nothrow {
this(ref Texture tex, const Rect texRect) pure nothrow {
this(tex);
super.setTextureRect(texRect);
@@ -209,7 +209,7 @@ public:
* If it's null, the whole Surface is filled.
*/
@nogc
void fill()(auto ref const Color4b col, const Rect* rect = null) nothrow {
void fill(const Color4b col, const Rect* rect = null) nothrow {
if (!_surface)
return;
@@ -308,7 +308,7 @@ public:
* Set the colorkey.
*/
@nogc
void setColorkey()(auto ref const Color4b col) nothrow {
void setColorkey(const Color4b col) nothrow {
if (!_surface)
return;
@@ -390,7 +390,7 @@ public:
* Set the clip rect.
*/
@nogc
void setClipRect()(auto ref const Rect clip) nothrow {
void setClipRect(const Rect clip) nothrow {
if (_surface) {
SDL_Rect a = void;
SDL_SetClipRect(_surface, _transfer(clip, a));
@@ -487,15 +487,15 @@ public:
* Returns the pixel at the given coordinates.
*/
@nogc
int getPixelAt()(auto ref const Vector2i pos) const nothrow {
int getPixelAt(const Vector2i pos) const nothrow {
return this.getPixelAt(pos.x, pos.y);
}
/**
* Put a new pixel at the given coordinates.
*/
@nogc
void putPixelAt()(auto ref const Vector2i pos, uint pixel) nothrow {
void putPixelAt(const Vector2i pos, uint pixel) nothrow {
if (!_surface)
return;
@@ -531,7 +531,7 @@ public:
* Returns the color on the given position.
*/
@nogc
Color4b getColorAt()(auto ref const Vector2i pos) const nothrow {
Color4b getColorAt(const Vector2i pos) const nothrow {
return this.getColorAt(pos.x, pos.y);
}
@@ -591,11 +591,11 @@ public:
* The subsurface is a separate Surface object.
*/
@nogc
Surface subSurface()(auto ref const Rect rect) nothrow {
Surface subSurface(const Rect rect) nothrow {
assert(!rect.isEmpty(), "Cannot take a empty subsurface.");
assert(_surface, "Cannot take a subsurface from null.");
SDL_Surface* sub = this.create(rect.width, rect.height);
SDL_Surface* sub = this.create(Masks.Zero, rect.width, rect.height, 32, null);
assert(sub, "Failed to construct a sub surface.");
SDL_Rect clip = void;
@@ -94,7 +94,7 @@ public:
* CTor
*/
@nogc
this()(auto ref const Surface srfc, Format fmt = Format.None) nothrow {
this(const Surface srfc, Format fmt = Format.None) nothrow {
this.loadFrom(srfc, fmt);
}
@@ -259,7 +259,7 @@ public:
* Load from Surface
*/
@nogc
void loadFrom()(auto ref const Surface srfc, Format fmt = Format.None) nothrow {
void loadFrom(const Surface srfc, Format fmt = Format.None) nothrow {
assert(srfc.isValid(), "Cannot load invalid Surface");
if (fmt == Format.None) {
@@ -306,7 +306,7 @@ public:
* Set a colorkey.
*/
@nogc
void setColorkey()(auto ref const Color4b colorkey) nothrow {
void setColorkey(const Color4b colorkey) nothrow {
if (_texId == 0)
return;
@@ -92,7 +92,7 @@ final:
* Sets the position
*/
@nogc
void setPosition()(auto ref const Vector2f pos) pure nothrow {
void setPosition(const Vector2f pos) pure nothrow {
_position = pos;
_notifyTransform();
}
@@ -111,7 +111,7 @@ final:
* Move the position by offset (x, y)
*/
@nogc
void move()(auto ref const Vector2f offset) pure nothrow {
void move(const Vector2f offset) pure nothrow {
_position += offset;
_notifyTransform();
}
@@ -186,7 +186,7 @@ final:
* the origin takes the place of the rotation center.
*/
@nogc
void setRotationCenter()(auto ref const Vector2f center) pure nothrow {
void setRotationCenter(const Vector2f center) pure nothrow {
_rotationCenter = center;
_notifyTransform();
}
@@ -221,7 +221,7 @@ final:
* the origin will suppress the rotation center and takes it's place.
*/
@nogc
void setOrigin()(auto ref const Vector2f origin) pure nothrow {
void setOrigin(const Vector2f origin) pure nothrow {
_origin = origin;
_notifyTransform();
}
@@ -248,7 +248,7 @@ final:
* Sets the scaling (for both, x and y)
*/
@nogc
void setScale()(auto ref const Vector2f offset) pure nothrow {
void setScale(const Vector2f offset) pure nothrow {
_scale = offset;
_notifyTransform();
}
@@ -257,7 +257,7 @@ final:
* Inc-/Decrease the scaling
*/
@nogc
void scale()(auto ref const Vector2f offset) pure nothrow {
void scale(const Vector2f offset) pure nothrow {
_scale += offset;
_notifyTransform();
}
@@ -82,7 +82,7 @@ final:
/**
* Stores a Vertex
*/
void append()(auto ref const Vertex vertex) pure nothrow {
void append(const Vertex vertex) pure nothrow {
_vertices ~= vertex;
}
@@ -93,7 +93,7 @@ final:
*
* Note: This method only works for Geometry.Quads.
*/
void appendQuad()(auto ref const Vector2f position, auto ref const Rect texRect) pure nothrow {
void appendQuad(const Vector2f position, const Rect texRect) pure nothrow {
assert(this.geometry == Geometry.Quads, "This method supports only Geometry.Quads");
immutable float tx = float(texRect.x) / _texture.width;
@@ -112,25 +112,25 @@ final:
_vertices ~= Vertex(
position,
Vector2f(tx, ty),
Color4f.White
Color4b.White
);
_vertices ~= Vertex(
Vector2f(cx_tw, position.y),
Vector2f(tx_tw, ty),
Color4f.White
Color4b.White
);
_vertices ~= Vertex(
Vector2f(cx_tw, cy_th),
Vector2f(tx_tw, ty_th),
Color4f.White
Color4b.White
);
_vertices ~= Vertex(
Vector2f(position.x, cy_th),
Vector2f(tx, ty_th),
Color4f.White
Color4b.White
);
}
@@ -134,7 +134,7 @@ public:
* Translate the Matrix
*/
@nogc
ref Matrix4x4 translate()(auto ref const Vector2f vec) pure nothrow {
ref Matrix4x4 translate(const Vector2f vec) pure nothrow {
const Matrix4x4 translation = Matrix4x4(1, 0, vec.x,
0, 1, vec.y,
0, 0, 1);
@@ -160,7 +160,7 @@ public:
* Rotate the Matrix about angle (in degree!) about the given center position
*/
@nogc
ref Matrix4x4 rotate()(float angle, auto ref const Vector2f center) pure nothrow {
ref Matrix4x4 rotate(float angle, const Vector2f center) pure nothrow {
immutable float rad = angle * std.math.PI / 180f;
immutable float cos = std.math.cos(rad);
immutable float sin = std.math.sin(rad);
@@ -175,7 +175,7 @@ public:
* Scale the Matrix about factor scale
*/
@nogc
ref Matrix4x4 scale()(auto ref const Vector2f scale) pure nothrow {
ref Matrix4x4 scale(const Vector2f scale) pure nothrow {
const Matrix4x4 scaling = Matrix4x4(scale.x, 0, 0,
0, scale.y, 0,
0, 0, 1);
@@ -187,7 +187,7 @@ public:
* Scale the Matrix about factor scale about the given center position
*/
@nogc
ref Matrix4x4 scale()(auto ref const Vector2f scale, auto ref const Vector2f center) pure nothrow {
ref Matrix4x4 scale(const Vector2f scale, const Vector2f center) pure nothrow {
const Matrix4x4 scaling = Matrix4x4(scale.x, 0, center.x * (1 - scale.x),
0, scale.y, center.y * (1 - scale.y),
0, 0, 1);
@@ -200,31 +200,31 @@ public:
* See: <a href="http://3dgep.com/understanding-the-view-matrix/#Look_At_Camera">here</a>
*/
@nogc
void lookAt()(auto ref const Vector3f eye, auto ref const Vector3f look, auto ref const Vector3f up) pure nothrow {
void lookAt(const Vector3f eye, const Vector3f look, const Vector3f up) pure nothrow {
const Vector3f dir = (look - eye).normalize();
const Vector3f right = dir.cross(up).normalize();
const Vector3f up2 = right.cross(dir).normalize();
Matrix4x4 mat;
mat.values[0] = right.x;
mat.values[4] = right.y;
mat.values[8] = right.z;
mat.values[12] = -right.dot(eye);
mat.values[1] = up2.x;
mat.values[5] = up2.y;
mat.values[9] = up2.z;
mat.values[13] = -up2.dot(eye);
mat.values[2] = -dir.x;
mat.values[6] = -dir.y;
mat.values[10] = -dir.z;
mat.values[14] = dir.dot(eye);
mat.values[3] = 0;
mat.values[7] = 0;
mat.values[11] = 0;
mat.values[15] = 1;
mat[0] = right.x;
mat[4] = right.y;
mat[8] = right.z;
mat[12] = -right.dot(eye);
mat[1] = up2.x;
mat[5] = up2.y;
mat[9] = up2.z;
mat[13] = -up2.dot(eye);
mat[2] = -dir.x;
mat[6] = -dir.y;
mat[10] = -dir.z;
mat[14] = dir.dot(eye);
mat[3] = 0;
mat[7] = 0;
mat[11] = 0;
mat[15] = 1;
merge(this, mat);
}
@@ -255,7 +255,7 @@ public:
* See: <a href="http://www.songho.ca/opengl/gl_projectionmatrix.html#ortho">here</a>
*/
@nogc
bool ortho()(auto ref const Rect rect, float zNear = 1, float zFar = -1) pure nothrow {
bool ortho(const Rect rect, float zNear = 1, float zFar = -1) pure nothrow {
if (!rect.isEmpty()) {
immutable float inv_z = 1.0 / (zFar - zNear);
immutable float inv_y = 1.0 / (cast(float) rect.x - rect.height);
Oops, something went wrong.

0 comments on commit 6488a68

Please sign in to comment.