Example #1
0
bool CSceneData::serializeLight(const scene::CLight* light, MemoryStreamPtr& stream)
{
    stream->write((s32)light->getNodeType());
    s32 parent = light->getParent() ? light->getParent()->getID() : -1;
    stream->write(parent);

    const std::string material = "";
    stream->write(material);

    return true;
}
Example #2
0
bool CSceneData::serializeCamera(const scene::CCamera* camera, MemoryStreamPtr& stream)
{
    stream->write((s32)camera->getNodeType());
    s32 parent = camera->getParent() ? camera->getParent()->getID() : -1;
    stream->write(parent);

    const std::string material = "";
    stream->write(material);

    return true;
}
Example #3
0
bool CSceneData::saveGeometry(MemoryStreamPtr& stream)
{
    u32 nodesCount = (u32)m_objectList.size();
    stream->write(nodesCount);
    LOG_INFO("Nodes count %d", nodesCount);

    bool success = false;
    for (auto& iter : m_objectList)
    {
        const CNode* node = iter.second;
        switch (node->getNodeType())
        {
        case eMesh:
            success = CSceneData::serializeMesh(static_cast<const CMesh*>(node), stream);
            break;

        case eCamera:
            success = CSceneData::serializeCamera(static_cast<const CCamera*>(node), stream);
            break;

        case eLight:
            success = CSceneData::serializeLight(static_cast<const CLight*>(node), stream);
            break;

        default:
            LOG_INFO(" CSceneData::saveGeometry: Node type not found %s", CNode::getNodeNameByType(node->getNodeType()));
            success = false;
            break;
        }

        if (!success)
        {
            return false;
        }
    }

    return true;
}
Example #4
0
bool CSceneData::save(const std::string& file, f32 version)
{
    if (m_objectList.empty())
    {
        LOG_ERROR("CSceneData::save: Object list empty, nothing save");
        return false;
    }
    LOG_DEBUG("CSceneData::save: Serialize model to memory stream");

    MemoryStreamPtr stream = CStreamManager::createMemoryStream();
    stream->seekBeg(0);
    stream->write(version);

    stream->write(m_id);
    stream->write(m_name);

    if (!CSceneData::saveMaterial(stream))
    {
        LOG_ERROR("CSceneData::save: Material serialize failed");
        return false;
    }

    if (!CSceneData::saveGeometry(stream))
    {
        LOG_ERROR("CSceneData::save: Geometry serialize failed");
        return false;
    }

    LOG_DEBUG("CSceneData::save: Save memory stream to file stream [%s]. Size [%d]", file.c_str(), stream->size());

    FileStreamPtr fileStream = CStreamManager::createFileStream(file, FileStream::e_create);
    fileStream->write(stream->getData(), sizeof(u8), stream->size());
    fileStream->close();

    return true;
}
StringPtr Values::to_s(){
	MemoryStreamPtr ms = xnew<MemoryStream>();
	ms->put_s(XTAL_STRING("("));

	const ValuesPtr* cur = &to_smartptr(this);
	for(int_t n=0; ; ++n){
		if(n!=0){
			ms->put_s(XTAL_STRING(", "));
		}

		ms->put_s((*cur)->head_);

		if(XTAL_detail_is_undefined((*cur)->tail_)){
			break;
		}
		cur = &(*cur)->tail_;
	}

	ms->put_s(XTAL_STRING(")"));
	return ms->to_s();

}
Example #6
0
bool CSceneData::serializeMesh(const CMesh* mesh, MemoryStreamPtr& stream)
{
    stream->write((s32)mesh->getNodeType());
    s32 parent = mesh->getParent() ? mesh->getParent()->getID() : -1;
    stream->write(parent);

    const std::string& material = mesh->getMaterial()->getResourseName();
    stream->write(material);

    MemoryStreamPtr subStream = CStreamManager::createMemoryStream();
    subStream->seekBeg(0);

    s32 id = mesh->getID();
    subStream->write(id);
    LOG_INFO("Mesh id %d", id);

    std::string name = mesh->getName();
    subStream->write(name);
    LOG_INFO("Mesh name %s", name.c_str());
    LOG_INFO("Mesh material %s", material.c_str());

    const renderer::GeometryPtr& geomerty = mesh->getGeometry();
    SVertexData& data = geomerty->getData();

    subStream->write((u32)data._indices.size());
    if (!data._indices.empty())
    {
        LOG_INFO("Mesh indices size %d", (u32)data._indices.size());
        subStream->write(data._indices.data(), sizeof(u32), (u32)data._indices.size());
    }

    LOG_INFO("Mesh vertices size %d", (u32)data._vertices.size() * 3);
    subStream->write((u32)data._vertices.size());
    subStream->write(data._vertices.data(), sizeof(f32), (u32)data._vertices.size() * 3);

    subStream->write((u32)data._normals.size());
    if (!data._normals.empty())
    {
        LOG_INFO("Mesh normals size %d", (u32)data._normals.size() * 3);
        subStream->write(data._normals.data(), sizeof(f32), (u32)data._normals.size() * 3);
    }

    subStream->write((u32)data._binormals.size());
    if (!data._binormals.empty())
    {
        LOG_INFO("Mesh binormals size %d", (u32)data._binormals.size() * 3);
        subStream->write(data._binormals.data(), sizeof(f32), (u32)data._binormals.size() * 3);
    }

    subStream->write((u32)data._tangents.size());
    if (!data._tangents.empty())
    {
        LOG_INFO("Mesh tangents size %d", (u32)data._tangents.size() * 3);
        subStream->write(data._tangents.data(), sizeof(f32), (u32)data._tangents.size() * 3);
    }

    subStream->write((u32)data._colors.size());
    if (!data._colors.empty())
    {
        LOG_INFO("Mesh colors size %d", (u32)data._colors.size() * 3);
        subStream->write(data._colors.data(), sizeof(f32), (u32)data._colors.size() * 3);
    }


    subStream->write((u32)data._texCoords.size());
    if (!data._texCoords.empty())
    {
        LOG_INFO("Mesh texCoords layer count %d", (u32)data._texCoords.size());
        for (u32 layer = 0; layer < data._texCoords.size(); ++layer)
        {
            if (!data._texCoords[layer].empty())
            {
                LOG_INFO("Mesh texCoords[%d] size %d", layer, (u32)data._texCoords[layer].size() * 2);
                subStream->write((u32)data._texCoords[layer].size());
                subStream->write(data._texCoords[layer].data(), sizeof(f32), (u32)data._texCoords[layer].size() * 2);
            }
        }
    }

    LOG_DEBUG("Mesh stream size %d\n", subStream->size());
    stream->write(subStream->size());
    stream->write(subStream->getData(), sizeof(u8), subStream->size());

    return true;
}
Example #7
0
bool CSceneData::saveMaterial(MemoryStreamPtr& stream)
{
    u32 materialsCount = (u32)m_materialList.size();
    stream->write(materialsCount);
    LOG_INFO("Materials count %d\n", materialsCount);

    bool success = false;
    for (auto& material : m_materialList)
    {
        MemoryStreamPtr subStream = CStreamManager::createMemoryStream();
        subStream->seekBeg(0);

        std::string name = material->getResourseName();
        subStream->write(name);
        LOG_INFO("Material name %s", name.c_str());

        //Texture

        decltype(m_textureList) textures;
        std::copy_if(m_textureList.cbegin(), m_textureList.cend(), std::inserter(textures, textures.begin()), [&material](auto& item) -> bool
        {
            return item.first == material;
        });

        u32 countTextures = (u32)textures.size();
        subStream->write(countTextures);
        LOG_INFO("Num Texutes %d", countTextures);

        for (auto& item : textures)
        {
            const std::string& name = item.second->getResourseName();
            LOG_INFO("Texute name %d", name.c_str());
            subStream->write(name);
        }
        /*for (u32 i = 0; i < countTextures; ++i)
        {
            const TexturePtr texure = material->getTexture(i);
            subStream->write(texure->getResourseName());
        }*/

        //Colors
        core::Vector4D diffuse = material->getDiffuseColor();
        subStream->write(&diffuse.x, sizeof(core::Vector4D), 1);

        core::Vector4D ambient = material->getAmbientColor();
        subStream->write(&ambient.x, sizeof(core::Vector4D), 1);

        core::Vector4D specular = material->getSpecularColor();
        subStream->write(&specular.x, sizeof(core::Vector4D), 1);

        core::Vector4D emission = material->getEmissionColor();
        subStream->write(&emission.x, sizeof(core::Vector4D), 1);

        subStream->write(material->getTransparency());
        subStream->write(material->getShininess());
        subStream->write(material->getGlossiness());

        LOG_DEBUG("Material stream size %d\n", subStream->size());
        stream->write(subStream->size());
        stream->write(subStream->getData(), sizeof(u8), subStream->size());
    }

    return true;
}
Example #8
0
StringPtr inspect_range(const CodePtr& code, const inst_t* start, const inst_t* end){

	int sz = 0;
	const inst_t* pc = start;
	StringPtr temp;
	MemoryStreamPtr ms = xnew<MemoryStream>();

	for(; pc < end;){switch(XTAL_opc(pc)){
		XTAL_NODEFAULT;

#define XTAL_INST_CASE(x) XTAL_CASE(x::NUMBER){ temp = x::inspect(pc, code); sz = x::ISIZE; }

//{INST_INSPECT{{
		XTAL_INST_CASE(InstLine);
		XTAL_INST_CASE(InstLoadValue);
		XTAL_INST_CASE(InstLoadConstant);
		XTAL_INST_CASE(InstLoadInt1Byte);
		XTAL_INST_CASE(InstLoadFloat1Byte);
		XTAL_INST_CASE(InstLoadCallee);
		XTAL_INST_CASE(InstLoadThis);
		XTAL_INST_CASE(InstCopy);
		XTAL_INST_CASE(InstInc);
		XTAL_INST_CASE(InstDec);
		XTAL_INST_CASE(InstPos);
		XTAL_INST_CASE(InstNeg);
		XTAL_INST_CASE(InstCom);
		XTAL_INST_CASE(InstAdd);
		XTAL_INST_CASE(InstSub);
		XTAL_INST_CASE(InstCat);
		XTAL_INST_CASE(InstMul);
		XTAL_INST_CASE(InstDiv);
		XTAL_INST_CASE(InstMod);
		XTAL_INST_CASE(InstAnd);
		XTAL_INST_CASE(InstOr);
		XTAL_INST_CASE(InstXor);
		XTAL_INST_CASE(InstShl);
		XTAL_INST_CASE(InstShr);
		XTAL_INST_CASE(InstUshr);
		XTAL_INST_CASE(InstAt);
		XTAL_INST_CASE(InstSetAt);
		XTAL_INST_CASE(InstGoto);
		XTAL_INST_CASE(InstNot);
		XTAL_INST_CASE(InstIf);
		XTAL_INST_CASE(InstIfEq);
		XTAL_INST_CASE(InstIfLt);
		XTAL_INST_CASE(InstIfRawEq);
		XTAL_INST_CASE(InstIfIs);
		XTAL_INST_CASE(InstIfIn);
		XTAL_INST_CASE(InstIfUndefined);
		XTAL_INST_CASE(InstIfDebug);
		XTAL_INST_CASE(InstPush);
		XTAL_INST_CASE(InstPop);
		XTAL_INST_CASE(InstAdjustValues);
		XTAL_INST_CASE(InstLocalVariable);
		XTAL_INST_CASE(InstSetLocalVariable);
		XTAL_INST_CASE(InstInstanceVariable);
		XTAL_INST_CASE(InstSetInstanceVariable);
		XTAL_INST_CASE(InstInstanceVariableByName);
		XTAL_INST_CASE(InstSetInstanceVariableByName);
		XTAL_INST_CASE(InstFilelocalVariable);
		XTAL_INST_CASE(InstSetFilelocalVariable);
		XTAL_INST_CASE(InstFilelocalVariableByName);
		XTAL_INST_CASE(InstSetFilelocalVariableByName);
		XTAL_INST_CASE(InstMember);
		XTAL_INST_CASE(InstMemberEx);
		XTAL_INST_CASE(InstCall);
		XTAL_INST_CASE(InstCallEx);
		XTAL_INST_CASE(InstSend);
		XTAL_INST_CASE(InstSendEx);
		XTAL_INST_CASE(InstProperty);
		XTAL_INST_CASE(InstSetProperty);
		XTAL_INST_CASE(InstScopeBegin);
		XTAL_INST_CASE(InstScopeEnd);
		XTAL_INST_CASE(InstReturn);
		XTAL_INST_CASE(InstYield);
		XTAL_INST_CASE(InstExit);
		XTAL_INST_CASE(InstRange);
		XTAL_INST_CASE(InstOnce);
		XTAL_INST_CASE(InstSetOnce);
		XTAL_INST_CASE(InstMakeArray);
		XTAL_INST_CASE(InstArrayAppend);
		XTAL_INST_CASE(InstMakeMap);
		XTAL_INST_CASE(InstMapInsert);
		XTAL_INST_CASE(InstMapSetDefault);
		XTAL_INST_CASE(InstClassBegin);
		XTAL_INST_CASE(InstClassEnd);
		XTAL_INST_CASE(InstDefineClassMember);
		XTAL_INST_CASE(InstDefineMember);
		XTAL_INST_CASE(InstMakeFun);
		XTAL_INST_CASE(InstMakeInstanceVariableAccessor);
		XTAL_INST_CASE(InstTryBegin);
		XTAL_INST_CASE(InstTryEnd);
		XTAL_INST_CASE(InstPushGoto);
		XTAL_INST_CASE(InstPopGoto);
		XTAL_INST_CASE(InstThrow);
		XTAL_INST_CASE(InstAssert);
		XTAL_INST_CASE(InstBreakPoint);
		XTAL_INST_CASE(InstMAX);
//}}INST_INSPECT}
	} ms->put_s(Xf("%04d(%04d):%s\n")->call((int_t)(pc-start), code->compliant_lineno(pc), temp)->to_s()); pc += sz; }

	ms->seek(0);
	return ms->get_s(ms->size());
}