CmdSpaceship was a course I taken in Parallel Processing course with threads in Linux, now fully rewrite using C++ thread library and winsock2. Originally only support nthreads (Input thread and Logic thread), now input are communicating via winsock2 layer.
This project should be in a working state locally (Please do expecting crashes)
- Open server first.
- Open client later.
- AD to move, W to shoot.
- Shoot bullet and dodge enemy's bullet.
- It has been only run via localhost, as due to lack of machines.
- Less desirable class architecture. Would be better with event dispatcher. (I was unable to find more on std::function and std::bind with templated varadic arguments)
- Local Authoritative hit detection. Simulated bullet might not sync with the actual bullet position.
- Unoptimized for loops, as they deteriorate when the pool increases. However, profiler didn't pick this up.
- No post-game reset game loop.
- Threads seems to lagging sometimes. (Profiler picks up on TaskSend())
-
"kbhit()" and "getch()" is somehow cannot be run on std::thread. Initially it freezed almost completely, take more than 2 seconds to render one page of ternimal characters. Moving that to main thread stop the data stalls.
-
std::mutex doesn't work if it is interact with something not in std::thread. Multiple crashes and fixed couple of them
-
Chrono doesn't seems very realible. Works with unoptimization off, doesn't work in optimization on. Replaced with Sleep(20) instead and position syncing is more realible locally. (100% not on remote machine)
- To familiar with const char* manipulation, usually seen in Network codes or Game codes.
- Threading, network code learning, as well as C++11,14,17 syntax.
- Learn to profiling and adjust codes.
The winsock2 part I take references from :
https://docs.microsoft.com/en-us/windows/win32/winsock/complete-server-code
https://docs.microsoft.com/en-us/windows/win32/winsock/complete-client-code