Forge: Map and PopScrollView build now.

This commit is contained in:
Jeff Teunissen 2001-05-07 09:43:25 +00:00
parent cc68e1a12e
commit a45dd9b289
4 changed files with 115 additions and 142 deletions

View file

@ -1,7 +1,7 @@
// Map is a list of Entity objects // Map is a collection of Entity objects
extern id map_i; extern id map_i;
@interface Map: NSMutableArray @interface Map: NSMutableArray
{ {
@ -10,12 +10,12 @@ extern id map_i;
float minz, maxz; float minz, maxz;
} }
- newMap; - (void) newMap;
- writeStats; - (void) writeStats;
- readMapFile: (NSString *) fname; - (void) readMapFile: (NSString *) fname;
- writeMapFile: (NSString *) fname useRegion: (BOOL) reg; - (void) writeMapFile: (NSString *) fname useRegion: (BOOL) reg;
- entityConnect: (vec3_t) p1 : (vec3_t) p2; - entityConnect: (vec3_t) p1 : (vec3_t) p2;
@ -24,16 +24,16 @@ extern id map_i;
- setTextureRay: (vec3_t) p1 : (vec3_t) p2 : (BOOL) allsides; - setTextureRay: (vec3_t) p1 : (vec3_t) p2 : (BOOL) allsides;
- getTextureRay: (vec3_t) p1 : (vec3_t) p2; - getTextureRay: (vec3_t) p1 : (vec3_t) p2;
- currentEntity; - (id) currentEntity;
- setCurrentEntity: ent; - (void) setCurrentEntity: (id) ent;
- (float) currentMinZ;
- setCurrentMinZ: (float) m;
- (float) currentMaxZ; - (float) currentMaxZ;
- setCurrentMaxZ: (float) m; - (float) currentMinZ;
- (void) setCurrentMaxZ: (float) m;
- (void) setCurrentMinZ: (float) m;
- (int) numSelected; - (int) numSelected;
- selectedBrush; // returns the first selected brush - (id) selectedBrush; // returns the first selected brush
// //
// operations on current selection // operations on current selection

View file

@ -2,10 +2,11 @@
@interface PopScrollView: NSScrollView @interface PopScrollView: NSScrollView
{ {
id button1, button2; NSButton *button1;
NSButton *button2;
} }
- initFrame:(const NSRect *)frameRect button1: b1 button2: b2; - (id) initWithFrame: (NSRect) frameRect button1: (NSButton *) b1 button2: (NSButton *) b2;
- tile; - (void) tile;
@end @end

View file

@ -13,7 +13,7 @@ FILE METHODS
=============================================================================== ===============================================================================
*/ */
- init - (id) init
{ {
[super init]; [super init];
map_i = self; map_i = self;
@ -25,7 +25,7 @@ FILE METHODS
return self; return self;
} }
- saveSelected - (void) saveSelected
{ {
int i, c; int i, c;
id o, w; id o, w;
@ -34,31 +34,28 @@ FILE METHODS
w = [self objectAtIndex: 0]; w = [self objectAtIndex: 0];
c = [w count]; c = [w count];
sb_newowner = oldselection; sb_newowner = oldselection;
for (i=0 ; i<c ; i++) for (i = 0; i < c; i++) {
{
o = [w objectAtIndex: 0]; o = [w objectAtIndex: 0];
if ([o selected]) if ([o selected]) {
[o moveToEntity]; [o moveToEntity];
else } else {
{
[w removeObjectAtIndex: 0]; [w removeObjectAtIndex: 0];
[o free]; [o release];
} }
} }
c = [self count]; c = [self count];
for (i=0 ; i<c ; i++) for (i = 0; i < c; i++) {
{
o = [self objectAtIndex: 0]; o = [self objectAtIndex: 0];
[self removeObjectAtIndex: 0]; [self removeObjectAtIndex: 0];
[o freeObjects]; [o removeAllObjects];
[o free]; [o release];
} }
return self; return;
} }
- addSelected - (void) addSelected
{ {
int i, c; int i, c;
id n, w; id n, w;
@ -67,20 +64,17 @@ FILE METHODS
w = [self objectAtIndex: 0]; // world object w = [self objectAtIndex: 0]; // world object
sb_newowner = w; sb_newowner = w;
for (i=0 ; i<c ; i++) for (i = 0; i < c; i++) {
{ n = [oldselection objectAtIndex: i--];
n = [oldselection objectAtIndex:i];
[n moveToEntity]; [n moveToEntity];
i--;
c--; c--;
} }
[oldselection removeAllObjects]; [oldselection removeAllObjects];
return self; return;
} }
- (void) newMap
- newMap
{ {
id ent; id ent;
@ -91,30 +85,29 @@ FILE METHODS
[self setCurrentEntity: ent]; [self setCurrentEntity: ent];
[self addSelected]; [self addSelected];
return self; return;
} }
- currentEntity - (id) currentEntity
{ {
return currentEntity; return currentEntity;
} }
- setCurrentEntity: ent - (void) setCurrentEntity: ent
{ {
id old; id old;
old = currentEntity; old = currentEntity;
currentEntity = ent; currentEntity = ent;
if (old != ent) if (old != ent) {
{
[things_i newCurrentEntity]; // update inspector [things_i newCurrentEntity]; // update inspector
[inspcontrol_i changeInspectorTo:i_things]; [inspcontrol_i changeInspectorTo:i_things];
} }
return self; return;
} }
- (float)currentMinZ - (float) currentMinZ
{ {
float grid; float grid;
@ -123,14 +116,14 @@ FILE METHODS
return minz; return minz;
} }
- setCurrentMinZ: (float)m - (void) setCurrentMinZ: (float) m
{ {
if (m > -2048) if (m > -2048)
minz = m; minz = m;
return self; return;
} }
- (float)currentMaxZ - (float) currentMaxZ
{ {
float grid; float grid;
@ -144,58 +137,54 @@ FILE METHODS
return maxz; return maxz;
} }
- setCurrentMaxZ: (float)m - (void) setCurrentMaxZ: (float) m
{ {
if (m < 2048) if (m < 2048)
maxz = m; maxz = m;
return self; return;
} }
- (void) removeObject: o - (void) removeObject: (id) o
{ {
[super removeObject: o]; [super removeObject: o];
if (o == currentEntity) if (o == currentEntity) { // select the world
{ // select the world
[self setCurrentEntity: [self objectAtIndex: 0]]; [self setCurrentEntity: [self objectAtIndex: 0]];
} }
} }
- writeStats - (void) writeStats
{ {
FILE *f; FILE *f;
extern int c_updateall; extern int c_updateall;
struct timeval tp; struct timeval tp;
struct timezone tzp; struct timezone tzp;
gettimeofday(&tp, &tzp); gettimeofday (&tp, &tzp);
f = fopen (FN_DEVLOG, "a"); f = fopen ([developerLogFile cString], "a");
fprintf (f,"%i %i\n", (int)tp.tv_sec, c_updateall); fprintf (f,"%i %i\n", (int) tp.tv_sec, c_updateall);
c_updateall = 0; c_updateall = 0;
fclose (f); fclose (f);
return self; return;
} }
- (int)numSelected - (int) numSelected
{ {
int i, c; int i, c;
int num; int num = 0;
num = 0;
c = [currentEntity count]; c = [currentEntity count];
for (i=0 ; i<c ; i++) for (i = 0; i < c; i++)
if ( [[currentEntity objectAtIndex: i] selected] ) if ([[currentEntity objectAtIndex: i] selected])
num++; num++;
return num; return num;
} }
- selectedBrush - (id) selectedBrush
{ {
int i, c; int i, c;
int num;
num = 0;
c = [currentEntity count]; c = [currentEntity count];
for (i=0 ; i<c ; i++) for (i=0 ; i<c ; i++)
if ( [[currentEntity objectAtIndex: i] selected] ) if ( [[currentEntity objectAtIndex: i] selected] )
@ -209,7 +198,7 @@ FILE METHODS
readMapFile readMapFile
================= =================
*/ */
- readMapFile: (char *)fname - (void) readMapFile: (NSString *) fname
{ {
char *dat, *cl; char *dat, *cl;
id new; id new;
@ -220,13 +209,12 @@ readMapFile
[self saveSelected]; [self saveSelected];
qprintf ("loading %s\n", fname); NSLog (@"loading %s\n", fname);
LoadFile (fname, (void **)&dat); LoadFile ((char *) [fname cString], (void **) &dat);
StartTokenParsing (dat); StartTokenParsing (dat);
do do {
{
new = [[Entity alloc] initFromTokens]; new = [[Entity alloc] initFromTokens];
if (!new) if (!new)
break; break;
@ -239,27 +227,23 @@ readMapFile
[self addSelected]; [self addSelected];
// load the apropriate texture wad // load the apropriate texture wad
dat = [currentEntity valueForQKey: "wad"]; dat = [currentEntity valueForQKey: "wad"];
if (dat && dat[0]) if (dat && dat[0]) {
{ if (dat[0] == '/') { // remove old style fullpaths
if (dat[0] == '/') // remove old style fullpaths
[currentEntity removeKeyPair: "wad"]; [currentEntity removeKeyPair: "wad"];
else } else {
{
if (strcmp ([texturepalette_i currentWad], dat) ) if (strcmp ([texturepalette_i currentWad], dat) )
[project_i setTextureWad: dat]; [project_i setTextureWad: dat];
} }
} }
// center the camera and XY view on the playerstart // center the camera and XY view on the playerstart
c = [self count]; c = [self count];
for (i=1 ; i<c ; i++) for (i=1 ; i<c ; i++) {
{
ent = [self objectAtIndex: i]; ent = [self objectAtIndex: i];
cl = [ent valueForQKey: "classname"]; cl = [ent valueForQKey: "classname"];
if (cl && !strcasecmp (cl,"info_player_start")) if (cl && !strcasecmp (cl,"info_player_start")) {
{
angle = atof( [ent valueForQKey: "angle"] ); angle = atof( [ent valueForQKey: "angle"] );
angle = angle/180*M_PI; angle = angle/180*M_PI;
[ent getVector: org forKey: "origin"]; [ent getVector: org forKey: "origin"];
@ -269,7 +253,7 @@ readMapFile
} }
} }
return self; return;
} }
/* /*
@ -277,23 +261,22 @@ readMapFile
writeMapFile writeMapFile
================= =================
*/ */
- writeMapFile: (char *)fname useRegion: (BOOL)reg - (void) writeMapFile: (NSString *) fname useRegion: (BOOL) reg
{ {
FILE *f; FILE *f;
int i; int i;
qprintf ("writeMapFile: %s", fname); NSLog (@"writeMapFile: %s", fname);
f = fopen (fname,"w"); if (!(f = fopen ([fname cString], "w")))
if (!f) NSLog (@"couldn't write %s", fname);
Error ("couldn't write %s", fname);
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: f region: reg];
fclose (f); fclose (f);
return self; return;
} }
/* /*
@ -395,12 +378,10 @@ to intervening world brushes
besttime = 99999; besttime = 99999;
c = [self count]; c = [self count];
for (i=c-1 ; i>=0 ; i--) for (i = c - 1; i >= 0; i--) {
{
ent = [self objectAtIndex: i]; ent = [self objectAtIndex: i];
c2 = [ent count]; c2 = [ent count];
for (j=0 ; j<c2 ; j++) for (j = 0; j < c2; j++) {
{
brush = [ent objectAtIndex: j]; brush = [ent objectAtIndex: j];
[brush hitByRay: p1 : p2 : &time : &face]; [brush hitByRay: p1 : p2 : &time : &face];
if (time < 0 || time >besttime) if (time < 0 || time >besttime)
@ -414,43 +395,36 @@ to intervening world brushes
break; // found an entity, so don't check the world break; // found an entity, so don't check the world
} }
if (besttime == 99999) if (besttime == 99999) {
{
qprintf ("trace missed"); qprintf ("trace missed");
return self; return self;
} }
if ( [bestbrush regioned] ) if ( [bestbrush regioned] ) {
{
qprintf ("WANRING: clicked on regioned brush"); qprintf ("WANRING: clicked on regioned brush");
return self; return self;
} }
if (bestent != currentEntity) if (bestent != currentEntity) {
{
[self makeSelectedPerform: @selector(deselect)]; [self makeSelectedPerform: @selector(deselect)];
[self setCurrentEntity: bestent]; [self setCurrentEntity: bestent];
} }
[quakeed_i disableFlushWindow]; [quakeed_i disableFlushWindow];
if ( ![bestbrush selected] ) if (![bestbrush selected]) {
{ if ([map_i numSelected] == 0) { // don't grab texture if others are selected
if ( [map_i numSelected] == 0)
{ // don't grab texture if others are selected
td = [bestbrush texturedefForFace: bestface]; td = [bestbrush texturedefForFace: bestface];
[texturepalette_i setTextureDef: td]; [texturepalette_i setTextureDef: td];
} }
[bestbrush setSelected: YES]; [bestbrush setSelected: YES];
qprintf ("selected entity %i brush %i face %i", [self indexOfObject:bestent], [bestent indexOfObject: bestbrush], bestface); qprintf ("selected entity %i brush %i face %i", [self indexOfObject:bestent], [bestent indexOfObject: bestbrush], bestface);
} } else {
else
{
[bestbrush setSelected: NO]; [bestbrush setSelected: NO];
qprintf ("deselected entity %i brush %i face %i", [self indexOfObject:bestent], [bestent indexOfObject: bestbrush], bestface); qprintf ("deselected entity %i brush %i face %i", [self indexOfObject:bestent], [bestent indexOfObject: bestbrush], bestface);
} }
[quakeed_i reenableFlushWindow]; [quakeed_i enableFlushWindow];
[quakeed_i updateAll]; [quakeed_i updateAll];
return self; return self;
@ -627,7 +601,7 @@ setTextureRay
[bestbrush setTexturedef: &td forFace: bestface]; [bestbrush setTexturedef: &td forFace: bestface];
qprintf ("deselected entity %i brush %i face %i", [self indexOfObject:bestent], [bestent indexOfObject: bestbrush], bestface); qprintf ("deselected entity %i brush %i face %i", [self indexOfObject:bestent], [bestent indexOfObject: bestbrush], bestface);
} }
[quakeed_i reenableFlushWindow]; [quakeed_i enableFlushWindow];
[quakeed_i updateAll]; [quakeed_i updateAll];
@ -925,14 +899,14 @@ UI operations
if (currentEntity != [self objectAtIndex: 0]) if (currentEntity != [self objectAtIndex: 0])
{ {
qprintf ("ERROR: can't makeEntity inside an entity"); qprintf ("ERROR: can't makeEntity inside an entity");
NXBeep (); NSBeep ();
return self; return self;
} }
if ( [self numSelected] == 0) if ( [self numSelected] == 0)
{ {
qprintf ("ERROR: must have a seed brush to make an entity"); qprintf ("ERROR: must have a seed brush to make an entity");
NXBeep (); NSBeep ();
return self; return self;
} }
@ -1084,7 +1058,7 @@ subtractSelection
{ {
o2 = [sourcelist objectAtIndex: j]; o2 = [sourcelist objectAtIndex: j];
[o2 carve]; [o2 carve];
[carve_in freeObjects]; [carve_in removeAllObjects];
} }
[sourcelist free]; // the individual have been moved/freed [sourcelist free]; // the individual have been moved/freed
@ -1094,8 +1068,8 @@ subtractSelection
// add the selection back to the remnants // add the selection back to the remnants
[currentEntity removeAllObjects]; [currentEntity removeAllObjects];
[currentEntity appendList: sourcelist]; [currentEntity addObjectsFromArray: sourcelist];
[currentEntity appendList: sellist]; [currentEntity addObjectsFromArray: sellist];
[sourcelist free]; [sourcelist free];
[sellist free]; [sellist free];

View file

@ -11,9 +11,9 @@ Initizes a scroll view with a button at it's lower right corner
==================== ====================
*/ */
- initFrame:(const NXRect *)frameRect button1:b1 button2:b2 - (id) initWithFrame: (NSRect) frameRect button1: (NSButton *) b1 button2: (NSButton *) b2
{ {
[super initFrame: frameRect]; [super initWithFrame: frameRect];
[self addSubview: b1]; [self addSubview: b1];
[self addSubview: b2]; [self addSubview: b2];
@ -21,11 +21,11 @@ Initizes a scroll view with a button at it's lower right corner
button1 = b1; button1 = b1;
button2 = b2; button2 = b2;
[self setHorizScrollerRequired: YES]; [self setHasHorizontalScroller: YES];
[self setVertScrollerRequired: YES]; [self setHasVerticalScroller: YES];
[self setBorderType: NSBezelBorder];
[self setBorderType: NX_BEZEL];
return self; return self;
} }
@ -38,50 +38,48 @@ Adjust the size for the pop up scale menu
================= =================
*/ */
- tile - (void) tile
{ {
NXRect scrollerframe; NSRect scrollerframe;
NXRect buttonframe, buttonframe2; NSRect buttonframe, buttonframe2;
NXRect newframe; NSRect newframe;
[super tile]; [super tile];
[button1 getFrame: &buttonframe]; [button1 setFrame: buttonframe];
[button2 getFrame: &buttonframe2]; [button2 setFrame: buttonframe2];
[hScroller getFrame: &scrollerframe]; [[self horizontalScroller] setFrame: scrollerframe];
newframe.origin.y = scrollerframe.origin.y; newframe.origin.y = scrollerframe.origin.y;
newframe.origin.x = frame.size.width - buttonframe.size.width; newframe.origin.x = [self frame].size.width - buttonframe.size.width;
newframe.size.width = buttonframe.size.width; newframe.size.width = buttonframe.size.width;
newframe.size.height = scrollerframe.size.height; newframe.size.height = scrollerframe.size.height;
scrollerframe.size.width -= newframe.size.width; scrollerframe.size.width -= newframe.size.width;
[button1 setFrame: &newframe]; [button1 setFrame: newframe];
newframe.size.width = buttonframe2.size.width; newframe.size.width = buttonframe2.size.width;
newframe.origin.x -= newframe.size.width; newframe.origin.x -= newframe.size.width;
[button2 setFrame: &newframe]; [button2 setFrame: newframe];
scrollerframe.size.width -= newframe.size.width; scrollerframe.size.width -= newframe.size.width;
[hScroller setFrame: &scrollerframe]; [[self horizontalScroller] setFrame: scrollerframe];
return self; return;
} }
- superviewSizeChanged:(const NXSize *)oldSize - (void) resizeWithOldSuperviewSize: (NSSize) oldFrameSize
{ {
[super superviewSizeChanged: oldSize]; [super resizeWithOldSuperviewSize: oldFrameSize];
[[self docView] newSuperBounds]; [[self documentView] newSuperBounds];
return self; return;
} }
-(BOOL) acceptsFirstResponder - (BOOL) acceptsFirstResponder
{ {
return YES; return YES;
} }
@end @end