diff --git a/CMakeLists.txt b/CMakeLists.txt index c451033..4cb1666 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,11 +3,7 @@ project(MingeCraft) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} CMakeModules/) -<<<<<<< HEAD -set(CMAKE_BUILD_TYPE Debug) -======= # set(CMAKE_BUILD_TYPE Debug) ->>>>>>> dev set(CMAKE_CXX_FLAGS "-Ofast") set(executable output) @@ -46,11 +42,7 @@ include_directories(${executable} file(GLOB SourceFiles ${SrcDIR}/* - ${SrcDIR}/util/* - ${SrcDIR}/game/* - ${SrcDIR}/world/* - ${SrcDIR}/world/chunk/* - ${SrcDIR}/renderer/* + ${SrcDIR}/ThirdParty/* ) add_executable(${executable} ${SourceFiles}) diff --git a/legacy/src/util/fastnoise.cpp b/src/ThirdParty/fastnoise.cpp similarity index 100% rename from legacy/src/util/fastnoise.cpp rename to src/ThirdParty/fastnoise.cpp diff --git a/legacy/src/util/fastnoise.hpp b/src/ThirdParty/fastnoise.hpp similarity index 100% rename from legacy/src/util/fastnoise.hpp rename to src/ThirdParty/fastnoise.hpp diff --git a/legacy/src/util/glad.c b/src/ThirdParty/glad.c similarity index 100% rename from legacy/src/util/glad.c rename to src/ThirdParty/glad.c diff --git a/legacy/src/util/stb_image.hpp b/src/ThirdParty/stb_image.hpp similarity index 100% rename from legacy/src/util/stb_image.hpp rename to src/ThirdParty/stb_image.hpp diff --git a/legacy/src/util/stb_image_write.hpp b/src/ThirdParty/stb_image_write.hpp similarity index 100% rename from legacy/src/util/stb_image_write.hpp rename to src/ThirdParty/stb_image_write.hpp diff --git a/src/display.cpp b/src/display.cpp new file mode 100644 index 0000000..eb64dce --- /dev/null +++ b/src/display.cpp @@ -0,0 +1,120 @@ +#include "display.hpp" + +Display::Display( int w, int h, std::string title ) + : mLogger() +{ + + mLogger << LOGGER_INFO << "Initializing display" << LOGGER_ENDL; + SDL_Init( SDL_INIT_VIDEO|SDL_INIT_AUDIO ); + + SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 ); + SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 ); + SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 ); + SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 ); + SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, 32 ); + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + + SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, 1 ); + SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 4 ); + + SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 4 ); + SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 5 ); + + // Create GL window + mLogger << LOGGER_INFO << "Creating window" << LOGGER_ENDL; + mWindow = SDL_CreateWindow( title.c_str(), + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, w, h, + SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE ); + + // Create GL context + mLogger << LOGGER_INFO << "Creating OpenGL context" << LOGGER_ENDL; + mGlContext = SDL_GL_CreateContext( mWindow ); + + SDL_SetRelativeMouseMode( SDL_TRUE ); + + // Set VSYNC swap interval + SDL_GL_SetSwapInterval( 1 ); + + mLogger << LOGGER_INFO << "Display set up" << LOGGER_ENDL; + + // Load OpenGL + gladLoadGLLoader( SDL_GL_GetProcAddress ); + glEnable( GL_MULTISAMPLE ); + // glEnable(GL_CULL_FACE); + glCullFace( GL_BACK ); + glEnable( GL_DEPTH_TEST ); + // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + + mLogger << LOGGER_INFO << "Loaded OpenGL" << LOGGER_ENDL; + mLogger << LOGGER_ENDL; + + IsWindowOpen = true; + +} + +void Display::Input( SDL_Event* e ) +{ + + Uint8* state = (Uint8*) SDL_GetKeyboardState( NULL ); + + while ( SDL_PollEvent( e ) ) + { + + switch ( e->type ) + { + + case SDL_KEYDOWN: + { + if ( e->key.keysym.sym == SDLK_ESCAPE ) + { + IsMouseActive = !IsMouseActive; + + if ( IsMouseActive ) + SDL_SetRelativeMouseMode( SDL_TRUE ); + else + SDL_SetRelativeMouseMode( SDL_FALSE ); + } + + break; + } + + case SDL_WINDOWEVENT: + { + if ( e->window.event == SDL_WINDOWEVENT_RESIZED ) + { + // CameraUpdateProjection( e->window.data1, e->window.data2 ); + glViewport( 0, 0, e->window.data1, e->window.data2 ); + } + + break; + } + + case SDL_QUIT: + { + IsWindowOpen = false; + break; + } + + } + + // if ( IsMouseActive ) m_player->HandleMouseSDL( *e ); + } + + // m_player->MoveSDL( state ); + +} + +void Display::PrepareFrame() +{ + static const float clear[] = { 186.0f / 255.0f, 214.0f / 255.0f, 254.0f / 255.0f }; + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glClearBufferfv( GL_COLOR, 0, clear ); +} + +void Display::NextFrame() +{ + SDL_GL_SwapWindow( mWindow ); +} + diff --git a/src/display.hpp b/src/display.hpp new file mode 100644 index 0000000..487be4b --- /dev/null +++ b/src/display.hpp @@ -0,0 +1,42 @@ +#ifndef MINECRAFT_DISPLAY_H_ +#define MINECRAFT_DISPLAY_H_ + +#include + +#include + +#if _WIN32 +#include +#else +#include +#endif + +#include +#include + +class Display +{ +public: + + Display( int w, int h, std::string title ); + + void Input( SDL_Event* e ); + + void PrepareFrame(); + void NextFrame(); + + bool IsWindowOpen = false; + bool IsMouseActive = true; + +private: + + Logger mLogger; + + SDL_Window* mWindow = nullptr; + SDL_GLContext mGlContext = nullptr; + + int mW, mH; + +}; + +#endif diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..3bfc896 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,78 @@ +#include +#include + +#define LOGGER_DEFINITION +#include + +#if _WIN32 +#include +#else +#include +#endif + +#include "display.hpp" +#include "settings.hpp" + + +#define __DEBUG + +static const int VERSION_MAJOR = 1; +static const int VERSION_MINOR = 1; +static const int VERSION_PATCH = 0; + +void version() +{ + std::stringstream version; + + auto& container = []( std::string s ) { std::string r = ""; for ( auto& c : s ) { r += "-"; } return r; }; + + version << "Minecraft "; + version << VERSION_MAJOR << "." << VERSION_MINOR << "." << VERSION_PATCH; + + std::cout << container( version.str() ) << std::endl; + std::cout << version.str() << std::endl; + std::cout << container( version.str() ) << std::endl; +} + +void Loop( Display* display ) +{ + SDL_Event e; + + while ( display->IsWindowOpen ) + { + display->PrepareFrame(); + + // make framerate agnostic + display->Input( &e ); + + + // rendering here + + display->NextFrame(); + } + + // cleanup + +} + +int main( int argc, char** argv ) +{ + version(); + + Logger mLogger; + +#ifdef __DEBUG + mLogger << LOGGER_DEBUG << "Debug mode enabled" << LOGGER_ENDL; +#endif + + // settup display + + std::stringstream version; + version << "Minecraft "; + version << VERSION_MAJOR << "." << VERSION_MINOR << "." << VERSION_PATCH; + + Display display { WindowWidth, WindowHeight, version.str() }; + + Loop( &display ); + +} diff --git a/src/settings.hpp b/src/settings.hpp new file mode 100644 index 0000000..08c49d3 --- /dev/null +++ b/src/settings.hpp @@ -0,0 +1,10 @@ +#ifndef MINECRAFT_SETTINGS_H_ +#define MINECRAFT_SETTINGS_H_ + +// TODO: import settings and stuff +// for now this works + +static const int WindowWidth = 1000; +static const int WindowHeight = 600; + +#endif