diff options
-rw-r--r-- | brice.dat | 8 | ||||
-rw-r--r-- | include/coolarray.hpp | 21 | ||||
-rw-r--r-- | include/ui_quest.hpp | 6 | ||||
-rw-r--r-- | src/entities.cpp | 8 | ||||
-rw-r--r-- | src/inventory.cpp | 8 | ||||
-rw-r--r-- | src/ui.cpp | 1 | ||||
-rw-r--r-- | src/world.cpp | 113 | ||||
-rw-r--r-- | xml/!town.xml | 4 |
8 files changed, 68 insertions, 101 deletions
@@ -1,7 +1,7 @@ 3 -Slow -0 -canJump -0 canSprint 1 +canJump +0 +Slow +0 diff --git a/include/coolarray.hpp b/include/coolarray.hpp index 5388aab..be221b8 100644 --- a/include/coolarray.hpp +++ b/include/coolarray.hpp @@ -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]; } diff --git a/include/ui_quest.hpp b/include/ui_quest.hpp index a0f3ad4..24a5e1b 100644 --- a/include/ui_quest.hpp +++ b/include/ui_quest.hpp @@ -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); } } } diff --git a/src/entities.cpp b/src/entities.cpp index 53d3aca..b93d1f0 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -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; diff --git a/src/inventory.cpp b/src/inventory.cpp index 7e8c94e..48adb86 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -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) @@ -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 diff --git a/src/world.cpp b/src/world.cpp index 52e197c..e43318f 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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); diff --git a/xml/!town.xml b/xml/!town.xml index 51fc08d..e824ef7 100644 --- a/xml/!town.xml +++ b/xml/!town.xml @@ -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"/> |