diff --git a/RoboCat/Assets/ARIBL0.ttf b/RoboCat/Assets/ARIBL0.ttf
new file mode 100644
index 00000000..a1e68a36
Binary files /dev/null and b/RoboCat/Assets/ARIBL0.ttf differ
diff --git a/RoboCat/Assets/Background_Image.jpg b/RoboCat/Assets/Background_Image.jpg
new file mode 100644
index 00000000..dc0ef63d
Binary files /dev/null and b/RoboCat/Assets/Background_Image.jpg differ
diff --git a/RoboCat/Assets/Player_Image.png b/RoboCat/Assets/Player_Image.png
new file mode 100644
index 00000000..c8f237fc
Binary files /dev/null and b/RoboCat/Assets/Player_Image.png differ
diff --git a/RoboCat/Assets/Rock_Image.png b/RoboCat/Assets/Rock_Image.png
new file mode 100644
index 00000000..f2322dae
Binary files /dev/null and b/RoboCat/Assets/Rock_Image.png differ
diff --git a/RoboCat/Assets/Square_Image.png b/RoboCat/Assets/Square_Image.png
new file mode 100644
index 00000000..c679d476
Binary files /dev/null and b/RoboCat/Assets/Square_Image.png differ
diff --git a/RoboCat/Chapter3.vcxproj b/RoboCat/Chapter3.vcxproj
index 8c859a81..cabc7347 100644
--- a/RoboCat/Chapter3.vcxproj
+++ b/RoboCat/Chapter3.vcxproj
@@ -92,6 +92,11 @@
true
true
Bin\$(Configuration)\
+ true
+ true
+ true
+ true
+ true
true
@@ -128,7 +133,7 @@
ProgramDatabase
EnableFastChecks
..\SDL\include;Inc;..\
- Use
+ NotUsing
RoboCatPCH.h
@@ -370,14 +375,24 @@
+
+
+
+
+
+
+
+
+
+
@@ -390,15 +405,21 @@
+
+
+
+
+
+
diff --git a/RoboCat/Inc/AckRange.h b/RoboCat/Inc/AckRange.h
index 004d14c9..d1432c4d 100644
--- a/RoboCat/Inc/AckRange.h
+++ b/RoboCat/Inc/AckRange.h
@@ -1,3 +1,5 @@
+#pragma once
+
//typedef PacketSequenceNumber uint16_t;
class AckRange
diff --git a/RoboCat/Inc/Colour.h b/RoboCat/Inc/Colour.h
new file mode 100644
index 00000000..5400c78d
--- /dev/null
+++ b/RoboCat/Inc/Colour.h
@@ -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; };
+};
\ No newline at end of file
diff --git a/RoboCat/Inc/DeliveryNotificationManager.h b/RoboCat/Inc/DeliveryNotificationManager.h
index b6a795a4..2622106f 100644
--- a/RoboCat/Inc/DeliveryNotificationManager.h
+++ b/RoboCat/Inc/DeliveryNotificationManager.h
@@ -1,52 +1,77 @@
+#pragma once
+
+#include "MemoryBitStream.h"
+#include "InFlightPacket.h"
+#include "AckRange.h"
+#include
+#include
+
+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 const& a,
+// std::pair 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& GetInFlightPackets() const { return mInFlightPackets; }
+ const deque> 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 mInFlightPackets;
+ deque> mInFlightPacketsPair;
+ deque 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;
};
diff --git a/RoboCat/Inc/GameObject.h b/RoboCat/Inc/GameObject.h
new file mode 100644
index 00000000..ef412ed8
--- /dev/null
+++ b/RoboCat/Inc/GameObject.h
@@ -0,0 +1,71 @@
+#pragma once
+
+#include
+#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 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 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 getPosition() { return mPosition; };
+
+ //Mutator(s)
+ float setPosX(float posX) { mPosition.first = posX; };
+ float setPosY(float posY) { mPosition.second = posY; };
+ void setPos(pair newPos) { mPosition = newPos; };
+
+ //Functions
+ virtual void update() = 0;
+ virtual void draw() = 0;
+};
\ No newline at end of file
diff --git a/RoboCat/Inc/GraphicsLibrary.h b/RoboCat/Inc/GraphicsLibrary.h
new file mode 100644
index 00000000..32ccafcc
--- /dev/null
+++ b/RoboCat/Inc/GraphicsLibrary.h
@@ -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
+#include
+
+#include "Colour.h"
+
+//https://github.com/liballeg/allegro_wiki/wiki/Allegro-in-Visual-Studio#using-nuget-within-visual-studio
+#include
+#include
+#include
+#include
+#include
+#include
+
+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> 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);
+};
\ No newline at end of file
diff --git a/RoboCat/Inc/InFlightPacket.h b/RoboCat/Inc/InFlightPacket.h
index 494e097e..9e620e3a 100644
--- a/RoboCat/Inc/InFlightPacket.h
+++ b/RoboCat/Inc/InFlightPacket.h
@@ -1,3 +1,9 @@
+#pragma once
+
+#include
+
+using std::unordered_map;
+
class DeliveryNotificationManager;
//in case we decide to change the type of the sequence number to use fewer or more bits
@@ -12,22 +18,22 @@ class InFlightPacket
PacketSequenceNumber GetSequenceNumber() const { return mSequenceNumber; }
float GetTimeDispatched() const { return mTimeDispatched; }
- void SetTransmissionData( int inKey, TransmissionDataPtr inTransmissionData )
+ void SetTransmissionData( int inKey, TransmissionData* inTransmissionData )
{
mTransmissionDataMap[ inKey ] = inTransmissionData;
}
- const TransmissionDataPtr GetTransmissionData( int inKey ) const
+ const TransmissionData* GetTransmissionData( int inKey ) const
{
auto it = mTransmissionDataMap.find( inKey );
return ( it != mTransmissionDataMap.end() ) ? it->second : nullptr;
}
- void HandleDeliveryFailure( DeliveryNotificationManager* inDeliveryNotificationManager ) const;
- void HandleDeliverySuccess( DeliveryNotificationManager* inDeliveryNotificationManager ) const;
+ void HandleDeliveryFailure(DeliveryNotificationManager* inDeliveryNotificationManager, const PacketSequenceNumber packetSequenceNum) const;
+ void HandleDeliverySuccess(DeliveryNotificationManager* inDeliveryNotificationManager, const PacketSequenceNumber packetSequenceNum) const;
private:
PacketSequenceNumber mSequenceNumber;
float mTimeDispatched;
- unordered_map< int, TransmissionDataPtr > mTransmissionDataMap;
+ unordered_map< int, TransmissionData* > mTransmissionDataMap;
};
\ No newline at end of file
diff --git a/RoboCat/Inc/InputSystem.h b/RoboCat/Inc/InputSystem.h
new file mode 100644
index 00000000..eb9ec329
--- /dev/null
+++ b/RoboCat/Inc/InputSystem.h
@@ -0,0 +1,75 @@
+#pragma once
+
+/*
+Allegro Wrapper Functions
+Written by Adel Talhouk in FA21
+InputSystem.h
+ File information:
+ This file contains the keycodes for input, which can be used in any way desired by other classes
+ and files.
+*/
+
+#include "GraphicsLibrary.h"
+
+//Include allegro libraries for input
+#include
+
+enum KeyCode
+{
+ Esc = ALLEGRO_KEY_ESCAPE,
+ R = ALLEGRO_KEY_R,
+ Tab = ALLEGRO_KEY_TAB,
+ W = ALLEGRO_KEY_W,
+ A = ALLEGRO_KEY_A,
+ S = ALLEGRO_KEY_S,
+ D = ALLEGRO_KEY_D,
+ BACK = ALLEGRO_KEY_BACKSPACE
+};
+
+enum MouseButton
+{
+ LeftMouse = 0,
+ RightMouse = 1,
+ MiddleMouse = 2
+};
+
+enum InputMode
+{
+ NONE = -1,
+ KeyPressed = ALLEGRO_EVENT_KEY_DOWN,
+ KeyReleased = ALLEGRO_EVENT_KEY_UP,
+ MouseDown = ALLEGRO_EVENT_MOUSE_BUTTON_DOWN,
+ MouseUp = ALLEGRO_EVENT_MOUSE_BUTTON_UP
+};
+
+class InputSystem
+{
+ //-------------------------Private data-------------------------
+
+ //Event queue
+ ALLEGRO_EVENT_QUEUE* mpMouseEventQueue;
+ ALLEGRO_EVENT_QUEUE* mpKeyboardEventQueue;
+
+ //Event
+ ALLEGRO_EVENT mMouseEvent;
+ ALLEGRO_EVENT mKeyboardEvent;
+
+ //-------------------------Public data-------------------------
+public:
+
+ //Constructor(s)
+ InputSystem();
+
+ //Destructor
+ ~InputSystem();
+
+ //Accessor(s)
+ float getMouseX();
+ float getMouseY();
+ std::pair getMousePosition();
+
+ //Functions
+ bool init(GraphicsLibrary* pGraphicsLib);
+ MouseButton getMouseInput(InputMode inputMode);
+ KeyCode getKeyboardInput(InputMode inputMode);
+};
\ No newline at end of file
diff --git a/RoboCat/Inc/MemoryBitStream.h b/RoboCat/Inc/MemoryBitStream.h
index c2138925..ba65a8ff 100644
--- a/RoboCat/Inc/MemoryBitStream.h
+++ b/RoboCat/Inc/MemoryBitStream.h
@@ -1,8 +1,10 @@
+#pragma once
#include
#include
#include
#include
+#include "RoboMath.h"
class GameObject;
diff --git a/RoboCat/Inc/Networker.h b/RoboCat/Inc/Networker.h
new file mode 100644
index 00000000..41caed9b
--- /dev/null
+++ b/RoboCat/Inc/Networker.h
@@ -0,0 +1,92 @@
+#pragma once
+
+#include
+#include