Giter Club home page Giter Club logo

online-ping-pong's Introduction

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

online-ping-pong's People

Contributors

easyip2023 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

manishbajpai

online-ping-pong's Issues

Font Updates

Updating the font needs to be more efficient.

Possible client.c rewrite

fork a new process and have one process update the screen while the waits for user input.

Much better approach then what I'm doing

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.