File main.py changed (mode: 100644) (index 7dc4a5f..4b7a7a0) |
... |
... |
class Model(object): |
221 |
221 |
""" |
""" |
222 |
222 |
self.add_block(position, texture, False) |
self.add_block(position, texture, False) |
223 |
223 |
|
|
224 |
|
def add_block(self, position, texture, sync=True): |
|
|
224 |
|
def add_block(self, position, texture, immediate=True): |
225 |
225 |
""" Add a block with the given `texture` and `position` to the world. |
""" Add a block with the given `texture` and `position` to the world. |
226 |
226 |
|
|
227 |
227 |
Parameters |
Parameters |
|
... |
... |
class Model(object): |
231 |
231 |
texture : list of len 3 |
texture : list of len 3 |
232 |
232 |
The coordinates of the texture squares. Use `tex_coords()` to |
The coordinates of the texture squares. Use `tex_coords()` to |
233 |
233 |
generate. |
generate. |
234 |
|
sync : bool |
|
|
234 |
|
immediate : bool |
235 |
235 |
Whether or not to draw the block immediately. |
Whether or not to draw the block immediately. |
236 |
236 |
|
|
237 |
237 |
""" |
""" |
238 |
238 |
if position in self.world: |
if position in self.world: |
239 |
|
self.remove_block(position, sync) |
|
|
239 |
|
self.remove_block(position, immediate) |
240 |
240 |
self.world[position] = texture |
self.world[position] = texture |
241 |
241 |
self.sectors.setdefault(sectorize(position), []).append(position) |
self.sectors.setdefault(sectorize(position), []).append(position) |
242 |
|
if sync: |
|
|
242 |
|
if immediate: |
243 |
243 |
if self.exposed(position): |
if self.exposed(position): |
244 |
244 |
self.show_block(position) |
self.show_block(position) |
245 |
245 |
self.check_neighbors(position) |
self.check_neighbors(position) |
246 |
246 |
|
|
247 |
|
def remove_block(self, position, sync=True): |
|
|
247 |
|
def remove_block(self, position, immediate=True): |
248 |
248 |
""" Remove the block at the given `position`. |
""" Remove the block at the given `position`. |
249 |
249 |
|
|
250 |
250 |
Parameters |
Parameters |
251 |
251 |
---------- |
---------- |
252 |
252 |
position : tuple of len 3 |
position : tuple of len 3 |
253 |
253 |
The (x, y, z) position of the block to remove. |
The (x, y, z) position of the block to remove. |
254 |
|
sync : bool |
|
|
254 |
|
immediate : bool |
255 |
255 |
Whether or not to immediately remove block from canvas. |
Whether or not to immediately remove block from canvas. |
256 |
256 |
|
|
257 |
257 |
""" |
""" |
258 |
258 |
del self.world[position] |
del self.world[position] |
259 |
259 |
self.sectors[sectorize(position)].remove(position) |
self.sectors[sectorize(position)].remove(position) |
260 |
|
if sync: |
|
|
260 |
|
if immediate: |
261 |
261 |
if position in self.shown: |
if position in self.shown: |
262 |
262 |
self.hide_block(position) |
self.hide_block(position) |
263 |
263 |
self.check_neighbors(position) |
self.check_neighbors(position) |
|
... |
... |
class Model(object): |
407 |
407 |
""" Process the entire queue while taking periodic breaks. This allows |
""" Process the entire queue while taking periodic breaks. This allows |
408 |
408 |
the game loop to run smoothly. The queue contains calls to |
the game loop to run smoothly. The queue contains calls to |
409 |
409 |
_show_block() and _hide_block() so this method should be called if |
_show_block() and _hide_block() so this method should be called if |
410 |
|
add_block() or remove_block() was called with sync=False |
|
|
410 |
|
add_block() or remove_block() was called with immediate=False |
411 |
411 |
|
|
412 |
412 |
""" |
""" |
413 |
413 |
start = time.clock() |
start = time.clock() |