replaced all crappy spaces with proper tabs

kept this in its own changeset so it doesn't interfere with real changes

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1334 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
trass3r 2010-01-06 20:37:29 +00:00
parent 8431753ba3
commit 2f2fc5d4fa
56 changed files with 8094 additions and 8094 deletions

View file

@ -1,37 +1,37 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.all;
version (linux)
{
version (build)
{
pragma(link, "dl"); //Link libdl.so (dlopen, dlsym)
}
version (build)
{
pragma(link, "dl"); //Link libdl.so (dlopen, dlsym)
}
}
@ -43,4 +43,4 @@ public import
dsfml.system.sleep,
// dsfml.system.thread, // thread isn't used anywhere in the library and D threading is nice, so the user can safely use standard threads
dsfml.system.vector2,
dsfml.system.vector3;
dsfml.system.vector3;

View file

@ -1,84 +1,84 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.alloc;
version (Tango)
{
public import tango.core.Memory;
public import tango.core.Memory;
}
else
{
public import core.memory;
public import core.memory;
}
/*
struct GC
{
static void* malloc(uint size)
{
return std.c.stdlib.malloc(size);
}
static void free(void* ptr)
{
std.c.stdlib.free(ptr);
}
static void addRange(void* ptr, uint size)
{
std.gc.addRange(ptr, ptr + size);
}
static void removeRange(void* ptr)
{
std.gc.removeRange(ptr);
}
}
struct GC
{
static void* malloc(uint size)
{
return std.c.stdlib.malloc(size);
}
static void free(void* ptr)
{
std.c.stdlib.free(ptr);
}
static void addRange(void* ptr, uint size)
{
std.gc.addRange(ptr, ptr + size);
}
static void removeRange(void* ptr)
{
std.gc.removeRange(ptr);
}
}
*/
/*
* Template for native non-GCed allocation for interaction between C and D threads.
* Template for native non-GCed allocation for interaction between C and D threads.
*/
template Alloc()
{
new (uint size)
{
void* p = GC.malloc(size);
if (!p)
assert(0, "Memory allocation failed");
GC.addRange(p, size);
return p;
}
new (uint size)
{
void* p = GC.malloc(size);
if (!p)
assert(0, "Memory allocation failed");
GC.addRange(p, size);
return p;
}
delete(void* p)
{
GC.removeRange(p);
GC.free(p);
}
delete(void* p)
{
GC.removeRange(p);
GC.free(p);
}
}

View file

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.clock;
@ -33,69 +33,69 @@ import dsfml.system.common;
*/
class Clock : DSFMLObject
{
/**
* Default constructor
*/
this()
{
super(sfClock_Create());
}
/**
* Default constructor
*/
this()
{
super(sfClock_Create());
}
/**
* Destructor
*/
override void dispose()
{
sfClock_Destroy(m_ptr);
}
/**
* Destructor
*/
override void dispose()
{
sfClock_Destroy(m_ptr);
}
/**
* Return the time elapsed since the last reset
* Returns:
* Elapsed Time in seconds
*/
float getElapsedTime()
{
return sfClock_GetTime(m_ptr);
}
/**
* Return the time elapsed since the last reset
* Returns:
* Elapsed Time in seconds
*/
float getElapsedTime()
{
return sfClock_GetTime(m_ptr);
}
/**
* Restart the timer
*/
void reset()
{
sfClock_Reset(m_ptr);
}
/**
* Restart the timer
*/
void reset()
{
sfClock_Reset(m_ptr);
}
private:
// External ====================================================================
extern (C)
{
typedef void* function() pf_sfClock_Create;
typedef void function(void*) pf_sfClock_Destroy;
typedef float function(void*) pf_sfClock_GetTime;
typedef void function(void*) pf_sfClock_Reset;
static pf_sfClock_Create sfClock_Create;
static pf_sfClock_Destroy sfClock_Destroy;
static pf_sfClock_GetTime sfClock_GetTime;
static pf_sfClock_Reset sfClock_Reset;
static this()
{
extern (C)
{
typedef void* function() pf_sfClock_Create;
typedef void function(void*) pf_sfClock_Destroy;
typedef float function(void*) pf_sfClock_GetTime;
typedef void function(void*) pf_sfClock_Reset;
static pf_sfClock_Create sfClock_Create;
static pf_sfClock_Destroy sfClock_Destroy;
static pf_sfClock_GetTime sfClock_GetTime;
static pf_sfClock_Reset sfClock_Reset;
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-system-d");
else
DllLoader dll = DllLoader.load("csfml-system");
sfClock_Create = cast(pf_sfClock_Create)dll.getSymbol("sfClock_Create");
sfClock_Destroy = cast(pf_sfClock_Destroy)dll.getSymbol("sfClock_Destroy");
sfClock_GetTime = cast(pf_sfClock_GetTime)dll.getSymbol("sfClock_GetTime");
sfClock_Reset = cast(pf_sfClock_Reset)dll.getSymbol("sfClock_Reset");
}
}
sfClock_Create = cast(pf_sfClock_Create)dll.getSymbol("sfClock_Create");
sfClock_Destroy = cast(pf_sfClock_Destroy)dll.getSymbol("sfClock_Destroy");
sfClock_GetTime = cast(pf_sfClock_GetTime)dll.getSymbol("sfClock_GetTime");
sfClock_Reset = cast(pf_sfClock_Reset)dll.getSymbol("sfClock_Reset");
}
}
}

View file

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.common;
@ -47,7 +47,7 @@ string loadFromSharedLib(string fname)
}
/**
* Base class for all DSFML classes.
* Base class for all DSFML classes.
*/
class DSFMLObject
{
@ -60,32 +60,32 @@ protected:
public:
this(void* ptr, bool preventDelete = false)
{
m_ptr = ptr;
}
~this()
{
if (!m_preventDelete)
dispose();
m_ptr = m_ptr.init;
}
abstract void dispose();
void* getNativePointer()
{
return m_ptr;
}
{
m_ptr = ptr;
}
~this()
{
if (!m_preventDelete)
dispose();
m_ptr = m_ptr.init;
}
abstract void dispose();
void* getNativePointer()
{
return m_ptr;
}
void setHandled(bool handled)
{
m_preventDelete = handled;
}
protected invariant()
{
assert(m_ptr !is null, "Problem occurs with a null pointer in " ~ this.toString);
}
void setHandled(bool handled)
{
m_preventDelete = handled;
}
protected invariant()
{
assert(m_ptr !is null, "Problem occurs with a null pointer in " ~ this.toString);
}
}

View file

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.dllloader;
@ -30,161 +30,161 @@ import dsfml.system.stringutil;
version (Tango)
{
import tango.io.Console;
import tango.sys.SharedLib;
import tango.io.Console;
import tango.sys.SharedLib;
}
else
{
import std.stdio;
version (Windows)
{
import std.c.windows.windows;
alias HMODULE MODULEHANDLE;
}
version (linux)
{
import std.c.linux.linux;
alias void* MODULEHANDLE;
const int RTLD_NOW = 0x00002;
const int RTLD_GLOBAL = 0x00100;
}
import std.stdio;
version (Windows)
{
import std.c.windows.windows;
alias HMODULE MODULEHANDLE;
}
version (linux)
{
import std.c.linux.linux;
alias void* MODULEHANDLE;
const int RTLD_NOW = 0x00002;
const int RTLD_GLOBAL = 0x00100;
}
}
static this()
{
version (Tango)
{
SharedLib.throwExceptions = false;
}
version (Tango)
{
SharedLib.throwExceptions = false;
}
}
private void report(string msg, string lib, string symb)
{
string str = "Loading error. Reason : " ~ msg ~ " (library : " ~ lib ~ ", symbol : " ~ symb ~ ")";
version (Tango)
{
Cerr(str).newline;
}
else
{
stderr.writeln(str);
}
string str = "Loading error. Reason : " ~ msg ~ " (library : " ~ lib ~ ", symbol : " ~ symb ~ ")";
version (Tango)
{
Cerr(str).newline;
}
else
{
stderr.writeln(str);
}
}
/**
* Simple Dll loader.
* Simple Dll loader.
*/
class DllLoader
{
static DllLoader load(string library)
{
version (Windows)
{
string libraryName = library ~ ".dll";
}
version (linux)
{
string libraryName = "lib" ~ library ~ ".so";
}
if (libraryName in alreadyLoaded)
{
return alreadyLoaded[libraryName];
}
else
{
DllLoader temp = new DllLoader(libraryName);
alreadyLoaded[libraryName] = temp;
return temp;
}
}
~this()
{
close();
}
static DllLoader load(string library)
{
version (Windows)
{
string libraryName = library ~ ".dll";
}
version (linux)
{
string libraryName = "lib" ~ library ~ ".so";
}
if (libraryName in alreadyLoaded)
{
return alreadyLoaded[libraryName];
}
else
{
DllLoader temp = new DllLoader(libraryName);
alreadyLoaded[libraryName] = temp;
return temp;
}
}
~this()
{
close();
}
void* getSymbol(string symbolName)
{
void* symb;
version (Tango)
{
symb = m_lib.getSymbol(toStringz(symbolName));
}
else
{
version (Windows)
{
symb = GetProcAddress(m_lib, toStringz(symbolName));
}
version (linux)
{
symb = dlsym(m_lib, toStringz(symbolName));
}
}
if (symb is null)
report( "Symbol cannot be found in specified library", m_libPath, symbolName);
return symb;
}
void* getSymbol(string symbolName)
{
void* symb;
version (Tango)
{
symb = m_lib.getSymbol(toStringz(symbolName));
}
else
{
version (Windows)
{
symb = GetProcAddress(m_lib, toStringz(symbolName));
}
version (linux)
{
symb = dlsym(m_lib, toStringz(symbolName));
}
}
if (symb is null)
report( "Symbol cannot be found in specified library", m_libPath, symbolName);
return symb;
}
void close()
{
version (Tango)
{
m_lib.unload();
}
else
{
version (Windows)
{
FreeLibrary(m_lib);
}
version (linux)
{
dlclose(m_lib);
}
alreadyLoaded.remove(this.m_libPath);
}
}
void close()
{
version (Tango)
{
m_lib.unload();
}
else
{
version (Windows)
{
FreeLibrary(m_lib);
}
version (linux)
{
dlclose(m_lib);
}
alreadyLoaded.remove(this.m_libPath);
}
}
private:
this(string libraryPath)
{
m_libPath = libraryPath;
version (Tango)
{
m_lib = SharedLib.load(libraryPath);
}
else
{
version (Windows)
{
m_lib = LoadLibraryA(toStringz(libraryPath));
}
version (linux)
{
m_lib = dlopen(toStringz(libraryPath), RTLD_NOW | RTLD_GLOBAL);
}
}
if (m_lib is null)
report("Cannot open library", m_libPath, null);
}
version (Tango)
{
SharedLib m_lib;
}
else
{
MODULEHANDLE m_lib;
}
static DllLoader[string] alreadyLoaded;
string m_libPath;
this(string libraryPath)
{
m_libPath = libraryPath;
version (Tango)
{
m_lib = SharedLib.load(libraryPath);
}
else
{
version (Windows)
{
m_lib = LoadLibraryA(toStringz(libraryPath));
}
version (linux)
{
m_lib = dlopen(toStringz(libraryPath), RTLD_NOW | RTLD_GLOBAL);
}
}
if (m_lib is null)
report("Cannot open library", m_libPath, null);
}
version (Tango)
{
SharedLib m_lib;
}
else
{
MODULEHANDLE m_lib;
}
static DllLoader[string] alreadyLoaded;
string m_libPath;
}

View file

@ -1,43 +1,43 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.exception;
class LoadingException : Exception
{
this(string msg)
{
super(msg);
}
this(string msg)
{
super(msg);
}
}
class NullParameterException : Exception
{
this(string msg)
{
super(msg);
}
this(string msg)
{
super(msg);
}
}

View file

@ -1,103 +1,103 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.linkedlist;
/*
* Trivial implementation of Queue linked list (for internal use)
* Trivial implementation of Queue linked list (for internal use)
*/
class LinkedList(T)
{
Node!(T) head;
Node!(T) tail;
private size_t m_count;
void enqueue(T object)
{
if (empty)
head = tail = new Node!(T)(object);
else
{
tail.Next = new Node!(T)(object);
tail = tail.Next;
}
m_count++;
}
T dequeue()
{
T o;
if (empty)
o = T.init;
else
{
o = head.Data;
head = head.Next;
m_count--;
}
return o;
}
bool empty()
{
return (head is null);
}
Node!(T) head;
Node!(T) tail;
private size_t m_count;
void enqueue(T object)
{
if (empty)
head = tail = new Node!(T)(object);
else
{
tail.Next = new Node!(T)(object);
tail = tail.Next;
}
m_count++;
}
T dequeue()
{
T o;
if (empty)
o = T.init;
else
{
o = head.Data;
head = head.Next;
m_count--;
}
return o;
}
bool empty()
{
return (head is null);
}
size_t getCount()
{
return m_count;
}
size_t getCount()
{
return m_count;
}
void clear()
{
T data;
while ((data = dequeue()) !is T.init) {}
}
void clear()
{
T data;
while ((data = dequeue()) !is T.init) {}
}
int opApply(int delegate(ref T) dg)
{
T data;
int result;
while ((data = dequeue) !is T.init)
{
if ((result = dg(data)) != 0)
break;
}
return result;
}
int opApply(int delegate(ref T) dg)
{
T data;
int result;
while ((data = dequeue) !is T.init)
{
if ((result = dg(data)) != 0)
break;
}
return result;
}
}
private class Node(T)
{
Node Next;
T Data;
this(T data)
{
Data = data;
}
Node Next;
T Data;
this(T data)
{
Data = data;
}
}

View file

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.lock;
@ -29,38 +29,38 @@ module dsfml.system.lock;
import dsfml.system.mutex;
/**
* Encapsulation of an critical section. Unlocking is guaranteed when the Lock goes out of scope, even on exception.
*
* Remarks:
* Lock is a scope class, you need to mark Lock object as scope :
*
* -----------------
* Mutex m = new Mutex;
* //..
* {
* scope Lock l = new Lock(m);
* // Critical section
* } // End of critical (Destructor called and mutex unlocked)
* //..
* Encapsulation of an critical section. Unlocking is guaranteed when the Lock goes out of scope, even on exception.
*
* Remarks:
* Lock is a scope class, you need to mark Lock object as scope :
*
* -----------------
* Mutex m = new Mutex;
* //..
* {
* scope Lock l = new Lock(m);
* // Critical section
* } // End of critical (Destructor called and mutex unlocked)
* //..
*
* -----------------
* -----------------
*/
scope class Lock
{
/**
* Construct the lock and lock the mutex
*/
this(Mutex m)
{
m_mutex = m;
m_mutex.lock();
}
~this()
{
m_mutex.unlock();
}
/**
* Construct the lock and lock the mutex
*/
this(Mutex m)
{
m_mutex = m;
m_mutex.lock();
}
~this()
{
m_mutex.unlock();
}
private:
Mutex m_mutex;
Mutex m_mutex;
}

View file

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.mutex;
@ -29,70 +29,70 @@ module dsfml.system.mutex;
import dsfml.system.common;
/**
* Provide portable implementation of Mutual Exclusion object.
*
* Uses CriticalSection on Windows and pthread mutexes on linux.
* Provide portable implementation of Mutual Exclusion object.
*
* Uses CriticalSection on Windows and pthread mutexes on linux.
*/
final class Mutex : DSFMLObject
{
/**
* Constructor
*/
this()
{
super(sfMutex_Create());
}
/**
* Constructor
*/
this()
{
super(sfMutex_Create());
}
override void dispose()
{
sfMutex_Destroy(m_ptr);
}
override void dispose()
{
sfMutex_Destroy(m_ptr);
}
/**
* Lock the mutex
*
* Can be called multiples times, but each lock must be unlocked with unlock()
*/
void lock()
{
sfMutex_Lock(m_ptr);
}
/**
* Unlock the mutex
*/
void unlock()
{
sfMutex_Unlock(m_ptr);
}
/**
* Lock the mutex
*
* Can be called multiples times, but each lock must be unlocked with unlock()
*/
void lock()
{
sfMutex_Lock(m_ptr);
}
/**
* Unlock the mutex
*/
void unlock()
{
sfMutex_Unlock(m_ptr);
}
private:
// External ====================================================================
extern (C)
{
typedef void* function() pf_sfMutex_Create;
typedef void function(void*) pf_sfMutex_Destroy;
typedef void function(void*) pf_sfMutex_Lock;
typedef void function(void*) pf_sfMutex_Unlock;
static pf_sfMutex_Create sfMutex_Create;
static pf_sfMutex_Destroy sfMutex_Destroy;
static pf_sfMutex_Lock sfMutex_Lock;
static pf_sfMutex_Unlock sfMutex_Unlock;
}
extern (C)
{
typedef void* function() pf_sfMutex_Create;
typedef void function(void*) pf_sfMutex_Destroy;
typedef void function(void*) pf_sfMutex_Lock;
typedef void function(void*) pf_sfMutex_Unlock;
static pf_sfMutex_Create sfMutex_Create;
static pf_sfMutex_Destroy sfMutex_Destroy;
static pf_sfMutex_Lock sfMutex_Lock;
static pf_sfMutex_Unlock sfMutex_Unlock;
}
static this()
{
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-system-d");
else
DllLoader dll = DllLoader.load("csfml-system");
sfMutex_Create = cast(pf_sfMutex_Create)dll.getSymbol("sfMutex_Create");
sfMutex_Destroy = cast(pf_sfMutex_Destroy)dll.getSymbol("sfMutex_Destroy");
sfMutex_Lock = cast(pf_sfMutex_Lock)dll.getSymbol("sfMutex_Lock");
sfMutex_Unlock = cast(pf_sfMutex_Unlock)dll.getSymbol("sfMutex_Unlock");
}
sfMutex_Create = cast(pf_sfMutex_Create)dll.getSymbol("sfMutex_Create");
sfMutex_Destroy = cast(pf_sfMutex_Destroy)dll.getSymbol("sfMutex_Destroy");
sfMutex_Lock = cast(pf_sfMutex_Lock)dll.getSymbol("sfMutex_Lock");
sfMutex_Unlock = cast(pf_sfMutex_Unlock)dll.getSymbol("sfMutex_Unlock");
}
}

View file

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.randomizer;
@ -29,64 +29,64 @@ module dsfml.system.randomizer;
import dsfml.system.common;
/**
* Randomizer is an utility class for generating pseudo-random
* numbers
*
* Examples:
* -----------------------------------------------------------
* int randI = Randomizer.Random(1, 100);
* float randF = Randomizer.Random(1.0, 10.0)
* -----------------------------------------------------------
* Randomizer is an utility class for generating pseudo-random
* numbers
*
* Examples:
* -----------------------------------------------------------
* int randI = Randomizer.Random(1, 100);
* float randF = Randomizer.Random(1.0, 10.0)
* -----------------------------------------------------------
*/
class Randomizer
{
/**
* Set the seed for the generator. Using a known seed
* allows you to reproduce the same sequence of random number
*
* Params:
* seed = Number to use as the seed
*
*/
/**
* Set the seed for the generator. Using a known seed
* allows you to reproduce the same sequence of random number
*
* Params:
* seed = Number to use as the seed
*
*/
static void setSeed(uint seed)
{
sfRandom_SetSeed(seed);
}
/**
* Get the seed used to generate random numbers the generator.
*
* Returns:
* Current seed
*/
/**
* Get the seed used to generate random numbers the generator.
*
* Returns:
* Current seed
*/
static uint getSeed()
{
return sfRandom_GetSeed();
}
/**
* Get a random float number in a given range
*
* Params:
* begin = Start of the range
* end = End of the range
* Returns:
* Random number in [Begin, End]
*/
/**
* Get a random float number in a given range
*
* Params:
* begin = Start of the range
* end = End of the range
* Returns:
* Random number in [Begin, End]
*/
static float random(float begin, float end)
{
return sfRandom_Float(begin, end);
}
/**
* Get a random integral number in a given range
*
* Params:
* begin = Start of the range
* end = End of the range
* Returns:
* Random number in [Begin, End]
*/
/**
* Get a random integral number in a given range
*
* Params:
* begin = Start of the range
* end = End of the range
* Returns:
* Random number in [Begin, End]
*/
static int random(int begin, int end)
{
return sfRandom_Int(begin, end);
@ -95,40 +95,40 @@ class Randomizer
private:
/*
* Prevent instanciation
*/
this()
{
}
/*
* Prevent instanciation
*/
this()
{
}
// External ====================================================================
extern (C)
{
typedef void function(uint) pf_sfRandom_SetSeed;
typedef uint function() pf_sfRandom_GetSeed;
typedef float function(float, float) pf_sfRandom_Float;
typedef int function(int, int) pf_sfRandom_Int;
static pf_sfRandom_SetSeed sfRandom_SetSeed;
static pf_sfRandom_GetSeed sfRandom_GetSeed;
static pf_sfRandom_Float sfRandom_Float;
static pf_sfRandom_Int sfRandom_Int;
}
extern (C)
{
typedef void function(uint) pf_sfRandom_SetSeed;
typedef uint function() pf_sfRandom_GetSeed;
typedef float function(float, float) pf_sfRandom_Float;
typedef int function(int, int) pf_sfRandom_Int;
static pf_sfRandom_SetSeed sfRandom_SetSeed;
static pf_sfRandom_GetSeed sfRandom_GetSeed;
static pf_sfRandom_Float sfRandom_Float;
static pf_sfRandom_Int sfRandom_Int;
}
static this()
{
static this()
{
debug
DllLoader dll = DllLoader.load("csfml-system-d");
else
DllLoader dll = DllLoader.load("csfml-system");
sfRandom_SetSeed = cast(pf_sfRandom_SetSeed)dll.getSymbol("sfRandom_SetSeed");
sfRandom_GetSeed = cast(pf_sfRandom_GetSeed)dll.getSymbol("sfRandom_GetSeed");
sfRandom_Float = cast(pf_sfRandom_Float)dll.getSymbol("sfRandom_Float");
sfRandom_Int = cast(pf_sfRandom_Int)dll.getSymbol("sfRandom_Int");
}
sfRandom_SetSeed = cast(pf_sfRandom_SetSeed)dll.getSymbol("sfRandom_SetSeed");
sfRandom_GetSeed = cast(pf_sfRandom_GetSeed)dll.getSymbol("sfRandom_GetSeed");
sfRandom_Float = cast(pf_sfRandom_Float)dll.getSymbol("sfRandom_Float");
sfRandom_Int = cast(pf_sfRandom_Int)dll.getSymbol("sfRandom_Int");
}
}

View file

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.sleep;
@ -42,17 +42,17 @@ static this()
else
DllLoader dll = DllLoader.load("csfml-system");
sfSleep = cast(pf_sfSleep)dll.getSymbol("sfSleep");
sfSleep = cast(pf_sfSleep)dll.getSymbol("sfSleep");
}
/**
* Make the current thread sleep for a given time
* Make the current thread sleep for a given time
*
* Params:
* duration = Time to sleep, in seconds
* Params:
* duration = Time to sleep, in seconds
*/
void sleep(float duration)
{
sfSleep(duration);
sfSleep(duration);
}

View file

@ -1,27 +1,27 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.stringutil;
@ -40,43 +40,43 @@ else
*/
T* toStringz(T)(T[] str)
{
if (str is null)
return null;
else if (str.length && str[$ - 1] is T.init)
return str.ptr;
T* toStringz(T)(T[] str)
{
if (str is null)
return null;
else if (str.length && str[$ - 1] is T.init)
return str.ptr;
auto ret = new Unqual!(T)[str.length + 1];
ret[0 .. str.length] = str[0 .. $];
ret[str.length] = 0;
return cast(T*) ret.ptr;
}
auto ret = new Unqual!(T)[str.length + 1];
ret[0 .. str.length] = str[0 .. $];
ret[str.length] = 0;
return cast(T*) ret.ptr;
}
size_t stringLength(T)(T* p)
{
if (p is null || *p == T.init)
return 0;
size_t length;
while (*(p + length))
{
length++;
}
return length;
}
size_t stringLength(T)(T* p)
{
if (p is null || *p == T.init)
return 0;
size_t length;
while (*(p + length))
{
length++;
}
return length;
}
T[] fromStringz(T)(T* ptr)
{
auto ret = new Unqual!(T)[stringLength(ptr)];
ret[0..$] = ptr[0..ret.length];
return cast(T[]) ret;
}
T[] fromStringz(T)(T* ptr)
{
auto ret = new Unqual!(T)[stringLength(ptr)];
ret[0..$] = ptr[0..ret.length];
return cast(T[]) ret;
}

View file

@ -1,158 +1,158 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.vector2;
/**
* Vector2 is an utility class for manipulating 2 dimensional
* vectors. Template parameter defines the type of coordinates
* (integer, float, ...)
* Vector2 is an utility class for manipulating 2 dimensional
* vectors. Template parameter defines the type of coordinates
* (integer, float, ...)
*/
struct Vector2(T)
{
T x;
T y;
T x;
T y;
static Vector2 opCall(T x, T y)
{
Vector2!(T) ret;
ret.x = x;
ret.y = y;
return ret;
}
static Vector2 opCall(T x, T y)
{
Vector2!(T) ret;
ret.x = x;
ret.y = y;
return ret;
}
/// unary (-) overload
Vector2 opNeg()
{
return Vector2!(T)(-x, -y);
}
/// unary (-) overload
Vector2 opNeg()
{
return Vector2!(T)(-x, -y);
}
/// (+=) overload
Vector2 opAddAssign(Vector2 other)
{
x += other.x;
y += other.y;
return this;
}
/// (+=) overload
Vector2 opAddAssign(Vector2 other)
{
x += other.x;
y += other.y;
return this;
}
/// (-=) overload
Vector2 opSubAssign(Vector2 other)
{
x -= other.x;
y -= other.y;
return this;
}
/// (-=) overload
Vector2 opSubAssign(Vector2 other)
{
x -= other.x;
y -= other.y;
return this;
}
/// (+) overload
Vector2 opAdd(Vector2 other)
{
return Vector2!(T)( (x + other.x), (y + other.y) );
}
/// (+) overload
Vector2 opAdd(Vector2 other)
{
return Vector2!(T)( (x + other.x), (y + other.y) );
}
/// (-) overload
Vector2 opSub(Vector2 other)
{
return Vector2!(T) ( (x - other.x), (y - other.y) );
}
/// (*) overload
Vector2 opMul(int i)
{
return Vector2!(T) ( (x * i), (y * i) );
}
/// (-) overload
Vector2 opSub(Vector2 other)
{
return Vector2!(T) ( (x - other.x), (y - other.y) );
}
/// (*) overload
Vector2 opMul(int i)
{
return Vector2!(T) ( (x * i), (y * i) );
}
/// (*=) overload
Vector2 opMulAssign(int i)
{
x *= i;
y *= i;
return this;
}
/// (*=) overload
Vector2 opMulAssign(int i)
{
x *= i;
y *= i;
return this;
}
/// (/) overload
Vector2 opDiv(int i)
{
return Vector2!(T) ( (x / i), (y / i));
}
/// (/) overload
Vector2 opDiv(int i)
{
return Vector2!(T) ( (x / i), (y / i));
}
/// (/=) overload
Vector2 opDivAssign(int i)
{
x /= i;
y /= i;
return this;
}
/// (/=) overload
Vector2 opDivAssign(int i)
{
x /= i;
y /= i;
return this;
}
///
const bool opEquals(ref const(Vector2) other)
{
return (x == other.x) && (y == other.y);
}
///
const bool opEquals(ref const(Vector2) other)
{
return (x == other.x) && (y == other.y);
}
}
version (UnitTest)
{
unittest
{
Vector2f main = Vector2f(10f, 10f);
Vector2f other = Vector2f(10f, 10f);
Vector2f result;
result = -main;
assert (result == Vector2f(-10.f, -10.f) );
result = main;
result += other;
assert (result == Vector2f(20.f, 20.f));
result = main;
result -= other;
assert (result == Vector2f(0.f, 0.f));
result = main + other;
assert (result == Vector2f(20.f, 20.f));
result = main - other;
assert (result == Vector2f(0.f, 0.f));
result = main * 10;
assert (result == Vector2f(100.f, 100.f));
result *= 2;
assert (result == Vector2f(200.f, 200.f));
result = main / 2;
assert (result == Vector2f(5.f, 5.f));
result = main;
result /= 2;
assert (result == Vector2f(5.f, 5.f));
}
unittest
{
Vector2f main = Vector2f(10f, 10f);
Vector2f other = Vector2f(10f, 10f);
Vector2f result;
result = -main;
assert (result == Vector2f(-10.f, -10.f) );
result = main;
result += other;
assert (result == Vector2f(20.f, 20.f));
result = main;
result -= other;
assert (result == Vector2f(0.f, 0.f));
result = main + other;
assert (result == Vector2f(20.f, 20.f));
result = main - other;
assert (result == Vector2f(0.f, 0.f));
result = main * 10;
assert (result == Vector2f(100.f, 100.f));
result *= 2;
assert (result == Vector2f(200.f, 200.f));
result = main / 2;
assert (result == Vector2f(5.f, 5.f));
result = main;
result /= 2;
assert (result == Vector2f(5.f, 5.f));
}
}
/// Aliases

View file

@ -1,164 +1,164 @@
/*
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
* DSFML - SFML Library wrapper for the D programming language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
* Copyright (C) 2010 Andreas Hollandt
*
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
* This software is provided 'as-is', without any express or
* implied warranty. In no event will the authors be held
* liable for any damages arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
* 1. The origin of this software must not be misrepresented;
* you must not claim that you wrote the original software.
* If you use this software in a product, an acknowledgment
* in the product documentation would be appreciated but
* is not required.
*
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
* 2. Altered source versions must be plainly marked as such,
* and must not be misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any
* source distribution.
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.vector3;
/**
* Vector3 is an utility class for manipulating 3 dimensional
* vectors. Template parameter defines the type of coordinates
* (integer, float, ...)
* Vector3 is an utility class for manipulating 3 dimensional
* vectors. Template parameter defines the type of coordinates
* (integer, float, ...)
*/
struct Vector3(T)
{
T x;
T y;
T z;
T x;
T y;
T z;
static Vector3 opCall(T x, T y, T z)
{
Vector3!(T) ret;
ret.x = x;
ret.y = y;
ret.z = z;
return ret;
}
static Vector3 opCall(T x, T y, T z)
{
Vector3!(T) ret;
ret.x = x;
ret.y = y;
ret.z = z;
return ret;
}
/// unary (-) overload
Vector3 opNeg()
{
return Vector3!(T)(-x, -y, -z);
}
/// unary (-) overload
Vector3 opNeg()
{
return Vector3!(T)(-x, -y, -z);
}
/// (+=) overload
Vector3 opAddAssign(Vector3 other)
{
x += other.x;
y += other.y;
z += other.z;
return this;
}
/// (+=) overload
Vector3 opAddAssign(Vector3 other)
{
x += other.x;
y += other.y;
z += other.z;
return this;
}
/// (-=) overload
Vector3 opSubAssign(Vector3 other)
{
x -= other.x;
y -= other.y;
z -= other.z;
return this;
}
/// (-=) overload
Vector3 opSubAssign(Vector3 other)
{
x -= other.x;
y -= other.y;
z -= other.z;
return this;
}
/// (+) overload
Vector3 opAdd(Vector3 other)
{
return Vector3!(T)( (x + other.x), (y + other.y), (z + other.z) );
}
/// (+) overload
Vector3 opAdd(Vector3 other)
{
return Vector3!(T)( (x + other.x), (y + other.y), (z + other.z) );
}
/// (-) overload
Vector3 opSub(Vector3 other)
{
return Vector3!(T) ( (x - other.x), (y - other.y), (z - other.z) );
}
/// (-) overload
Vector3 opSub(Vector3 other)
{
return Vector3!(T) ( (x - other.x), (y - other.y), (z - other.z) );
}
/// (*) overload
Vector3 opMul(int i)
{
return Vector3!(T) ( (x * i), (y * i), (z * i) );
}
/// (*) overload
Vector3 opMul(int i)
{
return Vector3!(T) ( (x * i), (y * i), (z * i) );
}
/// (*=) overload
Vector3 opMulAssign(int i)
{
x *= i;
y *= i;
z *= i;
return this;
}
/// (*=) overload
Vector3 opMulAssign(int i)
{
x *= i;
y *= i;
z *= i;
return this;
}
/// (/) overload
Vector3 opDiv(int i)
{
return Vector3!(T) ( (x / i), (y / i), (z / i) );
}
/// (/) overload
Vector3 opDiv(int i)
{
return Vector3!(T) ( (x / i), (y / i), (z / i) );
}
/// (/=) overload
Vector3 opDivAssign(int i)
{
x /= i;
y /= i;
z /= i;
return this;
}
/// (/=) overload
Vector3 opDivAssign(int i)
{
x /= i;
y /= i;
z /= i;
return this;
}
///
const bool opEquals(ref const(Vector3) other)
{
return (x == other.x) && (y == other.y) && (z == other.z) ;
}
///
const bool opEquals(ref const(Vector3) other)
{
return (x == other.x) && (y == other.y) && (z == other.z) ;
}
}
version (UnitTest)
{
unittest
{
Vector3f main = Vector3f(10f, 10f, 10.f);
Vector3f other = Vector3f(10f, 10f, 10.f);
Vector3f result;
result = -main;
assert (result == Vector3f(-10.f, -10.f, -10.f) );
result = main;
result += other;
assert (result == Vector3f(20.f, 20.f, 20.f));
result = main;
result -= other;
assert (result == Vector3f(0.f, 0.f, 0.f));
result = main + other;
assert (result == Vector3f(20.f, 20.f, 20.f));
result = main - other;
assert (result == Vector3f(0.f, 0.f, 0.f));
result = main * 10;
assert (result == Vector3f(100.f, 100.f, 100.f));
result *= 2;
assert (result == Vector3f(200.f, 200.f, 200.f));
result = main / 2;
assert (result == Vector3f(5.f, 5.f, 5.f));
result = main;
result /= 2;
assert (result == Vector3f(5.f, 5.f, 5.f));
}
unittest
{
Vector3f main = Vector3f(10f, 10f, 10.f);
Vector3f other = Vector3f(10f, 10f, 10.f);
Vector3f result;
result = -main;
assert (result == Vector3f(-10.f, -10.f, -10.f) );
result = main;
result += other;
assert (result == Vector3f(20.f, 20.f, 20.f));
result = main;
result -= other;
assert (result == Vector3f(0.f, 0.f, 0.f));
result = main + other;
assert (result == Vector3f(20.f, 20.f, 20.f));
result = main - other;
assert (result == Vector3f(0.f, 0.f, 0.f));
result = main * 10;
assert (result == Vector3f(100.f, 100.f, 100.f));
result *= 2;
assert (result == Vector3f(200.f, 200.f, 200.f));
result = main / 2;
assert (result == Vector3f(5.f, 5.f, 5.f));
result = main;
result /= 2;
assert (result == Vector3f(5.f, 5.f, 5.f));
}
}
/// Aliases