-
-
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.
fix imgui, add dice tool and p2prng (non functional yet)
- Loading branch information
Showing
10 changed files
with
305 additions
and
3 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
Submodule solanaceae_tox_p2prng
added at
516df1
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,162 @@ | ||
#include "./dice_tool.hpp" | ||
|
||
#include <solanaceae/contact/components.hpp> | ||
|
||
#include <imgui.h> | ||
|
||
#include <entt/container/dense_set.hpp> | ||
|
||
#include <cstdint> | ||
#include <iostream> | ||
|
||
DiceTool::DiceTool(P2PRNGI& p2prng, Contact3Registry& cr) : _p2prng(p2prng), _cr(cr) { | ||
p2prng.subscribe(this, P2PRNG_Event::init); | ||
p2prng.subscribe(this, P2PRNG_Event::hmac); | ||
p2prng.subscribe(this, P2PRNG_Event::secret); | ||
p2prng.subscribe(this, P2PRNG_Event::done); | ||
p2prng.subscribe(this, P2PRNG_Event::val_error); | ||
} | ||
|
||
DiceTool::~DiceTool(void) { | ||
} | ||
|
||
float DiceTool::render(float) { | ||
if (ImGui::Begin("DiceTool")) { | ||
// header with values for new roll | ||
|
||
ImGui::TextUnformatted("sides:"); | ||
ImGui::SameLine(); | ||
static uint16_t g_sides {6}; | ||
ImGui::InputScalar("##sides", ImGuiDataType_U16, &g_sides); | ||
|
||
static entt::dense_set<Contact3> peers; | ||
|
||
if (ImGui::CollapsingHeader("peers")) { | ||
ImGui::Indent(); | ||
// list with peers participating | ||
|
||
for (auto it = peers.begin(); it != peers.end();) { | ||
ImGui::PushID(entt::to_integral(*it)); | ||
if (ImGui::SmallButton("-")) { | ||
it = peers.erase(it); | ||
ImGui::PopID(); | ||
continue; | ||
} | ||
|
||
Contact3Handle c {_cr, *it}; | ||
|
||
const char* str_ptr = "<unk>"; | ||
if (const auto* name_ptr = c.try_get<Contact::Components::Name>(); name_ptr != nullptr && !name_ptr->name.empty()) { | ||
str_ptr = name_ptr->name.c_str(); | ||
} | ||
|
||
ImGui::SameLine(); | ||
ImGui::TextUnformatted(str_ptr); | ||
|
||
ImGui::PopID(); | ||
it++; | ||
} | ||
|
||
if (ImGui::Button("add")) { | ||
ImGui::OpenPopup("peer selector"); | ||
} | ||
if (ImGui::BeginPopup("peer selector")) { | ||
for (const auto& [cv] : _cr.view<Contact::Components::TagBig>().each()) { | ||
Contact3Handle c {_cr, cv}; | ||
|
||
if (peers.contains(c)) { | ||
continue; | ||
} | ||
|
||
const char* str_ptr = "<unk>"; | ||
if (const auto* name_ptr = c.try_get<Contact::Components::Name>(); name_ptr != nullptr && !name_ptr->name.empty()) { | ||
str_ptr = name_ptr->name.c_str(); | ||
} | ||
|
||
if (c.all_of<Contact::Components::TagGroup, Contact::Components::ParentOf>()) { | ||
if (ImGui::BeginMenu(str_ptr)) { | ||
for (const Contact3 child_cv : c.get<Contact::Components::ParentOf>().subs) { | ||
Contact3Handle child_c {_cr, child_cv}; | ||
|
||
if (peers.contains(child_c)) { | ||
continue; | ||
} | ||
|
||
const char* child_str_ptr = "<unk>"; | ||
if (const auto* name_ptr = child_c.try_get<Contact::Components::Name>(); name_ptr != nullptr && !name_ptr->name.empty()) { | ||
child_str_ptr = name_ptr->name.c_str(); | ||
} | ||
|
||
if (ImGui::MenuItem(child_str_ptr)) { | ||
peers.emplace(child_c); | ||
} | ||
} | ||
ImGui::EndMenu(); | ||
} | ||
} else { | ||
if (ImGui::MenuItem(str_ptr)) { | ||
peers.emplace(c); | ||
} | ||
} | ||
} | ||
|
||
|
||
ImGui::EndPopup(); | ||
} | ||
|
||
ImGui::SameLine(); | ||
if (ImGui::Button("clear")) { | ||
peers.clear(); | ||
} | ||
|
||
ImGui::Unindent(); | ||
} | ||
|
||
if (ImGui::Button("roll")) { | ||
//std::vector<Contact3Handle> c_vec{peers.cbegin(), peers.cend()}; | ||
std::vector<Contact3Handle> c_vec; | ||
for (const auto cv : peers) { | ||
c_vec.emplace_back(_cr, cv); | ||
} | ||
|
||
auto new_id = _p2prng.newGernationPeers(c_vec, ByteSpan{reinterpret_cast<uint8_t*>(&g_sides), sizeof(g_sides)}); | ||
if (!new_id.empty()) { | ||
auto& new_roll = _rolls.emplace_back(); | ||
new_roll.id = new_id; | ||
} | ||
} | ||
|
||
ImGui::SeparatorText("Rolls"); | ||
|
||
// list of past rolls and their state | ||
//ImGui::CollapsingHeader("d"); | ||
ImGui::Text("d6 [?] hmac 4/6"); | ||
ImGui::Text("d6 [?] secret 1/3"); | ||
ImGui::Text("d6 [1]"); | ||
} | ||
ImGui::End(); | ||
|
||
return 10.f; | ||
} | ||
|
||
bool DiceTool::onEvent(const P2PRNG::Events::Init&) { | ||
return false; | ||
} | ||
|
||
bool DiceTool::onEvent(const P2PRNG::Events::HMAC&) { | ||
return false; | ||
} | ||
|
||
bool DiceTool::onEvent(const P2PRNG::Events::Secret&) { | ||
return false; | ||
} | ||
|
||
bool DiceTool::onEvent(const P2PRNG::Events::Done&) { | ||
std::cout << "got a done!!!!!!!!!!!!!!!!!!\n"; | ||
return false; | ||
} | ||
|
||
bool DiceTool::onEvent(const P2PRNG::Events::ValError&) { | ||
return false; | ||
} | ||
|
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,36 @@ | ||
#pragma once | ||
|
||
#include <solanaceae/tox_p2prng/p2prng.hpp> | ||
#include <solanaceae/contact/contact_model3.hpp> | ||
|
||
#include <vector> | ||
|
||
class DiceTool : public P2PRNGEventI { | ||
P2PRNGI& _p2prng; | ||
Contact3Registry& _cr; | ||
|
||
struct Rolls { | ||
std::vector<uint8_t> id; | ||
|
||
P2PRNG::State state {P2PRNG::State::UNKNOWN}; | ||
uint16_t state_number_1{}; | ||
uint16_t state_number_2{}; | ||
|
||
uint16_t final_result{}; | ||
}; | ||
std::vector<Rolls> _rolls; | ||
|
||
public: | ||
DiceTool(P2PRNGI& p2prng, Contact3Registry& cr); | ||
~DiceTool(void); | ||
|
||
float render(float time_delta); | ||
|
||
protected: // p2prng | ||
bool onEvent(const P2PRNG::Events::Init&) override; | ||
bool onEvent(const P2PRNG::Events::HMAC&) override; | ||
bool onEvent(const P2PRNG::Events::Secret&) override; | ||
bool onEvent(const P2PRNG::Events::Done&) override; | ||
bool onEvent(const P2PRNG::Events::ValError&) override; | ||
}; | ||
|
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,79 @@ | ||
#include <solanaceae/plugin/solana_plugin_v1.h> | ||
|
||
#include "./dice_tool.hpp" | ||
#include <imgui.h> | ||
|
||
#include <entt/entt.hpp> | ||
#include <entt/fwd.hpp> | ||
|
||
#include <memory> | ||
#include <limits> | ||
#include <iostream> | ||
|
||
static std::unique_ptr<DiceTool> g_dt = nullptr; | ||
|
||
constexpr const char* plugin_name = "DiceTool"; | ||
|
||
extern "C" { | ||
|
||
SOLANA_PLUGIN_EXPORT const char* solana_plugin_get_name(void) { | ||
return plugin_name; | ||
} | ||
|
||
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_get_version(void) { | ||
return SOLANA_PLUGIN_VERSION; | ||
} | ||
|
||
SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) { | ||
std::cout << "PLUGIN " << plugin_name << " START()\n"; | ||
|
||
if (solana_api == nullptr) { | ||
return 1; | ||
} | ||
|
||
try { | ||
auto* p2prng_i = PLUG_RESOLVE_INSTANCE(P2PRNGI); | ||
auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1"); | ||
|
||
// static store, could be anywhere tho | ||
// construct with fetched dependencies | ||
g_dt = std::make_unique<DiceTool>(*p2prng_i, *cr); | ||
|
||
auto* imguic = PLUG_RESOLVE_INSTANCE_VERSIONED(ImGuiContext, ImGui::GetVersion()); | ||
auto* imguimemaf = PLUG_RESOLVE_INSTANCE_VERSIONED(ImGuiMemAllocFunc, ImGui::GetVersion()); | ||
auto* imguimemff = PLUG_RESOLVE_INSTANCE_VERSIONED(ImGuiMemFreeFunc, ImGui::GetVersion()); | ||
// meh | ||
auto* imguimemud = plug_resolveInstanceOptional<void*>(solana_api, "ImGuiMemUserData", ImGui::GetVersion()); | ||
|
||
ImGui::SetCurrentContext(imguic); | ||
ImGui::SetAllocatorFunctions(imguimemaf, imguimemff, imguimemud); | ||
|
||
// register types | ||
PLUG_PROVIDE_INSTANCE(DiceTool, plugin_name, g_dt.get()); | ||
} catch (const ResolveException& e) { | ||
std::cerr << "PLUGIN " << plugin_name << " " << e.what << "\n"; | ||
return 2; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
SOLANA_PLUGIN_EXPORT void solana_plugin_stop(void) { | ||
std::cout << "PLUGIN " << plugin_name << " STOP()\n"; | ||
|
||
g_dt.reset(); | ||
} | ||
|
||
SOLANA_PLUGIN_EXPORT float solana_plugin_tick(float delta) { | ||
(void)delta; | ||
//g_dt->iterate(); | ||
|
||
return std::numeric_limits<float>::max(); | ||
} | ||
|
||
SOLANA_PLUGIN_EXPORT float solana_plugin_render(float delta) { | ||
return g_dt->render(delta); | ||
} | ||
|
||
} // extern C | ||
|