T* ReplayBufferArray<T>::getNewArray() { if( !isHealthy() ) return NULL; // check, if we need a new block if( m_Buffer.m_number_objects_used == (m_Buffer.m_block_size*m_Buffer.m_number_blocks) ) { // we need a new block if( !m_Buffer.addNewBlock() ) return NULL; } // get current frame T* block_current = m_Buffer.m_pp_blocks[ m_Buffer.m_number_blocks-1 ]; size_t new_in_block_idx = m_Buffer.m_number_objects_used % m_Buffer.m_block_size; T* current = block_current + new_in_block_idx; assert( (current + m_array_size) <= (m_Buffer .m_pp_blocks[ m_Buffer.m_number_blocks-1 ] + m_Buffer.m_block_size) ); m_Buffer.m_number_objects_used += m_array_size; return current; }
bool ReplayBuffers::saveReplayHumanReadable( FILE *fd ) const { if( !isHealthy() ) return false; if( fprintf( fd, "frames: %u\n", getNumberFrames() ) < 1 ) return false; #ifdef REPLAY_SAVE_STATISTIC float time_step_min = 9999999.0f, time_step_max = 0.0f, time_last; #endif unsigned int frame_idx, kart_idx; ReplayFrame const *frame; ReplayKartState const *kart; for( frame_idx = 0; frame_idx < getNumberFrames(); ++frame_idx ) { frame = getFrameAt( frame_idx ); if( fprintf( fd, "frame %u time %f\n", frame_idx, frame->time ) < 1 ) return false; for( kart_idx = 0; kart_idx < m_number_karts; ++kart_idx ) { kart = frame->p_kart_states + kart_idx; if( fprintf( fd, "\tkart %u: %f,%f,%f,%f,%f,%f\n", kart_idx, kart->position.xyz[0], kart->position.xyz[1], kart->position.xyz[2], kart->position.hpr[0], kart->position.hpr[1], kart->position.hpr[2] ) < 1 ) return false; } #ifdef REPLAY_SAVE_STATISTIC if( frame_idx ) { float diff = frame->time - time_last; if( diff < time_step_min ) time_step_min = diff; if( diff > time_step_max ) time_step_max = diff; } time_last = frame->time; #endif } #ifdef REPLAY_SAVE_STATISTIC float time_step_avg; if( getNumberFrames() > 1 ) { time_step_avg = time_last / ( getNumberFrames() - 1 ); } else { time_step_avg = -1.0f; } fprintf( fd, "\n# statistic time-steps:\n# \tmin: %f\n# \tmax: %f\n# \tavg: %f\n", time_step_min, time_step_max, time_step_avg ); #endif return true; }
ReplayFrame* ReplayBuffers::getNewFrame() { // make sure initialization was called properly assert( m_BufferFrame.getNumberObjectsUsed() == m_BufferKartState.getNumberArraysUsed() ); if( !isHealthy() ) return NULL; ReplayFrame* frame = m_BufferFrame.getNewObject(); if( !frame ) return NULL; // get current karts-array ReplayKartState* karts_array = m_BufferKartState.getNewArray(); if( !karts_array ) return NULL; frame->p_kart_states = karts_array; return frame; }
// Get contact // Contact when sick is decreased by a random percentage between 5%-15% int Person::getContact() { if (isHealthy()) { return contact; } else { double tmpContact = contact; tmpContact = tmpContact - tmpContact * (contactSickPct / 100); if (1 > tmpContact) { contact = 1; } else { contact = tmpContact; } return contact; } }
//------------------------------------------------------------------------------ void Cloud::doUpdate( float dt ) { m_life += dt; if ( m_size == 0 ) { setBlack( static_cast<Game *>( Engine::instance()->getContext() )->getBlack() ); } updateDamageable( dt ); if ( m_black ) { m_sprite = Engine::rm()->GetSprite( BLACK[m_size] ); } else { m_sprite = Engine::rm()->GetSprite( WHITE[m_size] ); } if ( isDestroyed() ) { if ( m_size > 0 ) { for ( int i = 0; i < 3; ++i ) { Entity* entity = Engine::em()->factory( Cloud::TYPE ); if ( getBlack() ) { entity->setBlack( 0 ); } else { entity->setBlack( 1 ); } entity->setScale( 0.1f ); static_cast< Cloud * >( entity )->setSize( m_size - 1 ); entity->init(); entity->getBody()->SetXForm( m_body->GetPosition(), m_body->GetAngle() ); } } destroy(); } else if ( isHealthy() && m_size < 4 ) { Entity* entity = Engine::em()->factory( Cloud::TYPE ); if ( getBlack() ) { entity->setBlack( 0 ); } else { entity->setBlack( 1 ); } entity->setScale( 0.1f ); static_cast< Cloud * >( entity )->setSize( m_size + 1 ); entity->init(); entity->getBody()->SetXForm( m_body->GetPosition(), m_body->GetAngle() ); destroy(); } if ( getFriend() ) { b2Vec2 velocity( 0.0f, 0.0f ); m_body->SetAngularVelocity( 0.0f ); m_body->SetLinearVelocity( velocity ); } }