From 5912a80a5e4ea348d30bab70f69f89766525e687 Mon Sep 17 00:00:00 2001 From: flowtron Date: Sun, 26 Sep 2010 22:10:24 +0000 Subject: [PATCH] colourcoded editmode sparklies git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@5699 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/entities.cpp | 28 ++++++++++- source/src/renderparticles.cpp | 85 ++++++++++++++++++---------------- 2 files changed, 73 insertions(+), 40 deletions(-) diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 32bff7b9..4cc3a434 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -168,7 +168,33 @@ void renderentities() if(ice) continue; vec v(e.x, e.y, e.z); if(vec(v).sub(camera1->o).dot(camdir) < 0) continue; - particle_splash(i == closest ? 12 : 2, 2, 40, v); + //particle_splash(i == closest ? 12 : 2, 2, 40, v); + int sc = 17; // "carrot" (orange) - entity slot currently unused, possibly "reserved" + if(i==closest) + { + sc = 2; + } + else switch(e.type) + { + case LIGHT : sc = 12; break; // white + case PLAYERSTART: sc = 13; break; // green + case I_CLIPS: + case I_AMMO: + case I_GRENADE: sc = 14; break; // red + case I_HEALTH: + case I_HELMET: + case I_ARMOUR: + case I_AKIMBO: sc = 15; break; // yellow + case MAPMODEL: + case SOUND: sc = 16; break; // magenta + case LADDER: + case CLIP: + case PLCLIP: sc = 18; break; // grey + case CTF_FLAG: sc = 19; break; // turquoise + default: break; + } + //particle_splash(sc, i==closest?6:2, i==closest?120:40, v); + particle_splash(sc, 2, 40, v); } } } diff --git a/source/src/renderparticles.cpp b/source/src/renderparticles.cpp index 29f61e83..5458e306 100644 --- a/source/src/renderparticles.cpp +++ b/source/src/renderparticles.cpp @@ -15,14 +15,14 @@ static void genface(int depth, int i1, int i2, int i3) hemiindices[face+1] = i2; hemiindices[face+2] = i3; subdivide(depth, face); -} - +} + static void subdivide(int depth, int face) -{ +{ if(depth-- <= 0) return; int idx[6]; loopi(3) idx[i] = hemiindices[face+i]; - loopi(3) + loopi(3) { int vert = heminumverts++; hemiverts[vert] = vec(hemiverts[idx[i]]).add(hemiverts[idx[(i+1)%3]]).normalize(); //push on to unit sphere @@ -35,7 +35,7 @@ static void subdivide(int depth, int face) //subdiv version wobble much more nicely than a lat/longitude version static void inithemisphere(int hres, int depth) -{ +{ const int tris = hres << (2*depth); heminumverts = heminumindices = 0; DELETEA(hemiverts); @@ -52,14 +52,14 @@ static void inithemisphere(int hres, int depth) } GLuint createexpmodtex(int size, float minval) -{ +{ uchar *data = new uchar[size*size], *dst = data; loop(y, size) loop(x, size) { float dx = 2*float(x)/(size-1) - 1, dy = 2*float(y)/(size-1) - 1; float z = max(0.0f, 1.0f - dx*dx - dy*dy); if(minval) z = sqrtf(z); - else loopk(2) z *= z; + else loopk(2) z *= z; *dst++ = uchar(max(z, minval)*255); } GLuint tex = 0; @@ -70,8 +70,8 @@ GLuint createexpmodtex(int size, float minval) } static struct expvert -{ - vec pos; +{ + vec pos; float u, v, s, t; } *expverts = NULL; @@ -81,7 +81,7 @@ static GLuint lastexpmodtex = 0; VARP(mtexplosion, 0, 1, 1); void setupexplosion() -{ +{ if(!hemiindices) inithemisphere(5, 2); static int lastexpmillis = 0; @@ -124,7 +124,7 @@ void setupexplosion() glActiveTexture_(GL_TEXTURE0_ARB); glClientActiveTexture_(GL_TEXTURE0_ARB); - + if(!expmodtex[0]) expmodtex[0] = createexpmodtex(64, 0); if(!expmodtex[1]) expmodtex[1] = createexpmodtex(64, 0.25f); lastexpmodtex = 0; @@ -164,7 +164,7 @@ void drawexplosion(bool inside, float r, float g, float b, float a) } void cleanupexplosion() -{ +{ glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); @@ -184,7 +184,7 @@ void cleanupexplosion() } } -#define MAXPARTYPES 13 +#define MAXPARTYPES 20 struct particle { vec o, d; int fade, type; int millis; particle *next; }; particle *parlist[MAXPARTYPES], *parempty = NULL; @@ -250,19 +250,26 @@ void newparticle(const vec &o, const vec &d, int fade, int type) static struct parttype { int type; float r, g, b; int gr, tex; float sz; } parttypes[] = { - { PT_PART, 0.4f, 0.4f, 0.4f, 2, 0, 0.06f }, // yellow: sparks + { PT_PART, 0.4f, 0.4f, 0.4f, 2, 0, 0.06f }, // yellow: sparks { PT_PART, 1.0f, 1.0f, 1.0f, 20, 1, 0.15f }, // grey: small smoke - { PT_PART, 0.2f, 0.2f, 1.0f, 20, 0, 0.08f }, // blue: edit mode entities + { PT_PART, 0.0f, 0.0f, 1.0f, 20, 0, 0.08f }, // blue: edit mode closest ent { PT_BLOOD, 0.5f, 0.0f, 0.0f, 1, 4, 0.3f }, // red: blood spats { PT_PART, 1.0f, 0.1f, 0.1f, 0, 1, 0.2f }, // red: demotrack { PT_FIREBALL, 1.0f, 0.5f, 0.5f, 0, 2, 7.0f }, // explosion fireball { PT_SHOTLINE, 1.0f, 1.0f, 0.7f, 0, -1, 0.0f }, // yellow: shotline - { PT_BULLETHOLE, 1.0f, 1.0f, 1.0f, 0, 3, 0.3f }, // hole decal + { PT_BULLETHOLE, 1.0f, 1.0f, 1.0f, 0, 3, 0.3f }, // hole decal { PT_STAIN, 0.5f, 0.0f, 0.0f, 0, 4, 0.6f }, // red: blood stain { PT_DECAL, 1.0f, 1.0f, 1.0f, 0, 5, 1.5f }, // scorch decal - { PT_HUDFLASH, 1.0f, 1.0f, 1.0f, 0, 6, 0.7f }, // hudgun muzzle flash - { PT_FLASH, 1.0f, 1.0f, 1.0f, 0, 6, 0.7f }, // muzzle flash - { PT_PART, 1.0f, 0.5f, 0.2f, 20, 0, 0.08f }, // orange: edit mode closest ent + { PT_HUDFLASH, 1.0f, 1.0f, 1.0f, 0, 6, 0.7f }, // hudgun muzzle flash + { PT_FLASH, 1.0f, 1.0f, 1.0f, 0, 6, 0.7f }, // muzzle flash + { PT_PART, 1.0f, 1.0f, 1.0f, 20, 0, 0.08f }, // white: edit mode ent type : light + { PT_PART, 0.0f, 1.0f, 0.0f, 20, 0, 0.08f }, // green: edit mode ent type : spawn + { PT_PART, 1.0f, 0.0f, 0.0f, 20, 0, 0.08f }, // red: edit mode ent type : ammo + { PT_PART, 1.0f, 1.0f, 0.0f, 20, 0, 0.08f }, // yellow: edit mode ent type : pickup + { PT_PART, 1.0f, 0.0f, 1.0f, 20, 0, 0.08f }, // magenta: edit mode ent type : model, sound + { PT_PART, 1.0f, 0.5f, 0.2f, 20, 0, 0.08f }, // orange: edit mode ent type : "carrot" + { PT_PART, 0.5f, 0.5f, 0.5f, 20, 0, 0.08f }, // grey: edit mode ent type : ladder, (pl)clip + { PT_PART, 0.0f, 1.0f, 1.0f, 20, 0, 0.08f }, // turquoise: edit mode ent type : CTF-flag }; VAR(particlesize, 20, 100, 500); @@ -328,7 +335,7 @@ void render_particles(int time, int typemask) case PT_BLOOD: glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); - glColor3f(1-pt.r, 1-pt.g, 1-pt.b); + glColor3f(1-pt.r, 1-pt.g, 1-pt.b); glBegin(GL_QUADS); break; @@ -337,9 +344,9 @@ void render_particles(int time, int typemask) glBegin(GL_QUADS); break; } - + for(particle *p, **pp = &parlist[i]; (p = *pp);) - { + { switch(pt.type) { case PT_HUDFLASH: @@ -353,7 +360,7 @@ void render_particles(int time, int typemask) vec(-camright.x-camup.x, -camright.y-camup.y, -camright.z-camup.z) }; loopk(4) corners[k].rotate(p->d.x, p->d.y, camdir).mul(sz*p->d.z).add(p->o); - + glTexCoord2i(0, 1); glVertex3fv(corners[0].v); glTexCoord2i(1, 1); glVertex3fv(corners[1].v); glTexCoord2i(1, 0); glVertex3fv(corners[2].v); @@ -370,7 +377,7 @@ void render_particles(int time, int typemask) glTexCoord2i(0, 0); glVertex3f(p->o.x+(-camright.x-camup.x)*sz, p->o.y+(-camright.y-camup.y)*sz, p->o.z+(-camright.z-camup.z)*sz); xtraverts += 4; break; - + case PT_FIREBALL: { sz = 1.0f + (pt.sz-1.0f)*min(p->fade, lastmillis-p->millis)/p->fade; @@ -386,11 +393,11 @@ void render_particles(int time, int typemask) glRotatef(lastmillis/7.0f, 0, 0, 1); glScalef(-sz, sz, -sz); drawexplosion(inside, pt.r, pt.g, pt.b, 1.0f-sz/pt.sz); - glPopMatrix(); + glPopMatrix(); xtraverts += heminumverts; break; } - + case PT_SHOTLINE: glVertex3f(p->o.x, p->o.y, p->o.z); glVertex3f(p->d.x, p->d.y, p->d.z); @@ -402,7 +409,7 @@ void render_particles(int time, int typemask) sqr *s = S((int)p->o.x, (int)p->o.y); glColor4f(s->r/127.5f, s->g/127.5f, s->b/127.5, max(0.0f, min((p->millis+p->fade - lastmillis)/1000.0f, 0.7f))); vec dx(0, 0, 0), dy(0, 0, 0); - loopk(3) if(p->d[k]) { dx[(k+1)%3] = -1; dy[(k+2)%3] = p->d[k]; break; } + loopk(3) if(p->d[k]) { dx[(k+1)%3] = -1; dy[(k+2)%3] = p->d[k]; break; } int o = detrnd((size_t)p, 11); static const int tc[4][2] = { {0, 1}, {1, 1}, {1, 0}, {0, 0} }; glTexCoord2i(tc[o%4][0], tc[o%4][1]); glVertex3f(p->o.x+(-dx.x+dy.x)*pt.sz, p->o.y+(-dx.y+dy.y)*pt.sz, p->o.z+(-dx.z+dy.z)*pt.sz); @@ -419,11 +426,11 @@ void render_particles(int time, int typemask) glColor4f(pt.r*blend, pt.g*blend, pt.b*blend, blend); vec dx(0, 0, 0), dy(0, 0, 0); int tx = 0, ty = 1; - loopk(3) if(p->d[k]) - { - dx[(k+1)%3] = -1; dy[(k+2)%3] = p->d[k]; + loopk(3) if(p->d[k]) + { + dx[(k+1)%3] = -1; dy[(k+2)%3] = p->d[k]; if(k<2) { tx = k^1; ty = 2; } - break; + break; } glTexCoord2f(0.5f+0.5f*(-dx[tx]+dy[tx]), 0.5f+0.5f*(-dx[ty]+dy[ty])); glVertex3f(p->o.x+(-dx.x+dy.x)*pt.sz, p->o.y+(-dx.y+dy.y)*pt.sz, p->o.z+(-dx.z+dy.z)*pt.sz); glTexCoord2f(0.5f+0.5f*( dx[tx]+dy[tx]), 0.5f+0.5f*( dx[ty]+dy[ty])); glVertex3f(p->o.x+( dx.x+dy.x)*pt.sz, p->o.y+( dx.y+dy.y)*pt.sz, p->o.z+( dx.z+dy.z)*pt.sz); @@ -445,7 +452,7 @@ void render_particles(int time, int typemask) xtraverts += 4; break; } - + case PT_STAIN: { float blend = max(0.0f, min((p->millis+p->fade - lastmillis)/1000.0f, 1.0f)); @@ -463,7 +470,7 @@ void render_particles(int time, int typemask) break; } } - + if(time < 0) pp = &p->next; else if(!p->fade || lastmillis-p->millis>p->fade) { @@ -474,7 +481,7 @@ void render_particles(int time, int typemask) else { if(pt.gr) p->o.z -= ((lastmillis-p->millis)/3.0f)*time/(pt.gr*10000); - if(pt.type==PT_PART || pt.type==PT_BLOOD) + if(pt.type==PT_PART || pt.type==PT_BLOOD) { p->o.add(vec(p->d).mul(time/20000.0f)); if(OUTBORD((int)p->o.x, (int)p->o.y)) @@ -486,7 +493,7 @@ void render_particles(int time, int typemask) } } if(pt.type==PT_BLOOD) - { + { sqr *s = S((int)p->o.x, (int)p->o.y); if(s->type==SPACE && p->o.z<=s->floor) { @@ -500,7 +507,7 @@ void render_particles(int time, int typemask) pp = &p->next; } } - + switch(pt.type) { case PT_HUDFLASH: @@ -521,7 +528,7 @@ void render_particles(int time, int typemask) case PT_FIREBALL: cleanupexplosion(); break; - } + } if(pt.tex<0) glEnable(GL_TEXTURE_2D); } @@ -538,7 +545,7 @@ void particle_emit(int type, int *args, int basetime, int seed, const vec &p) if(type<0 || type>=MAXPARTYPES) return; parttype &pt = parttypes[type]; if(pt.type==PT_FIREBALL) particle_fireball(type, p); - else if(pt.type==PT_FLASH || pt.type==PT_HUDFLASH) + else if(pt.type==PT_FLASH || pt.type==PT_HUDFLASH) { if(lastmillis - basetime < args[0]) particle_flash(type, args[1]>0 ? args[1]/100.0f : 1.0f, seed%360, p); @@ -641,7 +648,7 @@ void addshotline(dynent *pl, const vec &from, const vec &to) if(pl == player1 || !shotlinettl || !shotline) return; bool fx = shotlinettl > 0 && (player1->isspectating() || !multiplayer(false)); // allow fx only in spect mode and locally if(rnd(3) && !fx) return; // show all shotlines when fx enabled - + int start = (camera1->o.dist(to) <= 10.0f) ? 8 : 5; vec unitv; float dist = to.dist(from, unitv);