Skip to content

3 types of portal skies, the standard, the global (the one like HL2 ), and the local for cutscenes #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added base/portalsky_00.pk4
Binary file not shown.
64 changes: 62 additions & 2 deletions d3xp/Game_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ void idGameLocal::Clear( void ) {
portalSkyEnt = NULL;
portalSkyActive = false;

playerOldEyePos.Zero();
globalPortalSky = false;

ResetSlowTimeVars();
#endif
}
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -1018,6 +1027,9 @@ void idGameLocal::LoadMap( const char *mapName, int randseed ) {
#ifdef _D3XP
portalSkyEnt = NULL;
portalSkyActive = false;

playerOldEyePos.Zero();
globalPortalSky = false;

ResetSlowTimeVars();
#endif
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion d3xp/Game_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -324,8 +330,20 @@ class idGameLocal : public idGame {
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;
Expand Down
23 changes: 23 additions & 0 deletions d3xp/Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
Expand All @@ -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 );
}

Expand All @@ -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 */
44 changes: 41 additions & 3 deletions d3xp/PlayerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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 ) {
Expand Down
14 changes: 14 additions & 0 deletions d3xp/Pvs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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
Loading