]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
indoorworld removal, substitutions made
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 17 Oct 2016 23:22:07 +0000 (19:22 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 17 Oct 2016 23:22:07 +0000 (19:22 -0400)
include/entities.hpp
include/world.hpp
src/engine.cpp
src/entities.cpp
src/ui.cpp
src/world.cpp
xml/!town.xml

index 5f85c265f4f5aa91c40dc82436d50396739df0a2..49598bdd3b292bfb804c86e01b14a252ae3a1bb0 100644 (file)
@@ -339,7 +339,7 @@ class Structures : public Entity {
 public:
        BUILD_SUB bsubtype;
        World *inWorld;
-       IndoorWorld *insideWorld;
+       World *insideWorld;
        std::string inside;
        std::string textureLoc;
 
index a574401306d5ea7e4c2fbfb45202fccdf7daed66..4b25e854263ea39e0e1c6ed81b8537f4c0ed3fa0 100644 (file)
@@ -17,7 +17,7 @@
  * in World::setBackground() to select the appropriate images.
  */
 enum class WorldBGType : unsigned int {
-       Forest,         /**< A forest theme. */
+       Forest = 0,     /**< A forest theme. */
        WoodHouse       /**< An indoor wooden house theme. */
 };
 
@@ -142,6 +142,7 @@ constexpr const char* WorldWeatherString[3] = {
 class WorldSystem : public entityx::System<WorldSystem>, public entityx::Receiver<WorldSystem> {
 private:
        World *world;
+       World *outside;
 
        WorldWeather weather;
 
@@ -149,7 +150,6 @@ private:
        std::string bgmObjFile;
 
        std::vector<std::string> bgFiles;
-       std::vector<std::string> bgFilesIndoors;
 
        TextureIterator bgTex;
 
@@ -180,6 +180,9 @@ public:
        void detect(entityx::TimeDelta dt);
 
        void detect2(entityx::TimeDelta dt);
+
+       void enterWorld(World *w);
+       void leaveWorld(void);
 };
 
 
@@ -190,9 +193,14 @@ public:
  * drawing.
  */
 class World {
-//friend class ItemLight;
+private:
+       bool m_Indoor;
+
 public:
 
+       inline bool isIndoor(void) const
+       { return m_Indoor; }
+
        WorldBGType bgType;
 
        std::string styleFolder;
@@ -285,7 +293,7 @@ public:
        /**
         * Constructs the world, resets variables.
         */
-       World(void);
+       World(bool indoor = false);
 
        /**
         * Destructs the world, frees memory.
@@ -431,50 +439,6 @@ public:
        Village *addVillage(std::string name, World *world);
 };
 
-/**
- * IndoorWorld - Indoor settings stored in a World class
- */
-class IndoorWorld : public World {
-private:
-
-       // like lines, but split into floors
-       std::vector<std::vector<float>> floor;
-
-       // the x coordinate to start each floor at
-       std::vector<float> fstart;
-
-       // handles physics for a single entity
-       void singleDetect(Entity *e);
-
-public:
-
-       World *outside;
-
-       // creates an IndoorWorld object
-       IndoorWorld(void);
-
-       // frees memory used by this object
-       ~IndoorWorld(void);
-
-       // adds a floor of the desired width
-       void addFloor(unsigned int width);
-
-       // adds a floor at the desired x coordinate with the given width
-       void addFloor(unsigned int width, unsigned int start);
-
-       // attempts to move the entity provided to the given floor
-       bool moveToFloor(Entity *e, unsigned int _floor);
-
-       // checks for a floor above the given entity
-       bool isFloorAbove(Entity *e);
-
-       // checks for a floor below the given entity
-       bool isFloorBelow(Entity *e);
-
-       // draws the world about the player
-       void draw(Player *p);
-};
-
 /**
  * The arena class - creates an arena.
  *
index 9a362e18cb8ae7a319a0c4af0c6d62776381a6bc..56dee480715cdb43afa0083e7fbff58126aae52a 100644 (file)
@@ -25,6 +25,8 @@ void Engine::init(void) {
     systems.add<PlayerSystem>(&player);
 
     systems.configure();
+
+       game::config::update();
 }
 
 void Engine::render(entityx::TimeDelta dt)
index 3afcc40a577de2f803e5f0e647ccc2fc4b9b1a77..6b9c3fe0b4a4431d8b62a7cc2bccfcd5847c840f 100644 (file)
@@ -95,11 +95,12 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
        auto kc = kde.keycode;
 
        auto worldSwitch = [&](const WorldSwitchInfo& wsi){
-               p->canMove = false;
+               player->canMove = false;
                ui::toggleBlackFast();
                ui::waitForCover();
                game::events.emit<BGMToggleEvent>(wsi.first->bgm, wsi.first);
                std::tie(currentWorld, player->loc) = wsi; // using p causes segfault
+               game::engine.getSystem<WorldSystem>()->setWorld(currentWorld);
                ui::toggleBlackFast();
                ui::waitForUncover();
                player->canMove = true; // using p causes segfault
@@ -397,6 +398,7 @@ void NPC::createFromXML(XMLElement *e, World *w=nullptr)
        unsigned int flooor;
 
        xmle = e;
+       (void)w;
 
     // spawn at coordinates if desired
        E_LOAD_COORDS(100);
@@ -412,10 +414,6 @@ void NPC::createFromXML(XMLElement *e, World *w=nullptr)
        else
         dialogIndex = 9999;
 
-
-    if (/*Indoor && */e->QueryUnsignedAttribute("floor", &flooor) == XML_NO_ERROR)
-        Indoorp(w)->moveToFloor(this, flooor);
-
     // custom health value
        E_LOAD_HEALTH;
 
@@ -497,8 +495,7 @@ void Structures::createFromXML(XMLElement *e, World *w)
 
        // edge
        if (!inside.empty()) {
-               insideWorld = dynamic_cast<IndoorWorld *>(loadWorldFromXMLNoTakeover(inside));
-               insideWorld->outside = inWorld;
+               insideWorld = loadWorldFromXMLNoTakeover(inside);
        }
 
        textureLoc = e->StrAttribute("texture");
index 09102a1b1471efaad9a029b920dd7feb8c745e77..aed2f487933a7c6ffd927fc5c77dab93c31507d1 100644 (file)
@@ -1441,7 +1441,6 @@ void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
        auto SCREEN_WIDTH = game::SCREEN_WIDTH;
        auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
 
-       auto indoor = dynamic_cast<IndoorWorld *>(currentWorld);
        Mob *m; // ;lkjfdsa
        Entity *ent; // used for interaction
 
@@ -1556,18 +1555,6 @@ void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
                                if (m != nullptr)
                                        m->ride(player);
                                break;
-                       case SDLK_i:
-                               if (indoor && indoor->isFloorAbove(player)) {
-                                       player->loc.y += INDOOR_FLOOR_HEIGHT;
-                                       player->ground = false;
-                               }
-                               break;
-                       case SDLK_k:
-                               if (indoor && indoor->isFloorBelow(player)) {
-                                       player->loc.y -= INDOOR_FLOOR_HEIGHT;
-                                       player->ground = false;
-                               }
-                               break;
                        case SDLK_l:
                                currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y}, 300.0f, {1.0f,1.0f,1.0f});
                                currentWorld->getLastLight().follow(player);
index 1290aa787f14a82fac72a5db3255e17ae23cdedf..11132703f109eee6d81baaeb3abde89074fe259a 100644 (file)
@@ -129,11 +129,9 @@ XMLDocument currentXMLDoc;
  * Creates a world object.
  * Note that all this does is nullify a pointer...
  */
-World::
-World(void)
+World::World(bool indoor)
+       : m_Indoor(indoor), lineCount(0), worldStart(0) 
 {
-       worldStart = 0;
-       lineCount = 0;
 }
 
 /**
@@ -196,23 +194,31 @@ generate(int width)
     worldData.front().groundHeight = GROUND_HEIGHT_INITIAL;
     auto wditer = std::begin(worldData) + GROUND_HILLINESS;
 
-    // give every GROUND_HILLINESSth entry a groundHeight value
-    for (; wditer < std::end(worldData); wditer += GROUND_HILLINESS)
-        wditer[-static_cast<int>(GROUND_HILLINESS)].groundHeight = wditer[0].groundHeight + (randGet() % 8 - 4);
-
-    // create slopes from the points that were just defined, populate the rest of the WorldData structure
-    for (wditer = std::begin(worldData) + 1; wditer < std::end(worldData); wditer++){
-        auto w = &*(wditer);
-
-        if (w->groundHeight != 0)
-            geninc = (w[static_cast<int>(GROUND_HILLINESS)].groundHeight - w->groundHeight) / GROUND_HILLINESS;
-
-        w->groundHeight   = std::clamp(w[-1].groundHeight + geninc, GROUND_HEIGHT_MINIMUM, GROUND_HEIGHT_MAXIMUM);
-        w->groundColor    = randGet() % 32 / 8;
-        w->grassUnpressed = true;
-        w->grassHeight[0] = (randGet() % 16) / 3 + 2;
-        w->grassHeight[1] = (randGet() % 16) / 3 + 2;
-    }
+       if (m_Indoor) {
+               for(; wditer < std::end(worldData); wditer++) {
+                       auto w = &*(wditer);
+                       w->groundHeight = 100;
+                       w->groundColor = 4;
+               }
+       } else {
+           // give every GROUND_HILLINESSth entry a groundHeight value
+           for (; wditer < std::end(worldData); wditer += GROUND_HILLINESS)
+               wditer[-static_cast<int>(GROUND_HILLINESS)].groundHeight = wditer[0].groundHeight + (randGet() % 8 - 4);
+
+       // create slopes from the points that were just defined, populate the rest of the WorldData structure
+           for (wditer = std::begin(worldData) + 1; wditer < std::end(worldData); wditer++){
+               auto w = &*(wditer);
+
+           if (w->groundHeight != 0)
+                   geninc = (w[static_cast<int>(GROUND_HILLINESS)].groundHeight - w->groundHeight) / GROUND_HILLINESS;
+
+           w->groundHeight   = std::clamp(w[-1].groundHeight + geninc, GROUND_HEIGHT_MINIMUM, GROUND_HEIGHT_MAXIMUM);
+               w->groundColor    = randGet() % 32 / 8;
+               w->grassUnpressed = true;
+               w->grassHeight[0] = (randGet() % 16) / 3 + 2;
+               w->grassHeight[1] = (randGet() % 16) / 3 + 2;
+           }
+       }
 
     // define x-coordinate of world's leftmost 'line'
     worldStart = (width - GROUND_HILLINESS) * game::HLINE / 2 * -1;
@@ -629,7 +635,7 @@ WorldSwitchInfo World::goInsideStructure(Player *p)
                outdoorName.clear();
                outdoorData.clear();
 
-               tmp = dynamic_cast<IndoorWorld *>(currentWorld)->outside; //loadWorldFromXML(inside.back());
+               /*tmp = dynamic_cast<IndoorWorld *>(currentWorld)->outside; //loadWorldFromXML(inside.back());
 
         Structures *b = nullptr;
         for (auto &s : tmp->entity) {
@@ -639,10 +645,10 @@ WorldSwitchInfo World::goInsideStructure(Player *p)
             }
         }
 
-        if (b == nullptr)
+        if (b == nullptr)*/
             return std::make_pair(this, vec2 {0, 0});
 
-               return std::make_pair(tmp, vec2 {b->loc.x + (b->width / 2), 0});
+               //return std::make_pair(tmp, vec2 {b->loc.x + (b->width / 2), 0});
        }
 
        return std::make_pair(this, vec2 {0, 0});
@@ -753,237 +759,6 @@ addHill(const ivec2 peak, const unsigned int width)
        }
 }
 
-IndoorWorld::IndoorWorld(void) {
-}
-
-IndoorWorld::~IndoorWorld(void) {
-       deleteEntities();
-}
-
-void IndoorWorld::
-addFloor(unsigned int width)
-{
-    if (floor.empty())
-        generate(width);
-
-    floor.emplace_back(width, floor.size() * INDOOR_FLOOR_HEIGHT);
-    fstart.push_back(0);
-}
-
-
-void IndoorWorld::
-addFloor(unsigned int width, unsigned int start)
-{
-    if (floor.empty())
-        generate(width);
-
-    floor.emplace_back(width, floor.size() * INDOOR_FLOOR_HEIGHT);
-    fstart.push_back(start);
-}
-
-bool IndoorWorld::
-moveToFloor(Entity *e, unsigned int _floor)
-{
-    if (_floor > floor.size())
-        return false;
-
-    e->loc.y = floor[_floor - 1][0];
-    return true;
-}
-
-bool IndoorWorld::
-isFloorAbove(Entity *e)
-{
-    for (unsigned int i = 0; i < floor.size(); i++) {
-        if (floor[i][0] + INDOOR_FLOOR_HEIGHTT - 100 > e->loc.y)
-            return (i + 1) != floor.size();
-    }
-    return false;
-}
-
-bool IndoorWorld::
-isFloorBelow(Entity *e)
-{
-    for (unsigned int i = 0; i < floor.size(); i++) {
-        if (floor[i][0] + INDOOR_FLOOR_HEIGHTT - 100 > e->loc.y)
-            return i > 0;
-    }
-    return false;
-}
-
-void IndoorWorld::
-singleDetect(Entity *e)
-{
-    unsigned int floornum = 0;
-    float start, end;
-
-    if (!e->isAlive())
-        return;
-
-    for (; floornum < floor.size(); floornum++) {
-        if (floor[floornum][0] + INDOOR_FLOOR_HEIGHTT - 100 > e->loc.y) {
-            if (e->loc.y < floor[floornum][0]) {
-                e->loc.y = floor[floornum][0];
-                e->vel.y = 0;
-                e->ground = true;
-            }
-            break;
-        }
-    }
-
-    if (e->vel.y > -2)
-        e->vel.y -= GRAVITY_CONSTANT * game::time::getDeltaTime();
-
-    if (e->ground) {
-        e->loc.y = ceil(e->loc.y);
-        e->vel.y = 0;
-    }
-
-    start = worldStart + HLINES(fstart[floornum]);
-    end = start + HLINES(floor[floornum].size());
-
-    if (e->loc.x < start) {
-        e->vel.x = 0;
-        e->loc.x = start + game::HLINE / 2;
-    } else if (e->loc.x + e->width + game::HLINE > end) {
-        e->vel.x = 0;
-        e->loc.x = end - e->width - game::HLINE;
-    }
-
-}
-
-void IndoorWorld::
-draw(Player *p)
-{
-       unsigned int i,fl;
-       int x;
-
-    auto SCREEN_WIDTH = game::SCREEN_WIDTH;
-    auto SCREEN_HEIGHT = game::SCREEN_HEIGHT;
-    auto HLINE = game::HLINE;
-
-    // draw lights
-    for (auto &l : light) {
-        if (l.belongsTo) {
-            l.loc.x = l.following->loc.x + SCREEN_WIDTH / 2;
-            l.loc.y = (l.following->loc.y > SCREEN_HEIGHT / 2) ? SCREEN_HEIGHT / 2 : l.following->loc.y;
-        }
-        if (l.flame) {
-            l.fireFlicker = .9 + ((rand() % 2) / 10.0f);
-            l.fireLoc.x = l.loc.x + (rand() % 2 - 1) * 3;
-            l.fireLoc.y = l.loc.y + (rand() % 2 - 1) * 3;
-        } else
-            l.fireFlicker = 1.0f;
-    }
-
-/*    std::unique_ptr<GLfloat[]> pointArrayBuf = std::make_unique<GLfloat[]> (2 * (light.size()));
-       auto pointArray = pointArrayBuf.get();
-    GLfloat flameArray[64];
-
-       for (i = 0; i < light.size(); i++) {
-        if (light[i].flame) {
-               pointArray[2 * i    ] = light[i].fireLoc.x - offset.x;
-               pointArray[2 * i + 1] = light[i].fireLoc.y;
-        }else{
-            pointArray[2 * i    ] = light[i].loc.x - offset.x;
-            pointArray[2 * i + 1] = light[i].loc.y;
-        }
-       }
-
-    for(i = 0; i < light.size(); i++) {
-        flameArray[i] = light[i].fireFlicker;
-    }
-
-       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-
-       glUseProgram(shaderProgram);
-       glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
-       glUniform1f(glGetUniformLocation(shaderProgram, "amb"), 0.02f + light.size()/50.0f);
-
-       if (light.empty())
-               glUniform1i(glGetUniformLocation(shaderProgram, "numLight"), 0);
-       else {
-               glUniform1i (glGetUniformLocation(shaderProgram, "numLight"), light.size());
-               glUniform2fv(glGetUniformLocation(shaderProgram, "lightLocation"), light.size(), pointArray);
-               glUniform3f (glGetUniformLocation(shaderProgram, "lightColor"), 1.0f, 1.0f, 1.0f);
-        glUniform1fv(glGetUniformLocation(shaderProgram, "fireFlicker"), light.size(), flameArray);
-       }
-*/
-
-       Render::worldShader.use();
-
-       glActiveTexture(GL_TEXTURE0);
-       //game::engine.getSystem<WorldSystem>bgTex(0);
-
-       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //for the s direction
-       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //for the t direction
-
-       glUniform1i(Render::worldShader.uniform[WU_texture], 0);
-       glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0);
-
-       GLfloat backTile[] = {worldStart - SCREEN_WIDTH / 2,    0,                                                                      9.9,
-                                                 -worldStart + SCREEN_WIDTH / 2,       0,                                                                      9.9,
-                                                 -worldStart + SCREEN_WIDTH / 2,       static_cast<float>(SCREEN_HEIGHT),      9.9,
-
-                                                 -worldStart + SCREEN_WIDTH / 2,       static_cast<float>(SCREEN_HEIGHT),      9.9,
-                                                 worldStart - SCREEN_WIDTH / 2,        static_cast<float>(SCREEN_HEIGHT),      9.9,
-                                                 worldStart - SCREEN_WIDTH / 2,        0,                                                                      9.9};
-
-       GLfloat backTile_tex[] = {0, 1,
-                                                         (-worldStart*2+SCREEN_WIDTH)/512, 1,
-                                                         (-worldStart*2+SCREEN_WIDTH)/512, 0,
-
-                                                         (-worldStart*2+SCREEN_WIDTH)/512, 0,
-                                                         0, 0,
-                                                         0, 1};
-
-       makeWorldDrawingSimplerEvenThoughAndyDoesntThinkWeCanMakeItIntoFunctions_JustDrawThis(0, backTile, backTile_tex, 6);
-
-       glUseProgram(0);
-
-       /*
-        *      Draw the ground.
-       */
-
-       // TODO make floor texture
-
-       static GLuint floorTex = Texture::genColor(Color(150, 100, 50));
-       glBindTexture(GL_TEXTURE_2D, floorTex);
-
-       Render::worldShader.use();
-       Render::useShader(&Render::worldShader);
-
-       for (fl = 0; fl < floor.size(); fl++) {
-        i = 0;
-       for (const auto &h : floor[fl]) {
-               x = worldStart + HLINES(fstart[fl] + i);
-
-                       Render::drawRect(vec2 {(float)x, h}, vec2 {(float)(x + HLINE), h - INDOOR_FLOOR_THICKNESS}, -3.0f);
-
-                       i++;
-       }
-    }
-
-       Render::worldShader.unuse();
-
-       /*
-        *      Draw all entities.
-       */
-
-       // TODO draw particles
-       // glBindTexture(GL_TEXTURE_2D, colorIndex);
-
-
-       /*for (auto &part : particles)
-               part.draw();*/
-
-       for (auto &e : entity)
-               e->draw();
-
-       p->draw();
-}
-
 Arena::Arena(void)
 {
        generate(800);
@@ -1076,7 +851,6 @@ loadWorldFromXMLNoSave(std::string path) {
 
        World *tmp;
        Entity *newEntity;
-       float spawnx;
        bool Indoor;
 
        const char *ptr;
@@ -1113,7 +887,7 @@ loadWorldFromXMLNoSave(std::string path) {
     else if ((wxml = _currentXMLDoc->FirstChildElement("IndoorWorld"))) {
                wxml = wxml->FirstChildElement();
                vil = NULL;
-               tmp = new IndoorWorld();
+               tmp = new World(true);
         Indoor = true;
        }
 
@@ -1198,6 +972,10 @@ loadWorldFromXMLNoSave(std::string path) {
             }
                }
 
+               else if (name == "floor" && tmp->isIndoor()) {
+                       tmp->generate(wxml->UnsignedAttribute("width") / game::HLINE);
+               }
+
                // weather tags
                else if (name == "weather") {
                        game::engine.getSystem<WorldSystem>()->setWeather(wxml->GetText());
@@ -1245,14 +1023,6 @@ loadWorldFromXMLNoSave(std::string path) {
             game::time::setTickCount(std::stoi(wxml->GetText()));
         }
 
-               // floor adding
-               else if (Indoor && name == "floor") {
-            if (wxml->QueryFloatAttribute("start",&spawnx) == XML_NO_ERROR)
-                Indoorp(tmp)->addFloor(wxml->UnsignedAttribute("width"), spawnx);
-            else
-                Indoorp(tmp)->addFloor(wxml->UnsignedAttribute("width"));
-        }
-
                if (newEntity != nullptr) {
                        //bool alive = true;
                        //if (wxml->QueryBoolAttribute("alive", &alive) != XML_NO_ERROR || alive) {
@@ -1278,7 +1048,6 @@ loadWorldFromXMLNoSave(std::string path) {
                        //}
                }
 
-        spawnx = 0;
                wxml = wxml->NextSiblingElement();
        }
 
@@ -1745,63 +1514,65 @@ void WorldSystem::render(void)
     Render::worldShader.disable();
        Render::worldShader.unuse();
 
-       bgTex++;
-    safeSetColorA(255, 255, 255, 255);
-
-    c.clear();
-    std::vector<GLfloat> grassc;
-    std::vector<GLfloat> grasst;
+       if (!world->isIndoor()) {
+               bgTex++;
+           safeSetColorA(255, 255, 255, 255);
 
-       for (int i = iStart; i < iEnd; i++) {
-        auto wd = worldData[i];
-        auto gh = wd.grassHeight;
+           c.clear();
+           std::vector<GLfloat> grassc;
+           std::vector<GLfloat> grasst;
 
-               // flatten the grass if the player is standing on it.
-       if (!wd.grassUnpressed) {
-               gh[0] /= 4;
-                       gh[1] /= 4;
-               }
+               for (int i = iStart; i < iEnd; i++) {
+               auto wd = worldData[i];
+               auto gh = wd.grassHeight;
 
-               // actually draw the grass.
-        if (wd.groundHeight) {
-            c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i)            , wd.groundHeight + gh[0],            -3)));
-            c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[0],            -3)));
-            c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT,     -3)));
+                       // flatten the grass if the player is standing on it.
+                       if (!wd.grassUnpressed) {
+                               gh[0] /= 4;
+                               gh[1] /= 4;
+                       }
 
-            c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT,     -3)));
-            c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + HLINES(i)               , wd.groundHeight - GRASS_HEIGHT,  -3)));
-            c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i)            , wd.groundHeight + gh[0],                    -3)));
+                       // actually draw the grass.
+               if (wd.groundHeight) {
+                   c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i)            , wd.groundHeight + gh[0],             -3)));
+                   c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[0],             -3)));
+                   c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT,      -3)));
 
-            c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[1],                    -3)));
-            c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight + gh[1],                    -3)));
-            c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight - GRASS_HEIGHT,     -3)));
+               c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT,  -3)));
+                   c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + HLINES(i)                , wd.groundHeight - GRASS_HEIGHT,  -3)));
+                   c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i)            , wd.groundHeight + gh[0],                     -3)));
 
-            c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight - GRASS_HEIGHT,     -3)));
-            c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT,     -3)));
-            c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[1],                    -3)));
-        }
-       }
+                   c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[1],                     -3)));
+                   c.push_back(std::make_pair(vec2(1, 0),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight + gh[1],                     -3)));
+                   c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight - GRASS_HEIGHT,      -3)));
 
-    for (auto &v : c) {
-        grassc.push_back(v.second.x);
-        grassc.push_back(v.second.y);
-        grassc.push_back(v.second.z);
+               c.push_back(std::make_pair(vec2(1, 1),vec3(worldStart + HLINES(i) + HLINE    , wd.groundHeight - GRASS_HEIGHT,  -3)));
+                   c.push_back(std::make_pair(vec2(0, 1),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight - GRASS_HEIGHT,      -3)));
+                   c.push_back(std::make_pair(vec2(0, 0),vec3(worldStart + HLINES(i) + HLINE / 2, wd.groundHeight + gh[1],                     -3)));
+               }
+               }
 
-        grasst.push_back(v.first.x);
-        grasst.push_back(v.first.y);
-    }
+           for (auto &v : c) {
+               grassc.push_back(v.second.x);
+               grassc.push_back(v.second.y);
+               grassc.push_back(v.second.z);
+       
+               grasst.push_back(v.first.x);
+           grasst.push_back(v.first.y);
+           }
 
-    Render::worldShader.use();
-       glUniform1f(Render::worldShader.uniform[WU_light_impact], 1.0f);
+           Render::worldShader.use();
+               glUniform1f(Render::worldShader.uniform[WU_light_impact], 1.0f);
 
-    Render::worldShader.enable();
+           Render::worldShader.enable();
 
-    glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 0, &grassc[0]);
-    glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0, &grasst[0]);
-    glDrawArrays(GL_TRIANGLES, 0 , c.size());
+           glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 0, &grassc[0]);
+           glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0, &grasst[0]);
+           glDrawArrays(GL_TRIANGLES, 0 , c.size());
 
-    Render::worldShader.disable();
-       Render::worldShader.unuse();
+       Render::worldShader.disable();
+               Render::worldShader.unuse();
+       }
 
        player->draw();
 }
@@ -1809,23 +1580,12 @@ void WorldSystem::render(void)
 void WorldSystem::setWorld(World *w)
 {
        world = w;
-       
-       for (const auto &s : bgPaths[0])
+
+       bgFiles.clear();
+       for (const auto &s : bgPaths[(int)w->bgType])
                bgFiles.push_back(w->styleFolder + s);
-       for (const auto &s : bgPaths[1])
-               bgFilesIndoors.push_back(w->styleFolder + s);
 
-       switch (w->bgType) {
-       case WorldBGType::Forest:
-               bgTex = TextureIterator(bgFiles);
-               break;
-       case WorldBGType::WoodHouse:
-               bgTex = TextureIterator(bgFilesIndoors);
-               break;
-    default:
-        UserError("Invalid world background type");
-        break;
-       }
+       bgTex = TextureIterator(bgFiles);
 }
 
 
@@ -1855,6 +1615,19 @@ void WorldSystem::setWeather(const std::string &s)
        weather = WorldWeather::None;
 }
 
+void WorldSystem::enterWorld(World *w)
+{
+       if (w != nullptr) {
+               outside = world;
+               world = w;
+       }
+}
+
+void WorldSystem::leaveWorld(void)
+{
+       world = outside;
+} 
+
 void WorldSystem::singleDetect(Entity *e, entityx::TimeDelta dt)
 {
        std::string killed;
index fd14db3042a55e0f3501637be7ba1ddf925827c7..12cc438aa10ed32bb3d788d5db76c5905abc2a44 100644 (file)
@@ -4,8 +4,8 @@
     <generation type="Random" width="1600"/>
     <time>6000</time>
     <spawnx>-300</spawnx>
-    <npc name="Sanc" hasDialog="true" health="1" x="-46.236156" y="62.098995" dindex="9999"/>
-    <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="271.72144" y="74.999023" dindex="0"/>
+    <npc name="Sanc" hasDialog="true" health="1" x="23.971899" y="59.998001" dindex="9999"/>
+    <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="308.18121" y="60.597992" dindex="0"/>
     <structure type="1" spawnx="300" alive="1"/>
     <structure inside="bobshouse.xml" type="1" spawnx="10" alive="1"/>
     <chest alive="1"/>