Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Delphix And Fps, Problem
kvarnerexpress
post Oct 6 2005, 11:07 AM
Post #1


Super Member
*********

Group: Members
Posts: 407
Joined: 13-December 04
Member No.: 2,696



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!
kvarnerexpress
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Two Lan Ports Problem(2)
  2. Need Help: Problem Seeing My Site(3)
  3. Weird Write Problem(3)
  4. Cannot Connect To Mail Server(3)
  5. [chsupport #ecn-115724]: Ftp/cpanel Login Problem(7)
  6. Rpg Maker 2003 Music Problem(2)
  7. Harddrive "open With..." Problem(1)
  8. Problem With My External Hard Disk(4)
  9. Phpmyadmin Problem [resolved](2)
  10. Dotworlds Free Domain Problem!(24)
  11. I Have A Girl Problem Here(24)
  12. Fantastico And Cpanel Skin Problem.(1)
  13. Laptop Keyboard Problem(6)
  14. Can Anyone Help Me With My Graphic Card - 8600 Gt [resolved](15)
  15. Why My Computer Freezez(4)
  1. Credits Problem(14)
  2. Mysql-essential-5.0.51 Installion Problem(2)
  3. Flash Problem(9)
  4. How To Reformat Your Harddrive...(10)
  5. I'm Having A Strange Problem With My Ping In Cs:s(27)
  6. My Dog Pukes Regularly(16)
  7. Remote Assistance Problem(7)
  8. Auto Webpage Resolution Format(7)
  9. Kitten Born With Only One Eye And No Nose(27)
  10. Sql Problem(2)
  11. Girls Problem(10)
  12. Html Problem(9)
  13. I Have A Big Problem With Cs 1.6.(3)
  14. Invoice Problem(2)
  15. Cd Drive Eject Button Problem(3)


 



- Lo-Fi Version Time is now: 20th July 2008 - 08:34 PM