From 19276c7a32f5cbba927c2d0c48e03fb019d8e2f0 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Mon, 12 Mar 2012 18:28:11 +0100 Subject: [PATCH 01/38] fixed handling of null strings in CLanguage.cs --- Vocaluxe/Base/CLanguage.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Vocaluxe/Base/CLanguage.cs b/Vocaluxe/Base/CLanguage.cs index cf118839..6b209bba 100644 --- a/Vocaluxe/Base/CLanguage.cs +++ b/Vocaluxe/Base/CLanguage.cs @@ -77,6 +77,9 @@ namespace Vocaluxe.Base public static string Translate(string KeyWord) { + if (KeyWord == null) + return null; + if (KeyWord.Length < 3) return KeyWord; From fd12b25d1e94b930b552da6a9a60d2608423375f Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Mon, 12 Mar 2012 19:40:37 +0100 Subject: [PATCH 02/38] close video in preview if the music is finished (by Darkice) --- Vocaluxe/Menu/SongMenu/CSongMenuFramework.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vocaluxe/Menu/SongMenu/CSongMenuFramework.cs b/Vocaluxe/Menu/SongMenu/CSongMenuFramework.cs index 43cd6f28..7c5c069e 100644 --- a/Vocaluxe/Menu/SongMenu/CSongMenuFramework.cs +++ b/Vocaluxe/Menu/SongMenu/CSongMenuFramework.cs @@ -394,7 +394,7 @@ namespace Vocaluxe.Menu.SongMenu if (_streams.Count > 0 && _video != -1) { - if (CVideo.VdFinished(_video)) + if (CVideo.VdFinished(_video) || CSound.IsFinished(_actsongstream)) { CVideo.VdClose(_video); _video = -1; From a88dd887547c21e986c1ccf40cba4b311240013a Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Mon, 12 Mar 2012 20:55:35 +0100 Subject: [PATCH 03/38] added outline font support, changed theme system version to 5, updated ambient theme with outline fonts --- Output/Fonts/Fonts.xml | 18 +++ Output/Themes/Ambient.xml | 4 +- .../Ambient/Screens/ScreenHighscore.xml | 86 +++++++------- Output/Themes/Ambient/Screens/ScreenLoad.xml | 6 +- Output/Themes/Ambient/Screens/ScreenMain.xml | 8 +- Output/Themes/Ambient/Screens/ScreenNames.xml | 20 ++-- .../Themes/Ambient/Screens/ScreenOptions.xml | 12 +- .../Ambient/Screens/ScreenOptionsGame.xml | 28 ++--- .../Ambient/Screens/ScreenOptionsRecord.xml | 32 +++--- .../Ambient/Screens/ScreenOptionsSound.xml | 20 ++-- .../Ambient/Screens/ScreenOptionsTheme.xml | 32 +++--- .../Ambient/Screens/ScreenOptionsVideo.xml | 16 +-- .../Themes/Ambient/Screens/ScreenProfiles.xml | 32 +++--- Output/Themes/Ambient/Screens/ScreenScore.xml | 52 ++++----- Output/Themes/Ambient/Screens/ScreenSing.xml | 4 +- Output/Themes/Ambient/Screens/ScreenSong.xml | 14 +-- Output/Themes/Ambient/Skin Blue.xml | 2 +- Output/Themes/Ambient/Skin Green.xml | 2 +- Output/Themes/Ambient/Skin Red.xml | 2 +- Output/Themes/Ambient/Skin Yellow.xml | 2 +- .../Changelog/Changelog_ThemeSystem.txt | 13 +++ Vocaluxe/Base/CFont.cs | 107 ++++++++++++++++-- Vocaluxe/Base/CTheme.cs | 2 +- Vocaluxe/Menu/CLyric.cs | 2 +- Vocaluxe/Menu/CText.cs | 9 ++ 25 files changed, 328 insertions(+), 197 deletions(-) diff --git a/Output/Fonts/Fonts.xml b/Output/Fonts/Fonts.xml index f9bd90df..5d499a59 100644 --- a/Output/Fonts/Fonts.xml +++ b/Output/Fonts/Fonts.xml @@ -2,10 +2,28 @@ Normal + 0,00 + 0,00 + 0,00 + 0,00 + 1,00 FreeSans FreeSans.ttf FreeSansBold.ttf FreeSansOblique.ttf FreeSansBoldOblique.ttf + + Outline + 0,08 + 0,00 + 0,00 + 0,00 + 1,00 + FreeSans + FreeSans.ttf + FreeSansBold.ttf + FreeSansOblique.ttf + FreeSansBoldOblique.ttf + \ No newline at end of file diff --git a/Output/Themes/Ambient.xml b/Output/Themes/Ambient.xml index 033f80e3..25940dca 100644 --- a/Output/Themes/Ambient.xml +++ b/Output/Themes/Ambient.xml @@ -1,12 +1,12 @@  - 4 + 5 Ambient bohning Ambient 0 - 1 + 2 Cursor diff --git a/Output/Themes/Ambient/Screens/ScreenHighscore.xml b/Output/Themes/Ambient/Screens/ScreenHighscore.xml index 596abbd3..80f2dd70 100644 --- a/Output/Themes/Ambient/Screens/ScreenHighscore.xml +++ b/Output/Themes/Ambient/Screens/ScreenHighscore.xml @@ -65,7 +65,7 @@ - Normal + Outline TR_SCREENHIGHSCORE_HIGHSCORE @@ -92,7 +92,7 @@ - Normal + Outline @@ -119,7 +119,7 @@ - Normal + Outline @@ -146,7 +146,7 @@ - Normal + Outline @@ -173,7 +173,7 @@ - Normal + Outline @@ -200,7 +200,7 @@ - Normal + Outline @@ -227,7 +227,7 @@ - Normal + Outline @@ -254,7 +254,7 @@ - Normal + Outline @@ -281,7 +281,7 @@ - Normal + Outline @@ -308,7 +308,7 @@ - Normal + Outline @@ -335,7 +335,7 @@ - Normal + Outline @@ -362,7 +362,7 @@ - Normal + Outline @@ -389,7 +389,7 @@ - Normal + Outline @@ -416,7 +416,7 @@ - Normal + Outline @@ -443,7 +443,7 @@ - Normal + Outline @@ -470,7 +470,7 @@ - Normal + Outline @@ -497,7 +497,7 @@ - Normal + Outline @@ -524,7 +524,7 @@ - Normal + Outline @@ -551,7 +551,7 @@ - Normal + Outline @@ -578,7 +578,7 @@ - Normal + Outline @@ -605,7 +605,7 @@ - Normal + Outline @@ -632,7 +632,7 @@ - Normal + Outline @@ -659,7 +659,7 @@ - Normal + Outline @@ -686,7 +686,7 @@ - Normal + Outline @@ -713,7 +713,7 @@ - Normal + Outline @@ -740,7 +740,7 @@ - Normal + Outline @@ -767,7 +767,7 @@ - Normal + Outline @@ -794,7 +794,7 @@ - Normal + Outline @@ -821,7 +821,7 @@ - Normal + Outline @@ -848,7 +848,7 @@ - Normal + Outline @@ -875,7 +875,7 @@ - Normal + Outline @@ -902,7 +902,7 @@ - Normal + Outline @@ -929,7 +929,7 @@ - Normal + Outline @@ -956,7 +956,7 @@ - Normal + Outline @@ -983,7 +983,7 @@ - Normal + Outline @@ -1010,7 +1010,7 @@ - Normal + Outline @@ -1037,7 +1037,7 @@ - Normal + Outline @@ -1064,7 +1064,7 @@ - Normal + Outline @@ -1091,7 +1091,7 @@ - Normal + Outline @@ -1118,7 +1118,7 @@ - Normal + Outline @@ -1145,7 +1145,7 @@ - Normal + Outline @@ -1172,7 +1172,7 @@ - Normal + Outline @@ -1199,7 +1199,7 @@ - Normal + Outline diff --git a/Output/Themes/Ambient/Screens/ScreenLoad.xml b/Output/Themes/Ambient/Screens/ScreenLoad.xml index a85293a5..bda793ce 100644 --- a/Output/Themes/Ambient/Screens/ScreenLoad.xml +++ b/Output/Themes/Ambient/Screens/ScreenLoad.xml @@ -49,7 +49,7 @@ - Normal + Outline TR_PROGRAM_NAME @@ -76,7 +76,7 @@ - Normal + Outline TR_SCREENLOAD_LOADING @@ -103,7 +103,7 @@ - Normal + Outline diff --git a/Output/Themes/Ambient/Screens/ScreenMain.xml b/Output/Themes/Ambient/Screens/ScreenMain.xml index 63ed0825..41404cb8 100644 --- a/Output/Themes/Ambient/Screens/ScreenMain.xml +++ b/Output/Themes/Ambient/Screens/ScreenMain.xml @@ -65,7 +65,7 @@ - Normal + Outline TR_SCREENMAIN_BUTTON_SING @@ -120,7 +120,7 @@ - Normal + Outline TR_SCREENMAIN_BUTTON_OPTIONS @@ -175,7 +175,7 @@ - Normal + Outline TR_SCREENMAIN_BUTTON_PROFILES @@ -230,7 +230,7 @@ - Normal + Outline TR_BUTTON_EXIT diff --git a/Output/Themes/Ambient/Screens/ScreenNames.xml b/Output/Themes/Ambient/Screens/ScreenNames.xml index 54e3df3c..0daa48e9 100644 --- a/Output/Themes/Ambient/Screens/ScreenNames.xml +++ b/Output/Themes/Ambient/Screens/ScreenNames.xml @@ -65,7 +65,7 @@ - Normal + Outline TR_SCREENNAMES_MENU @@ -93,7 +93,7 @@ - Normal + Outline @@ -136,7 +136,7 @@ - Normal + Outline TR_BUTTON_BACK @@ -191,7 +191,7 @@ - Normal + Outline TR_BUTTON_START @@ -246,7 +246,7 @@ - Normal + Outline TR_SCREENNAMES_BUTTON_1PLAYER @@ -293,7 +293,7 @@ - Normal + Outline TR_SCREENNAMES_BUTTON_2PLAYER @@ -340,7 +340,7 @@ - Normal + Outline TR_SCREENNAMES_BUTTON_3PLAYER @@ -410,7 +410,7 @@ 186,00 - Normal + Outline Bold @@ -475,7 +475,7 @@ 186,00 - Normal + Outline Bold @@ -540,7 +540,7 @@ 186,00 - Normal + Outline Bold diff --git a/Output/Themes/Ambient/Screens/ScreenOptions.xml b/Output/Themes/Ambient/Screens/ScreenOptions.xml index 0099e067..9bf1033a 100644 --- a/Output/Themes/Ambient/Screens/ScreenOptions.xml +++ b/Output/Themes/Ambient/Screens/ScreenOptions.xml @@ -49,7 +49,7 @@ - Normal + Outline TR_SCREENO_OPTIONS @@ -92,7 +92,7 @@ - Normal + Outline TR_SCREENO_BUTTON_GAME @@ -147,7 +147,7 @@ - Normal + Outline TR_SCRENNO_BUTTON_SOUND @@ -202,7 +202,7 @@ - Normal + Outline TR_SCREENO_BUTTON_RECORD @@ -257,7 +257,7 @@ - Normal + Outline TR_SCREENO_BUTTON_VIDEO @@ -312,7 +312,7 @@ - Normal + Outline TR_SCREENO_BUTTON_THEME diff --git a/Output/Themes/Ambient/Screens/ScreenOptionsGame.xml b/Output/Themes/Ambient/Screens/ScreenOptionsGame.xml index 3ae21688..0054fae4 100644 --- a/Output/Themes/Ambient/Screens/ScreenOptionsGame.xml +++ b/Output/Themes/Ambient/Screens/ScreenOptionsGame.xml @@ -145,7 +145,7 @@ - Normal + Outline TR_SCREENOGAME_OPTIONS @@ -172,7 +172,7 @@ - Normal + Outline TR_SCREENOGAME_LANGUAGE @@ -199,7 +199,7 @@ - Normal + Outline TR_SCREENOGAME_DEBUGLEVEL @@ -226,7 +226,7 @@ - Normal + Outline TR_SCREENOGAME_SONGMENU @@ -253,7 +253,7 @@ - Normal + Outline TR_SCREENOGAME_SONGSORTING @@ -280,7 +280,7 @@ - Normal + Outline TR_SCREENOGAME_TABS @@ -307,7 +307,7 @@ - Normal + Outline TR_SCREENOGAME_TIMERMODE @@ -350,7 +350,7 @@ - Normal + Outline TR_BUTTON_BACK @@ -428,7 +428,7 @@ 205,33 - Normal + Outline Bold @@ -493,7 +493,7 @@ 205,33 - Normal + Outline Bold @@ -558,7 +558,7 @@ 205,33 - Normal + Outline Bold @@ -623,7 +623,7 @@ 205,33 - Normal + Outline Bold @@ -688,7 +688,7 @@ 308,00 - Normal + Outline Bold @@ -753,7 +753,7 @@ 205,33 - Normal + Outline Bold diff --git a/Output/Themes/Ambient/Screens/ScreenOptionsRecord.xml b/Output/Themes/Ambient/Screens/ScreenOptionsRecord.xml index 3fdea73b..0e43d77c 100644 --- a/Output/Themes/Ambient/Screens/ScreenOptionsRecord.xml +++ b/Output/Themes/Ambient/Screens/ScreenOptionsRecord.xml @@ -177,7 +177,7 @@ - Normal + Outline TR_SCREENORECORD_OPTIONS @@ -204,7 +204,7 @@ - Normal + Outline TR_SCREENORECORD_DEVICE @@ -231,7 +231,7 @@ - Normal + Outline TR_SCREENORECORD_INPUT @@ -258,7 +258,7 @@ - Normal + Outline TR_SCREENORECORD_CHANNEL_1 @@ -285,7 +285,7 @@ - Normal + Outline TR_SCREENORECORD_CHANNEL_2 @@ -312,7 +312,7 @@ - Normal + Outline TR_SCREENORECORD_MIC_DELAY @@ -340,7 +340,7 @@ - Normal + Outline TR_SCREENORECORD_MIC_WARNING @@ -367,7 +367,7 @@ - Normal + Outline @@ -394,7 +394,7 @@ - Normal + Outline @@ -437,7 +437,7 @@ - Normal + Outline TR_BUTTON_BACK @@ -492,7 +492,7 @@ - Normal + Outline TR_SCREENORECORD_BUTTON_DELAYTEST @@ -570,7 +570,7 @@ 616,00 - Normal + Outline Bold @@ -635,7 +635,7 @@ 616,00 - Normal + Outline Bold @@ -700,7 +700,7 @@ 154,00 - Normal + Outline Bold @@ -765,7 +765,7 @@ 154,00 - Normal + Outline Bold @@ -830,7 +830,7 @@ 123,20 - Normal + Outline Bold diff --git a/Output/Themes/Ambient/Screens/ScreenOptionsSound.xml b/Output/Themes/Ambient/Screens/ScreenOptionsSound.xml index 259915bd..35751819 100644 --- a/Output/Themes/Ambient/Screens/ScreenOptionsSound.xml +++ b/Output/Themes/Ambient/Screens/ScreenOptionsSound.xml @@ -55,7 +55,7 @@ - Normal + Outline TR_SCREENOSOUND_OPTIONS @@ -82,7 +82,7 @@ - Normal + Outline TR_SCREENOSOUND_BACKGROUNDMUSIC @@ -109,7 +109,7 @@ - Normal + Outline TR_SCREENOSOUND_BACKGROUNDMUSICVOLUME @@ -136,7 +136,7 @@ - Normal + Outline TR_SCREENOSOUND_BACKGROUNDMUSICSOURCE @@ -179,7 +179,7 @@ - Normal + Outline TR_BUTTON_BACK @@ -257,7 +257,7 @@ 205,33 - Normal + Outline Bold @@ -322,7 +322,7 @@ 205,33 - Normal + Outline Bold @@ -385,13 +385,13 @@ 32,00 - 500 + 500,00 - Normal + Outline Bold 1 - + \ No newline at end of file diff --git a/Output/Themes/Ambient/Screens/ScreenOptionsTheme.xml b/Output/Themes/Ambient/Screens/ScreenOptionsTheme.xml index 3517c5bd..ac972646 100644 --- a/Output/Themes/Ambient/Screens/ScreenOptionsTheme.xml +++ b/Output/Themes/Ambient/Screens/ScreenOptionsTheme.xml @@ -161,7 +161,7 @@ - Normal + Outline TR_SCREENOTHEME_OPTIONS @@ -188,7 +188,7 @@ - Normal + Outline TR_SCREENOTHEME_THEME @@ -215,7 +215,7 @@ - Normal + Outline TR_SCREENOTHEME_SKIN @@ -242,7 +242,7 @@ - Normal + Outline TR_SCREENOTHEME_COVERTHEME @@ -269,7 +269,7 @@ - Normal + Outline TR_SCREENOTHEME_NOTELINES @@ -296,7 +296,7 @@ - Normal + Outline TR_SCREENOTHEME_TONEHELPER @@ -323,7 +323,7 @@ - Normal + Outline TR_SCREENOTHEME_TIMERLOOK @@ -350,7 +350,7 @@ - Normal + Outline TR_SCREENOTHEME_COVERLOADING @@ -393,7 +393,7 @@ - Normal + Outline TR_BUTTON_BACK @@ -471,7 +471,7 @@ 616,00 - Normal + Outline Bold @@ -536,7 +536,7 @@ 616,00 - Normal + Outline Bold @@ -601,7 +601,7 @@ 308,00 - Normal + Outline Bold @@ -666,7 +666,7 @@ 308,00 - Normal + Outline Bold @@ -731,7 +731,7 @@ 308,00 - Normal + Outline Bold @@ -796,7 +796,7 @@ 308,00 - Normal + Outline Bold @@ -861,7 +861,7 @@ 616,00 - Normal + Outline Bold diff --git a/Output/Themes/Ambient/Screens/ScreenOptionsVideo.xml b/Output/Themes/Ambient/Screens/ScreenOptionsVideo.xml index 292cce63..c74bdfd3 100644 --- a/Output/Themes/Ambient/Screens/ScreenOptionsVideo.xml +++ b/Output/Themes/Ambient/Screens/ScreenOptionsVideo.xml @@ -97,7 +97,7 @@ - Normal + Outline TR_SCREENOVIDEO_OPTIONS @@ -124,7 +124,7 @@ - Normal + Outline TR_SCREENOVIDEO_VIDEOBACKGROUNDS @@ -151,7 +151,7 @@ - Normal + Outline TR_SCREENOVIDEO_VIDEOPREVIEW @@ -178,7 +178,7 @@ - Normal + Outline TR_SCREENOVIDEO_VIDEOINSONGS @@ -221,7 +221,7 @@ - Normal + Outline TR_BUTTON_BACK @@ -299,7 +299,7 @@ 205,33 - Normal + Outline Bold @@ -364,7 +364,7 @@ 205,33 - Normal + Outline Bold @@ -429,7 +429,7 @@ 205,33 - Normal + Outline Bold diff --git a/Output/Themes/Ambient/Screens/ScreenProfiles.xml b/Output/Themes/Ambient/Screens/ScreenProfiles.xml index 7a6c788f..6f19efb6 100644 --- a/Output/Themes/Ambient/Screens/ScreenProfiles.xml +++ b/Output/Themes/Ambient/Screens/ScreenProfiles.xml @@ -145,7 +145,7 @@ - Normal + Outline TR_SCREENPROFILES_PROFILES @@ -172,7 +172,7 @@ - Normal + Outline TR_SCREENPROFILES_PLAYERNAME @@ -199,7 +199,7 @@ - Normal + Outline TR_SCREENPROFILES_GAMEDIFFICULTY @@ -226,7 +226,7 @@ - Normal + Outline TR_SCREENPROFILES_AVATAR @@ -253,7 +253,7 @@ - Normal + Outline TR_SCREENPROFILES_GUESTPROFILE @@ -280,7 +280,7 @@ - Normal + Outline TR_SCREENPROFILES_ACTIVE @@ -323,7 +323,7 @@ - Normal + Outline @@ -370,7 +370,7 @@ - Normal + Outline TR_BUTTON_BACK @@ -425,7 +425,7 @@ - Normal + Outline TR_BUTTON_SAVE @@ -480,7 +480,7 @@ - Normal + Outline TR_SCREENPROFILES_BUTTON_NEW @@ -535,7 +535,7 @@ - Normal + Outline TR_SCREENPROFILES_BUTTON_DELETE @@ -613,7 +613,7 @@ 219,20 - Normal + Outline Bold @@ -678,7 +678,7 @@ 208,67 - Normal + Outline Bold @@ -743,7 +743,7 @@ 208,67 - Normal + Outline Bold @@ -808,7 +808,7 @@ 313,00 - Normal + Outline Bold @@ -873,7 +873,7 @@ 313,00 - Normal + Outline Bold diff --git a/Output/Themes/Ambient/Screens/ScreenScore.xml b/Output/Themes/Ambient/Screens/ScreenScore.xml index d03c560d..1673c63e 100644 --- a/Output/Themes/Ambient/Screens/ScreenScore.xml +++ b/Output/Themes/Ambient/Screens/ScreenScore.xml @@ -398,7 +398,7 @@ - Normal + Outline TR_SCREENSCORE_SCORES @@ -425,7 +425,7 @@ - Normal + Outline @@ -452,7 +452,7 @@ - Normal + Outline @@ -479,7 +479,7 @@ - Normal + Outline @@ -506,7 +506,7 @@ - Normal + Outline @@ -533,7 +533,7 @@ - Normal + Outline @@ -560,7 +560,7 @@ - Normal + Outline @@ -587,7 +587,7 @@ - Normal + Outline @@ -614,7 +614,7 @@ - Normal + Outline @@ -641,7 +641,7 @@ - Normal + Outline @@ -668,7 +668,7 @@ - Normal + Outline @@ -695,7 +695,7 @@ - Normal + Outline @@ -722,7 +722,7 @@ - Normal + Outline @@ -749,7 +749,7 @@ - Normal + Outline @@ -776,7 +776,7 @@ - Normal + Outline @@ -803,7 +803,7 @@ - Normal + Outline @@ -830,7 +830,7 @@ - Normal + Outline @@ -857,7 +857,7 @@ - Normal + Outline @@ -884,7 +884,7 @@ - Normal + Outline @@ -911,7 +911,7 @@ - Normal + Outline @@ -938,7 +938,7 @@ - Normal + Outline @@ -965,7 +965,7 @@ - Normal + Outline @@ -992,7 +992,7 @@ - Normal + Outline @@ -1019,7 +1019,7 @@ - Normal + Outline @@ -1046,7 +1046,7 @@ - Normal + Outline @@ -1073,7 +1073,7 @@ - Normal + Outline diff --git a/Output/Themes/Ambient/Screens/ScreenSing.xml b/Output/Themes/Ambient/Screens/ScreenSing.xml index 935fb419..0e206c1d 100644 --- a/Output/Themes/Ambient/Screens/ScreenSing.xml +++ b/Output/Themes/Ambient/Screens/ScreenSing.xml @@ -611,7 +611,7 @@ - Normal + Outline TR_SCREENSING_BUTTON_CANCEL @@ -666,7 +666,7 @@ - Normal + Outline TR_SCREENSING_BUTTON_CONTINUE diff --git a/Output/Themes/Ambient/Screens/ScreenSong.xml b/Output/Themes/Ambient/Screens/ScreenSong.xml index 2d0cfcfb..f693065d 100644 --- a/Output/Themes/Ambient/Screens/ScreenSong.xml +++ b/Output/Themes/Ambient/Screens/ScreenSong.xml @@ -74,7 +74,7 @@ - Normal + Outline @@ -106,7 +106,7 @@ - Normal + Outline @@ -137,7 +137,7 @@ - Normal + Outline TR_SCREENSONG_SEARCH @@ -164,7 +164,7 @@ - Normal + Outline @@ -229,7 +229,7 @@ - Normal + Outline @@ -257,7 +257,7 @@ - Normal + Outline @@ -285,7 +285,7 @@ - Normal + Outline diff --git a/Output/Themes/Ambient/Skin Blue.xml b/Output/Themes/Ambient/Skin Blue.xml index 585aff80..9de8a3f4 100644 --- a/Output/Themes/Ambient/Skin Blue.xml +++ b/Output/Themes/Ambient/Skin Blue.xml @@ -169,7 +169,7 @@ 0,000 0,000 - 0,000 + 0,600 1,000 diff --git a/Output/Themes/Ambient/Skin Green.xml b/Output/Themes/Ambient/Skin Green.xml index c1fb83b1..81bc480d 100644 --- a/Output/Themes/Ambient/Skin Green.xml +++ b/Output/Themes/Ambient/Skin Green.xml @@ -169,7 +169,7 @@ 0,000 0,000 - 0,000 + 0,600 1,000 diff --git a/Output/Themes/Ambient/Skin Red.xml b/Output/Themes/Ambient/Skin Red.xml index bf15aab2..05c4d75a 100644 --- a/Output/Themes/Ambient/Skin Red.xml +++ b/Output/Themes/Ambient/Skin Red.xml @@ -169,7 +169,7 @@ 0,000 0,000 - 0,000 + 0,600 1,000 diff --git a/Output/Themes/Ambient/Skin Yellow.xml b/Output/Themes/Ambient/Skin Yellow.xml index a72e0825..52b8a5c8 100644 --- a/Output/Themes/Ambient/Skin Yellow.xml +++ b/Output/Themes/Ambient/Skin Yellow.xml @@ -169,7 +169,7 @@ 0,000 0,000 - 0,000 + 0,600 1,000 diff --git a/Output/Themes/Changelog/Changelog_ThemeSystem.txt b/Output/Themes/Changelog/Changelog_ThemeSystem.txt index 43e7ac09..0da5e6f1 100644 --- a/Output/Themes/Changelog/Changelog_ThemeSystem.txt +++ b/Output/Themes/Changelog/Changelog_ThemeSystem.txt @@ -1,5 +1,18 @@ Theme System +++++++++++ +Version 5: + +Added: + outline thickness 0..1 + outline color red + outline color green + outline color blue + outline color alpha + +to Fonts + + ++++++++++ Version 4: diff --git a/Vocaluxe/Base/CFont.cs b/Vocaluxe/Base/CFont.cs index 9841e1dd..16eb4208 100644 --- a/Vocaluxe/Base/CFont.cs +++ b/Vocaluxe/Base/CFont.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Drawing; +using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Drawing.Text; using System.IO; @@ -38,6 +39,7 @@ namespace Vocaluxe.Base public CGlyph(char chr) { + float outline = CFonts.Outline; TextFormatFlags flags = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix; float factor = GetFactor(chr, flags); @@ -53,19 +55,53 @@ namespace Vocaluxe.Base g.Dispose(); bmp.Dispose(); - bmp = new Bitmap((int)(sizeB.Width * 1.5f), sizeB.Height); + bmp = new Bitmap((int)(sizeB.Width * 2f), sizeB.Height); g = System.Drawing.Graphics.FromImage(bmp); g.Clear(System.Drawing.Color.Transparent); + g.SmoothingMode = SmoothingMode.AntiAlias; + g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; CFonts.Height = SIZEh; fo = CFonts.GetFont(); - g.DrawString(chr.ToString(), fo, Brushes.White, new PointF((sizeB.Width - size.Width) / 2f, (sizeB.Height - size.Height - (size.Height + SIZEh/4f) * (1f - factor)) / 2f)); + + PointF point = new PointF( + outline * Math.Abs(sizeB.Width - size.Width) + (sizeB.Width - size.Width) / 2f + SIZEh / 5f, + (sizeB.Height - size.Height - (size.Height + SIZEh/4f) * (1f - factor)) / 2f); + + GraphicsPath path = new GraphicsPath(); + path.AddString( + chr.ToString(), + fo.FontFamily, + (int)fo.Style, + SIZEh, + point, + new StringFormat()); + + Pen pen = new Pen( + Color.FromArgb( + (int)CFonts.OutlineColor.A * 255, + (int)CFonts.OutlineColor.R * 255, + (int)CFonts.OutlineColor.G * 255, + (int)CFonts.OutlineColor.B * 255), + SIZEh * outline); + + pen.LineJoin = LineJoin.Round; + g.DrawPath(pen, path); + g.FillPath(Brushes.White, path); + + /* + g.DrawString( + chr.ToString(), + fo, + Brushes.White, + point); + * */ Texture = CDraw.AddTexture(bmp); - + //bmp.Save("test.png", ImageFormat.Png); Chr = chr; - width = (int)(sizeB.Width * Texture.width/factor / bmp.Width); + width = (int)((1f + outline / 2f) * sizeB.Width * Texture.width/factor / bmp.Width); bmp.Dispose(); g.Dispose(); @@ -146,7 +182,8 @@ namespace Vocaluxe.Base CFonts.Height = h; CGlyph glyph = _Glyphs[(int)_htGlyphs[chr]]; float factor = h / glyph.Texture.height; - CDraw.DrawTexture(glyph.Texture, new SRectF(x, y, glyph.Texture.width * factor, h, z), color); + float d = glyph.SIZEh / 5f * factor; + CDraw.DrawTexture(glyph.Texture, new SRectF(x - d, y, glyph.Texture.width * factor, h, z), color); } public void DrawGlyphReflection(char chr, float x, float y, float h, float z, SColorF color, float rspace, float rheight) @@ -156,7 +193,8 @@ namespace Vocaluxe.Base CFonts.Height = h; CGlyph glyph = _Glyphs[(int)_htGlyphs[chr]]; float factor = h / glyph.Texture.height; - SRectF rect = new SRectF(x, y, glyph.Texture.width * factor, h, z); + float d = glyph.SIZEh / 5f * factor; + SRectF rect = new SRectF(x - d, y, glyph.Texture.width * factor, h, z); CDraw.DrawTextureReflection(glyph.Texture, rect, color, rect, rspace, rheight); } @@ -168,8 +206,9 @@ namespace Vocaluxe.Base CGlyph glyph = _Glyphs[(int)_htGlyphs[chr]]; float factor = h / glyph.Texture.height; float width = glyph.Texture.width * factor; - - CDraw.DrawTexture(glyph.Texture, new SRectF(x, y, width, h, z), color, begin, end); + float d = glyph.SIZEh / 5f * factor; + + CDraw.DrawTexture(glyph.Texture, new SRectF(x - d, y, width, h, z), color, begin, end); } public float GetWidth(char chr) @@ -215,6 +254,9 @@ namespace Vocaluxe.Base public string FileBold; public string FileBoldItalic; + public float Outline; //0..1, 0=not outline 1=100% outline + public SColorF OutlineColor; + public CFont Normal; public CFont Italic; public CFont Bold; @@ -252,6 +294,30 @@ namespace Vocaluxe.Base } } + public static float Outline + { + get { return _Fonts[_CurrentFont].Outline; } + set + { + SFont font = _Fonts[_CurrentFont]; + font.Outline = value; + if (font.Outline < 0f) + font.Outline = 0f; + if (font.Outline > 1f) + font.Outline = 1f; + } + } + + public static SColorF OutlineColor + { + get { return _Fonts[_CurrentFont].OutlineColor; } + set + { + SFont font = _Fonts[_CurrentFont]; + font.OutlineColor = value; + } + } + public static void Init() { _settings.Indent = true; @@ -610,6 +676,15 @@ namespace Vocaluxe.Base f = new CFont(value); sf.BoldItalic = f; + sf.Outline = 0f; + CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/Outline", navigator, ref sf.Outline); + + sf.OutlineColor = new SColorF(0f, 0f, 0f, 1f); + CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorR", navigator, ref sf.OutlineColor.R); + CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorG", navigator, ref sf.OutlineColor.G); + CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorB", navigator, ref sf.OutlineColor.B); + CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorA", navigator, ref sf.OutlineColor.A); + _Fonts.Add(sf); i++; } @@ -662,6 +737,15 @@ namespace Vocaluxe.Base f = new CFont(value); sf.BoldItalic = f; + sf.Outline = 0f; + ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/Outline", navigator, ref sf.Outline); + + sf.OutlineColor = new SColorF(0f, 0f, 0f, 1f); + ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorR", navigator, ref sf.OutlineColor.R); + ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorG", navigator, ref sf.OutlineColor.G); + ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorB", navigator, ref sf.OutlineColor.B); + ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorA", navigator, ref sf.OutlineColor.A); + if (ok) _Fonts.Add(sf); else @@ -698,6 +782,13 @@ namespace Vocaluxe.Base writer.WriteElementString("Name", _Fonts[Index].Name); writer.WriteElementString("Folder", _Fonts[Index].Folder); + + writer.WriteElementString("Outline", _Fonts[Index].Outline.ToString("#0.00")); + writer.WriteElementString("ColorR", _Fonts[Index].OutlineColor.R.ToString("#0.00")); + writer.WriteElementString("ColorG", _Fonts[Index].OutlineColor.G.ToString("#0.00")); + writer.WriteElementString("ColorB", _Fonts[Index].OutlineColor.B.ToString("#0.00")); + writer.WriteElementString("ColorA", _Fonts[Index].OutlineColor.A.ToString("#0.00")); + writer.WriteElementString("FileNormal", _Fonts[Index].FileNormal); writer.WriteElementString("FileBold", _Fonts[Index].FileBold); writer.WriteElementString("FileItalic", _Fonts[Index].FileItalic); diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index d28064da..639ebdac 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -82,7 +82,7 @@ namespace Vocaluxe.Base static class CTheme { // Version number for main theme and skin files. Increment it, if you've changed something on the theme files! - const int ThemeSystemVersion = 4; + const int ThemeSystemVersion = 5; const int SkinSystemVersion = 3; #region Vars diff --git a/Vocaluxe/Menu/CLyric.cs b/Vocaluxe/Menu/CLyric.cs index 8a70e0ab..15cd5d2b 100644 --- a/Vocaluxe/Menu/CLyric.cs +++ b/Vocaluxe/Menu/CLyric.cs @@ -142,7 +142,7 @@ namespace Vocaluxe.Menu { _Theme.Name = ElementName; LoadTextures(); - _Text = new CText(_X, _Y, _Z, _H, _MaxW, EAlignment.Left, EStyle.Bold, "Normal", Color, String.Empty); + _Text = new CText(_X, _Y, _Z, _H, _MaxW, EAlignment.Left, EStyle.Bold, "Outline", Color, String.Empty); } return _ThemeLoaded; } diff --git a/Vocaluxe/Menu/CText.cs b/Vocaluxe/Menu/CText.cs index 770a40f3..c0c95948 100644 --- a/Vocaluxe/Menu/CText.cs +++ b/Vocaluxe/Menu/CText.cs @@ -423,6 +423,9 @@ namespace Vocaluxe.Menu CurrentColor = new SColorF(SColor); SColorF color = new SColorF(CurrentColor.R, CurrentColor.G, CurrentColor.B, CurrentColor.A * Alpha); + + CFonts.SetFont(Fon); + CFonts.Style = Style; CFonts.DrawText(CLanguage.Translate(Text), h, x, y, Z, color); if (Reflection) @@ -461,6 +464,9 @@ namespace Vocaluxe.Menu CurrentColor = new SColorF(SColor); SColorF color = new SColorF(CurrentColor.R, CurrentColor.G, CurrentColor.B, CurrentColor.A * Alpha); + + CFonts.SetFont(Fon); + CFonts.Style = Style; CFonts.DrawText(Text, Height, x, Y, Z, color, begin, end); if (Reflection) @@ -520,6 +526,9 @@ namespace Vocaluxe.Menu CurrentColor = new SColorF(SColor); SColorF color = new SColorF(CurrentColor.R, CurrentColor.G, CurrentColor.B, CurrentColor.A * Alpha); + + CFonts.SetFont(Fon); + CFonts.Style = Style; CFonts.DrawText(CLanguage.Translate(Text), h, x, y, Z, color); if (reflection) From df04153d4bba32c7393c7ccfab0bd3e1a5818d32 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Mon, 12 Mar 2012 21:11:26 +0100 Subject: [PATCH 04/38] removed outline font from lyrics (perhaps later with another font) --- Output/Themes/Ambient/Skin Blue.xml | 2 +- Output/Themes/Ambient/Skin Green.xml | 2 +- Output/Themes/Ambient/Skin Red.xml | 2 +- Output/Themes/Ambient/Skin Yellow.xml | 2 +- Vocaluxe/Menu/CLyric.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Output/Themes/Ambient/Skin Blue.xml b/Output/Themes/Ambient/Skin Blue.xml index 9de8a3f4..585aff80 100644 --- a/Output/Themes/Ambient/Skin Blue.xml +++ b/Output/Themes/Ambient/Skin Blue.xml @@ -169,7 +169,7 @@ 0,000 0,000 - 0,600 + 0,000 1,000 diff --git a/Output/Themes/Ambient/Skin Green.xml b/Output/Themes/Ambient/Skin Green.xml index 81bc480d..c1fb83b1 100644 --- a/Output/Themes/Ambient/Skin Green.xml +++ b/Output/Themes/Ambient/Skin Green.xml @@ -169,7 +169,7 @@ 0,000 0,000 - 0,600 + 0,000 1,000 diff --git a/Output/Themes/Ambient/Skin Red.xml b/Output/Themes/Ambient/Skin Red.xml index 05c4d75a..bf15aab2 100644 --- a/Output/Themes/Ambient/Skin Red.xml +++ b/Output/Themes/Ambient/Skin Red.xml @@ -169,7 +169,7 @@ 0,000 0,000 - 0,600 + 0,000 1,000 diff --git a/Output/Themes/Ambient/Skin Yellow.xml b/Output/Themes/Ambient/Skin Yellow.xml index 52b8a5c8..a72e0825 100644 --- a/Output/Themes/Ambient/Skin Yellow.xml +++ b/Output/Themes/Ambient/Skin Yellow.xml @@ -169,7 +169,7 @@ 0,000 0,000 - 0,600 + 0,000 1,000 diff --git a/Vocaluxe/Menu/CLyric.cs b/Vocaluxe/Menu/CLyric.cs index 15cd5d2b..8a70e0ab 100644 --- a/Vocaluxe/Menu/CLyric.cs +++ b/Vocaluxe/Menu/CLyric.cs @@ -142,7 +142,7 @@ namespace Vocaluxe.Menu { _Theme.Name = ElementName; LoadTextures(); - _Text = new CText(_X, _Y, _Z, _H, _MaxW, EAlignment.Left, EStyle.Bold, "Outline", Color, String.Empty); + _Text = new CText(_X, _Y, _Z, _H, _MaxW, EAlignment.Left, EStyle.Bold, "Normal", Color, String.Empty); } return _ThemeLoaded; } From 89aa513ed7ecf1547b0990d5a35a769913105d9b Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Mon, 12 Mar 2012 21:13:07 +0100 Subject: [PATCH 05/38] higher outline to outline font --- Output/Fonts/Fonts.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Output/Fonts/Fonts.xml b/Output/Fonts/Fonts.xml index 5d499a59..70524adf 100644 --- a/Output/Fonts/Fonts.xml +++ b/Output/Fonts/Fonts.xml @@ -15,7 +15,7 @@ Outline - 0,08 + 0,10 0,00 0,00 0,00 From 0ea6a9043bc7fc7c184c6e703d19293b49a718e3 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Wed, 14 Mar 2012 19:55:59 +0100 Subject: [PATCH 06/38] use transactions when adding covers to db (thx to rayo) --- Vocaluxe/Base/CDataBase.cs | 51 ++++++--- Vocaluxe/Base/CDraw.cs | 185 +++++++++----------------------- Vocaluxe/Base/CSongs.cs | 37 +++---- Vocaluxe/Menu/CGraphics.cs | 2 +- Vocaluxe/Program.cs | 1 + Vocaluxe/Screens/CScreenLoad.cs | 2 +- 6 files changed, 106 insertions(+), 172 deletions(-) diff --git a/Vocaluxe/Base/CDataBase.cs b/Vocaluxe/Base/CDataBase.cs index 15c6f6f2..daa25460 100644 --- a/Vocaluxe/Base/CDataBase.cs +++ b/Vocaluxe/Base/CDataBase.cs @@ -29,6 +29,9 @@ namespace Vocaluxe.Base private static string _CoverFilePath; private static string _CreditsRessourcesFilePath; + private static SQLiteConnection _ConnectionCover = null; + private static SQLiteTransaction _TransactionCover = null; + public static void Init() { _HighscoreFilePath = Path.Combine(System.Environment.CurrentDirectory, CSettings.sFileHighscoreDB); @@ -959,18 +962,15 @@ namespace Vocaluxe.Base return false; } - SQLiteConnection connection = new SQLiteConnection(); - connection.ConnectionString = "Data Source=" + _CoverFilePath; + if (_ConnectionCover == null) + { + _ConnectionCover = new SQLiteConnection(); + _ConnectionCover.ConnectionString = "Data Source=" + _CoverFilePath; + _ConnectionCover.Open(); + } + SQLiteCommand command; - try - { - connection.Open(); - } - catch (Exception) - { - return false; - } - command = new SQLiteCommand(connection); + command = new SQLiteCommand(_ConnectionCover); command.CommandText = "SELECT id, width, height FROM Cover WHERE [Path] = @path"; command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = CoverPath; @@ -1016,6 +1016,11 @@ namespace Vocaluxe.Base if (reader != null) reader.Close(); + if (_TransactionCover == null) + { + _TransactionCover = _ConnectionCover.BeginTransaction(); + } + Bitmap origin; try { @@ -1032,8 +1037,6 @@ namespace Vocaluxe.Base reader.Dispose(); } command.Dispose(); - connection.Close(); - connection.Dispose(); return false; } @@ -1094,12 +1097,30 @@ namespace Vocaluxe.Base reader.Dispose(); } command.Dispose(); - connection.Close(); - connection.Dispose(); return result; } + public static void CommitCovers() + { + if (_TransactionCover != null) + { + _TransactionCover.Commit(); + _TransactionCover = null; + } + } + + public static void CloseConnections() + { + CommitCovers(); + + if (_ConnectionCover != null) + { + _ConnectionCover.Close(); + _ConnectionCover = null; + } + } + private static bool InitCoverDB() { SQLiteConnection connection = new SQLiteConnection(); diff --git a/Vocaluxe/Base/CDraw.cs b/Vocaluxe/Base/CDraw.cs index 3a62415b..6c0e0684 100644 --- a/Vocaluxe/Base/CDraw.cs +++ b/Vocaluxe/Base/CDraw.cs @@ -12,8 +12,6 @@ namespace Vocaluxe.Base { static class CDraw { - private static Object mutex = new object(); - private static IDraw _Draw = null; public static void InitDraw() @@ -50,259 +48,172 @@ namespace Vocaluxe.Base public static int GetScreenWidth() { - lock (mutex) - { - return _Draw.GetScreenWidth(); - } + return _Draw.GetScreenWidth(); } public static int GetScreenHeight() { - lock (mutex) - { - return _Draw.GetScreenHeight(); - } + return _Draw.GetScreenHeight(); } public static RectangleF GetTextBounds(CText text) { - lock (mutex) - { - return _Draw.GetTextBounds(text); - } + return _Draw.GetTextBounds(text); } public static RectangleF GetTextBounds(CText text, float Height) { - lock (mutex) - { - return _Draw.GetTextBounds(text, Height); - } + return _Draw.GetTextBounds(text, Height); } public static void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2) { - lock (mutex) - { - _Draw.DrawLine(a, r, g, b, w, x1, y1, x2, y2); - } + _Draw.DrawLine(a, r, g, b, w, x1, y1, x2, y2); } public static void DrawRect(SColorF Color, SRectF Rect, float Thickness) { - lock (mutex) - { - if (Thickness <= 0f) - return; + if (Thickness <= 0f) + return; - _Draw.DrawColor(Color, new SRectF(Rect.X - Thickness / 2, Rect.Y - Thickness / 2, Rect.W + Thickness, Thickness, Rect.Z)); - _Draw.DrawColor(Color, new SRectF(Rect.X - Thickness / 2, Rect.Y + Rect.H - Thickness / 2, Rect.W + Thickness, Thickness, Rect.Z)); - _Draw.DrawColor(Color, new SRectF(Rect.X - Thickness / 2, Rect.Y - Thickness / 2, Thickness, Rect.H + Thickness, Rect.Z)); - _Draw.DrawColor(Color, new SRectF(Rect.X + Rect.W - Thickness / 2, Rect.Y - Thickness / 2, Thickness, Rect.H + Thickness, Rect.Z)); - } + _Draw.DrawColor(Color, new SRectF(Rect.X - Thickness / 2, Rect.Y - Thickness / 2, Rect.W + Thickness, Thickness, Rect.Z)); + _Draw.DrawColor(Color, new SRectF(Rect.X - Thickness / 2, Rect.Y + Rect.H - Thickness / 2, Rect.W + Thickness, Thickness, Rect.Z)); + _Draw.DrawColor(Color, new SRectF(Rect.X - Thickness / 2, Rect.Y - Thickness / 2, Thickness, Rect.H + Thickness, Rect.Z)); + _Draw.DrawColor(Color, new SRectF(Rect.X + Rect.W - Thickness / 2, Rect.Y - Thickness / 2, Thickness, Rect.H + Thickness, Rect.Z)); } public static void DrawColor(SColorF color, SRectF rect) { - lock (mutex) - { - _Draw.DrawColor(color, rect); - } + _Draw.DrawColor(color, rect); } public static void ClearScreen() { - lock (mutex) - { - _Draw.ClearScreen(); - } + _Draw.ClearScreen(); } public static STexture CopyScreen() { - lock (mutex) - { - return _Draw.CopyScreen(); - } + return _Draw.CopyScreen(); } public static void CopyScreen(ref STexture Texture) { - lock (mutex) - { - _Draw.CopyScreen(ref Texture); - } + _Draw.CopyScreen(ref Texture); } public static void MakeScreenShot() { - lock (mutex) - { - _Draw.MakeScreenShot(); - } + _Draw.MakeScreenShot(); } // Draw Basic Text (must be deleted later) public static void DrawText(string Text, int x, int y, int h) { - lock (mutex) - { - _Draw.DrawText(Text, x, y, h); - } + _Draw.DrawText(Text, x, y, h); } public static STexture AddTexture(Bitmap Bitmap) { - lock (mutex) - { - return _Draw.AddTexture(Bitmap); - } + return _Draw.AddTexture(Bitmap); } public static STexture AddTexture(string TexturePath) { - lock (mutex) - { - return _Draw.AddTexture(TexturePath); - } + return _Draw.AddTexture(TexturePath); } public static STexture AddTexture(string TexturePath, int MaxSize) { - lock (mutex) - { - if (MaxSize == 0) - return _Draw.AddTexture(TexturePath); + if (MaxSize == 0) + return _Draw.AddTexture(TexturePath); - if (!System.IO.File.Exists(TexturePath)) - return new STexture(-1); + if (!System.IO.File.Exists(TexturePath)) + return new STexture(-1); - Bitmap origin = new Bitmap(TexturePath); - int w = MaxSize; - int h = MaxSize; + Bitmap origin = new Bitmap(TexturePath); + int w = MaxSize; + int h = MaxSize; - if (origin.Width >= origin.Height && origin.Width > w) - h = (int)Math.Round((float)w / origin.Width * origin.Height); - else if (origin.Height > origin.Width && origin.Height > h) - w = (int)Math.Round((float)h / origin.Height * origin.Width); + if (origin.Width >= origin.Height && origin.Width > w) + h = (int)Math.Round((float)w / origin.Width * origin.Height); + else if (origin.Height > origin.Width && origin.Height > h) + w = (int)Math.Round((float)h / origin.Height * origin.Width); - Bitmap bmp = new Bitmap(origin, w, h); - STexture tex = _Draw.AddTexture(bmp); - bmp.Dispose(); - return tex; - } + Bitmap bmp = new Bitmap(origin, w, h); + STexture tex = _Draw.AddTexture(bmp); + bmp.Dispose(); + return tex; } public static STexture AddTexture(int W, int H, IntPtr Data) { - lock (mutex) - { - return _Draw.AddTexture(W, H, Data); - } + return _Draw.AddTexture(W, H, Data); } public static STexture AddTexture(int W, int H, ref byte[] Data) { - lock (mutex) - { - return _Draw.AddTexture(W, H, ref Data); - } + return _Draw.AddTexture(W, H, ref Data); } public static bool UpdateTexture(ref STexture Texture, ref byte[] Data) { - lock (mutex) - { - return _Draw.UpdateTexture(ref Texture, ref Data); - } + return _Draw.UpdateTexture(ref Texture, ref Data); } public static bool UpdateTexture(ref STexture Texture, IntPtr Data) { - lock (mutex) - { - return _Draw.UpdateTexture(ref Texture, Data); - } + return _Draw.UpdateTexture(ref Texture, Data); } public static void RemoveTexture(ref STexture Texture) { - lock (mutex) - { - _Draw.RemoveTexture(ref Texture); - } + _Draw.RemoveTexture(ref Texture); } public static void DrawTexture(STexture Texture) { - lock (mutex) - { - _Draw.DrawTexture(Texture); - } + _Draw.DrawTexture(Texture); } public static void DrawTexture(STexture Texture, SRectF rect) { - lock (mutex) - { - _Draw.DrawTexture(Texture, rect); - } + _Draw.DrawTexture(Texture, rect); } public static void DrawTexture(STexture Texture, SRectF rect, SColorF color) { - lock (mutex) - { - _Draw.DrawTexture(Texture, rect, color); - } + _Draw.DrawTexture(Texture, rect, color); } public static void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds) { - lock (mutex) - { - _Draw.DrawTexture(Texture, rect, color, bounds); - } + _Draw.DrawTexture(Texture, rect, color, bounds); } public static void DrawTexture(STexture Texture, SRectF rect, SColorF color,bool mirrored) { - lock (mutex) - { - _Draw.DrawTexture(Texture, rect, color, mirrored); - } + _Draw.DrawTexture(Texture, rect, color, mirrored); } public static void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored) { - lock (mutex) - { - _Draw.DrawTexture(Texture, rect, color, bounds, mirrored); - } + _Draw.DrawTexture(Texture, rect, color, bounds, mirrored); } public static void DrawTexture(STexture Texture, SRectF rect, SColorF color, float begin, float end) { - lock (mutex) - { - _Draw.DrawTexture(Texture, rect, color, begin, end); - } + _Draw.DrawTexture(Texture, rect, color, begin, end); } public static void DrawTextureReflection(STexture Texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) { - lock (mutex) - { - _Draw.DrawTextureReflection(Texture, rect, color, bounds, space, height); - } + _Draw.DrawTextureReflection(Texture, rect, color, bounds, space, height); } public static int TextureCount() { - lock (mutex) - { - return _Draw.TextureCount(); - } + return _Draw.TextureCount(); } } diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index 778197f0..c9d4d71d 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -829,7 +829,7 @@ namespace Vocaluxe.Base CLog.StopBenchmark(1, "Load Songs "); } - public static void LoadCover(long WaitTime) + public static void LoadCover(long WaitTime, int NumLoads) { if (!SongsLoaded) return; @@ -846,25 +846,26 @@ namespace Vocaluxe.Base STexture texture = new STexture(-1); if (_CoverLoadTimer.ElapsedMilliseconds >= WaitTime) { - CSong song = new CSong(); - int i = GetNextSongWithoutCover(ref song); - - if (i < 0) - return; - - song.ReadNotes(); - if (song.CoverFileName != String.Empty) + for (int i = 0; i < NumLoads; i++) { - if (!CDataBase.GetCover(Path.Combine(song.Folder, song.CoverFileName), ref texture, CConfig.CoverSize)) - texture = CCover.NoCover; - } - else - texture = CCover.NoCover; - SetCoverSmall(i, texture); - SetCoverBig(i, texture); + CSong song = new CSong(); + int n = GetNextSongWithoutCover(ref song); - _CoverLoadTimer.Reset(); - _CoverLoadTimer.Start(); + if (n < 0) + return; + + song.ReadNotes(); + texture = song.CoverTextureSmall; + + SetCoverSmall(n, texture); + SetCoverBig(n, texture); + + if (CoverLoaded) + CDataBase.CommitCovers(); + + _CoverLoadTimer.Reset(); + _CoverLoadTimer.Start(); + } } } } diff --git a/Vocaluxe/Menu/CGraphics.cs b/Vocaluxe/Menu/CGraphics.cs index a47dd769..d924c584 100644 --- a/Vocaluxe/Menu/CGraphics.cs +++ b/Vocaluxe/Menu/CGraphics.cs @@ -317,7 +317,7 @@ namespace Vocaluxe.Menu CBackgroundMusic.Update(); if (CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_DYNAMIC && ActualScreen != EScreens.ScreenSing) - CSongs.LoadCover(30L); + CSongs.LoadCover(30L, 1); if (CSettings.GameState != EGameState.EditTheme) { diff --git a/Vocaluxe/Program.cs b/Vocaluxe/Program.cs index b5f3228e..854b4d8d 100644 --- a/Vocaluxe/Program.cs +++ b/Vocaluxe/Program.cs @@ -152,6 +152,7 @@ namespace Vocaluxe CVideo.VdCloseAll(); CDraw.Unload(); CLog.CloseAll(); + CDataBase.CloseConnections(); } static Assembly AssemblyResolver(Object sender, ResolveEventArgs args) diff --git a/Vocaluxe/Screens/CScreenLoad.cs b/Vocaluxe/Screens/CScreenLoad.cs index 1ffa133c..9d3f92c2 100644 --- a/Vocaluxe/Screens/CScreenLoad.cs +++ b/Vocaluxe/Screens/CScreenLoad.cs @@ -153,7 +153,7 @@ namespace Vocaluxe.Screens if (CSongs.SongsLoaded && CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART && _timer.ElapsedMilliseconds > 1000L) { - CSongs.LoadCover(20L); + CSongs.LoadCover(0L, 1); } bool next = ((CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART && CSongs.CoverLoaded) || From a78b61bbe796e6532bc03b68740221b8f144ee02 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Wed, 14 Mar 2012 19:56:22 +0100 Subject: [PATCH 07/38] use display lists in opengl --- Vocaluxe/Lib/Draw/COpenGL.cs | 412 +++++++++++++++++++---------------- 1 file changed, 224 insertions(+), 188 deletions(-) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 9644122f..0552995e 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -40,13 +40,14 @@ namespace Vocaluxe.Lib.Draw private bool _fullscreen = false; private List _Textures; + private List _GLList; private int h = 1; private int w = 1; private int y = 0; private int x = 0; - private bool _UsePBO = false; + private bool _UsePBO = true; #endregion private vars @@ -55,6 +56,7 @@ namespace Vocaluxe.Lib.Draw this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon)); _Textures = new List(); + _GLList = new List(); //Check AA Mode CConfig.AAMode = (EAntiAliasingModes)CheckAntiAliasingMode((int)CConfig.AAMode); @@ -440,6 +442,12 @@ namespace Vocaluxe.Lib.Draw ClearScreen(); _Run = _Run && CGraphics.Draw(); + foreach (int list in _GLList) + { + GL.CallList(list); + } + _GLList.Clear(); + _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); control.SwapBuffers(); @@ -595,17 +603,24 @@ namespace Vocaluxe.Lib.Draw public void DrawColor(SColorF color, SRectF rect) { - GL.Enable(EnableCap.Blend); - GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); + int list = GL.GenLists(1); + _GLList.Add(list); - GL.Begin(BeginMode.Quads); - GL.Vertex3(rect.X, rect.Y, rect.Z + CGraphics.ZOffset); - GL.Vertex3(rect.X, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); - GL.Vertex3(rect.X + rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); - GL.Vertex3(rect.X + rect.W, rect.Y, rect.Z + CGraphics.ZOffset); - GL.End(); + GL.NewList(list, ListMode.Compile); + { + GL.Enable(EnableCap.Blend); + GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); - GL.Disable(EnableCap.Blend); + GL.Begin(BeginMode.Quads); + GL.Vertex3(rect.X, rect.Y, rect.Z + CGraphics.ZOffset); + GL.Vertex3(rect.X, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); + GL.Vertex3(rect.X + rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); + GL.Vertex3(rect.X + rect.W, rect.Y, rect.Z + CGraphics.ZOffset); + GL.End(); + + GL.Disable(EnableCap.Blend); + } + GL.EndList(); } #endregion Basic Draw Methods @@ -1031,97 +1046,104 @@ namespace Vocaluxe.Lib.Draw if (_TextureExists(Texture)) { - GL.BindTexture(TextureTarget.Texture2D, Texture.index); - - float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; - float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; - float y1 = (bounds.Y - rect.Y) / rect.H * Texture.height_ratio; - float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; + int list = GL.GenLists(1); + _GLList.Add(list); - if (x1 < 0) - x1 = 0f; - - if (x2 > Texture.width_ratio) - x2 = Texture.width_ratio; - - if (y1 < 0) - y1 = 0f; - - if (y2 > Texture.height_ratio) - y2 = Texture.height_ratio; - - - float rx1 = rect.X; - float rx2 = rect.X + rect.W; - float ry1 = rect.Y; - float ry2 = rect.Y + rect.H; - - if (rx1 < bounds.X) - rx1 = bounds.X; - - if (rx2 > bounds.X + bounds.W) - rx2 = bounds.X + bounds.W; - - if (ry1 < bounds.Y) - ry1 = bounds.Y; - - if (ry2 > bounds.Y + bounds.H) - ry2 = bounds.Y + bounds.H; - - GL.Enable(EnableCap.Blend); - GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); - - GL.MatrixMode(MatrixMode.Texture); - GL.PushMatrix(); - - if (rect.Rotation != 0f) + GL.NewList(list, ListMode.Compile); { - GL.Translate(0.5f, 0.5f, 0); - GL.Rotate(-rect.Rotation, 0f, 0f, 1f); - GL.Translate(-0.5f, -0.5f, 0); + GL.BindTexture(TextureTarget.Texture2D, Texture.index); + + float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; + float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; + float y1 = (bounds.Y - rect.Y) / rect.H * Texture.height_ratio; + float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; + + if (x1 < 0) + x1 = 0f; + + if (x2 > Texture.width_ratio) + x2 = Texture.width_ratio; + + if (y1 < 0) + y1 = 0f; + + if (y2 > Texture.height_ratio) + y2 = Texture.height_ratio; + + + float rx1 = rect.X; + float rx2 = rect.X + rect.W; + float ry1 = rect.Y; + float ry2 = rect.Y + rect.H; + + if (rx1 < bounds.X) + rx1 = bounds.X; + + if (rx2 > bounds.X + bounds.W) + rx2 = bounds.X + bounds.W; + + if (ry1 < bounds.Y) + ry1 = bounds.Y; + + if (ry2 > bounds.Y + bounds.H) + ry2 = bounds.Y + bounds.H; + + GL.Enable(EnableCap.Blend); + GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); + + GL.MatrixMode(MatrixMode.Texture); + GL.PushMatrix(); + + if (rect.Rotation != 0f) + { + GL.Translate(0.5f, 0.5f, 0); + GL.Rotate(-rect.Rotation, 0f, 0f, 1f); + GL.Translate(-0.5f, -0.5f, 0); + } + + if (!mirrored) + { + GL.Begin(BeginMode.Quads); + + GL.TexCoord2(x1, y1); + GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset); + + GL.TexCoord2(x1, y2); + GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset); + + GL.TexCoord2(x2, y2); + GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset); + + GL.TexCoord2(x2, y1); + GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset); + + GL.End(); + } + else + { + GL.Begin(BeginMode.Quads); + + GL.TexCoord2(x2, y2); + GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset); + + GL.TexCoord2(x2, y1); + GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset); + + GL.TexCoord2(x1, y1); + GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset); + + GL.TexCoord2(x1, y2); + GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset); + + GL.End(); + } + + GL.PopMatrix(); + + GL.Disable(EnableCap.Blend); + GL.BindTexture(TextureTarget.Texture2D, 0); } - - if (!mirrored) - { - GL.Begin(BeginMode.Quads); - - GL.TexCoord2(x1, y1); - GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset); - - GL.TexCoord2(x1, y2); - GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset); - - GL.TexCoord2(x2, y2); - GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset); - - GL.TexCoord2(x2, y1); - GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset); - - GL.End(); - } - else - { - GL.Begin(BeginMode.Quads); - - GL.TexCoord2(x2, y2); - GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset); - - GL.TexCoord2(x2, y1); - GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset); - - GL.TexCoord2(x1, y1); - GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset); - - GL.TexCoord2(x1, y2); - GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset); - - GL.End(); - } - - GL.PopMatrix(); - - GL.Disable(EnableCap.Blend); - GL.BindTexture(TextureTarget.Texture2D, 0); + GL.EndList(); } } @@ -1129,31 +1151,38 @@ namespace Vocaluxe.Lib.Draw { if (_TextureExists(Texture)) { - GL.BindTexture(TextureTarget.Texture2D, Texture.index); - - GL.Enable(EnableCap.Blend); - GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); + int list = GL.GenLists(1); + _GLList.Add(list); - - GL.Begin(BeginMode.Quads); + GL.NewList(list, ListMode.Compile); + { + GL.BindTexture(TextureTarget.Texture2D, Texture.index); - GL.TexCoord2(0f + begin * Texture.width_ratio, 0f); - GL.Vertex3(rect.X + begin * rect.W, rect.Y, rect.Z + CGraphics.ZOffset); + GL.Enable(EnableCap.Blend); + GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); - GL.TexCoord2(0f + begin * Texture.width_ratio, Texture.height_ratio); - GL.Vertex3(rect.X + begin * rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); - GL.TexCoord2(Texture.width_ratio * end, Texture.height_ratio); - GL.Vertex3(rect.X + end * rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); + GL.Begin(BeginMode.Quads); - GL.TexCoord2(Texture.width_ratio * end, 0f); - GL.Vertex3(rect.X + end * rect.W, rect.Y, rect.Z + CGraphics.ZOffset); + GL.TexCoord2(0f + begin * Texture.width_ratio, 0f); + GL.Vertex3(rect.X + begin * rect.W, rect.Y, rect.Z + CGraphics.ZOffset); - GL.End(); - + GL.TexCoord2(0f + begin * Texture.width_ratio, Texture.height_ratio); + GL.Vertex3(rect.X + begin * rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); - GL.Disable(EnableCap.Blend); - GL.BindTexture(TextureTarget.Texture2D, 0); + GL.TexCoord2(Texture.width_ratio * end, Texture.height_ratio); + GL.Vertex3(rect.X + end * rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); + + GL.TexCoord2(Texture.width_ratio * end, 0f); + GL.Vertex3(rect.X + end * rect.W, rect.Y, rect.Z + CGraphics.ZOffset); + + GL.End(); + + + GL.Disable(EnableCap.Blend); + GL.BindTexture(TextureTarget.Texture2D, 0); + } + GL.EndList(); } } @@ -1173,81 +1202,88 @@ namespace Vocaluxe.Lib.Draw if (_TextureExists(Texture)) { - GL.BindTexture(TextureTarget.Texture2D, Texture.index); + int list = GL.GenLists(1); + _GLList.Add(list); - float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; - float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; - float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * Texture.height_ratio; - float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; - - if (x1 < 0) - x1 = 0f; - - if (x2 > Texture.width_ratio) - x2 = Texture.width_ratio; - - if (y1 < 0) - y1 = 0f; - - if (y2 > Texture.height_ratio) - y2 = Texture.height_ratio; - - - float rx1 = rect.X; - float rx2 = rect.X + rect.W; - float ry1 = rect.Y + rect.H + space; - float ry2 = rect.Y + rect.H + space + height; - - if (rx1 < bounds.X) - rx1 = bounds.X; - - if (rx2 > bounds.X + bounds.W) - rx2 = bounds.X + bounds.W; - - if (ry1 < bounds.Y + space) - ry1 = bounds.Y + space; - - if (ry2 > bounds.Y + bounds.H + space + height) - ry2 = bounds.Y + bounds.H + space + height; - - GL.Enable(EnableCap.Blend); - - GL.MatrixMode(MatrixMode.Texture); - GL.PushMatrix(); - - if (rect.Rotation != 0f) + GL.NewList(list, ListMode.Compile); { - GL.Translate(0.5f, 0.5f, 0); - GL.Rotate(-rect.Rotation, 0f, 0f, 1f); - GL.Translate(-0.5f, -0.5f, 0); + GL.BindTexture(TextureTarget.Texture2D, Texture.index); + + float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; + float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; + float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * Texture.height_ratio; + float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; + + if (x1 < 0) + x1 = 0f; + + if (x2 > Texture.width_ratio) + x2 = Texture.width_ratio; + + if (y1 < 0) + y1 = 0f; + + if (y2 > Texture.height_ratio) + y2 = Texture.height_ratio; + + + float rx1 = rect.X; + float rx2 = rect.X + rect.W; + float ry1 = rect.Y + rect.H + space; + float ry2 = rect.Y + rect.H + space + height; + + if (rx1 < bounds.X) + rx1 = bounds.X; + + if (rx2 > bounds.X + bounds.W) + rx2 = bounds.X + bounds.W; + + if (ry1 < bounds.Y + space) + ry1 = bounds.Y + space; + + if (ry2 > bounds.Y + bounds.H + space + height) + ry2 = bounds.Y + bounds.H + space + height; + + GL.Enable(EnableCap.Blend); + + GL.MatrixMode(MatrixMode.Texture); + GL.PushMatrix(); + + if (rect.Rotation != 0f) + { + GL.Translate(0.5f, 0.5f, 0); + GL.Rotate(-rect.Rotation, 0f, 0f, 1f); + GL.Translate(-0.5f, -0.5f, 0); + } + + + GL.Begin(BeginMode.Quads); + + GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); + GL.TexCoord2(x2, y2); + GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset); + + GL.Color4(color.R, color.G, color.B, 0f); + GL.TexCoord2(x2, y1); + GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset); + + GL.Color4(color.R, color.G, color.B, 0f); + GL.TexCoord2(x1, y1); + GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset); + + GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); + GL.TexCoord2(x1, y2); + GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset); + + GL.End(); + + + GL.PopMatrix(); + + GL.Disable(EnableCap.Blend); + GL.BindTexture(TextureTarget.Texture2D, 0); } - - - GL.Begin(BeginMode.Quads); - - GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); - GL.TexCoord2(x2, y2); - GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset); - - GL.Color4(color.R, color.G, color.B, 0f); - GL.TexCoord2(x2, y1); - GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset); - - GL.Color4(color.R, color.G, color.B, 0f); - GL.TexCoord2(x1, y1); - GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset); - - GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); - GL.TexCoord2(x1, y2); - GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset); - - GL.End(); - - - GL.PopMatrix(); - - GL.Disable(EnableCap.Blend); - GL.BindTexture(TextureTarget.Texture2D, 0); + GL.EndList(); } } From 0d9033d21e78d454d38aa682ba3311b2f34bf2c6 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Wed, 14 Mar 2012 22:26:20 +0100 Subject: [PATCH 08/38] use data queque when loading cover --- Vocaluxe/Base/CDataBase.cs | 6 +- Vocaluxe/Base/CDraw.cs | 5 + Vocaluxe/Base/CFont.cs | 2 +- Vocaluxe/Base/CSongs.cs | 21 +++ Vocaluxe/Lib/Draw/CDirect3D.cs | 5 + Vocaluxe/Lib/Draw/CDrawWinForm.cs | 5 + Vocaluxe/Lib/Draw/COpenGL.cs | 228 +++++++++++++++++++++++++----- Vocaluxe/Lib/Draw/IDraw.cs | 7 +- Vocaluxe/Screens/CScreenLoad.cs | 2 + 9 files changed, 237 insertions(+), 44 deletions(-) diff --git a/Vocaluxe/Base/CDataBase.cs b/Vocaluxe/Base/CDataBase.cs index daa25460..e1040bf8 100644 --- a/Vocaluxe/Base/CDataBase.cs +++ b/Vocaluxe/Base/CDataBase.cs @@ -1008,7 +1008,7 @@ namespace Vocaluxe.Base result = true; reader.Read(); byte[] data = GetBytes(reader); - tex = CDraw.AddTexture(w, h, ref data); + tex = CDraw.QuequeTexture(w, h, ref data); } } else @@ -1053,7 +1053,7 @@ namespace Vocaluxe.Base Graphics g = Graphics.FromImage(bmp); g.DrawImage(origin, new Rectangle(0, 0, w, h)); g.Dispose(); - tex = CDraw.AddTexture(bmp); + byte[] data = new byte[w * h * 4]; BitmapData bmp_data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); @@ -1061,6 +1061,8 @@ namespace Vocaluxe.Base bmp.UnlockBits(bmp_data); bmp.Dispose(); + tex = CDraw.QuequeTexture(w, h, ref data); + command.CommandText = "INSERT INTO Cover (Path, width, height) " + "VALUES (@path, " + w.ToString() + ", " + h.ToString() + ")"; command.Parameters.Add("@path", System.Data.DbType.String, 0).Value = CoverPath; diff --git a/Vocaluxe/Base/CDraw.cs b/Vocaluxe/Base/CDraw.cs index 6c0e0684..7c13e322 100644 --- a/Vocaluxe/Base/CDraw.cs +++ b/Vocaluxe/Base/CDraw.cs @@ -156,6 +156,11 @@ namespace Vocaluxe.Base return _Draw.AddTexture(W, H, ref Data); } + public static STexture QuequeTexture(int W, int H, ref byte[] Data) + { + return _Draw.QuequeTexture(W, H, ref Data); + } + public static bool UpdateTexture(ref STexture Texture, ref byte[] Data) { return _Draw.UpdateTexture(ref Texture, ref Data); diff --git a/Vocaluxe/Base/CFont.cs b/Vocaluxe/Base/CFont.cs index 16eb4208..fbf5d97a 100644 --- a/Vocaluxe/Base/CFont.cs +++ b/Vocaluxe/Base/CFont.cs @@ -133,7 +133,7 @@ namespace Vocaluxe.Base sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags); //size = g.MeasureString(chr.ToString(), fo); float h_style = sizeB.Height; - + g.Dispose(); return h_normal / h_style; } } diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index c9d4d71d..67a55e83 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -826,11 +826,32 @@ namespace Vocaluxe.Base CLog.StopBenchmark(2, "Sort Songs"); Category = -1; _SongsLoaded = true; + + if (CConfig.Renderer == ERenderer.TR_CONFIG_OPENGL) + { + CLog.StartBenchmark(2, "Load Cover"); + for (int i = 0; i < _Songs.Count; i++) + { + CSong song = _Songs[i]; + + song.ReadNotes(); + STexture texture = song.CoverTextureSmall; + song.CoverTextureBig = texture; + _CoverLoadIndex++; + } + + _CoverLoaded = true; + CDataBase.CommitCovers(); + CLog.StopBenchmark(2, "Load Cover"); + } CLog.StopBenchmark(1, "Load Songs "); } public static void LoadCover(long WaitTime, int NumLoads) { + if (CConfig.Renderer == ERenderer.TR_CONFIG_OPENGL) + return; //should be removed as soon as the other renderer are ready for queque + if (!SongsLoaded) return; diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 851b3028..d4e7e1f3 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -625,6 +625,11 @@ namespace Vocaluxe.Lib.Draw return AddTexture(W, H , ref PointerData); } + public STexture QuequeTexture(int W, int H, ref byte[] Data) + { + return AddTexture(W, H, ref Data); + } + public STexture AddTexture(int W, int H, ref byte[] Data) { STexture texture = new STexture(-1); diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index 254763d9..702fcc57 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -400,6 +400,11 @@ namespace Vocaluxe.Lib.Draw return new STexture(-1); } + public STexture QuequeTexture(int W, int H, ref byte[] Data) + { + return AddTexture(W, H, ref Data); + } + public STexture AddTexture(int W, int H, ref byte[] Data) { Bitmap bmp = new Bitmap(W, H); diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 0552995e..ae42fcb7 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -18,14 +18,21 @@ using Vocaluxe.Menu; namespace Vocaluxe.Lib.Draw { - public struct SClientRect + struct SClientRect { public Point location; public int width; public int height; }; - + struct STextureQueque + { + public int ID; + public int width; + public int height; + public byte[] data; + } + class COpenGL : Form, IDraw { #region private vars @@ -40,14 +47,18 @@ namespace Vocaluxe.Lib.Draw private bool _fullscreen = false; private List _Textures; + private List _IDs; private List _GLList; + private List _Queque; + + private Object MutexTexture = new Object(); private int h = 1; private int w = 1; private int y = 0; private int x = 0; - private bool _UsePBO = true; + private bool _UsePBO = false; #endregion private vars @@ -57,6 +68,13 @@ namespace Vocaluxe.Lib.Draw _Textures = new List(); _GLList = new List(); + _Queque = new List(); + _IDs = new List(); + + for (int i = 1; i < 1000000; i++) + { + _IDs.Add(i); + } //Check AA Mode CConfig.AAMode = (EAntiAliasingModes)CheckAntiAliasingMode((int)CConfig.AAMode); @@ -454,6 +472,8 @@ namespace Vocaluxe.Lib.Draw if ((CSettings.bFullScreen && !_fullscreen) || (!CSettings.bFullScreen && _fullscreen)) ToggleFullScreen(); + CheckQueque(); + if (CTime.IsRunning()) delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds()); @@ -513,7 +533,7 @@ namespace Vocaluxe.Lib.Draw int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); - texture.index = id; + texture.ID = id; texture.width = w; texture.height = h; @@ -537,21 +557,27 @@ namespace Vocaluxe.Lib.Draw // Add to Texture List texture.color = new SColorF(1f, 1f, 1f, 1f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); - _Textures.Add(texture); + + lock (MutexTexture) + { + texture.index = _IDs[0]; + _IDs.RemoveAt(0); + _Textures.Add(texture); + } return texture; } public void CopyScreen(ref STexture Texture) { - if (!_TextureExists(Texture) || (Texture.width != GetScreenWidth()) || (Texture.height != GetScreenHeight())) + if (!_TextureExists(ref Texture) || (Texture.width != GetScreenWidth()) || (Texture.height != GetScreenHeight())) { RemoveTexture(ref Texture); Texture = CopyScreen(); } else { - GL.BindTexture(TextureTarget.Texture2D, Texture.index); + GL.BindTexture(TextureTarget.Texture2D, Texture.ID); GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, (int)Texture.width, (int)Texture.height); @@ -658,10 +684,6 @@ namespace Vocaluxe.Lib.Draw if (bmp.Height == 0 || bmp.Width == 0) return texture; - int id = GL.GenTexture(); - GL.BindTexture(TextureTarget.Texture2D, id); - texture.index = id; - int MaxSize; switch (CConfig.TextureQuality) { @@ -700,6 +722,10 @@ namespace Vocaluxe.Lib.Draw h = MaxSize; } + int id = GL.GenTexture(); + GL.BindTexture(TextureTarget.Texture2D, id); + texture.ID = id; + texture.width = w; texture.height = h; @@ -711,7 +737,8 @@ namespace Vocaluxe.Lib.Draw g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height)); - + g.Dispose(); + texture.width_ratio = 1f; texture.height_ratio = 1f; @@ -742,6 +769,12 @@ namespace Vocaluxe.Lib.Draw texture.color = new SColorF(1f, 1f, 1f, 1f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.TexturePath = String.Empty; + + lock (MutexTexture) + { + texture.index = _IDs[0]; + _IDs.RemoveAt(0); + } _Textures.Add(texture); return texture; @@ -768,7 +801,7 @@ namespace Vocaluxe.Lib.Draw int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); - texture.index = id; + texture.ID = id; texture.width = W; texture.height = H; @@ -801,6 +834,12 @@ namespace Vocaluxe.Lib.Draw texture.color = new SColorF(1f, 1f, 1f, 1f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.TexturePath = String.Empty; + + lock (MutexTexture) + { + texture.index = _IDs[0]; + _IDs.RemoveAt(0); + } _Textures.Add(texture); return texture; @@ -828,7 +867,7 @@ namespace Vocaluxe.Lib.Draw int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); - texture.index = id; + texture.ID = id; texture.width = W; texture.height = H; @@ -861,14 +900,41 @@ namespace Vocaluxe.Lib.Draw texture.color = new SColorF(1f, 1f, 1f, 1f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.TexturePath = String.Empty; + + lock (MutexTexture) + { + texture.index = _IDs[0]; + _IDs.RemoveAt(0); + } _Textures.Add(texture); return texture; } + public STexture QuequeTexture(int W, int H, ref byte[] Data) + { + STexture texture = new STexture(-1); + STextureQueque queque = new STextureQueque(); + + queque.data = Data; + queque.height = H; + queque.width = W; + + lock (MutexTexture) + { + texture.index = _IDs[0]; + _IDs.RemoveAt(0); + queque.ID = texture.index; + _Queque.Add(queque); + _Textures.Add(texture); + } + + return texture; + } + public bool UpdateTexture(ref STexture Texture, IntPtr Data) { - if (_TextureExists(Texture)) + if (_TextureExists(ref Texture)) { if (_UsePBO) { @@ -884,7 +950,7 @@ namespace Vocaluxe.Lib.Draw GL.UnmapBuffer(BufferTarget.PixelUnpackBuffer); - GL.BindTexture(TextureTarget.Texture2D, Texture.index); + GL.BindTexture(TextureTarget.Texture2D, Texture.ID); GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)Texture.width, (int)Texture.height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); @@ -899,7 +965,7 @@ namespace Vocaluxe.Lib.Draw } } - GL.BindTexture(TextureTarget.Texture2D, Texture.index); + GL.BindTexture(TextureTarget.Texture2D, Texture.ID); GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)Texture.width, (int)Texture.height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, Data); @@ -923,7 +989,7 @@ namespace Vocaluxe.Lib.Draw public bool UpdateTexture(ref STexture Texture, ref byte[] Data) { - if (_TextureExists(Texture)) + if (_TextureExists(ref Texture)) { if (_UsePBO) { @@ -936,7 +1002,7 @@ namespace Vocaluxe.Lib.Draw GL.UnmapBuffer(BufferTarget.PixelUnpackBuffer); - GL.BindTexture(TextureTarget.Texture2D, Texture.index); + GL.BindTexture(TextureTarget.Texture2D, Texture.ID); GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)Texture.width, (int)Texture.height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); @@ -952,7 +1018,7 @@ namespace Vocaluxe.Lib.Draw } } - GL.BindTexture(TextureTarget.Texture2D, Texture.index); + GL.BindTexture(TextureTarget.Texture2D, Texture.ID); GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)Texture.width, (int)Texture.height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, Data); @@ -978,30 +1044,41 @@ namespace Vocaluxe.Lib.Draw { if ((Texture.index > 0) && (_Textures.Count > 0)) { - for (int i = 0; i < _Textures.Count; i++) - { - if (_Textures[i].index == Texture.index) + lock (MutexTexture) + { + for (int i = 0; i < _Textures.Count; i++) { - GL.DeleteTexture(Texture.index); - if (Texture.PBO > 0) - GL.DeleteBuffers(1, ref Texture.PBO); - _Textures.RemoveAt(i); - Texture.index = -1; - break; + if (_Textures[i].index == Texture.index) + { + _IDs.Add(Texture.index); + + GL.DeleteTexture(Texture.ID); + if (Texture.PBO > 0) + GL.DeleteBuffers(1, ref Texture.PBO); + _Textures.RemoveAt(i); + Texture.index = -1; + Texture.ID = -1; + break; + } } } } } - private bool _TextureExists(STexture Texture) + private bool _TextureExists(ref STexture Texture) { - if ((Texture.index > 0) && (_Textures.Count > 0)) + lock (MutexTexture) { for (int i = 0; i < _Textures.Count; i++) { - if (_Textures[i].index == Texture.index) + if (Texture.index == _Textures[i].index) { - return true; + if (_Textures[i].ID > 0) + { + Texture = _Textures[i]; + return true; + } + break; } } } @@ -1044,14 +1121,14 @@ namespace Vocaluxe.Lib.Draw if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y) return; - if (_TextureExists(Texture)) + if (_TextureExists(ref Texture)) { int list = GL.GenLists(1); _GLList.Add(list); GL.NewList(list, ListMode.Compile); { - GL.BindTexture(TextureTarget.Texture2D, Texture.index); + GL.BindTexture(TextureTarget.Texture2D, Texture.ID); float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; @@ -1149,14 +1226,14 @@ namespace Vocaluxe.Lib.Draw public void DrawTexture(STexture Texture, SRectF rect, SColorF color, float begin, float end) { - if (_TextureExists(Texture)) + if (_TextureExists(ref Texture)) { int list = GL.GenLists(1); _GLList.Add(list); GL.NewList(list, ListMode.Compile); { - GL.BindTexture(TextureTarget.Texture2D, Texture.index); + GL.BindTexture(TextureTarget.Texture2D, Texture.ID); GL.Enable(EnableCap.Blend); GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); @@ -1200,14 +1277,14 @@ namespace Vocaluxe.Lib.Draw if (height > bounds.H) height = bounds.H; - if (_TextureExists(Texture)) + if (_TextureExists(ref Texture)) { int list = GL.GenLists(1); _GLList.Add(list); GL.NewList(list, ListMode.Compile); { - GL.BindTexture(TextureTarget.Texture2D, Texture.index); + GL.BindTexture(TextureTarget.Texture2D, Texture.ID); float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; @@ -1291,6 +1368,79 @@ namespace Vocaluxe.Lib.Draw { return _Textures.Count; } + + private void CheckQueque() + { + lock (MutexTexture) + { + if (_Queque.Count == 0) + return; + + STextureQueque q = _Queque[0]; + STexture texture = new STexture(-1); + int index = -1; + for (int i = 0; i < _Textures.Count; i++) + { + if (_Textures[i].index == q.ID) + { + texture = _Textures[i]; + index = i; + break; + } + } + + if (texture.index < 1) + return; + + if (_UsePBO) + { + try + { + GL.GenBuffers(1, out texture.PBO); + GL.BindBuffer(BufferTarget.PixelUnpackBuffer, texture.PBO); + GL.BufferData(BufferTarget.PixelUnpackBuffer, (IntPtr)q.data.Length, IntPtr.Zero, BufferUsageHint.StreamDraw); + GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0); + } + catch (Exception) + { + //throw; + _UsePBO = false; + } + } + + int id = GL.GenTexture(); + GL.BindTexture(TextureTarget.Texture2D, id); + texture.ID = id; + + texture.width = q.width; + texture.height = q.height; + texture.w2 = (float)MathHelper.NextPowerOfTwo(texture.width); + texture.h2 = (float)MathHelper.NextPowerOfTwo(texture.height); + + texture.width_ratio = texture.width / texture.w2; + texture.height_ratio = texture.height / texture.h2; + + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, (int)texture.w2, (int)texture.h2, 0, + OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); + + GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, q.width, q.height, + OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, q.data); + + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); + + GL.BindTexture(TextureTarget.Texture2D, 0); + + // Add to Texture List + texture.color = new SColorF(1f, 1f, 1f, 1f); + texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); + texture.TexturePath = String.Empty; + + _Textures[index] = texture; + _Queque.RemoveAt(0); + } + } + #endregion Textures #endregion implementation diff --git a/Vocaluxe/Lib/Draw/IDraw.cs b/Vocaluxe/Lib/Draw/IDraw.cs index 5a2a5c09..2f8bbc82 100644 --- a/Vocaluxe/Lib/Draw/IDraw.cs +++ b/Vocaluxe/Lib/Draw/IDraw.cs @@ -67,6 +67,7 @@ namespace Vocaluxe.Lib.Draw { public int index; public int PBO; + public int ID; public string TexturePath; @@ -85,10 +86,11 @@ namespace Vocaluxe.Lib.Draw { index = Index; PBO = 0; + ID = -1; TexturePath = String.Empty; - width = 0f; - height = 0f; + width = 1f; + height = 1f; rect = new SRectF(0f, 0f, 1f, 1f, 0f); w2 = 2f; @@ -136,6 +138,7 @@ namespace Vocaluxe.Lib.Draw STexture AddTexture(Bitmap Bitmap); STexture AddTexture(int W, int H, IntPtr Data); STexture AddTexture(int W, int H, ref byte[] Data); + STexture QuequeTexture(int W, int H, ref byte[] Data); bool UpdateTexture(ref STexture Texture, ref byte[] Data); bool UpdateTexture(ref STexture Texture, IntPtr Data); diff --git a/Vocaluxe/Screens/CScreenLoad.cs b/Vocaluxe/Screens/CScreenLoad.cs index 9d3f92c2..924a1094 100644 --- a/Vocaluxe/Screens/CScreenLoad.cs +++ b/Vocaluxe/Screens/CScreenLoad.cs @@ -135,6 +135,7 @@ namespace Vocaluxe.Screens } CLog.StartBenchmark(3, "Load Cover"); + _SongLoaderThread.IsBackground = true; _SongLoaderThread.Start(); _timer.Start(); @@ -306,6 +307,7 @@ namespace Vocaluxe.Screens _Finished = CVideo.VdFinished(_VideoStream); STexture tex = new STexture(-1); + tex.height = 0f; CVideo.VdGetFrame(_VideoStream, ref tex, VideoTime, ref VideoTime); if (tex.height > 0) From 10e996c96cb99227e59a390d0cb0940608a68fe1 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Thu, 15 Mar 2012 07:33:09 +0100 Subject: [PATCH 09/38] fixed memory leak in COpenGL.cs --- Vocaluxe/Lib/Draw/COpenGL.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index ae42fcb7..5564610d 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -464,6 +464,9 @@ namespace Vocaluxe.Lib.Draw { GL.CallList(list); } + if (_GLList.Count > 0) + GL.DeleteLists(_GLList[0], _GLList.Count); + _GLList.Clear(); _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); @@ -1437,6 +1440,7 @@ namespace Vocaluxe.Lib.Draw texture.TexturePath = String.Empty; _Textures[index] = texture; + q.data = null; _Queque.RemoveAt(0); } } From fd8cba535264c85e78a28834ee5e840b46ff733e Mon Sep 17 00:00:00 2001 From: bohning Date: Thu, 15 Mar 2012 09:09:44 +0200 Subject: [PATCH 10/38] Fixed some typos --- README | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README b/README index 071051a3..ee39f054 100644 --- a/README +++ b/README @@ -28,9 +28,9 @@ Supported Operating Systems / Requirements: ================================= = 2. Download = ================================= -You can donwloadn precompiles Windows binaries at SourceForge: +You can download precompiled Windows binaries at SourceForge: -Download: http://sourceforge.net/projects/vocaluxe/ +http://sourceforge.net/projects/vocaluxe/ ================================= @@ -38,7 +38,7 @@ Download: http://sourceforge.net/projects/vocaluxe/ ================================= The development of Vocaluxe uses this git branching model: - http://nvie.com/posts/a-successful-git-branching-model/ +http://nvie.com/posts/a-successful-git-branching-model/ ================================= From 704a7cffe24a25979d625ee324a0dc897d48fd31 Mon Sep 17 00:00:00 2001 From: bohning Date: Thu, 15 Mar 2012 15:09:44 +0800 Subject: [PATCH 11/38] Fixed some typos --- README | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README b/README index 071051a3..ee39f054 100644 --- a/README +++ b/README @@ -28,9 +28,9 @@ Supported Operating Systems / Requirements: ================================= = 2. Download = ================================= -You can donwloadn precompiles Windows binaries at SourceForge: +You can download precompiled Windows binaries at SourceForge: -Download: http://sourceforge.net/projects/vocaluxe/ +http://sourceforge.net/projects/vocaluxe/ ================================= @@ -38,7 +38,7 @@ Download: http://sourceforge.net/projects/vocaluxe/ ================================= The development of Vocaluxe uses this git branching model: - http://nvie.com/posts/a-successful-git-branching-model/ +http://nvie.com/posts/a-successful-git-branching-model/ ================================= From fee141321b512df6a0a61134f36cbb6ea2c908a0 Mon Sep 17 00:00:00 2001 From: Florian Kuepper Date: Tue, 13 Mar 2012 19:27:08 +0800 Subject: [PATCH 12/38] Added text to credits-screen. --- Vocaluxe/Screens/CScreenCredits.cs | 86 ++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 5 deletions(-) diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index 278b4720..ba8f1fec 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -41,6 +41,10 @@ namespace Vocaluxe.Screens private Stopwatch LogoTimer; private Stopwatch CreditsTimer; + private Stopwatch TextTimer; + + private List paragraphs; + private List paragraphTexts; public CScreenCredits() { @@ -56,6 +60,26 @@ namespace Vocaluxe.Screens LogoTimer = new Stopwatch(); CreditsTimer = new Stopwatch(); + TextTimer = new Stopwatch(); + + //Text for last part of credits. + paragraphTexts = new List(); + paragraphs = new List(); + string paragraph = "Inspired by the achievements of UltraStar Deluxe and its variants and pursuing the goal of making a good thing even better, we ended up rewriting the game from scratch. And a new implementation in a new programming language called for a new name - and VOCALUXE it is!"; + string[] words = paragraph.Split(new Char[] { ' ' }); + paragraphs.Add(words); + + paragraph = "This first public version has already implemented many of the original features and it is fully compatible with all the song files in your existing song collection. The code design allows a much faster implementation of new features, thus the roadmap for the next few stable releases is packed and we expect much shorter release cycles than ever before. And, of course, our and your ideas may be the features of tomorrow."; + words = paragraph.Split(new Char[] { ' ' }); + paragraphs.Add(words); + + paragraph = "We appreciate the feedback in the beta release phase and are, of course, always open for bug reports, suggestions for improve- ments and ideas for new features. We would also like to thank the translators who make Vocaluxe an international experience from the very beginning. Last, but most definitely not least, we thank all those diligent song makers out there - there's a song for everyone!"; + words = paragraph.Split(new Char[] { ' ' }); + paragraphs.Add(words); + + paragraph = "Go ahead and grab your mics, crank up your stereo, warm up your voice and get ready to sing to the best of your abilities!"; + words = paragraph.Split(new Char[] { ' ' }); + paragraphs.Add(words); } public override bool HandleInput(KeyEvent KeyEvent) @@ -210,9 +234,39 @@ namespace Vocaluxe.Screens CreditEntryPinky007.direction = EDirection.Right; _CreditNames.Add(CreditEntryPinky007); + //Prepare Text + int lastY = 280; + for (int i = 0; i < paragraphs.Count; i++) + { + string line = ""; + for (int e = 0; e < paragraphs[i].Length; e++ ) + { + if (paragraphs[i][e] != null) + { + string newline = line + " " + paragraphs[i][e]; + CText text = new CText(75, lastY, -2, 30, -1, EAlignment.Left, EStyle.Bold, "Outline", new SColorF(1, 1, 1, 1), line); + if (CDraw.GetTextBounds(text).Width < (CSettings.iRenderW - 160)) + { + line = line + " " + paragraphs[i][e]; - //CreditEntry.image = new CStatic(tex, new SColorF(1, 1, 1, 1), new SRectF(0, 0, 350, 110, -4)); - + //Check if all words are used + if ((e + 1) == paragraphs[i].Length) + { + text.Text = line; + paragraphTexts.Add(text); + line = ""; + lastY += 40; + } + } + else + { + paragraphTexts.Add(text); + line = " "+paragraphs[i][e]; + lastY += 27; + } + } + } + } } public override void OnShowFinish() @@ -247,6 +301,15 @@ namespace Vocaluxe.Screens _CreditNames[i].particle.Draw(); } } + + //Draw Text + if (TextTimer.IsRunning) + { + for (int i = 0; i < paragraphTexts.Count; i++) + { + paragraphTexts[i].Draw(); + } + } return true; } @@ -347,12 +410,13 @@ namespace Vocaluxe.Screens //Check, if last name is set to false if (i == _CreditNames.Count - 1) { - //Will later fade to Main-Screen - active = false; - //Stop and reset timer for next time CreditsTimer.Stop(); CreditsTimer.Reset(); + + //Start Text-Timer + TextTimer.Start(); + active = true; } } break; @@ -361,6 +425,18 @@ namespace Vocaluxe.Screens } } + if (TextTimer.IsRunning) + { + if (TextTimer.ElapsedMilliseconds > 10000) + { + active = false; + } + else + { + active = true; + } + } + return active; } } From 7075e29e0ea821bcc2a196a51511b5391231c95c Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Thu, 15 Mar 2012 19:12:48 +0100 Subject: [PATCH 13/38] call all display lists at once --- Vocaluxe/Lib/Draw/COpenGL.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 5564610d..1492f0c0 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -460,10 +460,9 @@ namespace Vocaluxe.Lib.Draw ClearScreen(); _Run = _Run && CGraphics.Draw(); - foreach (int list in _GLList) - { - GL.CallList(list); - } + + GL.CallLists(_GLList.Count, ListNameType.Int, _GLList.ToArray()); + if (_GLList.Count > 0) GL.DeleteLists(_GLList[0], _GLList.Count); From f08e72bd70d723b5130e953d5f92fa67cff01acc Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Fri, 16 Mar 2012 12:48:34 +0100 Subject: [PATCH 14/38] Added threaded cover loading to CDirect3D.cs --- Vocaluxe/Base/CSongs.cs | 4 +- Vocaluxe/Lib/Draw/CDirect3D.cs | 945 ++++++++++++++++++++++++--------- 2 files changed, 699 insertions(+), 250 deletions(-) diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index 67a55e83..a6242d39 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -827,7 +827,7 @@ namespace Vocaluxe.Base Category = -1; _SongsLoaded = true; - if (CConfig.Renderer == ERenderer.TR_CONFIG_OPENGL) + if (CConfig.Renderer != ERenderer.TR_CONFIG_SOFTWARE) { CLog.StartBenchmark(2, "Load Cover"); for (int i = 0; i < _Songs.Count; i++) @@ -849,7 +849,7 @@ namespace Vocaluxe.Base public static void LoadCover(long WaitTime, int NumLoads) { - if (CConfig.Renderer == ERenderer.TR_CONFIG_OPENGL) + if (CConfig.Renderer != ERenderer.TR_CONFIG_SOFTWARE) return; //should be removed as soon as the other renderer are ready for queque if (!SongsLoaded) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index d4e7e1f3..65a9444f 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -36,6 +36,9 @@ namespace Vocaluxe.Lib.Draw private List _Textures; private List _D3DTextures; + private List _Queque; + + private Object MutexTexture = new Object(); private VertexBuffer _VertexBuffer; @@ -46,14 +49,20 @@ namespace Vocaluxe.Lib.Draw private Bitmap blankMap; private STexture blankTexture; + private Texture transparentTexture; #endregion private vars + /// + /// Creates a new Instance of the CDirect3D Class + /// public CDirect3D() { this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon)); _Textures = new List(); _D3DTextures = new List(); + _Queque = new List(); + _Keys = new CKeys(); _D3D = new Direct3D(); @@ -86,6 +95,8 @@ namespace Vocaluxe.Lib.Draw _PresentParameters.Multisample = MultisampleType.None; _PresentParameters.MultisampleQuality = 0; + //Apply antialiasing and check if antialiasing mode is supported + #region Antialiasing int quality = 0; if (CConfig.AAMode == EAntiAliasingModes.x0) { @@ -132,12 +143,15 @@ namespace Vocaluxe.Lib.Draw else CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA"); } + #endregion Antialiasing - if(CConfig.VSync == EOffOn.TR_CONFIG_ON) + //Apply the VSync configuration + if (CConfig.VSync == EOffOn.TR_CONFIG_ON) _PresentParameters.PresentationInterval = PresentInterval.Default; else _PresentParameters.PresentationInterval = PresentInterval.Immediate; - + + //GMA 950 graphics devices can only process vertices in software mode Capabilities caps = _D3D.GetDeviceCaps(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware); CreateFlags flags = CreateFlags.None; if ((caps.DeviceCaps & DeviceCaps.HWTransformAndLight) != 0) @@ -147,14 +161,16 @@ namespace Vocaluxe.Lib.Draw _Device = new Device(_D3D, _D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, Handle, flags, _PresentParameters); this.CenterToScreen(); - - blankMap = new Bitmap(1, 1); //Quick and Dirty, used for DrawColor + + //This creates a new white texture and adds it to the texture pool + //This texture is used for the DrawRect method + blankMap = new Bitmap(1, 1); Graphics g = Graphics.FromImage(blankMap); g.Clear(Color.White); g.Dispose(); blankTexture = AddTexture(blankMap); - h = ClientSize.Height; - w = ClientSize.Width; + + transparentTexture = new Texture(_Device, 1, 1, 0, Usage.None, Format.A8R8G8B8, Pool.Managed); blankMap.Dispose(); } @@ -186,9 +202,12 @@ namespace Vocaluxe.Lib.Draw RResize(); } #endregion form events - + /// + /// Resizes the viewport + /// private void RResize() { + // The window was minimized, so restore it to the last known size if (ClientSize.Width == 0 || ClientSize.Height == 0) { ClientSize = _SizeBeforeMinimize; @@ -202,28 +221,41 @@ namespace Vocaluxe.Lib.Draw if ((float)w / (float)h > CSettings.GetRenderAspect()) { + //The windows's width is too big w = (int)Math.Round((float)h * CSettings.GetRenderAspect()); x = (ClientSize.Width - w) / 2; } else { + //The windows's height is too big h = (int)Math.Round((float)w / CSettings.GetRenderAspect()); y = (ClientSize.Height - h) / 2; } + //Apply the new sizes to the PresentParameters _PresentParameters.BackBufferWidth = ClientSize.Width; _PresentParameters.BackBufferHeight = ClientSize.Height; ClearScreen(); + //To set new PresentParameters the device has to be resetted Reset(); + //All configurations got flushed due to Reset(), so apply them again Init(); + //Set the new Viewport _Device.Viewport = new Viewport(x, y, w, h); + //Store size so it can get restored after the window gets minimized _SizeBeforeMinimize = ClientSize; } } + /// + /// Triggers the Fullscreen mode + /// private void EnterFullScreen() { + //This currently not using real fullscreen mode but a borderless window + //Real fullscreen could be gained setting _PresentParameters.Windowed = true + //And calling Reset() and Init() after _OldSize = this.ClientSize; this.ClientSize = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); this.FormBorderStyle = FormBorderStyle.None; @@ -237,7 +269,9 @@ namespace Vocaluxe.Lib.Draw CConfig.SaveConfig(); } - + /// + /// Triggers the windowed mode + /// private void LeaveFullScreen() { this.ClientSize = _OldSize; @@ -312,34 +346,45 @@ namespace Vocaluxe.Lib.Draw #region implementation + /// + /// Inits the Device + /// + /// True if it succeeded else false public bool Init() { - this.Text = CSettings.GetFullVersionText(); - Matrix translate = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); - Matrix projection = Matrix.OrthoOffCenterLH(-CSettings.iRenderW / 2, CSettings.iRenderW / 2, -CSettings.iRenderH / 2, CSettings.iRenderH / 2, CSettings.zNear, CSettings.zFar); - _VertexBuffer = new VertexBuffer(_Device, 4 * Marshal.SizeOf(typeof(TexturedColoredVertex)), Usage.WriteOnly | Usage.Dynamic, VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Diffuse, Pool.Default); - _Device.SetStreamSource(0, _VertexBuffer, 0, Marshal.SizeOf(typeof(TexturedColoredVertex))); - _Device.VertexDeclaration = TexturedColoredVertex.GetDeclaration(_Device); - _Device.SetTransform(TransformState.Projection, projection); - _Device.SetTransform(TransformState.World, translate); - _Device.SetRenderState(RenderState.CullMode, Cull.None); - _Device.SetRenderState(RenderState.AlphaBlendEnable, true); - _Device.SetRenderState(RenderState.Lighting, false); - _Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha); - _Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha); - if(_PresentParameters.Multisample != MultisampleType.None) - _Device.SetRenderState(RenderState.MultisampleAntialias, true); - _Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear); - _Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear); - _Device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear); - _Device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Clamp); - _Device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Clamp); - _Device.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.Texture); - _Device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.Diffuse); - _Device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate); - return true; + if (!_Device.Disposed) + { + this.Text = CSettings.GetFullVersionText(); + Matrix translate = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); + Matrix projection = Matrix.OrthoOffCenterLH(-CSettings.iRenderW / 2, CSettings.iRenderW / 2, -CSettings.iRenderH / 2, CSettings.iRenderH / 2, CSettings.zNear, CSettings.zFar); + _VertexBuffer = new VertexBuffer(_Device, 4 * Marshal.SizeOf(typeof(TexturedColoredVertex)), Usage.WriteOnly | Usage.Dynamic, VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Diffuse, Pool.Default); + _Device.SetStreamSource(0, _VertexBuffer, 0, Marshal.SizeOf(typeof(TexturedColoredVertex))); + _Device.VertexDeclaration = TexturedColoredVertex.GetDeclaration(_Device); + _Device.SetTransform(TransformState.Projection, projection); + _Device.SetTransform(TransformState.World, translate); + _Device.SetRenderState(RenderState.CullMode, Cull.None); + _Device.SetRenderState(RenderState.AlphaBlendEnable, true); + _Device.SetRenderState(RenderState.Lighting, false); + _Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha); + _Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha); + if (_PresentParameters.Multisample != MultisampleType.None) + _Device.SetRenderState(RenderState.MultisampleAntialias, true); + _Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear); + _Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear); + _Device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear); + _Device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Clamp); + _Device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Clamp); + _Device.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.Texture); + _Device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.Diffuse); + _Device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate); + return true; + } + else + return false; } - + /// + /// Starts the rendering + /// public void MainLoop() { _Run = true; @@ -358,36 +403,46 @@ namespace Vocaluxe.Lib.Draw if (_Run) { + //Clear the previous Frame ClearScreen(); + //We want to begin drawing _Device.BeginScene(); + CheckQueque(); _Run = _Run && CGraphics.Draw(); - _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); + //We finished drawing the frame _Device.EndScene(); + _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); try { + //Now push the frame to the Viewport _Device.Present(); } catch (Direct3D9Exception) { - if (_Device.TestCooperativeLevel() == ResultCode.DeviceNotReset) //Do only reset when the device in a resetable state! + //In Direct3D devices can get lost. + //This happens for example when opening the Task Manager in Vista/Windows 7 or if a UAC message is opening + //We need to reset the device to get it to workable state again + //After a reset Init() needs to be called because all data in the Direct3D default pool are lost and need to be recreated + if (_Device.TestCooperativeLevel() == ResultCode.DeviceNotReset) { Reset(); Init(); } } + //Apply fullscreen mode if ((CSettings.bFullScreen && !_fullscreen) || (!CSettings.bFullScreen && _fullscreen)) { if (!_fullscreen) EnterFullScreen(); else - LeaveFullScreen(); + LeaveFullScreen(); } if (CTime.IsRunning()) delay = (int)Math.Floor(CConfig.CalcCycleTime() - CTime.GetMilliseconds()); if (delay >= 1) System.Threading.Thread.Sleep(delay); - + //Calculate the FPS Rate and restart the timer after a frame CTime.CalculateFPS(); CTime.Restart(); } @@ -396,19 +451,27 @@ namespace Vocaluxe.Lib.Draw } } + /// + /// Resets the device, all objects in the Direct3D default pool get flushed and need to be recreated + /// public void Reset() { + //Dispose all objects in the default pool, those need to be recreated TexturedColoredVertex.GetDeclaration(_Device).Dispose(); _VertexBuffer.Dispose(); _Device.Reset(_PresentParameters); } + /// + /// Unloads all Textures and other objects used by Direct3D for rendering + /// + /// public bool Unload() { + //Dispose all textures for (int i = 0; i < _D3DTextures.Count; i++) { _D3DTextures[i].Dispose(); - } TexturedColoredVertex.GetDeclaration(_Device).Dispose(); _VertexBuffer.Dispose(); @@ -417,21 +480,40 @@ namespace Vocaluxe.Lib.Draw return true; } + /// + /// Gets the current viewport width + /// + /// The current viewport width public int GetScreenWidth() { return _Device.Viewport.Width; } + /// + /// Gets the current viewport height + /// + /// The current viewport height public int GetScreenHeight() { return _Device.Viewport.Height; } + /// + /// Calculates the bounds for a CText object + /// + /// The CText object of which the bounds should be calculated for + /// RectangleF object containing the bounds public RectangleF GetTextBounds(CText text) { return GetTextBounds(text, text.Height); } + /// + /// Calculates the bounds for a CText object + /// + /// The CText object of which the bounds should be calculated for + /// The height of the CText object + /// RectangleF object containing the bounds public RectangleF GetTextBounds(CText text, float Height) { CFonts.Height = Height; @@ -442,30 +524,48 @@ namespace Vocaluxe.Lib.Draw #region Basic Draw Methods + /// + /// Removes all textures from the screen + /// public void ClearScreen() { _Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); } + + /// + /// Not implemented yet + /// + /// public STexture CopyScreen() { + //FIXME STexture texture = new STexture(-1); return texture; } + /// + /// Not implemented yet + /// + /// public void CopyScreen(ref STexture Texture) { + //FIXME return; } + /// + /// Creates a Screenshot of the current frame + /// public void MakeScreenShot() { string file = "Screenshot_"; string path = Path.Combine(Environment.CurrentDirectory, CSettings.sFolderScreenshots); - + int i = 0; while (File.Exists(Path.Combine(path, file + i.ToString("00000") + ".bmp"))) i++; + //create a surface of the frame using (Surface surface = _Device.GetBackBuffer(0, 0)) { Bitmap screen = new Bitmap(Surface.ToStream(surface, ImageFileFormat.Bmp)); @@ -476,29 +576,74 @@ namespace Vocaluxe.Lib.Draw _Mouse.Visible = true; } + /// + /// Draws a line + /// + /// The alpha value from 0-255 + /// The red value from 0-255 + /// The red value from 0-255 + /// The red value from 0-255 + /// The width of the line + /// The start x-value + /// The start y-value + /// The end x-value + /// The end y-value public void DrawLine(int a, int r, int g, int b, int w, int x1, int y1, int x2, int y2) { SColorF color = new SColorF(a / 255, g / 255, b / 255, a / 255); DrawTexture(blankTexture, new SRectF(x1, y1, x2, y2, 1), color); } + /// + /// Draws a text string + /// + /// The text to be drawn + /// The text's x-position + /// The text's y-position + /// The text's height public void DrawText(string Text, int x, int y, int h) { DrawText(Text, x, y, h, 0f); } + /// + /// Draws a text string + /// + /// The text to be drawn + /// The text's x-position + /// The text's y-position + /// The text's height + /// The text's x-position public void DrawText(string Text, int x, int y, float h, float z) { CFonts.DrawText(Text, h, x, y, z, new SColorF(1f, 1f, 1f, 1f)); } + /// + /// Draws a colored rectangle + /// + /// The color in which the rectangle will be drawn in + /// The coordinates in a SRectF struct public void DrawColor(SColorF color, SRectF rect) { + //blankMap = new Bitmap(1, 1); + //Graphics g = Graphics.FromImage(blankMap); + //g.Clear(Color.White); + //g.Dispose(); + //blankTexture = AddTexture(blankMap); + //blankMap.Dispose(); + DrawTexture(blankTexture, rect, color); + //RemoveTexture(ref blankTexture); } #endregion Basic Draw Methods #region Textures + /// + /// Adds a texture and stores it in the VRam + /// + /// The texture's filepath + /// A STexture object containing the added texture public STexture AddTexture(string TexturePath) { if (System.IO.File.Exists(TexturePath)) @@ -519,18 +664,30 @@ namespace Vocaluxe.Lib.Draw return new STexture(-1); } + /// + /// Calculates the next power of two + /// + /// The value of which the next power of two will be calculated + /// The next power of two private static float NextPowerOfTwo(float n) { if (n < 0) throw new ArgumentOutOfRangeException("n", "Must be positive."); return (float)System.Math.Pow(2, System.Math.Ceiling(System.Math.Log((double)n, 2))); } + /// + /// Adds a texture and stores it in the Vram + /// + /// The Bitmap of which the texute will be created from + /// The path to the texture + /// A STexture object containing the added texture public STexture AddTexture(Bitmap bmp, string TexturePath) { STexture texture = new STexture(-1); if (bmp.Height == 0 || bmp.Width == 0) return texture; int MaxSize; + //Apply the right max size switch (CConfig.TextureQuality) { case ETextureQuality.TR_CONFIG_TEXTURE_LOWEST: @@ -571,10 +728,13 @@ namespace Vocaluxe.Lib.Draw texture.width = w; texture.height = h; + //Older graphics card can only handle textures with sizes being powers of two texture.w2 = (float)NextPowerOfTwo(w); texture.h2 = (float)NextPowerOfTwo(h); + //Create a new Bitmap with the new sizes Bitmap bmp2 = new Bitmap((int)texture.w2, (int)texture.h2); + //Scale the texture Graphics g = Graphics.FromImage(bmp2); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; @@ -583,13 +743,17 @@ namespace Vocaluxe.Lib.Draw texture.width_ratio = 1f; texture.height_ratio = 1f; - + + //Fill the new Bitmap with the texture data BitmapData bmp_data = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); byte[] Data = new byte[4 * bmp2.Width * bmp2.Height]; Marshal.Copy(bmp_data.Scan0, Data, 0, Data.Length); bmp2.UnlockBits(bmp_data); - + + //Create a new texture in the managed pool, which does not need to be recreated on a lost device + //because a copy of the texture is hold in the Ram Texture t = new Texture(_Device, (int)texture.w2, (int)texture.h2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); + //Lock the texture and fill it with the data DataRectangle rect = t.LockRectangle(0, LockFlags.None); for (int i = 0; i < Data.Length; ) { @@ -608,11 +772,19 @@ namespace Vocaluxe.Lib.Draw texture.color = new SColorF(1f, 1f, 1f, 1f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.TexturePath = String.Empty; - _Textures.Add(texture); - + lock (MutexTexture) + { + _Textures.Add(texture); + } + return texture; } + /// + /// Adds a texture and stores it in the Vram + /// + /// The Bitmap of which the texute will be created from + /// A STexture object containing the added texture public STexture AddTexture(Bitmap bmp) { return AddTexture(bmp, String.Empty); @@ -622,12 +794,27 @@ namespace Vocaluxe.Lib.Draw { byte[] PointerData = new Byte[4 * W * H]; Marshal.Copy(Data, PointerData, 0, PointerData.Length); - return AddTexture(W, H , ref PointerData); + return AddTexture(W, H, ref PointerData); } public STexture QuequeTexture(int W, int H, ref byte[] Data) { - return AddTexture(W, H, ref Data); + STexture texture = new STexture(-1); + STextureQueque queque = new STextureQueque(); + + queque.data = Data; + queque.height = H; + queque.width = W; + + lock (MutexTexture) + { + _D3DTextures.Add(null); //_D3DTextures.Add(transparentTexture); + texture.index = _D3DTextures.Count - 1; + queque.ID = texture.index; + _Queque.Add(queque); + _Textures.Add(texture); + } + return texture; } public STexture AddTexture(int W, int H, ref byte[] Data) @@ -656,10 +843,20 @@ namespace Vocaluxe.Lib.Draw texture.color = new SColorF(1f, 1f, 1f, 1f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.TexturePath = String.Empty; - _Textures.Add(texture); + + lock (MutexTexture) + { + _Textures.Add(texture); + } return texture; } + /// + /// Updates the data of a texture + /// + /// The texture to update + /// A Pointer containing the data of which the texture should be updated + /// True if succeeded public bool UpdateTexture(ref STexture Texture, IntPtr Data) { byte[] PointerData = new Byte[4 * (int)Texture.width * (int)Texture.height]; @@ -668,297 +865,549 @@ namespace Vocaluxe.Lib.Draw return UpdateTexture(ref Texture, ref PointerData); } + /// + /// Updates the data of a texture + /// + /// The texture to update + /// A byte array containing the new texture's data + /// True if succeeded public bool UpdateTexture(ref STexture Texture, ref byte[] Data) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) + lock (MutexTexture) { - DataRectangle rect = _D3DTextures[Texture.index].LockRectangle(0, LockFlags.None); - for (int i = 0; i < Data.Length; ) + if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index) && _TextureExists(ref Texture)) { - rect.Data.Write(Data, i, 4 * (int)Texture.width); - i += 4 * (int)Texture.width; - rect.Data.Position = rect.Data.Position - 4 * (int)Texture.width; - rect.Data.Position += rect.Pitch; - } - _D3DTextures[Texture.index].UnlockRectangle(0); + DataRectangle rect = _D3DTextures[Texture.index].LockRectangle(0, LockFlags.None); + for (int i = 0; i < Data.Length; ) + { + rect.Data.Write(Data, i, 4 * (int)Texture.width); + i += 4 * (int)Texture.width; + rect.Data.Position = rect.Data.Position - 4 * (int)Texture.width; + rect.Data.Position += rect.Pitch; + } + _D3DTextures[Texture.index].UnlockRectangle(0); - Texture.height_ratio = Texture.height / NextPowerOfTwo(Texture.height); - Texture.width_ratio = Texture.width / NextPowerOfTwo(Texture.width); + Texture.height_ratio = Texture.height / NextPowerOfTwo(Texture.height); + Texture.width_ratio = Texture.width / NextPowerOfTwo(Texture.width); + return true; + } + else + return false; } - return true; } - private bool _TextureExists(STexture Texture) + /// + /// Checks if a texture exists + /// + /// The texture to check + /// True if the texture exists + private bool _TextureExists(ref STexture Texture) { - if ((Texture.index > 0) && (_Textures.Count > 0)) + lock (MutexTexture) { for (int i = 0; i < _Textures.Count; i++) { - if (_Textures[i].index == Texture.index) + if (Texture.index == _Textures[i].index) { - return true; + if (_Textures[i].index >= 0) + { + Texture = _Textures[i]; + return true; + } + break; } } } return false; } + /// + /// Removes a texture from the Vram + /// + /// The texture to be removed public void RemoveTexture(ref STexture Texture) { - if ((Texture.index >= 0) && (_Textures.Count > 0)) + lock (MutexTexture) { - for (int i = 0; i < _Textures.Count; i++) + if ((Texture.index >= 0) && (_Textures.Count > 0)) { - if (_Textures[i].index == Texture.index) + for (int i = 0; i < _Textures.Count; i++) { - _D3DTextures[Texture.index].Dispose(); - _Textures.RemoveAt(i); - Texture.index = -1; - GC.Collect(); - break; + if (_Textures[i].index == Texture.index) + { + _D3DTextures[Texture.index].Dispose(); + _Textures.RemoveAt(i); + Texture.index = -1; + Texture.ID = -1; + break; + } } } } } + /// + /// Draws a texture + /// + /// The texture to be drawn public void DrawTexture(STexture Texture) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, Texture.rect, Texture.color); + //lock (MutexTexture) + { + if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) + DrawTexture(Texture, Texture.rect, Texture.color); + } } + /// + /// Draws a texture + /// + /// The texture to be drawn + /// A SRectF struct containing the destination coordinates public void DrawTexture(STexture Texture, SRectF rect) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, rect, Texture.color, false); + //lock (MutexTexture) + { + if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) + DrawTexture(Texture, rect, Texture.color, false); + } } + /// + /// Draws a texture + /// + /// The texture to be drawn + /// A SRectF struct containing the destination coordinates + /// A SColorF struct containing a color which the texture will be colored in public void DrawTexture(STexture Texture, SRectF rect, SColorF color) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, rect, color, false); + //lock (MutexTexture) + { + if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) + DrawTexture(Texture, rect, color, false); + } } + /// + /// Draws a texture + /// + /// The texture to be drawn + /// A SRectF struct containing the destination coordinates + /// A SColorF struct containing a color which the texture will be colored in + /// A SRectF struct containing which part of the texture should be drawn public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, rect, color, bounds, false); + //lock (MutexTexture) + { + if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) + DrawTexture(Texture, rect, color, bounds, false); + } } + /// + /// Draws a texture + /// + /// The texture to be drawn + /// A SRectF struct containing the destination coordinates + /// A SColorF struct containing a color which the texture will be colored in + /// True if the texture should be mirrored public void DrawTexture(STexture Texture, SRectF rect, SColorF color, bool mirrored) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, rect, color, new SRectF(0, 0, CSettings.iRenderW, CSettings.iRenderH, rect.Z), mirrored); + //lock (MutexTexture) + { + if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) + DrawTexture(Texture, rect, color, new SRectF(0, 0, CSettings.iRenderW, CSettings.iRenderH, rect.Z), mirrored); + } } + /// + /// Draws a texture + /// + /// The texture to be drawn + /// A SRectF struct containing the destination coordinates + /// A SColorF struct containing a color which the texture will be colored in + /// A SRectF struct containing which part of the texture should be drawn + /// True if the texture should be mirrored public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) + //lock (MutexTexture) { - float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; - float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; - float y1 = (bounds.Y - rect.Y) / rect.H * Texture.height_ratio; - float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; - - if (x1 < 0) - x1 = 0f; - - if (x2 > Texture.width_ratio) - x2 = Texture.width_ratio; - - if (y1 < 0) - y1 = 0f; - - if (y2 > Texture.height_ratio) - y2 = Texture.height_ratio; - - float rx1 = rect.X; - float rx2 = rect.X + rect.W; - float ry1 = rect.Y; - float ry2 = rect.Y + rect.H; - - if (rx1 < bounds.X) - rx1 = bounds.X; - - if (rx2 > bounds.X + bounds.W) - rx2 = bounds.X + bounds.W; - - if (ry1 < bounds.Y) - ry1 = bounds.Y; - - if (ry2 > bounds.Y + bounds.H) - ry2 = bounds.Y + bounds.H; - - rx1 -= 0.5f; // Align pixels - ry1 -= 0.5f; - rx2 -= 0.5f; - ry2 -= 0.5f; - - if (color.R >= 1f) - color.R = 1f; - if (color.B >= 1f) - color.B = 1f; - if (color.G >= 1f) - color.G = 1f; - - if (rect.Rotation != 0) + if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index) && _TextureExists(ref Texture)) { - rect.Rotation = rect.Rotation * (float)Math.PI / 180; - float centerX = (rx1 + rx2) / 2f; - float centerY = -(ry1 + ry2) / 2f; + //Calculate the position + float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; + float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; + float y1 = (bounds.Y - rect.Y) / rect.H * Texture.height_ratio; + float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; - Matrix originTranslation = _Device.GetTransform(TransformState.World); - Matrix translationA = Matrix.Translation(-centerX, -centerY, 0); - Matrix rotation = Matrix.RotationZ(-rect.Rotation); - Matrix translationB = Matrix.Translation(centerX, centerY, 0); + if (x1 < 0) + x1 = 0f; - Matrix result = translationA * rotation * translationB * originTranslation; + if (x2 > Texture.width_ratio) + x2 = Texture.width_ratio; - _Device.SetTransform(TransformState.World, result); + if (y1 < 0) + y1 = 0f; + + if (y2 > Texture.height_ratio) + y2 = Texture.height_ratio; + + //Calculate the size + float rx1 = rect.X; + float rx2 = rect.X + rect.W; + float ry1 = rect.Y; + float ry2 = rect.Y + rect.H; + + if (rx1 < bounds.X) + rx1 = bounds.X; + + if (rx2 > bounds.X + bounds.W) + rx2 = bounds.X + bounds.W; + + if (ry1 < bounds.Y) + ry1 = bounds.Y; + + if (ry2 > bounds.Y + bounds.H) + ry2 = bounds.Y + bounds.H; + + //Align the pixels because Direct3D expects the pixels to be the left top corner + rx1 -= 0.5f; + ry1 -= 0.5f; + rx2 -= 0.5f; + ry2 -= 0.5f; + + if (color.R >= 1f) + color.R = 1f; + if (color.B >= 1f) + color.B = 1f; + if (color.G >= 1f) + color.G = 1f; + + //Apply rotation + //FIXME: Rotated textures get distorted when they hit the border of the window + if (rect.Rotation != 0) + { + rect.Rotation = rect.Rotation * (float)Math.PI / 180; + float centerX = (rx1 + rx2) / 2f; + float centerY = -(ry1 + ry2) / 2f; + + Matrix originTranslation = _Device.GetTransform(TransformState.World); + Matrix translationA = Matrix.Translation(-centerX, -centerY, 0); + Matrix rotation = Matrix.RotationZ(-rect.Rotation); + Matrix translationB = Matrix.Translation(centerX, centerY, 0); + + //Multiplicate the matrices to get the real world matrix, + //First shift the texture into the center + //Rotate it and shift it back to the origin position + //Apply the originTranslation after + Matrix result = translationA * rotation * translationB * originTranslation; + + _Device.SetTransform(TransformState.World, result); + } + + Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); + + //Create new vertices and write them into a vertexbuffer + DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); + if (!mirrored) + { + stream.WriteRange(new[] { + new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb()), + }); + } + else + { + stream.WriteRange(new[] { + new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, -y1), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, -y2), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, -y2), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, -y1), c.ToArgb()), + }); + } + _VertexBuffer.Unlock(); + stream.Dispose(); + //Set the texture + _Device.SetTexture(0, _D3DTextures[Texture.index]); + //Draw 2 triangles to build a quad + _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); + + //Reapply old matrices if the texture was rotated + if (rect.Rotation != 0) + { + Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); + _Device.SetTransform(TransformState.World, originTranslation); + } } + } + } - Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); - DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); - if (!mirrored) + /// + /// Draws a texture + /// + /// The texture to be drawn + /// A SRectF struct containing the destination coordinates + /// A SColorF struct containing a color which the texture will be colored in + /// A Value ranging from 0 to 1 containing the beginning of the texture + /// A Value ranging from 0 to 1 containing the ending of the texture + + public void DrawTexture(STexture Texture, SRectF rect, SColorF color, float begin, float end) + { + //lock (MutexTexture) + { + if (_TextureExists(ref Texture)) { + float x1 = 0f + begin * Texture.width_ratio; + float x2 = Texture.width_ratio * end; + float y1 = 0f; + float y2 = Texture.height_ratio; + + float rx1 = rect.X + begin * rect.W; + float rx2 = rect.X + end * rect.W; + float ry1 = rect.Y; + float ry2 = rect.Y + rect.H; + + //Align the pixels because Direct3D expects the pixels to be the left top corner + rx1 -= 0.5f; + ry1 -= 0.5f; + rx2 -= 0.5f; + ry2 -= 0.5f; + + Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); + + //Apply rotation + //FIXME: Rotated textures get distorted when they hit the border of the window + if (rect.Rotation != 0) + { + rect.Rotation = rect.Rotation * (float)Math.PI / 180; + float centerX = (rx1 + rx2) / 2f; + float centerY = -(ry1 + ry2) / 2f; + + Matrix originTranslation = _Device.GetTransform(TransformState.World); + Matrix translationA = Matrix.Translation(-centerX, -centerY, 0); + Matrix rotation = Matrix.RotationZ(-rect.Rotation); + Matrix translationB = Matrix.Translation(centerX, centerY, 0); + + //Multiplicate the matrices to get the real world matrix, + //First shift the texture into the center + //Rotate it and shift it back to the origin position + //Apply the originTranslation after + Matrix result = translationA * rotation * translationB * originTranslation; + + _Device.SetTransform(TransformState.World, result); + } + + //Create new vertices and write them into a vertexbuffer + DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); stream.WriteRange(new[] { new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()), new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb()), }); - } - else - { - stream.WriteRange(new[] { - new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, -y1), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, -y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, -y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, -y1), c.ToArgb()), - }); - } - _VertexBuffer.Unlock(); - stream.Dispose(); - _Device.SetTexture(0, _D3DTextures[Texture.index]); - _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); + _VertexBuffer.Unlock(); + stream.Dispose(); + //Set the texture + _Device.SetTexture(0, _D3DTextures[Texture.index]); + //Draw 2 triangles to build a quad + _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); - if (rect.Rotation != 0) - { - Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); - _Device.SetTransform(TransformState.World, originTranslation); + //Reapply old matrices if the texture was rotated + if (rect.Rotation != 0) + { + Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); + _Device.SetTransform(TransformState.World, originTranslation); + } } } } - public void DrawTexture(STexture Texture, SRectF rect, SColorF color, float begin, float end) - { - - float x1 = 0f + begin * Texture.width_ratio; - float x2 = Texture.width_ratio * end; - float y1 = 0f; - float y2 = Texture.height_ratio; - - float rx1 = rect.X + begin* rect.W; - float rx2 = rect.X + end * rect.W; - float ry1 = rect.Y; - float ry2 = rect.Y + rect.H; - - rx1 -= 0.5f; // Align pixels - ry1 -= 0.5f; - rx2 -= 0.5f; - ry2 -= 0.5f; - - Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); - DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); - stream.WriteRange(new[] { - new TexturedColoredVertex(new Vector3(rx1, ry1*-1f, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx1, ry2*-1f, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, ry2*-1f, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, ry1*-1f, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb()), - }); - _VertexBuffer.Unlock(); - stream.Dispose(); - _Device.SetTexture(0, _D3DTextures[Texture.index]); - _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); - } - + /// + /// Draws a reflection of a texture + /// + /// The texture of which a reflection should be drawn + /// A SRectF struct containing the destination coordinates + /// A SColorF struct containing a color which the texture will be colored in + /// A SRectF struct containing which part of the texture should be drawn + /// The space between the texture and the reflection + /// The height of the reflection public void DrawTextureReflection(STexture Texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) { - if (rect.W == 0f || rect.H == 0f || bounds.H == 0f || bounds.W == 0f || color.A == 0f || height <= 0f) - return; - - if (bounds.X > rect.X + rect.W || bounds.X + bounds.W < rect.X) - return; - - if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y) - return; - - if (height > bounds.H) - height = bounds.H; - - if (_TextureExists(Texture)) + //lock (MutexTexture) { - float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; - float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; - float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * Texture.height_ratio; - float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; + if (_TextureExists(ref Texture)) + { + if (rect.W == 0f || rect.H == 0f || bounds.H == 0f || bounds.W == 0f || color.A == 0f || height <= 0f) + return; - if (x1 < 0) - x1 = 0f; + if (bounds.X > rect.X + rect.W || bounds.X + bounds.W < rect.X) + return; - if (x2 > Texture.width_ratio) - x2 = Texture.width_ratio; + if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y) + return; - if (y1 < 0) - y1 = 0f; + if (height > bounds.H) + height = bounds.H; - if (y2 > Texture.height_ratio) - y2 = Texture.height_ratio; + if (_TextureExists(ref Texture)) + { + float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; + float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; + float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * Texture.height_ratio; + float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; + + if (x1 < 0) + x1 = 0f; + + if (x2 > Texture.width_ratio) + x2 = Texture.width_ratio; + + if (y1 < 0) + y1 = 0f; + + if (y2 > Texture.height_ratio) + y2 = Texture.height_ratio; - float rx1 = rect.X; - float rx2 = rect.X + rect.W; - float ry1 = rect.Y + rect.H + space; - float ry2 = rect.Y + rect.H + space + height; + float rx1 = rect.X; + float rx2 = rect.X + rect.W; + float ry1 = rect.Y + rect.H + space; + float ry2 = rect.Y + rect.H + space + height; - if (rx1 < bounds.X) - rx1 = bounds.X; + if (rx1 < bounds.X) + rx1 = bounds.X; - if (rx2 > bounds.X + bounds.W) - rx2 = bounds.X + bounds.W; + if (rx2 > bounds.X + bounds.W) + rx2 = bounds.X + bounds.W; - if (ry1 < bounds.Y + space) - ry1 = bounds.Y + space; + if (ry1 < bounds.Y + space) + ry1 = bounds.Y + space; - if (ry2 > bounds.Y + bounds.H + space + height) - ry2 = bounds.Y + bounds.H + space + height; + if (ry2 > bounds.Y + bounds.H + space + height) + ry2 = bounds.Y + bounds.H + space + height; - rx1 -= 0.5f; // Align pixels - ry1 -= 0.5f; - rx2 -= 0.5f; - ry2 -= 0.5f; + //Align the pixels because Direct3D expects the pixels to be the left top corner + rx1 -= 0.5f; + ry1 -= 0.5f; + rx2 -= 0.5f; + ry2 -= 0.5f; - DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); + //Apply rotation + //FIXME: Rotated textures get distorted when they hit the border of the window + if (rect.Rotation != 0) + { + rect.Rotation = rect.Rotation * (float)Math.PI / 180; + float centerX = (rx1 + rx2) / 2f; + float centerY = -(ry1 + ry2) / 2f; - Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); - Color t = Color.FromArgb(0, (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); + Matrix originTranslation = _Device.GetTransform(TransformState.World); + Matrix translationA = Matrix.Translation(-centerX, -centerY, 0); + Matrix rotation = Matrix.RotationZ(-rect.Rotation); + Matrix translationB = Matrix.Translation(centerX, centerY, 0); - stream.WriteRange(new[] { + //Multiplicate the matrices to get the real world matrix, + //First shift the texture into the center + //Rotate it and shift it back to the origin position + //Apply the originTranslation after + Matrix result = translationA * rotation * translationB * originTranslation; + + _Device.SetTransform(TransformState.World, result); + } + + Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); + Color transparent = Color.FromArgb(0, (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); + + //Create new vertices and write them into a vertexbuffer + DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); + stream.WriteRange(new[] { new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), t.ToArgb()), - new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), t.ToArgb()), + new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), transparent.ToArgb()), + new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), transparent.ToArgb()), new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), }); - _VertexBuffer.Unlock(); - stream.Dispose(); - _Device.SetTexture(0, _D3DTextures[Texture.index]); - _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); + _VertexBuffer.Unlock(); + stream.Dispose(); + //Set the texture + _Device.SetTexture(0, _D3DTextures[Texture.index]); + //Draw 2 triangles to build a quad + _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); + + //Reapply old matrices if the texture was rotated + if (rect.Rotation != 0) + { + Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); + _Device.SetTransform(TransformState.World, originTranslation); + } + } + } } } + private void CheckQueque() + { + lock (MutexTexture) + { + if (_Queque.Count == 0) + return; + + STextureQueque q = _Queque[0]; + STexture texture = new STexture(-1); + int index = -1; + for (int i = 0; i < _Textures.Count; i++) + { + if (_Textures[i].index == q.ID) + { + texture = _Textures[i]; + index = i; + break; + } + } + + if (texture.index < 0) + return; + + texture.width = q.width; + texture.height = q.height; + texture.w2 = NextPowerOfTwo(texture.width); + texture.h2 = NextPowerOfTwo(texture.height); + + texture.width_ratio = texture.width / texture.w2; + texture.height_ratio = texture.height / texture.h2; + + Texture t = new Texture(_Device, (int)texture.w2, (int)texture.h2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); + DataRectangle rect = t.LockRectangle(0, LockFlags.None); + for (int i = 0; i < q.data.Length; ) + { + rect.Data.Write(q.data, i, 4 * q.width); + i += 4 * q.width; + rect.Data.Position = rect.Data.Position - 4 * q.width; + rect.Data.Position += rect.Pitch; + } + t.UnlockRectangle(0); + _D3DTextures[q.ID] = t; + + // Add to Texture List + texture.color = new SColorF(1f, 1f, 1f, 1f); + texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); + texture.TexturePath = String.Empty; + + _Textures[index] = texture; + _Queque.RemoveAt(0); + } + } + + /// + /// Gets the count of current textures + /// + /// The amount of textures public int TextureCount() { - return _Textures.Count; + lock (MutexTexture) + { + return _Textures.Count; + } } #endregion Textures #endregion implementation @@ -968,12 +1417,12 @@ namespace Vocaluxe.Lib.Draw { private static VertexDeclaration sDeclaration; public static VertexElement[] Elements = - { - new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0), - new VertexElement(0, sizeof(float) *3, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0), - new VertexElement(0, sizeof(float) * 3 + sizeof(float)*2, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0), - VertexElement.VertexDeclarationEnd - }; + { + new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0), + new VertexElement(0, sizeof(float) *3, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0), + new VertexElement(0, sizeof(float) * 3 + sizeof(float)*2, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0), + VertexElement.VertexDeclarationEnd + }; public Vector3 Position; public Vector2 Texture; From 72a6c415ae0a07429b476104546f161d9c807e65 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Fri, 16 Mar 2012 12:49:42 +0100 Subject: [PATCH 15/38] Added jumpTo in songscreen --- Vocaluxe/Screens/CScreenSong.cs | 75 +++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index abc609de..68865476 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -65,13 +65,19 @@ namespace Vocaluxe.Screens if (KeyEvent.Handled) return true; + if (!Char.IsControl(KeyEvent.Unicode)) + { + JumpTo(KeyEvent.Unicode); + return true; + } + switch (KeyEvent.Key) { case Keys.Escape: if (CSongs.Category < 0 || CConfig.Tabs == EOffOn.TR_CONFIG_OFF) CGraphics.FadeTo(EScreens.ScreenMain); break; - + case Keys.Enter: if (CSongs.NumVisibleSongs > 0) StartSong(SongMenus[htSongMenus(SongMenu)].GetSelectedSong()); @@ -101,34 +107,34 @@ namespace Vocaluxe.Screens } break; - case Keys.A: - if (!_SearchActive && KeyEvent.Mod == Modifier.None) - { - StartRandomAllSongs(); - } - if (KeyEvent.Mod == Modifier.Ctrl) - { - StartRandomVisibleSongs(); - } - break; + //case Keys.A: + // if (!_SearchActive && KeyEvent.Mod == Modifier.None) + // { + // StartRandomAllSongs(); + // } + // if (KeyEvent.Mod == Modifier.Ctrl) + // { + // StartRandomVisibleSongs(); + // } + // break; - case Keys.F: - if (KeyEvent.Mod == Modifier.Ctrl){ - if (_SearchActive) - { - _SearchActive = false; - _SearchText = String.Empty; - ApplyNewSearchFilter(_SearchText); - } - else - { - _SearchActive = true; - } - } - break; + //case Keys.F: + // if (KeyEvent.Mod == Modifier.Ctrl){ + // if (_SearchActive) + // { + // _SearchActive = false; + // _SearchText = String.Empty; + // ApplyNewSearchFilter(_SearchText); + // } + // else + // { + // _SearchActive = true; + // } + // } + // break; case Keys.R: - if (CSongs.Category != -1) + if (CSongs.Category != -1 && KeyEvent.Mod == Modifier.Ctrl) { SongMenus[htSongMenus(SongMenu)].SetSelectedSong(CSongs.GetRandomSong()); } @@ -288,6 +294,23 @@ namespace Vocaluxe.Screens CGraphics.FadeTo(EScreens.ScreenNames); } + private void JumpTo(char Letter) + { + int song = SongMenus[htSongMenus(SongMenu)].GetSelectedSong(); + int id = -1; + if (song > -1 && song < CSongs.NumVisibleSongs) + { + id = CSongs.VisibleSongs[song].ID; + } + + Vocaluxe.Lib.Song.CSong s = Array.Find(CSongs.VisibleSongs, element => element.Artist.StartsWith(Letter.ToString(), StringComparison.OrdinalIgnoreCase)); + if (s != null && s.ID > -1) + { + id = s.ID; + SongMenus[htSongMenus(SongMenu)].SetSelectedSong(id); + } + } + private void ApplyNewSearchFilter(string NewFilterString) { int song = SongMenus[htSongMenus(SongMenu)].GetSelectedSong(); From df96c394091fc2a5bc0c546cfc26966e7c57bacd Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Fri, 16 Mar 2012 14:08:12 +0100 Subject: [PATCH 16/38] null textures will no longer get disposed --- Vocaluxe/Lib/Draw/CDirect3D.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 65a9444f..49942b2d 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -471,7 +471,8 @@ namespace Vocaluxe.Lib.Draw //Dispose all textures for (int i = 0; i < _D3DTextures.Count; i++) { - _D3DTextures[i].Dispose(); + if(_D3DTextures[i] != null) + _D3DTextures[i].Dispose(); } TexturedColoredVertex.GetDeclaration(_Device).Dispose(); _VertexBuffer.Dispose(); @@ -933,13 +934,13 @@ namespace Vocaluxe.Lib.Draw { for (int i = 0; i < _Textures.Count; i++) { - if (_Textures[i].index == Texture.index) + if (_Textures[i].index == Texture.index && _D3DTextures[i] != null) { _D3DTextures[Texture.index].Dispose(); + _D3DTextures[Texture.index] = null; _Textures.RemoveAt(i); Texture.index = -1; Texture.ID = -1; - break; } } } From a88c1227eb40a71ba01117c273e4052f58de4434 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Fri, 16 Mar 2012 15:46:15 +0100 Subject: [PATCH 17/38] Fixed memory leak --- Vocaluxe/Lib/Draw/CDirect3D.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 49942b2d..bceaf4d1 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -934,7 +934,7 @@ namespace Vocaluxe.Lib.Draw { for (int i = 0; i < _Textures.Count; i++) { - if (_Textures[i].index == Texture.index && _D3DTextures[i] != null) + if (_Textures[i].index == Texture.index) { _D3DTextures[Texture.index].Dispose(); _D3DTextures[Texture.index] = null; From 73132f3932bd220fe39db3c5ebb4476b488e56b2 Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Fri, 16 Mar 2012 16:30:34 +0100 Subject: [PATCH 18/38] Code cleanup --- Vocaluxe/Lib/Draw/CDirect3D.cs | 500 ++++++++++++++++----------------- 1 file changed, 238 insertions(+), 262 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index bceaf4d1..2df5bb7f 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -953,11 +953,8 @@ namespace Vocaluxe.Lib.Draw /// The texture to be drawn public void DrawTexture(STexture Texture) { - //lock (MutexTexture) - { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, Texture.rect, Texture.color); - } + if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) + DrawTexture(Texture, Texture.rect, Texture.color); } /// @@ -967,11 +964,8 @@ namespace Vocaluxe.Lib.Draw /// A SRectF struct containing the destination coordinates public void DrawTexture(STexture Texture, SRectF rect) { - //lock (MutexTexture) - { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, rect, Texture.color, false); - } + if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) + DrawTexture(Texture, rect, Texture.color, false); } /// @@ -982,11 +976,8 @@ namespace Vocaluxe.Lib.Draw /// A SColorF struct containing a color which the texture will be colored in public void DrawTexture(STexture Texture, SRectF rect, SColorF color) { - //lock (MutexTexture) - { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, rect, color, false); - } + if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) + DrawTexture(Texture, rect, color, false); } /// @@ -998,11 +989,8 @@ namespace Vocaluxe.Lib.Draw /// A SRectF struct containing which part of the texture should be drawn public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds) { - //lock (MutexTexture) - { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, rect, color, bounds, false); - } + if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) + DrawTexture(Texture, rect, color, bounds, false); } /// @@ -1014,11 +1002,8 @@ namespace Vocaluxe.Lib.Draw /// True if the texture should be mirrored public void DrawTexture(STexture Texture, SRectF rect, SColorF color, bool mirrored) { - //lock (MutexTexture) - { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) - DrawTexture(Texture, rect, color, new SRectF(0, 0, CSettings.iRenderW, CSettings.iRenderH, rect.Z), mirrored); - } + if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index)) + DrawTexture(Texture, rect, color, new SRectF(0, 0, CSettings.iRenderW, CSettings.iRenderH, rect.Z), mirrored); } /// @@ -1031,116 +1016,113 @@ namespace Vocaluxe.Lib.Draw /// True if the texture should be mirrored public void DrawTexture(STexture Texture, SRectF rect, SColorF color, SRectF bounds, bool mirrored) { - //lock (MutexTexture) + if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index) && _TextureExists(ref Texture)) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index) && _TextureExists(ref Texture)) + //Calculate the position + float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; + float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; + float y1 = (bounds.Y - rect.Y) / rect.H * Texture.height_ratio; + float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; + + if (x1 < 0) + x1 = 0f; + + if (x2 > Texture.width_ratio) + x2 = Texture.width_ratio; + + if (y1 < 0) + y1 = 0f; + + if (y2 > Texture.height_ratio) + y2 = Texture.height_ratio; + + //Calculate the size + float rx1 = rect.X; + float rx2 = rect.X + rect.W; + float ry1 = rect.Y; + float ry2 = rect.Y + rect.H; + + if (rx1 < bounds.X) + rx1 = bounds.X; + + if (rx2 > bounds.X + bounds.W) + rx2 = bounds.X + bounds.W; + + if (ry1 < bounds.Y) + ry1 = bounds.Y; + + if (ry2 > bounds.Y + bounds.H) + ry2 = bounds.Y + bounds.H; + + //Align the pixels because Direct3D expects the pixels to be the left top corner + rx1 -= 0.5f; + ry1 -= 0.5f; + rx2 -= 0.5f; + ry2 -= 0.5f; + + if (color.R >= 1f) + color.R = 1f; + if (color.B >= 1f) + color.B = 1f; + if (color.G >= 1f) + color.G = 1f; + + //Apply rotation + //FIXME: Rotated textures get distorted when they hit the border of the window + if (rect.Rotation != 0) { - //Calculate the position - float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; - float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; - float y1 = (bounds.Y - rect.Y) / rect.H * Texture.height_ratio; - float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; + rect.Rotation = rect.Rotation * (float)Math.PI / 180; + float centerX = (rx1 + rx2) / 2f; + float centerY = -(ry1 + ry2) / 2f; - if (x1 < 0) - x1 = 0f; + Matrix originTranslation = _Device.GetTransform(TransformState.World); + Matrix translationA = Matrix.Translation(-centerX, -centerY, 0); + Matrix rotation = Matrix.RotationZ(-rect.Rotation); + Matrix translationB = Matrix.Translation(centerX, centerY, 0); - if (x2 > Texture.width_ratio) - x2 = Texture.width_ratio; + //Multiplicate the matrices to get the real world matrix, + //First shift the texture into the center + //Rotate it and shift it back to the origin position + //Apply the originTranslation after + Matrix result = translationA * rotation * translationB * originTranslation; - if (y1 < 0) - y1 = 0f; + _Device.SetTransform(TransformState.World, result); + } - if (y2 > Texture.height_ratio) - y2 = Texture.height_ratio; + Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); - //Calculate the size - float rx1 = rect.X; - float rx2 = rect.X + rect.W; - float ry1 = rect.Y; - float ry2 = rect.Y + rect.H; - - if (rx1 < bounds.X) - rx1 = bounds.X; - - if (rx2 > bounds.X + bounds.W) - rx2 = bounds.X + bounds.W; - - if (ry1 < bounds.Y) - ry1 = bounds.Y; - - if (ry2 > bounds.Y + bounds.H) - ry2 = bounds.Y + bounds.H; - - //Align the pixels because Direct3D expects the pixels to be the left top corner - rx1 -= 0.5f; - ry1 -= 0.5f; - rx2 -= 0.5f; - ry2 -= 0.5f; - - if (color.R >= 1f) - color.R = 1f; - if (color.B >= 1f) - color.B = 1f; - if (color.G >= 1f) - color.G = 1f; - - //Apply rotation - //FIXME: Rotated textures get distorted when they hit the border of the window - if (rect.Rotation != 0) - { - rect.Rotation = rect.Rotation * (float)Math.PI / 180; - float centerX = (rx1 + rx2) / 2f; - float centerY = -(ry1 + ry2) / 2f; - - Matrix originTranslation = _Device.GetTransform(TransformState.World); - Matrix translationA = Matrix.Translation(-centerX, -centerY, 0); - Matrix rotation = Matrix.RotationZ(-rect.Rotation); - Matrix translationB = Matrix.Translation(centerX, centerY, 0); - - //Multiplicate the matrices to get the real world matrix, - //First shift the texture into the center - //Rotate it and shift it back to the origin position - //Apply the originTranslation after - Matrix result = translationA * rotation * translationB * originTranslation; - - _Device.SetTransform(TransformState.World, result); - } - - Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); - - //Create new vertices and write them into a vertexbuffer - DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); - if (!mirrored) - { - stream.WriteRange(new[] { - new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb()), - }); - } - else - { - stream.WriteRange(new[] { - new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, -y1), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, -y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, -y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, -y1), c.ToArgb()), + //Create new vertices and write them into a vertexbuffer + DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); + if (!mirrored) + { + stream.WriteRange(new[] { + new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb()), + }); + } + else + { + stream.WriteRange(new[] { + new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, -y1), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, -y2), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, -y2), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, -y1), c.ToArgb()), }); - } - _VertexBuffer.Unlock(); - stream.Dispose(); - //Set the texture - _Device.SetTexture(0, _D3DTextures[Texture.index]); - //Draw 2 triangles to build a quad - _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); + } + _VertexBuffer.Unlock(); + stream.Dispose(); + //Set the texture + _Device.SetTexture(0, _D3DTextures[Texture.index]); + //Draw 2 triangles to build a quad + _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); - //Reapply old matrices if the texture was rotated - if (rect.Rotation != 0) - { - Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); - _Device.SetTransform(TransformState.World, originTranslation); - } + //Reapply old matrices if the texture was rotated + if (rect.Rotation != 0) + { + Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); + _Device.SetTransform(TransformState.World, originTranslation); } } } @@ -1156,19 +1138,133 @@ namespace Vocaluxe.Lib.Draw public void DrawTexture(STexture Texture, SRectF rect, SColorF color, float begin, float end) { - //lock (MutexTexture) + if (_TextureExists(ref Texture)) { + float x1 = 0f + begin * Texture.width_ratio; + float x2 = Texture.width_ratio * end; + float y1 = 0f; + float y2 = Texture.height_ratio; + + float rx1 = rect.X + begin * rect.W; + float rx2 = rect.X + end * rect.W; + float ry1 = rect.Y; + float ry2 = rect.Y + rect.H; + + //Align the pixels because Direct3D expects the pixels to be the left top corner + rx1 -= 0.5f; + ry1 -= 0.5f; + rx2 -= 0.5f; + ry2 -= 0.5f; + + Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); + + //Apply rotation + //FIXME: Rotated textures get distorted when they hit the border of the window + if (rect.Rotation != 0) + { + rect.Rotation = rect.Rotation * (float)Math.PI / 180; + float centerX = (rx1 + rx2) / 2f; + float centerY = -(ry1 + ry2) / 2f; + + Matrix originTranslation = _Device.GetTransform(TransformState.World); + Matrix translationA = Matrix.Translation(-centerX, -centerY, 0); + Matrix rotation = Matrix.RotationZ(-rect.Rotation); + Matrix translationB = Matrix.Translation(centerX, centerY, 0); + + //Multiplicate the matrices to get the real world matrix, + //First shift the texture into the center + //Rotate it and shift it back to the origin position + //Apply the originTranslation after + Matrix result = translationA * rotation * translationB * originTranslation; + + _Device.SetTransform(TransformState.World, result); + } + + //Create new vertices and write them into a vertexbuffer + DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); + stream.WriteRange(new[] { + new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb()), + }); + _VertexBuffer.Unlock(); + stream.Dispose(); + //Set the texture + _Device.SetTexture(0, _D3DTextures[Texture.index]); + //Draw 2 triangles to build a quad + _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); + + //Reapply old matrices if the texture was rotated + if (rect.Rotation != 0) + { + Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); + _Device.SetTransform(TransformState.World, originTranslation); + } + } + } + + /// + /// Draws a reflection of a texture + /// + /// The texture of which a reflection should be drawn + /// A SRectF struct containing the destination coordinates + /// A SColorF struct containing a color which the texture will be colored in + /// A SRectF struct containing which part of the texture should be drawn + /// The space between the texture and the reflection + /// The height of the reflection + public void DrawTextureReflection(STexture Texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) + { + if (_TextureExists(ref Texture)) + { + if (rect.W == 0f || rect.H == 0f || bounds.H == 0f || bounds.W == 0f || color.A == 0f || height <= 0f) + return; + + if (bounds.X > rect.X + rect.W || bounds.X + bounds.W < rect.X) + return; + + if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y) + return; + + if (height > bounds.H) + height = bounds.H; + if (_TextureExists(ref Texture)) { - float x1 = 0f + begin * Texture.width_ratio; - float x2 = Texture.width_ratio * end; - float y1 = 0f; - float y2 = Texture.height_ratio; + float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; + float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; + float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * Texture.height_ratio; + float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; - float rx1 = rect.X + begin * rect.W; - float rx2 = rect.X + end * rect.W; - float ry1 = rect.Y; - float ry2 = rect.Y + rect.H; + if (x1 < 0) + x1 = 0f; + + if (x2 > Texture.width_ratio) + x2 = Texture.width_ratio; + + if (y1 < 0) + y1 = 0f; + + if (y2 > Texture.height_ratio) + y2 = Texture.height_ratio; + + + float rx1 = rect.X; + float rx2 = rect.X + rect.W; + float ry1 = rect.Y + rect.H + space; + float ry2 = rect.Y + rect.H + space + height; + + if (rx1 < bounds.X) + rx1 = bounds.X; + + if (rx2 > bounds.X + bounds.W) + rx2 = bounds.X + bounds.W; + + if (ry1 < bounds.Y + space) + ry1 = bounds.Y + space; + + if (ry2 > bounds.Y + bounds.H + space + height) + ry2 = bounds.Y + bounds.H + space + height; //Align the pixels because Direct3D expects the pixels to be the left top corner rx1 -= 0.5f; @@ -1176,8 +1272,6 @@ namespace Vocaluxe.Lib.Draw rx2 -= 0.5f; ry2 -= 0.5f; - Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); - //Apply rotation //FIXME: Rotated textures get distorted when they hit the border of the window if (rect.Rotation != 0) @@ -1200,13 +1294,16 @@ namespace Vocaluxe.Lib.Draw _Device.SetTransform(TransformState.World, result); } + Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); + Color transparent = Color.FromArgb(0, (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); + //Create new vertices and write them into a vertexbuffer DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); stream.WriteRange(new[] { - new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), + new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), transparent.ToArgb()), + new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), transparent.ToArgb()), + new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), }); _VertexBuffer.Unlock(); stream.Dispose(); @@ -1225,127 +1322,6 @@ namespace Vocaluxe.Lib.Draw } } - /// - /// Draws a reflection of a texture - /// - /// The texture of which a reflection should be drawn - /// A SRectF struct containing the destination coordinates - /// A SColorF struct containing a color which the texture will be colored in - /// A SRectF struct containing which part of the texture should be drawn - /// The space between the texture and the reflection - /// The height of the reflection - public void DrawTextureReflection(STexture Texture, SRectF rect, SColorF color, SRectF bounds, float space, float height) - { - //lock (MutexTexture) - { - if (_TextureExists(ref Texture)) - { - if (rect.W == 0f || rect.H == 0f || bounds.H == 0f || bounds.W == 0f || color.A == 0f || height <= 0f) - return; - - if (bounds.X > rect.X + rect.W || bounds.X + bounds.W < rect.X) - return; - - if (bounds.Y > rect.Y + rect.H || bounds.Y + bounds.H < rect.Y) - return; - - if (height > bounds.H) - height = bounds.H; - - if (_TextureExists(ref Texture)) - { - float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; - float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; - float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * Texture.height_ratio; - float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; - - if (x1 < 0) - x1 = 0f; - - if (x2 > Texture.width_ratio) - x2 = Texture.width_ratio; - - if (y1 < 0) - y1 = 0f; - - if (y2 > Texture.height_ratio) - y2 = Texture.height_ratio; - - - float rx1 = rect.X; - float rx2 = rect.X + rect.W; - float ry1 = rect.Y + rect.H + space; - float ry2 = rect.Y + rect.H + space + height; - - if (rx1 < bounds.X) - rx1 = bounds.X; - - if (rx2 > bounds.X + bounds.W) - rx2 = bounds.X + bounds.W; - - if (ry1 < bounds.Y + space) - ry1 = bounds.Y + space; - - if (ry2 > bounds.Y + bounds.H + space + height) - ry2 = bounds.Y + bounds.H + space + height; - - //Align the pixels because Direct3D expects the pixels to be the left top corner - rx1 -= 0.5f; - ry1 -= 0.5f; - rx2 -= 0.5f; - ry2 -= 0.5f; - - //Apply rotation - //FIXME: Rotated textures get distorted when they hit the border of the window - if (rect.Rotation != 0) - { - rect.Rotation = rect.Rotation * (float)Math.PI / 180; - float centerX = (rx1 + rx2) / 2f; - float centerY = -(ry1 + ry2) / 2f; - - Matrix originTranslation = _Device.GetTransform(TransformState.World); - Matrix translationA = Matrix.Translation(-centerX, -centerY, 0); - Matrix rotation = Matrix.RotationZ(-rect.Rotation); - Matrix translationB = Matrix.Translation(centerX, centerY, 0); - - //Multiplicate the matrices to get the real world matrix, - //First shift the texture into the center - //Rotate it and shift it back to the origin position - //Apply the originTranslation after - Matrix result = translationA * rotation * translationB * originTranslation; - - _Device.SetTransform(TransformState.World, result); - } - - Color c = Color.FromArgb((int)(color.A * 255 * CGraphics.GlobalAlpha), (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); - Color transparent = Color.FromArgb(0, (int)(color.R * 255), (int)(color.G * 255), (int)(color.B * 255)); - - //Create new vertices and write them into a vertexbuffer - DataStream stream = _VertexBuffer.Lock(0, 0, LockFlags.Discard); - stream.WriteRange(new[] { - new TexturedColoredVertex(new Vector3(rx2, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x2, y2), c.ToArgb()), - new TexturedColoredVertex(new Vector3(rx2, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x2, y1), transparent.ToArgb()), - new TexturedColoredVertex(new Vector3(rx1, -ry2, rect.Z + CGraphics.ZOffset), new Vector2(x1, y1), transparent.ToArgb()), - new TexturedColoredVertex(new Vector3(rx1, -ry1, rect.Z + CGraphics.ZOffset), new Vector2(x1, y2), c.ToArgb()), - }); - _VertexBuffer.Unlock(); - stream.Dispose(); - //Set the texture - _Device.SetTexture(0, _D3DTextures[Texture.index]); - //Draw 2 triangles to build a quad - _Device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); - - //Reapply old matrices if the texture was rotated - if (rect.Rotation != 0) - { - Matrix originTranslation = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0)); - _Device.SetTransform(TransformState.World, originTranslation); - } - } - } - } - } - private void CheckQueque() { lock (MutexTexture) From 92a84f62f171075483e4d47eaec20cf871a38c4f Mon Sep 17 00:00:00 2001 From: Stephan Sundermann Date: Fri, 16 Mar 2012 16:53:41 +0100 Subject: [PATCH 19/38] Removed unnecessary locks --- Vocaluxe/Lib/Draw/CDirect3D.cs | 47 +++++++++++++++------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 2df5bb7f..3bf614d5 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -764,17 +764,18 @@ namespace Vocaluxe.Lib.Draw rect.Data.Position += rect.Pitch; } t.UnlockRectangle(0); - _D3DTextures.Add(t); + bmp2.Dispose(); bmp_data = null; // Add to Texture List - texture.index = _D3DTextures.Count - 1; texture.color = new SColorF(1f, 1f, 1f, 1f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.TexturePath = String.Empty; lock (MutexTexture) { + _D3DTextures.Add(t); + texture.index = _D3DTextures.Count - 1; _Textures.Add(texture); } @@ -809,7 +810,7 @@ namespace Vocaluxe.Lib.Draw lock (MutexTexture) { - _D3DTextures.Add(null); //_D3DTextures.Add(transparentTexture); + _D3DTextures.Add(null); texture.index = _D3DTextures.Count - 1; queque.ID = texture.index; _Queque.Add(queque); @@ -838,15 +839,15 @@ namespace Vocaluxe.Lib.Draw rect.Data.Position += rect.Pitch; } t.UnlockRectangle(0); - _D3DTextures.Add(t); - texture.index = _D3DTextures.Count - 1; texture.color = new SColorF(1f, 1f, 1f, 1f); texture.rect = new SRectF(0f, 0f, texture.width, texture.height, 0f); texture.TexturePath = String.Empty; lock (MutexTexture) { + _D3DTextures.Add(t); + texture.index = _D3DTextures.Count - 1; _Textures.Add(texture); } return texture; @@ -874,27 +875,24 @@ namespace Vocaluxe.Lib.Draw /// True if succeeded public bool UpdateTexture(ref STexture Texture, ref byte[] Data) { - lock (MutexTexture) + if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index) && _TextureExists(ref Texture)) { - if ((Texture.index >= 0) && (_Textures.Count > 0) && (_D3DTextures.Count > Texture.index) && _TextureExists(ref Texture)) + DataRectangle rect = _D3DTextures[Texture.index].LockRectangle(0, LockFlags.None); + for (int i = 0; i < Data.Length; ) { - DataRectangle rect = _D3DTextures[Texture.index].LockRectangle(0, LockFlags.None); - for (int i = 0; i < Data.Length; ) - { - rect.Data.Write(Data, i, 4 * (int)Texture.width); - i += 4 * (int)Texture.width; - rect.Data.Position = rect.Data.Position - 4 * (int)Texture.width; - rect.Data.Position += rect.Pitch; - } - _D3DTextures[Texture.index].UnlockRectangle(0); - - Texture.height_ratio = Texture.height / NextPowerOfTwo(Texture.height); - Texture.width_ratio = Texture.width / NextPowerOfTwo(Texture.width); - return true; + rect.Data.Write(Data, i, 4 * (int)Texture.width); + i += 4 * (int)Texture.width; + rect.Data.Position = rect.Data.Position - 4 * (int)Texture.width; + rect.Data.Position += rect.Pitch; } - else - return false; + _D3DTextures[Texture.index].UnlockRectangle(0); + + Texture.height_ratio = Texture.height / NextPowerOfTwo(Texture.height); + Texture.width_ratio = Texture.width / NextPowerOfTwo(Texture.width); + return true; } + else + return false; } /// @@ -1381,10 +1379,7 @@ namespace Vocaluxe.Lib.Draw /// The amount of textures public int TextureCount() { - lock (MutexTexture) - { - return _Textures.Count; - } + return _Textures.Count; } #endregion Textures #endregion implementation From 269a66e267beb2d0ba726342c7b6377a36da8da3 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Fri, 16 Mar 2012 18:14:56 +0100 Subject: [PATCH 20/38] check ticks (some computers have problems with HPET) --- Vocaluxe/Base/CSound.cs | 6 +++--- Vocaluxe/Base/CUtility.cs | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Vocaluxe/Base/CSound.cs b/Vocaluxe/Base/CSound.cs index 2a2f9d0f..ff4a30ff 100644 --- a/Vocaluxe/Base/CSound.cs +++ b/Vocaluxe/Base/CSound.cs @@ -501,7 +501,7 @@ namespace Vocaluxe.Base long ticks = _Timer.ElapsedTicks; float dt = _Timer.ElapsedMilliseconds / 1000f; - if (Stopwatch.IsHighResolution) + if (Stopwatch.IsHighResolution && ticks != 0) dt = (float)(ticks * nanosecPerTick / 1000000000.0); return _SetValue + dt; @@ -581,7 +581,7 @@ namespace Vocaluxe.Base long ticks = _STimer.ElapsedTicks; float dt = _STimer.ElapsedMilliseconds / 1000f; - if (Stopwatch.IsHighResolution) + if (Stopwatch.IsHighResolution && ticks != 0) dt = (float)(ticks * nanosecPerTick / 1000000000.0); return _CurrentTime + dt; @@ -617,7 +617,7 @@ namespace Vocaluxe.Base long ticks = _STimer.ElapsedTicks; float dt = _STimer.ElapsedMilliseconds / 1000f; - if (Stopwatch.IsHighResolution) + if (Stopwatch.IsHighResolution && ticks != 0) dt = (float)(ticks * nanosecPerTick / 1000000000.0); float Ts = 0f; diff --git a/Vocaluxe/Base/CUtility.cs b/Vocaluxe/Base/CUtility.cs index fe8bcea8..ef4e94dd 100644 --- a/Vocaluxe/Base/CUtility.cs +++ b/Vocaluxe/Base/CUtility.cs @@ -147,8 +147,9 @@ namespace Vocaluxe.Base { if (_Stopwatch.IsRunning) { - if (Stopwatch.IsHighResolution) - return (float)(((double)nanosecPerTick * (double)_Stopwatch.ElapsedTicks) / (1000.0 * 1000.0)); + long ticks = _Stopwatch.ElapsedTicks; + if (Stopwatch.IsHighResolution && ticks != 0) + return (float)(((double)nanosecPerTick * (double)ticks) / (1000.0 * 1000.0)); else return (float)_Stopwatch.ElapsedMilliseconds; } From f2b53ce29d47cf71940dde26c3056f31e93a26d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20B=C3=B6hning?= Date: Fri, 16 Mar 2012 18:27:45 +0100 Subject: [PATCH 21/38] Update README --- README | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README b/README index ee39f054..633e455a 100644 --- a/README +++ b/README @@ -16,9 +16,11 @@ ================================= = 1. About = ================================= -Vocaluxe is a free and open source singing game. It allows up to three players (currently) to sing along with music using microphones in order to score points, depending on the pitch of the voice and the rhythm of singing. - -Vocaluxe is an entirely new development in C#, inspired by the original UltraStar (developed by corvus5) and the great Ultrastar Deluxe project. +Vocaluxe is a free and open source singing game, inspired by the original UltraStar (developed by corvus5) +and the great Ultrastar Deluxe project - yet it is an entirely new development in C#. It allows up to three +players (currently) to sing along with music using microphones in order to score points, depending on the +pitch of the voice and the rhythm of singing. It features mouse and keyboard navigation, a multi-language +interface, and singer profiles with avatars and supports songs in CP1250/52 and UTF8 encodings. Supported Operating Systems / Requirements: - WinXP, Vista, Windows 7 with .NET 2.0 From cd06dc7d497612faba335b4b5b464447b7a8e37d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20B=C3=B6hning?= Date: Fri, 16 Mar 2012 18:29:44 +0100 Subject: [PATCH 22/38] Update README --- README | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README b/README index 633e455a..9d9eb04e 100644 --- a/README +++ b/README @@ -16,11 +16,7 @@ ================================= = 1. About = ================================= -Vocaluxe is a free and open source singing game, inspired by the original UltraStar (developed by corvus5) -and the great Ultrastar Deluxe project - yet it is an entirely new development in C#. It allows up to three -players (currently) to sing along with music using microphones in order to score points, depending on the -pitch of the voice and the rhythm of singing. It features mouse and keyboard navigation, a multi-language -interface, and singer profiles with avatars and supports songs in CP1250/52 and UTF8 encodings. +Vocaluxe is a free and open source singing game, inspired by the original UltraStar (developed by corvus5) and the great Ultrastar Deluxe project - yet it is an entirely new development in C#. It allows up to three players (currently) to sing along with music using microphones in order to score points, depending on the pitch of the voice and the rhythm of singing. It features mouse and keyboard navigation, a multi-language interface, and singer profiles with avatars and supports songs in CP1250/52 and UTF8 encodings. Supported Operating Systems / Requirements: - WinXP, Vista, Windows 7 with .NET 2.0 From 5415be87d958312ed8447e0fa587fe78cc2559e4 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Fri, 16 Mar 2012 19:17:49 +0100 Subject: [PATCH 23/38] update of credits screen --- Vocaluxe/Screens/CScreenCredits.cs | 32 +++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index ba8f1fec..c1dfa851 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -65,19 +65,33 @@ namespace Vocaluxe.Screens //Text for last part of credits. paragraphTexts = new List(); paragraphs = new List(); - string paragraph = "Inspired by the achievements of UltraStar Deluxe and its variants and pursuing the goal of making a good thing even better, we ended up rewriting the game from scratch. And a new implementation in a new programming language called for a new name - and VOCALUXE it is!"; - string[] words = paragraph.Split(new Char[] { ' ' }); - paragraphs.Add(words); - paragraph = "This first public version has already implemented many of the original features and it is fully compatible with all the song files in your existing song collection. The code design allows a much faster implementation of new features, thus the roadmap for the next few stable releases is packed and we expect much shorter release cycles than ever before. And, of course, our and your ideas may be the features of tomorrow."; + string paragraph; + string[] words; + + paragraph = "Inspired by the achievements of UltraStar Deluxe and its variants and pursuing the goal of making " + + "a good thing even better, we ended up rewriting the game from scratch. And a new implementation in a new " + + "programming language called for a new name - and VOCALUXE [ˈvoʊˈkəˈlʌks] it is!"; words = paragraph.Split(new Char[] { ' ' }); paragraphs.Add(words); - paragraph = "We appreciate the feedback in the beta release phase and are, of course, always open for bug reports, suggestions for improve- ments and ideas for new features. We would also like to thank the translators who make Vocaluxe an international experience from the very beginning. Last, but most definitely not least, we thank all those diligent song makers out there - there's a song for everyone!"; + paragraph = "This first public version has already implemented many of the original features and it is fully " + + "compatible with all the song files in your existing song collection. The code design allows a much faster " + + "implementation of new features, thus the roadmap for the next few stable releases is packed and we expect much " + + "shorter release cycles than ever before. And, of course, our and your ideas may be the features of tomorrow."; words = paragraph.Split(new Char[] { ' ' }); paragraphs.Add(words); - paragraph = "Go ahead and grab your mics, crank up your stereo, warm up your voice and get ready to sing to the best of your abilities!"; + paragraph = "We appreciate the feedback in the beta release phase and are, of course, always open for bug reports, " + + "suggestions for improvements and ideas for new features. We would also like to thank the translators who make " + + "Vocaluxe an international experience from the very beginning and all those diligent song makers out there - " + + "there's something for everyone in the huge collection of available songs! Last but not least, thanks to " + + "Kosal Sen's Philly Sans type used in the Vocaluxe Logo."; + words = paragraph.Split(new Char[] { ' ' }); + paragraphs.Add(words); + + paragraph = "Go ahead and grab your mics, crank up your stereo, warm up your voice and get ready to sing to the best " + + "of your abilities!"; words = paragraph.Split(new Char[] { ' ' }); paragraphs.Add(words); } @@ -245,7 +259,7 @@ namespace Vocaluxe.Screens { string newline = line + " " + paragraphs[i][e]; CText text = new CText(75, lastY, -2, 30, -1, EAlignment.Left, EStyle.Bold, "Outline", new SColorF(1, 1, 1, 1), line); - if (CDraw.GetTextBounds(text).Width < (CSettings.iRenderW - 160)) + if (CDraw.GetTextBounds(text).Width < (CSettings.iRenderW - 200)) { line = line + " " + paragraphs[i][e]; @@ -303,7 +317,7 @@ namespace Vocaluxe.Screens } //Draw Text - if (TextTimer.IsRunning) + if (TextTimer.IsRunning || true) { for (int i = 0; i < paragraphTexts.Count; i++) { @@ -427,7 +441,7 @@ namespace Vocaluxe.Screens if (TextTimer.IsRunning) { - if (TextTimer.ElapsedMilliseconds > 10000) + if (TextTimer.ElapsedMilliseconds > 600000) { active = false; } From c276caa0c1578176a6c1fb2d798956b536b420a5 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Fri, 16 Mar 2012 19:19:42 +0100 Subject: [PATCH 24/38] fixed text drawing in credits screen --- Vocaluxe/Screens/CScreenCredits.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index c1dfa851..11b02cd9 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -317,7 +317,7 @@ namespace Vocaluxe.Screens } //Draw Text - if (TextTimer.IsRunning || true) + if (TextTimer.IsRunning) { for (int i = 0; i < paragraphTexts.Count; i++) { From 7b515207c0bcd08b49f1d6acd0f192660e18cc87 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Fri, 16 Mar 2012 19:38:05 +0100 Subject: [PATCH 25/38] reset timer in credits screen --- Vocaluxe/Screens/CScreenCredits.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index 11b02cd9..6f58a3e6 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -281,6 +281,9 @@ namespace Vocaluxe.Screens } } } + TextTimer.Reset(); + LogoTimer.Reset(); + CreditsTimer.Reset(); } public override void OnShowFinish() From 86ef72f833d85dd62f990e2712462cc760a5dd62 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Fri, 16 Mar 2012 19:39:03 +0100 Subject: [PATCH 26/38] reduced font texture base size from 100 to 50 => 75% lower memory consumption by fonts (quality is still ok) --- Vocaluxe/Base/CFont.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vocaluxe/Base/CFont.cs b/Vocaluxe/Base/CFont.cs index fbf5d97a..ab6e7157 100644 --- a/Vocaluxe/Base/CFont.cs +++ b/Vocaluxe/Base/CFont.cs @@ -32,7 +32,7 @@ namespace Vocaluxe.Base class CGlyph { - public readonly float SIZEh = 100f; + public readonly float SIZEh = 50f; public STexture Texture; public char Chr; public int width; From 2ca236f4dc3c5354c78f35716cda8e7f52508415 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Fri, 16 Mar 2012 19:48:23 +0100 Subject: [PATCH 27/38] removed display lists from COpenGL.cs --- Vocaluxe/Lib/Draw/COpenGL.cs | 405 ++++++++++++++++------------------- 1 file changed, 184 insertions(+), 221 deletions(-) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 1492f0c0..18896f52 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -48,7 +48,6 @@ namespace Vocaluxe.Lib.Draw private List _Textures; private List _IDs; - private List _GLList; private List _Queque; private Object MutexTexture = new Object(); @@ -67,7 +66,6 @@ namespace Vocaluxe.Lib.Draw this.Icon = new System.Drawing.Icon(Path.Combine(System.Environment.CurrentDirectory, CSettings.sIcon)); _Textures = new List(); - _GLList = new List(); _Queque = new List(); _IDs = new List(); @@ -461,13 +459,6 @@ namespace Vocaluxe.Lib.Draw _Run = _Run && CGraphics.Draw(); - GL.CallLists(_GLList.Count, ListNameType.Int, _GLList.ToArray()); - - if (_GLList.Count > 0) - GL.DeleteLists(_GLList[0], _GLList.Count); - - _GLList.Clear(); - _Run = CGraphics.UpdateGameLogic(_Keys, _Mouse); control.SwapBuffers(); @@ -631,24 +622,17 @@ namespace Vocaluxe.Lib.Draw public void DrawColor(SColorF color, SRectF rect) { - int list = GL.GenLists(1); - _GLList.Add(list); + GL.Enable(EnableCap.Blend); + GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); - GL.NewList(list, ListMode.Compile); - { - GL.Enable(EnableCap.Blend); - GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); + GL.Begin(BeginMode.Quads); + GL.Vertex3(rect.X, rect.Y, rect.Z + CGraphics.ZOffset); + GL.Vertex3(rect.X, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); + GL.Vertex3(rect.X + rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); + GL.Vertex3(rect.X + rect.W, rect.Y, rect.Z + CGraphics.ZOffset); + GL.End(); - GL.Begin(BeginMode.Quads); - GL.Vertex3(rect.X, rect.Y, rect.Z + CGraphics.ZOffset); - GL.Vertex3(rect.X, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); - GL.Vertex3(rect.X + rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); - GL.Vertex3(rect.X + rect.W, rect.Y, rect.Z + CGraphics.ZOffset); - GL.End(); - - GL.Disable(EnableCap.Blend); - } - GL.EndList(); + GL.Disable(EnableCap.Blend); } #endregion Basic Draw Methods @@ -1125,104 +1109,97 @@ namespace Vocaluxe.Lib.Draw if (_TextureExists(ref Texture)) { - int list = GL.GenLists(1); - _GLList.Add(list); + GL.BindTexture(TextureTarget.Texture2D, Texture.ID); - GL.NewList(list, ListMode.Compile); + float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; + float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; + float y1 = (bounds.Y - rect.Y) / rect.H * Texture.height_ratio; + float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; + + if (x1 < 0) + x1 = 0f; + + if (x2 > Texture.width_ratio) + x2 = Texture.width_ratio; + + if (y1 < 0) + y1 = 0f; + + if (y2 > Texture.height_ratio) + y2 = Texture.height_ratio; + + + float rx1 = rect.X; + float rx2 = rect.X + rect.W; + float ry1 = rect.Y; + float ry2 = rect.Y + rect.H; + + if (rx1 < bounds.X) + rx1 = bounds.X; + + if (rx2 > bounds.X + bounds.W) + rx2 = bounds.X + bounds.W; + + if (ry1 < bounds.Y) + ry1 = bounds.Y; + + if (ry2 > bounds.Y + bounds.H) + ry2 = bounds.Y + bounds.H; + + GL.Enable(EnableCap.Blend); + GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); + + GL.MatrixMode(MatrixMode.Texture); + GL.PushMatrix(); + + if (rect.Rotation != 0f) { - GL.BindTexture(TextureTarget.Texture2D, Texture.ID); - - float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; - float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; - float y1 = (bounds.Y - rect.Y) / rect.H * Texture.height_ratio; - float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; - - if (x1 < 0) - x1 = 0f; - - if (x2 > Texture.width_ratio) - x2 = Texture.width_ratio; - - if (y1 < 0) - y1 = 0f; - - if (y2 > Texture.height_ratio) - y2 = Texture.height_ratio; - - - float rx1 = rect.X; - float rx2 = rect.X + rect.W; - float ry1 = rect.Y; - float ry2 = rect.Y + rect.H; - - if (rx1 < bounds.X) - rx1 = bounds.X; - - if (rx2 > bounds.X + bounds.W) - rx2 = bounds.X + bounds.W; - - if (ry1 < bounds.Y) - ry1 = bounds.Y; - - if (ry2 > bounds.Y + bounds.H) - ry2 = bounds.Y + bounds.H; - - GL.Enable(EnableCap.Blend); - GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); - - GL.MatrixMode(MatrixMode.Texture); - GL.PushMatrix(); - - if (rect.Rotation != 0f) - { - GL.Translate(0.5f, 0.5f, 0); - GL.Rotate(-rect.Rotation, 0f, 0f, 1f); - GL.Translate(-0.5f, -0.5f, 0); - } - - if (!mirrored) - { - GL.Begin(BeginMode.Quads); - - GL.TexCoord2(x1, y1); - GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset); - - GL.TexCoord2(x1, y2); - GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset); - - GL.TexCoord2(x2, y2); - GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset); - - GL.TexCoord2(x2, y1); - GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset); - - GL.End(); - } - else - { - GL.Begin(BeginMode.Quads); - - GL.TexCoord2(x2, y2); - GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset); - - GL.TexCoord2(x2, y1); - GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset); - - GL.TexCoord2(x1, y1); - GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset); - - GL.TexCoord2(x1, y2); - GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset); - - GL.End(); - } - - GL.PopMatrix(); - - GL.Disable(EnableCap.Blend); - GL.BindTexture(TextureTarget.Texture2D, 0); + GL.Translate(0.5f, 0.5f, 0); + GL.Rotate(-rect.Rotation, 0f, 0f, 1f); + GL.Translate(-0.5f, -0.5f, 0); } - GL.EndList(); + + if (!mirrored) + { + GL.Begin(BeginMode.Quads); + + GL.TexCoord2(x1, y1); + GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset); + + GL.TexCoord2(x1, y2); + GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset); + + GL.TexCoord2(x2, y2); + GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset); + + GL.TexCoord2(x2, y1); + GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset); + + GL.End(); + } + else + { + GL.Begin(BeginMode.Quads); + + GL.TexCoord2(x2, y2); + GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset); + + GL.TexCoord2(x2, y1); + GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset); + + GL.TexCoord2(x1, y1); + GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset); + + GL.TexCoord2(x1, y2); + GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset); + + GL.End(); + } + + GL.PopMatrix(); + + GL.Disable(EnableCap.Blend); + GL.BindTexture(TextureTarget.Texture2D, 0); } } @@ -1230,38 +1207,31 @@ namespace Vocaluxe.Lib.Draw { if (_TextureExists(ref Texture)) { - int list = GL.GenLists(1); - _GLList.Add(list); + GL.BindTexture(TextureTarget.Texture2D, Texture.ID); - GL.NewList(list, ListMode.Compile); - { - GL.BindTexture(TextureTarget.Texture2D, Texture.ID); - - GL.Enable(EnableCap.Blend); - GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); + GL.Enable(EnableCap.Blend); + GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); - GL.Begin(BeginMode.Quads); + GL.Begin(BeginMode.Quads); - GL.TexCoord2(0f + begin * Texture.width_ratio, 0f); - GL.Vertex3(rect.X + begin * rect.W, rect.Y, rect.Z + CGraphics.ZOffset); + GL.TexCoord2(0f + begin * Texture.width_ratio, 0f); + GL.Vertex3(rect.X + begin * rect.W, rect.Y, rect.Z + CGraphics.ZOffset); - GL.TexCoord2(0f + begin * Texture.width_ratio, Texture.height_ratio); - GL.Vertex3(rect.X + begin * rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); + GL.TexCoord2(0f + begin * Texture.width_ratio, Texture.height_ratio); + GL.Vertex3(rect.X + begin * rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); - GL.TexCoord2(Texture.width_ratio * end, Texture.height_ratio); - GL.Vertex3(rect.X + end * rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); + GL.TexCoord2(Texture.width_ratio * end, Texture.height_ratio); + GL.Vertex3(rect.X + end * rect.W, rect.Y + rect.H, rect.Z + CGraphics.ZOffset); - GL.TexCoord2(Texture.width_ratio * end, 0f); - GL.Vertex3(rect.X + end * rect.W, rect.Y, rect.Z + CGraphics.ZOffset); + GL.TexCoord2(Texture.width_ratio * end, 0f); + GL.Vertex3(rect.X + end * rect.W, rect.Y, rect.Z + CGraphics.ZOffset); - GL.End(); + GL.End(); - GL.Disable(EnableCap.Blend); - GL.BindTexture(TextureTarget.Texture2D, 0); - } - GL.EndList(); + GL.Disable(EnableCap.Blend); + GL.BindTexture(TextureTarget.Texture2D, 0); } } @@ -1281,88 +1251,81 @@ namespace Vocaluxe.Lib.Draw if (_TextureExists(ref Texture)) { - int list = GL.GenLists(1); - _GLList.Add(list); + GL.BindTexture(TextureTarget.Texture2D, Texture.ID); - GL.NewList(list, ListMode.Compile); + float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; + float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; + float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * Texture.height_ratio; + float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; + + if (x1 < 0) + x1 = 0f; + + if (x2 > Texture.width_ratio) + x2 = Texture.width_ratio; + + if (y1 < 0) + y1 = 0f; + + if (y2 > Texture.height_ratio) + y2 = Texture.height_ratio; + + + float rx1 = rect.X; + float rx2 = rect.X + rect.W; + float ry1 = rect.Y + rect.H + space; + float ry2 = rect.Y + rect.H + space + height; + + if (rx1 < bounds.X) + rx1 = bounds.X; + + if (rx2 > bounds.X + bounds.W) + rx2 = bounds.X + bounds.W; + + if (ry1 < bounds.Y + space) + ry1 = bounds.Y + space; + + if (ry2 > bounds.Y + bounds.H + space + height) + ry2 = bounds.Y + bounds.H + space + height; + + GL.Enable(EnableCap.Blend); + + GL.MatrixMode(MatrixMode.Texture); + GL.PushMatrix(); + + if (rect.Rotation != 0f) { - GL.BindTexture(TextureTarget.Texture2D, Texture.ID); - - float x1 = (bounds.X - rect.X) / rect.W * Texture.width_ratio; - float x2 = (bounds.X + bounds.W - rect.X) / rect.W * Texture.width_ratio; - float y1 = (bounds.Y - rect.Y + rect.H - height) / rect.H * Texture.height_ratio; - float y2 = (bounds.Y + bounds.H - rect.Y) / rect.H * Texture.height_ratio; - - if (x1 < 0) - x1 = 0f; - - if (x2 > Texture.width_ratio) - x2 = Texture.width_ratio; - - if (y1 < 0) - y1 = 0f; - - if (y2 > Texture.height_ratio) - y2 = Texture.height_ratio; - - - float rx1 = rect.X; - float rx2 = rect.X + rect.W; - float ry1 = rect.Y + rect.H + space; - float ry2 = rect.Y + rect.H + space + height; - - if (rx1 < bounds.X) - rx1 = bounds.X; - - if (rx2 > bounds.X + bounds.W) - rx2 = bounds.X + bounds.W; - - if (ry1 < bounds.Y + space) - ry1 = bounds.Y + space; - - if (ry2 > bounds.Y + bounds.H + space + height) - ry2 = bounds.Y + bounds.H + space + height; - - GL.Enable(EnableCap.Blend); - - GL.MatrixMode(MatrixMode.Texture); - GL.PushMatrix(); - - if (rect.Rotation != 0f) - { - GL.Translate(0.5f, 0.5f, 0); - GL.Rotate(-rect.Rotation, 0f, 0f, 1f); - GL.Translate(-0.5f, -0.5f, 0); - } - - - GL.Begin(BeginMode.Quads); - - GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); - GL.TexCoord2(x2, y2); - GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset); - - GL.Color4(color.R, color.G, color.B, 0f); - GL.TexCoord2(x2, y1); - GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset); - - GL.Color4(color.R, color.G, color.B, 0f); - GL.TexCoord2(x1, y1); - GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset); - - GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); - GL.TexCoord2(x1, y2); - GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset); - - GL.End(); - - - GL.PopMatrix(); - - GL.Disable(EnableCap.Blend); - GL.BindTexture(TextureTarget.Texture2D, 0); + GL.Translate(0.5f, 0.5f, 0); + GL.Rotate(-rect.Rotation, 0f, 0f, 1f); + GL.Translate(-0.5f, -0.5f, 0); } - GL.EndList(); + + + GL.Begin(BeginMode.Quads); + + GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); + GL.TexCoord2(x2, y2); + GL.Vertex3(rx2, ry1, rect.Z + CGraphics.ZOffset); + + GL.Color4(color.R, color.G, color.B, 0f); + GL.TexCoord2(x2, y1); + GL.Vertex3(rx2, ry2, rect.Z + CGraphics.ZOffset); + + GL.Color4(color.R, color.G, color.B, 0f); + GL.TexCoord2(x1, y1); + GL.Vertex3(rx1, ry2, rect.Z + CGraphics.ZOffset); + + GL.Color4(color.R, color.G, color.B, color.A * CGraphics.GlobalAlpha); + GL.TexCoord2(x1, y2); + GL.Vertex3(rx1, ry1, rect.Z + CGraphics.ZOffset); + + GL.End(); + + + GL.PopMatrix(); + + GL.Disable(EnableCap.Blend); + GL.BindTexture(TextureTarget.Texture2D, 0); } } From 3f2b83d0c663fe127113031ab99834cd6323ce05 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Fri, 16 Mar 2012 20:15:53 +0100 Subject: [PATCH 28/38] set default audio latency to 0ms --- Vocaluxe/Base/CConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vocaluxe/Base/CConfig.cs b/Vocaluxe/Base/CConfig.cs index 87d16531..b4512ecc 100644 --- a/Vocaluxe/Base/CConfig.cs +++ b/Vocaluxe/Base/CConfig.cs @@ -191,7 +191,7 @@ namespace Vocaluxe.Base public static EPlaybackLib PlayBackLib = EPlaybackLib.PortAudio; public static ERecordLib RecordLib = ERecordLib.PortAudio; public static EBufferSize AudioBufferSize = EBufferSize.b2048; - public static int AudioLatency = 125; + public static int AudioLatency = 0; public static int BackgroundMusicVolume = 50; public static EOffOn BackgroundMusic = EOffOn.TR_CONFIG_ON; public static EBackgroundMusicSource BackgroundMusicSource = EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC; From f20a1496179613c89942df1a2c4c403be35ae66a Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Fri, 16 Mar 2012 20:54:35 +0100 Subject: [PATCH 29/38] some small improvements in text drawing --- Vocaluxe/Base/CFont.cs | 14 +++++++++++++- Vocaluxe/Lib/Draw/COpenGL.cs | 2 +- Vocaluxe/Menu/CText.cs | 19 ++++++------------- Vocaluxe/Screens/CScreenMain.cs | 4 ++++ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Vocaluxe/Base/CFont.cs b/Vocaluxe/Base/CFont.cs index ab6e7157..96807202 100644 --- a/Vocaluxe/Base/CFont.cs +++ b/Vocaluxe/Base/CFont.cs @@ -12,6 +12,7 @@ using System.Xml; using System.Xml.XPath; using Vocaluxe.Lib.Draw; +using Vocaluxe.Menu; namespace Vocaluxe.Base { @@ -551,7 +552,18 @@ namespace Vocaluxe.Base } } } - + + public static RectangleF GetTextBounds(CText text) + { + return GetTextBounds(text, text.Height); + } + + public static RectangleF GetTextBounds(CText text, float height) + { + Height = height; + return new RectangleF(text.X, text.Y, GetTextWidth(CLanguage.Translate(text.Text)), GetTextHeight(CLanguage.Translate(text.Text))); + } + public static float GetTextWidth(string text) { float dx = 0; diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 18896f52..06a9709b 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -511,7 +511,7 @@ namespace Vocaluxe.Lib.Draw CFonts.Height = Height; CFonts.SetFont(text.Fon); CFonts.Style = text.Style; - return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(text.Text)); + return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(CLanguage.Translate(text.Text))); } #region Basic Draw Methods diff --git a/Vocaluxe/Menu/CText.cs b/Vocaluxe/Menu/CText.cs index c0c95948..a9cf369c 100644 --- a/Vocaluxe/Menu/CText.cs +++ b/Vocaluxe/Menu/CText.cs @@ -394,15 +394,18 @@ namespace Vocaluxe.Menu if (!ForceDraw && !Visible && CSettings.GameState != EGameState.EditTheme) return; + CFonts.SetFont(Fon); + CFonts.Style = Style; + float h = Height; float y = Y; - RectangleF bounds = CDraw.GetTextBounds(this); + RectangleF bounds = CFonts.GetTextBounds(this); while (bounds.Width > Bounds.W) { h -= 0.2f; y += 0.1f; - bounds = CDraw.GetTextBounds(this, h); + bounds = CFonts.GetTextBounds(this, h); } float x = X; @@ -424,8 +427,7 @@ namespace Vocaluxe.Menu SColorF color = new SColorF(CurrentColor.R, CurrentColor.G, CurrentColor.B, CurrentColor.A * Alpha); - CFonts.SetFont(Fon); - CFonts.Style = Style; + CFonts.DrawText(CLanguage.Translate(Text), h, x, y, Z, color); if (Reflection) @@ -437,9 +439,6 @@ namespace Vocaluxe.Menu { CDraw.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f * CGraphics.GlobalAlpha), new SRectF(x, y, bounds.Width, bounds.Height, Z)); } - - CFonts.SetFont("Normal"); - CFonts.Style = EStyle.Normal; } public void Draw(float begin, float end) @@ -478,9 +477,6 @@ namespace Vocaluxe.Menu { CDraw.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f), new SRectF(x, Y, bounds.Width, bounds.Height, Z)); } - - CFonts.SetFont("Normal"); - CFonts.Style = EStyle.Normal; } public void DrawRelative(float x, float y) @@ -542,9 +538,6 @@ namespace Vocaluxe.Menu { CDraw.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f * CGraphics.GlobalAlpha), new SRectF(x, y, bounds.Width, bounds.Height, Z)); } - - CFonts.SetFont("Normal"); - CFonts.Style = EStyle.Normal; } public void UnloadTextures() diff --git a/Vocaluxe/Screens/CScreenMain.cs b/Vocaluxe/Screens/CScreenMain.cs index 14c0840c..e558cf24 100644 --- a/Vocaluxe/Screens/CScreenMain.cs +++ b/Vocaluxe/Screens/CScreenMain.cs @@ -140,7 +140,11 @@ namespace Vocaluxe.Screens base.DrawFG(); if (CSettings.VersionRevision != ERevision.Release) + { + CFonts.SetFont("Normal"); + CFonts.Style = EStyle.Normal; CDraw.DrawText(CSettings.GetFullVersionText(), 10, 680, 40); + } return true; } From aca6087488ef76ddf517522818abe89266d92c64 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Fri, 16 Mar 2012 21:14:44 +0100 Subject: [PATCH 30/38] fixed TextBounds check in d3d and winform --- Vocaluxe/Lib/Draw/CDirect3D.cs | 2 +- Vocaluxe/Lib/Draw/CDrawWinForm.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 3bf614d5..68e62185 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -520,7 +520,7 @@ namespace Vocaluxe.Lib.Draw CFonts.Height = Height; CFonts.SetFont(text.Fon); CFonts.Style = text.Style; - return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(text.Text)); + return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(CLanguage.Translate(text.Text))); } #region Basic Draw Methods diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index 702fcc57..c0779426 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -256,7 +256,7 @@ namespace Vocaluxe.Lib.Draw CFonts.Height = Height; CFonts.SetFont(text.Fon); CFonts.Style = text.Style; - return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(text.Text)); + return new RectangleF(text.X, text.Y, CFonts.GetTextWidth(CLanguage.Translate(text.Text)), CFonts.GetTextHeight(CLanguage.Translate(text.Text))); } public void ClearScreen() From 35205451389507fad492a1368d30cd001188c650 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Fri, 16 Mar 2012 22:00:23 +0100 Subject: [PATCH 31/38] deactivated JumpTo (it has a bug and should be for version 0.2) --- Vocaluxe/Screens/CScreenSong.cs | 66 +++++++++++++++++---------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/Vocaluxe/Screens/CScreenSong.cs b/Vocaluxe/Screens/CScreenSong.cs index 68865476..42fb3b06 100644 --- a/Vocaluxe/Screens/CScreenSong.cs +++ b/Vocaluxe/Screens/CScreenSong.cs @@ -54,9 +54,16 @@ namespace Vocaluxe.Screens { base.HandleInput(KeyEvent); - if (KeyEvent.KeyPressed && !Char.IsControl(KeyEvent.Unicode) && _SearchActive) + if (KeyEvent.KeyPressed && !Char.IsControl(KeyEvent.Unicode)) { - ApplyNewSearchFilter(_SearchText + KeyEvent.Unicode); + if (_SearchActive) + ApplyNewSearchFilter(_SearchText + KeyEvent.Unicode); + /* + else if (!Char.IsControl(KeyEvent.Unicode)) + { + JumpTo(KeyEvent.Unicode); + return true; + }*/ } else { @@ -65,12 +72,6 @@ namespace Vocaluxe.Screens if (KeyEvent.Handled) return true; - if (!Char.IsControl(KeyEvent.Unicode)) - { - JumpTo(KeyEvent.Unicode); - return true; - } - switch (KeyEvent.Key) { case Keys.Escape: @@ -107,31 +108,31 @@ namespace Vocaluxe.Screens } break; - //case Keys.A: - // if (!_SearchActive && KeyEvent.Mod == Modifier.None) - // { - // StartRandomAllSongs(); - // } - // if (KeyEvent.Mod == Modifier.Ctrl) - // { - // StartRandomVisibleSongs(); - // } - // break; + case Keys.A: + if (!_SearchActive && KeyEvent.Mod == Modifier.None) + { + StartRandomAllSongs(); + } + if (KeyEvent.Mod == Modifier.Ctrl) + { + StartRandomVisibleSongs(); + } + break; - //case Keys.F: - // if (KeyEvent.Mod == Modifier.Ctrl){ - // if (_SearchActive) - // { - // _SearchActive = false; - // _SearchText = String.Empty; - // ApplyNewSearchFilter(_SearchText); - // } - // else - // { - // _SearchActive = true; - // } - // } - // break; + case Keys.F: + if (KeyEvent.Mod == Modifier.Ctrl){ + if (_SearchActive) + { + _SearchActive = false; + _SearchText = String.Empty; + ApplyNewSearchFilter(_SearchText); + } + else + { + _SearchActive = true; + } + } + break; case Keys.R: if (CSongs.Category != -1 && KeyEvent.Mod == Modifier.Ctrl) @@ -303,6 +304,7 @@ namespace Vocaluxe.Screens id = CSongs.VisibleSongs[song].ID; } + // here is a fault: SetSelectedSong should point to the visible index Vocaluxe.Lib.Song.CSong s = Array.Find(CSongs.VisibleSongs, element => element.Artist.StartsWith(Letter.ToString(), StringComparison.OrdinalIgnoreCase)); if (s != null && s.ID > -1) { From 3b40111a1ebb583e520832428fc11376a28c7e53 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Fri, 16 Mar 2012 22:00:52 +0100 Subject: [PATCH 32/38] fixed text width test in screen credits --- Vocaluxe/Screens/CScreenCredits.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index 6f58a3e6..e1b988b4 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -259,7 +259,7 @@ namespace Vocaluxe.Screens { string newline = line + " " + paragraphs[i][e]; CText text = new CText(75, lastY, -2, 30, -1, EAlignment.Left, EStyle.Bold, "Outline", new SColorF(1, 1, 1, 1), line); - if (CDraw.GetTextBounds(text).Width < (CSettings.iRenderW - 200)) + if (CDraw.GetTextBounds(text).Width < (CSettings.iRenderW - 220)) { line = line + " " + paragraphs[i][e]; From cb153e50738b6327697628921e764f33104fb786 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Fri, 16 Mar 2012 22:35:44 +0100 Subject: [PATCH 33/38] update to build 0055 --- Vocaluxe/Base/CSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vocaluxe/Base/CSettings.cs b/Vocaluxe/Base/CSettings.cs index 40d2a062..d17bc699 100644 --- a/Vocaluxe/Base/CSettings.cs +++ b/Vocaluxe/Base/CSettings.cs @@ -47,7 +47,7 @@ namespace Vocaluxe.Base public const int iVersionSub = 0; // steps public const ERevision VersionRevision = ERevision.Beta; - public const int iBuild = 54; // Increase on every published version! Never Reset! + public const int iBuild = 55; // Increase on every published version! Never Reset! public const int iDatabaseHighscoreVersion = 1; public const int iDatabaseCoverVersion = 1; From 4cd4ccd1f11c3cd33cba66763e1c4807e5712344 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sat, 17 Mar 2012 09:51:19 +0100 Subject: [PATCH 34/38] some optimizations in CText.cs --- Vocaluxe/Menu/CText.cs | 300 +++++++++++++++++++++++++++++++++-------- 1 file changed, 246 insertions(+), 54 deletions(-) diff --git a/Vocaluxe/Menu/CText.cs b/Vocaluxe/Menu/CText.cs index a9cf369c..c9bb0ea1 100644 --- a/Vocaluxe/Menu/CText.cs +++ b/Vocaluxe/Menu/CText.cs @@ -14,27 +14,164 @@ namespace Vocaluxe.Menu { public string Name; + public string Text; public string ColorName; public string SColorName; //for Buttons } + struct STextPosition + { + public float X; + public float Y; + public float tH; + public float Width; + public float Height; + + public STextPosition(int dummy) + { + X = 0f; + Y = 0f; + tH = 0f; + Width = 0f; + Height = 0f; + } + } + class CText : IMenuElement { private SThemeText _Theme; private bool _ThemeLoaded; private bool _ButtonText; + private bool _PositionNeedsUpdate = true; - public float X; //left - public float Y; //higher - public float Z; - public float Height; - public float MaxWidth; - public SRectF Bounds; + private STextPosition _DrawPosition = new STextPosition(0); - public EAlignment Align; - public EStyle Style; - public string Fon; - + private float _X = 0f; + public float X //left + { + get { return _X; } + set + { + if (_X != value) + { + _X = value; + _PositionNeedsUpdate = true; + } + } + } + + private float _Y = 0f; + public float Y //higher + { + get { return _Y; } + set + { + if (_Y != value) + { + _Y = value; + _PositionNeedsUpdate = true; + } + } + } + + private float _Z = 0f; + public float Z + { + get { return _Z; } + set + { + if (_Z != value) + { + _Z = value; + _PositionNeedsUpdate = true; + } + } + } + + private float _Height = 0f; + public float Height + { + get { return _Height; } + set + { + if (_Height != value) + { + _Height = value; + _PositionNeedsUpdate = true; + } + } + } + + private float _MaxWidth = 0f; + public float MaxWidth + { + get { return _MaxWidth; } + set + { + if (_MaxWidth != value) + { + _MaxWidth = value; + _PositionNeedsUpdate = true; + } + } + } + + private SRectF _Bounds = new SRectF(); + public SRectF Bounds + { + get { return _Bounds; } + set + { + if (_Bounds.X != value.X || _Bounds.Y != value.Y || _Bounds.W != value.W || _Bounds.H != value.H || _Bounds.Z != value.Z) + { + _Bounds = value; + _PositionNeedsUpdate = true; + } + } + } + + private EAlignment _Align = EAlignment.Left; + public EAlignment Align + { + get { return _Align; } + set + { + if (_Align != value) + { + _Align = value; + _PositionNeedsUpdate = true; + } + } + } + + private EStyle _Style = EStyle.Normal; + public EStyle Style + { + get { return _Style; } + set + { + if (_Style != value) + { + _Style = value; + _PositionNeedsUpdate = true; + } + } + } + + private string _Fon = String.Empty; + public string Fon + { + get { return _Fon; } + set + { + if (_Fon != value) + { + _Fon = value; + _PositionNeedsUpdate = true; + } + } + } + public SColorF Color; //normal Color public SColorF SColor; //selected Color for Buttons @@ -42,7 +179,22 @@ namespace Vocaluxe.Menu public float ReflectionSpace; public float ReflectionHeight; - public string Text; + private string _Text = String.Empty; + public string Text + { + get { return _Theme.Text; } + set + { + string translation = CLanguage.Translate(value); + if (_Theme.Text != value || translation != _Text) + { + _Theme.Text = value; + _Text = translation; + _PositionNeedsUpdate = true; + } + } + } + public bool Selected; public bool Visible = true; @@ -94,7 +246,7 @@ namespace Vocaluxe.Menu Color = new SColorF(r, g, b, a); SColor = new SColorF(r, g, b, a); - text = Text; + Text = text; Selected = false; @@ -130,7 +282,7 @@ namespace Vocaluxe.Menu Color = new SColorF(r, g, b, a); SColor = new SColorF(r, g, b, a); - text = Text; + Text = text; Selected = false; @@ -226,14 +378,14 @@ namespace Vocaluxe.Menu string item = XmlPath + "/" + ElementName; _ThemeLoaded = true; - _ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/X", navigator, ref X); - _ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/Y", navigator, ref Y); + _ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/X", navigator, ref _X); + _ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/Y", navigator, ref _Y); if (!ButtonText) - _ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/Z", navigator, ref Z); + _ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/Z", navigator, ref _Z); - _ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/H", navigator, ref Height); - CHelper.TryGetFloatValueFromXML(item + "/MaxW", navigator, ref MaxWidth); + _ThemeLoaded &= CHelper.TryGetFloatValueFromXML(item + "/H", navigator, ref _Height); + CHelper.TryGetFloatValueFromXML(item + "/MaxW", navigator, ref _MaxWidth); if (CHelper.GetValueFromXML(item + "/Color", navigator, ref _Theme.ColorName, String.Empty)) { @@ -261,11 +413,11 @@ namespace Vocaluxe.Menu } } - _ThemeLoaded &= CHelper.TryGetEnumValueFromXML(item + "/Align", navigator, ref Align); - _ThemeLoaded &= CHelper.TryGetEnumValueFromXML(item + "/Style", navigator, ref Style); - _ThemeLoaded &= CHelper.GetValueFromXML(item + "/Font", navigator, ref Fon, "Normal"); + _ThemeLoaded &= CHelper.TryGetEnumValueFromXML(item + "/Align", navigator, ref _Align); + _ThemeLoaded &= CHelper.TryGetEnumValueFromXML(item + "/Style", navigator, ref _Style); + _ThemeLoaded &= CHelper.GetValueFromXML(item + "/Font", navigator, ref _Fon, "Normal"); - _ThemeLoaded &= CHelper.GetValueFromXML(item + "/Text", navigator, ref Text, String.Empty); + _ThemeLoaded &= CHelper.GetValueFromXML(item + "/Text", navigator, ref _Theme.Text, String.Empty); if (CHelper.ItemExistsInXML(item + "/Reflection", navigator) && !ButtonText) { @@ -276,6 +428,17 @@ namespace Vocaluxe.Menu else Reflection = false; + // Set values + X = _X; + Y = _Y; + Z = _Z; + Height = _Height; + MaxWidth = _MaxWidth; + Text = _Theme.Text; + Fon = _Fon; + Align = _Align; + Style = _Style; + if (_ThemeLoaded) { _Theme.Name = ElementName; @@ -352,8 +515,8 @@ namespace Vocaluxe.Menu writer.WriteElementString("Font", Fon); writer.WriteComment(": Text or translation tag"); - if (CLanguage.TranslationExists(Text)) - writer.WriteElementString("Text", Text); + if (CLanguage.TranslationExists(_Theme.Text)) + writer.WriteElementString("Text", _Theme.Text); else writer.WriteElementString("Text", string.Empty); @@ -394,50 +557,35 @@ namespace Vocaluxe.Menu if (!ForceDraw && !Visible && CSettings.GameState != EGameState.EditTheme) return; + // Update Text + Text = Text; + + if (_PositionNeedsUpdate) + UpdateTextPosition(); + CFonts.SetFont(Fon); CFonts.Style = Style; - float h = Height; - float y = Y; - RectangleF bounds = CFonts.GetTextBounds(this); - - while (bounds.Width > Bounds.W) - { - h -= 0.2f; - y += 0.1f; - bounds = CFonts.GetTextBounds(this, h); - } - - float x = X; - switch (Align) - { - case EAlignment.Center: - x = X - bounds.Width / 2; - break; - case EAlignment.Right: - x = X - bounds.Width; - break; - default: - break; - } - SColorF CurrentColor = new SColorF(Color); if (Selected) CurrentColor = new SColorF(SColor); SColorF color = new SColorF(CurrentColor.R, CurrentColor.G, CurrentColor.B, CurrentColor.A * Alpha); - - CFonts.DrawText(CLanguage.Translate(Text), h, x, y, Z, color); + + CFonts.DrawText(_Text, _DrawPosition.tH, _DrawPosition.X, _DrawPosition.Y, Z, color); if (Reflection) { - CFonts.DrawTextReflection(CLanguage.Translate(Text), h, x, y, Z, color, ReflectionSpace, ReflectionHeight); + CFonts.DrawTextReflection(_Text, _DrawPosition.tH, _DrawPosition.X, _DrawPosition.Y, Z, color, ReflectionSpace, ReflectionHeight); } if (Selected && (CSettings.GameState == EGameState.EditTheme)) { - CDraw.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f * CGraphics.GlobalAlpha), new SRectF(x, y, bounds.Width, bounds.Height, Z)); + CDraw.DrawColor( + new SColorF(0.5f, 1f, 0.5f, 0.5f * CGraphics.GlobalAlpha), + new SRectF(_DrawPosition.X, _DrawPosition.Y, _DrawPosition.Width, _DrawPosition.Height, Z) + ); } } @@ -491,6 +639,9 @@ namespace Vocaluxe.Menu public void DrawRelative(float rx, float ry, bool reflection, float reflectionSpace, float reflectionHeight, float rectHeight) { + // Update Text + Text = Text; + float h = Height; float x = X + rx; @@ -525,13 +676,13 @@ namespace Vocaluxe.Menu CFonts.SetFont(Fon); CFonts.Style = Style; - CFonts.DrawText(CLanguage.Translate(Text), h, x, y, Z, color); + CFonts.DrawText(_Text, h, x, y, Z, color); if (reflection) { float space = (rectHeight - Y - bounds.Height) * 2f + reflectionSpace; float height = reflectionHeight - (rectHeight - Y) + bounds.Height; - CFonts.DrawTextReflection(CLanguage.Translate(Text), h, x, y, Z, color, space, height); + CFonts.DrawTextReflection(_Text, h, x, y, Z, color, space, height); } if (Selected && (CSettings.GameState == EGameState.EditTheme)) @@ -573,5 +724,46 @@ namespace Vocaluxe.Menu Height = 1; } #endregion ThemeEdit + + private void UpdateTextPosition() + { + if (_Text == String.Empty) + return; + + CFonts.SetFont(Fon); + CFonts.Style = Style; + + float h = Height; + float y = Y; + RectangleF bounds = CFonts.GetTextBounds(this); + + while (bounds.Width > Bounds.W) + { + h -= 0.2f; + y += 0.1f; + bounds = CFonts.GetTextBounds(this, h); + } + + float x = X; + switch (Align) + { + case EAlignment.Center: + x = X - bounds.Width / 2; + break; + case EAlignment.Right: + x = X - bounds.Width; + break; + default: + break; + } + + _DrawPosition.X = x; + _DrawPosition.Y = y; + _DrawPosition.tH = h; + _DrawPosition.Width = bounds.Width; + _DrawPosition.Height = bounds.Height; + + _PositionNeedsUpdate = false; + } } } From 3771cc5dc402d9c0d61b6fb839192b1d4c02db54 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sat, 17 Mar 2012 09:56:26 +0100 Subject: [PATCH 35/38] load notes only one time (thx to rayo) --- Vocaluxe/Lib/Song/CSong.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Vocaluxe/Lib/Song/CSong.cs b/Vocaluxe/Lib/Song/CSong.cs index 1327363b..87ba20e7 100644 --- a/Vocaluxe/Lib/Song/CSong.cs +++ b/Vocaluxe/Lib/Song/CSong.cs @@ -25,6 +25,7 @@ namespace Vocaluxe.Lib.Song class CSong { private bool _CoverLoaded = false; + private bool _NotesLoaded = false; private STexture _CoverTextureSmall = new STexture(-1); private STexture _CoverTextureBig = new STexture(-1); @@ -54,7 +55,9 @@ namespace Vocaluxe.Lib.Song { if (!_CoverLoaded) { - this.ReadNotes(); + if (!_NotesLoaded) + this.ReadNotes(); + if (this.CoverFileName != String.Empty) { if (!CDataBase.GetCover(Path.Combine(this.Folder, this.CoverFileName), ref _CoverTextureSmall, CConfig.CoverSize)) @@ -466,6 +469,7 @@ namespace Vocaluxe.Lib.Song CLog.LogError("Error loading song. Line No.: " + FileLineNo.ToString() + ". An unhandled exception occured (" + e.Message + "): " + FilePath); return false; } + _NotesLoaded = true; return true; } From dfcf9b99af7fc843dec7d51b3c344d1a42748246 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sat, 17 Mar 2012 10:08:59 +0100 Subject: [PATCH 36/38] use queque instead of list for IDs (thx to rayo) --- Vocaluxe/Lib/Draw/COpenGL.cs | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 06a9709b..f12be76d 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -47,7 +47,7 @@ namespace Vocaluxe.Lib.Draw private bool _fullscreen = false; private List _Textures; - private List _IDs; + private Queue _IDs; private List _Queque; private Object MutexTexture = new Object(); @@ -67,11 +67,11 @@ namespace Vocaluxe.Lib.Draw _Textures = new List(); _Queque = new List(); - _IDs = new List(); + _IDs = new Queue(1000000); for (int i = 1; i < 1000000; i++) { - _IDs.Add(i); + _IDs.Enqueue(i); } //Check AA Mode @@ -553,8 +553,7 @@ namespace Vocaluxe.Lib.Draw lock (MutexTexture) { - texture.index = _IDs[0]; - _IDs.RemoveAt(0); + texture.index = _IDs.Dequeue(); _Textures.Add(texture); } @@ -758,10 +757,9 @@ namespace Vocaluxe.Lib.Draw lock (MutexTexture) { - texture.index = _IDs[0]; - _IDs.RemoveAt(0); + texture.index = _IDs.Dequeue(); + _Textures.Add(texture); } - _Textures.Add(texture); return texture; } @@ -823,11 +821,10 @@ namespace Vocaluxe.Lib.Draw lock (MutexTexture) { - texture.index = _IDs[0]; - _IDs.RemoveAt(0); + texture.index = _IDs.Dequeue(); + _Textures.Add(texture); } - _Textures.Add(texture); - + return texture; } @@ -889,11 +886,10 @@ namespace Vocaluxe.Lib.Draw lock (MutexTexture) { - texture.index = _IDs[0]; - _IDs.RemoveAt(0); + texture.index = _IDs.Dequeue(); + _Textures.Add(texture); } - _Textures.Add(texture); - + return texture; } @@ -908,8 +904,7 @@ namespace Vocaluxe.Lib.Draw lock (MutexTexture) { - texture.index = _IDs[0]; - _IDs.RemoveAt(0); + texture.index = _IDs.Dequeue(); queque.ID = texture.index; _Queque.Add(queque); _Textures.Add(texture); @@ -1036,7 +1031,7 @@ namespace Vocaluxe.Lib.Draw { if (_Textures[i].index == Texture.index) { - _IDs.Add(Texture.index); + _IDs.Enqueue(Texture.index); GL.DeleteTexture(Texture.ID); if (Texture.PBO > 0) From 3420cc09725d66eb4fcfaf001a8c475af38d32bd Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sat, 17 Mar 2012 10:09:35 +0100 Subject: [PATCH 37/38] fixed load songs at start options --- Vocaluxe/Base/CSongs.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index a6242d39..a3fc1a6b 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -827,7 +827,7 @@ namespace Vocaluxe.Base Category = -1; _SongsLoaded = true; - if (CConfig.Renderer != ERenderer.TR_CONFIG_SOFTWARE) + if (CConfig.Renderer != ERenderer.TR_CONFIG_SOFTWARE && CConfig.CoverLoading == ECoverLoading.TR_CONFIG_COVERLOADING_ATSTART) { CLog.StartBenchmark(2, "Load Cover"); for (int i = 0; i < _Songs.Count; i++) From ee70a8fa6bcd9d371b64392bf702ab1ffaa249ec Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sat, 17 Mar 2012 11:20:54 +0100 Subject: [PATCH 38/38] some performance changes in CNotes.cs (thx to rayo) --- Vocaluxe/Lib/Song/CNotes.cs | 66 ++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/Vocaluxe/Lib/Song/CNotes.cs b/Vocaluxe/Lib/Song/CNotes.cs index d5ac4dab..c732054e 100644 --- a/Vocaluxe/Lib/Song/CNotes.cs +++ b/Vocaluxe/Lib/Song/CNotes.cs @@ -245,6 +245,8 @@ namespace Vocaluxe.Lib.Song private int _EndBeat; private bool _PerfectLine; // for drawing perfect line effect + private int _MinBeat = int.MaxValue; + private int _MaxBeat = int.MinValue; private List _Notes; #region Constructors @@ -263,14 +265,7 @@ namespace Vocaluxe.Lib.Song get { return _StartBeat; } set { - int min = int.MaxValue; - foreach (CNote note in _Notes) - { - if (note.StartBeat < min) - min = note.StartBeat; - } - - if (value <= min) + if (value <= _MinBeat) _StartBeat = value; } } @@ -280,14 +275,7 @@ namespace Vocaluxe.Lib.Song get { return _EndBeat; } set { - int max = int.MinValue; - foreach (CNote note in _Notes) - { - if (note.EndBeat > max) - max = note.EndBeat; - } - - if (value >= max) + if (value >= _MaxBeat) _EndBeat = value; } } @@ -302,13 +290,7 @@ namespace Vocaluxe.Lib.Song { get { - int Result = int.MaxValue; - foreach (CNote note in _Notes) - { - if (note.StartBeat < Result) - Result = note.StartBeat; - } - return Result; + return _MinBeat; } } @@ -316,13 +298,7 @@ namespace Vocaluxe.Lib.Song { get { - int Result = int.MinValue; - foreach (CNote note in _Notes) - { - if (note.EndBeat > Result) - Result = note.EndBeat; - } - return Result; + return _MaxBeat; } } @@ -429,6 +405,7 @@ namespace Vocaluxe.Lib.Song public void AddNote(CNote Note) { _Notes.Add(Note); + updateMinMaxBeat(Note); } public bool InsertNote(CNote Note, int Index) @@ -436,6 +413,7 @@ namespace Vocaluxe.Lib.Song if (_Notes.Count >= Index) { _Notes.Insert(Index, Note); + updateMinMaxBeat(Note); return true; } return false; @@ -446,6 +424,7 @@ namespace Vocaluxe.Lib.Song if (_Notes.Count > Index) { _Notes.RemoveAt(Index); + updateMinMaxBeat(); return true; } return false; @@ -457,6 +436,7 @@ namespace Vocaluxe.Lib.Song { _Notes.RemoveAt(Index); _Notes.Insert(Index, Note); + updateMinMaxBeat(); return true; } return false; @@ -467,6 +447,7 @@ namespace Vocaluxe.Lib.Song if (_Notes.Count > 0) { _Notes[_Notes.Count - 1].Duration++; + updateMinMaxBeat(); } return false; } @@ -474,6 +455,31 @@ namespace Vocaluxe.Lib.Song public void DeleteAllNotes() { _Notes.Clear(); + _MinBeat = int.MaxValue; + _MaxBeat = int.MinValue; + } + + private void updateMinMaxBeat(CNote Note) + { + if (Note.StartBeat < _MinBeat) + { + _MinBeat = Note.StartBeat; + } + + if (Note.EndBeat > _MaxBeat) + { + _MaxBeat = Note.EndBeat; + } + } + + private void updateMinMaxBeat() + { + _MinBeat = int.MaxValue; + _MaxBeat = int.MinValue; + foreach (CNote note in _Notes) + { + updateMinMaxBeat(note); + } } #endregion Methods }