Example #1
0
	def init_world(self):
		for y in range(-self.FACTOR, self.size-self.FACTOR):
			for x in range(-self.FACTOR, self.size-self.FACTOR):
				#print "POS:",x,y
				self.pos_list.append((x,y))				
				ds = DiamondSquare((x, y), (self.OFFSET+1, self.OFFSET+1))
				ds.diamond_square_tile(self.diamonds)
				self.diamonds[(x,y)] = ds
				#if (not x == 1 and not y == -1):
					#if (not x == 0 and not y == 0):
						#if (not x == -1 and not y == 1):# or (not x == 1 and not y == -1):
				ds.save(PATH+str(x)+"_"+str(y)+".bmp")
Example #2
0
	def render_thing(self, que, resp_que, init, new_loc, offset, factor, use_old):
		from TextureHolder import TextureHolder
		h_ranges = {}
		h_range = (0, 255)
		#create new heightmaps
		nwlx, nwly = new_loc
		diamonds = que.get()
		pos_list = []
		if init and use_old:
			for newy in range(nwly-factor, nwly+factor+1):
				for newx in range(nwlx-factor, nwlx+factor+1):
					name = str(newx)+"_"+str(newy)+".bmp"
					if not os.path.isfile(PATH+name):
						if (newx-1, newy) in h_ranges:
							h_ranges[(newx,newy)] = min(max(random.choice(range(h_ranges[(newx-1,newy)]-2, h_ranges[(newx-1,newy)]+3)), 0), 4)
						elif (newx+1, newy) in h_ranges:
							h_ranges[(newx,newy)] = min(max(random.choice(range(h_ranges[(newx+1,newy)]-2, h_ranges[(newx+1,newy)]+3)), 0), 4)
						elif (newx, newy-1) in h_ranges:
							h_ranges[(newx,newy)] = min(max(random.choice(range(h_ranges[(newx,newy-1)]-2, h_ranges[(newx,newy-1)]+3)), 0), 4)
						elif (newx, newy+1) in h_ranges:
							h_ranges[(newx,newy)] = min(max(random.choice(range(h_ranges[(newx,newy+1)]-2, h_ranges[(newx,newy+1)]+3)), 0), 4)
						else:
							h_ranges[(newx,newy)] = 0


						pos_list.append((newx,newy))
						if not (newx, newy) in diamonds:
					#print "making squares..."
							ds = DiamondSquare((newx,newy), (offset+1, offset+1), self.height_ranges[h_ranges[(newx,newy)]])
							ds.diamond_square_tile(diamonds)
							diamonds[(newx,newy)] = ds
							ds.save(PATH+str(newx)+"_"+str(newy)+".bmp")
						
				        else:
						im = Image.open(PATH+name)
						pix = im.load()
						ds = DiamondSquare((newx,newy), (offset+1, offset+1), (0,255))
						for y in range(ds.height):
							for x in range(ds.width):
								ds[(x, y)] = pix[x, y]
						diamonds[(newx,newy)] = ds
		else:
			for newy in range(nwly-factor, nwly+factor+1):
				for newx in range(nwlx-factor, nwlx+factor+1):
					if (newx-1, newy) in h_ranges:
						h_ranges[(newx,newy)] = min(max(random.choice(range(h_ranges[(newx-1,newy)]-2, h_ranges[(newx-1,newy)]+3)), 0), 4)
					elif (newx+1, newy) in h_ranges:
						h_ranges[(newx,newy)] = min(max(random.choice(range(h_ranges[(newx+1,newy)]-2, h_ranges[(newx+1,newy)]+3)), 0), 4)
					elif (newx, newy-1) in h_ranges:
						h_ranges[(newx,newy)] = min(max(random.choice(range(h_ranges[(newx,newy-1)]-2, h_ranges[(newx,newy-1)]+3)), 0), 4)
					elif (newx, newy+1) in h_ranges:
						h_ranges[(newx,newy)] = min(max(random.choice(range(h_ranges[(newx,newy+1)]-2, h_ranges[(newx,newy+1)]+3)), 0), 4)
					else:
						h_ranges[(newx,newy)] = 0


					pos_list.append((newx,newy))
					if not (newx, newy) in diamonds:
					#print "making squares..."
						ds = DiamondSquare((newx,newy), (offset+1, offset+1), self.height_ranges[h_ranges[(newx,newy)]])
						ds.diamond_square_tile(diamonds)
						diamonds[(newx,newy)] = ds
						ds.save(PATH+str(newx)+"_"+str(newy)+".bmp")

		
		resp_que.put(pos_list, False)
		resp_que.put(diamonds, False)

		#creat new textures
		new_dic = {}
		copy_list = que.get()
		offset = que.get()
		convert = que.get()
		text_holder = TextureHolder()

		print "process running..."
		for location in pos_list:
			if not location in copy_list:
				#print "created someting"
				x,y = location
		
			        load = LoadTerrain(PATH+str(x)+"_"+str(y)+".bmp", convert, text_holder)
			        heights = load.load()
			
			        if init:
					tex_file_name, face_norms, vert_norms = load.init_createRenderList(heights,str(x)+"_"+str(y))
			        else:
					tex_file_name, face_norms, vert_norms = load.createRenderList(heights,str(x)+"_"+str(y))
			
				big_tup = (tex_file_name, face_norms, vert_norms, heights, x*offset, -y*offset, str(x)+"_"+str(y), pos_list.index(location))
              			new_dic[location] = big_tup
				print "CREATED A TILE!"

	        print "have new dic"
		resp_que.put(new_dic, False)
		print "enqued"