void Space::TimeStep(float step) { m_frameIndexValid = m_bodyIndexValid = m_sbodyIndexValid = false; // XXX does not need to be done this often CollideFrame(m_rootFrame.Get()); // update frames of reference for (BodyIterator i = m_bodies.begin(); i != m_bodies.end(); ++i) (*i)->UpdateFrame(); // AI acts here, then move all bodies and frames for (BodyIterator i = m_bodies.begin(); i != m_bodies.end(); ++i) (*i)->StaticUpdate(step); m_rootFrame->UpdateOrbitRails(m_game->GetTime(), m_game->GetTimeStep()); for (BodyIterator i = m_bodies.begin(); i != m_bodies.end(); ++i) (*i)->TimeStepUpdate(step); // XXX don't emit events in hyperspace. this is mostly to maintain the // status quo. in particular without this onEnterSystem will fire in the // frame immediately before the player leaves hyperspace and the system is // invalid when Lua goes and queries for it. we need to consider whether // there's anything useful that can be done with events in hyperspace if (m_starSystem) { LuaEvent::Emit(); Pi::luaTimer->Tick(); } UpdateBodies(); }
void Space::Update(double gameTime, double deltaTime) { CollideFrame(m_rootFrame.get()); m_frameUpdateSystem->update(m_entities, m_events, deltaTime); //run static update m_rootFrame->UpdateOrbitRails(gameTime, deltaTime); //run time step updates }
void Space::TimeStep(float step) { m_frameIndexValid = m_bodyIndexValid = m_sbodyIndexValid = false; // XXX does not need to be done this often CollideFrame(m_rootFrame.Get()); // update frames of reference for (BodyIterator i = m_bodies.begin(); i != m_bodies.end(); ++i) (*i)->UpdateFrame(); // AI acts here, then move all bodies and frames for (BodyIterator i = m_bodies.begin(); i != m_bodies.end(); ++i) (*i)->StaticUpdate(step); m_rootFrame->UpdateOrbitRails(m_game->GetTime(), m_game->GetTimeStep()); for (BodyIterator i = m_bodies.begin(); i != m_bodies.end(); ++i) (*i)->TimeStepUpdate(step); // XXX don't emit events in hyperspace. this is mostly to maintain the // status quo. in particular without this onEnterSystem will fire in the // frame immediately before the player leaves hyperspace and the system is // invalid when Lua goes and queries for it. we need to consider whether // there's anything useful that can be done with events in hyperspace if (m_starSystem) { Pi::luaOnEnterSystem->Emit(); Pi::luaOnLeaveSystem->Emit(); Pi::luaOnFrameChanged->Emit(); Pi::luaOnShipHit->Emit(); Pi::luaOnShipCollided->Emit(); Pi::luaOnShipDestroyed->Emit(); Pi::luaOnShipDocked->Emit(); Pi::luaOnShipAlertChanged->Emit(); Pi::luaOnShipUndocked->Emit(); Pi::luaOnShipLanded->Emit(); Pi::luaOnShipTakeOff->Emit(); Pi::luaOnJettison->Emit(); Pi::luaOnCargoUnload->Emit(); Pi::luaOnAICompleted->Emit(); Pi::luaOnCreateBB->Emit(); Pi::luaOnUpdateBB->Emit(); Pi::luaOnShipFlavourChanged->Emit(); Pi::luaOnShipEquipmentChanged->Emit(); Pi::luaOnShipFuelChanged->Emit(); Pi::luaTimer->Tick(); } UpdateBodies(); }
void Space::CollideFrame(Frame *f) { if (f->m_astroBody && (f->m_astroBody->IsType(Object::TERRAINBODY))) { // this is pretty retarded for (BodyIterator i = m_bodies.begin(); i!=m_bodies.end(); ++i) { if ((*i)->GetFrame() != f) continue; if (!(*i)->IsType(Object::DYNAMICBODY)) continue; DynamicBody *dynBody = static_cast<DynamicBody*>(*i); Aabb aabb; dynBody->GetAabb(aabb); const matrix4x4d &trans = dynBody->GetGeom()->GetTransform(); const vector3d aabbCorners[8] = { vector3d(aabb.min.x, aabb.min.y, aabb.min.z), vector3d(aabb.min.x, aabb.min.y, aabb.max.z), vector3d(aabb.min.x, aabb.max.y, aabb.min.z), vector3d(aabb.min.x, aabb.max.y, aabb.max.z), vector3d(aabb.max.x, aabb.min.y, aabb.min.z), vector3d(aabb.max.x, aabb.min.y, aabb.max.z), vector3d(aabb.max.x, aabb.max.y, aabb.min.z), vector3d(aabb.max.x, aabb.max.y, aabb.max.z) }; CollisionContact c; for (int j=0; j<8; j++) { const vector3d &s = aabbCorners[j]; vector3d pos = trans * s; double terrain_height = static_cast<Planet*>(f->m_astroBody)->GetTerrainHeight(pos.Normalized()); double altitude = pos.Length(); double hitDepth = terrain_height - altitude; if (altitude < terrain_height) { c.pos = pos; c.normal = pos.Normalized(); c.depth = hitDepth; c.userData1 = static_cast<void*>(dynBody); c.userData2 = static_cast<void*>(f->m_astroBody); hitCallback(&c); } } } } f->GetCollisionSpace()->Collide(&hitCallback); for (std::list<Frame*>::iterator i = f->m_children.begin(); i != f->m_children.end(); ++i) { CollideFrame(*i); } }
void Space::CollideFrame(Frame *f) { f->GetCollisionSpace()->Collide(&hitCallback); for (Frame::ChildIterator it = f->BeginChildren(); it != f->EndChildren(); ++it) CollideFrame(*it); }
void Space::CollideFrame(Frame* f) { f->GetCollisionSpace()->Collide(&hitCallback); for (auto child : f->GetChildren()) CollideFrame(child); }