#include <texture.hpp>
#include <events.hpp>
+#include <atomic>
+
/**
* @struct Position
* @brief Stores the position of an entity on the xy plane.
};
class RenderSystem : public entityx::System<RenderSystem> {
+private:
+ std::string loadTexString;
+ std::atomic<GLuint> loadTexResult;
public:
+ GLuint loadTexture(const std::string& file);
void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
};
const bool &run = game::engine.shouldRun;
while (run) {
- game::engine.render(0);
render();
+ game::engine.render(0);
}
thMain.join();
});
}
+GLuint RenderSystem::loadTexture(const std::string& file)
+{
+ loadTexString = file;
+ loadTexResult = 0xFFFF;
+ while (loadTexResult == 0xFFFF)
+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
+ return loadTexResult;
+}
+
void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
{
(void)ev;
+
+ if (!loadTexString.empty()) {
+ loadTexResult = Texture::loadTexture(loadTexString);
+ loadTexString.clear();
+ }
+
Render::worldShader.use();
en.each<Visible, Sprite, Position>([dt](entityx::Entity entity, Visible &visible, Sprite &sprite, Position &pos) {
#include <components.hpp>
#include <player.hpp>
-extern World *currentWorld;
-
Engine::Engine(void)
: shouldRun(true), systems(game::entities, game::events)
{
#include <chrono>
using namespace std::literals::chrono_literals;
-extern Menu* currentMenu;
+extern Menu *currentMenu;
std::array<SDL_Keycode, 6> controlMap = {
SDLK_w, SDLK_a, SDLK_d, SDLK_LSHIFT, SDLK_LCTRL, SDLK_e
static Mix_Chunk *dialogClick;
-extern void mainLoop(void);
-
/*
* Fade effect flags
*/
(void)ev;
(void)dt;
+ if (currentMenu != nullptr)
+ return;
auto SCREEN_WIDTH = game::SCREEN_WIDTH;
auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
//case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONDOWN:
+ if (currentMenu != nullptr)
+ break;
+
ev.emit<MouseClickEvent>(mouse, e.button.button);
// run actions?
#include <fstream>
-extern bool gameRunning;
-
extern Menu *currentMenu;
static Menu pauseMenu;
for (auto &m : currentMenu->items) {
// reset the background modifier
cMult = 1.0f;
-
+
//if the menu is any type of button
if (m.member == 0 || m.member == -1 || m.member == -2) {
//tests if the mouse is over the button
if (mouse.x >= offset.x+m.button.loc.x && mouse.x <= offset.x+m.button.loc.x + m.button.dim.x) {
if (mouse.y >= offset.y+m.button.loc.y && mouse.y <= offset.y+m.button.loc.y + m.button.dim.y) {
-
+
// set the darkness multiplier
cMult = 0.6f;
//test if mouse is inside of the slider's borders
if (mouse.x >= offset.x+m.slider.loc.x && mouse.x <= offset.x+m.slider.loc.x+m.slider.dim.x) {
if (mouse.y >= offset.y+m.slider.loc.y && mouse.y <= offset.y+m.slider.loc.y+m.slider.dim.y) {
-
+
// change multiplier background modifier
cMult = 0.75f;
-
+
//if we are inside the slider and click it will set the slider to that point
if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) {
//change handle location
if (m.slider.dim.y > m.slider.dim.x) {
*m.slider.var = (((mouse.y-offset.y) - m.slider.loc.y)/m.slider.dim.y)*100;
-
+
cMult = 0.5f;
}else{
*m.slider.var = (((mouse.x-offset.x) - m.slider.loc.x)/m.slider.dim.x)*100;
-
+
cMult = 0.5f;
}
}
void WorldSystem::load(const std::string& file)
{
+ auto& render = *game::engine.getSystem<RenderSystem>();
auto str2coord = [](std::string s) -> vec2 {
auto cpos = s.find(',');
s[cpos] = '\0';
world.indoorWidth = wxml->FloatAttribute("width");
auto str = wxml->StrAttribute("texture");
- auto tex = Texture::loadTexture(str);
+ auto tex = render.loadTexture(str);
world.indoorTex = tex;
}
<IndoorWorld>
<style background="0" bgm="assets/music/theme_jazz.wav" folder="assets/style/classic/"/>
- <house width="640" texture="assets/style/classic/bg/insideWoodHouse.png"/>
- <generation width="1600"/>
+ <house width="800" texture="assets/style/classic/bg/insideWoodHouse.png"/>
+ <generation width="320"/>
<time>6000</time>
<!--<link outside="town.xml"/>-->
<npc name="Bob" hasDialog="false" spawnx="30"/>