void CreateTreeTool::doPress(int x, int y, int flags, float pressure) { Vector3 from; if (!m_view->traceWorld(x, y, from, SelectPart::All)) { return; } m_actor = new SpeedTree(); m_view->getContext()->setSelection(m_actor); m_actor->setProperty("tree", m_mapContext->getMapState()->treeFilename); if (m_mapContext->getMapState()->isSnapToGrid) { from = Internal::snap(from, m_mapContext->getMapState()->snapToGrid); } m_actor->bindToGame(); GroupHis* grouphis = new GroupHis(m_context, "Create SpeedTree"); ActorList actorlist; actorlist.push_back(m_actor); UndeleteHis* undelhis = new UndeleteHis(m_context, "Create SpeedTree", actorlist); History* selhis = m_view->getContext()->setSelectionHistoried(actorlist); grouphis->append(undelhis); grouphis->append(selhis); m_context->addHistory(grouphis); doDrag(x, y, flags, pressure); }
void LayersManager::deleteLayer(VirtualDataSceneBase::ActorBase* layerActor, bool deleteChild) { osg::Node* layerNode = dynamic_cast<osg::Node*>(layerActor); if (layerActor->isInstanceOf(CLASS_ENTERPRISELAYER)) { _root->removeChild(layerNode); _enterpriseList.erase(std::find(_enterpriseList.begin(), _enterpriseList.end(), layerNode)); } else { VirtualDataSceneKernel::SingleLayerActor* ppLayer = dynamic_cast<VirtualDataSceneKernel::SingleLayerActor*>(layerNode->getParent(0)); if (!deleteChild) { ActorList returnValue; VirtualDataSceneKernel::DeviceGroup* parent = dynamic_cast<VirtualDataSceneKernel::DeviceGroup*>(layerActor); parent->getAllChildren(returnValue, CLASS_DEVICE); osg::ref_ptr<osg::Node> everyObj; for (unsigned int i = 0; i < returnValue.size(); ++i) { everyObj = dynamic_cast<osg::Node*>(returnValue.at(i)); parent->removeChild(everyObj); ppLayer->addChild(everyObj); } } dynamic_cast<VirtualDataSceneKernel::SingleLayerActor*>(layerActor)->mandatoryUnLoadNode(); ppLayer->removeChild(dynamic_cast<osg::Node*>(layerActor)); } }
void CreateEntityTool::doPress(int x, int y, int flags, float pressure) { Vector3 from; if (!m_view->traceWorld(x, y, from, SelectPart::All)) { return; } m_actor = new Entity(m_mapContext->getMapState()->entityClass); if (m_mapContext->getMapState()->isSnapToGrid) { from = Internal::snap(from, m_mapContext->getMapState()->snapToGrid); } m_actor->getGameEntity()->autoGenerateName(); m_actor->setOrigin(from); m_actor->bindToGame(); GroupHis* grouphis = new GroupHis(m_context, "Create Entity"); ActorList actorlist; actorlist.push_back(m_actor); UndeleteHis* undelhis = new UndeleteHis(m_context, "Create Entity", actorlist); History* selhis = m_view->getContext()->setSelectionHistoried(actorlist); grouphis->append(undelhis); grouphis->append(selhis); m_context->addHistory(grouphis); }
void LayersManager::loadInLayer(VirtualDataSceneBase::TransformableActor* layer, StringList loadExclusionList, StringList unLoadExclusionList) { if (_loadInLayer == layer) return; unLoadInLayer(unLoadExclusionList); dynamic_cast<SingleLayerActor*>(layer)->mandatoryLoadNodeAsynchronous(loadExclusionList); _loadInLayer = layer; SystemViewContext* currentcontext = getSystemViewContext(this); if (_loadInLayer->isInstanceOf(CLASS_EARTHLAYER)) { currentcontext->_mainViewer->getCamera()->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f)); currentcontext->_mainViewer->getCamera()->setNearFarRatio(1e-9); _root->removeChild(_sceneSky); } else { currentcontext->_mainViewer->getCamera()->setClearColor(osg::Vec4(0.004f, 0.0902f, 0.1804f, 1.0f)); currentcontext->_mainViewer->getCamera()->setNearFarRatio(1e-5); if (!_root->containsNode(_sceneSky)) _root->addChild(_sceneSky); //reset dynamic_cast<SingleLayerActor*>(_loadInLayer.get())->resetZeroTransform(); ActorList childLayerList; dynamic_cast<SingleLayerActor*>(_loadInLayer.get())->getAllChildren(childLayerList, CLASS_LAYER, true, false); for (unsigned int i = 0; i < childLayerList.size(); ++i) { dynamic_cast<SingleLayerActor*>(childLayerList.at(i))->resetDefaultTransform(); } } osg::ref_ptr<UserEventData> userData = new UserEventData(); userData->_eventObject = _loadInLayer.get(); userData->_eventType = UserEventData::LAYERCHANGED; currentcontext->_mainViewer->getEventQueue()->userEvent(userData.get()); }
bool walk( Actor& a, Vec dir ) { auto sgn = [](int x){return x>0? 1 : x<0? -1 : 0;}; Vec newPos = a.pos + Vec( sgn, dir ); ActorList::iterator actorHere = actor_at( newPos ); if( actorHere != actors.end() ) { std::string message( 1, a.image ); bool killed = attack( a, *actorHere ); log( "%c %s %c", a.image, killed? "killed":"hit", actorHere->image ); if( killed ) actors.erase( actorHere ); } else if( map.get(newPos) != '#' ) { a.pos = newPos; } else { return false; } a.cooldown += 25 / a.speed; return true; }
// ---------------------------------------------------------------------------- // bool ActorSelectField::setValue( LPCSTR value ) { CString key( value ); ActorList actors; int curPos = 0; while ( true ) { CString resToken = key.Tokenize( _T(" ,"), curPos ); if ( resToken.IsEmpty() ) break; resToken.MakeUpper(); ActorSelectField::EntryMap::iterator it = m_entries.find( resToken ); if ( it == m_entries.end() ) throw FieldException( "Invalid fixture number %s", (LPCSTR)resToken ); actors.push_back( (*it).second.m_actor ); } if ( actors.size() == 0 ) throw FieldException( "Select at least one fixture" ); if ( actors.size() > 1 && !m_allow_multiple ) throw FieldException( "Select a single fixture" ); m_selected_actors = actors; return InputField::setValue( value ); }
void LayersManager::getViewPointList(const std::string& targetID, ActorRefPtrList& viewPointList, int viewPointType) { ActorList childLayerList; dynamic_cast<SingleLayerActor*>(_loadInLayer.get())->getAllChildren(childLayerList, CLASS_VIEWPOINTDEFINE, false, false); for (unsigned int i = 0; i < childLayerList.size(); ++i) { std::string type = childLayerList.at(i)->getProperty(ACTOR_PROPERTY_VIEWPOINTTYPE)->toString(); std::stringstream ss; ss << viewPointType; if (viewPointType < 0 || type == ss.str()) viewPointList.push_back(dynamic_cast<VirtualDataSceneBase::TransformableActor*>(childLayerList.at(i))); } }
bool GCAddItem::Update(const float ticks) { ActorList partyList = ActorMgr::Instance().GetPartyList(); const std::string leaderName = ActorMgr::Instance().GetActivePlayer().GetStatBlock().GetName(); Item item = ItemDB::Instance().GetItem(m_itemName); //@TODO - better than before, not hard coded to chests, but can I do better? // for instance, still need a way to put the item back in the chest if there is no // room for anyone in the party to hold the item std::stringstream temp; temp << leaderName << " " << m_searchText << "^"; temp << leaderName << " found\n" << item.GetName().c_str() << ".^"; for (unsigned int i = 0; i < partyList.size(); ++i) { if (partyList[i]->GetStatBlock().AddItem(m_itemName)) { if (i == 0) { temp << leaderName << " recieved\n" << m_itemName.c_str() << "."; } else { temp << leaderName << " passed the\n" << m_itemName.c_str() << " to " << partyList[i]->GetStatBlock().GetName() << "."; } break; } if (i >= (partyList.size()-1)) { temp << "But, everyone's hands are full."; } } WindowMgr::Instance().AddDialogueGrp(temp.str()); /* Possible outcomes: DialogueWindow "BOWIE opened the chest.^BOWIE found\nITEM.^BOWIE recieved\nITEM." DialogueWindow "BOWIE opened the chest.^BOWIE found\nITEM.^BOWIE passed the\nITEM to OTHERMEMBER." DialogueWindow "BOWIE opened the chest.^BOWIE found\nITEM.^But, everyone's hands are full." */ return true; }
void Physics::newActors(ActorList const & newActors) { for(ActorList::const_iterator itr = newActors.begin(); itr != newActors.end(); ++itr) { btVector3 vel = (*itr)->initialVel; Physics::MotionState * actorMotion = new Physics::MotionState( btTransform( btQuaternion(0,0,0,1), (*itr)->pos ), *itr); motionStates.push_back( actorMotion ); PhysObject const & physObject = (*itr)->physObject; //grabs physical info about the actor if(physObject.mass != 0) physObject.shape->calculateLocalInertia(physObject.mass, *(physObject.fallInertia) ); //dynamic object so calculate local inertia btRigidBody::btRigidBodyConstructionInfo bodyCI(physObject.mass, actorMotion, physObject.shape, *(physObject.fallInertia) ); //TODO this can be shared so stop recreating btRigidBody * body = new btRigidBody(bodyCI); dynamicsWorld.addRigidBody(body); body->setLinearVelocity(btVector3(vel.getX(),vel.getY(), vel.getZ())); rigidBodies.push_back(body); } }
// ---------------------------------------------------------------------------- // ActorSelectField::ActorSelectField( LPCSTR field_label, Venue* venue, bool include_groups ) : InputField( field_label, "" ), m_venue( venue ), m_allow_multiple( true ) { FixturePtrArray fixtures = venue->getFixtures(); ActorList actors; for ( FixturePtrArray::iterator it=fixtures.begin(); it != fixtures.end(); ++it ) actors.push_back( SceneActor( (*it) ) ); if ( include_groups ) { FixtureGroupPtrArray fixture_groups = m_venue->getFixtureGroups(); for ( FixtureGroupPtrArray:: iterator it=fixture_groups.begin(); it != fixture_groups.end(); ++it ) actors.push_back( SceneActor( venue, (*it) ) ); } ActorPtrArray actor_ptrs; for ( size_t i=0; i < actors.size(); i++) actor_ptrs.push_back( &actors[i] ); init( actor_ptrs, UIDArray() ); }
/* boost::shared_ptr<PhysicsMesh> createConvexMesh(const char *filename, IStorm3D_Model_Object *object) { boost::shared_ptr<PhysicsMesh> mesh(new PhysicsMesh()); MeshData data; data.mesh = mesh; data.object = object; data.filename = filename; meshList.push_back(data); return mesh; } */ boost::shared_ptr<PhysicsActor> createActor(boost::shared_ptr<PhysicsMesh> &mesh, const VC3 &position, const QUAT &rotation, const VC3 &velocity, const VC3 &angularVelocity, float mass, int collisionGroup, int soundGroup) { boost::shared_ptr<PhysicsActor> actor(new PhysicsActor(position, rotation)); physicsActorList.push_back(actor.get()); ActorData data; data.actor = actor; data.mesh = mesh; data.velocity = velocity; data.angularVelocity = angularVelocity; data.mass = mass; data.collisionGroup = collisionGroup; data.soundGroup = soundGroup; actorList.push_back(data); return actor; }
void force_calc() { // Communication step: distribute ghost positions cells_update_ghosts(); // VIRTUAL_SITES pos (and vel for DPD) update for security reason !!! #ifdef VIRTUAL_SITES update_mol_vel_pos(); ghost_communicator(&cell_structure.update_ghost_pos_comm); #endif #if defined(VIRTUAL_SITES_RELATIVE) && defined(LB) // This is on a workaround stage: // When using virtual sites relative and LB at the same time, it is necessary // to reassemble the cell lists after all position updates, also of virtual // particles. if ((lattice_switch & LATTICE_LB) && cell_structure.type == CELL_STRUCTURE_DOMDEC && (!dd.use_vList) ) cells_update_ghosts(); #endif espressoSystemInterface.update(); #ifdef COLLISION_DETECTION prepare_collision_queue(); #endif #ifdef LB_GPU #ifdef SHANCHEN if (lattice_switch & LATTICE_LB_GPU && this_node == 0) lattice_boltzmann_calc_shanchen_gpu(); #endif // SHANCHEN // transfer_momentum_gpu check makes sure the LB fluid doesn't get updated on integrate 0 // this_node==0 makes sure it is the master node where the gpu exists if (lattice_switch & LATTICE_LB_GPU && transfer_momentum_gpu && (this_node == 0) ) lb_calc_particle_lattice_ia_gpu(); #endif // LB_GPU #ifdef ELECTROSTATICS if (iccp3m_initialized && iccp3m_cfg.set_flag) iccp3m_iteration(); #endif init_forces(); for (ActorList::iterator actor = forceActors.begin(); actor != forceActors.end(); ++actor) { (*actor)->computeForces(espressoSystemInterface); #ifdef ROTATION (*actor)->computeTorques(espressoSystemInterface); #endif } calc_long_range_forces(); switch (cell_structure.type) { case CELL_STRUCTURE_LAYERED: layered_calculate_ia(); break; case CELL_STRUCTURE_DOMDEC: if(dd.use_vList) { if (rebuild_verletlist) build_verlet_lists_and_calc_verlet_ia(); else calculate_verlet_ia(); } else calc_link_cell(); break; case CELL_STRUCTURE_NSQUARE: nsq_calculate_ia(); } #ifdef OIF_GLOBAL_FORCES double area_volume[2]; //There are two global quantities that need to be evaluated: object's surface and object's volume. One can add another quantity. area_volume[0] = 0.0; area_volume[1] = 0.0; for (int i=0;i< MAX_OBJECTS_IN_FLUID;i++){ calc_oif_global(area_volume,i); if (fabs(area_volume[0])<1e-100 && fabs(area_volume[1])<1e-100) break; add_oif_global_forces(area_volume,i); } #endif #ifdef IMMERSED_BOUNDARY // Must be done here. Forces need to be ghost-communicated IBM_VolumeConservation(); #endif #ifdef LB if (lattice_switch & LATTICE_LB) calc_particle_lattice_ia() ; #endif #ifdef COMFORCE calc_comforce(); #endif #ifdef METADYNAMICS /* Metadynamics main function */ meta_perform(); #endif #ifdef CUDA copy_forces_from_GPU(); #endif // VIRTUAL_SITES distribute forces #ifdef VIRTUAL_SITES ghost_communicator(&cell_structure.collect_ghost_force_comm); init_forces_ghosts(); distribute_mol_force(); #endif // Communication Step: ghost forces ghost_communicator(&cell_structure.collect_ghost_force_comm); // apply trap forces to trapped molecules #ifdef MOLFORCES calc_and_apply_mol_constraints(); #endif // should be pretty late, since it needs to zero out the total force #ifdef COMFIXED calc_comfixed(); #endif // mark that forces are now up-to-date recalc_forces = 0; }
void energy_calc(double *result) { if (!interactions_sanity_checks()) return; init_energies(&energy); #ifdef CUDA clear_energy_on_GPU(); #endif espressoSystemInterface.update(); // Compute the energies from the energyActors for (ActorList::iterator actor= energyActors.begin(); actor != energyActors.end(); ++actor) (*actor)->computeEnergy(espressoSystemInterface); on_observable_calc(); switch (cell_structure.type) { case CELL_STRUCTURE_LAYERED: layered_calculate_energies(); break; case CELL_STRUCTURE_DOMDEC: if(dd.use_vList) { if (rebuild_verletlist) build_verlet_lists(); calculate_verlet_energies(); } else calculate_link_cell_energies(); break; case CELL_STRUCTURE_NSQUARE: nsq_calculate_energies(); } /* rescale kinetic energy */ energy.data.e[0] /= (2.0*time_step*time_step); calc_long_range_energies(); #ifdef CUDA copy_energy_from_GPU(); #endif /* gather data */ MPI_Reduce(energy.data.e, result, energy.data.n, MPI_DOUBLE, MPI_SUM, 0, comm_cart); if (n_external_potentials > 0) { double* energies = (double*) malloc(n_external_potentials*sizeof(double)); for (int i=0; i<n_external_potentials; i++) { energies[i]=external_potentials[i].energy; } double* energies_sum = (double*) malloc(n_external_potentials*sizeof(double)); MPI_Reduce(energies, energies_sum, n_external_potentials, MPI_DOUBLE, MPI_SUM, 0, comm_cart); for (int i=0; i<n_external_potentials; i++) { external_potentials[i].energy=energies_sum[i]; } free(energies); free(energies_sum); } }
ActorList::iterator actor_at( Vec pos ) { return std::find_if ( actors.begin(), actors.end(), [=](const Actor& n) { return n.pos == pos; } ); }