Skip to content

Commit

Permalink
Merge branch 'main' into movement-depending-on-time-instead-of-ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
agustinesco committed Jun 26, 2024
2 parents 22a2037 + 353f988 commit 1ea9cf4
Show file tree
Hide file tree
Showing 41 changed files with 1,055 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/arena-brazil-testing-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }}
NEWRELIC_APP_NAME: ${{ vars.NEWRELIC_APP_NAME }}
NEWRELIC_KEY: ${{ secrets.NEWRELIC_KEY }}
DBUS_SESSION_BUS_ADDRESS: ${{ vars.DBUS_SESSION_BUS_ADDRESS }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
run: |
set -ex
Expand All @@ -72,4 +73,5 @@ jobs:
SECRET_KEY_BASE=${SECRET_KEY_BASE} \
NEWRELIC_APP_NAME=${NEWRELIC_APP_NAME} \
NEWRELIC_KEY=${NEWRELIC_KEY} \
DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS} \
/home/${SSH_USERNAME}/deploy-script/deploy.sh
2 changes: 2 additions & 0 deletions .github/workflows/arena-europe-testing-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }}
NEWRELIC_APP_NAME: ${{ vars.NEWRELIC_APP_NAME }}
NEWRELIC_KEY: ${{ secrets.NEWRELIC_KEY }}
DBUS_SESSION_BUS_ADDRESS: ${{ vars.DBUS_SESSION_BUS_ADDRESS }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
run: |
set -ex
Expand All @@ -72,4 +73,5 @@ jobs:
SECRET_KEY_BASE=${SECRET_KEY_BASE} \
NEWRELIC_APP_NAME=${NEWRELIC_APP_NAME} \
NEWRELIC_KEY=${NEWRELIC_KEY} \
DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS} \
/home/${SSH_USERNAME}/deploy-script/deploy.sh
2 changes: 2 additions & 0 deletions .github/workflows/central-europe-testing-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
JWT_PRIVATE_KEY_BASE_64: ${{ secrets.JWT_PRIVATE_KEY_BASE_64 }}
NEWRELIC_APP_NAME: ${{ vars.NEWRELIC_APP_NAME }}
NEWRELIC_KEY: ${{ secrets.NEWRELIC_KEY }}
DBUS_SESSION_BUS_ADDRESS: ${{ vars.DBUS_SESSION_BUS_ADDRESS }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
run: |
set -ex
Expand All @@ -74,4 +75,5 @@ jobs:
JWT_PRIVATE_KEY_BASE_64=${JWT_PRIVATE_KEY_BASE_64} \
NEWRELIC_APP_NAME=${NEWRELIC_APP_NAME} \
NEWRELIC_KEY=${NEWRELIC_KEY} \
DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS} \
/home/${SSH_USERNAME}/deploy-script/deploy.sh
2 changes: 2 additions & 0 deletions .github/workflows/loadtest-brazil-client-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }}
NEWRELIC_APP_NAME: ${{ vars.NEWRELIC_APP_NAME_LOADTEST }}
NEWRELIC_KEY: ${{ secrets.NEWRELIC_KEY }}
DBUS_SESSION_BUS_ADDRESS: ${{ vars.DBUS_SESSION_BUS_ADDRESS }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
run: |
set -ex
Expand All @@ -90,4 +91,5 @@ jobs:
SECRET_KEY_BASE=${SECRET_KEY_BASE} \
NEWRELIC_APP_NAME=${NEWRELIC_APP_NAME} \
NEWRELIC_KEY=${NEWRELIC_KEY} \
DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS} \
/home/${SSH_USERNAME}/deploy-script/deploy.sh
2 changes: 2 additions & 0 deletions .github/workflows/loadtest-brazil-server-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }}
NEWRELIC_APP_NAME: ${{ vars.NEWRELIC_APP_NAME_LOADTEST }}
NEWRELIC_KEY: ${{ secrets.NEWRELIC_KEY }}
DBUS_SESSION_BUS_ADDRESS: ${{ vars.DBUS_SESSION_BUS_ADDRESS }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
run: |
set -ex
Expand All @@ -68,4 +69,5 @@ jobs:
SECRET_KEY_BASE=${SECRET_KEY_BASE} \
NEWRELIC_APP_NAME=${NEWRELIC_APP_NAME} \
NEWRELIC_KEY=${NEWRELIC_KEY} \
DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS} \
/home/${SSH_USERNAME}/deploy-script/deploy.sh
2 changes: 2 additions & 0 deletions .github/workflows/loadtest-europe-client-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }}
NEWRELIC_APP_NAME: ${{ vars.NEWRELIC_APP_NAME_LOADTEST }}
NEWRELIC_KEY: ${{ secrets.NEWRELIC_KEY }}
DBUS_SESSION_BUS_ADDRESS: ${{ vars.DBUS_SESSION_BUS_ADDRESS }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
run: |
set -ex
Expand All @@ -88,4 +89,5 @@ jobs:
SECRET_KEY_BASE=${SECRET_KEY_BASE} \
NEWRELIC_APP_NAME=${NEWRELIC_APP_NAME} \
NEWRELIC_KEY=${NEWRELIC_KEY} \
DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS} \
/home/${SSH_USERNAME}/deploy-script/deploy.sh
2 changes: 2 additions & 0 deletions .github/workflows/loadtest-europe-server-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }}
NEWRELIC_APP_NAME: ${{ vars.NEWRELIC_APP_NAME_LOADTEST }}
NEWRELIC_KEY: ${{ secrets.NEWRELIC_KEY }}
DBUS_SESSION_BUS_ADDRESS: ${{ vars.DBUS_SESSION_BUS_ADDRESS }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
run: |
set -ex
Expand All @@ -68,4 +69,5 @@ jobs:
SECRET_KEY_BASE=${SECRET_KEY_BASE} \
NEWRELIC_APP_NAME=${NEWRELIC_APP_NAME} \
NEWRELIC_KEY=${NEWRELIC_KEY} \
DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS} \
/home/${SSH_USERNAME}/deploy-script/deploy.sh
8 changes: 8 additions & 0 deletions apps/arena/lib/arena/game/player.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule Arena.Game.Player do
Module for interacting with Player entity
"""

alias Arena.Game.Crate
alias Arena.GameUpdater
alias Arena.GameTracker
alias Arena.Utils
Expand Down Expand Up @@ -175,6 +176,13 @@ defmodule Arena.Game.Player do
{auto_aim?, skill_direction} =
skill_params.target
|> Skill.maybe_auto_aim(skill, player, targetable_players(game_state.players))
|> case do
{false, _} ->
Skill.maybe_auto_aim(skill_params.target, skill, player, Crate.interactable_crates(game_state.crates))

auto_aim ->
auto_aim
end

execution_duration = calculate_duration(skill, player.position, skill_direction, auto_aim?)
Process.send_after(self(), {:block_actions, player.id}, execution_duration)
Expand Down
5 changes: 2 additions & 3 deletions apps/arena/lib/arena/game/skill.ex
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,10 @@ defmodule Arena.Game.Skill do
def maybe_auto_aim(%{x: x, y: y}, skill, player, entities) when x == 0.0 and y == 0.0 do
case skill.autoaim do
true ->
nearest_entity_position_in_range =
{use_autoaim?, nearest_entity_position_in_range} =
Physics.nearest_entity_position_in_range(player, entities, skill.max_autoaim_range)
|> maybe_normalize(not skill.can_pick_destination)

{nearest_entity_position_in_range != player.direction, nearest_entity_position_in_range}
{use_autoaim?, nearest_entity_position_in_range |> maybe_normalize(not skill.can_pick_destination)}

false ->
{false, player.direction |> maybe_normalize(not skill.can_pick_destination)}
Expand Down
10 changes: 9 additions & 1 deletion apps/arena/lib/arena/game_socket_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ defmodule Arena.GameSocketHandler do
defp handle_decoded_message(%{action_type: {:toggle_bots, _bots_params}}, state),
do: GameUpdater.toggle_bots(state.game_pid)

defp handle_decoded_message(%{action_type: {:change_tickrate, tickrate_params}}, state),
do: GameUpdater.change_tickrate(state.game_pid, tickrate_params.tickrate)

defp handle_decoded_message(_action_type, %{enable: false} = _state), do: nil

defp handle_decoded_message(
Expand Down Expand Up @@ -244,5 +247,10 @@ defmodule Arena.GameSocketHandler do
end
end

defp handle_decoded_message(_, _), do: nil
# We don't do anything in these messages, we already handle these actions when we have to in previous functions.
defp handle_decoded_message(%{action_type: {action, _}}, _state) when action in [:move, :attack, :use_item], do: nil

defp handle_decoded_message(message, _) do
Logger.info("Unexpected message: #{inspect(message)}")
end
end
8 changes: 8 additions & 0 deletions apps/arena/lib/arena/game_updater.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ defmodule Arena.GameUpdater do
GenServer.cast(game_pid, :toggle_bots)
end

def change_tickrate(game_pid, tickrate) do
GenServer.cast(game_pid, {:change_tickrate, tickrate})
end

##########################
# END API
##########################
Expand Down Expand Up @@ -168,6 +172,10 @@ defmodule Arena.GameUpdater do
{:noreply, state}
end

def handle_cast({:change_tickrate, tickrate}, state) do
{:noreply, put_in(state, [:game_config, :game, :tick_rate_ms], tickrate)}
end

##########################
# END API Callbacks
##########################
Expand Down
15 changes: 15 additions & 0 deletions apps/arena/lib/arena/serialization/messages.pb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,14 @@ defmodule Arena.Serialization.ToggleBots do
use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"
end

defmodule Arena.Serialization.ChangeTickrate do
@moduledoc false

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

field(:tickrate, 1, type: :int64)
end

defmodule Arena.Serialization.GameAction do
@moduledoc false

Expand All @@ -661,6 +669,13 @@ defmodule Arena.Serialization.GameAction do

field(:toggle_zone, 6, type: Arena.Serialization.ToggleZone, json_name: "toggleZone", oneof: 0)
field(:toggle_bots, 7, type: Arena.Serialization.ToggleBots, json_name: "toggleBots", oneof: 0)

field(:change_tickrate, 8,
type: Arena.Serialization.ChangeTickrate,
json_name: "changeTickrate",
oneof: 0
)

field(:timestamp, 3, type: :int64)
end

Expand Down
6 changes: 4 additions & 2 deletions apps/arena/native/physics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,13 @@ fn nearest_entity_position_in_range(
entity: Entity,
entities: HashMap<u64, Entity>,
range: i64,
) -> Position {
) -> (bool, Position) {
let mut max_distance = range as f32;
let mut position = Position {
x: entity.direction.x,
y: entity.direction.y,
};
let mut use_autoaim: bool = false;

for other_entity in entities.values() {
if entity.id != other_entity.id {
Expand All @@ -163,11 +164,12 @@ fn nearest_entity_position_in_range(
x: difference_between_positions.x,
y: difference_between_positions.y,
};
use_autoaim = true;
}
}
}

position
(use_autoaim, position)
}
#[rustler::nif()]
fn distance_between_entities(entity_a: Entity, entity_b: Entity) -> f32 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,14 @@ defmodule ArenaLoadTest.Serialization.ToggleBots do
use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"
end

defmodule ArenaLoadTest.Serialization.ChangeTickrate do
@moduledoc false

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

field(:tickrate, 1, type: :int64)
end

defmodule ArenaLoadTest.Serialization.GameAction do
@moduledoc false

Expand Down Expand Up @@ -718,6 +726,12 @@ defmodule ArenaLoadTest.Serialization.GameAction do
oneof: 0
)

field(:change_tickrate, 8,
type: ArenaLoadTest.Serialization.ChangeTickrate,
json_name: "changeTickrate",
oneof: 0
)

field(:timestamp, 3, type: :int64)
end

Expand Down
15 changes: 15 additions & 0 deletions apps/bot_manager/lib/protobuf/messages.pb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,14 @@ defmodule BotManager.Protobuf.ToggleBots do
use Protobuf, syntax: :proto3, protoc_gen_elixir_version: "0.12.0"
end

defmodule BotManager.Protobuf.ChangeTickrate do
@moduledoc false

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

field(:tickrate, 1, type: :int64)
end

defmodule BotManager.Protobuf.GameAction do
@moduledoc false

Expand All @@ -661,6 +669,13 @@ defmodule BotManager.Protobuf.GameAction do

field(:toggle_zone, 6, type: BotManager.Protobuf.ToggleZone, json_name: "toggleZone", oneof: 0)
field(:toggle_bots, 7, type: BotManager.Protobuf.ToggleBots, json_name: "toggleBots", oneof: 0)

field(:change_tickrate, 8,
type: BotManager.Protobuf.ChangeTickrate,
json_name: "changeTickrate",
oneof: 0
)

field(:timestamp, 3, type: :int64)
end

Expand Down
104 changes: 104 additions & 0 deletions apps/configurator/lib/configurator/configuration.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
defmodule Configurator.Configuration do
@moduledoc """
The Configuration context.
"""

import Ecto.Query, warn: false
alias Configurator.Repo

alias Configurator.Configuration.Character

@doc """
Returns the list of characters.
## Examples
iex> list_characters()
[%Character{}, ...]
"""
def list_characters do
Repo.all(Character)
end

@doc """
Gets a single character.
Raises `Ecto.NoResultsError` if the Character does not exist.
## Examples
iex> get_character!(123)
%Character{}
iex> get_character!(456)
** (Ecto.NoResultsError)
"""
def get_character!(id), do: Repo.get!(Character, id)

@doc """
Creates a character.
## Examples
iex> create_character(%{field: value})
{:ok, %Character{}}
iex> create_character(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_character(attrs \\ %{}) do
%Character{}
|> Character.changeset(attrs)
|> Repo.insert()
end

@doc """
Updates a character.
## Examples
iex> update_character(character, %{field: new_value})
{:ok, %Character{}}
iex> update_character(character, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_character(%Character{} = character, attrs) do
character
|> Character.changeset(attrs)
|> Repo.update()
end

@doc """
Deletes a character.
## Examples
iex> delete_character(character)
{:ok, %Character{}}
iex> delete_character(character)
{:error, %Ecto.Changeset{}}
"""
def delete_character(%Character{} = character) do
Repo.delete(character)
end

@doc """
Returns an `%Ecto.Changeset{}` for tracking character changes.
## Examples
iex> change_character(character)
%Ecto.Changeset{data: %Character{}}
"""
def change_character(%Character{} = character, attrs \\ %{}) do
Character.changeset(character, attrs)
end
end
Loading

0 comments on commit 1ea9cf4

Please sign in to comment.