Compare commits
7 Commits
working_ve
...
4e5a1bec24
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e5a1bec24 | ||
|
|
72a359bce7 | ||
|
|
8f9318c83a | ||
|
|
1ce214bf7f | ||
|
|
a81d6bd00f | ||
|
|
7e859edd8e | ||
|
|
b2ac1f3757 |
@@ -1,10 +1,9 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
project(OpenGLPlayground)
|
||||
project(MingeCraft)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} CMakeModules/)
|
||||
cmake_policy(SET CMP0037 OLD)
|
||||
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
# set(CMAKE_BUILD_TYPE Debug)
|
||||
set(CMAKE_CXX_FLAGS "-Ofast")
|
||||
|
||||
set(executable output)
|
||||
@@ -43,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})
|
||||
|
||||
27
legacy/resources/shaders/simple.frag
Normal file
27
legacy/resources/shaders/simple.frag
Normal file
@@ -0,0 +1,27 @@
|
||||
#version 450
|
||||
|
||||
vec3 SkyColour = vec3(186.0f / 255.0f, 214.0f / 255.0f, 254.0f / 255.0f);
|
||||
|
||||
in vec3 TexCoord;
|
||||
in float Distance;
|
||||
|
||||
out vec4 outColour;
|
||||
|
||||
uniform sampler2DArray tex;
|
||||
|
||||
void main() {
|
||||
|
||||
outColour = texture(tex, TexCoord);
|
||||
//outColour = vec4(.9, .9, .9, 1);
|
||||
|
||||
if (outColour.w == .0)
|
||||
discard;
|
||||
|
||||
float fogMax = 60000;
|
||||
|
||||
vec3 colour = mix(outColour.xyz, SkyColour, min(1.0f, Distance / fogMax));
|
||||
|
||||
// Retain fragment transparency
|
||||
outColour = vec4(colour, outColour.w);
|
||||
|
||||
}
|
||||
26
legacy/resources/shaders/simple.vert
Normal file
26
legacy/resources/shaders/simple.vert
Normal file
@@ -0,0 +1,26 @@
|
||||
#version 450
|
||||
|
||||
layout (location = 0) in vec3 position;
|
||||
layout (location = 1) in vec3 texcoord;
|
||||
|
||||
out vec3 TexCoord;
|
||||
out float Distance;
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 proj;
|
||||
|
||||
void main() {
|
||||
|
||||
TexCoord = texcoord;
|
||||
|
||||
gl_Position = proj * view * model * vec4(position, 1.0);
|
||||
|
||||
// Makes no sense but it works
|
||||
Distance = (
|
||||
gl_Position.x * gl_Position.x +
|
||||
gl_Position.y * gl_Position.y +
|
||||
gl_Position.z * gl_Position.z
|
||||
);
|
||||
|
||||
}
|
||||
BIN
legacy/resources/textures/bedrock.png
Normal file
BIN
legacy/resources/textures/bedrock.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 225 B |
BIN
legacy/resources/textures/cobblestone.png
Normal file
BIN
legacy/resources/textures/cobblestone.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 568 B |
BIN
legacy/resources/textures/dirt.png
Normal file
BIN
legacy/resources/textures/dirt.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 266 B |
BIN
legacy/resources/textures/grass_side.png
Normal file
BIN
legacy/resources/textures/grass_side.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 660 B |
BIN
legacy/resources/textures/grass_top.png
Normal file
BIN
legacy/resources/textures/grass_top.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 766 B |
BIN
legacy/resources/textures/stone.png
Normal file
BIN
legacy/resources/textures/stone.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 223 B |
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/hash.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
13
legacy/src/main.cpp
Normal file
13
legacy/src/main.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "game.hpp"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
Game game;
|
||||
game.Setup(1080, 720);
|
||||
game.Run();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -26,7 +26,7 @@ float EntityCollider::m_xDepth(ColliderBox a, ColliderBox b) {
|
||||
|
||||
|
||||
float EntityCollider::m_yDepth(ColliderBox a, ColliderBox b) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,10 @@ public:
|
||||
void MoveCamera(Uint8* state);
|
||||
// Mouse
|
||||
void HandleMouse(SDL_Event e);
|
||||
// Mouse Delta
|
||||
void MouseMoved(glm::vec2 mouseDelta);
|
||||
|
||||
// Updatable by
|
||||
float MouseSensitivity = 0.1f;
|
||||
float CameraSpeed = 2.0f;
|
||||
|
||||
@@ -22,7 +22,6 @@ class FrustrumPlane {
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@ std::shared_ptr<CBlockDictionary> CBlockDictionary::GetInstance() {
|
||||
|
||||
void CBlockDictionary::Build() {
|
||||
|
||||
// Order matters !
|
||||
RegisterTexture("stone.png");
|
||||
RegisterTexture("dirt.png");
|
||||
RegisterTexture("grass_side.png");
|
||||
@@ -53,7 +53,7 @@ Chunk::Chunk(int x, int z, std::shared_ptr<FastNoise> terrainGenerator) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pow(y / (float)CHUNK_HEIGHT, 1.1024f) + terrainGenerator->GetNoise(x + (Z * CHUNK_WIDTH), y, z + (X * CHUNK_DEPTH)) * 0.60f < 0.5f) {
|
||||
if (pow((y / (float)CHUNK_HEIGHT), 1.1024f) + terrainGenerator->GetNoise(x + (Z * CHUNK_WIDTH), y, z + (X * CHUNK_DEPTH)) * 0.40f < 0.5f) {
|
||||
|
||||
Voxels.push_back((uint8_t)EBlockType::Grass);
|
||||
continue;
|
||||
@@ -149,9 +149,23 @@ void Chunk::Load() {
|
||||
|
||||
}
|
||||
|
||||
void Chunk::Unload() {
|
||||
|
||||
m_vertices.clear();
|
||||
m_uvs.clear();
|
||||
|
||||
glBindVertexArray(m_vao);
|
||||
|
||||
glDeleteBuffers(1, &m_vbo);
|
||||
glDeleteVertexArrays(1, &m_vao);
|
||||
|
||||
Loaded = false;
|
||||
|
||||
}
|
||||
|
||||
void Chunk::UploadMesh() {
|
||||
|
||||
if (!MeshReady)
|
||||
if (!MeshReady || !Loaded)
|
||||
return;
|
||||
|
||||
glGenVertexArrays(1, &m_vao);
|
||||
@@ -187,7 +201,7 @@ void Chunk::UploadMesh() {
|
||||
|
||||
void Chunk::Render(std::shared_ptr<Camera> camera, std::shared_ptr<Shader> shader) {
|
||||
|
||||
if (!Loaded)
|
||||
if (!MeshReady || !Loaded)
|
||||
return;
|
||||
|
||||
shader->Use();
|
||||
@@ -276,4 +290,6 @@ void Chunk::m_mesh() {
|
||||
|
||||
Chunk::~Chunk() {
|
||||
|
||||
Unload();
|
||||
|
||||
}
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
Chunk(int x, int z, std::shared_ptr<FastNoise> terrainGenerator);
|
||||
|
||||
void Load();
|
||||
void Unload();
|
||||
|
||||
void UploadMesh();
|
||||
bool MeshReady = false;
|
||||
6
legacy/src/world/generator/chunkgenerator.hpp
Normal file
6
legacy/src/world/generator/chunkgenerator.hpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef MINECRAFT_WORLD_GENERATOR_CHUNKGENERATOR_H_
|
||||
#define MINECRAFT_WORLD_GENERATOR_CHUNKGENERATOR_H_
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
28
legacy/src/world/generator/chunkmanager.hpp
Normal file
28
legacy/src/world/generator/chunkmanager.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef MINECRAFT_WORLD_GENERATOR_CUNKMANAGER_H_
|
||||
#define MINECRAFT_WORLD_GENERATOR_CUNKMANAGER_H_
|
||||
|
||||
#include "../../common.hpp"
|
||||
|
||||
|
||||
class Frustrum;
|
||||
|
||||
class ChunkManager {
|
||||
public:
|
||||
|
||||
// Instatntiated
|
||||
ChunkManager();
|
||||
|
||||
void Update();
|
||||
|
||||
void Play();
|
||||
void Pause();
|
||||
|
||||
void LoadChunksAroundWorldPoint(glm::vec3 worldPoint);
|
||||
|
||||
|
||||
|
||||
void CullFrustrumFromRenderQueue();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "world.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
#include "chunk/chunk.hpp"
|
||||
|
||||
#include "../renderer/shader.hpp"
|
||||
@@ -24,10 +27,11 @@ void World::LoadWorld() {
|
||||
m_noiseGenerator = std::make_shared<FastNoise>();
|
||||
m_noiseGenerator->SetSeed(rand());
|
||||
|
||||
m_noiseGenerator->SetNoiseType(FastNoise::Perlin);
|
||||
m_noiseGenerator->SetNoiseType(FastNoise::ValueFractal);
|
||||
|
||||
m_noiseGenerator->SetFractalOctaves(8);
|
||||
m_noiseGenerator->SetFractalOctaves(5);
|
||||
|
||||
// Generate a 54x54 chunk world
|
||||
for (int x = -4; x < 50; x++)
|
||||
for (int y = -50; y < 4; y++) {
|
||||
|
||||
@@ -56,9 +60,17 @@ void World::SetTextureMap(GLuint map) {
|
||||
|
||||
}
|
||||
|
||||
glm::vec2 World::GetChunkCoords(glm::vec3 wordCoords) {
|
||||
glm::vec3 World::GetChunkCoords(glm::vec3 worldCoords) {
|
||||
|
||||
return { wordCoords.x / CHUNK_WIDTH, wordCoords.z / CHUNK_DEPTH };
|
||||
return { worldCoords.x / static_cast<float>(CHUNK_WIDTH),
|
||||
worldCoords.y / static_cast<float>(CHUNK_HEIGHT),
|
||||
worldCoords.z / static_cast<float>(CHUNK_DEPTH) };
|
||||
|
||||
}
|
||||
|
||||
glm::vec2 World::GetChunk(glm::vec3 worldCoords) {
|
||||
|
||||
return { static_cast<int>(worldCoords.x / CHUNK_WIDTH), static_cast<int>(worldCoords.z / CHUNK_DEPTH) };
|
||||
|
||||
}
|
||||
|
||||
@@ -71,12 +83,12 @@ std::vector<std::shared_ptr<Chunk>> World::GetRenderableChunks() {
|
||||
// Should the chunk be rendererd ?
|
||||
if (chunk.second->ShouldRender) {
|
||||
|
||||
m_chunkMutex.lock();
|
||||
m_chunkLoderMutex.lock();
|
||||
|
||||
if (chunk.second->MeshReady)
|
||||
chunk.second->UploadMesh();
|
||||
|
||||
m_chunkMutex.unlock();
|
||||
m_chunkLoderMutex.unlock();
|
||||
|
||||
// If not, add it
|
||||
chunks.push_back(chunk.second);
|
||||
@@ -91,6 +103,21 @@ std::vector<std::shared_ptr<Chunk>> World::GetRenderableChunks() {
|
||||
|
||||
void World::Update(std::shared_ptr<Entity> player) {
|
||||
|
||||
// glm::vec2 inChunk = GetChunk(player->Position);
|
||||
|
||||
// if (m_chunks.find(inChunk) == m_chunks.end()) {
|
||||
|
||||
// m_chunkLoderMutex.lock();
|
||||
|
||||
// m_chunkLoaderQueue.push(inChunk);
|
||||
|
||||
// m_chunkLoderMutex.unlock();
|
||||
|
||||
// }
|
||||
|
||||
// std::cout << "Position: " << player->Position.x << ":" << player->Position.y << ":" << player->Position.z << std::endl;
|
||||
// std::cout << "Chunk: " << inChunk.x << ":" << inChunk.y << std::endl << std::endl;
|
||||
|
||||
}
|
||||
|
||||
void World::Render(std::shared_ptr<Entity> player) {
|
||||
@@ -118,30 +145,36 @@ World::~World() {
|
||||
|
||||
}
|
||||
|
||||
for (auto& chunk : m_chunks) {
|
||||
|
||||
chunk.second->Unload();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void World::m_loadChunks() {
|
||||
|
||||
while (m_generatorRunning) {
|
||||
|
||||
m_chunkMutex.lock();
|
||||
m_chunkLoderMutex.lock();
|
||||
|
||||
glm::vec2 coords = m_chunkLoaderQueue.front();
|
||||
m_chunkLoaderQueue.pop();
|
||||
|
||||
m_chunkMutex.unlock();
|
||||
m_chunkLoderMutex.unlock();
|
||||
|
||||
|
||||
std::shared_ptr<Chunk> loadingChunk = std::make_shared<Chunk>(coords.x, coords.y, m_noiseGenerator);
|
||||
loadingChunk->ShouldRender = true;
|
||||
std::cout << "Loaded chunk " << coords.x << ":" << coords.y << std::endl;
|
||||
|
||||
|
||||
m_chunkMutex.lock();
|
||||
m_chunkLoderMutex.lock();
|
||||
|
||||
m_chunks[coords] = loadingChunk;
|
||||
m_chunks[coords]->ShouldRender = true;
|
||||
|
||||
m_chunkMutex.unlock();
|
||||
m_chunkLoderMutex.unlock();
|
||||
|
||||
|
||||
while (m_chunkLoaderQueue.empty()) {
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "../renderer/camera.hpp"
|
||||
|
||||
#include "generator/chunkmanager.hpp"
|
||||
#include "chunk/chunk.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
@@ -23,14 +24,17 @@ public:
|
||||
// Default constructor
|
||||
World();
|
||||
|
||||
|
||||
// Preps the render threads and loads all of the shaders
|
||||
void LoadWorld();
|
||||
|
||||
void SetTextureMap(GLuint map);
|
||||
|
||||
// Takes world coordinates and gets a chunks coordinates
|
||||
glm::vec2 GetChunkCoords(glm::vec3 wordCoords);
|
||||
glm::vec3 GetChunkCoords(glm::vec3 wordCoords);
|
||||
|
||||
// Takes world coordinates and gets the chunk those coorinates
|
||||
// fall in
|
||||
glm::vec2 GetChunk(glm::vec3 worldCoords);
|
||||
|
||||
std::vector<std::shared_ptr<Chunk>> GetRenderableChunks();
|
||||
|
||||
@@ -59,10 +63,11 @@ private:
|
||||
// Indexed by chunk coorinates
|
||||
std::unordered_map<glm::vec2, std::shared_ptr<Chunk>> m_chunks;
|
||||
|
||||
std::mutex m_chunkUpdaterMutex;
|
||||
std::queue<glm::vec2> m_chunkUpdatesQueue;
|
||||
std::queue<glm::vec2> m_chunkLoaderQueue;
|
||||
|
||||
std::mutex m_chunkMutex;
|
||||
std::mutex m_chunkLoderMutex;
|
||||
std::queue<glm::vec2> m_chunkLoaderQueue;
|
||||
|
||||
// Generator
|
||||
std::shared_ptr<FastNoise> m_noiseGenerator;
|
||||
0
src/util/glad.c → src/ThirdParty/glad.c
vendored
0
src/util/glad.c → src/ThirdParty/glad.c
vendored
120
src/display.cpp
Normal file
120
src/display.cpp
Normal file
@@ -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 );
|
||||
}
|
||||
|
||||
42
src/display.hpp
Normal file
42
src/display.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef MINECRAFT_DISPLAY_H_
|
||||
#define MINECRAFT_DISPLAY_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <logger.h>
|
||||
|
||||
#if _WIN32
|
||||
#include <SDL.h>
|
||||
#else
|
||||
#include <SDL2/SDL.h>
|
||||
#endif
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <KHR/khrplatform.h>
|
||||
|
||||
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
|
||||
76
src/main.cpp
76
src/main.cpp
@@ -1,14 +1,78 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "game.hpp"
|
||||
#define LOGGER_DEFINITION
|
||||
#include <logger.h>
|
||||
|
||||
#if _WIN32
|
||||
#include <SDL.h>
|
||||
#else
|
||||
#include <SDL2/SDL.h>
|
||||
#endif
|
||||
|
||||
#include "display.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
#define __DEBUG
|
||||
|
||||
Game game;
|
||||
game.Setup(1080, 720);
|
||||
game.Run();
|
||||
static const int VERSION_MAJOR = 1;
|
||||
static const int VERSION_MINOR = 1;
|
||||
static const int VERSION_PATCH = 0;
|
||||
|
||||
return 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 );
|
||||
|
||||
}
|
||||
|
||||
10
src/settings.hpp
Normal file
10
src/settings.hpp
Normal file
@@ -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
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
|
||||
Reference in New Issue
Block a user