A micro general purpose media application framework in C++.
C++ CMake C Other
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



NSEngine is a micro general-purpose media application framework written in C++. It's mainly supposed to be used for rapid prototyping of games. It features hardware-accelerated 2D rendering and a cross-platform interface.


1 Overview

1.1 Usage

NSEngine acts as an underlying framework for your application. It is not a game engine per se, but it could be used as basis for one.

1.2 Structure

NSEngine consists of subsystems which cover specific parts. At the moment, the subsystems are:

  • Common: manages everything and keeps control of the Game, it serves for often used functions (printing, logging, ...)
  • Filesystem: abstract the file system
  • Graphics: contains all the code to draw simple rectangle graphics.
  • Input: provides access to keyboard and mouse
  • ResourceManager: loads game data (fonts, textures, sounds, ...)
  • SoundSystem: plays and loads sound data

All these subsystems are implemented as single classes, that are abstracted behind a public interface. (See NSEngine/include)

1.3 The Game

The "Game" is represented as a single shared library. This library is loaded by NSEngine. In this way, one engine executable can load different games, as long as they share the same API version. Alternatively you may compile your game directly into the NSEngine executable. This may be useful e.g. when shipping your game.

1.4 Initialization process

NSEngine handles all platform-specific and library initializations by itself. The app-developer only has to define one single initialization function, which is named "GameDllExchange", which is called by NSEngine to exchange interface pointers.

Example from GameTest/main.cpp:

class CGame : public IGame

CGame game_local;

extern "C" GAMEAPI void GameDllExchange(EngineGlobals *eg, GameGlobals *gg)
        ::common      = eg->common;
        ::config      = eg->config;
        ::fileSystem  = eg->filesystem;
        ::game        = &game_local;
        ::graphics    = eg->graphics;
        ::input       = eg->input;
        ::resMgr      = eg->resMgr;
        ::soundSystem = eg->soundSys;

        gg->game = &game_local;

The engine serves the app with interface-implementations, while the app shares its IGame object. The entire app is abstracted behind this single interface.

1.5 Runtime

On startup, the Engine loads all the libraries needed and initializes all the subsystem instances. Then it calls GameDllExchange (before loading the Game library, when it is not a standalone build). The pointers get exchanged. The engine enters the game loop and calls IGame::Update and IGame::Render every frame.

2 Building

2.1 Linux

Install g++, CMake, SDL, SDL_Image, SDL_TTF, SDL_mixer

Example for Debian based:

apt-get install g++ cmake libsdl1.2-dev libsdl-image1.2-dev libsdl-ttf2.0-dev tinyxml-dev

CD into the project directory. Run this:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..

2.2 OSX

Install clang, CMake, SDL, SDL_Image, SDL_TTF, SDL_mixer

brew install gcc clang cmake sdl sdl_ttf sdl_image sdl_mixer

CD into the project directory. Run this:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..

2.3 Windows

Install Visual Studio 2013 for Windows Desktop. Install CMake. Install my package manager, NSPkgMgr. Build it from here: https://github.com/Nuke928/NSPkgMgr

Inside NSPkgMgr, run these commands:

get sdl-dev sdl-x86 sdl_image-dev sdl_image-x86 sdl_mixer-dev sdl_mixer-x86 sdl_ttf-dev sdl_ttf-x86 tinyxml-dev

CD into the project directory. Run this:

mkdir build
cd build
cmake -G "Visual Studio 12" -DCMAKE_BUILD_TYPE=Debug ..

Now open the project with Visual Studio and compile.