Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9af7c50
Graphics lib and game code
HarrisSlesar Mar 4, 2022
b94bd6a
Committing working base game
HarrisSlesar Mar 25, 2022
eb6e79b
network manager
HarrisSlesar Mar 28, 2022
27c6a0c
Changes to test github building
HarrisSlesar Mar 28, 2022
2c4d505
Removing warnings to try and make git build this correctly
HarrisSlesar Mar 28, 2022
d700e41
Committing nearly working first network manager
HarrisSlesar Mar 28, 2022
549c6fe
Committing work from laptop. Instances of game can now connect to eac…
HarrisSlesar Mar 28, 2022
83ed85e
Working connection and syncing between two instances. Only one game o…
HarrisSlesar Mar 28, 2022
a934a22
Attempting to add more gameobjects
HarrisSlesar Mar 29, 2022
b937c1e
Working second game object. Still need to send packet
HarrisSlesar Mar 29, 2022
2aeecae
Update README.md
HarrisSlesar Mar 29, 2022
a3f3119
Update README.md
HarrisSlesar Mar 29, 2022
cedadcc
Working commit of assignment 2. 3 game objects with limited functiona…
HarrisSlesar Mar 29, 2022
c034a85
Merge branch 'assignment2' of https://github.com/HarrisSlesar/SocketD…
HarrisSlesar Mar 29, 2022
f2b8911
Merge branch 'assignment2' into assignment3
HarrisSlesar Apr 1, 2022
b447ea6
Almost working acknowledgement code?
HarrisSlesar Apr 11, 2022
722b510
Pain. Real pain. 12 hours later but I actually made my acknowledgemen…
HarrisSlesar Apr 12, 2022
0d80702
Working latency and jitter?
HarrisSlesar Apr 12, 2022
1d222d3
Implementing fix to make it so game doesn't simulate packet loss unti…
HarrisSlesar Apr 12, 2022
78232c8
Minor change to ReadMe file
HarrisSlesar Apr 12, 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
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Socket Demo
# Running and playing instructions
These are the step-by-step instructions for running and playing Assignment 3.

This code is to be used as a basis for doing assignment 1 and for the tutorials we will do in class.
1. Build the solution and launch a command window from SocketDemo\RoboCat\Bin\Debug
2. Run the .exe in the command window with the following arguments. For the first instance of the game, enter a port number and the username of the player.
Exe: SocketDemo.exe 8000 Harris
3. For all other instances once the master peer is open, give it the full address of the master peer, followed by the username.
Exe: SocketDemo.exe 127.0.0.1:8000 Scott
4. Once all game instances are open, press the S KEY on the master peer instance to start the game.
5. The game should now be started and you can take the following actions.

LEFT CLICK: Will draw the base game object on both instances. Can be held down to draw more.

RIGHT CLICK: Will delete all game objects at the clicked location

ONE KEY: Will create a different game object at a random location. The locations will be synced

TWO KEY: Will create a 3rd game object at your mouse location. Will then move to a new location every few seconds. (Note: I couldn't get the random working right so while the movement is synced, it's not exactly random.)

SPACE KEY: Will pause all animations. (It's updated every frame, so if the button is held it will toggle quickly.)

ESCAPE: Will quit and end the program. (Can be done even if not connected to other players)
76 changes: 66 additions & 10 deletions RoboCat/Chapter3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
<LinkIncremental>true</LinkIncremental>
<GenerateManifest>true</GenerateManifest>
<OutDir>Bin\$(Configuration)\</OutDir>
<Allegro_AddonImage>true</Allegro_AddonImage>
<Allegro_AddonTTF>true</Allegro_AddonTTF>
<Allegro_AddonAudio>true</Allegro_AddonAudio>
<Allegro_AddonFont>true</Allegro_AddonFont>
<Allegro_AddonPrimitives>true</Allegro_AddonPrimitives>
<Allegro_AddonAcodec>true</Allegro_AddonAcodec>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<LinkIncremental>true</LinkIncremental>
Expand Down Expand Up @@ -127,8 +133,8 @@
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<AdditionalIncludeDirectories>..\SDL\include;Inc;..\</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<AdditionalIncludeDirectories>..\SDL\include;Inc;..\;Inc\GraphicsInc;Inc\DeanInc;Inc\BaseGameInc</AdditionalIncludeDirectories>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>RoboCatPCH.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
Expand Down Expand Up @@ -370,10 +376,36 @@
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Inc\AckRange.h" />
<ClInclude Include="Inc\BaseGameInc\Game.h" />
<ClInclude Include="Inc\BaseGameInc\GraphicsBufferManager.h" />
<ClInclude Include="Inc\BaseGameInc\MemoryManager.h" />
<ClInclude Include="Inc\BaseGameInc\NetworkManager.h" />
<ClInclude Include="Inc\BaseGameInc\Unit.h" />
<ClInclude Include="Inc\BaseGameInc\UnitManager.h" />
<ClInclude Include="Inc\ByteSwap.h" />
<ClInclude Include="Inc\DeliveryNotificationManager.h" />
<ClInclude Include="Inc\InFlightPacket.h" />
<ClInclude Include="Inc\DeanInc\CircularQueue.h" />
<ClInclude Include="Inc\DeanInc\ConditionalCallback.h" />
<ClInclude Include="Inc\DeanInc\DataRepository.h" />
<ClInclude Include="Inc\DeanInc\DeanLibDefines.h" />
<ClInclude Include="Inc\DeanInc\DeanLibUtilities.h" />
<ClInclude Include="Inc\DeanInc\DeanMath.h" />
<ClInclude Include="Inc\DeanInc\MemoryPool.h" />
<ClInclude Include="Inc\DeanInc\MemoryTracker.h" />
<ClInclude Include="Inc\DeanInc\MultiDimensionalArray.h" />
<ClInclude Include="Inc\DeanInc\PerformanceTracker.h" />
<ClInclude Include="Inc\DeanInc\RayCaster.h" />
<ClInclude Include="Inc\DeanInc\TimedCallback.h" />
<ClInclude Include="Inc\DeanInc\Timer.h" />
<ClInclude Include="Inc\DeanInc\Trackable.h" />
<ClInclude Include="Inc\DeanInc\Vector2D.h" />
<ClInclude Include="Inc\GraphicsInc\Animation.h" />
<ClInclude Include="Inc\GraphicsInc\Color.h" />
<ClInclude Include="Inc\GraphicsInc\Font.h" />
<ClInclude Include="Inc\GraphicsInc\GraphicsBuffer.h" />
<ClInclude Include="Inc\GraphicsInc\GraphicsLib.h" />
<ClInclude Include="Inc\GraphicsInc\GraphicsSystem.h" />
<ClInclude Include="Inc\GraphicsInc\Sprite.h" />
<ClInclude Include="Inc\GraphicsInc\System.h" />
<ClInclude Include="Inc\LinkingContext.h" />
<ClInclude Include="Inc\MemoryBitStream.h" />
<ClInclude Include="Inc\OutputWindow.h" />
Expand All @@ -386,19 +418,43 @@
<ClInclude Include="Inc\RoboCatPCH.h" />
<ClInclude Include="Inc\RoboCatShared.h" />
<ClInclude Include="Inc\Timing.h" />
<ClInclude Include="Inc\TransmissionData.h" />
<ClInclude Include="Inc\UDPSocket.h" />
<ClCompile Include="Src\AckRange.cpp" />
<ClCompile Include="Src\DeliveryNotificationManager.cpp" />
<ClCompile Include="Src\InFlightPacket.cpp" />
<ClCompile Include="Src\Main.cpp" />
<ClCompile Include="Src\BaseGameSrc\Game.cpp" />
<ClCompile Include="Src\BaseGameSrc\GraphicsBufferManager.cpp" />
<ClCompile Include="Src\BaseGameSrc\main.cpp" />
<ClCompile Include="Src\BaseGameSrc\MemoryManager.cpp" />
<ClCompile Include="Src\BaseGameSrc\NetworkManager.cpp" />
<ClCompile Include="Src\BaseGameSrc\Unit.cpp" />
<ClCompile Include="Src\BaseGameSrc\UnitManager.cpp" />
<ClCompile Include="Src\DeanSrc\CircularQueue.cpp" />
<ClCompile Include="Src\DeanSrc\DataRepository.cpp" />
<ClCompile Include="Src\DeanSrc\DeanLibUtilities.cpp" />
<ClCompile Include="Src\DeanSrc\DeanMath.cpp" />
<ClCompile Include="Src\DeanSrc\MemoryPool.cpp" />
<ClCompile Include="Src\DeanSrc\MemoryTracker.cpp" />
<ClCompile Include="Src\DeanSrc\PerformanceTracker.cpp" />
<ClCompile Include="Src\DeanSrc\RayCaster.cpp" />
<ClCompile Include="Src\DeanSrc\Timer.cpp" />
<ClCompile Include="Src\DeanSrc\Trackable.cpp" />
<ClCompile Include="Src\DeanSrc\Vector2D.cpp" />
<ClCompile Include="Src\GraphicsSrc\Animation.cpp" />
<ClCompile Include="Src\GraphicsSrc\Color.cpp" />
<ClCompile Include="Src\GraphicsSrc\Font.cpp" />
<ClCompile Include="Src\GraphicsSrc\GraphicsBuffer.cpp" />
<ClCompile Include="Src\GraphicsSrc\GraphicsLib.cpp" />
<ClCompile Include="Src\GraphicsSrc\GraphicsSystem.cpp" />
<ClCompile Include="Src\GraphicsSrc\Sprite.cpp" />
<ClCompile Include="Src\GraphicsSrc\System.cpp" />
<ClCompile Include="Src\RoboMath.cpp" />
<ClCompile Include="Src\SocketMain.cpp" />
<ClCompile Include="Src\MemoryBitStream.cpp" />
<ClCompile Include="Src\OutputWindow.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\WeightedTimedMovingAverage.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\RoboCatPCH.cpp">
Expand Down
98 changes: 98 additions & 0 deletions RoboCat/Inc/BaseGameInc/Game.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#pragma once

#include <Trackable.h>
#include <Vector2D.h>




class System;
class Unit;
class GraphicsBuffer;
class UnitManager;
class MemoryManager;
class GraphicsBufferManager;
class NetworkManager;
typedef std::string GBKey;
class Game : public Trackable
{
public:

static Game* getInstance();
static void initInstance();
static void deleteInstance();

bool init(unsigned int width, unsigned int height, double targetTimePerFrame = 16.7);
void cleanup();

void doLoop();

System* getSystem() const { return mpSystem; };

double getTargetTimePerFrame() const { return mTargetTimePerFrame; };
GraphicsBufferManager* getGraphicsBufferManager() const { return mpGraphicsBufferManager; };
UnitManager* getUnitManager() const { return mpUnitManager; };
MemoryManager* getMemoryManager() const { return mpMemoryManager; };
NetworkManager* getNetworkManager() const { return mpNetworkManager; };
void startGame() { gameStarted = true; };

enum class ActionTypes
{
CreateUnit,
CreateUnitRand,
CreateUnitMove,
DestroyUnit,
ToggleAnimSingle,
ToggleAnimAll
};
enum class UnitTypes
{
BASE_UNIT,
RAND_DIR,
RAND_SPAWN
};
void HandleAction(ActionTypes, Vector2D, int);

private:
static Game* mspInstance;

System* mpSystem=NULL;
UnitManager* mpUnitManager = NULL;
GraphicsBufferManager* mpGraphicsBufferManager = NULL;
MemoryManager* mpMemoryManager = NULL;

double mTargetTimePerFrame=0;
bool mIsInitted = false;
bool mShouldContinue = true;
bool gameStarted = false;
NetworkManager* mpNetworkManager = NULL;



//private constructor/destructor - don't want someone trying to delete the instance directly
Game();
~Game();

//might as well invalidate copy constructor and assignment operator
Game(Game& game);
void operator=(const Game& game);

void getInput();
void update(double dt);
void render();

void loadBuffers();
void createUnit(const Vector2D& pos);
void createUnit(int seed);
void createUnit(const Vector2D& pos, int seed);


};



const GBKey WOODS("woods");
const GBKey SMURFS("smurfs");
const GBKey DEAN("dean");
const GBKey NUMBERED("numbered");

33 changes: 33 additions & 0 deletions RoboCat/Inc/BaseGameInc/GraphicsBufferManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <Trackable.h>
#include <map>
#include <string>

#include "Color.h"

class GraphicsBuffer;

typedef std::string GBKey;

class GraphicsBufferManager :public Trackable
{
public:
GraphicsBufferManager();
~GraphicsBufferManager();

void clear();

const GraphicsBuffer* createBuffer(const GBKey& key, const std::string& filename);
const GraphicsBuffer* createBuffer(const GBKey& key, unsigned int width, unsigned int height, Color color = Color());
const GraphicsBuffer* cloneBuffer(const GBKey& newKey, const GBKey& existingKey);//make a copy of existingKey's buffer and call it newKey
const GraphicsBuffer* getBuffer(const GBKey& key) const;
bool destroyBuffer(const GBKey& key);
bool destroyBuffer(GraphicsBuffer* pBuffer);

unsigned int getNumBuffersManaged() const { return mMap.size(); };
bool alreadyExists(const GBKey& key) const;

private:
std::map<GBKey, GraphicsBuffer*> mMap;
};
49 changes: 49 additions & 0 deletions RoboCat/Inc/BaseGameInc/MemoryManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once
#include <iostream>
#include <MemoryPool.h>
#include <MemoryTracker.h>

using namespace std;

class MemoryManager : public Trackable {
public:
MemoryManager();
~MemoryManager();

//Initialization and cleanup functions
void init();
void cleanup();

//Function to reset the memory allocations
void reset();

//Allocates memory to appropriate memoryPool
Byte* allocate(unsigned int);

//Deallocates memory from appropriate memoryPool
void deallocate(Byte*);

//returns total allocated memory
unsigned int getTotalAllocated() { return mTotalAllocated; };

//returns total capacity
unsigned int getTotalCapacity() { return mTotalCapacity; };

//returns total waste
unsigned int getTotalWaste() { return mTotalWaste; };

private:
MemoryPool* mpMemoryPoolSmall; //Pointer to small memory pool
MemoryPool* mpMemoryPoolMed; //Pointer to medium memory pool
MemoryPool* mpMemoryPoolLarge; //pointer to large memory pool

unsigned int mTotalCapacity;
unsigned int mTotalAllocated;

unsigned int mTotalWaste;

unsigned int mMaxCapacity;



};
Loading