Ejemplo n.º 1
0
func (this *FadeData) SetActive(result bool) {
	if result {
		this.Flags |= cseries.Word(0x8000)
	} else {
		this.Flags &^= cseries.Word(0x8000)
	}
}
Ejemplo n.º 2
0
func BurnColorTable(original, animated ColorTable, color *RgbColor, transparency cseries.Fixed) {
	customCeiling := func(n, ceiling int32) int32 {
		if n > ceiling {
			return ceiling
		} else {
			return n
		}
	}
	updateElement := func(adjusted cseries.Word, component int32) cseries.Word {
		return cseries.Word(customCeiling(component, int32(adjusted)))
	}
	computeComponent := func(unadjusted, color cseries.Word, transparency cseries.Fixed) int32 {
		return int32(cseries.Fixed(((color * unadjusted) >> cseries.FixedFractionalBits)) + transparency)
	}
	transparency = cseries.FixedOne - transparency
	for i := 0; i < len(original); i++ {
		r, g, b := original[i].Red, original[i].Green, original[i].Blue
		component := computeComponent(r, color.Red, transparency)
		animated[i].Red = updateElement(r, component)
		component = computeComponent(g, color.Green, transparency)
		animated[i].Green = updateElement(g, component)
		component = computeComponent(b, color.Blue, transparency)
		animated[i].Blue = updateElement(b, component)
	}

	//component= ((color->red*unadjusted->red)>>FIXED_FRACTIONAL_BITS) + transparency, adjusted->red= CEILING(component, unadjusted->red);
	//component= ((color->green*unadjusted->green)>>FIXED_FRACTIONAL_BITS) + transparency, adjusted->green= CEILING(component, unadjusted->green);
	//component= ((color->blue*unadjusted->blue)>>FIXED_FRACTIONAL_BITS) + transparency, adjusted->blue= CEILING(component, unadjusted->blue);

}
Ejemplo n.º 3
0
func DodgeColorTable(original, animated ColorTable, color *RgbColor, transparency cseries.Fixed) {
	customCeiling := func(n, ceiling int32) int32 {
		if n > ceiling {
			return ceiling
		} else {
			return n
		}
	}
	computeComponent := func(unadjusted, color cseries.Word) int32 {
		return int32(0xffff - cseries.Fixed((((color ^ 0xffff) * unadjusted) >> cseries.FixedFractionalBits)) - transparency)
	}
	updateElement := func(adjusted cseries.Word, component int32) cseries.Word {
		return cseries.Word(customCeiling(component, int32(adjusted)))
	}
	for i := 0; i < len(original); i++ {
		var component int32

		component = computeComponent(original[i].Red, color.Red)
		animated[i].Red = updateElement(original[i].Red, component)
		component = computeComponent(original[i].Blue, color.Blue)
		animated[i].Blue = updateElement(original[i].Blue, component)
		component = computeComponent(original[i].Green, color.Green)
		animated[i].Green = updateElement(original[i].Green, component)
	}

	// Using the comma operator instead of ; for assignment...why?
	//component= 0xffff - (((color->red^0xffff)*unadjusted->red)>>FIXED_FRACTIONAL_BITS) - transparency, adjusted->red= CEILING(component, unadjusted->red);
	//component= 0xffff - (((color->green^0xffff)*unadjusted->green)>>FIXED_FRACTIONAL_BITS) - transparency, adjusted->green= CEILING(component, unadjusted->green);
	//component= 0xffff - (((color->blue^0xffff)*unadjusted->blue)>>FIXED_FRACTIONAL_BITS) - transparency, adjusted->blue= CEILING(component, unadjusted->blue);
}
Ejemplo n.º 4
0
func SoftTintColorTable(original, animated ColorTable, color *RgbColor, transparency cseries.Fixed) {
	adjustedTransparency := cseries.Word(transparency >> AdjustedTransparencyDownshift)
	fn := func(x, y, z, w cseries.Word) cseries.Word {
		return cseries.Word(x + (((((y * w) >> (cseries.FixedFractionalBits - AdjustedTransparencyDownshift)) - x) * z) >> (cseries.FixedFractionalBits - AdjustedTransparencyDownshift)))
	}
	for i := 0; i < len(original); i++ {
		intensity := cseries.Word(cseries.Max(int64(original[i].Red), int64(original[i].Green)))
		intensity = cseries.Word(cseries.Max(int64(intensity), int64(original[i].Blue)) >> AdjustedTransparencyDownshift)

		animated[i].Red = fn(original[i].Red, color.Red, adjustedTransparency, intensity)
		animated[i].Green = fn(original[i].Green, color.Green, adjustedTransparency, intensity)
		animated[i].Blue = fn(original[i].Blue, color.Blue, adjustedTransparency, intensity)

	}
	//adjusted->red= unadjusted->red + (((((color->red*intensity)>>(FIXED_FRACTIONAL_BITS-ADJUSTED_TRANSPARENCY_DOWNSHIFT))-unadjusted->red)*adjusted_transparency)>>(FIXED_FRACTIONAL_BITS-ADJUSTED_TRANSPARENCY_DOWNSHIFT));
	//adjusted->green= unadjusted->green + (((((color->green*intensity)>>(FIXED_FRACTIONAL_BITS-ADJUSTED_TRANSPARENCY_DOWNSHIFT))-unadjusted->green)*adjusted_transparency)>>(FIXED_FRACTIONAL_BITS-ADJUSTED_TRANSPARENCY_DOWNSHIFT));
	//adjusted->blue= unadjusted->blue + (((((color->blue*intensity)>>(FIXED_FRACTIONAL_BITS-ADJUSTED_TRANSPARENCY_DOWNSHIFT))-unadjusted->blue)*adjusted_transparency)>>(FIXED_FRACTIONAL_BITS-ADJUSTED_TRANSPARENCY_DOWNSHIFT));
}
Ejemplo n.º 5
0
// unlike pathways, all colors won't pass through 50% gray at the same time
func NegateColorTable(original, animated ColorTable, color *RgbColor, transparency cseries.Fixed) {
	transparency = cseries.FixedOne - transparency

	fn := func(ov, cv cseries.Word) cseries.Word {
		var tmp cseries.Word
		if ov > 0x8000 {
			tmp = (ov ^ cv) + cseries.Word(transparency)
			return tmp.Ceiling(ov)
		} else {
			tmp = (ov ^ cv) - cseries.Word(transparency)
			return tmp.Floor(ov)
		}
	}
	for i := 0; i < len(original); i++ {
		animated[i].Red = fn(original[i].Red, color.Red)
		animated[i].Green = fn(original[i].Green, color.Green)
		animated[i].Blue = fn(original[i].Blue, color.Blue)
	}
}
Ejemplo n.º 6
0
func TintColorTable(original, animated ColorTable, color *RgbColor, transparency cseries.Fixed) {
	adjustedTransparency := transparency >> AdjustedTransparencyDownshift
	fn := func(unadjustedValue, colorValue cseries.Word) cseries.Word {
		return cseries.Word(cseries.Fixed(unadjustedValue) + ((cseries.Fixed(colorValue-unadjustedValue) * adjustedTransparency) >> (cseries.FixedFractionalBits - AdjustedTransparencyDownshift)))
	}
	for i := 0; i < len(original); i++ {
		animated[i].Red = fn(original[i].Red, color.Red)
		animated[i].Green = fn(original[i].Green, color.Green)
		animated[i].Blue = fn(original[i].Blue, color.Blue)
	}
}
Ejemplo n.º 7
0
func RandomizeColorTable(original, animated ColorTable, color *RgbColor, transparency cseries.Fixed) {
	var mask cseries.Word
	adjustedTransparency := transparency.Pin(0, 0xffff)
	// calculate a mask which has all bits including and lower than the high-bit in the transparency set
	for mask = 0; (cseries.Word(adjustedTransparency) &^ mask) != 0; mask = (mask << 1) | 1 {
		// empty loop body
	}
	fn := func(value, mask cseries.Word) cseries.Word {
		return value + (FadesRandom() & mask)
	}
	for i := 0; i < len(original); i++ {
		animated[i].Red = fn(original[i].Red, mask)
		animated[i].Green = fn(original[i].Green, mask)
		animated[i].Blue = fn(original[i].Blue, mask)
	}
}
Ejemplo n.º 8
0
func GammaCorrectColorTable(uncorrected, corrected ColorTable, gammaLevel int16) error {
	var gamma float32
	if !(gammaLevel >= 0 && gammaLevel < NumberOfGammaLevels) {
		return &cseries.AssertionError{
			Function: "GamaCorrectColorTable",
			Message:  fmt.Sprintf("Gamma level (%d) is not between [0,%d)", gammaLevel, NumberOfGammaLevels),
		}
	}
	gamma = ActualGammaValues[gammaLevel]

	fn := func(value cseries.Word, g float32) cseries.Word {
		return cseries.Word(math.Pow(float64(value/65535.0), float64(g)) * 65535.0)
	}
	for i := 0; i < len(uncorrected); i++ {
		corrected[i].Red = fn(uncorrected[i].Red, gamma)
		corrected[i].Green = fn(uncorrected[i].Green, gamma)
		corrected[i].Blue = fn(uncorrected[i].Blue, gamma)
	}

	return nil
}
Ejemplo n.º 9
0
func (this RenderFlags) Set(index, flag int16) {
	this[index] |= cseries.Word(flag)
}
Ejemplo n.º 10
0
func (this RenderFlags) Test(index, flag int16) bool {
	return (this[index] & cseries.Word(flag)) == 1
}
Ejemplo n.º 11
0
func (this *FloodMapNodeData) MarkAsUnexpanded() {
	this.Flags |= cseries.Word(0x8000)
}
Ejemplo n.º 12
0
func (this *FloodMapNodeData) IsExpanded() bool {
	return (this.flags & cseries.Word(0x8000)) != 0
}
Ejemplo n.º 13
0
func (this *FadeDefinition) IsActive() bool {
	return this.Flags&cseries.Word(0x8000) != 0
}
Ejemplo n.º 14
0
	EffectUnderLaval
	EffectUnderSewage
	EffectUnderGoo
	NumberOfFadeEffectTypes
)
const (
	AdjustedTransparencyDownshift = 8

	MinimumFadeRestartTicks = cseries.MachineTicksPerSecond / 2
	MinimumFadeUpdateTicks  = cseries.MachineTicksPerSecond / 8

	FullScreenFlag         = 0x0001
	RandomTransparencyFlag = 0x0002
)

var FadesRandomSeed = cseries.Word(0x1)

func FadesRandom() cseries.Word {
	if (FadesRandomSeed & 1) != 0 {
		FadesRandomSeed = (FadesRandomSeed >> 1) ^ 0xb400
	} else {
		FadesRandomSeed >>= 1
	}
	return FadesRandomSeed
}

type FadeProcedure func(ColorTable, ColorTable, *RgbColor, cseries.Fixed)

type FadeEffectDefinition struct {
	Type         int16
	Transparency cseries.Fixed