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 64 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 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
eda12c8
up
beats-dh Dec 8, 2024
cd2d197
Merge branch 'main' into beats-fixs
beats-dh Dec 8, 2024
37cf961
fix merge
beats-dh Dec 8, 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
8 changes: 4 additions & 4 deletions src/account/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ void Account::updatePremiumTime() {
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 @@ -281,7 +281,7 @@ bool Account::authenticateSession() {
}

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

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
22 changes: 11 additions & 11 deletions src/account/account_repository_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ AccountRepositoryDB::AccountRepositoryDB() {
bool AccountRepositoryDB::loadByID(const uint32_t &id, std::unique_ptr<AccountInfo> &acc) {
auto query = fmt::format("SELECT `id`, `type`, `premdays`, `lastday`, `creation`, `premdays_purchased`, 0 AS `expires` FROM `accounts` WHERE `id` = {}", id);
return load(query, acc);
};
}

bool AccountRepositoryDB::loadByEmailOrName(bool oldProtocol, const std::string &emailOrName, std::unique_ptr<AccountInfo> &acc) {
auto identifier = oldProtocol ? "name" : "email";
auto query = fmt::format("SELECT `id`, `type`, `premdays`, `lastday`, `creation`, `premdays_purchased`, 0 AS `expires` FROM `accounts` WHERE `{}` = {}", identifier, g_database().escapeString(emailOrName));
const auto query = fmt::format("SELECT `id`, `type`, `premdays`, `lastday`, `creation`, `premdays_purchased`, 0 AS `expires` FROM `accounts` WHERE `{}` = {}", identifier, g_database().escapeString(emailOrName));
return load(query, acc);
};
}

bool AccountRepositoryDB::loadBySession(const std::string &sessionKey, std::unique_ptr<AccountInfo> &acc) {
auto query = fmt::format(
Expand All @@ -42,7 +42,7 @@ bool AccountRepositoryDB::loadBySession(const std::string &sessionKey, std::uniq
g_database().escapeString(transformToSHA1(sessionKey))
);
return load(query, acc);
};
}

bool AccountRepositoryDB::save(const std::unique_ptr<AccountInfo> &accInfo) {
bool successful = g_database().executeQuery(
Expand All @@ -62,7 +62,7 @@ bool AccountRepositoryDB::save(const std::unique_ptr<AccountInfo> &accInfo) {
}

return successful;
};
}

bool AccountRepositoryDB::getCharacterByAccountIdAndName(const uint32_t &id, const std::string &name) {
auto result = g_database().storeQuery(fmt::format("SELECT `id` FROM `players` WHERE `account_id` = {} AND `name` = {}", id, g_database().escapeString(name)));
Expand All @@ -75,15 +75,15 @@ bool AccountRepositoryDB::getCharacterByAccountIdAndName(const uint32_t &id, con
}

bool AccountRepositoryDB::getPassword(const uint32_t &id, std::string &password) {
auto result = g_database().storeQuery(fmt::format("SELECT * FROM `accounts` WHERE `id` = {}", id));
const auto result = g_database().storeQuery(fmt::format("SELECT * FROM `accounts` WHERE `id` = {}", id));
if (!result) {
g_logger().error("Failed to get account:[{}] password!", id);
return false;
}

password = result->getString("password");
return true;
};
}

bool AccountRepositoryDB::getCoins(const uint32_t &id, CoinType coinType, uint32_t &coins) {
auto it = coinTypeToColumn.find(coinType);
Expand All @@ -107,7 +107,7 @@ bool AccountRepositoryDB::getCoins(const uint32_t &id, CoinType coinType, uint32
coins = result->getNumber<uint32_t>(column);

return true;
};
}

bool AccountRepositoryDB::setCoins(const uint32_t &id, CoinType coinType, const uint32_t &amount) {
auto it = coinTypeToColumn.find(coinType);
Expand All @@ -130,7 +130,7 @@ bool AccountRepositoryDB::setCoins(const uint32_t &id, CoinType coinType, const
}

return successful;
};
}

bool AccountRepositoryDB::registerCoinsTransaction(
const uint32_t &id,
Expand All @@ -139,7 +139,7 @@ bool AccountRepositoryDB::registerCoinsTransaction(
CoinType coinType,
const std::string &description
) {
bool successful = g_database().executeQuery(
const bool successful = g_database().executeQuery(
fmt::format(
"INSERT INTO `coins_transactions` (`account_id`, `type`, `coin_type`, `amount`, `description`) VALUES ({}, {}, {}, {}, {})",
id,
Expand All @@ -162,7 +162,7 @@ bool AccountRepositoryDB::registerCoinsTransaction(
}

return successful;
};
}

bool AccountRepositoryDB::loadAccountPlayers(std::unique_ptr<AccountInfo> &acc) const {
auto result = g_database().storeQuery(
Expand Down
16 changes: 8 additions & 8 deletions src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int CanaryServer::run() {
return EXIT_SUCCESS;
}

void CanaryServer::setWorldType() {
void CanaryServer::setWorldType() const {
const std::string worldType = asLowerCaseString(g_configManager().getString(WORLD_TYPE));
if (worldType == "pvp") {
g_game().setWorldType(WORLD_TYPE_PVP);
Expand Down Expand Up @@ -177,9 +177,9 @@ void CanaryServer::loadMaps() const {
}
}

void CanaryServer::setupHousesRent() {
void CanaryServer::setupHousesRent() const {
RentPeriod_t rentPeriod;
std::string strRentPeriod = asLowerCaseString(g_configManager().getString(HOUSE_RENT_PERIOD));
const std::string strRentPeriod = asLowerCaseString(g_configManager().getString(HOUSE_RENT_PERIOD));

if (strRentPeriod == "yearly") {
rentPeriod = RENTPERIOD_YEARLY;
Expand All @@ -196,7 +196,7 @@ void CanaryServer::setupHousesRent() {
g_game().map.houses.payHouses(rentPeriod);
}

void CanaryServer::logInfos() {
void CanaryServer::logInfos() const {
#if defined(GIT_RETRIEVED_STATE) && GIT_RETRIEVED_STATE
logger.debug("{} - Version [{}] dated [{}]", ProtocolStatus::SERVER_NAME, SERVER_RELEASE_VERSION, GIT_COMMIT_DATE_ISO8601);
#if GIT_IS_DIRTY
Expand Down Expand Up @@ -270,7 +270,7 @@ std::string CanaryServer::getCompiler() {
#endif
}

void CanaryServer::loadConfigLua() {
void CanaryServer::loadConfigLua() const {
std::string configName = "config.lua";
// Check if config or config.dist exist
std::ifstream c_test("./" + configName);
Expand Down Expand Up @@ -301,7 +301,7 @@ void CanaryServer::loadConfigLua() {
#endif
}

void CanaryServer::initializeDatabase() {
void CanaryServer::initializeDatabase() const {
logger.info("Establishing database connection... ");
if (!Database::getInstance().connect()) {
throw FailedToInitializeCanary("Failed to connect to database!");
Expand All @@ -325,7 +325,7 @@ void CanaryServer::initializeDatabase() {
g_logger().info("Database connection established!");
}

void CanaryServer::loadModules() {
void CanaryServer::loadModules() const {
// If "USE_ANY_DATAPACK_FOLDER" is set to true then you can choose any datapack folder for your server
const auto useAnyDatapack = g_configManager().getBoolean(USE_ANY_DATAPACK_FOLDER);
auto datapackName = g_configManager().getString(DATA_DIRECTORY);
Expand Down Expand Up @@ -382,7 +382,7 @@ void CanaryServer::loadModules() {
g_game().logCyclopediaStats();
}

void CanaryServer::modulesLoadHelper(bool loaded, std::string moduleName) {
void CanaryServer::modulesLoadHelper(bool loaded, std::string moduleName) const {
logger.debug("Loading {}", moduleName);
if (!loaded) {
throw FailedToInitializeCanary(fmt::format("Cannot load: {}", moduleName));
Expand Down
16 changes: 8 additions & 8 deletions src/canary_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class Logger;

class FailedToInitializeCanary : public std::exception {
class FailedToInitializeCanary final : public std::exception {
private:
std::string message;

Expand Down Expand Up @@ -52,19 +52,19 @@ class CanaryServer {

std::atomic<LoaderStatus> loaderStatus = LoaderStatus::LOADING;

void logInfos();
void logInfos() const;
static void toggleForceCloseButton();
static void badAllocationHandler();
static void shutdown();

static std::string getCompiler();
static std::string getPlatform();

void loadConfigLua();
void initializeDatabase();
void loadModules();
void setWorldType();
void loadConfigLua() const;
void initializeDatabase() const;
void loadModules() const;
void setWorldType() const;
void loadMaps() const;
void setupHousesRent();
void modulesLoadHelper(bool loaded, std::string moduleName);
void setupHousesRent() const;
void modulesLoadHelper(bool loaded, std::string moduleName) const;
};
2 changes: 1 addition & 1 deletion src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ bool ConfigManager::reload() {
return result;
}

void ConfigManager::missingConfigWarning(const char* identifier) {
void ConfigManager::missingConfigWarning(const char* identifier) const {
g_logger().debug("[{}]: Missing configuration for identifier: {}", __FUNCTION__, identifier);
}

Expand Down
2 changes: 1 addition & 1 deletion src/config/configmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ConfigManager {
bool load();
bool reload();

void missingConfigWarning(const char* identifier);
void missingConfigWarning(const char* identifier) const;

const std::string &setConfigFileLua(const std::string &what) {
configFileLua = { what };
Expand Down
Loading
Loading