Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*.pdb

Debug/
packages/
13 changes: 13 additions & 0 deletions Assignment3README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
run the server FIRST via command line: SocketDemo.exe server
run the client via command line: SocketDemo.exe

press the escape key to end the Allegro Display

server is a green circle
client is a red square

both can shoot with space bar but the projectiles do nothing and never die.

movement on both apps is just Up Down Left Right

the rain is simulated on the server and sent to the client.
43 changes: 39 additions & 4 deletions RoboCat/Chapter3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@
<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>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|X64'">
<LinkIncremental>true</LinkIncremental>
Expand Down Expand Up @@ -127,12 +131,12 @@
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<AdditionalIncludeDirectories>..\SDL\include;Inc;..\</AdditionalIncludeDirectories>
<PrecompiledHeader>Create</PrecompiledHeader>
<AdditionalIncludeDirectories>..\SDL\include;Inc;..\;$(SolutionDir)packages\Allegro.5.2.7.1\build\native\include\allegro5</AdditionalIncludeDirectories>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>RoboCatPCH.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalDependencies>d3d11.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies);Ws2_32.lib</AdditionalDependencies>
<AdditionalDependencies>allegro_color.lib;allegro_primitives.lib;allegro.lib;d3d11.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies);Ws2_32.lib</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
Expand All @@ -141,6 +145,7 @@
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
<SubSystem>Console</SubSystem>
<AdditionalLibraryDirectories>$(SolutionDir)packages/Allegro.5.2.7.1\build\native\v143\win32\lib</AdditionalLibraryDirectories>
</Link>
<Manifest>
<EnableDPIAwareness>true</EnableDPIAwareness>
Expand Down Expand Up @@ -370,16 +375,32 @@
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Inc\CircleClass.h" />
<ClInclude Include="Inc\RainParticle.h" />
<ClInclude Include="Inc\RectangleObject.h" />
<ClInclude Include="Inc\AckRange.h" />
<ClInclude Include="Inc\ByteSwap.h" />
<ClInclude Include="Inc\DeliveryNotificationManager.h" />
<ClInclude Include="Inc\InFlightPacket.h" />
<ClInclude Include="Inc\LinkingContext.h" />
<ClInclude Include="Inc\MemoryBitStream.h" />
<ClInclude Include="Inc\OutputWindow.h" />
<ClInclude Include="Inc\RoboMath.h" />
<ClInclude Include="Inc\SocketAddress.h" />
<ClInclude Include="Inc\SocketAddressFactory.h" />
<ClInclude Include="Inc\SocketUtil.h" />
<ClInclude Include="Inc\StringUtils.h" />
<ClInclude Include="Inc\TCPSocket.h" />
<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\MemoryBitStream.cpp" />
<ClCompile Include="Src\OutputWindow.cpp" />
<ClCompile Include="Src\SocketAddress.cpp" />
<ClCompile Include="Src\SocketAddressFactory.cpp" />
Expand All @@ -392,8 +413,22 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">RoboCatPCH.h</PrecompiledHeaderFile>
</ClCompile>
<ClCompile Include="Src\Timing.cpp" />
<ClCompile Include="Src\UDPSocket.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\AllegroDeps.1.12.1\build\native\AllegroDeps.targets" Condition="Exists('..\packages\AllegroDeps.1.12.1\build\native\AllegroDeps.targets')" />
<Import Project="..\packages\Allegro.5.2.7.1\build\native\Allegro.targets" Condition="Exists('..\packages\Allegro.5.2.7.1\build\native\Allegro.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\AllegroDeps.1.12.1\build\native\AllegroDeps.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\AllegroDeps.1.12.1\build\native\AllegroDeps.targets'))" />
<Error Condition="!Exists('..\packages\Allegro.5.2.7.1\build\native\Allegro.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Allegro.5.2.7.1\build\native\Allegro.targets'))" />
</Target>
</Project>
35 changes: 35 additions & 0 deletions RoboCat/Inc/AckRange.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//typedef PacketSequenceNumber uint16_t;

class AckRange
{
public:
AckRange() : mStart( 0 ), mCount( 0 ) {}

AckRange( PacketSequenceNumber inStart ) : mStart( inStart ), mCount( 1 ) {}

//if this is the next in sequence, just extend the range
inline bool ExtendIfShould( PacketSequenceNumber inSequenceNumber );

PacketSequenceNumber GetStart() const { return mStart; }
uint32_t GetCount() const { return mCount; }

void Write( OutputMemoryBitStream& inOutputStream ) const;
void Read( InputMemoryBitStream& inInputStream );

private:
PacketSequenceNumber mStart;
uint32_t mCount;
};

inline bool AckRange::ExtendIfShould( PacketSequenceNumber inSequenceNumber )
{
if( inSequenceNumber == mStart + mCount )
{
++mCount;
return true;
}
else
{
return false;
}
}
117 changes: 117 additions & 0 deletions RoboCat/Inc/ByteSwap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@

#ifndef RoboCat_ByteSwap_h
#define RoboCat_ByteSwap_h

inline uint16_t ByteSwap2( uint16_t inData )
{
return ( inData >> 8 ) | ( inData << 8 );
}

inline uint32_t ByteSwap4( uint32_t inData )
{
return ( ( inData >> 24 ) & 0x000000ff ) |
( ( inData >> 8 ) & 0x0000ff00 ) |
( ( inData << 8 ) & 0x00ff0000 ) |
( ( inData << 24 ) & 0xff000000 );
}

inline uint64_t ByteSwap8( uint64_t inData )
{
return ( ( inData >> 56 ) & 0x00000000000000ff ) |
( ( inData >> 40 ) & 0x000000000000ff00 ) |
( ( inData >> 24 ) & 0x0000000000ff0000 ) |
( ( inData >> 8 ) & 0x00000000ff000000 ) |
( ( inData << 8 ) & 0x000000ff00000000 ) |
( ( inData << 24 ) & 0x0000ff0000000000 ) |
( ( inData << 40 ) & 0x00ff000000000000 ) |
( ( inData << 56 ) & 0xff00000000000000 );
}


template < typename tFrom, typename tTo >
class TypeAliaser
{
public:
TypeAliaser( tFrom inFromValue ) :
mAsFromType( inFromValue ) {}
tTo& Get() { return mAsToType; }

union
{
tFrom mAsFromType;
tTo mAsToType;
};
};


template <typename T, size_t tSize > class ByteSwapper;

//specialize for 1...
template <typename T>
class ByteSwapper< T, 1 >
{
public:
T Swap( T inData ) const
{
return inData;
}
};


//specialize for 2...
template <typename T>
class ByteSwapper< T, 2 >
{
public:
T Swap( T inData ) const
{
uint16_t result =
ByteSwap2( TypeAliaser< T, uint16_t >( inData ).Get() );
return TypeAliaser< uint16_t, T >( result ).Get();
}
};

//specialize for 4...
template <typename T>
class ByteSwapper< T, 4 >
{
public:
T Swap( T inData ) const
{
uint32_t result =
ByteSwap4( TypeAliaser< T, uint32_t >( inData ).Get() );
return TypeAliaser< uint32_t, T >( result ).Get();
}
};


//specialize for 8...
template <typename T>
class ByteSwapper< T, 8 >
{
public:
T Swap( T inData ) const
{
uint64_t result =
ByteSwap8( TypeAliaser< T, uint64_t >( inData ).Get() );
return TypeAliaser< uint64_t, T >( result ).Get();
}
};

template < typename T >
T ByteSwap( T inData )
{
return ByteSwapper< T, sizeof( T ) >().Swap( inData );
}

inline void TestByteSwap()
{
int32_t test = 0x12345678;
float floatTest = 1.f;

printf( "swapped 0x%x is 0x%x\n", test, ByteSwap( test ) );
printf( "swapped %f is %f\n", floatTest, ByteSwap( floatTest ) );
printf( "swapped 0x%x is 0x%x\n", TypeAliaser< float, uint32_t >( floatTest ).Get(), TypeAliaser< float, uint32_t >( ByteSwap( floatTest ) ).Get() );
}

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

#include "allegro.h"
#include "allegro_primitives.h"
#include <string>
#include <vector>

class CircleClass
{
public:
CircleClass(string name, int windowWidth, int windowHeight, int xStart, int yStart, float newRadius);
CircleClass();
void Read(InputMemoryBitStream& iStream);
void Write(OutputMemoryBitStream& oStream) const;
void Draw();
void UpdatePos(int xChange, int yChange);

string mName;
int mWindowWidth;
int mWindowHeight;
std::vector<int> position;
float radius;
};

void CircleClass::Read(InputMemoryBitStream& iStream)
{
iStream.Read(mName);
iStream.Read(position[0]);
iStream.Read(position[1]);
iStream.Read(radius);
}

void CircleClass::Write(OutputMemoryBitStream& oStream) const
{
oStream.Write(mName);
oStream.Write(position[0]);
oStream.Write(position[1]);
oStream.Write(radius);
}

void CircleClass::Draw()
{
al_draw_filled_circle(position[0], position[1], radius, al_map_rgb(0, 255, 0));
}

CircleClass::CircleClass(string name, int windowWidth, int windowHeight, int xStart, int yStart, float newRadius)
{
mName = name;
mWindowWidth = windowWidth;
mWindowHeight = windowHeight;
position.push_back(xStart);
position.push_back(yStart);
radius = newRadius;
}

CircleClass::CircleClass()
{
mName = "";
mWindowWidth = 100;
mWindowHeight = 100;
int xTemp = 0;
int yTemp = 0;
position.push_back(xTemp);
position.push_back(yTemp);
radius = 10;
}

void CircleClass::UpdatePos(int xChange, int yChange)
{
position[0] += xChange;
position[1] += yChange;
if (position[0] > mWindowWidth) position[0] = 0;
if (position[1] > mWindowHeight) position[1] = 0;
if (position[0] < 0) position[0] = mWindowWidth;
if (position[1] < 0) position[1] = mWindowHeight;
}
Loading