mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +00:00
Use FixedTuple in EngineTrampoline, to make memory-layout consistent
This commit is contained in:
parent
43d2824f49
commit
7d2587ad2b
1 changed files with 37 additions and 6 deletions
|
|
@ -26,6 +26,10 @@
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#ifndef _FIXEDTUPLE_H_
|
||||||
|
#include "fixedTuple.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef _CONSOLETYPES_H_
|
#ifndef _CONSOLETYPES_H_
|
||||||
#include "console/consoleTypes.h"
|
#include "console/consoleTypes.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -347,6 +351,8 @@ struct _EngineTrampoline< R( ArgTs ... ) >
|
||||||
{
|
{
|
||||||
typedef std::tuple<ArgTs ...> Args;
|
typedef std::tuple<ArgTs ...> Args;
|
||||||
std::tuple<ArgTs ...> argT;
|
std::tuple<ArgTs ...> argT;
|
||||||
|
typedef fixed_tuple<ArgTs ...> FixedArgs;
|
||||||
|
fixed_tuple<ArgTs ...> fixedArgT;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
|
|
@ -365,6 +371,7 @@ struct _EngineFunctionTrampoline< R(ArgTs...) > : public _EngineFunctionTrampoli
|
||||||
private:
|
private:
|
||||||
using Super = _EngineFunctionTrampolineBase< R(ArgTs...) >;
|
using Super = _EngineFunctionTrampolineBase< R(ArgTs...) >;
|
||||||
using ArgsType = typename Super::Args;
|
using ArgsType = typename Super::Args;
|
||||||
|
using FixedArgsType = typename Super::FixedArgs;
|
||||||
|
|
||||||
template<size_t ...> struct Seq {};
|
template<size_t ...> struct Seq {};
|
||||||
template<size_t N, size_t ...S> struct Gens : Gens<N-1, N-1, S...> {};
|
template<size_t N, size_t ...S> struct Gens : Gens<N-1, N-1, S...> {};
|
||||||
|
|
@ -374,6 +381,11 @@ private:
|
||||||
static R dispatchHelper(typename Super::FunctionType fn, const ArgsType& args, Seq<I...>) {
|
static R dispatchHelper(typename Super::FunctionType fn, const ArgsType& args, Seq<I...>) {
|
||||||
return R( fn(std::get<I>(args) ...) );
|
return R( fn(std::get<I>(args) ...) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<size_t ...I>
|
||||||
|
static R dispatchHelper(typename Super::FunctionType fn, const FixedArgsType& args, Seq<I...>) {
|
||||||
|
return R( fn(fixed_tuple_accessor<I>::get(args) ...) );
|
||||||
|
}
|
||||||
|
|
||||||
using SeqType = typename Gens<sizeof...(ArgTs)>::type;
|
using SeqType = typename Gens<sizeof...(ArgTs)>::type;
|
||||||
public:
|
public:
|
||||||
|
|
@ -381,6 +393,11 @@ public:
|
||||||
{
|
{
|
||||||
return dispatchHelper(fn, args, SeqType());
|
return dispatchHelper(fn, args, SeqType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static R jmp(typename Super::FunctionType fn, const FixedArgsType& args )
|
||||||
|
{
|
||||||
|
return dispatchHelper(fn, args, SeqType());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Trampolines for engine methods
|
// Trampolines for engine methods
|
||||||
|
|
@ -398,6 +415,7 @@ struct _EngineMethodTrampoline< Frame, R(ArgTs ...) > : public _EngineMethodTram
|
||||||
private:
|
private:
|
||||||
using Super = _EngineMethodTrampolineBase< R(ArgTs ...) >;
|
using Super = _EngineMethodTrampolineBase< R(ArgTs ...) >;
|
||||||
using ArgsType = typename _EngineFunctionTrampolineBase< R(ArgTs ...) >::Args;
|
using ArgsType = typename _EngineFunctionTrampolineBase< R(ArgTs ...) >::Args;
|
||||||
|
using FixedArgsType = typename Super::FixedArgs;
|
||||||
|
|
||||||
template<size_t ...> struct Seq {};
|
template<size_t ...> struct Seq {};
|
||||||
template<size_t N, size_t ...S> struct Gens : Gens<N-1, N-1, S...> {};
|
template<size_t N, size_t ...S> struct Gens : Gens<N-1, N-1, S...> {};
|
||||||
|
|
@ -408,6 +426,11 @@ private:
|
||||||
return R( f._exec(std::get<I>(args) ...) );
|
return R( f._exec(std::get<I>(args) ...) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<size_t ...I>
|
||||||
|
static R dispatchHelper(Frame f, const FixedArgsType& args, Seq<I...>) {
|
||||||
|
return R( f._exec(fixed_tuple_accessor<I>::get(args) ...) );
|
||||||
|
}
|
||||||
|
|
||||||
using SeqType = typename Gens<sizeof...(ArgTs)>::type;
|
using SeqType = typename Gens<sizeof...(ArgTs)>::type;
|
||||||
public:
|
public:
|
||||||
static R jmp( typename Frame::ObjectType* object, const ArgsType& args )
|
static R jmp( typename Frame::ObjectType* object, const ArgsType& args )
|
||||||
|
|
@ -417,6 +440,14 @@ public:
|
||||||
f.object = object;
|
f.object = object;
|
||||||
return dispatchHelper(f, args, SeqType());
|
return dispatchHelper(f, args, SeqType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static R jmp( typename Frame::ObjectType* object, const FixedArgsType& args )
|
||||||
|
{
|
||||||
|
|
||||||
|
Frame f;
|
||||||
|
f.object = object;
|
||||||
|
return dispatchHelper(f, args, SeqType());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
@ -683,7 +714,7 @@ public:
|
||||||
#define DefineEngineFunction( name, returnType, args, defaultArgs, usage ) \
|
#define DefineEngineFunction( name, returnType, args, defaultArgs, usage ) \
|
||||||
static inline returnType _fn ## name ## impl args; \
|
static inline returnType _fn ## name ## impl args; \
|
||||||
TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## name \
|
TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## name \
|
||||||
( _EngineFunctionTrampoline< returnType args >::Args a ) \
|
( _EngineFunctionTrampoline< returnType args >::FixedArgs a ) \
|
||||||
{ \
|
{ \
|
||||||
_CHECK_ENGINE_INITIALIZED( name, returnType ); \
|
_CHECK_ENGINE_INITIALIZED( name, returnType ); \
|
||||||
return EngineTypeTraits< returnType >::ReturnValue( \
|
return EngineTypeTraits< returnType >::ReturnValue( \
|
||||||
|
|
@ -702,7 +733,7 @@ public:
|
||||||
( void* ) &fn ## name, \
|
( void* ) &fn ## name, \
|
||||||
0 \
|
0 \
|
||||||
); \
|
); \
|
||||||
static _EngineConsoleThunkType< returnType >::ReturnType _ ## name ## caster( SimObject*, S32 argc, ConsoleValueRef *argv ) \
|
static _EngineConsoleThunkType< returnType >::ReturnType _ ## name ## caster( SimObject*, S32 argc, ConsoleValueRef *argv ) \
|
||||||
{ \
|
{ \
|
||||||
return _EngineConsoleThunkType< returnType >::ReturnType( _EngineConsoleThunk< 1, returnType args >::thunk( \
|
return _EngineConsoleThunkType< returnType >::ReturnType( _EngineConsoleThunk< 1, returnType args >::thunk( \
|
||||||
argc, argv, &_fn ## name ## impl, _fn ## name ## DefaultArgs \
|
argc, argv, &_fn ## name ## impl, _fn ## name ## DefaultArgs \
|
||||||
|
|
@ -737,7 +768,7 @@ public:
|
||||||
|
|
||||||
#define _DefineMethodTrampoline( className, name, returnType, args ) \
|
#define _DefineMethodTrampoline( className, name, returnType, args ) \
|
||||||
TORQUE_API EngineTypeTraits< returnType >::ReturnValueType \
|
TORQUE_API EngineTypeTraits< returnType >::ReturnValueType \
|
||||||
fn ## className ## _ ## name ( className* object, _EngineMethodTrampoline< _ ## className ## name ## frame, returnType args >::Args a ) \
|
fn ## className ## _ ## name ( className* object, _EngineMethodTrampoline< _ ## className ## name ## frame, returnType args >::FixedArgs a )\
|
||||||
{ \
|
{ \
|
||||||
_CHECK_ENGINE_INITIALIZED( className::name, returnType ); \
|
_CHECK_ENGINE_INITIALIZED( className::name, returnType ); \
|
||||||
return EngineTypeTraits< returnType >::ReturnValue( \
|
return EngineTypeTraits< returnType >::ReturnValue( \
|
||||||
|
|
@ -820,7 +851,7 @@ public:
|
||||||
#define DefineEngineStaticMethod( className, name, returnType, args, defaultArgs, usage ) \
|
#define DefineEngineStaticMethod( className, name, returnType, args, defaultArgs, usage ) \
|
||||||
static inline returnType _fn ## className ## name ## impl args; \
|
static inline returnType _fn ## className ## name ## impl args; \
|
||||||
TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## className ## _ ## name \
|
TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## className ## _ ## name \
|
||||||
( _EngineFunctionTrampoline< returnType args >::Args a ) \
|
( _EngineFunctionTrampoline< returnType args >::FixedArgs a ) \
|
||||||
{ \
|
{ \
|
||||||
_CHECK_ENGINE_INITIALIZED( className::name, returnType ); \
|
_CHECK_ENGINE_INITIALIZED( className::name, returnType ); \
|
||||||
return EngineTypeTraits< returnType >::ReturnValue( \
|
return EngineTypeTraits< returnType >::ReturnValue( \
|
||||||
|
|
@ -920,7 +951,7 @@ public:
|
||||||
#define DefineNewEngineFunction( name, returnType, args, defaultArgs, usage ) \
|
#define DefineNewEngineFunction( name, returnType, args, defaultArgs, usage ) \
|
||||||
static inline returnType _fn ## name ## impl args; \
|
static inline returnType _fn ## name ## impl args; \
|
||||||
TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## name \
|
TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## name \
|
||||||
( _EngineFunctionTrampoline< returnType args >::Args a ) \
|
( _EngineFunctionTrampoline< returnType args >::FixedArgs a ) \
|
||||||
{ \
|
{ \
|
||||||
_CHECK_ENGINE_INITIALIZED( name, returnType ); \
|
_CHECK_ENGINE_INITIALIZED( name, returnType ); \
|
||||||
return EngineTypeTraits< returnType >::ReturnValue( \
|
return EngineTypeTraits< returnType >::ReturnValue( \
|
||||||
|
|
@ -967,7 +998,7 @@ public:
|
||||||
#define DefineNewEngineStaticMethod( className, name, returnType, args, defaultArgs, usage ) \
|
#define DefineNewEngineStaticMethod( className, name, returnType, args, defaultArgs, usage ) \
|
||||||
static inline returnType _fn ## className ## name ## impl args; \
|
static inline returnType _fn ## className ## name ## impl args; \
|
||||||
TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## className ## _ ## name \
|
TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## className ## _ ## name \
|
||||||
( _EngineFunctionTrampoline< returnType args >::Args a ) \
|
( _EngineFunctionTrampoline< returnType args >::FixedArgs a ) \
|
||||||
{ \
|
{ \
|
||||||
_CHECK_ENGINE_INITIALIZED( className::name, returnType ); \
|
_CHECK_ENGINE_INITIALIZED( className::name, returnType ); \
|
||||||
return EngineTypeTraits< returnType >::ReturnValue( \
|
return EngineTypeTraits< returnType >::ReturnValue( \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue