Skip to content

Commit

Permalink
Swap to using robinhood hash for noisetool mesh chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
Auburn committed Sep 8, 2021
1 parent a228926 commit 00230ff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
12 changes: 10 additions & 2 deletions NoiseTool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ CPMAddPackage(
GITHUB_REPOSITORY Auburn/imnodes
GIT_TAG a295b4af69045645d657363d5d135e2d8a3785f6
)

CPMAddPackage(
NAME robinhoodhashing
GITHUB_REPOSITORY martinus/robin-hood-hashing
GIT_TAG 3.11.3
)

# Use modules from magnum-integration since it has everything we need
set(CMAKE_MODULE_PATH "${magnum-integration_SOURCE_DIR}/modules" ${CMAKE_MODULE_PATH})
Expand All @@ -86,8 +92,10 @@ add_executable(NoiseTool
${NoiseTool_RESOURCES}
)

# Include imnodes in NoiseTool project since setting up separate cmake library with imgui dependancy was causing issues
target_include_directories(NoiseTool PRIVATE "${imnodes_SOURCE_DIR}")
# Include imnodes & rhh in NoiseTool project since setting up separate cmake library with imgui dependancy was causing issues
target_include_directories(NoiseTool PRIVATE
"${imnodes_SOURCE_DIR}"
"${robinhoodhashing_SOURCE_DIR}/src/include")

target_link_libraries(NoiseTool PRIVATE
FastNoise
Expand Down
12 changes: 6 additions & 6 deletions NoiseTool/MeshNoisePreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ void MeshNoisePreview::UpdateChunkQueues( const Vector3& position )
while( GetTimerDurationMs() < 14 && mCompleteQueue.Pop( meshData ) )
{
mInProgressChunks.erase( meshData.pos );
mDistanceOrderedChunks.push_back( meshData.pos );
mDistanceOrderedChunks.emplace_back( meshData.pos );

mMinMax << meshData.minMax;
mMinAirY = std::min( mMinAirY, meshData.minAirY );
mMaxSolidY = std::max( mMaxSolidY, meshData.maxSolidY );

mChunks.emplace( meshData.pos, meshData );
mChunks.try_emplace( meshData.pos, meshData );
newChunks++;
}
mAvgNewChunks += (newChunks - mAvgNewChunks) * 0.01f;
Expand Down Expand Up @@ -234,7 +234,7 @@ void MeshNoisePreview::UpdateChunkQueues( const Vector3& position )
// Increase load range if queue is not full
if( (double)mTriCount < mTriLimit * 0.85 && mInProgressChunks.size() < mThreads.size() * mAvgNewChunks )
{
mLoadRange = std::min( mLoadRange * (1 + GetLoadRangeModifier()), 2000.0f );
mLoadRange = std::min( mLoadRange * (1 + GetLoadRangeModifier()), 3000.0f );
}

}
Expand Down Expand Up @@ -284,8 +284,8 @@ void MeshNoisePreview::UpdateChunksForPosition( Vector3 position )


if( ( positionI - chunkPos ).dot() <= loadRangeSq &&
mChunks.find( chunkPos ) == mChunks.end() &&
mInProgressChunks.find( chunkPos ) == mInProgressChunks.end() )
!mChunks.contains( chunkPos ) &&
!mInProgressChunks.contains( chunkPos ) )
{
chunkPositions.push_back( chunkPos );
}
Expand All @@ -311,7 +311,7 @@ void MeshNoisePreview::UpdateChunksForPosition( Vector3 position )
}
}

//ImGui::Text( "UpdateChunksForPosition(%d) Ms: %.2f", staggerShift, GetTimerDurationMs() );
ImGui::Text( "UpdateChunksForPosition(%d) Ms: %.2f", staggerShift, GetTimerDurationMs() );
}

void MeshNoisePreview::GenerateLoopThread( GenerateQueue<Chunk::BuildData>& generateQueue, CompleteQueue<Chunk::MeshData>& completeQueue )
Expand Down
11 changes: 8 additions & 3 deletions NoiseTool/MeshNoisePreview.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <Magnum/GL/AbstractShaderProgram.h>
#include <Magnum/GL/Shader.h>

#include <robin_hood.h>

#include "FastNoise/FastNoise.h"
#include "MultiThreadQueues.h"

Expand Down Expand Up @@ -155,7 +157,10 @@ namespace Magnum
{
size_t operator()( const Vector3i& v ) const
{
return (size_t)v.x() ^ ((size_t)v.y() << sizeof( size_t ) * 2) ^ ((size_t)v.z() << sizeof( size_t ) * 4);
return robin_hood::hash<size_t>()(
(size_t)v.x() ^
((size_t)v.y() << sizeof( size_t ) * 2) ^
((size_t)v.z() << sizeof( size_t ) * 4) );
}
};

Expand All @@ -169,8 +174,8 @@ namespace Magnum
float GetTimerDurationMs();
void SetupSettingsHandlers();

std::unordered_map<Vector3i, Chunk, Vector3iHash> mChunks;
std::unordered_set<Vector3i, Vector3iHash> mInProgressChunks;
robin_hood::unordered_node_map<Vector3i, Chunk, Vector3iHash> mChunks;
robin_hood::unordered_set<Vector3i, Vector3iHash> mInProgressChunks;
std::vector<Vector3i> mDistanceOrderedChunks;

bool mEnabled = true;
Expand Down

0 comments on commit 00230ff

Please sign in to comment.