]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
coolarray, particles are good now
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 3 Jun 2016 12:47:13 +0000 (08:47 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 3 Jun 2016 12:47:13 +0000 (08:47 -0400)
Changelog
brice.dat
include/coolarray.hpp [new file with mode: 0644]
include/entities.hpp
include/world.hpp
src/entities.cpp
src/world.cpp
xml/playerSpawnHill1.xml

index 1dd6ef30bee988684d82acc9b0da1cf45b9d34f6..ec4a00e4450433ba92a451a10415da9f3e18c795 100644 (file)
--- a/Changelog
+++ b/Changelog
        - entitys can modify their XMLs
        - 'alive' XML attribute works
        - lighting's pretty neat
+
+6/3/2016:
+=========
+
+       - majorly improved particle handling, made CoolArray
+       - found bugs in quest handling...
+       - making lights and stars n stuff goood
+       - story??? art??? music???
index 4bfeac60c203b4b22f8a89cba605f469d3bf47d2..bda8adcb6642decd7a089554d88b1583f814346b 100644 (file)
--- a/brice.dat
+++ b/brice.dat
@@ -1,5 +1,5 @@
 2
-canJump
-1
 canSprint
 1
+canJump
+1
diff --git a/include/coolarray.hpp b/include/coolarray.hpp
new file mode 100644 (file)
index 0000000..3e167b7
--- /dev/null
@@ -0,0 +1,113 @@
+#ifndef COOLARRAY_H_
+#define COOLARRAY_H_
+
+#include <memory>
+#include <initializer_list>
+
+template<class T>
+class CoolArray {
+private:
+       T *buffer;
+       size_t _size, _capacity;
+public:
+       CoolArray(void) {
+               buffer = nullptr;
+               _size = 0;
+               _capacity = 0;
+       }
+
+       CoolArray(size_t n, const T& value) {
+               buffer = new T[n];
+               _size = n;
+               _capacity = n;
+               std::fill(buffer, buffer + _size, value);
+       }
+
+       ~CoolArray(void) {
+               delete[] buffer;
+       }
+
+       T& operator[](size_t idx) {
+               return buffer[idx];
+       }
+
+       void operator=(std::initializer_list<T> a) {
+               if (buffer != nullptr)
+                       delete[] buffer;
+
+               _size = a.size();
+               buffer = new T[_size];
+               _capacity = _size;
+               std::copy(a.begin(), a.end(), buffer);
+       }
+
+       template<class Func>
+       void remove_if(Func f) {
+               for (size_t i = 0; i < _size; ++i) {
+                       if (f(buffer[i]))
+                               std::move(buffer + i + 1, buffer + _size--, buffer + i);
+               }
+       }
+
+       void reserve(size_t n) {
+               if (buffer != nullptr) {
+                       T *newbuf = new T[n];
+                       std::copy(buffer, buffer + (_size < n ? _size : n), newbuf);
+                       _capacity = n;
+                       delete[] buffer;
+                       buffer = newbuf;
+               } else {
+                       buffer = new T[n];
+                       _capacity = n;
+               }
+       }
+               
+       void resize(size_t n) {
+               reserve(n);
+               _size = n;
+       }
+
+       void clear(void) {
+               delete[] buffer;
+               _size = 0;
+               _capacity = 0;
+       }
+
+       size_t size(void) const {
+               return _size;
+       }
+
+       size_t capacity(void) const {
+               return _capacity;
+       }
+
+       T& front(void) {
+               return buffer[0];
+       }
+
+       T& back(void) {
+               return buffer[_size - 1];
+       }
+
+       T* begin(void) {
+               return buffer;
+       }
+
+       T* end(void) {
+               return buffer + _size;
+       }
+
+       void push_back(const T& x) {
+               if (_size >= _capacity)
+                       reserve(_capacity + 5);
+
+               buffer[_size++] = x;
+       }
+
+       void pop_back(void) {
+               --_size;
+       }
+};
+
+
+#endif // COOLARRAY_H_
index 61ecc437e668f5e9ed384e9d18e8a27f7e89fbb2..e406397ccb742583047aeb3a798cb2de68aa1ecf 100644 (file)
@@ -419,6 +419,8 @@ public:
 
        Structures *stu;
 
+       Particles(void){}
+
        // creates a particle with the desired characteristics
        Particles(float x, float y, float w, float h, float vx, float vy, Color c, float d);
 
index 2494120385f1e7ff6a20a552790be26db888447b..26811ae0af36ae8685f6ca120b3788f37f2f4d53 100644 (file)
@@ -9,6 +9,7 @@
 // local game includes
 #include <common.hpp>
 #include <entities.hpp>
+#include <coolarray.hpp>
 
 /**
  * The background type enum.
@@ -256,7 +257,7 @@ protected:
         *
         * @see addParticle()
         */
-       std::list<Particles>    particles;
+       CoolArray<Particles>    particles;
 
        /**
         * A vector of all structures in the world.
index 2d9de76dd69678790c290e04d16a27e57cf0a8cf..f59b46281e2326c33f597d01fe94a9b8c7d2a095 100644 (file)
@@ -133,10 +133,10 @@ void Entity::die(void)
        alive = false;
        health = 0;
 
-       if (xmle) {
+       /*if (xmle) {
                xmle->SetAttribute("alive", false);
                currentXMLDoc.SaveFile(currentXML.c_str(), false);
-       }
+       }*/
 }
 
 bool Entity::isAlive(void) const
index 5ab20ede036643851bbfd3ed714bf7f3cc015b23..b0961802504ad0337e273811b0319ab09684997b 100644 (file)
@@ -718,7 +718,7 @@ void World::draw(Player *p)
        
        std::vector<GLfloat> partVec(pss);
        GLfloat *pIndex = &partVec[0];
-   
+
        for (const auto &p : particles) {
         pc += 30;
                if (pc > pss) {
@@ -1487,14 +1487,14 @@ addObject(std::string in, std::string p, float x, float y)
 void World::
 addParticle(float x, float y, float w, float h, float vx, float vy, Color color, int d)
 {
-       particles.emplace_back(x, y, w, h, vx, vy, color, d);
+       particles.push_back(Particles(x, y, w, h, vx, vy, color, d));
        particles.back().canMove = true;
 }
 
 void World::
 addParticle(float x, float y, float w, float h, float vx, float vy, Color color, int d, unsigned char flags)
 {
-       particles.emplace_back(x, y, w, h, vx, vy, color, d);
+       particles.push_back(Particles(x, y, w, h, vx, vy, color, d));
        particles.back().canMove = true;
     particles.back().gravity = flags & (1 << 0);
     particles.back().bounce  = flags & (1 << 1);
index 6a65fb13401134cd1f8ad64b0796d475a9e1a554..0f19f9aaeca5f46acbb4c2d42c7e1daebf11edc9 100644 (file)
@@ -5,7 +5,7 @@
     <link right="playerSpawnHill2.xml"/>
     <time>12000</time>
     <hill peakx="0" peaky="1000" width="50"/>
-    <rabbit x="300" aggressive="false" health="100" alive="0"/>
+    <rabbit x="300" aggressive="false" health="100"/>
     <bird y="500"/>
     <cat/>
     <!--<trigger x="-300" id="Test"/>-->
@@ -38,14 +38,14 @@ And it wasn't stormy.
 <Dialog name="Ralph">
     <text id="0" nextid="1">
                Hello there! My name is Ralph.
-                       <gotox>300</gotox>
+               <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,9 +54,9 @@ 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">
-                       Dank MayMay,2
-                       Wood Sword,1
+               <quest assign="Your First Quest">
+               Dank MayMay,2
+               Wood Sword,1
                </quest>
     </text>
     <text id="1" nextid="1" pause="true">
@@ -67,8 +67,10 @@ And it wasn't stormy.
 <Dialog name="Big Dave">
     <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"/></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"/>
+       </text>
 </Dialog>