Can't understand why the code is not working
by DIAG · in Torque Game Engine · 02/22/2007 (7:47 am) · 8 replies
I'm using torque as part of an assignment in College but I am a bad coder. I am trying to change the packet generation code in netConnection.cc so that it mimics a dead Reckoning traffic model that I have designed but I am having a luittle problem.
snippet of code
void NetConnection::checkPacketSend(bool force)
{
U32 curTime = Platform::getVirtualMilliseconds();
U32 delay = isServerConnection() ? gPacketUpdateDelayToServer : mCurRate.updateDelay;
//DM ADDED THIS HERE
if (isServerConnection() && packetGen == NULL )
{
Con::executef(this, 1, "getPacketGenerator");
}
if(!force)
{
if(curTime < mLastUpdateTime + delay - mSendDelayCredit)
return;
mSendDelayCredit = curTime - (mLastUpdateTime + delay - mSendDelayCredit);
if(mSendDelayCredit > 1000)
mSendDelayCredit = 1000;
if(mDemoWriteStream)
recordBlock(BlockTypeSendPacket, 0, 0);
}
if(windowFull())
return;
BitStream *stream = BitStream::getPacketStream(mCurRate.packetSize);
buildSendPacketHeader(stream);
mLastUpdateTime = curTime;
PacketNotify *note = allocNotify();
if(!mNotifyQueueHead)
mNotifyQueueHead = note;
else
mNotifyQueueTail->nextPacket = note;
mNotifyQueueTail = note;
note->nextPacket = NULL;
note->sendTime = curTime;
note->rateChanged = mCurRate.changed;
note->maxRateChanged = mMaxRate.changed;
if(stream->writeFlag(mCurRate.changed))
{
stream->writeInt(mCurRate.updateDelay, 10);
stream->writeInt(mCurRate.packetSize, 10);
mCurRate.changed = false;
}
if(stream->writeFlag(mMaxRate.changed))
{
stream->writeInt(mMaxRate.updateDelay, 10);
stream->writeInt(mMaxRate.packetSize, 10);
mMaxRate.changed = false;
}
U32 start = stream->getCurPos();
DEBUG_LOG(("PKLOG %d START", getId()) );
writePacket(stream, note);
DEBUG_LOG(("PKLOG %d END - %d", getId(), stream->getCurPos() - start) );
if(mSimulatedPacketLoss && Platform::getRandom() < mSimulatedPacketLoss)
{
//Con::printf("NET %d: SENDDROP - %d", getId(), mLastSendSeq);
stream->setBuffer(stream->getBuffer(), stream->getPosition(), stream->getPosition());
//
mRemoteConnection->processRawPacket(stream);
return;
}
mSimulatedPing = false;
if(torqueRaceFlag == 1 && packetSendingFlag == 0)
{
mSimulatedPing = generateNextIntervalRacing();
}
if(torqueFPSFlag == 1 && packetSendingFlag == 0)
{
mSimulatedPing = generateNextIntervalFPS();
}
if (isServerConnection())
Con::printf("%i %i %f %i", mSimulatedPing, torqueFPSFlag, DR, packetSendingFlag);
if(mSimulatedPing && packetSendingFlag == 0)
{
Con::printf("Sending DR packet.. with delay of %i", mSimulatedPing);
Sim::postEvent(getId(), new NetDelayEvent(stream), Sim::getCurrentTime() + mSimulatedPing);
packetSendingFlag = 1;
return;
}
else if(packetSendingFlag == 1)
{
Con::printf("***************Waiting for packet to send*****************");
Con::printf("***************isServerConnection is %i*******************", isServerConnection());
}
else
{
//Con::printf("Third else statement");
if(torqueFPSFlag != 1 || !torqueRaceFlag != 1)
{
Con::printf("%i %i %f %i", mSimulatedPing, torqueFPSFlag, DR, packetSendingFlag);
Con::printf("Normal packet has been sent....");
Con::printf("isServerConnection: %i", isServerConnection());
sendPacket(stream);
}
}
}
snippet of code
void NetConnection::checkPacketSend(bool force)
{
U32 curTime = Platform::getVirtualMilliseconds();
U32 delay = isServerConnection() ? gPacketUpdateDelayToServer : mCurRate.updateDelay;
//DM ADDED THIS HERE
if (isServerConnection() && packetGen == NULL )
{
Con::executef(this, 1, "getPacketGenerator");
}
if(!force)
{
if(curTime < mLastUpdateTime + delay - mSendDelayCredit)
return;
mSendDelayCredit = curTime - (mLastUpdateTime + delay - mSendDelayCredit);
if(mSendDelayCredit > 1000)
mSendDelayCredit = 1000;
if(mDemoWriteStream)
recordBlock(BlockTypeSendPacket, 0, 0);
}
if(windowFull())
return;
BitStream *stream = BitStream::getPacketStream(mCurRate.packetSize);
buildSendPacketHeader(stream);
mLastUpdateTime = curTime;
PacketNotify *note = allocNotify();
if(!mNotifyQueueHead)
mNotifyQueueHead = note;
else
mNotifyQueueTail->nextPacket = note;
mNotifyQueueTail = note;
note->nextPacket = NULL;
note->sendTime = curTime;
note->rateChanged = mCurRate.changed;
note->maxRateChanged = mMaxRate.changed;
if(stream->writeFlag(mCurRate.changed))
{
stream->writeInt(mCurRate.updateDelay, 10);
stream->writeInt(mCurRate.packetSize, 10);
mCurRate.changed = false;
}
if(stream->writeFlag(mMaxRate.changed))
{
stream->writeInt(mMaxRate.updateDelay, 10);
stream->writeInt(mMaxRate.packetSize, 10);
mMaxRate.changed = false;
}
U32 start = stream->getCurPos();
DEBUG_LOG(("PKLOG %d START", getId()) );
writePacket(stream, note);
DEBUG_LOG(("PKLOG %d END - %d", getId(), stream->getCurPos() - start) );
if(mSimulatedPacketLoss && Platform::getRandom() < mSimulatedPacketLoss)
{
//Con::printf("NET %d: SENDDROP - %d", getId(), mLastSendSeq);
stream->setBuffer(stream->getBuffer(), stream->getPosition(), stream->getPosition());
//
mRemoteConnection->processRawPacket(stream);
return;
}
mSimulatedPing = false;
if(torqueRaceFlag == 1 && packetSendingFlag == 0)
{
mSimulatedPing = generateNextIntervalRacing();
}
if(torqueFPSFlag == 1 && packetSendingFlag == 0)
{
mSimulatedPing = generateNextIntervalFPS();
}
if (isServerConnection())
Con::printf("%i %i %f %i", mSimulatedPing, torqueFPSFlag, DR, packetSendingFlag);
if(mSimulatedPing && packetSendingFlag == 0)
{
Con::printf("Sending DR packet.. with delay of %i", mSimulatedPing);
Sim::postEvent(getId(), new NetDelayEvent(stream), Sim::getCurrentTime() + mSimulatedPing);
packetSendingFlag = 1;
return;
}
else if(packetSendingFlag == 1)
{
Con::printf("***************Waiting for packet to send*****************");
Con::printf("***************isServerConnection is %i*******************", isServerConnection());
}
else
{
//Con::printf("Third else statement");
if(torqueFPSFlag != 1 || !torqueRaceFlag != 1)
{
Con::printf("%i %i %f %i", mSimulatedPing, torqueFPSFlag, DR, packetSendingFlag);
Con::printf("Normal packet has been sent....");
Con::printf("isServerConnection: %i", isServerConnection());
sendPacket(stream);
}
}
}
#2
The troqueFPSFlag and DeadReckonin_ threshold are set by Console methods. They seem to be working fine.
The torqueFPSFlag is not changed anywhere else in the code except for the console method. The problem is that it seems to be changing on me and then the else statement is running.
I have a sample from the console log here.
0 1 1.000000 1
***************Waiting for packet to send*****************
***************isServerConnection is 1*******************
0 -825307442 -1734829824.000000 0
Normal packet has been sent....
isServerConnection: 0
0 -825307442 -1734829824.000000 0
Normal packet has been sent....
isServerConnection: 0
As you can see here the torqueFPSFlag is being changed from 1 to -825307442 when isServerConnection() returns a 0. I do not why and I was wondering cpudl anyone tell me why it is changing
02/22/2007 (7:54 am)
Sorry I'm a slow typer...The troqueFPSFlag and DeadReckonin_ threshold are set by Console methods. They seem to be working fine.
The torqueFPSFlag is not changed anywhere else in the code except for the console method. The problem is that it seems to be changing on me and then the else statement is running.
I have a sample from the console log here.
0 1 1.000000 1
***************Waiting for packet to send*****************
***************isServerConnection is 1*******************
0 -825307442 -1734829824.000000 0
Normal packet has been sent....
isServerConnection: 0
0 -825307442 -1734829824.000000 0
Normal packet has been sent....
isServerConnection: 0
As you can see here the torqueFPSFlag is being changed from 1 to -825307442 when isServerConnection() returns a 0. I do not why and I was wondering cpudl anyone tell me why it is changing
#3
Your posted code only shows us torqueFPSFlag being checked against 1, can you show where it's being declared, changed, and transmitted?
02/22/2007 (8:04 am)
Can you post any engine and script code that directly touches torqueFPSFlag, let's see how it's being read and manipulated....Your posted code only shows us torqueFPSFlag being checked against 1, can you show where it's being declared, changed, and transmitted?
#4
{
torqueFPSFlag = val_in;
Con::printf("torqueFPSFlag is %i", torqueFPSFlag);
}
ConsoleMethod(NetConnection, setFPSFlag, S32, 3, 3, "( S32 errorThreshold ) Convert a ghost id from this connection to a real id.")
{
S32 gID = dAtoi(argv[2]);
object->setFPSFlag(gID);
return 0;
}
NetConnection.h
void NetConnection::setFPSFlag(int val_in);
int torqueFPSFlag;
02/22/2007 (8:08 am)
Void NetConnection::setFPSFlag(int val_in){
torqueFPSFlag = val_in;
Con::printf("torqueFPSFlag is %i", torqueFPSFlag);
}
ConsoleMethod(NetConnection, setFPSFlag, S32, 3, 3, "( S32 errorThreshold ) Convert a ghost id from this connection to a real id.")
{
S32 gID = dAtoi(argv[2]);
object->setFPSFlag(gID);
return 0;
}
NetConnection.h
void NetConnection::setFPSFlag(int val_in);
int torqueFPSFlag;
#5
02/22/2007 (8:08 am)
THE TORQUE FLAG IS NOT USED IN ANY OTHER FUNCTIONS...
#6
Also, you still haven't shown where you call the ConsoleMethod in script yet.
I'd echo the value before you call the ConsoleMethod, then echo it once you jump into your ConsoleMethod, and put break points at object->setFPSFlag(gID), and on torqueFPSFlag = val_in;
02/22/2007 (8:20 am)
My best suggestion is to a step by step debug process, using both script debugging (Torsion) and engine debugging using VS.Also, you still haven't shown where you call the ConsoleMethod in script yet.
I'd echo the value before you call the ConsoleMethod, then echo it once you jump into your ConsoleMethod, and put break points at object->setFPSFlag(gID), and on torqueFPSFlag = val_in;
#7
02/22/2007 (8:24 am)
Usually when you get numbers like -825307442 it means the variable has not been initialized and nothing has been assigned to it yet. Are you initializing it to 0 in the constructor?
#8
void NetConnection::setFPSFlag(int val_in)
{
Con::printf("torqueFPSFlag is %i", torqueFPSFlag);
torqueFPSFlag = val_in;
Con::printf("torqueFPSFlag is %i", torqueFPSFlag);
}
and I called it in the console as below and got the following output
serverConnection.setFPSFlag(1);
==>serverConnection.setFPSFlag(1);
torqueFPSFlag is -825307442
torqueFPSFlag is 1
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
218 1 3.450000 0
Sending DR packet.. with delay of 218
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
In anyways, I'll have a go at debugging it like you said. Cheers for your help, appreciate it.
02/22/2007 (8:32 am)
I changed the function for setting the Torque flag tovoid NetConnection::setFPSFlag(int val_in)
{
Con::printf("torqueFPSFlag is %i", torqueFPSFlag);
torqueFPSFlag = val_in;
Con::printf("torqueFPSFlag is %i", torqueFPSFlag);
}
and I called it in the console as below and got the following output
serverConnection.setFPSFlag(1);
==>serverConnection.setFPSFlag(1);
torqueFPSFlag is -825307442
torqueFPSFlag is 1
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
218 1 3.450000 0
Sending DR packet.. with delay of 218
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
0 -825307442 -1734829824.000000 0
In anyways, I'll have a go at debugging it like you said. Cheers for your help, appreciate it.
Employee Michael Perry
ZombieShortbus
Is there a compiler error? Does nothing happen? Does something happen but not what you expected?