From: Alexis Laferrière Date: Tue, 26 Sep 2017 19:27:46 +0000 (-0400) Subject: gamnit: split use of App::on_create between create_gamnit and create_scene X-Git-Url: http://nitlanguage.org gamnit: split use of App::on_create between create_gamnit and create_scene Signed-off-by: Alexis Laferrière --- diff --git a/contrib/asteronits/src/asteronits.nit b/contrib/asteronits/src/asteronits.nit index d7621de..cc9f6a8 100644 --- a/contrib/asteronits/src/asteronits.nit +++ b/contrib/asteronits/src/asteronits.nit @@ -64,7 +64,7 @@ redef class App private var fx_explosion_ship = new Sound("sounds/explosion_ship.wav") private var fx_explosion_asteroids = new Sound("sounds/explosion_asteroids.wav") - redef fun on_create + redef fun create_scene do super diff --git a/contrib/asteronits/src/touch_ui.nit b/contrib/asteronits/src/touch_ui.nit index 5cae0d4..2264f28 100644 --- a/contrib/asteronits/src/touch_ui.nit +++ b/contrib/asteronits/src/touch_ui.nit @@ -20,7 +20,7 @@ import gamnit::virtual_gamepad import asteronits redef class App - redef fun on_create + redef fun create_scene do super diff --git a/lib/gamnit/bmfont.nit b/lib/gamnit/bmfont.nit index cdeef2d..d052922 100644 --- a/lib/gamnit/bmfont.nit +++ b/lib/gamnit/bmfont.nit @@ -283,7 +283,7 @@ end # var pos: Point3d[Float] = ui_camera.top_left.offset(128.0, -128.0, 0.0) # var ui_text = new TextSprites(font, pos) # -# redef fun on_create +# redef fun create_scene # do # super # diff --git a/lib/gamnit/depth/cardboard.nit b/lib/gamnit/depth/cardboard.nit index ccecf15..35c0f76 100644 --- a/lib/gamnit/depth/cardboard.nit +++ b/lib/gamnit/depth/cardboard.nit @@ -80,7 +80,7 @@ redef class App end end - redef fun on_create + redef fun create_scene do super initialize_head_tracker diff --git a/lib/gamnit/depth/depth.nit b/lib/gamnit/depth/depth.nit index 1230c4a..fccb689 100644 --- a/lib/gamnit/depth/depth.nit +++ b/lib/gamnit/depth/depth.nit @@ -25,7 +25,7 @@ import shadow redef class App - redef fun on_create + redef fun create_gamnit do super diff --git a/lib/gamnit/depth/depth_core.nit b/lib/gamnit/depth/depth_core.nit index 588b321..0e45e3d 100644 --- a/lib/gamnit/depth/depth_core.nit +++ b/lib/gamnit/depth/depth_core.nit @@ -84,7 +84,7 @@ end # 3D model composed of `Mesh` and `Material`, loaded from the assets folder by default # -# Instances can be created at any time and must be loaded after or at the end of `on_create`. +# Instances can be created at any time and must be loaded after or at the end of `create_scene`. # If loading fails, the model is replaced by `placeholder_model`. # # ~~~ diff --git a/lib/gamnit/depth/shadow.nit b/lib/gamnit/depth/shadow.nit index 213b461..d65a3cb 100644 --- a/lib/gamnit/depth/shadow.nit +++ b/lib/gamnit/depth/shadow.nit @@ -52,7 +52,7 @@ redef class App private var perf_clock_shadow = new Clock is lazy - redef fun on_create + redef fun create_gamnit do super diff --git a/lib/gamnit/dynamic_resolution.nit b/lib/gamnit/dynamic_resolution.nit index fb78730..7399dd9 100644 --- a/lib/gamnit/dynamic_resolution.nit +++ b/lib/gamnit/dynamic_resolution.nit @@ -54,7 +54,7 @@ redef class App private var perf_clock_dynamic_resolution = new Clock is lazy - redef fun on_create + redef fun create_scene do super diff --git a/lib/gamnit/examples/fonts_showcase/src/fonts_showcase.nit b/lib/gamnit/examples/fonts_showcase/src/fonts_showcase.nit index 33a342c..10ba0b4 100644 --- a/lib/gamnit/examples/fonts_showcase/src/fonts_showcase.nit +++ b/lib/gamnit/examples/fonts_showcase/src/fonts_showcase.nit @@ -28,7 +28,7 @@ redef class App # Bottom right corner var corner = new Texture("corner.png") - redef fun on_create + redef fun create_scene do super diff --git a/lib/gamnit/examples/template/src/template.nit b/lib/gamnit/examples/template/src/template.nit index a0f37a0..2311d0a 100644 --- a/lib/gamnit/examples/template/src/template.nit +++ b/lib/gamnit/examples/template/src/template.nit @@ -17,7 +17,7 @@ import gamnit::flat # The 2D API, use `gamnit::depth` for 3D redef class App - # Texture, loaded automatically at `on_create` + # Texture, loaded in `create_scene` var texture = new Texture("fighter.png") # Sound effect, lazy loaded at first use @@ -26,7 +26,7 @@ redef class App # Sprite, must be loaded in or after `on_create` var sprite = new Sprite(texture, new Point3d[Float](0.0, 0.0, 0.0)) is lazy - redef fun on_create + redef fun create_scene do super diff --git a/lib/gamnit/examples/triangle/src/portable_triangle.nit b/lib/gamnit/examples/triangle/src/portable_triangle.nit index 9dfa49c..21492ad 100644 --- a/lib/gamnit/examples/triangle/src/portable_triangle.nit +++ b/lib/gamnit/examples/triangle/src/portable_triangle.nit @@ -39,7 +39,7 @@ redef class App # Vertex data for the triangle var vertex_array: VertexArray is noautoinit - redef fun on_create + redef fun create_scene do super diff --git a/lib/gamnit/flat/flat_core.nit b/lib/gamnit/flat/flat_core.nit index 55da8e7..7572271 100644 --- a/lib/gamnit/flat/flat_core.nit +++ b/lib/gamnit/flat/flat_core.nit @@ -417,10 +417,15 @@ redef class App # Second performance clock for smaller operations private var perf_clock_sprites = new Clock is lazy - redef fun on_create + redef fun create_gamnit do super + create_flat + end + # Prepare the flat framework services + fun create_flat + do var display = display assert display != null diff --git a/lib/gamnit/gamnit.nit b/lib/gamnit/gamnit.nit index bd26cbd..3051553 100644 --- a/lib/gamnit/gamnit.nit +++ b/lib/gamnit/gamnit.nit @@ -26,13 +26,15 @@ import gamnit_linux is conditional(linux) redef class App - # Main `GamnitDisplay` initialized by `on_create` + # Main `GamnitDisplay` initialized by `create_gamnit` var display: nullable GamnitDisplay = null - redef fun on_create + # Hook to setup the OpenGL context: compiling shaders, creating VBO, reloading textures, etc. + # + # The gamnit services redefine this method to prepare optimizations and more. + # Clients may also refine this method to prepare custom OpenGL resources. + fun create_gamnit do - super - var display = new GamnitDisplay display.setup self.display = display @@ -45,6 +47,15 @@ redef class App print "GL extensions: {glGetString(gl_EXTENSIONS)}" end + # Hook for client programs to setup the scene + # + # Refine this method to build the game world or the main menu, + # creating instances of `Sprite` and `Actor` as needed. + # + # This method is called only once per execution of the program and it should + # be considered as the entry point of most game logic. + fun create_scene do end + # Core of the frame logic, executed only when the display is visible # # This method should be redefined by user modules to customize the behavior of the game. diff --git a/lib/gamnit/gamnit_linux.nit b/lib/gamnit/gamnit_linux.nit index b86f8e5..3818878 100644 --- a/lib/gamnit/gamnit_linux.nit +++ b/lib/gamnit/gamnit_linux.nit @@ -46,6 +46,13 @@ redef class App accept_event gamnit_event end end + + redef fun on_create + do + super + create_gamnit + create_scene + end end redef class GamnitDisplay diff --git a/lib/gamnit/textures.nit b/lib/gamnit/textures.nit index 2aa405d..60cec5a 100644 --- a/lib/gamnit/textures.nit +++ b/lib/gamnit/textures.nit @@ -20,7 +20,7 @@ import display # Texture composed of pixels, loaded from the assets folder by default # # Most textures should be created with `App` (as attributes) -# for the method `on_create` to load them. +# for the method `create_scene` to load them. # # ~~~ # import gamnit::flat @@ -29,9 +29,9 @@ import display # # Create the texture object, it will be loaded automatically # var texture = new Texture("path/in/assets.png") # -# redef fun on_create() +# redef fun create_scene() # do -# # Let `on_create` load the texture +# # Let `create_scene` load the texture # super # # # Use the texture @@ -41,7 +41,7 @@ import display # end # ~~~ # -# Otherwise, they can be loaded and error checked explicitly after `on_create`. +# Otherwise, they can be loaded and error checked explicitly after `create_scene`. # # ~~~nitish # var texture = new Texture("path/in/assets.png") diff --git a/lib/gamnit/virtual_gamepad/virtual_gamepad.nit b/lib/gamnit/virtual_gamepad/virtual_gamepad.nit index f5b6bec..fb1920d 100644 --- a/lib/gamnit/virtual_gamepad/virtual_gamepad.nit +++ b/lib/gamnit/virtual_gamepad/virtual_gamepad.nit @@ -25,7 +25,7 @@ # # ~~~ # redef class App -# redef fun on_create +# redef fun create_scene # do # super #