diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2016-06-09 08:49:21 -0400 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2016-06-09 08:49:21 -0400 |
commit | 1e9f6aaddb2d21045f5e7dc63d6312a4407b3a08 (patch) | |
tree | 0d30324ce93301a4ab4ca3360c8a227249d4f468 | |
parent | 22882f01ed537cae28b2ce80b86264a9c9c52b00 (diff) |
Fixed particle crashing
-rw-r--r-- | brice.dat | 5 | ||||
-rw-r--r-- | include/entities.hpp | 1 | ||||
-rw-r--r-- | src/world.cpp | 31 | ||||
-rw-r--r-- | xml/playerSpawnHill1.xml | 21 | ||||
-rw-r--r-- | xml/playerSpawnHill1_Building1.xml | 6 |
5 files changed, 39 insertions, 25 deletions
@@ -0,0 +1,5 @@ +2 +canSprint +0 +canJump +0 diff --git a/include/entities.hpp b/include/entities.hpp index 826b0f6..605cc77 100644 --- a/include/entities.hpp +++ b/include/entities.hpp @@ -17,6 +17,7 @@ #include <inventory.hpp> #include <texture.hpp> #include <save_util.hpp> +#include <coolarray.hpp> // local library includes #include <tinyxml2.h> diff --git a/src/world.cpp b/src/world.cpp index 5809ab8..a36a9b8 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -9,6 +9,7 @@ #include <sstream> #include <fstream> #include <memory> +#include <mutex> // local game headers #include <ui.hpp> @@ -30,6 +31,9 @@ extern World *currentWorldToRight; // main.cpp extern bool inBattle; // ui.cpp? extern std::string xmlFolder; +// particle mutex +std::mutex partMutex; + // externally referenced in main.cpp int worldShade = 0; @@ -776,22 +780,23 @@ void World::draw(Player *p) glEnableVertexAttribArray(worldShader_attribute_coord); glEnableVertexAttribArray(worldShader_attribute_tex); - uint ps = particles.size(); + partMutex.lock(); + uint ps = particles.size(); uint pss = ps * 6 * 5; uint pc = 0; std::vector<GLfloat> partVec(pss); - GLfloat *pIndex = &partVec[0]; - - for (const auto &p : particles) { + auto *pIndex = &partVec[0]; + for (uint i = 0; i < ps; i++) { pc += 30; if (pc > pss) { // TODO resize the vector or something better than breaking - //std::cout << "Whoops:" << pc << "," << partVec.size() << std::endl; + std::cout << "Whoops:" << pc << "," << partVec.size() << std::endl; break; } - p.draw(pIndex); + particles[i].draw(pIndex); } + partMutex.unlock(); glVertexAttribPointer(worldShader_attribute_coord, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &partVec[0]); glVertexAttribPointer(worldShader_attribute_tex, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), &partVec[3]); @@ -802,7 +807,7 @@ void World::draw(Player *p) glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.0); - glUseProgram(0); + glUseProgram(0); } /** @@ -936,6 +941,8 @@ detect(Player *p) singleDetect(e); //std::thread(&World::singleDetect, this, e).detach(); + // qwertyuiop + partMutex.lock(); // handle particles for (auto &part : particles) { // get particle's current world line @@ -983,6 +990,7 @@ detect(Player *p) break; } } + partMutex.unlock(); // draws the village welcome message if the player enters the village bounds for (auto &v : village) { @@ -1033,15 +1041,16 @@ update(Player *p, unsigned int delta, unsigned int ticks) e->loc.y += e->vel.y * delta; } } - // iterate through particles + partMutex.lock(); + // iterate through particles particles.remove_if([](const Particles &part) { return part.duration <= 0; }); for (auto &pa : particles) { if (pa.canMove) { // causes overhead - pa.loc.y += pa.vel.y * delta; - pa.loc.x += pa.vel.x * delta; + pa.loc.y += pa.vel.y * game::time::getDeltaTime(); + pa.loc.x += pa.vel.x * game::time::getDeltaTime(); if (pa.stu != nullptr) { if (pa.loc.x >= pa.stu->loc.x && pa.loc.x <= pa.stu->loc.x + pa.stu->width && @@ -1050,7 +1059,7 @@ update(Player *p, unsigned int delta, unsigned int ticks) } } } - + partMutex.unlock(); // handle music fades if (!Mix_PlayingMusic()) Mix_FadeInMusic(bgmObj, -1, 2000); diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index d7889fc..f16b511 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -5,13 +5,13 @@ <link right="playerSpawnHill2.xml"/> <time>12000</time> <hill peakx="0" peaky="1000" width="50"/> - <rabbit spawnx="300" aggressive="false" maxHealth="100"/> - <bird spawny="500"/> - <cat/> + <rabbit spawnx="300" aggressive="false" maxHealth="100" health="50"/> + <bird spawny="500" x="-534.19525" y="712.36743" health="1"/> + <cat x="-48.600014" y="64.996986" alive="1"/> <!--<trigger x="-300" id="Test"/>--> - <npc name="Ralph" hasDialog="true" spawnx="300"/> - <npc name="Johnny" hasDialog="false" spawnx="300"/> - <npc name="Big Dave" hasDialog="true" spawnx="300"/> + <npc name="Ralph" hasDialog="true" spawnx="300" health="1" x="-22.480118" y="64.996986" dindex="0"/> + <npc name="Johnny" hasDialog="false" spawnx="300" health="1" x="639.87152" y="68.796982" dindex="9999"/> + <npc name="Big Dave" hasDialog="true" spawnx="300" health="1" x="794.33545" y="69.796974" dindex="0"/> <page spawnx="-200" id="assets/pages/gootaGoFast.png" cid="canSprint" cvalue="1"/> <page spawnx="-500" id="assets/pages/gootaJump.png" cid="canJump" cvalue="1"/> <village name="Big Dave's bagel emporium! The greatest place on earth!"> @@ -37,15 +37,14 @@ And it wasn't stormy. <Dialog name="Ralph"> <text id="0" nextid="1"> - Hello there! My name is Ralph. - <gotox>300</gotox> + Hello there! My name is Ralph. <gotox>300</gotox> </text> <text id="1" nextid="2" call="Johnny" callid="0" pause="true"> You should go talk to my friend Johnny. He's a pretty chill dude. </text> <text id="2"> Niice. - <quest check="Your First Quest" fail="3"/></text> + <quest check="Your First Quest" fail="3"/></text> <text id="3"> Go check out Johnny. He's cool. </text> @@ -54,7 +53,7 @@ And it wasn't stormy. <Dialog name="Johnny"> <text id="0" nextid="1" pause="true"> Sup bro! Have a quest. To complete it, just go talk to Ralph again. - <quest assign="Your First Quest"> + <quest assign="Your First Quest"> Dank MayMay,2 Wood Sword,1 </quest> @@ -68,5 +67,5 @@ And it wasn't stormy. <text id="0" pause="true"> Hey friend! It's dangerous out there, here take these! Wait, promise you'll stop by my stand in the local market! - <give id="Wood Sword" count="1"/> <give id="Hunters Bow" count="1"/> <give id="Crude Arrow" count="110"/> <give id="Fried Chicken" count="1"/> <give id="Mossy Torch" count="1"/></text> + <give id="Wood Sword" count="1"/> <give id="Hunters Bow" count="1"/> <give id="Crude Arrow" count="110"/> <give id="Fried Chicken" count="1"/> <give id="Mossy Torch" count="1"/></text> </Dialog> diff --git a/xml/playerSpawnHill1_Building1.xml b/xml/playerSpawnHill1_Building1.xml index 800f007..eb63d7b 100644 --- a/xml/playerSpawnHill1_Building1.xml +++ b/xml/playerSpawnHill1_Building1.xml @@ -10,17 +10,17 @@ <Dialog name="Bob"> <text id="0" nextid="1" pause="true"> Hey. Have a Dank MayMay :) - <give id="Dank MayMay" count="1"/></text> + <give id="Dank MayMay" count="1"/></text> <text id="1" nextid="2"> What? You want another Dank MayMay? </text> <text id="2" nextid="3" pause="true"> K. - <give id="Dank MayMay" count="1"/></text> + <give id="Dank MayMay" count="1"/></text> <text id="3" nextid="4"> Well... I'm out of Dank MayMays. </text> <text id="4"> Have a sword though. - <give id="Wood Sword" count="1"/></text> + <give id="Wood Sword" count="1"/></text> </Dialog> |