Skip to content

Commit

Permalink
fix: actually get all creature_movement
Browse files Browse the repository at this point in the history
for some reason, previous approach was only getting me 1 entry
  • Loading branch information
pikdum committed Sep 19, 2024
1 parent 8299c57 commit bf581b2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 0 additions & 2 deletions lib/behavior/wander.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
defmodule ThistleTea.WanderBehavior do
use GenServer

alias ThistleTea.Pathfinding

require Logger

def start_link(initial) do
Expand Down
5 changes: 5 additions & 0 deletions lib/spatial_hash.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ defmodule SpatialHash do
@cell_size 125
# TODO: benchmark different cell sizes

# TODO: benchmark some different options:
# - :write_concurrency
# - :read_concurrency
# - :decentralized_counters
# - :compressed: doesn't seem worth it, since data is small
def setup_tables do
:ets.new(:players, [:named_table, :public, :duplicate_bag])
:ets.new(:mobs, [:named_table, :public, :duplicate_bag])
Expand Down
20 changes: 17 additions & 3 deletions lib/state/mobsupervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,28 @@ defmodule ThistleTea.MobSupervisor do
from(c in Creature,
join: ct in assoc(c, :creature_template),
left_join: cm in assoc(c, :creature_movement),
preload: [creature_template: ct, creature_movement: cm],
where: c.modelid != 0,
select: c
select: {c, ct, cm}
)

children =
Mangos.all(query)
|> Enum.map(fn creature ->
# workaround since this wasn't working in ecto
|> Enum.group_by(fn {%{guid: guid}, _, _} -> guid end)
|> Enum.map(fn {_, entries} ->
{creature, creature_template, _} = List.first(entries)

movements =
entries
|> Enum.map(fn {_, _, cm} -> cm end)
|> Enum.filter(fn cm -> cm end)

creature = %Creature{
creature
| creature_template: creature_template,
creature_movement: movements
}

%{
id: {ThistleTea.Mob, creature.guid},
start: {ThistleTea.Mob, :start_link, [creature]}
Expand Down

0 comments on commit bf581b2

Please sign in to comment.