f68e483ee6bc3a92bb14644606b843f81963f565
[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 import textures
22 import programs
23
24 import gamnit_android is conditional(android)
25
26 redef class App
27
28 # Main `GamnitDisplay` initialized by `on_create`
29 var display: nullable GamnitDisplay = null
30
31 redef fun on_create
32 do
33 super
34
35 var display = new GamnitDisplay
36 display.setup
37 self.display = display
38 end
39
40 # Core of the frame logic, executed only when the display is visible
41 #
42 # This method should be redefined by user modules to customize the behavior of the game.
43 protected fun frame_core(display: GamnitDisplay) do end
44
45 # Full frame logic, executed even if the display is not visible
46 #
47 # This method wraps `frame_core` and other services to be executed in the main app loop.
48 #
49 # To customize the behavior on each turn, it is preferable to redefined `frame_core`.
50 # Still, `frame_full` can be redefined with care for more control.
51 protected fun frame_full
52 do
53 var display = display
54 if display != null then frame_core(display)
55
56 feed_events
57 end
58
59 redef fun run
60 do
61 if "NIT_TESTING".environ == "true" then exit 0
62
63 # TODO manage exit condition
64 loop frame_full
65 end
66
67 # Loop on available events and feed them back to the app
68 #
69 # The implementation varies per platform.
70 private fun feed_events do end
71 end