From 80bbc9c69c688a3253ec72217a0ff4ed92776ec7 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 23 Nov 2014 04:36:58 +0000 Subject: [PATCH] Use range_for on Dl_indices --- common/main/segment.h | 4 ++-- similar/main/gamesave.cpp | 25 +++++++++++++------------ similar/main/gameseg.cpp | 17 ++++++++--------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/common/main/segment.h b/common/main/segment.h index d017d9cd0..9501bad15 100644 --- a/common/main/segment.h +++ b/common/main/segment.h @@ -352,9 +352,9 @@ struct dl_index { #define DL_SCALE 2048 // Divide light to allow 3 bits integer, 5 bits fraction. -extern dl_index Dl_indices[MAX_DL_INDICES]; +extern array Dl_indices; extern delta_light Delta_lights[MAX_DELTA_LIGHTS]; -extern int Num_static_lights; +extern unsigned Num_static_lights; int subtract_light(segnum_t segnum, int sidenum); int add_light(segnum_t segnum, int sidenum); diff --git a/similar/main/gamesave.cpp b/similar/main/gamesave.cpp index b0eb28d77..a9d77ca01 100644 --- a/similar/main/gamesave.cpp +++ b/similar/main/gamesave.cpp @@ -995,11 +995,15 @@ static int load_game_data(PHYSFS_file *LoadFile) #if defined(DXX_BUILD_DESCENT_II) //================ READ DL_INDICES INFO =============== - for (int i = 0; i < Num_static_lights; i++) { - if (game_top_fileinfo_version < 29) { - Int3(); //shouldn't be here!!! - } else - dl_index_read(&Dl_indices[i], LoadFile); + if (game_top_fileinfo_version < 29) + { + if (Num_static_lights) + throw std::logic_error("Static lights in old file"); + } + else + { + range_for (auto &i, partial_range(Dl_indices, Num_static_lights)) + dl_index_read(&i, LoadFile); } // Indicate that no light has been subtracted from any vertices. @@ -1511,11 +1515,8 @@ int Errors_in_mine; static int compute_num_delta_light_records(void) { int total = 0; - - for (int i=0; i= 29) { dl_indices_offset = PHYSFS_tell(SaveFile); - for (int i = 0; i < Num_static_lights; i++) - dl_index_write(&Dl_indices[i], SaveFile); + range_for (auto &i, partial_range(Dl_indices, Num_static_lights)) + dl_index_write(&i, SaveFile); delta_light_offset = PHYSFS_tell(SaveFile); for (int i = 0; i < num_delta_lights; i++) diff --git a/similar/main/gameseg.cpp b/similar/main/gameseg.cpp index 612bb6562..b0e2b3d32 100644 --- a/similar/main/gameseg.cpp +++ b/similar/main/gameseg.cpp @@ -49,6 +49,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #include "compiler-range_for.h" +#include "partial_range.h" #include "highest_valid.h" using std::min; @@ -57,9 +58,9 @@ using std::min; #define PLANE_DIST_TOLERANCE 250 #if defined(DXX_BUILD_DESCENT_II) -dl_index Dl_indices[MAX_DL_INDICES]; +array Dl_indices; delta_light Delta_lights[MAX_DELTA_LIGHTS]; -int Num_static_lights; +unsigned Num_static_lights; #endif // ------------------------------------------------------------------------------------------ @@ -1687,12 +1688,11 @@ static void change_segment_light(segnum_t segnum,int sidenum,int dir) // dir = 0 -> you are dumb static void change_light(segnum_t segnum, int sidenum, int dir) { - for (int i=0; ivert_light[k] * DL_SCALE; @@ -1705,7 +1705,6 @@ static void change_light(segnum_t segnum, int sidenum, int dir) dlp++; } } - } //recompute static light for segment change_segment_light(segnum,sidenum,dir);