1 # This file is part of NIT ( http://www.nitlanguage.org ).
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 # Game and multimedia framework for Nit
24 import gamnit_android
is conditional
(android
)
25 import gamnit_linux
is conditional
(linux
)
26 import gamnit_ios
is conditional
(ios
)
27 import input_ios
is conditional
(ios
)
31 # Main `GamnitDisplay` initialized by `create_gamnit`
32 var display
: nullable GamnitDisplay = null
34 # Hook to setup the OpenGL context: compiling shaders, creating VBO, reloading textures, etc.
36 # The gamnit services redefine this method to prepare optimizations and more.
37 # Clients may also refine this method to prepare custom OpenGL resources.
38 fun create_gamnit
do end
40 # Hook to prepare for recreating the OpenGL context
42 # Some gamnit services refine this method to reset caches before the
43 # next call to `create_gamnit`.
44 fun recreate_gamnit
do end
46 # Create and set `self.display`
49 var display
= new GamnitDisplay
51 self.display
= display
53 # Print the current GL configuration, for debugging
54 print
"GL vendor: {glGetString(gl_VENDOR)}"
55 print
"GL renderer: {glGetString(gl_RENDERER)}"
56 print
"GL version: {glGetString(gl_VERSION)}"
57 print
"GLSL version: {glGetString(gl_SHADING_LANGUAGE_VERSION)}"
58 print
"GL extensions: {glGetString(gl_EXTENSIONS)}"
59 print
"GL max texture size: {glGetIntegerv(gl_MAX_TEXTURE_SIZE, 0)}"
62 # Hook for client programs to setup the scene
64 # Refine this method to build the game world or the main menu,
65 # creating instances of `Sprite` and `Actor` as needed.
67 # This method is called only once per execution of the program and it should
68 # be considered as the entry point of most game logic.
69 fun create_scene
do end
71 # Core of the frame logic, executed only when the display is visible
73 # This method should be redefined by user modules to customize the behavior of the game.
74 protected fun frame_core
(display
: GamnitDisplay) do end
76 # Full frame logic, executed even if the display is not visible
78 # This method wraps `frame_core` and other services to be executed in the main app loop.
80 # To customize the behavior on each turn, it is preferable to redefined `frame_core`.
81 # Still, `frame_full` can be redefined with care for more control.
82 protected fun frame_full
85 if display
!= null then frame_core
(display
)
92 # TODO manage exit condition
96 # Loop on available events and feed them back to the app
98 # The implementation varies per platform.
99 private fun feed_events
do end
101 # Hook to receive and respond to `event` triggered by the user or system
103 # Returns whether or not the event is used or intercepted.
104 # If `true`, the event will not be processed further by the system.
105 # Returns `false` to intercepts events like the back key on mobile devices.
107 # The instances passed as `event` may be freed (or overwritten),
108 # right after this method returns. They should not be preserved.
109 fun accept_event
(event
: InputEvent): Bool do return false
111 # The window has been resized by the user or system
113 # The framework handles resizing the viewport automatically.
114 fun on_resize
(display
: GamnitDisplay) do end
117 # Portable indirection to `glBindFramebuffer(gl_FRAMEBUFFER, fbo)`
119 # This is implemented differently on iOS.
120 fun bind_screen_framebuffer
(fbo
: Int) do glBindFramebuffer
(gl_FRAMEBUFFER
, fbo
)