~10 FPS from moving some oct stuff to const, ~0.5 fps from adding a few more consts to initializers in the kernel

This commit is contained in:
MitchellHansen
2017-10-07 21:32:22 -07:00
parent 58ef1da02a
commit c5c65474d6
8 changed files with 159 additions and 71 deletions

View File

@@ -23,9 +23,6 @@ Application::~Application() {
bool Application::init_clcaster() {
//Map _map(32);
//return 0;
// Start up the raycaster
raycaster = std::make_shared<CLCaster>();
if (!raycaster->init())
@@ -38,7 +35,9 @@ bool Application::init_clcaster() {
// Send the data to the GPU
raycaster->assign_map(map);
octree = std::make_shared<Map>(128, map.get());
// Init the raycaster with a specified dimension and a pointer to the source
// array style data
octree = std::make_shared<Map>(64, map.get());
raycaster->assign_octree(octree);

47
src/FrameWatcher.cpp Normal file
View File

@@ -0,0 +1,47 @@
#include "FrameWatcher.h"
#include <chrono>
FrameWatcher::FrameWatcher() {
}
FrameWatcher::~FrameWatcher()
{
}
void FrameWatcher::do_tick() {
elapsed_time = get_elapsed_time();
delta_time = elapsed_time - current_time;
current_time = elapsed_time;
if (delta_time > 0.2f)
delta_time = 0.2f;
accumulator_time += delta_time;
while ((accumulator_time - step_size) >= step_size) {
accumulator_time -= step_size;
// ==== DELTA TIME LOCKED ====
}
}
float FrameWatcher::get_elapsed_time() {
static std::chrono::time_point<std::chrono::system_clock> start;
static bool started = false;
if (!started) {
start = std::chrono::system_clock::now();
started = true;
}
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_time = now - start;
return static_cast<float>(elapsed_time.count());
}

View File

@@ -26,7 +26,7 @@
* - Octree, Map interface with the GPU
* - Octree, Map refactoring
* - Separate Application stages into areas that make sense
* -
* - Saving, loading of RLE voxel data and raw oct data
*/
#include "Application.h"

View File

@@ -66,7 +66,7 @@ bool Map::test_oct_arr_traversal(sf::Vector3i dimensions) {
}
void Map::setVoxel(sf::Vector3i pos, int val) {
voxel_data[pos.x + OCT_DIM * (pos.y + OCT_DIM * pos.z)] = val;
voxel_data[pos.x + octree.getDimensions() * (pos.y + octree.getDimensions() * pos.z)] = val;
}
char Map::getVoxel(sf::Vector3i pos){

View File

@@ -11,13 +11,15 @@ Octree::Octree() {
void Octree::Generate(char* data, sf::Vector3i dimensions) {
oct_dimensions = dimensions.x;
// Launch the recursive generator at (0,0,0) as the first point
// and the octree dimension as the initial block size
std::tuple<uint64_t, uint64_t> root_node = GenerationRecursion(data, dimensions, sf::Vector3i(0, 0, 0), OCT_DIM/2);
std::tuple<uint64_t, uint64_t> root_node = GenerationRecursion(data, dimensions, sf::Vector3i(0, 0, 0), oct_dimensions/2);
// ========= DEBUG ==============
PrettyPrintUINT64(std::get<0>(root_node), &output_stream);
output_stream << " " << OCT_DIM << " " << counter++ << std::endl;
output_stream << " " << oct_dimensions << " " << counter++ << std::endl;
// ==============================
// set the root nodes relative pointer to 1 because the next element will be the top of the tree, and push to the stack
@@ -51,7 +53,7 @@ OctState Octree::GetVoxel(sf::Vector3i position) {
state.parent_stack[state.parent_stack_position] = head;
// Set our initial dimension and the position at the corner of the oct to keep track of our position
int dimension = OCT_DIM;
int dimension = oct_dimensions;
sf::Vector3i quad_position(0, 0, 0);
// While we are not at the required resolution
@@ -313,7 +315,7 @@ std::tuple<uint64_t, uint64_t> Octree::GenerationRecursion(char* data, sf::Vecto
}
char Octree::get1DIndexedVoxel(char* data, sf::Vector3i dimensions, sf::Vector3i position) {
return data[position.x + OCT_DIM * (position.y + OCT_DIM * position.z)];
return data[position.x + oct_dimensions * (position.y + oct_dimensions * position.z)];
}
bool Octree::Validate(char* data, sf::Vector3i dimensions){
@@ -343,3 +345,7 @@ bool Octree::Validate(char* data, sf::Vector3i dimensions){
return true;
}
unsigned int Octree::getDimensions() {
return oct_dimensions;
}