]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Fixed particle crashing
authordrumsetmonkey <abelleisle@roadrunner.com>
Thu, 9 Jun 2016 12:49:21 +0000 (08:49 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Thu, 9 Jun 2016 12:49:21 +0000 (08:49 -0400)
brice.dat
include/entities.hpp
src/world.cpp
xml/playerSpawnHill1.xml
xml/playerSpawnHill1_Building1.xml

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..ea71945339f7a7cd6d35324a11df49578bb93bfc 100644 (file)
--- a/brice.dat
+++ b/brice.dat
@@ -0,0 +1,5 @@
+2
+canSprint
+0
+canJump
+0
index 826b0f6de1a4e73aeb1eaceb5d5a492bf89e428d..605cc771862cf8d8a85764921b9826423dd00d47 100644 (file)
@@ -17,6 +17,7 @@
 #include <inventory.hpp>
 #include <texture.hpp>
 #include <save_util.hpp>
+#include <coolarray.hpp>
 
 // local library includes
 #include <tinyxml2.h>
index 5809ab8d4470652dca1e121d8e5905feb1405a2f..a36a9b84346b2f8daf2d3b90b3cd7f4ccf9eae9f 100644 (file)
@@ -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);
index d7889fc5859afdb114a0fc2ac7f047d3d198e793..f16b5118644df8a840cb15b526921aeb6e4c1652 100644 (file)
@@ -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&apos;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>
index 800f0077d65373fb8243955dd828a773d125952d..eb63d7be21091bc92c0cf578c86d3d3a11e4680f 100644 (file)
 <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>