diff --git a/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp b/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp index 97acf526..36cc4c83 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp +++ b/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp @@ -111,7 +111,6 @@ void MessageHeader::PackFloat(float i, OysterByte& bytes) void MessageHeader::PackFloat(float i[], unsigned int elementCount, OysterByte& bytes) { - bytes.AddSize(4); //Pack number of elements PackUnsignedInt(elementCount, bytes); diff --git a/Code/Network/NetworkDependencies/Messages/MessageHeader.h b/Code/Network/NetworkDependencies/Messages/MessageHeader.h index 095ebc1e..61dfedab 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageHeader.h +++ b/Code/Network/NetworkDependencies/Messages/MessageHeader.h @@ -47,8 +47,9 @@ namespace Oyster void PackStr(char str[], OysterByte& bytes); void PackStr(std::string str, OysterByte& bytes); + //Maybe //TODO: Add Pack functions for Vec2, 3, 4 and maybe Matrix. Etc. - + //Unpack variables from message bool UnpackBool(OysterByte& bytes); @@ -71,6 +72,7 @@ namespace Oyster std::string UnpackStr(OysterByte& bytes); + //Maybe //TODO: Add Unpack functions for Vec2, 3, 4 and maybe Matrix. Etc. diff --git a/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.cpp b/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.cpp new file mode 100644 index 00000000..673b586f --- /dev/null +++ b/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.cpp @@ -0,0 +1,30 @@ +#include "MessagePlayerPos.h" + +using namespace Oyster::Network; +using namespace Oyster::Network::Messages; +using namespace Oyster::Network::Protocols; + +MessagePlayerPos::MessagePlayerPos() +{ +} + +MessagePlayerPos::~MessagePlayerPos() +{ +} + +void MessagePlayerPos::Pack(Protocols::ProtocolHeader& header, OysterByte& bytes) +{ + MessageHeader::Pack(header, bytes); + + PackInt(static_cast(&header)->ID, bytes); + PackFloat(static_cast(&header)->matrix, static_cast(&header)->nrOfFloats, bytes); + SetSize(bytes); +} + +void MessagePlayerPos::Unpack(OysterByte& bytes, Protocols::ProtocolHeader& header) +{ + MessageHeader::Unpack(bytes, header); + + static_cast(&header)->ID = UnpackInt(bytes); + static_cast(&header)->matrix = UnpackFloat(static_cast(&header)->nrOfFloats, bytes); +} \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.h b/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.h new file mode 100644 index 00000000..247e200e --- /dev/null +++ b/Code/Network/NetworkDependencies/Messages/MessagePlayerPos.h @@ -0,0 +1,34 @@ +#ifndef NETWORK_DEPENDENCIES_MESSAGE_PLAYER_POS_H +#define NETWORK_DEPENDENCIES_MESSAGE_PLAYER_POS_H + +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +#include "MessageHeader.h" + +namespace Oyster +{ + namespace Network + { + namespace Messages + { + class MessagePlayerPos : public MessageHeader + { + public: + MessagePlayerPos(); + virtual ~MessagePlayerPos(); + + virtual void Pack(Protocols::ProtocolHeader& header, OysterByte& bytes); + virtual void Unpack(OysterByte& bytes, Protocols::ProtocolHeader& header); + + private: + + + + }; + } + } +} + +#endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Messages/MessagesInclude.h b/Code/Network/NetworkDependencies/Messages/MessagesInclude.h index 8f4d41e3..8bdb5c8a 100644 --- a/Code/Network/NetworkDependencies/Messages/MessagesInclude.h +++ b/Code/Network/NetworkDependencies/Messages/MessagesInclude.h @@ -7,5 +7,6 @@ #include "MessageHeader.h" #include "MessageTest.h" +#include "MessagePlayerPos.h" #endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj index c0a1a8a9..d320872f 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj @@ -155,6 +155,7 @@ + @@ -170,6 +171,7 @@ + diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters index 3474a3b6..d3c0b9e5 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters @@ -10,6 +10,8 @@ + @@ -28,7 +30,16 @@ +<<<<<<< HEAD +======= +<<<<<<< HEAD + +======= + + +>>>>>>> Client interface and class for both server and client. now using postbox system +>>>>>>> 10c1dc57f3c9235ca6c6d4e69fed43465daa7752 \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Packing.cpp b/Code/Network/NetworkDependencies/Packing.cpp index 7adc395c..192700b6 100644 --- a/Code/Network/NetworkDependencies/Packing.cpp +++ b/Code/Network/NetworkDependencies/Packing.cpp @@ -87,7 +87,7 @@ namespace Oyster //floating point (32, 64-bit) void Pack(unsigned char buffer[], float i) { - int tempFloat = Pack754(i, 32, 8); + int tempFloat = (int)Pack754(i, 32, 8); Pack(buffer, tempFloat); } @@ -153,7 +153,7 @@ namespace Oyster fnorm = fnorm - 1.0; // calculate the binary form (non-float) of the significand data - significand = fnorm * ((1LL << significandbits) + 0.5f); + significand = (long long)(fnorm * ((1LL << significandbits) + 0.5f)); // get the biased exponent exp = shift + ((1 << (expbits - 1)) - 1); // shift + bias @@ -169,7 +169,7 @@ namespace Oyster //bool (1-bit) bool Unpackb(unsigned char buffer[]) { - return (bool)buffer; + return buffer; } //char (8-bit) @@ -305,7 +305,7 @@ namespace Oyster return 0.0; // pull the significand - result = (i&((1LL << significandbits) - 1)); // mask + result = (long double)(i&((1LL << significandbits) - 1)); // mask result /= (1LL << significandbits); // convert back to float result += 1.0f; // add the one back on diff --git a/Code/Network/NetworkDependencies/Protocols.h b/Code/Network/NetworkDependencies/Protocols.h index 8defcfb3..adf7154e 100644 --- a/Code/Network/NetworkDependencies/Protocols.h +++ b/Code/Network/NetworkDependencies/Protocols.h @@ -22,7 +22,7 @@ namespace Oyster PackageType_header, PackageType_test, PackageType_input, - PackageType_update_position + PackageType_player_pos, }; struct ProtocolHeader @@ -45,6 +45,16 @@ namespace Oyster virtual ~ProtocolTest() { delete[] f; } }; + struct ProtocolPlayerPos : public ProtocolHeader + { + int ID; + unsigned int nrOfFloats; + float *matrix; + + ProtocolPlayerPos() { this->packageType = PackageType_player_pos; } + virtual ~ProtocolPlayerPos() { delete[] matrix; } + }; + //Holding every protocol in an union. //Used because we now don't have to type case our protocol when we recieve them. @@ -56,6 +66,7 @@ namespace Oyster { ProtocolHeader* pHeader; ProtocolTest *pTest; + ProtocolPlayerPos *pPlayerPos; }Protocol; @@ -75,6 +86,12 @@ namespace Oyster delete Protocol.pTest; } break; + case PackageType_player_pos: + if(Protocol.pPlayerPos) + { + delete Protocol.pPlayerPos; + } + break; } } }; diff --git a/Code/Network/NetworkDependencies/Translator.cpp b/Code/Network/NetworkDependencies/Translator.cpp index 4bb739ca..746b00f2 100644 --- a/Code/Network/NetworkDependencies/Translator.cpp +++ b/Code/Network/NetworkDependencies/Translator.cpp @@ -17,6 +17,10 @@ void Translator::Pack( ProtocolHeader &header, OysterByte& bytes ) case PackageType_test: message = new MessageTest(); break; + + case PackageType_player_pos: + message = new MessagePlayerPos(); + break; } if(message != NULL) @@ -52,6 +56,12 @@ void Translator::Unpack(ProtocolSet* set, OysterByte& bytes ) set->Protocol.pTest = new ProtocolTest; message->Unpack(bytes, *set->Protocol.pTest); break; + + case PackageType_player_pos: + message = new MessagePlayerPos(); + set->Protocol.pPlayerPos = new ProtocolPlayerPos; + message->Unpack(bytes, *set->Protocol.pPlayerPos); + break; } if(message) diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index 60c9453f..bbf2ec6f 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -54,13 +54,13 @@ void chat(ThreadedClient &client) string msgSend = ""; ProtocolSet* set = new ProtocolSet; - ProtocolTest test; - test.numOfFloats = 5; - test.f = new float[test.numOfFloats]; - float temp = 12345.5654f; + ProtocolPlayerPos test; + test.ID = 5; + test.matrix = new float[16]; + float temp = 10; for(int i = 0; i < 5; i++) { - test.f[i] = temp; + test.matrix[i] = temp; temp++; } @@ -78,12 +78,20 @@ void chat(ThreadedClient &client) break; case PackageType_test: cout <<"Client 2: " << set->Protocol.pTest->textMessage <Protocol.pTest->numOfFloats; i++) + for(int i = 0; i < (int)set->Protocol.pTest->numOfFloats; i++) { cout << set->Protocol.pTest->f[i] << ' ' ; } cout << endl; break; + case PackageType_player_pos: + cout << "Server: ID " << set->Protocol.pPlayerPos->ID << endl; + for(int i = 0; i < set->Protocol.pPlayerPos->nrOfFloats; i++) + { + cout << set->Protocol.pPlayerPos->matrix[i] << ' '; + } + cout << endl; + break; } set->Release(); diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index cc80b165..f1014f59 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -40,17 +40,15 @@ int main() //Start listening //Accept a client - ProtocolTest test; + ProtocolPlayerPos test; test.clientID = 0; - test.size = 2; - test.textMessage = "hej"; - test.numOfFloats = 0; - test.f = new float[test.numOfFloats]; - float temp = 395.456f; - for(int i = 0; i < (int)test.numOfFloats; i++) + test.ID = 5; + test.nrOfFloats = 16; + test.matrix = new float[test.nrOfFloats]; + + for(int i = 0; i < test.nrOfFloats; i++) { - test.f[i] = temp; - temp--; + test.matrix[i] = i; } t.Pack(test, recvBuffer);