static duk_ret_t Component_SetProperty(duk_context* ctx) { /* 'this' binding: handler * [0]: target * [1]: key * [2]: val * [3]: receiver (proxy) */ const char* attrName = duk_to_string(ctx, 1); if (attrName && attrName[0] >= 'a' && attrName[0] <= 'z') { IComponent* comp = GetWeakObject<IComponent>(ctx, 0); if (comp) { IAttribute* attr = comp->AttributeById(String(attrName)); AssignAttributeValue(ctx, 2, attr, AttributeChange::Default); return 1; } } // Fallthrough to ordinary properties duk_dup(ctx, 1); duk_dup(ctx, 2); duk_put_prop(ctx, 0); duk_push_true(ctx); return 1; }
/** * Add/modify an entry in the parameter map for the given component * to update its position. The component is const * as the move doesn't actually change the object * @param comp A reference to the component to move * @param pmap A reference to the ParameterMap that will hold the new position * @param pos The new position * @param positionType Defines how the given position should be interpreted @see * TransformType enumeration */ void moveComponent(const IComponent &comp, ParameterMap &pmap, const Kernel::V3D &pos, const TransformType positionType) { // // This behaviour was copied from how MoveInstrumentComponent worked // // First set it to the new absolute position V3D newPos = pos; switch (positionType) { case Absolute: // Do nothing break; case Relative: newPos += comp.getPos(); break; default: throw std::invalid_argument("moveComponent - Unknown positionType: " + boost::lexical_cast<std::string>(positionType)); } // Then find the corresponding relative position auto parent = comp.getParent(); if (parent) { newPos -= parent->getPos(); Quat rot = parent->getRotation(); rot.inverse(); rot.rotate(newPos); } // Add a parameter for the new position pmap.addV3D(comp.getComponentID(), "pos", newPos); }
/** * Add/modify an entry in the parameter map for the given component * to update its rotation. The component is const * as the move doesn't actually change the object * @param comp A reference to the component to move * @param pmap A reference to the ParameterMap that will hold the new position * @param rot The rotation quaternion * @param rotType Defines how the given rotation should be interpreted @see * TransformType enumeration */ void rotateComponent(const IComponent &comp, ParameterMap &pmap, const Kernel::Quat &rot, const TransformType rotType) { // // This behaviour was copied from how RotateInstrumentComponent worked // Quat newRot = rot; if (rotType == Absolute) { // Find the corresponding relative position auto parent = comp.getParent(); if (parent) { Quat rot0 = parent->getRelativeRot(); rot0.inverse(); newRot = rot * rot0; } } else if (rotType == Relative) { const Quat &Rot0 = comp.getRelativeRot(); newRot = Rot0 * rot; } else { throw std::invalid_argument("rotateComponent - Unknown rotType: " + boost::lexical_cast<std::string>(rotType)); } // Add a parameter for the new rotation pmap.addQuat(comp.getComponentID(), "rot", newRot); }
IComponent* KEditDialogImpl::_CompFactory() { IComponent* pCompTmp = NULL; switch(m_uSelItemID) { case enRadio_Begin + 0: pCompTmp = new KCompText; break; case enRadio_Begin + 1: pCompTmp = new KCompButton; break; case enRadio_Begin + 2: pCompTmp = new KCompImgbtn; break; case enRadio_Begin + 3: pCompTmp = new KCompImg; break; default: pCompTmp = new KCompText; break; } if (pCompTmp != NULL) { pCompTmp->InitComp(); } return pCompTmp; }
GameObject EntityFactory::createObjectFromIML( const std::string &name, const IMLNode *iml) const { //printf("EntityFactory::createObjectFromIML: '%s'\n", name.c_str()); IMLNode *node = iml->findByName(name); if (!node || name.empty()) { fprintf(stderr, "Unable to create entity: '%s'\n", name.c_str()); return GameObject(0); } EntityManager &em = EntityManager::instance(); GameObject entity = em.createEntity(); std::list<IMLNode*> &components_iml = node->getChildren(); std::list<IMLNode*>::iterator it = components_iml.begin(); for (; it != components_iml.end(); ++it) { IMLTag *tag = dynamic_cast<IMLTag*>(*it); if (tag) { ComponentFactory &cf = ComponentFactory::instance(); IComponent *comp = cf.create((*it)->getName()); if (!comp) { fprintf(stderr, "Unable to create component: %s\n", (*it)->getName().c_str()); } else { comp->loadIML(*tag); em.addComponentToEntity(comp, entity); } } } return entity; }
VisualSizer::VisualSizer(shared_ptr<ObjectBase> obj,wxWindow *parent) : VisualObject(obj) { IComponent *comp = obj->GetObjectInfo()->GetComponent(); if (comp) { /* wxObject* yo = parent; IObject *objer = obj.get(); wxStaticBox* box = new wxStaticBox( (wxWindow*)yo, -1, objer->GetPropertyAsString(wxT("label"))); wxStaticBoxSizer* sizer = new wxStaticBoxSizer(box, objer->GetPropertyAsInteger(wxT("orient"))); SetSizer( sizer );*/ SetSizer((wxSizer *)(comp->Create(obj.get(),parent))); } else { // para que no pete ponemos un sizer por defecto, aunque deberá mostrar algun // mensaje de advertencia SetSizer(new wxBoxSizer(wxVERTICAL)); } shared_ptr<Property> pminsize = obj->GetProperty( wxT("minimum_size") ); if (pminsize) { wxSize minsize = StringToSize(pminsize->GetValue()); m_sizer->SetMinSize( minsize ); m_sizer->Layout(); } }
IComponent* CComponentManager::ConstructComponent(CEntityHandle ent, ComponentTypeId cid) { JSContext* cx = m_ScriptInterface.GetContext(); JSAutoRequest rq(cx); std::map<ComponentTypeId, ComponentType>::const_iterator it = m_ComponentTypesById.find(cid); if (it == m_ComponentTypesById.end()) { LOGERROR("Invalid component id %d", cid); return NULL; } const ComponentType& ct = it->second; ENSURE((size_t)ct.iid < m_ComponentsByInterface.size()); boost::unordered_map<entity_id_t, IComponent*>& emap1 = m_ComponentsByInterface[ct.iid]; if (emap1.find(ent.GetId()) != emap1.end()) { LOGERROR("Multiple components for interface %d", ct.iid); return NULL; } std::map<entity_id_t, IComponent*>& emap2 = m_ComponentsByTypeId[cid]; // If this is a scripted component, construct the appropriate JS object first JS::RootedValue obj(cx); if (ct.type == CT_Script) { m_ScriptInterface.CallConstructor(ct.ctor.get(), JS::HandleValueArray::empty(), &obj); if (obj.isNull()) { LOGERROR("Script component constructor failed"); return NULL; } } // Construct the new component IComponent* component = ct.alloc(m_ScriptInterface, obj); ENSURE(component); component->SetEntityHandle(ent); component->SetSimContext(m_SimContext); // Store a reference to the new component emap1.insert(std::make_pair(ent.GetId(), component)); emap2.insert(std::make_pair(ent.GetId(), component)); // TODO: We need to more careful about this - if an entity is constructed by a component // while we're iterating over all components, this will invalidate the iterators and everything // will break. // We probably need some kind of delayed addition, so they get pushed onto a queue and then // inserted into the world later on. (Be careful about immediation deletion in that case, too.) SEntityComponentCache* cache = ent.GetComponentCache(); ENSURE(cache != NULL && ct.iid < (int)cache->numInterfaces && cache->interfaces[ct.iid] == NULL); cache->interfaces[ct.iid] = component; return component; }
/** * 在模型销毁的时候, * 需判断组件是否由自身创建. * 检查m_SelfOwn, * 若为true, * 则需要同时销毁所有组件. */ Model::~Model() { for (UINT32 i = 0; i < m_ComponentList.size(); ++i) { IComponent *component = m_ComponentList[i]; component->Destroy(); } }
bool IEntity::EnterComponents() { size_t count = mComponents.Count(); FOR_EACH_SIZE(i, count) { IComponent* component = mComponents[i]; RETURN_FALSE_IF_FALSE(component->Enter()); }
void Entity::RemoveComponentRaw(QObject* comp) { IComponent* compPtr = dynamic_cast<IComponent*>(comp); if (compPtr) { ComponentPtr ptr = GetComponent(compPtr->TypeName(), compPtr->Name()); //the shared_ptr to this component RemoveComponent(ptr); } }
bool CComponentManager::AddComponent(entity_id_t ent, ComponentTypeId cid, const CParamNode& paramNode) { IComponent* component = ConstructComponent(ent, cid); if (!component) return false; component->Init(paramNode); return true; }
void Entity::Update(void) { std::list<IComponent*>::iterator iter = m_components.begin(); while(iter != m_components.end()) { IComponent * component = *iter; component->Update(); iter++; } }
void Entity::RemoveComponentRaw(QObject* comp) { LogWarning("Entity::RemoveComponentRaw: This function is deprecated and will be removed. Use RemoveComponent or RemoveComponentById instead."); IComponent* compPtr = dynamic_cast<IComponent*>(comp); if (compPtr) { ComponentPtr ptr = Component(compPtr->TypeName(), compPtr->Name()); //the shared_ptr to this component RemoveComponent(ptr); } }
void GameObject::setLayer(Layer* layer_in) { layer = layer_in; std::set<ComponentId> keys; make_key_set(components, keys); for (std::set<ComponentId>::iterator it=keys.begin() ; it != keys.end(); it++ ) { IComponent* component = getComponent(*it); component->setOwner(this); } }
/** AddCopy method * @param comp :: component to add * @return number of components in the assembly * * Add a copy of a component in the assembly. * Comp is cloned if valid, then added in the assembly * This becomes the parent of the cloned component */ int CompAssembly::addCopy(IComponent *comp) { if (m_map) throw std::runtime_error( "CompAssembly::addCopy() called for a parametrized CompAssembly."); if (comp) { IComponent *newcomp = comp->clone(); newcomp->setParent(this); m_children.push_back(newcomp); } return static_cast<int>(m_children.size()); }
int _tmain(int argc, _TCHAR* argv[]) { IUnknown* pU = CreateInstance(); IComponent *pI = NULL; pU->QueryInterface(IID_IComponent, (void**)&pI); pI->Print("testing"); char c; cin >> c; pI->Release(); cin >> c; return 0; }
IComponent* CComponentManager::ConstructComponent(entity_id_t ent, ComponentTypeId cid) { std::map<ComponentTypeId, ComponentType>::const_iterator it = m_ComponentTypesById.find(cid); if (it == m_ComponentTypesById.end()) { LOGERROR(L"Invalid component id %d", cid); return NULL; } const ComponentType& ct = it->second; ENSURE((size_t)ct.iid < m_ComponentsByInterface.size()); boost::unordered_map<entity_id_t, IComponent*>& emap1 = m_ComponentsByInterface[ct.iid]; if (emap1.find(ent) != emap1.end()) { LOGERROR(L"Multiple components for interface %d", ct.iid); return NULL; } std::map<entity_id_t, IComponent*>& emap2 = m_ComponentsByTypeId[cid]; // If this is a scripted component, construct the appropriate JS object first jsval obj = JSVAL_NULL; if (ct.type == CT_Script) { obj = m_ScriptInterface.CallConstructor(ct.ctor.get(), JSVAL_VOID); if (JSVAL_IS_VOID(obj)) { LOGERROR(L"Script component constructor failed"); return NULL; } } // Construct the new component IComponent* component = ct.alloc(m_ScriptInterface, obj); ENSURE(component); component->SetEntityId(ent); component->SetSimContext(m_SimContext); // Store a reference to the new component emap1.insert(std::make_pair(ent, component)); emap2.insert(std::make_pair(ent, component)); // TODO: We need to more careful about this - if an entity is constructed by a component // while we're iterating over all components, this will invalidate the iterators and everything // will break. // We probably need some kind of delayed addition, so they get pushed onto a queue and then // inserted into the world later on. (Be careful about immediation deletion in that case, too.) return component; }
void Entity::CleanUp(void) { std::list<IComponent*>::iterator iter = m_components.begin(); while(iter != m_components.end()) { IComponent * component = *iter; if(component->IsRenderable()) { m_context->GetRenderer()->RemoveRenderableComponent(reinterpret_cast<IRenderableComponent*>(component)); } iter++; } }
void ComponentBase::checkValidPort( IPort* port ) { if( !port ) throw NoSuchPortException( "illegal null port" ); IComponent* myType = getComponent(); ICompositeType* owner = port->getOwner(); if( owner != static_cast<ICompositeType*>( myType ) ) CORAL_THROW( NoSuchPortException, "port '" << port->getName() << "' belongs to " << owner->getFullName() << ", not to " << myType->getFullName() ); assert( port->getIndex() < myType->getPorts().getSize() ); }
VisualWindow::VisualWindow(shared_ptr<ObjectBase> obj, wxWindow *parent) : VisualObject(obj) { IComponent *comp = obj->GetObjectInfo()->GetComponent(); if (comp) SetWindow((wxWindow *)(comp->Create(obj.get(),parent))); else SetWindow(new GenericWindow(parent)); SetupWindow(); }
void Entity::Serialize(FileWriter & writer) { writer.WriteUnsignedInt(static_cast<unsigned int>(GetPos().X())); writer.WriteUnsignedInt(static_cast<unsigned int>(GetPos().Y())); writer.WriteUnsignedInt(static_cast<unsigned int>(m_components.size())); std::list<IComponent*>::iterator iter = m_components.begin(); while(iter != m_components.end()) { IComponent * component = *iter; writer.WriteUnsignedInt(component->GetComponentType()); component->Serialize(writer); iter++; } }
void Box2DPhysicsComponent::onContact( Contact contact, IContactable* other, b2BodyType type ) { if ( other ) { IComponent* hitByComp = dynamic_cast<IComponent*>(other); if ( hitByComp ) { GameObject* hitByObject = hitByComp->getGameObject(); this->getGameObject()->onHit( hitByObject, contact ); } } else { this->getGameObject()->onHit( nullptr, contact ); } }
size_t InstrumentVisitor::commonRegistration(const IComponent &component) { const size_t componentIndex = m_componentIds->size(); const ComponentID componentId = component.getComponentID(); markAsSourceOrSample(componentId, componentIndex); // Record the ID -> index mapping (*m_componentIdToIndexMap)[componentId] = componentIndex; // For any non-detector we extend the m_componentIds from the back m_componentIds->emplace_back(componentId); m_positions->emplace_back(Kernel::toVector3d(component.getPos())); m_rotations->emplace_back(Kernel::toQuaterniond(component.getRotation())); m_shapes->emplace_back(m_nullShape); m_scaleFactors->emplace_back(Kernel::toVector3d(component.getScaleFactor())); m_names->emplace_back(component.getName()); clearLegacyParameters(m_pmap, component); return componentIndex; }
void fromScriptValueComponentMap(const QScriptValue &obj, Entity::ComponentMap &components) { components.clear(); QScriptValueIterator it(obj); while(it.hasNext()) { it.next(); QObject *o = it.value().toQObject(); if (o) { IComponent *c = qobject_cast<IComponent *>(o); if (c) components[c->TypeId()] = c->shared_from_this(); } } }
DependenciesSolvingResult ComponentDependencies::completeListWithParents(const QList<IComponent *> &forParents) const { if (forParents.empty()) return DependenciesSolvingResult(); DependencySolver solver; QList<IComponent *> completeList; QList<IComponent *> unresolvedList(forParents); // TODO: refactoring is needed. // Find all children for parents and reverse parent-children dependencies for correct ordering: while (!unresolvedList.isEmpty()) { IComponent *parent = unresolvedList[0]; solver.addComponent(parent->name()); DependenciesSolvingResult result = getChildComponents(parent); for (IComponent * child : result.ordered()) { if (!completeList.contains(child) && !unresolvedList.contains(child)) unresolvedList.push_back(child); // We look all children for parents, so switch their dependencies: solver.addComponent(child->name()); solver.addDependency(parent->name(), child->name()); } unresolvedList.removeFirst(); completeList.push_back(parent); } QStringList ordered; QStringList orphans; QStringList missing; bool hasCyclic = !solver.solve(ordered, orphans, missing); if (hasCyclic) { Log.d("At least one cyclic dependency has been found in the component manager. Cycles in the component dependencies must be avoided."); return DependenciesSolvingResult(ordered, orphans, missing, m_components->toList(), hasCyclic); } if (!missing.isEmpty()) { Log.d(QString("A component declared a dependency on another component which is not declared to be loaded. Missing component(s): %1") .arg(missing.join(", ")).toLatin1()); } return DependenciesSolvingResult(ordered, orphans, missing, m_components->toList(), hasCyclic); }
//-------------------------------------------------------------------------------------------------------------- int32 HostProcessData::createBuffers (IComponent& component, AudioBusBuffers*& buffers, BusDirection dir, int32 bufferSamples) { int32 busCount = component.getBusCount (kAudio, dir); if (busCount > 0) { buffers = new AudioBusBuffers[busCount]; for (int32 i = 0; i < busCount; i++) { BusInfo busInfo = {0}; if (component.getBusInfo (kAudio, dir, i, busInfo) == kResultTrue) { buffers[i].numChannels = busInfo.channelCount; // allocate for each channel if (busInfo.channelCount > 0) { if (symbolicSampleSize == kSample64) buffers[i].channelBuffers64 = new Sample64* [busInfo.channelCount]; else buffers[i].channelBuffers32 = new Sample32* [busInfo.channelCount]; for (int32 j = 0; j < busInfo.channelCount; j++) { if (symbolicSampleSize == kSample64) { if (bufferSamples > 0) buffers[i].channelBuffers64[j] = new Sample64 [bufferSamples]; else buffers[i].channelBuffers64[j] = 0; } else { if (bufferSamples > 0) buffers[i].channelBuffers32[j] = new Sample32 [bufferSamples]; else buffers[i].channelBuffers32[j] = 0; } } } } } } return busCount; }
PVisualObject VisualObject::CreateVisualObject (shared_ptr<ObjectBase> obj, wxWindow *wx_parent) { PVisualObject vobj; shared_ptr<ObjectInfo> obj_info = obj->GetObjectInfo(); wxString type = obj->GetObjectTypeName(); // TO-DO: arreglar esto! // // El tipo de objeto se deberá indicar en el plugin // quizá sea conveniente dividir la macro COMPONENT("name",component) // estas tres: // WINDOW_COMPONENT // SIZER_COMPONENT // ABSTRACT_COMPONENT // y que se pueda consultar el tipo. IComponent *comp = obj->GetObjectInfo()->GetComponent(); if (comp) { int compType = comp->GetComponentType(); switch (compType) { case COMPONENT_TYPE_WINDOW: vobj = PVisualObject(new VisualWindow(obj,wx_parent)); break; case COMPONENT_TYPE_SIZER: vobj = PVisualObject(new VisualSizer(obj,wx_parent)); break; default: // items y forms vobj = PVisualObject(new VisualObject(obj)); break; } } else { vobj = PVisualObject(new VisualObject(obj)); wxLogError( wxT("Component for %s not found!"),obj->GetClassName().c_str() ); } return vobj; }
/** AddCopy method * @param comp :: component to add * @return number of components in the assembly * * Add a copy of a component in the assembly. * Comp is cloned if valid, then added in the assembly * This becomes the parent of the cloned component */ int ObjCompAssembly::addCopy(IComponent *comp) { if (m_map) throw std::runtime_error( "ObjCompAssembly::addCopy() called on a Parametrized object."); if (comp) { IComponent *newcomp = comp->clone(); ObjComponent *c = dynamic_cast<ObjComponent *>(newcomp); if (!c) { throw Kernel::Exception::InstrumentDefinitionError( "ObjCompAssembly cannot contain components of non-ObjComponent type"); } newcomp->setParent(this); group.push_back(c); } return static_cast<int>(group.size()); }
void Entity::Deserialize(FileReader & reader) { unsigned int xPos = reader.ReadUnsignedInt(); unsigned int yPos = reader.ReadUnsignedInt(); SetPos(Point(static_cast<float>(xPos),static_cast<float>(yPos))); unsigned int componentCount = reader.ReadUnsignedInt(); for(unsigned int i = 0; i < componentCount; i++) { ComponentTypes::type myType = static_cast<ComponentTypes::type>(reader.ReadUnsignedInt()); IComponent * newComponent = IComponent::CreateComponentOfType(this, myType, m_context); newComponent->Deserialize(reader); AddComponent(newComponent); } AddRenderableComponentsToRenderer(); }
Logic::CEntity *CEntityFactory::assembleEntity(const std::string &type) { mapB::const_iterator it = _mapBlueprints.find(type); // si el tipo se encuentra registrado. if (it != _mapBlueprints.end()) { CEntity* ent = new CEntity(EntityID::NextID()); std::string nombreComponente; bool dormido = false; // Añadimos todos sus componentes. IComponent* comp; vecComponentes::const_iterator itc = (*it).second.begin(); for(; itc !=(*it).second.end(); ++itc) { nombreComponente = (*itc).first; dormido = !(*itc).second; if(CComponentFactory::getSingletonPtr()->has(nombreComponente)) { comp = CComponentFactory::getSingletonPtr()->create(nombreComponente); comp->setName(nombreComponente); } else { assert(!"Nombre erroneo de un componente, Mira a ver si están todos bien escritos en el fichero de blueprints"); delete ent; return 0; } if(comp) ent->addComponent(comp,dormido); } return ent; } return 0; } // assembleEntity