From: Jean Privat Date: Tue, 28 Mar 2017 12:27:49 +0000 (-0400) Subject: Merge: intrepreter: Fix the documentation of `PrimitiveInstance` X-Git-Url: http://nitlanguage.org?hp=2c644de6100b81eeeb916a8fe9bb37aa570714e4 Merge: intrepreter: Fix the documentation of `PrimitiveInstance` Signed-off-by: Jean-Christophe Beaupré Pull-Request: #2400 --- diff --git a/contrib/action_nitro/src/action_nitro.nit b/contrib/action_nitro/src/action_nitro.nit index f6da14e..b780a5d 100644 --- a/contrib/action_nitro/src/action_nitro.nit +++ b/contrib/action_nitro/src/action_nitro.nit @@ -61,7 +61,7 @@ redef class App # --- # Background - private var city_texture = new Texture("textures/city_background_clean.png") + private var city_texture = new TextureAsset("textures/city_background_clean.png") private var stars_texture = new Texture("textures/stars.jpg") private var stars = new Sprite(stars_texture, new Point3d[Float](0.0, 1100.0, -600.0)) is lazy @@ -146,6 +146,7 @@ redef class App stars.scale = 2.1 # City background + city_texture.pixelated = true var city_sprite = new Sprite(city_texture, new Point3d[Float](0.0, 370.0, -600.0)) city_sprite.scale = 0.8 sprites.add city_sprite @@ -165,11 +166,12 @@ redef class App actors.add ground # Trees - for i in 1000.times do + for i in 2000.times do var s = 0.1 + 0.1.rand var h = tree_texture.height * s var sprite = new Sprite(tree_texture, new Point3d[Float](0.0 & 1500.0, h/2.0 - 10.0*s, 10.0 - 609.0.rand)) + sprite.static = true sprite.scale = s sprites.add sprite @@ -201,7 +203,7 @@ redef class App # Prepare for intro animation ui_sprites.add tutorial_goal - world_camera.far = 700.0 + world_camera.far = 1024.0 end redef fun update(dt) @@ -269,6 +271,7 @@ redef class App player.moving = 0.0 if pressed_keys.has("left") then player.moving -= 1.0 if pressed_keys.has("right") then player.moving += 1.0 + player.sprite.as(PlayerSprite).update end # Try to fire as long as a key is pressed @@ -350,9 +353,11 @@ redef class App var s = super if event isa QuitEvent then + print perfs exit 0 else if event isa KeyEvent then if event.name == "escape" and event.is_down then + print perfs exit 0 end @@ -631,16 +636,15 @@ class PlayerSprite # Stop the running animation fun stop_running do current_animation = null - redef fun texture + # Update `texture` from `current_animation` + fun update do var anim = current_animation if anim != null then var dt = app.world.t - anim_ot var i = (dt / time_per_frame).to_i+2 - return anim.modulo(i) + texture = anim.modulo(i) end - - return super end end diff --git a/contrib/action_nitro/src/game/core.nit b/contrib/action_nitro/src/game/core.nit index dc9a13b..9e437a1 100644 --- a/contrib/action_nitro/src/game/core.nit +++ b/contrib/action_nitro/src/game/core.nit @@ -227,17 +227,18 @@ abstract class Body if self.health <= 0.0 then die(world) end - # Die in the game logic, with graphical animations and scoring when applicable + # Die in the game logic, with graphical animations # # Calls `destroy` by default. fun die(world: World) do + if not is_alive then return is_alive = false destroy world end # Destroy this objects and most references to it - fun destroy(world: World) do end + protected fun destroy(world: World) do end # --- # Box services @@ -264,6 +265,7 @@ abstract class Platform redef fun die(world) do + if not is_alive then return super world.explode(center, width) world.score += 1 @@ -482,8 +484,9 @@ abstract class Human for plane in world.planes do # TODO optimize with quad tree if plane.left < right and plane.right > left then if old_y > plane.top and bottom <= plane.top then - if world.parachute != null then - world.parachute.destroy(world) + var parachute = world.parachute + if parachute != null then + parachute.die world world.parachute = null end parachute_deployed = false @@ -721,14 +724,14 @@ abstract class Bullet redef fun update(dt, world) do super - if world.t - creation_time >= weapon.bullet_lifespan then destroy world + if world.t - creation_time >= weapon.bullet_lifespan then die world end # Hit `body` fun hit_enemy(body: Body, world: World) do body.hit(self.weapon.damage, world) - destroy world + die world end end diff --git a/contrib/action_nitro/src/game/planegen.nit b/contrib/action_nitro/src/game/planegen.nit index 58c5410..94cb237 100644 --- a/contrib/action_nitro/src/game/planegen.nit +++ b/contrib/action_nitro/src/game/planegen.nit @@ -40,7 +40,7 @@ redef class World for i in planes.reverse_iterator do if i.out_of_screen(p, self) then #print "Despawning plane" - i.destroy(self) + i.die(self) end end @@ -118,14 +118,14 @@ redef class World if p == null then return if p.altitude >= boss_altitude then for e in enemies.reverse_iterator do if e isa JetpackEnemy then - e.destroy(self) + e.die(self) end return end for i in enemies.reverse_iterator do if i.out_of_screen(p, self) then #print "Despawning enemy" - i.destroy(self) + i.die(self) end end diff --git a/lib/c.nit b/lib/c.nit index 55a89a0..7db5945 100644 --- a/lib/c.nit +++ b/lib/c.nit @@ -30,7 +30,7 @@ abstract class CArray[E] # Pointer to the real C array var native_array: NATIVE is noinit - private init(length: Int) is old_style_init do self._length = length + init(length: Int) is old_style_init do self._length = length redef fun [](index) do diff --git a/lib/core/kernel.nit b/lib/core/kernel.nit index a821006..88dcc8a 100644 --- a/lib/core/kernel.nit +++ b/lib/core/kernel.nit @@ -1056,6 +1056,9 @@ end # Pointer classes are used to manipulate extern C structures. extern class Pointer + # C `NULL` pointer + new nul `{ return NULL; `} + # Is the address behind this Object at NULL? fun address_is_null: Bool `{ return self == NULL; `} diff --git a/lib/core/queue.nit b/lib/core/queue.nit index 5b4353e..f545504 100644 --- a/lib/core/queue.nit +++ b/lib/core/queue.nit @@ -238,6 +238,7 @@ class MinHeap[E: Object] redef fun is_empty do return items.is_empty redef fun length do return items.length redef fun iterator do return items.iterator + redef fun clear do items.clear redef fun peek do return items.first redef fun add(e) diff --git a/lib/gamnit/depth/depth.nit b/lib/gamnit/depth/depth.nit index 9fc0ba7..a9a446a 100644 --- a/lib/gamnit/depth/depth.nit +++ b/lib/gamnit/depth/depth.nit @@ -52,19 +52,26 @@ redef class App normals_program.use normals_program.mvp.uniform app.world_camera.mvp_matrix + frame_core_depth_clock.lapse for actor in actors do for leaf in actor.model.leaves do leaf.material.draw(actor, leaf) end end + perfs["gamnit depth actors"].add frame_core_depth_clock.lapse frame_core_world_sprites display + perfs["gamnit depth sprites"].add frame_core_depth_clock.lapse # Toggle writing to the depth buffer for particles effects glDepthMask false for system in particle_systems do system.draw glDepthMask true + perfs["gamnit depth particles"].add frame_core_depth_clock.lapse frame_core_ui_sprites display + perfs["gamnit depth ui_sprites"].add frame_core_depth_clock.lapse end + + private var frame_core_depth_clock = new Clock end diff --git a/lib/gamnit/examples/template_flat/Makefile b/lib/gamnit/examples/template_flat/Makefile new file mode 100644 index 0000000..61bfc25 --- /dev/null +++ b/lib/gamnit/examples/template_flat/Makefile @@ -0,0 +1,8 @@ +all: bin/template_flat bin/template_flat.apk + +bin/template_flat: $(shell nitls -M src/template_flat.nit linux) + nitc --debug src/template_flat.nit -m linux -o $@ + +android: bin/template_flat.apk +bin/template_flat.apk: $(shell nitls -M src/template_flat.nit android) + nitc src/template_flat.nit -m android -o $@ diff --git a/lib/gamnit/examples/template_flat/README.md b/lib/gamnit/examples/template_flat/README.md new file mode 100644 index 0000000..3ab2dbe --- /dev/null +++ b/lib/gamnit/examples/template_flat/README.md @@ -0,0 +1,6 @@ +Template for a 2D _gamnit_ game + +This project can be copied and modified to use as starting point for a new _gamnit_ 2D game +using the `flat` API. + +Both assets are published under CC0. diff --git a/lib/gamnit/examples/template_flat/assets/fighter.png b/lib/gamnit/examples/template_flat/assets/fighter.png new file mode 100644 index 0000000..d5f3ee4 Binary files /dev/null and b/lib/gamnit/examples/template_flat/assets/fighter.png differ diff --git a/lib/gamnit/examples/template_flat/assets/laser.mp3 b/lib/gamnit/examples/template_flat/assets/laser.mp3 new file mode 100644 index 0000000..d1f2ba2 Binary files /dev/null and b/lib/gamnit/examples/template_flat/assets/laser.mp3 differ diff --git a/lib/gamnit/examples/template_flat/bin/.gitignore b/lib/gamnit/examples/template_flat/bin/.gitignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/lib/gamnit/examples/template_flat/bin/.gitignore @@ -0,0 +1 @@ +* diff --git a/lib/gamnit/examples/template_flat/package.ini b/lib/gamnit/examples/template_flat/package.ini new file mode 100644 index 0000000..103ccd7 --- /dev/null +++ b/lib/gamnit/examples/template_flat/package.ini @@ -0,0 +1,11 @@ +[package] +name=template_flat +tags=game,example +maintainer=Alexis Laferrière +license=WTFPL +[upstream] +browse=https://github.com/nitlang/nit/tree/master/lib/gamnit/examples/template_flat/ +git=https://github.com/nitlang/nit.git +git.directory=lib/gamnit/examples/template_flat/ +homepage=http://nitlanguage.org +issues=https://github.com/nitlang/nit/issues diff --git a/lib/gamnit/examples/template_flat/src/template_flat.nit b/lib/gamnit/examples/template_flat/src/template_flat.nit new file mode 100644 index 0000000..b15d6b8 --- /dev/null +++ b/lib/gamnit/examples/template_flat/src/template_flat.nit @@ -0,0 +1,139 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the Do What The Fuck You Want To +# Public License, Version 2, as published by Sam Hocevar. See +# http://sam.zoy.org/projects/COPYING.WTFPL for more details. + +# Template for a 2D gamnit game +module template_flat is + app_name "gamnit 2D Template" + app_namespace "net.xymus.template_flat" + app_version(1, 0, git_revision) + + android_api_target 15 +end + +import gamnit::flat # For `Texture, Sprite`, etc. +import gamnit::keys # For `pressed_keys` +import app::audio # For `Sound` + +redef class App + + # Texture, loaded automatically at `on_create` + var texture = new Texture("fighter.png") + + # Sound effect, lazy loaded at first use + var sound = new Sound("laser.mp3") + + # 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 + do + super + + # Report errors on all loaded textures. + # Root textures are associated to pixel data, + # whereas other texture may be subtextures of root textures. + for tex in all_root_textures do + var error = tex.error + if error != null then print_error "Texture '{tex}' failed to load: {error}" + end + + # Draw the texture as pixelated, it looks better for such + # a small texture. + texture.as(TextureAsset).pixelated = true + + # Create the sprite and make it visible. + sprites.add sprite + + # Make the sprite smaller, by default each pixel corresponds to 1 world unit. + # However, it is often preferable to make 1 world unit correspond to + # something meaningful in the game world, such as 1 meter. + # + # Scale the ship so it is approximately 5 world units wide. + sprite.scale = 5.0 / texture.width + + # Move the camera to show 10 world units on the Y axis at Z = 0. + # The `sprite` should take approximately 1/4 of the height of the screen. + world_camera.reset_height 20.0 + + # Move the near clip wall closer to the camera because our world unit + # range is small. Moving the clip wall too close to the camera can + # cause glitches on mobiles devices with small depth buffer. + world_camera.near = 1.0 + + # Make the background blue and opaque. + glClearColor(0.0, 0.0, 1.0, 1.0) + + # If the first command line argument is an integer, add extra sprites. + if args.not_empty and args.first.is_int then + # It's a performance test, unlock the framerate. + maximum_fps = -1.0 + + # Add `args.first` sprites. + for i in args.first.to_i.times do + var s = new Sprite(texture, new Point3d[Float](30.0.rand - 15.0, 20.0.rand - 10.0, 0.0 - 30.0.rand)) + s.scale = 0.1 + sprites.add s + end + end + end + + redef fun update(dt) + do + # Update game logic here. + sprite.rotation += 0.1*pi*dt + + # Move `sprite` with the keyboard arrows. + # Set the speed according to the elapsed time since the last frame `dt` + # for a smooth animation. + var unit_per_second = 2.0 + for key in pressed_keys do + if key == "left" then + sprite.center.x -= unit_per_second*dt + else if key == "right" then + sprite.center.x += unit_per_second*dt + else if key == "up" then + sprite.center.y += unit_per_second*dt + else if key == "down" then + sprite.center.y -= unit_per_second*dt + end + end + end + + redef fun accept_event(event) + do + if super then return true + + if event isa QuitEvent or + (event isa KeyEvent and event.name == "escape" and event.is_up) then + # When window close button, escape or back key is pressed + # show the average FPS over the last few seconds. + print "{current_fps} fps" + print sys.perfs + + # Quit abruptly + exit 0 + else if event isa KeyEvent and event.is_down then + if event.name == "space" then + # Play a sound when space bar is pressed. + sound.play + return true + else if event.name == "s" then + # Remove a random sprite. + if sprites.not_empty then sprites.remove sprites.rand + else if event.name == "w" then + # Add a random sprite. + var s = new Sprite(texture, new Point3d[Float](30.0.rand - 15.0, 20.0.rand - 10.0, 0.0 - 30.0.rand)) + s.scale = 0.1 + s.tint[1] = 0.0 + s.tint[2] = 0.0 + sprites.add s + end + end + + return false + end +end diff --git a/lib/gamnit/examples/triangle/src/standalone_triangle.nit b/lib/gamnit/examples/triangle/src/standalone_triangle.nit index 9840d15..9817d09 100644 --- a/lib/gamnit/examples/triangle/src/standalone_triangle.nit +++ b/lib/gamnit/examples/triangle/src/standalone_triangle.nit @@ -73,7 +73,7 @@ void main() gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); } """@glsl_fragment_shader.to_cstring) -glIsShader fragment_shader +glCompileShader fragment_shader assert fragment_shader.is_compiled else print "Fragment shader compilation failed with: {glGetShaderInfoLog(fragment_shader)}" assert glGetError == gl_NO_ERROR diff --git a/lib/gamnit/flat.nit b/lib/gamnit/flat.nit index 6487ed2..d5cb28e 100644 --- a/lib/gamnit/flat.nit +++ b/lib/gamnit/flat.nit @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Simple API for 2D games, based around `Sprite` and `App::update` +# Simple API for 2D games, built around `Sprite` and `App::update` # # Client programs should implement `App::update` to execute game logic and # add instances of `Sprite` to `App::sprites` and `App::ui_sprites`. @@ -21,23 +21,23 @@ # This system relies on two cameras `App::world_camera` and `App::ui_camera`. # # * `App::world_camera` applies a perspective effect to draw the game world. -# This camera is designed to be moved around to see the world as well as to zoom in and out. -# It is used to position the sprites in `App::sprites`. +# This camera is designed to be moved around to see the world as well as to +# zoom in and out. It is used to position the sprites in `App::sprites`. # # * `App::ui_camera` is a simple orthogonal camera to display UI objects. -# This camera should mostly be still, it can still move for chock effects 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`. +# This camera should mostly be still, it can still move for chock effects +# 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 - -import geometry::points_and_lines +intrude import geometry::points_and_lines # For _x, _y and _z import matrix::projection import more_collections -import realtime +import performance_analysis import gamnit import gamnit::cameras @@ -45,69 +45,177 @@ import gamnit::limit_fps import android_two_fingers_motion is conditional(android) -# Image to draw on screen +# Draw a `texture` at `center` +# +# An instance of `Sprite` can only belong to a single `SpriteSet` at +# a time. The on screen position depends on the camera associated +# to the `SpriteSet`. class Sprite # Texture drawn to screen - var texture: Texture is writable + var texture: Texture is writable(texture_direct=) + + # Texture drawn to screen + fun texture=(value: Texture) + do + if isset _texture and value != texture then + needs_update + if value.root != texture.root then needs_remap + end + texture_direct = value + end + + # Center position of this sprite in world coordinates + var center: Point3d[Float] is writable(center_direct=), noautoinit + + # Center position of this sprite in world coordinates + fun center=(value: Point3d[Float]) is autoinit do + if isset _center and value != center then + needs_update + center.sprites_remove self + end + + value.sprites_add self + center_direct = value + end - # Position of this sprite in world coordinates - var center: Point3d[Float] is writable + # Rotation on the Z axis, positive values go counterclockwise + var rotation = 0.0 is writable(rotation_direct=) - # Rotation on the Z axis, where 0.0 points right and `0.5*pi` points up - var rotation = 0.0 is writable + # Rotation on the Z axis, positive values go counterclockwise + fun rotation=(value: Float) + do + if isset _rotation and value != rotation then needs_update + rotation_direct = value + end # Mirror `texture` horizontally, inverting each pixel on the X axis - var invert_x = false is writable + var invert_x = false is writable(invert_x_direct=) + + # Mirror `texture` horizontally, inverting each pixel on the X axis + fun invert_x=(value: Bool) + do + if isset _invert_x and value != invert_x then needs_update + invert_x_direct = value + end # Scale applied to this sprite - var scale = 1.0 is writable + # + # The default size of `self` depends on the size in pixels of `texture`. + var scale = 1.0 is writable(scale_direct=) + + # Scale applied to this sprite, see `scale` + fun scale=(value: Float) + do + if isset _scale and value != scale then needs_update + scale_direct = value + end - # Transparency applied to the texture on draw + # Red tint applied to `texture` on draw + fun red: Float do return tint[0] + + # Red tint applied to `texture` on draw + fun red=(value: Float) + do + if isset _tint and value != red then needs_update + tint[0] = value + end + + # Green tint applied to `texture` on draw + fun green: Float do return tint[1] + + # Green tint applied to `texture` on draw + fun green=(value: Float) + do + if isset _tint and value != green then needs_update + tint[1] = value + end + + # Blue tint applied to `texture` on draw + fun blue: Float do return tint[2] + + # Blue tint applied to `texture` on draw + fun blue=(value: Float) + do + if isset _tint and value != blue then needs_update + tint[2] = value + end + + # Transparency applied to `texture` on draw fun alpha: Float do return tint[3] - # Transparency applied to the texture on draw - fun alpha=(value: Float) do tint[3] = value + # Transparency applied to `texture` on draw + fun alpha=(value: Float) + do + if isset _tint and value != alpha then needs_update + tint[3] = value + end - # Tint applied to the texture on draw + # Tint applied to `texture` on draw + # + # Alternative to the accessors `red, green, blue & alpha`. + # Changes inside the array do not automatically set `needs_update`. # # Require: `tint.length == 4` - var tint: Array[Float] = [1.0, 1.0, 1.0, 1.0] is writable + var tint: Array[Float] = [1.0, 1.0, 1.0, 1.0] is writable(tint_direct=) - private fun draw + # Tint applied to `texture` on draw, see `tint` + fun tint=(value: Array[Float]) do - var simple_2d_program = app.simple_2d_program - - glActiveTexture gl_TEXTURE0 - glBindTexture(gl_TEXTURE_2D, texture.root.gl_texture) + if isset _tint and value != tint then needs_update + tint_direct = value + end - simple_2d_program.translation.array_enabled = false - simple_2d_program.color.array_enabled = false - simple_2d_program.scale.array_enabled = false + # Is this sprite static and added in bulk? + # + # Set to `true` to give a hint to the framework that this sprite won't + # change often and that it is added in bulk with other static sprites. + # This value can be ignored in the prototyping phase of a game and + # added only when better performance are needed. + var static = false is writable(static_direct=) + + # Is this sprite static and added in bulk? see `static` + fun static=(value: Bool) + do + if isset _static and value != static then needs_remap + static_direct = value + end - simple_2d_program.translation.uniform(center.x, center.y, center.z, 0.0) - simple_2d_program.color.uniform(tint[0], tint[1], tint[2], tint[3]) - simple_2d_program.scale.uniform scale + # Request an update on the CPU + # + # This is called automatically on modification of any value of `Sprite`. + # However, it can still be set manually if a modification can't be + # detected or by subclasses. + fun needs_update + do + var c = context + if c != null then c.sprites_to_update.add self + end - simple_2d_program.use_texture.uniform true - simple_2d_program.texture.uniform 0 - simple_2d_program.tex_coord.array( - if invert_x then - texture.texture_coords_invert_x - else texture.texture_coords, 2) - simple_2d_program.coord.array(texture.vertices, 3) + # Request a resorting of this sprite in its sprite list + # + # Resorting is required when `static` or the root of `texture` changes. + # This is called automatically when such changes are detected. + # However, it can still be set manually if a modification can't be + # detected or by subclasses. + fun needs_remap + do + var l = sprite_set + if l != null then l.sprites_to_remap.add self + end - simple_2d_program.rotation.uniform new Matrix.rotation(rotation, 0.0, 0.0, -1.0) + # Current context to which `self` was sorted + private var context: nullable SpriteContext = null - glDrawArrays(gl_TRIANGLE_STRIP, 0, 4) - end + # Current context to which `self` belongs + private var sprite_set: nullable SpriteSet = null end redef class App # Default graphic program to draw `sprites` - var simple_2d_program = new Simple2dProgram is lazy # TODO private + private var simple_2d_program = new Simple2dProgram is lazy - # Camera for world objects with perspective + # 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`. @@ -121,17 +229,51 @@ redef class App return camera end - # Camera for UI elements using an orthogonal view + # Camera for `ui_sprites` using an orthogonal view var ui_camera: UICamera = new UICamera(app.display.as(not null)) is lazy - # Live sprites to draw in reference to `world_camera` - var sprites: Sequence[Sprite] = new List[Sprite] + # World sprites to draw as seen by `world_camera` + var sprites: Set[Sprite] = new SpriteSet + + # UI sprites to draw as seen by `ui_camera`, drawn over world `sprites` + var ui_sprites: Set[Sprite] = new SpriteSet + + # Main method to refine in clients to update game logic and `sprites` + fun update(dt: Float) do end + + # Display `texture` as a splash screen + # + # Load `texture` if needed and resets `ui_camera` to 1080 units on the Y axis. + fun show_splash_screen(texture: Texture) + do + texture.load + + ui_camera.reset_height 1080.0 + + var splash = new Sprite(texture, ui_camera.center) + ui_sprites.add splash + + var display = display + assert display != null + glClear gl_COLOR_BUFFER_BIT + frame_core_ui_sprites display + display.flip + + ui_sprites.remove splash + end - # UI sprites to draw in reference to `ui_camera`, over world `sprites` - var ui_sprites: Sequence[Sprite] = new List[Sprite] + # --- + # Support and implementation + # Main clock used to count each frame `dt`, lapsed for `update` only private var clock = new Clock is lazy + # Performance clock to for `frame_core_draw` operations + private var perf_clock_main = new Clock + + # Second performance clock for smaller operations + private var perf_clock_sprites = new Clock is lazy + redef fun on_create do super @@ -140,7 +282,7 @@ redef class App assert display != null var gl_error = glGetError - assert gl_error == gl_NO_ERROR else print gl_error + assert gl_error == gl_NO_ERROR else print_error gl_error # Prepare program var program = simple_2d_program @@ -163,7 +305,7 @@ redef class App glClearColor(0.0, 0.0, 0.0, 1.0) gl_error = glGetError - assert gl_error == gl_NO_ERROR else print gl_error + assert gl_error == gl_NO_ERROR else print_error gl_error # Prepare to draw for tex in all_root_textures do @@ -176,6 +318,16 @@ redef class App end end + redef fun on_stop + do + # Clean up + simple_2d_program.delete + + # Close gamnit + var display = display + if display != null then display.close + end + redef fun frame_core(display) do # Prepare to draw, clear buffers @@ -183,11 +335,13 @@ redef class App # Check errors var gl_error = glGetError - assert gl_error == gl_NO_ERROR else print gl_error + assert gl_error == gl_NO_ERROR else print_error gl_error # Update game logic and set sprites + perf_clock_main.lapse var dt = clock.lapse.to_f update dt + sys.perfs["gamnit flat update client"].add perf_clock_main.lapse # Draw and flip screen frame_core_draw display @@ -195,129 +349,88 @@ redef class App # Check errors gl_error = glGetError - assert gl_error == gl_NO_ERROR else print gl_error + assert gl_error == gl_NO_ERROR else print_error gl_error end # 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_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 end - # Draw world sprites from `sprites` - protected fun frame_core_world_sprites(display: GamnitDisplay) + private fun frame_core_sprites(display: GamnitDisplay, sprite_set: SpriteSet, camera: Camera) do + var simple_2d_program = app.simple_2d_program simple_2d_program.use + simple_2d_program.mvp.uniform camera.mvp_matrix - # Set constant configs - simple_2d_program.coord.array_enabled = true - simple_2d_program.tex_coord.array_enabled = true - simple_2d_program.color.array_enabled = false + # draw + sprite_set.draw + end - # TODO optimize this draw to store constant values on the GPU - # World sprites - simple_2d_program.mvp.uniform world_camera.mvp_matrix - for sprite in sprites do sprite.draw + # Draw world sprites from `sprites` + protected fun frame_core_world_sprites(display: GamnitDisplay) + do + frame_core_sprites(display, sprites.as(SpriteSet), world_camera) end # Draw UI sprites from `ui_sprites` protected fun frame_core_ui_sprites(display: GamnitDisplay) do - simple_2d_program.use - - # Set constant configs - simple_2d_program.coord.array_enabled = true - simple_2d_program.tex_coord.array_enabled = true - simple_2d_program.color.array_enabled = false - # Reset only the depth buffer glClear gl_DEPTH_BUFFER_BIT - # UI sprites - simple_2d_program.mvp.uniform ui_camera.mvp_matrix - for sprite in ui_sprites do sprite.draw - end - - # Main method to refine in clients to update game logic and `sprites` - fun update(dt: Float) do end - - # Display `texture` as a splash screen - # - # Load `texture` if needed and resets `ui_camera` to 1080 units on the Y axis. - fun show_splash_screen(texture: Texture) - do - texture.load - - ui_camera.reset_height 1080.0 - - var splash = new Sprite(texture, ui_camera.center) - ui_sprites.add splash - - var display = display - assert display != null - glClear gl_COLOR_BUFFER_BIT - frame_core_ui_sprites display - display.flip - - ui_sprites.remove splash - end - - redef fun on_stop - do - # Clean up - simple_2d_program.delete - - # Close gamnit - var display = display - if display != null then display.close + frame_core_sprites(display, ui_sprites.as(SpriteSet), ui_camera) end end redef class Texture # Vertices coordinates of the base geometry + # + # Defines the default width and height of related sprites. private var vertices: Array[Float] is lazy do - var mod = 1.0 - var w = width * mod - var h = height * mod - var a = [-0.5*w, -0.5*h, 0.0] - var b = [ 0.5*w, -0.5*h, 0.0] - var c = [-0.5*w, 0.5*h, 0.0] - var d = [ 0.5*w, 0.5*h, 0.0] - - var vertices = new Array[Float] - for v in [c, d, a, b] do vertices.add_all v - return vertices + var w = width + var h = height + return [-0.5*w, 0.5*h, 0.0, + 0.5*w, 0.5*h, 0.0, + -0.5*w, -0.5*h, 0.0, + 0.5*w, -0.5*h, 0.0] end - # Coordinates of this texture on the `root` texture, with `[0..1.0]` + # Coordinates of this texture on the `root` texture, in `[0..1.0]` private var texture_coords: Array[Float] is lazy do - var a = [offset_left, offset_bottom] - var b = [offset_right, offset_bottom] - var c = [offset_left, offset_top] - var d = [offset_right, offset_top] - - var texture_coords = new Array[Float] - for v in [c, d, a, b] do texture_coords.add_all v - return texture_coords + var l = offset_left + var r = offset_right + var b = offset_bottom + var t = offset_top + return [l, t, + r, t, + l, b, + r, b] end - # Coordinates of this texture on the `root` texture, with the X axis inverted + # Coordinates of this texture on the `root` texture, inverting the X axis private var texture_coords_invert_x: Array[Float] is lazy do - var a = [offset_left, offset_bottom] - var b = [offset_right, offset_bottom] - var c = [offset_left, offset_top] - var d = [offset_right, offset_top] - - var texture_coords = new Array[Float] - for v in [d, c, b, a] do texture_coords.add_all v - return texture_coords + var l = offset_left + var r = offset_right + var b = offset_bottom + var t = offset_top + return [r, t, + l, t, + r, b, + l, b] end end # Graphic program to display simple models with a texture, translation, rotation and scale -class Simple2dProgram +private class Simple2dProgram super GamnitProgramFromSource redef var vertex_shader_source = """ @@ -340,16 +453,24 @@ class Simple2dProgram uniform mat4 mvp; // Rotation matrix - uniform mat4 rotation; + attribute vec4 rotation_row0; + attribute vec4 rotation_row1; + attribute vec4 rotation_row2; + attribute vec4 rotation_row3; - // Output for the fragment shader + mat4 rotation() + { + return mat4(rotation_row0, rotation_row1, rotation_row2, rotation_row3); + } + + // Output to the fragment shader varying vec4 v_color; varying vec2 v_coord; void main() { + gl_Position = (vec4(coord.xyz * scale, 1.0) * rotation() + translation)* mvp; v_color = color; - gl_Position = (vec4(coord.xyz * scale, 1.0) * rotation + translation) * mvp; v_coord = tex_coord; } """ @ glsl_vertex_shader @@ -371,7 +492,7 @@ class Simple2dProgram { if(use_texture) { gl_FragColor = v_color * texture2D(texture0, v_coord); - if (gl_FragColor.a == 0.0) discard; + if (gl_FragColor.a <= 0.1) discard; } else { gl_FragColor = v_color; } @@ -396,8 +517,17 @@ class Simple2dProgram # Translation applied to each vertex var translation = attributes["translation"].as(AttributeVec4) is lazy - # Rotation matrix - var rotation = uniforms["rotation"].as(UniformMat4) is lazy + # Rotation matrix, row 0 + var rotation_row0 = attributes["rotation_row0"].as(AttributeVec4) is lazy + + # Rotation matrix, row 1 + var rotation_row1 = attributes["rotation_row1"].as(AttributeVec4) is lazy + + # Rotation matrix, row 2 + var rotation_row2 = attributes["rotation_row2"].as(AttributeVec4) is lazy + + # Rotation matrix, row 3 + var rotation_row3 = attributes["rotation_row3"].as(AttributeVec4) is lazy # Scaling per vertex var scale = attributes["scale"].as(AttributeFloat) is lazy @@ -412,4 +542,711 @@ redef class Point3d[N] do return new Point3d[Float](self.x.to_f+x.to_f, self.y.to_f+y.to_f, self.z.to_f+z.to_f) end + + # --- + # Associate each point to its sprites + + private var sprites: nullable Array[Sprite] = null + + private fun sprites_add(sprite: Sprite) + do + var sprites = sprites + if sprites == null then + sprites = new Array[Sprite] + self.sprites = sprites + end + sprites.add sprite + end + + private fun sprites_remove(sprite: Sprite) + do + var sprites = sprites + assert sprites != null + sprites.remove sprite + end + + # --- + # Notify `sprites` on attribute modification + + private fun needs_update + do + var sprites = sprites + if sprites != null then for s in sprites do s.needs_update + end + + redef fun x=(v) + do + if isset _x and v != x then needs_update + super + end + + redef fun y=(v) + do + if isset _y and v != y then needs_update + super + end + + redef fun z=(v) + do + if isset _z and v != z then needs_update + super + end +end + +# Set of sprites sorting them into different `SpriteContext` +private class SpriteSet + super HashSet[Sprite] + + # Map texture then static vs dynamic to a `SpriteContext` + var contexts_map = new HashMap2[GamnitRootTexture, Bool, SpriteContext] + + # Contexts in `contexts_map` + var contexts_items = new Array[SpriteContext] + + # Sprites needing resorting in `contexts_map` + var sprites_to_remap = new Array[Sprite] + + # Add a sprite to the appropriate context + fun map_sprite(sprite: Sprite) + do + assert sprite.context == null else print_error "Sprite {sprite} belongs to another SpriteSet" + + var texture = sprite.texture.root + var context = contexts_map[texture, sprite.static] + + if context == null then + var usage = if sprite.static then gl_STATIC_DRAW else gl_DYNAMIC_DRAW + context = new SpriteContext(texture, usage) + + contexts_map[texture, sprite.static] = context + contexts_items.add context + end + + context.sprites.add sprite + context.sprites_to_update.add sprite + + sprite.context = context + sprite.sprite_set = self + end + + # Remove a sprite from its context + fun unmap_sprite(sprite: Sprite) + do + var context = sprite.context + assert context != null + context.sprites.remove sprite + + sprite.context = null + sprite.sprite_set = null + end + + # Draw all sprites by all contexts + fun draw + do + for sprite in sprites_to_remap do + unmap_sprite sprite + map_sprite sprite + end + sprites_to_remap.clear + + for context in contexts_items do context.draw + end + + redef fun add(e) + do + if contexts_items.has(e.context) then return + map_sprite e + super + end + + redef fun remove(e) + do + super + 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 + super + for c in contexts_items do c.destroy + contexts_map.clear + contexts_items.clear + end +end + +# Context for calls to `glDrawElements` +# +# Each context has only one `texture` and `usage`, but many sprites. +private class SpriteContext + + # --- + # Context config and state + + # Only root texture drawn by this context + var texture: nullable GamnitRootTexture + + # OpenGL ES usage of `buffer_array` and `buffer_element` + var usage: GLBufferUsage + + # Sprites drawn by this context + var sprites = new GroupedArray[Sprite] + + # Sprites to update since last `draw` + var sprites_to_update = new Set[Sprite] + + # Sprites that have been update and for which `needs_update` can be set to false + var updated_sprites = new Array[Sprite] + + # Buffer size to preallocate at `resize`, multiplied by `sprites.length` + # + # Require: `resize_ratio >= 1.0` + var resize_ratio = 1.2 + + # --- + # OpenGL ES data + + # OpenGL ES buffer name for vertex data + var buffer_array: Int = -1 + + # OpenGL ES buffer name for indices + var buffer_element: Int = -1 + + # Current capacity, in sprites, of `buffer_array` and `buffer_element` + var buffer_capacity = 0 + + # C buffers used to pass the data of a single sprite + var local_data_buffer = new GLfloatArray(float_per_vertex*4) is lazy + var local_indices_buffer = new CUInt16Array(indices_per_sprite) is lazy + + # --- + # Constants + + # Number of GL_FLOAT per vertex of `Simple2dProgram` + var float_per_vertex: Int is lazy do + # vec4 translation, vec4 color, vec4 coord, + # float scale, vec2 tex_coord, vec4 rotation_row* + return 4 + 4 + 4 + + 1 + 2 + 4*4 + end + + # Number of bytes per vertex of `Simple2dProgram` + var bytes_per_vertex: Int is lazy do + var fs = 4 # sizeof(GL_FLOAT) + return fs * float_per_vertex + end + + # Number of bytes per sprite + var bytes_per_sprite: Int is lazy do return bytes_per_vertex * 4 + + # Number of vertex indices per sprite draw call (2 triangles) + var indices_per_sprite = 6 + + # --- + # Main services + + # Allocate `buffer_array` and `buffer_element` + fun prepare + do + var bufs = glGenBuffers(2) + buffer_array = bufs[0] + buffer_element = bufs[1] + + var gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + end + + # Destroy `buffer_array` and `buffer_element` + fun destroy + do + glDeleteBuffers([buffer_array, buffer_element]) + var gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + + buffer_array = -1 + buffer_element = -1 + end + + # Resize `buffer_array` and `buffer_element` to fit all `sprites` (and more) + fun resize + do + app.perf_clock_sprites.lapse + + # Allocate a bit more space + var capacity = (sprites.capacity.to_f * resize_ratio).to_i + + var array_bytes = capacity * bytes_per_sprite + glBindBuffer(gl_ARRAY_BUFFER, buffer_array) + assert glIsBuffer(buffer_array) + glBufferData(gl_ARRAY_BUFFER, array_bytes, new Pointer.nul, usage) + var gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + + # GL_TRIANGLES 6 vertices * sprite + var n_indices = capacity * indices_per_sprite + var ius = 2 # sizeof(GL_UNSIGNED_SHORT) + var element_bytes = n_indices * ius + glBindBuffer(gl_ELEMENT_ARRAY_BUFFER, buffer_element) + assert glIsBuffer(buffer_element) + glBufferData(gl_ELEMENT_ARRAY_BUFFER, element_bytes, new Pointer.nul, usage) + gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + + buffer_capacity = capacity + + sys.perfs["gamnit flat gpu resize"].add app.perf_clock_sprites.lapse + end + + # Update GPU data of `sprite` + fun update_sprite(sprite: Sprite) + do + var sprite_index = sprites.index_of(sprite) + if sprite_index == -1 then return + + # Vertices data + + var data = local_data_buffer + var o = 0 + for v in [0..4[ do + # vec4 translation + data[o+ 0] = sprite.center.x + data[o+ 1] = sprite.center.y + data[o+ 2] = sprite.center.z + data[o+ 3] = 0.0 + + # vec4 color + data[o+ 4] = sprite.tint[0] + data[o+ 5] = sprite.tint[1] + data[o+ 6] = sprite.tint[2] + data[o+ 7] = sprite.tint[3] + + # float scale + data[o+ 8] = sprite.scale + + # vec4 coord + data[o+ 9] = sprite.texture.vertices[v*3+0] + data[o+10] = sprite.texture.vertices[v*3+1] + data[o+11] = sprite.texture.vertices[v*3+2] + data[o+12] = 0.0 + + # vec2 tex_coord + var texture = texture + if texture != null then + var tc = if sprite.invert_x then + sprite.texture.texture_coords_invert_x + else sprite.texture.texture_coords + data[o+13] = tc[v*2+0] + data[o+14] = tc[v*2+1] + end + + # mat4 rotation + var rot + if sprite.rotation == 0.0 then + # Cache the matrix at no rotation + rot = once new Matrix.identity(4) + else + rot = new Matrix.rotation(sprite.rotation, 0.0, 0.0, 1.0) + end + data.fill_from(rot.items, o+15) + + o += float_per_vertex + end + + glBindBuffer(gl_ARRAY_BUFFER, buffer_array) + glBufferSubData(gl_ARRAY_BUFFER, sprite_index*bytes_per_sprite, bytes_per_sprite, data.native_array) + + var gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + + # Element / indices + # + # 0--1 + # | /| + # |/ | + # 2--3 + + var indices = local_indices_buffer + var io = sprite_index*4 + indices[0] = io+0 + indices[1] = io+2 + indices[2] = io+1 + indices[3] = io+1 + indices[4] = io+2 + indices[5] = io+3 + + glBindBuffer(gl_ELEMENT_ARRAY_BUFFER, buffer_element) + glBufferSubData(gl_ELEMENT_ARRAY_BUFFER, sprite_index*6*2, 6*2, indices.native_array) + + gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + end + + # Draw all `sprites` + # + # Call `resize` and `update_sprite` as needed before actual draw operation. + # + # Require: `app.simple_2d_program` and `mvp` must be bound on the GPU + fun draw + do + if buffer_array == -1 then prepare + + assert buffer_array > 0 and buffer_element > 0 else + print_error "Internal error: {self} was destroyed" + end + + # Setup + glBindBuffer(gl_ARRAY_BUFFER, buffer_array) + glBindBuffer(gl_ELEMENT_ARRAY_BUFFER, buffer_element) + + # Resize GPU buffers? + if sprites.capacity > buffer_capacity then + # Try to defragment first + var moved = sprites.defragment + + if sprites.capacity > buffer_capacity then + # Defragmentation wasn't enough, grow + resize + + # We must update everything + for s in sprites.items do if s != null then sprites_to_update.add s + else + # Just update the moved sprites + for s in moved do sprites_to_update.add s + end + else if sprites.available.not_empty then + # Defragment a bit anyway + # TODO defrag only when there's time left on a frame + var moved = sprites.defragment(1) + for s in moved do sprites_to_update.add s + end + + # Update GPU sprites data + if sprites_to_update.not_empty then + app.perf_clock_sprites.lapse + + for sprite in sprites_to_update do update_sprite(sprite) + sprites_to_update.clear + + sys.perfs["gamnit flat gpu update"].add app.perf_clock_sprites.lapse + end + + # Update uniforms specific to this context + var texture = texture + app.simple_2d_program.use_texture.uniform texture != null + if texture != null then + glActiveTexture gl_TEXTURE0 + glBindTexture(gl_TEXTURE_2D, texture.gl_texture) + app.simple_2d_program.texture.uniform 0 + end + var gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + + # Configure attributes, in order: + # vec4 translation, vec4 color, float scale, vec4 coord, vec2 tex_coord, vec4 rotation_row* + var offset = 0 + var p = app.simple_2d_program + var sizeof_gl_float = 4 # sizeof(GL_FLOAT) + + var size = 4 # Number of floats + glEnableVertexAttribArray p.translation.location + glVertexAttribPointeri(p.translation.location, size, gl_FLOAT, false, bytes_per_vertex, offset) + offset += size * sizeof_gl_float + gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + + size = 4 + glEnableVertexAttribArray p.color.location + glVertexAttribPointeri(p.color.location, size, gl_FLOAT, false, bytes_per_vertex, offset) + offset += size * sizeof_gl_float + gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + + size = 1 + glEnableVertexAttribArray p.scale.location + glVertexAttribPointeri(p.scale.location, size, gl_FLOAT, false, bytes_per_vertex, offset) + offset += size * sizeof_gl_float + gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + + size = 4 + glEnableVertexAttribArray p.coord.location + glVertexAttribPointeri(p.coord.location, size, gl_FLOAT, false, bytes_per_vertex, offset) + offset += size * sizeof_gl_float + gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + + size = 2 + glEnableVertexAttribArray p.tex_coord.location + glVertexAttribPointeri(p.tex_coord.location, size, gl_FLOAT, false, bytes_per_vertex, offset) + offset += size * sizeof_gl_float + gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + + size = 4 + for r in [p.rotation_row0, p.rotation_row1, p.rotation_row2, p.rotation_row3] do + if r.is_active then + glEnableVertexAttribArray r.location + glVertexAttribPointeri(r.location, size, gl_FLOAT, false, bytes_per_vertex, offset) + end + offset += size * sizeof_gl_float + gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + end + + # Actual draw + for s in sprites.starts, e in sprites.ends do + var l = e-s + glDrawElementsi(gl_TRIANGLES, l*indices_per_sprite, gl_UNSIGNED_SHORT, 2*s*indices_per_sprite) + gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + end + + # Take down + for attr in [p.translation, p.color, p.scale, p.coord, p.tex_coord, + p.rotation_row0, p.rotation_row1, p.rotation_row2, p.rotation_row3: Attribute] do + if not attr.is_active then continue + glDisableVertexAttribArray(attr.location) + gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + end + + glBindBuffer(gl_ARRAY_BUFFER, 0) + glBindBuffer(gl_ELEMENT_ARRAY_BUFFER, 0) + gl_error = glGetError + assert gl_error == gl_NO_ERROR else print_error gl_error + end +end + +# Representation of sprite data on the GPU +# +# The main purpose of this class is to optimize the use of contiguous +# space in GPU memory. Each contiguous memory block can be drawn in a +# single call. The starts index of each block is kept by `starts, +# and the end + 1 by `ends`. +# +# The data can be compressed by a call to `defragment`. +# +# ~~~ +# var array = new GroupedArray[String] +# assert array.to_s == "" +# +# array.add "a" +# array.add "b" +# array.add "c" +# array.add "d" +# array.add "e" +# array.add "f" +# assert array.to_s == "[a,b,c,d,e,f]" +# assert array.capacity == 6 +# +# array.remove "a" +# assert array.to_s == "[b,c,d,e,f]" +# +# array.remove "b" +# assert array.to_s == "[c,d,e,f]" +# +# array.remove "f" +# assert array.to_s == "[c,d,e]" +# +# array.remove "d" +# assert array.to_s == "[c][e]" +# +# array.add "A" +# assert array.to_s == "[A][c][e]" +# +# array.add "B" +# assert array.to_s == "[A,B,c][e]" +# +# array.remove "e" +# assert array.to_s == "[A,B,c]" +# +# array.add "D" +# assert array.to_s == "[A,B,c,D]" +# +# array.add "E" +# assert array.to_s == "[A,B,c,D,E]" +# assert array.capacity == 5 +# assert array.length == 5 +# +# array.remove "A" +# array.remove "B" +# array.remove "c" +# array.remove "D" +# array.remove "E" +# assert array.to_s == "" +# +# array.add "a" +# assert array.to_s == "[a]" +# ~~~ +private class GroupedArray[E] + + # Memory with actual objects, and null in empty slots + var items = new Array[nullable E] + + # Number of items in the array + var length = 0 + + # Number of item slots in the array + fun capacity: Int do return items.length + + # Index of `item` + fun index_of(item: E): Int do return items.index_of(item) + + # List of available slots + var available = new MinHeap[Int].default + + # Start index of filled chunks + var starts = new List[Int] + + # Index of the spots after filled chunks + var ends = new List[Int] + + # Add `item` to the first available slot + fun add(item: E) + do + length += 1 + + if available.not_empty then + # starts & ends can't be empty + + var i = available.take + items[i] = item + + if i == starts.first - 1 then + # slot 0 free, 1 taken + starts.first -= 1 + else if i == 0 then + # slot 0 and more free + starts.unshift 0 + ends.unshift 1 + else if starts.length >= 2 and ends.first + 1 == starts[1] then + # merge 2 chunks + ends.remove_at 0 + starts.remove_at 1 + else + # at end of first chunk + ends.first += 1 + end + return + end + + items.add item + if ends.is_empty then + starts.add 0 + ends.add 1 + else ends.last += 1 + end + + # Remove the first instance of `item` + fun remove(item: E) + do + var i = items.index_of(item) + assert i != -1 + length -= 1 + items[i] = null + + var ii = 0 + for s in starts, e in ends do + if s <= i and i < e then + if s == e-1 then + # single item chunk + starts.remove_at ii + ends.remove_at ii + + if starts.is_empty then + items.clear + available.clear + return + end + else if e-1 == i then + # last item of chunk + ends[ii] -= 1 + + else if s == i then + # first item of chunk + starts[ii] += 1 + else + # break up chunk + ends.insert(ends[ii], ii+1) + ends[ii] = i + starts.insert(i+1, ii+1) + end + + available.add i + return + end + ii += 1 + end + + abort + end + + # Defragment and compress everything into a single chunks beginning at 0 + # + # Returns the elements that moved as a list. + # + # ~~~ + # var array = new GroupedArray[String] + # array.add "a" + # array.add "b" + # array.add "c" + # array.add "d" + # array.remove "c" + # array.remove "a" + # assert array.to_s == "[b][d]" + # + # var moved = array.defragment + # assert moved.to_s == "[d]" + # assert array.to_s == "[d,b]" + # assert array.length == 2 + # assert array.capacity == 2 + # + # array.add "e" + # array.add "f" + # assert array.to_s == "[d,b,e,f]" + # ~~~ + fun defragment(max: nullable Int): Array[E] + do + app.perf_clock_sprites.lapse + max = max or else length + + var moved = new Array[E] + while max > 0 and (starts.length > 1 or starts.first != 0) do + var i = ends.last - 1 + var e = items[i] + remove e + add e + moved.add e + max -= 1 + end + + if starts.length == 1 and starts.first == 0 then + for i in [length..capacity[ do items.pop + available.clear + end + + sys.perfs["gamnit flat gpu defrag"].add app.perf_clock_sprites.lapse + return moved + end + + redef fun to_s + do + var ss = new Array[String] + for s in starts, e in ends do + ss.add "[" + for i in [s..e[ do + var item: nullable Object = items[i] + if item == null then item = "null" + ss.add item.to_s + if i != e-1 then ss.add "," + end + ss.add "]" + end + return ss.join + end end diff --git a/lib/gamnit/tileset.nit b/lib/gamnit/tileset.nit index 6ea42e8..67bd32c 100644 --- a/lib/gamnit/tileset.nit +++ b/lib/gamnit/tileset.nit @@ -134,7 +134,7 @@ class TextSprites # # Defaults to `app::ui_sprites`, but it could also be set to a # `app::sprites` or a custom collection. - var target_sprite_set: Sequence[Sprite] = app.ui_sprites is lazy, writable + var target_sprite_set: Set[Sprite] = app.ui_sprites is lazy, writable private var cached_text: nullable Text = "" diff --git a/lib/glesv2/glesv2.nit b/lib/glesv2/glesv2.nit index a183c47..8acfde1 100644 --- a/lib/glesv2/glesv2.nit +++ b/lib/glesv2/glesv2.nit @@ -187,7 +187,7 @@ fun glValidateProgram(program: GLProgram) `{ glValidateProgram(program); `} # Delete the `program` object fun glDeleteProgram(program: GLProgram) `{ glDeleteProgram(program); `} -# Determine if `name` corresponds to a program object +# Does `name` corresponds to a program object? fun glIsProgram(name: GLProgram): Bool `{ return glIsProgram(name); `} # Attach a `shader` to `program` @@ -312,7 +312,7 @@ fun glCompileShader(shader: GLShader) `{ glCompileShader(shader); `} # Delete the `shader` object fun glDeleteShader(shader: GLShader) `{ glDeleteShader(shader); `} -# Determine if `name` corresponds to a shader object +# Does `name` corresponds to a shader object? fun glIsShader(name: GLShader): Bool `{ return glIsShader(name); `} # An OpenGL ES 2.0 fragment shader @@ -375,16 +375,26 @@ fun glDisableVertexAttribArray(index: Int) `{ glDisableVertexAttribArray(index); # Render primitives from array data fun glDrawArrays(mode: GLDrawMode, from, count: Int) `{ glDrawArrays(mode, from, count); `} -# Render primitives from array data by their index +# Render primitives from array data by their index listed in `indices` fun glDrawElements(mode: GLDrawMode, count: Int, typ: GLDataType, indices: Pointer) `{ glDrawElements(mode, count, typ, indices); `} +# Render primitives from array data, at `offset` in the element buffer +fun glDrawElementsi(mode: GLDrawMode, count: Int, typ: GLDataType, offset: Int) `{ + glDrawElements(mode, count, typ, (const GLvoid*)offset); +`} + # Define an array of generic vertex attribute data fun glVertexAttribPointer(index, size: Int, typ: GLDataType, normalized: Bool, stride: Int, array: NativeGLfloatArray) `{ glVertexAttribPointer(index, size, typ, normalized, stride, array); `} +# Define an array of generic vertex attribute data, at `offset` in the array buffer +fun glVertexAttribPointeri(index, size: Int, typ: GLDataType, normalized: Bool, stride: Int, offset: Int) `{ + glVertexAttribPointer(index, size, typ, normalized, stride, (const GLvoid*)offset); +`} + # Specify the value of a generic vertex attribute fun glVertexAttrib1f(index: Int, x: Float) `{ glVertexAttrib1f(index, x); `} @@ -440,11 +450,18 @@ class GLfloatArray end # Fill with the content of `array` - fun fill_from(array: Array[Float]) + # + # If `dst_offset` is set, the data is copied to the index `dst_offset`, + # otherwise, it is copied the beginning of `self`. + # + # Require: `length >= array.length + dst_offset or else 0` + fun fill_from(array: Array[Float], dst_offset: nullable Int) do - assert length >= array.length + dst_offset = dst_offset or else 0 + + assert length >= array.length + dst_offset for k in [0..array.length[ do - self[k] = array[k] + self[dst_offset+k] = array[k] end end end @@ -694,7 +711,7 @@ private fun native_glGenRenderbuffers(n: Int, renderbuffers: NativeCIntArray) `{ glGenRenderbuffers(n, (GLuint *)renderbuffers); `} -# Determine if `name` corresponds to a renderbuffer object +# Does `name` corresponds to a renderbuffer object? fun glIsRenderbuffer(name: Int): Bool `{ return glIsRenderbuffer(name); `} @@ -876,6 +893,62 @@ fun glHint(target: GLHintTarget, mode: GLHintMode) `{ # Generate and fill set of mipmaps for the texture object `target` fun glGenerateMipmap(target: GLTextureTarget) `{ glGenerateMipmap(target); `} +# Generate `n` buffer names +fun glGenBuffers(n: Int): Array[Int] +do + var array = new CIntArray(n) + native_glGenBuffers(n, array.native_array) + var a = array.to_a + array.destroy + return a +end + +private fun native_glGenBuffers(n: Int, buffers: NativeCIntArray) `{ + glGenBuffers(n, (GLuint *)buffers); +`} + +# Does `name` corresponds to a buffer object? +fun glIsBuffer(name: Int): Bool `{ + return glIsBuffer(name); +`} + +# Delete named buffer objects +fun glDeleteBuffers(buffers: SequenceRead[Int]) +do + var n = buffers.length + var array = new CIntArray.from(buffers) + native_glDeleteFramebuffers(n, array.native_array) + array.destroy +end + +private fun native_glDeleteBuffers(n: Int, buffers: NativeCIntArray) `{ + return glDeleteBuffers(n, (const GLuint *)buffers); +`} + +# Create and initialize a buffer object's data store +fun glBufferData(target: GLArrayBuffer, size: Int, data: Pointer, usage: GLBufferUsage) `{ + glBufferData(target, size, data, usage); +`} + +# Update a subset of a buffer object's data store +fun glBufferSubData(target: GLArrayBuffer, offset, size: Int, data: Pointer) `{ + glBufferSubData(target, offset, size, data); +`} + +# Expected usage of a buffer +extern class GLBufferUsage + super GLEnum +end + +# Data will be modified once and used a few times +fun gl_STREAM_DRAW: GLBufferUsage `{ return GL_STREAM_DRAW; `} + +# Data will be modified once and used many times +fun gl_STATIC_DRAW: GLBufferUsage `{ return GL_STATIC_DRAW; `} + +# Data will be modified repeatedly and used many times +fun gl_DYNAMIC_DRAW: GLBufferUsage `{ return GL_DYNAMIC_DRAW; `} + # Bind the named `buffer` object fun glBindBuffer(target: GLArrayBuffer, buffer: Int) `{ glBindBuffer(target, buffer); `} @@ -967,11 +1040,11 @@ do return a end -private fun native_glGenFramebuffers(n: Int, textures: NativeCIntArray) `{ - glGenFramebuffers(n, (GLuint *)textures); +private fun native_glGenFramebuffers(n: Int, framebuffers: NativeCIntArray) `{ + glGenFramebuffers(n, (GLuint *)framebuffers); `} -# Determine if `name` corresponds to a framebuffer object +# Does `name` corresponds to a framebuffer object? fun glIsFramebuffer(name: Int): Bool `{ return glIsFramebuffer(name); `} diff --git a/lib/matrix/matrix.nit b/lib/matrix/matrix.nit index 73131ca..91adb80 100644 --- a/lib/matrix/matrix.nit +++ b/lib/matrix/matrix.nit @@ -28,7 +28,7 @@ class Matrix var height: Int # Items of this matrix, rows by rows - private var items: Array[Float] is lazy do + var items: Array[Float] is lazy do return new Array[Float].filled_with(0.0, width*height) end diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 4ce8024..0d04167 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -1450,7 +1450,7 @@ abstract class AbstractCompilerVisitor # Checks # Can value be null? (according to current knowledge) - fun maybenull(value: RuntimeVariable): Bool + fun maybe_null(value: RuntimeVariable): Bool do return value.mcasttype isa MNullableType or value.mcasttype isa MNullType end @@ -1460,7 +1460,7 @@ abstract class AbstractCompilerVisitor do if self.compiler.modelbuilder.toolcontext.opt_no_check_null.value then return - if maybenull(recv) then + if maybe_null(recv) then self.add("if (unlikely({recv} == NULL)) \{") self.add_abort("Receiver is null") self.add("\}") @@ -3211,7 +3211,7 @@ redef class AAttrPropdef assert arguments.length == 2 var recv = arguments.first var arg = arguments[1] - if is_optional and v.maybenull(arg) then + if is_optional and v.maybe_null(arg) then var value = v.new_var(self.mpropdef.static_mtype.as(not null)) v.add("if ({arg} == NULL) \{") v.assign(value, evaluate_expr(v, recv)) @@ -3645,7 +3645,7 @@ redef class AOrElseExpr var res = v.new_var(self.mtype.as(not null)) var i1 = v.expr(self.n_expr, null) - if not v.maybenull(i1) then return i1 + if not v.maybe_null(i1) then return i1 v.add("if ({i1}!=NULL) \{") v.assign(res, i1) @@ -3898,7 +3898,7 @@ redef class AAsNotnullExpr var i = v.expr(self.n_expr, null) if v.compiler.modelbuilder.toolcontext.opt_no_check_assert.value then return i - if not v.maybenull(i) then return i + if not v.maybe_null(i) then return i v.add("if (unlikely({i} == NULL)) \{") v.add_abort("Cast failed") diff --git a/src/compiler/java_compiler.nit b/src/compiler/java_compiler.nit index f871f61..60aea2b 100644 --- a/src/compiler/java_compiler.nit +++ b/src/compiler/java_compiler.nit @@ -1301,7 +1301,7 @@ redef class MType # Is the associated Java type a primitive one? # - # ENSURE `result == (java_type != "Object")` + # ENSURE `result == (java_type != "RTVal")` var is_java_primitive: Bool is lazy do return java_type != "RTVal" end diff --git a/src/compiler/separate_compiler.nit b/src/compiler/separate_compiler.nit index e486b64..45790b3 100644 --- a/src/compiler/separate_compiler.nit +++ b/src/compiler/separate_compiler.nit @@ -1405,7 +1405,7 @@ class SeparateCompilerVisitor var res: nullable RuntimeVariable = null var recv = arguments.first var consider_null = not self.compiler.modelbuilder.toolcontext.opt_no_check_null.value or mmethod.name == "==" or mmethod.name == "!=" - if maybenull(recv) and consider_null then + if maybe_null(recv) and consider_null then self.add("if ({recv} == NULL) \{") if mmethod.name == "==" or mmethod.name == "is_same_instance" then res = self.new_var(bool_type) @@ -2061,12 +2061,6 @@ class SeparateCompilerVisitor return k == interface_kind or t.is_c_primitive end - fun maybe_null(value: RuntimeVariable): Bool - do - var t = value.mcasttype - return t isa MNullableType or t isa MNullType - end - redef fun array_instance(array, elttype) do var nclass = mmodule.native_array_class diff --git a/src/doc/console_templates/console_model.nit b/src/doc/console_templates/console_model.nit index 96b1a40..cacac49 100644 --- a/src/doc/console_templates/console_model.nit +++ b/src/doc/console_templates/console_model.nit @@ -208,7 +208,6 @@ redef class MModule end redef class MClass - redef fun mdoc_or_fallback do return intro.mdoc redef fun cs_icon do return intro.cs_icon # Format: `Foo[E]` @@ -258,7 +257,6 @@ redef class MClass end redef class MClassDef - redef fun mdoc_or_fallback do return mdoc or else mclass.mdoc_or_fallback redef fun cs_icon do return "C" # Depends if `self` is an intro or not. @@ -339,7 +337,6 @@ redef class MClassDef end redef class MProperty - redef fun mdoc_or_fallback do return intro.mdoc redef fun cs_modifiers do return intro.cs_modifiers redef fun cs_declaration do return intro.cs_declaration redef fun cs_icon do return intro.cs_icon @@ -373,8 +370,6 @@ redef class MProperty end redef class MPropDef - redef fun mdoc_or_fallback do return mdoc or else mproperty.mdoc_or_fallback - # Depends if `self` is an intro or not. # # * If intro contains the visibility and kind. diff --git a/src/doc/html_templates/model_html.nit b/src/doc/html_templates/model_html.nit index 0310a9c..20ae4ed 100644 --- a/src/doc/html_templates/model_html.nit +++ b/src/doc/html_templates/model_html.nit @@ -155,8 +155,6 @@ redef class MModule end redef class MClass - redef fun mdoc_or_fallback do return intro.mdoc - # Format: `Foo[E]` redef var html_name is lazy do var tpl = new Template @@ -201,8 +199,6 @@ redef class MClass end redef class MClassDef - redef fun mdoc_or_fallback do return mdoc or else mclass.mdoc_or_fallback - # Depends if `self` is an intro or not. # # * If intro contains the visibility and kind. @@ -303,7 +299,6 @@ redef class MClassDef end redef class MProperty - redef fun mdoc_or_fallback do return intro.mdoc redef fun html_modifiers do return intro.html_modifiers redef fun html_declaration do return intro.html_declaration @@ -327,8 +322,6 @@ redef class MProperty end redef class MPropDef - redef fun mdoc_or_fallback do return mdoc or else mproperty.mdoc_or_fallback - # Depends if `self` is an intro or not. # # * If intro contains the visibility and kind. diff --git a/src/highlight.nit b/src/highlight.nit index 8dd1637..cf7c598 100644 --- a/src/highlight.nit +++ b/src/highlight.nit @@ -425,6 +425,13 @@ redef class MEntity end return (new HTMLTag("a")).attr("href", href).text(text) end + + # Append an entry for the doc in the given infobox + private fun add_doc_to_infobox(res: HInfoBox) + do + var mdoc = mdoc_or_fallback + if mdoc != null then mdoc.fill_infobox(res) + end end redef class MModule @@ -433,8 +440,7 @@ redef class MModule var res = new HInfoBox(v, "module {name}") res.href = v.hrefto(self) res.new_field("module").add(linkto(v)) - var mdoc = self.mdoc - if mdoc != null then mdoc.fill_infobox(res) + add_doc_to_infobox(res) if in_importation.greaters.length > 1 then var c = res.new_dropdown("imports", "{in_importation.greaters.length-1} modules") for x in in_importation.greaters do @@ -459,9 +465,7 @@ redef class MClassDef res.new_field("redef class").text(mclass.name) res.new_field("intro").add mclass.intro.linkto_text(v, "in {mclass.intro_mmodule.to_s}") end - var mdoc = self.mdoc - if mdoc == null then mdoc = mclass.intro.mdoc - if mdoc != null then mdoc.fill_infobox(res) + add_doc_to_infobox(res) var in_hierarchy = self.in_hierarchy if in_hierarchy == null then return res @@ -515,9 +519,7 @@ redef class MPropDef else res.new_field("intro").add mproperty.intro.linkto_text(v, "in {mproperty.intro.mclassdef}") end - var mdoc = self.mdoc - if mdoc == null then mdoc = mproperty.intro.mdoc - if mdoc != null then mdoc.fill_infobox(res) + add_doc_to_infobox(res) if mproperty.mpropdefs.length > 1 then var c = res.new_dropdown("redef", "redefinitions") for x in mproperty.mpropdefs do @@ -535,9 +537,7 @@ redef class MClassType var res = new HInfoBox(v, to_s) res.href = v.hrefto(self) res.new_field("class").add mclass.intro.linkto(v) - var mdoc = mclass.mdoc - if mdoc == null then mdoc = mclass.intro.mdoc - if mdoc != null then mdoc.fill_infobox(res) + add_doc_to_infobox(res) return res end redef fun linkto(v) @@ -551,9 +551,7 @@ redef class MVirtualType var res = new HInfoBox(v, to_s) res.href = v.hrefto(mproperty) var p = mproperty - var pd = p.intro - res.new_field("virtual type").add pd.linkto(v) - var mdoc = pd.mdoc + add_doc_to_infobox(res) if mdoc != null then mdoc.fill_infobox(res) return res end @@ -649,9 +647,7 @@ redef class CallSite else res.new_field("intro").add mproperty.intro.linkto_text(v, "in {mproperty.intro.mclassdef}") end - var mdoc = mpropdef.mdoc - if mdoc == null then mdoc = mproperty.intro.mdoc - if mdoc != null then mdoc.fill_infobox(res) + add_doc_to_infobox(res) return res end diff --git a/src/interpreter/naive_interpreter.nit b/src/interpreter/naive_interpreter.nit index 0ec406c..430af89 100644 --- a/src/interpreter/naive_interpreter.nit +++ b/src/interpreter/naive_interpreter.nit @@ -691,9 +691,10 @@ abstract class Instance # ASSERT: not self.mtype.is_anchored var mtype: MType - # return true if the instance is the true value. - # return false if the instance is the true value. - # else aborts + # Return `true` if the instance is the `true` value. + # + # Return `false` if the instance is the `false` value. + # Abort if the instance is not a boolean value. fun is_true: Bool do abort # Return true if `self` IS `o` (using the Nit semantic of is) diff --git a/src/model/mdoc.nit b/src/model/mdoc.nit index 2035b06..408e572 100644 --- a/src/model/mdoc.nit +++ b/src/model/mdoc.nit @@ -39,9 +39,13 @@ redef class MEntity # The documentation associated to the entity or their main nested entity. # - # MPackage fall-back to their root MGroup - # MGroup fall-back to their default_mmodule - # Other entities do not fall-back + # * `MPackage`s fall back to their root `MGroup`. + # * `MGroup`s fall back to their `default_mmodule`. + # * `MClass`es, `MClassDef`s, `MProperty`s and `MPropDef`s fall-back to + # their introducing definition. + # * `MClassType`s fall back to their wrapped `MClass`. + # * `MVirtualType`s fall back to their wrapped `MProperty`. + # * Other entities do not fall back. # # One may use `MDoc::original_mentity` to retrieve the original # source of the documentation. diff --git a/src/model/model.nit b/src/model/model.nit index 2243a88..c1c950e 100644 --- a/src/model/model.nit +++ b/src/model/model.nit @@ -103,6 +103,9 @@ redef class Model # The only null type var null_type = new MNullType(self) + # The only bottom type + var bottom_type: MBottomType = null_type.as_notnull + # Build an ordered tree with from `concerns` fun concerns_tree(mconcerns: Collection[MConcern]): ConcernsTree do var seen = new HashSet[MConcern] @@ -566,7 +569,12 @@ class MClass # Is `self` and abstract class? var is_abstract: Bool is lazy do return kind == abstract_kind - redef fun mdoc_or_fallback do return intro.mdoc_or_fallback + redef fun mdoc_or_fallback + do + # Don’t use `intro.mdoc_or_fallback` because it would create an infinite + # recursion. + return intro.mdoc + end end @@ -725,6 +733,8 @@ class MClassDef # All property introductions and redefinitions (not inheritance) in `self` by its associated property. var mpropdefs_by_property = new HashMap[MProperty, MPropDef] + + redef fun mdoc_or_fallback do return mdoc or else mclass.mdoc_or_fallback end # A global static type @@ -898,15 +908,16 @@ abstract class MType # # Explanation of the example: # In H, T is set to B, because "H super G[B]", and U is bound to Y, - # because "redef type U: Y". Therefore, Map[T, U] is bound to + # because "redef type U: Y". Therefore, Map[T, U] is bound to # Map[B, Y] # + # REQUIRE: `self.need_anchor implies anchor != null` # ENSURE: `not self.need_anchor implies result == self` # ENSURE: `not result.need_anchor` - fun anchor_to(mmodule: MModule, anchor: MClassType): MType + fun anchor_to(mmodule: MModule, anchor: nullable MClassType): MType do if not need_anchor then return self - assert not anchor.need_anchor + assert anchor != null and not anchor.need_anchor # Just resolve to the anchor and clear all the virtual types var res = self.resolve_for(anchor, null, mmodule, true) assert not res.need_anchor @@ -1136,6 +1147,7 @@ abstract class MType # * H[G[A], B] -> 3 # # Formal types have a depth of 1. + # Only `MClassType` and `MFormalType` nodes are counted. fun depth: Int do return 1 @@ -1149,6 +1161,7 @@ abstract class MType # * H[G[A], B] -> 4 # # Formal types have a length of 1. + # Only `MClassType` and `MFormalType` nodes are counted. fun length: Int do return 1 @@ -1215,7 +1228,7 @@ class MClassType redef fun need_anchor do return false - redef fun anchor_to(mmodule: MModule, anchor: MClassType): MClassType + redef fun anchor_to(mmodule, anchor): MClassType do return super.as(MClassType) end @@ -1295,6 +1308,7 @@ class MClassType private var collect_mclasses_cache = new HashMap[MModule, Set[MClass]] private var collect_mtypes_cache = new HashMap[MModule, Set[MClassType]] + redef fun mdoc_or_fallback do return mclass.mdoc_or_fallback end # A type based on a generic class. @@ -1525,6 +1539,8 @@ class MVirtualType redef fun full_name do return self.mproperty.full_name redef fun c_name do return self.mproperty.c_name + + redef fun mdoc_or_fallback do return mproperty.mdoc_or_fallback end # The type associated to a formal parameter generic type of a class @@ -1809,7 +1825,7 @@ class MNullType redef fun c_name do return "null" redef fun as_nullable do return self - redef var as_notnull = new MBottomType(model) is lazy + redef var as_notnull: MBottomType = new MBottomType(model) is lazy redef fun need_anchor do return false redef fun resolve_for(mtype, anchor, mmodule, cleanup_virtual) do return self redef fun can_resolve_for(mtype, anchor, mmodule) do return true @@ -2049,7 +2065,12 @@ abstract class MProperty redef var location - redef fun mdoc_or_fallback do return intro.mdoc_or_fallback + redef fun mdoc_or_fallback + do + # Don’t use `intro.mdoc_or_fallback` because it would create an infinite + # recursion. + return intro.mdoc + end # The canonical name of the property. # @@ -2471,6 +2492,8 @@ abstract class MPropDef assert has_next_property: i.is_ok return i.item end + + redef fun mdoc_or_fallback do return mdoc or else mproperty.mdoc_or_fallback end # A local definition of a method diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index 0bbe61b..d5cbb46 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -81,11 +81,6 @@ private class TypeVisitor fun anchor_to(mtype: MType): MType do - var anchor = anchor - if anchor == null then - assert not mtype.need_anchor - return mtype - end return mtype.anchor_to(mmodule, anchor) end diff --git a/src/testing/testing_doc.nit b/src/testing/testing_doc.nit index b3e9c44..a17c8ab 100644 --- a/src/testing/testing_doc.nit +++ b/src/testing/testing_doc.nit @@ -263,7 +263,7 @@ class NitUnitExecutor f.write("# GENERATED FILE\n") f.write("# Docunits extracted from comments\n") if mmodule != null then - f.write("import {mmodule.name}\n") + f.write("intrude import {mmodule.name}\n") end f.write("\n") return f diff --git a/tests/sav/error_class_glob.res b/tests/sav/error_class_glob.res index d10f6b8..cccf1b2 100644 --- a/tests/sav/error_class_glob.res +++ b/tests/sav/error_class_glob.res @@ -9,5 +9,5 @@ ../lib/core/kernel.nit:601,1--705,3: Error: `kernel$Byte` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? ../lib/core/kernel.nit:707,1--885,3: Error: `kernel$Int` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? ../lib/core/kernel.nit:887,1--1055,3: Error: `kernel$Char` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:1057,1--1071,3: Error: `kernel$Pointer` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:1073,1--1082,3: Error: `kernel$Task` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? +../lib/core/kernel.nit:1057,1--1074,3: Error: `kernel$Pointer` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? +../lib/core/kernel.nit:1076,1--1085,3: Error: `kernel$Task` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? diff --git a/tests/sav/nituml_args3.res b/tests/sav/nituml_args3.res index adfe62c..d98d744 100644 --- a/tests/sav/nituml_args3.res +++ b/tests/sav/nituml_args3.res @@ -68,7 +68,7 @@ Char [ Discrete -> Char [dir=back arrowtail=open style=dashed]; Pointer [ - label = "{Pointer||+ address_is_null(): Bool\l+ free()\l- native_equals(o: Pointer): Bool\l}" + label = "{Pointer||+ nul(): Pointer\l+ address_is_null(): Bool\l+ free()\l- native_equals(o: Pointer): Bool\l}" ] Object -> Pointer [dir=back arrowtail=open style=dashed]; diff --git a/tests/sav/nituml_args4.res b/tests/sav/nituml_args4.res index e6a1e8c..10ba4a8 100644 --- a/tests/sav/nituml_args4.res +++ b/tests/sav/nituml_args4.res @@ -68,7 +68,7 @@ Char [ Discrete -> Char [dir=back arrowtail=open style=dashed]; Pointer [ - label = "{Pointer||+ address_is_null(): Bool\l+ free()\l}" + label = "{Pointer||+ nul(): Pointer\l+ address_is_null(): Bool\l+ free()\l}" ] Object -> Pointer [dir=back arrowtail=open style=dashed];