Use Qprintf for writing maps, and fileSystemRepresentation to get the path.

This commit is contained in:
Bill Currie 2010-12-27 12:11:07 +09:00
parent dc99bc19c5
commit d29e8deb0a
7 changed files with 32 additions and 31 deletions

View file

@ -4,6 +4,7 @@
#include <AppKit/AppKit.h> #include <AppKit/AppKit.h>
#include "QF/mathlib.h" #include "QF/mathlib.h"
#include "QF/quakeio.h"
typedef struct epair_s { typedef struct epair_s {
struct epair_s *next; struct epair_s *next;
@ -30,7 +31,7 @@ typedef struct epair_s {
- (const char *) targetname; - (const char *) targetname;
- (void) writeToFILE: (FILE *)f region: (BOOL)reg; - (void) writeToFile: (QFile *)file region: (BOOL)reg;
- (const char *) valueForQKey: (const char *)k; - (const char *) valueForQKey: (const char *)k;
- (void) getVector: (vec3_t)v forKey: (const char *)k; - (void) getVector: (vec3_t)v forKey: (const char *)k;

View file

@ -393,7 +393,7 @@ int nument;
return self; return self;
} }
- (void) writeToFILE: (FILE *)f - (void) writeToFile: (QFile *)file
region: (BOOL)reg; region: (BOOL)reg;
{ {
epair_t *e; epair_t *e;
@ -417,7 +417,7 @@ int nument;
} }
} }
fprintf (f, "{\n"); Qprintf (file, "{\n");
// set an origin epair // set an origin epair
if (!modifiable) { if (!modifiable) {
@ -441,15 +441,15 @@ int nument;
} }
for (e = epairs; e; e = e->next) for (e = epairs; e; e = e->next)
fprintf (f, "\"%s\"\t\"%s\"\n", e->key, e->value); Qprintf (file, "\"%s\"\t\"%s\"\n", e->key, e->value);
// fixed size entities don't save out brushes // fixed size entities don't save out brushes
if (modifiable) { if (modifiable) {
for (i = 0; i < [self count]; i++) for (i = 0; i < [self count]; i++)
[[self objectAtIndex: i] writeToFILE: f region: reg]; [[self objectAtIndex: i] writeToFile: file region: reg];
} }
fprintf (f, "}\n"); Qprintf (file, "}\n");
if (oldang) { if (oldang) {
[self setKey: "angle" toValue: oldang]; [self setKey: "angle" toValue: oldang];

View file

@ -22,7 +22,7 @@ extern id map_i;
- (id) writeStats; - (id) writeStats;
- (id) readMapFile: (NSString *)fname; - (id) readMapFile: (NSString *)fname;
- (id) writeMapFile: (const char *)fname useRegion: (BOOL)reg; - (id) writeMapFile: (NSString *)fname useRegion: (BOOL)reg;
- (id) entityConnect: (vec3_t)p1: (vec3_t)p2; - (id) entityConnect: (vec3_t)p1: (vec3_t)p2;

View file

@ -1,5 +1,8 @@
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "QF/quakeio.h" #include "QF/quakeio.h"
#include "QF/script.h" #include "QF/script.h"
@ -301,22 +304,23 @@ readMapFile
writeMapFile writeMapFile
================= =================
*/ */
- (id) writeMapFile: (const char *)fname - (id) writeMapFile: (NSString *)fname
useRegion: (BOOL)reg useRegion: (BOOL)reg
{ {
FILE *f;
unsigned int i; unsigned int i;
QFile *file = 0;
Sys_Printf ("writeMapFile: %s\n", fname); NSLog (@"writeMapFile: %@\n", fname);
f = fopen (fname, "w"); file = Qopen ([fname fileSystemRepresentation], "wb");
if (!f) if (!file) {
Sys_Error ("couldn't write %s", fname); NSLog (@"couldn't write %@, %s", fname, strerror (errno));
return self;
}
for (i = 0; i < [self count]; i++) for (i = 0; i < [self count]; i++)
[[self objectAtIndex: i] writeToFILE: f region: reg]; [[self objectAtIndex: i] writeToFile: file region: reg];
fclose (f);
Qclose (file);
return self; return self;
} }

View file

@ -133,8 +133,8 @@ Every five minutes, save a modified map
// automatic backup // automatic backup
if (autodirty) { if (autodirty) {
autodirty = NO; autodirty = NO;
#define FN_AUTOSAVE "/qcache/AutoSaveMap.map" #define FN_AUTOSAVE @"/qcache/AutoSaveMap.map"
[map_i writeMapFile: (char *) FN_AUTOSAVE useRegion: NO]; [map_i writeMapFile: FN_AUTOSAVE useRegion: NO];
} }
[map_i writeStats]; [map_i writeStats];
} }
@ -676,7 +676,7 @@ saveBSP
if ([regionbutton_i intValue]) { if ([regionbutton_i intValue]) {
mappath = [[filename stringByDeletingPathExtension] mappath = [[filename stringByDeletingPathExtension]
stringByAppendingPathExtension: @"reg"]; stringByAppendingPathExtension: @"reg"];
[map_i writeMapFile: [mappath cString] useRegion: YES]; [map_i writeMapFile: mappath useRegion: YES];
wt = YES; // allways pop the dialog on region ops wt = YES; // allways pop the dialog on region ops
} else { } else {
mappath = filename; mappath = filename;
@ -838,7 +838,7 @@ save:
stringByAppendingPathExtension: @"bak"]; stringByAppendingPathExtension: @"bak"];
rename ([filename cString], [backup cString]); // copy old to .bak rename ([filename cString], [backup cString]); // copy old to .bak
[map_i writeMapFile: [filename cString] useRegion: NO]; [map_i writeMapFile: filename useRegion: NO];
return self; return self;
} }

View file

@ -4,6 +4,7 @@
#include <AppKit/AppKit.h> #include <AppKit/AppKit.h>
#include "QF/mathlib.h" #include "QF/mathlib.h"
#include "QF/quakeio.h"
#include "TexturePalette.h" #include "TexturePalette.h"
@ -75,7 +76,7 @@ winding_t *NewWinding (int points);
- (id) calcWindings; - (id) calcWindings;
- (void) writeToFILE: (FILE *)f region: (BOOL)reg; - (void) writeToFile: (QFile *)file region: (BOOL)reg;
- (BOOL) selected; - (BOOL) selected;
- (BOOL) regioned; - (BOOL) regioned;

View file

@ -778,12 +778,7 @@ ParseVerts (script_t *script, int *n_verts)
return self; return self;
} }
/* - (void) writeToFile: (QFile *)file
===========
writeToFILE
===========
*/
- (void) writeToFILE: (FILE *)f
region: (BOOL)reg region: (BOOL)reg
{ {
int i, j; int i, j;
@ -792,19 +787,19 @@ writeToFILE
if (reg && regioned) if (reg && regioned)
return; return;
fprintf (f, "{\n"); Qprintf (file, "{\n");
for (i = 0; i < numfaces; i++) { for (i = 0; i < numfaces; i++) {
fa = &faces[i]; fa = &faces[i];
for (j = 0; j < 3; j++) { for (j = 0; j < 3; j++) {
fprintf (f, "( %d %d %d ) ", (int) fa->planepts[j][0], Qprintf (file, "( %d %d %d ) ", (int) fa->planepts[j][0],
(int) fa->planepts[j][1], (int) fa->planepts[j][2]); (int) fa->planepts[j][1], (int) fa->planepts[j][2]);
} }
td = &fa->texture; td = &fa->texture;
fprintf (f, "%s %d %d %d %f %f\n", td->texture, (int) td->shift[0], Qprintf (file, "%s %d %d %d %f %f\n", td->texture, (int) td->shift[0],
(int) td->shift[1], (int) td->rotate, td->scale[0], (int) td->shift[1], (int) td->rotate, td->scale[0],
td->scale[1]); td->scale[1]);
} }
fprintf (f, "}\n"); Qprintf (file, "}\n");
return; return;
} }