diff --git a/source/src/cube.h b/source/src/cube.h index e8a3e4a5..97939e58 100644 --- a/source/src/cube.h +++ b/source/src/cube.h @@ -511,7 +511,7 @@ extern vector players; // all the other clients (in multiplayer extern vector bounceents; extern bool editmode; extern vector ents; // map entities -extern vec worldpos; // current target of the crosshair in the world +extern vec worldpos, camup, camright; // current target of the crosshair in the world extern int lastmillis; // last time extern int curtime; // current frame time extern int gamemode, nextmode; diff --git a/source/src/main.cpp b/source/src/main.cpp index 910d8d22..0ebd5493 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -355,7 +355,6 @@ int main(int argc, char **argv) fps = (1000.0f/elapsed+fps*10)/11; computeraytable(player1->o.x, player1->o.y); - readdepth(scr_w, scr_h); SDL_GL_SwapBuffers(); extern void updatevol(); updatevol(); if(framesinmap++<5) // cheap hack to get rid of initial sparklies, even when triple buffering etc. diff --git a/source/src/protos.h b/source/src/protos.h index 56cb74b1..0edc001b 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -191,7 +191,6 @@ extern void addgib(playerent *d); extern void loadingscreen(); // renderparticles -extern void setorient(vec &r, vec &u); extern void particle_splash(int type, int num, int fade, vec &p); //extern void particle_splash(int num, int fade, vec &p); // extern void particle_trail(int type, int fade, vec &from, vec &to); Moved to cube.h by Rick @@ -281,7 +280,6 @@ extern void checkweaponswitch(); extern void weaponswitch(int gun); extern void setscope(bool activate); // Added by Rick -extern botent *botincrosshair(); extern bool intersect(dynent *d, vec &from, vec &to, vec *end = NULL); // End add by Rick diff --git a/source/src/renderextras.cpp b/source/src/renderextras.cpp index 049487b0..cc38c165 100644 --- a/source/src/renderextras.cpp +++ b/source/src/renderextras.cpp @@ -222,13 +222,15 @@ void renderents() // show sparkly thingies for map entities in edit mode float cursordepth = 0.9f; GLint viewport[4]; GLdouble mm[16], pm[16]; -vec worldpos; +vec worldpos, camup, camright; void readmatrices() { glGetIntegerv(GL_VIEWPORT, viewport); glGetDoublev(GL_MODELVIEW_MATRIX, mm); glGetDoublev(GL_PROJECTION_MATRIX, pm); + camright = vec(float(mm[0]), float(mm[4]), float(mm[8])); + camup = vec(float(mm[1]), float(mm[5]), float(mm[9])); }; // stupid function to cater for stupid ATI linux drivers that return incorrect depth values @@ -252,9 +254,6 @@ void readdepth(int w, int h) worldpos.x = (float)worldx; worldpos.y = (float)worldy; worldpos.z = (float)worldz; - vec r((float)mm[0], (float)mm[4], (float)mm[8]); - vec u((float)mm[1], (float)mm[5], (float)mm[9]); - setorient(r, u); }; void drawicon(float tx, float ty, int x, int y, Texture *tex = NULL, float scaling = 1/3.0f) // EDIT: AH @@ -353,10 +352,9 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat glEnable(GL_TEXTURE_2D); playerent *player = playerincrosshair(); - playerent *bot = botincrosshair(); if(getcurcommand()) rendercommand(20, 1570); else if(closeent[0]) draw_text(closeent, 20, 1570); - else if(player || (bot && (player=bot))) draw_text(player->name, 20, 1570); + else if(player) draw_text(player->name, 20, 1570); renderscores(); if(!rendermenu()) diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index 86ca5d93..06ecac20 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -394,12 +394,14 @@ void gl_drawframe(int w, int h, float changelod, float curfps) xtraverts = 0; + renderentities(); + + readdepth(w, h); + renderclients(); //monsterrender(); BotManager.RenderBots(); // Added by Rick - renderentities(); - renderspheres(curtime); renderents(); diff --git a/source/src/renderparticles.cpp b/source/src/renderparticles.cpp index 5cfef367..1b125382 100644 --- a/source/src/renderparticles.cpp +++ b/source/src/renderparticles.cpp @@ -39,10 +39,6 @@ void newparticle(vec &o, vec &d, int fade, int type, int tex = -1) VAR(demotracking, 0, 0, 1); VAR(particlesize, 20, 100, 500); -vec right, up; - -void setorient(vec &r, vec &u) { right = r; up = u; }; - void render_particles(int time) { if(demoplayback && demotracking) @@ -99,10 +95,10 @@ void render_particles(int time) float sz = pt.sz*particlesize/100.0f; // perf varray? - glTexCoord2i(0, 1); glVertex3f(p->o.x+(-right.x+up.x)*sz, p->o.z+(-right.y+up.y)*sz, p->o.y+(-right.z+up.z)*sz); - glTexCoord2i(1, 1); glVertex3f(p->o.x+( right.x+up.x)*sz, p->o.z+( right.y+up.y)*sz, p->o.y+( right.z+up.z)*sz); - glTexCoord2i(1, 0); glVertex3f(p->o.x+( right.x-up.x)*sz, p->o.z+( right.y-up.y)*sz, p->o.y+( right.z-up.z)*sz); - glTexCoord2i(0, 0); glVertex3f(p->o.x+(-right.x-up.x)*sz, p->o.z+(-right.y-up.y)*sz, p->o.y+(-right.z-up.z)*sz); + glTexCoord2i(0, 1); glVertex3f(p->o.x+(-camright.x+camup.x)*sz, p->o.z+(-camright.y+camup.y)*sz, p->o.y+(-camright.z+camup.z)*sz); + glTexCoord2i(1, 1); glVertex3f(p->o.x+( camright.x+camup.x)*sz, p->o.z+( camright.y+camup.y)*sz, p->o.y+( camright.z+camup.z)*sz); + glTexCoord2i(1, 0); glVertex3f(p->o.x+( camright.x-camup.x)*sz, p->o.z+( camright.y-camup.y)*sz, p->o.y+( camright.z-camup.z)*sz); + glTexCoord2i(0, 0); glVertex3f(p->o.x+(-camright.x-camup.x)*sz, p->o.z+(-camright.y-camup.y)*sz, p->o.y+(-camright.z-camup.z)*sz); xtraverts += 4; if(numrender++>maxparticles || (p->fade -= time)<0) diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index d7d20b5e..6347956e 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -4,7 +4,7 @@ struct guninfo { short sound, reload, reloadtime, attackdelay, damage, projspeed, part, spread, recoil, magsize, mdl_kick_rot, mdl_kick_back; bool isauto; char *name; }; -const int SGRAYS = 20; //down from 20 (default) +const int SGRAYS = 20; //down from 20, must be 32 or less (default) const float SGSPREAD = 2; vec sg[SGRAYS]; @@ -201,30 +201,50 @@ bool intersect(dynent *d, vec &from, vec &to, vec *end) // if lineseg hits ent && p->z >= d->o.z-d->eyeheight; }; -playerent *playerincrosshair() +playerent *intersectclosest(vec &from, vec &to, int &n, playerent *at) { - if(demoplayback) return NULL; + playerent *best = NULL; + float bestdist = 1e16f; + if(at!=player1) + { + best = player1; + bestdist = at->o.dist(player1->o); + }; loopv(players) { playerent *o = players[i]; - if(!o) continue; - if(intersect(o, player1->o, worldpos)) return o; + if(!o || o==at || o->state!=CS_ALIVE) continue; + if(!intersect(o, from, to)) continue; + float dist = at->o.dist(o->o); + if(disto, worldpos)) return o; + if(!o || o==at || o->state!=CS_ALIVE) continue; + if(!intersect(o, from, to)) continue; + float dist = at->o.dist(o->o); + if(disto, worldpos, n, player1); }; -// End add by Rick const int MAXPROJ = 100; struct projectile { vec o, to; float speed; playerent *owner; int gun; bool inuse, local; }; @@ -544,19 +564,47 @@ void hitpush(int target, int damage, playerent *d, playerent *at, vec &from, vec d->vel.add(v); }; -void raydamage(playerent *o, vec &from, vec &to, playerent *d, int i) +void shorten(vec &from, vec &to, vec &target) { - if(o->state!=CS_ALIVE) return; - int qdam = guns[d->gunselect].damage; - //if(d->quadmillis) qdam *= 4; + target.sub(from).normalize().mul(from.dist(to)).add(from); +}; + +void raydamage(vec &from, vec &to, playerent *d) +{ + int i = -1, gdam = guns[d->gunselect].damage;; + playerent *o = NULL; if(d->gunselect==GUN_SHOTGUN) { - int damage = 0; - loop(r, SGRAYS) if(intersect(o, from, sg[r])) damage += qdam; - if(damage) hitpush(i, damage, o, d, from, to); + uint done = 0; + playerent *cl = NULL; + int n = -1; + for(;;) + { + bool raysleft = false; + int damage = 0; + o = NULL; + loop(r, SGRAYS) if((done&(1<o, sg[r]); + } + else raysleft = true; + }; + if(damage) hitpush(i, damage, o, d, from, to); + if(!raysleft) break; + }; } - else if(intersect(o, from, to)) hitpush(i, qdam, o, d, from, to); -}; + else if((o = intersectclosest(from, to, i, d))) + { + hitpush(i, gdam, o, d, from, to); + shorten(from, o->o, to); + }; +}; void spreadandrecoil(vec &from, vec &to, playerent *d) { @@ -697,22 +745,6 @@ void shoot(playerent *d, vec &targ) shootv(d->gunselect, from, to, d, 0); addmsg(SV_SHOT, "ri8", d->gunselect, (int)(from.x*DMF), (int)(from.y*DMF), (int)(from.z*DMF), (int)(to.x*DMF), (int)(to.y*DMF), (int)(to.z*DMF), 0 ); if(guns[d->gunselect].projspeed || d->gunselect==GUN_GRENADE) return; - - loopv(players) - { - playerent *o = players[i]; - if(!o) continue; - raydamage(o, from, to, d, i); - }; - - // Added by Rick: raydamage on bots too - loopv(bots) - { - botent *o = bots[i]; - if(!o || (o == d)) continue; - raydamage(o, from, to, d, i); - }; - // End add by Rick - - if(d->type==ENT_BOT) raydamage(player1, from, to, d, -1); + + raydamage(from, to, d); };