Quack 3: Arena

This commit is contained in:
Literally A Penguin
2024-09-25 15:40:36 -05:00
committed by GitHub
parent 0bf99969fd
commit 40035fa235
74 changed files with 36999 additions and 0 deletions

332
rhapsody/in_next.m Normal file
View File

@ -0,0 +1,332 @@
// in_next.m
#import <AppKit/AppKit.h>
#import <drivers/event_status_driver.h>
#include "../client/client.h"
float mousex, mousey;
float mouse_center_x = 160;
float mouse_center_y = 100;
void PSsetmouse (float x, float y);
void PSshowcursor (void);
void PShidecursor (void);
void PScurrentmouse (int win, float *x, float *y);
extern NSView *vid_view_i;
extern NSWindow *vid_window_i;
qboolean mlooking;
qboolean mouseinitialized;
int mouse_buttons;
int mouse_oldbuttonstate;
int mouseactive;
int mousereset;
int mx_accum, my_accum;
int window_center_x, window_center_y;
int old_mouse_x, old_mouse_y;
cvar_t in_mouse = {"in_mouse", "0", CVAR_ARCHIVE};
cvar_t m_filter = {"m_filter", "0", CVAR_ARCHIVE};
cvar_t freelook = {"in_freelook", "0", CVAR_ARCHIVE};
/*
===========
IN_ActivateMouse
Called when the window gains focus or changes in some way
===========
*/
void IN_ActivateMouse (void)
{
NSRect r;
if (!mouseinitialized)
return;
if (!in_mouse.value)
return;
r = [vid_window_i frame];
window_center_x = r.size.width / 2;
window_center_y = r.size.height / 2;
if (!mouseactive)
PShidecursor ();
mouseactive = true;
mousereset = true;
}
/*
===========
IN_DeactivateMouse
Called when the window loses focus
===========
*/
void IN_DeactivateMouse (void)
{
if (!mouseinitialized)
return;
if (mouseactive)
PSshowcursor ();
mouseactive = false;
}
/*
===========
IN_StartupMouse
===========
*/
void IN_StartupMouse (void)
{
if ( COM_CheckParm ("-nomouse") )
return;
mouseinitialized = true;
mouse_buttons = 3;
IN_ActivateMouse ();
}
/*
===========
IN_MouseEvent
===========
*/
void IN_MouseEvent (int mstate)
{
int i;
if (!mouseactive)
return;
// perform button actions
for (i=0 ; i<mouse_buttons ; i++)
{
if ( (mstate & (1<<i)) &&
!(mouse_oldbuttonstate & (1<<i)) )
{
Key_Event (K_MOUSE1 + i, true);
}
if ( !(mstate & (1<<i)) &&
(mouse_oldbuttonstate & (1<<i)) )
{
Key_Event (K_MOUSE1 + i, false);
}
}
mouse_oldbuttonstate = mstate;
}
/*
===========
IN_Accumulate
===========
*/
void IN_Accumulate (void)
{
int dx, dy;
static int old_x, old_y;
if (!mouseinitialized)
return;
if (in_mouse.modified)
{
in_mouse.modified = false;
IN_DeactivateMouse ();
IN_ActivateMouse ();
}
if (!mouseactive)
return;
// [vid_view_i lockFocus];
if (mousereset)
{ // we haven't centered cursor yet
mousereset = false;
}
else
{
NSPoint p;
PScurrentmouse ([vid_window_i windowNumber], &mousex, &mousey);
p.x = mousex;
p.y = mousey;
p = [vid_view_i convertPoint:p fromView: nil];
mousex = p.x;
mousey = p.y;
dx = mousex - old_x;
dy = old_y - mousey;
if (!dx && !dy)
return;
mx_accum += dx;
my_accum += dy;
}
// force the mouse to the center, so there's room to move
PSsetmouse (window_center_x, window_center_y);
PScurrentmouse ([vid_window_i windowNumber], &mousex, &mousey);
// PSsetmouse (window_center_x, window_center_y);
old_x = window_center_x;
old_y = window_center_y;
// [vid_view_i unlockFocus];
}
/*
===========
IN_MouseMove
===========
*/
void IN_MouseMove (usercmd_t *cmd)
{
int mx, my;
int mouse_x, mouse_y;
IN_Accumulate ();
mx = mx_accum;
my = my_accum;
mx_accum = 0;
my_accum = 0;
if (m_filter.value)
{
mouse_x = (mx + old_mouse_x) * 0.5;
mouse_y = (my + old_mouse_y) * 0.5;
}
else
{
mouse_x = mx;
mouse_y = my;
}
old_mouse_x = mx;
old_mouse_y = my;
if (!mx && !my)
return;
if (!mouseactive)
return;
mouse_x *= sensitivity.value;
mouse_y *= sensitivity.value;
// add mouse X/Y movement to cmd
if ( (in_strafe.state & 1) || (lookstrafe.value && mlooking ))
cmd->sidemove += m_side.value * mouse_x;
else
cl.viewangles[YAW] -= m_yaw.value * mouse_x;
if ( (mlooking || freelook.value) && !(in_strafe.state & 1))
{
cl.viewangles[PITCH] += m_pitch.value * mouse_y;
if (cl.viewangles[PITCH] > 80)
cl.viewangles[PITCH] = 80;
if (cl.viewangles[PITCH] < -70)
cl.viewangles[PITCH] = -70;
}
else
{
cmd->forwardmove -= m_forward.value * mouse_y;
}
}
void IN_ShowMouse (void)
{
PSshowcursor ();
}
void IN_HideMouse (void)
{
PShidecursor ();
}
NXEventHandle eventhandle;
NXMouseScaling oldscaling, newscaling;
NXMouseButton oldbutton;
/*
=============
IN_Init
=============
*/
void IN_Init (void)
{
Cvar_RegisterVariable (&in_mouse);
Cvar_RegisterVariable (&m_filter);
Cvar_RegisterVariable (&freelook);
Cmd_AddCommand ("showmouse", IN_ShowMouse);
Cmd_AddCommand ("hidemouse", IN_HideMouse);
IN_StartupMouse ();
// open the event status driver
eventhandle = NXOpenEventStatus();
NXGetMouseScaling (eventhandle, &oldscaling);
NXSetMouseScaling (eventhandle, &newscaling);
oldbutton = NXMouseButtonEnabled (eventhandle);
NXEnableMouseButton (eventhandle, 2);
}
/*
=============
IN_Shutdown
=============
*/
void IN_Shutdown (void)
{
IN_DeactivateMouse ();
// put mouse scaling back the way it was
NXSetMouseScaling (eventhandle, &oldscaling);
NXEnableMouseButton (eventhandle, oldbutton);
NXCloseEventStatus (eventhandle);
}
void IN_Move (usercmd_t *cmd)
{
IN_MouseMove (cmd);
}
void IN_Commands (void)
{
}
/*
=========================================================================
VIEW CENTERING
=========================================================================
*/
void V_StopPitchDrift (void)
{
cl.laststop = cl.time;
cl.nodrift = true;
cl.pitchvel = 0;
}

63
rhapsody/makefile.bak Normal file
View File

@ -0,0 +1,63 @@
CFLAGS = -O -g -DGAME_HARD_LINKED -DREF_HARD_LINKED
LDFLAGS = -sectcreate __ICON __header quake2.iconheader -segprot __ICON r r -sectcreate __ICON app quake2.tiff -framework AppKit -framework Foundation
EXE = quake2
TARGETS = $(EXE)
all: $(TARGETS)
#----------------------------------------------------------------------
SERVERFILES = sv_ccmds.o sv_ents.o sv_game.o sv_init.o sv_main.o sv_send.o sv_user.o sv_world.o
GAMEFILES = g_ai.o g_cmds.o g_combat.o g_func.o g_items.o g_main.o g_misc.o g_monster.o g_phys.o g_save.o g_spawn.o g_target.o g_trigger.o g_utils.o g_weapon.o g_turret.o m_actor.o m_berserk.o m_boss2.o m_boss3.o m_boss31.o m_boss32.o m_brain.o m_chick.o m_flipper.o m_float.o m_flyer.o m_gladiator.o m_gunner.o m_hover.o m_infantry.o m_insane.o m_medic.o m_move.o m_mutant.o m_parasite.o m_soldier.o m_supertank.o m_tank.o p_client.o p_hud.o p_trail.o p_view.o p_weapon.o
CLIENTFILES = cl_ents.o cl_fx.o cl_input.o cl_inv.o cl_main.o cl_parse.o cl_pred.o cl_scrn.o cl_cin.o cl_tent.o cl_view.o console.o keys.o menu.o qmenu.o snd_dma.o snd_mem.o snd_mix.o
# commonfiles are used by both client and server
COMMONFILES = m_flash.o cmd.o cmodel.o common.o cvar.o files.o md4.o net_chan.o net_udp.o pmove.o
REFGLFILES = gl_draw.o gl_light.o gl_mesh.o gl_model.o gl_rmain.o gl_rmisc.o gl_rsurf.o gl_warp.o gl_image.o
REFSOFTFILES = r_aclip.o r_alias.o r_bsp.o r_draw.o r_edge.o r_image.o r_light.o r_main.o r_misc.o r_model.o r_part.o r_polyse.o r_poly.o r_rast.o r_scan.o r_sprite.o r_surf.o
# sharedfiles are included in EVERY dll
SHAREDFILES = q_shared.o
IRIXFILES = cd_sgi.o glx_imp.o qgl_sgi.o sys_sgi.o vid_sgi.o in_sgi.o snddma_null.o
RHAPFILES = cd_null.o in_null.o snddma_null.o sys_rhap.o vid_null.o swimp_rhap.o
NULLFILES = cd_null.o in_null.o snddma_null.o sys_null.o vid_null.o swimp_null.o
#----------------------------------------------------------------------
FILES = $(SERVERFILES) $(GAMEFILES) $(COMMONFILES) $(CLIENTFILES) $(REFSOFTFILES) $(SHAREDFILES) $(RHAPFILES)
$(EXE) : $(FILES)
cc -o $(EXE) $(FILES) $(LDFLAGS)
clean:
rm -f $(EXE) $(FILES)
#----------------------------------------------------------------------
# gnumake pattern rules are so cool!
%.o : ../game/%.c
cc $(CFLAGS) -c -o $@ $?
%.o : ../qcommon/%.c
cc $(CFLAGS) -c -o $@ $?
%.o : ../client/%.c
cc $(CFLAGS) -c -o $@ $?
%.o : ../server/%.c
cc $(CFLAGS) -c -o $@ $?
%.o : ../ref_soft/%.c
cc $(CFLAGS) -c -o $@ $?
%.o : ../ref_gl/%.c
cc $(CFLAGS) -c -o $@ $?
%.o : ../null/%.c
cc $(CFLAGS) -c -o $@ $?
%.o : ../rhapsody/%.m
cc $(CFLAGS) -c -o $@ $?

34
rhapsody/notes.txt Normal file
View File

@ -0,0 +1,34 @@
f1
not calling back to set vid size after sw_mode change?
do vid_xpos / ypos creep because of frames?
fix fullscreen fallback bug
nsping
icon
don't make sys_error varargs
cvar_stvalue in ref????
subframe event timing information
swimp init / swimp_initgraphics?
SWimp_SetMode shouldn't call
R_GammaCorrectAndSetPalette( ( const unsigned char * ) d_8to24table );
subclass window instead of view?
/*
** SWimp_SetPalette
**
** System specific palette setting routine. A NULL palette means
** to use the existing palette. The palette is expected to be in
** a padded 4-byte xRGB format.
*/
do we ever pass a NULL palette?

17
rhapsody/pb.project Normal file
View File

@ -0,0 +1,17 @@
{
DYNAMIC_CODE_GEN = YES;
FILESTABLE = {
FRAMEWORKS = (Foundation.framework);
OTHER_LINKED = (QuakeWorld_main.m);
OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, m.template, h.template);
};
LANGUAGE = English;
LOCALIZABLE_FILES = {};
MAKEFILEDIR = "$(NEXT_ROOT)/NextDeveloper/Makefiles/pb_makefiles";
NEXTSTEP_BUILDTOOL = /bin/gnumake;
PDO_UNIX_BUILDTOOL = $NEXT_ROOT/NextDeveloper/bin/make;
PROJECTNAME = QuakeWorld;
PROJECTTYPE = Tool;
PROJECTVERSION = 2.6;
WINDOWS_BUILDTOOL = $NEXT_ROOT/NextDeveloper/Executables/make;
}

View File

@ -0,0 +1,2 @@
F test.app test app
F test test app

BIN
rhapsody/quake2.tiff Normal file

Binary file not shown.

735
rhapsody/r_next.m Normal file
View File

@ -0,0 +1,735 @@
#import <AppKit/AppKit.h>
#include "../ref_soft/r_local.h"
/*
====================================================================
OPENSTEP specific stuff
====================================================================
*/
@interface QuakeView : NSView
@end
NSWindow *vid_window_i;
QuakeView *vid_view_i;
unsigned *buffernative;
//===========================================================
int Draw_SetResolution (void);
#define TYPE_FULLSCREEN 0
#define TYPE_WINDOWED 1
#define TYPE_STRETCHED 2
#define NUM_RESOLUTIONS 7
int resolutions[NUM_RESOLUTIONS][2] = {
{320,200}, {320,240}, {400,300}, {512,384}, {640,480}, {800,600}, {1024,768} };
qboolean available[NUM_RESOLUTIONS][3];
int mode_res = 0, mode_type = TYPE_WINDOWED;
byte gammatable[256]; // palette is sent through this
unsigned current_palette[256];
unsigned gamma_palette[256];
int cursor_res, cursor_type;
cvar_t *vid_x;
cvar_t *vid_y;
cvar_t *vid_mode;
cvar_t *vid_stretched;
cvar_t *vid_fullscreen;
cvar_t *draw_gamma;
void Draw_BuildGammaTable (void);
/*
====================================================================
MENU INTERACTION
====================================================================
*/
void FindModes (void)
{
if (mode_res < 0 || mode_res >= NUM_RESOLUTIONS)
mode_res = 0;
if (mode_type < 0 || mode_type > 3)
mode_type = 1;
}
void RM_Print (int x, int y, char *s)
{
while (*s)
{
Draw_Char (x, y, (*s)+128);
s++;
x += 8;
}
}
/*
================
Draw_MenuDraw
================
*/
void Draw_MenuDraw (void)
{
int i, j;
int y;
char string[32];
Draw_Pic ( 4, 4, "vidmodes");
RM_Print (80, 32, "fullscreen windowed stretched");
RM_Print (80, 40, "---------- -------- ---------");
y = 50;
// draw background behind selected mode
Draw_Fill ( (mode_type+1)*80, y+(mode_res)*10, 40,10, 8);
// draw available grid
for (i=0 ; i<NUM_RESOLUTIONS ; i++, y+= 10)
{
sprintf (string, "%ix%i", resolutions[i][0], resolutions[i][1]);
RM_Print (0, y, string);
for (j=0 ; j<3 ; j++)
if (available[i][j])
RM_Print ( 80 + j*80, y, "*");
}
// draw the cursor
Draw_Char (80 + cursor_type*80, 50 + cursor_res*10, 128 + 12+((int)(r_newrefdef.time*4)&1));
}
#define K_TAB 9
#define K_ENTER 13
#define K_ESCAPE 27
#define K_SPACE 32
// normal keys should be passed as lowercased ascii
#define K_BACKSPACE 127
#define K_UPARROW 128
#define K_DOWNARROW 129
#define K_LEFTARROW 130
#define K_RIGHTARROW 131
/*
================
Draw_MenuKey
================
*/
void Draw_MenuKey (int key)
{
switch (key)
{
case K_LEFTARROW:
cursor_type--;
if (cursor_type < 0)
cursor_type = 2;
break;
case K_RIGHTARROW:
cursor_type++;
if (cursor_type > 2)
cursor_type = 0;
break;
case K_UPARROW:
cursor_res--;
if (cursor_res < 0)
cursor_res = NUM_RESOLUTIONS-1;
break;
case K_DOWNARROW:
cursor_res++;
if (cursor_res >= NUM_RESOLUTIONS)
cursor_res = 0;
break;
case K_ENTER:
ri.Cmd_ExecuteText (EXEC_NOW, va("vid_mode %i", cursor_res));
switch (cursor_type)
{
case TYPE_FULLSCREEN:
ri.Cmd_ExecuteText (EXEC_NOW, "vid_fullscreen 1");
ri.Cmd_ExecuteText (EXEC_NOW, "vid_stretched 0");
break;
case TYPE_WINDOWED:
ri.Cmd_ExecuteText (EXEC_NOW, "vid_fullscreen 0");
ri.Cmd_ExecuteText (EXEC_NOW, "vid_stretched 0");
break;
case TYPE_STRETCHED:
ri.Cmd_ExecuteText (EXEC_NOW, "vid_fullscreen 0");
ri.Cmd_ExecuteText (EXEC_NOW, "vid_stretched 1");
break;
}
mode_res = cursor_res;
mode_type = cursor_type;
Draw_SetResolution ();
break;
default:
break;
}
}
//===========================================================
/*
================
Draw_SetResolution
The vid structure will be filled in on return
Also allocates the z buffer and surface cache
================
*/
int Draw_SetResolution (void)
{
NSRect content;
if (vid_mode->value < 0)
ri.Cmd_ExecuteText (EXEC_NOW, "vid_mode 0");
if (vid_mode->value >= NUM_RESOLUTIONS)
ri.Cmd_ExecuteText (EXEC_NOW, va("vid_mode %i", NUM_RESOLUTIONS-1));
vid_mode->modified = false;
vid_fullscreen->modified = false;
vid_stretched->modified = false;
// free nativebuffer
if (buffernative)
{
free (buffernative);
buffernative = NULL;
}
// free z buffer
if (d_pzbuffer)
{
free (d_pzbuffer);
d_pzbuffer = NULL;
}
// free surface cache
if (sc_base)
{
D_FlushCaches ();
free (sc_base);
sc_base = NULL;
}
vid.width = resolutions[(int)(vid_mode->value)][0];
vid.height = resolutions[(int)(vid_mode->value)][1];
vid.win_width = vid.width;
vid.win_height = vid.height;
if (vid_stretched->value)
{
vid.win_width <<= 1;
vid.win_height <<= 1;
}
vid.aspect = 1;
vid.buffer = malloc (vid.width*vid.height);
vid.rowbytes = vid.width;
d_pzbuffer = malloc(vid.width*vid.height*2);
buffernative = malloc(vid.width*vid.height*4);
D_InitCaches ();
Sys_SetPalette ((byte *)d_8to24table);
if (vid_view_i)
[vid_view_i unlockFocus];
if (vid_window_i)
[vid_window_i close];
//
// open a window
//
content = NSMakeRect (vid_x->value,vid_y->value,vid.win_width, vid.win_height);
vid_window_i = [[NSWindow alloc]
initWithContentRect: content
styleMask: NSTitledWindowMask
backing: NSBackingStoreRetained
defer: NO
];
[vid_window_i setDelegate: vid_window_i];
[vid_window_i display];
[NSApp activateIgnoringOtherApps: YES];
[vid_window_i makeKeyAndOrderFront: nil];
// NSPing ();
content.origin.x = content.origin.y = 0;
vid_view_i = [[QuakeView alloc] initWithFrame: content];
[vid_window_i setContentView: vid_view_i];
[vid_window_i makeFirstResponder: vid_view_i];
[vid_window_i setDelegate: vid_view_i];
// [vid_window_i addToEventMask: NS_FLAGSCHANGEDMASK];
[vid_window_i setTitle: @"Bitmap Quake Console"];
[vid_window_i makeKeyAndOrderFront: nil];
// leave focus locked forever
[vid_view_i lockFocus];
ri.VID_SetSize (vid.width, vid.height);
return 0;
}
/*
@@@@@@@@@@@@@@@@@@@@@
Draw_Init
@@@@@@@@@@@@@@@@@@@@@
*/
int Draw_Init (void *window)
{
[NSApplication sharedApplication];
[NSApp finishLaunching];
ri.Con_Printf (PRINT_ALL, "refresh version: "REF_VERSION"\n");
vid_x = ri.Cvar_Get ("vid_x", "0", CVAR_ARCHIVE);
vid_y = ri.Cvar_Get ("vid_y", "0", CVAR_ARCHIVE);
vid_mode = ri.Cvar_Get ("vid_mode", "0", CVAR_ARCHIVE);
vid_fullscreen = ri.Cvar_Get ("vid_fullscreen", "0", CVAR_ARCHIVE);
vid_stretched = ri.Cvar_Get ("vid_stretched", "0", CVAR_ARCHIVE);
draw_gamma = ri.Cvar_Get ("gamma", "1", CVAR_ARCHIVE);
Draw_GetPalette ();
Draw_BuildGammaTable ();
// get the lighting colormap
ri.FS_LoadFile ("gfx/colormap.lmp", (void **)&vid.colormap);
if (!vid.colormap)
{
ri.Con_Printf (PRINT_ALL, "ERROR: Couldn't load gfx/colormap.lmp");
return -1;
}
Draw_SetResolution ();
R_Init ();
return 0;
}
/*
@@@@@@@@@@@@@@@@@@@@@
Draw_Shutdown
@@@@@@@@@@@@@@@@@@@@@
*/
void Draw_Shutdown (void)
{
R_Shutdown ();
}
/*
@@@@@@@@@@@@@@@@@@@@@
Draw_BuildGammaTable
@@@@@@@@@@@@@@@@@@@@@
*/
void Draw_BuildGammaTable (void)
{
int i, inf;
float g;
draw_gamma->modified = false;
g = draw_gamma->value;
if (g == 1.0)
{
for (i=0 ; i<256 ; i++)
gammatable[i] = i;
return;
}
for (i=0 ; i<256 ; i++)
{
inf = 255 * pow ( (i+0.5)/255.5 , g ) + 0.5;
if (inf < 0)
inf = 0;
if (inf > 255)
inf = 255;
gammatable[i] = inf;
}
}
/*
@@@@@@@@@@@@@@@@@@@@@
Draw_BeginFram
@@@@@@@@@@@@@@@@@@@@@
*/
void Draw_BeginFrame (void)
{
if (vid_mode->modified || vid_fullscreen->modified
|| vid_stretched->modified)
Draw_SetResolution ();
if (draw_gamma->modified)
{
Draw_BuildGammaTable ();
Sys_SetPalette ((byte *)current_palette);
}
// MGL_beginDirectAccess();
// vid.buffer = mgldc->surface;
// vid.rowbytes = mgldc->mi.bytesPerLine;
}
/*
@@@@@@@@@@@@@@@@@@@@@
Draw_EndFrame
@@@@@@@@@@@@@@@@@@@@@
*/
void Draw_EndFrame (void)
{
int i, c;
int bps, spp, bpp, bpr;
unsigned char *planes[5];
NSRect bounds;
// translate to 24 bit color
c = vid.width*vid.height;
for (i=0 ; i<c ; i++)
buffernative[i] = gamma_palette[vid.buffer[i]];
bps = 8;
spp = 3;
bpp = 32;
bpr = vid.width * 4;
planes[0] = (unsigned char *)buffernative;
bounds = [vid_view_i bounds];
NSDrawBitmap(
bounds,
vid.width,
vid.height,
bps,
spp,
bpp,
bpr,
NO,
NO,
@"NSDeviceRGBColorSpace",
planes
);
}
//===============================================================================
#define HUNK_MAGIC 0xffaffaff
typedef struct
{
int magic;
int length;
int pad[6];
} hunkheader_t;
hunkheader_t *membase;
int maxsize;
int cursize;
void *Hunk_Begin (void)
{
kern_return_t r;
// reserve a huge chunk of memory, but don't commit any yet
maxsize = 16*1024*1024;
cursize = 0;
membase = NULL;
r = vm_allocate(task_self(), (vm_address_t *)&membase, maxsize, 1);
if (!membase || r != KERN_SUCCESS)
ri.Sys_Error (ERR_FATAL,"vm_allocate failed");
membase->magic = HUNK_MAGIC;
membase->length = maxsize;
cursize = 32;
return (void *)((byte *)membase + cursize);
}
void *Hunk_Alloc (int size)
{
// round to cacheline
size = (size+31)&~31;
cursize += size;
if (cursize > maxsize)
ri.Sys_Error (ERR_DROP, "Hunk_Alloc overflow");
memset ((byte *)membase+cursize-size,0,size);
return (void *)((byte *)membase+cursize-size);
}
int Hunk_End (void)
{
kern_return_t r;
// round to pagesize
cursize = (cursize+vm_page_size)&~(vm_page_size-1);
membase->length = cursize;
r = vm_deallocate(task_self(),
(vm_address_t)((byte *)membase + cursize),
maxsize - cursize);
if ( r != KERN_SUCCESS )
ri.Sys_Error (ERR_DROP, "vm_deallocate failed");
return cursize;
}
void Hunk_Free (void *base)
{
hunkheader_t *h;
kern_return_t r;
h = ((hunkheader_t *)base) - 1;
if (h->magic != HUNK_MAGIC)
ri.Sys_Error (ERR_FATAL, "Hunk_Free: bad magic");
r = vm_deallocate(task_self(), (vm_address_t)h, h->length);
if ( r != KERN_SUCCESS )
ri.Sys_Error (ERR_DROP, "vm_deallocate failed");
}
/*
================
Sys_MakeCodeWriteable
================
*/
void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
{
}
/*
================
Sys_SetPalette
================
*/
void Sys_SetPalette (byte *palette)
{
byte *p;
int i;
memcpy (current_palette, palette, sizeof(current_palette));
p = (byte *)gamma_palette;
// gamma correct and byte swap
for (i=0 ; i<256 ; i++, p+=4, palette+=4)
{
p[0] = gammatable[palette[0]];
p[1] = gammatable[palette[1]];
p[2] = gammatable[palette[2]];
p[3] = 0xff;
}
}
/*
==========================================================================
NEXTSTEP VIEW CLASS
==========================================================================
*/
#include "../client/keys.h"
void IN_ActivateMouse (void);
void IN_DeactivateMouse (void);
@implementation QuakeView
-(BOOL) acceptsFirstResponder
{
return YES;
}
- (void)windowDidMove: (NSNotification *)note
{
NSRect r;
r = [vid_window_i frame];
ri.Cmd_ExecuteText (EXEC_NOW, va("vid_x %i", (int)r.origin.x+1));
ri.Cmd_ExecuteText (EXEC_NOW, va("vid_y %i", (int)r.origin.y+1));
}
- (void)becomeKeyWindow
{
IN_ActivateMouse ();
}
- (void)resignKeyWindow
{
IN_DeactivateMouse ();
}
typedef struct
{
int source, dest;
} keymap_t;
keymap_t keymaps[] =
{
{103, K_RIGHTARROW},
{102, K_LEFTARROW},
{100, K_UPARROW},
{101, K_DOWNARROW},
{59, K_F1},
{60, K_F2},
{61, K_F3},
{62, K_F4},
{63, K_F5},
{64, K_F6},
{65, K_F7},
{66, K_F8},
{67, K_F9},
{68, K_F10},
{87, K_F11},
{88, K_F12},
{-1,-1}
};
keymap_t flagmaps[] =
{
{NSShiftKeyMask, K_SHIFT},
{NSControlKeyMask, K_CTRL},
{NSAlternateKeyMask, K_ALT},
{NSCommandKeyMask, K_ALT},
{-1,-1}
};
- (void)mouseDown:(NSEvent *)theEvent
{
Key_Event (K_MOUSE1, true);
}
- (void)mouseUp:(NSEvent *)theEvent
{
Key_Event (K_MOUSE1, false);
}
- (void)rightMouseDown:(NSEvent *)theEvent
{
Key_Event (K_MOUSE2, true);
}
- (void)rightMouseUp:(NSEvent *)theEvent
{
Key_Event (K_MOUSE2, false);
}
/*
===================
keyboard methods
===================
*/
- (void)keyDown:(NSEvent *)theEvent
{
int ch;
keymap_t *km;
// PSobscurecursor ();
// check for non-ascii first
ch = [theEvent keyCode];
for (km=keymaps;km->source!=-1;km++)
if (ch == km->source)
{
Key_Event (km->dest, true);
return;
}
ch = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
if (ch >= 'A' && ch <= 'Z')
ch += 'a' - 'A';
if (ch>=256)
return;
Key_Event (ch, true);
}
- (void)flagsChanged:(NSEvent *)theEvent
{
static int oldflags;
int newflags;
int delta;
keymap_t *km;
int i;
// PSobscurecursor ();
newflags = [theEvent modifierFlags];
delta = newflags ^ oldflags;
for (i=0 ; i<32 ; i++)
{
if ( !(delta & (1<<i)))
continue;
// changed
for (km=flagmaps;km->source!=-1;km++)
if ( (1<<i) == km->source)
{
if (newflags & (1<<i))
Key_Event (km->dest, true);
else
Key_Event (km->dest, false);
}
}
oldflags = newflags;
}
- (void)keyUp:(NSEvent *)theEvent
{
int ch;
keymap_t *km;
// check for non-ascii first
ch = [theEvent keyCode];
for (km=keymaps;km->source!=-1;km++)
if (ch == km->source)
{
Key_Event (km->dest, false);
return;
}
ch = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
if (ch >= 'A' && ch <= 'Z')
ch += 'a' - 'A';
if (ch>=256)
return;
Key_Event (ch, false);
}
@end

36
rhapsody/rhapqw.txt Normal file
View File

@ -0,0 +1,36 @@
Put this QuakeWorld executable in a directory with the registered quake and QuakeWorld files. You should be able to launch it from the workspace or the command line.
The sound is a bit lagged and will likely drift on longer games, because I am using the system timer to calculate sample position. This will need to be fixed at some point.
There is no assembly language in yet, and it is still just using DPS to draw, so it isn't real fast yet. Run it on a ppro with a write combining video driver.
If you ever lose your mouse cursor inapropriately due to the game messing up, if you can restart QuakeWorld, you can type "showmouse" to bump the visibility counter by one.
You should eb able to connect to any QuakeWorld server, but you will have to do it with manual connect commands at the console, because we don't have either qspy or a browser plugin (yet) for openstep to find servers.
Because the configuration ranges are different than windows, things like sensitivity and volume will need to be specified at the console.
Some typical values (all of these should be saved automatically in the config file):
vid_mode 1
Sets 320*240 resolution. 320*200 (vid_mode 0) is somewhat faster, but looks scrunched at some desktop resolutions.
vid_stretched 1
Sets pixel doubling. Slower, of cource.
snd_mixahead 0.2
Because this isn't very fast yet, you probably want to increase the mixahead from 0.1 so the sound doesn't break up.
volume 0.15
The default 0.7 is VERY loud on my system. I don't know what it will be like on other systems.
gamma 1.4
Because openstep desktops are typically gamma corrected, the game will look washed out with default settings. Geater than 1.0 gets darker, less than gets brighter.
sensitivity 20
The normal slider range probably doesn't give enough speed for most people.
in_mouse 0
The mouse is normally grabbed for controlling the game. Setting this to 0 will give the mouse back to the desktop.

2151
rhapsody/snd_next.m Normal file

File diff suppressed because it is too large Load Diff

580
rhapsody/swimp_rhap.m Normal file
View File

@ -0,0 +1,580 @@
#import <AppKit/AppKit.h>
#import <Interceptor/NSDirectScreen.h>
#import <AppKit/NSColor.h>
#include "../ref_soft/r_local.h"
@interface QuakeView : NSView
@end
NSWindow *vid_window_i;
QuakeView *vid_view_i;
NSDirectScreen *vid_screen;
byte *vid_buffer; // real framebuffer
int vid_rowbytes; // framebuffer rowbytes
unsigned *buffernative; // 24 bit off-screen back buffer for window
unsigned swimp_palette[256];
typedef enum {
rhap_shutdown,
rhap_windowed,
rhap_fullscreen
} rhapMode_t;
rhapMode_t rhap_mode;
/*
=======================================================================
FULLSCREEN
=======================================================================
*/
/*
** InitFullscreen
*/
rserr_t InitFullscreen (int width, int height)
{
NSDictionary *mode, *bestMode;
int modeWidth, bestWidth;
int modeHeight, bestHeight;
NSArray *modes;
int i;
NSString *string;
vid_screen = [[NSDirectScreen alloc] initWithScreen:[NSScreen mainScreen]];
// search for an apropriate mode
modes = [vid_screen availableDisplayModes];
bestMode = NULL;
bestWidth = 99999;
bestHeight = 99999;
for (i=0 ; i<[modes count] ; i++) {
mode = [modes objectAtIndex: i];
string = [mode objectForKey: @"NSDirectScreenPixelEncoding"];
if ( ![string isEqualToString: @"PPPPPPPP"] )
continue; // only look at paletted modes
modeWidth = [[mode objectForKey: @"NSDirectScreenWidth"] intValue];
modeHeight = [[mode objectForKey: @"NSDirectScreenHeight"] intValue];
if (modeWidth < width || modeHeight < height)
continue;
if (modeWidth < bestWidth) {
bestWidth = modeWidth;
bestHeight = modeHeight;
bestMode = mode;
}
}
// if there wasn't any paletted mode of that res or greater, fail
if (!bestMode)
return rserr_invalid_fullscreen;
ri.Con_Printf (PRINT_ALL, "SheildDisplay\n");
[vid_screen shieldDisplay];
// hide the cursor in all fullscreen modes
[NSCursor hide];
vid_window_i = [vid_screen shieldingWindow];
ri.Con_Printf (PRINT_ALL, "switchToDisplayMode\n");
[vid_screen switchToDisplayMode:bestMode];
// [vid_screen fadeDisplayOutToColor:[NSColor blackColor]];
// [vid_screen fadeDisplayInFromColor:[NSColor blackColor]];
vid_buffer = [vid_screen data];
vid_rowbytes = [vid_screen bytesPerRow];
return rserr_ok;
}
void ShutdownFullscreen (void)
{
[vid_screen dealloc];
[NSCursor unhide];
}
void SetPaletteFullscreen (const unsigned char *palette) {
#if 0
byte *p;
int i;
NSDirectPalette *pal;
pal = [NSDirectPalette init];
for (i=0 ; i<256 ; i++)
[pal setRed: palette[0]*(1.0/255)
green: palette[1]*(1.0/255)
blue: palette[2]*(1.0/255)
atIndex: i];
[vid_screen setPalette: pal];
[pal release];
#endif
}
void BlitFullscreen (void)
{
int i, j;
int w;
int *dest, *source;
w = vid.width>>2;
source = (int *)vid.buffer; // off-screen buffer
dest = (int *)vid_buffer; // directly on screen
for (j=0 ; j<vid.height ; j++
, source += (vid.rowbytes>>2), dest += (vid_rowbytes>>2) ) {
for (i=0 ; i<w ; i++ ) {
dest[i] = source[i];
}
}
}
/*
=======================================================================
WINDOWED
=======================================================================
*/
/*
** InitWindowed
*/
rserr_t InitWindowed (int width, int height)
{
rserr_t retval = rserr_ok;
NSRect content;
cvar_t *vid_xpos;
cvar_t *vid_ypos;
//
// open a window
//
vid_xpos = ri.Cvar_Get ("vid_xpos", "0", 0);
vid_ypos = ri.Cvar_Get ("vid_ypos", "0", 0);
content = NSMakeRect (vid_xpos->value,vid_ypos->value, width, height);
vid_window_i = [[NSWindow alloc]
initWithContentRect: content
styleMask: NSTitledWindowMask
backing: NSBackingStoreRetained
defer: NO
];
// [vid_window_i addToEventMask: NS_FLAGSCHANGEDMASK];
[vid_window_i setTitle: @"Quake2"];
buffernative = malloc(width * height * 4);
return retval;
}
void ShutdownWindowed (void)
{
if (vid_window_i)
{
[vid_window_i release];
vid_window_i = NULL;
}
if (buffernative)
{
free (buffernative);
buffernative = NULL;
}
}
void SetPaletteWindowed (const unsigned char *palette) {
byte *p;
int i;
p = (byte *)swimp_palette;
for (i=0 ; i<256 ; i++, p+=4, palette+=4)
{
p[0] = palette[0];
p[1] = palette[1];
p[2] = palette[2];
p[3] = 0xff;
}
}
void BlitWindowed (void)
{
int i, c;
int bps, spp, bpp, bpr;
unsigned char *planes[5];
NSRect bounds;
if (!vid_view_i)
return;
// translate to 24 bit color
c = vid.width*vid.height;
for (i=0 ; i<c ; i++)
buffernative[i] = swimp_palette[vid.buffer[i]];
bps = 8;
spp = 3;
bpp = 32;
bpr = vid.width * 4;
planes[0] = (unsigned char *)buffernative;
bounds = [vid_view_i bounds];
[vid_view_i lockFocus];
NSDrawBitmap(
bounds,
vid.width,
vid.height,
bps,
spp,
bpp,
bpr,
NO,
NO,
@"NSDeviceRGBColorSpace",
planes
);
[vid_view_i unlockFocus];
PSWait ();
}
//======================================================================
/*
** RW_IMP.C
**
** This file contains ALL Win32 specific stuff having to do with the
** software refresh. When a port is being made the following functions
** must be implemented by the port:
**
** SWimp_EndFrame
** SWimp_Init
** SWimp_SetPalette
** SWimp_Shutdown
*/
/*
** SWimp_Init
**
** This routine is responsible for initializing the implementation
** specific stuff in a software rendering subsystem.
*/
int SWimp_Init( void *hInstance, void *wndProc )
{
if (!NSApp)
{
[NSApplication sharedApplication];
[NSApp finishLaunching];
}
return true;
}
/*
** SWimp_SetMode
*/
rserr_t SWimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen)
{
const char *win_fs[] = { "W", "FS" };
NSRect content;
rserr_t ret;
// free resources in use
SWimp_Shutdown ();
ri.Con_Printf (PRINT_ALL, "setting mode %d:", mode );
if ( !ri.Vid_GetModeInfo( pwidth, pheight, mode ) )
{
ri.Con_Printf( PRINT_ALL, " invalid mode\n" );
return rserr_invalid_mode;
}
ri.Con_Printf( PRINT_ALL, " %d %d %s\n", *pwidth, *pheight, win_fs[fullscreen] );
vid.buffer = malloc(*pwidth * *pheight);
vid.rowbytes = *pwidth;
if (fullscreen) {
rhap_mode = rhap_fullscreen;
ret = InitFullscreen (*pwidth, *pheight);
} else {
rhap_mode = rhap_windowed;
ret = InitWindowed (*pwidth, *pheight);
}
if (ret != rserr_ok) {
SWimp_Shutdown ();
return ret;
}
/*
** the view is identical in windowed and fullscreen modes
*/
content.origin.x = content.origin.y = 0;
content.size.width = *pwidth;
content.size.height = *pheight;
vid_view_i = [[QuakeView alloc] initWithFrame: content];
[vid_window_i setContentView: vid_view_i];
[vid_window_i makeFirstResponder: vid_view_i];
[vid_window_i setDelegate: vid_view_i];
[NSApp activateIgnoringOtherApps: YES];
[vid_window_i makeKeyAndOrderFront: nil];
[vid_window_i display];
return ret;
}
/*
** SWimp_Shutdown
**
** System specific graphics subsystem shutdown routine
*/
void SWimp_Shutdown( void )
{
if (rhap_mode == rhap_windowed)
ShutdownWindowed ();
else if (rhap_mode == rhap_fullscreen)
ShutdownFullscreen ();
rhap_mode = rhap_shutdown;
if (vid.buffer)
{
free (vid.buffer);
vid.buffer = NULL;
}
}
/*
** SWimp_SetPalette
**
** System specific palette setting routine. A NULL palette means
** to use the existing palette. The palette is expected to be in
** a padded 4-byte xRGB format.
*/
void SWimp_SetPalette( const unsigned char *palette )
{
if (rhap_mode == rhap_windowed)
SetPaletteWindowed (palette);
else if (rhap_mode == rhap_fullscreen)
SetPaletteFullscreen (palette);
}
/*
** SWimp_EndFrame
**
** This does an implementation specific copy from the backbuffer to the
** front buffer. In the Win32 case it uses BitBlt or BltFast depending
** on whether we're using DIB sections/GDI or DDRAW.
*/
void SWimp_EndFrame (void)
{
if (rhap_mode == rhap_windowed)
BlitWindowed ();
else if (rhap_mode == rhap_fullscreen)
BlitFullscreen ();
}
/*
** SWimp_AppActivate
*/
void SWimp_AppActivate( qboolean active )
{
}
/*
==========================================================================
NEXTSTEP VIEW CLASS
==========================================================================
*/
#include "../client/keys.h"
void IN_ActivateMouse (void);
void IN_DeactivateMouse (void);
@implementation QuakeView
-(BOOL) acceptsFirstResponder
{
return YES;
}
- (void)windowDidMove: (NSNotification *)note
{
NSRect r;
r = [vid_window_i frame];
ri.Cmd_ExecuteText (EXEC_NOW, va("vid_xpos %i", (int)r.origin.x+1));
ri.Cmd_ExecuteText (EXEC_NOW, va("vid_ypos %i", (int)r.origin.y+1));
}
- (void)becomeKeyWindow
{
IN_ActivateMouse ();
}
- (void)resignKeyWindow
{
IN_DeactivateMouse ();
}
typedef struct
{
int source, dest;
} keymap_t;
keymap_t keymaps[] =
{
{0xf703, K_RIGHTARROW},
{0xf702, K_LEFTARROW},
{0xf700, K_UPARROW},
{0xf701, K_DOWNARROW},
{0xf704, K_F1},
{0xf705, K_F2},
{0xf706, K_F3},
{0xf707, K_F4},
{0xf708, K_F5},
{0xf709, K_F6},
{0xf70a, K_F7},
{0xf70b, K_F8},
{0xf70c, K_F9},
{0xf70d, K_F10},
{0xf70e, K_F11},
{0xf70f, K_F12},
{-1,-1}
};
keymap_t flagmaps[] =
{
{NSShiftKeyMask, K_SHIFT},
{NSControlKeyMask, K_CTRL},
{NSAlternateKeyMask, K_ALT},
{NSCommandKeyMask, K_ALT},
{-1,-1}
};
- (void)mouseDown:(NSEvent *)theEvent
{
Key_Event (K_MOUSE1, true, 0);
}
- (void)mouseUp:(NSEvent *)theEvent
{
Key_Event (K_MOUSE1, false, 0);
}
- (void)rightMouseDown:(NSEvent *)theEvent
{
Key_Event (K_MOUSE2, true, 0);
}
- (void)rightMouseUp:(NSEvent *)theEvent
{
Key_Event (K_MOUSE2, false, 0);
}
/*
===================
keyboard methods
===================
*/
- (void)keyDown:(NSEvent *)theEvent
{
int ch;
keymap_t *km;
// PSobscurecursor ();
ch = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
// check for non-ascii first
for (km=keymaps;km->source!=-1;km++)
if (ch == km->source)
{
Key_Event (km->dest, true, 0);
return;
}
if (ch >= 'A' && ch <= 'Z')
ch += 'a' - 'A';
if (ch>=256)
return;
Key_Event (ch, true, 0);
}
- (void)flagsChanged:(NSEvent *)theEvent
{
static int oldflags;
int newflags;
int delta;
keymap_t *km;
int i;
// PSobscurecursor ();
newflags = [theEvent modifierFlags];
delta = newflags ^ oldflags;
for (i=0 ; i<32 ; i++)
{
if ( !(delta & (1<<i)))
continue;
// changed
for (km=flagmaps;km->source!=-1;km++)
if ( (1<<i) == km->source)
{
if (newflags & (1<<i))
Key_Event (km->dest, true, 0);
else
Key_Event (km->dest, false, 0);
}
}
oldflags = newflags;
}
- (void)keyUp:(NSEvent *)theEvent
{
int ch;
keymap_t *km;
ch = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
// check for non-ascii first
for (km=keymaps;km->source!=-1;km++)
if (ch == km->source)
{
Key_Event (km->dest, false, 0);
return;
}
if (ch >= 'A' && ch <= 'Z')
ch += 'a' - 'A';
if (ch>=256)
return;
Key_Event (ch, false, 0);
}
@end

338
rhapsody/sys_rhap.m Normal file
View File

@ -0,0 +1,338 @@
#include <libc.h>
#import <AppKit/AppKit.h>
#include "../qcommon/qcommon.h"
int curtime;
int sys_frame_time;
void Sys_UnloadGame (void)
{
}
void *GetGameAPI (void *import);
void *Sys_GetGameAPI (void *parms)
{
// we are hard-linked in, so no need to load anything
return GetGameAPI (parms);
}
void Sys_CopyProtect (void)
{
}
char *Sys_GetClipboardData( void )
{
return NULL;
}
//===========================================================================
int hunkcount;
byte *membase;
int hunkmaxsize;
int cursize;
//#define VIRTUAL_ALLOC
void *Hunk_Begin (int maxsize)
{
// reserve a huge chunk of memory, but don't commit any yet
cursize = 0;
hunkmaxsize = maxsize;
#ifdef VIRTUAL_ALLOC
membase = VirtualAlloc (NULL, maxsize, MEM_RESERVE, PAGE_NOACCESS);
#else
membase = malloc (maxsize);
memset (membase, 0, maxsize);
#endif
if (!membase)
Sys_Error ("VirtualAlloc reserve failed");
return (void *)membase;
}
void *Hunk_Alloc (int size)
{
void *buf;
// round to cacheline
size = (size+31)&~31;
#ifdef VIRTUAL_ALLOC
// commit pages as needed
// buf = VirtualAlloc (membase+cursize, size, MEM_COMMIT, PAGE_READWRITE);
buf = VirtualAlloc (membase, cursize+size, MEM_COMMIT, PAGE_READWRITE);
if (!buf)
{
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buf, 0, NULL);
Sys_Error ("VirtualAlloc commit failed.\n%s", buf);
}
#endif
cursize += size;
if (cursize > hunkmaxsize)
Sys_Error ("Hunk_Alloc overflow");
return (void *)(membase+cursize-size);
}
int Hunk_End (void)
{
// free the remaining unused virtual memory
#if 0
void *buf;
// write protect it
buf = VirtualAlloc (membase, cursize, MEM_COMMIT, PAGE_READONLY);
if (!buf)
Sys_Error ("VirtualAlloc commit failed");
#endif
hunkcount++;
//Com_Printf ("hunkcount: %i\n", hunkcount);
return cursize;
}
void Hunk_Free (void *base)
{
if ( base )
#ifdef VIRTUAL_ALLOC
VirtualFree (base, 0, MEM_RELEASE);
#else
free (base);
#endif
hunkcount--;
}
//===========================================================================
void Sys_Mkdir (char *path)
{
if (mkdir (path, 0777) != -1)
return;
if (errno != EEXIST)
Com_Error (ERR_FATAL, "mkdir %s: %s",path, strerror(errno));
}
char *Sys_FindFirst (char *path, unsigned musthave, unsigned canthave)
{
return NULL;
}
char *Sys_FindNext (unsigned musthave, unsigned canthave)
{
return NULL;
}
void Sys_FindClose (void)
{
}
/*
================
Sys_Milliseconds
================
*/
int Sys_Milliseconds (void)
{
struct timeval tp;
struct timezone tzp;
static int secbase;
gettimeofday(&tp, &tzp);
if (!secbase)
{
secbase = tp.tv_sec;
return tp.tv_usec/1000;
}
curtime = (tp.tv_sec - secbase)*1000 + tp.tv_usec/1000;
return curtime;
}
/*
================
Sys_Error
================
*/
void Sys_Error (char *error, ...)
{
va_list argptr;
char string[1024];
// change stdin to non blocking
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
va_start (argptr,error);
vsprintf (string,error,argptr);
va_end (argptr);
printf ("Fatal error: %s\n",string);
if (!NSApp)
{ // appkit isn't running, so don't try to pop up a panel
exit (1);
}
NSRunAlertPanel (@"Fatal error",[NSString stringWithCString: string]
,@"exit",NULL,NULL);
[NSApp terminate: NULL];
exit(1);
}
/*
================
Sys_Printf
================
*/
void Sys_ConsoleOutput (char *text)
{
char *t_p;
int l, r;
l = strlen(text);
t_p = text;
// make sure everything goes through, even though we are non-blocking
while (l)
{
r = write (1, text, l);
if (r != l)
sleep (0);
if (r > 0)
{
t_p += r;
l -= r;
}
}
}
/*
================
Sys_Quit
================
*/
void Sys_Quit (void)
{
// change stdin to blocking
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
if (!NSApp)
exit (0); // appkit isn't running
[NSApp terminate:nil];
}
/*
================
Sys_Init
================
*/
void Sys_Init(void)
{
moncontrol(0); // turn off profiling except during real Quake work
// change stdin to non blocking
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
}
extern NSWindow *vid_window_i;
void Sys_AppActivate (void)
{
[vid_window_i makeKeyAndOrderFront: nil];
}
/*
================
Sys_SendKeyEvents
service any pending appkit events
================
*/
void Sys_SendKeyEvents (void)
{
NSEvent *event;
NSDate *date;
date = [NSDate date];
do
{
event = [NSApp
nextEventMatchingMask: 0xffffffff
untilDate: date
inMode: @"NSDefaultRunLoopMode"
dequeue: YES];
if (event)
[NSApp sendEvent: event];
} while (event);
// grab frame time
sys_frame_time = Sys_Milliseconds();
}
/*
================
Sys_ConsoleInput
Checks for a complete line of text typed in at the console, then forwards
it to the host command processor
================
*/
char *Sys_ConsoleInput (void)
{
static char text[256];
int len;
len = read (0, text, sizeof(text));
if (len < 1)
return NULL;
text[len-1] = 0; // rip off the /n and terminate
return text;
}
/*
=============
main
=============
*/
void main (int argc, char **argv)
{
int frame;
NSAutoreleasePool *pool;
int oldtime, t;
pool = [[NSAutoreleasePool alloc] init];
Qcommon_Init (argc, argv);
[pool release];
oldtime = Sys_Milliseconds ();
while (1)
{
pool =[[NSAutoreleasePool alloc] init];
if (++frame > 10)
moncontrol(1);// profile only while we do each Quake frame
t = Sys_Milliseconds ();
Qcommon_Frame (t - oldtime);
oldtime = t;
moncontrol(0);
[pool release];
}
}

1789
rhapsody/vid_next.m Normal file

File diff suppressed because it is too large Load Diff