Skip to content

Commit

Permalink
Add handling of ending events
Browse files Browse the repository at this point in the history
  • Loading branch information
RedTachyon committed Mar 22, 2024
1 parent a9502c2 commit 926bb30
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cogment_lab/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ async def on_message(self, messages: list):
"""Handle received messages."""
pass

async def on_ending(self, observation, rendered_frame):
"""Handle trial ending."""
pass

async def end(self):
"""Clean up when done."""
pass
Expand All @@ -250,10 +254,17 @@ async def impl(self, actor_session: ActorSession):
async for event in actor_session.all_events():
event: RecvEvent
self.current_event = event
if event.type != cogment.EventType.ACTIVE:
if event.type not in (cogment.EventType.ACTIVE, cogment.EventType.ENDING):
logging.info(f"Skipping event of type {event.type}")
continue

if event.type == cogment.EventType.ENDING:
observation = self.session_helper.get_observation(event)
await self.on_ending(observation.value, observation.rendered_frame)
continue

# type = ACTIVE

if event.observation:
observation = self.session_helper.get_observation(event)
if observation is None:
Expand Down

0 comments on commit 926bb30

Please sign in to comment.