Exemplo n.º 1
0
pbool PIni::load(const pchar *filename)
{
    //
    // Look for the file in the specified path
    //
    const pchar* pathList[] =
    {
        ".",
        pPathGetApplicationDirectory(),
        pPathGetExternalStoragePath(),
    };

    for (size_t i = 0; i < sizeof(pathList) / sizeof(pathList[0]); ++i)
    {
        if (pathList[i] != P_NULL)
        {
            PString cfgPath = PString(pathList[i]) + PString(pPathGetDelimiter()) + PString(filename);
            PFile *fp = pfopen(cfgPath.c_str(), "rb");
            if (fp != P_NULL)
            {
                if (ini_parse_file((FILE *)(fp), iniHandler_internal, this) < 0)
                {
                    PLOG_ERROR("Failed to parse %s", cfgPath.c_str());
                    pfclose(fp);
                    return false;
                }
                pfclose(fp);

                return true;
            }
        }
    }

    //
    // Look for the ini file in asset
    //
    PAsset asset = pAssetOpen(filename);
    if (pAssetIsValid(&asset))
    {
        PIniBufferObject iniBufferObject;
        iniBufferObject.m_buffer = (const pchar*)pAssetGetBuffer(&asset);
        iniBufferObject.m_bufferSize = pAssetGetSize(&asset);
        iniBufferObject.m_position = 0;
        
        if (ini_parse_buffer(&iniBufferObject, iniHandler_internal, this) < 0)
        {
            PLOG_ERROR("Failed to parse %s", filename);
            pAssetClose(&asset);
            return false;
        }

        pAssetClose(&asset);
        
        return true;
    }

    PLOG_ERROR("Failed to find %s", filename);
    
    return false;
}
Exemplo n.º 2
0
pbool PFrameBuffer::createFramebuffer()
{
    // Create framebuffer object.
    m_framebufferObject = PNEW(PGlFramebuffer);
    if (!m_framebufferObject->create(m_width, 
                                     m_height, 
                                     m_colorBufferFormat,
                                     m_depthBufferFormat, 
                                     m_stencilBufferFormat))
    {
        PDELETE(m_framebufferObject);
        PLOG_ERROR("Failed to create framebuffer object %s", m_id);
        return false;
    }

    // Create texture
    if (m_framebufferObject)
    {
        PString textureName;
        if (m_framebufferObject->colorBuffer())
        {
            textureName = m_id;
            textureName += ":color-texture";
            m_colorTexture = PNEW(PTexture(textureName.c_str(), this));
        }
    }

    return true;
}
Exemplo n.º 3
0
MyScene::MyScene(PContext *context)
    : PScene("my-scene", context)
{
    PRandom random(1001);

    const puint32 *rect = context->rect();

    for (puint32 i = 0; i < NUM_LOGOS; ++i)
    {
        m_velocities[i][0] = (random.getFloat32() - 0.5f) * (pfloat32)rect[2] * 0.001f; 
        m_velocities[i][1] = (random.getFloat32() - 0.5f) * (pfloat32)rect[3] * 0.001f; 
    }

    // -------------------------------------------------------------- 
    // Add camera
    // -------------------------------------------------------------- 
    PCamera *camera = PNEW(PCamera("camera", this));
    camera->setFixed(true);
    camera->transform().setLookAt(0.0f, 0.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
    camera->projection().window((pfloat32)rect[2], (pfloat32)rect[3]);
    setMainCamera(camera);
    
	PResourceManager* resMgr = context->module<PResourceManager>("resource-manager");

    // -------------------------------------------------------------- 
    // Scene objects
    // -------------------------------------------------------------- 
    PMaterial *material = PNEW(PMaterial("texture.pmt", resMgr));
    material->parameter("texture") = resMgr->getTexture("texture.png");
    material->setTransparent(true);
        
    PAbstractGeometry *geometry = PNEW(PGeometryPlane(resMgr));

    for (puint32 i = 0; i < NUM_LOGOS; ++i)
    {
        PString name = PString::fromUint(i);
        m_logos[i] = PNEW(PDrawable(name.c_str(), this));
        m_logos[i]->setGeometry(geometry);
        m_logos[i]->setMaterial(material);

        m_logos[i]->transform().setTranslation(pVector3(0.0f, 0.0f, 0.0f));
        m_logos[i]->transform().setScaling(pVector3(64.0f, 16.0f, 1.0f));
    }

    setBackgroundColor(pColorRGBA(1.0f, 1.0f, 1.0f, 0.0f));
}
Exemplo n.º 4
0
void PNode::setName(const pchar *name)
{
    if (m_name.toString() == name)
    {
        return ;
    }

    PString oldName = m_name.toString();
    
    PASSERT(name != P_NULL);
    m_name.setValue(name);

    // Remove from its parent.
    PStringMap<PNode*>::iterator it = m_parent->m_children.find(oldName.c_str());
    PASSERT(it != m_children.end());
    m_parent->m_children.erase(it);

    // and insert again
    m_parent->m_children.insert(const_cast<pchar *>(m_name.toString().c_str()), this);
}