42 #include "imgui_internal.h"
49 void GfxScene::CreateDustPools()
52 m_dustpools[
"dust"] =
new DustPool(m_scene_manager,
"tracks/Dust", 20);
53 m_dustpools[
"clump"] =
new DustPool(m_scene_manager,
"tracks/Clump", 20);
54 m_dustpools[
"sparks"] =
new DustPool(m_scene_manager,
"tracks/Sparks", 10);
55 m_dustpools[
"drip"] =
new DustPool(m_scene_manager,
"tracks/Drip", 50);
56 m_dustpools[
"splash"] =
new DustPool(m_scene_manager,
"tracks/Splash", 20);
57 m_dustpools[
"ripple"] =
new DustPool(m_scene_manager,
"tracks/Ripple", 20);
60 void GfxScene::ClearScene()
63 for (
auto itor : m_dustpools)
65 itor.second->Discard(m_scene_manager);
71 m_all_gfx_actors.clear();
72 m_all_gfx_characters.clear();
75 m_scene_manager->clearScene();
87 m_skidmark_conf.LoadDefaultSkidmarkDefs();
90 void GfxScene::UpdateScene(
float dt_sec)
93 for (
GfxActor* gfx_actor: m_live_gfx_actors)
95 gfx_actor->UpdateFlexbodies();
96 gfx_actor->UpdateWheelVisuals();
100 GfxActor* player_gfx_actor =
nullptr;
101 if (m_simbuf.simbuf_player_actor !=
nullptr)
103 player_gfx_actor = m_simbuf.simbuf_player_actor->GetGfxActor();
107 if (m_simbuf.simbuf_camera_behavior != CameraManager::CAMERA_BEHAVIOR_STATIC)
109 float fov = (m_simbuf.simbuf_camera_behavior == CameraManager::CAMERA_BEHAVIOR_VEHICLE_CINECAM)
117 for (
GfxActor* gfx_actor: m_all_gfx_actors)
119 if (!m_simbuf.simbuf_sim_paused && !gfx_actor->GetSimDataBuffer().simbuf_physics_paused)
121 gfx_actor->UpdateParticles(m_simbuf.simbuf_sim_speed * dt_sec);
124 for (
auto itor : m_dustpools)
126 itor.second->update();
132 if (player_gfx_actor !=
nullptr)
148 if (player_gfx_actor !=
nullptr)
164 sky->DetectSkyUpdate();
169 if (skyx_man !=
nullptr)
175 if (m_simbuf.simbuf_race_in_progress != m_simbuf.simbuf_race_in_progress_prev)
177 if (m_simbuf.simbuf_race_in_progress)
186 if (m_simbuf.simbuf_race_in_progress)
192 if (m_simbuf.simbuf_player_actor)
198 for (
GfxActor* gfx_actor: m_all_gfx_actors)
200 gfx_actor->UpdateNetLabels(m_simbuf.simbuf_sim_speed * dt_sec);
206 a->UpdateCharacterInScene();
210 for (
GfxActor* gfx_actor: m_all_gfx_actors)
212 if (gfx_actor->IsActorLive())
214 gfx_actor->UpdateRods();
215 gfx_actor->UpdateCabMesh();
216 gfx_actor->UpdateWingMeshes();
217 gfx_actor->UpdateAirbrakes();
218 gfx_actor->UpdateCParticles();
219 gfx_actor->UpdateAeroEngines();
220 gfx_actor->UpdatePropAnimations(dt_sec);
221 gfx_actor->UpdateRenderdashRTT();
224 gfx_actor->UpdateProps(dt_sec, (gfx_actor == player_gfx_actor));
226 gfx_actor->UpdateFlares(dt_sec, (gfx_actor == player_gfx_actor));
228 if (player_gfx_actor !=
nullptr)
233 if (m_simbuf.simbuf_player_actor->ar_driveable ==
TRUCK && m_simbuf.simbuf_player_actor->ar_engine !=
nullptr)
237 else if (m_simbuf.simbuf_player_actor->ar_driveable ==
AIRPLANE)
248 for (
GfxActor* gfx_actor: m_live_gfx_actors)
250 gfx_actor->FinishWheelUpdates();
251 gfx_actor->FinishFlexbodyTasks();
255 void GfxScene::SetParticlesVisible(
bool visible)
257 for (
auto itor : m_dustpools)
259 itor.second->setVisible(visible);
265 auto found = m_dustpools.find(name);
266 if (found != m_dustpools.end())
268 return found->second;
278 m_all_gfx_actors.push_back(gfx_actor);
281 void GfxScene::BufferSimulationData()
293 m_simbuf.simbuf_race_in_progress_prev = m_simbuf.simbuf_race_in_progress;
299 m_live_gfx_actors.clear();
302 if (a->IsActorLive() || !a->IsActorInitialized())
304 a->UpdateSimDataBuffer();
305 m_live_gfx_actors.push_back(a);
306 a->InitializeActor();
312 a->BufferSimulationData();
318 auto itor = std::remove(m_all_gfx_actors.begin(), m_all_gfx_actors.end(), remove_me);
319 if (itor != m_all_gfx_actors.end())
321 m_all_gfx_actors.erase(itor, m_all_gfx_actors.end());
327 m_all_gfx_characters.push_back(gfx_character);
332 auto itor = std::remove(m_all_gfx_characters.begin(), m_all_gfx_characters.end(), remove_me);
333 if (itor != m_all_gfx_characters.end())
335 m_all_gfx_characters.erase(itor, m_all_gfx_characters.end());
339 void GfxScene::DrawNetLabel(Ogre::Vector3 scene_pos,
float cam_dist, std::string
const& nick,
int colornum)
344 float font_size = std::max(0.6, cam_dist / 40.0);
349 nick +
" (" +
TOSTRING((
float)(ceil(cam_dist / 100) / 10.0) ) +
" km)";
351 else if (cam_dist > 20)
354 nick +
" (" +
TOSTRING((
int)cam_dist) +
" m)";
363 ImVec2 screen_size = ImGui::GetIO().DisplaySize;
367 Ogre::Vector3 pos_xyz = world2screen.
Convert(scene_pos);
373 ImVec2 pos((
int)pos_xyz.x+0.5, (
int)pos_xyz.y+0.5);
375 ImVec2 text_size = ImGui::CalcTextSize(caption.c_str());
379 ImGuiContext* g = ImGui::GetCurrentContext();
381 ImVec2 text_pos(pos.x - ((text_size.x / 2)), pos.y - ((text_size.y / 2)));
384 const float PADDING = 4.f;
385 drawlist->AddRectFilled(
386 text_pos - ImVec2(PADDING, PADDING),
387 text_pos + text_size + ImVec2(PADDING, PADDING),
389 ImGui::GetStyle().WindowRounding);
393 ImVec4 text_color(color.r, color.g, color.b, 1.f);
394 drawlist->AddText(g->Font, g->FontSize, text_pos, ImColor(text_color), caption.c_str());
397 #endif // USE_SOCKETW