particles.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "particles.h"
  17. #include "client.h"
  18. #include "collision.h"
  19. #include "client/renderingengine.h"
  20. #include "util/numeric.h"
  21. #include "light.h"
  22. #include "environment.h"
  23. #include "clientmap.h"
  24. #include "mapnode.h"
  25. #include "nodedef.h"
  26. #include "client.h"
  27. #include "settings.h"
  28. /*
  29. Utility
  30. */
  31. v3f random_v3f(v3f min, v3f max)
  32. {
  33. return v3f( rand()/(float)RAND_MAX*(max.X-min.X)+min.X,
  34. rand()/(float)RAND_MAX*(max.Y-min.Y)+min.Y,
  35. rand()/(float)RAND_MAX*(max.Z-min.Z)+min.Z);
  36. }
  37. Particle::Particle(
  38. IGameDef *gamedef,
  39. LocalPlayer *player,
  40. ClientEnvironment *env,
  41. v3f pos,
  42. v3f velocity,
  43. v3f acceleration,
  44. float expirationtime,
  45. float size,
  46. bool collisiondetection,
  47. bool collision_removal,
  48. bool vertical,
  49. video::ITexture *texture,
  50. v2f texpos,
  51. v2f texsize,
  52. const struct TileAnimationParams &anim,
  53. u8 glow,
  54. video::SColor color
  55. ):
  56. scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(),
  57. RenderingEngine::get_scene_manager())
  58. {
  59. // Misc
  60. m_gamedef = gamedef;
  61. m_env = env;
  62. // Texture
  63. m_material.setFlag(video::EMF_LIGHTING, false);
  64. m_material.setFlag(video::EMF_BACK_FACE_CULLING, false);
  65. m_material.setFlag(video::EMF_BILINEAR_FILTER, false);
  66. m_material.setFlag(video::EMF_FOG_ENABLE, true);
  67. m_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
  68. m_material.setTexture(0, texture);
  69. m_texpos = texpos;
  70. m_texsize = texsize;
  71. m_animation = anim;
  72. // Color
  73. m_base_color = color;
  74. m_color = color;
  75. // Particle related
  76. m_pos = pos;
  77. m_velocity = velocity;
  78. m_acceleration = acceleration;
  79. m_expiration = expirationtime;
  80. m_player = player;
  81. m_size = size;
  82. m_collisiondetection = collisiondetection;
  83. m_collision_removal = collision_removal;
  84. m_vertical = vertical;
  85. m_glow = glow;
  86. // Irrlicht stuff
  87. m_collisionbox = aabb3f
  88. (-size/2,-size/2,-size/2,size/2,size/2,size/2);
  89. this->setAutomaticCulling(scene::EAC_OFF);
  90. // Init lighting
  91. updateLight();
  92. // Init model
  93. updateVertices();
  94. }
  95. void Particle::OnRegisterSceneNode()
  96. {
  97. if (IsVisible)
  98. SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT_EFFECT);
  99. ISceneNode::OnRegisterSceneNode();
  100. }
  101. void Particle::render()
  102. {
  103. video::IVideoDriver* driver = SceneManager->getVideoDriver();
  104. driver->setMaterial(m_material);
  105. driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
  106. u16 indices[] = {0,1,2, 2,3,0};
  107. driver->drawVertexPrimitiveList(m_vertices, 4,
  108. indices, 2, video::EVT_STANDARD,
  109. scene::EPT_TRIANGLES, video::EIT_16BIT);
  110. }
  111. void Particle::step(float dtime)
  112. {
  113. m_time += dtime;
  114. if (m_collisiondetection) {
  115. aabb3f box = m_collisionbox;
  116. v3f p_pos = m_pos * BS;
  117. v3f p_velocity = m_velocity * BS;
  118. collisionMoveResult r = collisionMoveSimple(m_env,
  119. m_gamedef, BS * 0.5, box, 0, dtime, &p_pos,
  120. &p_velocity, m_acceleration * BS);
  121. if (m_collision_removal && r.collides) {
  122. // force expiration of the particle
  123. m_expiration = -1.0;
  124. } else {
  125. m_pos = p_pos / BS;
  126. m_velocity = p_velocity / BS;
  127. }
  128. } else {
  129. m_velocity += m_acceleration * dtime;
  130. m_pos += m_velocity * dtime;
  131. }
  132. if (m_animation.type != TAT_NONE) {
  133. m_animation_time += dtime;
  134. int frame_length_i, frame_count;
  135. m_animation.determineParams(
  136. m_material.getTexture(0)->getSize(),
  137. &frame_count, &frame_length_i, NULL);
  138. float frame_length = frame_length_i / 1000.0;
  139. while (m_animation_time > frame_length) {
  140. m_animation_frame++;
  141. m_animation_time -= frame_length;
  142. }
  143. }
  144. // Update lighting
  145. updateLight();
  146. // Update model
  147. updateVertices();
  148. }
  149. void Particle::updateLight()
  150. {
  151. u8 light = 0;
  152. bool pos_ok;
  153. v3s16 p = v3s16(
  154. floor(m_pos.X+0.5),
  155. floor(m_pos.Y+0.5),
  156. floor(m_pos.Z+0.5)
  157. );
  158. MapNode n = m_env->getClientMap().getNodeNoEx(p, &pos_ok);
  159. if (pos_ok)
  160. light = n.getLightBlend(m_env->getDayNightRatio(), m_gamedef->ndef());
  161. else
  162. light = blend_light(m_env->getDayNightRatio(), LIGHT_SUN, 0);
  163. u8 m_light = decode_light(light + m_glow);
  164. m_color.set(255,
  165. m_light * m_base_color.getRed() / 255,
  166. m_light * m_base_color.getGreen() / 255,
  167. m_light * m_base_color.getBlue() / 255);
  168. }
  169. void Particle::updateVertices()
  170. {
  171. f32 tx0, tx1, ty0, ty1;
  172. if (m_animation.type != TAT_NONE) {
  173. const v2u32 texsize = m_material.getTexture(0)->getSize();
  174. v2f texcoord, framesize_f;
  175. v2u32 framesize;
  176. texcoord = m_animation.getTextureCoords(texsize, m_animation_frame);
  177. m_animation.determineParams(texsize, NULL, NULL, &framesize);
  178. framesize_f = v2f(framesize.X / (float) texsize.X, framesize.Y / (float) texsize.Y);
  179. tx0 = m_texpos.X + texcoord.X;
  180. tx1 = m_texpos.X + texcoord.X + framesize_f.X * m_texsize.X;
  181. ty0 = m_texpos.Y + texcoord.Y;
  182. ty1 = m_texpos.Y + texcoord.Y + framesize_f.Y * m_texsize.Y;
  183. } else {
  184. tx0 = m_texpos.X;
  185. tx1 = m_texpos.X + m_texsize.X;
  186. ty0 = m_texpos.Y;
  187. ty1 = m_texpos.Y + m_texsize.Y;
  188. }
  189. m_vertices[0] = video::S3DVertex(-m_size / 2, -m_size / 2,
  190. 0, 0, 0, 0, m_color, tx0, ty1);
  191. m_vertices[1] = video::S3DVertex(m_size / 2, -m_size / 2,
  192. 0, 0, 0, 0, m_color, tx1, ty1);
  193. m_vertices[2] = video::S3DVertex(m_size / 2, m_size / 2,
  194. 0, 0, 0, 0, m_color, tx1, ty0);
  195. m_vertices[3] = video::S3DVertex(-m_size / 2, m_size / 2,
  196. 0, 0, 0, 0, m_color, tx0, ty0);
  197. v3s16 camera_offset = m_env->getCameraOffset();
  198. for (video::S3DVertex &vertex : m_vertices) {
  199. if (m_vertical) {
  200. v3f ppos = m_player->getPosition()/BS;
  201. vertex.Pos.rotateXZBy(atan2(ppos.Z-m_pos.Z, ppos.X-m_pos.X)/core::DEGTORAD+90);
  202. } else {
  203. vertex.Pos.rotateYZBy(m_player->getPitch());
  204. vertex.Pos.rotateXZBy(m_player->getYaw());
  205. }
  206. m_box.addInternalPoint(vertex.Pos);
  207. vertex.Pos += m_pos*BS - intToFloat(camera_offset, BS);
  208. }
  209. }
  210. /*
  211. ParticleSpawner
  212. */
  213. ParticleSpawner::ParticleSpawner(IGameDef *gamedef, LocalPlayer *player,
  214. u16 amount, float time,
  215. v3f minpos, v3f maxpos, v3f minvel, v3f maxvel, v3f minacc, v3f maxacc,
  216. float minexptime, float maxexptime, float minsize, float maxsize,
  217. bool collisiondetection, bool collision_removal, u16 attached_id, bool vertical,
  218. video::ITexture *texture, u32 id, const struct TileAnimationParams &anim,
  219. u8 glow,
  220. ParticleManager *p_manager) :
  221. m_particlemanager(p_manager)
  222. {
  223. m_gamedef = gamedef;
  224. m_player = player;
  225. m_amount = amount;
  226. m_spawntime = time;
  227. m_minpos = minpos;
  228. m_maxpos = maxpos;
  229. m_minvel = minvel;
  230. m_maxvel = maxvel;
  231. m_minacc = minacc;
  232. m_maxacc = maxacc;
  233. m_minexptime = minexptime;
  234. m_maxexptime = maxexptime;
  235. m_minsize = minsize;
  236. m_maxsize = maxsize;
  237. m_collisiondetection = collisiondetection;
  238. m_collision_removal = collision_removal;
  239. m_attached_id = attached_id;
  240. m_vertical = vertical;
  241. m_texture = texture;
  242. m_time = 0;
  243. m_animation = anim;
  244. m_glow = glow;
  245. for (u16 i = 0; i<=m_amount; i++)
  246. {
  247. float spawntime = (float)rand()/(float)RAND_MAX*m_spawntime;
  248. m_spawntimes.push_back(spawntime);
  249. }
  250. }
  251. void ParticleSpawner::step(float dtime, ClientEnvironment* env)
  252. {
  253. m_time += dtime;
  254. static thread_local const float radius =
  255. g_settings->getS16("max_block_send_distance") * MAP_BLOCKSIZE;
  256. bool unloaded = false;
  257. bool is_attached = false;
  258. v3f attached_pos = v3f(0,0,0);
  259. float attached_yaw = 0;
  260. if (m_attached_id != 0) {
  261. if (ClientActiveObject *attached = env->getActiveObject(m_attached_id)) {
  262. attached_pos = attached->getPosition() / BS;
  263. attached_yaw = attached->getYaw();
  264. is_attached = true;
  265. } else {
  266. unloaded = true;
  267. }
  268. }
  269. if (m_spawntime != 0) // Spawner exists for a predefined timespan
  270. {
  271. for(std::vector<float>::iterator i = m_spawntimes.begin();
  272. i != m_spawntimes.end();)
  273. {
  274. if ((*i) <= m_time && m_amount > 0)
  275. {
  276. m_amount--;
  277. // Pretend to, but don't actually spawn a particle if it is
  278. // attached to an unloaded object or distant from player.
  279. if (!unloaded) {
  280. v3f ppos = m_player->getPosition() / BS;
  281. v3f pos = random_v3f(m_minpos, m_maxpos);
  282. if (pos.getDistanceFrom(ppos) <= radius) {
  283. v3f vel = random_v3f(m_minvel, m_maxvel);
  284. v3f acc = random_v3f(m_minacc, m_maxacc);
  285. if (is_attached) {
  286. // Apply attachment yaw and position
  287. pos.rotateXZBy(attached_yaw);
  288. pos += attached_pos;
  289. vel.rotateXZBy(attached_yaw);
  290. acc.rotateXZBy(attached_yaw);
  291. }
  292. float exptime = rand()/(float)RAND_MAX
  293. *(m_maxexptime-m_minexptime)
  294. +m_minexptime;
  295. float size = rand()/(float)RAND_MAX
  296. *(m_maxsize-m_minsize)
  297. +m_minsize;
  298. Particle* toadd = new Particle(
  299. m_gamedef,
  300. m_player,
  301. env,
  302. pos,
  303. vel,
  304. acc,
  305. exptime,
  306. size,
  307. m_collisiondetection,
  308. m_collision_removal,
  309. m_vertical,
  310. m_texture,
  311. v2f(0.0, 0.0),
  312. v2f(1.0, 1.0),
  313. m_animation,
  314. m_glow);
  315. m_particlemanager->addParticle(toadd);
  316. }
  317. }
  318. i = m_spawntimes.erase(i);
  319. }
  320. else
  321. {
  322. ++i;
  323. }
  324. }
  325. }
  326. else // Spawner exists for an infinity timespan, spawn on a per-second base
  327. {
  328. // Skip this step if attached to an unloaded object
  329. if (unloaded)
  330. return;
  331. for (int i = 0; i <= m_amount; i++)
  332. {
  333. if (rand()/(float)RAND_MAX < dtime)
  334. {
  335. // Do not spawn particle if distant from player
  336. v3f ppos = m_player->getPosition() / BS;
  337. v3f pos = random_v3f(m_minpos, m_maxpos);
  338. if (pos.getDistanceFrom(ppos) <= radius) {
  339. v3f vel = random_v3f(m_minvel, m_maxvel);
  340. v3f acc = random_v3f(m_minacc, m_maxacc);
  341. if (is_attached) {
  342. // Apply attachment yaw and position
  343. pos.rotateXZBy(attached_yaw);
  344. pos += attached_pos;
  345. vel.rotateXZBy(attached_yaw);
  346. acc.rotateXZBy(attached_yaw);
  347. }
  348. float exptime = rand()/(float)RAND_MAX
  349. *(m_maxexptime-m_minexptime)
  350. +m_minexptime;
  351. float size = rand()/(float)RAND_MAX
  352. *(m_maxsize-m_minsize)
  353. +m_minsize;
  354. Particle* toadd = new Particle(
  355. m_gamedef,
  356. m_player,
  357. env,
  358. pos,
  359. vel,
  360. acc,
  361. exptime,
  362. size,
  363. m_collisiondetection,
  364. m_collision_removal,
  365. m_vertical,
  366. m_texture,
  367. v2f(0.0, 0.0),
  368. v2f(1.0, 1.0),
  369. m_animation,
  370. m_glow);
  371. m_particlemanager->addParticle(toadd);
  372. }
  373. }
  374. }
  375. }
  376. }
  377. ParticleManager::ParticleManager(ClientEnvironment* env) :
  378. m_env(env)
  379. {}
  380. ParticleManager::~ParticleManager()
  381. {
  382. clearAll();
  383. }
  384. void ParticleManager::step(float dtime)
  385. {
  386. stepParticles (dtime);
  387. stepSpawners (dtime);
  388. }
  389. void ParticleManager::stepSpawners (float dtime)
  390. {
  391. MutexAutoLock lock(m_spawner_list_lock);
  392. for (std::map<u32, ParticleSpawner*>::iterator i =
  393. m_particle_spawners.begin();
  394. i != m_particle_spawners.end();)
  395. {
  396. if (i->second->get_expired())
  397. {
  398. delete i->second;
  399. m_particle_spawners.erase(i++);
  400. }
  401. else
  402. {
  403. i->second->step(dtime, m_env);
  404. ++i;
  405. }
  406. }
  407. }
  408. void ParticleManager::stepParticles (float dtime)
  409. {
  410. MutexAutoLock lock(m_particle_list_lock);
  411. for(std::vector<Particle*>::iterator i = m_particles.begin();
  412. i != m_particles.end();)
  413. {
  414. if ((*i)->get_expired())
  415. {
  416. (*i)->remove();
  417. delete *i;
  418. i = m_particles.erase(i);
  419. }
  420. else
  421. {
  422. (*i)->step(dtime);
  423. ++i;
  424. }
  425. }
  426. }
  427. void ParticleManager::clearAll ()
  428. {
  429. MutexAutoLock lock(m_spawner_list_lock);
  430. MutexAutoLock lock2(m_particle_list_lock);
  431. for(std::map<u32, ParticleSpawner*>::iterator i =
  432. m_particle_spawners.begin();
  433. i != m_particle_spawners.end();)
  434. {
  435. delete i->second;
  436. m_particle_spawners.erase(i++);
  437. }
  438. for(std::vector<Particle*>::iterator i =
  439. m_particles.begin();
  440. i != m_particles.end();)
  441. {
  442. (*i)->remove();
  443. delete *i;
  444. i = m_particles.erase(i);
  445. }
  446. }
  447. void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
  448. LocalPlayer *player)
  449. {
  450. switch (event->type) {
  451. case CE_DELETE_PARTICLESPAWNER: {
  452. MutexAutoLock lock(m_spawner_list_lock);
  453. if (m_particle_spawners.find(event->delete_particlespawner.id) !=
  454. m_particle_spawners.end()) {
  455. delete m_particle_spawners.find(event->delete_particlespawner.id)->second;
  456. m_particle_spawners.erase(event->delete_particlespawner.id);
  457. }
  458. // no allocated memory in delete event
  459. break;
  460. }
  461. case CE_ADD_PARTICLESPAWNER: {
  462. {
  463. MutexAutoLock lock(m_spawner_list_lock);
  464. if (m_particle_spawners.find(event->add_particlespawner.id) !=
  465. m_particle_spawners.end()) {
  466. delete m_particle_spawners.find(event->add_particlespawner.id)->second;
  467. m_particle_spawners.erase(event->add_particlespawner.id);
  468. }
  469. }
  470. video::ITexture *texture =
  471. client->tsrc()->getTextureForMesh(*(event->add_particlespawner.texture));
  472. ParticleSpawner *toadd = new ParticleSpawner(client, player,
  473. event->add_particlespawner.amount,
  474. event->add_particlespawner.spawntime,
  475. *event->add_particlespawner.minpos,
  476. *event->add_particlespawner.maxpos,
  477. *event->add_particlespawner.minvel,
  478. *event->add_particlespawner.maxvel,
  479. *event->add_particlespawner.minacc,
  480. *event->add_particlespawner.maxacc,
  481. event->add_particlespawner.minexptime,
  482. event->add_particlespawner.maxexptime,
  483. event->add_particlespawner.minsize,
  484. event->add_particlespawner.maxsize,
  485. event->add_particlespawner.collisiondetection,
  486. event->add_particlespawner.collision_removal,
  487. event->add_particlespawner.attached_id,
  488. event->add_particlespawner.vertical,
  489. texture,
  490. event->add_particlespawner.id,
  491. event->add_particlespawner.animation,
  492. event->add_particlespawner.glow,
  493. this);
  494. /* delete allocated content of event */
  495. delete event->add_particlespawner.minpos;
  496. delete event->add_particlespawner.maxpos;
  497. delete event->add_particlespawner.minvel;
  498. delete event->add_particlespawner.maxvel;
  499. delete event->add_particlespawner.minacc;
  500. delete event->add_particlespawner.texture;
  501. delete event->add_particlespawner.maxacc;
  502. {
  503. MutexAutoLock lock(m_spawner_list_lock);
  504. m_particle_spawners.insert(
  505. std::pair<u32, ParticleSpawner*>(
  506. event->add_particlespawner.id,
  507. toadd));
  508. }
  509. break;
  510. }
  511. case CE_SPAWN_PARTICLE: {
  512. video::ITexture *texture =
  513. client->tsrc()->getTextureForMesh(*(event->spawn_particle.texture));
  514. Particle *toadd = new Particle(client, player, m_env,
  515. *event->spawn_particle.pos,
  516. *event->spawn_particle.vel,
  517. *event->spawn_particle.acc,
  518. event->spawn_particle.expirationtime,
  519. event->spawn_particle.size,
  520. event->spawn_particle.collisiondetection,
  521. event->spawn_particle.collision_removal,
  522. event->spawn_particle.vertical,
  523. texture,
  524. v2f(0.0, 0.0),
  525. v2f(1.0, 1.0),
  526. event->spawn_particle.animation,
  527. event->spawn_particle.glow);
  528. addParticle(toadd);
  529. delete event->spawn_particle.pos;
  530. delete event->spawn_particle.vel;
  531. delete event->spawn_particle.acc;
  532. delete event->spawn_particle.texture;
  533. break;
  534. }
  535. default: break;
  536. }
  537. }
  538. void ParticleManager::addDiggingParticles(IGameDef* gamedef,
  539. LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f)
  540. {
  541. // set the amount of particles here
  542. for (u16 j = 0; j < 32; j++) {
  543. addNodeParticle(gamedef, player, pos, n, f);
  544. }
  545. }
  546. void ParticleManager::addPunchingParticles(IGameDef* gamedef,
  547. LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f)
  548. {
  549. addNodeParticle(gamedef, player, pos, n, f);
  550. }
  551. void ParticleManager::addNodeParticle(IGameDef* gamedef,
  552. LocalPlayer *player, v3s16 pos, const MapNode &n, const ContentFeatures &f)
  553. {
  554. // Texture
  555. u8 texid = myrand_range(0, 5);
  556. const TileLayer &tile = f.tiles[texid].layers[0];
  557. video::ITexture *texture;
  558. struct TileAnimationParams anim;
  559. anim.type = TAT_NONE;
  560. // Only use first frame of animated texture
  561. if (tile.material_flags & MATERIAL_FLAG_ANIMATION)
  562. texture = (*tile.frames)[0].texture;
  563. else
  564. texture = tile.texture;
  565. float size = rand() % 64 / 512.;
  566. float visual_size = BS * size;
  567. v2f texsize(size * 2, size * 2);
  568. v2f texpos;
  569. texpos.X = ((rand() % 64) / 64. - texsize.X);
  570. texpos.Y = ((rand() % 64) / 64. - texsize.Y);
  571. // Physics
  572. v3f velocity((rand() % 100 / 50. - 1) / 1.5,
  573. rand() % 100 / 35.,
  574. (rand() % 100 / 50. - 1) / 1.5);
  575. v3f acceleration(0,-9,0);
  576. v3f particlepos = v3f(
  577. (f32) pos.X + rand() %100 /200. - 0.25,
  578. (f32) pos.Y + rand() %100 /200. - 0.25,
  579. (f32) pos.Z + rand() %100 /200. - 0.25
  580. );
  581. video::SColor color;
  582. if (tile.has_color)
  583. color = tile.color;
  584. else
  585. n.getColor(f, &color);
  586. Particle* toadd = new Particle(
  587. gamedef,
  588. player,
  589. m_env,
  590. particlepos,
  591. velocity,
  592. acceleration,
  593. rand() % 100 / 100., // expiration time
  594. visual_size,
  595. true,
  596. false,
  597. false,
  598. texture,
  599. texpos,
  600. texsize,
  601. anim,
  602. 0,
  603. color);
  604. addParticle(toadd);
  605. }
  606. void ParticleManager::addParticle(Particle* toadd)
  607. {
  608. MutexAutoLock lock(m_particle_list_lock);
  609. m_particles.push_back(toadd);
  610. }