Refactor world/ #74

Open
opened 2022-08-08 16:13:54 +02:00 by kazhnuz · 13 comments
Owner

The world system is an important part of the scene system, but have a lot of issues

  • The duplication of 2D/3D actor make it kinda difficult to use
  • The "base" actor is a mixin. That's a bit ugly tbf
  • 2D actor must have a z and d variables interally, but act weird related to that
  • A lot of world functions are duplicated with just x, y, z added
  • Difficult to really add new type of world (for instance a mode7 one, or maybe even later a full3D one with love3D or similar)
  • Add its own libs. Same for maps
The world system is an important part of the scene system, but have a lot of issues - The duplication of 2D/3D actor make it kinda difficult to use - The "base" actor is a mixin. That's a bit ugly tbf - 2D actor must have a z and d variables interally, but act weird related to that - A lot of world functions are duplicated with just x, y, z added - Difficult to really add new type of world (for instance a mode7 one, or maybe even later a full3D one with love3D or similar) - Add its own libs. Same for maps
kazhnuz added this to the epervier 0.8.0 (beta 1) milestone 2022-08-08 16:13:54 +02:00
kazhnuz added the
1. Bug
1. Improvement
3. Need investigation
2. Epic
4. Scenes
labels 2022-08-08 16:13:55 +02:00
Author
Owner

What would be nice:

  • Move "positions" to being a table ( {x=1, y=4, z=3} ) instead of each position taking a slot, which should unify a lot of API
  • Do the same with dimensions ( {h=1,w=3,d=4} ).
  • Try to unify API of 2D and 3D hitboxes (using the new table position/dimensions API) in order to be able to launch the same object in 2D/3D mode (maybe with an autodection from the world)
  • Put handling of bodies/shape/terrain in a sub-class with a simplified/unified API.
  • Give the ability to give both an axis and a speed to gravity (for instance world.physics:setGravity(z, -4)).

Later possibilities :

  • Add a "renderer" sub-class which would render the actors from the map, maybe even taking care of drawing them, if we go totally that road, same for calling the map.
What would be nice: - Move "positions" to being a table ( `{x=1, y=4, z=3}` ) instead of each position taking a slot, which should unify a lot of API - Do the same with dimensions ( `{h=1,w=3,d=4}` ). - Try to unify API of 2D and 3D hitboxes (using the new table position/dimensions API) in order to be able to launch the same object in 2D/3D mode (maybe with an autodection from the world) - Put handling of bodies/shape/terrain in a sub-class with a simplified/unified API. - Give the ability to give both an axis and a speed to gravity (for instance `world.physics:setGravity(z, -4)`). **Later possibilities :** - Add a "renderer" sub-class which would render the actors from the map, maybe even taking care of drawing them, if we go totally that road, same for calling the map.
Author
Owner

Having a "utils.position" could be nice, with stuff like. Maybe an utils.dimensions would be usefull too ?

utils.position.verify()
utils.position.merge(position1, position2) -- for very position, return x+x if both are here, else the one present
utils.position.replace(position1, position2) -- use every present position in position2 to replace those of position1

Those API would also be added in the Point/Point3D classes:

Having a "utils.position" could be nice, with stuff like. Maybe an utils.dimensions would be usefull too ? ```lua utils.position.verify() utils.position.merge(position1, position2) -- for very position, return x+x if both are here, else the one present utils.position.replace(position1, position2) -- use every present position in position2 to replace those of position1 ``` Those API would also be added in the Point/Point3D classes:
Author
Owner

This would affect the GUI too, moving it to the position API

This would affect the GUI too, moving it to the position API
Author
Owner

Same for assets, now I think about it... Maybe it should be done for 0.7.0 then ?

Same for assets, now I think about it... Maybe it should be done for 0.7.0 then ?
kazhnuz modified the milestone from epervier 0.8.0 (beta 1) to epervier 0.7.0 2022-08-10 13:01:40 +02:00
Author
Owner

Maybe even the "position" of an actor should be handled by the hitbox system ? An actor would just be a collection of hitbox tied together, which would allow to refactor them a lot, with then some elements added on top of that (like a sprite system, etc)

It might be even be interesting to "fuse" the hitbox and physics system in a "body" system that would handle

  • Speed/movement
  • Gravity
  • Hitboxes
  • Collisions
  • Etc
Maybe even the "position" of an actor should be handled by the hitbox system ? An actor would just be a collection of hitbox tied together, which would allow to refactor them a lot, with then some elements added on top of that (like a sprite system, etc) It might be even be interesting to "fuse" the hitbox and physics system in a "body" system that would handle - Speed/movement - Gravity - Hitboxes - Collisions - Etc
Author
Owner
actor -- the actor, handle everything
  .body -- a collection of hitboxes
    .speed -- a position which symbolise where the actor will be in one second compared to this current position.
    .friction -- a "counter force" symbolized by a number
      .value -- how much of your speed you loose each turn
      .ignoredAxis -- the axis ignored by the friction
    .gravity --
      .value -- value
      .axis -- the axis affected by gravity (just one)
    .isSolid -- if the object is solid
    .hitboxes
    	[main] -- the main hitboxes which will be affected by the speed and stuff. All other hitboxes have their position derived from this one.
  .visual -- a basic way of handling an actor visual. Will contain some simple API for some common visual (charset, "3DBoxes", sprites, a simple rectangle, a tile of a tileset, etc)
        
    
```lua actor -- the actor, handle everything .body -- a collection of hitboxes .speed -- a position which symbolise where the actor will be in one second compared to this current position. .friction -- a "counter force" symbolized by a number .value -- how much of your speed you loose each turn .ignoredAxis -- the axis ignored by the friction .gravity -- .value -- value .axis -- the axis affected by gravity (just one) .isSolid -- if the object is solid .hitboxes [main] -- the main hitboxes which will be affected by the speed and stuff. All other hitboxes have their position derived from this one. .visual -- a basic way of handling an actor visual. Will contain some simple API for some common visual (charset, "3DBoxes", sprites, a simple rectangle, a tile of a tileset, etc) ```
Author
Owner

Maybe a "no-hitbox" mode would be interesting for gfx and stuff like that.

Maybe a "no-hitbox" mode would be interesting for gfx and stuff like that.
Author
Owner

Incrémental steps:

  • [WORLD] Auto-detect scene
  • [ACTOR] Auto-detect current world (and fail epicly if no world).
  • [ACTOR] Get type from object-level variables/definitions (and as much config as possible ?).
  • [WORLD] World-level definitions.
  • [GFX] Remove centering of GFX.
  • [UTILS] Create position/geometry utils.
  • [CLASSES] Add new geometry classes.
  • [ACTOR+SPRITE] Transform sprite scaling into a 2D position
  • [ACTOR] Extract hitboxes into a simple class.
  • [ACTOR] Use a structure for hitboxes instead of the current list system.
  • [ACTOR] Use position API (and switch to geometry classes) + same for hitboxes.
    • [ACTOR] Extract hitboxes "datas" into a position and an area
  • [WORLD] Extract bump2D/3D manager into another class ("physics", which will also handle global gravity and friction).
  • [ACTOR+WORLD] Hitbox object and position class used come from "physics" class
  • [ACTOR] Coordinate and speed as positions.
  • [ACTOR+WORLD] Gravity axis.
  • [ACTOR+WORLD] New frictions.
  • [ACTOR] Use rect for hitboxes, and see how to link them well to main position (or in a "position" var/object ?)
  • [WORLD] Renderers (merge with camera system)
  • [ACTOR] Terrains (rework the current terrain system).
  • [ACTOR] Visuals (including shapes).
  • [WORLD] Just one world.
  • [ACTOR] Just one actor.

Other things

  • Better camera views ? => Part of the renderer system
  • Port at the same times world exemple, will help stuff

Future evolution it'll help

  • Cylinders/Circle collisions world
  • Mode 7 world
  • Real (but simplistic, SuperFX/32x/DS level) 3D World
  • Radial Position (distance, angle, vertical_angle) (that would just be converted to point internally)
Incrémental steps: - [x] \[WORLD\] Auto-detect scene - [x] \[ACTOR\] Auto-detect current world (and fail epicly if no world). - [x] \[ACTOR\] Get type from object-level variables/definitions (and as much config as possible ?). - [ ] \[WORLD\] World-level definitions. - [ ] \[GFX\] Remove centering of GFX. - [ ] \[UTILS\] Create position/geometry utils. - [ ] \[CLASSES\] Add new geometry classes. - [ ] \[ACTOR+SPRITE\] Transform sprite scaling into a 2D position - [ ] \[ACTOR\] Extract hitboxes into a simple class. - [ ] \[ACTOR\] Use a structure for hitboxes instead of the current list system. - [ ] \[ACTOR\] Use position API (and switch to geometry classes) + same for hitboxes. - [ ] \[ACTOR\] Extract hitboxes "datas" into a position and an area - [ ] \[WORLD\] Extract bump2D/3D manager into another class ("physics", which will also handle global gravity and friction). - [ ] \[ACTOR+WORLD\] Hitbox object and position class used come from "physics" class - [ ] \[ACTOR\] Coordinate and speed as positions. - [ ] \[ACTOR+WORLD\] Gravity axis. - [ ] \[ACTOR+WORLD\] New frictions. - [ ] \[ACTOR\] Use rect for hitboxes, and see how to link them well to main position (or in a "position" var/object ?) - [ ] \[WORLD\] Renderers (merge with camera system) - [ ] \[ACTOR\] Terrains (rework the current terrain system). - [ ] \[ACTOR\] Visuals (including shapes). - [ ] \[WORLD\] Just one world. - [ ] \[ACTOR\] Just one actor. Other things - Better camera views ? => Part of the renderer system - Port at the same times world exemple, will help stuff Future evolution it'll help - Cylinders/Circle collisions world - Mode 7 world - Real (but simplistic, SuperFX/32x/DS level) 3D World - Radial Position (distance, angle, vertical_angle) (that would just be converted to point internally)
Author
Owner

List of definitions

World-level

  • Gravity
    • value
    • axis
    • Objects follow gravity by default (false by default)
  • "world type" (for later)
  • List of collisions
  • List of Objects for the "obj" list
return {
  type = "2D",
  gravity = {axis = "y", value = 20},
  collisions = {
    wall = {isSolid = true, debugColor = {r = 0, g = 0, b = 0} },
    lava = {isSolid = true, damage = 40},
  },
  obj = {
    player = Obj.Player,
    coin = Obj.Coin,
    -- ...
  }
}

Object-level

  • Types (mandatory)
  • Dimensions (mandatory)
  • isSolid (optionnal, considered false if absent)
  • If it follow global gravs or not
  • Friction
  • bounceFactor
  • Sprites/visuals
Stuff.def = {
  type = "stuff",
  dimensions = {w = 16, h = 16},
  isSolid = false, -- false by default
  gravity = {axis = "y", value = 20}, -- can be "global"
  friction = {x = 0.4, y = 0.4},
  bounceFactor = 0,
  sprite = {name = "stuff", clone = false, origin = {x = 8, y = 8}}
}

( More stuff will be available to gizmos and collectibles, but that'll be for later )

### List of definitions #### World-level - Gravity - value - axis - Objects follow gravity by default (false by default) - "world type" (for later) - List of collisions - List of Objects for the "obj" list ```lua return { type = "2D", gravity = {axis = "y", value = 20}, collisions = { wall = {isSolid = true, debugColor = {r = 0, g = 0, b = 0} }, lava = {isSolid = true, damage = 40}, }, obj = { player = Obj.Player, coin = Obj.Coin, -- ... } } ``` #### Object-level - Types (mandatory) - Dimensions (mandatory) - isSolid (optionnal, considered false if absent) - If it follow global gravs or not - Friction - bounceFactor - Sprites/visuals ```lua Stuff.def = { type = "stuff", dimensions = {w = 16, h = 16}, isSolid = false, -- false by default gravity = {axis = "y", value = 20}, -- can be "global" friction = {x = 0.4, y = 0.4}, bounceFactor = 0, sprite = {name = "stuff", clone = false, origin = {x = 8, y = 8}} } ``` ( More stuff will be available to gizmos and collectibles, but that'll be for later )
kazhnuz removed the
3. Need investigation
label 2022-08-31 16:37:36 +02:00
Author
Owner

Maybe that it would be nice to make some aliases to easily create actors, like

local Actor = actor {
	parent = "scenes.gameplay.actors.test", --if there is a specific parent
	-- content of Actor.def
}

Which would need something like

function actor(def)
    local parent = "framework.scene.world.actor"
    if (def.parent ~= nil) then
    	parent = def.parent
        def.parent = nil
    end
    local Parent = require parent
    local Class = Parent:extend()

    Class.def = def
    return Class
end
Maybe that it would be nice to make some aliases to easily create actors, like ```lua local Actor = actor { parent = "scenes.gameplay.actors.test", --if there is a specific parent -- content of Actor.def } ``` Which would need something like ```lua function actor(def) local parent = "framework.scene.world.actor" if (def.parent ~= nil) then parent = def.parent def.parent = nil end local Parent = require parent local Class = Parent:extend() Class.def = def return Class end ```
Author
Owner

Changes:
-> Keep a mixin for handling speed/position instead of a sub-object for the moment.
-> Keep the current hitboxes system where all hitboxes are relative to the parent.

Changes: -> Keep a mixin for handling speed/position instead of a sub-object for the moment. -> Keep the current hitboxes system where all hitboxes are relative to the parent.
Author
Owner

-> Extract the hitboxes manager into a separate class too, it'll make the physics mixin a bit simpler

-> Extract the hitboxes manager into a separate class too, it'll make the physics mixin a bit simpler
Author
Owner

Would be a good occasion to remove every deprecated API (like the sprites API)

Would be a good occasion to remove every deprecated API (like the sprites API)
Sign in to join this conversation.
No description provided.