EasyIP2023 / online-ping-pong

:sunglasses: Online Ping Pong Game :sunglasses:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Online Ping Pong

๐Ÿข License ๐Ÿข

Run times (Just because this was hackishly created):

  • Client Runtime: O(n)
  • Server Runtime: O(n^2)

Audio From: https://www.bensound.com

Note: This is more for proof of concept

Yes I am aware that I could just use UDP Packets with recvfrom(2)/sendto(2) and have my thread pool watch individual UDP packets, but this is more for representation of how epoll, TCP sockets, multiple processes, and a thread pool can be utilized in such a application.

This is an online ping pong game written in C for my Graduate Operating Systems course at the University of Texas at San Antonio. No I am not using lucurious or Vulkan as I am still learning Vulkan and still writing lucurious. Plus I read that SDL is a simple to learn and use API.

Dependencies

  • SDL2
  • SDL2_image
  • SDL2_ttf
  • SDL2_mixer

Online Ping Pong makes full utilization of

  • SDL2: For graphics
  • TCP Sockets: For connection oriented socket streaming. Clients and server read/write exactly 13 bytes of data. Applicaton will read/write player y coordinate data, termination boolean variable, and the ball's x and y coordinate data (the initial player updates balls position).
  • Epoll: To better manage an array of open file descriptors to see which one is ready for read/write operations.
  • Non-Blocking I/0: All fd's are set into non-blocking mode, so that file descriptors don't have to wait for unix/linux system calls like read(2)/write(2) to finish.
  • Thread Pool: Queue's up task/work for threads to execute. I usually like to make the number of threads equal to the same number of CPU Cores - 1 (Main process is a thread). Helps with resource thrashing don't want to waste time in context switching between threads. Also helps with decreasing thread scheduler overhead. The more threads you have the higher the overhead for the thread scheduler is. You also don't want too many threads blocking becuase of I/O operations, this leaves too many threads idle.
  • If Statements: Bool functions final returns are not the same, so if statement checks vary from function to function. ๐Ÿ˜œ ๐Ÿ˜…

Installation/Usage

git clone https://github.com/EasyIP2023/online-ping-pong.git
mkdir -v build
meson build
ninja -C build
sudo ninja install -C build
# Server
online-ping-pong --port 8080 --server

# Client
online-ping-pong --ip 127.0.0.1 --port 8080 --client

Running Test

ninja test -C build/

References

About

:sunglasses: Online Ping Pong Game :sunglasses:

License:MIT License


Languages

Language:C 88.9%Language:HTML 6.8%Language:Meson 3.6%Language:Shell 0.7%