week 2 asynchronous architecture
Download
Skip this Video
Download Presentation
Week 2: Asynchronous Architecture

Loading in 2 Seconds...

play fullscreen
1 / 12

Week 2: Asynchronous Architecture - PowerPoint PPT Presentation


  • 102 Views
  • Uploaded on

Week 2: Asynchronous Architecture. Game Loop Design. Asynchronous Architecture Synchronous Loop. Quick prototype Complicated simulation code FPS bound Input lags with renderer Non-discrete Physics Only option when not threading Some cell phones & gaming systems

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Week 2: Asynchronous Architecture' - fathi


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
asynchronous architecture synchronous loop
Asynchronous ArchitectureSynchronous Loop
  • Quick prototype
  • Complicated simulation code
    • FPS bound Input lags with renderer
    • Non-discrete Physics
  • Only option when not threading
    • Some cell phones & gaming systems
    • New O/S’s may have buggy threading
asynchronous architecture asynchronous loop
Asynchronous Architecture Asynchronous Loop
  • Extra setup required
  • Simplifies Sim via discrete data
    • Input always represents same delta time
    • Simulation run at specific time deltas
  • Performance lost to critical sections
  • Can use multiple cores
asynchronous architecture thread basics
Asynchronous ArchitectureThread Basics
  • Priority (Normal, Above, High,…)
    • Extreme Caution:

Higher order threads must sleep/wait in order for lower order threads to execute.

  • Leaving thread kills it.
    • Desired: Sit thread in a “Wait Event” loop.
    • Brute Force: Use sleep(1);
  • ThreadID used to kill it from another.
asynchronous architecture standard thread api
Asynchronous ArchitectureStandard Thread API
  • CreateThread()
  • StartThread()
  • KillThread()
asynchronous architecture standard thread use
Asynchronous ArchitectureStandard Thread Use
  • Creating thread does not start it.
    • Set Priority (default = normal)
    • Specify Callback (the thread code)
  • StartThread() returns immediately
    • Thread is entered some time later.
  • Returning from the thread kills it.
    • Can force kill it from another thread
    • Normally sit in a “Wait for Event” loop
asynchronous architecture timer thread use
Asynchronous Architecture Timer Thread Use
  • Essentially a standard thread
    • Sits in a Wait event with a timeout
    • Executes your callback (unless kill raised)
  • Thread called at specified frequency
  • Must kill the thread using ThreadID
asynchronous architecture timer thread sample
Asynchronous Architecture Timer Thread Sample
  • const UINT HZ_32 = 1000/32;
  • timerID= timeSetEvent(
    • HZ_32, HZ_32/2, // freq & resolution
    • TimerThread, // static callback
    • (DWORD_PTR)this, // UserData
    • TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
  • timeKillEvent(timerID);
asynchronous architecture cross thread data access
Asynchronous ArchitectureCross Thread Data Access
  • volatile
    • Keyword forces compiler to skip optimizations and read var from RAM.
  • Mutex (Mutually Exclusive)
    • Reference counting object that tracks current thread owner.
  • InterlockedIncrement/Decrement
    • Inc & store
    • One CPU operation, no Mutex required
asynchronous architecture signals
Asynchronous ArchitectureSignals
  • Event
    • Raised setEvent( hEvent );
    • Not Raised resetEvent( hEvent );
  • WaitEvent( hEvent, TimeOut)
    • Used in a while() loop
    • Sleeps thread until event raised or timeout
asynchronous architecture atom
Asynchronous ArchitectureAtom
  • Cross process data
    • Simple string
  • Persists after process shutdown
  • Process crash can leave data in bad state
asynchronous architecture semaphores
Asynchronous ArchitectureSemaphores
  • Named Semaphores
    • Use across process boundaries
    • Better than Atom for use as a Mutex
ad