1 / 12

Week 2: Asynchronous Architecture

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

fathi
Download Presentation

Week 2: Asynchronous Architecture

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week 2: Asynchronous Architecture Game Loop Design

  2. 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

  3. 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

  4. 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.

  5. Asynchronous ArchitectureStandard Thread API • CreateThread() • StartThread() • KillThread()

  6. 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

  7. 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

  8. 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);

  9. 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

  10. 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

  11. Asynchronous ArchitectureAtom • Cross process data • Simple string • Persists after process shutdown • Process crash can leave data in bad state

  12. Asynchronous ArchitectureSemaphores • Named Semaphores • Use across process boundaries • Better than Atom for use as a Mutex

More Related