Bugfixes for CDataBase/COpenGL
Changed dynamic song loading to not use a thread as it was not threadsafe before
This commit is contained in:
1 parent
bd3f51b17e
commit
d2f8af880e
4 files changed
+45
-42
No files matched your search
@@ -1011,8 +1011,6 @@ namespace Vocaluxe.Base
|
|||||||
#region Cover
|
#region Cover
|
||||||
public static bool GetCover(string CoverPath, ref STexture tex, int MaxSize)
|
public static bool GetCover(string CoverPath, ref STexture tex, int MaxSize)
|
||||||
{
|
{
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
if (!File.Exists(CoverPath))
|
if (!File.Exists(CoverPath))
|
||||||
{
|
{
|
||||||
CLog.LogError("Can't find File: " + CoverPath);
|
CLog.LogError("Can't find File: " + CoverPath);
|
||||||
@@ -1048,10 +1046,11 @@ namespace Vocaluxe.Base
|
|||||||
|
|
||||||
if (reader.HasRows)
|
if (reader.HasRows)
|
||||||
{
|
{
|
||||||
result = true;
|
|
||||||
reader.Read();
|
reader.Read();
|
||||||
byte[] data = GetBytes(reader);
|
byte[] data = GetBytes(reader);
|
||||||
|
reader.Dispose();
|
||||||
tex = CDraw.QuequeTexture(w, h, ref data);
|
tex = CDraw.QuequeTexture(w, h, ref data);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1120,19 +1119,17 @@ namespace Vocaluxe.Base
|
|||||||
{
|
{
|
||||||
reader.Read();
|
reader.Read();
|
||||||
int id = reader.GetInt32(0);
|
int id = reader.GetInt32(0);
|
||||||
|
reader.Dispose();
|
||||||
command.CommandText = "INSERT INTO CoverData (CoverID, Data) VALUES (@id, @data)";
|
command.CommandText = "INSERT INTO CoverData (CoverID, Data) VALUES (@id, @data)";
|
||||||
command.Parameters.Add("@id", DbType.Int32).Value = id;
|
command.Parameters.Add("@id", DbType.Int32).Value = id;
|
||||||
command.Parameters.Add("@data", System.Data.DbType.Binary, 20).Value = data;
|
command.Parameters.Add("@data", System.Data.DbType.Binary, 20).Value = data;
|
||||||
command.ExecuteReader();
|
command.ExecuteReader();
|
||||||
result = true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reader != null)
|
|
||||||
reader.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CommitCovers()
|
public static void CommitCovers()
|
||||||
@@ -1284,14 +1281,7 @@ namespace Vocaluxe.Base
|
|||||||
|
|
||||||
command.CommandText = "SELECT Data FROM ImageData WHERE ImageID = @id";
|
command.CommandText = "SELECT Data FROM ImageData WHERE ImageID = @id";
|
||||||
command.Parameters.Add("@id",DbType.Int32).Value=id;
|
command.Parameters.Add("@id",DbType.Int32).Value=id;
|
||||||
try
|
reader = command.ExecuteReader();
|
||||||
{
|
|
||||||
reader = command.ExecuteReader();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reader.HasRows)
|
if (reader.HasRows)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ namespace Vocaluxe.Base
|
|||||||
CInput.Update();
|
CInput.Update();
|
||||||
|
|
||||||
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && _CurrentScreen != EScreens.ScreenSing)
|
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && _CurrentScreen != EScreens.ScreenSing)
|
||||||
CSongs.LoadCover();
|
CSongs.LoadCover(30, 1);
|
||||||
|
|
||||||
if (CSettings.GameState != EGameState.EditTheme)
|
if (CSettings.GameState != EGameState.EditTheme)
|
||||||
{
|
{
|
||||||
|
|||||||
+30
-24
@@ -43,7 +43,7 @@ namespace Vocaluxe.Base
|
|||||||
|
|
||||||
private static bool _SongsLoaded = false;
|
private static bool _SongsLoaded = false;
|
||||||
private static bool _CoverLoaded = false;
|
private static bool _CoverLoaded = false;
|
||||||
private static int _CoverLoadIndex = -1;
|
private static int _CoverLoadIndex = 0;
|
||||||
private static int _CatIndex = -1;
|
private static int _CatIndex = -1;
|
||||||
private static bool _Init = false;
|
private static bool _Init = false;
|
||||||
private static List<CCategory> _Categories = new List<CCategory>();
|
private static List<CCategory> _Categories = new List<CCategory>();
|
||||||
@@ -57,8 +57,6 @@ namespace Vocaluxe.Base
|
|||||||
private static ESongSorting _SongSorting = CConfig.SongSorting;
|
private static ESongSorting _SongSorting = CConfig.SongSorting;
|
||||||
private static bool _ShowDuetSongs = true;
|
private static bool _ShowDuetSongs = true;
|
||||||
|
|
||||||
private static Thread _CoverLoaderThread = null;
|
|
||||||
|
|
||||||
public static string SearchFilter
|
public static string SearchFilter
|
||||||
{
|
{
|
||||||
get { return _SearchFilter; }
|
get { return _SearchFilter; }
|
||||||
@@ -180,10 +178,10 @@ namespace Vocaluxe.Base
|
|||||||
if (!SongsLoaded)
|
if (!SongsLoaded)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (_Songs.Count > _CoverLoadIndex + 1)
|
if (_CoverLoadIndex < _Songs.Count)
|
||||||
{
|
{
|
||||||
_CoverLoadIndex++;
|
|
||||||
Song = _Songs[_CoverLoadIndex];
|
Song = _Songs[_CoverLoadIndex];
|
||||||
|
_CoverLoadIndex++;
|
||||||
return _CoverLoadIndex;
|
return _CoverLoadIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +189,7 @@ namespace Vocaluxe.Base
|
|||||||
}
|
}
|
||||||
public static int NumSongsWithCoverLoaded
|
public static int NumSongsWithCoverLoaded
|
||||||
{
|
{
|
||||||
get { return _CoverLoadIndex + 1; }
|
get { return _CoverLoadIndex; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetCoverSmall(int SongIndex, STexture Texture)
|
public static void SetCoverSmall(int SongIndex, STexture Texture)
|
||||||
@@ -200,11 +198,7 @@ namespace Vocaluxe.Base
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (SongIndex < _Songs.Count)
|
if (SongIndex < _Songs.Count)
|
||||||
{
|
|
||||||
_Songs[SongIndex].CoverTextureSmall = Texture;
|
_Songs[SongIndex].CoverTextureSmall = Texture;
|
||||||
if (SongIndex == _Songs.Count - 1)
|
|
||||||
_CoverLoaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public static void SetCoverBig(int SongIndex, STexture Texture)
|
public static void SetCoverBig(int SongIndex, STexture Texture)
|
||||||
@@ -213,11 +207,7 @@ namespace Vocaluxe.Base
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (SongIndex < _Songs.Count)
|
if (SongIndex < _Songs.Count)
|
||||||
{
|
|
||||||
_Songs[SongIndex].CoverTextureBig = Texture;
|
_Songs[SongIndex].CoverTextureBig = Texture;
|
||||||
if (SongIndex == _Songs.Count - 1)
|
|
||||||
_CoverLoaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -752,32 +742,48 @@ namespace Vocaluxe.Base
|
|||||||
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART)
|
if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART)
|
||||||
{
|
{
|
||||||
CLog.StartBenchmark(2, "Load Covers/Notes");
|
CLog.StartBenchmark(2, "Load Covers/Notes");
|
||||||
_LoadCover();
|
_LoadCoverAndNotes();
|
||||||
CLog.StopBenchmark(2, "Load Covers/Notes");
|
CLog.StopBenchmark(2, "Load Covers/Notes");
|
||||||
}
|
}
|
||||||
CLog.StopBenchmark(1, "Load Songs ");
|
CLog.StopBenchmark(1, "Load Songs ");
|
||||||
GC.Collect();
|
GC.Collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadCover()
|
public static void LoadCover(int WaitTime, int NumLoads)
|
||||||
{
|
{
|
||||||
if (CConfig.Renderer == ERenderer.TR_CONFIG_SOFTWARE)
|
if (CConfig.Renderer == ERenderer.TR_CONFIG_SOFTWARE)
|
||||||
return;
|
return; //should be removed as soon as the other renderer are ready for queque
|
||||||
|
|
||||||
if (!SongsLoaded || CoverLoaded)
|
if (!SongsLoaded || CoverLoaded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_CoverLoaderThread == null)
|
if (!_CoverLoadTimer.IsRunning)
|
||||||
{
|
{
|
||||||
_CoverLoaderThread = new Thread(new ThreadStart(_LoadCover));
|
_CoverLoadTimer.Reset();
|
||||||
_CoverLoaderThread.Name = "CoverLoader";
|
_CoverLoadTimer.Start();
|
||||||
_CoverLoaderThread.Priority = ThreadPriority.BelowNormal;
|
}
|
||||||
_CoverLoaderThread.IsBackground = true;
|
|
||||||
_CoverLoaderThread.Start();
|
if (_CoverLoadTimer.ElapsedMilliseconds >= WaitTime)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < NumLoads; i++)
|
||||||
|
{
|
||||||
|
CSong song = null;
|
||||||
|
int n = GetNextSongWithoutCover(ref song);
|
||||||
|
|
||||||
|
if (n < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
song.LoadSmallCover();
|
||||||
|
|
||||||
|
if (n == NumAllSongs)
|
||||||
|
CDataBase.CommitCovers();
|
||||||
|
}
|
||||||
|
_CoverLoadTimer.Reset();
|
||||||
|
_CoverLoadTimer.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void _LoadCover()
|
private static void _LoadCoverAndNotes()
|
||||||
{
|
{
|
||||||
foreach(CSong song in _Songs)
|
foreach(CSong song in _Songs)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -733,7 +733,14 @@ namespace Vocaluxe.Lib.Draw
|
|||||||
CLog.LogError("Error loading Texture: " + TexturePath);
|
CLog.LogError("Error loading Texture: " + TexturePath);
|
||||||
return new STexture(-1);
|
return new STexture(-1);
|
||||||
}
|
}
|
||||||
return AddTexture(bmp, TexturePath);
|
try
|
||||||
|
{
|
||||||
|
return AddTexture(bmp, TexturePath);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
bmp.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
CLog.LogError("Can't find File: " + TexturePath);
|
CLog.LogError("Can't find File: " + TexturePath);
|
||||||
return new STexture(-1);
|
return new STexture(-1);
|
||||||
|
|||||||
Reference in new issue
Block a user