Skip to content

Commit 2fadf8c

Browse files
committed
lessgo i fixed pulses
1 parent f8417b7 commit 2fadf8c

File tree

5 files changed

+53
-71
lines changed

5 files changed

+53
-71
lines changed

GD/Application.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <ctime>
99
#include <thread>
1010

11-
#define MULTITHREADING 0
12-
1311
Application* Application::instance;
1412
const float Application::zoomModifier = 2.f;
1513

@@ -23,13 +21,11 @@ void Application::start()
2321
window = new sf::RenderWindow(sf::VideoMode(1280, 720), "GD", sf::Style::Default, settings);
2422
renderTexture.create(1920, 1080);
2523
framerate = 0;
26-
window->setVerticalSyncEnabled(false);
27-
window->setActive(!MULTITHREADING);
2824

2925
ImGui::SFML::Init(*window);
3026

3127
ImGui::GetIO().Fonts->Clear();
32-
ImGui::GetIO().Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\arial.ttf", 16);
28+
ImGui::GetIO().Fonts->AddFontFromFileTTF("arial.ttf", 16);
3329
ImGui::SFML::UpdateFontTexture();
3430

3531
ImGuiStyle& style = ImGui::GetStyle();
@@ -40,11 +36,6 @@ void Application::start()
4036
std::shared_ptr<SelectLevelLayer> layer = SelectLevelLayer::create();
4137
pushLayer(layer);
4238

43-
#if MULTITHREADING == 1
44-
sf::Thread thread(&Application::draw, this);
45-
thread.launch();
46-
#endif
47-
4839
auto next_frame = std::chrono::steady_clock::now();
4940

5041
while (window->isOpen())
@@ -54,9 +45,7 @@ void Application::start()
5445

5546
update();
5647

57-
#if MULTITHREADING == 0
5848
draw();
59-
#endif
6049

6150
//custom framerate lock because sfml one fucking sucks
6251
if (framerate > 0)
@@ -102,22 +91,6 @@ void Application::update()
10291

10392
void Application::draw()
10493
{
105-
#if MULTITHREADING == 1
106-
while (window->isOpen())
107-
{
108-
window->clear(sf::Color::Blue);
109-
renderTexture.clear();
110-
111-
renderTexture.display();
112-
sf::Sprite sprite(renderTexture.getTexture());
113-
sf::Vector2f scaleFactor = {1, 1};
114-
scaleFactor *= (float)window->getSize().x / (float)renderTexture.getSize().x;
115-
sprite.setScale(scaleFactor);
116-
window->draw(sprite);
117-
window->display();
118-
}
119-
#else
120-
12194
window->clear(sf::Color::Blue);
12295
renderTexture.clear();
12396

@@ -135,7 +108,6 @@ void Application::draw()
135108
ImGui::SFML::Render(*window);
136109

137110
window->display();
138-
#endif
139111
}
140112

141113
void Application::onQuit()

GD/EffectGameObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void EffectGameObject::pulseAction()
113113
sf::Color fromColor = pulseType == 0 ? gameLayer->colorChannels[targetGroupId]->getColor() : sf::Color::White;
114114
sf::Color originalColor = pulseType == 0 ? gameLayer->colorChannels[targetGroupId]->getNonPulseColor() : sf::Color::White;
115115

116-
std::shared_ptr<PulseAction> pulseAction = PulseAction::create(fadeIn, hold, fadeOut, targetGroupId, fromColor, triggerColor, originalColor, pulseType, mainOnly, detailOnly);
116+
std::shared_ptr<PulseAction> pulseAction = PulseAction::create(fadeIn, hold, fadeOut, targetGroupId, triggerColor, pulseType, mainOnly, detailOnly);
117117

118118
gameLayer->pulseActionsActive.push_back(pulseAction);
119119
this->triggerAction = pulseAction;

GD/GameLayer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ bool GameLayer::init(int levelID)
3737
font.loadFromFile("C:\\Windows\\Fonts\\arial.ttf");
3838
framerate.setFont(font);
3939
framerate.setCharacterSize(24);
40+
framerate.setColor(sf::Color::Green);
4041

4142
loadLevel(std::to_string(levelID));
4243

@@ -114,6 +115,7 @@ void GameLayer::update()
114115
if (canStart && audioEngine && !audioEngine->isPlaying)
115116
{
116117
audioEngine->setPosition(musicOffset);
118+
audioEngine->setVolume(0.3f);
117119
audioEngine->play();
118120
}
119121

GD/PulseAction.cpp

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,57 @@
11
#include "PulseAction.h"
22
#include "GameLayer.h"
33

4-
std::shared_ptr<PulseAction> PulseAction::create(float fadein, float hold, float fadeout, int target, sf::Color from, sf::Color to, sf::Color original, int pulsetype, bool mainOnly, bool detailOnly)
4+
std::shared_ptr<PulseAction> PulseAction::create(
5+
float fadein, float hold, float fadeout, int target, sf::Color to, int pulsetype, bool mainOnly, bool detailOnly)
56
{
67
std::shared_ptr<PulseAction> ptr(new PulseAction);
78

8-
if (ptr->init(fadein, hold, fadeout, target, from, to, original, pulsetype, mainOnly, detailOnly))
9+
if (ptr->init(fadein, hold, fadeout, target, to, pulsetype, mainOnly, detailOnly))
910
return ptr;
1011

1112
return nullptr;
1213
}
1314

14-
bool PulseAction::init(float fadein, float hold, float fadeout, int target, sf::Color from, sf::Color to, sf::Color original, int pulsetype, bool mainOnly, bool detailOnly)
15+
bool PulseAction::init(
16+
float fadein, float hold, float fadeout, int target, sf::Color to, int pulsetype, bool mainOnly, bool detailOnly)
1517
{
1618
this->duration = fadein + hold + fadeout;
1719
this->fadein = fadein / duration;
1820
this->hold = hold / duration;
1921
this->fadeout = fadeout / duration;
20-
this->from = from;
2122
this->to = to;
22-
this->original = original;
2323
this->target = target;
2424
this->pulsetype = pulsetype;
2525
this->mainOnly = mainOnly;
2626
this->detailOnly = detailOnly;
2727

28-
this->deltar = static_cast<float>(to.r - from.r);
29-
this->deltag = static_cast<float>(to.g - from.g);
30-
this->deltab = static_cast<float>(to.b - from.b);
31-
32-
this->deltar2 = static_cast<float>(original.r - to.r);
33-
this->deltag2 = static_cast<float>(original.g - to.g);
34-
this->deltab2 = static_cast<float>(original.b - to.b);
3528
return true;
3629
}
3730

3831
void PulseAction::applyToSpriteIn(Sprite* spr, float fadetime)
3932
{
40-
if (spr->channel == nullptr || spr->channelType == 1 && detailOnly || spr->channelType == 2 && mainOnly || spr->channelType == 0)
33+
if (spr->channel == nullptr || spr->channelType == 1 && detailOnly || spr->channelType == 2 && mainOnly ||
34+
spr->channelType == 0)
4135
return;
42-
auto channelcolor = spr->channel->getColor();
43-
auto r1 = static_cast<sf::Uint8>(to.r - (float)(to.r - channelcolor.r) * (1 - fadetime));
44-
auto g1 = static_cast<sf::Uint8>(to.g - (float)(to.g - channelcolor.g) * (1 - fadetime));
45-
auto b1 = static_cast<sf::Uint8>(to.b - (float)(to.b - channelcolor.b) * (1 - fadetime));
46-
spr->setColor({ r1, g1, b1 });
36+
37+
sf::Color channelcolor = spr->channel->getColor();
38+
sf::Uint8 r1 = static_cast<sf::Uint8>(to.r - (float)(to.r - channelcolor.r) * (1.f - fadetime));
39+
sf::Uint8 g1 = static_cast<sf::Uint8>(to.g - (float)(to.g - channelcolor.g) * (1.f - fadetime));
40+
sf::Uint8 b1 = static_cast<sf::Uint8>(to.b - (float)(to.b - channelcolor.b) * (1.f - fadetime));
41+
spr->setColor({r1, g1, b1});
4742
}
4843

4944
void PulseAction::applyToSpriteOut(Sprite* spr, float fadetime)
5045
{
51-
if (spr->channel == nullptr || spr->channelType == 1 && detailOnly || spr->channelType == 2 && mainOnly || spr->channelType == 0)
46+
if (spr->channel == nullptr || spr->channelType == 1 && detailOnly || spr->channelType == 2 && mainOnly ||
47+
spr->channelType == 0)
5248
return;
53-
auto channelcolor = spr->channel->getColor();
54-
auto r1 = static_cast<sf::Uint8>(to.r - (float)(to.r - channelcolor.r) * (fadetime));
55-
auto g1 = static_cast<sf::Uint8>(to.g - (float)(to.g - channelcolor.g) * (fadetime));
56-
auto b1 = static_cast<sf::Uint8>(to.b - (float)(to.b - channelcolor.b) * (fadetime));
57-
spr->setColor({ r1, g1, b1 });
49+
50+
sf::Color channelcolor = spr->channel->getColor();
51+
sf::Uint8 r1 = static_cast<sf::Uint8>(to.r - (float)(to.r - channelcolor.r) * (fadetime));
52+
sf::Uint8 g1 = static_cast<sf::Uint8>(to.g - (float)(to.g - channelcolor.g) * (fadetime));
53+
sf::Uint8 b1 = static_cast<sf::Uint8>(to.b - (float)(to.b - channelcolor.b) * (fadetime));
54+
spr->setColor({r1, g1, b1});
5855
}
5956

6057
void PulseAction::update(float time)
@@ -67,10 +64,13 @@ void PulseAction::update(float time)
6764
if (fadein == 0)
6865
fadetime = 1.f;
6966
std::shared_ptr<ColorChannel> channel = GameLayer::instance->colorChannels[target];
70-
sf::Uint8 r = static_cast<sf::Uint8>(to.r - deltar * (1 - fadetime));
71-
sf::Uint8 g = static_cast<sf::Uint8>(to.g - deltag * (1 - fadetime));
72-
sf::Uint8 b = static_cast<sf::Uint8>(to.b - deltab * (1 - fadetime));
73-
channel->setColor({ r, g, b, channel->getColor().a }, true);
67+
sf::Color channelcolor = channel->getNonPulseColor();
68+
69+
sf::Uint8 r = static_cast<sf::Uint8>(to.r - (float)(to.r - channelcolor.r) * (1.f - fadetime));
70+
sf::Uint8 g = static_cast<sf::Uint8>(to.g - (float)(to.g - channelcolor.g) * (1.f - fadetime));
71+
sf::Uint8 b = static_cast<sf::Uint8>(to.b - (float)(to.b - channelcolor.b) * (1.f - fadetime));
72+
73+
channel->setColor({r, g, b, channel->getColor().a}, true);
7474
channel->setDirtyRecusively();
7575
}
7676
else if (time >= fadein + hold)
@@ -80,10 +80,20 @@ void PulseAction::update(float time)
8080
fadetime = 1.f;
8181

8282
std::shared_ptr<ColorChannel> channel = GameLayer::instance->colorChannels[target];
83-
sf::Uint8 r = static_cast<sf::Uint8>(original.r - deltar2 * (1 - fadetime));
84-
sf::Uint8 g = static_cast<sf::Uint8>(original.g - deltag2 * (1 - fadetime));
85-
sf::Uint8 b = static_cast<sf::Uint8>(original.b - deltab2 * (1 - fadetime));
86-
channel->setColor({ r, g, b, channel->getColor().a}, true);
83+
sf::Color channelcolor = channel->getNonPulseColor();
84+
85+
sf::Uint8 r = static_cast<sf::Uint8>(to.r - (float)(to.r - channelcolor.r) * (fadetime));
86+
sf::Uint8 g = static_cast<sf::Uint8>(to.g - (float)(to.g - channelcolor.g) * (fadetime));
87+
sf::Uint8 b = static_cast<sf::Uint8>(to.b - (float)(to.b - channelcolor.b) * (fadetime));
88+
89+
channel->setColor({r, g, b, channel->getColor().a}, true);
90+
channel->setDirtyRecusively();
91+
}
92+
else
93+
{
94+
std::shared_ptr<ColorChannel> channel = GameLayer::instance->colorChannels[target];
95+
96+
channel->setColor({to.r, to.g, to.b, channel->getColor().a}, true);
8797
channel->setDirtyRecusively();
8898
}
8999
}
@@ -98,7 +108,7 @@ void PulseAction::update(float time)
98108

99109
for (int i = GameLayer::instance->prevSection; i < GameLayer::instance->nextSection + 1; i++)
100110
{
101-
for (auto&pair : group->objectsInSections[i])
111+
for (auto& pair : group->objectsInSections[i])
102112
{
103113
GameObject* obj = pair.second;
104114
applyToSpriteIn(obj, fadetime);
@@ -115,7 +125,7 @@ void PulseAction::update(float time)
115125
std::shared_ptr<Group> group = GameLayer::instance->groups[target];
116126
for (int i = GameLayer::instance->prevSection; i < GameLayer::instance->nextSection + 1; i++)
117127
{
118-
for (auto&pair : group->objectsInSections[i])
128+
for (auto& pair : group->objectsInSections[i])
119129
{
120130
GameObject* obj = pair.second;
121131
applyToSpriteOut(obj, fadetime);
@@ -129,7 +139,7 @@ void PulseAction::update(float time)
129139
std::shared_ptr<Group> group = GameLayer::instance->groups[target];
130140
for (int i = GameLayer::instance->prevSection; i < GameLayer::instance->nextSection + 1; i++)
131141
{
132-
for (auto&pair : group->objectsInSections[i])
142+
for (auto& pair : group->objectsInSections[i])
133143
{
134144
GameObject* obj = pair.second;
135145
applyToSpriteIn(obj, fadein + hold);

GD/PulseAction.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ class PulseAction : public ActionInterval
99
private:
1010
int target, pulsetype = 0;
1111

12-
sf::Color from, to, original;
13-
14-
float deltar, deltag, deltab;
15-
float deltar2, deltag2, deltab2;
12+
sf::Color to;
13+
1614
float fadein, hold, fadeout;
1715

1816
bool mainOnly, detailOnly;
1917
public:
20-
static std::shared_ptr<PulseAction> create(float fadein, float hold, float fadeout, int target, sf::Color from, sf::Color to, sf::Color original, int pulsetype, bool mainOnly, bool detailOnly);
21-
bool init(float fadein, float hold, float fadeout, int target, sf::Color from, sf::Color to, sf::Color original, int pulsetype, bool mainOnly, bool detailOnly);
18+
static std::shared_ptr<PulseAction> create(float fadein, float hold, float fadeout, int target, sf::Color to, int pulsetype, bool mainOnly, bool detailOnly);
19+
bool init(float fadein, float hold, float fadeout, int target, sf::Color to, int pulsetype, bool mainOnly, bool detailOnly);
2220

2321
void applyToSpriteIn(Sprite* spr, float fadetime);
2422
void applyToSpriteOut(Sprite* spr, float fadetime);

0 commit comments

Comments
 (0)