Skip to content

Commit

Permalink
add test workflow ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyx14 committed Oct 5, 2023
1 parent 7678d92 commit f87f48b
Show file tree
Hide file tree
Showing 80 changed files with 1,458 additions and 1,074 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
text eol=lf
105 changes: 105 additions & 0 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
name: Build - Ubuntu

on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'src/**'
push:
paths:
- 'src/**'
branches:
- main

env:
CMAKE_BUILD_PARALLEL_LEVEL: 2
MAKEFLAGS: '-j 2'

jobs:
job:
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
name: ${{ matrix.os }}-${{ matrix.buildtype }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
buildtype: [linux-release, linux-debug]
include:
- os: ubuntu-20.04
triplet: x64-linux
- os: ubuntu-22.04
triplet: x64-linux

steps:
- name: Cancel Previous Runs
if: github.ref != 'refs/heads/main'
uses: fkirc/skip-duplicate-actions@master
with:
concurrent_skipping: 'same_content'
cancel_others: true

- name: Checkout repository
uses: actions/checkout@main

- name: Install Linux Dependencies
run: >
sudo apt-get update && sudo apt-get install ccache linux-headers-$(uname -r)
- name: Switch to gcc-11
if: matrix.os == 'ubuntu-20.04'
run: |
sudo apt install gcc-11 g++-11
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11
sudo update-alternatives --set gcc /usr/bin/gcc-11
- name: CCache
uses: hendrikmuhs/ccache-action@main
with:
max-size: "1G"
key: ccache-${{ matrix.os }}-${{ matrix.buildtype }}
restore-keys: |
ccache-${{ matrix.os }}
- name: Restore artifacts and install vcpkg
id: vcpkg-step
run: |
vcpkgCommitId=$(grep '.builtin-baseline' vcpkg.json | awk -F: '{print $2}' | tr -d '," ')
echo "vcpkg commit ID: $vcpkgCommitId"
echo "VCPKG_GIT_COMMIT_ID=$vcpkgCommitId" >> $GITHUB_ENV
- name: Get vcpkg commit id from vcpkg.json
uses: lukka/run-vcpkg@main
with:
vcpkgGitURL: "https://github.com/microsoft/vcpkg.git"
vcpkgGitCommitId: ${{ env.VCPKG_GIT_COMMIT_ID }}

- name: Get latest CMake and ninja
uses: lukka/get-cmake@main

- name: Run CMake
uses: lukka/run-cmake@main
with:
configurePreset: ${{ matrix.buildtype }}
buildPreset: ${{ matrix.buildtype }}
configurePresetAdditionalArgs: "['-DBUILD_TESTS=ON']"

- name: Create and Upload Artifact
uses: actions/upload-artifact@main
with:
name: canary-${{ matrix.os }}-${{ matrix.buildtype }}-${{ github.sha }}
path: |
${{ github.workspace }}/build/${{ matrix.buildtype }}/bin/
- name: Run Unit Tests
run: |
cd ${{ github.workspace }}/build/${{ matrix.buildtype }}/tests/unit
ctest --verbose
# - name: Run Integration Tests
# run: |
# cd ${{ github.workspace }}/build/${{ matrix.buildtype }}/tests/integration
# ctest --verbose
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [ "Windows" ]
"hostOS": ["Windows"]
}
},
"condition": {
Expand Down
2 changes: 2 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ onlyPremiumAccount = false
-- NOTE: buyAolCommandFee will add fee when player buy aol by command (!aol), active changing value more than 0 (fee value. ex: 1 = 1gp aol will be 50001)
-- NOTE: buyBlessCommandFee will add fee when player buy bless by command (!bless), active changing value between 1 and 100 (fee percent. ex: 3 = 3%, 30 = 30%)
-- NOTE: teleportPlayerToVocationRoom will enable oressa to teleport player to his/her room vocation
-- NOTE: toggleReceiveReward = true, will enable players to choose one of reward exercise weapon by command !reward
weatherRain = false
thunderEffect = false
allConsoleLog = false
Expand All @@ -200,6 +201,7 @@ toggleTravelsFree = false
buyAolCommandFee = 0
buyBlessCommandFee = 0
teleportPlayerToVocationRoom = true
toggleReceiveReward = false

-- Teleport summon
-- Set to true will never remove the summon
Expand Down
2 changes: 2 additions & 0 deletions src/config/config_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ enum booleanConfig_t {
TOGGLE_MOUNT_IN_PZ,
TOGGLE_HOUSE_TRANSFER_ON_SERVER_RESTART,

TOGGLE_RECEIVE_REWARD,

LAST_BOOLEAN_CONFIG
};

Expand Down
3 changes: 2 additions & 1 deletion src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "config/configmanager.hpp"
#include "declarations.hpp"
#include "game/game.hpp"
#include "lua/scripts/luajit_sync.hpp"
#include "server/network/webhook/webhook.hpp"

#if LUA_VERSION_NUM >= 502
Expand Down Expand Up @@ -393,6 +392,8 @@ bool ConfigManager::load() {

boolean[TOGGLE_HOUSE_TRANSFER_ON_SERVER_RESTART] = getGlobalBoolean(L, "togglehouseTransferOnRestart", false);

boolean[TOGGLE_RECEIVE_REWARD] = getGlobalBoolean(L, "toggleReceiveReward", false);

loaded = true;
lua_close(L);
return true;
Expand Down
30 changes: 15 additions & 15 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "creatures/monsters/monster.hpp"
#include "creatures/monsters/monsters.hpp"
#include "items/weapons/weapons.hpp"
#include "map/spectators.hpp"

int32_t Combat::getLevelFormula(std::shared_ptr<Player> player, const std::shared_ptr<Spell> wheelSpell, const CombatDamage &damage) const {
if (!player) {
Expand Down Expand Up @@ -72,7 +73,7 @@ CombatDamage Combat::getCombatDamage(std::shared_ptr<Creature> creature, std::sh
);
} else if (formulaType == COMBAT_FORMULA_SKILL) {
std::shared_ptr<Item> tool = player->getWeapon();
const Weapon* weapon = g_weapons().getWeapon(tool);
const WeaponShared_ptr weapon = g_weapons().getWeapon(tool);
if (weapon) {
damage.primary.value = normal_random(
static_cast<int32_t>(minb),
Expand Down Expand Up @@ -754,7 +755,7 @@ void Combat::CombatNullFunc(std::shared_ptr<Creature> caster, std::shared_ptr<Cr
CombatDispelFunc(caster, target, params, nullptr);
}

void Combat::combatTileEffects(const SpectatorHashSet &spectators, std::shared_ptr<Creature> caster, std::shared_ptr<Tile> tile, const CombatParams &params) {
void Combat::combatTileEffects(const CreatureVector &spectators, std::shared_ptr<Creature> caster, std::shared_ptr<Tile> tile, const CombatParams &params) {
if (params.itemId != 0) {
uint16_t itemId = params.itemId;
switch (itemId) {
Expand Down Expand Up @@ -998,7 +999,6 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin
getCombatArea(pos, pos, area, tileList);
}

SpectatorHashSet spectators;
uint32_t maxX = 0;
uint32_t maxY = 0;

Expand All @@ -1019,7 +1019,6 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin

const int32_t rangeX = maxX + MAP_MAX_VIEW_PORT_X;
const int32_t rangeY = maxY + MAP_MAX_VIEW_PORT_Y;
g_game().map.getSpectators(spectators, pos, true, true, rangeX, rangeX, rangeY, rangeY);

int affected = 0;
for (std::shared_ptr<Tile> tile : tileList) {
Expand Down Expand Up @@ -1071,6 +1070,7 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin
}

// Wheel of destiny get beam affected total
auto spectators = Spectators().find<Player>(pos, true, rangeX, rangeX, rangeY, rangeY);
std::shared_ptr<Player> casterPlayer = caster ? caster->getPlayer() : nullptr;
uint8_t beamAffectedTotal = casterPlayer ? casterPlayer->wheel()->getBeamAffectedTotal(tmpDamage) : 0;
uint8_t beamAffectedCurrent = 0;
Expand Down Expand Up @@ -1110,7 +1110,7 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin
}
}
}
combatTileEffects(spectators, caster, tile, params);
combatTileEffects(spectators.data(), caster, tile, params);
}

// Wheel of destiny update beam mastery damage
Expand Down Expand Up @@ -1339,11 +1339,10 @@ void Combat::doCombatDefault(std::shared_ptr<Creature> caster, std::shared_ptr<C

void Combat::doCombatDefault(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const Position &origin, const CombatParams &params) {
if (!params.aggressive || (caster != target && Combat::canDoCombat(caster, target, params.aggressive) == RETURNVALUE_NOERROR)) {
SpectatorHashSet spectators;
g_game().map.getSpectators(spectators, target->getPosition(), true, true);
auto spectators = Spectators().find<Player>(target->getPosition(), true);

CombatNullFunc(caster, target, params, nullptr);
combatTileEffects(spectators, caster, target->getTile(), params);
combatTileEffects(spectators.data(), caster, target->getTile(), params);

if (params.targetCallback) {
params.targetCallback->onTargetCombat(caster, target);
Expand Down Expand Up @@ -1396,13 +1395,12 @@ std::vector<std::pair<Position, std::vector<uint32_t>>> Combat::pickChainTargets
const int maxBacktrackingAttempts = 10; // Can be adjusted as needed
while (!targets.empty() && targets.size() <= maxTargets) {
auto currentTarget = targets.back();
SpectatorHashSet spectators;
g_game().map.getSpectators(spectators, currentTarget->getPosition(), false, false, chainDistance, chainDistance, chainDistance, chainDistance);
auto spectators = Spectators().find<Creature>(currentTarget->getPosition(), false, chainDistance, chainDistance, chainDistance, chainDistance);
g_logger().debug("Combat::pickChainTargets: currentTarget: {}, spectators: {}", currentTarget->getName(), spectators.size());

double closestDistance = std::numeric_limits<double>::max();
std::shared_ptr<Creature> closestSpectator = nullptr;
for (std::shared_ptr<Creature> spectator : spectators) {
for (const auto &spectator : spectators) {
if (!spectator || visited.contains(spectator->getID())) {
continue;
}
Expand Down Expand Up @@ -1516,7 +1514,7 @@ void ValueCallback::getMinMaxValues(std::shared_ptr<Player> player, CombatDamage
case COMBAT_FORMULA_SKILL: {
// onGetPlayerMinMaxValues(player, attackSkill, attackValue, attackFactor)
std::shared_ptr<Item> tool = player->getWeapon();
const Weapon* weapon = g_weapons().getWeapon(tool);
const WeaponShared_ptr weapon = g_weapons().getWeapon(tool);
std::shared_ptr<Item> item = nullptr;

if (weapon) {
Expand Down Expand Up @@ -1770,13 +1768,15 @@ bool ChainPickerCallback::onChainCombat(std::shared_ptr<Creature> creature, std:
//**********************************************************//

void AreaCombat::clear() {
areas.clear();
std::ranges::fill(areas, nullptr);
}

AreaCombat::AreaCombat(const AreaCombat &rhs) {
hasExtArea = rhs.hasExtArea;
for (const auto &it : rhs.areas) {
areas[it.first] = it.second->clone();
for (uint_fast8_t i = 0; i <= Direction::DIRECTION_LAST; ++i) {
if (const auto &area = rhs.areas[i]) {
areas[i] = area->clone();
}
}
}

Expand Down
13 changes: 3 additions & 10 deletions src/creatures/combat/combat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class Spell;
class Player;
class MatrixArea;

static const std::unique_ptr<MatrixArea> &MatrixAreaNull {};

// for luascript callback
class ValueCallback final : public CallBack {
public:
Expand Down Expand Up @@ -247,15 +245,10 @@ class AreaCombat {
}
}

auto it = areas.find(dir);
if (it == areas.end()) {
return MatrixAreaNull;
}

return it->second;
return areas[dir];
}

std::map<Direction, std::unique_ptr<MatrixArea>> areas;
std::array<std::unique_ptr<MatrixArea>, Direction::DIRECTION_LAST + 1> areas {};
bool hasExtArea = false;
};

Expand Down Expand Up @@ -368,7 +361,7 @@ class Combat {
static void CombatDispelFunc(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const CombatParams &params, CombatDamage* data);
static void CombatNullFunc(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const CombatParams &params, CombatDamage* data);

static void combatTileEffects(const SpectatorHashSet &spectators, std::shared_ptr<Creature> caster, std::shared_ptr<Tile> tile, const CombatParams &params);
static void combatTileEffects(const CreatureVector &spectators, std::shared_ptr<Creature> caster, std::shared_ptr<Tile> tile, const CombatParams &params);

/**
* @brief Calculate the level formula for combat.
Expand Down
6 changes: 3 additions & 3 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "game/game.hpp"
#include "game/scheduling/dispatcher.hpp"
#include "io/fileloader.hpp"
#include "map/spectators.hpp"

/**
* Condition
Expand Down Expand Up @@ -1190,13 +1191,12 @@ bool ConditionRegeneration::executeCondition(std::shared_ptr<Creature> creature,
message.primary.color = TEXTCOLOR_PASTELRED;
player->sendTextMessage(message);

SpectatorHashSet spectators;
g_game().map.getSpectators(spectators, player->getPosition(), false, true);
auto spectators = Spectators().find<Player>(player->getPosition());
spectators.erase(player);
if (!spectators.empty()) {
message.type = MESSAGE_HEALED_OTHERS;
message.text = player->getName() + " was healed for " + healString;
for (std::shared_ptr<Creature> spectator : spectators) {
for (const auto &spectator : spectators) {
spectator->getPlayer()->sendTextMessage(message);
}
}
Expand Down
19 changes: 5 additions & 14 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "creatures/monsters/monster.hpp"
#include "game/scheduling/scheduler.hpp"
#include "game/zones/zone.hpp"
#include "map/spectators.hpp"

double Creature::speedA = 857.36;
double Creature::speedB = 261.29;
Expand Down Expand Up @@ -1201,8 +1202,7 @@ void Creature::onGainExperience(uint64_t gainExp, std::shared_ptr<Creature> targ
master->onGainExperience(gainExp, target);

if (!m->isFamiliar()) {
SpectatorHashSet spectators;
g_game().map.getSpectators(spectators, position, false, true);
auto spectators = Spectators().find<Player>(position);
if (spectators.empty()) {
return;
}
Expand All @@ -1212,7 +1212,7 @@ void Creature::onGainExperience(uint64_t gainExp, std::shared_ptr<Creature> targ
message.primary.color = TEXTCOLOR_WHITE_EXP;
message.primary.value = gainExp;

for (std::shared_ptr<Creature> spectator : spectators) {
for (const auto &spectator : spectators) {
spectator->getPlayer()->sendTextMessage(message);
}
}
Expand Down Expand Up @@ -1800,16 +1800,7 @@ void Creature::iconChanged() {
return;
}

SpectatorHashSet spectators;
g_game().map.getSpectators(spectators, tile->getPosition(), true);
for (auto spectator : spectators) {
if (!spectator) {
continue;
}

auto player = spectator->getPlayer();
if (player) {
player->sendCreatureIcon(getCreature());
}
for (const auto &spectator : Spectators().find<Player>(tile->getPosition(), true)) {
spectator->getPlayer()->sendCreatureIcon(getCreature());
}
}
Loading

0 comments on commit f87f48b

Please sign in to comment.