From 037452348303e9bef6ca29bb24cbfd6d4d684230 Mon Sep 17 00:00:00 2001 From: driAn Date: Sat, 13 Aug 2005 14:35:27 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@26 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/Makefile | 2 +- source/src/clientextras.cpp | 8 +- source/src/physics.cpp | 747 +++++++++++++++++------------------- source/src/rendermd3.cpp | 45 ++- 4 files changed, 383 insertions(+), 419 deletions(-) diff --git a/source/src/Makefile b/source/src/Makefile index dc27fed2..d9403503 100644 --- a/source/src/Makefile +++ b/source/src/Makefile @@ -19,7 +19,7 @@ CLIENT_OBJS= \ renderextras.o \ rendergl.o \ rendermd2.o \ - rendermd3.o \ + rendermd3_2.o \ renderparticles.o \ rendertext.o \ rndmap.o \ diff --git a/source/src/clientextras.cpp b/source/src/clientextras.cpp index 65b8d32e..c570900b 100644 --- a/source/src/clientextras.cpp +++ b/source/src/clientextras.cpp @@ -15,7 +15,7 @@ void renderclient(dynent *d, bool team, char *mdlname, bool hellpig, float scale float speed = 100.0f; float mz = d->o.z-d->eyeheight+1.55f*scale; int basetime = -((int)d&0xFFF); - /*if(d->state==CS_DEAD) + if(d->state==CS_DEAD) { int r; if(hellpig) { n = 2; r = range[3]; } else { n = (int)d%3; r = range[n]; }; @@ -35,10 +35,10 @@ void renderclient(dynent *d, bool team, char *mdlname, bool hellpig, float scale else if((!d->move && !d->strafe) || !d->moving) { n = 12; } else if(!d->onfloor && d->timeinair>100) { n = 18; } else { n = 14; speed = 1200/d->maxspeed*scale; if(hellpig) speed = 300/d->maxspeed; }; - if(hellpig) { n++; scale *= 32; mz -= 1.9f; };*/ - //rendermodel(mdlname, frame[n], range[n], 0, 1.5f, d->o.x, mz, d->o.y, d->yaw+90, d->pitch/2, team, scale, speed, 0, basetime); + if(hellpig) { n++; scale *= 32; mz -= 1.9f; }; + rendermodel(mdlname, frame[n], range[n], 0, 1.5f, d->o.x, mz, d->o.y, d->yaw+90, d->pitch/2, team, scale, speed, 0, basetime); - rendermd3player(d); + //rendermd3player(d); }; extern int democlientnum; diff --git a/source/src/physics.cpp b/source/src/physics.cpp index bf9c16a6..59ca58df 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -1,391 +1,356 @@ -// physics.cpp: no physics books were hurt nor consulted in the construction of this code. -// All physics computations and constants were invented on the fly and simply tweaked until -// they "felt right", and have no basis in reality. Collision detection is simplistic but -// very robust (uses discrete steps at fixed fps). - -#include "cube.h" - -/* Modified by Rick: Now you can normally walk/jump/whatever on players -bool plcollide(dynent *d, dynent *o, float &headspace) // collide with player or monster -{ - if(o->state!=CS_ALIVE) return true; - const float r = o->radius+d->radius; - if(fabs(o->o.x-d->o.x)o.y-d->o.y)o.z-d->o.z)aboveeye+d->eyeheight) return false; - if(d->monsterstate) return false; // hack - headspace = d->o.z-o->o.z-o->aboveeye-d->eyeheight; - if(headspace<0) headspace = 10; - }; - return true; -}; -*/ - -bool plcollide(dynent *d, dynent *o, float &headspace, float &hi, float &lo) // collide with player or monster -{ - if(o->state!=CS_ALIVE) return true; - const float r = o->radius+d->radius; - if(fabs(o->o.x-d->o.x)o.y-d->o.y)o.z-d->eyeheighto.z-o->eyeheight) { if(o->o.z-o->eyeheighto.z-o->eyeheight-1; } - else if(o->o.z+o->aboveeye>lo) lo = o->o.z+o->aboveeye+1; - - if(fabs(o->o.z-d->o.z)aboveeye+d->eyeheight) return false; - if(d->monsterstate) return false; // hack - headspace = d->o.z-o->o.z-o->aboveeye-d->eyeheight; - if(headspace<0) headspace = 10; - }; - return true; -}; -// End mod - -bool cornertest(int mip, int x, int y, int dx, int dy, int &bx, int &by, int &bs) // recursively collide with a mipmapped corner cube -{ - sqr *w = wmip[mip]; - int sz = ssize>>mip; - bool stest = SOLID(SWS(w, x+dx, y, sz)) && SOLID(SWS(w, x, y+dy, sz)); - mip++; - x /= 2; - y /= 2; - if(SWS(wmip[mip], x, y, ssize>>mip)->type==CORNER) - { - bx = x<radius; - if(fabs(e.x-d->o.x)o.y)floor+mmi.zoff+e.attr3); - if(d->o.z-d->eyeheightlo) lo = mmz+mmi.h; - }; - }; -}; - -// all collision happens here -// spawn is a dirty side effect used in spawning -// drop & rise are supplied by the physics below to indicate gravity/push for current mini-timestep - -bool collide(dynent *d, bool spawn, float drop, float rise) -{ - const float fx1 = d->o.x-d->radius; // figure out integer cube rectangle this entity covers in map - const float fy1 = d->o.y-d->radius; - const float fx2 = d->o.x+d->radius; - const float fy2 = d->o.y+d->radius; - const int x1 = fast_f2nat(fx1); - const int y1 = fast_f2nat(fy1); - const int x2 = fast_f2nat(fx2); - const int y2 = fast_f2nat(fy2); - float hi = 127, lo = -128; - float minfloor = (d->monsterstate && !spawn && d->health>100) ? d->o.z-d->eyeheight-4.5f : -1000.0f; // big monsters are afraid of heights, unless angry :) - - for(int x = x1; x<=x2; x++) for(int y = y1; y<=y2; y++) // collide with map - { - if(OUTBORD(x,y)) return false; - sqr *s = S(x,y); - float ceil = s->ceil; - float floor = s->floor; - switch(s->type) - { - case SOLID: - return false; - - case CORNER: - { - int bx = x, by = y, bs = 1; - if(x==x1 && y==y1 && cornertest(0, x, y, -1, -1, bx, by, bs) && fx1-bx+fy1-by<=bs - || x==x2 && y==y1 && cornertest(0, x, y, 1, -1, bx, by, bs) && fx2-bx>=fy1-by - || x==x1 && y==y2 && cornertest(0, x, y, -1, 1, bx, by, bs) && fx1-bx<=fy2-by - || x==x2 && y==y2 && cornertest(0, x, y, 1, 1, bx, by, bs) && fx2-bx+fy2-by>=bs) - return false; - break; - }; - - case FHF: // FIXME: too simplistic collision with slopes, makes it feels like tiny stairs - floor -= (s->vdelta+S(x+1,y)->vdelta+S(x,y+1)->vdelta+S(x+1,y+1)->vdelta)/16.0f; - break; - - case CHF: - ceil += (s->vdelta+S(x+1,y)->vdelta+S(x,y+1)->vdelta+S(x+1,y+1)->vdelta)/16.0f; - - }; - if(ceillo) lo = floor; - if(flooreyeheight+d->aboveeye) return false; - - // Modified by Rick: plcollide now takes hi and lo in account aswell, that way we can jump/walk on players - - // Modified by Rick: plcollide now takes hi and lo in account aswell, that way we can - // jump/walk on players - - float headspace = 10; - loopv(players) // collide with other players - { - dynent *o = players[i]; - if(!o || o==d) continue; - if(!plcollide(d, o, headspace, hi, lo)) return false; - }; - - loopv(bots) // Added by Rick: collide with other bots - { - dynent *o = bots[i]; - if(!o || o==d) continue; - if(!plcollide(d, o, headspace, hi, lo)) return false; - }; // End add - - if(d!=player1) if(!plcollide(d, player1, headspace, hi, lo)) return false; - //dvector &v = getmonsters(); - // this loop can be a performance bottleneck with many monster on a slow cpu, - // should replace with a blockmap but seems mostly fast enough - //loopv(v) if(!vreject(d->o, v[i]->o, 7.0f) && d!=v[i] && !plcollide(d, v[i], headspace, hi, lo)) return false; - - headspace -= 0.01f; - - mmcollide(d, hi, lo); // collide with map models - - if(spawn) - { - d->o.z = lo+d->eyeheight; // just drop to floor (sideeffect) - d->startheight = d->o.z; - d->onfloor = true; - } - else - { - const float space = d->o.z-d->eyeheight-lo; - if(space<0) - { - - if(space>-0.01) //stick to step - { - d->o.z = lo+d->eyeheight; - } - else if(space>-1.26f) //rise thru stair - { - d->o.z += rise; - - } - else return false; - } - else - { - d->o.z -= min(min(drop, space), headspace); // gravity - }; - - const float space2 = hi-(d->o.z+d->aboveeye); - if(space2<0) - { - if(space2<-0.1) return false; // hack alert! - d->o.z = hi-d->aboveeye; // glue to ceiling - d->vel.z = 0; // cancel out jumping velocity - }; - - d->onfloor = d->o.z-d->eyeheight-lo<0.01f; - }; - return true; -}; - -float rad(float x) -{ - return x*3.14159f/180; -}; - -VAR(maxroll, 0, 3, 20); - -int physicsfraction = 0, physicsrepeat = 0; -const int MINFRAMETIME = 20; // physics always simulated at 50fps or better - -void physicsframe() // optimally schedule physics frames inside the graphics frames -{ - if(curtime>=MINFRAMETIME) - { - int faketime = curtime+physicsfraction; - physicsrepeat = faketime/MINFRAMETIME; - physicsfraction = faketime-physicsrepeat*MINFRAMETIME; - } - else - { - physicsrepeat = 1; - }; -}; - -// main physics routine, moves a player/monster for a curtime step -// moveres indicated the physics precision (which is lower for monsters and multiplayer prediction) -// local is false for multiplayer prediction - -void moveplayer(dynent *pl, int moveres, bool local, int curtime) -{ - const bool water = hdr.waterlevel>pl->o.z-0.5f; - const bool floating = (editmode && local) || pl->state==CS_EDITING; - - vec d; // vector of direction we ideally want to move in - - d.x = (float)(pl->move*cos(rad(pl->yaw-90))); - d.y = (float)(pl->move*sin(rad(pl->yaw-90))); - d.z = 0; - - if(floating || water) - { - d.x *= (float)cos(rad(pl->pitch)); - d.y *= (float)cos(rad(pl->pitch)); - d.z = (float)(pl->move*sin(rad(pl->pitch))); - }; - - d.x += (float)(pl->strafe*cos(rad(pl->yaw-180))); - d.y += (float)(pl->strafe*sin(rad(pl->yaw-180))); - - const float speed = curtime/(water ? 2000.0f : 1000.0f)*pl->maxspeed; - const float friction = water ? 20.0f : (pl->onfloor || floating ? 6.0f : 30.0f); - - const float fpsfric = friction/curtime*20.0f; - - vmul(pl->vel, fpsfric-1); // slowly apply friction and direction to velocity, gives a smooth movement - vadd(pl->vel, d); - vdiv(pl->vel, fpsfric); - d = pl->vel; - vmul(d, speed); // d is now frametime based velocity vector - - pl->blocked = false; - pl->moving = true; - - if(floating) // just apply velocity - { - vadd(pl->o, d); - if(pl->jumpnext) { pl->jumpnext = false; pl->vel.z = 2; } - } - else // apply velocity with collision - { - if (pl->onfloor || !pl->vel.z) - { - if ((int)pl->startheight - (int)pl->o.z > 8 && !pl->onladder && local) //try adding "&& local" if falling not fixed - selfdamage(abs((int)pl->startheight - (int)pl->o.z),-1,pl); - pl->startheight=pl->o.z; - }; - - if(pl->onfloor || water) - { - - if(pl->jumpnext && !pl->onladder) - { - pl->jumpnext = false; - pl->vel.z = 2.00f; // physics impulse upwards original 1.7f - if(water) { pl->vel.x /= 8; pl->vel.y /= 8; }; // dampen velocity change even harder, gives correct water feel - if(local) playsoundc(S_JUMP); - else if(pl->monsterstate) playsound(S_JUMP, &pl->o); - else if(pl->bIsBot) botplaysound(S_JUMP, pl); // Added by Rick - } - if (!pl->jumpnext && pl->onladder) - { - if(pl->k_up) - pl->vel.z = 0.5f; - }; - - pl->timeinair = 0; - } - else - { - if (pl->onladder) - { - pl->vel.z = 0; - if(pl->k_up) - pl->vel.z = 0.5f; - if(pl->k_down) - pl->vel.z = -0.5f; - }; - - pl->timeinair += curtime; - }; - - const float gravity = 20; - const float f = 1.0f/moveres; - float dropf = ((gravity-1)+pl->timeinair/15.0f); // incorrect, but works fine - if(water) { dropf = 5; pl->timeinair = 0; }; // float slowly down in water - if(pl->onladder) { dropf = 0; pl->timeinair = 0;}; - - // at high fps, gravity kicks in too fast - const float drop = dropf*curtime/gravity/100/moveres; - const float rise = speed/moveres/1.2f; - - - loopi(moveres) // discrete steps collision detection & sliding - { - // try move forward - pl->o.x += f*d.x; - pl->o.y += f*d.y; - pl->o.z += f*d.z; - if(collide(pl, false, drop, rise)) continue; - // player stuck, try slide along y axis - pl->blocked = true; - pl->o.x -= f*d.x; - if(collide(pl, false, drop, rise)) { d.x = 0; continue; }; - pl->o.x += f*d.x; - // still stuck, try x axis - pl->o.y -= f*d.y; - if(collide(pl, false, drop, rise)) { d.y = 0; continue; }; - pl->o.y += f*d.y; - // try just dropping down - pl->moving = false; - pl->o.x -= f*d.x; - pl->o.y -= f*d.y; - if(collide(pl, false, drop, rise)) { d.y = d.x = 0; continue; }; - pl->o.z -= f*d.z; - break; - }; - }; - - // detect wether player is outside map, used for skipping zbuffer clear mostly - - if(pl->o.x < 0 || pl->o.x >= ssize || pl->o.y <0 || pl->o.y > ssize) - { - pl->outsidemap = true; - } - else - { - sqr *s = S((int)pl->o.x, (int)pl->o.y); - pl->outsidemap = SOLID(s) - || pl->o.z < s->floor - (s->type==FHF ? s->vdelta/4 : 0) - || pl->o.z > s->ceil + (s->type==CHF ? s->vdelta/4 : 0); - }; - - // automatically apply smooth roll when strafing - - if(pl->strafe==0) - { - pl->roll = pl->roll/(1+(float)sqrt((float)curtime)/25); - } - else - { - pl->roll += pl->strafe*curtime/-30.0f; - if(pl->roll>maxroll) pl->roll = (float)maxroll; - if(pl->roll<-maxroll) pl->roll = (float)-maxroll; - }; - - // play sounds on water transitions - - if(!pl->inwater && water) { playsound(S_SPLASH2, &pl->o); pl->vel.z = 0; } - else if(pl->inwater && !water) playsound(S_SPLASH1, &pl->o); - pl->inwater = water; - // Added by Rick: Easy hack to store previous locations of all players/monsters/bots - pl->PrevLocations.Update(pl->o); - // End add -}; - -void moveplayer(dynent *pl, int moveres, bool local) -{ - loopi(physicsrepeat) moveplayer(pl, moveres, local, i ? curtime/physicsrepeat : curtime-curtime/physicsrepeat*(physicsrepeat-1)); -}; +// physics.cpp: no physics books were hurt nor consulted in the construction of this code. +// All physics computations and constants were invented on the fly and simply tweaked until +// they "felt right", and have no basis in reality. Collision detection is simplistic but +// very robust (uses discrete steps at fixed fps). + +#include "cube.h" + +/* Modified by Rick: Fix, so we can jump on players aswell +bool plcollide(dynent *d, dynent *o, float &headspace) // collide with player or monster +{ + if(o->state!=CS_ALIVE) return true; + const float r = o->radius+d->radius; + if(fabs(o->o.x-d->o.x)o.y-d->o.y)o.z-d->o.z)aboveeye+d->eyeheight) return false; + if(d->monsterstate) return false; // hack + headspace = d->o.z-o->o.z-o->aboveeye-d->eyeheight; + if(headspace<0) headspace = 10; + }; + return true; +}; +*/ + +bool plcollide(dynent *d, dynent *o, float &headspace, float &hi, float &lo) // collide with player or monster +{ + if(o->state!=CS_ALIVE) return true; + const float r = o->radius+d->radius; + if(fabs(o->o.x-d->o.x)o.y-d->o.y)o.z-d->eyeheighto.z-o->eyeheight) { if(o->o.z-o->eyeheighto.z-o->eyeheight-1; } + else if(o->o.z+o->aboveeye>lo) lo = o->o.z+o->aboveeye+1; + + if(fabs(o->o.z-d->o.z)aboveeye+d->eyeheight) return false; + //if(d->monsterstate) return false; // hack + headspace = d->o.z-o->o.z-o->aboveeye-d->eyeheight; + if(headspace<0) headspace = 10; + }; + return true; +}; + +bool cornertest(int mip, int x, int y, int dx, int dy, int &bx, int &by, int &bs) // recursively collide with a mipmapped corner cube +{ + sqr *w = wmip[mip]; + int sz = ssize>>mip; + bool stest = SOLID(SWS(w, x+dx, y, sz)) && SOLID(SWS(w, x, y+dy, sz)); + mip++; + x /= 2; + y /= 2; + if(SWS(wmip[mip], x, y, ssize>>mip)->type==CORNER) + { + bx = x<radius; + if(fabs(e.x-d->o.x)o.y)floor+mmi.zoff+e.attr3); + if(d->o.z-d->eyeheightlo) lo = mmz+mmi.h; + }; + }; +}; + +// all collision happens here +// spawn is a dirty side effect used in spawning +// drop & rise are supplied by the physics below to indicate gravity/push for current mini-timestep + +bool collide(dynent *d, bool spawn, float drop, float rise) +{ + const float fx1 = d->o.x-d->radius; // figure out integer cube rectangle this entity covers in map + const float fy1 = d->o.y-d->radius; + const float fx2 = d->o.x+d->radius; + const float fy2 = d->o.y+d->radius; + const int x1 = fast_f2nat(fx1); + const int y1 = fast_f2nat(fy1); + const int x2 = fast_f2nat(fx2); + const int y2 = fast_f2nat(fy2); + float hi = 127, lo = -128; + float minfloor = (d->monsterstate && !spawn && d->health>100) ? d->o.z-d->eyeheight-4.5f : -1000.0f; // big monsters are afraid of heights, unless angry :) + + for(int x = x1; x<=x2; x++) for(int y = y1; y<=y2; y++) // collide with map + { + if(OUTBORD(x,y)) return false; + sqr *s = S(x,y); + float ceil = s->ceil; + float floor = s->floor; + switch(s->type) + { + case SOLID: + return false; + + case CORNER: + { + int bx = x, by = y, bs = 1; + if(x==x1 && y==y1 && cornertest(0, x, y, -1, -1, bx, by, bs) && fx1-bx+fy1-by<=bs + || x==x2 && y==y1 && cornertest(0, x, y, 1, -1, bx, by, bs) && fx2-bx>=fy1-by + || x==x1 && y==y2 && cornertest(0, x, y, -1, 1, bx, by, bs) && fx1-bx<=fy2-by + || x==x2 && y==y2 && cornertest(0, x, y, 1, 1, bx, by, bs) && fx2-bx+fy2-by>=bs) + return false; + break; + }; + + case FHF: // FIXME: too simplistic collision with slopes, makes it feels like tiny stairs + floor -= (s->vdelta+S(x+1,y)->vdelta+S(x,y+1)->vdelta+S(x+1,y+1)->vdelta)/16.0f; + break; + + case CHF: + ceil += (s->vdelta+S(x+1,y)->vdelta+S(x,y+1)->vdelta+S(x+1,y+1)->vdelta)/16.0f; + + }; + if(ceillo) lo = floor; + if(flooreyeheight+d->aboveeye) return false; + + // Modified by Rick: plcollide now takes hi and lo in account aswell, that way we can jump/walk on players + + float headspace = 10; + loopv(players) // collide with other players + { + dynent *o = players[i]; + if(!o || o==d) continue; + if(!plcollide(d, o, headspace, hi, lo)) return false; + }; + + loopv(bots) // Added by Rick: collide with other bots + { + dynent *o = bots[i]; + if(!o || o==d) continue; + if(!plcollide(d, o, headspace, hi, lo)) return false; + }; + + if(d!=player1) if(!plcollide(d, player1, headspace, hi, lo)) return false; + //dvector &v = getmonsters(); + // this loop can be a performance bottleneck with many monster on a slow cpu, + // should replace with a blockmap but seems mostly fast enough + // Modified by Rick: Added v[i] pointer check + //loopv(v) if(v[i] && !vreject(d->o, v[i]->o, 7.0f) && d!=v[i] && !plcollide(d, v[i], headspace, hi, lo)) return false; + headspace -= 0.01f; + + mmcollide(d, hi, lo); // collide with map models + + if(spawn) + { + d->o.z = lo+d->eyeheight; // just drop to floor (sideeffect) + d->onfloor = true; + } + else + { + const float space = d->o.z-d->eyeheight-lo; + if(space<0) + { + if(space>-0.01) d->o.z = lo+d->eyeheight; // stick on step + else if(space>-1.26f) d->o.z += rise; // rise thru stair + else return false; + } + else + { + d->o.z -= min(min(drop, space), headspace); // gravity + }; + + const float space2 = hi-(d->o.z+d->aboveeye); + if(space2<0) + { + if(space2<-0.1) return false; // hack alert! + d->o.z = hi-d->aboveeye; // glue to ceiling + d->vel.z = 0; // cancel out jumping velocity + }; + + d->onfloor = d->o.z-d->eyeheight-lo<0.01f; + }; + return true; +} + +float rad(float x) { return x*3.14159f/180; }; + +VAR(maxroll, 0, 3, 20); + +int physicsfraction = 0, physicsrepeat = 0; +const int MINFRAMETIME = 20; // physics always simulated at 50fps or better + +void physicsframe() // optimally schedule physics frames inside the graphics frames +{ + if(curtime>=MINFRAMETIME) + { + int faketime = curtime+physicsfraction; + physicsrepeat = faketime/MINFRAMETIME; + physicsfraction = faketime-physicsrepeat*MINFRAMETIME; + } + else + { + physicsrepeat = 1; + }; +}; + +// main physics routine, moves a player/monster for a curtime step +// moveres indicated the physics precision (which is lower for monsters and multiplayer prediction) +// local is false for multiplayer prediction + +void moveplayer(dynent *pl, int moveres, bool local, int curtime) +{ + const bool water = hdr.waterlevel>pl->o.z-0.5f; + const bool floating = (editmode && local) || pl->state==CS_EDITING; + + vec d; // vector of direction we ideally want to move in + + d.x = (float)(pl->move*cos(rad(pl->yaw-90))); + d.y = (float)(pl->move*sin(rad(pl->yaw-90))); + d.z = 0; + + if(floating || water) + { + d.x *= (float)cos(rad(pl->pitch)); + d.y *= (float)cos(rad(pl->pitch)); + d.z = (float)(pl->move*sin(rad(pl->pitch))); + }; + + d.x += (float)(pl->strafe*cos(rad(pl->yaw-180))); + d.y += (float)(pl->strafe*sin(rad(pl->yaw-180))); + + const float speed = curtime/(water ? 2000.0f : 1000.0f)*pl->maxspeed; + const float friction = water ? 20.0f : (pl->onfloor || floating ? 6.0f : 30.0f); + + const float fpsfric = friction/curtime*20.0f; + + vmul(pl->vel, fpsfric-1); // slowly apply friction and direction to velocity, gives a smooth movement + vadd(pl->vel, d); + vdiv(pl->vel, fpsfric); + d = pl->vel; + vmul(d, speed); // d is now frametime based velocity vector + + pl->blocked = false; + pl->moving = true; + + if(floating) // just apply velocity + { + vadd(pl->o, d); + if(pl->jumpnext) { pl->jumpnext = false; pl->vel.z = 2; } + } + else // apply velocity with collision + { + if(pl->onfloor || water) + { + if(pl->jumpnext) + { + pl->jumpnext = false; + pl->vel.z = 1.7f; // physics impulse upwards + if(water) { pl->vel.x /= 8; pl->vel.y /= 8; }; // dampen velocity change even harder, gives correct water feel + if(local) playsoundc(S_JUMP); + else if(pl->monsterstate) playsound(S_JUMP, &pl->o); + else if(pl->bIsBot) botplaysound(S_JUMP, pl); // Added by Rick + } + else if(pl->timeinair>800) // if we land after long time must have been a high jump, make thud sound + { + if(local) playsoundc(S_LAND); + else if(pl->monsterstate) playsound(S_LAND, &pl->o); + else if(pl->bIsBot) botplaysound(S_LAND, pl); // Added by Rick + }; + pl->timeinair = 0; + } + else + { + pl->timeinair += curtime; + }; + + const float gravity = 20; + const float f = 1.0f/moveres; + float dropf = ((gravity-1)+pl->timeinair/15.0f); // incorrect, but works fine + if(water) { dropf = 5; pl->timeinair = 0; }; // float slowly down in water + const float drop = dropf*curtime/gravity/100/moveres; // at high fps, gravity kicks in too fast + const float rise = speed/moveres/1.2f; // extra smoothness when lifting up stairs + + loopi(moveres) // discrete steps collision detection & sliding + { + // try move forward + pl->o.x += f*d.x; + pl->o.y += f*d.y; + pl->o.z += f*d.z; + if(collide(pl, false, drop, rise)) continue; + // player stuck, try slide along y axis + pl->blocked = true; + pl->o.x -= f*d.x; + if(collide(pl, false, drop, rise)) { d.x = 0; continue; }; + pl->o.x += f*d.x; + // still stuck, try x axis + pl->o.y -= f*d.y; + if(collide(pl, false, drop, rise)) { d.y = 0; continue; }; + pl->o.y += f*d.y; + // try just dropping down + pl->moving = false; + pl->o.x -= f*d.x; + pl->o.y -= f*d.y; + if(collide(pl, false, drop, rise)) { d.y = d.x = 0; continue; }; + pl->o.z -= f*d.z; + break; + }; + }; + + // detect wether player is outside map, used for skipping zbuffer clear mostly + + if(pl->o.x < 0 || pl->o.x >= ssize || pl->o.y <0 || pl->o.y > ssize) + { + pl->outsidemap = true; + } + else + { + sqr *s = S((int)pl->o.x, (int)pl->o.y); + pl->outsidemap = SOLID(s) + || pl->o.z < s->floor - (s->type==FHF ? s->vdelta/4 : 0) + || pl->o.z > s->ceil + (s->type==CHF ? s->vdelta/4 : 0); + }; + + // automatically apply smooth roll when strafing + + if(pl->strafe==0) + { + pl->roll = pl->roll/(1+(float)sqrt((float)curtime)/25); + } + else + { + pl->roll += pl->strafe*curtime/-30.0f; + if(pl->roll>maxroll) pl->roll = (float)maxroll; + if(pl->roll<-maxroll) pl->roll = (float)-maxroll; + }; + + // play sounds on water transitions + + if(!pl->inwater && water) { playsound(S_SPLASH2, &pl->o); pl->vel.z = 0; } + else if(pl->inwater && !water) playsound(S_SPLASH1, &pl->o); + pl->inwater = water; + + // Added by Rick: Easy hack to store previous locations of all players/monsters/bots + pl->PrevLocations.Update(pl->o); + // End add +}; + +void moveplayer(dynent *pl, int moveres, bool local) +{ + loopi(physicsrepeat) moveplayer(pl, moveres, local, i ? curtime/physicsrepeat : curtime-curtime/physicsrepeat*(physicsrepeat-1)); +}; + diff --git a/source/src/rendermd3.cpp b/source/src/rendermd3.cpp index 6693063e..61631ab0 100644 --- a/source/src/rendermd3.cpp +++ b/source/src/rendermd3.cpp @@ -55,7 +55,7 @@ struct md3triangle { signed short vertex[3]; unsigned char normal[2]; -}; +}; struct md3face { @@ -80,8 +80,8 @@ struct md3tface struct md3animinfo { - int startframe; - int endframe; + int start; + int end; bool loop; int fps; }; @@ -245,12 +245,6 @@ void md3model::link(md3model *link, char *tag) }; }; -void modulo(int a, int b) -{ - conoutf("%i", a % b); -}; -COMMAND(modulo, ARG_2INT); - void md3model::render() { int startfrm = 0; @@ -263,13 +257,13 @@ void md3model::render() if(animations.length()) { anim = &animations[a->anim]; - if(a->frm < anim->startframe || a->frm > anim->endframe) + /*if(a->frm < anim->start || a->frm > anim->end) { - a->frm = anim->startframe; + a->frm = anim->start; a->lastTime = lastmillis; - }; - startfrm = anim->startframe; - endfrm = anim->endframe; + };*/ + startfrm = anim->start; + endfrm = anim->end; } int nextfrm = (a->frm + 1) % endfrm; @@ -287,13 +281,12 @@ void md3model::render() t = (float) elapsedtime / (1000 / anim->fps); if(t >= 1.0f) { + t = 0.0f; a->frm = nextfrm; a->lastTime = lastmillis; }; }; - printf("anim:%d\tfrm:%d\tt:%f\n", a->anim, a->frm, t); - loopv(objects) { md3object *obj = &objects[i]; @@ -431,12 +424,12 @@ void md3skin(char *objname, char *skin) // called by the {lower|upper|head}.cfg COMMAND(md3skin, ARG_2STR); -void md3animation(char *firstframe, char *numframes, char *loopingframes, char *fps) /* configurable animations - use hardcoded instead ? */ +void md3animation(char *first, char *nums, char *loopings, char *fps) /* configurable animations - use hardcoded instead ? */ { md3animinfo &a = tmp_animations.add(); - a.startframe = atoi(firstframe); - a.endframe = a.startframe + atoi(numframes); - (atoi(loopingframes) > 0) ? a.loop = true : a.loop = false; + a.start = atoi(first); + a.end = a.start + atoi(nums); + (atoi(loopings) > 0) ? a.loop = true : a.loop = false; a.fps = atoi(fps); }; @@ -454,7 +447,7 @@ void rendermd3player(dynent *d) { if(playermodels.length() >= 3 && d->mdl[MDL_LOWER] == 0) { - loopi(3) playermodels[d->mdl[i]]->animstate = &d->animstate[i]; // get d's current frame + loopi(3) playermodels[d->mdl[i]]->animstate = &d->animstate[i]; // get d's current md3setanim(d, anim); @@ -511,8 +504,8 @@ void loadplayermdl(char *model) sprintf_sd(path)("%s/%s", basedir, pl_objects[i]); mdls[i] = loadmd3(path); }; - mdls[MDL_LOWER]->link(mdls[MDL_UPPER], "tag_torso"); - mdls[MDL_UPPER]->link(mdls[MDL_HEAD], "tag_head"); + //mdls[MDL_LOWER]->link(mdls[MDL_UPPER], "tag_torso"); + //mdls[MDL_UPPER]->link(mdls[MDL_HEAD], "tag_head"); sprintf_sd(modelcfg)("%s/model.cfg", basedir); exec(modelcfg); // load animations to tmp_animation loopv(tmp_animations) // assign the loaded animations to the lower,upper or head model @@ -531,3 +524,9 @@ void loadplayermdl(char *model) }; COMMAND(loadplayermdl, ARG_1STR); + +void test1() +{ + md3model test; + test.load("packages/models/playermodels/lara/lower.md3"); +}; COMMAND(test1, ARG_NONE);