Wednesday, October 3, 2012

Reminder: TCPRelay 0.3 alpha 3 released!

For those people who follow my blog/Twitter: TCPRelay 0.3 alpha 3 is now available! Check out the original post for version 0.3 and download the 32-bit or 64-bit version. You may also need to install the Microsoft .NET Framework 4. Keep in mind that this is an alpha version; some features may not behave correctly.
There were two changes to the GUI:
  • NEW: [alpha 3] application now has an icon (thanks to Fryderyk "Ziel" Dachowski!)
  • FIXED: [alpha 3] tooltips for speed buttons were incorrectly referring to "as slow as possible".

Thursday, September 27, 2012

Simplify ternary operators

One of my pet peeves in Java/C/C++/C# programming is the use of the ternary operator ?: with boolean values. It's almost always redundant, makes code harder to read and can be easily replaced by a simpler boolean expression that also has the advantage of being "branch-free" in some languages, that is, do not require the CPU to select a path of execution based on a condition, which can be very expensive. The best compilers will optimize them away in a manner similar to what I describe below, but they still don't improve code readability.

From this point onward I'll be using the Java/C/C++/C# code syntax. A boolean expression is any valid expression that results in a boolean value. This may be anything from the constants true and false all the way to complex expressions such as x == 1 && (y > 3 || z <= 1.25) && !checkSomething(x, y, z) (assuming checkSomething(...) returns a boolean).

Say you have the condition c and the boolean expressions p and q. The following table contains all possible conversions from a ternary expression to an equivalent boolean expression:

#Ternary Expressionif-then-else ExpressionEquivalent to
1c ? p : qif (c) p else q(c && p) || (!c && q)
2c ? p : trueif (c) p else true!c || p
3c ? p : falseif (c) p else falsec && p
4c ? true : pif (c) true else pc || p
5c ? false : pif (c) false else p!c && p
6c ? true : falseif (c) true else falsec
7c ? false : trueif (c) false else true!c
8c ? true : trueif (c) true else truetrue
9c ? false : falseif (c) false else falsefalse

Note that #1 may or may not result in more readable code; it is probably better to use the ternary operator in that case. #6 through #9 are poor coding practices and should be replaced as soon as possible by their equivalent boolean expressions. #2 through #5 require attention and almost certainly will result in better, cleaner code.

Also note that c ? p : q is equivalent to if (c) b=p else b=q. In other words, if any boolean variables are assigned a value that depends on the condition of an if-then-else clause, then that value can be simplified according to the equivalence table above, as long as there are no unintended side-effects.

Let's try this with an example:

boolean b = i > 5 ? j == 3 : false

or, as an if-then-else clause:

boolean b;
if (i > 5) b = j == 3; else b = false;

Looking at the above table, this matches expression #3, with:

c = i > 5
p = j == 3

The equivalent expression would be:

boolean b = i > 5 && j == 3

which is slightly shorter and certainly less confusing than the above ternary or if-then-else statements.

Friday, September 21, 2012

Now Playing: Borderlands 2

This is going to be my first gaming-related post (yay!). I had a blast playing the first Borderlands game a while ago. Picked Mordecai, grabbed sniper rifles and pistols and chose a set of skills with emphasis on sniping. Cleared the whole game, including all DLCs. Leveled to 61 (before the cap was raised to 69). Then I got bored and hacked my character to make the most insanely powerful equipment out there -- 1.2k x4 damage pistols with near-perfect accuracy and very fast firing rates (and the ability to crash the game once in a while), "god mode" shields (which displayed as negative 2 billion and never drained), insanely fast sniper rifles and even some overpowered Eridian guns, and maxed out all skills in all trees just because. I remember doing a critical hit for the maximum possible damage of 99999 with a melee attack once. Needless to say, the poor victim exploded in a shower of gibs.

Back then I didn't have a computer powerful enough to record my gaming, nor did I have an YouTube channel or a stream, so unfortunately I got (almost) nothing to show you. :(

When the sequel was announced I was pumped. I watched every trailer and every bit of gameplay and just had to play it now (er...  then). Borderlands 2 was released three days ago (September 18th), but I had to wait two more days as the game would only release on September 20th here in Brazil.

The wait was over, and I had to stream it. Unfortunately, my microphone is really bad, so I couldn't comment on the stream itself.

Here goes my personal opinions on the game:
  • Borderlands 2 has an amazing sense of humor. Claptrap's lines are among the funniest, as are Handsome Jack's and pretty much every other non-srs-bsns characters'. If my microphone was working, you'd hear me laughing about every 10 seconds or so.
  • The guns are much better polished, and each brand feels unique -- an addition I liked a lot. I quite enjoy Jakobs pistols - they let me fire as fast as I can pull the trigger, which is to say, really fast. Tediore weapons are fun; you throw these cheap pieces of garbage away when reloading and a new gun materializes in your hands while the discarded gun proceeds to explode. I also like how Bandits can't spell their weapons properly.
  • Enemies are much smarter now too, and they also feel more "natural", more "realistic". Bandits will actually look for cover or just put their faces straight into your gun, and they also seem to work as a team now. They also have better environmental awareness and try to avoid/use explosives to their advantage (at least that's how it feels to me).
  • The world is HUGE. I've partially explored three major areas and this makes about 5% of the in-game world map. Each individual area is much larger than the previous iteration's areas. You also get a bunch of side-quests right at the beginning (OK, not too early) and there's always something to do or explore everywhere. Not to mention the vistas are amazing!
  • The new UI has a bunch of improvements, but the inventory feels a little clunky and not much of an improvement from the first game. Comparing items was made easier, but equipping items isn't as simple as before. To switch a weapon, you have to go to the backpack column, click on a weapon, then click on the weapon slot you want to switch. Switching shields, mods and stuff for some reason requires the same steps as above, even though there is only one slot for each. Buying and selling items, however, is much better than before.
And now, a bit of gameplay! The video quality should improve after YouTube decides to process the videos. Oh, and sorry about some videos being cut before the actual end. You're better off watching the videos from my stream channel anyway.






You can also watch the videos on my stream channel in 1080p: 1 2 3 4 5 6 7-1 7-2 7-3 8 9 10 11-1 11-2 11-3

Also, watch me live here!

Sunday, September 16, 2012

TCPRelay 0.3 alpha 3

TCPRelay 0.3 alpha 3 is now available! Download the 32-bit or 64-bit version. You may also need to install the Microsoft .NET Framework 4. Keep in mind that this is an alpha version; some features may not behave correctly.

What's new in this version:
  • General
    • NEW: localization support for:
      • [en-US] English (United States)
      • [pt-BR] Portuguese (Brazil)
    • Send me an e-mail if you wish to add your language.
    • NOTE: only the GUI version has support for localization for now.
  • Console
    • FIXED: application no longer crashes when a connection is closed. The fix never got into 0.2.2.3 for some reason.
  • GUI
    • NEW: Localization support, as above. By default the application will use the default language set in your operating system. You can override this by passing the language code as an argument to TCPRelay.exe. The supported language codes are listed between brackets above.
    • NEW: [alpha 3] application now has an icon (thanks to Fryderyk "Ziel" Dachowski!)
    • FIXED: [alpha 2] localization should now work properly on all parts of the GUI.
    • FIXED: [alpha 3] tooltips for speed buttons were incorrectly referring to "as slow as possible".
TCPRelay finally has its own icon, thanks to Fryderyk "Ziel" Dachowski! I appreciate your work :)

Check out the official topic on XSplit's forums and see for yourself all the great feedback people gave me.

Sunday, August 12, 2012

TCPRelay 0.2.2.3 beta

TCPRelay 0.2.2.3 beta is now available! Download the 32-bit or 64-bit version. You may also need to install the Microsoft .NET Framework 4.

What's new in this version:
  • General
    • FIXED: [0.2.2.1] no longer tries to reverse DNS lookup the target host. Should fix issues with not being able to connect to certain servers.
    • FIXED: [0.2.2.2] reduced socket buffer size. This should eliminate dropped frames and disconnects caused by a change in version 0.2.1.0.
  • Console
    • FIXED: [0.2.2.3] application no longer crashes when a connection is closed.
  • GUI
    • FIXED: Target URI field no longer loses selection after being populated by the Twitch.tv updater.
    • FIXED: speeds below 1 bps no longer show as ",# bps" or "bps".
    • FIXED: [0.2.2.3] outbound and inbound speeds were swapped.
    • IMPROVED: connection info no longer shows the local bandwidth (the old Received column). Since TCPRelay cannot receive more data than it can push to the servers (due to blocking I/O), that column was completely redundant. The numbers displayed in the GUI now represent the actual bandwidth usage (the old Published column).
    • IMPROVED: average speed is now an average of the last 2 seconds.
    • IMPROVED: connection info now displays connection duration in HH:MM:SS.
    • IMPROVED: [0.2.2.3] closed connections now display the overall average speeds.
    • Speed history graph:
      • IMPROVED: widened to fit the extra available space.
      • IMPROVED: now displays a wide bar with the current speeds to the right of the graph.
      • IMPROVED: slightly reduced resource usage.
TCPRelay still does not have its own icon. If anyone could provide me with one, preferably in 16x16, 32x32, 48x48, 64x64 ICO and 128x128, 256x256 PNG formats, I'd be very grateful! :)

Check out the official topic on XSplit's forums and see for yourself all the great feedback people gave me.

TCPRelay 0.2.1.0 beta

TCPRelay 0.2.1.0 beta is now available! Download the 32-bit or 64-bit version. You may also need to install the Microsoft .NET Framework 4.

What's new in this version:
  • General
    • FIXED: connection attempts may now timeout after 5 seconds.
    • IMPROVED: connection errors are now handled better.
  • GUI
    • FIXED: tab order between components is now fixed.
    • FIXED: speed graph no longer stops working after a while.
    • FIXED: sometimes clearing all closed connections would cause the scrollbar graphics to remain on the window.
    • IMPROVED: added tooltips to several components.
    • IMPROVED: target URI now accepts addresses in <host>:<port> format.
    • IMPROVED: error messages are now shown if TCPRelay fails to start.
    • IMPROVED: connection attempts and errors are now shown in the list.
    • IMPROVED: connection list refresh speed can be changed.
TCPRelay still does not have its own icon. If anyone could provide me with one, preferably in 16x16, 32x32, 48x48, 64x64 ICO and 128x128, 256x256 PNG formats, I'd be very grateful! :)

Check out the official topic on XSplit's forums and see for yourself all the great feedback people gave me.