0
|
1 /*
|
18
|
2 * $Id$
|
0
|
3 */
|
|
4 #include <stdio.h>
|
|
5 #include <stdlib.h>
|
|
6 #include "libps2.h"
|
|
7 #include "ps2util.h"
|
|
8 #include "mytype.h"
|
|
9 #include "col.h"
|
|
10 #include "field.h"
|
|
11 #include "car.h"
|
|
12 #include "quotanion.h"
|
|
13 #include "game.h"
|
|
14
|
|
15 #define DEFAULT_SET (EFFECT_TEXTURE_USE | EFFECT_ALPHABLEND_UNUSE | EFFECT_SHADING_FLAT)
|
|
16 #define BUFSIZE 256
|
|
17
|
|
18 /* --- main.c --- */
|
|
19 extern FILE *main_fp;
|
|
20 /* --- game.c --- */
|
|
21 extern Game game;
|
|
22
|
|
23
|
|
24 static int field_num_max = 0;
|
|
25 static int field_num = 1;
|
|
26
|
|
27 static FieldPtr field_list;
|
|
28 static FieldPtr field_actual;
|
|
29
|
|
30 static FieldPtr
|
|
31 field_create(char *fieldImg, char *colImg, TEXTURE* tex)
|
|
32 {
|
|
33 FieldPtr self;
|
|
34 OBJECT *obj;
|
|
35 PolygonInfo *xml;
|
|
36 void *free_addr;
|
|
37
|
|
38 FVECTOR location = {0, 0, 0, 1};
|
|
39 FVECTOR direction = {0, 0, 0, 1};
|
|
40
|
|
41 obj = ps2util_obj_Create_fromXML(fieldImg);
|
|
42 memcpy(obj->xyz, location, sizeof(FVECTOR));
|
|
43 memcpy(obj->angle, direction, sizeof(FVECTOR));
|
|
44 ps2util_obj_Renew_transMatrix(obj);
|
|
45 ps2util_obj_Set_effect(obj, DEFAULT_SET);
|
|
46 ps2util_obj_Set_texture(obj, tex);
|
|
47
|
|
48 xml = xml_read_file(colImg); //$B$3$3$G%3!<%9$NAv$l$k>l=j(B($BEv$?$jH=Dj(B)
|
|
49
|
|
50 if (malloc_align16(&free_addr, &self, sizeof(Field)) == -1) {
|
|
51 fprintf(stderr, "field.c: malloc_align16 error\n");
|
|
52 fflush(stderr);
|
|
53 exit(EXIT_FAILURE);
|
|
54 }
|
|
55 self->object = obj;
|
|
56 self->next = NULL;
|
|
57 self->prev = NULL;
|
|
58 self->free_addr = free_addr;
|
|
59 #ifdef DEBUG
|
|
60 fprintf(main_fp, "malloc fieldNode addr = %x\n", (int)free_addr);
|
|
61 #endif
|
|
62 col_init(&self->colface, xml);
|
|
63
|
|
64 xml_free(xml);
|
|
65
|
|
66 return self;
|
|
67 }
|
|
68
|
|
69 static void
|
|
70 field_new_readCSV(FILE *fp)
|
|
71 {
|
|
72 FieldPtr fieldHead = NULL;
|
|
73 FieldPtr newField = NULL;
|
|
74 FieldPtr prevField = NULL;
|
|
75 char buff[BUFSIZE], *bufp;
|
|
76 char fieldImg[BUFSIZE], colImg[BUFSIZE], texname[BUFSIZE];
|
|
77 TEXTURE *tex = NULL;
|
|
78 int course_id;
|
|
79 Bool flag = FALSE;
|
|
80
|
|
81 while ((bufp = fgets(buff, BUFSIZE, fp)) != NULL) {
|
|
82 bufp++;
|
|
83
|
|
84 switch (buff[0]) {
|
|
85 case 'n': // $B%3!<%9(BID$B$NFI$_<h$j(B
|
|
86 if (!flag) {
|
|
87 sscanf(bufp, " %d\n", &course_id);
|
|
88 if (game.course_id == course_id) {
|
|
89 flag = TRUE;
|
|
90 }
|
|
91 } else {
|
|
92 goto FINISH_LOAD;
|
|
93 }
|
|
94 break;
|
|
95 case 't': // $B%F%/%9%A%c$N%m!<%I(B
|
|
96 if (flag) {
|
|
97 sscanf(bufp, " %s\n", texname);
|
|
98 tex = read_png_file(texname);
|
|
99 ps2util_tex_Set(tex);
|
|
100 }
|
|
101 break;
|
|
102 case 'c': // $B%3!<%9$N%m!<%I(B
|
|
103 if (flag) {
|
|
104 sscanf(bufp, " %s %s\n", fieldImg, colImg);
|
|
105 newField = field_create(fieldImg, colImg, tex);
|
|
106 if (!fieldHead) {
|
|
107 fieldHead = prevField = newField;
|
|
108 } else {
|
|
109 prevField->next = newField;
|
|
110 newField->prev = prevField;
|
|
111 prevField = newField;
|
|
112 }
|
|
113 newField->init = fieldHead;
|
|
114 field_num_max++;
|
|
115 }
|
|
116 break;
|
|
117 default:
|
|
118 break;
|
|
119 }
|
|
120 }
|
|
121
|
|
122 FINISH_LOAD:
|
|
123 // $B@hF,$H:G8eHx$N%j%s%/$rD%$k(B
|
|
124 newField->next = newField->init;
|
|
125 newField->init->prev = newField;
|
|
126
|
|
127 field_list = field_actual = fieldHead;
|
|
128 }
|
|
129
|
|
130
|
|
131 /*---------------------/
|
|
132 FieldPtr
|
|
133 field_init:
|
|
134 $B;XDj$7$?%U%!%$%k$+$i%3!<%9$r@8@.$9$k!#(B
|
|
135 $BLa$jCM(B
|
|
136 $B%3!<%9@hF,$N%]%$%s%?(B
|
|
137 /---------------------*/
|
|
138 void
|
|
139 field_init()
|
|
140 {
|
|
141 FILE *fp;
|
|
142 char *filename = "course/course.dat";
|
|
143
|
|
144 if (!(fp = fopen(filename, "r"))) {
|
|
145 fprintf(main_fp, "error read file %s\n", filename);
|
|
146 exit(EXIT_FAILURE);
|
|
147 }
|
|
148 field_new_readCSV(fp);
|
|
149 fclose(fp);
|
|
150 }
|
|
151
|
|
152
|
|
153 static void
|
|
154 field_draw(FieldPtr p)
|
|
155 {
|
|
156 ps2_vu0_unit_matrix(p->object->transfer);
|
|
157
|
|
158 p->object->transfer[3][0] = p->location[0];
|
|
159 p->object->transfer[3][1] = p->location[1];
|
|
160 p->object->transfer[3][2] = p->location[2];
|
|
161 p->object->transfer[3][3] = p->location[3];
|
|
162 ps2util_obj_Draw(p->object);
|
|
163 }
|
|
164
|
|
165
|
|
166 void
|
|
167 field_update(CarPtr car)
|
|
168 {
|
|
169 FieldPtr p;
|
|
170
|
|
171 p = field_actual;
|
|
172 // current
|
|
173 p->location[0] = -car->location[0];
|
|
174 p->location[1] = -car->location[1];
|
|
175 p->location[2] = -car->location[2];
|
|
176 p->location[3] = 1;
|
|
177 field_draw(p);
|
|
178
|
|
179 // next
|
|
180 p = field_actual->next;
|
|
181 if (p) {
|
|
182 p->location[0] = -car->location[0];
|
|
183 p->location[1] = -car->location[1];
|
|
184 p->location[2] = -car->location[2];
|
|
185 p->location[3] = 1;
|
|
186 field_draw(p);
|
|
187 }
|
|
188
|
|
189 // prev
|
|
190 p = field_actual->prev;
|
|
191 if (p) {
|
|
192 p->location[0] = -car->location[0];
|
|
193 p->location[1] = -car->location[1];
|
|
194 p->location[2] = -car->location[2];
|
|
195 p->location[3] = 1;
|
|
196 field_draw(p);
|
|
197 }
|
|
198 }
|
|
199
|
|
200 void
|
|
201 field_destroy()
|
|
202 {
|
|
203 FieldPtr p = field_list;
|
|
204 FieldPtr d;
|
|
205 TEXTURE *t;
|
|
206
|
|
207 p->prev->next = NULL;
|
|
208
|
|
209 t = p->object->surfaces->texture;
|
|
210 ps2util_tex_Exclude(t);
|
|
211 free_texture(t);
|
|
212
|
|
213 while (p) {
|
|
214 d = p;
|
|
215 p = p->next;
|
|
216 ps2util_obj_Free(d->object);
|
|
217 free(d->free_addr);
|
|
218 #ifdef DEBUG
|
|
219 fprintf(main_fp, "free fieldNode addr = %x\n", (int)d->free_addr);
|
|
220 #endif
|
|
221 }
|
|
222
|
|
223 field_num_max = 0;
|
|
224 field_num = 1;
|
|
225 }
|
|
226
|
|
227 /*
|
|
228 * $B<~2s5-O?!#(B1$B<~$9$kKh$K(B1$B$rJV$9!#(B
|
|
229 */
|
|
230 int
|
|
231 field_rap_increment(int n)
|
|
232 {
|
|
233 field_num += n;
|
|
234 if (field_num > field_num_max) {
|
|
235 field_num = 1;
|
|
236 return 1;
|
|
237 } else {
|
|
238 return 0;
|
|
239 }
|
|
240 }
|
|
241
|
|
242 void
|
|
243 field_set_actual(FieldPtr p)
|
|
244 {
|
|
245 field_actual = p;
|
|
246 }
|
|
247
|
|
248 FieldPtr
|
|
249 field_get_actual()
|
|
250 {
|
|
251 return field_actual;
|
|
252 }
|