aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components.cpp66
-rw-r--r--src/engine.cpp13
-rw-r--r--src/render.cpp124
-rw-r--r--src/ui.cpp47
-rw-r--r--src/window.cpp6
-rw-r--r--src/world.cpp10
6 files changed, 166 insertions, 100 deletions
diff --git a/src/components.cpp b/src/components.cpp
index 4d80d25..28a81fe 100644
--- a/src/components.cpp
+++ b/src/components.cpp
@@ -72,49 +72,18 @@ Texture RenderSystem::loadTexture(const std::string& file)
return loadTexResult;
}
-void RenderSystem::fade(void)
+void RenderSystem::render(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;
-
if (!loadTexString.empty()) {
loadTexResult = Texture(loadTexString);
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) {
+ game::entities.lock();
+ game::entities.each<Visible, Sprite, Position>([](entityx::Entity entity, Visible &visible, Sprite &sprite, Position &pos) {
// Verticies and shit
float its = 0;
@@ -179,38 +148,13 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
Render::worldShader.disable();
Render::worldShader.unuse();
- en.each<Visible, Position, Solid, Name>([](entityx::Entity e, Visible &v, Position &pos, Solid& dim, Name &name) {
+ game::entities.each<Visible, Position, Solid, Name>([](entityx::Entity e, Visible &v, Position &pos, Solid& dim, Name &name) {
(void)e;
(void)v;
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();
+ game::entities.unlock();
}
void DialogSystem::configure(entityx::EventManager &ev)
diff --git a/src/engine.cpp b/src/engine.cpp
index abadf3f..c7999ed 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -38,22 +38,11 @@ void Engine::init(void) {
systems.configure();
ui::initSounds();
+ ui::menu::init();
game::config::update();
getSystem<PlayerSystem>()->create();
}
-void Engine::render(entityx::TimeDelta dt)
-{
- systems.update<RenderSystem>(dt);
- //systems.update<InventorySystem>(dt); // doesn't do anything...
-
- ui::fadeUpdate();
-}
-void Engine::resetRender(entityx::TimeDelta dt)
-{
- systems.update<WindowSystem>(dt);
-}
-
void Engine::update(entityx::TimeDelta dt)
{
systems.update<InputSystem>(dt);
diff --git a/src/render.cpp b/src/render.cpp
index 908b620..4e32311 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -1,7 +1,12 @@
#include <render.hpp>
+#include <texture.hpp>
+
static Shader *currentShader = nullptr;
+void preRender(void);
+void render(const int&);
+
namespace Render {
Shader worldShader;
@@ -62,4 +67,123 @@ void drawRect(vec2 ll, vec2 ur, float z)
currentShader->disable();
}
+void init(void)
+{
+#ifndef __WIN32__
+ glewExperimental = GL_TRUE;
+#endif
+
+ auto glewError = glewInit();
+ if (glewError != GLEW_OK)
+ UserError(std::string("GLEW was not able to initialize! Error: ")
+ + reinterpret_cast<const char *>(glewGetErrorString(glewError)));
+
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); // anti-aliasing
+ SDL_GL_SetSwapInterval(0); // v-sync
+ SDL_ShowCursor(SDL_DISABLE); // hide the cursor
+ glViewport(0, 0, game::SCREEN_WIDTH, game::SCREEN_HEIGHT); // pixel coordinates
+ glEnable(GL_BLEND); // alpha enabling
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //
+ glClearColor(1, 1, 1, 1); // white clear color
+
+ std::cout << "Initializing shaders!\n";
+ initShaders();
+ ::Colors::init();
+}
+
+void render(const int& fps)
+{
+ preRender();
+ ::render(fps);
+}
+
+} // namespace render
+
+#include <ui.hpp>
+#include <window.hpp>
+#include <world.hpp>
+#include <engine.hpp>
+#include <particle.hpp>
+#include <player.hpp>
+#include <entityx/entityx.h>
+#include <gametime.hpp>
+
+void preRender(void)
+{
+ static const glm::mat4 view = glm::lookAt(
+ glm::vec3(0.0f, 0.0f, 0.0f), // pos
+ glm::vec3(0.0f, 0.0f, -10.0f), // looking at
+ glm::vec3(0.0f, 1.0f, 0.0f) // up vector
+ );
+
+ static const auto& SCREEN_WIDTH2 = game::SCREEN_WIDTH / 2.0f;
+ static const auto& SCREEN_HEIGHT2 = game::SCREEN_HEIGHT / 2.0f;
+
+ //
+ // set the ortho
+ //
+
+ auto ps = game::engine.getSystem<PlayerSystem>();
+ auto ploc = ps->getPosition();
+ offset.x = ploc.x + ps->getWidth() / 2;
+
+ const auto& worldWidth = game::engine.getSystem<WorldSystem>()->getWidth();
+ if (worldWidth < (int)SCREEN_WIDTH2 * 2)
+ offset.x = 0;
+ else if (offset.x - SCREEN_WIDTH2 < worldWidth * -0.5f)
+ offset.x = ((worldWidth * -0.5f) + SCREEN_WIDTH2);
+ else if (offset.x + SCREEN_WIDTH2 > worldWidth * 0.5f)
+ offset.x = ((worldWidth * 0.5f) - SCREEN_WIDTH2);
+
+ // ortho y snapping
+ offset.y = std::max(ploc.y /*+ player->height / 2*/, SCREEN_HEIGHT2);
+
+ // "setup"
+ glm::mat4 projection = glm::ortho(floor(offset.x - SCREEN_WIDTH2), // left
+ floor(offset.x + SCREEN_WIDTH2), // right
+ floor(offset.y - SCREEN_HEIGHT2), // bottom
+ floor(offset.y + SCREEN_HEIGHT2), // top
+ static_cast<decltype(floor(10.0f))>(10.0), // near
+ static_cast<decltype(floor(10.0f))>(-10.0)); // far
+
+ glm::mat4 ortho = projection * view;
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glEnable(GL_DEPTH_TEST);
+
+ Render::worldShader.use();
+ glUniformMatrix4fv(Render::worldShader.uniform[WU_ortho], 1, GL_FALSE, glm::value_ptr(ortho));
+ glUniformMatrix4fv(Render::worldShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f)));
+ Render::worldShader.unuse();
+
+ Render::textShader.use();
+ glUniformMatrix4fv(Render::textShader.uniform[WU_transform], 1, GL_FALSE, glm::value_ptr(ortho));
+ glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0);
+ Render::textShader.unuse();
+}
+
+void render(const int& fps)
+{
+ preRender();
+
+ game::engine.getSystem<WorldSystem>()->render();
+
+ game::engine.getSystem<ParticleSystem>()->render();
+
+ game::engine.getSystem<RenderSystem>()->render();
+
+ // draw the debug overlay if desired
+ if (ui::debug) {
+ auto pos = game::engine.getSystem<PlayerSystem>()->getPosition();
+ ui::putText(offset.x - game::SCREEN_WIDTH / 2, (offset.y + game::SCREEN_HEIGHT / 2) - ui::fontSize,
+ "loc: %s\noffset: %s\nfps: %d\nticks: %d\npcount: %d\nxml: %s",
+ pos.toString().c_str(), offset.toString().c_str(), fps,
+ game::time::getTickCount(), game::engine.getSystem<ParticleSystem>()->getCount(),
+ game::engine.getSystem<WorldSystem>()->getXMLFile().c_str());
+ }
+
+ ui::drawFade();
+ ui::draw();
+
+ game::engine.getSystem<WindowSystem>()->render();
}
diff --git a/src/ui.cpp b/src/ui.cpp
index 21ed180..9470a56 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -535,8 +535,8 @@ namespace ui {
auto& fi = fadeIntensity;
fi = 0;
- //while (fi < 255)
- //std::this_thread::sleep_for(1ms);
+ while (fi < 255)
+ std::this_thread::sleep_for(1ms);
fi = 255;
}
@@ -973,6 +973,18 @@ namespace ui {
}*/
setFontColor(255,255,255,255);
}
+
+ if (currentMenu != nullptr)
+ menu::draw();
+
+ // draw the mouse
+ static const Texture mouseTex ("assets/goodmouse.png");
+ Render::textShader.use();
+ glActiveTexture(GL_TEXTURE0);
+ mouseTex.use();
+ Render::useShader(&Render::textShader);
+ Render::drawRect(vec2(ui::mouse.x, ui::mouse.y - 64), vec2(ui::mouse.x + 64, ui::mouse.y), -9.9);
+ Render::textShader.unuse();
}
void closeBox() {
@@ -1017,43 +1029,40 @@ namespace ui {
}
void drawFade(void) {
- static const auto SCREEN_WIDTH2 = game::SCREEN_WIDTH / 2;
- static const auto SCREEN_HEIGHT2 = game::SCREEN_HEIGHT / 2;
-
if (!fadeIntensity) {
if (fontSize != 16)
setFontSize(16);
return;
}
- static const GLfloat tex[] = {
- 0.0, 0.0,
- 1.0, 0.0,
- 0.0, 1.0,
- 1.0, 1.0
+ static const GLfloat tex[12] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
- GLfloat backdrop[] = {
- 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
+ vec2 p1 (offset.x - game::SCREEN_WIDTH / 2, offset.y - game::SCREEN_HEIGHT / 2);
+ vec2 p2 (p1.x + game::SCREEN_WIDTH, p1.y + game::SCREEN_HEIGHT);
+ GLfloat backdrop[18] = {
+ p1.x, p1.y, -7.9,
+ p2.x, p1.y, -7.9,
+ p2.x, p2.y, -7.9,
+
+ p2.x, p2.y, -7.9,
+ p1.x, p2.y, -7.9,
+ p1.x, p1.y, -7.9
};
setFontZ(-8.2);
- glUniform1i(Render::textShader.uniform[WU_texture], 0);
-
Render::textShader.use();
Render::textShader.enable();
+
Colors::black.use();
glUniform4f(Render::textShader.uniform[WU_tex_color], 1.0f, 1.0f, 1.0f, fadeIntensity / 255.0f);
glVertexAttribPointer(Render::textShader.coord, 3, GL_FLOAT, GL_FALSE, 0, backdrop);
glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ glDrawArrays(GL_TRIANGLES, 0, 6);
Render::textShader.disable();
Render::textShader.unuse();
-
setFontZ(-8.0);
}
diff --git a/src/window.cpp b/src/window.cpp
index 29bd7c7..992e3c1 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -95,11 +95,7 @@ void WindowSystem::receive(const ScreenshotEvent &scr)
std::cout << "Triggered\n";
}
-void WindowSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
+void WindowSystem::render(void)
{
- (void)en;
- (void)ev;
- (void)dt;
-
SDL_GL_SwapWindow(window);
}
diff --git a/src/world.cpp b/src/world.cpp
index a80fba8..6551442 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -1147,7 +1147,8 @@ void WorldSystem::detect(entityx::TimeDelta dt)
const auto& data = world.data;
if (loc.y < data[line].groundHeight) {
int dir = vel.x < 0 ? -1 : 1;
- if (line + dir * 2 < static_cast<int>(data.size()) &&
+ auto thing = line + dir * 2;
+ if (thing > 0 && thing < static_cast<int>(data.size()) &&
data[line + dir * 2].groundHeight - 30 > data[line + dir].groundHeight) {
loc.x -= (PLAYER_SPEED_CONSTANT + 2.7f) * dir * 2;
vel.x = 0;
@@ -1179,12 +1180,15 @@ void WorldSystem::goWorldRight(Position& p, Solid &d)
{
if (!(world.toRight.empty()) && (p.x + d.width > world.startX * -1 - HLINES(5))) {
auto& rs = *game::engine.getSystem<RenderSystem>();
- rs.fadeLock();
+ //rs.fadeLock();
+ ui::toggleBlack();
+ ui::waitForCover();
while (waitToSwap)
std::this_thread::sleep_for(1ms);
load(world.toRight);
game::engine.getSystem<PlayerSystem>()->setX(world.startX + HLINES(10));
- rs.unfade();
+ ui::toggleBlack();
+ //rs.unfade();
}
}