#include "Student.h"
#include "Splat.h"
#include <stdlib.h>
#include <fedtime.hh>
#ifndef _MSC_VER
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
#else
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;
#endif
#define STUDENT_NUM 10
extern RTI::RTIambassador rtiAmb;
extern Student* myStudent;
extern RTIfedTime Lookahead;
extern RTIfedTime CurrentTime;
extern RTI::Boolean Regulating;
RTI::RTIambassador* Student::ms_rtiAmb=NULL;
RTI::Boolean Student::ms_doRegistry=RTI::RTI_FALSE;
RTI::ObjectClassHandle Student::m_StudentHandle=0;
RTI::AttributeHandle Student::m_LunchMoneyHandle=0;
RTI::AttributeHandle Student::m_AmmoAmountHandle=0;
RTI::AttributeHandle Student::m_CleanlinessHandle=0;
RTI::AttributeHandle Student::m_PrivilegeToDeleteHandle=0;
char* const Student::ms_StudentTypeStr="Student";
char* const Student::ms_LunchMoneyTypeStr="LunchMoney";
char* const Student::ms_AmmoAmountTypeStr="AmmoAmount";
char* const Student::ms_CleanlinessTypeStr="Cleanliness";
char* const Student::ms_PrivilegeToDeleteTypeStr="PrivilegeToDelete";
Student* Student::ms_StudentExtent[MAX_FIGHTGAME_FEDERATES]=
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
int Student::ms_extentCardinality=0;
Student::Student(char* name)
:ms_name(NULL),
m_LunchMoney(20),
m_AmmoAmount(0),
m_Cleanliness(100),
m_EnsuingMess(10),
ms_OwnLunchMoney(RTI::RTI_TRUE),
ms_OwnAmmoAmount(RTI::RTI_TRUE),
ms_OwnCleanliness(RTI::RTI_TRUE),
ms_OwnPrivilegeToDelete(RTI::RTI_TRUE),
ms_TransferLunchMoney(RTI::RTI_FALSE),
ms_TransferAmmoAmount(RTI::RTI_FALSE),
ms_TransferCleanliness(RTI::RTI_FALSE),
ms_TransferPrivilegeToDelete(RTI::RTI_FALSE),
ms_LunchMoneyUpdate(RTI::RTI_FALSE),
ms_AmmoAmountUpdate(RTI::RTI_FALSE),
ms_CleanlinessUpdate(RTI::RTI_FALSE),
ms_InstanceDeleted(RTI::RTI_FALSE)
{
cout<<"***Student() OK"<<endl<<endl;
Student::ms_StudentExtent[ Student::ms_extentCardinality++ ] = this;
this->SetName(name);
this->SetLunchMoney(20);
this->SetAmmoAmount(0);
this->SetCleanliness(100);
this->SetEnsuingMess(10);
}
Student::Student(RTI::ObjectHandle id)
:ms_name(NULL),
m_InstanceId(id),
m_LunchMoney(20),
m_AmmoAmount(0),
m_Cleanliness(100),
m_EnsuingMess(10),
ms_OwnLunchMoney(RTI::RTI_FALSE),
ms_OwnAmmoAmount(RTI::RTI_FALSE),
ms_OwnCleanliness(RTI::RTI_FALSE),
ms_OwnPrivilegeToDelete(RTI::RTI_FALSE),
ms_TransferLunchMoney(RTI::RTI_FALSE),
ms_TransferAmmoAmount(RTI::RTI_FALSE),
ms_TransferCleanliness(RTI::RTI_FALSE),
ms_TransferPrivilegeToDelete(RTI::RTI_FALSE),
ms_LunchMoneyUpdate(RTI::RTI_FALSE),
ms_AmmoAmountUpdate(RTI::RTI_FALSE),
ms_CleanlinessUpdate(RTI::RTI_FALSE),
ms_InstanceDeleted(RTI::RTI_FALSE)
{
cout<<"***Student(id) OK"<<endl<<endl;
Student::ms_StudentExtent[ Student::ms_extentCardinality++ ] = this;
this->SetName("two");
this->SetLunchMoney(20);
this->SetAmmoAmount(0);
this->SetCleanliness(100);
this->SetEnsuingMess(10);
}
Student::~Student()
{
cout<<"***~Student() OK"<<endl<<endl;
Student *pStudent = NULL;
int idx=0;
for(idx=0;idx<Student::ms_extentCardinality;idx++)
{
pStudent = Student::ms_StudentExtent[idx];
if (pStudent && pStudent->GetInstanceId() == this->GetInstanceId())
{
break;
}
}
if (pStudent)
{
for (int i=idx;(i<Student::ms_extentCardinality) && (Student::ms_StudentExtent[i]!=NULL); i++)
{
Student::ms_StudentExtent[i] = Student::ms_StudentExtent[i+1];
}
Student::ms_extentCardinality = Student::ms_extentCardinality - 1;
if (ms_rtiAmb && idx == 0)
{
ms_rtiAmb->queryLookahead(Lookahead);
(void)ms_rtiAmb->deleteObjectInstance(this->GetInstanceId(),CurrentTime+Lookahead,"Student Quits");
}
else
{
}
}
delete [] ms_name;
}
void Student::Init(RTI::RTIambassador* rtiAmb)
{
cout<<"***Init() OK"<<endl<<endl;
ms_rtiAmb = rtiAmb;
if(ms_rtiAmb)
{
try
{
m_StudentHandle = ms_rtiAmb->getObjectClassHandle(ms_StudentTypeStr);
m_AmmoAmountHandle= ms_rtiAmb->getAttributeHandle(ms_AmmoAmountTypeStr,m_StudentHandle);
m_LunchMoneyHandle = ms_rtiAmb->getAttributeHandle(ms_LunchMoneyTypeStr,m_StudentHandle);
m_CleanlinessHandle = ms_rtiAmb->getAttributeHandle(ms_CleanlinessTypeStr,m_StudentHandle);
m_PrivilegeToDeleteHandle = ms_rtiAmb->getAttributeHandle(ms_PrivilegeToDeleteTypeStr,m_StudentHandle);
cout<<"***acquired class attribute handles"<<endl;
cout<<"***StudentHandle:"<<m_StudentHandle<<endl;
cout<<"***AmmoAmountHandle:"<<m_AmmoAmountHandle<<endl;
cout<<"***LunchMoneyHandle:"<<m_LunchMoneyHandle<<endl;
cout<<"***CleanlinessHandle:"<<m_CleanlinessHandle<<endl;
cout<<"***PrivilegeToDeleteHandle:"<<m_PrivilegeToDeleteHandle<<endl<<endl;
}
catch ( RTI::Exception& e )
{
cout << e << endl;
exit(1);
}
}
}
void Student::Publishing()
{
cout<<"***Publishing() OK"<<endl<<endl;
if(ms_rtiAmb)
{
RTI::AttributeHandleSet* StudentAttributes;
try
{
StudentAttributes = RTI::AttributeHandleSetFactory::create(4);
StudentAttributes->add(m_AmmoAmountHandle);
StudentAttributes->add(m_LunchMoneyHandle);
StudentAttributes->add(m_CleanlinessHandle);
StudentAttributes->add(m_PrivilegeToDeleteHandle);
}
catch ( RTI::Exception& e )
{
cout << e << endl;
exit(1);
}
try
{
cout<<"*** published objectclass student"<<endl<<endl;
ms_rtiAmb->publishObjectClass(m_StudentHandle,*StudentAttributes);
}
catch ( RTI::Exception& e )
{
cout << e << endl;
exit(1);
}
if(StudentAttributes)
{
StudentAttributes->empty();
delete StudentAttributes;
}
}
}
void Student::Subscribing()
{
cout<<"***Subscribing() OK"<<endl<<endl;
if(ms_rtiAmb)
{
RTI::AttributeHandleSet* StudentAttributes;
try
{
StudentAttributes = RTI::AttributeHandleSetFactory::create(4);
StudentAttributes->add(m_AmmoAmountHandle);
StudentAttributes->add(m_LunchMoneyHandle);
StudentAttributes->add(m_CleanlinessHandle);
StudentAttributes->add(m_PrivilegeToDeleteHandle);
}
catch ( RTI::Exception& e )
{
cout << e << endl;
exit(1);
}
try
{
cout<<"*** Subscribe objectclass student"<<endl<<endl;
ms_rtiAmb->subscribeObjectClassAttributes(m_StudentHandle,*StudentAttributes);
}
catch ( RTI::Exception& e )
{
cout << e << endl;
exit(1);
}
if(StudentAttributes)
{
StudentAttributes->empty();
delete StudentAttributes;
}
}
}
void Student::Register()
{
cout<<"***Register() OK"<<endl<<endl;
if(ms_rtiAmb)
{
if(!ms_doRegistry)
{
cout<<"*** because no one subscrib student class,so tick time!"<<endl;
}
while(!ms_doRegistry)
{
ms_rtiAmb->tick(0.01,2.0);
}
for(int n=0;n<STUDENT_NUM;n++)
{
try
{
(this->ms_StudentExtent[n])->m_InstanceId =
ms_rtiAmb->registerObjectInstance(
(this->ms_StudentExtent[n])->GetStudentRtiId(),
(this->ms_StudentExtent[n])->GetName());
cout<<"*** registered student:"
<<(this->ms_StudentExtent[n])->GetInstanceId()
<<"Name:"<<(this->ms_StudentExtent[n])->GetName()<<endl;
ms_rtiAmb->tick(0.01,2.0);
}
catch ( RTI::Exception& e )
{
cout << e << endl;
exit(1);
}
}
}
}
void Student::DeleteInstance(Student* myStudent)
{
cout<<"***DeleteInstance() OK"<<endl<<endl;
Student* pStudent = NULL;
for(int idx=0;idx<myStudent->ms_extentCardinality;idx++)
{
pStudent = myStudent->ms_StudentExtent[idx];
if(pStud
DXW19850806
- 粉丝: 5
- 资源: 6
最新资源
- stm32f103c8t6驱动st7735sLCD屏幕显示程序
- 精选微信小程序源码:美食菜谱小程序(含源码+源码导入视频教程&文档教程,亲测可用)
- Flume+Kafka+StructuredStreaming+Mysql分布式采集与微批处理
- 微信小程序识别二维码并提取二维码中的文本数据代码
- 基于51单片机 4*4*4三色光立方演示程序
- apache-tomcat-11.0.1-windows.zip
- 基于arduino PC 室内环境监测系统+项目源码+文档说明
- C# winform自定义饼图控件.zip
- 同步空间新手教程.docx
- 13章Electron+Vue3+AI+云存储-实战跨平台桌面应用
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
前往页