2003-03-18 19:48:24 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
#include "QF/quakeio.h"
|
|
|
|
#include "QF/script.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
|
|
|
#include "Map.h"
|
|
|
|
#include "Entity.h"
|
|
|
|
#include "TexturePalette.h"
|
|
|
|
#include "SetBrush.h"
|
|
|
|
#include "XYView.h"
|
|
|
|
#include "CameraView.h"
|
|
|
|
#include "QuakeEd.h"
|
|
|
|
#include "Things.h"
|
|
|
|
#include "InspectorControl.h"
|
|
|
|
#include "Project.h"
|
|
|
|
|
2010-09-12 07:25:25 +00:00
|
|
|
#define THING Map
|
|
|
|
#include "THING+NSArray.m"
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
id map_i;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
@implementation Map
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
FILE METHODS
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) init
|
2010-09-12 07:25:25 +00:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
array = [[NSMutableArray alloc] init];
|
2003-03-18 19:48:24 +00:00
|
|
|
map_i = self;
|
|
|
|
minz = 0;
|
|
|
|
maxz = 80;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
oldselection = [[NSMutableArray alloc] init];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) saveSelected
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, c;
|
|
|
|
id o, w;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[oldselection removeAllObjects];
|
2010-09-29 20:09:11 +00:00
|
|
|
w = [self objectAtIndex: 0];
|
|
|
|
c = [w count];
|
2003-03-18 19:48:24 +00:00
|
|
|
sb_newowner = oldselection;
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < c; i++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
o = [w objectAtIndex: 0];
|
2003-03-18 19:48:24 +00:00
|
|
|
if ([o selected])
|
|
|
|
[o moveToEntity];
|
2010-09-29 20:09:11 +00:00
|
|
|
else
|
|
|
|
[w removeObjectAtIndex: 0];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [self count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < c; i++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
o = [self objectAtIndex: 0];
|
|
|
|
[self removeObjectAtIndex: 0];
|
2010-09-09 11:46:38 +00:00
|
|
|
[o removeAllObjects];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) addSelected
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, c;
|
|
|
|
id n, w;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [oldselection count];
|
|
|
|
w = [self objectAtIndex: 0]; // world object
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
sb_newowner = w;
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < c; i++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
n = [oldselection objectAtIndex: i];
|
2003-03-18 19:48:24 +00:00
|
|
|
[n moveToEntity];
|
|
|
|
i--;
|
|
|
|
c--;
|
|
|
|
}
|
|
|
|
[oldselection removeAllObjects];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) newMap
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
id ent;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[self saveSelected];
|
2010-09-29 20:09:11 +00:00
|
|
|
ent = [[Entity alloc] initClass: "worldspawn"];
|
|
|
|
[self addObject: ent];
|
2003-03-18 19:48:24 +00:00
|
|
|
currentEntity = NULL;
|
2010-09-29 20:09:11 +00:00
|
|
|
[self setCurrentEntity: ent];
|
2003-03-18 19:48:24 +00:00
|
|
|
[self addSelected];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) currentEntity
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
return currentEntity;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) setCurrentEntity: ent
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
id old;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
old = currentEntity;
|
|
|
|
currentEntity = ent;
|
2010-09-11 10:03:41 +00:00
|
|
|
if (old != ent) {
|
2010-09-29 20:09:11 +00:00
|
|
|
[things_i newCurrentEntity]; // update inspector
|
2010-09-28 19:43:35 +00:00
|
|
|
[inspcontrol_i setCurrentInspector: i_things];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (float) currentMinZ
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
float grid;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
grid = [xyview_i gridsize];
|
2010-09-11 10:03:41 +00:00
|
|
|
minz = grid * rint (minz / grid);
|
2010-09-29 20:09:11 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return minz;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) setCurrentMinZ: (float)m
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
if (m > -2048)
|
|
|
|
minz = m;
|
2010-09-29 20:09:11 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (float) currentMaxZ
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
float grid;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
[self currentMinZ];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
// grid align
|
|
|
|
grid = [xyview_i gridsize];
|
2010-09-11 10:03:41 +00:00
|
|
|
maxz = grid * rint (maxz / grid);
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
if (maxz <= minz)
|
|
|
|
maxz = minz + grid;
|
2010-09-29 20:09:11 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return maxz;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) setCurrentMaxZ: (float)m
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
if (m < 2048)
|
|
|
|
maxz = m;
|
2010-09-29 20:09:11 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (void) removeObject: o
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
[super removeObject: o];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
if (o == currentEntity) // select the world
|
|
|
|
[self setCurrentEntity: [self objectAtIndex: 0]];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-11 11:30:01 +00:00
|
|
|
#define FN_DEVLOG "/qcache/devlog"
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) writeStats
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
FILE *f;
|
|
|
|
extern int c_updateall;
|
|
|
|
struct timeval tp;
|
|
|
|
struct timezone tzp;
|
|
|
|
|
|
|
|
gettimeofday (&tp, &tzp);
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
f = fopen (FN_DEVLOG, "a");
|
2010-09-29 20:09:11 +00:00
|
|
|
fprintf (f, "%i %i\n", (int) tp.tv_sec, c_updateall);
|
2003-03-18 19:48:24 +00:00
|
|
|
c_updateall = 0;
|
|
|
|
fclose (f);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (int) numSelected
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, c;
|
|
|
|
int num;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
num = 0;
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [currentEntity count];
|
|
|
|
for (i = 0; i < c; i++) {
|
|
|
|
if ([[currentEntity objectAtIndex: i] selected])
|
2003-03-18 19:48:24 +00:00
|
|
|
num++;
|
2010-09-29 20:09:11 +00:00
|
|
|
}
|
2003-03-18 19:48:24 +00:00
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) selectedBrush
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, c;
|
|
|
|
int num;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
num = 0;
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [currentEntity count];
|
|
|
|
for (i = 0; i < c; i++) {
|
|
|
|
if ([[currentEntity objectAtIndex: i] selected])
|
|
|
|
return [currentEntity objectAtIndex: i];
|
|
|
|
}
|
2003-03-18 19:48:24 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
readMapFile
|
|
|
|
=================
|
|
|
|
*/
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) readMapFile: (const char *)fname
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
char *dat;
|
|
|
|
const char *wad, *cl;
|
2010-09-11 10:03:41 +00:00
|
|
|
id new;
|
|
|
|
id ent;
|
|
|
|
int i, c;
|
|
|
|
vec3_t org;
|
|
|
|
float angle;
|
2010-09-29 20:09:11 +00:00
|
|
|
QFile *file;
|
|
|
|
script_t *script;
|
2010-09-09 11:46:38 +00:00
|
|
|
size_t size;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[self saveSelected];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
Sys_Printf ("loading %s\n", fname);
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
file = Qopen (fname, "rt");
|
2010-09-19 08:04:03 +00:00
|
|
|
if (!file)
|
|
|
|
return self;
|
2010-09-09 11:46:38 +00:00
|
|
|
size = Qfilesize (file);
|
|
|
|
dat = malloc (size + 1);
|
|
|
|
size = Qread (file, dat, size);
|
|
|
|
Qclose (file);
|
|
|
|
dat[size] = 0;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
script = Script_New ();
|
|
|
|
Script_Start (script, fname, dat);
|
|
|
|
|
|
|
|
do {
|
2010-09-29 20:09:11 +00:00
|
|
|
new = [[Entity alloc] initFromScript: script];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (!new)
|
|
|
|
break;
|
2010-09-29 20:09:11 +00:00
|
|
|
[self addObject: new];
|
2003-03-18 19:48:24 +00:00
|
|
|
} while (1);
|
|
|
|
|
|
|
|
free (dat);
|
|
|
|
|
|
|
|
[self addSelected];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-10-04 10:44:37 +00:00
|
|
|
ent = [self objectAtIndex: 0];
|
2010-09-29 20:09:11 +00:00
|
|
|
// load the apropriate texture wad
|
2010-10-04 10:44:37 +00:00
|
|
|
wad = [ent valueForQKey: "wad"];
|
2010-09-27 15:29:16 +00:00
|
|
|
if (wad && wad[0]) {
|
2010-09-29 20:09:11 +00:00
|
|
|
// remove old style fullpaths
|
|
|
|
if (wad[0] == '/')
|
2010-10-04 10:44:37 +00:00
|
|
|
[ent removeKeyPair: "wad"];
|
2010-09-29 20:09:11 +00:00
|
|
|
else if (strcmp ([texturepalette_i currentWad], wad))
|
|
|
|
[project_i setTextureWad: wad];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-28 13:17:31 +00:00
|
|
|
|
2010-10-04 10:44:37 +00:00
|
|
|
[self setCurrentEntity: ent];
|
2010-09-29 20:09:11 +00:00
|
|
|
|
|
|
|
// center the camera and XY view on the playerstart
|
|
|
|
c = [self count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 1; i < c; i++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
ent = [self objectAtIndex: i];
|
|
|
|
cl = [ent valueForQKey: "classname"];
|
2010-09-11 10:03:41 +00:00
|
|
|
if (cl && !strcasecmp (cl, "info_player_start")) {
|
2010-09-29 20:09:11 +00:00
|
|
|
angle = atof ([ent valueForQKey: "angle"]);
|
2010-09-11 10:03:41 +00:00
|
|
|
angle = angle / 180 * M_PI;
|
2010-09-29 20:09:11 +00:00
|
|
|
[ent getVector: org forKey: "origin"];
|
|
|
|
[cameraview_i setOrigin: org angle: angle];
|
|
|
|
[xyview_i centerOn: org];
|
2003-03-18 19:48:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
writeMapFile
|
|
|
|
=================
|
|
|
|
*/
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) writeMapFile: (const char *)fname
|
|
|
|
useRegion: (BOOL)reg
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
FILE *f;
|
|
|
|
unsigned int i;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("writeMapFile: %s\n", fname);
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
f = fopen (fname, "w");
|
2003-03-18 19:48:24 +00:00
|
|
|
if (!f)
|
2010-09-09 11:46:38 +00:00
|
|
|
Sys_Error ("couldn't write %s", fname);
|
2010-09-29 20:09:11 +00:00
|
|
|
for (i = 0; i < [self count]; i++)
|
|
|
|
[[self objectAtIndex: i] writeToFILE: f region: reg];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
fclose (f);
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
DRAWING
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
*/
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (void) ZDrawSelf
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, count;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
count = [self count];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < count; i++)
|
2010-09-29 20:09:11 +00:00
|
|
|
[[self objectAtIndex: i] ZDrawSelf];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (void) RenderSelf: (void (*)(face_t *))callback
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, count;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
count = [self count];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < count; i++)
|
2010-09-29 20:09:11 +00:00
|
|
|
[[self objectAtIndex: i] RenderSelf: callback];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
// ============================================================================
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
entityConnect
|
|
|
|
|
|
|
|
A command-shift-click on an entity while an entity is selected will
|
|
|
|
make a target connection from the original entity.
|
|
|
|
===================
|
|
|
|
*/
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) entityConnect: (vec3_t)p1
|
|
|
|
: (vec3_t)p2
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
id oldent, ent;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
oldent = [self currentEntity];
|
|
|
|
if (oldent == [self objectAtIndex: 0]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("Must have a non-world entity selected to connect\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
[self selectRay: p1: p2: YES];
|
|
|
|
ent = [self currentEntity];
|
2010-09-11 10:03:41 +00:00
|
|
|
if (ent == oldent) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("Must click on a different entity to connect\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
if (ent == [self objectAtIndex: 0]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("Must click on a non-world entity to connect\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
[oldent setKey: "target" toValue: [ent targetname]];
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
selectRay
|
|
|
|
|
|
|
|
If ef is true, any entity brush along the ray will be selected in preference
|
|
|
|
to intervening world brushes
|
|
|
|
=================
|
|
|
|
*/
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) selectRay: (vec3_t)p1
|
|
|
|
: (vec3_t)p2
|
|
|
|
: (BOOL)ef
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent, bestent;
|
|
|
|
id brush, bestbrush;
|
|
|
|
int face, bestface;
|
|
|
|
float time, besttime;
|
|
|
|
texturedef_t *td;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
bestent = nil;
|
|
|
|
bestface = -1;
|
|
|
|
bestbrush = nil;
|
|
|
|
besttime = 99999;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [self count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = c - 1; i >= 0; i--) {
|
2010-09-29 20:09:11 +00:00
|
|
|
ent = [self objectAtIndex: i];
|
|
|
|
c2 = [ent count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (j = 0; j < c2; j++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
brush = [ent objectAtIndex: j];
|
|
|
|
[brush hitByRay: p1 : p2 : &time : &face];
|
2010-09-11 10:03:41 +00:00
|
|
|
if (time < 0 || time > besttime)
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
|
|
|
bestent = ent;
|
|
|
|
besttime = time;
|
|
|
|
bestbrush = brush;
|
|
|
|
bestface = face;
|
|
|
|
}
|
2010-09-29 20:09:11 +00:00
|
|
|
if (i == 1 && ef && bestbrush) // found an entity, don't check the
|
|
|
|
// world
|
|
|
|
break;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if (besttime == 99999) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("trace missed\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
if ([bestbrush regioned]) {
|
2010-09-29 20:09:11 +00:00
|
|
|
Sys_Printf ("WARNING: clicked on regioned brush\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if (bestent != currentEntity) {
|
2010-09-29 20:09:11 +00:00
|
|
|
[self makeSelectedPerform: @selector (deselect)];
|
|
|
|
[self setCurrentEntity: bestent];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i disableFlushWindow];
|
2010-09-11 10:03:41 +00:00
|
|
|
if (![bestbrush selected]) {
|
2010-09-29 20:09:11 +00:00
|
|
|
// don't grab texture if others are selected
|
|
|
|
if ([map_i numSelected] == 0) {
|
|
|
|
td = [bestbrush texturedefForFace: bestface];
|
|
|
|
[texturepalette_i setTextureDef: td];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
[bestbrush setSelected: YES];
|
2010-09-28 13:17:31 +00:00
|
|
|
Sys_Printf ("selected entity %i brush %i face %i\n",
|
2010-09-29 20:09:11 +00:00
|
|
|
(int) [self indexOfObject: bestent],
|
|
|
|
(int) [bestent indexOfObject: bestbrush], bestface);
|
2010-09-11 10:03:41 +00:00
|
|
|
} else {
|
2010-09-29 20:09:11 +00:00
|
|
|
[bestbrush setSelected: NO];
|
2010-09-28 13:17:31 +00:00
|
|
|
Sys_Printf ("deselected entity %i brush %i face %i\n",
|
2010-09-29 20:09:11 +00:00
|
|
|
(int) [self indexOfObject: bestent],
|
|
|
|
(int) [bestent indexOfObject: bestbrush], bestface);
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[quakeed_i enableFlushWindow];
|
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
grabRay
|
|
|
|
|
2010-01-13 06:42:26 +00:00
|
|
|
checks only the selected brushes
|
2003-03-18 19:48:24 +00:00
|
|
|
Returns the brush hit, or nil if missed.
|
|
|
|
=================
|
|
|
|
*/
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) grabRay: (vec3_t)p1
|
|
|
|
: (vec3_t)p2
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent;
|
|
|
|
id brush, bestbrush;
|
|
|
|
int face;
|
|
|
|
float time, besttime;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
bestbrush = nil;
|
|
|
|
besttime = 99999;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [self count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < c; i++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
ent = [self objectAtIndex: i];
|
|
|
|
c2 = [ent count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (j = 0; j < c2; j++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
brush = [ent objectAtIndex: j];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (![brush selected])
|
|
|
|
continue;
|
2010-09-29 20:09:11 +00:00
|
|
|
[brush hitByRay: p1 : p2 : &time : &face];
|
2010-09-11 10:03:41 +00:00
|
|
|
if (time < 0 || time > besttime)
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
|
|
|
besttime = time;
|
|
|
|
bestbrush = brush;
|
|
|
|
}
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
if (besttime == 99999)
|
|
|
|
return nil;
|
|
|
|
return bestbrush;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
getTextureRay
|
|
|
|
=================
|
|
|
|
*/
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) getTextureRay: (vec3_t)p1
|
|
|
|
: (vec3_t)p2
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent, bestent;
|
|
|
|
id brush, bestbrush;
|
|
|
|
int face, bestface;
|
|
|
|
float time, besttime;
|
|
|
|
texturedef_t *td;
|
|
|
|
vec3_t mins, maxs;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
bestbrush = nil;
|
|
|
|
bestent = nil;
|
|
|
|
besttime = 99999;
|
|
|
|
bestface = -1;
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [self count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < c; i++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
ent = [self objectAtIndex: i];
|
|
|
|
c2 = [ent count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (j = 0; j < c2; j++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
brush = [ent objectAtIndex: j];
|
|
|
|
[brush hitByRay: p1 : p2 : &time : &face];
|
2010-09-11 10:03:41 +00:00
|
|
|
if (time < 0 || time > besttime)
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
|
|
|
bestent = ent;
|
|
|
|
bestface = face;
|
|
|
|
besttime = time;
|
|
|
|
bestbrush = brush;
|
|
|
|
}
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
if (besttime == 99999)
|
|
|
|
return nil;
|
2010-09-11 10:03:41 +00:00
|
|
|
if (![bestent modifiable]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("can't modify spawned entities\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
td = [bestbrush texturedefForFace: bestface];
|
|
|
|
[texturepalette_i setTextureDef: td];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("grabbed texturedef and sizes\n");
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
[bestbrush getMins: mins maxs: maxs];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
minz = mins[2];
|
|
|
|
maxz = maxs[2];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return bestbrush;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
setTextureRay
|
|
|
|
=================
|
|
|
|
*/
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) setTextureRay: (vec3_t)p1
|
|
|
|
: (vec3_t)p2
|
|
|
|
: (BOOL)allsides;
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent, bestent;
|
|
|
|
id brush, bestbrush;
|
|
|
|
int face, bestface;
|
|
|
|
float time, besttime;
|
|
|
|
texturedef_t td;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
bestent = nil;
|
|
|
|
bestface = -1;
|
|
|
|
bestbrush = nil;
|
|
|
|
besttime = 99999;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [self count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < c; i++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
ent = [self objectAtIndex: i];
|
|
|
|
c2 = [ent count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (j = 0; j < c2; j++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
brush = [ent objectAtIndex: j];
|
|
|
|
[brush hitByRay: p1 : p2 : &time : &face];
|
2010-09-11 10:03:41 +00:00
|
|
|
if (time < 0 || time > besttime)
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
|
|
|
bestent = ent;
|
|
|
|
besttime = time;
|
|
|
|
bestbrush = brush;
|
|
|
|
bestface = face;
|
|
|
|
}
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if (besttime == 99999) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("trace missed\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
if (![bestent modifiable]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("can't modify spawned entities\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if ([bestbrush regioned]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("WANRING: clicked on regioned brush\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
[texturepalette_i getTextureDef: &td];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i disableFlushWindow];
|
2010-09-11 10:03:41 +00:00
|
|
|
if (allsides) {
|
2010-09-29 20:09:11 +00:00
|
|
|
[bestbrush setTexturedef: &td];
|
|
|
|
Sys_Printf ("textured entity %i brush %i\n",
|
|
|
|
(int) [self indexOfObject: bestent],
|
|
|
|
(int) [bestent indexOfObject: bestbrush]);
|
2010-09-11 10:03:41 +00:00
|
|
|
} else {
|
2010-09-29 20:09:11 +00:00
|
|
|
[bestbrush setTexturedef: &td forFace: bestface];
|
|
|
|
Sys_Printf ("deselected entity %i brush %i face %i\n",
|
|
|
|
(int) [self indexOfObject: bestent],
|
|
|
|
(int) [bestent indexOfObject: bestbrush],
|
|
|
|
bestface);
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
[quakeed_i enableFlushWindow];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
OPERATIONS ON SELECTIONS
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
*/
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) makeSelectedPerform: (SEL)sel
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent, brush;
|
|
|
|
int total;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
total = 0;
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [self count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = c - 1; i >= 0; i--) {
|
2010-09-29 20:09:11 +00:00
|
|
|
ent = [self objectAtIndex: i];
|
|
|
|
c2 = [ent count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (j = c2 - 1; j >= 0; j--) {
|
2010-09-29 20:09:11 +00:00
|
|
|
brush = [ent objectAtIndex: j];
|
2010-09-11 10:03:41 +00:00
|
|
|
if (![brush selected])
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
|
|
|
if ([brush regioned])
|
|
|
|
continue;
|
|
|
|
total++;
|
2010-09-29 20:09:11 +00:00
|
|
|
[brush performSelector: sel];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
// if (!total)
|
2010-09-12 02:13:35 +00:00
|
|
|
// Sys_Printf ("nothing selected\n");
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
return self;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) makeUnselectedPerform: (SEL)sel
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent, brush;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [self count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = c - 1; i >= 0; i--) {
|
2010-09-29 20:09:11 +00:00
|
|
|
ent = [self objectAtIndex: i];
|
|
|
|
c2 = [ent count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (j = c2 - 1; j >= 0; j--) {
|
2010-09-29 20:09:11 +00:00
|
|
|
brush = [ent objectAtIndex: j];
|
2010-09-11 10:03:41 +00:00
|
|
|
if ([brush selected])
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
|
|
|
if ([brush regioned])
|
|
|
|
continue;
|
2010-09-29 20:09:11 +00:00
|
|
|
[brush performSelector: sel];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
return self;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) makeAllPerform: (SEL)sel
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent, brush;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [self count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = c - 1; i >= 0; i--) {
|
2010-09-29 20:09:11 +00:00
|
|
|
ent = [self objectAtIndex: i];
|
|
|
|
c2 = [ent count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (j = c2 - 1; j >= 0; j--) {
|
2010-09-29 20:09:11 +00:00
|
|
|
brush = [ent objectAtIndex: j];
|
2003-03-18 19:48:24 +00:00
|
|
|
if ([brush regioned])
|
|
|
|
continue;
|
2010-09-29 20:09:11 +00:00
|
|
|
[brush performSelector: sel];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
return self;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) makeGlobalPerform: (SEL)sel // in and out of region
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id ent, brush;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [self count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = c - 1; i >= 0; i--) {
|
2010-09-29 20:09:11 +00:00
|
|
|
ent = [self objectAtIndex: i];
|
|
|
|
c2 = [ent count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (j = c2 - 1; j >= 0; j--) {
|
2010-09-29 20:09:11 +00:00
|
|
|
brush = [ent objectAtIndex: j];
|
|
|
|
[brush performSelector: sel];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
return self;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
void
|
|
|
|
sel_identity (void)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
sel_x[0] = 1;
|
|
|
|
sel_x[1] = 0;
|
|
|
|
sel_x[2] = 0;
|
|
|
|
sel_y[0] = 0;
|
|
|
|
sel_y[1] = 1;
|
|
|
|
sel_y[2] = 0;
|
|
|
|
sel_z[0] = 0;
|
|
|
|
sel_z[1] = 0;
|
|
|
|
sel_z[2] = 1;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) transformSelection
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
if (![currentEntity modifiable]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("can't modify spawned entities\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
// find an origin to apply the transformation to
|
|
|
|
sb_mins[0] = sb_mins[1] = sb_mins[2] = 99999;
|
|
|
|
sb_maxs[0] = sb_maxs[1] = sb_maxs[2] = -99999;
|
2010-09-29 20:09:11 +00:00
|
|
|
[self makeSelectedPerform: @selector (addToBBox)];
|
|
|
|
sel_org[0] = [xyview_i snapToGrid: (sb_mins[0] + sb_maxs[0]) / 2];
|
|
|
|
sel_org[1] = [xyview_i snapToGrid: (sb_mins[1] + sb_maxs[1]) / 2];
|
|
|
|
sel_org[2] = [xyview_i snapToGrid: (sb_mins[2] + sb_maxs[2]) / 2];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
// do it!
|
2010-09-29 20:09:11 +00:00
|
|
|
[self makeSelectedPerform: @selector (transform)];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
[quakeed_i updateAll];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
void
|
|
|
|
swapvectors (vec3_t a, vec3_t b)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
vec3_t temp;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
VectorCopy (a, temp);
|
|
|
|
VectorCopy (b, a);
|
|
|
|
VectorSubtract (vec3_origin, temp, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============================================================================
|
|
|
|
|
|
|
|
UI operations
|
|
|
|
|
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) rotate_x: sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
sel_identity ();
|
2010-09-11 10:03:41 +00:00
|
|
|
swapvectors (sel_y, sel_z);
|
2003-03-18 19:48:24 +00:00
|
|
|
[self transformSelection];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) rotate_y: sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
sel_identity ();
|
2010-09-11 10:03:41 +00:00
|
|
|
swapvectors (sel_x, sel_z);
|
2003-03-18 19:48:24 +00:00
|
|
|
[self transformSelection];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) rotate_z: sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
sel_identity ();
|
2010-09-11 10:03:41 +00:00
|
|
|
swapvectors (sel_x, sel_y);
|
2003-03-18 19:48:24 +00:00
|
|
|
[self transformSelection];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) flip_x: sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
sel_identity ();
|
|
|
|
sel_x[0] = -1;
|
|
|
|
[self transformSelection];
|
2010-09-29 20:09:11 +00:00
|
|
|
[map_i makeSelectedPerform: @selector (flipNormals)];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) flip_y: sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
sel_identity ();
|
|
|
|
sel_y[1] = -1;
|
|
|
|
[self transformSelection];
|
2010-09-29 20:09:11 +00:00
|
|
|
[map_i makeSelectedPerform: @selector (flipNormals)];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) flip_z: sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
sel_identity ();
|
|
|
|
sel_z[2] = -1;
|
|
|
|
[self transformSelection];
|
2010-09-29 20:09:11 +00:00
|
|
|
[map_i makeSelectedPerform: @selector (flipNormals)];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) cloneSelection: sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, j, c, originalElements;
|
|
|
|
id o, b;
|
|
|
|
id new;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
sb_translate[0] = sb_translate[1] = [xyview_i gridsize];
|
2003-03-18 19:48:24 +00:00
|
|
|
sb_translate[2] = 0;
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
// copy individual brushes in the world entity
|
|
|
|
o = [self objectAtIndex: 0];
|
|
|
|
c = [o count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < c; i++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
b = [o objectAtIndex: i];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (![b selected])
|
|
|
|
continue;
|
2010-09-11 10:03:41 +00:00
|
|
|
// copy the brush, then translate the original
|
2010-09-29 20:09:11 +00:00
|
|
|
new = [b copy];
|
|
|
|
[new setSelected: YES];
|
2003-03-18 19:48:24 +00:00
|
|
|
[new translate];
|
2010-09-29 20:09:11 +00:00
|
|
|
[b setSelected: NO];
|
|
|
|
[o addObject: new];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
// copy entire entities otherwise
|
|
|
|
originalElements = [self count]; // don't copy the new ones
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 1; i < originalElements; i++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
o = [self objectAtIndex: i];
|
|
|
|
if (![[o objectAtIndex: 0] selected])
|
2003-03-18 19:48:24 +00:00
|
|
|
continue;
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
new = [o copy];
|
|
|
|
[self addObject: new];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [o count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (j = 0; j < c; j++)
|
2010-09-29 20:09:11 +00:00
|
|
|
[[o objectAtIndex: j] setSelected: NO];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [new count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (j = 0; j < c; j++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
b = [new objectAtIndex: j];
|
2003-03-18 19:48:24 +00:00
|
|
|
[b translate];
|
2010-09-29 20:09:11 +00:00
|
|
|
[b setSelected: YES];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[quakeed_i updateAll];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) selectCompleteEntity: sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
id o;
|
|
|
|
int i, c;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
o = [self selectedBrush];
|
2010-09-11 10:03:41 +00:00
|
|
|
if (!o) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("nothing selected\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
2010-09-29 20:09:11 +00:00
|
|
|
o = [o parent];
|
|
|
|
c = [o count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < c; i++)
|
2010-09-29 20:09:11 +00:00
|
|
|
[[o objectAtIndex: i] setSelected: YES];
|
|
|
|
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("%i brushes selected\n", c);
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
[quakeed_i updateAll];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) makeEntity: sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
if (currentEntity != [self objectAtIndex: 0]) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("ERROR: can't makeEntity inside an entity\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
NSBeep ();
|
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if ([self numSelected] == 0) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("ERROR: must have a seed brush to make an entity\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
NSBeep ();
|
|
|
|
return self;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
sb_newowner = [[Entity alloc] initClass: [things_i spawnName]];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
if ([sb_newowner modifiable]) {
|
|
|
|
[self makeSelectedPerform: @selector (moveToEntity)];
|
|
|
|
} else { // throw out seed brush and select entity fixed brush
|
|
|
|
[self makeSelectedPerform: @selector (remove)];
|
|
|
|
[[sb_newowner objectAtIndex: 0] setSelected: YES];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
[self addObject: sb_newowner];
|
|
|
|
[self setCurrentEntity: sb_newowner];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) selbox: (SEL)selector
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
id b;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if ([self numSelected] != 1) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("must have a single brush selected\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
2010-09-11 10:03:41 +00:00
|
|
|
}
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
b = [self selectedBrush];
|
|
|
|
[b getMins: select_min maxs: select_max];
|
2003-03-18 19:48:24 +00:00
|
|
|
[b remove];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
[self makeUnselectedPerform: selector];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("identified contents\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) selectCompletelyInside: sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
return [self selbox: @selector (selectComplete)];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) selectPartiallyInside: sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
return [self selbox: @selector (selectPartial)];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) tallBrush: sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
id b;
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
texturedef_t td;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if ([self numSelected] != 1) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("must have a single brush selected\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
2010-09-11 10:03:41 +00:00
|
|
|
}
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
b = [self selectedBrush];
|
2003-03-18 19:48:24 +00:00
|
|
|
td = *[b texturedef];
|
2010-09-29 20:09:11 +00:00
|
|
|
[b getMins: mins maxs: maxs];
|
2003-03-18 19:48:24 +00:00
|
|
|
[b remove];
|
|
|
|
|
|
|
|
mins[2] = -2048;
|
|
|
|
maxs[2] = 2048;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
b = [[SetBrush alloc] initOwner: [map_i objectAtIndex: 0]
|
|
|
|
mins: mins
|
|
|
|
maxs: maxs
|
|
|
|
texture: &td];
|
|
|
|
[[map_i objectAtIndex: 0] addObject: b];
|
|
|
|
[b setSelected: YES];
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) shortBrush: sender
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
id b;
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
texturedef_t td;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if ([self numSelected] != 1) {
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("must have a single brush selected\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
2010-09-11 10:03:41 +00:00
|
|
|
}
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
b = [self selectedBrush];
|
2003-03-18 19:48:24 +00:00
|
|
|
td = *[b texturedef];
|
2010-09-29 20:09:11 +00:00
|
|
|
[b getMins: mins maxs: maxs];
|
2003-03-18 19:48:24 +00:00
|
|
|
[b remove];
|
|
|
|
|
|
|
|
mins[2] = 0;
|
|
|
|
maxs[2] = 16;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
b = [[SetBrush alloc] initOwner: [map_i objectAtIndex: 0]
|
|
|
|
mins: mins
|
|
|
|
maxs: maxs
|
|
|
|
texture: &td];
|
|
|
|
[[map_i objectAtIndex: 0] addObject: b];
|
|
|
|
[b setSelected: YES];
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
subtractSelection
|
|
|
|
==================
|
|
|
|
*/
|
2010-09-29 20:09:11 +00:00
|
|
|
- (id) subtractSelection: semder
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-29 20:09:11 +00:00
|
|
|
int i, j, c, c2;
|
|
|
|
id o, o2;
|
|
|
|
id sellist, sourcelist;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("performing brush subtraction...\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
sourcelist = [[NSMutableArray alloc] init];
|
|
|
|
sellist = [[NSMutableArray alloc] init];
|
|
|
|
carve_in = [[NSMutableArray alloc] init];
|
|
|
|
carve_out = [[NSMutableArray alloc] init];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [currentEntity count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < c; i++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
o = [currentEntity objectAtIndex: i];
|
2003-03-18 19:48:24 +00:00
|
|
|
if ([o selected])
|
2010-09-29 20:09:11 +00:00
|
|
|
[sellist addObject: o];
|
2003-03-18 19:48:24 +00:00
|
|
|
else
|
2010-09-29 20:09:11 +00:00
|
|
|
[sourcelist addObject: o];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
c = [sellist count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < c; i++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
o = [sellist objectAtIndex: i];
|
2003-03-18 19:48:24 +00:00
|
|
|
[o setCarveVars];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
c2 = [sourcelist count];
|
2010-09-11 10:03:41 +00:00
|
|
|
for (j = 0; j < c2; j++) {
|
2010-09-29 20:09:11 +00:00
|
|
|
o2 = [sourcelist objectAtIndex: j];
|
2003-03-18 19:48:24 +00:00
|
|
|
[o2 carve];
|
2010-09-09 11:46:38 +00:00
|
|
|
[carve_in removeAllObjects];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
[sourcelist release]; // the individual have been moved/freed
|
2003-03-18 19:48:24 +00:00
|
|
|
sourcelist = carve_out;
|
2010-09-29 20:09:11 +00:00
|
|
|
carve_out = [[NSMutableArray alloc] init];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 20:09:11 +00:00
|
|
|
// add the selection back to the remnants
|
2003-03-18 19:48:24 +00:00
|
|
|
[currentEntity removeAllObjects];
|
2010-09-29 20:09:11 +00:00
|
|
|
[currentEntity addObjectsFromArray: sourcelist];
|
|
|
|
[currentEntity addObjectsFromArray: sellist];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-09 11:46:38 +00:00
|
|
|
[sourcelist release];
|
|
|
|
[sellist release];
|
|
|
|
[carve_in release];
|
|
|
|
[carve_out release];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
if (![currentEntity count]) {
|
2003-03-18 19:48:24 +00:00
|
|
|
o = currentEntity;
|
2010-09-29 20:09:11 +00:00
|
|
|
[self removeObject: o];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-12 02:13:35 +00:00
|
|
|
Sys_Printf ("subtracted selection\n");
|
2003-03-18 19:48:24 +00:00
|
|
|
[quakeed_i updateAll];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|