Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Game logic

Name: Anonymous 2010-05-16 5:18

How the fuck do they code games so that everything moves smoothly and at a consistent rate regardless of the speed of the machine you run it on, and still have tons of shit interacting with each other somehow?
Maybe I need to find a good open-source candidate to have a look at.

Also, I wish I knew the correct terms to describe what I'm talking about.

Name: Anonymous 2010-05-19 1:45

>>39
QueryPerformanceCounter is probably your best bet. No method is perfect though. rdtsc is a terrible idea that won't work at all: modern CPUs have variable clocks, and on top of that each core might have its own desynchronized counter. A lot of rdtsc-based stuff (mostly games) broke in recent years because of this.

Now, this is something that no soul should ever have to see, but behold: https://hg.mozilla.org/mozilla-central/file/f8a47845a0b8/js/src/prmjtime.cpp

Please see bug 363258 for why the win32 timing code is so complex.
 
     calibration mutex : Win32CriticalSection(spincount=0)
     data mutex : Win32CriticalSection(spincount=4096)
    
     def NowInit():
       init mutexes
       PRMJ_NowCalibration()
    
     def NowCalibration():
       expensive up-to-15ms call
    
     def PRMJ_Now():
       returnedTime = 0
       needCalibration = False
       cachedOffset = 0.0
       calibrated = False
       PR_CallOnce(PRMJ_NowInit)
       do
         if not global.calibrated or needCalibration:
           acquire calibration mutex
             acquire data mutex
    
               // Only recalibrate if someone didn't already
               if cachedOffset == calibration.offset:
                 // Have all waiting threads immediately wait
                 set data mutex spin count = 0
                 PRMJ_NowCalibrate()
                 calibrated = 1
    
                 set data mutex spin count = default
             release data mutex
           release calibration mutex
    
         calculate lowres time
    
         if highres timer available:
           acquire data mutex
             calculate highres time
             cachedOffset = calibration.offset
             highres time = calibration.last = max(highres time, calibration.last)
           release data mutex
    
           get kernel tick interval
    
           if abs(highres - lowres) < kernel tick:
             returnedTime = highres time
             needCalibration = False
           else:
             if calibrated:
               returnedTime = lowres
               needCalibration = False
             else:
               needCalibration = True
         else:
           returnedTime = lowres
       while needCalibration
    

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List