Beispiel #1
0
void TileBuilder::applyStyling(const Feature& _feature, const SceneLayer& _layer) {

    // If no rules matched the feature, return immediately
    if (!m_ruleSet.match(_feature, _layer, m_styleContext)) { return; }

    uint32_t selectionColor = 0;
    bool added = false;

    // For each matched rule, find the style to be used and
    // build the feature with the rule's parameters
    for (auto& rule : m_ruleSet.matchedRules()) {

        StyleBuilder* style = getStyleBuilder(rule.getStyleName());

        if (!style) {
            LOGN("Invalid style %s", rule.getStyleName().c_str());
            continue;
        }

        // Apply defaul draw rules defined for this style
        style->style().applyDefaultDrawRules(rule);

        if (!m_ruleSet.evaluateRuleForContext(rule, m_styleContext)) {
            continue;
        }

        bool interactive = false;
        if (rule.get(StyleParamKey::interactive, interactive) && interactive) {
            if (selectionColor == 0) {
                selectionColor = m_scene->featureSelection()->nextColorIdentifier();
            }
            rule.selectionColor = selectionColor;
            rule.featureSelection = m_scene->featureSelection().get();
        } else {
            rule.selectionColor = 0;
        }

        // build outline explicitly with outline style
        const auto& outlineStyleName = rule.findParameter(StyleParamKey::outline_style);
        if (outlineStyleName) {
            auto& styleName = outlineStyleName.value.get<std::string>();
            auto* outlineStyle = getStyleBuilder(styleName);
            if (!outlineStyle) {
                LOGN("Invalid style %s", styleName.c_str());
            } else {
                rule.isOutlineOnly = true;
                outlineStyle->addFeature(_feature, rule);
                rule.isOutlineOnly = false;
            }
        }

        // build feature with style
        added |= style->addFeature(_feature, rule);
    }

    if (added && (selectionColor != 0)) {
        m_selectionFeatures[selectionColor] = std::make_shared<Properties>(_feature.props);
    }
}
Beispiel #2
0
void Style::setupShaderUniforms(RenderState& rs, Scene& _scene) {
    for (auto& uniformPair : m_styleUniforms) {
        const auto& name = uniformPair.first;
        auto& value = uniformPair.second;

        if (value.is<std::string>()) {
            std::string textureName = value.get<std::string>();
            std::shared_ptr<Texture> texture = _scene.getTexture(textureName);

            if (!texture) {
                LOGN("Texture with texture name %s is not available to be sent as uniform",
                    textureName.c_str());
                continue;
            }

            texture->update(rs, rs.nextAvailableTextureUnit());
            texture->bind(rs, rs.currentTextureUnit());

            m_shaderProgram->setUniformi(rs, name, rs.currentTextureUnit());
        } else {

            if (value.is<bool>()) {
                m_shaderProgram->setUniformi(rs, name, value.get<bool>());
            } else if(value.is<float>()) {
                m_shaderProgram->setUniformf(rs, name, value.get<float>());
            } else if(value.is<glm::vec2>()) {
                m_shaderProgram->setUniformf(rs, name, value.get<glm::vec2>());
            } else if(value.is<glm::vec3>()) {
                m_shaderProgram->setUniformf(rs, name, value.get<glm::vec3>());
            } else if(value.is<glm::vec4>()) {
                m_shaderProgram->setUniformf(rs, name, value.get<glm::vec4>());
            } else if (value.is<UniformArray1f>()) {
                m_shaderProgram->setUniformf(rs, name, value.get<UniformArray1f>());
            } else if (value.is<UniformTextureArray>()) {
                UniformTextureArray& textureUniformArray = value.get<UniformTextureArray>();
                textureUniformArray.slots.clear();

                for (const auto& textureName : textureUniformArray.names) {
                    std::shared_ptr<Texture> texture = _scene.getTexture(textureName);

                    if (!texture) {
                        LOGN("Texture with texture name %s is not available to be sent as uniform",
                            textureName.c_str());
                        continue;
                    }

                    texture->update(rs, rs.nextAvailableTextureUnit());
                    texture->bind(rs, rs.currentTextureUnit());

                    textureUniformArray.slots.push_back(rs.currentTextureUnit());
                }

                m_shaderProgram->setUniformi(rs, name, textureUniformArray);
            }
        }
    }
}
Beispiel #3
0
void read_client_id(int listenfd, char *buf, int len,int index){
	ssize_t nread;
	if((nread = readn(listenfd, buf, len)) < 0){		/*read error*/
		LOGN("server", LOG_ERROR, "read error,%s",strerror(errno));
		exit(-1);
	} 
#if DEBUG
	LOGN("server", LOG_DEBUG, "pthread %d read %s", index, buf);	
#endif
	return ;

}
bool TextStyleBuilder::prepareLabel(TextStyle::Parameters& _params, Label::Type _type) {

    if (_params.text.empty() || _params.fontSize <= 0.f) {
        LOGD("invalid params: '%s' %f", _params.text.c_str(), _params.fontSize);
        return false;
    }

    // Apply text transforms
    const std::string* renderText;
    std::string text;

    if (_params.transform == TextLabelProperty::Transform::none) {
        renderText = &_params.text;
    } else {
        text = applyTextTransform(_params, _params.text);
        renderText = &text;
    }

    // Scale factor by which the texture glyphs are scaled to match fontSize
    _params.fontScale = _params.fontSize / _params.font->size();

    // Stroke width is normalized by the distance of the SDF spread, then
    // scaled to 255 and packed into the "alpha" channel of stroke.
    // Maximal strokeWidth is 3px, attribute is normalized to 0-1 range.

    auto ctx = m_style.context();

    uint32_t strokeAttrib = std::max(_params.strokeWidth / ctx->maxStrokeWidth() * 255.f, 0.f);
    if (strokeAttrib > 255) {
        LOGN("stroke_width too large: %f / %f", _params.strokeWidth, strokeAttrib/255.f);
        strokeAttrib = 255;
    }
    m_attributes.stroke = (_params.strokeColor & 0x00ffffff) + (strokeAttrib << 24);
    m_attributes.fill = _params.fill;
    m_attributes.fontScale = _params.fontScale * 64.f;
    if (m_attributes.fontScale > 255) {
        LOGN("Too large font scale %f, maximal scale is 4", _params.fontScale);
        m_attributes.fontScale = 255;
    }
    m_attributes.quadsStart = m_quads.size();

    m_attributes.textRanges = TextRange{};

    glm::vec2 bbox(0);
    if (ctx->layoutText(_params, *renderText, m_quads, m_atlasRefs, bbox, m_attributes.textRanges)) {
        m_attributes.width = bbox.x;
        m_attributes.height = bbox.y;
        return true;
    }
    return false;
}
Beispiel #5
0
void Close(int fd){	
	if (close(fd) == -1){
		perror("close error");
		LOGN("server", LOG_ERROR, "close error");
		exit(-1);
	}
}
Beispiel #6
0
Socket::SendStatus Socket::sendBuffer(void) {
    while (m_sendBufferEnd != m_sendBufferPos) {
        if (!waitForSocket(POLLOUT)) {
            LOGD("No POLLOUT event");
            return SendStatus::PARTIAL_DATA_SENT;
        }

        ssize_t t = TEMP_FAILURE_RETRY(send(m_sock, m_sendBuffer.data() + m_sendBufferPos,
                                            m_sendBufferEnd - m_sendBufferPos, MSG_NOSIGNAL));
        if (t == -1) {
            int err = errno;
            switch (err) {
                case EAGAIN:
#if EWOULDBLOCK != EAGAIN
                case EWOULDBLOCK:
#endif
                    continue;
                case ENOMEM:
                    throw NoMemoryException("'send' function failed due to ENOMEM");
                case EPIPE:
                    LOGN("Connection closed by server");
                    return SendStatus::CONNECTION_LOST;
                default:
                    LOGE("'send' function error [%d] : <%s>", err, strerror(err));
                    throw UnexpectedErrorException(err, strerror(err));
            }
        }
        m_sendBufferPos += static_cast<size_t>(t);
    }
    return SendStatus::ALL_DATA_SENT;
}
Beispiel #7
0
void ValidationMap::log(std::string logger) const {
    for (auto section_it = sections.begin(); section_it != sections.end(); ++section_it) {
        auto messages = section_it->second.getMessages();
        if (messages.empty())
            continue;

        if (isCritical()) {
            LOGN(ERROR, logger) << section_it->first << ":";
            for (auto it = messages.begin(); it != messages.end(); ++it)
                LOGN(ERROR, logger) << " - " << *it;
        } else {
            LOGN(WARNING, logger) << section_it->first << ":";
            for (auto it = messages.begin(); it != messages.end(); ++it)
                LOGN(WARNING, logger) << " - " << *it;
        }
    }
}
Beispiel #8
0
/**
 * @brief 			创建我们的工作线程,监听服务套接字
 * @param index 		表示是监听线程池中的第几个线程
 * @param listenfd 	要监听的套接字描述符
 */
int thread_make(int index, int listenfd){
	int n;

	if((n = pthread_create(&(tptr[index].thread_tid), NULL, &thread_main, (void *)(MAKEWORD(index, listenfd)))) == 0 ){
		return 0;
	}
	errno = n;				/*创建线程失败*/
#if DEBUG
	LOGN("server", LOG_DEBUG, "pthread_create %d error", index);
#endif
	return -1;			/*一个线程出错,其他线程可以继续产生,所以不直接退出*/
}
Beispiel #9
0
int	PLoginGLObject::Execute(IPackHead* pPackHead)
{
	switch (pPackHead->GetPacketDefine2())
	{
	case PACKET2_LOGIN_GL:
	//	g_NetObjectManager.AddLS(pPackHead->GetNetObject());
		LOGN("PLoginGLObject::Execute, PACKET2_LOGIN_GL.add:%x \n", pPackHead);

		break;
	default:
		//IF(pPackHead->GetPacketDefine2())
		LOGE("PLoginGLObject::Execute. case default:%d. add:%x\n", pPackHead->GetPacketDefine2(), pPackHead);

	}
	return 0;
}
Beispiel #10
0
void Importer::mergeMapFields(Node& target, const Node& import) {

    for (const auto& entry : import) {

        const auto& key = entry.first.Scalar();
        const auto& source = entry.second;
        auto dest = target[key];

        if (!dest) {
            dest = source;
            continue;
        }

        if (dest.Type() != source.Type()) {
            LOGN("Merging different node types: '%s'\n'%s'\n<==\n'%s'",
                 key.c_str(), Dump(dest).c_str(), Dump(source).c_str());
        }

        switch(dest.Type()) {
            case NodeType::Null:
            case NodeType::Scalar:
            case NodeType::Sequence:
                dest = source;
                break;

            case NodeType::Map: {
                auto newTarget = dest;
                if (source.IsMap()) {
                    mergeMapFields(newTarget, source);
                } else {
                    dest = source;
                }
                break;
            }
            default:
                // NodeType::Undefined is handled above by checking (!dest).
                // All types are handled, so this should never be reached.
                assert(false);
                break;
        }
    }
}
Beispiel #11
0
void MapLayer::onTouchMoved(cocos2d::Touch *touch, cocos2d::Event* event)
{
	/*
	Point mouseMove = touch->getLocation() - m_moveStartMousePos;
	
	Point curPos = this->getPosition();

	curPos.x += diff.x;
	curPos.x += diff.x;

	this->setPosition( curPos );

	*/
//	LOGN( "들어오죠?!" );

	Point delta = touch->getDelta();

	LOGN( "%g, %g", delta.x, delta.y );

	this->setPosition( this->getPosition() + delta );
}
Beispiel #12
0
void InMemoryStorageBackend::load(void) {
    bool isBackupValid = m_integrity.backupGuardExists();
    std::string bucketSuffix = "";
    std::string indexFilename = m_dbPath + m_indexFilename;
    std::string chsFilename = m_dbPath + m_chsFilename;

    if (isBackupValid) {
        bucketSuffix += m_backupFilenameSuffix;
        indexFilename += m_backupFilenameSuffix;
        chsFilename += m_backupFilenameSuffix;
    }

    try {
        std::ifstream chsStream;
        openFileStream(chsStream, chsFilename, isBackupValid);
        m_checksum.load(chsStream);

        auto indexStream = std::make_shared<std::ifstream>();
        openFileStream(*indexStream, indexFilename, isBackupValid);

        StorageDeserializer storageDeserializer(indexStream,
            std::bind(&InMemoryStorageBackend::bucketStreamOpener, this,
                      std::placeholders::_1, bucketSuffix, isBackupValid));

        storageDeserializer.initBuckets(buckets());
        storageDeserializer.loadBuckets(buckets());
    } catch (const DatabaseException &) {
        LOGC("Reading cynara database failed.");
        buckets().clear();
        throw DatabaseCorruptedException();
    }
    m_checksum.clear();

    if (!hasBucket(defaultPolicyBucketId)) {
        LOGN("Creating defaultBucket.");
        this->buckets().insert({ defaultPolicyBucketId, PolicyBucket(defaultPolicyBucketId) });
    }

    postLoadCleanup(isBackupValid);
}
Beispiel #13
0
void Style::draw(RenderState& rs, const Tile& _tile) {

    auto& styleMesh = _tile.getMesh(*this);

    if (!styleMesh) { return; }

    TileID tileID = _tile.getID();

    if (hasRasters() && !_tile.rasters().empty()) {
        UniformTextureArray textureIndexUniform;
        UniformArray2f rasterSizeUniform;
        UniformArray3f rasterOffsetsUniform;

        for (auto& raster : _tile.rasters()) {
            if (raster.isValid()) {
                auto& texture = raster.texture;
                auto texUnit = rs.nextAvailableTextureUnit();
                texture->update(rs, texUnit);
                texture->bind(rs, texUnit);

                textureIndexUniform.slots.push_back(texUnit);
                rasterSizeUniform.push_back({texture->getWidth(), texture->getHeight()});

                if (tileID.z > raster.tileID.z) {
                    float dz = tileID.z - raster.tileID.z;
                    float dz2 = powf(2.f, dz);

                    rasterOffsetsUniform.push_back({
                            fmodf(tileID.x, dz2) / dz2,
                                (dz2 - 1.f - fmodf(tileID.y, dz2)) / dz2,
                                1.f / dz2
                                });
                } else {
                    rasterOffsetsUniform.push_back({0, 0, 1});
                }
            }
        }

        m_shaderProgram->setUniformi(rs, m_uRasters, textureIndexUniform);
        m_shaderProgram->setUniformf(rs, m_uRasterSizes, rasterSizeUniform);
        m_shaderProgram->setUniformf(rs, m_uRasterOffsets, rasterOffsetsUniform);
    }

    m_shaderProgram->setUniformMatrix4f(rs, m_uModel, _tile.getModelMatrix());
    m_shaderProgram->setUniformf(rs, m_uProxyDepth, _tile.isProxy() ? 1.f : 0.f);
    m_shaderProgram->setUniformf(rs, m_uTileOrigin,
                                 _tile.getOrigin().x,
                                 _tile.getOrigin().y,
                                 tileID.s,
                                 tileID.z);

    if (!styleMesh->draw(rs, *m_shaderProgram)) {
        LOGN("Mesh built by style %s cannot be drawn", m_name.c_str());
    }

    if (hasRasters()) {
        for (auto& raster : _tile.rasters()) {
            if (raster.isValid()) {
                rs.releaseTextureUnit();
            }
        }
    }
}
Beispiel #14
0
/**
 * @brief 	我们的工作线程所要做的主要工作
 */
void *thread_main(void *arg){
	int connfd, listenfd, index;
	socklen_t clilen, addrlen;
	struct sockaddr cliaddr;
	char client_id[CLIENT_ID_MAX];

	index = LOWORD((int)arg);
	listenfd = HIWORD((int)arg);
	addrlen = sizeof(struct sockaddr);
#if DEBUG
	LOGN("server", LOG_DEBUG, "thread %d starting listening %d", index, listenfd);
#endif	
	for(; ;){
		clilen = addrlen;
		Pthread_mutex_lock(&mlock);
#if DEBUG		
		LOGN("server", LOG_DEBUG, "pthread %d accepting...", index);
#endif
again:
		if((connfd = accept(listenfd, &cliaddr, &clilen)) < 0){		/*accept  出错*/
#ifdef EPROTO   		/*协议出错*/
			if(errno == EPROTO || errno == ECONNABORTED || errno == EINTR)
#else 					/*连接被终止*/
			if(errno == ECONNABORTED || errno == EINTR)
#endif
				goto again;
			else{
				LOGN("server", LOG_ERROR, "accept error");
				exit(-1);
			}	
		}
		
		Pthread_mutex_unlock(&mlock);

		/*判断客户终端的ID  是否合法,如果合法则将connfd  加入TCP  连接*/
		read_client_id(connfd, client_id, CLIENT_ID_MAX, index);
		if(false == check_client_id(client_id)){		/*不是合法ID*/
			writen(connfd, "no", 3);
			Close(connfd);
		}else{											/*合法ID*/
			int i;
			for(i = 0; i < CONN_NUM_MAX; i++){			/*将其存入已连接套接字数组*/
				if(client[i].socketfd < 0){				/*这里是初次将其添加进来,所以 理论上不用和其他地方互斥*/
					client[i].socketfd = connfd;
					break;
				}
			}
			if(i == CONN_NUM_MAX){						/*超过服务器所能够承载的数目,告诉客户端稍后再试*/
				LOGN("server", LOG_DEBUG, "too many clients");
				client[i].socketfd = -1;
				Close(connfd);
				continue;
			}

			client[i].socketfd_status = 0;
			bzero(client[i].client_id, CLIENT_ID_MAX);
			strncpy(client[i].client_id, client_id, CLIENT_ID_MAX);
			FD_SET(connfd, &allset);					/*将其添加进select监听的套接字*/
			client[i].Q = Cqueue_init(CQUEUE_SIZE);		/*初始化循环队列*/
			writen(connfd, "ok", 3);
			
			if(connfd > maxfd)
				maxfd = connfd;
			if(i > maxi)
				maxi = i;
		}
	}
	
}