aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.cpp71
-rw-r--r--src/components.cpp62
-rw-r--r--src/world.cpp6
3 files changed, 92 insertions, 47 deletions
diff --git a/src/common.cpp b/src/common.cpp
index 6539a05..2ec80a7 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -18,8 +18,10 @@
#endif // __WIN32__
unsigned int millis(void) {
- std::chrono::system_clock::time_point now=std::chrono::system_clock::now();
- return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count();
+ using namespace std::chrono;
+
+ auto now = system_clock::now();
+ return duration_cast<milliseconds>(now.time_since_epoch()).count();
}
@@ -37,7 +39,7 @@ std::vector<std::string> StringTokenizer(const std::string& str, char delim)
std::string token;
while (getline(is, token, delim))
- tokens.push_back(token);
+ tokens.emplace_back(token);
return tokens;
}
@@ -51,56 +53,41 @@ void DEBUG_prints(const char* file, int line, const char *s,...)
va_end(args);
}
-int getdir(std::string dir, std::vector<std::string> &files)
+int getdir(std::string dir, std::list<std::string>& files)
{
#ifndef __WIN32__
- DIR *dp;
- struct dirent *dirp;
- if (!(dp = opendir(dir.c_str()))) {
- std::cout <<"Error ("<<errno<<") opening "<<dir<<std::endl;
- return errno;
- }
- while((dirp = readdir(dp)))
- files.push_back(std::string(dirp->d_name));
- closedir(dp);
-#else
- HANDLE dirh;
- WIN32_FIND_DATA file_data;
+ auto dp = opendir(dir.c_str());
+ if (dp == nullptr)
+ UserError("Couldn\'t open folder: " + dir);
- if ((dirh = FindFirstFile((dir + "/*").c_str(), &file_data)) == INVALID_HANDLE_VALUE)
- return -1; /* No files found */
+ auto dirp = readdir(dp);
+ while (dirp != nullptr) {
+ files.emplace_back(dirp->d_name);
+ dirp = readdir(dp);
+ }
- do {
- const std::string file_name = file_data.cFileName;
- const std::string full_file_name = dir + file_name;
- const bool is_directory = (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
+ closedir(dp);
+#else
+ WIN32_FIND_DATA fileData;
+ auto dirh = FindFirstFile((dir + "/*").c_str(), &fileData);
+ if (dirh == INVALID_HANDLE_VALUE)
+ UserError("Couldn\'t open folder: " + dir);
- if (file_name[0] == '.')
- continue;
+ do {
+ auto fileName = fileData.cFileName;
- if (is_directory)
- continue;
+ if (fileName[0] == '.')
+ continue;
- files.push_back(file_name);
- } while (FindNextFile(dirh, &file_data));
+ if (!(fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
+ files.emplace_back(fileName);
+ } while (FindNextFile(dirh, &fileData));
FindClose(dirh);
#endif // __WIN32__
- return 0;
-}
-void strVectorSortAlpha(std::vector<std::string> *v)
-{
- static bool change;
- do {
- change = false;
- for (unsigned int i=0; i < v->size() - 1; i++) {
- if (v[0][i] > v[0][i + 1]) {
- std::swap(v[0][i], v[0][i + 1]);
- change = true;
- }
- }
- } while (change);
+ files.sort();
+ return 0;
}
std::string readFile(const std::string& path)
diff --git a/src/components.cpp b/src/components.cpp
index a7d504d..4d80d25 100644
--- a/src/components.cpp
+++ b/src/components.cpp
@@ -12,6 +12,8 @@
#include <atomic>
+using namespace std::literals::chrono_literals;
+
static std::vector<std::string> randomDialog (readFileA("assets/dialog_en-us"));
void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
@@ -66,10 +68,34 @@ Texture RenderSystem::loadTexture(const std::string& file)
loadTexString = file;
loadTexResult = Texture();
while (loadTexResult.isEmpty())
- std::this_thread::sleep_for(std::chrono::milliseconds(1));
+ std::this_thread::sleep_for(1ms);
return loadTexResult;
}
+void RenderSystem::fade(void)
+{
+ fadeIn = false, fadeIntensity = 0;
+}
+
+void RenderSystem::fadeLock(void)
+{
+ fade();
+ while (fadeIntensity < 1)
+ std::this_thread::sleep_for(1ms);
+}
+
+void RenderSystem::unfade(void)
+{
+ fadeIn = true, fadeIntensity = 1;
+}
+
+void RenderSystem::unfadeLock(void)
+{
+ fade();
+ while (fadeIntensity > 0)
+ std::this_thread::sleep_for(1ms);
+}
+
void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
{
(void)ev;
@@ -79,7 +105,14 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
loadTexString.clear();
}
+ // update fade system
+ if (fadeIn && fadeIntensity > 0)
+ fadeIntensity -= 0.01f;
+ else if(!fadeIn && fadeIntensity < 1)
+ fadeIntensity += 0.01f;
+
Render::worldShader.use();
+ Render::worldShader.enable();
en.each<Visible, Sprite, Position>([dt](entityx::Entity entity, Visible &visible, Sprite &sprite, Position &pos) {
// Verticies and shit
@@ -131,7 +164,6 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
sp.tex.use();
glUniform1i(Render::worldShader.uniform[WU_texture], 0);
- Render::worldShader.enable();
glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coords);
glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coord);
@@ -153,6 +185,32 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
ui::setFontZ(-5.0);
ui::putStringCentered(pos.x + dim.width / 2, pos.y - ui::fontSize - HLINES(0.5), name.name);
});
+
+ // draw fade
+ static const GLfloat tex[8] = {
+ 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ auto SCREEN_WIDTH2 = game::SCREEN_WIDTH / 2, SCREEN_HEIGHT2 = game::SCREEN_HEIGHT / 2;
+ GLfloat coord[12] = {
+ offset.x - SCREEN_WIDTH2 - 1, offset.y - SCREEN_HEIGHT2, -7.9,
+ offset.x + SCREEN_WIDTH2, offset.y - SCREEN_HEIGHT2, -7.9,
+ offset.x - SCREEN_WIDTH2 - 1, offset.y + SCREEN_HEIGHT2, -7.9,
+ offset.x + SCREEN_WIDTH2, offset.y + SCREEN_HEIGHT2, -7.9
+ };
+
+ Render::textShader.use();
+ Render::textShader.enable();
+
+ Colors::black.use();
+ glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0f, 1.0f, 1.0f, fadeIntensity);
+ glUniform1i(Render::textShader.uniform[WU_texture], 0);
+ glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coord);
+ glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
+ glDrawArrays(GL_QUADS, 0, 4);
+
+ Render::textShader.disable();
+ Render::textShader.unuse();
}
void DialogSystem::configure(entityx::EventManager &ev)
diff --git a/src/world.cpp b/src/world.cpp
index a1d2f3c..a80fba8 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -1178,13 +1178,13 @@ void WorldSystem::detect(entityx::TimeDelta dt)
void WorldSystem::goWorldRight(Position& p, Solid &d)
{
if (!(world.toRight.empty()) && (p.x + d.width > world.startX * -1 - HLINES(5))) {
- ui::toggleBlack();
- ui::waitForCover();
+ auto& rs = *game::engine.getSystem<RenderSystem>();
+ rs.fadeLock();
while (waitToSwap)
std::this_thread::sleep_for(1ms);
load(world.toRight);
game::engine.getSystem<PlayerSystem>()->setX(world.startX + HLINES(10));
- ui::toggleBlack();
+ rs.unfade();
}
}