Skip to content

Guerrilla Renderer

Twarit Waikar edited this page Dec 11, 2018 · 13 revisions

Rubeus: Guerrilla Renderer

Created by SDSLabs with ❤️

Guerrilla Renderer is the standard renderer that Rubeus uses to render 2D sprites. The name Guerrilla comes from the fact that it attempts to add all the sprites to the GPU memory at once, instead of adding them one by one to provide a performance boost. (which makes the name a bit ironic)

How to use it?

  1. Before proceeding, check out Making a ping-pong game to see how to setup a Rubeus project.
  2. Create a level named sample_level.
  3. Create a game object named sample_object.
  4. Instantiate your level and object in user_init.cpp likewise:
Usample_level * sample_level = new Usample_level("sample_level");
Usample_object * sample_object = new Usample_object("sample_object",// Object name
                                                    "sample_level", // Your pre-made level name
                                                    3.0f, 3.0f,     // Position of the object (Lower left corner is origin and top right corner is 16.0f, 16.0f) 
                                                    3.0f, 3.0f,     // Width, Height (same scale as of the position)
                                                    255, 0, 0, 255  // Color in RGBA                                                   
);
  1. Run your game.

All game objects that belong to a level (argument #2) get loaded into the renderer when Rubeus engine loads that particular level.

Contributor's guide

Guerrilla Renderer is a member object of a Static Layer class. The layer's draw() function uses the member renderer and calls the submit() function on the sprite objects which also sends a reference to the layer's renderer and calls the submit() function on the passed-in renderer.

This type of a system where the responsibility of adding the sprite to the rendering queue is put on the sprite itself was done to incorporate children group objects in the game object hierarchy.

All group objects also have an overriding submit() function that is used by the static layer's draw() function, in case one of the children of the parent group object is a group object instead of a game object. To achieve this form of a functional polymorphism, the Group class and the Sprite class inherit from the RenderableObject class. The RenderableObject class provides a compulsorily overridable submit() function, which is polymorphed to be behaving differently when the object is of group type from when the object is of a game object type.

Rubeus' Guerrilla renderer is highly inspired by an older version of Sparky Engine, initially a cross-platform, high-performance 2D game engine.

The naive game loop implemented above will be hidden into the engine implementation later when the architecture has been decided.