2 \brief Intermediate Representation (IR) between Directory Structure and Engine Grammar
3 \details The IR serves as a storage structure that is populated during the
4 parsing of the input directory structure. After parsing is complete,
5 the IR will be condensed (removed of excess allocated space) and then
6 output as the Engine Grammar. In this file we describe the semantic actions
7 that are called at each step, and the memory buffers that they populate.
8 See parser.y for the description on how the input grammar is constructed,
9 and where/when semantic actions are called.
10 TODO: or just write it here.
11 \author Jordan Lavatai
13 ----------------------------------------------------------------------------*/
22 #define MAX_MODELS 256
24 #define MAX_CLASS_DEPTH 256
25 #define MAX_CLASSES 256
26 #define MAX_FRAMES 256
27 #define PTRS_IN_PAGE 1024
29 /* General: All information from the directory structure is stored in */
30 /* five buffers that comprise the IR: cdat_buf, odat_buf, vdat_buf, ref_buf */
31 /* and link_buf. Each buf corresponds to the data structure that it stores. */
32 /* The storage techique for all bufs (except cdat) is the same. Each bufs member first */
33 /* populates its struct and then allocates the space for the next member */
34 /* and increments the buf index. This means that we have to allocate the */
35 /* very first member of each buf at ir_init(), so that we don't segfault */
36 /* as the first member attempts to access memory that its previous member */
37 /* didn't allocate (because it doesnt exist). We access the buf members */
38 /* through standard array indexing but conceal the tediousness of array */
39 /* indexing with macros. E.g. without macros, acessing an elements name */
40 /* member would look like (split up to not go over line char limit): */
41 /* (*cdat_stackp)->set_list[(*cdat_stackp)->num_sets] */
42 /* .ele_list[(*cdat_stackp)->set_list[(*cdat_stackp->num_sets)].num_ele].name */
44 /* For cdats in cdat_buf, we allocate the memory for a cdat once a cdat
45 is recognized in the grammar. Cdat_buf is different from the other bufs
46 because cdats have a root cdat that all cdats are a subclass of. This root
47 cdat can have a set_list like other cdats. */
49 /* Elements: Ele stands for element and has two representations in the IR. */
50 /* In the cdat_buf eles store their name, cdat_idx (their classes index in */
51 /* the cdat_buf) and the ref_id (refer to ref ). In the odat_buf, eles store */
52 /* their object data (odat). At output time, the ref_id is dereferenced to */
53 /* determine the elements odat which is the data that the engine expects */
54 extern struct cdat
** cdat_stackp
;
55 /* from an element. */
58 /* All bufs are of pointers to their respective structs. When a buf is full */
59 /* (number of data structs pointers >= max number of data struct pointers), */
60 /* we need to allocate a more pointers for that buf. Allocate these */
61 /* pointers a page at a time (1024 = Page bytes (4096)/bytes per pointer(4)) */
69 /* Sets: The set is similar to the ele, but it contains a list of its */
70 /* elements. The set is populated at parse time AFTER the elements are */
71 /* populated, due to the nature of bottom up parsing. */
78 struct ele ele_list
[MAX_ELES
];
81 /* Cdats: A cdat is a class data structure. Cdats serve as the central */
82 /* data types of the IR. At output, the cdat_buf is iterated through and */
83 /* each is written to the output file. For each cdat, sets and element */
84 /* ref_ids must be dereferenced to determine the odat information. Cdats */
85 /* contain pointers to their subclasses so that the relationship between */
86 /* classes can be determined, but the subclasses are not represented inside */
87 /* of the cdat itself but rather in the subsequent cdats in cdat_buf. We */
88 /* can determine the number of subclasses (the last index into cdat_buf */
89 /* that represents a subclass of some arbitrary cdat) each cdat has by */
90 /* incrementing num_classes during parse time. */
91 /* TODO: Should classes point to their parent class? */
98 struct cdat
* class_list
[MAX_CLASSES
];
99 struct set set_list
[MAX_SETS
];
102 /* There are an unknown amount of cdats at compile time, so we maintain */
103 /* a cdat_buf of cdat pointers that can be expanded as needed. */
105 /* The cdat_stack is a stack pointers to cdat pointers, the top of which is
106 the cdat that is currently being parsed. Whenever a new cdat is recognized
107 by the grammar (CLOPEN), a cdat is pushed onto the cdat_stack, and we refer
108 to this cdat through the macro CURR_CDAT. By keeping a cdat_stack, we have
109 access to the current cdat so that the elements and sets can populate themselves
110 in the cdat accordingly. */
113 /* Refs: Each set/ele has a reference to its object data (odat) through a ref_id.
114 Ref_ids are unsigned 64 byte integers that map to the hex values RGBA. During
115 the construction of the directory structure, users can choose a RGBA value for
116 each object that any other object can refer to via links (see link). If a user
117 does not choose an RGBA value, then the object is given one from the system space.
118 We maintain a doubly linked list of refs in the ref_buf at parse time so that
119 links can be resolved after the parsing of the directory structure is complete.
120 For every 16th ref, we create a post so that we can reduce on the search time for
128 uint64_t ref_id
; //0xFFFFFF->digit
132 /* Like the cdat_buf, ref_buf stores pointers to refs and can
135 /* posts for ref_buf */
137 /* Links: At parse time, a set/ele can include a link in their
138 grammar representation instead of the actual data and this signifies
139 to the APC that that set/ele wishes to use the data of another
140 set/ele, either its video data (vdat) or object data (odat). The link
141 itself contains the type of link it is, the ref_id OR name, and
142 which set/ele created the link. During parse time, links can be made
143 to o/vdats that have yet to be parsed. In order to accomodate for this,
144 we resolve all links AFTER parse time by iterating through the link_buf,
145 finding the ref_id that was stored for some object (if the ref_id exists),
146 and creating a relative pointer from the original object to the data that
149 /* Svlinks stand for short vlink, which is a link to a vdat
150 TODO: diff btwn vlink*/
156 /* A vlink is what it sounds like, a link to a vdat
163 /* Olinks are links to odats */
171 struct svlink svlink
;
175 int type
; //1 = olink, 2 = vlink, 3 = svlink
182 /* link_buf contains all the links that
183 we encountered during parse time that need
184 to be resolved to an offset at output time.
185 This does not include quad refs, because
186 those are already known to need to be resolved */
189 /* Odats: Odats consist of the object data necessary for
190 each object. Odats are sometimes referred to as archetypes
191 at compile-time, in order to distinguish the difference from
192 a runtime object and a compile-time object.
193 TODO: Need more info about objects at runtime, to described
194 the reasoning behind odat structure at compile-time*/
196 /* Each set has a quad_list or a list of quads. The quad_list
200 uint64_t ref_id
; //rgba
213 struct ref
* refp
; /* pointer to it's ref on ref_list */
217 struct odat
* curr_set_odatp
; //when a set has elements, insert_set() can no longer
218 //refer to its odat via curr_odat, so save the set odat.
220 /* A framesheet is a grouping of animation frames in
221 a single direction (N,W,S,E) */
226 void* frames
[MAX_FRAMES
];
229 /* A model is a collection of framesheets for every
230 direction (N,W,S,E,NW,NE,SW,SE)*/
231 /* NAMED spritesheet */
234 struct framesheet spritesheet
[8]; //one for each
237 /* Vdat: Vdats are the video data of each object. They can not be
238 created as a stand alone object (because they consist solely
239 of animation information and not the skeleton on which the
240 animation manipulates). Vdats have a list of models for every
241 animation that the vdats odat can do for that vdat*/
243 struct odat
* creator
; //pointer to odat that made this vdat
245 struct model model_list
[MAX_MODELS
];
248 /* Called after the cdat open operator has been recognized in grammar. Allocates
249 the space for a cdat on the cdat_buf, pushes that pointer onto
254 /* Called after a cdat end operator has been recognized in grammar. Sets
255 top stack cdat ** to null and decrements stack pointer */
259 /* Called after an odat has been populated. Allocates memory for
263 insert_set_label(char*, uint64_t);
265 /* Populate the sets representation in CURR_CDAT with a ref_id and insert a link
266 into the link_buf that will resolve the ref_id to an actual odat after parse time. */
268 insert_set_olink(uint64_t);
270 /* Put the vlink in the link_buf to be processed after parsetime */
272 insert_set_vlink(uint64_t, char*);
274 /* Put svlink in the link_buf to be processed after parsetime */
276 insert_set_svlink(uint64_t);
278 /* Called for every set reduction except for sets with olinks. Populates the
279 set data structures in the CDAT and in the ODAT. Uses the name and ref_id
280 from insert_set_label. Also inserts a ref into the ref_buf with the CURR_ODAT
281 pointer so that we can also resolve the odat from its ref_id. */
285 /* Insertion of eles is practically equivalent to how sets are inserted because both
286 share the same data type (ODAT). Like sets, eles have links, labels
287 and odats. Eles have the added notion of a parent set, and so must be inserted
288 into said parent set, but this is the only place they truly differ from sets. */
291 insert_set_vdatid(void);
294 insert_ele_label(char*, uint64_t);
296 /* Insert an ele olink into the CURR_ODAT */
298 insert_ele_olink(uint64_t);
300 /* Insert a ele vlink into CURR_ODAT*/
302 insert_ele_vlink(uint64_t, char*);
304 /* Inserts an ele short vlink into CURR_ODAT*/
306 insert_ele_svlink(uint64_t);
308 /* inserts ele into CURR_CLASS and CURR_ODAT */
313 insert_ele_vdatid(void);
315 /* Inserts the hitbox into the CURR_ODAT */
319 /* Inserts the root into the CURR_ODAT */
321 insert_root(int, int, int);
323 /* Inserts a quad into the CURR_ODAT */
331 insert_framesheet(char, char*, uint64_t, int, int, int);
334 insert_frame_pointer(char, void*);