]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
fixed quest menu, only entity vector in worlds
authorClyne Sullivan <tullivan99@gmail.com>
Sat, 2 Jul 2016 14:11:45 +0000 (10:11 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Sat, 2 Jul 2016 14:11:45 +0000 (10:11 -0400)
brice.dat
include/coolarray.hpp
include/ui_quest.hpp
src/entities.cpp
src/inventory.cpp
src/ui.cpp
src/world.cpp
xml/!town.xml

index 4dad7115c21edf220ed1e407b1d7f9f20b430ea0..2033bae64b8c312af83dfe1243c6508df9c542aa 100644 (file)
--- a/brice.dat
+++ b/brice.dat
@@ -1,7 +1,7 @@
 3
-Slow
-0
-canJump
-0
 canSprint
 1
+canJump
+0
+Slow
+0
index 5388aab04a64d53db704a081a470d49916f48a46..be221b8133922dbd0d4d4bc696d1066c8deeb822 100644 (file)
@@ -16,7 +16,13 @@ public:
                _capacity = 0;
        }
 
-       CoolArray(size_t n, const T& value=0) {
+       CoolArray(size_t n) {
+               buffer = new T[n];
+               _size = 0;
+               _capacity = n;
+       }
+
+       CoolArray(size_t n, const T& value) {
                buffer = new T[n];
                _size = n;
                _capacity = n;
@@ -41,6 +47,11 @@ public:
                std::copy(a.begin(), a.end(), buffer);
        }
 
+       void operator+=(std::initializer_list<T> n) {
+               for (const auto &e : n)
+                       push_back(e);
+       }
+
        template<class Func>
        void remove_if(Func f) {
                for (size_t i = 0; i < _size; ++i) {
@@ -73,6 +84,10 @@ public:
                _capacity = 0;
        }
 
+       void reset(void) {
+               _size = 0;
+       }
+
        size_t size(void) const {
                return _size;
        }
@@ -81,6 +96,10 @@ public:
                return _capacity;
        }
 
+       T* data(void) {
+               return buffer;
+       }
+
        T& front(void) {
                return buffer[0];
        }
index a0f3ad43c09891b6c8e0ca27424ffda1410c7edb..24a5e1b51d05e173d24f0fc60f567ef337f014ab 100644 (file)
@@ -13,9 +13,13 @@ namespace ui {
                }
 
                void draw(void) {
+                       static unsigned int textWrap = 40;
+
                        if (!_toggle)
                                return;
 
+                       std::swap(textWrap, ui::textWrapLimit);
+
                        float top_y = offset.y + 200;
                        ui::drawNiceBox(vec2 {offset.x - 200, top_y },
                                        vec2 {offset.x + 200, offset.y - 200 },
@@ -31,6 +35,8 @@ namespace ui {
                                ui::putText(x + 40, y, q.desc.c_str());
                                y -= 40; 
                        }
+
+                       std::swap(textWrap, ui::textWrapLimit);
                }
        }
 }
index 53d3acae9d8132b92af607f7d6b5999f91161ed3..b93d1f0ddef1eaa43375ab874e4fc40f07beea73 100644 (file)
@@ -697,7 +697,7 @@ COMMONAIFUNC:
                                do {
                                        // assign quest
                                        if (!(qname = oxml->StrAttribute("assign")).empty())
-                                               player->qh.assign(qname, "None", std::string(oxml->GetText())); // TODO add descriptions
+                                               player->qh.assign(qname, oxml->StrAttribute("desc"), (oxml->GetText() == nullptr) ? "" : oxml->GetText());
 
                                        // check / finish quest
                                        else if (!(qname = oxml->StrAttribute("check")).empty()) {
@@ -1038,11 +1038,7 @@ void Particles::draw(GLfloat*& p) const
 {
        vec2 tc = vec2(0.25f * index.x, 0.125f * (8.0f - index.y));
 
-    float z = 0.9;
-       if (behind)
-               z = 2.0;
-
-       z += zOffset;
+       float z = (behind ? 2.0f : 0.9f) + zOffset;
 
        // lower left
     *(p++) = loc.x;
index 7e8c94ea07d701b2a5121b731507c2e87741fea7..48adb867b59ce78b9bd3fc0437ed5b7c71fd25a3 100644 (file)
@@ -342,12 +342,8 @@ void Inventory::draw(void) {
                return sum / v.size();
        };
 
-       ui::fontTransInv = 255 * (averagef(dfp) / range);
-       if (ui::fontTransInv > 255)
-               ui::fontTransInv = 255;
-       else if (ui::fontTransInv < 0)
-               ui::fontTransInv = 0;
-
+       ui::fontTransInv = std::clamp(255 * (averagef(dfp) / range), 0ul, 255ul);
+       
        if (invOpening) {
                for (auto &d : dfp) {
                        if (!a || dfp[a - 1] > 50)
index 098f6505b592b0712b88a4d95c75de0007d1566c..2d7f8bc993b40274d0c9b3a9c335cbf66a518d5a 100644 (file)
@@ -543,7 +543,6 @@ namespace ui {
                std::unique_ptr<char[]> printfbuf (new char[512]);
 
                textWrapLimit = game::SCREEN_WIDTH - HLINES(20);
-               std::cout << textWrapLimit << '\n';     
                dialogPassive = passive;
 
                // add speaker prefix
index 52e197ccc4817415655cbc686c6a2df0782706fc..e43318f8191c99dfe47a716daa779be950d7308a 100644 (file)
@@ -513,11 +513,8 @@ void World::draw(Player *p)
 
        uint ls = light.size();
 
-       GLfloat *lightCoords = new GLfloat[ls * 4];
-       GLfloat *lightColors = new GLfloat[ls * 4];
-
-       uint lpIndex = 0;
-       uint lcIndex = 0;
+       CoolArray<GLfloat> lightCoords (ls * 4);
+       CoolArray<GLfloat> lightColors (ls * 4);
 
        for (uint i = 0; i < ls; i++) {
                auto &l = light[i];
@@ -533,21 +530,14 @@ void World::draw(Player *p)
             l.fireFlicker = 1;
         }
 
-               lightCoords[lpIndex++] = l.loc.x;
-               lightCoords[lpIndex++] = l.loc.y;
-               lightCoords[lpIndex++] = 0.0;
-               lightCoords[lpIndex++] = l.radius;
-
-               lightColors[lcIndex++] = l.color.red;
-               lightColors[lcIndex++] = l.color.green;
-               lightColors[lcIndex++] = l.color.blue;
-               lightColors[lcIndex++] = 1.0;
+               lightCoords += {l.loc.x, l.loc.y, 0.0, l.radius};
+               lightColors += {l.color.red, l.color.green, l.color.blue, 1.0};
        }
 
        glUseProgram(worldShader);
 
-       glUniform4fv(worldShader_uniform_light, ls, lightCoords);
-       glUniform4fv(worldShader_uniform_light_color, ls, lightColors);
+       glUniform4fv(worldShader_uniform_light, ls, lightCoords.data());
+       glUniform4fv(worldShader_uniform_light_color, ls, lightColors.data());
        glUniform1i(worldShader_uniform_light_amt, ls);
 
        glUseProgram(0);
@@ -566,7 +556,9 @@ void World::draw(Player *p)
 
     // draw the dirt
     bgTex++;
-    std::vector<std::pair<vec2,vec3>> c;
+    
+       CoolArray<GLfloat> dirtc (12 * SCREEN_WIDTH);
+    CoolArray<GLfloat> dirtt (12 * SCREEN_WIDTH);
 
     for (int i = iStart; i < iEnd; i++) {
         if (worldData[i].groundHeight <= 0) { // TODO holes (andy)
@@ -576,104 +568,63 @@ void World::draw(Player *p)
             safeSetColorA(150, 150, 150, 255);
         }
 
-        int ty = worldData[i].groundHeight / 64 + worldData[i].groundColor;
-        // glTexCoord2i(0, 0);  glVertex2i(worldStart + i * HLINE         , worldData[i].groundHeight - GRASS_HEIGHT);
-        // glTexCoord2i(1, 0);  glVertex2i(worldStart + i * HLINE + HLINE , worldData[i].groundHeight - GRASS_HEIGHT);
-        // glTexCoord2i(1, ty); glVertex2i(worldStart + i * HLINE + HLINE, 0);
-        // glTexCoord2i(0, ty); glVertex2i(worldStart + i * HLINE            , 0);
+        float ty = floor(worldData[i].groundHeight / 64 + worldData[i].groundColor);
 
-               c.push_back(std::make_pair(vec2(0, 0), vec3(worldStart + HLINES(i),         worldData[i].groundHeight - GRASS_HEIGHT, -4.0f)));
-        c.push_back(std::make_pair(vec2(1, 0), vec3(worldStart + HLINES(i) + HLINE, worldData[i].groundHeight - GRASS_HEIGHT, -4.0f)));
-        c.push_back(std::make_pair(vec2(1, ty),vec3(worldStart + HLINES(i) + HLINE, 0,                                        -4.0f)));
+               dirtc += {worldStart + HLINES(i), worldData[i].groundHeight - GRASS_HEIGHT, -4.0f,
+                         worldStart + HLINES(i + 1), worldData[i].groundHeight - GRASS_HEIGHT, -4.0f,
+                         worldStart + HLINES(i + 1), 0, -4.0f,
+                         worldStart + HLINES(i + 1), 0, -4.0f,
+                         worldStart + HLINES(i), 0, -4.0f,
+                         worldStart + HLINES(i), worldData[i].groundHeight - GRASS_HEIGHT, -4.0f};
 
-        c.push_back(std::make_pair(vec2(1, ty),vec3(worldStart + HLINES(i) + HLINE, 0,                                        -4.0f)));
-        c.push_back(std::make_pair(vec2(0, ty),vec3(worldStart + HLINES(i),         0,                                        -4.0f)));
-        c.push_back(std::make_pair(vec2(0, 0), vec3(worldStart + HLINES(i),         worldData[i].groundHeight - GRASS_HEIGHT, -4.0f)));
+               dirtt += {0, 0, 1, 0, 1, ty, 1, ty, 0, ty, 0, 0};
 
         if (worldData[i].groundHeight == GROUND_HEIGHT_MINIMUM - 1)
             worldData[i].groundHeight = 0;
     }
 
-    std::vector<GLfloat> dirtc;
-    std::vector<GLfloat> dirtt;
-
-    for (auto &v : c) {
-        dirtc.push_back(v.second.x);
-        dirtc.push_back(v.second.y);
-        dirtc.push_back(v.second.z);
-
-        dirtt.push_back(v.first.x);
-        dirtt.push_back(v.first.y);
-    }
-
     glUseProgram(worldShader);
        glUniform1f(worldShader_uniform_light_impact, 0.45f);
 
-       makeWorldDrawingSimplerEvenThoughAndyDoesntThinkWeCanMakeItIntoFunctions_JustDrawThis(0, &dirtc[0], &dirtt[0], c.size());
+       makeWorldDrawingSimplerEvenThoughAndyDoesntThinkWeCanMakeItIntoFunctions_JustDrawThis(0, dirtc.data(), dirtt.data(), dirtc.size());
 
     glUseProgram(0);
-
-
-       //glEnd();
-
-       //glUseProgram(0);
-
-       // draw the grass
-       //glEnable(GL_TEXTURE_2D);
-       //glActiveTexture(GL_TEXTURE0);
+       
        bgTex++;
-       //glUseProgram(shaderProgram);
-       //glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0);
     safeSetColorA(255, 255, 255, 255);
 
-    c.clear();
-    std::vector<GLfloat> grassc;
-    std::vector<GLfloat> grasst;
+    CoolArray<GLfloat> grassc (24 * SCREEN_WIDTH);
+    CoolArray<GLfloat> grasst (24 * SCREEN_WIDTH);
 
        for (int i = iStart; i < iEnd; i++) {
         auto wd = worldData[i];
         auto gh = wd.grassHeight;
 
                // flatten the grass if the player is standing on it.
-       if (!wd.grassUnpressed) {
-               gh[0] /= 4;
+               if (!wd.grassUnpressed) {
+                       gh[0] /= 4;
                        gh[1] /= 4;
                }
 
                // 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(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)));
+                       float x = worldStart + HLINES(i);
 
+                       grassc += {x, wd.groundHeight + gh[0], -3, x + HLINE / 2, wd.groundHeight + gh[0], -3,
+                                  x + HLINE / 2, wd.groundHeight - GRASS_HEIGHT, -3, x + HLINE / 2, wd.groundHeight - GRASS_HEIGHT, -3,
+                                  x, wd.groundHeight - GRASS_HEIGHT, -3, x, wd.groundHeight + gh[0], -3,
+                                  x + HLINE / 2, wd.groundHeight + gh[1], -3, x + HLINE, wd.groundHeight + gh[1], -3,
+                                  x + HLINE, wd.groundHeight - GRASS_HEIGHT, -3, x + HLINE, wd.groundHeight - GRASS_HEIGHT, -3,
+                                  x + HLINE / 2, wd.groundHeight - GRASS_HEIGHT, -3, x + 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)));
-
-            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 += {0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0};
         }
        }
 
-    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);
-    }
-
     glUseProgram(worldShader);
        glUniform1f(worldShader_uniform_light_impact, 1.0f);
 
-       makeWorldDrawingSimplerEvenThoughAndyDoesntThinkWeCanMakeItIntoFunctions_JustDrawThis(0, &grassc[0], &grasst[0], c.size());
+       makeWorldDrawingSimplerEvenThoughAndyDoesntThinkWeCanMakeItIntoFunctions_JustDrawThis(0, grassc.data(), grasst.data(), grassc.size());
 
     glUseProgram(0);
 
index 51fc08db9ef58ed0c1dd0feea4d7ff58fa274f50..e824ef79e9e97e1faa7cf7197a8120ad029450c7 100644 (file)
@@ -4,8 +4,8 @@
     <generation type="Random" width="1600"/>
     <time>6000</time>
     <spawnx>-300</spawnx>
-    <npc name="Sanc" hasDialog="true"/>
-    <npc name="Bob" hasDialog="true" spawnx="30"/>
+    <npc name="Sanc" hasDialog="true" health="1" x="124.68252" y="61.799011" dindex="0"/>
+    <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="223.94865" y="63.39901" dindex="9999"/>
     <structure type="1" spawnx="300" alive="1"/>
     <structure inside="bobshouse.xml" type="1" spawnx="10" alive="1"/>
     <chest alive="1"/>