Skip to content

Commit

Permalink
Merge branch 'colobot:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
eschan145 authored Jan 28, 2025
2 parents 4c274f6 + 685c563 commit e2b0e94
Show file tree
Hide file tree
Showing 30 changed files with 286 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ jobs:
uses: lukka/run-vcpkg@v7
with:
setupOnly: true
vcpkgGitCommitId: 'f6a5d4e8eb7476b8d7fc12a56dff300c1c986131'
vcpkgGitCommitId: 'b322364f06308bdd24823f9d8f03fe0cc86fd46f'
vcpkgTriplet: ${{ matrix.vcpkg_triplet }}
# SHA-256 hash of the vcpkg.json file, recalculated automatically when it changes
appendedCacheKey: ${{ hashFiles( '**/vcpkg.json' ) }}
Expand Down
89 changes: 43 additions & 46 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,14 @@ cmake_minimum_required(VERSION 3.21)
cmake_policy(SET CMP0025 NEW)

project(colobot
VERSION 0.2.1.0
VERSION 0.3.0
LANGUAGES C CXX
)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)

##
# Project version
##
set(COLOBOT_VERSION_CODENAME "Gold")

# Used on official releases
#set(COLOBOT_VERSION_RELEASE_CODENAME "-alpha")
# Used on unreleased, development builds
set(COLOBOT_VERSION_UNRELEASED "+alpha")

# Append git characteristics to version
if(DEFINED COLOBOT_VERSION_UNRELEASED)
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
find_package(Git)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(COLOBOT_VERSION_UNRELEASED "${COLOBOT_VERSION_UNRELEASED}-git-${GIT_BRANCH}~r${GIT_REVISION}")
set(COLOBOT_VERSION_DISPLAY "git-${GIT_BRANCH}~r${GIT_REVISION}")
else()
set(COLOBOT_VERSION_DISPLAY "${COLOBOT_VERSION_CODENAME}-${COLOBOT_VERSION_UNRELEASED}")
endif()
else()
set(COLOBOT_VERSION_DISPLAY "${CMAKE_PROJECT_VERSION}${COLOBOT_VERSION_RELEASE_CODENAME}")
endif()

set(COLOBOT_VERSION_FULL "${CMAKE_PROJECT_VERSION}${COLOBOT_VERSION_UNRELEASED}${COLOBOT_VERSION_RELEASE_CODENAME}")
message(STATUS "Building Colobot \"${COLOBOT_VERSION_CODENAME}\" (${COLOBOT_VERSION_FULL})")

set(BUILD_NUMBER 0)
if(NOT "$ENV{BUILD_NUMBER}" STREQUAL "")
set(BUILD_NUMBER "$ENV{BUILD_NUMBER}")
message(STATUS "CI build #${BUILD_NUMBER}")
endif()


# Compiler detection
include("${PROJECT_SOURCE_DIR}/cmake/compilers/${CMAKE_CXX_COMPILER_ID}.cmake" OPTIONAL RESULT_VARIABLE COMPILER_INCLUDE)

Expand All @@ -73,10 +32,6 @@ if ("${SYSTEM_INCLUDE}" STREQUAL NOTFOUND)
include("${PROJECT_SOURCE_DIR}/cmake/systems/Other.cmake")
endif()

##
# Build options
##

# Build targets should be placed in the root build directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

Expand All @@ -85,6 +40,10 @@ list(PREPEND CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/cmake
)

##
# Build options
##

# Asserts can be enabled/disabled regardless of build type
option(ASSERTS "Enable assert()s" ON)

Expand Down Expand Up @@ -143,6 +102,44 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()

##
# Project version
##
set(COLOBOT_VERSION_CODENAME "Gold")
set(COLOBOT_VERSION_RELEASE "alpha")

if(COLOBOT_OFFICIAL_BUILD)
set(COLOBOT_VERSION_DISPLAY "${CMAKE_PROJECT_VERSION}-${COLOBOT_VERSION_RELEASE}")
set(COLOBOT_VERSION_FULL "${CMAKE_PROJECT_VERSION}-${COLOBOT_VERSION_RELEASE}")
else()
# Append git characteristics to version string
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
find_package(Git)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE)

set(COLOBOT_VERSION_DISPLAY "git-${GIT_BRANCH}~r${GIT_REVISION}")
set(COLOBOT_VERSION_FULL "${CMAKE_PROJECT_VERSION}-${COLOBOT_VERSION_RELEASE}-git-${GIT_BRANCH}~r${GIT_REVISION}")
else()
set(COLOBOT_VERSION_DISPLAY "${COLOBOT_VERSION_CODENAME}-${COLOBOT_VERSION_RELEASE}")
set(COLOBOT_VERSION_FULL "${CMAKE_PROJECT_VERSION}-${COLOBOT_VERSION_RELEASE}")
endif()
endif()

message(STATUS "Building Colobot '${COLOBOT_VERSION_CODENAME}' (${COLOBOT_VERSION_FULL})")

set(BUILD_NUMBER 0)
if(NOT "$ENV{BUILD_NUMBER}" STREQUAL "")
set(BUILD_NUMBER "$ENV{BUILD_NUMBER}")
message(STATUS "CI build #${BUILD_NUMBER}")
endif()

##
# Additional functions for colobot-lint
##
Expand Down
3 changes: 2 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"PORTABLE": true,
"TOOLS": true,
"TESTS": true,
"DESKTOP": true
"DESKTOP": true,
"CMAKE_MAKE_PROGRAM": "ninja.exe"
}
},
{
Expand Down
14 changes: 11 additions & 3 deletions colobot-base/src/common/config.h.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#include <string_view>

// Macros set by CMake
#cmakedefine PLATFORM_GNU @PLATFORM_GNU@
#cmakedefine PLATFORM_MACOSX @PLATFORM_MACOSX@

#ifdef PLATFORM_MACOSX
Expand All @@ -11,5 +12,12 @@

#cmakedefine OPENAL_SOUND

#define COLOBOT_DEFAULT_DATADIR "@COLOBOT_DATA_DIR@"
#define COLOBOT_I18N_DIR "@COLOBOT_I18N_DIR@"
namespace Config
{

// Default data directory
inline constexpr std::string_view DATA_DIR = "@COLOBOT_DATA_DIR@";
// Default language directory
inline constexpr std::string_view LANG_DIR = "@COLOBOT_I18N_DIR@";

}
51 changes: 47 additions & 4 deletions colobot-base/src/common/config_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include <nlohmann/json.hpp>

#include <deque>
#include <optional>
#include <string>
#include <sstream>
Expand Down Expand Up @@ -106,9 +107,8 @@ class CConfigFile : public CSingleton<CConfigFile>
*/
bool GetBoolProperty(std::string section, std::string key, bool &value);

/** Gets an array of values of type T in section under specified key
/** Sets an array of values of type T in section under specified key
* The value separator is ','.
* \a array will only be changed if key exists
* \return return true on success
*/
template<typename T>
Expand All @@ -127,9 +127,8 @@ class CConfigFile : public CSingleton<CConfigFile>
return true;
}

/** Sets an array of values of type T in section under specified key.
/** Gets an array of values of type T in section under specified key.
* The value separator is ','.
* \a array will only be changed if key exists
* \return return true on success
*/
template<typename T>
Expand All @@ -152,6 +151,50 @@ class CConfigFile : public CSingleton<CConfigFile>
return true;
}

/** Sets a deque of values of type T in section under specified key
* The value separator is ','.
* \return return true on success
*/
template<typename T>
bool SetDequeProperty(std::string section, std::string key, const std::deque<T>& que)
{
try
{
m_properties[section][key] = nlohmann::json(que);
m_needsSave = true;
}
catch (std::exception & e)
{
GetLogger()->Error("Error on editing config file: %%", e.what());
return false;
}
return true;
}

/** Gets a deque of values of type T in section under specified key.
* The value separator is ','.
* \return return true on success
*/
template<typename T>
bool GetDequeProperty(std::string section, std::string key, std::deque<T>& que)
{
try
{
que.clear();

for (auto& value : m_properties[section][key])
{
que.push_back(value.get<T>());
}
}
catch (std::exception & e)
{
GetLogger()->Log(m_loaded ? LOG_INFO : LOG_TRACE, "Error on parsing config file: %%", e.what());
return false;
}
return true;
}

private:
nlohmann::json m_properties;

Expand Down
10 changes: 9 additions & 1 deletion colobot-base/src/common/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ void CSettings::SaveAudioSettings()
GetConfigFile().SetBoolProperty("Setup", "FocusLostMute", m_focusLostMute);
}

void CSettings::SaveCommandHistory(const std::deque<std::string>& commands)
{
GetConfigFile().SetDequeProperty("Setup", "CommandHistory", commands);
GetConfigFile().Save();
}

void CSettings::LoadSettings()
{
CApplication* app = CApplication::GetInstancePointer();
Expand Down Expand Up @@ -269,7 +275,9 @@ void CSettings::LoadSettings()

CInput::GetInstancePointer()->LoadKeyBindings();


std::deque<std::string> commands;
GetConfigFile().GetDequeProperty("Setup", "CommandHistory", commands);
main->SetCommandHistory(std::move(commands));

GetConfigFile().GetFloatProperty("Edit", "FontSize", m_fontSize);
GetConfigFile().GetFloatProperty("Edit", "WindowPosX", m_windowPos.x);
Expand Down
2 changes: 2 additions & 0 deletions colobot-base/src/common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "common/language.h"
#include "common/singleton.h"

#include <deque>
#include <glm/glm.hpp>

namespace Gfx
Expand All @@ -37,6 +38,7 @@ class CSettings : public CSingleton<CSettings>
void LoadSettings();

void SaveAudioSettings();
void SaveCommandHistory(const std::deque<std::string>& commands);

void SetTooltips(bool tooltips);
bool GetTooltips() const;
Expand Down
9 changes: 5 additions & 4 deletions colobot-base/src/common/system/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "common/system/system.h"

#include "common/config.h"
#include "common/logger.h"
#include "common/stringutils.h"
#include "common/version.h"
Expand Down Expand Up @@ -200,17 +201,17 @@ std::filesystem::path CSystemUtils::GetBasePath() const
std::filesystem::path CSystemUtils::GetDataPath() const
{
if constexpr (Version::RELATIVE_PATHS)
return GetBasePath() / COLOBOT_DEFAULT_DATADIR;
return GetBasePath() / Config::DATA_DIR;
else
return COLOBOT_DEFAULT_DATADIR;
return Config::DATA_DIR;
}

std::filesystem::path CSystemUtils::GetLangPath() const
{
if constexpr (Version::RELATIVE_PATHS)
return GetBasePath() / COLOBOT_I18N_DIR;
return GetBasePath() / Config::LANG_DIR;
else
return COLOBOT_I18N_DIR;
return Config::LANG_DIR;
}

std::filesystem::path CSystemUtils::GetSaveDir() const
Expand Down
2 changes: 1 addition & 1 deletion colobot-base/src/common/thread/worker_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ class CWorkerThread
}
}

std::thread m_thread;
std::mutex m_mutex;
std::condition_variable m_cond;
bool m_running = true;
std::queue<ThreadFunctionPtr> m_queue;
std::thread m_thread;
};
22 changes: 11 additions & 11 deletions colobot-base/src/common/version.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

namespace Version
{
static inline constexpr bool OFFICIAL_BUILD = @CONFIG_OFFICIAL_BUILD@;
static inline constexpr bool DEVELOPMENT_BUILD = @CONFIG_DEVELOPMENT_BUILD@;
static inline constexpr bool PORTABLE_SAVES = @CONFIG_PORTABLE_SAVES@;
static inline constexpr bool RELATIVE_PATHS = @CONFIG_RELATIVE_PATHS@;
inline constexpr bool OFFICIAL_BUILD = @CONFIG_OFFICIAL_BUILD@;
inline constexpr bool DEVELOPMENT_BUILD = @CONFIG_DEVELOPMENT_BUILD@;
inline constexpr bool PORTABLE_SAVES = @CONFIG_PORTABLE_SAVES@;
inline constexpr bool RELATIVE_PATHS = @CONFIG_RELATIVE_PATHS@;

static inline constexpr int BUILD_NUMBER = @BUILD_NUMBER@;
inline constexpr int BUILD_NUMBER = @BUILD_NUMBER@;

static inline constexpr std::string_view FULL_NAME = "Colobot: Gold Edition @COLOBOT_VERSION_FULL@";
static inline constexpr std::string_view VERSION = "@CMAKE_PROJECT_VERSION@";
static inline constexpr int MAJOR = @CMAKE_PROJECT_VERSION_MAJOR@;
static inline constexpr int MINOR = @CMAKE_PROJECT_VERSION_MINOR@;
static inline constexpr int PATCH = @CMAKE_PROJECT_VERSION_PATCH@;
static inline constexpr std::string_view VERSION_DISPLAY = "@COLOBOT_VERSION_DISPLAY@";
inline constexpr std::string_view FULL_NAME = "Colobot: Gold Edition @COLOBOT_VERSION_FULL@";
inline constexpr std::string_view VERSION = "@CMAKE_PROJECT_VERSION@";
inline constexpr int MAJOR = @CMAKE_PROJECT_VERSION_MAJOR@;
inline constexpr int MINOR = @CMAKE_PROJECT_VERSION_MINOR@;
inline constexpr int PATCH = @CMAKE_PROJECT_VERSION_PATCH@;
inline constexpr std::string_view VERSION_DISPLAY = "@COLOBOT_VERSION_DISPLAY@";
}
18 changes: 12 additions & 6 deletions colobot-base/src/graphics/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1990,16 +1990,25 @@ bool CEngine::LoadAllTextures()
ok = false;
}

if (!data.material.detailTexture.empty())
const std::filesystem::path& detailTexture = data.material.variableDetail ? GetSecondTexture() : data.material.detailTexture;
if (!detailTexture.empty())
{
if (terrain)
data.detailTexture = LoadTexture(data.material.detailTexture, m_terrainTexParams);
{
data.detailTexture = LoadTexture(detailTexture, m_terrainTexParams);
}
else
data.detailTexture = LoadTexture(data.material.detailTexture);
{
data.detailTexture = LoadTexture(detailTexture);
}

if (!data.detailTexture.Valid())
ok = false;
}
else
{
data.detailTexture = Texture();
}

if (!data.material.materialTexture.empty())
{
Expand Down Expand Up @@ -4756,9 +4765,6 @@ void CEngine::AddBaseObjTriangles(int baseObjRank, const std::vector<Gfx::ModelT
if (!material.emissiveTexture.empty())
material.emissiveTexture = "objects" / material.emissiveTexture;

if (material.variableDetail)
material.detailTexture = GetSecondTexture();

EngineBaseObjDataTier& data = AddLevel(p1, EngineTriangleType::TRIANGLES, material);

data.vertices.insert(data.vertices.end(), vertices.begin(), vertices.end());
Expand Down
Loading

0 comments on commit e2b0e94

Please sign in to comment.