void wxExListViewFile::OnIdle(wxIdleEvent& event) { event.Skip(); if ( !IsShown() || GetItemCount() == 0 || !wxConfigBase::Get()->ReadBool("AllowSync", true)) { return; } if (m_ItemNumber < GetItemCount()) { wxExListItem item(this, m_ItemNumber); if ( item.GetFileName().FileExists() && (item.GetFileName().GetStat().GetModificationTime() != GetItemText(m_ItemNumber, _("Modified")) || item.GetFileName().GetStat().IsReadOnly() != item.IsReadOnly()) ) { item.Update(); wxExLogStatus(item.GetFileName(), STAT_SYNC | STAT_FULLPATH); m_ItemUpdated = true; } m_ItemNumber++; } else { m_ItemNumber = 0; if (m_ItemUpdated) { if (wxConfigBase::Get()->ReadBool("List/SortSync", true)) { SortColumn(_("Modified"), SORT_KEEP); } m_ItemUpdated = false; } } if ( IsShown() && GetItemCount() > 0) { CheckSync(); } }
//! Lecture (à travers le cache). Cache_Error Cache_Read(struct Cache *pcache, int irfile, void *precord) { if(CheckSync(pcache)) Cache_Sync(pcache); int ibfile = (int)(irfile/pcache->nrecords); struct Cache_Block_Header *cbh = NULL; for(struct Cache_Block_Header *h = pcache->headers; h < (pcache->headers + pcache->nblocks); h++) { if(h->ibfile == ibfile && (h->flags & VALID)) { cbh = h; pcache->instrument.n_hits++; break; } } if(!cbh) { cbh = Strategy_Replace_Block(pcache); if(!cbh) cbh = pcache->headers; if(cbh->flags&MODIF) { fseek(pcache->fp, DADDR(pcache, cbh->ibfile), SEEK_SET); fwrite(cbh->data, pcache->blocksz, 1, pcache->fp); } cbh->ibfile = ibfile; cbh->flags = VALID; fseek(pcache->fp, DADDR(pcache, ibfile), SEEK_SET); fread(cbh->data, pcache->blocksz, 1, pcache->fp); } memcpy(precord, ADDR(pcache, irfile, cbh), pcache->recordsz); pcache->instrument.n_reads++; Strategy_Read(pcache, cbh); return CACHE_OK; }
static unsigned Doctor(const char *filename) { if (util::GetExtension(filename) != "mp3") { fprintf(stderr, "Ignoring non-MP3 '%s'\n", filename); return 0; } printf("%s:\n", filename); std::unique_ptr<util::Stream> st; unsigned rc = util::OpenFileStream(filename, util::READ|util::SEQUENTIAL, &st); if (rc) { perror("open"); return rc; } uint64_t sz = st->GetLength(); uint64_t pos = 0; unsigned tail = 0; bool ok = true; /** Look for ID3v2 */ rc = CheckID3v2(st.get(), &pos, &ok); if (rc) return rc; /** Look for sync */ rc = CheckSync(st.get(), &pos, &ok); /** Walk frames */ rc = WalkFrames(st.get(), pos, &ok); if (ok) printf(" OK\n"); return 0; }
void NetworkManager::TryAdvanceTurn() { //only advance the turn IF we received the data for everyone if ( mTurnData[ mTurnNumber + 1 ].size() == mPlayerCount ) { if ( mState == NMS_Delay ) { //throw away any input accrued during delay InputManager::sInstance->ClearCommandList(); mState = NMS_Playing; //wait 100ms to give the slow peer a chance to catch up SDL_Delay( 100 ); } mTurnNumber++; mSubTurnNumber = 0; if ( CheckSync( mTurnData[ mTurnNumber ] ) ) { //process all the moves for this turn for ( auto& iter : mTurnData[ mTurnNumber ] ) { iter.second.GetCommandList().ProcessCommands( iter.first ); } //since we're still in sync, let's check for achievements CheckForAchievements(); } else { //for simplicity, just kill the game if it desyncs LOG( "DESYNC: Game over man, game over." ); Engine::sInstance->SetShouldKeepRunning( false ); } } else { //don't have all player's turn data, we have to delay :( mState = NMS_Delay; LOG( "Going into delay state, don't have all the info for turn %d", mTurnNumber + 1); } }
bool CGameServer::Update() { if(lastPlayerInfo<gu->gameTime-2){ lastPlayerInfo=gu->gameTime; if (game && game->playing) { int firstReal=0; if(gameSetup) firstReal=gameSetup->numDemoPlayers; //send info about the players for(int a=firstReal;a<gs->activePlayers;++a){ if(gs->players[a]->active){ serverNet->SendData<unsigned char, float, int>( NETMSG_PLAYERINFO, a, gs->players[a]->cpuUsage, gs->players[a]->ping); } } //decide new internal speed float maxCpu=0; for(int a=0;a<gs->activePlayers;++a){ if(gs->players[a]->cpuUsage>maxCpu && gs->players[a]->active){ maxCpu=gs->players[a]->cpuUsage; } } if (maxCpu != 0) { float wantedCpu=0.35f+(1-gs->speedFactor/gs->userSpeedFactor)*0.5f; //float speedMod=1+wantedCpu-maxCpu; float newSpeed=gs->speedFactor*wantedCpu/maxCpu; //logOutput.Print("Speed %f %f %f %f",maxCpu,wantedCpu,speedMod,newSpeed); newSpeed=(newSpeed+gs->speedFactor)*0.5f; if(newSpeed>gs->userSpeedFactor) newSpeed=gs->userSpeedFactor; if(newSpeed<0.1f) newSpeed=0.1f; if(newSpeed!=gs->speedFactor) serverNet->SendData<float>(NETMSG_INTERNAL_SPEED, newSpeed); } } } if(!ServerReadNet()){ logOutput.Print("Server read net wanted quit"); return false; } if (game && game->playing && !serverNet->playbackDemo){ CheckSync(); // Send out new frame messages. unsigned currentTick = SDL_GetTicks(); float timeElapsed=((float)(currentTick - lastTick))/1000.f; if(gameEndDetected) gameEndTime+=timeElapsed; // logOutput.Print("float value is %f",timeElapsed); if(gameClientUpdated){ gameClientUpdated=false; maxTimeLeft=2; } if(timeElapsed>maxTimeLeft) timeElapsed=maxTimeLeft; maxTimeLeft-=timeElapsed; timeLeft+=GAME_SPEED*gs->speedFactor*timeElapsed; lastTick=currentTick; while((timeLeft>0) && (!gs->paused || game->bOneStep)){ if(!game->creatingVideo){ game->bOneStep=false; CreateNewFrame(true); } timeLeft--; } } serverNet->Update(); CheckForGameEnd(); return true; }
/***************************************************************************** * Open: initializes ES structures *****************************************************************************/ static int Open( vlc_object_t * p_this ) { demux_t *p_demux = (demux_t*)p_this; demux_sys_t *p_sys; byte_t *p_peek; int i_peek = 0; vlc_bool_t b_big_endian = 0; /* Arbitrary initialisation */ /* Check if we are dealing with a WAV file */ if( stream_Peek( p_demux->s, &p_peek, 12 ) == 12 && !memcmp( p_peek, "RIFF", 4 ) && !memcmp( p_peek + 8, "WAVE", 4 ) ) { int i_size; /* Skip the wave header */ i_peek = 12 + 8; while( stream_Peek( p_demux->s, &p_peek, i_peek ) == i_peek && memcmp( p_peek + i_peek - 8, "data", 4 ) ) { i_peek += GetDWLE( p_peek + i_peek - 4 ) + 8; } /* TODO: should check wave format and sample_rate */ /* Some A52 wav files don't begin with a sync code so we do a more * extensive search */ i_size = stream_Peek( p_demux->s, &p_peek, i_peek + A52_PACKET_SIZE * 2); i_size -= (PCM_FRAME_SIZE + A52_MAX_HEADER_SIZE); while( i_peek < i_size ) { if( CheckSync( p_peek + i_peek, &b_big_endian ) != VLC_SUCCESS ) /* The data is stored in 16 bits words */ i_peek += 2; else { /* Check following sync code */ if( CheckSync( p_peek + i_peek + PCM_FRAME_SIZE, &b_big_endian ) != VLC_SUCCESS ) { i_peek += 2; continue; } break; } } } /* Have a peep at the show. */ if( stream_Peek( p_demux->s, &p_peek, i_peek + A52_MAX_HEADER_SIZE * 2 ) < i_peek + A52_MAX_HEADER_SIZE * 2 ) { /* Stream too short */ msg_Warn( p_demux, "cannot peek()" ); return VLC_EGENERIC; } if( CheckSync( p_peek + i_peek, &b_big_endian ) != VLC_SUCCESS ) { if( strncmp( p_demux->psz_demux, "a52", 3 ) ) { return VLC_EGENERIC; } /* User forced */ msg_Err( p_demux, "this doesn't look like a A52 audio stream, " "continuing anyway" ); } /* Fill p_demux fields */ p_demux->pf_demux = Demux; p_demux->pf_control = Control; p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); p_sys->b_start = VLC_TRUE; p_sys->i_mux_rate = 0; p_sys->b_big_endian = b_big_endian; /* * Load the A52 packetizer */ p_sys->p_packetizer = vlc_object_create( p_demux, VLC_OBJECT_DECODER ); p_sys->p_packetizer->pf_decode_audio = 0; p_sys->p_packetizer->pf_decode_video = 0; p_sys->p_packetizer->pf_decode_sub = 0; p_sys->p_packetizer->pf_packetize = 0; /* Initialization of decoder structure */ es_format_Init( &p_sys->p_packetizer->fmt_in, AUDIO_ES, VLC_FOURCC( 'a', '5', '2', ' ' ) ); p_sys->p_packetizer->p_module = module_Need( p_sys->p_packetizer, "packetizer", NULL, 0 ); if( !p_sys->p_packetizer->p_module ) { msg_Err( p_demux, "cannot find A52 packetizer" ); return VLC_EGENERIC; } /* Create one program */ p_sys->p_es = es_out_Add( p_demux->out, &p_sys->p_packetizer->fmt_in ); return VLC_SUCCESS; }