//----------------------------------------------------------------------------- // Regenerate the texture //----------------------------------------------------------------------------- void CDensityTextureRegen::RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect ) { unsigned char *imageData = pVTFTexture->ImageData( 0, 0, 0 ); int x, y, unitx, unity, offset, width, height, radius; Msg("Generating density texture...\n"); width = pVTFTexture->Width(); height = pVTFTexture->Height(); memset( imageData, 0, width * height ); CUnitBase *pUnit; CUnitBase **pList = g_Unit_Manager.AccessUnits(); for( int i = 0; i < g_Unit_Manager.NumUnits(); i++ ) { pUnit = pList[i]; DensityWeightsMap map; map.Init( pUnit ); map.SetType( DENSITY_GAUSSIAN ); map.OnCollisionSizeChanged(); const Vector &vOrigin = pUnit->GetAbsOrigin(); unitx = (vOrigin.x + (FOW_WORLDSIZE / 2)) / (float)DENSITY_TILESIZE; unity = (vOrigin.y + (FOW_WORLDSIZE / 2)) / (float)DENSITY_TILESIZE; radius = (int)((pUnit->CollisionProp()->BoundingRadius2D() * 2) / DENSITY_TILESIZE); Msg("%d Density %d %d %d %d %d %d %d\n", pUnit->entindex(), map.GetSizeX(), map.GetSizeY(), unitx, unity, radius, MAX(unity-radius, 0), MIN(unity+radius, height) ); for( y = MAX(unity-radius, 0); y < MIN(unity+radius, height); y++ ) { for( x = MAX(unitx-radius, 0); x < MIN(unitx+radius, width); x++ ) { offset = ( x + y * width ); Vector vTest = Vector( x * DENSITY_TILESIZE - ( FOW_WORLDSIZE / 2 ), y * DENSITY_TILESIZE - ( FOW_WORLDSIZE / 2 ), 0.0f ); imageData[offset] += map.Get( vTest ) * 255; } } } }
void CPotentialField::Update() { int iPosX, iPosY, iMinX, iMinY, iMaxX, iMaxY, x, y; CUnitBase *pUnit; CUnitBase **ppUnits = g_Unit_Manager.AccessUnits(); int i; for ( i = 0; i < g_Unit_Manager.NumUnits(); i++ ) { pUnit = ppUnits[i]; if( !pUnit->IsSolid() || !pUnit->CanBeSeen() ) continue; const Vector &origin = pUnit->GetAbsOrigin(); iPosX = (origin.x + (PF_SIZE / 2)) / (float)PF_TILESIZE; iPosY = (origin.y + (PF_SIZE / 2)) / (float)PF_TILESIZE; iMinX = MAX(iPosX-PF_CONSIDER, 0); iMaxX = MIN(PF_SIZE-1, iPosX+PF_CONSIDER); iMinY = MAX(iPosY-PF_CONSIDER, 0); iMaxY = MIN(PF_SIZE-1, iPosY+PF_CONSIDER); for(x=iMinX; x <= iMaxX; x++) { for(y=iMinY; y <= iMaxY; y++) { m_Density[x][y] += gaussian(x-iPosX, y-iPosY, unit_potential_stdev.GetFloat()); m_AvgVelocities[x][y] += pUnit->GetAbsVelocity()*m_Density[x][y]; } } }; for(x=0; x<PF_ARRAYSIZE; x++) { for(y=0; y<PF_ARRAYSIZE; y++) { if( m_Density[x][y] != 0 ) m_AvgVelocities[x][y] /= m_Density[x][y]; } } }