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

View file

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

View file

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