prevent forking a huge number of player processes by limiting them to
authorMichael Gernoth <michael@gernoth.net>
Tue, 12 Feb 2008 20:22:44 +0000 (21:22 +0100)
committerMichael Gernoth <michael@gernoth.net>
Tue, 12 Feb 2008 20:22:44 +0000 (21:22 +0100)
a maximum of 10 per second

src/sim/w_sound.c

index 3f2ec38..7558e47 100644 (file)
@@ -271,9 +271,22 @@ ShutDownSound()
 MakeSound(char *channel, char *id)
 {
   char filename[256], player[256];
+  static struct timeval last = {0, 0};
+  struct timeval now;
+  unsigned int diff;
   int i;
   pid_t pid;
 
+  gettimeofday(&now, NULL);
+
+  diff = ((now.tv_sec - last.tv_sec) * 1000000) +
+    (now.tv_usec - last.tv_usec);
+  
+  if (diff < 100000)
+    return;
+
+  last = now;
+
   if (!UserSoundOn) return;
   if (!SoundInitialized) return;
 
Impressum, Datenschutz