Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 19 Sep 2007
Offline Last Active Aug 20 2013 06:37 PM

Topics I've Started

Network Interpolation Help

28 February 2013 - 08:52 PM

Does anyone have some good resources with solid example code for writing network code for games? I'm fine with socket code, just the actual syncing and interpolation to make movement/animation between two clients look smooth and proper is really not going well for me. I looked through a few books but most were hundreds of pages long and the stuff I'm interested in is drowned in 400+ pages of instructions for doing things in very old depreciated versions of  directx. I've had no problem setting it up in things like Unity that handle all the fancy interpolation and timing for you, but I find using things like Unity cause me a lot of grief when I want to start doing more complicated things like hosting multiple rooms on the same server.

Any resources you guys know of that could help? To be more specific I mean real time authoritative server/client setups such as is often used for the source engine. The source engine papers are interesting and helpful, but not easy to reproduce for someone's beginner attempts at networked gaming. No help needed at all with transmission of data really, more just making that data sent useful and smooth looking to the client.

ENet packets not sending properly?

02 July 2011 - 03:32 PM

I've decided to give the ENet library ( http://enet.bespin.org/ ) a try for use in a simple game I'm trying to make. Unfortunately I'm having some trouble getting off the ground using it - everything was fine when I was using strings but now I've run into some trouble. I set up a simple packet structure that looks like this (example for the Vector3 packet):

[ packet type - 2 bytes ]
[ variable x - 4 bytes ]
[ variable y - 4 bytes ]
[ variable z - 4 bytes ]
on my console client test I have this code checking the packet ready to be sent, and everything checks out exactly as it should with typ1 and typ2 agreeing that the 2 byte header is 13.

Vector3 testvec;
testvec.type = 13;
testvec.x = 5.5;
testvec.y = 250;
testvec.z = 3.333;

packet = fillPacket( testvec );

uint16 *typ1;
uint16 typ2;
typ1 = (uint16*)(packet->data);
memcpy( &typ2, packet->data, 2);

std::cout << "typ1:" << (*typ1) << "\n";
std::cout << "typ2:" << typ2 << "\n";
enet_packet_destroy( packet );

then on my console test server, this is where everything goes wrong - the packet arrives the exact correct size, and x y and z are perfectly arranged bit-by-bit, but the 2 byte type header appears to be just random memory completely unrelated to what I sent.

	printf ("A packet of length %u was received from %s on channel %u.\n",
			event.packet -> dataLength,
			event.peer -> data,

	uint16 *typ1;
	uint16 typ2;

	typ1 = (uint16*)(event.packet->data);
	memcpy( &typ2, event.packet->data, 2);

	std::cout << "typ1:" << (*typ1) << "\n";
	std::cout << "typ2:" << typ2 << "\n";

I'm not really sure where to go from here - obviously if I can't get the packets to send properly I can't make a full game using this, and I'm not sure what's going wrong. Does anybody with more experience with ENet know what could be causing this? Does it have some kind of cruel hatred for unsigned shorts? Did I just make a dumb mistake like put an ampersand somewhere I shouldn't have?

Irrlicht/(SFML?) problems on vista32

15 January 2009 - 06:20 AM

I'm having a bit of trouble with irrlicht. I'm just using part of the GUI right now, to make a listbox/textbox/button for a simple chat interface. It worked fine until I transferred the code onto my new laptop, which is a 32bit vista. It compiles and runs fine, but when the text is sent it sends, and displays the message in the listbox, but then seconds later I get the popup that says "Chat.exe has stopped working". Here's the code, SFML is worked in for the networking half but I determined even if you comment out the SFML stuff it still happens.
#include <irrlicht.h>
#include "Network.h"

#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

struct SAppContext
	IrrlichtDevice *device;
	IGUIListBox*	listbox;
	IGUIEditBox*	textbox;
	IGUIEditBox*	namebox;
	IGUIWindow*		window;

	stringw			name;

	sf::SocketTCP	Socket;

// Define some values that we'll use to identify individual GUI controls.

void send_text( SAppContext &context );
void CreateNameSelector( SAppContext &context );

void send_text( SAppContext &context )
    //put message together
	stringw message = context.name.c_str();
	message += ": ";
	message += context.textbox->getText();

    //add message to listbox.
	context.listbox->addItem( message.c_str() );

    //convert to normal char, wchar_t* does not work in a console app iostream.
    char* conv_string;
	wchar_t* input = const_cast<wchar_t*> (message.c_str());
    wcstombs( conv_string, input, 800);
	// Send it to the server
	sf::Packet Packet;
	Packet << SEND_CHAT << conv_string;
	(context.Socket.Send(Packet) == sf::Socket::Done);

class MyEventReceiver : public IEventReceiver
	MyEventReceiver(SAppContext & context) : Context(context) { }

	virtual bool OnEvent(const SEvent& event)
		if (event.EventType == EET_GUI_EVENT)
			s32 id = event.GUIEvent.Caller->getID();
			IGUIEnvironment* env = Context.device->getGUIEnvironment();



				if (id == 101)
					send_text( Context );
					return true;

				if (id == 102)
				    Context.name = Context.namebox->getText();

		else if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
		    switch (event.KeyInput.Key)
            case irr::KEY_F2:
                CreateNameSelector( Context );
                return true;

			case irr::KEY_ESCAPE:
				return true;

            case irr::KEY_RETURN:
                send_text( Context );
                return true;

                return true;

		return false;

	SAppContext& Context;

void CreateNameSelector( SAppContext& context )
    context.listbox->addItem(L"Setting Name");

	context.window = context.device->getGUIEnvironment()->addWindow(
        rect<s32>(100, 100, 300, 160),
		L"Display Name:");

	context.namebox = context.device->getGUIEnvironment()->addEditBox(L"", rect<s32>( 10, 30, 140, 50), true, context.window);
	context.device->getGUIEnvironment()->addButton(rect<s32>( 150, 30, 200 - 10, 50), context.window, GUI_ID_SETNAME_BUTTON, L"Set", L"Set's your name");


void SetupGraphics( SAppContext& context )

	context.device->setWindowCaption(L"Irrlicht Engine - User Interface Demo");
	IGUISkin* skin = context.device->getGUIEnvironment()->getSkin();
	IGUIFont* font = context.device->getGUIEnvironment()->getFont("media/fonthaettenschweiler.bmp");
	if (font)

	skin->setFont(context.device->getGUIEnvironment()->getBuiltInFont(), EGDF_TOOLTIP);

	context.device->getGUIEnvironment()->addButton(rect<s32>(700 - 10, 600 - 10 - 20, 800 - 10, 600 - 10), 0, GUI_ID_SEND_BUTTON, L"Send", L"Send Message");
	IGUIListBox * listbox = context.device->getGUIEnvironment()->addListBox(rect<s32>(10, 10, 800 - 10, 600 - 20 - 20));

	context.textbox = context.device->getGUIEnvironment()->addEditBox(L"Editable Text", rect<s32>( 10, 600 - 10 - 20, 700 - 20, 600 - 10));

	context.listbox = listbox;

	context.name = L"Default";

	for (u32 i=0; i<EGDC_COUNT ; ++i)
		SColor col = context.device->getGUIEnvironment()->getSkin()->getColor((EGUI_DEFAULT_COLOR)i);
		context.device->getGUIEnvironment()->getSkin()->setColor((EGUI_DEFAULT_COLOR)i, col);

void SetupNetwork(unsigned short Port, SAppContext& context)
    sf::IPAddress ServerAddress = sf::IPAddress::GetLocalAddress();

    // Connect to the server
    if (!context.Socket.Connect(Port, ServerAddress))
        context.listbox->addItem(L"Failed to connect!");
        context.listbox->addItem(L"Connected Successfully");

int main()
	// create device and exit if creation failed

	IrrlichtDevice * device = createDevice(video::EDT_DIRECT3D9, core::dimension2d<s32>(800, 600), 32, false, false, true);

	if (device == 0)
		return 1; // could not create selected driver.

	// Store the appropriate data in a context structure.
	SAppContext context;
	context.device = device;

	SetupGraphics( context );
	SetupNetwork( 1337, context );

	// Then create the event receiver, giving it that context structure.
	MyEventReceiver receiver(context);

	// And tell the device to use our custom event receiver.

	while(device->run() && device->getVideoDriver())
	if (device->isWindowActive())
		device->getVideoDriver()->beginScene(true, true, SColor(0,200,200,200));



	return 0;
Network.h just has SFML/Network.hpp and the enum that has SEND_CHAT. Does anyone know what could be causing this or how I could fix it? EDIT:Text being entered with just a constant like this:
never causes any problems, so I imagine it would be a problem with the actual variable being entered? Maybe the conversion? I determined if I comment up to right before wcstombs it's fine, but it still doesn't make sense that that crashes it because it still executes past that for the rest of the function and sends it. It's also recieved properly in the other program (console), as the correct string... [Edited by - Elspin on January 15, 2009 1:02:34 PM]

Accessing embedded lua from C++?

21 February 2008 - 07:02 PM

I'm trying to figure out how to do certain things to lua from C++, but I'm having a bit of trouble. Such as creating a table in lua and adding a variable to it, the equivalent to below from C++
t = {}
t[1] = 1
just the basic creation of a table and adding a variable too it. So far, I've only figured out how to do this with the global table, _G. I appreciate any help with this.

Porting applications to other computers?

14 January 2008 - 04:31 PM

I don't really want to get into the specifics of entire other operating systems, but as for porting your applications to other computers of the same operating system, what is the requirement? I remember seeing an article somewhere on how to do this, and recently I tried to use an application I made on a friends computer and it failed. I thought I bookmarked the article, but apparently not. Can anyone tell me what I need to do?