1998-01-22 15:02:57 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1998-01-22 15:02:57 +08:00
|
|
|
*/
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "tile_cache.h"
|
|
|
|
#include "tile_manager.h"
|
|
|
|
#include "tile_swap.h"
|
|
|
|
|
1998-01-22 15:02:57 +08:00
|
|
|
#include "tile_manager_pvt.h"
|
1998-07-08 14:41:58 +08:00
|
|
|
#include "tile_pvt.h" /* ick. */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-07-13 07:01:33 +08:00
|
|
|
static int tile_manager_get_tile_num (TileManager *tm,
|
|
|
|
int xpixel,
|
1998-08-16 03:17:36 +08:00
|
|
|
int ypixel);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
TileManager*
|
|
|
|
tile_manager_new (int toplevel_width,
|
|
|
|
int toplevel_height,
|
|
|
|
int bpp)
|
|
|
|
{
|
|
|
|
TileManager *tm;
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
tm = g_new (TileManager, 1);
|
|
|
|
|
|
|
|
tm->user_data = NULL;
|
|
|
|
tm->validate_proc = NULL;
|
|
|
|
|
|
|
|
width = toplevel_width;
|
|
|
|
height = toplevel_height;
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
tm->width = width;
|
|
|
|
tm->height = height;
|
|
|
|
tm->bpp = bpp;
|
|
|
|
tm->ntile_rows = (height + TILE_HEIGHT - 1) / TILE_HEIGHT;
|
|
|
|
tm->ntile_cols = (width + TILE_WIDTH - 1) / TILE_WIDTH;
|
|
|
|
tm->tiles = NULL;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return tm;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tile_manager_destroy (TileManager *tm)
|
|
|
|
{
|
1998-08-16 03:17:36 +08:00
|
|
|
int ntiles;
|
1997-11-25 06:05:25 +08:00
|
|
|
int i;
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
if (tm->tiles)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-08-16 03:17:36 +08:00
|
|
|
ntiles = tm->ntile_rows * tm->ntile_cols;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
for (i = 0; i < ntiles; i++)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-08-16 03:17:36 +08:00
|
|
|
TILE_MUTEX_LOCK (tm->tiles[i]);
|
|
|
|
tile_detach (tm->tiles[i], tm, i);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
g_free (tm->tiles);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
g_free (tm);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
|
|
|
tile_manager_set_validate_proc (TileManager *tm,
|
|
|
|
TileValidateProc proc)
|
|
|
|
{
|
|
|
|
tm->validate_proc = proc;
|
|
|
|
}
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
Tile*
|
|
|
|
tile_manager_get_tile (TileManager *tm,
|
|
|
|
int xpixel,
|
|
|
|
int ypixel,
|
1998-07-10 10:43:12 +08:00
|
|
|
int wantread,
|
|
|
|
int wantwrite)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
int tile_num;
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
tile_num = tile_manager_get_tile_num (tm, xpixel, ypixel);
|
1998-07-13 07:01:33 +08:00
|
|
|
if (tile_num < 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
return NULL;
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
return tile_manager_get (tm, tile_num, wantread, wantwrite);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Tile*
|
|
|
|
tile_manager_get (TileManager *tm,
|
|
|
|
int tile_num,
|
1998-07-10 10:43:12 +08:00
|
|
|
int wantread,
|
|
|
|
int wantwrite)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-07-10 10:43:12 +08:00
|
|
|
Tile **tiles;
|
|
|
|
Tile **tile_ptr;
|
1997-11-25 06:05:25 +08:00
|
|
|
int ntiles;
|
|
|
|
int nrows, ncols;
|
|
|
|
int right_tile;
|
|
|
|
int bottom_tile;
|
|
|
|
int i, j, k;
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
ntiles = tm->ntile_rows * tm->ntile_cols;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if ((tile_num < 0) || (tile_num >= ntiles))
|
|
|
|
return NULL;
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
if (!tm->tiles)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-08-16 03:17:36 +08:00
|
|
|
tm->tiles = g_new (Tile*, ntiles);
|
|
|
|
tiles = tm->tiles;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
nrows = tm->ntile_rows;
|
|
|
|
ncols = tm->ntile_cols;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
right_tile = tm->width - ((ncols - 1) * TILE_WIDTH);
|
|
|
|
bottom_tile = tm->height - ((nrows - 1) * TILE_HEIGHT);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 0, k = 0; i < nrows; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < ncols; j++, k++)
|
|
|
|
{
|
1998-07-10 10:43:12 +08:00
|
|
|
tiles[k] = g_new (Tile, 1);
|
1998-08-16 03:17:36 +08:00
|
|
|
tile_init (tiles[k], tm->bpp);
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_attach (tiles[k], tm, k);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (j == (ncols - 1))
|
1998-07-10 10:43:12 +08:00
|
|
|
tiles[k]->ewidth = right_tile;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (i == (nrows - 1))
|
1998-07-10 10:43:12 +08:00
|
|
|
tiles[k]->eheight = bottom_tile;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
tile_ptr = &tm->tiles[tile_num];
|
1998-07-10 10:43:12 +08:00
|
|
|
|
|
|
|
if (wantread)
|
|
|
|
{
|
|
|
|
TILE_MUTEX_LOCK (*tile_ptr);
|
|
|
|
if (wantwrite)
|
|
|
|
{
|
|
|
|
if ((*tile_ptr)->share_count > 1)
|
|
|
|
{
|
|
|
|
/* Copy-on-write required */
|
|
|
|
Tile *newtile = g_new (Tile, 1);
|
|
|
|
tile_init (newtile, (*tile_ptr)->bpp);
|
|
|
|
newtile->ewidth = (*tile_ptr)->ewidth;
|
|
|
|
newtile->eheight = (*tile_ptr)->eheight;
|
|
|
|
newtile->valid = (*tile_ptr)->valid;
|
|
|
|
if ((*tile_ptr)->data != NULL)
|
|
|
|
{
|
|
|
|
newtile->data = g_new (guchar, tile_size (newtile));
|
|
|
|
memcpy (newtile->data, (*tile_ptr)->data, tile_size (newtile));
|
|
|
|
}
|
|
|
|
tile_detach (*tile_ptr, tm, tile_num);
|
|
|
|
TILE_MUTEX_LOCK (newtile);
|
|
|
|
tile_attach (newtile, tm, tile_num);
|
|
|
|
*tile_ptr = newtile;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*tile_ptr)->write_count++;
|
|
|
|
(*tile_ptr)->dirty = 1;
|
|
|
|
}
|
|
|
|
TILE_MUTEX_UNLOCK (*tile_ptr);
|
|
|
|
tile_lock (*tile_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *tile_ptr;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-07-13 07:01:33 +08:00
|
|
|
void
|
|
|
|
tile_manager_get_async (TileManager *tm,
|
|
|
|
int xpixel,
|
1998-08-16 03:17:36 +08:00
|
|
|
int ypixel)
|
1998-07-13 07:01:33 +08:00
|
|
|
{
|
|
|
|
Tile *tile_ptr;
|
|
|
|
int tile_num;
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
tile_num = tile_manager_get_tile_num (tm, xpixel, ypixel);
|
1998-07-13 07:01:33 +08:00
|
|
|
if (tile_num < 0)
|
|
|
|
return;
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
tile_ptr = tm->tiles[tile_num];
|
1998-07-13 07:01:33 +08:00
|
|
|
|
|
|
|
tile_swap_in_async (tile_ptr);
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
void
|
|
|
|
tile_manager_validate (TileManager *tm,
|
|
|
|
Tile *tile)
|
|
|
|
{
|
|
|
|
tile->valid = TRUE;
|
|
|
|
|
|
|
|
if (tm->validate_proc)
|
1998-08-16 03:17:36 +08:00
|
|
|
(* tm->validate_proc) (tm, tile);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tile_manager_invalidate_tiles (TileManager *tm,
|
|
|
|
Tile *toplevel_tile)
|
|
|
|
{
|
|
|
|
double x, y;
|
|
|
|
int row, col;
|
|
|
|
int num;
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
col = toplevel_tile->tlink->tile_num % tm->ntile_cols;
|
|
|
|
row = toplevel_tile->tlink->tile_num / tm->ntile_cols;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
x = (col * TILE_WIDTH + toplevel_tile->ewidth / 2.0) / (double) tm->width;
|
|
|
|
y = (row * TILE_HEIGHT + toplevel_tile->eheight / 2.0) / (double) tm->height;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
if (tm->tiles)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-08-16 03:17:36 +08:00
|
|
|
col = x * tm->width / TILE_WIDTH;
|
|
|
|
row = y * tm->height / TILE_HEIGHT;
|
|
|
|
num = row * tm->ntile_cols + col;
|
|
|
|
tile_invalidate (&tm->tiles[num], tm, num);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
1998-07-10 10:43:12 +08:00
|
|
|
|
|
|
|
|
1998-08-12 01:35:34 +08:00
|
|
|
void
|
|
|
|
tile_invalidate_tile (Tile **tile_ptr, TileManager *tm,
|
1998-08-16 03:17:36 +08:00
|
|
|
int xpixel, int ypixel)
|
1998-08-12 01:35:34 +08:00
|
|
|
{
|
|
|
|
int tile_num;
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
tile_num = tile_manager_get_tile_num (tm, xpixel, ypixel);
|
1998-08-12 01:35:34 +08:00
|
|
|
if (tile_num < 0) return;
|
|
|
|
|
|
|
|
tile_invalidate (tile_ptr, tm, tile_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_invalidate (Tile **tile_ptr, TileManager *tm, int tile_num)
|
|
|
|
{
|
|
|
|
Tile *tile = *tile_ptr;
|
|
|
|
|
|
|
|
TILE_MUTEX_LOCK (tile);
|
|
|
|
|
|
|
|
if (!tile->valid)
|
|
|
|
goto leave;
|
|
|
|
|
|
|
|
if (tile->share_count > 1)
|
|
|
|
{
|
|
|
|
/* This tile is shared. Replace it with a new, invalid tile. */
|
|
|
|
Tile *newtile = g_new (Tile, 1);
|
|
|
|
tile_init (newtile, tile->bpp);
|
|
|
|
newtile->ewidth = tile->ewidth;
|
|
|
|
newtile->eheight = tile->eheight;
|
|
|
|
tile_detach (tile, tm, tile_num);
|
|
|
|
TILE_MUTEX_LOCK (newtile);
|
|
|
|
tile_attach (newtile, tm, tile_num);
|
|
|
|
tile = *tile_ptr = newtile;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tile->listhead)
|
|
|
|
tile_cache_flush (tile);
|
|
|
|
|
|
|
|
tile->valid = FALSE;
|
|
|
|
if (tile->data)
|
|
|
|
{
|
|
|
|
g_free (tile->data);
|
|
|
|
tile->data = NULL;
|
|
|
|
}
|
|
|
|
if (tile->swap_offset != -1)
|
|
|
|
{
|
|
|
|
/* If the tile is on disk, then delete its
|
|
|
|
* presence there.
|
|
|
|
*/
|
|
|
|
tile_swap_delete (tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
leave:
|
|
|
|
TILE_MUTEX_UNLOCK (tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
tile_manager_map_tile (TileManager *tm,
|
|
|
|
int xpixel,
|
|
|
|
int ypixel,
|
|
|
|
Tile *srctile)
|
|
|
|
{
|
|
|
|
int tile_row;
|
|
|
|
int tile_col;
|
|
|
|
int tile_num;
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
if ((xpixel < 0) || (xpixel >= tm->width) ||
|
|
|
|
(ypixel < 0) || (ypixel >= tm->height))
|
1998-07-11 06:26:22 +08:00
|
|
|
{
|
|
|
|
g_warning ("tile_manager_map_tile: tile co-ord out of range.");
|
|
|
|
return;
|
|
|
|
}
|
1998-07-10 10:43:12 +08:00
|
|
|
|
|
|
|
tile_row = ypixel / TILE_HEIGHT;
|
|
|
|
tile_col = xpixel / TILE_WIDTH;
|
1998-08-16 03:17:36 +08:00
|
|
|
tile_num = tile_row * tm->ntile_cols + tile_col;
|
1998-07-10 10:43:12 +08:00
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
tile_manager_map (tm, tile_num, srctile);
|
1998-07-10 10:43:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tile_manager_map (TileManager *tm,
|
|
|
|
int tile_num,
|
|
|
|
Tile *srctile)
|
|
|
|
{
|
|
|
|
Tile **tiles;
|
|
|
|
Tile **tile_ptr;
|
|
|
|
int ntiles;
|
|
|
|
int nrows, ncols;
|
|
|
|
int right_tile;
|
|
|
|
int bottom_tile;
|
|
|
|
int i, j, k;
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
ntiles = tm->ntile_rows * tm->ntile_cols;
|
1998-07-10 10:43:12 +08:00
|
|
|
|
|
|
|
if ((tile_num < 0) || (tile_num >= ntiles))
|
1998-07-11 06:26:22 +08:00
|
|
|
{
|
|
|
|
g_warning ("tile_manager_map: tile out of range.");
|
|
|
|
return;
|
|
|
|
}
|
1998-07-10 10:43:12 +08:00
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
if (!tm->tiles)
|
1998-07-10 10:43:12 +08:00
|
|
|
{
|
1998-07-11 06:26:22 +08:00
|
|
|
/* g_warning ("tile_manager_map: empty tile level - init'ing.");*/
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
tm->tiles = g_new (Tile*, ntiles);
|
|
|
|
tiles = tm->tiles;
|
1998-07-10 10:43:12 +08:00
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
nrows = tm->ntile_rows;
|
|
|
|
ncols = tm->ntile_cols;
|
1998-07-10 10:43:12 +08:00
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
right_tile = tm->width - ((ncols - 1) * TILE_WIDTH);
|
|
|
|
bottom_tile = tm->height - ((nrows - 1) * TILE_HEIGHT);
|
1998-07-10 10:43:12 +08:00
|
|
|
|
|
|
|
for (i = 0, k = 0; i < nrows; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < ncols; j++, k++)
|
|
|
|
{
|
1998-07-11 06:26:22 +08:00
|
|
|
/* printf(",");fflush(stdout);*/
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
tiles[k] = g_new (Tile, 1);
|
1998-08-16 03:17:36 +08:00
|
|
|
tile_init (tiles[k], tm->bpp);
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_attach (tiles[k], tm, k);
|
|
|
|
|
|
|
|
if (j == (ncols - 1))
|
|
|
|
tiles[k]->ewidth = right_tile;
|
|
|
|
|
|
|
|
if (i == (nrows - 1))
|
|
|
|
tiles[k]->eheight = bottom_tile;
|
|
|
|
}
|
|
|
|
}
|
1998-07-11 06:26:22 +08:00
|
|
|
|
|
|
|
/* g_warning ("tile_manager_map: empty tile level - done.");*/
|
1998-07-10 10:43:12 +08:00
|
|
|
}
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
tile_ptr = &tm->tiles[tile_num];
|
1998-07-10 10:43:12 +08:00
|
|
|
|
1998-07-11 06:26:22 +08:00
|
|
|
/* printf(")");fflush(stdout);*/
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
TILE_MUTEX_LOCK (*tile_ptr);
|
1998-08-02 09:52:43 +08:00
|
|
|
if ((*tile_ptr)->ewidth != srctile->ewidth ||
|
|
|
|
(*tile_ptr)->eheight != srctile->eheight ||
|
|
|
|
(*tile_ptr)->bpp != srctile->bpp) {
|
|
|
|
g_warning ("tile_manager_map: nonconformant map (%p -> %p)",
|
|
|
|
srctile, *tile_ptr);
|
1998-08-02 19:03:36 +08:00
|
|
|
}
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_detach (*tile_ptr, tm, tile_num);
|
1998-07-11 06:26:22 +08:00
|
|
|
|
|
|
|
/* printf(">");fflush(stdout);*/
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
TILE_MUTEX_LOCK (srctile);
|
1998-07-11 06:26:22 +08:00
|
|
|
|
|
|
|
/* printf(" [src:%p tm:%p tn:%d] ", srctile, tm, tile_num); fflush(stdout);*/
|
|
|
|
|
1998-07-10 10:43:12 +08:00
|
|
|
tile_attach (srctile, tm, tile_num);
|
|
|
|
*tile_ptr = srctile;
|
|
|
|
TILE_MUTEX_UNLOCK (srctile);
|
1998-07-11 06:26:22 +08:00
|
|
|
|
|
|
|
/* printf("}");fflush(stdout);*/
|
1998-07-10 10:43:12 +08:00
|
|
|
}
|
1998-07-13 07:01:33 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
tile_manager_get_tile_num (TileManager *tm,
|
|
|
|
int xpixel,
|
1998-08-16 03:17:36 +08:00
|
|
|
int ypixel)
|
1998-07-13 07:01:33 +08:00
|
|
|
{
|
|
|
|
int tile_row;
|
|
|
|
int tile_col;
|
|
|
|
int tile_num;
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
if ((xpixel < 0) || (xpixel >= tm->width) ||
|
|
|
|
(ypixel < 0) || (ypixel >= tm->height))
|
1998-07-13 07:01:33 +08:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
tile_row = ypixel / TILE_HEIGHT;
|
|
|
|
tile_col = xpixel / TILE_WIDTH;
|
1998-08-16 03:17:36 +08:00
|
|
|
tile_num = tile_row * tm->ntile_cols + tile_col;
|
1998-07-13 07:01:33 +08:00
|
|
|
|
|
|
|
return tile_num;
|
|
|
|
}
|
1998-07-29 07:13:36 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
tile_manager_set_user_data (TileManager *tm,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
tm->user_data = user_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
tile_manager_get_user_data (TileManager *tm)
|
|
|
|
{
|
|
|
|
return tm->user_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-08-16 03:17:36 +08:00
|
|
|
tile_manager_level_width (TileManager *tm)
|
1998-07-29 07:13:36 +08:00
|
|
|
{
|
1998-08-16 03:17:36 +08:00
|
|
|
return tm->width;
|
1998-07-29 07:13:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-08-16 03:17:36 +08:00
|
|
|
tile_manager_level_height (TileManager *tm)
|
1998-07-29 07:13:36 +08:00
|
|
|
{
|
1998-08-16 03:17:36 +08:00
|
|
|
return tm->height;
|
1998-07-29 07:13:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-08-16 03:17:36 +08:00
|
|
|
tile_manager_level_bpp (TileManager *tm)
|
1998-07-29 07:13:36 +08:00
|
|
|
{
|
1998-08-16 03:17:36 +08:00
|
|
|
return tm->bpp;
|
1998-07-29 07:13:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tile_manager_get_tile_coordinates (TileManager *tm, Tile *tile, int *x, int *y)
|
|
|
|
{
|
|
|
|
TileLink *tl;
|
|
|
|
|
|
|
|
for (tl = tile->tlink; tl; tl = tl->next)
|
|
|
|
{
|
|
|
|
if (tl->tm == tm) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tl == NULL)
|
|
|
|
{
|
|
|
|
g_warning ("tile_manager_get_tile_coordinates: tile not attached to manager");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-08-16 03:17:36 +08:00
|
|
|
*x = TILE_WIDTH * (tl->tile_num % tm->ntile_cols);
|
|
|
|
*y = TILE_HEIGHT * (tl->tile_num / tm->ntile_cols);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
tile_manager_map_over_tile (TileManager *tm, Tile *tile, Tile *srctile)
|
|
|
|
{
|
|
|
|
TileLink *tl;
|
|
|
|
|
|
|
|
for (tl = tile->tlink; tl; tl = tl->next)
|
|
|
|
{
|
|
|
|
if (tl->tm == tm) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tl == NULL)
|
|
|
|
{
|
|
|
|
g_warning ("tile_manager_map_over_tile: tile not attached to manager");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tile_manager_map (tm, tl->tile_num, srctile);
|
1998-07-29 07:13:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|