Article written by Srekel.
This is how I set up the directories (and thus the code) for our game. I did it because it was annoying to have the dlls mixed with the source code. Note that I am not sure how this works in Linux; I have only tried it out in Windows so far. Feel free to use the same structure, or change it however you please.
Table of contents
The directory structure
This is what it looks like on our setup:
- ViolentWorld\ - root directory
- configs\ - contains ogre configs; plugins.cfg and resources.cfg
- dlls\ - contains ogre dlls (and any other dlls you might use)
- gamedata\ - contain non-media game-related data, such as level information
- media\ - same as the directory that comes with PyOgre, but with added files for the project, of course. ๐
- src\ - the python files
Now, in order to get this working, there are some things you will need to change in your initialization of Ogre.
Modifying paths
These are things you need to change to get everything to point in the right place. There is one thing that needs to be explained. The application must be started from the "dlls" directory, because it will only look in the directory it starts at for the dll-files. This means that you need to perform some tricks to get stuff working - because you got the source files in "src", right? Well, it's not that difficult. But I'll get to that.
- Creating the root:
self.root = ogre.Root("../configs/plugins.cfg")
- Setting up resources:
We've based our code on the PyOgre SampleFramework. You should recognize this method, just change it to the following.
def _setUpResources(self): """This sets up Ogre's resources, which are required to be in resources.cfg.""" config = ogre.ConfigFile() config.loadFromFile('../configs/resources.cfg' ) for sectionName, mm in config.getSectionIterator(): if mm: for key, path in mm.items(): ogre.ResourceGroupManager.getSingleton().addResourceLocation(path, key, sectionName)
- Anything else:
Just remember that the program starts in the dlls-folder, so every path reference should begin there. Usually this means doing something like
loadData("../myFolder/" + filename)
Running the game
As mentioned, you need to run the .py file, but you also need to make the program think it's being run from the dlls-folder. How do you accomplish this? With a .bat file! (Probably works with a shortcut as well).
StartGame.bat:
cd dlls python.exe ..\src\GameApplication.py cd ..
Place it in the root folder of your project. What it does is go into the dlls-folder, and then starts the application from there. Quite simple. ๐
Making an executable
If you want to use this with py2exe, well, here's my setup.py:
from distutils.core import setup import py2exe setup(windows=["GameApplication.py"])
Then I use a makeExe.bat file to make things a little bit easier for me:
python setup.py py2exe pause echo "copying" copy dist\* ..\dlls echo "done!" pause
The bat-file is placed in the src-folder.
End notes
That's basically it. There may be better ways to solve this problem that I don't know of - if so, feel free to add something to this page. ๐