Sooo, would anyone be willing to commit this?  Or...?

~ Nathan

On Thu, Oct 4, 2012 at 9:36 AM, Nathan <[email protected]> wrote:

> Andre, I'm not combining paths.  I'm using the string representation of
> the current state of the list of paths to add a unique prefix to the key
> used to cache the image.
>
> For example, if pyglet.resource.path is ['my_sad_theme', 'my_happy_theme'],
>
> ...then the key will end up being the string  "['my_sad_theme',
> 'my_happy_theme']imagename"
>
> If you change the path in any way, then the string representation of the
> entire path list changes, which results in a different unique key, and a
> new image searched for and cached using the new string representation of
> the list as a prefix to the key.
>
> Not quite as elegant as making a hash of the path state and using that as
> a shorter prefix, but it definitely works.
>
> ~ Nathan
>
>
> On Thu, Oct 4, 2012 at 5:35 AM, Andre D <[email protected]> wrote:
>
>> Please use os.path.join to combine paths
>>
>> On Thu, Oct 4, 2012 at 12:58 AM, Nathan <[email protected]> wrote:
>> > Currently, if you set pyglet.resource.path to ["foo"] and load "abc.png"
>> > (foo/abc.png), and then change pyglet.resource.path to ["bar"] and try
>> to
>> > load "abc.png", you still get foo/abc.png, since the caching looks at
>> the
>> > name of the image file only.
>> >
>> > This simple patch makes it so that the images are cached per specific
>> > setting of pyglet.resource.path.  I included the patch as an attachment
>> and
>> > inline below since it's so tiny.
>> >
>> > # HG changeset patch
>> > # User Nathan Stocks <[email protected]>
>> > # Date 1349326606 21600
>> > # Node ID f8102f9ee5b19c43c6129dac070bf393f82e3ef7
>> > # Parent  bf7f6c05275664ed76aab926944fe3a6a74ff022
>> > Made it so that once you load an image, you can still load more images
>> of
>> > the same name by changing pyglet.resource.path.
>> >
>> > diff -r bf7f6c052756 -r f8102f9ee5b1 pyglet/resource.py
>> > --- a/pyglet/resource.py Sat Sep 15 16:48:08 2012 -0500
>> > +++ b/pyglet/resource.py Wed Oct 03 22:56:46 2012 -0600
>> > @@ -504,9 +504,9 @@
>> >          '''
>> >          self._require_index()
>> >          if name in self._cached_images:
>> > -            identity = self._cached_images[name]
>> > +            identity = self._cached_images[str(self.path)+name]
>> >          else:
>> > -            identity = self._cached_images[name] =
>> self._alloc_image(name,
>> > +            identity = self._cached_images[str(self.path)+name] =
>> > self._alloc_image(name,
>> >                  atlas=atlas)
>> >
>> >          if not rotate and not flip_x and not flip_y:
>> >
>> >
>> > Works great for me!
>> >
>> > Thoughts?
>> >
>> > ~ Nathan
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "pyglet-users" group.
>> > To post to this group, send email to [email protected].
>> > To unsubscribe from this group, send email to
>> > [email protected].
>> > For more options, visit this group at
>> > http://groups.google.com/group/pyglet-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "pyglet-users" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/pyglet-users?hl=en.
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en.

Reply via email to