Exemplo n.º 1
0
/***************************************************************************\
* AddInstance
*
* Description:
* Adds a server side instance handle to the instance handle array.
* The array index becomes the client-side unique instance index used for
* identifying other client side handles.
*
* Returns:
* client side instance handle or 0 on error.
*
* History:
* 11-1-91 sanfords Created.
\***************************************************************************/
DWORD AddInstance(
HANDLE hInstServer)
{
    int i, iNextFree;
    PHANDLE ph;

    if (iFirstFreeInst >= cInstAllocated) {
        if (cInstAllocated == 0) {
           aInstance = (PHANDLE)DDEMLAlloc(sizeof(HANDLE) * INST_GROW_COUNT);
        } else {
           aInstance = (PHANDLE)DDEMLReAlloc((PVOID)aInstance,
                 sizeof(HANDLE) * (cInstAllocated + INST_GROW_COUNT));
        }
        if (aInstance == 0) {
            return (0);
        }
        ph = &aInstance[cInstAllocated];
        i = cInstAllocated + 1;
        while (i <= cInstAllocated + INST_GROW_COUNT) {
           *ph++ = (HANDLE)i++;
        }
        cInstAllocated += INST_GROW_COUNT;
    }
    iNextFree = (int)aInstance[iFirstFreeInst];
    if (iNextFree > MAX_INST) {
        /*
         * Instance limit for this process exceeded!
         */
        return(0);
    }
    aInstance[iFirstFreeInst] = hInstServer;
    i = iFirstFreeInst;
    iFirstFreeInst = iNextFree;
    return ((DWORD)CreateHandle(0, HTYPE_INSTANCE, i));
}
Exemplo n.º 2
0
	void Collider3D::ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const
	{
		float inertiaMatrix[3];
		float origin[3];

		// Si nous n'avons aucune instance, nous en créons une temporaire
		if (m_handles.empty())
		{
			PhysWorld3D world;

			NewtonCollision* collision = CreateHandle(&world);
			{
				NewtonConvexCollisionCalculateInertialMatrix(collision, inertiaMatrix, origin);
			}
			NewtonDestroyCollision(collision);
		}
		else // Sinon on utilise une instance au hasard (elles sont toutes identiques de toute façon)
			NewtonConvexCollisionCalculateInertialMatrix(m_handles.begin()->second, inertiaMatrix, origin);

		if (inertia)
			inertia->Set(inertiaMatrix);

		if (center)
			center->Set(origin);
	}
	void Collider3D::ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const
	{
		float inertiaMatrix[3];
		float origin[3];

		// Check for existing collision handles, and create a temporary one if none is available
		if (m_handles.empty())
		{
			PhysWorld3D world;

			NewtonCollision* collision = CreateHandle(&world);
			{
				NewtonConvexCollisionCalculateInertialMatrix(collision, inertiaMatrix, origin);
			}
			NewtonDestroyCollision(collision);
		}
		else
			NewtonConvexCollisionCalculateInertialMatrix(m_handles.begin()->second, inertiaMatrix, origin);

		if (inertia)
			inertia->Set(inertiaMatrix);

		if (center)
			center->Set(origin);
	}
Exemplo n.º 4
0
    /**
     * Returns -1 if command queue or pickup pool is full, 0 on success (will be
     * called by audio thread within the voice class).
     */
    int DiskThread::OrderNewStream(Stream::reference_t* pStreamRef, ::gig::DimensionRegion* pDimRgn, unsigned long SampleOffset, bool DoLoop) {
        dmsg(4,("Disk Thread: new stream ordered\n"));
        if (CreationQueue->write_space() < 1) {
            dmsg(1,("DiskThread: Order queue full!\n"));
            return -1;
        }

	const Stream::OrderID_t newOrder = CreateOrderID();
	if (!newOrder) {
		dmsg(1,("DiskThread: there was no free slot\n"));
		return -1; // there was no free slot
	}

        pStreamRef->State   = Stream::state_active;
        pStreamRef->OrderID = newOrder;
        pStreamRef->hStream = CreateHandle();
        pStreamRef->pStream = NULL; // a stream has to be activated by the disk thread first

        create_command_t cmd;
        cmd.OrderID      = pStreamRef->OrderID;
        cmd.hStream      = pStreamRef->hStream;
        cmd.pStreamRef   = pStreamRef;
        cmd.pDimRgn      = pDimRgn;
        cmd.SampleOffset = SampleOffset;
        cmd.DoLoop       = DoLoop;

        CreationQueue->push(&cmd);
        return 0;
    }
	NewtonCollision* Collider3D::GetHandle(PhysWorld3D* world) const
	{
		auto it = m_handles.find(world);
		if (it == m_handles.end())
			it = m_handles.insert(std::make_pair(world, CreateHandle(world))).first;

		return it->second;
	}
Exemplo n.º 6
0
Arquivo: Os.c Projeto: astaykov/ohNet
THandle OsNetworkCreate(OsNetworkSocketType aSocketType)
{
    int32_t socketH = socket(2, aSocketType, 0);
    OsNetworkHandle* handle = CreateHandle(socketH);
    if (handle == kHandleNull) {
        TEMP_FAILURE_RETRY(close(socketH));
    }
    return (THandle)handle;
}
Exemplo n.º 7
0
THandle OsNetworkCreate(OsContext* aContext, OsNetworkSocketType aSocketType)
{
    int32_t socketH = socket(2, aSocketType, 0);
    OsNetworkHandle* handle = CreateHandle(aContext, socketH);
    if (handle == kHandleNull) {
        /* close is the one networking call that is exempt from being wrapped by TEMP_FAILURE_RETRY.  See
        https://sites.google.com/site/michaelsafyan/software-engineering/checkforeintrwheninvokingclosethinkagain */
        close(socketH);
    }
    return (THandle)handle;
}
Exemplo n.º 8
0
    void GameWindow::SetPosition(Point2 value)
    {
        if (handle == nullptr)
            CreateHandle();

        if (position != value)
        {
            position = value;
            
            ::SetWindowPos(static_cast<HWND>(handle), nullptr, position.X, position.Y, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
        }
    }
Exemplo n.º 9
0
VFSHandle * VFSTransport::OpenLocation(char *loc, bool create)
{
	VFSHandle *handle = CreateHandle(this);

	if(handle->OpenLocation(loc,create) == true){
		m_handles.push_back(handle);
		return handle;
	}

	delete[] handle;
	return NULL;
}
Exemplo n.º 10
0
/* Get a new Tax ID given an old Tax ID from the merged node database */
Int4 DB_GetTaxMergedNodeRecNewTIDByOldTID(Int4 oldTaxId)
{
CharPtr search_mergeddb = "select new_taxid from seqhound.mergedtaxdb where old_taxid=?";
   SQLHANDLE hstmt;
   Int4 new_value = -1;
   Int2 sqlrc=SQL_SUCCESS;
   struct{
     Int4 len;
     Int4 val;
   }new_id;
 
   /* search merged db*/
   CreateHandle(&hstmt,search_mergeddb,&henv, &hdbc);

  SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG,SQL_INTEGER, 0, 0, &oldTaxId, 0, NULL);

  /* set auto commit on */
   SQLSetConnectAttr( hdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON, SQL_NTS);  

  /* execute statment */
  if (SQLExecute(hstmt) != SQL_SUCCESS){
	ErrPostEx(SEV_ERROR,0,0,"DB_GetTaxMergedNodeRecNewTIDByOldTID:unable to execute select statement.");
	print_err(hstmt);
	SQLFreeStmt(hstmt, SQL_DROP);
	return FALSE;
  }

  SQLBindCol(hstmt,1,SQL_C_LONG,&new_id.val,10,(long*)&new_id.len); 
 
  sqlrc = SQLFetch(hstmt);
  if(sqlrc == SQL_NO_DATA_FOUND){
    ErrPostEx(SEV_INFO, 0, 0, "Old Tax ID: %ld not found in Mergedtaxdb.", oldTaxId);
	return(-1);
  }
  else if(sqlrc == SQL_SUCCESS || sqlrc == SQL_SUCCESS_WITH_INFO){
    new_value = new_id.val; 
	}
  else{
    print_err(hstmt);
    return (-1);
  }

   /* Free statement handle. */
   if(SQLFreeStmt(hstmt, SQL_DROP) != SQL_SUCCESS){
     print_err(hstmt);
     return (-1);
   }
   return(new_value);

}
Exemplo n.º 11
0
/* Replace an SLRI-Taxon record in the database */
Int2 DB_ReplaceTaxRec(SLRITaxonPtr stp)
{
   Int4 bsLength=0;
   pABL Asnbuflen=NULL;
   Int4 taxid;
   CharPtr asn1;  
   SQLHANDLE hstmt;
   CharPtr update = "update seqhound.taxdb set asn1=? where taxid = ?";

   if(stp == NULL) {
     ErrPostEx(SEV_INFO, 3, 0, "DB_WriteTaxRec: Passed ASN.1 pointer is null.");
     return(-1);
    }
   
   CreateHandle(&hstmt,update,&henv,&hdbc);

   /*get the asn1 bioseq into a bytestore pointer so that we can put it into a buffer.*/
  Asnbuflen = AssignASNMemChar((Pointer) stp, (AsnWriteFunc) SLRITaxonAsnWrite);
  /* SK: NULL ptr check */
  if(Asnbuflen == NULL) {
     ErrPostEx(SEV_INFO, 3, 0, "DB_ReplaceTaxRec: NULL Asnbuflen.");
     return(-1);
  }
   asn1 = Asnbuflen->buf;
  bsLength = Asnbuflen->len;     
  
   /*set up the input parameters */
  SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_DEFAULT,SQL_BLOB, 0, 0, asn1, 0, (long*)&bsLength);
  SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG,SQL_INTEGER, 0, 0, &taxid, 0, NULL);

 taxid = stp->taxId;
	
  /* execute statment */
  if (SQLExecute (hstmt) != SQL_SUCCESS){
    ErrPostEx(SEV_ERROR,0,0, "DB_ReplaceTax: unable to execute insert statement. ");
    print_err(hstmt);
    return FALSE;
  }

  asn1 = MemFree(asn1);
/*  pABLtmp->buf = MemFree(pABLtmp->buf);*/
  FreeABL(Asnbuflen);

  if(SQLFreeStmt(hstmt, SQL_DROP) != SQL_SUCCESS){
     print_err(hstmt);
     return FALSE;
   }

   return TRUE;
}
Exemplo n.º 12
0
Arquivo: Os.c Projeto: broonie/ohNet
THandle OsNetworkAccept(THandle aHandle, TIpAddress* aClientAddress, uint32_t* aClientPort)
{
    SOCKET h;
    OsNetworkHandle* newHandle;
    OsNetworkHandle* handle = (OsNetworkHandle*)aHandle;
    WSAEVENT event;
    HANDLE handles[2];
    DWORD ret;
    struct sockaddr_in addr;
    socklen_t len = sizeof(addr);

    *aClientAddress = 0;
    *aClientPort = 0;
    if (SocketInterrupted(handle)) {
        return kHandleNull;
    }
    sockaddrFromEndpoint(&addr, 0, 0);
    event = WSACreateEvent();
    if (NULL == event) {
        return kHandleNull;
    }
    if (0 != WSAEventSelect(handle->iSocket, event, FD_ACCEPT|FD_CLOSE)) {
        WSACloseEvent(event);
        return kHandleNull;
    }

    h = accept(handle->iSocket, (struct sockaddr*)&addr, &len);
    if (INVALID_SOCKET==h && WSAEWOULDBLOCK==WSAGetLastError()) {
        handles[0] = event;
        handles[1] = handle->iEvent;
        ret = WSAWaitForMultipleEvents(2, &handles[0], FALSE, INFINITE, FALSE);
        if (WAIT_OBJECT_0 == ret) {
            h = accept(handle->iSocket, (struct sockaddr*)&addr, &len);
        }
    }
    SetSocketBlocking(handle->iSocket);
    WSACloseEvent(event);
    if (INVALID_SOCKET == h) {
        return kHandleNull;
    }

    newHandle = CreateHandle(handle->iCtx, h);
    if (NULL == newHandle) {
        return kHandleNull;
    }

    *aClientAddress = addr.sin_addr.s_addr;
    *aClientPort = SwapEndian16(addr.sin_port);
    return (THandle)newHandle;
}
Exemplo n.º 13
0
/**	Opens a file
 *
 *	@param filename	The name of the file being opened
 *	@param plugin		The plugin to be used to decode the file data
 *	@param create		Whether to create a non-existant file, or return a false upon attempting to open
 *
 *	Operation:
 *		-#	Creates a new handle
 *		-#	Move the pointer along the string to remove the transport identifier
 *		-#	Requests the handle open the file
 *		-#	Sets the plugin of the new handle
 *		-#	if opening the file was successful, returns the new file handle
 *		-#	Otherwise, handle is deleted and NULL is returned
 */
VFSHandle * VFSTransport::Open(char *filename, VFSPlugin *plugin, bool create)
{
	VFSHandle *handle = CreateHandle(this);

	handle->SetPlugin(plugin);

	if(handle->Open(filename, create) == true){
		m_handles.push_back(handle);
		return handle;
	}

	delete handle;
	return NULL;
}
Exemplo n.º 14
0
    void GameWindow::MoveToScreenCenter()
    {
        if (handle == nullptr)
            CreateHandle();

        RECT windowRect = { 0, 0, 0, 0 };
        if (::GetWindowRect(static_cast<HWND>(handle), &windowRect))
        {
            const SIZE screenSize = { GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN) };
            const SIZE windowSize = { windowRect.right - windowRect.left, windowRect.bottom - windowRect.top };
            const POINT windowPosition = { (screenSize.cx - windowSize.cx) / 2, (screenSize.cy - windowSize.cy) / 2 };

            SetPosition(Point2(windowPosition.x, windowPosition.y));
        }
    }
Exemplo n.º 15
0
    void GameWindow::SetTitle(const String& value)
    {
        if (handle == nullptr)
            CreateHandle();

        if (title != value)
        {
            title = value;

            std::vector<wchar_t> wideCharacters;
            wideCharacters.resize(MultiByteToWideChar(CP_UTF8, 0, title.CStr(), title.GetLength(), nullptr, 0) + 1, L'\0');
            MultiByteToWideChar(CP_UTF8, 0, title.CStr(), title.GetLength(), &wideCharacters[0], wideCharacters.size());
            
            ::SetWindowTextW(static_cast<HWND>(handle), &wideCharacters[0]);
        }
    }
Exemplo n.º 16
0
    void GameWindow::SetVisible(bool value)
    {
        if (handle == nullptr)
            CreateHandle();

        if (visible != value)
        {
            visible = value;

            int showCommand = SW_HIDE;
            if (visible)
                showCommand = SW_SHOW;

            ::ShowWindow(static_cast<HWND>(handle), showCommand);
        }
    }
Exemplo n.º 17
0
THandle OsNetworkAccept(THandle aHandle, TIpAddress* aClientAddress, uint32_t* aClientPort)
{
    OsNetworkHandle* handle = (OsNetworkHandle*)aHandle;
    *aClientAddress = 0;
    *aClientPort = 0;
    if (SocketInterrupted(handle)) {
        return kHandleNull;
    }
    struct sockaddr_in addr;
    sockaddrFromEndpoint(&addr, 0, 0);
    socklen_t len = sizeof(addr);

    SetFdNonBlocking(handle->iSocket);

    fd_set read;
    FD_ZERO(&read);
    FD_SET(handle->iPipe[0], &read);
    FD_SET(handle->iSocket, &read);
    fd_set error;
    FD_ZERO(&error);
    FD_SET(handle->iSocket, &error);

    int32_t h = TEMP_FAILURE_RETRY_2(accept(handle->iSocket, (struct sockaddr*)&addr, &len), handle);
    if (h==-1 && errno==EWOULDBLOCK) {
        int32_t selectErr = TEMP_FAILURE_RETRY_2(select(nfds(handle), &read, NULL, &error, NULL), handle);
        if (selectErr > 0 && FD_ISSET(handle->iSocket, &read)) {
            h = TEMP_FAILURE_RETRY_2(accept(handle->iSocket, (struct sockaddr*)&addr, &len), handle);
        }
    }
    SetFdBlocking(handle->iSocket);
    if (h == -1) {
        return kHandleNull;
    }

    OsNetworkHandle* newHandle = CreateHandle(handle->iCtx, h);
    if (newHandle == NULL) {
        close(h);
        return kHandleNull;
    }

    *aClientAddress = addr.sin_addr.s_addr;
    *aClientPort = ntohs(addr.sin_port);
    return (THandle)newHandle;
}
Exemplo n.º 18
0
    void GameWindow::SetSize(Point2 value)
    {
        if (handle == nullptr)
            CreateHandle();

        if (GetSize() != value)
        {
            size = value;

            const DWORD exWindowStyle = static_cast<DWORD>(GetWindowLong(static_cast<HWND>(handle), GWL_EXSTYLE));
            const DWORD windowStyle = static_cast<DWORD>(GetWindowLong(static_cast<HWND>(handle), GWL_STYLE));
            const BOOL hasMenu = GetMenu(static_cast<HWND>(handle)) != nullptr ? TRUE : FALSE;
            RECT windowRect = { 0, 0, size.X, size.Y };
            ::AdjustWindowRectEx(&windowRect, windowStyle, hasMenu, exWindowStyle);

            const SIZE windowSize = { windowRect.right - windowRect.left, windowRect.bottom - windowRect.top };
            ::SetWindowPos(static_cast<HWND>(handle), nullptr, 0, 0, windowSize.cx, windowSize.cy, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
        }
    }
Exemplo n.º 19
0
static void SetInterfaceChangedObserver_Linux(OsContext* aContext, InterfaceListChanged aCallback, void* aArg)
{
    struct sockaddr_nl addr;
    int sock = 0;

    aContext->iInterfaceChangedObserver = (InterfaceChangedObserver*) calloc(1, sizeof(InterfaceChangedObserver));
    if (aContext->iInterfaceChangedObserver == NULL) {
        goto Error;
    }

    if ((sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) == -1) {
        goto Error;
    }

    memset(&addr, 0, sizeof(addr));
    addr.nl_family = AF_NETLINK;
    addr.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR;
    if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
        close(sock);
        goto Error;
    }

    if ((aContext->iInterfaceChangedObserver->netHnd = CreateHandle(aContext, sock)) == NULL) {
        close(sock);
        goto Error;
    }

    aContext->iInterfaceChangedObserver->iCallback = aCallback;
    aContext->iInterfaceChangedObserver->iArg = aArg;
    if ((aContext->iInterfaceChangedObserver->iThread = DoThreadCreate(aContext,
                                                            "AdapterChangeObserverThread",
                                                            100, 16 * 1024, 1,
                                                            adapterChangeObserverThread,
                                                            aContext->iInterfaceChangedObserver)) == NULL) {
        goto Error;
    }
    
    return;

Error:
    DestroyInterfaceChangedObserver_Linux(aContext);
}
Exemplo n.º 20
0
	float Collider3D::ComputeVolume() const
	{
		float volume;

		// Si nous n'avons aucune instance, nous en créons une temporaire
		if (m_handles.empty())
		{
			PhysWorld3D world;

			NewtonCollision* collision = CreateHandle(&world);
			{
				volume = NewtonConvexCollisionCalculateVolume(collision);
			}
			NewtonDestroyCollision(collision);
		}
		else // Sinon on utilise une instance au hasard (elles sont toutes identiques de toute façon)
			volume = NewtonConvexCollisionCalculateVolume(m_handles.begin()->second);

		return volume;
	}
Exemplo n.º 21
0
	Boxf Collider3D::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
	{
		Vector3f min, max;

		// Si nous n'avons aucune instance, nous en créons une temporaire
		if (m_handles.empty())
		{
			PhysWorld3D world;

			NewtonCollision* collision = CreateHandle(&world);
			{
				NewtonCollisionCalculateAABB(collision, offsetMatrix, min, max);
			}
			NewtonDestroyCollision(collision);
		}
		else // Sinon on utilise une instance au hasard (elles sont toutes identiques de toute façon)
			NewtonCollisionCalculateAABB(m_handles.begin()->second, offsetMatrix, min, max);

		return Boxf(scale * min, scale * max);
	}
	Boxf Collider3D::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
	{
		Vector3f min, max;

		// Check for existing collision handles, and create a temporary one if none is available
		if (m_handles.empty())
		{
			PhysWorld3D world;

			NewtonCollision* collision = CreateHandle(&world);
			{
				NewtonCollisionCalculateAABB(collision, offsetMatrix, min, max);
			}
			NewtonDestroyCollision(collision);
		}
		else
			NewtonCollisionCalculateAABB(m_handles.begin()->second, offsetMatrix, min, max);

		return Boxf(scale * min, scale * max);
	}
	float Collider3D::ComputeVolume() const
	{
		float volume;

		// Check for existing collision handles, and create a temporary one if none is available
		if (m_handles.empty())
		{
			PhysWorld3D world;

			NewtonCollision* collision = CreateHandle(&world);
			{
				volume = NewtonConvexCollisionCalculateVolume(collision);
			}
			NewtonDestroyCollision(collision);
		}
		else
			volume = NewtonConvexCollisionCalculateVolume(m_handles.begin()->second);

		return volume;
	}
Exemplo n.º 24
0
static UCHAR EmsAlloc(USHORT NumPages, PUSHORT Handle)
{
    ULONG i, CurrentIndex = 0;
    PEMS_HANDLE HandleEntry;

    if (NumPages == 0) return EMS_STATUS_ZERO_PAGES;

    HandleEntry = CreateHandle(Handle);
    if (!HandleEntry)  return EMS_STATUS_NO_MORE_HANDLES;

    while (HandleEntry->PageCount < NumPages)
    {
        ULONG RunStart;
        ULONG RunSize = RtlFindNextForwardRunClear(&AllocBitmap, CurrentIndex, &RunStart);

        if (RunSize == 0)
        {
            /* Free what's been allocated already and report failure */
            EmsFree(*Handle);
            return EMS_STATUS_INSUFFICIENT_PAGES;
        }
        else if ((HandleEntry->PageCount + RunSize) > NumPages)
        {
            /* We don't need the entire run */
            RunSize = NumPages - HandleEntry->PageCount;
        }

        CurrentIndex = RunStart + RunSize;
        HandleEntry->PageCount += RunSize;
        RtlSetBits(&AllocBitmap, RunStart, RunSize);

        for (i = 0; i < RunSize; i++)
        {
            PageTable[RunStart + i].Handle = *Handle;
            InsertTailList(&HandleEntry->PageList, &PageTable[RunStart + i].Entry);
        }
    }

    return EMS_STATUS_SUCCESS;
}
mitk::BoundingShapeVtkMapper2D::LocalStorage::LocalStorage()
  : m_Actor(vtkSmartPointer<vtkActor>::New()),
  m_HandleActor(vtkSmartPointer<vtkActor2D>::New()),
  m_SelectedHandleActor(vtkSmartPointer<vtkActor2D>::New()),
  m_Mapper(vtkSmartPointer<vtkPolyDataMapper>::New()),
  m_HandleMapper(vtkSmartPointer<vtkPolyDataMapper2D>::New()),
  m_SelectedHandleMapper(vtkSmartPointer<vtkPolyDataMapper2D>::New()),
  m_Cutter(vtkSmartPointer<vtkCutter>::New()),
  m_CuttingPlane(vtkSmartPointer<vtkPlane>::New()),
  m_LastSliceNumber(0),
  m_PropAssembly(vtkSmartPointer<vtkPropAssembly>::New()),
  m_ZoomFactor(1.0)
{
  m_Actor->SetMapper(m_Mapper);
  m_Actor->GetProperty()->SetOpacity(0.3);
  m_Actor->VisibilityOn();

  m_HandleActor->SetMapper(m_HandleMapper);
  m_HandleActor->VisibilityOn();

  m_SelectedHandleActor->VisibilityOn();
  m_SelectedHandleActor->GetProperty()->SetColor(0, 1.0, 0);
  m_SelectedHandleActor->SetMapper(m_SelectedHandleMapper);

  vtkCoordinate *tcoord = vtkCoordinate::New();
  tcoord->SetCoordinateSystemToWorld();
  m_SelectedHandleMapper->SetTransformCoordinate(tcoord);
  tcoord->Delete();

  m_Cutter->SetCutFunction(m_CuttingPlane);

  for (int i = 0; i < 6; ++i)
    m_Handles.push_back(CreateHandle());

  m_PropAssembly->AddPart(m_Actor);
  m_PropAssembly->AddPart(m_HandleActor);
  m_PropAssembly->VisibilityOn();
}
	void Collider3D::ForEachPolygon(const std::function<void(const Vector3f* vertices, std::size_t vertexCount)>& callback) const
	{
		auto newtCallback = [](void* const userData, int vertexCount, const dFloat* const faceArray, int /*faceId*/)
		{
			static_assert(sizeof(Vector3f) == 3 * sizeof(float), "Vector3 is expected to contain 3 floats without padding");

			const auto& cb = *static_cast<std::add_pointer_t<decltype(callback)>>(userData);
			cb(reinterpret_cast<const Vector3f*>(faceArray), vertexCount);
		};

		// Check for existing collision handles, and create a temporary one if none is available
		if (m_handles.empty())
		{
			PhysWorld3D world;

			NewtonCollision* collision = CreateHandle(&world);
			{
				NewtonCollisionForEachPolygonDo(collision, Nz::Matrix4f::Identity(), newtCallback, const_cast<void*>(static_cast<const void*>(&callback))); //< This isn't that bad; pointer will not be used for writing
			}
			NewtonDestroyCollision(collision);
		}
		else
			NewtonCollisionForEachPolygonDo(m_handles.begin()->second, Nz::Matrix4f::Identity(), newtCallback, const_cast<void*>(static_cast<const void*>(&callback))); //< This isn't that bad; pointer will not be used for writing
	}
Exemplo n.º 27
0
/***************************************************************************\
* DdeConnectList (DDEML API)
*
* Description:
* Initiates DDE conversations with multiple servers or adds unique servers
* to an existing conversation list.
*
* History:
* 11-12-91 sanfords Created.
\***************************************************************************/
HCONVLIST DdeConnectList(
    DWORD idInst,
    HSZ hszService,
    HSZ hszTopic,
    HCONVLIST hConvList,
    PCONVCONTEXT pCC)
{
    PCL_INSTANCE_INFO pcii;
    PCONV_INFO pcoi, pcoiNew, pcoiExisting, pcoiNext;
    HCONVLIST hConvListRet = 0;
    HWND hwndTarget = 0;
    LATOM aNormalSvcName = 0;
    PCONVLIST pcl = NULL;
    HCONVLIST hConvListOld;
    int i;

    CheckDDECritOut;

    EnterDDECrit;

    if (!ValidateConnectParameters((HANDLE)idInst, &pcii, &hszService, hszTopic,
            &aNormalSvcName, &pCC, &hwndTarget, hConvList)) {
        goto Exit;
    }

    ValidateConvList(hConvList);

    hConvListOld = hConvList;
    pcoi = (PCONV_INFO)ConnectConv(pcii,
            LATOM_FROM_HSZ(hszService),
            LATOM_FROM_HSZ(hszTopic),
            hwndTarget,
            (pcii->afCmd & (CBF_FAIL_SELFCONNECTIONS | CBF_FAIL_CONNECTIONS)) ?
                pcii->hwndMother : 0,
            pCC,
            hConvListOld,
            CLST_MULT_INITIALIZING);

    if (pcoi == NULL) {
        /*
         * no new connections made
         */
        SetLastDDEMLError(pcii, DMLERR_NO_CONV_ESTABLISHED);
        hConvListRet = hConvListOld;
        goto Exit;
    }

    /*
     * allocate or reallocate the hConvList hwnd list for later addition
     * If we already have a valid list, reuse the handle so we don't have
     * to alter the preexisting pcoi->hConvList values.
     */
    if (hConvListOld == 0) {
        pcl = (PCONVLIST)DDEMLAlloc(sizeof(CONVLIST));
        if (pcl == NULL) {
            SetLastDDEMLError(pcii, DMLERR_MEMORY_ERROR);
            DisconnectConv(pcoi);
            goto Exit;
        }
        // pcl->chwnd = 0; LPTR zero inits.

        hConvList = (HCONVLIST)CreateHandle((DWORD)pcl,
                HTYPE_CONVERSATION_LIST, InstFromHandle(pcii->hInstClient));
        if (hConvList == 0) {
            DDEMLFree(pcl);
            SetLastDDEMLError(pcii, DMLERR_MEMORY_ERROR);
            DisconnectConv(pcoi);
            goto Exit;
        }
    } else {
        pcl = (PCONVLIST)GetHandleData((HANDLE)hConvList);
        pcl = DDEMLReAlloc(pcl, sizeof(CONVLIST) + sizeof(HWND) * pcl->chwnd);
        if (pcl == NULL) {
            SetLastDDEMLError(pcii, DMLERR_MEMORY_ERROR);
            hConvListRet = hConvListOld;
            DisconnectConv(pcoi);
            goto Exit;
        }
        SetHandleData((HANDLE)hConvList, (DWORD)pcl);
    }

    ValidateConvList(hConvListOld);

    if (hConvListOld) {
        /*
         * remove duplicates from new conversations
         *
         * Although we tried to prevent duplicates from happening
         * within the initiate enumeration code, wild initiates or
         * servers responding with different service names than
         * requested could cause duplicates.
         */

        /* For each client window... */

        for (i = 0; i < pcl->chwnd; i++) {

        /* For each existing conversation in that window... */

            for (pcoiExisting = (PCONV_INFO)
                        GetWindowLong(pcl->ahwnd[i], GWL_PCI);
                    pcoi != NULL && pcoiExisting != NULL;
                    pcoiExisting = pcoiExisting->next) {

                if (!(pcoiExisting->state & ST_CONNECTED))
                    continue;

        /* For each new conversation... */

                for (pcoiNew = pcoi; pcoiNew != NULL; pcoiNew = pcoiNext) {

                    pcoiNext = pcoiNew->next;

        /* see if the new conversation duplicates the existing one */

                    if (!(pcoiNew->state & ST_CONNECTED))
                        continue;

                    UserAssert(((PCL_CONV_INFO)pcoiExisting)->hwndReconnect);
                    UserAssert(((PCL_CONV_INFO)pcoiNew)->hwndReconnect);

                    if (((PCL_CONV_INFO)pcoiExisting)->hwndReconnect ==
                                ((PCL_CONV_INFO)pcoiNew)->hwndReconnect &&
                            pcoiExisting->laTopic == pcoiNew->laTopic &&
                            pcoiExisting->laService == pcoiNew->laService) {
                        /*
                         * duplicate conversation - disconnection causes an unlink
                         */
                        if (pcoiNew == pcoi) {
                            /*
                             * We are freeing up the head of the list,
                             * Reset the head to the next guy.
                             */
                            pcoi = pcoiNext;
                        }
                        ValidateConvList(hConvList);
                        ShutdownConversation(pcoiNew, FALSE);
                        ValidateConvList(hConvList);
                        break;
                    }
                }
            }
        }

        for (pcoiExisting = pcoi; pcoiExisting != NULL; pcoiExisting = pcoiExisting->next) {
            /*
             * if these are all zombies - we DONT want to link it in!
             * This is possible because ShutdownConversation() leaves the critical section
             * and could allow responding terminates to come through.
             */
            if (pcoiExisting->state & ST_CONNECTED) {
                goto FoundOne;
            }
        }
        pcoi = NULL;    // abandon this guy - he will clean up in time.
FoundOne:
        /*
         * add new pcoi (if any are left) hwnd to ConvList hwnd list.
         */
        if (pcoi != NULL) {
            UserAssert(pcoi->hwndConv);
            pcl->ahwnd[pcl->chwnd] = pcoi->hwndConv;
            pcl->chwnd++;
            hConvListRet = hConvList;
        } else {
            hConvListRet = hConvListOld;
            if (!hConvListOld) {
                DestroyHandle((HANDLE)hConvList);
            }
        }


    } else {    // no hConvListOld

        UserAssert(pcoi->hwndConv);
        pcl->ahwnd[0] = pcoi->hwndConv;
        pcl->chwnd = 1;
        hConvListRet = hConvList;
    }

    if (pcoi != NULL) {
        /*
         * set hConvList field for all remaining new conversations.
         */
        UserAssert(hConvListRet);
        for (pcoiNew = pcoi; pcoiNew != NULL; pcoiNew = pcoiNew->next) {
            if (pcoiNew->state & ST_CONNECTED) {
                ((PCL_CONV_INFO)pcoiNew)->hConvList = hConvListRet;
            }
        }
    }

Exit:
    if (aNormalSvcName) {
        DeleteAtom(aNormalSvcName);
    }
    ValidateConvList(hConvListRet);
    LeaveDDECrit;
    return (hConvListRet);
}
Exemplo n.º 28
0
FAudioDevice* FAudioDeviceManager::CreateAudioDevice(uint32& HandleOut, bool bCreateNewDevice)
{
	// If we don't have an audio device module, then we can't create new audio devices.
	if (AudioDeviceModule == nullptr)
	{
		HandleOut = AUDIO_DEVICE_HANDLE_INVALID;
		return nullptr;
	}

	// If we are running without the editor, we only need one audio device.
	if (!GIsEditor)
	{
		if (NumActiveAudioDevices == 1)
		{
			FAudioDevice* MainAudioDevice = GEngine->GetMainAudioDevice();
			if (MainAudioDevice)
			{
				HandleOut = MainAudioDevice->DeviceHandle;
				return MainAudioDevice;
			}
			return nullptr;
		}
	}

	FAudioDevice* NewAudioDevice = nullptr;

	if (NumActiveAudioDevices < AUDIO_DEVICE_DEFAULT_ALLOWED_DEVICE_COUNT || (bCreateNewDevice && NumActiveAudioDevices < AUDIO_DEVICE_MAX_DEVICE_COUNT))
	{
		// Create the new audio device and make sure it succeeded
		NewAudioDevice = AudioDeviceModule->CreateAudioDevice();
		if (NewAudioDevice == nullptr)
		{
			HandleOut = AUDIO_DEVICE_HANDLE_INVALID;
			return nullptr;
		}

		// Now generation a new audio device handle for the device and store the
		// ptr to the new device in the array of audio devices.

		uint32 AudioDeviceIndex(AUDIO_DEVICE_HANDLE_INVALID);

		// First check to see if we should start recycling audio device indices, if not
		// then we add a new entry to the Generation array and generate a new index
		if (FreeIndicesSize > AUDIO_DEVICE_MINIMUM_FREE_AUDIO_DEVICE_INDICES)
		{
			FreeIndices.Dequeue(AudioDeviceIndex);
			--FreeIndicesSize;
			check(int32(AudioDeviceIndex) < Devices.Num());
			check(Devices[AudioDeviceIndex] == nullptr);
			Devices[AudioDeviceIndex] = NewAudioDevice;
		}
		else
		{
			// Add a zeroth generation entry in the Generation array, get a brand new
			// index and append the created device to the end of the Devices array

			Generations.Add(0);
			AudioDeviceIndex = Generations.Num() - 1;
			check(AudioDeviceIndex < (1 << AUDIO_DEVICE_HANDLE_INDEX_BITS));
			Devices.Add(NewAudioDevice);
		}

		HandleOut = CreateHandle(AudioDeviceIndex, Generations[AudioDeviceIndex]);

		// Store the handle on the audio device itself
		NewAudioDevice->DeviceHandle = HandleOut;
	}
	else
	{
		++NumWorldsUsingMainAudioDevice;
		FAudioDevice* MainAudioDevice = GEngine->GetMainAudioDevice();
		if (MainAudioDevice)
		{
			HandleOut = MainAudioDevice->DeviceHandle;
			NewAudioDevice = MainAudioDevice;
		}
	}

	++NumActiveAudioDevices;

	return NewAudioDevice;
}
Exemplo n.º 29
0
Arquivo: Os.c Projeto: broonie/ohNet
THandle OsNetworkCreate(OsContext* aContext, OsNetworkSocketType aSocketType)
{
    SOCKET socketH = socket(AF_INET, aSocketType, 0);
    OsNetworkHandle* handle = CreateHandle(aContext, socketH);
    return (THandle)handle;
}
Exemplo n.º 30
0
/***************************************************************************\
* FreeConversationResources
*
* Description:
* Used when: Client window is disconnected by app, Server window is
* disconnected by either side, or when a conversation is disconnected
* at Uninitialize time.
*
* This function releases all resources held by the pcoi and unlinks it
* from its host window pcoi chian. pcoi is freed once this return s.
*
* History:
* 12-21-91 sanfords Created.
\***************************************************************************/
VOID FreeConversationResources(
    PCONV_INFO pcoi)
{
    PADVISE_LINK paLink;
    PDDE_MESSAGE_QUEUE pdmq;
    PXACT_INFO pxi;

    CheckDDECritIn;

    /*
     * Don't free resources on locked conversations.
     */
    if (pcoi->cLocks > 0) {
        pcoi->state |= ST_FREE_CONV_RES_NOW;
        return;
    }

    /*
     * Don't free resources if a synchronous transaction is in effect!
     */
    pxi = pcoi->pxiOut;
    while (pxi != NULL) {
        if (pxi->flags & XIF_SYNCHRONOUS) {
            /*
             * This conversation is in a synchronous transaction.
             * Shutdown the modal loop FIRST, then call this when
             * the loop exits.
             */
            PostMessage(pcoi->hwndConv, WM_TIMER, TID_TIMEOUT, 0);
            pcoi->state |= ST_FREE_CONV_RES_NOW;
            return;
        }
        pxi = pxi->next;
    }

    /*
     * If this is an Intra-Process conversation that hasn't yet received
     * a terminate message, make it a zombie.  We will call this routine
     * again once the terminate arrives or when WaitForZombieTerminate() has
     * timed out waiting.
     */
    if (pcoi->state & ST_INTRA_PROCESS && !(pcoi->state & ST_TERMINATE_RECEIVED)) {
        DestroyHandle((HANDLE)pcoi->hConv);
        pcoi->hConv = (HCONV)CreateHandle((DWORD)pcoi, HTYPE_ZOMBIE_CONVERSATION,
                InstFromHandle(pcoi->hConv));
        UnlinkConvFromOthers(pcoi, TRUE);
        return;
    }

    /*
     * remove any transactions left in progress
     */
    while (pcoi->pxiOut != NULL) {
        (pcoi->pxiOut->pfnResponse)(pcoi->pxiOut, 0, 0);
    }

    /*
     * Throw away any incomming queued DDE messages.
     */
    while (pcoi->dmqOut != NULL) {

        pdmq = pcoi->dmqOut;
        DumpDDEMessage(!(pcoi->state & ST_INTRA_PROCESS), pdmq->msg, pdmq->lParam);
        pcoi->dmqOut = pcoi->dmqOut->next;
        if (pcoi->dmqOut == NULL) {
            pcoi->dmqIn = NULL;
        }
        DDEMLFree(pdmq);
    }

    //
    // Remove all link info
    //
    paLink = pcoi->aLinks;
    while (pcoi->cLinks) {
        if (pcoi->state & ST_CLIENT) {
            MONLINK(pcoi->pcii, FALSE, paLink->wType & XTYPF_NODATA,
                    pcoi->laService, pcoi->laTopic,
                    LocalToGlobalAtom(paLink->laItem),
                    paLink->wFmt, FALSE,
                    (HCONV)pcoi->hwndPartner, (HCONV)pcoi->hwndConv);
        } else {
            MONLINK(pcoi->pcii, FALSE, paLink->wType & XTYPF_NODATA,
                    pcoi->laService, pcoi->laTopic,
                    LocalToGlobalAtom(paLink->laItem),
                    paLink->wFmt, TRUE,
                    (HCONV)pcoi->hwndConv, (HCONV)pcoi->hwndPartner);
        }
        if (!(pcoi->state & ST_CLIENT)) {
            DeleteLinkCount(pcoi->pcii, paLink->pLinkCount);
        }
        DeleteAtom(paLink->laItem); // link structure copy
        paLink++;
        pcoi->cLinks--;
    }
    if (pcoi->aLinks) {
        DDEMLFree(pcoi->aLinks);
    }

    //
    // free atoms associated with this conv
    //
    DeleteAtom(pcoi->laService);
    DeleteAtom(pcoi->laTopic);
    if (pcoi->laServiceRequested) {
        DeleteAtom(pcoi->laServiceRequested);
    }

    UnlinkConvFromOthers(pcoi, FALSE);

    /*
     * invalidate app's conversation handle
     */
    DestroyHandle((HANDLE)pcoi->hConv);

    DDEMLFree(pcoi);
}