-
Notifications
You must be signed in to change notification settings - Fork 60
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
Showing
12 changed files
with
103 additions
and
42 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
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,48 @@ | ||
|
||
#ifndef THREEPP_TASKMANAGER_HPP | ||
#define THREEPP_TASKMANAGER_HPP | ||
|
||
#include <functional> | ||
#include <queue> | ||
#include <utility> | ||
|
||
namespace threepp::utils { | ||
|
||
using Task = std::pair<std::function<void()>, double>; | ||
|
||
class TaskManager { | ||
|
||
public: | ||
inline void handleTasks(double deltaTime) { | ||
|
||
time += deltaTime; | ||
|
||
while (!tasks_.empty()) { | ||
auto& task = tasks_.top(); | ||
if (task.second < time) { | ||
task.first(); | ||
tasks_.pop(); | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void invokeLater(const std::function<void()>& f, double delay = 0) { | ||
|
||
tasks_.emplace(f, time + delay); | ||
} | ||
|
||
private: | ||
struct CustomComparator { | ||
bool operator()(const Task& l, const Task& r) const { return l.second > r.second; } | ||
}; | ||
|
||
double time{}; | ||
|
||
std::priority_queue<Task, std::vector<Task>, CustomComparator> tasks_; | ||
}; | ||
|
||
}// namespace threepp::utils | ||
|
||
#endif//THREEPP_TASKMANAGER_HPP |