Some machinations on a config structure as well as a restructure on how
I do logging.
This commit is contained in:
20
src/ConfigDB.cpp
Normal file
20
src/ConfigDB.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "ConfigDB.h"
|
||||
#include <iostream>
|
||||
|
||||
ConfigDB::ConfigDB()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ConfigDB::~ConfigDB()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool ConfigDB::init(std::string root_config_path) {
|
||||
|
||||
for (auto& p : std::experimental::filesystem::directory_iterator("../config"))
|
||||
std::cout << p << '\n';
|
||||
return true;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
80
src/Logger.cpp
Normal file
80
src/Logger.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "Logger.h"
|
||||
|
||||
Logger::LogDest Logger::log_destination = LogDest::STDOUT;
|
||||
Logger::LogLevel Logger::log_level = LogLevel::INFO;
|
||||
std::ofstream Logger::log_file;
|
||||
|
||||
void Logger::log(std::string log_string, LogLevel severity, uint32_t line_number, char* file_name) {
|
||||
|
||||
if (severity < log_level)
|
||||
return;
|
||||
|
||||
std::ostream &output = get_stream();
|
||||
|
||||
switch (severity) {
|
||||
|
||||
case LogLevel::INFO: {
|
||||
output << "[INFO] --> ";
|
||||
break;
|
||||
}
|
||||
case LogLevel::WARN: {
|
||||
output << "[WARN] --> ";
|
||||
break;
|
||||
}
|
||||
case LogLevel::ERROR: {
|
||||
output << "[ERROR] --> ";
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
output << "";
|
||||
}
|
||||
}
|
||||
|
||||
output << log_string.c_str();
|
||||
|
||||
if (line_number > 0 && file_name)
|
||||
output << "::" << file_name << ":" << line_number << std::endl;
|
||||
else
|
||||
output << std::endl;
|
||||
}
|
||||
|
||||
void Logger::set_log_level(LogLevel log_level) {
|
||||
Logger::log_level = log_level;
|
||||
}
|
||||
|
||||
void Logger::set_log_destination(LogDest log_destination) {
|
||||
Logger::log_destination = log_destination;
|
||||
}
|
||||
|
||||
bool Logger::open_log_file() {
|
||||
|
||||
log_file.open("../log/logfile.txt");
|
||||
|
||||
if (!log_file.is_open()) {
|
||||
std::cout << "Wooga Wooga! Can't open the log file for writing!" << std::endl;
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::ostream& Logger::get_stream() {
|
||||
|
||||
switch (log_destination) {
|
||||
|
||||
case LogDest::STDOUT: {
|
||||
return std::cout;
|
||||
}
|
||||
case LogDest::FILE: {
|
||||
|
||||
// Fall through if the file isn't open
|
||||
if (log_file.is_open())
|
||||
return log_file;
|
||||
}
|
||||
default: {
|
||||
return std::cout;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
src/main.cpp
11
src/main.cpp
@@ -41,6 +41,12 @@
|
||||
#include "imgui/imgui.h"
|
||||
#include "map/Map.h"
|
||||
|
||||
// Srsly people who macro error codes are the devil
|
||||
#undef ERROR
|
||||
#include "Logger.h"
|
||||
|
||||
|
||||
|
||||
const int WINDOW_X = 1536;
|
||||
const int WINDOW_Y = 1024;
|
||||
const int WORK_SIZE = WINDOW_X * WINDOW_Y;
|
||||
@@ -77,12 +83,13 @@ sf::Texture window_texture;
|
||||
|
||||
int main() {
|
||||
|
||||
srand(time(nullptr));
|
||||
|
||||
// =============================
|
||||
Map _map(32);
|
||||
//_map.test();
|
||||
//std::cin.get();
|
||||
|
||||
|
||||
|
||||
//return 0;
|
||||
// =============================
|
||||
|
||||
|
||||
@@ -1,37 +1,53 @@
|
||||
#include "map/Map.h"
|
||||
#include "Logger.h"
|
||||
|
||||
|
||||
Map::Map(uint32_t dimensions) {
|
||||
|
||||
|
||||
// ========= TEMP 3D voxel data ===========
|
||||
srand(time(nullptr));
|
||||
if ((int)pow(2, (int)log2(dimensions)) != dimensions)
|
||||
Logger::log("Map dimensions not an even exponent of 2", Logger::LogLevel::ERROR, __LINE__, __FILE__);
|
||||
|
||||
voxel_data = new char[dimensions * dimensions * dimensions];
|
||||
|
||||
for (uint64_t i = 0; i < dimensions * dimensions * dimensions; i++) {
|
||||
|
||||
voxel_data[i] = 1;
|
||||
}
|
||||
// randomly set the voxel data for testing
|
||||
for (uint64_t i = 0; i < dimensions * dimensions * dimensions; i++) {
|
||||
if (rand() % 25 < 2)
|
||||
voxel_data[i] = 1;
|
||||
else
|
||||
voxel_data[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
sf::Vector3i dim3(dimensions, dimensions, dimensions);
|
||||
|
||||
Logger::log("Generating Octree", Logger::LogLevel::INFO);
|
||||
octree.Generate(voxel_data, dim3);
|
||||
|
||||
octree.Validate(voxel_data, dim3);
|
||||
Logger::log("Validating Octree", Logger::LogLevel::INFO);
|
||||
if (!octree.Validate(voxel_data, dim3)) {
|
||||
Logger::log("Octree validation failed", Logger::LogLevel::ERROR, __LINE__, __FILE__);
|
||||
}
|
||||
|
||||
// TODO: Create test with mock octree data and defined test framework
|
||||
Logger::log("Testing Array vs Octree ray traversal", Logger::LogLevel::INFO);
|
||||
if (!test_oct_arr_traversal(dim3)) {
|
||||
Logger::log("Array and Octree traversals DID NOT MATCH!!!", Logger::LogLevel::ERROR, __LINE__, __FILE__);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Map::test_oct_arr_traversal(sf::Vector3i dimensions) {
|
||||
|
||||
sf::Vector2f cam_dir(0.95, 0.81);
|
||||
sf::Vector3f cam_pos(10.5, 10.5, 10.5);
|
||||
std::vector<std::tuple<sf::Vector3i, char>> list1 = CastRayCharArray(voxel_data, &dim3, &cam_dir, &cam_pos);
|
||||
std::vector<std::tuple<sf::Vector3i, char>> list2 = CastRayOctree(&octree, &dim3, &cam_dir, &cam_pos);
|
||||
std::vector<std::tuple<sf::Vector3i, char>> list1 = CastRayCharArray(voxel_data, &dimensions, &cam_dir, &cam_pos);
|
||||
std::vector<std::tuple<sf::Vector3i, char>> list2 = CastRayOctree(&octree, &dimensions, &cam_dir, &cam_pos);
|
||||
|
||||
|
||||
return;
|
||||
if (list1 != list2) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,6 +61,7 @@ char Map::getVoxel(sf::Vector3i pos){
|
||||
return octree.GetVoxel(pos).found;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::tuple<sf::Vector3i, char>> Map::CastRayCharArray(
|
||||
char* map,
|
||||
sf::Vector3i* map_dim,
|
||||
@@ -243,8 +260,6 @@ std::vector<std::tuple<sf::Vector3i, char>> Map::CastRayOctree(
|
||||
// Andrew Woo's raycasting algo
|
||||
do {
|
||||
|
||||
|
||||
|
||||
// check which direction we step in
|
||||
face_mask.x = intersection_t.x <= std::min(intersection_t.y, intersection_t.z);
|
||||
face_mask.y = intersection_t.y <= std::min(intersection_t.z, intersection_t.x);
|
||||
|
||||
@@ -36,8 +36,6 @@ void Octree::Generate(char* data, sf::Vector3i dimensions) {
|
||||
|
||||
DumpLog(&output_stream, "raw_data.txt");
|
||||
|
||||
GetVoxel(sf::Vector3i(1, 1, 1));
|
||||
GetVoxel(sf::Vector3i(0, 0, 0));
|
||||
}
|
||||
|
||||
OctState Octree::GetVoxel(sf::Vector3i position) {
|
||||
@@ -323,7 +321,6 @@ bool Octree::Validate(char* data, sf::Vector3i dimensions){
|
||||
// std::cout << (int)get1DIndexedVoxel(data, dimensions, sf::Vector3i(16, 16, 16)) << std::endl;
|
||||
// std::cout << (int)GetVoxel(sf::Vector3i(16, 16, 16)) << std::endl;
|
||||
|
||||
std::cout << "Validating map..." << std::endl;
|
||||
|
||||
for (int x = 0; x < OCT_DIM; x++) {
|
||||
for (int y = 0; y < OCT_DIM; y++) {
|
||||
@@ -343,7 +340,5 @@ bool Octree::Validate(char* data, sf::Vector3i dimensions){
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Done" << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user