Framework/engine design

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
wildrj
Posts: 301
Joined: Thu Mar 23, 2006 12:49 am
Location: Texas/ Cyberspace
Contact:

Framework/engine design

Post by wildrj »

Hello after talking with varmint for some time we came to the conclusion that my engine needs a complete rewrite. Its spaghetti like and no error checking or const use among other bad coding habits and "warning triggers"

So i was wondering on the designs you guys use for yours *preferably those who have had success with their engine*. Im looking for some designs and or techniques to get a efficient engine/framework

If you need more details id galdly give them.
http://wild.deathtouchstudios.com << My gamedev blog
<Programming is a way of life>
If at first you don't succeed press the delete key till you do :)
wildrj
Posts: 301
Joined: Thu Mar 23, 2006 12:49 am
Location: Texas/ Cyberspace
Contact:

Post by wildrj »

Well :P looks like this thread got deemed another "noob engine thread" but id like you to know i have found some resources and a design which i am going to attempt to implement. Ill be documenting all progress on my blog for those who are interested.
http://wild.deathtouchstudios.com << My gamedev blog
<Programming is a way of life>
If at first you don't succeed press the delete key till you do :)
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Only general techniques I can think of:

- Checkout other engines, especially the interfaces.
- Code applications first. After you wrote 2-3 applications with as little code as possible you will start see which parts turned out to be useful in all of them. Try to make that parts application independent.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

presumably you've also learned what went wrong with your original engine... what was difficult to use about it? what was easy and powerful to use about it? That should give you some good ideas on what you need to do better or retain from your original engine.

the use of the engine is possibly a factor in its design too... what type of games are you planning to use it for? or is it going to be a more general engine?
Image Image Image
jpoag
Posts: 25
Joined: Mon Aug 10, 2009 1:00 am

Post by jpoag »

Yeah, I was going to post last night, but I linked to your blog, then to the parallel engine design, then to demos...

I concur with the iteration approach for an engine. You can't really know how it will perform until you write a game with it.

I've released a couple commercial games and each time I've rewritten significant portions of code between projects. Sometimes I'll borrow features of other engines to integrate into my own.

As for a parallel engine, if your first engine looked like spaghetti, then I suggest a more refined version of that (to apply learned lessons) instead of jumping to a whole new design.

Also, if you use Visual Studio, I suggest Visual Assistant from whole tomato. You can right click and encapsulate an entire field or document a method...right click and generate half your code....
-James
wildrj
Posts: 301
Joined: Thu Mar 23, 2006 12:49 am
Location: Texas/ Cyberspace
Contact:

Post by wildrj »

I did find parts of my engine that would have taken a bit of time to rewrite most notable were the physics, Scene Loading, Entity Management. So that alone is about half my old engine. Also has I stated in my blog there was no error checking it presumed everything was just "correct" The engine was also designed as I coded there was no initial "design" I just kept adding things.

With the new engine I’m going to attempt to fully design it in Visio and go from there. I’ll be uploading some example diagrams later today.
I was hoping for a more general engine that could fit any game. I hope to accomplish this by creating smaller games and implementing the features in the engine as I need them. This way in the end i get a series of small games as well has an engine to add to my portfolio. I also plan all games and the engine itself to be cross platform.

If you read the design link it introduces a lot of concepts I’m not too familiar with so this will broaden my programming abilities. It’s also much easier to learn has you need it rather than sit down and just read articles on how to do something and just using simple “Hello world”.
The part of my engine that was spaghetti was mainly the scene loading part *you can look at it in the svn*. It worked for the most part but I’m not happy with the overall design of the engine. Plus my old engine was sort of rushed for the deadline.

What are your personal experiences with threading an engine? There are not a lot of articles talking about this considering many believe it to be “Advanced”.

Any extra articles or explanations of various things I’d gladly take.

P.S: Sorry if this post jumps around randomly its 7:50am and I’m in class typing this.
http://wild.deathtouchstudios.com << My gamedev blog
<Programming is a way of life>
If at first you don't succeed press the delete key till you do :)
haffax
Posts: 13
Joined: Wed Jul 29, 2009 1:40 pm

Post by haffax »

Designing an engine in UML never worked for me. Especially since class diagrams only show the static aspects and modeling dynamic aspects is way too tedious this way.

After getting enough general ideas from the internet, books, etc. I start on paper by laying out subsystems in a a way that seems sensible to me. Then start to think up scenarios/stories, whatever you want to call it and think how they would have to work.

What I am now developing uses pretty much the layout used in Nebula's application layer. It is explained here: http://flohofwoe.blogspot.com/2007/11/n ... vides.html

Message handling is a bit different, as I bind them to methods using delegates. instead of having a single handleMessage() function and other details are different too.

Radon Labs are nice enough to provide drops of their own engine under a liberal license, you can get it here: http://flohofwoe.blogspot.com/2009/04/n ... nload.html

Really a treasure trove of ideas already put into code.
jpoag
Posts: 25
Joined: Mon Aug 10, 2009 1:00 am

Post by jpoag »

wildrj wrote: What are your personal experiences with threading an engine? There are not a lot of articles talking about this considering many believe it to be “Advanced”.

Any extra articles or explanations of various things I’d gladly take.

P.S: Sorry if this post jumps around randomly its 7:50am and I’m in class typing this.
It's not really 'advanced'... When I was in college, we had a course that spent a large section talking about threading issues and we had assignments to create little programs...

Jump forward several years later and libraries like Boostmake cross-platform threading simple. Things like Signals/Conditions, mutexes, etc...

I use threading for asset loading (and level loading), decoding video/audio and in the last game some custom post processing (render a scene to sepia and cut into jigsaw pieces).

Really, the asset loading was the most important, and decoding video in a separate thread was a must. If I were going to do physics, I would kick off (resume) the physics thread at the beginning of my global update and wait on it to finish at the end of the global update. Probably to keep my physics from getting ahead of my game.

pseudo code:

Code: Select all

OnGlobalUpdate()
     Modify physics engine // (add impulses from user input)
     ResumePhysicsThread // (ODE->Update(0.01)) in a thread

     /// ... ///  Non physics dependent code

    WaitOnPhysicsThread() // JOIN
That Parallel engine article has some interesting ideas but I think that for my purposes I would probably simplify it a lot until really, all I had was the thread pool manager (in lock step mode). Many physics engines have their own internal set of data objects. ODE, Box2D, Chipmunk... so the whole Observer pattern is probably overkill. (although I can think of some improvements to the observer they're using with {Read, Read/Write} attributes to an observer, CopyOnWrite, and invalidating local copies.


Anyways, I suggest looking into Boost Thread, Signals2/Slots, Accumulators (Perf testing?), and the testingstuff. The testing might be overkill for a second iteration of an engine. Probably just need to check all inputs into a method and all outputs from a function.
-James
wildrj
Posts: 301
Joined: Thu Mar 23, 2006 12:49 am
Location: Texas/ Cyberspace
Contact:

Post by wildrj »

I have seen / used the boost lib before its really nice but it adds a huge dependence to the engine. Id also like to learn raw threading *pthreads and winthreads* and by learning to do these implementation it adds another nice thing to my portfolio :D

Also haffax im using the diagrams to just make sure i follow the engine design. Each part is being diagrammed out so i will know what goes were etc and how each one will interact. Also makes a nice visual aid for documentation if needed.
http://wild.deathtouchstudios.com << My gamedev blog
<Programming is a way of life>
If at first you don't succeed press the delete key till you do :)
yamashi
Posts: 82
Joined: Sat Jan 03, 2009 4:53 am

Post by yamashi »

pthread and winthreads are really nice, you can build your own thread lib based on it.
For my engine i made a job system :
say I want to execute a lot of parrallel tasks but short and fast, creating a new thread context each time I want to execute a job is expensive and useless. So i decided to make a fully virtual job class and then I just make childs and send them to the job manager which will execute the jobs on threads that have been running since the thread manager was created.
Example :

Code: Select all

class Inc : public CJob
{
public:
Inc(coherent_block<int>& __In):mData(__In){}
~Inc(){}
void Run()
{
mData++;
}

private:
coherent_block<int>& mData;
};

coherent_block<int> data;
data.setAtomic(true); // Thread safe
data.setCoherent(false); // Do not sync with CUDA memory
data.setPageable(false); // Pinned memory
data = 0;
for(int i = 0; i < 80 000; ++i)
ThreadManager::getInstance().SendBlock(new Inc(data));
Post Reply