Skip to content

Commit 72c728f

Browse files
committed
optimizing and fixing
1 parent 9f64fed commit 72c728f

File tree

9 files changed

+67
-41
lines changed

9 files changed

+67
-41
lines changed

src/EffectGameObject.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "EffectGameObject.h"
2-
#include "GameLayer.h"
32
#include "ActionEasing.h"
3+
#include "GameLayer.h"
44

5-
#define gameLayer GameLayer::instance //lol
5+
#define gameLayer GameLayer::instance // lol
66

77
void EffectGameObject::triggerActivated()
88
{
@@ -134,8 +134,30 @@ void EffectGameObject::moveAction()
134134

135135
void EffectGameObject::toggleAction()
136136
{
137+
gameLayer->groups[targetGroupId]->enabled = activateGroup;
138+
137139
for (GameObject* obj : gameLayer->groups[targetGroupId]->objects)
138140
{
141+
bool disabled = false;
142+
143+
if (activateGroup)
144+
{
145+
for (int group : obj->groups)
146+
{
147+
if (group == targetGroupId)
148+
continue;
149+
150+
if (!gameLayer->groups[group]->enabled)
151+
{
152+
disabled = true;
153+
break;
154+
}
155+
}
156+
}
157+
158+
if (disabled)
159+
continue;
160+
139161
obj->enabled = activateGroup;
140162

141163
if (!activateGroup && obj->currentBatcher)
@@ -191,11 +213,12 @@ void EffectGameObject::stopAction()
191213

192214
void EffectGameObject::followAction()
193215
{
194-
std::shared_ptr<FollowAction> followAction = FollowAction::create(duration, targetGroupId, secondaryTargetGroupId, xMod, yMod);
216+
std::shared_ptr<FollowAction> followAction =
217+
FollowAction::create(duration, targetGroupId, secondaryTargetGroupId, xMod, yMod);
195218

196-
if(!followAction)
219+
if (!followAction)
197220
return;
198-
221+
199222
gameLayer->followActionsActive.push_back(followAction);
200223

201224
this->triggerAction = followAction;

src/GameLayer.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "PlatformUtils.h"
88
#include "SelectLevelLayer.h"
99

10+
#include <algorithm>
11+
#include <execution>
1012
#include <cpr/cpr.h>
1113
#include <deque>
1214
#include <imgui.h>
@@ -144,16 +146,16 @@ void GameLayer::update()
144146
if (canStart && audioEngine && !audioEngine->isPlaying)
145147
{
146148
audioEngine->setPosition(musicOffset);
147-
audioEngine->setVolume(0.55f);
149+
audioEngine->setVolume(0.15f);
148150
audioEngine->play();
149151
}
150152

151153
if (audioEngine)
152154
audioEngine->update();
153-
155+
154156
frameTimer -= Application::instance->deltaTime;
155157

156-
if(frameTimer <= 0)
158+
if (frameTimer <= 0)
157159
{
158160
frameTimer = 0.25f;
159161
framerate = (int)ImGui::GetIO().Framerate;
@@ -209,13 +211,15 @@ void GameLayer::draw()
209211

210212
void GameLayer::GUI()
211213
{
212-
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
213-
ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background
214-
if (ImGui::Begin("Example: Simple overlay", (bool*)0, window_flags))
215-
{
216-
ImGui::Text(std::to_string(framerate).c_str());
217-
}
218-
ImGui::End();
214+
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoDocking |
215+
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings |
216+
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
217+
ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background
218+
if (ImGui::Begin("Example: Simple overlay", (bool*)0, window_flags))
219+
{
220+
ImGui::Text(std::to_string(framerate).c_str());
221+
}
222+
ImGui::End();
219223

220224
/* ImGui::Begin("Proprieties");
221225
@@ -833,7 +837,7 @@ void GameLayer::fillColorChannel(std::span<std::string_view> colorString, int id
833837

834838
void GameLayer::updateTriggers()
835839
{
836-
float camPos = camera.cameraPos.x - 50.f;
840+
float camPos = camera.cameraPos.x;
837841

838842
int curSection = Common::sectionForPos(camPos);
839843

@@ -842,6 +846,7 @@ void GameLayer::updateTriggers()
842846
if (i < sectionObjects.size() && i >= 0)
843847
{
844848
auto& section = sectionObjects[i];
849+
845850
for (auto& pair : section)
846851
{
847852
GameObject* obj = pair.second;

src/GameObject.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,9 @@ void GameObject::tryUpdateSection()
405405
thisSectionMap.erase(this->uniqueID);
406406

407407
int sectionSize = GameLayer::instance->sectionObjects.size();
408-
while (section >= sectionSize)
409-
{
410-
std::unordered_map<int, GameObject*> map;
411-
GameLayer::instance->sectionObjects.push_back(map);
412-
sectionSize++;
413-
}
408+
if(section >= sectionSize)
409+
GameLayer::instance->sectionObjects.resize(section + 1);
410+
414411
GameLayer::instance->sectionObjects[section].insert({this->uniqueID, this});
415412

416413
this->section = section;
@@ -422,11 +419,6 @@ void GameObject::tryUpdateSection()
422419

423420
groupMap->erase(uniqueID);
424421

425-
if (!group->objectsInSections.contains(section))
426-
{
427-
std::unordered_map<int, GameObject*> map;
428-
group->objectsInSections.insert({section, map});
429-
}
430422
group->objectsInSections[section].insert({static_cast<int>(uniqueID), this});
431423
}
432424

src/Group.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class Group
2121
std::vector<EffectGameObject*> spawnTriggered;
2222

2323
std::shared_ptr <ActionInterval> rotateAction = nullptr;
24+
25+
bool enabled = true;
2426
public:
2527
static std::shared_ptr<Group> create();
2628
};

src/HSV.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ glm::vec4 HSV::toRGB()
6969
case 5:
7070
return { v * 255.0f, p * 255.0f, q * 255.0f, 255.f };
7171
default:
72-
break;
72+
return {0, 255, 0, 0};
7373
}
7474
}
7575

src/PulseAction.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ void PulseAction::applyToSpriteIn(Sprite* spr, float fadetime)
6262
float r1 = static_cast<float>(to.r - (float)(to.r - channelcolor.r) * (1.f - fadetime));
6363
float g1 = static_cast<float>(to.g - (float)(to.g - channelcolor.g) * (1.f - fadetime));
6464
float b1 = static_cast<float>(to.b - (float)(to.b - channelcolor.b) * (1.f - fadetime));
65-
if (spr->getColor() != to)
66-
spr->setColor({r1, g1, b1, 255.f});
65+
66+
glm::vec4 col = {r1, g1, b1, 255.f};
67+
68+
if (spr->getColor() != col)
69+
spr->setColor(col);
6770
}
6871

6972
void PulseAction::applyToSpriteOut(Sprite* spr, float fadetime)
@@ -79,8 +82,11 @@ void PulseAction::applyToSpriteOut(Sprite* spr, float fadetime)
7982
float r1 = static_cast<float>(to.r - (float)(to.r - channelcolor.r) * (fadetime));
8083
float g1 = static_cast<float>(to.g - (float)(to.g - channelcolor.g) * (fadetime));
8184
float b1 = static_cast<float>(to.b - (float)(to.b - channelcolor.b) * (fadetime));
82-
if (spr->getColor() != to)
83-
spr->setColor({r1, g1, b1, 255.f});
85+
86+
glm::vec4 col = {r1, g1, b1, 255.f};
87+
88+
if (spr->getColor() != col)
89+
spr->setColor(col);
8490
}
8591

8692
void PulseAction::update(float time)
@@ -141,6 +147,7 @@ void PulseAction::update(float time)
141147
else
142148
GameLayer::instance->pulsedGroups.insert(target);
143149

150+
//fade in
144151
if (time <= fadein)
145152
{
146153
float fadetime = time / fadein;
@@ -161,7 +168,7 @@ void PulseAction::update(float time)
161168
applyToSpriteIn(spr.get(), fadetime);
162169
}
163170
}
164-
}
171+
} //fade out
165172
else if (time >= fadein + hold)
166173
{
167174
float fadetime = (time - hold - fadein) / fadeout;
@@ -181,7 +188,7 @@ void PulseAction::update(float time)
181188
applyToSpriteOut(spr.get(), fadetime);
182189
}
183190
}
184-
}
191+
} //hold
185192
else
186193
{
187194
std::shared_ptr<Group> group = GameLayer::instance->groups[target];

src/RotateAction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ void RotateAction::update(float time)
5555

5656
rotateLast = rotateAmount;
5757

58+
if(deltaRotation == 0)
59+
return;
60+
5861
glm::mat4 transform(1.0f);
5962

6063
if(rotateAround)

src/Sprite.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
void Sprite::updateVerticesPosition(bool send)
1212
{
1313
if (currentBatcher == nullptr)
14-
{
15-
// std::cout << "No batcher!";
1614
return;
17-
}
1815

1916
if (isDirty())
2017
updateTransform();
@@ -50,10 +47,7 @@ void Sprite::updateVerticesPosition(bool send)
5047
void Sprite::sendVertices()
5148
{
5249
if (currentBatcher == nullptr)
53-
{
54-
// std::cout << "No batcher!";
5550
return;
56-
}
5751

5852
for (int i = 0; i < 4; ++i)
5953
sendVertex(i);

src/Sprite.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Batcher;
1818
class Sprite : public Transformable
1919
{
2020
private:
21-
glm::vec4 hsvAppliedColor;
21+
glm::vec4 hsvAppliedColor = {0, 0, 255, 255};
2222
public:
2323
Vertex vertices[4];
2424
glm::vec2 originalPositions[4];

0 commit comments

Comments
 (0)