Ejemplo n.º 1
0
func UpdateFades() (bool, error) {
	if Fade.IsActive() {
		definition, err := GetFadeDefinition(Fade.Type)
		if err != nil {
			return false, err
		}
		tickCount, err0 := cseries.MachineTickCount()
		if err0 != nil {
			return false, err0
		}
		update := false
		var transparency cseries.Fixed
		phase := int16(tickCount - Fade.StartTick) // hmmm, this could be a problem
		if phase >= definition.Period {
			transparency = definition.FinalTransparency
			Fade.SetActive(false)
			update = true
		} else {
			if (tickCount - Fade.LastUpdateTick) >= MinimumFadeUpdateTicks {
				transparency = definition.InitialTransparency + (cseries.Fixed(phase)*(definition.FinalTransparency-definition.InitialTransparency))/cseries.Fixed(definition.Period)
				if (definition.Flags & RandomTransparencyFlag) != 0 {
					transparency += cseries.Fixed(FadesRandom()) % (definition.FinalTransparency - transparency)
				}
				update = true
			}
			if update {
				RecalculateAndDisplayColorTable(Fade.Type, transparency, Fade.OriginalColorTable, Fade.AnimatedColorTable)
			}
		}

	}
	return Fade.IsActive(), nil
}
Ejemplo n.º 2
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.º 3
0
func (this mediaIndex) UpdateOneMedia(forceUpdate bool) {
	media := this.GetMediaData()
	def := GetMediaDefinition(media.Type)

	// update height
	media.Height = media.Low + WorldDistance(cseries.Fixed(cseries.Fixed(media.High-media.Low)*GetLightIntensity(media.LightIndex)).IntegralPart())

	// update texture
	media.Texture = BuildDescriptor(def.Collection, def.Shape)
	media.TransferMode = def.TransferMode

}
Ejemplo n.º 4
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.º 5
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.º 6
0
func (this *MediaData) CalculateMediaHeight() int16 {
	return int16(this.Low) + cseries.Fixed(cseries.Fixed(this.Height-this.Low)*GetLightIntensity(this.LightIndex)).IntegralPart()
}