Copied some boilerplate code from InWorld to InCombat

This commit is contained in:
Kayne Ruse
2014-06-01 23:42:30 +10:00
parent 1cfb814ee4
commit 9d83abbd38
3 changed files with 113 additions and 7 deletions
+109 -5
View File
@@ -21,6 +21,11 @@
*/ */
#include "in_combat.hpp" #include "in_combat.hpp"
#include "channels.hpp"
#include "utility.hpp"
#include <stdexcept>
//------------------------- //-------------------------
//Public access members //Public access members
//------------------------- //-------------------------
@@ -44,6 +49,26 @@ InCombat::InCombat(
characterMap(*argCharacterMap), characterMap(*argCharacterMap),
enemyMap(*argEnemyMap) enemyMap(*argEnemyMap)
{ {
/* //setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
buttonImage.SetClipH(buttonImage.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
//pass the utility objects
backButton.SetImage(&buttonImage);
backButton.SetFont(&font);
//set the button positions
backButton.SetX(50);
backButton.SetY(50 + buttonImage.GetClipH() * 0);
//set the button texts
backButton.SetText("Back");
//request a sync
RequestSynchronize();
*/
//debug
// //
} }
@@ -60,7 +85,14 @@ void InCombat::FrameStart() {
} }
void InCombat::Update(double delta) { void InCombat::Update(double delta) {
// SerialPacket packet;
//suck in all waiting packets
while(network.Receive(&packet)) {
HandlePacket(packet);
}
//TODO: more
} }
void InCombat::FrameEnd() { void InCombat::FrameEnd() {
@@ -75,7 +107,13 @@ void InCombat::RenderFrame() {
} }
void InCombat::Render(SDL_Surface* const screen) { void InCombat::Render(SDL_Surface* const screen) {
// //TODO: draw the background
//TODO: draw the characters
//TODO: draw the enemies
//TODO: draw the UI
} }
//------------------------- //-------------------------
@@ -84,7 +122,7 @@ void InCombat::Render(SDL_Surface* const screen) {
void InCombat::QuitEvent() { void InCombat::QuitEvent() {
//exit the game AND the server //exit the game AND the server
// RequestDisconnect(); RequestDisconnect();
SetNextScene(SceneList::MAINMENU); SetNextScene(SceneList::MAINMENU);
} }
@@ -116,10 +154,76 @@ void InCombat::KeyUp(SDL_KeyboardEvent const& key) {
//Network handlers //Network handlers
//------------------------- //-------------------------
//TODO: network handlers void InCombat::HandlePacket(SerialPacket packet) {
switch(packet.meta.type) {
case SerialPacket::Type::DISCONNECT:
HandleDisconnect(packet);
break;
//handle errors
default:
throw(std::runtime_error(std::string() + "Unknown SerialPacket::Type encountered in InCombat: " + to_string_custom(int(packet.meta.type))));
break;
}
}
void InCombat::HandleDisconnect(SerialPacket) {
//TODO: stuff
//TODO: I probably need a separate disconnection scene, for setting the client state back to normal
}
//TODO: more network handlers
//------------------------- //-------------------------
//Server control //Server control
//------------------------- //-------------------------
//TODO: server control void InCombat::RequestSynchronize() {
SerialPacket packet;
//request a sync
packet.meta.type = SerialPacket::Type::SYNCHRONIZE;
packet.clientInfo.clientIndex = clientIndex;
packet.clientInfo.accountIndex = accountIndex;
packet.clientInfo.characterIndex = characterIndex;
network.SendTo(Channels::SERVER, &packet);
}
void InCombat::SendPlayerUpdate() {
SerialPacket packet;
//pack the packet
packet.meta.type = SerialPacket::Type::CHARACTER_UPDATE;
packet.characterInfo.clientIndex = clientIndex;
packet.characterInfo.accountIndex = accountIndex;
packet.characterInfo.characterIndex = characterIndex;
// packet.characterInfo.position = localCharacter->position;
// packet.characterInfo.motion = localCharacter->motion;
//TODO: stats
network.SendTo(Channels::SERVER, &packet);
}
void InCombat::RequestDisconnect() {
SerialPacket packet;
//send a disconnect request
packet.meta.type = SerialPacket::Type::DISCONNECT;
packet.clientInfo.clientIndex = clientIndex;
packet.clientInfo.accountIndex = accountIndex;
packet.clientInfo.characterIndex = characterIndex;
network.SendTo(Channels::SERVER, &packet);
}
void InCombat::RequestShutdown() {
SerialPacket packet;
//send a shutdown request
packet.meta.type = SerialPacket::Type::SHUTDOWN;
packet.clientInfo.clientIndex = clientIndex;
packet.clientInfo.accountIndex = accountIndex;
packet.clientInfo.characterIndex = characterIndex;
network.SendTo(Channels::SERVER, &packet);
}
+2 -1
View File
@@ -75,9 +75,10 @@ protected:
//Network handlers //Network handlers
void HandlePacket(SerialPacket); void HandlePacket(SerialPacket);
void HandleDisconnect(SerialPacket); void HandleDisconnect(SerialPacket);
//TODO: more //TODO: more network handlers
//Server control //Server control
void RequestSynchronize();
void SendPlayerUpdate(); void SendPlayerUpdate();
void RequestDisconnect(); void RequestDisconnect();
void RequestShutdown(); void RequestShutdown();
+2 -1
View File
@@ -77,7 +77,7 @@ InWorld::InWorld(
RequestSynchronize(); RequestSynchronize();
//debug //debug
// RequestRegion(0, 0); //
} }
InWorld::~InWorld() { InWorld::~InWorld() {
@@ -273,6 +273,7 @@ void InWorld::HandlePacket(SerialPacket packet) {
} }
void InWorld::HandleDisconnect(SerialPacket packet) { void InWorld::HandleDisconnect(SerialPacket packet) {
//TODO: I probably need a separate disconnection scene, for setting the client state back to normal
network.Unbind(Channels::SERVER); network.Unbind(Channels::SERVER);
clientIndex = -1; clientIndex = -1;
accountIndex = -1; accountIndex = -1;