Python Forum
Pygame Particle Generator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pygame Particle Generator
#4
(Aug-25-2017, 11:14 AM)DeaD_EyE Wrote: Cool :-)

One small tiny improvement: Put surface_cache (line no 37) into the function.

I wasn't sure what you meant, so I tried it out. I thought only lists worked like that, not dicts. Neat :)
>>> def cached(key, cache={}):
...   if key in cache:
...     return cache[key]
...   print("cache miss!")
...   cache[key] = "spam"
...   return cache[key]
...
>>> cached("eggs")
cache miss!
'spam'
>>> cached(42)
cache miss!
'spam'
>>> cached("eggs")
'spam'
Either way, I'm not sure it's needed. It just felt a little wasteful to have 1000 copies of the exact same thing in memory, so blitting one copy in multiple places felt better lol
Reply


Messages In This Thread
Pygame Particle Generator - by nilamo - Aug-25-2017, 05:12 AM
RE: Pygame Particle Generator - by Larz60+ - Aug-25-2017, 08:50 AM
RE: Pygame Particle Generator - by DeaD_EyE - Aug-25-2017, 11:14 AM
RE: Pygame Particle Generator - by nilamo - Aug-25-2017, 12:52 PM
RE: Pygame Particle Generator - by DeaD_EyE - Aug-27-2017, 09:21 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020