Merge branch 'unification/master' of github.com:dxx-rebirth/dxx-rebirth into unification/master

This commit is contained in:
zico 2015-02-22 17:31:17 +01:00
commit 31d1ec7be4
4 changed files with 62 additions and 34 deletions

View file

@ -79,7 +79,7 @@ void vms_vector_swap(vms_vector &v);
*/
struct chunk
{
ubyte *old_base; // where the offset sets off from (relative to beginning of model_data)
const uint8_t *old_base; // where the offset sets off from (relative to beginning of model_data)
ubyte *new_base; // where the base is in the aligned structure
short offset; // how much to add to base to get the address of the offset
short correction; // how much the value of the offset must be shifted for alignment
@ -89,7 +89,7 @@ struct chunk
* finds what chunks the data points to, adds them to the chunk_list,
* and returns the length of the current chunk
*/
int get_chunks(ubyte *data, ubyte *new_data, chunk *list, int *no);
int get_chunks(const uint8_t *data, uint8_t *new_data, chunk *list, int *no);
#endif //def WORDS_NEED_ALIGNMENT
#endif

View file

@ -37,12 +37,42 @@ int g3d_interp_outline;
#define MAX_INTERP_COLORS 100
#define w(p) (*((short *) (p)))
#define wp(p) ((short *) (p))
#define fp(p) ((fix *) (p))
#define vp(p) ((vms_vector *) (p))
static inline int16_t *wp(uint8_t *p)
{
return reinterpret_cast<int16_t *>(p);
}
static void rotate_point_list(g3s_point *dest,vms_vector *src,int n)
static inline const int16_t *wp(const uint8_t *p)
{
return reinterpret_cast<const int16_t *>(p);
}
static inline fix *fp(uint8_t *p)
{
return reinterpret_cast<fix *>(p);
}
static inline const fix *fp(const uint8_t *p)
{
return reinterpret_cast<const fix *>(p);
}
static inline vms_vector *vp(uint8_t *p)
{
return reinterpret_cast<vms_vector *>(p);
}
static inline const vms_vector *vp(const uint8_t *p)
{
return reinterpret_cast<const vms_vector *>(p);
}
static inline int16_t w(const uint8_t *p)
{
return *wp(p);
}
static void rotate_point_list(g3s_point *dest, const vms_vector *src, uint_fast32_t n)
{
while (n--)
g3_rotate_point(*dest++,*src++);
@ -51,7 +81,7 @@ static void rotate_point_list(g3s_point *dest,vms_vector *src,int n)
static const vms_angvec zero_angles = {0,0,0};
#ifdef WORDS_BIGENDIAN
void short_swap(short *s)
static void short_swap(short *s)
{
*s = SWAPSHORT(*s);
}
@ -88,7 +118,7 @@ void swap_polygon_model_data(ubyte *data)
short_swap(wp(p + 2));
n = w(p+2);
for (i = 0; i < n; i++)
vms_vector_swap(vp((p + 4) + (i * sizeof(vms_vector))));
vms_vector_swap(*vp((p + 4) + (i * sizeof(vms_vector))));
p += n*sizeof(struct vms_vector) + 4;
break;
@ -97,15 +127,15 @@ void swap_polygon_model_data(ubyte *data)
short_swap(wp(p + 4));
n = w(p+2);
for (i = 0; i < n; i++)
vms_vector_swap(vp((p + 8) + (i * sizeof(vms_vector))));
vms_vector_swap(*vp((p + 8) + (i * sizeof(vms_vector))));
p += n*sizeof(struct vms_vector) + 8;
break;
case OP_FLATPOLY:
short_swap(wp(p+2));
n = w(p+2);
vms_vector_swap(vp(p + 4));
vms_vector_swap(vp(p + 16));
vms_vector_swap(*vp(p + 4));
vms_vector_swap(*vp(p + 16));
short_swap(wp(p+28));
for (i=0; i < n; i++)
short_swap(wp(p + 30 + (i * 2)));
@ -115,8 +145,8 @@ void swap_polygon_model_data(ubyte *data)
case OP_TMAPPOLY:
short_swap(wp(p+2));
n = w(p+2);
vms_vector_swap(vp(p + 4));
vms_vector_swap(vp(p + 16));
vms_vector_swap(*vp(p + 4));
vms_vector_swap(*vp(p + 16));
for (i=0;i<n;i++) {
uvl_val = (g3s_uvl *)((p+30+((n&~1)+1)*2) + (i * sizeof(g3s_uvl)));
fix_swap(&uvl_val->u);
@ -129,8 +159,8 @@ void swap_polygon_model_data(ubyte *data)
break;
case OP_SORTNORM:
vms_vector_swap(vp(p + 4));
vms_vector_swap(vp(p + 16));
vms_vector_swap(*vp(p + 4));
vms_vector_swap(*vp(p + 16));
short_swap(wp(p + 28));
short_swap(wp(p + 30));
swap_polygon_model_data(p + w(p+28));
@ -139,8 +169,8 @@ void swap_polygon_model_data(ubyte *data)
break;
case OP_RODBM:
vms_vector_swap(vp(p + 20));
vms_vector_swap(vp(p + 4));
vms_vector_swap(*vp(p + 20));
vms_vector_swap(*vp(p + 4));
short_swap(wp(p+2));
fix_swap(fp(p + 16));
fix_swap(fp(p + 32));
@ -149,7 +179,7 @@ void swap_polygon_model_data(ubyte *data)
case OP_SUBCALL:
short_swap(wp(p+2));
vms_vector_swap(vp(p+4));
vms_vector_swap(*vp(p+4));
short_swap(wp(p+16));
swap_polygon_model_data(p + w(p+16));
p += 20;
@ -169,7 +199,7 @@ void swap_polygon_model_data(ubyte *data)
#endif
#ifdef WORDS_NEED_ALIGNMENT
static void add_chunk(ubyte *old_base, ubyte *new_base, int offset,
static void add_chunk(const uint8_t *old_base, uint8_t *new_base, int offset,
chunk *chunk_list, int *no_chunks)
{
Assert(*no_chunks + 1 < MAX_CHUNKS); //increase MAX_CHUNKS if you get this
@ -184,10 +214,10 @@ static void add_chunk(ubyte *old_base, ubyte *new_base, int offset,
* finds what chunks the data points to, adds them to the chunk_list,
* and returns the length of the current chunk
*/
int get_chunks(ubyte *data, ubyte *new_data, chunk *list, int *no)
int get_chunks(const uint8_t *data, uint8_t *new_data, chunk *list, int *no)
{
short n;
ubyte *p = data;
auto p = data;
while (INTEL_SHORT(w(p)) != OP_EOF) {
switch (INTEL_SHORT(w(p))) {

View file

@ -258,15 +258,14 @@ void ClipRank (ubyte *rank)
objnum_t objnum_remote_to_local(int remote_objnum, int owner)
{
if (owner == -1)
return(remote_objnum);
// Map a remote object number from owner to a local object number
if ((owner >= N_players) || (owner < -1)) {
Int3(); // Illegal!
return(remote_objnum);
}
if (owner == -1)
return(remote_objnum);
if ((remote_objnum < 0) || (remote_objnum >= MAX_OBJECTS))
return(object_none);

View file

@ -177,13 +177,13 @@ vms_angvec anim_angs[N_ANIM_STATES][MAX_SUBMODELS];
//set the animation angles for this robot. Gun fields of robot info must
//be filled in.
#ifdef WORDS_NEED_ALIGNMENT
static uint8_t *old_dest(const chunk &o) // return where chunk is (in unaligned struct)
static const uint8_t *old_dest(const chunk &o) // return where chunk is (in unaligned struct)
{
return o.old_base + INTEL_SHORT(*((short *)(o.old_base + o.offset)));
return GET_INTEL_SHORT(&o.old_base[o.offset]) + o.old_base;
}
static uint8_t *new_dest(const chunk &o) // return where chunk is (in aligned struct)
{
return o.new_base + INTEL_SHORT(*((short *)(o.old_base + o.offset))) + o.correction;
return GET_INTEL_SHORT(&o.old_base[o.offset]) + o.new_base + o.correction;
}
/*
* find chunk with smallest address
@ -203,7 +203,6 @@ static void align_polygon_model_data(polymodel *pm)
{
int chunk_len;
int total_correction = 0;
ubyte *cur_old, *cur_new;
chunk cur_ch;
chunk ch_list[MAX_CHUNKS];
int no_chunks = 0;
@ -213,8 +212,8 @@ static void align_polygon_model_data(polymodel *pm)
Assert(tmp != NULL);
//start with first chunk (is always aligned!)
cur_old = pm->model_data.get();
cur_new = tmp;
const uint8_t *cur_old = pm->model_data.get();
auto cur_new = tmp.get();
chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
memcpy(cur_new, cur_old, chunk_len);
while (no_chunks > 0) {
@ -234,7 +233,7 @@ static void align_polygon_model_data(polymodel *pm)
for (int i = 0; i < no_chunks; i++)
ch_list[i].correction += to_shift;
total_correction += to_shift;
Assert((u_int32_t)new_dest(cur_ch) % 4L == 0);
Assert(reinterpret_cast<uintptr_t>(new_dest(cur_ch)) % 4L == 0);
Assert(total_correction <= SHIFT_SPACE); // if you get this, increase SHIFT_SPACE
}
//write (corrected) chunk for current chunk:
@ -250,12 +249,12 @@ static void align_polygon_model_data(polymodel *pm)
for (int i = 0; i < MAX_SUBMODELS; i++)
if (&pm->model_data[pm->submodel_ptrs[i]] >= cur_old
&& &pm->model_data[pm->submodel_ptrs[i]] < cur_old + chunk_len)
pm->submodel_ptrs[i] += (cur_new - tmp) - (cur_old - pm->model_data.get());
pm->submodel_ptrs[i] += (cur_new - tmp.get()) - (cur_old - pm->model_data.get());
}
pm->model_data_size += total_correction;
pm->model_data = make_unique<ubyte[]>(pm->model_data_size);
Assert(pm->model_data != NULL);
memcpy(pm->model_data.get(), tmp, pm->model_data_size);
memcpy(pm->model_data.get(), tmp.get(), pm->model_data_size);
}
#endif //def WORDS_NEED_ALIGNMENT