From 9241ab974a4d48d468ca41df9ace8d5d9348abd2 Mon Sep 17 00:00:00 2001 From: plagman Date: Sun, 19 Apr 2009 17:23:07 +0000 Subject: [PATCH] Don't step over the bounds of the plane buffer in buffertoplane (now computeplane). git-svn-id: https://svn.eduke32.com/eduke32@1334 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/polymer.h | 2 +- polymer/eduke32/build/src/polymer.c | 39 ++++++++++++++++--------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/polymer/eduke32/build/include/polymer.h b/polymer/eduke32/build/include/polymer.h index e6f0afc1c..14813b6db 100644 --- a/polymer/eduke32/build/include/polymer.h +++ b/polymer/eduke32/build/include/polymer.h @@ -291,7 +291,7 @@ static int32_t polymer_initwall(int16_t wallnum); static void polymer_updatewall(int16_t wallnum); static void polymer_drawwall(int16_t sectnum, int16_t wallnum); // HSR -static void polymer_buffertoplane(GLfloat* buffer, GLushort* indices, int32_t indicecount, GLfloat* plane, GLfloat* t, GLfloat* b, GLfloat* n); +static void polymer_computeplane(_prplane* p); static inline void polymer_crossproduct(GLfloat* in_a, GLfloat* in_b, GLfloat* out); static inline void polymer_transformpoint(float* inpos, float* pos, float* matrix); static inline void polymer_pokesector(int16_t sectnum); diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index a3ef7f6f0..eee0f5feb 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -988,7 +988,7 @@ void polymer_drawsprite(int32_t snum) i++; } - polymer_buffertoplane(spriteplane.buffer, NULL, 4, spriteplane.plane, spriteplane.t, spriteplane.b, spriteplane.n); + polymer_computeplane(&spriteplane); spriteplane.lightcount = 0; i = 0; @@ -1765,10 +1765,8 @@ finish: if (wallinvalidate) { s->invalidid++; - polymer_buffertoplane(s->floor.buffer, s->floor.indices, s->indicescount, s->floor.plane, - s->floor.t, s->floor.b, s->floor.n); - polymer_buffertoplane(s->ceil.buffer, s->ceil.indices, s->indicescount, s->ceil.plane, - s->ceil.t, s->ceil.b, s->ceil.n); + polymer_computeplane(&s->floor); + polymer_computeplane(&s->ceil); } s->controlstate = 1; @@ -2331,10 +2329,10 @@ static void polymer_updatewall(int16_t wallnum) w->cap[10] += 1048576; // this one is arbitrary if (w->underover & 1) - polymer_buffertoplane(w->wall.buffer, NULL, 4, w->wall.plane, w->wall.t, w->wall.b, w->wall.n); + polymer_computeplane(&w->wall); if (w->underover & 2) - polymer_buffertoplane(w->over.buffer, NULL, 4, w->over.plane, w->over.t, w->over.b, w->over.n); - polymer_buffertoplane(w->mask.buffer, NULL, 4, w->mask.plane, w->mask.t, w->mask.b, w->mask.n); + polymer_computeplane(&w->over); + polymer_computeplane(&w->mask); if ((pr_vbos > 0)) { @@ -2409,17 +2407,28 @@ static void polymer_drawwall(int16_t sectnum, int16_t wallnum) if (pr_verbosity >= 3) OSD_Printf("PR : Finished drawing wall %i...\n", wallnum); } -#define INDICE(n) ((indices) ? (indices[i+n]*5) : ((i+n)*5)) +#define INDICE(n) ((p->indices) ? (p->indices[i+n]*5) : ((i+n)*5)) // HSR -static void polymer_buffertoplane(GLfloat* buffer, GLushort* indices, int32_t indicecount, GLfloat* plane, GLfloat* t, GLfloat* b, GLfloat* n) +static void polymer_computeplane(_prplane* p) { GLfloat vec1[5], vec2[5], norm, r;// BxN[3], NxT[3], TxB[3]; int32_t i; + GLfloat* buffer; + GLfloat* t; + GLfloat* b; + GLfloat* n; + GLfloat* plane; - if (indices && (indicecount < 3)) + if (p->indices && (p->indicescount < 3)) return; // corrupt sector (E3L4, I'm looking at you) + buffer = p->buffer; + t = p->t; + b = p->b; + n = p->n; + plane = p->plane; + i = 0; do { @@ -2439,7 +2448,9 @@ static void polymer_buffertoplane(GLfloat* buffer, GLushort* indices, in norm = plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]; - if (norm >= 15000) // hack to work around a precision issue with slopes + // hack to work around a precision issue with slopes + if ((norm >= 15000) || + (((p->indices) ? p->indices[i+2] : i+2) >= p->vertcount)) { // normalize the normal/plane equation and calculate its plane norm norm = -sqrt(norm); @@ -2508,9 +2519,9 @@ static void polymer_buffertoplane(GLfloat* buffer, GLushort* indices, in break; } - i+= 3; + i+= 1; } - while (i < indicecount); + while (i < p->indicescount); } static inline void polymer_crossproduct(GLfloat* in_a, GLfloat* in_b, GLfloat* out)