Ich habe die letzten Wochen, wenn ich denn mal programmiert habe ;D, viel an einem particle System gearbeitet.
Anfangs reines AutoIt, doch das wurde mir dann zu langsam, und so habe ich eine freebasic dll mit viel mühe und liebe gemacht (Man muss dazu sagen, dass das eines der ersten freebasic Programme von mir ist und sicherlich auch die dll noch Performance Steigerung bekommt).
Wenn ihr die Zeile 45 (direkt unter "While ...") auskommentiert, sieht es noch geiler aus 8).
Spoiler anzeigen
Global $iWidth = 1200, $iHeight = 600, $hColor = 0x88FFFFFF, $sAdd = "", $iAdd = 1
Global $iParticles = 500, $iMinVelo = -2.5, $iMaxVelo = 2.5, $iMinSize = 2, $iMaxSize = 15, $iFriction = 0.025, $iSmaller = 0.25
#include "QuickDraw.au3"
#include <Color.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <Array.au3>
#include "Particles.au3"
Opt("MouseCoordMode", 0)
_QuickDraw_Enable("ParticleDemo using OpenGL(QuickDraw library by Moritz) by Alizame", $iWidth, $iHeight, 20, 60, False)
___DeBug(@error, "Quickdraw startup", @extended)
_QuickDraw_SetRenderTarget($Normal_Buffer)
;~ _Particles_ReConfig(10000, -2.5, 2.5, 9, 10, 1.25, 0.25)
;Func _Particles_Startup($iParticleCount, $iMinVelo, $iMaxVelo, $iMinSize, $iMaxSize, $iFriction, $iSmaller,$iWidth,$iHeight)
If _Particles_Startup($iParticles, $iMinVelo, $iMaxVelo, $iMinSize, $iMaxSize, $iFriction, $iSmaller,0,0) <> 0 Then Exit
;~ Dim $aParticle[750][5]
;~ Dim $aAdd[1][2]
;~ $aAdd[0][0] = 0
;~ $aAdd[0][1] = 0
;~ $iAddCount = 0 ;immer + eins wegen 00
;0=xPos
;1=yPos
;2=xVelocity
;3=yVelocity
;;4=StartTime
;;5=EndTime
;4=Radius (0 = False)
For $i = 0 To 18
_Color()
Next
AdlibRegister("_FPS", 1000)
;~ AdlibRegister("_Color", 250)
;~ AdlibRegister("_Update", 100)
$iFPS = 0
;~ $hTimer = TimerInit()
[/autoit] [autoit][/autoit] [autoit]While ( _QuickDraw_Running() And (GUIGetMsg() <> $GUI_EVENT_CLOSE))
_QuickDraw_ClearBuffer(0xFF000000)
If _IsPressed("01") Then
$iMouseX = MouseGetPos(0)-10
$iMouseY = MouseGetPos(1)-10
;~ $Timer = TimerInit()
;~ _AddParticle($iMouseX, $iMouseY)
For $i = 0 To 20
_Particles_Add($iMouseX, $iMouseY)
Next
;~ ToolTip($iMouseX&" "&$iMouseY,0,0)
;~ ToolTip(TimerDiff($Timer),0,0)
EndIf
;~ _MoveParticle()
_Particles_Move()
For $i = 0 To $iParticles
_QuickDraw_Circle(_Particles_GetX($i), _Particles_GetY($i), _Particles_GetRadius($i), $Draw_Fill, $hColor)
Next
_QuickDraw_SwapBuffers()
Sleep(1)
$iFPS += 1
WEnd
_QuickDraw_Disable()
_Particles_Shutdown()
Func _FPS()
ToolTip($iFPS, 0, 0)
$iFPS = 0
;~ _Color()
EndFunc ;==>_FPS
Func ___DeBug($iError, $sAction, $iExt = 0)
Switch $iError
Case -1
ConsoleWrite(@CRLF & "-" & $sAction & @TAB & "@extended: " & $iExt & @CRLF)
Case 0
ConsoleWrite(@CRLF & "+" & $sAction & " - OK" & @CRLF)
Case Else
ConsoleWrite(@CRLF & "!" & $sAction & " - FAILED" & @TAB & "@error: " & $iError & @TAB & "@extended: " & $iExt & @CRLF)
Exit
EndSwitch
EndFunc ;==>___DeBug
Func _Color()
$hColor = 0x88000000 + _NewColor()
EndFunc ;==>_Color
;[user='202743']SEuBo[/user]
Func _NewColor()
Local $iStep = 5
Local Static $aRGB[3] = [255, 45, 45], $iIndex = 0, $fDown = False
If $fDown Then
$aRGB[$iIndex] -= $iStep
If $aRGB[$iIndex] <= 45 Then
$aRGB[$iIndex] = 45
$iIndex = Mod($iIndex + 1, 3)
$fDown = False
EndIf
Else
Local $iHoch = Mod($iIndex + 1, 3)
$aRGB[$iHoch] += $iStep
If $aRGB[$iHoch] >= 255 Then
$aRGB[$iHoch] = 255
$fDown = True
EndIf
EndIf
;~ ConsoleWrite($aRGB[0] & @TAB & $aRGB[1] & @TAB & $aRGB[2] & @TAB & @CRLF)
Return _ColorSetRGB($aRGB)
EndFunc ;==>_NewColor
Das Ganze drum herum mit der Dll wird vielleicht später noch eine UDF.
H&U : Kann man irgendwie mit freebasic und dllcall machen, dass man ein struct/Array zurück bekommt? Ich denke das wäre nämlich stark Performance steigernd!
PS.: Kritik und Lob ausdrücklich erwünscht!
PSS.: Im Bild mit Zeile 45 auskommentiert.
lg Ali