PDA

View Full Version : My First 3D Game



cairnswm
15-11-2005, 06:02 AM
Last night I started working on some 3D stuff. I've been avoiding 3D with a passion but lately decided I better start trying it out again (Mostly as there are kids half my age on www.nag.co.za that know more about it than I do... Making me feel bad :) ) - anyway I downloaded GLXTreem v2 and gave it a try.

Here is a screen shot of what I got right after about an hour - the lazers are particle effects:

http://www.cairnsgames.co.za/files/lazers.jpg

Not quite sure what I've going to do with this - maybe make a 3D space invaders - or the attack by Luke against the death star - I've always thought this would make a great 3D game.

cairnswm
15-11-2005, 07:47 AM
A first download:
http://www.cairnsgames.co.za/download.asp?file=files/AlienInvasion-Install.zip (0.5MB)

You will also need FreeImage.dll available here:
http://www.cairnsgames.co.za/files/freeimage.zip

Traveler
15-11-2005, 08:45 AM
Looks pretty good!
How is GLXtreem doing for you? I've downloaded and tested some of the demos of this new version, myself a couple days ago and I must say they were very impressive. Especially the little shooter (the physicsdemo iirc) was quite nice.

I thought you were working on something else though. Perhaps an opportunity to combine it with your 3d endeavour?

technomage
15-11-2005, 10:28 AM
That looks really good. I'm beginning to wish I wasn't writting my own 3D engine now :( I've been working on Alert Fighter for a while now and I don't have particle effects done yet. mind you I've been writting the support stuff like asset loaders and managers, editors for generate the assets etc, this is the stuff people don't think about when writting a game, I know I certainly didn't..:wink:


Is that a Sky box background? or just a flat background?

I'll try and download the demo and give it a shot later today.
:D

cairnswm
15-11-2005, 10:45 AM
Thanks guys.

Actually all the code, models, textures etc in this little App come from the GLXTreem Demos :) I just did a liberal dash of copy and paste.

The base of the game is the Models demo - I replaced the Jeep with the space fighter. Also added a couple of extra fighter for fun.
I then took the Skybox from the Path Following demo and added it to the program.
I then took the point emmitter from the Particles demo and modified it so that the particles would come from the sources I wanted them.
Using the rotation logic of the Physics demo I was able to start adding rotation for the Space craft.

Sorry - absolutly nothing original in that exe :)

I do not want to be writting engines. I am prepared to write wrappers for existing engines. I believe there are enough people out there who are good at writting engines. I want to write game and am therefore very thankful for engine writters. So I am always happy to use engines.

On what I think of GLXTreem - I used GLXTreem until the end of 2003. I then found a lot of problems on screen color depth, resolution etc and dropped it in favor of SDL. Yesterday I wanted to do some 3D stuff and remembered the ease GLXTreem had for loading Milkshape models. So I downloaded it at 8pm last night - it took about an hour - and by 10pm I had the demo you see there. So so far I am very happy with it :)

technomage
15-11-2005, 12:21 PM
Thanks guys.

no worries :D



I do not want to be writting engines. I am prepared to write wrappers for existing engines. I believe there are enough people out there who are good at writting engines. I want to write game and am therefore very thankful for engine writters. So I am always happy to use engines.

I would love to use someone elses engine, I had a hard time finding an engine that did what I needed it do, so I ended up writing my own from scratch. Many engines are FPS engines now, apart from FreeSpace2 I don't think I've ever seens a space combat engine that people can use. :(


I wanted to do some 3D stuff and remembered the ease GLXTreem had for loading Milkshape models.

If you still want to use SDL I have a milkshape model loader which is jut about stand alone, I can let you have a copy if you want... :?:

FNX
15-11-2005, 01:28 PM
Hello,
I think it's a good start for you :)

I would learn how to code 3d stuff but I'm too lazy and in love with old
school games to.. I've promised myself to never code 3d games/apps
so i'll continue with 2d. Maybe i'll add particle and lightining stuff to 2d.

About using someone else engines well, it's always the same question,
better to use already existing code (with potential limitations) or write
my own one (more time needed but re-code what already exist?)?
;)

Let us know about updates :)

PS: there is always younger people doing something better :oops:

Sly
16-11-2005, 03:07 AM
I do not want to be writting engines. I am prepared to write wrappers for existing engines. I believe there are enough people out there who are good at writting engines. I want to write game and am therefore very thankful for engine writters. So I am always happy to use engines.
I would like to use someone else's engine, but I have never found one that I would deem suitable. Most engines I have seen, especially for Delphi, heavily use classes and dynamic strings. Yeah, they're easy to use, but horribly inefficient when it comes to memory usage. This may come from my commercial game development background, but efficiency is key to making a good engine.

I want a lean, mean rendering machine, and I will probably have to write it myself.

cairnswm
16-11-2005, 04:48 AM
I do not have the low level understanding to be able to write engines etc. For this reason I use engines in what ever state they are. If the engine is not fully optimised I can live with it. I dont need 1000FPS, as long as I get above 30 FPS on my notebook I can be reasonably happy it will
behave well on other peoples PCs. My game typically do not need such brute power :)

Traveler
16-11-2005, 08:57 AM
Perhaps a bit off topic but I was wondering if you, Sly, could elaborate a bit more on your argument of classes and dynamic strings being inefficient?

Sly
16-11-2005, 09:30 AM
Any time you modify a string, mostly when adding to it, it has to reallocate the memory for that string. This usually involves a new memory allocation, copy the contents of the old string to the new buffer, then free the old memory buffer. Look at this over the lifetime of an application and you are talking about potentially millions of tiny memory allocations and frees.

If you ever declare variable as a string or a dynamic array in a function, the compiler secretly adds a try..finally block around the entire function to free the memory used by those strings and dynamic arrays. That takes extra CPU time to execute each time the function is called.

TObject, the base class for every class, contains string members. The process to create an instance of a TObject-derived class is quite expensive. The creation of each instance of a TObject-derived class involves multiple calls to InstanceSize(), which then allocates the memory for that instance. It then sets that memory to zero. It then performs a while loop, inside which is a for loop, to setup the interface table for that class instance. Remember, this is for each instance of the class that you create. There are similar expenses when destroying the class instance.

Unless you override some base methods in TObject, there is also no way to bulk-allocate a bunch of class instances. Each class instance must be created individually. That is horribly expensive when you might be talking about using a class for a vector or matrix. A mesh might have 10,000 vertices. That is a lot of needless overhead, and the time wasted can be noticed by the end user in longer load times.

As I said, this comes from having a commercial games development, and the amount of overhead in using TObject and strings rings alarm bells in my head.

cht666cht
16-11-2005, 09:59 AM
Does TObject have String members? if you look the code in the System unit it only has methods, and InstanceSize returns only 4 bytes.

Sly
16-11-2005, 10:11 AM
Ahh, got that bit wrong. The class itself doesn't have strings as members (the four bytes is a pointer to a virtual method table). The virtual method table (one table for each class) contains strings, but these are of the ShortString type.

LP
16-11-2005, 03:55 PM
Unless you override some base methods in TObject, there is also no way to bulk-allocate a bunch of class instances. Each class instance must be created individually. That is horribly expensive when you might be talking about using a class for a vector or matrix. A mesh might have 10,000 vertices. That is a lot of needless overhead, and the time wasted can be noticed by the end user in longer load times.

As I said, this comes from having a commercial games development, and the amount of overhead in using TObject and strings rings alarm bells in my head.
Perhaps if you had the same experience with C/C++ (please, don't throw any rocks), you should know that creating a class for each primitive like point or vector might not be a very good idea considering the performance.

Many libraries I have seen and have worked with, including Asphyre (which I am developer of) use clases to represent a single-instance objects like Canvas and use records and record arrays to store points, vertices, normals, matrices and so on. In fact, in my Asphyre library, there are primitive storage classes like TVectorList, which stores an array of TVector4 records and have method like Transform, which receives a pointer to the matrix and then multiplies all vectors in array either using a multiplication procedure (which is not part of any class), or using a batch procedure, which uses SSE to transform all vectors. No offence, but I really think you should review the libraries and how they work before doing really serious claims.

Traveler
16-11-2005, 04:01 PM
Thanks for the explanation Sly. Very informative.




No offence, but I really think you should review the libraries and how they work before doing really serious claims.

No need to...


Most engines I have seen, especially for Delphi, heavily use classes and dynamic strings.

Could be that yours was not among those Sly used.

LP
16-11-2005, 04:09 PM
Most engines I have seen, especially for Delphi, heavily use classes and dynamic strings.

Could be that yours was not among those Sly used.

This was written in Asphyre forum on 11 of July, 2005:

I was involved with Powerdraw when it was first released, and contributed a few fixes to it. However I never continued with it. I've always considered the use of components or heavy use of Delphi classes to be overkill and quite inefficient. Maybe that comes from my console development background where you have to be careful about every function call that you make.

I think Sly *is* referring to Asphyre and I would like to see the proof, that the usage of classes in Asphyre makes it inefficient.

technomage
16-11-2005, 09:54 PM
Unless you override some base methods in TObject, there is also no way to bulk-allocate a bunch of class instances. Each class instance must be created individually. That is horribly expensive when you might be talking about using a class for a vector or matrix. A mesh might have 10,000 vertices. That is a lot of needless overhead, and the time wasted can be noticed by the end user in longer load times.


This is exactly what i did for my engine, I created a TFastObject which just alocates memory and sets up the VMT but that's it, the performance increase just by doing that was very significant. I also tested allocating 10000's obf objects in an array by pre allocating the memory using a Frame Memory manager, again the performance was significantly improved.

I tend to use records for things like verties and normals as they tend to be easier to pass into opengl, but I always use objects for my engine, but since I derived from my TFastObject things work allot faster :D

cairnswm
17-11-2005, 05:16 AM
If anyone is interested in my progress:

http://www.cairnsgames.co.za/download.asp?file=files/AlienInvasion-Install.zip (0.9MB)

Each to their own I say. I WILL use classes and long strings becuase it makes my life easier.

cht666cht
17-11-2005, 09:04 AM
technomage, could you explain a bit more the implementation of your TFastObject, or show some code? it seems very interesting.

Thanks! :)

technomage
17-11-2005, 11:40 PM
I decided to write a short information sheet on the implementation of TFastObject over at Cerebral-Bicycle (http://www.cerebral-bicycle.co.uk), you can read the article here (http://www.cerebral-bicycle.co.uk/viewdoc.asp?doc=326) :D

Hope you find it usefull, if there is enough interest I'll post the stuff on a Frame Memory manager at some point and how it links into the TFastObject to make creating 1000's of objects even faster.

LP
18-11-2005, 12:47 AM
I decided to write a short information sheet on the implementation of TFastObject over at Cerebral-Bicycle (http://www.cerebral-bicycle.co.uk), you can read the article here (http://www.cerebral-bicycle.co.uk/viewdoc.asp?doc=326) :D

I've read the article and an alternative has occured to me. Why not using "object" declaration instead of "class"? This way you can create a large block which will contain 10000 of such objects at once and then assign correct pointers to each of them. In addition you may use a replacement memory manager like FastMM to improve the performance.

cairnswm
18-11-2005, 06:08 AM
A new update has now been loaded. (Same location as above) Alien Invasion is now starting to look like a game

Aliens now fly toward you and shoot.
You take damage from their lasers - but can still crash into them.
You get score if you shoot an alien.
You lose score if an alien gets past you.
You can move left and right a little faster.
F4 to turn AutoFire on - you cant turn it off yet.
f6 to make the game faster.
F5 to make the game slower.

No effect yet when you die. Aliens just contiue but you cant do anything.
ESC to quit.

savage
18-11-2005, 07:59 AM
[quote="technomage"]I decided to write a short information sheet on the implementation of TFastObject over at Cerebral-Bicycle (http://www.cerebral-bicycle.co.uk), you can read the article here (http://www.cerebral-bicycle.co.uk/viewdoc.asp?doc=326) :D

Hope you find it usefull, if there is enough interest I'll post the stuff on a Frame Memory manager at some point and how it ]

Great stuff Dean! It wouldbe great to get this into the Articles section on PGD as well.

technomage
18-11-2005, 08:48 AM
I've read the article and an alternative has occured to me. Why not using "object" declaration instead of "class"? This way you can create a large block which will contain 10000 of such objects at once and then assign correct pointers to each of them. In addition you may use a replacement memory manager like FastMM to improve the performance.

"object" is an alternative, but I'm not sure how much faster it would be, besides the benifited of deriving from a "class" I think would outweigh the benifits of using "object". I found an article on this at http://www.engineeringobjects.com/BooksAndPapers/BadDelphi.htm. At the end of the day it's down to personal preference. I know Delphi recommend NOT using "object" but I don't know if Free Pascal recommend then same thing :?:

Replacement memory managers are also a good move, I've used QMemory in my application, in conjuction with the changes I made in TFastObject.

cht666cht
18-11-2005, 10:32 AM
I decided to write a short information sheet on the implementation of TFastObject

Thanks again, I'll read it when I've a little time, it looks interesting.

cht666cht
18-11-2005, 10:40 AM
I've dowloaded Alien Invasion, it seems a good starting for a space shooter :)
I'm making something similar, but using GLScene. I'll post it when it is a little more advanced

alexione
18-11-2005, 11:49 AM
Quotation from Delphi's help for TObject.NewInstance:


Override NewInstance only for special memory allocation requirements. For example, when allocating a large number of identical objects that all need to be in memory at the same time, you could allocate a single block of memory for the entire group, then override NewInstance to use part of that larger block for each instance.

One more way to get faster allocation is to use good-old free-lists. Example: let's say we have object for each dynamic effect. Instead of creating new effect each there happens, you just don't deallocate old one, but mark it as "free-for-use", put it in "list-of-free" objects, or whatever, and your allocation gets even faster!

technomage
18-11-2005, 12:40 PM
I agree "Free Lists" are the way to go with things like Particle engines, where you could be creating and freeing 1000's of objects at the from one frame to the next.