Make a Scene

gdt::scene

template <typename CONTEXT>
class gdt::scene

Scenes are how you divide your game into logical and memory managable parts. You will usually subclass this template through your specified application type:

using my_game = gdt::application<...>;

class my_scene : public my_game::scene {
    ...
};

Template Parameters
  • CONTEXT: the user-specified context type to use.

Subclassed by gdt::empty_scene< CONTEXT >

Public Functions

virtual void update(const CONTEXT &ctx) = 0

You must provide your own update implementation. Put all your per-frame scene update logic here and make sure you invoke a call to gdt::scene::render. Don’t directly draw stuff in this method.

class my_scene : public my_app::scene {
  public:
    ...
    void update(const my_app::context & ctx) override {
        // Update your objects
        ...

        // Once you're done, call render to do the actual drawing
        render(ctx);
    }
};

virtual void render(const CONTEXT &ctx) = 0

You must provide your own rendering implementation. Make sure you draw only in this method, as this method could also be called by the engine.

You will usually want to reuse your render pass setup in a separate renderer class, but you can also directly code everything in your render method implementation:

class my_scene : public my_app::scene {
  public:
    ...
    void render(const my_app::context & ctx) override {
        my_app::render_pass(ctx)
            .target(my_app::graphics::screen_buffer)
            .clear();
        my_app::forward_pipeline()
            .use(ctx)
                .set_material(_material)
                .set_pov(_camera)
                .draw(_zombie);
    }
};

virtual void imgui(const CONTEXT &ctx)

If you have custom imgui code, implement this method and place it here.

gdt::asset

template <typename ACTUAL>
class gdt::asset

Inherits from gdt::is_entity< ACTUAL >, gdt::is_drivable< ACTUAL >

gdt::instance

template <typename T, int C = 1>
class gdt::instances

gdt::instances is a special template container for gdt::is_entity types (such as gdt::asset and gdt::camera). By default, gdt::is_entity types doesn’t have any 3D world transformation data. gdt::instances augment entities with 3D transformation and can also support graphical instancing of entities during rendering.

An instances object will manage a set of 3D transformations (gdt::math::mat4 instances) and a single contained object of your entity type.

You will almost always have to use gdt::instances or gdt::instance (and their related siblings, gdt::references and gdt::reference) to store your asset type:

gdt::instances<zombie, 1000> _my_army_of_zombies;
gdt::instance<hero> _my_single_hero;

When constructing an instances object, you will also get the opportunity to construct your entity object by passing its constructor paramters from the third argument onwards. See gdt::instances::instances for an example.

Template Parameters
  • T: your entity type
  • C: number of instances to own and manage transformations for.

Inherits from gdt::transforms< C >, gdt::container< T >, gdt::may_have_drawable< T, instances< T, C > >, gdt::may_have_drivable< T, instances< T, C > >, gdt::may_have_animatable< T, instances< T, C > >, gdt::may_have_collidable< T, instances< T, C > >

Public Functions

template <typename CONTEXT, typename... ARG>
instances(const CONTEXT &ctx, std::function<math::mat4(int)> pos_callback = [](int j) { UNUSED(j);return math::mat4 ().transpose();}, const ARG&... a, )

Constructing an instances object involves setting the instances preliminary transformation and then constructing the contained entity object:

class my_scene : public my_game::scene {
  private:
    gdt::instance<hero> _my_hero;

  public:
    my_scene(...) : _my_hero(ctx, gdt::pos::origin, "my hero name")
    {
    }
};