Skip to content
Permalink
Browse files

Merge pull #479 into master

  • Loading branch information
vLKp committed Dec 27, 2019
2 parents ce90656 + 398d901 commit 05a54ef7c17eeb749db4e83793252339dcc0ba6f
Showing with 79 additions and 13 deletions.
  1. +2 −0 common/main/bm.h
  2. +73 −13 similar/main/bm.cpp
  3. +4 −0 similar/main/polyobj.cpp
@@ -150,6 +150,8 @@ extern int Robot_replacements_loaded;
constexpr std::integral_constant<unsigned, 610> MAX_OBJ_BITMAPS{};
extern unsigned N_ObjBitmaps;
extern int extra_bitmap_num;
extern bool Exit_models_loaded;
extern bool Exit_bitmaps_loaded;
#endif

extern int Num_object_subtypes; // Number of possible IDs for the current type of object to be placed
@@ -161,6 +161,7 @@ int gamedata_init()
namespace dsx {

// Read compiled properties data from descent.pig
// (currently only ever called if D1)
void properties_read_cmp(d_vclip_array &Vclip, PHYSFS_File * fp)
{
auto &Effects = LevelUniqueEffectsClipState.Effects;
@@ -385,17 +386,20 @@ void bm_read_all(d_vclip_array &Vclip, PHYSFS_File * fp)
//@@PHYSFS_read( fp, controlcen_gun_points, sizeof(vms_vector), N_controlcen_guns );
//@@PHYSFS_read( fp, controlcen_gun_dirs, sizeof(vms_vector), N_controlcen_guns );

if (Piggy_hamfile_version < 3) {
if (Piggy_hamfile_version < 3) { // D1
exit_modelnum = PHYSFSX_readInt(fp);
destroyed_exit_modelnum = PHYSFSX_readInt(fp);
}
else
else // D2: to be loaded later
exit_modelnum = destroyed_exit_modelnum = N_polygon_models;
}

}

int extra_bitmap_num = 0;
bool Exit_models_loaded; // this and below only really used for D2
bool Exit_bitmaps_loaded;
unsigned Exit_bitmap_index;

static void bm_free_extra_objbitmaps()
{
@@ -410,10 +414,12 @@ static void bm_free_extra_objbitmaps()
d_free(GameBitmaps[i].bm_mdata);
}
extra_bitmap_num = Num_bitmap_files;
Exit_bitmaps_loaded = false;
}

static void bm_free_extra_models()
{
Exit_models_loaded = false;
const auto base = std::min(N_D2_POLYGON_MODELS.value, exit_modelnum);
auto &Polygon_models = LevelSharedPolygonModelState.Polygon_models;
range_for (auto &p, partial_range(Polygon_models, base, exchange(N_polygon_models, base)))
@@ -583,7 +589,7 @@ void load_robot_replacements(const d_fname &level_name)
*
* Used by d1 levels (including some add-ons), and by d2 shareware.
* Could potentially be used by d2 add-on levels, but only if they
* don't use "extra" robots...
* don't use "extra" robots... or maybe they do
*/

// formerly exitmodel_bm_load_sub
@@ -640,25 +646,73 @@ static grs_bitmap *bm_load_extra_objbitmap(const char *name)
}
}

static void bm_unload_last_objbitmaps(unsigned count)
{
assert(N_ObjBitmaps >= count);

unsigned new_N_ObjBitmaps = N_ObjBitmaps - count;
range_for (auto &o, partial_range(ObjBitmaps, new_N_ObjBitmaps, N_ObjBitmaps))
d_free(GameBitmaps[o.index].bm_mdata);
N_ObjBitmaps = new_N_ObjBitmaps;
}

// only called for D2 registered, but there is a D1 check anyway for
// possible later use
int load_exit_models()
{
int start_num;

bm_free_extra_models();
bm_free_extra_objbitmaps();
/*
don't free extra models in native D2 mode -- ziplantil. it's our
responsibility to make sure the exit stuff is already loaded rather than
loading it all again.
start_num = N_ObjBitmaps;
if (!bm_load_extra_objbitmap("steel1.bbm") ||
!bm_load_extra_objbitmap("rbot061.bbm") ||
!bm_load_extra_objbitmap("rbot062.bbm") ||
!bm_load_extra_objbitmap("steel1.bbm") ||
!bm_load_extra_objbitmap("rbot061.bbm") ||
!bm_load_extra_objbitmap("rbot063.bbm"))
however, in D1 mode, we always need to reload everything due to how
the exit data is loaded (which is different from D2 native mode)
*/
if (EMULATING_D1) // D1?
{
bm_free_extra_models();
bm_free_extra_objbitmaps();
}

// make sure there is enough space to load textures and models
if (!Exit_bitmaps_loaded && N_ObjBitmaps > ObjBitmaps.size() - 6)
{
con_puts(CON_NORMAL, "Can't load exit models!");
return 0;
}
if (!Exit_models_loaded && N_polygon_models > MAX_POLYGON_MODELS - 2)
{
return 0;
}

start_num = N_ObjBitmaps;
if (!Exit_bitmaps_loaded)
{
if (!bm_load_extra_objbitmap("steel1.bbm") ||
!bm_load_extra_objbitmap("rbot061.bbm") ||
!bm_load_extra_objbitmap("rbot062.bbm") ||
!bm_load_extra_objbitmap("steel1.bbm") ||
!bm_load_extra_objbitmap("rbot061.bbm") ||
!bm_load_extra_objbitmap("rbot063.bbm"))
{
// unload the textures that we already loaded
bm_unload_last_objbitmaps(N_ObjBitmaps - start_num);
con_puts(CON_NORMAL, "Can't load exit models!");
return 0;
}
Exit_bitmap_index = start_num;
}

auto &Polygon_models = LevelSharedPolygonModelState.Polygon_models;
if (Exit_models_loaded && exit_modelnum < N_polygon_models && destroyed_exit_modelnum < N_polygon_models)
{
// already loaded, just adjust texture indexes
Polygon_models[exit_modelnum].first_texture = Exit_bitmap_index;
Polygon_models[destroyed_exit_modelnum].first_texture = Exit_bitmap_index+3;
return 1;
}

if (auto exit_hamfile = PHYSFSX_openReadBuffered("exit.ham"))
{
exit_modelnum = N_polygon_models++;
@@ -702,6 +756,8 @@ int load_exit_models()
case D1_OEM_PIGSIZE:
case D1_MAC_PIGSIZE:
case D1_MAC_SHARE_PIGSIZE:
// unload the textures that we already loaded
bm_unload_last_objbitmaps(N_ObjBitmaps - start_num);
con_puts(CON_NORMAL, "Can't load exit models!");
return 0;
}
@@ -717,10 +773,14 @@ int load_exit_models()
polygon_model_data_read(&Polygon_models[exit_modelnum], exit_hamfile);
polygon_model_data_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile);
} else {
// unload the textures that we already loaded
bm_unload_last_objbitmaps(N_ObjBitmaps - start_num);
con_puts(CON_NORMAL, "Can't load exit models!");
return 0;
}

// set to be loaded, but only on D2 - always reload the data on D1
Exit_models_loaded = Exit_bitmaps_loaded = !EMULATING_D1;
return 1;
}
#endif
@@ -50,6 +50,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#if DXX_USE_OGL
#include "ogl_init.h"
#endif
#include "bm.h"

#include "compiler-make_unique.h"
#include "partial_range.h"
@@ -572,6 +573,9 @@ void free_polygon_models()
auto &Polygon_models = LevelSharedPolygonModelState.Polygon_models;
range_for (auto &i, partial_range(Polygon_models, N_polygon_models))
free_model(i);
#if defined(DXX_BUILD_DESCENT_II)
Exit_models_loaded = false;
#endif
}

}

0 comments on commit 05a54ef

Please sign in to comment.
You can’t perform that action at this time.