diff --git a/src/p_floor.c b/src/p_floor.c index 8b4b515fe..a5c358621 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -1581,7 +1581,7 @@ static INT32 P_HavePlayersEnteredArea(boolean *curPlayers, boolean *oldPlayers, // // \sa P_AddEachTimeThinker // -void T_EachTimeThinker(levelspecthink_t *eachtime) +void T_EachTimeThinker(eachtime_t *eachtime) { size_t i, j; sector_t *sec = NULL; @@ -1604,19 +1604,10 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) for (i = 0; i < MAXPLAYERS; i++) { - if (i & 1) - { - oldPlayersInArea[i] = eachtime->vars[i/2] & 65535; - oldPlayersOnArea[i] = eachtime->var2s[i/2] & 65535; - eachtime->vars[i/2] = 0; - eachtime->var2s[i/2] = 0; - } - else - { - oldPlayersInArea[i] = eachtime->vars[i/2] >> 16; - oldPlayersOnArea[i] = eachtime->var2s[i/2] >> 16; - } - + oldPlayersInArea[i] = eachtime->playersInArea[i]; + oldPlayersOnArea[i] = eachtime->playersOnArea[i]; + eachtime->playersInArea[i] = false; + eachtime->playersOnArea[i] = false; playersInArea[i] = false; playersOnArea[i] = false; } @@ -1705,20 +1696,12 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) if (floortouch == true && P_IsObjectOnGroundIn(players[j].mo, targetsec)) { - if (j & 1) - eachtime->var2s[j/2] |= 1; - else - eachtime->var2s[j/2] |= 1 << 16; - + eachtime->playersOnArea[j] = true; playersOnArea[j] = true; } else { - if (j & 1) - eachtime->vars[j/2] |= 1; - else - eachtime->vars[j/2] |= 1 << 16; - + eachtime->playersInArea[j] = true; playersInArea[j] = true; } } @@ -1766,27 +1749,19 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) if (floortouch == true && P_IsObjectOnRealGround(players[i].mo, sec)) { - if (i & 1) - eachtime->var2s[i/2] |= 1; - else - eachtime->var2s[i/2] |= 1 << 16; - + eachtime->playersOnArea[i] = true; playersOnArea[i] = true; } else { - if (i & 1) - eachtime->vars[i/2] |= 1; - else - eachtime->vars[i/2] |= 1 << 16; - + eachtime->playersInArea[i] = true; playersInArea[i] = true; } } } } - if ((eachtime->sourceline->flags & ML_BOUNCY) == ML_BOUNCY) + if (eachtime->triggerOnExit) inAndOut = true; // Check if a new player entered. diff --git a/src/p_saveg.c b/src/p_saveg.c index c93756983..58fb7ad52 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1659,6 +1659,24 @@ static void SaveSpecialLevelThinker(const thinker_t *th, const UINT8 type) WRITEUINT32(save_p, SaveSector(ht->sector)); } +// SaveEachTimeThinker +// +// Loads a eachtime_t from a save game +// +static void SaveEachTimeThinker(const thinker_t *th, const UINT8 type) +{ + const eachtime_t *ht = (const void *)th; + size_t i; + WRITEUINT8(save_p, type); + WRITEUINT32(save_p, SaveLine(ht->sourceline)); + for (i = 0; i < MAXPLAYERS; i++) + { + WRITECHAR(save_p, ht->playersInArea[i]); + WRITECHAR(save_p, ht->playersOnArea[i]); + } + WRITECHAR(save_p, ht->triggerOnExit); +} + // SaveRaiseThinker // // Saves a raise_t thinker @@ -2250,7 +2268,7 @@ static void P_NetArchiveThinkers(void) } else if (th->function.acp1 == (actionf_p1)T_EachTimeThinker) { - SaveSpecialLevelThinker(th, tc_eachtime); + SaveEachTimeThinker(th, tc_eachtime); continue; } else if (th->function.acp1 == (actionf_p1)T_RaiseSector) @@ -2788,6 +2806,25 @@ static thinker_t* LoadSpecialLevelThinker(actionf_p1 thinker, UINT8 floorOrCeili return &ht->thinker; } +// LoadEachTimeThinker +// +// Loads a eachtime_t from a save game +// +static thinker_t* LoadEachTimeThinker(actionf_p1 thinker) +{ + size_t i; + eachtime_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); + ht->thinker.function.acp1 = thinker; + ht->sourceline = LoadLine(READUINT32(save_p)); + for (i = 0; i < MAXPLAYERS; i++) + { + ht->playersInArea[i] = READCHAR(save_p); + ht->playersOnArea[i] = READCHAR(save_p); + } + ht->triggerOnExit = READCHAR(save_p); + return &ht->thinker; +} + // LoadRaiseThinker // // Loads a raise_t from a save game @@ -3481,7 +3518,7 @@ static void P_NetUnArchiveThinkers(void) break; case tc_eachtime: - th = LoadSpecialLevelThinker((actionf_p1)T_EachTimeThinker, 0); + th = LoadEachTimeThinker((actionf_p1)T_EachTimeThinker); break; case tc_raisesector: diff --git a/src/p_spec.c b/src/p_spec.c index a72f56cc0..7a99b1fad 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -6160,14 +6160,13 @@ static inline void P_AddNoEnemiesThinker(sector_t *sec, line_t *sourceline) /** Adds a thinker for Each-Time linedef executors. A linedef executor is run * only when a player enters the area and doesn't run again until they re-enter. * - * \param sec Control sector that contains the lines of executors we will want to run. * \param sourceline Control linedef. * \sa P_SpawnSpecials, T_EachTimeThinker * \author SSNTails */ -static void P_AddEachTimeThinker(sector_t *sec, line_t *sourceline) +static void P_AddEachTimeThinker(line_t *sourceline) { - levelspecthink_t *eachtime; + eachtime_t *eachtime; // create and initialize new thinker eachtime = Z_Calloc(sizeof (*eachtime), PU_LEVSPEC, NULL); @@ -6175,8 +6174,8 @@ static void P_AddEachTimeThinker(sector_t *sec, line_t *sourceline) eachtime->thinker.function.acp1 = (actionf_p1)T_EachTimeThinker; - eachtime->sector = sec; eachtime->sourceline = sourceline; + eachtime->triggerOnExit = !!(sourceline->flags & ML_BOUNCY); } /** Adds a camera scanner. @@ -7160,7 +7159,7 @@ void P_SpawnSpecials(boolean fromnetsave) case 332: case 335: sec = sides[*lines[i].sidenum].sector - sectors; - P_AddEachTimeThinker(§ors[sec], &lines[i]); + P_AddEachTimeThinker(&lines[i]); break; // No More Enemies Linedef Exec @@ -7192,7 +7191,7 @@ void P_SpawnSpecials(boolean fromnetsave) if (lines[i].special == 322) // Each time { sec = sides[*lines[i].sidenum].sector - sectors; - P_AddEachTimeThinker(§ors[sec], &lines[i]); + P_AddEachTimeThinker(&lines[i]); } break; diff --git a/src/p_spec.h b/src/p_spec.h index eb61ad7bf..8cccc96e4 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -320,6 +320,15 @@ typedef struct sector_t *sector; // Sector the thinker is from } levelspecthink_t; +typedef struct +{ + thinker_t thinker; + line_t *sourceline; // Source line of the thinker + boolean playersInArea[MAXPLAYERS]; + boolean playersOnArea[MAXPLAYERS]; + boolean triggerOnExit; +} eachtime_t; + typedef enum { RF_REVERSE = 1, //Lower when stood on @@ -377,7 +386,7 @@ void T_FloatSector(levelspecthink_t *floater); void T_MarioBlockChecker(levelspecthink_t *block); void T_ThwompSector(levelspecthink_t *thwomp); void T_NoEnemiesSector(levelspecthink_t *nobaddies); -void T_EachTimeThinker(levelspecthink_t *eachtime); +void T_EachTimeThinker(eachtime_t *eachtime); void T_CameraScanner(elevator_t *elevator); void T_RaiseSector(raise_t *raise);