-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathemitter.bmx
More file actions
178 lines (150 loc) · 5.48 KB
/
emitter.bmx
File metadata and controls
178 lines (150 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
Strict
'Import sidesign.minib3d
Import "particle.bmx"
'Import "particletype.bmx"
Type Emitter
Field _active:Int
Field _piv:TEntity ' PIVOT HANDLE
Field _est:Int ' TIME EMISSION STARTED
Field _pty:Int[11] ' UP To 10 PARTICLE TYPES PER EMITTER
Field _pta:Int[11] ' PARTICLE Type ENABLED? (True/False)
Field _pst:Int[11] ' PARTICLE Type START TIMES
Field _plt:Int[11] ' PARTICLE Type LIFE TIMES
Field _per:Float[11] ' PARTICLE Type EMISSION RATE (PER SECOND)
Field _peo:Float[11] ' PARTICLE Type EMISSION RATE REMEMBER
Field _pec:Float[11] ' PARTICLE Type EMISSION RATE CHANGE
Field _pea:Float[11] ' INCREASE, EMIT PARTICLE If ABOVE 1
Field _scl:Float = 1 ' EMITTER'S SCALE
Field _snd:Int ' EMITTER SOUND
Field _sch:Int ' REMEMBER SOUND CHANNEL HANDLE
Field _slp:Int ' LOOP SOUND (1) Or Not (0)
Field _mlt:Int ' EMITTER'S MAXIMAL LIFE-TIME (LONGEST PARTICLE TYPE)
Field _npt:Int ' NUMBER OF ASSIGNED PARTICLE TYPES
Field _particleList:TList
Field _dummyPivot:TEntity
Field _dummyMesh:TMesh
Field _dummySurface:TSurface
Method Create:Emitter( parent:TEntity = Null, scale:Float = 1.0, dummyPivot:TEntity = Null, dummyMesh:TMesh = Null, dummySurface:TSurface = Null )
Local n:Emitter = New Emitter
n._active = False
n._scl = scale
n._dummyPivot = dummyPivot
n._dummyMesh = dummyMesh
n._dummySurface = dummySurface
n._piv = CreateCube( parent )
Local marker:TEntity = CreateCube( n._piv )
ScaleEntity ( marker, 1.0, 0.2, 1.0 )
PositionEntity( marker, 0.0, 1.0, 0.0 )
EntityColor ( marker, 255, 0, 0 )
HideEntity ( n._piv )
n._particleList = New TList
Return n
End Method
Method addParticleType:Int( pid:Int, pst:Int = 0, plt:Int = 1000, per:Float = 10.0, pec:Float = 0.0 )
_npt = _npt + 1
_pty[_npt] = pid ' PARTICLE TYPES ID
_pst[_npt] = pst ' PARTICLE Type START TIME
_plt[_npt] = pst + plt ' PARTICLE Type LIFE TIME
_per[_npt] = per / 1000 ' PARTICLE Type EMISSION RATE (PER SECOND)
_peo[_npt] = per / 1000 ' PARTICLE Type EMISSION RATE REMEMBER
_pec[_npt] = pec / 1000 ' PARTICLE Type EMISSION RATE CHANGE
_pta[_npt] = True ' PARTICLE Type ENABLED? (True/False)
' EMITTER'S MAXIMAL LIFE-TIME (LONGEST LASTING PARTICLE TYPE)
If( pst + plt > _mlt ) _mlt = pst + plt
Return _npt
End Method
Method updateSlot( slotNum:Int, pst:Int = 0, plt:Int = 1000, per:Float = 10.0, pec:Float = 0.0 )
_pst[slotNum] = pst ' PARTICLE Type START TIME
_plt[slotNum] = pst + plt ' PARTICLE Type LIFE TIME
_per[slotNum] = per / 1000 ' PARTICLE Type EMISSION RATE (PER SECOND)
_peo[slotNum] = per / 1000 ' PARTICLE Type EMISSION RATE REMEMBER
_pec[slotNum] = pec / 1000 ' PARTICLE Type EMISSION RATE CHANGE
' EMITTER'S MAXIMAL LIFE-TIME (LONGEST LASTING PARTICLE TYPE)
If( pst + plt > _mlt ) _mlt = pst + plt
End Method
Method start()
DebugLog "starting..."
_active = True
_est = MilliSecs()
For Local i:Int = 1 To _npt
_per[i] = _peo[i]
Next
' ALSO START ATTACHED SOUND?
If( _snd )
'TODO If xChannelPlaying(Emitter.Sch) xStopChannel Emitter.Sch
'Emitter.Sch = xEmitSound(Emitter.Snd,Emitter.Piv)
End If
End Method
Method stop()
_active = False
'TODO If xChannelPlaying(Emitter.Sch) xStopChannel Emitter.Sch
End Method
Rem
Method setSound:Void( sndFile:String, slp:Int = 0 )
_slp = slp
'TODO Emitter.Snd = xLoad3DSound(sndFile)
'If Emitter.Snd < 1 Then RuntimeError "COULD NOT LOAD SOUND: " + sndFile
'If Emitter.slp Then xLoopSound Emitter.Snd
End Method
end rem
Method SetScale( scl:Float = 1.0 )
_scl = scl
ScaleEntity( _piv, scl, scl, scl, True )
End Method
Method GetScale:Float()
Return _scl
End Method
Method isActive()
Return _active
End Method
Method hasFinished()
For Local i:Int = 1 To _npt
If( MilliSecs() - _est < _plt[i] )
Return False
End If
Next
Return True
End Method
Method getParticleType:Int( slot:Int )
Return _pty[slot]
End Method
Method getSlot:Int( pid:Int )
For Local i:Int = 1 To _npt
If( _pty[i] = pid ) Return i
Next
Return -1
End Method
Method slotEnabled( slot:Int )
Return _pta[slot]
End Method
Method disableSlot( slot:Int )
_pta[slot] = False
End Method
Method enableSlot( slot:Int )
_pta[slot] = True
End Method
Method freeParticleTypes()
stop()
_npt = 0
_active = False
End Method
Method freeEmitter()
stop()
For Local particle:Particle = EachIn _particleList
If( GetParent( _dummyPivot ) = particle._piv ) EntityParent( _dummyPivot, Null, False )
If( GetParent( _dummyMesh ) = particle._piv ) EntityParent( _dummyMesh , Null, False )
_particleList.Remove( particle )
Next
_npt = 0
_active = False
'TODO If Emitter.Snd > 0 xFreeSound Emitter.Snd
FreeEntity( _piv )
End Method
Method clearParticles()
For Local particle:Particle = EachIn _particleList
If( GetParent( _dummyPivot ) = particle._piv ) EntityParent( _dummyPivot, Null, False )
If( GetParent( _dummyMesh ) = particle._piv ) EntityParent( _dummyMesh , Null, False )
_particleList.Remove( particle )
Next
End Method
End Type