1// This file is generated by WOWCube SDK project wizard
2//
3// Application UUID: UIvZXEq-Hw
4//
5
6use wowcube_sdk::application::{
7 AppErr, Application, ApplicationContext, Mappable, TimerController,
8};
9
10use wowcube_sdk::cubios;
11use wowcube_sdk::cubios::{comm, gfx, topology};
12
13const TEXT_SIZE: u32 = 10;
14const TIMER_ID_ONE: u8 = 1;
15
16#[derive(Default)]
17pub struct WorkingWIthEmulator {
18 initialized: bool,
19 app_context: ApplicationContext,
20 fps: f32,
21 seconds: u32,
22}
23
24impl WorkingWIthEmulator {
25 pub fn new() -> Self {
26 WorkingWIthEmulator::default()
27 }
28
29 pub fn initialize_resources(&mut self) {
30 comm::log_i("\n");
31 comm::log_i("*** WOWCube SDK Example \"Working with Emulator\" ***\n");
32 comm::log_i("Cubeapp is initializing...");
33 comm::log_i("Cubeapp is started");
34
35 self.set_timer(TIMER_ID_ONE, 1000, false);
36 }
37}
38
39impl Mappable for WorkingWIthEmulator {}
40
41impl Application for WorkingWIthEmulator {
42 fn app_context_mut(&mut self) -> &mut ApplicationContext {
43 &mut self.app_context
44 }
45
46 fn on_render(&self) -> Result<(), AppErr> {
47 if !self.initialized {
48 return Ok(());
49 }
50
51 for screen in 0..3 {
52 gfx::set_render_target(screen as u8);
53
54 gfx::clear(0xff000000);
55
56 gfx::draw_text(
57 120,
58 80,
59 TEXT_SIZE,
60 0,
61 cubios::TextAlign::Center,
62 0xffffffff as u32,
63 "CHECK",
64 );
65 gfx::draw_text(
66 120,
67 120,
68 TEXT_SIZE,
69 0,
70 cubios::TextAlign::Center,
71 0xffffffff as u32,
72 "THE",
73 );
74 gfx::draw_text(
75 120,
76 160,
77 TEXT_SIZE,
78 0,
79 cubios::TextAlign::Center,
80 0xffffffff as u32,
81 "CONSOLE",
82 );
83
84 gfx::render();
85 }
86
87 Ok(())
88 }
89
90 fn on_init(&mut self) -> Result<(), AppErr> {
91 self.initialized = true;
92
93 Ok(())
94 }
95
96 fn on_tick(&mut self) -> Result<(), AppErr> {
97 if !self.initialized {
98 self.on_init()?;
99 }
100
101 let delta_time = self.app_context.timer_controller.delta_time();
102 if delta_time > 0 {
103 self.fps = 1000.0 / delta_time as f32;
104 } else {
105 self.fps = 0.0;
106 }
107
108 comm::log_i(&format!(" Seconds passed: {:} s", self.seconds));
109 comm::log_i(&format!(" Current fps: {:.2}", self.fps));
110 comm::log_i(&format!(
111 " Delta time: {:} ms",
112 self.app_context.timer_controller.delta_time()
113 ));
114
115 Ok(())
116 }
117
118 fn on_timer(&mut self, timer_id: u8) -> Result<(), AppErr> {
119 match timer_id {
120 TIMER_ID_ONE => {
121 self.seconds += 1;
122 if self.seconds > 99 {
123 self.seconds = 0;
124 }
125 }
126 _ => {
127 println!("Unknown timer ID!");
128 }
129 }
130 Ok(())
131 }
132}
133