summaryrefslogtreecommitdiff
path: root/apps/plugins/xracer/README
blob: 8b6312c5f9080df69a11bf099dc40262e65b6858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
This file contains some quick notes about this plugin.
======================================================

Some useful links:
------------------

<http://codeincomplete.com/projects/racer/> - a very good tutorial on building a similar game in Javascript

<http://www.extentofthejam.com/pseudo/> - excellent page on pseudo-3d

Terminology:
------------

In the code, a "fixed-point" number is one that has a nonzero number of fractional bits.
When dealing with these numbers, you must be careful to convert all operands to fixed-point, and use the correct function/macro to replace the operators.
In the code, I've tried to make all fixed-point numbers of type 'long.'
An "integer" is a number with zero fractional bits.

(NOTE: I'm not sure if this "proper" terminology)

Code structure:
---------------

generator.c: random map generator

graphics.c: this is where almost all of the rendering takes place

main.c: main loop

sprite.c: static sprite data (offsets, dimensions)

util.c miscellaneous functions, also contains FOV calculation code

Proposed map formats:
---------------------

There will be two map formats: one that can be compiled into the executable ("Internal format"), and one that can be loaded from a file ("Interchange format").

Internal format:
----------------

This format is represented as a series of struct road_section's.

struct road_section {
    uchar type;
    uint32 len;
    int slope;
    long curve; // <<< this is fixed-point with 8 fracbits
};

'type' can be any of the following:
 0: constant segment - all 3 parameters used
 1: up-hill - an up hill is added. actual length is len + 2*slope due to enters and exits
 2: down-hill - a down hill is added. actual length is len + 2*slope due to enters and exits

Endianness is platform-dependent in the Internal format.

Interchange format:
-------------------

NOTE: all numbers are BIG-ENDIAN unless otherwise specified!

This format is essentially the Internal format serialized into a file, but with some minor differences.

File extension: .xrm

Current format version number: 0x0000

- File header - 8 bytes
  - 0x00-0x04: 'XMaP'
  - 0x05-0x06: version number (see above)
  - 0x07-0x08: 0xFF padding
- Data blocks - 15 bytes each (corresponds to the "sections" of the Internal format)
  - 0x00     : type
  - 0x01-0x04: length
  - 0x05-0x08: slope (signed two's complement)
  - 0x09-0x0C: curve (signed two's complement, fixed-point with 8 fractional bits)
  - 0x0D-0x0E: CRC16-CCITT of data from 0x0-0xC
  - 0x0F     : CRC high byte XOR CRC low byte