\author Jordan Lavatai\r
\date Aug 2016\r
----------------------------------------------------------------------------*/\r
-#include <stdlib.h>\r
-#include <stdio.h>\r
-#include <unitypes.h> //uint8_t as a char\r
-#include <unistr.h> //u32_cpy\r
+/* Standard */\r
+#include <stdlib.h> //exit, malloc\r
+#include <stdio.h> //print\r
+#include <stdarg.h> //va_args\r
#include <stdint.h> //uint64_t\r
-#include <string.h> //memset\r
-#include <unistd.h> //u8_* functions\r
+#include <string.h> //memset, str*\r
+#include <errno.h>\r
+/* Unicode */\r
+#include <unistd.h> //u8_* functions\r
+#include <unitypes.h> //uint8_t as a char\r
+#include <unistr.h> //u32_cpy\r
+#include <unistdio.h> //ulc_fprintf\r
+/* Local */\r
+#include "print.h"\r
#include "apc.h"\r
-\r
-\r
-extern\r
-int\r
-name_u8_cpy(struct name*, struct name*);\r
-\r
-extern\r
-int\r
-name_u8_cmp(struct name*, struct name*);\r
-\r
-extern\r
-int\r
-name_u8_set(struct name*, ucs4_t);\r
-\r
-int\r
-ir_init(void);\r
-struct cdat*\r
-alloc_cdat(void);\r
-struct odat*\r
-alloc_odat(void);\r
-void\r
-alloc_vdat(void);\r
-struct link*\r
-alloc_link(void);\r
-struct ref*\r
-alloc_ref(void);\r
-struct set*\r
-alloc_set(void);\r
-struct cdat*\r
-curr_cdat(void);\r
-struct odat*\r
-curr_odat(void);\r
-struct vdat*\r
-curr_vdat(void);\r
-struct map*\r
-curr_map(void);\r
-struct set*\r
-curr_cdat_set(void);\r
-struct set*\r
-curr_set(int);\r
-struct ref*\r
-curr_ref(void);\r
-struct model*\r
-curr_model(void);\r
-\r
-/* ir.c */\r
-void\r
-inc_posts(void);\r
-void\r
-push_cdat(struct name*);\r
-void\r
-pop_cdat(void);\r
-void\r
-insert_link_name(struct name*);\r
-void\r
-insert_link_namelist(struct name*);\r
-void\r
-insert_ss_name(struct name*);\r
-void\r
-insert_ss_namelist(struct name*);\r
-void\r
-insert_mlink(struct name*, int);\r
-void\r
-insert_vlink(struct name*, int);\r
-void\r
-insert_ref(struct odat*, int);\r
-void\r
-alloc_vdat(void);\r
-void\r
-insert_vdat(void);\r
-void\r
-insert_map(struct name*, int, int, int, int, uint8_t*);\r
-void\r
-insert_framesheet(struct name*, int, int, int, int, uint8_t*);\r
-\r
-\r
-\r
-//type safety handled by macro expansion (do not call these directly from code, make dependent macros for access to these)\r
-#define CHUNKS_LEN(STACK) ((STACK).csp - (STACK).chunks)\r
-#define CURRENT_CHUNK(STACK) ((STACK).chunks[CHUNKS_LEN(STACK) - 1])\r
-#define CHUNKS_FULL(STACK) ( (STACK).csp >= \\r
- (STACK).chunks + MAX_CHUNKS * (STACK).chunk_size)\r
-#define CURRENT_DSP(STACK,TYPE) ((TYPE*) ((STACK).dsp[CHUNKS_LEN(STACK) - 1]))\r
-#define DATA_FULL(STACK,TYPE) ((void*) CURRENT_DSP(STACK,TYPE) >= \\r
- (CURRENT_CHUNK(STACK) + (STACK).chunk_size))\r
-#define CSP_PUSH(STACK) (*(++(STACK).csp) = malloc((STACK).chunk_size))\r
-#define CURRENT_DATP(STACK,TYPE) (((TYPE**)(STACK).dsp)[CHUNKS_LEN(STACK) - 1])\r
-#define PREVIOUS_DATP(STACK,TYPE) (((TYPE**)(STACK).dsp)[CHUNKS_LEN(STACK) - 2])\r
-#define ALLOC_DAT(STACK,TYPE) (++CURRENT_DATP(STACK,TYPE))\r
-#define INIT_STACK(STACK,TYPE) \\r
- { int i; \\r
- (STACK).chunk_size = PAGES_PER_CHUNK * pagesize; \\r
- (STACK).max_dats = (STACK).chunk_size / sizeof (TYPE); \\r
- CSP_PUSH(STACK); \\r
- for( i = 0; i < MAX_CHUNKS; i++){ \\r
- (STACK).dsp[i] += pagesize; \\r
- } \\r
- }\r
-//Stack-specific macros (called directly from code (safety enforcement)\r
-#define INIT_ODAT() (INIT_STACK(ocs, struct odat))\r
-#define CURRENT_ODAT() (CURRENT_DATP(ocs,struct odat))\r
-#define ODAT_FULL() (DATA_FULL(ocs,struct odat))\r
-#define ODAT_ALLOC() (ALLOC_DAT(ocs,struct odat))\r
-#define OCS_FULL() (CHUNKS_FULL(ocs))\r
-#define INIT_VDAT() (INIT_STACK(vcs, struct vdat))\r
-#define CURRENT_VDAT() (CURRENT_DATP(vcs,struct vdat))\r
-#define VDAT_FULL() (DATA_FULL(vcs,struct vdat))\r
-#define VDAT_ALLOC() (ALLOC_DAT(vcs,struct vdat))\r
-#define VCS_FULL() (CHUNKS_FULL(vcs))\r
-#define INIT_CDAT() (INIT_STACK(ccs, struct cdat))\r
-#define CURRENT_CDAT() (CURRENT_DATP(ccs,struct cdat))\r
-#define CDAT_FULL() (DATA_FULL(ccs, struct cdat))\r
-#define CDAT_ALLOC() (ALLOC_DAT(ccs, struct cdat))\r
-#define CCS_FULL() (CHUNKS_FULL(ccs))\r
-#define INIT_SET() (INIT_STACK(scs, struct set))\r
-#define CURRENT_SET() (CURRENT_DATP(scs, struct set))\r
-#define SET_FULL() (DATA_FULL(scs, struct set))\r
-#define SET_ALLOC() (ALLOC_DAT(scs, struct set))\r
-#define SCS_FULL() (CHUNKS_FULL(scs))\r
-#define INIT_LINK() (INIT_STACK(lcs, struct link))\r
-#define CURRENT_LINK() (CURRENT_DATP(lcs,struct link))\r
-#define LDAT_FULL() (DATA_FULL(lcs, struct link))\r
-#define LDAT_ALLOC() (ALLOC_DAT(lcs, struct link))\r
-#define LCS_FULL() (CHUNKS_FULL(lcs))\r
-#define INIT_POST() (INIT_STACK(rcs, struct ref))\r
-#define CURRENT_POST() (CURRENT_DATP(pcs,struct ref))\r
-#define POST_FULL() (DATA_FULL(pcs,struct ref))\r
-#define POST_ALLOC() (ALLOC_DAT(pcs,struct ref))\r
-#define PCS_FULL() (CHUNKS_FULL(pcs))\r
-#define INIT_REF() (INIT_STACK(rcs, struct ref))\r
-#define CURRENT_REF() (CURRENT_DATP(rcs,struct ref))\r
-#define PREVIOUS_REF() (PREVIOUS_DATP(rcs, struct ref))\r
-#define REF_FULL() (DATA_FULL(rcs,struct ref))\r
-#define REF_ALLOC() (ALLOC_DAT(rcs,struct ref))\r
-#define RCS_FULL() (CHUNKS_FULL(rcs))\r
-//Metadata\r
-#define CURRENT_MODEL() (CURRENT_VDAT()->model_list[CURRENT_VDAT()->num_models])\r
-\r
-\r
-\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
-/* Cdats: A cdat is a class data structure. Cdats serve as the central */\r
-/* data types of the IR. Cdats 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
-/* TODO: Talk more about cdat set structure */\r
-struct cdat {\r
- struct name name;\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
-\r
-/* Sets: What is a set? \r
- Instantiation?\r
- Associations? \r
- Containment?\r
- Usage?\r
- The set is populated at parse time AFTER the elements are populated, due to\r
- the nature of bottom up parsing. */\r
-struct set {\r
- int cdat_idx;\r
- int num_sets;\r
- struct set* set_list[MAX_SETS];\r
-};\r
-\r
-/* Refs: Each set/ele has a reference to its object data (odat) through a refid.\r
- refids 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; //TODO: Is this needed?\r
- struct ref* nextref;\r
- struct ref* lastref;\r
- struct odat* odatp;\r
- int refid; //0xFFFFFF->digit\r
+#include "ir.h"\r
+#include "pagenode.h"\r
+#undef do_error\r
+#define do_error(...) exit(-1)\r
+#define XXH_PRIVATE_API\r
+#include "../xxHash/xxhash.h"\r
+/* Public */\r
+int ir_init(void);\r
+void ir_quit(void);\r
+void ir_test(void);\r
+int ir_linker(void);\r
+int ir_condenser(void);\r
+/* Set data mem */\r
+enum dtype { FSDAT, MSDAT, ADAT, LDAT, FBDAT };\r
+struct ir_namelist_t;\r
+struct ir_namelist_t\r
+{ struct ir_namelist_t* nextsib;\r
+ uint8_t* name;\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 refid 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 refid that was stored for some object (if the refid exists),\r
- and creating a relative pointer from the original object to the data that\r
- was linked */\r
-\r
-/* TODO: Explain links more betta */\r
-\r
-struct olink {\r
- int src_refid;\r
+struct ir_classld_t\r
+{ struct ir_class_t* root_class;\r
+ struct ir_namelist_t* namelist, * namelist_head;\r
};\r
- \r
-struct vlink {\r
- int src_refid;\r
- struct name src_animname;\r
- struct name src_namelist[MAX_DEPTH];\r
+struct ir_setld_t\r
+{ struct ir_classld_t* classld;\r
+ long long ref;\r
+ struct ir_namelist_t* namelist, * namelist_head;\r
};\r
-\r
-struct mlink {\r
- int src_refid;\r
- struct name src_mapname;\r
- struct name src_namelist[MAX_DEPTH];\r
-\r
+struct ir_setdata_header_t\r
+{ enum dtype type;\r
+ uint8_t* src_filename, * data_name;\r
+ union ir_setdata_t* nextsib;\r
};\r
-\r
-union link_t {\r
- struct vlink vlink;\r
- struct mlink mlink;\r
- struct olink olink;\r
+struct ir_framedata_t\r
+{ struct ir_setdata_header_t header;\r
+ struct ir_frameinfo_t frameinfo;\r
};\r
-\r
-\r
-/* From: src odat ()To: dest odat (refid)*/\r
-struct link {\r
- int type; //1 = olink, 2 = vlink, 3 = mlink\r
- union link_t link_t;\r
- int dest_refid; //if it exists\r
- struct odat* dest_odatp;\r
-\r
+struct ir_framebox_t\r
+{ struct ir_setdata_header_t header;\r
+ struct ir_framedata_t framesheets[FACING_MAX];\r
+ struct ir_framedata_t mapsheets[FACING_MAX];\r
};\r
-\r
-struct map {\r
- struct name name;\r
- int height;\r
- int width;\r
- uint8_t filepath[FPATH_MAX];\r
+struct ir_simplex_t { struct ir_setdata_header_t header; };\r
+struct ir_link_t\r
+{ struct ir_setdata_header_t header;\r
+ struct ir_classld_t* classld;\r
+ struct ir_setld_t* setld;\r
+ enum ltype type;\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
-struct odat {\r
- struct name name;\r
- int refid; \r
- int ismap;\r
- int vdat_idx;\r
- struct link* linkp; \r
- struct vdat* vdatp;\r
- struct odat* parent_odatp; // odat == set ? null : set refid\r
- struct ref* refp; /* pointer to it's ref on ref_list */\r
- struct map map; //only valid if odat ismap\r
-\r
+union ir_setdata_t\r
+{ struct ir_setdata_header_t header;\r
+ struct ir_framebox_t framebox;\r
+ struct ir_framedata_t framesheet;\r
+ struct ir_framedata_t mapsheet;\r
+ struct ir_simplex_t audio;\r
+ struct ir_link_t link;\r
};\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
-\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
- struct name name;\r
- uint8_t filepath[PATH_MAX];\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 map 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
- uint8_t filename[FNAME_MAX];\r
- int height;\r
- int width;\r
- uint8_t filepath[FPATH_MAX];\r
- struct model model_list[MAX_MODELS];\r
+struct ir_class_t\r
+{ struct ir_class_t* nextchild, * nextsib;\r
+ struct ir_set_t* root_set;\r
+ uint8_t* name;\r
};\r
-\r
-\r
-struct set_frame\r
-{ struct name namelist[MAX_DEPTH];\r
- int num_names;\r
- struct set* setp;\r
- struct odat* odatp;\r
-} ;\r
-\r
-\r
-\r
-struct set_stack\r
-{ struct set_frame set_frames[MAX_DEPTH];\r
- int curr_depth; //used to get most recently created set/odat + to check for undefined parents of namelists\r
+struct ir_set_t\r
+{ struct ir_set_t* nextchild, * nextsib;\r
+ uint32_t ref;\r
+ uint8_t* name;\r
+ struct ir_framebox_t* frameboxes;\r
+ struct ir_simplex_t* audio;\r
+ struct ir_link_t* links;\r
+ long filepos;\r
};\r
-\r
-\r
-//"type free" chunk stacking\r
-struct chunk_stack\r
-{ void* chunks[MAX_CHUNKS];\r
- void* *csp; //chunk stack pointer\r
- void* dsp[MAX_CHUNKS]; //dat stack pointer (per chunk)\r
- int chunk_size; //size of a chunk (including its forfeited page)\r
- int max_dats; //number of dats per chunk for this stack\r
-} ocs, vcs, ccs, rcs, lcs, pcs, scs; //odat, vdat, cdat, ref, link, post stacks\r
-\r
-\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
-struct cdat* cdat_stack[MAX_CLASSES];\r
-struct cdat** cdat_stackp;\r
-\r
-struct set_stack ss;\r
-struct name set_namelist[MAX_DEPTH];\r
-int set_numnames = 0;\r
-\r
-struct name link_namelist[MAX_DEPTH];\r
-int link_numnames = 0;\r
-\r
-int num_cdats = 0;\r
-int num_odats = 0;\r
-int num_vdats = 0;\r
-int num_sets = 0;\r
-int num_refs = 0;\r
-int ss_refid = 0x0FFFFFFF; /* system space for refids */\r
-int num_posts = 0;\r
-int num_links = 0;\r
-int num_models = 0;\r
-long pagesize = 0;\r
-\r
-\r
-/* The initalization function of the IR. */\r
-int\r
-ir_init()\r
-{ struct name name;\r
-\r
-\r
- uint8_t root[4] = "root";\r
-\r
- u8_stpncpy(name.name, root, 4);\r
-\r
- pagesize = sysconf(_SC_PAGESIZE);\r
- printf("pagesize is %l\n", pagesize);\r
-\r
- INIT_CDAT();\r
- *cdat_stackp = CURRENT_CDAT();\r
- name_u8_cpy(&(*cdat_stackp)->name, &name);\r
-\r
- INIT_ODAT();\r
- INIT_VDAT();\r
- VDAT_ALLOC(); //NULL vdat\r
- VDAT_ALLOC(); //First vdat req. because alloc_vdat happens after vdat is reduced\r
- INIT_SET();\r
- INIT_LINK();\r
- INIT_REF();\r
- INIT_POST();\r
-\r
+/* Functions */\r
+static inline\r
+struct ir_framebox_t* ir_set_add_framebox(struct ir_set_t*,uint8_t*);\r
+static inline\r
+union ir_setdata_t* ir_framedata (enum dtype,const uint8_t*,apc_facing,int,int);\r
+static inline\r
+int bytes_identical(const uint8_t*,const uint8_t*);\r
+static inline\r
+int classnames_identical(const uint8_t*,const uint8_t*);\r
+static\r
+uint8_t* name_alloc(const uint8_t*);\r
+static\r
+uint8_t* classname_alloc(const uint8_t*);\r
+#define struct_clear(_S) (memset((_S), 0, sizeof(*(_S))))\r
+#define REFHASH(ref) (XXH32(&ref, sizeof(uint32_t), 0xCEED) & 0xCFF)\r
+#define struct_alloc(_T) ((struct _T*) stack_alloc(&datapages, sizeof(struct _T)))\r
+extern //apc.c\r
+long sys_pagesize;\r
+static\r
+struct pagelist_t datapages, namepages, refhashpages;\r
+static\r
+struct ir_class_t root_class = { .name = (uint8_t*)"." };\r
+\r
+/* Init */\r
+int ir_init\r
+( void )\r
+{ pagelist_init(datapages, (size_t)SYS_PAGESIZE);\r
+ pagelist_init(namepages, (size_t)NAME_PAGESIZE);\r
+ pagelist_init(refhashpages, (size_t)SYS_PAGESIZE);\r
\r
return 0;\r
-\r
}\r
\r
-void\r
-ir_quit()\r
-{\r
- int i;\r
-\r
- for(i = 0; i < CHUNKS_LEN(ccs) ; i++)\r
- {\r
- free(ccs.chunks[i]);\r
- }\r
- for(i = 0; i < CHUNKS_LEN(ocs); i++)\r
- {\r
- free(ocs.chunks[i]);\r
- }\r
- for(i = 0; i < CHUNKS_LEN(vcs) ; i++)\r
- {\r
- free(vcs.chunks[i]);\r
- }\r
- for(i = 0; i < CHUNKS_LEN(rcs); i++)\r
- {\r
- free(rcs.chunks[i]);\r
- }\r
- for(i = 0; i < CHUNKS_LEN(lcs); i++)\r
- {\r
- free(lcs.chunks[i]);\r
- }\r
- for(i = 0; i < CHUNKS_LEN(pcs); i++)\r
- {\r
- free(pcs.chunks[i]);\r
- }\r
+/* Quit/Cleanup */\r
+void ir_quit\r
+( void )\r
+{ pagenode_free(datapages.root);\r
+ pagenode_free(namepages.root);\r
+ pagenode_free(refhashpages.root);\r
\r
}\r
\r
-struct cdat*\r
-alloc_cdat()\r
-{\r
- num_cdats++;\r
- if(CDAT_FULL())\r
- { if(CCS_FULL())\r
- { fprintf(stderr, "You have allocated to many (%d) cdats ", num_cdats);\r
- exit(EXIT_FAILURE);\r
- }\r
- else\r
- CSP_PUSH(ccs);\r
- }\r
- else\r
- CDAT_ALLOC();\r
-\r
- return CURRENT_CDAT();\r
+/* Link */\r
+int ir_linker\r
+( void )\r
+{ \r
+ return 0;\r
}\r
\r
-//these should probably be inline\r
-struct odat*\r
-alloc_odat\r
-()\r
-{\r
- num_odats++;\r
- if(ODAT_FULL())\r
- { if(!OCS_FULL())\r
- { fprintf(stderr, "You have allocated to many (%d) odats ", num_odats);\r
- exit(EXIT_FAILURE);\r
- }\r
- else\r
- CSP_PUSH(ocs);\r
+/* Condense */\r
+int ir_condenser\r
+( void )\r
+{ return 0; }\r
+\r
+/* Return the class's name string */\r
+uint8_t* ir_class_name\r
+( struct ir_class_t* class )\r
+{ return class->name; }\r
+\r
+/* Return a pointer to the root class */\r
+struct ir_class_t* ir_class_root\r
+( void )\r
+{ return &root_class; }\r
+\r
+/* Add a subclass to a class\r
+ Attempts to create a new subclass in the provided class, returning\r
+ the class if it already exists\r
+*/\r
+struct ir_class_t* ir_class_addchild\r
+( struct ir_class_t* class,\r
+ const uint8_t* name\r
+)\r
+{ struct ir_class_t* iter;\r
+ if (class->nextchild == NULL)\r
+ { class->nextchild = struct_alloc(ir_class_t);\r
+ struct_clear(class->nextchild);\r
+ class->nextchild->name = classname_alloc(name);\r
+ return class->nextchild;\r
}\r
- else\r
- ODAT_ALLOC();\r
-\r
- return CURRENT_ODAT();\r
-}\r
-\r
-void\r
-alloc_vdat\r
-()\r
-{ num_vdats++;\r
- if(VDAT_FULL())\r
- { if(!VCS_FULL())\r
- { fprintf(stderr, "You have allocated to many (%d) vdats ", num_vdats);\r
- exit(EXIT_FAILURE);\r
- }\r
- else\r
- CSP_PUSH(vcs);\r
+ iter = class->nextchild;\r
+ if (iter->name == NULL)\r
+ eprintf("Null name pointer in class %p\n", iter);\r
+ if (name == NULL)\r
+ eprintf("Null child added to class %s\n", iter->name);\r
+ check:\r
+ if (classnames_identical(iter->name, name))\r
+ return iter;\r
+ if (iter->nextsib != NULL)\r
+ { iter = iter->nextsib;\r
+ goto check;\r
}\r
- else\r
- VDAT_ALLOC();\r
-\r
- \r
-}\r
-\r
-struct set* \r
-alloc_set\r
-()\r
-{ num_sets++;\r
- if(SET_FULL())\r
- { if(!SCS_FULL())\r
- { fprintf(stderr, "You have allocated to many (%d) sets ", num_sets);\r
- exit(EXIT_FAILURE);\r
- }\r
- else\r
- CSP_PUSH(scs);\r
+ iter->nextsib = struct_alloc(ir_class_t);\r
+ struct_clear(iter->nextsib);\r
+ iter->nextsib->name = classname_alloc(name);\r
+ return iter->nextsib;\r
+}\r
+\r
+/* Add a set to a class\r
+ Attempts to create a new root set in the specified class, returning\r
+ the set if it already exists\r
+*/\r
+struct ir_set_t* ir_class_addset\r
+( struct ir_class_t* class,\r
+ const uint8_t* name\r
+)\r
+{ struct ir_set_t* iter;\r
+ if (class->root_set == NULL)\r
+ { class->root_set = struct_alloc(ir_set_t);\r
+ struct_clear(class->root_set);\r
+ class->root_set->name = name_alloc(name);\r
+ return class->root_set;\r
}\r
- else\r
- SET_ALLOC();\r
-\r
- return CURRENT_SET();\r
-}\r
-\r
-\r
-struct link*\r
-alloc_link\r
-()\r
-{ num_links++;\r
- if(LDAT_FULL())\r
- { if(!LCS_FULL())\r
- { fprintf(stderr, "You have allocated to many (%d) links ", num_links);\r
- exit(EXIT_FAILURE);\r
- }\r
- else\r
- CSP_PUSH(lcs);\r
+ iter = class->root_set;\r
+ if (iter->name == NULL)\r
+ eprintf("Null name pointer in class %p\n", iter);\r
+ if (name == NULL)\r
+ eprintf("Null set added to class %U\n", iter->name);\r
+ check:\r
+ if (bytes_identical(iter->name, name))\r
+ return iter;\r
+ if (iter->nextsib != NULL)\r
+ { iter = iter->nextsib;\r
+ goto check;\r
}\r
- else\r
- LDAT_ALLOC();\r
-\r
- return CURRENT_LINK();\r
-\r
-}\r
-\r
-struct ref*\r
-alloc_ref\r
-()\r
-{ num_refs++;\r
- if(REF_FULL())\r
- { if(!RCS_FULL())\r
- { fprintf(stderr, "You have allocated to many (%d) refs ", num_refs);\r
- exit(EXIT_FAILURE);\r
- }\r
- else\r
- CSP_PUSH(rcs);\r
+ iter->nextsib = struct_alloc(ir_set_t);\r
+ struct_clear(iter->nextsib);\r
+ iter->nextsib->name = name_alloc(name);\r
+ return iter->nextsib;\r
+}\r
+\r
+struct ir_set_t* ir_set_from_ref\r
+( uint32_t ref )\r
+{ uint16_t hash;\r
+ struct ir_set_t** iters;\r
+ struct pagenode_t* iterp;\r
+ iterp = refhashpages.root;\r
+ hash = REFHASH(ref);\r
+ do\r
+ iters = ((struct ir_set_t**) iterp->root) + hash;\r
+ while (*iters != NULL && (*iters)->ref != ref && (iterp = iterp->header.next) != NULL);\r
+ return *iters;\r
+}\r
+\r
+\r
+/* Add a set to a set\r
+ Attempts to create a new subset of the specified set, returning the\r
+ child if it already exists\r
+*/\r
+struct ir_set_t* ir_set_addchild\r
+( struct ir_set_t* set,\r
+ const uint8_t* name\r
+)\r
+{ struct ir_set_t* iter;\r
+ if (set->nextchild == NULL)\r
+ { set->nextchild = struct_alloc(ir_set_t);\r
+ struct_clear(set->nextchild);\r
+ set->nextchild->name = name_alloc(name);\r
+ return set->nextchild;\r
}\r
- else\r
- REF_ALLOC();\r
-\r
-\r
- if(num_refs % 16 == 0)\r
- { CURRENT_POST() = CURRENT_REF();\r
- inc_posts();\r
+ iter = set->nextchild;\r
+ if (name == NULL)\r
+ eprintf("Null child added to set %s\n", iter->name);\r
+ if (iter->name == NULL)\r
+ eprintf("Null name pointer in set %p\n", iter);\r
+ check:\r
+ if (bytes_identical(iter->name, name))\r
+ return iter;\r
+ if (iter->nextsib != NULL)\r
+ { iter = iter->nextsib;\r
+ goto check;\r
}\r
-\r
- return CURRENT_REF();\r
-}\r
-\r
-void\r
-inc_posts()\r
-{ num_posts++;\r
- if(POST_FULL())\r
- { if(!PCS_FULL())\r
- { fprintf(stderr, "You have allocated to many (%d) refs ", num_posts);\r
- exit(EXIT_FAILURE);\r
- }\r
- else\r
- CSP_PUSH(pcs);\r
+ iter->nextsib = struct_alloc(ir_set_t);\r
+ struct_clear(iter->nextsib);\r
+ iter->nextsib->name = name_alloc(name);\r
+ return iter->nextsib;\r
+}\r
+\r
+/* Add a framebox to a set\r
+ Attempts to create a new framebox of the specified set, returning\r
+ the framebox if it already exists\r
+ Name is not allocated, but assigned, unlike other "XXX_add" functions where\r
+ name is duplicated into IR's internal array.\r
+*/\r
+static inline\r
+struct ir_framebox_t* ir_set_add_framebox\r
+( struct ir_set_t* set,\r
+ uint8_t* name\r
+)\r
+{ struct ir_framebox_t* iter;\r
+ if (set->frameboxes == NULL)\r
+ { set->frameboxes = struct_alloc(ir_framebox_t);\r
+ struct_clear(set->frameboxes);\r
+ set->frameboxes->header.data_name = name;\r
+ return set->frameboxes;\r
}\r
- else\r
- POST_ALLOC();\r
-\r
-}\r
-\r
-struct cdat*\r
-curr_cdat\r
-()\r
-{\r
- return (*cdat_stackp);\r
-}\r
-\r
-struct odat*\r
-curr_odat\r
-()\r
-{\r
- return CURRENT_ODAT();\r
-}\r
-\r
-struct vdat*\r
-curr_vdat\r
-()\r
-{\r
- return CURRENT_VDAT();\r
-}\r
-\r
-struct set*\r
-curr_cdat_set \r
-()\r
-{\r
- return CURRENT_SET();\r
-}\r
-\r
-struct set*\r
-curr_set\r
-(int depth)\r
-{ int i;\r
- struct set* setp;\r
-\r
- for(i = 0; i <= depth; i++)\r
- { if(!(setp = setp->set_list[setp->num_sets]))\r
- { printf("You are trying to access a set that does not exist irmem.c\n");\r
- return NULL;\r
- }\r
+ iter = set->frameboxes;\r
+ check:\r
+ if (bytes_identical(iter->header.data_name, name))\r
+ return iter;\r
+ if (iter->header.nextsib != NULL)\r
+ { iter = (struct ir_framebox_t*) iter->header.nextsib;\r
+ goto check;\r
}\r
-\r
-\r
- return setp;\r
-}\r
-\r
-struct ref*\r
-curr_ref\r
-()\r
-{\r
- return CURRENT_REF();\r
-}\r
-struct ref*\r
-prev_ref\r
-()\r
-{\r
- return PREVIOUS_REF();\r
-}\r
-struct model*\r
-curr_model\r
-()\r
-{\r
- return &CURRENT_MODEL();\r
-}\r
-\r
-/* IR.C*/\r
-void\r
-push_cdat\r
-( name )\r
- struct name* name;\r
-{\r
- struct cdat* curr_cdatp;\r
-\r
- curr_cdatp = alloc_cdat();\r
-\r
- name_u8_cpy(&curr_cdatp->name, name);\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
-\r
-void\r
-insert_set_name\r
-( name )\r
- struct name* name;\r
-{ \r
- //Push name onto current namelist, set the set_namelist.\r
- name_u8_cpy(&set_namelist[set_numnames++], name);\r
- \r
- \r
-}\r
-\r
-\r
-void\r
-insert_set_namelist\r
-( name )\r
- struct name* name;\r
-{ int depth, nameidx, i;\r
-\r
- insert_set_name(name);\r
-\r
- //Check if entire string matches first? Only possible if namelist is contiguous (uint8_t strings seperated by \0)\r
- //Create odats/sets for each name in namelist where nameidx > ns_depth\r
- //first check if any parts of namelist matches what is currently on namestack\r
- //we can gauruntee that from ns_depth + 1 -> set_numnames namelists dont match. x\r
- \r
-\r
- //if name_list doesnt match, from the first depth at which namelist doesnt match\r
- //remove the nameframes namelist (zero out ones below?) and replace with current namelist,\r
- //then allocate a new odat and set it to the current set_frame.\r
- for( depth = 0; depth < set_numnames ; depth++ )\r
- { for (nameidx = 0; nameidx <= depth; nameidx++)\r
- { if( name_u8_cmp(&set_namelist[nameidx], &ss.set_frames[depth].namelist[nameidx]) != 0 )\r
- { /* Populate the namelist of the set at the current depth */\r
- for(i = 0; i <= depth; i++)\r
- name_u8_cpy(&ss.set_frames[depth].namelist[i], &set_namelist[i]);\r
-\r
- /* Alloc set and odat */\r
- ss.set_frames[depth].odatp = alloc_odat();\r
- ss.set_frames[depth].setp = alloc_set();\r
-\r
- /* populate set/odat name and cdat_idx */\r
- name_u8_cpy(&ss.set_frames[depth].odatp->name, &set_namelist[depth]);\r
- ss.set_frames[depth].setp->cdat_idx = ( *cdat_stackp)->idx;\r
- \r
- /* Insert allocated set and odat into their respective trees if there is a depth \r
- (they have parents) */ \r
- if(depth)\r
- { ss.set_frames[depth].odatp->parent_odatp = ss.set_frames[depth-1].odatp;\r
- if(ss.set_frames[depth-1].setp->num_sets < MAX_SETS)\r
- ss.set_frames[depth-1].setp->set_list[ss.set_frames[depth-1].setp->num_sets++] = ss.set_frames[depth].setp;\r
- else\r
- { printf("you have allocated too many sets in insert_namelist()\n");\r
- //TODO: EXIT()\r
- }\r
- }\r
- else /* no parent set, so assign to cdat set_list */\r
- { ss.set_frames[depth].odatp->parent_odatp = NULL; //no parent odat = NULL.\r
- if(curr_cdat_set()->num_sets < MAX_SETS)\r
- curr_cdat_set()->set_list[curr_cdat_set()->num_sets++] = ss.set_frames[depth].setp;\r
- else\r
- { printf("you have allocated too many sets in insert_namelist()\n");\r
- //TODO: EXIT()\r
- }\r
- }\r
- \r
- \r
- ss.set_frames[depth].num_names = set_numnames;\r
- ss.curr_depth = depth;\r
+ iter->header.nextsib = (union ir_setdata_t*) struct_alloc(ir_framebox_t);\r
+ struct_clear(iter->header.nextsib);\r
+ iter->header.nextsib->header.data_name = name;\r
+ return (struct ir_framebox_t*) (iter->header.nextsib);\r
+}\r
+\r
+/* Match two null-terminated bytestrings\r
+ Return 1 if the two bytestrings are identical, else 0\r
+*/\r
+static inline\r
+int bytes_identical\r
+( const uint8_t* stra,\r
+ const uint8_t* strb\r
+)\r
+{ int ca, cb;\r
+ do {\r
+ ca = *stra++;\r
+ cb = *strb++;\r
+ } while (ca && ca != '_' && ca == cb);\r
+ return (ca == cb);\r
+}\r
+\r
+static inline\r
+int classnames_identical\r
+( const uint8_t* stra,\r
+ const uint8_t* strb\r
+)\r
+{ int ca, cb;\r
+ do {\r
+ ca = *stra++;\r
+ cb = *strb++;\r
+ } while (ca && ca == cb);\r
+ return (ca == cb);\r
+}\r
+\r
+/* Assign Setdata to Set */\r
+void ir_set_assign_data\r
+( struct ir_set_t* set,\r
+ union ir_setdata_t* setdata\r
+)\r
+{ struct ir_framebox_t* framebox;\r
+ struct ir_simplex_t* simplex;\r
+ switch (setdata->header.type)\r
+ { case FSDAT:\r
+ framebox = ir_set_add_framebox(set, setdata->header.data_name);\r
+ if (framebox->framesheets[setdata->framesheet.frameinfo.facing].header.data_name != NULL)\r
+ wprintf("Duplicate framesheet [%i] %s\n",\r
+ setdata->framesheet.frameinfo.facing, setdata->header.data_name);\r
+ framebox->framesheets[setdata->framesheet.frameinfo.facing] = setdata->framesheet;\r
+ break;\r
+ case MSDAT:\r
+ framebox = ir_set_add_framebox(set, setdata->header.data_name);\r
+ if (framebox->mapsheets[setdata->mapsheet.frameinfo.facing].header.data_name != NULL)\r
+ wprintf("Duplicate mapsheet [%i] %s\n",\r
+ setdata->mapsheet.frameinfo.facing, setdata->header.data_name);\r
+ framebox->mapsheets[setdata->mapsheet.frameinfo.facing] = setdata->mapsheet;\r
+ break;\r
+ case ADAT:\r
+ if (set->audio == NULL)\r
+ { set->audio = (struct ir_simplex_t*) setdata;\r
+ return;\r
+ }\r
+ simplex = set->audio;\r
+ while (simplex->header.nextsib != NULL)\r
+ if (bytes_identical(simplex->header.data_name, setdata->header.data_name))\r
+ { wprintf("Duplicate audio %s\n", setdata->header.data_name);\r
+ *simplex = setdata->audio;\r
+ //setdata is now a pointer to redundant, unused memory.\r
+ return;\r
}\r
- \r
- }\r
- \r
+ else\r
+ simplex = (struct ir_simplex_t*) simplex->header.nextsib;\r
+ setdata->audio.header.nextsib = (union ir_setdata_t*) set->audio;\r
+ set->audio = (struct ir_simplex_t*) setdata;\r
+ break;\r
+ case LDAT:\r
+ setdata->link.header.nextsib = (union ir_setdata_t*) set->links;\r
+ set->links = (struct ir_link_t*) setdata;\r
+ break;\r
+ default:\r
+ fprintf(stderr, "Unknown setdata type %x\n", setdata->header.type);\r
+ exit(-1);\r
}\r
- done:\r
- ;\r
-}\r
-\r
-/*. 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
-\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
+void ir_set_assign_ref\r
+( struct ir_set_t* set,\r
+ uint32_t ref\r
+)\r
+{ uint16_t hash, oldhash;\r
+ struct ir_set_t** iters;\r
+ struct pagenode_t* iterp;\r
+ uint32_t oldref;\r
+ oldref = set->ref;\r
+ oldhash = 0;\r
+ hash = REFHASH(ref);\r
+ iterp = refhashpages.root;\r
+ check_depth:\r
+ iters = ((struct ir_set_t**) iterp->root) + hash;\r
+ if (*iters == NULL || *iters == set)\r
+ *iters = set;\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
-\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
+ { if (iterp->header.next == NULL)\r
+ pagelist_alloc(refhashpages);\r
+ iterp = iterp->header.next;\r
+ goto check_depth;\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
+ if (oldref != 0)\r
+ { wprintf("Ref override: 0x%x -> 0x%x for set %s\n", oldref, ref, set->name);\r
+ if (oldhash != 0)\r
+ *iters = NULL;\r
+ else\r
+ { oldhash = hash;\r
+ hash = REFHASH(oldref);\r
+ goto check_depth;\r
+ }\r
}\r
- \r
- \r
- \r
-}\r
-\r
-void\r
-insert_vdat\r
-()\r
-{ struct odat* curr_ss_odatp;\r
- struct vdat* curr_vdatp;\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_statement\r
-( refid )\r
- int refid;\r
-{ CURR_SS_ODATP()->refid = refid;\r
+ set->ref = ref;\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
+void ir_data_assign_path\r
+( union ir_setdata_t* setdata,\r
+ const uint8_t* path\r
)\r
-{\r
-\r
- struct set* curr_setp;\r
-\r
- curr_setp = curr_set();\r
- curr_set_odatp = alloc_odat();\r
-\r
- u8_cpy(curr_set_odatp->name, name, 32);\r
- u8_cpy(curr_setp->name, name, 32);\r
- curr_set_odatp->parent_odatp = NULL;\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
-( int refid\r
+{ if (path == NULL)\r
+ eprintf("Null path in data %s\n", setdata->header.data_name);\r
+ if (setdata->header.src_filename != NULL)\r
+ wprintf("Path override: %s -> %s for setdata %s\n",\r
+ setdata->header.src_filename, path, setdata->header.data_name);\r
+ setdata->header.src_filename = name_alloc(path);\r
+}\r
+\r
+union ir_setdata_t* ir_framesheet\r
+( const uint8_t* name,\r
+ apc_facing d,\r
+ int width,\r
+ int height\r
)\r
-{\r
- struct set* curr_setp;\r
-\r
- curr_setp = curr_set();\r
-\r
- curr_setp->refid = refid;\r
-\r
-}\r
+{ return ir_framedata(FSDAT, name, d, width, height); }\r
\r
-void\r
-insert_set_vlink\r
-( int refid,\r
- uint8_t* anim_name\r
+union ir_setdata_t* ir_mapsheet\r
+( const uint8_t* name,\r
+ apc_facing d,\r
+ int width,\r
+ int height\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.refid = refid;\r
- u8_cpy(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
-( int refid \r
+{ return ir_framedata(MSDAT, name, d, width, height); }\r
+\r
+static inline\r
+union ir_setdata_t* ir_framedata\r
+( enum dtype type,\r
+ const uint8_t* name,\r
+ apc_facing d,\r
+ int width,\r
+ int height\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.refid = refid;\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
-{ int refid;\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\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
- u8_cpy(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
- refid = curr_setp->refid; // refid set by insert_set_label(name, refid)\r
-\r
- curr_refp->refid = refid;\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 refid 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
-( uint8_t* name,\r
- int refid\r
+{ struct ir_framedata_t* framedata = struct_alloc(ir_framedata_t);\r
+ struct_clear(framedata);\r
+ if (name == NULL)\r
+ eprintf("Null name in set allocation\n");\r
+ framedata->header.type = type;\r
+ framedata->header.data_name = name_alloc(name);\r
+ framedata->frameinfo.facing = d;\r
+ framedata->frameinfo.w = width;\r
+ framedata->frameinfo.h = height;\r
+ return (union ir_setdata_t*) framedata;\r
+}\r
+\r
+union ir_setdata_t* ir_audio\r
+( const uint8_t* name )\r
+{ struct ir_simplex_t* audio = struct_alloc(ir_simplex_t);\r
+ struct_clear(audio);\r
+ if (name == NULL)\r
+ eprintf("Null audio\n");\r
+ audio->header.type = ADAT;\r
+ audio->header.data_name = name_alloc(name);\r
+ return (union ir_setdata_t*) audio;\r
+}\r
+\r
+\r
+/* Create classld that points to a class */\r
+struct ir_classld_t* ir_classld_from_class\r
+( struct ir_class_t* class )\r
+{ struct ir_classld_t* classld;\r
+ if (class == NULL)\r
+ eprintf("Null class in classld\n");\r
+ classld = struct_alloc(ir_classld_t);\r
+ struct_clear(classld);\r
+ classld->root_class = class;\r
+ return classld;\r
+}\r
+\r
+struct ir_setld_t* ir_setld_from_ref\r
+( uint32_t ref )\r
+{ struct ir_setld_t* setld;\r
+ setld = struct_alloc(ir_setld_t);\r
+ struct_clear(setld);\r
+ setld->ref = ref;\r
+ return setld;\r
+}\r
+\r
+struct ir_setld_t* ir_setld_from_classld\r
+( struct ir_classld_t* classld,\r
+ const uint8_t* name\r
)\r
-{\r
- struct odat* curr_odatp;\r
-\r
- curr_odatp = alloc_odat();\r
-\r
- u8_cpy(curr_odatp->name, name, 32);\r
- curr_odatp->map[0] = 0;\r
-\r
- if(refid != -1)\r
- curr_odatp->refid = refid;\r
- else\r
- curr_odatp->refid = ss_refid++;\r
-\r
-}\r
-\r
-/* We don't make an odat here, at output time we will resolve\r
- the refid to the corresponding odat. */\r
-void\r
-insert_ele_olink\r
-( int refid\r
+{ struct ir_setld_t* setld;\r
+ setld = struct_alloc(ir_setld_t);\r
+ struct_clear(setld);\r
+ setld->namelist = struct_alloc(ir_namelist_t);\r
+ struct_clear(setld->namelist);\r
+ setld->namelist_head = setld->namelist;\r
+ setld->namelist_head->name = name_alloc(name);\r
+ setld->classld = classld;\r
+ return setld; \r
+}\r
+\r
+struct ir_setld_t* ir_setld_addchild\r
+( struct ir_setld_t* setld,\r
+ const uint8_t* name\r
)\r
-{\r
- /* Do nothing because we already know the refid that\r
- the odat needs for this element (in the quad_file) */\r
+{ if (setld->namelist == NULL)\r
+ { setld->namelist = struct_alloc(ir_namelist_t);\r
+ struct_clear(setld->namelist);\r
+ setld->namelist_head = setld->namelist;\r
+ }\r
+ else\r
+ { setld->namelist_head->nextsib = struct_alloc(ir_namelist_t);\r
+ struct_clear(setld->namelist_head->nextsib);\r
+ setld->namelist_head = setld->namelist_head->nextsib;\r
+ }\r
+ setld->namelist_head->name = name_alloc(name);\r
+ return setld;\r
}\r
\r
-void\r
-insert_ele_vlink\r
-( int refid,\r
- uint8_t* anim_name\r
+union ir_setdata_t* ir_link\r
+( enum ltype link_type,\r
+ struct ir_setld_t* setld,\r
+ const uint8_t* 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.refid = refid;\r
- u8_cpy(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
-\r
+{ struct ir_link_t* link;\r
+ link = struct_alloc(ir_link_t);\r
+ struct_clear(link);\r
+ link->header.type = LDAT;\r
+ link->type = link_type; \r
+ link->classld = setld->classld;\r
+ link->setld = setld;\r
+ if (link_type != OLINK && name != NULL)\r
+ link->header.data_name = name_alloc(name);\r
+ return (union ir_setdata_t*) link;\r
+}\r
+\r
+\r
+static\r
+uint8_t* name_alloc\r
+( const uint8_t* name_src )\r
+{ const uint8_t* iter;\r
+ uint8_t* name;\r
+ int head_mem;\r
+ copy:\r
+ name = (uint8_t*)namepages.head->header.head;\r
+ iter = name_src;\r
+ for (head_mem = PL_HEADMEM(namepages); *iter && *iter != '_' && *iter != '.' && head_mem; head_mem--)\r
+ *(namepages.head->header.head)++ = *iter++;\r
+ if (head_mem < 1) //not enough room\r
+ { pagelist_alloc(namepages);\r
+ goto copy;\r
+ }\r
+ *(namepages.head->header.head)++ = '\0';\r
+ return name;\r
+}\r
+\r
+static\r
+uint8_t* classname_alloc\r
+( const uint8_t* name_src )\r
+{ const uint8_t* iter;\r
+ uint8_t* name;\r
+ int head_mem;\r
+ copy:\r
+ name = (uint8_t*)namepages.head->header.head;\r
+ iter = name_src;\r
+ for (head_mem = PL_HEADMEM(namepages); *iter && head_mem; head_mem--)\r
+ *(namepages.head->header.head)++ = *iter++;\r
+ if (head_mem < 1) //not enough room\r
+ { pagelist_alloc(namepages);\r
+ goto copy;\r
+ }\r
+ *(namepages.head->header.head)++ = '\0';\r
+ return name;\r
+}\r
+\r
+static void crawl_class(struct ir_class_t*);\r
+static void crawl_set(struct ir_set_t*,int);\r
+\r
+void ir_test(void)\r
+{ uprintf("IR From Directory: %s\n",getcwd(NULL,255));\r
+ crawl_class(&root_class);\r
+ if (root_class.root_set != NULL)\r
+ crawl_set(root_class.root_set, 0);\r
+ uprintf("starting binaryout \n");\r
+ ir_binout_init(&root_class);\r
+}\r
+\r
+\r
+static\r
+void crawl_class\r
+( struct ir_class_t* class )\r
+{ struct ir_class_t* iter;\r
+ for (iter = class->nextchild; iter != NULL; iter = iter->nextsib)\r
+ { wprintf("Crawling class %U/\n", iter->name);\r
+ if(chdir((char*)iter->name))\r
+ eprintf("CHDIR %U from %s\n",iter->name,getcwd(NULL,255));\r
+ crawl_class(iter);\r
+ if (iter->root_set != NULL)\r
+ crawl_set(iter->root_set, 0);\r
+ uprintf("%U\\\n",iter->name);\r
+ if (chdir(".."))\r
+ eprintf("CHDIR ..\n");\r
+ wprintf("Finished crawling class %U/\n", iter->name);\r
+ }\r
}\r
\r
-void\r
-insert_ele_svlink\r
-( int refid\r
+#define push_setp(setp) (*(struct ir_set_t**)stack_alloc(&datapages, sizeof(struct ir_set_t*)) = setp)\r
+#define pop_setp() (*(struct ir_set_t**)pagelist_pop(&datapages, sizeof(struct ir_set_t*)))\r
+static\r
+void crawl_set\r
+( struct ir_set_t* set,\r
+ int depth\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.refid = refid;\r
-\r
-\r
-}\r
-\r
-//Insert element into odat_buf and cdatpages\r
-void\r
-insert_ele()\r
-{\r
- int refid;\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
- curr_odatp->parent_odatp = curr_set_odatp;\r
-\r
- refid = curr_odatp->refid;\r
-\r
- curr_refp->refid = refid;\r
- curr_refp->lastref = prev_refp;\r
- curr_refp->odatp = curr_odatp;\r
- prev_refp->nextref = curr_refp;\r
-\r
-}\r
+{ struct ir_set_t* iter;\r
+ int i;\r
+ i = depth * 12;\r
+ while (i--)\r
+ putchar('.');\r
+ i = depth;\r
+\r
+ for(iter = set; iter != NULL; iter = iter->nextchild)\r
+ { uprintf("[%10U]", iter->name);\r
+ push_setp(iter);\r
+ i++;\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
+ putchar('\n');\r
+ while (--i >= depth)\r
+ if (((iter = pop_setp())->nextsib) != NULL)\r
+ crawl_set(iter->nextsib,i);\r
}\r
-\r
-\r
-\r
-#endif\r
-\r
-\r
- \r
-\r
-/* void */\r
-/* insert_quad */\r
-/* ( int x, int y, int z, int refid */\r
-/* ) */\r
-/* { */\r
-/* struct quad* curr_quadp; */\r
-\r
-/* curr_quadp = curr_quad(); */\r
-\r
-/* curr_quadp->x = x; */\r
-/* curr_quadp->y = y; */\r
-/* curr_quadp->z = z; */\r
-/* curr_quadp->refid = refid; */\r
- \r
-\r
-\r
-/* } */\r
-\r
-/* /\* serting 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
-\r
-\r
-/* void */\r
-/* insert_frame_pointer */\r
-/* ( uint8_t 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