annotate field.cc @ 99:c534f339ee8b

change c++
author e085768
date Thu, 02 Jun 2011 17:51:41 +0900
parents field.c@0b65ca27f113
children e5f2eb98b575
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
1 #include <stdio.h>
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
2 #include <stdlib.h>
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
3 #include <stdbool.h>
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
4 #include <string.h>
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
5 #include "libps2.h"
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
6 #include "ps2util.h"
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
7 #include "mytype.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
8 #include "field.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
9 #include "car.h"
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
10 #include "quotanion.h"
90
8edae89a3877 compile on Mac OS X
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
11 #include <stdbool.h>
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
12
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
13 #define BUFSIZE 256
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
14
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
15 /* --- main.c --- */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
16 extern FILE *main_fp;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
17
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
18 static int field_num_max = 0;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
19 static int field_num = 1;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
20
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
21 static FieldPtr field_list;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
22 static FieldPtr field_actual;
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
23
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
24 // 適当に自作:miya
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
25 PolygonInfo xml_read_file(char *colImg)
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
26 {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
27 PolygonInfo test;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
28 printf("xml_read_file");
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
29
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
30 return test;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
31 }
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
32
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
33
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
34 static FieldPtr
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
35 field_create(char *fieldImg, char *colImg, TEXTURE *tex)
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
36 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
37 FieldPtr self;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
38 OBJECT *obj;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
39 PolygonInfo *xml;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
40 void *free_addr;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
41
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
42 FVECTOR location = {0, 0, 0, 1};
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
43 FVECTOR direction = {0, 0, 0, 1};
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
44
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
45 obj = ps2util_obj_Create_fromXML(fieldImg);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
46 memcpy(obj->xyz, location, sizeof(FVECTOR));
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
47 memcpy(obj->angle, direction, sizeof(FVECTOR));
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
48 ps2util_obj_Renew_transMatrix(obj);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
49 ps2util_obj_Set_effect(obj, DEFAULT_SET);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
50 ps2util_obj_Set_texture(obj, tex);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
51
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
52 // xml = xml_read_file(colImg); //ここでコースの走れる場所(当たり判定)
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
53
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
54 if (malloc_align16(&free_addr, &self, sizeof(Field)) == -1) {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
55 fprintf(stderr, "field.c: malloc_align16 error\n");
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
56 fflush(stderr);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
57 exit(EXIT_FAILURE);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
58 }
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
59 self->object = obj;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
60 self->next = NULL;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
61 self->prev = NULL;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
62 self->free_addr = free_addr;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
63 #ifdef DEBUG
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
64 fprintf(main_fp, "malloc fieldNode addr = %x(free), %x(obj)\n", (int)free_addr, (int)self);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
65 #endif
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
66 col_init(&self->colface, xml);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
67
34
55f2d0326c4d *** empty log message ***
gongo
parents: 33
diff changeset
68 #ifdef DEBUG
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
69 fprintf(main_fp, " facenum = %d\n", self->colface.facenum);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
70 fprintf(main_fp, " facenum = %x(free), ", (int)self->colface.free_addr);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
71 fprintf(main_fp, "facenum = %x(obj)\n", (int)self->colface.colface);
34
55f2d0326c4d *** empty log message ***
gongo
parents: 33
diff changeset
72 #endif
55f2d0326c4d *** empty log message ***
gongo
parents: 33
diff changeset
73
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
74 //xml_free(xml);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
75
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
76 return self;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
77 }
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
78
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
79
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
80
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
81 static void
32
b5c5ffd4d2f2 *** empty log message ***
gongo
parents: 18
diff changeset
82 field_new_readCSV(FILE *fp, int id)
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
83 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
84 FieldPtr fieldHead = NULL;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
85 FieldPtr newField = NULL;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
86 FieldPtr prevField = NULL;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
87 char buff[BUFSIZE], *bufp;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
88 char fieldImg[BUFSIZE], colImg[BUFSIZE], texname[BUFSIZE];
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
89 TEXTURE *tex = NULL;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
90 int course_id;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
91 bool flag = false;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
92
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
93 while ((bufp = fgets(buff, BUFSIZE, fp)) != NULL) {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
94 bufp++;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
95
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
96 switch (buff[0]) {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
97 case 'n': // コースIDの読み取り
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
98 if (!flag) {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
99 sscanf(bufp, " %d\n", &course_id);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
100 if (id == course_id) {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
101 flag = true;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
102 }
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
103 } else {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
104 goto FINISH_LOAD;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
105 }
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
106 break;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
107 case 't': // テクスチャのロード
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
108 if (flag) {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
109 sscanf(bufp, " %s\n", texname);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
110 //tex = read_png_file(texname);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
111 ps2util_tex_Set(tex);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
112 }
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
113 break;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
114 case 'c': // コースのロード
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
115 if (flag) {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
116 sscanf(bufp, " %s %s\n", fieldImg, colImg);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
117 newField = field_create(fieldImg, colImg, tex);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
118 if (!fieldHead) {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
119 fieldHead = prevField = newField;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
120 } else {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
121 prevField->next = newField;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
122 newField->prev = prevField;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
123 prevField = newField;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
124 }
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
125 newField->init = fieldHead;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
126 field_num_max++;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
127 }
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
128 break;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
129 default:
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
130 break;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
131 }
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
132 }
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
133
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
134 FINISH_LOAD:
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
135 // 先頭と最後尾のリンクを張る
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
136 newField->next = newField->init;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
137 newField->init->prev = newField;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
138
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
139 field_list = field_actual = fieldHead;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
140 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
141
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
142
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
143 /*---------------------/
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
144 FieldPtr
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
145 field_init:
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
146 指定したファイルからコースを生成する。
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
147 戻り値
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
148 コース先頭のポインタ
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
149 /---------------------*/
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
150 void
32
b5c5ffd4d2f2 *** empty log message ***
gongo
parents: 18
diff changeset
151 field_init(int id)
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
152 {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
153 FILE *fp;
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
154 char *filename = "course/course.dat";
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
155
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
156 if (!(fp = fopen(filename, "r"))) {
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
157 fprintf(main_fp, "error read file %s\n", filename);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
158 exit(EXIT_FAILURE);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
159 }
32
b5c5ffd4d2f2 *** empty log message ***
gongo
parents: 18
diff changeset
160 field_new_readCSV(fp, id);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
161 fclose(fp);
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
162 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
163
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
164
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
165 static void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
166 field_draw(FieldPtr p)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
167 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
168 ps2_vu0_unit_matrix(p->object->transfer);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
169
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
170 p->object->transfer[3][0] = p->location[0];
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
171 p->object->transfer[3][1] = p->location[1];
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
172 p->object->transfer[3][2] = p->location[2];
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
173 p->object->transfer[3][3] = p->location[3];
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
174 ps2util_obj_Draw(p->object);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
175 }
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
176
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
177
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
178 void field_update(CarPtr car)
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
179 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
180 FieldPtr p;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
181
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
182 p = field_actual;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
183 // current
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
184 p->location[0] = -car->location[0];
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
185 p->location[1] = -car->location[1];
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
186 p->location[2] = -car->location[2];
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
187 p->location[3] = 1;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
188 field_draw(p);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
189
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
190 // next
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
191 p = field_actual->next;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
192 if (p) {
91
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
193 p->location[0] = -car->location[0];
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
194 p->location[1] = -car->location[1];
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
195 p->location[2] = -car->location[2];
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
196 p->location[3] = 1;
cb6c6de125dc halfway
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
197 field_draw(p);
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
198 }
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
199
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
200 // prev
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
201 p = field_actual->prev;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
202 if (p) {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
203 p->location[0] = -car->location[0];
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
204 p->location[1] = -car->location[1];
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
205 p->location[2] = -car->location[2];
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
206 p->location[3] = 1;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
207 field_draw(p);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
208 }
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
209 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
210
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
211 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
212 field_destroy()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
213 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
214 FieldPtr p = field_list;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
215 FieldPtr d;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
216 TEXTURE *t;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
217
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
218 p->prev->next = NULL;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
219
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
220 t = p->object->surfaces->texture;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
221 ps2util_tex_Exclude(t);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
222 free_texture(t);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
223
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
224 while (p) {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
225 d = p;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
226 p = p->next;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
227 ps2util_obj_Free(d->object);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
228 free(d->colface.free_addr);
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
229 free(d->free_addr);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
230 #ifdef DEBUG
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
231 fprintf(main_fp, "free fieldNode addr = %x\n", (int)d->free_addr);
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
232 #endif
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
233 }
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
234
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
235 field_num_max = 0;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
236 field_num = 1;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
237 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
238
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
239 /*
88
ce9ef7dcf2f0 convert UTF-8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 43
diff changeset
240 * 周回記録。1周する毎に1を返す。
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
241 */
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
242 int
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
243 field_rap_increment(int n)
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
244 {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
245 field_num += n;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
246 if (field_num > field_num_max) {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
247 field_num = 1;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
248 return 1;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
249 } else {
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
250 return 0;
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
251 }
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
252 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
253
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
254 void
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
255 field_set_actual(FieldPtr p)
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
256 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
257 field_actual = p;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
258 }
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
259
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
260 FieldPtr
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
261 field_get_actual()
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
262 {
96
0b65ca27f113 compile on Mac OS X 2
Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
263 return field_actual;
0
0fae5658fb0b Initial revision
gongo
parents:
diff changeset
264 }