Commit e42488ef authored by Karol Actun's avatar Karol Actun
Browse files

fixed the animation with carried tiles. carried particles cannot move now with...

fixed the animation with carried tiles. carried particles cannot move now with their move_to method.
parent 20e0b6c2
......@@ -90,7 +90,8 @@ class Particle(matter.Matter):
direction_coord = get_coordinates_in_direction(self.coordinates, direction)
direction_coord = self.check_within_border(direction, direction_coord)
if self.world.grid.are_valid_coordinates(direction_coord) \
and direction_coord not in self.world.particle_map_coordinates:
and direction_coord not in self.world.particle_map_coordinates \
and not self.__isCarried:
if self.coordinates in self.world.particle_map_coordinates:
del self.world.particle_map_coordinates[self.coordinates]
self.coordinates = direction_coord
......@@ -119,11 +120,14 @@ class Particle(matter.Matter):
if self.world.config_data.border == 1:
if self.world.config_data.type == 1:
if abs(direction_coord[0]) > self.world.get_x_size():
direction_coord = (-1 * (self.coordinates[0] - direction[0]), direction_coord[1], direction_coord[2])
direction_coord = (
-1 * (self.coordinates[0] - direction[0]), direction_coord[1], direction_coord[2])
if abs(direction_coord[1]) > self.world.get_y_size():
direction_coord = (direction_coord[0], -1* (self.coordinates[1] - direction[1]), direction_coord[2])
direction_coord = (
direction_coord[0], -1 * (self.coordinates[1] - direction[1]), direction_coord[2])
if abs(direction_coord[2]) > self.world.get_z_size():
direction_coord = (direction_coord[0], direction_coord[1], -1* (self.coordinates[2] - direction[2]))
direction_coord = (
direction_coord[0], direction_coord[1], -1 * (self.coordinates[2] - direction[2]))
else:
if abs(direction_coord[0]) > self.world.get_x_size():
direction_coord = (self.coordinates[0], direction_coord[1], direction_coord[2])
......@@ -147,7 +151,7 @@ class Particle(matter.Matter):
tmp_memory = target.read_whole_memory()
if tmp_memory is not None \
and not (hasattr(tmp_memory, '__len__')) or len(tmp_memory) > 0:
and not (hasattr(tmp_memory, '__len__')) or len(tmp_memory) > 0:
if target.type == "particle":
self.world.csv_round.update_metrics(particle_read=1)
self.csv_particle_writer.write_particle(particle_read=1)
......@@ -817,7 +821,6 @@ class Particle(matter.Matter):
logging.info("Could not delete particle on coordinates %s" % str(coordinates))
return False
def take_particle_with(self, particle_id):
"""
Takes a particle with a given tile id
......@@ -847,7 +850,6 @@ class Particle(matter.Matter):
logging.info("particle with particle id %s could not be taken" % str(particle_id))
return False
def take_particle_on(self, coordinates):
"""
Takes the particle on the given coordinates if it is not taken
......
......@@ -214,7 +214,7 @@ class Visualization:
# using the rounds_per_second and the
# timestamp of the start of the round, calculate the time left for animation
timeleft = (1/self._rounds_per_second) - (time.perf_counter() - round_start_time)
timeleft = (1 / self._rounds_per_second) - (time.perf_counter() - round_start_time)
# calculate the amount of animation steps we can do in the time left
steps = int(timeleft / frametime / 1.5)
......@@ -223,7 +223,7 @@ class Visualization:
# animate
for i in range(1, steps):
self._viewer.set_animation_percentage(float(i/steps))
self._viewer.set_animation_percentage(float(i / steps))
self._app.processEvents()
self._viewer.glDraw()
......@@ -238,7 +238,12 @@ class Visualization:
current_data = self._viewer.particle_offset_data[particle]
self._viewer.particle_offset_data[particle] = (current_data[0], current_data[1], particle.coordinates,
current_data[3])
for tile in self._viewer.tile_offset_data:
current_data = self._viewer.tile_offset_data[tile]
self._viewer.tile_offset_data[tile] = (current_data[0], current_data[1], tile.coordinates,
current_data[3])
self._viewer.particle_update_flag = True
self._viewer.tile_update_flag = True
def run(self, round_start_timestamp):
"""
......@@ -318,7 +323,7 @@ class Visualization:
self._viewer.tile_update_flag = True
prev_pos = tile.coordinates
if tile in self._viewer.tile_offset_data:
prev_pos = self._viewer.particle_offset_data[tile][0]
prev_pos = self._viewer.tile_offset_data[tile][0]
self._viewer.tile_offset_data[tile] = (tile.coordinates, tile.color, prev_pos,
1.0 if tile.get_tile_status() else 0.0)
......@@ -582,14 +587,14 @@ class Visualization:
if path[0].endswith("mp4") or path[0].endswith(".avi") or path[0].endswith(".mkv"):
fullpath = path[0]
else:
fullpath = path[0]+path[1].replace('*', '')
fullpath = path[0] + path[1].replace('*', '')
writer = cv2.VideoWriter(fullpath, cv2.VideoWriter_fourcc(*codec), rps, (width, height))
self._viewer.setDisabled(True)
# creating and opening loading window
lw = LoadingWindow("", "Exporting Video...")
lw.show()
for i in range(first_frame_idx-1, last_frame_idx):
for i in range(first_frame_idx - 1, last_frame_idx):
# update loading windows text and progress bar
processing = i - first_frame_idx + 2
out_of = last_frame_idx - first_frame_idx + 1
......@@ -601,7 +606,7 @@ class Visualization:
self._viewer.inject_record_data(self.recorder.records[i])
img = self._viewer.get_frame_cv(width, height)
writer.write(img)
self._viewer.inject_record_data(self.recorder.records[last_frame_idx-1])
self._viewer.inject_record_data(self.recorder.records[last_frame_idx - 1])
writer.release()
lw.close()
self._viewer.setDisabled(False)
......@@ -636,7 +641,7 @@ class Visualization:
if path[0].endswith(".svg"):
create_svg(self._world, path[0])
else:
create_svg(self._world, path[0]+".svg")
create_svg(self._world, path[0] + ".svg")
else:
show_msg("Not implemented yet.\nWorks only with Triangular Grid for now!\nSorry!", 2)
......@@ -658,4 +663,4 @@ class Visualization:
self._manual_animation_speed = manual_animation_speed
def get_manual_animation_speed(self):
return self._manual_animation_speed
\ No newline at end of file
return self._manual_animation_speed
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment