MCPcopy Create free account
hub / github.com/REGoth-project/REGoth / setVisual

Method setVisual

src/components/Vob.cpp:93–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91}
92
93void ::Vob::setVisual(VobInformation& vob, const std::string& _visual)
94{
95 std::string visual = _visual;
96 std::transform(visual.begin(), visual.end(), visual.begin(), ::toupper);
97
98 // Don't set twice
99 if (vob.visual && vob.visual->getName() == visual)
100 return;
101
102 Logic::VisualController** ppVisual = &vob.world->getComponentAllocator().getElement<Components::VisualComponent>(vob.entity).m_pVisualController;
103
104 // Clear old visual
105 delete *ppVisual;
106
107 *ppVisual = nullptr;
108 vob.visual = nullptr;
109
110 // Check type of visual
111 if (visual.find(".3DS") != std::string::npos || visual.find(".MMB") != std::string::npos || visual.find(".MMS") != std::string::npos || visual.find(".MDMS") != std::string::npos)
112 {
113 Logic::VisualController* ld = new Logic::StaticMeshVisual(*vob.world, vob.entity);
114 if (ld->load(visual))
115 (*ppVisual) = ld;
116 else
117 delete ld;
118 }
119 else if (visual.find(".MDM") != std::string::npos || visual.find(".MDL") != std::string::npos || visual.find(".MDS") != std::string::npos || visual.find(".ASC") != std::string::npos)
120 {
121 Logic::VisualController* ld = new Logic::ModelVisual(*vob.world, vob.entity);
122 if (ld->load(visual))
123 {
124 (*ppVisual) = ld;
125 }
126 else
127 delete ld;
128 }
129 else if (visual.find(".PFX") != std::string::npos)
130 {
131 Logic::VisualController* ld = new Logic::PfxVisual(*vob.world, vob.entity);
132 if (ld->load(visual))
133 {
134 (*ppVisual) = ld;
135 }
136 else
137 delete ld;
138 }
139
140 // Notify the logic controller
141 if (vob.visual != (*ppVisual))
142 {
143 if (vob.logic)
144 vob.logic->onVisualChanged();
145 }
146
147 vob.visual = (*ppVisual);
148}
149
150void ::Vob::setName(VobInformation& vob, const std::string& name)

Callers

nothing calls this directly

Calls 6

getNameMethod · 0.80
findMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
loadMethod · 0.45
onVisualChangedMethod · 0.45

Tested by

no test coverage detected