Switched bookmark manager to net object system
This commit is contained in:
parent
65436429b8
commit
c6f2ff18ef
12 changed files with 71 additions and 176 deletions
|
|
@ -67,6 +67,9 @@ namespace NetworkingObjects {
|
||||||
}
|
}
|
||||||
virtual uint32_t size() const = 0;
|
virtual uint32_t size() const = 0;
|
||||||
virtual const std::vector<NetObjOrderedListObjectInfoPtr<T>>& get_data() const = 0;
|
virtual const std::vector<NetObjOrderedListObjectInfoPtr<T>>& get_data() const = 0;
|
||||||
|
virtual const NetObjOrderedListObjectInfoPtr<T>& info_at(uint32_t index) const = 0;
|
||||||
|
virtual const NetObjPtr<T>& at(uint32_t index) const = 0;
|
||||||
|
virtual bool empty() const = 0;
|
||||||
virtual ~NetObjOrderedList() {}
|
virtual ~NetObjOrderedList() {}
|
||||||
protected:
|
protected:
|
||||||
virtual void insert(const NetObjPtr<NetObjOrderedList<T>>& l, uint32_t posToInsertAt, const NetObjPtr<T>& newObj) = 0;
|
virtual void insert(const NetObjPtr<NetObjOrderedList<T>>& l, uint32_t posToInsertAt, const NetObjPtr<T>& newObj) = 0;
|
||||||
|
|
@ -96,6 +99,15 @@ namespace NetworkingObjects {
|
||||||
virtual const std::vector<NetObjOrderedListObjectInfoPtr<T>>& get_data() const override {
|
virtual const std::vector<NetObjOrderedListObjectInfoPtr<T>>& get_data() const override {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
virtual const NetObjOrderedListObjectInfoPtr<T>& info_at(uint32_t index) const override {
|
||||||
|
return data[index];
|
||||||
|
}
|
||||||
|
virtual const NetObjPtr<T>& at(uint32_t index) const override {
|
||||||
|
return data[index]->obj;
|
||||||
|
}
|
||||||
|
virtual bool empty() const override {
|
||||||
|
return data.empty();
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
virtual void insert(const NetObjPtr<NetObjOrderedList<T>>& l, uint32_t posToInsertAt, const NetObjPtr<T>& newObj) override {
|
virtual void insert(const NetObjPtr<NetObjOrderedList<T>>& l, uint32_t posToInsertAt, const NetObjPtr<T>& newObj) override {
|
||||||
uint32_t actualPosToInsertAt = posToInsertAt = std::min<uint32_t>(posToInsertAt, data.size());
|
uint32_t actualPosToInsertAt = posToInsertAt = std::min<uint32_t>(posToInsertAt, data.size());
|
||||||
|
|
@ -183,6 +195,15 @@ namespace NetworkingObjects {
|
||||||
virtual const std::vector<NetObjOrderedListObjectInfoPtr<T>>& get_data() const override {
|
virtual const std::vector<NetObjOrderedListObjectInfoPtr<T>>& get_data() const override {
|
||||||
return clientData;
|
return clientData;
|
||||||
}
|
}
|
||||||
|
virtual const NetObjOrderedListObjectInfoPtr<T>& info_at(uint32_t index) const override {
|
||||||
|
return clientData[index];
|
||||||
|
}
|
||||||
|
virtual const NetObjPtr<T>& at(uint32_t index) const override {
|
||||||
|
return clientData[index]->obj;
|
||||||
|
}
|
||||||
|
virtual bool empty() const override {
|
||||||
|
return clientData.empty();
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
virtual void insert(const NetObjPtr<NetObjOrderedList<T>>& l, uint32_t posToInsertAt, const NetObjPtr<T>& newObj) {
|
virtual void insert(const NetObjPtr<NetObjOrderedList<T>>& l, uint32_t posToInsertAt, const NetObjPtr<T>& newObj) {
|
||||||
uint32_t actualPosToInsertAt = posToInsertAt = std::min<uint32_t>(posToInsertAt, clientData.size());
|
uint32_t actualPosToInsertAt = posToInsertAt = std::min<uint32_t>(posToInsertAt, clientData.size());
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "BookmarkManager.hpp"
|
#include "BookmarkManager.hpp"
|
||||||
#include "Helpers/Networking/NetLibrary.hpp"
|
#include "Helpers/Networking/NetLibrary.hpp"
|
||||||
|
#include "Helpers/NetworkingObjects/NetObjOrderedList.hpp"
|
||||||
#include "World.hpp"
|
#include "World.hpp"
|
||||||
#include "Server/CommandList.hpp"
|
#include "Server/CommandList.hpp"
|
||||||
#include "MainProgram.hpp"
|
#include "MainProgram.hpp"
|
||||||
|
|
@ -11,92 +12,25 @@ void Bookmark::scale_up(const WorldScalar& scaleUpAmount) {
|
||||||
|
|
||||||
BookmarkManager::BookmarkManager(World& w):
|
BookmarkManager::BookmarkManager(World& w):
|
||||||
world(w)
|
world(w)
|
||||||
{}
|
{
|
||||||
|
if(w.netObjMan.is_server())
|
||||||
void BookmarkManager::init_client_callbacks() {
|
bookmarks = w.netObjMan.make_obj<NetworkingObjects::NetObjOrderedList<Bookmark>>();
|
||||||
world.con.client_add_recv_callback(CLIENT_NEW_BOOKMARK, [&](cereal::PortableBinaryInputArchive& message) {
|
|
||||||
std::string bName;
|
|
||||||
message(bName);
|
|
||||||
auto& b = bookmarks[bName];
|
|
||||||
message(b);
|
|
||||||
changed = true;
|
|
||||||
});
|
|
||||||
world.con.client_add_recv_callback(CLIENT_REMOVE_BOOKMARK, [&](cereal::PortableBinaryInputArchive& message) {
|
|
||||||
std::string name;
|
|
||||||
message(name);
|
|
||||||
bookmarks.erase(name);
|
|
||||||
changed = true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarkManager::add_bookmark(const std::string& name) {
|
void BookmarkManager::add_bookmark(const std::string& name) {
|
||||||
Bookmark b{world.drawData.cam.c, world.main.window.size.cast<int32_t>()};
|
NetworkingObjects::NetObjPtr<Bookmark> a = bookmarks->emplace_back_direct(bookmarks, Bookmark{name, world.drawData.cam.c, world.main.window.size.cast<int32_t>()});
|
||||||
bookmarks[name] = b;
|
|
||||||
world.con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_NEW_BOOKMARK, name, b);
|
|
||||||
changed = true;
|
|
||||||
|
|
||||||
world.undo.push({[&world = world, &changed = changed, &bookmarks = bookmarks, name](){
|
|
||||||
bookmarks.erase(name);
|
|
||||||
world.con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_REMOVE_BOOKMARK, name);
|
|
||||||
changed = true;
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
[&world = world, &changed = changed, &bookmarks = bookmarks, name, b]() {
|
|
||||||
bookmarks[name] = b;
|
|
||||||
world.con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_NEW_BOOKMARK, name, b);
|
|
||||||
changed = true;
|
|
||||||
return true;
|
|
||||||
}});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarkManager::remove_bookmark(const std::string& name) {
|
void BookmarkManager::remove_bookmark(uint32_t bookmarkIndex) {
|
||||||
world.con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_REMOVE_BOOKMARK, name);
|
bookmarks->erase(bookmarks, bookmarkIndex);
|
||||||
auto it = bookmarks.find(name);
|
|
||||||
if(it != bookmarks.end()) {
|
|
||||||
Bookmark b = it->second;
|
|
||||||
bookmarks.erase(it);
|
|
||||||
|
|
||||||
changed = true;
|
|
||||||
|
|
||||||
world.undo.push({[&world = world, &changed = changed, &bookmarks = bookmarks, name, b](){
|
|
||||||
bookmarks[name] = b;
|
|
||||||
world.con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_NEW_BOOKMARK, name, b);
|
|
||||||
changed = true;
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
[&world = world, &changed = changed, &bookmarks = bookmarks, name]() {
|
|
||||||
bookmarks.erase(name);
|
|
||||||
world.con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_REMOVE_BOOKMARK, name);
|
|
||||||
changed = true;
|
|
||||||
return true;
|
|
||||||
}});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarkManager::jump_to_bookmark(const std::string& name) {
|
void BookmarkManager::jump_to_bookmark(uint32_t bookmarkIndex) {
|
||||||
auto it = bookmarks.find(name);
|
const NetworkingObjects::NetObjPtr<Bookmark>& b = bookmarks->at(bookmarkIndex);
|
||||||
if(it != bookmarks.end()) {
|
world.drawData.cam.smooth_move_to(world, b->coords, b->windowSize.cast<float>());
|
||||||
auto& b = it->second;
|
|
||||||
world.drawData.cam.smooth_move_to(world, b.coords, b.windowSize.cast<float>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<std::string>& BookmarkManager::sorted_names() {
|
|
||||||
if(changed) {
|
|
||||||
sortedNames.clear();
|
|
||||||
for(auto& [k, v] : bookmarks)
|
|
||||||
sortedNames.emplace_back(k);
|
|
||||||
std::sort(sortedNames.begin(), sortedNames.end());
|
|
||||||
changed = false;
|
|
||||||
}
|
|
||||||
return sortedNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::unordered_map<std::string, Bookmark>& BookmarkManager::bookmark_list() {
|
|
||||||
return bookmarks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarkManager::scale_up(const WorldScalar& scaleUpAmount) {
|
void BookmarkManager::scale_up(const WorldScalar& scaleUpAmount) {
|
||||||
for(auto& [n, b] : bookmarks)
|
for(uint32_t i = 0; i < bookmarks->size(); i++)
|
||||||
b.scale_up(scaleUpAmount);
|
bookmarks->at(i)->scale_up(scaleUpAmount);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <Helpers/Serializers.hpp>
|
#include <Helpers/Serializers.hpp>
|
||||||
#include <cereal/types/string.hpp>
|
#include <cereal/types/string.hpp>
|
||||||
|
#include <Helpers/NetworkingObjects/NetObjOrderedList.hpp>
|
||||||
#include "SharedTypes.hpp"
|
#include "SharedTypes.hpp"
|
||||||
#include "CoordSpaceHelper.hpp"
|
#include "CoordSpaceHelper.hpp"
|
||||||
|
|
||||||
struct Bookmark {
|
struct Bookmark {
|
||||||
|
std::string name;
|
||||||
CoordSpaceHelper coords;
|
CoordSpaceHelper coords;
|
||||||
Vector<int32_t, 2> windowSize;
|
Vector<int32_t, 2> windowSize;
|
||||||
template <class Archive> void serialize(Archive& a) {
|
template <class Archive> void serialize(Archive& a) {
|
||||||
a(coords, windowSize);
|
a(name, coords, windowSize);
|
||||||
}
|
}
|
||||||
void scale_up(const WorldScalar& scaleUpAmount);
|
void scale_up(const WorldScalar& scaleUpAmount);
|
||||||
};
|
};
|
||||||
|
|
@ -18,27 +20,27 @@ class World;
|
||||||
class BookmarkManager {
|
class BookmarkManager {
|
||||||
public:
|
public:
|
||||||
BookmarkManager(World& w);
|
BookmarkManager(World& w);
|
||||||
void init_client_callbacks();
|
|
||||||
void add_bookmark(const std::string& name);
|
void add_bookmark(const std::string& name);
|
||||||
void remove_bookmark(const std::string& name);
|
void remove_bookmark(uint32_t bookmarkIndex);
|
||||||
void jump_to_bookmark(const std::string& name);
|
void jump_to_bookmark(uint32_t bookmarkIndex);
|
||||||
void scale_up(const WorldScalar& scaleUpAmount);
|
void scale_up(const WorldScalar& scaleUpAmount);
|
||||||
|
|
||||||
const std::unordered_map<std::string, Bookmark>& bookmark_list();
|
|
||||||
|
|
||||||
template <typename Archive> void save(Archive& a) const {
|
template <typename Archive> void save(Archive& a) const {
|
||||||
a(bookmarks);
|
a(bookmarks->size());
|
||||||
|
for(uint32_t i = 0; i < bookmarks->size(); i++)
|
||||||
|
a(*bookmarks->at(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Archive> void load(Archive& a) {
|
template <typename Archive> void load(Archive& a) {
|
||||||
a(bookmarks);
|
uint32_t newSize = bookmarks->size();
|
||||||
changed = true;
|
for(uint32_t i = 0; i < newSize; i++) {
|
||||||
|
Bookmark b;
|
||||||
|
a(b);
|
||||||
|
bookmarks->emplace_back_direct(bookmarks, b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::string>& sorted_names();
|
NetworkingObjects::NetObjPtr<NetworkingObjects::NetObjOrderedList<Bookmark>> bookmarks;
|
||||||
private:
|
private:
|
||||||
bool changed = true;
|
|
||||||
std::vector<std::string> sortedNames;
|
|
||||||
std::unordered_map<std::string, Bookmark> bookmarks;
|
|
||||||
World& world;
|
World& world;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ MainProgram::MainProgram():
|
||||||
netObjectTypeList = std::make_shared<NetworkingObjects::NetObjManagerTypeList>();
|
netObjectTypeList = std::make_shared<NetworkingObjects::NetObjManagerTypeList>();
|
||||||
NetworkingObjects::register_generic_serialized_class<std::string>(*netObjectTypeList);
|
NetworkingObjects::register_generic_serialized_class<std::string>(*netObjectTypeList);
|
||||||
NetworkingObjects::register_ordered_list_class<std::string>(*netObjectTypeList);
|
NetworkingObjects::register_ordered_list_class<std::string>(*netObjectTypeList);
|
||||||
|
NetworkingObjects::register_generic_serialized_class<Bookmark>(*netObjectTypeList);
|
||||||
|
NetworkingObjects::register_ordered_list_class<Bookmark>(*netObjectTypeList);
|
||||||
|
|
||||||
displayName = Random::get().alphanumeric_str(10);
|
displayName = Random::get().alphanumeric_str(10);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@ enum ServerCommands : MessageCommandType {
|
||||||
SERVER_NEW_RESOURCE_ID,
|
SERVER_NEW_RESOURCE_ID,
|
||||||
SERVER_NEW_RESOURCE_DATA,
|
SERVER_NEW_RESOURCE_DATA,
|
||||||
SERVER_CHAT_MESSAGE,
|
SERVER_CHAT_MESSAGE,
|
||||||
SERVER_NEW_BOOKMARK,
|
|
||||||
SERVER_REMOVE_BOOKMARK,
|
|
||||||
SERVER_CANVAS_COLOR,
|
SERVER_CANVAS_COLOR,
|
||||||
SERVER_SET_GRID,
|
SERVER_SET_GRID,
|
||||||
SERVER_REMOVE_GRID,
|
SERVER_REMOVE_GRID,
|
||||||
|
|
@ -44,8 +42,6 @@ enum ClientCommands : MessageCommandType {
|
||||||
CLIENT_NEW_RESOURCE_ID,
|
CLIENT_NEW_RESOURCE_ID,
|
||||||
CLIENT_NEW_RESOURCE_DATA,
|
CLIENT_NEW_RESOURCE_DATA,
|
||||||
CLIENT_CHAT_MESSAGE,
|
CLIENT_CHAT_MESSAGE,
|
||||||
CLIENT_NEW_BOOKMARK,
|
|
||||||
CLIENT_REMOVE_BOOKMARK,
|
|
||||||
CLIENT_CANVAS_COLOR,
|
CLIENT_CANVAS_COLOR,
|
||||||
CLIENT_SET_GRID,
|
CLIENT_SET_GRID,
|
||||||
CLIENT_REMOVE_GRID,
|
CLIENT_REMOVE_GRID,
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ MainServer::MainServer(World& initWorld, const std::string& serverLocalID):
|
||||||
data.idToComponentMap.emplace(data.components.back()->id, data.components.back());
|
data.idToComponentMap.emplace(data.components.back()->id, data.components.back());
|
||||||
}
|
}
|
||||||
data.canvasScale = world.canvasScale;
|
data.canvasScale = world.canvasScale;
|
||||||
data.bookmarks = world.bMan.bookmark_list();
|
|
||||||
data.grids = world.gridMan.grids;
|
data.grids = world.gridMan.grids;
|
||||||
data.resources = world.rMan.resource_list();
|
data.resources = world.rMan.resource_list();
|
||||||
data.canvasBackColor = convert_vec3<Vector3f>(world.canvasTheme.backColor);
|
data.canvasBackColor = convert_vec3<Vector3f>(world.canvasTheme.backColor);
|
||||||
|
|
@ -75,7 +74,7 @@ MainServer::MainServer(World& initWorld, const std::string& serverLocalID):
|
||||||
{
|
{
|
||||||
cereal::PortableBinaryOutputArchive a(*ss);
|
cereal::PortableBinaryOutputArchive a(*ss);
|
||||||
a(CLIENT_INITIAL_DATA, isDirectConnect, newClient.serverID, newClient.cursorColor, newClient.displayName, newClient.camCoords, newClient.windowSize, fileDisplayName, clients, data);
|
a(CLIENT_INITIAL_DATA, isDirectConnect, newClient.serverID, newClient.cursorColor, newClient.displayName, newClient.camCoords, newClient.windowSize, fileDisplayName, clients, data);
|
||||||
world.stringListTest.write_create_message(a);
|
world.bMan.bookmarks.write_create_message(a);
|
||||||
}
|
}
|
||||||
netServer->send_string_stream_to_client(client, RELIABLE_COMMAND_CHANNEL, ss);
|
netServer->send_string_stream_to_client(client, RELIABLE_COMMAND_CHANNEL, ss);
|
||||||
for(auto& [id, rData] : data.resources) {
|
for(auto& [id, rData] : data.resources) {
|
||||||
|
|
@ -230,24 +229,6 @@ MainServer::MainServer(World& initWorld, const std::string& serverLocalID):
|
||||||
message(chatMessage);
|
message(chatMessage);
|
||||||
netServer->send_items_to_all_clients_except(client, RELIABLE_COMMAND_CHANNEL, CLIENT_CHAT_MESSAGE, client->customID, chatMessage);
|
netServer->send_items_to_all_clients_except(client, RELIABLE_COMMAND_CHANNEL, CLIENT_CHAT_MESSAGE, client->customID, chatMessage);
|
||||||
});
|
});
|
||||||
netServer->add_recv_callback(SERVER_NEW_BOOKMARK, [&](std::shared_ptr<NetServer::ClientData> client, cereal::PortableBinaryInputArchive& message) {
|
|
||||||
std::string name;
|
|
||||||
message(name);
|
|
||||||
Bookmark& b = data.bookmarks[name];
|
|
||||||
message(b);
|
|
||||||
|
|
||||||
auto& c = clients[client->customID];
|
|
||||||
if(c.canvasScale < data.canvasScale)
|
|
||||||
b.scale_up(FixedPoint::pow_int(CANVAS_SCALE_UP_STEP, data.canvasScale - c.canvasScale));
|
|
||||||
|
|
||||||
netServer->send_items_to_all_clients(RELIABLE_COMMAND_CHANNEL, CLIENT_NEW_BOOKMARK, name, b);
|
|
||||||
});
|
|
||||||
netServer->add_recv_callback(SERVER_REMOVE_BOOKMARK, [&](std::shared_ptr<NetServer::ClientData> client, cereal::PortableBinaryInputArchive& message) {
|
|
||||||
std::string name;
|
|
||||||
message(name);
|
|
||||||
data.bookmarks.erase(name);
|
|
||||||
netServer->send_items_to_all_clients(RELIABLE_COMMAND_CHANNEL, CLIENT_REMOVE_BOOKMARK, name);
|
|
||||||
});
|
|
||||||
netServer->add_recv_callback(SERVER_SET_GRID, [&](std::shared_ptr<NetServer::ClientData> client, cereal::PortableBinaryInputArchive& message) {
|
netServer->add_recv_callback(SERVER_SET_GRID, [&](std::shared_ptr<NetServer::ClientData> client, cereal::PortableBinaryInputArchive& message) {
|
||||||
ServerClientID gID;
|
ServerClientID gID;
|
||||||
message(gID);
|
message(gID);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ void ServerData::save(cereal::PortableBinaryOutputArchive& a) const {
|
||||||
a((uint64_t)components.size());
|
a((uint64_t)components.size());
|
||||||
for(uint64_t i = 0; i < components.size(); i++)
|
for(uint64_t i = 0; i < components.size(); i++)
|
||||||
a(components[i]->get_type(), components[i]->id, components[i]->coords, *components[i]);
|
a(components[i]->get_type(), components[i]->id, components[i]->coords, *components[i]);
|
||||||
a(bookmarks, grids);
|
a(grids);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerData::load(cereal::PortableBinaryInputArchive& a) {
|
void ServerData::load(cereal::PortableBinaryInputArchive& a) {
|
||||||
|
|
@ -21,12 +21,10 @@ void ServerData::load(cereal::PortableBinaryInputArchive& a) {
|
||||||
components.emplace_back(newComp);
|
components.emplace_back(newComp);
|
||||||
idToComponentMap.emplace(newComp->id, newComp);
|
idToComponentMap.emplace(newComp->id, newComp);
|
||||||
}
|
}
|
||||||
a(bookmarks, grids);
|
a(grids);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerData::scale_up(const WorldScalar& scaleUpAmount) {
|
void ServerData::scale_up(const WorldScalar& scaleUpAmount) {
|
||||||
for(auto& [n, b] : bookmarks)
|
|
||||||
b.scale_up(scaleUpAmount);
|
|
||||||
for(auto& [n, g] : grids)
|
for(auto& [n, g] : grids)
|
||||||
g.scale_up(scaleUpAmount);
|
g.scale_up(scaleUpAmount);
|
||||||
for(auto& c : components)
|
for(auto& c : components)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "cereal/archives/portable_binary.hpp"
|
#include "cereal/archives/portable_binary.hpp"
|
||||||
#include "../SharedTypes.hpp"
|
#include "../SharedTypes.hpp"
|
||||||
#include "../BookmarkManager.hpp"
|
|
||||||
#include "../ResourceManager.hpp"
|
#include "../ResourceManager.hpp"
|
||||||
#include "../WorldGrid.hpp"
|
#include "../WorldGrid.hpp"
|
||||||
|
|
||||||
|
|
@ -12,7 +11,6 @@ class ServerData {
|
||||||
std::vector<std::shared_ptr<DrawComponent>> components;
|
std::vector<std::shared_ptr<DrawComponent>> components;
|
||||||
std::unordered_map<ServerClientID, std::shared_ptr<DrawComponent>> idToComponentMap;
|
std::unordered_map<ServerClientID, std::shared_ptr<DrawComponent>> idToComponentMap;
|
||||||
std::unordered_map<ServerClientID, ResourceData> resources;
|
std::unordered_map<ServerClientID, ResourceData> resources;
|
||||||
std::unordered_map<std::string, Bookmark> bookmarks;
|
|
||||||
std::unordered_map<ServerClientID, WorldGrid> grids;
|
std::unordered_map<ServerClientID, WorldGrid> grids;
|
||||||
uint64_t canvasScale = 0;
|
uint64_t canvasScale = 0;
|
||||||
Vector3f canvasBackColor;
|
Vector3f canvasBackColor;
|
||||||
|
|
|
||||||
|
|
@ -802,12 +802,12 @@ void Toolbar::bookmark_menu(bool justOpened) {
|
||||||
gui.obstructing_window();
|
gui.obstructing_window();
|
||||||
float entryHeight = 25.0f;
|
float entryHeight = 25.0f;
|
||||||
gui.text_label_centered("Bookmarks");
|
gui.text_label_centered("Bookmarks");
|
||||||
if(main.world->bMan.sorted_names().empty())
|
if(main.world->bMan.bookmarks->empty())
|
||||||
gui.text_label_centered("No bookmarks yet...");
|
gui.text_label_centered("No bookmarks yet...");
|
||||||
std::string toDelete;
|
uint32_t toDelete = std::numeric_limits<uint32_t>::max();
|
||||||
gui.scroll_bar_many_entries_area("bookmark menu entries", entryHeight, main.world->bMan.sorted_names().size(), true, [&](size_t i, bool isListHovered) {
|
gui.scroll_bar_many_entries_area("bookmark menu entries", entryHeight, main.world->bMan.bookmarks->size(), true, [&](size_t i, bool isListHovered) {
|
||||||
const std::string& bookmark = main.world->bMan.sorted_names()[i];
|
const Bookmark& bookmark = *main.world->bMan.bookmarks->at(i);
|
||||||
bool selectedEntry = bookmark == bookMenu.newName;
|
bool selectedEntry = i == bookMenu.selectedBookmark;
|
||||||
CLAY_AUTO_ID({
|
CLAY_AUTO_ID({
|
||||||
.layout = {
|
.layout = {
|
||||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(entryHeight)},
|
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(entryHeight)},
|
||||||
|
|
@ -817,7 +817,7 @@ void Toolbar::bookmark_menu(bool justOpened) {
|
||||||
},
|
},
|
||||||
.backgroundColor = selectedEntry ? convert_vec4<Clay_Color>(io->theme->backColor1) : convert_vec4<Clay_Color>(io->theme->backColor2)
|
.backgroundColor = selectedEntry ? convert_vec4<Clay_Color>(io->theme->backColor1) : convert_vec4<Clay_Color>(io->theme->backColor2)
|
||||||
}) {
|
}) {
|
||||||
gui.text_label(bookmark);
|
gui.text_label(bookmark.name);
|
||||||
bool miniButtonClicked = false;
|
bool miniButtonClicked = false;
|
||||||
CLAY_AUTO_ID({
|
CLAY_AUTO_ID({
|
||||||
.layout = {
|
.layout = {
|
||||||
|
|
@ -829,36 +829,34 @@ void Toolbar::bookmark_menu(bool justOpened) {
|
||||||
}) {
|
}) {
|
||||||
if(gui.svg_icon_button_transparent("bookmark jump button", "data/icons/jump.svg", false, entryHeight, false)) {
|
if(gui.svg_icon_button_transparent("bookmark jump button", "data/icons/jump.svg", false, entryHeight, false)) {
|
||||||
miniButtonClicked = true;
|
miniButtonClicked = true;
|
||||||
main.world->bMan.jump_to_bookmark(bookmark);
|
main.world->bMan.jump_to_bookmark(i);
|
||||||
}
|
}
|
||||||
if(gui.svg_icon_button_transparent("delete trash", "data/icons/trash.svg", false, entryHeight, false)) {
|
if(gui.svg_icon_button_transparent("delete trash", "data/icons/trash.svg", false, entryHeight, false)) {
|
||||||
miniButtonClicked = true;
|
miniButtonClicked = true;
|
||||||
toDelete = bookmark;
|
toDelete = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(Clay_Hovered() && io->mouse.leftClick && isListHovered && !miniButtonClicked) {
|
if(Clay_Hovered() && io->mouse.leftClick && isListHovered && !miniButtonClicked) {
|
||||||
bookMenu.newName = bookmark;
|
bookMenu.newName = bookmark.name;
|
||||||
if(io->mouse.leftClick >= 2)
|
if(io->mouse.leftClick >= 2)
|
||||||
main.world->bMan.jump_to_bookmark(bookmark);
|
main.world->bMan.jump_to_bookmark(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(!toDelete.empty())
|
if(toDelete != std::numeric_limits<uint32_t>::max())
|
||||||
main.world->bMan.remove_bookmark(toDelete);
|
main.world->bMan.remove_bookmark(toDelete);
|
||||||
bool bookmarkExists = std::find(main.world->bMan.sorted_names().begin(), main.world->bMan.sorted_names().end(), bookMenu.newName) != main.world->bMan.sorted_names().end();
|
|
||||||
gui.left_to_right_line_layout([&]() {
|
gui.left_to_right_line_layout([&]() {
|
||||||
bool addByEnter = false;
|
bool addByEnter = false;
|
||||||
gui.input_text("bookmark text input", &bookMenu.newName, true, [&](GUIStuff::SelectionHelper& s) {
|
gui.input_text("bookmark text input", &bookMenu.newName, true, [&](GUIStuff::SelectionHelper& s) {
|
||||||
addByEnter = s.selected && io->key.enter;
|
addByEnter = s.selected && io->key.enter;
|
||||||
});
|
});
|
||||||
if(!bookmarkExists) {
|
if((gui.svg_icon_button("bookmark add button", "data/icons/plus.svg", false, GUIStuff::GUIManager::SMALL_BUTTON_SIZE) || addByEnter) && !bookMenu.newName.empty())
|
||||||
if((gui.svg_icon_button("bookmark add button", "data/icons/plus.svg", false, GUIStuff::GUIManager::SMALL_BUTTON_SIZE) || addByEnter) && !bookMenu.newName.empty())
|
main.world->bMan.add_bookmark(bookMenu.newName);
|
||||||
main.world->bMan.add_bookmark(bookMenu.newName);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if(io->mouse.leftClick && !Clay_Hovered() && !justOpened) {
|
if(io->mouse.leftClick && !Clay_Hovered() && !justOpened) {
|
||||||
bookMenu.newName.clear();
|
bookMenu.newName.clear();
|
||||||
bookMenu.popupOpen = false;
|
bookMenu.popupOpen = false;
|
||||||
|
bookMenu.selectedBookmark = std::numeric_limits<uint32_t>::max();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gui.pop_id();
|
gui.pop_id();
|
||||||
|
|
|
||||||
|
|
@ -192,6 +192,7 @@ class Toolbar {
|
||||||
struct BookmarkMenu {
|
struct BookmarkMenu {
|
||||||
bool popupOpen = false;
|
bool popupOpen = false;
|
||||||
std::string newName;
|
std::string newName;
|
||||||
|
uint32_t selectedBookmark = std::numeric_limits<uint32_t>::max();
|
||||||
} bookMenu;
|
} bookMenu;
|
||||||
|
|
||||||
struct GridMenu {
|
struct GridMenu {
|
||||||
|
|
|
||||||
|
|
@ -66,18 +66,9 @@ World::World(MainProgram& initMain, OpenWorldInfo& worldInfo):
|
||||||
|
|
||||||
drawProg.init_client_callbacks();
|
drawProg.init_client_callbacks();
|
||||||
rMan.init_client_callbacks();
|
rMan.init_client_callbacks();
|
||||||
bMan.init_client_callbacks();
|
|
||||||
gridMan.init_client_callbacks();
|
gridMan.init_client_callbacks();
|
||||||
init_client_callbacks();
|
init_client_callbacks();
|
||||||
con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_INITIAL_DATA, displayName, false);
|
con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_INITIAL_DATA, displayName, false);
|
||||||
|
|
||||||
using namespace NetworkingObjects;
|
|
||||||
if(netObjMan.is_server()) {
|
|
||||||
stringListTest = netObjMan.make_obj<NetObjOrderedList<std::string>>();
|
|
||||||
stringListTest->emplace_back_direct(stringListTest, "Hello");
|
|
||||||
stringListTest = netObjMan.make_obj<NetObjOrderedList<std::string>>();
|
|
||||||
stringListTest->emplace_back_direct(stringListTest, "World!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::init_client_callbacks() {
|
void World::init_client_callbacks() {
|
||||||
|
|
@ -96,12 +87,8 @@ void World::init_client_callbacks() {
|
||||||
set_canvas_background_color(newBackColor, false);
|
set_canvas_background_color(newBackColor, false);
|
||||||
message(canvasScale);
|
message(canvasScale);
|
||||||
drawProg.initialize_draw_data(message);
|
drawProg.initialize_draw_data(message);
|
||||||
message(bMan, gridMan);
|
message(gridMan);
|
||||||
stringListTest = netObjMan.read_create_message<NetworkingObjects::NetObjOrderedList<std::string>>(message, nullptr);
|
bMan.bookmarks = netObjMan.read_create_message<NetworkingObjects::NetObjOrderedList<Bookmark>>(message, nullptr);
|
||||||
//std::cout << "============================================" << std::endl;
|
|
||||||
//std::cout << "Client print: " << std::endl;
|
|
||||||
//for(const NetworkingObjects::NetObjOrderedListObjectInfoPtr<std::string>& o : stringListTest->get_data())
|
|
||||||
// std::cout << "At position: " << o->get_pos() << " we have string: \"" << *o->get_obj() << "\" with object id " << o->get_obj().get_net_id().to_string() << std::endl;
|
|
||||||
}
|
}
|
||||||
nextClientID = get_max_id(ownID);
|
nextClientID = get_max_id(ownID);
|
||||||
clientStillConnecting = false;
|
clientStillConnecting = false;
|
||||||
|
|
@ -116,14 +103,8 @@ void World::init_client_callbacks() {
|
||||||
add_chat_message(clients[id].displayName, "joined", Toolbar::ChatMessage::Type::JOIN);
|
add_chat_message(clients[id].displayName, "joined", Toolbar::ChatMessage::Type::JOIN);
|
||||||
});
|
});
|
||||||
con.client_add_recv_callback(CLIENT_UPDATE_NETWORK_OBJECT, [&](cereal::PortableBinaryInputArchive& message) {
|
con.client_add_recv_callback(CLIENT_UPDATE_NETWORK_OBJECT, [&](cereal::PortableBinaryInputArchive& message) {
|
||||||
if(!con.host_exists() && !clientStillConnecting) { // Dont update a direct connected client (which is just the server), and dont process these until the CLIENT_INITIAL_DATA message is received first
|
if(!con.host_exists() && !clientStillConnecting) // Dont update a direct connected client (which is just the server), and dont process these until the CLIENT_INITIAL_DATA message is received first
|
||||||
netObjMan.read_update_message(message, nullptr);
|
netObjMan.read_update_message(message, nullptr);
|
||||||
//std::cout << "============================================\n";
|
|
||||||
//std::cout << "Client print update: \n";
|
|
||||||
//for(const NetworkingObjects::NetObjOrderedListObjectInfoPtr<std::string>& o : stringListTest->get_data())
|
|
||||||
// std::cout << "At position: " << o->get_pos() << " we have string: \"" << *o->get_obj() << "\" with object id " << o->get_obj().get_net_id().to_string() << '\n';
|
|
||||||
//std::cout << std::endl;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
con.client_add_recv_callback(CLIENT_USER_DISCONNECT, [&](cereal::PortableBinaryInputArchive& message) {
|
con.client_add_recv_callback(CLIENT_USER_DISCONNECT, [&](cereal::PortableBinaryInputArchive& message) {
|
||||||
ServerPortionID id;
|
ServerPortionID id;
|
||||||
|
|
@ -172,9 +153,6 @@ void World::init_client_callbacks() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t testTimer = 0;
|
|
||||||
size_t strToAddNum = 0;
|
|
||||||
|
|
||||||
void World::focus_update() {
|
void World::focus_update() {
|
||||||
con.update();
|
con.update();
|
||||||
|
|
||||||
|
|
@ -208,17 +186,6 @@ void World::focus_update() {
|
||||||
}
|
}
|
||||||
con.client_send_items_to_server(UNRELIABLE_COMMAND_CHANNEL, SERVER_MOVE_SCREEN_MOUSE, main.input.mouse.pos);
|
con.client_send_items_to_server(UNRELIABLE_COMMAND_CHANNEL, SERVER_MOVE_SCREEN_MOUSE, main.input.mouse.pos);
|
||||||
drawProg.update();
|
drawProg.update();
|
||||||
|
|
||||||
testTimer++;
|
|
||||||
if(testTimer == 1) {
|
|
||||||
std::string strToAdd = (netObjMan.is_server() ? "Server " : "Client ") + std::to_string(strToAddNum++);
|
|
||||||
//std::cout << "============================================\n";
|
|
||||||
//std::cout << "Added: " << strToAdd << std::endl;
|
|
||||||
stringListTest->emplace_back_direct(stringListTest, strToAdd);
|
|
||||||
//for(const NetworkingObjects::NetObjOrderedListObjectInfoPtr<std::string>& o : stringListTest->get_data())
|
|
||||||
// std::cout << "At position: " << o->get_pos() << " we have string: \"" << *o->get_obj() << "\" with object id " << o->get_obj().get_net_id().to_string() << std::endl;
|
|
||||||
testTimer = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drawData.cam.update_main(*this);
|
drawData.cam.update_main(*this);
|
||||||
|
|
@ -317,7 +284,6 @@ void World::start_hosting(const std::string& initNetSource, const std::string& s
|
||||||
con.init_local_p2p(*this, serverLocalID);
|
con.init_local_p2p(*this, serverLocalID);
|
||||||
drawProg.init_client_callbacks();
|
drawProg.init_client_callbacks();
|
||||||
rMan.init_client_callbacks();
|
rMan.init_client_callbacks();
|
||||||
bMan.init_client_callbacks();
|
|
||||||
gridMan.init_client_callbacks();
|
gridMan.init_client_callbacks();
|
||||||
init_client_callbacks();
|
init_client_callbacks();
|
||||||
con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_INITIAL_DATA, displayName, true, drawData.cam.c, main.window.size.cast<float>().eval());
|
con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_INITIAL_DATA, displayName, true, drawData.cam.c, main.window.size.cast<float>().eval());
|
||||||
|
|
|
||||||
|
|
@ -93,8 +93,6 @@ class World {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::unordered_map<ServerPortionID, ClientData> clients;
|
std::unordered_map<ServerPortionID, ClientData> clients;
|
||||||
|
|
||||||
NetworkingObjects::NetObjPtr<NetworkingObjects::NetObjOrderedList<std::string>> stringListTest;
|
|
||||||
|
|
||||||
void set_canvas_background_color(const Vector3f& newBackColor, bool sendChangeOverNetwork = true);
|
void set_canvas_background_color(const Vector3f& newBackColor, bool sendChangeOverNetwork = true);
|
||||||
|
|
||||||
struct CanvasTheme {
|
struct CanvasTheme {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue