Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Chad Smith

Member Since 26 Jun 2005
Offline Last Active Today, 04:21 PM

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




#5051292 Code Review ::Pong Clone::

Posted by Chad Smith on 08 April 2013 - 02:39 PM

Thank you all for the different pointers. I honestly believe you can't get better unless you have constructive criticism. I really do appreciate all of you for looking through my code.


Also your code isn't bad for a beginner. You're also doing a lot of things right. One thing you're doing right is asking for constructive critsism. That is a good sign for a programmer. Though in terms of your code in general it isn't bad and you're doing a lot of things right.

Also on your next game, just as a good lesson, try to write down the game. Meaning write down all the elements you need in that game. Now pick those elements apart. What do those elements need? What do each of those elements have in common? Before ya know it you'll start seeing where you can use inhertience and be core you know it you would have ended up creating a basic framework you can use for any game you do.

Also on your next game don't be worried to come back here and ask for a code review it. Their are a lot of people here that love doing code reviews and helping people out.

Before you know it you'll understanding and applying popular design models without even realizing it!


#5044917 What does 2.5D actually mean?

Posted by Chad Smith on 20 March 2013 - 09:46 AM

I think most of agree what the term 2.5D in a graphical sort of way. Ina graphical way it looks like it is 3D but is using 2D techniques.

Though if you want to get technical then we could going on forever. What defines a "dimension." Does it have to be "graphical" or "visual?" If you brain can "define" it as a dimension then it counts as one. If your brain is telling you that their is depth a long with a width and height then I would say it is technically 3D as your brain is seeing "3 dimensions." While sure it technically still may be 2D in the end it's whatever your brain thinks.

I think it is being thought of too much and that 2.5D is not meant to be a technical or real life term used to describe our physical motion. If we did that then every game we played would be 2D I guess you could say. Even if you had 3D glasses, in the end it was just "fake."

Don't think we should get too technical on this as its just pixels on a screen really...


#5041898 Feel like I'm going nowhere

Posted by Chad Smith on 11 March 2013 - 10:40 AM

Well, I'm fairly confident I know the language well. My problem is the actual game design and architecture. What would you recommend for that?

 

Also, any ideas for projects that I should work on?

 

In reply to this part of your post:

 

Just coding in general.Most beginners fall into this trap which ends up being a huge hole.  Just code.  Don't worry about if things are perfect or not.  Just code.  When you're a beginner you will not make perfect things.  That is something that most of the time just automatically comes with experience.  It comes up when you are just coding more and more and next thing you know  you find yourself researching topics and implementing them.

 

When you have a problem, take a step back.  Sometimes two steps back.  Diagnose the problem and solving the problem STEP-BY-STEP.  I mean in the smallest steps.  Write down every step and before you know it you'll find yourself writing pseudo code that you can just about directly implement.

 

Important thing though: Do not worry about code design right now!  When working on a good beginner project just focus on the problem at hand.  Don't end up making one problem multiple problems because you're worried about code design.  Your first projects will have absolutely terrible code design.  It will just happen.  Too many beginners see that and get worried and start all over and they end up learning almost nothing.  You learn a lot more from actually finishing a project completely then starting over multiple times and not really ever getting further.  When you have finished a project you can post the code here and most of the time multiple users, a lot even professional, will give you great advice on ways to improve the code.  Try to understand what they are saying.  If you don't understand something research it.  If you still don't understand what they are saying ask them to explain a bit further but give your own ideas.  This will have them and other people help more as it shows you are very interested in learning this.  Finally try to implement some or all of their ideas into the project or write down their ideas.  When you do your next project see if you can incorporate some or all of their ideas into your project.  Don't force it though.  Again just code.  If you keep repeating this process, before you know it you will writing better designed code and even implementing designs on your own!

 

The most important part that doesn't get stressed enough sometimes.  Just code.  Don't worry about anything else right now.  Just code.  In time other things will come.

 

Also, I think I read from your OP that you do use Java.  LazyFoo uses C++ and SDL but honestly he does a pretty good job even explaining the concepts of what is being done.  From that you should be able to translate what he is doing into Java code pretty well.  Just focus on the concepts a lot.  Research how to do each of those concepts in your language and API of choice and try to implement it.




#5038602 IDE/windows development dilemma

Posted by Chad Smith on 02 March 2013 - 08:09 PM

Visual Studio Express Editions are very stable IDE's. the fact that it is crashing on such a simple applications has me wanting to see what exactly you're doing or see how you install it.  VS is prolly the most widely used IDE on Windows.

BTW, their is also Code::Blocks.

Also I hope I'm not coming across as rude but not to put a damper in your dreams, chances of you creating a Xbox game in C++ is very slim right now unless you have thousands of dollars and can convince MS to license you a dev kit. Their is C# and XNA if you do want X box development using The Indie Game Channel on the Xbox. You would then use Visual C#.


#5037925 Late night coding

Posted by Chad Smith on 28 February 2013 - 11:57 PM

I look at a lot of my University Assignments when I submit them and I go "I love this code.  Great looking code."  Then a week later I'll look at it again and be like "what is this crap?" 

 

Last semester I had to pull an all nighter to finish a programming assignment for my University.  At about 4:30 in the morning I ran into one last bug that was keeping it from being finished.  It was killing me.  I finally said w/e I'ma go to bed.  When I finally woke up I found and fixed the bug in literally one minute at looking at the code again and the mistake was a simple mistake that happens when you first start programming.  Oh I love late night coding.  lol.




#5031292 Learning By Doing vs Learning By Reading

Posted by Chad Smith on 11 February 2013 - 08:02 PM

Everyone learns different. I would not say their is any one way to learn programming well, except only thing in common is practice, practice, practice, oh and more practice.

When I first started learning programming everything I read I found a way to put into code and coded something. No matter if it wasn't fancy or if it was stupid and dumb. I coded it and enjoyed it. Now I'm to the point where I can't find myself to code. Not because I don't enjoy it now, I enjoy it more than ever still. It's because I for some reason all of a sudden started to care about how awesome something was coded instead of the project in general.

That is what is important in my opinion. Just code. Don't worry about how fancy or nice the code is. Just code. If you need/want help try your book, Internet, or ask here. Though just code. When your done with a project post it here and ask for a code review or something. So many people here will review your code and give you good suggestions. Then code some more and before you know it you'll be here answering questions for people. You will always be learning programming though. Professionals learn something new or different every project. Just keep coding and learning.

I guess you can say my suggestion is to just code, code, code. Need help look at your book or ask here. Though while beginning coding don't always worry about making it all fancy and nice code. You will never actually do or learn anything then. That's my problem right now.

Wish you best of luck




PARTNERS