/* When a extraction ends, the digged depth should be left back to the extraction-map. To be available for other extractors to use. */ void CMetalMap::removeExtraction(int x, int z, float depth) { ClampInt(x, 0, sizeX); ClampInt(z, 0, sizeZ); extractionMap[(z * sizeX) + x] -= depth; }
/* Gives the amount of metal on a single square. */ float CMetalMap::getMetalAmount(int x, int z) { ClampInt(x, 0, sizeX); ClampInt(z, 0, sizeZ); return metalMap[(z * sizeX) + x] * metalScale; }
void CMetalMap::SetMetalAmount(int x, int z, float m) { ClampInt(x, 0, sizeX); ClampInt(z, 0, sizeZ); metalMap[(z * sizeX) + x] = (metalScale == 0.0f) ? 0 : Clamp((int)(m / metalScale), 0, 255); }
float CMetalMap::GetMetalAmount(int x, int z) { ClampInt(x, 0, sizeX); ClampInt(z, 0, sizeZ); return distributionMap[(z * sizeX) + x] * metalScale; }
int CMetalMap::GetMetalExtraction(int x, int z) { ClampInt(x, 0, sizeX); ClampInt(z, 0, sizeZ); return extractionMap[(z * sizeX) + x]; }
void CMetalMap::SetMetalAmount(int x, int z, float m) { ClampInt(x, 0, sizeX); ClampInt(z, 0, sizeZ); distributionMap[(z * sizeX) + x] = (metalScale == 0.0f) ? 0 : Clamp((int)(m / metalScale), 0, 255); eventHandler.MetalMapChanged(x, z); }
/* Gives the amount of metal over an area. */ float CMetalMap::getMetalAmount(int x1, int z1, int x2, int z2) { ClampInt(x1, 0, sizeX); ClampInt(x2, 0, sizeX); ClampInt(z1, 0, sizeZ); ClampInt(z2, 0, sizeZ); float metal = 0.0f; int x, z; for (x = x1; x < x2; x++) { for (z = z1; z < z2; z++) { metal += metalMap[(z * sizeX) + x]; } } return metal * metalScale; }
// This method is called before rendering begins to allow the plug-in // to evaluate anything prior to the render so it can store this information. void Planet::Update(TimeValue t, Interval& ivalid) { if (!texValidity.InInterval(t)) { texValidity.SetInfinite(); xyzGen->Update(t, texValidity); for (int i = 0; i < NUM_COLORS; i++) { // pblock->GetValue(i+PB_COL1, t, col[i], texValidity); pblock->GetValue(i+planet_color1, t, col[i], texValidity); col[i].ClampMinMax(); } // pblock->GetValue(PB_SIZE, t, size, texValidity); pblock->GetValue(planet_size, t, size, texValidity); ClampFloat(size, MIN_SIZE, MAX_SIZE); // pblock->GetValue(PB_ISLAND, t, island, texValidity); pblock->GetValue(planet_island, t, island, texValidity); ClampFloat(island, MIN_ISLAND, MAX_ISLAND); // pblock->GetValue(PB_PERCENT, t, percent, texValidity); pblock->GetValue(planet_percent, t, percent, texValidity); ClampFloat(percent, MIN_PERCENT, MAX_PERCENT); land = percent/100.0f; // pblock->GetValue(PB_SEED, t, seed, texValidity); pblock->GetValue(planet_seed, t, seed, texValidity); ClampInt(seed, (int) MIN_SEED, (int) MAX_SEED); pblock->GetValue(planet_blend, t, blend, texValidity); } ivalid &= texValidity; }
// This method is called before rendering begins to allow the plug-in // to evaluate anything prior to the render so it can store this information. void Splat::Update(TimeValue t, Interval& ivalid) { if (!texValidity.InInterval(t)) { texValidity.SetInfinite(); xyzGen->Update(t, texValidity); // pblock->GetValue(PB_COL1, t, col[0], texValidity); pblock->GetValue(splat_color1, t, col[0], texValidity); col[0].ClampMinMax(); // pblock->GetValue(PB_COL2, t, col[1], texValidity); pblock->GetValue(splat_color2, t, col[1], texValidity); col[1].ClampMinMax(); // pblock->GetValue(PB_SIZE, t, size, texValidity); pblock->GetValue(splat_size, t, size, texValidity); ClampFloat(size, MIN_SIZE, MAX_SIZE); // pblock->GetValue(PB_THRESH, t, thresh, texValidity); pblock->GetValue(splat_threshold, t, thresh, texValidity); ClampFloat(thresh, MIN_THRESH, MAX_THRESH); // pblock->GetValue(PB_ITER, t, iter, texValidity); pblock->GetValue(splat_iteration, t, iter, texValidity); pblock->GetValue(splat_mapon1, t, mapOn[0], texValidity); pblock->GetValue(splat_mapon2, t, mapOn[1], texValidity); ClampInt(iter, (int) MIN_ITER, (int) MAX_ITER); for (int i = 0; i < NUM_SUB_TEXMAPS; i++) { if (subTex[i]) subTex[i]->Update(t, texValidity); } } ivalid &= texValidity; }
/* Makes a reqest for extracting metal from a given square. If there is metal left to extract to the requested depth, the amount available will be returned and the requested depth will be sat as new extraction-depth on the extraction-map. If the requested depth is grounder than the current extraction-depth 0.0 will be returned and nothing changed. */ float CMetalMap::requestExtraction(int x, int z, float toDepth) { ClampInt(x, 0, sizeX); ClampInt(z, 0, sizeZ); const float current = extractionMap[(z * sizeX) + x]; if (toDepth <= current) { return 0.0f; } const float available = toDepth - current; extractionMap[(z * sizeX) + x] = toDepth; return available; }
float CMetalMap::GetMetalAmount(int x1, int z1, int x2, int z2) { ClampInt(x1, 0, sizeX); ClampInt(x2, 0, sizeX); ClampInt(z1, 0, sizeZ); ClampInt(z2, 0, sizeZ); float metal = 0.0f; for (int x = x1; x < x2; x++) { for (int z = z1; z < z2; z++) { metal += distributionMap[(z * sizeX) + x]; } } return (metal * metalScale); }
unsigned char * QuarterImageSize( const unsigned char * src, const int width, const int height, const bool srgb ) { float table[256]; if ( srgb ) { for ( int i = 0; i < 256; i++ ) { table[ i ] = SRGBToLinear( i * ( 1.0f / 255.0f ) ); } } const int newWidth = OVR::Alg::Max( 1, width >> 1 ); const int newHeight = OVR::Alg::Max( 1, height >> 1 ); unsigned char * out = (unsigned char *)malloc( newWidth * newHeight * 4 ); unsigned char * out_p = out; for ( int y = 0; y < newHeight; y++ ) { const unsigned char * in_p = src + y * 2 * width * 4; for ( int x = 0; x < newWidth; x++ ) { for ( int i = 0; i < 4; i++ ) { if ( srgb ) { const float linear = ( table[ in_p[ i ] ] + table[ in_p[ 4 + i ] ] + table[ in_p[ width * 4 + i ] ] + table[ in_p[ width * 4 + 4 + i ] ] ) * 0.25f; const float gamma = LinearToSRGB( linear ); out_p[ i ] = ( unsigned char )ClampInt( ( int )( gamma * 255.0f + 0.5f ), 0, 255 ); } else { out_p[ i ] = ( in_p[ i ] + in_p[ 4 + i ] + in_p[ width * 4 + i ] + in_p[ width * 4 + 4 + i ] ) >> 2; } } out_p += 4; in_p += 8; } } return out; }
// This method is called before rendering begins to allow the plug-in // to evaluate anything prior to the render so it can store this information. void Water::Update(TimeValue t, Interval& ivalid) { if (!texValidity.InInterval(t)) { texValidity.SetInfinite(); xyzGen->Update(t, texValidity); // pblock->GetValue(PB_COL1, t, col[0], texValidity); pblock->GetValue(water_color1, t, col[0], texValidity); col[0].ClampMinMax(); // pblock->GetValue(PB_COL2, t, col[1], texValidity); pblock->GetValue(water_color2, t, col[1], texValidity); col[1].ClampMinMax(); // pblock->GetValue(PB_NUM, t, count, texValidity); pblock->GetValue(water_num, t, count, texValidity); ClampInt(count, (int) MIN_NUM, (int) MAX_NUM); // pblock->GetValue(PB_SIZE, t, size, texValidity); pblock->GetValue(water_size, t, size, texValidity); ClampFloat(size, MIN_SIZE, MAX_SIZE); // pblock->GetValue(PB_LEN_MIN, t, minperiod, texValidity); pblock->GetValue(water_len_min, t, minperiod, texValidity); ClampFloat(minperiod, MIN_LEN_MIN, MAX_LEN_MIN); // > 6/11/02 - 2:42pm --MQM-- typo, was MIN_LEN_MIN, MAX_LEN_MAX // pblock->GetValue(PB_LEN_MAX, t, maxperiod, texValidity); pblock->GetValue(water_len_max, t, maxperiod, texValidity); ClampFloat(maxperiod, MIN_LEN_MAX, MAX_LEN_MAX); // pblock->GetValue(PB_AMP, t, amp, texValidity); pblock->GetValue(water_amp, t, amp, texValidity); ClampFloat(amp, MIN_AMP, MAX_AMP); // pblock->GetValue(PB_PHASE, t, phase, texValidity); // pblock->GetValue(PB_TYPE, t, type, texValidity); pblock->GetValue(water_phase, t, phase, texValidity); pblock->GetValue(water_type, t, type, texValidity); for (int i = 0; i < NUM_SUB_TEXMAPS; i++) { if (subTex[i]) subTex[i]->Update(t, texValidity); // pblock->GetValue(PB_SEED, t, randSeed, texValidity); pblock->GetValue(water_seed, t, randSeed, texValidity); pblock->GetValue(water_mapon1, t, mapOn[0], texValidity); pblock->GetValue(water_mapon2, t, mapOn[1], texValidity); ReInit(); } } ivalid &= texValidity; }
// This method is called before rendering begins to allow the plug-in // to evaluate anything prior to the render so it can store this information. void Smoke::Update(TimeValue t, Interval& ivalid) { if (!texValidity.InInterval(t)) { texValidity.SetInfinite(); xyzGen->Update(t, texValidity); // pblock->GetValue(PB_COL1, t, col[0], texValidity); pblock->GetValue(smoke_color1, t, col[0], texValidity); col[0].ClampMinMax(); // pblock->GetValue(PB_COL2, t, col[1], texValidity); pblock->GetValue(smoke_color2, t, col[1], texValidity); col[1].ClampMinMax(); // pblock->GetValue(PB_SIZE, t, size, texValidity); pblock->GetValue(smoke_size, t, size, texValidity); ClampFloat(size, MIN_SIZE, MAX_SIZE); // pblock->GetValue(PB_EXP, t, power, texValidity); pblock->GetValue(smoke_exponent, t, power, texValidity); ClampFloat(power, MIN_EXP, MAX_EXP); // pblock->GetValue(PB_PHASE, t, phase, texValidity); // pblock->GetValue(PB_ITER, t, iter, texValidity); pblock->GetValue(smoke_phase, t, phase, texValidity); pblock->GetValue(smoke_iteration, t, iter, texValidity); ClampInt(iter, (int) MIN_ITER, (int) MAX_ITER); pblock->GetValue(smoke_mapon1, t, mapOn[0], texValidity); pblock->GetValue(smoke_mapon2, t, mapOn[1], texValidity); NotifyDependents(FOREVER, PART_TEXMAP, REFMSG_DISPLAY_MATERIAL_CHANGE); } if (!mapValid.InInterval(t)) { mapValid.SetInfinite(); for (int i = 0; i < NUM_SUB_TEXMAPS; i++) { if (subTex[i]) subTex[i]->Update(t, mapValid); } } ivalid &= texValidity; ivalid &= mapValid; }
unsigned char * ScaleImageRGBA( const unsigned char * src, const int width, const int height, const int newWidth, const int newHeight, const ImageFilter filter ) { int footprintMin = 0; int footprintMax = 0; int offsetX = 0; int offsetY = 0; switch ( filter ) { case IMAGE_FILTER_NEAREST: { footprintMin = 0; footprintMax = 0; offsetX = width; offsetY = height; break; } case IMAGE_FILTER_LINEAR: { footprintMin = 0; footprintMax = 1; offsetX = width - newWidth; offsetY = height - newHeight; break; } case IMAGE_FILTER_CUBIC: { footprintMin = -1; footprintMax = 2; offsetX = width - newWidth; offsetY = height - newHeight; break; } } unsigned char * scaled = ( unsigned char * )malloc( newWidth * newHeight * 4 * sizeof( unsigned char ) ); float * srcLinear = ( float * )malloc( width * height * 4 * sizeof( float ) ); float * scaledLinear = ( float * )malloc( newWidth * newHeight * 4 * sizeof( float ) ); float table[ 256 ]; for ( int i = 0; i < 256; i++ ) { table[ i ] = SRGBToLinear( i * ( 1.0f / 255.0f ) ); } for ( int y = 0; y < height; y++ ) { for ( int x = 0; x < width; x++ ) { for ( int c = 0; c < 4; c++ ) { srcLinear[ ( y * width + x ) * 4 + c ] = table[ src[ ( y * width + x ) * 4 + c ] ]; } } } for ( int y = 0; y < newHeight; y++ ) { const int srcY = ( y * height * 2 + offsetY ) / ( newHeight * 2 ); const float fracY = FracFloat( ( ( float )y * height * 2.0f + offsetY ) / ( newHeight * 2.0f ) ); float weightsY[ 4 ]; FilterWeights( fracY, filter, weightsY ); for ( int x = 0; x < newWidth; x++ ) { const int srcX = ( x * width * 2 + offsetX ) / ( newWidth * 2 ); const float fracX = FracFloat( ( ( float )x * width * 2.0f + offsetX ) / ( newWidth * 2.0f ) ); float weightsX[ 4 ]; FilterWeights( fracX, filter, weightsX ); float fR = 0.0f; float fG = 0.0f; float fB = 0.0f; float fA = 0.0f; for ( int fpY = footprintMin; fpY <= footprintMax; fpY++ ) { const float wY = weightsY[ fpY - footprintMin ]; for ( int fpX = footprintMin; fpX <= footprintMax; fpX++ ) { const float wX = weightsX[ fpX - footprintMin ]; const float wXY = wX * wY; const int cx = ClampInt( srcX + fpX, 0, width - 1 ); const int cy = ClampInt( srcY + fpY, 0, height - 1 ); fR += srcLinear[ ( cy * width + cx ) * 4 + 0 ] * wXY; fG += srcLinear[ ( cy * width + cx ) * 4 + 1 ] * wXY; fB += srcLinear[ ( cy * width + cx ) * 4 + 2 ] * wXY; fA += srcLinear[ ( cy * width + cx ) * 4 + 3 ] * wXY; } } scaledLinear[ ( y * newWidth + x ) * 4 + 0 ] = fR; scaledLinear[ ( y * newWidth + x ) * 4 + 1 ] = fG; scaledLinear[ ( y * newWidth + x ) * 4 + 2 ] = fB; scaledLinear[ ( y * newWidth + x ) * 4 + 3 ] = fA; } } for ( int y = 0; y < newHeight; y++ ) { for ( int x = 0; x < newWidth; x++ ) { for ( int c = 0; c < 4; c++ ) { const float gamma = LinearToSRGB( scaledLinear[ ( y * newWidth + x ) * 4 + c ] ); scaled[ ( y * newWidth + x ) * 4 + c ] = ( unsigned char )ClampInt( ( int )( gamma * 255.0f + 0.5f ), 0, 255 ); } } } free( scaledLinear ); free( srcLinear ); return scaled; }
//upkeep void ClampHealth(){ m_currentHealth = ClampInt(m_currentHealth, 0, m_maxHealth); }