RPGDXThe center of Indie-RPG gaming
Not logged in. [log in] [register]
 
 
Post new topic Reply to topic  
View previous topic - View next topic  
Author Message
zenogais
Slightly Deformed Faerie Princess


Joined: 10 Jan 2006
Posts: 34

PostPosted: Tue Jan 24, 2006 4:04 am    Post subject: Design Patterns In Your Programming [quote]

I recently began work on a game engine of my own a while back, being my first real game engine, I've no doubt ran into many coding problems. Luckily for me I had been reading a lot about design patterns recently as they have pertained to several PHP apps I had been writing. Long story short I came upon the Observer pattern or more specifically the Model-View-Controller pattern. Needless to say this has improved the look, functionality, modularity and readability of my code extensively and I will probably continue to use it.

What design patterns do others here use, what for, and how, if at all, has it helped you?

Note: I am using Model-View-Controller to seperate Players (Model) from the way they are drawn (View) and the way they are interacted with (Controller) by creating a central event management class which allows listeners to subscribe and receive certain types of events (right now they can subscribe to mouse, keyboard or miscellaneous events). Thus when the PlayerController class receives a keyboard event, it sends out a PlayerMovementRequest event which is read by the Player model and translated into a new internal position which then sends a PlayerMovementEvent to the GameView class which redraws the player at the new position. phew...I'm out of breath :P[/i]
Back to top  
Nephilim
Mage


Joined: 20 Jun 2002
Posts: 414

PostPosted: Tue Jan 24, 2006 4:18 am    Post subject: [quote]

Well, in addition to programming design patterns, there's actually a book on game design patterns called "Patterns in Game Design" (by Bjork and Holopainen, available at Amazon and elsewhere) which may be of interest to you.

With regard to actual programming design patterns, I think a neat one is the "decorator," which is a handy way to implement spell effects that influence character stats and such. Hang a "decorator" off of the "strength" attribute, and you have a nice encapsulated way to have a spell effect boost or drain strength, which can be easily removed when the spell effect wears off. (Alternatively, you could use the "composite" pattern to do something similar, depending on how you set it up.)
_________________
Visit the Sacraments web site to play the game and read articles about its development.
Back to top  
LeoDraco
Demon Hunter


Joined: 24 Jun 2003
Posts: 584
Location: Riverside, South Cali

PostPosted: Tue Jan 24, 2006 7:11 am    Post subject: [quote]

I use composites and visitors fairly frequently in my programs. My graphics base code features singletons, flyweights, strategies, states, and factories patterns. A project I have at work has amongst its patterns the adaptor, bridge, and abstract factory patterns. It is not uncommen, either, to find several of those meshed together into some sort of uber-pattern.

Yeah: DPs are fun stuff, especially as they radically simplify certain aspects of design.
_________________
"...LeoDraco is a pompus git..." -- Mandrake
Back to top  
Nodtveidt
Demon Hunter


Joined: 11 Nov 2002
Posts: 786
Location: Camuy, PR

PostPosted: Tue Jan 24, 2006 2:05 pm    Post subject: [quote]

This looks like yet another excuse to toss around buzzwords. :)
_________________
If you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows. - wallace
Back to top  
Nephilim
Mage


Joined: 20 Jun 2002
Posts: 414

PostPosted: Tue Jan 24, 2006 2:52 pm    Post subject: [quote]

Yeah, design patterns are buzzish nowadays, but they do have some usefulness in terms of communicating how you structure your code.

For instance, if you know the person you're talking to understands design patterns, you can just say "that's implemented as a decorator" and he/she will know what you mean without you having to explain how it's organized. (And if they don't know what a decorator is, all you have to say is "that's implemented as the decorator design pattern - look it up and bug me no further". Heh.)

Maybe we should talk about using design patterns for "Web 2.0"...
_________________
Visit the Sacraments web site to play the game and read articles about its development.
Back to top  
LeoDraco
Demon Hunter


Joined: 24 Jun 2003
Posts: 584
Location: Riverside, South Cali

PostPosted: Tue Jan 24, 2006 5:32 pm    Post subject: [quote]

nodtveidt wrote:
This looks like yet another excuse to toss around buzzwords. :)


Possibly, as long as you do not grok them; DPs are wonderful because they facilitate different aspects of design --- everything from structure to behavior can be abstracted therewith to facilitate cleaner code which is, ipso facto, more maintainable than code haphazardly thrown together. At the very least, DPs tend to add more meaning to the software they are inserted within, which helps alleviate headaches at points far off in the mystical future where memory has faded.

Certainly, they are not the be-all/end-all of program design, but they definitely do help in designing good software. Besides which: they have practically grown up with OOPLs (the original book by the GoF was focused on OOPL DPs (woot for acronyms!)), and are, essentially, a tried and true method with over a decade of published work backing their usefulness.
_________________
"...LeoDraco is a pompus git..." -- Mandrake
Back to top  
zenogais
Slightly Deformed Faerie Princess


Joined: 10 Jan 2006
Posts: 34

PostPosted: Tue Jan 24, 2006 11:01 pm    Post subject: [quote]

I think labeling design patterns as a "buzzword" simply to write them off is a massive underestimation of their power. Sure it's a phrase, like "Web 2.0", to describe a whole series of things, but that doesn't mean they're useless. In fact unlike "Web 2.0", the phrase "Design Pattern" actually denotes something useful. Although working in the web industry, I can tell you that I deal with people and the phrase "Web 2.0" pretty regularly, and I can tell you that 95% of those using it have no clue what it is or why they want it. However, "design patterns" don't have the same cloudy meaning and are in fact well defined things.
Back to top  
Post new topic Reply to topic Page 1 of 1 All times are GMT
 



Display posts from previous:   
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum