kvarnerexpress 0 Report post Posted September 22, 2005 I've recently acquired DelphiX and have gone through multiple tutorials on how to use it efficiently. However, through programming, I've come across code from a tutorial that was discontinued and I'd like to finish it for learning. The code's for an isometric tiling engine for a game, but the problem is that the FPS rate is EXTREMELY slow come rendering extremely large maps. It crawls at a rate of 5-7FPS, even on pretty powerful machines. (I'll include the code below.)Now, the code itself draws out at each interval of the timer (which I know is a bad way to do things) but there are animated tiles (6 frames each tile), so I don't know any alternative method to bypass the drawing of unupdated tiles. I know that it should only redraw when it needs to, but this is for a game so it should be redrawing quite often.I have looked elsewhere, but found no solutions and I have probed at the code for a few days now. Any suggestions/fixes/sample code would be nice.Code: unit uGame;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, DXDraws, StdCtrls, ExtCtrls, DXInput, DXClass;const TileHeight=15;type TTile = Record TileImage:Integer; Marked:Boolean; end;type TTileMap = Record Map:array[1..50,1..50]of TTile; end;type TMainForm = class(TDXForm) DXDraw: TDXDraw; TileMaps: TDXImageList; DXTimer: TDXTimer; DXInput: TDXInput; Panel: TPanel; Markers: TDXImageList; procedure DXTimerTimer(Sender: TObject; LagCount: Integer); procedure FormCreate(Sender: TObject); procedure DrawTiles(StartX,StartY:Integer); procedure CheckTiles(X,Y:Integer; var XTile, YTile: Integer); procedure DXDrawMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); private { Private declarations } public { Public declarations } end;var Frame:Integer; MainForm: TMainForm; Map:TTileMap; StartX,StartY:Integer; TileX,TileY:Integer;implementation{$R *.DFM}procedure TMainForm.DrawTiles(StartX,StartY:Integer);var PosX,PosY,LoopX,LoopY,XTile,YTile,NumOfTilesY,TileImage:Integer;begin PosY:=0; PosX:=1; NumOfTilesY := 0; for LoopY := 1 to 49 do begin NumOfTilesY := NumOfTilesY + 1; XTile:=1; YTile:=LoopY; for LoopX := 1 to NumOfTilesY do begin TileImage:=Map.Map[XTile,YTile].TileImage; TileMaps.Items[TileImage].Draw(DXDraw.Surface,StartX+PosX+LoopX*64,StartY+LoopY*15,Frame); if Map.Map[XTile,YTile].Marked then begin //Markers.Items[0].Draw(DXDraw.Surface,StartX+PosX+LoopX*64,StartY+LoopY*15,0); end; XTile:=XTile+1; YTile:=YTile-1; end; PosX:=PosX-32; PosY:=PosY+15; end; for LoopY := 1 to 50 do begin XTile:=LoopY; YTile:=50; for LoopX := 1 to NumOfTilesY do begin TileImage:=Map.Map[XTile,YTile].TileImage; TileMaps.Items[TileImage].Draw(DXDraw.Surface,StartX+PosX+LoopX*64,StartY+PosY+LoopY*15,Frame); if Map.Map[XTile,YTile].Marked then begin //Markers.Items[0].Draw(DXDraw.Surface,StartX+PosX+LoopX*64,StartY+PosY+LoopY*15,0); end; XTile:=XTile+1; YTile:=YTile-1; end; NumOfTilesY:=NumOfTilesY-1; PosX:=PosX+32; end; // draw map marker here, above all tiles... //Markers.Items[0].Draw(DXDraw.Surface,StartX+PosX+LoopX*64,StartY+PosY+LoopY*15,0); end;procedure TMainForm.DXTimerTimer(Sender: TObject; LagCount: Integer);begin if not DXDraw.CanDraw then Exit; DXDraw.Surface.Fill(0); Panel.Caption:='FPS: '+IntToStr(DXTimer.FrameRate) +' TileX: '+IntToStr(TileX) +' TileY: '+IntToStr(TileY); DrawTiles(StartX,StartY); DXDraw.Flip; DXInput.Update; { Check for mouse input here } If isLeft in DXInput.States then StartX:=StartX+16; If isRight in DXInput.States then StartX:=StartX-16; If isUp in DXInput.States then StartY:=StartY+8; If isDown in DXInput.States then StartY:=StartY-8; If (Frame=5) then Frame:=0 else Frame:=Frame+1;end;procedure TMainForm.FormCreate(Sender: TObject);var i,ii: integer;begin Frame:=0; StartX:=0; StartY:=0; for i := 1 to 50 do for ii := 1 to 50 do Map.Map[i,ii].TileImage := Random(16); // 0-12 DXTimer.Enabled:=True;end;procedure TMainForm.CheckTiles(X,Y:Integer; var XTile,YTile:Integer);var LoopX,LoopY:Integer;begin for LoopY := 1 to 50 do begin if (Y-((0.46875)*(X-StartX)+StartY+(LoopY*30))<15) and (Y-((0.46875)*(X-StartX)+StartY+(LoopY*30))>(-15)) then begin YTile:=LoopY; end; end; for LoopX := 1 to 50 do begin if (-(0.46875)*(X-StartX)+StartY+(LoopX*30)-Y<15) and ((-0.46875)*(X-StartX)+StartY+(LoopX*30)-Y>(-15)) then begin XTile:=LoopX; end; end;end;procedure TMainForm.DXDrawMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);begin Map.Map[TileX,TileY].Marked:=False; CheckTiles(X-96,Y,TileX,TileY); Map.Map[TileX,TileY].Marked:=True;end;procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin if key = 27 then Application.Terminate();end;end. Note: I've added the onKeyDown method for exiting. There used to be two buttons on the form, but that messed the control up when it came to scrolling with the keys.Note2: If anyone knows how to scroll with the mouse, I'd really like to learn that.Thanks to anyone that helps!Kvarnnerexpress Share this post Link to post Share on other sites
dul 0 Report post Posted September 27, 2005 I think you need to have a look onPaint event of the form. That could be help to you. That event draws all the tiles again. Even when mouse scrolling. Share this post Link to post Share on other sites