659c1249ff94df3d6aea4a332a82d0ee18a1fb93
[oweals/minetest.git] / src / particles.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include <string>
23 #include "irrlichttypes_bloated.h"
24 #include "tileanimation.h"
25
26 // This file defines the particle-related structures that both the server and
27 // client need. The ParticleManager and rendering is in client/particles.h
28
29 struct CommonParticleParams {
30         bool collisiondetection = false;
31         bool collision_removal = false;
32         bool object_collision = false;
33         bool vertical = false;
34         std::string texture;
35         struct TileAnimationParams animation;
36         u8 glow = 0;
37
38         CommonParticleParams() {
39                 animation.type = TAT_NONE;
40         }
41
42         /* This helper is useful for copying params from
43          * ParticleSpawnerParameters to ParticleParameters */
44         inline void copyCommon(CommonParticleParams &to) const {
45                 to.collisiondetection = collisiondetection;
46                 to.collision_removal = collision_removal;
47                 to.object_collision = object_collision;
48                 to.vertical = vertical;
49                 to.texture = texture;
50                 to.animation = animation;
51                 to.glow = glow;
52         }
53 };
54
55 struct ParticleParameters : CommonParticleParams {
56         v3f pos;
57         v3f vel;
58         v3f acc;
59         f32 expirationtime = 1;
60         f32 size = 1;
61
62         void serialize(std::ostream &os, u16 protocol_ver) const;
63         void deSerialize(std::istream &is, u16 protocol_ver);
64 };
65
66 struct ParticleSpawnerParameters : CommonParticleParams {
67         u16 amount = 1;
68         v3f minpos, maxpos, minvel, maxvel, minacc, maxacc;
69         f32 time = 1;
70         f32 minexptime = 1, maxexptime = 1, minsize = 1, maxsize = 1;
71
72         // For historical reasons no (de-)serialization methods here
73 };