feat: attempts to fix logging issue
All checks were successful
CI / build-and-test (push) Successful in 2m23s

This commit is contained in:
2025-11-17 19:14:27 +13:00
parent dcc21f2ba2
commit 26bcfac7d1
4 changed files with 95 additions and 25 deletions

20
.vscode/settings.json vendored
View File

@@ -72,6 +72,24 @@
"typeinfo": "cpp",
"variant": "cpp",
"format": "cpp",
"*.m": "cpp"
"*.m": "cpp",
"filesystem": "cpp",
"forward_list": "cpp",
"ios": "cpp",
"locale": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp"
}
}

View File

@@ -9,34 +9,34 @@ Size=400,400
Collapsed=0
[Window][Game Window]
Pos=8,25
Size=1264,581
Pos=8,29
Size=1264,360
Collapsed=0
DockId=0x00000001,0
[Window][Log Viewer]
Pos=8,608
Size=1264,104
Pos=8,391
Size=1264,321
Collapsed=0
DockId=0x00000002,0
[Window][##TOAST0]
Pos=1062,643
Size=198,57
Pos=1010,635
Size=250,65
Collapsed=0
[Window][##TOAST1]
Pos=1062,576
Size=198,57
Pos=1010,560
Size=250,65
Collapsed=0
[Window][##TOAST2]
Pos=1062,509
Size=198,57
Pos=1010,485
Size=250,65
Collapsed=0
[Docking][Data]
DockSpace ID=0x9076BACA Window=0x34F970D7 Pos=8,25 Size=1264,687 Split=Y Selected=0x27A02DAA
DockNode ID=0x00000001 Parent=0x9076BACA SizeRef=1264,579 CentralNode=1 Selected=0x27A02DAA
DockNode ID=0x00000002 Parent=0x9076BACA SizeRef=1264,104 Selected=0xBEDDA0C1
DockSpace ID=0x9076BACA Window=0x34F970D7 Pos=8,29 Size=1264,683 Split=Y Selected=0x27A02DAA
DockNode ID=0x00000001 Parent=0x9076BACA SizeRef=1264,360 CentralNode=1 Selected=0x27A02DAA
DockNode ID=0x00000002 Parent=0x9076BACA SizeRef=1264,321 Selected=0xBEDDA0C1

View File

@@ -2,7 +2,7 @@ float x = 50;
float y = 100;
void Update(float dt) {
x += 500 * dt;
x += 640 * dt;
if (x > 800) {
x = 0;
Print("X position reset!");

View File

@@ -5,6 +5,14 @@
#include <iostream>
#include "log.h"
#include "Application.h"
#include <filesystem> // Add this for cross-platform file handling
#ifdef _WIN32
#include <windows.h>
#include <fcntl.h>
#include <io.h>
#undef ShowCursor // Prevent conflict with Windows API
#endif
GuiManager::GuiManager() {}
@@ -103,19 +111,63 @@ void GuiManager::SetupDockspace(RenderTexture2D &renderTexture)
static std::string logContent;
static size_t lastFileSize = 0;
// Read the log file if it has changed
std::ifstream logFile("log.txt", std::ios::ate); // Open at the end to get the file size
if (logFile.is_open())
// Use std::filesystem to construct the log file path
std::filesystem::path logFilePath = std::filesystem::current_path() / "log.txt";
// Debugging: Print the log file path to the console
std::cout << "Log file path: " << logFilePath << std::endl;
// Check if the log file exists
if (std::filesystem::exists(logFilePath))
{
size_t fileSize = logFile.tellg();
if (fileSize != lastFileSize)
#ifdef _WIN32
// Convert the path to a narrow-character string
std::string logFilePathStr = logFilePath.string();
// Open the file with shared access on Windows
HANDLE hFile = CreateFileA(logFilePathStr.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
lastFileSize = fileSize;
logFile.seekg(0, std::ios::beg); // Go back to the beginning
logContent.assign((std::istreambuf_iterator<char>(logFile)),
std::istreambuf_iterator<char>());
LARGE_INTEGER fileSize;
if (GetFileSizeEx(hFile, &fileSize) && fileSize.QuadPart != lastFileSize)
{
lastFileSize = static_cast<size_t>(fileSize.QuadPart);
logContent.resize(lastFileSize);
DWORD bytesRead;
SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
ReadFile(hFile, logContent.data(), static_cast<DWORD>(lastFileSize), &bytesRead, NULL);
}
CloseHandle(hFile);
}
logFile.close();
else
{
std::cerr << "Failed to open log file with shared access: " << logFilePath << std::endl;
}
#else
// Standard file reading for non-Windows platforms
std::ifstream logFile(logFilePath, std::ios::ate);
if (logFile.is_open())
{
size_t fileSize = logFile.tellg();
if (fileSize != lastFileSize)
{
lastFileSize = fileSize;
logFile.seekg(0, std::ios::beg);
logContent.assign((std::istreambuf_iterator<char>(logFile)),
std::istreambuf_iterator<char>());
}
logFile.close();
}
else
{
std::cerr << "Failed to open log file: " << logFilePath << std::endl;
}
#endif
}
else
{
std::cerr << "Log file does not exist: " << logFilePath << std::endl;
}
// Display the log content in a scrollable text area