Skip to content

Commit

Permalink
Tweaked search light rendering and added light limit
Browse files Browse the repository at this point in the history
  • Loading branch information
jushar committed Dec 7, 2015
1 parent 1d2e786 commit c7e0a4e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
27 changes: 17 additions & 10 deletions MTA10/game_sa/CPointLightsSA.cpp
Expand Up @@ -9,9 +9,13 @@
* Multi Theft Auto is available from http://www.multitheftauto.com/
*
*****************************************************************************/

#include "StdInc.h"

using CHeli_SearchLightCone_t = void(__cdecl *)(int handleId, CVector startPos, CVector endPos, float radius1, float unknownConstant,
int unkown1, bool renderSpot, CVector* unkown3, CVector* unkown4, CVector* unknown5, int unknown6, float radius2);
using CHeli_PreSearchLightCone_t = int(__cdecl *)();
using CHeli_PostSearchLightCone_t = int(__cdecl *)();

void CPointLightsSA::AddLight ( int iMode, const CVector vecPosition, CVector vecDirection, float fRadius, SColor color, unsigned char uc_8, bool bCreatesShadow, CEntity * pAffected )
{
DWORD dwEntityInterface = 0;
Expand Down Expand Up @@ -41,22 +45,25 @@ void CPointLightsSA::AddLight ( int iMode, const CVector vecPosition, CVector ve
}
}

void CPointLightsSA::RenderHeliLight ( const CVector& vecStart, const CVector& vecEnd, float startRadius, float endRadius, bool renderSpot )
void CPointLightsSA::PreRenderHeliLights ()
{
using CHeli_SearchLightCone_t = void(__cdecl *)(int handleId, CVector startPos, CVector endPos, float radius1, float unknownConstant,
int unkown1, bool renderSpot, CVector* unkown3, CVector* unkown4, CVector* unknown5, int unknown6, float radius2);
using CHeli_PreSearchLightCone_t = int(__cdecl *)();
using CHeli_PostSearchLightCone_t = int(__cdecl *)();

auto CHeli_SearchLightCone = (CHeli_SearchLightCone_t)FUNC_CHeli_SearchLightCone;
auto CHeli_PreSearchLightCone = (CHeli_PreSearchLightCone_t)FUNC_CHeli_Pre_SearchLightCone;
CHeli_PreSearchLightCone ();
}

void CPointLightsSA::PostRenderHeliLights ()
{
auto CHeli_PostSearchLightCone = (CHeli_PostSearchLightCone_t)FUNC_CHeli_Post_SearchLightCone;
CHeli_PostSearchLightCone ();
}

void CPointLightsSA::RenderHeliLight ( const CVector& vecStart, const CVector& vecEnd, float startRadius, float endRadius, bool renderSpot )
{
auto CHeli_SearchLightCone = (CHeli_SearchLightCone_t)FUNC_CHeli_SearchLightCone;

// 3x3 translation matrix (initialised by the game)
CVector mat[] = { CVector(), CVector(), CVector() };

// Set render states and render
CHeli_PreSearchLightCone ();
CHeli_SearchLightCone ( 0, vecStart, vecEnd, endRadius, 1.0f, 0, renderSpot, &mat[0], &mat[1], &mat[2], 1, startRadius );
CHeli_PostSearchLightCone ();
}
6 changes: 4 additions & 2 deletions MTA10/game_sa/CPointLightsSA.h
Expand Up @@ -23,9 +23,11 @@
class CPointLightsSA : public CPointLights
{
public:
void AddLight ( int iMode, const CVector vecPosition, CVector vecDirection, float fRadius, SColor color, unsigned char uc_8, bool bCreatesShadow, CEntity * pAffected );
virtual void AddLight ( int iMode, const CVector vecPosition, CVector vecDirection, float fRadius, SColor color, unsigned char uc_8, bool bCreatesShadow, CEntity * pAffected ) override;

void RenderHeliLight ( const CVector& vecStart, const CVector& vecEnd, float startRadius, float endRadius, bool renderSpot );
virtual void PreRenderHeliLights () override;
virtual void PostRenderHeliLights () override;
virtual void RenderHeliLight ( const CVector& vecStart, const CVector& vecEnd, float startRadius, float endRadius, bool renderSpot ) override;;
};

#endif
2 changes: 1 addition & 1 deletion MTA10/mods/shared_logic/CClientManager.cpp
Expand Up @@ -26,7 +26,7 @@ CClientManager::CClientManager ( void )
m_pPickupStreamer = new CClientStreamer ( CClientPickupManager::IsPickupLimitReached, 100.0f, 300, 300 );
m_pPlayerStreamer = new CClientStreamer ( CClientPlayerManager::IsPlayerLimitReached, 250.0f, 300, 300 );
m_pVehicleStreamer = new CClientStreamer ( CClientVehicleManager::IsVehicleLimitReached, 250.0f, 300, 300 );
m_pLightStreamer = new CClientStreamer ( []() -> bool { return false; }, 600.0f, 300, 300 );
m_pLightStreamer = new CClientStreamer ( CClientPointLightsManager::IsLightsLimitReached, 600.0f, 300, 300 );
m_pModelRequestManager = new CClientModelRequestManager;

m_pGUIManager = new CClientGUIManager;
Expand Down
14 changes: 14 additions & 0 deletions MTA10/mods/shared_logic/CClientPointLightsManager.cpp
Expand Up @@ -104,10 +104,24 @@ void CClientPointLightsManager::DoPulse ( void )

void CClientPointLightsManager::RenderHeliLightHandler ()
{
// Set render states
auto pLights = g_pGame->GetPointLights ();
pLights->PreRenderHeliLights ();

// Render our lights
for ( auto pLight : m_SearchLightList )
{
pLight->Render ();
}

// Reset render states
pLights->PostRenderHeliLights ();
}

bool CClientPointLightsManager::IsLightsLimitReached ()
{
auto pThis = g_pClientGame->GetManager ()->GetPointLightsManager ();
return pThis->m_SearchLightList.size () >= 1000;
}

void CClientPointLightsManager::RemoveFromList ( CClientPointLights* pLight )
Expand Down
2 changes: 2 additions & 0 deletions MTA10/mods/shared_logic/CClientPointLightsManager.h
Expand Up @@ -42,6 +42,8 @@ class CClientPointLightsManager
void DoPulse ( void );
void RenderHeliLightHandler ( void );

static bool IsLightsLimitReached ();

private:

inline void AddToList ( CClientPointLights* pLight ) { m_List.push_back ( pLight ); };
Expand Down
3 changes: 3 additions & 0 deletions MTA10/sdk/game/CPointLights.h
Expand Up @@ -24,6 +24,9 @@ class CPointLights
{
public:
virtual void AddLight ( int iMode, const CVector vecPosition, CVector vecDirection, float fRadius, SColor color, unsigned char uc_8, bool bCreatesShadow, CEntity * pAffected ) = 0;

virtual void PreRenderHeliLights () = 0;
virtual void PostRenderHeliLights () = 0;
virtual void RenderHeliLight ( const CVector& vecStart, const CVector& vecEnd, float startRadius, float endRadius, bool renderSpot ) = 0;
};

Expand Down

0 comments on commit c7e0a4e

Please sign in to comment.