Nebula
Loading...
Searching...
No Matches
App

The App Subsystem

The App namespace offers a set of Application classes which simplify setting up a proper Nebula application. The general idea is that an application derives a subclass from one of the specialized Application classes and adds its own functionality to the virtual Application::Open(), Application::Run() and Application::Close() methods.

Here's an example of what a Nebula application's main source code should look like:

//------------------------------------------------------------------------------
// main.cc
// (C) 2021 Company name
//------------------------------------------------------------------------------
#include "stdneb.h"
#include "myapp/myapplication.h"
using namespace App;
using namespace Util;
//------------------------------------------------------------------------------
void
NebulaMain(const CommandLineArgs& args)
{
MyApplication app;
app.SetCompanyName("My Company");
app.SetAppTitle("My Application");
app.SetCmdLineArgs(args);
if (app.Open())
{
app.Run();
app.Close();
}
app.Exit();
}
#define ImplementNebulaApplication()
Definition appentry.h:33
A universal cmd line argument parser.
Definition commandlineargs.h:24
Definition gameapplication.cc:24
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6

The macro ImplementNebulaApplication() takes care about some platform-specifics (mainly how arguments are passed to a program) and then calls the NebulaMain() function, which receives a Util::CmdLineArgs object which contains the command line arguments. The MyApplication class is a user-derived class. The application object needs to be setup with a company name, an application name (these two uniquely identify the application and are for used to create a data directory under "My Files" which will contain application specific files (likes configuration settings or save game files). The Open() method will setup the application for use. If something goes wrong the method will return false. Run() should implement the actual application features, it may run in a loop until the user wants to exit, or it may return immediately. Close() will shutdown the application. Finally Exit() must be called to properly cleanup Nebula before exiting the application. This will shutdown any static objects, perform cleanup, a RefCounting leak and memory leak check and finally exit the application process.