generated from godotengine/godot-cpp-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose
Scheme
nodes to the repl upon _enter_tree
- Loading branch information
Showing
15 changed files
with
306 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef GODOT_S7_SCHEME_REPL_DEBUG_HPP | ||
#define GODOT_S7_SCHEME_REPL_DEBUG_HPP | ||
|
||
#include <godot_cpp/variant/utility_functions.hpp> | ||
|
||
using gd = godot::UtilityFunctions; | ||
|
||
#define DEBUG_REPL_INTERACTIONS 0 | ||
|
||
#if DEBUG_REPL_INTERACTIONS | ||
#define DEBUG_REPL(...) gd::print(__VA_ARGS__) | ||
#else | ||
#define DEBUG_REPL(...) 0 | ||
#endif | ||
|
||
#endif |
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,40 @@ | ||
#ifndef GODOT_S7_SCHEME_REPL_MESSAGE_HPP | ||
#define GODOT_S7_SCHEME_REPL_MESSAGE_HPP | ||
|
||
#include <godot_cpp/variant/string_name.hpp> | ||
#include <godot_cpp/variant/variant.hpp> | ||
#include <variant> | ||
|
||
struct ReplMessage { | ||
|
||
static ReplMessage publish_node(godot::StringName node_name, uint64_t node_id) { | ||
return ReplMessage{ PublishNode{ node_name, node_id } }; | ||
} | ||
|
||
static ReplMessage unpublish_node(uint64_t node_id) { | ||
return ReplMessage{ UnpublishNode{ node_id } }; | ||
} | ||
|
||
static ReplMessage eval_response(uint64_t request_id, godot::Variant result) { | ||
return ReplMessage{ EvalResponse{ request_id, result } }; | ||
} | ||
|
||
struct PublishNode { | ||
godot::StringName node_name; | ||
uint64_t node_id; | ||
}; | ||
|
||
struct UnpublishNode { | ||
uint64_t node_id; | ||
}; | ||
|
||
struct EvalResponse { | ||
uint64_t request_id; | ||
godot::Variant result; | ||
}; | ||
|
||
using Payload = std::variant<PublishNode, UnpublishNode, EvalResponse>; | ||
Payload payload; | ||
}; | ||
|
||
#endif |
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,28 @@ | ||
#include "node_registry.hpp" | ||
#include "debug.hpp" | ||
#include <godot_cpp/variant/utility_functions.hpp> | ||
|
||
using namespace godot; | ||
|
||
std::vector<String> ReplNodeRegistry::get_available_node_names() { | ||
auto result = std::vector<String>(); | ||
for (auto node = nodes.begin(); node != nodes.end(); ++node) { | ||
result.push_back(node->node_name); | ||
} | ||
return result; | ||
} | ||
|
||
void ReplNodeRegistry::register_node(uint64_t node_id, String node_name) { | ||
DEBUG_REPL("Scheme node ", node_name, " is available for repl interaction."); | ||
nodes.emplace_back(std::move(NodeRecord{ node_id, std::move(node_name) })); | ||
} | ||
|
||
void ReplNodeRegistry::unregister_node(uint64_t node_id) { | ||
for (auto node = nodes.begin(); node != nodes.end(); ++node) { | ||
if (node->node_id == node_id) { | ||
DEBUG_REPL("Scheme node ", node->node_name, " is no longer available for repl interaction."); | ||
nodes.erase(node); | ||
break; | ||
} | ||
} | ||
} |
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,21 @@ | ||
#ifndef GODOT_S7_SCHEME_REPL_NODE_REGISTRY_HPP | ||
#define GODOT_S7_SCHEME_REPL_NODE_REGISTRY_HPP | ||
|
||
#include <godot_cpp/variant/string.hpp> | ||
#include <vector> | ||
|
||
class ReplNodeRegistry { | ||
public: | ||
std::vector<godot::String> get_available_node_names(); | ||
void register_node(uint64_t node_id, godot::String node_name); | ||
void unregister_node(uint64_t node_id); | ||
|
||
private: | ||
struct NodeRecord { | ||
uint64_t node_id; | ||
godot::String node_name; | ||
}; | ||
|
||
std::vector<NodeRecord> nodes; | ||
}; | ||
#endif |
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,30 @@ | ||
#ifndef GODOT_S7_SCHEME_THREAD_SAFE_QUEUE_HPP | ||
#define GODOT_S7_SCHEME_THREAD_SAFE_QUEUE_HPP | ||
|
||
#include <mutex> | ||
#include <optional> | ||
#include <queue> | ||
|
||
template <typename T> | ||
class ThreadSafeQueue { | ||
private: | ||
std::queue<T> queue; | ||
std::mutex mutex; | ||
|
||
public: | ||
void push(T item) { | ||
std::lock_guard<std::mutex> lock(mutex); | ||
queue.push(std::move(item)); | ||
} | ||
|
||
std::optional<T> pop() { | ||
std::unique_lock<std::mutex> lock(mutex); | ||
if (queue.empty()) { | ||
return std::nullopt; | ||
} | ||
T item = std::move(queue.front()); | ||
queue.pop(); | ||
return std::move(item); | ||
} | ||
}; | ||
#endif |
Oops, something went wrong.