EntityImp* entFac::createPowerUpRandom(b2World& world, float x, float y) { std::string bodyData("res/conf/powerUpBody.cfg"); int totalChance = spawnRates.getValue<int>("LHydrogen") + spawnRates.getValue<int>("EnergyTorpedo") + spawnRates.getValue<int>("EMP"); int previous = 0; int rand_val = rand() % totalChance; if(rand_val < spawnRates.getValue<int>("LHydrogen")) { return new LHydrogen(world, bodyData, x, y); } else previous += spawnRates.getValue<int>("LHydrogen"); if(rand_val < previous + spawnRates.getValue<int>("EnergyTorpedo")) { return new ETorpedoPickup(world, bodyData, x, y); } else previous += spawnRates.getValue<int>("EnergyTorpedo"); if(rand_val < previous + spawnRates.getValue<int>("EMP")) { return new EMP(world, bodyData, x, y); } else previous += spawnRates.getValue<int>("EMP"); SError("Random value out of bounds", "The Randomization value for powerup spawn is not in the desired range" + rand_val); return 0; }
PassRefPtr<FormData> httpBodyFromRequest(CFURLRequestRef request) { // RetainPtr<CFDataRef> bodyData(AdoptCF, CFURLRequestCopyHTTPRequestBody(request)); //Ricardo: comentando y cambiando por la linea siguiente. RetainPtr<CFDataRef> bodyData(AdoptCF, 0); if (bodyData) return FormData::create(CFDataGetBytePtr(bodyData.get()), CFDataGetLength(bodyData.get())); RetainPtr<CFArrayRef> bodyParts(AdoptCF, wkCFURLRequestCopyHTTPRequestBodyParts(request)); if (bodyParts) { RefPtr<FormData> formData = FormData::create(); CFIndex count = CFArrayGetCount(bodyParts.get()); for (CFIndex i = 0; i < count; i++) { CFTypeRef bodyPart = CFArrayGetValueAtIndex(bodyParts.get(), i); CFTypeID typeID = CFGetTypeID(bodyPart); if (typeID == CFStringGetTypeID()) { String filename = (CFStringRef)bodyPart; formData->appendFile(filename); } else if (typeID == CFDataGetTypeID()) { CFDataRef data = (CFDataRef)bodyPart; formData->appendData(CFDataGetBytePtr(data), CFDataGetLength(data)); } else ASSERT_NOT_REACHED(); } return formData.release(); } // FIXME: what to do about arbitrary body streams? return 0; }
/** * @brief 解析body数据 * @param data 原始数据 * @param dataSize 数据大小 * @param dataIndex 数据下标 * @return 返回解析数据是否成功 */ const bool ParseRequestData::readBodyData(const char* data, const std::size_t& dataSize, std::size_t& dataIndex) { std::size_t currentBodySize = dataSize - dataIndex; std::string bodyData(data); bodyData = bodyData.substr(dataIndex); if (0 == _leaveBodySize) _leaveBodySize = _bodySize; if (_leaveBodySize < currentBodySize) { _requestBuffer->_reqStatus = REQ_ERROR; return false; } else { dataIndex = dataSize; _leaveBodySize -= currentBodySize; _requestBuffer->_body += bodyData; if (_leaveBodySize > currentBodySize) { _requestBuffer->_reqStatus = REQ_BODY; return false; } else { if (_requestBuffer->_body.length() != _bodySize) { _requestBuffer->_reqStatus = REQ_BODY; return false; } _requestBuffer->_reqStatus = REQ_DONE; } } return true; }
EntityImp* createPowerUpEMP(b2World& world, float x, float y) { std::string bodyData("res/conf/powerUpBody.cfg"); return new EMP(world, bodyData, x, y); }
EntityImp* entFac::createPowerUpEnergyTorpedo(b2World& world, float x, float y) { std::string bodyData("res/conf/powerUpBody.cfg"); return new ETorpedoPickup(world, bodyData, x, y); }
EntityImp* entFac::createPowerUpLHydrogen(b2World& world, float x, float y) { std::string bodyData("res/conf/powerUpBody.cfg"); return new LHydrogen(world, bodyData, x, y); }