3 {$INCLUDE ../shared/a_modes.inc}
7 uses LCLIntf
, LCLType
, LMessages
, e_graphics
, utils
;
9 function g_SimpleCreateTextureWAD(var ID
: DWORD
; Resource
: string): Boolean;
10 function g_SimpleCreateTextureWADSize(var ID
: DWORD
; Resource
: string;
11 X
, Y
, Width
, Height
: Word): Boolean;
13 function g_CreateTextureWAD(TextureName
: ShortString
; Resource
: string; flag
: Byte = 0): Boolean;
14 function g_CreateTextureWADSize(TextureName
: ShortString
; Resource
: string;
15 X
, Y
, Width
, Height
: Word; flag
: Byte = 0): Boolean;
16 function g_CreateTextureMemorySize(pData
: Pointer; dataLen
: Integer; Name
: ShortString
; X
, Y
,
17 Width
, Height
: Word; flag
: Byte = 0): Boolean;
19 function g_GetTexture(TextureName
: ShortString
; var ID
: DWORD
): Boolean;
20 function g_GetTextureFlagByName(TextureName
: ShortString
): Byte;
21 function g_GetTextureFlagByID(ID
: DWORD
): Byte;
22 procedure g_GetTextureSizeByName(TextureName
: ShortString
; var Width
, Height
: Word);
23 procedure g_GetTextureSizeByID(ID
: DWORD
; var Width
, Height
: Word);
25 procedure g_DeleteTexture(TextureName
: ShortString
);
26 procedure g_DeleteAllTextures();
31 e_log
, WADEDITOR
, g_basic
, SysUtils
;
42 TexturesArray
: array of _TTexture
= nil;
44 function FindTexture
: DWORD
;
48 if TexturesArray
<> nil then
49 for i
:= 0 to High(TexturesArray
) do
50 if TexturesArray
[i
].Name
= '' then
56 if TexturesArray
= nil then
58 SetLength(TexturesArray
, 8);
63 Result
:= High(TexturesArray
) + 1;
64 SetLength(TexturesArray
, Length(TexturesArray
) + 8);
68 function g_SimpleCreateTextureWAD(var ID
: DWORD
; Resource
: string): Boolean;
75 ResourceLength
: Integer;
78 g_ProcessResourceStr(Resource
, FileName
, SectionName
, ResourceName
);
80 WAD
:= TWADEditor_1
.Create
;
81 WAD
.ReadFile(FileName
);
83 if WAD
.GetResource(utf2win(SectionName
), utf2win(ResourceName
), TextureData
, ResourceLength
) then
85 if e_CreateTextureMem(TextureData
, ResourceLength
, ID
) then Result
:= True;
90 e_WriteLog(Format('Error loading texture %s', [Resource
]), MSG_WARNING
);
91 e_WriteLog(Format('WAD Reader error: %s', [WAD
.GetLastErrorStr
]), MSG_WARNING
);
96 function g_CreateTextureMemorySize(pData
: Pointer; dataLen
: Integer; Name
: ShortString
; X
, Y
,
97 Width
, Height
: Word; flag
: Byte = 0): Boolean;
105 find_id
:= FindTexture
;
107 if not e_CreateTextureMemEx(pData
, dataLen
, TexturesArray
[find_id
].ID
, X
, Y
, Width
, Height
) then
113 TexturesArray
[find_id
].Width
:= Width
;
114 TexturesArray
[find_id
].Height
:= Height
;
115 TexturesArray
[find_id
].Name
:= Name
;
116 TexturesArray
[find_id
].flag
:= flag
;
123 function g_CreateTextureWAD(TextureName
: ShortString
; Resource
: string; flag
: Byte = 0): Boolean;
128 ResourceName
: string;
129 TextureData
: Pointer;
131 ResourceLength
: Integer;
133 g_ProcessResourceStr(Resource
, FileName
, SectionName
, ResourceName
);
135 find_id
:= FindTexture
;
137 WAD
:= TWADEditor_1
.Create
;
138 WAD
.ReadFile(FileName
);
140 if WAD
.GetResource(utf2win(SectionName
), utf2win(ResourceName
), TextureData
, ResourceLength
) then
142 Result
:= e_CreateTextureMem(TextureData
, ResourceLength
, TexturesArray
[find_id
].ID
);
143 FreeMem(TextureData
);
146 e_GetTextureSize(TexturesArray
[find_id
].ID
, @TexturesArray
[find_id
].Width
,
147 @TexturesArray
[find_id
].Height
);
148 TexturesArray
[find_id
].Name
:= TextureName
;
149 TexturesArray
[find_id
].flag
:= flag
;
154 e_WriteLog(Format('Error loading texture %s', [Resource
]), MSG_WARNING
);
155 e_WriteLog(Format('WAD Reader error: %s', [WAD
.GetLastErrorStr
]), MSG_WARNING
);
161 function g_SimpleCreateTextureWADSize(var ID
: DWORD
; Resource
: string; X
, Y
, Width
, Height
: Word): Boolean;
166 ResourceName
: String;
167 TextureData
: Pointer;
168 ResourceLength
: Integer;
171 g_ProcessResourceStr(Resource
, FileName
, SectionName
, ResourceName
);
173 WAD
:= TWADEditor_1
.Create
;
174 WAD
.ReadFile(FileName
);
176 if WAD
.GetResource(utf2win(SectionName
), utf2win(ResourceName
), TextureData
, ResourceLength
) then
178 if e_CreateTextureMemEx(TextureData
, ResourceLength
, ID
, X
, Y
, Width
, Height
) then Result
:= True;
179 FreeMem(TextureData
);
183 e_WriteLog(Format('Error loading texture %s', [Resource
]), MSG_WARNING
);
184 e_WriteLog(Format('WAD Reader error: %s', [WAD
.GetLastErrorStr
]), MSG_WARNING
);
189 function g_CreateTextureWADSize(TextureName
: ShortString
; Resource
: string;
190 X
, Y
, Width
, Height
: Word; flag
: Byte = 0): Boolean;
195 ResourceName
: String;
196 TextureData
: Pointer;
198 ResourceLength
: Integer;
200 g_ProcessResourceStr(Resource
, FileName
, SectionName
, ResourceName
);
202 find_id
:= FindTexture
;
204 WAD
:= TWADEditor_1
.Create
;
205 WAD
.ReadFile(FileName
);
207 if WAD
.GetResource(utf2win(SectionName
), utf2win(ResourceName
), TextureData
, ResourceLength
) then
209 Result
:= e_CreateTextureMemEx(TextureData
, ResourceLength
, TexturesArray
[find_id
].ID
, X
, Y
, Width
, Height
);
210 FreeMem(TextureData
);
213 TexturesArray
[find_id
].Width
:= Width
;
214 TexturesArray
[find_id
].Height
:= Height
;
215 TexturesArray
[find_id
].Name
:= TextureName
;
216 TexturesArray
[find_id
].flag
:= flag
;
221 e_WriteLog(Format('Error loading texture %s', [Resource
]), MSG_WARNING
);
222 e_WriteLog(Format('WAD Reader error: %s', [WAD
.GetLastErrorStr
]), MSG_WARNING
);
228 function g_GetTexture(TextureName
: ShortString
; var ID
: DWORD
): Boolean;
234 if TexturesArray
= nil then Exit
;
236 if TextureName
= '' then Exit
;
238 for a
:= 0 to High(TexturesArray
) do
239 if TexturesArray
[a
].Name
= TextureName
then
241 ID
:= TexturesArray
[a
].ID
;
247 function g_GetTextureFlagByName(TextureName
: ShortString
): Byte;
253 if not g_GetTexture(TextureName
, ID
) then Exit
;
255 Result
:= TexturesArray
[ID
].flag
;
258 function g_GetTextureFlagByID(ID
: DWORD
): Byte;
260 Result
:= TexturesArray
[ID
].flag
;
263 procedure g_GetTextureSizeByName(TextureName
: ShortString
; var Width
, Height
: Word);
270 if not g_GetTexture(TextureName
, ID
) then Exit
;
272 e_GetTextureSize(ID
, @Width
, @Height
);
275 procedure g_GetTextureSizeByID(ID
: DWORD
; var Width
, Height
: Word);
277 e_GetTextureSize(ID
, @Width
, @Height
);
280 procedure g_DeleteTexture(TextureName
: ShortString
);
284 if TexturesArray
= nil then Exit
;
286 for a
:= 0 to High(TexturesArray
) do
287 if TexturesArray
[a
].Name
= TextureName
then
289 e_DeleteTexture(TexturesArray
[a
].ID
);
290 TexturesArray
[a
].Name
:= '';
291 TexturesArray
[a
].ID
:= 0;
292 TexturesArray
[a
].Width
:= 0;
293 TexturesArray
[a
].Height
:= 0;
297 procedure g_DeleteAllTextures
;
301 if TexturesArray
= nil then Exit
;
303 for a
:= 0 to High(TexturesArray
) do
304 if TexturesArray
[a
].Name
<> '' then
305 e_DeleteTexture(TexturesArray
[a
].ID
);
307 TexturesArray
:= nil;