Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 60450d4

Browse files
Pass Init parameters in 'memory'
Never release exposed function delegates Fix miscellaneous Rider warnings
1 parent 2180b3e commit 60450d4

File tree

9 files changed

+769
-995
lines changed

9 files changed

+769
-995
lines changed

‎Unity/Assets/CppSource/NativeScript/Bindings.cpp

Lines changed: 123 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -5951,142 +5951,146 @@ enum class InitMode : uint8_t
59515951
DLLEXPORT void Init(
59525952
uint8_t* memory,
59535953
int32_t memorySize,
5954-
InitMode initMode,
5955-
void (*releaseObject)(int32_t handle),
5956-
int32_t (*stringNew)(const char* chars),
5957-
void (*setException)(int32_t handle),
5958-
int32_t (*arrayGetLength)(int32_t handle),
5959-
int32_t (*enumerableGetEnumerator)(int32_t handle),
5960-
/*BEGIN INIT PARAMS*/
5961-
int32_t maxManagedObjects,
5962-
void (*releaseSystemDecimal)(int32_t handle),
5963-
int32_t (*systemDecimalConstructorSystemDouble)(double value),
5964-
int32_t (*systemDecimalConstructorSystemUInt64)(uint64_t value),
5965-
int32_t (*boxDecimal)(int32_t valHandle),
5966-
int32_t (*unboxDecimal)(int32_t valHandle),
5967-
UnityEngine::Vector3 (*unityEngineVector3ConstructorSystemSingle_SystemSingle_SystemSingle)(float x, float y, float z),
5968-
UnityEngine::Vector3 (*unityEngineVector3Methodop_AdditionUnityEngineVector3_UnityEngineVector3)(UnityEngine::Vector3& a, UnityEngine::Vector3& b),
5969-
int32_t (*boxVector3)(UnityEngine::Vector3& val),
5970-
UnityEngine::Vector3 (*unboxVector3)(int32_t valHandle),
5971-
int32_t (*unityEngineObjectPropertyGetName)(int32_t thisHandle),
5972-
void (*unityEngineObjectPropertySetName)(int32_t thisHandle, int32_t valueHandle),
5973-
int32_t (*unityEngineComponentPropertyGetTransform)(int32_t thisHandle),
5974-
UnityEngine::Vector3 (*unityEngineTransformPropertyGetPosition)(int32_t thisHandle),
5975-
void (*unityEngineTransformPropertySetPosition)(int32_t thisHandle, UnityEngine::Vector3& value),
5976-
int32_t (*systemCollectionsIEnumeratorPropertyGetCurrent)(int32_t thisHandle),
5977-
int32_t (*systemCollectionsIEnumeratorMethodMoveNext)(int32_t thisHandle),
5978-
int32_t (*unityEngineGameObjectMethodAddComponentMyGameBaseBallScript)(int32_t thisHandle),
5979-
int32_t (*unityEngineGameObjectMethodCreatePrimitiveUnityEnginePrimitiveType)(UnityEngine::PrimitiveType type),
5980-
void (*unityEngineDebugMethodLogSystemObject)(int32_t messageHandle),
5981-
int32_t (*unityEngineMonoBehaviourPropertyGetTransform)(int32_t thisHandle),
5982-
int32_t (*systemExceptionConstructorSystemString)(int32_t messageHandle),
5983-
int32_t (*boxPrimitiveType)(UnityEngine::PrimitiveType val),
5984-
UnityEngine::PrimitiveType (*unboxPrimitiveType)(int32_t valHandle),
5985-
System::Single (*unityEngineTimePropertyGetDeltaTime)(),
5986-
void (*releaseBaseBallScript)(int32_t handle),
5987-
void (*baseBallScriptConstructor)(int32_t cppHandle, int32_t* handle),
5988-
int32_t (*boxBoolean)(uint32_t val),
5989-
int32_t (*unboxBoolean)(int32_t valHandle),
5990-
int32_t (*boxSByte)(int8_t val),
5991-
System::SByte (*unboxSByte)(int32_t valHandle),
5992-
int32_t (*boxByte)(uint8_t val),
5993-
System::Byte (*unboxByte)(int32_t valHandle),
5994-
int32_t (*boxInt16)(int16_t val),
5995-
System::Int16 (*unboxInt16)(int32_t valHandle),
5996-
int32_t (*boxUInt16)(uint16_t val),
5997-
System::UInt16 (*unboxUInt16)(int32_t valHandle),
5998-
int32_t (*boxInt32)(int32_t val),
5999-
System::Int32 (*unboxInt32)(int32_t valHandle),
6000-
int32_t (*boxUInt32)(uint32_t val),
6001-
System::UInt32 (*unboxUInt32)(int32_t valHandle),
6002-
int32_t (*boxInt64)(int64_t val),
6003-
System::Int64 (*unboxInt64)(int32_t valHandle),
6004-
int32_t (*boxUInt64)(uint64_t val),
6005-
System::UInt64 (*unboxUInt64)(int32_t valHandle),
6006-
int32_t (*boxChar)(uint16_t val),
6007-
int16_t (*unboxChar)(int32_t valHandle),
6008-
int32_t (*boxSingle)(float val),
6009-
System::Single (*unboxSingle)(int32_t valHandle),
6010-
int32_t (*boxDouble)(double val),
6011-
System::Double (*unboxDouble)(int32_t valHandle)
6012-
/*END INIT PARAMS*/)
5954+
InitMode initMode)
60135955
{
60145956
uint8_t* curMemory = memory;
60155957

5958+
// Read fixed parameters
5959+
Plugin::ReleaseObject = *(void (**)(int32_t handle))curMemory;
5960+
curMemory += sizeof(Plugin::ReleaseObject);
5961+
Plugin::StringNew = *(int32_t (**)(const char*))curMemory;
5962+
curMemory += sizeof(Plugin::StringNew);
5963+
Plugin::SetException = *(void (**)(int32_t))curMemory;
5964+
curMemory += sizeof(Plugin::SetException);
5965+
Plugin::ArrayGetLength = *(int32_t (**)(int32_t))curMemory;
5966+
curMemory += sizeof(Plugin::ArrayGetLength);
5967+
Plugin::EnumerableGetEnumerator = *(int32_t (**)(int32_t))curMemory;
5968+
curMemory += sizeof(Plugin::EnumerableGetEnumerator);
5969+
5970+
// Read generated parameters
5971+
int32_t maxManagedObjects = *(int32_t*)curMemory;
5972+
curMemory += sizeof(int32_t);
5973+
/*BEGIN INIT BODY PARAMETER READS*/
5974+
Plugin::ReleaseSystemDecimal = *(void (**)(int32_t handle))curMemory;
5975+
curMemory += sizeof(Plugin::ReleaseSystemDecimal);
5976+
Plugin::SystemDecimalConstructorSystemDouble = *(int32_t (**)(double value))curMemory;
5977+
curMemory += sizeof(Plugin::SystemDecimalConstructorSystemDouble);
5978+
Plugin::SystemDecimalConstructorSystemUInt64 = *(int32_t (**)(uint64_t value))curMemory;
5979+
curMemory += sizeof(Plugin::SystemDecimalConstructorSystemUInt64);
5980+
Plugin::BoxDecimal = *(int32_t (**)(int32_t valHandle))curMemory;
5981+
curMemory += sizeof(Plugin::BoxDecimal);
5982+
Plugin::UnboxDecimal = *(int32_t (**)(int32_t valHandle))curMemory;
5983+
curMemory += sizeof(Plugin::UnboxDecimal);
5984+
Plugin::UnityEngineVector3ConstructorSystemSingle_SystemSingle_SystemSingle = *(UnityEngine::Vector3 (**)(float x, float y, float z))curMemory;
5985+
curMemory += sizeof(Plugin::UnityEngineVector3ConstructorSystemSingle_SystemSingle_SystemSingle);
5986+
Plugin::UnityEngineVector3Methodop_AdditionUnityEngineVector3_UnityEngineVector3 = *(UnityEngine::Vector3 (**)(UnityEngine::Vector3& a, UnityEngine::Vector3& b))curMemory;
5987+
curMemory += sizeof(Plugin::UnityEngineVector3Methodop_AdditionUnityEngineVector3_UnityEngineVector3);
5988+
Plugin::BoxVector3 = *(int32_t (**)(UnityEngine::Vector3& val))curMemory;
5989+
curMemory += sizeof(Plugin::BoxVector3);
5990+
Plugin::UnboxVector3 = *(UnityEngine::Vector3 (**)(int32_t valHandle))curMemory;
5991+
curMemory += sizeof(Plugin::UnboxVector3);
5992+
Plugin::UnityEngineObjectPropertyGetName = *(int32_t (**)(int32_t thisHandle))curMemory;
5993+
curMemory += sizeof(Plugin::UnityEngineObjectPropertyGetName);
5994+
Plugin::UnityEngineObjectPropertySetName = *(void (**)(int32_t thisHandle, int32_t valueHandle))curMemory;
5995+
curMemory += sizeof(Plugin::UnityEngineObjectPropertySetName);
5996+
Plugin::UnityEngineComponentPropertyGetTransform = *(int32_t (**)(int32_t thisHandle))curMemory;
5997+
curMemory += sizeof(Plugin::UnityEngineComponentPropertyGetTransform);
5998+
Plugin::UnityEngineTransformPropertyGetPosition = *(UnityEngine::Vector3 (**)(int32_t thisHandle))curMemory;
5999+
curMemory += sizeof(Plugin::UnityEngineTransformPropertyGetPosition);
6000+
Plugin::UnityEngineTransformPropertySetPosition = *(void (**)(int32_t thisHandle, UnityEngine::Vector3& value))curMemory;
6001+
curMemory += sizeof(Plugin::UnityEngineTransformPropertySetPosition);
6002+
Plugin::SystemCollectionsIEnumeratorPropertyGetCurrent = *(int32_t (**)(int32_t thisHandle))curMemory;
6003+
curMemory += sizeof(Plugin::SystemCollectionsIEnumeratorPropertyGetCurrent);
6004+
Plugin::SystemCollectionsIEnumeratorMethodMoveNext = *(int32_t (**)(int32_t thisHandle))curMemory;
6005+
curMemory += sizeof(Plugin::SystemCollectionsIEnumeratorMethodMoveNext);
6006+
Plugin::UnityEngineGameObjectMethodAddComponentMyGameBaseBallScript = *(int32_t (**)(int32_t thisHandle))curMemory;
6007+
curMemory += sizeof(Plugin::UnityEngineGameObjectMethodAddComponentMyGameBaseBallScript);
6008+
Plugin::UnityEngineGameObjectMethodCreatePrimitiveUnityEnginePrimitiveType = *(int32_t (**)(UnityEngine::PrimitiveType type))curMemory;
6009+
curMemory += sizeof(Plugin::UnityEngineGameObjectMethodCreatePrimitiveUnityEnginePrimitiveType);
6010+
Plugin::UnityEngineDebugMethodLogSystemObject = *(void (**)(int32_t messageHandle))curMemory;
6011+
curMemory += sizeof(Plugin::UnityEngineDebugMethodLogSystemObject);
6012+
Plugin::UnityEngineMonoBehaviourPropertyGetTransform = *(int32_t (**)(int32_t thisHandle))curMemory;
6013+
curMemory += sizeof(Plugin::UnityEngineMonoBehaviourPropertyGetTransform);
6014+
Plugin::SystemExceptionConstructorSystemString = *(int32_t (**)(int32_t messageHandle))curMemory;
6015+
curMemory += sizeof(Plugin::SystemExceptionConstructorSystemString);
6016+
Plugin::BoxPrimitiveType = *(int32_t (**)(UnityEngine::PrimitiveType val))curMemory;
6017+
curMemory += sizeof(Plugin::BoxPrimitiveType);
6018+
Plugin::UnboxPrimitiveType = *(UnityEngine::PrimitiveType (**)(int32_t valHandle))curMemory;
6019+
curMemory += sizeof(Plugin::UnboxPrimitiveType);
6020+
Plugin::UnityEngineTimePropertyGetDeltaTime = *(System::Single (**)())curMemory;
6021+
curMemory += sizeof(Plugin::UnityEngineTimePropertyGetDeltaTime);
6022+
Plugin::ReleaseBaseBallScript = *(void (**)(int32_t handle))curMemory;
6023+
curMemory += sizeof(Plugin::ReleaseBaseBallScript);
6024+
Plugin::BaseBallScriptConstructor = *(void (**)(int32_t cppHandle, int32_t* handle))curMemory;
6025+
curMemory += sizeof(Plugin::BaseBallScriptConstructor);
6026+
Plugin::BoxBoolean = *(int32_t (**)(uint32_t val))curMemory;
6027+
curMemory += sizeof(Plugin::BoxBoolean);
6028+
Plugin::UnboxBoolean = *(int32_t (**)(int32_t valHandle))curMemory;
6029+
curMemory += sizeof(Plugin::UnboxBoolean);
6030+
Plugin::BoxSByte = *(int32_t (**)(int8_t val))curMemory;
6031+
curMemory += sizeof(Plugin::BoxSByte);
6032+
Plugin::UnboxSByte = *(System::SByte (**)(int32_t valHandle))curMemory;
6033+
curMemory += sizeof(Plugin::UnboxSByte);
6034+
Plugin::BoxByte = *(int32_t (**)(uint8_t val))curMemory;
6035+
curMemory += sizeof(Plugin::BoxByte);
6036+
Plugin::UnboxByte = *(System::Byte (**)(int32_t valHandle))curMemory;
6037+
curMemory += sizeof(Plugin::UnboxByte);
6038+
Plugin::BoxInt16 = *(int32_t (**)(int16_t val))curMemory;
6039+
curMemory += sizeof(Plugin::BoxInt16);
6040+
Plugin::UnboxInt16 = *(System::Int16 (**)(int32_t valHandle))curMemory;
6041+
curMemory += sizeof(Plugin::UnboxInt16);
6042+
Plugin::BoxUInt16 = *(int32_t (**)(uint16_t val))curMemory;
6043+
curMemory += sizeof(Plugin::BoxUInt16);
6044+
Plugin::UnboxUInt16 = *(System::UInt16 (**)(int32_t valHandle))curMemory;
6045+
curMemory += sizeof(Plugin::UnboxUInt16);
6046+
Plugin::BoxInt32 = *(int32_t (**)(int32_t val))curMemory;
6047+
curMemory += sizeof(Plugin::BoxInt32);
6048+
Plugin::UnboxInt32 = *(System::Int32 (**)(int32_t valHandle))curMemory;
6049+
curMemory += sizeof(Plugin::UnboxInt32);
6050+
Plugin::BoxUInt32 = *(int32_t (**)(uint32_t val))curMemory;
6051+
curMemory += sizeof(Plugin::BoxUInt32);
6052+
Plugin::UnboxUInt32 = *(System::UInt32 (**)(int32_t valHandle))curMemory;
6053+
curMemory += sizeof(Plugin::UnboxUInt32);
6054+
Plugin::BoxInt64 = *(int32_t (**)(int64_t val))curMemory;
6055+
curMemory += sizeof(Plugin::BoxInt64);
6056+
Plugin::UnboxInt64 = *(System::Int64 (**)(int32_t valHandle))curMemory;
6057+
curMemory += sizeof(Plugin::UnboxInt64);
6058+
Plugin::BoxUInt64 = *(int32_t (**)(uint64_t val))curMemory;
6059+
curMemory += sizeof(Plugin::BoxUInt64);
6060+
Plugin::UnboxUInt64 = *(System::UInt64 (**)(int32_t valHandle))curMemory;
6061+
curMemory += sizeof(Plugin::UnboxUInt64);
6062+
Plugin::BoxChar = *(int32_t (**)(uint16_t val))curMemory;
6063+
curMemory += sizeof(Plugin::BoxChar);
6064+
Plugin::UnboxChar = *(int16_t (**)(int32_t valHandle))curMemory;
6065+
curMemory += sizeof(Plugin::UnboxChar);
6066+
Plugin::BoxSingle = *(int32_t (**)(float val))curMemory;
6067+
curMemory += sizeof(Plugin::BoxSingle);
6068+
Plugin::UnboxSingle = *(System::Single (**)(int32_t valHandle))curMemory;
6069+
curMemory += sizeof(Plugin::UnboxSingle);
6070+
Plugin::BoxDouble = *(int32_t (**)(double val))curMemory;
6071+
curMemory += sizeof(Plugin::BoxDouble);
6072+
Plugin::UnboxDouble = *(System::Double (**)(int32_t valHandle))curMemory;
6073+
curMemory += sizeof(Plugin::UnboxDouble);
6074+
/*END INIT BODY PARAMETER READS*/
6075+
60166076
// Init managed object ref counting
60176077
Plugin::RefCountsLenClass = maxManagedObjects;
60186078
Plugin::RefCountsClass = (int32_t*)curMemory;
60196079
curMemory += maxManagedObjects * sizeof(int32_t);
60206080

6021-
// Init pointers to C# functions
6022-
Plugin::StringNew = stringNew;
6023-
Plugin::ReleaseObject = releaseObject;
6024-
Plugin::SetException = setException;
6025-
Plugin::ArrayGetLength = arrayGetLength;
6026-
Plugin::EnumerableGetEnumerator = enumerableGetEnumerator;
6027-
/*BEGIN INIT BODY*/
6028-
Plugin::ReleaseSystemDecimal = releaseSystemDecimal;
6081+
/*BEGIN INIT BODY ARRAYS*/
60296082
Plugin::RefCountsSystemDecimal = (int32_t*)curMemory;
60306083
curMemory += 1000 * sizeof(int32_t);
60316084
Plugin::RefCountsLenSystemDecimal = 1000;
6032-
Plugin::SystemDecimalConstructorSystemDouble = systemDecimalConstructorSystemDouble;
6033-
Plugin::SystemDecimalConstructorSystemUInt64 = systemDecimalConstructorSystemUInt64;
6034-
Plugin::BoxDecimal = boxDecimal;
6035-
Plugin::UnboxDecimal = unboxDecimal;
6036-
Plugin::UnityEngineVector3ConstructorSystemSingle_SystemSingle_SystemSingle = unityEngineVector3ConstructorSystemSingle_SystemSingle_SystemSingle;
6037-
Plugin::UnityEngineVector3Methodop_AdditionUnityEngineVector3_UnityEngineVector3 = unityEngineVector3Methodop_AdditionUnityEngineVector3_UnityEngineVector3;
6038-
Plugin::BoxVector3 = boxVector3;
6039-
Plugin::UnboxVector3 = unboxVector3;
6040-
Plugin::UnityEngineObjectPropertyGetName = unityEngineObjectPropertyGetName;
6041-
Plugin::UnityEngineObjectPropertySetName = unityEngineObjectPropertySetName;
6042-
Plugin::UnityEngineComponentPropertyGetTransform = unityEngineComponentPropertyGetTransform;
6043-
Plugin::UnityEngineTransformPropertyGetPosition = unityEngineTransformPropertyGetPosition;
6044-
Plugin::UnityEngineTransformPropertySetPosition = unityEngineTransformPropertySetPosition;
6045-
Plugin::SystemCollectionsIEnumeratorPropertyGetCurrent = systemCollectionsIEnumeratorPropertyGetCurrent;
6046-
Plugin::SystemCollectionsIEnumeratorMethodMoveNext = systemCollectionsIEnumeratorMethodMoveNext;
6047-
Plugin::UnityEngineGameObjectMethodAddComponentMyGameBaseBallScript = unityEngineGameObjectMethodAddComponentMyGameBaseBallScript;
6048-
Plugin::UnityEngineGameObjectMethodCreatePrimitiveUnityEnginePrimitiveType = unityEngineGameObjectMethodCreatePrimitiveUnityEnginePrimitiveType;
6049-
Plugin::UnityEngineDebugMethodLogSystemObject = unityEngineDebugMethodLogSystemObject;
6050-
Plugin::UnityEngineMonoBehaviourPropertyGetTransform = unityEngineMonoBehaviourPropertyGetTransform;
6051-
Plugin::SystemExceptionConstructorSystemString = systemExceptionConstructorSystemString;
6052-
Plugin::BoxPrimitiveType = boxPrimitiveType;
6053-
Plugin::UnboxPrimitiveType = unboxPrimitiveType;
6054-
Plugin::UnityEngineTimePropertyGetDeltaTime = unityEngineTimePropertyGetDeltaTime;
6085+
60556086
Plugin::BaseBallScriptFreeListSize = 1000;
60566087
Plugin::BaseBallScriptFreeList = (MyGame::BaseBallScript**)curMemory;
60576088
curMemory += 1000 * sizeof(MyGame::BaseBallScript*);
60586089

6059-
Plugin::ReleaseBaseBallScript = releaseBaseBallScript;
6060-
Plugin::BaseBallScriptConstructor = baseBallScriptConstructor;
60616090
Plugin::BaseBallScriptFreeWholeListSize = 1000;
60626091
Plugin::BaseBallScriptFreeWholeList = (Plugin::BaseBallScriptFreeWholeListEntry*)curMemory;
60636092
curMemory += 1000 * sizeof(Plugin::BaseBallScriptFreeWholeListEntry);
6064-
6065-
Plugin::BoxBoolean = boxBoolean;
6066-
Plugin::UnboxBoolean = unboxBoolean;
6067-
Plugin::BoxSByte = boxSByte;
6068-
Plugin::UnboxSByte = unboxSByte;
6069-
Plugin::BoxByte = boxByte;
6070-
Plugin::UnboxByte = unboxByte;
6071-
Plugin::BoxInt16 = boxInt16;
6072-
Plugin::UnboxInt16 = unboxInt16;
6073-
Plugin::BoxUInt16 = boxUInt16;
6074-
Plugin::UnboxUInt16 = unboxUInt16;
6075-
Plugin::BoxInt32 = boxInt32;
6076-
Plugin::UnboxInt32 = unboxInt32;
6077-
Plugin::BoxUInt32 = boxUInt32;
6078-
Plugin::UnboxUInt32 = unboxUInt32;
6079-
Plugin::BoxInt64 = boxInt64;
6080-
Plugin::UnboxInt64 = unboxInt64;
6081-
Plugin::BoxUInt64 = boxUInt64;
6082-
Plugin::UnboxUInt64 = unboxUInt64;
6083-
Plugin::BoxChar = boxChar;
6084-
Plugin::UnboxChar = unboxChar;
6085-
Plugin::BoxSingle = boxSingle;
6086-
Plugin::UnboxSingle = unboxSingle;
6087-
Plugin::BoxDouble = boxDouble;
6088-
Plugin::UnboxDouble = unboxDouble;
6089-
/*END INIT BODY*/
6093+
/*END INIT BODY ARRAYS*/
60906094

60916095
// Make sure there was enough memory
60926096
int32_t usedMemory = (int32_t)(curMemory - (uint8_t*)memory);
@@ -6100,6 +6104,7 @@ DLLEXPORT void Init(
61006104

61016105
if (initMode == InitMode::FirstBoot)
61026106
{
6107+
// Clear memory
61036108
memset(memory, 0, memorySize);
61046109

61056110
/*BEGIN INIT BODY FIRST BOOT*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /