Calculating correct powers for canvasScale, which also prevents infinite loops when hosting a server
This commit is contained in:
parent
c1045dcee7
commit
b0ecf7896f
4 changed files with 11 additions and 10 deletions
|
|
@ -9,10 +9,7 @@
|
|||
#include <iostream>
|
||||
|
||||
DrawCamera::DrawCamera():
|
||||
c({0, 0}, WorldScalar(10), 0.0)
|
||||
//c({-843000, -72500}, WorldScalar(1000), 0.0)
|
||||
//c({0, 0}, WorldScalar(1000), 0.0)
|
||||
//c({"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}, WorldScalar("1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"), 0.0)
|
||||
c({0, 0}, WorldScalar(1000000), 0.0)
|
||||
{}
|
||||
|
||||
void DrawCamera::set_based_on_properties(World& w, const WorldVec& newPos, const WorldScalar& newZoom, double newRotate) {
|
||||
|
|
|
|||
|
|
@ -57,4 +57,4 @@ enum ClientCommands : MessageCommandType {
|
|||
#define VERSION_STRING "0.2.0"
|
||||
|
||||
// Arbitrary value. Higher scale up values lead to less scale up events (which can cause stuttering), but leads to larger numbers overall, which can cause a tiny bit of lag and increased memory usage
|
||||
#define CANVAS_SCALE_UP_STEP WorldScalar("2")
|
||||
#define CANVAS_SCALE_UP_STEP WorldScalar("100000000000000000000000000000000000000000000000000")
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ MainServer::MainServer(World& initWorld, const std::string& serverLocalID):
|
|||
|
||||
auto& c = clients[client->customID];
|
||||
if(c.canvasScale < data.canvasScale)
|
||||
newComp->scale_up(FixedPoint::pow_int(CANVAS_SCALE_UP_STEP, c.canvasScale - data.canvasScale));
|
||||
newComp->scale_up(FixedPoint::pow_int(CANVAS_SCALE_UP_STEP, data.canvasScale - c.canvasScale));
|
||||
|
||||
newComp->server_send_place(*this, placement);
|
||||
});
|
||||
|
|
@ -132,7 +132,7 @@ MainServer::MainServer(World& initWorld, const std::string& serverLocalID):
|
|||
auto& c = clients[client->customID];
|
||||
if(c.canvasScale < data.canvasScale) {
|
||||
for(auto& o : objOrderedVector)
|
||||
o->obj->scale_up(FixedPoint::pow_int(CANVAS_SCALE_UP_STEP, c.canvasScale - data.canvasScale));
|
||||
o->obj->scale_up(FixedPoint::pow_int(CANVAS_SCALE_UP_STEP, data.canvasScale - c.canvasScale));
|
||||
}
|
||||
|
||||
DrawComponent::server_send_place_many(*this, objOrderedVector);
|
||||
|
|
@ -167,7 +167,7 @@ MainServer::MainServer(World& initWorld, const std::string& serverLocalID):
|
|||
auto& c = clients[client->customID];
|
||||
if(c.canvasScale < data.canvasScale) {
|
||||
for(auto& [id, coord] : transformsToSend)
|
||||
coord.scale_about(WorldVec{0, 0}, FixedPoint::pow_int(CANVAS_SCALE_UP_STEP, c.canvasScale - data.canvasScale), true);
|
||||
coord.scale_about(WorldVec{0, 0}, FixedPoint::pow_int(CANVAS_SCALE_UP_STEP, data.canvasScale - c.canvasScale), true);
|
||||
}
|
||||
DrawComponent::server_send_transform_many(*this, transformsToSend);
|
||||
});
|
||||
|
|
@ -222,7 +222,7 @@ MainServer::MainServer(World& initWorld, const std::string& serverLocalID):
|
|||
|
||||
auto& c = clients[client->customID];
|
||||
if(c.canvasScale < data.canvasScale)
|
||||
b.scale_up(FixedPoint::pow_int(CANVAS_SCALE_UP_STEP, 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);
|
||||
});
|
||||
|
|
@ -240,7 +240,7 @@ MainServer::MainServer(World& initWorld, const std::string& serverLocalID):
|
|||
|
||||
auto& c = clients[client->customID];
|
||||
if(c.canvasScale < data.canvasScale)
|
||||
g.scale_up(FixedPoint::pow_int(CANVAS_SCALE_UP_STEP, c.canvasScale - data.canvasScale));
|
||||
g.scale_up(FixedPoint::pow_int(CANVAS_SCALE_UP_STEP, data.canvasScale - c.canvasScale));
|
||||
|
||||
netServer->send_items_to_all_clients(RELIABLE_COMMAND_CHANNEL, CLIENT_SET_GRID, gID, g);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -81,6 +81,10 @@ void World::init_client_callbacks() {
|
|||
message(canvasScale);
|
||||
drawProg.initialize_draw_data(message);
|
||||
message(bMan, gridMan);
|
||||
if(!clients.empty()) {
|
||||
auto& [randomClientServerID, randomClient] = *clients.begin();
|
||||
drawData.cam.smooth_move_to(*main.world, randomClient.camCoords, randomClient.windowSize, true);
|
||||
}
|
||||
}
|
||||
nextClientID = get_max_id(ownID);
|
||||
clientStillConnecting = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue