rjmelter Posted February 21, 2023 Share Posted February 21, 2023 What would I need to do to make these two feasible? #include "UltraEngine.h" #include "ComponentSystem.h" #include "UESystem.h" using namespace UltraEngine; UESystem CoreSystem; // SmartPointer World bool ProgramActive = true; int main(int argc, const char* argv[]) { CoreSystem = UESystem(); CoreSystem.Setup(1920,1080); //World = CoreSystem.World; while (ProgramActive) { CoreSystem.Update(); } // C L E A N U P return 0; } class UESystem { public: static void Setup(int height, int width),InitDisplays(), InitWindow(), InitWorld(), InitCamera(); // WORLD(S) -- ACTUAL "OBJECT" // CAMERA(S)-- ACTUAL "OBJECT" // WINDOW(S)-- ACTUAL "OBJECT" static int windowWidth; static int windowHeight; static void Update() { // World.Update(); // World.Render(framebuffer); } static void Setup(int height, int width) { windowHeight = height; windowWidth = width; InitDisplays(); InitWindow(); InitWorld(); InitCamera(); } static void InitDisplays() { //auto displays = GetDisplays(); } static void InitWindow() { //auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //auto framebuffer = CreateFramebuffer(window); } static void InitWorld() { //auto world = CreateWorld(); //auto light = CreateBoxLight(world); //light->SetRotation(35, 45, 0); //light->SetRange(-10, 10); } static void InitCamera() { //auto camera = CreateCamera(world); //camera->SetClearColor(0.125); //camera->SetFov(70); //camera->SetPosition(0, 0, -3); } }; *** I would like to be able to access the world from the coresystem if/when necessary and so within the UESystem class, I would like to have them as global variables probably static so that the individual functions will set the variables for future access when needed. The whole smart pointer thing is confusing me. I watched your video where you explained why you use auto, and that makes sense, and I would like to continue to use it for other stuff, but initially in this step, I would like fixed variables. Quote Link to comment Share on other sites More sharing options...
Solution SpiderPig Posted February 22, 2023 Solution Share Posted February 22, 2023 Are you just wondering how to define the variables? In which case you simply enclose the class name like this: shared_ptr<World> world; Quote Link to comment Share on other sites More sharing options...
rjmelter Posted February 22, 2023 Author Share Posted February 22, 2023 1 minute ago, SpiderPig said: Are you just wondering how to define the variables? In which case you simply enclose the class name like this: shared_ptr<World> world; Yeah so that it is not using auto but still relevant to the documentation. also was asking noobie question since I have not had to write header files in a while. What that include should look like. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted February 22, 2023 Share Posted February 22, 2023 In UESystem.h declare a variable after the class like this: extern UESystem CoreSystem; (I've only ever used raw pointers for this but I assume it will work the same) Then in you main.cpp keep your definition of: UESystem CoreSystem; Then you can include UESystem.h where ever you want and access its public members and methods ike so: CoreSystem.world ...etc. 1 Quote Link to comment Share on other sites More sharing options...
rjmelter Posted February 22, 2023 Author Share Posted February 22, 2023 17 minutes ago, SpiderPig said: In UESystem.h declare a variable after the class like this: extern UESystem CoreSystem; (I've only ever used raw pointers for this but I assume it will work the same) Then in you main.cpp keep your definition of: UESystem CoreSystem; Then you can include UESystem.h where ever you want and access its public members and methods ike so: CoreSystem.world ...etc. Ill try that soon. Put this together. Got it working with the class created before the main function etc and with your note on shared pointers etc. Noticed that there is no GUI interaction available when I used my own bool/while loop vs using the one that is created with the new project. Is there an underlying reason for that I assume when checking the window values? Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted February 22, 2023 Share Posted February 22, 2023 ...not too sure about that one. If your calling PeekEvent and WaitEvent it should work. It may be a bug... Quote Link to comment Share on other sites More sharing options...
Josh Posted February 22, 2023 Share Posted February 22, 2023 You probably want your Update method to do something like this: bool System::Update() { if (window->KeyDown(KEY_ESCAPE)) return false; world->Update(); world->Render(framebuffer); return true; } And then your main loop in main.cpp would be something like this: while (true) { if (not system.Update()) break; } If you are looking for a way to structure and compartmentalize your code, you may want to check out the entity component system. 1 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...
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.