-
-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dmSDK: Added possibility to load collection proxies and spawn factories from C++ #8667
Conversation
This includes HPropertyContainer and builder
{ | ||
dmExtension::Params params; | ||
params.m_ConfigFile = engine->m_Config; | ||
params.m_ResourceFactory = engine->m_Factory; | ||
if (engine->m_SharedScriptContext) { | ||
params.m_L = dmScript::GetLuaState(engine->m_SharedScriptContext); | ||
} else { | ||
params.m_L = dmScript::GetLuaState(engine->m_GOScriptContext); | ||
} | ||
dmExtension::Event event; | ||
event.m_Event = dmExtension::EVENT_ID_ENGINE_DELETE; | ||
dmExtension::DispatchEvent( ¶ms, &event ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New feature:
Since the extension system isn't aware of the game loop as such, I introduced two new events EVENT_ID_ENGINE_DELETE
and EVENT_ID_ENGINE_INITIALIZED
so that the extension can act upon it.
I.e. this helps with things like: don't load things before the game has been initialized, and don't delete your things too late.
dmGameObject::HComponentWorld m_World; | ||
/// User data storage pointer | ||
uintptr_t* m_UserData; | ||
dmGameObject::HComponentInternal m_UserData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding more type safety.
@@ -86,6 +86,34 @@ namespace dmGameObject | |||
*/ | |||
typedef struct CollectionHandle* HCollection; | |||
|
|||
/*# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from internal header.
* @typedef | ||
* @name HComponent | ||
*/ | ||
typedef void* HComponent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A HComponent, is intended to be a fully resolved pointer, to be used with our c++ sdk's.
* @typedef | ||
* @name HComponentInternal | ||
*/ | ||
typedef uintptr_t HComponentInternal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A HComponentInternal, may be anything that the component type needs (e.g. a uin16_t handle). It needs to be resolved (handled by our component extensions) to get an actual pointer.
@@ -97,18 +104,46 @@ namespace dmGameSystem | |||
return dmGameObject::UPDATE_RESULT_OK; | |||
} | |||
|
|||
void LoadComplete(CollectionProxyComponent* proxy) | |||
void LoadComplete(CollectionProxyComponent* proxy, dmGameObject::Result result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reusing the same flow for two use cases: messages vs c++ invokation
{ | ||
FactoryResource* resource = CompFactoryGetResource(component); | ||
(void)world; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While not technically needed, it seems nice to have a similar api from all the components in the form "CompMyTypeDoSomething(world, component)"
dmGameObject::HInstance CompFactorySpawn(HFactoryWorld world, HFactoryComponent component, dmGameObject::HCollection collection, | ||
uint32_t index, dmhash_t id, | ||
const dmVMath::Point3& position, const dmVMath::Quat& rotation, const dmVMath::Vector3& scale, | ||
dmGameObject::HPropertyContainer properties) | ||
{ | ||
dmGameObject::HPrototype prototype = CompFactoryGetPrototype(world, component); | ||
const char* path = CompFactoryGetPrototypePath(world, component); | ||
|
||
dmGameObject::HInstance instance = dmGameObject::Spawn(collection, prototype, path, id, properties, position, rotation, scale); | ||
if (instance != 0x0) | ||
{ | ||
dmGameObject::AssignInstanceIndex(index, instance); | ||
} | ||
else | ||
{ | ||
dmGameObject::ReleaseInstanceIndex(index, collection); | ||
} | ||
return instance; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from script_factory.cpp, helping us to encapsulate the functionality more.
@@ -557,11 +557,11 @@ namespace dmGameSystem | |||
InitParametersFromDescription(component, ddf); | |||
} | |||
|
|||
void* CompLabelGetComponent(const dmGameObject::ComponentGetParams& params) | |||
dmGameObject::HComponent CompLabelGetComponent(const dmGameObject::ComponentGetParams& params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a void*, but easier to understand what it's supposed to return.
@@ -235,16 +237,51 @@ namespace dmGameSystem | |||
* end | |||
* ``` | |||
*/ | |||
static int FactoryComp_CreateWithMessage(lua_State* L, dmGameObject::HCollection collection, dmGameObject::HInstance sender_instance, dmMessage::URL* receiver, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the more surprising case: When does this actually happen?
I.e. we call factory.create, but don't have a game object instance set?
I left it "as-is" for now. Potential candidate for removal imho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of stuff! But great stuff!
@@ -123,7 +123,7 @@ static dmGameObject::HInstance Spawn(dmResource::HFactory factory, dmGameObject: | |||
|
|||
static dmGameObject::HInstance Spawn(dmResource::HFactory factory, dmGameObject::HCollection collection, const char* prototype_name, dmhash_t id) | |||
{ | |||
return Spawn(factory, collection, prototype_name, id, 0, 0, Point3(0, 0, 0), Quat(0, 0, 0, 1), Vector3(1, 1, 1)); | |||
return Spawn(factory, collection, prototype_name, id, 0, Point3(0, 0, 0), Quat(0, 0, 0, 1), Vector3(1, 1, 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this using the new spawn function introduced in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the local test_gamesys.cpp:Spawn (see above), and it in turn uses the new dmGameObject::Spawn which takes a HProperties.
# Conflicts: # engine/gameobject/src/gameobject/gameobject.cpp # engine/gamesys/src/gamesys/test/test_gamesys.cpp
This update adds more functionality to our C++ sdk, which is part of our effort to allow a developer to write the game logic using C++.
It is an ongoing task, and we'll add more functionality along the way.
dmsdk/extension/extension.h
Allows for more control of from within an extension:
dmsdk/gameobject/gameobject_props.h
Removed Lua dependency when creating game object properties.
Added property container type to sdk for making it possible to spawn game objects:
dmsdk/gameobject/gameobject.h
Added more functionality that allows for spawning game objects, and getting components.
dmsdk/gameobject/component.h
Added more type safety (also for readability) using two new typedefs:
Misc
Removed deprecated function:
Fixes: #8930
PR checklist
Example of a well written PR description:
### Technical changes
Technical changes:
Technical notes: