43ec95c2a7763fbcae70308c05affdc531037d49
[nit.git] / lib / gamnit / gamnit.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Game and multimedia framework for Nit
16 module gamnit
17
18 import app
19
20 import display
21
22 import gamnit_android is conditional(android)
23
24 redef class App
25
26 # Main `GamnitDisplay` initialized by `on_create`
27 var display: nullable GamnitDisplay = null
28
29 redef fun on_create
30 do
31 super
32
33 var display = new GamnitDisplay
34 display.setup
35 self.display = display
36 end
37
38 # Core of the frame logic, executed only when the display is visible
39 #
40 # This method should be redefined by user modules to customize the behavior of the game.
41 protected fun frame_core do end
42
43 # Full frame logic, executed even if the display is not visible
44 #
45 # This method wraps `frame_core` and other services to be executed in the main app loop.
46 #
47 # To customize the behavior on each turn, it is preferable to redefined `frame_core`.
48 # Still, `frame_full` can be redefined with care for more control.
49 protected fun frame_full
50 do
51 var display = display
52 if display != null then frame_core
53
54 feed_events
55 end
56
57 redef fun run
58 do
59 # TODO manage exit condition
60 loop frame_full
61 end
62
63 # Loop on available events and feed them back to the app
64 #
65 # The implementation varies per platform.
66 private fun feed_events do end
67 end