Who wants to explain netcode to me?
Displaying 1-4 of 4 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Time_Wizard

I've been able to maintain at least a tenuous understanding of Verge's functions thus far, but I've found myself totally lost in trying to get netcode to work.

The most I've been able to do thus far is establish a connection, after studying the Vergechat code.

My initial idea was to have it so at the start of each gameloop, you send your mouse input to the other player and their game plays using that input. It wound up looking sort of like this:
    void GamePlayLoop(){ // set to Hooktimer
    if(Turn==ThisComputer){
    MouseX=mouse.x;
    MouseY=mouse.y;
    MouseL=mouse.l;
    MouseR=mouse.r;
    SocketSendInt(Socket,MouseX);
    SocketSendInt(Socket,MouseY);
    SocketSendInt(Socket,MouseL);
    SocketSendInt(Socket,MouseR);
    }else{
    MouseX=SocketGetInt(Socket);
    MouseY=SocketGetInt(Socket);
    MouseL=SocketGetInt(Socket);
    MouseR=SocketGetInt(Socket);
    }
    //game code blahblahblah...


Obviously this did not work. The game would freeze up once your opponent's turn came up. This is in mind, I have a few specific questions and I'd also appreciate some general advice on how to pull this sort of thing off.

- Should you have a different socket for each variable you're sending back and forth, or do you do it all across one socket?

- Should I be sending data on every gameloop? Can the connection keep up with that?

- When you do a SocketSendInt or SocketGetInt will Verge wait to make sure the data has been sent and recieved before proceeding or do you need to set up some sort of while loop that won't go forward until it has the data it needs?

Posted on 2006-03-01 23:19:06

Omni

I don't know much about netcode, but -->

1. You only need one socket: one socket represents a complete connection, one link to a single IP address. As far as I know.

2. A lot of the socket ordering stuff is handled internally, I believe. As for this, I believe there's actually a buffer of some sort that keeps track when you send multiple socket packets at once. Of course I believe only one socket packet can be received at one time, so the others have to either be delayed or queued.

Perhaps you have to set up this queue in your own code; perhaps Verge handles it and all you need to do is send/receive. You'd probably have to study the netcode to find the answer for that, as I've got no clue myself.

Posted on 2006-03-01 23:47:14

Overkill

Time Wizard: You only need one socket per connection to a unique IP. Also, if you don't have anything like SocketHasData(), that's bad. Because, you need to check to see IF there's any data before trying to grab it. Otherwise, it'll crash, and that's bad.

Also! I recommend you send ALL your packets as strings rather than ints, especially if you're planning to use strings anywhere else with netcode.


void GamePlayLoop()
{
// set to Hooktimer
if(Turn == ThisComputer)
{
// Packet: MOUSE x y left_button right_button
MouseX=mouse.x; MouseY=mouse.y; MouseL=mouse.l; MouseR=mouse.r; SocketSendString(Socket, "MOUSE "+str(MouseX)
+ " " + str(MouseY)
+ " " + str(MouseL)
+ " " + str(MouseR)
);
}
else if (SocketHasData(Socket))
{
ParsePacket(SocketGetString(Socket));
}
}

void ParsePacket(string s)
{
string a = GetToken(s, " ", 0);

if (!strcmp(a, "MOUSE"))
{
// Parse a mouse packet.
MouseX = val(GetToken(s, " ", 1));
MouseY = val(GetToken(s, " ", 2));
MouseL = val(GetToken(s, " ", 3));
MouseR = val(GetToken(s, " ", 4));
}
else
{
// Dump any unaccepted input to a log.
Log("Unknown packet:" + s);
}
}

Posted on 2006-03-02 12:29:56

Time_Wizard

It works! YAY! Overkill, I owe you a cookie. And I don't mean any old cookie, I'm talking about a delicious warm moist cookie with melty chocolate chips and such.

I may be able to release my first demo soon!

Posted on 2006-03-05 23:22:34


Displaying 1-4 of 4 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.