/****** t2d.c This test program converts a text file containing ts tile set declarations into various Data structures. ******/ #include #include #include "../common/data.h" int main() { char *buffer; int size = fileToMemory(&buffer, "xibalba.tsd"); struct Data *data = loadDataFromMemory(buffer, size); free(buffer); printf("---- total tile sets: %d\n", data->set_count); int bytes = 0; bytes += sizeof(struct Data) + (sizeof(int) * data->size) + (sizeof(struct TileSetData)*data->size); int count = 0; while (count < data->size) { int count_2 = 0; if (data->set[count]) { bytes += sizeof(struct TileSetData) + (sizeof(struct TileData*)*data->set[count]->size); bytes += sizeof(struct Table); while (count_2 < data->set[count]->size) { if (data->set[count]->tile[count_2]) { bytes += sizeof(struct TileData); printf("- TILE %d:%d\n", count, count_2); struct Table *table = data->set[count]->tile[count_2]->table; int i = 0; while (i < table->size) { struct TablePair *table_pair = table->pair[i]; while (table_pair != NULL) { bytes += sizeof(struct TablePair); bytes += sizeof(*table_pair->value); bytes += sizeof(*table_pair->key); if (table_pair->type == T_STRING) { printf("%s=>%s!\n", table_pair->key, table_pair->value); } else if (table_pair->type == T_INT) { printf("%s=>%d!\n", table_pair->key, *(int*)table_pair->value); } else if (table_pair->type == T_FLOAT) { printf("%s=>%f!\n", table_pair->key, *(float*)table_pair->value); } else if (table_pair->type == T_PROTO_INVENTORY) { printf("found inventory %s, running thru contents:\n", table_pair->key); struct InventoryData* inv = table_pair->value; while (inv != NULL) { printf(" name: %s\n", inv->name); printf(" count: %d-%d\n", inv->count.min, inv->count.max); printf(" chance: %f\n", inv->chance); printf(" -- retrieving --\n"); struct TileData *tile = getTileDataByKey(data, inv->name); if (tile != NULL) { printf(" found %s(%d:%d)\n", inv->name, tile->tid, tile->id); } else { printf(" tile doesn't exist :(\n"); } inv = inv->next; } } table_pair = table_pair->next; } i++; } } count_2++; } } count++; } printf("estimated bytes: %d\n", bytes); printf("getTileDataByKey 'big key'\n"); struct TileData *tile = getTileDataByKey(data, "big key"); if (tile != NULL) { printf("found %d:%d, dumping key=>value pairs\n", tile->tid, tile->id); int i = 0; printf("size is %d\n", tile->size); struct Table *table = tile->table; while (i < table->size) { struct TablePair *table_pair = table->pair[i]; while (table_pair != NULL) { if (table_pair->type == T_STRING) printf("%s=>%s!\n", table_pair->key, table_pair->value); table_pair = table_pair->next; } i++; } } else { printf("nope!\n"); } printf("getTileDataById '0, 1'\n"); tile = getTileDataById(data, 0, 1); if (tile != NULL) { printf("found %d:%d, dumping key=>value pairs\n", tile->tid, tile->id); int i = 0; printf("size is %d\n", tile->size); struct Table *table = tile->table; while (i < table->size) { struct TablePair *table_pair = table->pair[i]; while (table_pair != NULL) { if (table_pair->type == T_STRING) printf("%s=>%s!\n", table_pair->key, table_pair->value); table_pair = table_pair->next; } i++; } } else { printf("nope!\n"); } return 0; }