PDA

View Full Version : Speedup: basics



Rojekti
26-03-2007, 02:08 PM
Welleeh. I just dumped DelphiX after use of couple years. Sorry for noobish questions :-) I'll just ask them quickly and you'll get rid of me! ^^


So. If someone told me few things, I'd find out rest of things by my self..

Basic idea of drawing images on 2D-surface..
1. Loading images. Where I load them? Where's this ImageList which I'm used in DelphiX?
2. When I've got images loaded, it's probaply very simply to draw them; asphyrecanvas.draw(blabla,...

In fact, my big rpg/adventure/surviror/etc- game project's graphics are now mostly made with DelphiX's Draw- functions.. I'm planning to change the game from DelphiX -> Asphyre. There are my own Draw- procedures which draws given images in given positions. Will it be hard to move it to work with Apshyre?


Umm, this wasn't good post.. well, I'll write more when problems appears!

Got truly excited of this package :) Amazingly powerful. Just hope I could use it. Shouldn't be hard.

Robert Kosek
26-03-2007, 03:24 PM
Hey Rojekti, could you be a little bit more specific? Are you wondering how to draw an image on the canvas? Are you using Asphyre 3.1 or one of the beta 4 versions? The last question is very important, as how the canvas works has changed for version 4.

Rojekti
26-03-2007, 03:46 PM
Oh, sorry. As far I know, I'm using Asphyre eXtreme v3.1.0!

Yes, I'm trying to draw an image to canvas, also I'd like to know how I can control images; DelphiX has this ImageList- item where I can load manually images from file, then using ImageList's procedures, draw it on screen;

So first load the items to the list; imagelist.items.add(...), then draw them; imagelist.item[x].draw(...). How it could be done with Asphyre eXreme? Just simply 2D.. :)

Robert Kosek
26-03-2007, 03:58 PM
Aha! Well, I wrote a semi-complete game in Asphyre 3.1 and released the full source under the MPL. You are more than welcome to look at that as a way to learn to use Asphyre, and since it's a very simple game (I'm more or less a newbie in the whole realm of game programming, though I know Asphyre well) it won't take you very long at all.

There are many examples and discussions on the main forums there, afterwarp.net, and I would advise you to read a few of the samples available there.

Anyway, here's a link to my project (http://www.afterwarp.net/forum/thread818-2.html#td_post_6196) which you can dissemble at your leisure.

Asphyre uses a "TAsphyreImages" component, which then loads all images from an archive. Try looking at the examples provided and checking the form components, and how they are used. :)

Rojekti
02-04-2007, 12:28 PM
Hmm, it seems to be that your game doesn't work with my Delphi.. I got Delphi 7.0 and Asphyre 3.1 eXtreme; gives some odd errors of your code's syntax, weird. Which Delphi you have?

But, anyway. I read the code completely, then I searched with google and this forum's search engine everything that could help me but hmm, didn't found answers..

Well, umm.. I got now these components on my form; AsphyreTimer, AsphyreImages, AsphyreDevice and AsphyreCanvas.

So this is how it goes: I must load images to AsphyreImages and then draw them with AsphyreTimer to AsphyreCanvas (someone could tell me why there are AsphyreDevice and AsphyreCanvas separated :o is it that A-Canvas "sends" screen for A-Device which shows it on screen? :D).

So, since I'm trying to move my RPG-project from DelphiX to Asphyre, I'm now trying to create just a little testing program to make Asphyre familiar to me..

This program now has AddImage and DrawImage- procedures. AddImage adds given images to AsphyreImages and, oh man, it should be so simple, but it just doesn't work; I should draw image on AsphyreCanvas..


First load:


with pics.Add do
begin
{ Quality := aqHigh;
AlphaLevel := alFull; }
PatternSize:= Point(wi, he);
Size := Point(wi, he);
VisibleSize:= Point(wi, he);
LoadFromBitmap(sad, true, 0, 15);
Name := extractfilepath(kuva);
end;



And so on.. there's one problem: Delphi claims that "aqHigh" and "alFull" are undeclared identifiers! What's wrong? I even improvized; I added ImageFX to Uses- list but it didn't help..


And then, draw.. hmm, screen stays black:



can.Draw(pics.Item[0], x, y, 0, 0);


..the last parameter (last zero there) should be fxBlend or some other mode.. but Delphi claims them also as undeclared identifiers! Is that why nothing happens?


I do initialize Device in OnCreate of Form, and there are Begin- and EndScene- functions in Device.Render.. Should images be drawn in Device.render or with AsphyreTimer?


Oh man.. :/ am I just so noob? :( Seems to be that Asphyre requires kinda more "standard" programming style :) heh, I should learn that style too..

Rojekti
02-04-2007, 12:34 PM
Oh, yes, one more thing..

AsphyreImages loads images from archive.. well, umm. I think it's still possible to load images from file, from folder? It would be great. In fact, I really need this kind of a feature. I don't want to load them from some weird archive :( I did found some program from Asphyre's Example- folder, it made those archives from chosen images.. but noooo! :o just trying to load them from folder :/

Robert Kosek
02-04-2007, 01:55 PM
Yes, you can load your images from a file, but this isn't recommended. What if you want to animate an image like you do with sprites? Without adding to the archive, an ASDb file, and converting it to an AsphyreImage it won't work. It's too convoluted a process.

I used Turbo Delphi, BDS2006 dumbed down, so there might have been a few things. But, the problems you describe come from not including AsphyreDef in your Uses clause. :) My code might be rather amateur, but aside from the sound system there really aren't any bugs that I've found or been notified of. (On some computers there are instant crashes, which near enough as I can tell is related to the music. Odd, but I can't really explain that one.)

Once you get AsphyreDef in, remedy your aqHigh/alFull and fxBlend problems you should start to see results.

Half the problem seems to be that you aren't wanting to adapt, and so want to continue to use what conventions you are used to. In the end, you'll see that Asphyre is extremely powerful, and that you don't even have to stay where you are comfortable. To that end, I've worked with Asphyre 4 and extended it slightly to support ZIP archives ... so you just define all your resources in XML and then load them by groups from a Zip Archive. Wasn't hard, but it wasn't like I used to program either.

Rojekti
02-04-2007, 02:42 PM
Hmm, interesting, and sad :/

Well, I'll explain.. when I'm using DelphiX and I'm animating images (in the qurrent project), I have just done 5 DIFFERENT FILES for each frame. Must sound horrible, but it really does work. Qurrent system loads in the beginning all those images from grf- folder to DelphiX's ImageList and after that, I'm able to use them all without loading them from folder. Images are small, there are probably 10-20mb of them. Isn't this really possible in Asphyre? To load all the images in startup to lists and later use them from the list?

DrawImage(image+f(frame), x,y, w,h)...

Well, that's really true, I'm in love that system.. :D need some therapy..

Thanks for the Uses- tip! I'll try it immediately. Probably it helps :-)

Hmm, well, umm. Probably I must adapt, though it hurts me. I'll just have to study those examples and your program to get this all. Too sad there aren't good tutorials for Asphyre!

Robert Kosek
02-04-2007, 08:17 PM
Half the problem is that folks are too busy using it to make things, than they are writing tutorials. Reading the sourcecode of the library and existing applications works pretty well though. ;) The wiki is making some progress on tutorials as far as I know.

Yes, this is possible. You can also use "fasttile" under tools, to generate an animated sprite based off one of the 5 pieces, and all its frames. Then just add it in and load it all at once. It's completely possible, but sometimes not efficient enough for what you might want to do.

Rojekti
03-04-2007, 02:26 PM
Yes, that's maybe true. Well.

I got it working. Basic problems are now away. Just very simple graphics; that's all I had to achieve now.

Thanks for help! It really helped. Though I'm too stubborn to do things in right way.. some weird neurotic habits.. well, that's how I did it, could someone tell me how dumb is this:


First images are loaded from their directory; there's loadimage- procedure. It adds all the images from given folder to the AsphyreImages. Tolerance etc. sizes can be invidually changed for each image..

Then just, simply, I draw images with AsphyreCanvas' different procedures..

Umm, that wasn't so new.. well, anyway. Does it make the program heavier in memory usage etc. when I load them straight from folder to AsphyreImages and destroy everything in the end? I load all the images in the beginning so there will be no loading of new images when the game has started..

LP
03-04-2007, 03:59 PM
Does it make the program heavier in memory usage etc. when I load them straight from folder to AsphyreImages and destroy everything in the end? I load all the images in the beginning so there will be no loading of new images when the game has started..
No, this is exactly the suggested behavior with Asphyre 4 (although you can be loading images "on-the-fly"). An expection to this: if you are using render targets or dynamic textures, you will have to re-create them after the device has been recovered from lost state (they will be released automatically).

Rojekti
03-04-2007, 07:51 PM
Mmm, yes yes. Thanks for information!

But now I got one familiar problem.. so, the Ultimate Decimal Problem has appeared also with Asphyre now. I was just converting the whole game from DelphiX to Asphyre and when I finally got the code itself compiling with no errors, (umm, "with no errors") it threw the traditional "1077,0000293953 is an invalid integer value".

In this (http://www.pascalgamedevelopment.com/viewtopic.php?t=4227) thread I cried about this problem. I tried the mentioned codes.. neither one didn't work:


Set8087CW((Default8087CW and $FCFF) or $0200);

or


SetPrecisionMode(pmDouble);

The first one did help with DelphiX but what about Asphyre? They didn't help![/url]

czar
03-04-2007, 08:13 PM
It is possible that Asphyre sets the precision to single when it is initialized. So make sure you set pmdouble later in the program, after Asphyre has been set up.

Rojekti
04-04-2007, 01:13 PM
Hmm. Doesn't help. It's always the same number; "1077.00<something>...".. And the error shows even when I turn the whole program off; it doesn't do anything, and I shut it down.

Hmm. Weird..

Robert Kosek
04-04-2007, 02:10 PM
I have no clue about what that might be. In fact, I haven't ever experienced it. So I can't help you there. Are you loading something that is a float value? Or perhaps, outputting something into a string that is a floating point value?

LP
04-04-2007, 03:49 PM
Hmm. Doesn't help. It's always the same number; "1077.00<something>...".. And the error shows even when I turn the whole program off; it doesn't do anything, and I shut it down.

Hmm. Weird..
Why don't you debug your program to see exactly where the problem occurs? Also, any reason you need to use double-precision floating point numbers? AFAIK, using double-precision with Direct3D reduces the performance.

Rojekti
04-04-2007, 03:56 PM
Oh well, now it works! Maybe I placed those fixing codes in a wrong places.

Well, I'll be here soon if more problems appears :-)