ich habe eine teil der Tribase Engine Partikel-Manager welche in einem C++ buch benutzt wird zu PB umgeschrieben.
Nun läuft er so weit und befor ich das dann alles hier bereitstelle wollte ich das da wer nochmal drüber schaut.
Hab so das Gefühl das es noch nich so rund läuft.
so hier mal ein kleines beispiel

https://www.dropbox.com/s/f4xybyev4nlfnrk/test.exe
Hier das Bild zum selbst compilieren.
https://www.dropbox.com/s/1evyulg00mh1v ... e_fire.png
update:
Habe ein Performance problem entdeckt.
DeleteElement(Particle()) verursacht einen Lag wenn es mehrere elemente gleichzeit löscht ab 50 Partikel.
Bin auf der suche nun das Problem zu lösen

Grüße.
Code: Alles auswählen
;/********************************************************************
; _________ __ _____
; /\___ ___\ /\_\ /\ __\
; \/__/\ \__/ _ __\/_/_ \ \ \_\\ ____ _____ __
; \ \ \ /\`´__\ /\ \ \ \ __\ /\ __\_ /\ __\ /´__`\
; \ \ \ \ \ \/ \ \ \ \ \ \_\\\ \\_\ \\ \____\ /\ __/
; \ \_\ \ \_\ \ \_\ \ \____\\ \___\ \ \____\\ \____\
; \/_/ \/_/ \/_/ \/____/ \/__/ \/____/ \/____/
;tbParticleSystem.cpp
;Copyright goes to TriBase-Engine.
;Autor:
;David Scherfgen
;Portiert von Johannes Meyer
;PB 5.20 beta 16
UseJPEGImageDecoder() : UsePNGImageDecoder()
If InitMouse() = 0 Or InitSprite() = 0 Or InitKeyboard() = 0 Or InitSound() = 0 Or InitMovie() = 0
MessageRequester("test", "Can't open DirectX 11", 0)
End
EndIf
If OpenWindow(0, 0, 0,1024,900,"test") = 0
MessageRequester("test", "Can't open Screen", 0)
End
EndIf
If OpenWindowedScreen(WindowID(0),0,0,1024,900,0,0,0) = 0
MessageRequester("test", "Can't open Screen", 0)
End
EndIf
Enumeration
#Textur_Kreis
EndEnumeration
Structure Particle
fLifeTime.f
Particle.f
fParticle.f
fDeltaParticle.f
fStartParticle.f
fEndParticle.f
Array Vector3_position.f(1)
Array Vector3_velocity.f(1)
fFriction.f
fDeltaSize.f
fSize.f
fStartsize.f
fEndsize.f
Color.f
DeltaColor.i
Startcolor.i
Endcolor.i
fRotation.f
fStartRotation.f
fEndRotation.f
fDeltaRotation.f
StartTransparenz.i
maxparticle.i
EndStructure
Global NewList Particle.Particle()
Define Explode.Particle ;Explosion
Global maxparticle.i = 40 ;Maximale Partikel
Explode\fLifetime = 7.0 ;Lebenszeit
Explode\Vector3_velocity.f(0) = 1.0 ;Beschleunigung
Explode\Vector3_velocity.f(1) = 1.0
Explode\Vector3_position.f(0) = 20 ;pos
Explode\Vector3_position.f(1) = 20
Explode\fStartsize = 20.0 ;startGröße
Explode\fEndsize = 30.0 ;startGröße
Explode\Startcolor = RGB(0,0,0);startGröße
Explode\Endcolor = RGB(250,0,0);startGröße
Explode\StartTransparenz = 100 ;Trransparenz der Partikel
Explode\fStartParticle = 0
Explode\fFriction = 1.0
Explode\fEndParticle = #Textur_Kreis
;// Lade Textur
If Not CatchSprite(#Textur_Kreis,?Particle,#PB_Sprite_AlphaBlending)
Debug "error"
End
EndIf
;// Erstelle Textur
;CreateSprite(#Textur_Kreis,30,30,#PB_Sprite_AlphaBlending )
;StartDrawing(SpriteOutput(#Textur_Kreis))
; Circle(5,5,6,RGB(250,0,0))
;StopDrawing()
;
; // int-Zufallswert
Procedure IntRandom(iMin.i,iMax.i)
ProcedureReturn Random(iMax,iMin)
EndProcedure
Procedure.f FloatRandom(fMin.f, fMax.f)
ProcedureReturn fMin + (fMax - fMin) * (Random(10001) / 10000.0)
EndProcedure
Procedure.f FPS()
Static time.i = -1
Protected currentTime.i = ElapsedMilliseconds()
Protected timeDiff.i = currentTime - time
time = currentTime
If timeDiff > 0
ProcedureReturn 1000. / timeDiff
EndIf
EndProcedure
;// Bewegt alle Partikel
Procedure MOVE_PARTICLE(fTime.f)
;//Alle Partikel druchgehen
ForEach Particle()
With Particle()
;// Lebenszeit verringern
\fLifeTime - (fTime.f) ;// Lebenszeit verringern
;// Ist der Partikel verschwunden?
If \fLifeTime <= 0.0
DeleteElement(Particle())
ProcedureReturn OK
EndIf
;// Bewegen
\Vector3_position(0) + \Vector3_velocity(0) * (fTime.f) ;X
\Vector3_position(1) + \Vector3_velocity(1) * (fTime.f ) ;Y
;// Abbremsen
If Not \fFriction = 1.0
\Vector3_velocity(0) * Pow(\fFriction,(fTime.f))
\Vector3_velocity(1) * Pow(\fFriction,(fTime.f))
EndIf
;// Partikel animieren
\fParticle + \fDeltaParticle * fTime.f
\fSize + \fDeltaSize * fTime.f
\Color + \DeltaColor * fTime.f
\fRotation + \fDeltaRotation * fTime.f
\Vector3_position(0) + Cos(\fRotation) * \Vector3_velocity(0) ;X
\Vector3_position(1) + Sin(\fRotation) * \Vector3_velocity(1) ;Y
EndWith
Next
ProcedureReturn OK
EndProcedure
Procedure.f ADD_PARTICLE(fLifeTime.f,fStartParticle.f,fEndParticle.f,fXVector3_position.f,fYVector3_position.f,fXVector3_velocity.f,fYVector3_velocity.f,fFriction.f,fStartsize.f,fEndsize.f,Startcolor.i,Endcolor.i,fStartRotation.f,fEndRotation.f)
If(fLifeTime <= 0.0) : ProcedureReturn 0 : EndIf
Protected.f fInvLifeTime = 1.0 / fLifeTime;
If ListSize(Particle()) < maxparticle
AddElement(Particle())
With Particle()
\fLifeTime = fLifeTime
\fParticle = fStartParticle
\fDeltaParticle = (fEndParticle - fStartParticle) * fInvLifeTime;
\Vector3_position(0) = fXVector3_position
\Vector3_position(1) = fYVector3_position
\Vector3_velocity(0) = fXVector3_velocity
\Vector3_velocity(1) = fYVector3_velocity
\fFriction = fFriction
\fsize = fStartsize
\fDeltaSize = (fEndSize - fStartSize) * fInvLifeTime;
\color = Startcolor
\DeltaColor = (EndColor - StartColor) * fInvLifeTime;
\fRotation = fStartRotation;
\fDeltaRotation = (fEndRotation - fStartRotation) * fInvLifeTime;
EndWith
EndIf
ProcedureReturn OK
EndProcedure
Procedure RENDER_PARTICLE(fTime.f,Transp)
ForEach Particle ()
With Particle()
Debug \fSize
ZoomSprite(\Particle,\fSize,\fSize)
;DisplayTransparentSprite(\Particle,\Vector3_position(0),\Vector3_position(1),Transp,\Color)
DisplayTransparentSprite(\Particle,\Vector3_position(0),\Vector3_position(1))
EndWith
Next
ProcedureReturn OK
EndProcedure
Repeat
Define dwtime1 = ElapsedMilliseconds()
ClearScreen(0)
ADD_PARTICLE(Explode\fLifetime+FloatRandom(-0.25,0.25),Explode\fStartParticle,Explode\fEndParticle,Explode\Vector3_position.f(0)+FloatRandom(0.0,20.0),Explode\Vector3_position.f(1)+FloatRandom(0.0,20.0),Explode\Vector3_velocity.f(0)+FloatRandom(0.0,5.0),Explode\Vector3_velocity.f(1)+FloatRandom(0.0,5.0),Explode\fFriction,Explode\fStartsize+FloatRandom(-5.0,5.0),Explode\fendsize+FloatRandom(-5.0,5.0),Explode\Startcolor+FloatRandom(-1.0,1.0)*FloatRandom(0.0,0.5),Explode\Endcolor+FloatRandom(-1.0,1.0)*FloatRandom(0.0,0.5),FloatRandom(0.0,2.0),FloatRandom(0.0,2.0))
MOVE_PARTICLE(fTime.f)
;SpriteBlendingMode(5,2) ; Schöner "glüh-Effekt"
;SpriteQuality(1)
RENDER_PARTICLE(fTime.f,Transp)
StartDrawing(ScreenOutput())
DrawText(0,0,"Partikel: "+StrF(ListSize(Particle ())))
DrawText(0,20,"FPS: " + Str(FPS()))
StopDrawing()
FlipBuffers ()
Define dwTime2 = ElapsedMilliseconds()
Define.f ftime = (dwtime2 - dwtime1) / 1000.0
Define Event = WindowEvent ()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
DataSection
particle:
IncludeBinary "particle_fire.png"
EndDataSection