//----------------------------------------------------------------------------- CPUTMeshDX11::~CPUTMeshDX11() { //CC added // Release the index buffer SAFE_DELETE_ARRAY(mpIndexData); SAFE_DELETE_ARRAY(mpRawIndices); // Release the vertex buffer SAFE_DELETE_ARRAY(mpVertexData); _aligned_free(mpRawVertices); // CC added ends ClearAllObjects(); }
void CLevel::OnFrame () { #ifdef DEBUG_MEMORY_MANAGER debug_memory_guard __guard__; #endif // DEBUG_MEMORY_MANAGER #ifdef DEBUG DBG_RenderUpdate( ); #endif // #ifdef DEBUG Fvector temp_vector; m_feel_deny.feel_touch_update (temp_vector, 0.f); if (GameID()!=eGameIDSingle) psDeviceFlags.set(rsDisableObjectsAsCrows,true); else psDeviceFlags.set(rsDisableObjectsAsCrows,false); // commit events from bullet manager from prev-frame Device.Statistic->TEST0.Begin (); BulletManager().CommitEvents (); Device.Statistic->TEST0.End (); // Client receive if (net_isDisconnected()) { if (OnClient() && GameID() != eGameIDSingle) { #ifdef DEBUG Msg("* I'm disconnected, so clear all objects..."); #endif // #ifdef DEBUG ClearAllObjects(); } Engine.Event.Defer ("kernel:disconnect"); return; } else { Device.Statistic->netClient1.Begin(); ClientReceive (); Device.Statistic->netClient1.End (); } ProcessGameEvents (); if (m_bNeed_CrPr) make_NetCorrectionPrediction(); if(!g_dedicated_server ) { if (g_mt_config.test(mtMap)) Device.seqParallel.push_back (fastdelegate::FastDelegate0<>(m_map_manager,&CMapManager::Update)); else MapManager().Update (); if( IsGameTypeSingle() && Device.dwPrecacheFrame==0 ) { if (g_mt_config.test(mtMap)) Device.seqParallel.push_back (fastdelegate::FastDelegate0<>(m_game_task_manager,&CGameTaskManager::UpdateTasks)); else GameTaskManager().UpdateTasks(); } } // Inherited update inherited::OnFrame (); // Draw client/server stats if ( !g_dedicated_server && psDeviceFlags.test(rsStatistic)) { CGameFont* F = HUD().Font().pFontDI; if (!psNET_direct_connect) { if ( IsServer() ) { const IServerStatistic* S = Server->GetStatistic(); F->SetHeightI (0.015f); F->OutSetI (0.0f,0.5f); F->SetColor (D3DCOLOR_XRGB(0,255,0)); F->OutNext ("IN: %4d/%4d (%2.1f%%)", S->bytes_in_real, S->bytes_in, 100.f*float(S->bytes_in_real)/float(S->bytes_in)); F->OutNext ("OUT: %4d/%4d (%2.1f%%)", S->bytes_out_real, S->bytes_out, 100.f*float(S->bytes_out_real)/float(S->bytes_out)); F->OutNext ("client_2_sever ping: %d", net_Statistic.getPing()); F->OutNext ("SPS/Sended : %4d/%4d", S->dwBytesPerSec, S->dwBytesSended); F->OutNext ("sv_urate/cl_urate : %4d/%4d", psNET_ServerUpdate, psNET_ClientUpdate); F->SetColor (D3DCOLOR_XRGB(255,255,255)); struct net_stats_functor { xrServer* m_server; CGameFont* F; void operator()(IClient* C) { m_server->UpdateClientStatistic(C); F->OutNext("%10s: P(%d), BPS(%2.1fK), MRR(%2d), MSR(%2d), Retried(%2d), Blocked(%2d)", //Server->game->get_option_s(*C->Name,"name",*C->Name), C->name.c_str(), C->stats.getPing(), float(C->stats.getBPS()),// /1024, C->stats.getMPS_Receive (), C->stats.getMPS_Send (), C->stats.getRetriedCount(), C->stats.dwTimesBlocked ); } }; net_stats_functor tmp_functor; tmp_functor.m_server = Server; tmp_functor.F = F; Server->ForEachClientDo(tmp_functor); } if (IsClient()) { IPureClient::UpdateStatistic(); F->SetHeightI(0.015f); F->OutSetI (0.0f,0.5f); F->SetColor (D3DCOLOR_XRGB(0,255,0)); F->OutNext ("client_2_sever ping: %d", net_Statistic.getPing()); F->OutNext ("sv_urate/cl_urate : %4d/%4d", psNET_ServerUpdate, psNET_ClientUpdate); F->SetColor (D3DCOLOR_XRGB(255,255,255)); F->OutNext("P(%d), BPS(%2.1fK), MRR(%2d), MSR(%2d), Retried(%2d), Blocked(%2d), Sended(%2d), SPS(%2d)", //Server->game->get_option_s(C->Name,"name",C->Name), // C->Name, net_Statistic.getPing(), float(net_Statistic.getBPS()),// /1024, net_Statistic.getMPS_Receive (), net_Statistic.getMPS_Send (), net_Statistic.getRetriedCount(), net_Statistic.dwTimesBlocked, net_Statistic.dwBytesSended, net_Statistic.dwBytesPerSec ); #ifdef DEBUG if (!pStatGraphR) { pStatGraphR = new CStatGraph(); pStatGraphR->SetRect(50, 700, 300, 68, 0xff000000, 0xff000000); //m_stat_graph->SetGrid(0, 0.0f, 10, 1.0f, 0xff808080, 0xffffffff); pStatGraphR->SetMinMax(0.0f, 65536.0f, 1000); pStatGraphR->SetStyle(CStatGraph::stBarLine); pStatGraphR->AppendSubGraph(CStatGraph::stBarLine); } pStatGraphR->AppendItem(float(net_Statistic.getBPS()), 0xff00ff00, 0); F->OutSet(20.f, 700.f); F->OutNext("64 KBS"); #endif } } } else { #ifdef DEBUG if (pStatGraphR) xr_delete(pStatGraphR); #endif } // g_pGamePersistent->Environment().SetGameTime (GetGameDayTimeSec(),GetGameTimeFactor()); g_pGamePersistent->Environment().SetGameTime (GetEnvironmentGameDayTimeSec(),game->GetEnvironmentGameTimeFactor()); //Device.Statistic->cripting.Begin (); if (!g_dedicated_server) ai().script_engine().script_process (ScriptEngine::eScriptProcessorLevel)->update(); //Device.Statistic->Scripting.End (); m_ph_commander->update (); m_ph_commander_scripts->update (); // autosave_manager().update (); //просчитать полет пуль Device.Statistic->TEST0.Begin (); BulletManager().CommitRenderSet (); Device.Statistic->TEST0.End (); // update static sounds if(!g_dedicated_server) { if (g_mt_config.test(mtLevelSounds)) Device.seqParallel.push_back (fastdelegate::FastDelegate0<>(m_level_sound_manager,&CLevelSoundManager::Update)); else m_level_sound_manager->Update (); } // deffer LUA-GC-STEP if (!g_dedicated_server) { if (g_mt_config.test(mtLUA_GC)) Device.seqParallel.push_back (fastdelegate::FastDelegate0<>(this,&CLevel::script_gc)); else script_gc () ; } //----------------------------------------------------- if (pStatGraphR) { static float fRPC_Mult = 10.0f; static float fRPS_Mult = 1.0f; pStatGraphR->AppendItem(float(m_dwRPC)*fRPC_Mult, 0xffff0000, 1); pStatGraphR->AppendItem(float(m_dwRPS)*fRPS_Mult, 0xff00ff00, 0); }; }
// Create the DX vertex/index buffers and D3D11_INPUT_ELEMENT_DESC //----------------------------------------------------------------------------- CPUTResult CPUTMeshDX11::CreateNativeResources( CPUTModel *pModel, UINT meshIdx, int vertexElementCount, CPUTBufferElementInfo *pVertexDataInfo, UINT vertexCount, void *pVertexData, CPUTBufferElementInfo *pIndexDataInfo, UINT indexCount, void *pIndexData ){ CPUTResult result = CPUT_SUCCESS; HRESULT hr; ID3D11Device *pD3dDevice = CPUT_DX11::GetDevice(); // Release the layout, offset, stride, and vertex buffer structure objects ClearAllObjects(); // allocate the layout, offset, stride, and vertex buffer structure objects mpLayoutDescription = new D3D11_INPUT_ELEMENT_DESC[vertexElementCount+1]; // Create the index buffer D3D11_SUBRESOURCE_DATA resourceData; if(NULL!=pIndexData) { mIndexCount = indexCount; // set the data format info ZeroMemory( &mIndexBufferDesc, sizeof(mIndexBufferDesc) ); mIndexBufferDesc.Usage = D3D11_USAGE_DEFAULT; mIndexBufferDesc.ByteWidth = mIndexCount * pIndexDataInfo->mElementSizeInBytes; mIndexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; mIndexBufferDesc.CPUAccessFlags = 0; // default to no cpu access for speed // create the buffer ZeroMemory( &resourceData, sizeof(resourceData) ); resourceData.pSysMem = pIndexData; hr = pD3dDevice->CreateBuffer( &mIndexBufferDesc, &resourceData, &mpIndexBuffer ); ASSERT(!FAILED(hr), _L("Failed creating index buffer") ); CPUTSetDebugName( mpIndexBuffer, _L("Index buffer") ); // set the DX index buffer format mIndexBufferFormat = ConvertToDirectXFormat(pIndexDataInfo->mElementType, pIndexDataInfo->mElementComponentCount); } // Create the vertex buffer mVertexCount = vertexCount; ZeroMemory( &mVertexBufferDesc, sizeof(mVertexBufferDesc) ); mVertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; mVertexStride = pVertexDataInfo[vertexElementCount-1].mOffset + pVertexDataInfo[vertexElementCount-1].mElementSizeInBytes; // size in bytes of a single vertex block mVertexBufferDesc.ByteWidth = mVertexCount * mVertexStride; // size in bytes of entire buffer mVertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; mVertexBufferDesc.CPUAccessFlags = 0; // default to no cpu access for speed ZeroMemory( &resourceData, sizeof(resourceData) ); resourceData.pSysMem = pVertexData; if (pVertexData) { hr = pD3dDevice->CreateBuffer( &mVertexBufferDesc, &resourceData, &mpVertexBuffer ); } else { hr = pD3dDevice->CreateBuffer( &mVertexBufferDesc, NULL, &mpVertexBuffer ); } ASSERT( !FAILED(hr), _L("Failed creating vertex buffer") ); CPUTSetDebugName( mpVertexBuffer, _L("Vertex buffer") ); // create the buffer for the shader resource view D3D11_BUFFER_DESC desc; ZeroMemory( &desc, sizeof(desc) ); desc.Usage = D3D11_USAGE_DEFAULT; desc.ByteWidth = mVertexCount * mVertexStride; // size in bytes of entire buffer desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; desc.CPUAccessFlags = 0; desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; desc.StructureByteStride = mVertexStride; if (pVertexData) { hr = pD3dDevice->CreateBuffer( &desc, &resourceData, &mpVertexBufferForSRVDX ); } else { hr = pD3dDevice->CreateBuffer( &desc, NULL, &mpVertexBufferForSRVDX ); } ASSERT( !FAILED(hr), _L("Failed creating vertex buffer for SRV") ); CPUTSetDebugName( mpVertexBuffer, _L("Vertex buffer for SRV") ); // Create the shader resource view D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; ZeroMemory( &srvDesc, sizeof(srvDesc) ); srvDesc.Format = DXGI_FORMAT_UNKNOWN; srvDesc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; srvDesc.Buffer.ElementOffset = 0; srvDesc.Buffer.NumElements = mVertexCount; hr = pD3dDevice->CreateShaderResourceView( mpVertexBufferForSRVDX, &srvDesc, &mpVertexView ); ASSERT( !FAILED(hr), _L("Failed creating vertex buffer SRV") ); cString name = _L("@VertexBuffer") + ptoc(pModel) + itoc(meshIdx); mpVertexBufferForSRV = new CPUTBufferDX11( name, mpVertexBufferForSRVDX, mpVertexView ); CPUTAssetLibrary::GetAssetLibrary()->AddBuffer( name, _L(""), _L(""), mpVertexBufferForSRV ); // build the layout object int currentByteOffset=0; mNumberOfInputLayoutElements = vertexElementCount; for(int ii=0; ii<vertexElementCount; ii++) { mpLayoutDescription[ii].SemanticName = pVertexDataInfo[ii].mpSemanticName; // string name that matches mpLayoutDescription[ii].SemanticIndex = pVertexDataInfo[ii].mSemanticIndex; // if we have more than one mpLayoutDescription[ii].Format = ConvertToDirectXFormat(pVertexDataInfo[ii].mElementType, pVertexDataInfo[ii].mElementComponentCount); mpLayoutDescription[ii].InputSlot = 0; // TODO: We support only a single stream now. Support multiple streams. mpLayoutDescription[ii].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; mpLayoutDescription[ii].InstanceDataStepRate = 0; mpLayoutDescription[ii].AlignedByteOffset = currentByteOffset; currentByteOffset += pVertexDataInfo[ii].mElementSizeInBytes; } // set the last 'dummy' element to null. Not sure if this is required, as we also pass in count when using this list. memset( &mpLayoutDescription[vertexElementCount], 0, sizeof(D3D11_INPUT_ELEMENT_DESC) ); return result; }
//----------------------------------------------------------------------------- CPUTMeshDX11::~CPUTMeshDX11() { ClearAllObjects(); }
void CollisionManager::Shutdown() { ClearAllObjects(); }
void CLevel::remove_objects () { if (!IsGameTypeSingle()) Msg("CLevel::remove_objects - Start"); BOOL b_stored = psDeviceFlags.test(rsDisableObjectsAsCrows); Game().reset_ui (); if (OnServer()) { VERIFY (Server); Server->SLS_Clear (); } snd_Events.clear (); for (int i=0; i<6; ++i) { psNET_Flags.set (NETFLAG_MINIMIZEUPDATES,FALSE); // ugly hack for checks that update is twice on frame // we need it since we do updates for checking network messages ++(Device.dwFrame); psDeviceFlags.set (rsDisableObjectsAsCrows,TRUE); ClientReceive (); ProcessGameEvents (); Objects.Update (true); Sleep (100); } if (OnClient()) ClearAllObjects (); BulletManager().Clear (); ph_commander().clear (); ph_commander_scripts().clear(); if(!g_dedicated_server) space_restriction_manager().clear (); psDeviceFlags.set (rsDisableObjectsAsCrows, b_stored); g_b_ClearGameCaptions = true; if (!g_dedicated_server) ai().script_engine().collect_all_garbage (); stalker_animation_data_storage().clear (); VERIFY (Render); Render->models_Clear (FALSE); Render->clear_static_wallmarks (); #ifdef DEBUG if(!g_dedicated_server) if (!client_spawn_manager().registry().empty()) client_spawn_manager().dump (); #endif // DEBUG if(!g_dedicated_server) { VERIFY (client_spawn_manager().registry().empty()); client_spawn_manager().clear (); } for (int i=0; i<6; i++) { ++(Device.dwFrame); Objects.Update(true); } g_pGamePersistent->destroy_particles (false); //. xr_delete (m_seniority_hierarchy_holder); //. m_seniority_hierarchy_holder = xr_new<CSeniorityHierarchyHolder>(); if (!IsGameTypeSingle()) Msg("CLevel::remove_objects - End"); }
CVisibleObjectsHelper::~CVisibleObjectsHelper() { ClearAllObjects(); }
void CVisibleObjectsHelper::Reset() { ClearAllObjects(); }
void CLevel::OnFrame () { #ifdef DEBUG_MEMORY_MANAGER debug_memory_guard __guard__; #endif // DEBUG_MEMORY_MANAGER m_feel_deny.update (); if (GameID()!=GAME_SINGLE) psDeviceFlags.set(rsDisableObjectsAsCrows,true); else psDeviceFlags.set(rsDisableObjectsAsCrows,false); // commit events from bullet manager from prev-frame Device.Statistic->TEST0.Begin (); BulletManager().CommitEvents (); Device.Statistic->TEST0.End (); // Client receive if (net_isDisconnected()) { if (OnClient() && GameID() != GAME_SINGLE) ClearAllObjects(); Engine.Event.Defer ("kernel:disconnect"); return; } else { Device.Statistic->netClient1.Begin(); ClientReceive (); Device.Statistic->netClient1.End (); } ProcessGameEvents (); if (m_bNeed_CrPr) make_NetCorrectionPrediction(); if(!g_dedicated_server) MapManager().Update (); // Inherited update inherited::OnFrame (); // Draw client/server stats if ( !g_dedicated_server && psDeviceFlags.test(rsStatistic)) { CGameFont* F = HUD().Font().pFontDI; if (!psNET_direct_connect) { if ( IsServer() ) { const IServerStatistic* S = Server->GetStatistic(); F->SetHeightI (0.015f); F->OutSetI (0.0f,0.5f); F->SetColor (D3DCOLOR_XRGB(0,255,0)); F->OutNext ("IN: %4d/%4d (%2.1f%%)", S->bytes_in_real, S->bytes_in, 100.f*float(S->bytes_in_real)/float(S->bytes_in)); F->OutNext ("OUT: %4d/%4d (%2.1f%%)", S->bytes_out_real, S->bytes_out, 100.f*float(S->bytes_out_real)/float(S->bytes_out)); F->OutNext ("client_2_sever ping: %d", net_Statistic.getPing()); F->OutNext ("SPS/Sended : %4d/%4d", S->dwBytesPerSec, S->dwBytesSended); F->OutNext ("sv_urate/cl_urate : %4d/%4d", psNET_ServerUpdate, psNET_ClientUpdate); F->SetColor (D3DCOLOR_XRGB(255,255,255)); for (u32 I=0; I<Server->client_Count(); ++I) { IClient* C = Server->client_Get(I); Server->UpdateClientStatistic(C); F->OutNext("P(%d), BPS(%2.1fK), MRR(%2d), MSR(%2d), Retried(%2d), Blocked(%2d)", //Server->game->get_option_s(*C->Name,"name",*C->Name), // C->Name, C->stats.getPing(), float(C->stats.getBPS()),// /1024, C->stats.getMPS_Receive (), C->stats.getMPS_Send (), C->stats.getRetriedCount(), C->stats.dwTimesBlocked ); } } if (IsClient()) { IPureClient::UpdateStatistic(); F->SetHeightI(0.015f); F->OutSetI (0.0f,0.5f); F->SetColor (D3DCOLOR_XRGB(0,255,0)); F->OutNext ("client_2_sever ping: %d", net_Statistic.getPing()); F->OutNext ("sv_urate/cl_urate : %4d/%4d", psNET_ServerUpdate, psNET_ClientUpdate); F->SetColor (D3DCOLOR_XRGB(255,255,255)); F->OutNext("P(%d), BPS(%2.1fK), MRR(%2d), MSR(%2d), Retried(%2d), Blocked(%2d), Sended(%2d), SPS(%2d)", //Server->game->get_option_s(C->Name,"name",C->Name), // C->Name, net_Statistic.getPing(), float(net_Statistic.getBPS()),// /1024, net_Statistic.getMPS_Receive (), net_Statistic.getMPS_Send (), net_Statistic.getRetriedCount(), net_Statistic.dwTimesBlocked, net_Statistic.dwBytesSended, net_Statistic.dwBytesPerSec ); } } } // g_pGamePersistent->Environment().SetGameTime (GetGameDayTimeSec(),GetGameTimeFactor()); g_pGamePersistent->Environment().SetGameTime (GetEnvironmentGameDayTimeSec(),GetGameTimeFactor()); //Device.Statistic->cripting.Begin (); if (!g_dedicated_server) ai().script_engine().script_process (ScriptEngine::eScriptProcessorLevel)->update(); //Device.Statistic->Scripting.End (); m_ph_commander->update (); m_ph_commander_scripts->update (); // autosave_manager().update (); //просчитать полет пуль Device.Statistic->TEST0.Begin (); BulletManager().CommitRenderSet (); Device.Statistic->TEST0.End (); // update static sounds if(!g_dedicated_server) { if (g_mt_config.test(mtLevelSounds)) Device.seqParallel.push_back (fastdelegate::FastDelegate0<>(m_level_sound_manager,&CLevelSoundManager::Update)); else m_level_sound_manager->Update (); } // deffer LUA-GC-STEP if (!g_dedicated_server) { if (g_mt_config.test(mtLUA_GC)) Device.seqParallel.push_back (fastdelegate::FastDelegate0<>(this,&CLevel::script_gc)); else script_gc () ; } //----------------------------------------------------- if (pStatGraphR) { static float fRPC_Mult = 10.0f; static float fRPS_Mult = 1.0f; pStatGraphR->AppendItem(float(m_dwRPC)*fRPC_Mult, 0xffff0000, 1); pStatGraphR->AppendItem(float(m_dwRPS)*fRPS_Mult, 0xff00ff00, 0); }; }