A 3D racing game for casio PRIZM calculators - a fork from https://github.com/duarteapcoelho/prizm_racing
Go to file
duarteapcoelho 9cff8bfdcb
Add MIT license
2022-11-11 23:32:18 +00:00
prizm Improve build system, add model and icon sources 2022-11-11 22:03:24 +00:00
resources Add more information to README 2022-11-11 22:46:52 +00:00
sdl Improve build system, add model and icon sources 2022-11-11 22:03:24 +00:00
src Improve build system, add model and icon sources 2022-11-11 22:03:24 +00:00
.gitignore Improve build system, add model and icon sources 2022-11-11 22:03:24 +00:00
LICENSE Add MIT license 2022-11-11 23:32:18 +00:00
Makefile Improve build system, add model and icon sources 2022-11-11 22:03:24 +00:00
README.md Add more information to README 2022-11-11 22:46:52 +00:00

README.md

prizm_racing

A 3D, multiplayer racing game for casio fx-CG50 calculators

Pictures

Picture 1 Picture 2

Features

  • 3D graphics
  • Simple multiplayer (just connect two calculators)
  • Runs at 14 FPS normally and 21 FPS overclocked, on the fx-CG50.

Controls

  • Press up/8 to accelerate and down/5 to brake
  • Press left/4 and right/6 to turn
  • Press menu to exit
  • If you return from the menu, press any key to continue playing
  • Tip: if you use left and right to turn and 8 to accelerate, you can turn while accelerating

Notes/Bugs

  • In multiplayer, each player sees the other car behind where it really is, so it's possible that both players see themselves finish first.
  • For multiplayer to work, both calculators must be running at the same frequency (if you overclock one, you must overclock both).
  • The car's movement isn't totally independent from framerate, so it may be a bit more or less slippery if you're overclocking or underclocking.
  • This game also works on casio fx-CG20 calculators, but it's too slow (at least without overclocking).
  • Running this game might cause file transfer to stop working. To fix this, reset the calculator by pressing the button on the back or removing and re-inserting a battery. This doesn't delete any files.
  • If you connect the cable while one calculator is in the menu, it might start trying to receive data. To avoid this, only connect the cable while the game is running on both calculators).

How to build

Linux

  • Either set up the Prizm SDK (PrizmSDK Setup Guide)
  • Set the FXCGSDK environment variable to where you installed libfxcg (export FXCGSDK=...), or put the prizm_racing directory in libfxcg/projects/prizm_racing.
  • Run make prizm
  • If you want to compile the SDL version (used for testing), install sdl2 and sdl2-ttf and run make sdl. The binary will be in sdl/racing, but it must be run from the prizm_racing directory (with sdl/racing)

Windows

Technical information

3D rendering

  • All the rendering code is in src/rasterizer.h and src/rasterizer.cpp
  • Every triangle is clipped to avoid drawing triangles outside the screen. If a triangle is only partially inside the screen, it's cut in one or two triangles. This doesn't happen with the cones and the car to improve performance.
  • The triangles are rasterized using the scan line algorithm with a depth buffer.
  • This renderer only supports diffuse directional lighting, because this way there is only one color per triangle, which increases performance.
  • Because the calculator doesn't have a floating point unit (FPU), everything related to rendering uses fixed point numbers (defined in src/fp.h). This caused some issues related to precision, most of which were solved by checking where the floating point calculations were overflowing.
  • To improve performance, the cones that are too far away from the camera are replaced with a simpler model and the ones even further away aren't drawn at all.

Potential rendering performance improvements

  • Use DMA to clear the screen
  • Draw the grass without using the 3D renderer (maybe using DMA)
  • Clip models before clipping triangles

Multiplayer

All of the multiplayer code is in src/main.cpp

  • When the game starts, a second car is created outside the track.
  • Every frame, each calculator sends its car data (position, direction, etc.) to the other one over the 3-pin cable
  • If the calculators are connected, the other one receives the data and updates its enemyCar.
  • Otherwise, the enemy car doesn't move, and stays outside the track.
  • To synchronize the byte stream, each byte of data sent is in this format: 0 0 0 X A B C D, where X is 1 if it's the first byte sent in a frame, and A B C D are four bits of car data.

Lag

Improving this would be possible by synchronizing both calculator's clocks to measure the delay, and then trying to predict where the other car will be that time in the future, but I think it's better to keep the multiplayer simple.