diff options
-rw-r--r-- | Changelog | 8 | ||||
-rw-r--r-- | brice.dat | 5 | ||||
-rw-r--r-- | include/coolarray.hpp | 113 | ||||
-rw-r--r-- | include/entities.hpp | 2 | ||||
-rw-r--r-- | include/world.hpp | 3 | ||||
-rw-r--r-- | main.cpp | 4 | ||||
-rw-r--r-- | src/world.cpp | 14 | ||||
-rw-r--r-- | xml/playerSpawnHill1.xml | 20 |
8 files changed, 150 insertions, 19 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??? @@ -0,0 +1,5 @@ +2 +canJump +0 +canSprint +0 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. @@ -361,8 +361,8 @@ void render() { floor(offset.x+SCREEN_WIDTH/2), //right floor(offset.y-SCREEN_HEIGHT/2), //bottom floor(offset.y+SCREEN_HEIGHT/2), //top - 10.0, //near - -10.0); //far + 10.0f, //near + -10.0f); //far glm::mat4 view = glm::lookAt(glm::vec3(0,0,0.0f), //pos glm::vec3(0,0,-10.0f), //looking at diff --git a/src/world.cpp b/src/world.cpp index 698db7c..11bd671 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -712,13 +712,13 @@ void World::draw(Player *p) glEnableVertexAttribArray(worldShader_attribute_coord); glEnableVertexAttribArray(worldShader_attribute_tex); - uint ps = 0;particles.size(); + uint ps = particles.size(); uint pss = ps * 6 * 5; - //uint pc = 0; + uint pc = 0; std::vector<GLfloat> partVec(pss); - /*GLfloat *pIndex = &partVec[0]; - + GLfloat *pIndex = &partVec[0]; + for (const auto &p : particles) { pc += 30; if (pc > pss) { @@ -727,7 +727,7 @@ void World::draw(Player *p) break; } p.draw(pIndex); - }*/ + } 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]); @@ -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> |