From b493d56f7acfa0d46f1ef8b709a605ddd36f57bf Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Thu, 23 Mar 2017 00:45:13 -0700 Subject: [PATCH] Removed some extra headers in util, restricted the scope of some others --- include/LightHandle.h | 1 + include/map/Map.h | 2 + include/raycaster/Hardware_Caster.h | 1 + include/raycaster/RayCaster.h | 6 ++- include/util.hpp | 63 +++++++---------------------- src/main.cpp | 8 ++-- src/map/Map.cpp | 1 - 7 files changed, 26 insertions(+), 56 deletions(-) diff --git a/include/LightHandle.h b/include/LightHandle.h index 1846c5a..0465865 100644 --- a/include/LightHandle.h +++ b/include/LightHandle.h @@ -3,6 +3,7 @@ #include #include #include "Pub_Sub.h" +#include "Vector4.hpp" // Light Handle : diff --git a/include/map/Map.h b/include/map/Map.h index cd770d0..41bb930 100644 --- a/include/map/Map.h +++ b/include/map/Map.h @@ -1,10 +1,12 @@ #pragma once #include +#include #include #include #include #include "util.hpp" #include "map/Octree.h" +#include #define _USE_MATH_DEFINES #include diff --git a/include/raycaster/Hardware_Caster.h b/include/raycaster/Hardware_Caster.h index 9c15317..605de31 100644 --- a/include/raycaster/Hardware_Caster.h +++ b/include/raycaster/Hardware_Caster.h @@ -1,5 +1,6 @@ #pragma once #include +#include #include #include #include diff --git a/include/raycaster/RayCaster.h b/include/raycaster/RayCaster.h index 27771e3..97db676 100644 --- a/include/raycaster/RayCaster.h +++ b/include/raycaster/RayCaster.h @@ -1,12 +1,14 @@ #pragma once -#include -#include +#include "Vector4.hpp" #include +#include + class Old_Map; class Camera; struct PackedData; + class RayCaster { public: diff --git a/include/util.hpp b/include/util.hpp index 1e87624..a9bfa4b 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -1,26 +1,23 @@ #pragma once -#include -#include "Vector4.hpp" -#include -#include +#include +#include #include #include #include #include #include -#include -#include -#include #include const double PI = 3.141592653589793238463; const float PI_F = 3.14159265358979f; + struct fps_counter { public: fps_counter() {}; void frame(double delta_time) { + // Apply 100 units of smoothing if (frame_count == 100) { frame_count = 0; @@ -53,33 +50,6 @@ private: }; -struct debug_text { -public: - debug_text(int slot, int pixel_spacing, void* data_, std::string prefix_) : data(data_), prefix(prefix_) { - if (!f.loadFromFile("../assets/fonts/Arial.ttf")) { - std::cout << "couldn't find the fall back Arial font in ../assets/fonts/" << std::endl; - } - else { - t.setFont(f); - t.setCharacterSize(20); - t.setPosition(static_cast(20), static_cast(slot * pixel_spacing)); - } - - } - - void draw(sf::RenderWindow *r) { - t.setString(prefix + std::to_string(*(float*)data)); - r->draw(t); - } - -private: - void* data; - std::string prefix; - sf::Font f; - sf::Text t; - -}; - struct oct_state { int parent_stack_position = 0; @@ -98,7 +68,7 @@ inline sf::Vector3f SphereToCart(sf::Vector2f i) { (1 * sin(i.y) * cos(i.x)), (1 * sin(i.y) * sin(i.x)), (1 * cos(i.y)) - ); + ); return r; }; @@ -108,7 +78,7 @@ inline sf::Vector3f SphereToCart(sf::Vector3f i) { (i.x * sin(i.z) * cos(i.y)), (i.x * sin(i.z) * sin(i.y)), (i.x * cos(i.z)) - ); + ); return r; }; @@ -119,7 +89,7 @@ inline sf::Vector3f CartToSphere(sf::Vector3f in) { sqrt(in.x * in.x + in.y * in.y + in.z * in.z), atan(in.y / in.x), atan(sqrt(in.x * in.x + in.y * in.y) / in.z) - ); + ); return r; }; @@ -128,8 +98,7 @@ inline sf::Vector2f CartToNormalizedSphere(sf::Vector3f in) { auto r = sf::Vector2f( atan2(sqrt(in.x * in.x + in.y * in.y), in.z), atan2(in.y, in.x) - ); - + ); return r; } @@ -138,7 +107,7 @@ inline sf::Vector3f FixOrigin(sf::Vector3f base, sf::Vector3f head) { } inline sf::Vector3f Normalize(sf::Vector3f in) { - + float multiplier = sqrt(in.x * in.x + in.y * in.y + in.z * in.z); auto r = sf::Vector3f( in.x / multiplier, @@ -146,9 +115,9 @@ inline sf::Vector3f Normalize(sf::Vector3f in) { in.z / multiplier ); return r; - } + inline float DotProduct(sf::Vector3f a, sf::Vector3f b){ return a.x * b.x + a.y * b.y + a.z * b.z; } @@ -174,6 +143,7 @@ inline float RadiansToDegrees(float in) { } inline std::string read_file(std::string file_name){ + std::ifstream input_file(file_name); if (!input_file.is_open()){ @@ -194,7 +164,6 @@ inline void PrettyPrintUINT64(uint64_t i, std::stringstream* ss) { *ss << "[" << std::bitset<8>(i >> 16) << "]"; *ss << "[" << std::bitset<8>(i >> 24) << "]"; *ss << "[" << std::bitset<32>(i >> 32) << "]"; - } inline void PrettyPrintUINT64(uint64_t i) { @@ -204,7 +173,6 @@ inline void PrettyPrintUINT64(uint64_t i) { std::cout << "[" << std::bitset<8>(i >> 16) << "]"; std::cout << "[" << std::bitset<8>(i >> 24) << "]"; std::cout << "[" << std::bitset<32>(i >> 32) << "]" << std::endl; - } inline void DumpLog(std::stringstream* ss, std::string file_name) { @@ -213,9 +181,7 @@ inline void DumpLog(std::stringstream* ss, std::string file_name) { log_file.open(file_name); log_file << ss->str(); - log_file.close(); - } #ifdef _MSC_VER @@ -310,9 +276,8 @@ inline bool IsLeaf(const uint64_t descriptor) { // Only if valid and leaf are contiguous, then it's a leaf if ((descriptor & leaf_mask) == leaf_mask) return true; - else - return false; + } - else - return false; + + return false; } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 81c037a..da166aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -277,11 +277,11 @@ int main() { handle->set_position(light); } - light_pos[0] = static_cast(sin(elapsed_time) * 100.0f + 300.0f); - light_pos[1] = static_cast(sin(elapsed_time) * 100.0f + 300.0f); + //light_pos[0] = static_cast(sin(elapsed_time) * 100.0f + 300.0f); + //light_pos[1] = static_cast(sin(elapsed_time) * 100.0f + 300.0f); - sf::Vector3f light(light_pos[0], light_pos[1], light_pos[2]); - handle->set_position(light); + //sf::Vector3f light(light_pos[0], light_pos[1], light_pos[2]); + //handle->set_position(light); ImGui::End(); diff --git a/src/map/Map.cpp b/src/map/Map.cpp index 5fffbbc..5745e13 100644 --- a/src/map/Map.cpp +++ b/src/map/Map.cpp @@ -13,7 +13,6 @@ Map::Map(uint32_t dimensions) { else voxel_data[i] = 1; } - } uint64_t Map::generate_children(sf::Vector3i pos, int voxel_scale) {