@@ -7,3 +7,6 @@ | |||
[submodule "external/concurrentqueue"] | |||
path = external/concurrentqueue | |||
url = https://github.com/cameron314/concurrentqueue.git | |||
[submodule "external/sol2"] | |||
path = external/sol2 | |||
url = https://github.com/ThePhD/sol2.git |
@@ -1,7 +1,7 @@ | |||
cmake_minimum_required (VERSION 3.6) | |||
project ("voxeltronik") | |||
file (GLOB_RECURSE SOURCES "src/*.cpp" "src/*.c") | |||
include_directories("./include" "libcuckoo/libcuckoo") | |||
include_directories("./include" "libcuckoo/libcuckoo" "external/sol2" "/usr/include/luajit-2.0/") | |||
set(CMAKE_CXX_STANDARD 17) | |||
set(CMAKE_CXX_FLAGS "-O2") | |||
set(CMAKE_C_FLAGS "-fPIC") | |||
@@ -12,6 +12,6 @@ add_executable(vtk ${SOURCES}) | |||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE) | |||
find_package(Threads REQUIRED) | |||
target_link_libraries(vtk SDL2 GL GLEW GLU ${CMAKE_THREAD_LIBS_INIT}) | |||
target_link_libraries(vtk SDL2 GL GLEW GLU "luajit-5.1" ${CMAKE_THREAD_LIBS_INIT}) | |||
@@ -0,0 +1 @@ | |||
Subproject commit e3ff28f58d0da27cdcf48cda74b72c6a15aa6edb |
@@ -45,6 +45,10 @@ hierarchything { | |||
#include <vector> | |||
//Config stores values | |||
namespace sol { | |||
class state; | |||
} | |||
class Config { | |||
public: | |||
bool loadConfigFromFile(const std::string& fileName) { | |||
@@ -131,6 +135,8 @@ public: | |||
} | |||
} | |||
static void registerScriptInterface(sol::state& lua); | |||
protected: | |||
std::map<std::string, std::string> values; | |||
std::map<std::string, std::string> commandRules; |
@@ -4,6 +4,12 @@ | |||
#include "spdlog/spdlog.h" | |||
//forward declarations | |||
namespace sol { | |||
class state; | |||
} | |||
namespace vtk { | |||
class LoggerSetup { | |||
@@ -13,6 +19,8 @@ public: | |||
void setLogFolder(const std::string& path); | |||
void setup(); | |||
static void registerScriptInterface(sol::state& lua); | |||
protected: | |||
std::string mLogFolder; | |||
@@ -0,0 +1,15 @@ | |||
#pragma once | |||
#include "scene.h" | |||
namespace vtk { | |||
class ScriptScene : public Scene { | |||
public: | |||
void init(); // Called first time the scene is set | |||
void reInit(); // Called when switching from another scene | |||
void update(const float& dTime); //Logic | |||
void draw(); //Graphics | |||
}; | |||
} |
@@ -0,0 +1,3 @@ | |||
conf = config.new() | |||
conf:load_from_file('res/config.conf') | |||
log_info('X res: ' .. conf:get_value('graphics.res.x', '800')) |
@@ -1,21 +1,5 @@ | |||
/* | |||
* ===================================================================================== | |||
* | |||
* Filename: config.cpp | |||
* | |||
* Description: Specializations and shit | |||
* | |||
* Version: 1.0 | |||
* Created: 03/27/2014 10:56:51 PM | |||
* Revision: none | |||
* Compiler: gcc | |||
* | |||
* Author: YOUR NAME (), | |||
* Organization: | |||
* | |||
* ===================================================================================== | |||
*/ | |||
#include "config.h" | |||
#include "sol.hpp" | |||
template <> | |||
std::string Config::getValue<std::string>(const std::string& key, const std::string& fallback) { | |||
@@ -25,3 +9,10 @@ std::string Config::getValue<std::string>(const std::string& key, const std::str | |||
return fallback; | |||
} | |||
void Config::registerScriptInterface(sol::state &lua) { | |||
lua.new_usertype<Config>("config", | |||
"load_from_file", &Config::loadConfigFromFile, | |||
"get_value", &Config::getValue<std::string>, | |||
"set_value", &Config::setValue<std::string>); | |||
} |
@@ -46,7 +46,7 @@ void Game::init() { | |||
SDL_GL_SetSwapInterval(conf->getValue<int>("graphics.vsync", 0)); | |||
window.setTitle("OpenGL"); | |||
window.setTitle("VTK"); | |||
window.setResolution(conf->getValue<int>("graphics.res.x", 800), | |||
conf->getValue<int>("graphics.res.y", 600)); | |||
window.setFOV(conf->getValue<float>("graphics.fov", 45.0f)); | |||
@@ -68,28 +68,6 @@ void Game::init() { | |||
glClearDepth(0.0f); | |||
glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); | |||
/* | |||
//depth buffer stuff | |||
glGenTextures(1, &mColor); | |||
glBindTexture(GL_TEXTURE_2D, mColor); | |||
glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, conf->getValue<int>("graphics.res.x", 800), conf->getValue<int>("graphics.res.y", 600)); | |||
glBindTexture(GL_TEXTURE_2D, 0); | |||
glGenTextures(1, &mDepth); | |||
glBindTexture(GL_TEXTURE_2D, mDepth); | |||
glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT32F, conf->getValue<int>("graphics.res.x", 800), conf->getValue<int>("graphics.res.y", 600)); | |||
glBindTexture(GL_TEXTURE_2D, 0); | |||
glGenFramebuffers(1, &mFBO); | |||
glBindFramebuffer(GL_FRAMEBUFFER, mFBO); | |||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mColor, 0); | |||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, mDepth, 0); | |||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); | |||
if (status != GL_FRAMEBUFFER_COMPLETE) { | |||
fprintf(stderr, "glCheckFramebufferStatus: %x\n", status); | |||
} | |||
glBindFramebuffer(GL_FRAMEBUFFER, 0); | |||
*/ | |||
running = false; | |||
gls::setTracking(true); // track OpenGL state changes | |||
@@ -104,12 +82,12 @@ void Game::start() { | |||
void Game::loop() { | |||
std::chrono::steady_clock::time_point lastFrameTime = std::chrono::steady_clock::now(); | |||
std::chrono::steady_clock::time_point lastFrameTime = std::chrono::steady_clock::now(); | |||
while (running) { | |||
//time | |||
std::chrono::steady_clock::time_point curTime = std::chrono::steady_clock::now(); | |||
auto timeSpan = std::chrono::duration_cast<std::chrono::duration<float>>(curTime - lastFrameTime); | |||
//time | |||
std::chrono::steady_clock::time_point curTime = std::chrono::steady_clock::now(); | |||
auto timeSpan = std::chrono::duration_cast<std::chrono::duration<float>>(curTime - lastFrameTime); | |||
lastFrameTime = curTime; | |||
float dTime = timeSpan.count(); | |||
@@ -122,18 +100,6 @@ void Game::loop() { | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
activeScene->draw(); //draw the scene | |||
//glBindFramebuffer(GL_FRAMEBUFFER, 0); | |||
/* | |||
glBindFramebuffer(GL_READ_FRAMEBUFFER, mFBO); | |||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); // default FBO | |||
glBlitFramebuffer( | |||
0, 0, conf->getValue<int>("graphics.res.x", 800), conf->getValue<int>("graphics.res.y", 600), | |||
0, 0, conf->getValue<int>("graphics.res.x", 800), conf->getValue<int>("graphics.res.y", 600), | |||
GL_COLOR_BUFFER_BIT, GL_LINEAR); | |||
glBindFramebuffer(GL_FRAMEBUFFER, 0); | |||
*/ | |||
SDL_GL_SwapWindow(window.getWindow()); | |||
} | |||
cleanup(); |
@@ -1,23 +1,46 @@ | |||
#include "loggersetup.h" | |||
#include "sol.hpp" | |||
namespace vtk { | |||
LoggerSetup::LoggerSetup() { | |||
mLogFolder = "logs"; | |||
} | |||
void LoggerSetup::setLogFolder(const std::string& path) { | |||
mLogFolder = path; | |||
} | |||
void LoggerSetup::setup() { | |||
std::vector<spdlog::sink_ptr> logSinks; | |||
logSinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>("logs/log", 1048576 * 5, 3)); | |||
logSinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_st>()); | |||
auto generalLogger = std::make_shared<spdlog::logger>("general", begin(logSinks), end(logSinks)); | |||
auto fileLogger = std::make_shared<spdlog::logger>("file", begin(logSinks), end(logSinks)); | |||
spdlog::register_logger(generalLogger); | |||
spdlog::register_logger(fileLogger); | |||
spdlog::set_level(spdlog::level::debug); | |||
} | |||
LoggerSetup::LoggerSetup() { | |||
mLogFolder = "logs"; | |||
} | |||
void LoggerSetup::setLogFolder(const std::string& path) { | |||
mLogFolder = path; | |||
} | |||
void LoggerSetup::setup() { | |||
std::vector<spdlog::sink_ptr> logSinks; | |||
logSinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>("logs/log", 1048576 * 5, 3)); | |||
logSinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_st>()); | |||
auto generalLogger = std::make_shared<spdlog::logger>("general", begin(logSinks), end(logSinks)); | |||
auto fileLogger = std::make_shared<spdlog::logger>("file", begin(logSinks), end(logSinks)); | |||
auto scriptLogger = std::make_shared<spdlog::logger>("script", begin(logSinks), end(logSinks)); | |||
spdlog::register_logger(generalLogger); | |||
spdlog::register_logger(fileLogger); | |||
spdlog::register_logger(scriptLogger); | |||
spdlog::set_level(spdlog::level::debug); | |||
} | |||
void LoggerSetup::registerScriptInterface(sol::state& lua) { | |||
lua.set_function("log_info", [](std::string arg) { | |||
spdlog::get("script")->info(arg); | |||
}); | |||
lua.set_function("log_debug", [](std::string arg) { | |||
spdlog::get("script")->debug(arg); | |||
}); | |||
lua.set_function("log_warn", [](std::string arg) { | |||
spdlog::get("script")->warn(arg); | |||
}); | |||
lua.set_function("log_error", [](std::string arg) { | |||
spdlog::get("script")->error(arg); | |||
}); | |||
} | |||
} |
@@ -5,6 +5,7 @@ | |||
#include "spdlog/spdlog.h" | |||
#include "loggersetup.h" | |||
#include "threadpool.h" | |||
#include "sol.hpp" | |||
#include <iostream> | |||
#include <vector> | |||
@@ -29,11 +30,19 @@ int main (int argc, char *argv[]) | |||
conf->addArgumentRule("-h", "graphics.res.y"); | |||
conf->loadConfigFromArguments(argc, argv); | |||
sol::state lua; | |||
lua.open_libraries(sol::lib::base, sol::lib::package); | |||
vtk::LoggerSetup::registerScriptInterface(lua); | |||
Config::registerScriptInterface(lua); | |||
lua.script_file("res/init.lua"); | |||
/* | |||
vtk::Game game; | |||
game.setConfig(conf); | |||
game.init(); | |||
game.setScene(new vtk::TestScene); | |||
game.start(); | |||
*/ | |||
return 0; | |||
} |
@@ -118,7 +118,7 @@ void TestScene::init() { | |||
std::cout << std::endl; | |||
world.queueChunkLoadsAroundPoint(glm::vec3(0.0,0.0,0.0), 8); | |||
world.queueChunkLoadsAroundPoint(glm::vec3(0.0,0.0,0.0), 20); | |||
//world.forceGlobalGeometryUpdate(); | |||
@@ -184,7 +184,7 @@ void TestScene::update(const float& dTime) { | |||
float distance = glm::distance(camera.getPosition(), mCamLastLoadPosition); | |||
if (distance >= 16.0f) { | |||
mCamLastLoadPosition = camera.getPosition(); | |||
world.queueChunkLoadsAroundPoint(camera.getPosition(), 16); | |||
//world.queueChunkLoadsAroundPoint(camera.getPosition(), 16); | |||
} | |||
//player "physics" |