redhand::complex_world class

This is the underlying type for worlds with lots of low level functions for managing objects.

Constructors, destructors, conversion operators

complex_world()
The constructor will create an empty world which can be filled with objects.
~complex_world() virtual
The destructor will clean up everything and delete all objects stored in this world.

Public functions

auto addShader(std::unique_ptr<redhand::shader>) -> int virtual
The addShader function will add a shader to the world.
auto addTexture(std::unique_ptr<redhand::texture2D>) -> int virtual
The addTexture function will add a texture to the world.
auto addObject(std::unique_ptr<redhand::game_object>) -> int virtual
The addObject function will add an object to the world.
auto add(std::shared_ptr<redhand::Actor> obj) -> int virtual
add an actor to the world just by using +=
auto removeShader(std::string name) -> int virtual
This function removes a shader from its world and delete the shader.
auto removeTexture(std::string name) -> int virtual
This function removes a texture from its world and delete the texture.
auto removeObject(std::string name) -> int virtual
This function removes an object from its world and delete the object.
auto getShaderByName(std::string name) -> std::shared_ptr<redhand::shader> virtual
This function returns a pointer to the first shader with the given name.
auto getTextureByName(std::string name) -> std::shared_ptr<texture2D> virtual
This function returns a pointer to the first texture with the given name.
auto getObjectByName(std::string name) -> std::shared_ptr<game_object> virtual
This function returns a pointer to the first object with the given name.
auto get(std::string name) -> std::shared_ptr<Actor> virtual
This function returns a pointer to the first Actor with the given name.
void tick(redhand::game_loop_event evt) virtual
This function executes a world tick and is called for each frame.
void setCamera(float pos_x, float pos_y) virtual
This function is used to set the position of the camera.
void moveCamera(float delta_pos_x, float delta_pos_y) virtual
This function is used to set the position of the camera.
void zoomCamera(float delta_zoom) virtual
This factor will be multiplied with the current zoom factor so the value will be made positive.
void setWindowSize(int width, int height) virtual
This functions sets the window size to construct the projection matrix.
void draw() virtual
draw all the objects in this world
auto onCreate(redhand::event<redhand::engine> evt) -> int virtual
This function gets called when the world is created by the engine and should fill the world with its contents.
auto onSwitch(redhand::world_switching_event evt, bool isNextWorld) -> int virtual
This function gets called when the wolrd is switched by the engine and allows moving needed resources form one world to another.

Function documentation

int redhand::complex_world::addShader(std::unique_ptr<redhand::shader>) virtual

The addShader function will add a shader to the world.

Please add all shader you use for your objects to the world the objects resides in. Not doing this may easily cause NULL Pointer exceptions and Segmentation faults.

int redhand::complex_world::addTexture(std::unique_ptr<redhand::texture2D>) virtual

The addTexture function will add a texture to the world.

Please add all testures you use for your objects to the world the objects resides in. Not doing this may easily cause NULL Pointer exceptions and Segmentation faults.

int redhand::complex_world::addObject(std::unique_ptr<redhand::game_object>) virtual

The addObject function will add an object to the world.

All added objects will be drawn on each world tick.

int redhand::complex_world::add(std::shared_ptr<redhand::Actor> obj) virtual

add an actor to the world just by using +=

Returns int < 0 is something went wrong

int redhand::complex_world::removeShader(std::string name) virtual

This function removes a shader from its world and delete the shader.

Returns 0 if everything worked, 1 if no object was found, negative if something bad happened

int redhand::complex_world::removeTexture(std::string name) virtual

This function removes a texture from its world and delete the texture.

Returns 0 if everything worked, 1 if no object was found, negative if something bad happened

int redhand::complex_world::removeObject(std::string name) virtual

This function removes an object from its world and delete the object.

Returns 0 if everything worked, 1 if no object was found, negative if something bad happened

std::shared_ptr<redhand::shader> redhand::complex_world::getShaderByName(std::string name) virtual

This function returns a pointer to the first shader with the given name.

Parameters
name the name of the wanted shader
Returns pointer to the shader if everything worked, nullptr if no shader was found or something went wrong

std::shared_ptr<texture2D> redhand::complex_world::getTextureByName(std::string name) virtual

This function returns a pointer to the first texture with the given name.

Parameters
name the name of the wanted texture
Returns pointer to the texture if everything worked, nullptr if no shader was found or something went wrong

std::shared_ptr<game_object> redhand::complex_world::getObjectByName(std::string name) virtual

This function returns a pointer to the first object with the given name.

Parameters
name the name of the wanted object
Returns pointer to the object if everything worked, nullptr if no shader was found or something went wrong

std::shared_ptr<Actor> redhand::complex_world::get(std::string name) virtual

This function returns a pointer to the first Actor with the given name.

Parameters
name the name of the wanted Actor
Returns pointer to the Actor if everything worked, nullptr if no shader was found or something went wrong

void redhand::complex_world::tick(redhand::game_loop_event evt) virtual

This function executes a world tick and is called for each frame.

Parameters
evt the game tick event

All inputs are processed, the physics is calculated and all objects are rendered.

void redhand::complex_world::setCamera(float pos_x, float pos_y) virtual

This function is used to set the position of the camera.

Parameters
pos_x The x coordinate of the camera
pos_y The y coordinate of the camera

All units are in world space cooridinates. The camera postition will be applied to all shaders inside of this world

void redhand::complex_world::moveCamera(float delta_pos_x, float delta_pos_y) virtual

This function is used to set the position of the camera.

Parameters
delta_pos_x The amount the camera should move along the x-Axis
delta_pos_y The amount the camera should move along the y-Axis

All units are in world space cooridinates The camera postition will be applied to all shaders inside of this world

void redhand::complex_world::setWindowSize(int width, int height) virtual

This functions sets the window size to construct the projection matrix.

Parameters
width The width of the currently active window
height The height of the currently active window

Every time the window size changess this function should be called in order to prevent unwanted stretching of all the objects.

int redhand::complex_world::onCreate(redhand::event<redhand::engine> evt) virtual

This function gets called when the world is created by the engine and should fill the world with its contents.

Parameters
evt The simple event holding a pointer to the engine
Returns int negative if an error happened

int redhand::complex_world::onSwitch(redhand::world_switching_event evt, bool isNextWorld) virtual

This function gets called when the wolrd is switched by the engine and allows moving needed resources form one world to another.

Parameters
evt The world_switching event containing a pointer to the previous and next world
isNextWorld this is true is this function is resposible for the world that will be activated next
Returns int negative if an error happened