More style fixes
FossilOrigin-Name: c634a689e76e7c60fb8b685ea40cb9993a86f23474d1ead7159eb331e98f1110
This commit is contained in:
parent
d3dc40de33
commit
a838f496b1
39 changed files with 536 additions and 582 deletions
|
@ -7,12 +7,12 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
@property (readonly, nonatomic) bool persisted;
|
@property (readonly, nonatomic) bool persisted;
|
||||||
|
|
||||||
+ (instancetype)aliasWithName: (OFString *)name
|
+ (instancetype)aliasWithName: (OFString *)name
|
||||||
action: (OFString *)action
|
action: (OFString *)action
|
||||||
persisted: (bool)persisted OF_DIRECT;
|
persisted: (bool)persisted OF_DIRECT;
|
||||||
- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE;
|
- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE;
|
||||||
- (instancetype)initWithName: (OFString *)name
|
- (instancetype)initWithName: (OFString *)name
|
||||||
action: (OFString *)action
|
action: (OFString *)action
|
||||||
persisted: (bool)persisted OF_DESIGNATED_INITIALIZER
|
persisted: (bool)persisted OF_DESIGNATED_INITIALIZER
|
||||||
OF_DIRECT;
|
OF_DIRECT;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
12
src/Alias.m
12
src/Alias.m
|
@ -2,17 +2,17 @@
|
||||||
|
|
||||||
@implementation Alias
|
@implementation Alias
|
||||||
+ (instancetype)aliasWithName: (OFString *)name
|
+ (instancetype)aliasWithName: (OFString *)name
|
||||||
action: (OFString *)action
|
action: (OFString *)action
|
||||||
persisted: (bool)persisted;
|
persisted: (bool)persisted;
|
||||||
{
|
{
|
||||||
return [[self alloc] initWithName: name
|
return [[self alloc] initWithName: name
|
||||||
action: action
|
action: action
|
||||||
persisted: persisted];
|
persisted: persisted];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithName: (OFString *)name
|
- (instancetype)initWithName: (OFString *)name
|
||||||
action: (OFString *)action
|
action: (OFString *)action
|
||||||
persisted: (bool)persisted
|
persisted: (bool)persisted
|
||||||
{
|
{
|
||||||
self = [super initWithName: name];
|
self = [super initWithName: name];
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
OF_ASSUME_NONNULL_BEGIN
|
OF_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
#define COMMAND(name, nargs, block_) \
|
#define COMMAND(name, nargs, block_) \
|
||||||
OF_CONSTRUCTOR() \
|
OF_CONSTRUCTOR() \
|
||||||
{ \
|
{ \
|
||||||
enqueueInit(^ { \
|
enqueueInit(^ { \
|
||||||
Identifier.identifiers[@#name] = \
|
Identifier.identifiers[@#name] = [Command \
|
||||||
[Command commandWithName: @#name \
|
commandWithName: @#name \
|
||||||
argumentsTypes: nargs \
|
argumentsTypes: nargs \
|
||||||
block: block_]; \
|
block: block_]; \
|
||||||
}); \
|
}); \
|
||||||
}
|
}
|
||||||
|
|
||||||
OF_DIRECT_MEMBERS
|
OF_DIRECT_MEMBERS
|
||||||
|
@ -18,12 +18,12 @@ OF_DIRECT_MEMBERS
|
||||||
@property (readonly, nonatomic) int argumentsTypes;
|
@property (readonly, nonatomic) int argumentsTypes;
|
||||||
|
|
||||||
+ (instancetype)commandWithName: (OFString *)name
|
+ (instancetype)commandWithName: (OFString *)name
|
||||||
argumentsTypes: (int)argumentsTypes
|
argumentsTypes: (int)argumentsTypes
|
||||||
block: (id)block;
|
block: (id)block;
|
||||||
- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE;
|
- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE;
|
||||||
- (instancetype)initWithName: (OFString *)name
|
- (instancetype)initWithName: (OFString *)name
|
||||||
argumentsTypes: (int)argumentsTypes
|
argumentsTypes: (int)argumentsTypes
|
||||||
block: (id)block OF_DESIGNATED_INITIALIZER;
|
block: (id)block OF_DESIGNATED_INITIALIZER;
|
||||||
- (int)callWithArguments: (OFArray<OFString *> *)arguments isDown: (bool)isDown;
|
- (int)callWithArguments: (OFArray<OFString *> *)arguments isDown: (bool)isDown;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -25,17 +25,17 @@ padArguments(OFArray<OFString *> *arguments, size_t count)
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (instancetype)commandWithName: (OFString *)name
|
+ (instancetype)commandWithName: (OFString *)name
|
||||||
argumentsTypes: (int)argumentsTypes
|
argumentsTypes: (int)argumentsTypes
|
||||||
block: (id)block
|
block: (id)block
|
||||||
{
|
{
|
||||||
return [[self alloc] initWithName: name
|
return [[self alloc] initWithName: name
|
||||||
argumentsTypes: argumentsTypes
|
argumentsTypes: argumentsTypes
|
||||||
block: block];
|
block: block];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithName: (OFString *)name
|
- (instancetype)initWithName: (OFString *)name
|
||||||
argumentsTypes: (int)argumentsTypes
|
argumentsTypes: (int)argumentsTypes
|
||||||
block: (id)block
|
block: (id)block
|
||||||
{
|
{
|
||||||
self = [super initWithName: name];
|
self = [super initWithName: name];
|
||||||
|
|
||||||
|
|
24
src/Cube.m
24
src/Cube.m
|
@ -127,11 +127,9 @@ VARP(minmillis, 0, 5, 1000);
|
||||||
log(@"video: mode");
|
log(@"video: mode");
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
if ((_window = SDL_CreateWindow("cube engine",
|
if ((_window = SDL_CreateWindow("cube engine",
|
||||||
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||||
_width, _height,
|
_width, _height, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL |
|
||||||
SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL |
|
(!windowed ? SDL_WINDOW_FULLSCREEN : 0))) == NULL ||
|
||||||
(!windowed ? SDL_WINDOW_FULLSCREEN : 0))) ==
|
|
||||||
NULL ||
|
|
||||||
SDL_GL_CreateContext(_window) == NULL)
|
SDL_GL_CreateContext(_window) == NULL)
|
||||||
fatal(@"Unable to create OpenGL screen");
|
fatal(@"Unable to create OpenGL screen");
|
||||||
|
|
||||||
|
@ -244,8 +242,8 @@ VARP(minmillis, 0, 5, 1000);
|
||||||
if (_repeatsKeys ||
|
if (_repeatsKeys ||
|
||||||
event.key.repeat == 0)
|
event.key.repeat == 0)
|
||||||
keypress(event.key.keysym.sym,
|
keypress(event.key.keysym.sym,
|
||||||
event.key.state ==
|
(event.key.state ==
|
||||||
SDL_PRESSED);
|
SDL_PRESSED));
|
||||||
break;
|
break;
|
||||||
case SDL_TEXTINPUT:
|
case SDL_TEXTINPUT:
|
||||||
input(@(event.text.text));
|
input(@(event.text.text));
|
||||||
|
@ -305,19 +303,17 @@ VARP(minmillis, 0, 5, 1000);
|
||||||
SDL_Surface *temp;
|
SDL_Surface *temp;
|
||||||
|
|
||||||
if ((image = SDL_CreateRGBSurface(SDL_SWSURFACE, _width, _height, 24,
|
if ((image = SDL_CreateRGBSurface(SDL_SWSURFACE, _width, _height, 24,
|
||||||
0x0000FF, 0x00FF00, 0xFF0000, 0)) != NULL) {
|
0x0000FF, 0x00FF00, 0xFF0000, 0)) != NULL) {
|
||||||
if ((temp = SDL_CreateRGBSurface(SDL_SWSURFACE, _width, _height,
|
if ((temp = SDL_CreateRGBSurface(SDL_SWSURFACE, _width, _height,
|
||||||
24, 0x0000FF, 0x00FF00, 0xFF0000, 0)) != NULL) {
|
24, 0x0000FF, 0x00FF00, 0xFF0000, 0)) != NULL) {
|
||||||
glReadPixels(0, 0, _width, _height, GL_RGB,
|
glReadPixels(0, 0, _width, _height, GL_RGB,
|
||||||
GL_UNSIGNED_BYTE, image->pixels);
|
GL_UNSIGNED_BYTE, image->pixels);
|
||||||
|
|
||||||
for (int idx = 0; idx < _height; idx++) {
|
for (int idx = 0; idx < _height; idx++) {
|
||||||
char *dest =
|
char *dest =
|
||||||
(char *)temp->pixels + 3 * _width * idx;
|
(char *)temp->pixels + 3 * _width * idx;
|
||||||
memcpy(dest,
|
memcpy(dest, (char *)image->pixels + 3 *
|
||||||
(char *)image->pixels +
|
_width * (_height - 1 - idx), 3 * _width);
|
||||||
3 * _width * (_height - 1 - idx),
|
|
||||||
3 * _width);
|
|
||||||
endianswap(dest, 3, _width);
|
endianswap(dest, 3, _width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +343,7 @@ fatal(OFConstantString *s, ...)
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, s);
|
va_start(args, s);
|
||||||
OFMutableString *msg = [[OFMutableString alloc] initWithFormat: s
|
OFMutableString *msg = [[OFMutableString alloc] initWithFormat: s
|
||||||
arguments: args];
|
arguments: args];
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
[msg appendFormat: @" (%s)\n", SDL_GetError()];
|
[msg appendFormat: @" (%s)\n", SDL_GetError()];
|
||||||
|
|
18
src/MD2.h
18
src/MD2.h
|
@ -14,15 +14,15 @@ OF_DIRECT_MEMBERS
|
||||||
+ (instancetype)md2;
|
+ (instancetype)md2;
|
||||||
- (bool)loadWithIRI: (OFIRI *)IRI;
|
- (bool)loadWithIRI: (OFIRI *)IRI;
|
||||||
- (void)renderWithLight: (OFColor *)light
|
- (void)renderWithLight: (OFColor *)light
|
||||||
frame: (int)frame
|
frame: (int)frame
|
||||||
range: (int)range
|
range: (int)range
|
||||||
position: (OFVector3D)position
|
position: (OFVector3D)position
|
||||||
yaw: (float)yaw
|
yaw: (float)yaw
|
||||||
pitch: (float)pitch
|
pitch: (float)pitch
|
||||||
scale: (float)scale
|
scale: (float)scale
|
||||||
speed: (float)speed
|
speed: (float)speed
|
||||||
snap: (int)snap
|
snap: (int)snap
|
||||||
basetime: (int)basetime;
|
basetime: (int)basetime;
|
||||||
- (void)scaleWithFrame: (int)frame scale: (float)scale snap: (int)snap;
|
- (void)scaleWithFrame: (int)frame scale: (float)scale snap: (int)snap;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
24
src/MD2.m
24
src/MD2.m
|
@ -69,7 +69,7 @@ snap(int sn, float f)
|
||||||
@try {
|
@try {
|
||||||
stream = (OFSeekableStream *)[[OFIRIHandler handlerForIRI: IRI]
|
stream = (OFSeekableStream *)[[OFIRIHandler handlerForIRI: IRI]
|
||||||
openItemAtIRI: IRI
|
openItemAtIRI: IRI
|
||||||
mode: @"r"];
|
mode: @"r"];
|
||||||
} @catch (id e) {
|
} @catch (id e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ snap(int sn, float f)
|
||||||
|
|
||||||
[stream seekToOffset: header.offsetFrames whence: OFSeekSet];
|
[stream seekToOffset: header.offsetFrames whence: OFSeekSet];
|
||||||
[stream readIntoBuffer: _frames
|
[stream readIntoBuffer: _frames
|
||||||
exactLength: header.frameSize * header.numFrames];
|
exactLength: header.frameSize * header.numFrames];
|
||||||
|
|
||||||
for (int i = 0; i < header.numFrames; ++i)
|
for (int i = 0; i < header.numFrames; ++i)
|
||||||
endianswap(_frames + i * header.frameSize, sizeof(float), 6);
|
endianswap(_frames + i * header.frameSize, sizeof(float), 6);
|
||||||
|
@ -105,7 +105,7 @@ snap(int sn, float f)
|
||||||
|
|
||||||
[stream seekToOffset: header.offsetGlCommands whence: OFSeekSet];
|
[stream seekToOffset: header.offsetGlCommands whence: OFSeekSet];
|
||||||
[stream readIntoBuffer: _glCommands
|
[stream readIntoBuffer: _glCommands
|
||||||
exactLength: header.numGlCommands * sizeof(int)];
|
exactLength: header.numGlCommands * sizeof(int)];
|
||||||
endianswap(_glCommands, sizeof(int), header.numGlCommands);
|
endianswap(_glCommands, sizeof(int), header.numGlCommands);
|
||||||
|
|
||||||
_numFrames = header.numFrames;
|
_numFrames = header.numFrames;
|
||||||
|
@ -140,15 +140,15 @@ snap(int sn, float f)
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)renderWithLight: (OFColor *)light
|
- (void)renderWithLight: (OFColor *)light
|
||||||
frame: (int)frame
|
frame: (int)frame
|
||||||
range: (int)range
|
range: (int)range
|
||||||
position: (OFVector3D)position
|
position: (OFVector3D)position
|
||||||
yaw: (float)yaw
|
yaw: (float)yaw
|
||||||
pitch: (float)pitch
|
pitch: (float)pitch
|
||||||
scale: (float)sc
|
scale: (float)sc
|
||||||
speed: (float)speed
|
speed: (float)speed
|
||||||
snap: (int)sn
|
snap: (int)sn
|
||||||
basetime: (int)basetime
|
basetime: (int)basetime
|
||||||
{
|
{
|
||||||
for (int i = 0; i < range; i++)
|
for (int i = 0; i < range; i++)
|
||||||
if (!_mverts[frame + i])
|
if (!_mverts[frame + i])
|
||||||
|
|
|
@ -8,16 +8,16 @@ OF_DIRECT_MEMBERS
|
||||||
@property (copy, nonatomic) OFString *name;
|
@property (copy, nonatomic) OFString *name;
|
||||||
|
|
||||||
+ (instancetype)infoWithRad: (int)rad
|
+ (instancetype)infoWithRad: (int)rad
|
||||||
h: (int)h
|
h: (int)h
|
||||||
zoff: (int)zoff
|
zoff: (int)zoff
|
||||||
snap: (int)snap
|
snap: (int)snap
|
||||||
name: (OFString *)name;
|
name: (OFString *)name;
|
||||||
- (instancetype)init OF_UNAVAILABLE;
|
- (instancetype)init OF_UNAVAILABLE;
|
||||||
- (instancetype)initWithRad: (int)rad
|
- (instancetype)initWithRad: (int)rad
|
||||||
h: (int)h
|
h: (int)h
|
||||||
zoff: (int)zoff
|
zoff: (int)zoff
|
||||||
snap: (int)snap
|
snap: (int)snap
|
||||||
name: (OFString *)name;
|
name: (OFString *)name;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
OF_ASSUME_NONNULL_END
|
OF_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
@implementation MapModelInfo
|
@implementation MapModelInfo
|
||||||
+ (instancetype)infoWithRad: (int)rad
|
+ (instancetype)infoWithRad: (int)rad
|
||||||
h: (int)h
|
h: (int)h
|
||||||
zoff: (int)zoff
|
zoff: (int)zoff
|
||||||
snap: (int)snap
|
snap: (int)snap
|
||||||
name: (OFString *)name
|
name: (OFString *)name
|
||||||
{
|
{
|
||||||
return [[self alloc] initWithRad: rad
|
return [[self alloc] initWithRad: rad
|
||||||
h: h
|
h: h
|
||||||
|
@ -15,10 +15,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithRad: (int)rad
|
- (instancetype)initWithRad: (int)rad
|
||||||
h: (int)h
|
h: (int)h
|
||||||
zoff: (int)zoff
|
zoff: (int)zoff
|
||||||
snap: (int)snap
|
snap: (int)snap
|
||||||
name: (OFString *)name
|
name: (OFString *)name
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
|
|
|
@ -27,14 +27,14 @@ OF_DIRECT_MEMBERS
|
||||||
// TODO: Move this somewhere else
|
// TODO: Move this somewhere else
|
||||||
+ (void)endSinglePlayerWithAllKilled: (bool)allKilled;
|
+ (void)endSinglePlayerWithAllKilled: (bool)allKilled;
|
||||||
+ (instancetype)monsterWithType: (int)type
|
+ (instancetype)monsterWithType: (int)type
|
||||||
yaw: (int)yaw
|
yaw: (int)yaw
|
||||||
state: (int)state
|
state: (int)state
|
||||||
trigger: (int)trigger
|
trigger: (int)trigger
|
||||||
move: (int)move;
|
move: (int)move;
|
||||||
- (instancetype)initWithType: (int)type
|
- (instancetype)initWithType: (int)type
|
||||||
yaw: (int)yaw
|
yaw: (int)yaw
|
||||||
state: (int)state
|
state: (int)state
|
||||||
trigger: (int)trigger
|
trigger: (int)trigger
|
||||||
move: (int)move;
|
move: (int)move;
|
||||||
- (void)incurDamage: (int)damage fromEntity: (__kindof DynamicEntity *)d;
|
- (void)incurDamage: (int)damage fromEntity: (__kindof DynamicEntity *)d;
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -23,16 +23,16 @@ static int nextmonster, spawnremain, numkilled, monstertotal, mtimestart;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (instancetype)monsterWithType: (int)type
|
+ (instancetype)monsterWithType: (int)type
|
||||||
yaw: (int)yaw
|
yaw: (int)yaw
|
||||||
state: (int)state
|
state: (int)state
|
||||||
trigger: (int)trigger
|
trigger: (int)trigger
|
||||||
move: (int)move
|
move: (int)move
|
||||||
{
|
{
|
||||||
return [[self alloc] initWithType: type
|
return [[self alloc] initWithType: type
|
||||||
yaw: yaw
|
yaw: yaw
|
||||||
state: state
|
state: state
|
||||||
trigger: trigger
|
trigger: trigger
|
||||||
move: move];
|
move: move];
|
||||||
}
|
}
|
||||||
|
|
||||||
VARF(skill, 1, 3, 10, conoutf(@"skill is now %d", skill));
|
VARF(skill, 1, 3, 10, conoutf(@"skill is now %d", skill));
|
||||||
|
@ -76,10 +76,10 @@ monstertypes[NUMMONSTERTYPES] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
- (instancetype)initWithType: (int)type
|
- (instancetype)initWithType: (int)type
|
||||||
yaw: (int)yaw
|
yaw: (int)yaw
|
||||||
state: (int)state
|
state: (int)state
|
||||||
trigger: (int)trigger
|
trigger: (int)trigger
|
||||||
move: (int)move
|
move: (int)move
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
|
@ -172,10 +172,10 @@ spawnmonster() // spawn a random monster according to freq distribution in DMSP
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Monster *m = [Monster monsterWithType: e.attr2
|
Monster *m = [Monster monsterWithType: e.attr2
|
||||||
yaw: e.attr1
|
yaw: e.attr1
|
||||||
state: M_SLEEP
|
state: M_SLEEP
|
||||||
trigger: 100
|
trigger: 100
|
||||||
move: 0];
|
move: 0];
|
||||||
m.origin = OFMakeVector3D(e.x, e.y, e.z);
|
m.origin = OFMakeVector3D(e.x, e.y, e.z);
|
||||||
[monsters addObject: m];
|
[monsters addObject: m];
|
||||||
entinmap(m);
|
entinmap(m);
|
||||||
|
@ -289,16 +289,14 @@ enemylos(Monster *m, OFVector3D *v)
|
||||||
// patented "random walk" AI pathfinding (tm) ;)
|
// patented "random walk" AI pathfinding (tm) ;)
|
||||||
self.targetYaw += 180 + rnd(180);
|
self.targetYaw += 180 + rnd(180);
|
||||||
[self transitionWithState: M_SEARCH
|
[self transitionWithState: M_SEARCH
|
||||||
moving: 1
|
moving: 1
|
||||||
n: 400
|
n: 400
|
||||||
r: 1000];
|
r: 1000];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float enemyYaw = -(float)atan2(self.enemy.origin.x - self.origin.x,
|
float enemyYaw = -(float)atan2(self.enemy.origin.x - self.origin.x,
|
||||||
self.enemy.origin.y - self.origin.y) /
|
self.enemy.origin.y - self.origin.y) / PI * 180 + 180;
|
||||||
PI * 180 +
|
|
||||||
180;
|
|
||||||
|
|
||||||
switch (self.monsterState) {
|
switch (self.monsterState) {
|
||||||
case M_PAIN:
|
case M_PAIN:
|
||||||
|
@ -311,17 +309,16 @@ enemylos(Monster *m, OFVector3D *v)
|
||||||
r: 200];
|
r: 200];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case M_SLEEP: // state classic sp monster start in, wait for visual
|
// state classic sp monster start in, wait for visual contact
|
||||||
// contact
|
case M_SLEEP: {
|
||||||
{
|
|
||||||
OFVector3D target;
|
OFVector3D target;
|
||||||
if (editmode || !enemylos(self, &target))
|
if (editmode || !enemylos(self, &target))
|
||||||
return; // skip running physics
|
return; // skip running physics
|
||||||
[self normalizeWithAngle: enemyYaw];
|
[self normalizeWithAngle: enemyYaw];
|
||||||
float angle = (float)fabs(enemyYaw - self.yaw);
|
float angle = (float)fabs(enemyYaw - self.yaw);
|
||||||
if (disttoenemy < 8 // the better the angle to the player, the
|
// the better the angle to the player, the further the monster
|
||||||
// further the monster can see/hear
|
// can see/hear
|
||||||
|| (disttoenemy < 16 && angle < 135) ||
|
if (disttoenemy < 8 || (disttoenemy < 16 && angle < 135) ||
|
||||||
(disttoenemy < 32 && angle < 90) ||
|
(disttoenemy < 32 && angle < 90) ||
|
||||||
(disttoenemy < 64 && angle < 45) || angle < 10) {
|
(disttoenemy < 64 && angle < 45) || angle < 10) {
|
||||||
[self transitionWithState: M_HOME
|
[self transitionWithState: M_HOME
|
||||||
|
@ -342,9 +339,9 @@ enemylos(Monster *m, OFVector3D *v)
|
||||||
self.attacking = true;
|
self.attacking = true;
|
||||||
shoot(self, self.attackTarget);
|
shoot(self, self.attackTarget);
|
||||||
[self transitionWithState: M_ATTACKING
|
[self transitionWithState: M_ATTACKING
|
||||||
moving: 0
|
moving: 0
|
||||||
n: 600
|
n: 600
|
||||||
r: 0];
|
r: 0];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -358,9 +355,9 @@ enemylos(Monster *m, OFVector3D *v)
|
||||||
// no visual contact anymore, let monster get
|
// no visual contact anymore, let monster get
|
||||||
// as close as possible then search for player
|
// as close as possible then search for player
|
||||||
[self transitionWithState: M_HOME
|
[self transitionWithState: M_HOME
|
||||||
moving: 1
|
moving: 1
|
||||||
n: 800
|
n: 800
|
||||||
r: 500];
|
r: 500];
|
||||||
} else {
|
} else {
|
||||||
// the closer the monster is the more likely he
|
// the closer the monster is the more likely he
|
||||||
// wants to shoot
|
// wants to shoot
|
||||||
|
@ -371,17 +368,17 @@ enemylos(Monster *m, OFVector3D *v)
|
||||||
int n =
|
int n =
|
||||||
monstertypes[self.monsterType].lag;
|
monstertypes[self.monsterType].lag;
|
||||||
[self transitionWithState: M_AIMING
|
[self transitionWithState: M_AIMING
|
||||||
moving: 0
|
moving: 0
|
||||||
n: n
|
n: n
|
||||||
r: 10];
|
r: 10];
|
||||||
} else {
|
} else {
|
||||||
// track player some more
|
// track player some more
|
||||||
int n =
|
int n =
|
||||||
monstertypes[self.monsterType].rate;
|
monstertypes[self.monsterType].rate;
|
||||||
[self transitionWithState: M_HOME
|
[self transitionWithState: M_HOME
|
||||||
moving: 1
|
moving: 1
|
||||||
n: n
|
n: n
|
||||||
r: 0];
|
r: 0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,9 +398,8 @@ enemylos(Monster *m, OFVector3D *v)
|
||||||
if (self != m) {
|
if (self != m) {
|
||||||
// don't attack straight away, first get angry
|
// don't attack straight away, first get angry
|
||||||
self.anger++;
|
self.anger++;
|
||||||
int anger =
|
int anger = (self.monsterType == m.monsterType
|
||||||
(self.monsterType == m.monsterType ? self.anger / 2
|
? self.anger / 2 : self.anger);
|
||||||
: self.anger);
|
|
||||||
if (anger >= monstertypes[self.monsterType].loyalty)
|
if (anger >= monstertypes[self.monsterType].loyalty)
|
||||||
// monster infight if very angry
|
// monster infight if very angry
|
||||||
self.enemy = m;
|
self.enemy = m;
|
||||||
|
@ -416,9 +412,9 @@ enemylos(Monster *m, OFVector3D *v)
|
||||||
|
|
||||||
// in this state monster won't attack
|
// in this state monster won't attack
|
||||||
[self transitionWithState: M_PAIN
|
[self transitionWithState: M_PAIN
|
||||||
moving: 0
|
moving: 0
|
||||||
n: monstertypes[self.monsterType].pain
|
n: monstertypes[self.monsterType].pain
|
||||||
r: 200];
|
r: 200];
|
||||||
|
|
||||||
if ((self.health -= damage) <= 0) {
|
if ((self.health -= damage) <= 0) {
|
||||||
self.state = CS_DEAD;
|
self.state = CS_DEAD;
|
||||||
|
@ -438,8 +434,8 @@ enemylos(Monster *m, OFVector3D *v)
|
||||||
|
|
||||||
+ (void)endSinglePlayerWithAllKilled: (bool)allKilled
|
+ (void)endSinglePlayerWithAllKilled: (bool)allKilled
|
||||||
{
|
{
|
||||||
conoutf(allKilled ? @"you have cleared the map!"
|
conoutf(allKilled
|
||||||
: @"you reached the exit!");
|
? @"you have cleared the map!" : @"you reached the exit!");
|
||||||
conoutf(@"score: %d kills in %d seconds", numkilled,
|
conoutf(@"score: %d kills in %d seconds", numkilled,
|
||||||
(lastmillis - mtimestart) / 1000);
|
(lastmillis - mtimestart) / 1000);
|
||||||
monstertotal = 0;
|
monstertotal = 0;
|
||||||
|
|
|
@ -8,13 +8,13 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
OF_CONSTRUCTOR() \
|
OF_CONSTRUCTOR() \
|
||||||
{ \
|
{ \
|
||||||
enqueueInit(^ { \
|
enqueueInit(^ { \
|
||||||
Variable *variable = \
|
Variable *variable = [Variable \
|
||||||
[Variable variableWithName: @#name \
|
variableWithName: @#name \
|
||||||
min: min_ \
|
min: min_ \
|
||||||
max: max_ \
|
max: max_ \
|
||||||
storage: &name \
|
storage: &name \
|
||||||
function: NULL \
|
function: NULL \
|
||||||
persisted: true]; \
|
persisted: true]; \
|
||||||
Identifier.identifiers[@#name] = variable; \
|
Identifier.identifiers[@#name] = variable; \
|
||||||
}); \
|
}); \
|
||||||
}
|
}
|
||||||
|
@ -24,13 +24,13 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
OF_CONSTRUCTOR() \
|
OF_CONSTRUCTOR() \
|
||||||
{ \
|
{ \
|
||||||
enqueueInit(^ { \
|
enqueueInit(^ { \
|
||||||
Variable *variable = \
|
Variable *variable = [Variable \
|
||||||
[Variable variableWithName: @#name \
|
variableWithName: @#name \
|
||||||
min: min_ \
|
min: min_ \
|
||||||
max: max_ \
|
max: max_ \
|
||||||
storage: &name \
|
storage: &name \
|
||||||
function: NULL \
|
function: NULL \
|
||||||
persisted: false]; \
|
persisted: false]; \
|
||||||
Identifier.identifiers[@#name] = variable; \
|
Identifier.identifiers[@#name] = variable; \
|
||||||
}); \
|
}); \
|
||||||
}
|
}
|
||||||
|
@ -41,13 +41,13 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
OF_CONSTRUCTOR() \
|
OF_CONSTRUCTOR() \
|
||||||
{ \
|
{ \
|
||||||
enqueueInit(^ { \
|
enqueueInit(^ { \
|
||||||
Variable *variable = \
|
Variable *variable = [Variable \
|
||||||
[Variable variableWithName: @#name \
|
variableWithName: @#name \
|
||||||
min: min_ \
|
min: min_ \
|
||||||
max: max_ \
|
max: max_ \
|
||||||
storage: &name \
|
storage: &name \
|
||||||
function: var_##name \
|
function: var_##name \
|
||||||
persisted: false]; \
|
persisted: false]; \
|
||||||
Identifier.identifiers[@#name] = variable; \
|
Identifier.identifiers[@#name] = variable; \
|
||||||
}); \
|
}); \
|
||||||
} \
|
} \
|
||||||
|
@ -64,13 +64,13 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
OF_CONSTRUCTOR() \
|
OF_CONSTRUCTOR() \
|
||||||
{ \
|
{ \
|
||||||
enqueueInit(^ { \
|
enqueueInit(^ { \
|
||||||
Variable *variable = \
|
Variable *variable = [Variable \
|
||||||
[Variable variableWithName: @#name \
|
variableWithName: @#name \
|
||||||
min: min_ \
|
min: min_ \
|
||||||
max: max_ \
|
max: max_ \
|
||||||
storage: &name \
|
storage: &name \
|
||||||
function: var_##name \
|
function: var_##name \
|
||||||
persisted: true]; \
|
persisted: true]; \
|
||||||
Identifier.identifiers[@#name] = variable; \
|
Identifier.identifiers[@#name] = variable; \
|
||||||
}); \
|
}); \
|
||||||
} \
|
} \
|
||||||
|
@ -88,18 +88,18 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
@property (readonly, nonatomic) bool persisted;
|
@property (readonly, nonatomic) bool persisted;
|
||||||
|
|
||||||
+ (instancetype)variableWithName: (OFString *)name
|
+ (instancetype)variableWithName: (OFString *)name
|
||||||
min: (int)min
|
min: (int)min
|
||||||
max: (int)max
|
max: (int)max
|
||||||
storage: (int *)storage
|
storage: (int *)storage
|
||||||
function: (void (*_Nullable)())function
|
function: (void (*_Nullable)())function
|
||||||
persisted: (bool)persisted OF_DIRECT;
|
persisted: (bool)persisted OF_DIRECT;
|
||||||
- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE;
|
- (instancetype)initWithName: (OFString *)name OF_UNAVAILABLE;
|
||||||
- (instancetype)initWithName: (OFString *)name
|
- (instancetype)initWithName: (OFString *)name
|
||||||
min: (int)min
|
min: (int)min
|
||||||
max: (int)max
|
max: (int)max
|
||||||
storage: (int *)storage
|
storage: (int *)storage
|
||||||
function: (void (*_Nullable)())function
|
function: (void (*_Nullable)())function
|
||||||
persisted: (bool)persisted OF_DESIGNATED_INITIALIZER
|
persisted: (bool)persisted OF_DESIGNATED_INITIALIZER
|
||||||
OF_DIRECT;
|
OF_DIRECT;
|
||||||
- (void)printValue OF_DIRECT;
|
- (void)printValue OF_DIRECT;
|
||||||
- (void)setValue: (int)value OF_DIRECT;
|
- (void)setValue: (int)value OF_DIRECT;
|
||||||
|
|
|
@ -4,26 +4,26 @@
|
||||||
|
|
||||||
@implementation Variable
|
@implementation Variable
|
||||||
+ (instancetype)variableWithName: (OFString *)name
|
+ (instancetype)variableWithName: (OFString *)name
|
||||||
min: (int)min
|
min: (int)min
|
||||||
max: (int)max
|
max: (int)max
|
||||||
storage: (int *)storage
|
storage: (int *)storage
|
||||||
function: (void (*__cdecl)())function
|
function: (void (*__cdecl)())function
|
||||||
persisted: (bool)persisted
|
persisted: (bool)persisted
|
||||||
{
|
{
|
||||||
return [[self alloc] initWithName: name
|
return [[self alloc] initWithName: name
|
||||||
min: min
|
min: min
|
||||||
max: max
|
max: max
|
||||||
storage: storage
|
storage: storage
|
||||||
function: function
|
function: function
|
||||||
persisted: persisted];
|
persisted: persisted];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithName: (OFString *)name
|
- (instancetype)initWithName: (OFString *)name
|
||||||
min: (int)min
|
min: (int)min
|
||||||
max: (int)max
|
max: (int)max
|
||||||
storage: (int *)storage
|
storage: (int *)storage
|
||||||
function: (void (*__cdecl)())function
|
function: (void (*__cdecl)())function
|
||||||
persisted: (bool)persisted
|
persisted: (bool)persisted
|
||||||
{
|
{
|
||||||
self = [super initWithName: name];
|
self = [super initWithName: name];
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,15 @@
|
||||||
// very messy ad-hoc handling of animation frames, should be made more
|
// very messy ad-hoc handling of animation frames, should be made more
|
||||||
// configurable
|
// configurable
|
||||||
|
|
||||||
// D D D D' D D D D' A A' P P' I I'
|
// D D D D' D D D D' A A' P P' I I'
|
||||||
// R, R' E L J J'
|
// R, R' E L J J'
|
||||||
int frame[] = { 178, 184, 190, 137, 183, 189, 197, 164, 46, 51, 54, 32, 0, 0,
|
int frame[] = {
|
||||||
40, 1, 162, 162, 67, 168 };
|
178, 184, 190, 137, 183, 189, 197, 164, 46, 51, 54, 32, 0, 0, 40, 1,
|
||||||
int range[] = { 6, 6, 8, 28, 1, 1, 1, 1, 8, 19, 4, 18, 40, 1, 6, 15, 1, 1, 1,
|
162, 162, 67, 168
|
||||||
1 };
|
};
|
||||||
|
int range[] = {
|
||||||
|
6, 6, 8, 28, 1, 1, 1, 1, 8, 19, 4, 18, 40, 1, 6, 15, 1, 1, 1, 1
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
renderclient(
|
renderclient(
|
||||||
|
|
|
@ -313,13 +313,9 @@ selfdamage(int damage, int actor, DynamicEntity *act)
|
||||||
player1.armour -= ad;
|
player1.armour -= ad;
|
||||||
damage -= ad;
|
damage -= ad;
|
||||||
float droll = damage / 0.5f;
|
float droll = damage / 0.5f;
|
||||||
player1.roll += player1.roll > 0
|
// give player a kick depending on amount of damage
|
||||||
? droll
|
player1.roll += player1.roll > 0 ? droll : (player1.roll < 0 ? -droll :
|
||||||
: (player1.roll < 0
|
(rnd(2) ? droll : -droll));
|
||||||
? -droll
|
|
||||||
: (rnd(2) ? droll
|
|
||||||
: -droll)); // give player a kick depending
|
|
||||||
// on amount of damage
|
|
||||||
if ((player1.health -= damage) <= 0) {
|
if ((player1.health -= damage) <= 0) {
|
||||||
if (actor == -2) {
|
if (actor == -2) {
|
||||||
conoutf(@"you got killed by %@!", act.name);
|
conoutf(@"you got killed by %@!", act.name);
|
||||||
|
@ -332,8 +328,7 @@ selfdamage(int damage, int actor, DynamicEntity *act)
|
||||||
if (a != nil) {
|
if (a != nil) {
|
||||||
if (isteam(a.team, player1.team))
|
if (isteam(a.team, player1.team))
|
||||||
conoutf(@"you got fragged by a "
|
conoutf(@"you got fragged by a "
|
||||||
@"teammate (%@)",
|
@"teammate (%@)", a.name);
|
||||||
a.name);
|
|
||||||
else
|
else
|
||||||
conoutf(
|
conoutf(
|
||||||
@"you got fragged by %@", a.name);
|
@"you got fragged by %@", a.name);
|
||||||
|
|
|
@ -43,8 +43,8 @@ allowedittoggle()
|
||||||
}
|
}
|
||||||
|
|
||||||
VARF(rate, 0, 0, 25000,
|
VARF(rate, 0, 0, 25000,
|
||||||
if (clienthost && (!rate || rate > 1000))
|
if (clienthost && (!rate || rate > 1000))
|
||||||
enet_host_bandwidth_limit(clienthost, rate, rate));
|
enet_host_bandwidth_limit(clienthost, rate, rate));
|
||||||
|
|
||||||
void throttle();
|
void throttle();
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ addmsg(int rel, int num, int type, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
OFMutableData *msg = [OFMutableData dataWithItemSize: sizeof(int)
|
OFMutableData *msg = [OFMutableData dataWithItemSize: sizeof(int)
|
||||||
capacity: num + 2];
|
capacity: num + 2];
|
||||||
[msg addItem: &num];
|
[msg addItem: &num];
|
||||||
[msg addItem: &rel];
|
[msg addItem: &rel];
|
||||||
[msg addItem: &type];
|
[msg addItem: &type];
|
||||||
|
|
|
@ -45,17 +45,15 @@ updatepos(DynamicEntity *d)
|
||||||
const float dz = player1.origin.z - d.origin.z;
|
const float dz = player1.origin.z - d.origin.z;
|
||||||
const float rz = player1.aboveEye + d.eyeHeight;
|
const float rz = player1.aboveEye + d.eyeHeight;
|
||||||
const float fx = (float)fabs(dx), fy = (float)fabs(dy),
|
const float fx = (float)fabs(dx), fy = (float)fabs(dy),
|
||||||
fz = (float)fabs(dz);
|
fz = (float)fabs(dz);
|
||||||
if (fx < r && fy < r && fz < rz && d.state != CS_DEAD) {
|
if (fx < r && fy < r && fz < rz && d.state != CS_DEAD) {
|
||||||
if (fx < fy)
|
if (fx < fy)
|
||||||
// push aside
|
// push aside
|
||||||
d.origin = OFAddVectors3D(d.origin,
|
d.origin = OFAddVectors3D(d.origin, OFMakeVector3D(
|
||||||
OFMakeVector3D(
|
0, (dy < 0 ? r - fy : -(r - fy)), 0));
|
||||||
0, (dy < 0 ? r - fy : -(r - fy)), 0));
|
|
||||||
else
|
else
|
||||||
d.origin = OFAddVectors3D(d.origin,
|
d.origin = OFAddVectors3D(d.origin, OFMakeVector3D(
|
||||||
OFMakeVector3D(
|
(dx < 0 ? r - fx : -(r - fx)), 0, 0));
|
||||||
(dx < 0 ? r - fx : -(r - fx)), 0, 0));
|
|
||||||
}
|
}
|
||||||
int lagtime = lastmillis - d.lastUpdate;
|
int lagtime = lastmillis - d.lastUpdate;
|
||||||
if (lagtime) {
|
if (lagtime) {
|
||||||
|
@ -87,7 +85,7 @@ localservertoclient(unsigned char *buf, int len)
|
||||||
int prot = getint(&p);
|
int prot = getint(&p);
|
||||||
if (prot != PROTOCOL_VERSION) {
|
if (prot != PROTOCOL_VERSION) {
|
||||||
conoutf(@"you are using a different game "
|
conoutf(@"you are using a different game "
|
||||||
@"protocol (you: %d, server: %d)",
|
@"protocol (you: %d, server: %d)",
|
||||||
PROTOCOL_VERSION, prot);
|
PROTOCOL_VERSION, prot);
|
||||||
disconnect(false, false);
|
disconnect(false, false);
|
||||||
return;
|
return;
|
||||||
|
@ -102,7 +100,7 @@ localservertoclient(unsigned char *buf, int len)
|
||||||
if (text[0] &&
|
if (text[0] &&
|
||||||
strcmp(text, clientpassword.UTF8String)) {
|
strcmp(text, clientpassword.UTF8String)) {
|
||||||
conoutf(@"you need to set the correct password "
|
conoutf(@"you need to set the correct password "
|
||||||
@"to join this server!");
|
@"to join this server!");
|
||||||
disconnect(false, false);
|
disconnect(false, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -265,8 +263,8 @@ localservertoclient(unsigned char *buf, int len)
|
||||||
if (a != nil) {
|
if (a != nil) {
|
||||||
if (isteam(a.team, d.name))
|
if (isteam(a.team, d.name))
|
||||||
conoutf(@"%@ fragged his "
|
conoutf(@"%@ fragged his "
|
||||||
@"teammate (%@)",
|
@"teammate (%@)", a.name,
|
||||||
a.name, d.name);
|
d.name);
|
||||||
else
|
else
|
||||||
conoutf(@"%@ fragged %@",
|
conoutf(@"%@ fragged %@",
|
||||||
a.name, d.name);
|
a.name, d.name);
|
||||||
|
@ -303,8 +301,9 @@ localservertoclient(unsigned char *buf, int len)
|
||||||
realpickup(getint(&p), Player.player1);
|
realpickup(getint(&p), Player.player1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SV_EDITH: // coop editing messages, should be extended to
|
// coop editing messages, should be extended to include all
|
||||||
// include all possible editing ops
|
// possible editing ops
|
||||||
|
case SV_EDITH:
|
||||||
case SV_EDITT:
|
case SV_EDITT:
|
||||||
case SV_EDITS:
|
case SV_EDITS:
|
||||||
case SV_EDITD:
|
case SV_EDITD:
|
||||||
|
@ -367,8 +366,7 @@ localservertoclient(unsigned char *buf, int len)
|
||||||
case SV_PONG:
|
case SV_PONG:
|
||||||
addmsg(0, 2, SV_CLIENTPING,
|
addmsg(0, 2, SV_CLIENTPING,
|
||||||
Player.player1.ping = (Player.player1.ping * 5 +
|
Player.player1.ping = (Player.player1.ping * 5 +
|
||||||
lastmillis - getint(&p)) /
|
lastmillis - getint(&p)) / 6);
|
||||||
6);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SV_CLIENTPING:
|
case SV_CLIENTPING:
|
||||||
|
@ -401,9 +399,9 @@ localservertoclient(unsigned char *buf, int len)
|
||||||
conoutf(@"%s", text);
|
conoutf(@"%s", text);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SV_EXT: // so we can messages without breaking previous
|
// so we can messages without breaking previous
|
||||||
// clients/servers, if necessary
|
// clients/servers, if necessary
|
||||||
{
|
case SV_EXT: {
|
||||||
for (int n = getint(&p); n; n--)
|
for (int n = getint(&p); n; n--)
|
||||||
getint(&p);
|
getint(&p);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -22,8 +22,8 @@ alias(OFString *name, OFString *action)
|
||||||
|
|
||||||
if (alias == nil)
|
if (alias == nil)
|
||||||
Identifier.identifiers[name] = [Alias aliasWithName: name
|
Identifier.identifiers[name] = [Alias aliasWithName: name
|
||||||
action: action
|
action: action
|
||||||
persisted: true];
|
persisted: true];
|
||||||
else {
|
else {
|
||||||
if ([alias isKindOfClass: Alias.class])
|
if ([alias isKindOfClass: Alias.class])
|
||||||
alias.action = action;
|
alias.action = action;
|
||||||
|
|
|
@ -62,7 +62,7 @@ conoutf(OFConstantString *format, ...)
|
||||||
va_start(arguments, format);
|
va_start(arguments, format);
|
||||||
|
|
||||||
OFString *string = [[OFString alloc] initWithFormat: format
|
OFString *string = [[OFString alloc] initWithFormat: format
|
||||||
arguments: arguments];
|
arguments: arguments];
|
||||||
|
|
||||||
va_end(arguments);
|
va_end(arguments);
|
||||||
|
|
||||||
|
@ -83,8 +83,8 @@ renderconsole()
|
||||||
|
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (ConsoleLine *conline in conlines) {
|
for (ConsoleLine *conline in conlines) {
|
||||||
if (conskip ? i >= conskip - 1 || i >= conlines.count - ndraw
|
if (conskip ? i >= conskip - 1 || i >= conlines.count - ndraw :
|
||||||
: lastmillis - conline.outtime < 20000) {
|
lastmillis - conline.outtime < 20000) {
|
||||||
refs[nd++] = conline.text;
|
refs[nd++] = conline.text;
|
||||||
if (nd == ndraw)
|
if (nd == ndraw)
|
||||||
break;
|
break;
|
||||||
|
@ -107,7 +107,7 @@ COMMAND(keymap, ARG_3STR, ^ (OFString *code, OFString *key, OFString *action) {
|
||||||
keyMappings = [[OFMutableArray alloc] init];
|
keyMappings = [[OFMutableArray alloc] init];
|
||||||
|
|
||||||
KeyMapping *mapping = [KeyMapping mappingWithCode: code.cube_intValue
|
KeyMapping *mapping = [KeyMapping mappingWithCode: code.cube_intValue
|
||||||
name: key];
|
name: key];
|
||||||
mapping.action = action;
|
mapping.action = action;
|
||||||
[keyMappings addObject: mapping];
|
[keyMappings addObject: mapping];
|
||||||
})
|
})
|
||||||
|
@ -185,8 +185,8 @@ keypress(int code, bool isDown)
|
||||||
case SDLK_LEFT:
|
case SDLK_LEFT:
|
||||||
if (commandbuf.length > 0)
|
if (commandbuf.length > 0)
|
||||||
[commandbuf deleteCharactersInRange:
|
[commandbuf deleteCharactersInRange:
|
||||||
OFMakeRange(
|
OFMakeRange(
|
||||||
commandbuf.length - 1, 1)];
|
commandbuf.length - 1, 1)];
|
||||||
|
|
||||||
resetcomplete();
|
resetcomplete();
|
||||||
break;
|
break;
|
||||||
|
@ -221,9 +221,8 @@ keypress(int code, bool isDown)
|
||||||
if (code == SDLK_RETURN) {
|
if (code == SDLK_RETURN) {
|
||||||
if (commandbuf.length > 0) {
|
if (commandbuf.length > 0) {
|
||||||
if (vhistory == nil)
|
if (vhistory == nil)
|
||||||
vhistory =
|
vhistory = [[OFMutableArray
|
||||||
[[OFMutableArray alloc]
|
alloc] init];
|
||||||
init];
|
|
||||||
|
|
||||||
if (vhistory.count == 0 ||
|
if (vhistory.count == 0 ||
|
||||||
![vhistory.lastObject isEqual:
|
![vhistory.lastObject isEqual:
|
||||||
|
|
42
src/cube.h
42
src/cube.h
|
@ -108,8 +108,8 @@ struct header {
|
||||||
#define LARGEST_FACTOR 11 // 10 is already insane
|
#define LARGEST_FACTOR 11 // 10 is already insane
|
||||||
#define SOLID(x) ((x)->type == SOLID)
|
#define SOLID(x) ((x)->type == SOLID)
|
||||||
#define MINBORD 2 // 2 cubes from the edge of the world are always solid
|
#define MINBORD 2 // 2 cubes from the edge of the world are always solid
|
||||||
#define OUTBORD(x, y) \
|
#define OUTBORD(x, y) \
|
||||||
((x) < MINBORD || (y) < MINBORD || (x) >= ssize - MINBORD || \
|
((x) < MINBORD || (y) < MINBORD || (x) >= ssize - MINBORD || \
|
||||||
(y) >= ssize - MINBORD)
|
(y) >= ssize - MINBORD)
|
||||||
|
|
||||||
struct block {
|
struct block {
|
||||||
|
@ -255,16 +255,16 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
// map data, the mips are sequential 2D arrays in memory
|
// map data, the mips are sequential 2D arrays in memory
|
||||||
extern struct sqr *world, *wmip[];
|
extern struct sqr *world, *wmip[];
|
||||||
extern struct header hdr; // current map header
|
extern struct header hdr; // current map header
|
||||||
extern int sfactor, ssize; // ssize = 2^sfactor
|
extern int sfactor, ssize; // ssize = 2^sfactor
|
||||||
extern int cubicsize, mipsize; // cubicsize = ssize^2
|
extern int cubicsize, mipsize; // cubicsize = ssize^2
|
||||||
// all the other clients (in multiplayer)
|
// all the other clients (in multiplayer)
|
||||||
extern OFMutableArray *players;
|
extern OFMutableArray *players;
|
||||||
extern bool editmode;
|
extern bool editmode;
|
||||||
extern OFMutableArray<Entity *> *ents; // map entities
|
extern OFMutableArray<Entity *> *ents; // map entities
|
||||||
extern OFVector3D worldpos; // current target of the crosshair in the world
|
extern OFVector3D worldpos; // current target of the crosshair in the world
|
||||||
extern int lastmillis; // last time
|
extern int lastmillis; // last time
|
||||||
extern int curtime; // current frame time
|
extern int curtime; // current frame time
|
||||||
extern int gamemode, nextmode;
|
extern int gamemode, nextmode;
|
||||||
extern int xtraverts;
|
extern int xtraverts;
|
||||||
extern bool demoplayback;
|
extern bool demoplayback;
|
||||||
|
@ -284,22 +284,22 @@ extern bool demoplayback;
|
||||||
#define PI (3.1415927f)
|
#define PI (3.1415927f)
|
||||||
#define PI2 (2 * PI)
|
#define PI2 (2 * PI)
|
||||||
|
|
||||||
#define vreject(v, u, max) \
|
#define vreject(v, u, max) \
|
||||||
((v).x > (u).x + (max) || (v).x < (u).x - (max) || \
|
((v).x > (u).x + (max) || (v).x < (u).x - (max) || \
|
||||||
(v).y > (u).y + (max) || (v).y < (u).y - (max))
|
(v).y > (u).y + (max) || (v).y < (u).y - (max))
|
||||||
#define vlinterp(v, f, u, g) \
|
#define vlinterp(v, f, u, g) \
|
||||||
{ \
|
{ \
|
||||||
(v).x = (v).x * f + (u).x * g; \
|
(v).x = (v).x * f + (u).x * g; \
|
||||||
(v).y = (v).y * f + (u).y * g; \
|
(v).y = (v).y * f + (u).y * g; \
|
||||||
(v).z = (v).z * f + (u).z * g; \
|
(v).z = (v).z * f + (u).z * g; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define sgetstr() \
|
#define sgetstr() \
|
||||||
{ \
|
{ \
|
||||||
char *t = text; \
|
char *t = text; \
|
||||||
do { \
|
do { \
|
||||||
*t = getint(&p); \
|
*t = getint(&p); \
|
||||||
} while (*t++); \
|
} while (*t++); \
|
||||||
} // used by networking
|
} // used by networking
|
||||||
|
|
||||||
#define m_noitems (gamemode >= 4)
|
#define m_noitems (gamemode >= 4)
|
||||||
|
|
|
@ -43,16 +43,16 @@ OF_CONSTRUCTOR()
|
||||||
int selh = 0;
|
int selh = 0;
|
||||||
bool selset = false;
|
bool selset = false;
|
||||||
|
|
||||||
#define loopselxy(b) \
|
#define loopselxy(b) \
|
||||||
{ \
|
{ \
|
||||||
makeundo(); \
|
makeundo(); \
|
||||||
for (int x = 0; x < sel->xs; x++) { \
|
for (int x = 0; x < sel->xs; x++) { \
|
||||||
for (int y = 0; y < sel->ys; y++) { \
|
for (int y = 0; y < sel->ys; y++) { \
|
||||||
struct sqr *s = S(sel->x + x, sel->y + y); \
|
struct sqr *s = S(sel->x + x, sel->y + y); \
|
||||||
b; \
|
b; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
remip(sel, 0); \
|
remip(sel, 0); \
|
||||||
}
|
}
|
||||||
|
|
||||||
int cx, cy, ch;
|
int cx, cy, ch;
|
||||||
|
@ -72,16 +72,19 @@ toggleedit()
|
||||||
{
|
{
|
||||||
Player *player1 = Player.player1;
|
Player *player1 = Player.player1;
|
||||||
if (player1.state == CS_DEAD)
|
if (player1.state == CS_DEAD)
|
||||||
return; // do not allow dead players to edit to avoid state
|
// do not allow dead players to edit to avoid state
|
||||||
// confusion
|
return;
|
||||||
if (!editmode && !allowedittoggle())
|
if (!editmode && !allowedittoggle())
|
||||||
return; // not in most multiplayer modes
|
// not in most multiplayer modes
|
||||||
|
return;
|
||||||
if (!(editmode = !editmode)) {
|
if (!(editmode = !editmode)) {
|
||||||
settagareas(); // reset triggers to allow quick playtesting
|
// reset triggers to allow quick playtesting
|
||||||
entinmap(player1); // find spawn closest to current floating pos
|
settagareas();
|
||||||
|
// find spawn closest to current floating pos
|
||||||
|
entinmap(player1);
|
||||||
} else {
|
} else {
|
||||||
resettagareas(); // clear trigger areas to allow them to be
|
// clear trigger areas to allow them to be edited
|
||||||
// edited
|
resettagareas();
|
||||||
player1.health = 100;
|
player1.health = 100;
|
||||||
if (m_classicsp)
|
if (m_classicsp)
|
||||||
// all monsters back at their spawns for editing
|
// all monsters back at their spawns for editing
|
||||||
|
@ -127,14 +130,14 @@ noselection()
|
||||||
return !selset;
|
return !selset;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EDITSEL \
|
#define EDITSEL \
|
||||||
if (noteditmode() || noselection()) \
|
if (noteditmode() || noselection()) \
|
||||||
return;
|
return;
|
||||||
#define EDITSELMP \
|
#define EDITSELMP \
|
||||||
if (noteditmode() || noselection() || multiplayer()) \
|
if (noteditmode() || noselection() || multiplayer()) \
|
||||||
return;
|
return;
|
||||||
#define EDITMP \
|
#define EDITMP \
|
||||||
if (noteditmode() || multiplayer()) \
|
if (noteditmode() || multiplayer()) \
|
||||||
return;
|
return;
|
||||||
|
|
||||||
COMMAND(select, ARG_4INT, (^ (int x, int y, int xs, int ys) {
|
COMMAND(select, ARG_4INT, (^ (int x, int y, int xs, int ys) {
|
||||||
|
@ -342,9 +345,9 @@ COMMAND(paste, ARG_NONE, ^ {
|
||||||
blockpaste(copybuf);
|
blockpaste(copybuf);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// maintain most recently used of the texture lists when applying texture
|
||||||
void
|
void
|
||||||
tofronttex() // maintain most recently used of the texture lists when applying
|
tofronttex()
|
||||||
// texture
|
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
int c = curedittex[i];
|
int c = curedittex[i];
|
||||||
|
@ -408,20 +411,22 @@ COMMAND(editheight, ARG_2INT, ^ (int flr, int amount) {
|
||||||
void
|
void
|
||||||
edittexxy(int type, int t, const struct block *sel)
|
edittexxy(int type, int t, const struct block *sel)
|
||||||
{
|
{
|
||||||
loopselxy(switch (type) {
|
loopselxy(
|
||||||
case 0:
|
switch (type) {
|
||||||
s->ftex = t;
|
case 0:
|
||||||
break;
|
s->ftex = t;
|
||||||
case 1:
|
break;
|
||||||
s->wtex = t;
|
case 1:
|
||||||
break;
|
s->wtex = t;
|
||||||
case 2:
|
break;
|
||||||
s->ctex = t;
|
case 2:
|
||||||
break;
|
s->ctex = t;
|
||||||
case 3:
|
break;
|
||||||
s->utex = t;
|
case 3:
|
||||||
break;
|
s->utex = t;
|
||||||
});
|
break;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(edittex, ARG_2INT, ^ (int type, int dir) {
|
COMMAND(edittex, ARG_2INT, ^ (int type, int dir) {
|
||||||
|
@ -486,9 +491,8 @@ edittype(int type)
|
||||||
{
|
{
|
||||||
EDITSEL;
|
EDITSEL;
|
||||||
|
|
||||||
if (type == CORNER &&
|
if (type == CORNER && (sel.xs != sel.ys || sel.xs == 3 || (sel.xs > 4 &&
|
||||||
(sel.xs != sel.ys || sel.xs == 3 || (sel.xs > 4 && sel.xs != 8) ||
|
sel.xs != 8) || sel.x & ~-sel.xs || sel.y & ~-sel.ys)) {
|
||||||
sel.x & ~-sel.xs || sel.y & ~-sel.ys)) {
|
|
||||||
conoutf(@"corner selection must be power of 2 aligned");
|
conoutf(@"corner selection must be power of 2 aligned");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -582,11 +586,10 @@ COMMAND(arch, ARG_2INT, ^ (int sidedelta, int _a) {
|
||||||
struct block *sel_ = &sel;
|
struct block *sel_ = &sel;
|
||||||
// Ugly hack to make the macro work.
|
// Ugly hack to make the macro work.
|
||||||
struct block *sel = sel_;
|
struct block *sel = sel_;
|
||||||
loopselxy(s->vdelta = sel->xs > sel->ys
|
loopselxy(s->vdelta = sel->xs > sel->ys ? (archverts[sel->xs - 1][x] +
|
||||||
? (archverts[sel->xs - 1][x] +
|
(y == 0 || y == sel->ys - 1 ? sidedelta : 0)) :
|
||||||
(y == 0 || y == sel->ys - 1 ? sidedelta : 0))
|
(archverts[sel->ys - 1][y] + (x == 0 || x == sel->xs - 1 ?
|
||||||
: (archverts[sel->ys - 1][y] +
|
sidedelta : 0)));
|
||||||
(x == 0 || x == sel->xs - 1 ? sidedelta : 0)));
|
|
||||||
remipmore(sel, 0);
|
remipmore(sel, 0);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -51,11 +51,10 @@ renderentities()
|
||||||
if (mmi == nil)
|
if (mmi == nil)
|
||||||
continue;
|
continue;
|
||||||
rendermodel(mmi.name, 0, 1, e.attr4, (float)mmi.rad,
|
rendermodel(mmi.name, 0, 1, e.attr4, (float)mmi.rad,
|
||||||
OFMakeVector3D(e.x,
|
OFMakeVector3D(e.x, (float)S(e.x, e.y)->floor +
|
||||||
(float)S(e.x, e.y)->floor + mmi.zoff + e.attr3,
|
mmi.zoff + e.attr3, e.y), (float)((e.attr1 + 7) -
|
||||||
e.y),
|
(e.attr1 + 7) % 15), 0, false, 1.0f, 10.0f,
|
||||||
(float)((e.attr1 + 7) - (e.attr1 + 7) % 15), 0,
|
mmi.snap, 0);
|
||||||
false, 1.0f, 10.0f, mmi.snap, 0);
|
|
||||||
} else {
|
} else {
|
||||||
if (OUTBORD(e.x, e.y))
|
if (OUTBORD(e.x, e.y))
|
||||||
continue;
|
continue;
|
||||||
|
@ -65,10 +64,9 @@ renderentities()
|
||||||
if (e.type < I_SHELLS || e.type > TELEPORT)
|
if (e.type < I_SHELLS || e.type > TELEPORT)
|
||||||
continue;
|
continue;
|
||||||
renderent(e, entmdlnames[e.type - I_SHELLS],
|
renderent(e, entmdlnames[e.type - I_SHELLS],
|
||||||
(float)(1 +
|
(float)(1 + sin(lastmillis / 100.0 + e.x +
|
||||||
sin(lastmillis / 100.0 + e.x + e.y) /
|
e.y) / 20), lastmillis / 10.0f, 0, 1, 0,
|
||||||
20),
|
10.0f);
|
||||||
lastmillis / 10.0f, 0, 1, 0, 10.0f);
|
|
||||||
} else {
|
} else {
|
||||||
switch (e.attr2) {
|
switch (e.attr2) {
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -79,32 +77,26 @@ renderentities()
|
||||||
case 0:
|
case 0:
|
||||||
if (!e.spawned)
|
if (!e.spawned)
|
||||||
continue;
|
continue;
|
||||||
renderent(e, @"carrot",
|
renderent(e, @"carrot", (float)(1 +
|
||||||
(float)(1 +
|
sin(lastmillis / 100.0 + e.x +
|
||||||
sin(lastmillis / 100.0 + e.x +
|
e.y) / 20), lastmillis / (e.attr2 ?
|
||||||
e.y) /
|
1.0f : 10.0f), 0, 1, 0, 10.0f);
|
||||||
20),
|
|
||||||
lastmillis /
|
|
||||||
(e.attr2 ? 1.0f : 10.0f),
|
|
||||||
0, 1, 0, 10.0f);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
renderent(e, @"switch2", 3,
|
renderent(e, @"switch2", 3,
|
||||||
(float)e.attr3 * 90,
|
(float)e.attr3 * 90,
|
||||||
(!e.spawned && !triggertime) ? 1
|
(!e.spawned && !triggertime) ?
|
||||||
: 0,
|
1 : 0, (e.spawned || !triggertime) ?
|
||||||
(e.spawned || !triggertime) ? 1 : 2,
|
1 : 2, triggertime, 1050.0f);
|
||||||
triggertime, 1050.0f);
|
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
renderent(e, @"switch1", -0.15f,
|
renderent(e, @"switch1", -0.15f,
|
||||||
(float)e.attr3 * 90,
|
(float)e.attr3 * 90,
|
||||||
(!e.spawned && !triggertime) ? 30
|
(!e.spawned && !triggertime) ?
|
||||||
: 0,
|
30 : 0, (e.spawned ||
|
||||||
(e.spawned || !triggertime) ? 1
|
!triggertime) ? 1 : 30, triggertime,
|
||||||
: 30,
|
35.0f);
|
||||||
triggertime, 35.0f);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
|
|
||||||
// collide with player or monster
|
// collide with player or monster
|
||||||
static bool
|
static bool
|
||||||
plcollide(
|
plcollide(DynamicEntity *d, DynamicEntity *o, float *headspace, float *hi,
|
||||||
DynamicEntity *d, DynamicEntity *o, float *headspace, float *hi, float *lo)
|
float *lo)
|
||||||
{
|
{
|
||||||
if (o.state != CS_ALIVE)
|
if (o.state != CS_ALIVE)
|
||||||
return true;
|
return true;
|
||||||
|
@ -125,22 +125,15 @@ collide(DynamicEntity *d, bool spawn, float drop, float rise)
|
||||||
return false;
|
return false;
|
||||||
case CORNER: {
|
case CORNER: {
|
||||||
int bx = x, by = y, bs = 1;
|
int bx = x, by = y, bs = 1;
|
||||||
if ((x == x1 && y == y1 &&
|
if ((x == x1 && y == y1 && cornertest(0, x, y,
|
||||||
cornertest(
|
-1, -1, &bx, &by, &bs) && fx1 - bx + fy1 -
|
||||||
0, x, y, -1, -1, &bx, &by, &bs) &&
|
by <= bs) || (x == x2 && y == y1 &&
|
||||||
fx1 - bx + fy1 - by <= bs) ||
|
cornertest(0, x, y, 1, -1, &bx, &by, &bs) &&
|
||||||
(x == x2 && y == y1 &&
|
fx2 - bx >= fy1 - by) || (x == x1 && y ==
|
||||||
cornertest(
|
y2 && cornertest(0, x, y, -1, 1, &bx, &by,
|
||||||
0, x, y, 1, -1, &bx, &by, &bs) &&
|
&bs) && fx1 - bx <= fy2 - by) || (x == x2 &&
|
||||||
fx2 - bx >= fy1 - by) ||
|
y == y2 && cornertest(0, x, y, 1, 1, &bx,
|
||||||
(x == x1 && y == y2 &&
|
&by, &bs) && fx2 - bx + fy2 - by >= bs))
|
||||||
cornertest(
|
|
||||||
0, x, y, -1, 1, &bx, &by, &bs) &&
|
|
||||||
fx1 - bx <= fy2 - by) ||
|
|
||||||
(x == x2 && y == y2 &&
|
|
||||||
cornertest(
|
|
||||||
0, x, y, 1, 1, &bx, &by, &bs) &&
|
|
||||||
fx2 - bx + fy2 - by >= bs))
|
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -148,15 +141,13 @@ collide(DynamicEntity *d, bool spawn, float drop, float rise)
|
||||||
// it feels like tiny stairs
|
// it feels like tiny stairs
|
||||||
case FHF:
|
case FHF:
|
||||||
floor -= (s->vdelta + S(x + 1, y)->vdelta +
|
floor -= (s->vdelta + S(x + 1, y)->vdelta +
|
||||||
S(x, y + 1)->vdelta +
|
S(x, y + 1)->vdelta +
|
||||||
S(x + 1, y + 1)->vdelta) /
|
S(x + 1, y + 1)->vdelta) / 16.0f;
|
||||||
16.0f;
|
|
||||||
break;
|
break;
|
||||||
case CHF:
|
case CHF:
|
||||||
ceil += (s->vdelta + S(x + 1, y)->vdelta +
|
ceil += (s->vdelta + S(x + 1, y)->vdelta +
|
||||||
S(x, y + 1)->vdelta +
|
S(x, y + 1)->vdelta +
|
||||||
S(x + 1, y + 1)->vdelta) /
|
S(x + 1, y + 1)->vdelta) / 16.0f;
|
||||||
16.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ceil < hi)
|
if (ceil < hi)
|
||||||
|
@ -214,9 +205,8 @@ collide(DynamicEntity *d, bool spawn, float drop, float rise)
|
||||||
return false;
|
return false;
|
||||||
} else
|
} else
|
||||||
// gravity
|
// gravity
|
||||||
d.origin = OFSubtractVectors3D(d.origin,
|
d.origin = OFSubtractVectors3D(d.origin, OFMakeVector3D(
|
||||||
OFMakeVector3D(
|
0, 0, min(min(drop, space), headspace)));
|
||||||
0, 0, min(min(drop, space), headspace)));
|
|
||||||
|
|
||||||
const float space2 = hi - (d.origin.z + d.aboveEye);
|
const float space2 = hi - (d.origin.z + d.aboveEye);
|
||||||
if (space2 < 0) {
|
if (space2 < 0) {
|
||||||
|
@ -407,11 +397,10 @@ moveplayer4(DynamicEntity *pl, int moveres, bool local, int curtime)
|
||||||
pl.outsideMap = true;
|
pl.outsideMap = true;
|
||||||
else {
|
else {
|
||||||
struct sqr *s = S((int)pl.origin.x, (int)pl.origin.y);
|
struct sqr *s = S((int)pl.origin.x, (int)pl.origin.y);
|
||||||
pl.outsideMap = SOLID(s) ||
|
pl.outsideMap = (SOLID(s) || pl.origin.z < s->floor -
|
||||||
pl.origin.z <
|
(s->type == FHF ? s->vdelta / 4 : 0) ||
|
||||||
s->floor - (s->type == FHF ? s->vdelta / 4 : 0) ||
|
pl.origin.z > s->ceil + (s->type == CHF
|
||||||
pl.origin.z >
|
? s->vdelta / 4 : 0));
|
||||||
s->ceil + (s->type == CHF ? s->vdelta / 4 : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// automatically apply smooth roll when strafing
|
// automatically apply smooth roll when strafing
|
||||||
|
@ -443,8 +432,6 @@ void
|
||||||
moveplayer(DynamicEntity *pl, int moveres, bool local)
|
moveplayer(DynamicEntity *pl, int moveres, bool local)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < physicsrepeat; i++)
|
for (int i = 0; i < physicsrepeat; i++)
|
||||||
moveplayer4(pl, moveres, local,
|
moveplayer4(pl, moveres, local, i ? curtime / physicsrepeat
|
||||||
i ? curtime / physicsrepeat
|
: curtime - curtime / physicsrepeat * (physicsrepeat - 1));
|
||||||
: curtime -
|
|
||||||
curtime / physicsrepeat * (physicsrepeat - 1));
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,28 +31,28 @@ reallocv()
|
||||||
// the leaves of all these functions, and are part of the cpu bottleneck on
|
// the leaves of all these functions, and are part of the cpu bottleneck on
|
||||||
// really slow machines, hence the macros.
|
// really slow machines, hence the macros.
|
||||||
|
|
||||||
#define vertcheck() \
|
#define vertcheck() \
|
||||||
{ \
|
{ \
|
||||||
if (curvert >= curmaxverts) \
|
if (curvert >= curmaxverts) \
|
||||||
reallocv(); \
|
reallocv(); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define vertf(v1, v2, v3, ls, t1, t2) \
|
#define vertf(v1, v2, v3, ls, t1, t2) \
|
||||||
{ \
|
{ \
|
||||||
struct vertex *v = &verts[curvert++]; \
|
struct vertex *v = &verts[curvert++]; \
|
||||||
v->u = t1; \
|
v->u = t1; \
|
||||||
v->v = t2; \
|
v->v = t2; \
|
||||||
v->x = v1; \
|
v->x = v1; \
|
||||||
v->y = v2; \
|
v->y = v2; \
|
||||||
v->z = v3; \
|
v->z = v3; \
|
||||||
v->r = ls->r; \
|
v->r = ls->r; \
|
||||||
v->g = ls->g; \
|
v->g = ls->g; \
|
||||||
v->b = ls->b; \
|
v->b = ls->b; \
|
||||||
v->a = 255; \
|
v->a = 255; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define vert(v1, v2, v3, ls, t1, t2) \
|
#define vert(v1, v2, v3, ls, t1, t2) \
|
||||||
{ \
|
{ \
|
||||||
vertf((float)(v1), (float)(v2), (float)(v3), ls, t1, t2); \
|
vertf((float)(v1), (float)(v2), (float)(v3), ls, t1, t2); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,12 +75,12 @@ mipstats(int a, int b, int c)
|
||||||
conoutf(@"1x1/2x2/4x4: %d / %d / %d", a, b, c);
|
conoutf(@"1x1/2x2/4x4: %d / %d / %d", a, b, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define stripend() \
|
#define stripend() \
|
||||||
{ \
|
{ \
|
||||||
if (floorstrip || deltastrip) { \
|
if (floorstrip || deltastrip) { \
|
||||||
addstrip(ogltex, firstindex, curvert - firstindex); \
|
addstrip(ogltex, firstindex, curvert - firstindex); \
|
||||||
floorstrip = deltastrip = false; \
|
floorstrip = deltastrip = false; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
finishstrips()
|
finishstrips()
|
||||||
|
@ -138,14 +138,13 @@ render_flat(int wtex, int x, int y, int size, int h, struct sqr *l1,
|
||||||
} else // continue strip
|
} else // continue strip
|
||||||
{
|
{
|
||||||
int lighterr = lighterror * 2;
|
int lighterr = lighterror * 2;
|
||||||
|
// skip vertices if light values are close enough
|
||||||
if ((abs(ol3r - l3->r) < lighterr &&
|
if ((abs(ol3r - l3->r) < lighterr &&
|
||||||
abs(ol4r - l4->r) < lighterr // skip vertices if light
|
abs(ol4r - l4->r) < lighterr &&
|
||||||
// values are close enough
|
abs(ol3g - l3->g) < lighterr &&
|
||||||
&& abs(ol3g - l3->g) < lighterr &&
|
abs(ol4g - l4->g) < lighterr &&
|
||||||
abs(ol4g - l4->g) < lighterr &&
|
abs(ol3b - l3->b) < lighterr &&
|
||||||
abs(ol3b - l3->b) < lighterr &&
|
abs(ol4b - l4->b) < lighterr) || !wtex) {
|
||||||
abs(ol4b - l4->b) < lighterr) ||
|
|
||||||
!wtex) {
|
|
||||||
curvert -= 2;
|
curvert -= 2;
|
||||||
nquads--;
|
nquads--;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -206,12 +206,11 @@ renderents()
|
||||||
int e = closestent();
|
int e = closestent();
|
||||||
if (e >= 0) {
|
if (e >= 0) {
|
||||||
Entity *c = ents[e];
|
Entity *c = ents[e];
|
||||||
closeent =
|
closeent = [OFString stringWithFormat:
|
||||||
[OFString stringWithFormat:
|
@"closest entity = %@ (%d, %d, %d, %d), "
|
||||||
@"closest entity = %@ (%d, %d, %d, %d), "
|
@"selection = (%d, %d)",
|
||||||
@"selection = (%d, %d)",
|
entnames[c.type], c.attr1, c.attr2, c.attr3, c.attr4,
|
||||||
entnames[c.type], c.attr1, c.attr2, c.attr3, c.attr4,
|
getvar(@"selxs"), getvar(@"selys")];
|
||||||
getvar(@"selxs"), getvar(@"selys")];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +218,7 @@ COMMAND(loadsky, ARG_1STR, (^ (OFString *basename) {
|
||||||
static OFString *lastsky = @"";
|
static OFString *lastsky = @"";
|
||||||
|
|
||||||
basename = [basename stringByReplacingOccurrencesOfString: @"\\"
|
basename = [basename stringByReplacingOccurrencesOfString: @"\\"
|
||||||
withString: @"/"];
|
withString: @"/"];
|
||||||
|
|
||||||
if ([lastsky isEqual: basename])
|
if ([lastsky isEqual: basename])
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -58,7 +58,7 @@ gl_init(int w, int h)
|
||||||
hasoverbright = true;
|
hasoverbright = true;
|
||||||
else
|
else
|
||||||
conoutf(@"WARNING: cannot use overbright lighting, using old "
|
conoutf(@"WARNING: cannot use overbright lighting, using old "
|
||||||
@"lighting model!");
|
@"lighting model!");
|
||||||
|
|
||||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &glmaxtexsize);
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &glmaxtexsize);
|
||||||
|
|
||||||
|
@ -104,8 +104,7 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp)
|
||||||
SDL_ConvertSurface(s, format, 0);
|
SDL_ConvertSurface(s, format, 0);
|
||||||
if (converted == NULL) {
|
if (converted == NULL) {
|
||||||
conoutf(@"texture cannot be converted "
|
conoutf(@"texture cannot be converted "
|
||||||
@"to 24bpp: %@",
|
@"to 24bpp: %@", IRI.string);
|
||||||
IRI.string);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +150,7 @@ installtex(int tnum, OFIRI *IRI, int *xs, int *ys, bool clamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, *xs, *ys, GL_RGB,
|
if (gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, *xs, *ys, GL_RGB,
|
||||||
GL_UNSIGNED_BYTE, scaledimg))
|
GL_UNSIGNED_BYTE, scaledimg))
|
||||||
fatal(@"could not build mipmaps");
|
fatal(@"could not build mipmaps");
|
||||||
|
|
||||||
if (*xs != s->w)
|
if (*xs != s->w)
|
||||||
|
@ -202,7 +201,7 @@ COMMAND(texture, ARG_2STR, (^ (OFString *aframe, OFString *name) {
|
||||||
|
|
||||||
mapping[num][frame] = 1;
|
mapping[num][frame] = 1;
|
||||||
mapname[num][frame] = [name stringByReplacingOccurrencesOfString: @"\\"
|
mapname[num][frame] = [name stringByReplacingOccurrencesOfString: @"\\"
|
||||||
withString: @"/"];
|
withString: @"/"];
|
||||||
}))
|
}))
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -334,8 +333,8 @@ VARFP(gamma, 30, 100, 300, {
|
||||||
|
|
||||||
SDL_CalculateGammaRamp(f, ramp);
|
SDL_CalculateGammaRamp(f, ramp);
|
||||||
|
|
||||||
if (SDL_SetWindowGammaRamp(
|
if (SDL_SetWindowGammaRamp(Cube.sharedInstance.window,
|
||||||
Cube.sharedInstance.window, ramp, ramp, ramp) == -1) {
|
ramp, ramp, ramp) == -1) {
|
||||||
conoutf(
|
conoutf(
|
||||||
@"Could not set gamma (card/driver doesn't support it?)");
|
@"Could not set gamma (card/driver doesn't support it?)");
|
||||||
conoutf(@"sdl: %s", SDL_GetError());
|
conoutf(@"sdl: %s", SDL_GetError());
|
||||||
|
@ -355,8 +354,7 @@ transplayer()
|
||||||
|
|
||||||
glTranslated(-player1.origin.x,
|
glTranslated(-player1.origin.x,
|
||||||
(player1.state == CS_DEAD ? player1.eyeHeight - 0.2f : 0) -
|
(player1.state == CS_DEAD ? player1.eyeHeight - 0.2f : 0) -
|
||||||
player1.origin.z,
|
player1.origin.z, -player1.origin.y);
|
||||||
-player1.origin.y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VARP(fov, 10, 105, 120);
|
VARP(fov, 10, 105, 120);
|
||||||
|
@ -377,9 +375,9 @@ drawhudmodel(int start, int end, float speed, int base)
|
||||||
Player *player1 = Player.player1;
|
Player *player1 = Player.player1;
|
||||||
|
|
||||||
rendermodel(hudgunnames[player1.gunSelect], start, end, 0, 1.0f,
|
rendermodel(hudgunnames[player1.gunSelect], start, end, 0, 1.0f,
|
||||||
OFMakeVector3D(
|
OFMakeVector3D(player1.origin.x, player1.origin.z,
|
||||||
player1.origin.x, player1.origin.z, player1.origin.y),
|
player1.origin.y), player1.yaw + 90, player1.pitch, false, 1.0f,
|
||||||
player1.yaw + 90, player1.pitch, false, 1.0f, speed, 0, base);
|
speed, 0, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -91,7 +91,7 @@ rendermodel(OFString *mdl, int frame, int range, int tex, float rad,
|
||||||
MD2 *m = loadmodel(mdl);
|
MD2 *m = loadmodel(mdl);
|
||||||
|
|
||||||
if (isoccluded(Player.player1.origin.x, Player.player1.origin.y,
|
if (isoccluded(Player.player1.origin.x, Player.player1.origin.y,
|
||||||
position.x - rad, position.z - rad, rad * 2))
|
position.x - rad, position.z - rad, rad * 2))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
delayedload(m);
|
delayedload(m);
|
||||||
|
@ -109,28 +109,28 @@ rendermodel(OFString *mdl, int frame, int range, int tex, float rad,
|
||||||
float ll = 256.0f; // 0.96f;
|
float ll = 256.0f; // 0.96f;
|
||||||
float of = 0.0f; // 0.1f;
|
float of = 0.0f; // 0.1f;
|
||||||
light = [OFColor colorWithRed: s->r / ll + of
|
light = [OFColor colorWithRed: s->r / ll + of
|
||||||
green: s->g / ll + of
|
green: s->g / ll + of
|
||||||
blue: s->b / ll + of
|
blue: s->b / ll + of
|
||||||
alpha: 1];
|
alpha: 1.0f];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (teammate) {
|
if (teammate) {
|
||||||
float red, green, blue;
|
float red, green, blue;
|
||||||
[light getRed: &red green: &green blue: &blue alpha: NULL];
|
[light getRed: &red green: &green blue: &blue alpha: NULL];
|
||||||
light = [OFColor colorWithRed: red * 0.6f
|
light = [OFColor colorWithRed: red * 0.6f
|
||||||
green: green * 0.7f
|
green: green * 0.7f
|
||||||
blue: blue * 1.2f
|
blue: blue * 1.2f
|
||||||
alpha: 1];
|
alpha: 1.0f];
|
||||||
}
|
}
|
||||||
|
|
||||||
[m renderWithLight: light
|
[m renderWithLight: light
|
||||||
frame: frame
|
frame: frame
|
||||||
range: range
|
range: range
|
||||||
position: position
|
position: position
|
||||||
yaw: yaw
|
yaw: yaw
|
||||||
pitch: pitch
|
pitch: pitch
|
||||||
scale: scale
|
scale: scale
|
||||||
speed: speed
|
speed: speed
|
||||||
snap: snap
|
snap: snap
|
||||||
basetime: basetime];
|
basetime: basetime];
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,14 +72,13 @@ render_particles(int time)
|
||||||
} parttypes[] = {
|
} parttypes[] = {
|
||||||
{ 0.7f, 0.6f, 0.3f, 2, 3, 0.06f }, // yellow: sparks
|
{ 0.7f, 0.6f, 0.3f, 2, 3, 0.06f }, // yellow: sparks
|
||||||
{ 0.5f, 0.5f, 0.5f, 20, 7, 0.15f }, // grey: small smoke
|
{ 0.5f, 0.5f, 0.5f, 20, 7, 0.15f }, // grey: small smoke
|
||||||
{ 0.2f, 0.2f, 1.0f, 20, 3,
|
{ 0.2f, 0.2f, 1.0f, 20, 3, 0.08f }, // blue: edit mode entities
|
||||||
0.08f }, // blue: edit mode entities
|
{ 1.0f, 0.1f, 0.1f, 1, 7, 0.06f }, // red: blood spats
|
||||||
{ 1.0f, 0.1f, 0.1f, 1, 7, 0.06f }, // red: blood spats
|
{ 1.0f, 0.8f, 0.8f, 20, 6, 1.2f }, // yellow: fireball1
|
||||||
{ 1.0f, 0.8f, 0.8f, 20, 6, 1.2f }, // yellow: fireball1
|
{ 0.5f, 0.5f, 0.5f, 20, 7, 0.6f }, // grey: big smoke
|
||||||
{ 0.5f, 0.5f, 0.5f, 20, 7, 0.6f }, // grey: big smoke
|
{ 1.0f, 1.0f, 1.0f, 20, 8, 1.2f }, // blue: fireball2
|
||||||
{ 1.0f, 1.0f, 1.0f, 20, 8, 1.2f }, // blue: fireball2
|
{ 1.0f, 1.0f, 1.0f, 20, 9, 1.2f }, // green: fireball3
|
||||||
{ 1.0f, 1.0f, 1.0f, 20, 9, 1.2f }, // green: fireball3
|
{ 1.0f, 0.1f, 0.1f, 0, 7, 0.2f }, // red: demotrack
|
||||||
{ 1.0f, 0.1f, 0.1f, 0, 7, 0.2f }, // red: demotrack
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int numrender = 0;
|
int numrender = 0;
|
||||||
|
|
|
@ -140,7 +140,7 @@ draw_textf(OFConstantString *format, int left, int top, int gl_num, ...)
|
||||||
va_list arguments;
|
va_list arguments;
|
||||||
va_start(arguments, gl_num);
|
va_start(arguments, gl_num);
|
||||||
OFString *str = [[OFString alloc] initWithFormat: format
|
OFString *str = [[OFString alloc] initWithFormat: format
|
||||||
arguments: arguments];
|
arguments: arguments];
|
||||||
va_end(arguments);
|
va_end(arguments);
|
||||||
draw_text(str, left, top, gl_num);
|
draw_text(str, left, top, gl_num);
|
||||||
}
|
}
|
||||||
|
|
17
src/rndmap.m
17
src/rndmap.m
|
@ -16,13 +16,10 @@ noise(int x, int y, int seed)
|
||||||
float
|
float
|
||||||
smoothednoise(int x, int y, int seed)
|
smoothednoise(int x, int y, int seed)
|
||||||
{
|
{
|
||||||
float corners =
|
float corners = (noise(x - 1, y - 1, seed) + noise(x + 1, y - 1, seed) +
|
||||||
(noise(x - 1, y - 1, seed) + noise(x + 1, y - 1, seed) +
|
noise(x - 1, y + 1, seed) + noise(x + 1, y + 1, seed)) / 16;
|
||||||
noise(x - 1, y + 1, seed) + noise(x + 1, y + 1, seed)) /
|
|
||||||
16;
|
|
||||||
float sides = (noise(x - 1, y, seed) + noise(x + 1, y, seed) +
|
float sides = (noise(x - 1, y, seed) + noise(x + 1, y, seed) +
|
||||||
noise(x, y - 1, seed) + noise(x, y + 1, seed)) /
|
noise(x, y - 1, seed) + noise(x, y + 1, seed)) / 8;
|
||||||
8;
|
|
||||||
float center = noise(x, y, seed) / 4;
|
float center = noise(x, y, seed) / 4;
|
||||||
return corners + sides + center;
|
return corners + sides + center;
|
||||||
}
|
}
|
||||||
|
@ -78,11 +75,9 @@ perlinarea(const struct block *b, int scale, int seed, int psize)
|
||||||
struct sqr *s = S(x, y);
|
struct sqr *s = S(x, y);
|
||||||
if (!SOLID(s) && x != b->x + b->xs && y != b->y + b->ys)
|
if (!SOLID(s) && x != b->x + b->xs && y != b->y + b->ys)
|
||||||
s->type = FHF;
|
s->type = FHF;
|
||||||
s->vdelta =
|
s->vdelta = (int)(perlinnoise_2D(
|
||||||
(int)(perlinnoise_2D(x / ((float)scale) + seed,
|
x / ((float)scale) + seed,
|
||||||
y / ((float)scale) + seed, 1000, 0.01f) *
|
y / ((float)scale) + seed, 1000, 0.01f) * 50 + 25);
|
||||||
50 +
|
|
||||||
25);
|
|
||||||
if (s->vdelta > 128)
|
if (s->vdelta > 128)
|
||||||
s->vdelta = 0;
|
s->vdelta = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,9 +164,9 @@ loadstate(OFIRI *IRI)
|
||||||
if (strncmp(buf, "CUBESAVE", 8))
|
if (strncmp(buf, "CUBESAVE", 8))
|
||||||
goto out;
|
goto out;
|
||||||
if (gzgetc(f) != islittleendian)
|
if (gzgetc(f) != islittleendian)
|
||||||
goto out; // not supporting save->load accross
|
// not supporting save->load accross incompatible architectures
|
||||||
// incompatible architectures simpifies things
|
// simpifies things a LOT
|
||||||
// a LOT
|
goto out;
|
||||||
if (gzgeti() != SAVEGAMEVERSION ||
|
if (gzgeti() != SAVEGAMEVERSION ||
|
||||||
gzgeti() != DynamicEntity.serializedSize)
|
gzgeti() != DynamicEntity.serializedSize)
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -178,7 +178,7 @@ loadstate(OFIRI *IRI)
|
||||||
return;
|
return;
|
||||||
out:
|
out:
|
||||||
conoutf(@"aborting: savegame/demo from a different version of "
|
conoutf(@"aborting: savegame/demo from a different version of "
|
||||||
@"cube or cpu architecture");
|
@"cube or cpu architecture");
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ loadgameout()
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
conoutf(@"loadgame incomplete: savegame from a different version of "
|
conoutf(@"loadgame incomplete: savegame from a different version of "
|
||||||
@"this map");
|
@"this map");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -381,24 +381,24 @@ startdemo()
|
||||||
VAR(demodelaymsec, 0, 120, 500);
|
VAR(demodelaymsec, 0, 120, 500);
|
||||||
|
|
||||||
// spline interpolation
|
// spline interpolation
|
||||||
#define catmulrom(z, a, b, c, s, dest) \
|
#define catmulrom(z, a, b, c, s, dest) \
|
||||||
{ \
|
{ \
|
||||||
OFVector3D t1 = OFSubtractVectors3D(b, z); \
|
OFVector3D t1 = OFSubtractVectors3D(b, z); \
|
||||||
t1 = OFMultiplyVector3D(t1, 0.5f); \
|
t1 = OFMultiplyVector3D(t1, 0.5f); \
|
||||||
\
|
\
|
||||||
OFVector3D t2 = OFSubtractVectors3D(c, a); \
|
OFVector3D t2 = OFSubtractVectors3D(c, a); \
|
||||||
t2 = OFMultiplyVector3D(t2, 0.5f); \
|
t2 = OFMultiplyVector3D(t2, 0.5f); \
|
||||||
\
|
\
|
||||||
float s2 = s * s; \
|
float s2 = s * s; \
|
||||||
float s3 = s * s2; \
|
float s3 = s * s2; \
|
||||||
\
|
\
|
||||||
dest = OFMultiplyVector3D(a, 2 * s3 - 3 * s2 + 1); \
|
dest = OFMultiplyVector3D(a, 2 * s3 - 3 * s2 + 1); \
|
||||||
OFVector3D t = OFMultiplyVector3D(b, -2 * s3 + 3 * s2); \
|
OFVector3D t = OFMultiplyVector3D(b, -2 * s3 + 3 * s2); \
|
||||||
dest = OFAddVectors3D(dest, t); \
|
dest = OFAddVectors3D(dest, t); \
|
||||||
t1 = OFMultiplyVector3D(t1, s3 - 2 * s2 + s); \
|
t1 = OFMultiplyVector3D(t1, s3 - 2 * s2 + s); \
|
||||||
dest = OFAddVectors3D(dest, t1); \
|
dest = OFAddVectors3D(dest, t1); \
|
||||||
t2 = OFMultiplyVector3D(t2, s3 - s2); \
|
t2 = OFMultiplyVector3D(t2, s3 - s2); \
|
||||||
dest = OFAddVectors3D(dest, t2); \
|
dest = OFAddVectors3D(dest, t2); \
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -453,9 +453,8 @@ demoplaybackstep()
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert latest copy of player into history
|
// insert latest copy of player into history
|
||||||
if (extras &&
|
if (extras && (playerhistory.count == 0 ||
|
||||||
(playerhistory.count == 0 ||
|
playerhistory.lastObject.lastUpdate != playbacktime)) {
|
||||||
playerhistory.lastObject.lastUpdate != playbacktime)) {
|
|
||||||
Player *d = [target copy];
|
Player *d = [target copy];
|
||||||
d.lastUpdate = playbacktime;
|
d.lastUpdate = playbacktime;
|
||||||
|
|
||||||
|
|
11
src/server.m
11
src/server.m
|
@ -399,10 +399,10 @@ resetserverifempty()
|
||||||
int nonlocalclients = 0;
|
int nonlocalclients = 0;
|
||||||
int lastconnect = 0;
|
int lastconnect = 0;
|
||||||
|
|
||||||
|
// main server update, called from cube main loop in sp, or dedicated server
|
||||||
|
// loop
|
||||||
void
|
void
|
||||||
serverslice(int seconds,
|
serverslice(int seconds, unsigned int timeout)
|
||||||
unsigned int timeout) // main server update, called from cube main loop in
|
|
||||||
// sp, or dedicated server loop
|
|
||||||
{
|
{
|
||||||
// spawn entities when timer reached
|
// spawn entities when timer reached
|
||||||
[sents enumerateObjectsUsingBlock:
|
[sents enumerateObjectsUsingBlock:
|
||||||
|
@ -472,9 +472,8 @@ serverslice(int seconds,
|
||||||
c.peer->data = (void *)(clients.count - 1);
|
c.peer->data = (void *)(clients.count - 1);
|
||||||
char hn[1024];
|
char hn[1024];
|
||||||
c.hostname = (enet_address_get_host(
|
c.hostname = (enet_address_get_host(
|
||||||
&c.peer->address, hn, sizeof(hn)) == 0
|
&c.peer->address, hn, sizeof(hn)) == 0
|
||||||
? @(hn)
|
? @(hn) : @"localhost");
|
||||||
: @"localhost");
|
|
||||||
[OFStdOut writeFormat: @"client connected (%@)\n",
|
[OFStdOut writeFormat: @"client connected (%@)\n",
|
||||||
c.hostname];
|
c.hostname];
|
||||||
send_welcome(lastconnect = clients.count - 1);
|
send_welcome(lastconnect = clients.count - 1);
|
||||||
|
|
|
@ -57,14 +57,14 @@ COMMAND(music, ARG_1STR, (^ (OFString *name) {
|
||||||
|
|
||||||
if (soundvol && musicvol) {
|
if (soundvol && musicvol) {
|
||||||
name = [name stringByReplacingOccurrencesOfString: @"\\"
|
name = [name stringByReplacingOccurrencesOfString: @"\\"
|
||||||
withString: @"/"];
|
withString: @"/"];
|
||||||
OFString *path = [OFString stringWithFormat:
|
OFString *path = [OFString stringWithFormat:
|
||||||
@"packages/%@", name];
|
@"packages/%@", name];
|
||||||
OFIRI *IRI = [Cube.sharedInstance.gameDataIRI
|
OFIRI *IRI = [Cube.sharedInstance.gameDataIRI
|
||||||
IRIByAppendingPathComponent: path];
|
IRIByAppendingPathComponent: path];
|
||||||
|
|
||||||
if ((mod = Mix_LoadMUS(
|
if ((mod = Mix_LoadMUS(
|
||||||
IRI.fileSystemRepresentation.UTF8String)) != NULL) {
|
IRI.fileSystemRepresentation.UTF8String)) != NULL) {
|
||||||
Mix_PlayMusic(mod, -1);
|
Mix_PlayMusic(mod, -1);
|
||||||
Mix_VolumeMusic((musicvol * MAXVOL) / 255);
|
Mix_VolumeMusic((musicvol * MAXVOL) / 255);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,10 @@
|
||||||
#define min(a, b) (((a) < (b)) ? (a) : (b))
|
#define min(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
#define rnd(max) (rand() % (max))
|
#define rnd(max) (rand() % (max))
|
||||||
#define rndreset() (srand(1))
|
#define rndreset() (srand(1))
|
||||||
#define rndtime() \
|
#define rndtime() \
|
||||||
{ \
|
{ \
|
||||||
for (int i = 0; i < (lastmillis & 0xF); i++) \
|
for (int i = 0; i < (lastmillis & 0xF); i++) \
|
||||||
rnd(i + 1); \
|
rnd(i + 1); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef OF_WINDOWS
|
#ifndef OF_WINDOWS
|
||||||
|
|
37
src/world.m
37
src/world.m
|
@ -161,8 +161,7 @@ remip(const struct block *b, int level)
|
||||||
// next to hfs
|
// next to hfs
|
||||||
fh -=
|
fh -=
|
||||||
o[i]->vdelta /
|
o[i]->vdelta /
|
||||||
4 +
|
4 + 2;
|
||||||
2;
|
|
||||||
if (o[i]->type == CHF)
|
if (o[i]->type == CHF)
|
||||||
// FIXME: needs
|
// FIXME: needs
|
||||||
// to somehow
|
// to somehow
|
||||||
|
@ -173,8 +172,7 @@ remip(const struct block *b, int level)
|
||||||
// higher mips
|
// higher mips
|
||||||
ch +=
|
ch +=
|
||||||
o[i]->vdelta /
|
o[i]->vdelta /
|
||||||
4 +
|
4 + 2;
|
||||||
2;
|
|
||||||
}
|
}
|
||||||
if (fh < floor)
|
if (fh < floor)
|
||||||
// take lowest floor and
|
// take lowest floor and
|
||||||
|
@ -214,11 +212,11 @@ remip(const struct block *b, int level)
|
||||||
o[i]->ftex != o[3]->ftex ||
|
o[i]->ftex != o[3]->ftex ||
|
||||||
o[i]->ctex != o[3]->ctex ||
|
o[i]->ctex != o[3]->ctex ||
|
||||||
abs(o[i + 1]->r - o[0]->r) >
|
abs(o[i + 1]->r - o[0]->r) >
|
||||||
lighterr ||
|
lighterr ||
|
||||||
abs(o[i + 1]->g - o[0]->g) >
|
abs(o[i + 1]->g - o[0]->g) >
|
||||||
lighterr ||
|
lighterr ||
|
||||||
abs(o[i + 1]->b - o[0]->b) >
|
abs(o[i + 1]->b - o[0]->b) >
|
||||||
lighterr ||
|
lighterr ||
|
||||||
o[i]->utex != o[3]->utex ||
|
o[i]->utex != o[3]->utex ||
|
||||||
o[i]->wtex != o[3]->wtex)
|
o[i]->wtex != o[3]->wtex)
|
||||||
goto c;
|
goto c;
|
||||||
|
@ -228,25 +226,20 @@ remip(const struct block *b, int level)
|
||||||
// lie on one line
|
// lie on one line
|
||||||
if (r->type == CHF || r->type == FHF) {
|
if (r->type == CHF || r->type == FHF) {
|
||||||
if (o[0]->vdelta - o[1]->vdelta !=
|
if (o[0]->vdelta - o[1]->vdelta !=
|
||||||
o[1]->vdelta -
|
o[1]->vdelta -
|
||||||
SWS(w, x + 2, y, ws)
|
SWS(w, x + 2, y, ws)->vdelta ||
|
||||||
->vdelta ||
|
|
||||||
o[0]->vdelta - o[2]->vdelta !=
|
o[0]->vdelta - o[2]->vdelta !=
|
||||||
o[2]->vdelta -
|
o[2]->vdelta -
|
||||||
SWS(w, x + 2, y + 2, ws)
|
SWS(w, x + 2, y + 2, ws)->vdelta ||
|
||||||
->vdelta ||
|
|
||||||
o[0]->vdelta - o[3]->vdelta !=
|
o[0]->vdelta - o[3]->vdelta !=
|
||||||
o[3]->vdelta -
|
o[3]->vdelta -
|
||||||
SWS(w, x, y + 2, ws)
|
SWS(w, x, y + 2, ws)->vdelta ||
|
||||||
->vdelta ||
|
|
||||||
o[3]->vdelta - o[2]->vdelta !=
|
o[3]->vdelta - o[2]->vdelta !=
|
||||||
o[2]->vdelta -
|
o[2]->vdelta -
|
||||||
SWS(w, x + 2, y + 1, ws)
|
SWS(w, x + 2, y + 1, ws)->vdelta ||
|
||||||
->vdelta ||
|
|
||||||
o[1]->vdelta - o[2]->vdelta !=
|
o[1]->vdelta - o[2]->vdelta !=
|
||||||
o[2]->vdelta -
|
o[2]->vdelta -
|
||||||
SWS(w, x + 1, y + 2, ws)
|
SWS(w, x + 1, y + 2, ws)->vdelta)
|
||||||
->vdelta)
|
|
||||||
goto c;
|
goto c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,8 +170,8 @@ readmap(OFString *mname)
|
||||||
void
|
void
|
||||||
save_world(OFString *mname)
|
save_world(OFString *mname)
|
||||||
{
|
{
|
||||||
resettagareas(); // wouldn't be able to reproduce tagged areas
|
// wouldn't be able to reproduce tagged areas otherwise
|
||||||
// otherwise
|
resettagareas();
|
||||||
voptimize();
|
voptimize();
|
||||||
toptimize();
|
toptimize();
|
||||||
if (mname.length == 0)
|
if (mname.length == 0)
|
||||||
|
@ -203,16 +203,16 @@ save_world(OFString *mname)
|
||||||
}
|
}
|
||||||
struct sqr *t = NULL;
|
struct sqr *t = NULL;
|
||||||
int sc = 0;
|
int sc = 0;
|
||||||
#define spurge \
|
#define spurge \
|
||||||
while (sc) { \
|
while (sc) { \
|
||||||
gzputc(f, 255); \
|
gzputc(f, 255); \
|
||||||
if (sc > 255) { \
|
if (sc > 255) { \
|
||||||
gzputc(f, 255); \
|
gzputc(f, 255); \
|
||||||
sc -= 255; \
|
sc -= 255; \
|
||||||
} else { \
|
} else { \
|
||||||
gzputc(f, sc); \
|
gzputc(f, sc); \
|
||||||
sc = 0; \
|
sc = 0; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
for (int k = 0; k < cubicsize; k++) {
|
for (int k = 0; k < cubicsize; k++) {
|
||||||
struct sqr *s = &world[k];
|
struct sqr *s = &world[k];
|
||||||
|
@ -262,9 +262,10 @@ COMMAND(savemap, ARG_1STR, ^ (OFString *mname) {
|
||||||
save_world(mname);
|
save_world(mname);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// still supports all map formats that have existed since the earliest cube
|
||||||
|
// betas!
|
||||||
void
|
void
|
||||||
load_world(OFString *mname) // still supports all map formats that have existed
|
load_world(OFString *mname)
|
||||||
// since the earliest cube betas!
|
|
||||||
{
|
{
|
||||||
stopifrecording();
|
stopifrecording();
|
||||||
cleardlights();
|
cleardlights();
|
||||||
|
|
|
@ -42,11 +42,8 @@ lightray(float bx, float by, Entity *light)
|
||||||
// coloured light version, special case because most lights are
|
// coloured light version, special case because most lights are
|
||||||
// white
|
// white
|
||||||
if (light.attr3 || light.attr4) {
|
if (light.attr3 || light.attr4) {
|
||||||
int dimness = rnd(
|
int dimness = rnd((255 - (light.attr2 + light.attr3 +
|
||||||
(255 -
|
light.attr4) / 3) / 16 + 1);
|
||||||
(light.attr2 + light.attr3 + light.attr4) / 3) /
|
|
||||||
16 +
|
|
||||||
1);
|
|
||||||
x += stepx * dimness;
|
x += stepx * dimness;
|
||||||
y += stepy * dimness;
|
y += stepy * dimness;
|
||||||
|
|
||||||
|
@ -148,19 +145,20 @@ void
|
||||||
postlightarea(const struct block *a)
|
postlightarea(const struct block *a)
|
||||||
{
|
{
|
||||||
// assumes area not on edge of world
|
// assumes area not on edge of world
|
||||||
for (int x = 0; x < a->xs; x++)
|
for (int x = 0; x < a->xs; x++) {
|
||||||
for (int y = 0; y < a->ys; y++) {
|
for (int y = 0; y < a->ys; y++) {
|
||||||
struct sqr *s = S(x + a->x, y + a->y);
|
struct sqr *s = S(x + a->x, y + a->y);
|
||||||
#define median(m) \
|
|
||||||
s->m = \
|
// median is 4/2/1 instead
|
||||||
(s->m * 2 + SW(s, 1, 0)->m * 2 + SW(s, 0, 1)->m * 2 + \
|
#define median(m) \
|
||||||
SW(s, -1, 0)->m * 2 + SW(s, 0, -1)->m * 2 + SW(s, 1, 1)->m + \
|
s->m = (s->m * 2 + SW(s, 1, 0)->m * 2 + SW(s, 0, 1)->m * 2 + \
|
||||||
SW(s, 1, -1)->m + SW(s, -1, 1)->m + SW(s, -1, -1)->m) / \
|
SW(s, -1, 0)->m * 2 + SW(s, 0, -1)->m * 2 + SW(s, 1, 1)->m + \
|
||||||
14; // median is 4/2/1 instead
|
SW(s, 1, -1)->m + SW(s, -1, 1)->m + SW(s, -1, -1)->m) / 14;
|
||||||
median(r);
|
median(r);
|
||||||
median(g);
|
median(g);
|
||||||
median(b);
|
median(b);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
remip(a, 0);
|
remip(a, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,11 +38,12 @@ computeraytable(float vx, float vy)
|
||||||
// try to avoid tracing ray if outside of frustrum
|
// try to avoid tracing ray if outside of frustrum
|
||||||
// apitch must be bigger if fov > 120
|
// apitch must be bigger if fov > 120
|
||||||
if ((apitch > 45 || (angle < byaw && angle > syaw) ||
|
if ((apitch > 45 || (angle < byaw && angle > syaw) ||
|
||||||
(angle < byaw - PI2 && angle > syaw - PI2) ||
|
(angle < byaw - PI2 && angle > syaw - PI2) ||
|
||||||
(angle < byaw + PI2 && angle > syaw + PI2)) &&
|
(angle < byaw + PI2 && angle > syaw + PI2)) &&
|
||||||
!OUTBORD(vx, vy) && !SOLID(S((int)vx, (int)vy))) {
|
!OUTBORD(vx, vy) && !SOLID(S((int)vx, (int)vy))) {
|
||||||
float ray = i * 8 / (float)NUMRAYS;
|
float ray = i * 8 / (float)NUMRAYS;
|
||||||
float dx, dy;
|
float dx, dy;
|
||||||
|
|
||||||
if (ray > 1 && ray < 3) {
|
if (ray > 1 && ray < 3) {
|
||||||
dx = -(ray - 2);
|
dx = -(ray - 2);
|
||||||
dy = 1;
|
dy = 1;
|
||||||
|
@ -56,6 +57,7 @@ computeraytable(float vx, float vy)
|
||||||
dx = 1;
|
dx = 1;
|
||||||
dy = ray > 4 ? ray - 8 : ray;
|
dy = ray > 4 ? ray - 8 : ray;
|
||||||
}
|
}
|
||||||
|
|
||||||
float sx = vx;
|
float sx = vx;
|
||||||
float sy = vy;
|
float sy = vy;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -125,60 +127,64 @@ isoccluded(float vx, float vy, float cx, float cy,
|
||||||
// below
|
// below
|
||||||
|
|
||||||
float h, l;
|
float h, l;
|
||||||
if (cx <= vx) // ABDFG
|
if (cx <= vx) {
|
||||||
{
|
// ABDFG
|
||||||
if (cx + csize < vx) // ADF
|
if (cx + csize < vx) {
|
||||||
{
|
// ADF
|
||||||
if (cy <= vy) // AD
|
if (cy <= vy) {
|
||||||
{
|
// AD
|
||||||
if (cy + csize < vy) {
|
if (cy + csize < vy) {
|
||||||
|
// A
|
||||||
h = ca(-(cx - vx), -(cy + csize - vy)) +
|
h = ca(-(cx - vx), -(cy + csize - vy)) +
|
||||||
4;
|
4;
|
||||||
l = ca(-(cx + csize - vx), -(cy - vy)) +
|
l = ca(-(cx + csize - vx), -(cy - vy)) +
|
||||||
4;
|
4;
|
||||||
} // A
|
} else {
|
||||||
else {
|
// D
|
||||||
h = ma(-(cx + csize - vx),
|
h = ma(-(cx + csize - vx),
|
||||||
-(cy + csize - vy)) +
|
-(cy + csize - vy)) + 4;
|
||||||
4;
|
l = ma(-(cx + csize - vx),
|
||||||
l = ma(-(cx + csize - vx), -(cy - vy)) +
|
-(cy - vy)) + 4;
|
||||||
4;
|
}
|
||||||
} // D
|
|
||||||
} else {
|
} else {
|
||||||
|
// F
|
||||||
h = ca(cy + csize - vy, -(cx + csize - vx)) + 2;
|
h = ca(cy + csize - vy, -(cx + csize - vx)) + 2;
|
||||||
l = ca(cy - vy, -(cx - vx)) + 2;
|
l = ca(cy - vy, -(cx - vx)) + 2;
|
||||||
} // F
|
}
|
||||||
} else { // BG
|
} else {
|
||||||
|
// BG
|
||||||
if (cy <= vy) {
|
if (cy <= vy) {
|
||||||
if (cy + csize < vy) {
|
if (cy + csize < vy) {
|
||||||
|
// B
|
||||||
h = ma(-(cy + csize - vy), cx - vx) + 6;
|
h = ma(-(cy + csize - vy), cx - vx) + 6;
|
||||||
l = ma(-(cy + csize - vy),
|
l = ma(-(cy + csize - vy),
|
||||||
cx + csize - vx) +
|
cx + csize - vx) + 6;
|
||||||
6;
|
} else
|
||||||
} // B
|
|
||||||
else
|
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
// G
|
||||||
h = ma(cy - vy, -(cx + csize - vx)) + 2;
|
h = ma(cy - vy, -(cx + csize - vx)) + 2;
|
||||||
l = ma(cy - vy, -(cx - vx)) + 2;
|
l = ma(cy - vy, -(cx - vx)) + 2;
|
||||||
} // G
|
}
|
||||||
}
|
}
|
||||||
} else // CEH
|
} else {
|
||||||
{
|
// CEH
|
||||||
if (cy <= vy) // CE
|
if (cy <= vy) {
|
||||||
{
|
// CE
|
||||||
if (cy + csize < vy) {
|
if (cy + csize < vy) {
|
||||||
|
// C
|
||||||
h = ca(-(cy - vy), cx - vx) + 6;
|
h = ca(-(cy - vy), cx - vx) + 6;
|
||||||
l = ca(-(cy + csize - vy), cx + csize - vx) + 6;
|
l = ca(-(cy + csize - vy), cx + csize - vx) + 6;
|
||||||
} // C
|
} else {
|
||||||
else {
|
// E
|
||||||
h = ma(cx - vx, cy - vy);
|
h = ma(cx - vx, cy - vy);
|
||||||
l = ma(cx - vx, cy + csize - vy);
|
l = ma(cx - vx, cy + csize - vy);
|
||||||
} // E
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// H
|
||||||
h = ca(cx + csize - vx, cy - vy);
|
h = ca(cx + csize - vx, cy - vy);
|
||||||
l = ca(cx - vx, cy + csize - vy);
|
l = ca(cx - vx, cy + csize - vy);
|
||||||
} // H
|
}
|
||||||
}
|
}
|
||||||
// get indexes into occlusion map from angles
|
// get indexes into occlusion map from angles
|
||||||
int si = h * (NUMRAYS / 8) + NUMRAYS;
|
int si = h * (NUMRAYS / 8) + NUMRAYS;
|
||||||
|
@ -186,12 +192,11 @@ isoccluded(float vx, float vy, float cx, float cy,
|
||||||
if (ei <= si)
|
if (ei <= si)
|
||||||
ei += NUMRAYS;
|
ei += NUMRAYS;
|
||||||
|
|
||||||
for (int i = si; i <= ei; i++) {
|
for (int i = si; i <= ei; i++)
|
||||||
if (dist < rdist[i & (NUMRAYS - 1)])
|
if (dist < rdist[i & (NUMRAYS - 1)])
|
||||||
// if any value in this segment of the occlusion map is
|
// if any value in this segment of the occlusion map is
|
||||||
// further away then cube is not occluded
|
// further away then cube is not occluded
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
return 1; // cube is entirely occluded
|
return 1; // cube is entirely occluded
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,9 +125,9 @@ render_seg_new(
|
||||||
int sz = ssize >> mip;
|
int sz = ssize >> mip;
|
||||||
int vxx = ((int)vx + (1 << mip) / 2) >> mip;
|
int vxx = ((int)vx + (1 << mip) / 2) >> mip;
|
||||||
int vyy = ((int)vy + (1 << mip) / 2) >> mip;
|
int vyy = ((int)vy + (1 << mip) / 2) >> mip;
|
||||||
int lx =
|
// these mark the rect inside the current rest that we want to render
|
||||||
vxx - lodleft; // these mark the rect inside the current rest that
|
// using a lower mip level
|
||||||
// we want to render using a lower mip level
|
int lx = vxx - lodleft;
|
||||||
int ly = vyy - lodtop;
|
int ly = vyy - lodtop;
|
||||||
int rx = vxx + lodright;
|
int rx = vxx + lodright;
|
||||||
int ry = vyy + lodbot;
|
int ry = vyy + lodbot;
|
||||||
|
@ -139,7 +139,7 @@ render_seg_new(
|
||||||
for (int oy = y; oy < ys; oy++) {
|
for (int oy = y; oy < ys; oy++) {
|
||||||
SWS(w, ox, oy, sz)->occluded =
|
SWS(w, ox, oy, sz)->occluded =
|
||||||
isoccluded(player1.origin.x, player1.origin.y,
|
isoccluded(player1.origin.x, player1.origin.y,
|
||||||
(float)(ox << mip), (float)(oy << mip), fsize);
|
(float)(ox << mip), (float)(oy << mip), fsize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,19 +161,19 @@ render_seg_new(
|
||||||
// and are also deferred, and render them recursively. Anything left
|
// and are also deferred, and render them recursively. Anything left
|
||||||
// (perfect mips and higher lods) we render here.
|
// (perfect mips and higher lods) we render here.
|
||||||
|
|
||||||
#define LOOPH \
|
#define LOOPH \
|
||||||
{ \
|
{ \
|
||||||
for (int xx = x; xx < xs; xx++) \
|
for (int xx = x; xx < xs; xx++) \
|
||||||
for (int yy = y; yy < ys; yy++) { \
|
for (int yy = y; yy < ys; yy++) { \
|
||||||
struct sqr *s = SWS(w, xx, yy, sz); \
|
struct sqr *s = SWS(w, xx, yy, sz); \
|
||||||
if (s->occluded == 1) \
|
if (s->occluded == 1) \
|
||||||
continue; \
|
continue; \
|
||||||
if (s->defer && !s->occluded && mip && \
|
if (s->defer && !s->occluded && mip && \
|
||||||
xx >= lx && xx < rx && yy >= ly && \
|
xx >= lx && xx < rx && yy >= ly && \
|
||||||
yy < ry)
|
yy < ry)
|
||||||
#define LOOPD \
|
#define LOOPD \
|
||||||
struct sqr *t = SWS(s, 1, 0, sz); \
|
struct sqr *t = SWS(s, 1, 0, sz); \
|
||||||
struct sqr *u = SWS(s, 1, 1, sz); \
|
struct sqr *u = SWS(s, 1, 1, sz); \
|
||||||
struct sqr *v = SWS(s, 0, 1, sz);
|
struct sqr *v = SWS(s, 0, 1, sz);
|
||||||
|
|
||||||
LOOPH // ceils
|
LOOPH // ceils
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue