Esempio n. 1
0
int Map::updateInfectionState( void )
{
  int counter = 0;

  for( int y = 0; y < levels; y++ )
    for( int z = 0; z < height; z++ )
      for(  int x = 0; x < width; x++ )
      {
        int infection = getInfection(x, y, z);
        if(infection < MAX_INFECTION)
          continue;

        Cube *cube;

        for( int i = -1; i < 2; i++ )
          for( int j = -1; j < 2; j++ )
            for( int k = -1; k < 2; k++ )
            {
              if(!i &&!j && !k)
                continue;

              cube = getCube(x+k, y+i, z+j);
              if(cube && !cube->isTransparent())
              {
                int inf = cube->getInfection();
                counter += cube->incInfection() - inf;
              }
            }

        getCube(x,y,z)->setInfection(0);
        getCube(x,y,z)->setTransparent(true);
      }

  return counter;
}
    void expandFace(DirectionType direction, u16 image_x, u16 image_y, u16 image_z)
    {
        Cube* cube1 = getCube(direction, image_x, image_y, image_z);
        Face* face1 = cube1->face + direction;

        if (face1->width != 1 || face1->height != 1)
        {
            return;
        }

        for (s32 i = image_x + 1; i < m_side_length; i++)
        {
            Cube* cube2 = getCube(direction, i, image_y, image_z);
            Face* face2 = cube2->face + direction;

            if (face2->width == 1 && face2->height == 1 && cube1->col == cube2->col)
            {
                face1->width++;
                face2->width = face2->height = 0;
            }
            else
            {
                break;
            }
        }

        for (s32 i = image_y + 1; i < m_side_length; i++)
        {
            s32 max_image_x = image_x + face1->width;
            bool can_merge = true;

            for (s32 j = image_x; j < max_image_x; j++)
            {
                Cube* cube2 = getCube(direction, j, i, image_z);
                Face* face2 = cube2->face + direction;

                if (face2->width != 1 || face2->height != 1 || cube1->col != cube2->col)
                {
                    can_merge = false;
                    break;
                }
            }

            if (!can_merge)
            {
                break;
            }

            face1->height++;

            for (s32 j = image_x; j < max_image_x; j++)
            {
                Face* face2 = getCube(direction, j, i, image_z)->face + direction;

                face2->width = face2->height = 0;
            }
        }
    }
Esempio n. 3
0
void mbChargeLattice::recurseCube(mbLatticeCube *cube)
{
	mbLatticeCube *adjacentCube;
	int xIndex, yIndex, zIndex;
	int *latticeLocation = cube->latticePosition;
	xIndex = latticeLocation[0]; 
	yIndex = latticeLocation[1];
	zIndex = latticeLocation[2];
	float axisCases[6][3] = {
		{xIndex + 1, yIndex, zIndex},
		{xIndex - 1, yIndex, zIndex},
		{xIndex, yIndex + 1, zIndex},
		{xIndex, yIndex - 1, zIndex},
		{xIndex, yIndex, zIndex + 1},
		{xIndex, yIndex, zIndex - 1},
	};
	float* currentCase;
	int i;
	// Test 6 axis cases.
	for (i = 0; i < 6; i++)
	{
		currentCase = axisCases[i];
		adjacentCube = getCube(currentCase[0], currentCase[1], currentCase[2]);
		if (adjacentCube != NULL && adjacentCube->lastFrameVisited != currentFrame)
		{
			adjacentCube->lastFrameVisited = currentFrame;
			if (marchCube(adjacentCube))
				recurseCube(adjacentCube);
		}
	}
}
    Cube* getCube(DirectionType direction, u16 image_x, u16 image_y, u16 image_z)
    {
        r32 cube_x, cube_y, cube_z;
        calcCubePos(&cube_x, &cube_y, &cube_z, direction, image_x, image_y, image_z);

        return getCube(static_cast<u16>(cube_x), static_cast<u16>(cube_y), static_cast<u16>(cube_z));
    }
Esempio n. 5
0
bool Map::appendSubMap( Map* app_map,
                        int x, int y, int z, int rad )
{
  int *coord;
  coord = new int[6];
  if(!getSubMapCoord(x,y,z,rad,coord))
  {
    delete coord;
    return false;
  }

  if(!app_map)
  {
    delete coord;
    return false;
  }

  for( int i = coord[4]; i <= coord[5]; i++ )
    for( int j = coord[2]; j <= coord[3]; j++ )
      for( int k = coord[0]; k <= coord[1]; k++ )
      {
        Cube *cubeT, *cubeO;
        cubeO = getCube(k, i, j);
        cubeT = app_map->getCube(k-coord[0], i-coord[4], j-coord[2]);
        if(cubeT && cubeO)
        {
          cubeO->setInfection(cubeT->getInfection());
          cubeO->setTransparent(cubeT->isTransparent());
        }
      }

  delete coord;
  return true;
}
Esempio n. 6
0
void LegacyRulePlanNode::write(FileWriter &w, CPArea parentArea) const
{
	PlanNode::write(w, parentArea);
	// write rule identification including revision here
	w.appendIdentifier(getDatabase()->getId(),'/');
	w.appendIdentifier(getCube()->getId(),'/');
	w.appendIdentifier(getRule()->getId(),'/');
	w.appendIdentifier((IdentifierType)getDatabase()->getObjectRevision(),0); // TODO: -jj- serialize uint64_t
}
Esempio n. 7
0
Cube* Map::getSameCubeFrom( Map* map, CubeBasic* cube )
{
  if(levels != map->levels &&
     width  != map->width &&
     height != map->height)
    return NULL;

  int coord[3];

  if(!map->getCubeCoord(cube, coord))
    return NULL;

  return getCube(coord[0], coord[1], coord[2]);
}
Esempio n. 8
0
void mbChargeLattice::march()
{
	int i, xIndex, yIndex, zIndex;
	mbChargeNode *node;
	mbLatticeCube *cube;
	for (i = 0; i < chargeNodes.size(); i++)
	{
		node = &chargeNodes[i];
		//std::cout << "Searching node " << i << std::endl;
		xIndex = (int)((node->x + .5f) * xDim);
		yIndex = (int)((node->y + .5f) * yDim);
		zIndex = (int)((node->z + .5f) * zDim);
		//std::cout << xIndex << ',' << yIndex << ',' << zIndex << std::endl;

		while (zIndex >= 0)
		{
			cube = getCube(xIndex, yIndex, zIndex);
			//std::cout << "Cube is null " << (cube == NULL) << std::endl;
			if (cube != NULL && cube->lastFrameVisited != currentFrame)
			{
				//std::cout << "marching cube" << xIndex << yIndex << zIndex << std::endl;
				if (marchCube(cube))
				{
					//std::cout << "recursing cube" << xIndex << yIndex << zIndex << std::endl;
					recurseCube(cube);
					zIndex--;
				}
				cube->lastFrameVisited = currentFrame;
			}
			else
			{
				zIndex = -1;
			}
			zIndex--;
		}
	}


}
    void calcVertPos(fsVec* vert, DirectionType direction, u16 image_x, u16 image_y, u16 image_z)
    {
        Cube* cube = getCube(direction, image_x, image_y, image_z);
        Face* face = cube->face + direction;

        const r32 SIZE_MARGIN = 0.001f;

        r32 image_x2 = static_cast<r32>(image_x) - 0.5f - SIZE_MARGIN;
        r32 image_y2 = static_cast<r32>(image_y) - 0.5f - SIZE_MARGIN;
        r32 image_z2 = static_cast<r32>(image_z) - 0.5f - SIZE_MARGIN;

        r32 width2 = face->width + SIZE_MARGIN * 2.0f;
        r32 height2 = face->height + SIZE_MARGIN * 2.0f;

        r32 cube_x, cube_y, cube_z;

        calcCubePos(&cube_x, &cube_y, &cube_z, direction, image_x2, image_y2, image_z2);
        vert[0].set(cube_x, cube_y, cube_z);

        calcCubePos(&cube_x, &cube_y, &cube_z, direction, image_x2, image_y2 + height2, image_z2);
        vert[1].set(cube_x, cube_y, cube_z);

        calcCubePos(&cube_x, &cube_y, &cube_z, direction, image_x2 + width2, image_y2 + height2, image_z2);
        vert[2].set(cube_x, cube_y, cube_z);

        calcCubePos(&cube_x, &cube_y, &cube_z, direction, image_x2 + width2, image_y2, image_z2);
        vert[5].set(cube_x, cube_y, cube_z);

        fsVec offset = fsVec(1.0f, 1.0f, 1.0f) * (static_cast<r32>(m_side_length - 1) * 0.5f);

        vert[0] -= offset;
        vert[1] -= offset;
        vert[2] -= offset;
        vert[5] -= offset;

        vert[3] = vert[0];
        vert[4] = vert[2];
    }
Esempio n. 10
0
Map* Map::getSubMap( int x, int y, int z, int rad )
{
  int *coord;
  coord = new int[6];
  if(!getSubMapCoord(x,y,z,rad,coord))
  {
    delete coord;
    return NULL;
  }

  // Set transparent and infection in new map
  Map *map = new Map(coord[5] - coord[4] + 1,
                     coord[3] - coord[2] + 1,
                     coord[1] - coord[0] + 1);

  if(!map)
  {
    delete coord;
    return NULL;
  }

  for( int i = coord[4]; i <= coord[5]; i++ )
    for( int j = coord[2]; j <= coord[3]; j++ )
      for( int k = coord[0]; k <= coord[1]; k++ )
      {
        Cube *cubeT, *cubeO;
        cubeT = getCube(k, i, j);
        cubeO = map->getCube(k-coord[0], i-coord[4], j-coord[2]);
        if(cubeT && cubeO)
        {
          cubeO->setInfection(cubeT->getInfection());
          cubeO->setTransparent(cubeT->isTransparent());
        }
      }

  delete coord;
  return map;
}
Esempio n. 11
0
void mbChargeLattice::connectLatticeObjects() {
	int cubeIndex = 0;
	int edgeIndex = 0;
	mbLatticeCube *cubePointer, *adjacentCube;
	int* latticePosition;
	mbLatticeEdge** edges;
	mbLatticePoint** points;
	int iX, iY, iZ;
	for (iX = 0; iX < xDim; iX++)
		for (iY = 0; iY < yDim; iY++)
			for (iZ = 0; iZ < zDim; iZ++)
			{
				cubePointer = &latticeCubes[cubeIndex];
				cubeIndex++;
				latticePosition = cubePointer->latticePosition;
				latticePosition[0] = iX;
				latticePosition[1] = iY;
				latticePosition[2] = iZ;
				points = cubePointer->points;
				points[0] = getPoint(iX, iY, iZ);
				points[1] = getPoint(iX + 1, iY, iZ);
				points[2] = getPoint(iX + 1, iY + 1, iZ);
				points[3] = getPoint(iX, iY + 1, iZ);
				points[4] = getPoint(iX, iY, iZ + 1);
				points[5] = getPoint(iX + 1, iY, iZ + 1);
				points[6] = getPoint(iX + 1, iY + 1, iZ + 1);
				points[7] = getPoint(iX, iY + 1, iZ + 1);
				edges = cubePointer->edges;
				edges[5] = &latticeEdges[edgeIndex++];
				edges[5]->axis = Y_AXIS;
				edges[6] = &latticeEdges[edgeIndex++];
				edges[6]->axis = X_AXIS;
				edges[10] = &latticeEdges[edgeIndex++];
				edges[10]->axis = Z_AXIS;
				adjacentCube = getCube(iX + 1, iY, iZ);
				if (adjacentCube)
				{
					adjacentCube->edges[11] = edges[10];
					adjacentCube->edges[7] = edges[5];
				}
				adjacentCube = getCube(iX, iY + 1, iZ);
				if (adjacentCube)
				{
					adjacentCube->edges[4] = edges[6];
					adjacentCube->edges[9] = edges[10];
				}
				adjacentCube = getCube(iX, iY + 1, iZ + 1);
				if (adjacentCube)
				{
					adjacentCube->edges[0] = edges[6];
				}
				adjacentCube = getCube(iX + 1, iY, iZ + 1);
				if (adjacentCube)
				{
					adjacentCube->edges[3] = edges[5];
				}
				adjacentCube = getCube(iX + 1, iY + 1, iZ);
				if (adjacentCube)
				{
					adjacentCube->edges[8] = edges[10];
				}
				adjacentCube = getCube(iX, iY, iZ + 1);
				if (adjacentCube)
				{
					adjacentCube->edges[1] = edges[5];
					adjacentCube->edges[2] = edges[6];
				}
				if (!edges[0]) {
					edges[0] = &latticeEdges[edgeIndex++];
					edges[0]->axis = X_AXIS;
				}
				if (!edges[1]) {
					edges[1] = &latticeEdges[edgeIndex++];
					edges[1]->axis = Y_AXIS;
				}
				if (!edges[2]) {
					edges[2] = &latticeEdges[edgeIndex++];
					edges[2]->axis = X_AXIS;
				}
				if (!edges[3]) {
					edges[3] = &latticeEdges[edgeIndex++];
					edges[3]->axis = Y_AXIS;
				}
				if (!edges[4]) {
					edges[4] = &latticeEdges[edgeIndex++];
					edges[4]->axis = X_AXIS;
				}
				if (!edges[7]) {
					edges[7] = &latticeEdges[edgeIndex++];
					edges[7]->axis = Y_AXIS;
				}
				if (!edges[8]) {
					edges[8] = &latticeEdges[edgeIndex++];
					edges[8]->axis = Z_AXIS;
				}
				if (!edges[9]) {
					edges[9] = &latticeEdges[edgeIndex++];
					edges[9]->axis = Z_AXIS;
				}
				if (!edges[11]) {
					edges[11] = &latticeEdges[edgeIndex++];
					edges[11]->axis = Z_AXIS;
				}
			}
};
 void eraseFace(DirectionType direction, u16 image_x, u16 image_y, u16 image_z)
 {
     fsMemHelper::memset(getCube(direction, image_x, image_y, image_z)->face + direction, 0, sizeof(Face));
 }
 bool hasFace(DirectionType direction, u16 image_x, u16 image_y, u16 image_z)
 {
     return (getCube(direction, image_x, image_y, image_z)->face[direction].width > 0);
 }
 void setCubeColor(DirectionType direction, u16 image_x, u16 image_y, u16 image_z, fsCol col)
 {
     getCube(direction, image_x, image_y, image_z)->col = col;
 }
 fsCol getCubeColor(DirectionType direction, u16 image_x, u16 image_y, u16 image_z)
 {
     return getCube(direction, image_x, image_y, image_z)->col;
 }
 void eraseCube(DirectionType direction, u16 image_x, u16 image_y, u16 image_z)
 {
     fsMemHelper::memset(getCube(direction, image_x, image_y, image_z), 0, sizeof(Cube));
 }