Skip to content

Commit f2b2503

Browse files
committed
BLUGA: Fix compile
1 parent 0a2bd1c commit f2b2503

File tree

2 files changed

+18
-36
lines changed

2 files changed

+18
-36
lines changed

libs/B-luga-physics/include/B-luga-physics/ECSCustomTypes.hpp

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ namespace Types {
2828
struct CollisionRect {
2929
int width;
3030
int height;
31+
int offsetX;
32+
int offsetY;
3133

32-
NLOHMANN_DEFINE_TYPE_INTRUSIVE(CollisionRect, width, height);
34+
NLOHMANN_DEFINE_TYPE_INTRUSIVE(CollisionRect, width, height, offsetX, offsetY);
3335
};
3436

3537
struct Position {
@@ -121,23 +123,6 @@ namespace Types {
121123
initBounce(jsonObject, originPos);
122124
}
123125
}
124-
void addPhysic(std::string type)
125-
{
126-
auto it = physicsTypeMap.find(type);
127-
if (it == physicsTypeMap.end()) {
128-
Logger::error("Physics type not found");
129-
return;
130-
}
131-
addPhysic(it->second);
132-
}
133-
std::optional<std::size_t> getClock(PhysicsType type) const
134-
{
135-
if (_physicsMap.find(type) == _physicsMap.end()) {
136-
Logger::error("Physics not found");
137-
throw std::runtime_error("Get clock: Physics of type " + std::to_string(type) + " not found");
138-
}
139-
return _physicsMap.at(type);
140-
}
141126
std::vector<PhysicsType> getPhysics() const
142127
{
143128
std::vector<PhysicsType> physics;
@@ -167,15 +152,6 @@ namespace Types {
167152
{
168153
_physicsMap.clear();
169154
}
170-
std::size_t getClockId(PhysicsType type) const
171-
{
172-
auto it = _physicsMap.find(type);
173-
if (it == _physicsMap.end()) {
174-
Logger::error("Get clock id: Physics not found");
175-
throw std::runtime_error("Physics of type " + std::to_string(type) + " not found in getClockId");
176-
}
177-
return it->second.value();
178-
}
179155
private:
180156
void initBounce(nlohmann::json & /*unused*/, const Types::Position &originPos)
181157
{

libs/B-luga-physics/include/B-luga-physics/ECSSystems.hpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,21 +278,27 @@ namespace Systems {
278278
Registry::getInstance().getComponents<Types::Position>();
279279

280280
for (std::size_t id : ids) {
281-
std::size_t clockId = physicComps[id].getClockId(Types::PhysicsType::ZIGZAG);
281+
const Types::Zigzag &zigzagData = physicComps[id].getPhysicData<Types::Zigzag>(Types::ZIGZAG);
282282
std::size_t elapsedTimeInMs =
283-
Registry::getInstance().getClock().elapsedMillisecondsSince(clockId);
283+
Registry::getInstance().getClock().elapsedMillisecondsSince(zigzagData.clockId);
284284
if (elapsedTimeInMs == static_cast<std::size_t>(-1)) {
285-
Registry::getInstance().getClock().restart(clockId);
285+
Registry::getInstance().getClock().restart(zigzagData.clockId);
286286
elapsedTimeInMs = 0;
287287
}
288-
// Height of the wave = 10% of the screen
289-
float amplitude = 10.0F;
290-
// Time for the complete zigzag cycle 400ms
291-
float period = 400.0F;
288+
int maxY = Maths::floatToIntConservingDecimals(zigzagData.maxScreenY);
289+
int minY = Maths::floatToIntConservingDecimals(zigzagData.minScreenY);
290+
// Height of the wave = ?% of the screen
291+
float amplitude = zigzagData.amplitude / 2;
292+
// Time for the complete zigzag cycle
293+
float period = zigzagData.period;
292294
float WavePosY =
293295
amplitude * std::sin(2.0F * static_cast<float>(M_PI) * elapsedTimeInMs / period);
294-
positionComp[id].y =
295-
physicComps[id].getOriginPos().y + Maths::floatToIntConservingDecimals(WavePosY);
296+
positionComp[id].y = zigzagData.originPos.y + Maths::floatToIntConservingDecimals(WavePosY);
297+
if (positionComp[id].y < minY) {
298+
positionComp[id].y = minY;
299+
} else if (positionComp[id].y > maxY) {
300+
positionComp[id].y = maxY;
301+
}
296302
velocities[id].speedY = 0;
297303
}
298304
}

0 commit comments

Comments
 (0)