void CEntHost::PostThink() { m_bIsBot = (GetBotController()) ? true : false; if ( IsAlive() && IsActive() ) { UpdateComponents(); UpdateAttributes(); m_bOnCombat = (m_CombatTimer.HasStarted() && m_CombatTimer.IsLessThen( 10.0f )); m_bUnderAttack = (m_UnderAttackTimer.HasStarted() && m_UnderAttackTimer.IsLessThen( 5.0f )); if ( m_bIsBot && !m_bOnCombat ) { m_bOnCombat = GetBotController()->IsAlerted() || GetBotController()->IsCombating(); } } if ( GetAnimationSystem() ) { GetAnimationSystem()->Update(); } }
void CBoxEntity::Reset() { /* Reset all components */ m_pcEmbodiedEntity->Reset(); m_pcLEDEquippedEntity->Reset(); /* Update components */ UpdateComponents(); }
///////////////////////////// // Update // -Main loop void Player::Update() { Transform * playerT = (Transform*)GetComponent(C_TRANSFORM); InputController * input = (InputController*)GetComponent(C_INPUT); bool changedInput = false; if (input->GetKeyDown('W')) { playerT->SetY(playerT->GetY() - 1); changedInput = true; } if (input->GetKeyDown('A')) { playerT->SetX(playerT->GetX() - 1); changedInput = true; } if (input->GetKeyDown('S')) { playerT->SetY(playerT->GetY() + 1); changedInput = true; } if (input->GetKeyDown('D')) { playerT->SetX(playerT->GetX() + 1); changedInput = true; } if (changedInput) { NetworkView * nwView = (NetworkView*)GetComponent(C_NETWORK); nwView->UpdatePositionMessage(playerT->GetX(), playerT->GetY()); } UpdateComponents(); }
/** * Reset this link back to its original state */ void CMultibodyLinkEntity::Reset() { // Call through to our super reset method CComposableEntity::Reset(); // And reset embodiedEntity->Reset(); // Restore our state currentState = defaultState; // Get our reset position (relative to our parent) CVector3 pos{currentState.originX, currentState.originY, currentState.originZ}; // Get our orientation (relative to our parent) CRadians roll{currentState.roll}; CRadians pitch{currentState.pitch}; CRadians yaw{currentState.yaw}; // And wrap it in a quaternion CQuaternion orientation; orientation.FromEulerAngles(yaw, pitch, roll); // Set our position embodiedEntity->GetOriginAnchor().Position = pos; embodiedEntity->GetOriginAnchor().Orientation = orientation; UpdateComponents(); }
void CBluebotEntity::Reset() { /* Reset all components */ m_pcEmbodiedEntity->Reset(); m_pcControllableEntity->Reset(); m_pcWheeledEntity->Reset(); /* Update components */ UpdateComponents(); }
void CSphereEntity::Reset() { /* Reset all components */ m_pcEmbodiedEntity->Reset(); /* Update components */ UpdateComponents(); }
LRESULT CDlgLocalPanel::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if (WM_PAINT == message || WM_SIZE == message || WM_MOVE == message) { UpdateComponents(); } return CDialogEx::WindowProc(message, wParam, lParam); }
LRESULT CEasyClientDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if (/*WM_PAINT == message ||*/ WM_SIZE == message /*|| WM_MOVE == message*/) { UpdateComponents(); } return CDialogEx::WindowProc(message, wParam, lParam); }
void CDlgPanel::OnSize(UINT nType, int cx, int cy) { CEasySkinDialog::OnSize(nType, cx, cy); UpdateComponents(); if (m_pManager) { m_pManager->ResizeVideoWnd(); } }
void CEPuckEntity::Reset() { /* Reset all components */ m_pcEmbodiedEntity->Reset(); m_pcControllableEntity->Reset(); m_pcWheeledEntity->Reset(); m_pcLEDEquippedEntity->Reset(); m_pcRABEquippedEntity->Reset(); /* Update components */ UpdateComponents(); }
void CBluebotEntity::Init(TConfigurationNode& t_tree) { try { /* Init parent */ CEntity::Init(t_tree); /* Init components */ m_pcEmbodiedEntity->Init(t_tree); m_pcControllableEntity->Init(t_tree); m_pcWheeledEntity->Init(t_tree); UpdateComponents(); } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize entity \"" << GetId() << "\".", ex); } }
void CFootBotEntity::Reset() { /* Reset all components */ m_pcEmbodiedEntity->Reset(); m_pcControllableEntity->Reset(); m_pcWheeledEntity->Reset(); m_pcLEDEquippedEntity->Reset(); m_pcGripperEquippedEntity->Reset(); m_pcDistanceScannerEquippedEntity->Reset(); m_pcRABEquippedEntity->Reset(); m_pcWiFiEquippedEntity->Reset(); m_cTurretRotation = CRadians::ZERO; m_fTurretRotationSpeed = 0.0f; m_unTurretMode = 0; /* Update components */ UpdateComponents(); }
void CBoxEntity::Init(TConfigurationNode& t_tree) { try { /* Init parent */ CComposableEntity::Init(t_tree); /* Parse XML to get the size */ GetNodeAttribute(t_tree, "size", m_cSize); /* Parse XML to get the movable attribute */ bool bMovable; GetNodeAttribute(t_tree, "movable", bMovable); if(bMovable) { /* Parse XML to get the mass */ GetNodeAttribute(t_tree, "mass", m_fMass); } else { m_fMass = 0.0f; } /* Create embodied entity using parsed data */ m_pcEmbodiedEntity = new CEmbodiedEntity(this); AddComponent(*m_pcEmbodiedEntity); m_pcEmbodiedEntity->Init(GetNode(t_tree, "body")); m_pcEmbodiedEntity->SetMovable(bMovable); /* Init LED equipped entity component */ m_pcLEDEquippedEntity = new CLEDEquippedEntity(this, m_pcEmbodiedEntity); AddComponent(*m_pcLEDEquippedEntity); if(NodeExists(t_tree, "leds")) { /* Create LED equipped entity * NOTE: the LEDs are not added to the medium yet */ m_pcLEDEquippedEntity->Init(GetNode(t_tree, "leds")); /* Add the LEDs to the medium */ std::string strMedium; GetNodeAttribute(GetNode(t_tree, "leds"), "medium", strMedium); m_pcLEDMedium = &CSimulator::GetInstance().GetMedium<CLEDMedium>(strMedium); m_pcLEDEquippedEntity->AddToMedium(*m_pcLEDMedium); } else { /* No LEDs added, no need to update this entity */ m_pcLEDEquippedEntity->Disable(); m_pcLEDEquippedEntity->SetCanBeEnabledIfDisabled(false); } UpdateComponents(); } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize box entity \"" << GetId() << "\".", ex); } }
void CCylinderEntity::Init(TConfigurationNode& t_tree) { try { /* Init parent */ CEntity::Init(t_tree); /* Parse XML to get the radius */ GetNodeAttribute(t_tree, "radius", m_fRadius); /* Parse XML to get the height */ GetNodeAttribute(t_tree, "height", m_fHeight); /* Parse XML to get the movable attribute */ GetNodeAttribute(t_tree, "movable", m_bMovable); if(m_bMovable) { /* Parse XML to get the mass */ GetNodeAttribute(t_tree, "mass", m_fMass); } else { m_fMass = 0.0f; } /* Parse XML to get the visible attribute */ GetNodeAttributeOrDefault(t_tree, "visible", m_bVisible, m_bVisible); /* Init LED equipped entity component */ m_pcLEDEquippedEntity->Init(t_tree); if(NodeExists(t_tree, "leds")) { TConfigurationNode& tLEDs = GetNode(t_tree, "leds"); /* Go through the led entries */ CVector3 cPosition; CColor cColor; TConfigurationNodeIterator itLED("led"); for(itLED = itLED.begin(&tLEDs); itLED != itLED.end(); ++itLED) { GetNodeAttribute(*itLED, "position", cPosition); GetNodeAttribute(*itLED, "color", cColor); m_vecBaseLEDPositions.push_back(cPosition); m_pcLEDEquippedEntity->AddLed(cPosition, cColor); } } /* Create embodied entity using parsed data */ m_pcEmbodiedEntity = new CCylinderEmbodiedEntity(this, m_fRadius, m_fHeight); m_pcEmbodiedEntity->Init(t_tree); UpdateComponents(); } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize the cylinder entity.", ex); } }
void CHumanEntity::Init(TConfigurationNode& t_tree) { try { /* * Init parent */ CComposableEntity::Init(t_tree); /* * Create and init components */ /* Parse XML to get the radius */ GetNodeAttribute(t_tree, "radius", m_fRadius); /* Parse XML to get the height */ GetNodeAttribute(t_tree, "height", m_fHeight); /* Parse XML to get the mass */ GetNodeAttribute(t_tree, "mass", m_fMass); /* Parse XML to get the intensity */ GetNodeAttribute(t_tree, "intensity", m_fIntensity); /* Embodied entity */ m_pcEmbodiedEntity = new CEmbodiedEntity(this); AddComponent(*m_pcEmbodiedEntity); m_pcEmbodiedEntity->Init(GetNode(t_tree, "body")); /* Wheeled entity and wheel positions (left, right) */ m_pcWheeledEntity = new CWheeledEntity(this, "wheels_0", 2); AddComponent(*m_pcWheeledEntity); m_pcWheeledEntity->SetWheel(0, CVector3(0.0f, HALF_INTERWHEEL_DISTANCE, 0.0f), WHEEL_RADIUS); m_pcWheeledEntity->SetWheel(1, CVector3(0.0f, -HALF_INTERWHEEL_DISTANCE, 0.0f), WHEEL_RADIUS); /* Controllable entity It must be the last one, for actuators/sensors to link to composing entities correctly */ m_pcControllableEntity = new CControllableEntity(this); AddComponent(*m_pcControllableEntity); m_pcControllableEntity->Init(GetNode(t_tree, "controller")); /* Update components */ UpdateComponents(); } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize human entity \"" << GetId() << "\".", ex); } }
void CDirectionalLEDEquippedEntity::Init(TConfigurationNode& t_tree) { try { /* Init parent */ CComposableEntity::Init(t_tree); /* Go through the led entries */ TConfigurationNodeIterator itLED("directional_led"); for(itLED = itLED.begin(&t_tree); itLED != itLED.end(); ++itLED) { /* Initialise the LED using the XML */ CDirectionalLEDEntity* pcLED = new CDirectionalLEDEntity(this); pcLED->Init(*itLED); CVector3 cPositionOffset; GetNodeAttribute(*itLED, "position", cPositionOffset); CQuaternion cOrientationOffset; GetNodeAttribute(*itLED, "orientation", cOrientationOffset); /* Parse and look up the anchor */ std::string strAnchorId; GetNodeAttribute(*itLED, "anchor", strAnchorId); /* * NOTE: here we get a reference to the embodied entity * This line works under the assumption that: * 1. the DirectionalLEDEquippedEntity has a parent; * 2. the parent has a child whose id is "body" * 3. the "body" is an embodied entity * If any of the above is false, this line will bomb out. */ CEmbodiedEntity& cBody = GetParent().GetComponent<CEmbodiedEntity>("body"); /* Add the LED to this container */ m_vecInstances.emplace_back(*pcLED, cBody.GetAnchor(strAnchorId), cPositionOffset, cOrientationOffset); AddComponent(*pcLED); } UpdateComponents(); } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize directional LED equipped entity \"" << GetContext() + GetId() << "\".", ex); } }
void CFootBotEntity::Init(TConfigurationNode& t_tree) { try { /* Init parent */ CEntity::Init(t_tree); /* Init components */ m_pcEmbodiedEntity->Init(t_tree); m_pcControllableEntity->Init(t_tree); m_pcWheeledEntity->Init(t_tree); m_pcLEDEquippedEntity->Init(t_tree); m_pcGripperEquippedEntity->Init(t_tree); m_pcDistanceScannerEquippedEntity->Init(t_tree); m_pcRABEquippedEntity->Init(t_tree); m_pcWiFiEquippedEntity->Init(t_tree); UpdateComponents(); } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize entity \"" << GetId() << "\".", ex); } }
CTargetEntity::CTargetEntity(const std::string& id, const std::string& controllerId, const CVector3& position, const CQuaternion& orientation, Real rabRange, size_t rabDataSize) : CComposableEntity(nullptr, id) { try { embodiedEntity = new CEmbodiedEntity(this, bodyId, position, orientation); embodiedEntity->SetMovable(false); AddComponent(*embodiedEntity); ledEquippedEntity = new CLEDEquippedEntity(this, ledsId); AddComponent(*ledEquippedEntity); ledEquippedEntity->AddLEDRing( CVector3(0.0f, 0.0f, LED_RING_ELEVATION), LED_RING_RADIUS, LED_RING_START_ANGLE, 8, embodiedEntity->GetOriginAnchor()); rabEquippedEntity = new CRABEquippedEntity(this, rabId, rabDataSize, rabRange, embodiedEntity->GetOriginAnchor(), *embodiedEntity, CVector3(0.0f, 0.0f, RAB_ELEVATION)); AddComponent(*rabEquippedEntity); controllableEntity = new CControllableEntity(this, controllableId); AddComponent(*controllableEntity); controllableEntity->SetController(controllerId); UpdateComponents(); } catch (CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize entity \"" << GetId() << "\".", ex); } }
void CTargetEntity::Init(TConfigurationNode& t_tree) { try { CComposableEntity::Init(t_tree); embodiedEntity = new CEmbodiedEntity(this); AddComponent(*embodiedEntity); embodiedEntity->Init(GetNode(t_tree, "body")); ledEquippedEntity = new CLEDEquippedEntity(this, ledsId); AddComponent(*ledEquippedEntity); ledEquippedEntity->AddLEDRing( CVector3(0.0f, 0.0f, LED_RING_ELEVATION), LED_RING_RADIUS, LED_RING_START_ANGLE, 8, embodiedEntity->GetOriginAnchor()); Real fRange = 0.8f; GetNodeAttributeOrDefault(t_tree, "rab_range", fRange, fRange); UInt32 unDataSize = 2; GetNodeAttributeOrDefault(t_tree, "rab_data_size", unDataSize, unDataSize); rabEquippedEntity = new CRABEquippedEntity(this, rabId, unDataSize, fRange, embodiedEntity->GetOriginAnchor(), *embodiedEntity, CVector3(0.0f, 0.0f, RAB_ELEVATION)); AddComponent(*rabEquippedEntity); controllableEntity = new CControllableEntity(this); AddComponent(*controllableEntity); controllableEntity->Init(GetNode(t_tree, "controller")); UpdateComponents(); } catch (CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize entity \"" << GetId() << "\".", ex); } }
void CDirectionalLEDEquippedEntity::AddLED(const CVector3& c_position, const CQuaternion& c_orientation, SAnchor& s_anchor, const CRadians& c_observable_angle, const CColor& c_color) { /* create the new directional LED entity */ CDirectionalLEDEntity* pcLED = new CDirectionalLEDEntity(this, "directional_led_" + std::to_string(m_vecInstances.size()), c_position, c_orientation, c_observable_angle, c_color); /* add it to the instances vector */ m_vecInstances.emplace_back(*pcLED, s_anchor, c_position, c_orientation); /* inform the base class about the new entity */ AddComponent(*pcLED); UpdateComponents(); }
/** * Load the sphere configuration from its XML tag */ void CSphereEntity::Init(TConfigurationNode &t_tree) { try { // Init parent CComposableEntity::Init(t_tree); // Parse XML to get the radius (required) GetNodeAttribute(t_tree, "radius", m_fRadius); // Parse XML to get the movable attribute (optional: defaults to true) bool bMovable; GetNodeAttributeOrDefault(t_tree, "movable", bMovable, true); // Get the mass from XML if the sphere is movable if (bMovable) { // Parse XML to get the mass (optional, defaults to 1) GetNodeAttributeOrDefault(t_tree, "mass", m_fMass, 1.0f); } else { m_fMass = 0.0f; } // Create embodied entity using parsed data m_pcEmbodiedEntity = new CEmbodiedEntity(this); m_pcEmbodiedEntity->Init(GetNode(t_tree, "body")); m_pcEmbodiedEntity->SetMovable(bMovable); AddComponent(*m_pcEmbodiedEntity); UpdateComponents(); } catch (CARGoSException &ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize the ball entity.", ex); } }
void HistoryMessage::createComponents(const CreateConfig &config) { uint64 mask = 0; if (config.replyTo) { mask |= HistoryMessageReply::Bit(); } if (config.viaBotId) { mask |= HistoryMessageVia::Bit(); } if (config.viewsCount >= 0) { mask |= HistoryMessageViews::Bit(); } if (!config.author.isEmpty()) { mask |= HistoryMessageSigned::Bit(); } auto hasViaBot = (config.viaBotId != 0); auto hasInlineMarkup = [&config] { if (config.mtpMarkup) { return (config.mtpMarkup->type() == mtpc_replyInlineMarkup); } return (config.inlineMarkup != nullptr); }; if (config.editDate != TimeId(0)) { mask |= HistoryMessageEdited::Bit(); } if (config.senderOriginal) { mask |= HistoryMessageForwarded::Bit(); } if (config.mtpMarkup) { // optimization: don't create markup component for the case // MTPDreplyKeyboardHide with flags = 0, assume it has f_zero flag if (config.mtpMarkup->type() != mtpc_replyKeyboardHide || config.mtpMarkup->c_replyKeyboardHide().vflags.v != 0) { mask |= HistoryMessageReplyMarkup::Bit(); } } else if (config.inlineMarkup) { mask |= HistoryMessageReplyMarkup::Bit(); } UpdateComponents(mask); if (const auto reply = Get<HistoryMessageReply>()) { reply->replyToMsgId = config.replyTo; if (!reply->updateData(this)) { Auth().api().requestMessageData( history()->peer->asChannel(), reply->replyToMsgId, HistoryDependentItemCallback(fullId())); } } if (const auto via = Get<HistoryMessageVia>()) { via->create(config.viaBotId); } if (const auto views = Get<HistoryMessageViews>()) { views->_views = config.viewsCount; } if (const auto edited = Get<HistoryMessageEdited>()) { edited->date = config.editDate; } if (const auto msgsigned = Get<HistoryMessageSigned>()) { msgsigned->author = config.author; } if (const auto forwarded = Get<HistoryMessageForwarded>()) { forwarded->originalDate = config.originalDate; forwarded->originalSender = App::peer(config.senderOriginal); forwarded->originalId = config.originalId; forwarded->originalAuthor = config.authorOriginal; forwarded->savedFromPeer = App::peerLoaded(config.savedFromPeer); forwarded->savedFromMsgId = config.savedFromMsgId; } if (const auto markup = Get<HistoryMessageReplyMarkup>()) { if (config.mtpMarkup) { markup->create(*config.mtpMarkup); } else if (config.inlineMarkup) { markup->create(*config.inlineMarkup); } if (markup->flags & MTPDreplyKeyboardMarkup_ClientFlag::f_has_switch_inline_button) { _flags |= MTPDmessage_ClientFlag::f_has_switch_inline_button; } } _fromNameVersion = displayFrom()->nameVersion; }
CEyeBotEntity::CEyeBotEntity(const std::string& str_id, const std::string& str_controller_id, const CVector3& c_position, const CQuaternion& c_orientation, Real f_rab_range) : CComposableEntity(NULL, str_id), m_pcControllableEntity(NULL), m_pcEmbodiedEntity(NULL), m_pcLEDEquippedEntity(NULL), m_pcLightSensorEquippedEntity(NULL), m_pcProximitySensorEquippedEntity(NULL), m_pcQuadRotorEntity(NULL), m_pcRABEquippedEntity(NULL) { try { /* * Create and init components */ /* * Embodied entity * Better to put this first, because many other entities need this one */ m_pcEmbodiedEntity = new CEmbodiedEntity(this, "body_0", c_position, c_orientation); AddComponent(*m_pcEmbodiedEntity); /* Quadrotor entity */ m_pcQuadRotorEntity = new CQuadRotorEntity(this, "quadrotor_0"); AddComponent(*m_pcQuadRotorEntity); /* LED equipped entity, with LEDs [0-11] and beacon [12] */ m_pcLEDEquippedEntity = new CLEDEquippedEntity(this, "leds_0"); m_pcLEDEquippedEntity->AddLEDRing( CVector3(0.0f, 0.0f, LED_LOWER_RING_ELEVATION), LED_RING_RADIUS, HALF_LED_ANGLE_SLICE, 16, m_pcEmbodiedEntity->GetOriginAnchor()); m_pcLEDEquippedEntity->AddLEDRing( CVector3(0.0f, 0.0f, LED_UPPER_RING_ELEVATION), LED_RING_RADIUS, HALF_LED_ANGLE_SLICE, 16, m_pcEmbodiedEntity->GetOriginAnchor()); CVector3 cLEDPos(LED_RING_RADIUS * 0.7f, 0.0f, LED_LOWER_RING_ELEVATION - 0.01f); cLEDPos.RotateZ(3.0f * CRadians::PI_OVER_FOUR); m_pcLEDEquippedEntity->AddLED( cLEDPos, m_pcEmbodiedEntity->GetOriginAnchor()); AddComponent(*m_pcLEDEquippedEntity); /* Proximity sensor equipped entity */ m_pcProximitySensorEquippedEntity = new CProximitySensorEquippedEntity(this, "proximity_0"); AddComponent(*m_pcProximitySensorEquippedEntity); m_pcProximitySensorEquippedEntity->AddSensorRing( CVector3(0.0f, 0.0f, PROXIMITY_SENSOR_RING_ELEVATION), PROXIMITY_SENSOR_RING_RADIUS, PROXIMITY_SENSOR_RING_START_ANGLE, PROXIMITY_SENSOR_RING_RANGE, 24, m_pcEmbodiedEntity->GetOriginAnchor()); /* Light sensor equipped entity */ m_pcLightSensorEquippedEntity = new CLightSensorEquippedEntity(this, "light_0"); AddComponent(*m_pcLightSensorEquippedEntity); m_pcLightSensorEquippedEntity->AddSensorRing( CVector3(0.0f, 0.0f, PROXIMITY_SENSOR_RING_ELEVATION), PROXIMITY_SENSOR_RING_RADIUS, PROXIMITY_SENSOR_RING_START_ANGLE, PROXIMITY_SENSOR_RING_RANGE, 24, m_pcEmbodiedEntity->GetOriginAnchor()); /* RAB equipped entity */ m_pcRABEquippedEntity = new CRABEquippedEntity( this, "rab_0", 10, f_rab_range, m_pcEmbodiedEntity->GetOriginAnchor(), *m_pcEmbodiedEntity); AddComponent(*m_pcRABEquippedEntity); /* Controllable entity It must be the last one, for actuators/sensors to link to composing entities correctly */ m_pcControllableEntity = new CControllableEntity(this, "controller_0"); AddComponent(*m_pcControllableEntity); m_pcControllableEntity->SetController(str_controller_id); /* Update components */ UpdateComponents(); } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize entity \"" << GetId() << "\".", ex); } }
void CEyeBotEntity::Reset() { /* Reset all components */ CComposableEntity::Reset(); /* Update components */ UpdateComponents(); }
void CEyeBotEntity::Init(TConfigurationNode& t_tree) { try { /* * Init parent */ CComposableEntity::Init(t_tree); /* * Create and init components */ /* * Embodied entity * Better to put this first, because many other entities need this one */ m_pcEmbodiedEntity = new CEmbodiedEntity(this); AddComponent(*m_pcEmbodiedEntity); m_pcEmbodiedEntity->Init(GetNode(t_tree, "body")); /* Quadrotor entity */ m_pcQuadRotorEntity = new CQuadRotorEntity(this, "quadrotor_0"); AddComponent(*m_pcQuadRotorEntity); /* LED equipped entity, with LEDs [0-11] and beacon [12] */ m_pcLEDEquippedEntity = new CLEDEquippedEntity(this, "leds_0"); m_pcLEDEquippedEntity->AddLEDRing( CVector3(0.0f, 0.0f, LED_LOWER_RING_ELEVATION), LED_RING_RADIUS, HALF_LED_ANGLE_SLICE, 16, m_pcEmbodiedEntity->GetOriginAnchor()); m_pcLEDEquippedEntity->AddLEDRing( CVector3(0.0f, 0.0f, LED_UPPER_RING_ELEVATION), LED_RING_RADIUS, HALF_LED_ANGLE_SLICE, 16, m_pcEmbodiedEntity->GetOriginAnchor()); CVector3 cLEDPos(LED_RING_RADIUS * 0.7f, 0.0f, LED_LOWER_RING_ELEVATION - 0.01f); cLEDPos.RotateZ(3.0f * CRadians::PI_OVER_FOUR); m_pcLEDEquippedEntity->AddLED( cLEDPos, m_pcEmbodiedEntity->GetOriginAnchor()); AddComponent(*m_pcLEDEquippedEntity); /* Proximity sensor equipped entity */ m_pcProximitySensorEquippedEntity = new CProximitySensorEquippedEntity(this, "proximity_0"); AddComponent(*m_pcProximitySensorEquippedEntity); m_pcProximitySensorEquippedEntity->AddSensorRing( CVector3(0.0f, 0.0f, PROXIMITY_SENSOR_RING_ELEVATION), PROXIMITY_SENSOR_RING_RADIUS, PROXIMITY_SENSOR_RING_START_ANGLE, PROXIMITY_SENSOR_RING_RANGE, 24, m_pcEmbodiedEntity->GetOriginAnchor()); /* Light sensor equipped entity */ m_pcLightSensorEquippedEntity = new CLightSensorEquippedEntity(this, "light_0"); AddComponent(*m_pcLightSensorEquippedEntity); m_pcLightSensorEquippedEntity->AddSensorRing( CVector3(0.0f, 0.0f, PROXIMITY_SENSOR_RING_ELEVATION), PROXIMITY_SENSOR_RING_RADIUS, PROXIMITY_SENSOR_RING_START_ANGLE, PROXIMITY_SENSOR_RING_RANGE, 24, m_pcEmbodiedEntity->GetOriginAnchor()); /* RAB equipped entity */ Real fRange = 3.0f; GetNodeAttributeOrDefault(t_tree, "rab_range", fRange, fRange); m_pcRABEquippedEntity = new CRABEquippedEntity( this, "rab_0", 10, fRange, m_pcEmbodiedEntity->GetOriginAnchor(), *m_pcEmbodiedEntity); AddComponent(*m_pcRABEquippedEntity); /* Controllable entity It must be the last one, for actuators/sensors to link to composing entities correctly */ m_pcControllableEntity = new CControllableEntity(this); AddComponent(*m_pcControllableEntity); m_pcControllableEntity->Init(GetNode(t_tree, "controller")); /* Update components */ UpdateComponents(); } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize entity \"" << GetId() << "\".", ex); } }
void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationCommand>& commands) { PROFILE3("sim update"); PROFILE2_ATTR("turn %d", (int)m_TurnNumber); fixed turnLengthFixed = fixed::FromInt(turnLength) / 1000; /* * In serialization test mode, we save the original (primary) simulation state before each turn update. * We run the update, then load the saved state into a secondary context. * We serialize that again and compare to the original serialization (to check that * serialize->deserialize->serialize is equivalent to serialize). * Then we run the update on the secondary context, and check that its new serialized * state matches the primary context after the update (to check that the simulation doesn't depend * on anything that's not serialized). */ const bool serializationTestDebugDump = false; // set true to save human-readable state dumps before an error is detected, for debugging (but slow) const bool serializationTestHash = true; // set true to save and compare hash of state SerializationTestState primaryStateBefore; if (m_EnableSerializationTest) { ENSURE(m_ComponentManager.SerializeState(primaryStateBefore.state)); if (serializationTestDebugDump) ENSURE(m_ComponentManager.DumpDebugState(primaryStateBefore.debug, false)); if (serializationTestHash) ENSURE(m_ComponentManager.ComputeStateHash(primaryStateBefore.hash, false)); } UpdateComponents(m_SimContext, turnLengthFixed, commands); if (m_EnableSerializationTest) { // Initialise the secondary simulation CTerrain secondaryTerrain; CSimContext secondaryContext; secondaryContext.m_Terrain = &secondaryTerrain; CComponentManager secondaryComponentManager(secondaryContext, m_ComponentManager.GetScriptInterface().GetRuntime()); secondaryComponentManager.LoadComponentTypes(); ENSURE(LoadDefaultScripts(secondaryComponentManager, NULL)); ResetComponentState(secondaryComponentManager, false, false); // Load the map into the secondary simulation LDR_BeginRegistering(); CMapReader* mapReader = new CMapReader; // automatically deletes itself // TODO: this duplicates CWorld::RegisterInit and could probably be cleaned up a bit std::string mapType; m_ComponentManager.GetScriptInterface().GetProperty(m_InitAttributes.get(), "mapType", mapType); if (mapType == "random") { // TODO: support random map scripts debug_warn(L"Serialization test mode only supports scenarios"); } else { std::wstring mapFile; m_ComponentManager.GetScriptInterface().GetProperty(m_InitAttributes.get(), "map", mapFile); VfsPath mapfilename = VfsPath(mapFile).ChangeExtension(L".pmp"); mapReader->LoadMap(mapfilename, CScriptValRooted(), &secondaryTerrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &secondaryContext, INVALID_PLAYER, true); // throws exception on failure } LDR_EndRegistering(); ENSURE(LDR_NonprogressiveLoad() == INFO::OK); ENSURE(secondaryComponentManager.DeserializeState(primaryStateBefore.state)); SerializationTestState secondaryStateBefore; ENSURE(secondaryComponentManager.SerializeState(secondaryStateBefore.state)); if (serializationTestDebugDump) ENSURE(secondaryComponentManager.DumpDebugState(secondaryStateBefore.debug, false)); if (serializationTestHash) ENSURE(secondaryComponentManager.ComputeStateHash(secondaryStateBefore.hash, false)); if (primaryStateBefore.state.str() != secondaryStateBefore.state.str() || primaryStateBefore.hash != secondaryStateBefore.hash) { ReportSerializationFailure(&primaryStateBefore, NULL, &secondaryStateBefore, NULL); } SerializationTestState primaryStateAfter; ENSURE(m_ComponentManager.SerializeState(primaryStateAfter.state)); if (serializationTestHash) ENSURE(m_ComponentManager.ComputeStateHash(primaryStateAfter.hash, false)); UpdateComponents(secondaryContext, turnLengthFixed, CloneCommandsFromOtherContext(m_ComponentManager.GetScriptInterface(), secondaryComponentManager.GetScriptInterface(), commands)); SerializationTestState secondaryStateAfter; ENSURE(secondaryComponentManager.SerializeState(secondaryStateAfter.state)); if (serializationTestHash) ENSURE(secondaryComponentManager.ComputeStateHash(secondaryStateAfter.hash, false)); if (primaryStateAfter.state.str() != secondaryStateAfter.state.str() || primaryStateAfter.hash != secondaryStateAfter.hash) { // Only do the (slow) dumping now we know we're going to need to report it ENSURE(m_ComponentManager.DumpDebugState(primaryStateAfter.debug, false)); ENSURE(secondaryComponentManager.DumpDebugState(secondaryStateAfter.debug, false)); ReportSerializationFailure(&primaryStateBefore, &primaryStateAfter, &secondaryStateBefore, &secondaryStateAfter); } } // if (m_TurnNumber == 0) // m_ComponentManager.GetScriptInterface().DumpHeap(); // Run the GC occasionally // (TODO: we ought to schedule this for a frame where we're not // running the sim update, to spread the load) if (m_TurnNumber % 1 == 0) m_ComponentManager.GetScriptInterface().MaybeIncrementalRuntimeGC(); if (m_EnableOOSLog) DumpState(); // Start computing AI for the next turn CmpPtr<ICmpAIManager> cmpAIManager(m_SimContext, SYSTEM_ENTITY); if (cmpAIManager) cmpAIManager->StartComputation(); ++m_TurnNumber; }
CSpiriEntity::CSpiriEntity(const std::string& str_id, const std::string& str_controller_id, const CVector3& c_position, const CQuaternion& c_orientation, Real f_rab_range, size_t un_rab_data_size, const CRadians& c_cam_aperture, Real f_cam_range) : CComposableEntity(NULL, str_id), m_pcControllableEntity(NULL), m_pcEmbodiedEntity(NULL), m_pcQuadRotorEntity(NULL), m_pcRABEquippedEntity(NULL), m_pcPerspectiveCameraEquippedEntity(NULL) { try { /* * Create and init components */ /* * Embodied entity * Better to put this first, because many other entities need this one */ m_pcEmbodiedEntity = new CEmbodiedEntity(this, "body_0", c_position, c_orientation); AddComponent(*m_pcEmbodiedEntity); /* Quadrotor entity */ m_pcQuadRotorEntity = new CQuadRotorEntity(this, "quadrotor_0"); AddComponent(*m_pcQuadRotorEntity); /* RAB equipped entity */ SAnchor& cRABAnchor = m_pcEmbodiedEntity->AddAnchor( "rab", CVector3(0.0f, 0.0f, RAB_ELEVATION)); m_pcRABEquippedEntity = new CRABEquippedEntity( this, "rab_0", un_rab_data_size, f_rab_range, cRABAnchor, *m_pcEmbodiedEntity); AddComponent(*m_pcRABEquippedEntity); m_pcEmbodiedEntity->EnableAnchor("rab"); /* Perspective camera */ SAnchor& cCameraAnchor = m_pcEmbodiedEntity->AddAnchor( "camera", CVector3(BODY_RADIUS, 0.0f, 0.0f)); m_pcPerspectiveCameraEquippedEntity = new CPerspectiveCameraEquippedEntity( this, "perspective_camera_0", c_cam_aperture, 0.035f, f_cam_range, 640, 480, cCameraAnchor); AddComponent(*m_pcPerspectiveCameraEquippedEntity); m_pcEmbodiedEntity->EnableAnchor("camera"); /* Controllable entity It must be the last one, for actuators/sensors to link to composing entities correctly */ m_pcControllableEntity = new CControllableEntity(this, "controller_0"); AddComponent(*m_pcControllableEntity); m_pcControllableEntity->SetController(str_controller_id); /* Update components */ UpdateComponents(); } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize entity \"" << GetId() << "\".", ex); } }
void CSpiriEntity::Init(TConfigurationNode& t_tree) { try { /* * Init parent */ CComposableEntity::Init(t_tree); /* * Create and init components */ /* * Embodied entity * Better to put this first, because many other entities need this one */ m_pcEmbodiedEntity = new CEmbodiedEntity(this); AddComponent(*m_pcEmbodiedEntity); m_pcEmbodiedEntity->Init(GetNode(t_tree, "body")); /* Quadrotor entity */ m_pcQuadRotorEntity = new CQuadRotorEntity(this, "quadrotor_0"); AddComponent(*m_pcQuadRotorEntity); /* RAB equipped entity */ Real fRABRange = 3.0f; GetNodeAttributeOrDefault(t_tree, "rab_range", fRABRange, fRABRange); UInt32 unRABDataSize = 10; GetNodeAttributeOrDefault(t_tree, "rab_data_size", unRABDataSize, unRABDataSize); SAnchor& cRABAnchor = m_pcEmbodiedEntity->AddAnchor("rab", CVector3(0.0f, 0.0f, RAB_ELEVATION)); m_pcRABEquippedEntity = new CRABEquippedEntity( this, "rab_0", unRABDataSize, fRABRange, cRABAnchor, *m_pcEmbodiedEntity); AddComponent(*m_pcRABEquippedEntity); m_pcEmbodiedEntity->EnableAnchor("rab"); /* Perspective camera */ CDegrees cCameraAperture(30.0f); GetNodeAttributeOrDefault(t_tree, "camera_aperture", cCameraAperture, cCameraAperture); Real fCameraRange = 10.0f; GetNodeAttributeOrDefault(t_tree, "camera_range", fCameraRange, fCameraRange); SAnchor& cCameraAnchor = m_pcEmbodiedEntity->AddAnchor( "camera", CVector3(BODY_RADIUS, 0.0f, 0.0f)); m_pcPerspectiveCameraEquippedEntity = new CPerspectiveCameraEquippedEntity( this, "perspective_camera_0", ToRadians(cCameraAperture), 0.035f, fCameraRange, 640, 480, cCameraAnchor); AddComponent(*m_pcPerspectiveCameraEquippedEntity); m_pcEmbodiedEntity->EnableAnchor("camera"); /* Controllable entity It must be the last one, for actuators/sensors to link to composing entities correctly */ m_pcControllableEntity = new CControllableEntity(this); AddComponent(*m_pcControllableEntity); m_pcControllableEntity->Init(GetNode(t_tree, "controller")); /* Update components */ UpdateComponents(); } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Failed to initialize entity \"" << GetId() << "\".", ex); } }
void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationCommand>& commands) { PROFILE3("sim update"); PROFILE2_ATTR("turn %d", (int)m_TurnNumber); fixed turnLengthFixed = fixed::FromInt(turnLength) / 1000; /* * In serialization test mode, we save the original (primary) simulation state before each turn update. * We run the update, then load the saved state into a secondary context. * We serialize that again and compare to the original serialization (to check that * serialize->deserialize->serialize is equivalent to serialize). * Then we run the update on the secondary context, and check that its new serialized * state matches the primary context after the update (to check that the simulation doesn't depend * on anything that's not serialized). */ const bool serializationTestDebugDump = false; // set true to save human-readable state dumps before an error is detected, for debugging (but slow) const bool serializationTestHash = true; // set true to save and compare hash of state SerializationTestState primaryStateBefore; ScriptInterface& scriptInterface = m_ComponentManager.GetScriptInterface(); if (m_EnableSerializationTest) { ENSURE(m_ComponentManager.SerializeState(primaryStateBefore.state)); if (serializationTestDebugDump) ENSURE(m_ComponentManager.DumpDebugState(primaryStateBefore.debug, false)); if (serializationTestHash) ENSURE(m_ComponentManager.ComputeStateHash(primaryStateBefore.hash, false)); } UpdateComponents(m_SimContext, turnLengthFixed, commands); if (m_EnableSerializationTest) { // Initialise the secondary simulation CTerrain secondaryTerrain; CSimContext secondaryContext; secondaryContext.m_Terrain = &secondaryTerrain; CComponentManager secondaryComponentManager(secondaryContext, scriptInterface.GetRuntime()); secondaryComponentManager.LoadComponentTypes(); std::set<VfsPath> secondaryLoadedScripts; ENSURE(LoadDefaultScripts(secondaryComponentManager, &secondaryLoadedScripts)); ResetComponentState(secondaryComponentManager, false, false); // Load the trigger scripts after we have loaded the simulation. { JSContext* cx2 = secondaryComponentManager.GetScriptInterface().GetContext(); JSAutoRequest rq2(cx2); JS::RootedValue mapSettingsCloned(cx2, secondaryComponentManager.GetScriptInterface().CloneValueFromOtherContext( scriptInterface, m_MapSettings)); ENSURE(LoadTriggerScripts(secondaryComponentManager, mapSettingsCloned, &secondaryLoadedScripts)); } // Load the map into the secondary simulation LDR_BeginRegistering(); CMapReader* mapReader = new CMapReader; // automatically deletes itself std::string mapType; scriptInterface.GetProperty(m_InitAttributes, "mapType", mapType); if (mapType == "random") { // TODO: support random map scripts debug_warn(L"Serialization test mode does not support random maps"); } else { std::wstring mapFile; scriptInterface.GetProperty(m_InitAttributes, "map", mapFile); VfsPath mapfilename = VfsPath(mapFile).ChangeExtension(L".pmp"); mapReader->LoadMap(mapfilename, scriptInterface.GetJSRuntime(), JS::UndefinedHandleValue, &secondaryTerrain, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &secondaryContext, INVALID_PLAYER, true); // throws exception on failure } LDR_EndRegistering(); ENSURE(LDR_NonprogressiveLoad() == INFO::OK); ENSURE(secondaryComponentManager.DeserializeState(primaryStateBefore.state)); SerializationTestState secondaryStateBefore; ENSURE(secondaryComponentManager.SerializeState(secondaryStateBefore.state)); if (serializationTestDebugDump) ENSURE(secondaryComponentManager.DumpDebugState(secondaryStateBefore.debug, false)); if (serializationTestHash) ENSURE(secondaryComponentManager.ComputeStateHash(secondaryStateBefore.hash, false)); if (primaryStateBefore.state.str() != secondaryStateBefore.state.str() || primaryStateBefore.hash != secondaryStateBefore.hash) { ReportSerializationFailure(&primaryStateBefore, NULL, &secondaryStateBefore, NULL); } SerializationTestState primaryStateAfter; ENSURE(m_ComponentManager.SerializeState(primaryStateAfter.state)); if (serializationTestHash) ENSURE(m_ComponentManager.ComputeStateHash(primaryStateAfter.hash, false)); UpdateComponents(secondaryContext, turnLengthFixed, CloneCommandsFromOtherContext(scriptInterface, secondaryComponentManager.GetScriptInterface(), commands)); SerializationTestState secondaryStateAfter; ENSURE(secondaryComponentManager.SerializeState(secondaryStateAfter.state)); if (serializationTestHash) ENSURE(secondaryComponentManager.ComputeStateHash(secondaryStateAfter.hash, false)); if (primaryStateAfter.state.str() != secondaryStateAfter.state.str() || primaryStateAfter.hash != secondaryStateAfter.hash) { // Only do the (slow) dumping now we know we're going to need to report it ENSURE(m_ComponentManager.DumpDebugState(primaryStateAfter.debug, false)); ENSURE(secondaryComponentManager.DumpDebugState(secondaryStateAfter.debug, false)); ReportSerializationFailure(&primaryStateBefore, &primaryStateAfter, &secondaryStateBefore, &secondaryStateAfter); } } // if (m_TurnNumber == 0) // m_ComponentManager.GetScriptInterface().DumpHeap(); // Run the GC occasionally // No delay because a lot of garbage accumulates in one turn and in non-visual replays there are // much more turns in the same time than in normal games. // Every 500 turns we run a shrinking GC, which decommits unused memory and frees all JIT code. // Based on testing, this seems to be a good compromise between memory usage and performance. // Also check the comment about gcPreserveCode in the ScriptInterface code and this forum topic: // http://www.wildfiregames.com/forum/index.php?showtopic=18466&p=300323 // // (TODO: we ought to schedule this for a frame where we're not // running the sim update, to spread the load) if (m_TurnNumber % 500 == 0) scriptInterface.GetRuntime()->ShrinkingGC(); else scriptInterface.GetRuntime()->MaybeIncrementalGC(0.0f); if (m_EnableOOSLog) DumpState(); // Start computing AI for the next turn CmpPtr<ICmpAIManager> cmpAIManager(m_SimContext, SYSTEM_ENTITY); if (cmpAIManager) cmpAIManager->StartComputation(); ++m_TurnNumber; }
void MoveableEntity::Update() { UpdateComponents(); }