void Tribe::HandlePersistItem(gemNPCItem* item) { csVector3 position; iSector* sector; psGameObject::GetPosition(item,position,sector); // Check if we have this item as an asset Asset* asset = GetAsset(item->GetUID()); if(asset) { asset->item = item; } else { // TODO: Find buildings and items and add them seperate, for now add as BUILDING. asset = GetAsset(Tribe::ASSET_TYPE_BUILDING, item->GetName(), position, sector); if(asset) { asset->item = item; asset->itemUID = item->GetUID(); SaveAsset(asset); } else { // Add the new tribe item as an asset. asset = AddAsset(Tribe::ASSET_TYPE_BUILDING, item->GetName(), position, sector, Tribe::ASSET_STATUS_CONSTRUCTED); asset->item = item; asset->itemUID = item->GetUID(); SaveAsset(asset); } } }
void GenericBsa::Extract(const std::string& assetPath, const uint8_t ** const _data, size_t * const _size) const { //Get asset data. BsaAsset data = GetAsset(assetPath); if (data.path.empty()) throw error(LIBBSA_ERROR_INVALID_ARGS, "Asset not found"); pair<uint8_t*, size_t> dataPair; try { //Read file data. boost::filesystem::ifstream in(filePath, ios::binary); in.exceptions(ios::failbit | ios::badbit | ios::eofbit); //Causes ifstream::failure to be thrown if problem is encountered. dataPair = ReadData(in, data); *_data = dataPair.first; *_size = dataPair.second; in.close(); } catch (ios_base::failure& e) { delete[] dataPair.first; throw error(LIBBSA_ERROR_FILESYSTEM_ERROR, e.what()); } }
void SGlobalOpenAssetDialog::OnPressedEnterOnAssetsInPicker(const TArray<FAssetData>& SelectedAssets) { for (auto AssetIt = SelectedAssets.CreateConstIterator(); AssetIt; ++AssetIt) { if (UObject* ObjectToEdit = AssetIt->GetAsset()) { FAssetEditorManager::Get().OpenEditorForAsset(ObjectToEdit); } } }
AssetHandle AssetManager::GetAsset(std::string assetId) { int id = GetIdFromName(assetId); if (id == -1) { Asset* a = LoadAsset(assetId); if (!a) throw AssetException(AssetException::ASSETFAILEDTOLOAD); return a; } return GetAsset((unsigned)id); }
FReply SContentReference::OnClickUseButton() { TArray<FAssetData> Objects; FContentBrowserModule& ContentBrowserModule = FModuleManager::Get().LoadModuleChecked<FContentBrowserModule>(TEXT("ContentBrowser")); ContentBrowserModule.Get().GetSelectedAssets(Objects); for(auto It(Objects.CreateIterator());It;++It) { OnSetReference.ExecuteIfBound(It->GetAsset()); } return FReply::Handled(); }
void AssetManager::CheckForChangedAssets() { // Iterate through all assets for (std::pair<const unsigned, Asset*>& asset : mAssetContainer) { if (asset.second->mName == AssetHandleFee) continue; if (!asset.second->FileID().Valid()) continue; boost::filesystem::path filePath = asset.second->FileID().Filename(); boost::filesystem::path metaPath = filePath; metaPath += MetaExt; // If meta file already created, check time stamp if (boost::filesystem::exists(metaPath)) { // Check time stamp FILETIME writeTime = GetTimeStamp(filePath), metaTime = GetMetaTimeStamp(metaPath); // meta time is earlier than write time, reload asset if (CompareFileTime(&metaTime, &writeTime) < 0) { //UniqueFileID fileid(filePath.string()); GetAsset(filePath.leaf().string()).GetRawAssetPtr()->OnAssetFileChanged(); // Write time stamp to meta file WriteTimeStamp(metaPath, writeTime); } } else { // Write time stamp to meta file FILETIME writeTime = GetTimeStamp(filePath); WriteTimeStamp(metaPath, writeTime); } } }
void Tribe::Unbuild(NPC* npc, gemNPCItem* building) { NPCDebug(npc, 6, "Unbuilding building %s",building->GetName()); Asset* buildingAsset = GetAsset(building); if(buildingAsset) { buildingAsset->status = ASSET_STATUS_NOT_USED; buildingAsset->quantity = 0; SaveAsset(buildingAsset); // Check if there is a building spot that need to be downgrades as well csVector3 buildingPos = npc->GetTribe()->GetHomePosition(); buildingPos -= buildingAsset->pos; Asset* buildingSpot = GetNearestAsset(Tribe::ASSET_TYPE_BUILDINGSPOT, buildingAsset->name, Tribe::ASSET_STATUS_CONSTRUCTED, buildingPos, NULL, 5.0, NULL); if(buildingSpot) { buildingSpot->status = Tribe::ASSET_STATUS_NOT_USED; SaveAsset(buildingSpot); // Now the building asset and the spot is freed inform the server npcclient->GetNetworkMgr()->QueueUnbuildCommand(npc->GetActor(), building); } else { Error4("NPC %s(%s) Failed to find building spot for building %s",npc->GetName(),ShowID(npc->GetEID()),building->GetName()); } } else { Error4("NPC %s(%s) Failed to find building asset for building %s",npc->GetName(),ShowID(npc->GetEID()),building->GetName()); } }
ERet DeferredRenderer::RenderScene( const SceneView& sceneView, const Clump& sceneData ) { gfxMARKER(RenderScene); if( sceneView.viewportWidth != m_viewportWidth || sceneView.viewportHeight != m_viewportHeight ) { this->ResizeBuffers( sceneView.viewportWidth, sceneView.viewportHeight, false ); m_viewportWidth = sceneView.viewportWidth; m_viewportHeight = sceneView.viewportHeight; } mxDO(BeginRender_GBuffer()); G_PerCamera cbPerView; { cbPerView.g_viewMatrix = sceneView.viewMatrix; cbPerView.g_viewProjectionMatrix = sceneView.viewMatrix * sceneView.projectionMatrix; cbPerView.g_inverseViewMatrix = Matrix_OrthoInverse( sceneView.viewMatrix ); cbPerView.g_projectionMatrix = sceneView.projectionMatrix; cbPerView.g_inverseProjectionMatrix = ProjectionMatrix_Inverse( sceneView.projectionMatrix ); cbPerView.g_inverseViewProjectionMatrix = Matrix_Inverse( cbPerView.g_viewProjectionMatrix ); cbPerView.g_WorldSpaceCameraPos = sceneView.worldSpaceCameraPos; float n = sceneView.nearClip; float f = sceneView.farClip; float x = 1 - f / n; float y = f / n; float z = x / f; float w = y / f; cbPerView.g_ZBufferParams = Float4_Set( x, y, z, w ); cbPerView.g_ZBufferParams2 = Float4_Set( n, f, 1.0f/n, 1.0f/f ); float H = sceneView.projectionMatrix[0][0]; float V = sceneView.projectionMatrix[2][1]; float A = sceneView.projectionMatrix[1][2]; float B = sceneView.projectionMatrix[3][2]; cbPerView.g_ProjParams = Float4_Set( H, V, A, B ); // x = 1/H // y = 1/V // z = 1/B // w = -A/B cbPerView.g_ProjParams2 = Float4_Set( 1/H, 1/V, 1/B, -A/B ); llgl::UpdateBuffer(llgl::GetMainContext(), m_hCBPerCamera, sizeof(cbPerView), &cbPerView); } // G-Buffer Stage: Render all solid objects to a very sparse G-Buffer { gfxMARKER(Fill_Geometry_Buffer); mxDO(FxSlow_SetRenderState(m_hRenderContext, *m_rendererData, "Default")); G_PerObject cbPerObject; TObjectIterator< rxModel > modelIt( sceneData ); while( modelIt.IsValid() ) { const rxModel& model = modelIt.Value(); const Float3x4* TRS = model.m_transform; { cbPerObject.g_worldMatrix = Float3x4_Unpack( *TRS ); cbPerObject.g_worldViewMatrix = Matrix_Multiply(cbPerObject.g_worldMatrix, sceneView.viewMatrix); cbPerObject.g_worldViewProjectionMatrix = Matrix_Multiply(cbPerObject.g_worldMatrix, sceneView.viewProjectionMatrix); llgl::UpdateBuffer(m_hRenderContext, m_hCBPerObject, sizeof(cbPerObject), &cbPerObject); } const rxMesh* mesh = model.m_mesh; for( int iSubMesh = 0; iSubMesh < mesh->m_parts.Num(); iSubMesh++ ) { const rxSubmesh& submesh = mesh->m_parts[iSubMesh]; const rxMaterial* material = model.m_batches[iSubMesh]; const FxShader* shader = material->m_shader; if( shader->localCBs.Num() ) { mxASSERT(shader->localCBs.Num()==1); const ParameterBuffer& uniforms = material->m_uniforms; const FxCBuffer& rCB = shader->localCBs[0]; llgl::UpdateBuffer(m_hRenderContext, rCB.handle, uniforms.GetDataSize(), uniforms.ToPtr() ); } llgl::DrawCall batch; batch.Clear(); SetGlobalUniformBuffers( &batch ); BindMaterial( material, &batch ); batch.inputLayout = Rendering::g_inputLayouts[VTX_Draw]; batch.topology = mesh->m_topology; batch.VB[0] = mesh->m_vertexBuffer; batch.IB = mesh->m_indexBuffer; batch.b32bit = (mesh->m_indexStride == sizeof(UINT32)); batch.baseVertex = submesh.baseVertex; batch.vertexCount = submesh.vertexCount; batch.startIndex = submesh.startIndex; batch.indexCount = submesh.indexCount; llgl::Submit(m_hRenderContext, batch); } modelIt.MoveToNext(); } } EndRender_GBuffer(); // Deferred Lighting Stage: Accumulate all lights as a screen space operation { gfxMARKER(Deferred_Lighting); llgl::ViewState viewState; { viewState.Reset(); viewState.colorTargets[0].SetDefault(); viewState.targetCount = 1; viewState.flags = llgl::ClearColor; } llgl::SubmitView(m_hRenderContext, viewState); { gfxMARKER(Directional_Lights); mxDO(FxSlow_SetRenderState(m_hRenderContext, *m_rendererData, "Deferred_Lighting")); FxShader* shader; mxDO(GetByName(*m_rendererData, "deferred_directional_light", shader)); mxDO2(FxSlow_SetResource(shader, "GBufferTexture0", llgl::AsResource(m_colorRT0->handle), Rendering::g_samplers[PointSampler])); mxDO2(FxSlow_SetResource(shader, "GBufferTexture1", llgl::AsResource(m_colorRT1->handle), Rendering::g_samplers[PointSampler])); mxDO2(FxSlow_SetResource(shader, "DepthTexture", llgl::AsResource(m_depthRT->handle), Rendering::g_samplers[PointSampler])); TObjectIterator< rxGlobalLight > lightIt( sceneData ); while( lightIt.IsValid() ) { rxGlobalLight& light = lightIt.Value(); //mxDO(FxSlow_Commit(m_hRenderContext,shader)); DirectionalLight lightData; { lightData.direction = Matrix_TransformNormal(sceneView.viewMatrix, light.m_direction); lightData.color = light.m_color; } mxDO2(FxSlow_UpdateUBO(m_hRenderContext,shader,"DATA",&lightData,sizeof(lightData))); DrawFullScreenTriangle(shader); lightIt.MoveToNext(); } } { gfxMARKER(Point_Lights); mxDO(FxSlow_SetRenderState(m_hRenderContext, *m_rendererData, "Deferred_Lighting")); FxShader* shader; mxDO(GetAsset(shader,MakeAssetID("deferred_point_light.shader"),m_rendererData)); mxDO2(FxSlow_SetResource(shader, "GBufferTexture0", llgl::AsResource(m_colorRT0->handle), Rendering::g_samplers[PointSampler])); mxDO2(FxSlow_SetResource(shader, "GBufferTexture1", llgl::AsResource(m_colorRT1->handle), Rendering::g_samplers[PointSampler])); mxDO2(FxSlow_SetResource(shader, "DepthTexture", llgl::AsResource(m_depthRT->handle), Rendering::g_samplers[PointSampler])); TObjectIterator< rxLocalLight > lightIt( sceneData ); while( lightIt.IsValid() ) { rxLocalLight& light = lightIt.Value(); //mxDO(FxSlow_Commit(m_hRenderContext,shader)); PointLight lightData; { Float3 viewSpaceLightPosition = Matrix_TransformPoint(sceneView.viewMatrix, light.position); lightData.Position_InverseRadius = Float4_Set(viewSpaceLightPosition, 1.0f/light.radius); lightData.Color_Radius = Float4_Set(light.color, light.radius); } mxDO2(FxSlow_UpdateUBO(m_hRenderContext,shader,"DATA",&lightData,sizeof(lightData))); DrawFullScreenTriangle(shader); lightIt.MoveToNext(); } } } // Thursday, March 26, 2015 Implementing Weighted, Blended Order-Independent Transparency //http://casual-effects.blogspot.ru/2015/03/implemented-weighted-blended-order.html // Forward+ notes //http://bioglaze.blogspot.fi/2014/07/2048-point-lights-60-fps.html // Material Stage: Render all solid objects again while combining the lighting // from Stage 2 with certain material-properties (colors, reflections, glow, fog, etc.) // to produce the final image #if 0 { llgl::ViewState viewState; { viewState.Reset(); viewState.colorTargets[0].SetDefault(); viewState.targetCount = 1; } llgl::SubmitView(m_hRenderContext, viewState); } { mxDO(FxSlow_SetRenderState(m_hRenderContext, *m_rendererData, "NoCulling")); FxShader* shader; mxDO(GetByName(*m_rendererData, "full_screen_triangle", shader)); mxDO(FxSlow_SetResource(shader, "t_sourceTexture", llgl::AsResource(pColorRT1->handle), Rendering::g_samplers[PointSampler])); mxDO(FxSlow_Commit(m_hRenderContext,shader)); DrawFullScreenTriangle(shader); } #endif #if 0 { llgl::ViewState viewState; { viewState.Reset(); viewState.colorTargets[0].SetDefault(); viewState.targetCount = 1; } llgl::SubmitView(m_hRenderContext, viewState); } { FxShader* shader; mxDO(FxSlow_SetRenderState(m_hRenderContext, *m_rendererData, "Default")); { mxDO(GetAsset(shader,MakeAssetID("debug_draw_colored.shader"),m_rendererData)); mxDO(FxSlow_SetUniform(shader,"g_color",RGBAf::GRAY.ToPtr())); mxDO(FxSlow_Commit(m_hRenderContext,shader)); DBG_Draw_Models_With_Custom_Shader(sceneView, sceneData, *shader); } mxDO(FxSlow_SetRenderState(m_hRenderContext, *m_rendererData, "NoCulling")); { mxDO(GetAsset(shader,MakeAssetID("debug_draw_normals.shader"),m_rendererData)); float lineLength = 4.0f; mxDO(FxSlow_SetUniform(shader,"g_lineLength",&lineLength)); mxDO(FxSlow_Commit(m_hRenderContext,shader)); DBG_Draw_Models_With_Custom_Shader(sceneView, sceneData, *shader, Topology::PointList); } } #endif return ALL_OK; }
void myLevelSystem::ProcessEntity(const tinyxml2::XMLNode* EntityNode) { const tinyxml2::XMLElement* entityElement = EntityNode->ToElement(); std::string entityId; float posx; float posy; float rot; float scaleX; float scaleY; bool canAdd = true; do { if (entityElement->Attribute("id") == NULL) { break; } if (entityElement->Attribute("x") == NULL) { break; } if (entityElement->Attribute("y") == NULL) { break; } if (entityElement->Attribute("rot") == NULL) { break; } if (entityElement->Attribute("scalex") == NULL) { break; } if (entityElement->Attribute("scaley") == NULL) { break; } entityId = std::string((entityElement->Attribute("id"))); posx = myMath::PixelsToMeters((float) atof(entityElement->Attribute("x"))); posy = myMath::PixelsToMeters((float) atof(entityElement->Attribute("y"))); rot = (float) atof(entityElement->Attribute("rot")); rot = myMath::DegreesToRadians(rot); scaleX = (float) atof(entityElement->Attribute("scalex")); scaleY = (float) atof(entityElement->Attribute("scaley")); std::shared_ptr<myEntity> entity(new myEntity(entityId, posx, posy, rot, scaleX, scaleY)); // Process Components for (const tinyxml2::XMLNode* componentNode = EntityNode->FirstChild(); componentNode; componentNode = componentNode->NextSibling()) { const tinyxml2::XMLElement* componentElement = componentNode->ToElement(); if (strcmp(componentElement->Name(), "Component") == 0) { std::string componentId; int type; bool enabled; do { if (componentElement->Attribute("id") == NULL) { break; } if (componentElement->Attribute("type") == NULL) { break; } if (componentElement->Attribute("enabled") == NULL) { break; } componentId = std::string(componentElement->Attribute("id")); type = atoi(componentElement->Attribute("type")); enabled = (atoi(componentElement->Attribute("enabled")) != 0); switch (type) { case myComponent::RENDER: { const tinyxml2::XMLElement* assetElement = componentNode->FirstChild()->ToElement(); std::string assetId(assetElement->Attribute("asset")); std::shared_ptr<myAsset> asset = GetAsset(assetId); switch (asset->type) { case myAsset::SPRITE: { myDebug::Log(myDebug::LOG_INFO, "Loaded:\n%s", asset->ToString().c_str()); std::shared_ptr<myRenderComponent> component(new myRenderComponent(componentId, std::static_pointer_cast < mySprite > (asset), enabled)); entity->AddComponent(component); } break; case myAsset::SPRITE_SHEET: { myDebug::Log(myDebug::LOG_INFO, "Loaded:\n%s", asset->ToString().c_str()); std::shared_ptr<myRenderComponent> component(new myRenderComponent(componentId, std::static_pointer_cast < mySpriteSheet > (asset), enabled)); entity->AddComponent(component); } break; } } break; case myComponent::AUDIO: break; case myComponent::PHYSICS: { const tinyxml2::XMLElement* physicsElement = componentNode->FirstChild()->ToElement(); unsigned int bodyType = atoi(physicsElement->Attribute("type")); float density = (float) atof(physicsElement->Attribute("density")); float friction = (float) atof(physicsElement->Attribute("friction")); float restitution = (float) atof(physicsElement->Attribute("restitution")); float gravityScale = (float) atof(physicsElement->Attribute("gravityScale")); bool allowSleep = (atoi(physicsElement->Attribute("allowSleep")) != 0); std::shared_ptr<myPhysicsComponent> component(new myPhysicsComponent(componentId, bodyType, enabled)); component->density = density; component->friction = friction; component->restitution = restitution; component->gravityScale = gravityScale; component->allowSleep = allowSleep; entity->AddComponent(component); } break; case myComponent::INPUT: { const tinyxml2::XMLElement* inputElement = componentNode->FirstChild()->ToElement(); std::shared_ptr<myInputComponent> component(new myInputComponent(componentId, enabled)); entity->AddComponent(component); } break; case myComponent::SCRIPT: { const tinyxml2::XMLElement* scriptElement = componentNode->FirstChild()->ToElement(); std::string filename(scriptElement->Attribute("filename")); std::shared_ptr<myScriptComponent> component(new myScriptComponent(componentId, filename, enabled)); entity->AddComponent(component); } } /*if (component) { entity->AddComponent(component); Debug::Log(Debug::LOG_INFO, "Added Component To: %s\n%s", entity->GetId().c_str(), component->ToString().c_str()); }*/ } while (0); } } // process components for (auto sharedEntity : _sharedEntities) { if (strcmp(entity->GetId().c_str(), sharedEntity->GetId().c_str()) == 0) { canAdd = false; } } if (canAdd) { myDebug::Log(myDebug::LOG_INFO, "Loaded:\n%s", entity->ToString().c_str()); _sharedEntities.push_back(entity); } else { myDebug::Log(myDebug::LOG_INFO, "Could Not Load:\n%s", entity->ToString().c_str()); } } while (0); }