-/* Structures allocated for and updated during parse time that
- are the IR before writing to the output file */
-
-#define BUFF_SIZE 256
-#define MAX_SUBCLASSES 16
-#define MAX_SETS 256
-#define MAX_ELES 256
-#define MAX_REFS 256
-#define MAX_MODELS 256
-
-//These IR buffers will be condensed into their respective output files.
-//parse_init() all to zero.
-struct cdat CB[BUFF_SIZE];
-struct vdat VB[BUFF_SIZE];
-struct odat OB[BUFF_SIZE];
-
-//indexes for buffers
-int cbi = 0;
-int vbi = 0;
-int obi = 0;
-
-struct cdat {
- char label[32];
- int num_subclasses;
- int num_sets;
- int subclass_index;
- int set_index;
- struct cdat subclass_list[MAX_SUBCLASSES];
- struct set set_list[MAX_SETS];
-};
-
-//Element or a set
-struct odat {
- char label[32];
- int vdat_id;
- int class_id;
- int num_ref;
- int ref_index;
- struct ref ref_list[MAX_REFS];
-};
-
-struct ref {
- int x, y, z, objref;
-};
-
-struct set {
- int odat_id;
- int parent_id;//offset into CB
- int num_ele;
- int ele_index; //same as num_ele?
- struct ele ele_list[MAX_ELES];
-};
-
-struct ele {
- int odat_id;
- int parent_id;//offset into class set_stack
-};
-
-//TODO: Do vdats need labels?
-struct vdat {
- int num_models;
- int msi; //model_stack_index
- struct model model_list[MAX_MODELS];
-};
-
-//8 ids for each direction
-//fdat_id ordered by alphabetical direction
-struct model {
- char label[32];
- int fdat_id[8];
-};
-
+/*!@file\r
+ \brief Intermediate Representation (IR) between Directory Structure and Engine Grammar\r
+ \details The IR serves as a storage structure that is populated during the\r
+ parsing of the input directory structure. After parsing is complete,\r
+ the IR will be condensed (removed of excess allocated space) and then\r
+ output as the Engine Grammar. In this file we describe the semantic actions\r
+ that are called at each step, and the memory buffers that they populate.\r
+ See parser.y for the description on how the input grammar is constructed,\r
+ and where/when semantic actions are called.\r
+ TODO: or just write it here.\r
+ \author Jordan Lavatai\r
+ \date Aug 2016\r
+ ----------------------------------------------------------------------------*/\r
+\r
+\r
+#include <stdint.h>\r
+\r
+#define BUF_SIZE 256\r
+#define MAX_SETS 256\r
+#define MAX_ELES 256\r
+#define MAX_QUADS 256\r
+#define MAX_MODELS 256\r
+#define MAX_POSTS 256\r
+#define MAX_CLASS_DEPTH 256\r
+#define MAX_CLASSES 256\r
+#define MAX_FRAMES 256\r
+#define PTRS_IN_PAGE 1024\r
+#define MAX_CHUNKS 256\r
+#define PAGES_PER_CHUNK 16\r
+\r
+/* Sets: elements. The set is populated at parse time AFTER the\r
+ elements are populated, due to the nature of bottom up parsing. */\r
+\r
+struct set {\r
+ char name[32];\r
+ uint64_t ref_id;\r
+ int cdat_idx;\r
+};\r
+\r
+/* Cdats: A cdat is a class data structure. Cdats serve as the central */\r
+/* data types of the IR. For each cdat, sets and element */\r
+/* ref_ids must be dereferenced to determine the odat information. Cdats */\r
+/* contain pointers to their subclasses so that the relationship between */\r
+/* classes can be determined, but the subclasses are not represented inside */\r
+/* of the cdat itself but rather in subsequent cdats in cdat_buf. We */\r
+/* can determine the number of subclasses (the last index into cdat_buf */\r
+/* that represents a subclass of some arbitrary cdat) each cdat has by */\r
+/* incrementing num_classes during parse time. */\r
+/* TODO: Should classes point to their parent class? */\r
+\r
+struct cdat {\r
+ char name[32];\r
+ int idx;\r
+ int num_classes;\r
+ int num_sets;\r
+ struct cdat* class_list[MAX_CLASSES];\r
+ struct set set_list[MAX_SETS];\r
+};\r
+\r
+/* The cdat_stack is a stack pointers to cdat pointers, the top of which is\r
+ the cdat that is currently being parsed. Whenever a new cdat is recognized\r
+ by the grammar (CLOPEN), a cdat is pushed onto the cdat_stack, and we refer\r
+ to this cdat through the macro CURR_CDAT. By keeping a cdat_stack, we have\r
+ access to the current cdat so that the elements and sets can populate themselves\r
+ in the cdat accordingly. */\r
+\r
+\r
+/* Refs: Each set/ele has a reference to its object data (odat) through a ref_id.\r
+ Ref_ids are unsigned 64 byte integers that map to the hex values RGBA. During\r
+ the construction of the directory structure, users can choose a RGBA value for\r
+ each object that any other object can refer to via links (see link). If a user\r
+ does not choose an RGBA value, then the object is given one from the system space.\r
+ We maintain a doubly linked list of refs in the ref_buf at parse time so that\r
+ links can be resolved after the parsing of the directory structure is complete.\r
+ For every 16th ref, we create a post so that we can reduce on the search time for\r
+ a random access. */\r
+\r
+struct ref {\r
+ int type;\r
+ struct ref* nextref;\r
+ struct ref* lastref;\r
+ struct odat* odatp;\r
+ uint64_t ref_id; //0xFFFFFF->digit\r
+};\r
+\r
+\r
+/* Links: At parse time, a set/ele can include a link in their\r
+ grammar representation instead of the actual data and this signifies\r
+ to the APC that that set/ele wishes to use the data of another\r
+ set/ele, either its video data (vdat) or object data (odat). The link\r
+ itself contains the type of link it is, the ref_id OR name, and\r
+ which set/ele created the link. During parse time, links can be made\r
+ to o/vdats that have yet to be parsed. In order to accomodate for this,\r
+ we resolve all links AFTER parse time by iterating through the link_buf,\r
+ finding the ref_id that was stored for some object (if the ref_id exists),\r
+ and creating a relative pointer from the original object to the data that\r
+ was linked */\r
+\r
+/* Svlinks stand for short vlink, which is a link to a vdat. svlinks\r
+ differ from vlinks because they do not have a name */\r
+\r
+struct svlink {\r
+ uint64_t ref_id;\r
+};\r
+\r
+/* A vlink is what it sounds like, a link to a vdat */\r
+struct vlink {\r
+ uint64_t ref_id;\r
+ char anim_name[32];\r
+};\r
+\r
+union link_t {\r
+ struct vlink vlink;\r
+ struct svlink svlink;\r
+};\r
+\r
+/* From: src odat ()To: dest odat (ref_id)*/\r
+struct link {\r
+ int type; //1 = olink, 2 = vlink, 3 = svlink\r
+ union link_t link_t;\r
+ struct cdat* classp;\r
+ struct odat* odatp;\r
+ int set_idx;\r
+ int ele_idx;\r
+};\r
+\r
+\r
+/* Odats: Odats consist of the object data necessary for\r
+ each object. Odats are sometimes referred to as archetypes\r
+ at compile-time, in order to distinguish the difference from\r
+ a runtime object and a compile-time object.\r
+ TODO: Need more info about objects at runtime, to described\r
+ the reasoning behind odat structure at compile-time*/\r
+\r
+struct root {\r
+ int x, y, z;\r
+};\r
+\r
+struct odat {\r
+ char name[32];\r
+ struct vdat* vdatp;\r
+ int vdat_id; //\r
+ int cdat_idx;\r
+ int hitbox;\r
+ uint64_t ref_id;\r
+ struct root root;\r
+ struct ref* refp; /* pointer to it's ref on ref_list */\r
+ void* quad_filep;\r
+};\r
+\r
+struct odat* curr_set_odatp; //when a set has elements, insert_set() can no longer\r
+ //refer to its odat via curr_odat, so save the set odat. \r
+\r
+/* A framesheet is a grouping of animation frames in\r
+ a single direction (N,W,S,E) */\r
+struct framesheet {\r
+ int width;\r
+ int height;\r
+ int num_frames;\r
+ void* frames[MAX_FRAMES];\r
+};\r
+\r
+/* A model is a collection of framesheets for every\r
+ direction (N,W,S,E,NW,NE,SW,SE)*/\r
+/* NAMED spritesheet */\r
+struct model {\r
+ char name[32];\r
+ struct framesheet spritesheet[8]; //one for each\r
+};\r
+\r
+/* Vdat: Vdats are the video data of each object. They can not be\r
+ created as a stand alone object (because they consist solely\r
+ of animation information and not the skeleton on which the\r
+ animation manipulates). Vdats have a list of models for every\r
+ animation that the vdats odat can do for that vdat*/\r
+struct vdat {\r
+ struct odat* creator; //pointer to odat that made this vdat\r
+ int num_models;\r
+ struct model model_list[MAX_MODELS];\r
+};\r
+\r
+/* Called after the cdat open operator has been recognized in grammar. Allocates\r
+ the space for a cdat on the cdat_buf, pushes that pointer onto\r
+ the cdat_stack */\r
+void\r
+push_cdat(char*);\r
+\r
+/* Called after a cdat end operator has been recognized in grammar. Sets\r
+ top stack cdat ** to null and decrements stack pointer */\r
+void\r
+pop_cdat(void);\r
+\r
+/* Called after an odat has been populated. Allocates memory for\r
+ the next odat. */\r
+\r
+void\r
+insert_set_label(char*, uint64_t);\r
+\r
+/* Populate the sets representation in CURR_CDAT with a ref_id and insert a link\r
+ into the link_buf that will resolve the ref_id to an actual odat after parse time. */\r
+void\r
+insert_set_olink(uint64_t);\r
+\r
+/* Put the vlink in the link_buf to be processed after parsetime */\r
+void\r
+insert_set_vlink(uint64_t, char*);\r
+\r
+/* Put svlink in the link_buf to be processed after parsetime */\r
+void\r
+insert_set_svlink(uint64_t);\r
+\r
+/* Called for every set reduction except for sets with olinks. Populates the\r
+ set data structures in the CDAT and in the ODAT. Uses the name and ref_id\r
+ from insert_set_label. Also inserts a ref into the ref_buf with the CURR_ODAT\r
+ pointer so that we can also resolve the odat from its ref_id. */\r
+void\r
+insert_set(void);\r
+\r
+/* Insertion of eles is practically equivalent to how sets are inserted because both\r
+ share the same data type (ODAT). Like sets, eles have links, labels\r
+ and odats. Eles have the added notion of a parent set, and so must be inserted\r
+ into said parent set, but this is the only place they truly differ from sets. */\r
+\r
+void\r
+insert_set_vdatid(void);\r
+\r
+void\r
+insert_ele_label(char*, uint64_t);\r
+\r
+/* Insert an ele olink into the CURR_ODAT */\r
+void\r
+insert_ele_olink(uint64_t);\r
+\r
+/* Insert a ele vlink into CURR_ODAT*/\r
+void\r
+insert_ele_vlink(uint64_t, char*);\r
+\r
+/* Inserts an ele short vlink into CURR_ODAT*/\r
+void\r
+insert_ele_svlink(uint64_t);\r
+\r
+/* inserts ele into CURR_CLASS and CURR_ODAT */\r
+void\r
+insert_ele(void);\r
+\r
+void\r
+insert_ele_vdatid(void);\r
+\r
+/* Inserts the hitbox into the CURR_ODAT */\r
+void\r
+insert_hitbox(int);\r
+\r
+/* Inserts the root into the CURR_ODAT */\r
+void\r
+insert_root(int, int, int);\r
+\r
+/* Inserts a quad into the CURR_ODAT */\r
+void\r
+insert_quad(void*);\r
+\r
+void\r
+insert_model(void);\r
+\r
+void\r
+insert_framesheet(char, char*, uint64_t, int, int, int);\r
+\r
+void\r
+insert_frame_pointer(char, void*);\r
+\r
+void\r
+alloc_vdat(void);\r