Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert that lights must have non-zero-length active and inactive periods #23

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions Source_Files/Files/game_wad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,12 @@ bool process_map_wad(
}
}

// make sure no lights are malformed
for (count = 0; count<LightList.size(); ++count)
{
sanity_check_light(count);
}

/* Extract the annotations */
data= (uint8 *)extract_type_from_wad(wad, ANNOTATION_TAG, &data_length);
count = data_length/SIZEOF_map_annotation;
Expand Down
18 changes: 18 additions & 0 deletions Source_Files/GameWorld/lightsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ short new_light(
light->intensity= light->final_intensity;
change_light_state(light_index, LIGHT_IS_INITIALLY_ACTIVE(data) ? _light_primary_active : _light_primary_inactive);
light->phase= data->phase;
sanity_check_light(light_index);
rephase_light(light_index);

light->intensity= lighting_function_dispatch(get_lighting_function_specification(&light->static_data, light->state)->function,
Expand Down Expand Up @@ -291,6 +292,23 @@ bool set_tagged_light_statuses(
return changed;
}

void sanity_check_light(size_t light_index)
{
auto& light = LightList[light_index];
int total_active_period = 0;
total_active_period += light.static_data.primary_active.period;
total_active_period += light.static_data.primary_active.delta_period;
total_active_period += light.static_data.secondary_active.period;
total_active_period += light.static_data.secondary_active.delta_period;
assert(total_active_period > 0);
int total_inactive_period = 0;
total_inactive_period += light.static_data.primary_inactive.period;
total_inactive_period += light.static_data.primary_inactive.delta_period;
total_inactive_period += light.static_data.secondary_inactive.period;
total_inactive_period += light.static_data.secondary_inactive.delta_period;
assert(total_inactive_period > 0);
}

_fixed get_light_intensity(
size_t light_index)
{
Expand Down
1 change: 1 addition & 0 deletions Source_Files/GameWorld/lightsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ void update_lights(void);
bool get_light_status(size_t light_index);
bool set_light_status(size_t light_index, bool active);
bool set_tagged_light_statuses(short tag, bool new_status);
void sanity_check_light(size_t light_index);

_fixed get_light_intensity(size_t light_index);

Expand Down
Loading