Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 31 Jan 2009
Offline Last Active Private

#5316427 A quick way to determine if 8 small integers are all equal to each other

Posted by on Today, 03:38 AM

As you can see, no branches, no need for silly trickery. Just avoid the short-circuiting conditional && and || and the compiler will probably do fine.

Does the shortcircuiting matter here actually? I imagine the compiler should be able to optimize out cases where it notices that operations can be done in either order and it not affect the outcome.


EDIT: did some quick tests myself and... well, GCC does indeed fail to optimize that out. Whoops. Also pretty disappointed overall this time, GCC really didn't try to do anything clever regardless of what I threw at it. I guess there isn't much else to be done about it (assuming the code is already cache coherent). Then again I recall reading that CPUs now try to keep track of where recent branches tend to go? On code that's run on a tight loop that should already help reduce branch mispredictions after a few iterations.

#5316200 Moving from plain "ascii" to XML?

Posted by on 22 October 2016 - 05:40 AM

Wait, that parser can only accept the options if they come in that exact order? (even though each line starts with the name of the relevant setting)

As a counterpoint though, it can be convenient for the end user if config files ARE human-readable.

Yeah, especially if you changed something that keeps crashing the game miserably and want to undo it. Being able to edit the settings directly makes this task easier. It's also a good place to put obscure settings that normally wouldn't be useful (i.e. extremely advanced stuff) but that somebody may want to give a try.

#5316128 Moving from plain "ascii" to XML?

Posted by on 21 October 2016 - 03:34 PM

As has been said before the current format is already much simpler than XML... I wouldn't bother with XML unless you end up with complex enough structures to warrant deep trees. Doesn't look like that's the case here.


If you really want to switch to something more standard, I guess you could go with INI files, though there's a bunch of libraries out there to look for... and it may even be feasible to just write your own parser (the main reason they took off back then is that they're that simple, after all). Or even modify your own, I mean, replace the space with an equals sign and you're halfway there =P

#5315381 When you realize how dumb a bug is...

Posted by on 15 October 2016 - 08:58 PM

The problem in many cases is that you read what you think you wrote, not what you actually wrote. That tends to contribute to typos being so hard to find. Once you're tired of looking for an obvious mistake you'll just start rereading everything carefully again just to try to overcome that issue.


Of course there's also the complementary problem where you waste the whole day looking for a dumb typo, and then you realize the problem is that the algorithm is broken in the first place...

#5314682 Fast Approximation to memcpy()

Posted by on 11 October 2016 - 09:44 AM

Don't forget about overcommiting. Enjoy processes dying out of nowhere without any warning or explanation.


As for speed, reminds me of a situation I had with memcmp. Apparently at least on some implementations it's optimized for comparing large chunks of data when I was using it to compare a few bytes instead - but not a fixed amount so the compiler can't just unroll it. And this was in a tight loop. Turns out that the overhead of preparing for a large comparison outweighted the benefit, to the point that simply adding a simple check for the first byte (since most comparisons would fail) would speed it up like crazy.


Just because the standard library is probably better optimized than what you can do doesn't necessarily mean it'll be best optimized for your actual case.

#5313820 Things I wish I had never heard

Posted by on 04 October 2016 - 01:27 AM

Yeah, converting the PNG to 8-bit with dithering is another option (that turns out to save a lot of space), though not everybody likes the dithering and also has a serious potential to backfire if there are too many hues. Still probably the best option when you have control over what images are processed though, especially at high resolution. As for JPEG 2000, I think it also has the issue of nearly nothing supporting it, at least as far as everyday use goes (IIRC it has way more support in the professional side of things).


In any case the original point wasn't so much this but rather the suggestion of using javascript for an horrendously expensive operation =P

#5313686 Things I wish I had never heard

Posted by on 03 October 2016 - 03:22 AM

PNG compresses much worse for things like photos or the like (PNG is good at flat shades and gradients), but JPEG can't support transparencies at all so you're forced to stick with the rectangular shape. JNG is meant to be a middle point that uses the best part of both (see how its name is a mix of JPEG and PNG, even). Browsers don't support it though, so probably your best choice here is to split it into two files (a JPEG and a PNG) and merge them in a canvas. Or you can be careless, parse the format yourself in a script, then bring the browser to a halt because of how much CPU time and RAM you're hogging by doing that. Especially if the image is large.

#5313574 Things I wish I had never heard

Posted by on 02 October 2016 - 05:50 AM

"as a workaround you could probably decode JNG with javascript"


For context: https://en.wikipedia.org/wiki/JPEG_Network_Graphics

Basically JPEG for color with PNG for alpha. Legitimately good idea, but not supported in browsers because it's a subset of MNG and there's a religious war against MNG pretty much. But yeah, not the kind of thing you want to do in javascript, you'd be implementing the decompression algorithm yourself for starters...

#5312376 Why C# all of a sudden?

Posted by on 25 September 2016 - 01:11 AM

For 20 years C++ was the recommended standard language, especially in the gaming industry. Mostly because it is fast and powerful, inheriting most programming language standards you can possibly think of.

Game and engine development have diverged for a while and the breach is only getting larger over time. Neither AAA nor indie studios build their own engines anymore, that job is now left to middleware developers. All that performance you're talking about needs to be done on the engine side of things, while game developers now instead focus on the higher level stuff - and that can be done with languages that aren't as close to the metal as C++.

It also says something about how complex the game industry has gotten now.

#5309765 Why didn't somebody tell me?

Posted by on 07 September 2016 - 02:53 AM

Consistency? Pretty much every program will let Ctrl+C work as long as anything is selected, that's just how the clipboard works. If anything, Visual Studio is letting you to work around that =O)


EDIT: wait, are you talking about like when you select a blank line and accidentally copy it, or literally when absolutely nothing is selected? If the latter then yeah that's horribly dumb...

#5306945 Fast way to cast int to float!

Posted by on 20 August 2016 - 08:10 PM

In somewhat related news, today a coworker said two words that were never meant to go together: "Enterprise JavaScript". With systems like node.js being more popular we are seeing the rise of abominations that should have been killed on sight, without mercy. I told him I did not accept "Enterprise JavaScript" could possibly be a thing in a reality I participate in.



"Enterprise HTML5" has also been mentioned in that thread.

#5306516 When you realize how dumb a bug is...

Posted by on 18 August 2016 - 05:26 AM


Why do I keep getting all the weird tool bugs?
You're too deadly for normal bugs, so they went to plan B, and attack you indirectly by hiding in tools.


Considering how once I got a game to travel backwards in time by pausing it, I think you probably aren't too far off from the truth.

#5306342 GUI Objects

Posted by on 17 August 2016 - 06:57 AM

Yeah, you need to do these things:

  1. Not use the depth buffer
  2. Use a different projection matrix (2D instead of 3D)
  3. Render it after the 3D scene (so it's on top of it)

That's the simplest way to render UI elements. And of course undo all that when you start rendering 3D again the next frame!

#5306105 When you realize how dumb a bug is...

Posted by on 16 August 2016 - 01:40 AM

Had a sound engine spazzing out because it turns out the last byte of the stream data got trimmed out somehow. It required three tools and the memory layout to align just right (wrong?) for this to happen.


Why do I keep getting all the weird tool bugs?

#5302826 When Tertiary Operators Become Confusing

Posted by on 27 July 2016 - 04:56 PM

Yeah, the example replacement in the first post is not that great because it's actually adding more stuff (and indeed adding enough to be way too much for the ternary operator to stay readable).


That said, if it was up to me I'd do:

move_speed = normal_speed;
if (running)
   move_speed *= run_speed;

I'm lame =P