Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f791bc2
Initial commit of assignment 3, replicated files from assignment 2 af…
adel-talhouk Apr 1, 2022
0572ed1
Restored assets, restored display size to 1600x900 pixels.
adel-talhouk Apr 1, 2022
0c43d32
Networker::receiveGameObjectState now returns a PacketType, and main …
adel-talhouk Apr 1, 2022
f75a08a
Updated TO-DOs with questions and ideas.
adel-talhouk Apr 5, 2022
b2c6402
Started writing logic for simulating Latency and Jitter. Generating a…
AlexJaeger1 Apr 5, 2022
441b575
Finished first verions of the queue sorting function, might need to s…
AlexJaeger101 Apr 6, 2022
46954e5
Updated text file with notes and tips, started implementing InFlightP…
adel-talhouk Apr 8, 2022
24342ea
Worked on Jitter/Latency simulation. Created a struct that holds byte…
AlexJaeger1 Apr 8, 2022
a773133
Changed code to add outgoing packets to queue in random order and sen…
adel-talhouk Apr 11, 2022
27f4e5c
Updated TO-DOs with remaining work.
adel-talhouk Apr 11, 2022
79df4b4
Commented out TCP stuff, implemented connectUDP, gonna work on send a…
adel-talhouk Apr 12, 2022
5c301df
Changed code to call appropriate SendTo and ReceiveFrom functions for…
adel-talhouk Apr 12, 2022
468da37
Added includes, but it is broken (Vector3 and Quaternion are undefine…
adel-talhouk Apr 12, 2022
200a961
Added includes of .h files in .cpp files, classes that derive from Ga…
adel-talhouk Apr 12, 2022
0b2d207
Fixed errors in DeliveryNotificationManager.cpp.
adel-talhouk Apr 12, 2022
5d288e0
Changed send and receive in main to use the UDP functions. Saving bef…
adel-talhouk Apr 12, 2022
1b7ccd8
Updated code for connection. Will update instructions txt file.
adel-talhouk Apr 12, 2022
880e4b6
Only trying to resend packets on failure in Wall and Rock, success ne…
adel-talhouk Apr 13, 2022
c66945f
Added functionality to resend packets (but packet type is hard-coded,…
adel-talhouk Apr 13, 2022
b172ca9
Added reference to sequence number and finding the packet to resend, …
adel-talhouk Apr 13, 2022
6407818
Decrementing network ID when receiving a delete packet.
adel-talhouk Apr 14, 2022
6f79e6d
Work session WITH Alex over discord. Added code to get packet header …
adel-talhouk Apr 14, 2022
fb57337
The problem was most likely a circular include, so we commented out t…
adel-talhouk Apr 14, 2022
33feebd
Fixed a few things to get rid of a few errors, but we still have hund…
adel-talhouk Apr 14, 2022
04c7a86
NO ERRORS.
adel-talhouk Apr 14, 2022
0fb87c4
Builds.
adel-talhouk Apr 14, 2022
7f673d7
Adding unsaved change, trying to get UDP sockets to connect properly.
adel-talhouk Apr 14, 2022
de1b0b5
Connects with port number 8, but it starts the game before it actuall…
adel-talhouk Apr 15, 2022
9ae256f
Changed priorityu queue to hold pointers, deleting data after sending…
adel-talhouk Apr 15, 2022
031a980
Added comment to indicate new sorting in myComp struct.
adel-talhouk Apr 15, 2022
79e5529
Instances can connect to each other but we need to make sure both hav…
adel-talhouk Apr 15, 2022
994aacd
Added PacketType::PACKET_HELLO and not starting game until one is rec…
adel-talhouk Apr 15, 2022
390fcc1
Wrote code to send and receive connection setup packets (if ID sent i…
adel-talhouk Apr 15, 2022
c2b2748
It fails on the first line of OutputMemoryBitStream::WriteBits(), as …
adel-talhouk Apr 15, 2022
e5800c5
Trying to make it send but not quite working. Data is no longer erron…
adel-talhouk Apr 15, 2022
b7211ad
Only binding Server socket, need to change code in main to call right…
adel-talhouk Apr 15, 2022
f2ef410
Server should now be listening from client address (0.0.0.0:0).
adel-talhouk Apr 15, 2022
0c4e564
Server can send to any IP.
adel-talhouk Apr 15, 2022
3814f11
Server listening on its own socketAddress.
adel-talhouk Apr 15, 2022
eb5bc6e
Server can receive from anywhere.
adel-talhouk Apr 15, 2022
dad7ffa
Trying to get them to connect but the address is invalid. May call it…
adel-talhouk Apr 15, 2022
a5e845a
They connect! Now errors because it checks for an ID that is too high…
adel-talhouk Apr 15, 2022
016a40b
Cleaned up code. It's sending a PACKET_HELLO but receiving it itself.
adel-talhouk Apr 15, 2022
4548ac8
Fixing sockets binding and connecting, handing it off to Alex.
adel-talhouk Apr 15, 2022
31be9ed
Fixed UDP init functions so that the server and client connect to eac…
AlexJaeger1 Apr 15, 2022
ec0e57c
Players connect to each other, but do not create the instances of the…
adel-talhouk Apr 17, 2022
875428f
Client not receiving server's PACKET_CREATE, which in turn will not l…
adel-talhouk Apr 17, 2022
4153147
IT WORKS BABYYYYYYYY. I made sure it sends immediately if the ID is <…
adel-talhouk Apr 18, 2022
24baec2
Resized window. Sometime you can control both players from one instan…
adel-talhouk Apr 18, 2022
a0de763
txt
adel-talhouk Apr 18, 2022
4e42329
Making it SetTransmissionData for InFlightPackets. Not working yet, I…
adel-talhouk Apr 19, 2022
daede02
Created copy constructor for gameObject, I don't think this will be u…
adel-talhouk Apr 19, 2022
db288e5
The player controllers sent are becoming invalid so they cannot updat…
adel-talhouk Apr 19, 2022
6ec8835
Ran some tests to confirm player data is being sent and recieved prop…
AlexJaeger1 Apr 19, 2022
d2308f5
Removed shared pointers, data does not get fucked up anymore. Need to…
adel-talhouk Apr 22, 2022
667b7f2
Started reimplementing shared_ptrs, haven't tested yet since I had to…
AlexJaeger1 Apr 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added RoboCat/Assets/ARIBL0.ttf
Binary file not shown.
Binary file added RoboCat/Assets/Background_Image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RoboCat/Assets/Player_Image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RoboCat/Assets/Rock_Image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RoboCat/Assets/Square_Image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 22 additions & 1 deletion RoboCat/Chapter3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<OutDir>Bin\$(Configuration)\</OutDir>
<Allegro_AddonImage>true</Allegro_AddonImage>
<Allegro_AddonTTF>true</Allegro_AddonTTF>
<Allegro_AddonPrimitives>true</Allegro_AddonPrimitives>
<Allegro_AddonFont>true</Allegro_AddonFont>
<Allegro_AddonColor>true</Allegro_AddonColor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<LinkIncremental>true</LinkIncremental>
Expand Down Expand Up @@ -128,7 +133,7 @@
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<AdditionalIncludeDirectories>..\SDL\include;Inc;..\</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>RoboCatPCH.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
Expand Down Expand Up @@ -370,14 +375,24 @@
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Src\Colour.cpp" />
<ClCompile Include="Src\Networker.cpp" />
<ClCompile Include="Src\Wall.cpp" />
<ClInclude Include="Inc\AckRange.h" />
<ClInclude Include="Inc\ByteSwap.h" />
<ClInclude Include="Inc\Colour.h" />
<ClInclude Include="Inc\DeliveryNotificationManager.h" />
<ClInclude Include="Inc\GameObject.h" />
<ClInclude Include="Inc\GraphicsLibrary.h" />
<ClInclude Include="Inc\InFlightPacket.h" />
<ClInclude Include="Inc\InputSystem.h" />
<ClInclude Include="Inc\LinkingContext.h" />
<ClInclude Include="Inc\MemoryBitStream.h" />
<ClInclude Include="Inc\Networker.h" />
<ClInclude Include="Inc\OutputWindow.h" />
<ClInclude Include="Inc\PlayerController.h" />
<ClInclude Include="Inc\RoboMath.h" />
<ClInclude Include="Inc\Rock.h" />
<ClInclude Include="Inc\SocketAddress.h" />
<ClInclude Include="Inc\SocketAddressFactory.h" />
<ClInclude Include="Inc\SocketUtil.h" />
Expand All @@ -390,15 +405,21 @@
<ClInclude Include="Inc\UDPSocket.h" />
<ClCompile Include="Src\AckRange.cpp" />
<ClCompile Include="Src\DeliveryNotificationManager.cpp" />
<ClCompile Include="Src\GameObject.cpp" />
<ClCompile Include="Src\GraphicsLibrary.cpp" />
<ClCompile Include="Src\InFlightPacket.cpp" />
<ClCompile Include="Src\InputSystem.cpp" />
<ClCompile Include="Src\Main.cpp" />
<ClCompile Include="Src\MemoryBitStream.cpp" />
<ClCompile Include="Src\OutputWindow.cpp" />
<ClCompile Include="Src\PlayerController.cpp" />
<ClCompile Include="Src\Rock.cpp" />
<ClCompile Include="Src\SocketAddress.cpp" />
<ClCompile Include="Src\SocketAddressFactory.cpp" />
<ClCompile Include="Src\SocketUtil.cpp" />
<ClCompile Include="Src\StringUtils.cpp" />
<ClCompile Include="Src\TCPSocket.cpp" />
<ClInclude Include="Inc\Wall.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\RoboCatPCH.cpp">
Expand Down
2 changes: 2 additions & 0 deletions RoboCat/Inc/AckRange.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

//typedef PacketSequenceNumber uint16_t;

class AckRange
Expand Down
43 changes: 43 additions & 0 deletions RoboCat/Inc/Colour.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

/*
Allegro Wrapper Functions
Written by Adel Talhouk in FA21
Colour.h
File information:
This file contains data used for colours.
*/

class Colour
{
//-------------------------Private data-------------------------

//Red channel
unsigned __int8 mR;

//Green channel
unsigned __int8 mG;

//Blue channel
unsigned __int8 mB;

//Alpha channel
unsigned __int8 mA;

//-------------------------Public data-------------------------
public:

//Constructor(s)
Colour();
Colour(unsigned __int8 r, unsigned __int8 g, unsigned __int8 b);
Colour(unsigned __int8 r, unsigned __int8 g, unsigned __int8 b, unsigned __int8 a);

//Destructor
~Colour();

//Accessor(s)
unsigned __int8 getR() { return mR; };
unsigned __int8 getG() { return mG; };
unsigned __int8 getB() { return mB; };
unsigned __int8 getA() { return mA; };
};
83 changes: 54 additions & 29 deletions RoboCat/Inc/DeliveryNotificationManager.h
Original file line number Diff line number Diff line change
@@ -1,52 +1,77 @@
#pragma once

#include "MemoryBitStream.h"
#include "InFlightPacket.h"
#include "AckRange.h"
#include <utility>
#include <deque>

using std::deque;

typedef uint16_t PacketSequenceNumber;

////https://www.geeksforgeeks.org/priority-queue-of-pairs-in-c-with-ordering-by-first-and-second-element/
//struct myComp {
// constexpr bool operator()(
// std::pair<InFlightPacket, OutputMemoryBitStream&> const& a,
// std::pair<InFlightPacket, OutputMemoryBitStream&> const& b)
// const noexcept
// {
// return a.first.GetSequenceNumber() > b.first.GetSequenceNumber();
// }
//};

class Networker;

class DeliveryNotificationManager
{
public:


DeliveryNotificationManager( bool inShouldSendAcks, bool inShouldProcessAcks );
DeliveryNotificationManager(bool inShouldSendAcks, bool inShouldProcessAcks, Networker* pNetworker);
~DeliveryNotificationManager();

inline InFlightPacket* WriteState( OutputMemoryBitStream& inOutputStream );
inline bool ReadAndProcessState( InputMemoryBitStream& inInputStream );
inline InFlightPacket* WriteState(OutputMemoryBitStream& inOutputStream);
inline bool ReadAndProcessState(InputMemoryBitStream& inInputStream);

void ProcessTimedOutPackets();
void ResendPacket(const int ID, const PacketSequenceNumber packetSequenceNum);
void ProcessTimedOutPackets();

uint32_t GetDroppedPacketCount() const { return mDroppedPacketCount; }
uint32_t GetDeliveredPacketCount() const { return mDeliveredPacketCount; }
uint32_t GetDispatchedPacketCount() const { return mDispatchedPacketCount; }
uint32_t GetDroppedPacketCount() const { return mDroppedPacketCount; }
uint32_t GetDeliveredPacketCount() const { return mDeliveredPacketCount; }
uint32_t GetDispatchedPacketCount() const { return mDispatchedPacketCount; }

const deque< InFlightPacket >& GetInFlightPackets() const { return mInFlightPackets; }
//const deque<InFlightPacket>& GetInFlightPackets() const { return mInFlightPackets; }
const deque<std::pair<InFlightPacket, OutputMemoryBitStream*>> GetInFlightPackets() const { return mInFlightPacketsPair; }

private:



InFlightPacket* WriteSequenceNumber( OutputMemoryBitStream& inOutputStream );
void WriteAckData( OutputMemoryBitStream& inOutputStream );

InFlightPacket* WriteSequenceNumber(OutputMemoryBitStream& inOutputStream);
void WriteAckData(OutputMemoryBitStream& inOutputStream);

//returns wether to drop the packet- if sequence number is too low!
bool ProcessSequenceNumber( InputMemoryBitStream& inInputStream );
void ProcessAcks( InputMemoryBitStream& inInputStream );

bool ProcessSequenceNumber(InputMemoryBitStream& inInputStream);
void ProcessAcks(InputMemoryBitStream& inInputStream);

void AddPendingAck( PacketSequenceNumber inSequenceNumber );
void HandlePacketDeliveryFailure( const InFlightPacket& inFlightPacket );
void HandlePacketDeliverySuccess( const InFlightPacket& inFlightPacket );
void AddPendingAck(PacketSequenceNumber inSequenceNumber);
void HandlePacketDeliveryFailure(const InFlightPacket& inFlightPacket, const PacketSequenceNumber packetSequenceNum);
void HandlePacketDeliverySuccess(const InFlightPacket& inFlightPacket, const PacketSequenceNumber packetSequenceNum);

PacketSequenceNumber mNextOutgoingSequenceNumber;
PacketSequenceNumber mNextExpectedSequenceNumber;
PacketSequenceNumber mNextOutgoingSequenceNumber;
PacketSequenceNumber mNextExpectedSequenceNumber;

deque< InFlightPacket > mInFlightPackets;
deque< AckRange > mPendingAcks;
//deque<InFlightPacket> mInFlightPackets;
deque<std::pair<InFlightPacket, OutputMemoryBitStream*>> mInFlightPacketsPair;
deque<AckRange> mPendingAcks;

bool mShouldSendAcks;
bool mShouldProcessAcks;
bool mShouldSendAcks;
bool mShouldProcessAcks;

uint32_t mDeliveredPacketCount;
uint32_t mDroppedPacketCount;
uint32_t mDispatchedPacketCount;
uint32_t mDeliveredPacketCount;
uint32_t mDroppedPacketCount;
uint32_t mDispatchedPacketCount;

//Networker
Networker* mpNetworker;
};


Expand Down
71 changes: 71 additions & 0 deletions RoboCat/Inc/GameObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#pragma once

#include <utility>
#include "GraphicsLibrary.h"
#include "TransmissionData.h"

using std::pair;

/*
File information:
This file contains the definition for the GameObject class.
*/

enum GameObjectType
{
INVALID = -1,
ROCK,
WALL,
PLAYER,
ENUM_SIZE
};

class GameObject : public TransmissionData
{
//-------------------------Private data-------------------------


//-------------------------Protected data-------------------------

protected:

//Identifiers
const GameObjectType mGameObjectType = GameObjectType::INVALID;
const int mNetworkID;

//Position
pair<float, float> mPosition;

//Graphics library
GraphicsLibrary* pGraphicsLibrary;

//Sprite identifier
const std::string mSPRITE_IDENTIFIER;

//Constructor(s)
GameObject(GameObjectType gameObjectType, const int networkID, GraphicsLibrary* graphicsLibrary);
GameObject(GameObjectType gameObjectType, const int networkID, GraphicsLibrary* graphicsLibrary, pair<float, float> position, const std::string spriteIdentifier = "");

//-------------------------Public data-------------------------
public:

//Copy constructor
GameObject(const GameObject& copy);

//Destructor
virtual ~GameObject();

//Accessor(s)
const GameObjectType getGameObjectType() { return mGameObjectType; };
const int getNetworkID() { return mNetworkID; };
const pair<float, float> getPosition() { return mPosition; };

//Mutator(s)
float setPosX(float posX) { mPosition.first = posX; };
float setPosY(float posY) { mPosition.second = posY; };
void setPos(pair<float, float> newPos) { mPosition = newPos; };

//Functions
virtual void update() = 0;
virtual void draw() = 0;
};
80 changes: 80 additions & 0 deletions RoboCat/Inc/GraphicsLibrary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#pragma once

/*
Allegro Wrapper Functions
Written by Adel Talhouk in FA21
GraphicsLibrary.h
File information:
This file contains function abstractions from Allegro 5, wrapped up in my Graphics Library. This will
be used to render images and text to the screen.
Source I am consulting: Allegro 5.0.10 Manual - http://cdn.allegro.cc/file/library/allegro/5.0.10/allegro-5.0.10-manual.pdf
*/

#include <string>
#include <vector>

#include "Colour.h"

//https://github.com/liballeg/allegro_wiki/wiki/Allegro-in-Visual-Studio#using-nuget-within-visual-studio
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_acodec.h>
#include <allegro5/allegro_image.h>
#include <allegro5/allegro_primitives.h>

enum TextAlignment
{
ALIGN_LEFT = ALLEGRO_ALIGN_LEFT,
ALIGN_CENTER = ALLEGRO_ALIGN_CENTRE,
ALIGN_RIGHT = ALLEGRO_ALIGN_RIGHT
};

class GraphicsLibrary
{
//-------------------------Private data-------------------------

//Screen data
float mScreenSizeX;
float mScreenSizeY;

//Allegro display
ALLEGRO_DISPLAY* mpDisplay;

//Other images to draw
std::vector<std::pair<std::string, ALLEGRO_BITMAP*>> mBitmapPointersVector;

//UI text
ALLEGRO_FONT* mpFont;
ALLEGRO_COLOR mTextColour;

friend class InputSystem;

//-------------------------Public data-------------------------
public:

//Constructor(s)
GraphicsLibrary(float screenSizeX, float screenSizeY);

//Destructor
~GraphicsLibrary();

//Accessor(s)
float getScreenSizeX() { return mScreenSizeX; };
float getScreenSizeY() { return mScreenSizeY; };

//Mutator(s)

//Functions
bool init();
bool initText(std::string fontFilePath, int fontSize, Colour textColour);
void render();
void loadImage(std::string imageFilePath, std::string imageIdentifier);

//Drawing functions
void drawText(float posX, float posY, std::string text, TextAlignment alignment);
void drawRectangle(float topLeftX, float topLeftY, float bottomRightX, float bottomRightY, Colour colour, float thickness);
void drawImage(std::string imageIdentifier, float posX, float posY);
void drawScaledImage(std::string imageIdentifier, float posX, float posY, float scaleX, float scaleY);
void drawTintedImage(std::string imageIdentifier, float posX, float posY, Colour col);
};
Loading