Updated logger and minors tweaks
This commit is contained in:
parent
a4e0f7459e
commit
d1937d4f26
@ -46,7 +46,6 @@ endif()
|
||||
# targets declarations
|
||||
add_executable(${PROJECT_NAME})
|
||||
target_precompile_headers(${PROJECT_NAME} PRIVATE
|
||||
"$<$<COMPILE_LANGUAGE:CXX>:<iostream$<ANGLE-R>>"
|
||||
"$<$<COMPILE_LANGUAGE:CXX>:<string$<ANGLE-R>>"
|
||||
"$<$<COMPILE_LANGUAGE:CXX>:<stdexcept$<ANGLE-R>>"
|
||||
"$<$<COMPILE_LANGUAGE:CXX>:<vector$<ANGLE-R>>"
|
||||
|
@ -104,7 +104,7 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
|
||||
auto& oMesh = obj->GetObjectMesh();
|
||||
M3D_V3TransformPersDiv(
|
||||
projVertices + processedVerticesCnt, sizeof(M3D_F3),
|
||||
(M3D_F3*)oMesh.vertices.data(), sizeof(Vertex),
|
||||
reinterpret_cast<const M3D_F3*>(oMesh.vertices.data()), sizeof(M3D_F4),
|
||||
oMesh.vertices.size(),
|
||||
obj->GetTransform() * viewProjMat
|
||||
);
|
||||
@ -112,7 +112,7 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
|
||||
//TODO: Fill a z-depth buffer...
|
||||
|
||||
for (auto& objPt : obj->GetObjectMesh().parts) {
|
||||
auto indicePtr = (uint32_t*)objPt.indices.data();
|
||||
auto indicePtr = static_cast<const uint32_t*>(objPt.indices.data());
|
||||
for (uint32_t i = 0; i < objPt.GetIndicesCount(); i += 3) {
|
||||
// Misscontructed indices tree failsafe
|
||||
if (i+2 > objPt.GetIndicesCount())
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "Logger.hpp"
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
enum LOG_TYPE{
|
||||
@ -15,44 +16,73 @@ Logger* Logger::smInstance = nullptr;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void LogConsolePrint(const LOG_TYPE logType, const std::string& message, const double time) {
|
||||
std::cout << std::fixed << std::setprecision(6) << '[' << time;
|
||||
|
||||
inline static std::string GetLabelType(const LOG_TYPE logType) {
|
||||
switch (logType) {
|
||||
case LOG_TYPE_DBG:
|
||||
std::cout << "][DEBUG] ";
|
||||
return "][DEBUG] ";
|
||||
break;
|
||||
case LOG_TYPE_CRIT:
|
||||
std::cout << "][CRIT] ";
|
||||
return "][CRIT] ";
|
||||
break;
|
||||
case LOG_TYPE_WARN:
|
||||
std::cout << "][WARN] ";
|
||||
return "][WARN] ";
|
||||
break;
|
||||
case LOG_TYPE_INFO:
|
||||
default:
|
||||
std::cout << "][INFO] ";
|
||||
return "][INFO] ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void LogConsolePrint(const LOG_TYPE logType, const std::string& message, const double time) {
|
||||
std::cout << std::fixed << std::setprecision(6) << '[' << time;
|
||||
std::cout << GetLabelType(logType);
|
||||
std::cout << message << std::endl;
|
||||
}
|
||||
|
||||
static void LogFilePrint(const LOG_TYPE logType, const std::string& message, const double time) {
|
||||
std::ofstream outLogFile;
|
||||
outLogFile.open("log.txt", std::ios::app);
|
||||
|
||||
if (outLogFile.is_open()) {
|
||||
outLogFile << std::fixed << std::setprecision(6) << '[' << time;
|
||||
outLogFile << GetLabelType(logType);
|
||||
outLogFile << message << std::endl;
|
||||
|
||||
outLogFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
Logger::Logger() {
|
||||
mLogTimer = std::make_unique<SysTimer>();
|
||||
PrintInfo("Log module ready");
|
||||
LogConsolePrint(LOG_TYPE_INFO, "Log module ready", mLogTimer->GetElapsedTimeS());
|
||||
}
|
||||
|
||||
void Logger::PrintInfo(std::string _in) { LogConsolePrint(LOG_TYPE_INFO, _in, mLogTimer->GetElapsedTimeS()); }
|
||||
void Logger::PrintInfo(std::string _in, bool writeToFile) {
|
||||
LogConsolePrint(LOG_TYPE_INFO, _in, mLogTimer->GetElapsedTimeS());
|
||||
if (writeToFile)
|
||||
LogFilePrint(LOG_TYPE_INFO, _in, mLogTimer->GetElapsedTimeS());
|
||||
}
|
||||
|
||||
void Logger::PrintWarning(std::string _in) { LogConsolePrint(LOG_TYPE_WARN, _in, mLogTimer->GetElapsedTimeS()); }
|
||||
void Logger::PrintWarning(std::string _in, bool writeToFile) {
|
||||
LogConsolePrint(LOG_TYPE_WARN, _in, mLogTimer->GetElapsedTimeS());
|
||||
if (writeToFile)
|
||||
LogFilePrint(LOG_TYPE_WARN, _in, mLogTimer->GetElapsedTimeS());
|
||||
}
|
||||
|
||||
void Logger::PrintCritical(std::string _in) { LogConsolePrint(LOG_TYPE_CRIT, _in, mLogTimer->GetElapsedTimeS()); }
|
||||
void Logger::PrintCritical(std::string _in, bool writeToFile) {
|
||||
LogConsolePrint(LOG_TYPE_CRIT, _in, mLogTimer->GetElapsedTimeS());
|
||||
if (writeToFile)
|
||||
LogFilePrint(LOG_TYPE_CRIT, _in, mLogTimer->GetElapsedTimeS());
|
||||
}
|
||||
|
||||
void Logger::PrintDebug(std::string _in) {
|
||||
void Logger::PrintDebug(std::string _in, bool writeToFile) {
|
||||
#ifdef _DEBUG
|
||||
LogConsolePrint(LOG_TYPE_DBG, _in, mLogTimer->GetElapsedTimeS());
|
||||
if (writeToFile)
|
||||
LogFilePrint(LOG_TYPE_DBG, _in, mLogTimer->GetElapsedTimeS());
|
||||
#endif
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "../Utils/Timers.hpp"
|
||||
|
||||
|
||||
@ -19,10 +21,10 @@ public:
|
||||
Logger(Logger const&) = delete;
|
||||
Logger& operator= (Logger const&) = delete;
|
||||
|
||||
void PrintInfo(std::string inPrt);
|
||||
void PrintWarning(std::string inPrt);
|
||||
void PrintCritical(std::string inPrt);
|
||||
void PrintDebug(std::string inPrt);
|
||||
void PrintInfo(std::string inPrt, bool writeToFile = false);
|
||||
void PrintWarning(std::string inPrt, bool writeToFile = false);
|
||||
void PrintCritical(std::string inPrt, bool writeToFile = false);
|
||||
void PrintDebug(std::string inPrt, bool writeToFile = false);
|
||||
|
||||
private:
|
||||
Logger() noexcept(false);
|
||||
|
3
Game.cpp
3
Game.cpp
@ -5,6 +5,7 @@
|
||||
#include <SFML/Window/Keyboard.hpp>
|
||||
#include <SFML/Window/Mouse.hpp>
|
||||
|
||||
#include "Engine/Misc/Logger.hpp"
|
||||
#include "Engine/Utils/Perfs.hpp"
|
||||
|
||||
using std::make_shared;
|
||||
@ -39,7 +40,7 @@ GAME_STATUS Game::Tick() {
|
||||
msTicksMonitoring.push_back(((1000000.f / TARGET_FPS) - mLastCycleSleepDelta) * TARGET_FPS / 1000000.f);
|
||||
if (mPerfsTimer->GetDeltaTime() >= 1000) { // Every 1s
|
||||
// This average CPU/cycle_time method can monitor when CPU is in overload state (>0%) or in underload one (<0%)
|
||||
double cpuUsage = 200 * std::accumulate(msTicksMonitoring.begin(), msTicksMonitoring.end(), (double)(0)) / msTicksMonitoring.size() - 100;
|
||||
double cpuUsage = 200 * std::accumulate(msTicksMonitoring.begin(), msTicksMonitoring.end(), static_cast<double>(0)) / msTicksMonitoring.size() - 100;
|
||||
|
||||
mDbgUI->UpdateDebugData(cpuUsage, (((1000000.f / TARGET_FPS) - mLastCycleSleepDelta) / 1000), ((-mPrevdelta + mSysTimer.GetDeltaTimeUs()) / 1000), mFrameCnt, (PerfsGetVirtMem() / 1000), (PerfsGetPhysMem() / 1000));
|
||||
|
||||
|
1
Game.hpp
1
Game.hpp
@ -14,6 +14,7 @@ typedef enum eGameStatus {
|
||||
GAME_QUIT
|
||||
} GAME_STATUS;
|
||||
|
||||
//TODO: Use thread for Update/Render instance
|
||||
class Game final {
|
||||
public:
|
||||
static Game& getInstance(std::shared_ptr<sf::RenderWindow> mainWnd, bool dbgFlag) {
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "Game.hpp"
|
||||
|
||||
|
||||
static std::shared_ptr<sf::RenderWindow> InitWindow();
|
||||
static std::shared_ptr<sf::RenderWindow> InitWindow(unsigned int width, unsigned int height, bool fullscreen);
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Logger& log = Logger::getInstance();
|
||||
@ -17,7 +17,7 @@ int main(int argc, char** argv) {
|
||||
log.PrintInfo(LOGGER_MSG_FT("Create main window"));
|
||||
std::shared_ptr<sf::RenderWindow> mainWindow = nullptr;
|
||||
try {
|
||||
mainWindow = InitWindow();
|
||||
mainWindow = InitWindow(1280, 720, false);
|
||||
} catch (const std::exception& ex) {
|
||||
log.PrintCritical(std::string(ex.what()));
|
||||
return EXIT_FAILURE;
|
||||
@ -30,7 +30,6 @@ int main(int argc, char** argv) {
|
||||
for ( ;; ) {
|
||||
sf::Event event;
|
||||
while (mainWindow->pollEvent(event)) {
|
||||
if (event.type == sf::Event::Closed)
|
||||
switch (event.type) {
|
||||
case sf::Event::Closed:
|
||||
mainWindow->close();
|
||||
@ -43,11 +42,11 @@ int main(int argc, char** argv) {
|
||||
break;
|
||||
|
||||
//case sf::Event::LostFocus:
|
||||
// pause();
|
||||
// EventSuspending();
|
||||
// break;
|
||||
|
||||
//case sf::Event::GainedFocus:
|
||||
// resume();
|
||||
// EventResuming();
|
||||
// break;
|
||||
|
||||
default:
|
||||
@ -67,6 +66,11 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
|
||||
mainWindow->close();
|
||||
status = GAME_QUIT;
|
||||
}
|
||||
|
||||
status = arcadeGame.Tick();
|
||||
|
||||
if (status == GAME_QUIT)
|
||||
@ -77,7 +81,7 @@ int main(int argc, char** argv) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static std::shared_ptr<sf::RenderWindow> InitWindow() {
|
||||
static std::shared_ptr<sf::RenderWindow> InitWindow(unsigned int width, unsigned int height, bool fullscreen) {
|
||||
// Create default game window
|
||||
sf::ContextSettings sWindowSettings;
|
||||
sWindowSettings.depthBits = 0;
|
||||
@ -85,9 +89,13 @@ static std::shared_ptr<sf::RenderWindow> InitWindow() {
|
||||
sWindowSettings.antialiasingLevel = 8;
|
||||
sWindowSettings.sRgbCapable = true;
|
||||
|
||||
sf::Uint32 wndStyle = sf::Style::Close | sf::Style::Titlebar;
|
||||
if(fullscreen)
|
||||
wndStyle = wndStyle | sf::Style::Fullscreen;
|
||||
|
||||
auto wnd = std::make_shared<sf::RenderWindow>(
|
||||
sf::VideoMode(1280, 720), "ProtoTank",
|
||||
(sf::Style::Close | sf::Style::Titlebar),
|
||||
sf::VideoMode(width, height), "ProtoTank",
|
||||
wndStyle,
|
||||
sWindowSettings
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user