-/*!@file
- \brief IR Memory Implementation
- \details Intermediary memory management
- \author Jordan Lavatai
- \date Aug 2016
- ----------------------------------------------------------------------------*/
-#include <errno.h>
-#include <stdio.h>
-#include <stdint.h> //uint64_t
-#include <string.h> //memmove
-#include <stdlib.h> //malloc
-#include <apc/ir.h>
-
-
-
-/* functions needed from irmem.c */
-extern
-void
-ir_init(void);
-
-extern
-struct cdat*
-alloc_cdat(void);
-
-extern
-struct odat*
-alloc_odat(void);
-
-extern
-void
-alloc_vdat(void);
-
-extern
-struct link*
-alloc_link(void);
-
-extern
-struct ref*
-alloc_ref(void);
-
-extern
-struct cdat*
-curr_cdat(void);
-
-extern
-struct odat*
-curr_odat(void);
-
-extern
-struct vdat*
-curr_vdat(void);
-
-extern
-struct ele*
-curr_ele(void);
-
-extern
-struct set*
-curr_set(void);
-
-extern
-struct ref*
-prev_ref(void);
-
-extern
-struct quad*
-curr_quad(void);
-
-extern
-struct model*
-curr_model(void);
-
-/* struct definitions needed from irmem.c */
-extern int num_cdats;
-extern struct cdat** cdat_stackp;
-extern struct odat* curr_set_odatp;
-extern uint64_t ss_ref_id;
-
-extern int num_vdats;
-/* Dynamically allocate memory for a class data structure,
- or cdat, after a class has been identified in a grammar.
- We also create a stack of class pointers so that
- we can access the cdat during processing of that
- cdats sets and elements, a requirement because the
- nature of recursive classes prevents us from accessing
- the cdat based on the previous index into cdat_buf,
- which is a list of all allocated cdats*/
-void
-push_cdat
-( char* name
-)
-{
- struct cdat* curr_cdatp;
-
- curr_cdatp = alloc_cdat();
-
- memmove(curr_cdatp->name, name, 32);
- curr_cdatp->idx = num_cdats;
-
- /* Set the cdat as a subclass of the previous cdat */
- (*cdat_stackp)->class_list[(*cdat_stackp)->num_classes] = curr_cdatp;
- /* Push the cdat onto the cdat_stack */
- *++cdat_stackp = curr_cdatp;
-
-}
-
-void
-pop_cdat
-()
-{
- *cdat_stackp = NULL;
- cdat_stackp--;
-}
-
-/* Called in the reduction of a set. While both odats (eles and sets)
- have identical label terminals, we are unable to give a single grammatical rule
- for both due to how we allocate odats in the odat buf. Due to the
- nature of bottom up parsing, the set label is recognized first, and then the
- sets elements are recognized. This means that after we have processed the sets elemenets,
- the curr_odat is going to be the last element and NOT the set that was first allocated.
- To get around this, we create a global variable set_odatp that will store the pointer
- to the odat when it is first allocated (in insert_set_label()) so that insert_set() can
- have access to it. */
-
-void
-insert_set_label
-( char* name,
- uint64_t ref_id
-)
-{
- struct set* curr_setp;
-
- curr_setp = curr_set();
- curr_set_odatp = alloc_odat();
-
- memmove(curr_set_odatp->name, name, 32);
- memmove(curr_setp->name, name, 32);
- curr_setp->ref_id = ref_id;
-
-}
-void
-insert_set_olink
-( uint64_t ref_id
-)
-{
- struct set* curr_setp;
- struct cdat* curr_cdatp;
- struct link* curr_linkp;
-
- curr_setp = curr_set();
- curr_cdatp = curr_cdat();
- curr_linkp = alloc_link();
-
- curr_setp->cdat_idx = curr_cdatp->idx;
- curr_setp->ref_id = ref_id; /* Will be resolved to offset
- when link is processed */
- curr_linkp->type = 1;
- curr_linkp->link_t.olink.ref_id = ref_id;
- curr_linkp->cdat_idx = curr_cdatp->idx;
- curr_linkp->set_idx = curr_cdatp->num_sets++;
- curr_linkp->ele_idx = -1;
-
-}
-
-void
-insert_set_vlink
-( uint64_t ref_id,
- char* anim_name
-)
-{
- struct cdat* curr_cdatp;
- struct link* curr_linkp;
-
- curr_cdatp = curr_cdat();
- curr_linkp = alloc_link();
-
- /* Insert vlink into link_stack so that it gets processed at
- output time */
- curr_linkp->type = 2;
- curr_linkp->link_t.vlink.ref_id = ref_id;
- curr_linkp->cdat_idx = curr_cdatp->idx;
- curr_linkp->set_idx = curr_cdatp->num_sets;
- curr_linkp->ele_idx = -1;
- memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);
-
-}
-
-/* Svlinks dont have animation names */
-void
-insert_set_svlink
-( uint64_t ref_id
-)
-{
- struct cdat* curr_cdatp;
- struct link* curr_linkp;
-
- curr_cdatp = curr_cdat();
- curr_linkp = alloc_link();
-
- /* Insert svlink into link_stack so that it gets processed at
- output time */
- curr_linkp->type = 3;
- curr_linkp->cdat_idx = curr_cdatp->idx;
- curr_linkp->set_idx = curr_cdatp->num_sets;
- curr_linkp->ele_idx = -1;
- curr_linkp->link_t.svlink.ref_id = ref_id;
-
-}
-
-/* At the point of reducing to a set, most of the
- sets odat information has already been populated
- during the reduction of its right hand side
- non terminals (hitbox, root, quad_list). */
-void
-insert_set
-()
-{ uint64_t ref_id;
- struct odat* curr_odatp;
- struct cdat* curr_cdatp;
- struct set* curr_setp;
- struct ref* prev_refp;
- struct ref* curr_refp;
- struct vdat* curr_vdatp;
-
- curr_odatp = curr_set_odatp; //allocated at insert_set_label, preserved in global space
- curr_cdatp = curr_cdat();
- curr_setp = curr_set();
- prev_refp = prev_ref();
- curr_refp = alloc_ref();
- curr_vdatp = curr_vdat();
-
- curr_vdatp->creator = curr_set_odatp;
-
- curr_setp->cdat_idx = curr_cdatp->idx; //does a set need its class idx?
- memmove(curr_setp->name, curr_odatp->name, 32);
- curr_cdatp->num_sets++;
-
- curr_odatp->cdat_idx = curr_cdatp->idx;
- curr_odatp->refp = curr_refp;
-
- ref_id = curr_setp->ref_id; // ref_id set by insert_set_label(name, ref_id)
-
- if(ref_id == -1) /* user did not define a ref_id */
- { ref_id = ss_ref_id;
- ss_ref_id++;
- }
-
- curr_refp->ref_id = ref_id;
- curr_refp->lastref = prev_refp;
- curr_refp->odatp = curr_odatp;
- prev_refp->nextref = curr_refp;
-
-
-
-}
-/* Created as a seperate function, instead of setting the ODATS vdat_id and
- calling inc_vdat() inside of insert_set(), to account for the set reduction
- where a vdat is not created (o/v/svlinks). */
-void
-insert_set_vdatid
-()
-{
- curr_set_odatp->vdat_id = num_vdats; //no vdat_id for odats that have vlinks/svlinks
- curr_set_odatp = NULL; //So this sets odat cant be modified after (which would be a bug)
-}
-
-/* Populates both the odat name and ref_id
- for odat and ele */
-void
-insert_ele_label
-( char* name,
- uint64_t ref_id
-)
-{
- struct ele* curr_elep;
- struct odat* curr_odatp;
-
- curr_elep = curr_ele();
- curr_odatp = alloc_odat();
-
- memmove(curr_odatp->name, name, 32);
-
- memmove(curr_elep->name, name, 32);
- curr_elep->ref_id = ref_id;
-}
-
-/* We don't make an odat here, at output time we will resolve
- the ref_id to the corresponding odat. */
-void
-insert_ele_olink
-( uint64_t ref_id
-)
-{
- struct cdat* curr_cdatp;
- struct set* curr_setp;
- struct ele* curr_elep;
- struct link* curr_linkp;
-
- curr_cdatp = curr_cdat();
- curr_elep = curr_ele();
- curr_linkp = alloc_link();
-
- curr_elep->cdat_idx = curr_cdatp->idx;
- curr_elep->ref_id = ref_id;
-
- curr_linkp->type = 1;
- curr_linkp->link_t.olink.ref_id = ref_id;
- curr_linkp->cdat_idx = curr_cdatp->idx;
- curr_linkp->set_idx = curr_cdatp->num_sets++;
- curr_linkp->ele_idx = curr_setp->num_ele++;
-
-}
-
-void
-insert_ele_vlink
-( uint64_t ref_id,
- char* anim_name
-)
-{
- struct cdat* curr_cdatp;
- struct set* curr_setp;
- struct link* curr_linkp;
-
- curr_cdatp = curr_cdat();
- curr_setp = curr_set();
- curr_linkp = alloc_link();
-
- /* Insert vlink into link_stack so that it gets processed at
- output time */
- curr_linkp->cdat_idx = curr_cdatp->idx;
- curr_linkp->type = 2;
- curr_linkp->set_idx = curr_cdatp->num_sets;
- curr_linkp->ele_idx = curr_setp->num_ele;
- curr_linkp->link_t.vlink.ref_id = ref_id;
- memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);
-
-}
-
-void
-insert_ele_svlink
-( uint64_t ref_id
-)
-{
- struct cdat* curr_cdatp;
- struct set* curr_setp;
- struct link* curr_linkp;
-
- curr_cdatp = curr_cdat();
- curr_setp = curr_set();
- curr_linkp = alloc_link();
-
- curr_linkp->cdat_idx = curr_cdatp->idx;
- curr_linkp->type = 3;
-
- curr_linkp->ele_idx = curr_setp->num_ele;
- curr_linkp->link_t.svlink.ref_id = ref_id;
-
-
-}
-
-//Insert element into odat_buf and cdatpages
-void
-insert_ele()
-{
- uint64_t ref_id;
- struct cdat* curr_cdatp;
- struct odat* curr_odatp;
- struct vdat* curr_vdatp;
- struct set* curr_setp;
- struct ele* curr_elep;
- struct ref* curr_refp;
- struct ref* prev_refp;
-
-
- curr_cdatp = curr_cdat();
- curr_odatp = curr_odat(); //malloced @ insert_ele_label
- curr_vdatp = curr_vdat();
- curr_setp = curr_set();
- curr_elep = curr_ele();
- curr_refp = alloc_ref();
- prev_refp = prev_ref();
-
- curr_vdatp->creator = curr_odatp;
- /* Populate ele in cdat */
- curr_elep->cdat_idx = curr_cdatp->idx;
- curr_setp->num_ele++;
-
- /* Populate odat for ele */
- curr_odatp->cdat_idx = curr_cdatp->idx;
- curr_odatp->refp = curr_refp;
-
- /* Add ele to ref_buf */
- ref_id = curr_elep->ref_id;
-
- if(ref_id == -1) /* user did not define a ref_id so */
- { ref_id = ss_ref_id;
- ss_ref_id++;
- }
-
- curr_refp->ref_id = ref_id;
- curr_refp->lastref = prev_refp;
- curr_refp->odatp = curr_odatp;
- prev_refp->nextref = curr_refp;
-
-}
-
-void
-insert_ele_vdatid
-()
-{ struct odat* curr_odatp;
- curr_odatp = curr_odat();
- curr_odatp->vdat_id = num_vdats;
-}
-
-void
-insert_quad
-( void* quad_filep
-)
-{
-
- /* struct quad* curr_quadp; */
- /* struct odat* curr_odatp; */
-
- /* curr_quadp = curr_quad(); */
- /* curr_odatp = curr_odat(); */
-
- /* curr_quadp->x = x; */
- /* curr_quadp->y = y; */
- /* curr_quadp->z = z; */
- /* curr_quadp->ref_id = ref_id; */
- /* curr_odatp->num_quads++; */
- struct odat* curr_odatp;
-
- curr_odatp->quad_filep = quad_filep;
-}
-
-/* Inserting the hitbox into the set
- odat. Elements that don't have
- a hitbox will use the sets root. */
-void
-insert_hitbox
-( int hitbox
-)
-{ struct odat* curr_odatp;
-
- curr_odatp = curr_odat();
- curr_odatp->hitbox = hitbox;
-}
-
-/* Inserting the root into the set
- odat. Elements that don't have
- a root will use the sets root. */
-void
-insert_root
-( int x,
- int y,
- int z
-)
-{ struct odat* curr_odatp;
-
- curr_odatp = curr_odat();
- curr_odatp->root.x = x;
- curr_odatp->root.y = y;
- curr_odatp->root.z = z;
-}
-
-
-void
-insert_framesheet
-( char direction,
- char* name,
- uint64_t ref_id,
- int height ,
- int width,
- int num_frames
-)
-{ struct vdat* curr_vdatp;
- struct model* curr_modelp;
-
- curr_vdatp = curr_vdat();
- curr_modelp = curr_model();
-
- curr_modelp->spritesheet[(int)direction].height = height;
- curr_modelp->spritesheet[(int)direction].width = width;
- curr_modelp->spritesheet[(int)direction].num_frames = num_frames;
- curr_vdatp->num_models++;
-}
-
-void
-insert_frame_pointer
-( char direction,
- void* frame
-)
-{ struct model* curr_modelp;
-
- curr_modelp = curr_model();
-
- curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame;
-}
-
+/*!@file\r
+ \brief IR Memory Implementation\r
+ \details Intermediary memory management\r
+ \author Jordan Lavatai\r
+ \date Aug 2016\r
+ ----------------------------------------------------------------------------*/\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <stdint.h> //uint64_t\r
+#include <string.h> //memmove\r
+#include <stdlib.h> //malloc\r
+#include <apc/ir.h>\r
+\r
+\r
+\r
+/* functions needed from irmem.c */\r
+extern\r
+void\r
+ir_init(void);\r
+\r
+extern\r
+struct cdat*\r
+alloc_cdat(void);\r
+\r
+extern\r
+struct odat*\r
+alloc_odat(void);\r
+\r
+extern\r
+void\r
+alloc_vdat(void);\r
+\r
+extern\r
+struct link*\r
+alloc_link(void);\r
+\r
+extern\r
+struct ref*\r
+alloc_ref(void);\r
+\r
+extern\r
+struct cdat*\r
+curr_cdat(void);\r
+\r
+extern\r
+struct odat*\r
+curr_odat(void);\r
+\r
+extern\r
+struct vdat*\r
+curr_vdat(void);\r
+\r
+extern\r
+struct set*\r
+curr_set(void);\r
+\r
+extern\r
+struct ref*\r
+curr_ref(void);\r
+\r
+extern\r
+struct quad*\r
+curr_quad(void);\r
+\r
+extern\r
+struct model*\r
+curr_model(void);\r
+\r
+/* struct definitions needed from irmem.c */\r
+extern int num_cdats;\r
+extern struct cdat** cdat_stackp;\r
+extern struct odat* curr_set_odatp;\r
+extern uint64_t ss_ref_id;\r
+\r
+extern int num_vdats;\r
+/* Dynamically allocate memory for a class data structure,\r
+ or cdat, after a class has been identified in a grammar.\r
+ We also create a stack of class pointers so that\r
+ we can access the cdat during processing of that\r
+ cdats sets and elements, a requirement because the\r
+ nature of recursive classes prevents us from accessing\r
+ the cdat based on the previous index into cdat_buf,\r
+ which is a list of all allocated cdats*/\r
+void\r
+push_cdat\r
+( char* name\r
+)\r
+{\r
+ struct cdat* curr_cdatp;\r
+\r
+ curr_cdatp = alloc_cdat();\r
+\r
+ memmove(curr_cdatp->name, name, 32);\r
+ curr_cdatp->idx = num_cdats;\r
+\r
+ /* Set the cdat as a subclass of the previous cdat */\r
+ (*cdat_stackp)->class_list[(*cdat_stackp)->num_classes] = curr_cdatp;\r
+ /* Push the cdat onto the cdat_stack */\r
+ *++cdat_stackp = curr_cdatp;\r
+\r
+}\r
+\r
+void\r
+pop_cdat\r
+()\r
+{\r
+ cdat_stackp--;\r
+}\r
+\r
+/* Called in the reduction of a set. While both odats (eles and sets)\r
+ have identical label terminals, we are unable to give a single grammatical rule\r
+ for both due to how we allocate odats in the odat buf. Due to the\r
+ nature of bottom up parsing, the set label is recognized first, and then the\r
+ sets elements are recognized. This means that after we have processed the sets elemenets,\r
+ the curr_odat is going to be the last element and NOT the set that was first allocated.\r
+ To get around this, we create a global variable set_odatp that will store the pointer\r
+ to the odat when it is first allocated (in insert_set_label()) so that insert_set() can\r
+ have access to it. Curr set points the sets representation in the cdat, curr_set_odatp\r
+ points to the sets representation as an odat*/\r
+\r
+void\r
+insert_set_label\r
+( char* name,\r
+ uint64_t ref_id\r
+)\r
+{\r
+\r
+ struct set* curr_setp;\r
+\r
+ curr_setp = curr_set();\r
+ curr_set_odatp = alloc_odat();\r
+\r
+ memmove(curr_set_odatp->name, name, 32);\r
+ memmove(curr_setp->name, name, 32);\r
+\r
+ if(ref_id != -1)\r
+ { curr_set_odatp->ref_id = ref_id;\r
+ curr_setp->ref_id = ref_id;\r
+ }\r
+ else\r
+ { curr_setp->ref_id = ss_ref_id;\r
+ curr_set_odatp->ref_id = ss_ref_id++;\r
+ }\r
+\r
+}\r
+\r
+/* Inserting a olink instead of a set. Set is really just a placeholder\r
+ for another set. Allocate the memory for the set so taht it can be populated*/\r
+void\r
+insert_set_olink\r
+( uint64_t ref_id\r
+)\r
+{\r
+ struct set* curr_setp;\r
+\r
+ curr_setp = curr_set();\r
+\r
+ curr_setp->ref_id = ref_id;\r
+\r
+}\r
+\r
+void\r
+insert_set_vlink\r
+( uint64_t ref_id,\r
+ char* anim_name\r
+)\r
+{\r
+ struct cdat* curr_cdatp;\r
+ struct odat* curr_odatp;\r
+ struct link* curr_linkp;\r
+\r
+\r
+ curr_cdatp = curr_cdat();\r
+ curr_odatp = curr_odat();\r
+ curr_linkp = alloc_link();\r
+\r
+ /* Insert vlink into link_stack so that it gets processed at\r
+ output time */\r
+ curr_linkp->type = 2;\r
+ /* Store the target odat information*/\r
+ curr_linkp->link_t.vlink.ref_id = ref_id;\r
+ memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
+ /* Store the linking odat/cdat information */\r
+ curr_linkp->classp = curr_cdatp;\r
+ curr_linkp->odatp = curr_odatp;\r
+ curr_linkp->set_idx = curr_cdatp->num_sets;\r
+ curr_linkp->ele_idx = -1;\r
+\r
+}\r
+\r
+/* Svlinks dont have animation names */\r
+void\r
+insert_set_svlink\r
+( uint64_t ref_id \r
+)\r
+{\r
+ struct cdat* curr_cdatp;\r
+ struct link* curr_linkp;\r
+\r
+ curr_cdatp = curr_cdat();\r
+ curr_linkp = alloc_link();\r
+\r
+ /* Insert svlink into link_stack so that it gets processed at\r
+ output time */\r
+ curr_linkp->type = 3;\r
+ curr_linkp->classp = curr_cdatp;\r
+ curr_linkp->set_idx = curr_cdatp->num_sets;\r
+ curr_linkp->ele_idx = -1;\r
+ curr_linkp->link_t.svlink.ref_id = ref_id;\r
+\r
+}\r
+\r
+/* At the point of reducing to a set, most of the\r
+ sets odat information has already been populated\r
+ during the reduction of its right hand side\r
+ non terminals (hitbox, root, quad_list). */\r
+void\r
+insert_set\r
+()\r
+{ uint64_t ref_id;\r
+ struct odat* curr_odatp;\r
+ struct cdat* curr_cdatp;\r
+ struct set* curr_setp;\r
+ struct ref* prev_refp;\r
+ struct ref* curr_refp;\r
+ struct vdat* curr_vdatp;\r
+\r
+ curr_odatp = curr_set_odatp; //allocated at insert_set_label, preserved in global space\r
+ curr_cdatp = curr_cdat();\r
+ curr_setp = curr_set();\r
+ prev_refp = curr_ref();\r
+ curr_refp = alloc_ref();\r
+ curr_vdatp = curr_vdat();\r
+\r
+ curr_vdatp->creator = curr_set_odatp;\r
+\r
+ curr_setp->cdat_idx = curr_cdatp->idx; //does a set need its class idx?\r
+ memmove(curr_setp->name, curr_odatp->name, 32);\r
+ curr_cdatp->num_sets++;\r
+\r
+ curr_odatp->cdat_idx = curr_cdatp->idx;\r
+ curr_odatp->refp = curr_refp;\r
+\r
+ ref_id = curr_setp->ref_id; // ref_id set by insert_set_label(name, ref_id)\r
+\r
+ curr_refp->ref_id = ref_id;\r
+ curr_refp->lastref = prev_refp;\r
+ curr_refp->odatp = curr_odatp;\r
+ prev_refp->nextref = curr_refp;\r
+\r
+\r
+\r
+}\r
+/* Created as a seperate function, instead of setting the ODATS vdat_id and\r
+ calling inc_vdat() inside of insert_set(), to account for the set reduction\r
+ where a vdat is not created (o/v/svlinks). */\r
+void\r
+insert_set_vdatid\r
+()\r
+{\r
+ struct vdat* curr_vdatp;\r
+\r
+ curr_vdatp = curr_vdat();\r
+\r
+ curr_set_odatp->vdat_id = num_vdats; //no vdat_id for odats that have vlinks/svlinks\r
+ curr_set_odatp->vdatp = curr_vdatp;\r
+ curr_set_odatp = NULL; //This sets odat shouldnt be modified after populating odats vdat info\r
+}\r
+\r
+/* Populates the odat name and ref_id for odat, allocate the odat here for the rest of\r
+ the functions to use via curr_odat(). */\r
+void\r
+insert_ele_label\r
+( char* name,\r
+ uint64_t ref_id\r
+)\r
+{\r
+ struct odat* curr_odatp;\r
+\r
+ curr_odatp = alloc_odat();\r
+\r
+ memmove(curr_odatp->name, name, 32);\r
+\r
+ if(ref_id != -1)\r
+ curr_odatp->ref_id = ref_id;\r
+ else\r
+ curr_odatp->ref_id = ss_ref_id++;\r
+\r
+}\r
+\r
+/* We don't make an odat here, at output time we will resolve\r
+ the ref_id to the corresponding odat. */\r
+void\r
+insert_ele_olink\r
+( uint64_t ref_id\r
+)\r
+{\r
+ /* Do nothing because we already know the ref_id that\r
+ the odat needs for this element (in the quad_file) */\r
+}\r
+\r
+void\r
+insert_ele_vlink\r
+( uint64_t ref_id,\r
+ char* anim_name\r
+)\r
+{\r
+ struct cdat* curr_cdatp;\r
+ struct set* curr_setp;\r
+ struct link* curr_linkp;\r
+\r
+ curr_cdatp = curr_cdat();\r
+ curr_setp = curr_set();\r
+ curr_linkp = alloc_link();\r
+\r
+ /* Insert vlink into link_stack so that it gets processed at\r
+ output time */\r
+ curr_linkp->classp = curr_cdatp;\r
+ curr_linkp->type = 2;\r
+ curr_linkp->set_idx = curr_cdatp->num_sets;\r
+ //curr_linkp->ele_idx = curr_setp->num_ele;\r
+ curr_linkp->link_t.vlink.ref_id = ref_id;\r
+ memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
+\r
+}\r
+\r
+void\r
+insert_ele_svlink\r
+( uint64_t ref_id\r
+)\r
+{\r
+ struct cdat* curr_cdatp;\r
+ struct set* curr_setp;\r
+ struct link* curr_linkp;\r
+\r
+ curr_cdatp = curr_cdat();\r
+ curr_setp = curr_set();\r
+ curr_linkp = alloc_link();\r
+\r
+ curr_linkp->classp = curr_cdatp;\r
+ curr_linkp->type = 3;\r
+\r
+ //curr_linkp->ele_idx = curr_setp->num_ele;\r
+ curr_linkp->link_t.svlink.ref_id = ref_id;\r
+\r
+\r
+}\r
+\r
+//Insert element into odat_buf and cdatpages\r
+void\r
+insert_ele()\r
+{\r
+ uint64_t ref_id;\r
+ struct cdat* curr_cdatp;\r
+ struct odat* curr_odatp;\r
+ struct vdat* curr_vdatp;\r
+ struct set* curr_setp;\r
+ struct ele* curr_elep;\r
+ struct ref* curr_refp;\r
+ struct ref* prev_refp;\r
+\r
+\r
+ curr_odatp = curr_odat(); //malloced @ insert_ele_label\r
+ curr_vdatp = curr_vdat();\r
+ curr_setp = curr_set();\r
+ prev_refp = curr_ref();\r
+ curr_refp = alloc_ref();\r
+\r
+ curr_vdatp->creator = curr_odatp;\r
+\r
+ /* Populate odat for ele */\r
+ curr_odatp->cdat_idx = curr_cdatp->idx;\r
+ curr_odatp->refp = curr_refp;\r
+\r
+ ref_id = curr_odatp->ref_id;\r
+\r
+ curr_refp->ref_id = ref_id;\r
+ curr_refp->lastref = prev_refp;\r
+ curr_refp->odatp = curr_odatp;\r
+ prev_refp->nextref = curr_refp;\r
+\r
+}\r
+\r
+void\r
+insert_ele_vdatid\r
+()\r
+{ struct odat* curr_odatp;\r
+ curr_odatp = curr_odat();\r
+ curr_odatp->vdat_id = num_vdats;\r
+}\r
+\r
+void\r
+insert_quad\r
+( void* quad_filep\r
+)\r
+{\r
+ struct odat* curr_odatp;\r
+\r
+ curr_odatp->quad_filep = quad_filep;\r
+}\r
+\r
+/* Inserting the hitbox into the set\r
+ odat. Elements that don't have\r
+ a hitbox will use the sets root. */\r
+void\r
+insert_hitbox\r
+( int hitbox\r
+)\r
+{ struct odat* curr_odatp;\r
+\r
+ curr_odatp = curr_odat();\r
+ curr_odatp->hitbox = hitbox;\r
+}\r
+\r
+/* Inserting the root into the set\r
+ odat. Elements that don't have\r
+ a root will use the sets root. */\r
+void\r
+insert_root\r
+( int x,\r
+ int y,\r
+ int z\r
+)\r
+{ struct odat* curr_odatp;\r
+\r
+ curr_odatp = curr_odat();\r
+ curr_odatp->root.x = x;\r
+ curr_odatp->root.y = y;\r
+ curr_odatp->root.z = z;\r
+}\r
+\r
+\r
+void\r
+insert_framesheet\r
+( char direction,\r
+ char* name,\r
+ uint64_t ref_id,\r
+ int height ,\r
+ int width,\r
+ int num_frames\r
+)\r
+{ struct vdat* curr_vdatp;\r
+ struct model* curr_modelp;\r
+\r
+ curr_vdatp = curr_vdat();\r
+ curr_modelp = curr_model();\r
+\r
+ curr_modelp->spritesheet[(int)direction].height = height;\r
+ curr_modelp->spritesheet[(int)direction].width = width;\r
+ curr_modelp->spritesheet[(int)direction].num_frames = num_frames;\r
+ curr_vdatp->num_models++;\r
+}\r
+\r
+void\r
+insert_frame_pointer\r
+( char direction,\r
+ void* frame\r
+)\r
+{ struct model* curr_modelp;\r
+\r
+ curr_modelp = curr_model();\r
+\r
+ curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame;\r
+}\r
+\r