From ab39eb353596b2d948cd2dcc0053f500dbdf4795 Mon Sep 17 00:00:00 2001 From: BielBdeLuna <7318.tk@gmail.com> Date: Tue, 28 May 2013 02:48:56 +0200 Subject: [PATCH 1/2] portalSky simple rendering addition --- neo/renderer/RenderWorld_load.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/renderer/RenderWorld_load.cpp b/neo/renderer/RenderWorld_load.cpp index f1605d77..88b19dc6 100644 --- a/neo/renderer/RenderWorld_load.cpp +++ b/neo/renderer/RenderWorld_load.cpp @@ -655,7 +655,7 @@ void idRenderWorldLocal::AddWorldModelEntities() { for ( int j = 0; j < hModel->NumSurfaces(); j++ ) { const modelSurface_t *surf = hModel->Surface( j ); - if ( surf->shader->GetName() == idStr( "textures/smf/portal_sky" ) ) { + if ( ( surf->shader->GetName() == idStr( "textures/smf/portal_sky" ) ) || ( surf->shader->GetName() == idStr( "textures/editor/portal_sky" ) ) ) { //7318 - portalsky - moded def->needsPortalSky = true; } } From 8225cd76ae83263c195f49ec37486cbe8d3e9475 Mon Sep 17 00:00:00 2001 From: BielBdeLuna <7318.tk@gmail.com> Date: Tue, 28 May 2013 03:03:23 +0200 Subject: [PATCH 2/2] portalSky 1.3 modification --- neo/game/Game_local.cpp | 117 +++++++++++++++++++++++++++++++++++ neo/game/Game_local.h | 38 ++++++++++++ neo/game/Item.cpp | 38 ++++++++++++ neo/game/Misc.cpp | 90 +++++++++++++++++++++++++++ neo/game/Misc.h | 21 +++++++ neo/game/Player.cpp | 11 ++++ neo/game/PlayerView.cpp | 92 ++++++++++++++++++++++++++- neo/game/Pvs.cpp | 52 ++++++++++++++++ neo/game/Pvs.h | 4 ++ neo/game/gamesys/SysCvar.cpp | 3 + neo/game/gamesys/SysCvar.h | 3 + 11 files changed, 468 insertions(+), 1 deletion(-) diff --git a/neo/game/Game_local.cpp b/neo/game/Game_local.cpp index d7c846cb..5b8fc601 100644 --- a/neo/game/Game_local.cpp +++ b/neo/game/Game_local.cpp @@ -252,6 +252,13 @@ void idGameLocal::Clear( void ) { savedEventQueue.Init(); memset( lagometer, 0, sizeof( lagometer ) ); + + //neuro start + portalSkyEnt = NULL; + portalSkyActive = false; + playerOldEyePos.Zero(); // 7318 + globalPortalSky = false; // 7318 + //neuro end } /* @@ -536,6 +543,17 @@ void idGameLocal::SaveGame( idFile *f ) { savegame.WriteBool( isNewFrame ); savegame.WriteFloat( clientSmoothing ); + //neuro start + portalSkyEnt.Save( &savegame ); + savegame.WriteBool( portalSkyActive ); + savegame.WriteBool( globalPortalSky ); // 7318 + savegame.WriteInt( currentPortalSkyType ); // 7318 + savegame.WriteVec3( playerOldEyePos ); // 7318 + savegame.WriteVec3( portalSkyGlobalOrigin ); // 7318 + savegame.WriteVec3( portalSkyOrigin ); // 7318 + + //neuro end + savegame.WriteBool( mapCycleLoaded ); savegame.WriteInt( spawnCount ); @@ -906,6 +924,13 @@ void idGameLocal::LoadMap( const char *mapName, int randseed ) { sessionCommand = ""; nextGibTime = 0; + //neuro start + portalSkyEnt = NULL; + portalSkyActive = false; + playerOldEyePos.Zero(); // 7318 + globalPortalSky = false;// 7318 + //neuro end + vacuumAreaNum = -1; // if an info_vacuum is spawned, it will set this if ( !editEntities ) { @@ -1353,6 +1378,16 @@ bool idGameLocal::InitFromSaveGame( const char *mapName, idRenderWorld *renderWo savegame.ReadBool( isNewFrame ); savegame.ReadFloat( clientSmoothing ); + //neuro start + portalSkyEnt.Restore( &savegame ); + savegame.ReadBool( portalSkyActive ); + savegame.ReadBool( globalPortalSky ); // 7318 + savegame.ReadInt( currentPortalSkyType ); // 7318 + savegame.ReadVec3( playerOldEyePos ); // 7318 + savegame.ReadVec3( portalSkyGlobalOrigin ); // 7318 + savegame.ReadVec3( portalSkyOrigin ); // 7318 + //neuro end + savegame.ReadBool( mapCycleLoaded ); savegame.ReadInt( spawnCount ); @@ -1999,6 +2034,25 @@ void idGameLocal::SetupPlayerPVS( void ) { pvs.FreeCurrentPVS( otherPVS ); playerConnectedAreas = newPVS; } + + //neuro start + // if portalSky is preset, then merge into pvs so we get rotating brushes, etc + if ( portalSkyEnt.GetEntity() ) { + idEntity *skyEnt = portalSkyEnt.GetEntity(); + + otherPVS = pvs.SetupCurrentPVS( skyEnt->GetPVSAreas(), skyEnt->GetNumPVSAreas() ); + newPVS = pvs.MergeCurrentPVS( playerPVS, otherPVS ); + pvs.FreeCurrentPVS( playerPVS ); + pvs.FreeCurrentPVS( otherPVS ); + playerPVS = newPVS; + + otherPVS = pvs.SetupCurrentPVS( skyEnt->GetPVSAreas(), skyEnt->GetNumPVSAreas() ); + newPVS = pvs.MergeCurrentPVS( playerConnectedAreas, otherPVS ); + pvs.FreeCurrentPVS( playerConnectedAreas ); + pvs.FreeCurrentPVS( otherPVS ); + playerConnectedAreas = newPVS; + } + //neuro end } } @@ -4268,6 +4322,69 @@ void idGameLocal::ThrottleUserInfo( void ) { mpGame.ThrottleUserInfo(); } +//neuro start +/* +================= +idGameLocal::SetPortalSkyEnt +================= +*/ +void idGameLocal::SetPortalSkyEnt( idEntity *ent ) { + portalSkyEnt = ent; +} + +/* +================= +idGameLocal::IsPortalSkyAcive +================= +*/ +bool idGameLocal::IsPortalSkyAcive() { + return portalSkyActive; +} + +/* +================= +idGameLocal::CheckGlobalPortalSky --> 7318 +================= +*/ +bool idGameLocal::CheckGlobalPortalSky() { + return globalPortalSky; +} + +/* +================= +idGameLocal::SetGlobalPortalSky --> 7318 +================= +*/ +void idGameLocal::SetGlobalPortalSky( const char *name ) { + + if ( CheckGlobalPortalSky() ) { + Error( "more than one global portalSky:\ndelete them until you have just one.\nportalSky '%s' causes it.", name ); + } + else { + globalPortalSky = true; + } +} + +/* +================= +idGameLocal::SetCurrentPortalSkyType --> 7318 +================= +*/ +void idGameLocal::SetCurrentPortalSkyType( int type ) { + currentPortalSkyType = type; +} + +/* +================= +idGameLocal::GetCurrentPortalSkyType --> 7318 +================= +*/ +int idGameLocal::GetCurrentPortalSkyType() { + return currentPortalSkyType; +} + +//neuro end + /* =========== idGameLocal::SelectTimeGroup diff --git a/neo/game/Game_local.h b/neo/game/Game_local.h index 1f724434..4595adfc 100644 --- a/neo/game/Game_local.h +++ b/neo/game/Game_local.h @@ -165,6 +165,16 @@ typedef struct { //============================================================================ +//7318 start +enum { + PORTALSKY_STANDARD = 0, // classic portalsky + PORTALSKY_GLOBAL = 1, // always following portal sky + PORTALSKY_LOCAL = 2, // following portal sky from a spot +}; +//7318 end + +//============================================================================ + class idEventQueue { public: typedef enum { @@ -294,6 +304,30 @@ public: idEntityPtr lastGUIEnt; // last entity with a GUI, used by Cmd_NextGUI_f int lastGUI; // last GUI on the lastGUIEnt + //neuro start + idEntityPtr portalSkyEnt; + bool portalSkyActive; + //7318 start + bool globalPortalSky; + int portalSkyScale; + int currentPortalSkyType; //0 = classic, 1 = global, 2 = local + idVec3 portalSkyOrigin; + idVec3 portalSkyGlobalOrigin; + idVec3 playerOldEyePos; + //7318 end + + + void SetPortalSkyEnt( idEntity *ent ); + bool IsPortalSkyAcive(); + //7318 start + 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 + //7318 end + + //neuro end + // ---------------------- Public idGame Interface ------------------- idGameLocal(); @@ -387,6 +421,10 @@ public: bool InPlayerPVS( idEntity *ent ) const; bool InPlayerConnectedArea( idEntity *ent ) const; + //Ivan_the_B start + pvsHandle_t GetPlayerPVS() { return playerPVS; }; + //Ivan_the_B end + void SetCamera( idCamera *cam ); idCamera * GetCamera( void ) const; bool SkipCinematic( void ); diff --git a/neo/game/Item.cpp b/neo/game/Item.cpp index 97ae9523..eac982d0 100644 --- a/neo/game/Item.cpp +++ b/neo/game/Item.cpp @@ -712,6 +712,44 @@ void idObjective::Event_CamShot( ) { renderView_t fullView = *view; fullView.width = SCREEN_WIDTH; fullView.height = SCREEN_HEIGHT; + + //neuro start + // HACK : always draw sky-portal view if there is one in the map, this isn't real-time + if ( gameLocal.portalSkyEnt.GetEntity() && g_enablePortalSky.GetBool() ) { + renderView_t portalView = fullView; + portalView.vieworg = gameLocal.portalSkyEnt.GetEntity()->GetPhysics()->GetOrigin(); + + // setup global fixup projection vars + if ( 1 ) { + int vidWidth, vidHeight; + idVec2 shiftScale; + + renderSystem->GetGLSettings( vidWidth, vidHeight ); + + float pot; + int temp; + + int w = vidWidth; + for (temp = 1 ; temp < w ; temp<<=1) { + } + pot = (float)temp; + shiftScale.x = (float)w / pot; + + int h = vidHeight; + for (temp = 1 ; temp < h ; temp<<=1) { + } + pot = (float)temp; + shiftScale.y = (float)h / pot; + + fullView.shaderParms[4] = shiftScale.x; + fullView.shaderParms[5] = shiftScale.y; + } + + gameRenderWorld->RenderScene( &portalView ); + renderSystem->CaptureRenderToImage( "_currentRender" ); + } + //neuro end + // draw a view to a texture renderSystem->CropRenderSize( 256, 256, true ); gameRenderWorld->RenderScene( &fullView ); diff --git a/neo/game/Misc.cpp b/neo/game/Misc.cpp index bfde7193..e0b79cd7 100644 --- a/neo/game/Misc.cpp +++ b/neo/game/Misc.cpp @@ -3156,3 +3156,93 @@ void idPhantomObjects::Think( void ) { BecomeInactive( TH_THINK ); } } +//neuro start +/* +=============================================================================== + +idPortalSky + +=============================================================================== +*/ + +CLASS_DECLARATION( idEntity, idPortalSky ) + EVENT( EV_PostSpawn, idPortalSky::Event_PostSpawn ) + EVENT( EV_Activate, idPortalSky::Event_Activate ) +END_CLASS + +/* +=============== +idPortalSky::idPortalSky +=============== +*/ +idPortalSky::idPortalSky( void ) { + +} + +/* +=============== +idPortalSky::~idPortalSky +=============== +*/ +idPortalSky::~idPortalSky( void ) { + +} + +/* +=============== +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 ); + } + + +} + +/* +================ +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 ); +} + +/* +================ +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 ); +} +//neuro end diff --git a/neo/game/Misc.h b/neo/game/Misc.h index 89a4235e..e0bc7268 100644 --- a/neo/game/Misc.h +++ b/neo/game/Misc.h @@ -765,4 +765,25 @@ private: idList lastTargetPos; }; +//neuro start +/* +=============================================================================== + +idPortalSky + +=============================================================================== +*/ +class idPortalSky : public idEntity { +public: + CLASS_PROTOTYPE( idPortalSky ); + + idPortalSky(); + ~idPortalSky(); + + void Spawn( void ); + void Event_PostSpawn(); + void Event_Activate( idEntity *activator ); +}; +//neuro end + #endif /* !__GAME_MISC_H__ */ diff --git a/neo/game/Player.cpp b/neo/game/Player.cpp index e3878fa7..40ab35f3 100644 --- a/neo/game/Player.cpp +++ b/neo/game/Player.cpp @@ -6394,6 +6394,11 @@ void idPlayer::Think( void ) { } gameLocal.Printf( "%d: enemies\n", num ); } + + //neuro start + // determine if portal sky is in pvs + gameLocal.portalSkyActive = gameLocal.pvs.CheckAreasForPortalSky( gameLocal.GetPlayerPVS(), GetPhysics()->GetOrigin() ); + //neuro end } /* @@ -7923,6 +7928,12 @@ void idPlayer::ClientPredictionThink( void ) { if ( gameLocal.isNewFrame && entityNumber == gameLocal.localClientNum ) { playerView.CalculateShake(); } + //neuro start + // determine if portal sky is in pvs + pvsHandle_t clientPVS = gameLocal.pvs.SetupCurrentPVS( GetPVSAreas(), GetNumPVSAreas() ); + gameLocal.portalSkyActive = gameLocal.pvs.CheckAreasForPortalSky( clientPVS, GetPhysics()->GetOrigin() ); + gameLocal.pvs.FreeCurrentPVS( clientPVS ); + //neuro end } /* diff --git a/neo/game/PlayerView.cpp b/neo/game/PlayerView.cpp index 149b8292..154ce395 100644 --- a/neo/game/PlayerView.cpp +++ b/neo/game/PlayerView.cpp @@ -36,6 +36,15 @@ If you have questions concerning this license or the applicable additional terms #include "PlayerView.h" +//Ivan_the_B start +static int MakePowerOfTwo( int num ) { + int pot; + for (pot = 1 ; pot < num ; pot<<=1) { + } + return pot; +} +//Ivan_the_B end + const int IMPULSE_DELAY = 150; /* ============== @@ -452,7 +461,88 @@ void idPlayerView::SingleView( idUserInterface *hud, const renderView_t *view ) renderView_t hackedView = *view; hackedView.viewaxis = hackedView.viewaxis * ShakeAxis(); - gameRenderWorld->RenderScene( &hackedView ); + //neuro start + //7318 start + idVec3 diff, currentEyePos, PSOrigin, Zero; + + Zero.Zero(); + + //if ( gameLocal.CheckGlobalPortalSky() ) { + 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.IsPortalSkyAcive() && 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; + // 7318 end + + renderView_t portalView = hackedView; + portalView.vieworg = PSOrigin; // 7318 moded + + // setup global fixup projection vars + if ( 1 ) { + int vidWidth, vidHeight; + idVec2 shiftScale; + + renderSystem->GetGLSettings( vidWidth, vidHeight ); + + float pot; + int w = vidWidth; + pot = MakePowerOfTwo( w ); + shiftScale.x = (float)w / pot; + + int h = vidHeight; + pot = MakePowerOfTwo( h ); + shiftScale.y = (float)h / pot; + + hackedView.shaderParms[4] = shiftScale.x; + hackedView.shaderParms[5] = shiftScale.y; + } + + gameRenderWorld->RenderScene( &portalView ); + renderSystem->CaptureRenderToImage( "_currentRender" ); + + hackedView.forceUpdate = true; // FIX: for smoke particles not drawing when portalSky present + + } + else { + + gameLocal.playerOldEyePos = currentEyePos; // 7318 moded + // so if g_enablePortalSky is disabled GlobalPortalSkies don't broke + // when g_enablePortalSky gets re-enabled GlPS keep working + } + + + gameRenderWorld->RenderScene( &hackedView ); //was fxManager->Process( &hackedView ); + //neuro end if ( player->spectating ) { return; diff --git a/neo/game/Pvs.cpp b/neo/game/Pvs.cpp index 5c189e0e..3f488e7a 100644 --- a/neo/game/Pvs.cpp +++ b/neo/game/Pvs.cpp @@ -1420,3 +1420,55 @@ void idPVS::ReadPVS( const pvsHandle_t handle, const idBitMsg &msg ) { } #endif + +//neuro start +/* +================ +idPVS::CheckAreasForPortalSky +================ +*/ +bool idPVS::CheckAreasForPortalSky( const pvsHandle_t handle, const idVec3 &origin ) { + int j, sourceArea; + + if ( handle.i < 0 || handle.i >= MAX_CURRENT_PVS || handle.h != currentPVS[handle.i].handle.h ) { + return false; + } + + sourceArea = gameRenderWorld->PointInArea( origin ); + + if ( sourceArea == -1 ) { + // 7318 start + + // 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; + } + + for ( j = 0; j < numAreas; j++ ) { + + if ( !( currentPVS[handle.i].pvs[j>>3] & (1 << (j&7)) ) ) { + continue; + } + + if ( gameRenderWorld->CheckAreaForPortalSky( j ) ) { + return true; + } + } + + // 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 + } + // 7318 end + return false; +} +//neuro end diff --git a/neo/game/Pvs.h b/neo/game/Pvs.h index 963b1786..fcaea376 100644 --- a/neo/game/Pvs.h +++ b/neo/game/Pvs.h @@ -97,6 +97,10 @@ public: void ReadPVS( const pvsHandle_t handle, const idBitMsg &msg ); #endif + //neuro start + bool CheckAreasForPortalSky( const pvsHandle_t handle, const idVec3 &origin ); + //neuro end + private: int numAreas; int numPortals; diff --git a/neo/game/gamesys/SysCvar.cpp b/neo/game/gamesys/SysCvar.cpp index 9751ca8f..e82ae0c7 100644 --- a/neo/game/gamesys/SysCvar.cpp +++ b/neo/game/gamesys/SysCvar.cpp @@ -335,3 +335,6 @@ idCVar mod_validSkins( "mod_validSkins", "skins/characters/player/marine_mp idCVar net_serverDownload( "net_serverDownload", "0", CVAR_GAME | CVAR_INTEGER | CVAR_ARCHIVE, "enable server download redirects. 0: off 1: redirect to si_serverURL 2: use builtin download. see net_serverDl cvars for configuration" ); idCVar net_serverDlBaseURL( "net_serverDlBaseURL", "", CVAR_GAME | CVAR_ARCHIVE, "base URL for the download redirection" ); idCVar net_serverDlTable( "net_serverDlTable", "", CVAR_GAME | CVAR_ARCHIVE, "pak names for which download is provided, seperated by ;" ); +//neuro start +idCVar g_enablePortalSky( "g_enablePortalSky", "1", CVAR_GAME | CVAR_BOOL, "enables the portal sky" ); +//neuro end diff --git a/neo/game/gamesys/SysCvar.h b/neo/game/gamesys/SysCvar.h index da8e26ee..2c269129 100644 --- a/neo/game/gamesys/SysCvar.h +++ b/neo/game/gamesys/SysCvar.h @@ -254,4 +254,7 @@ extern const char *si_gameTypeArgs[]; extern const char *ui_skinArgs[]; +//neuro start +extern idCVar g_enablePortalSky; +//neuro end #endif /* !__SYS_CVAR_H__ */