static bool tile_size_ok(const gx_device_pdf *pdev, const gx_color_tile *p_tile, const gx_color_tile *m_tile) { /* * Acrobat Reader can't handle image Patterns with more than * 64K of data. :-( */ uint p_size = (p_tile == 0 ? 0 : tile_size(&p_tile->tbits, p_tile->depth)); uint m_size = (m_tile == 0 ? 0 : tile_size(&m_tile->tmask, 1)); return (max(p_size, m_size) <= 65500); }
void gimp_paint_core_validate_canvas_tiles (GimpPaintCore *core, gint x, gint y, gint w, gint h) { gint i, j; g_return_if_fail (GIMP_IS_PAINT_CORE (core)); g_return_if_fail (core->canvas_tiles != NULL); for (i = y; i < (y + h); i += (TILE_HEIGHT - (i % TILE_HEIGHT))) { for (j = x; j < (x + w); j += (TILE_WIDTH - (j % TILE_WIDTH))) { Tile *tile = tile_manager_get_tile (core->canvas_tiles, j, i, FALSE, FALSE); if (! tile_is_valid (tile)) { tile = tile_manager_get_tile (core->canvas_tiles, j, i, TRUE, TRUE); memset (tile_data_pointer (tile, 0, 0), 0, tile_size (tile)); tile_release (tile, TRUE); } } } }
static bool tile_size_ok(const gx_device_pdf *pdev, const gx_color_tile *p_tile, const gx_color_tile *m_tile) { /* * Acrobat Reader can't handle image Patterns with more than * 64K of data. :-( */ uint p_size = (p_tile == 0 ? 0 : tile_size(&p_tile->tbits, p_tile->depth)); uint m_size = (m_tile == 0 ? 0 : tile_size(&m_tile->tmask, 1)); /* The image limit only applies to Acrobat versions less than 5 * (PDF 1.4). */ if (pdev->CompatibilityLevel < 1.4) return (max(p_size, m_size) <= 65500); else return 1; }
void tile_cache_flush (Tile *tile) { GList *tmp; if (initialize) tile_cache_init (); /* Find where the tile is in the cache. */ tmp = g_hash_table_lookup (tile_hash_table, tile); if (tmp) { /* If the tile is in the cache, then remove it from the * tile list. */ if (tmp == tile_list_tail) tile_list_tail = tile_list_tail->prev; tile_list_head = g_list_remove_link (tile_list_head, tmp); if (!tile_list_head) tile_list_tail = NULL; g_list_free (tmp); /* Remove the tile from the tile hash table. */ g_hash_table_remove (tile_hash_table, tile); /* Note the decrease in the number of bytes the cache * is referencing. */ cur_cache_size -= tile_size (tile); /* Unreference the tile. * "tile_unref" may be used here since it does not call * this function (or any of the cache functions). */ tile_unref (tile, FALSE); } }
void tileMap(){ sf::RenderWindow window(sf::VideoMode(512, 256), "Tilemap"); sf::View view(sf::Vector2f(0, 0), sf::Vector2f(window.getSize())); sf::View minimap(view.getCenter(), view.getSize()*2.f); minimap.setViewport(sf::FloatRect(0.75f, 0, 0.25f, 0.25f)); sf::Texture tileset; tileset.loadFromFile("terrain-6.png"); sf::Vector2f player_position(90, 90); sf::Vector2f zone_center(player_position); sf::Vector2u tim(300, 300); //Tiles in Map sf::Vector2u tiz(25, 25); // Tiles in Zone sf::Vector2u tile_size(32, 32); sf::Vector2u tex_tile_size(tileset.getSize()/16u); sf::Vector2f zone_size(tiz.x*tile_size.x, tiz.y*tile_size.y); std::vector<uint8_t> tiles(tiz.x*tiz.y); sf::VertexArray vertices(sf::Quads, tiz.x*tiz.y*4); std::ifstream map_file; map_file.open("map.data", std::ifstream::binary); //map_file.read(reinterpret_cast<char*> (&tiles[0]), tiles.size() * sizeof(tiles[0])); while (window.isOpen()){ sf::Event event; while (window.pollEvent(event)){ if(event.type == sf::Event::Closed) window.close(); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){ player_position.x-=2; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){ player_position.x+=2; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){ player_position.y-=1; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){ player_position.y+=1; } if (std::abs(player_position.x - zone_center.x) > zone_size.x || std::abs(player_position.y - zone_center.y) > zone_size.y){ for (int y = (player_position.y - ((tiz.y-1)/2)); y <= player_position.y + ((tiz.y-1)/2); y++){ int x = (player_position.x - ((tiz.x-1)/2)); int n = y*tiz.x+x; map_file.read(reinterpret_cast<char*> (&tiles[n]), tim.x * sizeof(tiles[0])); } for (size_t y=0; y<tiz.y; y++){ for (size_t x=0; x<tiz.x; x++){ sf::Vertex* quad = &vertices[(y*tiz.x+x)*4]; quad[0].position = sf::Vector2f(y*tile_size.x, x*tile_size.y); quad[1].position = sf::Vector2f((y+1)*tile_size.x, x*tile_size.y); quad[2].position = sf::Vector2f((y+1)*tile_size.x, (x+1)*tile_size.y); quad[3].position = sf::Vector2f(y*tile_size.x, (x+1)*tile_size.y); const int tile_id = tiles[y*tiz.x+x]; const int tx = tile_id % (tileset.getSize().x / tex_tile_size.x); const int ty = tile_id / (tileset.getSize().x / tex_tile_size.x); quad[0].texCoords = sf::Vector2f(tx*tex_tile_size.x, ty*tex_tile_size.y); quad[1].texCoords = sf::Vector2f((tx+1)*tex_tile_size.x, ty*tex_tile_size.y); quad[2].texCoords = sf::Vector2f((tx+1)*tex_tile_size.x, (ty+1)*tex_tile_size.y); quad[3].texCoords = sf::Vector2f(tx*tex_tile_size.x, (ty+1)*tex_tile_size.y); } } } window.clear(sf::Color::White); window.setView(view); view.setCenter(player_position); window.draw(vertices, &tileset); minimap.setCenter(view.getCenter()); window.setView(minimap); window.draw(vertices, &tileset); window.display(); sf::sleep(sf::milliseconds(10)); } }
// Parse the command line a use options to override the MapConfig defaults bool parseCommandLine(MapConfig& config, QString& error) { QCommandLineParser parser; const QCommandLineOption helpOption = parser.addHelpOption(); QCommandLineOption server(QStringList() << "s" << "server-url", QCoreApplication::translate("main", "Map tile server URL with trailing /"), QCoreApplication::translate("main", "URL")); parser.addOption(server); QCommandLineOption format(QStringList() << "f" << "image-format", QCoreApplication::translate("main", "Map tile image format (e.g. png)"), QCoreApplication::translate("main", "format")); parser.addOption(format); QCommandLineOption min_zoom(QStringList() << "min-zoom", QCoreApplication::translate("main", "Map minimum zoom level"), QCoreApplication::translate("main", "zoom")); parser.addOption(min_zoom); QCommandLineOption max_zoom(QStringList() << "max-zoom", QCoreApplication::translate("main", "Map maximum zoom level"), QCoreApplication::translate("main", "zoom")); parser.addOption(max_zoom); QCommandLineOption tile_size(QStringList() << "t" << "tile-size", QCoreApplication::translate("main", "Map tile size in pixels (e.g. 256)"), QCoreApplication::translate("main", "size")); parser.addOption(tile_size); QCommandLineOption cache_size(QStringList() << "c" << "cache-size", QCoreApplication::translate("main", "Map tile cache size in tiles (e.g. 512)"), QCoreApplication::translate("main", "cache")); parser.addOption(cache_size); if (!parser.parse(QGuiApplication::arguments())) { error = parser.errorText(); return true; } if (parser.isSet(helpOption)) { parser.showHelp(); return false; } if (parser.isSet(server)) { QString s = parser.value(server); QHostInfo info = QHostInfo::fromName(s); if (info.error() == QHostInfo::NoError) { config.server = s; } else { qDebug() << "Invalid map tile server URL: " << s; } } if (parser.isSet(format)) { config.format = parser.value(format); } if (parser.isSet(min_zoom)) { QVariant range(parser.value(min_zoom)); config.min_zoom = range.toInt(); } if (parser.isSet(max_zoom)) { QVariant range(parser.value(max_zoom)); config.max_zoom = range.toInt(); } if (parser.isSet(tile_size)) { QVariant range(parser.value(tile_size)); config.tile_size = range.toInt(); } if (parser.isSet(cache_size)) { QVariant range(parser.value(cache_size)); config.cache_size = size_t(range.toInt()); } return false; }
void tile_cache_insert (Tile *tile) { GList *tmp; if (initialize) tile_cache_init (); /* First check and see if the tile is already * in the cache. In that case we will simply place * it at the end of the tile list to indicate that * it was the most recently accessed tile. */ tmp = g_hash_table_lookup (tile_hash_table, tile); if (tmp) { /* The tile was already in the cache. Place it at * the end of the tile list. */ if (tmp == tile_list_tail) tile_list_tail = tile_list_tail->prev; tile_list_head = g_list_remove_link (tile_list_head, tmp); if (!tile_list_head) tile_list_tail = NULL; g_list_free (tmp); /* Remove the old reference to the tiles list node * in the tile hash table. */ g_hash_table_remove (tile_hash_table, tile); tile_list_tail = g_list_append (tile_list_tail, tile); if (!tile_list_head) tile_list_head = tile_list_tail; tile_list_tail = g_list_last (tile_list_tail); /* Add the tiles list node to the tile hash table. The * list node is indexed by the tile itself. This makes * for a quick lookup of which list node the tile is in. */ g_hash_table_insert (tile_hash_table, tile, tile_list_tail); } else { /* The tile was not in the cache. First check and see * if there is room in the cache. If not then we'll have * to make room first. Note: it might be the case that the * cache is smaller than the size of a tile in which case * it won't be possible to put it in the cache. */ if ((cur_cache_size + max_tile_size) > max_cache_size) { while (tile_list_head && (cur_cache_size + max_cache_size * FREE_QUANTUM) > max_cache_size) tile_cache_zorch_next (); if ((cur_cache_size + max_tile_size) > max_cache_size) return; } /* Place the tile at the end of the tile list. */ tile_list_tail = g_list_append (tile_list_tail, tile); if (!tile_list_head) tile_list_head = tile_list_tail; tile_list_tail = g_list_last (tile_list_tail); /* Add the tiles list node to the tile hash table. */ g_hash_table_insert (tile_hash_table, tile, tile_list_tail); /* Note the increase in the number of bytes the cache * is referencing. */ cur_cache_size += tile_size (tile); /* Reference the tile so that it won't be swapped out * to disk. Swap the tile in if necessary. * "tile_ref" cannot be used here since it calls this * function. */ tile->ref_count += 1; { extern int tile_ref_count; tile_ref_count += 1; } if (tile->ref_count == 1) { tile_swap_in (tile); /* the tile must be clean */ tile->dirty = FALSE; } } }
void Save::save(const Image & in, const Image_Io_Frame_Info & frame) throw (Error) { //DJV_DEBUG("Save::save"); //DJV_DEBUG_PRINT("in = " << in); // Open the file. _open(_file.get(frame.frame)); // Convert the image. const Pixel_Data * p = ∈ if (in.info() != _info) { //DJV_DEBUG_PRINT("convert = " << _image); _image.zero(); Gl_Image::copy(in, _image); p = &_image; } // Write the file. const int w = p->w(), h = p->h(); const int channels = Pixel::channels(p->info().pixel); const int channel_bytes = Pixel::channel_bytes(p->info().pixel); const int bytes = Pixel::bytes(p->info().pixel); bool compress = _options.compression ? true : false; uint32_t length = 0; //DJV_DEBUG_PRINT("channels = " << channels); //DJV_DEBUG_PRINT("channel_bytes = " << channel_bytes); //DJV_DEBUG_PRINT("bytes = " << bytes); size_t pos = 0; pos = _io.position(); //DJV_DEBUG_PRINT("position = " << static_cast<int>(pos)); // 'FOR4' type _io.set_u8('F'); _io.set_u8('O'); _io.set_u8('R'); _io.set_u8('4'); // 'FOR4' length // NOTE: only reserved for now. _io.set_u32(length); // 'TBMP' type _io.set_u8('T'); _io.set_u8('B'); _io.set_u8('M'); _io.set_u8('P'); // Write tiles. V2i size = tile_size (w, h); // Y order. for (int y = 0; y < size.y; y++) { // X order. for (int x = 0; x < size.x; x++) { // Set tile coordinates. uint16_t xmin, xmax, ymin, ymax; // Set xmin and xmax. xmin = x * tile_width(); xmax = Math::min(xmin + tile_width(), w) - 1; // Set ymin and ymax. ymin = y * tile_height(); ymax = Math::min(ymin + tile_height(), h) - 1; // Set width and height. uint32_t tw = xmax - xmin + 1; uint32_t th = ymax - ymin + 1; // Set type. _io.set_u8('R'); _io.set_u8('G'); _io.set_u8('B'); _io.set_u8('A'); // Length. uint32_t length = tw * th * bytes; // Tile length. uint32_t tile_length = length; // Align. length = align_size(length, 4); // Append xmin, xmax, ymin and ymax. length += 8; // Tile compression. bool tile_compress = compress; // Set bytes. Memory_Buffer<uint8_t> tile(tile_length); uint8_t * out_p = tile(); // Handle 8-bit data. if (p->info().pixel == Pixel::RGB_U8 || p->info().pixel == Pixel::RGBA_U8) { if (tile_compress) { uint32_t index = 0, size = 0; // Set bytes. // NOTE: prevent buffer overrun. Memory_Buffer<uint8_t> tmp(tile_length * 2); // Map: RGB(A)8 RGBA to BGRA for (int c = (channels * channel_bytes) - 1; c >= 0; --c) { Memory_Buffer<uint8_t> in(tw * th); uint8_t * in_p = in(); // Data. for (uint16_t py = ymin; py <= ymax; py++) { const uint8_t * in_dy = p->data(0, py); for (uint16_t px = xmin; px <= xmax; px++) { // Get pixel. uint8_t pixel; const uint8_t * in_dx = in_dy + px * bytes + c; Memory::copy(in_dx, &pixel, 1); // Set pixel. *in_p++ = pixel; } } // Compress size = rle_save(in(), tmp() + index, tw * th); index += size; } // If size exceeds tile length use uncompressed. if (index < tile_length) { Memory::copy(tmp(), tile(), index); // Set tile length. tile_length = index; // Append xmin, xmax, ymin and ymax. length = index + 8; // Set length. uint32_t align = align_size(length, 4); if (align > length) { out_p = tile() + index; // Pad. for (int i = 0; i < static_cast<int>(align - length); i++) { *out_p++ = '\0'; tile_length++; } } } else { tile_compress = false; } } if (!tile_compress) { for (uint16_t py = ymin; py <= ymax; py++) { const uint8_t * in_dy = p->data(0, py); for (uint16_t px = xmin; px <= xmax; px++) { // Map: RGB(A)8 RGBA to BGRA for (int c = channels - 1; c >= 0; --c) { // Get pixel. uint8_t pixel; const uint8_t * in_dx = in_dy + px * bytes + c * channel_bytes; Memory::copy(in_dx, &pixel, 1); // Set pixel. *out_p++ = pixel; } } } } } // Handle 16-bit data. else if ( p->info().pixel == Pixel::RGB_U16 || p->info().pixel == Pixel::RGBA_U16) { if (tile_compress) { uint32_t index = 0, size = 0; // Set bytes. // NOTE: prevent buffer overrun. Memory_Buffer<uint8_t> tmp(tile_length * 2); // Set map. int* map = NULL; if (Memory::endian () == Memory::LSB) { int rgb16[] = { 0, 2, 4, 1, 3, 5 }; int rgba16[] = { 0, 2, 4, 7, 1, 3, 5, 6 }; if (_info.pixel == Pixel::RGB_U16) { map = rgb16; } else { map = rgba16; } } else { int rgb16[] = { 1, 3, 5, 0, 2, 4 }; int rgba16[] = { 1, 3, 5, 7, 0, 2, 4, 6 }; if (_info.pixel == Pixel::RGB_U16) { map = rgb16; } else { map = rgba16; } } // Map: RGB(A)16 RGBA to BGRA for (int c = (channels * channel_bytes) - 1; c >= 0; --c) { int mc = map[c]; Memory_Buffer<uint8_t> in(tw * th); uint8_t * in_p = in(); // Data. for (uint16_t py = ymin; py <= ymax; py++) { const uint8_t * in_dy = p->data(0, py); for (uint16_t px = xmin; px <= xmax; px++) { // Get pixel. uint8_t pixel; const uint8_t * in_dx = in_dy + px * bytes + mc; Memory::copy(in_dx, &pixel, 1); // Set pixel. *in_p++ = pixel; } } // Compress size = rle_save(in(), tmp() + index, tw * th); index += size; } // If size exceeds tile length use uncompressed. if (index < tile_length) { Memory::copy(tmp(), tile(), index); // Set tile length. tile_length = index; // Append xmin, xmax, ymin and ymax. length = index + 8; // Set length. uint32_t align = align_size(length, 4); if (align > length) { out_p = tile() + index; // Pad. for ( int i = 0; i < static_cast<int>(align - length); i++) { *out_p++ = '\0'; tile_length++; } } } else { tile_compress = false; } } if (!tile_compress) { for (uint16_t py = ymin; py <= ymax; py++) { const uint8_t * in_dy = p->data(0, py); for (uint16_t px = xmin; px <= xmax; px++) { // Map: RGB(A)16 RGBA to BGRA for (int c = channels - 1; c >= 0; --c) { uint16_t pixel; const uint8_t * in_dx = in_dy + px * bytes + c * channel_bytes; if (Memory::endian () == Memory::LSB) { Memory::endian(in_dx, &pixel, 1, 2); } else { Memory::copy(in_dx, &pixel, 2); } // Set pixel. *out_p++ = pixel; out_p++; } } } } } // Set length. _io.set_u32(length); // Set xmin, xmax, ymin and ymax. _io.set_u16(xmin); _io.set_u16(ymin); _io.set_u16(xmax); _io.set_u16(ymax); // Write. _io.set(tile(), tile_length); } } // Set FOR4 CIMG and FOR4 TBMP size uint32_t p0 = _io.position() - 8; uint32_t p1 = p0 - pos; // NOTE: FOR4 <size> CIMG _io.position (4); _io.set_u32 (p0); // NOTE: FOR4 <size> TBMP _io.position (pos + 4); _io.set_u32 (p1); _io.close(); }
sf::Vector2f Colisionable::evalCollisions(sf::Vector2f posOld, sf::Vector2f posNew, sf::Vector2f size){ /* float dist= sqrt((posNew.x-posOld.x)*(posNew.x-posOld.x)+(posNew.y-posOld.y)*(posNew.y-posOld.y)); while(dist>Settings::TILE_SIZE){ sf::Vector2f posOldOld = posOld; float ratio = (Settings::TILE_SIZE-1)/dist; sf::Vector2f newPosAux(((1-ratio)*posOld.x+ratio*posNew.x),((1-ratio)*posOld.y+ratio*posNew.y)); posOld = evalCollisions(posOld,newPosAux,size); if(posOldOld == posOld) return posOld; dist= sqrt((posNew.x-posOld.x)*(posNew.x-posOld.x)+(posNew.y-posOld.y)*(posNew.y-posOld.y)); }*/ sf::Vector2f pos_aux(posNew.x, posNew.y); sf::Vector2f size_aux(size.x, size.y); Map* map = Scene::getScene()->getMap(); Tile* firstT = map->getTile(pos_aux.x, pos_aux.y, 1); Tile* lastT = map->getTile(pos_aux.x+size_aux.x, pos_aux.y+size_aux.y, 1); if(firstT != nullptr && lastT != nullptr){ col_bottom = 0; col_top = 0; col_left = 0; col_right = 0; col_bottom_dist = 0; col_top_dist = 0; col_left_dist = 0; col_right_dist = 0; std::vector<Tile*> tiles_col = map->getTilesCol(pos_aux, size_aux); //std::cout << "number of cols" << tiles_col._size() << std::endl; //std::cout << "lel" << std::endl; for(int i = 0; i< tiles_col.size(); ++i){ // //comproba colisions Tile* t = tiles_col[i]; sf::Vector2f tile_size(t->getWidth(), t->getHeight()); FixColision(pos_aux, size_aux, t->GetPosition(), tile_size); } bool valid_move = true; if(bool(col_bottom) + bool(col_left) + bool(col_right) + bool(col_top) >=3) valid_move = false; if(abs(posNew.x-posOld.x) > Settings::TILE_SIZE*3 || abs(posNew.y-posOld.y) > Settings::TILE_SIZE*3) { //float dist= sqrt((posNew.x-posOld.x)*(posNew.x-posOld.x)+(posNew.y-posOld.y)*(posNew.y-posOld.y)); valid_move = false; } if(col_bottom >= col_top){ col_top = 0; posNew.y = posNew.y - col_bottom_dist; } else{ col_bottom = 0; posNew.y = posNew.y + col_top_dist; } if(col_left >= col_right){ col_right = 0; posNew.x = posNew.x + col_left_dist; } else{ col_left = 0; posNew.x = posNew.x - col_right_dist; } if(valid_move) return posNew; else { return evalCollisions(sf::Vector2f(posOld.x,posOld.y-32),sf::Vector2f(posOld.x,posOld.y-32),size); } } return posOld; }