void PRenderer::render(PRenderState *renderState) { PASSERT(m_scene->mainCamera() != P_NULL); // Create a default render pass if none exists if (m_renderPassArray.isEmpty()) { PRenderPass *renderPass = PNEW(PRenderPass("default", m_scene)); renderPass->setCamera(m_scene->mainCamera()); renderPass->queue()->addNodes(m_scene->root()); renderPass->target()->setColorClearValue(m_backgroundColor); PShadowPass *shadowPass = PNEW(PShadowPass("shadow", m_scene)); addRenderPass(shadowPass); addRenderPass(renderPass); } if (m_renderPassArray.isEmpty()) { PLOG_WARNING("There is no valid render pass existing."); return ; } for (puint32 i = 0; i < m_renderPassArray.size(); ++i) { m_renderPassArray[i]->render(renderState); } }
void PMaterial::apply(PRenderState *renderState, PDrawable *drawable, PCamera *camera, const PRenderLightQueue &lights) { PASSERT(m_resource != P_NULL); if (m_resource== P_NULL) { PLOG_WARNING("Use an invalid material."); return ; } // Enable the shader. renderState->useMaterial(m_resource); // Upload drawable's values to shader PRenderTransform transform(drawable, camera); puint32 num; puint32 numTextures = 0; num = m_resource->numberOfRenderParameters(); for (puint32 i = 0; i < num; ++i) { m_resource->renderParameter(i)->upload(m_resource->shader(), &transform, camera, lights); } num = m_materialParameters.count(); for (puint32 i = 0; i < num; ++i) { m_materialParameters[i]->upload(m_resource, renderState, numTextures); } }
void PMaterialParameter::operator=(PTexture *value) { PASSERT(m_uniformType == P_GLSHADERUNIFORM_SAMPLERCUBE || m_uniformType == P_GLSHADERUNIFORM_SAMPLER2D || m_uniformType == P_GLSHADERUNIFORM_UNKNOWN); if (m_uniformType != P_GLSHADERUNIFORM_SAMPLERCUBE && m_uniformType != P_GLSHADERUNIFORM_SAMPLER2D) { PLOG_WARNING("%s is not a texture parameter", m_name.c_str()); return ; } if (m_value.t != value) { if (m_value.t != P_NULL) { m_value.t->release(); } m_value.t = value; // Increase the reference count of texture object. if (m_value.t != P_NULL) { m_value.t->retain(); } } }
void PScene::setMainCamera(PCamera *camera) { PASSERT(camera != P_NULL); if (camera->scene() != this) { PLOG_WARNING("The camera doesn't belong to this scene"); } m_mainCamera = camera; }
const PString &PIni::entry(const PString &name) const { PMap<PString, PString>::const_iterator it = m_entries.find(name); if (it != m_entries.end()) { return it.value(); } PLOG_WARNING("Failed to find entry called %s.", name.c_str()); return m_nullString; }
void PRenderLightQueue::addLight(PAbstractLight *light) { PASSERT(light != P_NULL); switch (light->type()) { case P_LIGHT_POINT: if (m_lights[0] != P_NULL && m_lights[1] != P_NULL) { PLOG_WARNING("One scene can render up to two point lights."); return ; } if (m_lights[0] == P_NULL) { m_lights[0] = reinterpret_cast<PPointLight *>(light); } else if (m_lights[1] == P_NULL) { m_lights[1] = reinterpret_cast<PPointLight *>(light); } break; case P_LIGHT_DIRECTIONAL: if (m_lights[2] != P_NULL) { PLOG_WARNING("One scene can render only one directional light."); return ; } m_lights[2] = reinterpret_cast<PDirectionalLight *>(light); break; case P_LIGHT_SPOT: if (m_lights[3] != P_NULL) { PLOG_WARNING("One scene can render only one spot light."); return ; } m_lights[3] = reinterpret_cast<PSpotLight *>(light); break; } }
void PScene::removeEffect(PAbstractEffect *effect) { PASSERT(effect != P_NULL); PList<PAbstractEffect *>::iterator it = m_effects.find(effect); if (it != m_effects.end()) { m_effects.erase(it); } else { PLOG_WARNING("Fail to find such effect."); } }
void PSceneManager::setMainScene(PScene *scene) { #if defined P_DEBUG PList<PScene *>::iterator it = m_scenes.find(scene); if (it == m_scenes.end()) { PLOG_WARNING("The scene is not in the scene list of the context"); } #endif PASSERT(scene != P_NULL); m_mainScene = scene; }
void PRenderPass::render(PRenderState *renderState) { PASSERT(renderState != P_NULL); if (m_camera == P_NULL) { PLOG_WARNING("Render pass %s doesn't have a camera.", m_name.c_str()); return ; } m_renderTarget->use(renderState); m_renderQueue->render(m_scene, m_camera, renderState); }
PRenderPass *PRenderer::renderPass(const pchar *name) const { puint32 n = m_renderPassArray.count(); for (puint32 i = 0; i < n; ++i) { if (m_renderPassArray[i]->name() == name) { return m_renderPassArray[i]; } } PLOG_WARNING("Failed to find render pass %s in renderer.", name); return P_NULL; }
PMaterialParameter &PMaterial::parameter(const pchar *name) const { // TODO: use PDictionary instead of PArray for (puint32 i = 0; i < m_materialParameters.count(); ++i) { if (m_materialParameters[i]->name() == name) { return *m_materialParameters[i]; } } PLOG_WARNING("Failed to find parameter %s in this material.", name); return *s_phonyMaterialParameter; }
void PMaterial::apply(PRenderState *renderState) { PASSERT(m_resource != P_NULL); if (m_resource== P_NULL) { PLOG_WARNING("Use an invalid material."); return ; } // Enable the shader. renderState->useMaterial(m_resource); puint32 num = m_materialParameters.count(); puint32 numTextures = 0; for (puint32 i = 0; i < num; ++i) { m_materialParameters[i]->upload(m_resource, renderState, numTextures); } }
void PNode::setParent(PNode *parent) { PASSERT(parent != P_NULL); // This new parent can't be child of this object node. if (parent != P_NULL) { if (child(parent->name().c_str()) != P_NULL) { PLOG_WARNING("Can't have its child to be the parent"); return ; } m_parent->removeChild(m_name.toString().c_str()); m_parent = parent; m_parent->addChild(this); } }
PMaterial *PMaterial::unpack(PXmlElement *element, PResourceManager *resourceManager) { PASSERT(element->isValid()); PMaterial *ret; const pchar *idValue = element->attribute("id"); if (idValue == P_NULL) { PLOG_ERROR("Failed to find the id of the material in this xml node."); return P_NULL; } ret = PNEW(PMaterial(idValue, resourceManager)); // Go over all material parameters and set their values. puint32 numParameters = ret->numberOfMaterialParameters(); for (puint32 i = 0; i < numParameters; ++i) { PMaterialParameter *parameter = ret->materialParameter(i); const pchar *parameterValue = element->attribute(parameter->name().c_str()); if (parameterValue != P_NULL) { if (!parameter->unpack(parameterValue, resourceManager)) { PLOG_WARNING("Failed to unpack parameter %s in materail %s.", parameterValue, idValue); } } } // TODO: validate the matching of type of uniform variable to the type of material parameter. const pchar *transparentValue = element->attribute("transparent"); if (transparentValue != P_NULL && pstrcmp(transparentValue, "true") == 0) { ret->setTransparent(true); } return ret; }
void PRenderLightQueue::removeLight(PAbstractLight *light) { if (m_lights[0] == light) { m_lights[0] = m_lights[1]; m_lights[1] = P_NULL; } else if (m_lights[1] == light) { m_lights[1] = P_NULL; } else if (m_lights[2] == light) { m_lights[2] = P_NULL; } else if (m_lights[3] == light) { m_lights[3] = P_NULL; } else { PLOG_WARNING("Failed to find light %s in the queue.", light->name().c_str()); } }
void PGestureTap::touchDown(pint32 x, pint32 y, puint32 timeStamp, pint32 pointer) { if (!m_enabled) { return ; } if (pointer > 0 && m_state == STATE_POSSIBLE) { reset(); PLOG_WARNING("Gesture tap support only one touch"); return; } if (m_state == STATE_READY) { m_firstPoint[0] = x; m_firstPoint[1] = y; m_firstTapTime = timeStamp; m_state = STATE_POSSIBLE; } }
PDir::PDir(const pchar *dir) { // Check if the directory exists. struct stat s; if (stat(dir, &s) != 0 || !S_ISDIR(s.st_mode)) { PLOG_ERROR("%s is not a valid directory.", dir); m_exists = false; } else { m_exists = true; // Fetch the item names in that directory. DIR* dirObject; dirent* dirEntry; m_items = P_NULL; m_numberOfItems = 0; puint32 capacity = 32; puint8* itemData = PNEWARRAY(puint8, capacity * sizeof(PDirItem)); pmemset(itemData, 0, sizeof(capacity * sizeof(PDirItem))); if ((dirObject = opendir(dir)) == NULL) { PLOG_ERROR("Failed to read directory %s.", dir); PDELETEARRAY(itemData); } else { char path[4096]; while ((dirEntry = readdir(dirObject)) != NULL) { // Find first file will always return "." and ".." // as the first two directories. if (pstrcmp(dirEntry->d_name, ".") != 0 && pstrcmp(dirEntry->d_name, "..") != 0) { //Build up our file path using the passed in // [sDir] and the file/foldername we just found: psprintf(path, 4096, "%s\\%s", dir, dirEntry->d_name); //Is the entity a File or Folder? if (dirEntry->d_type == DT_DIR) { // TODO: use the absolute path. new (itemData + m_numberOfItems * sizeof(PDirItem)) PDirItem(P_DIR_ITEM_DIRECTORY, path); m_numberOfItems++; } else if (dirEntry->d_type == DT_REG) { // TODO: use the absolute path. new (itemData + m_numberOfItems * sizeof(PDirItem)) PDirItem(P_DIR_ITEM_FILE, path); m_numberOfItems++; } else { PLOG_WARNING("%s is not supported.", path); } if (m_numberOfItems > capacity) { resizeItemArray(itemData, capacity, 2 * capacity); capacity *= 2; } } } closedir(dirObject); //Always, Always, clean things up! m_items = reinterpret_cast<PDirItem*>(itemData); } } }
pbool BContent::unpack(const PXmlElement *xmlElement) { // Sanity check. if (pstrcmp(xmlElement->name(), "content") != 0) { PLOG_ERROR("It is not a content element"); return false; } PXmlElement childElement = xmlElement->firstChild(); while (childElement.isValid()) { if (pstrcmp(childElement.name(), "entry") == 0) { const pchar *levelValue = childElement.attribute("level"); const pchar *textValue = childElement.attribute("text"); const pchar *pageNumberValue = childElement.attribute("pageno"); if (levelValue == P_NULL || textValue == P_NULL || pageNumberValue == P_NULL) { PLOG_WARNING("entry is incomplete."); } else { pint32 pageNumber; pint32 level; if (pStringUnpackInt(levelValue, &level) == P_NULL || pStringUnpackInt(pageNumberValue, &pageNumber) == P_NULL) { PLOG_WARNING("entry information is incomplete."); } else { if ((puint32)pageNumber > m_book->numberOfPages()) { PLOG_ERROR("entry's page number is not valide"); } else { BContentEntry *entry = PNEW(BContentEntry); entry->level = level; entry->text = pstrdup(textValue); entry->pageNumber = pageNumber; m_entries.append(entry); } } } } else { PLOG_WARNING("Unknown element node (%s) in entry.", childElement.name()); } childElement = childElement.nextSibling(); } return true; }
PDir::PDir(const pchar *dir) { // Check if the directory exists. DWORD dwAttrib = GetFileAttributesA(dir); m_exists = ((dwAttrib != INVALID_FILE_ATTRIBUTES) && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); // Fetch the item names in that directory. WIN32_FIND_DATAA fdFile; HANDLE hFind = NULL; pchar path[MAX_PATH]; m_items = P_NULL; m_numberOfItems = 0; puint32 capacity = 32; puint8 *itemData = PNEWARRAY(puint8, capacity * sizeof(PDirItem)); pmemset(itemData, 0, sizeof(capacity * sizeof(PDirItem))); // Specify a file mask. *.* = We want everything! psprintf(path, MAX_PATH, "%s\\*.*", dir); if ((hFind = FindFirstFileA(path, &fdFile)) == INVALID_HANDLE_VALUE) { PLOG_ERROR("Failed to read directory %s.", dir); PDELETEARRAY(itemData); } else { do { // Find first file will always return "." and ".." // as the first two directories. if (pstrcmp(fdFile.cFileName, ".") != 0 && pstrcmp(fdFile.cFileName, "..") != 0) { //Build up our file path using the passed in // [sDir] and the file/foldername we just found: psprintf(path, MAX_PATH, "%s\\%s", dir, fdFile.cFileName); //Is the entity a File or Folder? if (fdFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // TODO: use the absolute path. new (itemData + m_numberOfItems * sizeof(PDirItem)) PDirItem(P_DIR_ITEM_DIRECTORY, path); m_numberOfItems++; } else if ((fdFile.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) || (fdFile.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)) { // TODO: use the absolute path. new (itemData + m_numberOfItems * sizeof(PDirItem)) PDirItem(P_DIR_ITEM_FILE, path); m_numberOfItems++; } else { PLOG_WARNING("%s is not seen supported.", path); } if (m_numberOfItems > capacity) { resizeItemArray(itemData, capacity, 2 * capacity); capacity *= 2; } } } while (FindNextFileA(hFind, &fdFile)); // Find the next file. FindClose(hFind); //Always, Always, clean things up! } m_items = reinterpret_cast<PDirItem*>(itemData); }
void PTimer::kill() { PLOG_WARNING( "The timer destroy by call kill"); m_manager->removeTimer(this); PDELETETHIS(this); }
pbool PScene::unpack(const PXmlElement* xmlElement) { // Sanity check if (pstrcmp(xmlElement->name(), "scene") != 0) { PLOG_ERROR("It is not a scene element"); return false; } // Delete all scene nodes PDELETE(m_root); PResourceManager *resourceManager = context()->module<PResourceManager>("resource-manager"); // Delete all effects PList<PAbstractEffect *>::iterator it = m_effects.begin(); PList<PAbstractEffect *>::iterator ie = m_effects.end(); while (it != ie) { PAbstractEffect *effect = *it; effect->m_scene = P_NULL; PDELETE(effect); ++it; } // Recursively unpack its children PXmlElement childElement = xmlElement->firstChild(); while (childElement.isValid()) { if (pstrcmp(childElement.name(), "root") == 0) { const pchar *rootNameValue = childElement.attribute("name"); PASSERT(rootNameValue != P_NULL); m_root = PNEW(PRootNode(rootNameValue, this)); if (!m_root->unpack(&childElement)) { return false; } } else if (pstrcmp(childElement.name(), "effect") == 0) { PAbstractEffect *effect = s_effectFactory.unpack(&childElement, this); if (effect == P_NULL) { return false; } } else if (pstrcmp(childElement.name(), "texture") == 0) { const pchar *textureId = childElement.attribute("id"); if (textureId != P_NULL) { PTexture *texture = resourceManager->getTexture(textureId); if (texture == P_NULL) { PLOG_ERROR("Failed to find texture %s.", textureId); } else { const pchar *wrapValue = childElement.attribute("wrap"); if (wrapValue != P_NULL) { if (pstrcmp(wrapValue, "repeat") == 0) { texture->setRepeatWrappingEnabled(true, true); } } const pchar *mipmapValue = childElement.attribute("mipmap"); if (mipmapValue != P_NULL) { if (pstrcmp(mipmapValue, "true") == 0) { // TODO: PASSERT_NOTIMPLEMENTED(); } } } } else { PLOG_ERROR("Failed to find the id of the texture is missing."); } } else { PLOG_WARNING("Unknown element node (%s) in scene.", childElement.name()); } childElement = childElement.nextSibling(); } // Find the main camera. const pchar *mainCameraValue = xmlElement->attribute("maincamera"); m_mainCamera = P_NULL; if (mainCameraValue == P_NULL) { // When the main camera is not specified, use the first camera in the // scene nodes as the main camera. PNode::iterator ni(m_root); PNode *node = *(++ni); // Skip the root while (node != P_NULL) { PCamera *camera = dynamic_cast<PCamera *>(node); if (camera != P_NULL) { m_mainCamera = camera; break; } node = *(++ni); } if (m_mainCamera == P_NULL) { PLOG_WARNING("No camera is found. The scene may not be rendered properly."); } } else { PNode::iterator ni(m_root); PNode *node = *(++ni); // Skip the root while (node != P_NULL) { if (node->name() == mainCameraValue) { PCamera *camera = dynamic_cast<PCamera *>(node); if (camera != P_NULL) { m_mainCamera = camera; break; } } node = *(++ni); } if (m_mainCamera == P_NULL) { PLOG_WARNING("There is no such camera called %s in the scene."); } } return true; }
void system_framework_main(void) #endif { sfw_ret_t ret; id_t mb_id; id_t tsk_id; unsigned long len; timeval_st rcv_timeout; sfw_tsk_st *ptsk; void *pmsg; tsk_id = sfw_tsk_gid(); /* Who am I? */ ptsk = sfw_get_task(tsk_id); if (ptsk == NULL) { PLOG_ERROR(MW_SFW_MOD, (PRINT_OPTIONS \ "Application not found!\n", PRINT_PORT)); h_return; } if (ptsk->pfunction == NULL) { /* Failed */ PLOG_ERROR(MW_SFW_MOD, (PRINT_OPTIONS \ "Message handler have not initialized!\n", PRINT_PORT)); goto _END_TASK; } /* Very earlier, We call Message Handler */ ptsk->pfunction(ptsk, ptsk->pattach); #ifdef TSK_REPORTER snd_tsk_info(tsk_id); #endif if (ptsk->lightweigt) { goto _END_TASK; } gext_agent_tsk_id = sfw_ext_agent_getid(); rcv_timeout.sec = 0; rcv_timeout.usec = 0; mb_id = ptsk->mb_id; while(1) { len = 0; ret = sfw_mb_rcv(mb_id, &pmsg, &len, rcv_timeout); if (ret < 0 || pmsg == NULL) { sfw_db(("Task %d: Failed to get message (ret = %d)!\n", ptsk->tsk_id, ret)); PLOG_WARNING(MW_SFW_MOD, (PRINT_OPTIONS \ "Failed to receive message from MB (app = %d, ret = %d, pmsg = 0x%p)!\n", PRINT_PORT, ptsk->tsk_id, ret, pmsg)); continue; } sfw_db(("Task %d got message!\n", ptsk->tsk_id)); if (is_copy_mode(((msg_st *) pmsg)->hdr.cat.u_cat.type)) { if (((msg_st *) pmsg)->hdr.len != 0) { ((msg_st *) pmsg)->pdata = (U8*)((char *) pmsg + sizeof(msg_st)); } else { ((msg_st *) pmsg)->pdata = NULL; } } ptsk->pfunction(ptsk, (void *) pmsg); #ifdef _HOS_ if (ret == MB_SND_DATA_COPY) { HOS_KFREE(pmsg); /* memory allocated by mailbox */ pmsg = NULL; } #endif } _END_TASK: free(ptsk); h_return; }