1// This file is generated by WOWCube SDK project wizard
2
3#include <stdint.h>
4#include <string>
5#include <vector>
6#include <string>
7#include <memory>
8
9#include "AppManager.h"
10#include "GfxRenderTarget.h"
11
12using namespace Cubios;
13using namespace Cubios::Math;
14using namespace Cubios::Gfx;
15
16//Applicaton initialization callback. Called once when CUB application starts
17void OnInit(Cubios::AppManager& appMgr)
18{
19 RenderTarget* theApp = new RenderTarget();
20
21 appMgr.SetApplication(theApp,"AAbbCCddEE");
22
23 theApp->InitializeResources();
24}
25
26
27RenderTarget::RenderTarget()
28{
29}
30
31RenderTarget::~RenderTarget()
32{
33 this->Scene.DisposeAllObjects();
34}
35
36void RenderTarget::InitializeResources()
37{
38 //Create tile sprites
39 this->Scene.CreateObjectWithID(GfxObjects::terrain,new Sprite("terrain.png",Transform(120,120,0)));
40
41 this->Scene.CreateObjectWithID(GfxObjects::pit,new Sprite("pit.png",Transform(120,120,0)));
42 this->Scene.CreateObjectWithID(GfxObjects::plant,new Sprite("plant.png",Transform(120,120,0)));
43 this->Scene.CreateObjectWithID(GfxObjects::plant2,new Sprite("plant2.png",Transform(120,120,0)));
44 this->Scene.CreateObjectWithID(GfxObjects::plant3,new Sprite("plant3.png",Transform(120,120,0)));
45 this->Scene.CreateObjectWithID(GfxObjects::plant4,new Sprite("plant4.png",Transform(120,120,0)));
46
47 this->Scene.CreateObjectWithID(GfxObjects::rock,new Sprite("rock.png",Transform(120,120,0)));
48 this->Scene.CreateObjectWithID(GfxObjects::rock2,new Sprite("rock2.png",Transform(120,120,0)));
49 this->Scene.CreateObjectWithID(GfxObjects::rock3,new Sprite("rock3.png",Transform(120,120,0)));
50
51 this->Scene.CreateObjectWithID(GfxObjects::myBackground,new Background(Cubios::Gfx::Colors::black));
52
53 //Create offscreen render target
54 this->prepareOffscreenResource();
55
56 //Uncomment this line in order to see actuall FPSes
57 //this->ShowFPSCounter(true);
58}
59
60void RenderTarget::prepareOffscreenResource()
61{
62 OffscreenRenderTarget* rt = new OffscreenRenderTarget(240,240,Cubios::GFX_PixelFormat_t::FORMAT_RGB565);
63 rt->SetPosition(120,120);
64
65 Sprite* terrain = (Sprite*)this->Scene[GfxObjects::terrain];
66 Sprite* rock3 = (Sprite*)this->Scene[GfxObjects::rock3];
67 Sprite* plant3 = (Sprite*)this->Scene[GfxObjects::plant3];
68
69 rt->Begin(true);
70
71 rt->Add(this->Scene[GfxObjects::myBackground]);
72
73 rt->Add(terrain);
74 rt->AddCopy(new Sprite(*terrain))->SetPosition(120-79,120-47);
75 rt->AddCopy(new Sprite(*terrain))->SetPosition(120+79,120-47);
76 rt->AddCopy(new Sprite(*terrain))->SetPosition(120+79,120+47);
77 rt->AddCopy(new Sprite(*terrain))->SetPosition(120-79,120+47);
78
79 rt->AddCopy(new Sprite(*terrain))->SetPosition(120,120-47*2);
80 rt->AddCopy(new Sprite(*terrain))->SetPosition(120,120+47*2);
81
82 rt->AddCopy(new Sprite(*terrain))->SetPosition(120-79*2,120-47*2);
83 rt->AddCopy(new Sprite(*terrain))->SetPosition(120-79*2,120+47*2);
84
85 rt->AddCopy(new Sprite(*terrain))->SetPosition(120+79*2,120-47*2);
86 rt->AddCopy(new Sprite(*terrain))->SetPosition(120+79*2,120+47*2);
87
88 rt->AddCopy(new Sprite(*terrain))->SetPosition(120+79*2,120);
89 rt->AddCopy(new Sprite(*terrain))->SetPosition(120-79*2,120);
90
91 rt->Add(this->Scene[GfxObjects::pit]);
92
93 rt->Add(rock3)->SetPosition(120-79,120-47);
94 rt->Add(this->Scene[GfxObjects::rock])->SetPosition(120-79,120-47);
95 rt->Add(this->Scene[GfxObjects::rock2])->SetPosition(120,120-47*2);
96
97 rt->AddCopy(new Sprite(*rock3))->SetPosition(120+79,120-47);
98 rt->AddCopy(new Sprite(*plant3))->SetPosition(120+79,120-47);
99
100 rt->AddCopy(new Sprite(*rock3))->SetPosition(120-79,120+47);
101 rt->AddCopy(new Sprite(*rock3))->SetPosition(120,120+47*2);
102 rt->AddCopy(new Sprite(*plant3))->SetPosition(120,120+47*2);
103
104 rt->Add(this->Scene[GfxObjects::plant])->SetPosition(120+79,120+47);
105 rt->Add(this->Scene[GfxObjects::plant4])->SetPosition(120-79,120+77);
106
107 rt->Add(this->Scene[GfxObjects::plant2])->SetPosition(120-39,120+7);
108
109 rt->End();
110
111 this->Scene.CreateObjectWithID(GfxObjects::myRT,rt);
112}
113
114//This callback is called every "tick" of cubeapp application loop
115void RenderTarget::on_Tick(uint32_t currentTime, uint32_t deltaTime)
116{
117}
118
119//This callback is called every time device is about to render visuals. Use it for calling your rendering code.
120void RenderTarget::on_Render(std::array<Cubios::Screen, 3>& screens)
121{
122 for(auto it = screens.begin(); it != screens.end(); ++it)
123 {
124 //Start adding objects to a screen
125 it->Begin(TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_GRAVITY,true);
126
127 it->Add(this->Scene[GfxObjects::myRT]);
128
129 //Finish adding objects
130 it->End();
131 }
132}
133
134//The "physics" callback. Gets called recurrently with at least 33ms resolution or less depending on the load.
135void RenderTarget::on_PhysicsTick(const std::array<Cubios::Screen, 3>& screens)
136{
137}
138
139//This callback is called on programmable timer (if any)
140void RenderTarget::on_Timer(uint8_t timerID)
141{
142}
143
144//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
145void RenderTarget::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)
146{
147}
148
149//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
150void RenderTarget::on_Message(uint32_t type, uint8_t* pkt, u32_t size)
151{
152}
153
154//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source
155void RenderTarget::on_ExternalMessage(uint8_t* pkt, u32_t size)
156{
157}
158
159//Screen pat callback
160void RenderTarget::on_Pat(uint32_t count)
161{
162}