void Font_DrawCharOnBitmap(fontData_t *fontData, int which, FT_Bitmap *font_bitmap, int charnum, int flags, int topleft_x, int topleft_y, int x, int y, int height, bitmap_t *bitmap) { int i, j, numCharsLoaded, c; fontGlyphData_t **chars; chars = fontData->chars[which]; numCharsLoaded = fontData->numCharsLoaded; if (numCharsLoaded >= MAX_CHARS) { Console_DPrintf("Too many characters loaded, not loading char #%i\n", charnum); return; } if (!fontData->charMap[charnum]) { Console_DPrintf("Putting char %c (%i) in slot %i\n", charnum, charnum, numCharsLoaded+1); fontData->charMap[charnum] = numCharsLoaded+1; //0 is reserved fontData->numCharsLoaded++; } c = fontData->charMap[charnum]; if (font_bitmap->width) { chars[c] = (fontGlyphData_t*)Tag_Malloc(sizeof(fontGlyphData_t), MEM_FONT); chars[c]->topLeft[0] = topleft_x; chars[c]->topLeft[1] = topleft_y; chars[c]->dimensions[0] = font_bitmap->width; chars[c]->dimensions[1] = height; Console_DPrintf("font %i: new char at (%i, %i), width %i, height %i\n", which, x, y, font_bitmap->width, font_bitmap->rows); int *data = (int*)bitmap->data[0]; int mask = LittleInt(0xFF000000); //shadow pass for (i = 0; i < font_bitmap->rows; i++) for (j = 0; j < font_bitmap->width; j++) #if BYTE_ORDER == LITTLE_ENDIAN data[(bitmap->width * (y + i+1) + x + j+1)] = LittleInt(mask & (font_bitmap->buffer[font_bitmap->width * i + j]<<24)); #else data[(bitmap->width * (y + i+1) + x + j+1)] = LittleInt(mask & (font_bitmap->buffer[font_bitmap->width * i + j])); #endif //light pass for(i = 0; i < font_bitmap->rows; i++) for(j = 0; j < font_bitmap->width; j++) { int a = data[(bitmap->width * (y + i) + x + j)]>>24 & 0xff; float sa = font_bitmap->buffer[font_bitmap->width * i + j] / 255.0; int c = 255 * sa; int da = MAX(font_bitmap->buffer[font_bitmap->width * i + j], a); data[(bitmap->width * (y + i) + x + j)] = LittleInt(((da << 24) & 0xff000000) | (c<<16) | (c<<8) | c); //bitmap->data[(bitmap->width * (y + i) + x + j)*bitmap->bmptype + bitmap->bmptype-1] = font_bitmap->buffer[font_bitmap->width * i + j]; } }
bool WSock_PreProcessPacket(netconnection_t *nc) { byte flags; unsigned int seq; //extract sequence number and flags from the packet header Mem_Copy(&seq, nc->recv.__buf, sizeof(unsigned int)); seq = LittleInt(seq); flags = nc->recv.__buf[HEADER_FLAG_LOC]; if (flags & PACKET_RELIABLE) { if (WSock_ProcessReliablePacket(nc, nc->recv.__buf, &nc->recvAddr)) return true; else return false; } //okay, it's not a reliable packet, so the sequence should match the generic nonreliable sequence number // if not, it's probably a fragmented packet and we should throw it out if (seq != NONRELIABLE_SEQUENCE) { NET_PRINTF("Got invalid packet data - sequence %u\n", seq); return false; } if (flags & PACKET_ACK) { WSock_ProcessPacketAck(nc); return false; } return true; }
/* ================ idDict::WriteToFileHandle ================ */ void idDict::WriteToFileHandle( idFile *f ) const { int c = LittleInt( args.Num() ); f->Write( &c, sizeof( c ) ); for ( int i = 0; i < args.Num(); i++ ) // don't loop on the swapped count use the original { WriteString( args[i].GetKey().c_str(), f ); WriteString( args[i].GetValue().c_str(), f ); } }
bool WSock_ProcessReliablePacket(netconnection_t *nc, unsigned char *buf, struct sockaddr_in *from) { packet_t ackpacket; //static char ackbuf[HEADER_SIZE + sizeof(unsigned int)]; unsigned int buf_seq; bool process = true; Mem_Copy(&buf_seq, buf, sizeof(unsigned int)); buf_seq = LittleInt(buf_seq); NET_PRINTF("got reliable packet with sequence %u, waiting for %u\n", buf_seq, nc->reliableRecv_lastseq+1); if (buf_seq > nc->reliableRecv_lastseq+1) { //drop it, out of order - wait for the next packet before jumping ahead, to maintain transfer order // don't even ACK it, so they think we never got it and resend it after resending the earlier one(s) we missed NET_PRINTF("Received out of order sequence %u, waiting for %u\n", buf_seq, nc->reliableRecv_lastseq+1); return false; } else if (buf_seq == nc->reliableRecv_lastseq+1) { //this is a new reliable packet that we've waiting for. Increment the incoming sequence, and use the packet nc->reliableRecv_lastseq++; NET_PRINTF("reliable packet with sequence %u is valid, incrementing our lastseq to %u\n", buf_seq, nc->reliableRecv_lastseq); } else //buf_seq < nc->reliableRecv_lastseq+1 { //this is a resend for a packet we've gotten already. ACK it, but don't process it again NET_PRINTF("Received resend of reliable packet sequence %u, not using it\n", buf_seq); process = false; } //send an ACK for this reliable packet //HACK: write the client ID if we're a client memset(&ackpacket, 0, sizeof(packet_t)); if (nc == &ncLocalClient) { Pkt_WriteShort(&ackpacket, (short)client_id); Pkt_WriteInt(&ackpacket, buf_seq); } else { Pkt_WriteInt(&ackpacket, buf_seq); } //hack to stress-test the reliable packet code if (!net_forcedPacketDrop.value || M_Randnum(0,1) <= 0.5) { NET_PRINTF("Sending ack for reliable packet sequence %u\n", buf_seq); _WSock_SendPacket(nc->sock, (struct sockaddr *)(&nc->sendAddr), ackpacket.__buf, ackpacket.length + HEADER_SIZE, NONRELIABLE_SEQUENCE, PACKET_NORMAL | PACKET_ACK); } return process; }
/* ================ idDict::ReadFromFileHandle ================ */ void idDict::ReadFromFileHandle( idFile *f ) { int c; idStr key, val; Clear(); f->Read( &c, sizeof( c ) ); c = LittleInt( c ); for ( int i = 0; i < c; i++ ) { key = ReadString( f ); val = ReadString( f ); Set( key, val ); } }
void WSock_AddHeader(unsigned char fullPacket[], byte flags, unsigned int seq) { union { unsigned int i; byte b[4]; } u; u.i = LittleInt(seq); fullPacket[0] = u.b[0]; fullPacket[1] = u.b[1]; fullPacket[2] = u.b[2]; fullPacket[3] = u.b[3]; fullPacket[4] = flags; }
/* ================= idFile::WriteUnsignedInt ================= */ int idFile::WriteUnsignedInt( const unsigned int value ) { unsigned int v = LittleInt(value); return Write( &v, sizeof( v ) ); }
/* ================= idFile::WriteInt ================= */ int idFile::WriteInt( const int value ) { int v = LittleInt(value); return Write( &v, sizeof( v ) ); }
/* ================= idFile::ReadUnsignedInt ================= */ int idFile::ReadUnsignedInt( unsigned int &value ) { int result = Read( &value, sizeof( value ) ); value = LittleInt(value); return result; }
/* ================ usercmd_t::ByteSwap ================ */ void usercmd_t::ByteSwap( void ) { angles[0] = LittleShort( angles[0] ); angles[1] = LittleShort( angles[1] ); angles[2] = LittleShort( angles[2] ); sequence = LittleInt( sequence ); }