DSC Engine
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
DSC::Scene Class Reference

An active game execution part
More...

#include <scene.hpp>

Inheritance diagram for DSC::Scene:
DSC::GenericScene256 DSC::SceneTemplates::VisualNovelScene

Public Member Functions

 Scene ()=default
 Creates a new Scene instance
More...
 
SceneComclose ()
 Closes this scene and clears all its resources. More...
 
virtual void init ()
 Contains Scene initialization routines (setting variables, loading VRAM etc.) More...
 
virtual void frame ()
 The Scene main loop logic. This method is executed at VBlank. More...
 
 __attribute__ ((noinline)) virtual void run()
 

Public Attributes

Event key_down
 Key down event.
 
Event key_held
 Key held event.
 
Event key_up
 Key up event.
 

Detailed Description

An active game execution part

Constructor & Destructor Documentation

◆ Scene()

DSC::Scene::Scene ( )
default

Creates a new Scene instance

Warning
Do NOT use the constructor for anything but loading the constructor parameters! Use Scene::init() for the out-of-class initialization purposes.

Member Function Documentation

◆ close()

SceneCom * DSC::Scene::close ( )

Closes this scene and clears all its resources.

Returns
an internal inter-scene communication which can load the next scene
Warning
  • Due to the way close() is implemented, don't try to use statically declared Scenes. Only use pointer Scenes with their specialized api (dsc_launch(), SceneCom::next())
  • Don't access any of the Scene's properies after close()-ing it! close() literally deletes the object in order to make room for the next Scene to load. Don't do:
    class MyScene : public DSC::Scene
    {
    public:
    int my_property = 123;
    void next_scene()
    {
    this->close()->next(new MyOtherScene(my_property));
    // After close(), my_property is no longer available
    // Therefore, the line above leads to runtime error
    }
    };
    An active game execution part
    Definition: scene.hpp:17
    Do it this way:
    class MyScene : public DSC::Scene
    {
    public:
    int my_property = 123;
    void next_scene()
    {
    // save my_property to stack
    int my_backup = my_property;
    // Even though closing the Scene deletes its properties,
    // we can still retrieve our valuable variable from the
    // local scope
    this->close()->next(new MyOtherScene(my_backup));
    }
    };
  • Due to limited hardware resources, only one scene should exist at a time. Is is recommended not to create your next Scene before closing the previous one.
    // Potentially buggy:
    MyNewScene* new_scene = new MyNewScene();
    this->close()->next(new_scene); // "this" and "new_scene" exist at the same time
    // Safer approach:
    auto* scene_com = this->close(); // "this" is now gone
    MyNewScene* new_scene = new MyNewScene(); // it is the only active scene
    scene_com->next(new_scene); // Ok
    SceneCom * close()
    Closes this scene and clears all its resources.
    void next(Scene *new_scene)
    Loads the next scene.

◆ frame()

virtual void DSC::Scene::frame ( )
virtual

The Scene main loop logic. This method is executed at VBlank.

Reimplemented in DSC::GenericScene256, and DSC::SceneTemplates::VisualNovelScene.

◆ init()

virtual void DSC::Scene::init ( )
virtual

Contains Scene initialization routines (setting variables, loading VRAM etc.)

Reimplemented in DSC::GenericScene256, and DSC::SceneTemplates::VisualNovelScene.


The documentation for this class was generated from the following file: