/*
Updating some obsolete blocks.
Using FIFO-principle.
*/
void CPathEstimator::Update() {
	pathCache->Update();
	int counter = 0;
	while(!needUpdate.empty() && counter < BLOCKS_TO_UPDATE) {
		//Next block in line.
		SingleBlock sb = needUpdate.front();
		needUpdate.pop_front();
		int blocknr = sb.block.y * nbrOfBlocksX + sb.block.x;

		//Check if already updated.
		if(!(blockState[blocknr].options & PATHOPT_OBSOLETE))
			continue;

		//Update the block.
		FindOffset(*sb.moveData, sb.block.x, sb.block.y);
		CalculateVertices(*sb.moveData, sb.block.x, sb.block.y);

		//Mark as updated.
		if(sb.moveData==moveinfo->moveData.back()){
			blockState[blocknr].options &= ~PATHOPT_OBSOLETE;
		}

		//One block updated.
		counter++;
	}
}
//int32_t CLineFollowerNavigatorEngine::ProcessImageData(const sensor_msgs::ImageConstPtr img, bool bDisplayImage)
	int32_t CLineFollowerNavigatorEngine::ProcessImage(IplImage *pFrame, bool bDisplayImage, float &fAngle, CvPoint &vanishingPoint)
	{
		int nRet = 0;

		//SetDebugDisplayImage(bDisplayImage);

		if (m_bPaused == true)
		{
			nRet = 1;
			return nRet;
		}
		//cv_bridge::CvImagePtr cv_ptr = cv_bridge::toCvCopy(img, sensor_msgs::image_encodings::MONO8);
		cv::Mat workingCVMat;
		/*
		   if (m_pUndistorter != 0)
		   {
		    assert(m_pUndistorter->isValid());
		    m_pUndistorter->undistort(cv_ptr->image, workingCVMat);
		   }
		   else
		 */
		{
			workingCVMat = pFrame;
		}
		if (pFrame != NULL)
		{
			m_nWidth = pFrame->width;
			m_nHeight = pFrame->height;
		}
		//printf("workingCVMat: depth=%d, channels=%d, dims=%d, (%dx%d)\n", workingCVMat.depth(), workingCVMat.channels(), workingCVMat.dims, workingCVMat.rows, workingCVMat.cols);
		// process this gray-scale data
		int32_t nCenterX = 0, nCenterY = 0;
		float fOffsetX = 0, fOffsetY = 0;

		nRet = FindLineCenter(workingCVMat, 0, nCenterX, nCenterY, bDisplayImage);

		if (nRet <= 0)
		{
			//printf("Fail to find line center\n");
			goto err_out;
		}

		nRet = FindOffset(nCenterX, nCenterY, fOffsetX, fOffsetY);
		if (nRet <= 0)
		{
			myprintf(_ERRORLINENO, 1, "Fail to find offset\n");
			goto err_out;
		}

		nRet = OffsetNavigator(fOffsetX, fAngle, vanishingPoint);
		if (nRet <= 0)
		{
			myprintf(_ERRORLINENO, 1, "Fail to OffsetNavigator\n");
			goto err_out;
		}
err_out:
		return nRet;
	}
Пример #3
0
FamilyNode * FamilyNode::FindOffset( const char *_name, Matrix &matrix, Bool local) // = FALSE)
{
  FamilyNode *node = Find( _name, local);
  if (node && Child())
  {
    FindOffset( node, matrix, local);
  }
  return node;
}
void CPathEstimator::CalculateBlockOffsets(int minBlock, int maxBlock, int) {
	assert(maxBlock <= nbrOfBlocks);

	for (int idx = minBlock; idx < maxBlock; idx++) {
		int x = idx % nbrOfBlocksX;
		int z = idx / nbrOfBlocksX;

		vector<MoveData*>::iterator mi;
		for (mi = moveinfo->moveData.begin(); mi < moveinfo->moveData.end(); mi++) {
			FindOffset(**mi, x, z);
		}
	}
}
Пример #5
0
void CPathEstimator::CalculateBlockOffsets(int idx, int thread) {
	int x = idx % nbrOfBlocksX;
	int z = idx / nbrOfBlocksX;

	if (thread == 0 && (idx/1000)!=lastOffsetMessage) {
		lastOffsetMessage=idx/1000;
		char calcMsg[128];
		sprintf(calcMsg, "Block offset: %d of %d (size %d)", lastOffsetMessage*1000, nbrOfBlocks, BLOCK_SIZE);
		net->Send(CBaseNetProtocol::Get().SendCPUUsage(BLOCK_SIZE | (lastOffsetMessage<<8)));
		PrintLoadMsg(calcMsg);
	}

	for (vector<MoveData*>::iterator mi = moveinfo->moveData.begin(); mi != moveinfo->moveData.end(); mi++)
		FindOffset(**mi, x, z);
}
Пример #6
0
void CPathEstimator::CalculateBlockOffsets(int idx, int thread)
{
	const int x = idx % nbrOfBlocksX;
	const int z = idx / nbrOfBlocksX;

	if (thread == 0 && idx >= nextOffsetMessage) {
		nextOffsetMessage = idx + blockStates.GetSize() / 16;
		net->Send(CBaseNetProtocol::Get().SendCPUUsage(BLOCK_SIZE | (idx << 8)));
	}

	for (vector<MoveData*>::iterator mi = moveinfo->moveData.begin(); mi != moveinfo->moveData.end(); mi++) {
		if ((*mi)->unitDefRefCount > 0) {
			FindOffset(**mi, x, z);
		}
	}
}
Пример #7
0
int main()
{
	HWND hWindow = 0,hWindowOld = 0;
	DWORD dwWritten, dwPid;
	HANDLE hProcess;
	LPMODULEENTRY32 lpsModule;

	SetConsoleTitle("Steam");
	SetDebugPrivilege();
	while(1)
	{
		printf("Zhdem nachala igri\n");
		while( (hWindow = FindWindow(NULL, "League of Legends (TM) Client")) == 0 || hWindow == hWindowOld )
			Sleep(1000);

		hWindowOld = hWindow;
		GetWindowThreadProcessId(hWindow, &dwPid);
		hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPid);
		if( hProcess == NULL )
		{
			printf("Couldn't get client handle!\n\n");
			continue;
		}
		printf("Nashel!\n");
		lpsModule = GetModuleInfo(dwPid);
		for( int i = 0; i < sizeof(g_sPatchList)/sizeof(OffsetInfo); ++i )
		{
			if( g_sPatchList[i].dwOffset == 0)
			{
				if( lpsModule )
					FindOffset(hProcess, lpsModule, i);
			}

			if( g_sPatchList[i].dwOffset )
			{
				WriteProcessMemory(hProcess,(void*)g_sPatchList[i].dwOffset,(void*)g_sPatchList[i].lpbyData,g_sPatchList[i].dwLen,&dwWritten);
				printf("GOTOVO! Polozhil Podorozhnik na adres: %X\n",g_sPatchList[i].dwOffset);
			}else
				printf("NOT Patched: %s\n",g_sPatchList[i].lpszName);
		}
		CloseHandle(hProcess);
		printf("\n");
	}
	
	return 0;
}
/*
Constructor.
Loading precalculated data.
*/
CPathEstimator::CPathEstimator(CPathFinder* pf, unsigned int BSIZE, unsigned int mmOpt, string name) :
pathFinder(pf),
BLOCK_SIZE(BSIZE),
BLOCK_PIXEL_SIZE(BSIZE * SQUARE_SIZE),
BLOCKS_TO_UPDATE(SQUARES_TO_UPDATE / (BLOCK_SIZE * BLOCK_SIZE) + 1),
moveMathOptions(mmOpt)
{
	//Gives the changes in (x,z) when moved one step in given direction.
	//(Need to be placed befor pre-calculations)
	directionVector[PATHDIR_LEFT].x = 1;
	directionVector[PATHDIR_LEFT].y = 0;
	directionVector[PATHDIR_LEFT_UP].x = 1;
	directionVector[PATHDIR_LEFT_UP].y = 1;
	directionVector[PATHDIR_UP].x = 0;
	directionVector[PATHDIR_UP].y = 1;
	directionVector[PATHDIR_RIGHT_UP].x = -1;
	directionVector[PATHDIR_RIGHT_UP].y = 1;
	directionVector[PATHDIR_RIGHT].x = -1;
	directionVector[PATHDIR_RIGHT].y = 0;
	directionVector[PATHDIR_RIGHT_DOWN].x = -1;
	directionVector[PATHDIR_RIGHT_DOWN].y = -1;
	directionVector[PATHDIR_DOWN].x = 0;
	directionVector[PATHDIR_DOWN].y = -1;
	directionVector[PATHDIR_LEFT_DOWN].x = 1;
	directionVector[PATHDIR_LEFT_DOWN].y = -1;

	goalSqrOffset.x=BLOCK_SIZE/2;
	goalSqrOffset.y=BLOCK_SIZE/2;

	//Creates the block-map and the vertices-map.
	nbrOfBlocksX = gs->mapx / BLOCK_SIZE;
	nbrOfBlocksZ = gs->mapy / BLOCK_SIZE;
	nbrOfBlocks = nbrOfBlocksX * nbrOfBlocksZ;

	blockState = SAFE_NEW BlockInfo[nbrOfBlocks];
	nbrOfVertices = moveinfo->moveData.size() * nbrOfBlocks * PATH_DIRECTION_VERTICES;
	vertex = SAFE_NEW float[nbrOfVertices];
	openBlockBufferPointer=openBlockBuffer;

	int i;
	for(i = 0; i < nbrOfVertices; i++)
		vertex[i] = PATHCOST_INFINITY;

	//Initialize blocks.
	int x, z;
	for(z = 0; z < nbrOfBlocksZ; z++){
		for(x = 0; x < nbrOfBlocksX; x++) {
			int blocknr = z * nbrOfBlocksX + x;
			blockState[blocknr].cost = PATHCOST_INFINITY;
			blockState[blocknr].options = 0;
			blockState[blocknr].parentBlock.x = -1;
			blockState[blocknr].parentBlock.y = -1;
			blockState[blocknr].sqrCenter = SAFE_NEW int2[moveinfo->moveData.size()];
		}
	}

	//Pre-read/calculate data.
	PrintLoadMsg("Reading estimate path costs");
	if(!ReadFile(name)) {
		//Generate text-message.
		char calcMsg[1000], buffer[10];
		strcpy(calcMsg, "Analyzing map accessability \"");
		SNPRINTF(buffer,10,"%d",BLOCK_SIZE);
		strcat(calcMsg, buffer);
		strcat(calcMsg, "\"");
		PrintLoadMsg(calcMsg);
		//Calculating block-center-offsets.
		for(z = 0; z < nbrOfBlocksZ; z++) {
			for(x = 0; x < nbrOfBlocksX; x++) {
				vector<MoveData*>::iterator mi;
				for(mi = moveinfo->moveData.begin(); mi < moveinfo->moveData.end(); mi++) {
					FindOffset(**mi, x, z);
				}
			}
		}

		//Calculating vectors.
		vector<MoveData*>::iterator mi;
		for(mi = moveinfo->moveData.begin(); mi < moveinfo->moveData.end(); mi++) {
			//Generate text-message.
			char calcMsg[10000];
			sprintf(calcMsg,"Calculating estimate path costs \"%i\" %i/%i",BLOCK_SIZE,(*mi)->pathType,moveinfo->moveData.size());
			PrintLoadMsg(calcMsg);
			//Calculate
			for(z = 0; z < nbrOfBlocksZ; z++) {
				for(x = 0; x < nbrOfBlocksX; x++) {
					CalculateVertices(**mi, x, z);
				}
			}
		}
		WriteFile(name);
	}

	//As all vertexes are bidirectional and having equal values
	//in both directions, only one value are needed to be stored.
	//This vector helps getting the right vertex.
	//(Need to be placed after pre-calculations)
	directionVertex[PATHDIR_LEFT] = PATHDIR_LEFT;
	directionVertex[PATHDIR_LEFT_UP] = PATHDIR_LEFT_UP;
	directionVertex[PATHDIR_UP] = PATHDIR_UP;
	directionVertex[PATHDIR_RIGHT_UP] = PATHDIR_RIGHT_UP;
	directionVertex[PATHDIR_RIGHT] = int(PATHDIR_LEFT) - PATH_DIRECTION_VERTICES;
	directionVertex[PATHDIR_RIGHT_DOWN] = int(PATHDIR_LEFT_UP) - (nbrOfBlocksX * PATH_DIRECTION_VERTICES) - PATH_DIRECTION_VERTICES;
	directionVertex[PATHDIR_DOWN] = int(PATHDIR_UP) - (nbrOfBlocksX * PATH_DIRECTION_VERTICES);
	directionVertex[PATHDIR_LEFT_DOWN] = int(PATHDIR_RIGHT_UP) - (nbrOfBlocksX * PATH_DIRECTION_VERTICES) + PATH_DIRECTION_VERTICES;

	pathCache=SAFE_NEW CPathCache(nbrOfBlocksX,nbrOfBlocksZ);
}
Пример #9
0
/* End of test binpatch variables */
int
main(int argc, char *argv[])
{
  struct exec e;
  int c;
  u_long addr = 0, offset = 0;
  u_long index = 0;/* Related to offset */
  u_long replace = 0, do_replace = 0;
  char *symbol = 0;
  char size = 4;  /* default to long */
  char size_opt = 0; /* Flag to say size option was set, used with index */
  char *fname;
  char *pgname = argv[0]; /* Program name */
  int fd;
  int type, off;
  u_long  lval;
  u_short sval;
  u_char  cval;


  while ((c = getopt (argc, argv, "H:a:bwlr:s:o:")) != -1)
    switch (c)
      {
      case 'H':
        Usage(argv[0]);
        break;
      case 'a':
	if (addr || symbol)
	  error ("only one address/symbol allowed");
	if (! strncmp (optarg, "0x", 2))
	  sscanf (optarg, "%x", &addr);
	else
	  addr = atoi (optarg);
	if (! addr)
	  error ("invalid address");
	break;

      case 'b':
	size = 1;
        size_opt = 1;
	break;

      case 'w':
	size = 2;
        size_opt = 1;
	break;

      case 'l':
	size = 4;
        size_opt = 1;
	break;

      case 'r':
	do_replace = 1;
	if (! strncmp (optarg, "0x", 2))
	  sscanf (optarg, "%x", &replace);
	else
	  replace = atoi (optarg);
	break;

      case 's':
	if (addr || symbol)
	  error ("only one address/symbol allowed");
	symbol = optarg;
	break;

      case 'o':
	if (offset)
	  error ("only one offset allowed");
	if (! strncmp (optarg, "0x", 2))
	  sscanf (optarg, "%x", &offset);
	else
          offset = atoi (optarg);
        break;
      }/* while switch() */

  if (argc > 1)
  {
    if (addr || symbol)
    {
      argv += optind;
      argc -= optind;

      if (argc < 1)
        error ("No file to patch.");

      fname = argv[0];
      if ((fd = open (fname, 0)) < 0)
        error ("Can't open file");

      if (read (fd, &e, sizeof (e)) != sizeof (e)
        || N_BADMAG (e))
        error ("Not a valid executable.");

      /* fake mid, so the N_ macros work on the amiga.. */
      e.a_midmag |= 127 << 16;

      if (symbol)
      {
        struct nlist nl[2];
        if (offset == 0)
	{
            u_long new_do_replace = 0;
            new_do_replace = FindAssign(symbol,&replace);
            if (new_do_replace && do_replace)
              error("Cannot use both '=' and '-r' option!");
            FindOffset(symbol,&index);
            if (size_opt)
               offset = index*size; /* Treat like an index */
            else
               offset = index; /* Treat index like an offset */
	    if (new_do_replace)
	       do_replace = new_do_replace;
	}
        nl[0].n_un.n_name = symbol;
        nl[1].n_un.n_name = 0;
        if (nlist (fname, nl) != 0)
	{
          fprintf(stderr,"Symbol is %s ",symbol);
	  error ("Symbol not found.");
        }
        addr = nl[0].n_value;
        type = nl[0].n_type & N_TYPE;
      }
      else
      {
        type = N_UNDF;
        if (addr >= N_TXTADDR(e) && addr < N_DATADDR(e))
	  type = N_TEXT;
        else if (addr >= N_DATADDR(e) && addr < N_DATADDR(e) + e.a_data)
	  type = N_DATA;
      }
      addr += offset;

      /* if replace-mode, have to reopen the file for writing.
         Can't do that from the beginning, or nlist() will not
         work (at least not under AmigaDOS) */
      if (do_replace)
      {
        close (fd);
        if ((fd = open (fname, 2)) == -1)
	  error ("Can't reopen file for writing.");
      }

      if (type != N_TEXT && type != N_DATA)
        error ("address/symbol is not in text or data section.");

      if (type == N_TEXT)
        off = addr - N_TXTADDR(e) + N_TXTOFF(e);
      else
        off = addr - N_DATADDR(e) + N_DATOFF(e);

      if (lseek (fd, off, 0) == -1)
        error ("lseek");

      /* not beautiful, but works on big and little endian machines */
      switch (size)
        {
        case 1:
          if (read (fd, &cval, 1) != 1)
	    error ("cread");
          lval = cval;
          break;

        case 2:
          if (read (fd, &sval, 2) != 2)
	    error ("sread");
          lval = sval;
          break;

        case 4:
          if (read (fd, &lval, 4) != 4)
	    error ("lread");
          break;
        }/* switch size */


      if (symbol)
        printf ("%s(0x%x): %d (0x%x)\n", symbol, addr, lval, lval);
      else
        printf ("0x%x: %d (0x%x)\n", addr, lval, lval);

      if (do_replace)
      {
        if (lseek (fd, off, 0) == -1)
	  error ("write-lseek");
        switch (size)
	  {
	  case 1:
	    cval = replace;
	    if (cval != replace)
	      error ("byte-value overflow.");
	    if (write (fd, &cval, 1) != 1)
	      error ("cwrite");
	    break;

	  case 2:
	    sval = replace;
	    if (sval != replace)
	      error ("word-value overflow.");
	    if (write (fd, &sval, 2) != 2)
	      error ("swrite");
	    break;

	  case 4:
	    if (write (fd, &replace, 4) != 4)
	      error ("lwrite");
	    break;
	  }/* switch(size) */
      }/* if (do_replace) */

      close (fd);
    }/* if(addr || symbol ) */
    else
    {
      error("Must specify either address or symbol.");
    }
  }/* if argc < 1 */
  else
  {
    Synopsis(pgname);
  }
  return(0);
}/* main () */
Пример #10
0
void ComputeLightMaps (int segNum)
{
	tSegment		*segP; 
	tSide			*sideP; 
	tLightMap	*lmapP; 
	int			sideNum, lastSeg, mapNum; 
	short			sideVerts [4]; 

#if 1
#	define		Xs 8
#	define		Ys 8
#else
	int			Xs = 8, Ys = 8; 
#endif
	int			x, y, xy; 
	int			v0, v1, v2, v3; 
	GLfloat		*pTexColor;// = {0.0, 0.0, 0.0, 1.0}; 
	GLfloat		texColor [Xs][Ys][4];

#if 1
#	define		pixelOffset 0.0
#else
	double		pixelOffset = 0; //0.5
#endif
	int			l, s, nMethod, sideRad; 
	GLfloat		tempBright = 0; 
	vmsVector	OffsetU, OffsetV, pixelPos [Xs][Ys], *pPixelPos, rayVec, faceNorm, sidePos; 
	double		brightPrct, pixelDist; 
	double		delta; 
	double		f_offset [8] = {
						0.0 / (Xs - 1), 1.0 / (Xs - 1), 2.0 / (Xs - 1), 3.0 / (Xs - 1),
						4.0 / (Xs - 1), 5.0 / (Xs - 1), 6.0 / (Xs - 1), 7.0 / (Xs - 1)
						};
#if LMAP_REND2TEX
	ubyte			brightMap [512];
	ubyte			lightMap [512*3];
	tUVL			lMapUVL [4];
	fix			nDist, nMinDist;
	GLuint		lightMapId;
	int			bStart;
#endif

if (segNum <= 0) {
	DestroyLightMaps ();
	if (!InitLightData ())
		return;
#if LMAP_REND2TEX
	InitBrightMap (brightMap);
	memset (&lMapUVL, 0, sizeof (lMapUVL));
#endif
	}
INIT_PROGRESS_LOOP (segNum, lastSeg, gameData.segs.nSegments);
//Next Go through each surface and create a lightmap for it.
for (mapNum = 6 * segNum, segP = gameData.segs.segments + segNum; 
	  segNum < lastSeg; 
	  segNum++, segP++) {
	for (sideNum = 0, sideP = segP->sides; sideNum < 6; sideNum++, mapNum++, sideP++) {
#if TEXTURE_CHECK
		if ((segP->children [sideNum] >= 0) && !IS_WALL (WallNumS (sideP)))
			continue; 	//skip open sides
#endif			
		GetSideVerts (sideVerts, segNum, sideNum); 
#if LMAP_REND2TEX
		OglCreateFBuffer (&lightMaps [mapNum].fbuffer, 64, 64);
		OglEnableFBuffer (&lightMaps [mapNum].fbuffer);
#else
		lightMaps [mapNum].handle = EmptyTexture (Xs, Ys); 
		OGL_BINDTEX (lightMaps [mapNum].handle); 
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

		nMethod = (sideP->nType == SIDE_IS_QUAD) || (sideP->nType == SIDE_IS_TRI_02);
		pPixelPos = &pixelPos [0][0];
		for (x = 0; x < Xs; x++) {
			for (y = 0; y < Ys; y++, pPixelPos++) {
				if (nMethod) {
					v0 = sideVerts [0]; 
					v2 = sideVerts [2]; 
					if (x >= y)	{
						v1 = sideVerts [1]; 
						//Next calculate this pixel's place in the world (tricky stuff)
						FindOffset (&OffsetU, gameData.segs.vertices [v0], gameData.segs.vertices [v1], f_offset [x]); //(((double) x) + pixelOffset) / (Xs - 1)); //took me forever to figure out this should be an inverse thingy
						FindOffset (&OffsetV, gameData.segs.vertices [v1], gameData.segs.vertices [v2], f_offset [y]); //(((double) y) + pixelOffset) / (Ys - 1)); 
						VmVecAdd (pPixelPos, &OffsetU, &OffsetV); 
						VmVecInc (pPixelPos, gameData.segs.vertices + v0);  //This should be the real world position of the pixel.
						//Find Normal
						VmVecNormal (&faceNorm, gameData.segs.vertices + v0, gameData.segs.vertices + v2, gameData.segs.vertices + v1); 
						}
					else {
						//Next calculate this pixel's place in the world (tricky stuff)
						v3 = sideVerts [3]; 
						FindOffset (&OffsetV, gameData.segs.vertices [v0], gameData.segs.vertices [v3], f_offset [y]); //(((double) y) + pixelOffset) / (Xs - 1)); //Notice y/x and OffsetU/OffsetV are swapped from above
						FindOffset (&OffsetU, gameData.segs.vertices [v3], gameData.segs.vertices [v2], f_offset [x]); //(((double) x) + pixelOffset) / (Ys - 1)); 
						VmVecAdd (pPixelPos, &OffsetU, &OffsetV); 
						VmVecInc (pPixelPos, gameData.segs.vertices + v0);  //This should be the real world position of the pixel.
						VmVecNormal (&faceNorm, gameData.segs.vertices + v0, gameData.segs.vertices + v3, gameData.segs.vertices + v2); 
						}
					}
				else {//SIDE_IS_TRI_02
					v1 = sideVerts [1]; 
					v3 = sideVerts [3]; 
					if (Xs - x >= y) {
						v0 = sideVerts [0]; 
						FindOffset (&OffsetU, gameData.segs.vertices [v0], gameData.segs.vertices [v1], f_offset [x]); //(((double) x) + pixelOffset) / (Xs - 1)); 
						FindOffset (&OffsetV, gameData.segs.vertices [v0], gameData.segs.vertices [v3], f_offset [y]); //(((double) y) + pixelOffset) / (Xs - 1)); 
						VmVecAdd (pPixelPos, &OffsetU, &OffsetV); 
						VmVecInc (pPixelPos, gameData.segs.vertices + v0);  //This should be the real world position of the pixel.
						}
					else {
						v2 = sideVerts [2]; 
						//Not certain this is correct, may need to subtract something
						FindOffset (&OffsetV, gameData.segs.vertices [v2], gameData.segs.vertices [v1], f_offset [Xs - 1 - y]); //((double) ((Xs - 1) - y) + pixelOffset) / (Xs - 1)); 
						FindOffset (&OffsetU, gameData.segs.vertices [v2], gameData.segs.vertices [v3], f_offset [Xs - 1 - x]); //((double) ((Xs - 1) - x) + pixelOffset) / (Xs - 1)); 
						VmVecAdd (pPixelPos, &OffsetU, &OffsetV); 
						VmVecInc (pPixelPos, gameData.segs.vertices + v2);  //This should be the real world position of the pixel.
						}
					}
				}
			}
#endif
		//Calculate LightVal
		//Next iterate through all the lights and add the light to the pixel every iteration.
		sideRad = (int) (SideRad (segNum, sideNum) + 0.5);
		VmVecAvg4 (
			&sidePos, 
			&pixelPos [0][0],
			&pixelPos [Xs-1][0],
			&pixelPos [Xs-1][Ys-1],
			&pixelPos [0][Ys-1]);
#if 1
		pTexColor = texColor [0][0] + 3;
		memset (texColor, 0, sizeof (texColor));
		for (xy = Xs * Ys; xy; xy--, pTexColor += 4)
			*pTexColor = 1;
#else
		pTexColor = texColor [0][0];
		for (x = 0; x < Xs; x++) {
			for (y = 0; y < Ys; y++, pTexColor += 4) {
				pTexColor [0] = 
				pTexColor [1] = 
				pTexColor [2] = 0; 
				pTexColor [3] = 1; 
				}
			}
#endif
#if LMAP_REND2TEX
		bStart = 1;
#endif
		for (l = 0, lmapP = lightData; l < numLightMaps; l++, lmapP++) {
#if LMAP_REND2TEX
			nMinDist = 0x7FFFFFFF;
			// get the distances of all 4 tSide corners to the light source center 
			// scaled by the light source range
			for (i = 0; i < 4; i++) {
				int svi = sideVerts [i];
				sidePos.x = gameData.segs.vertices [svi].x;
				sidePos.y = gameData.segs.vertices [svi].y;
				sidePos.z = gameData.segs.vertices [svi].z;
				nDist = f2i (VmVecDist (&sidePos, &lmapP->pos));	// calc distance
				if (nMinDist > nDist)
					nMinDist = nDist;
				lMapUVL [i].u = F1_0 * (double) nDist / (double) lmapP->range;	// scale distance
				}
			if ((lmapP->color [0] + lmapP->color [1] + lmapP->color [2] < 3) &&
				(nMinDist < lmapP->range + sideRad)) {
				// create and initialize an OpenGL texture for the lightmap
				InitLightMap (lightMap, brightMap, lmapP->color);
				glGenTextures (1, &lightMapId); 
				glTexImage1D (GL_TEXTURE_1D, 0, GL_RGB, 512, 1, GL_RGB, GL_UNSIGNED_BYTE, lightMap);
				OglActiveTexture (GL_TEXTURE0_ARB);
				glEnable (GL_TEXTURE_1D);
				glEnable (GL_BLEND);
				glBlendFunc (GL_ONE, bStart ? GL_ZERO : GL_ONE);
				// If processing first light, set the lightmap, else modify it
				glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, bStart ? GL_REPLACE : GL_ADD);
				glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_RGBA);
				glBindTexture (GL_TEXTURE_1D, lightMapId); 
				// extend the lightmap to the texture edges
				glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
				glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP);
				glBegin (GL_QUADS);
				glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
				for (i = 0; i < 4; i++) {
					glMultiTexCoord2f (GL_TEXTURE0_ARB, f2fl (lMapUVL [i].u), f2fl (lMapUVL [i].v));
					glVertex3f (f2fl (gameData.segs.vertices [sideVerts [i]].x), 
									f2fl (gameData.segs.vertices [sideVerts [i]].y), 
								   f2fl (gameData.segs.vertices [sideVerts [i]].z));
					}
				glEnd ();
				glDisable (GL_BLEND);
				glDisable (GL_TEXTURE_1D);
				glDeleteTextures (1, &lightMapId);
				bStart = 0;
				}
#else
			if (f2i (VmVecDist (&sidePos, &lmapP->pos)) < lmapP->range + sideRad) {
				pPixelPos = &pixelPos [0][0];
				pTexColor = texColor [0][0];
#if 1
				for (xy = Xs * Ys; xy; xy--, pPixelPos++, pTexColor += 4) { 
#else
				for (x = 0; x < Xs; x++)
					for (y = 0; y < Ys; y++, pPixelPos++, pTexColor += 4) {
#endif
						//Find angle to this light.
						pixelDist = f2i (VmVecDist (pPixelPos, &lmapP->pos)); 
						if (pixelDist >= lmapP->range)
							continue;
						VmVecSub (&rayVec, &lmapP->pos, pPixelPos); 
						delta = f2db (VmVecDeltaAng (&lmapP->dir, &rayVec, NULL)); 
						if (delta < 0)
							delta = -delta; 
						brightPrct = 1 - (pixelDist / lmapP->range); 
						brightPrct *= brightPrct; //square result
						if (delta < 0.245)
							brightPrct /= 4; 
						pTexColor [0] += (GLfloat) (brightPrct * lmapP->color [0]); 
						pTexColor [1] += (GLfloat) (brightPrct * lmapP->color [1]); 
						pTexColor [2] += (GLfloat) (brightPrct * lmapP->color [2]); 
						}
				}
#endif
			}
#if LMAP_REND2TEX
		lightMaps [mapNum].handle = lightMaps [mapNum].fbuffer.texId;
		lightMaps [mapNum].fbuffer.texId = 0;
		OglDestroyFBuffer (&lightMaps [mapNum].fbuffer);
#else
		pPixelPos = &pixelPos [0][0];
		pTexColor = texColor [0][0];
		for (x = 0; x < Xs; x++)
			for (y = 0; y < Ys; y++, pPixelPos++, pTexColor += 4) {
				tempBright = 0;
				for (s = 0; s < 3; s++)
					if (pTexColor [s] > tempBright)
						tempBright = pTexColor [s]; 
				if (tempBright > 1.0)
					for (s = 0; s < 3; s++)
						pTexColor [s] /= tempBright; 
				glTexSubImage2D (GL_TEXTURE_2D, 0, x, y, 1, 1, GL_RGBA, GL_FLOAT, pTexColor); 
				}
#endif
		}
	}
}

//------------------------------------------------------------------------------

int HaveLightMaps (void)
{
return (lightData != NULL);
}

//------------------------------------------------------------------------------

static int segNum = 0;

static void CreateLightMapsPoll (int nItems, tMenuItem *m, int *key, int cItem)
{
GrPaletteStepLoad (NULL);
if (segNum < gameData.segs.nSegments) {
	ComputeLightMaps (segNum);
	segNum += PROGRESS_INCR;
	}
else {
	*key = -2;
	GrPaletteStepLoad (NULL);
	return;
	}
m [0].value++;
m [0].rebuild = 1;
*key = 0;
GrPaletteStepLoad (NULL);
return;
}