This repository has been archived by the owner on Nov 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.monkey
115 lines (92 loc) · 2.38 KB
/
app.monkey
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
Strict
Private
Import bono
Import brl.asyncevent
Import mojo.app
Import mojo.graphics
Public
Class App Extends app.App Abstract
Private
Field timer:DeltaTimer
Field contentScaler:ContentScaler
Public
Const DEFAULT_FPS:Int = 60
Field renderable:Renderable
Field suspendable:Suspendable
Field updateable:Updateable
Method Run:Void() Abstract
Method TranslateSpace:Vector2D(vec:Vector2D)
If Not contentScaler Then Return vec.Copy()
Return contentScaler.TranslateSpace(Self, vec.Copy())
End
Method GetDirector:Director()
Return Director.Shared()
End
Method SetHandler:Void(obj:Object)
renderable = Renderable(obj)
suspendable = Suspendable(obj)
updateable = Updateable(obj)
End
' --- CONFIG
Method GetTargetFps:Int()
Return DEFAULT_FPS
End
Method GetContentScaler:ContentScaler()
Return Null
End
Method GetVirtualSize:Vector2D()
Return Device.GetSize()
End
' --- MONKEY APP
Method OnCreate:Int()
Try
SetUpdateRate(GetTargetFps())
contentScaler = GetContentScaler()
Director.Shared().SetApp(Self)
Run()
Catch ex:Exception
Error ex
End
Return 0
End
Method OnRender:Int()
Try
Cls(0, 0, 0)
UpdateAsyncEvents()
If contentScaler Then contentScaler.OnRenderPre(Self)
If renderable Then renderable.OnRender()
If contentScaler Then contentScaler.OnRenderPost(Self)
Catch ex:Exception
Error ex
End
Return 0
End
Method OnUpdate:Int()
If Not timer Then timer = New DeltaTimer(GetTargetFps())
Try
timer.OnUpdate()
If timer.delta <> 0 And updateable Then updateable.OnUpdate(timer)
Catch ex:Exception
Error ex
End
Return 0
End
Method OnResume:Int()
Try
If timer Then timer.Play()
If suspendable Then suspendable.OnResume()
Catch ex:Exception
Error ex
End
Return 0
End
Method OnSuspend:Int()
Try
If timer Then timer.Pause()
If suspendable Then suspendable.OnSuspend()
Catch ex:Exception
Error ex
End
Return 0
End
End