Basic Application Example

When creating a new application using Chilli Source the first thing you will need is a subclass of Application.

class BasicApp final : public CSCore::Application
{
public:
 void CreateSystems() override;
 void OnOnit() override;
 void PushInitialState() override;
 void OnDestroy() override;
};
 
void BasicApp::CreateSystems()
{
 //Create app systems here.
}
 
void BasicApp::OnOnit()
{
 //Initialisation code here.
}
 
void BasicApp::PushInitialState()
{
 //create the first state.
}
 
void BasicApp::OnDestroy()
{
 //Destruction code here.
}

This is instantiated on start up by the engine using the CreateApplication() function. This can be defined anywhere.

CSCore::Application* CreateApplication()
{
 return new BasicApp();
}

Next you will need your first state.

class BasicState final : public CSCore::State
{
public:
 void CreateSystems() override;
 void OnOnit() override;
 void OnUpdate(f32 in_deltaTime) override;
 void OnDestroy() override;
}
 
void BasicState::CreateSystems()
{
 //Create state systems here.
}
 
void BasicState::OnOnit()
{
 //Initialisation code here.
}
 
void BasicState::OnUpdate(f32 in_deltaTime)
{
 //Update code here.
}
 
void BasicState::OnDestroy()
{
 //Destruction code here.
}

This should be pushed to the state stack by your Application:

void BasicApp::PushInitialState()
{
 GetStateManager()->Push(std::make_shared());
}

This should be enough to compile and run the application! Most applications will also need a camera. A camera is an Entity with a Camera Component attached to it. Camera Components can be created through the Render Component Factory. Render Component Factory is an App System, which can be acquired through the Application.

void BasicState::OnOnit()
{
 //Create the camera component
 CSRendering::RenderComponentFactory* renderComponentFactory = CSCore::Application::Get()->GetSystem();
 CSRendering::CameraComponentSPtr cameraComponent = renderComponentFactory->CreatePerspectiveCameraComponent(CSCore::MathUtils::k_pi / 2.0f, 1.0f, 100.0f);
 
 //create the camera entity and add the camera component
 CSCore::EntitySPtr cameraEntity = CSCore::Entity::Create();
 cameraEntity->AddComponent(cameraComponent);
 
 //add the camera to the scene
 GetScene()->Add(cameraEntity);

More complete examples of a Chilli Source application can be found in the Chilli Source Samples repository. This can be found at https://github.com/ChilliWorks/CSSamples.