Friday, December 14, 2012

TCPRelay 0.3 beta


TCPRelay 0.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:
  • GUI
    • NEW: the last Target URI and Listen Port values are now saved to the Windows Registry under the key:

              HKEY_CURRENT_USER\Software\StrikerX3\TCPRelay

      Now every time you restart TCPRelay the last used server and listen port should be automatically set.
Check out the official topic on XSplit's forums and see for yourself all the great feedback people gave me.

Friday, November 30, 2012

State of TCPRelay, and Natural Selection 2

It's been a while since my last update here. If you're wondering why I haven't been updating TCPRelay lately, it's mostly because there was no demand for improvements or fixes for it. Also, I work as a systems analyst and that involves a lot of programming, so it's also a matter of being burned out too.
Anyway, here's a few ideas for the next versions of TCPRelay I have written down:
  • Stream delay: I'm not entirely sure this is possible without inspecting the stream data, but this is definitely worth checking out.
  • A way to fetch server lists from other services (own3d.tv, YouTube, ustream, ...). Also enable users to add their own lists, keep them between sessions and share with others.
  • Improve localization support and allow users to translate TCPRelay to other languages.
  • Fork into TCPProbe -- basically TCPRelay with packet inspection and manipulation capabilities through .NET plugins. Could be useful for network development.
If you have any suggestions, please feel free to comment.

On another note, I've been looking for a strong, competitive FPS that's reminded me of the old, but fun formula of Unreal Tournament and Quake: fast-paced action with insane movement skills and pinpoint aiming accuracy required. Unfortunately, since 2007 (when UT3 was released), there was not a single memorable FPS that followed the formula and caught my interest, turning me off from the genre. I went on to other games, including World of Warcraft, Starcraft 2, Borderlands 2 and several casual and indie games. That is, until last month.

Natural Selection 2 was developed by Unknown Worlds Entertainment and released on October 30th. I haven't heard much about the game until then, but instantly got addicted the moment I got into a multiplayer game. It's an amazing blend of RTS and FPS with a surprisingly friendly community -- the complete opposite of most popular games such as Dota 2, LoL and Starcraft 2. People in NS2 actually help each other out, newbies ask questions and learn tricks and tactics from veterans (there's even some pro players giving out "classes" for free on their servers! See here and here); there's no split between the n00bz and the pros. Teamwork and coordination are absolutely required to get somewhere. Trying to Leeroy Jenkins your way into the enemy base *will* get you killed, unless you happen to be an Onos fighting against a bunch of rookie marines (and even then, if they know how to press the fire button and move their mouse to follow a giant suicidal gorilla-rhino-thing around, you *will* go down).

I highly recommend NS2 to anyone who has been yearning for something other than the generic "realistic" war shooter #235 with killstreaks and "realistic" gunfights, or anyone who enjoys either the FPS or RTS genres at all. It may not be as popular as LoL or Dota or SC2, but it's definitely competitive and interesting to watch. Refer to this topic on the UWE forums for a list of streams/YouTube channels/whatnot on NS2 competitive play. Oh, and it's cheap on Steam -- just 25 bucks.

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.

Friday, August 10, 2012

TCPRelay 0.2 beta

TCPRelay 0.2 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:
  • Completely rewritten in C#. TCPRelay now requires .NET Framework 4 instead of Java. Should help eliminate some of the issues people were having with the Java Virtual Machine.
  • NEW: created a graphical user interface for easier configuration and real-time connection and bandwidth usage statistics. The command line version still exists as a separate executable file.
  • FIXED: -ttv now lists the default Twitch.tv server as well.
Some screenshots of the new GUI:

Right after starting up

TCPRelay 0.2 beta GUI

The server list

TCPRelay 0.2 beta GUI

Doing a bandwidth test with XSplit
TCPRelay 0.2 beta GUI

TCPRelay does not have its own icon yet. 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.

Wednesday, July 4, 2012

Using the Xbox 360 Controller as a mouse on Windows

I wrote a small JNI library while I was learning how to use XInput for use in my Java games and to test it I wrote a little program that uses my Xbox 360 Controller for Windows as a mouse controller.

To use it, you need to have at least one Xbox 360 controller connected to your computer.

While the program is running:
  • Press Start on any connected controller to begin controlling the mouse cursor with that controller. Press Start again to stop.
  • Press Back to release the controller (the program will no longer accept input from it). Once all controllers are released, the program will terminate.
  • To move the mouse cursor, use the left stick.
  • Press A to left-click, B to right-click, and X to middle-click.
  • The analog triggers act as the scroll wheel. Left scrolls up, and right scrolls down.
  • Press and hold the shoulder buttons to alter the cursor and scroll movement speeds. Left slows down, and right speeds up.
Note that this only works in Windows, and only with Xbox 360 Controllers for Windows.

Download here: http://www.sendspace.com/file/ipigmh (if you have any suggestions for a better place to share files, please tell me in the comments!)

You may need to install the Microsoft Visual C++ 2010 redistributable packages as well:

The Entity-Component Model

Most game programmers, when they start thinking of their game structure, will usually go the Object-Oriented route: have an Entity abstract base class from which to derive every game object. It starts out great: "I want some objects to be affected by physics, so I'll make a PhysicsEntity abstract class and derive them from it. Cars are affected by physics, so obviously I should extend Car from PhysicsEntity." But then, things start to get out of control. "But wait, my cars are destructible, so I should make them composed of several breakable pieces. How about extending Car from DestructibleEntity? Or maybe make the car composed of several DestructibleEntity parts? And how is the player supposed to control it? Should I subclass Car? PhysicsEntity? Or should I create a Controller class and extend it to handle Player input and... ARGH!"

You can easily see where this is going. There are several ways to solve the problem using OO, but none of them actually solve the cause of the problem, which is the fact that game objects are not easily represented as a hierarchy of classes. In the above example, how would you make the car controllable by the players?
  • By making a Controller or Player entity that tells the Car what to do based on player input?
  • By extending the Car such that it responds to player input?
  • By implementing player input handling on the Car itself? (Please don't do this. Ever.)
  • By creating a superclass of entities that can be controlled by the player and have the Car or PhysicsEntity extend that?
  • ... seriously, there are so many ways to "solve" this!
There are also many other problems with this. For instance, what if the game designer goes crazy and decides to let players drive rocks and tree trunks? This is suddenly very hard, if not impossible to do.

So, how do you really solve this problem? If you're reading this, you already know the answer. Hint: It's in the title!

The solution is to use an Entity-Component model.

What is an Entity-Component model?

Entity-Component models take advantage of aggregation instead of inheritance to represent game objects. There are three key concepts of an Entity-Component model:
  • The entity, which is nothing more than an identifier that represents one instance of a game object in the game world;
  • The component, which contains data regarding one feature of the entity;
  • The subsystem, responsible for executing the game logic with the components.
Each entity really is nothing more than an identifier. This could be an integer number, a string, a UUID, a key in a database, or anything that uniquely identifies a single instance of a game object in the game world. Entities do not contain any kind of logic or data in them (though you may keep a list of components in them for performance reasons). These are instead stored in an entity manager, which not only keeps track of every entity existing in the game world, but also the components attached to each entity, and lets subsystems query for entities that possess a particular set of components.

Each component represents one singular feature of the game object, such as "position in game world", "physics-related data (velocity, mass, density, etc.)", "able to wear equipment", "wearable", "shoots projectiles", "has a health meter", "has a mana meter", and so on. One important restriction is that each entity may possess only one of each component type. It doesn't make sense for a car to have two positions, right? The beauty of this model is that you can attach absolutely any kind of component to any entity, so you can do really silly stuff like having a camera that has a mana bar and is wearable by rocks that can shoot more cameras with mana bars. Even better: you can do this while the game is running. No need to recompile everything because you added one new feature to the camera. That's because the responsibility of performing the game logic is delegated to the subsystems.

Each subsystem performs one small part of the game logic based on a set of required components. Rendering the scene is one of them, as is physics processing, combat calculations, player input processing and many others. Subsystems act on components rather than entities, which means that it doesn't matter what "kind" of entity it is (there is no such thing anyway), the subsystems will work on every entity that possess the required set of components. So, if a physics processing component requires Position, Velocity and Acceleration components, every single entity that possess all three components will be processed by it, be it cars, rocks, stars, the track itself, cameras, or anything - so long as they have Position, Velocity and Acceleration components. Since you can add them while the game is running, as soon as you attach these components to anything, that anything will get processed by the physics subsystem and begin moving around.

There are many other advantages to using an Entity-Component model that goes beyond the modeling itself. Since components and subsystems are very small and (usually) independent, they can be processed in parallel, taking advantage of multi-core CPUs. Also, game designers are free to try all sorts of crazy stuff as mentioned above, and it's very easy to implement new features and subsystems. Try adding a regenerating shield to your cars and make them work with everything else (yes, Rocks, TreeTrunks, Cameras and the track itself too) in the hierarchical model. You'll probably end up with either another bloated superclass or adding the shield functionality to an already super-bloated Entity base class. With the Entity-Component model all you need to do is modify the Health component and its subsystem to be able to handle shields. Now everything that has health may also have shields. You could even make health optional if you wanted to. But don't try to make Shield a separate component in this case, as it will lead to some difficulties later.

By the way, guess what you need to do now to make anything in the world controllable by the player? Yes, create a Driver component and the corresponding subsystem. (Of course, you're still going to need to implement the logic, but it is certainly much faster and easier than before.)

These are the basics of an Entity-Component model. There will be many questions from now on. For instance, how do you instantiate entities that resemble a car now? What about the track, the rocks, the tree trunks? I'll leave this as an exercise for the reader, and explain about it later.

Over the next few posts I will be presenting my own implementation of the Entity-Component model while developing a simple space shooter game.

Read more about Entity Systems:

Saturday, June 30, 2012

TCPRelay 0.1.1 beta

Let me start this blog by talking about one of my simplest (and quite successful) projects: TCPRelay. This is a very simple program whose main purpose is to help users of XSplit (used to run my gaming stream) deal with some upload bandwidth issues. It started as a quick and dirty program that served as a relay between XSplit and the Twitch.tv server and became a nice little command-line tool that made a lot of people happy.

It works like this: while TCPRelay is running, it is listening to a TCP port in the local machine which is by default 1935. For every connection made to this port, a new connection will be made to the target server, the default being live.justin.tv:1935. Every byte TCPRelay receives on the local connection will be sent to the target server, and all responses made by the server will be transferred to the local connection. It is, in fact, a data relay, doing nothing but transferring data from one side to the other. XSplit users will have to go through the process of creating a custom connection to the local machine so as to make the program send and receive data through TCPRelay instead of connecting directly to the streaming servers. Some would call this a proxy, but it lacks the ability to dynamically choose the target server (which is impossible, given the network protocol used).

So now you are asking: how did this solve the upload bandwidth problem? The answer is something that eludes me and a few XSplit developers alike. Somehow, it works. I like to call it magic. See for yourself:

XSplit bandwidth test without TCPRelay

XSplit bandwidth test without TCPRelay

XSplit bandwidth test with TCPRelay

XSplit bandwidth test with TCPRelay

Amazing, huh? By the way, the game running behind it is StarCraft II: Wings of Liberty.

You can download version 0.1.1 beta (latest as of this writing) here. Also check out the official topic on XSplit's forums and see for yourself all the great feedback people gave me.

Welcome!

Welcome to my blog!

In this blog I will be talking a bit about what I do as a hobby -- gaming and programming. When I'm not hacking through enemies, I'm most certainly hacking through code. I will be talking about my personal projects and giving hints, tips and tutorials about all sorts of programming topics, from basic to advanced. Expect to see a lot of things related to game development here! As for games, I'll probably be showing off my achievements and feats and some news, hints and tips. :)