Use RAIIdmem for height_array
This commit is contained in:
parent
7fccbe2d0d
commit
d3e657222e
|
@ -91,12 +91,12 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename U, typename T = typename tt::remove_extent<U>::type>
|
||||||
class RAIIdmem : public std::unique_ptr<T, RAIIdmem_deleter<T>>
|
class RAIIdmem : public std::unique_ptr<U, RAIIdmem_deleter<T>>
|
||||||
{
|
{
|
||||||
static_assert(tt::is_pod<T>::value, "RAIIdmem cannot manage non-POD");
|
static_assert(tt::is_pod<T>::value, "RAIIdmem cannot manage non-POD");
|
||||||
public:
|
public:
|
||||||
DXX_INHERIT_CONSTRUCTORS(RAIIdmem, std::unique_ptr<T, RAIIdmem_deleter<T>>);
|
DXX_INHERIT_CONSTRUCTORS(RAIIdmem, std::unique_ptr<U, RAIIdmem_deleter<T>>);
|
||||||
operator T*() const
|
operator T*() const
|
||||||
#ifdef DXX_HAVE_CXX11_REF_QUALIFIER
|
#ifdef DXX_HAVE_CXX11_REF_QUALIFIER
|
||||||
&
|
&
|
||||||
|
@ -110,14 +110,14 @@ template <typename T>
|
||||||
T *MALLOC(RAIIdmem<T> &r, std::size_t count, const char *var, const char *file, unsigned line)
|
T *MALLOC(RAIIdmem<T> &r, std::size_t count, const char *var, const char *file, unsigned line)
|
||||||
{
|
{
|
||||||
T *p;
|
T *p;
|
||||||
return r = RAIIdmem<T>(MALLOC<T>(p, count, var, file, line));
|
return r.reset(MALLOC<T>(p, count, var, file, line)), p;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T *CALLOC(RAIIdmem<T> &r, std::size_t count, const char *var, const char *file, unsigned line)
|
T *CALLOC(RAIIdmem<T> &r, std::size_t count, const char *var, const char *file, unsigned line)
|
||||||
{
|
{
|
||||||
T *p;
|
T *p;
|
||||||
return r = RAIIdmem<T>(CALLOC<T>(p, count, var, file, line));
|
return r.reset(CALLOC<T>(p, count, var, file, line)), p;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MALLOC( var, type, count ) (MALLOC<type>(var, (count)*sizeof(type),#var, __FILE__,__LINE__ ))
|
#define MALLOC( var, type, count ) (MALLOC<type>(var, (count)*sizeof(type),#var, __FILE__,__LINE__ ))
|
||||||
|
|
|
@ -50,7 +50,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
||||||
|
|
||||||
static int grid_w,grid_h;
|
static int grid_w,grid_h;
|
||||||
|
|
||||||
static ubyte *height_array;
|
static RAIIdmem<ubyte[]> height_array;
|
||||||
static std::unique_ptr<uint8_t[]> light_array;
|
static std::unique_ptr<uint8_t[]> light_array;
|
||||||
|
|
||||||
#define HEIGHT(_i,_j) (height_array[(_i)*grid_w+(_j)])
|
#define HEIGHT(_i,_j) (height_array[(_i)*grid_w+(_j)])
|
||||||
|
@ -327,8 +327,7 @@ void render_terrain(const vms_vector &org_point,int org_2dx,int org_2dy)
|
||||||
|
|
||||||
void free_height_array()
|
void free_height_array()
|
||||||
{
|
{
|
||||||
if (height_array)
|
height_array.reset();
|
||||||
d_free(height_array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_terrain(const char *filename)
|
void load_terrain(const char *filename)
|
||||||
|
@ -342,17 +341,13 @@ void load_terrain(const char *filename)
|
||||||
if (iff_error != IFF_NO_ERROR) {
|
if (iff_error != IFF_NO_ERROR) {
|
||||||
Error("File %s - IFF error: %s",filename,iff_errormsg(iff_error));
|
Error("File %s - IFF error: %s",filename,iff_errormsg(iff_error));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (height_array)
|
|
||||||
d_free(height_array);
|
|
||||||
|
|
||||||
grid_w = height_bitmap.bm_w;
|
grid_w = height_bitmap.bm_w;
|
||||||
grid_h = height_bitmap.bm_h;
|
grid_h = height_bitmap.bm_h;
|
||||||
|
|
||||||
Assert(grid_w <= GRID_MAX_SIZE);
|
Assert(grid_w <= GRID_MAX_SIZE);
|
||||||
Assert(grid_h <= GRID_MAX_SIZE);
|
Assert(grid_h <= GRID_MAX_SIZE);
|
||||||
|
|
||||||
height_array = height_bitmap.get_bitmap_data();
|
height_array.reset(height_bitmap.get_bitmap_data());
|
||||||
|
|
||||||
max_h=0; min_h=255;
|
max_h=0; min_h=255;
|
||||||
for (i=0;i<grid_w;i++)
|
for (i=0;i<grid_w;i++)
|
||||||
|
|
Loading…
Reference in a new issue