void WBCompEldEndgameCounter::SetHUDHidden( const bool Hidden ) const { UIManager* const pUIManager = GetFramework()->GetUIManager(); ASSERT( pUIManager ); STATIC_HASHED_STRING( HUD ); STATIC_HASHED_STRING( EndgameImg ); STATIC_HASHED_STRING( EndgameCounter ); { WB_MAKE_EVENT( SetWidgetHidden, GetEntity() ); WB_SET_AUTO( SetWidgetHidden, Hash, Screen, sHUD ); WB_SET_AUTO( SetWidgetHidden, Hash, Widget, sEndgameImg ); WB_SET_AUTO( SetWidgetHidden, Bool, Hidden, Hidden ); WB_DISPATCH_EVENT( GetEventManager(), SetWidgetHidden, pUIManager ); } { WB_MAKE_EVENT( SetWidgetHidden, GetEntity() ); WB_SET_AUTO( SetWidgetHidden, Hash, Screen, sHUD ); WB_SET_AUTO( SetWidgetHidden, Hash, Widget, sEndgameCounter ); WB_SET_AUTO( SetWidgetHidden, Bool, Hidden, Hidden ); WB_DISPATCH_EVENT( GetEventManager(), SetWidgetHidden, pUIManager ); } }
void WBCompEldFrobbable::SetHUDHidden(const bool Hidden) const { UIManager* const pUIManager = GetFramework()->GetUIManager(); ASSERT(pUIManager); STATIC_HASHED_STRING(HUD); STATIC_HASHED_STRING(FrobName); STATIC_HASHED_STRING(FrobVerb); STATIC_HASHED_STRING(FrobHold); { WB_MAKE_EVENT(SetWidgetHidden, GetEntity()); WB_SET_AUTO(SetWidgetHidden, Hash, Screen, sHUD); WB_SET_AUTO(SetWidgetHidden, Hash, Widget, sFrobName); WB_SET_AUTO(SetWidgetHidden, Bool, Hidden, Hidden); WB_DISPATCH_EVENT(GetEventManager(), SetWidgetHidden, pUIManager); } { WB_MAKE_EVENT(SetWidgetHidden, GetEntity()); WB_SET_AUTO(SetWidgetHidden, Hash, Screen, sHUD); WB_SET_AUTO(SetWidgetHidden, Hash, Widget, sFrobVerb); WB_SET_AUTO(SetWidgetHidden, Bool, Hidden, Hidden); WB_DISPATCH_EVENT(GetEventManager(), SetWidgetHidden, pUIManager); } { WB_MAKE_EVENT(SetWidgetHidden, GetEntity()); WB_SET_AUTO(SetWidgetHidden, Hash, Screen, sHUD); WB_SET_AUTO(SetWidgetHidden, Hash, Widget, sFrobHold); WB_SET_AUTO(SetWidgetHidden, Bool, Hidden, Hidden || !m_HoldReleaseMode); WB_DISPATCH_EVENT(GetEventManager(), SetWidgetHidden, pUIManager); } }
void WBCompEldWallet::AddMoney(const uint Money, const bool ShowPickupScreen) { m_Money = Min(m_Money + Money, m_Limit); PublishToHUD(); if (ShowPickupScreen) { // Show the money pickup screen and hide it after some time STATICHASH(MoneyPickup); STATICHASH(Money); ConfigManager::SetInt(sMoney, Money, sMoneyPickup); STATIC_HASHED_STRING(MoneyPickupScreen); { WB_MAKE_EVENT(PushUIScreen, NULL); WB_SET_AUTO(PushUIScreen, Hash, Screen, sMoneyPickupScreen); WB_DISPATCH_EVENT(GetEventManager(), PushUIScreen, NULL); } { // Remove previously queued hide event if any GetEventManager()->UnqueueEvent(m_HidePickupScreenUID); WB_MAKE_EVENT(RemoveUIScreen, NULL); WB_SET_AUTO(RemoveUIScreen, Hash, Screen, sMoneyPickupScreen); m_HidePickupScreenUID = WB_QUEUE_EVENT_DELAY( GetEventManager(), RemoveUIScreen, NULL, m_HidePickupScreenDelay); } } }
void WBCompEldPickup::GiveItemTo(WBEntity* const pEntity) const { // Because Pickup is now unfortunately doubling as a Purchaseable. // This is such a hack. // TODO: Make a separate Purchaseable component. if (m_GiveItemDef == "") { // OnObtained is fired whether purchased, stolen, or given WB_MAKE_EVENT(OnObtained, GetEntity()); WB_SET_AUTO(OnObtained, Entity, Buyer, pEntity); WB_DISPATCH_EVENT(GetEventManager(), OnObtained, GetEntity()); return; } DEVASSERT(pEntity); WBCompEldInventory* const pInventory = GET_WBCOMP(pEntity, EldInventory); ASSERT(pInventory); WBEntity* const pGivenEntity = WBWorld::GetInstance()->CreateEntity(m_GiveItemDef); ASSERT(pGivenEntity); pInventory->AddItem(pGivenEntity); WB_MAKE_EVENT(OnItemGiven, GetEntity()); WB_SET_AUTO(OnItemGiven, Entity, GivenTo, pEntity); WB_DISPATCH_EVENT(GetEventManager(), OnItemGiven, GetEntity()); GetEntity()->Destroy(); }
void WBCompEldHands::ShowHands() const { WB_MAKE_EVENT( Show, GetEntity() ); WB_DISPATCH_EVENT( GetEventManager(), Show, GetRightHand() ); WB_DISPATCH_EVENT( GetEventManager(), Show, GetLeftHand() ); WB_DISPATCH_EVENT( GetEventManager(), Show, GetItemInRightHand() ); WB_DISPATCH_EVENT( GetEventManager(), Show, GetItemInLeftHand() ); }
WBCompEldHUDMarker::~WBCompEldHUDMarker() { WBEventManager* const pEventManager = GetEventManager(); if( pEventManager ) { STATIC_HASHED_STRING( OnCameraTicked ); GetEventManager()->RemoveObserver( sOnCameraTicked, this ); } }
WBCompEldAnchor::WBCompEldAnchor() : m_IsAnchored( false ) , m_AnchorPoint() , m_AnchorDirection() { STATIC_HASHED_STRING( OnWorldChanged ); GetEventManager()->AddObserver( sOnWorldChanged, this ); STATIC_HASHED_STRING( OnStaticCollisionChanged ); GetEventManager()->AddObserver( sOnStaticCollisionChanged, this ); }
void Framework3D::ResetRenderer() { XTRACE_FUNCTION; if (m_Renderer->Reset()) { // TODO: RefreshDisplay also resets the renderer--could that be problematic? WB_MAKE_EVENT(RefreshDisplay, NULL); WB_DISPATCH_EVENT(GetEventManager(), RefreshDisplay, this); } else { // Defer the command WB_MAKE_EVENT(ResetRenderer, NULL); WB_QUEUE_EVENT(GetEventManager(), ResetRenderer, this); } }
/*virtual*/ void WBCompEldHard::HandleEvent( const WBEvent& Event ) { XTRACE_FUNCTION; Super::HandleEvent( Event ); STATIC_HASHED_STRING( SetHard ); STATIC_HASHED_STRING( PushPersistence ); STATIC_HASHED_STRING( PullPersistence ); const HashedString EventName = Event.GetEventName(); if( EventName == sSetHard ) { m_Hard = true; // Broadcast event to everything with an EldHardListener component. WB_MAKE_EVENT( NotifyHardModeSet, NULL ); WB_DISPATCH_EVENT( GetEventManager(), NotifyHardModeSet, NULL ); } else if( EventName == sPushPersistence ) { PushPersistence(); } else if( EventName == sPullPersistence ) { PullPersistence(); } }
WBCompEldSensorTheft::~WBCompEldSensorTheft() { WBEventManager* const pEventManager = GetEventManager(); if (pEventManager) { STATIC_HASHED_STRING(OnTheft); pEventManager->RemoveObserver(sOnTheft, this); } }
WBCompEldSleeper::~WBCompEldSleeper() { WBEventManager* const pEventManager = GetEventManager(); if (pEventManager) { STATIC_HASHED_STRING(OnAINoise); pEventManager->RemoveObserver(sOnAINoise, this); } }
void WBCompEldWatson::TickActivated() { if( !EldritchGame::IsPlayerAlive() ) { // Player can't cause Watson to prime when dead return; } if( !EldritchGame::IsPlayerVisible() ) { // Player can't cause Watson to prime when invisible return; } // Don't check min distance, because we don't want to re-prime right after an attack. if( IsPlayerVulnerable( false ) ) { return; } // We're activated and the player has (probably) seen us. Primed for attack. m_Primed = true; WB_MAKE_EVENT( OnWatsonPrimed, GetEntity() ); WB_DISPATCH_EVENT( GetEventManager(), OnWatsonPrimed, GetEntity() ); }
WBCompEldRope::WBCompEldRope() : m_CollisionFatten(0.0f), m_MeshFatten(0.0f), m_EndpointSpacing(0.0f), m_AnchorDepth(0.0f), m_HookLength(0.0f), m_DangleHeight(0.0f), m_HookEntity(""), m_Anchor(), m_Dropped(false) { STATIC_HASHED_STRING(OnWorldChanged); GetEventManager()->AddObserver(sOnWorldChanged, this); STATIC_HASHED_STRING(OnStaticCollisionChanged); GetEventManager()->AddObserver(sOnStaticCollisionChanged, this); }
void WBCompEldPickup::NotifyTheftBy(WBEntity* const pEntity) const { DEVASSERT(pEntity); { WB_MAKE_EVENT(OnTheft, GetEntity()); WB_SET_AUTO(OnTheft, Entity, Thief, pEntity); WB_DISPATCH_EVENT(GetEventManager(), OnTheft, GetEntity()); } { // OnObtained is fired whether purchased, stolen, or given WB_MAKE_EVENT(OnObtained, GetEntity()); WB_SET_AUTO(OnObtained, Entity, Buyer, pEntity); WB_DISPATCH_EVENT(GetEventManager(), OnObtained, GetEntity()); } }
void WBCompEldHUDMarker::UpdateMarkerPosition() const { WBEntity* const pEntity = GetEntity(); WBCompEldTransform* const pTransform = pEntity->GetTransformComponent<WBCompEldTransform>(); EldritchWorld* const pWorld = GetWorld(); const View* const pView = GetFramework()->GetMainView(); Vector Location = pTransform->GetLocation(); Location.z += m_OffsetZ; const Vector& ViewLocation = pView->m_Location; const Vector2 ScreenLocation = pView->ProjectAndClipToScreen( Location ); CollisionInfo Info; Info.m_CollideWorld = true; Info.m_CollideEntities = true; Info.m_CollidingEntity = pEntity; Info.m_UserFlags = EECF_Occlusion; Info.m_StopAtAnyCollision = true; const bool Occluded = pWorld->LineCheck( ViewLocation, Location, Info ); const float Distance = ( Location - ViewLocation ).Length(); const float Alpha = Occluded ? Attenuate( Distance, m_FalloffRadius ) : 1.0f; { WB_MAKE_EVENT( SetWidgetImage, NULL ); WB_SET_AUTO( SetWidgetImage, Hash, Screen, m_UIScreenName ); WB_SET_AUTO( SetWidgetImage, Hash, Widget, m_UIWidgetName ); WB_SET_AUTO( SetWidgetImage, Hash, Image, Occluded ? m_OccludedImage : m_UnoccludedImage ); WB_DISPATCH_EVENT( GetEventManager(), SetWidgetImage, NULL ); } { WB_MAKE_EVENT( SetWidgetLocation, NULL ); WB_SET_AUTO( SetWidgetLocation, Hash, Screen, m_UIScreenName ); WB_SET_AUTO( SetWidgetLocation, Hash, Widget, m_UIWidgetName ); WB_SET_AUTO( SetWidgetLocation, Float, X, ScreenLocation.x ); WB_SET_AUTO( SetWidgetLocation, Float, Y, ScreenLocation.y ); WB_DISPATCH_EVENT( GetEventManager(), SetWidgetLocation, NULL ); } { WB_MAKE_EVENT( SetWidgetAlpha, NULL ); WB_SET_AUTO( SetWidgetAlpha, Hash, Screen, m_UIScreenName ); WB_SET_AUTO( SetWidgetAlpha, Hash, Widget, m_UIWidgetName ); WB_SET_AUTO( SetWidgetAlpha, Float, Alpha, Alpha ); WB_DISPATCH_EVENT( GetEventManager(), SetWidgetAlpha, NULL ); } }
void RodinBTNodeWaitForEvent::OnStart() { RodinBTNode::OnStart(); // Currently, I'm only listening for events on this entity. GetEventManager()->AddObserver(m_Rule.GetEvent(), this, GetEntity()); m_BehaviorTree->Sleep(this); }
void WBCompEldAnchor::Unanchor() { ASSERT( m_IsAnchored ); m_IsAnchored = false; WB_MAKE_EVENT( OnUnanchored, GetEntity() ); WB_DISPATCH_EVENT( GetEventManager(), OnUnanchored, GetEntity() ); }
WBCompEldHands::~WBCompEldHands() { WBEventManager* const pEventManager = GetEventManager(); if( pEventManager ) { STATIC_HASHED_STRING( OnWorldLoaded ); pEventManager->RemoveObserver( sOnWorldLoaded, this ); } }
CProjectStatistic::CProjectStatistic(const CBSLProjectStatistic& bslProjectStatistic) : CObject(), CBSLProjectStatistic() { CObjectLocker olLock(this); *this = bslProjectStatistic; SetProjectStatisticHandle(this); GetEventManager()->FireEvent(wxEVT_BSLPROJECTSTATISTIC_ADD, GetHostHandle(), GetProjectStatisticHandle()); }
void RodinBTNodeWaitForEvent::OnFinish() { RodinBTNode::OnFinish(); // Currently, I'm only listening for events on this entity. GetEventManager()->RemoveObserver(m_Rule.GetEvent(), this, GetEntity()); if (m_IsSleeping) { m_BehaviorTree->Wake(this); } }
int NetMgrEventHandler::Open() { LOG_DEBUG("open event handlers, client:[%s]", _peerAddr.ToString().c_str()); _sendbuffer.Clear(); _recvbuffer.Clear(); timeval tv = {_networkOption->timeout/1000, _networkOption->timeout%1000*1000}; return GetEventManager()->RegisterHandler(base::ReadMask, this, &tv); }
void WBCompEldSleeper::Wake() { if (m_IsAwake) { return; } m_IsAwake = true; WB_MAKE_EVENT(OnWoken, GetEntity()); WB_DISPATCH_EVENT(GetEventManager(), OnWoken, GetEntity()); }
WBCompEldRope::~WBCompEldRope() { WBEventManager* const pEventManager = GetEventManager(); if (pEventManager) { STATIC_HASHED_STRING(OnWorldChanged); pEventManager->RemoveObserver(sOnWorldChanged, this); STATIC_HASHED_STRING(OnStaticCollisionChanged); pEventManager->RemoveObserver(sOnStaticCollisionChanged, this); } }
CNotification::CNotification(const CBSLNotification& bslNotification) : CObject(), CBSLNotification() { CObjectLocker olLock(this); *this = bslNotification; SetNotificationHandle(this); GetEventManager()->FireEvent(wxEVT_BSLNOTIFICATION_ADD, GetHostHandle(), GetNotificationHandle()); }
void WBCompEldPickup::SellItemTo( WBEntity* const pEntity ) { DEVASSERT( pEntity ); sm_PurchasePickup = this; sm_Purchaser = pEntity; WBCompEldWallet* const pWallet = GET_WBCOMP( pEntity, EldWallet ); ASSERT( pWallet ); const bool CanAfford = ( pWallet->GetMoney() >= m_Price ); STATICHASH( Purchase ); STATICHASH( NameTag ); ConfigManager::SetString( sNameTag, m_FriendlyName.CStr(), sPurchase ); STATICHASH( ItemDesc ); ConfigManager::SetString( sItemDesc, m_FriendlyDesc.CStr(), sPurchase ); STATICHASH( PriceTag ); ConfigManager::SetInt( sPriceTag, m_Price, sPurchase ); STATIC_HASHED_STRING( PurchaseScreen ); STATIC_HASHED_STRING( PurchaseBuyButton ); // Disable the buy button if the price is too high { WB_MAKE_EVENT( SetWidgetDisabled, GetEntity() ); WB_SET_AUTO( SetWidgetDisabled, Hash, Screen, sPurchaseScreen ); WB_SET_AUTO( SetWidgetDisabled, Hash, Widget, sPurchaseBuyButton ); WB_SET_AUTO( SetWidgetDisabled, Bool, Disabled, !CanAfford ); WB_DISPATCH_EVENT( GetEventManager(), SetWidgetDisabled, NULL ); } // Show the purchase screen { WB_MAKE_EVENT( PushUIScreen, GetEntity() ); WB_SET_AUTO( PushUIScreen, Hash, Screen, sPurchaseScreen ); WB_DISPATCH_EVENT( GetEventManager(), PushUIScreen, NULL ); } }
void GameApplication::Initialize(float width, float height) { m_ScreenWidth = width; m_ScreenHeight = height; // initialize physics m_Physics->Initialize(); // initialize renderer m_Renderer->Initialize(); m_Scene->GetCamera()->SetProjection(width, height, 0.0, 50.0f); // has to be initialized first as its projection is also used by GUI menus // Load default placeholder textures/shaders before loading level ResourceManager::GetInstance()->LoadShader("sprite", "shaders/sprite.vs", "shaders/sprite.frag")->SetInteger("EnableLighting", 1, true); ResourceManager::GetInstance()->LoadTexture("specular", "textures/specular.png"); ResourceManager::GetInstance()->LoadTexture("normal", "textures/normal.png"); // register for global game event EventListenerDelegate eventListener = fastdelegate::MakeDelegate(this, &GameApplication::OnStartLevel); GetEventManager()->AddListener(eventListener, Event_StartLevel::s_EventType); eventListener = fastdelegate::MakeDelegate(this, &GameApplication::OnQuitGame); GetEventManager()->AddListener(eventListener, Event_QuitGame::s_EventType); eventListener = fastdelegate::MakeDelegate(this, &GameApplication::OnDestroyActor); GetEventManager()->AddListener(eventListener, Event_DestroyActor::s_EventType); // load font(s) and initialize text-renderer std::shared_ptr<Font> font = ResourceManager::GetInstance()->LoadFont("gui/font.fnt"); m_TextRenderer->Initialize(font); // initialize audio m_Audio->PreLoad(); // initialize GUI m_GUIContainers["main_menu"] = std::shared_ptr<GUIContainer>(new GUIMainMenu); m_GUIContainers["scene_intro"] = std::shared_ptr<GUISceneIntro>(new GUISceneIntro); m_GUIContainers["game_menu"] = std::shared_ptr<GUIGameMenu>(new GUIGameMenu); for(auto it = m_GUIContainers.begin(); it != m_GUIContainers.end(); ++it) it->second->Init(); // Start game in main menu SwitchState(GameState::GAME_MAIN_MENU); }
WBCompEldHUDMarker::WBCompEldHUDMarker() : m_UIScreenName() , m_UIWidgetName() , m_OccludedImage() , m_UnoccludedImage() , m_FalloffRadius( 0.0f ) , m_OffsetZ( 0.0f ) { STATIC_HASHED_STRING( OnCameraTicked ); GetEventManager()->AddObserver( sOnCameraTicked, this ); }
CNotification& CNotification::operator= (const CBSLNotification& bslNotification) { CObjectLocker olLock(this); CBSLNotification::operator=(bslNotification); SetNotificationHandle(this); UpdateLastModified(); GetEventManager()->FireEvent(wxEVT_BSLNOTIFICATION_UPDATE, GetHostHandle(), GetNotificationHandle()); return *this; }
void WBCompEldHands::SetHandMeshes( const SimpleString& LeftHandMesh, const SimpleString& LeftHandTexture, const SimpleString& RightHandMesh, const SimpleString& RightHandTexture ) const { { WB_MAKE_EVENT( SetMesh, GetEntity() ); WB_SET_AUTO( SetMesh, Hash, Mesh, LeftHandMesh ); WB_SET_AUTO( SetMesh, Hash, Texture, LeftHandTexture ); WB_DISPATCH_EVENT( GetEventManager(), SetMesh, GetLeftHand() ); } { WB_MAKE_EVENT( SetMesh, GetEntity() ); WB_SET_AUTO( SetMesh, Hash, Mesh, RightHandMesh ); WB_SET_AUTO( SetMesh, Hash, Texture, RightHandTexture ); WB_DISPATCH_EVENT( GetEventManager(), SetMesh, GetRightHand() ); } }
CProjectStatistic& CProjectStatistic::operator= (const CBSLProjectStatistic& bslProjectStatistic) { CObjectLocker olLock(this); CBSLProjectStatistic::operator=(bslProjectStatistic); SetProjectStatisticHandle(this); UpdateLastModified(); GetEventManager()->FireEvent(wxEVT_BSLPROJECTSTATISTIC_UPDATE, GetHostHandle(), GetProjectStatisticHandle()); return *this; }