Fixed floating point comparisons

This commit is contained in:
Flamefire committed 2013-04-23 15:42:32 +02:00
1 parent 9d481cabc1
commit 5cd47f0537
13 files changed
+32 -32

No files matched your search

+10 -10
View File
@@ -211,7 +211,7 @@ namespace Vocaluxe.Base
if (_AllFileNames.Count > 0 && _CurrentMusicStream != -1) if (_AllFileNames.Count > 0 && _CurrentMusicStream != -1)
{ {
float timeToPlay; float timeToPlay;
if (_CurrentPlaylistElement.Finish == 0f) //No End-Tag defined if (Math.Abs(_CurrentPlaylistElement.Finish) < 0.001) //No End-Tag defined
timeToPlay = CSound.GetLength(_CurrentMusicStream) - CSound.GetPosition(_CurrentMusicStream); timeToPlay = CSound.GetLength(_CurrentMusicStream) - CSound.GetPosition(_CurrentMusicStream);
else //End-Tag found else //End-Tag found
timeToPlay = _CurrentPlaylistElement.Finish - CSound.GetPosition(_CurrentMusicStream); timeToPlay = _CurrentPlaylistElement.Finish - CSound.GetPosition(_CurrentMusicStream);
@@ -222,13 +222,13 @@ namespace Vocaluxe.Base
if (_RepeatSong) if (_RepeatSong)
{ {
//Seek to #Start-Tag, if found //Seek to #Start-Tag, if found
if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON)
CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start); CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start);
else else
CSound.SetPosition(_CurrentMusicStream, 0); CSound.SetPosition(_CurrentMusicStream, 0);
if (_VideoEnabled && _Video != -1) if (_VideoEnabled && _Video != -1)
{ {
if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) if (_CurrentPlaylistElement.Start >0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON)
CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap);
else else
CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap); CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap);
@@ -269,7 +269,7 @@ namespace Vocaluxe.Base
CSound.SetStreamVolumeMax(_CurrentMusicStream, CConfig.BackgroundMusicVolume); CSound.SetStreamVolumeMax(_CurrentMusicStream, CConfig.BackgroundMusicVolume);
//Seek to #Start-Tag, if found //Seek to #Start-Tag, if found
if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) if (_CurrentPlaylistElement.Start >0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON)
CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start); CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start);
if (_VideoEnabled) if (_VideoEnabled)
@@ -289,13 +289,13 @@ namespace Vocaluxe.Base
if (CSound.GetPosition(_CurrentMusicStream) >= 1.5f) if (CSound.GetPosition(_CurrentMusicStream) >= 1.5f)
{ {
//Seek to #Start-Tag, if found //Seek to #Start-Tag, if found
if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) if (_CurrentPlaylistElement.Start >0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON)
CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start); CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start);
else else
CSound.SetPosition(_CurrentMusicStream, 0); CSound.SetPosition(_CurrentMusicStream, 0);
if (_VideoEnabled && _Video != -1) if (_VideoEnabled && _Video != -1)
{ {
if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) if (_CurrentPlaylistElement.Start >0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON)
CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap);
else else
CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap); CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap);
@@ -321,13 +321,13 @@ namespace Vocaluxe.Base
else if (_CurrentMusicStream != -1) else if (_CurrentMusicStream != -1)
{ {
//Seek to #Start-Tag, if found //Seek to #Start-Tag, if found
if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) if (_CurrentPlaylistElement.Start >0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON)
CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start); CSound.SetPosition(_CurrentMusicStream, _CurrentPlaylistElement.Start);
else else
CSound.SetPosition(_CurrentMusicStream, 0); CSound.SetPosition(_CurrentMusicStream, 0);
if (_VideoEnabled && _Video != -1) if (_VideoEnabled && _Video != -1)
{ {
if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON)
CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap);
else else
CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap); CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap);
@@ -434,7 +434,7 @@ namespace Vocaluxe.Base
Pause(); Pause();
} }
if (CConfig.BackgroundMusicVolume != newVolume) if (Math.Abs(CConfig.BackgroundMusicVolume - newVolume) > 0.01)
{ {
CConfig.BackgroundMusicVolume = (int)newVolume; CConfig.BackgroundMusicVolume = (int)newVolume;
ApplyVolume(); ApplyVolume();
@@ -499,7 +499,7 @@ namespace Vocaluxe.Base
if (_Video == -1) if (_Video == -1)
{ {
_Video = CVideo.VdLoad(_CurrentPlaylistElement.VideoFilePath); _Video = CVideo.VdLoad(_CurrentPlaylistElement.VideoFilePath);
if (_CurrentPlaylistElement.Start != 0f && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) if (_CurrentPlaylistElement.Start >0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON)
CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); CVideo.VdSkip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap);
else else
CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap); CVideo.VdSkip(_Video, 0f, _CurrentPlaylistElement.VideoGap);
+1 -1
View File
@@ -122,7 +122,7 @@ namespace Vocaluxe.Base
if (Math.Abs(_Cursor.Rect.X - x) > CSettings.MouseMoveDiffMin || if (Math.Abs(_Cursor.Rect.X - x) > CSettings.MouseMoveDiffMin ||
Math.Abs(_Cursor.Rect.Y - y) > CSettings.MouseMoveDiffMin) Math.Abs(_Cursor.Rect.Y - y) > CSettings.MouseMoveDiffMin)
{ {
if (_CursorTargetAlpha == 0f) if (_CursorTargetAlpha < 0.01)
_Fade(1f, 0.2f); _Fade(1f, 0.2f);
_Movetimer.Reset(); _Movetimer.Reset();
+1 -1
View File
@@ -156,7 +156,7 @@ namespace Vocaluxe.Base
space += " "; space += " ";
float ms; float ms;
if (Stopwatch.IsHighResolution && _NanosecPerTick != 0.0) if (Stopwatch.IsHighResolution && _NanosecPerTick > 0)
ms = (float)((_NanosecPerTick * _BenchmarkTimer[benchmarkNr].ElapsedTicks) / (1000.0 * 1000.0)); ms = (float)((_NanosecPerTick * _BenchmarkTimer[benchmarkNr].ElapsedTicks) / (1000.0 * 1000.0));
else else
ms = _BenchmarkTimer[benchmarkNr].ElapsedMilliseconds; ms = _BenchmarkTimer[benchmarkNr].ElapsedMilliseconds;
+1 -1
View File
@@ -319,7 +319,7 @@ namespace Vocaluxe.Lib.Draw
public void CopyScreen(ref STexture texture) public void CopyScreen(ref STexture texture)
{ {
if ((texture.Index == 0) || (texture.Width != GetScreenWidth()) || (texture.Height != GetScreenHeight())) if (texture.Index == 0 || (int)texture.Width != GetScreenWidth() || (int)texture.Height != GetScreenHeight())
{ {
RemoveTexture(ref texture); RemoveTexture(ref texture);
texture = CopyScreen(); texture = CopyScreen();
+1 -1
View File
@@ -57,7 +57,7 @@ namespace Vocaluxe.Lib.Input
{ {
get get
{ {
if (!_Timer.IsRunning && _Duration != 0f) if (!_Timer.IsRunning && Math.Abs(_Duration) > float.Epsilon)
{ {
_Timer.Start(); _Timer.Start();
return true; return true;
+3 -3
View File
@@ -317,7 +317,7 @@ namespace Vocaluxe.Screens
{ {
_CurrentTime = CSound.GetPosition(_CurrentStream); _CurrentTime = CSound.GetPosition(_CurrentStream);
if (_FinishTime != 0 && _CurrentTime >= _FinishTime) if (_FinishTime >0.001 && _CurrentTime >= _FinishTime)
finish = true; finish = true;
} }
else else
@@ -1237,7 +1237,7 @@ namespace Vocaluxe.Screens
return; return;
float totalTime = CSound.GetLength(_CurrentStream); float totalTime = CSound.GetLength(_CurrentStream);
if (song.Finish != 0) if (Math.Abs(song.Finish) > 0.001)
totalTime = song.Finish; totalTime = song.Finish;
float remainingTime = totalTime - _CurrentTime; float remainingTime = totalTime - _CurrentTime;
@@ -1316,7 +1316,7 @@ namespace Vocaluxe.Screens
return; return;
float totalTime = CSound.GetLength(_CurrentStream); float totalTime = CSound.GetLength(_CurrentStream);
if (song.Finish != 0) if (Math.Abs(song.Finish) > 0.001)
totalTime = song.Finish; totalTime = song.Finish;
totalTime -= song.Start; totalTime -= song.Start;
+4 -4
View File
@@ -105,7 +105,7 @@ namespace VocaluxeLib.Menu
public bool IsAlive public bool IsAlive
{ {
get { return _Age < _MaxAge || _MaxAge == 0f; } get { return _Age < _MaxAge || Math.Abs(_MaxAge) < float.Epsilon; }
} }
#endregion public vars #endregion public vars
@@ -218,7 +218,7 @@ namespace VocaluxeLib.Menu
if (Math.Round(Y) < maxy) if (Math.Round(Y) < maxy)
{ {
float vdx = 0f; float vdx = 0f;
if (_Vx != 0) if (Math.Abs(_Vx) > float.Epsilon)
vdx = (float)Math.Sin(currentTime / _Vx * Math.PI); vdx = (float)Math.Sin(currentTime / _Vx * Math.PI);
X += _Vx * timediff * (0.5f + vdx); X += _Vx * timediff * (0.5f + vdx);
@@ -242,7 +242,7 @@ namespace VocaluxeLib.Menu
// update size // update size
if (_Vsize != 0f) if (Math.Abs(_Vsize) > float.Epsilon)
{ {
float size = _Size; float size = _Size;
switch (_Type) switch (_Type)
@@ -275,7 +275,7 @@ namespace VocaluxeLib.Menu
} }
// update rotation // update rotation
if (_Vr != 0f) if (Math.Abs(_Vr) > 0.01)
{ {
float r = currentTime * _Vr / 60f; float r = currentTime * _Vr / 60f;
_Angle = _Rotation + 360f * (r - (float)Math.Floor(r)); _Angle = _Rotation + 360f * (r - (float)Math.Floor(r));
+2 -2
View File
@@ -503,11 +503,11 @@ namespace VocaluxeLib.Menu
writer.WriteElementString("TextH", TextH.ToString("#0.00")); writer.WriteElementString("TextH", TextH.ToString("#0.00"));
writer.WriteComment("<TextRelativeX>: Text relative x-position"); writer.WriteComment("<TextRelativeX>: Text relative x-position");
if (TextRelativeX != 0) if (Math.Abs(TextRelativeX) > 0.01)
writer.WriteElementString("TextRelativeX", TextRelativeX.ToString("#0.00")); writer.WriteElementString("TextRelativeX", TextRelativeX.ToString("#0.00"));
writer.WriteComment("<TextRelativeY>: Text relative y-position"); writer.WriteComment("<TextRelativeY>: Text relative y-position");
if (TextRelativeY != 0) if (Math.Abs(TextRelativeY) > 0.01)
writer.WriteElementString("TextRelativeY", TextRelativeY.ToString("#0.00")); writer.WriteElementString("TextRelativeY", TextRelativeY.ToString("#0.00"));
writer.WriteComment("<TextMaxW>: Maximum text width (if exists)"); writer.WriteComment("<TextMaxW>: Maximum text width (if exists)");
+5 -5
View File
@@ -74,7 +74,7 @@ namespace VocaluxeLib.Menu
get { return _X; } get { return _X; }
set set
{ {
if (_X != value) if (Math.Abs(_X - value) > 0.01)
{ {
_X = value; _X = value;
_PositionNeedsUpdate = true; _PositionNeedsUpdate = true;
@@ -89,7 +89,7 @@ namespace VocaluxeLib.Menu
get { return _Y; } get { return _Y; }
set set
{ {
if (_Y != value) if (Math.Abs(_Y - value) > 0.01)
{ {
_Y = value; _Y = value;
_PositionNeedsUpdate = true; _PositionNeedsUpdate = true;
@@ -110,7 +110,7 @@ namespace VocaluxeLib.Menu
get { return _Height; } get { return _Height; }
set set
{ {
if (_Height != value) if (Math.Abs(_Height - value) > 0.01)
{ {
_Height = value; _Height = value;
_PositionNeedsUpdate = true; _PositionNeedsUpdate = true;
@@ -124,7 +124,7 @@ namespace VocaluxeLib.Menu
get { return _MaxWidth; } get { return _MaxWidth; }
set set
{ {
if (_MaxWidth != value) if (Math.Abs(_MaxWidth - value) > 0.01)
{ {
_MaxWidth = value; _MaxWidth = value;
if (_MaxWidth > 0) if (_MaxWidth > 0)
@@ -143,7 +143,7 @@ namespace VocaluxeLib.Menu
get { return _Bounds; } get { return _Bounds; }
set set
{ {
if (_Bounds.X != value.X || _Bounds.Y != value.Y || _Bounds.W != value.W || _Bounds.H != value.H || _Bounds.Z != value.Z) if (Math.Abs(_Bounds.X - value.X) > 0.01 || Math.Abs(_Bounds.Y - value.Y) > 0.01 || Math.Abs(_Bounds.W - value.W) > 0.01 || Math.Abs(_Bounds.H - value.H) > 0.01 || Math.Abs(_Bounds.Z - value.Z) > 0.01)
{ {
_Bounds = value; _Bounds = value;
_PositionNeedsUpdate = true; _PositionNeedsUpdate = true;
+1 -1
View File
@@ -316,7 +316,7 @@ namespace VocaluxeLib.Menu.SingNotes
float beats = line.LastNoteBeat - line.FirstNoteBeat + 1; float beats = line.LastNoteBeat - line.FirstNoteBeat + 1;
if (beats == 0) if (beats < 1)
return; return;
SColorF color = new SColorF( SColorF color = new SColorF(
+1 -1
View File
@@ -988,7 +988,7 @@ namespace VocaluxeLib.Menu.SongMenu
} }
} }
if (PreviewStart == 0f) if (Math.Abs(PreviewStart) < 0.001)
{ {
if (Medley.Source == EMedleySource.Calculated) if (Medley.Source == EMedleySource.Calculated)
PreviewStart = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM); PreviewStart = CBase.Game.GetTimeFromBeats(Medley.StartBeat, BPM);
@@ -616,7 +616,7 @@ namespace VocaluxeLib.Menu.SongMenu
float startposition = CBase.Songs.GetVisibleSong(_Actsong).PreviewStart; float startposition = CBase.Songs.GetVisibleSong(_Actsong).PreviewStart;
if (startposition == 0f) if (Math.Abs(startposition) < 0.001)
startposition = CBase.Sound.GetLength(stream) / 4f; startposition = CBase.Sound.GetLength(stream) / 4f;
CBase.Sound.SetPosition(stream, startposition); CBase.Sound.SetPosition(stream, startposition);
@@ -423,7 +423,7 @@ namespace VocaluxeLib.Menu.SongMenu
_MedleyTagIcon.Visible = song.Medley.Source == EMedleySource.Tag; _MedleyTagIcon.Visible = song.Medley.Source == EMedleySource.Tag;
float time = CBase.Sound.GetLength(_SongStream); float time = CBase.Sound.GetLength(_SongStream);
if (song.Finish != 0) if (Math.Abs(song.Finish) > 0.001)
time = song.Finish; time = song.Finish;
time -= song.Start; time -= song.Start;