add main.hh, physics.hh

master
Daniel Kolesa 2020-06-10 01:46:45 +02:00
parent 2c0bbe98b5
commit d6466cee3d
24 changed files with 162 additions and 125 deletions

View File

@ -1,5 +1,6 @@
// console.cpp: the console buffer, its display, and command line control // console.cpp: the console buffer, its display, and command line control
#include "main.hh"
#include "octaedit.hh" // editmode #include "octaedit.hh" // editmode
#include "rendertext.hh" #include "rendertext.hh"

View File

@ -4,8 +4,6 @@
#include "cube.hh" #include "cube.hh"
#include "world.hh" #include "world.hh"
#ifndef STANDALONE
#include "light.hh" #include "light.hh"
#include "bih.hh" #include "bih.hh"
@ -21,10 +19,6 @@ extern const ivec facecoords[6][4];
extern const uchar fv[6][4]; extern const uchar fv[6][4];
extern const uchar fvmasks[64]; extern const uchar fvmasks[64];
extern const uchar faceedgesidx[6][4]; extern const uchar faceedgesidx[6][4];
extern bool inbetweenframes, renderedframe;
extern SDL_Window *screen;
extern int screenw, screenh;
// renderlights // renderlights
@ -101,10 +95,6 @@ extern void updatedynlights();
extern int finddynlights(); extern int finddynlights();
extern bool getdynlight(int n, vec &o, float &radius, vec &color, vec &dir, int &spot, int &flags); extern bool getdynlight(int n, vec &o, float &radius, vec &color, vec &dir, int &spot, int &flags);
// client
extern void localdisconnect(bool cleanup = true);
extern void clientkeepalive();
// command // command
extern hashnameset<ident> idents; extern hashnameset<ident> idents;
extern int identflags; extern int identflags;
@ -133,52 +123,5 @@ extern tagval *addreleaseaction(ident *id, int numargs);
extern void writebinds(stream *f); extern void writebinds(stream *f);
extern void writecompletions(stream *f); extern void writecompletions(stream *f);
// main
extern int mainmenu;
extern void clearmainmenu();
enum
{
NOT_INITING = 0,
INIT_GAME,
INIT_LOAD,
INIT_RESET
};
extern int initing, numcpus;
extern bool initwarning(const char *desc, int level = INIT_RESET, int type = 0);
extern bool grabinput, minimized;
extern void pushevent(const SDL_Event &e);
extern bool interceptkey(int sym);
extern float loadprogress;
extern void renderbackground(const char *caption = NULL, Texture *mapshot = NULL, const char *mapname = NULL, const char *mapinfo = NULL, bool force = false);
extern void renderprogress(float bar, const char *text, bool background = false);
extern void getframemillis(float &avg, float &best, float &worst);
extern void getfps(int &fps, int &bestdiff, int &worstdiff);
extern void swapbuffers(bool overlay = true);
extern int getclockmillis();
enum { KR_CONSOLE = 1<<0, KR_GUI = 1<<1, KR_EDITMODE = 1<<2 };
extern void keyrepeat(bool on, int mask = ~0);
enum { TI_CONSOLE = 1<<0, TI_GUI = 1<<1 };
extern void textinput(bool on, int mask = ~0);
// physics
extern void mousemove(int dx, int dy);
extern bool overlapsdynent(const vec &o, float radius);
extern void rotatebb(vec &center, vec &radius, int yaw, int pitch, int roll = 0);
extern float shadowray(const vec &o, const vec &ray, float radius, int mode, extentity *t = NULL);
#endif
#endif #endif

View File

@ -1,6 +1,8 @@
#include "blend.hh" #include "blend.hh"
#include "main.hh" // renderbackground
#include "octa.hh" #include "octa.hh"
#include "octaedit.hh" // commitchanges #include "octaedit.hh" // commitchanges
#include "physics.hh"
#include "renderlights.hh" #include "renderlights.hh"
#include "texture.hh" #include "texture.hh"

View File

@ -1,5 +1,7 @@
// main.cpp: initialisation & main loop // main.cpp: initialisation & main loop
#include "main.hh"
#include "blend.hh" #include "blend.hh"
#include "movie.hh" #include "movie.hh"
#include "octaedit.hh" #include "octaedit.hh"
@ -16,6 +18,11 @@
#include "engine.hh" #include "engine.hh"
static SDL_Window *screen = NULL;
static int curvsync = -1;
static void swapbuffers(bool overlay = true);
VAR(mainmenu, 1, 1, 0); VAR(mainmenu, 1, 1, 0);
void clientkeepalive() {} void clientkeepalive() {}
@ -39,13 +46,13 @@ void clearmainmenu()
} }
} }
void localdisconnect(bool cleanup) static void localdisconnect()
{ {
game::gamedisconnect(cleanup); game::gamedisconnect(true);
mainmenu = 1; mainmenu = 1;
} }
void trydisconnect() static void trydisconnect()
{ {
if(haslocalclients()) localdisconnect(); if(haslocalclients()) localdisconnect();
else conoutf("not connected"); else conoutf("not connected");
@ -53,9 +60,9 @@ void trydisconnect()
ICOMMAND(disconnect, "", (), trydisconnect()); ICOMMAND(disconnect, "", (), trydisconnect());
extern void cleargamma(); static void cleargamma();
void cleanup() static void cleanup()
{ {
recorder::stop(); recorder::stop();
SDL_ShowCursor(SDL_TRUE); SDL_ShowCursor(SDL_TRUE);
@ -74,9 +81,9 @@ void cleanup()
SDL_Quit(); SDL_Quit();
} }
extern void writeinitcfg(); static void writeinitcfg();
void quit() // normal exit static void quit() // normal exit
{ {
writeinitcfg(); writeinitcfg();
localdisconnect(); localdisconnect();
@ -118,8 +125,7 @@ void fatal(const char *s, ...) // failure exit
VAR(desktopw, 1, 0, 0); VAR(desktopw, 1, 0, 0);
VAR(desktoph, 1, 0, 0); VAR(desktoph, 1, 0, 0);
int screenw = 0, screenh = 0; int screenw = 0, screenh = 0;
SDL_Window *screen = NULL; static SDL_GLContext glcontext = NULL;
SDL_GLContext glcontext = NULL;
int curtime = 0, lastmillis = 1, elapsedtime = 0, totalmillis = 1; int curtime = 0, lastmillis = 1, elapsedtime = 0, totalmillis = 1;
@ -146,7 +152,7 @@ bool initwarning(const char *desc, int level, int type)
VARFN(screenw, scr_w, SCR_MINW, -1, SCR_MAXW, initwarning("screen resolution")); VARFN(screenw, scr_w, SCR_MINW, -1, SCR_MAXW, initwarning("screen resolution"));
VARFN(screenh, scr_h, SCR_MINH, -1, SCR_MAXH, initwarning("screen resolution")); VARFN(screenh, scr_h, SCR_MINH, -1, SCR_MAXH, initwarning("screen resolution"));
void writeinitcfg() static void writeinitcfg()
{ {
stream *f = openutf8file("config/init.cfg", "w"); stream *f = openutf8file("config/init.cfg", "w");
if(!f) return; if(!f) return;
@ -170,12 +176,12 @@ static void getbackgroundres(int &w, int &h)
h = int(ceil(h*hk)); h = int(ceil(h*hk));
} }
string backgroundcaption = ""; static string backgroundcaption = "";
Texture *backgroundmapshot = NULL; static Texture *backgroundmapshot = NULL;
string backgroundmapname = ""; static string backgroundmapname = "";
char *backgroundmapinfo = NULL; static char *backgroundmapinfo = NULL;
void bgquad(float x, float y, float w, float h, float tx = 0, float ty = 0, float tw = 1, float th = 1) static void bgquad(float x, float y, float w, float h, float tx = 0, float ty = 0, float tw = 1, float th = 1)
{ {
gle::begin(GL_TRIANGLE_STRIP); gle::begin(GL_TRIANGLE_STRIP);
gle::attribf(x, y); gle::attribf(tx, ty); gle::attribf(x, y); gle::attribf(tx, ty);
@ -185,7 +191,7 @@ void bgquad(float x, float y, float w, float h, float tx = 0, float ty = 0, floa
gle::end(); gle::end();
} }
void renderbackgroundview(int w, int h, const char *caption, Texture *mapshot, const char *mapname, const char *mapinfo) static void renderbackgroundview(int w, int h, const char *caption, Texture *mapshot, const char *mapname, const char *mapinfo)
{ {
static int lastupdate = -1, lastw = -1, lasth = -1; static int lastupdate = -1, lastw = -1, lasth = -1;
static float backgroundu = 0, backgroundv = 0; static float backgroundu = 0, backgroundv = 0;
@ -276,7 +282,7 @@ void renderbackgroundview(int w, int h, const char *caption, Texture *mapshot, c
VAR(menumute, 0, 1, 1); VAR(menumute, 0, 1, 1);
void setbackgroundinfo(const char *caption = NULL, Texture *mapshot = NULL, const char *mapname = NULL, const char *mapinfo = NULL) static void setbackgroundinfo(const char *caption = NULL, Texture *mapshot = NULL, const char *mapname = NULL, const char *mapinfo = NULL)
{ {
renderedframe = false; renderedframe = false;
copystring(backgroundcaption, caption ? caption : ""); copystring(backgroundcaption, caption ? caption : "");
@ -315,7 +321,7 @@ void renderbackground(const char *caption, Texture *mapshot, const char *mapname
setbackgroundinfo(caption, mapshot, mapname, mapinfo); setbackgroundinfo(caption, mapshot, mapname, mapinfo);
} }
void restorebackground(int w, int h, bool force = false) static void restorebackground(int w, int h, bool force = false)
{ {
if(renderedframe) if(renderedframe)
{ {
@ -327,7 +333,7 @@ void restorebackground(int w, int h, bool force = false)
float loadprogress = 0; float loadprogress = 0;
void renderprogressview(int w, int h, float bar, const char *text) // also used during loading static void renderprogressview(int w, int h, float bar, const char *text) // also used during loading
{ {
hudmatrix.ortho(0, w, h, 0, -1, 1); hudmatrix.ortho(0, w, h, 0, -1, 1);
resethudmatrix(); resethudmatrix();
@ -400,7 +406,7 @@ void renderprogress(float bar, const char *text, bool background) // also used
getbackgroundres(w, h); getbackgroundres(w, h);
gettextres(w, h); gettextres(w, h);
extern int mesa_swap_bug, curvsync; extern int mesa_swap_bug;
bool forcebackground = progressbackground || (mesa_swap_bug && (curvsync || totalmillis==1)); bool forcebackground = progressbackground || (mesa_swap_bug && (curvsync || totalmillis==1));
if(background || forcebackground) restorebackground(w, h, forcebackground); if(background || forcebackground) restorebackground(w, h, forcebackground);
@ -410,9 +416,11 @@ void renderprogress(float bar, const char *text, bool background) // also used
VARNP(relativemouse, userelativemouse, 0, 1, 1); VARNP(relativemouse, userelativemouse, 0, 1, 1);
bool shouldgrab = false, grabinput = false, minimized = false, canrelativemouse = true, relativemouse = false; static bool shouldgrab = false, grabinput = false;
int keyrepeatmask = 0, textinputmask = 0; static bool canrelativemouse = true, relativemouse = false;
Uint32 textinputtime = 0; bool minimized = false;
static int keyrepeatmask = 0, textinputmask = 0;
static Uint32 textinputtime = 0;
VAR(textinputfilter, 0, 5, 1000); VAR(textinputfilter, 0, 5, 1000);
void keyrepeat(bool on, int mask) void keyrepeat(bool on, int mask)
@ -439,7 +447,7 @@ void textinput(bool on, int mask)
} }
} }
void inputgrab(bool on) static void inputgrab(bool on)
{ {
if(on) if(on)
{ {
@ -472,9 +480,9 @@ void inputgrab(bool on)
shouldgrab = false; shouldgrab = false;
} }
bool initwindowpos = false; static bool initwindowpos = false;
void setfullscreen(bool enable) static void setfullscreen(bool enable)
{ {
if(!screen) return; if(!screen) return;
//initwarning(enable ? "fullscreen" : "windowed"); //initwarning(enable ? "fullscreen" : "windowed");
@ -497,7 +505,7 @@ VARF(fullscreen, 0, 0, 1, setfullscreen(fullscreen!=0));
VARF(fullscreen, 0, 1, 1, setfullscreen(fullscreen!=0)); VARF(fullscreen, 0, 1, 1, setfullscreen(fullscreen!=0));
#endif #endif
void screenres(int w, int h) static void screenres(int w, int h)
{ {
scr_w = clamp(w, SCR_MINW, SCR_MAXW); scr_w = clamp(w, SCR_MINW, SCR_MAXW);
scr_h = clamp(h, SCR_MINH, SCR_MAXH); scr_h = clamp(h, SCR_MINH, SCR_MAXH);
@ -529,20 +537,19 @@ VARFNP(gamma, reqgamma, 30, 100, 300,
setgamma(curgamma); setgamma(curgamma);
}); });
void restoregamma() static void restoregamma()
{ {
if(initing || reqgamma == 100) return; if(initing || reqgamma == 100) return;
curgamma = reqgamma; curgamma = reqgamma;
setgamma(curgamma); setgamma(curgamma);
} }
void cleargamma() static void cleargamma()
{ {
if(curgamma != 100 && screen) SDL_SetWindowBrightness(screen, 1.0f); if(curgamma != 100 && screen) SDL_SetWindowBrightness(screen, 1.0f);
} }
int curvsync = -1; static void restorevsync()
void restorevsync()
{ {
if(initing || !glcontext) return; if(initing || !glcontext) return;
extern int vsync, vsynctear; extern int vsync, vsynctear;
@ -555,7 +562,7 @@ VARFP(vsynctear, 0, 0, 1, { if(vsync) restorevsync(); });
VAR(dbgmodes, 0, 0, 1); VAR(dbgmodes, 0, 0, 1);
void setupscreen() static void setupscreen()
{ {
if(glcontext) if(glcontext)
{ {
@ -621,7 +628,7 @@ void setupscreen()
hudh = screenh; hudh = screenh;
} }
void resetgl() static void resetgl()
{ {
//clearchanges(CHANGE_GFX|CHANGE_SHADERS); //clearchanges(CHANGE_GFX|CHANGE_SHADERS);
@ -669,9 +676,9 @@ void resetgl()
COMMAND(resetgl, ""); COMMAND(resetgl, "");
vector<SDL_Event> events; static vector<SDL_Event> events;
void pushevent(const SDL_Event &e) static void pushevent(const SDL_Event &e)
{ {
events.add(e); events.add(e);
} }
@ -767,7 +774,7 @@ static void checkmousemotion(int &dx, int &dy)
} }
} }
void checkinput() static void checkinput()
{ {
SDL_Event event; SDL_Event event;
//int lasttype = 0, lastbut = 0; //int lasttype = 0, lastbut = 0;
@ -875,7 +882,7 @@ void checkinput()
if(mousemoved) resetmousemotion(); if(mousemoved) resetmousemotion();
} }
void swapbuffers(bool overlay) static void swapbuffers(bool overlay)
{ {
recorder::capture(overlay); recorder::capture(overlay);
gle::disable(); gle::disable();
@ -885,7 +892,7 @@ void swapbuffers(bool overlay)
VAR(menufps, 0, 60, 1000); VAR(menufps, 0, 60, 1000);
VARP(maxfps, 0, 125, 1000); VARP(maxfps, 0, 125, 1000);
void limitfps(int &millis, int curmillis) static void limitfps(int &millis, int curmillis)
{ {
int limit = (mainmenu || minimized) && menufps ? (maxfps ? min(maxfps, menufps) : menufps) : maxfps; int limit = (mainmenu || minimized) && menufps ? (maxfps ? min(maxfps, menufps) : menufps) : maxfps;
if(!limit) return; if(!limit) return;
@ -929,7 +936,7 @@ __declspec(dllexport)
#endif #endif
#if defined(WIN32) && !defined(_DEBUG) && !defined(__GNUC__) #if defined(WIN32) && !defined(_DEBUG) && !defined(__GNUC__)
void stackdumper(unsigned int type, EXCEPTION_POINTERS *ep) static void stackdumper(unsigned int type, EXCEPTION_POINTERS *ep)
{ {
if(!ep) fatal("unknown type"); if(!ep) fatal("unknown type");
EXCEPTION_RECORD *er = ep->ExceptionRecord; EXCEPTION_RECORD *er = ep->ExceptionRecord;
@ -972,21 +979,22 @@ void stackdumper(unsigned int type, EXCEPTION_POINTERS *ep)
#define MAXFPSHISTORY 60 #define MAXFPSHISTORY 60
int fpspos = 0, fpshistory[MAXFPSHISTORY]; static int fpspos = 0, fpshistory[MAXFPSHISTORY];
void resetfpshistory() static void resetfpshistory()
{ {
loopi(MAXFPSHISTORY) fpshistory[i] = 1; loopi(MAXFPSHISTORY) fpshistory[i] = 1;
fpspos = 0; fpspos = 0;
} }
void updatefpshistory(int millis) static void updatefpshistory(int millis)
{ {
fpshistory[fpspos++] = max(1, min(1000, millis)); fpshistory[fpspos++] = max(1, min(1000, millis));
if(fpspos>=MAXFPSHISTORY) fpspos = 0; if(fpspos>=MAXFPSHISTORY) fpspos = 0;
} }
void getframemillis(float &avg, float &bestdiff, float &worstdiff) #if 0
static void getframemillis(float &avg, float &bestdiff, float &worstdiff)
{ {
int total = fpshistory[MAXFPSHISTORY-1], best = total, worst = total; int total = fpshistory[MAXFPSHISTORY-1], best = total, worst = total;
loopi(MAXFPSHISTORY-1) loopi(MAXFPSHISTORY-1)
@ -1001,6 +1009,7 @@ void getframemillis(float &avg, float &bestdiff, float &worstdiff)
best = best - avg; best = best - avg;
worstdiff = avg - worst; worstdiff = avg - worst;
} }
#endif
void getfps(int &fps, int &bestdiff, int &worstdiff) void getfps(int &fps, int &bestdiff, int &worstdiff)
{ {
@ -1018,7 +1027,7 @@ void getfps(int &fps, int &bestdiff, int &worstdiff)
worstdiff = fps-1000/worst; worstdiff = fps-1000/worst;
} }
void getfps_(int *raw) static void getfps_(int *raw)
{ {
if(*raw) floatret(1000.0f/fpshistory[(fpspos+MAXFPSHISTORY-1)%MAXFPSHISTORY]); if(*raw) floatret(1000.0f/fpshistory[(fpspos+MAXFPSHISTORY-1)%MAXFPSHISTORY]);
else else

43
src/engine/main.hh 100644
View File

@ -0,0 +1,43 @@
#ifndef ENGINE_MAIN_HH
#define ENGINE_MAIN_HH
#include <shared/tools.hh>
extern int initing, numcpus;
extern int mainmenu;
extern int screenw, screenh;
extern bool minimized;
extern float loadprogress;
extern bool inbetweenframes, renderedframe;
void clearmainmenu();
enum
{
NOT_INITING = 0,
INIT_GAME,
INIT_LOAD,
INIT_RESET
};
bool initwarning(const char *desc, int level = INIT_RESET, int type = 0);
bool interceptkey(int sym);
struct Texture;
void renderbackground(const char *caption = NULL, Texture *mapshot = NULL, const char *mapname = NULL, const char *mapinfo = NULL, bool force = false);
void renderprogress(float bar, const char *text, bool background = false);
void getfps(int &fps, int &bestdiff, int &worstdiff);
int getclockmillis();
enum { KR_CONSOLE = 1<<0, KR_GUI = 1<<1, KR_EDITMODE = 1<<2 };
void keyrepeat(bool on, int mask = ~0);
enum { TI_CONSOLE = 1<<0, TI_GUI = 1<<1 };
void textinput(bool on, int mask = ~0);
#endif

View File

@ -7,6 +7,9 @@
// avidemux - ok - 3Apr09-RockKeyman:had to swap UV channels as it showed up blue // avidemux - ok - 3Apr09-RockKeyman:had to swap UV channels as it showed up blue
// kino - ok // kino - ok
#include "movie.hh"
#include "main.hh" // getfps, getclockmillis, screenw/h, inbetweenframes, renderedframe
#include "rendergl.hh" #include "rendergl.hh"
#include "rendertext.hh" #include "rendertext.hh"
#include "texture.hh" #include "texture.hh"

View File

@ -1,3 +1,4 @@
#include "main.hh" // renderprogress
#include "texture.hh" #include "texture.hh"
#include "engine.hh" #include "engine.hh"

View File

@ -1,6 +1,8 @@
// core world management routines // core world management routines
#include "octa.hh" #include "octa.hh"
#include "main.hh" // renderprogress
#include "octaedit.hh" #include "octaedit.hh"
#include "world.hh" #include "world.hh"

View File

@ -1,6 +1,7 @@
#include "octaedit.hh" #include "octaedit.hh"
#include "blend.hh" #include "blend.hh"
#include "main.hh" // mainmenu, keyrepeat, renderedframe
#include "material.hh" #include "material.hh"
#include "octa.hh" #include "octa.hh"
#include "pvs.hh" #include "pvs.hh"

View File

@ -2,6 +2,7 @@
#include "blend.hh" #include "blend.hh"
#include "grass.hh" #include "grass.hh"
#include "main.hh" // mainmenu, laodprogress
#include "material.hh" #include "material.hh"
#include "rendergl.hh" #include "rendergl.hh"
#include "renderlights.hh" #include "renderlights.hh"

View File

@ -3,6 +3,8 @@
// they "felt right", and have no basis in reality. Collision detection is simplistic but // they "felt right", and have no basis in reality. Collision detection is simplistic but
// very robust (uses discrete steps at fixed fps). // very robust (uses discrete steps at fixed fps).
#include "physics.hh"
#include "rendermodel.hh" #include "rendermodel.hh"
#include "octa.hh" #include "octa.hh"
#include "world.hh" #include "world.hh"
@ -111,7 +113,7 @@ void resetclipplanes()
else if(v[i] < p.o[i]-p.r[i] || v[i] > p.o[i]+p.r[i]) exit; \ else if(v[i] < p.o[i]-p.r[i] || v[i] > p.o[i]+p.r[i]) exit; \
} }
vec hitsurface; vec hitsurface; /* extern'd */
static inline bool raycubeintersect(const clipplanes &p, const cube &c, const vec &v, const vec &ray, const vec &invray, float maxdist, float &dist) static inline bool raycubeintersect(const clipplanes &p, const cube &c, const vec &v, const vec &ray, const vec &invray, float maxdist, float &dist)
{ {
@ -128,8 +130,8 @@ static inline bool raycubeintersect(const clipplanes &p, const cube &c, const ve
return true; return true;
} }
float hitentdist; static float hitentdist;
int hitent, hitorient; static int hitent, hitorient;
static float disttoent(octaentities *oc, const vec &o, const vec &ray, float radius, int mode, extentity *t) static float disttoent(octaentities *oc, const vec &o, const vec &ray, float radius, int mode, extentity *t)
{ {
@ -434,7 +436,7 @@ const float WALLZ = 0.2f;
extern const float JUMPVEL = 125.0f; extern const float JUMPVEL = 125.0f;
extern const float GRAVITY = 200.0f; extern const float GRAVITY = 200.0f;
bool ellipseboxcollide(physent *d, const vec &dir, const vec &o, const vec &center, float yaw, float xr, float yr, float hi, float lo) static bool ellipseboxcollide(physent *d, const vec &dir, const vec &o, const vec &center, float yaw, float xr, float yr, float hi, float lo)
{ {
float below = (o.z+center.z-lo) - (d->o.z+d->aboveeye), float below = (o.z+center.z-lo) - (d->o.z+d->aboveeye),
above = (d->o.z-d->eyeheight) - (o.z+center.z+hi); above = (d->o.z-d->eyeheight) - (o.z+center.z+hi);
@ -489,7 +491,7 @@ bool ellipseboxcollide(physent *d, const vec &dir, const vec &o, const vec &cent
return false; return false;
} }
bool ellipsecollide(physent *d, const vec &dir, const vec &o, const vec &center, float yaw, float xr, float yr, float hi, float lo) static bool ellipsecollide(physent *d, const vec &dir, const vec &o, const vec &center, float yaw, float xr, float yr, float hi, float lo)
{ {
float below = (o.z+center.z-lo) - (d->o.z+d->aboveeye), float below = (o.z+center.z-lo) - (d->o.z+d->aboveeye),
above = (d->o.z-d->eyeheight) - (o.z+center.z+hi); above = (d->o.z-d->eyeheight) - (o.z+center.z+hi);
@ -549,7 +551,7 @@ VARF(dynentsize, 4, 7, 12, cleardynentcache());
#define DYNENTHASH(x, y) (((((x)^(y))<<5) + (((x)^(y))>>5)) & (DYNENTCACHESIZE - 1)) #define DYNENTHASH(x, y) (((((x)^(y))<<5) + (((x)^(y))>>5)) & (DYNENTCACHESIZE - 1))
const vector<physent *> &checkdynentcache(int x, int y) static const vector<physent *> &checkdynentcache(int x, int y)
{ {
dynentcacheentry &dec = dynentcache[DYNENTHASH(x, y)]; dynentcacheentry &dec = dynentcache[DYNENTHASH(x, y)];
if(dec.x == x && dec.y == y && dec.frame == dynentframe) return dec.dynents; if(dec.x == x && dec.y == y && dec.frame == dynentframe) return dec.dynents;
@ -628,7 +630,7 @@ static inline bool plcollide(physent *d, const vec &dir, physent *o)
} }
} }
bool plcollide(physent *d, const vec &dir, bool insideplayercol) // collide with player static bool plcollide(physent *d, const vec &dir, bool insideplayercol) // collide with player
{ {
if(d->type==ENT_CAMERA || d->state!=CS_ALIVE) return false; if(d->type==ENT_CAMERA || d->state!=CS_ALIVE) return false;
int lastinside = collideinside; int lastinside = collideinside;
@ -801,7 +803,7 @@ static bool fuzzycollideellipse(physent *d, const vec &dir, float cutoff, const
VAR(testtricol, 0, 0, 2); VAR(testtricol, 0, 0, 2);
bool mmcollide(physent *d, const vec &dir, float cutoff, octaentities &oc) // collide with a mapmodel static bool mmcollide(physent *d, const vec &dir, float cutoff, octaentities &oc) // collide with a mapmodel
{ {
const vector<extentity *> &ents = entities::getents(); const vector<extentity *> &ents = entities::getents();
loopv(oc.mapmodels) loopv(oc.mapmodels)
@ -1153,7 +1155,7 @@ bool collide(physent *d, const vec &dir, float cutoff, bool playercol, bool insi
return octacollide(d, dir, cutoff, bo, bs) || (playercol && plcollide(d, dir, insideplayercol)); // collide with world return octacollide(d, dir, cutoff, bo, bs) || (playercol && plcollide(d, dir, insideplayercol)); // collide with world
} }
void recalcdir(physent *d, const vec &oldvel, vec &dir) static void recalcdir(physent *d, const vec &oldvel, vec &dir)
{ {
float speed = oldvel.magnitude(); float speed = oldvel.magnitude();
if(speed > 1e-6f) if(speed > 1e-6f)
@ -1165,7 +1167,7 @@ void recalcdir(physent *d, const vec &oldvel, vec &dir)
} }
} }
void slideagainst(physent *d, vec &dir, const vec &obstacle, bool foundfloor, bool slidecollide) static void slideagainst(physent *d, vec &dir, const vec &obstacle, bool foundfloor, bool slidecollide)
{ {
vec wall(obstacle); vec wall(obstacle);
if(foundfloor ? wall.z > 0 : slidecollide) if(foundfloor ? wall.z > 0 : slidecollide)
@ -1180,7 +1182,7 @@ void slideagainst(physent *d, vec &dir, const vec &obstacle, bool foundfloor, bo
recalcdir(d, oldvel, dir); recalcdir(d, oldvel, dir);
} }
void switchfloor(physent *d, vec &dir, const vec &floor) static void switchfloor(physent *d, vec &dir, const vec &floor)
{ {
if(floor.z >= FLOORZ) d->falling = vec(0, 0, 0); if(floor.z >= FLOORZ) d->falling = vec(0, 0, 0);
@ -1196,7 +1198,7 @@ void switchfloor(physent *d, vec &dir, const vec &floor)
recalcdir(d, oldvel, dir); recalcdir(d, oldvel, dir);
} }
bool trystepup(physent *d, vec &dir, const vec &obstacle, float maxstep, const vec &floor) static bool trystepup(physent *d, vec &dir, const vec &obstacle, float maxstep, const vec &floor)
{ {
vec old(d->o), stairdir = (obstacle.z >= 0 && obstacle.z < SLOPEZ ? vec(-obstacle.x, -obstacle.y, 0) : vec(dir.x, dir.y, 0)).rescale(1); vec old(d->o), stairdir = (obstacle.z >= 0 && obstacle.z < SLOPEZ ? vec(-obstacle.x, -obstacle.y, 0) : vec(dir.x, dir.y, 0)).rescale(1);
bool cansmooth = true; bool cansmooth = true;
@ -1287,7 +1289,7 @@ bool trystepup(physent *d, vec &dir, const vec &obstacle, float maxstep, const v
return false; return false;
} }
bool trystepdown(physent *d, vec &dir, float step, float xy, float z, bool init = false) static bool trystepdown(physent *d, vec &dir, float step, float xy, float z, bool init = false)
{ {
vec stepdir(dir.x, dir.y, 0); vec stepdir(dir.x, dir.y, 0);
stepdir.z = -stepdir.magnitude2()*z/xy; stepdir.z = -stepdir.magnitude2()*z/xy;
@ -1338,7 +1340,7 @@ bool trystepdown(physent *d, vec &dir, float step, float xy, float z, bool init
return false; return false;
} }
bool trystepdown(physent *d, vec &dir, bool init = false) static bool trystepdown(physent *d, vec &dir, bool init = false)
{ {
if((!d->move && !d->strafe) || !game::allowmove(d)) return false; if((!d->move && !d->strafe) || !game::allowmove(d)) return false;
vec old(d->o); vec old(d->o);
@ -1364,7 +1366,7 @@ bool trystepdown(physent *d, vec &dir, bool init = false)
return false; return false;
} }
void falling(physent *d, vec &dir, const vec &floor) static void falling(physent *d, vec &dir, const vec &floor)
{ {
if(floor.z > 0.0f && floor.z < SLOPEZ) if(floor.z > 0.0f && floor.z < SLOPEZ)
{ {
@ -1377,7 +1379,7 @@ void falling(physent *d, vec &dir, const vec &floor)
d->physstate = PHYS_FALL; d->physstate = PHYS_FALL;
} }
void landing(physent *d, vec &dir, const vec &floor, bool collided) static void landing(physent *d, vec &dir, const vec &floor, bool collided)
{ {
#if 0 #if 0
if(d->physstate == PHYS_FALL) if(d->physstate == PHYS_FALL)
@ -1393,7 +1395,7 @@ void landing(physent *d, vec &dir, const vec &floor, bool collided)
d->floor = floor; d->floor = floor;
} }
bool findfloor(physent *d, const vec &dir, bool collided, const vec &obstacle, bool &slide, vec &floor) static bool findfloor(physent *d, const vec &dir, bool collided, const vec &obstacle, bool &slide, vec &floor)
{ {
bool found = false; bool found = false;
vec moved(d->o); vec moved(d->o);
@ -1451,7 +1453,7 @@ foundfloor:
return found; return found;
} }
bool move(physent *d, vec &dir) static bool move(physent *d, vec &dir)
{ {
vec old(d->o); vec old(d->o);
bool collided = false, slidecollide = false; bool collided = false, slidecollide = false;
@ -1673,7 +1675,7 @@ bool droptofloor(vec &o, float radius, float height)
return false; return false;
} }
float dropheight(entity &e) static float dropheight(entity &e)
{ {
switch(e.type) switch(e.type)
{ {
@ -1690,7 +1692,7 @@ void dropenttofloor(entity *e)
droptofloor(e->o, 1.0f, dropheight(*e)); droptofloor(e->o, 1.0f, dropheight(*e));
} }
void phystest() static void phystest()
{ {
static const char * const states[] = {"float", "fall", "slide", "slope", "floor", "step up", "step down", "bounce"}; static const char * const states[] = {"float", "fall", "slide", "slope", "floor", "step up", "step down", "bounce"};
printf ("PHYS(pl): %s, air %d, floor: (%f, %f, %f), vel: (%f, %f, %f), g: (%f, %f, %f)\n", states[player->physstate], player->timeinair, player->floor.x, player->floor.y, player->floor.z, player->vel.x, player->vel.y, player->vel.z, player->falling.x, player->falling.y, player->falling.z); printf ("PHYS(pl): %s, air %d, floor: (%f, %f, %f), vel: (%f, %f, %f), g: (%f, %f, %f)\n", states[player->physstate], player->timeinair, player->floor.x, player->floor.y, player->floor.z, player->vel.x, player->vel.y, player->vel.z, player->falling.x, player->falling.y, player->falling.z);
@ -1740,7 +1742,7 @@ FVAR(straferoll, 0, 0.033f, 90);
FVAR(faderoll, 0, 0.95f, 1); FVAR(faderoll, 0, 0.95f, 1);
VAR(floatspeed, 1, 100, 10000); VAR(floatspeed, 1, 100, 10000);
void modifyvelocity(physent *pl, bool local, bool water, bool floating, int curtime) static void modifyvelocity(physent *pl, bool local, bool water, bool floating, int curtime)
{ {
bool allowmove = game::allowmove(pl); bool allowmove = game::allowmove(pl);
if(floating) if(floating)
@ -1801,7 +1803,7 @@ void modifyvelocity(physent *pl, bool local, bool water, bool floating, int curt
// pl->vel.lerp(pl->vel, d, fpsfric); // pl->vel.lerp(pl->vel, d, fpsfric);
} }
void modifygravity(physent *pl, bool water, int curtime) static void modifygravity(physent *pl, bool water, int curtime)
{ {
float secs = curtime/1000.0f; float secs = curtime/1000.0f;
vec g(0, 0, 0); vec g(0, 0, 0);
@ -1898,7 +1900,7 @@ bool moveplayer(physent *pl, int moveres, bool local, int curtime)
return true; return true;
} }
int physsteps = 0, physframetime = PHYSFRAMETIME, lastphysframe = 0; static int physsteps = 0, physframetime = PHYSFRAMETIME, lastphysframe = 0;
void physicsframe() // optimally schedule physics frames inside the graphics frames void physicsframe() // optimally schedule physics frames inside the graphics frames
{ {
@ -1915,7 +1917,7 @@ void physicsframe() // optimally schedule physics frames inside the gra
VAR(physinterp, 0, 1, 1); VAR(physinterp, 0, 1, 1);
void interppos(physent *pl) static void interppos(physent *pl)
{ {
pl->o = pl->newpos; pl->o = pl->newpos;

View File

@ -0,0 +1,12 @@
#ifndef ENGINE_PHYSICS_HH
#define ENGINE_PHYSICS_HH
#include <shared/geom.hh>
struct extentity;
bool overlapsdynent(const vec &o, float radius);
void rotatebb(vec &center, vec &radius, int yaw, int pitch, int roll = 0);
float shadowray(const vec &o, const vec &ray, float radius, int mode, extentity *t = NULL);
#endif

View File

@ -1,4 +1,6 @@
#include "pvs.hh" #include "pvs.hh"
#include "main.hh" // numcpus, interceptkey, renderbackground
#include "octa.hh" #include "octa.hh"
#include "engine.hh" #include "engine.hh"

View File

@ -3,6 +3,7 @@
#include "aa.hh" #include "aa.hh"
#include "blend.hh" #include "blend.hh"
#include "grass.hh" #include "grass.hh"
#include "main.hh" // mainmenu, renderbackground, getfps, getclockmillis, screenw/h, inbetweenframes, renderedframe
#include "material.hh" #include "material.hh"
#include "pvs.hh" #include "pvs.hh"
#include "octaedit.hh" #include "octaedit.hh"

View File

@ -80,4 +80,6 @@ struct cubemapside; /* texture.hh */
void drawcubemap(int size, const vec &o, float yaw, float pitch, const cubemapside &side, bool onlysky = false); void drawcubemap(int size, const vec &o, float yaw, float pitch, const cubemapside &side, bool onlysky = false);
void mousemove(int dx, int dy);
#endif #endif

View File

@ -1,6 +1,7 @@
#include "renderlights.hh" #include "renderlights.hh"
#include "aa.hh" #include "aa.hh"
#include "main.hh" // initwarning
#include "material.hh" #include "material.hh"
#include "octaedit.hh" // editmode #include "octaedit.hh" // editmode
#include "pvs.hh" #include "pvs.hh"

View File

@ -1,6 +1,7 @@
#include "rendermodel.hh" #include "rendermodel.hh"
#include "aa.hh" #include "aa.hh"
#include "main.hh" // loadprogress, renderprogress
#include "pvs.hh" #include "pvs.hh"
#include "rendergl.hh" #include "rendergl.hh"
#include "renderva.hh" #include "renderva.hh"

View File

@ -1,5 +1,6 @@
// renderparticles.cpp // renderparticles.cpp
#include "main.hh" // initing, minimized, loadprogress
#include "renderparticles.hh" #include "renderparticles.hh"
#include "octaedit.hh" // editmode #include "octaedit.hh" // editmode
#include "pvs.hh" #include "pvs.hh"

View File

@ -1,8 +1,10 @@
// renderva.cpp: handles the occlusion and rendering of vertex arrays // renderva.cpp: handles the occlusion and rendering of vertex arrays
#include "renderva.hh" #include "renderva.hh"
#include "blend.hh" #include "blend.hh"
#include "grass.hh" #include "grass.hh"
#include "main.hh" // renderprogress
#include "octaedit.hh" // editmode #include "octaedit.hh" // editmode
#include "pvs.hh" #include "pvs.hh"
#include "rendergl.hh" #include "rendergl.hh"

View File

@ -1,5 +1,6 @@
// shader.cpp: OpenGL GLSL shader management // shader.cpp: OpenGL GLSL shader management
#include "main.hh" // loadprogress, renderprogress
#include "rendergl.hh" #include "rendergl.hh"
#include "rendermodel.hh" // cleanupmodels #include "rendermodel.hh" // cleanupmodels
#include "shader.hh" #include "shader.hh"

View File

@ -1,3 +1,4 @@
#include "main.hh" // initing, loadprogress
#include "material.hh" #include "material.hh"
#include "rendergl.hh" #include "rendergl.hh"
#include "rendermodel.hh" // loadmapmodel #include "rendermodel.hh" // loadmapmodel

View File

@ -1,5 +1,6 @@
// texture.cpp: texture slot management // texture.cpp: texture slot management
#include "main.hh" // initwarning, loadprogress, renderprogress, screenw/h, renderedframe
#include "material.hh" #include "material.hh"
#include "octaedit.hh" #include "octaedit.hh"
#include "rendergl.hh" #include "rendergl.hh"
@ -3059,6 +3060,7 @@ static GLuint genenvmap(const vec &o, int envmapsize, int blur, bool onlysky)
} }
glBindFramebuffer_(GL_FRAMEBUFFER, 0); glBindFramebuffer_(GL_FRAMEBUFFER, 0);
glViewport(0, 0, hudw, hudh); glViewport(0, 0, hudw, hudh);
extern void clientkeepalive(); /* FIXME */
clientkeepalive(); clientkeepalive();
return tex; return tex;
} }

View File

@ -1,8 +1,10 @@
// world.cpp: core map management stuff // world.cpp: core map management stuff
#include "blend.hh" #include "blend.hh"
#include "main.hh" // clearmainmenu
#include "octa.hh" #include "octa.hh"
#include "octaedit.hh" #include "octaedit.hh"
#include "physics.hh"
#include "pvs.hh" #include "pvs.hh"
#include "rendergl.hh" /* fovy */ #include "rendergl.hh" /* fovy */
#include "renderlights.hh" #include "renderlights.hh"

View File

@ -1,6 +1,7 @@
// worldio.cpp: loading & saving of maps and savegames // worldio.cpp: loading & saving of maps and savegames
#include "blend.hh" #include "blend.hh"
#include "main.hh" // clearmainmenu, renderbackground
#include "octa.hh" #include "octa.hh"
#include "octaedit.hh" // texmru #include "octaedit.hh" // texmru
#include "pvs.hh" #include "pvs.hh"