Example #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
}
Example #2
0
func ExplicitStartFade(fade int16, originalColorTable, animatedColorTable ColorTable) error {
	definition, err1 := GetFadeDefinition(fade)
	if err1 != nil {
		return err1
	}
	tickCount, err0 := cseries.MachineTickCount()
	if err0 != nil {
		return err0
	}
	doFade := true

	if Fade.IsActive() {
		oldDefinition, err2 := GetFadeDefinition(Fade.Type)
		if err2 != nil {
			return err2
		}
		if oldDefinition.Priority > definition.Priority {
			doFade = false
		}

		if ((tickCount - Fade.StartTick) > MinimumFadeRestartTicks) && Fade.Type == fade {
			doFade = false
		}
	}

	if doFade {
		Fade.SetActive(false)

		RecalculateAndDisplayColorTable(fade, definition.InitialTransparency, originalColorTable, animatedColorTable)
		if definition.Period != 0 {
			Fade.Type = fade
			Fade.LastUpdateTick = tickCount
			Fade.StartTick = tickCount
			Fade.OriginalColorTable = originalColorTable
			Fade.AnimatedColorTable = animatedColorTable
			Fade.SetActive(true)
		}
	}
	return nil
}