Merge pull request #65 from learn-more/master

Cleanup & refactor
This commit is contained in:
yvt 2013-09-13 20:06:22 -07:00
commit a0950570cb
51 changed files with 7816 additions and 7624 deletions

4
.gitignore vendored
View File

@ -22,6 +22,10 @@ build
# cmake generated
OpenSpades.h
# cmake input dir (optional)
Sources/Externals/include/
Sources/Externals/lib/
# autotools
Makefile
Makefile.in

View File

@ -5,6 +5,7 @@ set(OpenSpades_VERSION_MAJOR 0)
set(OpenSpades_VERSION_MINOR 0)
set(OpenSpades_VERSION_REVISION 8)
set(CMAKE_PREFIX_PATH Sources/Externals)
include(FindSDL)
if(NOT SDL_FOUND)
@ -21,13 +22,6 @@ if(NOT GLEW_FOUND)
message(FATAL_ERROR "GLEW not found, please install it and make sure CMake can find it (add it to the PATH)")
endif()
#include(FindOpenAL)
#if(OPENAL_FOUND)
# set(HAVE_OPENAL TRUE)
#else()
# message(STATUS "OpenAL not found, set ENV{OPENALDIR} to point to OpenAL")
#endif()
set(FLTK_SKIP_OPENGL TRUE)
set(FLTK_SKIP_FORMS TRUE)
set(FLTK_SKIP_FLUID TRUE)
@ -118,6 +112,16 @@ if(OPENSPADES_RESDIR)
endif()
if(CMAKE_CXX_COMPILER_ID)
if(CMAKE_CXX_COMPILER_VERSION)
set(_version " ${CMAKE_CXX_COMPILER_VERSION}")
else()
set(_version "")
endif()
set(OPENSPADES_COMPILER ${CMAKE_CXX_COMPILER_ID}${_version})
endif()
configure_file("${PROJECT_SOURCE_DIR}/OpenSpades.h.in" "${PROJECT_BINARY_DIR}/OpenSpades.h")
include_directories("${PROJECT_BINARY_DIR}")
include_directories("${SDL_INCLUDE_DIR}")
@ -132,21 +136,4 @@ include_directories("${CURL_INCLUDE_DIRS}")
add_subdirectory(Resources)
add_subdirectory(Sources)
#EXECUTABLE_OUTPUT_PATH
#if test "$prefix" = "NONE"; then
# FLTK_CONFIG="fltk-config"
#else
# FLTK_CONFIG="${prefix}/bin/fltk-config"
#fi
#FLTK_CFLAGS=`${FLTK_CONFIG} --cxxflags --use-images`
#FLTK_LIBS=`${FLTK_CONFIG} --ldflags --use-images`
#AC_CHECK_MEMBER(struct msghdr.msg_flags, [AC_DEFINE(HAS_MSGHDR_FLAGS)], , [#include <sys/socket.h>])
#AC_CHECK_TYPE(socklen_t, [AC_DEFINE(HAS_SOCKLEN_T)], ,
#include <sys/types.h>
#include <sys/socket.h>
#)

2
NEWS
View File

@ -1,2 +0,0 @@

View File

@ -5,13 +5,17 @@
#define OpenSpades_VERSION_MINOR @OpenSpades_VERSION_MINOR@
#define OpenSpades_VERSION_REVISION @OpenSpades_VERSION_REVISION@
#define OS_STRINGIFY2(x) #x
#define OS_STRINGIFY(x) OS_STRINGIFY2(x)
#define OS_STRINGIFY2(x) #x
#define OS_STRINGIFY(x) OS_STRINGIFY2(x)
#define OpenSpades_VER_STR "OpenSpades " OS_STRINGIFY(OpenSpades_VERSION_MAJOR) "." OS_STRINGIFY(OpenSpades_VERSION_MINOR) "." OS_STRINGIFY(OpenSpades_VERSION_REVISION)
#define PACKAGE_STRING OpenSpades_VER_STR
#define OpenSpades_VER_STR "OpenSpades " OS_STRINGIFY(OpenSpades_VERSION_MAJOR) "." OS_STRINGIFY(OpenSpades_VERSION_MINOR) "." OS_STRINGIFY(OpenSpades_VERSION_REVISION)
#define PACKAGE_STRING OpenSpades_VER_STR
#cmakedefine HAS_OPENAL
#define OPENSPADES_COMPILER_STR "${OPENSPADES_COMPILER}"
#define SDL_VERSION_STR "${SDL_VERSION_STRING}"
#define ZLIB_VERSION_STR "${ZLIB_VERSION_STRING}"
#define CURL_VERSION_STR "${CURL_VERSION_STRING}"
#cmakedefine RESDIR_DEFINED
#define RESDIR "${RESDIR}"

View File

@ -1,467 +1,467 @@
#include "scriptany.h"
#include <new>
#include <assert.h>
#include <string.h>
BEGIN_AS_NAMESPACE
// We'll use the generic interface for the factories as we need the engine pointer
static void ScriptAnyFactory_Generic(asIScriptGeneric *gen)
{
asIScriptEngine *engine = gen->GetEngine();
*(CScriptAny**)gen->GetAddressOfReturnLocation() = new CScriptAny(engine);
}
static void ScriptAnyFactory2_Generic(asIScriptGeneric *gen)
{
asIScriptEngine *engine = gen->GetEngine();
void *ref = (void*)gen->GetArgAddress(0);
int refType = gen->GetArgTypeId(0);
*(CScriptAny**)gen->GetAddressOfReturnLocation() = new CScriptAny(ref,refType,engine);
}
static CScriptAny &ScriptAnyAssignment(CScriptAny *other, CScriptAny *self)
{
return *self = *other;
}
static void ScriptAnyAssignment_Generic(asIScriptGeneric *gen)
{
CScriptAny *other = (CScriptAny*)gen->GetArgObject(0);
CScriptAny *self = (CScriptAny*)gen->GetObject();
*self = *other;
gen->SetReturnObject(self);
}
static void ScriptAny_Store_Generic(asIScriptGeneric *gen)
{
void *ref = (void*)gen->GetArgAddress(0);
int refTypeId = gen->GetArgTypeId(0);
CScriptAny *self = (CScriptAny*)gen->GetObject();
self->Store(ref, refTypeId);
}
static void ScriptAny_StoreInt_Generic(asIScriptGeneric *gen)
{
asINT64 *ref = (asINT64*)gen->GetArgAddress(0);
CScriptAny *self = (CScriptAny*)gen->GetObject();
self->Store(*ref);
}
static void ScriptAny_StoreFlt_Generic(asIScriptGeneric *gen)
{
double *ref = (double*)gen->GetArgAddress(0);
CScriptAny *self = (CScriptAny*)gen->GetObject();
self->Store(*ref);
}
static void ScriptAny_Retrieve_Generic(asIScriptGeneric *gen)
{
void *ref = (void*)gen->GetArgAddress(0);
int refTypeId = gen->GetArgTypeId(0);
CScriptAny *self = (CScriptAny*)gen->GetObject();
*(bool*)gen->GetAddressOfReturnLocation() = self->Retrieve(ref, refTypeId);
}
static void ScriptAny_RetrieveInt_Generic(asIScriptGeneric *gen)
{
asINT64 *ref = (asINT64*)gen->GetArgAddress(0);
CScriptAny *self = (CScriptAny*)gen->GetObject();
*(bool*)gen->GetAddressOfReturnLocation() = self->Retrieve(*ref);
}
static void ScriptAny_RetrieveFlt_Generic(asIScriptGeneric *gen)
{
double *ref = (double*)gen->GetArgAddress(0);
CScriptAny *self = (CScriptAny*)gen->GetObject();
*(bool*)gen->GetAddressOfReturnLocation() = self->Retrieve(*ref);
}
static void ScriptAny_AddRef_Generic(asIScriptGeneric *gen)
{
CScriptAny *self = (CScriptAny*)gen->GetObject();
self->AddRef();
}
static void ScriptAny_Release_Generic(asIScriptGeneric *gen)
{
CScriptAny *self = (CScriptAny*)gen->GetObject();
self->Release();
}
static void ScriptAny_GetRefCount_Generic(asIScriptGeneric *gen)
{
CScriptAny *self = (CScriptAny*)gen->GetObject();
*(int*)gen->GetAddressOfReturnLocation() = self->GetRefCount();
}
static void ScriptAny_SetFlag_Generic(asIScriptGeneric *gen)
{
CScriptAny *self = (CScriptAny*)gen->GetObject();
self->SetFlag();
}
static void ScriptAny_GetFlag_Generic(asIScriptGeneric *gen)
{
CScriptAny *self = (CScriptAny*)gen->GetObject();
*(bool*)gen->GetAddressOfReturnLocation() = self->GetFlag();
}
static void ScriptAny_EnumReferences_Generic(asIScriptGeneric *gen)
{
CScriptAny *self = (CScriptAny*)gen->GetObject();
asIScriptEngine *engine = *(asIScriptEngine**)gen->GetAddressOfArg(0);
self->EnumReferences(engine);
}
static void ScriptAny_ReleaseAllHandles_Generic(asIScriptGeneric *gen)
{
CScriptAny *self = (CScriptAny*)gen->GetObject();
asIScriptEngine *engine = *(asIScriptEngine**)gen->GetAddressOfArg(0);
self->ReleaseAllHandles(engine);
}
void RegisterScriptAny(asIScriptEngine *engine)
{
if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") )
RegisterScriptAny_Generic(engine);
else
RegisterScriptAny_Native(engine);
}
void RegisterScriptAny_Native(asIScriptEngine *engine)
{
int r;
r = engine->RegisterObjectType("any", sizeof(CScriptAny), asOBJ_REF | asOBJ_GC); assert( r >= 0 );
// We'll use the generic interface for the constructor as we need the engine pointer
r = engine->RegisterObjectBehaviour("any", asBEHAVE_FACTORY, "any@ f()", asFUNCTION(ScriptAnyFactory_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_FACTORY, "any@ f(?&in)", asFUNCTION(ScriptAnyFactory2_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_ADDREF, "void f()", asMETHOD(CScriptAny,AddRef), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_RELEASE, "void f()", asMETHOD(CScriptAny,Release), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "any &opAssign(any&in)", asFUNCTION(ScriptAnyAssignment), asCALL_CDECL_OBJLAST); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "void store(?&in)", asMETHODPR(CScriptAny,Store,(void*,int),void), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "void store(int64&in)", asMETHODPR(CScriptAny,Store,(asINT64&),void), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "void store(double&in)", asMETHODPR(CScriptAny,Store,(double&),void), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "bool retrieve(?&out)", asMETHODPR(CScriptAny,Retrieve,(void*,int) const,bool), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "bool retrieve(int64&out)", asMETHODPR(CScriptAny,Retrieve,(asINT64&) const,bool), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "bool retrieve(double&out)", asMETHODPR(CScriptAny,Retrieve,(double&) const,bool), asCALL_THISCALL); assert( r >= 0 );
// Register GC behaviours
r = engine->RegisterObjectBehaviour("any", asBEHAVE_GETREFCOUNT, "int f()", asMETHOD(CScriptAny,GetRefCount), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_SETGCFLAG, "void f()", asMETHOD(CScriptAny,SetFlag), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_GETGCFLAG, "bool f()", asMETHOD(CScriptAny,GetFlag), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_ENUMREFS, "void f(int&in)", asMETHOD(CScriptAny,EnumReferences), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_RELEASEREFS, "void f(int&in)", asMETHOD(CScriptAny,ReleaseAllHandles), asCALL_THISCALL); assert( r >= 0 );
}
void RegisterScriptAny_Generic(asIScriptEngine *engine)
{
int r;
r = engine->RegisterObjectType("any", sizeof(CScriptAny), asOBJ_REF | asOBJ_GC); assert( r >= 0 );
// We'll use the generic interface for the constructor as we need the engine pointer
r = engine->RegisterObjectBehaviour("any", asBEHAVE_FACTORY, "any@ f()", asFUNCTION(ScriptAnyFactory_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_FACTORY, "any@ f(?&in)", asFUNCTION(ScriptAnyFactory2_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_ADDREF, "void f()", asFUNCTION(ScriptAny_AddRef_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_RELEASE, "void f()", asFUNCTION(ScriptAny_Release_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "any &opAssign(any&in)", asFUNCTION(ScriptAnyAssignment_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "void store(?&in)", asFUNCTION(ScriptAny_Store_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "void store(int64&in)", asFUNCTION(ScriptAny_StoreInt_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "void store(double&in)", asFUNCTION(ScriptAny_StoreFlt_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "bool retrieve(?&out) const", asFUNCTION(ScriptAny_Retrieve_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "bool retrieve(int64&out) const", asFUNCTION(ScriptAny_RetrieveInt_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "bool retrieve(double&out) const", asFUNCTION(ScriptAny_RetrieveFlt_Generic), asCALL_GENERIC); assert( r >= 0 );
// Register GC behaviours
r = engine->RegisterObjectBehaviour("any", asBEHAVE_GETREFCOUNT, "int f()", asFUNCTION(ScriptAny_GetRefCount_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_SETGCFLAG, "void f()", asFUNCTION(ScriptAny_SetFlag_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_GETGCFLAG, "bool f()", asFUNCTION(ScriptAny_GetFlag_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_ENUMREFS, "void f(int&in)", asFUNCTION(ScriptAny_EnumReferences_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_RELEASEREFS, "void f(int&in)", asFUNCTION(ScriptAny_ReleaseAllHandles_Generic), asCALL_GENERIC); assert( r >= 0 );
}
CScriptAny &CScriptAny::operator=(const CScriptAny &other)
{
// Hold on to the object type reference so it isn't destroyed too early
if( other.value.valueObj && (other.value.typeId & asTYPEID_MASK_OBJECT) )
{
asIObjectType *ot = engine->GetObjectTypeById(other.value.typeId);
if( ot )
ot->AddRef();
}
FreeObject();
value.typeId = other.value.typeId;
if( value.typeId & asTYPEID_OBJHANDLE )
{
// For handles, copy the pointer and increment the reference count
value.valueObj = other.value.valueObj;
engine->AddRefScriptObject(value.valueObj, engine->GetObjectTypeById(value.typeId));
}
else if( value.typeId & asTYPEID_MASK_OBJECT )
{
// Create a copy of the object
value.valueObj = engine->CreateScriptObjectCopy(other.value.valueObj, engine->GetObjectTypeById(value.typeId));
}
else
{
// Primitives can be copied directly
value.valueInt = other.value.valueInt;
}
return *this;
}
int CScriptAny::CopyFrom(const CScriptAny *other)
{
if( other == 0 ) return asINVALID_ARG;
*this = *(CScriptAny*)other;
return 0;
}
CScriptAny::CScriptAny(asIScriptEngine *engine)
{
this->engine = engine;
refCount = 1;
gcFlag = false;
value.typeId = 0;
value.valueInt = 0;
// Notify the garbage collector of this object
engine->NotifyGarbageCollectorOfNewObject(this, engine->GetObjectTypeByName("any"));
}
CScriptAny::CScriptAny(void *ref, int refTypeId, asIScriptEngine *engine)
{
this->engine = engine;
refCount = 1;
gcFlag = false;
value.typeId = 0;
value.valueInt = 0;
// Notify the garbage collector of this object
engine->NotifyGarbageCollectorOfNewObject(this, engine->GetObjectTypeByName("any"));
Store(ref, refTypeId);
}
CScriptAny::~CScriptAny()
{
FreeObject();
}
void CScriptAny::Store(void *ref, int refTypeId)
{
// Hold on to the object type reference so it isn't destroyed too early
if( *(void**)ref && (refTypeId & asTYPEID_MASK_OBJECT) )
{
asIObjectType *ot = engine->GetObjectTypeById(refTypeId);
if( ot )
ot->AddRef();
}
FreeObject();
value.typeId = refTypeId;
if( value.typeId & asTYPEID_OBJHANDLE )
{
// We're receiving a reference to the handle, so we need to dereference it
value.valueObj = *(void**)ref;
engine->AddRefScriptObject(value.valueObj, engine->GetObjectTypeById(value.typeId));
}
else if( value.typeId & asTYPEID_MASK_OBJECT )
{
// Create a copy of the object
value.valueObj = engine->CreateScriptObjectCopy(ref, engine->GetObjectTypeById(value.typeId));
}
else
{
// Primitives can be copied directly
value.valueInt = 0;
// Copy the primitive value
// We receive a pointer to the value.
int size = engine->GetSizeOfPrimitiveType(value.typeId);
memcpy(&value.valueInt, ref, size);
}
}
void CScriptAny::Store(double &ref)
{
Store(&ref, asTYPEID_DOUBLE);
}
void CScriptAny::Store(asINT64 &ref)
{
Store(&ref, asTYPEID_INT64);
}
bool CScriptAny::Retrieve(void *ref, int refTypeId) const
{
if( refTypeId & asTYPEID_OBJHANDLE )
{
// Is the handle type compatible with the stored value?
// A handle can be retrieved if the stored type is a handle of same or compatible type
// or if the stored type is an object that implements the interface that the handle refer to.
if( (value.typeId & asTYPEID_MASK_OBJECT) &&
engine->IsHandleCompatibleWithObject(value.valueObj, value.typeId, refTypeId) )
{
engine->AddRefScriptObject(value.valueObj, engine->GetObjectTypeById(value.typeId));
*(void**)ref = value.valueObj;
return true;
}
}
else if( refTypeId & asTYPEID_MASK_OBJECT )
{
// Is the object type compatible with the stored value?
// Copy the object into the given reference
if( value.typeId == refTypeId )
{
engine->AssignScriptObject(ref, value.valueObj, engine->GetObjectTypeById(value.typeId));
return true;
}
}
else
{
// Is the primitive type compatible with the stored value?
if( value.typeId == refTypeId )
{
int size = engine->GetSizeOfPrimitiveType(refTypeId);
memcpy(ref, &value.valueInt, size);
return true;
}
// We know all numbers are stored as either int64 or double, since we register overloaded functions for those
if( value.typeId == asTYPEID_INT64 && refTypeId == asTYPEID_DOUBLE )
{
*(double*)ref = double(value.valueInt);
return true;
}
else if( value.typeId == asTYPEID_DOUBLE && refTypeId == asTYPEID_INT64 )
{
*(asINT64*)ref = asINT64(value.valueFlt);
return true;
}
}
return false;
}
bool CScriptAny::Retrieve(asINT64 &value) const
{
return Retrieve(&value, asTYPEID_INT64);
}
bool CScriptAny::Retrieve(double &value) const
{
return Retrieve(&value, asTYPEID_DOUBLE);
}
int CScriptAny::GetTypeId() const
{
return value.typeId;
}
void CScriptAny::FreeObject()
{
// If it is a handle or a ref counted object, call release
if( value.typeId & asTYPEID_MASK_OBJECT )
{
// Let the engine release the object
asIObjectType *ot = engine->GetObjectTypeById(value.typeId);
engine->ReleaseScriptObject(value.valueObj, ot);
// Release the object type info
if( ot )
ot->Release();
value.valueObj = 0;
value.typeId = 0;
}
// For primitives, there's nothing to do
}
void CScriptAny::EnumReferences(asIScriptEngine *engine)
{
// If we're holding a reference, we'll notify the garbage collector of it
if( value.valueObj && (value.typeId & asTYPEID_MASK_OBJECT) )
{
engine->GCEnumCallback(value.valueObj);
// The object type itself is also garbage collected
asIObjectType *ot = engine->GetObjectTypeById(value.typeId);
if( ot )
engine->GCEnumCallback(ot);
}
}
void CScriptAny::ReleaseAllHandles(asIScriptEngine * /*engine*/)
{
FreeObject();
}
int CScriptAny::AddRef() const
{
// Increase counter and clear flag set by GC
gcFlag = false;
return asAtomicInc(refCount);
}
int CScriptAny::Release() const
{
// Decrease the ref counter
gcFlag = false;
if( asAtomicDec(refCount) == 0 )
{
// Delete this object as no more references to it exists
delete this;
return 0;
}
return refCount;
}
int CScriptAny::GetRefCount()
{
return refCount;
}
void CScriptAny::SetFlag()
{
gcFlag = true;
}
bool CScriptAny::GetFlag()
{
return gcFlag;
}
END_AS_NAMESPACE
#include "scriptany.h"
#include <new>
#include <assert.h>
#include <string.h>
BEGIN_AS_NAMESPACE
// We'll use the generic interface for the factories as we need the engine pointer
static void ScriptAnyFactory_Generic(asIScriptGeneric *gen)
{
asIScriptEngine *engine = gen->GetEngine();
*(CScriptAny**)gen->GetAddressOfReturnLocation() = new CScriptAny(engine);
}
static void ScriptAnyFactory2_Generic(asIScriptGeneric *gen)
{
asIScriptEngine *engine = gen->GetEngine();
void *ref = (void*)gen->GetArgAddress(0);
int refType = gen->GetArgTypeId(0);
*(CScriptAny**)gen->GetAddressOfReturnLocation() = new CScriptAny(ref,refType,engine);
}
static CScriptAny &ScriptAnyAssignment(CScriptAny *other, CScriptAny *self)
{
return *self = *other;
}
static void ScriptAnyAssignment_Generic(asIScriptGeneric *gen)
{
CScriptAny *other = (CScriptAny*)gen->GetArgObject(0);
CScriptAny *self = (CScriptAny*)gen->GetObject();
*self = *other;
gen->SetReturnObject(self);
}
static void ScriptAny_Store_Generic(asIScriptGeneric *gen)
{
void *ref = (void*)gen->GetArgAddress(0);
int refTypeId = gen->GetArgTypeId(0);
CScriptAny *self = (CScriptAny*)gen->GetObject();
self->Store(ref, refTypeId);
}
static void ScriptAny_StoreInt_Generic(asIScriptGeneric *gen)
{
asINT64 *ref = (asINT64*)gen->GetArgAddress(0);
CScriptAny *self = (CScriptAny*)gen->GetObject();
self->Store(*ref);
}
static void ScriptAny_StoreFlt_Generic(asIScriptGeneric *gen)
{
double *ref = (double*)gen->GetArgAddress(0);
CScriptAny *self = (CScriptAny*)gen->GetObject();
self->Store(*ref);
}
static void ScriptAny_Retrieve_Generic(asIScriptGeneric *gen)
{
void *ref = (void*)gen->GetArgAddress(0);
int refTypeId = gen->GetArgTypeId(0);
CScriptAny *self = (CScriptAny*)gen->GetObject();
*(bool*)gen->GetAddressOfReturnLocation() = self->Retrieve(ref, refTypeId);
}
static void ScriptAny_RetrieveInt_Generic(asIScriptGeneric *gen)
{
asINT64 *ref = (asINT64*)gen->GetArgAddress(0);
CScriptAny *self = (CScriptAny*)gen->GetObject();
*(bool*)gen->GetAddressOfReturnLocation() = self->Retrieve(*ref);
}
static void ScriptAny_RetrieveFlt_Generic(asIScriptGeneric *gen)
{
double *ref = (double*)gen->GetArgAddress(0);
CScriptAny *self = (CScriptAny*)gen->GetObject();
*(bool*)gen->GetAddressOfReturnLocation() = self->Retrieve(*ref);
}
static void ScriptAny_AddRef_Generic(asIScriptGeneric *gen)
{
CScriptAny *self = (CScriptAny*)gen->GetObject();
self->AddRef();
}
static void ScriptAny_Release_Generic(asIScriptGeneric *gen)
{
CScriptAny *self = (CScriptAny*)gen->GetObject();
self->Release();
}
static void ScriptAny_GetRefCount_Generic(asIScriptGeneric *gen)
{
CScriptAny *self = (CScriptAny*)gen->GetObject();
*(int*)gen->GetAddressOfReturnLocation() = self->GetRefCount();
}
static void ScriptAny_SetFlag_Generic(asIScriptGeneric *gen)
{
CScriptAny *self = (CScriptAny*)gen->GetObject();
self->SetFlag();
}
static void ScriptAny_GetFlag_Generic(asIScriptGeneric *gen)
{
CScriptAny *self = (CScriptAny*)gen->GetObject();
*(bool*)gen->GetAddressOfReturnLocation() = self->GetFlag();
}
static void ScriptAny_EnumReferences_Generic(asIScriptGeneric *gen)
{
CScriptAny *self = (CScriptAny*)gen->GetObject();
asIScriptEngine *engine = *(asIScriptEngine**)gen->GetAddressOfArg(0);
self->EnumReferences(engine);
}
static void ScriptAny_ReleaseAllHandles_Generic(asIScriptGeneric *gen)
{
CScriptAny *self = (CScriptAny*)gen->GetObject();
asIScriptEngine *engine = *(asIScriptEngine**)gen->GetAddressOfArg(0);
self->ReleaseAllHandles(engine);
}
void RegisterScriptAny(asIScriptEngine *engine)
{
if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") )
RegisterScriptAny_Generic(engine);
else
RegisterScriptAny_Native(engine);
}
void RegisterScriptAny_Native(asIScriptEngine *engine)
{
int r;
r = engine->RegisterObjectType("any", sizeof(CScriptAny), asOBJ_REF | asOBJ_GC); assert( r >= 0 );
// We'll use the generic interface for the constructor as we need the engine pointer
r = engine->RegisterObjectBehaviour("any", asBEHAVE_FACTORY, "any@ f()", asFUNCTION(ScriptAnyFactory_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_FACTORY, "any@ f(?&in)", asFUNCTION(ScriptAnyFactory2_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_ADDREF, "void f()", asMETHOD(CScriptAny,AddRef), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_RELEASE, "void f()", asMETHOD(CScriptAny,Release), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "any &opAssign(any&in)", asFUNCTION(ScriptAnyAssignment), asCALL_CDECL_OBJLAST); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "void store(?&in)", asMETHODPR(CScriptAny,Store,(void*,int),void), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "void store(int64&in)", asMETHODPR(CScriptAny,Store,(asINT64&),void), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "void store(double&in)", asMETHODPR(CScriptAny,Store,(double&),void), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "bool retrieve(?&out)", asMETHODPR(CScriptAny,Retrieve,(void*,int) const,bool), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "bool retrieve(int64&out)", asMETHODPR(CScriptAny,Retrieve,(asINT64&) const,bool), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "bool retrieve(double&out)", asMETHODPR(CScriptAny,Retrieve,(double&) const,bool), asCALL_THISCALL); assert( r >= 0 );
// Register GC behaviours
r = engine->RegisterObjectBehaviour("any", asBEHAVE_GETREFCOUNT, "int f()", asMETHOD(CScriptAny,GetRefCount), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_SETGCFLAG, "void f()", asMETHOD(CScriptAny,SetFlag), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_GETGCFLAG, "bool f()", asMETHOD(CScriptAny,GetFlag), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_ENUMREFS, "void f(int&in)", asMETHOD(CScriptAny,EnumReferences), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_RELEASEREFS, "void f(int&in)", asMETHOD(CScriptAny,ReleaseAllHandles), asCALL_THISCALL); assert( r >= 0 );
}
void RegisterScriptAny_Generic(asIScriptEngine *engine)
{
int r;
r = engine->RegisterObjectType("any", sizeof(CScriptAny), asOBJ_REF | asOBJ_GC); assert( r >= 0 );
// We'll use the generic interface for the constructor as we need the engine pointer
r = engine->RegisterObjectBehaviour("any", asBEHAVE_FACTORY, "any@ f()", asFUNCTION(ScriptAnyFactory_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_FACTORY, "any@ f(?&in)", asFUNCTION(ScriptAnyFactory2_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_ADDREF, "void f()", asFUNCTION(ScriptAny_AddRef_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_RELEASE, "void f()", asFUNCTION(ScriptAny_Release_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "any &opAssign(any&in)", asFUNCTION(ScriptAnyAssignment_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "void store(?&in)", asFUNCTION(ScriptAny_Store_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "void store(int64&in)", asFUNCTION(ScriptAny_StoreInt_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "void store(double&in)", asFUNCTION(ScriptAny_StoreFlt_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "bool retrieve(?&out) const", asFUNCTION(ScriptAny_Retrieve_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "bool retrieve(int64&out) const", asFUNCTION(ScriptAny_RetrieveInt_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("any", "bool retrieve(double&out) const", asFUNCTION(ScriptAny_RetrieveFlt_Generic), asCALL_GENERIC); assert( r >= 0 );
// Register GC behaviours
r = engine->RegisterObjectBehaviour("any", asBEHAVE_GETREFCOUNT, "int f()", asFUNCTION(ScriptAny_GetRefCount_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_SETGCFLAG, "void f()", asFUNCTION(ScriptAny_SetFlag_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_GETGCFLAG, "bool f()", asFUNCTION(ScriptAny_GetFlag_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_ENUMREFS, "void f(int&in)", asFUNCTION(ScriptAny_EnumReferences_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("any", asBEHAVE_RELEASEREFS, "void f(int&in)", asFUNCTION(ScriptAny_ReleaseAllHandles_Generic), asCALL_GENERIC); assert( r >= 0 );
}
CScriptAny &CScriptAny::operator=(const CScriptAny &other)
{
// Hold on to the object type reference so it isn't destroyed too early
if( other.value.valueObj && (other.value.typeId & asTYPEID_MASK_OBJECT) )
{
asIObjectType *ot = engine->GetObjectTypeById(other.value.typeId);
if( ot )
ot->AddRef();
}
FreeObject();
value.typeId = other.value.typeId;
if( value.typeId & asTYPEID_OBJHANDLE )
{
// For handles, copy the pointer and increment the reference count
value.valueObj = other.value.valueObj;
engine->AddRefScriptObject(value.valueObj, engine->GetObjectTypeById(value.typeId));
}
else if( value.typeId & asTYPEID_MASK_OBJECT )
{
// Create a copy of the object
value.valueObj = engine->CreateScriptObjectCopy(other.value.valueObj, engine->GetObjectTypeById(value.typeId));
}
else
{
// Primitives can be copied directly
value.valueInt = other.value.valueInt;
}
return *this;
}
int CScriptAny::CopyFrom(const CScriptAny *other)
{
if( other == 0 ) return asINVALID_ARG;
*this = *(CScriptAny*)other;
return 0;
}
CScriptAny::CScriptAny(asIScriptEngine *engine)
{
this->engine = engine;
refCount = 1;
gcFlag = false;
value.typeId = 0;
value.valueInt = 0;
// Notify the garbage collector of this object
engine->NotifyGarbageCollectorOfNewObject(this, engine->GetObjectTypeByName("any"));
}
CScriptAny::CScriptAny(void *ref, int refTypeId, asIScriptEngine *engine)
{
this->engine = engine;
refCount = 1;
gcFlag = false;
value.typeId = 0;
value.valueInt = 0;
// Notify the garbage collector of this object
engine->NotifyGarbageCollectorOfNewObject(this, engine->GetObjectTypeByName("any"));
Store(ref, refTypeId);
}
CScriptAny::~CScriptAny()
{
FreeObject();
}
void CScriptAny::Store(void *ref, int refTypeId)
{
// Hold on to the object type reference so it isn't destroyed too early
if( *(void**)ref && (refTypeId & asTYPEID_MASK_OBJECT) )
{
asIObjectType *ot = engine->GetObjectTypeById(refTypeId);
if( ot )
ot->AddRef();
}
FreeObject();
value.typeId = refTypeId;
if( value.typeId & asTYPEID_OBJHANDLE )
{
// We're receiving a reference to the handle, so we need to dereference it
value.valueObj = *(void**)ref;
engine->AddRefScriptObject(value.valueObj, engine->GetObjectTypeById(value.typeId));
}
else if( value.typeId & asTYPEID_MASK_OBJECT )
{
// Create a copy of the object
value.valueObj = engine->CreateScriptObjectCopy(ref, engine->GetObjectTypeById(value.typeId));
}
else
{
// Primitives can be copied directly
value.valueInt = 0;
// Copy the primitive value
// We receive a pointer to the value.
int size = engine->GetSizeOfPrimitiveType(value.typeId);
memcpy(&value.valueInt, ref, size);
}
}
void CScriptAny::Store(double &ref)
{
Store(&ref, asTYPEID_DOUBLE);
}
void CScriptAny::Store(asINT64 &ref)
{
Store(&ref, asTYPEID_INT64);
}
bool CScriptAny::Retrieve(void *ref, int refTypeId) const
{
if( refTypeId & asTYPEID_OBJHANDLE )
{
// Is the handle type compatible with the stored value?
// A handle can be retrieved if the stored type is a handle of same or compatible type
// or if the stored type is an object that implements the interface that the handle refer to.
if( (value.typeId & asTYPEID_MASK_OBJECT) &&
engine->IsHandleCompatibleWithObject(value.valueObj, value.typeId, refTypeId) )
{
engine->AddRefScriptObject(value.valueObj, engine->GetObjectTypeById(value.typeId));
*(void**)ref = value.valueObj;
return true;
}
}
else if( refTypeId & asTYPEID_MASK_OBJECT )
{
// Is the object type compatible with the stored value?
// Copy the object into the given reference
if( value.typeId == refTypeId )
{
engine->AssignScriptObject(ref, value.valueObj, engine->GetObjectTypeById(value.typeId));
return true;
}
}
else
{
// Is the primitive type compatible with the stored value?
if( value.typeId == refTypeId )
{
int size = engine->GetSizeOfPrimitiveType(refTypeId);
memcpy(ref, &value.valueInt, size);
return true;
}
// We know all numbers are stored as either int64 or double, since we register overloaded functions for those
if( value.typeId == asTYPEID_INT64 && refTypeId == asTYPEID_DOUBLE )
{
*(double*)ref = double(value.valueInt);
return true;
}
else if( value.typeId == asTYPEID_DOUBLE && refTypeId == asTYPEID_INT64 )
{
*(asINT64*)ref = asINT64(value.valueFlt);
return true;
}
}
return false;
}
bool CScriptAny::Retrieve(asINT64 &value) const
{
return Retrieve(&value, asTYPEID_INT64);
}
bool CScriptAny::Retrieve(double &value) const
{
return Retrieve(&value, asTYPEID_DOUBLE);
}
int CScriptAny::GetTypeId() const
{
return value.typeId;
}
void CScriptAny::FreeObject()
{
// If it is a handle or a ref counted object, call release
if( value.typeId & asTYPEID_MASK_OBJECT )
{
// Let the engine release the object
asIObjectType *ot = engine->GetObjectTypeById(value.typeId);
engine->ReleaseScriptObject(value.valueObj, ot);
// Release the object type info
if( ot )
ot->Release();
value.valueObj = 0;
value.typeId = 0;
}
// For primitives, there's nothing to do
}
void CScriptAny::EnumReferences(asIScriptEngine *engine)
{
// If we're holding a reference, we'll notify the garbage collector of it
if( value.valueObj && (value.typeId & asTYPEID_MASK_OBJECT) )
{
engine->GCEnumCallback(value.valueObj);
// The object type itself is also garbage collected
asIObjectType *ot = engine->GetObjectTypeById(value.typeId);
if( ot )
engine->GCEnumCallback(ot);
}
}
void CScriptAny::ReleaseAllHandles(asIScriptEngine * /*engine*/)
{
FreeObject();
}
int CScriptAny::AddRef() const
{
// Increase counter and clear flag set by GC
gcFlag = false;
return asAtomicInc(refCount);
}
int CScriptAny::Release() const
{
// Decrease the ref counter
gcFlag = false;
if( asAtomicDec(refCount) == 0 )
{
// Delete this object as no more references to it exists
delete this;
return 0;
}
return refCount;
}
int CScriptAny::GetRefCount()
{
return refCount;
}
void CScriptAny::SetFlag()
{
gcFlag = true;
}
bool CScriptAny::GetFlag()
{
return gcFlag;
}
END_AS_NAMESPACE

View File

@ -1,76 +1,76 @@
#ifndef SCRIPTANY_H
#define SCRIPTANY_H
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
BEGIN_AS_NAMESPACE
class CScriptAny
{
public:
// Constructors
CScriptAny(asIScriptEngine *engine);
CScriptAny(void *ref, int refTypeId, asIScriptEngine *engine);
// Memory management
int AddRef() const;
int Release() const;
// Copy the stored value from another any object
CScriptAny &operator=(const CScriptAny&);
int CopyFrom(const CScriptAny *other);
// Store the value, either as variable type, integer number, or real number
void Store(void *ref, int refTypeId);
void Store(asINT64 &value);
void Store(double &value);
// Retrieve the stored value, either as variable type, integer number, or real number
bool Retrieve(void *ref, int refTypeId) const;
bool Retrieve(asINT64 &value) const;
bool Retrieve(double &value) const;
// Get the type id of the stored value
int GetTypeId() const;
// GC methods
int GetRefCount();
void SetFlag();
bool GetFlag();
void EnumReferences(asIScriptEngine *engine);
void ReleaseAllHandles(asIScriptEngine *engine);
protected:
virtual ~CScriptAny();
void FreeObject();
mutable int refCount;
mutable bool gcFlag;
asIScriptEngine *engine;
// The structure for holding the values
struct valueStruct
{
union
{
asINT64 valueInt;
double valueFlt;
void *valueObj;
};
int typeId;
};
valueStruct value;
};
void RegisterScriptAny(asIScriptEngine *engine);
void RegisterScriptAny_Native(asIScriptEngine *engine);
void RegisterScriptAny_Generic(asIScriptEngine *engine);
END_AS_NAMESPACE
#endif
#ifndef SCRIPTANY_H
#define SCRIPTANY_H
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
BEGIN_AS_NAMESPACE
class CScriptAny
{
public:
// Constructors
CScriptAny(asIScriptEngine *engine);
CScriptAny(void *ref, int refTypeId, asIScriptEngine *engine);
// Memory management
int AddRef() const;
int Release() const;
// Copy the stored value from another any object
CScriptAny &operator=(const CScriptAny&);
int CopyFrom(const CScriptAny *other);
// Store the value, either as variable type, integer number, or real number
void Store(void *ref, int refTypeId);
void Store(asINT64 &value);
void Store(double &value);
// Retrieve the stored value, either as variable type, integer number, or real number
bool Retrieve(void *ref, int refTypeId) const;
bool Retrieve(asINT64 &value) const;
bool Retrieve(double &value) const;
// Get the type id of the stored value
int GetTypeId() const;
// GC methods
int GetRefCount();
void SetFlag();
bool GetFlag();
void EnumReferences(asIScriptEngine *engine);
void ReleaseAllHandles(asIScriptEngine *engine);
protected:
virtual ~CScriptAny();
void FreeObject();
mutable int refCount;
mutable bool gcFlag;
asIScriptEngine *engine;
// The structure for holding the values
struct valueStruct
{
union
{
asINT64 valueInt;
double valueFlt;
void *valueObj;
};
int typeId;
};
valueStruct value;
};
void RegisterScriptAny(asIScriptEngine *engine);
void RegisterScriptAny_Native(asIScriptEngine *engine);
void RegisterScriptAny_Generic(asIScriptEngine *engine);
END_AS_NAMESPACE
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,103 +1,103 @@
#ifndef SCRIPTARRAY_H
#define SCRIPTARRAY_H
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
// Sometimes it may be desired to use the same method names as used by C++ STL.
// This may for example reduce time when converting code from script to C++ or
// back.
//
// 0 = off
// 1 = on
#ifndef AS_USE_STLNAMES
#define AS_USE_STLNAMES 0
#endif
BEGIN_AS_NAMESPACE
struct SArrayBuffer;
struct SArrayCache;
class CScriptArray
{
public:
CScriptArray(asUINT length, asIObjectType *ot);
CScriptArray(asUINT length, void *defVal, asIObjectType *ot);
CScriptArray(const CScriptArray &other);
virtual ~CScriptArray();
void AddRef() const;
void Release() const;
// Type information
asIObjectType *GetArrayObjectType() const;
int GetArrayTypeId() const;
int GetElementTypeId() const;
void Reserve(asUINT maxElements);
void Resize(asUINT numElements);
asUINT GetSize() const;
bool IsEmpty() const;
// Get a pointer to an element. Returns 0 if out of bounds
void *At(asUINT index);
const void *At(asUINT index) const;
// Set value of an element
void SetValue(asUINT index, void *value);
CScriptArray &operator=(const CScriptArray&);
bool operator==(const CScriptArray &) const;
void InsertAt(asUINT index, void *value);
void RemoveAt(asUINT index);
void InsertLast(void *value);
void RemoveLast();
void SortAsc();
void SortDesc();
void SortAsc(asUINT index, asUINT count);
void SortDesc(asUINT index, asUINT count);
void Sort(asUINT index, asUINT count, bool asc);
void Reverse();
int Find(void *value) const;
int Find(asUINT index, void *value) const;
// GC methods
int GetRefCount();
void SetFlag();
bool GetFlag();
void EnumReferences(asIScriptEngine *engine);
void ReleaseAllHandles(asIScriptEngine *engine);
protected:
mutable int refCount;
mutable bool gcFlag;
asIObjectType *objType;
SArrayBuffer *buffer;
int elementSize;
int subTypeId;
bool Less(const void *a, const void *b, bool asc, asIScriptContext *ctx, SArrayCache *cache);
void *GetArrayItemPointer(int index);
void *GetDataPointer(void *buffer);
void Copy(void *dst, void *src);
void Precache();
bool CheckMaxSize(asUINT numElements);
void Resize(int delta, asUINT at);
void CreateBuffer(SArrayBuffer **buf, asUINT numElements);
void DeleteBuffer(SArrayBuffer *buf);
void CopyBuffer(SArrayBuffer *dst, SArrayBuffer *src);
void Construct(SArrayBuffer *buf, asUINT start, asUINT end);
void Destruct(SArrayBuffer *buf, asUINT start, asUINT end);
bool Equals(const void *a, const void *b, asIScriptContext *ctx, SArrayCache *cache) const;
};
void RegisterScriptArray(asIScriptEngine *engine, bool defaultArray);
END_AS_NAMESPACE
#endif
#ifndef SCRIPTARRAY_H
#define SCRIPTARRAY_H
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
// Sometimes it may be desired to use the same method names as used by C++ STL.
// This may for example reduce time when converting code from script to C++ or
// back.
//
// 0 = off
// 1 = on
#ifndef AS_USE_STLNAMES
#define AS_USE_STLNAMES 0
#endif
BEGIN_AS_NAMESPACE
struct SArrayBuffer;
struct SArrayCache;
class CScriptArray
{
public:
CScriptArray(asUINT length, asIObjectType *ot);
CScriptArray(asUINT length, void *defVal, asIObjectType *ot);
CScriptArray(const CScriptArray &other);
virtual ~CScriptArray();
void AddRef() const;
void Release() const;
// Type information
asIObjectType *GetArrayObjectType() const;
int GetArrayTypeId() const;
int GetElementTypeId() const;
void Reserve(asUINT maxElements);
void Resize(asUINT numElements);
asUINT GetSize() const;
bool IsEmpty() const;
// Get a pointer to an element. Returns 0 if out of bounds
void *At(asUINT index);
const void *At(asUINT index) const;
// Set value of an element
void SetValue(asUINT index, void *value);
CScriptArray &operator=(const CScriptArray&);
bool operator==(const CScriptArray &) const;
void InsertAt(asUINT index, void *value);
void RemoveAt(asUINT index);
void InsertLast(void *value);
void RemoveLast();
void SortAsc();
void SortDesc();
void SortAsc(asUINT index, asUINT count);
void SortDesc(asUINT index, asUINT count);
void Sort(asUINT index, asUINT count, bool asc);
void Reverse();
int Find(void *value) const;
int Find(asUINT index, void *value) const;
// GC methods
int GetRefCount();
void SetFlag();
bool GetFlag();
void EnumReferences(asIScriptEngine *engine);
void ReleaseAllHandles(asIScriptEngine *engine);
protected:
mutable int refCount;
mutable bool gcFlag;
asIObjectType *objType;
SArrayBuffer *buffer;
int elementSize;
int subTypeId;
bool Less(const void *a, const void *b, bool asc, asIScriptContext *ctx, SArrayCache *cache);
void *GetArrayItemPointer(int index);
void *GetDataPointer(void *buffer);
void Copy(void *dst, void *src);
void Precache();
bool CheckMaxSize(asUINT numElements);
void Resize(int delta, asUINT at);
void CreateBuffer(SArrayBuffer **buf, asUINT numElements);
void DeleteBuffer(SArrayBuffer *buf);
void CopyBuffer(SArrayBuffer *dst, SArrayBuffer *src);
void Construct(SArrayBuffer *buf, asUINT start, asUINT end);
void Destruct(SArrayBuffer *buf, asUINT start, asUINT end);
bool Equals(const void *a, const void *b, asIScriptContext *ctx, SArrayCache *cache) const;
};
void RegisterScriptArray(asIScriptEngine *engine, bool defaultArray);
END_AS_NAMESPACE
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,167 +1,167 @@
#ifndef SCRIPTBUILDER_H
#define SCRIPTBUILDER_H
//---------------------------
// Compilation settings
//
// Set this flag to turn on/off metadata processing
// 0 = off
// 1 = on
#ifndef AS_PROCESS_METADATA
#define AS_PROCESS_METADATA 1
#endif
// TODO: Implement flags for turning on/off include directives and conditional programming
//---------------------------
// Declaration
//
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
#if defined(_MSC_VER) && _MSC_VER <= 1200
// disable the annoying warnings on MSVC 6
#pragma warning (disable:4786)
#endif
#include <string>
#include <map>
#include <set>
#include <vector>
BEGIN_AS_NAMESPACE
class CScriptBuilder;
// This callback will be called for each #include directive encountered by the
// builder. The callback should call the AddSectionFromFile or AddSectionFromMemory
// to add the included section to the script. If the include cannot be resolved
// then the function should return a negative value to abort the compilation.
typedef int (*INCLUDECALLBACK_t)(const char *include, const char *from, CScriptBuilder *builder, void *userParam);
// Helper class for loading and pre-processing script files to
// support include directives and metadata declarations
class CScriptBuilder
{
public:
CScriptBuilder();
// Start a new module
int StartNewModule(asIScriptEngine *engine, const char *moduleName);
// Load a script section from a file on disk
// Returns 1 if the file was included
// 0 if the file had already been included before
// <0 on error
int AddSectionFromFile(const char *filename);
// Load a script section from memory
// Returns 1 if the section was included
// 0 if a section with the same name had already been included before
// <0 on error
int AddSectionFromMemory(const char *sectionName,
const char *scriptCode,
unsigned int scriptLength = 0);
// Build the added script sections
int BuildModule();
// Returns the current module
asIScriptModule *GetModule();
// Register the callback for resolving include directive
void SetIncludeCallback(INCLUDECALLBACK_t callback, void *userParam);
// Add a pre-processor define for conditional compilation
void DefineWord(const char *word);
// Enumerate included script sections
unsigned int GetSectionCount() const;
std::string GetSectionName(unsigned int idx) const;
#if AS_PROCESS_METADATA == 1
// Get metadata declared for class types and interfaces
const char *GetMetadataStringForType(int typeId);
// Get metadata declared for functions
const char *GetMetadataStringForFunc(asIScriptFunction *func);
// Get metadata declared for global variables
const char *GetMetadataStringForVar(int varIdx);
// Get metadata declared for class variables
const char *GetMetadataStringForTypeProperty(int typeId, int varIdx);
// Get metadata declared for class functions
const char *GetMetadataStringForTypeMethod(int typeId, asIScriptFunction *method);
#endif
protected:
void ClearAll();
int Build();
int ProcessScriptSection(const char *script, unsigned int length, const char *sectionname);
int LoadScriptSection(const char *filename);
bool IncludeIfNotAlreadyIncluded(const char *filename);
int SkipStatement(int pos);
int ExcludeCode(int start);
void OverwriteCode(int start, int len);
asIScriptEngine *engine;
asIScriptModule *module;
std::string modifiedScript;
INCLUDECALLBACK_t includeCallback;
void *callbackParam;
#if AS_PROCESS_METADATA == 1
int ExtractMetadataString(int pos, std::string &outMetadata);
int ExtractDeclaration(int pos, std::string &outDeclaration, int &outType);
// Temporary structure for storing metadata and declaration
struct SMetadataDecl
{
SMetadataDecl(std::string m, std::string d, int t, std::string c, std::string ns) : metadata(m), declaration(d), type(t), parentClass(c), nameSpace(ns) {}
std::string metadata;
std::string declaration;
int type;
std::string parentClass;
std::string nameSpace;
};
std::vector<SMetadataDecl> foundDeclarations;
std::string currentClass;
std::string currentNamespace;
// Storage of metadata for global declarations
std::map<int, std::string> typeMetadataMap;
std::map<int, std::string> funcMetadataMap;
std::map<int, std::string> varMetadataMap;
// Storage of metadata for class member declarations
struct SClassMetadata
{
SClassMetadata(const std::string& aName) : className(aName) {}
std::string className;
std::map<int, std::string> funcMetadataMap;
std::map<int, std::string> varMetadataMap;
};
std::map<int, SClassMetadata> classMetadataMap;
#endif
std::set<std::string> includedScripts;
std::set<std::string> definedWords;
};
END_AS_NAMESPACE
#endif
#ifndef SCRIPTBUILDER_H
#define SCRIPTBUILDER_H
//---------------------------
// Compilation settings
//
// Set this flag to turn on/off metadata processing
// 0 = off
// 1 = on
#ifndef AS_PROCESS_METADATA
#define AS_PROCESS_METADATA 1
#endif
// TODO: Implement flags for turning on/off include directives and conditional programming
//---------------------------
// Declaration
//
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
#if defined(_MSC_VER) && _MSC_VER <= 1200
// disable the annoying warnings on MSVC 6
#pragma warning (disable:4786)
#endif
#include <string>
#include <map>
#include <set>
#include <vector>
BEGIN_AS_NAMESPACE
class CScriptBuilder;
// This callback will be called for each #include directive encountered by the
// builder. The callback should call the AddSectionFromFile or AddSectionFromMemory
// to add the included section to the script. If the include cannot be resolved
// then the function should return a negative value to abort the compilation.
typedef int (*INCLUDECALLBACK_t)(const char *include, const char *from, CScriptBuilder *builder, void *userParam);
// Helper class for loading and pre-processing script files to
// support include directives and metadata declarations
class CScriptBuilder
{
public:
CScriptBuilder();
// Start a new module
int StartNewModule(asIScriptEngine *engine, const char *moduleName);
// Load a script section from a file on disk
// Returns 1 if the file was included
// 0 if the file had already been included before
// <0 on error
int AddSectionFromFile(const char *filename);
// Load a script section from memory
// Returns 1 if the section was included
// 0 if a section with the same name had already been included before
// <0 on error
int AddSectionFromMemory(const char *sectionName,
const char *scriptCode,
unsigned int scriptLength = 0);
// Build the added script sections
int BuildModule();
// Returns the current module
asIScriptModule *GetModule();
// Register the callback for resolving include directive
void SetIncludeCallback(INCLUDECALLBACK_t callback, void *userParam);
// Add a pre-processor define for conditional compilation
void DefineWord(const char *word);
// Enumerate included script sections
unsigned int GetSectionCount() const;
std::string GetSectionName(unsigned int idx) const;
#if AS_PROCESS_METADATA == 1
// Get metadata declared for class types and interfaces
const char *GetMetadataStringForType(int typeId);
// Get metadata declared for functions
const char *GetMetadataStringForFunc(asIScriptFunction *func);
// Get metadata declared for global variables
const char *GetMetadataStringForVar(int varIdx);
// Get metadata declared for class variables
const char *GetMetadataStringForTypeProperty(int typeId, int varIdx);
// Get metadata declared for class functions
const char *GetMetadataStringForTypeMethod(int typeId, asIScriptFunction *method);
#endif
protected:
void ClearAll();
int Build();
int ProcessScriptSection(const char *script, unsigned int length, const char *sectionname);
int LoadScriptSection(const char *filename);
bool IncludeIfNotAlreadyIncluded(const char *filename);
int SkipStatement(int pos);
int ExcludeCode(int start);
void OverwriteCode(int start, int len);
asIScriptEngine *engine;
asIScriptModule *module;
std::string modifiedScript;
INCLUDECALLBACK_t includeCallback;
void *callbackParam;
#if AS_PROCESS_METADATA == 1
int ExtractMetadataString(int pos, std::string &outMetadata);
int ExtractDeclaration(int pos, std::string &outDeclaration, int &outType);
// Temporary structure for storing metadata and declaration
struct SMetadataDecl
{
SMetadataDecl(std::string m, std::string d, int t, std::string c, std::string ns) : metadata(m), declaration(d), type(t), parentClass(c), nameSpace(ns) {}
std::string metadata;
std::string declaration;
int type;
std::string parentClass;
std::string nameSpace;
};
std::vector<SMetadataDecl> foundDeclarations;
std::string currentClass;
std::string currentNamespace;
// Storage of metadata for global declarations
std::map<int, std::string> typeMetadataMap;
std::map<int, std::string> funcMetadataMap;
std::map<int, std::string> varMetadataMap;
// Storage of metadata for class member declarations
struct SClassMetadata
{
SClassMetadata(const std::string& aName) : className(aName) {}
std::string className;
std::map<int, std::string> funcMetadataMap;
std::map<int, std::string> varMetadataMap;
};
std::map<int, SClassMetadata> classMetadataMap;
#endif
std::set<std::string> includedScripts;
std::set<std::string> definedWords;
};
END_AS_NAMESPACE
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,123 +1,123 @@
#ifndef SCRIPTDICTIONARY_H
#define SCRIPTDICTIONARY_H
// The dictionary class relies on the script string object, thus the script
// string type must be registered with the engine before registering the
// dictionary type
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
#include <string>
#ifdef _MSC_VER
// Turn off annoying warnings about truncated symbol names
#pragma warning (disable:4786)
#endif
#include <map>
// Sometimes it may be desired to use the same method names as used by C++ STL.
// This may for example reduce time when converting code from script to C++ or
// back.
//
// 0 = off
// 1 = on
#ifndef AS_USE_STLNAMES
#define AS_USE_STLNAMES 0
#endif
BEGIN_AS_NAMESPACE
class CScriptArray;
class CScriptDictionary
{
public:
// Memory management
CScriptDictionary(asIScriptEngine *engine);
void AddRef() const;
void Release() const;
CScriptDictionary &operator =(const CScriptDictionary &other);
// Sets/Gets a variable type value for a key
void Set(const std::string &key, void *value, int typeId);
bool Get(const std::string &key, void *value, int typeId) const;
// Sets/Gets an integer number value for a key
void Set(const std::string &key, asINT64 &value);
bool Get(const std::string &key, asINT64 &value) const;
// Sets/Gets a real number value for a key
void Set(const std::string &key, double &value);
bool Get(const std::string &key, double &value) const;
// Returns true if the key is set
bool Exists(const std::string &key) const;
bool IsEmpty() const;
asUINT GetSize() const;
// Deletes the key
void Delete(const std::string &key);
// Deletes all keys
void DeleteAll();
// Get an array of all keys
CScriptArray *GetKeys() const;
// Garbage collections behaviours
int GetRefCount();
void SetGCFlag();
bool GetGCFlag();
void EnumReferences(asIScriptEngine *engine);
void ReleaseAllReferences(asIScriptEngine *engine);
protected:
// The structure for holding the values
struct valueStruct
{
union
{
asINT64 valueInt;
double valueFlt;
void *valueObj;
};
int typeId;
};
// We don't want anyone to call the destructor directly, it should be called through the Release method
virtual ~CScriptDictionary();
// Helper methods
void FreeValue(valueStruct &value);
// Our properties
asIScriptEngine *engine;
mutable int refCount;
mutable bool gcFlag;
// TODO: optimize: Use C++11 std::unordered_map instead
std::map<std::string, valueStruct> dict;
};
// This function will determine the configuration of the engine
// and use one of the two functions below to register the dictionary object
void RegisterScriptDictionary(asIScriptEngine *engine);
// Call this function to register the math functions
// using native calling conventions
void RegisterScriptDictionary_Native(asIScriptEngine *engine);
// Use this one instead if native calling conventions
// are not supported on the target platform
void RegisterScriptDictionary_Generic(asIScriptEngine *engine);
END_AS_NAMESPACE
#endif
#ifndef SCRIPTDICTIONARY_H
#define SCRIPTDICTIONARY_H
// The dictionary class relies on the script string object, thus the script
// string type must be registered with the engine before registering the
// dictionary type
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
#include <string>
#ifdef _MSC_VER
// Turn off annoying warnings about truncated symbol names
#pragma warning (disable:4786)
#endif
#include <map>
// Sometimes it may be desired to use the same method names as used by C++ STL.
// This may for example reduce time when converting code from script to C++ or
// back.
//
// 0 = off
// 1 = on
#ifndef AS_USE_STLNAMES
#define AS_USE_STLNAMES 0
#endif
BEGIN_AS_NAMESPACE
class CScriptArray;
class CScriptDictionary
{
public:
// Memory management
CScriptDictionary(asIScriptEngine *engine);
void AddRef() const;
void Release() const;
CScriptDictionary &operator =(const CScriptDictionary &other);
// Sets/Gets a variable type value for a key
void Set(const std::string &key, void *value, int typeId);
bool Get(const std::string &key, void *value, int typeId) const;
// Sets/Gets an integer number value for a key
void Set(const std::string &key, asINT64 &value);
bool Get(const std::string &key, asINT64 &value) const;
// Sets/Gets a real number value for a key
void Set(const std::string &key, double &value);
bool Get(const std::string &key, double &value) const;
// Returns true if the key is set
bool Exists(const std::string &key) const;
bool IsEmpty() const;
asUINT GetSize() const;
// Deletes the key
void Delete(const std::string &key);
// Deletes all keys
void DeleteAll();
// Get an array of all keys
CScriptArray *GetKeys() const;
// Garbage collections behaviours
int GetRefCount();
void SetGCFlag();
bool GetGCFlag();
void EnumReferences(asIScriptEngine *engine);
void ReleaseAllReferences(asIScriptEngine *engine);
protected:
// The structure for holding the values
struct valueStruct
{
union
{
asINT64 valueInt;
double valueFlt;
void *valueObj;
};
int typeId;
};
// We don't want anyone to call the destructor directly, it should be called through the Release method
virtual ~CScriptDictionary();
// Helper methods
void FreeValue(valueStruct &value);
// Our properties
asIScriptEngine *engine;
mutable int refCount;
mutable bool gcFlag;
// TODO: optimize: Use C++11 std::unordered_map instead
std::map<std::string, valueStruct> dict;
};
// This function will determine the configuration of the engine
// and use one of the two functions below to register the dictionary object
void RegisterScriptDictionary(asIScriptEngine *engine);
// Call this function to register the math functions
// using native calling conventions
void RegisterScriptDictionary_Native(asIScriptEngine *engine);
// Use this one instead if native calling conventions
// are not supported on the target platform
void RegisterScriptDictionary_Generic(asIScriptEngine *engine);
END_AS_NAMESPACE
#endif

View File

@ -1,337 +1,337 @@
#include "scripthandle.h"
#include <new>
#include <assert.h>
#include <string.h>
BEGIN_AS_NAMESPACE
static void Construct(CScriptHandle *self) { new(self) CScriptHandle(); }
static void Construct(CScriptHandle *self, const CScriptHandle &o) { new(self) CScriptHandle(o); }
// This one is not static because it needs to be friend with the CScriptHandle class
void Construct(CScriptHandle *self, void *ref, int typeId) { new(self) CScriptHandle(ref, typeId); }
static void Destruct(CScriptHandle *self) { self->~CScriptHandle(); }
CScriptHandle::CScriptHandle()
{
m_ref = 0;
m_type = 0;
}
CScriptHandle::CScriptHandle(const CScriptHandle &other)
{
m_ref = other.m_ref;
m_type = other.m_type;
AddRefHandle();
}
CScriptHandle::CScriptHandle(void *ref, asIObjectType *type)
{
m_ref = ref;
m_type = type;
AddRefHandle();
}
// This constructor shouldn't be called from the application
// directly as it requires an active script context
CScriptHandle::CScriptHandle(void *ref, int typeId)
{
m_ref = 0;
m_type = 0;
Assign(ref, typeId);
}
CScriptHandle::~CScriptHandle()
{
ReleaseHandle();
}
void CScriptHandle::ReleaseHandle()
{
if( m_ref && m_type )
{
asIScriptEngine *engine = m_type->GetEngine();
engine->ReleaseScriptObject(m_ref, m_type);
m_ref = 0;
m_type = 0;
}
}
void CScriptHandle::AddRefHandle()
{
if( m_ref && m_type )
{
asIScriptEngine *engine = m_type->GetEngine();
engine->AddRefScriptObject(m_ref, m_type);
}
}
CScriptHandle &CScriptHandle::operator =(const CScriptHandle &other)
{
// Don't do anything if it is the same reference
if( m_ref == other.m_ref )
return *this;
ReleaseHandle();
m_ref = other.m_ref;
m_type = other.m_type;
AddRefHandle();
return *this;
}
void CScriptHandle::Set(void *ref, asIObjectType *type)
{
if( m_ref == ref ) return;
ReleaseHandle();
m_ref = ref;
m_type = type;
AddRefHandle();
}
asIObjectType *CScriptHandle::GetType()
{
return m_type;
}
// This method shouldn't be called from the application
// directly as it requires an active script context
CScriptHandle &CScriptHandle::Assign(void *ref, int typeId)
{
// When receiving a null handle we just clear our memory
if( typeId == 0 )
{
Set(0, 0);
return *this;
}
// Dereference received handles to get the object
if( typeId & asTYPEID_OBJHANDLE )
{
// Store the actual reference
ref = *(void**)ref;
typeId &= ~asTYPEID_OBJHANDLE;
}
// Get the object type
asIScriptContext *ctx = asGetActiveContext();
asIScriptEngine *engine = ctx->GetEngine();
asIObjectType *type = engine->GetObjectTypeById(typeId);
Set(ref, type);
return *this;
}
bool CScriptHandle::operator==(const CScriptHandle &o) const
{
if( m_ref == o.m_ref &&
m_type == o.m_type )
return true;
// TODO: If type is not the same, we should attempt to do a dynamic cast,
// which may change the pointer for application registered classes
return false;
}
bool CScriptHandle::operator!=(const CScriptHandle &o) const
{
return !(*this == o);
}
bool CScriptHandle::Equals(void *ref, int typeId) const
{
// Null handles are received as reference to a null handle
if( typeId == 0 )
ref = 0;
// Dereference handles to get the object
if( typeId & asTYPEID_OBJHANDLE )
{
// Compare the actual reference
ref = *(void**)ref;
typeId &= ~asTYPEID_OBJHANDLE;
}
// TODO: If typeId is not the same, we should attempt to do a dynamic cast,
// which may change the pointer for application registered classes
if( ref == m_ref ) return true;
return false;
}
// AngelScript: used as '@obj = cast<obj>(ref);'
void CScriptHandle::Cast(void **outRef, int typeId)
{
// If we hold a null handle, then just return null
if( m_type == 0 )
{
*outRef = 0;
return;
}
// It is expected that the outRef is always a handle
assert( typeId & asTYPEID_OBJHANDLE );
// Compare the type id of the actual object
typeId &= ~asTYPEID_OBJHANDLE;
asIScriptEngine *engine = m_type->GetEngine();
asIObjectType *type = engine->GetObjectTypeById(typeId);
*outRef = 0;
if( type == m_type )
{
// If the requested type is a script function it is
// necessary to check if the functions are compatible too
if( m_type->GetFlags() & asOBJ_SCRIPT_FUNCTION )
{
asIScriptFunction *func = reinterpret_cast<asIScriptFunction*>(m_ref);
if( !func->IsCompatibleWithTypeId(typeId) )
return;
}
// Must increase the ref count as we're returning a new reference to the object
AddRefHandle();
*outRef = m_ref;
}
else if( m_type->GetFlags() & asOBJ_SCRIPT_OBJECT )
{
// Attempt a dynamic cast of the stored handle to the requested handle type
if( engine->IsHandleCompatibleWithObject(m_ref, m_type->GetTypeId(), typeId) )
{
// The script type is compatible so we can simply return the same pointer
AddRefHandle();
*outRef = m_ref;
}
}
else
{
// TODO: Check for the existance of a reference cast behaviour.
// Both implicit and explicit casts may be used
// Calling the reference cast behaviour may change the actual
// pointer so the AddRef must be called on the new pointer
}
}
void RegisterScriptHandle_Native(asIScriptEngine *engine)
{
int r;
r = engine->RegisterObjectType("ref", sizeof(CScriptHandle), asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ_APP_CLASS_CDAK); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(Construct, (CScriptHandle *), void), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f(const ref &in)", asFUNCTIONPR(Construct, (CScriptHandle *, const CScriptHandle &), void), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f(const ?&in)", asFUNCTIONPR(Construct, (CScriptHandle *, void *, int), void), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_DESTRUCT, "void f()", asFUNCTIONPR(Destruct, (CScriptHandle *), void), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_REF_CAST, "void f(?&out)", asMETHODPR(CScriptHandle, Cast, (void **, int), void), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "ref &opAssign(const ref &in)", asMETHOD(CScriptHandle, operator=), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "ref &opAssign(const ?&in)", asMETHOD(CScriptHandle, Assign), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ref &in) const", asMETHODPR(CScriptHandle, operator==, (const CScriptHandle &) const, bool), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ?&in) const", asMETHODPR(CScriptHandle, Equals, (void*, int) const, bool), asCALL_THISCALL); assert( r >= 0 );
}
void CScriptHandle_Construct_Generic(asIScriptGeneric *gen)
{
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
new(self) CScriptHandle();
}
void CScriptHandle_ConstructCopy_Generic(asIScriptGeneric *gen)
{
CScriptHandle *other = reinterpret_cast<CScriptHandle*>(gen->GetArgAddress(0));
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
new(self) CScriptHandle(*other);
}
void CScriptHandle_ConstructVar_Generic(asIScriptGeneric *gen)
{
void *ref = gen->GetArgAddress(0);
int typeId = gen->GetArgTypeId(0);
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
Construct(self, ref, typeId);
}
void CScriptHandle_Destruct_Generic(asIScriptGeneric *gen)
{
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
self->~CScriptHandle();
}
void CScriptHandle_Cast_Generic(asIScriptGeneric *gen)
{
void **ref = reinterpret_cast<void**>(gen->GetArgAddress(0));
int typeId = gen->GetArgTypeId(0);
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
self->Cast(ref, typeId);
}
void CScriptHandle_Assign_Generic(asIScriptGeneric *gen)
{
CScriptHandle *other = reinterpret_cast<CScriptHandle*>(gen->GetArgAddress(0));
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
*self = *other;
gen->SetReturnAddress(self);
}
void CScriptHandle_AssignVar_Generic(asIScriptGeneric *gen)
{
void *ref = gen->GetArgAddress(0);
int typeId = gen->GetArgTypeId(0);
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
self->Assign(ref, typeId);
gen->SetReturnAddress(self);
}
void CScriptHandle_Equals_Generic(asIScriptGeneric *gen)
{
CScriptHandle *other = reinterpret_cast<CScriptHandle*>(gen->GetArgAddress(0));
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
gen->SetReturnByte(*self == *other);
}
void CScriptHandle_EqualsVar_Generic(asIScriptGeneric *gen)
{
void *ref = gen->GetArgAddress(0);
int typeId = gen->GetArgTypeId(0);
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
gen->SetReturnByte(self->Equals(ref, typeId));
}
void RegisterScriptHandle_Generic(asIScriptEngine *engine)
{
int r;
r = engine->RegisterObjectType("ref", sizeof(CScriptHandle), asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ_APP_CLASS_CDAK); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(CScriptHandle_Construct_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f(const ref &in)", asFUNCTION(CScriptHandle_ConstructCopy_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f(const ?&in)", asFUNCTION(CScriptHandle_ConstructVar_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(CScriptHandle_Destruct_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_REF_CAST, "void f(?&out)", asFUNCTION(CScriptHandle_Cast_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "ref &opAssign(const ref &in)", asFUNCTION(CScriptHandle_Assign_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "ref &opAssign(const ?&in)", asFUNCTION(CScriptHandle_AssignVar_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ref &in) const", asFUNCTION(CScriptHandle_Equals_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ?&in) const", asFUNCTION(CScriptHandle_EqualsVar_Generic), asCALL_GENERIC); assert( r >= 0 );
}
void RegisterScriptHandle(asIScriptEngine *engine)
{
if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") )
RegisterScriptHandle_Generic(engine);
else
RegisterScriptHandle_Native(engine);
}
END_AS_NAMESPACE
#include "scripthandle.h"
#include <new>
#include <assert.h>
#include <string.h>
BEGIN_AS_NAMESPACE
static void Construct(CScriptHandle *self) { new(self) CScriptHandle(); }
static void Construct(CScriptHandle *self, const CScriptHandle &o) { new(self) CScriptHandle(o); }
// This one is not static because it needs to be friend with the CScriptHandle class
void Construct(CScriptHandle *self, void *ref, int typeId) { new(self) CScriptHandle(ref, typeId); }
static void Destruct(CScriptHandle *self) { self->~CScriptHandle(); }
CScriptHandle::CScriptHandle()
{
m_ref = 0;
m_type = 0;
}
CScriptHandle::CScriptHandle(const CScriptHandle &other)
{
m_ref = other.m_ref;
m_type = other.m_type;
AddRefHandle();
}
CScriptHandle::CScriptHandle(void *ref, asIObjectType *type)
{
m_ref = ref;
m_type = type;
AddRefHandle();
}
// This constructor shouldn't be called from the application
// directly as it requires an active script context
CScriptHandle::CScriptHandle(void *ref, int typeId)
{
m_ref = 0;
m_type = 0;
Assign(ref, typeId);
}
CScriptHandle::~CScriptHandle()
{
ReleaseHandle();
}
void CScriptHandle::ReleaseHandle()
{
if( m_ref && m_type )
{
asIScriptEngine *engine = m_type->GetEngine();
engine->ReleaseScriptObject(m_ref, m_type);
m_ref = 0;
m_type = 0;
}
}
void CScriptHandle::AddRefHandle()
{
if( m_ref && m_type )
{
asIScriptEngine *engine = m_type->GetEngine();
engine->AddRefScriptObject(m_ref, m_type);
}
}
CScriptHandle &CScriptHandle::operator =(const CScriptHandle &other)
{
// Don't do anything if it is the same reference
if( m_ref == other.m_ref )
return *this;
ReleaseHandle();
m_ref = other.m_ref;
m_type = other.m_type;
AddRefHandle();
return *this;
}
void CScriptHandle::Set(void *ref, asIObjectType *type)
{
if( m_ref == ref ) return;
ReleaseHandle();
m_ref = ref;
m_type = type;
AddRefHandle();
}
asIObjectType *CScriptHandle::GetType()
{
return m_type;
}
// This method shouldn't be called from the application
// directly as it requires an active script context
CScriptHandle &CScriptHandle::Assign(void *ref, int typeId)
{
// When receiving a null handle we just clear our memory
if( typeId == 0 )
{
Set(0, 0);
return *this;
}
// Dereference received handles to get the object
if( typeId & asTYPEID_OBJHANDLE )
{
// Store the actual reference
ref = *(void**)ref;
typeId &= ~asTYPEID_OBJHANDLE;
}
// Get the object type
asIScriptContext *ctx = asGetActiveContext();
asIScriptEngine *engine = ctx->GetEngine();
asIObjectType *type = engine->GetObjectTypeById(typeId);
Set(ref, type);
return *this;
}
bool CScriptHandle::operator==(const CScriptHandle &o) const
{
if( m_ref == o.m_ref &&
m_type == o.m_type )
return true;
// TODO: If type is not the same, we should attempt to do a dynamic cast,
// which may change the pointer for application registered classes
return false;
}
bool CScriptHandle::operator!=(const CScriptHandle &o) const
{
return !(*this == o);
}
bool CScriptHandle::Equals(void *ref, int typeId) const
{
// Null handles are received as reference to a null handle
if( typeId == 0 )
ref = 0;
// Dereference handles to get the object
if( typeId & asTYPEID_OBJHANDLE )
{
// Compare the actual reference
ref = *(void**)ref;
typeId &= ~asTYPEID_OBJHANDLE;
}
// TODO: If typeId is not the same, we should attempt to do a dynamic cast,
// which may change the pointer for application registered classes
if( ref == m_ref ) return true;
return false;
}
// AngelScript: used as '@obj = cast<obj>(ref);'
void CScriptHandle::Cast(void **outRef, int typeId)
{
// If we hold a null handle, then just return null
if( m_type == 0 )
{
*outRef = 0;
return;
}
// It is expected that the outRef is always a handle
assert( typeId & asTYPEID_OBJHANDLE );
// Compare the type id of the actual object
typeId &= ~asTYPEID_OBJHANDLE;
asIScriptEngine *engine = m_type->GetEngine();
asIObjectType *type = engine->GetObjectTypeById(typeId);
*outRef = 0;
if( type == m_type )
{
// If the requested type is a script function it is
// necessary to check if the functions are compatible too
if( m_type->GetFlags() & asOBJ_SCRIPT_FUNCTION )
{
asIScriptFunction *func = reinterpret_cast<asIScriptFunction*>(m_ref);
if( !func->IsCompatibleWithTypeId(typeId) )
return;
}
// Must increase the ref count as we're returning a new reference to the object
AddRefHandle();
*outRef = m_ref;
}
else if( m_type->GetFlags() & asOBJ_SCRIPT_OBJECT )
{
// Attempt a dynamic cast of the stored handle to the requested handle type
if( engine->IsHandleCompatibleWithObject(m_ref, m_type->GetTypeId(), typeId) )
{
// The script type is compatible so we can simply return the same pointer
AddRefHandle();
*outRef = m_ref;
}
}
else
{
// TODO: Check for the existance of a reference cast behaviour.
// Both implicit and explicit casts may be used
// Calling the reference cast behaviour may change the actual
// pointer so the AddRef must be called on the new pointer
}
}
void RegisterScriptHandle_Native(asIScriptEngine *engine)
{
int r;
r = engine->RegisterObjectType("ref", sizeof(CScriptHandle), asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ_APP_CLASS_CDAK); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(Construct, (CScriptHandle *), void), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f(const ref &in)", asFUNCTIONPR(Construct, (CScriptHandle *, const CScriptHandle &), void), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f(const ?&in)", asFUNCTIONPR(Construct, (CScriptHandle *, void *, int), void), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_DESTRUCT, "void f()", asFUNCTIONPR(Destruct, (CScriptHandle *), void), asCALL_CDECL_OBJFIRST); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_REF_CAST, "void f(?&out)", asMETHODPR(CScriptHandle, Cast, (void **, int), void), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "ref &opAssign(const ref &in)", asMETHOD(CScriptHandle, operator=), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "ref &opAssign(const ?&in)", asMETHOD(CScriptHandle, Assign), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ref &in) const", asMETHODPR(CScriptHandle, operator==, (const CScriptHandle &) const, bool), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ?&in) const", asMETHODPR(CScriptHandle, Equals, (void*, int) const, bool), asCALL_THISCALL); assert( r >= 0 );
}
void CScriptHandle_Construct_Generic(asIScriptGeneric *gen)
{
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
new(self) CScriptHandle();
}
void CScriptHandle_ConstructCopy_Generic(asIScriptGeneric *gen)
{
CScriptHandle *other = reinterpret_cast<CScriptHandle*>(gen->GetArgAddress(0));
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
new(self) CScriptHandle(*other);
}
void CScriptHandle_ConstructVar_Generic(asIScriptGeneric *gen)
{
void *ref = gen->GetArgAddress(0);
int typeId = gen->GetArgTypeId(0);
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
Construct(self, ref, typeId);
}
void CScriptHandle_Destruct_Generic(asIScriptGeneric *gen)
{
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
self->~CScriptHandle();
}
void CScriptHandle_Cast_Generic(asIScriptGeneric *gen)
{
void **ref = reinterpret_cast<void**>(gen->GetArgAddress(0));
int typeId = gen->GetArgTypeId(0);
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
self->Cast(ref, typeId);
}
void CScriptHandle_Assign_Generic(asIScriptGeneric *gen)
{
CScriptHandle *other = reinterpret_cast<CScriptHandle*>(gen->GetArgAddress(0));
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
*self = *other;
gen->SetReturnAddress(self);
}
void CScriptHandle_AssignVar_Generic(asIScriptGeneric *gen)
{
void *ref = gen->GetArgAddress(0);
int typeId = gen->GetArgTypeId(0);
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
self->Assign(ref, typeId);
gen->SetReturnAddress(self);
}
void CScriptHandle_Equals_Generic(asIScriptGeneric *gen)
{
CScriptHandle *other = reinterpret_cast<CScriptHandle*>(gen->GetArgAddress(0));
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
gen->SetReturnByte(*self == *other);
}
void CScriptHandle_EqualsVar_Generic(asIScriptGeneric *gen)
{
void *ref = gen->GetArgAddress(0);
int typeId = gen->GetArgTypeId(0);
CScriptHandle *self = reinterpret_cast<CScriptHandle*>(gen->GetObject());
gen->SetReturnByte(self->Equals(ref, typeId));
}
void RegisterScriptHandle_Generic(asIScriptEngine *engine)
{
int r;
r = engine->RegisterObjectType("ref", sizeof(CScriptHandle), asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ_APP_CLASS_CDAK); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(CScriptHandle_Construct_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f(const ref &in)", asFUNCTION(CScriptHandle_ConstructCopy_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_CONSTRUCT, "void f(const ?&in)", asFUNCTION(CScriptHandle_ConstructVar_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(CScriptHandle_Destruct_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectBehaviour("ref", asBEHAVE_REF_CAST, "void f(?&out)", asFUNCTION(CScriptHandle_Cast_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "ref &opAssign(const ref &in)", asFUNCTION(CScriptHandle_Assign_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "ref &opAssign(const ?&in)", asFUNCTION(CScriptHandle_AssignVar_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ref &in) const", asFUNCTION(CScriptHandle_Equals_Generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterObjectMethod("ref", "bool opEquals(const ?&in) const", asFUNCTION(CScriptHandle_EqualsVar_Generic), asCALL_GENERIC); assert( r >= 0 );
}
void RegisterScriptHandle(asIScriptEngine *engine)
{
if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") )
RegisterScriptHandle_Generic(engine);
else
RegisterScriptHandle_Native(engine);
}
END_AS_NAMESPACE

View File

@ -1,61 +1,61 @@
#ifndef SCRIPTHANDLE_H
#define SCRIPTHANDLE_H
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
BEGIN_AS_NAMESPACE
class CScriptHandle
{
public:
// Constructors
CScriptHandle();
CScriptHandle(const CScriptHandle &other);
CScriptHandle(void *ref, asIObjectType *type);
~CScriptHandle();
// Copy the stored value from another any object
CScriptHandle &operator=(const CScriptHandle &other);
// Set the reference
void Set(void *ref, asIObjectType *type);
// Compare equalness
bool operator==(const CScriptHandle &o) const;
bool operator!=(const CScriptHandle &o) const;
bool Equals(void *ref, int typeId) const;
// Dynamic cast to desired handle type
void Cast(void **outRef, int typeId);
// Returns the type of the reference held
asIObjectType *GetType();
protected:
// These functions need to have access to protected
// members in order to call them from the script engine
friend void Construct(CScriptHandle *self, void *ref, int typeId);
friend void RegisterScriptHandle_Native(asIScriptEngine *engine);
friend void CScriptHandle_AssignVar_Generic(asIScriptGeneric *gen);
void ReleaseHandle();
void AddRefHandle();
// These shouldn't be called directly by the
// application as they requires an active context
CScriptHandle(void *ref, int typeId);
CScriptHandle &Assign(void *ref, int typeId);
void *m_ref;
asIObjectType *m_type;
};
void RegisterScriptHandle(asIScriptEngine *engine);
END_AS_NAMESPACE
#endif
#ifndef SCRIPTHANDLE_H
#define SCRIPTHANDLE_H
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
BEGIN_AS_NAMESPACE
class CScriptHandle
{
public:
// Constructors
CScriptHandle();
CScriptHandle(const CScriptHandle &other);
CScriptHandle(void *ref, asIObjectType *type);
~CScriptHandle();
// Copy the stored value from another any object
CScriptHandle &operator=(const CScriptHandle &other);
// Set the reference
void Set(void *ref, asIObjectType *type);
// Compare equalness
bool operator==(const CScriptHandle &o) const;
bool operator!=(const CScriptHandle &o) const;
bool Equals(void *ref, int typeId) const;
// Dynamic cast to desired handle type
void Cast(void **outRef, int typeId);
// Returns the type of the reference held
asIObjectType *GetType();
protected:
// These functions need to have access to protected
// members in order to call them from the script engine
friend void Construct(CScriptHandle *self, void *ref, int typeId);
friend void RegisterScriptHandle_Native(asIScriptEngine *engine);
friend void CScriptHandle_AssignVar_Generic(asIScriptGeneric *gen);
void ReleaseHandle();
void AddRefHandle();
// These shouldn't be called directly by the
// application as they requires an active context
CScriptHandle(void *ref, int typeId);
CScriptHandle &Assign(void *ref, int typeId);
void *m_ref;
asIObjectType *m_type;
};
void RegisterScriptHandle(asIScriptEngine *engine);
END_AS_NAMESPACE
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,79 +1,79 @@
#ifndef SCRIPTHELPER_H
#define SCRIPTHELPER_H
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
BEGIN_AS_NAMESPACE
// Compare relation between two objects of the same type
int CompareRelation(asIScriptEngine *engine, void *lobj, void *robj, int typeId, int &result);
// Compare equality between two objects of the same type
int CompareEquality(asIScriptEngine *engine, void *lobj, void *robj, int typeId, bool &result);
// Compile and execute simple statements
// The module is optional. If given the statements can access the entities compiled in the module.
// The caller can optionally provide its own context, for example if a context should be reused.
int ExecuteString(asIScriptEngine *engine, const char *code, asIScriptModule *mod = 0, asIScriptContext *ctx = 0);
// Compile and execute simple statements with option of return value
// The module is optional. If given the statements can access the entitites compiled in the module.
// The caller can optionally provide its own context, for example if a context should be reused.
int ExecuteString(asIScriptEngine *engine, const char *code, void *ret, int retTypeId, asIScriptModule *mod = 0, asIScriptContext *ctx = 0);
// Write the registered application interface to a file for an offline compiler.
// The format is compatible with the offline compiler in /sdk/samples/asbuild/.
int WriteConfigToFile(asIScriptEngine *engine, const char *filename);
// Print details of the script exception to the standard output
void PrintException(asIScriptContext *ctx, bool printStack = false);
// Determine traits of a type for registration of value types
// Relies on C++11 features so it can not be used with non-compliant compilers
#if !defined(_MSC_VER) || _MSC_VER >= 1700 // MSVC 2012
#if !defined(__GNUC__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) // gnuc 4.7
END_AS_NAMESPACE
#include <type_traits>
BEGIN_AS_NAMESPACE
template<typename T>
asUINT GetTypeTraits()
{
bool hasConstructor = std::is_default_constructible<T>::value && !std::has_trivial_default_constructor<T>::value;
#if defined(__GNUC__) && __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
// http://stackoverflow.com/questions/12702103/writing-code-that-works-when-has-trivial-destructor-is-defined-instead-of-is
bool hasDestructor = std::is_destructible<T>::value && !std::is_trivially_destructible<T>::value;
#else
bool hasDestructor = std::is_destructible<T>::value && !std::has_trivial_destructor<T>::value;
#endif
bool hasAssignmentOperator = std::is_copy_assignable<T>::value && !std::has_trivial_copy_assign<T>::value;
bool hasCopyConstructor = std::is_copy_constructible<T>::value && !std::has_trivial_copy_constructor<T>::value;
bool isFloat = std::is_floating_point<T>::value;
bool isPrimitive = std::is_integral<T>::value || std::is_pointer<T>::value || std::is_enum<T>::value;
if( isFloat )
return asOBJ_APP_FLOAT;
if( isPrimitive )
return asOBJ_APP_PRIMITIVE;
asDWORD flags = asOBJ_APP_CLASS;
if( hasConstructor )
flags |= asOBJ_APP_CLASS_CONSTRUCTOR;
if( hasDestructor )
flags |= asOBJ_APP_CLASS_DESTRUCTOR;
if( hasAssignmentOperator )
flags |= asOBJ_APP_CLASS_ASSIGNMENT;
if( hasCopyConstructor )
flags |= asOBJ_APP_CLASS_COPY_CONSTRUCTOR;
return flags;
}
#endif // gnuc 4.7
#endif // msvc 2012
END_AS_NAMESPACE
#endif
#ifndef SCRIPTHELPER_H
#define SCRIPTHELPER_H
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
BEGIN_AS_NAMESPACE
// Compare relation between two objects of the same type
int CompareRelation(asIScriptEngine *engine, void *lobj, void *robj, int typeId, int &result);
// Compare equality between two objects of the same type
int CompareEquality(asIScriptEngine *engine, void *lobj, void *robj, int typeId, bool &result);
// Compile and execute simple statements
// The module is optional. If given the statements can access the entities compiled in the module.
// The caller can optionally provide its own context, for example if a context should be reused.
int ExecuteString(asIScriptEngine *engine, const char *code, asIScriptModule *mod = 0, asIScriptContext *ctx = 0);
// Compile and execute simple statements with option of return value
// The module is optional. If given the statements can access the entitites compiled in the module.
// The caller can optionally provide its own context, for example if a context should be reused.
int ExecuteString(asIScriptEngine *engine, const char *code, void *ret, int retTypeId, asIScriptModule *mod = 0, asIScriptContext *ctx = 0);
// Write the registered application interface to a file for an offline compiler.
// The format is compatible with the offline compiler in /sdk/samples/asbuild/.
int WriteConfigToFile(asIScriptEngine *engine, const char *filename);
// Print details of the script exception to the standard output
void PrintException(asIScriptContext *ctx, bool printStack = false);
// Determine traits of a type for registration of value types
// Relies on C++11 features so it can not be used with non-compliant compilers
#if !defined(_MSC_VER) || _MSC_VER >= 1700 // MSVC 2012
#if !defined(__GNUC__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) // gnuc 4.7
END_AS_NAMESPACE
#include <type_traits>
BEGIN_AS_NAMESPACE
template<typename T>
asUINT GetTypeTraits()
{
bool hasConstructor = std::is_default_constructible<T>::value && !std::has_trivial_default_constructor<T>::value;
#if defined(__GNUC__) && __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
// http://stackoverflow.com/questions/12702103/writing-code-that-works-when-has-trivial-destructor-is-defined-instead-of-is
bool hasDestructor = std::is_destructible<T>::value && !std::is_trivially_destructible<T>::value;
#else
bool hasDestructor = std::is_destructible<T>::value && !std::has_trivial_destructor<T>::value;
#endif
bool hasAssignmentOperator = std::is_copy_assignable<T>::value && !std::has_trivial_copy_assign<T>::value;
bool hasCopyConstructor = std::is_copy_constructible<T>::value && !std::has_trivial_copy_constructor<T>::value;
bool isFloat = std::is_floating_point<T>::value;
bool isPrimitive = std::is_integral<T>::value || std::is_pointer<T>::value || std::is_enum<T>::value;
if( isFloat )
return asOBJ_APP_FLOAT;
if( isPrimitive )
return asOBJ_APP_PRIMITIVE;
asDWORD flags = asOBJ_APP_CLASS;
if( hasConstructor )
flags |= asOBJ_APP_CLASS_CONSTRUCTOR;
if( hasDestructor )
flags |= asOBJ_APP_CLASS_DESTRUCTOR;
if( hasAssignmentOperator )
flags |= asOBJ_APP_CLASS_ASSIGNMENT;
if( hasCopyConstructor )
flags |= asOBJ_APP_CLASS_COPY_CONSTRUCTOR;
return flags;
}
#endif // gnuc 4.7
#endif // msvc 2012
END_AS_NAMESPACE
#endif

View File

@ -1,307 +1,307 @@
#include <assert.h>
#include <math.h>
#include <string.h>
#include "scriptmath.h"
#ifdef __BORLANDC__
#include <cmath>
// The C++Builder RTL doesn't pull the *f functions into the global namespace per default.
using namespace std;
#if __BORLANDC__ < 0x580
// C++Builder 6 and earlier don't come with any *f variants of the math functions at all.
inline float cosf (float arg) { return std::cos (arg); }
inline float sinf (float arg) { return std::sin (arg); }
inline float tanf (float arg) { return std::tan (arg); }
inline float atan2f (float y, float x) { return std::atan2 (y, x); }
inline float logf (float arg) { return std::log (arg); }
inline float powf (float x, float y) { return std::pow (x, y); }
inline float sqrtf (float arg) { return std::sqrt (arg); }
#endif
// C++Builder doesn't define most of the non-standard float-specific math functions with
// "*f" suffix; instead it provides overloads for the standard math functions which take
// "float" arguments.
inline float acosf (float arg) { return std::acos (arg); }
inline float asinf (float arg) { return std::asin (arg); }
inline float atanf (float arg) { return std::atan (arg); }
inline float coshf (float arg) { return std::cosh (arg); }
inline float sinhf (float arg) { return std::sinh (arg); }
inline float tanhf (float arg) { return std::tanh (arg); }
inline float log10f (float arg) { return std::log10 (arg); }
inline float ceilf (float arg) { return std::ceil (arg); }
inline float fabsf (float arg) { return std::fabs (arg); }
inline float floorf (float arg) { return std::floor (arg); }
// C++Builder doesn't define a non-standard "modff" function but rather an overload of "modf"
// for float arguments. However, BCC's float overload of fmod() is broken (QC #74816; fixed
// in C++Builder 2010).
inline float modff (float x, float *y)
{
double d;
float f = (float) modf((double) x, &d);
*y = (float) d;
return f;
}
#endif
BEGIN_AS_NAMESPACE
// Determine whether the float version should be registered, or the double version
#ifndef AS_USE_FLOAT
#if !defined(_WIN32_WCE) // WinCE doesn't have the float versions of the math functions
#define AS_USE_FLOAT 1
#endif
#endif
// The modf function doesn't seem very intuitive, so I'm writing this
// function that simply returns the fractional part of the float value
#if AS_USE_FLOAT
float fractionf(float v)
{
float intPart;
return modff(v, &intPart);
}
#else
double fraction(double v)
{
double intPart;
return modf(v, &intPart);
}
#endif
// As AngelScript doesn't allow bitwise manipulation of float types we'll provide a couple of
// functions for converting float values to IEEE 754 formatted values etc. This also allow us to
// provide a platform agnostic representation to the script so the scripts don't have to worry
// about whether the CPU uses IEEE 754 floats or some other representation
float fpFromIEEE(asUINT raw)
{
// TODO: Identify CPU family to provide proper conversion
// if the CPU doesn't natively use IEEE style floats
return *reinterpret_cast<float*>(&raw);
}
asUINT fpToIEEE(float fp)
{
return *reinterpret_cast<asUINT*>(&fp);
}
double fpFromIEEE(asQWORD raw)
{
return *reinterpret_cast<double*>(&raw);
}
asQWORD fpToIEEE(double fp)
{
return *reinterpret_cast<asQWORD*>(&fp);
}
void RegisterScriptMath_Native(asIScriptEngine *engine)
{
int r;
// Conversion between floating point and IEEE bits representations
r = engine->RegisterGlobalFunction("float fpFromIEEE(uint)", asFUNCTIONPR(fpFromIEEE, (asUINT), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("uint fpToIEEE(float)", asFUNCTIONPR(fpToIEEE, (float), asUINT), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double fpFromIEEE(uint64)", asFUNCTIONPR(fpFromIEEE, (asQWORD), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("uint64 fpToIEEE(double)", asFUNCTIONPR(fpToIEEE, (double), asQWORD), asCALL_CDECL); assert( r >= 0 );
#if AS_USE_FLOAT
// Trigonometric functions
r = engine->RegisterGlobalFunction("float cos(float)", asFUNCTIONPR(cosf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float sin(float)", asFUNCTIONPR(sinf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float tan(float)", asFUNCTIONPR(tanf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float acos(float)", asFUNCTIONPR(acosf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float asin(float)", asFUNCTIONPR(asinf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float atan(float)", asFUNCTIONPR(atanf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float atan2(float,float)", asFUNCTIONPR(atan2f, (float, float), float), asCALL_CDECL); assert( r >= 0 );
// Hyberbolic functions
r = engine->RegisterGlobalFunction("float cosh(float)", asFUNCTIONPR(coshf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float sinh(float)", asFUNCTIONPR(sinhf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float tanh(float)", asFUNCTIONPR(tanhf, (float), float), asCALL_CDECL); assert( r >= 0 );
// Exponential and logarithmic functions
r = engine->RegisterGlobalFunction("float log(float)", asFUNCTIONPR(logf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float log10(float)", asFUNCTIONPR(log10f, (float), float), asCALL_CDECL); assert( r >= 0 );
// Power functions
r = engine->RegisterGlobalFunction("float pow(float, float)", asFUNCTIONPR(powf, (float, float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float sqrt(float)", asFUNCTIONPR(sqrtf, (float), float), asCALL_CDECL); assert( r >= 0 );
// Nearest integer, absolute value, and remainder functions
r = engine->RegisterGlobalFunction("float ceil(float)", asFUNCTIONPR(ceilf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float abs(float)", asFUNCTIONPR(fabsf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float floor(float)", asFUNCTIONPR(floorf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float fraction(float)", asFUNCTIONPR(fractionf, (float), float), asCALL_CDECL); assert( r >= 0 );
// Don't register modf because AngelScript already supports the % operator
#else
// double versions of the same
r = engine->RegisterGlobalFunction("double cos(double)", asFUNCTIONPR(cos, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sin(double)", asFUNCTIONPR(sin, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double tan(double)", asFUNCTIONPR(tan, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double acos(double)", asFUNCTIONPR(acos, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double asin(double)", asFUNCTIONPR(asin, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double atan(double)", asFUNCTIONPR(atan, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double atan2(double,double)", asFUNCTIONPR(atan2, (double, double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double cosh(double)", asFUNCTIONPR(cosh, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sinh(double)", asFUNCTIONPR(sinh, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double tanh(double)", asFUNCTIONPR(tanh, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double log(double)", asFUNCTIONPR(log, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double log10(double)", asFUNCTIONPR(log10, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double pow(double, double)", asFUNCTIONPR(pow, (double, double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sqrt(double)", asFUNCTIONPR(sqrt, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double ceil(double)", asFUNCTIONPR(ceil, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double abs(double)", asFUNCTIONPR(fabs, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double floor(double)", asFUNCTIONPR(floor, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double fraction(double)", asFUNCTIONPR(fraction, (double), double), asCALL_CDECL); assert( r >= 0 );
#endif
}
#if AS_USE_FLOAT
// This macro creates simple generic wrappers for functions of type 'float func(float)'
#define GENERICff(x) \
void x##_generic(asIScriptGeneric *gen) \
{ \
float f = *(float*)gen->GetAddressOfArg(0); \
*(float*)gen->GetAddressOfReturnLocation() = x(f); \
}
GENERICff(cosf)
GENERICff(sinf)
GENERICff(tanf)
GENERICff(acosf)
GENERICff(asinf)
GENERICff(atanf)
GENERICff(coshf)
GENERICff(sinhf)
GENERICff(tanhf)
GENERICff(logf)
GENERICff(log10f)
GENERICff(sqrtf)
GENERICff(ceilf)
GENERICff(fabsf)
GENERICff(floorf)
GENERICff(fractionf)
void powf_generic(asIScriptGeneric *gen)
{
float f1 = *(float*)gen->GetAddressOfArg(0);
float f2 = *(float*)gen->GetAddressOfArg(1);
*(float*)gen->GetAddressOfReturnLocation() = powf(f1, f2);
}
void atan2f_generic(asIScriptGeneric *gen)
{
float f1 = *(float*)gen->GetAddressOfArg(0);
float f2 = *(float*)gen->GetAddressOfArg(1);
*(float*)gen->GetAddressOfReturnLocation() = atan2f(f1, f2);
}
#else
// This macro creates simple generic wrappers for functions of type 'double func(double)'
#define GENERICdd(x) \
void x##_generic(asIScriptGeneric *gen) \
{ \
double f = *(double*)gen->GetAddressOfArg(0); \
*(double*)gen->GetAddressOfReturnLocation() = x(f); \
}
GENERICdd(cos)
GENERICdd(sin)
GENERICdd(tan)
GENERICdd(acos)
GENERICdd(asin)
GENERICdd(atan)
GENERICdd(cosh)
GENERICdd(sinh)
GENERICdd(tanh)
GENERICdd(log)
GENERICdd(log10)
GENERICdd(sqrt)
GENERICdd(ceil)
GENERICdd(fabs)
GENERICdd(floor)
GENERICdd(fraction)
void pow_generic(asIScriptGeneric *gen)
{
double f1 = *(double*)gen->GetAddressOfArg(0);
double f2 = *(double*)gen->GetAddressOfArg(1);
*(double*)gen->GetAddressOfReturnLocation() = pow(f1, f2);
}
void atan2_generic(asIScriptGeneric *gen)
{
double f1 = *(double*)gen->GetAddressOfArg(0);
double f2 = *(double*)gen->GetAddressOfArg(1);
*(double*)gen->GetAddressOfReturnLocation() = atan2(f1, f2);
}
#endif
void RegisterScriptMath_Generic(asIScriptEngine *engine)
{
int r;
#if AS_USE_FLOAT
// Trigonometric functions
r = engine->RegisterGlobalFunction("float cos(float)", asFUNCTION(cosf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float sin(float)", asFUNCTION(sinf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float tan(float)", asFUNCTION(tanf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float acos(float)", asFUNCTION(acosf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float asin(float)", asFUNCTION(asinf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float atan(float)", asFUNCTION(atanf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float atan2(float,float)", asFUNCTION(atan2f_generic), asCALL_GENERIC); assert( r >= 0 );
// Hyberbolic functions
r = engine->RegisterGlobalFunction("float cosh(float)", asFUNCTION(coshf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float sinh(float)", asFUNCTION(sinhf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float tanh(float)", asFUNCTION(tanhf_generic), asCALL_GENERIC); assert( r >= 0 );
// Exponential and logarithmic functions
r = engine->RegisterGlobalFunction("float log(float)", asFUNCTION(logf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float log10(float)", asFUNCTION(log10f_generic), asCALL_GENERIC); assert( r >= 0 );
// Power functions
r = engine->RegisterGlobalFunction("float pow(float, float)", asFUNCTION(powf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float sqrt(float)", asFUNCTION(sqrtf_generic), asCALL_GENERIC); assert( r >= 0 );
// Nearest integer, absolute value, and remainder functions
r = engine->RegisterGlobalFunction("float ceil(float)", asFUNCTION(ceilf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float abs(float)", asFUNCTION(fabsf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float floor(float)", asFUNCTION(floorf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float fraction(float)", asFUNCTION(fractionf_generic), asCALL_GENERIC); assert( r >= 0 );
// Don't register modf because AngelScript already supports the % operator
#else
// double versions of the same
r = engine->RegisterGlobalFunction("double cos(double)", asFUNCTION(cos_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sin(double)", asFUNCTION(sin_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double tan(double)", asFUNCTION(tan_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double acos(double)", asFUNCTION(acos_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double asin(double)", asFUNCTION(asin_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double atan(double)", asFUNCTION(atan_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double atan2(double,double)", asFUNCTION(atan2_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double cosh(double)", asFUNCTION(cosh_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sinh(double)", asFUNCTION(sinh_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double tanh(double)", asFUNCTION(tanh_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double log(double)", asFUNCTION(log_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double log10(double)", asFUNCTION(log10_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double pow(double, double)", asFUNCTION(pow_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sqrt(double)", asFUNCTION(sqrt_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double ceil(double)", asFUNCTION(ceil_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double abs(double)", asFUNCTION(fabs_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double floor(double)", asFUNCTION(floor_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double fraction(double)", asFUNCTION(fraction_generic), asCALL_GENERIC); assert( r >= 0 );
#endif
}
void RegisterScriptMath(asIScriptEngine *engine)
{
if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") )
RegisterScriptMath_Generic(engine);
else
RegisterScriptMath_Native(engine);
}
END_AS_NAMESPACE
#include <assert.h>
#include <math.h>
#include <string.h>
#include "scriptmath.h"
#ifdef __BORLANDC__
#include <cmath>
// The C++Builder RTL doesn't pull the *f functions into the global namespace per default.
using namespace std;
#if __BORLANDC__ < 0x580
// C++Builder 6 and earlier don't come with any *f variants of the math functions at all.
inline float cosf (float arg) { return std::cos (arg); }
inline float sinf (float arg) { return std::sin (arg); }
inline float tanf (float arg) { return std::tan (arg); }
inline float atan2f (float y, float x) { return std::atan2 (y, x); }
inline float logf (float arg) { return std::log (arg); }
inline float powf (float x, float y) { return std::pow (x, y); }
inline float sqrtf (float arg) { return std::sqrt (arg); }
#endif
// C++Builder doesn't define most of the non-standard float-specific math functions with
// "*f" suffix; instead it provides overloads for the standard math functions which take
// "float" arguments.
inline float acosf (float arg) { return std::acos (arg); }
inline float asinf (float arg) { return std::asin (arg); }
inline float atanf (float arg) { return std::atan (arg); }
inline float coshf (float arg) { return std::cosh (arg); }
inline float sinhf (float arg) { return std::sinh (arg); }
inline float tanhf (float arg) { return std::tanh (arg); }
inline float log10f (float arg) { return std::log10 (arg); }
inline float ceilf (float arg) { return std::ceil (arg); }
inline float fabsf (float arg) { return std::fabs (arg); }
inline float floorf (float arg) { return std::floor (arg); }
// C++Builder doesn't define a non-standard "modff" function but rather an overload of "modf"
// for float arguments. However, BCC's float overload of fmod() is broken (QC #74816; fixed
// in C++Builder 2010).
inline float modff (float x, float *y)
{
double d;
float f = (float) modf((double) x, &d);
*y = (float) d;
return f;
}
#endif
BEGIN_AS_NAMESPACE
// Determine whether the float version should be registered, or the double version
#ifndef AS_USE_FLOAT
#if !defined(_WIN32_WCE) // WinCE doesn't have the float versions of the math functions
#define AS_USE_FLOAT 1
#endif
#endif
// The modf function doesn't seem very intuitive, so I'm writing this
// function that simply returns the fractional part of the float value
#if AS_USE_FLOAT
float fractionf(float v)
{
float intPart;
return modff(v, &intPart);
}
#else
double fraction(double v)
{
double intPart;
return modf(v, &intPart);
}
#endif
// As AngelScript doesn't allow bitwise manipulation of float types we'll provide a couple of
// functions for converting float values to IEEE 754 formatted values etc. This also allow us to
// provide a platform agnostic representation to the script so the scripts don't have to worry
// about whether the CPU uses IEEE 754 floats or some other representation
float fpFromIEEE(asUINT raw)
{
// TODO: Identify CPU family to provide proper conversion
// if the CPU doesn't natively use IEEE style floats
return *reinterpret_cast<float*>(&raw);
}
asUINT fpToIEEE(float fp)
{
return *reinterpret_cast<asUINT*>(&fp);
}
double fpFromIEEE(asQWORD raw)
{
return *reinterpret_cast<double*>(&raw);
}
asQWORD fpToIEEE(double fp)
{
return *reinterpret_cast<asQWORD*>(&fp);
}
void RegisterScriptMath_Native(asIScriptEngine *engine)
{
int r;
// Conversion between floating point and IEEE bits representations
r = engine->RegisterGlobalFunction("float fpFromIEEE(uint)", asFUNCTIONPR(fpFromIEEE, (asUINT), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("uint fpToIEEE(float)", asFUNCTIONPR(fpToIEEE, (float), asUINT), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double fpFromIEEE(uint64)", asFUNCTIONPR(fpFromIEEE, (asQWORD), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("uint64 fpToIEEE(double)", asFUNCTIONPR(fpToIEEE, (double), asQWORD), asCALL_CDECL); assert( r >= 0 );
#if AS_USE_FLOAT
// Trigonometric functions
r = engine->RegisterGlobalFunction("float cos(float)", asFUNCTIONPR(cosf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float sin(float)", asFUNCTIONPR(sinf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float tan(float)", asFUNCTIONPR(tanf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float acos(float)", asFUNCTIONPR(acosf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float asin(float)", asFUNCTIONPR(asinf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float atan(float)", asFUNCTIONPR(atanf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float atan2(float,float)", asFUNCTIONPR(atan2f, (float, float), float), asCALL_CDECL); assert( r >= 0 );
// Hyberbolic functions
r = engine->RegisterGlobalFunction("float cosh(float)", asFUNCTIONPR(coshf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float sinh(float)", asFUNCTIONPR(sinhf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float tanh(float)", asFUNCTIONPR(tanhf, (float), float), asCALL_CDECL); assert( r >= 0 );
// Exponential and logarithmic functions
r = engine->RegisterGlobalFunction("float log(float)", asFUNCTIONPR(logf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float log10(float)", asFUNCTIONPR(log10f, (float), float), asCALL_CDECL); assert( r >= 0 );
// Power functions
r = engine->RegisterGlobalFunction("float pow(float, float)", asFUNCTIONPR(powf, (float, float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float sqrt(float)", asFUNCTIONPR(sqrtf, (float), float), asCALL_CDECL); assert( r >= 0 );
// Nearest integer, absolute value, and remainder functions
r = engine->RegisterGlobalFunction("float ceil(float)", asFUNCTIONPR(ceilf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float abs(float)", asFUNCTIONPR(fabsf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float floor(float)", asFUNCTIONPR(floorf, (float), float), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float fraction(float)", asFUNCTIONPR(fractionf, (float), float), asCALL_CDECL); assert( r >= 0 );
// Don't register modf because AngelScript already supports the % operator
#else
// double versions of the same
r = engine->RegisterGlobalFunction("double cos(double)", asFUNCTIONPR(cos, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sin(double)", asFUNCTIONPR(sin, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double tan(double)", asFUNCTIONPR(tan, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double acos(double)", asFUNCTIONPR(acos, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double asin(double)", asFUNCTIONPR(asin, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double atan(double)", asFUNCTIONPR(atan, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double atan2(double,double)", asFUNCTIONPR(atan2, (double, double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double cosh(double)", asFUNCTIONPR(cosh, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sinh(double)", asFUNCTIONPR(sinh, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double tanh(double)", asFUNCTIONPR(tanh, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double log(double)", asFUNCTIONPR(log, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double log10(double)", asFUNCTIONPR(log10, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double pow(double, double)", asFUNCTIONPR(pow, (double, double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sqrt(double)", asFUNCTIONPR(sqrt, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double ceil(double)", asFUNCTIONPR(ceil, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double abs(double)", asFUNCTIONPR(fabs, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double floor(double)", asFUNCTIONPR(floor, (double), double), asCALL_CDECL); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double fraction(double)", asFUNCTIONPR(fraction, (double), double), asCALL_CDECL); assert( r >= 0 );
#endif
}
#if AS_USE_FLOAT
// This macro creates simple generic wrappers for functions of type 'float func(float)'
#define GENERICff(x) \
void x##_generic(asIScriptGeneric *gen) \
{ \
float f = *(float*)gen->GetAddressOfArg(0); \
*(float*)gen->GetAddressOfReturnLocation() = x(f); \
}
GENERICff(cosf)
GENERICff(sinf)
GENERICff(tanf)
GENERICff(acosf)
GENERICff(asinf)
GENERICff(atanf)
GENERICff(coshf)
GENERICff(sinhf)
GENERICff(tanhf)
GENERICff(logf)
GENERICff(log10f)
GENERICff(sqrtf)
GENERICff(ceilf)
GENERICff(fabsf)
GENERICff(floorf)
GENERICff(fractionf)
void powf_generic(asIScriptGeneric *gen)
{
float f1 = *(float*)gen->GetAddressOfArg(0);
float f2 = *(float*)gen->GetAddressOfArg(1);
*(float*)gen->GetAddressOfReturnLocation() = powf(f1, f2);
}
void atan2f_generic(asIScriptGeneric *gen)
{
float f1 = *(float*)gen->GetAddressOfArg(0);
float f2 = *(float*)gen->GetAddressOfArg(1);
*(float*)gen->GetAddressOfReturnLocation() = atan2f(f1, f2);
}
#else
// This macro creates simple generic wrappers for functions of type 'double func(double)'
#define GENERICdd(x) \
void x##_generic(asIScriptGeneric *gen) \
{ \
double f = *(double*)gen->GetAddressOfArg(0); \
*(double*)gen->GetAddressOfReturnLocation() = x(f); \
}
GENERICdd(cos)
GENERICdd(sin)
GENERICdd(tan)
GENERICdd(acos)
GENERICdd(asin)
GENERICdd(atan)
GENERICdd(cosh)
GENERICdd(sinh)
GENERICdd(tanh)
GENERICdd(log)
GENERICdd(log10)
GENERICdd(sqrt)
GENERICdd(ceil)
GENERICdd(fabs)
GENERICdd(floor)
GENERICdd(fraction)
void pow_generic(asIScriptGeneric *gen)
{
double f1 = *(double*)gen->GetAddressOfArg(0);
double f2 = *(double*)gen->GetAddressOfArg(1);
*(double*)gen->GetAddressOfReturnLocation() = pow(f1, f2);
}
void atan2_generic(asIScriptGeneric *gen)
{
double f1 = *(double*)gen->GetAddressOfArg(0);
double f2 = *(double*)gen->GetAddressOfArg(1);
*(double*)gen->GetAddressOfReturnLocation() = atan2(f1, f2);
}
#endif
void RegisterScriptMath_Generic(asIScriptEngine *engine)
{
int r;
#if AS_USE_FLOAT
// Trigonometric functions
r = engine->RegisterGlobalFunction("float cos(float)", asFUNCTION(cosf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float sin(float)", asFUNCTION(sinf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float tan(float)", asFUNCTION(tanf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float acos(float)", asFUNCTION(acosf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float asin(float)", asFUNCTION(asinf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float atan(float)", asFUNCTION(atanf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float atan2(float,float)", asFUNCTION(atan2f_generic), asCALL_GENERIC); assert( r >= 0 );
// Hyberbolic functions
r = engine->RegisterGlobalFunction("float cosh(float)", asFUNCTION(coshf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float sinh(float)", asFUNCTION(sinhf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float tanh(float)", asFUNCTION(tanhf_generic), asCALL_GENERIC); assert( r >= 0 );
// Exponential and logarithmic functions
r = engine->RegisterGlobalFunction("float log(float)", asFUNCTION(logf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float log10(float)", asFUNCTION(log10f_generic), asCALL_GENERIC); assert( r >= 0 );
// Power functions
r = engine->RegisterGlobalFunction("float pow(float, float)", asFUNCTION(powf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float sqrt(float)", asFUNCTION(sqrtf_generic), asCALL_GENERIC); assert( r >= 0 );
// Nearest integer, absolute value, and remainder functions
r = engine->RegisterGlobalFunction("float ceil(float)", asFUNCTION(ceilf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float abs(float)", asFUNCTION(fabsf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float floor(float)", asFUNCTION(floorf_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("float fraction(float)", asFUNCTION(fractionf_generic), asCALL_GENERIC); assert( r >= 0 );
// Don't register modf because AngelScript already supports the % operator
#else
// double versions of the same
r = engine->RegisterGlobalFunction("double cos(double)", asFUNCTION(cos_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sin(double)", asFUNCTION(sin_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double tan(double)", asFUNCTION(tan_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double acos(double)", asFUNCTION(acos_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double asin(double)", asFUNCTION(asin_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double atan(double)", asFUNCTION(atan_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double atan2(double,double)", asFUNCTION(atan2_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double cosh(double)", asFUNCTION(cosh_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sinh(double)", asFUNCTION(sinh_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double tanh(double)", asFUNCTION(tanh_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double log(double)", asFUNCTION(log_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double log10(double)", asFUNCTION(log10_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double pow(double, double)", asFUNCTION(pow_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double sqrt(double)", asFUNCTION(sqrt_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double ceil(double)", asFUNCTION(ceil_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double abs(double)", asFUNCTION(fabs_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double floor(double)", asFUNCTION(floor_generic), asCALL_GENERIC); assert( r >= 0 );
r = engine->RegisterGlobalFunction("double fraction(double)", asFUNCTION(fraction_generic), asCALL_GENERIC); assert( r >= 0 );
#endif
}
void RegisterScriptMath(asIScriptEngine *engine)
{
if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") )
RegisterScriptMath_Generic(engine);
else
RegisterScriptMath_Native(engine);
}
END_AS_NAMESPACE

View File

@ -1,26 +1,26 @@
#ifndef SCRIPTMATH_H
#define SCRIPTMATH_H
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
BEGIN_AS_NAMESPACE
// This function will determine the configuration of the engine
// and use one of the two functions below to register the math functions
void RegisterScriptMath(asIScriptEngine *engine);
// Call this function to register the math functions
// using native calling conventions
void RegisterScriptMath_Native(asIScriptEngine *engine);
// Use this one instead if native calling conventions
// are not supported on the target platform
void RegisterScriptMath_Generic(asIScriptEngine *engine);
END_AS_NAMESPACE
#endif
#ifndef SCRIPTMATH_H
#define SCRIPTMATH_H
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
BEGIN_AS_NAMESPACE
// This function will determine the configuration of the engine
// and use one of the two functions below to register the math functions
void RegisterScriptMath(asIScriptEngine *engine);
// Call this function to register the math functions
// using native calling conventions
void RegisterScriptMath_Native(asIScriptEngine *engine);
// Use this one instead if native calling conventions
// are not supported on the target platform
void RegisterScriptMath_Generic(asIScriptEngine *engine);
END_AS_NAMESPACE
#endif

View File

@ -1,61 +1,66 @@
#ifndef SCRIPTMATHCOMPLEX_H
#define SCRIPTMATHCOMPLEX_H
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
BEGIN_AS_NAMESPACE
// This class implements complex numbers and the common
// operations that can be done with it.
//
// Ref: http://mathworld.wolfram.com/ComplexNumber.html
struct Complex
{
Complex();
Complex(const Complex &other);
Complex(float r, float i = 0);
// Assignment operator
Complex &operator=(const Complex &other);
// Compound assigment operators
Complex &operator+=(const Complex &other);
Complex &operator-=(const Complex &other);
Complex &operator*=(const Complex &other);
Complex &operator/=(const Complex &other);
float length() const;
float squaredLength() const;
// Swizzle operators
Complex get_ri() const;
void set_ri(const Complex &in);
Complex get_ir() const;
void set_ir(const Complex &in);
// Comparison
bool operator==(const Complex &other) const;
bool operator!=(const Complex &other) const;
// Math operators
Complex operator+(const Complex &other) const;
Complex operator-(const Complex &other) const;
Complex operator*(const Complex &other) const;
Complex operator/(const Complex &other) const;
float r;
float i;
};
// This function will determine the configuration of the engine
// and use one of the two functions below to register the string type
void RegisterScriptMathComplex(asIScriptEngine *engine);
END_AS_NAMESPACE
#endif
#ifndef SCRIPTMATHCOMPLEX_H
#define SCRIPTMATHCOMPLEX_H
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
BEGIN_AS_NAMESPACE
// This class implements complex numbers and the common
// operations that can be done with it.
//
// Ref: http://mathworld.wolfram.com/ComplexNumber.html
//lm: thanks gcc...
#ifdef Complex
#undef Complex
#endif
struct Complex
{
Complex();
Complex(const Complex &other);
Complex(float r, float i = 0);
// Assignment operator
Complex &operator=(const Complex &other);
// Compound assigment operators
Complex &operator+=(const Complex &other);
Complex &operator-=(const Complex &other);
Complex &operator*=(const Complex &other);
Complex &operator/=(const Complex &other);
float length() const;
float squaredLength() const;
// Swizzle operators
Complex get_ri() const;
void set_ri(const Complex &in);
Complex get_ir() const;
void set_ir(const Complex &in);
// Comparison
bool operator==(const Complex &other) const;
bool operator!=(const Complex &other) const;
// Math operators
Complex operator+(const Complex &other) const;
Complex operator-(const Complex &other) const;
Complex operator*(const Complex &other) const;
Complex operator/(const Complex &other) const;
float r;
float i;
};
// This function will determine the configuration of the engine
// and use one of the two functions below to register the string type
void RegisterScriptMathComplex(asIScriptEngine *engine);
END_AS_NAMESPACE
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,53 +1,53 @@
//
// Script std::string
//
// This function registers the std::string type with AngelScript to be used as the default string type.
//
// The string type is registered as a value type, thus may have performance issues if a lot of
// string operations are performed in the script. However, for relatively few operations, this should
// not cause any problem for most applications.
//
#ifndef SCRIPTSTDSTRING_H
#define SCRIPTSTDSTRING_H
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
#include <string>
//---------------------------
// Compilation settings
//
// The use of the string pool can improve performance quite drastically
// for scripts that work with a lot of literal string constants.
//
// 1 = on
// 0 = off
#ifndef AS_USE_STRINGPOOL
#define AS_USE_STRINGPOOL 1
#endif
// Sometimes it may be desired to use the same method names as used by C++ STL.
// This may for example reduce time when converting code from script to C++ or
// back.
//
// 0 = off
// 1 = on
#ifndef AS_USE_STLNAMES
#define AS_USE_STLNAMES 0
#endif
BEGIN_AS_NAMESPACE
void RegisterStdString(asIScriptEngine *engine);
void RegisterStdStringUtils(asIScriptEngine *engine);
END_AS_NAMESPACE
#endif
//
// Script std::string
//
// This function registers the std::string type with AngelScript to be used as the default string type.
//
// The string type is registered as a value type, thus may have performance issues if a lot of
// string operations are performed in the script. However, for relatively few operations, this should
// not cause any problem for most applications.
//
#ifndef SCRIPTSTDSTRING_H
#define SCRIPTSTDSTRING_H
#ifndef ANGELSCRIPT_H
// Avoid having to inform include path if header is already include before
#include "angelscript.h"
#endif
#include <string>
//---------------------------
// Compilation settings
//
// The use of the string pool can improve performance quite drastically
// for scripts that work with a lot of literal string constants.
//
// 1 = on
// 0 = off
#ifndef AS_USE_STRINGPOOL
#define AS_USE_STRINGPOOL 1
#endif
// Sometimes it may be desired to use the same method names as used by C++ STL.
// This may for example reduce time when converting code from script to C++ or
// back.
//
// 0 = off
// 1 = on
#ifndef AS_USE_STLNAMES
#define AS_USE_STLNAMES 0
#endif
BEGIN_AS_NAMESPACE
void RegisterStdString(asIScriptEngine *engine);
void RegisterStdStringUtils(asIScriptEngine *engine);
END_AS_NAMESPACE
#endif

View File

@ -1,129 +1,129 @@
#include <assert.h>
#include "scriptstdstring.h"
#include "scriptarray.h"
#include <stdio.h>
#include <string.h>
using namespace std;
BEGIN_AS_NAMESPACE
// This function takes an input string and splits it into parts by looking
// for a specified delimiter. Example:
//
// string str = "A|B||D";
// array<string>@ array = str.split("|");
//
// The resulting array has the following elements:
//
// {"A", "B", "", "D"}
//
// AngelScript signature:
// array<string>@ string::split(const string &in delim) const
static CScriptArray *StringSplit(const string &delim, const string &str)
{
// Obtain a pointer to the engine
asIScriptContext *ctx = asGetActiveContext();
asIScriptEngine *engine = ctx->GetEngine();
// TODO: This should only be done once
// TODO: This assumes that CScriptArray was already registered
asIObjectType *arrayType = engine->GetObjectTypeById(engine->GetTypeIdByDecl("array<string>"));
// Create the array object
CScriptArray *array = new CScriptArray(0, arrayType);
// Find the existence of the delimiter in the input string
int pos = 0, prev = 0, count = 0;
while( (pos = (int)str.find(delim, prev)) != (int)string::npos )
{
// Add the part to the array
array->Resize(array->GetSize()+1);
((string*)array->At(count))->assign(&str[prev], pos-prev);
// Find the next part
count++;
prev = pos + (int)delim.length();
}
// Add the remaining part
array->Resize(array->GetSize()+1);
((string*)array->At(count))->assign(&str[prev]);
return array;
}
static void StringSplit_Generic(asIScriptGeneric *gen)
{
// Get the arguments
string *str = (string*)gen->GetObject();
string *delim = *(string**)gen->GetAddressOfArg(0);
// Return the array by handle
*(CScriptArray**)gen->GetAddressOfReturnLocation() = StringSplit(*delim, *str);
}
// This function takes as input an array of string handles as well as a
// delimiter and concatenates the array elements into one delimited string.
// Example:
//
// array<string> array = {"A", "B", "", "D"};
// string str = join(array, "|");
//
// The resulting string is:
//
// "A|B||D"
//
// AngelScript signature:
// string join(const array<string> &in array, const string &in delim)
static string StringJoin(const CScriptArray &array, const string &delim)
{
// Create the new string
string str = "";
if( array.GetSize() )
{
int n;
for( n = 0; n < (int)array.GetSize() - 1; n++ )
{
str += *(string*)array.At(n);
str += delim;
}
// Add the last part
str += *(string*)array.At(n);
}
return str;
}
static void StringJoin_Generic(asIScriptGeneric *gen)
{
// Get the arguments
CScriptArray *array = *(CScriptArray**)gen->GetAddressOfArg(0);
string *delim = *(string**)gen->GetAddressOfArg(1);
// Return the string
new(gen->GetAddressOfReturnLocation()) string(StringJoin(*array, *delim));
}
// This is where the utility functions are registered.
// The string type must have been registered first.
void RegisterStdStringUtils(asIScriptEngine *engine)
{
int r;
if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") )
{
r = engine->RegisterObjectMethod("string", "array<string>@ split(const string &in) const", asFUNCTION(StringSplit_Generic), asCALL_GENERIC); assert(r >= 0);
r = engine->RegisterGlobalFunction("string join(const array<string> &in, const string &in)", asFUNCTION(StringJoin_Generic), asCALL_GENERIC); assert(r >= 0);
}
else
{
r = engine->RegisterObjectMethod("string", "array<string>@ split(const string &in) const", asFUNCTION(StringSplit), asCALL_CDECL_OBJLAST); assert(r >= 0);
r = engine->RegisterGlobalFunction("string join(const array<string> &in, const string &in)", asFUNCTION(StringJoin), asCALL_CDECL); assert(r >= 0);
}
}
END_AS_NAMESPACE
#include <assert.h>
#include "scriptstdstring.h"
#include "scriptarray.h"
#include <stdio.h>
#include <string.h>
using namespace std;
BEGIN_AS_NAMESPACE
// This function takes an input string and splits it into parts by looking
// for a specified delimiter. Example:
//
// string str = "A|B||D";
// array<string>@ array = str.split("|");
//
// The resulting array has the following elements:
//
// {"A", "B", "", "D"}
//
// AngelScript signature:
// array<string>@ string::split(const string &in delim) const
static CScriptArray *StringSplit(const string &delim, const string &str)
{
// Obtain a pointer to the engine
asIScriptContext *ctx = asGetActiveContext();
asIScriptEngine *engine = ctx->GetEngine();
// TODO: This should only be done once
// TODO: This assumes that CScriptArray was already registered
asIObjectType *arrayType = engine->GetObjectTypeById(engine->GetTypeIdByDecl("array<string>"));
// Create the array object
CScriptArray *array = new CScriptArray(0, arrayType);
// Find the existence of the delimiter in the input string
int pos = 0, prev = 0, count = 0;
while( (pos = (int)str.find(delim, prev)) != (int)string::npos )
{
// Add the part to the array
array->Resize(array->GetSize()+1);
((string*)array->At(count))->assign(&str[prev], pos-prev);
// Find the next part
count++;
prev = pos + (int)delim.length();
}
// Add the remaining part
array->Resize(array->GetSize()+1);
((string*)array->At(count))->assign(&str[prev]);
return array;
}
static void StringSplit_Generic(asIScriptGeneric *gen)
{
// Get the arguments
string *str = (string*)gen->GetObject();
string *delim = *(string**)gen->GetAddressOfArg(0);
// Return the array by handle
*(CScriptArray**)gen->GetAddressOfReturnLocation() = StringSplit(*delim, *str);
}
// This function takes as input an array of string handles as well as a
// delimiter and concatenates the array elements into one delimited string.
// Example:
//
// array<string> array = {"A", "B", "", "D"};
// string str = join(array, "|");
//
// The resulting string is:
//
// "A|B||D"
//
// AngelScript signature:
// string join(const array<string> &in array, const string &in delim)
static string StringJoin(const CScriptArray &array, const string &delim)
{
// Create the new string
string str = "";
if( array.GetSize() )
{
int n;
for( n = 0; n < (int)array.GetSize() - 1; n++ )
{
str += *(string*)array.At(n);
str += delim;
}
// Add the last part
str += *(string*)array.At(n);
}
return str;
}
static void StringJoin_Generic(asIScriptGeneric *gen)
{
// Get the arguments
CScriptArray *array = *(CScriptArray**)gen->GetAddressOfArg(0);
string *delim = *(string**)gen->GetAddressOfArg(1);
// Return the string
new(gen->GetAddressOfReturnLocation()) string(StringJoin(*array, *delim));
}
// This is where the utility functions are registered.
// The string type must have been registered first.
void RegisterStdStringUtils(asIScriptEngine *engine)
{
int r;
if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") )
{
r = engine->RegisterObjectMethod("string", "array<string>@ split(const string &in) const", asFUNCTION(StringSplit_Generic), asCALL_GENERIC); assert(r >= 0);
r = engine->RegisterGlobalFunction("string join(const array<string> &in, const string &in)", asFUNCTION(StringJoin_Generic), asCALL_GENERIC); assert(r >= 0);
}
else
{
r = engine->RegisterObjectMethod("string", "array<string>@ split(const string &in) const", asFUNCTION(StringSplit), asCALL_CDECL_OBJLAST); assert(r >= 0);
r = engine->RegisterGlobalFunction("string join(const array<string> &in, const string &in)", asFUNCTION(StringJoin), asCALL_CDECL); assert(r >= 0);
}
}
END_AS_NAMESPACE

View File

@ -0,0 +1,55 @@
cmake_minimum_required(VERSION 2.6)
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
cmake_policy(SET CMP0003 NEW)
project(Angelscript_addons)
set(ANGELSCRIPT_SOURCE
../../addons/scriptany.cpp
../../addons/scriptarray.cpp
../../addons/scriptbuilder.cpp
../../addons/scriptdictionary.cpp
../../addons/scripthandle.cpp
../../addons/scripthelper.cpp
../../addons/scriptmath.cpp
../../addons/scriptmathcomplex.cpp
../../addons/scriptstdstring.cpp
../../addons/scriptstdstring_utils.cpp
../../addons/weakref.cpp
)
set(ANGELSCRIPT_HEADERS
../../include/angelscript.h
../../addons/scriptany.h
../../addons/scriptarray.h
../../addons/scriptbuilder.h
../../addons/scriptdictionary.h
../../addons/scripthandle.h
../../addons/scripthelper.h
../../addons/scriptmath.h
../../addons/scriptmathcomplex.h
../../addons/scriptstdstring.h
../../addons/weakref.h
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../include)
add_definitions("-D_CRT_SECURE_NO_WARNINGS -DANGELSCRIPT_EXPORT -D_LIB")
# Fix x64 issues on Linux
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" AND NOT APPLE)
add_definitions(-fPIC)
endif()
add_library(Angelscript_addons STATIC ${ANGELSCRIPT_SOURCE} ${ANGELSCRIPT_HEADERS})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
find_package(Threads)
target_link_libraries(Angelscript_addons ${CMAKE_THREAD_LIBS_INIT})
if(MSVC)
set_target_properties(Angelscript_addons PROPERTIES COMPILE_FLAGS "/MP")
endif(MSVC)
set(RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../../bin)

View File

@ -16,47 +16,54 @@ file(GLOB JSON_INCLUDE json/include/json/*.h)
file(GLOB POLY2TRI_FILES poly2tri/*.cc poly2tri/*.h)
file(GLOB POLY2TRI_COMMON_FILES poly2tri/common/*.cc poly2tri/common/*.h)
file(GLOB POLY2TRI_SWEEP_FILES poly2tri/sweep/*.cc poly2tri/sweep/*.h)
file(GLOB SCRIPTBINDING_FILES ScriptBindings/*.cpp ScriptBindings/*.h)
file(GLOB UNZIP_FILES unzip/*.c unzip/*.h)
add_subdirectory(AngelScript/projects/cmake)
set(ANGELSCRIPT_LIBS Angelscript)
add_subdirectory(AngelScript/projects/cmake_addons)
set(ANGELSCRIPT_LIBS Angelscript Angelscript_addons)
include_directories(".")
include_directories("json/include")
include_directories("ENet/include")
add_executable(OpenSpades ${AUDIO_FILES} ${AUDIO_AL_FILES} ${BINPACK_FILES} ${CLIENT_FILES} ${CORE_FILES} ${DRAW_FILES} ${ENET_FILES} ${ENET_INCLUDE} ${GUI_FILES}
${IMPORTS_FILES} ${KISS_FILES} ${JSON_FILES} ${JSON_INCLUDE} ${POLY2TRI_COMMON_FILES} ${POLY2TRI_SWEEP_FILES} ${UNZIP_FILES})
${IMPORTS_FILES} ${KISS_FILES} ${JSON_FILES} ${JSON_INCLUDE} ${POLY2TRI_COMMON_FILES} ${POLY2TRI_SWEEP_FILES} ${UNZIP_FILES} ${SCRIPTBINDING_FILES})
set_target_properties(OpenSpades PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(OpenSpades PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set_target_properties(OpenSpades PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set_target_properties(OpenSpades PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_dependencies(OpenSpades Angelscript)
add_dependencies(OpenSpades Angelscript Angelscript_addons)
if(WIN32)
string(REGEX REPLACE "\\.lib$" ".dll" SDL_DLL ${SDL_LIBRARY})
add_custom_command(TARGET OpenSpades POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SDL_DLL}" "${CMAKE_BINARY_DIR}/bin/\$\(Configuration\)/")
foreach(LIB ${SDL_LIBRARY})
string(REGEX REPLACE "\\.lib$" ".dll" SDL_DLL ${LIB})
if(EXISTS "${SDL_DLL}")
add_custom_command(TARGET OpenSpades POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SDL_DLL}" "${CMAKE_BINARY_DIR}/bin/\$\(Configuration\)/")
endif()
endforeach()
add_definitions(-DCURL_STATICLIB)
endif()
source_group("Audio" FILES ${AUDIO_FILES})
source_group("Audio\\AL" FILES ${AUDIO_AL_FILES})
source_group("binpack2d" FILES ${BINPACK_FILES})
source_group("libs\\binpack2d" FILES ${BINPACK_FILES})
source_group("Client" FILES ${CLIENT_FILES})
source_group("Core" FILES ${CORE_FILES})
source_group("Draw" FILES ${DRAW_FILES})
source_group("Enet" FILES ${ENET_FILES})
source_group("Enet\\include" FILES ${ENET_INCLUDE})
source_group("libs\\Enet" FILES ${ENET_FILES})
source_group("libs\\Enet\\include" FILES ${ENET_INCLUDE})
source_group("Gui" FILES ${GUI_FILES})
source_group("Imports" FILES ${IMPORTS_FILES})
source_group("kiss_fft130" FILES ${KISS_FILES})
source_group("json" FILES ${JSON_FILES})
source_group("json\\include" FILES ${JSON_INCLUDE})
source_group("poly2tri" FILES ${POLY2TRI_FILES})
source_group("poly2tri\\common" FILES ${POLY2TRI_COMMON_FILES})
source_group("poly2tri\\sweep" FILES ${POLY2TRI_SWEEP_FILES})
source_group("unzip" FILES ${UNZIP_FILES})
source_group("libs\\kiss_fft130" FILES ${KISS_FILES})
source_group("libs\\json" FILES ${JSON_FILES})
source_group("libs\\json\\include" FILES ${JSON_INCLUDE})
source_group("libs\\poly2tri" FILES ${POLY2TRI_FILES})
source_group("libs\\poly2tri\\common" FILES ${POLY2TRI_COMMON_FILES})
source_group("libs\\poly2tri\\sweep" FILES ${POLY2TRI_SWEEP_FILES})
source_group("ScriptBindings" FILES ${SCRIPTBINDING_FILES})
source_group("libs\\unzip" FILES ${UNZIP_FILES})
target_link_libraries(OpenSpades ${SDL_LIBRARY} ${OPENGL_LIBRARIES} ${GLEW_LIBRARY} ${FLTK_OS_LIBS} ${ZLIB_LIBRARIES} ${CURL_LIBRARY} ${CMAKE_DL_LIBS} ${ANGELSCRIPT_LIBS})

View File

@ -198,7 +198,8 @@ namespace spades {
// remove '\n' in the end of the result of asctime().
timeStr.resize(timeStr.size()-1);
sprintf(buf, "%s [%s:%d] %s\n",
//lm: using \r\n instead of \n so that some shitty windows editors (notepad f.e.) can parse this file aswell (all decent editors should ignore it anyway)
sprintf(buf, "%s [%s:%d] %s\r\n",
timeStr.c_str(),
fn.c_str(), line, str.c_str());

View File

@ -20,7 +20,6 @@
#include "Math.h"
#include <stdlib.h>
#include "ScriptManager.h"
#include <new>
namespace spades {
@ -526,526 +525,4 @@ namespace spades {
Vector3 Mix(Vector3 a, Vector3 b, float frac) {
return a + (b - a) * frac;
}
class MathScriptObjectRegistrar: public ScriptObjectRegistrar {
public:
MathScriptObjectRegistrar():
ScriptObjectRegistrar("Math"){}
virtual void Register(ScriptManager *manager, Phase phase) {
asIScriptEngine *eng = manager->GetEngine();
int r;
eng->SetDefaultNamespace("spades");
switch(phase){
case PhaseObjectType:
r = eng->RegisterObjectType("IntVector3",
sizeof(IntVector3),
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLINTS);
manager->CheckError(r);
r = eng->RegisterObjectType("Vector2",
sizeof(Vector2),
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLINTS);
manager->CheckError(r);
r = eng->RegisterObjectType("Vector3",
sizeof(Vector3),
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLINTS);
manager->CheckError(r);
r = eng->RegisterObjectType("Vector4",
sizeof(Vector4),
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLINTS);
manager->CheckError(r);
r = eng->RegisterObjectType("Matrix4",
sizeof(Matrix4),
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLINTS);
manager->CheckError(r);
break;
case PhaseObjectMember:
struct IntVector3Funcs {
static void Construct1(IntVector3 *self) {
new(self) IntVector3();
}
static void Construct2(const IntVector3& old, IntVector3 *self) {
new(self) IntVector3(old);
}
static void Construct3(int x, int y, int z, IntVector3 *self) {
new(self) IntVector3();
self->x = x; self->y = y; self->z = z;
}
static void Construct4(const Vector3& old, IntVector3 *self) {
new(self) IntVector3();
self->x = (int)old.x; self->y = (int)old.y; self->z = (int)old.z;
}
};
// Register the constructors
r = eng->RegisterObjectBehaviour("IntVector3", asBEHAVE_CONSTRUCT,
"void f()",
asFUNCTION(IntVector3Funcs::Construct1),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("IntVector3", asBEHAVE_CONSTRUCT,
"void f(const IntVector3 &in)",
asFUNCTION(IntVector3Funcs::Construct2),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("IntVector3", asBEHAVE_CONSTRUCT,
"void f(int, int, int)",
asFUNCTION(IntVector3Funcs::Construct3),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("IntVector3", asBEHAVE_CONSTRUCT,
"void f(const Vector3 &in)",
asFUNCTION(IntVector3Funcs::Construct4),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
// Register the operator overloads
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 &opAddAssign(const IntVector3 &in)",
asMETHODPR(IntVector3, operator+=, (const IntVector3 &), IntVector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 &opSubAssign(const IntVector3 &in)",
asMETHODPR(IntVector3, operator-=, (const IntVector3 &), IntVector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 &opMulAssign(const IntVector3 &in)",
asMETHODPR(IntVector3, operator*=, (const IntVector3 &), IntVector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 &opDivAssign(const IntVector3 &in)",
asMETHODPR(IntVector3, operator/=, (const IntVector3 &), IntVector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"bool opEquals(const IntVector3 &in) const",
asMETHODPR(IntVector3, operator==, (const IntVector3 &) const, bool), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 opAdd(const IntVector3 &in) const",
asMETHODPR(IntVector3, operator+, (const IntVector3 &) const, IntVector3), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 opSub(const IntVector3 &in) const",
asMETHODPR(IntVector3, operator-, (const IntVector3 &) const, IntVector3), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 opMul(const IntVector3 &in) const",
asMETHODPR(IntVector3, operator*, (const IntVector3 &) const, IntVector3), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 opDiv(const IntVector3 &in) const",
asMETHODPR(IntVector3, operator/, (const IntVector3 &) const, IntVector3), asCALL_THISCALL);
manager->CheckError(r);
// Register the object methods
r = eng->RegisterObjectMethod("IntVector3",
"int get_ManhattanLength() const",
asMETHOD(IntVector3, GetManhattanLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"int get_ChebyshevLength() const",
asMETHOD(IntVector3, GetChebyshevLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("int Dot(const IntVector3& in, const IntVector3& in)",
asFUNCTION(IntVector3::Dot),
asCALL_CDECL);
manager->CheckError(r);
struct Vector2Funcs {
static void Construct1(Vector2 *self) {
new(self) Vector2();
}
static void Construct2(const Vector2& old, Vector2 *self) {
new(self) Vector2(old);
}
static void Construct3(float x, float y, Vector2 *self) {
new(self) Vector2();
self->x = x; self->y = y;
}
};
// Register the constructors
r = eng->RegisterObjectBehaviour("Vector2", asBEHAVE_CONSTRUCT,
"void f()",
asFUNCTION(Vector2Funcs::Construct1),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("Vector2", asBEHAVE_CONSTRUCT,
"void f(const Vector2 &in)",
asFUNCTION(Vector2Funcs::Construct2),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("Vector2", asBEHAVE_CONSTRUCT,
"void f(float, float)",
asFUNCTION(Vector2Funcs::Construct3),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
// Register the operator overloads
r = eng->RegisterObjectMethod("Vector2",
"Vector2 &opAddAssign(const Vector2 &in)",
asMETHODPR(Vector2, operator+=, (const Vector2 &), Vector2&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"Vector2 &opSubAssign(const Vector2 &in)",
asMETHODPR(Vector2, operator-=, (const Vector2 &), Vector2&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"Vector2 &opMulAssign(const Vector2 &in)",
asMETHODPR(Vector2, operator*=, (const Vector2 &), Vector2&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"Vector2 &opDivAssign(const Vector2 &in)",
asMETHODPR(Vector2, operator/=, (const Vector2 &), Vector2&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"bool opEquals(const Vector2 &in) const",
asMETHODPR(Vector2, operator==, (const Vector2 &) const, bool), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"Vector2 opAdd(const Vector2 &in) const",
asMETHODPR(Vector2, operator+, (const Vector2 &) const, Vector2), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"Vector2 opSub(const Vector2 &in) const",
asMETHODPR(Vector2, operator-, (const Vector2 &) const, Vector2), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"Vector2 opMul(const Vector2 &in) const",
asMETHODPR(Vector2, operator*, (const Vector2 &) const, Vector2), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"Vector2 opDiv(const Vector2 &in) const",
asMETHODPR(Vector2, operator/, (const Vector2 &) const, Vector2), asCALL_THISCALL);
manager->CheckError(r);
// Register the object methods
r = eng->RegisterObjectMethod("Vector2",
"float get_Length() const",
asMETHOD(Vector2, GetLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"float get_LengthPowered() const",
asMETHOD(Vector2, GetPoweredLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"float get_ManhattanLength() const",
asMETHOD(Vector2, GetManhattanLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"float get_ChebyshevLength() const",
asMETHOD(Vector2, GetChebyshevLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"float get_Normalized() const",
asMETHOD(Vector2, Normalize),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("float Dot(const Vector2& in, const Vector2& in)",
asFUNCTION(Vector2::Dot),
asCALL_CDECL);
manager->CheckError(r);
struct Vector3Funcs {
static void Construct1(Vector3 *self) {
new(self) Vector3();
}
static void Construct2(const Vector3& old, Vector3 *self) {
new(self) Vector3(old);
}
static void Construct3(float x, float y, float z, Vector3 *self) {
new(self) Vector3();
self->x = x; self->y = y; self->z = z;
}
static void Construct4(const IntVector3& old, Vector3 *self) {
new(self) Vector3();
self->x = old.x; self->y = old.y; self->z = old.z;
}
static Vector3 Floor(const Vector3& v) {
return Vector3::Make(floorf(v.x), floorf(v.y), floorf(v.z));
}
static Vector3 Ceil(const Vector3& v) {
return Vector3::Make(ceilf(v.x), ceilf(v.y), ceilf(v.z));
}
};
// Register the constructors
r = eng->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT,
"void f()",
asFUNCTION(Vector3Funcs::Construct1),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT,
"void f(const Vector3 &in)",
asFUNCTION(Vector3Funcs::Construct2),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT,
"void f(float, float, float)",
asFUNCTION(Vector3Funcs::Construct3),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT,
"void f(const IntVector3&in)",
asFUNCTION(Vector3Funcs::Construct4),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
// Register the operator overloads
r = eng->RegisterObjectMethod("Vector3",
"Vector3 &opAddAssign(const Vector3 &in)",
asMETHODPR(Vector3, operator+=, (const Vector3 &), Vector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"Vector3 &opSubAssign(const Vector3 &in)",
asMETHODPR(Vector3, operator-=, (const Vector3 &), Vector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"Vector3 &opMulAssign(const Vector3 &in)",
asMETHODPR(Vector3, operator*=, (const Vector3 &), Vector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"Vector3 &opDivAssign(const Vector3 &in)",
asMETHODPR(Vector3, operator/=, (const Vector3 &), Vector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"bool opEquals(const Vector3 &in) const",
asMETHODPR(Vector3, operator==, (const Vector3 &) const, bool), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"Vector3 opAdd(const Vector3 &in) const",
asMETHODPR(Vector3, operator+, (const Vector3 &) const, Vector3), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"Vector3 opSub(const Vector3 &in) const",
asMETHODPR(Vector3, operator-, (const Vector3 &) const, Vector3), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"Vector3 opMul(const Vector3 &in) const",
asMETHODPR(Vector3, operator*, (const Vector3 &) const, Vector3), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"Vector3 opDiv(const Vector3 &in) const",
asMETHODPR(Vector3, operator/, (const Vector3 &) const, Vector3), asCALL_THISCALL);
manager->CheckError(r);
// Register the object methods
r = eng->RegisterObjectMethod("Vector3",
"float get_Length() const",
asMETHOD(Vector3, GetLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"float get_LengthPowered() const",
asMETHOD(Vector3, GetPoweredLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"float get_ManhattanLength() const",
asMETHOD(Vector3, GetManhattanLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"float get_ChebyshevLength() const",
asMETHOD(Vector3, GetChebyshevLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"float get_Normalized() const",
asMETHOD(Vector3, Normalize),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("float Dot(const Vector3& in, const Vector3& in)",
asFUNCTION(Vector3::Dot),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Vector3 Floor(const Vector3& in)",
asFUNCTION(Vector3Funcs::Floor),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Vector3 Ceil(const Vector3& in)",
asFUNCTION(Vector3Funcs::Ceil),
asCALL_CDECL);
manager->CheckError(r);
struct Matrix4Funcs {
static void Construct1(Matrix4 *self) {
new(self) Matrix4();
*self = Matrix4::Identity();
}
static void Construct2(const Matrix4& old, Matrix4 *self) {
new(self) Matrix4(old);
}
static void Construct3(float m00, float m10, float m20, float m30,
float m01, float m11, float m21, float m31,
float m02, float m12, float m22, float m32,
float m03, float m13, float m23, float m33,
Matrix4 *self) {
new(self) Matrix4(m00, m10, m20, m30,
m01, m11, m21, m31,
m02, m12, m22, m32,
m03, m13, m23, m33);
}
};
// Register the constructors
r = eng->RegisterObjectBehaviour("Matrix4", asBEHAVE_CONSTRUCT,
"void f()",
asFUNCTION(Matrix4Funcs::Construct1),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("Matrix4", asBEHAVE_CONSTRUCT,
"void f(const Matrix4 &in)",
asFUNCTION(Matrix4Funcs::Construct2),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("Matrix4", asBEHAVE_CONSTRUCT,
"void f(float, float, float, float,"
"float, float, float, float,"
"float, float, float, float,"
"float, float, float, float)",
asFUNCTION(Matrix4Funcs::Construct3),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
// Register the operator overloads
r = eng->RegisterObjectMethod("Matrix4",
"Matrix4 &opMulAssign(const Matrix4 &in)",
asMETHODPR(Matrix4, operator*=, (const Matrix4 &), Matrix4&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Matrix4",
"Matrix4 opMul(const Matrix4 &in) const",
asMETHODPR(Matrix4, operator*, (const Matrix4 &) const, Matrix4), asCALL_THISCALL);
manager->CheckError(r);
// Register the object methods
r = eng->RegisterObjectMethod("Matrix4",
"Matrix4 get_Transposed() const",
asMETHOD(Matrix4, Transposed),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Matrix4",
"Matrix4 get_Inversed() const",
asMETHOD(Matrix4, Inversed),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Matrix4",
"float get_InversedFast() const",
asMETHOD(Matrix4, InversedFast),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Matrix4",
"Vector3 GetOrigin() const",
asMETHOD(Matrix4, GetOrigin),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Matrix4",
"Vector3 GetAxis(int) const",
asMETHOD(Matrix4, GetAxis),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Matrix4 CreateTranslateMatrix(Vector3)",
asFUNCTIONPR(Matrix4::Translate, (Vector3), Matrix4),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Matrix4 CreateTranslateMatrix(float, float, float)",
asFUNCTIONPR(Matrix4::Translate, (float,float,float), Matrix4),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Matrix4 CreateRotateMatrix(Vector3, float)",
asFUNCTION(Matrix4::Rotate),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Matrix4 CreateScaleMatrix(float)",
asFUNCTIONPR(Matrix4::Scale, (float), Matrix4),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Matrix4 CreateScaleMatrix(Vector3)",
asFUNCTIONPR(Matrix4::Scale, (Vector3), Matrix4),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Matrix4 CreateScaleMatrix(float, float, float)",
asFUNCTIONPR(Matrix4::Scale, (float,float,float), Matrix4),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Matrix4 CreateMatrixFromAxes(Vector3,Vector3,Vector3,Vector3)",
asFUNCTION(Matrix4::FromAxis),
asCALL_CDECL);
manager->CheckError(r);
/*** Other Global Functions ***/
r = eng->RegisterGlobalFunction("string Replace(const string&in, const string& in, const string&in)",
asFUNCTION(Replace),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("string TrimSpaces(const string&in)",
asFUNCTION(TrimSpaces),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("float GetRandom()",
asFUNCTION(GetRandom),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("float Mix(float,float,float)",
asFUNCTIONPR(Mix, (float,float,float), float),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Vector2 Mix(Vector2,Vector2,Vector2)",
asFUNCTIONPR(Mix, (Vector2,Vector2,float), Vector2),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Vector3 Mix(Vector3,Vector3,Vector3)",
asFUNCTIONPR(Mix, (Vector3,Vector3,float), Vector3),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("float SmoothStep(float)",
asFUNCTION(SmoothStep),
asCALL_CDECL);
manager->CheckError(r);
break;
}
}
};
static MathScriptObjectRegistrar registrar;
}

View File

@ -18,6 +18,7 @@
*/
#include <stdint.h>
#include "IGLShadowMapRenderer.h"
#include "IGLDevice.h"

0
Sources/Externals/include/ignore vendored Normal file
View File

0
Sources/Externals/lib/ignore vendored Normal file
View File

23
Sources/Externals/readme.txt vendored Normal file
View File

@ -0,0 +1,23 @@
When building (on windows) you can put dependencies in this folder.
Headers go in the include folder (grouped by product, f.e. 'SDL', 'FL', 'curl') except for zlib, this goes directly in the include.
Libs all go in the lib folder, without subfolders.
Example:
Externals/
readme.txt
include/
zlib.h
zconf.h
curl/
* all curl headers
FL/
* all FL headers
SDL/
* all SDL headers
lib/
zlib.lib
libcurl.lib
fltk.lib
SDL.lib

View File

@ -22,6 +22,7 @@
#include <FL/Fl_Window.H>
#include "../Core/Settings.h"
#include <FL/fl_draw.H>
#include <algorithm>
DetailConfigTable::DetailConfigTable(int X,int Y,int W,int H,const char* L) : Fl_Table(X,Y,W,H,L) {
callback(&event_callback, (void*)this);
@ -36,15 +37,37 @@ DetailConfigTable::DetailConfigTable(int X,int Y,int W,int H,const char* L) : Fl
input->box(FL_THIN_UP_BOX);
row_edit = col_edit = 0;
s_left = s_top = s_right = s_bottom = 0;
/*for (int c = 0; c < MAX_COLS; c++)
for (int r = 0; r < MAX_ROWS; r++)
values[r][c] = (r + 2) * (c + 3); // initialize cells
*/
items = spades::Settings::GetInstance()->GetAllItemNames();
mAllItems = spades::Settings::GetInstance()->GetAllItemNames();
filterUpdated();
}
bool iEqual( char left, char right )
{
return toupper(left) == toupper(right);
}
void DetailConfigTable::setFilter( const char* newFilter )
{
if( mFilter != newFilter ) {
mFilter = newFilter;
filterUpdated();
}
}
void DetailConfigTable::filterUpdated()
{
mFilteredItems.clear();
for( size_t n = 0; n < mAllItems.size(); ++n ) {
std::string& cur = mAllItems[n];
if( cur.end() != std::search( cur.begin(), cur.end(), mFilter.begin(), mFilter.end(), iEqual ) ) {
mFilteredItems.push_back( cur );
}
}
begin();
row_header(0);
rows(items.size());
rows(mFilteredItems.size());
cols(2);
col_width(0, 250);
@ -52,10 +75,11 @@ DetailConfigTable::DetailConfigTable(int X,int Y,int W,int H,const char* L) : Fl
row_height_all(20);
end();
}
void DetailConfigTable::set_value_hide() {
spades::Settings::ItemHandle item(items[row_edit]);
spades::Settings::ItemHandle item(mFilteredItems[row_edit]);
std::string old = item;
std::string newv = input->value();
@ -75,7 +99,7 @@ void DetailConfigTable::done_editing() {
}
void DetailConfigTable::start_editing(int R, int C) {
spades::Settings::ItemHandle item(items[R]);
spades::Settings::ItemHandle item(mFilteredItems[R]);
row_edit = R; // Now editing this row/col
col_edit = C;
int X,Y,W,H;
@ -187,10 +211,10 @@ void DetailConfigTable::draw_cell(TableContext context, int R,int C, int X,int Y
fl_color(FL_FOREGROUND_COLOR);
fl_font(FL_HELVETICA, 12); // ..in regular font
spades::Settings::ItemHandle item(items[R]);
spades::Settings::ItemHandle item(mFilteredItems[R]);
const char *str;
if(C == 0){
str = items[R].c_str();
str = mFilteredItems[R].c_str();
}else{
str = item.CString();
}

View File

@ -26,8 +26,10 @@
#include <string>
class DetailConfigTable: public Fl_Table {
std::vector<std::string> items;
std::vector<std::string> mAllItems;
std::vector<std::string> mFilteredItems;
std::string mFilter;
Fl_Input *input;
int row_edit, col_edit; // row/col being modified
@ -45,11 +47,12 @@ class DetailConfigTable: public Fl_Table {
}
protected:
void filterUpdated();
virtual void draw_cell(TableContext context, int R,int C, int X,int Y,int W,int H);
public:
DetailConfigTable(int X,int Y,int W,int H,const char* L=0);
~DetailConfigTable() { }
void setFilter( const char* newFilter );
void EndEditing() { done_editing(); }
};

View File

@ -9,6 +9,13 @@ hide();
void DetailConfigWindow::cb_Dismiss(Fl_Return_Button* o, void* v) {
((DetailConfigWindow*)(o->parent()))->cb_Dismiss_i(o,v);
}
void DetailConfigWindow::cb_inputFilter_i(Fl_Input*, void*) {
onFilterChange();
}
void DetailConfigWindow::cb_inputFilter(Fl_Input* o, void* v) {
((DetailConfigWindow*)(o->parent()))->cb_inputFilter_i(o,v);
}
DetailConfigWindow::DetailConfigWindow(int X, int Y, int W, int H, const char *L)
: Fl_Window(X, Y, W, H, L) {
_DetailConfigWindow();
@ -39,7 +46,7 @@ this->when(FL_WHEN_RELEASE);
{ Fl_Return_Button* o = new Fl_Return_Button(480, 475, 100, 25, "Dismiss");
o->callback((Fl_Callback*)cb_Dismiss);
} // Fl_Return_Button* o
{ table = new DetailConfigTable(10, 10, 570, 455);
{ table = new DetailConfigTable(10, 35, 570, 430);
table->box(FL_THIN_DOWN_FRAME);
table->color(FL_BACKGROUND_COLOR);
table->selection_color(FL_BACKGROUND_COLOR);
@ -51,5 +58,9 @@ this->when(FL_WHEN_RELEASE);
table->when(FL_WHEN_RELEASE);
table->end();
} // DetailConfigTable* table
{ inputFilter = new Fl_Input(50, 11, 530, 24, "Filter:");
inputFilter->callback((Fl_Callback*)cb_inputFilter);
inputFilter->when(FL_WHEN_CHANGED);
} // Fl_Input* inputFilter
end();
}

View File

@ -4,20 +4,25 @@ header_name {.h}
code_name {.cpp}
widget_class DetailConfigWindow {
label {Advanced Settings} open
xywh {594 187 591 513} type Double
xywh {382 218 591 513} type Double
code0 {\#include "DetailConfigTable.h"}
class Fl_Window visible
} {
Fl_Return_Button {} {
label Dismiss
callback {table->EndEditing();
hide();} selected
hide();}
xywh {480 475 100 25}
}
Fl_Table table {open
xywh {10 10 570 455}
xywh {10 35 570 430}
class DetailConfigTable
} {}
Function {Init()} {open
Function {onFilterChange()} {open
} {}
Fl_Input inputFilter {
label {Filter:}
callback {onFilterChange();}
xywh {50 11 530 24} when 1
}
}

View File

@ -6,6 +6,7 @@
#include <FL/Fl_Window.H>
#include "DetailConfigTable.h"
#include <FL/Fl_Return_Button.H>
#include <FL/Fl_Input.H>
class DetailConfigWindow : public Fl_Window {
void _DetailConfigWindow();
@ -18,6 +19,11 @@ private:
static void cb_Dismiss(Fl_Return_Button*, void*);
public:
DetailConfigTable *table;
void Init();
Fl_Input *inputFilter;
private:
inline void cb_inputFilter_i(Fl_Input*, void*);
static void cb_inputFilter(Fl_Input*, void*);
public:
void onFilterChange();
};
#endif

View File

@ -23,9 +23,7 @@
#include <vector>
#include <string>
void DetailConfigWindow::Init() {
std::vector<std::string> items;
items = spades::Settings::GetInstance()->GetAllItemNames();
void DetailConfigWindow::onFilterChange()
{
table->setFilter( inputFilter->value() );
}

View File

@ -20,20 +20,21 @@
#include <OpenSpades.h>
#include "MainWindow.h"
#include "../Core/FileManager.h"
#include "../Core/DirectoryFileSystem.h"
#include "../Core/Debug.h"
#include "../Core/Settings.h"
#include "../Core/ConcurrentDispatch.h"
#include "../Core/ZipFileSystem.h"
#include <Core/FileManager.h>
#include <Core/DirectoryFileSystem.h>
#include <Core/Debug.h>
#include <Core/Settings.h>
#include <Core/ConcurrentDispatch.h>
#include <Core/ZipFileSystem.h>
#include "ErrorDialog.h"
#include "../Core/VoxelModel.h"
#include "../Draw/GLOptimizedVoxelModel.h"
#include <Core/VoxelModel.h>
#include <Draw/GLOptimizedVoxelModel.h>
#include "../Core/ScriptManager.h"
#include <ScriptBindings/ScriptManager.h>
#include <algorithm> //std::sort
//using namespace spades::gui;
#ifdef WIN32
#include <windows.h>
#include <shlobj.h>

View File

@ -192,6 +192,7 @@ this->when(FL_WHEN_RELEASE);
groupAbout->end();
} // Fl_Group* groupAbout
{ Fl_Group* o = new Fl_Group(10, 130, 595, 220, "Setup");
o->hide();
{ Fl_Group* o = new Fl_Group(10, 150, 385, 70, "Video");
o->box(FL_ENGRAVED_FRAME);
o->align(Fl_Align(FL_ALIGN_TOP_LEFT));
@ -294,8 +295,7 @@ this->when(FL_WHEN_RELEASE);
} // Fl_Group* o
groupReport->end();
} // Fl_Group* groupReport
{ Fl_Tabs* o = new Fl_Tabs(10, 130, 595, 220, "Serverlist");
o->hide();
{ groupServerlist = new Fl_Tabs(10, 130, 595, 220, "Serverlist");
{ serverListbox = new Fl_Browser(10, 150, 595, 200, "Serverlist");
serverListbox->type(2);
serverListbox->callback((Fl_Callback*)cb_serverListbox);
@ -340,8 +340,8 @@ this->when(FL_WHEN_RELEASE);
} // Fl_Group* o
o->end();
} // Fl_Group* o
o->end();
} // Fl_Tabs* o
groupServerlist->end();
} // Fl_Tabs* groupServerlist
mainTab->end();
} // Fl_Tabs* mainTab
{ bannerBox = new Fl_Box(5, 5, 605, 70);
@ -354,209 +354,211 @@ inited = false;
browser = 0;
end();
}
unsigned char aboutText[4625] = /* binary data included from AboutText.html */
unsigned char aboutText[4695] = /* binary data included from AboutText.html */
{60,104,49,62,36,123,80,65,67,75,65,71,69,95,83,84,82,73,78,71,125,60,47,
104,49,62,10,10,60,104,50,62,67,114,101,100,105,116,115,60,47,104,50,62,10,60,
99,101,110,116,101,114,62,10,9,60,102,111,110,116,32,115,105,122,101,61,51,62,
10,34,121,118,116,34,32,45,32,77,111,115,116,32,111,102,32,116,104,101,32,99,
111,100,101,60,98,114,62,10,34,68,97,110,121,48,34,32,45,32,83,121,115,116,101,
109,32,112,114,111,102,105,108,101,114,44,32,105,100,101,97,115,44,32,101,116,
99,46,60,98,114,62,10,34,108,101,97,114,110,95,109,111,114,101,34,32,45,32,67,
77,97,107,101,32,115,117,112,112,111,114,116,44,32,115,101,114,118,101,114,32,
98,114,111,119,115,101,114,44,32,105,100,101,97,115,60,98,114,62,10,34,105,97,
109,103,114,101,97,115,101,114,34,32,45,32,65,111,83,32,48,46,55,54,32,112,114,
111,116,111,99,111,108,32,115,117,112,112,111,114,116,60,98,114,62,10,34,69,114,
105,99,115,111,110,50,51,49,52,34,32,45,32,66,101,116,116,101,114,32,105,110,
115,116,97,108,108,97,116,105,111,110,32,103,117,105,100,101,10,9,60,47,102,111,
110,116,62,10,60,47,99,101,110,116,101,114,62,10,10,60,104,50,62,80,111,114,116,
105,111,110,115,32,111,102,32,112,114,111,103,114,97,109,32,105,115,32,98,97,
115,101,100,32,111,110,32,102,111,108,108,111,119,105,110,103,32,115,111,102,
116,119,97,114,101,115,58,60,47,104,50,62,10,10,60,104,51,62,112,121,115,112,97,
100,101,115,60,47,104,51,62,10,10,60,112,62,76,105,99,101,110,115,101,100,32,98,
121,32,71,80,76,118,51,46,32,67,82,69,68,73,84,83,47,67,79,78,84,82,73,66,85,84,
73,79,78,83,47,65,67,75,78,79,87,76,69,68,71,69,77,69,78,84,83,58,60,47,112,62,
10,10,60,117,108,62,10,9,60,108,105,62,77,97,116,104,105,97,115,32,34,77,97,
116,94,50,34,32,75,97,101,114,108,101,118,32,45,32,77,111,115,116,32,111,102,32,
116,104,101,32,99,111,100,101,60,47,108,105,62,10,9,60,108,105,62,34,104,111,
109,112,121,34,32,45,32,70,108,111,97,116,105,110,103,32,98,108,111,99,107,32,
100,101,116,101,99,116,105,111,110,44,32,73,82,67,32,99,108,105,101,110,116,44,
32,103,101,110,101,114,97,108,32,99,111,100,101,44,32,101,116,99,46,60,47,108,
105,62,10,9,60,108,105,62,34,84,114,105,112,108,101,102,111,120,34,32,45,32,77,
97,112,32,103,101,110,101,114,97,116,111,114,32,99,111,100,101,44,32,110,101,
116,119,111,114,107,32,99,111,100,101,44,32,101,116,99,46,60,47,108,105,62,10,9,
104,49,62,13,10,13,10,60,104,50,62,67,114,101,100,105,116,115,60,47,104,50,62,
13,10,60,99,101,110,116,101,114,62,13,10,9,60,102,111,110,116,32,115,105,122,
101,61,51,62,13,10,34,121,118,116,34,32,45,32,77,111,115,116,32,111,102,32,116,
104,101,32,99,111,100,101,60,98,114,62,13,10,34,68,97,110,121,48,34,32,45,32,83,
121,115,116,101,109,32,112,114,111,102,105,108,101,114,44,32,105,100,101,97,115,
44,32,101,116,99,46,60,98,114,62,13,10,34,108,101,97,114,110,95,109,111,114,
101,34,32,45,32,67,77,97,107,101,32,115,117,112,112,111,114,116,44,32,115,101,
114,118,101,114,32,98,114,111,119,115,101,114,44,32,105,100,101,97,115,60,98,
114,62,13,10,34,105,97,109,103,114,101,97,115,101,114,34,32,45,32,65,111,83,32,
48,46,55,54,32,112,114,111,116,111,99,111,108,32,115,117,112,112,111,114,116,
60,98,114,62,13,10,34,69,114,105,99,115,111,110,50,51,49,52,34,32,45,32,66,101,
116,116,101,114,32,105,110,115,116,97,108,108,97,116,105,111,110,32,103,117,105,
100,101,13,10,9,60,47,102,111,110,116,62,13,10,60,47,99,101,110,116,101,114,62,
13,10,13,10,60,104,50,62,80,111,114,116,105,111,110,115,32,111,102,32,112,114,
111,103,114,97,109,32,105,115,32,98,97,115,101,100,32,111,110,32,102,111,108,
108,111,119,105,110,103,32,115,111,102,116,119,97,114,101,115,58,60,47,104,50,
62,13,10,13,10,60,104,51,62,112,121,115,112,97,100,101,115,60,47,104,51,62,13,
10,13,10,60,112,62,76,105,99,101,110,115,101,100,32,98,121,32,71,80,76,118,51,
46,32,67,82,69,68,73,84,83,47,67,79,78,84,82,73,66,85,84,73,79,78,83,47,65,67,
75,78,79,87,76,69,68,71,69,77,69,78,84,83,58,60,47,112,62,13,10,13,10,60,117,
108,62,13,10,9,60,108,105,62,77,97,116,104,105,97,115,32,34,77,97,116,94,50,34,
32,75,97,101,114,108,101,118,32,45,32,77,111,115,116,32,111,102,32,116,104,101,
32,99,111,100,101,60,47,108,105,62,13,10,9,60,108,105,62,34,104,111,109,112,
121,34,32,45,32,70,108,111,97,116,105,110,103,32,98,108,111,99,107,32,100,101,
116,101,99,116,105,111,110,44,32,73,82,67,32,99,108,105,101,110,116,44,32,103,
101,110,101,114,97,108,32,99,111,100,101,44,32,101,116,99,46,60,47,108,105,62,
13,10,9,60,108,105,62,34,84,114,105,112,108,101,102,111,120,34,32,45,32,77,97,
112,32,103,101,110,101,114,97,116,111,114,32,99,111,100,101,44,32,110,101,116,
119,111,114,107,32,99,111,100,101,44,32,101,116,99,46,60,47,108,105,62,13,10,9,
60,108,105,62,34,83,104,97,109,34,32,45,32,72,111,115,116,105,110,103,32,97,
110,100,32,116,101,115,116,105,110,103,60,47,108,105,62,10,9,60,108,105,62,34,
89,111,117,114,115,101,108,102,34,32,45,32,83,99,114,105,112,116,115,60,47,108,
105,62,10,9,60,108,105,62,34,98,105,108,100,114,97,109,101,114,34,32,45,32,70,
108,111,97,116,105,110,103,32,98,108,111,99,107,32,100,101,116,101,99,116,105,
111,110,32,40,65,42,41,32,97,110,100,32,109,105,115,99,46,32,99,111,100,101,60,
47,108,105,62,10,9,60,108,105,62,34,84,104,101,71,114,97,110,100,109,97,115,
116,101,114,34,32,45,32,84,101,115,116,101,114,44,32,105,100,101,97,115,32,97,
110,100,32,116,104,101,32,111,102,102,105,99,105,97,108,32,109,97,112,60,47,108,
105,62,10,9,60,108,105,62,34,84,101,103,117,34,32,45,32,76,111,103,111,44,32,
105,100,101,97,115,44,32,116,101,115,116,105,110,103,32,97,110,100,32,116,104,
101,32,111,102,102,105,99,105,97,108,32,109,97,112,60,47,108,105,62,10,9,60,108,
105,62,34,69,110,97,114,105,34,32,45,32,84,101,115,116,105,110,103,44,32,109,
105,115,99,46,32,99,111,100,101,32,97,110,100,32,105,100,101,97,115,60,47,108,
105,62,10,60,47,117,108,62,10,10,10,60,104,50,62,84,104,105,115,32,112,114,111,
103,114,97,109,32,105,110,99,108,117,100,101,115,32,102,111,108,108,111,119,105,
110,103,32,99,111,109,112,111,110,101,110,116,115,58,60,47,104,50,62,10,10,60,
104,51,62,65,110,103,101,108,67,111,100,101,32,83,99,114,105,112,116,105,110,
103,32,76,105,98,114,97,114,121,60,47,104,51,62,10,10,60,112,62,67,111,112,121,
114,105,103,104,116,32,38,99,111,112,121,59,32,50,48,48,51,45,50,48,49,51,32,65,
110,100,114,101,97,115,32,74,195,182,110,115,115,111,110,60,47,112,62,10,10,60,
112,62,84,104,105,115,32,115,111,102,116,119,97,114,101,32,105,115,32,112,114,
111,118,105,100,101,100,32,39,97,115,45,105,115,39,44,32,119,105,116,104,111,
117,116,32,97,110,121,32,101,120,112,114,101,115,115,32,111,114,32,105,109,112,
108,105,101,100,32,119,97,114,114,97,110,116,121,46,32,73,110,32,110,111,32,101,
118,101,110,116,32,119,105,108,108,32,116,104,101,32,97,117,116,104,111,114,115,
32,98,101,32,104,101,108,100,32,108,105,97,98,108,101,32,102,111,114,32,97,110,
121,32,100,97,109,97,103,101,115,32,97,114,105,115,105,110,103,32,102,114,111,
109,32,116,104,101,32,117,115,101,32,111,102,32,116,104,105,115,32,115,111,102,
116,119,97,114,101,46,60,47,112,62,10,60,112,62,80,101,114,109,105,115,115,105,
111,110,32,105,115,32,103,114,97,110,116,101,100,32,116,111,32,97,110,121,111,
110,101,32,116,111,32,117,115,101,32,116,104,105,115,32,115,111,102,116,119,97,
114,101,32,102,111,114,32,97,110,121,32,112,117,114,112,111,115,101,44,32,105,
110,99,108,117,100,105,110,103,32,99,111,109,109,101,114,99,105,97,108,32,97,
112,112,108,105,99,97,116,105,111,110,115,44,32,97,110,100,32,116,111,32,97,108,
116,101,114,32,105,116,32,97,110,100,32,114,101,100,105,115,116,114,105,98,117,
116,101,32,105,116,32,102,114,101,101,108,121,44,32,115,117,98,106,101,99,116,
32,116,111,32,116,104,101,32,102,111,108,108,111,119,105,110,103,32,114,101,
115,116,114,105,99,116,105,111,110,115,58,60,47,112,62,10,60,111,108,62,10,9,60,
108,105,62,84,104,101,32,111,114,105,103,105,110,32,111,102,32,116,104,105,115,
32,115,111,102,116,119,97,114,101,32,109,117,115,116,32,110,111,116,32,98,101,
32,109,105,115,114,101,112,114,101,115,101,110,116,101,100,59,32,121,111,117,
32,109,117,115,116,32,110,111,116,32,99,108,97,105,109,32,116,104,97,116,32,
121,111,117,32,119,114,111,116,101,32,116,104,101,32,111,114,105,103,105,110,97,
108,32,115,111,102,116,119,97,114,101,46,32,73,102,32,121,111,117,32,117,115,
101,32,116,104,105,115,32,115,111,102,116,119,97,114,101,32,105,110,32,97,32,
112,114,111,100,117,99,116,44,32,97,110,32,97,99,107,110,111,119,108,101,100,
103,109,101,110,116,32,105,110,32,116,104,101,32,112,114,111,100,117,99,116,32,
100,111,99,117,109,101,110,116,97,116,105,111,110,32,119,111,117,108,100,32,98,
101,32,97,112,112,114,101,99,105,97,116,101,100,32,98,117,116,32,105,115,32,110,
111,116,32,114,101,113,117,105,114,101,100,46,60,47,108,105,62,10,9,60,108,105,
62,65,108,116,101,114,101,100,32,115,111,117,114,99,101,32,118,101,114,115,105,
111,110,115,32,109,117,115,116,32,98,101,32,112,108,97,105,110,108,121,32,109,
97,114,107,101,100,32,97,115,32,115,117,99,104,44,32,97,110,100,32,109,117,115,
116,32,110,111,116,32,98,101,32,109,105,115,114,101,112,114,101,115,101,110,116,
101,100,32,97,115,32,98,101,105,110,103,32,116,104,101,32,111,114,105,103,105,
110,97,108,32,115,111,102,116,119,97,114,101,46,60,47,108,105,62,10,9,60,108,
105,62,84,104,105,115,32,110,111,116,105,99,101,32,109,97,121,32,110,111,116,32,
98,101,32,114,101,109,111,118,101,100,32,111,114,32,97,108,116,101,114,101,100,
32,102,114,111,109,32,97,110,121,32,115,111,117,114,99,101,32,100,105,115,116,
114,105,98,117,116,105,111,110,46,60,47,108,105,62,10,60,47,111,108,62,10,10,60,
104,51,62,69,78,101,116,60,47,104,51,62,10,60,112,62,67,111,112,121,114,105,103,
104,116,32,38,99,111,112,121,59,32,50,48,48,50,45,50,48,49,49,32,76,101,101,32,
83,97,108,122,109,97,110,60,47,112,62,10,60,112,62,10,9,80,101,114,109,105,115,
115,105,111,110,32,105,115,32,104,101,114,101,98,121,32,103,114,97,110,116,101,
100,44,32,102,114,101,101,32,111,102,32,99,104,97,114,103,101,44,32,116,111,32,
97,110,121,32,112,101,114,115,111,110,32,111,98,116,97,105,110,105,110,103,32,
97,32,99,111,112,121,32,111,102,32,116,104,105,115,32,115,111,102,116,119,97,
114,101,32,97,110,100,32,97,115,115,111,99,105,97,116,101,100,32,100,111,99,117,
109,101,110,116,97,116,105,111,110,32,102,105,108,101,115,32,40,116,104,101,32,
34,83,111,102,116,119,97,114,101,34,41,44,32,116,111,32,100,101,97,108,32,105,
110,32,116,104,101,32,83,111,102,116,119,97,114,101,32,119,105,116,104,111,117,
116,32,114,101,115,116,114,105,99,116,105,111,110,44,32,105,110,99,108,117,100,
105,110,103,32,119,105,116,104,111,117,116,32,108,105,109,105,116,97,116,105,
111,110,32,116,104,101,32,114,105,103,104,116,115,32,116,111,32,117,115,101,44,
32,99,111,112,121,44,32,109,111,100,105,102,121,44,32,109,101,114,103,101,44,
32,112,117,98,108,105,115,104,44,32,100,105,115,116,114,105,98,117,116,101,44,
32,115,117,98,108,105,99,101,110,115,101,44,32,97,110,100,47,111,114,32,115,
101,108,108,32,99,111,112,105,101,115,32,111,102,32,116,104,101,32,83,111,102,
116,119,97,114,101,44,32,97,110,100,32,116,111,32,112,101,114,109,105,116,32,
112,101,114,115,111,110,115,32,116,111,32,119,104,111,109,32,116,104,101,32,83,
111,102,116,119,97,114,101,32,105,115,32,102,117,114,110,105,115,104,101,100,32,
116,111,32,100,111,32,115,111,44,32,115,117,98,106,101,99,116,32,116,111,32,116,
104,101,32,102,111,108,108,111,119,105,110,103,32,99,111,110,100,105,116,105,
111,110,115,58,10,60,47,112,62,10,60,112,62,10,9,84,104,101,32,97,98,111,118,
101,32,99,111,112,121,114,105,103,104,116,32,110,111,116,105,99,101,32,97,110,
100,32,116,104,105,115,32,112,101,114,109,105,115,115,105,111,110,32,110,111,
116,105,99,101,32,115,104,97,108,108,32,98,101,32,105,110,99,108,117,100,101,
100,32,105,110,32,97,108,108,32,99,111,112,105,101,115,32,111,114,32,115,117,98,
115,116,97,110,116,105,97,108,32,112,111,114,116,105,111,110,115,32,111,102,32,
116,104,101,32,83,111,102,116,119,97,114,101,46,10,60,47,112,62,10,60,112,62,10,
9,84,72,69,32,83,79,70,84,87,65,82,69,32,73,83,32,80,82,79,86,73,68,69,68,32,
34,65,83,32,73,83,34,44,32,87,73,84,72,79,85,84,32,87,65,82,82,65,78,84,89,32,
79,70,32,65,78,89,32,75,73,78,68,44,32,69,88,80,82,69,83,83,32,79,82,32,73,77,
80,76,73,69,68,44,32,73,78,67,76,85,68,73,78,71,32,66,85,84,32,78,79,84,32,76,
73,77,73,84,69,68,32,84,79,32,84,72,69,32,87,65,82,82,65,78,84,73,69,83,32,79,
70,32,77,69,82,67,72,65,78,84,65,66,73,76,73,84,89,44,32,70,73,84,78,69,83,83,
32,70,79,82,32,65,32,80,65,82,84,73,67,85,76,65,82,32,80,85,82,80,79,83,69,32,
65,78,68,32,78,79,78,73,78,70,82,73,78,71,69,77,69,78,84,46,32,73,78,32,78,79,
32,69,86,69,78,84,32,83,72,65,76,76,32,84,72,69,32,65,85,84,72,79,82,83,32,79,
82,32,67,79,80,89,82,73,71,72,84,32,72,79,76,68,69,82,83,32,66,69,32,76,73,65,
66,76,69,32,70,79,82,32,65,78,89,32,67,76,65,73,77,44,32,68,65,77,65,71,69,83,
32,79,82,32,79,84,72,69,82,32,76,73,65,66,73,76,73,84,89,44,32,87,72,69,84,72,
69,82,32,73,78,32,65,78,32,65,67,84,73,79,78,32,79,70,32,67,79,78,84,82,65,67,
84,44,32,84,79,82,84,32,79,82,32,79,84,72,69,82,87,73,83,69,44,32,65,82,73,83,
73,78,71,32,70,82,79,77,44,32,79,85,84,32,79,70,32,79,82,32,73,78,32,67,79,78,
78,69,67,84,73,79,78,32,87,73,84,72,32,84,72,69,32,83,79,70,84,87,65,82,69,32,
79,82,32,84,72,69,32,85,83,69,32,79,82,32,79,84,72,69,82,32,68,69,65,76,73,78,
71,83,32,73,78,32,84,72,69,32,83,79,70,84,87,65,82,69,46,10,60,47,112,62,10,10,
60,104,51,62,75,105,115,115,32,70,70,84,60,47,104,51,62,10,60,112,62,67,111,
112,121,114,105,103,104,116,32,38,99,111,112,121,59,32,50,48,48,51,45,50,48,49,
48,32,77,97,114,107,32,66,111,114,103,101,114,100,105,110,103,60,47,112,62,10,
60,112,62,65,108,108,32,114,105,103,104,116,115,32,114,101,115,101,114,118,101,
100,46,60,47,112,62,10,60,112,62,82,101,100,105,115,116,114,105,98,117,116,105,
111,110,32,97,110,100,32,117,115,101,32,105,110,32,115,111,117,114,99,101,32,97,
110,100,32,98,105,110,97,114,121,32,102,111,114,109,115,44,32,119,105,116,104,
32,111,114,32,119,105,116,104,111,117,116,32,109,111,100,105,102,105,99,97,116,
105,111,110,44,32,97,114,101,32,112,101,114,109,105,116,116,101,100,32,112,114,
111,118,105,100,101,100,32,116,104,97,116,32,116,104,101,32,102,111,108,108,111,
119,105,110,103,32,99,111,110,100,105,116,105,111,110,115,32,97,114,101,32,109,
101,116,58,60,47,112,62,10,60,117,108,62,10,9,60,108,105,62,82,101,100,105,115,
116,114,105,98,117,116,105,111,110,115,32,111,102,32,115,111,117,114,99,101,32,
99,111,100,101,32,109,117,115,116,32,114,101,116,97,105,110,32,116,104,101,32,
97,98,111,118,101,32,99,111,112,121,114,105,103,104,116,32,110,111,116,105,99,
101,44,32,116,104,105,115,32,108,105,115,116,32,111,102,32,99,111,110,100,105,
116,105,111,110,115,32,97,110,100,32,116,104,101,32,102,111,108,108,111,119,105,
110,103,32,100,105,115,99,108,97,105,109,101,114,46,60,47,108,105,62,10,9,60,
108,105,62,82,101,100,105,115,116,114,105,98,117,116,105,111,110,115,32,105,110,
32,98,105,110,97,114,121,32,102,111,114,109,32,109,117,115,116,32,114,101,112,
114,111,100,117,99,101,32,116,104,101,32,97,98,111,118,101,32,99,111,112,121,
114,105,103,104,116,32,110,111,116,105,99,101,44,32,116,104,105,115,32,108,105,
115,116,32,111,102,32,99,111,110,100,105,116,105,111,110,115,32,97,110,100,32,
116,104,101,32,102,111,108,108,111,119,105,110,103,32,100,105,115,99,108,97,105,
109,101,114,32,105,110,32,116,104,101,32,100,111,99,117,109,101,110,116,97,116,
105,111,110,32,97,110,100,47,111,114,32,111,116,104,101,114,32,109,97,116,101,
114,105,97,108,115,32,112,114,111,118,105,100,101,100,32,119,105,116,104,32,116,
104,101,32,100,105,115,116,114,105,98,117,116,105,111,110,46,60,47,108,105,62,
10,9,60,108,105,62,78,101,105,116,104,101,114,32,116,104,101,32,97,117,116,104,
111,114,32,110,111,114,32,116,104,101,32,110,97,109,101,115,32,111,102,32,97,
110,121,32,99,111,110,116,114,105,98,117,116,111,114,115,32,109,97,121,32,98,
101,32,117,115,101,100,32,116,111,32,101,110,100,111,114,115,101,32,111,114,32,
112,114,111,109,111,116,101,32,112,114,111,100,117,99,116,115,32,100,101,114,
105,118,101,100,32,102,114,111,109,32,116,104,105,115,32,115,111,102,116,119,97,
114,101,32,119,105,116,104,111,117,116,32,115,112,101,99,105,102,105,99,32,112,
114,105,111,114,32,119,114,105,116,116,101,110,32,112,101,114,109,105,115,115,
105,111,110,46,60,47,108,105,62,10,60,47,117,108,62,10,60,112,62,10,84,72,73,83,
32,83,79,70,84,87,65,82,69,32,73,83,32,80,82,79,86,73,68,69,68,32,66,89,32,84,
72,69,32,67,79,80,89,82,73,71,72,84,32,72,79,76,68,69,82,83,32,65,78,68,32,67,
79,78,84,82,73,66,85,84,79,82,83,32,34,65,83,32,73,83,34,32,65,78,68,32,65,78,
89,32,69,88,80,82,69,83,83,32,79,82,32,73,77,80,76,73,69,68,32,87,65,82,82,65,
78,84,73,69,83,44,32,73,78,67,76,85,68,73,78,71,44,32,66,85,84,32,78,79,84,32,
76,73,77,73,84,69,68,32,84,79,44,32,84,72,69,32,73,77,80,76,73,69,68,32,87,65,
82,82,65,78,84,73,69,83,32,79,70,32,77,69,82,67,72,65,78,84,65,66,73,76,73,84,
89,32,65,78,68,32,70,73,84,78,69,83,83,32,70,79,82,32,65,32,80,65,82,84,73,67,
85,76,65,82,32,80,85,82,80,79,83,69,32,65,82,69,32,68,73,83,67,76,65,73,77,69,
68,46,32,73,78,32,78,79,32,69,86,69,78,84,32,83,72,65,76,76,32,84,72,69,32,67,
79,80,89,82,73,71,72,84,32,79,87,78,69,82,32,79,82,32,67,79,78,84,82,73,66,85,
84,79,82,83,32,66,69,32,76,73,65,66,76,69,32,70,79,82,32,65,78,89,32,68,73,82,
69,67,84,44,32,73,78,68,73,82,69,67,84,44,32,73,78,67,73,68,69,78,84,65,76,44,
32,83,80,69,67,73,65,76,44,32,69,88,69,77,80,76,65,82,89,44,32,79,82,32,67,79,
78,83,69,81,85,69,78,84,73,65,76,32,68,65,77,65,71,69,83,32,40,73,78,67,76,85,
68,73,78,71,44,32,66,85,84,32,78,79,84,32,76,73,77,73,84,69,68,32,84,79,44,32,
80,82,79,67,85,82,69,77,69,78,84,32,79,70,32,83,85,66,83,84,73,84,85,84,69,32,
71,79,79,68,83,32,79,82,32,83,69,82,86,73,67,69,83,59,32,76,79,83,83,32,79,70,
32,85,83,69,44,32,68,65,84,65,44,32,79,82,32,80,82,79,70,73,84,83,59,32,79,82,
32,66,85,83,73,78,69,83,83,32,73,78,84,69,82,82,85,80,84,73,79,78,41,32,72,79,
87,69,86,69,82,32,67,65,85,83,69,68,32,65,78,68,32,79,78,32,65,78,89,32,84,72,
69,79,82,89,32,79,70,32,76,73,65,66,73,76,73,84,89,44,32,87,72,69,84,72,69,82,
32,73,78,32,67,79,78,84,82,65,67,84,44,32,83,84,82,73,67,84,32,76,73,65,66,73,
76,73,84,89,44,32,79,82,32,84,79,82,84,32,40,73,78,67,76,85,68,73,78,71,32,78,
69,71,76,73,71,69,78,67,69,32,79,82,32,79,84,72,69,82,87,73,83,69,41,32,65,82,
73,83,73,78,71,32,73,78,32,65,78,89,32,87,65,89,32,79,85,84,32,79,70,32,84,72,
69,32,85,83,69,32,79,70,32,84,72,73,83,32,83,79,70,84,87,65,82,69,44,32,69,86,
69,78,32,73,70,32,65,68,86,73,83,69,68,32,79,70,32,84,72,69,32,80,79,83,83,73,
66,73,76,73,84,89,32,79,70,32,83,85,67,72,32,68,65,77,65,71,69,46,10,60,47,112,
62,10};
110,100,32,116,101,115,116,105,110,103,60,47,108,105,62,13,10,9,60,108,105,62,
34,89,111,117,114,115,101,108,102,34,32,45,32,83,99,114,105,112,116,115,60,47,
108,105,62,13,10,9,60,108,105,62,34,98,105,108,100,114,97,109,101,114,34,32,45,
32,70,108,111,97,116,105,110,103,32,98,108,111,99,107,32,100,101,116,101,99,
116,105,111,110,32,40,65,42,41,32,97,110,100,32,109,105,115,99,46,32,99,111,100,
101,60,47,108,105,62,13,10,9,60,108,105,62,34,84,104,101,71,114,97,110,100,109,
97,115,116,101,114,34,32,45,32,84,101,115,116,101,114,44,32,105,100,101,97,115,
32,97,110,100,32,116,104,101,32,111,102,102,105,99,105,97,108,32,109,97,112,60,
47,108,105,62,13,10,9,60,108,105,62,34,84,101,103,117,34,32,45,32,76,111,103,
111,44,32,105,100,101,97,115,44,32,116,101,115,116,105,110,103,32,97,110,100,32,
116,104,101,32,111,102,102,105,99,105,97,108,32,109,97,112,60,47,108,105,62,13,
10,9,60,108,105,62,34,69,110,97,114,105,34,32,45,32,84,101,115,116,105,110,103,
44,32,109,105,115,99,46,32,99,111,100,101,32,97,110,100,32,105,100,101,97,115,
60,47,108,105,62,13,10,60,47,117,108,62,13,10,13,10,13,10,60,104,50,62,84,104,
105,115,32,112,114,111,103,114,97,109,32,105,110,99,108,117,100,101,115,32,102,
111,108,108,111,119,105,110,103,32,99,111,109,112,111,110,101,110,116,115,58,60,
47,104,50,62,13,10,13,10,60,104,51,62,65,110,103,101,108,67,111,100,101,32,83,
99,114,105,112,116,105,110,103,32,76,105,98,114,97,114,121,60,47,104,51,62,13,
10,13,10,60,112,62,67,111,112,121,114,105,103,104,116,32,38,99,111,112,121,59,
32,50,48,48,51,45,50,48,49,51,32,65,110,100,114,101,97,115,32,74,195,182,110,
115,115,111,110,60,47,112,62,13,10,13,10,60,112,62,84,104,105,115,32,115,111,
102,116,119,97,114,101,32,105,115,32,112,114,111,118,105,100,101,100,32,39,97,
115,45,105,115,39,44,32,119,105,116,104,111,117,116,32,97,110,121,32,101,120,
112,114,101,115,115,32,111,114,32,105,109,112,108,105,101,100,32,119,97,114,114,
97,110,116,121,46,32,73,110,32,110,111,32,101,118,101,110,116,32,119,105,108,
108,32,116,104,101,32,97,117,116,104,111,114,115,32,98,101,32,104,101,108,100,
32,108,105,97,98,108,101,32,102,111,114,32,97,110,121,32,100,97,109,97,103,101,
115,32,97,114,105,115,105,110,103,32,102,114,111,109,32,116,104,101,32,117,115,
101,32,111,102,32,116,104,105,115,32,115,111,102,116,119,97,114,101,46,60,47,
112,62,13,10,60,112,62,80,101,114,109,105,115,115,105,111,110,32,105,115,32,103,
114,97,110,116,101,100,32,116,111,32,97,110,121,111,110,101,32,116,111,32,117,
115,101,32,116,104,105,115,32,115,111,102,116,119,97,114,101,32,102,111,114,32,
97,110,121,32,112,117,114,112,111,115,101,44,32,105,110,99,108,117,100,105,110,
103,32,99,111,109,109,101,114,99,105,97,108,32,97,112,112,108,105,99,97,116,105,
111,110,115,44,32,97,110,100,32,116,111,32,97,108,116,101,114,32,105,116,32,97,
110,100,32,114,101,100,105,115,116,114,105,98,117,116,101,32,105,116,32,102,114,
101,101,108,121,44,32,115,117,98,106,101,99,116,32,116,111,32,116,104,101,32,
102,111,108,108,111,119,105,110,103,32,114,101,115,116,114,105,99,116,105,111,
110,115,58,60,47,112,62,13,10,60,111,108,62,13,10,9,60,108,105,62,84,104,101,32,
111,114,105,103,105,110,32,111,102,32,116,104,105,115,32,115,111,102,116,119,97,
114,101,32,109,117,115,116,32,110,111,116,32,98,101,32,109,105,115,114,101,112,
114,101,115,101,110,116,101,100,59,32,121,111,117,32,109,117,115,116,32,110,111,
116,32,99,108,97,105,109,32,116,104,97,116,32,121,111,117,32,119,114,111,116,
101,32,116,104,101,32,111,114,105,103,105,110,97,108,32,115,111,102,116,119,97,
114,101,46,32,73,102,32,121,111,117,32,117,115,101,32,116,104,105,115,32,115,
111,102,116,119,97,114,101,32,105,110,32,97,32,112,114,111,100,117,99,116,44,32,
97,110,32,97,99,107,110,111,119,108,101,100,103,109,101,110,116,32,105,110,32,
116,104,101,32,112,114,111,100,117,99,116,32,100,111,99,117,109,101,110,116,97,
116,105,111,110,32,119,111,117,108,100,32,98,101,32,97,112,112,114,101,99,105,
97,116,101,100,32,98,117,116,32,105,115,32,110,111,116,32,114,101,113,117,105,
114,101,100,46,60,47,108,105,62,13,10,9,60,108,105,62,65,108,116,101,114,101,
100,32,115,111,117,114,99,101,32,118,101,114,115,105,111,110,115,32,109,117,115,
116,32,98,101,32,112,108,97,105,110,108,121,32,109,97,114,107,101,100,32,97,115,
32,115,117,99,104,44,32,97,110,100,32,109,117,115,116,32,110,111,116,32,98,101,
32,109,105,115,114,101,112,114,101,115,101,110,116,101,100,32,97,115,32,98,101,
105,110,103,32,116,104,101,32,111,114,105,103,105,110,97,108,32,115,111,102,116,
119,97,114,101,46,60,47,108,105,62,13,10,9,60,108,105,62,84,104,105,115,32,110,
111,116,105,99,101,32,109,97,121,32,110,111,116,32,98,101,32,114,101,109,111,
118,101,100,32,111,114,32,97,108,116,101,114,101,100,32,102,114,111,109,32,97,
110,121,32,115,111,117,114,99,101,32,100,105,115,116,114,105,98,117,116,105,111,
110,46,60,47,108,105,62,13,10,60,47,111,108,62,13,10,13,10,60,104,51,62,69,78,
101,116,60,47,104,51,62,13,10,60,112,62,67,111,112,121,114,105,103,104,116,32,
38,99,111,112,121,59,32,50,48,48,50,45,50,48,49,49,32,76,101,101,32,83,97,108,
122,109,97,110,60,47,112,62,13,10,60,112,62,13,10,9,80,101,114,109,105,115,115,
105,111,110,32,105,115,32,104,101,114,101,98,121,32,103,114,97,110,116,101,100,
44,32,102,114,101,101,32,111,102,32,99,104,97,114,103,101,44,32,116,111,32,97,
110,121,32,112,101,114,115,111,110,32,111,98,116,97,105,110,105,110,103,32,97,
32,99,111,112,121,32,111,102,32,116,104,105,115,32,115,111,102,116,119,97,114,
101,32,97,110,100,32,97,115,115,111,99,105,97,116,101,100,32,100,111,99,117,109,
101,110,116,97,116,105,111,110,32,102,105,108,101,115,32,40,116,104,101,32,34,
83,111,102,116,119,97,114,101,34,41,44,32,116,111,32,100,101,97,108,32,105,110,
32,116,104,101,32,83,111,102,116,119,97,114,101,32,119,105,116,104,111,117,116,
32,114,101,115,116,114,105,99,116,105,111,110,44,32,105,110,99,108,117,100,105,
110,103,32,119,105,116,104,111,117,116,32,108,105,109,105,116,97,116,105,111,
110,32,116,104,101,32,114,105,103,104,116,115,32,116,111,32,117,115,101,44,32,
99,111,112,121,44,32,109,111,100,105,102,121,44,32,109,101,114,103,101,44,32,
112,117,98,108,105,115,104,44,32,100,105,115,116,114,105,98,117,116,101,44,32,
115,117,98,108,105,99,101,110,115,101,44,32,97,110,100,47,111,114,32,115,101,
108,108,32,99,111,112,105,101,115,32,111,102,32,116,104,101,32,83,111,102,116,
119,97,114,101,44,32,97,110,100,32,116,111,32,112,101,114,109,105,116,32,112,
101,114,115,111,110,115,32,116,111,32,119,104,111,109,32,116,104,101,32,83,111,
102,116,119,97,114,101,32,105,115,32,102,117,114,110,105,115,104,101,100,32,116,
111,32,100,111,32,115,111,44,32,115,117,98,106,101,99,116,32,116,111,32,116,104,
101,32,102,111,108,108,111,119,105,110,103,32,99,111,110,100,105,116,105,111,
110,115,58,13,10,60,47,112,62,13,10,60,112,62,13,10,9,84,104,101,32,97,98,111,
118,101,32,99,111,112,121,114,105,103,104,116,32,110,111,116,105,99,101,32,97,
110,100,32,116,104,105,115,32,112,101,114,109,105,115,115,105,111,110,32,110,
111,116,105,99,101,32,115,104,97,108,108,32,98,101,32,105,110,99,108,117,100,
101,100,32,105,110,32,97,108,108,32,99,111,112,105,101,115,32,111,114,32,115,
117,98,115,116,97,110,116,105,97,108,32,112,111,114,116,105,111,110,115,32,111,
102,32,116,104,101,32,83,111,102,116,119,97,114,101,46,13,10,60,47,112,62,13,10,
60,112,62,13,10,9,84,72,69,32,83,79,70,84,87,65,82,69,32,73,83,32,80,82,79,86,
73,68,69,68,32,34,65,83,32,73,83,34,44,32,87,73,84,72,79,85,84,32,87,65,82,82,
65,78,84,89,32,79,70,32,65,78,89,32,75,73,78,68,44,32,69,88,80,82,69,83,83,32,
79,82,32,73,77,80,76,73,69,68,44,32,73,78,67,76,85,68,73,78,71,32,66,85,84,32,
78,79,84,32,76,73,77,73,84,69,68,32,84,79,32,84,72,69,32,87,65,82,82,65,78,84,
73,69,83,32,79,70,32,77,69,82,67,72,65,78,84,65,66,73,76,73,84,89,44,32,70,73,
84,78,69,83,83,32,70,79,82,32,65,32,80,65,82,84,73,67,85,76,65,82,32,80,85,82,
80,79,83,69,32,65,78,68,32,78,79,78,73,78,70,82,73,78,71,69,77,69,78,84,46,32,
73,78,32,78,79,32,69,86,69,78,84,32,83,72,65,76,76,32,84,72,69,32,65,85,84,72,
79,82,83,32,79,82,32,67,79,80,89,82,73,71,72,84,32,72,79,76,68,69,82,83,32,66,
69,32,76,73,65,66,76,69,32,70,79,82,32,65,78,89,32,67,76,65,73,77,44,32,68,65,
77,65,71,69,83,32,79,82,32,79,84,72,69,82,32,76,73,65,66,73,76,73,84,89,44,32,
87,72,69,84,72,69,82,32,73,78,32,65,78,32,65,67,84,73,79,78,32,79,70,32,67,79,
78,84,82,65,67,84,44,32,84,79,82,84,32,79,82,32,79,84,72,69,82,87,73,83,69,44,
32,65,82,73,83,73,78,71,32,70,82,79,77,44,32,79,85,84,32,79,70,32,79,82,32,73,
78,32,67,79,78,78,69,67,84,73,79,78,32,87,73,84,72,32,84,72,69,32,83,79,70,84,
87,65,82,69,32,79,82,32,84,72,69,32,85,83,69,32,79,82,32,79,84,72,69,82,32,68,
69,65,76,73,78,71,83,32,73,78,32,84,72,69,32,83,79,70,84,87,65,82,69,46,13,10,
60,47,112,62,13,10,13,10,60,104,51,62,75,105,115,115,32,70,70,84,60,47,104,51,
62,13,10,60,112,62,67,111,112,121,114,105,103,104,116,32,38,99,111,112,121,59,
32,50,48,48,51,45,50,48,49,48,32,77,97,114,107,32,66,111,114,103,101,114,100,
105,110,103,60,47,112,62,13,10,60,112,62,65,108,108,32,114,105,103,104,116,115,
32,114,101,115,101,114,118,101,100,46,60,47,112,62,13,10,60,112,62,82,101,100,
105,115,116,114,105,98,117,116,105,111,110,32,97,110,100,32,117,115,101,32,105,
110,32,115,111,117,114,99,101,32,97,110,100,32,98,105,110,97,114,121,32,102,111,
114,109,115,44,32,119,105,116,104,32,111,114,32,119,105,116,104,111,117,116,32,
109,111,100,105,102,105,99,97,116,105,111,110,44,32,97,114,101,32,112,101,114,
109,105,116,116,101,100,32,112,114,111,118,105,100,101,100,32,116,104,97,116,32,
116,104,101,32,102,111,108,108,111,119,105,110,103,32,99,111,110,100,105,116,
105,111,110,115,32,97,114,101,32,109,101,116,58,60,47,112,62,13,10,60,117,108,
62,13,10,9,60,108,105,62,82,101,100,105,115,116,114,105,98,117,116,105,111,110,
115,32,111,102,32,115,111,117,114,99,101,32,99,111,100,101,32,109,117,115,116,
32,114,101,116,97,105,110,32,116,104,101,32,97,98,111,118,101,32,99,111,112,
121,114,105,103,104,116,32,110,111,116,105,99,101,44,32,116,104,105,115,32,108,
105,115,116,32,111,102,32,99,111,110,100,105,116,105,111,110,115,32,97,110,100,
32,116,104,101,32,102,111,108,108,111,119,105,110,103,32,100,105,115,99,108,97,
105,109,101,114,46,60,47,108,105,62,13,10,9,60,108,105,62,82,101,100,105,115,
116,114,105,98,117,116,105,111,110,115,32,105,110,32,98,105,110,97,114,121,32,
102,111,114,109,32,109,117,115,116,32,114,101,112,114,111,100,117,99,101,32,116,
104,101,32,97,98,111,118,101,32,99,111,112,121,114,105,103,104,116,32,110,111,
116,105,99,101,44,32,116,104,105,115,32,108,105,115,116,32,111,102,32,99,111,
110,100,105,116,105,111,110,115,32,97,110,100,32,116,104,101,32,102,111,108,108,
111,119,105,110,103,32,100,105,115,99,108,97,105,109,101,114,32,105,110,32,116,
104,101,32,100,111,99,117,109,101,110,116,97,116,105,111,110,32,97,110,100,47,
111,114,32,111,116,104,101,114,32,109,97,116,101,114,105,97,108,115,32,112,114,
111,118,105,100,101,100,32,119,105,116,104,32,116,104,101,32,100,105,115,116,
114,105,98,117,116,105,111,110,46,60,47,108,105,62,13,10,9,60,108,105,62,78,101,
105,116,104,101,114,32,116,104,101,32,97,117,116,104,111,114,32,110,111,114,32,
116,104,101,32,110,97,109,101,115,32,111,102,32,97,110,121,32,99,111,110,116,
114,105,98,117,116,111,114,115,32,109,97,121,32,98,101,32,117,115,101,100,32,
116,111,32,101,110,100,111,114,115,101,32,111,114,32,112,114,111,109,111,116,
101,32,112,114,111,100,117,99,116,115,32,100,101,114,105,118,101,100,32,102,114,
111,109,32,116,104,105,115,32,115,111,102,116,119,97,114,101,32,119,105,116,104,
111,117,116,32,115,112,101,99,105,102,105,99,32,112,114,105,111,114,32,119,114,
105,116,116,101,110,32,112,101,114,109,105,115,115,105,111,110,46,60,47,108,105,
62,13,10,60,47,117,108,62,13,10,60,112,62,13,10,84,72,73,83,32,83,79,70,84,87,
65,82,69,32,73,83,32,80,82,79,86,73,68,69,68,32,66,89,32,84,72,69,32,67,79,80,
89,82,73,71,72,84,32,72,79,76,68,69,82,83,32,65,78,68,32,67,79,78,84,82,73,66,
85,84,79,82,83,32,34,65,83,32,73,83,34,32,65,78,68,32,65,78,89,32,69,88,80,82,
69,83,83,32,79,82,32,73,77,80,76,73,69,68,32,87,65,82,82,65,78,84,73,69,83,44,
32,73,78,67,76,85,68,73,78,71,44,32,66,85,84,32,78,79,84,32,76,73,77,73,84,69,
68,32,84,79,44,32,84,72,69,32,73,77,80,76,73,69,68,32,87,65,82,82,65,78,84,73,
69,83,32,79,70,32,77,69,82,67,72,65,78,84,65,66,73,76,73,84,89,32,65,78,68,32,
70,73,84,78,69,83,83,32,70,79,82,32,65,32,80,65,82,84,73,67,85,76,65,82,32,80,
85,82,80,79,83,69,32,65,82,69,32,68,73,83,67,76,65,73,77,69,68,46,32,73,78,32,
78,79,32,69,86,69,78,84,32,83,72,65,76,76,32,84,72,69,32,67,79,80,89,82,73,71,
72,84,32,79,87,78,69,82,32,79,82,32,67,79,78,84,82,73,66,85,84,79,82,83,32,66,
69,32,76,73,65,66,76,69,32,70,79,82,32,65,78,89,32,68,73,82,69,67,84,44,32,73,
78,68,73,82,69,67,84,44,32,73,78,67,73,68,69,78,84,65,76,44,32,83,80,69,67,73,
65,76,44,32,69,88,69,77,80,76,65,82,89,44,32,79,82,32,67,79,78,83,69,81,85,69,
78,84,73,65,76,32,68,65,77,65,71,69,83,32,40,73,78,67,76,85,68,73,78,71,44,32,
66,85,84,32,78,79,84,32,76,73,77,73,84,69,68,32,84,79,44,32,80,82,79,67,85,82,
69,77,69,78,84,32,79,70,32,83,85,66,83,84,73,84,85,84,69,32,71,79,79,68,83,32,
79,82,32,83,69,82,86,73,67,69,83,59,32,76,79,83,83,32,79,70,32,85,83,69,44,32,
68,65,84,65,44,32,79,82,32,80,82,79,70,73,84,83,59,32,79,82,32,66,85,83,73,78,
69,83,83,32,73,78,84,69,82,82,85,80,84,73,79,78,41,32,72,79,87,69,86,69,82,32,
67,65,85,83,69,68,32,65,78,68,32,79,78,32,65,78,89,32,84,72,69,79,82,89,32,79,
70,32,76,73,65,66,73,76,73,84,89,44,32,87,72,69,84,72,69,82,32,73,78,32,67,79,
78,84,82,65,67,84,44,32,83,84,82,73,67,84,32,76,73,65,66,73,76,73,84,89,44,32,
79,82,32,84,79,82,84,32,40,73,78,67,76,85,68,73,78,71,32,78,69,71,76,73,71,69,
78,67,69,32,79,82,32,79,84,72,69,82,87,73,83,69,41,32,65,82,73,83,73,78,71,32,
73,78,32,65,78,89,32,87,65,89,32,79,85,84,32,79,70,32,84,72,69,32,85,83,69,32,
79,70,32,84,72,73,83,32,83,79,70,84,87,65,82,69,44,32,69,86,69,78,32,73,70,32,
65,68,86,73,83,69,68,32,79,70,32,84,72,69,32,80,79,83,83,73,66,73,76,73,84,89,
32,79,70,32,83,85,67,72,32,68,65,77,65,71,69,46,13,10,60,47,112,62,13,10};

View File

@ -7,7 +7,7 @@ decl {namespace spades { class Serverbrowser; }} {public global
widget_class MainWindow {
label {OpenSpades Startup} open
xywh {534 291 615 356} type Double labelsize 12 align 80
xywh {148 243 615 356} type Double labelsize 12 align 80
code0 {\#include <string>}
code1 {\#include <vector>}
class Fl_Window visible
@ -30,7 +30,7 @@ widget_class MainWindow {
}
Fl_Group {} {
label Setup open
private xywh {10 130 595 220}
private xywh {10 130 595 220} hide
} {
Fl_Group {} {
label Video open
@ -69,7 +69,7 @@ SavePrefs();} open
}
}
Fl_Group {} {
label Graphics open selected
label Graphics open
private xywh {10 240 385 105} box ENGRAVED_FRAME align 5
} {
Fl_Light_Button softParticleCheck {
@ -149,9 +149,9 @@ SavePrefs();} open
}
}
}
Fl_Tabs {} {
label Serverlist open
xywh {10 130 595 220} hide
Fl_Tabs groupServerlist {
label Serverlist open selected
xywh {10 130 595 220}
} {
Fl_Browser serverListbox {
label Serverlist

View File

@ -91,6 +91,7 @@ public:
Fl_Output *outputGLVersion;
Fl_Output *outputGLSLVersion;
Fl_Help_View *glInfoView;
Fl_Tabs *groupServerlist;
protected:
Fl_Browser *serverListbox;
private:
@ -151,5 +152,5 @@ public:
void updateFilters();;
~MainWindow();
};
extern unsigned char aboutText[4625];
extern unsigned char aboutText[4695];
#endif

View File

@ -78,10 +78,6 @@ static std::vector<spades::IntVector3> g_modes;
MainWindow::~MainWindow()
{
if( browser ) {
if( browser->IsAlive() ) {
browser->stopReading();
browser->Join();
}
delete browser;
}
}
@ -333,7 +329,8 @@ void MainWindow::Init() {
checkFilterV75->value( flags & spades::ServerFilter::flt_Ver075 );
checkFilterV76->value( flags & spades::ServerFilter::flt_Ver076 );
checkFilterVOther->value( flags & spades::ServerFilter::flt_VerOther );
browser->Start();
browser->startQuery();
mainTab->value(groupServerlist);
}
/** This function is called after showing window.
@ -399,7 +396,16 @@ void MainWindow::CheckGLCapability() {
outputGLRenderer->value("(unknown)");
}
if((str = (const char *)glGetString(GL_VERSION)) != NULL) {
outputGLVersion->value(str);
double ver = atof(str);
if( ver <= 0.1 ) { //TODO: determine required version!
std::string tmp = str;
tmp += " (too old)";
outputGLVersion->textcolor( FL_RED );
outputGLVersion->value( tmp.c_str() );
capable = false;
}else{
outputGLVersion->value( str );
}
SPLog("Version: %s", str);
}else{
outputGLVersion->value("(unknown)");
@ -780,7 +786,6 @@ void MainWindow::OpenDetailConfig() {
DetailConfigWindow cfg;
cfg.set_modal();
cfg.Init();
cfg.show();
while(cfg.visible()){
Fl::wait();

View File

@ -62,10 +62,11 @@ ReportError(err, __LINE__, __PRETTY_FUNCTION__); \
//lm: The macro would not work on windows, the application simply fails to start if dependency's are missing.
// unline *nix, runtime dependency's are all resolved at application start.
// unline ?mac?, runtime dependency's are all resolved at application start.
// one would need a construction like OpenAL, where functions are resolved dynamically (GetProcAddress / dlsym)
//on GCC this was giving me warnings aswell...
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__GNUC__)
#define CheckExistence(func)
#else
#define CheckExistence(func) do { \
@ -240,7 +241,7 @@ ReportError(err, __LINE__, __PRETTY_FUNCTION__); \
glFrontFace(GL_CCW);
break;
default:
SPInvalidEnum("val", "val");
SPInvalidEnum("val", val);
}
CheckError();
}

View File

@ -31,7 +31,7 @@
SPADES_SETTING2(cg_protocolVersion, "", "The protocol version to use, 3 = 0.75, 4 = 0.76");
SPADES_SETTING(cg_serverlistFilter, "31");
SPADES_SETTING(cg_serverlistSort, "0");
SPADES_SETTING(cg_serverlistSort, "16385"); //0x4001 (sort on players, descending)
#define SERVICE_URL "http://services.buildandshoot.com/serverlist.json"
@ -163,6 +163,20 @@ Serverbrowser::Serverbrowser( Fl_Browser* box )
curl_global_init( CURL_GLOBAL_ALL );
}
Serverbrowser::~Serverbrowser()
{
if( IsAlive() ) {
stopQuery();
Join();
}
}
void Serverbrowser::startQuery()
{
mStopRequested = false;
Start();
}
void Serverbrowser::Run()
{
CURL* cHandle = curl_easy_init();

View File

@ -72,7 +72,7 @@ namespace ServerFilter
class Serverbrowser : public Thread
class Serverbrowser : protected Thread
{
bool mStopRequested;
std::string mBuffer;
@ -90,7 +90,10 @@ class Serverbrowser : public Thread
public:
Serverbrowser( Fl_Browser* box );
void stopReading() { mStopRequested = true; }
~Serverbrowser();
void startQuery();
void stopQuery() { mStopRequested = true; }
bool isBusy() { return IsAlive(); }
void onSelection( void* ptr, Fl_Input* input );
void onHeaderClick( int x );
void setFilter( ServerFilter::Flags newFlags );
@ -100,6 +103,7 @@ public:
}; //namespace spades
//saves casting when working with enum.
inline static spades::ServerFilter::Flags& operator |= (spades::ServerFilter::Flags& a, const spades::ServerFilter::Flags b)
{
a = static_cast<spades::ServerFilter::Flags>(static_cast<unsigned int>(a) | static_cast<unsigned int>(b));

View File

@ -13,5 +13,11 @@
#include <OpenGL/gl3.h>
#include <OpenGL/gl3ext.h>
#else
#include <GL/glew.h> // <glew.h>?
#include <GL/glew.h>
// v3.3 / GL_ARB_occlusion_query2
#ifndef GL_ANY_SAMPLES_PASSED
# define GL_ANY_SAMPLES_PASSED 0x8C2F
#endif
#endif

View File

@ -0,0 +1,549 @@
/*
Copyright (c) 2013 yvt
This file is part of OpenSpades.
OpenSpades is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenSpades is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Core/Math.h>
#include <stdlib.h>
#include "ScriptManager.h"
#include <new>
namespace spades {
class MathScriptObjectRegistrar: public ScriptObjectRegistrar {
public:
MathScriptObjectRegistrar():
ScriptObjectRegistrar("Math"){}
virtual void Register(ScriptManager *manager, Phase phase) {
asIScriptEngine *eng = manager->GetEngine();
int r;
eng->SetDefaultNamespace("spades");
switch(phase){
case PhaseObjectType:
r = eng->RegisterObjectType("IntVector3",
sizeof(IntVector3),
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLINTS);
manager->CheckError(r);
r = eng->RegisterObjectType("Vector2",
sizeof(Vector2),
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLINTS);
manager->CheckError(r);
r = eng->RegisterObjectType("Vector3",
sizeof(Vector3),
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLINTS);
manager->CheckError(r);
r = eng->RegisterObjectType("Vector4",
sizeof(Vector4),
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLINTS);
manager->CheckError(r);
r = eng->RegisterObjectType("Matrix4",
sizeof(Matrix4),
asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK | asOBJ_APP_CLASS_ALLINTS);
manager->CheckError(r);
break;
case PhaseObjectMember:
struct IntVector3Funcs {
static void Construct1(IntVector3 *self) {
new(self) IntVector3();
}
static void Construct2(const IntVector3& old, IntVector3 *self) {
new(self) IntVector3(old);
}
static void Construct3(int x, int y, int z, IntVector3 *self) {
new(self) IntVector3();
self->x = x; self->y = y; self->z = z;
}
static void Construct4(const Vector3& old, IntVector3 *self) {
new(self) IntVector3();
self->x = (int)old.x; self->y = (int)old.y; self->z = (int)old.z;
}
};
// Register the constructors
r = eng->RegisterObjectBehaviour("IntVector3", asBEHAVE_CONSTRUCT,
"void f()",
asFUNCTION(IntVector3Funcs::Construct1),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("IntVector3", asBEHAVE_CONSTRUCT,
"void f(const IntVector3 &in)",
asFUNCTION(IntVector3Funcs::Construct2),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("IntVector3", asBEHAVE_CONSTRUCT,
"void f(int, int, int)",
asFUNCTION(IntVector3Funcs::Construct3),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("IntVector3", asBEHAVE_CONSTRUCT,
"void f(const Vector3 &in)",
asFUNCTION(IntVector3Funcs::Construct4),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
// Register the operator overloads
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 &opAddAssign(const IntVector3 &in)",
asMETHODPR(IntVector3, operator+=, (const IntVector3 &), IntVector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 &opSubAssign(const IntVector3 &in)",
asMETHODPR(IntVector3, operator-=, (const IntVector3 &), IntVector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 &opMulAssign(const IntVector3 &in)",
asMETHODPR(IntVector3, operator*=, (const IntVector3 &), IntVector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 &opDivAssign(const IntVector3 &in)",
asMETHODPR(IntVector3, operator/=, (const IntVector3 &), IntVector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"bool opEquals(const IntVector3 &in) const",
asMETHODPR(IntVector3, operator==, (const IntVector3 &) const, bool), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 opAdd(const IntVector3 &in) const",
asMETHODPR(IntVector3, operator+, (const IntVector3 &) const, IntVector3), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 opSub(const IntVector3 &in) const",
asMETHODPR(IntVector3, operator-, (const IntVector3 &) const, IntVector3), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 opMul(const IntVector3 &in) const",
asMETHODPR(IntVector3, operator*, (const IntVector3 &) const, IntVector3), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"IntVector3 opDiv(const IntVector3 &in) const",
asMETHODPR(IntVector3, operator/, (const IntVector3 &) const, IntVector3), asCALL_THISCALL);
manager->CheckError(r);
// Register the object methods
r = eng->RegisterObjectMethod("IntVector3",
"int get_ManhattanLength() const",
asMETHOD(IntVector3, GetManhattanLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("IntVector3",
"int get_ChebyshevLength() const",
asMETHOD(IntVector3, GetChebyshevLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("int Dot(const IntVector3& in, const IntVector3& in)",
asFUNCTION(IntVector3::Dot),
asCALL_CDECL);
manager->CheckError(r);
struct Vector2Funcs {
static void Construct1(Vector2 *self) {
new(self) Vector2();
}
static void Construct2(const Vector2& old, Vector2 *self) {
new(self) Vector2(old);
}
static void Construct3(float x, float y, Vector2 *self) {
new(self) Vector2();
self->x = x; self->y = y;
}
};
// Register the constructors
r = eng->RegisterObjectBehaviour("Vector2", asBEHAVE_CONSTRUCT,
"void f()",
asFUNCTION(Vector2Funcs::Construct1),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("Vector2", asBEHAVE_CONSTRUCT,
"void f(const Vector2 &in)",
asFUNCTION(Vector2Funcs::Construct2),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("Vector2", asBEHAVE_CONSTRUCT,
"void f(float, float)",
asFUNCTION(Vector2Funcs::Construct3),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
// Register the operator overloads
r = eng->RegisterObjectMethod("Vector2",
"Vector2 &opAddAssign(const Vector2 &in)",
asMETHODPR(Vector2, operator+=, (const Vector2 &), Vector2&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"Vector2 &opSubAssign(const Vector2 &in)",
asMETHODPR(Vector2, operator-=, (const Vector2 &), Vector2&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"Vector2 &opMulAssign(const Vector2 &in)",
asMETHODPR(Vector2, operator*=, (const Vector2 &), Vector2&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"Vector2 &opDivAssign(const Vector2 &in)",
asMETHODPR(Vector2, operator/=, (const Vector2 &), Vector2&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"bool opEquals(const Vector2 &in) const",
asMETHODPR(Vector2, operator==, (const Vector2 &) const, bool), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"Vector2 opAdd(const Vector2 &in) const",
asMETHODPR(Vector2, operator+, (const Vector2 &) const, Vector2), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"Vector2 opSub(const Vector2 &in) const",
asMETHODPR(Vector2, operator-, (const Vector2 &) const, Vector2), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"Vector2 opMul(const Vector2 &in) const",
asMETHODPR(Vector2, operator*, (const Vector2 &) const, Vector2), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"Vector2 opDiv(const Vector2 &in) const",
asMETHODPR(Vector2, operator/, (const Vector2 &) const, Vector2), asCALL_THISCALL);
manager->CheckError(r);
// Register the object methods
r = eng->RegisterObjectMethod("Vector2",
"float get_Length() const",
asMETHOD(Vector2, GetLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"float get_LengthPowered() const",
asMETHOD(Vector2, GetPoweredLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"float get_ManhattanLength() const",
asMETHOD(Vector2, GetManhattanLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"float get_ChebyshevLength() const",
asMETHOD(Vector2, GetChebyshevLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector2",
"float get_Normalized() const",
asMETHOD(Vector2, Normalize),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("float Dot(const Vector2& in, const Vector2& in)",
asFUNCTION(Vector2::Dot),
asCALL_CDECL);
manager->CheckError(r);
struct Vector3Funcs {
static void Construct1(Vector3 *self) {
new(self) Vector3();
}
static void Construct2(const Vector3& old, Vector3 *self) {
new(self) Vector3(old);
}
static void Construct3(float x, float y, float z, Vector3 *self) {
new(self) Vector3();
self->x = x; self->y = y; self->z = z;
}
static void Construct4(const IntVector3& old, Vector3 *self) {
new(self) Vector3();
self->x = old.x; self->y = old.y; self->z = old.z;
}
static Vector3 Floor(const Vector3& v) {
return Vector3::Make(floorf(v.x), floorf(v.y), floorf(v.z));
}
static Vector3 Ceil(const Vector3& v) {
return Vector3::Make(ceilf(v.x), ceilf(v.y), ceilf(v.z));
}
};
// Register the constructors
r = eng->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT,
"void f()",
asFUNCTION(Vector3Funcs::Construct1),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT,
"void f(const Vector3 &in)",
asFUNCTION(Vector3Funcs::Construct2),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT,
"void f(float, float, float)",
asFUNCTION(Vector3Funcs::Construct3),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT,
"void f(const IntVector3&in)",
asFUNCTION(Vector3Funcs::Construct4),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
// Register the operator overloads
r = eng->RegisterObjectMethod("Vector3",
"Vector3 &opAddAssign(const Vector3 &in)",
asMETHODPR(Vector3, operator+=, (const Vector3 &), Vector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"Vector3 &opSubAssign(const Vector3 &in)",
asMETHODPR(Vector3, operator-=, (const Vector3 &), Vector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"Vector3 &opMulAssign(const Vector3 &in)",
asMETHODPR(Vector3, operator*=, (const Vector3 &), Vector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"Vector3 &opDivAssign(const Vector3 &in)",
asMETHODPR(Vector3, operator/=, (const Vector3 &), Vector3&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"bool opEquals(const Vector3 &in) const",
asMETHODPR(Vector3, operator==, (const Vector3 &) const, bool), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"Vector3 opAdd(const Vector3 &in) const",
asMETHODPR(Vector3, operator+, (const Vector3 &) const, Vector3), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"Vector3 opSub(const Vector3 &in) const",
asMETHODPR(Vector3, operator-, (const Vector3 &) const, Vector3), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"Vector3 opMul(const Vector3 &in) const",
asMETHODPR(Vector3, operator*, (const Vector3 &) const, Vector3), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"Vector3 opDiv(const Vector3 &in) const",
asMETHODPR(Vector3, operator/, (const Vector3 &) const, Vector3), asCALL_THISCALL);
manager->CheckError(r);
// Register the object methods
r = eng->RegisterObjectMethod("Vector3",
"float get_Length() const",
asMETHOD(Vector3, GetLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"float get_LengthPowered() const",
asMETHOD(Vector3, GetPoweredLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"float get_ManhattanLength() const",
asMETHOD(Vector3, GetManhattanLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"float get_ChebyshevLength() const",
asMETHOD(Vector3, GetChebyshevLength),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Vector3",
"float get_Normalized() const",
asMETHOD(Vector3, Normalize),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("float Dot(const Vector3& in, const Vector3& in)",
asFUNCTION(Vector3::Dot),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Vector3 Floor(const Vector3& in)",
asFUNCTION(Vector3Funcs::Floor),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Vector3 Ceil(const Vector3& in)",
asFUNCTION(Vector3Funcs::Ceil),
asCALL_CDECL);
manager->CheckError(r);
struct Matrix4Funcs {
static void Construct1(Matrix4 *self) {
new(self) Matrix4();
*self = Matrix4::Identity();
}
static void Construct2(const Matrix4& old, Matrix4 *self) {
new(self) Matrix4(old);
}
static void Construct3(float m00, float m10, float m20, float m30,
float m01, float m11, float m21, float m31,
float m02, float m12, float m22, float m32,
float m03, float m13, float m23, float m33,
Matrix4 *self) {
new(self) Matrix4(m00, m10, m20, m30,
m01, m11, m21, m31,
m02, m12, m22, m32,
m03, m13, m23, m33);
}
};
// Register the constructors
r = eng->RegisterObjectBehaviour("Matrix4", asBEHAVE_CONSTRUCT,
"void f()",
asFUNCTION(Matrix4Funcs::Construct1),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("Matrix4", asBEHAVE_CONSTRUCT,
"void f(const Matrix4 &in)",
asFUNCTION(Matrix4Funcs::Construct2),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
r = eng->RegisterObjectBehaviour("Matrix4", asBEHAVE_CONSTRUCT,
"void f(float, float, float, float,"
"float, float, float, float,"
"float, float, float, float,"
"float, float, float, float)",
asFUNCTION(Matrix4Funcs::Construct3),
asCALL_CDECL_OBJLAST);
manager->CheckError(r);
// Register the operator overloads
r = eng->RegisterObjectMethod("Matrix4",
"Matrix4 &opMulAssign(const Matrix4 &in)",
asMETHODPR(Matrix4, operator*=, (const Matrix4 &), Matrix4&), asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Matrix4",
"Matrix4 opMul(const Matrix4 &in) const",
asMETHODPR(Matrix4, operator*, (const Matrix4 &) const, Matrix4), asCALL_THISCALL);
manager->CheckError(r);
// Register the object methods
r = eng->RegisterObjectMethod("Matrix4",
"Matrix4 get_Transposed() const",
asMETHOD(Matrix4, Transposed),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Matrix4",
"Matrix4 get_Inversed() const",
asMETHOD(Matrix4, Inversed),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Matrix4",
"float get_InversedFast() const",
asMETHOD(Matrix4, InversedFast),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Matrix4",
"Vector3 GetOrigin() const",
asMETHOD(Matrix4, GetOrigin),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterObjectMethod("Matrix4",
"Vector3 GetAxis(int) const",
asMETHOD(Matrix4, GetAxis),
asCALL_THISCALL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Matrix4 CreateTranslateMatrix(Vector3)",
asFUNCTIONPR(Matrix4::Translate, (Vector3), Matrix4),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Matrix4 CreateTranslateMatrix(float, float, float)",
asFUNCTIONPR(Matrix4::Translate, (float,float,float), Matrix4),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Matrix4 CreateRotateMatrix(Vector3, float)",
asFUNCTION(Matrix4::Rotate),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Matrix4 CreateScaleMatrix(float)",
asFUNCTIONPR(Matrix4::Scale, (float), Matrix4),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Matrix4 CreateScaleMatrix(Vector3)",
asFUNCTIONPR(Matrix4::Scale, (Vector3), Matrix4),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Matrix4 CreateScaleMatrix(float, float, float)",
asFUNCTIONPR(Matrix4::Scale, (float,float,float), Matrix4),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Matrix4 CreateMatrixFromAxes(Vector3,Vector3,Vector3,Vector3)",
asFUNCTION(Matrix4::FromAxis),
asCALL_CDECL);
manager->CheckError(r);
/*** Other Global Functions ***/
r = eng->RegisterGlobalFunction("string Replace(const string&in, const string& in, const string&in)",
asFUNCTION(Replace),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("string TrimSpaces(const string&in)",
asFUNCTION(TrimSpaces),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("float GetRandom()",
asFUNCTION(GetRandom),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("float Mix(float,float,float)",
asFUNCTIONPR(Mix, (float,float,float), float),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Vector2 Mix(Vector2,Vector2,Vector2)",
asFUNCTIONPR(Mix, (Vector2,Vector2,float), Vector2),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("Vector3 Mix(Vector3,Vector3,Vector3)",
asFUNCTIONPR(Mix, (Vector3,Vector3,float), Vector3),
asCALL_CDECL);
manager->CheckError(r);
r = eng->RegisterGlobalFunction("float SmoothStep(float)",
asFUNCTION(SmoothStep),
asCALL_CDECL);
manager->CheckError(r);
break;
}
}
};
static MathScriptObjectRegistrar registrar;
}

View File

@ -19,9 +19,9 @@
*/
#include "ScriptManager.h"
#include "Debug.h"
#include <Core/Debug.h>
#include <vector>
#include "Exception.h"
#include <Core/Exception.h>
namespace spades {

View File

@ -20,17 +20,17 @@
#pragma once
#include "../AngelScript/include/angelscript.h"
#include "../AngelScript/source/scriptany.h"
#include "../AngelScript/source/scriptarray.h"
#include "../AngelScript/source/scriptbuilder.h"
#include "../AngelScript/source/scriptdictionary.h"
#include "../AngelScript/source/scripthandle.h"
#include "../AngelScript/source/scripthelper.h"
#include "../AngelScript/source/scriptmath.h"
#include "../AngelScript/source/scriptmathcomplex.h"
#include "../AngelScript/source/scriptstdstring.h"
#include "../AngelScript/source/weakref.h"
#include <AngelScript/include/angelscript.h>
#include <AngelScript/addons/scriptany.h>
#include <AngelScript/addons/scriptarray.h>
#include <AngelScript/addons/scriptbuilder.h>
#include <AngelScript/addons/scriptdictionary.h>
#include <AngelScript/addons/scripthandle.h>
#include <AngelScript/addons/scripthelper.h>
#include <AngelScript/addons/scriptmath.h>
#include <AngelScript/addons/scriptmathcomplex.h>
#include <AngelScript/addons/scriptstdstring.h>
#include <AngelScript/addons/weakref.h>
namespace spades {