gamnit: fix nitunit
[nit.git] / lib / gamnit / flat.nit
index 6eb8fab..3073035 100644 (file)
@@ -29,7 +29,8 @@
 #   and the like. It can be used to standardize the size of the UI across
 #   devices. It is used to position the sprites in `App::ui_sprites`.
 #
-# See the sample game at `contrib/asteronits/`.
+# See the sample game at `contrib/asteronits/` and the basic project template
+# at `lib/gamnit/examples/template_flat/`.
 module flat
 
 import glesv2
@@ -40,9 +41,9 @@ import performance_analysis
 
 import gamnit
 import gamnit::cameras
+import gamnit::dynamic_resolution
 import gamnit::limit_fps
-
-import android_two_fingers_motion is conditional(android)
+import gamnit::camera_control
 
 # Draw a `texture` at `center`
 #
@@ -216,20 +217,20 @@ redef class App
 
        # Camera for world `sprites` and `depth::actors` with perspective
        #
-       # By default, the camera is configured to respect the resolution
-       # of the screen in world coordinates at `z == 0.0`.
+       # By default, the camera is configured to a height of 1080 units
+       # of world coordinates at `z == 0.0`.
        var world_camera: EulerCamera is lazy do
                var camera = new EulerCamera(app.display.as(not null))
 
-               # Aim for pixel resolution at level 0
-               camera.reset_height
-               camera.near = 100.0
+               # Aim for full HD pixel resolution at level 0
+               camera.reset_height 1080.0
+               camera.near = 10.0
 
                return camera
        end
 
        # Camera for `ui_sprites` using an orthogonal view
-       var ui_camera: UICamera = new UICamera(app.display.as(not null)) is lazy
+       var ui_camera = new UICamera(app.display.as(not null)) is lazy
 
        # World sprites to draw as seen by `world_camera`
        var sprites: Set[Sprite] = new SpriteSet
@@ -354,13 +355,16 @@ redef class App
        # Draw the whole screen, all `glDraw...` calls should be executed here
        protected fun frame_core_draw(display: GamnitDisplay)
        do
-               perf_clock_main.lapse
+               frame_core_dynamic_resolution_before display
 
+               perf_clock_main.lapse
                frame_core_world_sprites display
                perfs["gamnit flat world_sprites"].add perf_clock_main.lapse
 
                frame_core_ui_sprites display
                perfs["gamnit flat ui_sprites"].add perf_clock_main.lapse
+
+               frame_core_dynamic_resolution_after display
        end
 
        private fun frame_core_sprites(display: GamnitDisplay, sprite_set: SpriteSet, camera: Camera)
@@ -491,7 +495,7 @@ private class Simple2dProgram
                {
                        if(use_texture) {
                                gl_FragColor = v_color * texture2D(texture0, v_coord);
-                               if (gl_FragColor.a <= 0.1) discard;
+                               if (gl_FragColor.a <= 0.01) discard;
                        } else {
                                gl_FragColor = v_color;
                        }
@@ -653,6 +657,7 @@ private class SpriteSet
 
        redef fun add(e)
        do
+               if contexts_items.has(e.context) then return
                map_sprite e
                super
        end
@@ -663,8 +668,18 @@ private class SpriteSet
                if e isa Sprite then unmap_sprite e
        end
 
+       redef fun remove_all(e)
+       do
+               if not has(e) then return
+               remove e
+       end
+
        redef fun clear
        do
+               for sprite in self do
+                       sprite.context = null
+                       sprite.sprite_set = null
+               end
                super
                for c in contexts_items do c.destroy
                contexts_map.clear
@@ -1062,7 +1077,7 @@ end
 #
 # array.add "E"
 # assert array.to_s == "[A,B,c,D,E]"
-# assert array.capacity == 5
+# assert array.capacity == 6
 # assert array.length == 5
 #
 # array.remove "A"