mirror of
https://bitbucket.org/King_DuckZ/jumping-in-d.git
synced 2024-10-30 02:49:01 +00:00
Add the ObjRef wrapper.
This commit is contained in:
parent
71c4f0f089
commit
af02f4a868
3 changed files with 45 additions and 3 deletions
|
@ -21,6 +21,7 @@ add_executable(${PROJECT_NAME}
|
||||||
src/collisionline.d
|
src/collisionline.d
|
||||||
src/rect.d
|
src/rect.d
|
||||||
src/collidingentity.d
|
src/collidingentity.d
|
||||||
|
src/objref.d
|
||||||
|
|
||||||
lib/DerelictSDL2/source/derelict/sdl2/functions.d
|
lib/DerelictSDL2/source/derelict/sdl2/functions.d
|
||||||
lib/DerelictSDL2/source/derelict/sdl2/image.d
|
lib/DerelictSDL2/source/derelict/sdl2/image.d
|
||||||
|
|
|
@ -18,11 +18,12 @@
|
||||||
module collisionline;
|
module collisionline;
|
||||||
public import vector : Vector;
|
public import vector : Vector;
|
||||||
import rect : Rect;
|
import rect : Rect;
|
||||||
|
import objref;
|
||||||
|
|
||||||
alias vec2 = Vector!(float, 2);
|
alias vec2 = Vector!(float, 2);
|
||||||
|
|
||||||
struct CollisionLine {
|
struct CollisionLine {
|
||||||
this (in vec2 parA, in vec2 parB) {
|
this (vec2 parA, vec2 parB) {
|
||||||
m_from = parA;
|
m_from = parA;
|
||||||
m_to = parB;
|
m_to = parB;
|
||||||
assert(m_from != m_to);
|
assert(m_from != m_to);
|
||||||
|
@ -55,11 +56,15 @@ struct CollisionQuad {
|
||||||
alias m_lines this;
|
alias m_lines this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool collides (CollisionLine parLine, CollisionLine parLine1, vec2 parOffs, out vec2 parPoint) {
|
alias CollisionQuadRef = TObjRef!(const(CollisionQuad)).ObjRef;
|
||||||
|
alias CollisionLineRef = TObjRef!(const(CollisionLine)).ObjRef;
|
||||||
|
alias vec2ref = TObjRef!(const(vec2)).ObjRef;
|
||||||
|
|
||||||
|
bool collides (CollisionLineRef parLine, CollisionLineRef parLine1, vec2ref parOffs, out vec2 parPoint) {
|
||||||
parPoint = vec2(0.0f);
|
parPoint = vec2(0.0f);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool collides (CollisionQuad parQuad, CollisionQuad parQuad1, vec2 parOffs, out vec2 parPoint) {
|
bool collides (CollisionQuadRef parQuad, CollisionQuadRef parQuad1, vec2ref parOffs, out vec2 parPoint) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
36
src/objref.d
Normal file
36
src/objref.d
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/* Copyright 2015, Michele Santullo
|
||||||
|
* This file is part of "Jumping in D".
|
||||||
|
*
|
||||||
|
* "Jumping in D" is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* "Jumping in D" is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with "Jumping in D". If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module objref;
|
||||||
|
|
||||||
|
template TObjRef(T) {
|
||||||
|
static if (T.sizeof > size_t.sizeof) {
|
||||||
|
struct ObjRef {
|
||||||
|
this(ref T parMainObj) {
|
||||||
|
m_ref = &parMainObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
ref inout(T) get_ref() inout { return *m_ref; }
|
||||||
|
alias get_ref this;
|
||||||
|
|
||||||
|
private T* m_ref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alias ObjRef = T;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue