SUNENGINE 0.0.2
A simple and bright C++ game engine.
 
Loading...
Searching...
No Matches
SUNENGINE Documentation

Introduction

Welcome to the documentation for the SUNENGINE application. This engine is designed to provide a comprehensive framework for game development, offering a wide range of features to facilitate the creation and management of GameObjects, scenes, and input handling. The engine is built with a modular design, allowing for easy extension and customization to suit various game development needs.

Features

  • Game Loop: Provides a game loop for managing the flow of the game, including initialization, updating, drawing, and ending scenes.
  • AZUL Graphics: Utilizes the AZUL graphics library for rendering 2D/3D models, textures, and shaders.
  • Asset Management: Manages the loading and unloading of game assets, including textures, models, and fonts.
  • Scene Management: Efficiently handles the initialization, updating, drawing, and unloading of scenes.
  • GameObject Management: Provides a base class for game entities, allowing for easy registration and management of GameObjects.
  • Input Handling: Manages keyboard and mouse input events, providing a robust system for user interaction.
  • Collision Detection: Manages the registration and processing of collisions between GameObjects.
  • Drawable and Updatable Management: Handles objects that need to be drawn or updated in the game loop.
  • Sprites and SpriteFonts: Provides classes for managing 2D sprites and sprite fonts for rendering text.
  • Alarm System: Allows for timed events and actions within the game loop.
  • Camera Management: Manages the camera view for rendering scenes.
  • Memory Tracking: Dynamic memory leak tracking to ensure efficient memory usage.

Installation

Step 1: Setting Up the Project

  • Add "Framework.h" as a forced include file in your project settings.
  • Define the following preprocessor definitions:
    • WINDOWS_TARGET_PLATFORM="$(TargetPlatformVersion)"
    • MEMORY_LOGS_DIR=R"($(SolutionDir))"

Step 2: Building the Engine

  • Include the necessary headers in your source files.
  • Link against the required libraries.
  • Build the project using Visual Studio 2022.

Usage

Initialization

The engine is initialized and run through the WinMain function:

int WINAPI WinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPSTR, _In_ int)
{
SUNENGINEAttorney::InitDestroy::Destroy();
return 0;
}
static void Run()
Initializes the SUNENGINE instance.
Definition SUNENGINEAttorney.h:48
int WINAPI WinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPSTR, _In_ int)
Entry point for the application.
Definition main.cpp:19

LoadResources and Asset Management

The engine provides classes for managing the loading and unloading of game assets, including textures, models, and fonts.

TextureManager::Load("TextureName", "texture_file.tga");
ShaderManager::Load("ShaderName", "shader_file");
ModelManager::Load("ModelName", "model_file.azul");
ImageManager::Load("ImageName", TextureManager::Get("TextureName"));
SpriteFontManager::Load("FontName", "font_file.tga");
Texture* myTexture = TextureManager::Get("MyTexture");
Model* myModel = ModelManager::Get("MyModel");
SpriteFont* myFont = SpriteFontManager::Get("MyFont");
SceneManager::SetNextScene(new MyScene()); // Set the next scene to be loaded
static void Load(MapKey key, Texture *tex)
Loads an Image object from a Texture.
Definition ImageManager.h:70
static Model * Get(const std::string &key)
Retrieves a Model object by its key (private implementation).
Definition ModelManager.h:68
static void Load(const std::string &key, const Model::PreMadeModels model)
Loads a pre-made Model object (private implementation).
Definition ModelManager.h:76
static void SetNextScene(Scene *scene)
Sets the next scene to transition to.
Definition SceneManager.cpp:36
static void Load(const std::string &key, const std::string &path)
Loads a ShaderObject object from a file path.
Definition ShaderManager.h:80
Represents a font in the SUNENGINE.
Definition SpriteFont.h:19
static void Load(MapKey key, std::string path)
Loads a SpriteFont from a file.
Definition SpriteFontManager.h:40
static SpriteFont * Get(MapKey key)
Retrieves a SpriteFont by key.
Definition SpriteFontManager.h:33
static Texture * Get(const std::string &key)
Retrieves a Texture object by its key.
Definition TextureManager.h:63
static void Load(const std::string &key, const std::string &path)
Loads a Texture object from a file path.
Definition TextureManager.h:71

Scene Management

Scenes are managed by the Scene class, which provides methods for initialization, updating, drawing, and ending the scene. GameObjects can be registered for updates, drawing, alarms, input, and collisions.

class MyScene : public Scene
{
public:
void Initialize() override
{
// Initialization code here
}
void SceneEnd() override
{
// Cleanup code here
}
};
// Setting the current scene
Represents a scene in the engine.
Definition Scene.h:32
virtual void SceneEnd()=0
Ends the scene. Defined by the user.
virtual void Initialize()=0
Initializes the scene. Defined by the user.
static void SetCurrentScene(Scene *scene)
Sets the current scene.
Definition SceneManager.h:93

GameObject Management

GameObjects are the primary class for game entities that use the following components. They can be registered for updates, drawing, alarms, input, and collisions. The GameObject class provides a base implementation for game entities.

class MyGameObject : public GameObject
{
public:
void SceneEntry() override
{
// Code to execute when the object enters the scene
SubmitAlarmRegistration(AlarmableManager::ALARM_ID::ALARM_0, 5.0f);
SubmitKeyRegistration(AZUL_KEY::KEY_A, EventType::KEY_HELD);
}
void SceneExit() override
{
// Code to execute when the object exits the scene
SubmitAlarmDeregistration(AlarmableManager::ALARM_ID::ALARM_0);
SubmitKeyDeregistration(AZUL_KEY::KEY_A, EventType::KEY_HELD);
}
void Update() override
{
// Update logic here
}
void Draw() override
{
// Drawing logic here
}
void Draw2D() override
{
// 2D drawing logic here
}
void KeyInactive(AZUL_KEY key) override
{
// Key pressed logic here
}
void KeyPress(AZUL_KEY key) override
{
// Key pressed logic here
}
void KeyHeld(AZUL_KEY key) override
{
// Key pressed logic here
}
void KeyRelease(AZUL_KEY key) override
{
// Key released logic here
}
void Alarm0() override
{
// Alarm logic here
}
void Collision(GameObject* other) override
{
// Collision handling logic here
}
};
void SubmitAlarmDeregistration(AlarmableManager::ALARM_ID id)
Submits the alarm deregistration for the GameObject.
Definition Alarmable.cpp:33
virtual void Alarm0()
Virtual method to be implemented by derived classes for alarm 0 when triggered.
Definition Alarmable.h:68
void SubmitAlarmRegistration(AlarmableManager::ALARM_ID id, float t)
Submits the alarm registration for the GameObject.
Definition Alarmable.cpp:25
void SubmitCollisionRegistration()
Submits the collision registration for the GameObject.
Definition Collidable.cpp:38
void SubmitCollisionDeregistration()
Submits the collision deregistration for the GameObject.
Definition Collidable.cpp:45
void SubmitDrawDeregistration()
Submits the draw deregistration for the GameObject.
Definition Drawable.cpp:27
void SubmitDrawRegistration()
Submits the draw registration for the GameObject.
Definition Drawable.cpp:20
virtual void Draw2D()
Virtual method to be implemented by derived classes for 2D draw functionality.
Definition Drawable.h:67
virtual void Draw()
Virtual method to be implemented by derived classes for draw functionality.
Definition Drawable.h:62
Base class for all GameObjects in the engine.
Definition GameObject.h:21
virtual void SceneExit()
Called when the GameObject exits the scene; used for registration management, called by user.
Definition GameObject.h:81
virtual void SceneEntry()=0
Called when the GameObject enters the scene; used for registration management, called by system on en...
virtual void KeyPress(AZUL_KEY k)
Virtual method to be implemented by derived classes for key press functionality.
Definition Inputable.h:161
virtual void KeyInactive(AZUL_KEY k)
Virtual method to be implemented by derived classes for key inactive functionality.
Definition Inputable.h:155
virtual void KeyRelease(AZUL_KEY k)
Virtual method to be implemented by derived classes for key release functionality.
Definition Inputable.h:173
virtual void KeyHeld(AZUL_KEY k)
Virtual method to be implemented by derived classes for key held functionality.
Definition Inputable.h:167
void SubmitKeyRegistration(AZUL_KEY k, EventType e)
Submits the key registration for the GameObject.
Definition Inputable.cpp:31
void SubmitKeyDeregistration(AZUL_KEY k, EventType e)
Submits the key deregistration for the GameObject.
Definition Inputable.cpp:54
void SubmitUpdateDeregistration()
Submits the update deregistration for the GameObject.
Definition Updatable.cpp:27
void SubmitUpdateRegistration()
Submits the update registration for the GameObject.
Definition Updatable.cpp:18
virtual void Update()
Virtual method to be implemented by derived classes for update functionality.
Definition Updatable.h:62

Input Handling

The Inputable class provides a base implementation for handling keyboard input events. It manages registration and deregistration with the KeyboardEventManager.

class MyInputable : public GameObject
{
public:
void KeyInactive(AZUL_KEY key) override
{
// Key pressed logic here
}
void KeyPress(AZUL_KEY key) override
{
// Key pressed logic here
}
void KeyHeld(AZUL_KEY key) override
{
// Key pressed logic here
}
void KeyRelease(AZUL_KEY key) override
{
// Key released logic here
}
};
SubmitKeyRegistration(AZUL_KEY::KEY_A, EventType::KEY_HELD); // Register for key held events

Collision Detection

The Collidable class provides a base implementation for objects that need to participate in collision detection. It manages registration and deregistration with the CollisionManager.

class MyCollidable : public GameObject
{
public:
void Collision(GameObject* other) override
{
// Collision handling logic here
}
};
SetCollisionSelf<AdvancedFrigate>();
SetCollisionSelf<Cottage>();
SetCollisionPair<AdvancedFrigate, Cottage>(); // Set collision pairs for the scene
SetColliderModel(pGObj->getModel());
SetCollidableGroup<AdvancedFrigate>();
SubmitCollisionRegistration(); //Set the collision model and group in the GameObject.
this->UpdateCollisionData(world); // Ensure the collision data is up to date after movement.

Drawable Management

The Drawable class provides a base implementation for objects that need to be drawn during the game loop. It manages registration and deregistration with the DrawableManager.

class MyDrawable : public GameObject
{
public:
void Draw() override
{
// Drawing logic here
}
void Draw2D() override
{
// 2D drawing logic here
}
};
SubmitDrawRegistration(); // Register for drawing

Updatable Management

The Updatable class provides a base implementation for objects that need to be updated during the game loop. It manages registration and deregistration with the UpdatableManager.

class MyUpdatable : public GameObject
{
public:
void Update() override
{
// Update logic here
}
};
SubmitUpdateRegistration(); // Register for updates

Sprites and SpriteFonts

The engine provides classes for managing 2D sprites and sprite fonts for rendering text.

SUNENGINESprite* mySprite = new SUNENGINESprite("MySprite");
mySprite->SetPosition(100.0f, 150.0f);
mySprite->SetScaleFactor(0.5f, 0.5f);
SpriteString* myString = new SpriteString(SpriteFontManager::Get("Courier_New"), "Hello, World!", 10, 40);
Represents a sprite in the SUNENGINE.
Definition Sprites/SUNENGINESprite.h:16
void SetScaleFactor(float x, float y)
Sets the scale factor of the sprite.
Definition Sprites/SUNENGINESprite.cpp:50
void SetPosition(float x, float y)
Sets the position of the sprite.
Definition Sprites/SUNENGINESprite.cpp:34
Represents a string of sprites in the SUNENGINE.
Definition SpriteString.h:18

Alarm System

The engine provides an alarm system that allows for timed events and actions within the game loop.

class MyAlarmable : public GameObject
{
public:
void Alarm0() override
{
// Alarm logic here
}
};
SubmitAlarmRegistration(AlarmableManager::ALARM_ID::ALARM_0, 5.0f); // Set an alarm for 5 seconds

Camera Management

The engine provides classes for managing the camera view for rendering scenes.

Camera* myCamera = new Camera(Camera::Type::PERSPECTIVE_3D);
myCamera->setOrientAndPosition(Vect(0.0f, 1.0f, 0.0f), Vect(0.0f, 0.0f, -1.0f), Vect(0.0f, 0.0f, 5.0f));