-/*. We create new odats for each map variant that are children of the current odat/set\r
- , set their name as the map name, and identify them by marking them as a map. This lets\r
- us distinguish between sibling odatsthat have the same name because the map of the parent\r
- odat had the same name as another, regular odat*/\r
-#define CURR_SS_FRAME() (ss.set_frames[ss.curr_depth])\r
-#define CURR_SS_SETP() (CURR_SS_FRAME().setp)\r
-#define CURR_SS_ODATP() (CURR_SS_FRAME().odatp)\r
-void\r
-insert_map\r
-( name, direction, height, width, refid, filepath )\r
- struct name* name;\r
- int direction, height, width, refid;\r
- uint8_t* filepath;\r
-{ int i;\r
- struct odat* curr_mem_odatp; //pointer to odat in odat_buf\r
- struct set* curr_mem_setp; //pointer to set in set_buf\r
- struct link* linkp;\r
-\r
- curr_mem_odatp = alloc_odat();\r
- curr_mem_setp = alloc_set();\r
- //Create a new odat, make its parent be the set. Make a set for mdat, its name should\r
- //be the name of the odat + name of model. That makes a conflict beween odats that are named\r
- //the same thing as the model of a sibling odat that was created from a map. They can have\r
- //same name if the map odat is marked. So mark the map odat.\r
-\r
- //insert parent odat\r
- curr_mem_odatp->parent_odatp = CURR_SS_ODATP(); \r
- //insert into set_list\r
- if(CURR_SS_SETP()->num_sets < MAX_SETS)\r
- CURR_SS_SETP()->set_list[CURR_SS_SETP()->num_sets++] = curr_mem_setp;\r
- else\r
- { printf("You have allocated to many sets, error in insert_map()\n");\r
- //TODO: EXIT()\r
- }\r
- \r
- //indicate that newly created odat is a map\r
- curr_mem_odatp->ismap = 1;\r
- //set odat and set name\r
- name_u8_cpy(&curr_mem_odatp->name, name);\r
-\r
- /* set cdat idx values for both set and odat */\r
- curr_mem_setp->cdat_idx = num_cdats;\r
-\r
- /* TODO: INSERT MAP HEIGHT/WIDTH/NAME/FILEPATH INTO ODAT */\r
-\r
-\r
- /* Generate refid if needed, put into ref_buf */\r
- if(!refid)\r
- refid = ss_refid++;\r
-\r
- insert_ref(curr_mem_odatp, refid);\r
-\r
- /* If current odatp on stack has a link, then we need to make our own link. just set the vdat_idx */\r
- if(CURR_SS_ODATP()->vdat_idx == 0)\r
- { //alloc a link\r
- linkp = alloc_link();\r
- linkp->type = CURR_SS_ODATP()->linkp->type;\r
- linkp->dest_odatp = CURR_SS_ODATP();\r
- linkp->dest_refid = refid;\r
- linkp->link_t.mlink.src_refid = CURR_SS_ODATP()->linkp->link_t.mlink.src_refid;\r
-\r
- /* Copy the animation name of the vlink*/\r
- name_u8_cpy(&linkp->link_t.vlink.src_animname, &CURR_SS_ODATP()->linkp->link_t.vlink.src_animname);\r
- /* Copy the namelist of the vlink*/\r
- for(i = 0; i < MAX_DEPTH; i++)\r
- name_u8_cpy(&linkp->link_t.vlink.src_namelist[i], &CURR_SS_ODATP()->linkp->link_t.vlink.src_namelist[i]);\r
- }\r
- else\r
- curr_mem_odatp->vdat_idx = CURR_SS_ODATP()->vdat_idx;\r
-\r
- \r
- \r
- \r
-}\r
- \r
-\r
-/* 11/22 Each vdat has a multiple models. Each model has 8 framesheets, one in each\r
- direction, that create a spritesheet. Inserting framesheets into the correct \r
- model is just a matter of checking whether or not the last models name matches\r
-\r
- the current one. We can never get a framesheet that is for the same model before \r
- AND after some other model, due to alphasorting of the files in each directory */\r
-void\r
-insert_framesheet\r
-( model_name, direction, height, width, refid, filepath )\r
- struct name* model_name;\r
- int direction, height, width, refid;\r
- uint8_t* filepath;\r
-{ struct vdat* curr_vdatp;\r
- struct model* curr_modelp;\r
- static struct name last_model_name[32];\r
-\r
- \r
- curr_vdatp = curr_vdat();\r
-\r
- /* If the model name changed, that means there are no more\r
- framesheets for that model to be processed, a guaruntee we make\r
- b/c the filenames are alphabetically sorted */\r
- if(!name_u8_cmp(last_model_name, model_name))\r
- { if(curr_vdatp->num_models)\r
- curr_vdatp->num_models++;\r
- num_models++; // total number of models\r
- }\r
- \r
-\r
- if(CURR_SS_ODATP()->refid == 0)\r
- { if(!refid)\r
- refid = ss_refid++;\r
- insert_ref(CURR_SS_ODATP(), refid);//given a odatp and a refid, insert the odatp into the ref_buf.\r
- //push ref into ref_buf. \r
- } \r
- else\r
- printf("error: redefining a previously set refid\n");\r
- \r
- curr_modelp = curr_model(); \r
-\r
- name_u8_cpy(&curr_modelp->name, model_name);\r
- curr_modelp->spritesheet[direction].height = height;\r
- curr_modelp->spritesheet[direction].width = width;\r
- /* TODO: INSERT FILEPATH INTO VDAT */\r
- u8_stpncpy(curr_modelp->spritesheet[direction].filepath, filepath, FPATH_MAX);\r
-\r
- name_u8_cpy(last_model_name, model_name);\r
-\r
- \r
-}\r
-\r
-\r
-\r
-//src_path is stored in link_namelist\r
-void\r
-insert_mlink\r
-( src_mapname, src_refid)\r
- struct name* src_mapname;\r
- int src_refid;\r
-{ struct link* linkp;\r
- int i;\r
-\r
- linkp = alloc_link();\r
-\r
- /* set type */\r
- linkp->type = 3;\r
- /* set the name of the src map for the link, if a name exists */\r
- if(src_mapname)\r
- name_u8_cpy(&linkp->link_t.mlink.src_mapname, src_mapname);\r
- /* Set the source ref id of the link */\r
- linkp->link_t.mlink.src_refid = src_refid;\r
- /* Copy the entire namelist of the link, if it exists */\r
- for(i = 0; i < link_numnames; i--) //TODO MAX_DEPTH -> link_namelist_num??\r
- { name_u8_cpy(&linkp->link_t.mlink.src_namelist[i], &link_namelist[i]);\r
- name_u8_set(&link_namelist[i], (ucs4_t) 0);\r
- }\r
- link_numnames = 0;\r
- \r
- linkp->dest_odatp = CURR_SS_ODATP();//current odat on set_stack\r
-\r
-}\r
-\r
-void\r
-insert_link_name\r
-( name )\r
- struct name* name;\r
-{ \r
- //Push name onto current namelist, set the set_namelist.\r
- name_u8_cpy(&link_namelist[link_numnames++], name);\r
- \r
-}\r
-\r
-/* Nearly identical to mlink */\r
-void\r
-insert_vlink\r
-( src_animname, src_refid ) \r
- struct name* src_animname;\r
- int src_refid;\r
-{ struct link* linkp;\r
- int i;\r
-\r
- linkp = alloc_link();\r
-\r
- /* set type */\r
- linkp->type = 2;\r
- \r
- /* set the name of the src animname for the link, if a name exists */\r
- if(src_animname)\r
- name_u8_cpy(&linkp->link_t.vlink.src_animname, src_animname);\r
- \r
- /* Set the source ref id of the link */\r
- linkp->link_t.mlink.src_refid = src_refid;\r
- \r
- /* Copy the entire namelist of the link, if it exists */\r
- for(i = 0; i < link_numnames; i++) //TODO MAX_DEPTH -> link_namelist_num??\r
- { name_u8_cpy(&linkp->link_t.vlink.src_namelist[i], &link_namelist[i]);\r
- name_u8_set(&link_namelist[i], (ucs4_t) 0);//set to null for next link_namelist\r
- }\r
- \r
- linkp->dest_odatp = CURR_SS_ODATP();//current odat on set_stack\r
-\r
-}\r
-\r
-\r
-/* TODO: Do we really need to store the prev/next pointer? iterating through the \r
- ref_buf could be achieved by iterating until the num_refs anyway. */\r
-void\r
-insert_ref\r
-( odatp, refid )\r
- struct odat* odatp;\r
- int refid;\r
-{ struct ref* curr_refp;\r
- struct ref* prev_refp;\r
-\r
- curr_refp = alloc_ref();\r
- prev_refp = prev_ref();\r
-\r
- prev_refp->nextref = curr_refp;\r
- curr_refp->lastref = prev_refp;\r
-\r
- curr_refp->odatp = odatp;\r
- curr_refp->refid = refid;\r
-\r
- if(refid % 16)\r
- { POST_ALLOC();\r
- CURRENT_POST()->refid = refid;\r
- CURRENT_POST()->odatp = odatp;\r
- }\r
- \r
- \r
- \r
-}\r
-\r
-void\r
-insert_vdat\r
-()\r
-{ struct vdat* curr_vdatp;\r
-\r
- curr_vdatp = curr_vdat();\r
- \r
- curr_vdatp->creator = CURR_SS_ODATP();\r
- CURR_SS_ODATP()->vdat_idx = num_vdats;\r
- CURR_SS_ODATP()->vdatp = curr_vdatp;\r
- alloc_vdat();\r
-}\r
-\r
-void\r
-insert_refid\r
-( refid )\r
- int refid;\r
-{ CURR_SS_ODATP()->refid = refid;\r
-}\r
-#if 0\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
-//TODO: Add insert_set_ref()\r
-//TODO: Is this the correct allocation scheme? No do the one ken suggested\r
-void\r
-insert_s_name\r
-( struct name* name\r