aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2017-01-11 10:50:19 -0500
committerClyne Sullivan <tullivan99@gmail.com>2017-01-11 10:50:19 -0500
commit76a8dfce1c91c8536c940b53883eaf0ed7bd769a (patch)
tree311c5e1588eb1f8bd1bf5559eb6134edda4517bc
parentf800dbc034e7a70a613bab8cd9d147be4f6e88b6 (diff)
more windows stuff
-rw-r--r--Makefile10
-rw-r--r--include/events.hpp7
-rw-r--r--include/ui.hpp7
-rw-r--r--main.cpp12
-rw-r--r--src/components.cpp3
-rw-r--r--src/ui.cpp243
-rw-r--r--src/world.cpp6
-rw-r--r--xml/bobshouse.xml4
8 files changed, 154 insertions, 138 deletions
diff --git a/Makefile b/Makefile
index f8d7511..0e1f54e 100644
--- a/Makefile
+++ b/Makefile
@@ -39,11 +39,11 @@ cleandata:
touch brice.dat
$(EXEC): $(CXXOUTDIR)/$(CXXOBJ) main.cpp
- g++ -I. -std=c++11 -c entityx/help/Pool.cc -o out/Pool.o
- g++ -I. -std=c++11 -c entityx/help/Timer.cc -o out/Timer.o
- g++ -I. -std=c++11 -c entityx/Event.cc -o out/Event.o
- g++ -I. -std=c++11 -c entityx/Entity.cc -o out/Entity.o
- g++ -I. -std=c++11 -c entityx/System.cc -o out/System.o
+ #g++ -I. -std=c++11 -c entityx/help/Pool.cc -o out/Pool.o
+ #g++ -I. -std=c++11 -c entityx/help/Timer.cc -o out/Timer.o
+ #g++ -I. -std=c++11 -c entityx/Event.cc -o out/Event.o
+ #g++ -I. -std=c++11 -c entityx/Entity.cc -o out/Entity.o
+ #g++ -I. -std=c++11 -c entityx/System.cc -o out/System.o
@echo " CXX/LD main"
@$(CXX) $(CXXFLAGS) $(CXXINC) $(CXXWARN) -o $(EXEC) main.cpp out/*.o $(LIBS)
diff --git a/include/events.hpp b/include/events.hpp
index 2daae56..1f06544 100644
--- a/include/events.hpp
+++ b/include/events.hpp
@@ -16,6 +16,13 @@ class World;
/// INPUT EVENTS
//////////////////////////
+struct MainSDLEvent {
+ MainSDLEvent(SDL_Event e)
+ : event(e) {}
+
+ SDL_Event event;
+};
+
struct MouseScrollEvent {
MouseScrollEvent(int sd = 0)
: scrollDistance(sd) {}
diff --git a/include/ui.hpp b/include/ui.hpp
index 519d259..67c1010 100644
--- a/include/ui.hpp
+++ b/include/ui.hpp
@@ -44,8 +44,13 @@ SDL_Keycode getControl(int index);
#include <entityx/entityx.h>
-class InputSystem : public entityx::System<InputSystem> {
+class InputSystem : public entityx::System<InputSystem>, public entityx::Receiver<InputSystem> {
public:
+ inline void configure(entityx::EventManager &ev) {
+ ev.subscribe<MainSDLEvent>(*this);
+ }
+
+ void receive(const MainSDLEvent& event);
void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
};
diff --git a/main.cpp b/main.cpp
index a9ccac8..66b729a 100644
--- a/main.cpp
+++ b/main.cpp
@@ -108,7 +108,7 @@ int main(int argc, char *argv[])
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
// enable v-sync (TODO but 1000 fps?)
- SDL_GL_SetSwapInterval(1);
+ SDL_GL_SetSwapInterval(0);
// hide the cursor
SDL_ShowCursor(SDL_DISABLE);
// switch to pixel grid
@@ -196,7 +196,7 @@ int main(int argc, char *argv[])
worldShade = 50 * sin((game::time::getTickCount() + (DAY_CYCLE / 2)) / (DAY_CYCLE / PI));
// update fades
- ui::fadeUpdate();
+ //ui::fadeUpdate();
// increment game ticker
game::time::tick();
@@ -207,7 +207,7 @@ int main(int argc, char *argv[])
std::this_thread::sleep_for(1ms);
}
});
-
+
static float fpsInternal = 0;
// the debug loop, gets debug screen values
@@ -219,12 +219,16 @@ int main(int argc, char *argv[])
}
});
- // thre render loop, renders
+ // the render loop, renders
const bool &run = game::engine.shouldRun;
while (run) {
fpsInternal++;
render();
game::engine.resetRender(0); // TODO stupid
+
+ SDL_Event e;
+ while (SDL_PollEvent(&e))
+ game::events.emit<MainSDLEvent>(e);
}
// on game end, get back together
diff --git a/src/components.cpp b/src/components.cpp
index 7e6f204..fb0977f 100644
--- a/src/components.cpp
+++ b/src/components.cpp
@@ -172,7 +172,8 @@ void DialogSystem::receive(const MouseClickEvent &mce)
((mce.position.y > pos.y) & (mce.position.y < pos.y + dim.height))) {
if (!dialogRun.load()) {
- std::thread([&] {
+ // copy entity, windows destroys the original after thread detach
+ std::thread([e, &pos, &dim, &d, &name] {
std::string questAssignedText;
int newIndex;
diff --git a/src/ui.cpp b/src/ui.cpp
index 06e5841..d1b6055 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -534,8 +534,12 @@ namespace ui {
void waitForCover(void) {
auto& fi = fadeIntensity;
fi = 0;
- while (fi < 255)
+
+ while (fi < 255) {
+ fadeUpdate();
std::this_thread::sleep_for(1ms);
+ }
+
fi = 255;
}
@@ -1168,148 +1172,143 @@ namespace ui {
using namespace ui;
-void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
+void InputSystem::receive(const MainSDLEvent& event)
{
- (void)en;
- (void)ev;
- (void)dt;
-
if (currentMenu != nullptr)
return;
-
- auto SCREEN_WIDTH = game::SCREEN_WIDTH;
- auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
-
- SDL_Event e;
-
- // update mouse coords
- mouse.x = premouse.x + offset.x - (SCREEN_WIDTH / 2);
- mouse.y = (offset.y + SCREEN_HEIGHT / 2) - premouse.y;
-
- while(SDL_PollEvent(&e)) {
- switch(e.type) {
-
- // escape - quit game
- case SDL_QUIT:
- game::endGame();
- break;
-
- // window events - used for resizing and stuff
- case SDL_WINDOWEVENT:
- switch (e.window.event) {
- case SDL_WINDOWEVENT_RESIZED:
- std::cout << "Window " << e.window.windowID << " resized to: " << e.window.data1 << ", " << e.window.data2 << std::endl;
- auto w = e.window.data1;
- auto h = e.window.data2;
- ev.emit<WindowResizeEvent>(w,h);
- break;
- }
+
+ const auto& e = event.event;
+ auto& ev = game::events;
+
+ switch (e.type) {
+ // escape - quit game
+ case SDL_QUIT:
+ game::endGame();
+ break;
+
+ // window events - used for resizing and stuff
+ case SDL_WINDOWEVENT:
+ switch (e.window.event) {
+ case SDL_WINDOWEVENT_RESIZED:
+ std::cout << "Window " << e.window.windowID << " resized to: " << e.window.data1 << ", " << e.window.data2 << std::endl;
+ auto w = e.window.data1;
+ auto h = e.window.data2;
+ ev.emit<WindowResizeEvent>(w,h);
break;
+ }
+ break;
+ // mouse movement - update mouse vector
+ case SDL_MOUSEMOTION:
+ premouse.x=e.motion.x;
+ premouse.y=e.motion.y;
+ break;
- // mouse movement - update mouse vector
- case SDL_MOUSEMOTION:
- premouse.x=e.motion.x;
- premouse.y=e.motion.y;
+ //case SDL_MOUSEBUTTONUP:
+ case SDL_MOUSEBUTTONDOWN:
+ if (currentMenu != nullptr)
break;
- //case SDL_MOUSEBUTTONUP:
-
- case SDL_MOUSEBUTTONDOWN:
- if (currentMenu != nullptr)
- break;
-
- ev.emit<MouseClickEvent>(mouse, e.button.button);
+ ev.emit<MouseClickEvent>(mouse, e.button.button);
- // run actions?
- //if ((action::make = e.button.button & SDL_BUTTON_RIGHT))
- // /*player->inv->invHover =*/ edown = false;
+ // run actions?
+ //if ((action::make = e.button.button & SDL_BUTTON_RIGHT))
+ // /*player->inv->invHover =*/ edown = false;
- textToDraw.clear();
+ textToDraw.clear();
- if (dialogBoxExists || pageTexReady) {
- // right click advances dialog
- if ((e.button.button & SDL_BUTTON_RIGHT))
- dialogAdvance();
- } else {
- // left click uses item
- if (e.button.button & SDL_BUTTON_LEFT) {
- /*if ((ent = currentWorld->getNearMob(*player)) != nullptr) {
- player->inv->currentAddInteract(ent);
- }
- player->inv->useCurrent();*/
+ if (dialogBoxExists || pageTexReady) {
+ // right click advances dialog
+ if ((e.button.button & SDL_BUTTON_RIGHT))
+ dialogAdvance();
+ } else {
+ // left click uses item
+ if (e.button.button & SDL_BUTTON_LEFT) {
+ /*if ((ent = currentWorld->getNearMob(*player)) != nullptr) {
+ player->inv->currentAddInteract(ent);
}
-
+ player->inv->useCurrent();*/
}
- break;
- case SDL_MOUSEWHEEL:
- ev.emit<MouseScrollEvent>(e.wheel.y);
+ }
+ break;
+
+ case SDL_MOUSEWHEEL:
+ ev.emit<MouseScrollEvent>(e.wheel.y);
+ break;
+
+ // key presses
+ case SDL_KEYDOWN:
+ ev.emit<KeyDownEvent>(SDL_KEY);
+ switch(SDL_KEY){
+ case SDLK_t:
+ game::time::tick(100);
+ break;
+ }
+ break;
+
+ // key release
+ case SDL_KEYUP:
+ ev.emit<KeyUpEvent>(SDL_KEY);
+
+ if (SDL_KEY == SDLK_ESCAPE)
+ ui::menu::toggle();
+
+ if (SDL_KEY == SDLK_q) {
+ /*auto item = player->inv->getCurrentItem();
+ if (item != nullptr) {
+ if (player->inv->takeItem(item->name, 1) == 0)
+ currentWorld->addObject(item->name, "o shit waddup",
+ player->loc.x + player->width / 2, player->loc.y + player->height / 2);
+ }*/
+ } else if (SDL_KEY == SDLK_h) {
+ quest::toggle();
+ } else switch (SDL_KEY) {
+ case SDLK_F3:
+ debug ^= true;
break;
-
- // key presses
- case SDL_KEYDOWN:
- ev.emit<KeyDownEvent>(SDL_KEY);
- switch(SDL_KEY){
- case SDLK_t:
- game::time::tick(100);
- break;
- }
+ case SDLK_BACKSLASH:
+ dialogBoxExists = false;
break;
- /*
- * KEYUP
- */
-
- case SDL_KEYUP:
- ev.emit<KeyUpEvent>(SDL_KEY);
-
- if (SDL_KEY == SDLK_ESCAPE)
- ui::menu::toggle();
-
- if (SDL_KEY == SDLK_q) {
- /*auto item = player->inv->getCurrentItem();
- if (item != nullptr) {
- if (player->inv->takeItem(item->name, 1) == 0)
- currentWorld->addObject(item->name, "o shit waddup",
- player->loc.x + player->width / 2, player->loc.y + player->height / 2);
- }*/
- } else if (SDL_KEY == SDLK_h) {
- quest::toggle();
- } else switch (SDL_KEY) {
- case SDLK_F3:
- debug ^= true;
- break;
- case SDLK_BACKSLASH:
- dialogBoxExists = false;
- break;
- case SDLK_b:
- if (debug)
- posFlag ^= true;
- break;
- case SDLK_F12:
- // Make the BYTE array, factor of 3 because it's RBG.
- /*static GLubyte* pixels;
- pixels = new GLubyte[ 3 * SCREEN_WIDTH * SCREEN_HEIGHT];
- glReadPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, pixels);
- takeScreenshot(pixels);*/
+ case SDLK_b:
+ if (debug)
+ posFlag ^= true;
+ break;
+ case SDLK_F12:
+ // Make the BYTE array, factor of 3 because it's RBG.
+ /*static GLubyte* pixels;
+ pixels = new GLubyte[ 3 * SCREEN_WIDTH * SCREEN_HEIGHT];
+ glReadPixels(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, pixels);
+ takeScreenshot(pixels);*/
- ev.emit<ScreenshotEvent>(game::SCREEN_WIDTH, game::SCREEN_HEIGHT);
-
- std::cout << "Took screenshot" << std::endl;
- break;
- case SDLK_UP:
- //player->inv->setSelectionUp();
- break;
- case SDLK_DOWN:
- //player->inv->setSelectionDown();
- break;
- default:
- break;
- }
+ ev.emit<ScreenshotEvent>(game::SCREEN_WIDTH, game::SCREEN_HEIGHT);
+ std::cout << "Took screenshot" << std::endl;
+ break;
+ case SDLK_UP:
+ //player->inv->setSelectionUp();
+ break;
+ case SDLK_DOWN:
+ //player->inv->setSelectionDown();
break;
default:
break;
}
+ break;
+
+ default:
+ break;
+
}
}
+
+void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
+{
+ (void)en;
+ (void)ev;
+ (void)dt;
+
+ // update mouse coords
+ mouse.x = premouse.x + offset.x - (game::SCREEN_WIDTH / 2);
+ mouse.y = (offset.y + game::SCREEN_HEIGHT / 2) - premouse.y;
+}
diff --git a/src/world.cpp b/src/world.cpp
index 7ca3cce..6b7b89b 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -162,7 +162,7 @@ float WorldSystem::isAboveGround(const vec2& p) const
static Color ambient;
bool WorldSystem::save(void)
-{
+{
if (world.indoor)
return false;
@@ -241,7 +241,7 @@ void WorldSystem::load(const std::string& file)
game::engine.getSystem<PlayerSystem>()->create();
// iterate through tags
- while (wxml) {
+ while (wxml != nullptr) {
std::string tagName = wxml->Name();
// style tag
@@ -276,7 +276,7 @@ void WorldSystem::load(const std::string& file)
UserError("<house> can only be used inside <IndoorWorld>");
//world.indoorWidth = wxml->FloatAttribute("width");
- world.indoorTex = render.loadTexture(wxml->StrAttribute("texture"));
+ (void)render;//world.indoorTex = render.loadTexture(wxml->StrAttribute("texture")); // TODO winbloze lol
//auto str = wxml->StrAttribute("texture");
//auto tex = render.loadTexture(str);
//world.indoorTex = tex;
diff --git a/xml/bobshouse.xml b/xml/bobshouse.xml
index cde1cdc..d79274d 100644
--- a/xml/bobshouse.xml
+++ b/xml/bobshouse.xml
@@ -2,8 +2,8 @@
<include file="entities.xml"/>
<IndoorWorld>
- <style background="0" bgm="assets/music/theme_jazz.wav" folder="assets/style/classic/"/>
- <house width="800" texture="assets/style/classic/bg/insideWoodHouse.png"/>
+ <style background="0" bgm="assets/music/theme_jazz.wav" folder="assets/style/classic/"/>
+ <house width="800" texture="assets/style/classic/bg/insideWoodHouse.png"/>
<generation width="320"/>
<time>6000</time>
<!--<link outside="town.xml"/>-->