void ControlCubeCache::_freeCache() { if (cudaSuccess != cudaSetDevice(_device)) { std::cerr<<"Control Cube Cache, error setting device: "<<cudaGetErrorString(cudaGetLastError())<<std::endl; throw; } if (_memory != 0) { if(cudaSuccess != cudaFree((void*)_memory)) { std::cerr<<"Control Cubes Cache, error free memory: "<<cudaGetErrorString(cudaGetLastError())<<std::endl; throw; } _memory = 0; } #ifdef TIMING int dim = exp2(_nLevels); index_node_t s = coordinateToIndex(vmml::vector<3, int>(0,0,0), _levelCube, _nLevels); index_node_t e = coordinateToIndex(vmml::vector<3, int>(dim-1, dim-1, dim-1), _levelCube, _nLevels); std::cout<<"==== CONTROL CUBE CACHE ====="<<std::endl; std::cout<<"Max num cubes "<< _maxNumCubes<<" cubes form "<<s<<" to "<<e<<" total "<<e-s+1<<std::endl; #endif ControlElementCache::_freeCache(); #ifdef TIMING std::cout<<"=============================="<<std::endl; #endif }
void Board::mouseOver(int x, int y) { //check if inside boundaries or able to interact if(!insideBoundaries(x,y) || mSwitching || !mMousePressed) return; //transform screen coordinates to index on vector Point xy = coordinateToIndex(x,y); int index = XYCoordinatesToIndex(xy); //select it selecteGemAtPoint(xy); mTiles[index]->mouseOver(x,y); }
void Board::mousePressed(int x, int y) { if(!insideBoundaries(x,y) || mSwitching) return; mMousePressed = true; //transform screen coordinates to index on vector Point xy = coordinateToIndex(x,y); int index = XYCoordinatesToIndex(xy); //select it selecteGemAtPoint(xy); mTiles[index]->mousePressed(x,y); }
void ControlCubeCache::_reSizeCache() { _nLevels = _nextnLevels; _levelCube = _nextLevelCube; _offset = _nextOffset; _nextnLevels = 0; _nextLevelCube = 0; _dimCube = exp2(_nLevels - _levelCube) + 2 * CUBE_INC; _sizeElement = pow(_dimCube, 3); int dimV = exp2(_nLevels); _minValue = coordinateToIndex(vmml::vector<3,int>(0,0,0), _levelCube, _nLevels); _maxValue = coordinateToIndex(vmml::vector<3,int>(dimV-1,dimV-1,dimV-1), _levelCube, _nLevels); int dc = exp2(_nLevels - _levelCube); vmml::vector<3,int> mn = _cpuCache->getMinCoord(); vmml::vector<3,int> mx = _cpuCache->getMaxCoord(); _maxC = mx - mn; if ((mx.x() - mn.x()) % dc != 0) _maxC[0] += dc; if ((mx.y() - mn.y()) % dc != 0) _maxC[1] += dc; if ((mx.z() - mn.z()) % dc != 0) _maxC[2] += dc; if (cudaSuccess != cudaSetDevice(_device)) { std::cerr<<"Control Cube Cache, error setting device: "<<cudaGetErrorString(cudaGetLastError())<<std::endl; throw; } if (_memory != 0) if (cudaSuccess != cudaFree((void*)_memory)) { std::cerr<<"Control Cube Cache, error resizing cache: "<<cudaGetErrorString(cudaGetLastError())<<std::endl; throw; } size_t total = 0; size_t free = 0; if (cudaSuccess != cudaMemGetInfo(&free, &total)) { std::cerr<<"Control Cube Cache, error resizing cache: "<<cudaGetErrorString(cudaGetLastError())<<std::endl; throw; } float memorySize = (0.80f*free); // Get 80% of free memory _maxNumCubes = memorySize/ (_sizeElement*sizeof(float)); if (_maxNumCubes == 0) { std::cerr<<"Control Cube Cache: Memory aviable is not enough "<<memorySize/1024/1024<<" MB"<<std::endl; throw; } if (cudaSuccess != cudaMalloc((void**)&_memory, _maxNumCubes*_sizeElement*sizeof(float))) { std::cerr<<"Control Cube Cache, error resizing cache: "<<cudaGetErrorString(cudaGetLastError())<<std::endl; throw; } _freeSlots = _maxNumCubes; ControlElementCache::_reSizeCache(); }