Skip to content

Commit

Permalink
Revert "Revert the dual-CPU P_CheckSights implementation"
Browse files Browse the repository at this point in the history
This reverts commit 79bb7f5.
  • Loading branch information
viciious committed Aug 6, 2023
1 parent 48d578d commit bece363
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 5 deletions.
15 changes: 15 additions & 0 deletions mars.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ enum

MARS_SECCMD_AM_DRAW,

MARS_SECCMD_P_SIGHT_CHECKS,

MARS_SECCMD_MELT_DO_WIPE,

MARS_SECCMD_NUMCMDS
Expand All @@ -63,6 +65,7 @@ void Mars_Sec_R_DrawPlanes(void) ATTR_DATA_CACHE_ALIGN;
void Mars_Sec_R_PreDrawPlanes(void) ATTR_DATA_CACHE_ALIGN;
void Mars_Sec_R_DrawSprites(int sprscreenhalf, int *sortedsprites) ATTR_DATA_CACHE_ALIGN;
void Mars_Sec_R_DrawPSprites(int sprscreenhalf) ATTR_DATA_CACHE_ALIGN;
void Mars_Sec_P_CheckSights(void) ATTR_DATA_CACHE_ALIGN;
void Mars_Sec_wipe_doMelt(void);

void Mars_Sec_M_AnimateFire(void) ATTR_OPTIMIZE_EXTREME;
Expand Down Expand Up @@ -162,6 +165,18 @@ static inline void Mars_AM_EndDrawer(void)
Mars_R_SecWait();
}

static inline void Mars_P_BeginCheckSights(void)
{
while (MARS_SYS_COMM4 != 0) {};
MARS_SYS_COMM6 = 0;
MARS_SYS_COMM4 = MARS_SECCMD_P_SIGHT_CHECKS;
}

static inline void Mars_P_EndCheckSights(void)
{
while (MARS_SYS_COMM4 != 0);
}

static inline void Mars_melt_BeginWipe(short *yy)
{
while (MARS_SYS_COMM4 != 0) {};
Expand Down
3 changes: 3 additions & 0 deletions marsnew.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ void Mars_Secondary(void)
case MARS_SECCMD_AM_DRAW:
Mars_Sec_AM_Drawer();
break;
case MARS_SECCMD_P_SIGHT_CHECKS:
Mars_Sec_P_CheckSights();
break;
case MARS_SECCMD_MELT_DO_WIPE:
Mars_Sec_wipe_doMelt();
break;
Expand Down
6 changes: 6 additions & 0 deletions p_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,12 @@ void P_RunMobjBase2(void)

for (mo = mobjhead.next; mo != (void*)&mobjhead; mo = next)
{
#ifdef MARS
// clear cache for mobj flags following the sight check as
// the other CPU might have modified the MF_SEETARGET state
if (mo->tics == 1)
Mars_ClearCacheLine(&mo->flags);
#endif
next = mo->next; /* in case mo is removed this time */
if (!mo->player)
P_MobjThinker(mo);
Expand Down
115 changes: 111 additions & 4 deletions p_sight.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ static boolean PS_CrossSubsector(sightWork_t* sw, int num) ATTR_DATA_CACHE_ALIGN
static boolean PS_CrossBSPNode(sightWork_t* sw, int bspnum) ATTR_DATA_CACHE_ALIGN;
static boolean PS_RejectCheckSight(mobj_t* t1, mobj_t* t2) ATTR_DATA_CACHE_ALIGN;
static boolean P_MobjCanSightCheck(mobj_t *mobj) ATTR_DATA_CACHE_ALIGN;
static mobj_t *P_GetSightMobj(mobj_t *pmobj, int c, int *pcnt) ATTR_DATA_CACHE_ALIGN;
static boolean PS_CheckSight2(mobj_t* t1, mobj_t* t2) ATTR_DATA_CACHE_ALIGN;
void P_CheckSights2(void) ATTR_DATA_CACHE_ALIGN __attribute__((noinline));
#ifdef MARS
void P_CheckSights2(int c) ATTR_DATA_CACHE_ALIGN;
#else
void P_CheckSights2(void) ATTR_DATA_CACHE_ALIGN;
#endif

//
// Returns side 0 (front), 1 (back), or 2 (on).
Expand Down Expand Up @@ -389,18 +394,120 @@ static boolean P_MobjCanSightCheck(mobj_t *mobj)
return true;
}

#ifdef MARS
static char ps_lock = 0;

static void P_LockSight(void)
{
int res;
do {
__asm volatile (\
"tas.b %1\n\t" \
"movt %0\n\t" \
: "=&r" (res) \
: "m" (ps_lock) \
);
} while (res == 0);
}

static void P_UnlockSight(void)
{
ps_lock = 0;
}

static mobj_t *P_GetSightMobj(mobj_t *mobj, int c, int *pcnt)
{
int next;
int cnt = *pcnt;

P_LockSight();

for (next = MARS_SYS_COMM6; ; next++)
{
if (c == 1)
{
for (; cnt < next; cnt++)
{
if (mobj == (void*)&mobjhead)
goto done;
Mars_ClearCacheLine(&mobj->next);
mobj = mobj->next;
}
Mars_ClearCacheLines(mobj, (sizeof(mobj_t)+31)/16);
}
else
{
for (; cnt < next; cnt++)
{
if (mobj == (void*)&mobjhead)
goto done;
mobj = mobj->next;
}
}

if (P_MobjCanSightCheck(mobj))
break;
}

done:
MARS_SYS_COMM6 = cnt + 1;

P_UnlockSight();

*pcnt = cnt;
return mobj;
}

#define P_NextSightMobj(mobj) (mobj)

#else

static mobj_t *P_GetSightMobj(mobj_t *mobj, int c, int *pcnt)
{
for ( ; mobj != (void*)&mobjhead; mobj = mobj->next)
{
if (P_MobjCanSightCheck(mobj))
break;
}
return mobj;
}

#define P_NextSightMobj(mobj) (mobj)->next

#endif

//
// Optimal mobj sight checking that checks sights in the main tick loop rather
// than from multiple mobj action routines.
//
#ifdef MARS
void P_CheckSights2(int c)
#else
void P_CheckSights2(void)
#endif
{
mobj_t *mobj;
int cnt = 0;
#ifndef MARS
int c = 0;
#else
mobj_t *ctrgt = NULL;
Mars_ClearCacheLines(&mobjhead.next, 1);
#endif

for (mobj = mobjhead.next; mobj != (void*)&mobjhead; mobj = mobj->next)
for (mobj = mobjhead.next; ; mobj = P_NextSightMobj(mobj))
{
if (!P_MobjCanSightCheck(mobj))
continue;
if ((mobj = P_GetSightMobj(mobj, c, &cnt)) == (void*)&mobjhead)
return;

#ifdef MARS
if (c == 1 && ctrgt != mobj->target)
{
Mars_ClearCacheLines(mobj->target, (sizeof(mobj_t)+31)/16);
ctrgt = mobj->target;
}
#endif

if (PS_CheckSight2(mobj, mobj->target))
mobj->flags |= MF_SEETARGET;
}
Expand Down
17 changes: 16 additions & 1 deletion p_tick.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,28 @@ void P_RunThinkers (void)
===============
*/

void P_CheckSights2(void);
#ifdef MARS
void P_CheckSights2(int c) ATTR_DATA_CACHE_ALIGN ATTR_OPTIMIZE_SIZE;
#else
void P_CheckSights2(void) ATTR_DATA_CACHE_ALIGN ATTR_OPTIMIZE_SIZE;
#endif

#ifdef MARS
void Mars_Sec_P_CheckSights(void)
{
P_CheckSights2(1);
}
#endif

void P_CheckSights (void)
{
#ifdef JAGUAR
extern int p_sight_start;
DSPFunction (&p_sight_start);
#elif defined(MARS)
Mars_P_BeginCheckSights();
P_CheckSights2(0);
Mars_P_EndCheckSights();
#else
P_CheckSights2();
#endif
Expand Down

0 comments on commit bece363

Please sign in to comment.