void* Graphics::ReserveScratchBuffer(unsigned size) { if (!size) return 0; if (size > maxScratchBufferRequest_) maxScratchBufferRequest_ = size; // First check for a free buffer that is large enough for (Vector<ScratchBuffer>::Iterator i = scratchBuffers_.Begin(); i != scratchBuffers_.End(); ++i) { if (!i->reserved_ && i->size_ >= size) { i->reserved_ = true; return i->data_.Get(); } } // Then check if a free buffer can be resized for (Vector<ScratchBuffer>::Iterator i = scratchBuffers_.Begin(); i != scratchBuffers_.End(); ++i) { if (!i->reserved_) { i->data_ = new unsigned char[size]; i->size_ = size; i->reserved_ = true; URHO3D_LOGDEBUG("Resized scratch buffer to size " + String(size)); return i->data_.Get(); } } // Finally allocate a new buffer ScratchBuffer newBuffer; newBuffer.data_ = new unsigned char[size]; newBuffer.size_ = size; newBuffer.reserved_ = true; scratchBuffers_.Push(newBuffer); return newBuffer.data_.Get(); URHO3D_LOGDEBUG("Allocated scratch buffer with size " + String(size)); }
void Graphics::CleanupScratchBuffers() { for (ScratchBuffer & elem : scratchBuffers_) { if (!elem.reserved_ && elem.size_ > maxScratchBufferRequest_ * 2 && elem.size_ >= 1024 * 1024) { elem.data_.reset(maxScratchBufferRequest_ > 0 ? new uint8_t[maxScratchBufferRequest_] : nullptr); elem.size_ = maxScratchBufferRequest_; URHO3D_LOGDEBUG("Resized scratch buffer to size " + QString::number(maxScratchBufferRequest_)); } } maxScratchBufferRequest_ = 0; }
VariantVector RaycastVehicle::GetWheelDataAttr() const { VariantVector ret; ret.Reserve(GetNumWheels() * 22 + 1); ret.Push(GetNumWheels()); for (int i = 0; i < GetNumWheels(); i++) { Node* wNode = GetWheelNode(i); int node_id = wNode->GetID(); URHO3D_LOGDEBUG("RaycastVehicle: Saving node id = " + String(node_id)); ret.Push(node_id); ret.Push(GetWheelDirection(i)); ret.Push(GetWheelAxle(i)); ret.Push(GetWheelRestLength(i)); ret.Push(GetWheelRadius(i)); ret.Push(IsFrontWheel(i)); ret.Push(GetSteeringValue(i)); ret.Push(GetWheelConnectionPoint(i)); ret.Push(origRotation_[i]); ret.Push(GetWheelSkidInfoCumulative(i)); ret.Push(GetWheelSideSlipSpeed(i)); ret.Push(WheelIsGrounded(i)); ret.Push(GetContactPosition(i)); ret.Push(GetContactNormal(i)); // 14 ret.Push(GetWheelSuspensionStiffness(i)); ret.Push(GetWheelDampingRelaxation(i)); ret.Push(GetWheelDampingCompression(i)); ret.Push(GetWheelFrictionSlip(i)); ret.Push(GetWheelRollInfluence(i)); ret.Push(GetEngineForce(i)); ret.Push(GetBrake(i)); ret.Push(GetWheelSkidInfo(i)); } URHO3D_LOGDEBUG("RaycastVehicle: saved items: " + String(ret.Size())); URHO3D_LOGDEBUG("maxSideSlipSpeed_ value save: " + String(maxSideSlipSpeed_)); return ret; }
void* Graphics::ReserveScratchBuffer(unsigned size) { if (!size) return nullptr; if (size > maxScratchBufferRequest_) maxScratchBufferRequest_ = size; // First check for a free buffer that is large enough for (ScratchBuffer & elem : scratchBuffers_) { if (!elem.reserved_ && elem.size_ >= size) { elem.reserved_ = true; return elem.data_.get(); } } // Then check if a free buffer can be resized for (ScratchBuffer & elem : scratchBuffers_) { if (!elem.reserved_) { elem.data_.reset(new uint8_t[size]); elem.size_ = size; elem.reserved_ = true; URHO3D_LOGDEBUG("Resized scratch buffer to size " + QString::number(size)); return elem.data_.get(); } } // Finally allocate a new buffer ScratchBuffer newBuffer{std::unique_ptr<uint8_t[]>(new uint8_t[size]), size, true}; scratchBuffers_.emplace_back(std::move(newBuffer)); URHO3D_LOGDEBUG("Allocated scratch buffer with size " + QString::number(size)); return scratchBuffers_.back().data_.get(); }
void Graphics::CleanupScratchBuffers() { for (Vector<ScratchBuffer>::Iterator i = scratchBuffers_.Begin(); i != scratchBuffers_.End(); ++i) { if (!i->reserved_ && i->size_ > maxScratchBufferRequest_ * 2 && i->size_ >= 1024 * 1024) { i->data_ = maxScratchBufferRequest_ > 0 ? new unsigned char[maxScratchBufferRequest_] : 0; i->size_ = maxScratchBufferRequest_; URHO3D_LOGDEBUG("Resized scratch buffer to size " + String(maxScratchBufferRequest_)); } } maxScratchBufferRequest_ = 0; }
void Graphics::RemoveGPUObject(GPUObject* object) { MutexLock lock(gpuObjectMutex_); if(gpuObjects_.empty()) { // this might happen if Graphics subsystem is shutting down. return; } auto iter = std::find(gpuObjects_.begin(),gpuObjects_.end(),object); if(iter==gpuObjects_.end()) { URHO3D_LOGDEBUG("Graphics::RemoveGPUObject called multiple times on same object"); } gpuObjects_.erase(iter); }
void NamedPipe::Close() { if (handle_ != INVALID_HANDLE_VALUE) { URHO3D_PROFILE(CloseNamedPipe); if (isServer_) { DisconnectNamedPipe(handle_); isServer_ = false; } CloseHandle(handle_); handle_ = INVALID_HANDLE_VALUE; pipeName_.Clear(); URHO3D_LOGDEBUG("Closed named pipe " + pipeName_); } }
HttpRequest::HttpRequest(const String& url, const String& verb, const Vector<String>& headers, const String& postData) : url_(url.Trimmed()), verb_(!verb.Empty() ? verb : "GET"), headers_(headers), postData_(postData), state_(HTTP_INITIALIZING), httpReadBuffer_(new unsigned char[READ_BUFFER_SIZE]), readBuffer_(new unsigned char[READ_BUFFER_SIZE]), readPosition_(0), writePosition_(0) { // Size of response is unknown, so just set maximum value. The position will also be changed // to maximum value once the request is done, signaling end for Deserializer::IsEof(). size_ = M_MAX_UNSIGNED; URHO3D_LOGDEBUG("HTTP " + verb_ + " request to URL " + url_); #ifdef URHO3D_THREADING // Start the worker thread to actually create the connection and read the response data. Run(); #else URHO3D_LOGERROR("HTTP request will not execute as threading is disabled"); #endif }
void RaycastVehicle::ApplyAttributes() { int index = 0; hullBody_ = node_->GetOrCreateComponent<RigidBody>(); Scene* scene = GetScene(); vehicleData_->Init(scene, hullBody_); VariantVector& value = loadedWheelData_; int numObjects = value[index++].GetInt(); int wheelIndex = 0; origRotation_.Clear(); skidInfoCumulative_.Clear(); wheelSideSlipSpeed_.Clear(); for (int i = 0; i < numObjects; i++) { int node_id = value[index++].GetInt(); Vector3 direction = value[index++].GetVector3(); Vector3 axle = value[index++].GetVector3(); float restLength = value[index++].GetFloat(); float radius = value[index++].GetFloat(); bool isFrontWheel = value[index++].GetBool(); float steering = value[index++].GetFloat(); Vector3 connectionPoint = value[index++].GetVector3(); Quaternion origRotation = value[index++].GetQuaternion(); float skidInfoC = value[index++].GetFloat(); float sideSlipSpeed = value[index++].GetFloat(); bool isContact = value[index++].GetBool(); Vector3 contactPosition = value[index++].GetVector3(); Vector3 contactNormal = value[index++].GetVector3(); float suspensionStiffness = value[index++].GetFloat(); float dampingRelaxation = value[index++].GetFloat(); float dampingCompression = value[index++].GetFloat(); float frictionSlip = value[index++].GetFloat(); float rollInfluence = value[index++].GetFloat(); float engineForce = value[index++].GetFloat(); float brake = value[index++].GetFloat(); float skidInfo = value[index++].GetFloat(); Node* wheelNode = GetScene()->GetNode(node_id); if (!wheelNode) { URHO3D_LOGERROR("RaycastVehicle: Incorrect node id = " + String(node_id) + " index: " + String(index)); continue; } btRaycastVehicle* vehicle = vehicleData_->Get(); int id = GetNumWheels(); btVector3 connectionPointCS0(connectionPoint.x_, connectionPoint.y_, connectionPoint.z_); btVector3 wheelDirectionCS0(direction.x_, direction.y_, direction.z_); btVector3 wheelAxleCS(axle.x_, axle.y_, axle.z_); btWheelInfo& wheel = vehicle->addWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, restLength, radius, vehicleData_->tuning_, isFrontWheel); wheelNodes_.Push(wheelNode); origRotation_.Push(origRotation); skidInfoCumulative_.Push(skidInfoC); wheelSideSlipSpeed_.Push(sideSlipSpeed); SetSteeringValue(wheelIndex, steering); wheel.m_raycastInfo.m_isInContact = isContact; wheel.m_raycastInfo.m_contactNormalWS = btVector3(contactNormal.x_, contactNormal.y_, contactNormal.z_); wheel.m_raycastInfo.m_contactPointWS = btVector3(contactPosition.x_, contactPosition.y_, contactPosition.z_); wheel.m_suspensionStiffness = suspensionStiffness; wheel.m_wheelsDampingRelaxation = dampingRelaxation; wheel.m_wheelsDampingCompression = dampingCompression; wheel.m_frictionSlip = frictionSlip; wheel.m_rollInfluence = rollInfluence; wheel.m_engineForce = engineForce; wheel.m_brake = brake; wheel.m_skidInfo = skidInfo; wheelIndex++; } URHO3D_LOGDEBUG("maxSideSlipSpeed_ value: " + String(maxSideSlipSpeed_)); URHO3D_LOGDEBUG("loaded items: " + String(index)); URHO3D_LOGDEBUG("loaded wheels: " + String(GetNumWheels())); }
bool NamedPipe::Open(const String& pipeName, bool isServer) { #ifdef __EMSCRIPTEN__ URHO3D_LOGERROR("Opening a named pipe not supported on Web platform"); return false; #else URHO3D_PROFILE(OpenNamedPipe); Close(); isServer_ = false; String serverReadName = pipePath + pipeName + "SR"; String clientReadName = pipePath + pipeName + "CR"; // Make sure SIGPIPE is ignored and will not lead to process termination signal(SIGPIPE, SIG_IGN); if (isServer) { mkfifo(serverReadName.CString(), 0660); mkfifo(clientReadName.CString(), 0660); readHandle_ = open(serverReadName.CString(), O_RDONLY | O_NDELAY); writeHandle_ = open(clientReadName.CString(), O_WRONLY | O_NDELAY); if (readHandle_ == -1 && writeHandle_ == -1) { URHO3D_LOGERROR("Failed to create named pipe " + pipeName); SAFE_CLOSE(readHandle_); SAFE_CLOSE(writeHandle_); unlink(serverReadName.CString()); unlink(clientReadName.CString()); return false; } else { URHO3D_LOGDEBUG("Created named pipe " + pipeName); pipeName_ = pipeName; isServer_ = true; return true; } } else { readHandle_ = open(clientReadName.CString(), O_RDONLY | O_NDELAY); writeHandle_ = open(serverReadName.CString(), O_WRONLY | O_NDELAY); if (readHandle_ == -1 && writeHandle_ == -1) { URHO3D_LOGERROR("Failed to connect to named pipe " + pipeName); SAFE_CLOSE(readHandle_); SAFE_CLOSE(writeHandle_); return false; } else { URHO3D_LOGDEBUG("Connected to named pipe " + pipeName); pipeName_ = pipeName; return true; } } #endif }