Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: change shared_ptrs from copy to reference #2863

Open
wants to merge 61 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
655ec2d
init
beats-dh Jul 28, 2024
470cc87
up
beats-dh Jul 30, 2024
37aa37c
test
beats-dh Jul 31, 2024
4053cf8
improve
beats-dh Aug 1, 2024
ef024cb
fix crash
beats-dh Aug 2, 2024
5042d46
up
beats-dh Aug 4, 2024
c74a062
?
beats-dh Aug 15, 2024
c1d38ce
fix warnig and ative SIMD
beats-dh Aug 16, 2024
3219358
fix crash
beats-dh Aug 17, 2024
a1eca9c
test
beats-dh Aug 17, 2024
0b985aa
improve
beats-dh Aug 18, 2024
e399679
init
beats-dh Aug 17, 2024
ec43734
test
beats-dh Aug 24, 2024
e108c96
teste
beats-dh Aug 27, 2024
bd821b8
Update events.cpp
beats-dh Aug 29, 2024
c5a2b08
remove opemtelemetry lib metrics off
beats-dh Aug 30, 2024
b735dc1
Code format - (Clang-format)
github-actions[bot] Aug 31, 2024
467210d
Update qodana.yml
beats-dh Aug 31, 2024
87714c7
update
beats-dh Sep 1, 2024
a927fc3
update
beats-dh Sep 1, 2024
555c59a
fix exploit login
beats-dh Sep 1, 2024
727ffd6
update
beats-dh Sep 2, 2024
082eb72
update 07/09/2024
beats-dh Sep 8, 2024
8ff19f3
add atomic-queue connection
beats-dh Sep 11, 2024
bd4ef8b
update avx2 encrypt, decrypt and fix crash convertIP function
beats-dh Sep 11, 2024
486e880
update player online cycle
beats-dh Sep 11, 2024
2e4c0e7
fix crash
beats-dh Sep 11, 2024
429bccf
remove SIMD condition
beats-dh Sep 12, 2024
09ee5aa
new use atomic_queue in getOutputMessage
beats-dh Sep 13, 2024
9211e68
restore changes
beats-dh Sep 14, 2024
304b93d
up
beats-dh Sep 14, 2024
ff9ea35
up
beats-dh Sep 16, 2024
0480fda
up
beats-dh Sep 17, 2024
c876ec8
Code format - (Clang-format)
github-actions[bot] Sep 19, 2024
67575ab
up
beats-dh Sep 25, 2024
03dca05
fix build
beats-dh Sep 28, 2024
7d43c43
Code format - (Clang-format)
github-actions[bot] Sep 28, 2024
d68524c
fix
beats-dh Sep 29, 2024
e05caee
fix build
beats-dh Sep 29, 2024
14433a6
up
beats-dh Oct 1, 2024
dad1025
fix: some reverts and adjustments
dudantas Oct 16, 2024
edbfb8f
Merge branch 'main' into beats-fixs
dudantas Oct 16, 2024
174a763
fix: compilation errors conflicts
dudantas Oct 16, 2024
6e10a67
feat: some adjustments
dudantas Oct 16, 2024
b0d8af6
feat: some reverts
dudantas Oct 16, 2024
81eb200
fix
beats-dh Oct 17, 2024
e1fe506
feat: convert SpawnMonster to shared_ptr
dudantas Oct 17, 2024
f3caa03
fix: client debug
dudantas Oct 17, 2024
35f07c9
improve: some reverts and adjustments
dudantas Oct 17, 2024
9c89b04
improve: some reverts and others shared_ptr to const reference
dudantas Oct 17, 2024
71599eb
improve: change filestream/fileloader to std::ranges::copy
dudantas Oct 17, 2024
77449e0
fix: revert wrong
dudantas Oct 17, 2024
9c67268
Merge branch 'main' into beats-fixs
dudantas Oct 18, 2024
2979ca2
Merge branch 'main' into beats-fixs
dudantas Oct 18, 2024
7e4b62d
fix: sonar check and enum forward declaration
dudantas Oct 18, 2024
4021fdf
improve: fix some sonar check and ubuntu compilation
dudantas Oct 18, 2024
e3a924e
Code format - (Clang-format)
github-actions[bot] Oct 18, 2024
fb8c8a4
fix: some sonar checks
dudantas Oct 18, 2024
a49ce33
fix: sonar
dudantas Oct 18, 2024
652b969
Merge branch 'main' into beats-fixs
beats-dh Oct 31, 2024
668528e
Merge branch 'main' into beats-fixs
dudantas Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,4 @@ vcpkg_installed

# CLION
cmake-build-*
canary-debug
70 changes: 70 additions & 0 deletions cmake/modules/CheckSIMDSupport.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
include(CheckCXXCompilerFlag)

if(MSVC)
check_cxx_compiler_flag("/arch:AVX2" COMPILER_SUPPORTS_AVX2)
if(COMPILER_SUPPORTS_AVX2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX2")
add_definitions(-D__AVX2__ -D__SSE4_2__ -D__SSE4_1__ -D__SSE3__ -D__SSE2__ -D__SSE__)
log_option_enabled("AVX2: Advanced Vector Extensions 2 supported and enabled.")
elseif(COMPILER_SUPPORTS_AVX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:AVX")
add_definitions(-D__AVX__ -D__SSE4_2__ -D__SSE4_1__ -D__SSE3__ -D__SSE2__ -D__SSE__)
log_option_enabled("AVX: Advanced Vector Extensions supported and enabled.")
elseif(COMPILER_SUPPORTS_SSE42)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE4.2")
add_definitions(-D__SSE4_2__ -D__SSE4_1__ -D__SSE3__ -D__SSE2__ -D__SSE__)
log_option_enabled("SSE4.2: Streaming SIMD Extensions 4.2 supported and enabled.")
elseif(COMPILER_SUPPORTS_SSE41)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE4.1")
add_definitions(-D__SSE4_1__ -D__SSE3__ -D__SSE2__ -D__SSE__)
log_option_enabled("SSE4.1: Streaming SIMD Extensions 4.1 supported and enabled.")
elseif(COMPILER_SUPPORTS_SSE3)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE3")
add_definitions(-D__SSE3__ -D__SSE2__ -D__SSE__)
log_option_enabled("SSE3: Streaming SIMD Extensions 3 supported and enabled.")
elseif(COMPILER_SUPPORTS_SSE2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
add_definitions(-D__SSE2__ -D__SSE__)
log_option_enabled("SSE2: Streaming SIMD Extensions 2 supported and enabled.")
elseif(COMPILER_SUPPORTS_SSE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE")
add_definitions(-D__SSE__)
log_option_enabled("SSE: Streaming SIMD Extensions supported and enabled.")
else()
message(STATUS "No advanced SIMD support found. Proceeding with the default instruction set.")
endif()
else()
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-mavx2" COMPILER_SUPPORTS_AVX2)
if(COMPILER_SUPPORTS_AVX2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2")
add_definitions(-D__AVX2__)
log_option_enabled("AVX2: Advanced Vector Extensions 2 supported and enabled.")
elseif(COMPILER_SUPPORTS_AVX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
add_definitions(-D__AVX__)
log_option_enabled("AVX: Advanced Vector Extensions supported and enabled.")
elseif(COMPILER_SUPPORTS_SSE42)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
add_definitions(-D__SSE4_2__)
log_option_enabled("SSE4.2: Streaming SIMD Extensions 4.2 supported and enabled.")
elseif(COMPILER_SUPPORTS_SSE41)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
add_definitions(-D__SSE4_1__)
log_option_enabled("SSE4.1: Streaming SIMD Extensions 4.1 supported and enabled.")
elseif(COMPILER_SUPPORTS_SSE3)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
add_definitions(-D__SSE3__)
log_option_enabled("SSE3: Streaming SIMD Extensions 3 supported and enabled.")
elseif(COMPILER_SUPPORTS_SSE2)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
add_definitions(-D__SSE2__)
log_option_enabled("SSE2: Streaming SIMD Extensions 2 supported and enabled.")
elseif(COMPILER_SUPPORTS_SSE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse")
add_definitions(-D__SSE__)
log_option_enabled("SSE: Streaming SIMD Extensions supported and enabled.")
else()
message(STATUS "No advanced SIMD support found. Proceeding with the default instruction set.")
endif()
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,36 @@ condition:setParameter(CONDITION_PARAM_HEALTHGAIN, 0.01)
condition:setParameter(CONDITION_PARAM_HEALTHTICKS, 7 * 1000)

local gazHaragothHeal = CreatureEvent("GazHaragothHeal")
function gazHaragothHeal.onThink(creature)
local hp = (creature:getHealth() / creature:getMaxHealth()) * 100
if hp < 12.5 and not creature:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT, 88888) then
creature:addCondition(condition)
creature:say("Gaz'haragoth begins to draw on the nightmares to HEAL himself!", TALKTYPE_MONSTER_YELL)
addEvent(function(cid)
local creature = Creature(cid)
if not creature then
return
function gazHaragothHeal.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if not creature then
return true
end
local creatureName = creature:getName():lower() == "gaz'haragoth"
if creatureName then
if attacker then
local hp = (creature:getHealth() / creature:getMaxHealth()) * 100
if hp > 12.5 then
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
if hp <= 12.5 and not creature:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT, 88888) then
if not creature then
return true
end
creature:addCondition(condition)
creature:say("Gaz'haragoth begins to draw on the nightmares to HEAL himself!", TALKTYPE_MONSTER_YELL)
addEvent(function()
if not creature then
return true
end
creature:addHealth(300000)
creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
creature:say("Gaz'haragoth HEALS himself!", TALKTYPE_MONSTER_YELL)
return true
end, 7000, creature:getId())
end
creature:addHealth(300000)
creature:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
creature:say("Gaz'haragoth HEALS himself!", TALKTYPE_MONSTER_YELL)
return true
end, 7000, creature:getId())
end
end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end

gazHaragothHeal:register()
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.22 FATAL_ERROR)

# Base configurations and settings for the project
include(BaseConfig)
include(CheckSIMDSupport)
include(GNUInstallDirs)

# Import configurations, source definitions, and linker settings
Expand Down
57 changes: 30 additions & 27 deletions src/account/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,85 +62,88 @@
return load();
}

uint8_t Account::save() {
uint8_t Account::save() const {
using enum AccountErrors_t;

if (!m_accLoaded) {
return enumToValue(AccountErrors_t::NotInitialized);
return enumToValue(NotInitialized);
}

if (!g_accountRepository().save(m_account)) {
return enumToValue(AccountErrors_t::Storage);
return enumToValue(Storage);
}

return enumToValue(AccountErrors_t::Ok);
return enumToValue(Ok);
}

std::tuple<uint32_t, uint8_t> Account::getCoins(const uint8_t &type) const {
std::tuple<uint32_t, AccountErrors_t> Account::getCoins(CoinType type) const {
using enum AccountErrors_t;
if (!m_accLoaded) {
return { 0, enumToValue(AccountErrors_t::NotInitialized) };
return { 0, NotInitialized };
}

uint32_t coins = 0;
if (!g_accountRepository().getCoins(m_account->id, type, coins)) {
return { 0, enumToValue(AccountErrors_t::Storage) };

Check failure on line 85 in src/account/account.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

could not convert ‘{0, enumToValue<AccountErrors_t>(AccountErrors_t::Storage)}’ from ‘<brace-enclosed initializer list>’ to ‘std::tuple<unsigned int, AccountErrors_t>’

Check failure on line 85 in src/account/account.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

could not convert ‘{0, enumToValue<AccountErrors_t>(AccountErrors_t::Storage)}’ from ‘<brace-enclosed initializer list>’ to ‘std::tuple<unsigned int, AccountErrors_t>’
}

return { coins, enumToValue(AccountErrors_t::Ok) };
return { coins, Ok };
}

uint8_t Account::addCoins(const uint8_t &type, const uint32_t &amount, const std::string &detail) {
AccountErrors_t Account::addCoins(CoinType type, const uint32_t &amount, const std::string &detail) {
using enum AccountErrors_t;
if (!m_accLoaded) {
return enumToValue(AccountErrors_t::NotInitialized);
return NotInitialized;
}

if (amount == 0) {
return enumToValue(AccountErrors_t::Ok);
return Ok;
}

auto [coins, result] = getCoins(type);

if (AccountErrors_t::Ok != enumFromValue<AccountErrors_t>(result)) {
if (Ok != result) {
return result;
}

if (!g_accountRepository().setCoins(m_account->id, type, coins + amount)) {
return enumToValue(AccountErrors_t::Storage);

Check failure on line 108 in src/account/account.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

cannot convert ‘unsigned char’ to ‘AccountErrors_t’ in return

Check failure on line 108 in src/account/account.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

cannot convert ‘unsigned char’ to ‘AccountErrors_t’ in return
}

registerCoinTransaction(enumToValue(CoinTransactionType::Add), type, amount, detail);
registerCoinTransaction(CoinTransactionType::Add, type, amount, detail);

return enumToValue(AccountErrors_t::Ok);
return Ok;
}

uint8_t Account::removeCoins(const uint8_t &type, const uint32_t &amount, const std::string &detail) {
AccountErrors_t Account::removeCoins(CoinType type, const uint32_t &amount, const std::string &detail) {
using enum AccountErrors_t;
if (!m_accLoaded) {
return enumToValue(AccountErrors_t::NotInitialized);
return NotInitialized;
}

if (amount == 0) {
return enumToValue(AccountErrors_t::Ok);
return AccountErrors_t::Ok;
}

auto [coins, result] = getCoins(type);

if (AccountErrors_t::Ok != enumFromValue<AccountErrors_t>(result)) {
if (Ok != result) {
return result;
}

if (coins < amount) {
g_logger().info("Account doesn't have enough coins! current[{}], remove:[{}]", coins, amount);
return enumToValue(AccountErrors_t::RemoveCoins);
return RemoveCoins;
}

if (!g_accountRepository().setCoins(m_account->id, type, coins - amount)) {
return enumToValue(AccountErrors_t::Storage);

Check failure on line 138 in src/account/account.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

cannot convert ‘unsigned char’ to ‘AccountErrors_t’ in return

Check failure on line 138 in src/account/account.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-24.04-linux-debug

cannot convert ‘unsigned char’ to ‘AccountErrors_t’ in return
}

registerCoinTransaction(enumToValue(CoinTransactionType::Remove), type, amount, detail);
registerCoinTransaction(CoinTransactionType::Remove, type, amount, detail);

return enumToValue(AccountErrors_t::Ok);
return Ok;
}

void Account::registerCoinTransaction(const uint8_t &transactionType, const uint8_t &type, const uint32_t &amount, const std::string &detail) {
void Account::registerCoinTransaction(CoinTransactionType transactionType, CoinType type, const uint32_t &amount, const std::string &detail) {
if (!m_accLoaded) {
return;
}
Expand Down Expand Up @@ -221,10 +224,10 @@
time_t lastDay = m_account->premiumLastDay;
uint32_t remainingDays = m_account->premiumRemainingDays;

time_t currentTime = getTimeNow();
const time_t currentTime = getTimeNow();

auto daysLeft = static_cast<int32_t>((lastDay - currentTime) / 86400);
auto timeLeft = static_cast<int32_t>((lastDay - currentTime) % 86400);
const auto daysLeft = static_cast<int32_t>((lastDay - currentTime) / 86400);
const auto timeLeft = static_cast<int32_t>((lastDay - currentTime) % 86400);

m_account->premiumRemainingDays = daysLeft > 0 ? daysLeft : 0;

Expand Down Expand Up @@ -276,7 +279,7 @@
}

bool Account::authenticatePassword(const std::string &password) {
if (Argon2 {}.argon(password.c_str(), getPassword())) {
if (Argon2().argon(password, getPassword())) {
return true;
}

Expand Down
14 changes: 9 additions & 5 deletions src/account/account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

struct AccountInfo;

enum class CoinType : uint8_t;
enum class CoinTransactionType : uint8_t;
enum class AccountErrors_t : uint8_t;

class Account {
public:
explicit Account(const uint32_t &id);
Expand All @@ -26,7 +30,7 @@ class Account {
* @return uint32_t Number of coins
* @return AccountErrors_t AccountErrors_t::Ok(0) Success, otherwise Fail.
*/
[[nodiscard]] std::tuple<uint32_t, uint8_t> getCoins(const uint8_t &type) const;
[[nodiscard]] std::tuple<uint32_t, AccountErrors_t> getCoins(CoinType type) const;

/**
* @brief Add coins to the account.
Expand All @@ -35,7 +39,7 @@ class Account {
* @param amount Amount of coins to be added
* @return AccountErrors_t AccountErrors_t::Ok(0) Success, otherwise Fail.
*/
uint8_t addCoins(const uint8_t &type, const uint32_t &amount, const std::string &detail = "ADD Coins");
AccountErrors_t addCoins(CoinType type, const uint32_t &amount, const std::string &detail = "ADD Coins");

/**
* @brief Removes coins from the account.
Expand All @@ -44,7 +48,7 @@ class Account {
* @param amount Amount of coins to be removed
* @return AccountErrors_t AccountErrors_t::Ok(0) Success, otherwise Fail.
*/
uint8_t removeCoins(const uint8_t &type, const uint32_t &amount, const std::string &detail = "REMOVE Coins");
AccountErrors_t removeCoins(CoinType type, const uint32_t &amount, const std::string &detail = "REMOVE Coins");

/**
* @brief Registers a coin transaction.
Expand All @@ -53,7 +57,7 @@ class Account {
* @param amount Amount of coins to be added
* @param detail Detail of the transaction
*/
void registerCoinTransaction(const uint8_t &transactionType, const uint8_t &type, const uint32_t &amount, const std::string &detail);
void registerCoinTransaction(CoinTransactionType transactionType, CoinType type, const uint32_t &amount, const std::string &detail);

/***************************************************************************
* Account Load/Save
Expand All @@ -64,7 +68,7 @@ class Account {
*
* @return AccountErrors_t AccountErrors_t::Ok(0) Success, otherwise Fail.
*/
uint8_t save();
uint8_t save() const;

/**
* @brief Load Account Information.
Expand Down
1 change: 0 additions & 1 deletion src/account/account_repository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

#include "account/account_repository.hpp"

#include "lib/di/container.hpp"

AccountRepository &AccountRepository::getInstance() {
Expand Down
11 changes: 7 additions & 4 deletions src/account/account_repository.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

struct AccountInfo;

enum class CoinType : uint8_t;
enum class CoinTransactionType : uint8_t;

class AccountRepository {
public:
AccountRepository() = default;
Expand All @@ -31,13 +34,13 @@ class AccountRepository {

virtual bool getPassword(const uint32_t &id, std::string &password) = 0;

virtual bool getCoins(const uint32_t &id, const uint8_t &type, uint32_t &coins) = 0;
virtual bool setCoins(const uint32_t &id, const uint8_t &type, const uint32_t &amount) = 0;
virtual bool getCoins(const uint32_t &id, CoinType coinType, uint32_t &coins) = 0;
virtual bool setCoins(const uint32_t &id, CoinType coinType, const uint32_t &amount) = 0;
virtual bool registerCoinsTransaction(
const uint32_t &id,
uint8_t type,
CoinTransactionType type,
uint32_t coins,
const uint8_t &coinType,
CoinType coinType,
const std::string &description
) = 0;
};
Expand Down
Loading
Loading