Skip to content

Basic engine initialization

Michele edited this page Oct 9, 2019 · 5 revisions

Preface

Most of the "basic engine usage" Wiki is based on the SimpleGame code, so there will be examples referring to that code.

Initialize the engine

SimpleGame keep all the initialization in Game.cpp, directly inside int main().

The first thing to do it's to create an EngineManager object calling:

ScrapEngine::Manager::EngineManager(...)

This will initialize the engine and create a game instance, creating the window and all the engine stuff.

The loading screen

Once the engine has been initialized, it will display the loading screen until you start the game. This is useful because you can take all the time you need to load a huge 3D model or to initialize a large amount of objects. So, until you start the game, the loading screen is displayed and you can do whatever you want without slowing down the game render.

Getting the main managers

The ScrapEngine is divided into Managers, every side of it has a Manager that manage its calls and objects. There are 2 managers that are very important, the LogicManagerView and the ComponentsManager. Let's describe the main managers:

  • LogicManagerView: it's a user-view of the LogicManager, responsible of executing the GameObject events and registering/unregistering GameObjects. A GameObjects doesn't execute game_start() and game_update(...) if it hasn't been registered in the LogicManager. game_start() and game_update(...) aren't always necessary so it's up to the user if to register a GameObject or not.

  • ComponentsManager: it's responsible of creating and managing components. a Component it's an object that is possesed by a GameObject (a Mesh for example). If you need to create or to destroy a component, you must use the methods in ComponentsManager.

But there are others managers that are useful, such as:

  • InputManager: if you want/need to read user input, you must use the InputManager. It's responsible of managing the mouse cursor and reading if a keyboard/mouse key is pressed or not.

  • SceneManager: right now the SceneManager is responsible only of creating and editing a Skybox. But more stuff might be added in the future, as sun light management or similar .

  • RenderManagerView: it's a user-view of the RenderManager, responsible of rendering the game. Right now is useful only to get the GameWindow and the game Camera, but more stuff might be added in the future.

Remember that all the necessary managers are accessible from the EngineManager, that's the public interface to the user.

Starting the game

Once you're done creating the engine and the objects, you can start the game with:

scrap_engine_manager_obj->start_game_loop();

First, the EngineManager will call game_start() to every SGameObject registered. Then, the game render will begin, starting the execution of the engine loop (see article).

I want to know more

For more about creating objects and engine calls see "basic engine usage".