diff options
author | tobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2008-03-31 16:51:40 +0000 |
---|---|---|
committer | tobigun <tobigun@b956fd51-792f-4845-bead-9b4dfca2ff2c> | 2008-03-31 16:51:40 +0000 |
commit | 62c4bbdbc5ddb61836bc6aa57d0cce33ef55e7e5 (patch) | |
tree | fb3adbafe4274be1098278d56dacb680e5879715 /Game/Code/Classes | |
parent | 9dee24b21d397016b0ecb7f37f8774b6b5f658f6 (diff) | |
download | usdx-62c4bbdbc5ddb61836bc6aa57d0cce33ef55e7e5.tar.gz usdx-62c4bbdbc5ddb61836bc6aa57d0cce33ef55e7e5.tar.xz usdx-62c4bbdbc5ddb61836bc6aa57d0cce33ef55e7e5.zip |
Now colorized textures are appended to the TTextureDatabase too. This will prevent USDX from loading textures for buttons, statics etc. multiple times.
This saves approx. 100MB of memory (100MB instead of 200MB, which is still too many) and speeds-up the loading process (starts in 3-6secs now instead of 12secs).
git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@992 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r-- | Game/Code/Classes/UGraphic.pas | 40 | ||||
-rw-r--r-- | Game/Code/Classes/UTexture.pas | 70 |
2 files changed, 74 insertions, 36 deletions
diff --git a/Game/Code/Classes/UGraphic.pas b/Game/Code/Classes/UGraphic.pas index 7af4b724..afb986e1 100644 --- a/Game/Code/Classes/UGraphic.pas +++ b/Game/Code/Classes/UGraphic.pas @@ -278,9 +278,9 @@ begin // zaladowanie tekstur Log.LogStatus('Loading Textures', 'LoadTextures'); - Tex_Left[0] := Texture.LoadTexture(pchar(Skin.GetTextureFileName('GrayLeft')), TEXTURE_TYPE_TRANSPARENT, 0); //brauch man die noch? - Tex_Mid[0] := Texture.LoadTexture(pchar(Skin.GetTextureFileName('GrayMid')), TEXTURE_TYPE_PLAIN, 0); //brauch man die noch? - Tex_Right[0] := Texture.LoadTexture(pchar(Skin.GetTextureFileName('GrayRight')), TEXTURE_TYPE_TRANSPARENT, 0); //brauch man die noch? + Tex_Left[0] := Texture.LoadTexture(Skin.GetTextureFileName('GrayLeft'), TEXTURE_TYPE_TRANSPARENT, 0); //brauch man die noch? + Tex_Mid[0] := Texture.LoadTexture(Skin.GetTextureFileName('GrayMid'), TEXTURE_TYPE_PLAIN, 0); //brauch man die noch? + Tex_Right[0] := Texture.LoadTexture(Skin.GetTextureFileName('GrayRight'), TEXTURE_TYPE_TRANSPARENT, 0); //brauch man die noch? Log.LogStatus('Loading Textures - A', 'LoadTextures'); @@ -292,35 +292,35 @@ begin LoadColor(R, G, B, 'P' + IntToStr(P) + 'Light'); Col := $10000 * Round(R*255) + $100 * Round(G*255) + Round(B*255); - Tex_Left[P] := Texture.LoadTexture(pchar(Skin.GetTextureFileName('GrayLeft')), TEXTURE_TYPE_COLORIZED, Col); - Tex_Mid[P] := Texture.LoadTexture(pchar(Skin.GetTextureFileName('GrayMid')), TEXTURE_TYPE_COLORIZED, Col); - Tex_Right[P] := Texture.LoadTexture(pchar(Skin.GetTextureFileName('GrayRight')), TEXTURE_TYPE_COLORIZED, Col); + Tex_Left[P] := Texture.LoadTexture(Skin.GetTextureFileName('GrayLeft'), TEXTURE_TYPE_COLORIZED, Col); + Tex_Mid[P] := Texture.LoadTexture(Skin.GetTextureFileName('GrayMid'), TEXTURE_TYPE_COLORIZED, Col); + Tex_Right[P] := Texture.LoadTexture(Skin.GetTextureFileName('GrayRight'), TEXTURE_TYPE_COLORIZED, Col); - Tex_plain_Left[P] := Texture.LoadTexture(pchar(Skin.GetTextureFileName('NotePlainLeft')), TEXTURE_TYPE_COLORIZED, Col); - Tex_plain_Mid[P] := Texture.LoadTexture(pchar(Skin.GetTextureFileName('NotePlainMid')), TEXTURE_TYPE_COLORIZED, Col); - Tex_plain_Right[P] := Texture.LoadTexture(pchar(Skin.GetTextureFileName('NotePlainRight')), TEXTURE_TYPE_COLORIZED, Col); + Tex_plain_Left[P] := Texture.LoadTexture(Skin.GetTextureFileName('NotePlainLeft'), TEXTURE_TYPE_COLORIZED, Col); + Tex_plain_Mid[P] := Texture.LoadTexture(Skin.GetTextureFileName('NotePlainMid'), TEXTURE_TYPE_COLORIZED, Col); + Tex_plain_Right[P] := Texture.LoadTexture(Skin.GetTextureFileName('NotePlainRight'), TEXTURE_TYPE_COLORIZED, Col); - Tex_BG_Left[P] := Texture.LoadTexture(pchar(Skin.GetTextureFileName('NoteBGLeft')), TEXTURE_TYPE_COLORIZED, Col); - Tex_BG_Mid[P] := Texture.LoadTexture(pchar(Skin.GetTextureFileName('NoteBGMid')), TEXTURE_TYPE_COLORIZED, Col); - Tex_BG_Right[P] := Texture.LoadTexture(pchar(Skin.GetTextureFileName('NoteBGRight')), TEXTURE_TYPE_COLORIZED, Col); + Tex_BG_Left[P] := Texture.LoadTexture(Skin.GetTextureFileName('NoteBGLeft'), TEXTURE_TYPE_COLORIZED, Col); + Tex_BG_Mid[P] := Texture.LoadTexture(Skin.GetTextureFileName('NoteBGMid'), TEXTURE_TYPE_COLORIZED, Col); + Tex_BG_Right[P] := Texture.LoadTexture(Skin.GetTextureFileName('NoteBGRight'), TEXTURE_TYPE_COLORIZED, Col); end; Log.LogStatus('Loading Textures - B', 'LoadTextures'); - Tex_Note_Perfect_Star := Texture.LoadTexture(pchar(Skin.GetTextureFileName('NotePerfectStar')), TEXTURE_TYPE_TRANSPARENT, 0); - Tex_Note_Star := Texture.LoadTexture(pchar(Skin.GetTextureFileName('NoteStar')) , TEXTURE_TYPE_TRANSPARENT, $FFFFFF); - Tex_Ball := Texture.LoadTexture(pchar(Skin.GetTextureFileName('Ball')), TEXTURE_TYPE_TRANSPARENT, $FF00FF); - Tex_Lyric_Help_Bar := Texture.LoadTexture(pchar(Skin.GetTextureFileName('LyricHelpBar')), TEXTURE_TYPE_TRANSPARENT, $FF00FF); + Tex_Note_Perfect_Star := Texture.LoadTexture(Skin.GetTextureFileName('NotePerfectStar'), TEXTURE_TYPE_TRANSPARENT, 0); + Tex_Note_Star := Texture.LoadTexture(Skin.GetTextureFileName('NoteStar') , TEXTURE_TYPE_TRANSPARENT, $FFFFFF); + Tex_Ball := Texture.LoadTexture(Skin.GetTextureFileName('Ball'), TEXTURE_TYPE_TRANSPARENT, $FF00FF); + Tex_Lyric_Help_Bar := Texture.LoadTexture(Skin.GetTextureFileName('LyricHelpBar'), TEXTURE_TYPE_TRANSPARENT, $FF00FF); //TimeBar mod - Tex_TimeProgress := Texture.LoadTexture(pchar(Skin.GetTextureFileName('TimeBar'))); + Tex_TimeProgress := Texture.LoadTexture(Skin.GetTextureFileName('TimeBar')); //eoa TimeBar mod //SingBar Mod - Tex_SingBar_Back := Texture.LoadTexture(pchar(Skin.GetTextureFileName('SingBarBack')), TEXTURE_TYPE_PLAIN, 0); - Tex_SingBar_Bar := Texture.LoadTexture(pchar(Skin.GetTextureFileName('SingBarBar')), TEXTURE_TYPE_PLAIN, 0); - Tex_SingBar_Front := Texture.LoadTexture(pchar(Skin.GetTextureFileName('SingBarFront')), TEXTURE_TYPE_PLAIN, 0); + Tex_SingBar_Back := Texture.LoadTexture(Skin.GetTextureFileName('SingBarBack'), TEXTURE_TYPE_PLAIN, 0); + Tex_SingBar_Bar := Texture.LoadTexture(Skin.GetTextureFileName('SingBarBar'), TEXTURE_TYPE_PLAIN, 0); + Tex_SingBar_Front := Texture.LoadTexture(Skin.GetTextureFileName('SingBarFront'), TEXTURE_TYPE_PLAIN, 0); //end Singbar Mod Log.LogStatus('Loading Textures - C', 'LoadTextures'); diff --git a/Game/Code/Classes/UTexture.pas b/Game/Code/Classes/UTexture.pas index 603592a6..5b572185 100644 --- a/Game/Code/Classes/UTexture.pas +++ b/Game/Code/Classes/UTexture.pas @@ -68,6 +68,7 @@ type TTextureEntry = record Name: string; Typ: TTextureType; + Color: Cardinal; // we use normal TTexture, it's easier to implement and if needed - we copy ready data Texture: TTexture; @@ -93,14 +94,17 @@ type CreateCacheMipmap: boolean; // function GetNumberFor - function GetTexture(const Name: string; Typ: TTextureType): TTexture; overload; - function GetTexture(const Name: string; Typ: TTextureType; FromCache: boolean): TTexture; overload; - function FindTexture(const Name: string): integer; + function GetTexture(const Name: string; Typ: TTextureType; FromCache: boolean = true): TTexture; overload; + function GetTexture(const Name: string; Typ: TTextureType; Col: LongWord; FromCache: boolean = true): TTexture; overload; + function FindTexture(const Name: string; Typ: TTextureType; Col: Cardinal): integer; function LoadTexture(FromRegistry: boolean; const Identifier: string; Typ: TTextureType; Col: LongWord): TTexture; overload; function LoadTexture(const Identifier: string; Typ: TTextureType; Col: LongWord): TTexture; overload; function LoadTexture(const Identifier: string): TTexture; overload; function CreateTexture(var Data: array of byte; const Name: string; W, H: word; Bits: byte): TTexture; - procedure UnloadTexture(const Name: string; FromCache: boolean); + procedure UnloadTexture(const Name: string; Typ: TTextureType; FromCache: boolean); overload; + procedure UnloadTexture(const Name: string; Typ: TTextureType; Col: Cardinal; FromCache: boolean); overload; + //procedure FlushTextureDatabase(); + Constructor Create; Destructor Destroy; override; end; @@ -745,12 +749,12 @@ begin end; -function TTextureUnit.GetTexture(const Name: string; Typ: TTextureType): TTexture; +function TTextureUnit.GetTexture(const Name: string; Typ: TTextureType; FromCache: boolean): TTexture; begin - Result := GetTexture(Name, Typ, true); + Result := GetTexture(Name, Typ, 0, FromCache); end; -function TTextureUnit.GetTexture(const Name: string; Typ: TTextureType; FromCache: boolean): TTexture; +function TTextureUnit.GetTexture(const Name: string; Typ: TTextureType; Col: LongWord; FromCache: boolean): TTexture; var T: integer; // texture C: integer; // cover @@ -761,7 +765,7 @@ begin exit; // find texture entry - T := FindTexture(Name); + T := FindTexture(Name, Typ, Col); if T = -1 then begin @@ -769,8 +773,9 @@ begin T := Length(TextureDatabase.Texture); SetLength(TextureDatabase.Texture, T+1); - TextureDatabase.Texture[T].Name := Name; - TextureDatabase.Texture[T].Typ := Typ; + TextureDatabase.Texture[T].Name := Name; + TextureDatabase.Texture[T].Typ := Typ; + TextureDatabase.Texture[T].Color := Col; // inform database that no textures have been loaded into memory TextureDatabase.Texture[T].Texture.TexNum := -1; @@ -787,7 +792,7 @@ begin {$ifdef blindydebug} Log.LogStatus('...', 'GetTexture('''+Name+''','''+Typ+''')'); {$endif} - TextureDatabase.Texture[T].Texture := LoadTexture(false, Name, Typ, $0); + TextureDatabase.Texture[T].Texture := LoadTexture(false, Name, Typ, Col); {$ifdef blindydebug} Log.LogStatus('done',' '); {$endif} @@ -814,14 +819,23 @@ begin end; end; -function TTextureUnit.FindTexture(const Name: string): integer; +function TTextureUnit.FindTexture(const Name: string; Typ: TTextureType; Col: Cardinal): integer; var T: integer; // texture begin Result := -1; for T := 0 to high(TextureDatabase.Texture) do - if (TextureDatabase.Texture[T].Name = Name) then - Result := T; + if (TextureDatabase.Texture[T].Name = Name) and + (TextureDatabase.Texture[T].Typ = Typ) then + begin + // colorized textures must match in their color too + if (TextureDatabase.Texture[T].Typ <> TEXTURE_TYPE_COLORIZED) or + (TextureDatabase.Texture[T].Color = Col) then + begin + Result := T; + break; + end; + end; end; function TTextureUnit.LoadTexture(const Identifier: string; Typ: TTextureType; Col: LongWord): TTexture; @@ -886,12 +900,17 @@ begin Result.Name := Name; end; -procedure TTextureUnit.UnloadTexture(const Name: string; FromCache: boolean); +procedure TTextureUnit.UnloadTexture(const Name: string; Typ: TTextureType; FromCache: boolean); +begin + UnloadTexture(Name, Typ, 0, FromCache); +end; + +procedure TTextureUnit.UnloadTexture(const Name: string; Typ: TTextureType; Col: Cardinal; FromCache: boolean); var T: integer; TexNum: integer; begin - T := FindTexture(Name); + T := FindTexture(Name, Typ, Col); if not FromCache then begin TexNum := TextureDatabase.Texture[T].Texture.TexNum; @@ -910,6 +929,25 @@ begin end; end; +(* This needs some work +procedure TTextureUnit.FlushTextureDatabase(); +var + i: integer; + Tex: ^TTexture; +begin + for i := 0 to High(TextureDatabase.Texture) do + begin + // only delete non-cached entries + if (TextureDatabase.Texture[i].Texture.TexNum <> -1) then + begin + Tex := @TextureDatabase.Texture[i].Texture; + glDeleteTextures(1, PGLuint(Tex^.TexNum)); + Tex^.TexNum := -1; + end; + end; +end; +*) + function TextureTypeToStr(TexType: TTextureType): string; begin Result := TextureTypeStr[TexType]; |