Entity* AbstractEntityFactory::createEntity(std::string entityTemplateID) { Entity* pNewEntity = nullptr; EntityTemplate* entityTemplate = _entityTemplateManager.getResource(entityTemplateID); tinyxml2::XMLElement* pRootNode = entityTemplate->getXmlData().FirstChildElement(); if (!pRootNode) { OutputDebugString("Error RootNode in Create Entity null!\n"); //TODO error crash } else { pNewEntity = new Entity(); //for each second level element create a new component object and add it to the new entity object for (tinyxml2::XMLElement* pNode = pRootNode->FirstChildElement(); pNode; pNode = pNode->NextSiblingElement()) { IEntityComponent* newComponent = createComponent(pNode); pNewEntity->addComponent(newComponent); } } return pNewEntity; }
Slide::Slide(QWidget *parent) : QWidget(parent) { createComponent(); connections(); input(); }
Transfer::Transfer(QWidget *parent) : QWidget(parent) { createComponent(); connections(); input(); }
Object* ObjectFactory::createObjectInternal(const std::string& path) { if(path.length() > 0 && path[0] == '.') { const std::string className = path.substr(1); if(Object* object = createRawObject(className)) { // Perform internal initialization object->createElements(); return object; } } else { RafPrototypeHeader raf; raf.load(path); const RJNode& configuration = raf.getCustomJsonHeaderRef(); Object* object = createObjectInternal(configuration["proto"]); Actor* actor = dynamic_cast<Actor*>(object); if(actor) { // Create dynamic components. const RJNode& dclJson = configuration["dcl"]; for(RJNode::const_iterator it = dclJson.begin(); it != dclJson.end(); ++it) { const std::string componentName = it.key(); const std::string className = it.value(); Component* component = createComponent(className, componentName, actor); if(component) { component->xiMarkAsDynamic(); } else { rLogErr(g_log, "[ObjectManager] Couldn`t create component \"" << componentName << "\". Skipping."); } } actor->siDeserialize(ESerializationHint::Definition, configuration); std::shared_ptr<PrototypeAsset> prototype = core::getAssetManager()->getPrototype(path); if(prototype && ji::hasChild(configuration, "script")) { prototype->xiEnsureScriptLoaded(ji::getChild(configuration, "script")); } return actor; } else { destroyObject(object); } } return nullptr; }
void KWin::DeclarativeScript::run() { if (running()) { return; } // add read config KDeclarative kdeclarative; kdeclarative.setDeclarativeEngine(m_engine); kdeclarative.initialize(); kdeclarative.setupBindings(); installScriptFunctions(kdeclarative.scriptEngine()); qmlRegisterType<DesktopThumbnailItem>("org.kde.kwin", 0, 1, "DesktopThumbnailItem"); qmlRegisterType<WindowThumbnailItem>("org.kde.kwin", 0, 1, "ThumbnailItem"); qmlRegisterType<KWin::ScriptingClientModel::ClientModel>(); qmlRegisterType<KWin::ScriptingClientModel::SimpleClientModel>("org.kde.kwin", 0, 1, "ClientModel"); qmlRegisterType<KWin::ScriptingClientModel::ClientModelByScreen>("org.kde.kwin", 0, 1, "ClientModelByScreen"); qmlRegisterType<KWin::ScriptingClientModel::ClientModelByScreenAndDesktop>("org.kde.kwin", 0, 1, "ClientModelByScreenAndDesktop"); qmlRegisterType<KWin::ScriptingClientModel::ClientFilterModel>("org.kde.kwin", 0, 1, "ClientFilterModel"); qmlRegisterType<KWin::Client>(); m_engine->rootContext()->setContextProperty("options", options); m_component->loadUrl(QUrl::fromLocalFile(scriptFile().fileName())); if (m_component->isLoading()) { connect(m_component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), SLOT(createComponent())); } else { createComponent(); } }
Component* ComponentFactory::createComponent(const std::string& typeName) { auto typeInfo = getTypeInfo(typeName); if (typeInfo->isAbstract()) { throw std::runtime_error("Cannot create instance of abstract component type '" + typeName + "'"); } return typeInfo->createComponent(); }
void LRClickableAreaWTextComp::clickLeft(tribool down, bool previousState) { if((!down) && previousState) { std::vector<CComponent*> comp(1, createComponent()); LOCPLINT->showInfoDialog(text, comp); } }
TopMenu::TopMenu(QWidget *parent) : QWidget(parent) { createComponent(); input(); connections(); }
Configuration::Configuration(QWidget *parent) : QWidget(parent) { createComponent(); input(); connections(); }
void ComponentManager<T>::addComponent(id entity) { if (hasComponent(entity)) { resetComponent(entity); } else { reserveComponentIndex(entity); deletedComponentsIndex.size() == 0 ? createComponent(entity) : reuseComponent(entity); fireEntityAddedSignal(entity); } }
topMenu::topMenu(QWidget *parent) : QWidget(parent) { createComponent(); setComponent(); connect(menuButton,SIGNAL(mouseOnImage(bool)),this,SLOT(onFocus_menuButton(bool))); connect(fullScreen,SIGNAL(onClick()),this,SLOT(onClick_fullScreen())); connect(nickName,SIGNAL(onClick()),SLOT(onClick_nickName())); }
CounterInterface::CounterInterface(QWidget *parent) : QWidget(parent) { createComponent(); statics(); connections(); totalValueOrder = 0; isAdd = true; }
CtrlrComponent *CtrlrComponentTypeManager::createComponent (const ValueTree &savedState, CtrlrModulator &owner) { if (savedState.hasProperty (Ids::uiType)) { CtrlrComponent *c = createComponent(savedState.getProperty(Ids::uiType).toString(), owner); c->restoreState (savedState); return (c); } jassertfalse; // trying to restore a component with no type, can't do that return (0); }
void KWin::DeclarativeScript::run() { if (running()) { return; } m_component->loadUrl(QUrl::fromLocalFile(scriptFile().fileName())); if (m_component->isLoading()) { connect(m_component, &QQmlComponent::statusChanged, this, &DeclarativeScript::createComponent); } else { createComponent(); } }
void LRClickableAreaWTextComp::clickRight(tribool down, bool previousState) { if(down) { if(CComponent *comp = createComponent()) { CRClickPopup::createAndPush(text, CInfoWindow::TCompsInfo(1, comp)); return; } } LRClickableAreaWText::clickRight(down, previousState); //only if with-component variant not occurred }
void HostCommunication::parseCmd() { GraphCmd cmd = (GraphCmd)buffer[0]; if (cmd == GraphCmdEnd) { MICROFLO_DEBUG(this, DebugLevelDetailed, DebugEndOfTransmission); const uint8_t cmd[] = { GraphCmdTransmissionEnded }; transport->sendCommand(cmd, sizeof(cmd)); state = LookForHeader; } else if (cmd == GraphCmdReset) { network->reset(); } else if (cmd == GraphCmdStartNetwork) { network->start(); } else if (cmd == GraphCmdCreateComponent) { MICROFLO_DEBUG(this, DebugLevelDetailed, DebugComponentCreateStart); Component *c = createComponent((MicroFlo::ComponentId)buffer[1]); MICROFLO_DEBUG(this, DebugLevelDetailed, DebugComponentCreateEnd); network->addNode(c, buffer[2]); } else if (cmd == GraphCmdConnectNodes) { MICROFLO_DEBUG(this, DebugLevelDetailed, DebugConnectNodesStart); network->connect(buffer[1], buffer[3], buffer[2], buffer[4]); } else if (cmd == GraphCmdSendPacket) { const Msg packetType = (Msg)buffer[3]; Packet p; if (packetType == MsgBracketStart || packetType == MsgBracketEnd || packetType == MsgVoid) { p = Packet(packetType); } else if (packetType == MsgInteger) { const long val = buffer[4] + ((long)(buffer[5])<<8) + ((long)(buffer[6])<<16) + ((long)(buffer[7])<<24); p = Packet(val); } else if (packetType == MsgByte) { p = Packet(buffer[4]); } else if (packetType == MsgBoolean) { p = Packet(!(buffer[4] == 0)); } if (p.isValid()) { network->sendMessageId(buffer[1], buffer[2], p); const uint8_t cmd[] = { GraphCmdSendPacketDone, buffer[1], buffer[2], (uint8_t)packetType }; transport->sendCommand(cmd, sizeof(cmd)); } else { MICROFLO_DEBUG(this, DebugLevelError, DebugParserUnknownPacketType); } } else if (cmd == GraphCmdConfigureDebug) { network->setDebugLevel((DebugLevel)buffer[1]); } else if (cmd == GraphCmdSubscribeToPort) { network->subscribeToPort(buffer[1], buffer[2], (bool)buffer[3]); } else if (cmd == GraphCmdConnectSubgraphPort) { #ifdef MICROFLO_ENABLE_SUBGRAPHS // FIXME: validate const bool isOutput = (unsigned int)buffer[1]; const int subgraphNode = (unsigned int)buffer[2]; const int subgraphPort = (unsigned int)buffer[3]; const int childNode = (unsigned int)buffer[4]; const int childPort = (unsigned int)buffer[5]; network->connectSubgraph(isOutput, subgraphNode, subgraphPort, childNode, childPort); #else MICROFLO_DEBUG(this, DebugLevelError, DebugNotSupported); #endif } else if (cmd == GraphCmdPing) { const uint8_t cmd[] = { GraphCmdPong, cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], cmd[6], cmd[7] }; transport->sendCommand(cmd, sizeof(cmd)); } else if (cmd == GraphCmdSetIoValue) { network->setIoValue(buffer, MICROFLO_CMD_SIZE); } else if (cmd >= GraphCmdInvalid) { MICROFLO_ASSERT(memcmp(buffer, MICROFLO_GRAPH_MAGIC, sizeof(MICROFLO_GRAPH_MAGIC)) == 0, this, DebugLevelError, DebugParserInvalidCommand); } else { MICROFLO_DEBUG(this, DebugLevelError, DebugParserUnknownCommand); } }
void RequestHandler::handling_thread(g_message* _request) { // wrap in local for auto-delete g_local < g_message > request(_request); // read parameters g_pid requester_pid = g_get_pid_for_tid(request()->sender); g_fd requesters_output = request()->parameterA; g_fd requesters_input = request()->parameterB; g_pid my_pid = g_get_pid(); // register a name std::stringstream namestr; namestr << "windowserver:handler@"; namestr << requester_pid; g_task_register_id(namestr.str().c_str()); // clone pipe ends g_fs_clonefd_status clone_input_status; g_fd requester_out = g_clone_fd_s(requesters_input, requester_pid, my_pid, &clone_input_status); if (clone_input_status != G_FS_CLONEFD_SUCCESSFUL) { g_logger::log("unable to clone input file descriptor (%i in process %i) on open request (status: %i)", requesters_input, requester_pid, clone_input_status); return; } g_fs_clonefd_status clone_output_status; g_fd requester_in = g_clone_fd_s(requesters_output, requester_pid, my_pid, &clone_output_status); if (clone_output_status != G_FS_CLONEFD_SUCCESSFUL) { g_logger::log("unable to clone output file descriptor (%i in process %i) on open request (status: %i)", requesters_input, requester_pid, clone_output_status); return; } // send response g_message_empty (response); response.type = G_UI_COMMAND_OPEN_RESPONSE; response.topic = request()->topic; g_send_msg(request()->sender, &response); // add process add_process(requester_pid, requester_out, requester_in); // start event dispatch thread g_create_thread((void*) &event_dispatch_thread); while (true) { // read transaction id uint32_t idlen = sizeof(g_ui_transaction_id); uint8_t id[idlen]; g_read(requester_in, id, idlen); g_ui_transaction_id transaction = *((g_ui_transaction_id*) id); // read length uint32_t lenlen = sizeof(uint32_t); uint8_t len[lenlen]; g_read(requester_in, len, lenlen); uint32_t length = *((uint32_t*) len); // read data // TODO limit data uint8_t* data = new uint8_t[length]; int32_t rd = 0; while (rd < length) { rd += g_read(requester_in, &data[rd], length - rd); } g_value_placer data_reader(data); // handle command g_ui_protocol_command_id command = data_reader.get<g_ui_protocol_command_id>(); if (command == G_UI_PROTOCOL_CREATE_WINDOW) { uint32_t window_id; g_ui_protocol_status status = createWindow(&window_id); // write response uint32_t response_len = G_UI_PROTOCOL_HEADER_LENGTH + G_UI_PROTOCOL_CREATE_WINDOW_RESPONSE_LENGTH; g_local < uint8_t > response(new uint8_t[response_len]); g_value_placer response_writer(response()); response_writer.put(G_UI_PROTOCOL_CREATE_WINDOW); response_writer.put(status); response_writer.put(window_id); send(requester_out, transaction, response(), response_len); } else if (command == G_UI_PROTOCOL_SET_VISIBLE) { uint32_t component_id = data_reader.get<uint32_t>(); bool visible = data_reader.get<uint8_t>(); // handle command g_ui_protocol_status status = setVisible(component_id, visible); // write response uint32_t response_len = G_UI_PROTOCOL_HEADER_LENGTH + G_UI_PROTOCOL_SET_VISIBLE_RESPONSE_LENGTH; g_local < uint8_t > response(new uint8_t[response_len]); g_value_placer response_writer(response()); response_writer.put(G_UI_PROTOCOL_SET_VISIBLE); response_writer.put(status); send(requester_out, transaction, response(), response_len); } else if (command == G_UI_PROTOCOL_CREATE_COMPONENT) { uint32_t component_type = data_reader.get<uint32_t>(); // handle command uint32_t component_id; g_ui_protocol_status status = createComponent(component_type, &component_id); // write response uint32_t response_length = G_UI_PROTOCOL_HEADER_LENGTH + G_UI_PROTOCOL_CREATE_COMPONENT_RESPONSE_LENGTH; g_local < uint8_t > response(new uint8_t[response_length]); g_value_placer response_writer(response()); response_writer.put(G_UI_PROTOCOL_CREATE_COMPONENT); response_writer.put(status); response_writer.put(component_id); send(requester_out, transaction, response(), response_length); } else if (command == G_UI_PROTOCOL_ADD_COMPONENT) { uint32_t parent_id = data_reader.get<uint32_t>(); uint32_t child_id = data_reader.get<uint32_t>(); // handle command g_ui_protocol_status status = addComponent(parent_id, child_id); // write response uint32_t response_length = G_UI_PROTOCOL_HEADER_LENGTH + G_UI_PROTOCOL_ADD_COMPONENT_RESPONSE_LENGTH; g_local < uint8_t > response(new uint8_t[response_length]); g_value_placer response_writer(response()); response_writer.put(G_UI_PROTOCOL_ADD_COMPONENT); response_writer.put(status); send(requester_out, transaction, response(), response_length); } else if (command == G_UI_PROTOCOL_SET_TITLE) { uint32_t component_id = data_reader.get<uint32_t>(); uint32_t title_length = data_reader.get<uint32_t>(); g_local<char> title(new char[title_length]); data_reader.get((uint8_t*) title(), title_length); // handle command g_ui_protocol_status status = setTitle(component_id, title()); // write response uint32_t response_length = G_UI_PROTOCOL_HEADER_LENGTH + G_UI_PROTOCOL_SET_TITLE_RESPONSE_LENGTH; g_local < uint8_t > response(new uint8_t[response_length]); g_value_placer response_writer(response()); response_writer.put(G_UI_PROTOCOL_SET_TITLE); response_writer.put(status); send(requester_out, transaction, response(), response_length); } else if (command == G_UI_PROTOCOL_GET_TITLE) { uint32_t component_id = data_reader.get<uint32_t>(); // handle command std::string title; g_ui_protocol_status status = getTitle(component_id, title); int title_length = title.length() + 1; // write response uint32_t response_length = G_UI_PROTOCOL_HEADER_LENGTH + G_UI_PROTOCOL_GET_TITLE_RESPONSE_LENGTH + title_length; g_local < uint8_t > response(new uint8_t[response_length]); g_value_placer response_writer(response()); response_writer.put(G_UI_PROTOCOL_GET_TITLE); response_writer.put(status); response_writer.put(title_length); response_writer.put((uint8_t*) title.c_str(), title_length); send(requester_out, transaction, response(), response_length); } else if (command == G_UI_PROTOCOL_SET_BOUNDS) { uint32_t component_id = data_reader.get<uint32_t>(); int32_t x = data_reader.get<int32_t>(); int32_t y = data_reader.get<int32_t>(); int32_t width = data_reader.get<int32_t>(); int32_t height = data_reader.get<int32_t>(); // handle command g_ui_protocol_status status = setBounds(component_id, x, y, width, height); // write response uint32_t response_length = G_UI_PROTOCOL_HEADER_LENGTH + G_UI_PROTOCOL_SET_BOUNDS_RESPONSE_LENGTH; g_local < uint8_t > response(new uint8_t[response_length]); g_value_placer response_writer(response()); response_writer.put(G_UI_PROTOCOL_SET_BOUNDS); response_writer.put(status); send(requester_out, transaction, response(), response_length); } else if (command == G_UI_PROTOCOL_SET_ACTION_LISTENER) { uint32_t component_id = data_reader.get<uint32_t>(); // handle command uint32_t listener_id; g_ui_protocol_status status = setActionListener(requester_pid, component_id, &listener_id); // write response uint32_t response_length = G_UI_PROTOCOL_HEADER_LENGTH + G_UI_PROTOCOL_SET_ACTION_LISTENER; g_local < uint8_t > response(new uint8_t[response_length]); g_value_placer response_writer(response()); response_writer.put<g_ui_protocol_command_id>(G_UI_PROTOCOL_SET_ACTION_LISTENER); response_writer.put<g_ui_protocol_status>(status); response_writer.put<uint32_t>(listener_id); send(requester_out, transaction, response(), response_length); } } // TODO close all windows // TODO remove listeners remove_process(requester_pid); }
void QVisualBinding::MouseEvent( TEvent& e ) { if (e.type&evMouseDown) { currc=doc->inComponent( e.pos.x, e.pos.y ); if (e.btn==1) { if (currc) { state=stateDraggin; gui_wmode( XOR_PUT ); posold = e.pos; size = QPoint(currc->r.deltax(), currc->r.deltay()); delta = QPoint( e.pos.x-currc->r.a.x, e.pos.y-currc->r.a.y ); draw_icon( posold ); } else if (doc->inNode( e.pos.x, e.pos.y, &currn, &currp)) if (!simOn) { state=stateConnect; gui_wmode( XOR_PUT ); posold = posori = currp->pos(); } else { currn->state = !currn->state; do_draw_flags( bDrawNodes ); } } } ////////////////////////////////////////////////////////////////// if (e.type&evMouseMove) { if (state==stateDraggin) { draw_icon( posold ); draw_icon( posold=e.pos ); } else if (state==stateConnect) { draw_line( EGA_WHITE, posori.x, posori.y, posold.x, posold.y); posold = e.pos; draw_line( EGA_WHITE, posori.x, posori.y, posold.x, posold.y); } } ////////////////////////////////////////////////////////////////// if (e.type&evMouseUp) { if (state==stateDraggin) { draw_icon( posold ); gui_wmode( COPY_PUT ); state=0; if (currc) // cuando se mueve un componente currc->moveto( posold.x-currc->r.a.x-delta.x, posold.y-currc->r.a.y-delta.y); else if (canvas->Bounds.contain(e.pos)) // Cuando se coloca uno nuevo... doc->addComponent( createComponent( posold.x-delta.x, posold.y-delta.y, complist->pos ) ); currc=NULL; canvas->doDraw(); } else if (state==stateConnect) { draw_line( EGA_WHITE, posori.x, posori.y, posold.x, posold.y); state = 0; gui_wmode( COPY_PUT ); if (currn && currp) { QNode *n; QNodePoint *p; if (doc->inNode(posold.x, posold.y, &n, &p) && (n!=currn)) { doc->joinNodes( currn, n ); currn->addPoint(new QNodeNiple(currp, p)); } else currn->addPoint(new QNodePoint(posold, currp)); } currn = NULL; currp = NULL; canvas->doDraw(); } else if (e.btn==2) { QComponent *c=doc->inComponent( e.pos.x, e.pos.y ); if (c!=selectc) { selectc=c; do_draw_flags( bDrawComps ); } } } }
TreatmentInterface::TreatmentInterface(QWidget *parent) : QWidget(parent) { createComponent(); connections(); }
vector<vector <Point> > findConnectedComponents(struct ConnectedComponentConfig & config,Mat & depthImage, Mat & mask,Mat & labeledComponents) { static struct ConnectedComponentData data; int numberOfComponents = 1; data.depthImage = depthImage; //Initialize the data to prep calculating the connected component connectedComponentsDataInit(config,data); //Loop through pixels for(int y =0; y < data.depthImage.rows; y++) { //Get the pointers to the rows float * depthImageRow = data.depthImage.ptr<float>(y); signed short int * labelsRow = data.labels.ptr<signed short int>(y); unsigned char * maskRow = mask.ptr<unsigned char>(y); for(int x =0; x < data.depthImage.cols; x++) { //Check if the current pixel is valid for labeling if(labelsRow[x] ==CONNECTED_COMPONENT_UNLABELED && maskRow[x] !=0) { // resetInqueueLabels(data.labels); // vector <Point> currentComponent; //Handle resizing the component vector if((int)data.listOfConnectedComponents.size() < numberOfComponents) { data.listOfConnectedComponents.resize(numberOfComponents); } else { data.listOfConnectedComponents[numberOfComponents-1].clear(); } int currentComponent = numberOfComponents-1; //Current point struct Point currentPoint(x,y); //Clear the quue data.currentQueue.clear(); //Add this point to the queue to start a new component data.currentQueue.push_back(currentPoint); //Change the current node/pixels class ((signed short int*)(data.labels.data + data.labels.step[0]*currentPoint.y))[currentPoint.x] = data.currentLabel;// at<signed short int>(currentPoint) = data.currentLabel; //Create the component createComponent(config, mask, data, data.listOfConnectedComponents[currentComponent]); //Make sure the pixel area size is acceptable, if it isn't then label the component as too small if((int)data.listOfConnectedComponents[currentComponent].size() < config.minPixelArea) { for(int pointId = 0; pointId < (int)data.listOfConnectedComponents[currentComponent].size(); pointId++) { ((signed short int*)(data.labels.data + data.labels.step[0]*data.listOfConnectedComponents[currentComponent][pointId].y))[data.listOfConnectedComponents[currentComponent][pointId].x] = CONNECTED_COMPONENT_AREA_TOO_SMALL_LABEL;//data.labels.at<signed short int>(data.listOfConnectedComponents[currentComponent][pointId]) = CONNECTED_COMPONENT_AREA_TOO_SMALL_LABEL; } } else { //Increment the currentLabel id data.currentLabel++; numberOfComponents++; } // displayComponentResults(data.labels); // waitKey(0); } else if(maskRow[x] ==0) { labelsRow[x] = CONNECTED_COMPONENT_MASKED_LABEL; } } } //Since we may have over allocated the list of connected components vector, lets clear out the empty ones while(numberOfComponents < (int)data.listOfConnectedComponents.size()) { data.listOfConnectedComponents.pop_back(); } labeledComponents = data.labels; return data.listOfConnectedComponents; }
BDTools::BDTools(QObject *parent) : QObject(parent) { createComponent(); }
cocos2d::Node* SceneReader::createNodeWithSceneFile(const std::string &fileName, AttachComponentType attachComponent /*= AttachComponentType::EMPTY_NODE*/) { std::string reDir = fileName; std::string file_extension = ""; size_t pos = reDir.find_last_of('.'); if (pos != std::string::npos) { file_extension = reDir.substr(pos, reDir.length()); std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper); } if (file_extension == ".JSON") { _node = nullptr; rapidjson::Document jsonDict; do { CC_BREAK_IF(!readJson(fileName, jsonDict)); _node = createObject(jsonDict, nullptr, attachComponent); TriggerMng::getInstance()->parse(jsonDict); } while (0); return _node; } else if(file_extension == ".CSB") { do { std::string binaryFilePath = CCFileUtils::getInstance()->fullPathForFilename(fileName); auto fileData = FileUtils::getInstance()->getDataFromFile(binaryFilePath); auto fileDataBytes = fileData.getBytes(); CC_BREAK_IF(fileData.isNull()); CocoLoader tCocoLoader; if (tCocoLoader.ReadCocoBinBuff((char*)fileDataBytes)) { stExpCocoNode *tpRootCocoNode = tCocoLoader.GetRootCocoNode(); rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader); if (rapidjson::kObjectType == tType) { stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray(&tCocoLoader); CC_BREAK_IF(tpRootCocoNode->GetChildNum() == 0); _node = Node::create(); int nCount = 0; std::vector<Component*> _vecComs; ComRender *pRender = nullptr; std::string key = tpChildArray[15].GetName(&tCocoLoader); if (key == "components") { nCount = tpChildArray[15].GetChildNum(); } stExpCocoNode *pComponents = tpChildArray[15].GetChildArray(&tCocoLoader); SerData *data = new (std::nothrow) SerData(); for (int i = 0; i < nCount; i++) { stExpCocoNode *subDict = pComponents[i].GetChildArray(&tCocoLoader); if (subDict == nullptr) { continue; } std::string key1 = subDict[1].GetName(&tCocoLoader); const char *comName = subDict[1].GetValue(&tCocoLoader); Component *pCom = nullptr; if (key1 == "classname" && comName != nullptr) { pCom = createComponent(comName); } CCLOG("classname = %s", comName); if (pCom != nullptr) { data->_rData = nullptr; data->_cocoNode = subDict; data->_cocoLoader = &tCocoLoader; if (pCom->serialize(data)) { ComRender *pTRender = dynamic_cast<ComRender*>(pCom); if (pTRender != nullptr) { pRender = pTRender; } else { _vecComs.push_back(pCom); } } else { CC_SAFE_RELEASE_NULL(pCom); } } if(_fnSelector != nullptr) { _fnSelector(pCom, (void*)(data)); } } setPropertyFromJsonDict(&tCocoLoader, tpRootCocoNode, _node); for (std::vector<Component*>::iterator iter = _vecComs.begin(); iter != _vecComs.end(); ++iter) { _node->addComponent(*iter); } stExpCocoNode *pGameObjects = tpChildArray[11].GetChildArray(&tCocoLoader); int length = tpChildArray[11].GetChildNum(); for (int i = 0; i < length; ++i) { createObject(&tCocoLoader, &pGameObjects[i], _node, attachComponent); } TriggerMng::getInstance()->parse(&tCocoLoader, tpChildArray); } } }while (0); return _node; } else { log("read file [%s] error!\n", fileName.c_str()); } return nullptr; }
Ads::Ads(QWidget *parent) : QWidget(parent) { createComponent(); input(); }
/** * Creates an entity component for the given entity from XML data. * Does not add it to the entity. */ virtual EntityComponent *createComponent(Entity *entity, EntityComponentTemplate *tpl) { return createComponent(entity); }
cocos2d::Node* SceneReader::createObject(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node* parent, AttachComponentType attachComponent) { const char *className = nullptr; stExpCocoNode *pNodeArray = cocoNode->GetChildArray(cocoLoader); std::string Key = pNodeArray[1].GetName(cocoLoader); if (Key == "classname") { className = pNodeArray[1].GetValue(cocoLoader); } if(strcmp(className, "CCNode") == 0) { Node* gb = nullptr; std::vector<Component*> _vecComs; ComRender *pRender = nullptr; int count = 0; std::string key = pNodeArray[13].GetName(cocoLoader); if (key == "components") { count = pNodeArray[13].GetChildNum(); } stExpCocoNode *pComponents = pNodeArray[13].GetChildArray(cocoLoader); SerData *data = new (std::nothrow) SerData(); for (int i = 0; i < count; ++i) { stExpCocoNode *subDict = pComponents[i].GetChildArray(cocoLoader); if (subDict == nullptr) { continue; } std::string key1 = subDict[1].GetName(cocoLoader); const char *comName = subDict[1].GetValue(cocoLoader); Component *pCom = nullptr; if (key1 == "classname" && comName != nullptr) { pCom = createComponent(comName); } CCLOG("classname = %s", comName); if (pCom != nullptr) { data->_rData = nullptr; data->_cocoNode = subDict; data->_cocoLoader = cocoLoader; if (pCom->serialize(data)) { ComRender *pTRender = dynamic_cast<ComRender*>(pCom); if (pTRender != nullptr) { pRender = pTRender; } else { _vecComs.push_back(pCom); } } else { CC_SAFE_RELEASE_NULL(pCom); } } if(_fnSelector != nullptr) { _fnSelector(pCom, (void*)(data)); } } CC_SAFE_DELETE(data); if (parent != nullptr) { if (pRender == nullptr || attachComponent == AttachComponentType::EMPTY_NODE) { gb = CCNode::create(); if (pRender != nullptr) { _vecComs.push_back(pRender); } } else { gb = pRender->getNode(); gb->retain(); pRender->setNode(nullptr); CC_SAFE_RELEASE_NULL(pRender); } parent->addChild(gb); } setPropertyFromJsonDict(cocoLoader, cocoNode, gb); for (std::vector<Component*>::iterator iter = _vecComs.begin(); iter != _vecComs.end(); ++iter) { gb->addComponent(*iter); } stExpCocoNode *pGameObjects = pNodeArray[12].GetChildArray(cocoLoader); if (pGameObjects != nullptr) { int length = pNodeArray[12].GetChildNum(); for (int i = 0; i < length; ++i) { createObject(cocoLoader, &pGameObjects[i], gb, attachComponent); } } return gb; } return nullptr; }
void TestMoveComponent::RunTests() { try { u64 version = 32; VPLTime_t time = 456; // trying to move non-existing component version++; time++; testMoveComponent("a", "b", version, time, DATASETDB_ERR_UNKNOWN_COMPONENT); // moving to itself is allowed. Just updates version and modtime of parent. version++; time++; createComponent("self", version, time); testGetComponentVersion("", DATASETDB_OK, version); testGetComponentLastModifyTime("", DATASETDB_OK, time); testGetComponentLastModifyTime("self", DATASETDB_OK, time); version++; time++; testMoveComponent("self", "self", version, time, DATASETDB_OK); // simple case: file in root version++; time++; createComponent("a", version, time); const VPLTime_t time_a = time; version++; time++; testMoveComponent("a", "b", version, time, DATASETDB_OK); confirmComponentVisible("b"); confirmComponentUnknown("a"); // Move will not change the time on the moved components. // It will change the time of the parents only. testGetComponentVersion("", DATASETDB_OK, version); testGetComponentLastModifyTime("", DATASETDB_OK, time); testGetComponentLastModifyTime("b", DATASETDB_OK, time_a); testGetComponentCreateTime("b", DATASETDB_OK, time_a); // nested case version++; time++; createComponent("p/q/r/s", version, time); const VPLTime_t time_pqrs = time; confirmComponentVisible("p"); confirmComponentVisible("p/q"); confirmComponentVisible("p/q/r"); confirmComponentVisible("p/q/r/s"); testGetComponentVersion("", DATASETDB_OK, version); testGetComponentVersion("p", DATASETDB_OK, version); testGetComponentVersion("p/q", DATASETDB_OK, version); testGetComponentVersion("p/q/r", DATASETDB_OK, version); testGetComponentVersion("p/q/r/s", DATASETDB_OK, version); testGetComponentLastModifyTime("", DATASETDB_OK, time); testGetComponentLastModifyTime("p", DATASETDB_OK, time); testGetComponentLastModifyTime("p/q", DATASETDB_OK, time); testGetComponentLastModifyTime("p/q/r", DATASETDB_OK, time_pqrs); testGetComponentLastModifyTime("p/q/r/s", DATASETDB_OK, time_pqrs); version++; time++; testMoveComponent("p/q/r", "p/t", version, time, DATASETDB_OK); confirmComponentVisible("p/t"); confirmComponentVisible("p/t/s"); confirmComponentUnknown("p/q/r"); confirmComponentUnknown("p/q/r/s"); testGetComponentVersion("", DATASETDB_OK, version); testGetComponentVersion("p", DATASETDB_OK, version); testGetComponentVersion("p/q", DATASETDB_OK, version); testGetComponentVersion("p/t", DATASETDB_OK, version); testGetComponentVersion("p/t/s", DATASETDB_OK, version); testGetComponentLastModifyTime("", DATASETDB_OK, time_pqrs); testGetComponentLastModifyTime("p", DATASETDB_OK, time); testGetComponentLastModifyTime("p/q", DATASETDB_OK, time); testGetComponentLastModifyTime("p/t", DATASETDB_OK, time_pqrs); testGetComponentLastModifyTime("p/t/s", DATASETDB_OK, time_pqrs); testPassed = true; } catch (...) { testPassed = false; } }