ppackage

hi,

Im currently try to handle ppackage and stumble into some issues (panda 1.7.1):

  1. if i pack everything into one single p3d the sound (openal) is messed up + some files seems to miss

← missing sounds + missing showCollisions (which works correctly if called from the ide)

  1. i can load a file added to the all-in-one p3d without problems but if i seperate it into a package and try it to load it from a py in this package it simply fails (cannot find file but it should be there according to the contents.xml).

  2. the auto-update seems to have a “cooldown” (or is maybe completely broken?) if used locally (with file:///). If I made a change I had to delete the folders in the hosts dir to get the changed files.

p.s: found in the panda3d.cvs.sourceforge.net/view … nda3d.pdef → excludeModule . Maybe it should be added to the manual?

And i have another question:
file(“src/gamedata/ADDITIONAL.DES”,newDir=“gamedata”,extract=True) ← how/where can i open that file from within the p3d if it is extracted?

I had the same problem and I solved with this kind of code (I don’t know if this is the best approach, though):

( ExecutionEnvironment.getEnvironmentVariable( 'MYPACKAGE_ROOT' ) if base.appRunner else '../MyPackage' ) + '/path/to/file.ext'

Anyway, this happens only with some kind of files (the ones that aren’t added to model path, I think).

You can double check your analysis of the contents of the package with multify -tvf yourPackage.mf.

I also experience it if I add a package.

Already tried multify but it failed (maybe because its a mf.pz file).
Thanks for your code but does not it break the “normal” execution from the IDE?
btw I tried to generate the packages and the p3d with only one pdef but it seems like the p3d needs the contents.xml first and i was not abled to force generating it during the pdef execution, so that the p3d can find it directly. Is there a way to “merge” both steps into one file (not very important just a little issue; the focus lies more on the other issues)?

Have you tried this?

punzip yourPackage.mf.pz; multify -tvf yourPackage.mf

Sorry, I don’t understand, can you elaborate please?

In my case, I’ve a Sconscript script which initially invokes the creation of the packages, uploads them and finally it creates the p3d file. So, I don’t know how you can do this in only one command. But you could try to define a single pdef file with both packages definition and your p3d definition: I haven’t read anything against this approach, so you could experiment with that.

Thanks for this punzip tip. Works like a charm and the file was there(as excepted).

To the “if-else” thingy: well i was just confused by the "else ‘…/MyPackage’ " because i would expect something like ‘’ or ‘.’. Anyway it will be a bit messy to add this to every single codecs.open call but i guess i have no choice.

And the “all-in-one” file approach fails due to the described behaviour (missing contents.xml during execution because it is written after the pdef is closed and i found no way to dump it during execution).

EDIT (IMPORTANT NOTE for follower):
‘MYPACKAGE_ROOT’ has to be interpreted as ‘[PACKAGENAME]_ROOT’ so in my case it was ‘SCHLEICHFAHRTGAME_ROOT’!

You’re right, mine wasn’t a brilliant example.

It’s true, maybe a context manager could be a more elegant solution.

Any idea how i could allow a user to edit a configfile within the p3d (or at least a copied local version)? Because in “C:\Users\Nox\AppData\Local\Panda3D\start” should be the file (according to a print of the location) but even if i define the file as a “extract=True” file it wont show up there (i guess it will be anywhere else). I already thought about an editor for the (more or less text) file within the p3d itself but i want to avoid writing a panda3d-text-editor myself.

I never faced this problem (in my case the configuration file is generated at runtime during the first launch and I store it in the start folder), I hope other users could help you. Anyway, I was looking at the sources, and Packager.py line 3299 says:

So, I don’t know if this exactly what you want. Have you checked if the file is there during runtime?

Yeah it is placed here:
C:\Users\Nox\AppData\Local\Panda3D\hosts\533b040c609dedcaf5b03df86a1d1dc2\schleichfahrtgame\0.1\gamedata (with extract = True). I can change this file but the change is simply overwritten if i start the game again. I guess I have to make an explicit local copy of it.

Some example code how i solved the “local config file” issue (importer.DesReader is an extended RawConfigParser):

import hashlib

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        
        if base.appRunner:
            path                = ExecutionEnvironment.getEnvironmentVariable( 'SCHLEICHFAHRTGAME_ROOT')
            srcdata             = open(path + "/gamedata/ADDITIONAL.DES","rb").read()
            globalvar.additional= importer.DesReader("ADDITIONAL.DES", False) if os.path.exists("ADDITIONAL.DES") else None
            m                 = hashlib.md5()
            m.update(srcdata)
            hash = str(m.hexdigest())
            
            if not globalvar.additional or hash != globalvar.additional.get("Version","Hash"):
                des = open("ADDITIONAL.DES","w+b")
                des.write(codecs.getencoder("cp850")("[Version]\r\nHash = " + hash + "\r\n\r\n")[0])
                des.write(srcdata)
                des.close()
                globalvar.additional = importer.DesReader("ADDITIONAL.DES", False)
        else:
            globalvar.additional = importer.DesReader("gamedata/ADDITIONAL.DES", False)

In words: I just compare the hash of the original file in the package with the stored hash within the local copy. If the local copy does not exists or the original file has changed the local copy will be rewritten.