From 5e1ce57322bd4c80f7698d139ff6cb328ec5a651 Mon Sep 17 00:00:00 2001 From: Jeff Teunissen Date: Sat, 17 Aug 2002 05:27:34 +0000 Subject: [PATCH] Okay, this might or might not work (but it should). It's the beginning of the Ruamoko standard library overhaul. --- ruamoko/cl_menu/client_menu.h | 2 +- ruamoko/cl_menu/client_menu.qc | 2 +- ruamoko/cl_menu/options.qc | 2 +- ruamoko/cl_menu/servlist.qc | 2 +- ruamoko/game/Axe.h | 18 +++ ruamoko/game/{axe.r => Axe.r} | 25 ++-- ruamoko/game/{gameent.h => GameEntity.h} | 14 ++- ruamoko/game/{gameent.r => GameEntity.r} | 5 +- ruamoko/game/Makefile.am | 2 +- ruamoko/game/Weapon.h | 13 ++ ruamoko/game/{world.h => World.h} | 0 ruamoko/game/World.r | 82 +++++++++++++ ruamoko/game/axe.h | 15 --- ruamoko/game/weapon.h | 11 -- ruamoko/game/world.r | 70 ----------- ruamoko/include/Entity.h | 51 ++++++++ ruamoko/include/{inputline.h => InputLine.h} | 36 +++--- ruamoko/include/Makefile.am | 20 +-- ruamoko/include/{object.h => Object.h} | 6 +- ruamoko/include/Point.h | 27 ++++ ruamoko/include/Rect.h | 39 ++++++ ruamoko/include/Size.h | 61 +++++++++ ruamoko/include/debug.h | 82 ++++++++++++- ruamoko/include/draw.h | 2 +- ruamoko/include/entities.h | 84 +++++++++++++ ruamoko/include/entity.h | 30 ----- ruamoko/include/math.h | 123 +++++++++++++++++-- ruamoko/include/point.h | 17 --- ruamoko/lib/Entity.r | 28 +++++ ruamoko/lib/{inputline.r => InputLine.r} | 45 ++++--- ruamoko/lib/Makefile.am | 17 ++- ruamoko/lib/{object.r => Object.r} | 2 +- ruamoko/lib/Point.r | 64 ++++++++++ ruamoko/lib/draw.r | 10 +- ruamoko/lib/{entity.r => entities.r} | 32 +---- ruamoko/lib/point.r | 33 ----- 36 files changed, 763 insertions(+), 309 deletions(-) create mode 100644 ruamoko/game/Axe.h rename ruamoko/game/{axe.r => Axe.r} (74%) rename ruamoko/game/{gameent.h => GameEntity.h} (61%) rename ruamoko/game/{gameent.r => GameEntity.r} (73%) create mode 100644 ruamoko/game/Weapon.h rename ruamoko/game/{world.h => World.h} (100%) create mode 100644 ruamoko/game/World.r delete mode 100644 ruamoko/game/axe.h delete mode 100644 ruamoko/game/weapon.h delete mode 100644 ruamoko/game/world.r create mode 100644 ruamoko/include/Entity.h rename ruamoko/include/{inputline.h => InputLine.h} (57%) rename ruamoko/include/{object.h => Object.h} (98%) create mode 100644 ruamoko/include/Point.h create mode 100644 ruamoko/include/Rect.h create mode 100644 ruamoko/include/Size.h create mode 100644 ruamoko/include/entities.h delete mode 100644 ruamoko/include/entity.h delete mode 100644 ruamoko/include/point.h create mode 100644 ruamoko/lib/Entity.r rename ruamoko/lib/{inputline.r => InputLine.r} (62%) rename ruamoko/lib/{object.r => Object.r} (99%) create mode 100644 ruamoko/lib/Point.r rename ruamoko/lib/{entity.r => entities.r} (58%) delete mode 100644 ruamoko/lib/point.r diff --git a/ruamoko/cl_menu/client_menu.h b/ruamoko/cl_menu/client_menu.h index a0a17f5ca..a44768497 100644 --- a/ruamoko/cl_menu/client_menu.h +++ b/ruamoko/cl_menu/client_menu.h @@ -1,7 +1,7 @@ #ifndef __client_menu_h #define __client_menu_h -#include "inputline.h" +#include "InputLine.h" @extern inputline_t input_active; diff --git a/ruamoko/cl_menu/client_menu.qc b/ruamoko/cl_menu/client_menu.qc index b3528c9bb..1b023bc8f 100644 --- a/ruamoko/cl_menu/client_menu.qc +++ b/ruamoko/cl_menu/client_menu.qc @@ -3,7 +3,7 @@ #include "cmd.h" #include "draw.h" #include "key.h" -#include "inputline.h" +#include "InputLine.h" #include "string.h" #include "../include/string.h" #include "math.h" diff --git a/ruamoko/cl_menu/options.qc b/ruamoko/cl_menu/options.qc index 9bafca5f0..129c3615c 100644 --- a/ruamoko/cl_menu/options.qc +++ b/ruamoko/cl_menu/options.qc @@ -33,7 +33,7 @@ #include "draw.h" #include "cvar.h" #include "key.h" -#include "inputline.h" +#include "InputLine.h" #include "controls_o.h" #include "options_util.h" diff --git a/ruamoko/cl_menu/servlist.qc b/ruamoko/cl_menu/servlist.qc index c9bf4689a..72ecb6318 100644 --- a/ruamoko/cl_menu/servlist.qc +++ b/ruamoko/cl_menu/servlist.qc @@ -1,6 +1,6 @@ #include "menu.h" #include "draw.h" -#include "inputline.h" +#include "InputLine.h" #include "options_util.h" #include "controls_o.h" #include "client_menu.h" diff --git a/ruamoko/game/Axe.h b/ruamoko/game/Axe.h new file mode 100644 index 000000000..61d0231fe --- /dev/null +++ b/ruamoko/game/Axe.h @@ -0,0 +1,18 @@ +#ifndef __Axe_h +#define __Axe_h + +#include "Object.h" +#include "Entity.h" +#include "Weapon.h" + +@interface Axe: Object +{ + Entity owner; + float damage; +} + +- (id) init; + +@end + +#endif //__Axe_h diff --git a/ruamoko/game/axe.r b/ruamoko/game/Axe.r similarity index 74% rename from ruamoko/game/axe.r rename to ruamoko/game/Axe.r index 9c7fd05fc..4da0c7f7c 100644 --- a/ruamoko/game/axe.r +++ b/ruamoko/game/Axe.r @@ -1,41 +1,43 @@ -#include "axe.h" -#include "gameent.h" #include "math.h" #include "physics.h" #include "qw_message.h" #include "sound.h" + #include "tempent.h" -#include "world.h" + +#include "GameEntity.h" +#include "World.h" +#include "Axe.h" @implementation Axe --init +- (id) init { [super init]; damage = (deathmatch > 3) ? 75.0 : 20.0; return self; } --setOwner:(Entity)o +- (void) setOwner: (Entity) o { owner = o; - return self; } --fire +- (void) fire { - local entity s = [owner ent]; - local vector org, source; + local entity s = [owner ent]; + local vector org, source; makevectors (s.v_angle); source = s.origin + '0 0 16'; + traceline (source, source + v_forward * 64, NO, s); if (trace_fraction == 1.0) - return self; + return; org = trace_endpos - v_forward * 4; - if ([trace_ent.@this takeDamage:self inflictor:s attacker:s :damage]) + if ([trace_ent.@this takeDamage: self inflictor: s attacker: s : damage]) SpawnBlood (org, 20); else { sound (s, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM); @@ -48,7 +50,6 @@ WriteCoord (MSG_MULTICAST, org_z); multicast (org, MULTICAST_PVS); } - return self; } @end diff --git a/ruamoko/game/gameent.h b/ruamoko/game/GameEntity.h similarity index 61% rename from ruamoko/game/gameent.h rename to ruamoko/game/GameEntity.h index 12a2d81e4..241558d98 100644 --- a/ruamoko/game/gameent.h +++ b/ruamoko/game/GameEntity.h @@ -1,7 +1,7 @@ -#ifndef __gameent_h -#define __gameent_h +#ifndef __GameEntity_h +#define __GameEntity_h -#include "entity.h" +#include "Entity.h" @extern .vector angles; @extern .float modelindex; @@ -16,8 +16,10 @@ @extern .float flags; @extern .vector v_angle; -@interface GameEntity : Entity --(BOOL)takeDamage:weapon :inflictor :attacker :(float)damage; +@interface GameEntity: Entity + +- (BOOL) takeDamage: weapon :inflictor :attacker : (float)damage; + @end -#endif//__gameent_h +#endif //__GameEntity_h diff --git a/ruamoko/game/gameent.r b/ruamoko/game/GameEntity.r similarity index 73% rename from ruamoko/game/gameent.r rename to ruamoko/game/GameEntity.r index f372896f4..9fe698f45 100644 --- a/ruamoko/game/gameent.r +++ b/ruamoko/game/GameEntity.r @@ -1,4 +1,4 @@ -#include "gameent.h" +#include "GameEntity.h" .vector angles; .float modelindex; @@ -14,7 +14,8 @@ .vector v_angle; @implementation GameEntity --(BOOL)takeDamage:weapon :inflictor :attacker :damage + +- (BOOL) takeDamage: weapon : inflictor : attacker : damage { return NO; } diff --git a/ruamoko/game/Makefile.am b/ruamoko/game/Makefile.am index 3cfac96fa..fc777b081 100644 --- a/ruamoko/game/Makefile.am +++ b/ruamoko/game/Makefile.am @@ -12,7 +12,7 @@ STRIP=$(shell echo `echo -n $(srcdir)/ | sed -e 's/[^/]//g' | wc -c`) pkgdata_DATA= game.dat -game_src= axe.r gameent.r tempent.r world.r +game_src= Axe.r GameEntity.r World.r tempent.r %.qfo: %.r $(QFCC) $(QCFLAGS) $(QCPPFLAGS) -p $(STRIP) -c -o $@ $< diff --git a/ruamoko/game/Weapon.h b/ruamoko/game/Weapon.h new file mode 100644 index 000000000..3ed7ecc30 --- /dev/null +++ b/ruamoko/game/Weapon.h @@ -0,0 +1,13 @@ +#ifndef __Weapon_h +#define __Weapon_h + +#include "Entity.h" + +@protocol Weapon + +- (void) setOwner: (Entity)o; +- (void) fire; + +@end + +#endif //__Weapon_h diff --git a/ruamoko/game/world.h b/ruamoko/game/World.h similarity index 100% rename from ruamoko/game/world.h rename to ruamoko/game/World.h diff --git a/ruamoko/game/World.r b/ruamoko/game/World.r new file mode 100644 index 000000000..fc0980a29 --- /dev/null +++ b/ruamoko/game/World.r @@ -0,0 +1,82 @@ +#include "GameEntity.h" +#include "World.h" + +id world; +integer deathmatch; + +#define MAX_BODIES 8 + +@interface BodyQueue: Object +{ + entity [MAX_BODIES] bodies; + integer head; +} + +- (id) init; +- (void) addEntity: (GameEntity)ent; + +@end + +@implementation BodyQueue + +- (id) init +{ + local integer i; + id (self) = [super init]; + + self.head = NIL; + + for (i = 0; i < MAX_BODIES; i++) { + local GameEntity ent = NIL; + id(ent) = [[GameEntity alloc] init]; + self.bodies[i] = ent.ent; + } +} + +- (void) addEntity: (GameEntity)ent +{ + local entity be = bodies[head++]; + local entity e = [ent ent]; + + be.angles = e.angles; + be.model = e.model; + be.modelindex = e.modelindex; + be.frame = e.frame; + be.colormap = e.colormap; + be.movetype = e.movetype; + be.velocity = e.velocity; + be.flags = 0; + + setorigin (be, e.origin); + setsize (be, e.mins, e.maxs); +} +@end + +@interface World: GameEntity +{ + id bodyque; +} + +- (void) spawn: (entity)ent; +- (void) copyToBodyQueue: (GameEntity)ent; + +@end + +@implementation World + +- spawn: (entity)ent +{ + [self initWithEntity: ent]; + bodyque = [[BodyQueue alloc] init]; +} + +- (void) copyToBodyQueue: (GameEntity)ent +{ + [bodyque addEntity: ent]; +} +@end + +void () worldspawn = +{ + world = [[World alloc] initWithEntity: @self]; +}; diff --git a/ruamoko/game/axe.h b/ruamoko/game/axe.h deleted file mode 100644 index a7835d9ac..000000000 --- a/ruamoko/game/axe.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __axe_h -#define __axe_h - -#include "entity.h" -#include "weapon.h" - -@interface Axe : Object -{ - Entity owner; - float damage; -} --init; -@end - -#endif//__axe_h diff --git a/ruamoko/game/weapon.h b/ruamoko/game/weapon.h deleted file mode 100644 index 91ca2278b..000000000 --- a/ruamoko/game/weapon.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __weapon_h -#define __weapon_h - -#include "entity.h" - -@protocol Weapon --setOwner:(Entity)o; --fire; -@end - -#endif//__weapon_h diff --git a/ruamoko/game/world.r b/ruamoko/game/world.r deleted file mode 100644 index ce4c0ed09..000000000 --- a/ruamoko/game/world.r +++ /dev/null @@ -1,70 +0,0 @@ -#include "gameent.h" -#include "world.h" - -id world; -integer deathmatch; - -#define MAX_BODIES 8 - -@interface BodyQue : Object -{ - entity [MAX_BODIES] bodies; - integer head; -} --init; --add:(GameEntity)ent; -@end - -@implementation BodyQue --init -{ - local integer i; - [super init]; - self.head = 0; - for (i = 0; i < MAX_BODIES; i++) - self.bodies[i] = [GameEntity new]; -} - --add:(GameEntity)ent -{ - local entity be = bodies[head++]; - local entity e = [ent ent]; - be.angles = e.angles; - be.model = e.model; - be.modelindex = e.modelindex; - be.frame = e.frame; - be.colormap = e.colormap; - be.movetype = e.movetype; - be.velocity = e.velocity; - be.flags = 0; - setorigin (be, e.origin); - setsize (be, e.mins, e.maxs); - return self; -} -@end - -@interface World : GameEntity -{ - BodyQue bodyque; -} --spawn:(entity)ent; --copyToBodyQue:(GameEntity)ent; -@end - -@implementation World --spawn:(entity)ent -{ - [self initWithEntity:ent]; - id (bodyque) = [[BodyQue alloc] init]; -} - --copyToBodyQue:(GameEntity)ent -{ - [bodyque add:ent]; -} -@end - -void () worldspawn = -{ - world = [[World alloc] initWithEntity:@self]; -}; diff --git a/ruamoko/include/Entity.h b/ruamoko/include/Entity.h new file mode 100644 index 000000000..928c9393f --- /dev/null +++ b/ruamoko/include/Entity.h @@ -0,0 +1,51 @@ +/* + Entity.h + + Entity class definition + + Copyright (C) 2002 Bill Currie + Copyright (C) 2002 Jeff Teunissen + + This file is part of the Ruamoko Standard Library. + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or (at + your option) any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + + $Id$ +*/ +#ifndef __ruamoko_Entity_h +#define __ruamoko_Entity_h + +#include "Object.h" +#include "entities.h" + +@interface Entity: Object +{ +@public + entity ent; +} + +- (id) init; +- (id) initWithEntity: (entity) e; +- (void) free; + +- (entity) ent; + +@end + +#endif //__ruamoko_Entity_h diff --git a/ruamoko/include/inputline.h b/ruamoko/include/InputLine.h similarity index 57% rename from ruamoko/include/inputline.h rename to ruamoko/include/InputLine.h index e5f9eb897..fbffb8dc1 100644 --- a/ruamoko/include/inputline.h +++ b/ruamoko/include/InputLine.h @@ -1,9 +1,9 @@ -#ifndef __ruamoko_inputline_h -#define __ruamoko_inputline_h +#ifndef __ruamoko_InputLine_h +#define __ruamoko_InputLine_h -#include "point.h" +#include "Rect.h" -#define OLD_API //FIXME update the input line api +#define OLD_API // FIXME update the input line api struct _inputline_t = {}; // opaque type :) typedef _inputline_t [] inputline_t; @@ -22,18 +22,24 @@ typedef _inputline_t [] inputline_t; @extern void (inputline_t il, string str) InputLine_SetText; @extern string (inputline_t il) InputLine_GetText; -@interface InputLine : Object +@interface InputLine: Object { - Point at; - inputline_t il; + Rect frame; + inputline_t il; } --free; --initAt:(Point)p HistoryLines:(integer)l LineSize:(integer)s PromptChar:(integer)prompt; --setWidth:(integer)visibleWidth; --process:(integer)key; --draw:(BOOL)cursor; --setText:(string)text; --(string)getText; + +- (id) initWithBounds: (Rect)aRect promptCharacter: (integer)char; +//-initAt:(Point)p HistoryLines:(integer)l LineSize:(integer)s PromptChar:(integer)prompt; +- (void) free; + +- (void) setWidth: (integer)width; +- (void) draw: (BOOL)cursor; + +- (void) processInput: (integer)key; + +- (id) setText: (string)text; +- (string) text; + @end -#endif//__ruamoko_inputline_h +#endif //__ruamoko_inputline_h diff --git a/ruamoko/include/Makefile.am b/ruamoko/include/Makefile.am index b7a8a1378..8e5d043f3 100644 --- a/ruamoko/include/Makefile.am +++ b/ruamoko/include/Makefile.am @@ -1,10 +1,10 @@ -AUTOMAKE_OPTIONS = foreign -includedir = $(prefix)/include/QF/ruamoko -include_HEADERS = \ - crudefile.h debug.h entity.h infokey.h math.h message.h nq_message.h \ - object.h physics.h qw_message.h qw_physics.h qw_sys.h sound.h \ - string.h system.h \ - \ - draw.h key.h inputline.h point.h \ - \ - cbuf.h cmd.h cvar.h file.h +AUTOMAKE_OPTIONS= foreign +includedir= $(prefix)/include/QF/ruamoko +include_HEADERS= \ + crudefile.h debug.h entities.h infokey.h math.h message.h nq_message.h \ + physics.h qw_message.h qw_physics.h qw_sys.h sound.h string.h system.h \ + \ + draw.h key.h \ + \ + cbuf.h cmd.h cvar.h file.h \ + Object.h Entity.h InputLine.h Point.h Rect.h Size.h diff --git a/ruamoko/include/object.h b/ruamoko/include/Object.h similarity index 98% rename from ruamoko/include/object.h rename to ruamoko/include/Object.h index 60b946ccb..a5de0cdf9 100644 --- a/ruamoko/include/object.h +++ b/ruamoko/include/Object.h @@ -1,5 +1,5 @@ -#ifndef __ruamoko_object_h -#define __ruamoko_object_h +#ifndef __ruamoko_Object_h +#define __ruamoko_Object_h typedef enum { NO, @@ -134,4 +134,4 @@ typedef enum { //-awake; @end -#endif//__ruamoko_object_h +#endif //__ruamoko_Object_h diff --git a/ruamoko/include/Point.h b/ruamoko/include/Point.h new file mode 100644 index 000000000..385dd3a0c --- /dev/null +++ b/ruamoko/include/Point.h @@ -0,0 +1,27 @@ +#ifndef __ruamoko_Point_h +#define __ruamoko_Point_h + +#include "Object.h" + +@interface Point: Object +{ +@public + integer x; + integer y; +} + +- (id) initWithComponents: (integer)_x : (integer)_y; +- (id) initWithPoint: (Point)aPoint; +- (id) copy; + +- (void) addPoint: (Point)aPoint; +- (void) subtractPoint: (Point)aPoint; + +- (integer) x; +- (integer) y; + +- (void) setPoint: (Point)aPoint; + +@end + +#endif //__ruamoko_Point_h diff --git a/ruamoko/include/Rect.h b/ruamoko/include/Rect.h new file mode 100644 index 000000000..cb95cb68d --- /dev/null +++ b/ruamoko/include/Rect.h @@ -0,0 +1,39 @@ +#ifndef __ruamoko_Rect_h +#define __ruamoko_Rect_h + +#include "Object.h" +#include "Point.h" +#include "Size.h" + +@interface Rect: Object +{ +@public + Point origin; + Size size; +} + +- (id) initWithOrigin: (Point)_origin size: (Size)_size; +- (id) initWithComponents: (integer)x : (integer)y : (integer)w : (integer)h; +- (id) initWithRect: (Rect)aRect; +- (id) copy; + +- (BOOL) intersectsRect: (Rect)aRect; +- (BOOL) containsPoint: (Point)aPoint; +- (BOOL) containsRect: (Rect)aRect; +- (BOOL) isEqualToRect: (Rect)aRect; +- (BOOL) isEmpty; + +- (Rect) intersectionWithRect: (Rect)aRect; +- (Rect) unionWithRect: (Rect)aRect; + +- (Rect) insetBySize: (Size)aSize; +- (Rect) offsetBySize: (Size)aSize; + +- (Point) origin; +- (Size) size; + +- (void) setSize: (Size)aSize; + +@end + +#endif //__ruamoko_Rect_h diff --git a/ruamoko/include/Size.h b/ruamoko/include/Size.h new file mode 100644 index 000000000..0ed739455 --- /dev/null +++ b/ruamoko/include/Size.h @@ -0,0 +1,61 @@ +#ifndef __ruamoko_Size_h +#define __ruamoko_Size_h + +#include "Object.h" +#include "Point.h" +#include "Size.h" + +@interface Size: Object +{ +@public + integer width; + integer height; +} + +- (id) initWithWidth: (integer)w height: (integer)h; +- (id) initWithSize: (Size)aSize; +- (id) copy; + +- (void) addSize: (Size)aSize; +- (void) subtractSize: (Size)aSize; + +- (integer) width; +- (integer) height; + +- (void) setSize: (Size)aSize; +- (void) setWidth: (integer)_width; +- (void) setHeight: (integer)_width; + +@end + +@interface Rect: Object +{ +@public + Point origin; + Size size; +} + +- (id) initWithOrigin: (Point)_origin size: (Size)_size; +- (id) initWithComponents: (integer)x : (integer)y : (integer)w : (integer)h; +- (id) initWithRect: (Rect)aRect; +- (id) copy; + +- (BOOL) intersectsRect: (Rect)aRect; +- (BOOL) containsPoint: (Point)aPoint; +- (BOOL) containsRect: (Rect)aRect; +- (BOOL) isEqualToRect: (Rect)aRect; +- (BOOL) isEmpty; + +- (Rect) intersectionWithRect: (Rect)aRect; +- (Rect) unionWithRect: (Rect)aRect; + +- (Rect) insetBySize: (Size)aSize; + +- (Point) origin; +- (Size) size; + +- (void) setSize: (Size)aSize; + +@end + +#endif//__ruamoko_point_h diff --git a/ruamoko/include/debug.h b/ruamoko/include/debug.h index c1cc4692a..e21e27827 100644 --- a/ruamoko/include/debug.h +++ b/ruamoko/include/debug.h @@ -1,13 +1,91 @@ +/* + debug.h + + Debugging function definitions + + Copyright (C) 2002 Bill Currie + Copyright (C) 2002 Jeff Teunissen + + This file is part of the Ruamoko Standard Library. + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or (at + your option) any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + + $Id$ +*/ #ifndef __ruamoko_debug_h #define __ruamoko_debug_h -//FIXME@extern void () break; +/* + abort (in QuakeC, this was break) + + Tell the engine to abort (stop) code processing. +*/ +@extern void () abort; + +/* + error + + Abort (crash) the server. "e" is the message the server crashes with. +*/ @extern void (string e) error; + +/* + objerror + + Prints info on the "self" ENTITY (not object), and error message "e". + The entity is freed. +*/ @extern void (string e) objerror; + +/* + dprint + + Print string "e" if the developer Cvar is set to a nonzero value +*/ @extern void (string s) dprint; + +/* + coredump + + Tell the engine to print all edicts (entities) +*/ @extern void () coredump; + +/* + traceon + + Enable instruction trace in the interpreter +*/ @extern void () traceon; + +/* + traceoff + + Disable instruction trace in the interpreter +*/ @extern void () traceoff; + +/* + eprint + + Print all information on an entity to the server console +*/ @extern void (entity e) eprint; -#endif//__ruamoko_debug_h +#endif //__ruamoko_debug_h diff --git a/ruamoko/include/draw.h b/ruamoko/include/draw.h index d020732f7..16f285e8e 100644 --- a/ruamoko/include/draw.h +++ b/ruamoko/include/draw.h @@ -1,7 +1,7 @@ #ifndef __ruamoko_draw_h #define __ruamoko_draw_h -#include "object.h" +#include "Object.h" struct _qpic_t = { integer width; diff --git a/ruamoko/include/entities.h b/ruamoko/include/entities.h new file mode 100644 index 000000000..4e20cae0c --- /dev/null +++ b/ruamoko/include/entities.h @@ -0,0 +1,84 @@ +/* + entities.h + + Entity function prototypes + + Copyright (C) 2002 Bill Currie + Copyright (C) 2002 Jeff Teunissen + + This file is part of the Ruamoko Standard Library. + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or (at + your option) any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + + $Id$ +*/ +#ifndef __ruamoko_entities_h +#define __ruamoko_entities_h + +/* + setmodel + + Sets the model name for entity e to string m. + Set the entity's move type and solid type before calling this. +*/ +@extern void (entity e, string m) setmodel; + +/* + setorigin + + Sets origin for entity e to vector o. +*/ +@extern void (entity e, vector o) setorigin; + +/* + setsize + + Set the size of entity e to a cube with the bounds ( x1 y1 z1 ) ( x2 y2 z2 ) +*/ +@extern void (entity e, vector min, vector max) setsize; + +/* + spawn + + Creates a new entity and returns it. +*/ +@extern entity () spawn; + +/* + remove + + Remove entity e. +*/ +@extern void (entity e) remove; + +@extern entity (entity start, .string fld, string match) find; +@extern entity (vector org, float rad) findradius; +@extern entity (entity e) nextent; + +/* + makestatic + + Make entity e static (part of the world). + Static entities do not interact with the game. +*/ +@extern void (entity e) makestatic; + +@extern void (entity e) setspawnparms; + +#endif //__ruamoko_entities_h diff --git a/ruamoko/include/entity.h b/ruamoko/include/entity.h deleted file mode 100644 index fc9f2a21c..000000000 --- a/ruamoko/include/entity.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __ruamoko_entity_h -#define __ruamoko_entity_h - -#include "object.h" - -@interface Entity : Object -{ - entity ent; -} - --init; --initWithEntity:(entity)e; --free; - --(entity)new; --(entity)ent; -@end - -@extern void (entity e, vector o) setorigin; -@extern void (entity e, string m) setmodel; -@extern void (entity e, vector min, vector max) setsize; -@extern entity () spawn; -@extern void (entity e) remove; -@extern entity (entity start, .string fld, string match) find; -@extern entity (vector org, float rad) findradius; -@extern entity (entity e) nextent; -@extern void (entity e) makestatic; -@extern void (entity e) setspawnparms; - -#endif//__ruamoko_entity_h diff --git a/ruamoko/include/math.h b/ruamoko/include/math.h index d75969766..ebab4dd11 100644 --- a/ruamoko/include/math.h +++ b/ruamoko/include/math.h @@ -1,19 +1,126 @@ +/* + math.h + + Built-in math function definitions + + Copyright (C) 2002 Bill Currie + Copyright (C) 2002 Jeff Teunissen + + This file is part of the Ruamoko Standard Library. + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or (at + your option) any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + + $Id$ +*/ #ifndef __ruamoko_math_h #define __ruamoko_math_h +/* + random + + Generate a random number such that 0 <= num <= 1 (0 to 1 inclusive) +*/ +@extern float () random; + +/* + ftoi + + Returns the integer component of f +*/ +@extern integer (float f) ftoi; + +/* + itof + + Returns the float representation of i +*/ +@extern float (integer i) itof; + +/* + rint + + Rounds v to the nearest integer value and returns it. + rint() does not change the type. +*/ +@extern float (float v) rint; + +/* + floor + + Returns v, rounded down to the next lower integer +*/ +@extern float (float v) floor; + +/* + ceil + + Returns v, rounded up to the next highest integer +*/ +@extern float (float v) ceil; + +/* + fabs + + Returns the absolute value of v +*/ +@extern float (float f) fabs; + +/**************************************************************************** + * VECTORS * + ****************************************************************************/ + @extern vector v_forward, v_up, v_right; +/* + makevectors + + Set v_forward, v_up, v_right global vectors from the vector ang +*/ @extern void (vector ang) makevectors; -@extern float () random; -@extern integer (float f) ftoi; -@extern float (integer i) itof; + +/* + normalize + + Transform vector v into a unit vector (a vector with a length of 1). + The direction is not changed, except for (possible) roundoff errors. +*/ @extern vector (vector v) normalize; + +/* + vlen + + Return the length of vector v +*/ @extern float (vector v) vlen; + +/* + vectoyaw + + Returns the yaw angle ("bearing"), in degrees, associated with vector v. +*/ @extern float (vector v) vectoyaw; -@extern float (float v) rint; -@extern float (float v) floor; -@extern float (float v) ceil; -@extern float (float f) fabs; + +/* + vectoangles + + Returns a vector 'pitch yaw 0' corresponding to vector v. +*/ @extern vector (vector v) vectoangles; -#endif//__ruamoko_math_h +#endif //__ruamoko_math_h diff --git a/ruamoko/include/point.h b/ruamoko/include/point.h deleted file mode 100644 index 150a5c460..000000000 --- a/ruamoko/include/point.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __ruamoko_point_h -#define __ruamoko_point_h - -#include "object.h" - -@interface Point : Object -{ -@public - integer x,y; -} --initAtX:(integer)_x Y:(integer)_y; --initWithPoint:(Point)p; --setTo:(Point)p; --moveBy:(Point)p; -@end - -#endif//__ruamoko_point_h diff --git a/ruamoko/lib/Entity.r b/ruamoko/lib/Entity.r new file mode 100644 index 000000000..322d2bb01 --- /dev/null +++ b/ruamoko/lib/Entity.r @@ -0,0 +1,28 @@ +#include "Entity.h" + +@implementation Entity + +- (id) init +{ + return [self initWithEntity: spawn ()]; +} + +- (id) initWithEntity: (entity)e +{ + ent = e; + ent.@this = self; + return self; +} + +- (void) free +{ + remove (ent); + [super free]; +} + +- (entity) ent +{ + return self.ent; +} + +@end diff --git a/ruamoko/lib/inputline.r b/ruamoko/lib/InputLine.r similarity index 62% rename from ruamoko/lib/inputline.r rename to ruamoko/lib/InputLine.r index 144984c5e..6eb26cd9b 100644 --- a/ruamoko/lib/inputline.r +++ b/ruamoko/lib/InputLine.r @@ -1,4 +1,4 @@ -#include "inputline.h" +#include "InputLine.h" inputline_t (integer lines, integer size, integer prompt) InputLine_Create = #0; void (inputline_t il, void [] data) InputLine_SetUserData = 0; @@ -16,50 +16,49 @@ string (inputline_t il) InputLine_GetText = #0; @implementation InputLine --free +- (id) initWithBounds: (Rect)aRect promptCharacter: (integer)char { - [at free]; + id (self) = [super init]; + id (frame) = [aRect copy]; + + il = InputLine_Create (frame.size.height, frame.size.width, char); + InputLine_SetUserData (il, frame); + + return self; +} + +- (void) free +{ + [frame free]; InputLine_Destroy (il); - return [super free]; + [super free]; } --initAt:(Point)p HistoryLines:(integer)l LineSize:(integer)s PromptChar:(integer)prompt +- (void) setWidth: (integer)visibleWidth { - [super init]; - id(at) = [[Point alloc] initWithPoint:p]; - il = InputLine_Create (l, s, prompt); - InputLine_SetUserData (il, at); - return self; + InputLine_SetWidth (il, width); } --setWidth:(integer)visibleWidth -{ - InputLine_SetWidth (il, visibleWidth); - return self; -} - --process:(integer)key +- (void) processInput: (integer)key { InputLine_Process (il, key); - return self; } --draw:(BOOL)cursor +- (void) draw: (BOOL)cursor { #ifdef OLD_API - InputLine_Draw (il, at.x, at.y, cursor); + InputLine_Draw (il, frame.origin.x, frame.origin.y, cursor); #else InputLine_Draw (il, cursor); #endif } --setText:(string)text +- (void) setText: (string)text { InputLine_SetText (il, text); - return self; } --(string)getText +- (string) text { return InputLine_GetText (il); } diff --git a/ruamoko/lib/Makefile.am b/ruamoko/lib/Makefile.am index 6defc0dff..f488a192c 100644 --- a/ruamoko/lib/Makefile.am +++ b/ruamoko/lib/Makefile.am @@ -16,19 +16,18 @@ noinst_LIBRARIES= libr.a libgui.a libcsqc.a %.o: %.r $(QFCC) $(QCFLAGS) $(QCPPFLAGS) -p $(STRIP) -c -o $@ $< - libr_a_SOURCES=\ - crudefile.r debug.r entity.r infokey.r math.r message.r nq_message.r \ - object.r physics.r qw_message.r qw_physics.r qw_sys.r sound.r \ - string.r system.r + crudefile.r debug.r entities.r infokey.r math.r message.r nq_message.r \ + physics.r qw_message.r qw_physics.r qw_sys.r sound.r string.r system.r \ + Object.r Entity.r libr_a_AR=$(PAK) -cf libgui_a_SOURCES=\ - draw.r inputline.r key.r point.r + draw.r InputLine.r key.r Point.r libgui_a_AR=$(PAK) -cf -libcsqc_a_SOURCES=\ - cbuf.r cmd.r cvar.r file.r -libcsqc_a_AR=$(PAK) -cf +libcsqc_a_SOURCES= \ + cbuf.r cmd.r cvar.r file.r +libcsqc_a_AR= $(PAK) -cf -CLEANFILES = *.qfo +CLEANFILES= *.qfo diff --git a/ruamoko/lib/object.r b/ruamoko/lib/Object.r similarity index 99% rename from ruamoko/lib/object.r rename to ruamoko/lib/Object.r index 47e71d256..d97a156fe 100644 --- a/ruamoko/lib/object.r +++ b/ruamoko/lib/Object.r @@ -1,4 +1,4 @@ -#include "object.h" +#include "Object.h" void (obj_module_t [] msg) __obj_exec_class = #0; void (id object, integer code, string fmt, ...) obj_error = #0; diff --git a/ruamoko/lib/Point.r b/ruamoko/lib/Point.r new file mode 100644 index 000000000..ccd419d98 --- /dev/null +++ b/ruamoko/lib/Point.r @@ -0,0 +1,64 @@ +#include "Point.h" + +@implementation Point + +- (id) initWithComponents: (integer)_x : (integer)_y +{ + id (self) = [super init]; + x = _x; + y = _y; + return self; +} + +- (id) initWithPoint: (Point) aPoint +{ + id (self) = [super init]; + + if (!self || !aPoint) + return NIL; + + x = [aPoint x]; + y = [aPoint y]; + + return self; +} + +- (id) copy +{ + local id myCopy = [super copy]; + + if (!myCopy) + myCopy = [[self class] alloc]; + + return [myCopy initWithComponents: x : y]; +} + +- (id) x +{ + return x; +} + +- (id) y +{ + return y; +} + +- (void) setPoint: (Point)aPoint +{ + x = [aPoint x]; + y = [aPoint y]; +} + +- (void) addPoint: (Point) aPoint +{ + x += [aPoint x]; + y += [aPoint y]; +} + +- (void) subtractPoint: (Point) aPoint +{ + x -= [aPoint x]; + y -= [aPoint y]; +} + +@end diff --git a/ruamoko/lib/draw.r b/ruamoko/lib/draw.r index b4066b520..2bac83092 100644 --- a/ruamoko/lib/draw.r +++ b/ruamoko/lib/draw.r @@ -61,11 +61,6 @@ void (integer x, integer y, integer width, integer lines) text_box = @implementation QPic --initName:(string)n -{ - return [self initName:n Centered:NO]; -} - -initName:(string)n Centered:(BOOL)c { [super init]; @@ -76,6 +71,11 @@ void (integer x, integer y, integer width, integer lines) text_box = return self; } +-initName:(string)n +{ + return [self initName:n Centered:NO]; +} + -draw:(integer)x :(integer)y { local qpic_t pic = Draw_CachePic (name, 1); diff --git a/ruamoko/lib/entity.r b/ruamoko/lib/entities.r similarity index 58% rename from ruamoko/lib/entity.r rename to ruamoko/lib/entities.r index d8da469e5..57fd85ce4 100644 --- a/ruamoko/lib/entity.r +++ b/ruamoko/lib/entities.r @@ -1,4 +1,4 @@ -#include "entity.h" +#include "entities.h" void (entity e, vector o) setorigin = #2; void (entity e, string m) setmodel = #3; @@ -10,33 +10,3 @@ entity (vector org, float rad) findradius = #22; entity (entity e) nextent = #47; void (entity e) makestatic = #69; void (entity e) setspawnparms = #78; - -@implementation Entity --init -{ - return [self initWithEntity:[self new]]; -} - --initWithEntity:(entity)e -{ - self.ent = e; - e.@this = self; - return self; -} - --free -{ - remove (self.ent); - return [super free]; -} - --new -{ - return spawn (); -} - --ent -{ - return self.ent; -} -@end diff --git a/ruamoko/lib/point.r b/ruamoko/lib/point.r deleted file mode 100644 index f892a12fc..000000000 --- a/ruamoko/lib/point.r +++ /dev/null @@ -1,33 +0,0 @@ -#include "point.h" - -@implementation Point - --initAtX:(integer)_x Y:(integer)_y -{ - [super init]; - x = _x; - y = _y; - return self; -} - --initWithPoint:(Point)p -{ - [super init]; - x = p.x; - y = p.y; - return self; -} - --setTo:(Point)p -{ - x = p.x; - y = p.y; - return self; -} - --moveBy:(Point)p -{ - x += p.x; - y += p.y; - return self; -}