Originally Posted by
hwnd
With blocks there is a thing: each block could have a animation with his own FPS, (how fast tiles are animating). I once tried it with another TTimer, but it was ugly.
Using standard timers (TTimer) for any precise timing is bad idea. The rason of this is the fact that TTimer heavily relies on Windows messages meaning that during high system loads it can become quite inacurate. Using multiple timers is even worse idea since they afect each other.
So using TThreadedTimer is much better idea.
Originally Posted by
hwnd
but at the same time, i don't like that the editor will take 100% CPU
But it should redraw fast, i tried TThreadedTimer and set it interval to 1ms. It was good, because user can just "paint" tiles on blocks and editor should draw them immediately without any delay. That's why 1ms timer. Although i know that TTimer is limited to >16ms
Using timer with 1ms for contoling renderning is pointles. Why? By doing so you are forcing your computer to do more redraws (1000 redraws per second) that hardware is capable of. This will in the end consume all the CPU power.
Since you are only making editor I think that having 30 redraws per second would be more than enough. So you could simply use 33ms timer delay which makes aprox 30 FPS.
As for animations you do have to use some global counter (integer variable) which is increased everytime you redraw your screen. Then you calculate which frame is needed to be drawn at specific time. Below is the code example.
Code:
TAni = record //Record defining animation information
FPS: Integer; //Defines how many animation frames are being drawn per second
FramesCount: Integer; //Defines how many total frames is in animation
Frame: Integer; //Defines current animation frame
end;
... //some code
//Global unit declarations
var FrameCounter: Integer; //Framecounter is being used to count the number of frames which has already been drawn
//since its last reset
FPS: Integer; //Variable defining desired application FPS.
Ani: TAni; //Ani is of type TAni
...//some code
procedure OnDraw; //your renderning procedure
begin
//code used to calculate which animation frame needs to be drawn.
//this code can be put on the beggining off your rendering procedure
Ani.Frame := (FrameCounter div (FPS div Ani.FPS)) mod Ani1.FramesCount;
...//some code
//Code used to count how many frames have been drawns since last FrameCounters reset.
FrameCounter := FrameCounter + 1;
//Below code is used to reset FrameCount back to 0 after reaching AniResetFrame. Without this code FrameCounter
//will eventually exceed maximum integer value which could lead t many problems.
//AnimationsResetFrame is constand number representing frame number on which all animations would reach Frame 0
//at the same time.
//It is imperitive to reset FrameCounter at the right time to avouid jumpy animation.
if FrameCounter = AnimationsResetFrame then FrameCounter := 0;
end;
And one final suggestion:
Do implement some keyboard shourtcuts for various controls. Especially for rotatng objects so you don't have to do half dozen clicks just to find the right orientation for certain objects.
EDIT: Go and make you own thread in MyProjects section so we can continue discusion there and thus keep our forum nice and clean. I can then move relavent posts there.
Bookmarks