Same make_obj call allocates the correct type

This commit is contained in:
Yousef Khadadeh 2025-12-08 20:51:11 +03:00
parent 5d24b34200
commit d9a90dda16
10 changed files with 53 additions and 17 deletions

View file

@ -18,8 +18,8 @@ class ConnectionManager {
bool client_exists();
std::unordered_map<ServerClientID, NetLibrary::DownloadProgress> server_get_resource_retrieval_progress();
NetLibrary::DownloadProgress client_get_resource_retrieval_progress();
std::unique_ptr<MainServer> localServer;
private:
std::shared_ptr<NetClient> client;
std::unique_ptr<MainServer> localServer;
std::chrono::steady_clock::time_point lastKeepAliveTime;
};

View file

@ -1,5 +1,6 @@
#include "MainProgram.hpp"
#include "DrawingProgram/DrawingProgramToolBase.hpp"
#include "Helpers/NetworkingObjects/NetObjManagerTypeList.hpp"
#include "VersionConstants.hpp"
#include "cereal/archives/portable_binary.hpp"
#include "cereal/details/helpers.hpp"
@ -37,19 +38,16 @@
#endif
#include <Helpers/Logger.hpp>
#include <Helpers/Networking/NetLibrary.hpp>
#include <Helpers/NetworkingObjects/NetObjOrderedList.hpp>
#include <Helpers/NetworkingObjects/NetObjManager.hpp>
#include <Helpers/NetworkingObjects/NetObjGenericSerializedClass.hpp>
MainProgram::MainProgram():
fonts(std::make_shared<FontData>()),
toolbar(*this)
{
auto typeList = std::make_shared<NetworkingObjects::NetObjManagerTypeList>();
NetworkingObjects::register_generic_serialized_class<std::string>(*typeList);
NetworkingObjects::register_ordered_list_class<std::string>(*typeList);
auto nObjMan = std::make_shared<NetworkingObjects::NetObjManager>(typeList, false);
netObjectTypeList = std::make_shared<NetworkingObjects::NetObjManagerTypeList>();
NetworkingObjects::register_generic_serialized_class<std::string>(*netObjectTypeList);
NetworkingObjects::register_ordered_list_class<std::string>(*netObjectTypeList);
displayName = Random::get().alphanumeric_str(10);

View file

@ -9,6 +9,7 @@
#include "SharedTypes.hpp"
#include <Eigen/Dense>
#include <include/core/SkSurfaceProps.h>
#include <Helpers/NetworkingObjects/NetObjManagerTypeList.hpp>
#include "Toolbar.hpp"
#include "World.hpp"
@ -115,6 +116,8 @@ class MainProgram {
std::string displayName;
std::shared_ptr<NetworkingObjects::NetObjManagerTypeList> netObjectTypeList;
~MainProgram();
private:
void new_tab_open();

View file

@ -30,7 +30,8 @@ World::World(MainProgram& initMain, OpenWorldInfo& worldInfo):
rMan(*this),
drawProg(*this),
bMan(*this),
gridMan(*this)
gridMan(*this),
netObjMan(initMain.netObjectTypeList, worldInfo.conType != CONNECTIONTYPE_CLIENT)
{
set_canvas_background_color(main.defaultCanvasBackgroundColor);
displayName = main.displayName;
@ -68,6 +69,14 @@ World::World(MainProgram& initMain, OpenWorldInfo& worldInfo):
gridMan.init_client_callbacks();
init_client_callbacks();
con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_INITIAL_DATA, displayName, false);
using namespace NetworkingObjects;
stringListTest = netObjMan.make_obj<NetObjOrderedList<std::string>>();
stringListTest->emplace_back_direct(stringListTest, "Hello");
stringListTest->emplace_back_direct(stringListTest, "World");
stringListTest->emplace_back_direct(stringListTest, "Test");
for(const 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;
}
void World::init_client_callbacks() {

View file

@ -1,4 +1,5 @@
#pragma once
#include "Helpers/NetworkingObjects/NetObjOrderedList.hpp"
#include "UndoManager.hpp"
#include "BookmarkManager.hpp"
#include "ResourceManager.hpp"
@ -7,6 +8,7 @@
#include "Toolbar.hpp"
#include "SharedTypes.hpp"
#include "GridManager.hpp"
#include <Helpers/NetworkingObjects/NetObjManager.hpp>
#include <filesystem>
class MainProgram;
@ -45,6 +47,7 @@ class World {
BookmarkManager bMan;
ConnectionManager con;
GridManager gridMan;
NetworkingObjects::NetObjManager netObjMan;
std::deque<Toolbar::ChatMessage> chatMessages;
@ -88,6 +91,8 @@ class World {
std::string name;
std::unordered_map<ServerPortionID, ClientData> clients;
NetworkingObjects::NetObjPtr<NetworkingObjects::NetObjOrderedList<std::string>> stringListTest;
void set_canvas_background_color(const Vector3f& newBackColor, bool sendChangeOverNetwork = true);
struct CanvasTheme {
@ -100,6 +105,7 @@ class World {
uint64_t canvasScale = 0;
private:
ClientPortionID get_max_id(ServerPortionID serverID);
void init_client_callbacks();