/* ============ WriteGame This will be called whenever the game goes to a new level, and when the user explicitly saves the game. Game information include cross level data, like multi level triggers, help computer info, and all client states. A single player death will automatically restore from the last save position. ============ */ void WriteGame(const char *filename, qboolean autosave) { FILE *f; int i; if (!autosave) SaveClientData(); f = fopen(filename, "wb"); if (!f) gi.error("Couldn't open %s", filename); write_int(f, SAVE_MAGIC1); write_int(f, SAVE_VERSION); game.autosaved = autosave; write_fields(f, gamefields, &game); game.autosaved = qfalse; for (i = 0; i < game.maxclients; i++) { write_fields(f, clientfields, &game.clients[i]); } fclose(f); }
/* ================= WriteLevel ================= */ void WriteLevel(const char *filename) { int i; edict_t *ent; FILE *f; f = fopen(filename, "wb"); if (!f) gi.error("Couldn't open %s", filename); write_int(f, SAVE_MAGIC2); write_int(f, SAVE_VERSION); // write out level_locals_t write_fields(f, levelfields, &level); // write out all the entities for (i = 0; i < globals.num_edicts; i++) { ent = &g_edicts[i]; if (!ent->inuse) continue; write_int(f, i); write_fields(f, entityfields, ent); } write_int(f, -1); fclose(f); }
HIDDEN void get_large_field_input(FILE *fp, int write_flag) { char **tmp_rec; int field_no; int card_len; int last_field; int i; tmp_rec = prev_rec; prev_rec = curr_rec; curr_rec = tmp_rec; for ( field_no=0; field_no < NO_OF_FIELDS; field_no ++ ) curr_rec[field_no][0] = '\0'; card_len = strlen( line ); last_field = (card_len - 8)/16 + 1; if ( ((last_field - 1) * 16 + 8) < card_len ) last_field++; if ( last_field > 5 ) last_field = 5; bu_strlcpy( curr_rec[0], line, 8 ); curr_rec[0][8] = '\0'; for ( field_no=1; field_no < last_field; field_no++ ) { bu_strlcpy( curr_rec[field_no], &line[field_no*16 - 8], 16 ); curr_rec[field_no][16] = '\0'; } /* remove the newline from the end of the last field */ i = strlen( curr_rec[last_field-1] ) - 1; while ( isspace( curr_rec[last_field-1][i] ) || curr_rec[last_field-1][i] == '\012' || curr_rec[last_field-1][i] == '\015' ) i--; curr_rec[last_field-1][++i] = '\0'; if ( next_line[0] == '*' ) { if ( !get_next_record( fp, 0, 0 ) ) { bu_exit(1, "unexpected end of INPUT at line #%d\n", line_count ); } card_len = strlen( line ); last_field = (card_len - 8)/16 + 1; if ( ((last_field - 1) * 16 + 8) < card_len ) last_field++; if ( last_field > 5 ) last_field = 5; last_field += 4; for ( field_no=5; field_no < last_field; field_no++ ) { bu_strlcpy( curr_rec[field_no], &line[(field_no-4)*16 - 8], 16 ); curr_rec[field_no][16] = '\0'; } } if ( write_flag ) write_fields(); }
int OptionsDialog::exec() { read_fields(); bool accepted = (QDialog::exec() == QDialog::Accepted); if (accepted) { write_fields(); } return accepted; }
static void write_object(io::stream& e, const void* object) { auto pd = bsdata::findbyptr(object); if(!pd) return; e << "#" << pd->id << " "; auto skip = write_key(e, object, pd->fields); e << " "; write_fields(e, object, pd->fields, skip); }
HIDDEN void get_small_field_input(FILE *fp, int write_flag) { char **tmp_rec; int field_no; int card_len; int last_field; tmp_rec = prev_rec; prev_rec = curr_rec; curr_rec = tmp_rec; for ( field_no=0; field_no < NO_OF_FIELDS; field_no ++ ) curr_rec[field_no][0] = '\0'; card_len = strlen( line ); last_field = card_len/8 + 1; if ( (last_field * 8) < card_len ) last_field++; if ( last_field > 9 ) last_field = 9; bu_strlcpy( curr_rec[0], line, 8 ); curr_rec[0][8] = '\0'; for ( field_no=2; field_no < last_field+1; field_no++ ) { bu_strlcpy( curr_rec[field_no-1], &line[(field_no-1)*8], 8 ); curr_rec[field_no-1][8] = '\0'; } if ( next_line[0] == '+' ) { if ( !get_next_record( fp, 0, 0 ) ) { bu_exit(1, "unexpected end of INPUT at line #%d\n", line_count ); } card_len = strlen( line ); last_field = card_len/8 + 1; if ( (last_field * 8) < card_len ) last_field++; if ( last_field > 9 ) last_field = 9; last_field += 9; for ( field_no=10; field_no < last_field+1; field_no++ ) { bu_strlcpy( curr_rec[field_no-1], &line[(field_no-9)*8], 8 ); curr_rec[field_no-1][8] = '\0'; } } if ( write_flag ) write_fields(); }
HIDDEN void get_ctria3(void) { int pid; int g1, g2, g3; int gin1, gin2, gin3; point_t pt1, pt2, pt3; struct vertex **v[3]; struct faceuse *fu; struct shell *s; struct pshell *psh; int pid_index=0; pid = atoi(curr_rec[2]); pid_index = get_pid_index(pid); g1 = atoi(curr_rec[3]); g2 = atoi(curr_rec[4]); g3 = atoi(curr_rec[5]); gin1 = get_gridi(g1); gin2 = get_gridi(g2); gin3 = get_gridi(g3); v[0] = &g_pts[gin1].v[pid_index]; v[1] = &g_pts[gin2].v[pid_index]; v[2] = &g_pts[gin3].v[pid_index]; VSCALE(pt1, g_pts[gin1].pt, conv[units]); VSCALE(pt2, g_pts[gin2].pt, conv[units]); VSCALE(pt3, g_pts[gin3].pt, conv[units]); if (!nmg_model && !pid) { struct nmgregion *r; nmg_model = nmg_mm(); r = nmg_mrsv(nmg_model); nmg_shell = BU_LIST_FIRST(shell, &r->s_hd); } if (!pid) s = nmg_shell; else { int found=0; /* find pshell entry for this pid */ for (BU_LIST_FOR(psh, pshell, &pshell_head.l)) { if (psh->pid == pid) { found = 1; break; } } if (!found) { bu_log("Cannot find PSHELL entry for a CTRIA3 element (ignoring)!\n"); write_fields(); return; } if (psh->s) s = psh->s; else { struct model *m; struct nmgregion *r; m = nmg_mm(); r = nmg_mrsv(m); s = BU_LIST_FIRST(shell, &r->s_hd); psh->s = s; } } fu = nmg_cmface(s, v, 3); if (!g_pts[gin1].v[pid_index]->vg_p) nmg_vertex_gv(g_pts[gin1].v[pid_index], pt1); if (!g_pts[gin2].v[pid_index]->vg_p) nmg_vertex_gv(g_pts[gin2].v[pid_index], pt2); if (!g_pts[gin3].v[pid_index]->vg_p) nmg_vertex_gv(g_pts[gin3].v[pid_index], pt3); nmg_calc_face_g(fu); }
HIDDEN void get_free_form_input(FILE *fp, int write_flag) { char **tmp_rec; size_t field_no; int i, j; i = (-1); while (isspace((int)line[++i])); if (line[i] == '=' && isdigit((int)line[i+1])) { int count; count = atoi(&line[i+1]); i = (-1); while (isspace((int)prev_line[++i])); if (prev_line[i] == '=' && isdigit((int)prev_line[i+1])) { bu_log("Cannot use consecutive replication cards:\n"); bu_log("%s", prev_line); bu_log("%s", line); bu_exit(1, "ERROR: Cannot use consecutive replication cards\n"); } for (i=0; i<count; i++) { bu_strlcpy(line, prev_line, MAX_LINE_SIZE); get_free_form_input(fp, write_flag); } return; } else { tmp_rec = prev_rec; prev_rec = curr_rec; curr_rec = tmp_rec; for (field_no=0; field_no < NO_OF_FIELDS; field_no ++) curr_rec[field_no][0] = '\0'; field_no = (-1); i = 0; while (++field_no < NO_OF_FIELDS && line[i] != '\0') { while (line[i] != '\0' && isspace((int)line[i])) i++; j = (-1); while (line[i] != '\0' && line[i] != COMMA && !isspace((int)line[i])) curr_rec[field_no][++j] = line[i++]; curr_rec[field_no][++j] = '\0'; if (line[i] == COMMA) i++; } if (strchr(curr_rec[9], '+')) { /* continuation card */ if (!get_next_record(fp, 0, 0)) { bu_exit(1, "unexpected end of INPUT at line #%ld\n", line_count); } i = 0; while (++field_no < NO_OF_FIELDS && line[i] != '\0') { while (line[i] != '\0' && isspace((int)line[i])) i++; j = (-1); while (line[i] != '\0' && line[i] != COMMA && !isspace((int)line[i])) curr_rec[field_no][++j] = line[i++]; curr_rec[field_no][++j] = '\0'; if (line[i] == COMMA) i++; } } } do_silly_nastran_shortcuts(); if (write_flag) write_fields(); }
char* darxen_shapefiles_filter_shp(DarxenShapefile* shapefile, int dataLevel, const char* site, float latCenter, float lonCenter, float radius) { GSList* lstNewDBFs = NULL; GSList* lstNewSHPs = NULL; DBFHandle hDBF; SHPHandle hSHP; SHPHandle hNewSHP = NULL; DBFHandle hNewDBF = NULL; int pnEntities; int pnShapeType; int i; SHPObject *psObject = NULL; char* filteredPath; g_assert(shapefile->file); g_assert(!shapefile->dataLevels || shapefile->dataLevels->field); g_assert(!shapefile->dataLevels || (dataLevel >= 0 && dataLevel < g_slist_length(shapefile->dataLevels->levels))); gchar* gfilteredFile; if (shapefile->dataLevels) gfilteredFile = g_strdup_printf("%s_%s_%i", shapefile->file, site, dataLevel); else gfilteredFile = g_strdup_printf("%s_%s", shapefile->file, site); gchar* gfilteredPath = g_build_filename(darxen_file_support_get_app_path(), "shapefiles", "cache", gfilteredFile, NULL); filteredPath = strdup(gfilteredPath); g_free(gfilteredFile); g_free(gfilteredPath); //don't recreate the file, just return the path gchar* shpFile = g_strdup_printf("%s.shp", filteredPath); gchar* dbfFile = g_strdup_printf("%s.dbf", filteredPath); if (g_file_test(shpFile, G_FILE_TEST_EXISTS) && g_file_test(dbfFile, G_FILE_TEST_EXISTS)) { g_free(shpFile); g_free(dbfFile); return filteredPath; } g_free(shpFile); g_free(dbfFile); gchar* pathPart = g_strdup_printf("%s.shp", shapefile->file); gchar* pathPart2 = g_build_filename("shapefiles", pathPart, NULL); gchar* shapefilePath = darxen_file_support_get_overridable_file_path(pathPart2); //g_build_filename(darxen_file_support_get_app_path(), "shapefiles", shapefile->file, NULL); g_free(pathPart); g_free(pathPart2); g_assert(shapefilePath); shapefilePath[strlen(shapefilePath)-4] = '\0'; hSHP = SHPOpen(shapefilePath, "rb"); if (!hSHP) { g_free(shapefilePath); g_critical("Invalid shapefile path: %s", shapefile->file); return NULL; } hDBF = DBFOpen(shapefilePath, "rb"); if (!hDBF) { g_free(shapefilePath); g_critical("Invalid shapefile dbf path: %s", shapefile->file); return NULL; } g_free(shapefilePath); int dbfCount = DBFGetRecordCount(hDBF); SHPGetInfo(hSHP, &pnEntities, &pnShapeType, NULL, NULL); if (dbfCount != pnEntities) { g_critical("dbf and shp have a differing number of records!"); SHPClose(hSHP); DBFClose(hDBF); return NULL; } if (shapefile->dataLevels) { GSList* pLevel = shapefile->dataLevels->levels; i = 0; while (pLevel) { gfilteredFile = g_strdup_printf("%s_%s_%i", shapefile->file, site, i); gfilteredPath = g_build_filename(darxen_file_support_get_app_path(), "shapefiles", "cache", gfilteredFile, NULL); hNewDBF = DBFCreate(gfilteredPath); hNewSHP = SHPCreate(gfilteredPath, pnShapeType); if (!hNewDBF || !hNewSHP || !create_required_fields(shapefile, hDBF, hNewDBF)) { SHPClose(hSHP); DBFClose(hDBF); if (hNewDBF) DBFClose(hNewDBF); if (hNewSHP) SHPClose(hNewSHP); GSList* plstNewDBFs = lstNewDBFs; while (plstNewDBFs) { DBFClose((DBFHandle)plstNewDBFs->data); plstNewDBFs = plstNewDBFs->next; } g_slist_free(lstNewDBFs); GSList* plstNewSHPs = lstNewSHPs; while (plstNewSHPs) { SHPClose((SHPHandle)plstNewSHPs->data); plstNewSHPs = plstNewSHPs->next; } g_slist_free(lstNewSHPs); g_critical("Unable to create filtered shapefile lists: (level %i)", i); return NULL; } lstNewDBFs = g_slist_append(lstNewDBFs, hNewDBF); lstNewSHPs = g_slist_append(lstNewSHPs, hNewSHP); g_free(gfilteredPath); g_free(gfilteredFile); i++; pLevel = pLevel->next; } hNewDBF = NULL; hNewSHP = NULL; } else { hNewSHP = SHPCreate(filteredPath, pnShapeType); if (!hNewSHP) { SHPClose(hSHP); DBFClose(hDBF); g_critical("Unable to create filtered shapefile: %s", filteredPath); return NULL; } hNewDBF = DBFCreate(filteredPath); if (!hNewDBF || !create_required_fields(shapefile, hDBF, hNewDBF)) { SHPClose(hSHP); DBFClose(hDBF); SHPClose(hNewSHP); g_critical("Unable to create filtered dbf shapefile: %s", filteredPath); return NULL; } } float filterRegionX1 = lonCenter - radius; float filterRegionX2 = lonCenter + radius; float filterRegionY1 = latCenter - radius; float filterRegionY2 = latCenter + radius; for (i = 0; i < pnEntities; i++) { psObject = SHPReadObject(hSHP, i); if (((filterRegionX1 >= psObject->dfXMin && filterRegionX1 <= psObject->dfXMax) || (filterRegionX2 >= psObject->dfXMin && filterRegionX2 <= psObject->dfXMax) || (psObject->dfXMin >= filterRegionX1 && psObject->dfXMin <= filterRegionX2) || (psObject->dfXMax >= filterRegionX1 && psObject->dfXMax <= filterRegionX2)) && ((filterRegionY1 >= psObject->dfYMin && filterRegionY1 <= psObject->dfYMax) || (filterRegionY2 >= psObject->dfYMin && filterRegionY2 <= psObject->dfYMax) || (psObject->dfYMin >= filterRegionY1 && psObject->dfYMin <= filterRegionY2) || (psObject->dfYMax >= filterRegionY1 && psObject->dfYMax <= filterRegionY2))) { psObject->nShapeId = -1; if (shapefile->dataLevels) { int fieldIndex = DBFGetFieldIndex(hDBF, shapefile->dataLevels->field); GSList* pDataLevels = shapefile->dataLevels->levels; GSList* pLstNewSHPs = lstNewSHPs; GSList* pLstNewDBFs = lstNewDBFs; while (pDataLevels) { DarxenShapefileDataLevel* level = (DarxenShapefileDataLevel*)pDataLevels->data; hNewSHP = (SHPHandle)pLstNewSHPs->data; hNewDBF = (DBFHandle)pLstNewDBFs->data; double value = DBFReadDoubleAttribute(hDBF, i, fieldIndex); gboolean cond; switch (shapefile->dataLevels->comparisonType) { case DATALEVELS_COMPARISON_TYPE_MIN: cond = (level->value < value); break; case DATALEVELS_COMPARISON_TYPE_MAX: cond = (level->value > value); break; default: g_warning("Invalid comparison type: %i", shapefile->dataLevels->comparisonType); cond = TRUE; } if (cond) { int index = SHPWriteObject(hNewSHP, -1, psObject); write_fields(shapefile, i, index, hDBF, hNewDBF); break; } pDataLevels = pDataLevels->next; pLstNewDBFs = pLstNewDBFs->next; pLstNewSHPs = pLstNewSHPs->next; } hNewDBF = NULL; hNewSHP = NULL; } else { int index = SHPWriteObject(hNewSHP, -1, psObject); write_fields(shapefile, i, index, hDBF, hNewDBF); } } SHPDestroyObject(psObject); } SHPClose(hSHP); DBFClose(hDBF); if (hNewDBF) DBFClose(hNewDBF); if (hNewSHP) SHPClose(hNewSHP); GSList* plstNewDBFs = lstNewDBFs; while (plstNewDBFs) { DBFClose((DBFHandle)plstNewDBFs->data); plstNewDBFs = plstNewDBFs->next; } g_slist_free(lstNewDBFs); GSList* plstNewSHPs = lstNewSHPs; while (plstNewSHPs) { SHPClose((SHPHandle)plstNewSHPs->data); plstNewSHPs = plstNewSHPs->next; } g_slist_free(lstNewSHPs); // g_assert(g_file_test(filteredPath, G_FILE_TEST_EXISTS)); return filteredPath; }