Jump to content

The only way to learn c++ is with Ultra Engine. xD


Recommended Posts

Posted

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);
    }
   
}

 

  • Confused 1

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Posted

I find your class confusing, but if you use make_shared<CWindow>(width, height) it will create a shared pointer for you.

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted
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++.

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...