Sign in to follow this  
  • entries
    32
  • comments
    30
  • views
    10759

Rock On.

Sign in to follow this  
Lacutis

124 views

Ok, so I got it working.

My server waits for connection, and when a connection is achieved it creates a "CComHello" object, and pushes it to the other side.



So I have the script in Torque2d doing this:

$TestObj = new NetObj(testobj);
echo("NetObj = " @ $TestObj);
$TestObj.setVariable(42);
echo("NetObj Var = " @ $TestObj.getVariable());
$TestObj.Receive();




Which creates a new NetObj, calls some test functions that I havent removed and then calls the Recieve method.

Inside the C++ side of the T2d engine, I have this:


bool NetObj::Receive()
{
// receive the data
int bytes = m_Sock.Receive( m_buffer, 1024 );

// tell the protocol policy object about the received data.
Translate(m_buffer, bytes );

return (bytes > 0);
}

void NetObj::Translate(char *p_buffer, int p_size)
{
for( int i = 0; i < p_size; i++ )
{
// if the buffer isn't full, add it to the buffer
char c = p_buffer;
if(m_recbufsize < 1024 )
{
m_recbuffer[m_recbufsize] = c;
m_recbufsize++;
}
if(m_recbufsize >= sizeof(CCommand)/sizeof(char))
{
switch(((CCommand*)m_buffer)->Type)
{
case COM_NONE:
if(m_recbufsize == sizeof(CCommand)/sizeof(char))
{
// printf("Got COM_NONE");
m_recbufsize = 0;
}
break;
case COM_HELLO:
if(m_recbufsize == sizeof(CComHello)/sizeof(char))
{
// Handle((CCommand*)m_buffer);
Con::executef(this, 2, "onHello", "Connected!");
m_recbufsize = 0;
}
case COM_DISPLAY:
if(m_recbufsize == sizeof(CComDisplay)/sizeof(char))
{
// Handle((CCommand*)m_buffer);
Con::executef(this, 2, "onDisplay", ((CComDisplay*)m_recbuffer)->m_Msg);
m_recbufsize = 0;
}
break;
}
}
}
}




Finally, back in torquescript land I defined this callback:

function TestObj::onHello()
{
echo("Connected()!");
}




The net result being:



So wow, some of the parts were harder than I expected, and others were easier, so I guess it evened out in the end.

Now I have a basis I can use to add more entity types, and spawn them from the server. The next step is to read through the torquescript documentation and figure out how to search for spawned entities inside the simulation. That will be needed for allowing the server to control their lcations, etc.

Unfortunately it's sunday, and that means laundry and shopping, which I will need to get started on in an hour or so.
Sign in to follow this  


2 Comments


Recommended Comments

I don't know about fun.

The scripting language is really easy to use. Like I said before the "shooter" demo you can download here is a lot like the tutorial that you get with the engine. You get most of the shooter done in an hour, maybe 2. That kind of power is impressive.

I'm going to work on coding the command derivatives that will allow me to pass entities to spawn the the clients tommorow. If I can get it to spawn a player entity and send commands back to the server when I hit a button to move. I'll be in real good shape.

The really frustrating thing about the engine is that if you don't also have a Torque Game Engine license, you can't access any of the TGE forums. So when you are searching for things using the built in google search it keeps turning up exactly what you need on forums you can't access. That's mainly why it took me most of a day to figure out how to get my new object working properly.

I guess the fun part is trying to bend and flex someone elses engine to be a client for your custom server. That's fun.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now