Example #1
0
void DiscoItemsConvertor::doConvertToLua(lua_State* L, std::shared_ptr<DiscoItems> payload) {
    lua_newtable(L);
    if (!payload->getNode().empty()) {
        lua_pushstring(L, payload->getNode().c_str());
        lua_setfield(L, -2, "node");
    }
    const std::vector<DiscoItems::Item>& items = payload->getItems();
    if (!items.empty()) {
        lua_createtable(L, boost::numeric_cast<int>(items.size()), 0);
        for (size_t i = 0; i < items.size(); ++i) {
            lua_createtable(L, 0, 0);
            if (!items[i].getName().empty()) {
                lua_pushstring(L, items[i].getName().c_str());
                lua_setfield(L, -2, "name");
            }
            if (!items[i].getNode().empty()) {
                lua_pushstring(L, items[i].getNode().c_str());
                lua_setfield(L, -2, "node");
            }
            if (items[i].getJID().isValid()) {
                lua_pushstring(L, items[i].getJID().toString().c_str());
                lua_setfield(L, -2, "jid");
            }
            lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
        }
        lua_setfield(L, -2, "items");
    }
}
void PubSubOwnerConfigureConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubOwnerConfigure> payload) {
    lua_createtable(L, 0, 0);
    if (payload->getNode()) {
        lua_pushstring(L, (*payload->getNode()).c_str());
        lua_setfield(L, -2, "node");
    }
    if (convertors->convertToLuaUntyped(L, payload->getData()) > 0) {
        lua_setfield(L, -2, "data");
    }
}
std::string PubSubOwnerConfigureSerializer::serializePayload(std::shared_ptr<PubSubOwnerConfigure> payload) const {
    if (!payload) {
        return "";
    }
    XMLElement element("configure", "http://jabber.org/protocol/pubsub#owner");
    if (payload->getNode()) {
        element.setAttribute("node", *payload->getNode());
    }
    element.addNode(std::make_shared<XMLRawTextNode>(FormSerializer().serialize(payload->getData())));
    return element.serialize();
}
void PubSubEventCollectionConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubEventCollection> payload) {
    lua_createtable(L, 0, 0);
    if (payload->getNode()) {
        lua_pushstring(L, (*payload->getNode()).c_str());
        lua_setfield(L, -2, "node");
    }
    if (convertors->convertToLuaUntyped(L, payload->getDisassociate()) > 0) {
        lua_setfield(L, -2, "disassociate");
    }
    if (convertors->convertToLuaUntyped(L, payload->getAssociate()) > 0) {
        lua_setfield(L, -2, "associate");
    }
}
void PubSubUnsubscribeConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubUnsubscribe> payload) {
    lua_createtable(L, 0, 0);
    if (payload->getNode()) {
        lua_pushstring(L, (*payload->getNode()).c_str());
        lua_setfield(L, -2, "node");
    }
    lua_pushstring(L, payload->getJID().toString().c_str());
    lua_setfield(L, -2, "jid");
    if (payload->getSubscriptionID()) {
        lua_pushstring(L, (*payload->getSubscriptionID()).c_str());
        lua_setfield(L, -2, "subscription_id");
    }
}
std::string PubSubUnsubscribeSerializer::serializePayload(std::shared_ptr<PubSubUnsubscribe> payload) const {
    if (!payload) {
        return "";
    }
    XMLElement element("unsubscribe", "http://jabber.org/protocol/pubsub");
    if (payload->getNode()) {
        element.setAttribute("node", *payload->getNode());
    }
    element.setAttribute("jid", payload->getJID());
    if (payload->getSubscriptionID()) {
        element.setAttribute("subid", *payload->getSubscriptionID());
    }
    return element.serialize();
}
void PubSubEventDeleteConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubEventDelete> payload) {
    lua_createtable(L, 0, 0);
    lua_pushstring(L, payload->getNode().c_str());
    lua_setfield(L, -2, "node");
    if (convertors->convertToLuaUntyped(L, payload->getRedirects()) > 0) {
        lua_setfield(L, -2, "redirects");
    }
}
	void putWormLikeSpring(size_t n1, size_t n2) {

		auto p1 = model->getNode(n1);
		auto p2 = model->getNode(n2);
		double length = glm::length(p1->getPosition() - p2->getPosition());
		auto spring = std::make_shared<WormLikeChainForce>(n1, n2, length, defaultTemperature, defaultPersistanceLength, defaultContourLengthMultipler);
		model->constraints.insert(spring);
	}
	void putLinearSpring(size_t n1, size_t n2) {

		auto p1 = model->getNode(n1);
		auto p2 = model->getNode(n2);
		double length = glm::length(p1->getPosition() - p2->getPosition());
		auto spring = std::make_shared<SpringForce>(n1, n2, length, defaultSpringStiffness);
		model->constraints.insert(spring);
	}
std::string PubSubEventPurgeSerializer::serializePayload(std::shared_ptr<PubSubEventPurge> payload) const {
    if (!payload) {
        return "";
    }
    XMLElement element("purge", "http://jabber.org/protocol/pubsub#event");
    element.setAttribute("node", payload->getNode());
    return element.serialize();
}
std::string PubSubEventConfigurationSerializer::serializePayload(std::shared_ptr<PubSubEventConfiguration> payload) const {
    if (!payload) {
        return "";
    }
    XMLElement element("configuration", "http://jabber.org/protocol/pubsub#event");
    element.setAttribute("node", payload->getNode());
    element.addNode(std::make_shared<XMLRawTextNode>(FormSerializer().serialize(payload->getData())));
    return element.serialize();
}
	void putTorsionSpring(size_t n1, size_t n2, size_t n3) {

		//if (n2 >= 15 && n2 <= 19)
		//	return;

		auto leftNode = model->getNode(n1);
		auto centerNode = model->getNode(n2);
		auto rightNode = model->getNode(n3);

		glm::dvec3 p1 = leftNode->getPosition() - centerNode->getPosition();
		glm::dvec3 p2 = rightNode->getPosition() - centerNode->getPosition();

		double cos_theta = glm::dot(p1,p2) / glm::length(p1) / glm::length(p2);
		double theta = ::acos(cos_theta); // всегда в пределах [0;pi]

		auto torsionSpring = std::make_shared<TorsionSpringForce>(n1, n2, n3, defaultTorsionSpringStiffness, theta);
		model->constraints.insert(torsionSpring);
	}
void PubSubSubscriptionsConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubSubscriptions> payload) {
    lua_createtable(L, 0, 0);
    if (payload->getNode()) {
        lua_pushstring(L, (*payload->getNode()).c_str());
        lua_setfield(L, -2, "node");
    }
    if (!payload->getSubscriptions().empty()) {
        {
            int i = 0;
            for (auto&& item : payload->getSubscriptions()) {
                if (convertors->convertToLuaUntyped(L, item) > 0) {
                    lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
                    ++i;
                }
            }
        }
    }
}
std::string PubSubOptionsSerializer::serializePayload(std::shared_ptr<PubSubOptions> payload) const {
    if (!payload) {
        return "";
    }
    XMLElement element("options", "http://jabber.org/protocol/pubsub");
    element.setAttribute("node", payload->getNode());
    element.setAttribute("jid", payload->getJID());
    element.addNode(std::make_shared<XMLRawTextNode>(FormSerializer().serialize(payload->getData())));
    if (payload->getSubscriptionID()) {
        element.setAttribute("subid", *payload->getSubscriptionID());
    }
    return element.serialize();
}
/*
	traverse():
*/
bool MazeTraverseAStar::traverse(int32_t startX, int32_t startY
	, int32_t finishX, int32_t finishY
	, const std::shared_ptr<maze::Maze> maze)
{
	assert(maze);

	_finish.x = finishX;
	_finish.y = finishY;

	// Get Maze Width
	_width = maze->width();
	_height = maze->height();
	//bool found = false;


	// Initialise sCell States
	_cells.reserve(_width * _height);
	
	for (uint32_t i = 0; i < _cells.capacity(); ++i)
	{
		AStarCell cell;
		//cell.queued = false;
		cell.visited = false;
		cell.pathX = -1;
		cell.pathY = -1;
		cell.bestCost = -1;

		_cells.push_back(cell);
	}

	// Push Starting Node
	pushStart(startX, startY, 0);

	// Continue while Nodes are still available :)
	while (!_queue.empty())
	{
		// Get First Node
		const AStarPriority & priority = pop();
		
		// Is this the finsh Node? Set Found Flag
		if (priority.x == finishX && priority.y == finishY)
		{
		//	found = true;

		//	std::cout << "ASTAR: Path is found : " << std::endl;
			break;
		}
		
		// Get Maze Node
		const maze::MazeNode & node = maze->getNode(priority.x, priority.y);

		// Push Adjacent Nodes
		for (const maze::MazeCell & adjacent : node.adjacent)
		{
			// Push Node Onto Queue
			push(priority, adjacent.x, adjacent.y, 1);
		}
	}

	// Build the Path Edges
	buildPath();

	return true;
}
void PubSubEventPurgeConvertor::doConvertToLua(lua_State* L, std::shared_ptr<PubSubEventPurge> payload) {
    lua_createtable(L, 0, 0);
    lua_pushstring(L, payload->getNode().c_str());
    lua_setfield(L, -2, "node");
}
Example #17
0
void InputConnection::connectHalf(std::shared_ptr<OutputConnection> outputConnection) {
	auto n = std::static_pointer_cast<Node>(outputConnection->getNode()->shared_from_this());
	connected_to[outputConnection] = n;
}
/*
	traverse():
*/
bool MazeTraversalTremaux::traverse(int32_t startX, int32_t startY
	, int32_t finishX, int32_t finishY
	, const std::shared_ptr<maze::Maze> maze)
{
//	std::cout << "TREMAUX: START" << std::endl;

	// Set Dimensions
	_width = maze->width();
	_height = maze->height();

	// Create Tremaux Cell Map
	_cells.reserve(maze->width() * maze->height());
	for (uint32_t i = 0; i < _cells.capacity(); ++i)
		_cells.push_back(0);
	
	// Push Opening Cell
	push(startX, startY);

	// Loop while things remain in the stack
	while (! _stack.empty())
	{
		// Set Previous Cell
		//previous = cell;

		// Get the topmost Cell
		maze::MazeCell cell = _stack.top();
		
		// Get the Cell Data
		const maze::MazeNode & node = maze->getNode(cell.x, cell.y);

		// Finished ?
		if (node.x == finishX && node.y == finishY)
			break;
		
		// Determine Available Pathways
		std::vector<maze::MazeCell> paths;

		for (const maze::MazeCell & adj : node.adjacent)
		{
			TremauxCell & tremauxAdj = getCell(adj.x, adj.y);

			if (tremauxAdj == UNVISITED)
				paths.push_back(adj);
		}

		// Decide what to do from here.
		if (paths.size() == DEADEND)
		{
			// Is this a dead-end ?? Requires 1 adjacent cell

			// This is a dead-end.
			// Nowhere new to travel. 
			// Backtracking
			// Pop the Cell

			pop();
		}
		else
		{
			// Is this a Junction ?? Requires 3 or more adjacent 
			// cells, that haven't already been travelled : Push Cell

			// Is this a pathway ?? Requires 2 adjacent cells 
			// that haven't already been travelled : Push Cell

			// Choose which path go down
			int32_t index = rand() % paths.size();

			push(paths[index].x, paths[index].y);
		}
	}

	// Path not found
	if (_stack.empty())
	{
		return false;
	}

	// Backtrack along the path...
	while (! _stack.empty())
	{
		// Get topmost cell
		maze::MazeCell & cell = _stack.top();

		// Add to path list
		_path.insert(_path.begin(), cell);

		// Pop Cell
		_stack.pop();
	}

	return true;
}