Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1957e40
add new code for assignment
sabarrett Feb 25, 2022
75a1ece
add allegro package, update gitignore
sabarrett Feb 25, 2022
3359377
remove unused code
sabarrett Feb 25, 2022
16ff55b
remove SDL
trobol Feb 25, 2022
3ef7d87
add raylib
trobol Feb 25, 2022
d7af19b
fix ray lib conflicts
trobol Mar 28, 2022
4edecbb
get sockets working
trobol Mar 28, 2022
1857f3d
Collisions and objects draw
GoGetAVegan Mar 28, 2022
8340ec8
merge
trobol Mar 28, 2022
88cefa0
add read and write functions for vec2
trobol Mar 28, 2022
0314041
Transform Struct
GoGetAVegan Mar 29, 2022
bd0c863
add tcp packet handling
trobol Mar 29, 2022
84b03a8
merge
trobol Mar 29, 2022
8b6adec
Two players can play the game
GoGetAVegan Mar 29, 2022
44af943
merge
trobol Mar 29, 2022
0772f67
most of networking stuff done, and some visual polish
trobol Mar 29, 2022
c7c8fdf
add more juice
trobol Mar 29, 2022
9a86978
add nicknames
trobol Mar 29, 2022
5a09713
remove packet logging
trobol Mar 29, 2022
1057a37
initial state for assignment 3
sabarrett Apr 1, 2022
e201259
adding juice
trobol Apr 1, 2022
0b2dbeb
even more juice
trobol Apr 12, 2022
4d02b67
merge assignment 3 code changes
trobol Apr 12, 2022
f0971fb
Putting global variables in a struct
GoGetAVegan Apr 12, 2022
f337141
fix compile errors and rename tcp stuff
trobol Apr 12, 2022
6964610
Cleaned up member functions for GameInit
GoGetAVegan Apr 12, 2022
a1117d7
switch to udp
trobol Apr 12, 2022
b0cb198
Merge branch 'assignment3' of https://github.com/trobol/SocketDemo in…
trobol Apr 12, 2022
5991ecf
fixing issue with address:
trobol Apr 30, 2022
13e37a5
add artificial lag
trobol Apr 30, 2022
8906562
add prediction and network graph
trobol Apr 30, 2022
0cbd642
reduce number of packets
trobol Apr 30, 2022
7cef237
improve prediction on blocks
trobol Apr 30, 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
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/
42 changes: 37 additions & 5 deletions RoboCat/Chapter3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
<ExceptionHandling>Sync</ExceptionHandling>
<AdditionalOptions> %(AdditionalOptions)</AdditionalOptions>
<PreprocessorDefinitions>WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;DEBUG;PROFILE;_WINDOWS;_WIN32_WINNT=0x0600;GRAPHICS_API_OPENGL_33;PLATFORM_DESKTOP;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<AdditionalIncludeDirectories>..\SDL\include;Inc;..\</AdditionalIncludeDirectories>
<PrecompiledHeader>Create</PrecompiledHeader>
<AdditionalIncludeDirectories>..\SDL\include;Inc;..\;..\raylib\include</AdditionalIncludeDirectories>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>RoboCatPCH.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<AdditionalDependencies>d3d11.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies);Ws2_32.lib</AdditionalDependencies>
<AdditionalDependencies>d3d11.lib;dxguid.lib;winmm.lib;comctl32.lib;%(AdditionalDependencies);Ws2_32.lib;raylib.lib</AdditionalDependencies>
<GenerateDebugInformation>true</GenerateDebugInformation>
<LargeAddressAware>true</LargeAddressAware>
<RandomizedBaseAddress>true</RandomizedBaseAddress>
Expand All @@ -141,6 +141,7 @@
<UACExecutionLevel>AsInvoker</UACExecutionLevel>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
<SubSystem>Console</SubSystem>
<AdditionalLibraryDirectories>..\raylib\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<Manifest>
<EnableDPIAwareness>true</EnableDPIAwareness>
Expand Down Expand Up @@ -370,30 +371,61 @@
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<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\NetworkManager.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\Packet.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\NetworkManager.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\Packet.cpp" />
<ClCompile Include="Src\TCPSocket.cpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Src\RoboCatPCH.cpp">
<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;
}
}
121 changes: 121 additions & 0 deletions RoboCat/Inc/ByteSwap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@

#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
72 changes: 72 additions & 0 deletions RoboCat/Inc/DeliveryNotificationManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

class DeliveryNotificationManager
{
public:


DeliveryNotificationManager( bool inShouldSendAcks, bool inShouldProcessAcks );
~DeliveryNotificationManager();

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

void ProcessTimedOutPackets();

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; }

private:



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 );


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

PacketSequenceNumber mNextOutgoingSequenceNumber;
PacketSequenceNumber mNextExpectedSequenceNumber;

deque< InFlightPacket > mInFlightPackets;
deque< AckRange > mPendingAcks;

bool mShouldSendAcks;
bool mShouldProcessAcks;

uint32_t mDeliveredPacketCount;
uint32_t mDroppedPacketCount;
uint32_t mDispatchedPacketCount;

};



inline InFlightPacket* DeliveryNotificationManager::WriteState( OutputMemoryBitStream& inOutputStream )
{
InFlightPacket* toRet = WriteSequenceNumber( inOutputStream );
if( mShouldSendAcks )
{
WriteAckData( inOutputStream );
}
return toRet;
}

inline bool DeliveryNotificationManager::ReadAndProcessState( InputMemoryBitStream& inInputStream )
{
bool toRet = ProcessSequenceNumber( inInputStream );
if( mShouldProcessAcks )
{
ProcessAcks( inInputStream );
}
return toRet;
}
33 changes: 33 additions & 0 deletions RoboCat/Inc/InFlightPacket.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class DeliveryNotificationManager;

//in case we decide to change the type of the sequence number to use fewer or more bits
typedef uint16_t PacketSequenceNumber;

class InFlightPacket
{
public:

InFlightPacket( PacketSequenceNumber inSequenceNumber );

PacketSequenceNumber GetSequenceNumber() const { return mSequenceNumber; }
float GetTimeDispatched() const { return mTimeDispatched; }

void SetTransmissionData( int inKey, TransmissionDataPtr inTransmissionData )
{
mTransmissionDataMap[ inKey ] = inTransmissionData;
}
const TransmissionDataPtr 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;

private:
PacketSequenceNumber mSequenceNumber;
float mTimeDispatched;

unordered_map< int, TransmissionDataPtr > mTransmissionDataMap;
};
Loading