File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -3,18 +3,23 @@ project(ChessEngine)
33
44set (CMAKE_CXX_STANDARD 23)
55option (WASM "Build Webassembly binary" TRUE )
6+ option (LOGTOFILE "Make a file with a detailed search log" FALSE )
67
78add_executable (ChessEngine main.cpp)
89
910set (CMAKE_CXX_FLAGS "-std=c++23" )
1011
11- message ("WASM=${WASM} " )
1212if (WASM)
1313 message ("Building for Webassembly" )
1414 add_compile_definitions (wasm)
1515 set (CMAKE_CXX_FLAGS "-std=c++23 -fexperimental-library" )
1616endif ()
1717
18+ if (LOGTOFILE)
19+ message ("Logging to file enabled" )
20+ add_compile_definitions (logtofile)
21+ endif ()
22+
1823include_directories (src)
1924add_subdirectory (src)
2025
Original file line number Diff line number Diff line change 11#include " Logger.h"
22
33#include < iostream>
4- #include < format>
54
65#ifdef wasm
76#include " emscripten.h"
1110void Logger::start () {
1211 stop = false ;
1312 processingThread = std::thread (&Logger::threadFunc, this );
13+ #ifdef logtofile
1414 logFile.open (" log.txt" );
15+ #endif
1516}
1617
1718void Logger::end () {
1819 stop = true ;
1920 processingThread.join ();
21+ #ifdef logtofile
2022 logFile.close ();
23+ #endif
2124}
2225
2326void Logger::log (const std::string message) const {
@@ -29,29 +32,38 @@ void Logger::log(const std::string message) const {
2932}
3033
3134void Logger::logToFile (std::string message) const {
35+ // Since the function doesn't do anything with the flag disabled the compiler should technically remove it and all the calls to it
36+ #ifdef logtofile
3237 auto * newNode = new MessageNode ();
3338 newNode->type = TOFILE;
3439 newNode->msg = message;
3540 tail->next = newNode;
3641 tail = newNode;
42+ #endif
3743}
3844
3945void Logger::sendInt (const std::string name, const int value) const {
46+ // Since the function doesn't do anything with the flag disabled the compiler should technically remove it and all the calls to it
47+ #ifdef wasm
4048 auto * newNode = new IntNode ();
4149 newNode->type = INT;
4250 newNode->name = name;
4351 newNode->value = value;
4452 tail->next = newNode;
4553 tail = newNode;
54+ #endif
4655}
4756
4857void Logger::sendString (const std::string name, const std::string value) const {
58+ // Since the function doesn't do anything with the flag disabled the compiler should technically remove it and all the calls to it
59+ #ifdef wasm
4960 auto * newNode = new StringNode ();
5061 newNode->type = STRING;
5162 newNode->name = name;
5263 newNode->value = value;
5364 tail->next = newNode;
5465 tail = newNode;
66+ #endif
5567}
5668
5769
@@ -83,10 +95,12 @@ bool Logger::processNode() const {
8395 if (newHead->type == LOG) {
8496 std::cout << reinterpret_cast <MessageNode *>(newHead)->msg ;
8597 }
98+ #ifdef logtofile
8699 else if (newHead->type == TOFILE) {
87100 logFile << reinterpret_cast <MessageNode *>(newHead)->msg ;
88101 }
89102#endif
103+ #endif
90104
91105#ifdef wasm
92106 switch (newHead->type ) {
You can’t perform that action at this time.
0 commit comments