Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor|Server: Initializing a map outline packet
  • Loading branch information
skyjake committed Feb 1, 2017
1 parent 83ed18d commit 127bba6
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 25 deletions.
5 changes: 5 additions & 0 deletions doomsday/apps/client/include/world/map.h
Expand Up @@ -30,6 +30,7 @@
#include <doomsday/world/map.h>
#include <doomsday/world/ithinkermapping.h>
#include <doomsday/uri.h>
#include <de/shell/Protocol>
#include <de/BinaryTree>
#include <de/Id>
#include <de/Observers>
Expand Down Expand Up @@ -953,6 +954,10 @@ class Map : public world::BaseMap
inline de::dint editablePolyobjCount() const { return editablePolyobjs().count(); }
inline de::dint editableSectorCount () const { return editableSectors ().count(); }

//- Multiplayer -------------------------------------------------------------------------

void initMapOutlinePacket(de::shell::MapOutlinePacket &packet);

private:
DENG2_PRIVATE(d)
};
Expand Down
Expand Up @@ -118,4 +118,10 @@ home {
color icon.heretic { rgb <0.4, 0.7, 0.25> }
color icon.hexen { rgb <1.0, 0.25, 0.1> }
color icon.other { rgb <1.0, 1.0, 1.0> }

item.background {
color selected.inverted {
rgb $= gui.colorMix(background.rgb, altaccent.rgb, 0.333)
}
}
}
Expand Up @@ -122,7 +122,11 @@ font small inherits default {

editor {
font plaintext inherits default {}
font hint inherits default {
font hint.default inherits default {
style: italic
weight: light
}
font hint.small inherits small {
style: italic
weight: light
}
Expand Down
12 changes: 12 additions & 0 deletions doomsday/apps/client/src/world/base/map.cpp
Expand Up @@ -4023,6 +4023,18 @@ Map::Sectors const &Map::editableSectors() const
return d->editable.sectors;
}

void Map::initMapOutlinePacket(shell::MapOutlinePacket &packet)
{
forAllLines([&packet] (Line &line)
{
packet.addLine(line.from().origin().toVector2i(),
line.to ().origin().toVector2i(),
(line.front().hasSector() && line.back().hasSector()) ?
shell::MapOutlinePacket::TwoSidedLine : shell::MapOutlinePacket::OneSidedLine);
return LoopContinue;
});
}

Map::Polyobjs const &Map::editablePolyobjs() const
{
if (!d->editingEnabled)
Expand Down
28 changes: 17 additions & 11 deletions doomsday/apps/server/src/remoteuser.cpp
Expand Up @@ -23,11 +23,13 @@
#include "network/net_event.h"
#include "server/sv_def.h"
#include "serverapp.h"
#include "world/map.h"

#include <de/data/json.h>
#include <de/memory.h>
#include <de/Message>
#include <de/ByteRefArray>
#include <de/shell/Protocol>

#include <QCryptographicHash>

Expand Down Expand Up @@ -56,7 +58,7 @@ DENG2_PIMPL(RemoteUser)
{
DENG2_ASSERT(socket != 0);

QObject::connect(socket, SIGNAL(disconnected()), thisPublic, SLOT(socketDisconnected()));
QObject::connect(socket, SIGNAL(disconnected()), thisPublic, SLOT(socketDisconnected()));
QObject::connect(socket, SIGNAL(messagesReady()), thisPublic, SLOT(handleIncomingPackets()));

address = socket->peerAddress();
Expand Down Expand Up @@ -129,17 +131,21 @@ DENG2_PIMPL(RemoteUser)
// Status query?
if (command == "Info?")
{
shell::ServerInfo const info = ServerApp::currentServerInfo(); //Sv_GetInfo(&info);
//Str_Init(&msg);
//Str_Appendf(&msg, "Info\n");
shell::ServerInfo const info = ServerApp::currentServerInfo();
Block const msg = "Info\n" + composeJSON(info);
//Sv_InfoToString(&info, &msg);

LOGDEV_NET_VERBOSE("Info reply:\n%s") << String::fromUtf8(msg); //Str_Text(&msg);

self() << msg; //mRefArray(Str_Text(&msg), Str_Length(&msg));

//Str_Free(&msg);
LOGDEV_NET_VERBOSE("Info reply:\n%s") << String::fromUtf8(msg);
self() << msg;
}
else if (command == "MapOutline?")
{
shell::MapOutlinePacket packet;
if (ServerApp::world().hasMap())
{
ServerApp::world().map().initMapOutlinePacket(packet);
}
Block serialized;
Writer(serialized).withHeader() << packet;
self() << Block("MapOutline\n" + serialized.compressed());
}
else if (length >= 5 && command.startsWith("Shell"))
{
Expand Down
15 changes: 3 additions & 12 deletions doomsday/apps/server/src/shelluser.cpp
Expand Up @@ -134,18 +134,9 @@ void ShellUser::sendMapOutline()
{
if (!App_World().hasMap()) return;

std::unique_ptr<shell::MapOutlinePacket> packet(new shell::MapOutlinePacket);

App_World().map().forAllLines ([&packet] (Line &line)
{
packet->addLine(line.from().origin().toVector2i(),
line.to ().origin().toVector2i(),
(line.front().hasSector() && line.back().hasSector()) ?
shell::MapOutlinePacket::TwoSidedLine : shell::MapOutlinePacket::OneSidedLine);
return LoopContinue;
});

*this << *packet;
shell::MapOutlinePacket packet;
App_World().map().initMapOutlinePacket(packet);
*this << packet;
}

void ShellUser::sendPlayerInfo()
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libshell/include/de/shell/protocol.h
Expand Up @@ -140,7 +140,7 @@ class LIBSHELL_PUBLIC MapOutlinePacket : public Packet
enum LineType
{
OneSidedLine = 0,
TwoSidedLine = 1
TwoSidedLine = 1,
};
struct Line
{
Expand Down

0 comments on commit 127bba6

Please sign in to comment.