Jump to content

Creating a class for initial system.


rjmelter
 Share

Go to solution Solved by SpiderPig,

Recommended Posts

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

 

UltraEngine1.png

***

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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?
 

 

Link to comment
Share on other sites

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.

  • Like 1

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

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.

 Share

×
×
  • Create New...