1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
23 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
24 e_graphics
, MAPDEF
, ImagingTypes
, Imaging
, ImagingUtility
;
27 TLevelTexture
= record
28 textureName
: AnsiString;
31 false: (textureID
: LongWord);
32 true: (framesID
: LongWord; framesCount
: Byte; speed
: Byte);
35 TLevelTextureArray
= array of TLevelTexture
;
37 TAnimation
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
42 mCounter
: Byte; // Ñ÷åò÷èê îæèäàíèÿ ìåæäó êàäðàìè
43 mSpeed
: Byte; // Âðåìÿ îæèäàíèÿ ìåæäó êàäðàìè
44 mCurrentFrame
: Integer; // Òåêóùèé êàäð (íà÷èíàÿ ñ 0)
45 mLoop
: Boolean; // Ïåðåõîäèòü íà ïåðâûé êàäð ïîñëå ïîñëåäíåãî?
46 mEnabled
: Boolean; // Ðàáîòà ðàçðåøåíà?
47 mPlayed
: Boolean; // Ïðîèãðàíà âñÿ õîòÿ áû ðàç?
50 mMinLength
: Byte; // Îæèäàíèå ïîñëå ïðîèãðûâàíèÿ
51 mRevert
: Boolean; // Ñìåíà êàäðîâ îáðàòíàÿ?
54 constructor Create (aframesID
: LongWord; aloop
: Boolean; aspeed
: Byte);
55 destructor Destroy (); override;
57 procedure draw (x
, y
: Integer; mirror
: TMirrorType
);
58 procedure drawEx (x
, y
: Integer; mirror
: TMirrorType
; rpoint
: TDFPoint
; angle
: SmallInt);
64 procedure revert (r
: Boolean);
66 procedure saveState (st
: TStream
);
67 procedure loadState (st
: TStream
);
69 function totalFrames (): Integer; inline;
72 property played
: Boolean read mPlayed
;
73 property enabled
: Boolean read mEnabled
;
74 property isReverse
: Boolean read mRevert
;
75 property loop
: Boolean read mLoop write mLoop
;
76 property speed
: Byte read mSpeed write mSpeed
;
77 property minLength
: Byte read mMinLength write mMinLength
;
78 property currentFrame
: Integer read mCurrentFrame write mCurrentFrame
;
79 property currentCounter
: Byte read mCounter write mCounter
;
80 property counter
: Byte read mCounter
;
81 property blending
: Boolean read mBlending write mBlending
;
82 property alpha
: Byte read mAlpha write mAlpha
;
83 property framesId
: LongWord read mId
;
84 property width
: Word read mWidth
;
85 property height
: Word read mHeight
;
89 function g_Texture_CreateWAD (var ID
: LongWord; const Resource
: AnsiString): Boolean;
90 function g_Texture_CreateFile (var ID
: LongWord; const FileName
: AnsiString): Boolean;
91 function g_Texture_CreateWADEx (const textureName
, Resource
: AnsiString): Boolean;
92 function g_Texture_CreateFileEx (const textureName
, FileName
: AnsiString): Boolean;
93 function g_Texture_Get (const textureName
: AnsiString; var ID
: LongWord): Boolean;
94 function g_Texture_GetSize (const textureName
: AnsiString; var w
, h
: Integer): Boolean; overload
;
95 function g_Texture_GetSize (ID
: LongWord; var w
, h
: Integer): Boolean; overload
;
96 procedure g_Texture_Delete (const textureName
: AnsiString);
97 procedure g_Texture_DeleteAll ();
99 function g_CreateFramesImg (ia
: TDynImageDataArray
; ID
: PDWORD
; const Name
: AnsiString; BackAnimation
: Boolean=false): Boolean;
101 function g_Frames_CreateWAD (ID
: PDWORD
; const Name
, Resource
: AnsiString; mWidth
, mHeight
, mCount
: Word; BackAnimation
: Boolean=false): Boolean;
102 function g_Frames_CreateFile (ID
: PDWORD
; const Name
, FileName
: AnsiString; mWidth
, mHeight
, mCount
: Word; BackAnimation
: Boolean=false): Boolean;
103 function g_Frames_CreateMemory (ID
: PDWORD
; const Name
: AnsiString; pData
: Pointer; dataSize
: LongInt;
104 mWidth
, mHeight
, mCount
: Word; BackAnimation
: Boolean=false): Boolean;
105 function g_Frames_Dup (const NewName
, OldName
: AnsiString): Boolean;
106 //function g_Frames_CreateRevert(ID: PDWORD; Name: ShortString; Frames: string): Boolean;
107 function g_Frames_Get (out ID
: LongWord; const FramesName
: AnsiString): Boolean;
108 function g_Frames_GetTexture (out ID
: LongWord; const FramesName
: AnsiString; Frame
: Word): Boolean;
109 function g_Frames_Exists (const FramesName
: AnsiString): Boolean;
110 procedure g_Frames_DeleteByName (const FramesName
: AnsiString);
111 procedure g_Frames_DeleteByID (ID
: LongWord);
112 procedure g_Frames_DeleteAll ();
114 procedure DumpTextureNames ();
116 function g_Texture_Light (): Integer;
122 g_game
, e_log
, g_basic
, g_console
, wadreader
,
123 g_language
, GL
, utils
, xstreams
;
134 texturesID
: array of LongWord;
136 frameWidth
, frameHeight
: Word;
141 texturesArray
: array of _TTexture
= nil;
142 framesArray
: array of TFrames
= nil;
146 ANIM_SIGNATURE
= $4D494E41; // 'ANIM'
149 function allocTextureSlot (): LongWord;
153 for f
:= 0 to High(texturesArray
) do
155 if (not texturesArray
[f
].used
) then
162 result
:= Length(texturesArray
);
163 SetLength(texturesArray
, result
+64);
164 for f
:= result
to High(texturesArray
) do
166 with texturesArray
[f
] do
178 function allocFrameSlot (): LongWord;
182 for f
:= 0 to High(framesArray
) do
184 if (not framesArray
[f
].used
) then
191 result
:= Length(framesArray
);
192 SetLength(framesArray
, result
+64);
193 for f
:= result
to High(framesArray
) do
195 with framesArray
[f
] do
207 // ////////////////////////////////////////////////////////////////////////// //
208 function g_Texture_CreateWAD (var ID
: LongWord; const Resource
: AnsiString): Boolean;
211 FileName
: AnsiString;
212 TextureData
: Pointer;
213 ResourceLength
: Integer;
216 FileName
:= g_ExtractWadName(Resource
);
218 WAD
:= TWADFile
.Create
;
219 WAD
.ReadFile(FileName
);
221 if WAD
.GetResource(g_ExtractFilePathName(Resource
), TextureData
, ResourceLength
) then
223 if e_CreateTextureMem(TextureData
, ResourceLength
, ID
) then
229 FreeMem(TextureData
);
234 e_WriteLog(Format('Error loading texture %s', [Resource
]), TMsgType
.Warning
);
235 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
241 function g_Texture_CreateFile (var ID
: LongWord; const FileName
: AnsiString): Boolean;
244 if not e_CreateTexture(FileName
, ID
) then
246 e_WriteLog(Format('Error loading texture %s', [FileName
]), TMsgType
.Warning
);
252 function g_Texture_CreateWADEx (const textureName
, Resource
: AnsiString): Boolean;
255 FileName
: AnsiString;
256 TextureData
: Pointer;
258 ResourceLength
: Integer;
260 FileName
:= g_ExtractWadName(Resource
);
262 find_id
:= allocTextureSlot();
264 WAD
:= TWADFile
.Create
;
265 WAD
.ReadFile(FileName
);
267 if WAD
.GetResource(g_ExtractFilePathName(Resource
), TextureData
, ResourceLength
) then
269 result
:= e_CreateTextureMem(TextureData
, ResourceLength
, texturesArray
[find_id
].ID
);
272 e_GetTextureSize(texturesArray
[find_id
].ID
, @texturesArray
[find_id
].width
, @texturesArray
[find_id
].height
);
273 texturesArray
[find_id
].used
:= true;
274 texturesArray
[find_id
].Name
:= textureName
;
278 FreeMem(TextureData
);
283 e_WriteLog(Format('Error loading texture %s', [Resource
]), TMsgType
.Warning
);
284 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
291 function g_Texture_CreateFileEx (const textureName
, FileName
: AnsiString): Boolean;
295 find_id
:= allocTextureSlot();
296 result
:= e_CreateTexture(FileName
, texturesArray
[find_id
].ID
);
299 texturesArray
[find_id
].used
:= true;
300 texturesArray
[find_id
].Name
:= textureName
;
301 e_GetTextureSize(texturesArray
[find_id
].ID
, @texturesArray
[find_id
].width
, @texturesArray
[find_id
].height
);
303 else e_WriteLog(Format('Error loading texture %s', [FileName
]), TMsgType
.Warning
);
307 function g_Texture_Get (const textureName
: AnsiString; var id
: LongWord): Boolean;
312 if (Length(texturesArray
) = 0) or (Length(textureName
) = 0) then exit
;
313 for a
:= 0 to High(texturesArray
) do
315 if (StrEquCI1251(texturesArray
[a
].name
, textureName
)) then
317 id
:= texturesArray
[a
].id
;
322 //if not Result then g_ConsoleAdd('Texture '+TextureName+' not found');
326 function g_Texture_GetSize (const textureName
: AnsiString; var w
, h
: Integer): Boolean; overload
;
333 if (Length(texturesArray
) = 0) or (Length(textureName
) = 0) then exit
;
334 for a
:= 0 to High(texturesArray
) do
336 if (StrEquCI1251(texturesArray
[a
].name
, textureName
)) then
338 w
:= texturesArray
[a
].width
;
339 h
:= texturesArray
[a
].height
;
347 function g_Texture_GetSize (ID
: LongWord; var w
, h
: Integer): Boolean; overload
;
354 if (Length(texturesArray
) = 0) then exit
;
355 for a
:= 0 to High(texturesArray
) do
357 if (texturesArray
[a
].id
= ID
) then
359 w
:= texturesArray
[a
].width
;
360 h
:= texturesArray
[a
].height
;
368 procedure g_Texture_Delete (const textureName
: AnsiString);
372 if (Length(texturesArray
) = 0) or (Length(textureName
) = 0) then exit
;
373 for a
:= 0 to High(texturesArray
) do
375 if (StrEquCI1251(texturesArray
[a
].name
, textureName
)) then
377 e_DeleteTexture(texturesArray
[a
].ID
);
378 texturesArray
[a
].used
:= false;
379 texturesArray
[a
].name
:= '';
380 texturesArray
[a
].id
:= 0;
381 texturesArray
[a
].width
:= 0;
382 texturesArray
[a
].height
:= 0;
388 procedure g_Texture_DeleteAll ();
392 for a
:= 0 to High(texturesArray
) do
394 if (texturesArray
[a
].used
) then e_DeleteTexture(texturesArray
[a
].ID
);
396 texturesArray
:= nil;
400 function g_Frames_CreateFile (ID
: PDWORD
; const Name
, FileName
: AnsiString;
401 mWidth
, mHeight
, mCount
: Word; BackAnimation
: Boolean = false): Boolean;
408 find_id
:= allocFrameSlot();
410 if (mCount
<= 2) then BackAnimation
:= false;
412 if BackAnimation
then SetLength(framesArray
[find_id
].TexturesID
, mCount
+mCount
-2)
413 else SetLength(framesArray
[find_id
].TexturesID
, mCount
);
415 for a
:= 0 to mCount
-1 do
417 if not e_CreateTextureEx(FileName
, framesArray
[find_id
].TexturesID
[a
], a
*mWidth
, 0, mWidth
, mHeight
) then exit
;
420 if BackAnimation
then
422 for a
:= 1 to mCount
-2 do framesArray
[find_id
].TexturesID
[mCount
+mCount
-2-a
] := framesArray
[find_id
].TexturesID
[a
];
425 framesArray
[find_id
].used
:= true;
426 framesArray
[find_id
].FrameWidth
:= mWidth
;
427 framesArray
[find_id
].FrameHeight
:= mHeight
;
428 if (Name
<> '') then framesArray
[find_id
].Name
:= Name
else framesArray
[find_id
].Name
:= '<noname>';
430 if (ID
<> nil) then ID
^ := find_id
;
436 function CreateFramesMem (pData
: Pointer; dataSize
: LongInt; ID
: PDWORD
; Name
: AnsiString;
437 mWidth
, mHeight
, mCount
: Word; BackAnimation
: Boolean = false): Boolean;
444 find_id
:= allocFrameSlot();
446 if (mCount
<= 2) then BackAnimation
:= false;
448 if BackAnimation
then SetLength(framesArray
[find_id
].TexturesID
, mCount
+mCount
-2)
449 else SetLength(framesArray
[find_id
].TexturesID
, mCount
);
451 for a
:= 0 to mCount
-1 do
452 if not e_CreateTextureMemEx(pData
, dataSize
, framesArray
[find_id
].TexturesID
[a
], a
*mWidth
, 0, mWidth
, mHeight
) then
458 if BackAnimation
then
460 for a
:= 1 to mCount
-2 do framesArray
[find_id
].TexturesID
[mCount
+mCount
-2-a
] := framesArray
[find_id
].TexturesID
[a
];
463 framesArray
[find_id
].used
:= true;
464 framesArray
[find_id
].FrameWidth
:= mWidth
;
465 framesArray
[find_id
].FrameHeight
:= mHeight
;
466 if (Name
<> '') then framesArray
[find_id
].Name
:= Name
else framesArray
[find_id
].Name
:= '<noname>';
468 if (ID
<> nil) then ID
^ := find_id
;
474 function g_CreateFramesImg (ia
: TDynImageDataArray
; ID
: PDWORD
; const Name
: AnsiString; BackAnimation
: Boolean = false): Boolean;
480 find_id
:= allocFrameSlot();
482 mCount
:= Length(ia
);
484 //e_WriteLog(Format('+++ creating %d frames [%s]', [FCount, Name]), MSG_NOTIFY);
486 if (mCount
< 1) then exit
;
487 if (mCount
<= 2) then BackAnimation
:= false;
489 if BackAnimation
then SetLength(framesArray
[find_id
].TexturesID
, mCount
+mCount
-2)
490 else SetLength(framesArray
[find_id
].TexturesID
, mCount
);
492 //e_WriteLog(Format('+++ creating %d frames, %dx%d', [FCount, ia[0].width, ia[0].height]), MSG_NOTIFY);
494 for a
:= 0 to mCount
-1 do
496 if not e_CreateTextureImg(ia
[a
], framesArray
[find_id
].TexturesID
[a
]) then exit
;
497 //e_WriteLog(Format('+++ frame %d, %dx%d', [a, ia[a].width, ia[a].height]), MSG_NOTIFY);
500 if BackAnimation
then
502 for a
:= 1 to mCount
-2 do framesArray
[find_id
].TexturesID
[mCount
+mCount
-2-a
] := framesArray
[find_id
].TexturesID
[a
];
505 framesArray
[find_id
].used
:= true;
506 framesArray
[find_id
].FrameWidth
:= ia
[0].width
;
507 framesArray
[find_id
].FrameHeight
:= ia
[0].height
;
508 if (Name
<> '') then framesArray
[find_id
].Name
:= Name
else framesArray
[find_id
].Name
:= '<noname>';
510 if (ID
<> nil) then ID
^ := find_id
;
516 function g_Frames_CreateWAD (ID
: PDWORD
; const Name
, Resource
: AnsiString;
517 mWidth
, mHeight
, mCount
: Word; BackAnimation
: Boolean=false): Boolean;
520 FileName
: AnsiString;
521 TextureData
: Pointer;
522 ResourceLength
: Integer;
526 // models without "advanced" animations asks for "nothing" like this; don't spam log
527 if (Length(Resource
) > 0) and ((Resource
[Length(Resource
)] = '/') or (Resource
[Length(Resource
)] = '\')) then exit
;
529 FileName
:= g_ExtractWadName(Resource
);
531 WAD
:= TWADFile
.Create();
532 WAD
.ReadFile(FileName
);
534 if not WAD
.GetResource(g_ExtractFilePathName(Resource
), TextureData
, ResourceLength
) then
537 e_WriteLog(Format('Error loading texture %s', [Resource
]), TMsgType
.Warning
);
538 //e_WriteLog(Format('WAD Reader error: %s', [WAD.GetLastErrorStr]), MSG_WARNING);
542 if not CreateFramesMem(TextureData
, ResourceLength
, ID
, Name
, mWidth
, mHeight
, mCount
, BackAnimation
) then
554 function g_Frames_CreateMemory (ID
: PDWORD
; const Name
: AnsiString; pData
: Pointer; dataSize
: LongInt;
555 mWidth
, mHeight
, mCount
: Word; BackAnimation
: Boolean = false): Boolean;
557 result
:= CreateFramesMem(pData
, dataSize
, ID
, Name
, mWidth
, mHeight
, mCount
, BackAnimation
);
561 {function g_Frames_CreateRevert(ID: PDWORD; Name: ShortString; Frames: string): Boolean;
568 if not g_Frames_Get(b, Frames) then Exit;
570 find_id := FindFrame();
572 FramesArray[find_id].Name := Name;
573 FramesArray[find_id].FrameWidth := FramesArray[b].FrameWidth;
574 FramesArray[find_id].FrameHeight := FramesArray[b].FrameHeight;
576 c := High(FramesArray[find_id].TexturesID);
579 FramesArray[find_id].TexturesID[a] := FramesArray[b].TexturesID[c-a];
585 function g_Frames_Dup (const NewName
, OldName
: AnsiString): Boolean;
587 find_id
, b
: LongWord;
592 if not g_Frames_Get(b
, OldName
) then exit
;
594 find_id
:= allocFrameSlot();
596 framesArray
[find_id
].used
:= true;
597 framesArray
[find_id
].Name
:= NewName
;
598 framesArray
[find_id
].FrameWidth
:= framesArray
[b
].FrameWidth
;
599 framesArray
[find_id
].FrameHeight
:= framesArray
[b
].FrameHeight
;
601 c
:= High(framesArray
[b
].TexturesID
);
602 SetLength(framesArray
[find_id
].TexturesID
, c
+1);
604 for a
:= 0 to c
do framesArray
[find_id
].TexturesID
[a
] := framesArray
[b
].TexturesID
[a
];
610 procedure g_Frames_DeleteByName (const FramesName
: AnsiString);
614 if (Length(framesArray
) = 0) then exit
;
615 for a
:= 0 to High(framesArray
) do
617 if (StrEquCI1251(framesArray
[a
].Name
, FramesName
)) then
619 if framesArray
[a
].TexturesID
<> nil then
621 for b
:= 0 to High(framesArray
[a
].TexturesID
) do e_DeleteTexture(framesArray
[a
].TexturesID
[b
]);
623 framesArray
[a
].used
:= false;
624 framesArray
[a
].TexturesID
:= nil;
625 framesArray
[a
].Name
:= '';
626 framesArray
[a
].FrameWidth
:= 0;
627 framesArray
[a
].FrameHeight
:= 0;
633 procedure g_Frames_DeleteByID (ID
: LongWord);
637 if (Length(framesArray
) = 0) then exit
;
638 if (framesArray
[ID
].TexturesID
<> nil) then
640 for b
:= 0 to High(framesArray
[ID
].TexturesID
) do e_DeleteTexture(framesArray
[ID
].TexturesID
[b
]);
642 framesArray
[ID
].used
:= false;
643 framesArray
[ID
].TexturesID
:= nil;
644 framesArray
[ID
].Name
:= '';
645 framesArray
[ID
].FrameWidth
:= 0;
646 framesArray
[ID
].FrameHeight
:= 0;
650 procedure g_Frames_DeleteAll ();
654 for a
:= 0 to High(framesArray
) do
656 if (framesArray
[a
].used
) then
658 for b
:= 0 to High(framesArray
[a
].TexturesID
) do e_DeleteTexture(framesArray
[a
].TexturesID
[b
]);
660 framesArray
[a
].used
:= false;
661 framesArray
[a
].TexturesID
:= nil;
662 framesArray
[a
].Name
:= '';
663 framesArray
[a
].FrameWidth
:= 0;
664 framesArray
[a
].FrameHeight
:= 0;
670 function g_Frames_Get (out ID
: LongWord; const FramesName
: AnsiString): Boolean;
675 if (Length(framesArray
) = 0) then exit
;
676 for a
:= 0 to High(framesArray
) do
678 if (StrEquCI1251(framesArray
[a
].Name
, FramesName
)) then
685 if not result
then g_FatalError(Format(_lc
[I_GAME_ERROR_FRAMES
], [FramesName
]));
689 function g_Frames_GetTexture (out ID
: LongWord; const FramesName
: AnsiString; Frame
: Word): Boolean;
694 if (Length(framesArray
) = 0) then exit
;
695 for a
:= 0 to High(framesArray
) do
697 if (StrEquCI1251(framesArray
[a
].Name
, FramesName
)) then
699 if (Frame
< Length(framesArray
[a
].TexturesID
)) then
701 ID
:= framesArray
[a
].TexturesID
[Frame
];
707 if not result
then g_FatalError(Format(_lc
[I_GAME_ERROR_FRAMES
], [FramesName
]));
711 function g_Frames_Exists (const FramesName
: AnsiString): Boolean;
716 if (Length(framesArray
) = 0) then exit
;
717 for a
:= 0 to High(framesArray
) do
719 if (StrEquCI1251(framesArray
[a
].Name
, FramesName
)) then
728 procedure DumpTextureNames ();
732 e_WriteLog('BEGIN Textures:', TMsgType
.Notify
);
733 for i
:= 0 to High(texturesArray
) do e_WriteLog(' '+IntToStr(i
)+'. '+texturesArray
[i
].Name
, TMsgType
.Notify
);
734 e_WriteLog('END Textures.', TMsgType
.Notify
);
736 e_WriteLog('BEGIN Frames:', TMsgType
.Notify
);
737 for i
:= 0 to High(framesArray
) do e_WriteLog(' '+IntToStr(i
)+'. '+framesArray
[i
].Name
, TMsgType
.Notify
);
738 e_WriteLog('END Frames.', TMsgType
.Notify
);
744 constructor TAnimation
.Create (aframesID
: LongWord; aloop
: Boolean; aspeed
: Byte);
746 if (aframesID
>= Length(framesArray
)) then raise Exception
.Create('trying to create inexisting frame: something is very wrong here');
755 mWidth
:= framesArray
[mId
].FrameWidth
;
756 mHeight
:= framesArray
[mId
].FrameHeight
;
760 destructor TAnimation
.Destroy ();
766 procedure TAnimation
.draw (x
, y
: Integer; mirror
: TMirrorType
);
768 if (not mEnabled
) then exit
;
769 e_DrawAdv(framesArray
[mId
].TexturesID
[mCurrentFrame
], x
, y
, mAlpha
, true, mBlending
, 0, nil, mirror
);
770 //e_DrawQuad(X, Y, X+FramesArray[ID].FrameWidth-1, Y+FramesArray[ID].FrameHeight-1, 0, 255, 0);
774 procedure TAnimation
.update ();
776 if (not mEnabled
) then exit
;
780 if (mCounter
>= mSpeed
) then
782 // Îæèäàíèå ìåæäó êàäðàìè çàêîí÷èëîñü
783 // Îáðàòíûé ïîðÿäîê êàäðîâ?
786 // Äîøëè äî êîíöà àíèìàöèè. Âîçìîæíî, æäåì åùå
787 if (mCurrentFrame
= 0) then
789 if (Length(framesArray
[mId
].TexturesID
)*mSpeed
+mCounter
< mMinLength
) then exit
;
793 mPlayed
:= (mCurrentFrame
< 0);
795 // Ïîâòîðÿòü ëè àíèìàöèþ ïî êðóãó?
798 if mLoop
then mCurrentFrame
:= High(framesArray
[mId
].TexturesID
) else mCurrentFrame
+= 1;
805 // Ïðÿìîé ïîðÿäîê êàäðîâ
806 // Äîøëè äî êîíöà àíèìàöèè. Âîçìîæíî, æäåì åùå
807 if (mCurrentFrame
= High(framesArray
[mId
].TexturesID
)) then
809 if (Length(framesArray
[mId
].TexturesID
)*mSpeed
+mCounter
< mMinLength
) then exit
;
813 mPlayed
:= (mCurrentFrame
> High(framesArray
[mId
].TexturesID
));
815 // Ïîâòîðÿòü ëè àíèìàöèþ ïî êðóãó?
818 if mLoop
then mCurrentFrame
:= 0 else mCurrentFrame
-= 1;
827 procedure TAnimation
.reset ();
829 if mRevert
then mCurrentFrame
:= High(framesArray
[mId
].TexturesID
) else mCurrentFrame
:= 0;
835 procedure TAnimation
.disable (); begin mEnabled
:= false; end;
836 procedure TAnimation
.enable (); begin mEnabled
:= true; end;
839 procedure TAnimation
.drawEx (x
, y
: Integer; mirror
: TMirrorType
; rpoint
: TDFPoint
; angle
: SmallInt);
841 if (not mEnabled
) then exit
;
842 e_DrawAdv(framesArray
[mId
].TexturesID
[mCurrentFrame
], x
, y
, mAlpha
, true, mBlending
, angle
, @rpoint
, mirror
);
846 function TAnimation
.totalFrames (): Integer; inline; begin result
:= Length(framesArray
[mId
].TexturesID
); end;
849 procedure TAnimation
.revert (r
: Boolean);
856 procedure TAnimation
.saveState (st
: TStream
);
858 if (st
= nil) then exit
;
860 utils
.writeSign(st
, 'ANIM');
861 utils
.writeInt(st
, Byte(0)); // version
862 // Ñ÷åò÷èê îæèäàíèÿ ìåæäó êàäðàìè
863 utils
.writeInt(st
, Byte(mCounter
));
865 utils
.writeInt(st
, LongInt(mCurrentFrame
));
866 // Ïðîèãðàíà ëè àíèìàöèÿ öåëèêîì
867 utils
.writeBool(st
, mPlayed
);
868 // Alpha-êàíàë âñåé òåêñòóðû
869 utils
.writeInt(st
, Byte(mAlpha
));
871 utils
.writeInt(st
, Byte(mBlending
));
872 // Âðåìÿ îæèäàíèÿ ìåæäó êàäðàìè
873 utils
.writeInt(st
, Byte(mSpeed
));
874 // Çàöèêëåíà ëè àíèìàöèÿ
875 utils
.writeBool(st
, mLoop
);
877 utils
.writeBool(st
, mEnabled
);
878 // Îæèäàíèå ïîñëå ïðîèãðûâàíèÿ
879 utils
.writeInt(st
, Byte(mMinLength
));
880 // Îáðàòíûé ëè ïîðÿäîê êàäðîâ
881 utils
.writeBool(st
, mRevert
);
885 procedure TAnimation
.loadState (st
: TStream
);
887 if (st
= nil) then exit
;
889 if not utils
.checkSign(st
, 'ANIM') then raise XStreamError
.Create('animation chunk expected');
890 if (utils
.readByte(st
) <> 0) then raise XStreamError
.Create('invalid animation chunk version');
891 // Ñ÷åò÷èê îæèäàíèÿ ìåæäó êàäðàìè
892 mCounter
:= utils
.readByte(st
);
894 mCurrentFrame
:= utils
.readLongInt(st
);
895 // Ïðîèãðàíà ëè àíèìàöèÿ öåëèêîì
896 mPlayed
:= utils
.readBool(st
);
897 // Alpha-êàíàë âñåé òåêñòóðû
898 mAlpha
:= utils
.readByte(st
);
900 mBlending
:= utils
.readBool(st
);
901 // Âðåìÿ îæèäàíèÿ ìåæäó êàäðàìè
902 mSpeed
:= utils
.readByte(st
);
903 // Çàöèêëåíà ëè àíèìàöèÿ
904 mLoop
:= utils
.readBool(st
);
906 mEnabled
:= utils
.readBool(st
);
907 // Îæèäàíèå ïîñëå ïðîèãðûâàíèÿ
908 mMinLength
:= utils
.readByte(st
);
909 // Îáðàòíûé ëè ïîðÿäîê êàäðîâ
910 mRevert
:= utils
.readBool(st
);
914 // ////////////////////////////////////////////////////////////////////////// //
918 function g_Texture_Light (): Integer;
920 Radius
: Integer = 128;
928 GetMem(tex
, (Radius
*2)*(Radius
*2)*4);
930 for y
:= 0 to Radius
*2-1 do
932 for x
:= 0 to Radius
*2-1 do
934 dist
:= 1.0-sqrt((x
-Radius
)*(x
-Radius
)+(y
-Radius
)*(y
-Radius
))/Radius
;
944 //tc.setPixel(x, y, Color(cast(int)(dist*255), cast(int)(dist*255), cast(int)(dist*255)));
945 if (dist
> 0.5) then dist
:= 0.5;
946 a
:= round(dist
*255);
947 if (a
< 0) then a
:= 0 else if (a
> 255) then a
:= 255;
948 tpp
^ := 255; Inc(tpp
);
949 tpp
^ := 255; Inc(tpp
);
950 tpp
^ := 255; Inc(tpp
);
951 tpp
^ := Byte(a
); Inc(tpp
);
956 glGenTextures(1, @ltexid
);
957 //if (tid == 0) assert(0, "VGL: can't create screen texture");
959 glBindTexture(GL_TEXTURE_2D
, ltexid
);
960 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
961 glTexParameterf(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
962 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
963 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
965 //GLfloat[4] bclr = 0.0;
966 //glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, bclr.ptr);
968 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, Radius
*2, Radius
*2, 0, GL_RGBA
{gltt}, GL_UNSIGNED_BYTE
, tex
);