/** * CmdQUpdateAllSends updates the sending of all packets. * Packets that need to be transferred are sent. Those that don't, don't. * The amount of packets sent depends on the baud rate and the last time * this routine was called. * *<!-----------------------------------------------------------------------*/ T_void CmdQUpdateAllSends(T_void) { T_byte8 currentCmd; T_cmdQPacketStruct *p_packet = NULL; T_cmdQPacketStruct *p_next = NULL; T_byte8 packetLength; T_word32 time; T_sword16 status; T_word16 bytesused; T_word32 maxOutput; E_Boolean onceFlag = FALSE; E_Boolean sentAny; DebugRoutine("CmdQUpdateAllSends") ; /* Get the current time. */ time = TickerGet(); bytesused = 0; maxOutput = 100; currentCmd = 0; if (bytesused < maxOutput) { do { sentAny = FALSE; p_next = 0; p_packet = G_activeCmdQList[currentCmd].first; do { /* Try sending the command at currentCmd. */ /* See if there is anything that needs to be sent. */ if ((p_packet != NULL) && (bytesused < maxOutput)) { DebugCheck(currentCmd < PACKET_COMMAND_UNKNOWN); p_next = p_packet->next; #ifndef NDEBUG if (strcmp(p_packet->tag, "CmQ") != 0) { printf("Bad packet %p\n", p_packet); DebugCheck(FALSE); } #endif /* See if it is time to send it. */ /** (It's always time to send an ACK.) **/ if ((currentCmd == PACKET_COMMAND_ACK) || (p_packet->timeToRetry < time)) { /* Yes, it is time to send it. */ packetLength = p_packet->packet.header.packetLength; /* Add the count to the output. */ bytesused += packetLength + sizeof(T_packetHeader); /* Make sure this didn't go over the threshold. */ if (bytesused >= maxOutput) break; /* Let's send that packet to the given destination. */ DirectTalkSetDestination(&p_packet->destination); status = PacketSend( (T_packetEitherShortOrLong *)(&p_packet->packet)); sentAny = TRUE; #ifdef COMPILE_OPTION_CREATE_PACKET_DATA_FILE fprintf(G_packetFile, "S(%d) cmd=%2d, id=%ld, time=%ld\n", CmdQGetActivePortNum (), p_packet->packet.data[0], p_packet->packet.header.id, SyncTimeGet()); fflush(G_packetFile); #endif /* Was the packet actually sent? */ if (status == 0) { /* Packet was sent correctly (as far as we know). */ /* Is this a lossy or lossless command queue? */ if ((G_CmdQTypeCommand[currentCmd] == PACKET_COMMAND_TYPE_LOSSY) || (DirectTalkIsBroadcastAddress( &p_packet->destination))) { /* Lossy. Means we can go ahead and */ /* discard this packet. */ ICmdQDiscardPacket(currentCmd, p_packet); } else { /* Lossless. Means we must wait for an ACK */ /* packet to confirm that we were sent. */ /* Until then, we can't discard the packet. */ /* But we might have to resend latter. */ /* Set up the retry time. */ p_packet->timeToRetry = time + p_packet->retryTime; } } else { /* Packet was NOT sent correctly. */ /** -- IFF the packet is lossless... **/ /* We'll have to retry later. Change the time, */ /* but don't remove it from the linked list. */ if (G_CmdQTypeCommand[currentCmd] == PACKET_COMMAND_TYPE_LOSSLESS) { p_packet->timeToRetry = time + p_packet->retryTime; } else { /* Waste it! We can't wait around */ ICmdQDiscardPacket(currentCmd, p_packet); } } } else { /* Don't loop if it is not time to send. */ break; } /** Now, if we aren't checking the ACK queue, we need **/ /** to break after the first send. If we are, we **/ /** want to dump everything in the queue. **/ if (currentCmd != PACKET_COMMAND_ACK) break; } // Move to the next packet (if any) p_packet = p_next; while (!p_packet) { /* Update to the next command. */ currentCmd++; if (currentCmd < PACKET_COMMAND_MAX) { // Get the beginning of the list p_packet = G_activeCmdQList[currentCmd].first; if (p_packet) p_next = p_packet->next; else p_next = 0; } else { break; } } } while (currentCmd < PACKET_COMMAND_MAX); // Loop back to the start looking for more to send currentCmd = 0; } while ((bytesused < maxOutput) && (sentAny == TRUE)); } DebugEnd() ; }
T_efxID EfxCreate (E_efxType type, // type of effect T_word32 Xorigin, // x,y,z location of effect T_word32 Yorigin, T_word32 Zorigin, T_word16 numberOf, // number of objects to create E_Boolean transparent, // should objects be transparent? T_word32 extraData) // extra data for some efx { T_doubleLinkListElement myElement=NULL; T_efxStruct *p_efx; DebugRoutine ("EfxCreate"); DebugCheck (type < EFX_UNKNOWN); if (type < EFX_UNKNOWN) { /* create a new efx structure */ p_efx=(T_efxStruct *)MemAlloc(sizeof(T_efxStruct)); DebugCheck (p_efx != NULL); if (p_efx != NULL) { /* initialize a double linked list to hold all newly created */ /* object pointers */ p_efx->objectList=DOUBLE_LINK_LIST_BAD; p_efx->objectList=DoubleLinkListCreate(); DebugCheck (p_efx->objectList != DOUBLE_LINK_LIST_BAD); if (p_efx->objectList != DOUBLE_LINK_LIST_BAD) { /* init extra data */ p_efx->reserved=TickerGet(); p_efx->updateCallback=NULL; p_efx->Xorigin=Xorigin; p_efx->Yorigin=Yorigin; p_efx->Zorigin=Zorigin; p_efx->numberOf=numberOf; p_efx->duration=0; /* add this efx to global list */ p_efx->myID=DoubleLinkListAddElementAtEnd(G_effectsInProgress,p_efx); /* call the effect set up routine */ switch (type) { case EFX_BLOOD_SHRAPNEL: EfxCreateBloodSplat (p_efx->myID,transparent); break; case EFX_WALL_HIT: EfxCreateGenericShrapnel (OBJECT_TYPE_WALL_HIT, p_efx->myID, FALSE, TRUE); break; case EFX_TELEPORT: p_efx->duration=100; EfxCreateGenericExplosion (OBJECT_TYPE_TELEPORT, p_efx->myID, TRUE, 0); AreaSoundCreate( p_efx->Xorigin>>16, p_efx->Yorigin>>16, 500, 255, AREA_SOUND_TYPE_ONCE, 0, AREA_SOUND_BAD, NULL, 0, SOUND_TELEPORT) ; break; case EFX_POWER_EXPLOSION: EfxCreateGenericExplosion (OBJECT_TYPE_POWER_EXPLOSION, p_efx->myID, FALSE, 0); break; case EFX_POISON_EXPLOSION: EfxCreateGenericExplosion (OBJECT_TYPE_POISON_EXPLOSION, p_efx->myID, FALSE, 0); break; case EFX_ACID_EXPLOSION: EfxCreateGenericExplosion (OBJECT_TYPE_ACID_EXPLOSION, p_efx->myID, FALSE, 0); break; case EFX_ELECTRIC_EXPLOSION: EfxCreateGenericExplosion (OBJECT_TYPE_ELECTRIC_EXPLOSION, p_efx->myID, FALSE, -20); break; case EFX_MAGIC_EXPLOSION: EfxCreateGenericExplosion (OBJECT_TYPE_MAGIC_EXPLOSION, p_efx->myID, FALSE, -20); break; case EFX_FIRE_EXPLOSION: EfxCreateGenericExplosion (OBJECT_TYPE_FIRE_EXPLOSION, p_efx->myID, FALSE, -25); EfxCreate (EFX_FLAME_SHRAPNEL, p_efx->Xorigin, p_efx->Yorigin, p_efx->Zorigin, 3, FALSE, 0); break; case EFX_FIRE_SHRAPNEL: p_efx->duration=150; EfxCreateGenericShrapnel(OBJECT_TYPE_FIRE_SHRAPNEL, p_efx->myID, TRUE, FALSE); break; case EFX_FLAME_SHRAPNEL: p_efx->duration=80; EfxCreateGenericShrapnel(OBJECT_TYPE_FLAME_SHRAPNEL, p_efx->myID, TRUE, FALSE); break; case EFX_BONE_SHRAPNEL: p_efx->duration=80; EfxCreateGenericShrapnel(OBJECT_TYPE_BONE_SHRAPNEL, p_efx->myID, TRUE, FALSE); break; case EFX_ACID_SHRAPNEL: EfxCreateGenericShrapnel(OBJECT_TYPE_ACID_SHRAPNEL, p_efx->myID, FALSE, TRUE); break; case EFX_POISON_SHRAPNEL: EfxCreateGenericShrapnel(OBJECT_TYPE_POISON_SHRAPNEL, p_efx->myID, FALSE, TRUE); break; case EFX_ELECTRIC_SHRAPNEL: p_efx->duration=60; EfxCreateGenericShrapnel(OBJECT_TYPE_ELECTRIC_SHRAPNEL, p_efx->myID, TRUE, FALSE); break; case EFX_MAGIC_SHRAPNEL: p_efx->duration=60; EfxCreateGenericShrapnel(OBJECT_TYPE_MANA_SHRAPNEL, p_efx->myID, TRUE, FALSE); break; default: break; } }
T_void FormGenericControl(E_Boolean *exitflag) { static T_word32 delta = 0, lastupdate = 0; T_keyboardEventHandler keyhandl; T_mouseEventHandler mousehandl; T_bitmap *p_bitmap; T_resource r_bitmap; T_bitmap *p_oldBitmap; T_word16 hotX, hotY; DebugRoutine("FormGenericControl"); lastupdate = TickerGet(); *exitflag = FALSE; /** Initialize the mouse. **/ MouseGetBitmap(&hotX, &hotY, &p_oldBitmap); p_bitmap = (T_bitmap *)PictureLock("UI/MOUSE/DEFAULT", &r_bitmap); DebugCheck(p_bitmap != NULL); MouseSetDefaultBitmap(0, 0, p_bitmap); MouseUseDefaultBitmap(); /* show the mouse and set the keyboard/mouse event handlers */ keyhandl = KeyboardGetEventHandler(); mousehandl = MouseGetEventHandler(); /* flush the keyboard */ KeyboardDebounce(); MouseSetEventHandler(FormHandleMouse); KeyboardSetEventHandler(FormHandleKey); // MouseShow(); do { delta = TickerGet(); /* update color every 4 ticks */ if ((delta - lastupdate) > 0) { lastupdate = delta; ColorUpdate(delta - lastupdate); } /* update events */ GraphicUpdateAllGraphics(); // MouseHide(); MouseUpdateEvents(); KeyboardUpdateEvents(); SoundUpdate(); // MouseShow(); // delay (20); } while (*exitflag == FALSE && KeyboardGetScanCode(KEY_SCAN_CODE_ESC) == FALSE); /* clean up */ // MouseHide(); FormCleanUp(); MouseSetEventHandler(mousehandl); KeyboardSetEventHandler(keyhandl); KeyboardDebounce(); /** free up the mouse pointer resource. **/ ResourceUnlock(r_bitmap); ResourceUnfind(r_bitmap); /* Turn off the mouse */ MouseSetDefaultBitmap(hotX, hotY, p_oldBitmap); MouseUseDefaultBitmap(); DebugEnd(); }