Help loop slow down
Blitz3D Forums/Blitz3D Programming/Help loop slow down
| ||
Can anyone help me fix this loop so it will stop lagging? Your help is GREATLY appreciated. It works, but the problem is, it repeats & repeats & repeats the function request() or notify() depending if a file is dragged to screen. I need it to activate request() and notify() 1 time. ~DarkShadowWing~ |
| ||
Now the problem is my whole select code. Any help is GREATLY appreciated =) Can someone please help me fix this? ~DarkShadowWing~ |
| ||
anyone? |
| ||
Once you've been through once use WB3D_FlushEvents. I don't see why you would need this - check the rest of your code, and use step by step debug. I did something similar - but it was my code's fault that I kept calling the same routine. |
| ||
thanks but it doesnt help if i dont see an example. ~DarkShadowWing~ |
| ||
ok, i know you guys have your own things to do. But seriously, if you can't answer, don't. otherwise, please show me examples. i can't learn if i don't have an example. ~DarkShadowWing~ |
| ||
Mmm... getting prickly. Perhaps not one's first choice of attitude to endear yourself to those you seek help from. |
| ||
I'm sorry, but do you know how hard it is when all's you do all day is wait for an answer that you wont get on a forum? I've had a not so good day. Lets leave it at that. I apologize for any attitude I may have used. Now. is there anything you can do to help fix this example? If not, I understand ~DarkShadowWing~ |
| ||
Have you tried putting it all in a function and doing something like this:myTimer=millisecs() While myLoop ; your main loop is here if millisecs()-MyTimer >= 1000 then MyFunction() MyTimer=millisecs() end if Wend This above should call "MyFunction" once per second. Adjust for the time you want it to be called, and voila'. Unfortunaly I never played with WB3D, so I can't help you there :( |
| ||
I'll take a guess that the loop "For do_files = 0 To WB3D_CountDroppedFiles()" should start at 1 instead of 0. |
| ||
well. unfortunately, i need the function to run ONCE per drag & drop. i also need the load music function to work but ONE time PER file request open. i think it's loading more than once. it like slows down. and i need the drag & drop to simply work. its not workin.. =/ also, kev used 0 in the for loop, so thats what i use. ~DarkShadowWing~ |
| ||
anyone? i really need a fix for this. ~DarkShadowWing~ |
| ||
You probably have to solve this yourself. Nobody else knows exactly what you are doing and what results you are getting. It might be easier to set aside the real program and write a very simple test. This would respond to "drag and drop" events and ignore everyting else ( excect QUIT, of course ). Instead of doing any sort of processing it would simply display information: event IDs, the number of files dropped, the names of the files as it reads them etc. |
| ||
i already told you what results i want. well. unfortunately, i need the function to run ONCE per drag & drop. i also need the load music function to work but ONE time PER file request open. i think it's loading more than once. it like slows down. and i need the drag & drop to simply work. its not workin.. =/ also, kev used 0 in the for loop, so thats what i use. ~DarkShadowWing~ |
| ||
As Floyd said "It might be easier to set aside the real program and write a very simple test." As I said start tracking through your code line by line to find out why the same code keeps being executed when it shouldn't. In my case I probably spent 6 hours patiently executing the code line by line until I finally spotted the variable (in my surrounding code) that was causing the WB3D code to be called again and again. The variable that I had not set back to zero. I can hear Kev laughing from here. |
| ||
I know, but its not the lag i need fixed. its the code itself. the drag drop has YET to work.. Alls I need is a simple fix. thats all i ask. no offense intended. ~DarkShadowWing~ |
| ||
You didn't say it didn't work at all. You said it worked multiple times. Just a thought: have you applied WB3D_DragAcceptFiles(window,state) to your own window, so that it _can_ accept files? |
| ||
actually, yes i did. "Now the problem is my whole select code. Any help is GREATLY appreciated =) Can someone please help me fix this?" and yes, i did. ~DarkShadowWing~ |
| ||
i looked through the code, and i think 1 of the consts are doing it. when i didnt include the const.bb file then the drag drog SORTA worked. it keeps repeating itself, lagging my code b/c the song keeps loading and loading. can anyone look through the code & say whats wrong? |
| ||
|
| ||
You know. I have waited over 24 hours for an answer. I'm sorry if I sound snippy or incorrect, but all's I need help with is getting the select to work right. Right now, I don't CARE about lag. I provided the constants above because I think there is a constant that is disabling me from drag dropping a file. If someone would PLEASE be kind enough to help me fix this, it would be GREATLY appreciated. ~DarkShadowWing~ |
| ||
If someone would PLEASE be kind enough to help me fix this... We are trying to help, but you need to play a more active role. You haven't shown us any code we can actually run. So the best anyone can do is read some code fragments and make educated guesses. And I guarantee nobody will examine two thousand arbitrary hex values looking for a bad one. I still suggest you write a very simple test app. This would probably need about three constants out of the enormous list you posted. You could put them in the code directly, no need for any Includes. There are two benefits to this. The main one is to clarify your understanding of how drag-drop and events are being handled. The other is that you will have some reasonably sized code to post here. There would then be a realistic chance of getting some help. |
| ||
ok. well here's what ill do. do you have an email, or msn, or aim or yahoo? if so, may i please get it? ill send you a small example w/ few constants if you're willing to help me. =) Thanks floyd =) ~DarkShadowWing~ |
| ||
floyd?.. |
| ||
ok. well here's what ill do. Why don't you just do what he suggested instead of coming up with your own version? You're the one asking for help, but you never seem to want to actually do anything to make it any easier to help you. |
| ||
i do. id just like to get his email so i can send him the code. |
| ||
He didn't ask you to send him the code. He said The other is that you will have some reasonably sized code to post here. There would then be a realistic chance of getting some help. Post the code first. Worry about getting his email address later. |
| ||
ok. ill post it. but its only to get debugged. its copyright. =) i apologize for the inconvenience. i just don't like to post code b/c i know some n00bs out there try to steal it & claim it as theirs. thats why i only post portions. but in this case, i REALLY need this fixed so ill post the whole thing. itll be 2 posts, cuz it needs const.bb to run. PLEASE feel free to do whatever it takes to fix it. take stuff out, i don't care. =) Here's the main code: and any id with "EM0" through "EM11". i apologize if this is a bit messed up. im in a hurry. =) Thanks again! =) ~DarkShadowWing~ |
| ||
i was in a hurry, so i forgot to tell ya. It also requires wb3d =) (winblitz3d for those of you that have no idea what that is =) ) ~DarkShadowWing~ |
| ||
You still haven't done any of the things people asked you to do. You say you've been waiting this long and waiting that long for replies, but I didn't realise you meant you had literally been doing nothing and waiting. People asked you to put together a small sample which didn't have hundreds of unused constants, third party dependancies and masses of code unrelated to the problem. All I can think is you can't want this problem solved very badly if you're not prepared to do anything to it yourself. As it stands that's far too much code to have to look at and understand for me to even try. |
| ||
...and if I can quietly sneak in a mention of Code Box at this point... |
| ||
Hey. dont be rude by mouthing off. #1 I'm not waiting for ANYONE to do it for me. I've put together this WHOLE thing so far. All I'm asking for is a little help. ~DarkShadowWing~ |
| ||
I'm not waiting for ANYONE to do it for me. Good, because you won't get any from me with that attitude. I've put together this WHOLE thing so far. It's your (copyrighted) program. You want credit for writing your own program now? All I'm asking for is a little help. No, you're asking for a lot of help, and being pretty ill-mannered and impatient in the process. If you tried this sort of thing on some forums, you'd have been torn a new one long before now. On here, people have been politely urging you to help yourself, and gently pushing you in the right direction so that you might get some help. You, however, seem intent on ignoring them, making no effort to cut that huge mass of code down into something manageable, and instead just repeatedly posting about how desperate you are and how long you've been waiting. So yeah, keep complaining how long you've been waiting, don't cut that code down, don't strip any of the unnecessary third party dependencies out of it, keep telling everyone that *you're* in a hurry while asking them to take a long time to read your pages of code, keep telling anyone who dares to tell you that you're not doing anything to help yourself that they're rude, and keep wondering why you're not getting as much help as you think you deserve. If you change your mind, however, I'll take another look. |
| ||
fine. i apologize. i was just a little upset earlier. i will post an example demo code. ~DarkShadowWing~ |
| ||
heres the code shortened & tested, it still wont work.. |
| ||
Please edit your posts and use the [ codebox ] tags instead of [ code ]? This thread is very hard to peruse as it is. |
| ||
my apologies. i didnt know there was such a function =) Thanks for telling me =) |
| ||
fixed. now. can anyone help me fix this please? it would be greatly appreciated. ive done all i can to narrow it down. thanks =) |
| ||
I'll take a look at your code when I get home this afternoon but you need to work on your patience. You only need to ask for help once otherwise people will pick up on your frustration. You have asked over 10 times in this thread for help. If you can't learn patience you need to find another hobby because programming requires a lot of it... but I think you have realized that already ;). |
| ||
Thanks man =) Ill try. I apologize for bein so pushy. I've had a bad day yesterday. I didn't mean to take it out on all of you.. =/ ~DarkShadowWing~ |
| ||
What version of WinBlitz3D are you using DarkShadowWing? |
| ||
Yeah, he's probably using an old version... I downloaded WB3D and tried his code, and it just gives "Not enough parameters" on WB3D_HotKeyEvent... Try downloading the latest version, man :) (the link where I downloaded it: http://www.whitegatesoftware.com/winblitz3d.zip) EDIT: I commented out the 2 Hotkeyevent lines, and the program ran fine with winblitz3d from the link above. EDIT2: Oops, appears that drag'n'drop isnt really detected... :P EDIT3: Your code is bugged, you're checking for WB3D_EVENT_DRAGDROP inside the Select/Case code block for MENU EVENT. Put the DRAGDROP check below the "end select" for the menu event, and it should work, the drag'n drop is detected... but there still more bugs, since you call "waitevent" just after geting the file list, and there's no event being sent at that time. Try putting some indentation in your code, it would help a lot in cases like this, and also, try to understand how windows events works - they're assyncronous, so "waitevent" doesnt lock your program and keeps waiting for a result, it just keeps sending data all the time. (run the program in debug mode, and put a "DebugLog event" just below event = WB3D_WaitEvent() so you can see what I mean. |
| ||
slotman, here's the results so far it works, yet it still lags: stayne, im using 1.1. ~DarkShadowWing~ |
| ||
ok. i have tried EVERYTHING to be able to fix the lag, but it STILL doesnt work. can someone please be kind enough to help me? Thanks =) ~DarkShadowWing~ |
| ||
What lag? After selecting the file? That's just the time Blitz take to load it into memory :P Use the libs I sent you to play mp3/mid/wav, and it will open the files *much* faster, since it will be streaming then from disk, instead of loading it all to RAM. |
| ||
i am. the problem is, after a while of loading songs, it lags >< ~DarkShadowWing~ |
| ||
I found the problem. how do i fix it? The event keeps lagging b/c it keeps reading. |
| ||
Ok. I found the glitch by using both file => open, and drag & drop. not at the same time. i did this multiple times, i found it also by doing a debuglog event. it kept showing the events over & over. it should only do it once yes? and im using windows xp. also, i dont get why "case tabber" doesnt work. if u dont understand what i said above, feel free to ask me questions =) ~DarkShadowWing~ |
| ||
anyone? please, i NEED to finish this project before January. ~DarkShadowWing~ |
| ||
Someone once asked me what it takes to be a programmer. Answer, one word: Tenacity. (-and lots of coffee). Debug. Debug. Debug. No-one can do it for you. And for your other questions on the forum, raid the code archives, and pick the code apart to learn. No-ones got the time to do it for you. They've all learned the hard and slow way. |
| ||
Thanks. but no thanks. I need help. I dont want it done for me. Alls I need is a lag fix. thats ALL i ask. nothing more. If no one is willing to help, then Ill just take it to another forum, and never come here again. ~DarkShadowWing~ |
| ||
I found the glitch by using both file => open, and drag & drop. not at the same time. i did this multiple times, i found it also by doing a debuglog event. it kept showing the events over & over. it should only do it once yes? and im using windows xp. also, i dont get why "case tabber" doesnt work. Post a small example showing the problem and removing any unnecessary dependencies. |
| ||
heres my code w/o anything added, and dependencies removed |
| ||
heres a working drag&dropInclude "WB3DStyles.bb" ; setup gfx mode. Graphics3D 640,480,16,3 Global RuntimeWindow_hWnd = WB3D_InitializeGUI(SystemProperty("AppHwnd"),10,10,800,600) WB3D_DragAcceptFiles RuntimeWindow_hWnd,True ; cleanup any old creation events, its better to do this before we enter the main ; event loop, when some gadgets are created they generate events. WB3D_FlushEvents ; setup out quit flag, and loop until the flag is set. QUIT = 0 While Not QUIT = 1 Cls ; get an event of the event queue. event = WB3D_WaitEvent() Select event Case WB3D_EVENT_DRAGDROP Select WB3D_EventSource() Case RuntimeWindow_hWnd For do_files = 0 To WB3D_CountDroppedFiles() file$ = WB3D_DroppedFileName(do_files) WB3D_Notify "dropped files",file$,0 Next End Select Case WB3D_EVENT_GADGET Select WB3D_EventSource() End Select Case WB3D_EVENT_WINDOW_CLOSE Select WB3D_EventSource() Case RuntimeWindow_hWnd QUIT = 1 End Select End Select ; generate an internal blitz event Flip Wend ; use notify using external winapi constants. WB3D_Notify "WB3D GUI Window Example","Bye, Thats It I Quit",MB_OK Or MB_ICONASTERISK WB3D_EndGUI() EndGraphics End Sorry but i dont quite understand what you want and whats not working, looking through your post i cant seem to make sence of the problem. looking at your code above i would recommend you use the event loop in such away as my examples. a basic event loop under winblitz3d Include "WB3DStyles.bb" ; setup gfx mode. Graphics3D 640,480,16,3 Global RuntimeWindow_hWnd = WB3D_InitializeGUI(SystemProperty("AppHwnd"),10,10,800,600) ; cleanup any old creation events, its better to do this before we enter the main ; event loop, when some gadgets are created they generate events. WB3D_FlushEvents ; setup out quit flag, and loop until the flag is set. QUIT = 0 While Not QUIT = 1 Cls ; get an event of the event queue. event = WB3D_WaitEvent() Select event Case WB3D_EVENT_DRAGDROP Case WB3D_EVENT_GADGET Case WB3D_EVENT_WINDOW_CLOSE Select WB3D_EventSource() Case RuntimeWindow_hWnd QUIT = 1 End Select End Select ; generate an internal blitz event Flip Wend ; use notify using external winapi constants. WB3D_Notify "WB3D GUI Window Example","Bye, Thats It I Quit",MB_OK Or MB_ICONASTERISK WB3D_EndGUI() EndGraphics End please if you can be clearer of your problem im happy to help kev |
| ||
Well, the problem is. When it starts playing a song (Loads a song into memory), it starts lagging, or taking up memory usage. and it keeps going. I ran some tests, and windows media player doesnt take up memory usage when PLAYING the song. only when LOADING the song. so ONE of the events keeps repeating itself, i think. What I wanna know is how I can play a song multiple times w/o it taking up memory usage, except when loading the song. Thanks Kev =) ~DarkShadowWing~ |
| ||
i would do it like so, i first create an array to hold the playlist. I then load and play the first item in the playlist, finaly i check if the songs still playing if not i free it then move to the next song in the playlist. and example Include "WB3DStyles.bb" ; setup gfx mode. Graphics3D 640,480,16,3 Global RuntimeWindow_hWnd = WB3D_InitializeGUI(SystemProperty("AppHwnd"),10,10,800,600) WB3D_DragAcceptFiles RuntimeWindow_hWnd,True ; quick playlist contains the filename of files To be played Dim playlist$(200) ; the playing loaded_song, and its play status Global loaded_song,loaded_song_playing ; the index of the loaded_song playing Global current_loaded_song_index = 0 ; cleanup any old creation events, its better to do this before we enter the main ; event loop, when some gadgets are created they generate events. WB3D_FlushEvents ; setup out quit flag, and loop until the flag is set. QUIT = 0 While Not QUIT = 1 Cls ; get an event of the event queue. event = WB3D_WaitEvent() Select event Case WB3D_EVENT_DRAGDROP Select WB3D_EventSource() Case RuntimeWindow_hWnd For do_files = 0 To WB3D_CountDroppedFiles() file$ = WB3D_DroppedFileName(do_files) playlist(do_files) = file$ Next End Select ; play first loaded_song in playlist loaded_song = LoadSound(playlist(current_loaded_song_index)) loaded_song_playing = PlaySound(loaded_song) Case WB3D_EVENT_GADGET Select WB3D_EventSource() End Select Case WB3D_EVENT_WINDOW_CLOSE Select WB3D_EventSource() Case RuntimeWindow_hWnd QUIT = 1 End Select End Select Text 10,10,"Playing loaded_song: "+playlist(current_loaded_song_index) ; generate an internal blitz event Flip ; process the playlist process_playlist() Wend ; plays the next loaded_song in the playlist, or reset to the first loaded_song. Function process_playlist() ; return if loaded_songs still playing If ChannelPlaying(loaded_song_playing) = 1 Return Else ; free the memory of the finished loaded_song FreeSound loaded_song ; move to the next loaded_song in the playlist current_loaded_song_index = current_loaded_song_index + 1 ; check we have a loaded_song in the playlist, if we do play it If playlist(current_loaded_song_index) <> "" Then loaded_song = LoadSound(playlist(current_loaded_song_index)) loaded_song_playing = PlaySound(loaded_song) Else ; loop playlist current_loaded_song_index = 0 loaded_song = LoadSound(playlist(current_loaded_song_index)) loaded_song_playing = PlaySound(loaded_song) EndIf EndIf End Function ; use notify using external winapi constants. WB3D_Notify "WB3D GUI Window Example","Bye, Thats It I Quit",MB_OK Or MB_ICONASTERISK WB3D_EndGUI() EndGraphics End there no error checking with the example but it should point you in the right direction kev |
| ||
This helps a little bit. I cant figure out what to do to allow playlist() to be used with file request function: request(). I need to know how to use File => open just like it works for drag & drop. Code: Then it will be PERFECT =) ~DarkShadowWing~ |
| ||
you cant use multi file selection in wb3d openfilerequester, so what you need to do is use a global var that hold the current play list index for the selected files then once your finished with the selection of files call process_playlist() function to check the state of playing files i can add it to the above example but it wont be tonight kev |
| ||
i dont wanna use multiple songs. i want it to work like drag drop, only using File => Open =) ~DarkShadowWing~ |
| ||
this will popup the filerequester and add the selected song to the playlist then start playing it. NOTE theres no error checking you need to add this yourself; open filerequester and select song to play ext$ = "*.mid"+Chr$(0)+"*.mid"+Chr$(0)+"*.mp3"+Chr$(0)+"*.mp3"+Chr$(0) file$ = WB3D_OpenFileRequest("..","..",ext$,"") playlist(0) = file$ ; play first loaded_song in playlist loaded_song = LoadSound(playlist(current_loaded_song_index)) loaded_song_playing = PlaySound(loaded_song) kev |
| ||
Kev. I honestly cant thank ya enough =) You saved my program from disaster =) I was afraid if I couldnt figure it out, I'd have to cancel it due to lag. But it is now fixed. Thanks again! =) ~DarkShadowWing~ |