May 12, 2008

Delphix And Fps Problems

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Assembler and Delphi

free web hosting

Delphix And Fps Problems

kvarnerexpress
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:

CODE
unit uGame;

interface

uses
 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

 

 

 


Reply

dul
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.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. delphix - 46.70 hr back.
  2. dxdraws on the video - 62.63 hr back.
  3. dxinput delphix - 96.65 hr back.
  4. dxdraw slow update - 145.45 hr back.
  5. delphix learning - 151.68 hr back.
  6. delphix game tutorial - 163.78 hr back.
  7. delphix surface - 126.24 hr back.
Similar Topics

Keywords : delphix, fps, problems

  1. Delphix And Fps
    Problem (0)


      Looking for delphix, fps, problems

Searching Video's for delphix, fps, problems
advertisement



Delphix And Fps Problems



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE