diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ddf614e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,57 @@ +{ + "files.associations": { + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "array": "cpp", + "atomic": "cpp", + "strstream": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "chrono": "cpp", + "complex": "cpp", + "condition_variable": "cpp", + "cstdint": "cpp", + "deque": "cpp", + "list": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "fstream": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "thread": "cpp", + "cinttypes": "cpp", + "type_traits": "cpp", + "tuple": "cpp", + "typeindex": "cpp", + "typeinfo": "cpp", + "utility": "cpp", + "variant": "cpp" + } +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index d880678..0e50163 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ include_directories(${executable} ${IncludeDIR} ) -file(GLOB_RECURSE SourceFiles +file(GLOB SourceFiles ${SrcDIR}/* ) diff --git a/include/logger.h b/include/logger.h index 58951fb..8f75454 100644 --- a/include/logger.h +++ b/include/logger.h @@ -61,13 +61,18 @@ typedef enum { } ConsoleColour; #endif - class Colour { public: static void resetColour(); - template - static void consoleColour(T colour); + template + static void consoleColour(T colour) { + #ifdef _WIN32 + SetConsoleTextAttribute(h, colour); + #else + std::cout << "\033[" << colour << "m"; + #endif + } }; typedef enum { @@ -85,7 +90,6 @@ typedef enum { class Logger { public: - std::stringstream outStream; std::map lookupTable; Logger(); @@ -122,7 +126,6 @@ public: #ifdef LOGGER_DEFINITION #undef LOGGER_DEFINITION - void Colour::resetColour() { #ifdef _WIN32 SetConsoleTextAttribute(h, CONSOLE_COLOUR_BG_DEFAULT); @@ -134,15 +137,6 @@ void Colour::resetColour() { #endif } -template -void Colour::consoleColour(T colour) { -#ifdef _WIN32 - SetConsoleTextAttribute(h, colour); -#else - std::cout << "\033[" << colour << "m"; -#endif -} - Logger::Logger() { #ifdef _WIN32 diff --git a/legacy/main.cpp b/legacy/main.cpp index a8acf06..64a01f8 100644 --- a/legacy/main.cpp +++ b/legacy/main.cpp @@ -19,7 +19,7 @@ #include // Custom includes -#define LOGGER_DEFINITION +// #define LOGGER_DEFINITION #include #include "timers.h" #include "object.h" diff --git a/src/display.cpp b/src/display.cpp index dc4a294..cca779f 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1,12 +1,14 @@ #include "display.h" -Display::Display(std::string name, int w, int h, Logger& logger, +Display::Display(std::string name, Logger& logger, int w, int h, SMH_VSYNC_DISPLAY_MODE vsyncMode, - SMH_MXAA_MODE mxaaMode) { + SMH_MXAA_MODE mxaaMode) + : logger(logger) { MXAAMode = mxaaMode; VSyncMode = vsyncMode; + logger << LOGGER_INFO << "Initializing display" << LOGGER_ENDL; SDL_Init(SDL_INIT_EVERYTHING); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); @@ -44,36 +46,56 @@ Display::Display(std::string name, int w, int h, Logger& logger, SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, mxaaLevel); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, smxaaLevel.c_str()); + logger << LOGGER_INFO << "MXAA set to " << mxaaLevel << "xMSAA" << LOGGER_ENDL; + } else { + logger << LOGGER_INFO << "MXAA disabled" << LOGGER_ENDL; } SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5); // Create GL window + logger << LOGGER_INFO << "Creating window" << LOGGER_ENDL; window = SDL_CreateWindow(name.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_OPENGL); // Create GL context + logger << LOGGER_INFO << "Creating OpenGL context" << LOGGER_ENDL; glContext = SDL_GL_CreateContext(window); // Set VSYNC swap interval - if (vsyncMode == VSYNC_DEFAULT || vsyncMode == VSYNC_ENABLED) + if (vsyncMode == VSYNC_DEFAULT || vsyncMode == VSYNC_ENABLED) { SDL_GL_SetSwapInterval(1); - if (vsyncMode == VSYNC_DISABLED) + logger << LOGGER_INFO << "VSync enabled" << LOGGER_ENDL; + } + if (vsyncMode == VSYNC_DISABLED) { SDL_GL_SetSwapInterval(0); + logger << LOGGER_INFO << "VSync disabled" << LOGGER_ENDL; + } + + logger << LOGGER_INFO << "Display set up" << LOGGER_ENDL; // Load OpenGL gladLoadGLLoader(SDL_GL_GetProcAddress); + logger << LOGGER_INFO << "Loaded OpenGL" << LOGGER_ENDL; + logger << LOGGER_ENDL; + isClosed = false; } -Display::Display(std::string name, int w, int h, Logger& logger, + + + + +Display::Display(std::string name, Logger& logger, int w, int h, SMH_MXAA_MODE mxaaMode, - SMH_VSYNC_DISPLAY_MODE vsyncMode) { + SMH_VSYNC_DISPLAY_MODE vsyncMode) + : logger(logger) { MXAAMode = mxaaMode; VSyncMode = vsyncMode; + logger << LOGGER_INFO << "Initializing display" << LOGGER_ENDL; SDL_Init(SDL_INIT_EVERYTHING); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); @@ -111,27 +133,41 @@ Display::Display(std::string name, int w, int h, Logger& logger, SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, mxaaLevel); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, smxaaLevel.c_str()); + logger << LOGGER_INFO << "MXAA set to " << mxaaLevel << "xMSAA" << LOGGER_ENDL; + } else { + logger << LOGGER_INFO << "MXAA disabled" << LOGGER_ENDL; } SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5); // Create GL window + logger << LOGGER_INFO << "Creating window" << LOGGER_ENDL; window = SDL_CreateWindow(name.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_OPENGL); // Create GL context + logger << LOGGER_INFO << "Creating OpenGL context" << LOGGER_ENDL; glContext = SDL_GL_CreateContext(window); // Set VSYNC swap interval - if (vsyncMode == VSYNC_DEFAULT || vsyncMode == VSYNC_ENABLED) + if (vsyncMode == VSYNC_DEFAULT || vsyncMode == VSYNC_ENABLED) { SDL_GL_SetSwapInterval(1); - if (vsyncMode == VSYNC_DISABLED) + logger << LOGGER_INFO << "VSync enabled" << LOGGER_ENDL; + } + if (vsyncMode == VSYNC_DISABLED) { SDL_GL_SetSwapInterval(0); + logger << LOGGER_INFO << "VSync disabled" << LOGGER_ENDL; + } + + logger << LOGGER_INFO << "Display set up" << LOGGER_ENDL; // Load OpenGL gladLoadGLLoader(SDL_GL_GetProcAddress); + logger << LOGGER_INFO << "Loaded OpenGL" << LOGGER_ENDL; + logger << LOGGER_ENDL; + isClosed = false; } void Display::setName(std::string name) { diff --git a/src/display.h b/src/display.h index f08909d..1b994ad 100644 --- a/src/display.h +++ b/src/display.h @@ -33,23 +33,27 @@ typedef enum { class Display { public: - Display(std::string name, int w, int h, Logger& logger, + Display(std::string name, Logger& logger, int w, int h, SMH_VSYNC_DISPLAY_MODE vsyncMode = VSYNC_DEFAULT, SMH_MXAA_MODE mxaaMode = MXAA_DEFAULT); - Display(std::string name, int w, int h, Logger& logger, + Display(std::string name, Logger& logger, int w, int h, SMH_MXAA_MODE mxaaMode = MXAA_DEFAULT, SMH_VSYNC_DISPLAY_MODE vsyncMode = VSYNC_DEFAULT); void setName(std::string name); + bool isClosed = true; + SDL_Window* window; SDL_GLContext glContext; SMH_VSYNC_DISPLAY_MODE VSyncMode = VSYNC_DEFAULT; - SMH_MXAA_MODE MXAAMode = MXAA_DEFAULT; + SMH_MXAA_MODE MXAAMode = MXAA_DEFAULT; virtual ~Display(); +private: + Logger& logger; }; #endif diff --git a/src/main.cpp b/src/main.cpp index be42290..b13a112 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,9 +2,9 @@ #include #include -#include -#include -#include +// #include +// #include +// #include // Custom includes #define LOGGER_DEFINITION @@ -13,10 +13,22 @@ #include "display.h" int main (int argc, char** argv) { - Logger logger; - Display display {"SMH Engine", 1280, 720, logger, MXAA_8X, VSYNC_ENABLED}; - + std::cout << "-----------------------------\n" + << "----- SMH Render Engine -----\n" + << "-------- Version 0.0 --------\n" + << "----- ©Benjamin Kyd 2019 ----\n" + << "-----------------------------\n\n"; + + Logger logger; + + Display display {"SMH Engine", logger, 1280, 720, MXAA_4X, VSYNC_ENABLED}; + + SDL_Event e; + while (!display.isClosed) + while (SDL_PollEvent(&e)) + if (e.type == SDL_QUIT || e.key.keysym.sym == SDLK_ESCAPE) + display.isClosed = true; return 0; }