Code Monkey home page Code Monkey logo

ecspanse's People

Contributors

aedwardg avatar bastes avatar hl avatar holykol avatar iacobson avatar teifion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ecspanse's Issues

Query ancestors

The current queries permit searching for descendants entities.
Introduce also the possibility to query ancestors.

In the context of the Orbituary game, there are orbital ring entities, that have orbital nodes, that hold the players.
It would be useful to query the orbital ring directly starting from the player entity.

Missing parts in the tutorial

I believe some parts are missing in the tutorial. The demo repo provides some missing insight and I will keep updating this as I follow the tutorial:

The Ecspanse.Entity is missing in the tutorial from:
https://github.com/iacobson/ecspanse_demo/blob/ad29dc421b08435ff83fc81d82508e1a0f44c750/lib/demo/api.ex#L9

and is needed here: https://github.com/iacobson/ecspanse_demo/blob/ad29dc421b08435ff83fc81d82508e1a0f44c750/lib/demo/api.ex#L20

The function list_hero_resources/1 is in the tutorial but adding it to the fetch_hero_details/0 function under the resources key part is missing.

Will there be a monitoring dashboard

There's another Elixir ECS library called ECSx but it seems less full featured than Ecspanse. One thing that I do like about ECSx though is that it has a plugin for the Phoenix dashboard that shows how much time each of the systems are consuming so you can see if you've got systems that aren't finishing during their tick, etc.

ECSx dashboard

I've been playing with both of these and I think I'm going to try using Ecspanse first (love the name, btw).

Introduce Projections

The idea of the Projections is to enhance communication with external systems (eg. Phoenix, Livebook, etc.).

The Projection is a GenServer that queries the Ecspanse components and returns a struct. The queries run every frame, and if any change in the struct state happens, an optional on_update callback is triggered.

The callback for example, can do a PubSub push to a LiveView.

The projections are complex models based on various component queries.

Fetch commands don't have a nice error if the application isn't started

Obviously if the use Ecspanse module isn't started as part of the supervision tree you get something like this:

iex(2)> Durandal.Entities.Player.fetch()
** (ArgumentError) argument error
    (stdlib 5.2) :ets.select(:ets_ecspanse_components_state, [{{{:"$1", :"$2"}, :"$3", :"$4"}, [], [{{:"$1", :"$2"}}]}])
    (ecspanse 0.8.0) lib/ecspanse/util.ex:63: Ecspanse.Util.__list_entities_components_memoize/0
    (memoize 1.4.2) lib/memoize/cache.ex:111: Memoize.Cache.do_get_or_run/3
    (ecspanse 0.8.0) lib/ecspanse/query.ex:1002: Ecspanse.Query.filter_for_entities/1
    (ecspanse 0.8.0) lib/ecspanse/query.ex:214: Ecspanse.Query.stream/1
    (ecspanse 0.8.0) lib/ecspanse/query.ex:237: Ecspanse.Query.one/1
    (durandal 0.1.0) lib/durandal/entities/player.ex:16: Durandal.Entities.Player.fetch/0
    iex:2: (file)

For people brand new to the project who maybe missed that line at the start a more informative error message would be a nice pointer.

For context, the fetch command is from the tutorial (swap Hero for Player)

  def fetch do
    Ecspanse.Query.select({Ecspanse.Entity}, with: [Components.Owner])
    |> Ecspanse.Query.one()
    |> case do
      {%Ecspanse.Entity{} = entity} -> {:ok, entity}
      _ -> {:error, :not_found}
    end
  end

Tags optimizations

Looking for tags has a significant impact on the FPS.
TODO:

  • optimize the tag searching

UNRELATED:

  • deprecate the auto-generated events

Projections should be consistent

For performance reasons, projections were implemented to run in parallel with the systems, on every frame.
However, this offers no guarantee on the state of the components, as some systems may have run already, while others did not.

The solution is to move the projections update at the end of the frame after all systems are executed.

also, the on_change callback should receive both the new projection state, but also the previous.

Conditionally run projections

  • add an optional run?/2 callback to projections to skip running expensive projections if not in the correct state
  • if the callback is not implemented, the projection will run, so it is not a breaking change

`:ets.new(..., [..., write_concurrency: :auto])` only works with Erlang OTP-26

Hello,

Following the tutorial, I've generated a fresh new phoenix v1.7.11 with Ecspanse v0.8.1 on elixir v1.14.0 and with Erlang/OTP v24, and was surprised to get an error right after plugging the Ecspanse app in the application module:

** (Mix) Could not start application ecs: Ecs.Application.start(:normal, []) returned an error: shutdown: failed to start child: Ecs
    ** (EXIT) an exception was raised:
        ** (ArgumentError) errors were found at the given arguments:

  * 2nd argument: invalid options

            (stdlib 3.17.2.4) :ets.new(:ets_ecspanse_components_state, [:set, :public, :named_table, {:read_concurrency, true}, {:write_concurrency, :auto}])
            (ecspanse 0.8.1) lib/ecspanse/server.ex:134: Ecspanse.Server.init/1
            (stdlib 3.17.2.4) gen_server.erl:423: :gen_server.init_it/2
            (stdlib 3.17.2.4) gen_server.erl:390: :gen_server.init_it/6
            (stdlib 3.17.2.4) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

This led me to this line:

write_concurrency: :auto

    :ets.new(Util.components_state_ets_table(), [
      :set,
      :public,
      :named_table,
      read_concurrency: true,
      write_concurrency: :auto
    ])

From the :ets otp module, I see the :auto atom for write_concurrency has only been added in Erlang/OTP v26.

I'm going to restart using a later Elixir and Erlang/OTP v26, but I thought you might want to know in case you'd like backwards compatibility or something.

Implement Projections State

  • instead of returning the actual projection result, return an %Ecspanse.Projection{} that holds the result in a field.
  • another field should be the state of the projection

This can then be used in the templates to show part of the UI just if the projection is in a certain state

Tutorial issue

Something is wrong with the MoveHero system:

  @impl Ecspanse
  def setup(data) do
    data
    |> Ecspanse.add_startup_system(Systems.SpawnHero)
    |> Ecspanse.add_system(Systems.RestoreEnergy, run_if: [{__MODULE__, :energy_not_max}])
    |> Ecspanse.add_system(Systems.MoveHero, after: [Systems.RestoreEnergy])
    |> Ecspanse.add_frame_end_system(Ecspanse.System.Timer)
  end

I run Demo.API.move_hero(:up) many times but the hero only moves once or a few times.

This happens even when I clone the tutorial repo and run that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.