From cf78b28adf7cf70e645dda3cf1bc3d728380028d Mon Sep 17 00:00:00 2001 From: Jonathan Haas Date: Sun, 27 Dec 2015 10:45:11 +0100 Subject: [PATCH] Use memmove for shifting Use memmove for shifting the customer history, rename ride fields, and add back the offset comments. --- src/peep/peep.c | 14 +++++------ src/ride/ride.c | 67 ++++++++++++++++++++++--------------------------- src/ride/ride.h | 9 ++++--- 3 files changed, 43 insertions(+), 47 deletions(-) diff --git a/src/peep/peep.c b/src/peep/peep.c index f5c2408136..0c6b85fee4 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -1911,7 +1911,7 @@ void peep_update_ride_sub_state_1(rct_peep* peep){ peep->destination_y = y; peep->destination_tolerence = 3; - ride->customer_counter++; + ride->cur_num_customers++; peep_on_enter_or_exit_ride(peep, peep->current_ride, 0); peep->sub_state = 17; return; @@ -1938,7 +1938,7 @@ void peep_update_ride_sub_state_1(rct_peep* peep){ peep->destination_y = y; peep->current_car = 0; - ride->customer_counter++; + ride->cur_num_customers++; peep_on_enter_or_exit_ride(peep, peep->current_ride, 0); peep->sub_state = 14; return; @@ -2297,7 +2297,7 @@ static void peep_update_ride_sub_state_5(rct_peep* peep){ return; vehicle->num_peeps++; - ride->customer_counter++; + ride->cur_num_customers++; vehicle->friction += seated_peep->var_41; invalidate_sprite_2((rct_sprite*)seated_peep); @@ -2312,7 +2312,7 @@ static void peep_update_ride_sub_state_5(rct_peep* peep){ } vehicle->num_peeps++; - ride->customer_counter++; + ride->cur_num_customers++; vehicle->friction += peep->var_41; invalidate_sprite_2((rct_sprite*)vehicle); @@ -6767,7 +6767,7 @@ static int peep_interact_with_shop(rct_peep* peep, sint16 x, sint16 y, rct_map_e peep_window_state_update(peep); peep->time_on_ride = 0; - ride->customer_counter++; + ride->cur_num_customers++; if (peep->flags & PEEP_FLAGS_TRACKING){ RCT2_GLOBAL(0x0013CE952, rct_string_id) = peep->name_string_idx; RCT2_GLOBAL(0x0013CE954, uint32) = peep->id; @@ -8358,7 +8358,7 @@ loc_69B221: ride->total_profit += (price - get_shop_item_cost(shopItem)); ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME; - ride->customer_counter++; + ride->cur_num_customers++; ride->total_customers++; ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_CUSTOMER; @@ -8379,7 +8379,7 @@ static bool peep_should_use_cash_machine(rct_peep *peep, int rideIndex) rct_ride *ride = GET_RIDE(rideIndex); ride_update_satisfaction(ride, peep->happiness >> 6); - ride->customer_counter++; + ride->cur_num_customers++; ride->total_customers++; ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_CUSTOMER; return true; diff --git a/src/ride/ride.c b/src/ride/ride.c index 6258b12138..0837314d77 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -1832,23 +1832,17 @@ static void ride_update(int rideIndex) ride_update_station(ride, i); // Update financial statistics - ride->statistics_tick_counter++; + ride->num_customers_timeout++; - if (ride->statistics_tick_counter >= 960) { + if (ride->num_customers_timeout >= 960) { // This is meant to update about every 30 seconds - ride->statistics_tick_counter = 0; + ride->num_customers_timeout = 0; - ride->customer_count_history[9] = ride->customer_count_history[8]; - ride->customer_count_history[8] = ride->customer_count_history[7]; - ride->customer_count_history[7] = ride->customer_count_history[6]; - ride->customer_count_history[6] = ride->customer_count_history[5]; - ride->customer_count_history[5] = ride->customer_count_history[4]; - ride->customer_count_history[4] = ride->customer_count_history[3]; - ride->customer_count_history[3] = ride->customer_count_history[2]; - ride->customer_count_history[2] = ride->customer_count_history[1]; - ride->customer_count_history[1] = ride->customer_count_history[0]; - ride->customer_count_history[0] = ride->customer_counter; - ride->customer_counter = 0; + // Shift number of customers history, start of the array is the most recent one + memmove(ride->num_customers + 1, ride->num_customers, 9 * sizeof(*(ride->num_customers))); + ride->num_customers[0] = ride->cur_num_customers; + + ride->cur_num_customers = 0; ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_CUSTOMER; ride->income_per_hour = ride_calculate_income_per_hour(ride); @@ -5380,8 +5374,8 @@ foundRideEntry: ride->measurement_index = 255; ride->excitement = (ride_rating)-1; - ride->customer_counter = 0; - ride->statistics_tick_counter = 0; + ride->cur_num_customers = 0; + ride->num_customers_timeout = 0; ride->var_148 = 0; ride->price = 0; @@ -5433,17 +5427,16 @@ foundRideEntry: } } - ride->customer_counter = 0; - ride->customer_count_history[0] = 0; - ride->customer_count_history[1] = 0; - ride->customer_count_history[2] = 0; - ride->customer_count_history[3] = 0; - ride->customer_count_history[4] = 0; - ride->customer_count_history[5] = 0; - ride->customer_count_history[6] = 0; - ride->customer_count_history[7] = 0; - ride->customer_count_history[8] = 0; - ride->customer_count_history[9] = 0; + ride->num_customers[0] = 0; + ride->num_customers[1] = 0; + ride->num_customers[2] = 0; + ride->num_customers[3] = 0; + ride->num_customers[4] = 0; + ride->num_customers[5] = 0; + ride->num_customers[6] = 0; + ride->num_customers[7] = 0; + ride->num_customers[8] = 0; + ride->num_customers[9] = 0; ride->value = 0xFFFF; ride->satisfaction = 255; @@ -7379,15 +7372,15 @@ const uint32 ride_customers_per_hour(const rct_ride *ride) { // Calculates the number of customers for this ride in the last 5 minutes (or more correctly 9600 game ticks) const uint32 ride_customers_in_last_5_minutes(const rct_ride *ride) { - uint32 sum = ride->customer_count_history[0] - + ride->customer_count_history[1] - + ride->customer_count_history[2] - + ride->customer_count_history[3] - + ride->customer_count_history[4] - + ride->customer_count_history[5] - + ride->customer_count_history[6] - + ride->customer_count_history[7] - + ride->customer_count_history[8] - + ride->customer_count_history[9]; + uint32 sum = ride->num_customers[0] + + ride->num_customers[1] + + ride->num_customers[2] + + ride->num_customers[3] + + ride->num_customers[4] + + ride->num_customers[5] + + ride->num_customers[6] + + ride->num_customers[7] + + ride->num_customers[8] + + ride->num_customers[9]; return sum; } diff --git a/src/ride/ride.h b/src/ride/ride.h index e849931bca..b2d17f6d05 100644 --- a/src/ride/ride.h +++ b/src/ride/ride.h @@ -201,9 +201,12 @@ typedef struct { uint8 pad_11C[0x2]; uint8 num_sheltered_sections; // 0x11E uint8 var_11F; - uint16 customer_counter; // Customer count in the current 960 game tick (about 30 seconds) interval - uint16 statistics_tick_counter; // Counts ticks to update customer intervals, resets each 960 game ticks. - uint16 customer_count_history[10]; // Customer count in the last 10 * 960 game ticks + // Customer counter in the current 960 game tick (about 30 seconds) interval + uint16 cur_num_customers; // 0x120 + // Counts ticks to update customer intervals, resets each 960 game ticks. + uint16 num_customers_timeout; // 0x122 + // Customer count in the last 10 * 960 game ticks (sliding window) + uint16 num_customers[10]; // 0x124 money16 price; // 0x138 sint16 var_13A; sint16 var_13C;