Gods Sine Table Format

From ModdingWiki
Jump to navigation Jump to search

SINCOS.DAT is a sine lookup table used by Gods for circular and curved enemy movement. It is one of the few data files that is not compressed.

File format

The file is 1280 bytes: 640 signed big-endian 16-bit values.

Data type Name Description
INT16BE[512] sine One full sine wave: entry i = sin(i × 2π / 512) × 32767, rounded (entries may be off by 1 or 2)
INT16BE[128] tail Not used, see below

The table has 512 steps per full circle, so a quarter circle is 128 entries (256 bytes). The game gets the cosine from the same table by reading 256 bytes further on: cos(i) = sine[i + 128].

The last 256 bytes of the file contain small unrelated values. The game does not use them: after loading the file it overwrites them with a copy of the first 128 entries, so that sine[i + 128] works for every angle up to 511 without wrapping.

The game typically scales the result down by shifting it right 10 bits, giving a range of about ±32.

Source code

From re-gods, the open-source HTML5 port:

Credits

This file format was reverse engineered by VorticonCmdr. If you find this information helpful in a project you're working on, please give credit where credit is due. (A link back to this wiki would be nice too!)