Like in BigEndian builds do netmisc_calc_checksum() only with expected items of segment/side struct to prevent different checksums in case these structs change; Fixed several issues when building with editor; Fixed compiler warning regarding set but unused variable

This commit is contained in:
zicodxx 2011-05-22 19:54:44 +02:00
parent 3791862055
commit 6fe57317cc
6 changed files with 40 additions and 77 deletions

View file

@ -1,5 +1,9 @@
D1X-Rebirth Changelog
20110522
--------
editor/med.c, main/game.c, main/gameseg.c, main/gameseq.c, main/menu.c: Like in BigEndian builds do netmisc_calc_checksum() only with expected items of segment/side struct to prevent different checksums in case these structs change; Fixed several issues when building with editor; Fixed compiler warning regarding set but unused variable
20110520
--------
INSTALL.txt, RELEASE-NOTES.txt: Updated docs and fixed some typos

View file

@ -999,9 +999,9 @@ void editor(void)
gr_set_curfont(editor_font);
//Editor renders into full (320x200) game screen
#ifndef __LINUX__
set_warn_func(med_show_warning);
#endif
// _MARK_("start of editor");//Nuked to compile -KRB
ui_mouse_hide();
@ -1061,8 +1061,8 @@ void editor(void)
// Only update if there is no key waiting and we're not in
// fast play mode.
if (!key_peekkey()) //-- && (MacroStatus != UI_STATUS_FASTPLAY))
medlisp_update_screen();
// if (!key_peekkey()) //-- && (MacroStatus != UI_STATUS_FASTPLAY))
// medlisp_update_screen();
//do editor stuff
gr_set_curfont(editor_font);
@ -1356,7 +1356,7 @@ void editor(void)
// _MARK_("end of editor");//Nuked to compile -KRB
set_warn_func(msgbox_warning);
// set_warn_func(msgbox_warning);
//kill our camera object

View file

@ -927,9 +927,6 @@ window *game_setup(void)
{
window *game_wind;
#ifdef EDITOR
keyd_editor_mode = 0;
#endif
PlayerCfg.CockpitMode[1] = PlayerCfg.CockpitMode[0];
last_drawn_cockpit = -1; // Force cockpit to redraw next time a frame renders.
Endlevel_sequence = 0;

View file

@ -1247,6 +1247,7 @@ int check_for_degenerate_side(segment *sp, int sidenum)
}
extern int Degenerate_segment_found;
// ----
// See if a segment has gotten turned inside out, or something.
// If so, set global Degenerate_segment_found and return 1, else return 0.

View file

@ -94,15 +94,16 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "multi.h"
#endif
#include "strutil.h"
#ifdef EDITOR
#include "editor/editor.h"
#endif
#include "custom.h"
#ifdef SCRIPT
#include "script.h"
#endif
#include "byteswap.h"
#include "segment.h"
#include "gameseg.h"
void init_player_stats_new_ship();
void copy_defaults_to_robot_all(void);
@ -562,17 +563,8 @@ char *get_level_file(int level_num)
#endif
}
//FIXME: Certain combinations of players having and not having the editor will cause the segment checksum code to fail.
#ifdef WORDS_BIGENDIAN
#include "byteswap.h"
#include "segment.h"
#include "gameseg.h"
// routine to calculate the checksum of the segments. We add these specialized routines
// since the current way is byte order dependent.
void mac_do_checksum_calc(ubyte *b, int len, unsigned int *s1, unsigned int *s2)
// routine to calculate the checksum of the segments.
void do_checksum_calc(ubyte *b, int len, unsigned int *s1, unsigned int *s2)
{
while(len--) {
@ -582,7 +574,7 @@ void mac_do_checksum_calc(ubyte *b, int len, unsigned int *s1, unsigned int *s2)
}
}
ushort mac_calc_segment_checksum()
ushort netmisc_calc_checksum()
{
int i, j, k;
unsigned int sum1,sum2;
@ -592,87 +584,59 @@ ushort mac_calc_segment_checksum()
sum1 = sum2 = 0;
for (i = 0; i < Highest_segment_index + 1; i++) {
for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) {
mac_do_checksum_calc((unsigned char *)&(Segments[i].sides[j].type), 1, &sum1, &sum2);
mac_do_checksum_calc(&(Segments[i].sides[j].pad), 1, &sum1, &sum2);
do_checksum_calc((unsigned char *)&(Segments[i].sides[j].type), 1, &sum1, &sum2);
do_checksum_calc(&(Segments[i].sides[j].pad), 1, &sum1, &sum2);
s = INTEL_SHORT(Segments[i].sides[j].wall_num);
mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
s = INTEL_SHORT(Segments[i].sides[j].tmap_num);
mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
s = INTEL_SHORT(Segments[i].sides[j].tmap_num2);
mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
for (k = 0; k < 4; k++) {
t = INTEL_INT(((int)Segments[i].sides[j].uvls[k].u));
mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
t = INTEL_INT(((int)Segments[i].sides[j].uvls[k].v));
mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
t = INTEL_INT(((int)Segments[i].sides[j].uvls[k].l));
mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
}
for (k = 0; k < 2; k++) {
t = INTEL_INT(((int)Segments[i].sides[j].normals[k].x));
mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
t = INTEL_INT(((int)Segments[i].sides[j].normals[k].y));
mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
t = INTEL_INT(((int)Segments[i].sides[j].normals[k].z));
mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
}
}
for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) {
s = INTEL_SHORT(Segments[i].children[j]);
mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
}
for (j = 0; j < MAX_VERTICES_PER_SEGMENT; j++) {
s = INTEL_SHORT(Segments[i].verts[j]);
mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
}
s = INTEL_SHORT(Segments[i].objects);
mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
mac_do_checksum_calc((unsigned char *)&(Segments[i].special), 1, &sum1, &sum2);
mac_do_checksum_calc((unsigned char *)&(Segments[i].matcen_num), 1, &sum1, &sum2);
do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
do_checksum_calc((unsigned char *)&(Segments[i].special), 1, &sum1, &sum2);
do_checksum_calc((unsigned char *)&(Segments[i].matcen_num), 1, &sum1, &sum2);
s = INTEL_SHORT(Segments[i].value);
mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
t = INTEL_INT(((int)Segments[i].static_light));
mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
#ifndef EDITOR
s = INTEL_SHORT(Segments[i].pad); // necessary? If this isn't set to 0 it won't work Intel-Intel anyway.
mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
#else
s = INTEL_SHORT(0); // no matter if we need alignment on our platform, if we have editor we MUST consider this integer to get the same checksum as non-editor games calculate
do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
#endif
}
sum2 %= 255;
return ((sum1<<8)+ sum2);
}
// this routine totally and completely relies on the fact that the network
// checksum must be calculated on the segments!!!!!
ushort netmisc_calc_checksum(void * vptr, int len)
{
vptr = vptr;
len = len;
return mac_calc_segment_checksum();
}
#else /* !WORDS_BIGENDIAN */
// Calculates the checksum of a block of memory.
ushort netmisc_calc_checksum(void * vptr, int len)
{
ubyte *ptr = (ubyte *)vptr;
unsigned int sum1,sum2;
sum1 = sum2 = 0;
while(len--) {
sum1 += *ptr++;
if (sum1 >= 255) sum1 -= 255;
sum2 += sum1;
}
sum2 %= 255;
return ((sum1<<8)+ sum2);
}
#endif /* WORDS_BIGENDIAN */
//load a level off disk. level numbers start at 1. Secret levels are -1,-2,-3
void LoadLevel(int level_num)
{
@ -696,7 +660,7 @@ void LoadLevel(int level_num)
#endif
#ifdef NETWORK
my_segments_checksum = netmisc_calc_checksum(Segments, sizeof(segment)*(Highest_segment_index+1));
my_segments_checksum = netmisc_calc_checksum();
#endif
load_endlevel_data(level_num);
@ -1314,7 +1278,7 @@ void InitPlayerPosition(int random)
NewPlayer = Player_num;
else if (random == 1)
{
int i, closest = -1, trys=0;
int i, trys=0;
fix closest_dist = 0x7ffffff, dist;
timer_update();
@ -1323,7 +1287,6 @@ void InitPlayerPosition(int random)
trys++;
NewPlayer = d_rand() % NumNetPlayerPositions;
closest = -1;
closest_dist = 0x7fffffff;
for (i=0; i<N_players; i++ ) {
@ -1331,7 +1294,6 @@ void InitPlayerPosition(int random)
dist = find_connected_distance(&Objects[Players[i].objnum].pos, Objects[Players[i].objnum].segnum, &Player_init[NewPlayer].pos, Player_init[NewPlayer].segnum, 15, WID_FLY_FLAG ); // Used to be 5, search up to 15 segments
if ( (dist < closest_dist) && (dist >= 0) ) {
closest_dist = dist;
closest = i;
}
}
}

View file

@ -544,7 +544,6 @@ int do_option ( int select)
create_new_mine();
SetPlayerFromCurseg();
keyd_editor_mode = 1;
hide_menus();
editor();
if ( Function_mode == FMODE_GAME ) {