gamnit: split use of App::on_create between create_gamnit and create_scene
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 26 Sep 2017 19:27:46 +0000 (15:27 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Tue, 21 Nov 2017 19:02:54 +0000 (14:02 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

16 files changed:
contrib/asteronits/src/asteronits.nit
contrib/asteronits/src/touch_ui.nit
lib/gamnit/bmfont.nit
lib/gamnit/depth/cardboard.nit
lib/gamnit/depth/depth.nit
lib/gamnit/depth/depth_core.nit
lib/gamnit/depth/shadow.nit
lib/gamnit/dynamic_resolution.nit
lib/gamnit/examples/fonts_showcase/src/fonts_showcase.nit
lib/gamnit/examples/template/src/template.nit
lib/gamnit/examples/triangle/src/portable_triangle.nit
lib/gamnit/flat/flat_core.nit
lib/gamnit/gamnit.nit
lib/gamnit/gamnit_linux.nit
lib/gamnit/textures.nit
lib/gamnit/virtual_gamepad/virtual_gamepad.nit

index d7621de..cc9f6a8 100644 (file)
@@ -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
 
index 5cae0d4..2264f28 100644 (file)
@@ -20,7 +20,7 @@ import gamnit::virtual_gamepad
 import asteronits
 
 redef class App
-       redef fun on_create
+       redef fun create_scene
        do
                super
 
index cdeef2d..d052922 100644 (file)
@@ -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
 #
index ccecf15..35c0f76 100644 (file)
@@ -80,7 +80,7 @@ redef class App
                end
        end
 
-       redef fun on_create
+       redef fun create_scene
        do
                super
                initialize_head_tracker
index 1230c4a..fccb689 100644 (file)
@@ -25,7 +25,7 @@ import shadow
 
 redef class App
 
-       redef fun on_create
+       redef fun create_gamnit
        do
                super
 
index 588b321..0e45e3d 100644 (file)
@@ -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`.
 #
 # ~~~
index 213b461..d65a3cb 100644 (file)
@@ -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
 
index fb78730..7399dd9 100644 (file)
@@ -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
 
index 33a342c..10ba0b4 100644 (file)
@@ -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
 
index a0f37a0..2311d0a 100644 (file)
@@ -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
 
index 9dfa49c..21492ad 100644 (file)
@@ -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
 
index 55da8e7..7572271 100644 (file)
@@ -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
 
index bd26cbd..3051553 100644 (file)
@@ -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.
index b86f8e5..3818878 100644 (file)
@@ -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
index 2aa405d..60cec5a 100644 (file)
@@ -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")
index f5b6bec..fb1920d 100644 (file)
@@ -25,7 +25,7 @@
 #
 # ~~~
 # redef class App
-#     redef fun on_create
+#     redef fun create_scene
 #     do
 #         super
 #