-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fe4b2b
commit 12a3f78
Showing
10 changed files
with
163 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <atomic> | ||
#include <mutex> | ||
#include <thread> | ||
#include "world.hpp" | ||
#include "distance_field_builder.hpp" | ||
|
||
|
||
struct AsyncDistanceFieldBuilder | ||
{ | ||
WorldGrid& map; | ||
std::atomic<bool> update_requested; | ||
bool running; | ||
std::mutex mutex; | ||
std::condition_variable condition; | ||
std::thread worker; | ||
|
||
explicit | ||
AsyncDistanceFieldBuilder(WorldGrid& map_) | ||
: map(map_) | ||
, update_requested(false) | ||
, running(true) | ||
{ | ||
worker = std::thread([this]{update();}); | ||
} | ||
|
||
~AsyncDistanceFieldBuilder() | ||
{ | ||
update_requested = true; | ||
running = false; | ||
condition.notify_all(); | ||
worker.join(); | ||
} | ||
|
||
void update() | ||
{ | ||
std::unique_lock<std::mutex> lock(mutex); | ||
while (running) { | ||
condition.wait(lock, [this](){return update_requested.load();}); | ||
update_requested = false; | ||
DistanceFieldBuilder::computeDistance(map); | ||
} | ||
} | ||
|
||
void requestUpdate() | ||
{ | ||
update_requested = true; | ||
condition.notify_all(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ struct MapLoader | |
} | ||
} | ||
} | ||
DistanceFieldBuilder::computeDistance(world.map); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters