Пример #1
0
bool CTextFileLoader::Load(const char * c_szFileName)
{
	m_strFileName = c_szFileName;

	m_dwcurLineIndex = 0;

	FILE* fp = fopen(c_szFileName, "rb");

	if (NULL == fp)
		return false;

	fseek(fp, 0L, SEEK_END);
	const size_t fileSize = ftell(fp);
	fseek(fp, 0, SEEK_SET);

	char * pData = M2_NEW char[fileSize];
	fread(pData, fileSize, 1, fp);
	fclose(fp);

	m_fileLoader.Bind(fileSize, pData);
	M2_DELETE_ARRAY(pData);

	LoadGroup(&m_globalNode);
	return true;
}
Пример #2
0
void PanamaDestroy()
{
	PanamaVectorType::iterator it = s_panamaVector.begin();

	while (it != s_panamaVector.end()) {
		M2_DELETE_ARRAY(it->second);
		++it;
	}
}
Пример #3
0
char *locale_convert(const char *src, int len)
{
	const char	*tmp;
	int		i, j;
	char	*buf, *dest;
	int		start = 0;
	char	last_char = 0;

	if (!len)
		return NULL;

	buf = M2_NEW char[len + 1];

	for (j = i = 0, tmp = src, dest = buf; i < len; i++, tmp++)
	{
		if (*tmp == '"')
		{
			if (last_char != '\\')
				start = !start;
			else
				goto ENCODE;
		}
		else if (*tmp == ';')
		{
			if (last_char != '\\' && !start)
				break;
			else
				goto ENCODE;
		}
		else if (start)
		{
ENCODE:
			if (*tmp == '\\' && *(tmp + 1) == 'n')
			{
				*(dest++) = '\n';
				tmp++;
				last_char = '\n';
			}
			else
			{
				*(dest++) = *tmp;
				last_char = *tmp;
			}

			j++;
		}
	}

	if (!j)
	{
		M2_DELETE_ARRAY(buf);
		return NULL;
	}

	*dest = '\0';
	return (buf);
}
Пример #4
0
void SectreeTest(LPSECTREE pSec)
{
	sys_log(0, " %d %d section attribute ------------------------------", pSec->GetID().coord.x, pSec->GetID().coord.y);

	DWORD * line = M2_NEW DWORD[SECTREE_SIZE / CELL_SIZE];

	for (int y = 0; y < SECTREE_SIZE / CELL_SIZE; y++)
	{
		pSec->GetAttributePtr()->CopyRow(y, line);

		for (int x = 0; x < SECTREE_SIZE / CELL_SIZE; x++)
			printf("%c", line[x] ? 'X' : ' ');

		puts("");
	}

	M2_DELETE_ARRAY(line);
}
Пример #5
0
void ConvertAttribute2(const char * filename)
{
	std::string newFileName = std::string(filename) + ".new";
	FILE * fp = fopen(filename, "rb");
	FILE * wfp = fopen(newFileName.c_str(), "wb");

	if (!fp)
	{
		printf("cannot open %s\n", filename);
		return;
	}

	if (!wfp)
	{
		printf("cannot open %s\n", newFileName.c_str());
		return;
	}

	unsigned int uiSize;
	unsigned int uiDestSize;

	size_t maxMemSize = LZOManager::instance().GetMaxCompressedSize(sizeof(DWORD) * (SECTREE_SIZE / CELL_SIZE) * (SECTREE_SIZE / CELL_SIZE));

	std::vector <BYTE> abComp(maxMemSize);
	DWORD * attr = M2_NEW DWORD[maxMemSize];

	int iWidth, iHeight;

	fread(&iWidth, sizeof(int), 1, fp);
	fread(&iHeight, sizeof(int), 1, fp);

	fwrite(&iWidth, sizeof(int), 1, wfp);
	fwrite(&iHeight, sizeof(int), 1, wfp);

	printf("width %d height %d\n", iWidth, iHeight);
	sleep(1);

	for (int y = 0; y < iHeight; ++y)
		for (int x = 0; x < iWidth; ++x)
		{
			fread(&uiSize, sizeof(int), 1, fp);
			fread(&abComp[0], sizeof(char), uiSize, fp);

			printf("orig_size %d ", uiSize);
			uiDestSize = sizeof(DWORD) * maxMemSize;
			LZOManager::instance().Decompress(&abComp[0], uiSize, (BYTE *) attr, &uiDestSize);

			if (uiDestSize != sizeof(DWORD) * (SECTREE_SIZE / CELL_SIZE) * (SECTREE_SIZE / CELL_SIZE))
			{
				printf("SECTREE_MANAGER::LoadAttribte: %s: size mismatch! %d\n", filename, uiDestSize);
				fclose(fp);

				M2_DELETE_ARRAY(attr);
				continue;
			}

			bool found = false;

			for (int i = 0; i < (SECTREE_SIZE / CELL_SIZE) * (SECTREE_SIZE / CELL_SIZE); ++i)
				if (IS_SET(attr[i], 0xFFFFFFF8))
				{
					if (!found)
					{
						printf("!!! ");
						found = true;
					}

					REMOVE_BIT(attr[i], 0xFFFFFFF8);
				}

			LZOManager::instance().Compress((unsigned char *) attr, uiDestSize, &abComp[0], &uiDestSize);
			printf("new_size %d\n", uiDestSize);

			fwrite(&uiDestSize, sizeof(int), 1, wfp);
			fwrite(&abComp[0], uiDestSize, 1, wfp);
		}

	fclose(fp);
	fclose(wfp);
}
Пример #6
0
bool ReadMapAttribute(DWORD dwAreaX, DWORD dwAreaY, const char * c_pszFileName)
{
	FILE * fp = fopen(c_pszFileName, "rb");

	if (!fp)
	{
		sys_err("cannot open %s", c_pszFileName);
		return false;
	}

	WORD wCC, wWidth, wHeight;
	fread(&wCC,		sizeof(WORD), 1, fp);

	if (wCC != 2634)
	{
		sys_err("not a attribute file: %s cc: %d", c_pszFileName, wCC);
		fclose(fp);
		return false;
	}

	fread(&wWidth,	sizeof(WORD), 1, fp);
	fread(&wHeight,	sizeof(WORD), 1, fp);

	sys_log(0, "Reading attribute on %d %d (w %d h %d)", dwAreaX, dwAreaY, wWidth, wHeight);
	//printf("Reading attribute on %d %d (w %d h %d)", dwAreaX, dwAreaY, wWidth, wHeight);

	BYTE * pbAttr = M2_NEW BYTE [wWidth * wHeight];

	if (fread(pbAttr, sizeof(BYTE), wWidth * wHeight, fp) != (DWORD) (wWidth * wHeight))
	{
		sys_err("cannot read %s", c_pszFileName);
		M2_DELETE_ARRAY(pbAttr);
		fclose(fp);
		return false;
	}

	fclose(fp);	// close file

	// 
	// 하나의 SECTREE는 6400 PIXEL을 차지 100픽셀이 1미터 이므로 
	// 1 SECTREE = 64m = 6400px
	//
	// 클라이언트의 하나의 Area는 256m를 차지하므로 SECTREE 네개를 처리해야 
	// 한다.
	//
	DWORD dwStartX, dwStartY, dwEndX, dwEndY;

	dwEndX = (dwAreaX + 1) * (25600 / SECTREE_SIZE);
	dwEndY = (dwAreaY + 1) * (25600 / SECTREE_SIZE);
	dwStartX = dwEndX - (25600 / SECTREE_SIZE);
	dwStartY = dwEndY - (25600 / SECTREE_SIZE);

	for (DWORD y = dwStartY; y < dwEndY; ++y)
	{
		for (DWORD x = dwStartX; x < dwEndX; ++x)
		{
			SECTREEID id;

			id.coord.x = x+g_bx;
			id.coord.y = y+g_by;

			LPSECTREE pSec;

			if (!(pSec = g_pkMapSectree->Find(id.package)))
			{
				sys_err("cannot get sectree (id %d %d)", id.coord.x, id.coord.y);
				break;
			}

			// 64 128 192 256
			//  0   1   2   3
			for (int ay = region[y - dwStartY][0], py = 0; ay < region[y - dwStartY][1]; ++ay, py += 2)
			{
				for (int ax = region[x - dwStartX][0], px = 0; ax < region[x - dwStartX][1]; ++ax, px += 2)
				{
					// AREA의 경우 속성 해상도가 1m 이므로
					// CELL 1개가 50x50cm인 SECTREE에서는
					// AREA의 속성 한개가 2x2개를 차지 한다.
					BYTE bAttr = pbAttr[ay * wHeight + ax];

					if (bAttr & ATTR_OBJECT)
					{
						printf("8");
						REMOVE_BIT(bAttr, ATTR_OBJECT);
					}

					printf("%u", bAttr);

					pSec->SetAttribute(px   , py   , bAttr);
					pSec->SetAttribute(px   , py + 1, bAttr);
					pSec->SetAttribute(px + 1, py   , bAttr);
					pSec->SetAttribute(px + 1, py + 1, bAttr);
				}
			}
		}
	}

	M2_DELETE_ARRAY(pbAttr);
	return true;
}
Пример #7
0
void locale_init(const char *filename)
{
	FILE        *fp = fopen(filename, "rb");
	char        *buf;

	if (!fp) return;

	fseek(fp, 0L, SEEK_END);
	int i = ftell(fp); 
	fseek(fp, 0L, SEEK_SET);

	i++;

	buf = M2_NEW char[i];

	memset(buf, 0, i);

	fread(buf, i - 1, sizeof(char), fp);

	fclose(fp);

	const char * tmp;
	const char * end;

	char *	strings[NUM_LOCALES];

	if (!buf)
	{
		sys_err("locale_read: no file %s", filename);
		exit(1);
	}

	tmp = buf;

	do
	{
		for (i = 0; i < NUM_LOCALES; i++)
			strings[i] = NULL;

		if (*tmp == '"')
		{
			for (i = 0; i < NUM_LOCALES; i++)
			{
				if (!(end = quote_find_end(tmp)))
					break;

				strings[i] = locale_convert(tmp, end - tmp);
				tmp = ++end;

				while (*tmp == '\n' || *tmp == '\r' || *tmp == ' ') tmp++;

				if (i + 1 == NUM_LOCALES)
					break;

				if (*tmp != '"')
				{
					sys_err("locale_init: invalid format filename %s", filename);
					break;
				}
			}

			if (strings[0] == NULL || strings[1] == NULL)
				break;

			locale_add((const char**)strings);

			for (i = 0; i < NUM_LOCALES; i++)
				if (strings[i])
					M2_DELETE_ARRAY(strings[i]);
		}
		else
		{
			tmp = strchr(tmp, '\n');

			if (tmp)
				tmp++;
		}
	}
	while (tmp && *tmp);

	M2_DELETE_ARRAY(buf);
}