Jump to content

  • Log In with Google      Sign In   
  • Create Account

Beginners Observation: Fundamental Lack of Source Code Examples?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
21 replies to this topic

#1 Thiatsii   Members   -  Reputation: 145

Like
1Likes
Like

Posted 02 September 2014 - 02:19 AM

Greetings All.

 

After a few months of searching the web and this site, I wanted to share my observation as a beginner to graphics programming. So, without further ado, here I go:

FYI: This is not meant with any animosity. It is offered more as a report on the current state as seen, offered in the dry 'Dragnet' voice of, "Just the facts, Ma'am."

 

There should be concrete examples in the 'Beginner's Resources.'

Like the human genome, I don't believe 'Best Implementation Examples' should be patented or relegated to super-secrecy. Yes, you're not going to learn anything if all you do is cut-and-paste; but, if you're like me, who takes a piece of code and breaks it apart to fully grasp it, then us 'Noobs' would not be filling the forum with so many questions. A case in point would be Input. When I began a few months back, I was trying to tackle Direct Input. I should have been spending my time on RAW Input instead. I realized my mistake recently while reading through these forums. Here's an example which should be in the beginner's resource Designing a Robust Input Handling System for Games, by ApochPiQ. At least, it should be there if the off-site source code was explained a bit more clearly. I understand enough to know that, following this example would vastly improve my knowledge of how a game engine interacts with different aspects of my game, simply through the Input system.

 

There is a vast amount of code going on under the hood just to get the graphics up and running. I keep seeing people referred back to the DirectX SDK for examples which is fine if dealing with anything other than DirectX itself. These examples can be confusing because they're bare bones and don't fully implement error-checking. I started learning with the Rastertek DirectX 10 tutorials. Finally, when I started onto DirectX 11, I stumbled on Chuck Walbourn's blog which gave references to the new dxerror files you need to download and use. Although I might not have found it yet, there should be source code available in the beginner's resources or DirectX, for a solid implementation that includes feature checks, device capability, error-handling, lost-device, and properly switching between windowed and full-screen modes. Once all this stuff is in place, everything then comes down to the actual graphics programming. And, when the beginning programmer has the ability to get input from the user, any further questions would then be on dealing with specific graphics related items.

 

Of course, I'd love to see a good implementation for handling and or creating entities such as sprites with different AI, etc.

 

My whole point, really, is that a few solid source examples in these areas, would save a great deal of time searching for articles that may or may not supply code that actually works. Beginners need a solid foundation, and good coding practices. Example code that can be built upon is extremely valuable. I know that on multiple occasions, I've followed along with book code examples only to learn after 4 hours that it doesn't compile. What did I learn from that? I'm sure much of it was workable, but in the end, I had to throw it all out and start over.

 

Peace!

 

 

If there is sufficient feedback to this post with useful suggestions, I will put them all together into an article to cover those topics. I, for one, am still trying to get all this together myself. I'll make the time to offer both DirectX 9 and DirectX 11 full implementations (I mean the checking, error-handling, etc,.. not the installer portion).


Edited by Thiatsii, 02 September 2014 - 04:08 PM.


Sponsor:

#2 Ashaman73   Crossbones+   -  Reputation: 7992

Like
11Likes
Like

Posted 02 September 2014 - 02:43 AM


I don't believe 'Best Implementation Examples' should be patented or relegated to super-secrecy.

Well, the issue is, that they do not exist. Once you are knee deep into development, you will understand, that there isn't anything like the 'best solution to solve problem <x>', other then some standards (like A*) which has already been docuement all over the internet and wiki.

 

The second problem is, that as experienced developer, you can only provide one of many working (not necessarily good) solutions, often limited by a NDA if you work in the game industry (a working solution embedded in a game is often not your property and you are not allowed to distribute it).

 

The third problem is, that your solution is often embedded in a quite complex program which will most likely not help any noob at all. A week ago someone asked me to show off my behavior tree implementation. Even if I have provided my 5000 lines of code, it would communicate with so many other sub-systems, that a noob coder would most likely not understand a single piece of code.

 

Well, as experienced coder, the best option would be to write dedicated example code (lot of unpaid work!) or to provide some of your knowledge in a forum.


Edited by Ashaman73, 02 September 2014 - 03:00 AM.


#3 Thiatsii   Members   -  Reputation: 145

Like
0Likes
Like

Posted 02 September 2014 - 03:00 AM


... (a working solution embedded in a game is often not your property and you are not allowed to distribute it).

I understand about the property rights, I just disagree about its usage. In my case, if I uploaded a 'Metallica' mpeg onto a secret computer, then only until a Security Officer verified that this was not indeed 'Secret' and reclassified it, that mpeg would be considered 'Secret'. Stupid-right?

 

 

 


Well, as experienced coder then best chance would be to write dedicated example code (lot of unpaid work!) or provide some of your knowledge in a forum.

I'd love to collaborate on some of the examples. The only reason I didn't start with an article at first, was that I haven't solved some of these issues... like the switching between windowed and full-screen that properly resizes the buffers. I didn't want to fill this up with a bunch of code that wasn't worked out yet.


Edited by Thiatsii, 02 September 2014 - 03:10 AM.


#4 Madolite   Members   -  Reputation: 207

Like
0Likes
Like

Posted 02 September 2014 - 03:25 AM

*snip*

 

The fourth issue is that you got a lot of (rightfully) concerned professionals who discourage you from teaching openly and freely to beginners, because of the potential for learning what later needs to be unlearn. With a certain level of critical thinking, this becomes a non-concern (because critical thinkers know how to follow up on sources) a but, regretfully in our world of reverence of authority over science, those professionals to often end up being correct.

Oh well, my two cents.


Edited by Madolite, 02 September 2014 - 02:32 PM.


#5 Thiatsii   Members   -  Reputation: 145

Like
0Likes
Like

Posted 02 September 2014 - 03:40 AM


The fourth issue is that you got a lot of (rightfully) paranoid professionals who discourage anyone from teaching openly and freely to beginners, because they're afraid that the beginners will somehow learn a bunch of stuff that they'll later have to unlearn. With a certain level of critical thinking, this becomes a complete non-issue but, regretfully in our world of ignorance, those professionals to often end up being correct.

Oh, sad but true.  Why should knowledge that benefits all of mankind be secreted away? I agree with paying an instructor for his time, but I don't believe I should have to pay for courses at a college/ university if I've already learned the subject. I should be able to challenge it and if need-be, pay the accreditation cost. The same thing applies to school text books teaching the same stuff that is open-source. Somebody is making money here and it sure isn't the student, and rarely the teacher.

 

I will freely share what I learn after I get it into a more cohesive form. Now, if only we can find some more open-minded professionals.



#6 TheChubu   Crossbones+   -  Reputation: 4766

Like
1Likes
Like

Posted 02 September 2014 - 03:41 AM

Specially on graphics programming. There is just so much stuff you have to learn before even starting to worry about how many draw calls are you making, how often you change state around and how the rest of the game communicates with the render system .

 

In most things at least, you can (should) learn basics first, then start to ask around how to make them fit in a bigger system, which is a whole issue on its own. Once you separate those two steps, you can learn new things in a more efficient manner (ie, first make them work, then make them fit).


"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

 

My journals: dustArtemis ECS framework and Making a Terrain Generator


#7 Thiatsii   Members   -  Reputation: 145

Like
0Likes
Like

Posted 02 September 2014 - 04:05 AM

Question on How to Proceed?

 

Should I start an Article and have a massive amount of updates/revisions to be referred to?

   Or...

Should I start another Forum Topic with the code that needs to be revised through collaboration?



#8 Buckeye   Crossbones+   -  Reputation: 6313

Like
6Likes
Like

Posted 02 September 2014 - 07:59 AM


Should I start another Forum Topic with the code... [emphasis mine]

 

Perhaps more difficult than simply posting a topic.

 

Your topic indicates you're interested only in C++ and DirectX. DirectX 9.0c with the June 2010 SDK? Direct3D 11? DirectInput, RAW or just windows messages for input? D3DX, XM or SimpleMath? Visual Studio IDE only?

 

When those decisions have been made, then another topic will be opened - "Why aren't there examples for my setup?" wink.png


Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#9 Thiatsii   Members   -  Reputation: 145

Like
0Likes
Like

Posted 02 September 2014 - 03:29 PM


Your topic indicates you're interested only in C++ and DirectX. DirectX 9.0c with the June 2010 SDK? Direct3D 11? DirectInput, RAW or just windows messages for input? D3DX, XM or SimpleMath? Visual Studio IDE only?

 

I just put a caveat at the top of my post to explain that it's more of a Dragnet style voice for the report... no animosity intended.

 

In this topic I was speaking more in the general sense which applies to all versions of DirectX.

 

C++, Direct3D 11, and RAW input since MSDN does not recommend Direct Input for mouse and keyboard. Also, before I even attempt it, I need to decipher ApochPiQ's source code for robust input handling. I had started out with DirectX 10 and 9.0c and had the Direct Input working, but I realized that since DX11 supports windows 7, there was no reason I shouldn't take full advantage of all the new features, math included, by learning version 11. I own a copy of VS2010 pro, but to fully take advantage of the new items, I grabbed a copy of VS2013 Express Update 3 for Desktop. Yes, I am using the DirectXTK.


Edited by Thiatsii, 02 September 2014 - 03:49 PM.


#10 Thiatsii   Members   -  Reputation: 145

Like
1Likes
Like

Posted 02 September 2014 - 04:34 PM


(ie, first make them work, then make them fit).

Exactly!  

 

I'm coming into this from the Animation side where I want to insure proper 'tweening' and set those ease-in and ease-out of keyframes in a coded environment. Coding is a lot more difficult than I anticipated... but I refuse to give up. Once I can get them working like a proof of concept, I can then delve into the coding needed to make it all fit together. Hardest part is keeping a clear and ordered path to learning.


Edited by Thiatsii, 02 September 2014 - 04:36 PM.


#11 Álvaro   Crossbones+   -  Reputation: 13915

Like
10Likes
Like

Posted 02 September 2014 - 05:56 PM

I find basic explanations and pseudo-code much more useful than production code.

You can try to learn about alpha-beta search by reading the code in Stockfish. As a beginner you'll be confused and frustrated, because what probably started as some elegant implementation of a simple concept was complicated over the years to implement more and more bells and whistles, and by now the original structure is hard to glimpse.

Alternatively, you can read a short explanation of minimax with pseudo-code followed by an explanation of the modifications you need for alpha-beta pruning and some more pseudo-code, and you'll get the idea without any of the confusion. If you work to turn that into a working implementation, you'll learn a ton of things in the process. That is a much better resource for a beginner, if you ask me.

[EDIT: I didn't pick Stockfish because its code is overly complicated: The code is actually really nice. But my observation still stands. The code is not needlessly complicated, but it is too complicated for a beginner.]

Edited by Álvaro, 02 September 2014 - 05:58 PM.


#12 BHXSpecter   Members   -  Reputation: 1673

Like
3Likes
Like

Posted 02 September 2014 - 07:23 PM

Most programmers rely on pseudo-code to express concepts rather than actual code for the simple fact that concepts usually are universal. Once you wrap your head around the concept or method expressed in the pseudo-code then it is a matter of using a library to do what it says. In my opinion, pseudo-code makes you think more about what you are doing than just reading through the code trying to understand the examples.


"Through vengence I was born.Through war I was trained.Through love I was found. Through death I was released. Through release I was given a purpose."


#13 Thiatsii   Members   -  Reputation: 145

Like
0Likes
Like

Posted 03 September 2014 - 07:22 AM

Thank you ÁlvaroBHXSpecter.

 

I agree that pseudo-code is an invaluable asset to learning. In fact, I write up a lot of my own conceptualizations as pseudo-code. There are many great articles where I find all I need is the the idea of the code expressed in order to grasp it.

 

Where solid examples would be appreciated though, is getting the initialization (DirectX) code worked out, and grabbing raw input in a tiered approach. As far as the raw input, I'm not saying you have to go crazy in implementation, but a working example that can be understood so the beginner can see how it all fits together would be a great boon. The link on RAW input (from this site in the developer's journal "The Bag of Holding") was explained well for the concept, but when I open the example source code I feel an absolute Noob. If I didn't see it's immediate value, I wouldn't be banging my head against the wall as I try to figure out concepts which I have not delved into before.



#14 Glass_Knife   Moderators   -  Reputation: 4998

Like
3Likes
Like

Posted 03 September 2014 - 11:44 AM

I'm coming into this from the Animation side

 

 

Because we tack on the word "Engineer" to software, sometimes people get the wrong idea.  There isn't a lot of engineering going on with game development.  More like voodoo, duct tape, and alchemy.  Game programmers should really be called "rules artists" but that just sounds silly.

 

Can you point me to the tutorial that shows me how to correctly animate a character?  Or how about the "right" way to light a scene.  Or how about the book that explains to the beginner the correct method for drawing hands?  There isn't one, because it is all a matter of skill, knowledge, style, and flair.  The same goes for programming.  But you don't really see the code, or how easy is it to go horribly wrong, or how hard it is to get something simple working that never fails.  

 

The more you code the more you realize that there isn't any one person out there that even knows the "right" way to do something,  because thousands of changes are made to hundreds of software components every day.  We're thankful if the stuff on the machine built last night.

 

If there was a right way, then we wouldn't have many computers, devices, programming languages, and design methods.  And really, I don't want a single way, because that would be boring.


I think, therefore I am. I think? - "George Carlin"
Indie Game Programming

#15 ApochPiQ   Moderators   -  Reputation: 16407

Like
3Likes
Like

Posted 03 September 2014 - 06:21 PM

Learning to read code is an important skill. You will fail as a programmer if you cannot read and extract significance from someone else's code.

Take it apart slowly. If you have to, go one word at a time - see something you don't recognize? Look it up. Play with it in isolation if you can, to understand it at even a superficial level, before moving on. Proceed until you find yourself able to read larger and larger chunks of code.


The input handling example is one of the cleanest and simplest pieces of code I've ever released. Production code would probably make you run away screaming with blood pouring from your eyes ;-)

#16 Glass_Knife   Moderators   -  Reputation: 4998

Like
0Likes
Like

Posted 03 September 2014 - 07:47 PM


The input handling example is one of the cleanest and simplest pieces of code I've ever released. Production code would probably make you run away screaming with blood pouring from your eyes ;-)

 

Yes, I went and looked at it, but I didn't want to say "Wow, this is really clean, organized, and well documented."  That could make a beginner freak out.

 

When I did the code for my Java book, I spent most of my time refactoring all the extra crap out of the code so it is, without a doubt, the cleanest code I've every written.  And people are still saying that that 650 page book is not enough to explain everything.


I think, therefore I am. I think? - "George Carlin"
Indie Game Programming

#17 Servant of the Lord   Crossbones+   -  Reputation: 21060

Like
1Likes
Like

Posted 03 September 2014 - 11:47 PM

The third problem is, that your solution is often embedded in a quite complex program which will most likely not help any noob at all. A week ago someone asked me to show off my behavior tree implementation. Even if I have provided my 5000 lines of code, it would communicate with so many other sub-systems, that a noob coder would most likely not understand a single piece of code.

 
^^^ This ^^^
 
I frequently run into this, wanting to share small or even large chunks of my code library to help others, but then realizing I have to rip out and write replacements for alot of pieces.
 
Sure, I'd love to share my level-loading code! Oh wait, that depends on my Serialization library. Which depends on my ByteBuffer class. dry.png 
I can no longer just share a 15 line piece of code.
 
My code doesn't really exist in isolation - it's built up in layers. Code ideas (in theory and in actual practice) is built up in self-contained functions and classes that are built from other self-contained functions and classes to make complex code easy to reason about at high or low levels.
 
I'm most pleased with my programming, when I realize a complex function can be written in only a few lines of higher level code.
I wrote this today:

//Returns the diameter needed for a circle centered at [a rectangle's center] to contain all four corners of this rect.
unsigned cRect::GetBoundingDiameter() const;

 I was pleased when I realized I could write it as:

unsigned cRect::GetBoundingDiameter() const
{
	//The diameter of the circle needed, is equivalent to the diagonal of the rectangle it is containing.
	//The diagonal of the rectangle is equivalent to splitting the rectangle into two triangles and getting the hypotenuse of either triangle.
	//So, we just use pythagorean's theorem.
	return this->TopLeft().DistanceFrom(this->BottomRight());
}

 
Which I used to write:

//Returns a new rectangle that is large enough to contain all four points of 'rect', no matter how much 'rect' is rotated.
static cRect cRect::GetRotatedMaxBounds(const cRect &rect)
{
	//If a rectangle is rotated, all the rotations together form a circle.
	//The diameter of that circle is also the width and height of the square needed to contain that circle.
	int size = static_cast<int>(rect.GetBoundingDiameter());
	return cRect::CreateFromCenter(rect.Center(), cSize(size, size));
}

 
My goal isn't to cram code into a single line - often I spread out even simple equations over several lines just to help me understand them better.
My goal is to abstract ideas into their own functions, and make them easy to re-assemble as needed to accomplish tasks.
 
Tasks like this:

How do you load a file of lines like: "blah = 117" and "green = 35"

Into a std::map<string, int> that's case-insensitive?

 
Can then be solved like this:

auto myMap = StringToMap<std::string, int, case_insensitive>(LoadFileAsString("file.txt"), '\n', '='); 

That's a simple line of code, but to share it, I'd have to share the implementation of 'StringToMap()', and case_insensitive, and LoadFileAsString(), which depend on other functions.
 
For a quick example, StringToMap() is:

template<...bunch of template args...>
std::map<...> StringToMap(...)
{
	return StringListToMap<...>(String::Seperate(str, ...), ...);
}

(Using StringListToMap() and String::Seperate())
 
And StringListToMap() is:

template<....>
std::map<...> StringListToMap(const StringList &elements, ....)
{
	std::map<...> map;

	for(const auto &element : elements)
	{
		map.insert(StringToPair<...>(element, ...));
	}

	return map;
}

(Using StringToPair())
 
And StringToPair() is:

template<...>
std::pair<...> StringToPair(const std::string &str, ..., toKeyCallback, toValueCallback)
{
	auto pair = String::Split(str, ...);
	Key key = toKeyCallback(pair.first);
	Value value = toValueCallback(pair.second);

	return std::make_pair(key, value);
}

It's a useful piece of code. I'd like to share it with others... but it also is built on yet more parts of my library.

In this case, it'd require some string to int conversion functions and also is dependant on some functors I use that validate whether characters are certain symbols or not. I can swap them out with other functions before I share them, but many times it takes thirty minutes or more (sometimes much more) to get the code sharable enough that people can compile and run it. Sharing code has much more than a zero-cost in labor.
 
To share what is simple code, I have to either share five or so other functions or classes which might be built on five more which might be built upon five more, or actually make the function more complex by removing the dependencies and in-lining it in the function. The very purpose of those dependencies is to make it easier to code, and to make the use of the code more simplified and easier to read.
 
Neither solution is ideal, because either I'm now code-dumping dozens of pages of code and twenty or thirty functions, or I'm code-dumping a monolithic function that is poorly coded in a hurry just to share it, and hasn't been tested or debugged, neither of which is really helpful to a beginner, and both of which are very burdensome for me to do when trying to help a beginner.
 
So instead I make a mental todo note: "Seperate out your string parsing and conversion functions into their own self-contained library and release it as public domain.". Yeah, that's a month-long project of it's own, and I'd have to take time away from my real project to do it. I'd have to spend several weeks re-writing and re-organizing it to make it less dependant on other parts of the library, so I could release it in self-contained libraries instead of one giant library. It's something I'd like to do, but I don't want to take significant time away from my actual game development to do so.


Edited by Servant of the Lord, 03 September 2014 - 11:48 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#18 Thiatsii   Members   -  Reputation: 145

Like
1Likes
Like

Posted 04 September 2014 - 03:31 AM


The input handling example is one of the cleanest and simplest pieces of code I've ever released. Production code would probably make you run away screaming with blood pouring from your eyes ;-)

 

tongue.png I knew immediately that I needed to learn this no matter how difficult [to me]. Your comment reminded me of an Indian saying, "Do not seek for enlightenment unless you seek it like a man whose hair is on fire seeks water."



#19 Ohforf sake   Members   -  Reputation: 1832

Like
3Likes
Like

Posted 04 September 2014 - 01:46 PM

I recently had to use SDL2 and to bootstrap things I googled for a minimal example to get things started. Turns out like 90% of all the example code out there is for SDL1 and outdated. A friend of mine, who started to work with OpenGL, had pretty much the same problem. He would search for tutorials/examples and also find them, but only later on realize that they were for OpenGL 1.2 and severely outdated.

The problem is that writing good, clean, and self contained example code, especially for the more advanced stuff, takes a lot of time. And then a couple of years later, the world has moved on and all that work goes to waste.

#20 SkyFireZ   Members   -  Reputation: 152

Like
0Likes
Like

Posted 06 September 2014 - 09:51 AM

From the perspective of a noob, actual production codes wouldn't help in learning at all. When a noob will see the code, he won't understand half of the things going on and he will be like "what is this sorcery?!" Production codes will scare any beginner away. 

​Pseudo codes on the other hand provide an easy to understand logic flow breakdown which can be implemented in any language. 






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS