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 MAPDEF
, BinEditor
, g_textures
, xdynrec
;
26 TAddTextureArray
= Array of
32 TPanel
= Class (TObject
)
36 mGUID
: Integer; // will be assigned in "g_map.pas"
44 False: (Tex
: Cardinal);
45 True: (AnTex
: TAnimation
);
48 mMovingSpeed
: TDFPoint
;
49 mMovingStart
: TDFPoint
;
51 mMovingActive
: Boolean;
54 function getx1 (): Integer; inline;
55 function gety1 (): Integer; inline;
56 function getvisvalid (): Boolean; inline;
59 FCurTexture
: Integer; // Íîìåð òåêóùåé òåêñòóðû
63 FWidth
, FHeight
: Word;
65 FSaveIt
: Boolean; // Ñîõðàíÿòü ïðè SaveState?
71 // sorry, there fields are public to allow setting 'em in g_map; this should be fixed later
72 // for now, PLEASE, don't modify 'em, or all hell will break loose
73 arrIdx
: Integer; // index in one of internal arrays; sorry
74 tag
: Integer; // used in coldets and such; sorry; see g_map.GridTagXXX
75 proxyId
: Integer; // proxy id in map grid (DO NOT USE!)
76 mapId
: AnsiString; // taken directly from map file; dunno why it is here
78 constructor Create(PanelRec
: TDynRecord
;
79 AddTextures
: TAddTextureArray
;
81 var Textures
: TLevelTextureArray
; aguid
: Integer);
82 destructor Destroy(); override;
85 procedure DrawShadowVolume(lightX
: Integer; lightY
: Integer; radius
: Integer);
87 procedure SetFrame(Frame
: Integer; Count
: Byte);
88 procedure NextTexture(AnimLoop
: Byte = 0);
89 procedure SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
90 function GetTextureID(): Cardinal;
91 function GetTextureCount(): Integer;
93 procedure SaveState(var Mem
: TBinMemoryWriter
);
94 procedure LoadState(var Mem
: TBinMemoryReader
);
96 procedure positionChanged (); inline;
98 function isGBack (): Boolean; inline; // gRenderBackgrounds
99 function isGStep (): Boolean; inline; // gSteps
100 function isGWall (): Boolean; inline; // gWalls
101 function isGAcid1 (): Boolean; inline; // gAcid1
102 function isGAcid2 (): Boolean; inline; // gAcid2
103 function isGWater (): Boolean; inline; // gWater
104 function isGFore (): Boolean; inline; // gRenderForegrounds
105 function isGLift (): Boolean; inline; // gLifts
106 function isGBlockMon (): Boolean; inline; // gBlockMon
110 property visvalid
: Boolean read getvisvalid
; // panel is "visvalid" when it's width and height are positive
113 property guid
: Integer read mGUID
; // will be assigned in "g_map.pas"
114 property x0
: Integer read FX
;
115 property y0
: Integer read FY
;
116 property x1
: Integer read getx1
; // inclusive!
117 property y1
: Integer read gety1
; // inclusive!
118 property x
: Integer read FX write FX
;
119 property y
: Integer read FY write FY
;
120 property width
: Word read FWidth write FWidth
;
121 property height
: Word read FHeight write FHeight
;
122 property panelType
: Word read FPanelType write FPanelType
;
123 property saveIt
: Boolean read FSaveIt write FSaveIt
; // Ñîõðàíÿòü ïðè SaveState?
124 property enabled
: Boolean read FEnabled write FEnabled
; // Ñîõðàíÿòü ïðè SaveState?
125 property door
: Boolean read FDoor write FDoor
; // Ñîõðàíÿòü ïðè SaveState?
126 property moved
: Boolean read FMoved write FMoved
; // Ñîõðàíÿòü ïðè SaveState?
127 property liftType
: Byte read FLiftType write FLiftType
; // Ñîõðàíÿòü ïðè SaveState?
128 property lastAnimLoop
: Byte read FLastAnimLoop write FLastAnimLoop
; // Ñîõðàíÿòü ïðè SaveState?
130 property movingActive
: Boolean read mMovingActive write mMovingActive
;
133 property movingSpeed
: TDFPoint read mMovingSpeed write mMovingSpeed
;
134 property movingStart
: TDFPoint read mMovingStart write mMovingStart
;
135 property movingEnd
: TDFPoint read mMovingEnd write mMovingEnd
;
138 TPanelArray
= Array of TPanel
;
143 SysUtils
, g_basic
, g_map
, g_game
, g_gfx
, e_graphics
,
144 g_console
, g_language
, g_monsters
, g_player
, e_log
, GL
;
147 PANEL_SIGNATURE
= $4C4E4150; // 'PANL'
151 constructor TPanel
.Create(PanelRec
: TDynRecord
;
152 AddTextures
: TAddTextureArray
;
154 var Textures
: TLevelTextureArray
; aguid
: Integer);
160 Width
:= PanelRec
.Width
;
161 Height
:= PanelRec
.Height
;
169 mapId
:= PanelRec
.id
;
172 mMovingSpeed
:= PanelRec
.moveSpeed
;
173 mMovingStart
:= PanelRec
.moveStart
;
174 mMovingEnd
:= PanelRec
.moveEnd
;
175 mMovingActive
:= PanelRec
['move_active'].varvalue
;
178 PanelType
:= PanelRec
.PanelType
;
216 if ByteBool(PanelRec
.Flags
and PANEL_FLAG_HIDE
) then
218 SetLength(FTextureIDs
, 0);
222 // Ïàíåëè, íå èñïîëüçóþùèå òåêñòóðû:
223 if ByteBool(PanelType
and
228 PANEL_BLOCKMON
)) then
230 SetLength(FTextureIDs
, 0);
235 // Åñëè ýòî æèäêîñòü áåç òåêñòóðû - ñïåöòåêñòóðó:
236 if WordBool(PanelType
and (PANEL_WATER
or PANEL_ACID1
or PANEL_ACID2
)) and
237 (not ByteBool(PanelRec
.Flags
and PANEL_FLAG_WATERTEXTURES
)) then
239 SetLength(FTextureIDs
, 1);
240 FTextureIDs
[0].Anim
:= False;
242 case PanelRec
.PanelType
of
244 FTextureIDs
[0].Tex
:= LongWord(TEXTURE_SPECIAL_WATER
);
246 FTextureIDs
[0].Tex
:= LongWord(TEXTURE_SPECIAL_ACID1
);
248 FTextureIDs
[0].Tex
:= LongWord(TEXTURE_SPECIAL_ACID2
);
255 SetLength(FTextureIDs
, Length(AddTextures
));
260 if CurTex
>= Length(FTextureIDs
) then
261 FCurTexture
:= Length(FTextureIDs
) - 1
263 FCurTexture
:= CurTex
;
265 for i
:= 0 to Length(FTextureIDs
)-1 do
267 FTextureIDs
[i
].Anim
:= AddTextures
[i
].Anim
;
268 if FTextureIDs
[i
].Anim
then
269 begin // Àíèìèðîâàííàÿ òåêñòóðà
270 FTextureIDs
[i
].AnTex
:=
271 TAnimation
.Create(Textures
[AddTextures
[i
].Texture
].FramesID
,
272 True, Textures
[AddTextures
[i
].Texture
].Speed
);
273 FTextureIDs
[i
].AnTex
.Blending
:= ByteBool(PanelRec
.Flags
and PANEL_FLAG_BLENDING
);
274 FTextureIDs
[i
].AnTex
.Alpha
:= PanelRec
.Alpha
;
278 begin // Îáû÷íàÿ òåêñòóðà
279 FTextureIDs
[i
].Tex
:= Textures
[AddTextures
[i
].Texture
].TextureID
;
283 // Òåêñòóð íåñêîëüêî - íóæíî ñîõðàíÿòü òåêóùóþ:
284 if Length(FTextureIDs
) > 1 then
287 // Åñëè íå ñïåöòåêñòóðà, òî çàäàåì ðàçìåðû:
288 if PanelRec
.TextureNum
> High(Textures
) then
290 e_WriteLog(Format('WTF?! PanelRec.TextureNum is out of limits! (%d : %d)', [PanelRec
.TextureNum
, High(Textures
)]), MSG_FATALERROR
);
294 FBlending
:= ByteBool(0);
296 else if not g_Map_IsSpecialTexture(Textures
[PanelRec
.TextureNum
].TextureName
) then
298 FTextureWidth
:= Textures
[PanelRec
.TextureNum
].Width
;
299 FTextureHeight
:= Textures
[PanelRec
.TextureNum
].Height
;
300 FAlpha
:= PanelRec
.Alpha
;
301 FBlending
:= ByteBool(PanelRec
.Flags
and PANEL_FLAG_BLENDING
);
305 destructor TPanel
.Destroy();
309 for i
:= 0 to High(FTextureIDs
) do
310 if FTextureIDs
[i
].Anim
then
311 FTextureIDs
[i
].AnTex
.Free();
312 SetLength(FTextureIDs
, 0);
317 function TPanel
.getx1 (): Integer; inline; begin result
:= X
+Width
-1; end;
318 function TPanel
.gety1 (): Integer; inline; begin result
:= Y
+Height
-1; end;
319 function TPanel
.getvisvalid (): Boolean; inline; begin result
:= (Width
> 0) and (Height
> 0); end;
321 function TPanel
.isGBack (): Boolean; inline; begin result
:= ((tag
and GridTagBack
) <> 0); end;
322 function TPanel
.isGStep (): Boolean; inline; begin result
:= ((tag
and GridTagStep
) <> 0); end;
323 function TPanel
.isGWall (): Boolean; inline; begin result
:= ((tag
and (GridTagWall
or GridTagDoor
)) <> 0); end;
324 function TPanel
.isGAcid1 (): Boolean; inline; begin result
:= ((tag
and GridTagAcid1
) <> 0); end;
325 function TPanel
.isGAcid2 (): Boolean; inline; begin result
:= ((tag
and GridTagAcid2
) <> 0); end;
326 function TPanel
.isGWater (): Boolean; inline; begin result
:= ((tag
and GridTagWater
) <> 0); end;
327 function TPanel
.isGFore (): Boolean; inline; begin result
:= ((tag
and GridTagFore
) <> 0); end;
328 function TPanel
.isGLift (): Boolean; inline; begin result
:= ((tag
and GridTagLift
) <> 0); end;
329 function TPanel
.isGBlockMon (): Boolean; inline; begin result
:= ((tag
and GridTagBlockMon
) <> 0); end;
331 procedure TPanel
.Draw();
337 if {Enabled and} (FCurTexture
>= 0) and
338 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) and
339 ((g_dbg_scale
<> 1.0) or g_Collide(X
, Y
, Width
, Height
, sX
, sY
, sWidth
, sHeight
)) then
341 if FTextureIDs
[FCurTexture
].Anim
then
342 begin // Àíèìèðîâàííàÿ òåêñòóðà
343 if FTextureIDs
[FCurTexture
].AnTex
= nil then
346 for xx
:= 0 to (Width
div FTextureWidth
)-1 do
347 for yy
:= 0 to (Height
div FTextureHeight
)-1 do
348 FTextureIDs
[FCurTexture
].AnTex
.Draw(
349 X
+ xx
*FTextureWidth
,
350 Y
+ yy
*FTextureHeight
, M_NONE
);
353 begin // Îáû÷íàÿ òåêñòóðà
354 case FTextureIDs
[FCurTexture
].Tex
of
355 LongWord(TEXTURE_SPECIAL_WATER
):
356 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
357 0, 0, 255, 0, B_FILTER
);
358 LongWord(TEXTURE_SPECIAL_ACID1
):
359 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
360 0, 128, 0, 0, B_FILTER
);
361 LongWord(TEXTURE_SPECIAL_ACID2
):
362 e_DrawFillQuad(X
, Y
, X
+Width
-1, Y
+Height
-1,
363 128, 0, 0, 0, B_FILTER
);
364 LongWord(TEXTURE_NONE
):
365 if g_Texture_Get('NOTEXTURE', NoTextureID
) then
367 e_GetTextureSize(NoTextureID
, @NW
, @NH
);
368 e_DrawFill(NoTextureID
, X
, Y
, Width
div NW
, Height
div NH
,
372 xx
:= X
+ (Width
div 2);
373 yy
:= Y
+ (Height
div 2);
374 e_DrawFillQuad(X
, Y
, xx
, yy
,
376 e_DrawFillQuad(xx
, Y
, X
+Width
-1, yy
,
378 e_DrawFillQuad(X
, yy
, xx
, Y
+Height
-1,
380 e_DrawFillQuad(xx
, yy
, X
+Width
-1, Y
+Height
-1,
385 e_DrawFill(FTextureIDs
[FCurTexture
].Tex
, X
, Y
,
386 Width
div FTextureWidth
,
387 Height
div FTextureHeight
,
388 FAlpha
, True, FBlending
);
394 procedure TPanel
.DrawShadowVolume(lightX
: Integer; lightY
: Integer; radius
: Integer);
395 procedure extrude (x
: Integer; y
: Integer);
397 glVertex2i(x
+(x
-lightX
)*500, y
+(y
-lightY
)*500);
398 //e_WriteLog(Format(' : (%d,%d)', [x+(x-lightX)*300, y+(y-lightY)*300]), MSG_WARNING);
401 procedure drawLine (x0
: Integer; y0
: Integer; x1
: Integer; y1
: Integer);
403 // does this side facing the light?
404 if ((x1
-x0
)*(lightY
-y0
)-(lightX
-x0
)*(y1
-y0
) >= 0) then exit
;
405 //e_WriteLog(Format('lightpan: (%d,%d)-(%d,%d)', [x0, y0, x1, y1]), MSG_WARNING);
406 // this edge is facing the light, extrude and draw it
414 if radius
< 4 then exit
;
415 if Enabled
and (FCurTexture
>= 0) and (Width
> 0) and (Height
> 0) and (FAlpha
< 255) and g_Collide(X
, Y
, Width
, Height
, sX
, sY
, sWidth
, sHeight
) then
417 if not FTextureIDs
[FCurTexture
].Anim
then
419 case FTextureIDs
[FCurTexture
].Tex
of
420 LongWord(TEXTURE_SPECIAL_WATER
): exit
;
421 LongWord(TEXTURE_SPECIAL_ACID1
): exit
;
422 LongWord(TEXTURE_SPECIAL_ACID2
): exit
;
423 LongWord(TEXTURE_NONE
): exit
;
426 if (X
+Width
< lightX
-radius
) then exit
;
427 if (Y
+Height
< lightY
-radius
) then exit
;
428 if (X
> lightX
+radius
) then exit
;
429 if (Y
> lightY
+radius
) then exit
;
430 //e_DrawFill(FTextureIDs[FCurTexture].Tex, X, Y, Width div FTextureWidth, Height div FTextureHeight, FAlpha, True, FBlending);
433 drawLine(x
, y
, x
+width
, y
); // top
434 drawLine(x
+width
, y
, x
+width
, y
+height
); // right
435 drawLine(x
+width
, y
+height
, x
, y
+height
); // bottom
436 drawLine(x
, y
+height
, x
, y
); // left
442 procedure TPanel
.positionChanged (); inline;
444 px
, py
, pw
, ph
: Integer;
446 if (proxyId
>= 0) then
448 monsGrid
.getBodyDims(proxyId
, px
, py
, pw
, ph
);
449 if (px
<> x
) or (py
<> y
) or (pw
<> Width
) or (ph
<> Height
) then
451 g_Mark(px
, py
, pw
, ph
, MARK_WALL
, false);
452 if (pw
<> Width
) or (ph
<> Height
) then mapGrid
.moveResizeBody(proxyId
, X
, Y
, Width
, Height
)
453 else mapGrid
.moveBody(proxyId
, X
, Y
);
454 g_Mark(X
, Y
, Width
, Height
, MARK_WALL
);
461 monMoveList
: array of TMonster
= nil;
462 monMoveListUsed
: Integer = 0;
464 procedure TPanel
.Update();
469 function doPush (px
, py
, pw
, ph
: Integer; out dx
, dy
: Integer): Boolean;
471 result
:= g_Collide(px
, py
, pw
, ph
, nx
, ny
, Width
, Height
);
475 if (mMovingSpeed
.X
< 0) then dx
:= nx
-(px
+pw
)
476 else if (mMovingSpeed
.X
> 0) then dx
:= (nx
+Width
)-px
478 if (mMovingSpeed
.Y
< 0) then dy
:= ny
-(py
+ph
)
479 else if (mMovingSpeed
.Y
> 0) then dy
:= (ny
+Height
)-py
489 function monMove (mon
: TMonster
): Boolean;
491 result
:= false; // don't stop
492 mon
.GameX
:= mon
.GameX
+mMovingSpeed
.X
;
493 mon
.GameY
:= mon
.GameY
+mMovingSpeed
.Y
;
494 if (monMoveListUsed
>= Length(monMoveList
)) then SetLength(monMoveList
, monMoveListUsed
+64);
495 monMoveList
[monMoveListUsed
] := mon
;
496 Inc(monMoveListUsed
);
499 function monPush (mon
: TMonster
): Boolean;
501 px
, py
, pw
, ph
, dx
, dy
: Integer;
503 result
:= false; // don't stop
504 mon
.getMapBox(px
, py
, pw
, ph
);
505 if doPush(px
, py
, pw
, ph
, dx
, dy
) then
507 mon
.GameX
:= mon
.GameX
+dx
;
508 mon
.GameY
:= mon
.GameY
+dy
;
509 if (monMoveListUsed
>= Length(monMoveList
)) then SetLength(monMoveList
, monMoveListUsed
+64);
510 monMoveList
[monMoveListUsed
] := mon
;
511 Inc(monMoveListUsed
);
515 procedure plrMove (plr
: TPlayer
);
517 px
, py
, pw
, ph
, dx
, dy
: Integer;
519 if (plr
= nil) then exit
;
520 plr
.getMapBox(px
, py
, pw
, ph
);
524 if doPush(px
, py
, pw
, ph
, dx
, dy
) then
526 plr
.GameX
:= plr
.GameX
+dx
;
527 plr
.GameY
:= plr
.GameY
+dy
;
528 plr
.positionChanged();
532 if (px
+pw
<= X
) then exit
;
533 if (px
>= X
+Width
) then exit
;
534 plr
.GameX
:= plr
.GameX
+mMovingSpeed
.X
;
535 plr
.GameY
:= plr
.GameY
+mMovingSpeed
.Y
;
536 plr
.positionChanged();
540 if Enabled
and (FCurTexture
>= 0) and
541 (FTextureIDs
[FCurTexture
].Anim
) and
542 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
543 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
545 FTextureIDs
[FCurTexture
].AnTex
.Update();
546 FCurFrame
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
;
547 FCurFrameCount
:= FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
;
550 if mMovingActive
and (not mMovingSpeed
.isZero
) then
552 monMoveListUsed
:= 0;
553 nx
:= X
+mMovingSpeed
.X
;
554 ny
:= Y
+mMovingSpeed
.Y
;
555 // move monsters on lifts
556 g_Mons_ForEachAt(X
, Y
-1, Width
, 1, monMove
);
558 g_Mons_ForEachAt(nx
, ny
, Width
, Height
, monPush
);
559 // move and push players
560 for f
:= 0 to High(gPlayers
) do plrMove(gPlayers
[f
]);
561 // reverse moving direction, if necessary
562 if (mMovingSpeed
.X
< 0) and (nx
<= mMovingStart
.X
) then mMovingSpeed
.X
:= -mMovingSpeed
.X
563 else if (mMovingSpeed
.X
> 0) and (nx
>= mMovingEnd
.X
) then mMovingSpeed
.X
:= -mMovingSpeed
.X
;
564 if (mMovingSpeed
.Y
< 0) and (ny
<= mMovingStart
.Y
) then mMovingSpeed
.Y
:= -mMovingSpeed
.Y
565 else if (mMovingSpeed
.Y
> 0) and (ny
>= mMovingEnd
.Y
) then mMovingSpeed
.Y
:= -mMovingSpeed
.Y
;
567 //g_Mark(X, Y, Width, Height, MARK_WALL, false);
570 //g_Mark(nx, ny, Width, Height, MARK_WALL);
573 // notify moved monsters about their movement
574 for f
:= 0 to monMoveListUsed
-1 do monMoveList
[f
].positionChanged();
578 procedure TPanel
.SetFrame(Frame
: Integer; Count
: Byte);
580 function ClampInt(X
, A
, B
: Integer): Integer;
583 if X
< A
then Result
:= A
else if X
> B
then Result
:= B
;
587 if Enabled
and (FCurTexture
>= 0) and
588 (FTextureIDs
[FCurTexture
].Anim
) and
589 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
590 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
592 FCurFrame
:= ClampInt(Frame
, 0, FTextureIDs
[FCurTexture
].AnTex
.TotalFrames
);
593 FCurFrameCount
:= Count
;
594 FTextureIDs
[FCurTexture
].AnTex
.CurrentFrame
:= FCurFrame
;
595 FTextureIDs
[FCurTexture
].AnTex
.CurrentCounter
:= FCurFrameCount
;
599 procedure TPanel
.NextTexture(AnimLoop
: Byte = 0);
601 Assert(FCurTexture
>= -1, 'FCurTexture < -1');
604 if Length(FTextureIDs
) = 0 then
607 // Òîëüêî îäíà òåêñòóðà:
608 if Length(FTextureIDs
) = 1 then
610 if FCurTexture
= 0 then
616 // Áîëüøå îäíîé òåêñòóðû:
620 // Ñëåäóþùåé íåò - âîçâðàò ê íà÷àëó:
621 if FCurTexture
>= Length(FTextureIDs
) then
625 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
626 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
628 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
630 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
635 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
638 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
640 FTextureIDs
[FCurTexture
].AnTex
.Reset();
643 LastAnimLoop
:= AnimLoop
;
646 procedure TPanel
.SetTexture(ID
: Integer; AnimLoop
: Byte = 0);
649 if Length(FTextureIDs
) = 0 then
652 // Òîëüêî îäíà òåêñòóðà:
653 if Length(FTextureIDs
) = 1 then
655 if (ID
= 0) or (ID
= -1) then
659 // Áîëüøå îäíîé òåêñòóðû:
661 if (ID
>= -1) and (ID
<= High(FTextureIDs
)) then
665 // Ïåðåêëþ÷èëèñü íà âèäèìóþ àíèì. òåêñòóðó:
666 if (FCurTexture
>= 0) and FTextureIDs
[FCurTexture
].Anim
then
668 if (FTextureIDs
[FCurTexture
].AnTex
= nil) then
670 g_FatalError(_lc
[I_GAME_ERROR_SWITCH_TEXTURE
]);
675 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= True
678 FTextureIDs
[FCurTexture
].AnTex
.Loop
:= False;
680 FTextureIDs
[FCurTexture
].AnTex
.Reset();
683 LastAnimLoop
:= AnimLoop
;
686 function TPanel
.GetTextureID(): DWORD
;
688 Result
:= LongWord(TEXTURE_NONE
);
690 if (FCurTexture
>= 0) then
692 if FTextureIDs
[FCurTexture
].Anim
then
693 Result
:= FTextureIDs
[FCurTexture
].AnTex
.FramesID
695 Result
:= FTextureIDs
[FCurTexture
].Tex
;
699 function TPanel
.GetTextureCount(): Integer;
701 Result
:= Length(FTextureIDs
);
702 if Enabled
and (FCurTexture
>= 0) then
703 if (FTextureIDs
[FCurTexture
].Anim
) and
704 (FTextureIDs
[FCurTexture
].AnTex
<> nil) and
705 (Width
> 0) and (Height
> 0) and (FAlpha
< 255) then
706 Result
:= Result
+ 100;
709 procedure TPanel
.SaveState(Var Mem
: TBinMemoryWriter
);
714 if (Mem
= nil) then exit
;
715 //if not SaveIt then exit;
718 sig
:= PANEL_SIGNATURE
; // 'PANL'
720 // Îòêðûòà/çàêðûòà, åñëè äâåðü:
721 Mem
.WriteBoolean(FEnabled
);
722 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò:
723 Mem
.WriteByte(FLiftType
);
724 // Íîìåð òåêóùåé òåêñòóðû:
725 Mem
.WriteInt(FCurTexture
);
729 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà:
730 if (FCurTexture
>= 0) and (FTextureIDs
[FCurTexture
].Anim
) then
732 Assert(FTextureIDs
[FCurTexture
].AnTex
<> nil,
733 'TPanel.SaveState: No animation object');
738 Mem
.WriteBoolean(anim
);
739 // Åñëè äà - ñîõðàíÿåì àíèìàöèþ:
741 FTextureIDs
[FCurTexture
].AnTex
.SaveState(Mem
);
742 // moving platform state
743 Mem
.WriteInt(mMovingSpeed
.X
);
744 Mem
.WriteInt(mMovingSpeed
.Y
);
745 Mem
.WriteInt(mMovingStart
.X
);
746 Mem
.WriteInt(mMovingStart
.Y
);
747 Mem
.WriteInt(mMovingEnd
.X
);
748 Mem
.WriteInt(mMovingEnd
.Y
);
749 Mem
.WriteBoolean(mMovingActive
);
752 procedure TPanel
.LoadState(var Mem
: TBinMemoryReader
);
758 if (Mem
= nil) then exit
;
759 //if not SaveIt then exit;
763 if sig
<> PANEL_SIGNATURE
then // 'PANL'
765 raise EBinSizeError
.Create('TPanel.LoadState: Wrong Panel Signature');
767 // Îòêðûòà/çàêðûòà, åñëè äâåðü:
768 Mem
.ReadBoolean(FEnabled
);
769 // Íàïðàâëåíèå ëèôòà, åñëè ëèôò:
770 Mem
.ReadByte(FLiftType
);
771 // Íîìåð òåêóùåé òåêñòóðû:
772 Mem
.ReadInt(FCurTexture
);
778 //e_LogWritefln('panel %s(%s): old=(%s,%s); new=(%s,%s); delta=(%s,%s)', [arrIdx, proxyId, ox, oy, FX, FY, FX-ox, FY-oy]);
779 // Àíèìèðîâàííàÿ ëè òåêóùàÿ òåêñòóðà:
780 Mem
.ReadBoolean(anim
);
781 // Åñëè äà - çàãðóæàåì àíèìàöèþ:
784 Assert((FCurTexture
>= 0) and
785 (FTextureIDs
[FCurTexture
].Anim
) and
786 (FTextureIDs
[FCurTexture
].AnTex
<> nil),
787 'TPanel.LoadState: No animation object');
788 FTextureIDs
[FCurTexture
].AnTex
.LoadState(Mem
);
790 // moving platform state
791 Mem
.ReadInt(mMovingSpeed
.X
);
792 Mem
.ReadInt(mMovingSpeed
.Y
);
793 Mem
.ReadInt(mMovingStart
.X
);
794 Mem
.ReadInt(mMovingStart
.Y
);
795 Mem
.ReadInt(mMovingEnd
.X
);
796 Mem
.ReadInt(mMovingEnd
.Y
);
797 Mem
.ReadBoolean(mMovingActive
);
800 //mapGrid.proxyEnabled[proxyId] := FEnabled; // done in g_map.pas