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