PDA

View Full Version : DELPHIX Problems. Need help with multiple problems



seiferalmasy
26-05-2006, 10:40 PM
Windows XP, SP1a, DelphiX, Borland delphi 4 and 7, Pentium 4 2.8 GHz, Geforce 2 MMX400 64 MB, 512 MB DDR 3200

1. Delphix timer seems to reach only a maximum FPS of 64 on my computer, 100 on my cousins (even though we are using pentium 4 processors). It si very strange but the bug disappears as soon as I open certain programs like DXDIAG from Run. Sometimes the bug is more provailent when delphi itself is not running...very strange. Really need help with this (furthermore all high precision timers won't reach above 64 FPS on my computer). I am thinking it is a problem with the OS me and my cousin are using?

2. I need to add images to TDXimagelist at runtime?

3. I need to change the background and 1 or 2 sprites SIZE and see the change reflected on screen. I jave tried putting image.patternheight:=image.patternheight-10; at nearly every point in the program but no luck at all :(. In other words I need to see say my character "grow" or "shrink".

4. If I have Vsync on the FPS changes too, and it seems to chane depending on screen frequency of the computer in question as would be expected. Unfortunately this also changes the gameplay speed depending on each computer. How can I ensure the game will be the same on all computers? I.e. Charcter sprites moving at same speed etc etc etc.

5. How do I reference other Sprites from inside another sprites DoMove? I need to say x:= [insert other sprites x position here]. Or do I simply have to do it the hard way and use a global variable?

Thanks for any help, I really am stuck!

Seifer Almasy

Traveler
27-05-2006, 09:40 AM
Can't really help you with the first question. My first thoughts are vsync, but you mentioned that in your 4th question, so that's probably not it either.

2: something like this

procedure TForm1.BitBtn1Click(Sender: TObject);
var
Item: TPictureCollectionItem;
picture : TPicture;
begin
picture := TPicture.Create;
picture.LoadFromFile('c:\windows\Zapotec.bmp');
try
Item := TPictureCollectionItem.Create(DXImageList1.Items);
Item.Picture.Graphic := picture.Graphic;

doneLoading := true;
finally
picture.Free;
end;
end;

procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
if doneLoading then
begin
dximagelist1.Items.Items[0].Draw(dxdraw1.Surface,1 0,10,0);
end;
dxdraw1.Flip;
end;

3: change draw procedure into

if doneLoading then
begin
dximagelist1.Items.Items[0].StretchDraw(dxdraw1.Su rface, rect(10,10,200,200), 0);
end;

4: look into timebased movement, instead of framebased.

5: Easiest way would indeed be to use a global var.

activeSpriteList[1].X := activeSpriteList[0].X

Hope that helps.

AthenaOfDelphi
27-05-2006, 02:28 PM
Question 2:-

I've not read Travellers code, but the key thing I found was to finalize the TDXDraw component that the TDXImageList is linked to, load the images, build the colour tables and assign them to the TDXDraw.surface (IIRC) and the initialize the TDXDraw.

I had this problem during the competition and this was the only way I could make it work.

seiferalmasy
27-05-2006, 06:36 PM
I will give these suggestions so far a try and report back. THANKS!

seiferalmasy
27-05-2006, 10:52 PM
No.5, yes that is a nice idea. I have implemented a record array, is that what you intended me to use?

I have figured out no.2. You see I am using the sprite engine, not the draw surface;)

code was simple and I should have figured it out:

dximagelist1.Items[2].picture.LoadFromFile('c:\1.bmp');

-------

Unfortunately, the resize is also needed for use with the domove part of the sprite in question. I havent got it to worj yet:(

Although it works well for dxdraw on the surface, I have no idea how to get it working with the sprite engine. maybe I have to destroy the sprite and then recreate each time?

Any ideas? And maybe athena can supply some code?

Traveler
28-05-2006, 10:24 AM
I have implemented a record array, is that what you intended me to use?

What you want to use is up to you. I found it quite easy to use arrays.


dximagelist1.Items[2].picture.LoadFromFile('c:\1.bmp');
This assumes you already have reserved an dximagelist item. But yeah, that works as well.


maybe I have to destroy the sprite and then recreate each time? Depending how often this is going to happen, it would slow down your game a lot.

I'm not sure what you want, but I'd stay away from the TBackground class, and write your own. It's quite easy to draw a tilemap.

Could you show some code where you're having problems with?

seiferalmasy
28-05-2006, 11:48 AM
Difficult to supply code because I don't have any code for the thing in question. I have mnaged to get the game area shrinking properly thanks to your help and by not using tbackground

Unfortunately The enemy has to be a sprite and thus making him grow from 25 pixels * 25 pixels to 40 * 40 is proving difficult. I would have thought it as easy as height:=height+1; but it seems that delphix only takes this into consideration in the create and not domove :( of course I could probably animate the growth if not for the fact people are allowed to upload their freinds photo to replace the default enemy picture ;)

I was rather hoping hori had programmed a special method for this like DoSize hehe but looks like not.

On other things, I might be able to get away with vsunc and use a permanent 100 fps (only problem being there is some weird phenomina that makes it run at 64 fps (if above an interval of 10) regardless when program is not running from within delphi)

2b. Is it possible with that draw instead of stretch it centres the image?

3b. And a very big favour I have to ask you. I really need to get to the bottom off this timer problem. I have uploaded with source and exe a simple test to see if DXtimer is the fault of me or the timer. When you recieve it, you can open the exe, report to me whether it is achieving 1000 ms resolution. If I could be bolder I would like you to then compile the source on your end and then send me back the exe. This will enable me to find out more about the nature of this problem. If you could do that that would be neat!

http://www.uploading.com/?get=J6DJ9LM3

Above is the link to the file.

Traveler
28-05-2006, 04:46 PM
2b. Is it possible with that draw instead of stretch it centres the image?
It is: add a trackbar and dximagelist component to your form and c/p the following code. Set trackbar position to say 100 and add an image to the imagelist.


procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
dxdraw1.Surface.Fill(0);
dximagelist1.Items.Items[0].StretchDraw(dxdraw1.Su rface, rect(100-trackbar1.Position,100-trackbar1.Position,200+trackbar1.Position,200+trac kbar1.Position), 0);
dxdraw1.Flip;
end;

3b: done. Getting 1000ms almost right at startup. Compiled it too, but with the same result.
I doubt it'll be different on your pc but here (http://www.gameprogrammer.net/zip/TimerDebug.rar)'s the rarfile.

seiferalmasy
28-05-2006, 08:02 PM
Very good. You have answered 1 major question also but this is a serious problem now.

It is not the compiled exe that matters nor is it delphi or delphix. It is some other factor and no matter what, other peoples delphi apps are not going to run properly on mine or my cousins computer. This means that there will be others like me where the delphi apps will be fundamentally flawed

How very bizarre....Threaded timers and delphix timer are not running at anwhere near 1ms on certain machines? And if so it may be because directx in Xp, or XP itself is somehow changing the way thread timers operate. Obviously someone needs to look into this issue. I cannot understand why it would be that the timer does not run at the desired speed.

There is something very wrong here...I have also checked at a mates house, again XP, again nowhere near 1ms.

I have ran some tests and it seems the following:

Intervals 1-10 are defaulting to 64 FPS, 11-20 to another fixed FPS and so on....the rates they are fixed at are also not remaining constant. For instance on my cousins machines the 1-10 are defaulting to 100 FPS and then following the same pattern mentioned above. I can't be the only one woth this problem?

Somone mentioned none NT based machines may be the cause? Is there anyway to make delphi believe it is running on an NT machine (i doubt it), or even better if noone has any idea why this is happening, maybe someone could supply a way of making a timer that can achieve a constant 100 FPS. Which is the best way to do it and have you got any example code?

----

Also, when I said centre and not stretch I meant the actual image as it shrinks;) stretch draw strteches the image to FIT the size of the height,width. I was wondering weather there was a way to let the image resize but the picture get its ends chopped off, if you see what I mean;)


http://www.uploading.com/?get=VXBP9UV9

That should make it clearer :):):)

Traveler
28-05-2006, 10:24 PM
Why is it so important to have a timer that runs on 100fps?
IMO all that matters is how fluent a game runs. And you can have that even at 30fps.

If I understand you correctly, what you are looking for is a crop function, not a resize. You can do so by drawing a portion of the image. When drawing the surface, dont use clientrect, but your own defined rect.
ie not

DXDraw1.Surface.Draw(0,0, yourImageSurface.ClientRect, yourImageSurface, false);
but

DXDraw1.Surface.Draw(0,0, rect(10,10,50,50), yourImageSurface, false);

seiferalmasy
28-05-2006, 11:02 PM
Yeah the problem is that my player sprites are moving around the screen fast, I tried 60 fps but the movement is jittery... and then with vsync we have the problem of it refreshing at monitors rate and I have yet to fully understand how I can achieve time based movement when I have a timer that is constantly changing depending on ppls monitor refreshes:( I will send you a small sample of what I mean, you will probably then be able to tell me if I have done something wrong?

Your help has been great btw.

I have looked at queryperformancecounter. Is this the best way of making my own timer? What is the best way for compatibility, reliabilty and speed?

TEST TO SEE SPRITE JITTER: http://www.uploading.com/?get=5TJ8Y0P0

Above is a file/source that I have quickly put together to demonstrate the jitter at 60 fps. This is the maximum speed the the sprite roams the screen but the jitter is unnacceptable. Maybe I have done something wrong?

-----
edit: actually moving on I have devised a nice way to get around this. I can just say Player1.x:=Player1.x + (1/Refresh rate of monitor) * 600 (where 600 is the amount of pixels to be moved a second).

This should mean the speeds involved when vsync is ON will always be the same does it not?

Traveler
29-05-2006, 07:57 PM
I've tested your game, but it apears to move as it should and without jittering. (Though extremely fast)

The movement of sprites has nothing to do with refreshrates. Only with time.


at game start up, get time
while your game is running
begin
calculate elapsed time for current frame
save newly retrieved frametime

Player1.x:= Player1.x * elapsed time
end;

This way it does not make a difference if someone is using 60hz, 85 or 100. Nor does it matter if a user has a 3ghz or a 700mhz processor. His sprite will always move at the same speed.

seiferalmasy
29-05-2006, 10:50 PM
Thanks for all your help, sorry for being such a nuisance:) I gave that test prog to my firnd and cousin, they say it runs like a broken pocket watch so I can only assume your successs with it is because you are using non XP or an NT based machine.

Regardless your help has been invaluble, thanks. And you prob aint seen the last of me yet;)

Traveler
30-05-2006, 07:39 AM
Thanks for all your help
No problem :)



I gave that test prog to my firnd and cousin, they say it runs like a broken pocket watch so I can only assume your successs with it is because you are using non XP or an NT based machine.


I am running xp sp 1, on a 3ghz pc with 1gig ram and a gforce 6800gt 256mb gfx card

seiferalmasy
30-05-2006, 09:33 AM
Thanks for all your help
No problem :)



I gave that test prog to my firnd and cousin, they say it runs like a broken pocket watch so I can only assume your successs with it is because you are using non XP or an NT based machine.


I am running xp sp 1, on a 3ghz pc with 1gig ram and a gforce 6800gt 256mb gfx card

Then must be something else..something I am missing Is yours based on NT technology? (not sure if xp can be, i remember win2000 being nt or not).

Something weird with them timers but doesnt matter now cause its staying on realtime from now on :) Envious of your G.card ;) I am getting the 6600GT 256 AGP 8* soon It is the thing I really need updating hardware wise;) At moment I am still using a geforce 2 MMX 400 64MB

czar
30-05-2006, 10:12 AM
The demo as is runs at 32FPS

XP 3Ghz, Nvidia 7800GS.

Get rid of the interval and I get about 2400 FPS

Getting rid of the dxtimer interval (set to 17) and setting option dowaitvblank. Made it the demo very smooth (85 FPS) - but way to fast.

I never liked the sprite engine. I have always made my own. Much more control.

Traveler
30-05-2006, 11:16 AM
Then must be something else..something I am missing Is yours based on NT technology? (not sure if xp can be, i remember win2000 being nt or not).
XP is nt based.

Perhaps your gfx card drivers are the problem. I remember a couple threads about slowdowns due to an nvidia driver update. That was a couple months ago so it might not be relevant, but then, you never know.

seiferalmasy
31-05-2006, 12:57 AM
I would believe that was the cause except that it runs way lower than 60 fps (when set to 17 interval) on my cousins and mates machines, 1 of which uses a radeon 9200 .

I have no idea why it would happen but I have ruled out the problem occuring within delphi becasue you recompiled and sent me back the exe. Its very strange. Not just the dxtimer as said...all threaded ones like the one by carlos barbosa.

While I am here though, How do I centre text taht is written on dxdraw.surface.canvas?

When I want to centre labels I just say

MainFm.Points_Label.left:=(mainFm.width-MainFm.Points_Label.width) div 2;

I was wondering weather there is an equivelent? I notice TextWidth but it isnt the actual pixel width just the no. of chars?

Traveler
31-05-2006, 11:31 AM
I was wondering weather there is an equivelent? I notice TextWidth but it isnt the actual pixel width just the no. of chars?

Not that I know of. You can't easily calculate the lenght of the text unless you take specific fonttypes, like courier (new), where you know the length of each character is always the same.

seiferalmasy
31-05-2006, 11:33 AM
I was wrong! textWidth does give its precise pixel length:) so now I just say

((Dxdraw1.width div 2) - (textwidth(Player2Name+': '+inttostr( points2 ) ) div 2) etc :) nice.

That avatar of yours is freaking me out by the way ;)

WILL
02-06-2006, 02:41 AM
That avatar of yours is freaking me out by the way ;)
I know, it's creepy isn't it? :)

seiferalmasy
02-06-2006, 06:51 AM
without a doubt:)

seiferalmasy
02-06-2006, 03:47 PM
The movement of sprites has nothing to do with refreshrates. Only with time.


at game start up, get time
while your game is running
begin
calculate elapsed time for current frame
save newly retrieved frametime

Player1.x:= Player1.x * elapsed time
end;



I have looked back on this to see if it is any better than the methods I have tried. How would I go about measuring the time of the frame etc? and getting time? How would I go about implementing the above?

I have a small prob now...game seems to jump even with vsync on...if I measure the frame rate of dxtimer during play I see it is going from between 79-85 (85 being my monitor refresh rate). Why isnt the frame rate steady? I use high priority mode and it seems to work alot better but then my controls go awkward and soemtimes don't respond. I have checked processes but nothinbg appears to be wrong.

maybe I have done something in the code or used an option in dxdraw that slows the game down? Someone mentioned lagcount being able to help in skipping situations?

Traveler
02-06-2006, 07:25 PM
IIRC lagcount is the equivalent of frametime.
ie player.x := player.x +1 * lagcount should work for you when using dxtimer.

Alternatively, when using your own gameloop (for example in the application.onIdle event.) the method I wrote above works.

Here's some sample code too (note: I haven't actually compiled it so it may contain a syntax error, but I'm sure it'll get the point across)

procedure mainloop();
begin
finished := False;

gameStart := GetTickCount(); // Get Time when demo started

while not finished do
begin
LastTime := ElapsedTime;
ElapsedTime := GetTickCount() - gameStart ; //Calculate Elapsed Time
ElapsedTime := (LastTime + ElapsedTime) div 2;

{.. your other stuff in here...}
player.x := player.x + player.xspeed * ElapsedTime
{.. your other stuff in here...}
end;
end;


That avatar of yours is freaking me out by the way :wink:
Wait until you see the next one :wink:

seiferalmasy
03-06-2006, 12:29 PM
and onto one of the final points:

Is anyone ever going to fix the buggy force feedback in dxinput?

I have 2 problems with that component. USB joypads don't seem to work at all with force feedback. If Usedirectinput is set to true also, a constant -x value is put into the input states from somewhere and the character just veers off to the left. I have to use analog to get around the problem....

Anyone know where I can contact soemoen who may be working on bug fixes to delphix in the hope they may consider sorting these issues?

seiferalmasy
05-06-2006, 02:22 PM
Problem making music play in my game. Plays ok but when the song needs to change the game crashes:


procedure setupmusic(thefile:string;looping:boolean);
var
WaveFormat: TwaveFormatEx;
begin
if (MainFm.Music1.enabled=true)then
begin
mainFm.Audio.AutoUpdate := True;
mainfm.Audio.BufferLength := 1000;
mainfm.Audio.FileName :=TheFile;
mainfm.Audio.Looped := looping;


MakePCMWaveFormatEx(WaveFormat, 22050, mainfm.Audio.Format.wBitsPerSample, 2);
mainfm.DXSound1.Primary.SetFormat(waveFormat);

end;
end;

I pass the file to be played in then say audio.play; It is some problem caused by not freeing the music? or not clearing the buffer?

Anyone know what I am doing wrong here, driving me nuts.

Traveler
05-06-2006, 08:34 PM
Just a guess, but it would seem to me that you can't actually set the buffer length to some random value.

seiferalmasy
05-06-2006, 08:37 PM
Even with no buffer the problem persists.

Seems to be something to do with the wave not loading in time. For example, if I enter the filename with 1 button, then use .play with another all works fine.

If I enter the filename and then after it add .play in the same button click I get all kinds of error messages:( i need the music to play from 1 music to the next. Any clue how I can achieve this? I don't want to go back to delphi mediaplayer

seiferalmasy
05-06-2006, 11:07 PM
Yeah I was right. Its because I am trying to play the file before the wav has loaded. Question is, how can I program it so that I can be sure the file has loaded and is ready to be played? I can't put sleep(2000) or something similar it just isnt good programming.

Traveler
06-06-2006, 07:38 AM
This is a bit of a unknown area to me, but I'd imagine the load function gives back a boolean result. Perhaps you can do something with that?

cairnswm
06-06-2006, 08:52 AM
Or load the sound files before you need them. This will cache them in memory until needed.

seiferalmasy
06-06-2006, 02:12 PM
well I put sleep(100) before the main loading and for some reason it all works. It isnt the loading of the file, seems to be maybe a bug in delphix, doesnt like the file loaded into memory and then processed straight away when going from 1 music to the next. a short stall in the program doesn't give it more time to load, just seems to rectify the problem. This can be a temp solution.

seiferalmasy
07-06-2006, 05:01 PM
Ok, so I want to add net support. This is the one area of delphix I am completely ruined on. I just need a simple explanation of how to make a label in 1 application display information passed from a variable on another if you see what I mean. From there I can probably manage to do more than nothing.

Any good tutorials around?

Traveler
07-06-2006, 06:56 PM
It's not entirely clear from your post, but if you're talking about netwerk examples, there are 2 demos that come with (un)delphix.

Perhaps they might offer some insight?

seiferalmasy
07-06-2006, 07:59 PM
yay;0 looked at those, they go into sending messages, seems very complicated. Its muchy better to start with something ultra simple:)

seiferalmasy
07-06-2006, 10:23 PM
and also yo traveller, did you finish that pop the baloon prog? It looks fun do you have an exe download? and did you make it with delphix?

cairnswm
08-06-2006, 06:03 AM
Networking is all about messages.

To make a label update based on a label on another computer you need to send a message from the one to the other to tell the label to update to the new value.

Traveler
08-06-2006, 07:46 AM
and also yo traveller, did you finish that pop the baloon prog? It looks fun do you have an exe download? and did you make it with delphix?

Yes, I actually have finished it.
I'm afraid I've been heavily neglecting my website in the pas few months. On top of that, (and I haven't got a clue why) the entire projects section is not function anymore, as well as a few other minor things.

I have some plans for a new site, that is more focussed towards the Village Defense game, but it'll probably take a few more weeks before some results are visible.

In the meantime, you can download Ptb from here (http://www.gameprogrammer.net/zip/popballoon_full.zip). (incl source code)

seiferalmasy
08-06-2006, 05:46 PM
was pas a typo? or have you just got pas files on the brain;)

that was a nice game of yours...i will look at the source code soon, see how you accomplished the baloons popping, very neat.

Are games faster /better in full screen mode or does it not matter?

WILL
08-06-2006, 11:16 PM
seiferalmasy: Wow, this thread is turning into quite a list of sub-topics. :) Why don't you try breaking it up by area of focus so that way when people are looking through old post, it's not so much of a jumble for them.

Also, you may even get a more focused response to one of your specific problems too. So it's kind of a win-win for both things. ;)

seiferalmasy
08-06-2006, 11:45 PM
ahh forget it....i just goin through the problems as they arrive...and they just keep on arriving hahaha :)

Luckliy most of the questions are being answered in 1 way or another;)

seiferalmasy
09-06-2006, 04:00 PM
Here is another.

Played my game on 2 machines. 1 a pentium 4 the other a crap pentium 3. Both computers running my game at 50 and 2% full speed respectively. bad graphics cards that is true, is this maybe because of no hardware acceleration support....

Should I be experiencing this kind of slow down when playing game on low end g. card?

ahh just to clarify:

If I use dxSpriteEngine1.Move(lagcount); this will make sure that the game will play at correct speed regardless of cpu etc?

Sorry for being useless ;) but another thing,

I have sorted movement of the main player using 1000/lagcount(which gives refresh rate?) as I am allowing vsync this changes. So I use dxSpriteEngine1.Move(lagcount); and then lagcount is passed to movecount. Now, heres the trouble. I can sucessfully make the player move at the exact same speed regardless of refresh rate using 1/refreshrate*pixels_to_move_a_sec.

That seems to work. Sadly the animation speed changes. I need someone to explain to me exactly how dxSpriteEngine1.Move(lagcount); works:( i need game to work at right speed regardless of refresh rate and cpu but at same time using dxtimer:(

Further small research I have figured the following: correct me if i am wrong.

a. Move(lagcount) will pass the value of lagcount into movecount.

b. The value passed into move does not alter the speed of the object, the forumla inside the domove is what ultimately matters

c. move(lagcount) should skip frames if the cpu is slow?

D. If I want to move my character by 600 pixels a second regardless of CPU/frame rate, the following should theoretically work? - (600/1000)*lagcount

-----------
I ahve also looked into the options of dxdraw but haven't found information regading:

Dohardware: I am assuming this should always be left true and is hardware acceleration

Doretained: ?

DoDirectX7: Why would I want this true?

DoSystemmemory: Faster to use vid memory so alwasy keep this off I assume

Doallowpallettextures: ?

DoZbuffer: ?

Docentre:?

Dostretch?

Doselectdriver: probably best to stay on?

I am playing 2D game in non full screen, Do I still need do3d and doflip?


thanks.

seiferalmasy
14-06-2006, 02:37 PM
Didn't want to start a new topic but....just tested your game traveller. Very nice.

Not got much playability with it, being a balloon game get bored easily but that isn't the point:) Great programming....

Bug found too, I got 71358 points and the game score reset to about 5000, suggest you use better variable for storing score?

Not bad at all.

Traveler
14-06-2006, 08:09 PM
Thanks! :)

IIRC there was a bug with the scoring system. Thought I had fixed it too.
Oh well. I hope you'll find the code useful...

seiferalmasy
14-06-2006, 09:09 PM
what about those last queries of mine above though:) yeah they prob are the last ones hahaha :oops: