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

Cornstalks

Member Since 25 Sep 2004
Online Last Active Today, 11:13 AM
*****

#5062811 Making a "Busy Loop" not consume that much CPU (without Sleep)

Posted by Cornstalks on 18 May 2013 - 09:22 AM

You can yield the thread's time slice. This will reduce CPU usage while still being higher "precision" than sleep(). There are several ways to do it:

 

C++11 threads: std::this_thread::yield()

C11 threads: thrd_yield()

Boost threads: boost::this_thread::yield()

Pthreads: pthread_yield()

Win32 threads: Sleep(0)

Java: Thread.yield()

C#: Thread.Yield()

 

If you're using another language, you'll have to look up how to do it in that language.




#5062701 std::sort vs. list::sort

Posted by Cornstalks on 17 May 2013 - 06:59 PM

The standard does not state what algorithm must be used for either std::sort or std::list::sort. It does say, however, that both must complete in O(nlogn) (on average; I'm unsure if the standard states their maximum complexity on worst case execution). From what I've heard, std::sort typically uses intro-sort (which is O(nlogn) in both the average and worst cases). std::list::sort often uses mergesort. Implementations might do some clever modifications to these general algorithms, though, so they may not just be straight implementations of well known algorithms.

 

There are several things that might contribute to your big discrepancy:

  • Bad compiler options for timing code. If you didn't test "release" code (and instead tested "debug" code), the standard containers might be doing a lot of error checking and validating of iterators. Also, you should consider turning on your compiler's optimization flags so it doesn't generate "dumb" machine code (but if it's too smart, it could optimize too much of your code away and make your timings meaningless).
  • Cache misses. This one can be huge, and it's hard to say exactly when and if it's occurring. Tools like valgrind (if you're not on Windows) can help detect cache misses. std::list doesn't necessarily store the elements in a contiguous array, which could result in some extra cache misses (and in terms of CPU cycles, a cache miss is a big slow down).
  • Usage of std::clock(). std::clock() does not measure "wall clock" time (i.e. what your watch says). It measures "CPU time," which is completely different. While it should work in theory (the difference of two std::clock() calls is supposedly meaningful, compared to the actual value of an individual call), it's not the best way to really profile your code (CPU sampling with a proper profiler (like Visual Studio's) is far more effective).



#5061424 When to run the collision detection code?

Posted by Cornstalks on 12 May 2013 - 10:54 PM

Don't do collision detection every single time you move an object (that is, don't move an object, do collision, move the next object, do collision again, etc.). That messes up time of impact ordering (that is, one object is at the new updated position while everything else is at the old positions... if you run collision detection code now it could collide with things that should have moved). Additionally, this is at least twice as expensive as it needs to be (in terms of computation).

 

Move all objects. Then do collision detection. It'll give correct time of impact ordering and it's more efficient.

 

If you're doing swept collision detection, you can solve for velocities, do collision detection, then integrate for positions. But it's still a "update them all at the same time en masse" concept.




#5061416 What's the true worth of an initial game idea?

Posted by Cornstalks on 12 May 2013 - 09:59 PM

To answer the title's question of "What's the true worth of an initial game idea?": nothing.

 

The initial idea in and of itself is not worth anything. Initial ideas are incomplete, flawed, and vague.

 

Refined ideas that are complete, specific, etc. might be worth something though. But it's not the initial idea that gives them worth. It's the refining process that gives them worth. That refining process takes time and involves feedback from those doing the actual implementation. It takes good communication skills, and requires a smart and creative mind to work around legal and physical constraints and limitations that might come up when implementing the actual game. It requires the ability to look at the initial idea from different perspectives and fill in holes and missing details.

 

In short, you don't pay the idea man for his initial idea. You pay the idea man for his ability to refine his initial idea into a full fledged game (at which point he's no longer an "idea man" but a proper game designer).




#5060681 FFmpeg: calculating PTS of decoded video frames

Posted by Cornstalks on 09 May 2013 - 02:35 PM

  • Despite the fact that the first video frame doesn't show up until 6.68 seconds into playing the video, are the audio and video in sync?
  • Does the audio also have a delay, or does it start immediately?
  • Are you taking into account AVFormatContext.start_time? If the start_time is > 0, I would suggest subtracting start_time from all PTS (otherwise there's a delay).

 

Note that AVPacket.dts is in AVStream.time_base units, not AVCodecContext.time_base units.

 

PTS/DTS issues are my primary source of anger when dealing with video. I have found the method used by dranger's tutorial not to be sufficient. I used a combination of methods: checking AVFrame.best_effort_timestamp, checking AVPacket.dts and pts, and maybe a few other things I can't remember. If all of those failed (i.e. were AV_NOPTS_VALUE), I gave the frame a duration of 1/fps.

 

Also, what files are you struggling with? I typically found MPGs to be the most problematic.




#5060611 Your thoughts on Adobe's new subscription-only model?

Posted by Cornstalks on 09 May 2013 - 10:08 AM

I just dont see why people are so upset...

Because a) not everyone buys the full suite1, b) not everyone upgrades to the latest and greatest every time a new version comes out2, and c) choice is nice3.

 

1: Sure, this might be nice if you're the kind of person who bought the Master collection, but if you didn't buy the Master collection but instead bought a couple of products or bought the Design or Web collections, this deal isn't nearly as worthwhile.

 

2: You do realize that if you bought CS3 when it came out 6 years ago, then upgraded to CS6 today for the $2000 you don't want to pay, that's still about half the price you'd be paying for the $50/mo CC subscription, right? Some of us would prefer to do that because we don't always need the latest features, and it's cheaper to wait and upgrade every few versions than pay $50/mo. Or, if you're an even cheaper person, you wouldn't ever upgrade and would instead run CS3 (because it might fulfill all your needs) for several more years, making the $50/mo subscription look even less attractive.

 

3: I have nothing against Creative Cloud in and of itself. If it works for someone, great. But I do have something against it being the only way to get Adobe products now. Just because it works well for you does not mean it works well for me. And in fact, it doesn't work well for me. I've done the numbers. For the Adobe products I use, and for how much I use them, and for how much money I make using them (read: $0), CC is way more expensive. I can't justify the subscription.

 

As a side bonus: I can get CS6 Master collection for $600 with a perpetual license. I can buy it now and use it for several years. That's waaay better than the educational pricing of $30/mo (because a) I can use CS6 Master collection after I graduate (while I can't for CC), and b) $600/$30 = 20 months, meaning that after 20 months of CC I'd have been better off buying it for $600 and using that for a few years and then upgrading when I feel compelled to).




#5060036 Your thoughts on Adobe's new subscription-only model?

Posted by Cornstalks on 07 May 2013 - 09:45 AM

What are your thoughts on Adobe's subscription-only model? Personally, I'm disappointed. I think offering a subscription model is fine, but I think only offering a subscription model is... dumb.

 

My family has had Photoshop CS3 Extended for about 6 years now. The newer versions of Photoshop have offered fewer and fewer new features that justified upgrading, and as a result of not upgrading for ~6 years we've been able to stretch our "dollar per year" out to a decent amount. $20/mo seems fine, and I'm okay with it for Photoshop, actually, but my dad wants to buy Lightroom and Acrobat (which, no matter how you look at it, are not worth $20/mo each), which means to get what we want requires $50/mo. Not worth it at all. Sure, we get access to more software at $50/mo, but much of it is software I don't need or want.

 

So, how do you feel about Adobe's new subscription-only model? Will you be subscribing, or holding onto your current versions (or buying a copy of CS6)? Do you think this will help any Adobe alternatives to become more popular, and if so, which ones do you think will increase? I'm always looking for new, good alternatives. I've been using Gimp and Inkscape on one computer, and they're okay, but certainly not a drop-in replacement for Photoshop or Illustrator.

 

I for one will be upgrading things to CS6 and not subscribing. I also hope this move by Adobe encourages competition in their monopoly.




#5058783 sfml mouse clicking bugs

Posted by Cornstalks on 02 May 2013 - 09:17 PM

It's impossible to say with that little snippet of code. That said, this looks wrong:

 

 

sfMousePos.x = (float)sfEvent.mouseMove.x;
sfMousePos.y = (float)sfEvent.mouseMove.y;
 
You don't even know if sfEvent is a MouseMoved event. First check if sfEvent.type is sf::EventMouseMoved, and if it is, then retrieve the mouse position. If it's not a MouseMoved event, then you're going to just get garbage values out of sfEvent.mouseMove.x/y (since sfEvent is a union of various events). Something like:
 

while(window.pollEvent(sfEvent)){
 
     switch(sfEvent.type){
 
     case sf::Event::Closed:
         window.close();
         break;
 
     case sf::Event::MouseMoved:
         sfMousePos.x = (float)sfEvent.mouseMove.x;
         sfMousePos.y = (float)sfEvent.mouseMove.y;
         break;
     case sf::Event::MouseLeft:
         bPaused = true;
         break;
 
     case sf::Event::MouseEntered:
         bPaused = false;
         break;
 
     default: break;
     }
}




#5058769 Two classes, same name - solution?

Posted by Cornstalks on 02 May 2013 - 06:52 PM

Please use a "normal" archiving format, like zip. Using something weird, like rar, will make people less likely to download the code.

 

Wait, rar a weird archiving format? In all due honesty, thats a new one for me, rar has been my "standard" for years now. But, never mind, I strongly suppose you know what you are talking about, so, yeah, will relate to zip in the future.

Well, given the fact that neither Windows nor OS X can extract files from .rars without some 3rd party software, I consider it a "weird" format.




#5058749 Two classes, same name - solution?

Posted by Cornstalks on 02 May 2013 - 04:47 PM

Please use a "normal" archiving format, like zip. Using something weird, like rar, will make people less likely to download the code.

 

It looks like you're running into MSVCs issue with files with the same name. At least that's my guess. It's technically a bug in MSVC. It's kind of a pain in the butt; I wish they'd fix it.

 

Edit: SiCrane... It is unholy how ninja-like you are!

 

Edit edit: @downvoter: care to expand on the reason behind the downvote? I'm not offended or anything, but I am puzzled about what deserved a downvote, and if there's something I can improve I'd like to know.




#5058619 Row vs Column Major Matrices: Most Useful?

Posted by Cornstalks on 02 May 2013 - 08:19 AM

Before you're dead set on using column-vectors, check what your shaders use, because, oh joy, HLSL uses row vectors and GLSL column vectors AFAIK, another major difference (pun indended).

Really? So HLSL uses row vectors but (defaults to) column-major matrices?




#5057603 Simple c++ problem question

Posted by Cornstalks on 28 April 2013 - 06:18 PM

If I have a rectangle of size 42 x 22 as above.And I want to cut it in pieces of 30 x 20.In the above example,it shows me that the pieces I will get will be 0.How is that possible? Shouldn't it be 1?!

To expand on what Adam_42 said, it sounds like the textbook is asking you to come up with a certain number of cuts of each size such that the minimum amount of paper is wasted.

 

To give an analogous problem: I have a $3.50. There are 4 things in the store I can buy, all of them costing different prices. Let's say item 1 is $0.50, item 2 is $1, item 3 is $2, and item 4 is $3.25. What should I buy such that I have the least amount of money left? Sure, I could afford to buy one of item #4. But that would leave me with $0.25 remaining, which isn't the "least amount of money left" (because if I instead bought one of items 1, 2, and 3, I would spend $3.50 total and have 0 left, which is more "optimal").

 

Similarly, in your problem, it's not about "what can you cut?" It's about "what should you cut to get the least waste?"




#5057589 Scared that Nintendo will say that one word: "NO!" (need input)

Posted by Cornstalks on 28 April 2013 - 05:39 PM

Also, please know I have great respect for the gaming community and the laws surrounding it and for video game companies, and if Nintendo says no, then I won't continue on respectfully.

I think I understand what you mean, but the way that's worded, it reads like you'll continue on disrespectfully wink.png




#5057584 Scared that Nintendo will say that one word: "NO!" (need input)

Posted by Cornstalks on 28 April 2013 - 05:33 PM

So, my question is this:  If you were Nintendo, what would you say?

I would say no. I wouldn't care that you wouldn't be making money or not. The problem is that I'm not making money (regardless of whether you are or not). It's my intellectual property. I use it to make money. It's what funds my company. If you use it, it must benefit me.

Also, if I let you use it, then I am giving up some control of it. I want to control the story. I want to set the stage. I want to make sure that the game evolves in such a way that it creates maximum profit for me. I need the story to be written the way I want it written. If I let you do that... well, that's not gonna happen.

AND, if you were to say no, in the future what would I need to show Nintendo to even get a possible yes?

I would need to see a professional portfolio of past completed work. You would need to be a professional studio that had already released games that impressed me. That would prove to me that you have the skill to complete it with the kind of high quality that I expect (and demand). I certainly wouldn't let a small indie studio use my intellectual property.

But even then, chances are I wouldn't let you, even if you were a professional studio. I'm Nintendo. I've got studios. If I want it done, I've got an army of professionals to do it. You'd have to be pretty dang convincing to convince me to let you make a game for me, instead of using the thousands of employees I already have.

Would Nintendo want, for example, a Game Design Document?

I'd say yes and no. Yes, they would probably want that, but no, that probably wouldn't be enough. Not even close.

Sorry, I'm just trying to be realistic. Nintendo is pretty defensive about their intellectual property. Most companies are. It's like trying to walk into the White House to meet with the president because "you have a good idea." You don't really get to just walk into the oval office, present your idea to the president, and have him say, "I like it, I approve!" Fat. Chance.


#5057484 Sfml2.0 networking tutorial?

Posted by Cornstalks on 28 April 2013 - 10:37 AM

The SFML tutorials don't really explain how networking works in detail. They mostly focus on how to use SFML to do networking (i.e. the code). The SFML 1.6 networking tutorials can be useful, and it's usually pretty easy to convert 1.6 code to SFML 2.0.

 

But if you're wondering how sockets and all that stuff, +1 for Beej's network tutorial.

 

Someone told me that the latest SFML 2 version has examples and documentation, just not yet up on the website. If you download from the repository, and build with CMake, you can have it build the documentation and examples as well.

The tutorials are done but not all uploaded to the website, but they're not in the code repository either. The documentation is up to date on the website. It does have examples, though, which could be useful.

 

FWIW, the new SFML 2 logo is going to be chosen today, and then integrated into the website for the official SFML 2 release in a few days. So the 2.0 tutorials will be up really soon.






PARTNERS