I would suggest instead of using a massive 4096/4096 texture map, use the dynamic texture to create a mask for several smaller repeating textures.
Took 2.16 seconds to load “120”.
Clicking and drawing drops the framerate down to 40FPS.
Just a note on the code:
You have some cryptic stuff going on and some rather long functions. Even if things aren’t used in multiple places, the functions should be broken down, particularly ones like ‘fill_areas’ which is 150 lines long and has great stacks like this:
for i in range(3):
for key in paper:
area_color = paper[key]
if area_color != 0:
search = [[-1,0],[0,1],[1,0],[0,-1]]
for n in search:
n_key = (key + n,key + n)
neighbor_tile = paper.get(n_key,None)
if neighbor_tile == 0:
roads[n_key] = 1
paper[n_key] = area_color
Also, I have discovered in workin in CaveX16 that you need to separate the map into various parts. Initially I had a map class that contained everything about the map, and hit some issues with that becoming unmanagable when I tried to implement pathfinding on top of resource collection on top of … It ended up with me re-writing the entire map system.
What I ended up doing was to create a separate ‘node’ class representing each logical section. Then that node could be manipulated.
Unfortunately I didn’t fully avoid a map superclass, but if I were to do it again I would have each node know about it’s neighbour nodes, have each node have a plot function that will draw on it’s section of texture etc.
You may also want to consider breaking out constants to the top of the script, such as:
MAP_SIZE = 4096
TILE_PATH = bge.logic.expandPath('//brushes//')
There are also some tricks, like to join sections of a path in a cross-platform manner, use:
os.path.join(path1, path2, path3, path4)
Things like loading the brushes don’t need to be part of the map class. Perhaps part of a brush handling module.
Also, I’d reccomend using the text in an external editor, and firing up the dreaded pylint and pep008 checkers. Your code looks good stylistically, but those two will force you to maintain the style (and tell you when functions are getting too long and complex).