Refactor linedef type 5 (Camera Scanner)

This commit is contained in:
Jaime Ita Passos 2021-04-08 15:13:39 -03:00
parent 1db163f942
commit 7fdcba5014
7 changed files with 86 additions and 73 deletions

View file

@ -1706,7 +1706,7 @@ void T_RaiseSector(raise_t *raise)
P_RecalcPrecipInSector(&sectors[i]); P_RecalcPrecipInSector(&sectors[i]);
} }
void T_CameraScanner(elevator_t *elevator) void T_CameraScanner(scanner_t *scanner)
{ {
// leveltime is compared to make multiple scanners in one map function correctly. // leveltime is compared to make multiple scanners in one map function correctly.
static tic_t lastleveltime = 32000; // any number other than 0 should do here static tic_t lastleveltime = 32000; // any number other than 0 should do here
@ -1720,58 +1720,28 @@ void T_CameraScanner(elevator_t *elevator)
if (players[displayplayer].mo) if (players[displayplayer].mo)
{ {
if (players[displayplayer].mo->subsector->sector == elevator->actionsector) if (players[displayplayer].mo->subsector->sector == scanner->actionsector)
{ {
if (t_cam_dist == -42) camera.scanner.height = scanner->height;
t_cam_dist = cv_cam_dist.value; camera.scanner.dist = scanner->dist;
if (t_cam_height == -42) camera.scanner.rotate = &scanner->rotate;
t_cam_height = cv_cam_height.value;
if (t_cam_rotate == -42)
t_cam_rotate = cv_cam_rotate.value;
CV_SetValue(&cv_cam_height, FixedInt(elevator->sector->floorheight));
CV_SetValue(&cv_cam_dist, FixedInt(elevator->sector->ceilingheight));
CV_SetValue(&cv_cam_rotate, elevator->distance);
camerascanned = true; camerascanned = true;
} }
else if (!camerascanned) else if (!camerascanned)
{ P_ResetCameraScanner(&camera);
if (t_cam_height != -42 && cv_cam_height.value != t_cam_height)
CV_Set(&cv_cam_height, va("%f", (double)FIXED_TO_FLOAT(t_cam_height)));
if (t_cam_dist != -42 && cv_cam_dist.value != t_cam_dist)
CV_Set(&cv_cam_dist, va("%f", (double)FIXED_TO_FLOAT(t_cam_dist)));
if (t_cam_rotate != -42 && cv_cam_rotate.value != t_cam_rotate)
CV_Set(&cv_cam_rotate, va("%f", (double)t_cam_rotate));
t_cam_dist = t_cam_height = t_cam_rotate = -42;
}
} }
if (splitscreen && players[secondarydisplayplayer].mo) if (splitscreen && players[secondarydisplayplayer].mo)
{ {
if (players[secondarydisplayplayer].mo->subsector->sector == elevator->actionsector) if (players[secondarydisplayplayer].mo->subsector->sector == scanner->actionsector)
{ {
if (t_cam2_rotate == -42) camera2.scanner.height = scanner->height;
t_cam2_dist = cv_cam2_dist.value; camera2.scanner.dist = scanner->dist;
if (t_cam2_rotate == -42) camera2.scanner.rotate = &scanner->rotate;
t_cam2_height = cv_cam2_height.value;
if (t_cam2_rotate == -42)
t_cam2_rotate = cv_cam2_rotate.value;
CV_SetValue(&cv_cam2_height, FixedInt(elevator->sector->floorheight));
CV_SetValue(&cv_cam2_dist, FixedInt(elevator->sector->ceilingheight));
CV_SetValue(&cv_cam2_rotate, elevator->distance);
camerascanned2 = true; camerascanned2 = true;
} }
else if (!camerascanned2) else if (!camerascanned2)
{ P_ResetCameraScanner(&camera2);
if (t_cam2_height != -42 && cv_cam2_height.value != t_cam2_height)
CV_Set(&cv_cam2_height, va("%f", (double)FIXED_TO_FLOAT(t_cam2_height)));
if (t_cam2_dist != -42 && cv_cam2_dist.value != t_cam2_dist)
CV_Set(&cv_cam2_dist, va("%f", (double)FIXED_TO_FLOAT(t_cam2_dist)));
if (t_cam2_rotate != -42 && cv_cam2_rotate.value != t_cam2_rotate)
CV_Set(&cv_cam2_rotate, va("%f", (double)t_cam2_rotate));
t_cam2_dist = t_cam2_height = t_cam2_rotate = -42;
}
} }
} }

View file

@ -89,10 +89,7 @@ typedef struct camera_s
angle_t startangle; angle_t startangle;
// Camera demobjerization // Camera demobjerization
// Info for drawing: position.
fixed_t x, y, z; fixed_t x, y, z;
//More drawing info: to determine current sprite.
angle_t angle; // orientation angle_t angle; // orientation
struct subsector_s *subsector; struct subsector_s *subsector;
@ -109,6 +106,14 @@ typedef struct camera_s
// Momentums, used to update position. // Momentums, used to update position.
fixed_t momx, momy, momz; fixed_t momx, momy, momz;
// Camera scanner effect (linedef type 5).
struct
{
fixed_t *height;
fixed_t *dist;
INT32 *rotate;
} scanner;
} camera_t; } camera_t;
extern camera_t camera, camera2; extern camera_t camera, camera2;
@ -122,16 +127,15 @@ extern consvar_t cv_cam_savedist[2][2], cv_cam_saveheight[2][2];
void CV_UpdateCamDist(void); void CV_UpdateCamDist(void);
void CV_UpdateCam2Dist(void); void CV_UpdateCam2Dist(void);
extern fixed_t t_cam_dist, t_cam_height, t_cam_rotate; void P_ResetCamera(player_t *player, camera_t *thiscam);
extern fixed_t t_cam2_dist, t_cam2_height, t_cam2_rotate; void P_ResetCameraScanner(camera_t *thiscam);
boolean P_TryCameraMove(fixed_t x, fixed_t y, camera_t *thiscam);
void P_SlideCameraMove(camera_t *thiscam);
boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcalled);
INT32 P_GetPlayerControlDirection(player_t *player); INT32 P_GetPlayerControlDirection(player_t *player);
void P_AddPlayerScore(player_t *player, UINT32 amount); void P_AddPlayerScore(player_t *player, UINT32 amount);
void P_StealPlayerScore(player_t *player, UINT32 amount); void P_StealPlayerScore(player_t *player, UINT32 amount);
void P_ResetCamera(player_t *player, camera_t *thiscam);
boolean P_TryCameraMove(fixed_t x, fixed_t y, camera_t *thiscam);
void P_SlideCameraMove(camera_t *thiscam);
boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcalled);
pflags_t P_GetJumpFlags(player_t *player); pflags_t P_GetJumpFlags(player_t *player);
boolean P_PlayerInPain(player_t *player); boolean P_PlayerInPain(player_t *player);
void P_DoPlayerPain(player_t *player, mobj_t *source, mobj_t *inflictor); void P_DoPlayerPain(player_t *player, mobj_t *source, mobj_t *inflictor);

View file

@ -2210,6 +2210,15 @@ static inline void SaveDynamicSlopeThinker(const thinker_t *th, const UINT8 type
WRITEMEM(save_p, ht->vex, sizeof(ht->vex)); WRITEMEM(save_p, ht->vex, sizeof(ht->vex));
} }
static void SaveScannerThinker(const thinker_t *th, const UINT8 type)
{
const scanner_t *ht = (const void *)th;
WRITEUINT8(save_p, type);
WRITEUINT32(save_p, SaveSector(ht->sector));
WRITEUINT32(save_p, SaveSector(ht->actionsector));
WRITEINT32(save_p, ht->rotate);
}
static inline void SavePolyrotatetThinker(const thinker_t *th, const UINT8 type) static inline void SavePolyrotatetThinker(const thinker_t *th, const UINT8 type)
{ {
const polyrotate_t *ht = (const void *)th; const polyrotate_t *ht = (const void *)th;
@ -2407,7 +2416,7 @@ static void P_NetArchiveThinkers(void)
} }
else if (th->function.acp1 == (actionf_p1)T_CameraScanner) else if (th->function.acp1 == (actionf_p1)T_CameraScanner)
{ {
SaveElevatorThinker(th, tc_camerascanner); SaveScannerThinker(th, tc_camerascanner);
continue; continue;
} }
else if (th->function.acp1 == (actionf_p1)T_Scroll) else if (th->function.acp1 == (actionf_p1)T_Scroll)
@ -3381,6 +3390,18 @@ static inline thinker_t* LoadDynamicSlopeThinker(actionf_p1 thinker)
return &ht->thinker; return &ht->thinker;
} }
static thinker_t* LoadScannerThinker(actionf_p1 thinker)
{
scanner_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL);
ht->thinker.function.acp1 = thinker;
ht->sector = LoadSector(READUINT32(save_p));
ht->actionsector = LoadSector(READUINT32(save_p));
ht->height = &ht->sector->floorheight;
ht->dist = &ht->sector->ceilingheight;
ht->rotate = READINT32(save_p);
return &ht->thinker;
}
static inline thinker_t* LoadPolyrotatetThinker(actionf_p1 thinker) static inline thinker_t* LoadPolyrotatetThinker(actionf_p1 thinker)
{ {
polyrotate_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL); polyrotate_t *ht = Z_Malloc(sizeof (*ht), PU_LEVSPEC, NULL);
@ -3602,7 +3623,7 @@ static void P_NetUnArchiveThinkers(void)
break; break;
case tc_camerascanner: case tc_camerascanner:
th = LoadElevatorThinker((actionf_p1)T_CameraScanner, false); th = LoadScannerThinker((actionf_p1)T_CameraScanner);
break; break;
case tc_bouncecheese: case tc_bouncecheese:

View file

@ -3755,6 +3755,9 @@ static void P_SetupCamera(void)
camera.subsector = R_PointInSubsector(camera.x, camera.y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18) camera.subsector = R_PointInSubsector(camera.x, camera.y); // make sure camera has a subsector set -- Monster Iestyn (12/11/18)
} }
} }
P_ResetCameraScanner(&camera);
P_ResetCameraScanner(&camera2);
} }
static void P_InitCamera(void) static void P_InitCamera(void)

View file

@ -5896,21 +5896,21 @@ static void P_AddEachTimeThinker(line_t *sourceline)
*/ */
static inline void P_AddCameraScanner(sector_t *sourcesec, sector_t *actionsector, angle_t angle) static inline void P_AddCameraScanner(sector_t *sourcesec, sector_t *actionsector, angle_t angle)
{ {
elevator_t *elevator; // Why not? LOL scanner_t *scanner;
CONS_Alert(CONS_WARNING, M_GetText("Detected a camera scanner effect (linedef type 5). This effect is deprecated and will be removed in the future!\n")); //CONS_Alert(CONS_WARNING, M_GetText("Detected a camera scanner effect (linedef type 5). This effect is deprecated and will be removed in the future!\n"));
// create and initialize new elevator thinker // create and initialize the new scanner thinker
elevator = Z_Calloc(sizeof (*elevator), PU_LEVSPEC, NULL); scanner = Z_Calloc(sizeof (*scanner), PU_LEVSPEC, NULL);
P_AddThinker(THINK_MAIN, &elevator->thinker); P_AddThinker(THINK_MAIN, &scanner->thinker);
elevator->thinker.function.acp1 = (actionf_p1)T_CameraScanner; scanner->thinker.function.acp1 = (actionf_p1)T_CameraScanner;
elevator->type = elevateBounce; scanner->sector = sourcesec;
scanner->actionsector = actionsector;
// set up the fields according to the type of elevator action scanner->height = &sourcesec->floorheight;
elevator->sector = sourcesec; scanner->dist = &sourcesec->ceilingheight;
elevator->actionsector = actionsector; scanner->rotate = FixedInt(AngleFixed(angle));
elevator->distance = FixedInt(AngleFixed(angle));
} }
/** Flashes a laser block. /** Flashes a laser block.

View file

@ -407,6 +407,16 @@ typedef struct
boolean triggerOnExit; boolean triggerOnExit;
} eachtime_t; } eachtime_t;
typedef struct
{
thinker_t thinker;
sector_t *sector;
sector_t *actionsector;
fixed_t *height;
fixed_t *dist;
INT32 rotate;
} scanner_t;
typedef enum typedef enum
{ {
RF_REVERSE = 1, //Lower when stood on RF_REVERSE = 1, //Lower when stood on
@ -464,7 +474,7 @@ void T_MarioBlockChecker(mariocheck_t *block);
void T_ThwompSector(thwomp_t *thwomp); void T_ThwompSector(thwomp_t *thwomp);
void T_NoEnemiesSector(noenemies_t *nobaddies); void T_NoEnemiesSector(noenemies_t *nobaddies);
void T_EachTimeThinker(eachtime_t *eachtime); void T_EachTimeThinker(eachtime_t *eachtime);
void T_CameraScanner(elevator_t *elevator); void T_CameraScanner(scanner_t *scanner);
void T_RaiseSector(raise_t *raise); void T_RaiseSector(raise_t *raise);
typedef struct typedef struct

View file

@ -9721,13 +9721,6 @@ void CV_UpdateCam2Dist(void)
CV_Set(&cv_cam2_height, va("%f", FIXED_TO_FLOAT(cv_cam_saveheight[cv_useranalog[1].value][1].value))); CV_Set(&cv_cam2_height, va("%f", FIXED_TO_FLOAT(cv_cam_saveheight[cv_useranalog[1].value][1].value)));
} }
fixed_t t_cam_dist = -42;
fixed_t t_cam_height = -42;
fixed_t t_cam_rotate = -42;
fixed_t t_cam2_dist = -42;
fixed_t t_cam2_height = -42;
fixed_t t_cam2_rotate = -42;
#define MAXCAMERADIST 140*FRACUNIT // Max distance the camera can be in front of the player (2D mode) #define MAXCAMERADIST 140*FRACUNIT // Max distance the camera can be in front of the player (2D mode)
void P_ResetCamera(player_t *player, camera_t *thiscam) void P_ResetCamera(player_t *player, camera_t *thiscam)
@ -9915,6 +9908,13 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
camheight = FixedMul(cv_cam2_height.value, mo->scale); camheight = FixedMul(cv_cam2_height.value, mo->scale);
} }
if (thiscam->scanner.height)
camheight = (*thiscam->scanner.height);
if (thiscam->scanner.dist)
camdist = (*thiscam->scanner.dist);
if (thiscam->scanner.rotate)
camrotate = (*thiscam->scanner.rotate);
if (!(twodlevel || (mo->flags2 & MF2_TWOD)) && !(player->powers[pw_carry] == CR_NIGHTSMODE)) if (!(twodlevel || (mo->flags2 & MF2_TWOD)) && !(player->powers[pw_carry] == CR_NIGHTSMODE))
camheight = FixedMul(camheight, player->camerascale); camheight = FixedMul(camheight, player->camerascale);
@ -9966,8 +9966,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
else else
angle = focusangle + FixedAngle(camrotate*FRACUNIT); angle = focusangle + FixedAngle(camrotate*FRACUNIT);
if (!resetcalled && (cv_analog[0].value || demoplayback) && ((thiscam == &camera && t_cam_rotate != -42) || (thiscam == &camera2 if (!resetcalled && (cv_analog[0].value || demoplayback) && thiscam->scanner.rotate)
&& t_cam2_rotate != -42)))
{ {
angle = FixedAngle(camrotate*FRACUNIT); angle = FixedAngle(camrotate*FRACUNIT);
thiscam->angle = angle; thiscam->angle = angle;
@ -10468,7 +10467,13 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
} }
return (x == thiscam->x && y == thiscam->y && z == thiscam->z && angle == thiscam->aiming); return (x == thiscam->x && y == thiscam->y && z == thiscam->z && angle == thiscam->aiming);
}
void P_ResetCameraScanner(camera_t *thiscam)
{
thiscam->scanner.height = NULL;
thiscam->scanner.dist = NULL;
thiscam->scanner.rotate = NULL;
} }
boolean P_SpectatorJoinGame(player_t *player) boolean P_SpectatorJoinGame(player_t *player)