void particle_system_update(struct particle_system *ps, float dt) { int i = 0; if (ps->isActive) { float rate = ps->config->emissionRate; // emitCounter should not increase where ps->particleCount == ps->totalParticles if (ps->particleCount < ps->config->totalParticles) { ps->emitCounter += dt; } while (ps->particleCount < ps->config->totalParticles && ps->emitCounter > rate) { _addParticle(ps); ps->emitCounter -= rate; } ps->elapsed += dt; if (ps->config->duration != DURATION_INFINITY && ps->config->duration < ps->elapsed) { _stopSystem(ps); } } while (i < ps->particleCount) { struct particle *p = &ps->particles[i]; p->timeToLive -= dt; if (p->timeToLive > 0) { _update_particle(ps, p, dt); if (p->size <= 0) { _remove_particle(ps, i); } else { ++i; } } else { _remove_particle(ps, i); } } ps->isAlive = ps->particleCount > 0; }
void rDeviceAllegroDogCAN::onTerminate() { _stopSystem(); _closeCAN(); map<int, CANProtocolBuffer*>::iterator itr = _RxCmdQueue.begin(); while (itr != _RxCmdQueue.end()) { delete (itr->second); itr++; } _RxCmdQueue.clear(); RD_DEVICE_CLASS(Base)::onTerminate(); }
int rDeviceAllegroDogCAN::command(int cmd, int arg, void* udata, int port) { switch (cmd) { case CAN_CMD_MOTOR_ON: { if (port >= 0 && port < _jdof) _motorOn(getMotorDrvId(port)); else _motorOn(); } break; case CAN_CMD_MOTOR_OFF: { if (port >= 0 && port < _jdof) _motorOff(getMotorDrvId(port)); else _motorOff(); } break; case CAN_CMD_HOMING: { int offset = (short)(arg & 0x0000ffff); int direction = (short)((arg & 0xffff0000) >> 16); if (port >= 0 && port < _jdof) _homing(offset, direction, getMotorDrvId(port), getMotorDrvChId(port)); else _homing(offset, direction); } break; case CAN_CMD_RESET_ENC: { if (port >= 0 && port < _jdof) _resetEncoder(getMotorDrvId(port)); else _resetEncoder(); } break; case CAN_CMD_QUERY_STATUS: { if (port >= 0 && port < _jdof) _queryStatus(getMotorDrvId(port)); else _queryStatus(); } break; case CAN_CMD_ENABLE: { _startPeriodicCommunication(); } break; case CAN_CMD_DISABLE: { _stopPeriodicCommunication(); } break; case CAN_CMD_OPMODE_POSITION: { if (port >= 0 && port < _jdof) _setModeOfOperation(eOP_MODE_POS, getMotorDrvId(port)); else _setModeOfOperation(eOP_MODE_POS); } break; case CAN_CMD_OPMODE_VELOCITY: { if (port >= 0 && port < _jdof) _setModeOfOperation(eOP_MODE_VEL, getMotorDrvId(port)); else _setModeOfOperation(eOP_MODE_VEL); } break; case CAN_CMD_OPMODE_CURRENT: { if (port >= 0 && port < _jdof) _setModeOfOperation(eOP_MODE_CUR, getMotorDrvId(port)); else _setModeOfOperation(eOP_MODE_CUR); } break; case CAN_CMD_SET_POS_TARGET_RELATIVE: { if (port >= 0 && port < _jdof) _sendMotorCmdP2PRelative(getMotorDrvId(port)); else _sendMotorCmdP2PRelative(); } break; case CAN_CMD_SET_POS_TARGET_ABSOLUTE: { if (port >= 0 && port < _jdof) _sendMotorCmdP2PAbsolute(getMotorDrvId(port)); else _sendMotorCmdP2PAbsolute(); } break; case CAN_CMD_SET_POS_MAX_VELOCITY: { if (port >= 0 && port < _jdof) _setVelocityInP2PMode(arg, arg, getMotorDrvId(port)); else _setVelocityInP2PMode(arg, arg); } break; case CAN_CMD_STOP_SYS: { _stopSystem(); } break; case CAN_CMD_UPDATE_READ: updateWriteValue(0); break; case CAN_CMD_UPDATE_WRITE: updateReadValue(0); break; } return 0; }