pass scriptable particle on collisions

This commit is contained in:
ZappoMan 2013-12-30 16:35:58 -08:00
parent 9194a53410
commit 5057517b78
3 changed files with 8 additions and 10 deletions

View file

@ -540,7 +540,7 @@ void Particle::runUpdateScript() {
} }
} }
void Particle::collisionWithParticle(unsigned int otherID) { void Particle::collisionWithParticle(Particle* other) {
if (!_script.isEmpty()) { if (!_script.isEmpty()) {
QScriptEngine engine; QScriptEngine engine;
@ -564,14 +564,12 @@ void Particle::collisionWithParticle(unsigned int otherID) {
if (getParticlesScriptingInterface()) { if (getParticlesScriptingInterface()) {
QScriptValue particleScripterValue = engine.newQObject(getParticlesScriptingInterface()); QScriptValue particleScripterValue = engine.newQObject(getParticlesScriptingInterface());
engine.globalObject().setProperty("Particles", particleScripterValue); engine.globalObject().setProperty("Particles", particleScripterValue);
printf("has Particles...\n");
} else {
printf("no Particles...\n");
} }
QScriptValue result = engine.evaluate(_script); QScriptValue result = engine.evaluate(_script);
particleScriptable.emitCollisionWithParticle(otherID); ParticleScriptObject otherParticleScriptable(other);
particleScriptable.emitCollisionWithParticle(&otherParticleScriptable);
if (getVoxelsScriptingInterface()) { if (getVoxelsScriptingInterface()) {
getVoxelsScriptingInterface()->getPacketSender()->releaseQueuedMessages(); getVoxelsScriptingInterface()->getPacketSender()->releaseQueuedMessages();

View file

@ -114,7 +114,7 @@ public:
static void adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssize_t length, int clockSkew); static void adjustEditPacketForClockSkew(unsigned char* codeColorBuffer, ssize_t length, int clockSkew);
void update(); void update();
void collisionWithParticle(unsigned int otherID); void collisionWithParticle(Particle* other);
void debugDump() const; void debugDump() const;
@ -170,7 +170,7 @@ public:
ParticleScriptObject(Particle* particle) { _particle = particle; } ParticleScriptObject(Particle* particle) { _particle = particle; }
void emitUpdate() { emit update(); } void emitUpdate() { emit update(); }
void emitCollisionWithParticle(uint32_t otherID) { emit collisionWithParticle(otherID); } void emitCollisionWithParticle(QObject* other) { emit collisionWithParticle(other); }
void emitCollisionWithVoxel() { emit collisionWithVoxel(); } void emitCollisionWithVoxel() { emit collisionWithVoxel(); }
public slots: public slots:
@ -196,7 +196,7 @@ public slots:
signals: signals:
void update(); void update();
void collisionWithVoxel(); void collisionWithVoxel();
void collisionWithParticle(unsigned int otherID); void collisionWithParticle(QObject* other);
private: private:
Particle* _particle; Particle* _particle;

View file

@ -92,8 +92,8 @@ void ParticleCollisionSystem::updateCollisionWithParticles(Particle* particle) {
if (_particles->findSpherePenetration(center, radius, penetration, (void**)&penetratedParticle)) { if (_particles->findSpherePenetration(center, radius, penetration, (void**)&penetratedParticle)) {
// let the particles run their collision scripts if they have them // let the particles run their collision scripts if they have them
particle->collisionWithParticle(penetratedParticle->getID()); particle->collisionWithParticle(penetratedParticle);
penetratedParticle->collisionWithParticle(particle->getID()); penetratedParticle->collisionWithParticle(particle);
penetration /= (float)TREE_SCALE; penetration /= (float)TREE_SCALE;
updateCollisionSound(particle, penetration, VOXEL_COLLISION_FREQUENCY); updateCollisionSound(particle, penetration, VOXEL_COLLISION_FREQUENCY);