short pof_read_short(ubyte *bufp) { short s; s = *((short *) &bufp[Pof_addr]); Pof_addr += 2; return INTEL_SHORT(s); // if (PHYSFS_read(f,&s,sizeof(s),1) != 1) // Error("Unexpected end-of-file while reading object"); // // return s; }
// reads header information from the PCX file into the bitmap pointer int pcx_read_header(char *real_filename, int *w, int *h, ubyte *pal ) { PCXHeader header; CFILE * PCXfile; char filename[MAX_FILENAME_LEN]; strcpy( filename, real_filename ); char *p = strchr( filename, '.' ); if ( p ) *p = 0; strcat( filename, ".pcx" ); PCXfile = cfopen( filename , "rb" ); if ( !PCXfile ) return PCX_ERROR_OPENING; // read 128 char PCX header if (cfread( &header, sizeof(PCXHeader), 1, PCXfile )!=1) { cfclose( PCXfile ); return PCX_ERROR_NO_HEADER; } header.Xmin = INTEL_SHORT( header.Xmin ); header.Ymin = INTEL_SHORT( header.Ymin ); header.Xmax = INTEL_SHORT( header.Xmax ); header.Ymax = INTEL_SHORT( header.Ymax ); header.Hdpi = INTEL_SHORT( header.Hdpi ); header.Vdpi = INTEL_SHORT( header.Vdpi ); for ( int i=0; i<16; i++ ){ for ( int j=0; j<3; j++){ header.ColorMap[i][j] = INTEL_INT( header.ColorMap[i][j] ); } } header.BytesPerLine = INTEL_SHORT( header.BytesPerLine ); for ( int i=0; i<60; i++ ){ header.filler[i] = INTEL_INT( header.filler[i] ); } // Is it a 256 color PCX file? if ((header.Manufacturer != 10)||(header.Encoding != 1)||(header.Nplanes != 1)||(header.BitsPerPixel != 8)||(header.Version != 5)) { cfclose( PCXfile ); return PCX_ERROR_WRONG_VERSION; } if (w) *w = header.Xmax - header.Xmin + 1; if (h) *h = header.Ymax - header.Ymin + 1; if ( pal ) { cfseek( PCXfile, -768, CF_SEEK_END ); cfread( pal, 3, 256, PCXfile ); } cfclose(PCXfile); return PCX_ERROR_NONE; }
void BESendMissingObjFrames(ubyte *server, ubyte *node, ubyte *netAddress) { int i; memcpy (nmDataBuf, &networkData.sync [0].objs.missingFrames, sizeof (networkData.sync [0].objs.missingFrames)); ((tMissingObjFrames *) &nmDataBuf [0])->nFrame = INTEL_SHORT (networkData.sync [0].objs.missingFrames.nFrame); i = 2 * sizeof (ubyte) + sizeof (ushort); if (netAddress != NULL) IPXSendPacketData(nmDataBuf, i, server, node, netAddress); else if ((server == NULL) && (node == NULL)) IPXSendBroadcastData(nmDataBuf, i); else IPXSendInternetPacketData(nmDataBuf, i, server, node); }
void gr_bm_ubitblt0x_rle(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest, int masked ) { int i, data_offset; register int y1; unsigned char * sbits; data_offset = 1; if (src->bm_flags & BM_FLAG_RLE_BIG) data_offset = 2; sbits = &src->bm_data[4 + (src->bm_h*data_offset)]; for (i=0; i<sy; i++ ) sbits += (int)(INTEL_SHORT(src->bm_data[4+(i*data_offset)])); for (y1=0; y1 < h; y1++ ) { gr_rle_expand_scanline_generic( dest, dx, dy+y1, sbits, sx, sx+w-1); if ( src->bm_flags & BM_FLAG_RLE_BIG ) sbits += (int)INTEL_SHORT(*((short *)&(src->bm_data[4+((y1+sy)*data_offset)]))); else sbits += (int)src->bm_data[4+y1+sy]; } }
void NetworkSendEndLevelSub (int nPlayer) { tEndLevelInfo end; int i, j = 0; // Send an endlevel packet for a tPlayer end.nType = PID_ENDLEVEL; end.nPlayer = nPlayer; end.connected = gameData.multiplayer.players [nPlayer].connected; end.kills = INTEL_SHORT (gameData.multiplayer.players [nPlayer].netKillsTotal); end.killed = INTEL_SHORT (gameData.multiplayer.players [nPlayer].netKilledTotal); memcpy (end.killMatrix, gameData.multigame.kills.matrix [nPlayer], MAX_PLAYERS*sizeof (short)); #if defined (WORDS_BIGENDIAN) || defined (__BIG_ENDIAN__) for (i = 0; i < MAX_PLAYERS; i++) for (j = 0; j < MAX_PLAYERS; j++) end.killMatrix [i][j] = INTEL_SHORT (end.killMatrix [i][j]); #else j = j; // to satisfy compiler #endif if (gameData.multiplayer.players [nPlayer].connected == 1) {// Still playing Assert (gameData.reactor.bDestroyed); end.seconds_left = gameData.reactor.countdown.nSecsLeft; } for (i = 0; i < gameData.multiplayer.nPlayers; i++) { if ((i != gameData.multiplayer.nLocalPlayer) && (i != nPlayer) && (gameData.multiplayer.players [i].connected)) { if (gameData.multiplayer.players [i].connected == 1) NetworkSendEndLevelShortSub (nPlayer, i); else if (gameStates.multi.nGameType >= IPX_GAME) IPXSendPacketData ( (ubyte *)&end, sizeof (tEndLevelInfo), netPlayers.players [i].network.ipx.server, netPlayers.players [i].network.ipx.node, gameData.multiplayer.players [i].netAddress); } } }
void BESendSequencePacket(sequence_packet seq, ubyte *server, ubyte *node, ubyte *net_address) { short tmps; int loc, tmpi; loc = 0; memset(out_buffer, 0, sizeof(out_buffer)); out_buffer[0] = seq.type; loc++; tmpi = INTEL_INT(seq.Security); memcpy(out_buffer + loc, &tmpi, 4); loc += 4; loc += 3; memcpy(out_buffer + loc, seq.player.callsign, CALLSIGN_LEN+1); loc += CALLSIGN_LEN+1; memcpy(out_buffer + loc, seq.player.network.ipx.server, 4); loc += 4; memcpy(out_buffer + loc, seq.player.network.ipx.node, 6); loc += 6; out_buffer[loc] = seq.player.version_major; loc++; out_buffer[loc] = seq.player.version_minor; loc++; out_buffer[loc] = seq.player.computer_type; loc++; out_buffer[loc] = seq.player.connected; loc++; tmps = INTEL_SHORT(seq.player.socket); memcpy(out_buffer + loc, &tmps, 2); loc += 2; out_buffer[loc]=seq.player.rank; loc++; // for pad byte if (net_address != NULL) IPXSendPacketData(out_buffer, loc, server, node, net_address); else if (!server && !node) IPXSendBroadcastData(out_buffer, loc); else IPXSendInternetPacketData(out_buffer, loc, server, node); }
/* * 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) { short n; ubyte *p = data; while (INTEL_SHORT(w(p)) != OP_EOF) { switch (INTEL_SHORT(w(p))) { case OP_DEFPOINTS: n = INTEL_SHORT(w(p+2)); p += n*sizeof(struct vms_vector) + 4; break; case OP_DEFP_START: n = INTEL_SHORT(w(p+2)); p += n*sizeof(struct vms_vector) + 8; break; case OP_FLATPOLY: n = INTEL_SHORT(w(p+2)); p += 30 + ((n&~1)+1)*2; break; case OP_TMAPPOLY: n = INTEL_SHORT(w(p+2)); p += 30 + ((n&~1)+1)*2 + n*12; break; case OP_SORTNORM: add_chunk(p, p - data + new_data, 28, list, no); add_chunk(p, p - data + new_data, 30, list, no); p += 32; break; case OP_RODBM: p+=36; break; case OP_SUBCALL: add_chunk(p, p - data + new_data, 16, list, no); p+=20; break; case OP_GLOW: p += 4; break; default: Error("invalid polygon model\n"); } } return p + 2 - data; }
ubyte * new_dest(chunk o) // return where chunk is (in aligned struct) { return o.new_base + INTEL_SHORT(*((short *)(o.old_base + o.offset))) + o.correction; }
void receive_d1x_netgame_packet(ubyte *data, netgame_info *netgame) { int i, j; int loc = 0; netgame->type = data[loc]; loc++; if (netgame->type == PID_D1X_GAME_LITE) { memset(netgame, 0, sizeof(netgame_info)); netgame->type = PID_D1X_GAME_LITE; } netgame->protocol_version = data[loc]; loc++; netgame->subprotocol = data[loc]; loc++; netgame->required_subprotocol = data[loc]; loc++; memcpy(netgame->game_name, &(data[loc]), NETGAME_NAME_LEN); loc += NETGAME_NAME_LEN; netgame->game_name[NETGAME_NAME_LEN] = 0; memcpy(netgame->mission_name, &(data[loc]), 8); loc += 8; netgame->mission_name[8] = 0; memcpy(netgame->mission_title, &(data[loc]), MISSION_NAME_LEN); loc += MISSION_NAME_LEN; netgame->mission_title[MISSION_NAME_LEN] = 0; netgame->levelnum = ((signed char *)data)[loc]; loc++; netgame->gamemode = data[loc]; loc++; netgame->difficulty = data[loc]; loc++; netgame->game_status = data[loc]; loc++; netgame->game_flags = data[loc]; loc++; netgame->max_numplayers = data[loc]; loc++; netgame->team_vector = data[loc]; loc++; if (netgame->type == PID_D1X_GAME_LITE) { j = netgame->numplayers = data[loc]; loc++; for (i = 0; i < j; i++) netgame->players[i].connected = 1; get_netplayer_info(&(data[loc]), &(netgame->players[0]), 1);loc += NETPLAYER_D1X_SIZE; //added 4/18/99 Matt Mueller - send .flags as well, so 'I' can show them if (netgame->subprotocol>=1){ memcpy(&netgame->flags, &data[loc], 4); loc += 4; netgame->flags = INTEL_INT(netgame->flags); } //end addition -MM } else { netgame->numplayers = data[loc]; loc++; j = data[loc]; loc++; // sizeof netplayer struct if (j > 29) { /* sanity: 304+29*8=536, just below IPX_MAX=542 */ netgame->protocol_version = 0; return; } for (i = 0; i < MAX_PLAYERS; i++) { get_netplayer_info(&(data[loc]), &(netgame->players[i]), 1); loc += j; } memcpy(netgame->team_name[0], &(data[loc]), CALLSIGN_LEN); loc += CALLSIGN_LEN; netgame->team_name[0][CALLSIGN_LEN] = 0; memcpy(netgame->team_name[1], &(data[loc]), CALLSIGN_LEN); loc += CALLSIGN_LEN; netgame->team_name[1][CALLSIGN_LEN] = 0; for (i = 0; i < MAX_PLAYERS; i++) { netgame->locations[i] = data[loc]; loc++; } for (i = 0; i < MAX_PLAYERS; i++) { for (j = 0; j < MAX_PLAYERS; j++) { memcpy(&(netgame->kills[i][j]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! netgame->kills[i][j] = INTEL_SHORT(netgame->kills[i][j]); } } memcpy(&(netgame->segments_checksum), &(data[loc]), 2); loc += 2; // SWAP_HERE netgame->segments_checksum = INTEL_SHORT(netgame->segments_checksum); memcpy(&(netgame->team_kills[0]), &(data[loc]), 2); loc += 2; // SWAP_HERE netgame->team_kills[0] = INTEL_SHORT(netgame->team_kills[0]); memcpy(&(netgame->team_kills[1]), &(data[loc]), 2); loc += 2; // SWAP_HERE netgame->team_kills[1] = INTEL_SHORT(netgame->team_kills[1]); for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->killed[i]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! netgame->killed[i] = INTEL_SHORT(netgame->killed[i]); } for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->player_kills[i]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! netgame->player_kills[i] = INTEL_SHORT(netgame->player_kills[i]); } memcpy(&(netgame->level_time), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->level_time = INTEL_INT(netgame->level_time); memcpy(&(netgame->control_invul_time), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->control_invul_time = INTEL_INT(netgame->control_invul_time); memcpy(&(netgame->monitor_vector), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->monitor_vector = INTEL_INT(netgame->monitor_vector); for (i = 0; i < 8; i++) { memcpy(&(netgame->player_score[i]), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->player_score[i] = INTEL_INT(netgame->player_score[i]); } memcpy(netgame->player_flags, &(data[loc]), 8); loc += 8; netgame->packets_per_sec = data[loc]; loc++; memcpy(&netgame->flags, &data[loc], 4); loc += 4; netgame->flags = INTEL_INT(netgame->flags); } }
int rle_expand (grsBitmap *bmP, ubyte *colorMap, int bSwap0255) { ubyte *expandBuf, *pSrc, *pDest; ubyte c, h; int i, j, l, bBigRLE; unsigned short nLineSize; if (!(bmP->bm_props.flags & BM_FLAG_RLE)) return bmP->bm_props.h * bmP->bm_props.rowsize; if (!(expandBuf = D2_ALLOC (bmP->bm_props.h * bmP->bm_props.rowsize))) return -1; bBigRLE = (bmP->bm_props.flags & BM_FLAG_RLE_BIG) != 0; if (bBigRLE) pSrc = bmP->bm_texBuf + 4 + 2 * bmP->bm_props.h; else pSrc = bmP->bm_texBuf + 4 + bmP->bm_props.h; pDest = expandBuf; for (i = 0; i < bmP->bm_props.h; i++, pSrc += nLineSize) { if (bBigRLE) nLineSize = INTEL_SHORT (*((unsigned short *) (bmP->bm_texBuf + 4 + 2 * i))); else nLineSize = bmP->bm_texBuf [4 + i]; for (j = 0; j < nLineSize; j++) { h = pSrc [j]; if (!IS_RLE_CODE (h)) { c = colorMap ? colorMap [h] : h; // translate if (bSwap0255) { if (c == 0) c = 255; else if (c == 255) c = 0; } if (pDest - expandBuf > bmP->bm_props.h * bmP->bm_props.rowsize) { D2_FREE (expandBuf); return -1; } *pDest++ = c; } else if ((l = (h & NOT_RLE_CODE))) { c = pSrc [++j]; if (colorMap) c = colorMap [c]; if (bSwap0255) { if (c == 0) c = 255; else if (c == 255) c = 0; } if (pDest - expandBuf + l > bmP->bm_props.h * bmP->bm_props.rowsize) { D2_FREE (expandBuf); return -1; } memset (pDest, c, l); pDest += l; } } } l = (int) (pDest - expandBuf); Assert (l <= bmP->bm_props.h * bmP->bm_props.rowsize); memcpy (bmP->bm_texBuf, expandBuf, l); bmP->bm_props.flags &= ~(BM_FLAG_RLE | BM_FLAG_RLE_BIG); D2_FREE (expandBuf); return l; }
void receive_netgame_packet(ubyte *data, netgame_info *netgame, int d1x) { int i, j; int loc = 0; if (d1x) { receive_d1x_netgame_packet(data, netgame); return; } netgame->type = data[loc]; loc++; memcpy(netgame->game_name, &(data[loc]), NETGAME_NAME_LEN+1); loc += (NETGAME_NAME_LEN+1); memcpy(netgame->team_name, &(data[loc]), 2*(CALLSIGN_LEN+1)); loc += 2*(CALLSIGN_LEN+1); netgame->gamemode = data[loc]; loc++; netgame->difficulty = data[loc]; loc++; netgame->game_status = data[loc]; loc++; netgame->numplayers = data[loc]; loc++; netgame->max_numplayers = data[loc]; loc++; netgame->game_flags = data[loc]; loc++; for (i = 0; i < MAX_PLAYERS; i++) { get_netplayer_info(&(data[loc]), &(netgame->players[i]), 0); loc += NETPLAYER_ORIG_SIZE; } #if 0 if (d1x) { for (i = 0; i < MAX_PLAYERS; i++) { netgame->locations[i] = data[loc]; loc++; } } else #endif { for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->locations[i]), &(data[loc]), 4); loc += 4; // SWAP HERE!!! netgame->locations[i] = INTEL_INT(netgame->locations[i]); } } for (i = 0; i < MAX_PLAYERS; i++) { for (j = 0; j < MAX_PLAYERS; j++) { memcpy(&(netgame->kills[i][j]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! netgame->kills[i][j] = INTEL_SHORT(netgame->kills[i][j]); } } memcpy(&(netgame->levelnum), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->levelnum = INTEL_INT(netgame->levelnum); netgame->protocol_version = data[loc]; loc++; netgame->team_vector = data[loc]; loc++; memcpy(&(netgame->segments_checksum), &(data[loc]), 2); loc += 2; // SWAP_HERE netgame->segments_checksum = INTEL_SHORT(netgame->segments_checksum); memcpy(&(netgame->team_kills[0]), &(data[loc]), 2); loc += 2; // SWAP_HERE netgame->team_kills[0] = INTEL_SHORT(netgame->team_kills[0]); memcpy(&(netgame->team_kills[1]), &(data[loc]), 2); loc += 2; // SWAP_HERE netgame->team_kills[1] = INTEL_SHORT(netgame->team_kills[1]); for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->killed[i]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! netgame->killed[i] = INTEL_SHORT(netgame->killed[i]); } for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->player_kills[i]), &(data[loc]), 2); loc += 2; // SWAP HERE!!! netgame->player_kills[i] = INTEL_SHORT(netgame->player_kills[i]); } memcpy(&(netgame->level_time), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->level_time = INTEL_INT(netgame->level_time); memcpy(&(netgame->control_invul_time), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->control_invul_time = INTEL_INT(netgame->control_invul_time); memcpy(&(netgame->monitor_vector), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->monitor_vector = INTEL_INT(netgame->monitor_vector); for (i = 0; i < 8; i++) { memcpy(&(netgame->player_score[i]), &(data[loc]), 4); loc += 4; // SWAP_HERE netgame->player_score[i] = INTEL_INT(netgame->player_score[i]); } memcpy(netgame->player_flags, &(data[loc]), 8); loc += 8; #if 0 for (i = 0; i < 8; i++) { memcpy(&(netgame->player_flags[i]), &(data[loc]), 1); loc++; } #endif memcpy(netgame->mission_name, &(data[loc]), 9); loc += 9; memcpy(netgame->mission_title, &(data[loc]), MISSION_NAME_LEN+1); loc += (MISSION_NAME_LEN+1); #if 0 if (d1x && netgame->protocol_version == MULTI_PROTO_D1X_VER) { netgame->packets_per_sec = data[loc]; loc++; memcpy(&netgame->flags, &data[loc], 4); loc += 4; netgame->flags = INTEL_INT(netgame->flags); } #endif }
void send_d1x_netgame_packet(ubyte *server, ubyte *node) { uint tmpi; ushort tmps; int i, j; int loc = 0; memset(out_buffer, 0, MAX_DATA_SIZE); out_buffer[loc] = Netgame.type; loc++; out_buffer[loc] = MULTI_PROTO_D1X_VER; loc++; out_buffer[loc] = Netgame.subprotocol; loc++; out_buffer[loc] = Netgame.required_subprotocol; loc++; memcpy(&(out_buffer[loc]), Netgame.game_name, NETGAME_NAME_LEN); loc += NETGAME_NAME_LEN; memcpy(&(out_buffer[loc]), Netgame.mission_name, 8); loc += 8; memcpy(&(out_buffer[loc]), Netgame.mission_title, MISSION_NAME_LEN); loc += MISSION_NAME_LEN; out_buffer[loc] = Netgame.levelnum; loc++; out_buffer[loc] = Netgame.gamemode; loc++; out_buffer[loc] = Netgame.difficulty; loc++; out_buffer[loc] = Netgame.game_status; loc++; out_buffer[loc] = Netgame.game_flags; loc++; out_buffer[loc] = Netgame.max_numplayers; loc++; out_buffer[loc] = Netgame.team_vector; loc++; if (Netgame.type == PID_D1X_GAME_LITE) { int master = -1; j = 0; for (i = 0; i < Netgame.numplayers; i++) if (Players[i].connected) { if (master == -1) master = i; j++; } out_buffer[loc] = j; loc++; /* numconnected */ if (master == -1) /* should not happen, but... */ master = Player_num; put_netplayer_info(&(out_buffer[loc]), &Netgame.players[master], 1); loc += NETPLAYER_D1X_SIZE; //added 4/18/99 Matt Mueller - send .flags as well, so 'I' can show them tmpi = INTEL_INT(Netgame.flags); memcpy(&out_buffer[loc], &tmpi, 4); loc += 4; //end addition -MM } else { out_buffer[loc] = Netgame.numplayers; loc++; out_buffer[loc] = NETPLAYER_D1X_SIZE; loc++; // sizeof netplayer struct for (i = 0; i < MAX_PLAYERS; i++) { put_netplayer_info(&(out_buffer[loc]), &Netgame.players[i], 1); loc += NETPLAYER_D1X_SIZE; } memcpy(&(out_buffer[loc]), Netgame.team_name[0], CALLSIGN_LEN); loc += CALLSIGN_LEN; memcpy(&(out_buffer[loc]), Netgame.team_name[1], CALLSIGN_LEN); loc += CALLSIGN_LEN; for (i = 0; i < MAX_PLAYERS; i++) { out_buffer[loc] = Netgame.locations[i]; loc++; } for (i = 0; i < MAX_PLAYERS; i++) { for (j = 0; j < MAX_PLAYERS; j++) { tmps = INTEL_SHORT(Netgame.kills[i][j]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! } } tmps = INTEL_SHORT(Netgame.segments_checksum); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE tmps = INTEL_SHORT(Netgame.team_kills[0]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE tmps = INTEL_SHORT(Netgame.team_kills[1]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP_HERE for (i = 0; i < MAX_PLAYERS; i++) { tmps = INTEL_SHORT(Netgame.killed[i]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! } for (i = 0; i < MAX_PLAYERS; i++) { tmps = INTEL_SHORT(Netgame.player_kills[i]); memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; // SWAP HERE!!! } tmpi = INTEL_INT(Netgame.level_time); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE tmpi = INTEL_INT(Netgame.control_invul_time); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE tmpi = INTEL_INT(Netgame.monitor_vector); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE for (i = 0; i < 8; i++) { tmpi = INTEL_INT(Netgame.player_score[i]); memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; // SWAP_HERE } memcpy(&(out_buffer[loc]), Netgame.player_flags, MAX_PLAYERS); loc += MAX_PLAYERS; out_buffer[loc] = Netgame.packets_per_sec; loc++; tmpi = INTEL_INT(Netgame.flags); memcpy(&out_buffer[loc], &tmpi, 4); loc += 4; } if (server == NULL) NetDrvSendBroadcastPacketData(out_buffer, loc); else NetDrvSendInternetworkPacketData(out_buffer, loc, server, node); }
void NetworkDoFrame (int bForce, int bListen) { tFrameInfoShort shortSyncPack; static fix xLastEndlevel = 0; int i; if (!(gameData.app.nGameMode & GM_NETWORK)) return; if ((networkData.nStatus == NETSTAT_PLAYING) && !gameStates.app.bEndLevelSequence) { // Don't send postion during escape sequence... if (nakedData.nLength) { Assert (nakedData.nDestPlayer >- 1); if (gameStates.multi.nGameType >= IPX_GAME) IPXSendPacketData (reinterpret_cast<ubyte*> (nakedData.buf), nakedData.nLength, netPlayers.players [nakedData.nDestPlayer].network.ipx.server, netPlayers.players [nakedData.nDestPlayer].network.ipx.node, gameData.multiplayer.players [nakedData.nDestPlayer].netAddress); nakedData.nLength = 0; nakedData.nDestPlayer = -1; } if (networkData.refuse.bWaitForAnswer && TimerGetApproxSeconds ()> (networkData.refuse.xTimeLimit+ (I2X (12)))) networkData.refuse.bWaitForAnswer=0; networkData.xLastSendTime += gameData.time.xFrame; networkData.xLastTimeoutCheck += gameData.time.xFrame; // Send out packet PacksPerSec times per second maximum... unless they fire, then send more often... if ((networkData.xLastSendTime > I2X (1) / PacketsPerSec ()) || (gameData.multigame.laser.bFired) || bForce || networkData.bPacketUrgent) { if (LOCALPLAYER.connected) { int nObject = LOCALPLAYER.nObject; networkData.bPacketUrgent = 0; if (bListen) { MultiSendRobotFrame (0); MultiSendFire (); // Do firing if needed.. } networkData.xLastSendTime = 0; if (netGame.bShortPackets) { #if defined (WORDS_BIGENDIAN) || defined (__BIG_ENDIAN__) ubyte send_data [MAX_PACKETSIZE]; #endif memset (&shortSyncPack, 0, sizeof (shortSyncPack)); CreateShortPos (&shortSyncPack.objPos, OBJECTS+nObject, 0); shortSyncPack.nType = PID_PDATA; shortSyncPack.nPlayer = gameData.multiplayer.nLocalPlayer; shortSyncPack.objRenderType = OBJECTS [nObject].info.renderType; shortSyncPack.nLevel = gameData.missions.nCurrentLevel; shortSyncPack.dataSize = networkData.syncPack.dataSize; memcpy (shortSyncPack.data, networkData.syncPack.data, networkData.syncPack.dataSize); networkData.syncPack.nPackets = INTEL_INT (gameData.multiplayer.players [0].nPacketsSent++); shortSyncPack.nPackets = networkData.syncPack.nPackets; #if !(defined (WORDS_BIGENDIAN) || defined (__BIG_ENDIAN__)) IpxSendGamePacket ( reinterpret_cast<ubyte*> (&shortSyncPack), sizeof (tFrameInfoShort) - networkData.nMaxXDataSize + networkData.syncPack.dataSize); #else SquishShortFrameInfo (shortSyncPack, send_data); IpxSendGamePacket ( reinterpret_cast<ubyte*> (send_data), IPX_SHORT_INFO_SIZE-networkData.nMaxXDataSize+networkData.syncPack.dataSize); #endif } else {// If long packets int send_dataSize; networkData.syncPack.nType = PID_PDATA; networkData.syncPack.nPlayer = gameData.multiplayer.nLocalPlayer; networkData.syncPack.objRenderType = OBJECTS [nObject].info.renderType; networkData.syncPack.nLevel = gameData.missions.nCurrentLevel; networkData.syncPack.nObjSeg = OBJECTS [nObject].info.nSegment; networkData.syncPack.objPos = OBJECTS [nObject].info.position.vPos; networkData.syncPack.objOrient = OBJECTS [nObject].info.position.mOrient; networkData.syncPack.physVelocity = OBJECTS [nObject].mType.physInfo.velocity; networkData.syncPack.physRotVel = OBJECTS [nObject].mType.physInfo.rotVel; send_dataSize = networkData.syncPack.dataSize; // do this so correct size data is sent #if defined (WORDS_BIGENDIAN) || defined (__BIG_ENDIAN__) // do the swap stuff if (gameStates.multi.nGameType >= IPX_GAME) { networkData.syncPack.nObjSeg = INTEL_SHORT (networkData.syncPack.nObjSeg); INTEL_VECTOR (networkData.syncPack.objPos); INTEL_MATRIX (networkData.syncPack.objOrient); INTEL_VECTOR (networkData.syncPack.physVelocity); INTEL_VECTOR (networkData.syncPack.physRotVel); networkData.syncPack.dataSize = INTEL_SHORT (networkData.syncPack.dataSize); } #endif networkData.syncPack.nPackets = INTEL_INT (gameData.multiplayer.players [0].nPacketsSent++); IpxSendGamePacket ( reinterpret_cast<ubyte*> (&networkData.syncPack), sizeof (tFrameInfo) - networkData.nMaxXDataSize + send_dataSize); } networkData.syncPack.dataSize = 0; // Start data over at 0 length. networkData.bD2XData = 0; if (gameData.reactor.bDestroyed) { if (gameStates.app.bPlayerIsDead) LOCALPLAYER.connected=3; if (TimerGetApproxSeconds () > (xLastEndlevel+ (I2X (1)/2))) { NetworkSendEndLevelPacket (); xLastEndlevel = TimerGetApproxSeconds (); } } } } if (!bListen) return; if ((networkData.xLastTimeoutCheck > I2X (1)) && !gameData.reactor.bDestroyed) { fix t = (fix) SDL_GetTicks (); // Check for CPlayerData timeouts for (i = 0; i < gameData.multiplayer.nPlayers; i++) { if ((i != gameData.multiplayer.nLocalPlayer) && ((gameData.multiplayer.players [i].connected == 1) || downloadManager.Downloading (i))) { if ((networkData.nLastPacketTime [i] == 0) || (networkData.nLastPacketTime [i] + downloadManager.GetTimeoutSecs () * 1000 > t)) { ResetPlayerTimeout (i, t); continue; } #if 1//!DBG if (gameOpts->multi.bTimeoutPlayers && (t - networkData.nLastPacketTime [i] > 15000)) NetworkTimeoutPlayer (i); #endif } } networkData.xLastTimeoutCheck = 0; } } if (!bListen) { networkData.syncPack.dataSize = 0; return; } NetworkListen (); #if 0 if ((networkData.sync.nPlayer != -1) && !(gameData.app.nFrameCount & 63)) ResendSyncDueToPacketLoss (); // This will resend to network_player_rejoining #endif NetworkDoSyncFrame (); if (NetworkIAmMaster ()) tracker.AddServer (); }
void NetworkSyncObjects (tNetworkSyncData *syncP) { tObject *objP; sbyte owner; short nRemoteObj; int bufI, i, h; int nObjFrames = 0; int nPlayer = syncP->player [1].player.connected; // Send clear OBJECTS array tTrigger and send tPlayer num objFilter [OBJ_MARKER] = !gameStates.app.bHaveExtraGameInfo [1]; for (h = 0; h < OBJ_PACKETS_PER_FRAME; h++) { // Do more than 1 per frame, try to speed it up without // over-stressing the receiver. nObjFrames = 0; memset (objBuf, 0, DATALIMIT); objBuf [0] = PID_OBJECT_DATA; bufI = (gameStates.multi.nGameType == UDP_GAME) ? 4 : 3; if (syncP->objs.nCurrent == -1) { // first packet tells the receiver to reset it's object data syncP->objs.nSent = 0; syncP->objs.nMode = 0; syncP->objs.nFrame = 0; NW_SET_SHORT (objBuf, bufI, syncP->objs.missingFrames.nFrame ? -3 : -1); // object number -1 NW_SET_BYTE (objBuf, bufI, nPlayer); bufI += 2; // Placeholder for nRemoteObj, not used here syncP->objs.nCurrent = 0; syncP->objs.nFrame = 0; nObjFrames = 1; // first frame contains "reset object data" info } for (i = syncP->objs.nCurrent, objP = OBJECTS + i; i <= gameData.objs.nLastObject [0]; i++, objP++) { if (NetworkFilterObject (objP)) continue; if (syncP->objs.nMode) { if ((gameData.multigame.nObjOwner [i] != -1) && (gameData.multigame.nObjOwner [i] != nPlayer)) continue; } else { if ((gameData.multigame.nObjOwner [i] == -1) || (gameData.multigame.nObjOwner [i] == nPlayer)) continue; } if ((DATALIMIT - bufI - 1) < (int) sizeof (tObject) + 5) break; // Not enough room for another tObject nObjFrames++; syncP->objs.nSent++; nRemoteObj = ObjnumLocalToRemote ((short) i, &owner); Assert (owner == gameData.multigame.nObjOwner [i]); NW_SET_SHORT (objBuf, bufI, i); NW_SET_BYTE (objBuf, bufI, owner); NW_SET_SHORT (objBuf, bufI, nRemoteObj); NW_SET_BYTES (objBuf, bufI, objP, sizeof (tObject)); if (gameStates.multi.nGameType >= IPX_GAME) SwapObject ((tObject *) (objBuf + bufI - sizeof (tBaseObject))); } if (nObjFrames) { // Send any objects we've buffered syncP->objs.nCurrent = i; if (NetworkObjFrameFilter (syncP)) { objBuf [1] = nObjFrames; if (gameStates.multi.nGameType == UDP_GAME) *((short *) (objBuf + 2)) = INTEL_SHORT (syncP->objs.nFrame); else objBuf [2] = (ubyte) syncP->objs.nFrame; Assert (bufI <= DATALIMIT); if (gameStates.multi.nGameType >= IPX_GAME) IPXSendInternetPacketData ( objBuf, bufI, syncP->player [1].player.network.ipx.server, syncP->player [1].player.network.ipx.node); } } if (i > gameData.objs.nLastObject [0]) { if (syncP->objs.nMode) { syncP->objs.nCurrent = i; // Send count so other tSide can make sure he got them all objBuf [0] = PID_OBJECT_DATA; objBuf [1] = 1; syncP->objs.nFrame++; if (gameStates.multi.nGameType == UDP_GAME) { bufI = 2; NW_SET_SHORT (objBuf, bufI, syncP->objs.nFrame); } else { objBuf [2] = (ubyte) syncP->objs.nFrame; bufI = 3; } nRemoteObj = syncP->objs.missingFrames.nFrame ? -4 : -2; NW_SET_SHORT (objBuf, bufI, nRemoteObj); NW_SET_SHORT (objBuf, bufI, syncP->objs.nSent); syncP->nState = syncP->objs.missingFrames.nFrame ? 1 : 2; } else { syncP->objs.nCurrent = 0; syncP->objs.nMode = 1; // go to next mode } break; } } }
void BESendNetGamePacket(ubyte *server, ubyte *node, ubyte *net_address, int lite_flag) // lite says shorter netgame packets { uint tmpi; ushort tmps; // p; int i, j; int loc = 0; memset(out_buffer, 0, IPX_MAX_DATA_SIZE); memcpy(out_buffer + loc, &(netGame.type), 1); loc++; tmpi = INTEL_INT(netGame.Security); memcpy(out_buffer + loc, &tmpi, 4); loc += 4; memcpy(out_buffer + loc, netGame.game_name, NETGAME_NAME_LEN+1); loc += (NETGAME_NAME_LEN+1); memcpy(out_buffer + loc, netGame.mission_title, MISSION_NAME_LEN+1); loc += (MISSION_NAME_LEN+1); memcpy(out_buffer + loc, netGame.mission_name, 9); loc += 9; tmpi = INTEL_INT(netGame.levelnum); memcpy(out_buffer + loc, &tmpi, 4); loc += 4; memcpy(out_buffer + loc, &(netGame.gamemode), 1); loc++; memcpy(out_buffer + loc, &(netGame.RefusePlayers), 1); loc++; memcpy(out_buffer + loc, &(netGame.difficulty), 1); loc++; memcpy(out_buffer + loc, &(netGame.game_status), 1); loc++; memcpy(out_buffer + loc, &(netGame.numplayers), 1); loc++; memcpy(out_buffer + loc, &(netGame.max_numplayers), 1); loc++; memcpy(out_buffer + loc, &(netGame.numconnected), 1); loc++; memcpy(out_buffer + loc, &(netGame.game_flags), 1); loc++; memcpy(out_buffer + loc, &(netGame.protocol_version), 1); loc++; memcpy(out_buffer + loc, &(netGame.version_major), 1); loc++; memcpy(out_buffer + loc, &(netGame.version_minor), 1); loc++; memcpy(out_buffer + loc, &(netGame.team_vector), 1); loc++; if (lite_flag) goto do_send; // will this work -- damn bitfields -- totally bogus when trying to do // this type of stuff // Watcom makes bitfields from left to right. CW7 on the mac goes // from right to left. then they are endian swapped tmps = *(ushort *)((ubyte *)(&netGame.team_vector) + 1); // get the values for the first short bitfield tmps = INTEL_SHORT(tmps); memcpy(out_buffer + loc, &tmps, 2); loc += 2; tmps = *(ushort *)((ubyte *)(&netGame.team_vector) + 3); // get the values for the second short bitfield tmps = INTEL_SHORT(tmps); memcpy(out_buffer + loc, &tmps, 2); loc += 2; #if 0 // removed since I reordered bitfields on mac p = *(ushort *)((ubyte *)(&netGame.team_vector) + 1); // get the values for the first short bitfield tmps = 0; for (i = 15; i >= 0; i--) { if (p & (1 << i)) tmps |= (1 << (15 - i); } tmps = INTEL_SHORT(tmps); memcpy(out_buffer + loc, &tmps, 2); loc += 2; p = *(ushort *)((ubyte *)(&netGame.team_vector) + 3); // get the values for the second short bitfield tmps = 0; for (i = 15; i >= 0; i--) { if (p & (1 << i)) tmps |= (1 << (15 - i); } tmps = INTEL_SHORT(tmps); memcpy(out_buffer + loc, &tmps, 2); loc += 2; #endif memcpy(out_buffer + loc, netGame.team_name, 2*(CALLSIGN_LEN+1)); loc += 2*(CALLSIGN_LEN+1); for (i = 0; i < MAX_PLAYERS; i++) { tmpi = INTEL_INT(netGame.locations[i]); memcpy(out_buffer + loc, &tmpi, 4); loc += 4; // SWAP HERE!!! } for (i = 0; i < MAX_PLAYERS; i++) { for (j = 0; j < MAX_PLAYERS; j++) { tmps = INTEL_SHORT(netGame.kills[i][j]); memcpy(out_buffer + loc, &tmps, 2); loc += 2; // SWAP HERE!!! } } tmps = INTEL_SHORT(netGame.segments_checksum); memcpy(out_buffer + loc, &tmps, 2); loc += 2; // SWAP_HERE tmps = INTEL_SHORT(netGame.team_kills[0]); memcpy(out_buffer + loc, &tmps, 2); loc += 2; // SWAP_HERE tmps = INTEL_SHORT(netGame.team_kills[1]); memcpy(out_buffer + loc, &tmps, 2); loc += 2; // SWAP_HERE for (i = 0; i < MAX_PLAYERS; i++) { tmps = INTEL_SHORT(netGame.killed[i]); memcpy(out_buffer + loc, &tmps, 2); loc += 2; // SWAP HERE!!! } for (i = 0; i < MAX_PLAYERS; i++) { tmps = INTEL_SHORT(netGame.player_kills[i]); memcpy(out_buffer + loc, &tmps, 2); loc += 2; // SWAP HERE!!! } tmpi = INTEL_INT(netGame.KillGoal); memcpy(out_buffer + loc, &tmpi, 4); loc += 4; // SWAP_HERE tmpi = INTEL_INT(netGame.PlayTimeAllowed); memcpy(out_buffer + loc, &tmpi, 4); loc += 4; // SWAP_HERE tmpi = INTEL_INT(netGame.level_time); memcpy(out_buffer + loc, &tmpi, 4); loc += 4; // SWAP_HERE tmpi = INTEL_INT(netGame.control_invul_time); memcpy(out_buffer + loc, &tmpi, 4); loc += 4; // SWAP_HERE tmpi = INTEL_INT(netGame.monitor_vector); memcpy(out_buffer + loc, &tmpi, 4); loc += 4; // SWAP_HERE for (i = 0; i < MAX_PLAYERS; i++) { tmpi = INTEL_INT(netGame.player_score[i]); memcpy(out_buffer + loc, &tmpi, 4); loc += 4; // SWAP_HERE } for (i = 0; i < MAX_PLAYERS; i++) { memcpy(out_buffer + loc, &(netGame.player_flags[i]), 1); loc++; } tmps = INTEL_SHORT(netGame.nPacketsPerSec); memcpy(out_buffer + loc, &tmps, 2); loc += 2; memcpy(out_buffer + loc, &(netGame.bShortPackets), 1); loc++; do_send: if (net_address != NULL) IPXSendPacketData(out_buffer, loc, server, node, net_address); else if ((server == NULL) && (node == NULL)) IPXSendBroadcastData(out_buffer, loc); else IPXSendInternetPacketData(out_buffer, loc, server, node); }
void BESwapObject(object *objP) { // swap the short and int entries for this object objP->signature = INTEL_INT(objP->signature); objP->next = INTEL_SHORT(objP->next); objP->prev = INTEL_SHORT(objP->prev); objP->segnum = INTEL_SHORT(objP->segnum); objP->pos.x = INTEL_INT(objP->pos.x); objP->pos.y = INTEL_INT(objP->pos.y); objP->pos.z = INTEL_INT(objP->pos.z); objP->orient.rvec.x = INTEL_INT(objP->orient.rvec.x); objP->orient.rvec.y = INTEL_INT(objP->orient.rvec.y); objP->orient.rvec.z = INTEL_INT(objP->orient.rvec.z); objP->orient.fvec.x = INTEL_INT(objP->orient.fvec.x); objP->orient.fvec.y = INTEL_INT(objP->orient.fvec.y); objP->orient.fvec.z = INTEL_INT(objP->orient.fvec.z); objP->orient.uvec.x = INTEL_INT(objP->orient.uvec.x); objP->orient.uvec.y = INTEL_INT(objP->orient.uvec.y); objP->orient.uvec.z = INTEL_INT(objP->orient.uvec.z); objP->size = INTEL_INT(objP->size); objP->shields = INTEL_INT(objP->shields); objP->last_pos.x = INTEL_INT(objP->last_pos.x); objP->last_pos.y = INTEL_INT(objP->last_pos.y); objP->last_pos.z = INTEL_INT(objP->last_pos.z); objP->lifeleft = INTEL_INT(objP->lifeleft); switch (objP->movement_type) { case MT_PHYSICS: objP->mtype.phys_info.velocity.x = INTEL_INT(objP->mtype.phys_info.velocity.x); objP->mtype.phys_info.velocity.y = INTEL_INT(objP->mtype.phys_info.velocity.y); objP->mtype.phys_info.velocity.z = INTEL_INT(objP->mtype.phys_info.velocity.z); objP->mtype.phys_info.thrust.x = INTEL_INT(objP->mtype.phys_info.thrust.x); objP->mtype.phys_info.thrust.y = INTEL_INT(objP->mtype.phys_info.thrust.y); objP->mtype.phys_info.thrust.z = INTEL_INT(objP->mtype.phys_info.thrust.z); objP->mtype.phys_info.mass = INTEL_INT(objP->mtype.phys_info.mass); objP->mtype.phys_info.drag = INTEL_INT(objP->mtype.phys_info.drag); objP->mtype.phys_info.brakes = INTEL_INT(objP->mtype.phys_info.brakes); objP->mtype.phys_info.rotvel.x = INTEL_INT(objP->mtype.phys_info.rotvel.x); objP->mtype.phys_info.rotvel.y = INTEL_INT(objP->mtype.phys_info.rotvel.y); objP->mtype.phys_info.rotvel.z = INTEL_INT(objP->mtype.phys_info.rotvel.z); objP->mtype.phys_info.rotthrust.x = INTEL_INT(objP->mtype.phys_info.rotthrust.x); objP->mtype.phys_info.rotthrust.y = INTEL_INT(objP->mtype.phys_info.rotthrust.y); objP->mtype.phys_info.rotthrust.z = INTEL_INT(objP->mtype.phys_info.rotthrust.z); objP->mtype.phys_info.turnroll = INTEL_INT(objP->mtype.phys_info.turnroll); objP->mtype.phys_info.flags = INTEL_SHORT(objP->mtype.phys_info.flags); break; case MT_SPINNING: objP->mtype.spin_rate.x = INTEL_INT(objP->mtype.spin_rate.x); objP->mtype.spin_rate.y = INTEL_INT(objP->mtype.spin_rate.y); objP->mtype.spin_rate.z = INTEL_INT(objP->mtype.spin_rate.z); break; } switch (objP->control_type) { case CT_WEAPON: objP->ctype.laser_info.parent_type = INTEL_SHORT(objP->ctype.laser_info.parent_type); objP->ctype.laser_info.parent_num = INTEL_SHORT(objP->ctype.laser_info.parent_num); objP->ctype.laser_info.parent_signature = INTEL_INT(objP->ctype.laser_info.parent_signature); objP->ctype.laser_info.creation_time = INTEL_INT(objP->ctype.laser_info.creation_time); objP->ctype.laser_info.last_hitobj = INTEL_SHORT(objP->ctype.laser_info.last_hitobj); objP->ctype.laser_info.track_goal = INTEL_SHORT(objP->ctype.laser_info.track_goal); objP->ctype.laser_info.multiplier = INTEL_INT(objP->ctype.laser_info.multiplier); break; case CT_EXPLOSION: objP->ctype.expl_info.spawn_time = INTEL_INT(objP->ctype.expl_info.spawn_time); objP->ctype.expl_info.delete_time = INTEL_INT(objP->ctype.expl_info.delete_time); objP->ctype.expl_info.delete_objnum = INTEL_SHORT(objP->ctype.expl_info.delete_objnum); objP->ctype.expl_info.attach_parent = INTEL_SHORT(objP->ctype.expl_info.attach_parent); objP->ctype.expl_info.prev_attach = INTEL_SHORT(objP->ctype.expl_info.prev_attach); objP->ctype.expl_info.next_attach = INTEL_SHORT(objP->ctype.expl_info.next_attach); break; case CT_AI: objP->ctype.ai_info.hide_segment = INTEL_SHORT(objP->ctype.ai_info.hide_segment); objP->ctype.ai_info.hide_index = INTEL_SHORT(objP->ctype.ai_info.hide_index); objP->ctype.ai_info.path_length = INTEL_SHORT(objP->ctype.ai_info.path_length); objP->ctype.ai_info.danger_laser_num = INTEL_SHORT(objP->ctype.ai_info.danger_laser_num); objP->ctype.ai_info.danger_laser_signature = INTEL_INT(objP->ctype.ai_info.danger_laser_signature); objP->ctype.ai_info.dying_start_time = INTEL_INT(objP->ctype.ai_info.dying_start_time); break; case CT_LIGHT: objP->ctype.light_info.intensity = INTEL_INT(objP->ctype.light_info.intensity); break; case CT_POWERUP: objP->ctype.powerup_info.count = INTEL_INT(objP->ctype.powerup_info.count); objP->ctype.powerup_info.creation_time = INTEL_INT(objP->ctype.powerup_info.creation_time); // Below commented out 5/2/96 by Matt. I asked Allender why it was // here, and he didn't know, and it looks like it doesn't belong. // if (objP->id == POW_VULCAN_WEAPON) // objP->ctype.powerup_info.count = VULCAN_WEAPON_AMMO_AMOUNT; break; } switch (objP->render_type) { case RT_MORPH: case RT_POLYOBJ: { int i; objP->rtype.pobj_info.model_num = INTEL_INT(objP->rtype.pobj_info.model_num); for (i=0;i<MAX_SUBMODELS;i++) { objP->rtype.pobj_info.anim_angles[i].p = INTEL_INT(objP->rtype.pobj_info.anim_angles[i].p); objP->rtype.pobj_info.anim_angles[i].b = INTEL_INT(objP->rtype.pobj_info.anim_angles[i].b); objP->rtype.pobj_info.anim_angles[i].h = INTEL_INT(objP->rtype.pobj_info.anim_angles[i].h); } objP->rtype.pobj_info.subobj_flags = INTEL_INT(objP->rtype.pobj_info.subobj_flags); objP->rtype.pobj_info.tmap_override = INTEL_INT(objP->rtype.pobj_info.tmap_override); objP->rtype.pobj_info.alt_textures = INTEL_INT(objP->rtype.pobj_info.alt_textures); break; } case RT_WEAPON_VCLIP: case RT_HOSTAGE: case RT_POWERUP: case RT_FIREBALL: case RT_THRUSTER: objP->rtype.vclip_info.nClipIndex = INTEL_INT(objP->rtype.vclip_info.nClipIndex); objP->rtype.vclip_info.xFrameTime = INTEL_INT(objP->rtype.vclip_info.xFrameTime); break; case RT_LASER: break; } // END OF SWAPPING OBJECT STRUCTURE }
ubyte * old_dest(chunk o) // return where chunk is (in unaligned struct) { return o.old_base + INTEL_SHORT(*((short *)(o.old_base + o.offset))); }
/** * @return -1 if couldn't init font, otherwise returns the font id number. */ int gr_create_font(char * typeface) { CFILE *fp; font *fnt; int n, fontnum; fnt = Fonts; n = -1; for (fontnum=0; fontnum<Num_fonts; fontnum++ ) { if (fnt->id != 0 ) { if ( !_strnicmp( fnt->filename, typeface, MAX_FILENAME_LEN ) ) { return fontnum; } } else { if ( n < 0 ) { n = fontnum; } } fnt++; } if ( fontnum == MAX_FONTS ) { Warning( LOCATION, "Too many fonts!\nSee John, or change MAX_FONTS in Graphics\\Font.h\n" ); return -1; } if ( fontnum == Num_fonts ) { Num_fonts++; } bool localize = true; fp = cfopen( typeface, "rb", CFILE_NORMAL, CF_TYPE_ANY, localize ); if ( fp == NULL ) return -1; strncpy( fnt->filename, typeface, MAX_FILENAME_LEN ); cfread( &fnt->id, 4, 1, fp ); cfread( &fnt->version, sizeof(int), 1, fp ); cfread( &fnt->num_chars, sizeof(int), 1, fp ); cfread( &fnt->first_ascii, sizeof(int), 1, fp ); cfread( &fnt->w, sizeof(int), 1, fp ); cfread( &fnt->h, sizeof(int), 1, fp ); cfread( &fnt->num_kern_pairs, sizeof(int), 1, fp ); cfread( &fnt->kern_data_size, sizeof(int), 1, fp ); cfread( &fnt->char_data_size, sizeof(int), 1, fp ); cfread( &fnt->pixel_data_size, sizeof(int), 1, fp ); fnt->id = INTEL_SHORT( fnt->id ); //-V570 fnt->version = INTEL_INT( fnt->version ); //-V570 fnt->num_chars = INTEL_INT( fnt->num_chars ); //-V570 fnt->first_ascii = INTEL_INT( fnt->first_ascii ); //-V570 fnt->w = INTEL_INT( fnt->w ); //-V570 fnt->h = INTEL_INT( fnt->h ); //-V570 fnt->num_kern_pairs = INTEL_INT( fnt->num_kern_pairs ); //-V570 fnt->kern_data_size = INTEL_INT( fnt->kern_data_size ); //-V570 fnt->char_data_size = INTEL_INT( fnt->char_data_size ); //-V570 fnt->pixel_data_size = INTEL_INT( fnt->pixel_data_size ); //-V570 if ( fnt->kern_data_size ) { fnt->kern_data = (font_kernpair *)vm_malloc( fnt->kern_data_size ); Assert(fnt->kern_data!=NULL); cfread( fnt->kern_data, fnt->kern_data_size, 1, fp ); } else { fnt->kern_data = NULL; } if ( fnt->char_data_size ) { fnt->char_data = (font_char *)vm_malloc( fnt->char_data_size ); Assert( fnt->char_data != NULL ); cfread( fnt->char_data, fnt->char_data_size, 1, fp ); for (int i=0; i<fnt->num_chars; i++) { fnt->char_data[i].spacing = INTEL_INT( fnt->char_data[i].spacing ); //-V570 fnt->char_data[i].byte_width = INTEL_INT( fnt->char_data[i].byte_width ); //-V570 fnt->char_data[i].offset = INTEL_INT( fnt->char_data[i].offset ); //-V570 fnt->char_data[i].kerning_entry = INTEL_INT( fnt->char_data[i].kerning_entry ); //-V570 fnt->char_data[i].user_data = INTEL_SHORT( fnt->char_data[i].user_data ); //-V570 } } else { fnt->char_data = NULL; } if ( fnt->pixel_data_size ) { fnt->pixel_data = (ubyte *)vm_malloc( fnt->pixel_data_size ); Assert(fnt->pixel_data!=NULL); cfread( fnt->pixel_data, fnt->pixel_data_size, 1, fp ); } else { fnt->pixel_data = NULL; } cfclose(fp); // Create a bitmap for hardware cards. // JAS: Try to squeeze this into the smallest square power of two texture. // This should probably be done at font generation time, not here. int w, h; if ( fnt->pixel_data_size*4 < 64*64 ) { w = h = 64; } else if ( fnt->pixel_data_size*4 < 128*128 ) { w = h = 128; } else if ( fnt->pixel_data_size*4 < 256*256 ) { w = h = 256; } else if ( fnt->pixel_data_size*4 < 512*512 ) { w = h = 512; } else { w = h = 1024; } fnt->bm_w = w; fnt->bm_h = h; fnt->bm_data = (ubyte *)vm_malloc(fnt->bm_w*fnt->bm_h); fnt->bm_u = (int *)vm_malloc(sizeof(int)*fnt->num_chars); fnt->bm_v = (int *)vm_malloc(sizeof(int)*fnt->num_chars); memset( fnt->bm_data, 0, fnt->bm_w * fnt->bm_h ); int i,x,y; x = y = 0; for (i=0; i<fnt->num_chars; i++ ) { ubyte * ubp; int x1, y1; ubp = &fnt->pixel_data[fnt->char_data[i].offset]; if ( x + fnt->char_data[i].byte_width >= fnt->bm_w ) { x = 0; y += fnt->h + 2; if ( y+fnt->h > fnt->bm_h ) { Error( LOCATION, "Font too big!\n" ); } } fnt->bm_u[i] = x; fnt->bm_v[i] = y; for( y1=0; y1<fnt->h; y1++ ) { for (x1=0; x1<fnt->char_data[i].byte_width; x1++ ) { uint c = *ubp++; if ( c > 14 ) c = 14; fnt->bm_data[(x+x1)+(y+y1)*fnt->bm_w] = (unsigned char)(c); } } x += fnt->char_data[i].byte_width + 2; } fnt->bitmap_id = bm_create( 8, fnt->bm_w, fnt->bm_h, fnt->bm_data, BMP_AABITMAP ); return fontnum; }
//int pcx_read_bitmap_16bpp( char * real_filename, ubyte *org_data, ubyte bpp, int aabitmap, int nondark ) int pcx_read_bitmap( const char * real_filename, ubyte *org_data, ubyte *pal, int byte_size, int aabitmap, int nondark, int cf_type ) { PCXHeader header; CFILE * PCXfile; int row, col, count, xsize, ysize; ubyte data=0; int buffer_size, buffer_pos; ubyte buffer[1024]; ubyte *pixdata; char filename[MAX_FILENAME_LEN]; ubyte palette[768]; ushort bit_16; COLOR32 bit_32; ubyte r, g, b, al; strcpy_s( filename, real_filename ); char *p = strchr( filename, '.' ); if ( p ) *p = 0; strcat_s( filename, ".pcx" ); PCXfile = cfopen( filename , "rb", CFILE_NORMAL, cf_type ); if ( !PCXfile ){ return PCX_ERROR_OPENING; } // read 128 char PCX header if (cfread( &header, sizeof(PCXHeader), 1, PCXfile )!=1) { cfclose( PCXfile ); return PCX_ERROR_NO_HEADER; } header.Xmin = INTEL_SHORT( header.Xmin ); //-V570 header.Ymin = INTEL_SHORT( header.Ymin ); //-V570 header.Xmax = INTEL_SHORT( header.Xmax ); //-V570 header.Ymax = INTEL_SHORT( header.Ymax ); //-V570 header.Hdpi = INTEL_SHORT( header.Hdpi ); //-V570 header.Vdpi = INTEL_SHORT( header.Vdpi ); //-V570 header.BytesPerLine = INTEL_SHORT( header.BytesPerLine ); //-V570 // Is it a 256 color PCX file? if ((header.Manufacturer != 10)||(header.Encoding != 1)||(header.Nplanes != 1)||(header.BitsPerPixel != 8)||(header.Version != 5)) { cfclose( PCXfile ); return PCX_ERROR_WRONG_VERSION; } // Find the size of the image xsize = header.Xmax - header.Xmin + 1; ysize = header.Ymax - header.Ymin + 1; // Read the extended palette at the end of PCX file // Read in a character which should be 12 to be extended palette file cfseek( PCXfile, -768, CF_SEEK_END ); cfread( palette, 1, (3 * 256), PCXfile ); cfseek( PCXfile, sizeof(PCXHeader), CF_SEEK_SET ); buffer_size = 1024; buffer_pos = 0; // Assert( buffer_size == 1024 ); // AL: removed to avoid optimized warning 'unreachable code' buffer_size = cfread( buffer, 1, buffer_size, PCXfile ); count = 0; for (row=0; row<ysize;row++) { pixdata = org_data; for (col=0; col<header.BytesPerLine;col++) { if ( count == 0 ) { data = buffer[buffer_pos++]; if ( buffer_pos == buffer_size ) { buffer_size = cfread( buffer, 1, buffer_size, PCXfile ); Assert( buffer_size > 0 ); buffer_pos = 0; } if ((data & 0xC0) == 0xC0) { count = data & 0x3F; data = buffer[buffer_pos++]; if ( buffer_pos == buffer_size ) { buffer_size = cfread( buffer, 1, buffer_size, PCXfile ); Assert( buffer_size > 0 ); buffer_pos = 0; } } else { count = 1; } } // stuff the pixel if ( col < xsize ) { // 8-bit PCX reads if ( byte_size == 1 ) { *pixdata++ = data; } else { // 16-bit AABITMAP reads if ( (byte_size == 2) && aabitmap ) { // stuff the pixel // memcpy(pixdata, &data, 2); *((ushort*)pixdata) = (ushort)data; } else { // stuff the 24 bit value r = palette[data*3]; g = palette[data*3 + 1]; b = palette[data*3 + 2]; // clear the pixel bit_16 = 0; memset(&bit_32, 0, sizeof(COLOR32)); // 16-bit non-darkening reads if ( (byte_size == 2) && nondark ) { al = 0; if (palman_is_nondarkening(r, g, b)) { al = 255; } } else { // if the color matches the transparent color, make it so al = 255; if ( (0 == (int)palette[data*3]) && (255 == (int)palette[data*3+1]) && (0 == (int)palette[data*3+2]) ) { r = b = 0; g = (byte_size == 4) ? 0 : 255; al = 0; } } // normal 16-bit reads if ( byte_size == 2 ) { // stuff the color bm_set_components((ubyte*)&bit_16, &r, &g, &b, &al); // stuff the pixel *((ushort*)pixdata) = bit_16; } // normal 32-bit reads else if ( byte_size == 4 ) { if ( /*(r == 0) && (b == 0) && (g == 255) && (al == 0)*/ 0 ) { memset(&bit_32, 0, sizeof(COLOR32)); } else { bit_32.r = r; bit_32.g = g; bit_32.b = b; bit_32.a = al; } // stuff the pixel *((COLOR32*)pixdata) = bit_32; } } pixdata += byte_size; } } count--; } org_data += (xsize * byte_size); } cfclose(PCXfile); return PCX_ERROR_NONE; }
int CFWriteShort (short s, CFILE *file) { s = INTEL_SHORT (s); return CFWrite (&s, sizeof (s), 1, file); }
int CFWriteFixAng (fixang a, CFILE *file) { a = INTEL_SHORT (a); return CFWrite (&a, sizeof (a), 1, file); }
void BEReceiveNetGamePacket(ubyte *data, netgame_info *netgame, int lite_flag) { int i, j; int loc = 0; short bitfield; // new_field; memcpy(&(netgame->type), data + loc, 1); loc++; memcpy(&(netgame->Security), data + loc, 4); loc += 4; netgame->Security = INTEL_INT(netgame->Security); memcpy(netgame->game_name, data + loc, NETGAME_NAME_LEN+1); loc += (NETGAME_NAME_LEN+1); memcpy(netgame->mission_title, data + loc, MISSION_NAME_LEN+1); loc += (MISSION_NAME_LEN+1); memcpy(netgame->mission_name, data + loc, 9); loc += 9; memcpy(&(netgame->levelnum), data + loc, 4); loc += 4; netgame->levelnum = INTEL_INT(netgame->levelnum); memcpy(&(netgame->gamemode), data + loc, 1); loc++; memcpy(&(netgame->RefusePlayers), data + loc, 1); loc++; memcpy(&(netgame->difficulty), data + loc, 1); loc++; memcpy(&(netgame->game_status), data + loc, 1); loc++; memcpy(&(netgame->numplayers), data + loc, 1); loc++; memcpy(&(netgame->max_numplayers), data + loc, 1); loc++; memcpy(&(netgame->numconnected), data + loc, 1); loc++; memcpy(&(netgame->game_flags), data + loc, 1); loc++; memcpy(&(netgame->protocol_version), data + loc, 1); loc++; memcpy(&(netgame->version_major), data + loc, 1); loc++; memcpy(&(netgame->version_minor), data + loc, 1); loc++; memcpy(&(netgame->team_vector), data + loc, 1); loc++; if (lite_flag) return; memcpy(&bitfield, data + loc, 2); loc += 2; bitfield = INTEL_SHORT(bitfield); memcpy(((ubyte *)(&netgame->team_vector) + 1), &bitfield, 2); memcpy(&bitfield, data + loc, 2); loc += 2; bitfield = INTEL_SHORT(bitfield); memcpy(((ubyte *)(&netgame->team_vector) + 3), &bitfield, 2); #if 0 // not used since reordering mac bitfields memcpy(&bitfield, data + loc, 2); loc += 2; new_field = 0; for (i = 15; i >= 0; i--) { if (bitfield & (1 << i)) new_field |= (1 << (15 - i); } new_field = INTEL_SHORT(new_field); memcpy(((ubyte *)(&netgame->team_vector) + 1), &new_field, 2); memcpy(&bitfield, data + loc, 2); loc += 2; new_field = 0; for (i = 15; i >= 0; i--) { if (bitfield & (1 << i)) new_field |= (1 << (15 - i); } new_field = INTEL_SHORT(new_field); memcpy(((ubyte *)(&netgame->team_vector) + 3), &new_field, 2); #endif memcpy(netgame->team_name, data + loc, 2*(CALLSIGN_LEN+1)); loc += 2*(CALLSIGN_LEN+1); for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->locations[i]), data + loc, 4); loc += 4; netgame->locations[i] = INTEL_INT(netgame->locations[i]); } for (i = 0; i < MAX_PLAYERS; i++) { for (j = 0; j < MAX_PLAYERS; j++) { memcpy(&(netgame->kills[i][j]), data + loc, 2); loc += 2; netgame->kills[i][j] = INTEL_SHORT(netgame->kills[i][j]); } } memcpy(&(netgame->segments_checksum), data + loc, 2); loc += 2; netgame->segments_checksum = INTEL_SHORT(netgame->segments_checksum); memcpy(&(netgame->team_kills[0]), data + loc, 2); loc += 2; netgame->team_kills[0] = INTEL_SHORT(netgame->team_kills[0]); memcpy(&(netgame->team_kills[1]), data + loc, 2); loc += 2; netgame->team_kills[1] = INTEL_SHORT(netgame->team_kills[1]); for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->killed[i]), data + loc, 2); loc += 2; netgame->killed[i] = INTEL_SHORT(netgame->killed[i]); } for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->player_kills[i]), data + loc, 2); loc += 2; netgame->player_kills[i] = INTEL_SHORT(netgame->player_kills[i]); } memcpy(&(netgame->KillGoal), data + loc, 4); loc += 4; netgame->KillGoal = INTEL_INT(netgame->KillGoal); memcpy(&(netgame->PlayTimeAllowed), data + loc, 4); loc += 4; netgame->PlayTimeAllowed = INTEL_INT(netgame->PlayTimeAllowed); memcpy(&(netgame->level_time), data + loc, 4); loc += 4; netgame->level_time = INTEL_INT(netgame->level_time); memcpy(&(netgame->control_invul_time), data + loc, 4); loc += 4; netgame->control_invul_time = INTEL_INT(netgame->control_invul_time); memcpy(&(netgame->monitor_vector), data + loc, 4); loc += 4; netgame->monitor_vector = INTEL_INT(netgame->monitor_vector); for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->player_score[i]), data + loc, 4); loc += 4; netgame->player_score[i] = INTEL_INT(netgame->player_score[i]); } for (i = 0; i < MAX_PLAYERS; i++) { memcpy(&(netgame->player_flags[i]), data + loc, 1); loc++; } memcpy(&(netgame->nPacketsPerSec), data + loc, 2); loc += 2; netgame->nPacketsPerSec = INTEL_SHORT(netgame->nPacketsPerSec); memcpy(&(netgame->bShortPackets), data + loc, 1); loc ++; }
// #define GET_BUF() do { buffer = &Pcx_load[Pcx_load_offset]; if(Pcx_load_offset + buffer_size > Pcx_load_size) { buffer_size = Pcx_load_size - Pcx_load_offset; } } while(0); int pcx_read_bitmap_8bpp( char * real_filename, ubyte *org_data, ubyte *palette ) { PCXHeader header; CFILE * PCXfile; int row, col, count, xsize, ysize; ubyte data=0; int buffer_size, buffer_pos; ubyte buffer[1024]; ubyte *pixdata; char filename[MAX_FILENAME_LEN]; strcpy( filename, real_filename ); char *p = strchr( filename, '.' ); if ( p ) *p = 0; strcat( filename, ".pcx" ); PCXfile = cfopen( filename , "rb" ); if ( !PCXfile ) return PCX_ERROR_OPENING; // read 128 char PCX header if (cfread( &header, sizeof(PCXHeader), 1, PCXfile )!=1) { cfclose( PCXfile ); return PCX_ERROR_NO_HEADER; } header.Xmin = INTEL_SHORT( header.Xmin ); header.Ymin = INTEL_SHORT( header.Ymin ); header.Xmax = INTEL_SHORT( header.Xmax ); header.Ymax = INTEL_SHORT( header.Ymax ); header.Hdpi = INTEL_SHORT( header.Hdpi ); header.Vdpi = INTEL_SHORT( header.Vdpi ); header.BytesPerLine = INTEL_SHORT( header.BytesPerLine ); // Is it a 256 color PCX file? if ((header.Manufacturer != 10)||(header.Encoding != 1)||(header.Nplanes != 1)||(header.BitsPerPixel != 8)||(header.Version != 5)) { cfclose( PCXfile ); return PCX_ERROR_WRONG_VERSION; } // Find the size of the image xsize = header.Xmax - header.Xmin + 1; ysize = header.Ymax - header.Ymin + 1; // Read the extended palette at the end of PCX file // Read in a character which should be 12 to be extended palette file cfseek( PCXfile, -768, CF_SEEK_END ); cfread( palette, 3, 256, PCXfile ); for ( int i=0; i<256; i++ ){ //tigital palette[i] = INTEL_INT( palette[i] ); } cfseek( PCXfile, sizeof(PCXHeader), CF_SEEK_SET ); buffer_size = 1024; buffer_pos = 0; // Assert( buffer_size == 1024 ); // AL: removed to avoid optimized warning 'unreachable code' buffer_size = cfread( buffer, 1, buffer_size, PCXfile ); count = 0; for (row=0; row<ysize;row++) { pixdata = org_data; for (col=0; col<header.BytesPerLine;col++) { if ( count == 0 ) { data = buffer[buffer_pos++]; if ( buffer_pos == buffer_size ) { buffer_size = cfread( buffer, 1, buffer_size, PCXfile ); Assert( buffer_size > 0 ); buffer_pos = 0; } if ((data & 0xC0) == 0xC0) { count = data & 0x3F; data = buffer[buffer_pos++]; if ( buffer_pos == buffer_size ) { buffer_size = cfread( buffer, 1, buffer_size, PCXfile ); Assert( buffer_size > 0 ); buffer_pos = 0; } } else { count = 1; } } if ( col < xsize ) *pixdata++ = data; count--; } org_data += xsize; } cfclose(PCXfile); return PCX_ERROR_NONE; }
void BEReceiveMissingObjFrames(ubyte *data, tMissingObjFrames *missingObjFrames) { memcpy (missingObjFrames, nmDataBuf, sizeof (tMissingObjFrames)); missingObjFrames->nFrame = INTEL_SHORT (missingObjFrames->nFrame); }
int CFile::WriteFixAng (fixang a) { a = INTEL_SHORT (a); return Write (&a, sizeof (a), 1); }
void NetworkReadPDataPacket (tFrameInfo *pd) { int nTheirPlayer; int theirObjNum; CObject * theirObjP = NULL; // tFrameInfo should be aligned...for mac, make the necessary adjustments #if defined (WORDS_BIGENDIAN) || defined (__BIG_ENDIAN__) if (gameStates.multi.nGameType >= IPX_GAME) { pd->nPackets = INTEL_INT (pd->nPackets); pd->objPos[X] = INTEL_INT (pd->objPos[X]); pd->objPos[Y] = INTEL_INT (pd->objPos[Y]); pd->objPos[Z] = INTEL_INT (pd->objPos[Z]); pd->objOrient.RVec ()[X] = (fix)INTEL_INT ((int)pd->objOrient.RVec ()[X]); pd->objOrient.RVec ()[Y] = (fix)INTEL_INT ((int)pd->objOrient.RVec ()[Y]); pd->objOrient.RVec ()[Z] = (fix)INTEL_INT ((int)pd->objOrient.RVec ()[Z]); pd->objOrient.UVec ()[X] = (fix)INTEL_INT ((int)pd->objOrient.UVec ()[X]); pd->objOrient.UVec ()[Y] = (fix)INTEL_INT ((int)pd->objOrient.UVec ()[Y]); pd->objOrient.UVec ()[Z] = (fix)INTEL_INT ((int)pd->objOrient.UVec ()[Z]); pd->objOrient.FVec ()[X] = (fix)INTEL_INT ((int)pd->objOrient.FVec ()[X]); pd->objOrient.FVec ()[Y] = (fix)INTEL_INT ((int)pd->objOrient.FVec ()[Y]); pd->objOrient.FVec ()[Z] = (fix)INTEL_INT ((int)pd->objOrient.FVec ()[Z]); pd->physVelocity[X] = (fix)INTEL_INT ((int)pd->physVelocity[X]); pd->physVelocity[Y] = (fix)INTEL_INT ((int)pd->physVelocity[Y]); pd->physVelocity[Z] = (fix)INTEL_INT ((int)pd->physVelocity[Z]); pd->physRotVel[X] = (fix)INTEL_INT ((int)pd->physRotVel[X]); pd->physRotVel[Y] = (fix)INTEL_INT ((int)pd->physRotVel[Y]); pd->physRotVel[Z] = (fix)INTEL_INT ((int)pd->physRotVel[Z]); pd->nObjSeg = INTEL_SHORT (pd->nObjSeg); pd->dataSize = INTEL_SHORT (pd->dataSize); } #endif nTheirPlayer = pd->nPlayer; theirObjNum = gameData.multiplayer.players [pd->nPlayer].nObject; if (nTheirPlayer < 0) { Int3 (); // This packet is bogus!! return; } if ((networkData.sync [0].nPlayer != -1) && (nTheirPlayer == networkData.sync [0].nPlayer)) networkData.sync [0].nPlayer = -1; if (!gameData.multigame.bQuitGame && (nTheirPlayer >= gameData.multiplayer.nPlayers)) { if (networkData.nStatus != NETSTAT_WAITING) { Int3 (); // We missed an important packet! NetworkConsistencyError (); } return; } if (gameStates.app.bEndLevelSequence || (networkData.nStatus == NETSTAT_ENDLEVEL)) { int old_Endlevel_sequence = gameStates.app.bEndLevelSequence; gameStates.app.bEndLevelSequence = 1; if (pd->dataSize > 0) // pass pd->data to some parser function.... MultiProcessBigData (reinterpret_cast<char*> (pd->data), pd->dataSize); gameStates.app.bEndLevelSequence = old_Endlevel_sequence; return; } if ((sbyte)pd->nLevel != gameData.missions.nCurrentLevel) { #if 1 console.printf (CON_DBG, "Got frame packet from CPlayerData %d wrong level %d!\n", pd->nPlayer, pd->nLevel); #endif return; } theirObjP = OBJECTS + theirObjNum; //------------- Keep track of missed packets ----------------- gameData.multiplayer.players [nTheirPlayer].nPacketsGot++; networkData.nTotalPacketsGot++; ResetPlayerTimeout (nTheirPlayer, -1); if (pd->nPackets != gameData.multiplayer.players [nTheirPlayer].nPacketsGot) { networkData.nMissedPackets = pd->nPackets - gameData.multiplayer.players [nTheirPlayer].nPacketsGot; if ((pd->nPackets-gameData.multiplayer.players [nTheirPlayer].nPacketsGot) > 0) networkData.nTotalMissedPackets += pd->nPackets-gameData.multiplayer.players [nTheirPlayer].nPacketsGot; #if 1 if (networkData.nMissedPackets > 0) console.printf (0, "Missed %d packets from CPlayerData #%d (%d total)\n", pd->nPackets-gameData.multiplayer.players [nTheirPlayer].nPacketsGot, nTheirPlayer, networkData.nMissedPackets); else console.printf (CON_DBG, "Got %d late packets from CPlayerData #%d (%d total)\n", gameData.multiplayer.players [nTheirPlayer].nPacketsGot-pd->nPackets, nTheirPlayer, networkData.nMissedPackets); #endif gameData.multiplayer.players [nTheirPlayer].nPacketsGot = pd->nPackets; } //------------ Read the CPlayerData's ship's CObject info ---------------------- theirObjP->info.position.vPos = pd->objPos; theirObjP->info.position.mOrient = pd->objOrient; theirObjP->mType.physInfo.velocity = pd->physVelocity; theirObjP->mType.physInfo.rotVel = pd->physRotVel; if ((theirObjP->info.renderType != pd->objRenderType) && (pd->objRenderType == RT_POLYOBJ)) MultiMakeGhostPlayer (nTheirPlayer); OBJECTS [theirObjNum].RelinkToSeg (pd->nObjSeg); if (theirObjP->info.movementType == MT_PHYSICS) theirObjP->SetThrustFromVelocity (); //------------ Welcome them back if reconnecting -------------- if (!gameData.multiplayer.players [nTheirPlayer].connected) { gameData.multiplayer.players [nTheirPlayer].connected = 1; if (gameData.demo.nState == ND_STATE_RECORDING) NDRecordMultiReconnect (nTheirPlayer); MultiMakeGhostPlayer (nTheirPlayer); OBJECTS [theirObjNum].CreateAppearanceEffect (); audio.PlaySound (SOUND_HUD_MESSAGE); ClipRank (reinterpret_cast<char*> (&netPlayers.players [nTheirPlayer].rank)); if (gameOpts->multi.bNoRankings) HUDInitMessage ("'%s' %s", gameData.multiplayer.players [nTheirPlayer].callsign, TXT_REJOIN); else HUDInitMessage ("%s'%s' %s", pszRankStrings [netPlayers.players [nTheirPlayer].rank], gameData.multiplayer.players [nTheirPlayer].callsign, TXT_REJOIN); MultiSendScore (); } //------------ Parse the extra dataP at the end --------------- if (pd->dataSize > 0) // pass pd->data to some parser function.... MultiProcessBigData (reinterpret_cast<char*> (pd->data), pd->dataSize); }
void BESwapObject (tObject *objP) { // swap the short and int entries for this tObject objP->info.nSignature = INTEL_INT (objP->info.nSignature); objP->info.nNextInSeg = INTEL_SHORT (objP->info.nNextInSeg); objP->info.nPrevInSeg = INTEL_SHORT (objP->info.nPrevInSeg); objP->info.nSegment = INTEL_SHORT (objP->info.nSegment); INTEL_VECTOR (objP->info.position.vPos); INTEL_MATRIX (objP->info.position.mOrient); objP->info.xSize = INTEL_INT (objP->info.xSize); objP->info.xShields = INTEL_INT (objP->info.xShields); INTEL_VECTOR (objP->info.vLastPos); objP->info.xLifeLeft = INTEL_INT (objP->info.xLifeLeft); switch (objP->info.movementType) { case MT_PHYSICS: INTEL_VECTOR (objP->mType.physInfo.velocity); INTEL_VECTOR (objP->mType.physInfo.thrust); objP->mType.physInfo.mass = INTEL_INT (objP->mType.physInfo.mass); objP->mType.physInfo.drag = INTEL_INT (objP->mType.physInfo.drag); objP->mType.physInfo.brakes = INTEL_INT (objP->mType.physInfo.brakes); INTEL_VECTOR (objP->mType.physInfo.rotVel); INTEL_VECTOR (objP->mType.physInfo.rotThrust); objP->mType.physInfo.turnRoll = INTEL_INT (objP->mType.physInfo.turnRoll); objP->mType.physInfo.flags = INTEL_SHORT (objP->mType.physInfo.flags); break; case MT_SPINNING: INTEL_VECTOR (objP->mType.spinRate); break; } switch (objP->info.controlType) { case CT_WEAPON: objP->cType.laserInfo.parent.nType = INTEL_SHORT (objP->cType.laserInfo.parent.nType); objP->cType.laserInfo.parent.nObject = INTEL_SHORT (objP->cType.laserInfo.parent.nObject); objP->cType.laserInfo.parent.nSignature = INTEL_INT (objP->cType.laserInfo.parent.nSignature); objP->cType.laserInfo.xCreationTime = INTEL_INT (objP->cType.laserInfo.xCreationTime); objP->cType.laserInfo.nLastHitObj = INTEL_SHORT (objP->cType.laserInfo.nLastHitObj); if (objP->cType.laserInfo.nLastHitObj < 0) objP->cType.laserInfo.nLastHitObj = 0; else { gameData.objs.nHitObjects [OBJ_IDX (objP) * MAX_HIT_OBJECTS] = objP->cType.laserInfo.nLastHitObj; objP->cType.laserInfo.nLastHitObj = 1; } objP->cType.laserInfo.nHomingTarget = INTEL_SHORT (objP->cType.laserInfo.nHomingTarget); objP->cType.laserInfo.xScale = INTEL_INT (objP->cType.laserInfo.xScale); break; case CT_EXPLOSION: objP->cType.explInfo.nSpawnTime = INTEL_INT (objP->cType.explInfo.nSpawnTime); objP->cType.explInfo.nDeleteTime = INTEL_INT (objP->cType.explInfo.nDeleteTime); objP->cType.explInfo.nDeleteObj = INTEL_SHORT (objP->cType.explInfo.nDeleteObj); objP->cType.explInfo.attached.nParent = INTEL_SHORT (objP->cType.explInfo.attached.nParent); objP->cType.explInfo.attached.nPrev = INTEL_SHORT (objP->cType.explInfo.attached.nPrev); objP->cType.explInfo.attached.nNext = INTEL_SHORT (objP->cType.explInfo.attached.nNext); break; case CT_AI: objP->cType.aiInfo.nHideSegment = INTEL_SHORT (objP->cType.aiInfo.nHideSegment); objP->cType.aiInfo.nHideIndex = INTEL_SHORT (objP->cType.aiInfo.nHideIndex); objP->cType.aiInfo.nPathLength = INTEL_SHORT (objP->cType.aiInfo.nPathLength); objP->cType.aiInfo.nDangerLaser = INTEL_SHORT (objP->cType.aiInfo.nDangerLaser); objP->cType.aiInfo.nDangerLaserSig = INTEL_INT (objP->cType.aiInfo.nDangerLaserSig); objP->cType.aiInfo.xDyingStartTime = INTEL_INT (objP->cType.aiInfo.xDyingStartTime); break; case CT_LIGHT: objP->cType.lightInfo.intensity = INTEL_INT (objP->cType.lightInfo.intensity); break; case CT_POWERUP: objP->cType.powerupInfo.nCount = INTEL_INT (objP->cType.powerupInfo.nCount); objP->cType.powerupInfo.xCreationTime = INTEL_INT (objP->cType.powerupInfo.xCreationTime); break; } switch (objP->info.renderType) { case RT_MORPH: case RT_POLYOBJ: { int i; objP->rType.polyObjInfo.nModel = INTEL_INT (objP->rType.polyObjInfo.nModel); for (i = 0; i < MAX_SUBMODELS; i++) INTEL_ANGVEC (objP->rType.polyObjInfo.animAngles [i]); objP->rType.polyObjInfo.nSubObjFlags = INTEL_INT (objP->rType.polyObjInfo.nSubObjFlags); objP->rType.polyObjInfo.nTexOverride = INTEL_INT (objP->rType.polyObjInfo.nTexOverride); objP->rType.polyObjInfo.nAltTextures = INTEL_INT (objP->rType.polyObjInfo.nAltTextures); break; } case RT_WEAPON_VCLIP: case RT_HOSTAGE: case RT_POWERUP: case RT_FIREBALL: case RT_THRUSTER: objP->rType.vClipInfo.nClipIndex = INTEL_INT (objP->rType.vClipInfo.nClipIndex); objP->rType.vClipInfo.xFrameTime = INTEL_INT (objP->rType.vClipInfo.xFrameTime); break; case RT_LASER: break; } }
int pcx_read_bitmap_16bpp_nondark( char * real_filename, ubyte *org_data ) { PCXHeader header; CFILE * PCXfile; int row, col, count, xsize, ysize; ubyte data=0; int buffer_size, buffer_pos; ubyte buffer[1024]; ubyte *pixdata; char filename[MAX_FILENAME_LEN]; ubyte palette[768]; ushort bit_16; ubyte r, g, b, al; strcpy( filename, real_filename ); char *p = strchr( filename, '.' ); if ( p ) *p = 0; strcat( filename, ".pcx" ); PCXfile = cfopen( filename , "rb" ); if ( !PCXfile ){ return PCX_ERROR_OPENING; } // read 128 char PCX header if (cfread( &header, sizeof(PCXHeader), 1, PCXfile )!=1) { cfclose( PCXfile ); return PCX_ERROR_NO_HEADER; } header.Xmin = INTEL_SHORT( header.Xmin ); header.Ymin = INTEL_SHORT( header.Ymin ); header.Xmax = INTEL_SHORT( header.Xmax ); header.Ymax = INTEL_SHORT( header.Ymax ); header.Hdpi = INTEL_SHORT( header.Hdpi ); header.Vdpi = INTEL_SHORT( header.Vdpi ); header.BytesPerLine = INTEL_SHORT( header.BytesPerLine ); // Is it a 256 color PCX file? if ((header.Manufacturer != 10)||(header.Encoding != 1)||(header.Nplanes != 1)||(header.BitsPerPixel != 8)||(header.Version != 5)) { cfclose( PCXfile ); return PCX_ERROR_WRONG_VERSION; } // Find the size of the image xsize = header.Xmax - header.Xmin + 1; ysize = header.Ymax - header.Ymin + 1; // Read the extended palette at the end of PCX file // Read in a character which should be 12 to be extended palette file cfseek( PCXfile, -768, CF_SEEK_END ); cfread( palette, 3, 256, PCXfile ); cfseek( PCXfile, sizeof(PCXHeader), CF_SEEK_SET ); buffer_size = 1024; buffer_pos = 0; // Assert( buffer_size == 1024 ); // AL: removed to avoid optimized warning 'unreachable code' buffer_size = cfread( buffer, 1, buffer_size, PCXfile ); count = 0; for (row=0; row<ysize;row++) { pixdata = org_data; for (col=0; col<header.BytesPerLine;col++) { if ( count == 0 ) { data = buffer[buffer_pos++]; if ( buffer_pos == buffer_size ) { buffer_size = cfread( buffer, 1, buffer_size, PCXfile ); Assert( buffer_size > 0 ); buffer_pos = 0; } if ((data & 0xC0) == 0xC0) { count = data & 0x3F; data = buffer[buffer_pos++]; if ( buffer_pos == buffer_size ) { buffer_size = cfread( buffer, 1, buffer_size, PCXfile ); Assert( buffer_size > 0 ); buffer_pos = 0; } } else { count = 1; } } // stuff the pixel if ( col < xsize ){ // stuff the 24 bit value r = palette[data*3]; g = palette[data*3 + 1]; b = palette[data*3 + 2]; // if this is a nondarkening texture // if this color matches a nondarkening pixel color, set the alpha to high al = 0; if(palman_is_nondarkening(r, g, b)){ al = 255; } // set the pixel bit_16 = 0; bm_set_components((ubyte*)&bit_16, &r, &g, &b, &al); // stuff the pixel *((ushort*)pixdata) = bit_16; pixdata += 2; } count--; } org_data += (xsize * 2); } cfclose(PCXfile); return PCX_ERROR_NONE; }
int CFile::WriteShort (short s) { s = INTEL_SHORT (s); return Write(&s, sizeof (s), 1); }