Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Chad Smith

Member Since 26 Jun 2005
Online Last Active Today, 08:58 AM

#5228247 Different GCC Versions Resulting in Different Output

Posted by Chad Smith on 10 May 2015 - 11:33 AM

Sounds wierd. I can't see anything wrong.

 

You are initializing l2TotalTries to zero, right?

 

What the...Ok, that is what I get for coding at 2 in the morning I guess. 

I saw that last night and said "ahh, that's the issue, DUH!" Though after I fixed that I could of swore I tried it again on both my Universities linux machine and my Windows machine with gcc and it still gave the wrong output.  Though after doing that again today, setting l2TotalTries to zero works, as it should, and not initializing it to zero doesn't work.

 

Which I do sort of understand. l2TotalTries would be just garbage data, correct? So I can either get the desired results, or the wrong results. It seems using Visual Studio in both release and debug mode gives me the desired results when it is not set to zero. My friends Mac Book Pro did the same thing. While my University machines just used garbage data, and compiled under GCC on my Windows computer also resulted it in it being set to garbage data.

 

Little odd that different versions of compilers and different systems did different things to that variable. Though I understand that is not covered in the standard so the results are unknown. Guess I see why you always initialize your variables. Though I still swear that I tried that last night and it still gave unexpected results. Though I can't repeat it today.

 

I guess lets just ignore this post now. I do feel pretty dumb for making a mistake like that now and not understanding it. *embarrassed* 




#5226836 Best comment ever

Posted by Chad Smith on 02 May 2015 - 09:46 AM

I always like the comments from sections of Code that are copied and pasted from old code or another project. Ran into that the other day at work. Comment said it did something, code did something else unrelated.


#5177793 Did I begin learning late?

Posted by Chad Smith on 02 September 2014 - 09:19 PM

Not even close too old.  Matter of fact, I'd say you are at the perfect age too.

 

I attend a University and I remember in one of my first Computer Science courses there was a guy in his 60's coming back to school just so he could learn programming.  




#5175310 Strange output when writing to a file object and printing it out

Posted by Chad Smith on 21 August 2014 - 11:14 AM

Honestly, I sort of feel this is why some people are afraid to post some questions or post in the For Beginners section.

 

While I completely understand and agree that seeing multiple questions from the same person that at first glance doesn't seem to be trying to figure out the issue before they ask the question can be a bit annoying and not programming.  I totally understand that.  Though I also feel that this is the For Beginners section and the one thing that is always advised to beginner programmers is to ASK if you have an issue to try to understand it.  I feel the advice was just fine but also feel the advice was presented in a very impatient manner and also in a manner that made it seem like it is a bother that they asked a question.

 

1: If you feel the question is a bother to you, then you don't need to answer it.  Allow someone else too.  If you're going to be impatient with a beginner trying to figure something out then I feel you're doing more harm than good.

 

2: Typing in all caps to get a point across to a beginner is rude.  Even if your advice is good and sound.  I feel its rude to try to get the point across to the beginner in all caps.  Again it feels like you're being impatient with them.

 

Again, while I completely agree with the advice I feel it was presented in a rather impatient manner, something I don't think we need when helping beginners out in the For Beginners section. 




#5172674 Good step-by-step development tutorials/books

Posted by Chad Smith on 10 August 2014 - 06:58 PM

They do have advantages:

  • They give beginners a good notion of all the required expertise when implementing a specific game
  • They give a good insight on different ways of tackling different problems (different devs, different approaches to game dev)
  • They give a good notion of what's required to implement a speicifc game design
The only ones that get that advantage are the ones who actually bother understanding the code in the tutorials. Unfortunately, the number of 'beginners' who are impatient and want to go from 0 to 60 now is steadily increasing.

Then that is a totally different argument and nothing to do with the actual content that he original poster is asking for. While I do agree with you, you will only get out of those tutorials by how much effort you put in. Though if you actually put in the the time and effort, like it seems the orginal poster wants to do, then those tutorials can be of great benefit.

I just think it's wrong to say those tutorials/content is bad for a programmer then blame it soley on the users of the content that doesn't put the time and effort in.


#5125159 Is HTML5 a legit language for developing game?

Posted by Chad Smith on 20 January 2014 - 03:37 PM

...

I sense someone didn't like Steve Jobs...




#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++.






PARTNERS