void FastMarch2D::Initialize() {
    static int ci, pi, flag;
	for(int i = 1; i <= Nx; i++)
	{
        //if(Done == 0)  f= 0: change --> -1^f = -1;           NO -->  0^f = 0; 1^f = 1;
        //if(Done == -1) f=-1: change -->  0^f = -1; 1^f = -2; NO --> -1^f = 0;
        //if(Done == 1)  f= 1: change --> -1^f = -2;           NO -->  0^f = 1; 1^f = 0;
        flag = grid[GI(i,1)].DoneFlag;
		for(int j = 2; j <= Ny; j++)
		{
            ci = GI(i,j);
            if((flag ^ grid[ci].DoneFlag) < 0)
            {
                pi = GI(i,j-1);
                flag = grid[ci].DoneFlag;
                if(flag >= 0) {
                    grid[ci].DoneFlag = 1;
                    AddClose(GI(i,j+1));
                    grid[ci].value = min(grid[ci].value, abs(h + grid[pi].value));
                }
                else {
                    grid[pi].DoneFlag = 1;
                    AddClose(GI(i,j-2));
                    grid[pi].value = min(grid[pi].value, abs(h + grid[ci].value));
                }
            }
        }
    }
    
	for(int j = 1; j <= Ny; j++)
	{
        flag = grid[GI(1,j)].DoneFlag;
		for(int i = 2; i <= Nx; i++)
		{
            ci = GI(i,j);
            if((flag ^ grid[ci].DoneFlag) < 0)
            {
                pi = GI(i-1,j);
                flag = grid[ci].DoneFlag;
                if(flag >= 0) {
                    grid[ci].DoneFlag = 1;
                    AddClose(GI(i+1,j));
                    grid[ci].value = min(grid[ci].value, abs(h + grid[pi].value));
                }
                else {
                    grid[pi].DoneFlag = 1;
                    AddClose(GI(i-2,j));
                    grid[pi].value = min(grid[pi].value, abs(h + grid[ci].value));
                }
            }
		}
	}
}
Exemplo n.º 2
0
int CIocpServer::CloseSock(SOCKET_OBJ *sock,bool close_delay) //关闭当前的客户端
{
	if(sock == NULL)
		return -1;

#ifdef DEBUG_IOCP
	_ASSERTE(sock->onclosed == 0);	//已经调用过OnClose()了!
	_ASSERTE(sock->freeed == 0);    //已经free掉了!
#endif

	if( ( sock->flag_close == 0 ) || (sock->s == INVALID_SOCKET))
		return -1;

	LOCK(&sock->cs);

	if(sock->s != INVALID_SOCKET)
	{
		sock->flag_close = 0; //设置关闭标志

		if(close_delay)
		{	  //延时关闭
			AddClose(sock,GetTickCount());
			shutdown(sock->s,SD_BOTH);
		}
		else 
		{			  //立即关闭
			SOCKET s = sock->s;
			sock->s = INVALID_SOCKET;
			closesocket(s);
		}
	}

	UNLOCK(&sock->cs);

	return 0;
}