Posts Tagged Game Programming

Internet Multiplayer Issues With August 2011 UDK Builds [Solved]

Quite a few people have noted that they are having multiplayer issues with recent UDK builds. They can connect to a server just fine over a LAN, but whenever they connect to a server hosted on the internet they get dropped. Since so many people are having this issue I decided to post a new thread instead of just posting my solution 7 pages deep in another one.

The output is similar to the following:

Client Log

[0058.77] DevNet: Browse: /TT-T_Sandbox1?Name=Player?Team=255
[0058.77] Init: WinSock: Socket queue 32768 / 32768
[0058.77] DevNet: Game client on port 7777, rate 10000
[0059.67] DevNet: Welcomed by server (Level: TT-T_Sandbox1, Game: Titan.TitanGame)
[0059.79] NetComeGo: Close TcpNetDriver_0 TcpipConnection_0 :7777 09/18/11 20:55:44
[0059.80] Log: Pending connect to '/TT-T_Sandbox1?Name=Player?Team=255?game=Titan.TitanGame' failed; Your connection to the host has been lost.
[0059.80] ScriptLog: (UTGameViewportClient_0) UTGameViewportClient::None:NotifyConnectionError Message:'Your connection to the host has been lost.' Title:'Connection Lost'
[0059.82] DevNet: URL: Adding default option Name=Player
[0059.82] DevNet: URL: Adding default option Team=255
[0059.82] DevNet: Browse: TT-T_Sandbox1?closed?Name=Player?Team=255
[0059.82] Log: Failed; returning to Entry
[0060.10] Log: LoadMap: TT-T_Sandbox1?closed?Name=Player?Team=255

Server Log

DevNet: NotifyAcceptingConnection: Server TheWorld accept
NetComeGo: Open TheWorld 09/18/11 22:24:04
DevNet: NotifyAcceptingChannel Control 0 server World TT-T_Sandbox1.TheWorld: Accepted
DevNet: Remote platform is 1
NetComeGo: Close TcpNetDriver_0 TcpipConnection_4 :59619 09/18/11 22:24:04
DevNet: NotifyAcceptingConnection: Server TheWorld accept
NetComeGo: Open TheWorld 09/18/11 22:24:04
NetComeGo: Close TcpNetDriver_0 TcpipConnection_5 :59619 09/18/11 22:24:04
DevNet: NotifyAcceptingConnection: Server TheWorld accept
NetComeGo: Open TheWorld 09/18/11 22:24:04

I noticed that this problem vanished when I tested with a teammate after cooking and packaging, and I believe I know why. After cooking and packaging a file appeared in my UDK//Binaries folder called UnSetup.Game.xml. This XML file contains two fields, GameUniqueID and MachineUniqueID. I noticed this file also was packaged with my installer. I decided to copy that file from package-created installation folder and place it in my development Binaries folder that is under source control which ensured all teammates had the identical file.

This seems to have solved the problem. My assumption is that the engine cares about the GameUniqueID when an internet multiplayer session is started, but it seems to ignore it for LAN games.

So to recap, if you are having this issue, please try the following.

  1. Using Unreal Frontend, fully recompile all scripts
  2. Cook all game packages
  3. Package your game into a UDK installer
  4. Install the game from that installer, and look in the Binaries folder in that new directory for UnSetup.Game.xml
  5. Copy that xml file back into the Binaries folder in your UDK development folder
  6. Ensure all teammates have an identical file

Best of luck to you!

,

2 Comments

C++ Vector2D & Rectangle classes

I’n my current C++ class we’ve been playing with the Allegro C++ library to create some 2D games.  While Allegro is a fairly powerful library, it’s shortcomings made me miss the Microsoft XNA Framework quite a bit.  I suppose I cannot fault Allegro in this regard, but I have grown so accustomed to using Microsoft’s implementation of 2D vectors and rectangles that learning new variants seems convoluted.

Now, before anyone judges me for not wanting to learn a new API, consider this.  Allegro has a plethora of 2D methods, but the only vector methods I am able to find are 3D.  Fine you say, just zero the Z element and be done with it.

Well sure.  But would I rather use a non OOP implementation like this:

float x = <someXValue>;
float y = <someYValue>;
float z = 0.0f;
void normalize_vector_f(float *x, float *y, float *z);

Or would I rather take an OOP approach:

Vector2D vec( <someXValue>, <someYValue> );
vec.Normalize();

Call me crazy, but I prefer the later.  As such, I’m going to go ahead and post my Vector2D class here, as well as the Rectangle class I am using.  Normally I would cite sources I used for help in writing these classes.   However, in the case of the Vector2D class most of the methods used are fairly standard and there is nothing really out of the ordinary.

As for the Rectangle class, there are some cool static methods I added that Microsoft released in their RectangleExtensions class (released under the MSPL).  I ported these methods over from C# to C++,and they seem to work correctly, however I haven’t tested them thoroughly and they may have a bug or two.

Anyway, enough ranting.  Here’s the code.

Vector2D.h

#ifndef _VECTOR2D_H
#define _VECTOR2D_H
#pragma once

#include <math.h>

class Vector2D
{

public:
	Vector2D(float x = 0, float y = 0);
	~Vector2D() {};

	void Rotate( const float angle );
	float Magnitude() const;
	float Normalize();
	float DotProduct( const Vector2D& v2 ) const;
	float CrossProduct( const Vector2D& v2 ) const;

	static Vector2D Zero();
	static float Distance( const Vector2D& v1, const Vector2D& v2);

	Vector2D& operator= ( const Vector2D& v2 );

	Vector2D& operator+= ( const Vector2D& v2 );
	Vector2D& operator-= ( const Vector2D& v2 );
	Vector2D& operator*= ( const float scalar);
	Vector2D& operator/= ( const float scalar);

	const Vector2D operator+( const Vector2D &v2 ) const;
	const Vector2D operator-( const Vector2D &v2 ) const;
	const Vector2D operator*( const float scalar ) const;
	const Vector2D operator/( const float scalar ) const;

	bool operator== ( const Vector2D& v2 ) const;
	bool operator!= ( const Vector2D& v2 ) const;

public:
	float x, y;
};
#endif

Vector2D.cpp

#include "Vector2D.h"

//-----------------------------------------------------------------------------
// Purpose:	Constructor
//-----------------------------------------------------------------------------
Vector2D::Vector2D( float x, float y )
{
	this->x = x;
	this->y = y;
}

//-----------------------------------------------------------------------------
// Purpose:	Rotate a vector
//-----------------------------------------------------------------------------
void Vector2D::Rotate( const float angle )
{
	float xt = (x * cosf(angle)) - (y * sinf(angle));
	float yt = (y * cosf(angle)) + (x * sinf(angle));
	x = xt;
	y = yt;
}

//-----------------------------------------------------------------------------
// Purpose:	Get vector magnitude
//-----------------------------------------------------------------------------
float Vector2D::Magnitude() const
{
	return sqrtf(x * x + y * y);
}

//-----------------------------------------------------------------------------
// Purpose:	Convert vector to a unit vector and return previous magnitude
//-----------------------------------------------------------------------------
float Vector2D::Normalize()
{
	float mag = Magnitude();

	if(mag != 0.0)
	{
		x /= mag;
		y /= mag;
	}

	return mag;
}

//-----------------------------------------------------------------------------
// Purpose:	Dot Product
//-----------------------------------------------------------------------------
float Vector2D::DotProduct( const Vector2D &v2 ) const
{
	return (x * v2.x) + (y * v2.y);
}

//-----------------------------------------------------------------------------
// Purpose:	Cross Product
//-----------------------------------------------------------------------------
float Vector2D::CrossProduct( const Vector2D &v2 ) const
{
	return (x * v2.y) - (y * v2.x);
}

//-----------------------------------------------------------------------------
// Purpose:	Return an empty vector
//-----------------------------------------------------------------------------
Vector2D Vector2D::Zero()
{
	return Vector2D(0, 0);
}

//-----------------------------------------------------------------------------
// Purpose:	Get distance between two vectors
//-----------------------------------------------------------------------------
float Vector2D::Distance( const Vector2D& v1, const Vector2D& v2)
{
	return sqrtf( pow((v2.x - v1.x), 2 ) + pow((v2.y - v1.y), 2) );
}

Vector2D& Vector2D::operator= ( const Vector2D& v2 )
{
	if (this == &v2)
		return *this;

	x = v2.x;
	y = v2.y;

	return *this;
}

Vector2D& Vector2D::operator+= ( const Vector2D& v2 )
{
	x += v2.x;
	y += v2.y;

	return *this;
}

Vector2D& Vector2D::operator-= ( const Vector2D& v2 )
{
	x -= v2.x;
	y -= v2.y;

	return *this;
}

Vector2D& Vector2D::operator*= ( const float scalar )
{
	x *= scalar;
	y *= scalar;

	return *this;
}

Vector2D& Vector2D::operator/= ( const float scalar )
{
	x /= scalar;
	y /= scalar;

	return *this;
}

const Vector2D Vector2D::operator+( const Vector2D &v2 ) const
{
	return Vector2D(*this) += v2;
}

const Vector2D Vector2D::operator-( const Vector2D &v2 ) const
{
	return Vector2D(*this) -= v2;
}

const Vector2D Vector2D::operator*( const float scalar ) const
{
	return Vector2D(*this) *= scalar;
}

const Vector2D Vector2D::operator/( const float scalar ) const
{
	return Vector2D(*this) /= scalar;
}

bool Vector2D::operator== ( const Vector2D& v2 ) const
{
	return ((x == v2.x) && (y == v2.y));
}

bool Vector2D::operator!= ( const Vector2D& v2 ) const
{
	return !((x == v2.x) && (y == v2.y));
}

Rectangle.h

#ifndef _RECTANGLE_H
#define _RECTANGLE_H
#pragma once

#include "Vector2D.h"

class Rectangle
{
public:
	Rectangle( int x = 0, int y = 0, int w = 0, int h = 0 );
	~Rectangle( void ) {};

	inline int Left( void ) const { return x; }
	inline int Right( void ) const { return x + w; }
	inline int Top( void ) const { return y; }
	inline int Bottom( void ) const { return y + h; }

	bool Contains( Vector2D& vVec ) const;
	bool Contains( int x, int y ) const;

	static Rectangle Empty();

	// Static methods below are derived from the RectangleExtensions class
	// written in C#, released under the MSPL
	static Vector2D GetIntersectionDepth( const Rectangle& rectA, const Rectangle& rectB );
	static Vector2D GetBottomCenter( const Rectangle& rect );
	static Vector2D GetCenter( const Rectangle& rect );
	static float GetDistance( const Rectangle& rectA, const Rectangle& rectB);
	static Vector2D GetDirection( const Rectangle& rectA, const Rectangle& rectB);

	Rectangle& operator= ( const Rectangle& r2 );

	bool operator== ( const Rectangle& r2 ) const;
	bool operator!= ( const Rectangle& r2 ) const;

public:
	int x, y, w, h;
};

#endif

Rectangle.cpp

#include "Rectangle.h"
#include <stdlib.h>

//-----------------------------------------------------------------------------
// Purpose:	Constructor
//-----------------------------------------------------------------------------
Rectangle::Rectangle( int x, int y, int w, int h )
{
	this->x = x;
	this->y = y;
	this->w = w;
	this->h = h;
}

//-----------------------------------------------------------------------------
// Purpose:	Check if rectangle contains a 2D vector
//-----------------------------------------------------------------------------
bool Rectangle::Contains( Vector2D& vVec ) const
{
	if ( ( vVec.x >= x )&&
		 ( vVec.x <= x + w ) &&
		 ( vVec.y >= y ) &&
		 ( vVec.x <= y + h ) )
	{
		return true;
	}
	else
		return false;
}

//-----------------------------------------------------------------------------
// Purpose:	Check if rectangle contains a set of coords
//-----------------------------------------------------------------------------
bool Rectangle::Contains( int x, int y ) const
{
	if ( ( x >= this->x )&&
		( x <= this->x + this->w ) &&
		( y >= this->y ) &&
		( x <= this->y + this->h ) )
	{
		return true;
	}
	else
		return false;
}

//-----------------------------------------------------------------------------
// Purpose:	Return an empty rectangle
//-----------------------------------------------------------------------------
Rectangle Rectangle::Empty()
{
	return Rectangle();
}

//-----------------------------------------------------------------------------
// Purpose:	Get intersection depth between two rectangles
//-----------------------------------------------------------------------------
Vector2D Rectangle::GetIntersectionDepth( const Rectangle& rectA, const Rectangle& rectB )
{
	// Calculate half sizes.
	float halfWidthA = rectA.w / 2.0f;
	float halfHeightA = rectA.h / 2.0f;
	float halfWidthB = rectB.w / 2.0f;
	float halfHeightB = rectB.h / 2.0f;

	// Calculate centers.
	Vector2D centerA(rectA.x + halfWidthA, rectA.y + halfHeightA);
	Vector2D centerB(rectB.x + halfWidthB, rectB.y + halfHeightB);

	// Calculate current and minimum-non-intersecting distances between centers.
	float distanceX = centerA.x - centerB.x;
	float distanceY = centerA.y - centerB.y;
	float minDistanceX = halfWidthA + halfWidthB;
	float minDistanceY = halfHeightA + halfHeightB;

	// If we are not intersecting at all, return (0, 0).
	if ( abs(distanceX) >= minDistanceX || abs(distanceY) >= minDistanceY )
		return Vector2D::Zero();

	// Calculate and return intersection depths.
	float depthX = distanceX > 0 ? minDistanceX - distanceX : -minDistanceX - distanceX;
	float depthY = distanceY > 0 ? minDistanceY - distanceY : -minDistanceY - distanceY;
	return Vector2D(depthX, depthY);
}

//-----------------------------------------------------------------------------
// Purpose:	Gets the position of the center of the bottom edge of the rectangle.
//-----------------------------------------------------------------------------
Vector2D Rectangle::GetBottomCenter(const Rectangle& rect)
{
	return Vector2D( (float)(rect.x + rect.w / 2.0f), (float)(rect.y + rect.h) );
}

//-----------------------------------------------------------------------------
// Purpose:	Gets the position of the center point of a rectangle
//-----------------------------------------------------------------------------
Vector2D Rectangle::GetCenter(const Rectangle& rect)
{
	return Vector2D( (float)(rect.x + rect.w / 2.0f), (float)(rect.y + rect.h / 2.0f) );
}

//-----------------------------------------------------------------------------
// Purpose:	Gets the floating point distance between the center point
//			of one rectangle and the center point of another.
//-----------------------------------------------------------------------------
float Rectangle::GetDistance( const Rectangle& rectA, const Rectangle& rectB )
{
	return Vector2D::Distance(GetCenter(rectA), GetCenter(rectB));
}

//-----------------------------------------------------------------------------
// Purpose:	Gets the unit vector from one rectangle to another
//-----------------------------------------------------------------------------
Vector2D Rectangle::GetDirection( const Rectangle& rectA, const Rectangle& rectB )
{
	Vector2D direction = GetCenter(rectA) - GetCenter(rectB);
	direction.Normalize();
	return direction;
}

Rectangle& Rectangle::operator= ( const Rectangle& r2 )
{
	if (this == &r2)
		return *this;

	x = r2.x;
	y = r2.y;
	w = r2.w;
	h = r2.h;

	return *this;
}

bool Rectangle::operator== ( const Rectangle& r2 ) const
{
	return ((w == r2.w) && (h == r2.h));
}

bool Rectangle::operator!= ( const Rectangle& r2 ) const
{
	return !((w == r2.w) && (h == r2.h));
}

,

8 Comments

Project Daedalus Update 4/10

It’s been some time since my last progress update, and I have sort of fallen out of the groove.  As such, this is going to be a short post to sort of get back into the swing of things.

I spent a good while last night working out a good solution to adding rotating gear platforms into the Boilerworks.  The initial idea was simple.  I was going to simply convert the gear texture into a set of vertices and load them up as a collision volume.  However, I realized this solution was not going to be viable as I have been using SAT collision, and a single gear polygon would have been a concave polygon (not supported by SAT implementation).  I decided to try Distance Grid collision instead of SAT, but the difference was noticeable and caused some big headaches.

It doesn’t look like the good folks at Farseer will be implementing concave polygon decomposition until Farseer 3.0 is released, so I had to take an alternate route.

The end result was simply generating multiple convex geometries programmatically that matched mt gear texture.  This ended up working perfectly, and as such we now have some really nice gear platforms ready to be added to levels.  A screenshot of the testbed is below.

Hopefully I’ll start updating this a bit more often as development continues.

, ,

No Comments

Upcoming level editor updates

After switching gears and looking at my editor from an RPG standpoint instead of a sidescrolling standpoint, I’ve noticed a few shortcomings in my editor and engine design.

As such, a few changes are planned.

  1. Shadow mapping.  I have a few different ideas on to how create shadows with a decent degree of alpha transparency.  More than likely I will go with a separate B&W image that stores that shadow textures and have the engine draw them as needed with alpha transparency.
  2. Layers, layers, LAYERS.  Three layers, simply, is not enough.  As such, I’m going to transition from the current 3 layer system to an unlimited layer system.
  3. Zooming.  RPG maps are going to be somewhat large.  I think zooming in and out of the editor will be a very helpful addition.
  4. Advanced entity spawning system.  I’m on the fence with this one.  I may or may not implement this in the editor.  Part of me thinks creating an NPC editor would be smarter.  We’ll see how this pans out though.

That is all for now.

, ,

No Comments

Tile Based Level Editor Progress

Well it’s about time isn’t it?  I finally got around to writing this blog post regarding my tile editor.  I recently joined a team to produce an RPG in C# using XNA Studio 3.1, so I figured now would be a good time to put some more work into the tile engine / editor and showcase what is working so far.

As it stands, the editor is pretty robust.  Currently it supports three tile layers, a rear, mid, and foreground layer.  The rear layer is self explanatory.  The mid layer renders over the rear layer to add details, and the foreground layer renders over NPCs, the player, particles, etc (as long as your engine supports it).  The foreground layer is currently tinted yellow so it can be distinguished.

Tiles can be drawn in as single tiles and regions.  You can also choose to fill an entire layer with a single tile if you so choose.

The editor supports multiple collision types such as impassible, platform, slopes, etc.  These are basically just flags that your engine needs to interpret correctly.

The editor also supports spawn points.  Any entity your engine supports can be dumped into a plain text file and the editor will parse it.  The spawn points can be added dynamically to the map.

It also supports a portal layer which allows for areas of the map to be flagged as a portal.  This allows for your engine to do a check against those regions and load a new map as needed.

We also support terrain effects which are regions of the map that will be processed with some sort of effect.  My demo shows this being used with a simple water shader I wrote.

You can set the background color of the map to any of the predefined .NET colors, as well as a custom color using the color wheel.  You can resize the map dynamically as well as specify the tile size to match your tile set.

The next iteration of this editor will support more layers, likely unlimited using just a list of layers.  In addition I plan to implement a sort of multilayer occlusion so that the foreground layer is more or less dynamic.  Different layers will occlude other layers, so on and so forth.  This is not really needed for a platformer, but will be pretty useful in RPG world building.

Videos:

(My apologies as the audio goes out of sync near the end of part 1 and into part 2, blame Camstudio.)

, ,

No Comments

Level Editor Progress

I’ve been hard at work on the level editor for my game engine and I figured I’d get something up here showing current progress. It is currently near completion actually. It allows for editing of 3 tile layers, background, midground, and foreground. It also allows for world hazards, spawn points, portals, and multiple collision types. The editor renders using the XNA framework within a normal WinForms application. Output is serialized using the XNA intermediate serializer into an XML file that can be directly loaded into the game itself.

Basically, pretty sweet.

Here is a screenshot for the time being.

Level Editor Alpha

Level Editor Alpha

, ,

No Comments

Added Flamethrower to Sidescroller

I know I said the last update would be the last before new assets and a level, but I just finished the flamethrower weapon and it turned out really well. I figured I’d share it. Enjoy!

, ,

3 Comments

Final Sidescroller Pre-Alpha

This will be the final pre-alpha entry. Sound is up and running now, collision has been improved but is still a little wonky at times. Particle bugs are worked out, and hit detection is much better. Enjoy.

, ,

1 Comment

2D Sidescroller Development Continues…

Things are coming together very well. Rudimentary AI routines are implemented, which will serve as the framework for upcoming NPC enemies. A few particle effects are working, as well as world hazards, and a parallax scrolling background.

I hope to have a few enemies functional in the next few days, but this is dependent on time.

, ,

No Comments

More 2D Sidescroller Progress…

The milestones mentioned in my last post where met over the weekend. World collision is now fully functional as well as a fairly decent camera follow that clamps to the world boundaries. Within the next few days I plan to implement basic enemy AI as well as a functional combat system. Soon enough I will be looking to replace these temporary art assets with new, unique art. Unfortunately sprite and tile creation is not my strong point, so if you would like to offer your assistance or know of anyone who would like to help, please comment here and let me know.

Additionally, here is a short video documenting current progress.

, ,

2 Comments