d3xp now also can use the new portalskies

This commit is contained in:
«BielBdeLuna» 2024-06-25 12:59:38 +02:00
parent 8d8a09c9a4
commit 6f459b3b58
6 changed files with 160 additions and 6 deletions

View file

@ -296,6 +296,9 @@ void idGameLocal::Clear( void ) {
portalSkyEnt = NULL;
portalSkyActive = false;
playerOldEyePos.Zero();
globalPortalSky = false;
ResetSlowTimeVars();
#endif
}
@ -630,6 +633,12 @@ void idGameLocal::SaveGame( idFile *f ) {
#ifdef _D3XP
portalSkyEnt.Save( &savegame );
savegame.WriteBool( portalSkyActive );
savegame.WriteBool( globalPortalSky );
savegame.WriteInt( currentPortalSkyType );
savegame.WriteVec3( playerOldEyePos );
savegame.WriteVec3( portalSkyGlobalOrigin );
savegame.WriteVec3( portalSkyOrigin );
fast.Save( &savegame );
slow.Save( &savegame );
@ -1018,6 +1027,9 @@ void idGameLocal::LoadMap( const char *mapName, int randseed ) {
#ifdef _D3XP
portalSkyEnt = NULL;
portalSkyActive = false;
playerOldEyePos.Zero();
globalPortalSky = false;
ResetSlowTimeVars();
#endif
@ -1539,6 +1551,12 @@ bool idGameLocal::InitFromSaveGame( const char *mapName, idRenderWorld *renderWo
#ifdef _D3XP
portalSkyEnt.Restore( &savegame );
savegame.ReadBool( portalSkyActive );
savegame.ReadBool( globalPortalSky );
savegame.ReadInt( currentPortalSkyType );
savegame.ReadVec3( playerOldEyePos );
savegame.ReadVec3( portalSkyGlobalOrigin );
savegame.ReadVec3( portalSkyOrigin );
fast.Restore( &savegame );
slow.Restore( &savegame );
@ -4796,13 +4814,55 @@ void idGameLocal::SetPortalSkyEnt( idEntity *ent ) {
/*
=================
idPlayer::IsPortalSkyAcive
idPlayer::IsPortalSkyActive
=================
*/
bool idGameLocal::IsPortalSkyAcive() {
bool idGameLocal::IsPortalSkyActive() {
return portalSkyActive;
}
/*
=================
idGameLocal::CheckGlobalPortalSky
=================
*/
bool idGameLocal::CheckGlobalPortalSky() {
return globalPortalSky;
}
/*
=================
idGameLocal::SetGlobalPortalSky
=================
*/
void idGameLocal::SetGlobalPortalSky( const char *name ) {
if ( CheckGlobalPortalSky() ) {
Error( "idGameLocal::SetGlobalPortalSky : more than one global portalSky:\ndelete them until you have just one.\nportalSky '%s' causes it.", name );
}
else {
globalPortalSky = true;
}
}
/*
=================
idGameLocal::SetCurrentPortalSkyType
=================
*/
void idGameLocal::SetCurrentPortalSkyType( int type ) {
currentPortalSkyType = type;
}
/*
=================
idGameLocal::GetCurrentPortalSkyType
=================
*/
int idGameLocal::GetCurrentPortalSkyType() {
return currentPortalSkyType;
}
/*
===========
idGameLocal::SelectTimeGroup

View file

@ -166,6 +166,12 @@ typedef struct {
#endif
} spawnSpot_t;
enum {
PORTALSKY_STANDARD = 0, // classic portalsky
PORTALSKY_GLOBAL = 1, // always following portal sky
PORTALSKY_LOCAL = 2, // following portal sky from a spot
};
//============================================================================
class idEventQueue {
@ -324,8 +330,20 @@ public:
idEntityPtr<idEntity> portalSkyEnt;
bool portalSkyActive;
bool globalPortalSky;
int portalSkyScale;
int currentPortalSkyType; // 0 = classic, 1 = global, 2 = local
idVec3 portalSkyOrigin;
idVec3 portalSkyGlobalOrigin;
idVec3 playerOldEyePos;
void SetPortalSkyEnt( idEntity *ent );
bool IsPortalSkyAcive();
bool IsPortalSkyActive();
bool CheckGlobalPortalSky();
void SetGlobalPortalSky(const char *name);
void SetCurrentPortalSkyType(int type); // 0 = classic, 1 = global, 2 = local
int GetCurrentPortalSkyType(); // 0 = classic, 1 = global, 2 = local
timeState_t fast;
timeState_t slow;

View file

@ -3737,7 +3737,15 @@ idPortalSky::Spawn
===============
*/
void idPortalSky::Spawn( void ) {
if ( spawnArgs.GetInt( "type" ) == PORTALSKY_GLOBAL ) {
gameLocal.SetGlobalPortalSky( spawnArgs.GetString( "name" ) );
gameLocal.portalSkyGlobalOrigin = GetPhysics()->GetOrigin();
}
if ( !spawnArgs.GetBool( "triggered" ) ) {
if ( spawnArgs.GetInt( "type" ) != PORTALSKY_STANDARD ) {
gameLocal.portalSkyScale = spawnArgs.GetInt( "scale", "16" );
}
PostEventMS( &EV_PostSpawn, 1 );
}
}
@ -3748,6 +3756,13 @@ idPortalSky::Event_PostSpawn
================
*/
void idPortalSky::Event_PostSpawn() {
gameLocal.SetCurrentPortalSkyType( spawnArgs.GetInt( "type", "0" ) );
if ( gameLocal.GetCurrentPortalSkyType() != PORTALSKY_GLOBAL ) {
gameLocal.portalSkyOrigin = GetPhysics()->GetOrigin();
// both standard and local portalSky share the origin, it's in the execution that things change.
}
gameLocal.SetPortalSkyEnt( this );
}
@ -3757,6 +3772,14 @@ idPortalSky::Event_Activate
================
*/
void idPortalSky::Event_Activate( idEntity *activator ) {
gameLocal.SetCurrentPortalSkyType( spawnArgs.GetInt( "type", "0" ) );
if ( gameLocal.GetCurrentPortalSkyType() != PORTALSKY_GLOBAL ) {
gameLocal.portalSkyOrigin = GetPhysics()->GetOrigin();
// both standard and local portalSky share the origin, it's in the execution that things change.
}
gameLocal.portalSkyScale = spawnArgs.GetInt( "scale", "16" );
gameLocal.SetPortalSkyEnt( this );
}
#endif /* _D3XP */

View file

@ -484,9 +484,42 @@ void idPlayerView::SingleView( idUserInterface *hud, const renderView_t *view )
hackedView.viewaxis = hackedView.viewaxis * ShakeAxis();
#ifdef _D3XP
if ( gameLocal.portalSkyEnt.GetEntity() && gameLocal.IsPortalSkyAcive() && g_enablePortalSky.GetBool() ) {
idVec3 diff, currentEyePos, PSOrigin, Zero;
Zero.Zero();
if ( ( gameLocal.CheckGlobalPortalSky() ) || ( gameLocal.GetCurrentPortalSkyType() == PORTALSKY_LOCAL ) ) {
// in a case of a moving portalSky
currentEyePos = hackedView.vieworg;
if ( gameLocal.playerOldEyePos == Zero ) {
gameLocal.playerOldEyePos = currentEyePos;
//initialize playerOldEyePos, this will only happen in one tick.
}
diff = ( currentEyePos - gameLocal.playerOldEyePos) / gameLocal.portalSkyScale;
gameLocal.portalSkyGlobalOrigin += diff; // this is for the global portalSky.
// It should keep going even when not active.
}
if ( gameLocal.portalSkyEnt.GetEntity() && gameLocal.IsPortalSkyActive() && g_enablePortalSky.GetBool() ) {
if ( gameLocal.GetCurrentPortalSkyType() == PORTALSKY_STANDARD ) {
PSOrigin = gameLocal.portalSkyOrigin;
}
if ( gameLocal.GetCurrentPortalSkyType() == PORTALSKY_GLOBAL ) {
PSOrigin = gameLocal.portalSkyGlobalOrigin;
}
if ( gameLocal.GetCurrentPortalSkyType() == PORTALSKY_LOCAL ) {
gameLocal.portalSkyOrigin += diff;
PSOrigin = gameLocal.portalSkyOrigin;
}
gameLocal.playerOldEyePos = currentEyePos;
renderView_t portalView = hackedView;
portalView.vieworg = gameLocal.portalSkyEnt.GetEntity()->GetPhysics()->GetOrigin();
portalView.vieworg = PSOrigin;
// setup global fixup projection vars
if ( 1 ) {
@ -512,10 +545,15 @@ void idPlayerView::SingleView( idUserInterface *hud, const renderView_t *view )
renderSystem->CaptureRenderToImage( "_currentRender" );
hackedView.forceUpdate = true; // FIX: for smoke particles not drawing when portalSky present
} else {
gameLocal.playerOldEyePos = currentEyePos;
// so if g_enablePortalSky is disabled GlobalPortalSkies don't broke
// when g_enablePortalSky gets re-enabled GlPS keep working
}
// process the frame
fxManager->Process( &hackedView );
gameRenderWorld->RenderScene( &hackedView );
#endif
if ( player->spectating ) {

View file

@ -1439,6 +1439,13 @@ bool idPVS::CheckAreasForPortalSky( const pvsHandle_t handle, const idVec3 &orig
sourceArea = gameRenderWorld->PointInArea( origin );
if ( sourceArea == -1 ) {
// this is the case where the player is not in any AAS area;
// this is, he is in noclip mode out of the map. let's do a global/local PS check!
if ( gameLocal.CheckGlobalPortalSky() || ( gameLocal.GetCurrentPortalSkyType() == PORTALSKY_LOCAL ) ) {
//this is... if the current PS is local, or there exist a global PS in the map, even if it's not current...
return true; // in any one of those cases keep callculating for the global or the local portalSky
}
return false;
}
@ -1453,6 +1460,13 @@ bool idPVS::CheckAreasForPortalSky( const pvsHandle_t handle, const idVec3 &orig
}
}
// here if the player is in an unreachable AAS like inisde a sealed room, where he teleports in,
// the function will return false. so let's repeat the global/local PS check!
if ( gameLocal.CheckGlobalPortalSky() || ( gameLocal.GetCurrentPortalSkyType() == PORTALSKY_LOCAL ) ) {
//this is... if the current PS is local, or there exist a global PS in the map, even if it's not current...
return true; // in any one of those cases keep callculating for the global or the local portalSky
}
return false;
}
#endif

View file

@ -527,6 +527,7 @@ void idPlayerView::SingleView( idUserInterface *hud, const renderView_t *view )
// when g_enablePortalSky gets re-enabled GlobalPortalSkies keep working
}
// process the frame
gameRenderWorld->RenderScene( &hackedView );
if ( player->spectating ) {