Skip to content
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
4 changes: 4 additions & 0 deletions trinity/Eve/SpaceObject/Children/EveChildMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,10 @@ void EveChildMesh::GetPickingBatches( ITriRenderBatchAccumulator* batches, Tr2Pi
}
}
}
Tr2MeshBase* EveChildMesh::GetMesh() const
{
return m_mesh;
}
Comment thread
Ikreb1 marked this conversation as resolved.

void EveChildMesh::UpdatePerObjectBuffer( Tr2RenderContextEnum::ShaderType shaderType, uint32_t size, void* data )
{
Expand Down
1 change: 1 addition & 0 deletions trinity/Eve/SpaceObject/Children/EveChildMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ BLUE_CLASS( EveChildMesh ) :
void GetPickingBatches( ITriRenderBatchAccumulator * batches, Tr2PickTypes pickTypes, const Tr2PerObjectData* perObjectData ) override;

// access
Tr2MeshBase* GetMesh() const;
Comment thread
Ikreb1 marked this conversation as resolved.
void SetMesh( Tr2MeshBase * mesh );
void SetOrigin( Origin origin );
void SetReflectionMode( EntityComponents::ReflectionMode reflectionMode );
Expand Down
21 changes: 21 additions & 0 deletions trinity/Eve/SpaceObject/Children/EveChildTurret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,22 @@ Matrix EveChildTurret::GetFiringBoneWorldTransform( unsigned int muzzle ) const
return GetTurretBoneTransform( boneID );
}

void EveChildTurret::SetControllerVariable( const char* name, float value )
{
if( m_firingEffect )
{
m_firingEffect->SetControllerVariable( name, value );
}
}

void EveChildTurret::StartControllers()
{
if( m_firingEffect )
{
m_firingEffect->StartControllers();
}
}

void EveChildTurret::InitializeFiringEffect()
{
m_firingEffectMuzzlePosSet = false;
Expand Down Expand Up @@ -822,6 +838,11 @@ void EveChildTurret::SetTargetObject( IRoot* target )
{
if( !target )
{
if( m_state == STATE_TARGETING || m_state == STATE_FIRING )
{
EnterStateIdle();
}
m_target->SetTargetable( nullptr );
return;
}
ITriTargetablePtr oldTargetPtr = m_target->GetTargetable();
Expand Down
4 changes: 4 additions & 0 deletions trinity/Eve/SpaceObject/Children/EveChildTurret.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ BLUE_CLASS( EveChildTurret ) :

Matrix GetFiringBoneWorldTransform( unsigned int muzzle ) const;

// controllers: forwarded to the firing effect, the child owns none itself
void SetControllerVariable( const char* name, float value );
void StartControllers();

// turret set states
enum State
{
Expand Down
12 changes: 12 additions & 0 deletions trinity/Eve/SpaceObject/Children/EveChildTurret_Blue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,17 @@ const Be::ClassInfo* EveChildTurret::ExposeToBlue()
"\n:param idx: index of the firing bone in the current model."
"\n:returns: The world transform matrix." )

MAP_METHOD_AND_WRAP(
"SetControllerVariable",
SetControllerVariable,
"Set a controller variable, forwarded to the firing effect's controllers\n"
":param name: variable name\n"
":param value: new variable value\n" )

MAP_METHOD_AND_WRAP(
"StartControllers",
StartControllers,
"Start the firing effect's controllers" )

EXPOSURE_CHAINTO( EveChildMesh )
}
124 changes: 80 additions & 44 deletions trinity/Eve/SpaceObjectFactory/EveSOF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "BlueObjectMetadata.h"
#include "ITr2TextureProvider.h"
#include "TriSettingsRegistrar.h"
#include "Eve/SpaceObject/Children/EveChildTurret.h"

#include <ITriFunction.h>

Expand Down Expand Up @@ -4180,72 +4181,107 @@ void EveSOF::CreatePlacement(

// --------------------------------------------------------------------------------
// Description:
// setup the material of a turret with the data from faction
// override the parameters of a turret shader with the data from SOF faction, reading the faction's turret area
// --------------------------------------------------------------------------------
void EveSOF::SetupTurretMaterialFromFaction( EveTurretSet* turretSet, const char* factionName )
void EveSOF::ApplyFactionToTurretShader( Tr2Effect* shader, const EveSOFDataMgr::GenericData* genericData, const EveSOFDataMgr::FactionData* factionData ) const
{
// get generic data
const EveSOFDataMgr::GenericData* genericData = m_dataMgr.GetGenericData();
// get faction data
const EveSOFDataMgr::FactionData* factionData = m_dataMgr.GetFactionData( factionName );
if( factionData == nullptr )
if( !shader )
{
return;
}
// get area data
const EveSOFDataMgr::AreaMaterialData* areaMaterialData = &factionData->areaMaterials;

// start modifying the parameters of the turret's shader
Tr2Effect* shader = turretSet->GetShader();
if( shader )
// try override shader's parameter, const's first
if( !shader->m_constParameters.empty() )
{
// try override shader's parameter, const's first
if( !shader->m_constParameters.empty() )
shader->StartUpdate();
for( auto it = shader->m_constParameters.begin(); it != shader->m_constParameters.end(); ++it )
{
shader->StartUpdate();
for( auto it = shader->m_constParameters.begin(); it != shader->m_constParameters.end(); ++it )
// build the parameter
EveSOFUtilsParameterName param( genericData->materialPrefixes, it->name.c_str() );
if( param.IsMaterialIdxValid() )
{
// build the parameter
EveSOFUtilsParameterName param( genericData->materialPrefixes, it->name.c_str() );
if( param.IsMaterialIdxValid() )
{
param.ChangeMaterialIdx( genericData, factionData->materialUsageList[param.GetMaterialIdx()] );
}
// find data
const Vector4* res = EveSOFUtils::SearchForParameterData( &m_dataMgr, factionData->colorData.colors, areaMaterialData, EveSOFDataArea::TYPE_PRIMARY, &param );
if( res )
{
it->value = *res;
}
param.ChangeMaterialIdx( genericData, factionData->materialUsageList[param.GetMaterialIdx()] );
}
// find data
const Vector4* res = EveSOFUtils::SearchForParameterData( &m_dataMgr, factionData->colorData.colors, areaMaterialData, genericData->turretAreaType, &param );
if( res )
{
it->value = *res;
}
shader->EndUpdate();
}
else
shader->EndUpdate();
}
else
{
// then non-const parameters
for( auto it = shader->m_parameters.begin(); it != shader->m_parameters.end(); ++it )
{
// then non-const parameters
for( auto it = shader->m_parameters.begin(); it != shader->m_parameters.end(); ++it )
// build the parameter
EveSOFUtilsParameterName param( genericData->materialPrefixes, ( *it )->GetParameterName() );
if( param.IsMaterialIdxValid() )
{
// build the parameter
EveSOFUtilsParameterName param( genericData->materialPrefixes, ( *it )->GetParameterName() );
if( param.IsMaterialIdxValid() )
{
param.ChangeMaterialIdx( genericData, factionData->materialUsageList[param.GetMaterialIdx()] );
}
// find data
const Vector4* res = EveSOFUtils::SearchForParameterData( &m_dataMgr, factionData->colorData.colors, areaMaterialData, EveSOFDataArea::TYPE_PRIMARY, &param );
if( res )
param.ChangeMaterialIdx( genericData, factionData->materialUsageList[param.GetMaterialIdx()] );
}
// find data
const Vector4* res = EveSOFUtils::SearchForParameterData( &m_dataMgr, factionData->colorData.colors, areaMaterialData, genericData->turretAreaType, &param );
if( res )
{
Tr2Vector4ParameterPtr p;
if( ( *it )->QueryInterface( BlueInterfaceIID<Tr2Vector4Parameter>(), (void**)&p, BEQI_SILENT ) )
{
Tr2Vector4ParameterPtr p;
if( ( *it )->QueryInterface( BlueInterfaceIID<Tr2Vector4Parameter>(), (void**)&p, BEQI_SILENT ) )
{
p->SetValue( *res );
}
p->SetValue( *res );
}
}
}
}
}

// --------------------------------------------------------------------------------
// Description:
// setup the material of a turret with the data from faction
// --------------------------------------------------------------------------------
void EveSOF::SetupTurretMaterialFromFaction( EveTurretSet* turretSet, const char* factionName )
{
// get faction data
const EveSOFDataMgr::FactionData* factionData = m_dataMgr.GetFactionData( factionName );
if( factionData == nullptr )
{
return;
}
Comment thread
Ikreb1 marked this conversation as resolved.
ApplyFactionToTurretShader( turretSet->GetShader(), m_dataMgr.GetGenericData(), factionData );
}

void EveSOF::SetupChildTurretMaterialFromFaction( EveChildTurret* childTurret, const char* factionName )
{
// get faction data
const EveSOFDataMgr::FactionData* factionData = m_dataMgr.GetFactionData( factionName );
if( !childTurret || !factionData )
{
return;
}
Tr2MeshBase* mesh = childTurret->GetMesh();
if( !mesh )
{
return;
}

const Tr2MeshAreaVector* areas = mesh->GetAreas( TRIBATCHTYPE_OPAQUE );
if( !areas )
{
return;
}
const EveSOFDataMgr::GenericData* genericData = m_dataMgr.GetGenericData();
for( const Tr2MeshAreaPtr& area : *areas )
{
if( area )
{
ApplyFactionToTurretShader( area->GetMaterialInterface(), genericData, factionData );
}
}
}

// --------------------------------------------------------------------------------
// Description:
// setup the material of a turret with the data from SOF faction
Expand Down
3 changes: 3 additions & 0 deletions trinity/Eve/SpaceObjectFactory/EveSOF.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ BLUE_DECLARE( EveSOFDNA );
BLUE_DECLARE( Tr2InstancedMesh );
BLUE_DECLARE( Tr2MeshArea );
BLUE_DECLARE( EveChildContainer );
BLUE_DECLARE( EveChildTurret );
BLUE_DECLARE_INTERFACE( IEveEffectChildrenOwner );
BLUE_DECLARE_INTERFACE( ITr2LightOwner );
BLUE_DECLARE_INTERFACE( IEveSpaceObjectAttachment );
Expand Down Expand Up @@ -60,6 +61,7 @@ class EveSOF : public IRoot
// change the material of a turret with SOF data
void SetupTurretMaterialFromDNA( EveTurretSet* turretSet, const char* dnaString );
void SetupTurretMaterialFromFaction( EveTurretSet* turretSet, const char* factionName );
void SetupChildTurretMaterialFromFaction( EveChildTurret* childTurret, const char* factionName );

bool LoadData( const char* filePath );

Expand Down Expand Up @@ -117,6 +119,7 @@ class EveSOF : public IRoot
void SetupImpactEffects( EveSpaceObject2Ptr obj, const EveSOFDNAPtr dna, ArmorDamageEffectCache& armorDamageEffectCache ) const;
void SetupLights( ITr2LightOwnerPtr obj, const EveSOFDNAPtr dna, const std::vector<Matrix>& offsets ) const;
void SetupLayout( EveSpaceObject2Ptr obj, EveChildContainerPtr layoutContainer, EveChildInstancedMeshesPtr& sharedMeshes, ArmorDamageEffectCache& armorDamageEffectCache, const EveSOFDNAPtr dna, const std::vector<Matrix>& offsets, int& partTag, bool perPlacementTags, uint32_t seedOverwrite = 0 );
void ApplyFactionToTurretShader( Tr2Effect* shader, const EveSOFDataMgr::GenericData* genericData, const EveSOFDataMgr::FactionData* factionData ) const;


Tr2MeshPtr CreateMesh( const EveSOFDNAPtr dna ) const;
Expand Down
7 changes: 7 additions & 0 deletions trinity/Eve/SpaceObjectFactory/EveSOF_Blue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "StdAfx.h"
#include "EveSOF.h"

#include "Eve/SpaceObject/Children/EveChildTurret.h"
#include "Eve/Turret/EveTurretSet.h"

BLUE_DEFINE( EveSOF );
Expand Down Expand Up @@ -46,6 +47,12 @@ const Be::ClassInfo* EveSOF::ExposeToBlue()
"Change the material of the turret according to the faction in SOF\n"
":param turretSet: turret set that will be modified\n"
":param faction: faction name" )
MAP_METHOD_AND_WRAP(
"SetupChildTurretMaterialFromFaction",
SetupChildTurretMaterialFromFaction,
"Change the material of every opaque area of a child turret according to the faction in SOF\n"
":param childTurret: child turret whose mesh materials will be modified\n"
":param faction: faction name" )


EXPOSURE_END()
Expand Down
2 changes: 0 additions & 2 deletions trinity/Eve/Turret/EveTurretSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ BLUE_DECLARE( TriObserverLocal );
// constants
// maximum number of single turrets per turret set
const unsigned int EVE_MAX_TURRETS_PER_SET = 24;
// maximum time offset for turret firing
const float EVE_TURRET_RANDOM_DELAY_MAX = 0.6f;

struct EveTurretSetVSData
{
Expand Down
8 changes: 7 additions & 1 deletion trinity/Eve/Turret/EveTurretTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ ITriTargetablePtr EveTurretTarget::GetTargetable() const

// --------------------------------------------------------------------------------
// Description:
// Set the target object. Since this most liekly has changed, trigger
// Set the target object. Since this most likely has changed, trigger
// the targetposition smoothing (interpolating)
// --------------------------------------------------------------------------------
bool EveTurretTarget::SetTargetable( IRoot* object )
{
if( !object )
{
m_object = nullptr;
m_objectPos = nullptr;
return true;
}
// set new target object
ITriTargetablePtr newTarget;
if( !object->QueryInterface( BlueInterfaceIID<ITriTargetable>(), (void**)&newTarget ) )
Expand Down
8 changes: 8 additions & 0 deletions trinity/Eve/Turret/EveTurretTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include "Include/ITriTargetable.h"

// maximum time offset for turret firing; godma reads it back through GetShotTimeVariance
// as the window for grouping shots that belong to one damage message
const float EVE_TURRET_RANDOM_DELAY_MAX = 0.6f;

namespace ImpactBehaviour
{

Expand Down Expand Up @@ -55,6 +59,10 @@ BLUE_CLASS( EveTurretTarget ) :
double GetLastShotTime() const;
bool PopShotMissed();
size_t MissQueueSize() const;
float GetShotTimeVariance() const
{
return EVE_TURRET_RANDOM_DELAY_MAX;
}

// target object queries
float GetRadius() const;
Expand Down
21 changes: 21 additions & 0 deletions trinity/Eve/Turret/EveTurretTarget_Blue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,26 @@ const Be::ClassInfo* EveTurretTarget::ExposeToBlue()
MAP_ATTRIBUTE( "positionOldInfluence", m_positionOldInfluence, "Influence of previous tracking position", Be::READ )
MAP_ATTRIBUTE( "behaviour", m_impactBehaviour, "Impact behaviour", Be::READ )

MAP_METHOD_AND_WRAP(
"SetShotMissed",
SetShotMissed,
"Queue whether the next shot misses. godma pushes one entry per damage message, the turret pops one per shot.\n"
":param missed: is the next shot a miss" )

MAP_METHOD_AND_WRAP(
"GetLastShotTime",
GetLastShotTime,
"Get the time we last queued a shot in arbitrary units. Only use for comparison between turrets." )

MAP_METHOD_AND_WRAP(
"GetShotTimeVariance",
GetShotTimeVariance,
"Get maximum firing time variance between turrets." )

MAP_METHOD_AND_WRAP(
"MissQueueSize",
MissQueueSize,
"Get the size of the active miss/hit queue." )

EXPOSURE_END()
}