particles.cpp 17 KB

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