Josh Posted August 22, 2023 Share Posted August 22, 2023 C++ component system integration with editor is finished. The best way to learn is to look at the sample components in Source/Components. To use a component include the header file. If you want components to be loaded automatically from a map, you need to call RegisterComponent() so the engine knows it exists: #include "UltraEngine.h" #include "Components/Motion/Mover.hpp" #include "Components/Player/CameraControls.hpp" using namespace UltraEngine; int main(int argc, const char* argv[]) { RegisterComponent<Mover>(); RegisterComponent<CameraControls>(); Don't forget the component name, since this is how it is identified: Mover() { name = "Mover"; } The Copy method is also required. In most cases you can just use this code, which will just copy all the object values: virtual shared_ptr<Component> Copy() { return std::make_shared<Mover>(*this); } When loading a component from a map, the engine will automatically call the Load method: virtual bool Load(table& properties, shared_ptr<Stream> binstream, shared_ptr<Scene> scene, const LoadFlags flags) { if (properties["movementspeed"].is_array() and properties["movementspeed"].size() == 3) { movementspeed.x = properties["movementspeed"][0]; movementspeed.y = properties["movementspeed"][1]; movementspeed.z = properties["movementspeed"][2]; } if (properties["rotationspeed"].is_array() and properties["rotationspeed"].size() == 3) { rotationspeed.x = properties["rotationspeed"][0]; rotationspeed.y = properties["rotationspeed"][1]; rotationspeed.z = properties["rotationspeed"][2]; } if (properties["globalcoords"].is_boolean()) globalcoords = properties["globalcoords"]; return true; } New methods have been added. UpdateMatrix() will be called anytime the entity moves or rotates. Listen() and ProcessEvent() can be used to respond to GUI and other events: bool Component::ProcessEvent(const Event& e) { switch (e.id) { case EVENT_KEYDOWN: break; } return true; } 3 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted August 23, 2023 Share Posted August 23, 2023 You're the best, now the real fun begins! I'll be playing with this for sure this weekend. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
reepblue Posted August 26, 2023 Share Posted August 26, 2023 I can't seem to call RegisterComponent from the engine API, it states it's undefined. I just copied and pasted the function in my code, and it works. Made it work, it was my implementation as I don't want to register everything within the main function. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted August 26, 2023 Author Share Posted August 26, 2023 I tried to make it so each component header would automatically register its own class, but this is not really possible in C++: https://en.cppreference.com/w/cpp/language/siof Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted August 26, 2023 Share Posted August 26, 2023 I just created a file called "RegisterComponents.cpp" and I have it in my Components folder. Then I call the function in my Program class. #pragma once #include "UltraEngine.h" #include "RegisterComponents.h" // Components #include "Motion/Mover.hpp" #include "Player/CameraControls.hpp" #include "Player/SettingsListener.hpp" namespace UltraEngine::Game { void RegisterComponents() { RegisterComponent<Mover>(); RegisterComponent<CameraControls>(); RegisterComponent<SettingsListener>(); } } Everything works as expected. My only issue right now is that the editor can't load existing ultra maps which makes further developing this annoying, but I expect this to be fixed eventually. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.