Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Program Structure

Author
Message
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 1st Jul 2008 08:34
As some of you know, I'm hoping to make a 2D tile-based RPG. I know that's a lot of work, but it's my favorite style of game, and I think it won't be too difficult if I take it step by step.

I think I can handle coding most of it. But, there's one thing I'm finding that I'm not good at: the structure of the program. I'm not at all sure how to structure the program so it is workable and expandable. Does anyone have links to an article or similar that would shed some light on this?
Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 1st Jul 2008 14:12
I would add these general habits to your design. While not really a concrete program structuring method, keep the following in mind. It can help tremendously.

Any project of an RPG's magnitude needs to be module-based. This means that the game has a Core engine running, and you can add and take away various modules while still being able to run the program without errors. For example:

You have the 'Core Engine', the 'Player Module' and the 'Monster Module'. If you run the game without either module engaged, you'd have nothing but a black screen. Activating the 'player Module' will allow you to move around with a character. Activating the 'Monster Module' and the 'Player Module' together allows you to move around your character as well as kill monsters.

That is a very, very basic example. In essence, here are some good programming strategies for a large project;
1 - Document everything. When you program a function and don't look at it again for awhile you could lose grasp on how it works. Just simple explanations will do as long as you are the only one working on it. In a team it is best to give an in-depth explanation.
2 - Use namespaces. They allow much better control over function names as you won't collide with other functions. Use them liberally, but keep track of them.
3 - Use headers for organization. When writing various aspects of the game, put all the prototypes and variables into header files for easy, reliable organization. Keeping your source in a single file is very difficult to organize.
4 - Rarely, if ever, use global variables. Yes, they are nice and make things easy, but if messes up your memory organization. Keep globals to as few as possible. Instead, pass balues from function to function by reference.
5 - Keep an up-to-date log of changes and additions made to the game as well as the functionality of various modules. If a module is not working, update the log to reflect this when you are done for the night.
6 - Name Modules and Functions as succinctly as possible. Remember, functions should be quickly recognized, so making huge elaborate or descriptive names is not a good idea as you will likely be typing them a lot.
7 - Get comfortable with dynamic memory. It takes a little extra work, but it much cleaner.
8 - Use classes. It is very convenient to be able to create custom data types and should be implemented to it's max. Classes can make or break a program so use them, to a lesser extent structs, as often as possible to stay organised.

Remember, organization is key to survival with a large project like an RPG. Keep up to dat logs and make sure to work on the project daily, lest you fall out of sync and lose headway.

Cheers,
Bishop


Tux is my guildmaster.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 1st Jul 2008 19:55
I've already started on the basis of modular design. I've already also been doing 3, 4, 6, 7, and 8. The rest, thanks for the tips.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 2nd Jul 2008 17:33 Edited at: 2nd Jul 2008 17:34
In that I'm somewhat OOP oriented I'm inclined to make objects of everything and encapsulate everything inside a logical structure. Event the game itself is an object. Without going too deeply into it all.....

I think much of the structure in my current game can still be applied to an RPG. In my Capsules game I have a class called DarkCap. One of the public methods is called Run(). So I start things off with


The constructor for the DarkCap class contains the code for initializing the screen parameters and setting up a singleton for the mouse. I haven't implemented joystick yet but that too would probably need to be handled in the game constructor as a singleton. Keyboard too, though I haven't developed a keyboard class for this yet.

The Run() method looks like:



and Menu() looks something like this: (going from memory)



From there it's all a matter of what you need to have your game do. The methods carry it from there but you may use objects buried in various methods.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 2nd Jul 2008 18:01
What good tile RPG doesn't have those classic dialog menus? You know, the blue ones with the white text that you can press space to advance through? Program generic functions for this sort of thing early on, so that you don't get hung up on it later. If you need help, I can show you some good GUI programming techniques...it's kind of my thing.


My site, for various stuff that I make.

Attachments

Login to view attachments
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 2nd Jul 2008 19:35
Like Final Fantasy?

I love those games. My inspiration for this game was Final Fantasy and Dragon Quest.

I hope to make some functions for boxes like that once I get the tile system finished. I'm having trouble making it work well. :/

Thanks, Lilith, for the code you posted. I'll consider that style of structure. I like it.
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 3rd Jul 2008 09:14
i'm working on a project that probably parallels your own, so you can ask me questions too. ;9

~you can call me lantz~
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 3rd Jul 2008 17:41 Edited at: 3rd Jul 2008 17:41
nice thread - only one slight disagreement:

Quote: " functions should be quickly recognized, so making huge elaborate or descriptive names is not a good idea as you will likely be typing them a lot"


I agree to an extent - but intellisense does alot for you, and typical frequency of a function might be a guide to how cramped the name should be - for example - if you have a special function that isn't used a lot - a LONG name might be all the self documentation you need - where something used often... like ascii to integer (most people know of the atoi() function) then short names are a blessing.

Also - I think you might find some really good modular coding and gui examples here: http://code.google.com/p/darkgdkoop/

--Good Luck - and Good Question! code makes computers do things - design allows us to manage it for the long haul!

--JAson

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 3rd Jul 2008 19:17
Thanks for all of your answers. One last question, though: Hungarian notation. I've used underscores between lower case words for almost all names. Should I be using Hungarian notation? I didn't think it would be best except for OOP names.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 3rd Jul 2008 19:36
I really hate Hungarian notation. Too much to remember and I don't think I get much out of it. I have trouble trying to interpret what others are trying to do.

For the most part I capitalize the first letter in a class name and methods. Variables I start out with lower case but if there's a new word as part of the name I capitalize it. And the same second word capitalization applies to methods also. In some instance I see people who tend to put "m_" to indicate that the variable is a member of the class. But I have to ask myself, which class?

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 3rd Jul 2008 21:01 Edited at: 3rd Jul 2008 21:02
I usually name variables like so: num_types, map_x, start_x, or, for classes, cTileMap, cPlayer, et cetera.

So, only a little Hungarian notation, though not really even a little. That's the only thing I use if for: class names.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 3rd Jul 2008 21:11
Quote: "I usually name variables like so: num_types, map_x, start_x,"


<whine>But you have to hold down the shift key!!!!</whine>

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 3rd Jul 2008 21:26
Same for numTypes, mapX, and startX.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 3rd Jul 2008 21:44
Quote: "Same for numTypes, mapX, and startX. "


<whimper>But you have to hold the shift key and reach way up!!</whimper>

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 3rd Jul 2008 22:01
Oh. Well, then it depends on your typing speed.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 3rd Jul 2008 22:05 Edited at: 3rd Jul 2008 22:05
Quote: "For the most part I capitalize the first letter in a class name and methods. Variables I start out with lower case but if there's a new word as part of the name I capitalize it. And the same second word capitalization applies to methods also"

I do exactly the same.

Quote: "<whine>But you have to hold down the shift key!!!!</whine>"

Not on this keyboard.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 3rd Jul 2008 22:08
I'm fine with using the shift every once and awhile. And what kind of crazy keyboard do you use?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 3rd Jul 2008 22:24
I think personal preferance - some guys Hate Camel humpback - but I use it AllTheTime

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 3rd Jul 2008 22:45
Camel what? o.O
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 3rd Jul 2008 23:02
ThisIsCamelHumpback. EachWordHasACapital. I Do Use underscores too... but I'm not religeous about ... for example - For all my classes I have in my DarkGDK OOP lib - JGC I have classes named like:

JFC_RGBA or JFC_STRING .. ALL Uppercase I usually reserve for stuff like classes or defines or other stuff I think warrants it. Other wise... I name functions in a way I can open the code 3 months later and know what is going on fairly quickly.

I definately have my own flavor of coding style - and it was hungarian'ish before intellisense - and when intellisense isn't available. I like the alphabetical listing and show of data type in intellisense - but in languages/editors where thats not the rule I tend to use a homebrew notation that is platform independant for core data types - andhopefully discernable for platform specific stuff - so they aren't to complex or hard to figure out.

Example:

iGenericInt, i1, i2, i4, i8 - Integers with byte count.
uUnsignedInt, u1, u2, u4, u8 - Unsigned Integers with byte count.

I have many more - s, sz, p_ (parameter to function) etc.. I actually wrote a complete documentation of it for ESPN news when I was consulting there because the guys there liked it - because that combined with some other suggestions I made - made it easy for the business folk, coders, and graphics people to align on a base nonmenclature in meeting - which was a big diconnect on big projects when I was there... but I digress.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 3rd Jul 2008 23:48
So you have a career in programming?
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 3rd Jul 2008 23:58
Quote: "some guys Hate Camel humpback - but I use it AllTheTime "


ObviouslyNotAllTheTime.EventuallyItWouldBecomeVeryHardToReadSomeOfYourLongerPosts.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 3rd Jul 2008 23:59
And you whined about having to use the shift key.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 4th Jul 2008 00:01
one has to make some sacrifices for the sake of humor. at other times one must compensate or, actually, over compensate.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 4th Jul 2008 00:25
Lilith - You're so Awesome!

Mahoney - Yes - I've been coding for 26 years and I've been working "professionally" for the last 16.... Now I feel old...

THANX! LOL
--Jason

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 00:31
And I feel inadequate.

I would love to take up programming as a career, just not good enough at it yet.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 4th Jul 2008 01:40
Careful what you wish for LOL - The moment the "fun" turns to "work" it can be pure drudgery!

Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 4th Jul 2008 01:44
I use CamelHumpback all the time. That's usually the way you do everything with Lua, and that's where I started.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 01:48 Edited at: 4th Jul 2008 01:49
I prefer an initialLowerCase, then capitals. Except when it's a ClassName.
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 4th Jul 2008 02:00
Yeah, that's actually what I do. Is that still called Camel Humpback?

SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 4th Jul 2008 02:07
In all cases, I use the firstLowerCaseThenCapitals. With my window system, form elements that are part of the window have it's abbreviated name in all lower, then caps. If I have the window "bool newGameWindow", then a button would be controlled by "int ngwOkButton". I like to show the relation of the variables to each other.


My site, for various stuff that I make.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 02:29
To be honest, I generally use this_style for almost everything. Would it really be best to switch to thisStyle? I know it's a preference, but, in general, which is more widely accepted.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 4th Jul 2008 03:39
My opinion about everyone else's opinion (LOL) is this: Consistancy!

That doesn't mean you shouldn't change up. Just try to be systemic (make it a complete switch in your project)!

Example: From one consultant job to the next - one company to another - I have yet to see consistancy from company to company - similiarities MAYBE (cuz clean code is clean right?) but sometimes you see mismash from different developers - and even that is readble if they themselves are consistant. Obviously - ideal - everyone writes the same style - rarely happens.

My main concerns are:

"Can I read my own code?" (Most important)
"Am I being fairly consistant about it?" (no one is perfect)
"Can others read my code?" For something like the DarkGDK OOP I wrote - I tried to make it legible... but usually if I write it good enough that I can put it down and read it a month or more later and understand the jist pretty quickly... than most coders will be able to read it just fine - unless they happen across some wizardry code that might be less than easy to figure out with clean or dirty source LOL

To be thorough - you can learn "styles" from other peoples code - but what will PROBABLY happen - is over time you'll see ONE technique you like from Lilith, another from me, another from LIT, another from VanB, another from SunDawg, Another from Benjamin, etc... and you'll eventually just start to write code YOU understand and you'll get consistant - and before you know it - someone else is reading your project - and might say something like - "Yeah I saw your code..." you'll ask.. "could you read it ok?" and the reply will be "Yeah...Why do you ask?" LOL

Hang in bro - the fact that you even care is a HUGE STEP in the right direction!

--Jason

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 04:23
I try to write neat code. I like it that way.
elantzb
16
Years of Service
User Offline
Joined: 10th May 2008
Location: Classified
Posted: 4th Jul 2008 09:12
we can all agree that sloppy code is a bozo no-no

~you can call me lantz~
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 09:17
Definitely.

You know what's funny about that? Some of the sloppiest code I've seen has been professional code. For instance: you can download the source to an operating system from Microsoft called Singularity. I looked at a bit of the code, and it's very cramped and confusing. It may be that I'm not good at coding, but it looked like crap.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 09:27
I've looked over the code for Singularity some more. Imagine the crazy usage of underscores and capitals in the Win32 API strewn throughout the source code of an operating system.
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 4th Jul 2008 09:41
I hate Win32 API. It hates me too.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 10:10
It uses WAY_TOO_MANY CAPTIALS_AND_UNDERSCORES fOrNames of_Variables.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 4th Jul 2008 18:05
That's probably because Microsoft imposes its own set of coding practices since they have so many programmers working on projects. Consistency in a large programming environment where coding is assigned to multiple programmers is very likely advantageous.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 18:33
I know. It's so confusing to learn, though.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 4th Jul 2008 18:35 Edited at: 4th Jul 2008 18:36
Quote: "It uses WAY_TOO_MANY CAPTIALS_AND_UNDERSCORES fOrNames of_Variables. "

I'm not sure where you get this from as there are no variables in the Windows API header files, only definitions, prototypes, structures, etc.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 19:48
Sorry, function names and such. The function parameters and typedefs, also.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 4th Jul 2008 19:50
Could you give some specific examples?

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 19:54




Just a few examples.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 19:56
_LOTS_OF_REALLY LARGE_NAMES _IN_CAPS AND_UNDERSCORES, then, out of no where, variables wIth nOrmal Names.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 4th Jul 2008 20:13
Those are constants (which uppercase and underscores is standard for in many coding circles) and typedefs. Function names aren't like that.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 20:22
It is still very confusing in presentation.
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 4th Jul 2008 21:43
Windows API is unfriendly at first, but works well once you understand how to work with it, and why the functions have so many seemingly useless parameters.


My site, for various stuff that I make.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 21:56
It's just the look of it. It's very complex in appearance. I think they should have done a slightly neater job with some of it. But, I can't complain.

Login to post a reply

Server time is: 2024-11-20 15:36:11
Your offset time is: 2024-11-20 15:36:11