// //////////////////////////////////////////////////////////////////////////// // INFORM others that a building has been started, and base plate should be put down. BOOL sendBuildStarted(STRUCTURE *psStruct,DROID *psDroid) { NETMSG msg; UDWORD zero=0; NetAdd(msg,0,((UBYTE)psDroid->player)); //player NetAdd(msg,1,psDroid->psTarStats->ref); //id of thing to build NetAdd(msg,5,psDroid->orderX); // x NetAdd(msg,7,psDroid->orderY); // y NetAdd(msg,11,psDroid->id); // droid to order to build it NetAdd(msg,15,psStruct->id); // building id to create NetAdd(msg,19,((UBYTE)psDroid->order)); // building id to create if(psDroid->psTarget && (psDroid->psTarget->type == OBJ_STRUCTURE)) { NetAdd(msg,20,((STRUCTURE*)psDroid->psTarget)->id); } else { NetAdd(msg,20,zero); } NetAdd(msg,24,psStruct->z); msg.size =28; msg.type = NET_BUILD; return (NETbcast(&msg,FALSE)); }
BOOL NETend(void) { assert(NETgetPacketDir() != PACKET_INVALID); // If we are decoding just return true if (NETgetPacketDir() == PACKET_DECODE) { return true; } // If the packet is invalid or failed to compile if (NETgetPacketDir() != PACKET_ENCODE || !NetMsg.status) { return false; } // We have sent the packet, so make it invalid (to prevent re-sending) NETsetPacketDir(PACKET_INVALID); // Send the packet, updating the send functions is on my todo list! if (NetMsg.destination == NET_ALL_PLAYERS) { return NETbcast(&NetMsg); } else { return NETsend(&NetMsg, NetMsg.destination); } }
static VOID sendAudioComplete(VOID) { NETMSG msg; msg.type = AUDIOMSG; msg.size = 1; NETbcast(&msg,FALSE); }
// //////////////////////////////////////////////////////////////////////////// // Inform others that a structure has been destroyed BOOL SendDestroyStructure(STRUCTURE *s) { NETMSG m; technologyGiveAway(s); NetAdd(m,0,s->id); // struct to destroy m.size =sizeof(UDWORD); m.type=NET_STRUCTDEST; return( NETbcast(&m,FALSE)); }
// //////////////////////////////////////////////////////////////////////////// // demolish message. BOOL SendDemolishFinished( STRUCTURE *psStruct,DROID *psDroid) { NETMSG m; NetAdd(m,0,psStruct->id); NetAdd(m,4,psDroid->id); m.size = 2*sizeof(UDWORD); m.type = NET_DEMOLISH; return( NETbcast(&m,FALSE)); }
BOOL sendLasSat(UBYTE player,STRUCTURE *psStruct, BASE_OBJECT *psObj) { NETMSG msg; NetAdd(msg,0,player); NetAdd(msg,1,psStruct->id); NetAdd(msg,5,psObj->id); NetAdd(msg,9,((UBYTE)psObj->player)); msg.size = 10; msg.type = NET_LASSAT; return (NETbcast(&msg,FALSE) ); }
// //////////////////////////////////////////////////////////////////////////// // INFORM others that a building has been completed. BOOL SendBuildFinished(STRUCTURE *psStruct) { NETMSG m; NetAdd(m,0,psStruct->id); //id of finished struct // also enough info to build it if we don't already know about it. NetAdd(m,4,psStruct->pStructureType->ref); // kind of building. NetAdd(m,8,psStruct->x); // x pos NetAdd(m,10,psStruct->y); // y pos NetAdd(m,12,psStruct->z); // y pos m.body[14] =(char) psStruct->player; // player m.size =15; m.type =NET_BUILDFINISHED; return (NETbcast(&m,FALSE)); }
// //////////////////////////////////////////////////////////////////////// static BOOL sendAudioBuffer(BOOL bNow) { DWORD read; static DWORD lastread=0; HRESULT hr; NETMSG msg; UWORD size=0; LPVOID lpvPtr1,lpvPtr2; DWORD dwBytes1=0,dwBytes2=0; hr = IDirectSoundCaptureBuffer_GetCurrentPosition(lpDirectSoundCaptureBuffer,NULL,&read); if(hr != DS_OK) { return FALSE; } // if buffer is still pretty empty if(lastread <= read) // non wrapped. { size = (UWORD) (read - lastread); } else // wrapped { size = (UWORD) (read + (captureBuff.dwBufferBytes - lastread)); } if(!bNow) { if(size < ((MaxMsgSize*3)/4) ) { return TRUE; } } // send an audio packet if getting near the end of the buffer. if(size > MaxMsgSize) { size = MaxMsgSize; DBPRINTF(("NETPLAY:lost some audio\n")); } // lock an area hr = IDirectSoundCaptureBuffer_Lock(lpDirectSoundCaptureBuffer, //Obtain mem add. of write block. lastread, // start at size, // read this much &lpvPtr1,&dwBytes1, &lpvPtr2,&dwBytes2, 0 //DSCBLOCK_ENTIREBUFFER ); lastread = lastread+size; if(lastread >captureBuff.dwBufferBytes) // wrapped { lastread = lastread - captureBuff.dwBufferBytes; } if(hr != DS_OK) { return FALSE; } // read it out memcpy(msg.body,lpvPtr1,dwBytes1); // copy first part into buffer if (lpvPtr2 != NULL) // second part. { memcpy(((UBYTE *)msg.body)+dwBytes1,lpvPtr2,dwBytes2); // buffer contents } // unlock area. hr = IDirectSoundCaptureBuffer_Unlock(lpDirectSoundCaptureBuffer, lpvPtr1,dwBytes1, lpvPtr2,dwBytes2); if(hr != DS_OK) { return FALSE; } // may want to compress it! //MMRESULT acmFormatSuggest( HACMDRIVER had, LPWAVEFORMATEX pwfxSrc, LPWAVEFORMATEX pwfxDst, DWORD cbwfxDst, DWORD fdwSuggest // send the buffer elsewhere msg.type = AUDIOMSG; msg.size = (UWORD)(dwBytes1+dwBytes2); NETbcast(&msg,FALSE); return TRUE; }