Difference between revisions of "SDK 6.3/C++/GFX Engine"
(GFX Engine: detailed per-method reference + usage patterns from official samples (WowBot)) |
(Fix ROBODoc typo parsing (LB_getInfo/LB_getScore restored), detailed Scramble+Splashscreen (WowBot)) |
||
| Line 1: | Line 1: | ||
| − | {{notice|'''Official WOWCube SDK documentation.''' SDK 6.3, C++ (WebAssembly) API. Signatures are extracted from the canonical SDK headers | + | {{notice|'''Official WOWCube SDK documentation.''' SDK 6.3, C++ (WebAssembly) API. Signatures are extracted from the canonical SDK headers shipped with the WOWCube Development Kit; the headers remain authoritative.}} |
{{SDK 6.3 nav}} | {{SDK 6.3 nav}} | ||
| + | |||
''← [[SDK 6.3]] · C++ / GFX Engine'' | ''← [[SDK 6.3]] · C++ / GFX Engine'' | ||
| − | The object-oriented retained layer of the C++ SDK (namespace <code>Cubios</code>): a scene graph with sprites, text, backgrounds, sounds and math primitives. It sits on top of the [[SDK 6.3/C++/Native API|native ABI]] and is driven by the [[SDK 6.3/C++/Application|Application framework]]. | + | The object-oriented retained layer of the C++ SDK (namespace <code>Cubios</code>): a scene graph with sprites, text, backgrounds, sounds and math primitives. It sits on top of the [[SDK 6.3/C++/Native API|native ABI]] and is driven by the [[SDK 6.3/C++/Application|Application framework]]. Public signatures below are extracted from the SDK 6.3 headers. |
| + | |||
| + | === Scene === | ||
| + | |||
| + | The retained scene graph owned by every <code>Application</code> (field <code>app.Scene</code>). Holds scene objects and renders them per screen. | ||
| + | |||
| + | Public interface (<code>Scene.h</code>): | ||
| − | + | Scene(); | |
| + | virtual ~Scene(); | ||
| + | uint32_t CreateObject(SceneObject* obj); | ||
| + | bool CreateObjectWithID(uint32_t id, SceneObject* obj); | ||
| + | uint32_t CreateSound(Sound* obj); | ||
| + | bool CreateSoundWithID(uint32_t id, Sound* obj); | ||
| + | bool DisposeObjectWithID(uint32_t id); | ||
| + | bool DisposeSoundWithID(uint32_t id); | ||
| + | void DisposeAllObjects(); | ||
| + | void Play(uint32_t id, uint8_t volume); | ||
| − | + | === SceneObject === | |
| − | + | Base class of every visual object in the scene graph. Provides position, rotation, scale, opacity, z-order, per-screen placement and lifecycle. | |
| − | |||
| − | + | Public interface (<code>SceneObject.h</code>): | |
| − | void | + | SceneObject():Parent(nullptr),ScreenAngle(0),Visible(true),InBegin(false); |
| − | + | virtual ~SceneObject(); | |
| − | + | virtual void Render() = 0; | |
| − | + | SceneObject* SetColor(uint32_t v); | |
| − | + | SceneObject* SetA(uint8_t a); | |
| − | + | SceneObject* SetAf(float a); | |
| − | + | SceneObject* SetAfSafe(float a); | |
| + | SceneObject* SetR(uint8_t r); | ||
| + | SceneObject* SetG(uint8_t g); | ||
| + | SceneObject* SetB(uint8_t b); | ||
| + | SceneObject* SetVisible(bool v); | ||
| + | SceneObject* SetTransform(const Math::Transform& t); | ||
| + | SceneObject* SetPosition(const Math::Vec2& p); | ||
| + | SceneObject* SetPosition(float x, float y); | ||
| + | SceneObject* SetRotation(int r); | ||
| + | SceneObject* SetMirroring(unsigned int m); | ||
| + | SceneObject* SetScale(unsigned int s); | ||
| + | SceneObject* SetScale(unsigned int sx, unsigned int sy); | ||
| + | SceneObject* SetXScale(unsigned int s); | ||
| + | SceneObject* SetYScale(unsigned int s); | ||
| + | const Math::Vec2 ScreenPosition(); | ||
| + | if(this->Parent==nullptr) return pos; | ||
| + | switch(ScreenAngle); | ||
| + | pos.Set(this->Transform.Position.X,this->Transform.Position.Y); | ||
| + | pos.Set(240-this->Transform.Position.Y,this->Transform.Position.X); | ||
| + | pos.Set(240-this->Transform.Position.X,240-this->Transform.Position.Y); | ||
| + | pos.Set(this->Transform.Position.Y,240-this->Transform.Position.X); | ||
| + | SceneObject* Move(const Math::Vec2& v); | ||
| + | SceneObject* Move(float dx, float dy); | ||
| + | if(this->Parent==nullptr) return this; | ||
| + | if(!this->InBegin); | ||
| + | LOG_w("SceneObject: Move() can only be called within Begin/End block!\n"); | ||
| − | + | === Screen === | |
| − | + | One of the three displays of the current module; passed to <code>on_Render()</code> / <code>on_PhysicsTick()</code>. Render target selector. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Public interface (<code>Screen.h</code>): | |
| − | == | + | Screen(uint8_t id); |
| + | void SetOrientation(TOPOLOGY_orientation_mode_t mode); | ||
| + | uint8_t Position() const; | ||
| + | TOPOLOGY_orientation_t Direction() const; | ||
| + | uint8_t OppositeFace() const; | ||
| + | uint8_t Face() const; | ||
| + | inline uint8_t ID() const; | ||
| + | inline uint32_t Angle() const; | ||
| + | SceneObject* Add(SceneObject* obj); | ||
| + | SceneObject* AddCopy(SceneObject* obj); | ||
| + | void Begin(TOPOLOGY_orientation_mode_t mode = Cubios::ORIENTATION_MODE_MENU,bool autorotation = false); | ||
| + | void End(); | ||
| + | inline bool IsAutorotation(); | ||
| − | + | === Object === | |
| − | + | Minimal reference-counted base class for engine resources. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Public interface (<code>Object.h</code>): | |
| − | + | Object(); | |
| + | virtual ~Object(); | ||
| + | inline void SetId(int16_t id); | ||
| − | + | === Gfx::Background === | |
| − | : | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Full-screen background image object. | |
| − | + | Public interface (<code>Gfx/Background.h</code>): | |
| − | + | Background(uint32_t color); | |
| + | Background(uint8_t R, uint8_t G, uint8_t B); | ||
| + | Background(uint8_t R, uint8_t G, uint8_t B, uint8_t A); | ||
| + | virtual ~Background(); | ||
| + | void Render() override; | ||
| + | Cubios::SceneObject* SetColor(uint32_t color); | ||
| + | Cubios::SceneObject* SetColor(uint8_t R, uint8_t G, uint8_t B); | ||
| + | Cubios::SceneObject* SetColor(uint8_t R, uint8_t G, uint8_t B, uint8_t A); | ||
| − | + | === Gfx::Sprite === | |
| − | |||
| − | |||
| − | : | ||
| − | |||
| − | : | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Static image sprite bound to an image asset by name. | |
| − | + | Public interface (<code>Gfx/Sprite.h</code>): | |
| + | Sprite(std::string name, const Cubios::Math::Transform& t); | ||
| + | Sprite(std::string name, float x, float y); | ||
Sprite(std::string name); | Sprite(std::string name); | ||
| − | |||
| − | |||
Sprite(const Sprite& sprite); | Sprite(const Sprite& sprite); | ||
| + | virtual ~Sprite(); | ||
| + | void Render() override; | ||
| + | |||
| + | === Gfx::AnimatedSprite === | ||
| + | |||
| + | Frame-animated sprite. | ||
| + | |||
| + | Public interface (<code>Gfx/AnimatedSprite.h</code>): | ||
| + | |||
| + | AnimatedSprite(std::vector<std::string>& names, const Cubios::Math::Transform& t); | ||
| + | AnimatedSprite(std::vector<std::string>& names, float x, float y); | ||
| + | AnimatedSprite(std::vector<std::string>& names); | ||
| + | AnimatedSprite(std::string name,std::string extension, int16_t firstFrame, int16_t lastFrame, const Cubios::Math::Transform& t); | ||
| + | AnimatedSprite(std::string name,std::string extension, int16_t firstFrame, int16_t lastFrame, float x, float y); | ||
| + | AnimatedSprite(std::string name,std::string extension, int16_t firstFrame, int16_t lastFrame); | ||
| + | AnimatedSprite(const AnimatedSprite& sprite); | ||
| + | AnimatedSprite(Cubios::Gfx::SpriteAtlas<Cubios::Gfx::SpriteAtlasElement>* atlas, const Cubios::Math::Transform& t); | ||
| + | AnimatedSprite(Cubios::Gfx::SpriteAtlas<Cubios::Gfx::SpriteAtlasElement>* atlas, float x, float y); | ||
| + | AnimatedSprite(Cubios::Gfx::SpriteAtlas<Cubios::Gfx::SpriteAtlasElement>* atlas); | ||
| + | virtual ~AnimatedSprite(); | ||
void Render() override; | void Render() override; | ||
| + | int16_t Tick(uint32_t dt); | ||
| + | Cubios::SceneObject* SetFrame(int16_t frameNumber); | ||
| + | Cubios::SceneObject* SetPlaybackSpeed(int16_t speed); | ||
| + | Cubios::SceneObject* SetPlaybackMode(playbackMode_t mode); | ||
| + | int16_t PrevFrame(); | ||
| + | int16_t NextFrame(); | ||
| + | |||
| + | === Gfx::SpriteAtlas === | ||
| + | |||
| + | Sprite atlas: a sheet of sub-images rendered via <code>SpriteAtlasElement</code>. Added in SDK 6.2. | ||
| + | |||
| + | Public interface (<code>Gfx/SpriteAtlas.h</code>): | ||
| + | |||
| + | SpriteAtlas(std::string name, Cubios::Scene* scene); | ||
| + | virtual ~SpriteAtlas(); | ||
| + | bool AddSprite(uint32_t id, const Cubios::Math::Rect2& rc); | ||
| + | bool RemoveSprite(uint32_t id); | ||
| + | T* Get(uint32_t ind); | ||
| + | inline size_t Count(); | ||
| + | inline std::vector<uint32_t>* ElementsInsertionOrder(); | ||
| + | |||
| + | === Gfx::SpriteAtlasElement === | ||
| − | + | One element (sub-rectangle) of a <code>SpriteAtlas</code>. | |
| − | + | Public interface (<code>Gfx/SpriteAtlas.h</code>): | |
| + | |||
| + | SpriteAtlasElement(SpriteAtlasBase* host, const Cubios::Math::Rect2& rc); | ||
| + | virtual ~SpriteAtlasElement(); | ||
| + | void Render() override; | ||
| + | virtual SpriteAtlasElement* Copy(); | ||
| + | inline Cubios::Math::Rect2* Rect(); | ||
| − | + | === Gfx::Text === | |
| − | + | Text object with scale, alignment and color. | |
| − | Text | + | Public interface (<code>Gfx/Text.h</code>): |
| + | Text(std::string text, const Cubios::Math::Transform& t, uint32_t fontSize, const Cubios::Math::Color& color, Cubios::text_align_t al = Cubios::text_align_t::TEXT_ALIGN_CENTER); | ||
| + | Text(std::string text, const Cubios::Math::Transform& t, uint32_t fontSize = 10, Cubios::text_align_t al = Cubios::text_align_t::TEXT_ALIGN_CENTER); | ||
Text(std::string text, float x, float y, uint32_t fontSize = 10); | Text(std::string text, float x, float y, uint32_t fontSize = 10); | ||
| − | Text(std::string text, float x, float y, uint32_t fontSize, const Math::Color& color); | + | Text(std::string text, float x, float y, uint32_t fontSize, const Cubios::Math::Color& color); |
| − | Text(std::string text, const Math::Transform& t, | + | virtual ~Text(); |
| − | + | void Render() override; | |
| + | Cubios::SceneObject* SetContent(std::string text); | ||
| + | Cubios::SceneObject* FormatContent(char const* format,...); | ||
| + | Cubios::SceneObject* SetFontSize(uint32_t fontSize); | ||
| + | |||
| + | === Gfx::QRCode === | ||
| + | |||
| + | QR-code object rendered on screen. Added in SDK 6.0. | ||
| + | |||
| + | Public interface (<code>Gfx/QRCode.h</code>): | ||
| + | |||
| + | QRCode(std::string data, const Cubios::Math::Transform& t); | ||
| + | QRCode(std::string data, float x, float y); | ||
| + | QRCode(std::string data, const Cubios::Math::Transform& t, u32_t size); | ||
| + | QRCode(std::string data, float x, float y, u32_t size); | ||
| + | QRCode(const QRCode& qr); | ||
| + | virtual ~QRCode(); | ||
| + | Cubios::SceneObject* SetSize(u32_t size); | ||
| + | Cubios::SceneObject* SetColor(const Math::Color& color); | ||
| + | Cubios::SceneObject* SetBackgroundColor(const Math::Color& color); | ||
| + | Cubios::SceneObject* SetData(std::string data); | ||
| + | void Render() override; | ||
| + | |||
| + | === Gfx::OffscreenRenderTarget === | ||
| + | |||
| + | Offscreen render target (baked image) usable as a scene object. | ||
| + | |||
| + | Public interface (<code>Gfx/OffscreenRenderTarget.h</code>): | ||
| + | |||
| + | OffscreenRenderTarget(u32_t width, u32_t height, Cubios::GFX_PixelFormat_t format); | ||
| + | virtual ~OffscreenRenderTarget(); | ||
| + | Cubios::SceneObject* Add(Cubios::SceneObject* obj); | ||
| + | Cubios::SceneObject* AddCopy(Cubios::SceneObject* obj); | ||
| + | void Begin(bool overwrite=false); | ||
| + | void End(); | ||
| + | void Render() override; | ||
| + | virtual void RenderLayer(renderLayerOrder_t order); | ||
| + | |||
| + | === Sound === | ||
| + | |||
| + | A sound asset; play, stop and query state. | ||
| + | |||
| + | Public interface (<code>Sound.h</code>): | ||
| + | |||
| + | explicit Sound(const std::string& name); | ||
| + | ~Sound(); | ||
| + | void Play(uint8_t volume = 100); | ||
| + | static void Stop(); | ||
| + | static bool IsPlaying(); | ||
| + | |||
| + | === SoundCollection === | ||
| + | |||
| + | A set of sounds with random playback helpers. Added in SDK 6.2. | ||
| + | |||
| + | Public interface (<code>Sound.h</code>): | ||
| + | |||
| + | SoundCollection(std::vector<std::string>& names); | ||
| + | SoundCollection(std::vector<Cubios::Sound*>& sounds); | ||
| + | virtual ~SoundCollection(); | ||
| + | bool PlayRandomSound(uint8_t volume = 100, bool stopCurrent = true); | ||
| + | bool RepeatRandomSounds(uint8_t volume, int delayMin, int delayMax, int deltaTime); | ||
| + | void Stop(); | ||
| + | bool IsPlaying(); | ||
| + | |||
| + | === NetworkMessage === | ||
| + | |||
| + | Bit-packed serializer for inter-module messages (write/read ints, signed ints, floats). | ||
| + | |||
| + | Public interface (<code>NetworkMessage.h</code>): | ||
| + | |||
| + | NetworkMessage(uint8_t* data=NULL,int length=MESSAGE_SIZE_MAX); | ||
| + | virtual ~NetworkMessage(); | ||
| + | void Print(); | ||
| + | void WriteInt(int value, int bits); | ||
| + | void WriteByte(uint8_t value); | ||
| + | void WriteSignedInt(int value, int bits); | ||
| + | void WriteBool(bool value); | ||
| + | void WriteFloat(float value); | ||
| + | int ReadInt(int bits); | ||
| + | int ReadSignedInt(int bits); | ||
| + | uint8_t ReadByte(); | ||
| + | bool ReadBool(); | ||
| + | float ReadFloat(); | ||
| + | uint8_t* GetData(int& length); | ||
| + | void SetData(uint8_t* data, int length); | ||
| + | inline void Reset(bool zero=false); | ||
| + | |||
| + | === SaveMessage === | ||
| + | |||
| + | Serializer for persistent state (used with <code>SaveState()</code> / <code>LoadState()</code>). Added in SDK 6.0. | ||
| + | |||
| + | Public interface (<code>SaveMessage.h</code>): | ||
| + | |||
| + | SaveMessage(uint8_t* data=NULL,int length=GAME_SAVE_SIZE); | ||
| + | virtual ~SaveMessage(); | ||
| + | void Print(); | ||
| + | void WriteInt(int value, int bits); | ||
| + | void WriteByte(uint8_t value); | ||
| + | void WriteSignedInt(int value, int bits); | ||
| + | void WriteBool(bool value); | ||
| + | void WriteFloat(float value); | ||
| + | int ReadInt(int bits); | ||
| + | int ReadSignedInt(int bits); | ||
| + | uint8_t ReadByte(); | ||
| + | bool ReadBool(); | ||
| + | float ReadFloat(); | ||
| + | uint8_t* GetData(int& length); | ||
| + | void SetData(uint8_t* data, int length); | ||
| + | inline void Reset(bool zero=false); | ||
| − | + | === Scramble === | |
| − | |||
| − | |||
| − | |||
| − | + | Cube-scramble helper. Added in SDK 6.0. | |
| − | + | Public interface (<code>Scramble.h</code>): | |
| − | ; | + | Scramble(); |
| − | + | ~Scramble(); | |
| − | + | void StartScramble(uint8_t twistsCount); | |
| − | + | void VirtualTwist(uint8_t screen, uint8_t direction); | |
| − | + | virtual void on_BeforeTwist() = 0; | |
| − | + | virtual void on_MappingChanged(uint8_t moduleTo, uint8_t screenTo, uint8_t moduleFrom, uint8_t screenFrom) = 0; | |
| + | virtual void on_Twist(const Cubios::TOPOLOGY_twistInfo_t twist) = 0; | ||
| − | == | + | === Splashscreen === |
| − | + | Standard splash screen with leaderboard support (reworked in SDK 6.2). | |
| − | + | Public interface (<code>Splashscreen.h</code>): | |
| − | |||
| − | |||
| − | ; | + | Splashscreen(Cubios::Application *app, SplsParms::e_LeadersDataType dataType); |
| − | : | + | ~Splashscreen(); |
| − | ; | + | virtual void Render(Cubios::Screen* screen); |
| − | : | + | virtual void Tick(uint32_t currentTime, uint32_t deltaTime); |
| + | uint32_t GetPersonalBest(); | ||
| + | void SetRecord(uint32_t value); | ||
| + | void SetNamedValue(uint8_t idx, std::string name, uint32_t value, SplsParms::e_LeadersDataType type = SplsParms::e_LeadersDataType::typeNumber); | ||
| + | void SetSeparator(std::string s); | ||
| + | void SetLabel(SplsParms::e_LabelTypes idx, std::string text); | ||
| + | void SetApplicationName(std::string name); | ||
| + | void SetLeaderBoardTable(SplsParms::e_LeaderBoardType type); | ||
| + | void SetLeaderBoardTable(uint32_t (&lbTable)[TOPOLOGY_FACES_MAX][TOPOLOGY_POSITIONS_MAX]); | ||
| + | void SetPlaybackSpeed(SplsParms::e_LabelTypes idx, uint32_t speed); | ||
| + | void SetQRCodeLink(std::string link); | ||
| + | void SetColors(Cubios::Math::Color key, Cubios::Math::Color base); | ||
| + | void SetTopology(uint8_t screen, Cubios::TOPOLOGY_place_t p); | ||
| + | void GetTopology(TOPOLOGY_orientation_mode_t mode, bool replaceFaceToOrientation); | ||
| + | virtual void RenderUserDefinedScreen(uint8_t type); | ||
| − | == | + | === Math::Vec2 === |
| − | + | 2D float vector. | |
| − | + | Public interface (<code>Math/Vec2.h</code>): | |
| − | ; | + | Vec2(); |
| − | + | Vec2(const float _x, const float _y); | |
| − | + | Vec2(const Vec2& vec); | |
| − | + | Vec2(const float* p); | |
| + | void Set(const float _x, const float _y); | ||
| + | void Set(const Vec2& vec); | ||
| + | void Set(const float* p); | ||
| + | float Len() const; | ||
| + | void Norm(); | ||
| + | bool IsEqual(const Vec2& v, const float tol) const; | ||
| + | int Compare(const Vec2& v, float tol) const; | ||
| − | == | + | === Math::Vec2i === |
| − | + | 2D integer vector. | |
| − | + | Public interface (<code>Math/Vec2.h</code>): | |
| − | ; | + | Vec2i(); |
| − | + | Vec2i(const int16_t _x, const int16_t _y); | |
| − | + | Vec2i(const Vec2i& vec); | |
| − | + | Vec2i(const int16_t* p); | |
| − | + | void Set(const int16_t _x, const int16_t _y); | |
| − | + | void Set(const Vec2i& vec); | |
| − | + | void Set(const int16_t* p); | |
| − | + | float Len() const; | |
| − | + | void Norm(); | |
| + | bool IsEqual(const Vec2i& v, const float tol) const; | ||
| + | int Compare(const Vec2i& v, float tol) const; | ||
| − | == | + | === Math::Transform === |
| − | + | Position + rotation + mirroring transform of a scene object. | |
| − | + | Public interface (<code>Math/Transform.h</code>): | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | : | ||
| − | + | Transform():Position(0,0),Rotation(0),Mirroring(0),ScaleX(100),ScaleY(100); | |
| + | Transform(float x, float y): Position(x,y),Rotation(0),Mirroring(0),ScaleX(100),ScaleY(100); | ||
| + | Transform(float x, float y, unsigned int a): Position(x,y),Rotation(a),Mirroring(0),ScaleX(100),ScaleY(100); | ||
| + | Transform(float x, float y, unsigned int a, unsigned int sx, unsigned int sy ): Position(x,y),Rotation(a),Mirroring(0),ScaleX(sx),ScaleY(sy); | ||
| + | Transform(float x, float y, unsigned int a, unsigned int m): Position(x,y),Rotation(a),Mirroring(m),ScaleX(100),ScaleY(100); | ||
| + | Transform(float x, float y, unsigned int a, unsigned int sx, unsigned int sy, unsigned int m): Position(x,y),Rotation(a),Mirroring(m),ScaleX(sx),ScaleY(sy); | ||
| + | Transform(const Transform& t): Position(t.Position),Rotation(t.Rotation),Mirroring(t.Mirroring),ScaleX(t.ScaleX),ScaleY(t.ScaleY); | ||
| + | int SafeRotation(); | ||
| − | == | + | === Math::Color === |
| − | + | RGBA color with float/byte accessors (see also <code>Gfx/Colors.h</code> named constants). | |
| − | + | Public interface (<code>Math/Color.h</code>): | |
| − | + | Color():_R(255),_G(255),_B(255),_A(255),_Value(0xFFFFFFFF); | |
| + | Color(uint8_t r, uint8_t g, uint32_t b):_R(r),_G(g),_B(b),_A(255); | ||
| + | Color(uint8_t r, uint8_t g, uint32_t b, uint8_t a):_R(r),_G(g),_B(b),_A(a); | ||
| + | Color(uint32_t v):_Value(v); | ||
| + | this->_B = (v & 0x000000ff); | ||
| + | this->_G = (v & 0x0000ff00) >> 8; | ||
| + | this->_R = (v & 0x00ff0000) >> 16; | ||
| + | this->_A = (v & 0xff000000) >> 24; | ||
| + | void Set(uint8_t r, uint8_t g, uint32_t b, uint8_t a); | ||
| + | void Set(uint8_t r, uint8_t g, uint32_t b); | ||
| + | void Set(uint32_t v); | ||
| + | inline void SetA(uint8_t a); | ||
| + | inline void SetAf(float a); | ||
| + | inline void SetAfSafe(float a); | ||
| + | inline void SetR(uint8_t r); | ||
| + | inline void SetG(uint8_t g); | ||
| + | inline void SetB(uint8_t b); | ||
| + | inline uint8_t A(); | ||
| + | inline float Af(); | ||
| + | inline uint8_t R(); | ||
| + | inline uint8_t G(); | ||
| + | inline uint8_t B(); | ||
| + | inline uint32_t Value(); | ||
| − | == Math == | + | === Math::Rect2 === |
| − | + | 2D rectangle. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Public interface (<code>Math/Rect2.h</code>): | |
| − | + | Rect2(); | |
| + | Rect2(const Vec2i& topLeft, const Vec2i& bottomRight); | ||
| + | Rect2(int16_t x, int16_t y, int16_t width, int16_t height); | ||
| + | void Set(const Vec2i& topLeft, const Vec2i& bottomRight); | ||
| + | bool IsInside(const Vec2i& p) const; | ||
| + | Vec2i Midpoint() const; | ||
[[Category:SDK 6.3]] | [[Category:SDK 6.3]] | ||
[[Category:C++ API]] | [[Category:C++ API]] | ||
Revision as of 09:39, 26 July 2026
SDK 6.3 · PAWN API: Core ·
Graphics ·
Topology ·
Sound ·
Motion Sensor ·
Leaderboard ·
Splash Screen ·
Physics ·
Network ·
Save ·
Scramble ·
Logging
C++: Native API · Application · GFX Engine · Rust: Rust API (experimental) · Changelog
← SDK 6.3 · C++ / GFX Engine
The object-oriented retained layer of the C++ SDK (namespace Cubios): a scene graph with sprites, text, backgrounds, sounds and math primitives. It sits on top of the native ABI and is driven by the Application framework. Public signatures below are extracted from the SDK 6.3 headers.
Contents
- 1 Scene
- 2 SceneObject
- 3 Screen
- 4 Object
- 5 Gfx::Background
- 6 Gfx::Sprite
- 7 Gfx::AnimatedSprite
- 8 Gfx::SpriteAtlas
- 9 Gfx::SpriteAtlasElement
- 10 Gfx::Text
- 11 Gfx::QRCode
- 12 Gfx::OffscreenRenderTarget
- 13 Sound
- 14 SoundCollection
- 15 NetworkMessage
- 16 SaveMessage
- 17 Scramble
- 18 Splashscreen
- 19 Math::Vec2
- 20 Math::Vec2i
- 21 Math::Transform
- 22 Math::Color
- 23 Math::Rect2
Scene
The retained scene graph owned by every Application (field app.Scene). Holds scene objects and renders them per screen.
Public interface (Scene.h):
Scene(); virtual ~Scene(); uint32_t CreateObject(SceneObject* obj); bool CreateObjectWithID(uint32_t id, SceneObject* obj); uint32_t CreateSound(Sound* obj); bool CreateSoundWithID(uint32_t id, Sound* obj); bool DisposeObjectWithID(uint32_t id); bool DisposeSoundWithID(uint32_t id); void DisposeAllObjects(); void Play(uint32_t id, uint8_t volume);
SceneObject
Base class of every visual object in the scene graph. Provides position, rotation, scale, opacity, z-order, per-screen placement and lifecycle.
Public interface (SceneObject.h):
SceneObject():Parent(nullptr),ScreenAngle(0),Visible(true),InBegin(false);
virtual ~SceneObject();
virtual void Render() = 0;
SceneObject* SetColor(uint32_t v);
SceneObject* SetA(uint8_t a);
SceneObject* SetAf(float a);
SceneObject* SetAfSafe(float a);
SceneObject* SetR(uint8_t r);
SceneObject* SetG(uint8_t g);
SceneObject* SetB(uint8_t b);
SceneObject* SetVisible(bool v);
SceneObject* SetTransform(const Math::Transform& t);
SceneObject* SetPosition(const Math::Vec2& p);
SceneObject* SetPosition(float x, float y);
SceneObject* SetRotation(int r);
SceneObject* SetMirroring(unsigned int m);
SceneObject* SetScale(unsigned int s);
SceneObject* SetScale(unsigned int sx, unsigned int sy);
SceneObject* SetXScale(unsigned int s);
SceneObject* SetYScale(unsigned int s);
const Math::Vec2 ScreenPosition();
if(this->Parent==nullptr) return pos;
switch(ScreenAngle);
pos.Set(this->Transform.Position.X,this->Transform.Position.Y);
pos.Set(240-this->Transform.Position.Y,this->Transform.Position.X);
pos.Set(240-this->Transform.Position.X,240-this->Transform.Position.Y);
pos.Set(this->Transform.Position.Y,240-this->Transform.Position.X);
SceneObject* Move(const Math::Vec2& v);
SceneObject* Move(float dx, float dy);
if(this->Parent==nullptr) return this;
if(!this->InBegin);
LOG_w("SceneObject: Move() can only be called within Begin/End block!\n");
Screen
One of the three displays of the current module; passed to on_Render() / on_PhysicsTick(). Render target selector.
Public interface (Screen.h):
Screen(uint8_t id); void SetOrientation(TOPOLOGY_orientation_mode_t mode); uint8_t Position() const; TOPOLOGY_orientation_t Direction() const; uint8_t OppositeFace() const; uint8_t Face() const; inline uint8_t ID() const; inline uint32_t Angle() const; SceneObject* Add(SceneObject* obj); SceneObject* AddCopy(SceneObject* obj); void Begin(TOPOLOGY_orientation_mode_t mode = Cubios::ORIENTATION_MODE_MENU,bool autorotation = false); void End(); inline bool IsAutorotation();
Object
Minimal reference-counted base class for engine resources.
Public interface (Object.h):
Object(); virtual ~Object(); inline void SetId(int16_t id);
Gfx::Background
Full-screen background image object.
Public interface (Gfx/Background.h):
Background(uint32_t color); Background(uint8_t R, uint8_t G, uint8_t B); Background(uint8_t R, uint8_t G, uint8_t B, uint8_t A); virtual ~Background(); void Render() override; Cubios::SceneObject* SetColor(uint32_t color); Cubios::SceneObject* SetColor(uint8_t R, uint8_t G, uint8_t B); Cubios::SceneObject* SetColor(uint8_t R, uint8_t G, uint8_t B, uint8_t A);
Gfx::Sprite
Static image sprite bound to an image asset by name.
Public interface (Gfx/Sprite.h):
Sprite(std::string name, const Cubios::Math::Transform& t); Sprite(std::string name, float x, float y); Sprite(std::string name); Sprite(const Sprite& sprite); virtual ~Sprite(); void Render() override;
Gfx::AnimatedSprite
Frame-animated sprite.
Public interface (Gfx/AnimatedSprite.h):
AnimatedSprite(std::vector<std::string>& names, const Cubios::Math::Transform& t); AnimatedSprite(std::vector<std::string>& names, float x, float y); AnimatedSprite(std::vector<std::string>& names); AnimatedSprite(std::string name,std::string extension, int16_t firstFrame, int16_t lastFrame, const Cubios::Math::Transform& t); AnimatedSprite(std::string name,std::string extension, int16_t firstFrame, int16_t lastFrame, float x, float y); AnimatedSprite(std::string name,std::string extension, int16_t firstFrame, int16_t lastFrame); AnimatedSprite(const AnimatedSprite& sprite); AnimatedSprite(Cubios::Gfx::SpriteAtlas<Cubios::Gfx::SpriteAtlasElement>* atlas, const Cubios::Math::Transform& t); AnimatedSprite(Cubios::Gfx::SpriteAtlas<Cubios::Gfx::SpriteAtlasElement>* atlas, float x, float y); AnimatedSprite(Cubios::Gfx::SpriteAtlas<Cubios::Gfx::SpriteAtlasElement>* atlas); virtual ~AnimatedSprite(); void Render() override; int16_t Tick(uint32_t dt); Cubios::SceneObject* SetFrame(int16_t frameNumber); Cubios::SceneObject* SetPlaybackSpeed(int16_t speed); Cubios::SceneObject* SetPlaybackMode(playbackMode_t mode); int16_t PrevFrame(); int16_t NextFrame();
Gfx::SpriteAtlas
Sprite atlas: a sheet of sub-images rendered via SpriteAtlasElement. Added in SDK 6.2.
Public interface (Gfx/SpriteAtlas.h):
SpriteAtlas(std::string name, Cubios::Scene* scene); virtual ~SpriteAtlas(); bool AddSprite(uint32_t id, const Cubios::Math::Rect2& rc); bool RemoveSprite(uint32_t id); T* Get(uint32_t ind); inline size_t Count(); inline std::vector<uint32_t>* ElementsInsertionOrder();
Gfx::SpriteAtlasElement
One element (sub-rectangle) of a SpriteAtlas.
Public interface (Gfx/SpriteAtlas.h):
SpriteAtlasElement(SpriteAtlasBase* host, const Cubios::Math::Rect2& rc); virtual ~SpriteAtlasElement(); void Render() override; virtual SpriteAtlasElement* Copy(); inline Cubios::Math::Rect2* Rect();
Gfx::Text
Text object with scale, alignment and color.
Public interface (Gfx/Text.h):
Text(std::string text, const Cubios::Math::Transform& t, uint32_t fontSize, const Cubios::Math::Color& color, Cubios::text_align_t al = Cubios::text_align_t::TEXT_ALIGN_CENTER); Text(std::string text, const Cubios::Math::Transform& t, uint32_t fontSize = 10, Cubios::text_align_t al = Cubios::text_align_t::TEXT_ALIGN_CENTER); Text(std::string text, float x, float y, uint32_t fontSize = 10); Text(std::string text, float x, float y, uint32_t fontSize, const Cubios::Math::Color& color); virtual ~Text(); void Render() override; Cubios::SceneObject* SetContent(std::string text); Cubios::SceneObject* FormatContent(char const* format,...); Cubios::SceneObject* SetFontSize(uint32_t fontSize);
Gfx::QRCode
QR-code object rendered on screen. Added in SDK 6.0.
Public interface (Gfx/QRCode.h):
QRCode(std::string data, const Cubios::Math::Transform& t); QRCode(std::string data, float x, float y); QRCode(std::string data, const Cubios::Math::Transform& t, u32_t size); QRCode(std::string data, float x, float y, u32_t size); QRCode(const QRCode& qr); virtual ~QRCode(); Cubios::SceneObject* SetSize(u32_t size); Cubios::SceneObject* SetColor(const Math::Color& color); Cubios::SceneObject* SetBackgroundColor(const Math::Color& color); Cubios::SceneObject* SetData(std::string data); void Render() override;
Gfx::OffscreenRenderTarget
Offscreen render target (baked image) usable as a scene object.
Public interface (Gfx/OffscreenRenderTarget.h):
OffscreenRenderTarget(u32_t width, u32_t height, Cubios::GFX_PixelFormat_t format); virtual ~OffscreenRenderTarget(); Cubios::SceneObject* Add(Cubios::SceneObject* obj); Cubios::SceneObject* AddCopy(Cubios::SceneObject* obj); void Begin(bool overwrite=false); void End(); void Render() override; virtual void RenderLayer(renderLayerOrder_t order);
Sound
A sound asset; play, stop and query state.
Public interface (Sound.h):
explicit Sound(const std::string& name); ~Sound(); void Play(uint8_t volume = 100); static void Stop(); static bool IsPlaying();
SoundCollection
A set of sounds with random playback helpers. Added in SDK 6.2.
Public interface (Sound.h):
SoundCollection(std::vector<std::string>& names); SoundCollection(std::vector<Cubios::Sound*>& sounds); virtual ~SoundCollection(); bool PlayRandomSound(uint8_t volume = 100, bool stopCurrent = true); bool RepeatRandomSounds(uint8_t volume, int delayMin, int delayMax, int deltaTime); void Stop(); bool IsPlaying();
NetworkMessage
Bit-packed serializer for inter-module messages (write/read ints, signed ints, floats).
Public interface (NetworkMessage.h):
NetworkMessage(uint8_t* data=NULL,int length=MESSAGE_SIZE_MAX); virtual ~NetworkMessage(); void Print(); void WriteInt(int value, int bits); void WriteByte(uint8_t value); void WriteSignedInt(int value, int bits); void WriteBool(bool value); void WriteFloat(float value); int ReadInt(int bits); int ReadSignedInt(int bits); uint8_t ReadByte(); bool ReadBool(); float ReadFloat(); uint8_t* GetData(int& length); void SetData(uint8_t* data, int length); inline void Reset(bool zero=false);
SaveMessage
Serializer for persistent state (used with SaveState() / LoadState()). Added in SDK 6.0.
Public interface (SaveMessage.h):
SaveMessage(uint8_t* data=NULL,int length=GAME_SAVE_SIZE); virtual ~SaveMessage(); void Print(); void WriteInt(int value, int bits); void WriteByte(uint8_t value); void WriteSignedInt(int value, int bits); void WriteBool(bool value); void WriteFloat(float value); int ReadInt(int bits); int ReadSignedInt(int bits); uint8_t ReadByte(); bool ReadBool(); float ReadFloat(); uint8_t* GetData(int& length); void SetData(uint8_t* data, int length); inline void Reset(bool zero=false);
Scramble
Cube-scramble helper. Added in SDK 6.0.
Public interface (Scramble.h):
Scramble(); ~Scramble(); void StartScramble(uint8_t twistsCount); void VirtualTwist(uint8_t screen, uint8_t direction); virtual void on_BeforeTwist() = 0; virtual void on_MappingChanged(uint8_t moduleTo, uint8_t screenTo, uint8_t moduleFrom, uint8_t screenFrom) = 0; virtual void on_Twist(const Cubios::TOPOLOGY_twistInfo_t twist) = 0;
Splashscreen
Standard splash screen with leaderboard support (reworked in SDK 6.2).
Public interface (Splashscreen.h):
Splashscreen(Cubios::Application *app, SplsParms::e_LeadersDataType dataType); ~Splashscreen(); virtual void Render(Cubios::Screen* screen); virtual void Tick(uint32_t currentTime, uint32_t deltaTime); uint32_t GetPersonalBest(); void SetRecord(uint32_t value); void SetNamedValue(uint8_t idx, std::string name, uint32_t value, SplsParms::e_LeadersDataType type = SplsParms::e_LeadersDataType::typeNumber); void SetSeparator(std::string s); void SetLabel(SplsParms::e_LabelTypes idx, std::string text); void SetApplicationName(std::string name); void SetLeaderBoardTable(SplsParms::e_LeaderBoardType type); void SetLeaderBoardTable(uint32_t (&lbTable)[TOPOLOGY_FACES_MAX][TOPOLOGY_POSITIONS_MAX]); void SetPlaybackSpeed(SplsParms::e_LabelTypes idx, uint32_t speed); void SetQRCodeLink(std::string link); void SetColors(Cubios::Math::Color key, Cubios::Math::Color base); void SetTopology(uint8_t screen, Cubios::TOPOLOGY_place_t p); void GetTopology(TOPOLOGY_orientation_mode_t mode, bool replaceFaceToOrientation); virtual void RenderUserDefinedScreen(uint8_t type);
Math::Vec2
2D float vector.
Public interface (Math/Vec2.h):
Vec2(); Vec2(const float _x, const float _y); Vec2(const Vec2& vec); Vec2(const float* p); void Set(const float _x, const float _y); void Set(const Vec2& vec); void Set(const float* p); float Len() const; void Norm(); bool IsEqual(const Vec2& v, const float tol) const; int Compare(const Vec2& v, float tol) const;
Math::Vec2i
2D integer vector.
Public interface (Math/Vec2.h):
Vec2i(); Vec2i(const int16_t _x, const int16_t _y); Vec2i(const Vec2i& vec); Vec2i(const int16_t* p); void Set(const int16_t _x, const int16_t _y); void Set(const Vec2i& vec); void Set(const int16_t* p); float Len() const; void Norm(); bool IsEqual(const Vec2i& v, const float tol) const; int Compare(const Vec2i& v, float tol) const;
Math::Transform
Position + rotation + mirroring transform of a scene object.
Public interface (Math/Transform.h):
Transform():Position(0,0),Rotation(0),Mirroring(0),ScaleX(100),ScaleY(100); Transform(float x, float y): Position(x,y),Rotation(0),Mirroring(0),ScaleX(100),ScaleY(100); Transform(float x, float y, unsigned int a): Position(x,y),Rotation(a),Mirroring(0),ScaleX(100),ScaleY(100); Transform(float x, float y, unsigned int a, unsigned int sx, unsigned int sy ): Position(x,y),Rotation(a),Mirroring(0),ScaleX(sx),ScaleY(sy); Transform(float x, float y, unsigned int a, unsigned int m): Position(x,y),Rotation(a),Mirroring(m),ScaleX(100),ScaleY(100); Transform(float x, float y, unsigned int a, unsigned int sx, unsigned int sy, unsigned int m): Position(x,y),Rotation(a),Mirroring(m),ScaleX(sx),ScaleY(sy); Transform(const Transform& t): Position(t.Position),Rotation(t.Rotation),Mirroring(t.Mirroring),ScaleX(t.ScaleX),ScaleY(t.ScaleY); int SafeRotation();
Math::Color
RGBA color with float/byte accessors (see also Gfx/Colors.h named constants).
Public interface (Math/Color.h):
Color():_R(255),_G(255),_B(255),_A(255),_Value(0xFFFFFFFF); Color(uint8_t r, uint8_t g, uint32_t b):_R(r),_G(g),_B(b),_A(255); Color(uint8_t r, uint8_t g, uint32_t b, uint8_t a):_R(r),_G(g),_B(b),_A(a); Color(uint32_t v):_Value(v); this->_B = (v & 0x000000ff); this->_G = (v & 0x0000ff00) >> 8; this->_R = (v & 0x00ff0000) >> 16; this->_A = (v & 0xff000000) >> 24; void Set(uint8_t r, uint8_t g, uint32_t b, uint8_t a); void Set(uint8_t r, uint8_t g, uint32_t b); void Set(uint32_t v); inline void SetA(uint8_t a); inline void SetAf(float a); inline void SetAfSafe(float a); inline void SetR(uint8_t r); inline void SetG(uint8_t g); inline void SetB(uint8_t b); inline uint8_t A(); inline float Af(); inline uint8_t R(); inline uint8_t G(); inline uint8_t B(); inline uint32_t Value();
Math::Rect2
2D rectangle.
Public interface (Math/Rect2.h):
Rect2(); Rect2(const Vec2i& topLeft, const Vec2i& bottomRight); Rect2(int16_t x, int16_t y, int16_t width, int16_t height); void Set(const Vec2i& topLeft, const Vec2i& bottomRight); bool IsInside(const Vec2i& p) const; Vec2i Midpoint() const;