Пример #1
0
void GLMesh::Init(const struct aiScene* pScene) {
  m_pScene = pScene;
  m_Meshes.resize(pScene->mNumMeshes);
  InitNode(m_pScene, m_pScene->mRootNode, aiMatrix4x4());
  LoadMeshTextures();
  ComputeDimensions();
}
Пример #2
0
void NodeButton::SetDisabledSelectedNode(INode* val, bool updateSize /*= false*/)
{
	RETURN_IF_EQUAL(mDisabledSelectedNode, val);
	DeleteChild(mDisabledSelectedNode);
	mDisabledSelectedNode = val;
	if (mDisabledSelectedNode!=nullptr)
	{
		InitNode(mDisabledSelectedNode);
		mDisabledSelectedNode->SetName(MEDUSA_PREFIX(DisabledSelected));

		AddChild(mDisabledSelectedNode);
		mDisabledSelectedNode->SetVisible(false);
	}

	if (mButtonState == ButtonState::DisabledSelected)
	{
		OnUpdateNode();
		if (updateSize&&mDisabledSelectedNode!=nullptr)
		{
			SetSize(mDisabledSelectedNode->Size());
		}
	}

	
}
Пример #3
0
// remove a node, clear all ack from this node and reset askret
void Net_CloseConnection(INT32 node)
{
	INT32 i;
	boolean forceclose = (node & FORCECLOSE) != 0;
	node &= ~FORCECLOSE;

	if (!node)
		return;

	nodes[node].flags |= CLOSE;

	// try to Send ack back (two army problem)
	if (GetAcktosend(node))
	{
		Net_SendAcks(node);
		Net_SendAcks(node);
	}

	// check if we are waiting for an ack from this node
	for (i = 0; i < MAXACKPACKETS; i++)
		if (ackpak[i].acknum && ackpak[i].destinationnode == node)
		{
			if (!forceclose)
				return; // connection will be closed when ack is returned
			else
				ackpak[i].acknum = 0;
		}

	InitNode(node);
	AbortSendFiles(node);
	I_NetFreeNodenum(node);
}
Пример #4
0
/* Make a new node and initialize to have all branch cells empty.
*/
Node_t *RTreeNewNode(RTree_t * rtp)
{
    register Node_t *n;

    rtp->NodeCount++;
    n = (Node_t *) malloc(sizeof(Node_t));
    InitNode(n);
    return n;
}
Пример #5
0
static void InitAck(void)
{
	INT32 i;

	for (i = 0; i < MAXACKPACKETS; i++)
		ackpak[i].acknum = 0;

	for (i = 0; i < MAXNETNODES; i++)
		InitNode(i);
}
static void BoundaryPMfinal(Node* (*lists)[2], int maxbits,
                       Node* leaves, int numsymbols, NodePool* pool, int index) {
  int lastcount = lists[index][1]->count;  /* Count of last chain of list. */

  Node* newchain = GetFreeNode(lists, maxbits, pool);
  Node* oldchain = lists[index][1];

  /* These are set up before the recursive calls below, so that there is a list
   pointing to the new node, to let the garbage collection know it's in use. */
  lists[index][0] = oldchain;
  lists[index][1] = newchain;

  size_t sum = lists[index - 1][0]->weight + lists[index - 1][1]->weight;
  if (lastcount < numsymbols && sum > leaves[lastcount].weight) {
    /* New leaf inserted in list, so count is incremented. */
    InitNode(leaves[lastcount].weight, lastcount + 1, oldchain->tail, newchain);
  } else {
    InitNode(sum, lastcount, lists[index - 1][1], newchain);
  }
}
RTREE_TEMPLATE
typename RTREE_QUAL::Node* RTREE_QUAL::AllocNode() {
    Node* newNode;
#ifdef RTREE_DONT_USE_MEMPOOLS
    newNode = new Node;
#else // RTREE_DONT_USE_MEMPOOLS
    // EXAMPLE
#endif // RTREE_DONT_USE_MEMPOOLS
    InitNode(newNode);
    return newNode;
}
int main(int argc, char *argv[]) {
	InitNode();
	InitTree();

	printf("- In-Order Tree Traversal\n\n");

	printf("[*] Method : Recursive\n");
	Recursive_Traverse(nBuf[0]->left); // head_node->left => parent

	printf("\n[*] Method : Stack\n");
	Stack_Traverse(nBuf[0]->left); // head_node->left => parent
}
Пример #9
0
static void InitAck(void)
{
	INT32 i;

#ifndef NONET
	for (i = 0; i < MAXACKPACKETS; i++)
		ackpak[i].acknum = 0;
#endif

	for (i = 0; i < MAXNETNODES; i++)
		InitNode(i);
}
// When the quad-tree manager is initialized, it instantiates the entire possible tree to avoid having to do a bunch of 
// time wasting news and deletes during runtime.
void QuadTreeManager::InitQuadTree(float left, float right, float top, float bottom, unsigned int maxDepth, unsigned int maxPerNode, RenderShape outlineTemplate)
{
	_maxPerNode = maxPerNode;
	_maxDepth = maxDepth;
	_outlineTemplate = outlineTemplate;
	_quadTree.resize(GetDepthIndex(maxDepth));
	_quadTree[0] = InitNode(0, 0, 0, left, right, top, bottom);
	int maxI = GetDepthIndex(maxDepth - 1);
	for (int i = 0; i < maxI; ++i)
	{
		InitChildren(i);
	}
}
static status_t
fs_read_vnode(fs_volume* _volume, ino_t vnodeID, fs_vnode* _node,
	int* _type, uint32* _flags, bool reenter)
{
	iso9660_volume* volume = (iso9660_volume*)_volume->private_volume;

	iso9660_inode* newNode = (iso9660_inode*)calloc(sizeof(iso9660_inode), 1);
	if (newNode == NULL)
		return B_NO_MEMORY;

	uint32 pos = vnodeID & 0x3fffffff;
	uint32 block = vnodeID >> 30;

	TRACE(("fs_read_vnode - block = %u, pos = %u, raw = %Lu node %p\n",
		(unsigned)block, (unsigned) pos, vnodeID, newNode));

	if (pos > volume->logicalBlkSize[FS_DATA_FORMAT]) {
		free(newNode);
		return B_BAD_VALUE;
	}

	char* data = (char*)block_cache_get(volume->fBlockCache, block);
	if (data == NULL) {
		free(newNode);
		return B_IO_ERROR;
	}

	status_t result = InitNode(volume, newNode, data + pos, NULL);
	block_cache_put(volume->fBlockCache, block);

	if (result < B_OK) {
		free(newNode);
		return result;
	}

	newNode->volume = volume;
	newNode->id = vnodeID;

	_node->private_node = newNode;
	_node->ops = &gISO9660VnodeOps;
	*_type = newNode->attr.stat[FS_DATA_FORMAT].st_mode
		& ~(S_IWUSR | S_IWGRP | S_IWOTH);
	*_flags = 0;

	if ((newNode->flags & ISO_IS_DIR) == 0) {
		newNode->cache = file_cache_create(volume->id, vnodeID,
			newNode->dataLen[FS_DATA_FORMAT]);
	}

	return B_OK;
}
Пример #12
0
void Insert(char *s,int now)
{
	for (char *c=s;*c;c++)
	{
		int d=GetNum(*c);
		if (!T[now].ch[d])
		{
			T[now].ch[d]=++Ttot;
			InitNode(Ttot,d);
		}
		now=T[now].ch[d];
	}
	T[now].flag=1;
}
Пример #13
0
void Main()
{
	Root=Ttot=1;
	InitNode(1,-1);
	for (int i=1;i<=N;++i)
	{
		scanf("%s",Buf);
		Insert(Buf,Root);
	}
	BuildAC();
	memset(F,60,sizeof(F));
	scanf("%s",S+1);
	int L=strlen(S+1);
	for (int i=1;i<=L;++i)
	{
		D[i]=GetNum(S[i]);
	}
	F[0][1]=0;
	int Qh=0,Qt=1;Q[1][0]=0;Q[1][1]=1;
	inQ[0][1]=1;
	int Ans=F[1][1];
	while (Qh!=Qt)
	{
		++Qh;int i=Q[Qh][0],j=Q[Qh][1];
		for (int k=0;k<4;++k)
		{
			int nj=T[j].ch[k],w=(D[i+1]==k)?0:1;
			if (!nj) nj=Root;
			if (T[nj].flag) continue;
			if (F[i+1][nj]>F[i][j]+w)
			{
				F[i+1][nj]=F[i][j]+w;
				if (i+1==L)
				{
					if (Ans>F[i+1][nj]) Ans=F[i+1][nj];
					continue;
				}
				if (!inQ[i+1][nj])
				{
					inQ[i+1][nj]=1;
					++Qt;Q[Qt][0]=i+1;Q[Qt][1]=nj;
				}
			}
		}
		inQ[i][j]=0;
	}
	if (Ans==1010580540) puts("-1");
	else printf("%d\n",Ans);
}
Пример #14
0
FileNode_t CFileList::createNodeInfo(string szFilePath)
{
	FileNode_t	node;

	InitNode(node);
    char fpath[1024];
    sprintf(fpath, "%s",szFilePath.data());
    
    node.filepath=fpath;
    
    
     CheckPlatform(node, szFilePath);

	return node;
}
Пример #15
0
NodeCarDriver::NodeCarDriver(const Uri& uri) {
  debug_level_ = 0;
  device_id_ = uri.properties.Get<std::string>("id", "NodeCar");
  sim_name_ = uri.properties.Get<std::string>("sim", "LocalSim");
  device_name_ = uri.properties.Get<std::string>("name", device_id_);
  node_topic_ = device_name_;
  bool initDone = InitNode();
  initDone = RegisterInHost(uri);
  if (!initDone) {
    LOG(ERROR) << "Could not initialize the node or register the controller "
               << "in Simulator. The messages printed above should "
               << "be helpful.";
  } else {
    LOG(debug_level_) << "SUCCESS: NodeCar initialization";
  }
}
Пример #16
0
void GLMesh::InitNode(const struct aiScene* sc, const struct aiNode* nd,
                      const aiMatrix4x4& mTransformation) {
  aiMatrix4x4 trans = mTransformation * nd->mTransformation;
  // draw all meshes assigned to this node
  for (unsigned int n = 0; n < nd->mNumMeshes; ++n) {
    const struct aiMesh* mesh = m_pScene->mMeshes[nd->mMeshes[n]];

    InitMesh(m_uMeshCount, mesh, trans);
    m_uMeshCount++;
  }

  // draw all children
  for (unsigned int n = 0; n < nd->mNumChildren; ++n) {
    InitNode(sc, nd->mChildren[n], trans);
  }
}
Пример #17
0
void 
draw_loading()
{
  draw_background(0);

  draw_icon(ICON_FINDER, ICON_X1, ICON_Y);
  draw_string(ICON_X1 + 12, ICON_STRING_Y, "FINDER", FONT_COLOR);
  draw_icon(ICON_PHOTO, ICON_X2, ICON_Y);
  draw_string(ICON_X2 + 12, ICON_STRING_Y, "PHOTO", FONT_COLOR);
  draw_icon(ICON_TEXT, ICON_X3, ICON_Y);
  draw_string(ICON_X3 + 20, ICON_STRING_Y, "TEXT", FONT_COLOR);
  draw_icon(ICON_GAME, ICON_X4, ICON_Y);
  draw_string(ICON_X4 + 17, ICON_STRING_Y, "GAME", FONT_COLOR);
  draw_icon(ICON_DRAW, ICON_X5, ICON_Y);
  draw_string(ICON_X5 + 17, ICON_STRING_Y, "DRAW", FONT_COLOR);
  draw_icon(ICON_SETTING, ICON_X6, ICON_Y);
  draw_string(ICON_X6 + 8, ICON_STRING_Y, "SETTING", FONT_COLOR);

  display_to_screen(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  draw_mouse(ori_x_mouse, ori_y_mouse);

  InitNode();
  InitWindow();
}
Пример #18
0
int ZopfliLengthLimitedCodeLengths(
    const size_t* frequencies, int n, int maxbits, unsigned* bitlengths) {
  Node* pool;
  int i;
  int numsymbols = 0;  /* Amount of symbols with frequency > 0. */
  int numBoundaryPMRuns;
  Node* nodes;
  unsigned char stack[16];

  /* Array of lists of chains. Each list requires only two lookahead chains at
  a time, so each list is a array of two Node*'s. */
  Node* (*lists)[2];

  /* One leaf per symbol. Only numsymbols leaves will be used. */
  Node* leaves = (Node*)malloc(n * sizeof(*leaves));

  /* Initialize all bitlengths at 0. */
  for (i = 0; i < n; i++) {
    bitlengths[i] = 0;
  }

  /* Count used symbols and place them in the leaves. */
  for (i = 0; i < n; i++) {
    if (frequencies[i]) {
      leaves[numsymbols].weight = frequencies[i];
      leaves[numsymbols].count = i;  /* Index of symbol this leaf represents. */
      numsymbols++;
    }
  }

  /* Check special cases and error conditions. */
  if ((1 << maxbits) < numsymbols) {
    free(leaves);
    return 1;  /* Error, too few maxbits to represent symbols. */
  }
  if (numsymbols == 0) {
    free(leaves);
    return 0;  /* No symbols at all. OK. */
  }
  if (numsymbols == 1) {
    bitlengths[leaves[0].count] = 1;
    free(leaves);
    return 0;  /* Only one symbol, give it bitlength 1, not 0. OK. */
  }
  if (numsymbols == 2) {
    bitlengths[leaves[0].count]++;
    bitlengths[leaves[1].count]++;
    free(leaves);
    return 0;
  }

  /* Sort the leaves from lightest to heaviest. Add count into the same
  variable for stable sorting. */
  for (i = 0; i < numsymbols; i++) {
    if (leaves[i].weight >=
        ((size_t)1 << (sizeof(leaves[0].weight) * CHAR_BIT - 9))) {
      free(leaves);
      return 1;  /* Error, we need 9 bits for the count. */
    }
    leaves[i].weight = (leaves[i].weight << 9) | leaves[i].count;
  }
  qsort(leaves, numsymbols, sizeof(Node), LeafComparator);
  for (i = 0; i < numsymbols; i++) {
    leaves[i].weight >>= 9;
  }

  if (numsymbols - 1 < maxbits) {
    maxbits = numsymbols - 1;
  }

  /* Initialize node memory pool. */
  nodes = (Node*)malloc(maxbits * 2 * numsymbols * sizeof(Node));
  pool = nodes;

  lists = (Node* (*)[2])malloc(maxbits * sizeof(*lists));
  InitLists(pool, leaves, maxbits, lists);
  pool += 2;

  /* In the last list, 2 * numsymbols - 2 active chains need to be created. Two
  are already created in the initialization. Each BoundaryPM run creates one. */
  numBoundaryPMRuns = 2 * numsymbols - 4;
  for (i = 0; i < numBoundaryPMRuns - 1; i++) {
    /*
    Performs a Boundary Package-Merge step. Puts a new chain in the given list. The
    new chain is, depending on the weights, a leaf or a combination of two chains
    from the previous list.
    */
    unsigned stackpos;
    stack[0] = maxbits - 1;

    for (stackpos = 0; ;) {
      unsigned char index = stack[stackpos];

      int lastcount = lists[index][1]->count;  /* Count of last chain of list. */

      Node* newchain = pool++;
      Node* oldchain = lists[index][1];
      size_t sum;

      /* These are set up before the recursive calls below, so that there is a list
      pointing to the new node, to let the garbage collection know it's in use. */
      lists[index][0] = oldchain;
      lists[index][1] = newchain;

      sum = lists[index - 1][0]->weight + lists[index - 1][1]->weight;

      if (lastcount < numsymbols && sum > leaves[lastcount].weight) {
        /* New leaf inserted in list, so count is incremented. */
        InitNode(leaves[lastcount].weight, lastcount + 1, oldchain->tail, newchain);
      } else {
        InitNode(sum, lastcount, lists[index - 1][1], newchain);
        /* Two lookahead chains of previous list used up, create new ones. */
        if (index == 1) {
          if (lists[0][1]->count < numsymbols) {
            lastcount = lists[0][1]->count;
            lists[0][0] = lists[0][1];
            lists[0][1] = pool++;
            InitNode(leaves[lastcount].weight, lastcount + 1, 0, lists[0][1]);
            lastcount++;
            if(lastcount < numsymbols){
              lists[0][0] = lists[0][1];
              lists[0][1] = pool++;
              InitNode(leaves[lastcount].weight, lastcount + 1, 0, lists[0][1]);
            }
          }
        }
        else {
          stack[stackpos++] = index - 1;
          stack[stackpos++] = index - 1;
        }
      }
      if (!stackpos--) {
        break;
      }
    }
  }
  BoundaryPMFinal(lists, leaves, numsymbols, pool, maxbits - 1);

  ExtractBitLengths(lists[maxbits - 1][1], leaves, bitlengths);

  free(lists);
  free(leaves);
  free(nodes);
  return 0;  /* OK. */
}
Пример #19
0
/*!	Reads in a single directory entry and fills in the values in the
	dirent struct. Uses the cookie to keep track of the current block
	and position within the block. Also uses the cookie to determine when
	it has reached the end of the directory file.
*/
status_t
ISOReadDirEnt(iso9660_volume *volume, dircookie *cookie, struct dirent *dirent,
	size_t bufferSize)
{
	int	result = B_NO_ERROR;
	bool done = false;

	TRACE(("ISOReadDirEnt - ENTER\n"));

	while (!done) {
		off_t totalRead = cookie->pos + (cookie->block - cookie->startBlock)
			* volume->logicalBlkSize[FS_DATA_FORMAT];

		// If we're at the end of the data in a block, move to the next block.
		char *blockData;
		while (true) {
			blockData
				= (char*)block_cache_get(volume->fBlockCache, cookie->block);
			if (blockData != NULL && *(blockData + cookie->pos) == 0) {
				// NULL data, move to next block.
				block_cache_put(volume->fBlockCache, cookie->block);
				blockData = NULL;
				totalRead
					+= volume->logicalBlkSize[FS_DATA_FORMAT] - cookie->pos;
				cookie->pos = 0;
				cookie->block++;
			} else
				break;

			if (totalRead >= cookie->totalSize)
				break;
		}

		off_t cacheBlock = cookie->block;

		if (blockData != NULL && totalRead < cookie->totalSize) {
			iso9660_inode node;
			size_t bytesRead = 0;
			result = InitNode(volume, &node, blockData + cookie->pos,
				&bytesRead);

			// if we hit an entry that we don't support, we just skip it
			if (result != B_OK && result != B_NOT_SUPPORTED)
				break;

			if (result == B_OK && (node.flags & ISO_IS_ASSOCIATED_FILE) == 0) {
				size_t nameBufferSize = bufferSize - sizeof(struct dirent);

				dirent->d_dev = volume->id;
				dirent->d_ino = ((ino_t)cookie->block << 30)
					+ (cookie->pos & 0x3fffffff);
				dirent->d_reclen = sizeof(struct dirent) + node.name_length + 1;

				if (node.name_length <= nameBufferSize) {
					// need to do some size checking here.
					strlcpy(dirent->d_name, node.name, node.name_length + 1);
					TRACE(("ISOReadDirEnt  - success, name is %s, block %Ld, "
						"pos %Ld, inode id %Ld\n", dirent->d_name, cookie->block,
						cookie->pos, dirent->d_ino));
				} else {
					// TODO: this can be just normal if we support reading more
					// than one entry.
					TRACE(("ISOReadDirEnt - ERROR, name %s does not fit in "
						"buffer of size %d\n", node.name, (int)nameBufferSize));
					result = B_BAD_VALUE;
				}

				done = true;
			}

			cookie->pos += bytesRead;

			if (cookie->pos == volume->logicalBlkSize[FS_DATA_FORMAT]) {
				cookie->pos = 0;
				cookie->block++;
			}
		} else {
			if (totalRead >= cookie->totalSize)
				result = B_ENTRY_NOT_FOUND;
			else
				result = B_NO_MEMORY;
			done = true;
		}

		if (blockData != NULL)
			block_cache_put(volume->fBlockCache, cacheBlock);
	}

	TRACE(("ISOReadDirEnt - EXIT, result is %s, vnid is %Lu\n",
		strerror(result), dirent->d_ino));

	return result;
}
Пример #20
0
status_t
ISOMount(const char *path, uint32 flags, iso9660_volume **_newVolume,
	bool allowJoliet)
{
	// path: 		path to device (eg, /dev/disk/scsi/030/raw)
	// partition:	partition number on device ????
	// flags:		currently unused

	// determine if it is an ISO volume.
	char buffer[ISO_PVD_SIZE];
	bool done = false;
	bool isISO = false;
	off_t offset = 0x8000;
	ssize_t retval;
	partition_info partitionInfo;
	int deviceBlockSize, multiplier;
	iso9660_volume *volume;

	(void)flags;

	TRACE(("ISOMount - ENTER\n"));

	volume = (iso9660_volume *)calloc(sizeof(iso9660_volume), 1);
	if (volume == NULL) {
		TRACE(("ISOMount - mem error \n"));
		return B_NO_MEMORY;
	}

	memset(&partitionInfo, 0, sizeof(partition_info));

	/* open and lock the device */
	volume->fdOfSession = open(path, O_RDONLY);

	/* try to open the raw device to get access to the other sessions as well */
	if (volume->fdOfSession >= 0) {
		if (ioctl(volume->fdOfSession, B_GET_PARTITION_INFO, &partitionInfo) < 0) {
			TRACE(("B_GET_PARTITION_INFO: ioctl returned error\n"));
			strcpy(partitionInfo.device, path);
		}
		TRACE(("ISOMount: open device/file \"%s\"\n", partitionInfo.device));

		volume->fd = open(partitionInfo.device, O_RDONLY);
	}

	if (volume->fdOfSession < 0 || volume->fd < 0) {
		close(volume->fd);
		close(volume->fdOfSession);

		TRACE(("ISO9660 ERROR - Unable to open <%s>\n", path));
		free(volume);
		return B_BAD_VALUE;
	}

	deviceBlockSize = get_device_block_size(volume->fdOfSession);
	if (deviceBlockSize < 0)  {
		TRACE(("ISO9660 ERROR - device block size is 0\n"));
		close(volume->fd);
		close(volume->fdOfSession);

		free(volume);
		return B_BAD_VALUE;
	}

	volume->joliet_level = 0;
	while (!done && offset < 0x10000) {
		retval = read_pos(volume->fdOfSession, offset, (void*)buffer,
			ISO_PVD_SIZE);
		if (retval < ISO_PVD_SIZE) {
			isISO = false;
			break;
		}

		if (strncmp(buffer + 1, kISO9660IDString, 5) == 0) {
			if (*buffer == 0x01 && !isISO) {
				// ISO_VD_PRIMARY
				off_t maxBlocks;

				TRACE(("ISOMount: Is an ISO9660 volume, initting rec\n"));

				InitVolDesc(volume, buffer);
				strncpy(volume->devicePath,path,127);
				volume->id = ISO_ROOTNODE_ID;
				TRACE(("ISO9660: volume->blockSize = %d\n", volume->logicalBlkSize[FS_DATA_FORMAT]));

				multiplier = deviceBlockSize / volume->logicalBlkSize[FS_DATA_FORMAT];
				TRACE(("ISOMount: block size multiplier is %d\n", multiplier));

				// if the session is on a real device, size != 0
				if (partitionInfo.size != 0) {
					maxBlocks = (partitionInfo.size + partitionInfo.offset)
						/ volume->logicalBlkSize[FS_DATA_FORMAT];
				} else
					maxBlocks = volume->volSpaceSize[FS_DATA_FORMAT];

				/* Initialize access to the cache so that we can do cached i/o */
				TRACE(("ISO9660: cache init: dev %d, max blocks %Ld\n", volume->fd, maxBlocks));
				volume->fBlockCache = block_cache_create(volume->fd, maxBlocks,
					volume->logicalBlkSize[FS_DATA_FORMAT], true);
				isISO = true;
			} else if (*buffer == 0x02 && isISO && allowJoliet) {
				// ISO_VD_SUPPLEMENTARY

				// JOLIET extension
				// test escape sequence for level of UCS-2 characterset
			    if (buffer[88] == 0x25 && buffer[89] == 0x2f) {
					switch (buffer[90]) {
						case 0x40: volume->joliet_level = 1; break;
						case 0x43: volume->joliet_level = 2; break;
						case 0x45: volume->joliet_level = 3; break;
					}

					TRACE(("ISO9660 Extensions: Microsoft Joliet Level %d\n", volume->joliet_level));

					// Because Joliet-stuff starts at other sector,
					// update root directory record.
					if (volume->joliet_level > 0) {
						InitNode(volume, &volume->rootDirRec, &buffer[156],
							NULL);
					}
				}
			} else if (*(unsigned char *)buffer == 0xff) {
				// ISO_VD_END
				done = true;
			} else
				TRACE(("found header %d\n",*buffer));
		}
		offset += 0x800;
	}

	if (!isISO) {
		// It isn't an ISO disk.
		close(volume->fdOfSession);
		close(volume->fd);
		free(volume);

		TRACE(("ISOMount: Not an ISO9660 volume!\n"));
		return B_BAD_VALUE;
	}

	TRACE(("ISOMount - EXIT, returning %p\n", volume));
	*_newVolume = volume;
	return B_OK;
}
Пример #21
0
static status_t
parse_rock_ridge(iso9660_volume* volume, iso9660_inode* node, char* buffer,
	char* end, bool relocated)
{
	// Now we're at the start of the rock ridge stuff
	char* altName = NULL;
	char* slName = NULL;
	uint16 altNameSize = 0;
	uint16 slNameSize = 0;
	uint8 slFlags = 0;
	uint8 length = 0;
	bool done = false;

	TRACE(("RR: Start of extensions at %p\n", buffer));

	while (!done) {
		buffer += length;
		if (buffer + 2 >= end)
			break;
		length = *(uint8*)(buffer + 2);
		if (buffer + length > end)
			break;
		if (length == 0)
			break;

		switch (((int)buffer[0] << 8) + buffer[1]) {
			// Stat structure stuff
			case 'PX':
			{
				uint8 bytePos = 3;
				TRACE(("RR: found PX, length %u\n", length));
				node->attr.pxVer = *(uint8*)(buffer + bytePos++);

				// st_mode
				node->attr.stat[LSB_DATA].st_mode
					= *(mode_t*)(buffer + bytePos);
				bytePos += 4;
				node->attr.stat[MSB_DATA].st_mode
					= *(mode_t*)(buffer + bytePos);
				bytePos += 4;

				// st_nlink
				node->attr.stat[LSB_DATA].st_nlink
					= *(nlink_t*)(buffer+bytePos);
				bytePos += 4;
				node->attr.stat[MSB_DATA].st_nlink
					= *(nlink_t*)(buffer + bytePos);
				bytePos += 4;

				// st_uid
				node->attr.stat[LSB_DATA].st_uid
					= *(uid_t*)(buffer + bytePos);
				bytePos += 4;
				node->attr.stat[MSB_DATA].st_uid
					= *(uid_t*)(buffer + bytePos);
				bytePos += 4;

				// st_gid
				node->attr.stat[LSB_DATA].st_gid
					= *(gid_t*)(buffer + bytePos);
				bytePos += 4;
				node->attr.stat[MSB_DATA].st_gid
					= *(gid_t*)(buffer + bytePos);
				bytePos += 4;
				break;
			}

			case 'PN':
				TRACE(("RR: found PN, length %u\n", length));
				break;

			// Symbolic link info
			case 'SL':
			{
				uint8 bytePos = 3;
				uint8 lastCompFlag = 0;
				uint8 addPos = 0;
				bool slDone = false;
				bool useSeparator = true;

				TRACE(("RR: found SL, length %u\n", length));
				TRACE(("Buffer is at %p\n", buffer));
				TRACE(("Current length is %u\n", slNameSize));
				//kernel_debugger("");
				node->attr.slVer = *(uint8*)(buffer + bytePos++);
				slFlags = *(uint8*)(buffer + bytePos++);

				TRACE(("sl flags are %u\n", slFlags));
				while (!slDone && bytePos < length) {
					uint8 compFlag = *(uint8*)(buffer + bytePos++);
					uint8 compLen = *(uint8*)(buffer + bytePos++);

					if (slName == NULL)
						useSeparator = false;

					addPos = slNameSize;

					TRACE(("sl comp flags are %u, length is %u\n", compFlag, compLen));
					TRACE(("Current name size is %u\n", slNameSize));

					switch (compFlag) {
						case SLCP_CONTINUE:
							useSeparator = false;
						default:
							// Add the component to the total path.
							slNameSize += compLen;
							if (useSeparator)
								slNameSize++;
							slName = (char*)realloc(slName,
								slNameSize + 1);
							if (slName == NULL)
								return B_NO_MEMORY;

							if (useSeparator) {
								TRACE(("Adding separator\n"));
								slName[addPos++] = '/';
							}

							TRACE(("doing memcopy of %u bytes at offset %d\n", compLen, addPos));
							memcpy(slName + addPos, buffer + bytePos,
								compLen);

							addPos += compLen;
							useSeparator = true;
							break;

						case SLCP_CURRENT:
							TRACE(("InitNode - found link to current directory\n"));
							slNameSize += 2;
							slName = (char*)realloc(slName,
								slNameSize + 1);
							if (slName == NULL)
								return B_NO_MEMORY;

							memcpy(slName + addPos, "./", 2);
							useSeparator = false;
							break;

						case SLCP_PARENT:
							slNameSize += 3;
							slName = (char*)realloc(slName,
								slNameSize + 1);
							if (slName == NULL)
								return B_NO_MEMORY;

							memcpy(slName + addPos, "../", 3);
							useSeparator = false;
							break;

						case SLCP_ROOT:
							TRACE(("InitNode - found link to root directory\n"));
							slNameSize += 1;
							slName = (char*)realloc(slName,
								slNameSize + 1);
							if (slName == NULL)
								return B_NO_MEMORY;
							memcpy(slName + addPos, "/", 1);
							useSeparator = false;
							break;

						case SLCP_VOLROOT:
							slDone = true;
							break;

						case SLCP_HOST:
							slDone = true;
							break;
					}
					slName[slNameSize] = '\0';
					lastCompFlag = compFlag;
					bytePos += compLen;
					TRACE(("Current sl name is \'%s\'\n", slName));
				}
				node->attr.slName = slName;
				TRACE(("InitNode = symlink name is \'%s\'\n", slName));
				break;
			}

			// Altername name
			case 'NM':
			{
				uint8 bytePos = 3;
				uint8 flags = 0;
				uint16 oldEnd = altNameSize;

				altNameSize += length - 5;
				altName = (char*)realloc(altName, altNameSize + 1);
				if (altName == NULL)
					return B_NO_MEMORY;

				TRACE(("RR: found NM, length %u\n", length));
				// Read flag and version.
				node->attr.nmVer = *(uint8 *)(buffer + bytePos++);
				flags = *(uint8 *)(buffer + bytePos++);

				TRACE(("RR: nm buffer is %s, start at %p\n", (buffer + bytePos), buffer + bytePos));

				// Build the file name.
				memcpy(altName + oldEnd, buffer + bytePos, length - 5);
				altName[altNameSize] = '\0';
				TRACE(("RR: alt name is %s\n", altName));

				// If the name is not continued in another record, update
				// the record name.
				if (!(flags & NM_CONTINUE)) {
					// Get rid of the ISO name, replace with RR name.
					if (node->name != NULL)
						free(node->name);
					node->name = altName;
					node->name_length = altNameSize;
				}
				break;
			}

			// Deep directory record masquerading as a file.
			case 'CL':
			{
				TRACE(("RR: found CL, length %u\n", length));
				// Reinitialize the node with the information at the
				// "." entry of the pointed to directory data
				node->startLBN[LSB_DATA] = *(uint32*)(buffer+4);
				node->startLBN[MSB_DATA] = *(uint32*)(buffer+8);

				char* buffer = (char*)block_cache_get(volume->fBlockCache,
					node->startLBN[FS_DATA_FORMAT]);
				if (buffer == NULL)
					break;

				InitNode(volume, node, buffer, NULL, true);
				block_cache_put(volume->fBlockCache,
					node->startLBN[FS_DATA_FORMAT]);
				break;
			}

			case 'PL':
				TRACE(("RR: found PL, length %u\n", length));
				break;

			case 'RE':
				// Relocated directory, we should skip.
				TRACE(("RR: found RE, length %u\n", length));
				if (!relocated)
					return B_NOT_SUPPORTED;
				break;

			case 'TF':
				TRACE(("RR: found TF, length %u\n", length));
				break;

			case 'RR':
				TRACE(("RR: found RR, length %u\n", length));
				break;

			case 'SF':
				TRACE(("RR: found SF, sparse files not supported!\n"));
				// TODO: support sparse files
				return B_NOT_SUPPORTED;

			default:
				if (buffer[0] == '\0') {
					TRACE(("RR: end of extensions\n"));
					done = true;
				} else
					TRACE(("RR: Unknown tag %c%c\n", buffer[0], buffer[1]));
				break;
		}
	}

	return B_OK;
}
Пример #22
0
static status_t
InitVolDesc(iso9660_volume *volume, char *buffer)
{
	TRACE(("InitVolDesc - ENTER\n"));

	volume->volDescType = *(uint8 *)buffer++;

	volume->stdIDString[5] = '\0';
	strncpy(volume->stdIDString, buffer, 5);
	buffer += 5;

	volume->volDescVersion = *(uint8 *)buffer;
	buffer += 2; // 8th byte unused

	volume->systemIDString[32] = '\0';
	strncpy(volume->systemIDString, buffer, 32);
	buffer += 32;
	TRACE(("InitVolDesc - system id string is %s\n", volume->systemIDString));

	volume->volIDString[32] = '\0';
	strncpy(volume->volIDString, buffer, 32);
	buffer += (32 + 80-73 + 1);	// bytes 80-73 unused
	TRACE(("InitVolDesc - volume id string is %s\n", volume->volIDString));

	volume->volSpaceSize[LSB_DATA] = *(uint32 *)buffer;
	buffer += 4;
	volume->volSpaceSize[MSB_DATA] = *(uint32 *)buffer;
	buffer+= (4 + 120-89 + 1); 		// bytes 120-89 unused

	volume->volSetSize[LSB_DATA] = *(uint16*)buffer;
	buffer += 2;
	volume->volSetSize[MSB_DATA] = *(uint16*)buffer;
	buffer += 2;

	volume->volSeqNum[LSB_DATA] = *(uint16*)buffer;
	buffer += 2;
	volume->volSeqNum[MSB_DATA] = *(uint16*)buffer;
	buffer += 2;

	volume->logicalBlkSize[LSB_DATA] = *(uint16*)buffer;
	buffer += 2;
	volume->logicalBlkSize[MSB_DATA] = *(uint16*)buffer;
	buffer += 2;

	volume->pathTblSize[LSB_DATA] = *(uint32*)buffer;
	buffer += 4;
	volume->pathTblSize[MSB_DATA] = *(uint32*)buffer;
	buffer += 4;

	volume->lPathTblLoc[LSB_DATA] = *(uint16*)buffer;
	buffer += 2;
	volume->lPathTblLoc[MSB_DATA] = *(uint16*)buffer;
	buffer += 2;

	volume->optLPathTblLoc[LSB_DATA] = *(uint16*)buffer;
	buffer += 2;
	volume->optLPathTblLoc[MSB_DATA] = *(uint16*)buffer;
	buffer += 2;

	volume->mPathTblLoc[LSB_DATA] = *(uint16*)buffer;
	buffer += 2;
	volume->mPathTblLoc[MSB_DATA] = *(uint16*)buffer;
	buffer += 2;

	volume->optMPathTblLoc[LSB_DATA] = *(uint16*)buffer;
	buffer += 2;
	volume->optMPathTblLoc[MSB_DATA] = *(uint16*)buffer;
	buffer += 2;

	// Fill in directory record.
	volume->joliet_level = 0;
	InitNode(volume, &volume->rootDirRec, buffer, NULL);

	volume->rootDirRec.id = ISO_ROOTNODE_ID;
	buffer += 34;

	volume->volSetIDString[128] = '\0';
	strncpy(volume->volSetIDString, buffer, 128);
	buffer += 128;
	TRACE(("InitVolDesc - volume set id string is %s\n", volume->volSetIDString));

	volume->pubIDString[128] = '\0';
	strncpy(volume->pubIDString, buffer, 128);
	buffer += 128;
	TRACE(("InitVolDesc - volume pub id string is %s\n", volume->pubIDString));

	volume->dataPreparer[128] = '\0';
	strncpy(volume->dataPreparer, buffer, 128);
	buffer += 128;
	TRACE(("InitVolDesc - volume dataPreparer string is %s\n", volume->dataPreparer));

	volume->appIDString[128] = '\0';
	strncpy(volume->appIDString, buffer, 128);
	buffer += 128;
	TRACE(("InitVolDesc - volume app id string is %s\n", volume->appIDString));

	volume->copyright[38] = '\0';
	strncpy(volume->copyright, buffer, 38);
	buffer += 38;
	TRACE(("InitVolDesc - copyright is %s\n", volume->copyright));

	volume->abstractFName[38] = '\0';
	strncpy(volume->abstractFName, buffer, 38);
	buffer += 38;

	volume->biblioFName[38] = '\0';
	strncpy(volume->biblioFName, buffer, 38);
	buffer += 38;

	init_volume_date(&volume->createDate, buffer);
	buffer += 17;

	init_volume_date(&volume->modDate, buffer);
	buffer += 17;

	init_volume_date(&volume->expireDate, buffer);
	buffer += 17;

	init_volume_date(&volume->effectiveDate, buffer);
	buffer += 17;

	volume->fileStructVers = *(uint8*)buffer;
	return B_OK;
}
Пример #23
0
int main(int argc, char *argv[])
{
    struct passwd   *pw;
    int		    i, rc; 
    socklen_t	    addrlen = sizeof(struct sockaddr_in6);
    char	    str[INET6_ADDRSTRLEN];
#ifdef  HAVE_GEOIP_H
    GeoIP   *gi;
#endif

    /*
     * The next trick is to supply a fake environment variable
     * FTND_ROOT because this program is started from inetd.
     * This will setup the variable so InitConfig() will work.
     * The /etc/passwd must point to the correct homedirectory.
     */
    pw = getpwuid(geteuid());
    if (getenv("FTND_ROOT") == NULL) {
	envptr = xstrcpy((char *)"FTND_ROOT=");
	envptr = xstrcat(envptr, pw->pw_dir);
	putenv(envptr);
    }
    mypid = getpid();

    /*
     * Read the global configuration data, registrate connection
     */
    InitConfig();
    InitMsgs();
    InitUser();
    InitFidonet();
    InitNode();
    umask(002);
    memset(&usrconfig, 0, sizeof(usrconfig));

    t_start = time(NULL);
    InitClient(pw->pw_name, (char *)"ftnnntp", CFG.location, CFG.logfile, 
	    CFG.util_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
    Syslog(' ', "FTNNNTP v%s", VERSION);
    IsDoing("Loging in");

#ifdef	USE_NEWSGATE
    WriteError("FTNd is compiled for full newsgate, you cannot use ftnnntp!");
#endif

    /*
     * Catch all the signals we can, and ignore the rest.
     */
    for(i = 0; i < NSIG; i++) {

	if ((i == SIGINT) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM) || (i == SIGIOT))
	    signal(i, (void (*))die);
	else if (i == SIGCHLD)
	    signal(i, SIG_DFL);
	else if ((i != SIGKILL) && (i != SIGSTOP))
	    signal(i, SIG_IGN);
    }

    if ((rc = rawport()) != 0)
	WriteError("Unable to set raw mode");
    else {
	if (getpeername(0,(struct sockaddr*)&peeraddr6,&addrlen) == 0) {
	    /*
	     * Copy IPv4 part into the IPv6 structure. There has to be a better way
	     * to deal with mixed incoming sockets ???
	     */
	    memcpy(&peeraddr4, &peeraddr6, sizeof(struct sockaddr_in));
	    if ((peeraddr6.sin6_family == AF_INET6) && (inet_ntop(AF_INET6, &peeraddr6.sin6_addr, str, sizeof(str)))) {
		Syslog('+', "Incoming IPv6 connection from %s", str);
	    } else if ((peeraddr4.sin_family == AF_INET) && (inet_ntop(AF_INET, &peeraddr4.sin_addr, str, sizeof(str)))) {
		Syslog('+', "Incoming IPv4 connection from %s", str);
	    }

#ifdef  HAVE_GEOIP_H
	    _GeoIP_setup_dbfilename();
	    if (peeraddr6.sin6_family == AF_INET6) {
	    	if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION_V6)) {
		    if ((gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD)) != NULL) {
		    	geoiplookup(gi, str, GEOIP_COUNTRY_EDITION_V6);
		    }
		    GeoIP_delete(gi);
	    	}
	    } else if (peeraddr6.sin6_family == AF_INET) {
		if (GeoIP_db_avail(GEOIP_COUNTRY_EDITION)) {
		    if ((gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION, GEOIP_STANDARD)) != NULL) {
			geoiplookup(gi, str, GEOIP_COUNTRY_EDITION);
		    }
		    GeoIP_delete(gi);
		}
	    }
#endif
#ifdef	USE_NEWSGATE
	    send_nntp("400 Server closed");
#else
	    if (! check_free()) {
		send_nntp("400 Server closed");
	    } else {
		send_nntp("200 FTNNNTP v%s server ready -- posting allowed", VERSION);
		nntp();
	    }
#endif
	}
    }

    cookedport();

    die(0);
    return 0;
}
Пример #24
0
void CIntervalTree::DoInsert(const interval_type& interval, TTreeMapI value)
{
    _ASSERT(TTraits::IsNormal(interval));

    // ensure our tree covers specified interval
    if ( interval.GetTo() > GetMaxRootCoordinate() ) {
        // insert one more level on top
        if ( m_Root.m_Left || m_Root.m_Right || m_Root.m_NodeIntervals ) {
            // non empty tree, insert new root node
            do {
                TTreeNode* newLeft = AllocNode();
                // copy root node contents
                *newLeft = m_Root;
                // fill new root
                m_Root.m_Key = GetNextRootKey();
                m_Root.m_Left = newLeft;
                m_Root.m_Right = 0;
                m_Root.m_NodeIntervals = 0;
            } while ( interval.GetTo() > GetMaxRootCoordinate() );
        }
        else {
            // empty tree, just recalculate root
            do {
                m_Root.m_Key = GetNextRootKey();
            } while ( interval.GetTo() > GetMaxRootCoordinate() );
        }
    }

    TTreeNode* node = &m_Root;
    coordinate_type nodeSize = m_Root.m_Key;
    for ( ;; ) {
        coordinate_type key = node->m_Key;
        nodeSize = (nodeSize + 1) / 2;

        TTreeNode** nextPtr;
        coordinate_type nextKeyOffset;

        if ( interval.GetFrom() > key  ) {
            nextPtr = &node->m_Right;
            nextKeyOffset = nodeSize;
        }
        else if ( interval.GetTo() < key ) {
            nextPtr = &node->m_Left;
            nextKeyOffset = -nodeSize;
        }
        else {
            // found our tile
            TTreeNodeInts* nodeIntervals = node->m_NodeIntervals;
            if ( !nodeIntervals )
                node->m_NodeIntervals = nodeIntervals = CreateNodeIntervals();
            nodeIntervals->Insert(interval, value);
            return;
        }

        TTreeNode* next = *nextPtr;
        if ( !next ) // create new node
            (*nextPtr) = next = InitNode(AllocNode(), key + nextKeyOffset);

        _ASSERT(next->m_Key == key + nextKeyOffset);
        node = next;
    }
}
Пример #25
0
Node::Node(Geometry* Geometry)
	:m_Geometry(Geometry)
{
	m_Parent = NULL;
	InitNode(Geometry);
} // Constructor
Пример #26
0
void BattleGroundAV::Reset()
{
    BattleGround::Reset();
    // set the reputation and honor variables:
    bool isBGWeekend = BattleGroundMgr::IsBGWeekend(GetTypeID());

    m_HonorMapComplete    = (isBGWeekend) ? BG_AV_KILL_MAP_COMPLETE_HOLIDAY : BG_AV_KILL_MAP_COMPLETE;
    m_RepTowerDestruction = (isBGWeekend) ? BG_AV_REP_TOWER_HOLIDAY         : BG_AV_REP_TOWER;
    m_RepCaptain          = (isBGWeekend) ? BG_AV_REP_CAPTAIN_HOLIDAY       : BG_AV_REP_CAPTAIN;
    m_RepBoss             = (isBGWeekend) ? BG_AV_REP_BOSS_HOLIDAY          : BG_AV_REP_BOSS;
    m_RepOwnedGrave       = (isBGWeekend) ? BG_AV_REP_OWNED_GRAVE_HOLIDAY   : BG_AV_REP_OWNED_GRAVE;
    m_RepSurviveCaptain   = (isBGWeekend) ? BG_AV_REP_SURVIVING_CAPTAIN_HOLIDAY : BG_AV_REP_SURVIVING_CAPTAIN;
    m_RepSurviveTower     = (isBGWeekend) ? BG_AV_REP_SURVIVING_TOWER_HOLIDAY : BG_AV_REP_SURVIVING_TOWER;
    m_RepOwnedMine        = (isBGWeekend) ? BG_AV_REP_OWNED_MINE_HOLIDAY    : BG_AV_REP_OWNED_MINE;

    m_CaptainBuffTimer[0]    = (180000 + (urand(0,6) * 10000));
    m_CaptainBuffTimer[1]    = (180000 + (urand(0,6) * 10000));
    m_GeneralBuffTimer[0]    = 0;
    m_GeneralBuffTimer[1]    = 0;

    for(uint8 i = 0; i < BG_TEAMS_COUNT; i++)
    {
        for(uint8 j = 0; j < 9; j++)                        // 9 quests getting tracked
            m_Team_QuestStatus[i][j] = 0;
        m_TeamScores[i]         = BG_AV_SCORE_INITIAL_POINTS;
        m_IsInformedNearLose[i] = false;
        m_ActiveEvents[BG_AV_NodeEventCaptainDead_A + i] = BG_EVENT_NONE;
    }

    for(uint8 i = 0; i < BG_AV_MAX_MINES; i++)
    {
        m_Mine_Owner[i] = BG_AV_TEAM_NEUTRAL;
        m_Mine_PrevOwner[i] = m_Mine_Owner[i];
        m_ActiveEvents[BG_AV_MINE_BOSSES+ i] = BG_AV_TEAM_NEUTRAL;
        m_ActiveEvents[BG_AV_MINE_EVENT + i] = BG_AV_TEAM_NEUTRAL;
        m_Mine_Timer[i] = BG_AV_MINE_TICK_TIMER;
    }

    m_ActiveEvents[BG_AV_Smith_A] = 0;
    m_ActiveEvents[BG_AV_Smith_H] = 0;
    m_ActiveEvents[BG_AV_BOSS_SUMMON_MASTER_A] = 0;
    m_ActiveEvents[BG_AV_BOSS_SUMMON_MASTER_H] = 0;
    m_ActiveEvents[BG_AV_CAPTAIN_A] = 0;
    m_ActiveEvents[BG_AV_CAPTAIN_H] = 0;
    m_ActiveEvents[BG_AV_HERALD] = 0;
    m_ActiveEvents[BG_AV_BOSS_A] = 0;
    m_ActiveEvents[BG_AV_BOSS_H] = 0;
    for(BG_AV_Nodes i = BG_AV_NODES_DUNBALDAR_SOUTH; i <= BG_AV_NODES_FROSTWOLF_WTOWER; ++i)   // towers
    {
        uint8 tmp = i - BG_AV_NODES_DUNBALDAR_SOUTH;
        //marshall and warmaster of the own towers are spawned at the beginning
        m_ActiveEvents[BG_AV_MARSHAL_A_SOUTH + tmp] = 0;
        //marshall and warmaster of the enemy towers are despawned at the beginning
        m_ActiveEvents[BG_AV_MARSHAL_H_SOUTH + tmp] = 0;
        SpawnEvent(BG_AV_MARSHAL_H_SOUTH + tmp, 0, false);
    }

    for(BG_AV_Nodes i = BG_AV_NODES_FIRSTAID_STATION; i <= BG_AV_NODES_STONEHEART_GRAVE; ++i)   // alliance graves
        InitNode(i, BG_AV_TEAM_ALLIANCE, false);
    for(BG_AV_Nodes i = BG_AV_NODES_DUNBALDAR_SOUTH; i <= BG_AV_NODES_STONEHEART_BUNKER; ++i)   // alliance towers
        InitNode(i, BG_AV_TEAM_ALLIANCE, true);

    for(BG_AV_Nodes i = BG_AV_NODES_ICEBLOOD_GRAVE; i <= BG_AV_NODES_FROSTWOLF_HUT; ++i)        // horde graves
        InitNode(i, BG_AV_TEAM_HORDE, false);
    for(BG_AV_Nodes i = BG_AV_NODES_ICEBLOOD_TOWER; i <= BG_AV_NODES_FROSTWOLF_WTOWER; ++i)     // horde towers
        InitNode(i, BG_AV_TEAM_HORDE, true);

    InitNode(BG_AV_NODES_SNOWFALL_GRAVE, BG_AV_TEAM_NEUTRAL, false);                            // give snowfall neutral owner

}
Пример #27
0
bool CPathFind::PathFind(int startx, int starty, int endx, int endy) {
    InitNode(startx,starty,endx,endy);
    //首先做几个预先判断
    if ((startx == endx) && (starty == endy)) {
        cout << "起点就是终点";
    }
    m_startx = startx;
    m_starty = starty;
    m_endx = endx;
    m_endy = endy;
    pNode node = CreateFirstNode(startx, starty);
    //将这个节点放入openlist
    m_openlist.push_back(node);
    //对这个地方进行排序
    push_heap(m_openlist.begin(),m_openlist.end(),NodeSort);
    pNode tmpnode = NULL;
    for(;;)
    {
        if(m_openlist.empty())
        {
            cout<<"错误:不能找到目标节点"<<endl;
            return false;
        }
        tmpnode = m_openlist.front();
        ++m_step;
        pop_heap(m_openlist.begin(),m_openlist.end(),NodeSort);
        m_openlist.pop_back();
        if (!CheckIsDestination(tmpnode))
        {
            //这里不是是目标地点
            for(int i = 0 ;i<8 ;i++)
            {
                int nextx ;
                int nexty ;
                GetShiftByDirectory(i,&nextx,&nexty);
                nextx = tmpnode->x + nextx;
                nexty = tmpnode->y + nexty;
                //判断这个点是可以通过的
                cout<<"next is"<<nextx<<":"<<nexty<<endl;
                if(isIllegle(nextx,nexty))
                {
                   //这里可以通过
                    //计算这个点的G值
                    int newGvalue;
                    if(i % 2 ==0)
                      newGvalue = tmpnode->G+10;
                    else
                      newGvalue = tmpnode->G+14;

                    vector<pNode>::iterator OpenIt;
                    //说明该节点在OPEN表中
                    for(OpenIt=m_openlist.begin();OpenIt<m_openlist.end();OpenIt++)
                    {
                        if (((*OpenIt)->x == nextx)&&((*OpenIt)->y ==nexty))
                        {
                             break;
                        }
                    }

                    if(OpenIt != m_openlist.end())
                    {
                       if ((*OpenIt)->G <= newGvalue)
                           continue;
                    }
                    //说明该节点在close表中
                    vector<pNode>::iterator CloseIt;

                    for(CloseIt=m_closelist.begin();CloseIt<m_closelist.end();CloseIt++)
                    {
                        if (((*CloseIt)->x == nextx)&&((*CloseIt)->y ==nexty))
                        {
                             break;
                        }
                    }

                    if(CloseIt != m_closelist.end())
                    {
                       if ((*CloseIt)->G <= newGvalue)
                           continue;
                    }

                    //如果都不满足上边的条件那么说明这个节点是最优节点
                    Node *bestNode = new Node;
                    bestNode->x = nextx;
                    bestNode->y = nexty;
                    bestNode->father = tmpnode;
                    bestNode->G = newGvalue;
                    bestNode->H = CalcG(nextx,nexty);
                    bestNode->F = bestNode->G + bestNode->H;

                    if (CloseIt != m_closelist.end())
                    {
                        delete(*CloseIt);
                        m_closelist.erase(CloseIt);
                    }

                    if (OpenIt != m_openlist.end())
                    {
                        delete(*OpenIt);
                        m_openlist.erase(OpenIt);
                        make_heap(m_openlist.begin(),m_openlist.end(),NodeSort);

                    }
                    m_openlist.push_back(bestNode);
                    push_heap(m_openlist.begin(),m_openlist.end(),NodeSort);
                    for(vector<pNode>::iterator k = m_openlist.begin() ;k<m_openlist.end();k++)
                    {
                        cout<<"x:"<<(*k)->x<<",y:"<<(*k)->y<<endl;


                    }
                    cout<<" isIlleglea is true"<<endl;
                }
                else
                {
                    cout<<" isIlleglea is false"<<endl;
                    //不能通过
                }


            }
            m_closelist.push_back(tmpnode);


        }
        else
        {
                generatePath();
                return true;
         }


    }


}
Пример #28
0
NodeButton::NodeButton(StringRef name,
							 INode* normalNode,
							 INode* selectedNode/*=nullptr*/,
							 INode* disabledNode/*=nullptr*/,
							 INode* disabledSelectedNode/*=nullptr*/)
							 :IButton(name),
							 mNormalNode(normalNode),
							 mSelectedNode(selectedNode),
							 mDisabledNode(disabledNode),
							 mDisabledSelectedNode(disabledSelectedNode)
{
	bool hasSize = false;
	if (mNormalNode!=nullptr)
	{
		InitNode(mNormalNode);
		mNormalNode->SetName(MEDUSA_PREFIX(Normal));
		
		AddChild(mNormalNode);
		mNormalNode->SetVisible(false);
		SetSize(mNormalNode->Size());	//default to normal size
		hasSize = true;
	}
	if (mSelectedNode != nullptr)
	{
		InitNode(mSelectedNode);
		mSelectedNode->SetName(MEDUSA_PREFIX(Selected));

		AddChild(mSelectedNode);
		mSelectedNode->SetVisible(false);
		if (!hasSize)
		{
			SetSize(mSelectedNode->Size());
			hasSize = true;
		}
	}
	if (mDisabledNode != nullptr)
	{
		InitNode(mDisabledNode);
		mDisabledNode->SetName(MEDUSA_PREFIX(Disabled));

		AddChild(mDisabledNode);
		mDisabledNode->SetVisible(false);
		if (!hasSize)
		{
			SetSize(mDisabledNode->Size());
			hasSize = true;
		}
	}
	if (mDisabledSelectedNode != nullptr)
	{
		InitNode(mDisabledSelectedNode);
		mDisabledSelectedNode->SetName(MEDUSA_PREFIX(DisabledSelected));

		AddChild(mDisabledSelectedNode);
		mDisabledSelectedNode->SetVisible(false);
		if (!hasSize)
		{
			SetSize(mDisabledSelectedNode->Size());
			//hasSize = true;
		}
	}
}
Пример #29
0
static int node_dynamic_parse(struct bNode *node)
{
#ifndef WITH_PYTHON
	return -1;
#else
	PyObject *dict= NULL;
	PyObject *pynode_data= NULL;
	PyObject *pynode= NULL;
	PyObject *args= NULL;
	NodeScriptDict *nsd = NULL;
	PyObject *pyresult = NULL;
	char *buf = NULL;
	int is_valid_script = 0;
	PyGILState_STATE gilstate;

	if (!node->id || !node->storage)
		return 0;

	/* READY, no need to be here */
	if (BTST(node->custom1, NODE_DYNAMIC_READY))
		return 0;

	/* for threading */
	gilstate = PyGILState_Ensure();

	nsd = (NodeScriptDict *)node->storage;

	dict = (PyObject *)(nsd->dict);
	buf = txt_to_buf((Text *)node->id);

	pyresult = PyRun_String(buf, Py_file_input, dict, dict);

	MEM_freeN(buf);

	if (!pyresult) {
		if (BTST(node->custom1, NODE_DYNAMIC_LOADED)) {
			node_dynamic_disable(node);
		} else {
		node_dynamic_disable_all_by_id(node->id);
		}
		node_dynamic_pyerror_print(node);
		PyGILState_Release(gilstate);
		return -1;
	}

	Py_DECREF(pyresult);

	pynode_data = node_dynamic_get_pynode(dict);

	if (pynode_data) {
		BPy_NodeSocketLists *socklists = Node_CreateSocketLists(node);

		args = Py_BuildValue("(O)", socklists);

		/* init it to get the input and output sockets */
		pynode = PyObject_Call(pynode_data, args, NULL);

		Py_DECREF(pynode_data);
		Py_DECREF(socklists);
		Py_DECREF(args);

		if (!PyErr_Occurred() && pynode && pytype_is_pynode(pynode)) {
			InitNode((BPy_Node *)(pynode), node);
			nsd->node = pynode;
			node->typeinfo->execfunc = node_dynamic_exec_cb;
			is_valid_script = 1;

			/* for NEW, LOADED, REPARSE */
			if (BNTST(node->custom1, NODE_DYNAMIC_ADDEXIST)) {
				node->typeinfo->pydict = dict;
				node->typeinfo->pynode = pynode;
				node->typeinfo->id = node->id;
				if (BNTST(node->custom1, NODE_DYNAMIC_LOADED))
					nodeAddSockets(node, node->typeinfo);
				if (BNTST(node->custom1, NODE_DYNAMIC_REPARSE))
					node_dynamic_register_type(node);
			}

			node->custom1 = 0;
			node->custom1 = BSET(node->custom1, NODE_DYNAMIC_READY);
		}
	}

	PyGILState_Release(gilstate);

	if (!is_valid_script) { /* not a valid pynode script */
		node_dynamic_disable_all_by_id(node->id);
		node_dynamic_pyerror_print(node);
		return -1;
	}

	return 0;
#endif
}
static status_t
fs_walk(fs_volume* _volume, fs_vnode* _base, const char* file, ino_t* _vnodeID)
{
	iso9660_volume* volume = (iso9660_volume*)_volume->private_volume;
	iso9660_inode* baseNode = (iso9660_inode*)_base->private_node;
	iso9660_inode* newNode = NULL;

	TRACE(("fs_walk - looking for %s in dir file of length %d\n", file,
		(int)baseNode->dataLen[FS_DATA_FORMAT]));

	if (strcmp(file, ".") == 0)  {
		// base directory
		TRACE(("fs_walk - found \".\" file.\n"));
		*_vnodeID = baseNode->id;
		return get_vnode(_volume, *_vnodeID, NULL);
	} else if (strcmp(file, "..") == 0) {
		// parent directory
		TRACE(("fs_walk - found \"..\" file.\n"));
		*_vnodeID = baseNode->parID;
		return get_vnode(_volume, *_vnodeID, NULL);
	}

	// look up file in the directory
	uint32 dataLength = baseNode->dataLen[FS_DATA_FORMAT];
	status_t result = ENOENT;
	size_t totalRead = 0;
	off_t block = baseNode->startLBN[FS_DATA_FORMAT];
	bool done = false;

	while (totalRead < dataLength && !done) {
		off_t cachedBlock = block;
		char* blockData = (char*)block_cache_get(volume->fBlockCache, block);
		if (blockData == NULL)
			break;

		size_t bytesRead = 0;
		off_t blockBytesRead = 0;
		iso9660_inode node;
		int initResult;

		TRACE(("fs_walk - read buffer from disk at LBN %Ld into buffer "
			"%p.\n", block, blockData));

		// Move to the next block if necessary
		// Don't go over end of buffer, if dir record sits on boundary.

		while (blockBytesRead < volume->logicalBlkSize[FS_DATA_FORMAT]
			&& totalRead + blockBytesRead < dataLength
			&& blockData[0] != 0
			&& !done) {
			initResult = InitNode(volume, &node, blockData, &bytesRead);
			TRACE(("fs_walk - InitNode returned %s, filename %s, %u bytes "
				"read\n", strerror(initResult), node.name, (unsigned)bytesRead));

			if (initResult == B_OK) {
				if ((node.flags & ISO_IS_ASSOCIATED_FILE) == 0
					&& !strcmp(node.name, file)) {
					TRACE(("fs_walk - success, found vnode at block %Ld, pos "
						"%Ld\n", block, blockBytesRead));

					*_vnodeID = (block << 30) + (blockBytesRead & 0xffffffff);
					TRACE(("fs_walk - New vnode id is %Ld\n", *_vnodeID));

					result = get_vnode(_volume, *_vnodeID, (void**)&newNode);
					if (result == B_OK) {
						newNode->parID = baseNode->id;
						done = true;
					}
				} else {
					free(node.name);
					free(node.attr.slName);
				}
			} else {
				result = initResult;
				if (bytesRead == 0)
					done = true;
			}
			blockData += bytesRead;
			blockBytesRead += bytesRead;

			TRACE(("fs_walk - Adding %u bytes to blockBytes read (total "
				"%Ld/%u).\n", (unsigned)bytesRead, blockBytesRead,
				(unsigned)baseNode->dataLen[FS_DATA_FORMAT]));
		}
		totalRead += volume->logicalBlkSize[FS_DATA_FORMAT];
		block++;

		TRACE(("fs_walk - moving to next block %Ld, total read %u\n",
			block, (unsigned)totalRead));
		block_cache_put(volume->fBlockCache, cachedBlock);
	}

	TRACE(("fs_walk - EXIT, result is %s, vnid is %Lu\n",
		strerror(result), *_vnodeID));
	return result;
}