Began bringing the client into line with the server's changes
Several parts of the client already built correctly. Updated LobbyMenu, it not builds.
This commit is contained in:
@@ -124,7 +124,7 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
|
|||||||
activeScene = new OptionsMenu(&config);
|
activeScene = new OptionsMenu(&config);
|
||||||
break;
|
break;
|
||||||
case SceneList::LOBBYMENU:
|
case SceneList::LOBBYMENU:
|
||||||
activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex, &characterIndex);
|
activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex);
|
||||||
break;
|
break;
|
||||||
case SceneList::INWORLD:
|
case SceneList::INWORLD:
|
||||||
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap);
|
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap);
|
||||||
|
|||||||
+1
-3
@@ -23,8 +23,6 @@
|
|||||||
#define INWORLD_HPP_
|
#define INWORLD_HPP_
|
||||||
|
|
||||||
//maps
|
//maps
|
||||||
#include "map_allocator.hpp"
|
|
||||||
#include "map_file_format.hpp"
|
|
||||||
#include "region_pager.hpp"
|
#include "region_pager.hpp"
|
||||||
|
|
||||||
//networking
|
//networking
|
||||||
@@ -112,7 +110,7 @@ protected:
|
|||||||
TileSheet tileSheet;
|
TileSheet tileSheet;
|
||||||
|
|
||||||
//map
|
//map
|
||||||
RegionPager<BlankAllocator, DummyFormat> regionPager;
|
RegionPager regionPager;
|
||||||
|
|
||||||
//UI
|
//UI
|
||||||
Button disconnectButton;
|
Button disconnectButton;
|
||||||
|
|||||||
+41
-37
@@ -34,14 +34,12 @@ LobbyMenu::LobbyMenu(
|
|||||||
ConfigUtility* const argConfig,
|
ConfigUtility* const argConfig,
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex
|
||||||
int* const argCharacterIndex
|
|
||||||
):
|
):
|
||||||
config(*argConfig),
|
config(*argConfig),
|
||||||
network(*argNetwork),
|
network(*argNetwork),
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
accountIndex(*argAccountIndex),
|
accountIndex(*argAccountIndex)
|
||||||
characterIndex(*argCharacterIndex)
|
|
||||||
{
|
{
|
||||||
//setup the utility objects
|
//setup the utility objects
|
||||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||||
@@ -87,9 +85,9 @@ void LobbyMenu::FrameStart() {
|
|||||||
|
|
||||||
void LobbyMenu::Update(double delta) {
|
void LobbyMenu::Update(double delta) {
|
||||||
//suck in and process all waiting packets
|
//suck in and process all waiting packets
|
||||||
SerialPacket packet;
|
char packetBuffer[MAX_PACKET_SIZE];
|
||||||
while(network.Receive(&packet)) {
|
while(network.Receive(reinterpret_cast<SerialPacket*>(packetBuffer))) {
|
||||||
HandlePacket(packet);
|
HandlePacket(reinterpret_cast<SerialPacket*>(packetBuffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +147,7 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
|||||||
if (search.MouseButtonUp(button) == Button::State::HOVER) {
|
if (search.MouseButtonUp(button) == Button::State::HOVER) {
|
||||||
//broadcast to the network, or a specific server
|
//broadcast to the network, or a specific server
|
||||||
SerialPacket packet;
|
SerialPacket packet;
|
||||||
packet.meta.type = SerialPacket::Type::BROADCAST_REQUEST;
|
packet.type = SerialPacketType::BROADCAST_REQUEST;
|
||||||
network.SendTo(config["server.host"].c_str(), config.Int("server.port"), &packet);
|
network.SendTo(config["server.host"].c_str(), config.Int("server.port"), &packet);
|
||||||
|
|
||||||
//reset the server list
|
//reset the server list
|
||||||
@@ -159,11 +157,9 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
|||||||
|
|
||||||
else if (join.MouseButtonUp(button) == Button::State::HOVER && selection != nullptr && selection->compatible) {
|
else if (join.MouseButtonUp(button) == Button::State::HOVER && selection != nullptr && selection->compatible) {
|
||||||
//pack the packet
|
//pack the packet
|
||||||
SerialPacket packet;
|
ClientPacket packet;
|
||||||
packet.meta.type = SerialPacket::Type::JOIN_REQUEST;
|
packet.type = SerialPacketType::JOIN_REQUEST;
|
||||||
strncpy(packet.clientInfo.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
|
strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
|
||||||
strncpy(packet.clientInfo.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
|
|
||||||
strncpy(packet.clientInfo.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
|
|
||||||
|
|
||||||
//join the selected server
|
//join the selected server
|
||||||
network.SendTo(&selection->address, &packet);
|
network.SendTo(&selection->address, &packet);
|
||||||
@@ -176,6 +172,7 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
|||||||
|
|
||||||
else if (
|
else if (
|
||||||
//has the user selected a server on the list?
|
//has the user selected a server on the list?
|
||||||
|
//TODO: replace with regular collision checker
|
||||||
button.x > listBox.x &&
|
button.x > listBox.x &&
|
||||||
button.x < listBox.x + listBox.w &&
|
button.x < listBox.x + listBox.w &&
|
||||||
button.y > listBox.y &&
|
button.y > listBox.y &&
|
||||||
@@ -204,34 +201,41 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) {
|
|||||||
//Network handlers
|
//Network handlers
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void LobbyMenu::HandlePacket(SerialPacket packet) {
|
void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
|
||||||
switch(packet.meta.type) {
|
switch(argPacket->type) {
|
||||||
case SerialPacket::Type::BROADCAST_RESPONSE: {
|
case SerialPacketType::BROADCAST_RESPONSE:
|
||||||
//extract the data
|
HandleBroadcastResponse(dynamic_cast<ServerPacket*>(argPacket));
|
||||||
ServerInformation server;
|
|
||||||
server.address = packet.meta.srcAddress;
|
|
||||||
server.networkVersion = packet.serverInfo.networkVersion;
|
|
||||||
server.name = packet.serverInfo.name;
|
|
||||||
server.playerCount = packet.serverInfo.playerCount;
|
|
||||||
|
|
||||||
//NOTE: Check compatibility here
|
|
||||||
server.compatible = server.networkVersion == NETWORK_VERSION;
|
|
||||||
|
|
||||||
//push
|
|
||||||
serverInfo.push_back(server);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case SerialPacket::Type::JOIN_RESPONSE:
|
case SerialPacketType::JOIN_RESPONSE:
|
||||||
clientIndex = packet.clientInfo.clientIndex;
|
HandleJoinResponse(dynamic_cast<ClientPacket*>(argPacket));
|
||||||
accountIndex = packet.clientInfo.accountIndex;
|
|
||||||
characterIndex = packet.clientInfo.characterIndex;
|
|
||||||
network.Bind(&packet.meta.srcAddress, Channels::SERVER);
|
|
||||||
SetNextScene(SceneList::INWORLD);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//handle errors
|
//handle errors
|
||||||
default:
|
default:
|
||||||
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(int(packet.meta.type))));
|
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(static_cast<int>(argPacket->type)) ));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
|
||||||
|
//extract the data
|
||||||
|
ServerInformation server;
|
||||||
|
server.address = argPacket->srcAddress;
|
||||||
|
server.name = argPacket->name;
|
||||||
|
server.playerCount = argPacket->playerCount;
|
||||||
|
server.version = argPacket->version;
|
||||||
|
|
||||||
|
//NOTE: Check compatibility here
|
||||||
|
server.compatible = server.version == NETWORK_VERSION;
|
||||||
|
|
||||||
|
//push
|
||||||
|
serverInfo.push_back(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
|
||||||
|
clientIndex = argPacket->clientIndex;
|
||||||
|
accountIndex = argPacket->accountIndex;
|
||||||
|
network.Bind(&argPacket->srcAddress, Channels::SERVER);
|
||||||
|
SetNextScene(SceneList::INWORLD);
|
||||||
|
|
||||||
|
//TODO: send this player's character info
|
||||||
|
}
|
||||||
@@ -22,13 +22,13 @@
|
|||||||
#ifndef LOBBYMENU_HPP_
|
#ifndef LOBBYMENU_HPP_
|
||||||
#define LOBBYMENU_HPP_
|
#define LOBBYMENU_HPP_
|
||||||
|
|
||||||
//graphics & utilities
|
//graphics & ui
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "raster_font.hpp"
|
#include "raster_font.hpp"
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
#include "config_utility.hpp"
|
|
||||||
|
|
||||||
//network
|
//utilities
|
||||||
|
#include "config_utility.hpp"
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
//client
|
//client
|
||||||
@@ -44,8 +44,7 @@ public:
|
|||||||
ConfigUtility* const argConfig,
|
ConfigUtility* const argConfig,
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex
|
||||||
int* const argCharacterIndex
|
|
||||||
);
|
);
|
||||||
~LobbyMenu();
|
~LobbyMenu();
|
||||||
|
|
||||||
@@ -64,14 +63,15 @@ protected:
|
|||||||
void KeyUp(SDL_KeyboardEvent const&);
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
//Network handlers
|
//Network handlers
|
||||||
void HandlePacket(SerialPacket);
|
void HandlePacket(SerialPacket* const);
|
||||||
|
void HandleBroadcastResponse(ServerPacket* const);
|
||||||
|
void HandleJoinResponse(ClientPacket* const);
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
ConfigUtility& config;
|
ConfigUtility& config;
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network;
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
int& characterIndex;
|
|
||||||
|
|
||||||
//members
|
//members
|
||||||
Image image;
|
Image image;
|
||||||
@@ -83,9 +83,9 @@ protected:
|
|||||||
//server list
|
//server list
|
||||||
struct ServerInformation {
|
struct ServerInformation {
|
||||||
IPaddress address;
|
IPaddress address;
|
||||||
int networkVersion;
|
|
||||||
std::string name;
|
std::string name;
|
||||||
int playerCount;
|
int playerCount;
|
||||||
|
int version;
|
||||||
bool compatible;
|
bool compatible;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,11 @@ Region* RegionPager::FindRegion(int x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Region* RegionPager::LoadRegion(int x, int y) {
|
Region* RegionPager::LoadRegion(int x, int y) {
|
||||||
|
//only work if using lua
|
||||||
|
if (!luaState) {
|
||||||
|
throw(std::runtime_error("RegionPager::luaState is null"));
|
||||||
|
}
|
||||||
|
|
||||||
//load the region if possible
|
//load the region if possible
|
||||||
|
|
||||||
//snap the coords
|
//snap the coords
|
||||||
@@ -97,6 +102,11 @@ Region* RegionPager::LoadRegion(int x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Region* RegionPager::SaveRegion(int x, int y) {
|
Region* RegionPager::SaveRegion(int x, int y) {
|
||||||
|
//only work if using lua
|
||||||
|
if (!luaState) {
|
||||||
|
throw(std::runtime_error("RegionPager::luaState is null"));
|
||||||
|
}
|
||||||
|
|
||||||
//snap the coords
|
//snap the coords
|
||||||
x = snapToBase(REGION_WIDTH, x);
|
x = snapToBase(REGION_WIDTH, x);
|
||||||
y = snapToBase(REGION_HEIGHT, y);
|
y = snapToBase(REGION_HEIGHT, y);
|
||||||
@@ -118,6 +128,11 @@ Region* RegionPager::SaveRegion(int x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Region* RegionPager::CreateRegion(int x, int y) {
|
Region* RegionPager::CreateRegion(int x, int y) {
|
||||||
|
//only work if using lua
|
||||||
|
if (!luaState) {
|
||||||
|
throw(std::runtime_error("RegionPager::luaState is null"));
|
||||||
|
}
|
||||||
|
|
||||||
//snap the coords
|
//snap the coords
|
||||||
x = snapToBase(REGION_WIDTH, x);
|
x = snapToBase(REGION_WIDTH, x);
|
||||||
y = snapToBase(REGION_HEIGHT, y);
|
y = snapToBase(REGION_HEIGHT, y);
|
||||||
@@ -143,6 +158,11 @@ Region* RegionPager::CreateRegion(int x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RegionPager::UnloadRegion(int x, int y) {
|
void RegionPager::UnloadRegion(int x, int y) {
|
||||||
|
//only work if using lua
|
||||||
|
if (!luaState) {
|
||||||
|
throw(std::runtime_error("RegionPager::luaState is null"));
|
||||||
|
}
|
||||||
|
|
||||||
//snap the coords
|
//snap the coords
|
||||||
x = snapToBase(REGION_WIDTH, x);
|
x = snapToBase(REGION_WIDTH, x);
|
||||||
y = snapToBase(REGION_HEIGHT, y);
|
y = snapToBase(REGION_HEIGHT, y);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
//TODO: split this into two: "RegionPagerBase" and "RegionPagerLua"
|
||||||
class RegionPager {
|
class RegionPager {
|
||||||
public:
|
public:
|
||||||
RegionPager() = default;
|
RegionPager() = default;
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ struct SerialPacketBase {
|
|||||||
SerialPacketType type;
|
SerialPacketType type;
|
||||||
IPaddress srcAddress;
|
IPaddress srcAddress;
|
||||||
|
|
||||||
typedef SerialPacketType Type;
|
|
||||||
|
|
||||||
virtual ~SerialPacketBase() {};
|
virtual ~SerialPacketBase() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user