From 3666d1a2ecd258f5911af580b84158ae4c08af31 Mon Sep 17 00:00:00 2001 From: Deve Date: Sun, 25 Mar 2018 23:04:01 +0200 Subject: [PATCH] Allow to use scripting on arm64 --- src/scriptengine/aswrappedcall.hpp | 1017 ++++++++++++++++++++++++ src/scriptengine/script_audio.cpp | 12 +- src/scriptengine/script_challenges.cpp | 44 +- src/scriptengine/script_engine.cpp | 1 + src/scriptengine/script_gui.cpp | 35 +- src/scriptengine/script_kart.cpp | 34 +- src/scriptengine/script_physics.cpp | 13 +- src/scriptengine/script_track.cpp | 114 ++- src/scriptengine/script_utils.cpp | 51 +- src/scriptengine/scriptvec3.cpp | 34 +- 10 files changed, 1329 insertions(+), 26 deletions(-) create mode 100644 src/scriptengine/aswrappedcall.hpp diff --git a/src/scriptengine/aswrappedcall.hpp b/src/scriptengine/aswrappedcall.hpp new file mode 100644 index 000000000..d34df5767 --- /dev/null +++ b/src/scriptengine/aswrappedcall.hpp @@ -0,0 +1,1017 @@ +#ifndef AS_GEN_WRAPPER_H +#define AS_GEN_WRAPPER_H + +#ifndef ANGELSCRIPT_H +// Avoid having to inform include path if header is already include before +#include +#endif +#include + +namespace gw { + +template class Proxy { + public: + T value; + Proxy(T value) : value(value) {} + static T cast(void * ptr) { + return reinterpret_cast *>(&ptr)->value; + } + private: + Proxy(const Proxy &); + Proxy & operator=(const Proxy &); +}; + +template struct Wrapper {}; +template struct ObjFirst {}; +template struct ObjLast {}; +template struct Constructor {}; + +template +void destroy(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + static_cast(gen->GetObject())->~T(); +} +template <> +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)()); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)()); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)()); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)()); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)()); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)()); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + Proxy::cast(gen->GetObject()))); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + Proxy::cast(gen->GetObject()))); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + Proxy::cast(gen->GetObject()))); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + Proxy::cast(gen->GetObject()))); + } +}; +template +struct Constructor { + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetObject()) T(); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value)); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + Proxy::cast(gen->GetObject()), + static_cast *>(gen->GetAddressOfArg(0))->value)); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + Proxy::cast(gen->GetObject()), + static_cast *>(gen->GetAddressOfArg(0))->value)); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + Proxy::cast(gen->GetObject()))); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + Proxy::cast(gen->GetObject()))); + } +}; +template +struct Constructor { + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetObject()) T( + static_cast *>(gen->GetAddressOfArg(0))->value); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value)); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + Proxy::cast(gen->GetObject()), + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value)); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + Proxy::cast(gen->GetObject()), + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value)); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + Proxy::cast(gen->GetObject()))); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + Proxy::cast(gen->GetObject()))); + } +}; +template +struct Constructor { + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetObject()) T( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value)); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + Proxy::cast(gen->GetObject()), + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value)); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + Proxy::cast(gen->GetObject()), + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value)); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + Proxy::cast(gen->GetObject()))); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + Proxy::cast(gen->GetObject()))); + } +}; +template +struct Constructor { + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetObject()) T( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value)); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + Proxy::cast(gen->GetObject()), + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value)); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + Proxy::cast(gen->GetObject()), + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value)); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + Proxy::cast(gen->GetObject()))); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + Proxy::cast(gen->GetObject()))); + } +}; +template +struct Constructor { + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetObject()) T( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value)); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + Proxy::cast(gen->GetObject()), + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value)); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + Proxy::cast(gen->GetObject()), + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value)); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + Proxy::cast(gen->GetObject()))); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + Proxy::cast(gen->GetObject()))); + } +}; +template +struct Constructor { + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetObject()) T( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value)); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + Proxy::cast(gen->GetObject()), + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value)); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + Proxy::cast(gen->GetObject()), + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value)); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value, + Proxy::cast(gen->GetObject()))); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value, + Proxy::cast(gen->GetObject()))); + } +}; +template +struct Constructor { + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetObject()) T( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value, + static_cast *>(gen->GetAddressOfArg(6))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value, + static_cast *>(gen->GetAddressOfArg(6))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value, + static_cast *>(gen->GetAddressOfArg(6))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value, + static_cast *>(gen->GetAddressOfArg(6))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value, + static_cast *>(gen->GetAddressOfArg(6))->value)); + } +}; +template +struct Wrapper { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((static_cast(gen->GetObject())->*fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value, + static_cast *>(gen->GetAddressOfArg(6))->value)); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + Proxy::cast(gen->GetObject()), + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value, + static_cast *>(gen->GetAddressOfArg(6))->value)); + } +}; +template +struct ObjFirst { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + Proxy::cast(gen->GetObject()), + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value, + static_cast *>(gen->GetAddressOfArg(6))->value)); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + ((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value, + static_cast *>(gen->GetAddressOfArg(6))->value, + Proxy::cast(gen->GetObject()))); + } +}; +template +struct ObjLast { + template + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetAddressOfReturnLocation()) Proxy((fp)( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value, + static_cast *>(gen->GetAddressOfArg(6))->value, + Proxy::cast(gen->GetObject()))); + } +}; +template +struct Constructor { + static void f(AS_NAMESPACE_QUALIFIER asIScriptGeneric * gen) { + new (gen->GetObject()) T( + static_cast *>(gen->GetAddressOfArg(0))->value, + static_cast *>(gen->GetAddressOfArg(1))->value, + static_cast *>(gen->GetAddressOfArg(2))->value, + static_cast *>(gen->GetAddressOfArg(3))->value, + static_cast *>(gen->GetAddressOfArg(4))->value, + static_cast *>(gen->GetAddressOfArg(5))->value, + static_cast *>(gen->GetAddressOfArg(6))->value); + } +}; +template +struct Id { + template AS_NAMESPACE_QUALIFIER asSFuncPtr f(void) { return asFUNCTION(&Wrapper::template f); } + template AS_NAMESPACE_QUALIFIER asSFuncPtr of(void) { return asFUNCTION(&ObjFirst::template f); } + template AS_NAMESPACE_QUALIFIER asSFuncPtr ol(void) { return asFUNCTION(&ObjLast::template f); } +}; + +template +Id id(T fn_ptr) { return Id(); } + +// On some versions of GNUC it is necessary to use the template keyword as disambiguator, +// on others the template keyword gives an error, hence the need for the following define. +// MSVC on the other hand seems to accept both with or without the template keyword. +#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4)) + // GNUC 4.4.3 doesn't need the template keyword, and + // hopefully upcoming versions won't need it either + #define TMPL template +#else + #define TMPL +#endif + +#define WRAP_FN(name) (::gw::id(name).TMPL f< name >()) +#define WRAP_MFN(ClassType, name) (::gw::id(&ClassType::name).TMPL f< &ClassType::name >()) +#define WRAP_OBJ_FIRST(name) (::gw::id(name).TMPL of< name >()) +#define WRAP_OBJ_LAST(name) (::gw::id(name).TMPL ol< name >()) + +#define WRAP_FN_PR(name, Parameters, ReturnType) asFUNCTION((::gw::Wrapper::TMPL f< name >)) +#define WRAP_MFN_PR(ClassType, name, Parameters, ReturnType) asFUNCTION((::gw::Wrapper::TMPL f< &ClassType::name >)) +#define WRAP_OBJ_FIRST_PR(name, Parameters, ReturnType) asFUNCTION((::gw::ObjFirst::TMPL f< name >)) +#define WRAP_OBJ_LAST_PR(name, Parameters, ReturnType) asFUNCTION((::gw::ObjLast::TMPL f< name >)) + +#define WRAP_CON(ClassType, Parameters) asFUNCTION((::gw::Constructor::f)) +#define WRAP_DES(ClassType) asFUNCTION((::gw::destroy)) + +} // end namespace gw + +#endif diff --git a/src/scriptengine/script_audio.cpp b/src/scriptengine/script_audio.cpp index 673ef8ab0..1b56fc025 100644 --- a/src/scriptengine/script_audio.cpp +++ b/src/scriptengine/script_audio.cpp @@ -18,9 +18,11 @@ #include "script_audio.hpp" #include "audio/sfx_manager.hpp" +#include "scriptengine/aswrappedcall.hpp" #include #include +#include /** \cond DOXYGEN_IGNORE */ namespace Scripting @@ -50,7 +52,15 @@ namespace Scripting { int r; // of type asERetCodes engine->SetDefaultNamespace("Audio"); - r = engine->RegisterGlobalFunction("void playSound(const string &in)", asFUNCTION(playSound), asCALL_CDECL); assert(r >= 0); + + if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY")) + { + r = engine->RegisterGlobalFunction("void playSound(const string &in)", WRAP_FN(playSound), asCALL_GENERIC); assert(r >= 0); + } + else + { + r = engine->RegisterGlobalFunction("void playSound(const string &in)", asFUNCTION(playSound), asCALL_CDECL); assert(r >= 0); + } } } diff --git a/src/scriptengine/script_challenges.cpp b/src/scriptengine/script_challenges.cpp index d1340afaa..415e0ef57 100644 --- a/src/scriptengine/script_challenges.cpp +++ b/src/scriptengine/script_challenges.cpp @@ -30,6 +30,7 @@ #include "tracks/track.hpp" #include "tracks/track_object.hpp" #include "tracks/track_object_manager.hpp" +#include "scriptengine/aswrappedcall.hpp" #include #include @@ -107,11 +108,34 @@ namespace Scripting /** @}*/ /** @}*/ - void registerScriptFunctions(asIScriptEngine *engine) + void registerScriptFunctions_Generic(asIScriptEngine *engine) { int r; // of type asERetCodes + + r = engine->RegisterGlobalFunction("int getCompletedChallengesCount()", + WRAP_FN(getCompletedChallengesCount), + asCALL_GENERIC); + assert( r >= 0 ); - engine->SetDefaultNamespace("Challenges"); + r = engine->RegisterGlobalFunction("int getChallengeCount()", + WRAP_FN(getChallengeCount), + asCALL_GENERIC); + assert( r >= 0 ); + + r = engine->RegisterGlobalFunction("bool isChallengeUnlocked(string &in)", + WRAP_FN(isChallengeUnlocked), + asCALL_GENERIC); + assert( r >= 0 ); + + r = engine->RegisterGlobalFunction("int getChallengeRequiredPoints(string &in)", + WRAP_FN(getChallengeRequiredPoints), + asCALL_GENERIC); + assert( r >= 0 ); + } + + void registerScriptFunctions_Native(asIScriptEngine *engine) + { + int r; // of type asERetCodes r = engine->RegisterGlobalFunction("int getCompletedChallengesCount()", asFUNCTION(getCompletedChallengesCount), @@ -129,7 +153,21 @@ namespace Scripting asFUNCTION(getChallengeRequiredPoints), asCALL_CDECL); assert(r >= 0); - } // registerScriptFunctions + } + + void registerScriptFunctions(asIScriptEngine *engine) + { + engine->SetDefaultNamespace("Challenges"); + + if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY")) + { + registerScriptFunctions_Generic(engine); + } + else + { + registerScriptFunctions_Native(engine); + } + } // registerScriptFunctions } // namespace Challenges diff --git a/src/scriptengine/script_engine.cpp b/src/scriptengine/script_engine.cpp index 2c1ccbf3e..7a13aea5a 100644 --- a/src/scriptengine/script_engine.cpp +++ b/src/scriptengine/script_engine.cpp @@ -21,6 +21,7 @@ #include "io/file_manager.hpp" #include "karts/kart.hpp" #include "modes/world.hpp" +#include "scriptengine/aswrappedcall.hpp" #include "scriptengine/script_audio.hpp" #include "scriptengine/script_challenges.hpp" #include "scriptengine/script_kart.hpp" diff --git a/src/scriptengine/script_gui.cpp b/src/scriptengine/script_gui.cpp index 74418d701..996c9eaae 100644 --- a/src/scriptengine/script_gui.cpp +++ b/src/scriptengine/script_gui.cpp @@ -23,6 +23,7 @@ #include "input/input_device.hpp" #include "input/input_manager.hpp" #include "modes/world.hpp" +#include "scriptengine/aswrappedcall.hpp" #include "states_screens/dialogs/tutorial_message_dialog.hpp" #include "tracks/track.hpp" #include "tracks/track_object.hpp" @@ -165,11 +166,25 @@ namespace Scripting return translate(formatString, arg1, arg2, arg3); } /** \endcond */ - - void registerScriptFunctions(asIScriptEngine *engine) + + void registerScriptFunctions_Generic(asIScriptEngine *engine) { int r; // of type asERetCodes - engine->SetDefaultNamespace("GUI"); + + r = engine->RegisterGlobalFunction("void displayModalMessage(const string &in)", WRAP_FN(displayModalMessage), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void displayOverlayMessage(const string &in)", WRAP_FN(displayOverlayMessage), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void clearOverlayMessages()", WRAP_FN(clearOverlayMessages), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("string getKeyBinding(int input)", WRAP_FN(getKeyBinding), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("string translate(const string &in)", WRAP_FN(proxy_translate), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("string translate(const string &in, const string &in)", WRAP_FN(proxy_translateAndInsertValues1), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("string translate(const string &in, const string &in, const string &in)", WRAP_FN(proxy_translateAndInsertValues2), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("string translate(const string &in, const string &in, const string &in, const string &in)", WRAP_FN(proxy_translateAndInsertValues3), asCALL_GENERIC); assert(r >= 0); + } + + void registerScriptFunctions_Native(asIScriptEngine *engine) + { + int r; // of type asERetCodes + r = engine->RegisterGlobalFunction("void displayModalMessage(const string &in)", asFUNCTION(displayModalMessage), asCALL_CDECL); assert(r >= 0); r = engine->RegisterGlobalFunction("void displayOverlayMessage(const string &in)", asFUNCTION(displayOverlayMessage), asCALL_CDECL); assert(r >= 0); r = engine->RegisterGlobalFunction("void clearOverlayMessages()", asFUNCTION(clearOverlayMessages), asCALL_CDECL); assert(r >= 0); @@ -179,6 +194,20 @@ namespace Scripting r = engine->RegisterGlobalFunction("string translate(const string &in, const string &in, const string &in)", asFUNCTION(proxy_translateAndInsertValues2), asCALL_CDECL); assert(r >= 0); r = engine->RegisterGlobalFunction("string translate(const string &in, const string &in, const string &in, const string &in)", asFUNCTION(proxy_translateAndInsertValues3), asCALL_CDECL); assert(r >= 0); } + + void registerScriptFunctions(asIScriptEngine *engine) + { + engine->SetDefaultNamespace("GUI"); + + if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY")) + { + registerScriptFunctions_Generic(engine); + } + else + { + registerScriptFunctions_Native(engine); + } + } void registerScriptEnums(asIScriptEngine *engine) { diff --git a/src/scriptengine/script_kart.cpp b/src/scriptengine/script_kart.cpp index 38dce873a..47ed32b7c 100644 --- a/src/scriptengine/script_kart.cpp +++ b/src/scriptengine/script_kart.cpp @@ -22,6 +22,7 @@ #include "karts/kart_properties.hpp" #include "modes/world.hpp" #include "scriptvec3.hpp" +#include "scriptengine/aswrappedcall.hpp" #include #include @@ -128,11 +129,24 @@ namespace Scripting /** @}*/ /** @}*/ - - void registerScriptFunctions(asIScriptEngine *engine) + + void registerScriptFunctions_Generic(asIScriptEngine *engine) { int r; // of type asERetCodes - engine->SetDefaultNamespace("Kart"); + + r = engine->RegisterGlobalFunction("void squash(int id, float time)", WRAP_FN(squash), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void teleport(int id, const Vec3 &in)", WRAP_FN(teleport), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void setVelocity(int id, const Vec3 &in)", WRAP_FN(setVelocity), asCALL_GENERIC); assert(r >= 0); + //r = engine->RegisterGlobalFunction("void jumpTo(int id, float x, float y)", WRAP_FN(jumpTo), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("Vec3 getLocation(int id)", WRAP_FN(getLocation), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("Vec3 getVelocity(int id)", WRAP_FN(getVelocity), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("float getMaxSpeed(int id)", WRAP_FN(getMaxSpeed), asCALL_GENERIC); assert(r >= 0); + } + + void registerScriptFunctions_Native(asIScriptEngine *engine) + { + int r; // of type asERetCodes + r = engine->RegisterGlobalFunction("void squash(int id, float time)", asFUNCTION(squash), asCALL_CDECL); assert(r >= 0); r = engine->RegisterGlobalFunction("void teleport(int id, const Vec3 &in)", asFUNCTION(teleport), asCALL_CDECL); assert(r >= 0); r = engine->RegisterGlobalFunction("void setVelocity(int id, const Vec3 &in)", asFUNCTION(setVelocity), asCALL_CDECL); assert(r >= 0); @@ -141,6 +155,20 @@ namespace Scripting r = engine->RegisterGlobalFunction("Vec3 getVelocity(int id)", asFUNCTION(getVelocity), asCALL_CDECL); assert(r >= 0); r = engine->RegisterGlobalFunction("float getMaxSpeed(int id)", asFUNCTION(getMaxSpeed), asCALL_CDECL); assert(r >= 0); } + + void registerScriptFunctions(asIScriptEngine *engine) + { + engine->SetDefaultNamespace("Kart"); + + if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY")) + { + registerScriptFunctions_Generic(engine); + } + else + { + registerScriptFunctions_Native(engine); + } + } void registerScriptEnums(asIScriptEngine *engine) { diff --git a/src/scriptengine/script_physics.cpp b/src/scriptengine/script_physics.cpp index 22adb3a1c..3e5eb6e4b 100644 --- a/src/scriptengine/script_physics.cpp +++ b/src/scriptengine/script_physics.cpp @@ -19,9 +19,10 @@ #include #include #include "script_physics.hpp" +#include "graphics/explosion.hpp" #include "graphics/hit_effect.hpp" #include "items/projectile_manager.hpp" -#include "graphics/explosion.hpp" +#include "scriptengine/aswrappedcall.hpp" namespace Scripting { @@ -41,7 +42,15 @@ namespace Scripting { int r; engine->SetDefaultNamespace("Physics"); - r = engine->RegisterGlobalFunction("string createExplosion(Vec3 &in)", asFUNCTION(createExplosion), asCALL_GENERIC); assert(r >= 0); + + if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY")) + { + r = engine->RegisterGlobalFunction("string createExplosion(Vec3 &in)", WRAP_FN(createExplosion), asCALL_GENERIC); assert(r >= 0); + } + else + { + r = engine->RegisterGlobalFunction("string createExplosion(Vec3 &in)", asFUNCTION(createExplosion), asCALL_GENERIC); assert(r >= 0); + } } } } diff --git a/src/scriptengine/script_track.cpp b/src/scriptengine/script_track.cpp index 5d327df91..bb3daf30b 100644 --- a/src/scriptengine/script_track.cpp +++ b/src/scriptengine/script_track.cpp @@ -30,6 +30,7 @@ #include "input/input_manager.hpp" #include "modes/world.hpp" #include "scriptengine/property_animator.hpp" +#include "scriptengine/aswrappedcall.hpp" #include "states_screens/dialogs/tutorial_message_dialog.hpp" #include "states_screens/dialogs/race_paused_dialog.hpp" #include "tracks/track.hpp" @@ -447,20 +448,89 @@ namespace Scripting /** @}*/ /** @}*/ - - void registerScriptFunctions(asIScriptEngine *engine) + + void registerScriptFunctions_Generic(asIScriptEngine *engine) { int r; // of type asERetCodes + + //r = engine->RegisterGlobalFunction("void disableTrackObject(const string &in)", WRAP_FN(disableTrackObject), asCALL_GENERIC); assert(r >= 0); + //r = engine->RegisterGlobalFunction("void enableTrackObject(const string &in)", WRAP_FN(enableTrackObject), asCALL_GENERIC); assert(r >= 0); + //r = engine->RegisterGlobalFunction("void enableTrigger(const string &in)", WRAP_FN(enableTrigger), asCALL_GENERIC); assert(r >= 0); + //r = engine->RegisterGlobalFunction("void disableTrigger(const string &in)", WRAP_FN(disableTrigger), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void createTrigger(const string &in, const Vec3 &in, float distance)", + WRAP_FN(createTrigger), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void createTextBillboard(const string &in, const Vec3 &in)", + WRAP_FN(createTextBillboard), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void setTriggerReenableTimeout(const string &in, const string &in, float reenable_time)", + WRAP_FN(setTriggerReenableTimeout), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("TrackObject@ getTrackObject(const string &in, const string &in)", WRAP_FN(getTrackObject), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void exitRace()", WRAP_FN(exitRace), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void pauseRace()", WRAP_FN(pauseRace), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void setFog(float maxDensity, float start, float end, int r, int g, int b, float duration)", WRAP_FN(setFog), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("int getNumberOfKarts()", WRAP_FN(getNumberOfKarts), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("int getNumLocalPlayers()", WRAP_FN(getNumLocalPlayers), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("bool isReverse()", WRAP_FN(isTrackReverse), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("int getMajorRaceMode()", WRAP_FN(getMajorRaceMode), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("int getMinorRaceMode()", WRAP_FN(getMinorRaceMode), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("bool isDuringDay()", WRAP_FN(isDuringDay), asCALL_GENERIC); assert(r >= 0); - engine->SetDefaultNamespace("Track"); + // TrackObject + r = engine->RegisterObjectMethod("TrackObject", "void setEnabled(bool status)", WRAP_MFN(::TrackObject, setEnabled), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "SoundEmitter@ getSoundEmitter()", WRAP_MFN(::TrackObject, getSoundEmitter), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "Light@ getLight()", WRAP_MFN(::TrackObject, getLight), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "PhysicalObject@ getPhysics()", WRAP_MFN(::TrackObject, getPhysics), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "Mesh@ getMesh()", WRAP_MFN(::TrackObject, getMesh), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "ParticleEmitter@ getParticleEmitter()", WRAP_MFN(::TrackObject, getParticleEmitter), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "Animator@ getIPOAnimator()", WRAP_MFN(::TrackObject, getIPOAnimator), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "void moveTo(const Vec3 &in, bool)", WRAP_MFN(::TrackObject, moveTo), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "Vec3 getCenterPosition()", WRAP_OBJ_LAST(TrackObject::getCenterPosition), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "Vec3 getOrigin()", WRAP_OBJ_LAST(TrackObject::getOrigin), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "TrackObject@ getParentLibrary()", WRAP_MFN(::TrackObject, getParentLibrary), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("TrackObject", "string getName()", WRAP_MFN(::TrackObject, getName), asCALL_GENERIC); assert(r >= 0); - r = engine->RegisterObjectType("TrackObject", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); - r = engine->RegisterObjectType("PhysicalObject", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); - r = engine->RegisterObjectType("Mesh", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); // TrackObjectPresentationMesh - r = engine->RegisterObjectType("ParticleEmitter", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); - r = engine->RegisterObjectType("SoundEmitter", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); - r = engine->RegisterObjectType("Animator", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); - r = engine->RegisterObjectType("Light", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); + // PhysicalObject + r = engine->RegisterObjectMethod("PhysicalObject", "bool isFlattenKartObject()", WRAP_MFN(PhysicalObject, isFlattenKartObject), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("PhysicalObject", "void disable()", WRAP_MFN(PhysicalObject, disable), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("PhysicalObject", "void enable()", WRAP_MFN(PhysicalObject, enable), asCALL_GENERIC); assert(r >= 0); + + // Animated Mesh + r = engine->RegisterObjectMethod("Mesh", "void setFrameLoop(int start, int end)", WRAP_OBJ_LAST(Mesh::setFrameLoop), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("Mesh", "void setFrameLoopOnce(int start, int end)", WRAP_OBJ_LAST(Mesh::setFrameLoopOnce), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("Mesh", "int getFrameNr()", WRAP_OBJ_LAST(Mesh::getFrameNr), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("Mesh", "int getAnimationSet()", WRAP_OBJ_LAST(Mesh::getAnimationSet), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("Mesh", "void useAnimationSet(int set_num)", WRAP_OBJ_LAST(Mesh::useAnimationSet), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("Mesh", "void addAnimationSet(int start, int end)", WRAP_OBJ_LAST(Mesh::addAnimationSet), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("Mesh", "void removeAllAnimationSet()", WRAP_OBJ_LAST(Mesh::removeAllAnimationSet), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("Mesh", "void setCurrentFrame(int frame)", WRAP_OBJ_LAST(Mesh::setCurrentFrame), asCALL_GENERIC); assert(r >= 0); + //r = engine->RegisterObjectMethod("Mesh", "void move(Vec3 &in)", WRAP_OBJ_LAST(movePresentation), asCALL_GENERIC); assert(r >= 0); + + // Particle Emitter + r = engine->RegisterObjectMethod("ParticleEmitter", "void stop()", WRAP_OBJ_LAST(ParticleEmitter::stop), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("ParticleEmitter", "void stopIn(float)", WRAP_OBJ_LAST(ParticleEmitter::stopIn), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("ParticleEmitter", "void setEmissionRate(float)", WRAP_OBJ_LAST(ParticleEmitter::setEmissionRate), asCALL_GENERIC); assert(r >= 0); + + // Sound Effect + //r = engine->RegisterObjectMethod("SoundEmitter", "void move(Vec3 &in)", WRAP_OBJ_LAST(movePresentation), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("SoundEmitter", "void stop()", WRAP_OBJ_LAST(SoundEmitter::stop), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("SoundEmitter", "void playOnce()", WRAP_OBJ_LAST(SoundEmitter::playOnce), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("SoundEmitter", "void playLoop()", WRAP_OBJ_LAST(SoundEmitter::playLoop), asCALL_GENERIC); assert(r >= 0); + + // Light + r = engine->RegisterObjectMethod("Light", "void setEnergy(float)", WRAP_OBJ_LAST(Light::setEnergy), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("Light", "void animateEnergy(float, float)", WRAP_OBJ_LAST(Light::animateEnergy), asCALL_GENERIC); assert(r >= 0); + + // Curve based Animation + //fails due to insufficient visibility to scripts TODO : Decide whether to fix visibility or introduce wrappers + //r = engine->RegisterObjectMethod("Animator", "void setPaused(bool mode)", WRAP_MFN(ThreeDAnimation, setPaused), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("Animator", "void setPaused(bool mode)", WRAP_OBJ_LAST(Animator::setPaused), asCALL_GENERIC); assert(r >= 0); + // TODO: add method to set current frame + // TODO: add method to launch playback from frame X to frame Y + // TODO: add method to register onAnimationComplete notifications ? + } + + void registerScriptFunctions_Native(asIScriptEngine *engine) + { + int r; // of type asERetCodes //r = engine->RegisterGlobalFunction("void disableTrackObject(const string &in)", asFUNCTION(disableTrackObject), asCALL_CDECL); assert(r >= 0); //r = engine->RegisterGlobalFunction("void enableTrackObject(const string &in)", asFUNCTION(enableTrackObject), asCALL_CDECL); assert(r >= 0); @@ -536,6 +606,30 @@ namespace Scripting // TODO: add method to launch playback from frame X to frame Y // TODO: add method to register onAnimationComplete notifications ? } + + void registerScriptFunctions(asIScriptEngine *engine) + { + int r; // of type asERetCodes + + engine->SetDefaultNamespace("Track"); + + r = engine->RegisterObjectType("TrackObject", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); + r = engine->RegisterObjectType("PhysicalObject", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); + r = engine->RegisterObjectType("Mesh", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); // TrackObjectPresentationMesh + r = engine->RegisterObjectType("ParticleEmitter", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); + r = engine->RegisterObjectType("SoundEmitter", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); + r = engine->RegisterObjectType("Animator", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); + r = engine->RegisterObjectType("Light", 0, asOBJ_REF | asOBJ_NOCOUNT); assert(r >= 0); + + if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY")) + { + registerScriptFunctions_Generic(engine); + } + else + { + registerScriptFunctions_Native(engine); + } + } /** \cond DOXYGEN_IGNORE */ } diff --git a/src/scriptengine/script_utils.cpp b/src/scriptengine/script_utils.cpp index 03f698569..f791473e1 100644 --- a/src/scriptengine/script_utils.cpp +++ b/src/scriptengine/script_utils.cpp @@ -22,6 +22,7 @@ #include "input/device_manager.hpp" #include "input/input_device.hpp" #include "input/input_manager.hpp" +#include "scriptengine/aswrappedcall.hpp" #include "scriptengine/script_engine.hpp" #include "states_screens/dialogs/tutorial_message_dialog.hpp" #include "tracks/track.hpp" @@ -135,6 +136,15 @@ namespace Scripting { ScriptEngine::getInstance()->addPendingTimeout(delay, obj); } + + void setTimeoutDelegate_Generic(asIScriptGeneric *gen) + { + asIScriptFunction *obj = (asIScriptFunction*)gen->GetArgAddress(0); + float delay = gen->GetArgFloat(1); + obj->AddRef(); + ScriptEngine::getInstance()->addPendingTimeout(delay, obj); + } + /** Log to the console */ void logInfo(std::string* log) @@ -180,10 +190,33 @@ namespace Scripting } /** \endcond */ - void registerScriptFunctions(asIScriptEngine *engine) + void registerScriptFunctions_Generic(asIScriptEngine *engine) + { + int r; // of type asERetCodes + + r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in)", WRAP_FN(proxy_insertValues1), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in, const string &in)", WRAP_FN(proxy_insertValues2), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in, const string &in, const string &in)", WRAP_FN(proxy_insertValues3), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in, const string &in, const string &in, const string &in)", WRAP_FN(proxy_insertValues4), asCALL_GENERIC); assert(r >= 0); + + r = engine->RegisterGlobalFunction("void runScript(string &in)", WRAP_FN(runScript), asCALL_GENERIC); assert(r >= 0); + + r = engine->RegisterGlobalFunction("int randomInt(int, int)", WRAP_FN(randomInt), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("float randomFloat(int, int)", WRAP_FN(randomFloat), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void setTimeout(const string &in, float)", WRAP_FN(setTimeout), asCALL_GENERIC); assert(r >= 0); + + r = engine->RegisterFuncdef("void TimeoutCallback()"); assert(r >= 0); + r = engine->RegisterGlobalFunction("void setTimeoutDelegate(TimeoutCallback@, float)", asFUNCTION(setTimeoutDelegate_Generic), asCALL_GENERIC); assert(r >= 0); + //~ r = engine->RegisterGlobalFunction("void setTimeoutDelegate(TimeoutCallback@, float)", WRAP_FN(setTimeoutDelegate), asCALL_GENERIC); assert(r >= 0); + + r = engine->RegisterGlobalFunction("void logInfo(const string &in)", WRAP_FN(logInfo), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void logWarning(const string &in)", WRAP_FN(logWarning), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void logError(const string &in)", WRAP_FN(logError), asCALL_GENERIC); assert(r >= 0); + } + + void registerScriptFunctions_Native(asIScriptEngine *engine) { int r; // of type asERetCodes - engine->SetDefaultNamespace("Utils"); r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in)", asFUNCTION(proxy_insertValues1), asCALL_CDECL); assert(r >= 0); r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in, const string &in)", asFUNCTION(proxy_insertValues2), asCALL_CDECL); assert(r >= 0); @@ -203,6 +236,20 @@ namespace Scripting r = engine->RegisterGlobalFunction("void logWarning(const string &in)", asFUNCTION(logWarning), asCALL_CDECL); assert(r >= 0); r = engine->RegisterGlobalFunction("void logError(const string &in)", asFUNCTION(logError), asCALL_CDECL); assert(r >= 0); } + + void registerScriptFunctions(asIScriptEngine *engine) + { + engine->SetDefaultNamespace("Utils"); + + if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY")) + { + registerScriptFunctions_Generic(engine); + } + else + { + registerScriptFunctions_Native(engine); + } + } } /** \cond DOXYGEN_IGNORE */ diff --git a/src/scriptengine/scriptvec3.cpp b/src/scriptengine/scriptvec3.cpp index b2eab94eb..c70e1b403 100644 --- a/src/scriptengine/scriptvec3.cpp +++ b/src/scriptengine/scriptvec3.cpp @@ -21,6 +21,7 @@ #include "karts/kart.hpp" #include "script_kart.hpp" #include "scriptvec3.hpp" +#include "scriptengine/aswrappedcall.hpp" //debug #include @@ -59,10 +60,24 @@ namespace Scripting float getZ(SimpleVec3* v) { return v->getZ(); } float getLength(SimpleVec3* v) { return v->getLength(); } - void RegisterVec3(asIScriptEngine *engine) + void RegisterVec3_Generic(asIScriptEngine *engine) + { + int r; + // Register the behaviours + r = engine->RegisterObjectBehaviour("Vec3", asBEHAVE_CONSTRUCT, "void f()", WRAP_OBJ_LAST(Constructor), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectBehaviour("Vec3", asBEHAVE_DESTRUCT, "void f()", WRAP_OBJ_LAST(Destructor), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("Vec3", "Vec3 &opAssign(const Vec3 &in)", WRAP_MFN_PR(SimpleVec3, operator =, (const SimpleVec3&), SimpleVec3&), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectBehaviour("Vec3", asBEHAVE_CONSTRUCT, "void f(float, float, float)", WRAP_OBJ_LAST(ConstructVector3FromFloats), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void printVec3(Vec3 a)", WRAP_FN(printVec3), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("Vec3", "float getX()", WRAP_OBJ_LAST(getX), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("Vec3", "float getY()", WRAP_OBJ_LAST(getY), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("Vec3", "float getZ()", WRAP_OBJ_LAST(getZ), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterObjectMethod("Vec3", "float getLength()", WRAP_OBJ_LAST(getLength), asCALL_GENERIC); assert(r >= 0); + } + + void RegisterVec3_Native(asIScriptEngine *engine) { int r; - r = engine->RegisterObjectType("Vec3", sizeof(SimpleVec3), asOBJ_VALUE | asOBJ_APP_CLASS_ALLFLOATS | asOBJ_APP_CLASS_CDA); assert(r >= 0); // Register the behaviours r = engine->RegisterObjectBehaviour("Vec3", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(Constructor), asCALL_CDECL_OBJLAST); assert(r >= 0); r = engine->RegisterObjectBehaviour("Vec3", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(Destructor), asCALL_CDECL_OBJLAST); assert(r >= 0); @@ -74,4 +89,19 @@ namespace Scripting r = engine->RegisterObjectMethod("Vec3", "float getZ()", asFUNCTION(getZ), asCALL_CDECL_OBJLAST); assert(r >= 0); r = engine->RegisterObjectMethod("Vec3", "float getLength()", asFUNCTION(getLength), asCALL_CDECL_OBJLAST); assert(r >= 0); } + + void RegisterVec3(asIScriptEngine *engine) + { + int r; + r = engine->RegisterObjectType("Vec3", sizeof(SimpleVec3), asOBJ_VALUE | asOBJ_APP_CLASS_ALLFLOATS | asOBJ_APP_CLASS_CDA); assert(r >= 0); + + if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY")) + { + RegisterVec3_Generic(engine); + } + else + { + RegisterVec3_Native(engine); + } + } }