示例#1
0
void TileRepository::importBitmap(BITMAP* tileBitmap, const char* group_name, int tile_w, int tile_h, int tile_spacing)
{
	BITMAP *tempBitmap;
	TileType *tempTileType;
	char tempTilename[256];
	int x, y;

	ASSERT(tileBitmap);

	for (y = 0; y < (tileBitmap->h / (tile_h + tile_spacing)); y++)
	{
		for (x = 0; x < (tileBitmap->w / (tile_w + tile_spacing)); x++)
		{
			// Create a new tile type and add it to the hash_map
			tempBitmap = create_bitmap(tile_w, tile_h);
			blit(
				tileBitmap, tempBitmap,
				x * (tile_w + tile_spacing),
				y * (tile_h + tile_spacing),
				0, 0, tile_w, tile_h
			);

			sprintf(tempTilename, "%s%03d", group_name, y * (tileBitmap->w / tile_w) + x);

			tempTileType = new TileType(tempBitmap, tempTilename);
			tileTypes.insert(make_pair(tempTileType->getName(), tempTileType));
		}
	}
}
示例#2
0
void TileRepository::importDatafile(DATAFILE *file)
{
	if (!file) return;

	TileType *tempTileType;
	BITMAP *tempBitmap;

	// Import bitmaps from the datafile
	while (file->type != DAT_END) {
		switch (file->type) {
		case DAT_FILE:
			// Go recursively into nested datafiles
			importDatafile((DATAFILE*)file->dat);
			break;
		case DAT_BITMAP:
			// Create a new tile type and add it to the hash_map
			tempBitmap = create_bitmap(((BITMAP*)file->dat)->w, ((BITMAP*)file->dat)->h);
			blit((BITMAP*)file->dat, tempBitmap, 0, 0, 0, 0, tempBitmap->w, tempBitmap->h);

			tempTileType = new TileType(tempBitmap, get_datafile_property(file, DAT_ID('N','A','M','E')));

			tileTypes.insert(make_pair(tempTileType->getName(), tempTileType));
			break;
		}
		file++;
	}
}
示例#3
0
TileManager::TileManager() 
	: m_tiles(NULL)
	, m_x(0)
	, m_y(0)
	, m_updating(false)
	, m_numTypesToRender(0)
	, m_typesToRender(NULL)
{
	TileType* testType = HYDNEW TileType();
	TileType* testType2 = HYDNEW TileType();
	testType->Initialise("C:\\Assets\\01 - Default.xml");
	testType2->Initialise("C:\\Assets\\alt.xml");

	std::pair<int, TileType*> newPair;
	std::pair<int, TileType*> newPair2;

	newPair.first	= 0;
	newPair.second	= testType;

	newPair2.first	= 1;
	newPair2.second	= testType2;

	m_tileTypes.insert(newPair);
	m_tileTypes.insert(newPair2);
		
	m_typesToRender = HYDNEW_ARRAY(TileType*, MAX_TYPES_RENDERED_PER_FRAME);
}
示例#4
0
	/**
	 * Returns the name of this tile type.
	 *
	 * @returns string This tile type's name.
	 */
	int TileType_name(lua_State *lua)
	{
		TileType *tile = castUData<TileType>(lua, 1);
		if (tile)
		{
			lua_pushstring(lua, tile->getName());
			return 1;
		}
		return LuaState::expectedContext(lua, "name", "TileType");
	}
示例#5
0
void TileRepository::exportBitmap(const char *filename, int tile_w, int tile_h, int tile_spacing, int tiles_in_row)
{
	list<TileType*> tiles_to_save;
	map<const char*, TileType*, ltstr>::iterator i;
	list<TileType*>::iterator j;
	char tempTilename[256];
	char tempFilename[256];
	replace_extension(tempFilename, get_filename(filename), "", 256);

	if (!(tiles_in_row > 0 && tile_w > 0 && tile_h > 0)) {
		allegro_message("WARNING: tiles_in_row (%d), tile_w (%d) and tile_h (%d) must all be larger than 0.", tiles_in_row, tile_w, tile_h);
		return;
	}

	for (i = tileTypes.begin(); i != tileTypes.end(); i++)
	{
		TileType* tempTileType = (*i).second;
		replace_extension(tempTilename, tempTileType->getName(), "", 256);
		if (ustrcmp(tempFilename, tempTilename) == 0) {
			tiles_to_save.push_back(tempTileType);
		}
	}

	if (tiles_to_save.empty()) {
		allegro_message("WARNING: No tiles to save in %s.", filename);
		return;
	}

	BITMAP *tile_bitmap;
	PALETTE pal;

	tile_bitmap = create_bitmap
	(
		tiles_in_row * tile_w,
		(tiles_to_save.size() / tiles_in_row +
		 tiles_to_save.size() % tiles_in_row) * tile_h
	);
	int x = 0;
	int y = 0;

	for (j = tiles_to_save.begin(); j != tiles_to_save.end(); j++)
	{
		blit((*j)->getBitmap(), tile_bitmap, 0, 0, x * tile_w, y * tile_h, tile_w, tile_h);
		x++;
		if (x == tiles_in_row) {
			y++;
			x = 0;
		}
	}

	get_palette(pal);
	save_bitmap(filename, tile_bitmap, pal);

	destroy_bitmap(tile_bitmap);
}
示例#6
0
	/**
	 * Sets the full name of the tile type.
	 * This is used to display the name of the tile type to the user.
	 *
	 * @param string fullName The full name of the tile type.
	 * @returns TileType This
	 */
	int TileType_full_name(lua_State *lua)
	{
		TileType *tile = castUData<TileType>(lua, 1);
		if (tile)
		{
			if (lua_gettop(lua) == 1)
			{
				lua_pushstring(lua, tile->getFullName());
				return 1;
			}
			else if (lua_isstr(lua, 2))
			{
				tile->setFullName(lua_tostring(lua, 2));
				lua_first(lua);
			}
			return LuaState::expectedArgs(lua, "full_name", "string fullName");
		}
		return LuaState::expectedContext(lua, "full_name", "TileType");
	}
示例#7
0
void TileRepository::importBitmap(const char *filename, int tile_w, int tile_h, int tile_spacing)
{
	BITMAP *tileBitmap;
	BITMAP *tempBitmap;
	TileType *tempTileType;
	char tempTilename[256];
	char tempFilename[256];
	PALETTE pal;
	int x, y;

	tileBitmap = load_bitmap(filename, pal);
	if (!tileBitmap) {
		allegro_message("Warning, %s is not a valid tile bitmap!\n", filename);
		return;
	}

	set_palette(pal);
	replace_extension(tempFilename, get_filename(filename), "", 256);

	ASSERT(tileBitmap);

	for (y = 0; y < (tileBitmap->h / (tile_h + tile_spacing)); y++)
	{
		for (x = 0; x < (tileBitmap->w / (tile_w + tile_spacing)); x++)
		{
			// Create a new tile type and add it to the hash_map
			tempBitmap = create_bitmap(tile_w, tile_h);
			blit(
				tileBitmap, tempBitmap,
				x * (tile_w + tile_spacing),
				y * (tile_h + tile_spacing),
				0, 0, tile_w, tile_h
			);

			sprintf(tempTilename, "%s%03d", tempFilename, y * (tileBitmap->w / tile_w) + x);

			tempTileType = new TileType(tempBitmap, tempTilename);
			tileTypes.insert(make_pair(tempTileType->getName(), tempTileType));
		}
	}

	destroy_bitmap(tileBitmap);
}
示例#8
0
void DeviceCfgDbFiller::initTileTypeDb(TileTypeCfgDb& tileTypeDb,
  const TileType& tileType, size_t tileTypeIndex)
{
    // clear tile type database
    tileTypeDb.clear();

    // set its tile type
    tileTypeDb.typeIndex(tileTypeIndex);

    // clear map and copy pointer to control sets
    m_pipControlSetMap.clear();
    m_pipControlSets = &(tileTypeDb.pipControlSets());

    // loop over all PIPs and sort them into control sets
    const PIPs& pips = tileType.pips();
    size_t pipCount = pips.size();
    for (size_t i = 0; i < pipCount; ++i)
    {
        // get current PIP and create/find its control set
        const PIP& pip = pips[i];
        PIPControlSet& controlSet = addPIPControlSet(pip.endWireIndex());

        // add new PIPBitValue entry to control set
        PIPBitValues& pipBitValues = controlSet.pipBitValues();
        size_t count = pipBitValues.size();
        pipBitValues.push_back(PIPBitValue());
        PIPBitValue& pipBitValue = pipBitValues[count];

        // set its properties
        pipBitValue.pipIndex(i);
        pipBitValue.bitValue(PIPBitValue::VALUE_UNUSED);
    }

    // empty map
    m_pipControlSetMap.clear();

    // collapse all control sets with only one PIP into one
    // collapsePIPControlSets(); // Not sure if that's a good idea

    // empty control sets pointer again
    m_pipControlSets = 0;
}
示例#9
0
void SquareMap::drawLayer(BITMAP *dest, bool drawObstacle, TiledMapLayer *layer, int opacity)
{
	Rectangle oldClip;
	TileType *tempTileType;
	Tile* tempTile;

	oldClip.clipToRect(dest);
	cameraScreenRect.rectToClip(dest);

	// Calculate the part of the map that needs to be drawn (visible part)
	Point start = screenToTile(Point(cameraScreenRect.x, cameraScreenRect.y));
	Point end = screenToTile(Point(cameraScreenRect.x + cameraScreenRect.w - 1, cameraScreenRect.y + cameraScreenRect.h - 1));

	start.x = MAX(0, MIN(mapWidth  - 1, start.x));
	start.y = MAX(0, MIN(mapHeight - 1, start.y));

	if (opacity < 255) {
		set_trans_blender(0,0,0,opacity);
		drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
	}

	for (int y = start.y; y <= end.y; y++) {
		for (int x = start.x; x <= end.x; x++) {
			tempTile = layer->getTile(Point(x, y));
			tempTileType = tempTile->getType();
			if (tempTileType) {
				if (opacity < 255) {
					draw_trans_sprite(
						dest,
						tempTileType->getBitmap(),
						cameraScreenRect.x - cameraCoords.x + x * tileWidth,
						cameraScreenRect.y - cameraCoords.y + y * tileHeight
					);
				}
				else {
					draw_sprite(
						dest,
						tempTileType->getBitmap(),
						cameraScreenRect.x - cameraCoords.x + x * tileWidth,
						cameraScreenRect.y - cameraCoords.y + y * tileHeight
					);
				}
			}
			if (drawObstacle) {
				int tx = cameraScreenRect.x - cameraCoords.x + x * tileWidth;
				int ty = cameraScreenRect.y - cameraCoords.y + y * tileHeight;
				int tw = tileWidth;
				int th = tileHeight;
				int to = tempTile->obstacle;
				
				if (to & OB_TOP) {
					line(dest, tx + 2,      ty + 2,      tx + tw - 3, ty + 2,      makecol(255,0,0));
					line(dest, tx + 3,      ty + 3,      tx + tw - 2, ty + 3,      makecol(0,0,0));
				}
				if (to & OB_LEFT) {
					line(dest, tx + 2,      ty + 2,      tx + 2,      ty + th - 3, makecol(255,0,0));
					line(dest, tx + 3,      ty + 3,      tx + 3,      ty + th - 2, makecol(0,0,0));
				}
				if (to & OB_RIGHT) {
					line(dest, tx + tw - 3, ty + 2,      tx + tw - 3, ty + th - 3, makecol(255,0,0));
					line(dest, tx + tw - 2, ty + 3,      tx + tw - 2, ty + th - 2, makecol(0,0,0));
				}
				if (to & OB_BOTTOM) {
					line(dest, tx + 2,      ty + th - 3, tx + tw - 3, ty + th - 3, makecol(255,0,0));
					line(dest, tx + 3,      ty + th - 2, tx + tw - 2, ty + th - 2, makecol(0,0,0));
				}
			}
		}
	}

	if (opacity < 255) {
		drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
	}

	oldClip.rectToClip(dest);
}
示例#10
0
	bool TileType::loadStandardTileTypesLua(const char *filename)
	{
		LuaState lua(false);
		if (!lua.loadFile(filename))
		{
			lua.logStack("TITLE");
			lua.close();
			stringstream errss;
			errss << "Unable to load standard tile types";
			am_log("TILE", errss);
			return false;
		}

		lua_getglobal(lua, "types");
		if (!lua_istable(lua, -1))
		{
			stringstream errss;
			errss << "Unable to load standard tile types, loaded file was of type: " << lua_typename(lua, -1);
			am_log("TILE", errss);
			lua.close();
			return false;
		}

		/* table is in the stack at index 't' */
		lua_pushnil(lua);  /* first key */
		while (lua_next(lua, -2) != 0) 
		{
			/* uses 'key' (at index -2) and 'value' (at index -1) */
			if (lua_isstring(lua, -2))
			{
				if (!lua_istable(lua, -1))
				{
					stringstream errss;
					errss << "Tile type '" << lua_tostring(lua, -2) << "' was of type '" << lua_typename(lua, -1) << "' and not an object.";
					am_log("TILE", errss);
					continue;
				}

				string tileName = Utils::toLowerCase(lua_tostring(lua, -2));

				TileType *loadedType = new TileType(tileName.c_str());
				if (!loadedType->loadFromDef(lua))
				{
					stringstream errss;
					errss << "Failed to load '" << tileName << "' object in definition was invalid.";
					am_log("TILE", errss);
					delete loadedType;
					continue;
				}

				stringstream ss;
				ss << "Added tile type '" << loadedType->getName() << "'";
				am_log("TILE", ss);
				// TODO: Change to not needing this loadStandard function.
				Engine::getEngine()->addTileType(loadedType);
			}
			/* removes 'value'; keeps 'key' for next iteration */
			lua_pop(lua, 1);
		}
		lua.close();
		return true;
	}