Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - Darkone

Pages: [1]
1
Creative Projects / Python Multiprocessing module issue
« on: February 14, 2010, 06:24:05 pm »
Having a problem with using multiprocessing in conjunction with libtcod

note: lots of commented out stuff from testing different approaches

Code: [Select]
#!/usr/bin/env python
from multiprocessing import *
import time
import libtcodpy as libtcod

#actual size of the window
SCREEN_WIDTH = 46
SCREEN_HEIGHT = 20

#size of the map
MAP_WIDTH = 46
MAP_HEIGHT = 20

color_dark_wall = libtcod.Color(50, 50, 50)
color_dark_ground = libtcod.Color(150, 150, 150)

class Tile:
    #a tile of the map and its properties
    def __init__(self, blocked, block_sight = None):
        self.blocked = blocked
        self.clearance = 0
       
        #by default, if a tile is blocked, it also blocks sight
        if block_sight is None: block_sight = blocked
        self.block_sight = block_sight
   

smap = ['##############################################',
        '#######################      #################',
        '#####################    #     ###############',
        '######################  ###        ###########',
        '##################      #####             ####',
        '################       ########    ###### ####',
        '###############      #################### ####',
        '################    ######                  ##',
        '########   #######  ######   #     #     #  ##',
        '########   ######      ###                  ##',
        '########                                    ##',
        '####       ######      ###   #     #     #  ##',
        '#### ###   ########## ####                  ##',
        '#### ###   ##########   ###########=##########',
        '#### ##################   #####          #####',
        '#### ###             #### #####          #####',
        '####           #     ####                #####',
        '########       #     #### #####          #####',
        '########       #####      ####################',
        '##############################################',
        ]

def make_map():
    global map
   
    #fill map with "unblocked" tiles
    map = [[ Tile(False)
        for y in range(MAP_HEIGHT) ]
            for x in range(MAP_WIDTH) ]
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            if smap[y][x] == "#":
                map[x][y].blocked = True
               
def render_all():
    global color_light_wall
    global color_light_ground
   
    #go through all tiles, and set their background color
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            wall = map[x][y].blocked
            if wall:
                libtcod.console_set_back(0, x, y, color_dark_wall, libtcod.BKGND_SET )
            else:
                libtcod.console_set_back(0, x, y, color_dark_ground, libtcod.BKGND_SET )           
            if map[x][y].clearance >= 1:
                libtcod.console_put_char(0, x, y, str(map[x][y].clearance), libtcod.BKGND_NONE)
               
libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False)

##class threadhandler(threading.Thread):
####    def __init__(self, thread, queue):
####        threading.thread.__init__(self)
####        self.thread = thread[0]
####        self.args = thread[1]
####        self.queue = queue
##    def run(self):
##        while True:
##            task = pool.get()
##            if task != None:
##                thread = task[0]
##                args = task[1]
##                threading.Thread(target=thread, args=args).start()
##                pool.task_done()

def make_clearance(x,y):
    global map
    incrementor = 0
    if not map[x][y].blocked:
        map[x][y].clearance = 1
        incrementor += 1
        increase = True
        while increase == True:
            for iy in range(y, (y + incrementor + 1)):
                if map[x + incrementor][iy].blocked:
                    increase = False
            for ix in range(x, (x + incrementor + 1)):
                if map[ix][y + incrementor].blocked:
                    increase = False
            if increase == True:
                map[x][y].clearance += 1
                incrementor += 1
            else:
                increase = False
                incrementor = 0
#threading.Thread(target=your_function).start()

##class Collision(threading.Thread):
##    def __init__(self, queue, x, y):
##        threading.thread.__init__(self)
##        self.queue = queue
##        self.x = x
##        self.y = y
##
##    def run(self):
##        global map
##        incrementor = 0
##        if not map[self.x][self.y].blocked:
##            map[self.x][self.y].clearance = 1
##            incrementor += 1
##            increase = True
##            while increase == True:
##                for iy in range(self.y, (self.y + incrementor + 1)):
##                    if map[self.x + incrementor][iy].blocked:
##                        increase = False
##                for ix in range(self.x, (self.x + incrementor + 1)):
##                    if map[ix][self.y + incrementor].blocked:
##                        increase = False
##                if increase == True:
##                    map[self.x][self.y].clearance += 1
##                    incrementor += 1
##                else:
##                    increase = False
##                    incrementor = 0

#original function, the ix/iy loops are for checked the new edges every time you expand the square
##def make_collision():
##    global map
##    incrementor = 0
##    for y in range(MAP_HEIGHT):
##        for x in range(MAP_WIDTH):
##            if not map[x][y].blocked:
##                map[x][y].clearance = 1
##                incrementor += 1
##                increase = True
##                while increase == True:
##                    for iy in range(y, (y + incrementor + 1)):
##                        if map[x + incrementor][iy].blocked:
##                            increase = False
##                    for ix in range(x, (x + incrementor + 1)):
##                        if map[ix][y + incrementor].blocked:
##                            increase = False
##                    if increase == True:
##                        map[x][y].clearance += 1
##                        incrementor += 1
##                    else:
##                        increase = False
##                        incrementor = 0

#generate map (at this point it's not drawn to the screen)
make_map()
##pool = Queue.Queue()
pool = Pool(processes = 4)
##if not libtcod.console_is_window_closed():
if __name__ == '__main__':
    start = time.time() # timing test for later, ignore.
##    for x in range(4):
##        threadhandler().start()
##    for y in range(MAP_HEIGHT):
##        for x in range(MAP_WIDTH):
##            pool.put((make_clearance,(x,y)))
##    pool.join()
    for y in range(MAP_HEIGHT):
        for x in range(MAP_WIDTH):
            pool.apply_async(make_clearance, (x,y))
    print "Elapsed Time: %s" %(time.time() - start)
    #render the screen
    render_all()
    libtcod.console_flush()
    key = libtcod.console_wait_for_keypress(True)
The issue is, when I try it run it, as far as I can tell, it attempts to open a new libtcod window for every single iteration of make_clearance. Would be greatly appreciated if someone could point out what stupid little thing I've screwed up :< edit2: So, the question becomes- How the ehll do I fix this?  ???

edit:I'm assuming, from my limited knowledge of what's actually happening behind the scenes, that it's copying over the entire process, and thus, the libtcod console? edit2: quick look at some non-destructive sample code shows it opening 4 python.exe processes, so I'm going to guess that this is the issue.

2
Life Advice / Car GPS
« on: July 31, 2009, 02:51:16 pm »
So, dads looking to buy a GPS. Anyone have any recommendations?

3
Other Games / ST:Bridge Commander
« on: March 22, 2009, 04:51:23 pm »
Sooo... anyone here play it? I've been playing it recently, and with the Kobyashi Maru mod, online play (when people are on! D:) is great fun. Maybe if we could get together some B12G people, we could infuse some life into MP :P

4
Other Games / Another programming thread. What should I use?
« on: January 22, 2009, 07:27:25 pm »
Right, so. I've been tinkering about with a few languages for a while, and wanting to make a 2d game. Issue: Needs hardware acceleration. Solution: Use textured quads.  Issue:Trying to get into OpenGL/DX, which seem purposely designed to have an incredible ammount of extra code REQUIRED that will only be useful to someone doing higher end graphics (I'm looking at you NeHe ;P). As well as C#/C++ being frustrating difficult to debug sometimes.  Solution: Python and a library for [usually] openGL.

Issue: Which should I use? I thought I hit the jackpot when I stumbled upon Rabbyt. Very very simple, full hardware acceleration, runs smoothly with alot of sprites onscreen. But, there aren't many (any?) tutorials for it, and it doesn't seem to support zooming, which is a must if I'm going to spend the time learning the language (for a later project >.>). Pyglet is nice, but there aren't much in the way of tutorials on its sprite functions, and the example programs don't explain quite a bit of their code.

So. I'm looking for a 2d library (or combination of libraries(or wrapper for a more complex library)), with HW acceleration; The works, rotation, scaling, camera Z function, and preferably better collision detection than circular (checking collisions between the masks of images is apparently plenty fast). Preferably in python, or fairly simple C++, as I jsut tired out on C++/C# pretty damn quick when I was doing a little self-goal-tutorial of making a program that converted text into numbers, converted them to another base, and did various things to them; it constantly gave me stupid errors and issues, whereas pythin worked fine the first time through, excluding one human error, and was done in under an hour without even knowing much about python.

Grateful for any help.

edit:Also, I would try the IRC channel first, if it wasn't for the fact that worldIRC isn't letting me connect :/

Pages: [1]