Pong Game triggers game over immediately on MAC OSX

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Pong Game triggers game over immediately on MAC OSX

intractablehero
Hello,

I just finished Ch. 11 and passed all tests, however, when I run the Pong game in the VMEmulator on my Mac OSX (Monterey 12.4, Intel I7), game over is triggered immediately and a score of 1 is shown. I didn't get a chance to move the bat.. in 'no animation' mode game over is shown as soon as I click run.

I ran the exact same code on Linux, and the game works fine. Also, I noticed that translating the .jack code using the supplied JackCompiler tool resulted in the same behaviour; on my MAC, game over triggered immediately.

I wondered if the game was simply running 'too fast' on my Mac, and added a "do Sys.wait(50);" command at the very end of the Ball.move() method in Ball.jack. This fixed the issue!

I don't know enough about the source code, or differences in JRE on MAC/Linux, but is it possible there is such a speed difference when running the VMEmulator on Mac? I'm currently using Java SE Runtime Environment 18.0.1.1+2-6.

This post is mostly for curiosity, since my fix worked well enough to solve my problem. Just thought I'd let the community know and also hope someone more knowledgeable can answer my question. If there is a way to ensure consistent behaviour across OS's that would be good, since I plan on teaching from this textbook next year, and my students use different OS's.

Thanks!

ps - great book! Love it.
Reply | Threaded
Open this post in threaded view
|

Re: Pong Game triggers game over immediately on MAC OSX

WBahn
Administrator
That seems quite possible. In the early days of personal computers, nearly all machines ran at 4.77 MHz (that was a frequency that was easily derived from cheap television crystals). Because of the extreme limitation in both speed and memory, game makers relied heavily on delay loops to control timing and this worked well enough since most machines ran at the same clock speed. But then speeds started to increase and games ran too fast to play (as did other applications that either played this same timing game or that merely tried to run as fast as the machine allowed). This led to "Turbo" mode, which was a switch on the front of the machine that let the machine run at its normal speed -- in non-turbo mode, the system clock was reduced to 4.77 MHz so that affected legacy code could run properly.

Today, most code that has timing/speed sensitivities use operating system calls to control the speed to a consistent level. My guess is that VM emulator code for the MAC didn't get this done correctly.
Reply | Threaded
Open this post in threaded view
|

Re: Pong Game triggers game over immediately on MAC OSX

intractablehero
Thank you!

-Robert