| 172 | } |
| 173 | |
| 174 | void EveTacticalTrails::UpdateGraphicsState( Be::Time now ) |
| 175 | { |
| 176 | m_segmentCount = accumulate( m_trackedObjects.begin(), m_trackedObjects.end(), 0u, []( uint32_t sum, const auto& object ) { return sum + static_cast<uint32_t>( std::max( object.positions.size(), size_t( 1 ) ) - 1 ); } ); |
| 177 | if( m_segmentCount == 0 ) |
| 178 | { |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | USE_MAIN_THREAD_RENDER_CONTEXT(); |
| 183 | if( !renderContext.IsValid() ) |
| 184 | { |
| 185 | m_segmentCount = 0; |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | if( m_vertexDeclHandle == Tr2EffectStateManager::UNINITIALIZED_DECLARATION ) |
| 190 | { |
| 191 | static Tr2VertexDefinition s_curveLineDataVertexDecl; |
| 192 | if( s_curveLineDataVertexDecl.empty() ) |
| 193 | { |
| 194 | Tr2VertexDefinition& tvd = s_curveLineDataVertexDecl; |
| 195 | |
| 196 | tvd.Add( tvd.FLOAT32_3, tvd.POSITION ); |
| 197 | tvd.Add( tvd.FLOAT32_3, tvd.TEXCOORD, 0 ); |
| 198 | tvd.Add( tvd.FLOAT32_1, tvd.TEXCOORD, 1 ); |
| 199 | tvd.Add( tvd.FLOAT32_2, tvd.TEXCOORD, 2 ); |
| 200 | } |
| 201 | |
| 202 | m_vertexDeclHandle = Tr2EffectStateManager::GetVertexDeclarationHandle( s_curveLineDataVertexDecl ); |
| 203 | } |
| 204 | |
| 205 | auto data = reinterpret_cast<LineVertex*>( Tr2Renderer::GetPoolAllocator()->Allocate( m_segmentCount * SEGMENT_VERTEX_COUNT * sizeof( LineVertex ) ) ); |
| 206 | if( !data ) |
| 207 | { |
| 208 | return; |
| 209 | } |
| 210 | auto dest = data; |
| 211 | for( auto& object : m_trackedObjects ) |
| 212 | { |
| 213 | if( object.positions.size() < 2 ) |
| 214 | { |
| 215 | continue; |
| 216 | } |
| 217 | |
| 218 | auto ToWorld = [&]( const Vector3d& pos ) -> Vector3 { |
| 219 | return ( pos - m_egoBallPosition ).AsVector3(); |
| 220 | }; |
| 221 | |
| 222 | Vector3 pos1 = ToWorld( object.positions[0].position ); |
| 223 | float time1 = TimeAsFloat( now - object.positions[0].time ) / m_fadeOutTime; |
| 224 | Vector3 pos2 = ToWorld( object.positions[1].position ); |
| 225 | |
| 226 | for( size_t i = 0; i + 1 < object.positions.size(); ++i ) |
| 227 | { |
| 228 | float time2 = TimeAsFloat( now - object.positions[i + 1].time ) / m_fadeOutTime; |
| 229 | auto posNext = i + 2 >= object.positions.size() ? pos2 + ( pos2 - pos1 ) : ToWorld( object.positions[i + 2].position ); |
| 230 | WriteLineVerticesToBuffer( |
| 231 | pos1, |
nothing calls this directly
no test coverage detected