Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions average_steer_partitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ def event_to_analog_value(event: ControlEntry):
val >>= int32(8)
return -val

def clean_duplicate_events(events: list):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please annotate that this also returns list.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"""
ESWC events seem a bit janky. Try to get rid of that by removing 'duplicate'
events. Take the latest one
"""
events_cleaned = []
for i in range(0, (len(events)-1)):
if int(events[i+1].time / 10) * 10 != int(events[i].time / 10) * 10:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when there's events like this?

10000 Accelerate (1)
10000 Brake (1)
10010 Accelerate (0)

Is the first accelerate simply skipped?

Copy link
Author

@kugelrund kugelrund Jun 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point. Reworked the function to skip over everything that is not a Steer event

events_cleaned.append(events[i])
events_cleaned.append(events[-1])
return events_cleaned

def partition_steer_events(events: list, sample_period: int):
p = []
current = []
Expand Down Expand Up @@ -56,6 +68,24 @@ def try_parse_old_ghost(g: Gbx):

return None

def try_parse_nations_eswc_ghost(g: Gbx):
ghost = CGameCtnGhost(0)
ghost.login = "" # unavailable in ESWC?

parser = g.find_raw_chunk_id(0x3f00dff)
if parser:
parser.seen_loopback = True
g.read_ghost_events(ghost, parser, 0x3f00dff)
return ghost

parser = g.find_raw_chunk_id(0x3f00dfa)
if parser:
parser.seen_loopback = True
g.read_ghost_events(ghost, parser, 0x3f00dfa)
return ghost

return None

def analyze_replay(path: str):
try:
g = Gbx(path)
Expand All @@ -67,16 +97,18 @@ def analyze_replay(path: str):
if not ghosts:
ghost = try_parse_old_ghost(g)
if not ghost:
print('Error: no ghosts')
return None
ghost = try_parse_nations_eswc_ghost(g)
if not ghost:
print('Error: no ghosts')
return None
ghost.control_entries = clean_duplicate_events(ghost.control_entries)

if not ghost.control_entries:
print('Error: no control entries')
return None
else:
ghost = ghosts[0]

ghost = ghosts[0]
results = {'version': ghost.game_version, 'login': ghost.login, 'max_spikes': 0, 'spikes': 0}

partitions = partition_steer_events(ghost.control_entries, TIME_PERIOD)
Expand Down
36 changes: 36 additions & 0 deletions generate_input_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ def event_to_analog_value(event: ControlEntry):
val >>= int32(8)
return -val

def clean_duplicate_events(events: list):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"""
ESWC events seem a bit janky. Try to get rid of that by removing 'duplicate'
events. Take the latest one
"""
events_cleaned = []
for i in range(0, (len(events)-1)):
if int(events[i+1].time / 10) * 10 != int(events[i].time / 10) * 10:
events_cleaned.append(events[i])
events_cleaned.append(events[-1])
return events_cleaned

def try_parse_old_ghost(g: Gbx):
ghost = CGameCtnGhost(0)

Expand All @@ -69,6 +81,24 @@ def try_parse_old_ghost(g: Gbx):

return None

def try_parse_nations_eswc_ghost(g: Gbx):
ghost = CGameCtnGhost(0)
ghost.login = "" # unavailable in ESWC?

parser = g.find_raw_chunk_id(0x3f00dff)
if parser:
parser.seen_loopback = True
g.read_ghost_events(ghost, parser, 0x3f00dff)
return ghost

parser = g.find_raw_chunk_id(0x3f00dfa)
if parser:
parser.seen_loopback = True
g.read_ghost_events(ghost, parser, 0x3f00dfa)
return ghost

return None

def try_extract_2020(g: Gbx):
cbp = g.find_raw_chunk_id(0x0309201D)
if not cbp:
Expand Down Expand Up @@ -181,6 +211,12 @@ def process_path(path, write_func):
ghosts = g.get_classes_by_ids([GbxType.CTN_GHOST, GbxType.CTN_GHOST_OLD])
if not ghosts:
ghost = try_parse_old_ghost(g)
if not ghost:
ghost = try_parse_nations_eswc_ghost(g)
if not ghost:
print('Error: no ghosts')
return None
ghost.control_entries = clean_duplicate_events(ghost.control_entries)
else:
ghost = ghosts[0]

Expand Down