Logger and console colour classes working, moved math.h and started a little bit more on entitymanager and entitybase
This commit is contained in:
55
.vscode/settings.json
vendored
Normal file
55
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"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",
|
||||
"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",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
# CMAKE generated file: DO NOT EDIT!
|
||||
# Generated by "Unix Makefiles" Generator, CMake Version 3.7
|
||||
# Generated by "Unix Makefiles" Generator, CMake Version 3.12
|
||||
|
||||
# Relative path conversion top directories.
|
||||
set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/ben/Desktop/crumpet-engine")
|
||||
set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/ben/Desktop/crumpet-engine")
|
||||
set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/ben/Programming/crumpet-engine")
|
||||
set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/ben/Programming/crumpet-engine")
|
||||
|
||||
# Force unix paths in dependencies.
|
||||
set(CMAKE_FORCE_UNIX_PATHS 1)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# CMAKE generated file: DO NOT EDIT!
|
||||
# Generated by "Unix Makefiles" Generator, CMake Version 3.7
|
||||
# Generated by "Unix Makefiles" Generator, CMake Version 3.12
|
||||
|
||||
# The generator used is:
|
||||
set(CMAKE_DEPENDS_GENERATOR "Unix Makefiles")
|
||||
@@ -7,30 +7,31 @@ set(CMAKE_DEPENDS_GENERATOR "Unix Makefiles")
|
||||
# The top level Makefile was generated from the following files:
|
||||
set(CMAKE_MAKEFILE_DEPENDS
|
||||
"CMakeCache.txt"
|
||||
"CMakeFiles/3.7.2/CMakeCCompiler.cmake"
|
||||
"CMakeFiles/3.7.2/CMakeCXXCompiler.cmake"
|
||||
"CMakeFiles/3.7.2/CMakeSystem.cmake"
|
||||
"CMakeFiles/3.12.3/CMakeCCompiler.cmake"
|
||||
"CMakeFiles/3.12.3/CMakeCXXCompiler.cmake"
|
||||
"CMakeFiles/3.12.3/CMakeSystem.cmake"
|
||||
"CMakeFiles/FindSDL2_image.cmake"
|
||||
"CMakeLists.txt"
|
||||
"/usr/lib/i386-linux-gnu/cmake/SDL2/sdl2-config.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/CMakeCInformation.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/CMakeCXXInformation.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/CMakeCommonLanguageInclude.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/CMakeGenericSystem.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/CMakeLanguageInformation.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/CMakeParseArguments.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/CMakeSystemSpecificInformation.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/CMakeSystemSpecificInitialize.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/Compiler/GNU-C.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/Compiler/GNU-CXX.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/Compiler/GNU.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/FindPackageHandleStandardArgs.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/FindPackageMessage.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/Platform/Linux-GNU-C.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/Platform/Linux-GNU-CXX.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/Platform/Linux-GNU.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/Platform/Linux.cmake"
|
||||
"/usr/share/cmake-3.7/Modules/Platform/UnixPaths.cmake"
|
||||
"/usr/lib/x86_64-linux-gnu/cmake/SDL2/sdl2-config.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/CMakeCInformation.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/CMakeCXXInformation.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/CMakeCommonLanguageInclude.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/CMakeGenericSystem.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/CMakeInitializeConfigs.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/CMakeLanguageInformation.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/CMakeSystemSpecificInformation.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/CMakeSystemSpecificInitialize.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/Compiler/CMakeCommonCompilerMacros.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/Compiler/GNU-C.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/Compiler/GNU-CXX.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/Compiler/GNU.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/FindPackageHandleStandardArgs.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/FindPackageMessage.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/Platform/Linux-GNU-C.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/Platform/Linux-GNU-CXX.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/Platform/Linux-GNU.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/Platform/Linux.cmake"
|
||||
"/usr/share/cmake-3.12/Modules/Platform/UnixPaths.cmake"
|
||||
)
|
||||
|
||||
# The corresponding makefile is:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# CMAKE generated file: DO NOT EDIT!
|
||||
# Generated by "Unix Makefiles" Generator, CMake Version 3.7
|
||||
# Generated by "Unix Makefiles" Generator, CMake Version 3.12
|
||||
|
||||
# Default target executed when no arguments are given to make.
|
||||
default_target: all
|
||||
@@ -16,6 +16,11 @@ preinstall:
|
||||
|
||||
.PHONY : preinstall
|
||||
|
||||
# The main recursive clean target
|
||||
clean:
|
||||
|
||||
.PHONY : clean
|
||||
|
||||
#=============================================================================
|
||||
# Special targets provided by cmake.
|
||||
|
||||
@@ -54,10 +59,10 @@ RM = /usr/bin/cmake -E remove -f
|
||||
EQUALS = =
|
||||
|
||||
# The top-level source directory on which CMake was run.
|
||||
CMAKE_SOURCE_DIR = /home/ben/Desktop/crumpet-engine
|
||||
CMAKE_SOURCE_DIR = /home/ben/Programming/crumpet-engine
|
||||
|
||||
# The top-level build directory on which CMake was run.
|
||||
CMAKE_BINARY_DIR = /home/ben/Desktop/crumpet-engine
|
||||
CMAKE_BINARY_DIR = /home/ben/Programming/crumpet-engine
|
||||
|
||||
#=============================================================================
|
||||
# Target rules for target CMakeFiles/bin/crumpet-engine.dir
|
||||
@@ -66,7 +71,7 @@ CMAKE_BINARY_DIR = /home/ben/Desktop/crumpet-engine
|
||||
CMakeFiles/bin/crumpet-engine.dir/all:
|
||||
$(MAKE) -f CMakeFiles/bin/crumpet-engine.dir/build.make CMakeFiles/bin/crumpet-engine.dir/depend
|
||||
$(MAKE) -f CMakeFiles/bin/crumpet-engine.dir/build.make CMakeFiles/bin/crumpet-engine.dir/build
|
||||
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/ben/Desktop/crumpet-engine/CMakeFiles --progress-num=1,2,3,4,5,6,7,8,9,10,11,12 "Built target bin/crumpet-engine"
|
||||
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/ben/Programming/crumpet-engine/CMakeFiles --progress-num=1,2,3,4,5,6,7,8,9,10,11,12 "Built target bin/crumpet-engine"
|
||||
.PHONY : CMakeFiles/bin/crumpet-engine.dir/all
|
||||
|
||||
# Include target in all.
|
||||
@@ -76,9 +81,9 @@ all: CMakeFiles/bin/crumpet-engine.dir/all
|
||||
|
||||
# Build rule for subdir invocation for target.
|
||||
CMakeFiles/bin/crumpet-engine.dir/rule: cmake_check_build_system
|
||||
$(CMAKE_COMMAND) -E cmake_progress_start /home/ben/Desktop/crumpet-engine/CMakeFiles 12
|
||||
$(CMAKE_COMMAND) -E cmake_progress_start /home/ben/Programming/crumpet-engine/CMakeFiles 12
|
||||
$(MAKE) -f CMakeFiles/Makefile2 CMakeFiles/bin/crumpet-engine.dir/all
|
||||
$(CMAKE_COMMAND) -E cmake_progress_start /home/ben/Desktop/crumpet-engine/CMakeFiles 0
|
||||
$(CMAKE_COMMAND) -E cmake_progress_start /home/ben/Programming/crumpet-engine/CMakeFiles 0
|
||||
.PHONY : CMakeFiles/bin/crumpet-engine.dir/rule
|
||||
|
||||
# Convenience name for target.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
/home/ben/Desktop/crumpet-engine/CMakeFiles/rebuild_cache.dir
|
||||
/home/ben/Desktop/crumpet-engine/CMakeFiles/edit_cache.dir
|
||||
/home/ben/Desktop/crumpet-engine/CMakeFiles/bin/crumpet-engine.dir
|
||||
/home/ben/Programming/crumpet-engine/CMakeFiles/rebuild_cache.dir
|
||||
/home/ben/Programming/crumpet-engine/CMakeFiles/bin/crumpet-engine.dir
|
||||
/home/ben/Programming/crumpet-engine/CMakeFiles/edit_cache.dir
|
||||
|
||||
Binary file not shown.
57
include/colour.h
Normal file
57
include/colour.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
typedef enum {
|
||||
CONSOLE_COLOUR_FG_DEFAULT = 39,
|
||||
CONSOLE_COLOUR_FG_BLACK = 30,
|
||||
CONSOLE_COLOUR_FG_RED = 31,
|
||||
CONSOLE_COLOUR_FG_GREEN = 32,
|
||||
CONSOLE_COLOUR_FG_YELLOW = 33,
|
||||
CONSOLE_COLOUR_FG_BLUE = 34,
|
||||
CONSOLE_COLOUR_FG_MAGENTA = 35,
|
||||
CONSOLE_COLOUR_FG_CYAN = 36,
|
||||
CONSOLE_COLOUR_FG_LIGHT_GRAY = 37,
|
||||
CONSOLE_COLOUR_FG_DARK_GRAY = 90,
|
||||
CONSOLE_COLOUR_FG_LIGHT_RED = 91,
|
||||
CONSOLE_COLOUR_FG_LIGHT_GREEN = 92,
|
||||
CONSOLE_COLOUR_FG_LIGHT_YELLOW = 93,
|
||||
CONSOLE_COLOUR_FG_LIGHT_BLUE = 94,
|
||||
CONSOLE_COLOUR_FG_LIGHT_MAGENTA = 95,
|
||||
CONSOLE_COLOUR_FG_LIGHT_CYAN = 96,
|
||||
CONSOLE_COLOUR_FG_WHITE = 97
|
||||
} ConsoleForegroundColour;
|
||||
|
||||
typedef enum {
|
||||
CONSOLE_COLOUR_BG_RED = 41,
|
||||
CONSOLE_COLOUR_BG_GREEN = 42,
|
||||
CONSOLE_COLOUR_BG_BLUE = 44,
|
||||
CONSOLE_COLOUR_BG_DEFAULT = 49
|
||||
} ConsoleBackgroundColour;
|
||||
|
||||
class Colour {
|
||||
public:
|
||||
template<class T, class D>
|
||||
static std::string getColouredText(T colour, D text) {
|
||||
std::stringstream output;
|
||||
output << "\033[" << colour << "m" << text;
|
||||
output << "\033[" << CONSOLE_COLOUR_BG_DEFAULT << "m";
|
||||
output << "\033[" << CONSOLE_COLOUR_FG_DEFAULT << "m";
|
||||
return output.str();
|
||||
}
|
||||
|
||||
static void foregroundColour(ConsoleForegroundColour colour) {
|
||||
std::cout << "\033[" << colour << "m";
|
||||
}
|
||||
|
||||
static void backgroundColour(ConsoleForegroundColour colour) {
|
||||
std::cout << "\033[" << colour << "m";
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static void consoleColour(T colour) {
|
||||
std::cout << "\033[" << colour << "m";
|
||||
}
|
||||
};
|
||||
55
include/logger.h
Normal file
55
include/logger.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include <time.h>
|
||||
#include <colour.h>
|
||||
|
||||
class Logger {
|
||||
public:
|
||||
template<class T>
|
||||
static void log(T obj) {
|
||||
std::cout << getTime() << " " << obj << std::endl;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static void info(T obj) {
|
||||
std::cout
|
||||
<< getTime() << " [" << Colour::getColouredText(CONSOLE_COLOUR_FG_GREEN, "INFO")
|
||||
<< "] " << obj << std::endl;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static void warn(T obj) {
|
||||
std::cout
|
||||
<< getTime() << " [" << Colour::getColouredText(CONSOLE_COLOUR_FG_LIGHT_YELLOW, "WARN")
|
||||
<< "] " << obj << std::endl;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static void error(T obj) {
|
||||
std::cout
|
||||
<< getTime() << " [" << Colour::getColouredText(CONSOLE_COLOUR_FG_LIGHT_RED, "ERROR")
|
||||
<< "] " << obj << std::endl;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static void panic(T obj) {
|
||||
std::cout
|
||||
<< getTime() << " [" << Colour::getColouredText(CONSOLE_COLOUR_FG_RED, "PANIC")
|
||||
<< "] " << obj << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
private:
|
||||
static std::string getTime() {
|
||||
time_t t = time(NULL);
|
||||
struct tm tm = *localtime(&t);
|
||||
std::stringstream stream;
|
||||
stream << "["
|
||||
<< tm.tm_mday << "-"
|
||||
<< tm.tm_mon + 1 << "-"
|
||||
<< tm.tm_year + 1900 << " "
|
||||
<< tm.tm_hour << ":"
|
||||
<< tm.tm_min << ":"
|
||||
<< tm.tm_sec << "]";
|
||||
return stream.str();
|
||||
}
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "entitybase.h"
|
||||
|
||||
EntityBase::EntityBase() {
|
||||
EntityBase::EntityBase()
|
||||
: textureDimensions(0, 0) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <math.h>
|
||||
|
||||
#include "../resourcemanager/resourcemanager.h"
|
||||
|
||||
class EntityBase {
|
||||
public:
|
||||
EntityBase();
|
||||
|
||||
std::string texture;
|
||||
SDL_Texture* texture;
|
||||
|
||||
virtual ~EntityBase();
|
||||
private:
|
||||
std::string textureRef;
|
||||
std::string textureSource;
|
||||
Vec2 textureDimensions;
|
||||
};
|
||||
|
||||
@@ -4,16 +4,15 @@
|
||||
#include <map>
|
||||
|
||||
#include "entity.h"
|
||||
#include "../resourcemanager/resourcemanager.h"
|
||||
|
||||
class EntityManager {
|
||||
public:
|
||||
EntityManager(ResourceManger* resourceManager);
|
||||
|
||||
|
||||
int registerEntity(Entity* entity);
|
||||
|
||||
virtual ~EntityManager();
|
||||
private:
|
||||
std::map<unsigned short int, Entity> m_activeEntities;
|
||||
std::map<unsigned short int, Entity*> m_activeEntities;
|
||||
ResourceManger* resourceManger;
|
||||
};
|
||||
|
||||
@@ -6,17 +6,19 @@ Renderer::Renderer() {
|
||||
|
||||
void Renderer::createWindow(std::string title, int width, int height, ScreenMode mode) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
std::cout << "SDL could not initialize, SDL ERROR: " << SDL_GetError() << std::endl;
|
||||
Logger::error("SDL could not initialize, SDL ERROR: ");
|
||||
Logger::panic(SDL_GetError());
|
||||
}
|
||||
std::cout << "SDL initialized" << std::endl;
|
||||
Logger::info("SDL Initialized");
|
||||
|
||||
m_window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN);
|
||||
std::cout << "SDL window created" << std::endl;
|
||||
Logger::info("SDL Window Created");
|
||||
|
||||
if (mode == SCREEN_MODE_DEFAULT)
|
||||
SDLRenderer = SDL_CreateRenderer(m_window, -1, SDL_RENDERER_ACCELERATED);
|
||||
if (mode == SCREEN_MODE_VSYNC)
|
||||
SDLRenderer = SDL_CreateRenderer(m_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
||||
Logger::info("SDL Render Context Initalized");
|
||||
|
||||
SDL_SetRenderDrawColor(SDLRenderer, 66, 134, 244, 255);
|
||||
m_isWindowClosed = false;
|
||||
@@ -30,7 +32,7 @@ void Renderer::destroyWindow() {
|
||||
m_isWindowClosed = true;
|
||||
SDL_DestroyWindow(m_window);
|
||||
SDL_Quit();
|
||||
std::cout << "SDL uninitialized" << std::endl;
|
||||
Logger::info("SDL Uninitialized");
|
||||
}
|
||||
|
||||
void Renderer::clear() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <logger.h>
|
||||
#include <string>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
|
||||
@@ -8,12 +8,14 @@ bool TextureManager::registerTexture(std::string textureSource, std::string text
|
||||
SDL_Texture* texture;
|
||||
SDL_Surface* loadSurface = IMG_Load(textureSource.c_str());
|
||||
if (loadSurface == NULL) {
|
||||
std::cout << "ERROR LOADING SURFACE " << SDL_GetError() << std::endl;
|
||||
Logger::error("ERROR LOADING SURFACE");
|
||||
Logger::panic(SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
texture = SDL_CreateTextureFromSurface(m_renderer->SDLRenderer, loadSurface);
|
||||
if (texture == NULL) {
|
||||
std::cout << "ERROR LOADING TEXTURE " << SDL_GetError() << std::endl;
|
||||
Logger::error("ERROR LOADING TEXTURE");
|
||||
Logger::panic(SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
SDL_FreeSurface(loadSurface);
|
||||
@@ -21,6 +23,8 @@ bool TextureManager::registerTexture(std::string textureSource, std::string text
|
||||
m_textureSources[textureName] = textureSource;
|
||||
m_registerdTextures[textureName] = texture;
|
||||
|
||||
Logger::info("Loaded texture " + textureSource + " as " + textureName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <iostream>
|
||||
#include <logger.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user