Gamestudio Links
Zorro Links
Newest Posts
Z9 getting Error 058
by k_ivan. 04/25/26 19:13
ZorroGPT
by TipmyPip. 04/25/26 16:09
Stooq now requires an API key
by jcl. 04/13/26 09:42
Strange "Alien" Skull created with >Knubber<
by NeoDumont. 04/10/26 18:58
400 free seamless texture pack downl. here !
by NeoDumont. 04/08/26 19:55
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (TipmyPip, 1 invisible), 3,464 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
valino, juergenwue, VladMak, Geir, ondrej
19209 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
best practice to remove a loop sound #299475
11/24/09 09:05
11/24/09 09:05
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
I use a code similiar to the following:

Code:
action play_snd() {	
	SOUND* snd = snd_create(my.string1);
	int x = 0;
	var sound_handle;	
	if (snd != NULL) {
		sound_handle = ent_playloop (my, snd, 100);
	}	
}



The problem is that the sound that is created by snd_create isn't removed from memory when a new level is loaded.

I'm currently setting a variable "levelLoaded" when changing the level, so that the code looks something like this:

Code:
action play_snd() {	
        ENTITY* thisEnt = my;
        my = NULL;
	SOUND* snd = snd_create(thisEnt.string1);
	int x = 0;
	var sound_handle;	
	if (snd != NULL) {
		sound_handle = ent_playloop (thisEnt, snd, 100);
                while(levelLoaded == 1) { wait(1); }
                snd_stop(sound_handle);
                ptr_remove(snd);
	}	
}



Is there a better way to do this?

Regards,
Pegamode.

Re: best practice to remove a loop sound [Re: pegamode] #299479
11/24/09 10:13
11/24/09 10:13
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
I'm currently thinking about storing the handles of such objects that were dynamically created in a c-container. With those handles I could do a snd_stop and then remove the pointer by getting it per ptr_for_handle.

So I could get rid of

while(levelLoaded == 1) { wait(1); }

and the functions won't run in background anymore.

Any other suggestions?

Last edited by pegamode; 11/24/09 10:20.
Re: best practice to remove a loop sound [Re: pegamode] #299482
11/24/09 11:28
11/24/09 11:28
Joined: Jul 2000
Posts: 28,094
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,094
Frankfurt
I would not care about individually stopping sounds, but just call

snd_stopall(3)

when you change the level. That's what the snd_stopall commands were made for.

Re: best practice to remove a loop sound [Re: jcl] #299485
11/24/09 11:52
11/24/09 11:52
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Hey ... that's just the hint I needed ...

I haven't seen the snd_stopall command at all :-( ... shame on me ...

That makes it a lot easier for me. I just store the pointers of my dynamically created objects and then remove them when changing the level.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1