static void UpdateListener( ARRAY8Ptr addr, void **closure ) { struct socklist *s; *closure = NULL; if (addr == NULL) { ARRAY8 tmpaddr; struct in_addr in; #if defined(IPv6) && defined(AF_INET6) struct in6_addr in6 = in6addr_any; tmpaddr.length = sizeof(in6); tmpaddr.data = (CARD8Ptr) &in6; UpdateListener( &tmpaddr, closure ); if (*closure) return; #endif in.s_addr = htonl( INADDR_ANY ); tmpaddr.length = sizeof(in); tmpaddr.data = (CARD8Ptr) ∈ UpdateListener( &tmpaddr, closure ); return; } if (c_request_port == request_port && (s = FindInList( listensocks, addr ))) { *closure = (void *)s; s->ref = 1; return; } if (!(s = CreateSocklistEntry( addr ))) return; if ((s->fd = CreateListeningSocket( s->addr, s->salen )) < 0) { free( s->addr ); free( s ); return; } s->ref = 1; s->next = listensocks; listensocks = s; *closure = (void *)s; }
status_t NotificationManager::UpdateListener(const char* serviceName, uint32 eventMask, NotificationListener& listener) { char buffer[96]; KMessage specifier; specifier.SetTo(buffer, sizeof(buffer), 0); specifier.AddInt32(kEventMaskString, eventMask); return UpdateListener(serviceName, &specifier, listener); }
void DefaultWinInputHandler::VOnUpdate(void) { for(uint i = 0; i < 0xFE; ++i) { if(m_isKeyDown[i]) { InputMessage keymsg; keymsg.button = i; keymsg.message = KEY_DOWN; UpdateListener(keymsg); } } }
void DemoSoundListener::PostUpdate (const NewtonWorld* const world, dFloat timestep) { DemoEntityManager* const scene = (DemoEntityManager*) NewtonWorldGetUserData(world); DemoCamera* const camera = scene->GetCamera(); dMatrix matrix0 (camera->GetCurrentMatrix ()); dMatrix matrix1 (camera->GetNextMatrix ()); dVector veloc ((matrix1.m_posit - matrix0.m_posit).Scale (1.0f / timestep)); //printf ("%f %f %f %f\n", veloc.m_x, veloc.m_y, veloc.m_z, timestepInSecunds); UpdateListener (matrix1.m_posit, veloc, matrix0.m_front, matrix0.m_up); dSoundManager::Update(); }
bool CCheckpointSystem::SaveGame(EntityId checkpointId, const char* fileName) { CRY_ASSERT(fileName); if(!fileName || CHECKPOINT_SAVE_XML_NODE || CHECKPOINT_LOAD_XML_NODE) return false; //set extension FixedCheckpointString file(fileName); SetFilenameExtension(file); CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_COMMENT, "Saving checkpoint %s", file.c_str()); CHECKPOINT_SAVE_XML_NODE = GetISystem()->CreateXmlNode("Checkpoint"); //write checkpoint data SCheckpointData metaData; WriteMetaData(checkpointId, CHECKPOINT_SAVE_XML_NODE, metaData); //actor data // TODO For now, not saving actor info (AI) - If this happens later, support needs to be added for entity pools //WriteActorData(CHECKPOINT_SAVE_XML_NODE); //vehicle data WriteVehicleData(CHECKPOINT_SAVE_XML_NODE); //write game tokens WriteGameTokens(CHECKPOINT_SAVE_XML_NODE); //let game write if (m_pGameHandler) { m_pGameHandler->OnWriteData(CHECKPOINT_SAVE_XML_NODE); } //inform listeners UpdateListener(metaData, true); //write to file WriteXML(CHECKPOINT_SAVE_XML_NODE, file.c_str()); //draw text message on screen //static const ColorF color (0.0f, 0.85f, 0.2f, 1.0f); //g_pGame->GetIGameFramework()->GetIPersistantDebug()->Add2DText("Checkpoint saved", 2.5f, color, 2.0f); CHECKPOINT_SAVE_XML_NODE = NULL; return true; }
void COpenALSound::Update() { for (int a=0;a<maxSounds;a++) { if (Sources[a]) { ALint state; alGetSourcei(Sources[a],AL_SOURCE_STATE, &state); if (state == AL_STOPPED) { alDeleteSources(1,&Sources[a]); Sources[a]=0; } } } CheckError("COpenALSound::Update"); UpdateListener(); }
bool DefaultWinInputHandler::VOnMessage(const MSG& msg) { switch(msg.message) { case WM_MOUSEMOVE: { int posx = GET_X_LPARAM(msg.lParam); int posy = GET_Y_LPARAM(msg.lParam); InputMessage imsg; imsg.mouseX = posx; imsg.mouseY = posy; if(m_isMouseGrabbed) { RECT rc; GetWindowRect(m_hwnd, &rc); int x = (rc.right - rc.left) / 2; int y = (rc.bottom - rc.top) / 2; imsg.mouseDY = posy - y; imsg.mouseDX = posx - x; imsg.message = TBD_MOUSE_MOVED; if(imsg.mouseDX != 0 || imsg.mouseDY != 0) { //add 8 and 30 pixels to compensate borders, TODO SetCursorPos(rc.left + x + m_curserXOffset, rc.top + y + m_curserYOffset); } } else { imsg.mouseDY = posy - m_lastMousePosY; imsg.mouseDX = posx - m_lastMousePosX; imsg.message = TBD_MOUSE_MOVED; m_lastMousePosX = posx; m_lastMousePosY = posy; } if(imsg.mouseDX != 0 || imsg.mouseDY) { UpdateListener(imsg); } } break; case WM_LBUTTONDOWN: { int posx = GET_X_LPARAM(msg.lParam); int posy = GET_Y_LPARAM(msg.lParam); InputMessage imsg; imsg.mouseX = posx; imsg.mouseY = posy; imsg.button = MOUSE_BTN_LEFT; imsg.message = MOUSE_BUTTON_PRESSED; UpdateListener(imsg); } break; case WM_RBUTTONDOWN: { int posx = GET_X_LPARAM(msg.lParam); int posy = GET_Y_LPARAM(msg.lParam); InputMessage imsg; imsg.mouseX = posx; imsg.mouseY = posy; imsg.button = MOUSE_BTN_RIGHT; imsg.message = MOUSE_BUTTON_PRESSED; UpdateListener(imsg); } break; case WM_LBUTTONUP: { int posx = GET_X_LPARAM(msg.lParam); int posy = GET_Y_LPARAM(msg.lParam); InputMessage imsg; imsg.mouseX = posx; imsg.mouseY = posy; imsg.button = MOUSE_BTN_LEFT; imsg.message = MOUSE_BUTTON_RELEASED; UpdateListener(imsg); } break; case WM_RBUTTONUP: { int posx = GET_X_LPARAM(msg.lParam); int posy = GET_Y_LPARAM(msg.lParam); InputMessage imsg; imsg.mouseX = posx; imsg.mouseY = posy; imsg.button = MOUSE_BTN_RIGHT; imsg.message = MOUSE_BUTTON_RELEASED; UpdateListener(imsg); } break; case WM_KEYDOWN: { InputMessage imsg; imsg.button = (uint)msg.wParam; imsg.message = (KF_REPEAT & HIWORD(msg.lParam)) ? KEY_REPEAT : KEY_PRESSED; UpdateListener(imsg); m_isKeyDown[imsg.button] = true; } break; case WM_KEYUP: { InputMessage imsg; imsg.button = (uint)msg.wParam; imsg.message = KEY_RELEASED; UpdateListener(imsg); m_isKeyDown[imsg.button] = false; } break; case WM_MOUSEWHEEL: { int posx = GET_X_LPARAM(msg.lParam); int posy = GET_Y_LPARAM(msg.lParam); InputMessage imsg; imsg.mouseX = posx; imsg.mouseY = posy; imsg.message = MOUSE_WHEEL; imsg.mouseWheelDelta = GET_WHEEL_DELTA_WPARAM(msg.wParam); UpdateListener(imsg); } break; } return true; }
int KRLLocalCharacter::Update(double fTime, double fTimeLast, DWORD dwGameLoop, BOOL bFrame) { int nRetCode = false; int nResult = false; HRESULT hr = E_FAIL; RL_ANIMATION_UP nAnimationUp = RL_ANIMATION_UP_NONE; RL_ANIMATION_DOWN nAnimationDown = RL_ANIMATION_DOWN_NONE; RL_ADVANCE nAdvance = RL_ADVANCE_FORWARD; ASSERT(!m_RLCharacter.IsFadeOut()); if (m_RLCharacter.m_RenderData.HasLoadedMDL()) { if (bFrame) { m_RLCharacter.m_FrameData.UpdateRepresentFrameData(TRUE); if (m_bSheath != m_RLCharacter.m_FrameData.m_Current.bSheathFlag) { m_bSheath = m_RLCharacter.m_FrameData.m_Current.bSheathFlag; m_RLCharacter.UpdateSheath(m_bSheath); } } nRetCode = m_RLCharacter.m_FrameData.Interpolate(m_RLCharacter.m_RenderData.IsVisible(), false); KGLOG_PROCESS_ERROR(nRetCode); nRetCode = UpdatePosition(); KGLOG_PROCESS_ERROR(nRetCode); nRetCode = UpdateDirection(); KGLOG_PROCESS_ERROR(nRetCode); nAnimationDown = GetRLAnimationDown( m_RLCharacter.m_FrameData.m_Current.nMoveState, m_RLCharacter.m_FrameData.m_Current.nOTAction, m_RLCharacter.m_FrameData.m_Current.nJumpCount, m_nTurning); nAdvance = GetAdvance(nAnimationDown); nRetCode = UpdateListener(); KGLOG_PROCESS_ERROR(nRetCode); if (bFrame) { if (m_RLCharacter.m_bAnimationPaused && nAnimationDown != RL_ANIMATION_DOWN_FREEZE) m_RLCharacter.PauseAnimation(FALSE); nAnimationUp = GetRLAnimationUp(m_RLCharacter.m_FrameData.m_Current.nOTAction); if (nAnimationUp == RL_ANIMATION_UP_NONE && m_nAnimationUp != RL_ANIMATION_UP_NONE || nAnimationUp != RL_ANIMATION_UP_NONE) { nRetCode = m_RLCharacter.UpdateAnimationUp(nAnimationUp); KGLOG_PROCESS_ERROR(nRetCode); m_nAnimationUp = nAnimationUp; } nRetCode = m_RLCharacter.UpdateVehicle( m_RLCharacter.m_FrameData.m_Current.nVehicleTrack, FALSE); KGLOG_PROCESS_ERROR(nRetCode); nRetCode = m_RLCharacter.UpdateAnimationDown(nAnimationDown, nAdvance, m_RLCharacter.m_FrameData.m_Current.nFightFlag, m_RLCharacter.m_FrameData.m_Current.dwSkillBuffs); KGLOG_PROCESS_ERROR(nRetCode); UpdateLifeState(); UpdateAnimationSpeed(nAnimationDown, nAdvance); if (m_dwLockControlFrame > 0) { --m_dwLockControlFrame; } hr = m_RLCharacter.m_RenderData.Update(); KGLOG_COM_PROCESS_ERROR(hr); } } nResult = true; Exit0: return nResult; }
bool CCheckpointSystem::LoadGame(const char* fileName) { //make sure not not save/load recursively or multiple times at once if(CHECKPOINT_SAVE_XML_NODE || CHECKPOINT_LOAD_XML_NODE) return false; //set extension FixedCheckpointString file(fileName); SetFilenameExtension(file); CHECKPOINT_LOAD_XML_NODE = ReadXML(file.c_str()); if(!CHECKPOINT_LOAD_XML_NODE) return false; CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_COMMENT, "Loading checkpoint %s", file.c_str()); //check for EntityId errors CHECKPOINT_RESAVE_NECESSARY = false; //process meta data SCheckpointData metaData; if(!ReadMetaData(CHECKPOINT_LOAD_XML_NODE, metaData)) return false; //check version number if(metaData.m_versionNumber != CHECKPOINT_VERSION_NUMBER) { CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Checkpoint version number (%i) does not match current version (%i). Please reexport all checkpoints of this level to prevent errors!", metaData.m_versionNumber, CHECKPOINT_VERSION_NUMBER); } //check for level mismatch CryFixedStringT<32> curlevelName = CCryAction::GetCryAction()->GetLevelName(); RepairLevelName(curlevelName); if(curlevelName.empty() || stricmp(metaData.m_levelName.c_str(), curlevelName.c_str())) { if(!LoadCheckpointMap(metaData, curlevelName)) return false; } else { //reset the dynamic parts of the engine ResetEngine(); } //read actor data and respawn AI // TODO For now, not restoring actor info (AI) - If this happens later, support needs to be added for entity pools //RespawnAI(CHECKPOINT_LOAD_XML_NODE); //load gametokens again ReadGameTokens(CHECKPOINT_LOAD_XML_NODE); //let game read if (m_pGameHandler) { m_pGameHandler->OnReadData(CHECKPOINT_LOAD_XML_NODE); } //resets some gameplay data like action filters etc. RestartGameplay(); //load external entities, that are controlled by flowgraph LoadExternalEntities(CHECKPOINT_LOAD_XML_NODE); //inform listeners UpdateListener(metaData, false); //trigger flowgraph node OnCheckpointLoaded(metaData); //draw text message on screen //static const ColorF color (0.0f, 0.85f, 0.2f, 1.0f); //g_pGame->GetIGameFramework()->GetIPersistantDebug()->Add2DText("Checkpoint loaded", 2.5f, color, 2.0f); //checkpoint file sanity check if(CHECKPOINT_RESAVE_NECESSARY) { CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Checkpoint file contained obsolete or wrong data, trying to re-save checkpoint."); //resave checkpoint to fix changed entity Ids SaveGame(metaData.m_checkPointId, fileName); //make sure the script entity is aware of the activity OnCheckpointLoaded(metaData); } CHECKPOINT_LOAD_XML_NODE = NULL; //when a checkpoint was loaded, it becomes the most recent checkpoint g_lastSavedCheckpoint = fileName; //make sure the scripts are clean //CXP : this caused a crash after some reloads, which hints to problems in the gamerules script //gEnv->pScriptSystem->ForceGarbageCollection(); return true; }
// Rebuild the sound stage to reflect any recent changes in sound HRESULT DS3DSoundEngine::Update() { HRESULT hr; Vector vectListenerPosition; DWORD dwUpdateTime = timeGetTime(); DWORD dwUpdatePeriod = dwUpdateTime - m_dwLastUpdateTime; // mdvalley: Update no faster than every 30ms if(dwUpdatePeriod < 30) return S_OK; // fire the update event. m_peventsourceUpdate->Trigger(dwUpdatePeriod); typedef std::vector<DSVirtualSoundBuffer*> TempSoundList; // get the current position of the listener, to use for future // calculations. hr = m_plistener->GetPosition(vectListenerPosition); if (ZFailed(hr)) return hr; // Walk the list of active sounds and call update for each one, // removing the sounds which have ended, keeping track of which sounds // have playing buffers TempSoundList listPrevSounds; listPrevSounds.reserve(m_nNumBuffersMax); VirtualSoundList::iterator iterSound; for (iterSound = m_listActiveSounds.begin(); iterSound != m_listActiveSounds.end();) { hr = (*iterSound)->Update(dwUpdatePeriod, vectListenerPosition, m_fRolloffFactor); if (ZFailed(hr)) return hr; // if this is no longer playing, remove it from the list. if ((*iterSound)->IsStopped()) { iterSound = m_listActiveSounds.erase(iterSound); } else { // if the sound has an active buffer, keep track of it. if ((*iterSound)->HasPlayingBuffer()) listPrevSounds.push_back( (TRef<DSVirtualSoundBuffer>)(*iterSound) ); ++iterSound; } } // get the n most important sounds that we wish to play TempSoundList listNewSounds; if (!m_listActiveSounds.empty()) { // create a list of all of the sounds TempSoundList listAllSounds(m_listActiveSounds.size()); std::transform(m_listActiveSounds.begin(), m_listActiveSounds.end(), listAllSounds.begin(), RefToPtr<DSVirtualSoundBuffer>()); // turn it into a priority queue std::make_heap(listAllSounds.begin(), listAllSounds.end(), std::not2(SoundPriorityCompare())); // get the m_nNumBuffersDesired most important sounds by popping // them off of the queue listNewSounds.reserve(m_nNumBuffersDesired); for (int nSound = 0; nSound < min(m_nNumBuffersDesired, listAllSounds.size()); nSound++) { std::pop_heap(listAllSounds.begin(), listAllSounds.end() - nSound, std::not2(SoundPriorityCompare())); DSVirtualSoundBuffer* pbuffer = (*(listAllSounds.end() - nSound - 1)); if (pbuffer->IsAudible()) listNewSounds.push_back(pbuffer); } } // Compare the previously playing sounds and the list of new sounds we // want to play, and start and stop the sound buffers as needed to // achieve this. { // sort the old list by priority std::sort(listPrevSounds.begin(), listPrevSounds.end(), SoundPriorityCompare()); // find the first sound which is not in the new list TempSoundList::iterator iterDead = (listNewSounds.empty()) ? listPrevSounds.begin() : std::find_if(listPrevSounds.begin(), listPrevSounds.end(), std::bind1st(SoundPriorityCompare(), *(listNewSounds.end() - 1))); // stop all of the old buffers // REVIEW: should fade out, if we have buffers. for (; iterDead != listPrevSounds.end(); iterDead++) { hr = (*iterDead)->StopBuffer(); if (ZFailed(hr)) return hr; } // Start any new sounds for (TempSoundList::iterator iterNew = listNewSounds.begin(); iterNew != listNewSounds.end(); ++iterNew) { if (!(*iterNew)->HasPlayingBuffer()) { if(m_pDirectSound8) hr = (*iterNew)->StartBuffer8(m_pDirectSound8, m_quality, m_bAllowHardware); else hr = (*iterNew)->StartBuffer(m_pDirectSound, m_quality, m_bAllowHardware); if (IsSeriousError(hr)) { // Silently fail debugf("Serious error during update while starting sound: %X\n", hr); } } }; } // update the listener's position, velocity, etc., hr = UpdateListener(); if (ZFailed(hr)) return hr; // Commit any and all deferred changes. hr = m_pDSListener->CommitDeferredSettings(); if (ZFailed(hr)) return hr; m_dwLastUpdateTime = dwUpdateTime; return S_OK; }