Skip to content

Commit

Permalink
Send delta for crates
Browse files Browse the repository at this point in the history
  • Loading branch information
AminArria committed Aug 30, 2024
1 parent e9f322d commit e143d64
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
3 changes: 1 addition & 2 deletions apps/arena/lib/arena/game_updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ defmodule Arena.GameUpdater do
state_diff =
Map.put(game_state, :obstacles, state_diff[:obstacles])
|> Map.put(:bushes, state_diff[:bushes])
|> Map.put(:crates, state_diff[:crates])

broadcast_game_update(state_diff, game_state.game_id)

Expand Down Expand Up @@ -726,8 +727,6 @@ defmodule Arena.GameUpdater do
})}
})

# %GameEvent{event: {:update, %{players: %{1 => %{position: decoded_position}}}}} = GameEvent.decode(encoded_state)
# IO.inspect(decoded_position, label: "decoded position")
IO.inspect(byte_size(encoded_state), label: "full byte_size")

PubSub.broadcast(Arena.PubSub, game_id, {:game_update, encoded_state})
Expand Down
16 changes: 11 additions & 5 deletions apps/arena/lib/arena/serialization/messages.pb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Arena.Serialization.ProjectileStatus do

use Protobuf, enum: true, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field :UNDEFINED, 0
field :PROJECTILE_STATUS_UNDEFINED, 0
field :ACTIVE, 1
field :EXPLODED, 2
field :CONSUMED, 3
Expand All @@ -25,8 +25,9 @@ defmodule Arena.Serialization.CrateStatus do

use Protobuf, enum: true, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field :FINE, 0
field :DESTROYED, 1
field :CRATE_STATUS_UNDEFINED, 0
field :FINE, 1
field :DESTROYED, 2
end

defmodule Arena.Serialization.PowerUpstatus do
Expand Down Expand Up @@ -599,8 +600,13 @@ defmodule Arena.Serialization.Crate do

use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"

field :health, 1, type: :uint64
field :amount_of_power_ups, 2, type: :uint64, json_name: "amountOfPowerUps"
field :health, 1, proto3_optional: true, type: :uint64

field :amount_of_power_ups, 2,
proto3_optional: true,
type: :uint64,
json_name: "amountOfPowerUps"

field :status, 3, type: Arena.Serialization.CrateStatus, enum: true
end

Expand Down
11 changes: 6 additions & 5 deletions apps/serialization/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ message Projectile {
}

enum ProjectileStatus {
UNDEFINED = 0;
PROJECTILE_STATUS_UNDEFINED = 0;
ACTIVE = 1;
EXPLODED = 2;
CONSUMED = 3;
Expand All @@ -258,14 +258,15 @@ message PowerUp {
}

message Crate {
uint64 health = 1;
uint64 amount_of_power_ups = 2;
optional uint64 health = 1;
optional uint64 amount_of_power_ups = 2;
CrateStatus status = 3;
}

enum CrateStatus {
FINE = 0;
DESTROYED = 1;
CRATE_STATUS_UNDEFINED = 0;
FINE = 1;
DESTROYED = 2;
}

enum PowerUpstatus {
Expand Down

0 comments on commit e143d64

Please sign in to comment.