void ETHCustomDataManager::AddToFloat(const str_type::string &name, const float &value) { std::map<str_type::string, ETHCustomDataPtr>::const_iterator iter = m_data.find(name); if (iter == m_data.end()) { ETH_STREAM_DECL(ss) << GS_L("There's no matching data for ") << name; return; } if (iter->second->GetType() != ETHDT_FLOAT) { ETH_STREAM_DECL(ss) << name << GS_L(":is not a float"); return; } iter->second->Set(value+iter->second->GetFloat()); }
void ETHTempEntityHandler::RunCallbacksFromList() { for (std::list<ETHRenderEntity*>::iterator iter = m_dynamicOrTempEntities.begin(); iter != m_dynamicOrTempEntities.end();) { if (!((*iter)->IsAlive())) { #ifdef _DEBUG ETH_STREAM_DECL(ss) << GS_L("Entity removed from dynamic entity list: ") << (*iter)->GetEntityName(); m_provider->Log(ss.str(), Platform::Logger::INFO); #endif (*iter)->Release(); iter = m_dynamicOrTempEntities.erase(iter); continue; } else { if ((*iter)->HasAnyCallbackFunction()) { (*iter)->RunCallbackScript(); } iter++; } } for (std::list<ETHRenderEntity*>::iterator iter = m_lastFrameCallbacks.begin(); iter != m_lastFrameCallbacks.end();) { if (!((*iter)->IsAlive())) { #ifdef _DEBUG ETH_STREAM_DECL(ss) << GS_L("Entity callback removed: ") << (*iter)->GetEntityName(); m_provider->Log(ss.str(), Platform::Logger::INFO); #endif (*iter)->Release(); iter = m_lastFrameCallbacks.erase(iter); continue; } else { if ((*iter)->HasAnyCallbackFunction()) { (*iter)->RunCallbackScript(); } (*iter)->Release(); iter++; } } m_lastFrameCallbacks.clear(); }
bool ETHCustomDataManager::GetInt(const str_type::string &name, int &outValue) const { std::map<str_type::string, ETHCustomDataPtr>::const_iterator iter = m_data.find(name); if (iter == m_data.end()) { ETH_STREAM_DECL(ss) << GS_L("There's no matching data for ") << name; return false; } if (iter->second->GetType() != ETHDT_INT) { ETH_STREAM_DECL(ss) << name << GS_L(":is not an int"); return false; } outValue = iter->second->GetInt(); return true; }
bool ETHBucketManager::DeleteEntity(const int id) { for (ETHBucketMap::iterator bucketIter = GetFirstBucket(); bucketIter != GetLastBucket(); ++bucketIter) { ETHEntityList& entityList = bucketIter->second; ETHEntityList::const_iterator iEnd = entityList.end(); for (ETHEntityList::iterator iter = entityList.begin(); iter != iEnd; ++iter) { if ((*iter)->GetID() == id) { #if defined(_DEBUG) || defined(DEBUG) ETH_STREAM_DECL(ss) << GS_L("Entity ") << (*iter)->GetEntityName() << GS_L(" (ID#") << (*iter)->GetID() << GS_L(") removed (DeleteEntity method)"); m_provider->Log(ss.str(), Platform::Logger::INFO); #endif if (m_entityKillListener) m_entityKillListener->EntityKilled((*iter)); (*iter)->Kill(); (*iter)->Release(); entityList.erase(iter); return true; } } } return false; }
bool ETHScene::SaveToFile(const str_type::string& fileName) { if (m_buckets.IsEmpty()) { ETH_STREAM_DECL(ss) << GS_L("ETHScene::Save: there are no entities to save: ") << fileName; m_provider->Log(ss.str(), Platform::FileLogger::ERROR); return false; } // Write the header to the file TiXmlDocument doc; TiXmlDeclaration *pDecl = new TiXmlDeclaration(GS_L("1.0"), GS_L(""), GS_L("")); doc.LinkEndChild(pDecl); TiXmlElement *pElement = new TiXmlElement(GS_L("Ethanon")); doc.LinkEndChild(pElement); TiXmlElement *pRoot = doc.RootElement(); // write the property header m_sceneProps.WriteToXMLFile(pRoot); // start writing entities TiXmlElement *pEntities = new TiXmlElement(GS_L("EntitiesInScene")); pRoot->LinkEndChild(pEntities); // Write every entity for (ETHBucketMap::iterator bucketIter = m_buckets.GetFirstBucket(); bucketIter != m_buckets.GetLastBucket(); ++bucketIter) { ETHEntityList::const_iterator iEnd = bucketIter->second.end(); for (ETHEntityList::iterator iter = bucketIter->second.begin(); iter != iEnd; ++iter) { (*iter)->WriteToXMLFile(pEntities); #if defined(_DEBUG) || defined(DEBUG) ETH_STREAM_DECL(ss) << GS_L("Entity written to file: ") << (*iter)->GetEntityName(); m_provider->Log(ss.str(), Platform::FileLogger::INFO); #endif } } doc.SaveFile(fileName); #ifdef GS2D_STR_TYPE_ANSI m_provider->GetFileManager()->ConvertAnsiFileToUTF16LE(fileName); #endif return true; }
void ETHScriptWrapper::UsePixelShaders(const bool enable) { if (!m_provider->GetShaderManager()->IsPixelLightingSupported() && enable) { ETH_STREAM_DECL(ss) << GS_L("Scripting error: pixel shaders are no supported."); m_provider->Log(ss.str(), Platform::FileLogger::WARNING); return; } m_provider->GetShaderManager()->UsePS(enable); }
void PrintException(asIScriptContext *pContext) { asIScriptEngine *m_pASEngine = pContext->GetEngine(); const int funcId = pContext->GetExceptionFunction(); const asIScriptFunction *pFunction = m_pASEngine->GetFunctionDescriptorById(funcId); ETH_STREAM_DECL(ss) << GS_L("Function: ") << pFunction->GetDeclaration() << std::endl << GS_L("Section: ") << pFunction->GetScriptSectionName() << std::endl << GS_L("Line: ") << pContext->GetExceptionLineNumber() << std::endl << GS_L("Description: ") << pContext->GetExceptionString() << std::endl; ETHResourceProvider::Log(ss.str(), Platform::Logger::ERROR); }
bool ETHScene::LoadFromFile(const str_type::string& fileName) { Platform::FileManagerPtr fileManager = m_provider->GetVideo()->GetFileManager(); // load the scene from a file { Platform::FileBuffer file; fileManager->GetFileBuffer(fileName, file); if (!file) { ETH_STREAM_DECL(ss) << GS_L("ETHScene::Open: file not found (") << fileName << GS_L(")"); m_provider->Log(ss.str(), Platform::FileLogger::ERROR); return false; } } m_minSceneHeight = 0.0f; m_maxSceneHeight = m_provider->GetVideo()->GetScreenSizeF().y; // Read the header and check if the file is valid TiXmlDocument doc(fileName); str_type::string content; fileManager->GetUTF16FileString(fileName, content); if (!doc.LoadFile(content, TIXML_ENCODING_LEGACY)) { ETH_STREAM_DECL(ss) << GS_L("ETHScene::Open: file found, but parsing failed (") << fileName << GS_L(")"); m_provider->Log(ss.str(), Platform::FileLogger::ERROR); return false; } TiXmlHandle hDoc(&doc); TiXmlHandle hRoot(0); TiXmlElement *pElement = hDoc.FirstChildElement().Element(); if (!pElement) { ETH_STREAM_DECL(ss) << GS_L("ETHScene::Open: couldn't find root element (") << fileName << GS_L(")"); m_provider->Log(ss.str(), Platform::FileLogger::ERROR); return false; } return ReadFromXMLFile(pElement); }
bool ETHScriptWrapper::WarnIfRunsInMainFunction(const str_type::string &functionName) { if (IsRunningMainFunction()) { ETH_STREAM_DECL(ss) << std::endl << GS_L("WARNING: do not load resources or do scene-related operations inside the main() function.") << std::endl << GS_L("Use onSceneLoaded or onSceneUpdate functions instead.") << std::endl << GS_L("Function used: ") << functionName << std::endl; m_provider->Log(ss.str(), Platform::Logger::ERROR); return true; } return false; }
SpritePtr ETHGraphicResourceManager::AddFile( VideoPtr video, const str_type::string &path, const str_type::string& resourceDirectory, const bool cutOutBlackPixels) { str_type::string fileName = Platform::GetFileName(path); { SpritePtr sprite = FindSprite(path, fileName, resourceDirectory); if (sprite) return sprite; } SpritePtr pBitmap; str_type::string fixedName(path); Platform::FixSlashes(fixedName); ETHSpriteDensityManager::DENSITY_LEVEL densityLevel; const str_type::string finalFileName(m_densityManager.ChooseSpriteVersion(fixedName, video, densityLevel)); if (!(pBitmap = video->CreateSprite(finalFileName, (cutOutBlackPixels)? 0xFF000000 : 0xFFFF00FF))) { pBitmap.reset(); ETH_STREAM_DECL(ss) << GS_L("(Not loaded) ") << path; ETHResourceProvider::Log(ss.str(), Platform::Logger::ERROR); return SpritePtr(); } m_densityManager.SetSpriteDensity(pBitmap, densityLevel); //#if defined(_DEBUG) || defined(DEBUG) ETH_STREAM_DECL(ss) << GS_L("(Loaded) ") << fileName; ETHResourceProvider::Log(ss.str(), Platform::Logger::INFO); //#endif m_resource.insert(std::pair<str_type::string, SpriteResource>(fileName, SpriteResource(resourceDirectory, fixedName, pBitmap))); return pBitmap; }
bool ETHScene::AssignCallbackScript(ETHSpriteEntity* entity) { // removes extension from file name (to make a function name with it) const str_type::string entityName = ETHGlobal::RemoveExtension(entity->GetEntityName().c_str()); // assembles a function name based on it's ID. If we don't find any, // we'll try to find a function based on entity original file name str_type::stringstream funcName; funcName << ETH_CALLBACK_PREFIX << entity->GetID(); int id=-1; if ((id = CScriptBuilder::GetFunctionIdByName(m_pModule, funcName.str())) < 0) { // let's try to find a function with name based on the entity original file name funcName.str(GS_L("")); funcName << ETH_CALLBACK_PREFIX << entityName; id = CScriptBuilder::GetFunctionIdByName(m_pModule, funcName.str()); } // if we found anything... if (id >= 0) { entity->SetController(ETHEntityControllerPtr(new ETHRawEntityController(entity->GetController(), m_pContext, id))); #ifdef _DEBUG ETH_STREAM_DECL(ss) << GS_L("ETHScene::AssignCallbackScripts: Callback assigned (") << funcName.str() << GS_L(")."); m_provider->Log(ss.str(), Platform::FileLogger::INFO); #endif } else { str_type::stringstream ss; switch (id) { case asERROR: ss << GS_L("ETHScene::AssignCallbackScripts: invalid module (") << funcName.str() << GS_L(")."); m_provider->Log(ss.str(), Platform::FileLogger::ERROR); return false; case asMULTIPLE_FUNCTIONS: ss << GS_L("\n*Script error:\nETHScene::AssignCallbackScripts: there are multiple functions with this name (") << funcName.str() << GS_L(")."); m_provider->Log(ss.str(), Platform::FileLogger::ERROR); return false; }; } return true; }
void ETHBucketManager::Add(ETHRenderEntity* entity, const SIDE side) { const Vector2 bucket = ETHBucketManager::GetBucket(entity->GetPositionXY(), GetBucketSize()); if (side == FRONT) { m_entities[bucket].push_front(entity); } else { m_entities[bucket].push_back(entity); } #if defined(_DEBUG) || defined(DEBUG) ETH_STREAM_DECL(ss) << GS_L("Entity ") << entity->GetEntityName() << GS_L(" (ID#") << entity->GetID() << GS_L(") added to bucket ") << GS_L("(") << bucket.x << GS_L(", ") << bucket.y << GS_L(")"); m_provider->Log(ss.str(), Platform::Logger::INFO); #endif }
bool ETHActiveEntityHandler::RemoveFinishedTemporaryEntity(ETHRenderEntity* entity, ETHBucketManager& buckets) { if ((entity->IsTemporary() && entity->AreParticlesOver())) { const Vector2 v2Bucket = ETHBucketManager::GetBucket(entity->GetPositionXY(), buckets.GetBucketSize()); ETHBucketMap::iterator bucketIter = buckets.Find(v2Bucket); assert(bucketIter != buckets.GetLastBucket()); // Remove from main bucket map buckets.DeleteEntity(entity->GetID(), v2Bucket, false); #if defined(_DEBUG) || defined(DEBUG) ETH_STREAM_DECL(ss) << GS_L("Entity ") << entity->GetEntityName() << GS_L(" (ID#") << entity->GetID() << GS_L(") removed from dynamic entity list (particle effects over)"); m_provider->Log(ss.str(), Platform::Logger::INFO); #endif return true; } return false; }
ETHParticleManager::ETHParticleManager( ETHResourceProviderPtr provider, const str_type::string& file, const Vector2& v2Pos, const Vector3& v3Pos, const float angle, const float entityVolume) : m_provider(provider) { ETHParticleSystem partSystem; if (partSystem.ReadFromFile(file, m_provider->GetFileManager())) { CreateParticleSystem(partSystem, v2Pos, v3Pos, angle, entityVolume, 1.0f); } else { ETH_STREAM_DECL(ss) << GS_L("ETHParticleManager: file not found: ") << file; m_provider->Log(ss.str(), Platform::FileLogger::ERROR); } }
void ETHTempEntityHandler::CheckTemporaryEntities(const Vector2& zAxisDir, ETHBucketManager& buckets, const unsigned long lastFrameElapsedTime) { #ifdef _DEBUG TestEntityLists(); #endif for (std::list<ETHRenderEntity*>::iterator iter = m_dynamicOrTempEntities.begin(); iter != m_dynamicOrTempEntities.end();) { ETHRenderEntity* pRenderEntity = *iter; pRenderEntity->Update(lastFrameElapsedTime, zAxisDir, buckets); // if the particle system is finished, erase it if ((pRenderEntity->IsTemporary() && pRenderEntity->AreParticlesOver())) { const Vector2 v2Bucket = ETHGlobal::GetBucket(pRenderEntity->GetPositionXY(), buckets.GetBucketSize()); ETHBucketMap::iterator bucketIter = buckets.Find(v2Bucket); if (bucketIter == buckets.GetLastBucket()) { iter++; continue; } // Remove from main bucket map buckets.DeleteEntity(pRenderEntity->GetID(), v2Bucket, false); #ifdef _DEBUG ETH_STREAM_DECL(ss) << GS_L("Entity ") << (*iter)->GetEntityName() << GS_L(" (ID#") << pRenderEntity->GetID() << GS_L(") removed from dynamic entity list (particle effects over)"); m_provider->Log(ss.str(), Platform::Logger::INFO); #endif (*iter)->Release(); iter = m_dynamicOrTempEntities.erase(iter); continue; } iter++; } }
ETHLightmapGen::ETHLightmapGen(ETHRenderEntity* entity, boost::shared_ptr<ETHShaderManager> shaderManager, std::list<ETHLight>::iterator iBegin, std::list<ETHLight>::iterator iEnd, ETHBucketManager& buckets, const Vector3& oldPos, const Vector3& newPos, const float minHeight, const float maxHeight, const ETHSceneProperties &sceneProps) { const SpritePtr& sprite = entity->m_pSprite; const ETHEntityProperties& props = entity->m_properties; if (!sprite || !props.staticEntity || !props.applyLight) { return; } const VideoPtr& video = entity->m_provider->GetVideo(); const Platform::FileLogger* logger = entity->m_provider->GetLogger(); if (video->Rendering()) { ETH_STREAM_DECL(ss) << GS_L("Entity ID #") << entity->GetID() << GS_L(": lightmaps can't be generated during application render."); logger->Log(ss.str(), Platform::FileLogger::ERROR); return; } const Vector2 v2Size = (sprite->GetNumRects() <= 1) ? sprite->GetBitmapSizeF() : sprite->GetRect().size; if (!(entity->m_pLightmap = video->CreateRenderTarget(static_cast<unsigned int>(v2Size.x), static_cast<unsigned int>(v2Size.y)))) { ETH_STREAM_DECL(ss) << GS_L("ETHRenderEntity::GenerateLightmap: coudn't create the render target."); logger->Log(ss.str(), Platform::FileLogger::ERROR); entity->m_pLightmap.reset(); return; } // Paint it black video->SetRenderTarget(entity->m_pLightmap); if (!video->BeginTargetScene(GS_BLACK)) { ETH_STREAM_DECL(ss) << GS_L("ETHRenderEntity::GenerateLightmap: coudn't render to target."); logger->Log(ss.str(), Platform::FileLogger::ERROR); entity->m_pLightmap.reset(); return; } video->EndTargetScene(); entity->m_controller->SetPos(newPos); Vector2 v2CamPos = video->GetCameraPos(); video->SetCameraPos(Vector2(0,0)); for (std::list<ETHLight>::iterator iter = iBegin; iter != iEnd; iter++) { if (!iter->staticLight) continue; SpritePtr tempTarget; if (!(tempTarget = video->CreateRenderTarget(static_cast<unsigned int>(v2Size.x), static_cast<unsigned int>(v2Size.y)))) { ETH_STREAM_DECL(ss) << GS_L("ETHRenderEntity::GenerateLightmap: coudn't create temporary render target."); logger->Log(ss.str(), Platform::FileLogger::ERROR); entity->m_pLightmap.reset(); return; } if (!video->SetRenderTarget(tempTarget)) { ETH_STREAM_DECL(ss) << GS_L("ETHRenderEntity::GenerateLightmap: coudn't set render target."); logger->Log(ss.str(), Platform::FileLogger::ERROR); entity->m_pLightmap.reset(); return; } if (!video->BeginTargetScene(GS_BLACK)) { ETH_STREAM_DECL(ss) << GS_L("ETHRenderEntity::GenerateLightmap: coudn't render to temporary target."); logger->Log(ss.str(), Platform::FileLogger::ERROR); entity->m_pLightmap.reset(); return; } // draw light if (shaderManager->BeginLightPass(entity, &(*iter), video->GetScreenSizeF().y, 0.0f, sceneProps.lightIntensity, 0, true)) { entity->DrawLightPass(sceneProps.zAxisDirection, true); shaderManager->EndLightPass(); } // draw shadows if (entity->GetType() != ETH_VERTICAL) { for (ETHBucketMap::iterator bucketIter = buckets.GetFirstBucket(); bucketIter != buckets.GetLastBucket(); bucketIter++) { for (ETHEntityList::iterator entityIter = bucketIter->second.begin(); entityIter != bucketIter->second.end(); entityIter++) { if (!(*entityIter)->IsStatic()) continue; Vector3 oldPos2 = (*entityIter)->GetPosition(); Vector3 newPos2 = oldPos2-(oldPos-newPos); (*entityIter)->SetOrphanPosition(newPos2); if (shaderManager->BeginShadowPass((*entityIter), &(*iter), maxHeight, minHeight)) { (*entityIter)->DrawShadow(maxHeight, minHeight, sceneProps, *iter, 0, true, true, entity->GetAngle(), entity->GetPosition()); shaderManager->EndShadowPass(); } (*entityIter)->SetOrphanPosition(oldPos2); } } } video->EndTargetScene(); // draw the shadowed light by adding it to the final lightmap video->SetRenderTarget(entity->m_pLightmap); video->BeginTargetScene(GS_BLACK, false); const GS_ALPHA_MODE oldAM = video->GetAlphaMode(); video->SetAlphaMode(GSAM_ADD); tempTarget->Draw(Vector2(0,0)); video->SetAlphaMode(oldAM); video->EndTargetScene(); } entity->m_pLightmap->GenerateBackup(); video->SetRenderTarget(SpritePtr()); video->SetCameraPos(v2CamPos); }
void ETHActiveEntityHandler::UpdateActiveEntities(const Vector2& zAxisDir, ETHBucketManager& buckets, const unsigned long lastFrameElapsedTime) { #if defined(_DEBUG) || defined(DEBUG) TestEntityLists(); #endif for (std::list<ETHRenderEntity*>::iterator iter = m_dynamicOrTempEntities.begin(); iter != m_dynamicOrTempEntities.end();) { ETHRenderEntity* entity = (*iter); if (!(entity->IsAlive()) || RemoveFinishedTemporaryEntity(entity, buckets)) { #if defined(_DEBUG) || defined(DEBUG) ETH_STREAM_DECL(ss) << GS_L("Entity removed from dynamic entity list: ") << entity->GetEntityName(); m_provider->Log(ss.str(), Platform::Logger::INFO); #endif entity->Release(); iter = m_dynamicOrTempEntities.erase(iter); continue; } entity->Update(lastFrameElapsedTime, zAxisDir, buckets); if (entity->HasAnyCallbackFunction()) { entity->RunCallbackScript(); } ++iter; } // todo/to-do remove duplicate code for (std::list<ETHRenderEntity*>::iterator iter = m_lastFrameCallbacks.begin(); iter != m_lastFrameCallbacks.end();) { ETHRenderEntity* entity = (*iter); if (!(entity->IsAlive())) { #if defined(_DEBUG) || defined(DEBUG) ETH_STREAM_DECL(ss) << GS_L("Entity callback removed: ") << entity->GetEntityName(); m_provider->Log(ss.str(), Platform::Logger::INFO); #endif entity->Release(); iter = m_lastFrameCallbacks.erase(iter); continue; } else { entity->Update(lastFrameElapsedTime, zAxisDir, buckets); if (entity->HasAnyCallbackFunction()) { entity->RunCallbackScript(); } entity->Release(); ++iter; } } m_lastFrameCallbacks.clear(); }
bool ETHScene::GenerateLightmaps(const int id) { if (!m_provider->IsRichLightingEnabled()) { return false; } // save current global scale and temporarily set it to 1 const ETHGlobalScaleManagerPtr& scaleManager = m_provider->GetGlobalScaleManager(); const float globalScale = scaleManager->GetScale(); scaleManager->SetScaleFactor(1.0f); const ETHSpriteEntity *pRender = (id >= 0) ? m_buckets.SeekEntity(id) : 0; const Vector2 v2Bucket = (pRender) ? ETHBucketManager::GetBucket(pRender->GetPositionXY(), GetBucketSize()) : Vector2(0,0); for (ETHBucketMap::iterator bucketIter = m_buckets.GetFirstBucket(); bucketIter != m_buckets.GetLastBucket(); ++bucketIter) { // if we're lighting only one entity and it is not in this bucket, skip it. // I know we could have used the find method to go directly to that bucket // but this function os not that critical to make the effort worth it. if (id >= 0) if (v2Bucket != bucketIter->first) continue; // iterate over all entities in this bucket ETHEntityList& entityList = bucketIter->second; ETHEntityList::const_iterator iEnd = entityList.end(); for (ETHEntityList::iterator iter = entityList.begin(); iter != iEnd; ++iter) { ETHRenderEntity* entity = (*iter); // if nID is valid, let's try to generate the lightmap for this one and only entity if (id >= 0) if (id != entity->GetID()) continue; Vector2 v2Size(1,1); Vector2 v2AbsoluteOrigin(0,0); if (entity->GetSprite()) { v2Size = entity->GetCurrentSize(); v2AbsoluteOrigin = entity->ComputeAbsoluteOrigin(v2Size); } // Place the current entity at the top-left corner to align // it to the render target const Vector3 oldPos = entity->GetPosition(); const Vector3 newPos = Vector3(v2AbsoluteOrigin.x, v2AbsoluteOrigin.y, 0); std::list<ETHLight> lights; // fill the light list for (ETHBucketMap::iterator lbucketIter = m_buckets.GetFirstBucket(); lbucketIter != m_buckets.GetLastBucket(); ++lbucketIter) { ETHEntityList& lEntityList = lbucketIter->second; ETHEntityList::const_iterator liEnd = lEntityList.end(); for (ETHEntityList::iterator liter = lEntityList.begin(); liter != liEnd; ++liter) { ETHRenderEntity* lightEntity = (*liter); if (lightEntity->IsStatic() && lightEntity->HasLightSource()) { lights.push_back( ETHEntityRenderingManager::BuildChildLight( *(lightEntity->GetLight()), newPos - oldPos + lightEntity->GetPosition(), lightEntity->GetScale())); } } } if (lights.size() > 0) { ETHLightmapGen((*iter), m_provider->GetShaderManager(), lights.begin(), lights.end(), m_buckets, oldPos, newPos, m_minSceneHeight, m_maxSceneHeight, m_sceneProps); } else { entity->ReleaseLightmap(); } entity->SetOrphanPosition(oldPos); lights.clear(); } } #if defined(_DEBUG) || defined(DEBUG) ETH_STREAM_DECL(ss) << GS_L("Lightmaps created... "); m_provider->Log(ss.str(), Platform::FileLogger::INFO); #endif // go back to the previous global scale scaleManager->SetScaleFactor(globalScale); return true; }
bool ETHScene::GenerateLightmaps(const int id) { const ETHSpriteEntity *pRender = (id >= 0) ? m_buckets.SeekEntity(id) : 0; const Vector2 v2Bucket = (pRender) ? ETHGlobal::GetBucket(pRender->GetPositionXY(), GetBucketSize()) : Vector2(0,0); for (ETHBucketMap::iterator bucketIter = m_buckets.GetFirstBucket(); bucketIter != m_buckets.GetLastBucket(); bucketIter++) { // if we're lighting only one entity and it is not in this bucket, skip it. // I know we could have used the find method to go directly to that bucket // but this function os not that critical to make the effort worth it. if (id >= 0) if (v2Bucket != bucketIter->first) continue; // iterate over all entities in this bucket ETHEntityList::const_iterator iEnd = bucketIter->second.end(); for (ETHEntityList::iterator iter = bucketIter->second.begin(); iter != iEnd; iter++) { // if nID is valid, let's try to generate the lightmap for this one and only entity if (id >= 0) if (id != (*iter)->GetID()) continue; Vector2 v2Size(1,1); Vector2 v2Origin(0,0); if ((*iter)->GetSprite()) { v2Size = (*iter)->GetCurrentSize(); v2Origin = (*iter)->ComputeOrigin(v2Size); } // Place the current entity at the top-left corner to align // it to the render target const Vector3 oldPos = (*iter)->GetPosition(); const Vector3 newPos = Vector3(v2Origin.x, v2Origin.y, 0); // fill the light list for (ETHBucketMap::iterator lbucketIter = m_buckets.GetFirstBucket(); lbucketIter != m_buckets.GetLastBucket(); lbucketIter++) { ETHEntityList::const_iterator liEnd = lbucketIter->second.end(); for (ETHEntityList::iterator liter = lbucketIter->second.begin(); liter != liEnd; liter++) { if ((*liter)->IsStatic() && (*liter)->HasLightSource()) { AddLight(*((*liter)->GetLight()), newPos-oldPos+(*liter)->GetPosition()); } } } ETHLightmapGen((*iter), m_provider->GetShaderManager(), m_lights.begin(), m_lights.end(), m_buckets, oldPos, newPos, m_minSceneHeight, m_maxSceneHeight, m_sceneProps); (*iter)->SetOrphanPosition(oldPos); m_lights.clear(); } } #ifdef _DEBUG ETH_STREAM_DECL(ss) << GS_L("Lightmaps created... "); m_provider->Log(ss.str(), Platform::FileLogger::INFO); #endif return true; }
void ETHScriptWrapper::Print(const str_type::string &str) { ETH_STREAM_DECL(ss) << str; m_provider->Log(ss.str(), Platform::FileLogger::INFO); }
void ETHScriptWrapper::PrintFloat(const float f) { ETH_STREAM_DECL(ss) << f; m_provider->Log(ss.str(), Platform::FileLogger::INFO); }
bool ETHParticleManager::CreateParticleSystem( const ETHParticleSystem& partSystem, const Vector2& v2Pos, const Vector3& v3Pos, const float angle, const float entityVolume, const float scale) { GS2D_UNUSED_ARGUMENT(v3Pos); if (partSystem.nParticles <= 0) { ETH_STREAM_DECL(ss) << GS_L("ETHParticleManager::CreateParticleSystem: The number of particles must be greater than 0."); m_provider->Log(ss.str(), Platform::FileLogger::ERROR); return false; } m_finished = false; m_killed = false; m_nActiveParticles = 0; m_soundVolume = 1.0f; m_isSoundLooping = false; m_isSoundStopped = false; m_generalVolume = 1.0f; m_system = partSystem; m_entityVolume = entityVolume; m_system.Scale(scale); if (m_system.bitmapFile.empty()) { m_system.bitmapFile = ETH_DEFAULT_PARTICLE_BITMAP; } ETHGraphicResourceManagerPtr graphics = m_provider->GetGraphicResourceManager(); ETHAudioResourceManagerPtr samples = m_provider->GetAudioResourceManager(); Platform::FileIOHubPtr fileIOHub = m_provider->GetFileIOHub(); Platform::FileManagerPtr fileManager = m_provider->GetFileManager(); // if there's no resource path, search the current module's path const str_type::string& resourcePath = fileIOHub->GetResourceDirectory(); const str_type::string& programPath = fileIOHub->GetProgramDirectory(); const str_type::string currentPath = (resourcePath.empty() && !fileManager->IsPacked()) ? programPath : resourcePath; m_pBMP = graphics->GetPointer(m_provider->GetVideo(), m_system.bitmapFile, currentPath, ETHDirectories::GetParticlesDirectory(), (m_system.alphaMode == Video::AM_ADD)); // find the particle sound effect if (m_system.soundFXFile != GS_L("")) { m_pSound = samples->GetPointer(m_provider->GetAudio(), m_provider->GetFileIOHub(), m_system.soundFXFile, ETHDirectories::GetSoundFXDirectory(), Audio::SOUND_EFFECT); } if (m_system.allAtOnce) { m_nActiveParticles = m_system.nParticles; } else { m_nActiveParticles = 0; } m_particles.resize(m_system.nParticles); Matrix4x4 rot = RotateZ(DegreeToRadian(angle)); for (int t = 0; t < m_system.nParticles; t++) { m_particles[t].id = t; m_particles[t].released = false; ResetParticle(t, v2Pos, Vector3(v2Pos,0), angle, rot); } return true; }
bool ETHParticleManager::DrawParticleSystem( Vector3 v3Ambient, const float maxHeight, const float minHeight, const DEPTH_SORTING_MODE ownerType, const Vector2& zAxisDirection, const Vector2& parallaxOffset, const float ownerDepth) { if (!m_pBMP) { ETH_STREAM_DECL(ss) << GS_L("ETHParticleManager::DrawParticleSystem: Invalid particle system bitmap"); m_provider->Log(ss.str(), Platform::FileLogger::WARNING); return false; } const VideoPtr& video = m_provider->GetVideo(); Video::ALPHA_MODE alpha = video->GetAlphaMode(); video->SetAlphaMode(m_system.alphaMode); // if the alpha blending is not additive, we'll have to sort it if (alpha == Video::AM_PIXEL) { BubbleSort(m_particles); } m_pBMP->SetOrigin(Sprite::EO_CENTER); for (int t = 0; t < m_system.nParticles; t++) { const PARTICLE& particle = m_particles[t]; if (m_system.repeat > 0) if (particle.repeat >= m_system.repeat) continue; if (particle.size <= 0.0f || !particle.released) continue; if (Killed() && particle.elapsed > particle.lifeTime) continue; Vector3 v3FinalAmbient(1, 1, 1); if (m_system.alphaMode == Video::AM_PIXEL || m_system.alphaMode == Video::AM_ALPHA_TEST) { v3FinalAmbient.x = Min(m_system.emissive.x + v3Ambient.x, 1.0f); v3FinalAmbient.y = Min(m_system.emissive.y + v3Ambient.y, 1.0f); v3FinalAmbient.z = Min(m_system.emissive.z + v3Ambient.z, 1.0f); } Color dwColor; const Vector4& color(particle.color); dwColor.a = (GS_BYTE)(color.w * 255.0f); dwColor.r = (GS_BYTE)(color.x * v3FinalAmbient.x * 255.0f); dwColor.g = (GS_BYTE)(color.y * v3FinalAmbient.y * 255.0f); dwColor.b = (GS_BYTE)(color.z * v3FinalAmbient.z * 255.0f); // compute the right in-screen position const Vector2 v2Pos = ETHGlobal::ToScreenPos(Vector3(particle.pos, m_system.startPoint.z), zAxisDirection); SetParticleDepth(ComputeParticleDepth(ownerType, ownerDepth, particle, maxHeight, minHeight)); // draw if (m_system.spriteCut.x > 1 || m_system.spriteCut.y > 1) { if ((int)m_pBMP->GetNumColumns() != m_system.spriteCut.x || (int)m_pBMP->GetNumRows() != m_system.spriteCut.y) m_pBMP->SetupSpriteRects(m_system.spriteCut.x, m_system.spriteCut.y); m_pBMP->SetRect(particle.currentFrame); } else { m_pBMP->UnsetRect(); } m_pBMP->DrawOptimal((v2Pos + parallaxOffset), dwColor, particle.angle, Vector2(particle.size, particle.size)); } video->SetAlphaMode(alpha); return true; }
void ETHScriptWrapper::PrintUInt(const unsigned int n) { ETH_STREAM_DECL(ss) << n; m_provider->Log(ss.str(), Platform::FileLogger::INFO); }
bool ETHBucketManager::DeleteEntity(const int id, const Vector2 &searchBucket, const bool stopSfx) { ETHBucketMap::iterator bucketIter = Find(searchBucket); // try getting it from bucket (faster) if (bucketIter != GetLastBucket()) { ETHEntityList& entityList = bucketIter->second; ETHEntityList::const_reverse_iterator iEnd = entityList.rend(); for (ETHEntityList::reverse_iterator iter = entityList.rbegin(); iter != iEnd; ++iter) { if ((*iter)->GetID() == id) { #if defined(_DEBUG) || defined(DEBUG) ETH_STREAM_DECL(ss) << GS_L("Entity ") << (*iter)->GetEntityName() << GS_L(" (ID#") << (*iter)->GetID() << GS_L(") removed (DeleteEntity method)"); m_provider->Log(ss.str(), Platform::Logger::INFO); #endif if (m_entityKillListener) m_entityKillListener->EntityKilled((*iter)); if(!stopSfx) (*iter)->SetStopSFXWhenDestroyed(false); (*iter)->Kill(); (*iter)->Release(); ETHEntityList::iterator i = iter.base(); --i; entityList.erase(i); return true; } } } // If it can't find it, it probably means the entity is lost and its move // request has been sent. Let's just kill it then for (bucketIter = GetFirstBucket(); bucketIter != GetLastBucket(); ++bucketIter) { ETHEntityList& entityList = bucketIter->second; ETHEntityList::const_iterator iEnd = entityList.end(); for (ETHEntityList::iterator iter = entityList.begin(); iter != iEnd; ++iter) { if ((*iter)->GetID() == id) { #if defined(_DEBUG) || defined(DEBUG) ETH_STREAM_DECL(ss) << GS_L("Entity ") << (*iter)->GetEntityName() << GS_L(" (ID#") << (*iter)->GetID() << GS_L(") removed (DeleteEntity method)"); m_provider->Log(ss.str(), Platform::Logger::INFO); #endif if (m_entityKillListener) m_entityKillListener->EntityKilled((*iter)); (*iter)->Kill(); return true; } } } ETH_STREAM_DECL(ss) << GS_L("Couldn't find the entity to delete: ID") << id; m_provider->Log(ss.str(), Platform::Logger::ERROR); return false; }