Example #1
0
//-------------------------------------------------------------------------------------
bool Components::checkComponents(int32 uid, COMPONENT_ID componentID)
{
#if KBE_PLATFORM == PLATFORM_WIN32
	return true;
#endif

	if(componentID <= 0)
		return true;

	int idx = 0;

	while(true)
	{
		COMPONENT_TYPE ct = ALL_COMPONENT_TYPES[idx++];
		if(ct == UNKNOWN_COMPONENT_TYPE)
			break;

		ComponentInfos* cinfos = findComponent(ct, uid, componentID);
		if(cinfos != NULL)
		{
			ERROR_MSG("Components::checkComponents: uid:%u, componentType=%s, componentID:%"PRAppID" exist.\n", 
				uid, COMPONENT_NAME[ct],  componentID);

			KBE_ASSERT(false && "Components::checkComponents: componentID exist.\n");
			return false;
		}
	}

	return true;
}
Example #2
0
/**
 * Handles mouse up events
 * @param button - Event information.
 */	
void WindowMainMenu::mouseUp(SDL_MouseButtonEvent button) {
	
	//Find out if a component was hit
	UIComponent *component = findComponent(button.x, button.y);
	
	if (component == buttonStart) {
		this->sounds.playSound(SOUND_CLICK);
		this->close(1);
	}
	
	// Creates the credits window and deletes it when returning to main menu
	else if (component == buttonCredits) {
		
		Window *window = new WindowCredits(this->graphics, this->sounds);
		
		this->sounds.playSound(SOUND_CLICK);
		window->open();
		
		if (window)
			delete window;
		
		redraw();
	}
	else if (component == buttonQuit) {
		this->sounds.playSound(SOUND_CLICK);
		this->close(0);
	}
}
Example #3
0
  //----------------------------------------------------------------------------
  bool XmlConfig::setParameter( const std::string& key,
                                const std::string& val,
                                const std::string& type )
  {
    if( !_config )
      return false;

    std::cout << "setParameter(key = " << key
                         << ", val = " << val
                         << ", type = " << type
                         << ")"
                         << std::endl;

    //resolve parts of identifier (Renderer:FeatureX) and find in config
    std::string valname;
    TiXmlNode* container = parseIdentifier(key, valname, true);

    if( key.length() > valname.length() + 1 )
    {
      std::string component_name =
        key.substr(0, key.length() - valname.length() - 1);
      Configurable* comp = findComponent(component_name);
      if( !comp )
        LOG_ERROR("No such component: " << component_name);
      else
        comp->setParameter(valname, val, type);
    }

    //check if exists
    TiXmlNode* node = container->FirstChild(valname);
    TiXmlElement* arg = 0;
    if( node )
    {
      arg = node->ToElement();

      //check if it matches
      int res = checkTypeMatch(key, arg, type);
      if(res == 1)
        arg->SetAttribute("type", type);
      else if(res == 0)
        return false;

    }
    else
    {
      //create new one
      arg = new TiXmlElement( valname );
      container->LinkEndChild(arg);
      arg->SetAttribute("type", type);
    }

    arg->SetAttribute("val", val);

    _dirty_write = true;

    saveFile(); // TODO check if multiple variables changed within small
                //      time window

    return true;
  }
Example #4
0
//-------------------------------------------------------------------------------------
bool Components::checkComponents(int32 uid, COMPONENT_ID componentID, uint32 pid)
{
	if(componentID <= 0)
		return true;

	int idx = 0;

	while(true)
	{
		COMPONENT_TYPE ct = ALL_COMPONENT_TYPES[idx++];
		if(ct == UNKNOWN_COMPONENT_TYPE)
			break;

		ComponentInfos* cinfos = findComponent(ct, uid, componentID);
		if(cinfos != NULL)
		{
			if(cinfos->componentType != MACHINE_TYPE && cinfos->pid != 0 /* 等于0通常是预设, 这种情况我们先不作比较 */ && pid != cinfos->pid)
			{
				ERROR_MSG(fmt::format("Components::checkComponents: uid:{}, componentType={}, componentID:{} exist.\n",
					uid, COMPONENT_NAME_EX(ct), componentID));

				KBE_ASSERT(false && "Components::checkComponents: componentID exist.\n");
			}
			return false;
		}
	}

	return true;
}
bool SystemTree::replaceSubsystem(int subsystemId, JausSubsystem newSubs)
{
	JausSubsystem currentSubs = system[subsystemId];
	if(!currentSubs)
	{
		addSubsystem(subsystemId, newSubs); // No subsystem to replace, so add the newSubs
		return true;
	}

	JausSubsystem cloneSubs = jausSubsystemClone(newSubs);
	if(!cloneSubs)
	{
		return false;
	}
	
	if(currentSubs->identification)
	{
		size_t stringLength = strlen(currentSubs->identification) + 1;
		cloneSubs->identification = (char *) realloc(cloneSubs->identification, stringLength);
		sprintf(cloneSubs->identification, "%s", currentSubs->identification);
	}

	for(int i = 0; i < cloneSubs->nodes->elementCount; i++)
	{
		JausNode cloneNode = (JausNode)cloneSubs->nodes->elementData[i];
		JausNode currentNode = findNode(cloneNode);
		if(currentNode)
		{
			if(currentNode->identification)
			{
				size_t stringLength = strlen(currentNode->identification) + 1;
				cloneNode->identification = (char *) realloc(cloneNode->identification, stringLength);
				sprintf(cloneNode->identification, "%s", currentNode->identification);
			}
			
			for(int i = 0; i < cloneNode->components->elementCount; i++)
			{
				JausComponent cloneCmpt = (JausComponent)cloneNode->components->elementData[i];
				JausComponent currentCmpt = findComponent(cloneCmpt);
				if(currentCmpt && currentCmpt->identification)
				{
					size_t stringLength = strlen(currentCmpt->identification) + 1;
					cloneCmpt->identification = (char *) realloc(cloneCmpt->identification, stringLength);
					sprintf(cloneCmpt->identification, "%s", currentNode->identification);
				}
			}
		}
	}
	jausSubsystemDestroy(system[subsystemId]);

	system[subsystemId] = cloneSubs;
	subsystemCount++;

	//char string[1024] = {0};
	//jausSubsystemTableToString(cloneSubs, string);
	//printf("Replaced Subsystem: \n%s\n", string);
	
	return true;
}
Example #6
0
void findComponent(const vector<vector<int> >& G, int v, set<int>& c) {
	c.insert(v);
	for(int i = 0; i < G[v].size(); ++i) {
		int x = G[v][i];
		if(c.count(x)) continue;
		findComponent(G, x, c);
	}
}
Example #7
0
//-------------------------------------------------------------------------------------		
void Components::addComponent(int32 uid, const char* username, 
			COMPONENT_TYPE componentType, COMPONENT_ID componentID, 
			uint32 intaddr, uint16 intport, 
			uint32 extaddr, uint16 extport, 
			Mercury::Channel* pChannel)
{
	COMPONENTS& components = getComponents(componentType);

	if(!checkComponents(uid, componentID))
		return;

	ComponentInfos* cinfos = findComponent(componentType, uid, componentID);
	if(cinfos != NULL)
	{
		WARNING_MSG("Components::addComponent[%s]: uid:%d, username:%s, "
			"componentType:%d, componentID:%"PRAppID" is exist!\n", 
			COMPONENT_NAME[(uint8)componentType], uid, username, (int32)componentType, componentID);
		return;
	}
	
	ComponentInfos componentInfos;

	componentInfos.pIntAddr.reset(new Mercury::Address(intaddr, intport));
	componentInfos.pExtAddr.reset(new Mercury::Address(extaddr, extport));
	componentInfos.uid = uid;
	componentInfos.cid = componentID;
	componentInfos.pChannel = pChannel;
	componentInfos.componentType = componentType;

	strncpy(componentInfos.username, username, MAX_NAME);

	if(cinfos == NULL)
		components.push_back(componentInfos);
	else
		*cinfos = componentInfos;

	_globalOrderLog[uid]++;

	switch(componentType)
	{
	case BASEAPP_TYPE:
		_baseappGrouplOrderLog[uid]++;
		break;
	case CELLAPP_TYPE:
		_cellappGrouplOrderLog[uid]++;
		break;
	case LOGINAPP_TYPE:
		_loginappGrouplOrderLog[uid]++;
		break;
	default:
		break;
	};

	INFO_MSG("Components::addComponent[%s], uid:%d, "
		"componentID:%"PRAppID", totalcount=%d\n", 
			COMPONENT_NAME[(uint8)componentType], uid, 
			componentID, components.size());
}
JausComponent SystemTree::getComponent(int subsystemId, int nodeId, int componentId, int instanceId)
{
	JausComponent cmpt = findComponent(subsystemId, nodeId, componentId, instanceId);
	if(cmpt)
	{
		return jausComponentClone(cmpt);
	}
	return NULL;
}
bool SystemTree::replaceNode(int subsystemId, int nodeId, JausNode newNode)
{
	JausNode currentNode = findNode(subsystemId, nodeId);
	if(!currentNode)
	{
		// No node to replace, so add the newNode
		addNode(subsystemId, nodeId, newNode);
		return true;
	}

	JausNode cloneNode = jausNodeCreate();
	if(!cloneNode)
	{
		return false;
	}
	cloneNode->id = currentNode->id;
	size_t stringLength = strlen(currentNode->identification) + 1;
	cloneNode->identification = (char *) realloc(cloneNode->identification, stringLength);
	sprintf(cloneNode->identification, "%s", currentNode->identification);
	cloneNode->subsystem = currentNode->subsystem;
	
	for(int i = 0; i < newNode->components->elementCount; i++)
	{
		JausComponent newCmpt = (JausComponent)newNode->components->elementData[i];
		JausComponent addCmpt = findComponent(newCmpt);
		if(addCmpt)
		{
			addCmpt = jausComponentClone(addCmpt);
		}
		else
		{
			addCmpt = jausComponentCreate();
			addCmpt->address->subsystem = subsystemId;
			addCmpt->address->node = nodeId;
			addCmpt->address->component = newCmpt->address->component;
			addCmpt->address->instance = newCmpt->address->instance;
		}
		addCmpt->node = cloneNode;
		jausArrayAdd(cloneNode->components, addCmpt);
	}

	for(int i = 0; i < system[subsystemId]->nodes->elementCount; i++)
	{
		JausNode node = (JausNode)system[subsystemId]->nodes->elementData[i];
		if(currentNode->id == node->id)
		{
			jausArrayRemoveAt(system[subsystemId]->nodes, i);
			jausNodeDestroy(node);
			break;
		}
	}
	
	cloneNode->subsystem = system[subsystemId];
	jausArrayAdd(system[subsystemId]->nodes, cloneNode);
	return true;
}
Example #10
0
bool sameComponents(const vector<vector<int> >& A, const vector<vector<int> >& B) {
	if(A.size() != B.size()) return false;
	int n = A.size();
	set<int> found;
	for(int v = 0; v < n; ++v) {
		if(found.count(v)) continue;
		set<int> cA, cB;
		findComponent(A, v, cA);
		findComponent(B, v, cB);
		if(cA.size() != cB.size()) return false;
		if(!std::equal(cA.begin(), cA.end(), cB.begin())) return false;
		
		for(set<int>::iterator i = cA.begin(); i != cA.end(); ++i) {
			found.insert(*i);
		}
	}
	
	return true;
}
Example #11
0
/**
 * Handles mouse up events
 */
void WindowCreateWorld::mouseUp(SDL_MouseButtonEvent button) {
	
	//Find out if a button was hit
	if (button.x > 824  &&  this->scrollMode == false) {
		UIComponent *component = findComponent(button.x, button.y);
	
		//Increase number of planets
		if (component == butMorePlanets) {
			if (this->numPlanets < MAX_PLANETS) {
				this->numPlanets++;
				this->sounds.playSound(SOUND_CLICK);
			} else {
				this->sounds.playSound(SOUND_TICK);
			}
			
			this->textNumPlanets->setText(numPlanets);
		}
		
		//Decrease number of planets
		else if (component == butLessPlanets) {
			if (this->numPlanets > MIN_PLANETS) {
				this->numPlanets--;
				this->sounds.playSound(SOUND_CLICK);
			} else {
				this->sounds.playSound(SOUND_TICK);
			}
			
			this->textNumPlanets->setText(numPlanets);
		}
		
		//'Create world' button
		else if (component == butCreate) {
			this->sounds.playSound(SOUND_CLICK);
			createWorld();
		}
		
		//'Finish' button
		else if (component == butStart) {
			this->sounds.playSound(SOUND_CLICK);
			this->close(1);
		}
		
		//'Back to main menu' button
		else if (component == butQuit) {
			this->close(0);
		}
	}

	//Deactivate scroll mode
	if (this->scrollMode) {
		SDL_WM_GrabInput(SDL_GRAB_OFF);
		SDL_ShowCursor(SDL_ENABLE);
		this->scrollMode = false;
	}
}
Example #12
0
/**
 * Handles mouse up events
 */
void WindowLocations::mouseUp(SDL_MouseButtonEvent button) {
	if (button.x > 824  &&  this->scrollMode == false) {
		//Clicking sidebar. Find out if a component was hit.
		UIComponent *component = findComponent(button.x, button.y);

		//'Next player' button
		if (component == butNext) {
			if (playerInTurn >= gameEngine.getPlayerCount())
				this->startGame();
			else
				this->nextPlayer();
		}
		
		//'Back to main menu' button
		else if (component == butQuit) {
			this->close(0);
		}
	} else {
		//Clicking game area
		
		//Convert to world coordinates
		Coordinates* coords = this->graphics.getWorldCoordinates(button.x, button.y);
		
		Player *player;
		Ai *ai = NULL;
		player = gameEngine.getPlayer(playerInTurn);
		
		if (player)
			ai = player->getAI();
		
		//If AI is in turn, disable controls
		if (ai)
			player = NULL;
			
		//Set location
		if (player  &&  this->dragDistance < 5) {
			if (player->setLocation(coords->getX(), coords->getY()) == 0) {
				this->sounds.playSound(SOUND_CLICK);
				nextPlayer();
			} else {
				this->sounds.playSound(SOUND_TICK);
			}
		}
		
		delete coords;
	}

	//Deactivate scroll mode
	if (this->scrollMode) {
		SDL_WM_GrabInput(SDL_GRAB_OFF);
		SDL_ShowCursor(SDL_ENABLE);
		this->scrollMode = false;
	}
}
Example #13
0
	static int objectFindComponent(lua_State* L)
	{
		luaL_checkany(L, 2);
		auto obj = checkarg<GameObject*>(L, 1);
		auto comp = checkarg<std::string&>(L, 2);

		Component* got = obj->findComponent(comp);
		if (got == nullptr || !got->accept(PushComponentVisitor(L)))
			lua_pushnil(L);

		return 1;
	}
bool SystemTree::setComponentServices(JausAddress address, JausArray inputServices)
{
	JausComponent cmpt = findComponent(address);
	if(cmpt)
	{
		// Remove current service set
		if(cmpt->services) jausServicesDestroy(cmpt->services);
		cmpt->services = jausServicesClone(inputServices);
		return true;
	}
	return false;
}
Example #15
0
bool Solution::isDestroyable()
{
	mark = new bool[nodes]{0};
	for (int i = 0; i < nodes; i++)
		if (!mark[i]) {
			int robotsInComponent = findComponent(i);
			///Two or more robots in the same connectivity component are always destroyable
			if (robotsInComponent == 1)
				return false;
		}
	return true;
}
bool SystemTree::hasComponentServices(int subsystemId, int nodeId, int componentId, int instanceId)
{
	JausComponent cmpt = findComponent(subsystemId, nodeId, componentId, instanceId);
	if(cmpt && cmpt->services->elementCount > 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
bool SystemTree::hasComponentIdentification(int subsystemId, int nodeId, int componentId, int instanceId)
{
	JausComponent cmpt = findComponent(subsystemId, nodeId, componentId, instanceId);
	if(cmpt && cmpt->identification)
	{
		return true;
	}
	else
	{
		return false;
	}
}
Example #18
0
void Dock::itemDropped (const SourceDetails& dragSourceDetails)
{
    int sourcePanelIndex = -1, sourcePanelSubIndex = -1,
        targetPanelIndex = -1, targetPanelSubIndex = -1;

	Point<int> p (dragSourceDetails.localPosition);
    Component* targetComponent = getComponentAt (p);

    if (findComponent (dragSourceDetails.sourceComponent, sourcePanelIndex, sourcePanelSubIndex)
        && findComponent (targetComponent, targetPanelIndex, targetPanelSubIndex))
    {
        panels.getUnchecked (sourcePanelIndex)->swapComponent (sourcePanelSubIndex,
                                                               panels.getUnchecked (targetPanelIndex),
                                                               targetPanelSubIndex);

        resized();
    }

    somethingIsBeingDraggedOver = false;
    repaint();
}
Example #19
0
/**
 * Handles mouse up events
 */
void WindowPlayers::mouseUp(SDL_MouseButtonEvent button) {

	//Find out if a button was hit
	UIComponent *component = findComponent(button.x, button.y);
	
	//'Start game' button
	if (component == buttonStart) {
		this->sounds.playSound(SOUND_CLICK);
		this->startGame();
	}
	
	//'Add player' button
	else if (component == butAdd) {
		addPlayer();
	}
	
	//Player type (increase)
	else if (component == butIncrType) {
		newPlayerType++;
		if (newPlayerType > 3)
			newPlayerType = 0;
	
		this->sounds.playSound(SOUND_CLICK);

		updatePlayerType();
	}
	
	//Player type (decrease)
	else if (component == butDecrType) {
		newPlayerType--;
		if (newPlayerType < 0)
			newPlayerType = 3;
			
		this->sounds.playSound(SOUND_CLICK);
		
		updatePlayerType();
	}
	
	//'Remove all' button
	else if (component == butRemoveAll) {
		gameEngine.removeAllPlayers();
		this->humanNumbering = 1;
		this->aiNumbering = 1;
		this->playerCount = 0;

		this->sounds.playSound(SOUND_TICK);

		updatePlayers();
	}
	
	redraw();
}
bool SystemTree::updateComponentTimestamp(JausAddress address)
{
	JausComponent cmpt = findComponent(address);
	if(cmpt)
	{
		jausComponentUpdateTimestamp(cmpt);
		return true;
	}
	else
	{
		return false;
	}
}
QTreeWidgetItem* QDisplayPropertyWidget::findGroup(const QString& component, const QString& group) const
{
    QTreeWidgetItem *componentItem = NULL;
    componentItem = findComponent(component);
    if(!componentItem)
        return NULL;

    QTreeWidgetItem *groupItem = NULL;
    for(unsigned int i = 0; (groupItem = componentItem->child(i)); ++i)
        if(groupItem->text(0) == group)
            break;

    return groupItem;
}
bool SystemTree::setComponentIdentification(JausAddress address, char *identification)
{
	JausComponent cmpt = findComponent(address);
	if(cmpt)
	{
		size_t stringLength = strlen(identification) + 1;
		cmpt->identification = (char *) realloc(cmpt->identification, stringLength);
		if(cmpt->identification)
		{
			sprintf(cmpt->identification, "%s", identification);
			return true;
		}
	}
	return false;
}
Example #23
0
int Solution::findComponent(int node)
{
	mark[node] = true;
	int res = robots->contains(node) ? 1 : 0;
	QSet<int> *adjacentNodes = edges->value(node);
	if (!adjacentNodes)
		return res;
	foreach(int intermediateNode, *adjacentNodes) {
		QSet<int> *nodes = edges->value(intermediateNode);
		if (!nodes)
			continue;
		foreach (int newNode, *nodes)
			if (!mark[newNode])
				res += findComponent(newNode);
	}
	return res;
}
Example #24
0
bool GameObject::addComponent(GameObjectComponent *component)
{
	bool wasAdded = false;

	const std::string &name = component->getComponentName();
	if (!findComponent(name))
	{
		_components.push_back(component);
		component->setParent(this);
		component->onAttachToParent();
        wasAdded = true;
        
        for(GameObjectComponent* comp : _components)
            comp->onParentChangedComponents();
	}

	return wasAdded;
}
Example #25
0
//-------------------------------------------------------------------------------------		
Components::ComponentInfos* Components::findComponent(COMPONENT_ID componentID)
{
	int idx = 0;
	int32 uid = getUserUID();

	while(true)
	{
		COMPONENT_TYPE ct = ALL_COMPONENT_TYPES[idx++];
		if(ct == UNKNOWN_COMPONENT_TYPE)
			break;

		ComponentInfos* cinfos = findComponent(ct, uid, componentID);
		if(cinfos != NULL)
		{
			return cinfos;
		}
	}

	return NULL;
}
Example #26
0
char* Device::execute(char* command) {
  split(command);
  Component &c = components[findComponent(command1)];
  if(!found) {
    //Serial.println("component not found");
    return "\n";
  }
  if(parameter1[0]=='\0') {
    //Serial.println("reading");
    char* r=c.read();
    return r;
  }
  else {
    //Serial.println("writing");
    return c.write(parameter1);
  }




  
}
Example #27
0
static void printTypedTree(int type, Tree *tree, unsigned index)
{
    int v, c;
    Tree *node;
    int numComp;
    if (!tree) {
        printf("?");
        return;
    }
    invariant(type != -1);
    invariant(guide.ssUniv[tree->d] >= 0);
    v = findVariant(tree, treetypes[type].numVariants, 0, &node, index);
    if (v == -1) {
        printf("?");
        return;
    }
    printf(treetypes[type].variantName[v]);
    numComp = treetypes[type].numComponents[v];
    if (numComp > 0) {
        printf("(");
        if (numComp > 1) {
            for (c = 0; c < numComp; c++) {
                if (c != 0)
                    printf(",");
                printTypedTree(treetypes[type].componentType[v][c],
                               findComponent(node, numComp, c),
                               index);
            }
        }
        else /* only one component, dummy on right */
            printTypedTree(treetypes[type].componentType[v][0],
                           node->left,
                           index);
        printf(")");
    }
}
Example #28
0
//-------------------------------------------------------------------------------------		
int Components::connectComponent(COMPONENT_TYPE componentType, int32 uid, COMPONENT_ID componentID, bool printlog)
{
	Components::ComponentInfos* pComponentInfos = findComponent(componentType, uid, componentID);
	if (pComponentInfos == NULL)
	{
		if (printlog)
		{
			ERROR_MSG(fmt::format("Components::connectComponent: not found componentType={}, uid={}, componentID={}!\n",
				COMPONENT_NAME_EX(componentType), uid, componentID));
		}

		return -1;
	}

	Network::EndPoint * pEndpoint = Network::EndPoint::createPoolObject();
	pEndpoint->socket(SOCK_STREAM);
	if (!pEndpoint->good())
	{
		if (printlog)
		{
			ERROR_MSG("Components::connectComponent: couldn't create a socket\n");
		}

		Network::EndPoint::reclaimPoolObject(pEndpoint);
		return -1;
	}

	pEndpoint->addr(*pComponentInfos->pIntAddr);
	int ret = pEndpoint->connect(pComponentInfos->pIntAddr->port, pComponentInfos->pIntAddr->ip);

	if(ret == 0)
	{
		Network::Channel* pChannel = Network::Channel::createPoolObject();
		bool ret = pChannel->initialize(*_pNetworkInterface, pEndpoint, Network::Channel::INTERNAL);
		if(!ret)
		{
			if (printlog)
			{
				ERROR_MSG(fmt::format("Components::connectComponent: initialize({}) is failed!\n",
					pChannel->c_str()));
			}

			pChannel->destroy();
			Network::Channel::reclaimPoolObject(pChannel);
			return -1;
		}

		pComponentInfos->pChannel = pChannel;
		pComponentInfos->pChannel->componentID(componentID);
		if(!_pNetworkInterface->registerChannel(pComponentInfos->pChannel))
		{
			if (printlog)
			{
				ERROR_MSG(fmt::format("Components::connectComponent: registerChannel({}) is failed!\n",
					pComponentInfos->pChannel->c_str()));
			}

			pComponentInfos->pChannel->destroy();
			Network::Channel::reclaimPoolObject(pComponentInfos->pChannel);

			// 此时不可强制释放内存,destroy中已经对其减引用
			// SAFE_RELEASE(pComponentInfos->pChannel);
			pComponentInfos->pChannel = NULL;
			return -1;
		}
		else
		{
			Network::Bundle* pBundle = Network::Bundle::createPoolObject();
			if(componentType == BASEAPPMGR_TYPE)
			{
				(*pBundle).newMessage(BaseappmgrInterface::onRegisterNewApp);
				
				BaseappmgrInterface::onRegisterNewAppArgs11::staticAddToBundle((*pBundle), getUserUID(), getUsername(), 
					componentType_, componentID_, 
					g_componentGlobalOrder, g_componentGroupOrder,
					_pNetworkInterface->intaddr().ip, _pNetworkInterface->intaddr().port,
					_pNetworkInterface->extaddr().ip, _pNetworkInterface->extaddr().port, g_kbeSrvConfig.getConfig().externalAddress);
			}
			else if(componentType == CELLAPPMGR_TYPE)
			{
				(*pBundle).newMessage(CellappmgrInterface::onRegisterNewApp);
				
				CellappmgrInterface::onRegisterNewAppArgs11::staticAddToBundle((*pBundle), getUserUID(), getUsername(), 
					componentType_, componentID_, 
					g_componentGlobalOrder, g_componentGroupOrder,
					_pNetworkInterface->intaddr().ip, _pNetworkInterface->intaddr().port,
					_pNetworkInterface->extaddr().ip, _pNetworkInterface->extaddr().port, g_kbeSrvConfig.getConfig().externalAddress);
			}
			else if(componentType == CELLAPP_TYPE)
			{
				(*pBundle).newMessage(CellappInterface::onRegisterNewApp);
				
				CellappInterface::onRegisterNewAppArgs11::staticAddToBundle((*pBundle), getUserUID(), getUsername(), 
					componentType_, componentID_, 
					g_componentGlobalOrder, g_componentGroupOrder,
						_pNetworkInterface->intaddr().ip, _pNetworkInterface->intaddr().port,
					_pNetworkInterface->extaddr().ip, _pNetworkInterface->extaddr().port, g_kbeSrvConfig.getConfig().externalAddress);
			}
			else if(componentType == BASEAPP_TYPE)
			{
				(*pBundle).newMessage(BaseappInterface::onRegisterNewApp);
				
				BaseappInterface::onRegisterNewAppArgs11::staticAddToBundle((*pBundle), getUserUID(), getUsername(), 
					componentType_, componentID_, 
					g_componentGlobalOrder, g_componentGroupOrder,
					_pNetworkInterface->intaddr().ip, _pNetworkInterface->intaddr().port,
					_pNetworkInterface->extaddr().ip, _pNetworkInterface->extaddr().port, g_kbeSrvConfig.getConfig().externalAddress);
			}
			else if(componentType == DBMGR_TYPE)
			{
				(*pBundle).newMessage(DbmgrInterface::onRegisterNewApp);
				
				DbmgrInterface::onRegisterNewAppArgs11::staticAddToBundle((*pBundle), getUserUID(), getUsername(), 
					componentType_, componentID_, 
					g_componentGlobalOrder, g_componentGroupOrder,
					_pNetworkInterface->intaddr().ip, _pNetworkInterface->intaddr().port,
					_pNetworkInterface->extaddr().ip, _pNetworkInterface->extaddr().port, g_kbeSrvConfig.getConfig().externalAddress);
			}
			else if(componentType == LOGGER_TYPE)
			{
				(*pBundle).newMessage(LoggerInterface::onRegisterNewApp);
				
				LoggerInterface::onRegisterNewAppArgs11::staticAddToBundle((*pBundle), getUserUID(), getUsername(), 
					componentType_, componentID_, 
					g_componentGlobalOrder, g_componentGroupOrder,
					_pNetworkInterface->intaddr().ip, _pNetworkInterface->intaddr().port,
					_pNetworkInterface->extaddr().ip, _pNetworkInterface->extaddr().port, g_kbeSrvConfig.getConfig().externalAddress);
			}
			else
			{
				KBE_ASSERT(false && "invalid componentType.\n");
			}

			pComponentInfos->pChannel->send(pBundle);
		}
	}
	else
	{
		if (printlog)
		{
			ERROR_MSG(fmt::format("Components::connectComponent: connect({}) is failed! {}.\n",
				pComponentInfos->pIntAddr->c_str(), kbe_strerror()));
		}

		Network::EndPoint::reclaimPoolObject(pEndpoint);
		return -1;
	}

	return ret;
}
Example #29
0
//-------------------------------------------------------------------------------------		
void Components::addComponent(int32 uid, const char* username, 
			COMPONENT_TYPE componentType, COMPONENT_ID componentID, COMPONENT_ORDER globalorderid, COMPONENT_ORDER grouporderid, COMPONENT_GUS gus,
			uint32 intaddr, uint16 intport, uint32 extaddr, uint16 extport, std::string& extaddrEx, uint32 pid,
			float cpu, float mem, uint32 usedmem, uint64 extradata, uint64 extradata1, uint64 extradata2, uint64 extradata3,
			Network::Channel* pChannel)
{
	COMPONENTS& components = getComponents(componentType);

	if(!checkComponents(uid, componentID, pid))
		return;

	ComponentInfos* cinfos = findComponent(componentType, uid, componentID);
	if(cinfos != NULL)
	{
		WARNING_MSG(fmt::format("Components::addComponent[{}]: uid:{}, username:{}, "
			"componentType:{}, componentID:{} is exist!\n",
			COMPONENT_NAME_EX(componentType), uid, username, (int32)componentType, componentID));
		return;
	}
	
	// 如果该uid下没有已经运行的任何相关组件,那么重置计数器
	if (getGameSrvComponentsSize(uid) == 0)
	{
		_globalOrderLog[uid] = 0;
		_baseappGrouplOrderLog[uid] = 0;
		_cellappGrouplOrderLog[uid] = 0;
		_loginappGrouplOrderLog[uid] = 0;

		INFO_MSG(fmt::format("Components::addComponent: reset orderLog, uid={}!\n",
			uid));
	}

	ComponentInfos componentInfos;

	componentInfos.pIntAddr.reset(new Network::Address(intaddr, intport));
	componentInfos.pExtAddr.reset(new Network::Address(extaddr, extport));

	if(extaddrEx.size() > 0)
		strncpy(componentInfos.externalAddressEx, extaddrEx.c_str(), MAX_NAME);
	
	componentInfos.uid = uid;
	componentInfos.cid = componentID;
	componentInfos.pChannel = pChannel;
	componentInfos.componentType = componentType;
	componentInfos.groupOrderid = 1;
	componentInfos.globalOrderid = 1;

	componentInfos.mem = mem;
	componentInfos.cpu = cpu;
	componentInfos.usedmem = usedmem;
	componentInfos.extradata = extradata;
	componentInfos.extradata1 = extradata1;
	componentInfos.extradata2 = extradata2;
	componentInfos.extradata3 = extradata3;
	componentInfos.pid = pid;

	if(pChannel)
		pChannel->componentID(componentID);

	strncpy(componentInfos.username, username, MAX_NAME);

	_globalOrderLog[uid]++;

	switch(componentType)
	{
	case BASEAPP_TYPE:
		_baseappGrouplOrderLog[uid]++;
		componentInfos.groupOrderid = _baseappGrouplOrderLog[uid];
		break;
	case CELLAPP_TYPE:
		_cellappGrouplOrderLog[uid]++;
		componentInfos.groupOrderid = _cellappGrouplOrderLog[uid];
		break;
	case LOGINAPP_TYPE:
		_loginappGrouplOrderLog[uid]++;
		componentInfos.groupOrderid = _loginappGrouplOrderLog[uid];
		break;
	default:
		break;
	};
	
	if(grouporderid > 0)
		componentInfos.groupOrderid = grouporderid;

	if(globalorderid > 0)
		componentInfos.globalOrderid = globalorderid;
	else
		componentInfos.globalOrderid = _globalOrderLog[uid];

	componentInfos.gus = gus;

	if(cinfos == NULL)
		components.push_back(componentInfos);
	else
		*cinfos = componentInfos;

	INFO_MSG(fmt::format("Components::addComponent[{}], uid={}, "
		"componentID={}, globalorderid={}, grouporderid={}, totalcount={}\n",
			COMPONENT_NAME_EX(componentType), 
			uid,
			componentID, 
			((int32)componentInfos.globalOrderid),
			((int32)componentInfos.groupOrderid),
			components.size()));
	
	if(_pHandler)
		_pHandler->onAddComponent(&componentInfos);
}
Example #30
0
void
LCPBar::setValue(int num, int value, int diff)
{
    std::ostringstream compname;
    compname << "pbar_text" << (num+1);
    Paragraph* p = getParagraph(*this, compname.str());

    std::ostringstream os;
    os<<std::fixed;
    os<<std::setprecision(1);
    if(num==PTECH)
    {
        os<<value/10000.0;
     }
    else if(num==PMONEY)
    {
        if(abs(value)>=1000000000)
            os<<value/1000000<<"M";
        else if(abs(value)>1000000)
            os<<value/1000000.0<<"M";
        else if(abs(value)>1000)
            os<<value/1000.0<<"K";
        else
            os<<value;
    }
    else
        os<<value;
    if( diff != 0 ){
        p->setText(os.str());
    }
    os.str("");
    os<<"pbar_barview"<<(num+1);

    float sv=0;
    switch(num)
    {
      case PPOP:
        sv=pbar_adjust_pop(diff);
        break;
      case PTECH:
        sv=pbar_adjust_tech(diff);
        break;
      case PFOOD:
        sv=pbar_adjust_food(diff);break;
      case PJOBS:
        sv=pbar_adjust_jobs(diff);break;
      case PCOAL:
        sv=pbar_adjust_coal(diff);break;
      case PGOODS:
        sv=pbar_adjust_goods(diff);break;
      case PORE:
        sv=pbar_adjust_ore(diff);break;
      case PSTEEL:
        sv=pbar_adjust_steel(diff);break;
      case PMONEY:
        sv=pbar_adjust_money(diff);break;
      };
      
    sv/=10.0;
    
    
     if(sv>1.0)
      sv=1.0;
     if(sv<-1.0)
      sv=-1.0; 
        
    Component *c=findComponent(os.str()+"a");
    if(c)
    {
      BarView *bv=dynamic_cast<BarView*>(c);
      if(bv)
      {
        bv->setValue(sv);
      }
    }
    c=findComponent(os.str()+"b");
    if(c)
    {
      BarView *bv=dynamic_cast<BarView*>(c);
      if(bv)
      {
        bv->setValue(sv);
      }
    }
    
}