Thursday, 18 February 2016

Low-Level Programming_Post16

Low-Level Programming: Post 16 18/02.2016

February 18th 2016 is the date of the sixteenth lesson on Low-Level Programming.

In today's lesson, we (sort-of) went back to the normal routine of the theoretical part of the lesson and the practical side of the lesson. Although it was mostly practical based, there were still some lesson slides to have a look at. Below are the main points taken from the lesson...

  • Networking: How to handle disconnected or slow clients.
  • Threading: Basic principles of threading.
  • Dungeon Death: Continue working on the client development.
Connections

Disconnections
  • Client: How should we handle client disconnections?
  • Heartbeat Monitoring: One option is to continually poll the clients and see if they respond. This is known as heartbeat monitoring. i.e. listening for a heartbeat.
  • On Demand: Maybe we could perform the check only when we want to send data, but this can cause delays in the thread and means we have stale sockets.
  • Messages: The best approach is to get the client to send a disconnect message to the server, indicating when it’s disconnected. Then the server can remove the connection.
  • SF: The SFML library also sends a disconnected message as well. This can be used to detect disconnections by clients.
Pings/Latency
  • Latency: As discussed before, the latency refers to the delay in data being sent and received between two hosts.
  • Ping: The ping is the amount of time it takes to send a message and receive a response. This is an easy to measure value.
  • On Demand: Clients with high latency should be disconnected in games where real-time updates are essential, as they can negatively impact all users experience.
Ping in Action
  • Ping: Save the start time and send message to the server. This is the ping. The server will respond will reply with a pong response.
  • Pong: When that pong arrives at the client side we can calculate the difference i.e. 𝑑𝑢𝑟 = 𝑒𝑡 − 𝑠t.

Once we finished the 'Connections' based slides, we started to work on our first practical session of the lesson. 

In this session, we were given the complete set-up of the Chat Client and Chat Server project that we have been working on for the past few weeks. We then had to add some components into the project (some snippets were provided). However, at the start of the project, the lib files were incorrect (they didn't match with each other), so after the tutor helped me to fix the problem, I was than able to start working on the task at hand. Initially, it was going fine, where I thought I put the code in the correct place(s). However, due to an error in the network system at the University, I couldn't properly run the program. Despite this, however, I still had some code missing from my project, as the tutor than showed us the solution to connect the two together.

Once the first practical was finished, we than went back to the theoretical side of the lesson.

Threading

Threading
  • What is it?: Threading is the execution of parallel tasks running outside of a single point of execution.
  • Why?: Modern day CPU architecture is completely based around the ideal of using multiple CPU cores running unique tasks at the same time.
  • Multi-Threaded: Programs that utilise this type of technology are often known as being ‘mutithreaded’. In this modern day of development, you can’t get away from working with threads.
Multi-Core
  • Why?: The interesting thing about modern day CPUs is that they often run at a slower clock speed than their counterpart from a decade ago.
  • From GHZ To Cores: Unfortunately, increases in GHz became prohibitive due to the amount of additional electrical power required to power them.
  • Parallel: By using multiple cores on one CPU die, but running them at a slower clock speed, the CPU’s became more efficient and less susceptible to these issues. However, now we need to communicate between the cores to unlock their potential.
  • CPUS: Modern day CPU dies are normally constructed from more than one core. Quad core is fairly common place.
  • Cache: These cores tend to have a small dedicated high speed cache and a slower but bigger shared one.
SFML Disconnections
  • Contention: Remember that there can be issues of contention where large data is shared between CPU cores.
  • Coherency: The hardware will maintain the caches for each core. However, this can cause necessary performance loss.
  • Fences: Memory fences can be used to pause execution until values have been written, thus ensuring order.
The Problem
  • Single Threaded Game Loop: Traditionally, we break the engine into sub tasks, run them in order and rinse and repeat.
  • Sequential: This approach was fine before the use of multi-core CPUs, but on a modern day system this would leave all the other x number of cores unused.
Subsystem Threads
  • Simultaneous Actions: Often our game loop is busy polling for actions or inputs from various subsystems. Whilst we poll for these system events, the execution is blocked, until we receive a response.
  • Asynchronous: Let’s consider an approach when we run specific tasks asynchronously i.e. in another independent thread.
  • Candidates:
  1. Network Messages.
  2. Input Polling.
  3. Event Processing.
  • Shared Data: It’s also important to establish the relationship between data being shared and modified by threads.
Pipelining
  • Pipeline Parallelism?: Running two parts of the same pipeline in synchronised threads. This is known as lockstepping. i.e. we need the first part to finish before the second starts.
  • Graphics: The graphics rendering can be started on a different thread, as long as the update of game logic has been completed.
Semaphore
  • Render: The semaphore (our concurrent object) count is increased when the engine update is completed and the decreased once the render phase is over.
  • Engine: It’s good practice to have a semaphore in the opposite direction to stop the engine’s update getting too far ahead of the rendering phase.
Fork & Join
  • What is it?: Divide a unit of work into smaller subunits, distribute (fork) these workloads to multiple threads and merge the result of all the workloads (join).
  • Animation Blending: Animations are blending using skeleton poses. The LERP process can be completed on each joint independently.
After finishing the theoretical side of the lesson, we then moved onto the second practical of the session. Unfortunately, due to the problems with the networking (as mentioned earlier in this post), I was unable to download the ZIP file provided to us from 'tinyURL', thus unable to work on the tutorial. Because of this, we were allowed to finish the lesson early.

No comments:

Post a Comment