Click here to Skip to main content
15,890,512 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: calling a function two ways Pin
Jay0328-Aug-06 5:46
Jay0328-Aug-06 5:46 
AnswerRe: calling a function two ways Pin
Zac Howland28-Aug-06 5:34
Zac Howland28-Aug-06 5:34 
GeneralRe: calling a function two ways Pin
Jay0328-Aug-06 5:43
Jay0328-Aug-06 5:43 
GeneralRe: calling a function two ways Pin
Jay0328-Aug-06 5:47
Jay0328-Aug-06 5:47 
GeneralRe: calling a function two ways Pin
Zac Howland28-Aug-06 5:53
Zac Howland28-Aug-06 5:53 
GeneralRe: calling a function two ways Pin
Jay0328-Aug-06 5:56
Jay0328-Aug-06 5:56 
GeneralRe: calling a function two ways Pin
David Crow28-Aug-06 6:08
David Crow28-Aug-06 6:08 
GeneralRe: calling a function two ways Pin
Jay0328-Aug-06 6:38
Jay0328-Aug-06 6:38 
RTI::AttributeHandleValuePairSet* Ball::createNVPSet()
{
RTI::AttributeHandleValuePairSet* pBallAttributes = NULL;

//! Make sure the RTI Ambassador is set.
if ( ms_rtiAmb ) // if ms_rtiAmb!=NULL 
{
pBallAttributes = RTI::AttributeSetFactory::create( 4 );

pBallAttributes->add( Ball::ms_ballLocationXId,
(char*)&this->m_currentState.x,
sizeof(double) );
pBallAttributes->add( Ball::ms_ballLocationYId,
(char*)&this->m_currentState.y,
sizeof(double) );
pBallAttributes->add( Ball::ms_ballVelocityXId,
(char*)&this->m_currentState.vx,
sizeof(double) );
pBallAttributes->add( Ball::ms_ballVelocityYId,
(char*)&this->m_currentState.vy,
sizeof(double) );
}

//! pClockAttributes is allocated on the heap and must be
//! deallocated by the calling function
return pBallAttributes;
}


void Ball::sendUpdate()
{
if ( m_nextStateCalculated == RTI::RTI_TRUE )
{
m_currentState = m_nextState;
m_nextStateCalculated = RTI::RTI_FALSE;

try
{
/*!
* In order to send the values of our attributes, we must
* construct an AttributeHandleValuePairSet (AHVPS) which
* is a set comprised of attribute handles, values, and
* the size of the values.
*/
RTI::AttributeHandleValuePairSet* pNvpSet = createNVPSet();
/*!
* Send the AHVPS to the federation.
*
* this call returns an event retraction handle but we
* don't support event retraction so no need to store it.
*/
(void) ms_rtiAmb->updateAttributeValues( getInstanceId(),
*pNvpSet,
NULL );
//! Must free the memory
pNvpSet->empty();
delete pNvpSet;
}
catch ( RTI::Exception& e )
{
cerr << "BALL: Error:" << &e << endl;
}
}
}




void Ball::update(
RTI::InteractionClassHandle theInteraction,
const RTI::ParameterHandleValuePairSet& theParameters )
{
if (ms_rtiAmb) // if ms_rtiAmb!=NULL 
{
if ( theInteraction == Ball::ms_clockTickId )
{
RTI::ParameterHandle paramHandle;
RTI::ULong valueLength;

//! We need to iterate through the AttributeHandleValuePairSet
//! to extract each AttributeHandleValuePair. Based on the type
//! specified ( the value returned by getHandle() ) we need to
//! extract the data frlom the buffer that is returned by
//! getValue().
for ( unsigned int i = 0; i < theParameters.size(); i++ )
{
paramHandle = theParameters.getHandle( i );
if ( paramHandle == Ball::ms_clockTickIntervalId )
{
double timeInterval = 1 / 60.0;
theParameters.getValue( i, (char*)&timeInterval, valueLength );

//! Update all clock objects
for ( unsigned int j = 0; j < ms_numInstances; j++ )
{
( *( (Ball*)(ms_instances[j]) ) ).m_stateTimeInterval = timeInterval;
}
}
else if ( paramHandle == Ball::ms_clockTickNumId )
{
//! Don't care
}
else if ( paramHandle == Ball::ms_clockTickTimeId )
{
//! Don't care
}
else
{
//! There must be an error since there should only be
//! one parameter to Communication.
cerr << "BALL: Error: I seem to have received a parameter for "
<< "interaction class ClockTick that I don't "
<< "know about." << endl;
}
}

Ball* pBall;

for ( unsigned int k = 0; k < ms_numInstances; k++ )
{
cout << "BALL: Iterating through all Balls." << endl;

//! Get a pointer to the ball instance
pBall = (Ball*)ms_instances[ k ];

//! ** dequeue state from m_stateQueue and place it in m_currentState
if ( pBall->m_nextStateCalculated == RTI::RTI_TRUE )
{
pBall->m_currentState = pBall->m_nextState;
pBall->m_nextStateCalculated = RTI::RTI_FALSE;

try
{
/*!
* In order to send the values of our attributes, we must
* construct an AttributeHandleValuePairSet (AHVPS) which
* is a set comprised of attribute handles, values, and
* the size of the values. CreateNVPSet() is a method
* defined on the Ball class - it is not part of the RTI.
* Look inside the method to see how to construct an AHVPS
*/
cout << "BALL: Creating NVP set." << endl;
RTI::AttributeHandleValuePairSet* pNvpSet = pBall->createNVPSet();
/*!
* Send the AHVPS to the federation.
*
* this call returns an event retraction handle but we
* don't support event retraction so no need to store it.
*/
cout << "BALL: Sending new ball state out into the world." << endl;
(void) ms_rtiAmb->updateAttributeValues( pBall->getInstanceId(),
*pNvpSet,
NULL );
//! Must free the memory
pNvpSet->empty();
delete pNvpSet;
}
catch ( RTI::Exception& e )
{
cerr << "BALL: Error:" << &e << endl;
}
}
else
{
cerr << "BALL: Next state not ready." << endl;
}
}

}
else
{
cerr << "BALL: Recieved an interaction class I don't know about." << endl;
}

}
} 

GeneralRe: calling a function two ways Pin
toxcct28-Aug-06 7:06
toxcct28-Aug-06 7:06 
GeneralRe: calling a function two ways Pin
Jay0328-Aug-06 6:40
Jay0328-Aug-06 6:40 
GeneralRe: calling a function two ways Pin
Zac Howland28-Aug-06 6:08
Zac Howland28-Aug-06 6:08 
QuestionHandling mouseover events on toolbar with popup Pin
WebMaster28-Aug-06 5:01
WebMaster28-Aug-06 5:01 
QuestionTitleBar Pin
HakunaMatada28-Aug-06 3:48
HakunaMatada28-Aug-06 3:48 
AnswerRe: TitleBar Pin
Hamid_RT3-Sep-06 9:04
Hamid_RT3-Sep-06 9:04 
GeneralRe: TitleBar Pin
HakunaMatada3-Sep-06 19:37
HakunaMatada3-Sep-06 19:37 
GeneralRe: TitleBar Pin
Hamid_RT3-Sep-06 22:27
Hamid_RT3-Sep-06 22:27 
QuestionCan anybody answer please? Pin
ivanris28-Aug-06 3:37
ivanris28-Aug-06 3:37 
GeneralRe: Can anybody answer please? Jeremy - THIS is a programming question... :) Pin
#realJSOP28-Aug-06 3:40
mve#realJSOP28-Aug-06 3:40 
GeneralRe: Can anybody answer please? Pin
Colin Angus Mackay28-Aug-06 3:46
Colin Angus Mackay28-Aug-06 3:46 
GeneralRe: Can anybody answer please? [modified*2] Pin
John M. Drescher28-Aug-06 3:52
John M. Drescher28-Aug-06 3:52 
JokeRe: Can anybody answer please? [modified*2] Pin
toxcct28-Aug-06 5:10
toxcct28-Aug-06 5:10 
QuestionRe: Can anybody answer please? Pin
David Crow28-Aug-06 4:51
David Crow28-Aug-06 4:51 
QuestionDisplaying a dialog derrived from CRecordview Pin
ivanris28-Aug-06 3:34
ivanris28-Aug-06 3:34 
AnswerRe: Displaying a dialog derrived from CRecordview Pin
David Crow28-Aug-06 3:51
David Crow28-Aug-06 3:51 
QuestionTo Shell a program Pin
Sina Parastgary28-Aug-06 2:32
Sina Parastgary28-Aug-06 2:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.