1 /*---------------------------------------------------------------------------*
2 Project: Dolphin/Revolution gx demo
3 File: ind-tile-data.c
4
5 Copyright 1998-2006 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12 *---------------------------------------------------------------------------*/
13
14 #include <demo.h>
15
16 /*---------------------------------------------------------------------------*
17 Defines
18 *---------------------------------------------------------------------------*/
19 #define WIDTH_LYR1 128
20 #define HALF_WIDTH_LYR1 64
21 #define HMASK_LYR1 127
22 #define HSHIFT_LYR1 7
23 #define HEIGHT_LYR1 64
24 #define HALF_HEIGHT_LYR1 32
25 #define VMASK_LYR1 63
26 #define VSHIFT_LYR1 6
27
28 #define TILE_WIDTH_LYR1 32
29 #define TILE_HSHIFT_LYR1 5
30 #define TILE_HEIGHT_LYR1 32
31 #define TILE_VSHIFT_LYR1 5
32
33 #define WORLD_WIDTH (WIDTH_LYR1 * TILE_WIDTH_LYR1)
34 #define WORLD_HEIGHT (HEIGHT_LYR1 * TILE_HEIGHT_LYR1)
35
36 #define NUM_TILES_LYR1 95
37
38 /*---------------------------------------------------------------------------*
39 Global Variables and Data
40 *---------------------------------------------------------------------------*/
41
42 typedef struct
43 {
44 f32 rPosX; // Position vector X component (measured in tile coordinates)
45 f32 rPosY; // Position vector Y component (measured in tile coordinates)
46 f32 rOriX; // Normalized orientation vector X component
47 f32 rOriY; // Normalized orientation vector Y component
48 } G2DPosOri; // 2D Position and Orientation
49
50 extern G2DPosOri poShip;
51
52 GXTexObj toTilesRGB_1;
53
54 GXTexObj toTileMap_1;
55
56 static u8 tmap1[WIDTH_LYR1 * HEIGHT_LYR1] ATTRIBUTE_ALIGN(32);
57
58 static u8 map1[WIDTH_LYR1 * HEIGHT_LYR1] =
59 {
60 "6aT..............46a..............P.13jTPEIOL0LT..1222222222DC222222222223j......P.4C2222222222222223j1222222222222222DC2222222D"
61 "6aT..............13j..............P.dfiTPK0KHJGSV.decccccccco6bcccccccccchi......P.46bcccccccccccccchidecccccccccccccco6bcccccco"
62 "6aT..............dfi..............XNNNNWPHIG0EIOT...........46a............../0/.P.46a...79n.....................79n..46aMNNNO.4"
63 "6aT.....................................XOEJFK0KT...........46a..79n......../0/0/P.46a...4Bp888;<=++>?()++,-:8888A6m..13jT...P.4"
64 "6aT......................................PL0LHIGT...........46a.7ABqn.......0/0/0P.46a...4C2222yz{uu|}@tuuvwx2222D6a..dfiT...P.4"
65 "6aT......................................PHJGMNNW...........46a.1DC3l......./0/0/P.46a...13gcccccccccc_`cccccccccr3jMNNNNW...P.4"
66 "6aT......................................XNNNW..............46a.dr3si......../0/.P.46a...dfiMNNNNNNNNNNNNNNNNNNO.dfiT........P.4"
67 "6aT.........................EF..............................46a..dfi.URRRRRRRRRRRQ.46aMNNNNNW..................XNNNNW........P.4"
68 "6aT.......................EIGK..............................46a......P.............46aT......................................P.4"
69 "6aT.......................HJIG...........URRRRRV............13j......P.788888888888A6aT.............................URRRRV...P.4"
70 "6aT......................................P.....T............dfi......P.4C222222222223jT.............................P....T...P.4"
71 "6aT......................................P.789nT..........URRRRRRRRRRQ.46bcccccccccchiT....................URV......P.79nT...P.4"
72 "6aT......................................P.456mT..........P............46aMNNNNNNNNNNNW...................UQ0SV.....P.46mT...P.4"
73 "6aT......................................P.456aT..........P.78888888888A6aT.....................URV.......P0/0T.....P.46aT...P.4"
74 "6aT.................................URRRRQ.456aSRRRRV.....P.4C22222222223jT....................UQ0SV......XO0MW.....P.46aT...P.4"
75 "6aT.................................P......456a.....T.....P.46bccccccccchiT....................P0/0T..URV..XNW......P.46aT...P.4"
76 "6aT.................................P.78888A5Bp8889nT.....P.46aMNNNNNNNNNNW....................XO0MW.UQ0SV..........P.46aT...P.4"
77 "6aT...................0.0.0.0.0.....P.4555555555556mT.....P.13jT................................XNW..P0/0T..........P.46aT...P.4"
78 "6aT.................................P.12222D5C22223jT.....P.dfiT.....................................XO0MW..........P.46aT...P.4"
79 "6aT...................0.0.0.0.0.....P.deccco56bccchiT.....P....T......................................XNW...........P.46aT...P.4"
80 "6aT.................................XNNNNO.456aMNNNNW.....P.79nT....................................................P.46aT...P.4"
81 "6aT...................0.0.0.0.0..........P.456aT..........P.46mT.......................................URV..........P.46aT...P.4"
82 "6aT......................................P.456aT..........P.46aT......................................UQ0SV.........P.46aT...P.4"
83 "6aT...................0.0.0.0.0..........P.123jT..........P.46aT......................................P0/0T.........P.46aT...P.4"
84 "6aT......................................P.dehiT..........P.46aT......................................XO0MW.........P.46aT...P.4"
85 "6aT...................0.0.0.0.0..........XNNNNNW..........P.46aT.......................................XNW..........P.46aT...P.4"
86 "6aSRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRQ.46aT....................................................P.46aT...P.4"
87 "6a..........................................................46aT.URRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRV..........P.46aT...P.4"
88 "Bp888888888888888888888;<=++>?!n.... ()++,-:8888888888888888A6aT.P0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0T..........P.46aT...P.4"
89 "C2222222222222222222222yz{uu|}$%....#@tuuvwx222222222222222223jT.P/...................................../T..........P.46aT...P.4"
90 "6bcccccccccccccccccccccccccccc_'....d&`cccccccccccccccccccccchiT.P0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0T........URQ.46aT...P.4"
91 "6aMNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNW.XNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNW........P...46aT...P.4"
92 "3jT...............................................................................................................P.78A6aT...P.1"
93 "fiT...............................................................................................................P.1223jT...P.d"
94 "NNW..............................................................................URRRRV...........................P.dechiT...XNN"
95 ".................................................................................P....T...........................XNNNNNNW......"
96 ".................................................................................P.79nT........................................."
97 ".................................................................................P.46mT........................................."
98 ".................................................................................P.46aT...........URRRV........................."
99 "...............................URRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRV................P.46aT........URRQEJFT...........URRRRRRV......"
100 "RRV............................P................................SRRRRRRRRRRRRRRRRQ.46aT........PEIOL0LT...........P......T...URR"
101 "..T............................P.788888888888888888888888888889n...................46aT........PK0KHJGSV..........P.7889nT...P.."
102 "9nT............................P.1222222222222222222222222222DBp888;<=+>?()+,-:8888A6aT........PHIG0EIOT..........P.12D6mT...P.7"
103 "6mT..............79n...........P.deccccccccccccccccccccccccccoC2222yz{u|}@tuvwx222223jT........XOEJFK0KT..........P.deo6aT...P.4"
104 "6aT...........79n13l79n........XNNNNNNNNNNNNNNNNNNNNNNNNNNNO.46bccccccccc_`ccccccccchiT.........PL0LHIGT..........XNO.46aT...P.4"
105 "6aT........79n13ldfi13l79n.................................P.46aMNNNNNNNNNNNNNNNNNNNNNW.........PHJGMNNW............P.13jT...P.4"
106 "6aT........13ldfi !ndfi13l.................................P.46aT...............................XNNNW...............P.dfiT...P.4"
107 "6aT........dfi !n#$% !ndfi.................................P.46aT...................................................XNNNNW...P.4"
108 "6aT........ !n#$%d&'#$% !n.................................P.46aT............................................................P.4"
109 "6aT.....79n#$%d&'...d&'#$%79n..............................P.46aT............................................................P.4"
110 "6aT.....46md&'...*.....d&'46m..............................P.46aT............................................................P.4"
111 "6aT.....13j !n......... !n13j..............................P.46aT............................................................P.4"
112 "6aT.....dfi#$% !n... !n#$%dfi..............................P.46aT............................................................P.4"
113 "6aT........d&'#$% !n#$%d&'.................................P.13jT.......79n...........EFEFEF.................................P.4"
114 "6aT........79nd&'#$%d&'79n.................................P.dfiT.......46m...........KHGHGK.................................P.4"
115 "6aT........13l79nd&'79n13l..............0.0.0.0.0..........XNNNNW.......46a...........HFEFEG.................................P.4"
116 "6aT........dfi13l79n13ldfi..............................................46a...........0HGHG0.................................P.4"
117 "6aT...........dfi46mdfi.................0...0...0.79n...................46a......................URRRRRRRRRRRRRRV............P.4"
118 "6aSRRRRRRRRRRRRV.46aURRRRRRRRRRRRRRRRRRV..........46m...................46a......................P..............T............P.4"
119 "6a.............T.46aP..................T0.0.0.0.0.46a........ !n........46a......................P.78888889n.79nT............P.4"
120 "Bp88888;<=+>?!nT.46aP. ()+,-:888888889nT..........46a........#$%........46a......................P.4C2222D6m.46mT............P.4"
121 "C222222yz{u|}$%T.46aP.#@tuvwx2222222D6mT..........46a........d&'........46a......URRRRRRRRRRRRRRRQ.46bcccr3j.46aSRRRRRRRRRRRRQ.4"
122 "6bccccccccccc_'T.46aP.d&`ccccccccccco6aT...URRRV..46a...................46a......P.................46a79ndfi.46a...............4"
123 "6aMNNNNNNNNNNNNW.46aXNNNNNNNNNNNNNO.46aTURRQEJFT..4Bp8888888888888888888A6a......P.7888888888888888A6a4Bp8888ABp888888888888888A"
124 };
125
126 typedef struct
127 {
128 u8 nMaterial; // Tile type / texture-map selection
129 u8 nS; // S texture coordinate
130 u8 nT; // T texture coordinate
131 u8 nCI; // Color Index
132 u8 aUser[4]; // User data
133 }
134 G2DTileDesc;
135
136 static G2DTileDesc tileDescLyr1[NUM_TILES_LYR1] =
137 {
138 // M S T CI User // M=Material (S,T) = Tex Coords -or-
139 // M R G B Data // CI = Color Index -or- (R,G,B) = RGB8 Color
140 1, 8, 8, 0, 0,1,0,0, // ' ': Solo Tower
141 1, 9, 8, 0, 3,1,0,0, // '!': Solo Tower
142 0, 0, 0, 0, 0,0,0,0, // '"':
143 1, 8, 9, 0, 1,1,0,0, // '#': Solo Tower
144 1, 9, 9, 0, 2,1,0,0, // '$': Solo Tower
145 1, 10, 9, 0, 0,0,0,0, // '%': Solo Tower
146 1, 9, 10, 0, 0,0,0,0, // '&': Solo Tower
147 1, 10, 10, 0, 0,0,0,0, // ''': Solo Tower
148 1, 1, 11, 0, 0,2,0,0, // '(': Solo Tower
149 1, 2, 11, 0, 0,2,0,0, // ')': Raised
150 1, 7, 7, 0, 0,0,0,0, // '*': Starting position
151 1, 3, 11, 0, 0,2,0,0, // '+': Raised
152 1, 4, 11, 0, 0,2,0,0, // ',': Raised
153 1, 5, 11, 0, 0,2,0,0, // '-': Raised
154 1, 7, 7, 1, 0,0,0,0, // '.': Basic tile (colored)
155 1, 4, 9, 0, 0,0,0,0, // '/': Inverse Bump
156 1, 1, 9, 0, 0,0,0,0, // '0': Bump
157 1, 0, 5, 0, 1,1,0,0, // '1': Bottom Left
158 1, 1, 5, 0, 2,2,0,0, // '2': Bottom
159 1, 5, 5, 0, 2,1,0,0, // '3': Bottom Right
160 1, 0, 4, 0, 1,2,0,0, // '4': Left
161 1, 4, 4, 2, 0,3,0,0, // '5': Mid
162 1, 5, 4, 0, 3,2,0,0, // '6': Right
163 1, 0, 0, 0, 0,1,0,0, // '7': Top Left
164 1, 1, 0, 0, 0,2,0,0, // '8': Top
165 1, 5, 0, 0, 3,1,0,0, // '9': Top Right
166 1, 6, 11, 0, 0,2,0,0, // ':': Raised
167 1, 7, 11, 0, 0,2,0,0, // ';': Raised
168 1, 8, 11, 0, 0,2,0,0, // '<': Raised
169 1, 9, 11, 0, 0,2,0,0, // '=': Raised
170 1, 10, 11, 0, 0,2,0,0, // '>': Raised
171 1, 11, 11, 0, 0,2,0,0, // '?': Raised
172 1, 1, 12, 0, 2,2,0,0, // '@': Raised
173 1, 3, 4, 0, 0,3,0,0, // 'A': Inner TL
174 1, 1, 4, 0, 3,3,0,0, // 'B': Inner TR
175 1, 1, 1, 0, 2,3,0,0, // 'C': Inner BR
176 1, 4, 1, 0, 1,3,0,0, // 'D': Inner BL
177
178 1, 0, 8, 1, 0,0,0,0, // 'E': Floor Marking
179 1, 2, 8, 0, 0,0,0,0, // 'F': Floor Marking
180 1, 2, 10, 0, 0,0,0,0, // 'G': Floor Marking
181 1, 0, 10, 0, 0,0,0,0, // 'H': Floor Marking
182 1, 1, 8, 0, 0,0,0,0, // 'I': Floor Marking
183 1, 1, 10, 0, 0,0,0,0, // 'J': Floor Marking
184 1, 2, 9, 0, 0,0,0,0, // 'K': Floor Marking
185 1, 0, 9, 0, 0,0,0,0, // 'L': Floor Marking
186 1, 3, 8, 0, 0,0,0,0, // 'M': Floor Marking
187 1, 4, 8, 0, 0,0,0,0, // 'N': Floor Marking
188 1, 5, 8, 0, 0,0,0,0, // 'O': Floor Marking
189 1, 5, 9, 0, 0,0,0,0, // 'P': Floor Marking
190 1, 5, 10, 0, 0,0,0,0, // 'Q': Floor Marking
191 1, 4, 10, 0, 0,0,0,0, // 'R': Floor Marking
192 1, 3, 10, 0, 0,0,0,0, // 'S': Floor Marking
193 1, 3, 9, 0, 0,0,0,0, // 'T': Floor Marking
194 1, 6, 8, 0, 0,0,0,0, // 'U': Floor Marking
195 1, 7, 8, 0, 0,0,0,0, // 'V': Floor Marking
196 1, 7, 9, 0, 0,0,0,0, // 'W': Floor Marking
197 1, 6, 9, 0, 0,0,0,0, // 'X': Floor Marking
198 0, 0, 0, 0, 0,0,0,0, // 'Y':
199 0, 0, 0, 0, 0,0,0,0, // 'Z':
200 0, 0, 0, 0, 0,0,0,0, // '[':
201 0, 0, 0, 0, 0,0,0,0, // '\':
202 0, 0, 0, 0, 0,0,0,0, // ']':
203 0, 0, 0, 0, 0,0,0,0, // '^':
204 1, 12, 13, 0, 0,0,0,0, // '_': Shadow
205 1, 2, 13, 0, 0,0,0,0, // '`': Shadow
206
207 1, 2, 3, 0, 0,0,0,0, // 'a': Shadow
208 1, 2, 2, 0, 0,0,0,0, // 'b': Shadow
209 1, 3, 2, 0, 0,0,0,0, // 'c': Shadow
210 1, 0, 6, 0, 0,0,0,0, // 'd': Shadow
211 1, 1, 6, 0, 0,0,0,0, // 'e': Shadow
212 1, 3, 7, 0, 0,0,0,0, // 'f': Shadow
213 1, 4, 6, 0, 0,0,0,0, // 'g': Shadow
214 1, 5, 6, 0, 0,0,0,0, // 'h': Shadow
215 1, 6, 6, 0, 0,0,0,0, // 'i': Shadow
216 1, 6, 5, 0, 0,0,0,0, // 'j': Shadow
217 1, 6, 4, 0, 0,0,0,0, // 'k': Shadow
218 1, 7, 3, 0, 0,0,0,0, // 'l': Shadow
219 1, 6, 1, 0, 0,0,0,0, // 'm': Shadow
220 1, 6, 0, 0, 0,0,0,0, // 'n': Shadow
221 1, 4, 2, 0, 1,2,0,0, // 'o': Left Shadow
222 1, 2, 4, 0, 0,2,0,0, // 'p': Top Shadow
223 1, 6, 2, 0, 3,1,0,0, // 'q': TR Shadow
224 1, 2, 6, 0, 1,1,0,0, // 'r': BL Shadow
225 1, 12, 9, 0, 0,0,0,0, // 's': Shadow
226
227 1, 2, 12, 0, 2,2,0,0, // 't': Raised
228 1, 3, 12, 0, 2,2,0,0, // 'u': Raised
229 1, 4, 12, 0, 2,2,0,0, // 'v': Raised
230 1, 5, 12, 0, 2,2,0,0, // 'w': Raised
231 1, 6, 12, 0, 2,2,0,0, // 'x': Raised
232 1, 7, 12, 0, 2,2,0,0, // 'y': Raised
233 1, 8, 12, 0, 2,2,0,0, // 'z': Raised
234 1, 9, 12, 0, 2,2,0,0, // '{': Raised
235 1, 10, 12, 0, 2,2,0,0, // '|': Raised
236 1, 11, 12, 0, 2,2,0,0, // '}': Raised
237 0, 0, 0, 0, 0,0,0,0, // '~': Raised
238 };
239
240 void MapInit( TPLPalettePtr *tpl );
241
242 /*---------------------------------------------------------------------------*
243 Name: MapInit
244
245 Description: Initializes the tile map indirect texture.
246
247 Arguments: TPLPalettePtr to necessary tpl file
248 Returns: none
249 *---------------------------------------------------------------------------*/
MapInit(TPLPalettePtr * tpl)250 void MapInit( TPLPalettePtr *tpl )
251 {
252 s32 nI, nJ, ndx;
253 u8 tile;
254 s32 off;
255 u8 nS, nT;
256
257 for (nJ=0; nJ<HEIGHT_LYR1; nJ++)
258 {
259 for (nI=0; nI<WIDTH_LYR1; nI++)
260 {
261 ndx = (nJ<<HSHIFT_LYR1)+nI;
262 if (map1[ndx] == '*')
263 {
264 map1[ndx] = '.';
265 // Initial ship world position (in pixels)
266 poShip.rPosX = (f32) nI/WIDTH_LYR1;
267 poShip.rPosY = (f32) nJ/HEIGHT_LYR1;
268 }
269 tile = (u8) (map1[ndx] - ' ');
270
271 nS = tileDescLyr1[tile].nS;
272 nT = tileDescLyr1[tile].nT;
273
274 // This offset calculation works for map widths that are
275 // powers of 2
276 off = (nI & 7) | ((nI >> 3) << 5) | ((nJ & 3) << 3) |
277 ((nJ >> 2) << (5+(HSHIFT_LYR1-3)));
278
279 tmap1[off] = (u8) ((nS<<4) | (nT));
280 }
281 }
282 DCFlushRange((void *) tmap1, 64*128);
283
284 // Set up tile texture for bilinear interpolation
285
286 // Tiles
287 TPLGetGXTexObjFromPalette(*tpl, &toTilesRGB_1, 0);
288 GXInitTexObjLOD( &toTilesRGB_1,
289 GX_LINEAR, GX_LINEAR, 0.0F, 0.0F, 0.0F,
290 GX_FALSE, GX_FALSE, GX_ANISO_1 );
291
292 // Tile Map
293 GXInitTexObj(&toTileMap_1, // texture object
294 (void*) &tmap1, // data
295 128, // width
296 64, // height
297 GX_TF_IA4, // format
298 GX_REPEAT, // wrap s
299 GX_REPEAT, // wrap t
300 GX_FALSE); // mipmap
301
302 GXInitTexObjLOD( &toTileMap_1,
303 GX_NEAR, GX_NEAR, 0.0F, 0.0F, 0.0F,
304 GX_FALSE, GX_FALSE, GX_ANISO_1 );
305 }
306