Minor - Adds build versioning to the engine - V14.1.0

Implements a build versioning system to track and display the engine's build information.

- Adds a version header file defining version constants.
- Increments the build number automatically from a configuration file on each build in the binary folder.
- Displays the build version in the ImGui menu bar for easy identification.
- Persists version information by reading/writing to the config file

This provides better tracking and identification of specific engine builds.
This commit is contained in:
2025-09-18 01:58:18 +02:00
parent 2346625afb
commit 29db39910c
8 changed files with 178 additions and 15 deletions

2
.gitattributes vendored
View File

@@ -6,3 +6,5 @@ enginecustom/x64/Debug/lua54.dll filter=lfs diff=lfs merge=lfs -text
enginecustom/x64/Release/lua54.dll filter=lfs diff=lfs merge=lfs -text
x64/Debug/lua54.dll filter=lfs diff=lfs merge=lfs -text
x64/Release/lua54.dll filter=lfs diff=lfs merge=lfs -text
x64/Debug/config.txt filter=lfs diff=lfs merge=lfs -text
x64/Release/config.txt filter=lfs diff=lfs merge=lfs -text

View File

@@ -156,6 +156,7 @@
<ClInclude Include="src\inc\system\text_class.h" />
<ClInclude Include="src\inc\system\texture_class.h" />
<ClInclude Include="src\inc\system\timer_class.h" />
<ClInclude Include="src\inc\system\version.h" />
<ClInclude Include="src\inc\system\vulkan.h" />
</ItemGroup>
<ItemGroup>

View File

@@ -12,7 +12,7 @@ Collapsed=0
Pos=1267,19
Size=317,842
Collapsed=0
DockId=0x00000005,0
DockId=0x00000006,0
[Window][render Stats]
Pos=0,630
@@ -48,20 +48,20 @@ DockId=0x0000000B,0
Pos=1267,462
Size=317,166
Collapsed=0
DockId=0x00000006,0
DockId=0x00000002,0
[Docking][Data]
DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=0,19 Size=1584,842 Split=Y
DockNode ID=0x00000003 Parent=0xCCBD8CF7 SizeRef=1584,609 Split=X
DockNode ID=0x0000000B Parent=0x00000003 SizeRef=234,842 Selected=0x031DC75C
DockNode ID=0x0000000C Parent=0x00000003 SizeRef=1348,842 Split=X
DockNode ID=0x00000007 Parent=0x0000000C SizeRef=266,842 Selected=0x393905AB
DockNode ID=0x00000008 Parent=0x0000000C SizeRef=1316,842 Split=X
DockNode ID=0x00000001 Parent=0x00000008 SizeRef=1265,842 CentralNode=1
DockNode ID=0x00000002 Parent=0x00000008 SizeRef=317,842 Split=Y Selected=0x9F035453
DockNode ID=0x00000005 Parent=0x00000002 SizeRef=317,441 Selected=0x9F035453
DockNode ID=0x00000006 Parent=0x00000002 SizeRef=317,166 Selected=0x0B098C4B
DockNode ID=0x00000004 Parent=0xCCBD8CF7 SizeRef=1584,231 Split=X Selected=0xF5D1BB37
DockNode ID=0x00000009 Parent=0x00000004 SizeRef=792,231 Selected=0xF5D1BB37
DockNode ID=0x0000000A Parent=0x00000004 SizeRef=790,231 Selected=0xAB74BEE9
DockSpace ID=0xCCBD8CF7 Window=0x3DA2F1DE Pos=0,19 Size=1584,842 Split=X
DockNode ID=0x00000005 Parent=0xCCBD8CF7 SizeRef=1265,842 Split=Y
DockNode ID=0x00000003 Parent=0x00000005 SizeRef=1584,609 Split=X
DockNode ID=0x0000000B Parent=0x00000003 SizeRef=234,842 Selected=0x031DC75C
DockNode ID=0x0000000C Parent=0x00000003 SizeRef=1348,842 Split=X
DockNode ID=0x00000007 Parent=0x0000000C SizeRef=266,842 Selected=0x393905AB
DockNode ID=0x00000008 Parent=0x0000000C SizeRef=1316,842 Split=X
DockNode ID=0x00000001 Parent=0x00000008 SizeRef=1265,842 CentralNode=1
DockNode ID=0x00000002 Parent=0x00000008 SizeRef=317,842 Selected=0x9F035453
DockNode ID=0x00000004 Parent=0x00000005 SizeRef=1584,231 Split=X Selected=0xF5D1BB37
DockNode ID=0x00000009 Parent=0x00000004 SizeRef=792,231 Selected=0xF5D1BB37
DockNode ID=0x0000000A Parent=0x00000004 SizeRef=790,231 Selected=0xAB74BEE9
DockNode ID=0x00000006 Parent=0xCCBD8CF7 SizeRef=317,842 Selected=0x9F035453

View File

@@ -17,6 +17,8 @@
#include "scene_manager.h"
#include "ecs/entity_manager.h"
#include "version.h"
class application_class;
class stats;
@@ -47,6 +49,16 @@ public:
imguiManager();
~imguiManager();
/**
* Load the build version from a configuration file.
* The configuration file should contain a line with the build version in the format "VER=XXX...".
* If the line is not found, it will be added with a version of 0.
* The build version will be incremented by 1 each time this function is called.
* @param filepath The path to the configuration file.
* @return True if the build version was loaded successfully, otherwise false.
*/
bool IncrementBuildVersionInConfig(const std::string& filepath);
/**
* Initializes the ImGui manager.
* @param hwnd Handle to the window where ImGui will be rendered.
@@ -217,6 +229,8 @@ private:
std::string version_driver_;
ecs::EntityID m_selected_entity_id = 0; // ID of the currently selected entity
int BUILD_VERSION_VER = -1;
};
#endif

View File

@@ -0,0 +1,24 @@
#pragma once
#include "imgui.h"
#define BUILD_VERSION_MAJOR 14
#define BUILD_VERSION_MINOR 0
#define BUILD_VERSION_PATCH 3
// BUILD_VERSION_VER est un int persist<73> dans un fichier, <20> charger au lancement et incr<63>menter <20> chaque build (voir point 3)
extern int BUILD_VERSION_VER;
#ifdef _DEBUG
#define BUILD_VERSION_TYPE "Debug"
#define BUILD_VERSION_INVERSE "Release"
// define a color for debug mode (dark yellow)
#define DEBUG_MODE_COLOR IM_COL32(204, 153, 0, 255)
#else
#define BUILD_VERSION_TYPE "Release"
#define BUILD_VERSION_INVERSE "Debug"
// define a color for release mode (rouge bordeau)
#define DEBUG_MODE_COLOR IM_COL32(128, 0, 32, 255)
#endif
// BUILD_VERSION_STATE est d<>fini manuellement (ex "Dev" ou "Stable")
#define BUILD_VERSION_STATE "Dev"
//#define BUILD_VERSION_STATE "Stable"

View File

@@ -49,6 +49,50 @@ imguiManager::~imguiManager()
{
}
bool imguiManager::IncrementBuildVersionInConfig(const std::string& filepath) {
std::ifstream file_in(filepath);
if (!file_in) return false; // fichier introuvable
std::vector<std::string> lines;
std::string line;
// Lire toutes les lignes pour les manipuler
while (std::getline(file_in, line)) {
if (line.find("VER=") == 0) {
// Extraire la version actuelle
std::string ver_str = line.substr(4);
try {
BUILD_VERSION_VER = std::stoi(ver_str);
if (BUILD_VERSION_STATE == "Dev")
{
BUILD_VERSION_VER += 1;
line = "VER=" + std::to_string(BUILD_VERSION_VER);
}
} catch (...) {
return false; // erreur conversion
}
}
lines.push_back(line);
}
file_in.close();
// Si pas trouvé VER=, on l'ajoute
if (BUILD_VERSION_VER == -1) {
BUILD_VERSION_VER = 0;
lines.push_back("VER=0");
}
// Réécrire tout le fichier
std::ofstream file_out(filepath, std::ios::trunc);
if (!file_out) return false;
for (const auto& l : lines) {
file_out << l << "\n";
}
file_out.close();
return true;
}
bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* deviceContext)
{
Logger::Get().Log("Initializing imgui", __FILE__, __LINE__, Logger::LogLevel::Initialize);
@@ -187,6 +231,40 @@ bool imguiManager::Initialize(HWND hwnd, ID3D11Device* device, ID3D11DeviceConte
entity_manager_ = app_->get_entity_manager();
// Get the exe parent directory to find config.txt ../exefolder
char exePath[MAX_PATH];
GetModuleFileNameA(NULL, exePath, MAX_PATH);
std::string exeDir = std::string(exePath);
// Retirer la partie exe filename (tout après le dernier slash)
size_t lastSlash = exeDir.find_last_of("\\/");
if (lastSlash != std::string::npos) {
exeDir = exeDir.substr(0, lastSlash);
} else {
exeDir = "";
}
// Retirer encore le dernier dossier (rebrousser dans le parent) : aller dans le dossier parent
lastSlash = exeDir.find_last_of("\\/");
if (lastSlash != std::string::npos) {
exeDir = exeDir.substr(0, lastSlash + 1); // garder slash de fin pour concat
} else {
exeDir = "";
}
std::string configPath = "config.txt"; // ou chemin complet
configPath = exeDir + BUILD_VERSION_TYPE + "\\" + configPath;
if (!IncrementBuildVersionInConfig(configPath)) {
Logger::Get().Log("Failed to increment build version in config.txt", __FILE__, __LINE__, Logger::LogLevel::Warning);
}
// update the build version text in the inverse build type folder
configPath = "config.txt";
configPath = exeDir + BUILD_VERSION_INVERSE + "\\" + configPath;
Logger::Get().Log("Inverse build type config path: " + configPath, __FILE__, __LINE__, Logger::LogLevel::Info);
if (!IncrementBuildVersionInConfig(configPath)) {
Logger::Get().Log("Failed to increment build version in config.txt of inverse build type", __FILE__, __LINE__, Logger::LogLevel::Warning);
}
Logger::Get().Log("imgui initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true;
@@ -276,6 +354,44 @@ void imguiManager::SetupDockspace() {
ImGui::EndMenu();
}
const float PAD_X = 14.0f;
float menuBarHeight = ImGui::GetFrameHeight();
std::string versionText = std::string("Build-") + BUILD_VERSION_TYPE + "-" +
std::to_string(BUILD_VERSION_MAJOR) + "." +
std::to_string(BUILD_VERSION_MINOR) + "." +
std::to_string(BUILD_VERSION_PATCH) + "." +
std::to_string(BUILD_VERSION_VER) + "-" +
BUILD_VERSION_STATE;
ImVec2 textSize = ImGui::CalcTextSize(versionText.c_str());
float windowWidth = ImGui::GetWindowContentRegionMax().x;
// Rectangle ajusté parfaitement à la hauteur
float rectWidth = textSize.x + PAD_X * 2;
float rectX = ImGui::GetWindowPos().x + windowWidth - rectWidth - 10.0f; // marge droite
float rectY = ImGui::GetWindowPos().y;
float offsetX = textSize.x * 0.2f;
ImVec2 rectMin(rectX - offsetX, rectY);
ImVec2 rectMax(rectX + rectWidth - offsetX, rectY + menuBarHeight);
// Fond arrondi parfaitement aligné avec la barre
ImGui::GetForegroundDrawList()->AddRectFilled(
rectMin, rectMax, DEBUG_MODE_COLOR, menuBarHeight / 2.0f
);
// Texte centré verticalement dans le rectangle
ImVec2 textPos(
rectMin.x + PAD_X,
rectMin.y + (menuBarHeight - textSize.y) / 2.0f
);
ImGui::GetForegroundDrawList()->AddText(
ImGui::GetFont(), ImGui::GetFontSize(),
textPos, IM_COL32(255,255,255,255), versionText.c_str()
);
ImGui::EndMenuBar();
}

BIN
x64/Debug/config.txt (Stored with Git LFS) Normal file

Binary file not shown.

BIN
x64/Release/config.txt (Stored with Git LFS) Normal file

Binary file not shown.