计算机仿真中的HLA技术中的餐馆例子分析 (3)Viewer



相比起来,Viewer联邦与transport联邦很相似,都是TAR方式推进时间的,步长都是1.0,lookahead不同,Viewer的lookahead是0.1
程序结构也很相似。 同样,Viewer没有实质性地参与联邦运行。这点与transport联邦不同。
 

主要的流程都在mainThread函数中:
 
(1)读取配置数据,产生联邦,加入联邦;
 
(2)使能时间调节(为了使其他联邦运行得足
摘要由CSDN通过智能技术生成

相比起来,Viewer联邦与transport联邦很相似,都是TAR方式推进时间的,步长都是1.0,lookahead不同,Viewer的lookahead是0.1

程序结构也很相似。 同样,Viewer没有实质性地参与联邦运行。这点与transport联邦不同。

 

主要的流程都在mainThread函数中:

 

(1)读取配置数据,产生联邦,加入联邦;

 

(2)使能时间调节(为了使其他联邦运行得足够慢)和时间受限;

 

(3)获取各种handles,订阅。Viewer联邦订阅了如下属性和交互:

    _rti.subscribeObjectClassAttributesPassively(_BoatClass, _BoatAttributes);

    //changing these subscriptions to active causes the Serving.type and state

    //attributes to be updated

    _rti.subscribeObjectClassAttributes(_ServingClass, _ServingAttributes);

    _rti.subscribeObjectClassAttributes(_ChefClass, _ChefAttributes);

    _rti.subscribeObjectClassAttributes(_DinerClass, _DinerAttributes);

    _rti.subscribeInteractionClass(_SimulationEndsClass);

 

(4)在第一个同步点ReadyToPopulate完成同步;

 

(5)在第二个同步点ReadyToRun完成同步;

 

(6)进入主循环(与transport联邦的主循环完全一样):

 

      //advance time in steps until SimulationEnds received

      _targetTime = new LogicalTimeDouble(0.0);

      _targetTime.setTo(_logicalTime);    //设置要TAR的时间点初始时间为0.0

    timeLoop:

      while (!_simulationEndsReceived) {

        //advance by a step

        _targetTime.increaseBy(_advanceInterval);   //时间请求按步长进行,每次1.0

        _userInterface.setTimeStateAdvancing();

_userInterface.post("This is before TAR:  "+_targetTime);

        _rti.timeAdvanceRequest(_targetTime);        //时间推进请求TAR

        //chew through all the events we receive from the RTI

        boolean wasTimeAdvanceGrant;

        do {

          Callback callback = _callbackQueue.dequeue();   //获取外部时间队列中的第一个事件(注意callbackQueue是排序的)

          wasTimeAdvanceGrant = callback.dispatch();      //通过调用该事件的dispatch函数来处理事件,并返回是否是time grant的布尔量

          if (_simulationEndsReceived) break timeLoop;    //如果是SimulationEnds交互则推出外层循环

        } while (!wasTimeAdvanceGrant);                         //直到收到time grant事件 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值