WOWCube Docs logo
WOWCube Docs
Mission Control
Section Shortcuts
APIExamplesSourceWOWConnectChangelog
Filters
SDK and language defaults persist in cookies.
SDK version
Navigation Tree
Collapsed by default, focused on the active path.
Made byMcKay Seamons
GitHub
  1. Home
  2. Docs
  3. Examples
  4. Jukebox.cpp
Mission NodeSDK 6.1C++GFX SamplesProject Included

Jukebox.cpp

Example: Jukebox.cpp

Examples / SDK 6.1 / C++ / GFX Samples / Jukebox / project / src
Jukebox.cpp
CPP
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 "Jukebox.h"
11
12
13using namespace Cubios;
14using namespace Cubios::Math;
15using namespace Cubios::Gfx;
16
17//Applicaton initialization callback. Called once when CUB application starts
18void OnInit(Cubios::AppManager& appMgr)
19{
20 Jukebox* theApp = new Jukebox();
21
22 appMgr.SetApplication(theApp,"AAbbCCddEE");
23
24 theApp->InitializeResources();
25}
26
27
28Jukebox::Jukebox()
29{
30 this->secondsCount = 5;
31 this->playing = false;
32 this->timer500Started = false;
33}
34
35Jukebox::~Jukebox()
36{
37 this->Scene.DisposeAllObjects();
38}
39
40void Jukebox::InitializeResources()
41{
42 this->Scene.CreateObjectWithID(GfxObjects::myBackground,new Background(0,0,0));
43
44 this->Scene.CreateObjectWithID(GfxObjects::myCountdown,new Countdown());
45 this->countdown = dynamic_cast<Countdown*>(this->Scene[GfxObjects::myCountdown]);
46
47 std::vector<std::string> anim;
48 anim.push_back("meter1.png");
49 anim.push_back("meter2.png");
50 anim.push_back("meter3.png");
51 anim.push_back("meter4.png");
52
53 this->Scene.CreateObjectWithID(GfxObjects::myMeter,new AnimatedSprite(anim,Transform(120,120,0)));
54 this->meter = dynamic_cast<AnimatedSprite*>(this->Scene[GfxObjects::myMeter]);
55 this->meter->Visible = false;
56 this->meter->SetPlaybackSpeed(107);
57
58 if(Cubios::cubeN==0)
59 {
60 this->Scene.CreateSoundWithID(0,new Sound("LastNinja_2.mp3"));
61 }
62
63 this->SetTimer(1,430);
64
65 this->ShowFPSCounter(true);
66}
67
68//This callback is called every "tick" of cubeapp application loop
69void Jukebox::on_Tick(uint32_t currentTime, uint32_t deltaTime)
70{
71 this->countdown->Tick(deltaTime);
72 this->meter->Tick(deltaTime);
73
74 if(Cubios::cubeN==0)
75 {
76 if(!this->timer500Started)
77 {
78 this->timerMessage.Reset(true);
79 this->timerMessage.WriteInt(currentTime,32);
80 this->receivedTime = currentTime;
81
82 this->SendNetworkMessage(0, &this->timerMessage);
83 }
84 }
85
86 if(currentTime>3000)
87 {
88 if(!this->countdown->Visible)
89 {
90 if(this->secondsCount>0)
91 {
92 this->countdown->SetContent(std::to_string(this->secondsCount));
93 this->secondsCount--;
94 }
95 else
96 {
97 this->countdown->Visible = false;
98 if(Cubios::cubeN==0)
99 {
100 if(!this->playing)
101 {
102 this->timerMessage.Reset(true);
103
104 //send empty message just to indicate the meter is visible now
105 this->SendNetworkMessage(1,&this->timerMessage);
106
107 this->Scene.Play(0,100);
108 this->playing = true;
109
110 if(!this->timer500Started)
111 {
112 this->StartTimer(1);
113 this->timer500Started = true;
114 this->meter->Visible = true;
115 }
116 }
117 }
118 }
119 }
120 }
121}
122
123//This callback is called every time device is about to render visuals. Use it for calling your rendering code.
124void Jukebox::on_Render(std::array<Cubios::Screen, 3>& screens)
125{
126 for(auto it = screens.begin(); it != screens.end(); ++it)
127 {
128 //Start adding objects to a screen
129 it->Begin(TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_GRAVITY,true);
130
131 //add background
132 it->Add(this->Scene[GfxObjects::myBackground]);
133
134 //add sprites
135 it->Add(this->countdown);
136 it->Add(this->meter);
137
138 //Finish adding objects
139 it->End();
140 }
141}
142
143//The "physics" callback. Gets called recurrently with at least 33ms resolution or less depending on the load.
144void Jukebox::on_PhysicsTick(const std::array<Cubios::Screen, 3>& screens)
145{
146}
147
148//This callback is called on programmable timer (if any)
149void Jukebox::on_Timer(uint8_t timerID)
150{
151 switch(timerID)
152 {
153 case 1:
154 this->receivedTime+=500;
155 this->meter->SetFrame(0);
156 break;
157 }
158}
159
160//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
161void Jukebox::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)
162{
163}
164
165//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
166void Jukebox::on_Message(uint32_t type, uint8_t* pkt, u32_t size)
167{
168 NetworkMessage nm(pkt,size);
169 if(Cubios::cubeN!=0)
170 {
171 switch(type)
172 {
173 case 0:
174 {
175 this->receivedTime = nm.ReadInt(32);
176 }
177 break;
178 case 1:
179 {
180 if(!this->timer500Started)
181 {
182 this->StartTimer(1);
183 this->timer500Started = true;
184 this->meter->Visible = true;
185 }
186 }
187 default:break;
188 }
189 }
190
191}
192
193//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source
194void Jukebox::on_ExternalMessage(uint8_t* pkt, u32_t size)
195{
196}
197
198//Screen tap callback
199void Jukebox::on_Tap(uint32_t count)
200{
201}
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Context Rail

Project files

Countdown.cpp
project/src/Countdown.cpp
Countdown.h
project/src/Countdown.h
Jukebox.cpp
project/src/Jukebox.cpp
Jukebox.h
project/src/Jukebox.h
wowcubeapp-build.json
project/wowcubeapp-build.json
Context Rail

Related nodes

Countdown.cpp
Examples / SDK 6.1 / C++ / GFX Samples / Jukebox / project / src
Countdown.h
Examples / SDK 6.1 / C++ / GFX Samples / Jukebox / project / src
Jukebox.h
Examples / SDK 6.1 / C++ / GFX Samples / Jukebox / project / src
Jukebox
Examples / SDK 6.1 / C++ / GFX Samples
Previous Node
Countdown.h
Examples / SDK 6.1 / C++ / GFX Samples / Jukebox / project / src
Next Node
Jukebox.h
Examples / SDK 6.1 / C++ / GFX Samples / Jukebox / project / src