Added the trunk/branches/tags directories at repository root, and moved previous root into trunk/

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1002 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
laurentgom 2009-01-28 16:18:34 +00:00
commit 2f524481c1
974 changed files with 295448 additions and 0 deletions

View file

@ -0,0 +1,45 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 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)
}
}
public import
dsfml.system.clock,
dsfml.system.lock,
dsfml.system.mutex,
dsfml.system.randomizer,
dsfml.system.sleep,
dsfml.system.thread,
dsfml.system.vector2,
dsfml.system.vector3;

View file

@ -0,0 +1,81 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.alloc;
version (Tango)
{
public import tango.core.Memory;
}
else
{
import std.c.stdlib;
import std.gc;
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 Alloc()
{
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);
}
}

View file

@ -0,0 +1,97 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.clock;
import dsfml.system.common;
/**
* Utility class for manipulating time
*/
class Clock : DSFMLObject
{
/**
* Default constructor
*/
this()
{
super(sfClock_Create());
}
/**
* 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);
}
/**
* 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()
{
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");
}
}
}

View file

@ -0,0 +1,70 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.common;
public import dsfml.system.dllloader;
/**
* Base class for all DSFML classes.
*/
class DSFMLObject
{
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;
}
void setHandled(bool handled)
{
m_preventDelete = handled;
}
protected invariant()
{
assert(m_ptr !is null, "Problem occurs with a null pointer in " ~ this.toString);
}
protected:
void* m_ptr;
private:
bool m_preventDelete;
}

View file

@ -0,0 +1,189 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.dllloader;
import dsfml.system.stringutil;
version (Tango)
{
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;
}
}
static this()
{
version (Tango)
{
SharedLib.throwExceptions = false;
}
}
private void report(char[] msg, char[] lib, char[] symb)
{
char[] str = "Loading error. Reason : " ~ msg ~ " (library : " ~ lib ~ ", symbol : " ~ symb ~ ")";
version (Tango)
{
Cerr(str).newline;
}
else
{
fwritefln(stderr, str);
}
}
/**
* Simple Dll loader.
*/
class DllLoader
{
static DllLoader load(char[] library)
{
version (Windows)
{
char[] libraryName = library ~ ".dll";
}
version (linux)
{
char[] 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(char[] 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);
}
}
private:
this(char[] 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[char[]] alreadyLoaded;
char[] m_libPath;
}

View file

@ -0,0 +1,42 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.exception;
class LoadingException : Exception
{
this(char[] msg)
{
super(msg);
}
}
class NullParameterException : Exception
{
this(char[] msg)
{
super(msg);
}
}

View file

@ -0,0 +1,102 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 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)
*/
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);
}
size_t getCount()
{
return m_count;
}
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;
}
}
private class Node(T)
{
Node Next;
T Data;
this(T data)
{
Data = data;
}
}

View file

@ -0,0 +1,65 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
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)
* //..
*
* -----------------
*/
scope class Lock
{
/**
* Construct the lock and lock the mutex
*/
this(Mutex m)
{
m_mutex = m;
m_mutex.lock();
}
~this()
{
m_mutex.unlock();
}
private:
Mutex m_mutex;
}

View file

@ -0,0 +1,94 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.mutex;
import dsfml.system.common;
/**
* 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());
}
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);
}
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;
}
static this()
{
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");
}
}

View file

@ -0,0 +1,130 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
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)
* -----------------------------------------------------------
*/
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
*
*/
static void setSeed(uint seed)
{
sfRandom_SetSeed(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]
*/
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]
*/
static int random(int begin, int end)
{
return sfRandom_Int(begin, end);
}
private:
/*
* 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;
}
static this()
{
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");
}
}

View file

@ -0,0 +1,53 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.sleep;
import dsfml.system.common;
extern(C)
{
typedef void function(float) pf_sfSleep;
private static pf_sfSleep sfSleep;
}
static this()
{
DllLoader dll = DllLoader.load("csfml-system");
sfSleep = cast(pf_sfSleep)dll.getSymbol("sfSleep");
}
/**
* Make the current thread sleep for a given time
*
* Params:
* duration = Time to sleep, in seconds
*/
void sleep(float duration)
{
sfSleep(duration);
}

View file

@ -0,0 +1,169 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.stringutil;
// version (Tango)
// {
// public import tango.stdc.stringz;
// }
// 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[] ret = new T[str.length + 1];
ret[0 .. str.length] = str[0 .. $];
ret[str.length] = 0;
return 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;
}
T[] fromStringz(T)(T* ptr)
{
T[] ret = new T[stringLength(ptr)];
ret[0..$] = ptr[0..ret.length];
return ret;
}
// /*
// * Tango equivalent functions
// *
// * Author : Keinfarbton
// * Licence : BSD style
// */
// char* toStringz(char[] s)
// {
// if (s.ptr)
// if (!(s.length && s[$-1] is 0))
// s = s ~ '\0';
// return s.ptr;
// }
//
// char[] fromStringz (char* s)
// {
// size_t i;
//
// if (s)
// while (*(s+i))
// ++i;
//
// return s ? s[0 .. i] : null;
// }
//
// wchar* toString16z(wchar[] s)
// {
// if (s.ptr)
// if (!(s.length && s[$-1] is 0))
// s = s ~ '\0';
// return s.ptr;
// }
//
// wchar[] fromString16z (wchar* s)
// {
// size_t i;
//
// if (s)
// while (*(s+i))
// ++i;
//
// return s ? s[0 .. i] : null;
// }
//
// dchar* toString32z (dchar[] s)
// {
// if (s.ptr)
// if (!(s.length && s[$-1] is 0))
// s = s ~ "\0"d;
// return s.ptr;
// }
//
//
// dchar[] fromString32z (dchar* s)
// {
// size_t i;
//
// if (s)
// while (*(s+i))
// ++i;
//
// return s ? s[0 .. i] : null;
// }
// }
version (UnitTest)
{
void main()
{
}
unittest
{
char[] str = "Test";
char[] espaceStr = "string with espace";
dchar[] strW = "Test"d;
dchar[] espaceStrW = "string with espace"d;
char[] empty = "";
dchar[] emptyW = ""d;
char[] nullStr = null;
dchar[] nullStrW = null;
assert(fromStringz(toStringz(str)) == str);
assert(fromStringz(toStringz(espaceStr)) == espaceStr);
assert(fromStringz(toStringz(strW)) == strW);
assert(fromStringz(toStringz(espaceStrW)) == espaceStrW);
assert(fromStringz(toStringz(empty)) == empty);
assert(fromStringz(toStringz(emptyW)) == emptyW);
assert(fromStringz(toStringz(nullStr)) == nullStr);
assert(fromStringz(toStringz(nullStrW)) == nullStrW);
}
}

View file

@ -0,0 +1,216 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 3. This notice may not be removed or altered from any
* source distribution.
*/
module dsfml.system.thread;
version(Tango)
{
static import tango.core.Thread;
alias tango.core.Thread.Thread DThread;
}
else
{
static import std.thread;
alias std.thread.Thread DThread;
}
/**
* Thread defines a simple thread abstraction.
*
* Examples:
* Can be a base class (you need to override void run(void) method) :
* --------------------
* class MyThread : Thread
* {
* void function()
* {
* this.launch();
* }
*
* //Thread entry point
* protected void run()
* {
* }
* }
* --------------------
*
* or
*
* --------------------
* void main()
* {
* Thread t = new Thread(&threadStart);
* t.launch();
* t.wait(); //Wait the end of t thread
* }
*
* //Thread entry point
* void threadStart (void* userData)
* {
*
* }
* --------------------
*
* or
*
* --------------------
* void main()
* {
* MyObject foo = new MyObject();
* Thread t = new Thread(&foo.bar);
* t.launch();
* t.wait(); //Wait the end of t thread
* }
*
* class MyObject
* {
* void bar(void* user)
* {
* //...
* }
* }
* --------------------
*/
class Thread
{
/**
* Construct the thread from a function pointer.
*
* Params:
* func = Entry point of the thread
* userData = Data to pass to the thread function (NULL by default)
*
*/
this(void function(void*) func, void* userData = null)
{
m_t = new DThread(&threadStart);
m_func = func;
m_userData = userData;
}
/**
* Construct the thread from a delegate.
*
* Params:
* dg = Entry point of the thread
* userData = Data to pass to the thread function (NULL by default)
*
*/
this(void delegate(void*) dg, void* userData = null)
{
m_t = new DThread(&threadStart);
m_dg = dg;
m_userData = userData;
m_isDelegate = true;
}
/**
* Run the thread
*/
final void launch()
{
if (!m_running)
{
m_t.start();
m_running = true;
}
}
/**
* Wait until the thread finishes
*/
final void wait()
{
if(m_running)
{
version (Tango)
{
m_t.join();
}
else
{
m_t.wait();
}
}
}
protected:
/**
* Protected constructor
*/
this()
{
m_t = new DThread(&threadStart);
}
/**
* Override this method in class derived from Thread.
*/
void run()
{
if (m_isDelegate)
this.m_dg(this.m_userData);
else
this.m_func(this.m_userData);
}
private:
DThread m_t;
bool m_isDelegate;
bool m_running;
union
{
void function(void*) m_func;
void delegate(void*) m_dg;
}
void* m_userData;
/*
* Thread entry point
*/
version (Tango)
{
final void threadStart()
{
run();
m_running = false;
}
}
else
{
final int threadStart()
{
run();
m_running = false;
return 0;
}
}
}

View file

@ -0,0 +1,160 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 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, ...)
*/
struct Vector2(T)
{
T x;
T y;
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);
}
/// (+=) 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 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 opMulAssign(int i)
{
x *= i;
y *= i;
return *this;
}
/// (/) overload
Vector2 opDiv(int i)
{
return Vector2!(T) ( (x / i), (y / i));
}
/// (/=) overload
Vector2 opDivAssign(int i)
{
x /= i;
y /= i;
return *this;
}
///
int opEquals(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));
}
}
/// Aliases
alias Vector2!(float) Vector2f;
/// ditto
alias Vector2!(int) Vector2i;

View file

@ -0,0 +1,166 @@
/*
* DSFML - SFML Library binding in D language.
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
*
* 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:
*
* 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.
*
* 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, ...)
*/
struct Vector3(T)
{
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;
}
/// 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 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 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 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 opDivAssign(int i)
{
x /= i;
y /= i;
z /= i;
return *this;
}
///
int opEquals(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));
}
}
/// Aliases
alias Vector3!(float) Vector3f;
/// ditto
alias Vector3!(int) Vector3i;