Skip to content

Commit

Permalink
Store short vertices in RAM
Browse files Browse the repository at this point in the history
  • Loading branch information
viciious committed Oct 30, 2023
1 parent efc577c commit b609248
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 85 deletions.
10 changes: 5 additions & 5 deletions am_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ static void AM_Drawer_ (int c)
for (i=0 ; i<numlines ; i++,line++)
{
int flags;
vertex_t *v1, *v2;
mapvertex_t *v1, *v2;

flags = line->flags;
if ((!(flags & ML_MAPPED) || /* IF NOT MAPPED OR DON'T DRAW */
Expand All @@ -666,8 +666,8 @@ static void AM_Drawer_ (int c)
v1 = &vertexes[line->v1];
v2 = &vertexes[line->v2];

y1 = v1->y;
y2 = v2->y;
y1 = v1->y << FRACBITS;
y2 = v2->y << FRACBITS;

y1 -= oy;
y2 -= oy;
Expand All @@ -684,8 +684,8 @@ static void AM_Drawer_ (int c)
outcode2 |= (y2 < miny) ;
if (outcode & outcode2) continue;

x1 = v1->x;
x2 = v2->x;
x1 = v1->x << FRACBITS;
x2 = v2->x << FRACBITS;

x1 -= ox;
x2 -= ox;
Expand Down
8 changes: 4 additions & 4 deletions p_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ static boolean PB_BoxCrossLine(line_t *ld, pmovetest_t *mt)
x2 = mt->testbbox[BOXLEFT ];
}

lx = vertexes[ld->v1].x;
ly = vertexes[ld->v1].y;
ldx = (vertexes[ld->v2].x - vertexes[ld->v1].x) >> FRACBITS;
ldy = (vertexes[ld->v2].y - vertexes[ld->v1].y) >> FRACBITS;
lx = vertexes[ld->v1].x << FRACBITS;
ly = vertexes[ld->v1].y << FRACBITS;
ldx = vertexes[ld->v2].x - vertexes[ld->v1].x;
ldy = vertexes[ld->v2].y - vertexes[ld->v1].y;

dx1 = (x1 - lx) >> FRACBITS;
dy1 = (mt->testbbox[BOXTOP] - ly) >> FRACBITS;
Expand Down
12 changes: 6 additions & 6 deletions p_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ boolean P_TryMove (ptrymove_t *tm, mobj_t *thing, fixed_t x, fixed_t y)
===============
*/

fixed_t P_InterceptVector (divline_t *v2, divline_t *v1)
static fixed_t P_InterceptVector (divline_t *v2, divline_t *v1)
{
fixed_t frac, num, den;

Expand All @@ -117,12 +117,12 @@ fixed_t P_InterceptVector (divline_t *v2, divline_t *v1)
==============
*/

void P_MakeDivline (line_t *li, divline_t *dl)
static void P_MakeDivline (line_t *li, divline_t *dl)
{
dl->x = vertexes[li->v1].x;
dl->y = vertexes[li->v1].y;
dl->dx = vertexes[li->v2].x - vertexes[li->v1].x;
dl->dy = vertexes[li->v2].y - vertexes[li->v1].y;
dl->x = vertexes[li->v1].x << FRACBITS;
dl->y = vertexes[li->v1].y << FRACBITS;
dl->dx = (vertexes[li->v2].x - vertexes[li->v1].x) << FRACBITS;
dl->dy = (vertexes[li->v2].y - vertexes[li->v1].y) << FRACBITS;
}


Expand Down
15 changes: 10 additions & 5 deletions p_maputl.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ int P_PointOnLineSide (fixed_t x, fixed_t y, line_t *line)
ldx = vertexes[line->v2].x - vertexes[line->v1].x;
ldy = vertexes[line->v2].y - vertexes[line->v1].y;

dx = (x - vertexes[line->v1].x);
dy = (y - vertexes[line->v1].y);
dx = x - (vertexes[line->v1].x << FRACBITS);
dy = y - (vertexes[line->v1].y << FRACBITS);

left = (ldy>>16) * (dx>>16);
right = (dy>>16) * (ldx>>16);
left = (ldy) * (dx>>16);
right = (dy>>16) * (ldx);

if (right < left)
return 0; /* front side */
Expand Down Expand Up @@ -138,7 +138,7 @@ fixed_t P_LineOpening (line_t *linedef)

void P_LineBBox(line_t* ld, fixed_t *bbox)
{
vertex_t* v1 = &vertexes[ld->v1], * v2 = &vertexes[ld->v2];
mapvertex_t* v1 = &vertexes[ld->v1], * v2 = &vertexes[ld->v2];

if (v1->x < v2->x)
{
Expand All @@ -160,6 +160,11 @@ void P_LineBBox(line_t* ld, fixed_t *bbox)
bbox[BOXBOTTOM] = v2->y;
bbox[BOXTOP] = v1->y;
}

bbox[BOXTOP] <<= FRACBITS;
bbox[BOXBOTTOM] <<= FRACBITS;
bbox[BOXLEFT] <<= FRACBITS;
bbox[BOXRIGHT] <<= FRACBITS;
}

/*
Expand Down
7 changes: 5 additions & 2 deletions p_move.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,11 @@ static boolean PM_BoxCrossLine(line_t *ld, pmovework_t *mw)

lx = vertexes[ld->v1].x;
ly = vertexes[ld->v1].y;
ldx = (vertexes[ld->v2].x - lx) >> FRACBITS;
ldy = (vertexes[ld->v2].y - ly) >> FRACBITS;
ldx = vertexes[ld->v2].x - lx;
ldy = vertexes[ld->v2].y - ly;

lx <<= FRACBITS;
ly <<= FRACBITS;

dx1 = (x1 - lx) >> FRACBITS;
dy1 = (y1 - ly) >> FRACBITS;
Expand Down
20 changes: 10 additions & 10 deletions p_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "mars.h"

int numvertexes;
vertex_t *vertexes;
mapvertex_t *vertexes;

int numsegs;
seg_t *segs;
Expand Down Expand Up @@ -54,19 +54,19 @@ void P_LoadVertexes (int lump)
byte *data;
int i;
mapvertex_t *ml;
vertex_t *li;
mapvertex_t *li;

numvertexes = W_LumpLength (lump) / sizeof(mapvertex_t);
vertexes = Z_Malloc (numvertexes*sizeof(vertex_t) + 16,PU_LEVEL);
vertexes = Z_Malloc (numvertexes*sizeof(mapvertex_t) + 16,PU_LEVEL);
vertexes = (void*)(((uintptr_t)vertexes + 15) & ~15); // aline on cacheline boundary
data = W_GetLumpData(lump);

ml = (mapvertex_t *)data;
li = vertexes;
for (i=0 ; i<numvertexes ; i++, li++, ml++)
{
li->x = LITTLESHORT(ml->x)<<FRACBITS;
li->y = LITTLESHORT(ml->y)<<FRACBITS;
li->x = LITTLESHORT(ml->x);
li->y = LITTLESHORT(ml->y);
}
}

Expand Down Expand Up @@ -340,7 +340,7 @@ void P_LoadLineDefs (int lump)
int i;
maplinedef_t *mld;
line_t *ld;
vertex_t *v1, *v2;
mapvertex_t *v1, *v2;

numlines = W_LumpLength (lump) / sizeof(maplinedef_t);
lines = Z_Malloc (numlines*sizeof(line_t)+16,PU_LEVEL);
Expand All @@ -360,8 +360,8 @@ void P_LoadLineDefs (int lump)
ld->v2 = LITTLESHORT(mld->v2);
v1 = &vertexes[ld->v1];
v2 = &vertexes[ld->v2];
dx = v2->x - v1->x;
dy = v2->y - v1->y;
dx = (v2->x - v1->x) << FRACBITS;
dy = (v2->y - v1->y) << FRACBITS;
if (!dx)
ld->flags |= ML_ST_VERTICAL;
else if (!dy)
Expand Down Expand Up @@ -568,8 +568,8 @@ void P_GroupLines (void)
for (j=0 ; j<sector->linecount ; j++)
{
li = lines + sector->lines[j];
M_AddToBox (bbox, vertexes[li->v1].x, vertexes[li->v1].y);
M_AddToBox (bbox, vertexes[li->v2].x, vertexes[li->v2].y);
M_AddToBox (bbox, vertexes[li->v1].x << FRACBITS, vertexes[li->v1].y << FRACBITS);
M_AddToBox (bbox, vertexes[li->v2].x << FRACBITS, vertexes[li->v2].y << FRACBITS);
}

/* set the degenmobj_t to the middle of the bounding box */
Expand Down
30 changes: 15 additions & 15 deletions p_shoot.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ typedef struct
fixed_t shootx, shooty, shootz; // location for puff/blood
} shootWork_t;

static fixed_t PA_SightCrossLine(shootWork_t *sw, vertex_t *v1, vertex_t *v2) ATTR_DATA_CACHE_ALIGN;
static fixed_t PA_SightCrossLine(shootWork_t *sw, mapvertex_t *v1, mapvertex_t *v2) ATTR_DATA_CACHE_ALIGN;
static boolean PA_ShootLine(shootWork_t *sw, line_t* li, fixed_t interceptfrac) ATTR_DATA_CACHE_ALIGN;
static boolean PA_ShootThing(shootWork_t *sw, mobj_t* th, fixed_t interceptfrac) ATTR_DATA_CACHE_ALIGN;
static boolean PA_DoIntercept(shootWork_t *sw, intercept_t* in) ATTR_DATA_CACHE_ALIGN;
Expand All @@ -84,16 +84,16 @@ void P_Shoot2(lineattack_t *la) ATTR_DATA_CACHE_ALIGN;
// the intersection occurs at. If 0 < intercept < 1.0, the line will block
// the sight.
//
static fixed_t PA_SightCrossLine(shootWork_t *sw, vertex_t *v1, vertex_t *v2)
static fixed_t PA_SightCrossLine(shootWork_t *sw, mapvertex_t *v1, mapvertex_t *v2)
{
fixed_t s1, s2;
fixed_t p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y, dx, dy, ndx, ndy;

// p1, p2 are endpoints
p1x = v1->x >> FRACBITS;
p1y = v1->y >> FRACBITS;
p2x = v2->x >> FRACBITS;
p2y = v2->y >> FRACBITS;
p1x = v1->x;
p1y = v1->y;
p2x = v2->x;
p2y = v2->y;

// p3, p4 are sight endpoints
p3x = sw->ssx1;
Expand Down Expand Up @@ -284,7 +284,7 @@ static boolean PA_CrossSubsector(shootWork_t *sw, int bspnum)
mobj_t *thing;
subsector_t *sub = &subsectors[bspnum];
intercept_t in;
vertex_t tv1, tv2;
mapvertex_t tv1, tv2;
VINT *lvalidcount, vc;

// check things
Expand All @@ -298,17 +298,17 @@ static boolean PA_CrossSubsector(shootWork_t *sw, int bspnum)
// check a corner to corner cross-section for hit
if(sw->shootdivpositive)
{
tv1.x = thing->x - thing->radius;
tv1.y = thing->y + thing->radius;
tv2.x = thing->x + thing->radius;
tv2.y = thing->y - thing->radius;
tv1.x = (thing->x - thing->radius) >> FRACBITS;
tv1.y = (thing->y + thing->radius) >> FRACBITS;
tv2.x = (thing->x + thing->radius) >> FRACBITS;
tv2.y = (thing->y - thing->radius) >> FRACBITS;
}
else
{
tv1.x = thing->x - thing->radius;
tv1.y = thing->y - thing->radius;
tv2.x = thing->x + thing->radius;
tv2.y = thing->y + thing->radius;
tv1.x = (thing->x - thing->radius) >> FRACBITS;
tv1.y = (thing->y - thing->radius) >> FRACBITS;
tv2.x = (thing->x + thing->radius) >> FRACBITS;
tv2.y = (thing->y + thing->radius) >> FRACBITS;
}

frac = PA_SightCrossLine(sw, &tv1, &tv2);
Expand Down
22 changes: 12 additions & 10 deletions p_sight.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ static boolean PS_CrossSubsector(sightWork_t *sw, int num)
fixed_t opentop;
fixed_t openbottom;
divline_t divl;
vertex_t *v1;
vertex_t *v2;
vertex_t v1, v2;
fixed_t frac;
fixed_t slope;
int side;
Expand Down Expand Up @@ -201,19 +200,22 @@ static boolean PS_CrossSubsector(sightWork_t *sw, int num)
continue;
lvalidcount[seg->linedef] = vc;

v1 = &vertexes[line->v1];
v2 = &vertexes[line->v2];
s1 = P_DivlineSide(v1->x, v1->y, strace);
s2 = P_DivlineSide(v2->x, v2->y, strace);
v1.x = vertexes[line->v1].x << FRACBITS;
v1.y = vertexes[line->v1].y << FRACBITS;
v2.x = vertexes[line->v2].x << FRACBITS;
v2.y = vertexes[line->v2].y << FRACBITS;

s1 = P_DivlineSide(v1.x, v1.y, strace);
s2 = P_DivlineSide(v2.x, v2.y, strace);

// line isn't crossed?
if (s1 == s2)
continue;

divl.x = v1->x;
divl.y = v1->y;
divl.dx = v2->x - v1->x;
divl.dy = v2->y - v1->y;
divl.x = v1.x;
divl.y = v1.y;
divl.dx = v2.x - v1.x;
divl.dy = v2.y - v1.y;
s1 = P_DivlineSide (strace->x, strace->y, &divl);
s2 = P_DivlineSide (t2x, t2y, &divl);

Expand Down
39 changes: 22 additions & 17 deletions p_slide.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef struct
fixed_t endbox[4]; // final proposed position
fixed_t nvx, nvy; // normalized line vector

vertex_t *p1, *p2; // p1, p2 are line endpoints
vertex_t p1, p2; // p1, p2 are line endpoints
fixed_t p3x, p3y, p4x, p4y; // p3, p4 are move endpoints

int numspechit;
Expand All @@ -62,8 +62,8 @@ static int SL_PointOnSide(pslidework_t *sw, fixed_t x, fixed_t y)
{
fixed_t dx, dy, dist;

dx = x - sw->p1->x;
dy = y - sw->p1->y;
dx = x - sw->p1.x;
dy = y - sw->p1.y;

dx = FixedMul(dx, sw->nvx);
dy = FixedMul(dy, sw->nvy);
Expand All @@ -85,14 +85,14 @@ static fixed_t SL_CrossFrac(pslidework_t *sw)
fixed_t dx, dy, dist1, dist2;

// project move start and end points onto line normal
dx = sw->p3x - sw->p1->x;
dy = sw->p3y - sw->p1->y;
dx = sw->p3x - sw->p1.x;
dy = sw->p3y - sw->p1.y;
dx = FixedMul(dx, sw->nvx);
dy = FixedMul(dy, sw->nvy);
dist1 = dx + dy;

dx = sw->p4x - sw->p1->x;
dy = sw->p4y - sw->p1->y;
dx = sw->p4x - sw->p1.x;
dy = sw->p4y - sw->p1.y;
dx = FixedMul(dx, sw->nvx);
dy = FixedMul(dy, sw->nvy);
dist2 = dx + dy;
Expand Down Expand Up @@ -162,7 +162,7 @@ static boolean SL_CheckLine(line_t *ld, pslidework_t *sw)
fixed_t opentop, openbottom;
sector_t *front, *back;
int side1;
vertex_t *vtmp;
vertex_t vtmp;
fixed_t ldbbox[4];

P_LineBBox(ld, ldbbox);
Expand Down Expand Up @@ -201,8 +201,10 @@ static boolean SL_CheckLine(line_t *ld, pslidework_t *sw)

// the line is definitely blocking movement at this point
findfrac:
sw->p1 = &vertexes[ld->v1];
sw->p2 = &vertexes[ld->v2];
sw->p1.x = vertexes[ld->v1].x << FRACBITS;
sw->p1.y = vertexes[ld->v1].y << FRACBITS;
sw->p2.x = vertexes[ld->v2].x << FRACBITS;
sw->p2.y = vertexes[ld->v2].y << FRACBITS;
sw->nvx = finesine(ld->fineangle);
sw->nvy = -finecosine(ld->fineangle);

Expand All @@ -215,9 +217,12 @@ static boolean SL_CheckLine(line_t *ld, pslidework_t *sw)
if(ld->sidenum[1] == -1)
return true; // don't clip to backs of one-sided lines
// reverse coordinates and angle
vtmp = sw->p1;
sw->p1 = sw->p2;
sw->p2 = vtmp;
vtmp.x = sw->p1.x;
vtmp.y = sw->p1.y;
sw->p1.x = sw->p2.x;
sw->p1.y = sw->p2.y;
sw->p2.x = vtmp.x;
sw->p2.y = vtmp.y;
sw->nvx = -sw->nvx;
sw->nvy = -sw->nvy;
break;
Expand Down Expand Up @@ -424,10 +429,10 @@ static void SL_CheckSpecialLines(pslidework_t *sw)
continue;
}

x3 = vertexes[ld->v1].x;
y3 = vertexes[ld->v1].y;
x4 = vertexes[ld->v2].x;
y4 = vertexes[ld->v2].y;
x3 = vertexes[ld->v1].x << FRACBITS;
y3 = vertexes[ld->v1].y << FRACBITS;
x4 = vertexes[ld->v2].x << FRACBITS;
y4 = vertexes[ld->v2].y << FRACBITS;

side1 = SL_PointOnSide2(x1, y1, x3, y3, x4, y4);
side2 = SL_PointOnSide2(x2, y2, x3, y3, x4, y4);
Expand Down
2 changes: 1 addition & 1 deletion r_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ extern spritedef_t sprites[NUMSPRITES];
*/

extern int numvertexes;
extern vertex_t *vertexes;
extern mapvertex_t *vertexes;

extern int numsegs;
extern seg_t *segs;
Expand Down
Loading

0 comments on commit b609248

Please sign in to comment.