diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-06-03 08:47:13 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-06-03 08:47:13 -0400 |
commit | f4632d58014dce0edc2d447dc934bae9cf957439 (patch) | |
tree | ef6018e960d1111f414be9e24fb3d21d2ba693c8 | |
parent | 2e6369f4dbe2b49a3cb8bec3bacd6559c9733a55 (diff) |
coolarray, particles are good now
-rw-r--r-- | Changelog | 8 | ||||
-rw-r--r-- | brice.dat | 4 | ||||
-rw-r--r-- | include/coolarray.hpp | 113 | ||||
-rw-r--r-- | include/entities.hpp | 2 | ||||
-rw-r--r-- | include/world.hpp | 3 | ||||
-rw-r--r-- | src/entities.cpp | 4 | ||||
-rw-r--r-- | src/world.cpp | 6 | ||||
-rw-r--r-- | xml/playerSpawnHill1.xml | 20 |
8 files changed, 143 insertions, 17 deletions
@@ -1027,3 +1027,11 @@ - 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??? @@ -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 index 0000000..3e167b7 --- /dev/null +++ b/include/coolarray.hpp @@ -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_ diff --git a/include/entities.hpp b/include/entities.hpp index 61ecc43..e406397 100644 --- a/include/entities.hpp +++ b/include/entities.hpp @@ -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); diff --git a/include/world.hpp b/include/world.hpp index 2494120..26811ae 100644 --- a/include/world.hpp +++ b/include/world.hpp @@ -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. diff --git a/src/entities.cpp b/src/entities.cpp index 2d9de76..f59b462 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -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 diff --git a/src/world.cpp b/src/world.cpp index 5ab20ed..b096180 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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); diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index 6a65fb1..0f19f9a 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -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> |