Help add play time to particle

Blitz3D Forums/Blitz3D Programming/Help add play time to particle

Guy Fawkes(Posted 2008) [#1]
Hi. I'm having a problem trying to add the amount of song play time to the particle's life time.

Optimized Code:



The line of the particle life:



Inside CreateEmitter_Waterfall()

Basically, I want the songs play time to be the particle's life time =)

Any help would be GREATLY appreciated =)

~DarkShadowWing~


Guy Fawkes(Posted 2008) [#2]
anyone? please. it would be greatly appreciated. I'm on a time schedule.... =/

~DarkShadowWing~


Mahan(Posted 2008) [#3]

Hi. I'm having a problem trying to add the amount of song play time to the particle's life time.

Basically, I want the songs play time to be the particle's life time =)



I'll try to help but first I need some clarification:
* Are you sure you want each particle to live as long as a song?

That sounds very long for a particle to be honest. I can however understand why you would like the particle effect to live throughout the song.

If this is the case you should probably read up on particle effects and learn about emitters and particles and their responsibilities. (Emitters and particles are standard parts of most particle systems)

* What happens when you run your program,and how is that different from what you want to happen?

* If you want quick answers I'd strongly recommend you to make small example snippets that demonstrate whats happening along with the descriptions of what you'd like to happen.

* If you have debugged some of the problem yourself and pinpointed the problem to a certain line it will also help others on this forum to help out.

* When you do examples try to make them as small as possible (while still demonstrating the problem) and make them depend on as few external libs/userlibs as possible. It's easier for people to feel motivated to try to recreate your problem if they don't have to spend an hour trying to set up an rig that will run the program in the first place.


Guy Fawkes(Posted 2008) [#4]
1) I would like the particle to live through the song. Otherwise, my project is pointless. Thats the whole idea. 2) I already showed an example above. 3) What i need, is a variable I can use as the particle's lifetime. The PROBLEM is the function w/ the particle has to be called BEFORE the loop. It wont let me use a variable AFTER the song has been called.

~DarkShadowWing~


Mahan(Posted 2008) [#5]
I found this information (http://www.x-pressive.com/ParticleCandy/html/feeding.html) and i guess this is what you need:



UPDATING ATTACHED PARTICLE TYPES
With version 1.4.9, a new command has been introduced:

Emitter_UpdateSlot MyEmitter%, SlotID%, A%, B%, C%


Using this command, you can change a particle type's emission rate, start time and duration at any later time again. The parameters are the same as with the AddParticleType()-command above:
A = Delay time (in milliseconds) of that particle type
B = The duration of the particle emission in milliseconds
C = Emission rate per second.

Note, that you must provide an Emitter ID and a Slot ID here. A Slot ID can be obtained when you attach a particle type to an emitter:

SlotID% =
Emitter_AddParticleType (MyEmitter%, MyParticleType%, A%, B%, C%)


So Slot ID is the returned slot number of the emitter where this particle type has been attached to. To learn more about an emitter's particle slots, please refer to this chapter.




It should allow you to update the added particle-types after the song has been loaded with the correct playtime. (Note that you'll have to save a handle to the particle types when you first create them, to be able to update them later)


Also i see another (very probable) problem with the code:

global play_time

function playtime(song$)
  if songtype('something') then return play_time = mcimp3length(snd%)
end function

; later inside the loop:


play_time = playtime(song$)



The construction "return play_time = mcimp3length(snd%)" is probably not what you want. What this means is that if the variable play_time is the same as mcimp3length(snd%) then return True (i.e. the integer 1) as return from the function.

Most of the time play_time will probably not be equal to mcimp3length(snd%) and therefore you'll get False as return from the function and that equals integer 0.

If you instead write it like this it will probably work better:

global play_time

function playtime(song$)
  if songtype('something') then return mcimp3length(snd%)
end function

; later inside the loop:


play_time = playtime(song$)



Note that i return mcimp3length(snd%) instead of returning the result of the comparision between mcimp3length(snd%) and the play_time variable.


Guy Fawkes(Posted 2008) [#6]
What do you mean save the particles to a type? Can you please show me a small example? Its the only way I know how to learn

~DarkShadowWing~


Mahan(Posted 2008) [#7]
I mean exactly like it says in the example:

SlotID% = Emitter_AddParticleType (MyEmitter%, MyParticleType%, A%, B%, C%)


Notice that Emitter_AddParticleType returns a SlotID%. It is necessary that you save this slot id in some structure or variable if you want to use the function.
Emitter_UpdateSlot MyEmitter%, SlotID%, A%, B%, C%.


As you see the Emitter_UpdateSlot MyEmitter% takes the slotId as a parameter and to get a valid slotId you have to save it somewhere when calling Emitter_AddParticleType to have it later on in the main-loop after you have loaded a new song and call Emitter_UpdateSlot MyEmitter% afterwards.


Guy Fawkes(Posted 2008) [#8]
I tried that. Can you show me a small example? B/c I took your advice, and it still didnt work.

Heres what I have:

Misc:



Call for particle:



Functions:



Loop:



The problem is this line:



The problem is that as you see, I must call the emitter function BEFORE the song plays, thats why it returns 0 on Emitter_AddParticleType.

I need it so it happens EVERY time I play a song =)

~DarkShadowWing~


Ross C(Posted 2008) [#9]
What does your time schedule relate to?


Guy Fawkes(Posted 2008) [#10]
If I dont get done by January, I'm gonna have to trash the project. I need to finish it on time, so I can start selling it. I want to hopefully get a patent for it. Or w/e I have to do to sell it on store shelves.

~DarkShadowWing~


Mahan(Posted 2008) [#11]
I see that you still haven't fixed the Function playtime(snd%) in your post #8 as i suggested in my post #5, so I made a little example program that illustrates the problem a bit more clear.

Imho issues like this are should probably be posted in the beginner forums, but it's not my decision.

Global song_length


Function ExampleGetSongFunc()
	Return Rand(1500, 2500)
End Function

Function EpicFailSongLength%()
	Return song_length = ExampleGetSongFunc()
End Function

Function CorrectSongLength%()
	Return ExampleGetSongFunc()
End Function


Graphics3D 640, 480
While Not KeyHit(1)
	Cls
	Text 0,0, "Epic Fail returns: " + Str(EpicFailSongLength%())
	Text 0, 10, "Correct returns: " + Str(CorrectSongLength%())
	Flip
	Delay(1000)
Wend



Guy Fawkes(Posted 2008) [#12]
i see. i know what you're doing. the prob is, i just dont know how to update the below lines:



as its needed in CreateEmitter_Waterfall() in order to work. is it not? PLEASE do correct if Im wrong.


Ross C(Posted 2008) [#13]
No offensive here intended, but how can you have dead lines, and stick to them, using a programing language you don't understand? All the best though.


Mortiis(Posted 2008) [#14]
No offensive here intended, but how can you have dead lines, and stick to them, using a programing language you don't understand? All the best though.


I second that.


Guy Fawkes(Posted 2008) [#15]
PLEASE. I REALLY need help w/ this. I'm willing to send anyone who is willing to help me fix this very last problem the ENTIRE source. I'm desperate. I'll give whoever helps fix it a free copy of the final version AND any updates afterwords for free.

~DarkShadowWing~


Guy Fawkes(Posted 2008) [#16]
PLEASE. This is the FINAL problem im having w/ it....

How do I get the variable into the Emitter_Addtype and have it update so it shows the particle?


Guy Fawkes(Posted 2008) [#17]
Kev, I need your help 1 last time....

Please


Mahan(Posted 2008) [#18]

i see. i know what you're doing.



No I don't think you do. If you understood the importance of my suggestion in post #5 (and very clearly exemplified in post #11), you'd know that this is one big source to your problem. The way you have written it play_time will probably be stuck on 0 (false/zero). I'm pretty sure of this even though i have never run your code.

Furthermore post #5 shows you the info you need to use to update the particle system "on the fly". Note that I have never in my life used that particle system but nevertheless i find the info that i found with google on their site clear as water to understand.

I took some time and checked other posts you've made on this forum and you seem to ask people to do the programming for you, which I find a bit strange since you apparently try to make an releasable product. When you write things like this ...

I'm on a time schedule.... =/


... and ...

Can you show me a small example?


... again and again it sounds to me that you don't really want to learn this language or understand the problems at hand, but rather get some ready code that will magically solve your problems for you.

I cannot speak for everybody here, but for my part I really enjoy helping people struggling with concepts and algorithms to understand how things work. Likewise I'm very thankful when others show me new things I haven't been able to grasp before.

All information you need to resolve this matter can now be found in this thread (I'm >95% sure about this). It's now mostly a matter of wanting to learn it and use it correctly on your part.

My hottest tip is the debugger. Use the Stop-keyword and then step through you own code and look at the variables at the same time to get a good grip on what your program is actually doing.


Guy Fawkes(Posted 2008) [#19]
i fixed that..... i take some offense to this post... i do NOT want people to do it for me. The ONLY way I know how to learn is by seeing something as CLOSE to my code I show you as possible. I will even PROVE I fixed it. It wont WORK b/c you CANT repeat the CreateEmitter_Waterfall() function. And I cant learn when people give me problems about it. Im sorry, but Im already upset about something else..

I know you're trying to help, I'm not saying you're the 1 giving me problems b/c you're not. It's some other people on this forum, and i wont give names.

Anyway, I fixed the function:



If I could see an example, thats AS CLOSE to MY code as you can, THEN I might understand. The rest of my code should be in post 1.

~DarkShadowWing~


Mahan(Posted 2008) [#20]
That function you got there it looks a lot better!

(of course I'd recommend against having both local and global variables called the same thing, like play_time, but I don't wanna bother you about it to much because what you wrote there should work)

Now given that I don't have access to the libs you've got I have only quickly glanced the docs, but I'll try to give some hints from how I believe it works:

Inside you function Function CreateEmitter_Waterfall% () I'd recommend you save the slots where the three particle types are added.

This code right now looks like this:

	Emitter_AddParticleType EM, P1, 0,play_time,115
	Emitter_AddParticleType EM, P2, 1000,play_time-1000,40
	Emitter_AddParticleType EM, P3, 0,play_time,50



I'd do this:

	emitter_slot1 = Emitter_AddParticleType EM, P1, 0,play_time,115
	emitter_slot2 = Emitter_AddParticleType EM, P2, 1000,play_time-1000,40
	emitter_slot3 = Emitter_AddParticleType EM, P3, 0,play_time,50


Now what are the emitter_slot* variables? Well we'll need to access them from elsewhere so I'd suggest to just declare them global, right beside your global play_time variable:

Global play_time
Global emitter_slot1%
Global emitter_slot2%
Global emitter_slot3%


Now we've save those for future use. And what might that be?

Inside your function Function Update_Particle(EM8) You've got a new set of Emitter_AddParticleType calls.

I think you should change those calls into the calls Emitter_UpdateSlot MyEmitter%, SlotID%, A%, B%, C% that i cut&pasted into post #5.

And now i think you see where the saved emitter_slot* are going, don't you?

These calls are your way of modifying existing Particle type slots inside a "living" emitter with new parameters.

At least thats how I think this works.


Guy Fawkes(Posted 2008) [#21]
Thanks mate. Im CLOSE. Can you please tell me what im doing wrong now?

I looked through particle candy, and there is a function that makes this easier. ( Emitter_IsActive(Emitter%) )

Globals:



Loop:



Functions:



~DarkShadowWing~


Mahan(Posted 2008) [#22]
I really don't know. :-)

The code examples a beginning to look reasonable, but I am not able to see the whole code or run it myself.

I got a suggestion though: Why don't you write a completely separate program in a separate folder just to try out this feature?

If you want to try out how "Updating a particle system on the fly, making it run for exactly x seconds", it's a real advantage to try out that without all the rest of the code.

I develop software for a living and i use this technique 2-5 times a week to try out some stuff or experiment to see how something behaves "out of context".

Also while you're at it, try some debugging! You'll go from "shit, this thing does not work at all!" to "What? is play_time set to zero at this time? It can't be? I'll have to check the calc()-function once again!"


stayne(Posted 2008) [#23]
If your song is still playing check to make sure the emitter is still active...

If play_time < mcimp3length and Emitter_IsActive(EM1) = False then StartEmitter(EM1).


Guy Fawkes(Posted 2008) [#24]
Mahan. If I sent you the code, could you at least look at it? I think it might work if theres a way to create a Emitter_exists() function. Emitter_IsActive() just wont do it for me.

stayne, I did, and it made no difference to me.

~DarkShadowWing~


Guy Fawkes(Posted 2008) [#25]
OMG! IDK HOW! BUT I FIXED IT! HAHA! THIS IS AMAZING! There's only ONE SMALL prob left. when it repeats, it doesnt restart the Emitter. o.o

~DarkShadowWing~


Guy Fawkes(Posted 2008) [#26]
Guys. I have a few probs here. I need the particle to loop EVERYTIME the music is played. Not just once then stop. Also, for some reason, my particles are being effected by play_time. Idk why, but when you use sparks for example, it doesnt look like sparks. It looks like smoke.. =/

Anyway, here's my code:



These are the only 2 known problems left w/ my code. Please help 1 last time. Anyone who can help will get a free copy of my final project and all updates free afterwords if any =)

Thanks again! =)

~DarkShadowWing~


Guy Fawkes(Posted 2008) [#27]
I will upload my project compiled.


Guy Fawkes(Posted 2008) [#28]
Here's my compiled beta. I hope you guys understand what I'm trying to fix. =)

http://www.wikiupload.com/download_page.php?id=84801


Ginger Tea(Posted 2009) [#29]
ran the exe (sure hope i dont have any trojans because of it :p)
no matter what mp3 i load no particles appear and each time i click on a particle it says now load a song
"its playing the damn thing already"

If I dont get done by January, I'm gonna have to trash the project. I need to finish it on time, so I can start selling it. I want to hopefully get a patent for it. Or w/e I have to do to sell it on store shelves.


from what i could gather reading this thread you want some form of visualization ala windows media player
well thats the patent idea shot down for a start
and iir YOU would have to pay for the mp3 licence (perhaps even on freeware?)
edit: or was that only for encoding?

sell it?
not in that state
half of the menu's are just 'odd'
open
o
a>
quit

o and a are what exactly
and loop loops regardless if i click it on or off

seeing as you get windows media player 'free' with windows im always warey of buying something that does 'just the same' but better
so having seen 'it' what is 'it' meant to be if it isnt what i think it is, just a basic mp3 visualization program

edit:
and im not coming at this from a coding stand point as youve done more coding than i have (just ask anyone here ;) ) im coming at this from an end user/customer stand point
i want to know what you are 'selling' and what it can do


Guy Fawkes(Posted 2009) [#30]
Well. What it can do is play 3D particles in different 3D scenes, such as a valley w/ a rocky waterfall, etc. And much more. As for the license, I already bought some mp3, midi & wav source from someone but right now I need some help to fix it. The menus are only in beta. I fix them whenever the program works correctly. The particles work on my end just not correctly. I'm gonna build a readme file today and recompile, so there won't be any more problems like this. As for the loop thing thanks for reminding me, that's another glitch I have NO idea how to fix.

I tried loop1 = 1-loop1 : loop1=wb3d_checkmenu() or w/e, and it acted up. so i took it out til it can be fixed.

Any more glitches, PLEASE let me know.

Also, can anyone help me fix these 2 glitches?

Thanks for all the help! =)

I really appreciate it =)

~DarkShadowWing~


Ross C(Posted 2009) [#31]
I don't really get whats supposed to happen? I load the app. Choose a menu item, then have to go back into file, open an .mp3, then choose my particle type and it tells me again i have to load a song. The song plays anyway, but nothing happens. No particles?


Ross C(Posted 2009) [#32]
Ok, i got the fountain one to work. If i click on fountain again, i get a lib error. TBH it looks like the particle candy demo.


Guy Fawkes(Posted 2009) [#33]
I never said I was finished, lol. These are just tests. I'm gonna make my own particles when I'm done. Right now, I don't get why the particles are coming out wrong. The only thing I know, is if you change the play_time variable in CreateEmitter_blah() to an actual #, it looks right, but if u dont, then it looks messed up. For instance, try the spark particle. You shall see what I mean. Also, I dont get why waterfall wont work. I tried everything. Also, the particle only plays once per song loop. I need it to play everytime the song loops. And I tried loop1=1-loop : wb3d_checkmenuitem(loop, 5) and it wont turn on the loop if clicked once, then if clicked again , it wont turn off the loop.

~DarkShadowWing~


Guy Fawkes(Posted 2009) [#34]
I'll recompile into debug mode, b/c it's not giving me an error.


Guy Fawkes(Posted 2009) [#35]
Edit: Nvm. I found the lib error. Fixed.

~DarkShadowWing~


Guy Fawkes(Posted 2009) [#36]
Ok. I fixed the particle problem. the only 3 problems left is clicking on the loop option, allowing the particle to loop as many times as the song, and clicking on a particle button more than once results in window message.

~DarkShadowWing~


Ross C(Posted 2009) [#37]
Ah, so it isn't programmed to emit particles yet. Interesting app. What will it be used for?


Guy Fawkes(Posted 2009) [#38]
Now it is. Lol. It is gonna be a media player capable of playing 3d particle while u listen to ur music (U can set the volume of the particle sound later on), among alot of other things. I'm HOPING if I can get blitz movie, it will play videos, although the particles wont activate during that. :P

Also, if u know a fix for Case 5 in the select code, (AKA Loop option), then PLEASE tell me. b/c loop1=1-loop1 : wb3d_checkmenuitem(loop, 5) didnt work.

Thanks again! =)

~DarkShadowWing~


Ross C(Posted 2009) [#39]
I'm afraid i'm not familiar with the GUI system, so i can't help you too much.

loop1=1-loop1 << that obviously works perfectly, so it's a problem with the code used to operate the lib, or particles candy.


Guy Fawkes(Posted 2009) [#40]
i know. its only supposed to checkmark the menu when the menu "loop" is selected. =/ What I need is a function that tells the gui when you select a menu option.

~DarkShadowWing~