2009-01-29 00:18:34 +08:00
|
|
|
/*
|
2010-01-07 04:37:29 +08:00
|
|
|
* DSFML - SFML Library wrapper for the D programming language.
|
|
|
|
* Copyright (C) 2008 Julien Dagorn (sirjulio13@gmail.com)
|
|
|
|
* Copyright (C) 2010 Andreas Hollandt
|
2009-01-29 00:18:34 +08:00
|
|
|
*
|
2010-01-07 04:37:29 +08:00
|
|
|
* 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.
|
2009-01-29 00:18:34 +08:00
|
|
|
*
|
2010-01-07 04:37:29 +08:00
|
|
|
* 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:
|
2009-01-29 00:18:34 +08:00
|
|
|
*
|
2010-01-07 04:37:29 +08:00
|
|
|
* 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.
|
2009-01-29 00:18:34 +08:00
|
|
|
*
|
2010-01-07 04:37:29 +08:00
|
|
|
* 2. Altered source versions must be plainly marked as such,
|
|
|
|
* and must not be misrepresented as being the original software.
|
2009-01-29 00:18:34 +08:00
|
|
|
*
|
2010-01-07 04:37:29 +08:00
|
|
|
* 3. This notice may not be removed or altered from any
|
|
|
|
* source distribution.
|
2009-01-29 00:18:34 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
module dsfml.system.common;
|
|
|
|
|
|
|
|
public import dsfml.system.dllloader;
|
|
|
|
|
2010-01-07 04:25:45 +08:00
|
|
|
// type aliases for D2
|
|
|
|
package
|
|
|
|
{
|
|
|
|
alias const(char) cchar;
|
|
|
|
alias const(wchar) cwchar;
|
|
|
|
alias const(dchar) cdchar;
|
|
|
|
alias immutable(char) ichar;
|
|
|
|
alias immutable(wchar) iwchar;
|
|
|
|
alias immutable(dchar) idchar;
|
|
|
|
alias const(char)[] cstring;
|
2010-03-16 07:35:53 +08:00
|
|
|
|
|
|
|
// alias immutable(void) ivoid;
|
|
|
|
alias const(void) cvoid;
|
2010-04-21 01:35:30 +08:00
|
|
|
typedef immutable(void)* SFMLClass;
|
2010-01-07 04:25:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// used to mixin code function
|
|
|
|
string loadFromSharedLib(string fname)
|
|
|
|
{
|
|
|
|
return fname ~ " = " ~ "cast(typeof(" ~ fname ~ ")) dll.getSymbol(\"" ~ fname ~ "\");";
|
|
|
|
}
|
|
|
|
|
2010-01-13 03:56:38 +08:00
|
|
|
//used to mixin code function
|
2010-03-13 09:56:39 +08:00
|
|
|
string loadFromSharedLib2(S...)(string lib, string className, S fnames)
|
2010-01-13 03:56:38 +08:00
|
|
|
{
|
|
|
|
string res = `static this()
|
|
|
|
{
|
|
|
|
debug
|
2011-01-31 02:09:15 +08:00
|
|
|
DllLoader dll = DllLoader.load("` ~ lib ~ `-d-2");
|
2010-01-13 03:56:38 +08:00
|
|
|
else
|
2011-01-31 02:09:15 +08:00
|
|
|
DllLoader dll = DllLoader.load("` ~ lib ~ `-2");
|
2010-01-13 03:56:38 +08:00
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
foreach(fname; fnames)
|
|
|
|
{
|
2010-03-13 09:56:39 +08:00
|
|
|
res ~= "\t" ~ className ~ "_" ~ fname ~ " = " ~ "cast(typeof(" ~ className ~ "_" ~ fname ~ ")) dll.getSymbol(\"" ~ className ~ "_" ~ fname ~ "\");\n";
|
2010-01-13 03:56:38 +08:00
|
|
|
}
|
|
|
|
return res ~ "}\n";
|
|
|
|
}
|
|
|
|
|
2010-03-13 09:56:39 +08:00
|
|
|
string loadDerivedFromSharedLib(S...)(string lib, string baseClass, string derivedClass, S fnames)
|
2010-01-13 03:56:38 +08:00
|
|
|
{
|
2010-03-13 09:56:39 +08:00
|
|
|
string res = `static this()
|
|
|
|
{
|
|
|
|
debug
|
2011-01-31 02:09:15 +08:00
|
|
|
DllLoader dll = DllLoader.load("` ~ lib ~ `-d-2");
|
2010-03-13 09:56:39 +08:00
|
|
|
else
|
2011-01-31 02:09:15 +08:00
|
|
|
DllLoader dll = DllLoader.load("` ~ lib ~ `-2");
|
2010-03-13 09:56:39 +08:00
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
foreach(fname; fnames)
|
|
|
|
{
|
2010-03-16 07:35:53 +08:00
|
|
|
res ~= "\t" ~ baseClass ~ "_" ~ fname ~ " = " ~ "cast(typeof(" ~ baseClass ~ "_" ~ fname ~ ")) dll.getSymbol(\"" ~ derivedClass ~ "_" ~ fname ~ "\");\n";
|
2010-03-13 09:56:39 +08:00
|
|
|
}
|
|
|
|
return res ~ "}\n";
|
2010-01-13 03:56:38 +08:00
|
|
|
}
|
|
|
|
|
2009-01-29 00:18:34 +08:00
|
|
|
/**
|
2010-03-16 07:35:53 +08:00
|
|
|
* Base class for all DSFML classes.
|
|
|
|
*/
|
2009-01-29 00:18:34 +08:00
|
|
|
class DSFMLObject
|
|
|
|
{
|
2010-01-07 04:25:45 +08:00
|
|
|
private:
|
|
|
|
bool m_preventDelete;
|
|
|
|
|
|
|
|
protected:
|
2010-03-16 07:35:53 +08:00
|
|
|
SFMLClass m_ptr;
|
|
|
|
|
|
|
|
abstract void dispose();
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// get the underlying C pointer
|
|
|
|
@property final SFMLClass nativePointer()
|
|
|
|
{
|
|
|
|
return m_ptr;
|
|
|
|
}
|
2010-01-07 04:25:45 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2010-03-16 07:35:53 +08:00
|
|
|
this(SFMLClass ptr, bool preventDelete = false)
|
2010-01-07 04:37:29 +08:00
|
|
|
{
|
|
|
|
m_ptr = ptr;
|
2010-01-08 02:07:22 +08:00
|
|
|
m_preventDelete = preventDelete;
|
2010-01-07 04:37:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
~this()
|
|
|
|
{
|
|
|
|
if (!m_preventDelete)
|
|
|
|
dispose();
|
|
|
|
|
|
|
|
m_ptr = m_ptr.init;
|
|
|
|
}
|
|
|
|
|
2009-01-29 00:18:34 +08:00
|
|
|
|
2010-03-16 07:35:53 +08:00
|
|
|
final void setHandled(bool handled)
|
2010-01-07 04:37:29 +08:00
|
|
|
{
|
|
|
|
m_preventDelete = handled;
|
|
|
|
}
|
|
|
|
|
2010-03-16 07:35:53 +08:00
|
|
|
override bool opEquals(Object o)
|
|
|
|
{
|
|
|
|
return (m_ptr == (cast(DSFMLObject)o).nativePointer);
|
|
|
|
}
|
|
|
|
|
2010-01-07 04:37:29 +08:00
|
|
|
protected invariant()
|
|
|
|
{
|
|
|
|
assert(m_ptr !is null, "Problem occurs with a null pointer in " ~ this.toString);
|
|
|
|
}
|
2010-01-07 04:25:45 +08:00
|
|
|
}
|