View previous topic - View next topic |
Author |
Message |
Gardon Scholar
Joined: 05 Feb 2006 Posts: 157
|
Posted: Fri Feb 17, 2006 3:43 am Post subject: |
[quote] |
|
And what ABOUT my input class? How else would you handle updates? Just keep setting values in engine and passing thema long to whoever needs it? i might as well handle input in engine.cpp then.
Jason
|
|
Back to top |
|
|
zenogais Slightly Deformed Faerie Princess
Joined: 10 Jan 2006 Posts: 34
|
Posted: Fri Feb 17, 2006 5:10 am Post subject: |
[quote] |
|
You structure your project by breaking code up into logical units. You don't cram stuff together that has no business being together (i.e. they are not related in any way other than that one relies on the other for something).
As for the input class, I'd use the observer pattern if I was really interested in separating events from the code that reacts to them. The code you have now is fine, but it's inflexible and there is a better way. That being said it's probably just fine for a small RPG, however for a much larger, more complex RPG it would start becoming more of a hindrance.
All of these questions you are asking you have to figure out for yourself. You have to figure how you like to structure your code and then structure it that way, it's a personal decision and not one someone else can make for you. Spend some time reading C++ articles and brushing, 95% of the questions you have can be solved by research (e.g. Google).
|
|
Back to top |
|
|
RuneLancer Mage
Joined: 17 Jun 2005 Posts: 441
|
Posted: Fri Feb 17, 2006 6:28 am Post subject: |
[quote] |
|
You could handle input by having an input module which polls the keyboard for keys held down. Other modules in your code could query the input module to see which keys are currently being held and react accordingly.
Various input libraries already do this for you, btw. Dunno what SDL has to offer, but I believe it should be able to fill this purpose out nicely. _________________ Endless Saga
An OpenGL RPG in the making. Now with new hosting!
|
|
Back to top |
|
|
LeoDraco Demon Hunter
Joined: 24 Jun 2003 Posts: 584 Location: Riverside, South Cali
|
Posted: Fri Feb 17, 2006 6:41 am Post subject: |
[quote] |
|
(Just to toot my own horn, I offered some advice on this subject in your other thread, with links even.)
The past couple of days, as a side effect of your other thread, I have been reading some of the answers offered at both the C++ FAQ Lite and on Bjarne Stroustrupe's homepage; they seem to have a good deal of useful information, so you might consider perusing them, should the language be hindering you. I'm also given to understand that Stroustrupe's book is the definitive guide to C++ --- which makes sense: he did, after all, create the language --- however I have yet to give it a read.
If you should gain anything from the first of those links --- the FAQ lite --- it should be: "There are no hard and fast absolutes;" applying that to program design, you should realize that a number of tradeoffs occur over the course of developing anything, and the utilization of a given construct --- be it something language supported, such as an enumeration and switches, to something far more abstract, such as design patterns utilizing crazy amounts of OO code --- is never without its consequences. (That said, certain approaches have consequences more dire than do their alternatives.)
I once had it explained to me that any method numbering more than 100 lines was illwrought, and should probably be refactored; that magic number varies per person, and even per hour --- for instance, some people might be wary of methods the length of which is greater than their text-editor window's height; others might think that methods more than a dozen lines should be rethought, while others still might be perfectly happy with dumping massive amounts of code into arbitrarily tossed together methods. Intrinsically, as long as your source makes sense to you, and you are happy with its run-time and memory footprint, nobody really cares how it is done, unless they themselves have to start maintaining it.
Another thing to gain from that FAQ: "good" program design should start at as abstract a level as possible; consider only the interfaces by which your classes will interact, which is to say, consider their behavior, not their data. The latter quatum is important, but designing to data generally causes greater headaches than does designing to behavior.
And certainly: do your own research! Folks around here are amiable enough to talk about things at abstract levels, and certainly will give guiding help for things more concrete. However, you shall not always have others around to hold your hand when things become difficult; mentors are great, but you sould hardly rely solely upon them. _________________ "...LeoDraco is a pompus git..." -- Mandrake
|
|
Back to top |
|
|
RuneLancer Mage
Joined: 17 Jun 2005 Posts: 441
|
Posted: Fri Feb 17, 2006 7:30 am Post subject: |
[quote] |
|
Meh... just gonna post before heading off to bed.
Quote: | for instance, some people might be wary of methods the length of which is greater than their text-editor window's height |
It's such a psychological barrier... ;) My college C teacher (who owned; one of the only 2 teachers who knew their shit... both of which were let go in favor of the fat drunk comp. sci. director and his bitch) put this barrier at 50-ish lines.
What LD says about it making sense to you and satisfying your expectations regardless of how you go about doing it is true, but don't get carried away. If you end up with a job in computer programming, you'll often have to deal with a convention established by your dev team. It can be frustrating (I like keeping code compact; for instance, I often put if() blocks on one line if the command is short enough (if(health < 0) { isDead = true; gameState = GS_DIED; }) but this is simply inacceptable at work. ;)
Quote: | "good" program design should start at as abstract a level as possible; consider only the interfaces by which your classes will interact, which is to say, consider their behavior, not their data. |
Also true. Think about what you need your class to do before thinking about how you'll do it. If you're not even sure what your class is going to acheive (ie, "Well, it'll represent a sprite... I'll see what I can use it for later.") then how can you build anything solid if you stop the thinking there?
Quote: | mentors are great, but you sould hardly rely solely upon them. |
Yes. For that matter, some of us got here without mentors in the first place, so how hard can it be? You won't learn anything if people fix your code for you whenever a problem comes up. On the other hand, if you put up with the head-scratching, painfully following your code's execution line by line in the debugger, and occasionally ask why "x" doesn't do "y" when you'd expect it to (as opposed to, "why is "y" occuring?"), you'll build up the skills necessary to solving these kinds of problems on your own.
Best of luck. And g'nite RPGDX... gotta work in ~5:30 hours so... bedtime. _________________ Endless Saga
An OpenGL RPG in the making. Now with new hosting!
|
|
Back to top |
|
|
tunginobi Wandering Minstrel
Joined: 13 Dec 2005 Posts: 91
|
Posted: Fri Feb 17, 2006 12:33 pm Post subject: |
[quote] |
|
Gardon wrote: | Ya, but what I mean is how exactly do you structure your projects? Lots of files, lots of classes, what?
I mean, would you really want hundreds of lines of code in the main function that runs your game loop?
Jason |
You think "hundreds of lines" is a lot of code?
...
I think you should know your code well enough to be able to say to yourself which bits in a large function could be broken off and generalised into a smaller general-purpose function.
Often you'll find in the process of programming that, in a single block of code, there'll be a small chunk of lines that handle one task, then another that may or may not share some variables or other data with the last chunk, and so on. It should be possible to separate those in whatever organisation you need.
Long story short, we can't tell you exactly how to structure projects. Well, we could, but there'd be parts you wouldn't get, or wouldn't understand, or simply won't work for you.
We can answer your questions, but we can't do your job for you. Don't be afraid of having a good shot at things on your own.
|
|
Back to top |
|
|
Gardon Scholar
Joined: 05 Feb 2006 Posts: 157
|
Posted: Fri Feb 17, 2006 1:11 pm Post subject: |
[quote] |
|
I like neat and organized, so hundreds of lines IN ONE FILE is a lot, yes
Jason
|
|
Back to top |
|
|
|
Page 2 of 2 |
All times are GMT Goto page Previous 1, 2
|
|
|
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
|
|