int main (int argc, char **argv) { double start, stop; dstring_t *portalfile = dstring_new (); QFile *f; start = Sys_DoubleTime (); this_program = argv[0]; DecodeArgs (argc, argv); if (!options.bspfile) { usage (1); Sys_Error ("%s: no bsp file specified.", this_program); } QFS_SetExtension (options.bspfile, ".bsp"); f = Qopen (options.bspfile->str, "rb"); if (!f) Sys_Error ("couldn't open %s for reading.", options.bspfile->str); bsp = LoadBSPFile (f, Qfilesize (f)); Qclose (f); visdata = dstring_new (); dstring_copystr (portalfile, options.bspfile->str); QFS_SetExtension (portalfile, ".prt"); LoadPortals (portalfile->str); uncompressed = calloc (bitbytes_l, portalclusters); CalcVis (); if (options.verbosity >= 0) printf ("c_chains: %i%s\n", c_chains, options.threads > 1 ? " (not reliable)" :""); BSP_AddVisibility (bsp, (byte *) visdata->str, visdata->size); if (options.verbosity >= 0) printf ("visdatasize:%ld compressed from %ld\n", (long) bsp->visdatasize, (long) originalvismapsize); CalcAmbientSounds (); f = Qopen (options.bspfile->str, "wb"); if (!f) Sys_Error ("couldn't open %s for writing.", options.bspfile->str); WriteBSPFile (bsp, f); Qclose (f); stop = Sys_DoubleTime (); if (options.verbosity >= 0) printf ("%5.1f seconds elapsed\n", stop - start); return 0; }
VISIBLE void Cmd_Exec_File (cbuf_t *cbuf, const char *path, int qfs) { char *f; int len; QFile *file; if (!path || !*path) return; if (qfs) { QFS_FOpenFile (path, &file); } else { char *newpath = Sys_ExpandSquiggle (path); file = Qopen (newpath, "r"); free (newpath); } if (file) { len = Qfilesize (file); f = (char *) malloc (len + 1); if (f) { f[len] = 0; Qread (file, f, len); Cbuf_InsertText (cbuf, f); free (f); } Qclose (file); } }
void process_wad_script (const char *name) { char *buf; QFile *file; int bytes; script_t *script; file = Qopen (name, "rt"); if (!file) Sys_Error ("couldn't open %s. %s", name, strerror(errno)); bytes = Qfilesize (file); buf = malloc (bytes + 1); bytes = Qread (file, buf, bytes); buf[bytes] = 0; Qclose (file); dstring_copystr (&destfile, name); dstring_appendstr (&destfile, ".wad"); script = Script_New (); Script_Start (script, name, buf); parse_script (script); if (wadfile) wad_close (wadfile); }
int SND_LoadMidi (QFile *file, sfx_t *sfx, char *realname) { wavinfo_t info; midi *handle; unsigned char *local_buffer; unsigned long int local_buffer_size = Qfilesize (file); if (!midi_intiialized) { if (midi_init ()) { return -1; } } local_buffer = malloc (local_buffer_size); Qread (file, local_buffer, local_buffer_size); Qclose (file); // WildMidi takes ownership, so be damned if you touch it handle = WildMidi_OpenBuffer (local_buffer, local_buffer_size); if (handle == NULL) return -1; info = midi_get_info (handle); WildMidi_Close (handle); Sys_MaskPrintf (SYS_DEV, "stream %s\n", realname); // we init stream here cause we will only ever stream SND_SFX_Stream (sfx, realname, info, midi_stream_open); return 0; }
static sfx_t * midi_stream_open (sfx_t *sfx) { sfxstream_t *stream = sfx->data.stream; QFile *file; midi *handle; unsigned char *local_buffer; unsigned long int local_buffer_size; midi_file_t *mf; QFS_FOpenFile (stream->file, &file); local_buffer_size = Qfilesize (file); local_buffer = malloc (local_buffer_size); Qread (file, local_buffer, local_buffer_size); Qclose (file); handle = WildMidi_OpenBuffer(local_buffer, local_buffer_size); if (handle == NULL) return NULL; mf = calloc (sizeof (midi_file_t), 1); mf->handle = handle; return SND_SFX_StreamOpen (sfx, mf, midi_stream_read, midi_stream_seek, midi_stream_close); }
void Menu_Load (void) { int size; QFile *file; Hash_FlushTable (menu_hash); menu = 0; top_menu = 0; menu_pr_state.progs = 0; if ((file = QFS_FOpenFile (menu_pr_state.progs_name))) { size = Qfilesize (file); PR_LoadProgsFile (&menu_pr_state, file, size, 0, 1024 * 1024); Qclose (file); if (!PR_RunLoadFuncs (&menu_pr_state)) { free (menu_pr_state.progs); menu_pr_state.progs = 0; } } if (!menu_pr_state.progs) { // Not a fatal error, just means no menus Con_SetOrMask (0x80); Sys_Printf ("Menu_Load: could not load %s\n", menu_pr_state.progs_name); Con_SetOrMask (0x00); return; } run_menu_pre (); RUA_Cbuf_SetCbuf (&menu_pr_state, con_data.cbuf); InputLine_Progs_SetDraw (&menu_pr_state, C_DrawInputLine); PR_ExecuteProgram (&menu_pr_state, menu_init); run_menu_post (); }
static QFile * open_file (const char *path, int *len) { QFile *file = Qopen (path, "rbz"); if (!file) return 0; *len = Qfilesize (file); return file; }
int main (int argc, char *argv[]) { QFile *bspfile; bsp_t *bsp; image_t *image; /* Enough args? */ if (argc < 3) { show_help (); return 1; } /* Setup options */ def_options (&options); get_options (&options, argc, argv); show_options (&options); bspfile = Qopen (options.bspf_name, "rbz"); if (bspfile == NULL) { fprintf (stderr, "Error opening bsp file %s.\n", options.bspf_name); return 1; } bsp = LoadBSPFile (bspfile, Qfilesize (bspfile)); Qclose (bspfile); image = render_map (bsp); BSP_Free (bsp); /* Write image */ switch (options.outf_type) { case 0: write_pcx (image); break; case 1: write_png (image); break; } printf ("File written to %s.\n", options.outf_name); /* Close, done! */ free (image->image); free (image); return 0; }
/* we've opened the trackmap file from the quake resources * go through it, and make ourselves a tracklist map */ static int Load_Tracklist (void) { QFile *oggfile = NULL; char *buffile = NULL; int size; /* kill off the old tracklist, and make sure we're not playing anything */ I_OGGMus_Shutdown (); ogglistvalid = false; mus_enabled = false; if (!mus_ogglist || strequal (mus_ogglist->string, "none")) { return -1; // bail if we don't have a valid filename } oggfile = QFS_FOpenFile (mus_ogglist->string); if (!oggfile) { Sys_Printf ("Mus_OggInit: open of file \"%s\" failed\n", mus_ogglist->string); return -1; } if (!oggfile) { return -1; } /* rewind the stream */ Qseek (oggfile, 0, SEEK_SET); size = Qfilesize (oggfile); buffile = calloc (size+10, sizeof (char)); Qread (oggfile, buffile, size); tracklist = PL_GetPropertyList (buffile); if (!tracklist || PL_Type (tracklist) != QFDictionary) { Sys_Printf ("Malformed or empty tracklist file. check mus_ogglist\n"); return -1; } free (buffile); Qclose (oggfile); ogglistvalid = true; mus_enabled = true; return 0; }
static void Host_Loadgame_f (void) { dstring_t *name = 0; QFile *f; char *mapname = 0; script_t *script = 0; plitem_t *game = 0; plitem_t *list; plitem_t *item; char *script_data = 0; int i; int entnum; int count; int version; float spawn_parms[NUM_SPAWN_PARMS]; if (cmd_source != src_command) goto end; if (Cmd_Argc () != 2) { Sys_Printf ("load <savename> : load a game\n"); goto end; } cls.demonum = -1; // stop demo loop in case this fails name = dstring_newstr (); dsprintf (name, "%s/%s", qfs_gamedir->dir.def, Cmd_Argv (1)); QFS_DefaultExtension (name, ".sav"); cl.loading = true; CL_UpdateScreen (cl.time); Sys_Printf ("Loading game from %s...\n", name->str); f = QFS_Open (name->str, "rz"); if (!f) { Sys_Printf ("ERROR: couldn't open.\n"); goto end; } script_data = malloc (Qfilesize (f) + 1); i = Qread (f, script_data, Qfilesize (f)); script_data[i] = 0; Qclose (f); script = Script_New (); script->single = ""; // disable {}()': lexing Script_Start (script, name->str, script_data); Script_GetToken (script, 1); if (strequal (script->token->str, PACKAGE_NAME)) { if (!Script_TokenAvailable (script, 1)) { Sys_Printf ("Unexpected EOF reading %s\n", name->str); goto end; } game = PL_GetPropertyList (script->p); } else { sscanf (script->token->str, "%i", &version); if (version != SAVEGAME_VERSION) { Sys_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION); goto end; } game = convert_to_game_dict (script); } item = PL_ObjectForKey (game, "spawn_parms"); for (i = 0; i < NUM_SPAWN_PARMS; i++) { if (i >= PL_A_NumObjects (item)) break; spawn_parms[i] = atof (PL_String (PL_ObjectAtIndex (item, i))); } current_skill = atoi (PL_String (PL_ObjectForKey (game, "current_skill"))); Cvar_SetValue (skill, current_skill); mapname = strdup (PL_String (PL_ObjectForKey (game, "name"))); CL_Disconnect_f (); SV_SpawnServer (mapname); if (!sv.active) { Sys_Printf ("Couldn't load map %s\n", mapname); goto end; } sv.paused = true; // pause until all clients connect sv.loadgame = true; list = PL_ObjectForKey (game, "lightstyles"); for (i = 0; i < MAX_LIGHTSTYLES; i++) { const char *style; char *str; if (i >= PL_A_NumObjects (list)) break; item = PL_ObjectAtIndex (list, i); style = PL_String (item); sv.lightstyles[i] = str = Hunk_Alloc (strlen (style) + 1); strcpy (str, style); } ED_InitGlobals (&sv_pr_state, PL_ObjectForKey (game, "globals")); list = PL_ObjectForKey (game, "entities"); entnum = 0; count = PL_A_NumObjects (list); if (count > sv.max_edicts) Host_Error ("too many entities in saved game. adjust max_edicts\n"); for (entnum = 0; entnum < count; entnum++) { plitem_t *entity = PL_ObjectAtIndex (list, entnum); edict_t *ent = EDICT_NUM (&sv_pr_state, entnum); memset (&ent->v, 0, sv_pr_state.progs->entityfields * 4); ent->free = false; ED_InitEntity (&sv_pr_state, entity, ent); // link it into the bsp tree if (!ent->free) SV_LinkEdict (ent, false); } sv.num_edicts = entnum; sv.time = atof (PL_String (PL_ObjectForKey (game, "time"))); for (i = 0; i < NUM_SPAWN_PARMS; i++) svs.clients->spawn_parms[i] = spawn_parms[i]; if (cls.state != ca_dedicated) { CL_EstablishConnection ("local"); Host_Reconnect_f (); } end: if (game) PL_Free (game); if (mapname) free (mapname); if (script) Script_Delete (script); if (script_data) free (script_data); if (name) dstring_delete (name); }