29 #define CURR_CDAT (*cdat_stackp)
30 #define CURR_SET set_list[CURR_CDAT->num_sets]
31 #define CURR_ELE ele_list[CURR_CDAT->CURR_SET.num_ele]
32 #define PREV_REF (ref_buf[num_refs-1])
33 #define CURR_REF (ref_buf[num_refs])
34 #define PREV_ODAT (odat_buf[num_odats-1])
35 #define CURR_ODAT (odat_buf[num_odats])
36 #define CURR_VDAT (vdat_buf[num_vdats])
37 #define PREV_VDAT (vdat_buf[num_vdats-1])
38 #define CURR_MODEL model_list[CURR_VDAT->num_models]
39 #define CURR_LINK (link_buf[num_links])
40 #define CURR_POST (post_buf[num_posts])
42 /* General: All information from the directory structure is stored in */
43 /* five buffers that comprise the IR: cdat_buf, odat_buf, vdat_buf, ref_buf */
44 /* and link_buf. Each buf corresponds to the data structure that it stores. */
45 /* The storage techique for all bufs (except cdat) is the same. Each bufs member first */
46 /* populates its struct and then allocates the space for the next member */
47 /* and increments the buf index. This means that we have to allocate the */
48 /* very first member of each buf at ir_init(), so that we don't segfault */
49 /* as the first member attempts to access memory that its previous member */
50 /* didn't allocate (because it doesnt exist). We access the buf members */
51 /* through standard array indexing but conceal the tediousness of array */
52 /* indexing with macros. E.g. without macros, acessing an elements name */
53 /* member would look like (split up to not go over line char limit): */
54 /* (*cdat_stackp)->set_list[(*cdat_stackp)->num_sets] */
55 /* .ele_list[(*cdat_stackp)->set_list[(*cdat_stackp->num_sets)].num_ele].name */
57 /* For cdats in cdat_buf, we allocate the memory for a cdat once a cdat
58 is recognized in the grammar. Cdat_buf is different from the other bufs
59 because cdats have a root cdat that all cdats are a subclass of. This root
60 cdat can have a set_list like other cdats. */
62 /* Elements: Ele stands for element and has two representations in the IR. */
63 /* In the cdat_buf eles store their name, cdat_idx (their classes index in */
64 /* the cdat_buf) and the ref_id (refer to ref ). In the odat_buf, eles store */
65 /* their object data (odat). At output time, the ref_id is dereferenced to */
66 /* determine the elements odat which is the data that the engine expects */
67 /* from an element. */
70 /* All bufs are of pointers to their respective structs. When a buf is full */
71 /* (number of data structs pointers >= max number of data struct pointers), */
72 /* we need to allocate a more pointers for that buf. Allocate these */
73 /* pointers a page at a time (1024 = Page bytes (4096)/bytes per pointer(4)) */
81 /* Sets: The set is similar to the ele, but it contains a list of its */
82 /* elements. The set is populated at parse time AFTER the elements are */
83 /* populated, due to the nature of bottom up parsing. */
90 struct ele ele_list
[MAX_ELES
];
93 /* Cdats: A cdat is a class data structure. Cdats serve as the central */
94 /* data types of the IR. At output, the cdat_buf is iterated through and */
95 /* each is written to the output file. For each cdat, sets and element */
96 /* ref_ids must be dereferenced to determine the odat information. Cdats */
97 /* contain pointers to their subclasses so that the relationship between */
98 /* classes can be determined, but the subclasses are not represented inside */
99 /* of the cdat itself but rather in the subsequent cdats in cdat_buf. We */
100 /* can determine the number of subclasses (the last index into cdat_buf */
101 /* that represents a subclass of some arbitrary cdat) each cdat has by */
102 /* incrementing num_classes during parse time. */
103 /* TODO: Should classes point to their parent class? */
110 struct cdat
* class_list
[MAX_CLASSES
];
111 struct set set_list
[MAX_SETS
];
114 /* There are an unknown amount of cdats at compile time, so we maintain */
115 /* a cdat_buf of cdat pointers that can be expanded as needed. */
116 struct cdat
* cdat_buf
[PTRS_IN_PAGE
];
118 /* The cdat_stack is a stack pointers to cdat pointers, the top of which is
119 the cdat that is currently being parsed. Whenever a new cdat is recognized
120 by the grammar (CLOPEN), a cdat is pushed onto the cdat_stack, and we refer
121 to this cdat through the macro CURR_CDAT. By keeping a cdat_stack, we have
122 access to the current cdat so that the elements and sets can populate themselves
123 in the cdat accordingly. */
125 struct cdat
* cdat_stack
[PTRS_IN_PAGE
];
126 struct cdat
** cdat_stackp
;
128 int curr_max_cdats
= PTRS_IN_PAGE
;
130 /* Refs: Each set/ele has a reference to its object data (odat) through a ref_id.
131 Ref_ids are unsigned 64 byte integers that map to the hex values RGBA. During
132 the construction of the directory structure, users can choose a RGBA value for
133 each object that any other object can refer to via links (see link). If a user
134 does not choose an RGBA value, then the object is given one from the system space.
135 We maintain a doubly linked list of refs in the ref_buf at parse time so that
136 links can be resolved after the parsing of the directory structure is complete.
137 For every 16th ref, we create a post so that we can reduce on the search time for
145 uint64_t ref_id
; //0xFFFFFF->digit
149 /* Like the cdat_buf, ref_buf stores pointers to refs and can
151 struct ref
* ref_buf
[PTRS_IN_PAGE
];
153 int curr_max_refs
= PTRS_IN_PAGE
;
154 uint64_t ss_ref_id
= 0x00FFFFFF; /* system space for ref_ids */
156 /* posts for ref_buf */
157 struct ref
* post_buf
[PTRS_IN_PAGE
];
159 int curr_max_posts
= PTRS_IN_PAGE
;
161 /* Links: At parse time, a set/ele can include a link in their
162 grammar representation instead of the actual data and this signifies
163 to the APC that that set/ele wishes to use the data of another
164 set/ele, either its video data (vdat) or object data (odat). The link
165 itself contains the type of link it is, the ref_id OR name, and
166 which set/ele created the link. During parse time, links can be made
167 to o/vdats that have yet to be parsed. In order to accomodate for this,
168 we resolve all links AFTER parse time by iterating through the link_buf,
169 finding the ref_id that was stored for some object (if the ref_id exists),
170 and creating a relative pointer from the original object to the data that
173 /* Svlinks stand for short vlink, which is a link to a vdat
174 TODO: diff btwn vlink*/
180 /* A vlink is what it sounds like, a link to a vdat
187 /* Olinks are links to odats */
195 struct svlink svlink
;
199 int type
; //1 = olink, 2 = vlink, 3 = svlink
206 /* link_buf contains all the links that
207 we encountered during parse time that need
208 to be resolved to an offset at output time.
209 This does not include quad refs, because
210 those are already known to need to be resolved */
211 struct link
* link_buf
[PTRS_IN_PAGE
];
213 int curr_max_links
= PTRS_IN_PAGE
;
216 /* Odats: Odats consist of the object data necessary for
217 each object. Odats are sometimes referred to as archetypes
218 at compile-time, in order to distinguish the difference from
219 a runtime object and a compile-time object.
220 TODO: Need more info about objects at runtime, to described
221 the reasoning behind odat structure at compile-time*/
223 /* Each set has a quad_list or a list of quads. The quad_list
227 uint64_t ref_id
; //rgba
240 struct ref
* refp
; /* pointer to it's ref on ref_list */
242 struct quad quad_list
[MAX_QUADS
];
244 struct odat
* odat_buf
[PTRS_IN_PAGE
];
246 int curr_max_odats
= PTRS_IN_PAGE
;
248 /* A framesheet is a grouping of animation frames in
249 a single direction (N,W,S,E) */
254 void* frames
[MAX_FRAMES
];
257 /* A model is a collection of framesheets for every
258 direction (N,W,S,E,NW,NE,SW,SE)*/
259 /* NAMED spritesheet */
262 struct framesheet spritesheet
[8]; //one for each
265 /* Vdat: Vdats are the video data of each object. They can not be
266 created as a stand alone object (because they consist solely
267 of animation information and not the skeleton on which the
268 animation manipulates). Vdats have a list of models for every
269 animation that the vdats odat can do for that vdat*/
271 struct odat
* creator
; //pointer to odat that made this vdat
273 struct model model_list
[MAX_MODELS
];
276 struct vdat
* vdat_buf
[PTRS_IN_PAGE
];
278 int curr_max_vdats
= PTRS_IN_PAGE
;
286 if(num_odats
>= curr_max_odats
)
287 { if( (realloc((void*) odat_buf
, PTRS_IN_PAGE
* 4)) == NULL
)
288 perror("realloc odat_buf failed");
289 curr_max_odats
+= PTRS_IN_PAGE
;
291 if( (CURR_ODAT
= (struct odat
*) malloc(sizeof (struct odat
))) == NULL
)
292 perror("malloc odat failed");
302 if(num_vdats
>= curr_max_vdats
)
303 { if( (realloc((void*) vdat_buf
, PTRS_IN_PAGE
* 4)) == NULL
)
304 perror("realloc vdat_buf failed");
305 curr_max_vdats
+= PTRS_IN_PAGE
;
307 if((CURR_VDAT
= (struct vdat
*) malloc(sizeof (struct vdat
))) == NULL
)
308 perror("malloc vdat failed");
320 if(num_links
>= curr_max_links
)
321 { if( (realloc((void*) link_buf
, PTRS_IN_PAGE
* 4)) == NULL
)
322 perror("realloc vdat_buf failed");
323 curr_max_links
+= PTRS_IN_PAGE
;
325 if((CURR_LINK
= (struct link
*) malloc(sizeof (struct link
))) == NULL
)
326 perror("malloc link failed");
337 if(num_refs
% 16 == 0)
338 { CURR_POST
= CURR_REF
;
342 if(num_refs
>= curr_max_refs
)
343 { if( (realloc((void*) ref_buf
, PTRS_IN_PAGE
* 4)) == NULL
)
344 perror("realloc ref_buf failed");
345 curr_max_refs
+= PTRS_IN_PAGE
;
347 if((CURR_REF
= (struct ref
*) malloc(sizeof (struct ref
))) == NULL
)
348 perror("malloc ref failed");
370 return CURR_CDAT
->CURR_SET
;
376 return CURR_CDAT
->CURR_SET
->CURR_ELE
;