mirror of
https://github.com/lubosz/overte.git
synced 2025-04-19 12:24:01 +02:00
added update to particle
This commit is contained in:
parent
d0944b0278
commit
68a51f5205
10 changed files with 76 additions and 13 deletions
|
@ -2479,6 +2479,8 @@ void Application::update(float deltaTime) {
|
|||
updateDialogs(deltaTime); // update various stats dialogs if present
|
||||
updateAudio(deltaTime); // Update audio stats for procedural sounds
|
||||
updateCursor(deltaTime); // Handle cursor updates
|
||||
|
||||
_particles.update(); // update the particles...
|
||||
}
|
||||
|
||||
void Application::updateAvatar(float deltaTime) {
|
||||
|
|
|
@ -18,6 +18,13 @@ ParticleTreeRenderer::ParticleTreeRenderer() :
|
|||
ParticleTreeRenderer::~ParticleTreeRenderer() {
|
||||
}
|
||||
|
||||
void ParticleTreeRenderer::update() {
|
||||
if (_tree) {
|
||||
ParticleTree* tree = (ParticleTree*)_tree;
|
||||
tree->update();
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleTreeRenderer::renderElement(OctreeElement* element) {
|
||||
// actually render it here...
|
||||
// we need to iterate the actual particles of the element
|
||||
|
|
|
@ -32,7 +32,8 @@ public:
|
|||
virtual PACKET_TYPE getMyQueryMessageType() const { return PACKET_TYPE_PARTICLE_QUERY; }
|
||||
virtual PACKET_TYPE getExpectedPacketType() const { return PACKET_TYPE_PARTICLE_DATA; }
|
||||
virtual void renderElement(OctreeElement* element);
|
||||
|
||||
|
||||
void update();
|
||||
protected:
|
||||
};
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ public:
|
|||
|
||||
bool OctreeRenderer::renderOperation(OctreeElement* element, void* extraData) {
|
||||
RenderArgs* args = static_cast<RenderArgs*>(extraData);
|
||||
if (element->isInView(*args->_viewFrustum)) {
|
||||
if (true || element->isInView(*args->_viewFrustum)) {
|
||||
if (element->hasContent()) {
|
||||
args->_renderer->renderElement(element);
|
||||
}
|
||||
|
|
|
@ -193,3 +193,27 @@ bool Particle::encodeParticleEditMessageDetails(PACKET_TYPE command, int count,
|
|||
return success;
|
||||
}
|
||||
|
||||
|
||||
void Particle::update() {
|
||||
uint64_t now = usecTimestampNow();
|
||||
uint64_t elapsed = now - _lastUpdated;
|
||||
uint64_t USECS_PER_SECOND = 1000 * 1000;
|
||||
uint64_t USECS_PER_FIVE_SECONDS = 5 * USECS_PER_SECOND;
|
||||
uint64_t USECS_PER_TEN_SECONDS = 10 * USECS_PER_SECOND;
|
||||
uint64_t USECS_PER_THIRTY_SECONDS = 30 * USECS_PER_SECOND;
|
||||
uint64_t USECS_PER_MINUTE = 60 * USECS_PER_SECOND;
|
||||
uint64_t USECS_PER_HOUR = 60 * USECS_PER_MINUTE;
|
||||
float timeElapsed = (float)((float)elapsed/(float)USECS_PER_SECOND);
|
||||
printf("elapsed=%llu timeElapsed=%f\n", elapsed, timeElapsed);
|
||||
|
||||
glm::vec3 position = getPosition() * (float)TREE_SCALE;
|
||||
printf("OLD position=%f, %f, %f\n", position.x, position.y, position.z);
|
||||
printf("velocity=%f, %f, %f\n", getVelocity().x, getVelocity().y, getVelocity().z);
|
||||
|
||||
_position += _velocity * timeElapsed;
|
||||
|
||||
position = getPosition() * (float)TREE_SCALE;
|
||||
printf("NEW position=%f, %f, %f\n", position.x, position.y, position.z);
|
||||
_lastUpdated = now;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,9 @@ public:
|
|||
|
||||
static bool encodeParticleEditMessageDetails(PACKET_TYPE command, int count, const ParticleDetail* details,
|
||||
unsigned char* bufferOut, int sizeIn, int& sizeOut);
|
||||
|
||||
void update();
|
||||
|
||||
protected:
|
||||
glm::vec3 _position;
|
||||
rgbColor _color;
|
||||
|
|
|
@ -32,9 +32,8 @@ void ParticleTree::storeParticle(const Particle& particle) {
|
|||
float size = particle.getRadius();
|
||||
ParticleTreeElement* element = (ParticleTreeElement*)getOrCreateChildElementAt(position.x, position.y, position.z, size);
|
||||
|
||||
printf("ParticleTree::storeParticle() element=%p particle.getPosition()=%f,%f,%f\n",
|
||||
element,
|
||||
particle.getPosition().x, particle.getPosition().y, particle.getPosition().z);
|
||||
//printf("ParticleTree::storeParticle() element=%p particle.getPosition()=%f,%f,%f\n",
|
||||
// element, particle.getPosition().x, particle.getPosition().y, particle.getPosition().z);
|
||||
|
||||
element->storeParticle(particle);
|
||||
|
||||
|
@ -50,15 +49,13 @@ int ParticleTree::processEditPacketData(PACKET_TYPE packetType, unsigned char* p
|
|||
switch (packetType) {
|
||||
case PACKET_TYPE_PARTICLE_ADD: {
|
||||
|
||||
printf("got PACKET_TYPE_PARTICLE_ADD....\n");
|
||||
//printf("got PACKET_TYPE_PARTICLE_ADD....\n");
|
||||
Particle newParticle = Particle::fromEditPacket(editData, maxLength, processedBytes);
|
||||
|
||||
printf("newParticle...getPosition()=%f,%f,%f\n", newParticle.getPosition().x, newParticle.getPosition().y, newParticle.getPosition().z);
|
||||
|
||||
//printf("newParticle...getPosition()=%f,%f,%f\n", newParticle.getPosition().x, newParticle.getPosition().y, newParticle.getPosition().z);
|
||||
storeParticle(newParticle);
|
||||
|
||||
// It seems like we need some way to send the ID back to the creator??
|
||||
|
||||
} break;
|
||||
|
||||
case PACKET_TYPE_PARTICLE_ERASE: {
|
||||
|
@ -68,3 +65,21 @@ printf("newParticle...getPosition()=%f,%f,%f\n", newParticle.getPosition().x, ne
|
|||
return processedBytes;
|
||||
}
|
||||
|
||||
|
||||
class UpdateArgs {
|
||||
public:
|
||||
};
|
||||
|
||||
bool ParticleTree::updateOperation(OctreeElement* element, void* extraData) {
|
||||
UpdateArgs* args = static_cast<UpdateArgs*>(extraData);
|
||||
ParticleTreeElement* particleTreeElement = static_cast<ParticleTreeElement*>(element);
|
||||
particleTreeElement->update();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ParticleTree::update() {
|
||||
UpdateArgs args = { };
|
||||
recurseTreeWithOperation(updateOperation, &args);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,10 +29,13 @@ public:
|
|||
virtual bool handlesEditPacketType(PACKET_TYPE packetType) const;
|
||||
virtual int processEditPacketData(PACKET_TYPE packetType, unsigned char* packetData, int packetLength,
|
||||
unsigned char* editData, int maxLength);
|
||||
|
||||
|
||||
void update();
|
||||
private:
|
||||
void storeParticle(const Particle& particle);
|
||||
|
||||
static bool updateOperation(OctreeElement* element, void* extraData);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -41,13 +41,11 @@ ParticleTreeElement* ParticleTreeElement::addChildAtIndex(int index) {
|
|||
bool ParticleTreeElement::appendElementData(OctreePacketData* packetData) const {
|
||||
bool success = true; // assume the best...
|
||||
|
||||
|
||||
|
||||
// write our particles out...
|
||||
uint16_t numberOfParticles = _particles.size();
|
||||
success = packetData->appendValue(numberOfParticles);
|
||||
|
||||
printf("ParticleTreeElement::appendElementData()... numberOfParticles=%d\n",numberOfParticles);
|
||||
//printf("ParticleTreeElement::appendElementData()... numberOfParticles=%d\n",numberOfParticles);
|
||||
|
||||
if (success) {
|
||||
for (uint16_t i = 0; i < numberOfParticles; i++) {
|
||||
|
@ -61,6 +59,14 @@ printf("ParticleTreeElement::appendElementData()... numberOfParticles=%d\n",numb
|
|||
return success;
|
||||
}
|
||||
|
||||
void ParticleTreeElement::update() {
|
||||
// update our contained particles
|
||||
uint16_t numberOfParticles = _particles.size();
|
||||
for (uint16_t i = 0; i < numberOfParticles; i++) {
|
||||
_particles[i].update();
|
||||
// what if this update moves the particle to a new element??
|
||||
}
|
||||
}
|
||||
|
||||
int ParticleTreeElement::readElementDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
|
||||
ReadBitstreamToTreeParams& args) {
|
||||
|
|
|
@ -70,6 +70,8 @@ public:
|
|||
virtual bool isRendered() const { return getShouldRender(); }
|
||||
|
||||
const std::vector<Particle>& getParticles() const { return _particles; }
|
||||
|
||||
void update();
|
||||
|
||||
protected:
|
||||
void storeParticle(const Particle& particle);
|
||||
|
|
Loading…
Reference in a new issue