]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
more windows stuff
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 11 Jan 2017 15:50:19 +0000 (10:50 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 11 Jan 2017 15:50:19 +0000 (10:50 -0500)
Makefile
include/events.hpp
include/ui.hpp
main.cpp
src/components.cpp
src/ui.cpp
src/world.cpp
xml/bobshouse.xml

index f8d751131a94c9a40f810b3c62d352ac811bbc4e..0e1f54e6985f2519e30921a5e6ffe33fb3415c69 100644 (file)
--- 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)
index 2daae5608c0243275f84fd206cdc99be28333950..1f06544e3ec21ce4b8923d56226caa7fafd5b0ac 100644 (file)
@@ -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) {}
index 519d2596d1ea45046d9f61f6fa5c457a493e1868..67c1010e0a1e63aea28ccefc440be3203b94ebbd 100644 (file)
@@ -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;
 };
 
index a9ccac85de505e1199adabb2e6f2c6b1e67538ec..66b729a0f4018b153eda532b6a885c304ccab574 100644 (file)
--- 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
index 7e6f204ea79d0b3d8773a43c9845ffae7a55a379..fb0977f6e7ec91f1b9249169cdb6d78a93b7a762 100644 (file)
@@ -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;
 
index 06e5841585e513f2d4d556cbcf541fc5b26bc8cf..d1b605526250b8ca197d10cd81136b6fd137aea3 100644 (file)
@@ -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;
+}
index 7ca3cce232a7fa9c8789c3820f102f0fa4467f01..6b7b89b5c439b02f57023f8a849eea9583109d99 100644 (file)
@@ -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;
index cde1cdcf9b09f290631aff9160e4c5e9806b44e0..d79274da82eee51da70f8284963dc40e00d1eb98 100644 (file)
@@ -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"/>-->