A simulation project for Distributed Computing (STDISCM) course. This is the third iteration and is our final project. This involves simulating particles in a 2D space with elastic collisions. The developer server must be able to add particles to the simulation. The simulation must be able to calculate the collisions between particles and screen edges. Clients connect and move around the simulation space in a zoomed up screen and can also see each other. They can also disconnect and connect again at any time, however, only up to three (3) existing clients as a limitation.
The server acts as a state checker that all clients will follow. Essentially, the program runs and computes on both server and client, but the client tries to refresh based on the server's current state to stay synced up with other clients and the server itself. Made with nonblocking UDP sockets.
The Server and Client communicate with each other using a custom message passing protocol.
<c>uid,x,y</c>
- New client connection with uid and position x, y<m>uid,x,y,dirX,dirY</m>
- Move client with uid to x, y with direction dirX, dirY<p>x,y,angle,velocity</p>
- Add particle to the simulation with position x, y, angle and velocity<b>1,num,startX,endX,startY,endY,angle,velocity</b>
- Particle batch method 1<b>2,num,startAngle,endAngle,startX,startY,velocity</b>
- Particle batch method 2<b>3,num,startX,startY,angle,startVelocity,endVelocity</b>
- Particle batch method 3<r>either <p> or <b> message</r>
- (Used in client loader) load particle history record
- A client connects to the server with #1, and the server returns #7 that contains #3 or #4 or #5 or #6, depending on if particles were added before client joined the simulation. Otherwise, just sends "DONE".
- A client moves with #2. It updates its position in the server and direction if it is moving. It only sends if the client's direction changes.
- Whenever server adds a particles, it sends #3, #4, #5, or #6 to all clients.
The clients calculate the particle movements and player movements. The server simply acts as a relay for the clients.
When a client joins the server late, the server sends the client the particle history record. The client then simulates the particles from the last known state. This is because the history records contains record logs with time taken since the previous record. The client can simulate this by running the simulation with delta 1 the same number of seconds as the simulation's runtime.
Whenever a client moves, the client sends the server the new position and direction. The server then sends this information to all clients. The clients then update that player's position and direction. Should be noted that it is not always sending as it is moving. It only sends when it changes direction (e.g.: player starts moving up, or player stops moving) meaning a player can hold a direction and only send information if it stops holding. Same as if player presses once. To accommodate latency or movement calculation mismatch, the current position of the player is also sent. Therefore, if a player stops moving or changes direction, it will move the player to that spot.
- Clone the repository
git clone --recurse-submodules https://github.com/erik-lance/Particle-Simulator-v3.git
- Go to
Server-Developer
folder and make sure thevcpkg
folder has files.- If it does not have files, you can clone
https://github.com/microsoft/vcpkg.git
in theServer-Developer
folder.
- If it does not have files, you can clone
- Go to
CMakeLists.txt
and hitCTRL+S
to automatically start downloading the required packages. - Run the project with
CMakeLists.txt
as the startup file.
- Open the project in IntelliJ IDEA.
- Build the project in Maven
- Run the project with
Main.java
as the main class.
- Open the folder
Client-Explorer
in Visual Studio Code. - Run the project with
Main.java
as the main class. Note: You may need to install the Java Extension Pack in Visual Studio Code. See instructions at (Client-Explorer-README)[https://github.com/erik-lance/Particle-Simulator-v3/blob/master/Client-Explorer/README.md].
Otherwise, you can also simply open the Client-Explorer.jar
found under Client-Explorer/
.