Yue Posted August 28 Share Posted August 28 Question, is this well implemented with smart pointers? no need to remove anything from memory? #include "UltraEngine.h" #include <memory> #include "CWindow.h" using namespace UltraEngine; // Constructor por defecto CWindow::CWindow() : width(800), height(600) { //Get the displays auto displays = GetDisplays(); //Create a window window = CreateWindow("Test Game", 0, 0, 1280 * displays[0]->scale, 720 * displays[0]->scale, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); if (this->window) { Print("Object Windows Create... Ok!"); } } shared_ptr<Window> CWindow::getWindow() const { if (this->window) { return shared_ptr<Window>(this->window); } } bool CWindow::getKeyDown(KeyCode KEY_CODE) { if (this->window) { return this->window->KeyDown(KEY_CODE); } } 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted August 28 Share Posted August 28 I find your class confusing, but if you use make_shared<CWindow>(width, height) it will create a shared pointer for you. 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...
Andy90 Posted August 29 Share Posted August 29 What do you want to do with the CWindow ? Quote Link to comment Share on other sites More sharing options...
Yue Posted August 29 Author Share Posted August 29 6 hours ago, Andy90 said: ¿Qué desea hacer con CWindow? It's just a test to learn how to program in C++ and the motivation is that with Leadwers and Ultra engine I am very motivated. It would be only a class to implement the Windows object in main. Something like this. //******************************************************************// // Nombre del Proyecto : Astrocuco. // // Programador : Yue Rexie. // // Sitio Web : www.papillon-games.xyz // // Fichero : main.cpp. // // Descripción : Fichero principal de entrada al programa. // // // //******************************************************************// #include "UltraEngine.h" //#include "ComponentSystem.h" //#include "Steamworks/Steamworks.h" using namespace UltraEngine; using namespace std; #include "CApp.h" #include "CWindow.h" int main(int argc, const char* argv[]) { //RegisterComponents(); //auto cl = ParseCommandLine(argc, argv); //Load FreeImage plugin (optional) auto fiplugin = LoadPlugin("Plugins/FITextureLoader"); // Objects. shared_ptr<CApp> App = make_shared<CApp>(); shared_ptr<CWindow> window = make_shared<CWindow>(App->GetName()); //Create a framebuffer auto framebuffer = CreateFramebuffer(window->getWindow()); //Create a world auto world = CreateWorld(); auto camera = CreateCamera(world); auto scene = LoadMap(world, "Maps/start.ultra"); //Main loop while (window->getWindow()->Closed() == false and window->getKeyDown(KEY_ESCAPE) == false) { world->Update(); world->Render(framebuffer); } return 0; The class is being implemented with a smart pointer, which implies that the object is automatically deleted and frees me from responsibility if it breaks, ever try it in Leadwers and memory overflow. xD. #include "UltraEngine.h" #include <memory> #include "CWindow.h" using namespace UltraEngine; // Constructor por defecto CWindow::CWindow(const string nameApp) { //Get the displays auto displays = GetDisplays(); this->width = 1280; this->height = 720; //Create a window window = CreateWindow(nameApp, 0, 0, this->width * displays[0]->scale, this->height * displays[0]->scale, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); if (this->window) { Print("Object Windows Create... Ok!"); } } shared_ptr<Window> CWindow::getWindow() const { if (this->window) { return shared_ptr<Window>(this->window); } } bool CWindow::getKeyDown(KeyCode KEY_CODE) { if (this->window) { return this->window->KeyDown(KEY_CODE); } } For some reason my journey with Josh's engines is just that, a continuous learning process, and with the basics of Lua script, I'm finally taking the step to C++. Quote 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.