Jump to content

  • Log In with Google      Sign In   
  • Create Account


Chad Smith

Member Since 26 Jun 2005
Offline Last Active Feb 11 2014 11:22 AM
-----

#5101966 How do you 'learn' a programming language?

Posted by Chad Smith on 16 October 2013 - 04:02 PM

really the best way to learn programming is to just code and keep coding.  You said you read something and you do the examples.  Ok good, but is that all?  I used to do the same thing and well I thought I knew all the concepts but I found later on when it came to applying them to a different program I hadn't really learned them.  Then what I started to do was create my own examples.  Ask yourself questions while reading.  While your reading try creating your own examples before you even get to your exercises in the book.  What you will end up doing is helping yourself understand this concept in a lot of different ways.  The ways/examples you do might not be meaningful or useful but that is ok.

 

Next after you do the examples in the book, try to extend on them and make them into a more "complete" program/example.

 

Finally if you don't understand a certain concept try writing it down.  Work through that concept on paper like the program would run it step by step.  Then put that concept into a program and use your debugging tools to attempt to run the program step by step.  Look at what values changed?  Why did they change?  Work that out on paper and compare the results.  If you are getting the same results on paper as you would get in the program then you're understanding the concept more.

 

It all comes down to, just keep programming.  Their will be concepts you don't get or understand right away.  Just keep programming.  We all need breaks and everyone here understands that.  Though in the end make sure you come back and keep programming.  When you come back instead of thinking that you have to reread everything try testing yourself on what you read previously without looking at your book.  If you keep doing all of this before you know it you will solving problems all on your on.

 

Just remember though we all need help sometimes.  Don't be afraid to ask questions.  Everyone here be it professional or not need to ask questions sometimes and we have all been there before and we all understand (ok their are a select few people I've noticed that do believe they are above everyone and think they understood everything first try, but ignore those people).




#5094759 C++ skips a statement in it's first run

Posted by Chad Smith on 17 September 2013 - 03:12 PM

string n_movie[n];
 
Or perhaps.....  
 
vector<string> n_movie;
n_movie.resize(n);
 
??


What's the question? Is there one? Yes I'd use a vector but it is likely the OP hasn't studied vectors yet so an array is fine with him learning.


#5075864 std::move and std::unique_ptr

Posted by Chad Smith on 07 July 2013 - 03:41 AM

I'm pretty new to some C++11 and also smart pointers.  While reading and studying part of the bare bone basics of a scene graph I came across the following C++11 code.  Guess just wanted to make sure I am on the right track on what I believe is happening and just wanted some clarification.

 

Here is the function:

RemoveChild(const SceneNode& node)
{
	auto found = std::find_if(children.begin(), children.end(), [&] (ScenePointer& p) -> bool {return p.get() == &node; });

	assert(found != children.end());

	ScenePointer result = std::move(*found);
	result->parent = nullptr;
	children.erase(found);

	return result;
}

Couple notes:

  • children is just a vector container.  It contains std::unique_ptrs of SceneNodes
  • ScenePointer is just a typedef of std::unique_ptr<SceneNode>

 

It's using the find_if algorithm to go through each element in the vector.  Uses a Lambda Expression to check if that elements pointer is the address of the node we are searching for (whew I need to study up more on Lambda Expressions I'm noticing).

It then uses an assertion to validate that the node we searched for could actually be found

 

It will store the result by just using the C++11 move semantics in std::move.  Because found is actually an iterator (I think?) I need to dereference it?

 

Then since it is removing a child we set the child's parent pointer to null then just use erase to remove it from the vector since it's not longer a child.  Finally return the detached node/smart pointer.

 

Am I close on this?  My main question is about the std::move(*found).  I understand hat this would actually be moving the content and won't require a copy of the entire object.  So that position in the vector is empty now, right?  My main question is: why exactly was the dereference needed here really?  

 

Thanks to any and to all who can give me the confirmation and help!




#5074947 learned c++, now what?

Posted by Chad Smith on 03 July 2013 - 12:17 AM

If you still interested in learning SDL then I would highly suggest the Lazyfoo SDL Tutorials.  These will get you started with SDL on your way.

 

On creating your game, the best way would be to just start learning/studying the API of your choice (seems to be SDL that you're interested in) then just start thinking about "ok, how can I get this happen?"  Then try designing and programming it.  Start from the most basic step of just getting a window up, then learn how to draw something to that window.  Learn how to get input, move it, animate it.  One step at a time.  Just keep building on it.

 

Also with you just starting here is what I suggest: at the starting point don't focus too much on perfect code or the best designed code.  I will go ahead and tell you something, that you might not want to hear.  Your code to your first game will look like crap.  Everyones code to their first game looks like crap.  Don't focus on trying to make it look good, professional, or 100% proper.  Just focus on getting your game made.  You will learn how to write well designed code in time and with experience.  Too many first games are never completed because they get refactored so many times with people trying to make the code "perfect."  Just write it and finish it.  When you do finish it you could even post the code and ask here for a code review.  Their are some very good programmers here that don't mind at all to do a quick code review and will give you some very good pointers.  One thing these programmers will always say though before they even start the code review is "congrats on finishing the game!"

 

So the LazyFoo SDL Tutorials: http://lazyfoo.net/

Also keep the SDL Documenation near you so you can study up on SDL that way also.  Then just program and try stuff out.  Start the most basic thing then move forward one step at a time.  Don't try to write the entire time right from the start.  One step at a time.

 

Also, if you are not too sure about SDL or are interested in trying something else out, I will throw out the suggestion of SFML.  I myself like the design of it better than SDL.

http://www.sfml-dev.org/

 

If you have any questions don't hesitate to ask.  99% of the time we will be very happy to assist you, as long as you have shown you have put some thought and work into it yourself.  As in we won't just write your game for you or anything like that.  lol.




#5069297 Transforming the Young Blank Dull Slate into a sharp Genius In Math.

Posted by Chad Smith on 12 June 2013 - 10:10 PM

Maybe game development is just not the thing for him.

I'm sorry but that was just flat out the wrong thing to say.  I've seen some very good game programmers be successful while still not being good at math.

 

When I was a Freshmen in high school I absolutely hated math.  But I got into Computer Science when I was a freshmen in high school because my Algebra teacher was a Computer Science Major fresh out of college and he helped get that schools Computer Science department going.  He saw I was interested in it so he took my hand and guided me privately, for free, while taking time out of his busy schedule.  He helped me understand everything so much more.

 

Now I am in college majoring in Computer Science and minoring in math.  I'm still not the best at math and don't pretend to be.  Matter of fact I do still make some dumb mistakes on math tests and I do still need to study very hard to make a good grade in it.  But he solely is the one to get me interested in Computer Science/Game Development.  I don't like hearing "it's not the thing for him."

 

Heck, my Cal 2 Professor couple semesters back told me a story of how when she was going to school to major in Math.  She told me how she was the worst in the class, failed some math classes and all that.  She was kept on being told "Math is not for you."  She didn't care.  Now she has PhD in Math and is a very well known and high up professor.  Telling someone "it's just not for them" is never the right thing IMO.  They can still do game development.




#5066776 box collision detection help needed

Posted by Chad Smith on 01 June 2013 - 06:32 PM

Thanks BeerNuts,

I have heard of these libraries but thought it would be important to learn everthing from the bottom up (collision is the worst). I have also read that professional game studios and developers don't bother make their own code for physics etc, they just use 3rd party libraries. Do you think it's worth the time to and frustration to struggle with the collision and physics or should I not bother wasting time and just switch to the library you recommended?

Mike


I'd say it fully depends on your needs.

Though what I generally say is that if you are just learning/practicing and not writing anything really that you'd release or working on a project then try learning it completely. It gives you a great idea how things are implemented internally in libraries you use.

Though if you are working on a project then try using a physics/collision library if it fits your needs. Most of the time these libraries are so much better and optimized than anything you would write, plus youd be wasting development time reinventing the well.

If you're just learning though then it's fine. It's good to know how stuff is internally represented just in case you run into issues. You have an idea what the problem may be.


#5062723 Need help choosing environment

Posted by Chad Smith on 17 May 2013 - 09:45 PM

For C# you may look at MS XNA, and the Mono-project - cross platform .NET environment.  I think there is a port MonoXNA, as well.

For java you may look on jMonkey game engine which will do many annoying things for you.

Rated you back up because I can't figure out why you were down voted for at least giving suggestions that did relate to the topic.

 

If  you want to learn C# then go ahead.  Sounds like you have a good Java knowledge so it shouldn't take you long at all to switch.  1: Because C# is similar to Java and 2: Because in general programming concepts transfer from language to language.  Just takes time to learn how you do something in that specified language.

 

Like was stated, with C# their are many viable options.  You could easily use XNA.  Honestly I'd ignore any post that really says "XNA IS DEAD!111!"  Yes it hasn't been updated but it still very much alive and usable.  You can still use it just fine.  Theirs nothing stopping it being used and it running.  Indie Game Store on the 360 is still there also so yes you can still use XNA to get something on the 360.

 

Their is also MonoGame.  It is an Open Source implementation of the XNA Framework.

http://monogame.codeplex.com/

 

Also for a game engine that is popular, you can use Unity.  While it is mainly 3D you can do 2D with it.  Basically you would just not use one axis.

http://unity3d.com/

 

No matter what you chose though, even a language you know, you will need to just take your time and create some test games to get used to working with graphics, sound, collision detection, and more. 




#5062698 std::sort vs. list::sort

Posted by Chad Smith on 17 May 2013 - 06:24 PM

I wanted to do a quick performance (very unscientific though) test on std::vector and std::list and I was very surprised by the results.  Maybe it's just me not understanding or knowing how each implements everything internally.

 

 

My surprise came when I sorted a vector vs. sorted a equally size linked list.  I understand that std::sort requires a random access iterator that std::list doesn't provide which is why their is a list::sort method.  Though I thought that using std::sort would require a swap internally (not sure why I do think that, I'm sure I should be doing more research about the internals of each) which wold require each and every object to be copied over.  Now the test object I use is just a very basic struct that "simulates" a Rectangle that has a length, width, x position, and y position, all stored as doubles.  I overloaded the < operator in it to do the sort and it should sort it based on area (just went ahead and calculated the length*width instead of storing an area member variable, not trying to make this scientific or find performances).

 

In my test I store 1,000,000 rectangles in a vector a list and set the length, width, xPosition, and yPosition to random numbers for each element in the vector.  I then set each elements length, width, xPosition, and yPosition in the list to the vectors corresponding element.  Calculate the time for each.  Maybe I should use a more scientific approach to this, as I am only using std::clock_t and CLOCKS_PER_SEC to calculate.

 

When doing this I am very surprised at the performance gap between the two!

First, here's my code to do this quick test, although it isn't anything special or scientific

// Tests Sorting Lists and Vectors Performance

#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <ctime>

struct Rectangle
{
	double length;
	double width;
	double xPosition;
	double yPosition;

	bool operator<(const Rectangle& rect) const
	{
		return (length*width) < (rect.length*rect.width);
	}
};

int main()
{
	const int NUM_ELEMENTS = 1000000;
	std::clock_t startTime;
	std::clock_t stopTime;

	std::vector<Rectangle> myVector(NUM_ELEMENTS);
	std::vector<Rectangle>::iterator vectIter;

	// Insert rectangle data in vector
	startTime = clock();
	for(vectIter = myVector.begin(); vectIter != myVector.end(); ++vectIter)
	{
		vectIter->length = 1.0*rand()/RAND_MAX;
		vectIter->width = 1.0*rand()/RAND_MAX;
		vectIter->xPosition = 1.0*rand()/RAND_MAX;
		vectIter->yPosition = 1.0*rand()/RAND_MAX;
	}
	stopTime = clock();
	double totalTime = (stopTime-startTime)/(double) CLOCKS_PER_SEC;
	std::cout << "Inserted rectangles in vector in: " << totalTime <<std::endl;

	std::list<Rectangle> myList(NUM_ELEMENTS);
	std::list<Rectangle>::iterator listIter;

	// Insert rectangle data in list
	startTime = clock();
	for(vectIter = myVector.begin(), listIter = myList.begin(); listIter != myList.end() && vectIter != myVector.end(); ++listIter, ++vectIter)
	{
		listIter->length = vectIter->length;
		listIter->width = vectIter->width;
		listIter->xPosition = vectIter->xPosition;
		listIter->yPosition = vectIter->yPosition;
	}
	stopTime = clock();
	totalTime = (stopTime-startTime)/(double) CLOCKS_PER_SEC;
	std::cout << "Inserted rectangles in list in: " << totalTime <<std::endl;

	// sort the vector using std::sort algoorithm
	startTime = clock();
	std::sort(myVector.begin(), myVector.end());
	stopTime = clock();
	totalTime = (stopTime-startTime)/(double) CLOCKS_PER_SEC;
	std::cout << "Time for sorting a vector: " << totalTime << std::endl;

	// sort the list
	// can't use std::sort, use the list member function
	startTime = clock();
	myList.sort();
	stopTime = clock();
	totalTime = (stopTime-startTime)/(double) CLOCKS_PER_SEC;
	std::cout << "Time for sorting a list: " << totalTime << std::endl;

	return 0;
} 

The output/performance I get

Inserted Rectangles in Vector in: 1.597

Inserted Rectangles in List in: 2.989

Time for sorting a vector: 3.384

Time for sorting a list: 111.252

 

What's with the HUGE perforamance decrease in sorting that list?  I understand list is slow at random access and that is what std::vector is strong at, but that big a performance hit when using a list?  I think list::sort uses a merge sort, which is O(NlogN), I believe.  What would std::sort be using in this case?  is their any guarantee or way to see what implementation it is using (maybe I didn't research enough), but does the standard guarantee what it will use? Is their a worst case Big-Oh run time that std::sort guarantees?  Average Big-Oh run time?

 

I understand that this isn't a scientific test nor would I use something like that in a real world code, but is their something just crazy wrong with my code that I'm missing that is causing the list to be that much slower?  I do still understand where benefits of using a list would come in, but if this is correct I can totally understand why I've always been told "look at std::vector first."  Is this correct?  Maybe it's because since the object I am sorting in each is very basic and if I was using a larger and more advanced class that would take longer to copy and results could be different?

 

Interested in any comments on this.

 

Note: this is just curiosity and I am not trying to pre-optimize current real world code that I have or anything.  Just my Computer Science brain being curious.




#5058375 What programming language should i go with? (C++,C# or java?)

Posted by Chad Smith on 01 May 2013 - 12:51 PM

Title^.

 

I basically have the same knowledge on all of the above and i wanted to know what should i learn and keep going with?

 

my goal is to create games and someday build (maybe) an engine for myself.

 

i think i want to use OpenGL for that and i figured that if all of these languages have opengl library (now all of them the same i know)

i should go with one of them.

 

what is the best choice to go with?

C++ is pretty hard to learn but i can handle it. (pretty fast too from what i understand)

C# is really easy and i can easily learn that language but it's not as quick as C++ and i dont know if the openTK (or what's it called) is the same as opengl openal.. (same function's)

Java same as C# but i dont really like that language i dont know way lol

 

 

thanks! smile.png

First of I just want to say, C# is plenty fast.  If you're just beginning you won't notice the "speed differences."  Don't even think about it.

 

Honestly choose what ever language you want really.  There is no correct or wrong language choice.

 

I myself though would go ahead and choose C# right now.  You will be more productive.  The best language for a job is the language that makes you more productive.  Plus I feel by the time you you to where  you can make your own engine your knowledge of programming should be pretty good which by then you would be able to pick up C++ with ease.  Just beginning you won't be doing anything where you will notice speed differences between C++ and C#.  Just because you do choose C++ doesn't mean you'll immediately get code that runs faster.  Matter of fact it may be easier to write code that is slower in C++ than it's C# counterpart.  Just because C++ allows you to do it doesn't mean it is the best or fastest way to do it.

 

Also just want to say their have been some reports that some algorithm implemented in C# have ran just as fast as the same algorithm implemented in C++.




#5058373 Scripting Language Choice

Posted by Chad Smith on 01 May 2013 - 12:39 PM

Python is a good one.  I also see and here good things about Lua.  

http://www.lua.org/about.html

 

I think a lot of people here use Lua as their scripting language in their games.




#5057646 Modulus Operator Usage

Posted by Chad Smith on 28 April 2013 - 10:56 PM

You can also use it to bring a random int into a range:
 

int n = intrand(); //gives random value between 0 and a bajillion
n %= MY_ MAX_RAND; //brings the value into the range 0 to MY_MAX_RAND
 
The circular sequence behavior that ultramailman pointed out can be useful in many situations:
//pseudocode
int n = 0;
loop {
  n %= 5;
  print(n++);
}
0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0.....

Actually HUGE thank you for this.  Just yesterday I was dealing with that and I ended up writing a simple if statement to reset it!  I don't think I would have ever thought about using the modulus operator there.  Thanks.

 

Hodgman: That's an interesting example also because I was working out a formula for that the other day.  Interesting I ask about this and I immediately get like two examples that I've dealt or thought of.

On what you said about "how do you know when to use addition or division?"  That is an interesting question to pose.  I would say just because it was drilled into our minds so much in school that you learn to use it while using the modulus isn't really drilled into your mind to use in school.  Only reason I can think of I guess...?

 

Thanks everyone!




#5056726 C++ - freeing dynamic memory

Posted by Chad Smith on 25 April 2013 - 01:53 PM

I just wanted to give some advice from someone taking a CSCE class at a University right now (Computing Foundations 2).

1: it is very good to learn the standard containers and the smart pointers it can provide. Defintely learn and use then in your personal projects.

Though I would not suggest to just forget about raw pointers after you learn them and never use them again. Honestly I was suggested same thing when I first started learning but IMO it hindered my ability to learn the core concepts. First thig is first learn the core concepts. These teach you internally about each container and allows you I better chose which contained you need at the time.

In my university class when we were taught the basics of some algorithms in some containers and we had to go implement them, we were NOT allowed to use any of the standard containers. When we had to implement a basic linked list, we could not use the std::list. That relies on raw pointers, allocating and deallocating memory on the heap. We had to imement a basic stack, and a basic tree. Now we are implementing a Graph.

They aren't being "mean" and saying the standard library containers suck and you shouldn't use them, but they are teaching us the basics of each one, the basics of how they are done internally. This is all very important. It's important to know how to use and where to use raw pointers. Don't just forget about them and never ever use them again. The core concepts are very important.

Though yes in personal projects I would use smart pointers where I could and of course the containers in the standard library.

I just wanted to point that out. The core concepts of a pointer are very important and I wouldn't suggest that you just forget them after you learn them and never use them again.


#5055070 Coding Style: Curly Braces

Posted by Chad Smith on 19 April 2013 - 05:34 PM

Even though I said I have a hard time reading when the braces are on the same line in my original post when asking the question, I will say as long as the style STAYS consistent (and the style is actually possible for a human brain to read and understand in the first place lol) throughout the code base then I really don't have much problem reading it.  Much of a code style is how consistent it is.  Then again could it even be called a "style" if it is not consistent?

 

Cornstalks: don't know any languages in the Scheme family, though what the heck is defining a scope or what is a scope in that family of languages?




#5053550 Multiline comments - why the extra stars?

Posted by Chad Smith on 15 April 2013 - 01:58 PM

I'm sure for me it is just some kind of convention that I started doing for some things, but I tend to use that convention or a convention similar to it when I want comments in the form of something similar to how it would be in documentation.  Even though I don't even use a documentation engine right now.

 

It partly may be that my brain for some reason doesn't like seeing or reading 

/* this is my comment
that goes on another line
yet another line
*/

I can't ever read that.  It likes:

/*
*     This is my comment
*     I know this is documenting something in my code
*     I know to look at it
*/

Though their is one thing that I do need to consistent on when I use those comments.  Tabs.  Most of the time I tab over after the '*' though sometimes I find something just typing the comment right after the '*.'

 

I don't know but my brain just likes that style better than just "regular" multi-line comments (C Style comments?).




#5053047 Academia

Posted by Chad Smith on 14 April 2013 - 12:52 AM

int l,dijk=di+nx*(dj+oy*dk),dijkl,dijkr,ima=step_div(dk-ez,nz);
int qj=dj+step_int(-ima*byz*ysp),qjdiv=step_div(qj-ey,ny);
int qi=di+step_int((-ima*bxz-qjdiv*bxy)*xsp),qidiv=step_div(qi,nx);
int fi=qi-qidiv*nx,fj=qj-qjdiv*ny,fijk=fi+nx*(fj+oy*(dk-ima*nz)),fijk2;
double disy=ima*byz+qjdiv*by,switchy=(dj-ey)*boxy-ima*byz-qjdiv*by;
double disx=ima*bxz+qjdiv*bxy+qidiv*bx,switchx=di*boxx-ima*bxz-qjdiv*bxy-qidiv*bx;
double switchx2,disxl,disxr,disx2,disxr2;

/*
so you have created qj, qi, and more badly named
crap at the top of your function... again.
*/

What the?  What human could just look at that and know exactly what is going on?  If I had to read crap like that every day I'd just quit programming.  I don't think it'd be worth the pain every day.






PARTNERS