Browse Source

Add parallel processes to game context

master
C. J. Howard 3 years ago
parent
commit
68ef139df4
4 changed files with 22 additions and 1 deletions
  1. +1
    -0
      src/debug/logger.cpp
  2. +2
    -0
      src/debug/logger.hpp
  3. +15
    -1
      src/game/bootloader.cpp
  4. +4
    -0
      src/game/context.hpp

+ 1
- 0
src/debug/logger.cpp View File

@ -71,6 +71,7 @@ void logger::log(const std::string& text)
message += "\n"; message += "\n";
// Add message to log history // Add message to log history
const std::lock_guard<std::mutex> history_lock(history_mutex);
history += message; history += message;
// Output message // Output message

+ 2
- 0
src/debug/logger.hpp View File

@ -24,6 +24,7 @@
#include <ostream> #include <ostream>
#include <stack> #include <stack>
#include <string> #include <string>
#include <mutex>
namespace debug { namespace debug {
@ -115,6 +116,7 @@ private:
std::string success_postfix; std::string success_postfix;
std::stack<std::string> tasks; std::stack<std::string> tasks;
std::string history; std::string history;
std::mutex history_mutex;
}; };
inline const std::string& logger::get_history() const inline const std::string& logger::get_history() const

+ 15
- 1
src/game/bootloader.cpp View File

@ -93,6 +93,8 @@
#include <functional> #include <functional>
#include <string> #include <string>
#include <vector> #include <vector>
#include <execution>
#include <algorithm>
static constexpr double seconds_per_day = 24.0 * 60.0 * 60.0; static constexpr double seconds_per_day = 24.0 * 60.0 * 60.0;
@ -992,6 +994,18 @@ void setup_callbacks(game::context* ctx)
for (const auto& control: ctx->controls) for (const auto& control: ctx->controls)
control.second->update(); control.second->update();
// Update processes
std::for_each
(
std::execution::par,
ctx->processes.begin(),
ctx->processes.end(),
[t, dt](const auto& process)
{
process.second(t, dt);
}
);
// Update tweens // Update tweens
ctx->time_tween->update(); ctx->time_tween->update();
ctx->surface_sky_pass->update_tweens(); ctx->surface_sky_pass->update_tweens();
@ -1001,7 +1015,7 @@ void setup_callbacks(game::context* ctx)
// Set time tween time // Set time tween time
(*ctx->time_tween)[1] = t; (*ctx->time_tween)[1] = t;
ctx->timeline->advance(dt); ctx->timeline->advance(dt);

+ 4
- 0
src/game/context.hpp View File

@ -40,6 +40,7 @@
#include <optional> #include <optional>
#include <entt/entt.hpp> #include <entt/entt.hpp>
#include <fstream> #include <fstream>
#include <queue>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include "resources/json.hpp" #include "resources/json.hpp"
@ -216,6 +217,9 @@ struct context
input::mapper* input_mapper; input::mapper* input_mapper;
input::listener* input_listener; input::listener* input_listener;
std::unordered_map<std::string, input::control*> controls; std::unordered_map<std::string, input::control*> controls;
// Parallel processes
std::unordered_map<std::string, std::function<void(double, double)>> processes;
// Entities // Entities
entity::registry* entity_registry; entity::registry* entity_registry;

Loading…
Cancel
Save