Using Integers as Boolean Flags


Something I find handy while programming is being able to use the bits in an integer-type variable as boolean flags. What I mean by that is, let’s say you have an INT that is 4 bytes in size. Each byte consists of 8 bits so this INT contains 32 bits in total (4 bytes * 8 bits in a byte). If we have a program that has 32 different boolean variables, wouldn’t it be more effective to store all of them in a single integer variable? This would especially be helpful when you want to keep your networking packets small. 32 booleans in 4 bytes instead of 32 bytes! Ultimately, it’s up to you to decide how to use it; I’m just here to show you how.

Read the rest of this entry »

How to find the systemroot (in C#, C++ and Java)


Naturally, a lot of my search engine traffic comes here from searching for terms like “system root in &ltinsert language here>” or “%systemroot%”. So, to live up to my domain, and you Googler’s expectations, I’ve decided to write a post about how to get the path to the system root in a few languages. If you know more, drop a comment and I’ll add it here.

Read the rest of this entry »

Saving to a Custom Binary File Format with Versioning


While working on Fondusi’s I came up with a great way to store the map data (or any binary data, really) in such a way that previous files could be loaded using new versions of the software. It has some great capabilities and, after answering a question about it on gamedev.StackExchange, I thought it might be helpful to write a post about it here.

Read the rest of this entry »

Fix: Cannot Generate SSPI Context


I was recently working on an ASP.Net project and was receiving this error on attempting to .Open() my SQL Server database connection:
System.Data.SqlClient.SqlException: Cannot generate SSPI context.

As you may have noticed, the connection uses SSPI (i.e. Windows login authentication) to connect to SQL Server. I thought this was a bit strange and tried restarting the project (it was running in debug mode). That didn’t help.

Fortunately, I remembered that my Windows password was set to expire today. It had expired while I was logged in, and so, was preventing me from being able to authenticate my login with SQL Server.

So, if you’re receiving this error, try updating your password if it may have expired.

Fondusi’s Dev Blog – Week 6 – Part 1 – C# Sockets and Servers


This week we spent some time doing little things – fixing bugs, changing how things look, etc. We also started work on the networking code which is what I talk about in this post. I discuss the beginnings of the TCP multi-client server application with actual code examples and descriptions.

Read the rest of this entry »

Fondusi’s Dev Blog – Week 2 – Pixel Shaders and Moving Players


The second week of development was spent reorganizing the map editor and fleshing out more-or-less how we wanted it to look and function. We added a basic pixel shader effect file and changed how players move across tiles, which I discuss in more detail in the full post.

Read the rest of this entry »

XNA – Converting from angle to Vector2 and back


I was recently working on an XNA project and needed to convert from an angle to a Vector2. There are a lot of resources showing how to go one way (angle->Vector2) or the other (Vector2->angle) but not many showing both. So, I figured it might be helpful to put it up here, even if I only use it for reference.

Angle -> Vector2

Now, the reason I make the Y value negative is because that’s how the screen coordinate system works. If you didn’t do this, the angle in radians would go clock-wise instead of counter-clockwise.

Vector2 -> Angle
Read the rest of this entry »

XNA – Check if a click is on the game form/window


One of the annoying things with XNA, happens when handling mouse clicks. If you’ve ever worked on an XNA windows game (note: this only really applies to a windows game) in windowed mode and tried switching applications, you may have noticed that XNA still captures the clicks even when the window is not active! It also reports the mouse position when it’s outside of the window which can cause more issues in and of itself. Unfortunately, the fix for the first problem doesn’t work if you’re using multiple forms in the same application.

So, we have three issues:

  • XNA captures clicks while the game is not active (i.e. from other applications)
  • and it reports the mouse position when it’s outside of the viewable area
  • and the fix for the first item above doesn’t work when you have multiple forms in your application.

Fortunately, there’s an easy way to resolve these! “Great!”, you say, “now how do I do it?”. Click on, my friend.

Read the rest of this entry »

Latest Posts



Post Calendar

November 2014
M T W T F S S
« Sep    
 12
3456789
10111213141516
17181920212223
24252627282930