diff --git a/Engine/source/T3D/components/game/triggerComponent.cpp b/Engine/source/T3D/components/game/triggerComponent.cpp index 873c1307d8..eb183117bb 100644 --- a/Engine/source/T3D/components/game/triggerComponent.cpp +++ b/Engine/source/T3D/components/game/triggerComponent.cpp @@ -18,28 +18,28 @@ #include "gfx/sim/debugDraw.h" -IMPLEMENT_CALLBACK( TriggerComponent, onEnterViewCmd, void, +IMPLEMENT_CALLBACK( TriggerComponent, onEnterView, void, ( Entity* cameraEnt, bool firstTimeSeeing ), ( cameraEnt, firstTimeSeeing ), "@brief Called when an object enters the volume of the Trigger instance using this TriggerData.\n\n" "@param trigger the Trigger instance whose volume the object entered\n" "@param obj the object that entered the volume of the Trigger instance\n" ); -IMPLEMENT_CALLBACK( TriggerComponent, onExitViewCmd, void, +IMPLEMENT_CALLBACK( TriggerComponent, onExitView, void, ( Entity* cameraEnt ), ( cameraEnt ), "@brief Called when an object enters the volume of the Trigger instance using this TriggerData.\n\n" "@param trigger the Trigger instance whose volume the object entered\n" "@param obj the object that entered the volume of the Trigger instance\n" ); -IMPLEMENT_CALLBACK( TriggerComponent, onUpdateInViewCmd, void, +IMPLEMENT_CALLBACK( TriggerComponent, onUpdateInView, void, ( Entity* cameraEnt ), ( cameraEnt ), "@brief Called when an object enters the volume of the Trigger instance using this TriggerData.\n\n" "@param trigger the Trigger instance whose volume the object entered\n" "@param obj the object that entered the volume of the Trigger instance\n" ); -IMPLEMENT_CALLBACK( TriggerComponent, onUpdateOutOfViewCmd, void, +IMPLEMENT_CALLBACK( TriggerComponent, onUpdateOutOfView, void, ( Entity* cameraEnt ), ( cameraEnt ), "@brief Called when an object enters the volume of the Trigger instance using this TriggerData.\n\n" diff --git a/Engine/source/T3D/components/game/triggerComponent.h b/Engine/source/T3D/components/game/triggerComponent.h index bac45b62a8..c90ceb6a4e 100644 --- a/Engine/source/T3D/components/game/triggerComponent.h +++ b/Engine/source/T3D/components/game/triggerComponent.h @@ -65,10 +65,10 @@ class TriggerComponent : public Component void visualizeFrustums(F32 renderTimeMS); - DECLARE_CALLBACK(void, onEnterViewCmd, (Entity* cameraEnt, bool firstTimeSeeing)); - DECLARE_CALLBACK(void, onExitViewCmd, (Entity* cameraEnt)); - DECLARE_CALLBACK(void, onUpdateInViewCmd, (Entity* cameraEnt)); - DECLARE_CALLBACK(void, onUpdateOutOfViewCmd, (Entity* cameraEnt)); + DECLARE_CALLBACK(void, onEnterView, (Entity* cameraEnt, bool firstTimeSeeing)); + DECLARE_CALLBACK(void, onExitView, (Entity* cameraEnt)); + DECLARE_CALLBACK(void, onUpdateInView, (Entity* cameraEnt)); + DECLARE_CALLBACK(void, onUpdateOutOfView, (Entity* cameraEnt)); }; #endif // _EXAMPLEBEHAVIOR_H_ diff --git a/Engine/source/T3D/trigger.cpp b/Engine/source/T3D/trigger.cpp index 52d6898ebf..5d65f2ed3d 100644 --- a/Engine/source/T3D/trigger.cpp +++ b/Engine/source/T3D/trigger.cpp @@ -235,6 +235,9 @@ bool Trigger::castRay(const Point3F &start, const Point3F &end, RayInfo* info) DECLARE_STRUCT( Polyhedron ); IMPLEMENT_STRUCT( Polyhedron, Polyhedron,, "" ) + FIELD(mPointList, mPointList, 1, "") + FIELD(mPlaneList, mPlaneList, 1, "") + FIELD(mEdgeList, mEdgeList, 1, "") END_IMPLEMENT_STRUCT; ConsoleType(floatList, TypeTriggerPolyhedron, Polyhedron, "") diff --git a/Engine/source/T3D/vehicles/guiSpeedometer.cpp b/Engine/source/T3D/vehicles/guiSpeedometer.cpp index 9d92bd5e25..45f2a281cb 100644 --- a/Engine/source/T3D/vehicles/guiSpeedometer.cpp +++ b/Engine/source/T3D/vehicles/guiSpeedometer.cpp @@ -41,7 +41,7 @@ class GuiSpeedometerHud : public GuiBitmapCtrl F32 mMaxAngle; ///< Max pos of needle F32 mMinAngle; ///< Min pos of needle Point2F mCenter; ///< Center of needle rotation - LinearColorF mColor; ///< Needle Color + LinearColorF mNeedleColor; ///< Needle Color F32 mNeedleLength; F32 mNeedleWidth; F32 mTailLength; @@ -103,7 +103,7 @@ GuiSpeedometerHud::GuiSpeedometerHud() mNeedleWidth = 3; mNeedleLength = 10; mTailLength = 5; - mColor.set(1,0,0,1); + mNeedleColor.set(1,0,0,1); } void GuiSpeedometerHud::initPersistFields() @@ -122,7 +122,7 @@ void GuiSpeedometerHud::initPersistFields() "Angle (in radians) of the needle when the Vehicle speed is >= maxSpeed. " "An angle of 0 points right, 90 points up etc)." ); - addField("color", TypeColorF, Offset( mColor, GuiSpeedometerHud ), + addField("needleColor", TypeColorF, Offset( mNeedleColor, GuiSpeedometerHud ), "Color of the needle" ); addField("center", TypePoint2F, Offset( mCenter, GuiSpeedometerHud ), @@ -210,7 +210,7 @@ void GuiSpeedometerHud::onRender(Point2I offset, const RectI &updateRect) GFX->setTexture(0, NULL); // Render the needle - PrimBuild::color4f(mColor.red, mColor.green, mColor.blue, mColor.alpha); + PrimBuild::color4f(mNeedleColor.red, mNeedleColor.green, mNeedleColor.blue, mNeedleColor.alpha); PrimBuild::begin(GFXLineStrip, 5); for(int k=0; k<5; k++){ rotMatrix.mulP(vertList[k]); diff --git a/Engine/source/afx/afxEffectGroup.cpp b/Engine/source/afx/afxEffectGroup.cpp index 71c6a89b6f..0502be17f3 100644 --- a/Engine/source/afx/afxEffectGroup.cpp +++ b/Engine/source/afx/afxEffectGroup.cpp @@ -162,7 +162,7 @@ void afxEffectGroupData::initPersistFields() // for each of these, dummy_fx_entry is set and then a validator adds it to the appropriate effects list static egValidator emptyValidator(0); - addFieldV("addEffect", TYPEID(), myOffset(dummy_fx_entry), &emptyValidator, + addFieldV("effect", TYPEID(), myOffset(dummy_fx_entry), &emptyValidator, "..."); Parent::initPersistFields(); diff --git a/Engine/source/afx/afxEffectron.cpp b/Engine/source/afx/afxEffectron.cpp index cf60ede4bd..437fd6b3cb 100644 --- a/Engine/source/afx/afxEffectron.cpp +++ b/Engine/source/afx/afxEffectron.cpp @@ -118,7 +118,7 @@ void afxEffectronData::initPersistFields() // for each of these, dummy_fx_entry is set and then a validator adds it to the appropriate effects list static ewValidator emptyValidator(0); - addFieldV("addEffect", TYPEID(), myOffset(dummy_fx_entry), &emptyValidator, + addFieldV("effect", TYPEID(), myOffset(dummy_fx_entry), &emptyValidator, "..."); Parent::initPersistFields(); diff --git a/Engine/source/afx/afxMagicSpell.cpp b/Engine/source/afx/afxMagicSpell.cpp index e169d70d78..bf9c73626f 100644 --- a/Engine/source/afx/afxMagicSpell.cpp +++ b/Engine/source/afx/afxMagicSpell.cpp @@ -225,7 +225,7 @@ void afxMagicSpellData::initPersistFields() "..."); addField("extraCastingTime", TypeF32, myOffset(mExtra_casting_time), "..."); - addFieldV("addCastingEffect", TYPEID(), Offset(mDummy_fx_entry, afxMagicSpellData), &_castingPhrase, + addFieldV("castingEffect", TYPEID(), Offset(mDummy_fx_entry, afxMagicSpellData), &_castingPhrase, "..."); endGroup("Casting Stage"); @@ -236,9 +236,9 @@ void afxMagicSpellData::initPersistFields() "..."); addField("extraDeliveryTime", TypeF32, myOffset(mExtra_delivery_time), "..."); - addFieldV("addLaunchEffect", TYPEID(), Offset(mDummy_fx_entry, afxMagicSpellData), &_launchPhrase, + addFieldV("launchEffect", TYPEID(), Offset(mDummy_fx_entry, afxMagicSpellData), &_launchPhrase, "..."); - addFieldV("addDeliveryEffect", TYPEID(), Offset(mDummy_fx_entry, afxMagicSpellData), &_deliveryPhrase, + addFieldV("deliveryEffect", TYPEID(), Offset(mDummy_fx_entry, afxMagicSpellData), &_deliveryPhrase, "..."); endGroup("Delivery Stage"); @@ -249,9 +249,9 @@ void afxMagicSpellData::initPersistFields() "..."); addField("extraLingerTime", TypeF32, myOffset(mExtra_linger_time), "..."); - addFieldV("addImpactEffect", TYPEID(), Offset(mDummy_fx_entry, afxMagicSpellData), &_impactPhrase, + addFieldV("impactEffect", TYPEID(), Offset(mDummy_fx_entry, afxMagicSpellData), &_impactPhrase, "..."); - addFieldV("addLingerEffect", TYPEID(), Offset(mDummy_fx_entry, afxMagicSpellData), &_lingerPhrase, + addFieldV("lingerEffect", TYPEID(), Offset(mDummy_fx_entry, afxMagicSpellData), &_lingerPhrase, "..."); endGroup("Linger Stage"); diff --git a/Engine/source/afx/arcaneFX.cpp b/Engine/source/afx/arcaneFX.cpp index 385c056f61..9c0335a1c7 100644 --- a/Engine/source/afx/arcaneFX.cpp +++ b/Engine/source/afx/arcaneFX.cpp @@ -718,6 +718,8 @@ DefineEngineMethod(NetConnection, ResolveGhost, S32, (int ghostIndex),, IMPLEMENT_STRUCT( ByteRange, ByteRange,, "" ) + FIELD(low, low, 1, "") + FIELD(high, high, 1, "") END_IMPLEMENT_STRUCT; ConsoleType( ByteRange, TypeByteRange, ByteRange, "") diff --git a/Engine/source/afx/ce/afxPhraseEffect.cpp b/Engine/source/afx/ce/afxPhraseEffect.cpp index b574afbedf..0a24a26c4a 100644 --- a/Engine/source/afx/ce/afxPhraseEffect.cpp +++ b/Engine/source/afx/ce/afxPhraseEffect.cpp @@ -183,7 +183,7 @@ void afxPhraseEffectData::initPersistFields() // effect lists // for each of these, dummy_fx_entry is set and then a validator adds it to the appropriate effects list static ewValidator emptyValidator(0); - addFieldV("addEffect", TYPEID< afxEffectBaseData >(), myOffset(dummy_fx_entry), &emptyValidator, + addFieldV("effect", TYPEID< afxEffectBaseData >(), myOffset(dummy_fx_entry), &emptyValidator, "A field macro which adds an effect wrapper datablock to a list of effects associated " "with the phrase-effect's single phrase. Unlike other fields, addEffect follows an " "unusual syntax. Order is important since the effects will resolve in the order they " diff --git a/Engine/source/cinterface/c_consoleInterface.cpp b/Engine/source/cinterface/c_consoleInterface.cpp index 09b406da38..8ce5f97068 100644 --- a/Engine/source/cinterface/c_consoleInterface.cpp +++ b/Engine/source/cinterface/c_consoleInterface.cpp @@ -26,12 +26,12 @@ namespace Con { - DefineNewEngineFunction(AddConsumer, void, (ConsumerCallback cb), , "") + TORQUE_API void fnAddConsumer(ConsumerCallback cb) { addConsumer(cb); } - DefineNewEngineFunction(RemoveConsumer, void, (ConsumerCallback cb), , "") + TORQUE_API void fnRemoveConsumer(ConsumerCallback cb) { removeConsumer(cb); } diff --git a/Engine/source/cinterface/c_simobjectInterface.cpp b/Engine/source/cinterface/c_simobjectInterface.cpp index 4c018c0ab1..e987a74e44 100644 --- a/Engine/source/cinterface/c_simobjectInterface.cpp +++ b/Engine/source/cinterface/c_simobjectInterface.cpp @@ -27,7 +27,7 @@ DefineNewEngineMethod(SimObject, RegisterObject, bool, (),,"") { return object->registerObject(); } - +/* DefineNewEngineMethod(SimObject, GetField, String, (String fieldName, String arrayIndex),, "") { return object->getDataField(StringTable->insert(fieldName), StringTable->insert(arrayIndex)); @@ -37,6 +37,7 @@ DefineNewEngineMethod(SimObject, SetField, void, (String fieldName, String array { object->setDataField(StringTable->insert(fieldName), StringTable->insert(arrayIndex), StringTable->insert(value)); } +*/ DefineNewEngineMethod(SimObject, CopyFrom, void, (SimObject* parent),, "") { diff --git a/Engine/source/console/codeInterpreter.cpp b/Engine/source/console/codeInterpreter.cpp index 186354869e..80b0d79e29 100644 --- a/Engine/source/console/codeInterpreter.cpp +++ b/Engine/source/console/codeInterpreter.cpp @@ -2178,14 +2178,16 @@ OPCodeReturn CodeInterpreter::op_callfunc(U32 &ip) // ConsoleFunctionType is for any function defined by script. // Any 'callback' type is an engine function that is exposed to script. - if (mNSEntry->mType == Namespace::Entry::ConsoleFunctionType - || cFunctionRes) + if (cFunctionRes + || (mNSEntry && mNSEntry->mType == Namespace::Entry::ConsoleFunctionType)) { + ConsoleValue retVal; ConsoleValueRef ret; if (cFunctionRes) { - StringStackConsoleWrapper retVal(1, &cRetRes); - ret = retVal.argv[0]; + retVal.init(); + ret.value = &retVal; + retVal.setStackStringValue(cRetRes); } else if (mNSEntry->mFunctionOffset) { diff --git a/Engine/source/console/consoleFunctions.cpp b/Engine/source/console/consoleFunctions.cpp index b7ef6b5ee6..03e16631cc 100644 --- a/Engine/source/console/consoleFunctions.cpp +++ b/Engine/source/console/consoleFunctions.cpp @@ -2144,14 +2144,14 @@ DefineEngineFunction( gotoWebPage, void, ( const char* address ),, //----------------------------------------------------------------------------- -DefineEngineFunction( displaySplashWindow, bool, (const char* path), (""), +DefineEngineFunction( displaySplashWindow, bool, (String path), (""), "Display a startup splash window suitable for showing while the engine still starts up.\n\n" "@note This is currently only implemented on Windows.\n\n" "@param path relative path to splash screen image to display.\n" "@return True if the splash window could be successfully initialized.\n\n" "@ingroup Platform" ) { - if (path == NULL || *path == '\0') + if (path.isEmpty()) { path = Con::getVariable("$Core::splashWindowImage"); } diff --git a/Engine/source/console/engineAPI.h b/Engine/source/console/engineAPI.h index 78a4695224..80292c9bab 100644 --- a/Engine/source/console/engineAPI.h +++ b/Engine/source/console/engineAPI.h @@ -110,8 +110,8 @@ namespace engineAPI { // Temp support for allowing const char* to remain in the API functions as long as we // still have the console system around. When that is purged, these definitions should // be deleted and all const char* uses be replaced with String. -template<> struct EngineTypeTraits< const char* > : public EngineTypeTraits< String > {}; -template<> inline const EngineTypeInfo* TYPE< const char* >() { return TYPE< String >(); } +//template<> struct EngineTypeTraits< const char* > : public EngineTypeTraits< UTF8* > {}; +//template<> inline const EngineTypeInfo* TYPE< const char* >() { return TYPE< UTF8* >(); } @@ -349,10 +349,10 @@ template struct _EngineTrampoline { template< typename R, typename ...ArgTs > struct _EngineTrampoline< R( ArgTs ... ) > { - typedef std::tuple Args; - std::tuple argT; - typedef fixed_tuple FixedArgs; - fixed_tuple fixedArgT; + template using AVT = typename EngineTypeTraits::ArgumentValueType; + typedef fixed_tuple Params; + typedef fixed_tuple ...> Args; + Args argT; }; template< typename T > @@ -370,21 +370,23 @@ struct _EngineFunctionTrampoline< R(ArgTs...) > : public _EngineFunctionTrampoli { private: using Super = _EngineFunctionTrampolineBase< R(ArgTs...) >; + using ParamsType = typename Super::Params; using ArgsType = typename Super::Args; - using FixedArgsType = typename Super::FixedArgs; + using SelfType = _EngineFunctionTrampoline< R(ArgTs...) >; + template using ToValue = typename _EngineTypeTraits::ArgumentToValue; template struct Seq {}; template struct Gens : Gens {}; template struct Gens<0, I...>{ typedef Seq type; }; - template - static R dispatchHelper(typename Super::FunctionType fn, const ArgsType& args, Seq) { - return R( fn(std::get(args) ...) ); + template + static typename fixed_tuple_element>::type getAndToType(const ArgsType& args) { + return typename EngineTypeTraits>::type>::ArgumentToValue(fixed_tuple_accessor::get(args)); } template - static R dispatchHelper(typename Super::FunctionType fn, const FixedArgsType& args, Seq) { - return R( fn(fixed_tuple_accessor::get(args) ...) ); + static R dispatchHelper(typename Super::FunctionType fn, const ArgsType& args, Seq) { + return R( fn(SelfType::template getAndToType(args) ...) ); } using SeqType = typename Gens::type; @@ -393,11 +395,6 @@ struct _EngineFunctionTrampoline< R(ArgTs...) > : public _EngineFunctionTrampoli { return dispatchHelper(fn, args, SeqType()); } - - static R jmp(typename Super::FunctionType fn, const FixedArgsType& args ) - { - return dispatchHelper(fn, args, SeqType()); - } }; // Trampolines for engine methods @@ -414,36 +411,28 @@ struct _EngineMethodTrampoline< Frame, R(ArgTs ...) > : public _EngineMethodTram using FunctionType = R( typename Frame::ObjectType*, ArgTs ...); private: using Super = _EngineMethodTrampolineBase< R(ArgTs ...) >; - using ArgsType = typename _EngineFunctionTrampolineBase< R(ArgTs ...) >::Args; - using FixedArgsType = typename Super::FixedArgs; + using ParamsType = typename Super::Params; + using ArgsType = Super::Args; + using SelfType = _EngineMethodTrampoline< Frame, R(ArgTs ...) >; template struct Seq {}; template struct Gens : Gens {}; template struct Gens<0, I...>{ typedef Seq type; }; - - template - static R dispatchHelper(Frame f, const ArgsType& args, Seq) { - return R( f._exec(std::get(args) ...) ); + + template + static typename fixed_tuple_element>::type getAndToType(const ArgsType& args) { + return typename EngineTypeTraits>::type>::ArgumentToValue(fixed_tuple_accessor::get(args)); } template - static R dispatchHelper(Frame f, const FixedArgsType& args, Seq) { - return R( f._exec(fixed_tuple_accessor::get(args) ...) ); + static R dispatchHelper(Frame f, const ArgsType& args, Seq) { + return R( f._exec(SelfType::template getAndToType(args) ...) ); } using SeqType = typename Gens::type; public: static R jmp( typename Frame::ObjectType* object, const ArgsType& args ) { - - Frame f; - f.object = object; - 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()); @@ -582,7 +571,7 @@ namespace engineAPI{ { return EngineUnmarshallData< IthArgType >()( argv[ startArgc + index ] ); } else { - return std::get(defaultArgs.mArgs); + return fixed_tuple_accessor::get(defaultArgs.mData); } } @@ -714,7 +703,7 @@ struct _EngineConsoleThunk { #define DefineEngineFunction( name, returnType, args, defaultArgs, usage ) \ static inline returnType _fn ## name ## impl args; \ TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## name \ - ( _EngineFunctionTrampoline< returnType args >::FixedArgs a ) \ + ( _EngineFunctionTrampoline< returnType args >::Args a ) \ { \ _CHECK_ENGINE_INITIALIZED( name, returnType ); \ return EngineTypeTraits< returnType >::ReturnValue( \ @@ -768,7 +757,7 @@ struct _EngineConsoleThunk { #define _DefineMethodTrampoline( className, name, returnType, args ) \ TORQUE_API EngineTypeTraits< returnType >::ReturnValueType \ - fn ## className ## _ ## name ( className* object, _EngineMethodTrampoline< _ ## className ## name ## frame, returnType args >::FixedArgs a )\ + fn ## className ## _ ## name ( className* object, _EngineMethodTrampoline< _ ## className ## name ## frame, returnType args >::Args a )\ { \ _CHECK_ENGINE_INITIALIZED( className::name, returnType ); \ return EngineTypeTraits< returnType >::ReturnValue( \ @@ -851,7 +840,7 @@ struct _EngineConsoleThunk { #define DefineEngineStaticMethod( className, name, returnType, args, defaultArgs, usage ) \ static inline returnType _fn ## className ## name ## impl args; \ TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## className ## _ ## name \ - ( _EngineFunctionTrampoline< returnType args >::FixedArgs a ) \ + ( _EngineFunctionTrampoline< returnType args >::Args a ) \ { \ _CHECK_ENGINE_INITIALIZED( className::name, returnType ); \ return EngineTypeTraits< returnType >::ReturnValue( \ @@ -886,61 +875,71 @@ struct _EngineConsoleThunk { ); \ static inline returnType _fn ## className ## name ## impl args -# define DefineEngineStringlyVariadicFunction(name,returnType,minArgs,maxArgs,usage) \ - static inline returnType _fn ## name ## impl (SimObject *, S32 argc, ConsoleValueRef *argv); \ +# define DefineEngineStringlyVariadicFunction(name,returnType,minArgs,maxArgs,usage) \ + static inline returnType _fn ## name ## impl (SimObject *, S32, ConsoleValueRef*); \ TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## name \ - (S32 argc, const char** argv) \ + (Vector* vec) \ { \ _CHECK_ENGINE_INITIALIZED( name, returnType ); \ - StringStackConsoleWrapper args(argc, argv); \ + StringStackConsoleWrapper args(vec->size(), vec->address()); \ return EngineTypeTraits< returnType >::ReturnValue( \ _fn ## name ## impl(NULL, args.count(), args) \ ); \ } \ - static _EngineFunctionDefaultArguments< void (S32 argc, const char** argv) > _fn ## name ## DefaultArgs; \ + static _EngineFunctionDefaultArguments< void (Vector vec) > _fn ## name ## DefaultArgs; \ static EngineFunctionInfo _fn ## name ## FunctionInfo( \ #name, \ &_SCOPE<>()(), \ usage, \ - #returnType " " #name "(S32 argc, const char** argv)", \ + #returnType " " #name "(Vector args)", \ "fn" #name, \ - TYPE< returnType (S32 argc, const char** argv) >(), \ + TYPE< returnType (Vector* vec) >(), \ &_fn ## name ## DefaultArgs, \ ( void* ) &fn ## name, \ 0 \ ); \ - ConsoleConstructor cc_##name##_obj(NULL,#name,_fn ## name ## impl,usage,minArgs,maxArgs); \ + ConsoleConstructor cc_##name##_obj(NULL,#name,_fn ## name ## impl,usage,minArgs,maxArgs); \ returnType _fn ## name ## impl(SimObject *, S32 argc, ConsoleValueRef *argv) # define DefineEngineStringlyVariadicMethod(className, name,returnType,minArgs,maxArgs,usage) \ - static inline returnType _fn ## className ## _ ## name ## impl (className* object, S32 argc, ConsoleValueRef* argv); \ + struct _ ## className ## name ## frame \ + { \ + typedef className ObjectType; \ + className* object; \ + inline returnType _exec (S32 argc, ConsoleValueRef* argv) const; \ + }; \ TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## className ## _ ## name \ - (className* object, S32 argc, const char** argv) \ + (className* object, Vector* vec) \ { \ _CHECK_ENGINE_INITIALIZED( name, returnType ); \ - StringStackConsoleWrapper args(argc, argv); \ + StringStackConsoleWrapper args(vec->size(), vec->address()); \ + _ ## className ## name ## frame frame {}; \ + frame.object = static_cast< className* >( object ); \ return EngineTypeTraits< returnType >::ReturnValue( \ - _fn ## className ## _ ## name ## impl(object, args.count(), args) \ + frame._exec(args.count(), args) \ ); \ } \ - static _EngineFunctionDefaultArguments< void (className* object, S32 argc, const char** argv) > _fn ## className ## _ ## name ## DefaultArgs; \ - static EngineFunctionInfo _fn ## className ## _ ## name ## FunctionInfo( \ + static _EngineFunctionDefaultArguments< void (className* object, S32 argc, const char** argv) > \ + _fn ## className ## name ## DefaultArgs; \ + static EngineFunctionInfo _fn ## className ## name ## FunctionInfo( \ #name, \ - &_SCOPE<>()(), \ + &_SCOPE< className >()(), \ usage, \ - #returnType " " #name "(SimObject* object, S32 argc, const char** argv)", \ + "virtual " #returnType " " #name "(Vector args)", \ "fn" #className "_" #name, \ - TYPE< returnType (SimObject* object, S32 argc, const char** argv) >(), \ - &_fn ## className ## _ ## name ## DefaultArgs, \ + TYPE< _EngineMethodTrampoline< _ ## className ## name ## frame, returnType (Vector vec) >::FunctionType >(), \ + &_fn ## className ## name ## DefaultArgs, \ ( void* ) &fn ## className ## _ ## name, \ 0 \ ); \ returnType cm_##className##_##name##_caster(SimObject* object, S32 argc, ConsoleValueRef* argv) { \ AssertFatal( dynamic_cast( object ), "Object passed to " #name " is not a " #className "!" ); \ - conmethod_return_##returnType ) _fn ## className ## _ ## name ## impl(static_cast(object),argc,argv); \ + _ ## className ## name ## frame frame {}; \ + frame.object = static_cast< className* >( object ); \ + conmethod_return_##returnType ) frame._exec(argc,argv); \ }; \ ConsoleConstructor cc_##className##_##name##_obj(#className,#name,cm_##className##_##name##_caster,usage,minArgs,maxArgs); \ - static inline returnType _fn ## className ## _ ## name ## impl(className *object, S32 argc, ConsoleValueRef *argv) + inline returnType _ ## className ## name ## frame::_exec(S32 argc, ConsoleValueRef *argv) const @@ -951,7 +950,7 @@ struct _EngineConsoleThunk { #define DefineNewEngineFunction( name, returnType, args, defaultArgs, usage ) \ static inline returnType _fn ## name ## impl args; \ TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## name \ - ( _EngineFunctionTrampoline< returnType args >::FixedArgs a ) \ + ( _EngineFunctionTrampoline< returnType args >::Args a ) \ { \ _CHECK_ENGINE_INITIALIZED( name, returnType ); \ return EngineTypeTraits< returnType >::ReturnValue( \ @@ -998,7 +997,7 @@ struct _EngineConsoleThunk { #define DefineNewEngineStaticMethod( className, name, returnType, args, defaultArgs, usage ) \ static inline returnType _fn ## className ## name ## impl args; \ TORQUE_API EngineTypeTraits< returnType >::ReturnValueType fn ## className ## _ ## name \ - ( _EngineFunctionTrampoline< returnType args >::FixedArgs a ) \ + ( _EngineFunctionTrampoline< returnType args >::Args a ) \ { \ _CHECK_ENGINE_INITIALIZED( className::name, returnType ); \ return EngineTypeTraits< returnType >::ReturnValue( \ diff --git a/Engine/source/console/engineFunctions.h b/Engine/source/console/engineFunctions.h index eb935d9950..abf389d647 100644 --- a/Engine/source/console/engineFunctions.h +++ b/Engine/source/console/engineFunctions.h @@ -30,10 +30,10 @@ #endif #ifndef _ENGINEEXPORTS_H_ - #include "console/engineExports.h" +#include "console/engineExports.h" #endif #ifndef _ENGINETYPEINFO_H_ - #include "console/engineTypeInfo.h" +#include "console/engineTypeInfo.h" #endif @@ -42,115 +42,99 @@ #ifdef TORQUE_COMPILER_VISUALC - #define TORQUE_API extern "C" __declspec( dllexport ) +#define TORQUE_API extern "C" __declspec( dllexport ) #elif defined( TORQUE_COMPILER_GCC ) - #define TORQUE_API extern "C" __attribute__( ( visibility( "default" ) ) ) +#define TORQUE_API extern "C" __attribute__( ( visibility( "default" ) ) ) #else - #error Unsupported compiler. +#error Unsupported compiler. #endif -// #pragma pack is bugged in GCC in that the packing in place at the template instantiation -// sites rather than their definition sites is used. Enable workarounds. -#ifdef TORQUE_COMPILER_GCC - #define _PACK_BUG_WORKAROUNDS -#endif - - - -/// Structure storing the default argument values for a function invocation -/// frame. struct EngineFunctionDefaultArguments { - /// Number of default arguments for the function call frame. - /// - /// @warn This is @b NOT the size of the memory block returned by getArgs() and also - /// not the number of elements it contains. U32 mNumDefaultArgs; - - /// Return a pointer to the variable-sized array of default argument values. - /// - /// @warn The arguments must be stored @b IMMEDIATELY after #mNumDefaultArgs. - /// @warn This is a @b FULL frame and not just the default arguments, i.e. it starts with the - /// first argument that the function takes and ends with the last argument it takes. - /// @warn If the compiler's #pragma pack is buggy, the elements in this structure are allowed - /// to be 4-byte aligned rather than byte-aligned as they should be. - const U8* getArgs() const - { - return ( const U8* ) &( mNumDefaultArgs ) + sizeof( mNumDefaultArgs ); - } + U32* mOffsets; + U8* mFirst; }; - -// Need byte-aligned packing for the default argument structures. -#ifdef _WIN64 -#pragma pack( push, 8 ) -#else -#pragma pack( push, 1 ) -#endif - - -// Structure encapsulating default arguments to an engine API function. template< typename T > struct _EngineFunctionDefaultArguments {}; -template -struct _EngineFunctionDefaultArguments< void(ArgTs...) > : public EngineFunctionDefaultArguments +template +struct _EngineFunctionDefaultArguments< R(ArgTs...) > : EngineFunctionDefaultArguments { +private: template using DefVST = typename EngineTypeTraits::DefaultArgumentValueStoreType; - fixed_tuple ...> mFixedArgs; - std::tuple ...> mArgs; + using SelfType = _EngineFunctionDefaultArguments< R(ArgTs...) >; + typedef fixed_tuple...> TupleType; + +public: + TupleType mData; + private: - using SelfType = _EngineFunctionDefaultArguments< void(ArgTs...) >; - template struct Seq {}; template struct Gens : Gens {}; - + template struct Gens<0, I...>{ typedef Seq type; }; - + template - static void copyHelper(std::tuple ...> &args, std::tuple ...> &defaultArgs, Seq) { + static void copyHelper(std::tuple...>& args, std::tuple ...>& defaultArgs, Seq) { std::tie(std::get(args)...) = defaultArgs; } - + #if defined(_MSC_VER) && (_MSC_VER >= 1910) template struct DodgyVCHelper { - using type = typename std::enable_if::type; + using type = typename std::enable_if...>>::type; }; template using MaybeSelfEnabled = typename DodgyVCHelper::type; #else template using MaybeSelfEnabled = typename std::enable_if::type; #endif - + template static MaybeSelfEnabled tailInit(TailTs ...tail) { + static MaybeSelfEnabled tailInit(TailTs ...tail) { std::tuple...> argsT; std::tuple...> tailT = std::make_tuple(tail...); SelfType::copyHelper(argsT, tailT, typename Gens::type()); return argsT; }; - + + template + typename std::enable_if::type initOffsetsHelper() + { } + + template + typename std::enable_if < I < sizeof...(ArgTs)>::type initOffsetsHelper() + { + mOffsets[I] = fixed_tuple_accessor::getOffset(mData); + initOffsetsHelper(); + } + public: - template _EngineFunctionDefaultArguments(TailTs ...tail) - : EngineFunctionDefaultArguments({sizeof...(TailTs)}), mArgs(SelfType::tailInit(tail...)) + template + _EngineFunctionDefaultArguments(TailTs... tail) + : EngineFunctionDefaultArguments() { - fixed_tuple_mutator...), void(DefVST...)>::copy(mArgs, mFixedArgs); + mNumDefaultArgs = sizeof...(TailTs); + mOffsets = new U32[sizeof...(ArgTs)]; + initOffsetsHelper(); + std::tuple...> tmpTup = SelfType::tailInit(tail...); + fixed_tuple_mutator...), void(DefVST...)>::copy(tmpTup, mData); + mFirst = (U8*)& mData; } }; -#pragma pack( pop ) - - // Helper to allow flags argument to DEFINE_FUNCTION to be empty. struct _EngineFunctionFlags { U32 val; _EngineFunctionFlags() - : val( 0 ) {} - _EngineFunctionFlags( U32 val ) - : val( val ) {} + : val(0) {} + _EngineFunctionFlags(U32 val) + : val(val) {} operator U32() const { return val; } }; @@ -160,7 +144,7 @@ enum EngineFunctionFlags { /// Function is a callback into the control layer. If this flag is not set, /// the function is a call-in. - EngineFunctionCallout = BIT( 0 ), + EngineFunctionCallout = BIT(0), }; @@ -215,85 +199,85 @@ enum EngineFunctionFlags /// class EngineFunctionInfo : public EngineExport { - public: - - DECLARE_CLASS( EngineFunctionInfo, EngineExport ); - - protected: - - /// A combination of EngineFunctionFlags. - BitSet32 mFunctionFlags; - - /// The type of the function. - const EngineTypeInfo* mFunctionType; - - /// Default values for the function arguments. - const EngineFunctionDefaultArguments* mDefaultArgumentValues; - - /// Name of the DLL symbol denoting the address of the exported entity. - const char* mBindingName; - - /// Full function prototype string. Useful for quick printing and most importantly, - /// this will be the only place containing information about the argument names. - const char* mPrototypeString; - - /// Address of either the function implementation or the variable taking the address - /// of a call-out. - void* mAddress; - - /// Next function in the global link chain of engine functions. - EngineFunctionInfo* mNextFunction; - - /// First function in the global link chain of engine functions. - static EngineFunctionInfo* smFirstFunction; - - public: - - /// - EngineFunctionInfo( const char* name, - EngineExportScope* scope, - const char* docString, - const char* protoypeString, - const char* bindingName, - const EngineTypeInfo* functionType, - const EngineFunctionDefaultArguments* defaultArgs, - void* address, - U32 flags ); - - /// Return the name of the function. - const char* getFunctionName() const { return getExportName(); } - - /// Return the function's full prototype string including the return type, function name, - /// and argument list. - const char* getPrototypeString() const { return mPrototypeString; } - - /// Return the DLL export symbol name. - const char* getBindingName() const { return mBindingName; } - - /// Test whether this is a callout function. - bool isCallout() const { return mFunctionFlags.test( EngineFunctionCallout ); } - - /// Test whether the function is variadic, i.e. takes a variable number of arguments. - bool isVariadic() const { return mFunctionType->isVariadic(); } - - /// Return the type of this function. - const EngineTypeInfo* getFunctionType() const { return mFunctionType; } - - /// Return the return type of the function. - const EngineTypeInfo* getReturnType() const { return getFunctionType()->getArgumentTypeTable()->getReturnType(); } - - /// Return the number of arguments that this function takes. If the function is variadic, - /// this is the number of fixed arguments. - U32 getNumArguments() const { return getFunctionType()->getArgumentTypeTable()->getNumArguments(); } - - /// - const EngineTypeInfo* getArgumentType( U32 index ) const { return ( *( getFunctionType()->getArgumentTypeTable() ) )[ index ]; } - - /// Return the vector storing the default argument values. - const EngineFunctionDefaultArguments* getDefaultArguments() const { return mDefaultArgumentValues; } - - /// Reset all callout function pointers back to NULL. This deactivates all callbacks. - static void resetAllCallouts(); +public: + + DECLARE_CLASS(EngineFunctionInfo, EngineExport); + +protected: + + /// A combination of EngineFunctionFlags. + BitSet32 mFunctionFlags; + + /// The type of the function. + const EngineTypeInfo* mFunctionType; + + /// Default values for the function arguments. + const EngineFunctionDefaultArguments* mDefaultArgumentValues; + + /// Name of the DLL symbol denoting the address of the exported entity. + const char* mBindingName; + + /// Full function prototype string. Useful for quick printing and most importantly, + /// this will be the only place containing information about the argument names. + const char* mPrototypeString; + + /// Address of either the function implementation or the variable taking the address + /// of a call-out. + void* mAddress; + + /// Next function in the global link chain of engine functions. + EngineFunctionInfo* mNextFunction; + + /// First function in the global link chain of engine functions. + static EngineFunctionInfo* smFirstFunction; + +public: + + /// + EngineFunctionInfo(const char* name, + EngineExportScope* scope, + const char* docString, + const char* protoypeString, + const char* bindingName, + const EngineTypeInfo* functionType, + const EngineFunctionDefaultArguments* defaultArgs, + void* address, + U32 flags); + + /// Return the name of the function. + const char* getFunctionName() const { return getExportName(); } + + /// Return the function's full prototype string including the return type, function name, + /// and argument list. + const char* getPrototypeString() const { return mPrototypeString; } + + /// Return the DLL export symbol name. + const char* getBindingName() const { return mBindingName; } + + /// Test whether this is a callout function. + bool isCallout() const { return mFunctionFlags.test(EngineFunctionCallout); } + + /// Test whether the function is variadic, i.e. takes a variable number of arguments. + bool isVariadic() const { return mFunctionType->isVariadic(); } + + /// Return the type of this function. + const EngineTypeInfo* getFunctionType() const { return mFunctionType; } + + /// Return the return type of the function. + const EngineTypeInfo* getReturnType() const { return getFunctionType()->getArgumentTypeTable()->getReturnType(); } + + /// Return the number of arguments that this function takes. If the function is variadic, + /// this is the number of fixed arguments. + U32 getNumArguments() const { return getFunctionType()->getArgumentTypeTable()->getNumArguments(); } + + /// + const EngineTypeInfo* getArgumentType(U32 index) const { return (*(getFunctionType()->getArgumentTypeTable()))[index]; } + + /// Return the vector storing the default argument values. + const EngineFunctionDefaultArguments* getDefaultArguments() const { return mDefaultArgumentValues; } + + /// Reset all callout function pointers back to NULL. This deactivates all callbacks. + static void resetAllCallouts(); }; @@ -324,8 +308,8 @@ class EngineFunctionInfo : public EngineExport ); \ } } \ TORQUE_API returnType bindingName args - - + + /// /// /// Not all control layers may be able to access data variables in a DLL so this macro exposes @@ -348,6 +332,6 @@ class EngineFunctionInfo : public EngineExport EngineFunctionCallout | EngineFunctionFlags( flags ) \ ); \ } - + #endif // !_ENGINEFUNCTIONS_H_ diff --git a/Engine/source/console/enginePrimitives.cpp b/Engine/source/console/enginePrimitives.cpp index de5f1f7b31..b3dbdf06e7 100644 --- a/Engine/source/console/enginePrimitives.cpp +++ b/Engine/source/console/enginePrimitives.cpp @@ -27,9 +27,23 @@ IMPLEMENT_PRIMITIVE( bool, bool,, "Boolean true/false." ); IMPLEMENT_PRIMITIVE( S8, byte,, "8bit signed integer." ); IMPLEMENT_PRIMITIVE( U8, ubyte,, "8bit unsigned integer." ); +IMPLEMENT_PRIMITIVE( S16, short,, "16bit signed integer." ); +IMPLEMENT_PRIMITIVE( U16, ushort,, "16bit unsigned integer." ); IMPLEMENT_PRIMITIVE( S32, int,, "32bit signed integer." ); IMPLEMENT_PRIMITIVE( U32, uint,, "32bit unsigned integer." ); IMPLEMENT_PRIMITIVE( F32, float,, "32bit single-precision floating-point." ); IMPLEMENT_PRIMITIVE( F64, double,, "64bit double-precision floating-point." ); -IMPLEMENT_PRIMITIVE( String, string,, "Null-terminated UTF-16 Unicode string." ); +IMPLEMENT_PRIMITIVE( String, string,, "Null-terminated UTF-8 Unicode string." ); IMPLEMENT_PRIMITIVE( void*, ptr,, "Opaque pointer." ); + +IMPLEMENT_PRIMITIVE(const UTF8*, cstring, , "Null-terminated UTF-8 Unicode string."); + +IMPLEMENT_PRIMITIVE(bool*, ptr_bool, , "Pointer to a bool."); +IMPLEMENT_PRIMITIVE(U8*, ptr_ubyte, , "Pointer to an unsigned byte."); +IMPLEMENT_PRIMITIVE(U32*, ptr_uint, , "Pointer to an unsigned byte."); +IMPLEMENT_PRIMITIVE(S32*, ptr_int, , "Pointer to a 32bit int."); +IMPLEMENT_PRIMITIVE(F32*, ptr_float, , "Pointer to a 32bit float."); +IMPLEMENT_PRIMITIVE(Point3F*, ptr_Point3F, , "Pointer to a Point3F struct."); +IMPLEMENT_PRIMITIVE(PlaneF*, ptr_PlaneF, , "Pointer to a PlaneF struct."); +IMPLEMENT_PRIMITIVE(PolyhedronData::Edge*, ptr_Edge, , "Pointer to an Edge struct."); +IMPLEMENT_PRIMITIVE(const char**, ptr_string, , "Pointer to a string."); diff --git a/Engine/source/console/enginePrimitives.h b/Engine/source/console/enginePrimitives.h index 7f0b376701..0bec3f35d6 100644 --- a/Engine/source/console/enginePrimitives.h +++ b/Engine/source/console/enginePrimitives.h @@ -27,6 +27,10 @@ #include "console/engineTypes.h" #endif +#include "core/strings/stringFunctions.h" +#include "math/mPlane.h" +#include "math/mPolyhedron.h" + /// @file /// Definitions for the core primitive types used in the @@ -37,6 +41,7 @@ DECLARE_PRIMITIVE_R( bool ); DECLARE_PRIMITIVE_R(S8); DECLARE_PRIMITIVE_R(U8); +DECLARE_PRIMITIVE_R(U16); DECLARE_PRIMITIVE_R(S32); DECLARE_PRIMITIVE_R(U32); DECLARE_PRIMITIVE_R(F32); @@ -45,11 +50,20 @@ DECLARE_PRIMITIVE_R(U64); DECLARE_PRIMITIVE_R(S64); DECLARE_PRIMITIVE_R(void*); +DECLARE_PRIMITIVE_R(bool*); +DECLARE_PRIMITIVE_R(U8*); +DECLARE_PRIMITIVE_R(S32*); +DECLARE_PRIMITIVE_R(F32*); +DECLARE_PRIMITIVE_R(Point3F*); +DECLARE_PRIMITIVE_R(PlaneF*); +DECLARE_PRIMITIVE_R(PolyhedronData::Edge*); +DECLARE_PRIMITIVE_R(const char**); + //FIXME: this allows String to be used as a struct field type // String is special in the way its data is exchanged through the API. Through -// calls, strings are passed as plain, null-terminated UTF-16 character strings. +// calls, strings are passed as plain, null-terminated UTF-8 character strings. // In addition, strings passed back as return values from engine API functions // are considered to be owned by the API layer itself. The rule here is that such // a string is only valid until the next API call is made. Usually, control layers @@ -58,17 +72,17 @@ _DECLARE_TYPE_R(String); template<> struct EngineTypeTraits< String > : public _EnginePrimitiveTypeTraits< String > { - typedef const UTF16* ArgumentValueType; - typedef const UTF16* ReturnValueType; + typedef const UTF8* ArgumentValueType; + typedef const UTF8* ReturnValueType; //FIXME: this needs to be sorted out; for now, we store default value literals in ASCII typedef const char* DefaultArgumentValueStoreType; - static const UTF16* ReturnValue( const String& str ) + static const UTF8* ReturnValue( const String& str ) { static String sTemp; sTemp = str; - return sTemp.utf16(); + return sTemp.utf8(); } }; @@ -80,4 +94,16 @@ template<> struct EngineTypeTraits< const UTF16* > : public EngineTypeTraits< St template<> inline const EngineTypeInfo* TYPE< const UTF16* >() { return TYPE< String >(); } inline const EngineTypeInfo* TYPE( const UTF16*& ) { return TYPE< String >(); } +_DECLARE_TYPE_R(const UTF8*); +template<> +struct EngineTypeTraits< const UTF8* > : public _EnginePrimitiveTypeTraits< const UTF8* > +{ + static const UTF8* ReturnValue(const String& str) + { + static String sTemp; + sTemp = str; + return sTemp.utf8(); + } +}; + #endif // !_ENGINEPRIMITIVES_H_ diff --git a/Engine/source/console/engineStructs.cpp b/Engine/source/console/engineStructs.cpp index a719220733..c9d387b0f2 100644 --- a/Engine/source/console/engineStructs.cpp +++ b/Engine/source/console/engineStructs.cpp @@ -26,28 +26,109 @@ #include "core/util/uuid.h" #include "core/color.h" +// Compute the offsets for vectors +const U32 Vector::offset[] = { Offset(mElementCount, Vector), Offset(mArraySize, Vector), Offset(mArray, Vector)}; +const U32 Vector::offset[] = { Offset(mElementCount, Vector), Offset(mArraySize, Vector), Offset(mArray, Vector)}; +const U32 Vector::offset[] = { Offset(mElementCount, Vector), Offset(mArraySize, Vector), Offset(mArray, Vector)}; +const U32 Vector::offset[] = { Offset(mElementCount, Vector), Offset(mArraySize, Vector), Offset(mArray, Vector)}; +const U32 Vector::offset[] = { Offset(mElementCount, Vector), Offset(mArraySize, Vector), Offset(mArray, Vector)}; +const U32 Vector::offset[] = { Offset(mElementCount, Vector), Offset(mArraySize, Vector), Offset(mArray, Vector)}; +const U32 Vector::offset[] = { Offset(mElementCount, Vector), Offset(mArraySize, Vector), Offset(mArray, Vector)}; IMPLEMENT_STRUCT( Vector< bool >, BoolVector,, "" ) + {"elementCount", "", 1, TYPE(), Vector::offset[0]}, + {"arraySize", "", 1, TYPE(), Vector::offset[1]}, + {"array", "", 1, TYPE(), Vector::offset[2]}, END_IMPLEMENT_STRUCT; IMPLEMENT_STRUCT( Vector< S32 >, IntVector,, "" ) + {"elementCount", "", 1, TYPE(), Vector::offset[0]}, + {"arraySize", "", 1, TYPE(), Vector::offset[1]}, + {"array", "", 1, TYPE(), Vector::offset[2]}, END_IMPLEMENT_STRUCT; - IMPLEMENT_STRUCT( Vector< F32 >, FloatVector,, "" ) + {"elementCount", "", 1, TYPE(), Vector::offset[0]}, + {"arraySize", "", 1, TYPE(), Vector::offset[1]}, + {"array", "", 1, TYPE(), Vector::offset[2]}, +END_IMPLEMENT_STRUCT; + +IMPLEMENT_STRUCT( Vector< Point3F >, + Point3FVector,, + "" ) + {"elementCount", "", 1, TYPE(), Vector::offset[0]}, + {"arraySize", "", 1, TYPE(), Vector::offset[1]}, + {"array", "", 1, TYPE(), Vector::offset[2]}, +END_IMPLEMENT_STRUCT; + +IMPLEMENT_STRUCT(PlaneF, + PlaneF, , + "") + FIELD(x, x, 1, "") + FIELD(y, y, 1, "") + FIELD(z, z, 1, "") + FIELD(d, d, 1, "") + END_IMPLEMENT_STRUCT; + +IMPLEMENT_STRUCT( Vector< PlaneF >, + PlaneFVector,, + "" ) + {"elementCount", "", 1, TYPE(), Vector::offset[0]}, + {"arraySize", "", 1, TYPE(), Vector::offset[1]}, + {"array", "", 1, TYPE(), Vector::offset[2]}, END_IMPLEMENT_STRUCT; +IMPLEMENT_STRUCT( PolyhedronData::Edge, + Edge,, + "" ) + { "face", "", 2, TYPE(), (U32)FIELDOFFSET( face ) }, + { "vertex", "", 2, TYPE(), (U32)FIELDOFFSET( vertex ) }, +END_IMPLEMENT_STRUCT; + +IMPLEMENT_STRUCT( Vector< PolyhedronData::Edge >, + EdgeVector,, + "" ) + {"elementCount", "", 1, TYPE(), Vector::offset[0]}, + {"arraySize", "", 1, TYPE(), Vector::offset[1]}, + {"array", "", 1, TYPE(), Vector::offset[2]}, +END_IMPLEMENT_STRUCT; + + +IMPLEMENT_STRUCT( Vector< const char* >, + StringVector,, + "" ) + {"elementCount", "", 1, TYPE(), Vector::offset[0]}, + {"arraySize", "", 1, TYPE(), Vector::offset[1]}, + {"array", "", 1, TYPE(), Vector::offset[2]}, +END_IMPLEMENT_STRUCT; + + +// Compute the offsets for UUID +const U32 Torque::UUID::offset[] = { + Offset(a, Torque::UUID), + Offset(b, Torque::UUID), + Offset(c, Torque::UUID), + Offset(d, Torque::UUID), + Offset(e, Torque::UUID), + Offset(f, Torque::UUID) +}; IMPLEMENT_STRUCT( Torque::UUID, UUID,, "" ) + {"a", "", 1, TYPE(), Torque::UUID::offset[0]}, + {"b", "", 1, TYPE(), Torque::UUID::offset[1]}, + {"c", "", 1, TYPE(), Torque::UUID::offset[2]}, + {"d", "", 1, TYPE(), Torque::UUID::offset[3]}, + {"e", "", 1, TYPE(), Torque::UUID::offset[4]}, + {"f", "", 6, TYPE(), Torque::UUID::offset[5]}, END_IMPLEMENT_STRUCT; diff --git a/Engine/source/console/engineStructs.h b/Engine/source/console/engineStructs.h index 8cbfad3298..5d008a204f 100644 --- a/Engine/source/console/engineStructs.h +++ b/Engine/source/console/engineStructs.h @@ -27,6 +27,9 @@ #include "console/engineTypes.h" #endif +#include "math/mPlane.h" +#include "math/mPolyhedron.h" + /// @file /// Definitions for the core engine structured types. @@ -44,8 +47,13 @@ class LinearColorF; DECLARE_STRUCT_R(Vector< bool >); DECLARE_STRUCT_R(Vector< S32 >); DECLARE_STRUCT_R(Vector< F32 >); +DECLARE_STRUCT_R(Vector< Point3F >); +DECLARE_STRUCT_R(PlaneF); +DECLARE_STRUCT_R(Vector< PlaneF >); +DECLARE_STRUCT_R(PolyhedronData::Edge); +DECLARE_STRUCT_R(Vector< PolyhedronData::Edge >); +DECLARE_STRUCT_R(Vector< const char* >); DECLARE_STRUCT_R(Torque::UUID); DECLARE_STRUCT_R(ColorI); DECLARE_STRUCT_R(LinearColorF); - #endif // !_ENGINESTRUCTS_H_ diff --git a/Engine/source/console/engineTypes.h b/Engine/source/console/engineTypes.h index 51d2ef84d7..ec9d116431 100644 --- a/Engine/source/console/engineTypes.h +++ b/Engine/source/console/engineTypes.h @@ -161,8 +161,6 @@ struct EngineTypeTraits< const T& > : public EngineTypeTraits< T > {}; template< typename T > struct EngineTypeTraits< const T > : public EngineTypeTraits< T > {}; - - /// Return the type info for the given engine type. template< typename T > inline const EngineTypeInfo* TYPE() { return EngineTypeTraits< T >::TYPEINFO; } @@ -236,16 +234,16 @@ template< typename T > struct _EngineStructTypeTraits { typedef T Type; - typedef const T ValueType; + typedef const T& ValueType; typedef void SuperType; // Structs get passed in as pointers and passed out as full copies. - typedef T ArgumentValueType; + typedef T* ArgumentValueType; typedef T ReturnValueType; typedef T DefaultArgumentValueStoreType; typedef ReturnValueType ReturnValue; - static ValueType ArgumentToValue( ArgumentValueType val ) { return val; } + static ValueType ArgumentToValue( ArgumentValueType val ) { return *val; } static const EngineTypeInfo* const TYPEINFO; }; diff --git a/Engine/source/console/engineXMLExport.cpp b/Engine/source/console/engineXMLExport.cpp index ae1b182bb3..00f9bda849 100644 --- a/Engine/source/console/engineXMLExport.cpp +++ b/Engine/source/console/engineXMLExport.cpp @@ -58,9 +58,10 @@ static const char* getDocString(const EngineExport* exportInfo) } template< typename T > -inline T getArgValue(const EngineFunctionDefaultArguments* defaultArgs, U32 offset) +inline T getArgValue(const EngineFunctionDefaultArguments* defaultArgs, U32 idx) { - return *reinterpret_cast< const T* >(defaultArgs->getArgs() + offset); + return *(const T*)(defaultArgs->mFirst + defaultArgs->mOffsets[idx]); + //return *reinterpret_cast< const T* >(defaultArgs->getArgs() + offset); } @@ -122,7 +123,7 @@ static Vector< String > parseFunctionArgumentNames(const EngineFunctionInfo* fun // Parse out name. const char* end = ptr + 1; - while (ptr > prototype && dIsalnum(*ptr)) + while (ptr > prototype && (dIsalnum(*ptr) || *ptr == '_')) ptr--; const char* start = ptr + 1; @@ -170,19 +171,20 @@ static Vector< String > parseFunctionArgumentNames(const EngineFunctionInfo* fun //----------------------------------------------------------------------------- -static String getDefaultArgumentValue(const EngineFunctionInfo* function, const EngineTypeInfo* type, U32 offset) +static String getValueForType(const EngineTypeInfo* type, void* addr) { String value; - const EngineFunctionDefaultArguments* defaultArgs = function->getDefaultArguments(); + +#define ADDRESS_TO_TYPE(tp) *(const tp*)(addr); switch (type->getTypeKind()) { case EngineTypeKindPrimitive: { -#define PRIMTYPE( tp ) \ + #define PRIMTYPE( tp ) \ if( TYPE< tp >() == type ) \ { \ - tp val = getArgValue< tp >( defaultArgs, offset ); \ + tp val = ADDRESS_TO_TYPE(tp); \ value = String::ToString( val ); \ } @@ -194,11 +196,17 @@ static String getDefaultArgumentValue(const EngineFunctionInfo* function, const PRIMTYPE(F32); PRIMTYPE(F64); + if (TYPE< const UTF8* >() == type) + { + const UTF8* val = *((const UTF8**)(addr)); + value = String(val); + } + //TODO: for now we store string literals in ASCII; needs to be sorted out - if (TYPE< const char* >() == type) + if (TYPE< String >() == type) { - const char* val = reinterpret_cast(defaultArgs->getArgs() + offset); - value = val; + const UTF8* val = *((const UTF8**)(addr)); + value = String(val); } #undef PRIMTYPE @@ -207,7 +215,7 @@ static String getDefaultArgumentValue(const EngineFunctionInfo* function, const case EngineTypeKindEnum: { - S32 val = getArgValue< S32 >(defaultArgs, offset); + S32 val = ADDRESS_TO_TYPE(S32); AssertFatal(type->getEnumTable(), "engineXMLExport - Enum type without table!"); const EngineEnumTable& table = *(type->getEnumTable()); @@ -225,7 +233,7 @@ static String getDefaultArgumentValue(const EngineFunctionInfo* function, const case EngineTypeKindBitfield: { - S32 val = getArgValue< S32 >(defaultArgs, offset); + S32 val = ADDRESS_TO_TYPE(S32); AssertFatal(type->getEnumTable(), "engineXMLExport - Bitfield type without table!"); const EngineEnumTable& table = *(type->getEnumTable()); @@ -248,6 +256,24 @@ static String getDefaultArgumentValue(const EngineFunctionInfo* function, const case EngineTypeKindStruct: { //TODO: struct type default argument values + + AssertFatal(type->getFieldTable(), "engineXMLExport - Struct type without table!"); + const EngineFieldTable* fieldTable = type->getFieldTable(); + U32 numFields = fieldTable->getNumFields(); + + + for (int i = 0; i < numFields; ++i) + { + const EngineTypeInfo* fieldType = (*fieldTable)[i].getType(); + U32 fieldOffset = (*fieldTable)[i].getOffset(); + AssertFatal((*fieldTable)[i].getNumElements() == 1, "engineXMLExport - numElements != 1 not supported currently."); + if (i == 0) { + value = getValueForType(fieldType, (void*)((size_t)addr + fieldOffset)); + } else { + value += " " + getValueForType(fieldType, (void*)((size_t)addr + fieldOffset)); + } + } + break; } @@ -257,21 +283,31 @@ static String getDefaultArgumentValue(const EngineFunctionInfo* function, const // For these two kinds, we support "null" as the only valid // default value. - const void* ptr = getArgValue< const void* >(defaultArgs, offset); + const void* ptr = ADDRESS_TO_TYPE(void*); if (!ptr) value = "null"; break; } default: + Con::printf("Uuuh"); break; } +#undef ADDRESS_TO_TYPE return value; } //----------------------------------------------------------------------------- +static String getDefaultArgumentValue(const EngineFunctionInfo* function, const EngineTypeInfo* type, U32 idx) +{ + const EngineFunctionDefaultArguments* defaultArgs = function->getDefaultArguments(); + return getValueForType(type, (void*)(defaultArgs->mFirst + defaultArgs->mOffsets[idx])); +} + +//----------------------------------------------------------------------------- + static void exportFunction(const EngineFunctionInfo* function, SimXMLDocument* xml) { if (isExportFiltered(function)) @@ -295,9 +331,6 @@ static void exportFunction(const EngineFunctionInfo* function, SimXMLDocument* x Vector< String > argumentNames = parseFunctionArgumentNames(function); const U32 numArgumentNames = argumentNames.size(); - // Accumulated offset in function argument frame vector. - U32 argFrameOffset = 0; - for (U32 i = 0; i < numArguments; ++i) { xml->pushNewElement("EngineFunctionArgument"); @@ -313,21 +346,17 @@ static void exportFunction(const EngineFunctionInfo* function, SimXMLDocument* x if (i >= firstDefaultArg) { - String defaultValue = getDefaultArgumentValue(function, type, argFrameOffset); + String defaultValue = getDefaultArgumentValue(function, type, i); xml->setAttribute("defaultValue", defaultValue); } - xml->popElement(); - - if (type->getTypeKind() == EngineTypeKindStruct) - argFrameOffset += type->getInstanceSize(); - else - argFrameOffset += type->getValueSize(); + // A bit hacky, default arguments have all offsets. + if (function->getDefaultArguments() != NULL) + { + xml->setAttribute("offset", String::ToString(function->getDefaultArguments()->mOffsets[i])); + } -#ifdef _PACK_BUG_WORKAROUNDS - if (argFrameOffset % 4 > 0) - argFrameOffset += 4 - (argFrameOffset % 4); -#endif + xml->popElement(); } xml->popElement(); @@ -579,4 +608,4 @@ DefineEngineFunction(exportEngineAPIToXML, SimXMLDocument*, (), , exportScope(EngineExportScope::getGlobalScope(), xml, true); return xml; -} \ No newline at end of file +} diff --git a/Engine/source/console/fixedTuple.h b/Engine/source/console/fixedTuple.h index 871cd70116..4418145171 100644 --- a/Engine/source/console/fixedTuple.h +++ b/Engine/source/console/fixedTuple.h @@ -22,6 +22,240 @@ #ifndef _FIXEDTUPLE_H_ #define _FIXEDTUPLE_H_ +#include "engineTypes.h" + +template +struct StdTupleIndexedHelper +{ + static const int getSize(std::tuple& tuple) + { + int size = sizeof(std::tuple_element>(tuple)); + if (I != 0) + { + size += StdTupleIndexedHelper::getSize(); + } + return size; + } + + static const int getOffset(std::tuple& tuple) + { + return (int)((size_t)&std::get(tuple)) - ((size_t)&tuple); + } +}; + + +template +struct BlockTupleIndexedHelper +{ + static const int getSize() + { + return sizeof(T) + BlockTupleIndexedHelper::getSize(); + } + + static const int getOffset() + { + return sizeof(T) + BlockTupleIndexedHelper::getOffset(); + } + + using type = T; +}; + +template +struct BlockTupleIndexedHelper<0, T, TailTs...> +{ + static const int getSize() + { + return sizeof(T); + } + + static const int getOffset() + { + return 0; + } + + using type = T; +}; + +template +struct BlockTupleHelper +{ + const static int getSize() + { + return sizeof(T) + BlockTupleHelper::getSize(); + } + + const static size_t size = sizeof(T) + BlockTupleHelper::size; +}; + +template +struct BlockTupleHelper +{ + const static int getSize() + { + return sizeof(T); + } + + const static size_t size = sizeof(T); +}; + +template< typename T > +struct BlockTuple +{ +}; + +template +struct BlockTuple< R(ArgTs...) > +{ + char data[BlockTupleHelper::size]; +private: + using SelfType = BlockTuple< void(ArgTs...) >; + + template struct Seq {}; + template struct Gens : Gens {}; + + template struct Gens<0, I...> { typedef Seq type; }; + + using SeqType = typename Gens::type; + +public: + + template + static typename BlockTupleIndexedHelper::type& get(BlockTuple& tuple) + { + return *reinterpret_cast::type*>( + ((size_t)& tuple.data) + + BlockTupleIndexedHelper::getOffset() + ); + } + + template + static typename BlockTupleIndexedHelper::type& set(BlockTuple& tuple, HeadT head, TailTs... tail) + { + return *reinterpret_cast::type*>( + ((size_t)& tuple.data) + + BlockTupleIndexedHelper::getOffset() + ); + } + + BlockTuple(char data[BlockTupleHelper::size]) + { + dMemmove(this->data, data, BlockTupleHelper::size); + } +}; + +template +struct InheritanceTuple; + +template< typename T, typename ...TailTs > +struct InheritanceTuple : InheritanceTuple +{ + T data; + + using SelfType = InheritanceTuple; + using SuperType = InheritanceTuple; + + template + typename std::tuple_element >::type& get(InheritanceTuple& tuple) + { + if (I == 0) + { + return data; + } + return SuperType::get(); + } + + template + typename std::tuple_element >::type& get(const InheritanceTuple& tuple) + { + if (I == 0) + { + return data; + } + return SuperType::get(); + } +}; + +template< typename T > +struct InheritanceTuple +{ + T data; + + template + typename std::tuple_element >::type& get(InheritanceTuple& tuple) + { + return data; + } + + template + typename std::tuple_element >::type& get(const InheritanceTuple& tuple) + { + return data; + } +}; + +template <> +struct InheritanceTuple<> {}; + +template< typename T > +struct _InheritanceTuple {}; + +template< typename R, typename ...ArgTs > +struct _InheritanceTuple : InheritanceTuple {}; + +template < ::std::size_t i> +struct InheritanceTupleAccessor +{ + template + static inline typename std::tuple_element >::type& get(InheritanceTuple& t) + { + return InheritanceTupleAccessor::get(t.rest); + } +}; + +template <> +struct InheritanceTupleAccessor<0> +{ + template + static inline typename std::tuple_element<0, std::tuple >::type& get(InheritanceTuple& t) + { + return t.data; + } +}; + +/* +template +struct InheritanceTuple< R(ArgTs...) > +{ + char data[BlockTupleHelper::size]; +private: + using SelfType = BlockTuple< void(ArgTs...) >; + + template struct Seq {}; + template struct Gens : Gens {}; + + template struct Gens<0, I...> { typedef Seq type; }; + + using SeqType = typename Gens::type; + + //typename EngineTypeTraits::ArgumentToValue(StoreType); +public: + + template + static typename BlockTupleIndexedHelper::type& get(BlockTuple& tuple) + { + return *reinterpret_cast::type*>( + ((size_t)& tuple.data) + + BlockTupleIndexedHelper::getOffset() + ); + } + + BlockTuple(char data[BlockTupleHelper::size]) + { + dMemmove(this->data, data, BlockTupleHelper::size); + } +}; +*/ + /// @name Fixed-layout tuple definition /// These structs and templates serve as a way to pass arguments from external /// applications and into the T3D console system. @@ -50,6 +284,8 @@ struct fixed_tuple fixed_tuple(U&& u, Us&&...tail) : first(::std::forward(u)), rest(::std::forward(tail)...) {} + + }; template @@ -95,6 +331,30 @@ struct fixed_tuple_accessor { return fixed_tuple_accessor::get(t.rest); } + + template + static inline typename fixed_tuple_element >::type * getRef(fixed_tuple & t) + { + return fixed_tuple_accessor::getRef(t.rest); + } + + template + static inline const typename fixed_tuple_element >::type * getRef(const fixed_tuple & t) + { + return fixed_tuple_accessor::getRef(t.rest); + } + + template + static inline U32 getOffset(fixed_tuple & t) + { + return (U32)((size_t)fixed_tuple_accessor::getRef(t)) - ((size_t)& t); + } + + template + static inline const U32 getOffset(const fixed_tuple & t) + { + return (U32)((size_t)fixed_tuple_accessor::getRef(t)) - ((size_t)& t); + } }; template <> @@ -111,13 +371,35 @@ struct fixed_tuple_accessor<0> { return t.first; } + template + static inline typename fixed_tuple_element<0, fixed_tuple >::type * getRef(fixed_tuple & t) + { + return &t.first; + } + + template + static inline const typename fixed_tuple_element<0, fixed_tuple >::type * getRef(const fixed_tuple & t) + { + return &t.first; + } + template + static inline U32 getOffset(fixed_tuple & t) + { + return (int)((size_t)& t.first) - ((size_t)& t); + } + + template + static inline const U32 getOffset(const fixed_tuple & t) + { + return (int)((size_t)& t.first) - ((size_t)& t); + } }; template< typename T1, typename T2 > struct fixed_tuple_mutator {}; -template -struct fixed_tuple_mutator +template +struct fixed_tuple_mutator { template static inline typename std::enable_if::type @@ -144,10 +426,23 @@ struct fixed_tuple_mutator fixed_tuple_accessor::get(dest) = std::get(src); copy(src, dest); } + + template + static inline typename std::enable_if::type + copyPtrs(std::tuple& src, fixed_tuple& dest) + { } + + template + static inline typename std::enable_if::type + copyPtrs(std::tuple& src, fixed_tuple& dest) + { + fixed_tuple_accessor::get(dest) = &std::get(src); + copyPtrs(src, dest); + } }; /// @} -#endif // !_FIXEDTUPLE_H_ \ No newline at end of file +#endif // !_FIXEDTUPLE_H_ diff --git a/Engine/source/console/simObject.cpp b/Engine/source/console/simObject.cpp index 6cf6fd0291..3f5a4dfb9d 100644 --- a/Engine/source/console/simObject.cpp +++ b/Engine/source/console/simObject.cpp @@ -42,6 +42,7 @@ #include "persistence/taml/tamlCustom.h" #include "sim/netObject.h" +#include "cinterface/cinterface.h" IMPLEMENT_CONOBJECT( SimObject ); @@ -829,6 +830,10 @@ bool SimObject::isMethod( const char* methodName ) if( !methodName || !methodName[0] ) return false; + if (CInterface::isMethod(this->getName(), methodName) || CInterface::isMethod(this->getClassName(), methodName)) { + return true; + } + StringTableEntry stname = StringTable->insert( methodName ); if( getNamespace() ) @@ -2220,7 +2225,7 @@ bool SimObject::setProtectedName(void *obj, const char *index, const char *data) return false; SimObject *object = static_cast(obj); - if ( object->isProperlyAdded() ) + if ( object->isProperlyAdded() || true ) object->assignName( data ); // always return false because we assign the name here @@ -2828,12 +2833,13 @@ DefineEngineMethod( SimObject, isField, bool, ( const char* fieldName ),, //----------------------------------------------------------------------------- -DefineEngineMethod( SimObject, getFieldValue, const char*, ( const char* fieldName, S32 index ), ( -1 ), +DefineEngineMethod( SimObject, getFieldValue, String, ( String fieldName, S32 index ), ( -1 ), "Return the value of the given field on this object.\n" "@param fieldName The name of the field. If it includes a field index, the index is parsed out.\n" "@param index Optional parameter to specify the index of an array field separately.\n" "@return The value of the given field or \"\" if undefined." ) { + const char* _fieldName = fieldName.c_str(); const U32 nameLen = dStrlen( fieldName ); if (nameLen == 0) return ""; @@ -2846,23 +2852,23 @@ DefineEngineMethod( SimObject, getFieldValue, const char*, ( const char* fieldNa const char* arrayIndex = NULL; if( fieldName[ nameLen - 1 ] == ']' ) { - const char* leftBracket = dStrchr( fieldName, '[' ); - const char* rightBracket = &fieldName[ nameLen - 1 ]; + const char* leftBracket = dStrchr( _fieldName, '[' ); + const char* rightBracket = &_fieldName[ nameLen - 1 ]; - const U32 fieldNameLen = getMin( U32( leftBracket - fieldName ), sizeof( fieldNameBuffer ) - 1 ); + const U32 fieldNameLen = getMin( U32( leftBracket - _fieldName ), sizeof( fieldNameBuffer ) - 1 ); const U32 arrayIndexLen = getMin( U32( rightBracket - leftBracket - 1 ), sizeof( arrayIndexBuffer ) - 1 ); - dMemcpy( fieldNameBuffer, fieldName, fieldNameLen ); + dMemcpy( fieldNameBuffer, _fieldName, fieldNameLen ); dMemcpy( arrayIndexBuffer, leftBracket + 1, arrayIndexLen ); fieldNameBuffer[ fieldNameLen ] = '\0'; arrayIndexBuffer[ arrayIndexLen ] = '\0'; - fieldName = fieldNameBuffer; + _fieldName = fieldNameBuffer; arrayIndex = arrayIndexBuffer; } - fieldName = StringTable->insert( fieldName ); + _fieldName = StringTable->insert(_fieldName); if( index != -1 ) { @@ -2870,7 +2876,7 @@ DefineEngineMethod( SimObject, getFieldValue, const char*, ( const char* fieldNa arrayIndex = arrayIndexBuffer; } - return object->getDataField( fieldName, arrayIndex ); + return object->getDataField(_fieldName, arrayIndex ); } //----------------------------------------------------------------------------- diff --git a/Engine/source/console/simPersistID.cpp b/Engine/source/console/simPersistID.cpp index c4f26e18e6..f2113168e2 100644 --- a/Engine/source/console/simPersistID.cpp +++ b/Engine/source/console/simPersistID.cpp @@ -24,16 +24,25 @@ #include "console/simObject.h" #include "core/util/tDictionary.h" #include "core/util/safeDelete.h" +#include "engineAPI.h" //#define DEBUG_SPEW +IMPLEMENT_CLASS(SimPersistID, "") +END_IMPLEMENT_CLASS; SimPersistID::LookupTableType* SimPersistID::smLookupTable; //----------------------------------------------------------------------------- +SimPersistID::SimPersistID() +{ + mUUID.generate(); + smLookupTable->insertUnique(mUUID, this); +} + SimPersistID::SimPersistID( SimObject* object ) : mObject( object ) { @@ -136,3 +145,13 @@ SimPersistID* SimPersistID::findOrCreate( const Torque::UUID& uuid ) return pid; } + +DefineNewEngineMethod(SimPersistID, getUUID, Torque::UUID, (),, "") +{ + return object->getUUID(); +} + +DefineNewEngineMethod(SimPersistID, getObject, SimObject*, (),, "") +{ + return object->getObject(); +} \ No newline at end of file diff --git a/Engine/source/console/simPersistID.h b/Engine/source/console/simPersistID.h index 46b1a45591..5125f76bed 100644 --- a/Engine/source/console/simPersistID.h +++ b/Engine/source/console/simPersistID.h @@ -30,6 +30,8 @@ #include "core/util/refBase.h" #endif +#include "console/engineObject.h" + /// @file /// Persistent IDs for SimObjects. @@ -40,12 +42,26 @@ template< typename, typename > class HashTable; /// A globally unique persistent ID for a SimObject. -class SimPersistID : public StrongRefBase +class SimPersistID : public EngineObject { public: + DECLARE_CLASS(SimPersistID, EngineObject); typedef void Parent; friend class SimObject; + + SimPersistID(); + + /// Construct a new persistent ID for "object" by generating a fresh + /// unique identifier. + SimPersistID(SimObject* object); + + /// Construct a persistent ID stub for the given unique identifier. + /// The stub remains not bound to any object until it is resolved. + SimPersistID(const Torque::UUID& uuid); + + /// + ~SimPersistID(); protected: @@ -60,17 +76,6 @@ class SimPersistID : public StrongRefBase /// Table of persistent object IDs. static LookupTableType* smLookupTable; - - /// Construct a new persistent ID for "object" by generating a fresh - /// unique identifier. - SimPersistID( SimObject* object ); - - /// Construct a persistent ID stub for the given unique identifier. - /// The stub remains not bound to any object until it is resolved. - SimPersistID( const Torque::UUID& uuid ); - - /// - ~SimPersistID(); /// Bind this unresolved PID to the given object. void resolve( SimObject* object ); diff --git a/Engine/source/core/util/tVector.h b/Engine/source/core/util/tVector.h index 0280db5f5f..2a42b87676 100644 --- a/Engine/source/core/util/tVector.h +++ b/Engine/source/core/util/tVector.h @@ -77,7 +77,10 @@ class Vector void destroy(U32 start, U32 end); ///< Destructs elements from start to end-1 void construct(U32 start, U32 end); ///< Constructs elements from start to end-1 void construct(U32 start, U32 end, const T* array); + public: + static const U32 offset[]; + Vector(const U32 initialSize = 0); Vector(const U32 initialSize, const char* fileName, const U32 lineNum); Vector(const char* fileName, const U32 lineNum); diff --git a/Engine/source/core/util/uuid.h b/Engine/source/core/util/uuid.h index e4ed4153a3..261a3557f1 100644 --- a/Engine/source/core/util/uuid.h +++ b/Engine/source/core/util/uuid.h @@ -49,6 +49,7 @@ namespace Torque static UUID smNull; public: + static const U32 offset[]; UUID() { diff --git a/Engine/source/gfx/sim/debugDraw.h b/Engine/source/gfx/sim/debugDraw.h index e40889dc0d..331bd70f27 100644 --- a/Engine/source/gfx/sim/debugDraw.h +++ b/Engine/source/gfx/sim/debugDraw.h @@ -93,6 +93,8 @@ class GFont; /// class DebugDrawer : public SimObject { + typedef SimObject Parent; + public: DECLARE_CONOBJECT(DebugDrawer); @@ -162,7 +164,6 @@ class DebugDrawer : public SimObject /// @} private: - typedef SimObject Parent; static DebugDrawer* sgDebugDrawer; diff --git a/Engine/source/gui/buttons/guiButtonBaseCtrl.cpp b/Engine/source/gui/buttons/guiButtonBaseCtrl.cpp index 4621d5feab..fc0e280fc8 100644 --- a/Engine/source/gui/buttons/guiButtonBaseCtrl.cpp +++ b/Engine/source/gui/buttons/guiButtonBaseCtrl.cpp @@ -515,9 +515,14 @@ DefineEngineMethod( GuiButtonBaseCtrl, setTextID, void, ( const char* id ),, //----------------------------------------------------------------------------- -DefineEngineMethod( GuiButtonBaseCtrl, getText, const char*, (),, - "Get the text display on the button's label (if any).\n\n" - "@return The button's label." ) +struct _GuiButtonBaseCtrlgetTextframe { typedef GuiButtonBaseCtrl ObjectType; GuiButtonBaseCtrl* object; inline const char* _exec () const; }; +TORQUE_API EngineTypeTraits< const char* >::ReturnValueType fnGuiButtonBaseCtrl_getText ( GuiButtonBaseCtrl* object, _EngineMethodTrampoline< _GuiButtonBaseCtrlgetTextframe, const char* () >::FixedArgs a ) +{ + if( !engineAPI::gIsInitialized ) { Con::errorf( "EngineAPI: Engine not initialized when calling " "GuiButtonBaseCtrl::getText" ); + return EngineTypeTraits< const char* >::ReturnValue( EngineTypeTraits< const char* >::ReturnValueType() ); }; + return EngineTypeTraits< const char* >::ReturnValue( _EngineMethodTrampoline< _GuiButtonBaseCtrlgetTextframe, const char* () >::jmp( object, a ) ); +}; static _EngineFunctionDefaultArguments< _EngineMethodTrampoline< _GuiButtonBaseCtrlgetTextframe, void () >::FunctionType > _fnGuiButtonBaseCtrlgetTextDefaultArgs ; static EngineFunctionInfo _fnGuiButtonBaseCtrlgetTextFunctionInfo( "getText", &_SCOPE< GuiButtonBaseCtrl >()(), "Get the text display on the button's label (if any).\n\n" "@return The button's label.", "virtual " "const char*" " " "getText" "()", "fn" "GuiButtonBaseCtrl" "_" "getText", TYPE< _EngineMethodTrampoline< _GuiButtonBaseCtrlgetTextframe, const char* () >::FunctionType >(), &_fnGuiButtonBaseCtrlgetTextDefaultArgs, ( void* ) &fnGuiButtonBaseCtrl_getText, 0 ); static _EngineConsoleThunkType< const char* >::ReturnType _GuiButtonBaseCtrlgetTextcaster( SimObject* object, S32 argc, ConsoleValueRef *argv ) { _GuiButtonBaseCtrlgetTextframe frame; frame.object = static_cast< GuiButtonBaseCtrl* >( object ); return _EngineConsoleThunkType< const char* >::ReturnType( _EngineConsoleThunk< 2, const char* () >::thunk( argc, argv, &_GuiButtonBaseCtrlgetTextframe::_exec, &frame, _fnGuiButtonBaseCtrlgetTextDefaultArgs ) ); } static ConsoleFunctionHeader _GuiButtonBaseCtrlgetTextheader ( "const char*", "()", "" ); static ConsoleConstructor GuiButtonBaseCtrlgetTextobj( "GuiButtonBaseCtrl", "getText", _EngineConsoleThunkType< const char* >::CallbackType( _GuiButtonBaseCtrlgetTextcaster ), "Get the text display on the button's label (if any).\n\n" "@return The button's label.", _EngineConsoleThunk< 2, const char* () >::NUM_ARGS - _EngineConsoleThunkCountArgs() , _EngineConsoleThunk< 2, const char* () >::NUM_ARGS, false, &_GuiButtonBaseCtrlgetTextheader ); +const char* _GuiButtonBaseCtrlgetTextframe::_exec () const { return object->getText( ); } diff --git a/Engine/source/gui/core/guiScriptNotifyControl.cpp b/Engine/source/gui/core/guiScriptNotifyControl.cpp index bd1cc63deb..eba4d730dc 100644 --- a/Engine/source/gui/core/guiScriptNotifyControl.cpp +++ b/Engine/source/gui/core/guiScriptNotifyControl.cpp @@ -67,13 +67,13 @@ void GuiScriptNotifyCtrl::initPersistFields() { // Callbacks Group addGroup("Callbacks"); - addField("onChildAdded", TypeBool, Offset( mOnChildAdded, GuiScriptNotifyCtrl ), "Enables/disables onChildAdded callback" ); - addField("onChildRemoved", TypeBool, Offset( mOnChildRemoved, GuiScriptNotifyCtrl ), "Enables/disables onChildRemoved callback" ); - addField("onChildResized", TypeBool, Offset( mOnChildResized, GuiScriptNotifyCtrl ), "Enables/disables onChildResized callback" ); - addField("onParentResized", TypeBool, Offset( mOnParentResized, GuiScriptNotifyCtrl ), "Enables/disables onParentResized callback" ); - addField("onResize", TypeBool, Offset( mOnResize, GuiScriptNotifyCtrl ), "Enables/disables onResize callback" ); - addField("onLoseFirstResponder", TypeBool, Offset( mOnLoseFirstResponder, GuiScriptNotifyCtrl ), "Enables/disables onLoseFirstResponder callback" ); - addField("onGainFirstResponder", TypeBool, Offset( mOnGainFirstResponder, GuiScriptNotifyCtrl ), "Enables/disables onGainFirstResponder callback" ); + addField("notifyOnChildAdded", TypeBool, Offset( mOnChildAdded, GuiScriptNotifyCtrl ), "Enables/disables onChildAdded callback" ); + addField("notifyOnChildRemoved", TypeBool, Offset( mOnChildRemoved, GuiScriptNotifyCtrl ), "Enables/disables onChildRemoved callback" ); + addField("notifyOnChildResized", TypeBool, Offset( mOnChildResized, GuiScriptNotifyCtrl ), "Enables/disables onChildResized callback" ); + addField("notifyOnParentResized", TypeBool, Offset( mOnParentResized, GuiScriptNotifyCtrl ), "Enables/disables onParentResized callback" ); + addField("notifyOnResize", TypeBool, Offset( mOnResize, GuiScriptNotifyCtrl ), "Enables/disables onResize callback" ); + addField("notifyOnLoseFirstResponder", TypeBool, Offset( mOnLoseFirstResponder, GuiScriptNotifyCtrl ), "Enables/disables onLoseFirstResponder callback" ); + addField("notifyOnGainFirstResponder", TypeBool, Offset( mOnGainFirstResponder, GuiScriptNotifyCtrl ), "Enables/disables onGainFirstResponder callback" ); endGroup("Callbacks"); Parent::initPersistFields(); diff --git a/Engine/source/gui/editor/guiFilterCtrl.cpp b/Engine/source/gui/editor/guiFilterCtrl.cpp index 03c0c8a9ce..6abc3d53cc 100644 --- a/Engine/source/gui/editor/guiFilterCtrl.cpp +++ b/Engine/source/gui/editor/guiFilterCtrl.cpp @@ -89,7 +89,7 @@ DefineEngineStringlyVariadicMethod( GuiFilterCtrl, setValue, void, 3, 20, "(f1, object->set(filter); } -DefineEngineMethod( GuiFilterCtrl, identity, void, (), , "Reset the filtering." +DefineEngineMethod( GuiFilterCtrl, resetFiltering, void, (), , "Reset the filtering." "@internal") { object->identity(); diff --git a/Engine/source/math/mMatrix.h b/Engine/source/math/mMatrix.h index 71a95946b6..cd87118df8 100644 --- a/Engine/source/math/mMatrix.h +++ b/Engine/source/math/mMatrix.h @@ -45,6 +45,8 @@ class MatrixF F32 m[16]; ///< Note: Torque uses row-major matrices public: + static const U32 offset[]; + /// Create an uninitialized matrix. /// /// @param identity If true, initialize to the identity matrix. diff --git a/Engine/source/math/mathTypes.cpp b/Engine/source/math/mathTypes.cpp index 89be98f187..3c72631710 100644 --- a/Engine/source/math/mathTypes.cpp +++ b/Engine/source/math/mathTypes.cpp @@ -88,30 +88,51 @@ END_IMPLEMENT_STRUCT; IMPLEMENT_STRUCT( RectI, RectI, MathTypes, "" ) + FIELD(point, point, 1, "The XY coordinate of the Rect.") + FIELD(extent, extent, 1, "The width and height of the Rect.") END_IMPLEMENT_STRUCT; IMPLEMENT_STRUCT( RectF, RectF, MathTypes, "" ) + FIELD(point, point, 1, "The XY coordinate of the Rect.") + FIELD(extent, extent, 1, "The width and height of the Rect.") END_IMPLEMENT_STRUCT; + + +// Compute the offsets for vectors +const U32 MatrixF::offset[] = { Offset(m, MatrixF) }; + IMPLEMENT_STRUCT( MatrixF, MatrixF, MathTypes, "" ) + {"m", "", 16, TYPE(), MatrixF::offset[0]}, END_IMPLEMENT_STRUCT; + IMPLEMENT_STRUCT( AngAxisF, AngAxisF, MathTypes, "" ) + FIELD(axis, axis, 1, "") + FIELD(angle, angle, 1, "") END_IMPLEMENT_STRUCT; IMPLEMENT_STRUCT( TransformF, TransformF, MathTypes, "" ) + FIELD(mPosition, position, 1, "") + FIELD(mOrientation, orientation, 1, "") + FIELD(mHasRotation, hasRotation, 1, "") END_IMPLEMENT_STRUCT; IMPLEMENT_STRUCT( Box3F, Box3F, MathTypes, "" ) + FIELD(minExtents, minExtents, 1, "Minimum extents of box") + FIELD(maxExtents, maxExtents, 1, "Maximum extents of box") END_IMPLEMENT_STRUCT; IMPLEMENT_STRUCT( EaseF, EaseF, MathTypes, "" ) + FIELD(mDir, mDir, 1, "inout, in, out") + FIELD(mType, mType, 1, "linear, etc...") + { "mParam", "optional params", 2, TYPE(), (U32)FIELDOFFSET(mParam) }, END_IMPLEMENT_STRUCT; IMPLEMENT_STRUCT(RotationF, RotationF, MathTypes, diff --git a/Engine/source/module/moduleDefinition.cpp b/Engine/source/module/moduleDefinition.cpp index c8dae30d84..795186aef6 100644 --- a/Engine/source/module/moduleDefinition.cpp +++ b/Engine/source/module/moduleDefinition.cpp @@ -82,8 +82,6 @@ void ModuleDefinition::initPersistFields() // Call parent. Parent::initPersistFields(); - addProtectedField("ModuleId", TypeString, Offset(mModuleId, ModuleDefinition), &defaultProtectedSetFn, &defaultProtectedGetFn, ""); - /// Module configuration. addProtectedField( "ModuleId", TypeString, Offset(mModuleId, ModuleDefinition), &setModuleId, &defaultProtectedGetFn, "A unique string Id for the module. It can contain any characters except a comma or semi-colon (the asset scope character)." ); addProtectedField( "VersionId", TypeS32, Offset(mVersionId, ModuleDefinition), &setVersionId, &defaultProtectedGetFn, "The version Id. Breaking changes to a module should use a higher version Id." ); diff --git a/Engine/source/module/moduleManager.cpp b/Engine/source/module/moduleManager.cpp index e122177e8d..402ed896a7 100644 --- a/Engine/source/module/moduleManager.cpp +++ b/Engine/source/module/moduleManager.cpp @@ -40,6 +40,7 @@ // Script bindings. #include "moduleManager_ScriptBinding.h" +#include "cinterface/cinterface.h" //----------------------------------------------------------------------------- @@ -811,16 +812,7 @@ bool ModuleManager::loadModuleExplicit( const char* pModuleId, const U32 version const bool scriptFileExecuted = dAtob( Con::executef("exec", pLoadReadyModuleDefinition->getModuleScriptFilePath() ) ); // Did we execute the script file? - if ( scriptFileExecuted ) - { - // Yes, so is the create method available? - if ( pScopeSet->isMethod( pLoadReadyModuleDefinition->getCreateFunction() ) ) - { - // Yes, so call the create method. - Con::executef( pScopeSet, pLoadReadyModuleDefinition->getCreateFunction() ); - } - } - else + if ( !scriptFileExecuted ) { // No, so warn. Con::errorf( "Module Manager: Cannot load explicit module Id '%s' at version Id '%d' as it failed to have the script file '%s' loaded.", @@ -828,6 +820,13 @@ bool ModuleManager::loadModuleExplicit( const char* pModuleId, const U32 version } } + // Is the create method available? + if (pScopeSet->isMethod(pLoadReadyModuleDefinition->getCreateFunction())) + { + // Yes, so call the create method. + Con::executef(pScopeSet, pLoadReadyModuleDefinition->getCreateFunction()); + } + // Raise notifications. raiseModulePostLoadNotifications( pLoadReadyModuleDefinition ); } diff --git a/Engine/source/postFx/postEffect.cpp b/Engine/source/postFx/postEffect.cpp index ce6e9ffc03..35d88fbeb9 100644 --- a/Engine/source/postFx/postEffect.cpp +++ b/Engine/source/postFx/postEffect.cpp @@ -379,7 +379,7 @@ void PostEffect::initPersistFields() addField( "allowReflectPass", TypeBool, Offset( mAllowReflectPass, PostEffect ), "Is this effect processed during reflection render passes." ); - addProtectedField( "isEnabled", TypeBool, Offset( mEnabled, PostEffect), + addProtectedField( "enabled", TypeBool, Offset( mEnabled, PostEffect), &PostEffect::_setIsEnabled, &defaultProtectedGetFn, "Is the effect on." ); diff --git a/Engine/source/sfx/sfxSource.cpp b/Engine/source/sfx/sfxSource.cpp index 2beb34634a..698f09087a 100644 --- a/Engine/source/sfx/sfxSource.cpp +++ b/Engine/source/sfx/sfxSource.cpp @@ -1531,7 +1531,7 @@ DefineEngineMethod( SFXSource, setPitch, void, ( F32 pitch ),, // Need an overload here as we can't use a default parameter to signal omission of the direction argument // and we need to properly detect the omission to leave the currently set direction on the source as is. - +/* TODO support this DEFINE_CALLIN( fnSFXSoure_setTransform1, setTransform, SFXSource, void, ( SFXSource* source, const VectorF& position ),,, "Set the position of the source's 3D sound.\n\n" "@param position The new position in world space.\n" @@ -1551,7 +1551,7 @@ DEFINE_CALLIN( fnSFXSoure_setTransform2, setTransform, SFXSource, void, ( SFXSou mat.setColumn( 1, direction ); source->setTransform( mat ); } - +*/ // Console interop version. static ConsoleDocFragment _sSetTransform1( diff --git a/Engine/source/sim/netGhost.cpp b/Engine/source/sim/netGhost.cpp index d903d74735..0970717328 100644 --- a/Engine/source/sim/netGhost.cpp +++ b/Engine/source/sim/netGhost.cpp @@ -793,7 +793,7 @@ void NetConnection::objectInScope(NetObject *obj) walk->flags |= GhostInfo::InScope; // Make sure scope always if reflected on the ghostinfo too - if (obj->mNetFlags.test(NetObject::ScopeAlways)) + if (obj->mNetFlags.test(NetObject::ScopeAlways) && !(walk->flags & GhostInfo::Flags::KillingGhost)) walk->flags |= GhostInfo::ScopeAlways; return; diff --git a/Engine/source/util/undo.cpp b/Engine/source/util/undo.cpp index ae6163774d..3276e1875e 100644 --- a/Engine/source/util/undo.cpp +++ b/Engine/source/util/undo.cpp @@ -565,7 +565,7 @@ DefineEngineMethod(UndoManager, getNextRedoName, const char *, (),, "UndoManager //----------------------------------------------------------------------------- -DefineEngineMethod( UndoManager, pushCompound, const char*, ( String name ), ("\"\""), "( string name=\"\" ) - Push a CompoundUndoAction onto the compound stack for assembly." ) +DefineEngineMethod( UndoManager, pushCompound, const char*, ( String name ), (""), "( string name=\"\" ) - Push a CompoundUndoAction onto the compound stack for assembly." ) { CompoundUndoAction* action = object->pushCompound( name );