int main() { int m = 0, n = 0; RingNodePtr pHead = NULL; printf("---------------Josephus Ring---------------\n"); printf("N(person count) = "); scanf("%d", &n); printf("M(out number) = "); scanf("%d", &m); if(n <= 0 || m <= 0) { printf("Input Error\n"); system("pause"); return 0; } // 建立链表 pHead = (RingNodePtr)malloc(sizeof(RingNode)); pHead->pos = 1; pHead->next = NULL; CreateRing(pHead, n); #ifdef _DEBUG PrintRing(pHead); #endif // 开始出圈 printf("\nKick Order: "); KickFromRing(pHead, m); printf("\n"); return 0; }
// runs her teleport-away and reappear states. static void run_teleport(Object *o) { switch (o->state) { // teleport away, then reappear someplace else case STATE_TP_AWAY: { o->state++; o->timer = 0; o->invisible = true; o->flags &= ~FLAG_SHOOTABLE; CreateObject(o->x, o->y, OBJ_MISERY_PHASE)->dir = LEFT; CreateObject(o->x, o->y, OBJ_MISERY_PHASE)->dir = RIGHT; NXE::Sound::SoundManager::getInstance()->playSfx(NXE::Sound::SFX::SND_TELEPORT); } case STATE_TP_AWAY + 1: { o->timer++; // it takes exactly 8 frames for the phase-in animation to complete if (o->timer == 42) { // we don't actually move until the last possible second // in order not to bring the floattext/damage numbers with us, // which gives away our position. o->xmark = (random(9, 31) * TILE_W) * CSFI; o->ymark = (random(5, 7) * TILE_H) * CSFI; CreateObject(o->xmark + 0x2000, o->ymark, OBJ_MISERY_PHASE)->dir = LEFT; CreateObject(o->xmark - 0x2000, o->ymark, OBJ_MISERY_PHASE)->dir = RIGHT; } else if (o->timer == 50) { // switch back to showing real misery instead of the phase-in effect o->flags |= FLAG_SHOOTABLE; o->invisible = false; o->frame = 0; o->dir = LEFT; o->x = o->xmark; o->y = o->ymark; // spawn rings if (o->hp < 340) { CreateRing(o, 0x00); CreateRing(o, 0x80); if (o->hp < 180) { CreateRing(o, 0x40); CreateRing(o, 0xC0); } } // after tp we can summon the black balls if the player // is far enough away from us that they won't immediately trigger if (abs(player->x - o->x) > 112 * CSFI) { o->state = STATE_SUMMON_BALLS; } else { o->state = STATE_FIGHTING; } // setup sinusoidal hover, both of those possible states // are in-air states that do it. o->timer = 0; o->yinertia = -0x200; // counteracts yinertia of first visible frame, so it's a // seamless transition from the phase-in effect. o->y += 0x220; } } break; } }
MeshData MeshBuilder::CreateCone(float radius, float height, uint axisDivisions, uint heightDivisions, Color color) { MeshData data; uint v = 0, t = 0; uint numVerts = 2 + (axisDivisions * heightDivisions); uint numTris = axisDivisions * ((2 * heightDivisions) - 1) + axisDivisions; data.vertices.resize(numVerts); data.indices.resize(numTris * 3); height *= 0.5f; // centering our cone at the origion /// // Vertices /// // bottom data.vertices[v++].position = Vector3::Up * -height; // rings for (uint i = 0; i < axisDivisions; i++) { float theta = ((float)i / axisDivisions) * PI * 2; float x = cosf(theta) * radius; float z = sinf(theta) * radius; v = CreateVertexLine(Vector3::Up * -height, Vector3(x, height, z), heightDivisions , v, data.vertices); } // top data.vertices[v++].position = Vector3::Up * height; /// // Indices /// // bottom "ring" uint nextAxis; for (uint i = 0; i < axisDivisions; i++) { nextAxis = i * heightDivisions; data.indices[t++] = 0; data.indices[t++] = nextAxis + 1; data.indices[t++] = nextAxis + heightDivisions + 1; } // Set the last value back to one data.indices[t - 1] = 1; // Remaining "rings" for (uint i = 1; i < heightDivisions; i++) { t = CreateRing(axisDivisions, heightDivisions, i, t, data.indices); } // Top circle for (uint i = 1; i <= axisDivisions; i++) { data.indices[t++] = heightDivisions * i; data.indices[t++] = data.vertices.size() - 1; data.indices[t++] = heightDivisions * i + heightDivisions; } data.indices[t - 1] = heightDivisions; for (uint i = 0; i < data.vertices.size(); i++) { data.vertices[i].color = color; // BAD data.vertices[i].normal = Vector3::Normalize(data.vertices[i].position); } return data; }
IOReturn CLASS::UIMCreateControlEndpoint(UInt8 functionNumber, UInt8 endpointNumber, UInt16 maxPacketSize, UInt8 speed, USBDeviceAddress highSpeedHub, int highSpeedPort) { TRBStruct localTrb = { 0U }; IOReturn rc; ContextStruct* pContext; ringStruct* pRing; int32_t retFromCMD; uint16_t packetSize; uint8_t slot; if (functionNumber == _hub3Address || functionNumber == _hub2Address) return kIOReturnSuccess; packetSize = maxPacketSize != 9U ? maxPacketSize : 512U; if (!functionNumber) { if (_numEndpoints >= _maxNumEndpoints) return kIOUSBEndpointCountExceeded; retFromCMD = WaitForCMD(&localTrb, XHCI_TRB_TYPE_ENABLE_SLOT, 0); if (retFromCMD == -1 || retFromCMD <= -1000) return retFromCMD == (-1000 - XHCI_TRB_ERROR_NO_SLOTS) ? kIOUSBDeviceCountExceeded : kIOReturnInternalError; slot = static_cast<uint8_t>(retFromCMD); #if 0 /* * Note: Added Mavericks */ if (_vendorID == kVendorIntel && _IntelSlotWorkaround && slot == _numSlots) { _IntelSlotWorkaround = false; retFromCMD = CleanupControlEndpoint(slot, true); _IntelSWSlot = slot; if (retFromCMD == -1 || retFromCMD <= -1000) return kIOReturnInternalError; ClearTRB(&localTrb, true); retFromCMD = WaitForCMD(&localTrb, XHCI_TRB_TYPE_ENABLE_SLOT, 0); if (retFromCMD == -1 || retFromCMD <= -1000) return retFromCMD == (-1000 - XHCI_TRB_ERROR_NO_SLOTS) ? kIOUSBDeviceCountExceeded : kIOReturnInternalError; slot = static_cast<uint8_t>(retFromCMD); if (slot == _numSlots) ExecuteGetPortBandwidthWorkaround(); } _IntelSlotWorkaround = false; #endif if (!slot || slot > _numSlots) { /* * Sanity check. Bail out, 'cause UIMDeleteEndpoint * won't handle invalid slot # well. */ CleanupControlEndpoint(slot, true); IOLog("%s: xHC assigned invalid slot number %u\n", __FUNCTION__, slot); return kIOUSBDeviceCountExceeded; } pRing = CreateRing(slot, 1, 0U); if (!pRing || pRing->md) { CleanupControlEndpoint(slot, true); return kIOReturnInternalError; } _addressMapper.Slot[0] = slot; _addressMapper.Active[0] = true; rc = AllocRing(pRing, 1); if (rc != kIOReturnSuccess) { CleanupControlEndpoint(slot, false); return kIOReturnNoMemory; } rc = MakeBuffer(kIOMemoryPhysicallyContiguous | kIODirectionInOut, GetDeviceContextSize(), -PAGE_SIZE, &SlotPtr(slot)->md, reinterpret_cast<void**>(&SlotPtr(slot)->ctx), &SlotPtr(slot)->physAddr); if (rc != kIOReturnSuccess) { CleanupControlEndpoint(slot, false); return kIOReturnNoMemory; } if (!pRing->asyncEndpoint) { pRing->epType = CTRL_EP; pRing->asyncEndpoint = XHCIAsyncEndpoint::withParameters(this, pRing, packetSize, 0U, 0U); if (!pRing->asyncEndpoint) { CleanupControlEndpoint(slot, false); return kIOReturnNoMemory; } static_cast<void>(__sync_fetch_and_add(&_numEndpoints, 1)); } SetDCBAAAddr64(&_dcbaa.ptr[slot], ConstSlotPtr(slot)->physAddr); return AddressDevice(slot, packetSize, false, speed, GetSlotID(highSpeedHub), highSpeedPort); } if (endpointNumber) return kIOReturnInternalError; slot = GetSlotID(functionNumber); if (!slot) return kIOReturnInternalError; pContext = GetSlotContext(slot, 1); if (!pContext) return kIOReturnInternalError; if (XHCI_EPCTX_1_MAXP_SIZE_GET(pContext->_e.dwEpCtx1) == packetSize) return kIOReturnSuccess; GetInputContext(); pContext = GetInputContextPtr(); pContext->_ic.dwInCtx1 = XHCI_INCTX_1_ADD_MASK(1U); pContext = GetInputContextPtr(2); pContext->_e.dwEpCtx1 = XHCI_EPCTX_1_MAXP_SIZE_SET(static_cast<uint32_t>(packetSize)); SetTRBAddr64(&localTrb, _inputContext.physAddr); localTrb.d = XHCI_TRB_3_SLOT_SET(static_cast<uint32_t>(slot)); retFromCMD = WaitForCMD(&localTrb, XHCI_TRB_TYPE_EVALUATE_CTX, 0); ReleaseInputContext(); if (retFromCMD == -1) return kIOReturnInternalError; if (retFromCMD > -1000) return kIOReturnSuccess; if (retFromCMD == -1000 - XHCI_TRB_ERROR_PARAMETER) { #if 0 PrintContext(GetInputContextPtr()); PrintContext(GetInputContextPtr(2)); #endif } return kIOReturnInternalError; }
MeshData MeshBuilder::CreateCylinder(float radius, float height, uint axisDivisions, uint heightDivisions, Color color) { MeshData data; uint v = 0, t = 0; uint numVerts = 2 + (axisDivisions * (heightDivisions + 1)); uint numTris = 2 * axisDivisions + 2 * heightDivisions * axisDivisions; data.vertices.resize(numVerts); data.indices.resize(numTris * 3); height *= 0.5f; data.vertices[v++].position = Vector3::Up * -height; for (uint i = 0; i < axisDivisions; i++) { float theta = ((float)i / axisDivisions) * PI * 2; float x = cosf(theta) * radius; float z = sinf(theta) * radius; v = CreateVertexLineC(Vector3(x, -height, z), Vector3(x, height, z), heightDivisions, v, data.vertices); } data.vertices[v++].position = Vector3::Up * height; /// // Indices /// // bottom circle uint base = 1; for (uint i = 1; i <= axisDivisions; i++) { data.indices[t++] = 0; data.indices[t++] = base; data.indices[t++] = base + (heightDivisions + 1); base += heightDivisions + 1; } data.indices[t - 1] = 1; // rings for (uint i = 1; i <= heightDivisions ; i++) { t = CreateRing(axisDivisions, heightDivisions + 1, i, t, data.indices); } // Top circle for (uint i = 1; i <= axisDivisions; i++) { data.indices[t++] = (heightDivisions + 1) * i; data.indices[t++] = data.vertices.size() - 1; data.indices[t++] = (heightDivisions + 1) * i + (heightDivisions + 1); } data.indices[t - 1] = heightDivisions + 1; for (uint i = 0; i < data.vertices.size(); i++) { data.vertices[i].color = color; data.vertices[i].normal = Vector3::Normalize(data.vertices[i].position); } return data; }