Пример #1
0
void InputService::onEnable()
{
	bindings.clear();

	bindKey(KEY_UP, sf::Keyboard::W);
	bindKey(KEY_LEFT, sf::Keyboard::A);
	bindKey(KEY_DOWN, sf::Keyboard::S);
	bindKey(KEY_RIGHT, sf::Keyboard::D);
	bindKey(KEY_YIELD_CONTROL, sf::Keyboard::Tab);
	bindKey(KEY_SPRINT, sf::Keyboard::Space);
	bindKey(KEY_EXIT, sf::Keyboard::Escape);
	// todo load from config

	// check all keys have been registered
	if (bindings.left.size() != KEY_UNKNOWN)
	{
		Logger::logError(format("Expected %1% key bindings, received %2% instead",
								_str(KEY_UNKNOWN), _str(bindings.left.size())));

		error("Invalid number of key bindings");
	}

	// listen to input events
	auto events = Locator::locate<EventService>();
	events->registerListener(this, EVENT_RAW_INPUT_KEY);
	events->registerListener(this, EVENT_RAW_INPUT_CLICK);
}
Пример #2
0
BodyData *CollisionMap::createBodyData(BlockType blockType, const sf::Vector2i &tilePos)
{
	// outside building doors
	if (blockType == BLOCK_SLIDING_DOOR)
	{
		BodyData *data = new BodyData; // todo cache
		data->type = BODYDATA_BLOCK;
		data->blockData.blockDataType = BLOCKDATA_DOOR;

		boost::optional<std::pair<Building *, Door *>> buildingAndDoor;
		container->getBuildingMap().getBuildingByOutsideDoorTile(tilePos, buildingAndDoor);

		if (!buildingAndDoor)
		{
			Logger::logWarning(
					format("Cannot add block data for door at (%1%, %2%), because there is no building there",
						   _str(tilePos.x), _str(tilePos.y)));
			return nullptr;
		}

		DoorBlockData *doorData = &data->blockData.door;
		doorData->building = buildingAndDoor->first;
		doorData->door = buildingAndDoor->second;

		return data;
	}

	return nullptr;
}
Пример #3
0
World *WorldService::WorldLoader::loadWorlds(const std::string &mainWorldName)
{
	// load main world
	LoadedWorld &mainWorld = loadWorld(mainWorldName, false);
	if (mainWorld.failed())
	{
		error("Failed to load main world");
		return nullptr;
	}

	WorldTreeNode worldTreeRoot;
	worldTreeRoot.value = mainWorld.world;

  	// allocate main world building IDs
	for (auto &building : buildings)
	{
		Logger::logDebuggier(format("Found building %1% '%2%' in main world", 
          			_str(building.insideWorldID), building.insideWorldName));
    	Logger::pushIndent();

    	loadWorld(building.insideWorldName, true, building.insideWorldID);

    	Logger::popIndent();
	}

	// transfer building IDs to doors
	for (auto &door : mainWorld.doors)
	{
		LoadedBuilding *owningBuilding = findDoorBuilding(door);
		if (owningBuilding == nullptr)
		{
			error("A door at (%1%, %2%) is not in any buildings!",
			            _str(door.tile.x), _str(door.tile.y));
			return nullptr;
		}

		door.doorTag = DOORTAG_WORLD_ID;
		door.worldID = owningBuilding->insideWorldID;
		owningBuilding->doors.push_back(door);
	}

  	std::set<WorldID> visitedWorlds;

	// load all worlds recursively without connecting doors
	discoverAndLoadAllWorlds(mainWorld, mainWorld.world->getID(), visitedWorlds);
	visitedWorlds.clear();

	// connect up the doors
	connectDoors(worldTreeRoot, mainWorld, visitedWorlds);

	return mainWorld.world;
}
Пример #4
0
void InputService::bindKey(InputKey binding, sf::Keyboard::Key key)
{
	std::string verb("Set");

	// remove existing
	auto existing = bindings.left.find(binding);
	if (existing != bindings.left.end())
	{
		verb = "Replaced existing";
		bindings.left.replace_data(existing, key);
	}

	bindings.left.insert({binding, key});
	Logger::logDebuggier(format("%1% binding for key %2%: %3%", verb, _str(key), _str(binding)));
}
Пример #5
0
void CollisionMap::GlobalContactListener::BeginContact(b2Contact *contact)
{
	b2Fixture *a = contact->GetFixtureA();
	b2Fixture *b = contact->GetFixtureB();

	BodyData *aData = (BodyData *) a->GetUserData();
	BodyData *bData = (BodyData *) b->GetUserData();

	if (aData == nullptr || bData == nullptr)
		return;

	// entity with block
	if (aData->type != bData->type)
	{
		BodyData *entity = aData->type == BODYDATA_ENTITY ? aData : bData;
		BodyData *block = entity == aData ? bData : aData;

		// door
		if (block->blockData.blockDataType == BLOCKDATA_DOOR)
		{
			DoorBlockData *door = &block->blockData.door;
			Door *targetDoor = door->building->getConnectedDoor(door->door);
			if (targetDoor == nullptr)
			{
				Logger::logError(format("Could not find connected door for door %1% in building %2%",
										_str(door->door->id), _str(door->building->getID())));
				return;
			}

			Event event;
			event.type = EVENT_HUMAN_JOIN_WORLD;
			event.entityID = entity->entityID.id;
			event.joinWorld.newWorldID = 1010101; // todo world's need IDs!

			event.joinWorld.spawnDirection = DIRECTION_NORTH; // todo store in Door
			event.joinWorld.spawnX = targetDoor->localTilePos.x;
			event.joinWorld.spawnY = targetDoor->localTilePos.y;

			Logger::logDebug(format("Door interaction with building %1%", _str(door->building->getID())));

			// todo complete the two above todos before actually calling the event
			// Locator::locate<EventService>()->callEvent(event);
		}


	}

}
Пример #6
0
/**
 * get string from root to this node
 */
wstring DictionaryNode::getStringFromRoot(void)
{
	// current node is this node
	DictionaryNode* current = this;
	wstring _str(L"");
	while (true) {
		// stop if root is reached
		if (current == NULL) 
		{
			break;
		}
		wchar_t _ch = current->getCharacter();
		if (_ch == L' ')
		{
			break;
		}
		_str.push_back(_ch);
		// jump to parent node
		current = current->getParentNode();
	}
	// initialize an empty string
	wstring result(L"");
	int _len = _str.length();
	for (int i = _len - 1; i >= 0; --i) {
		result.push_back(_str.back());
		_str.pop_back();
	}
	return result;
}
Пример #7
0
std::string Locator::serviceToString(ServiceType type)
{
	switch (type)
	{
		case SERVICE_ANIMATION:
			return "Animation";
		case SERVICE_CAMERA:
			return "Camera";
		case SERVICE_CONFIG:
			return "Config";
		case SERVICE_ENTITY:
			return "Entity";
		case SERVICE_EVENT:
			return "Event";
		case SERVICE_INPUT:
			return "Input";
		case SERVICE_LOGGING:
			return "Logging";
		case SERVICE_RENDER:
			return "Render";
		case SERVICE_WORLD:
			return "World";
		default:
			return format("Unknown (%1%)", _str(type));
	}
}
Пример #8
0
/*
 * rpmemd_print_pool_attr -- print pool attributes
 */
static void
rpmemd_print_pool_attr(const struct rpmem_pool_attr *attr)
{
	if (attr == NULL) {
		RPMEMD_LOG(INFO, RPMEMD_LOG_INDENT "NULL");
	} else {
		RPMEMD_LOG(INFO, RPMEMD_LOG_INDENT "signature: '%s'",
				_str(attr->signature));
		RPMEMD_LOG(INFO, RPMEMD_LOG_INDENT "major: %u", attr->major);
		RPMEMD_LOG(INFO, RPMEMD_LOG_INDENT "compat_features: 0x%x",
				attr->compat_features);
		RPMEMD_LOG(INFO, RPMEMD_LOG_INDENT "incompat_features: 0x%x",
				attr->incompat_features);
		RPMEMD_LOG(INFO, RPMEMD_LOG_INDENT "ro_compat_features: 0x%x",
				attr->ro_compat_features);
		RPMEMD_LOG(INFO, RPMEMD_LOG_INDENT "poolset_uuid: %s",
				uuid2str(attr->poolset_uuid));
		RPMEMD_LOG(INFO, RPMEMD_LOG_INDENT "uuid: %s",
				uuid2str(attr->uuid));
		RPMEMD_LOG(INFO, RPMEMD_LOG_INDENT "next_uuid: %s",
				uuid2str(attr->next_uuid));
		RPMEMD_LOG(INFO, RPMEMD_LOG_INDENT "prev_uuid: %s",
			uuid2str(attr->prev_uuid));
	}
}
Пример #9
0
/*
 * rpmemd_print_info -- print basic info and configuration
 */
static void
rpmemd_print_info(struct rpmemd *rpmemd)
{
    RPMEMD_LOG(NOTICE, "ssh connection: %s",
               _str(getenv("SSH_CONNECTION")));
    RPMEMD_LOG(NOTICE, "user: %s", _str(getenv("USER")));
    RPMEMD_LOG(NOTICE, "configuration");
    RPMEMD_LOG(NOTICE, "\tpool set directory: '%s'",
               _str(rpmemd->config.poolset_dir));
    RPMEMD_LOG(NOTICE, "\tpersist method: %s",
               rpmem_persist_method_to_str(rpmemd->persist_method));
    RPMEMD_LOG(NOTICE, "\tnumber of threads: %lu", rpmemd->nthreads);
    RPMEMD_DBG("\tpersist APM: %s",
               bool2str(rpmemd->config.persist_apm));
    RPMEMD_DBG("\tpersist GPSPM: %s",
               bool2str(rpmemd->config.persist_general));
    RPMEMD_DBG("\tuse syslog: %s", bool2str(rpmemd->config.use_syslog));
    RPMEMD_DBG("\tlog file: %s", _str(rpmemd->config.log_file));
    RPMEMD_DBG("\tlog level: %s",
               rpmemd_log_level_to_str(rpmemd->config.log_level));
}
Пример #10
0
///--- PInvoke code ---
///---Begin closure code ---
System_Void _TestShapes_Main() {
    System_Double vreg_5;
    System_Double vreg_6;
    System_Double vreg_7;
    System_Single vreg_8;
    System_Double vreg_9;
    System_Single vreg_10;
    
    System_Console_Write(_str(0));
    _Square  vreg_1;vreg_1._typeId = 4;
    _Cube  vreg_3;vreg_3._typeId = 6;
    System_Console_Write(_str(1));
    vreg_5 = _Square_get_Area(&vreg_1);
    System_Console_WriteLine(vreg_5);
    System_Console_Write(_str(2));
    vreg_6 = _Cube_get_Area(&vreg_3);
    System_Console_WriteLine(vreg_6);
    System_Console_Write(_str(3));
    _Square_set_Area(&vreg_1, 50);
    _Cube_set_Area(&vreg_3, 50);
    System_Console_Write(_str(4));
    vreg_7 = vreg_1.side;
    vreg_8 = (float)vreg_7;
    System_Console_WriteLine(vreg_8);
    System_Console_Write(_str(5));
    vreg_9 = vreg_3.side;
    vreg_10 = (float)vreg_9;
    System_Console_WriteLine(vreg_10);

    return;
}
Пример #11
0
/*
 * rpmemd_common_fip_init -- initialize fabric provider
 */
static int
rpmemd_common_fip_init(struct rpmemd *rpmemd, const struct rpmem_req_attr *req,
	struct rpmem_resp_attr *resp, int *status)
{
	/* register the whole pool with header in RDMA */
	void *addr = (void *)((uintptr_t)rpmemd->pool->pool_addr);
	struct rpmemd_fip_attr fip_attr = {
		.addr		= addr,
		.size		= req->pool_size,
		.nlanes		= req->nlanes,
		.nthreads	= rpmemd->nthreads,
		.provider	= req->provider,
		.persist_method = rpmemd->persist_method,
		.deep_persist	= rpmemd_deep_persist,
		.ctx		= rpmemd
	};

	const int is_pmem = rpmemd_db_pool_is_pmem(rpmemd->pool);
	if (rpmemd_apply_pm_policy(&fip_attr.persist_method, &fip_attr.persist,
			is_pmem)) {
		*status = RPMEM_ERR_FATAL;
		goto err_fip_init;
	}

	const char *node = rpmem_get_ssh_conn_addr();
	enum rpmem_err err;

	rpmemd->fip = rpmemd_fip_init(node, NULL, &fip_attr, resp, &err);
	if (!rpmemd->fip) {
		*status = (int)err;
		goto err_fip_init;
	}

	return 0;
err_fip_init:
	return -1;
}

/*
 * rpmemd_print_req_attr -- print request attributes
 */
static void
rpmemd_print_req_attr(const struct rpmem_req_attr *req)
{
	RPMEMD_LOG(NOTICE, RPMEMD_LOG_INDENT "pool descriptor: '%s'",
			_str(req->pool_desc));
	RPMEMD_LOG(NOTICE, RPMEMD_LOG_INDENT "pool size: %lu", req->pool_size);
	RPMEMD_LOG(NOTICE, RPMEMD_LOG_INDENT "nlanes: %u", req->nlanes);
	RPMEMD_LOG(NOTICE, RPMEMD_LOG_INDENT "provider: %s",
			rpmem_provider_to_str(req->provider));
}
Пример #12
0
/*
 * rpmemd_print_pool_attr -- print pool attributes
 */
static void
rpmemd_print_pool_attr(const struct rpmem_pool_attr *attr)
{
    RPMEMD_LOG(INFO, "\tsignature: '%s'", _str(attr->signature));
    RPMEMD_LOG(INFO, "\tmajor: %u", attr->major);
    RPMEMD_LOG(INFO, "\tcompat_features: 0x%x", attr->compat_features);
    RPMEMD_LOG(INFO, "\tincompat_features: 0x%x", attr->incompat_features);
    RPMEMD_LOG(INFO, "\tro_compat_features: 0x%x",
               attr->ro_compat_features);
    RPMEMD_LOG(INFO, "\tpoolset_uuid: %s", uuid2str(attr->poolset_uuid));
    RPMEMD_LOG(INFO, "\tuuid: %s", uuid2str(attr->uuid));
    RPMEMD_LOG(INFO, "\tnext_uuid: %s", uuid2str(attr->next_uuid));
    RPMEMD_LOG(INFO, "\tprev_uuid: %s", uuid2str(attr->prev_uuid));
}
Пример #13
0
void WorldService::WorldLoader::connectDoors(WorldTreeNode &currentNode, LoadedWorld &world,
		std::set<WorldID> &visitedWorlds)
{
	if (visitedWorlds.find(world.world->getID()) != visitedWorlds.end())
		return;
	visitedWorlds.insert(world.world->getID());

	for (LoadedDoor &door : world.doors)
	{
		LoadedWorld *childWorld = getLoadedWorld(door.doorID > 0 ? door.worldID : currentNode.parent->value->getID());
		if (childWorld == nullptr)
		{
			Logger::logError(format("World %1% has not been loaded yet in connectDoors()", 
						_str(door.worldID)));
			return;
		}

		LoadedDoor *targetDoor = findPartnerDoor(*childWorld, door.doorID, world.world->getID());
		if (targetDoor == nullptr)
		{
			Logger::logError(format("Cannot find partner door in world %1% for door %2% in world %3%",
						_str(door.worldID), _str(door.doorID), _str(world.world->getID())));
			return;
		}

		// add connection to this world's lookup table
		Location loc(world.world->getID(), door.tile);
		connectionLookup.emplace(std::piecewise_construct,
		                         std::forward_as_tuple(loc),
		                         std::forward_as_tuple(childWorld->world->getID(), targetDoor->tile));

		doorDetails.insert({loc, ConnectionDetails(loc, door.orientation, door.dimensions)});

		Logger::logDebuggiest(format("Added world connection %1% to %2% from %3% through door %4%",
					door.doorID < 0 ? "up" : "down", _str(world.world->getID()), 
					_str(childWorld->world->getID()), _str(door.doorID)));

		// add node
		if (door.doorID > 0)
		{
			currentNode.children.emplace_back();
			WorldTreeNode &childNode = currentNode.children.back();
			childNode.parent = &currentNode;
			childNode.value = childWorld->world;

			// recurse
			connectDoors(childNode, *childWorld, visitedWorlds);
		}

	}
}
Пример #14
0
/*
 * rpmemd_common_fip_init -- initialize fabric provider
 */
static int
rpmemd_common_fip_init(struct rpmemd *rpmemd, const struct rpmem_req_attr *req,
                       struct rpmem_resp_attr *resp, int *status)
{
    void *addr = (void *)((uintptr_t)rpmemd->pool->pool_addr +
                          POOL_HDR_SIZE);
    struct rpmemd_fip_attr fip_attr = {
        .addr		= addr,
        .size		= req->pool_size,
        .nlanes		= req->nlanes,
        .nthreads	= rpmemd->nthreads,
        .provider	= req->provider,
        .persist_method = rpmemd->persist_method,
        .persist	= rpmemd->persist,
    };

    const char *node = rpmem_get_ssh_conn_addr();
    enum rpmem_err err;

    rpmemd->fip = rpmemd_fip_init(node, NULL, &fip_attr, resp, &err);
    if (!rpmemd->fip) {
        *status = (int)err;
        goto err_fip_init;
    }

    return 0;
err_fip_init:
    return -1;
}

/*
 * rpmemd_print_req_attr -- print request attributes
 */
static void
rpmemd_print_req_attr(const struct rpmem_req_attr *req)
{
    RPMEMD_LOG(NOTICE, "\tpool descriptor: '%s'", _str(req->pool_desc));
    RPMEMD_LOG(NOTICE, "\tpool size: %lu", req->pool_size);
    RPMEMD_LOG(NOTICE, "\tnlanes: %u", req->nlanes);
    RPMEMD_LOG(NOTICE, "\tprovider: %s",
               rpmem_provider_to_str(req->provider));
}
Пример #15
0
void InputService::setPlayerEntity(EntityID entity)
{
	auto es = Locator::locate<EntityService>();
	if (!es->hasComponent(entity, COMPONENT_INPUT))
		error("Cannot set player entity to %1% as it doesn't have an input component", _str(entity));

	// switch out brain
	auto head = es->getComponent<InputComponent>(entity, COMPONENT_INPUT);
	playersOldBrain = boost::dynamic_pointer_cast<EntityBrain>(head->brain);

	if (!inputBrain)
		inputBrain.reset(new InputBrain(entity)); // lazy init
	else
		inputBrain->setEntity(entity);

	head->brain = inputBrain;

	playerEntity = entity;
	Locator::locate<CameraService>()->setTrackedEntity(entity);
}
Пример #16
0
void InputService::handleKeyEvent(const Event &event)
{
	InputKey binding(getBinding(event.rawInputKey.key));

	// unrecognized key
	if (binding == KEY_UNKNOWN)
		return;

	// quit
	if (binding == KEY_EXIT)
	{
		Logger::logDebug("Exit key pressed, quitting");
		Locator::locate<RenderService>()->getWindow()->close();
		return;
	}

	EventService *es = Locator::locate<EventService>();
	bool hasEntity = hasPlayerEntity();

	Event e;

	// assign entity id
	e.entityID = hasEntity ? *playerEntity : CAMERA_ENTITY;

	// yield entity control
	if (binding == KEY_YIELD_CONTROL)
	{
		if (hasEntity)
		{
			e.type = EVENT_INPUT_YIELD_CONTROL;
			clearPlayerEntity();
			es->callEvent(e);
		}
		return;
	}

	// sprint
	if (binding == KEY_SPRINT)
	{
		e.type = EVENT_INPUT_SPRINT;
		e.sprintToggle.start = event.rawInputKey.pressed;
		es->callEvent(e);
		return;
	}

	// input
	bool startMoving = event.rawInputKey.pressed;
	e.type = startMoving ? EVENT_INPUT_START_MOVING : EVENT_INPUT_STOP_MOVING;

	DirectionType direction;

	switch (binding)
	{
		case KEY_UP:
			direction = DIRECTION_NORTH;
			break;
		case KEY_LEFT:
			direction = DIRECTION_WEST;
			break;
		case KEY_DOWN:
			direction = DIRECTION_SOUTH;
			break;
		case KEY_RIGHT:
			direction = DIRECTION_EAST;
			break;
		default:
			error("An invalid movement key slipped through InputService's onEvent: %1%", _str(binding));
			return;
	}

	if (startMoving)
		e.startMove.direction = direction;
	else
		e.stopMove.direction = direction;

	es->callEvent(e);
}
Пример #17
0
void WorldService::WorldLoader::discoverAndLoadAllWorlds(LoadedWorld &world, WorldID lastWorldID,
                                                         std::set<WorldID> &visitedWorlds)
{
  	if (visitedWorlds.find(world.world->getID()) != visitedWorlds.end())
      	return;
  	visitedWorlds.insert(world.world->getID());

	std::sort(world.doors.begin(), world.doors.end(), 
			[] (const LoadedDoor &a, const LoadedDoor &/* b */)
			{
				return a.doorTag != DOORTAG_WORLD_SHARE;
			});

	// iterate all doors found in last world
	for (LoadedDoor &door : world.doors)
	{
		// initialise negative/ascending doors
		if (door.doorID < 0)
		{
			door.doorTag = DOORTAG_WORLD_ID;
			door.worldID = lastWorldID;
			continue;
		}

    	LoadedWorld *newWorld = nullptr;

		// find the other door with same world share
		if (door.doorTag == DOORTAG_WORLD_SHARE)
		{
			auto otherDoor = std::find_if(world.doors.begin(), world.doors.end(),
			        [door](const LoadedDoor &d)
			        {
				    	return d.doorTag != DOORTAG_WORLD_SHARE &&
				    	d.worldShare == door.worldShare;
			        });

			if (otherDoor == world.doors.end())
			{
				Logger::logError(format("Door %1% has an unknown world share tag '%2%'",
				            _str(door.doorID), door.worldShare));
				continue;
			}

			// share world ID
			door.worldID = otherDoor->worldID;
		}

		// load world
		else if (door.doorTag == DOORTAG_WORLD_NAME)
		{
      		Logger::logDebuggiest(format("Door ID %1% loads world '%2%'", _str(door.doorID), door.worldName));
			LoadedWorld &loadedWorld = loadWorld(door.worldName, true);
			if (loadedWorld.failed())
			{
				Logger::logError(format("Cannot find building world '%1%', owner of door %2%",
				            door.worldName, _str(door.doorID)));
				continue;
			}

			door.worldID = loadedWorld.world->getID();
      		newWorld = &loadedWorld;
		}

		else if (door.doorTag == DOORTAG_UNKNOWN)
		{
			Logger::logError(format("Door %1% has no assigned door tag", _str(door.doorID)));
      		return;
		}

		if (newWorld == nullptr)
			newWorld = getLoadedWorld(door.worldID);

		discoverAndLoadAllWorlds(*newWorld, world.world->getID(), visitedWorlds);
	}
}
Пример #18
0
WorldService::WorldLoader::LoadedWorld &WorldService::WorldLoader::loadWorld(const std::string &name, 
    	bool isBuilding, WorldID worldID)
{
  	// create new LoadedWorld in place
  	LoadedWorld &loadedWorld = loadedWorlds.emplace(worldID, LoadedWorld{}).first->second;

	// load tmx
	auto path = getWorldFilePath(name, isBuilding);
	loadedWorld.tmx.load(path);
	loadedWorld.world = new World(worldID, name, !isBuilding); // todo dont use heap
	Logger::logDebuggier(format("World %1% is '%2%'", _str(worldID), name));

	// load terrain if first time for this world name
	auto cachedTerrain = terrainCache.find(name);
	if (cachedTerrain == terrainCache.end())
	{
		Logger::logDebuggier(format("Loading terrain for world '%1%'", name));
		Logger::pushIndent();
		WorldTerrain &terrain = terrainCache.emplace(
				std::piecewise_construct,
				std::forward_as_tuple(name),
				std::forward_as_tuple(loadedWorld.world, loadedWorld.tmx.size)).first->second;
		loadedWorld.world->setTerrain(terrain);
		terrain.loadFromTileMap(loadedWorld.tmx, flippedTileGIDs);
		Logger::popIndent();
	}

	// find buildings and doors
	auto buildingLayer = std::find_if(loadedWorld.tmx.layers.begin(), loadedWorld.tmx.layers.end(),
	        [](const TMX::Layer &layer)
	        {
		    return layer.name == "buildings";
	        });

	// no buildings layer
	if (buildingLayer == loadedWorld.tmx.layers.end())
  	{
    	Logger::logDebuggier("No \"buildings\" layer");
		return loadedWorld;
  	}


	for (const TMX::TileWrapper &tile : buildingLayer->items)
	{
		if (tile.type != TMX::TILE_PROPERTY_SHAPE)
			continue;

		const TMX::PropertyObject &propObj = tile.property;

		if (propObj.hasProperty(TMX::PROPERTY_BUILDING_WORLD))
		{
			// buildings
			if (isBuilding)
				error("Unsupported: a building cannot have a building inside it");


			sf::IntRect bounds(
					(int) (tile.tile.position.x / Constants::tilesetResolution),
					(int) (tile.tile.position.y / Constants::tilesetResolution),
					(int) (propObj.dimensions.x / Constants::tilesetResolution),
					(int) (propObj.dimensions.y / Constants::tilesetResolution)
					);

			LoadedBuilding b;
			b.bounds = bounds;
			b.insideWorldName = propObj.getProperty(TMX::PROPERTY_BUILDING_WORLD);
      		b.insideWorldID = generateWorldID();
			buildings.push_back(b);
		}

		else if (propObj.hasProperty(TMX::PROPERTY_DOOR_ID))
		{
			// doors
			LoadedDoor d;
			d.tile.x = (tile.tile.position.x / Constants::tilesetResolution);
			d.tile.y = (tile.tile.position.y / Constants::tilesetResolution);
			d.doorID = boost::lexical_cast<int>(propObj.getProperty(TMX::PROPERTY_DOOR_ID));
			d.doorTag = DOORTAG_UNKNOWN;
			d.dimensions = Math::multiply(propObj.dimensions, 1.f / Constants::tilesetResolution);

			if (!propObj.hasProperty(TMX::PROPERTY_DOOR_ORIENTATION))
				error("Door at (%1%, %2%) in world %3% is missing \"door-orientation\"",
				      _str(d.tile.x), _str(d.tile.y), _str(worldID));

			d.orientation = Direction::parseString(propObj.getProperty(TMX::PROPERTY_DOOR_ORIENTATION));
			if (d.orientation == DIRECTION_UNKNOWN)
				error("Invalid direction \"%1%\"", propObj.getProperty(TMX::PROPERTY_DOOR_ORIENTATION));

			// preloaded
			if (propObj.hasProperty(TMX::PROPERTY_DOOR_WORLD_ID))
			{
				d.doorTag = DOORTAG_WORLD_ID;
				d.worldID = boost::lexical_cast<WorldID>(propObj.getProperty(TMX::PROPERTY_DOOR_WORLD_ID));
			}

			// unloaded
			if (propObj.hasProperty(TMX::PROPERTY_DOOR_WORLD))
			{
				d.doorTag = DOORTAG_WORLD_NAME;
				d.worldName = propObj.getProperty(TMX::PROPERTY_DOOR_WORLD);
			}

			// sharing
			else if (propObj.hasProperty(TMX::PROPERTY_DOOR_WORLD_SHARE_SPECIFIER))
			{
				d.doorTag = DOORTAG_WORLD_SHARE;
				d.worldShare = propObj.getProperty(TMX::PROPERTY_DOOR_WORLD_SHARE_SPECIFIER);
			}

			// share source
			if (propObj.hasProperty(TMX::PROPERTY_DOOR_WORLD_SHARE_SOURCE))
			{
				d.worldShare = propObj.getProperty(TMX::PROPERTY_DOOR_WORLD_SHARE_SOURCE);
			}

			loadedWorld.doors.push_back(d);
		}
	}

	return loadedWorld;
}
Пример #19
0
WString _str(const LPCSTR ptr) {
  return _str(ptr, true);
}
    // When an error has occurred, pop elements off the stack until the top
    // state has an error-item. If none is found, the default recovery
    // mode (which is to abort) is activated. 
    //
    // If EOF is encountered without being appropriate for the current state,
    // then the error recovery will fall back to the default recovery mode.
    // (i.e., parsing terminates)
void JSONTokenizer::errorRecovery()
try
{
    if (d_acceptedTokens__ >= d_requiredTokens__)// only generate an error-
    {                                           // message if enough tokens 
        ++d_nErrors__;                          // were accepted. Otherwise
        std::string _str("Syntax error at line ");
        muzzley::tostr(_str, d_scanner.lineNr());
        error(_str.data());                  // simply skip input
    }


    // get the error state
    while (not (s_state[top__()][0].d_type & ERR_ITEM))
    {
        pop__();
    }

    // In the error state, lookup a token allowing us to proceed.
    // Continuation may be possible following multiple reductions,
    // but eventuall a shift will be used, requiring the retrieval of
    // a terminal token. If a retrieved token doesn't match, the catch below 
    // will ensure the next token is requested in the while(true) block
    // implemented below:

    int lastToken = d_token__;                  // give the unexpected token a
                                                // chance to be processed
                                                // again.

    pushToken__(_error_);                       // specify _error_ as next token
    push__(lookup(true));                       // push the error state

    d_token__ = lastToken;                      // reactivate the unexpected
                                                // token (we're now in an
                                                // ERROR state).

    bool gotToken = true;                       // the next token is a terminal

    while (true)
    {
        try
        {
            if (s_state[d_state__]->d_type & REQ_TOKEN)
            {
                gotToken = d_token__ == _UNDETERMINED_;
                nextToken();                    // obtain next token
            }
            
            int action = lookup(true);

            if (action > 0)                 // push a new state
            {
                push__(action);
                popToken__();

                if (gotToken)
                {

                    d_acceptedTokens__ = 0;
                    return;
                }
            }
            else if (action < 0)
            {
                // no actions executed on recovery but save an already 
                // available token:
                if (d_token__ != _UNDETERMINED_)
                    pushToken__(d_token__);
 
                                            // next token is the rule's LHS
                reduce__(s_productionInfo[-action]); 
            }
            else
                ABORT();                    // abort when accepting during
                                            // error recovery
        }
        catch (...)
        {
            if (d_token__ == _EOF_)
                ABORT();                    // saw inappropriate _EOF_
                      
            popToken__();                   // failing token now skipped
        }
    }
}
catch (ErrorRecovery__)       // This is: DEFAULT_RECOVERY_MODE
{
    ABORT();
}
Пример #21
0
void InitMsg( void )
{
    internationalData = LoadInternationalData( _str( __msg_file_prefix ) );
}
Пример #22
0
void qlevel_save(STRING *filename)
{
	STRING *file = "#256";
	make_path(file, filename);
	
	STRING *backup = "#256";
	str_cpy(backup, file);
	str_cat(backup, ".bak");
	file_delete(backup);
	file_rename(file, backup);
	
	ini_write_int(file, "Level Information", "EntityCount", 0);
	ini_write_int(file, "Level Information", "LightCount", 0);
	ini_write_int(file, "Level Information", "FogCount", 0);
	
	int countEntity = 0;
	int countLight = 0;
	int countFog = 0;
	
	STRING *section = "#64";
	for(you = ent_next(NULL); you != NULL; you = ent_next(you))
	{
		switch(you->group)
		{
			case GROUP_LEVEL:
				str_cpy(section, "Entity ");
				str_cat(section, str_for_int(NULL, countEntity));
				
				ini_write_string(file, section, "Model", you->type);
				ini_write_int(file, section, "ActionCount", 0);
				int actionCount = 0;
				STRING *actionName = "#64";
				ActionInformation *entry;
				for(entry = list_first(you->string1); entry != NULL; entry = list_next(you->string1, entry))
				{
					str_cpy(actionName, "Action");
					str_cat(actionName, str_for_int(NULL, actionCount));
					ini_write_string(file, section, actionName, _str(entry->actionname));
					actionCount++;
				}
				ini_write_int(file, section, "ActionCount", actionCount);
				
				ini_write_float(file, section, "X", you->x);
				ini_write_float(file, section, "Y", you->y);
				ini_write_float(file, section, "Z", you->z);
				ini_write_float(file, section, "Pan", cycle(you->pan, 0, 360));
				ini_write_float(file, section, "Tilt", cycle(you->tilt, 0, 360));
				ini_write_float(file, section, "Roll", cycle(you->roll, 0, 360));
				ini_write_float(file, section, "ScaleX", you->scale_x);
				ini_write_float(file, section, "ScaleY", you->scale_y);
				ini_write_float(file, section, "ScaleZ", you->scale_z);
				ini_write_float(file, section, "Lightrange", you->lightrange);

				countEntity++;
				break;
		}
	}
	
	ini_write_int(file, "Level Information", "EntityCount", countEntity);
	ini_write_int(file, "Level Information", "LightCount", countLight);
	ini_write_int(file, "Level Information", "FogCount", countFog);
}
Пример #23
0
LRESULT CDlgFileAssoc::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) {

	switch (uMsg) {
		
		case WM_INITDIALOG: {

#ifdef SHELL_AYGSHELL
			// Initializes menubar		
			SHMENUBARINFO mbi;
			memset(&mbi, 0, sizeof(SHMENUBARINFO));
			mbi.cbSize = sizeof(SHMENUBARINFO);
			mbi.hwndParent = hWnd;
			mbi.nToolBarId = MNU_OKCANCEL;
			mbi.hInstRes = player()->hInstance;
			mbi.nBmpId = 0;
			mbi.cBmpImages = 0;
			if (SHCreateMenuBar(&mbi)) {
				hWndMenuBar = mbi.hwndMB;
				SetSoftkeyText(hWndMenuBar, 0, _str(STR_CANCEL));
				SetSoftkeyText(hWndMenuBar, 1, _str(STR_OK));
			} else {
				hWndMenuBar = NULL;
			}
#else
            hWndMenuBar = NULL;
#endif

#ifdef SHELL_AYGSHELL
			// Initializes fullscreen dialog
			SHINITDLGINFO shidi;
			shidi.dwMask = SHIDIM_FLAGS;
			shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN|SHIDIF_DONEBUTTON|SHIDIF_WANTSCROLLBAR;
			shidi.hDlg = hWnd;
			SHInitDialog(&shidi);
#endif

			SetWindowText(hWnd, _str(STR_FILEASSOCIATIONS));
			SetDlgItemText(hWnd, LBL_USETOOPEN, _str(STR_USENITROGENTOOPE));
			SetDlgItemText(hWnd, BTN_SELALL, _str(STR_SELECTALL));
			SetDlgItemText(hWnd, BTN_SELNONE, _str(STR_SELECTNONE));
			SetDlgItemText(hWnd, LBL_NOTRUNNING, _str(STR_IFTHEPLAYERISNOT));
			SetDlgItemText(hWnd, LBL_RUNNING, _str(STR_IFTHEPLAYERISALR));

			int rActions[3] = {STR_SETFILEASPLAYLIS, STR_ADDFILETOPLAYLIS, STR_SETFOLDERASPLAYL};
			for (int i = 0; i < 3; i++) {
				SendDlgItemMessage(hWnd, CBB_NOTRUNNING, CB_ADDSTRING, 0, (LPARAM)_str(rActions[i]));
				SendDlgItemMessage(hWnd, CBB_RUNNING, CB_ADDSTRING, 0, (LPARAM)_str(rActions[i]));
			}

			SendDlgItemMessage(hWnd, CBB_NOTRUNNING, CB_SETCURSEL, (WPARAM)player()->lpConfig->cf.FileAssNotRunning, 0);
			SendDlgItemMessage(hWnd, CBB_RUNNING, CB_SETCURSEL, (WPARAM)player()->lpConfig->cf.FileAssRunning, 0);

			ListView_SetExtendedListViewStyle(GetDlgItem(hWnd, LST_EXTENSIONS), LVS_EX_CHECKBOXES|LVS_EX_FULLROWSELECT);
		
			LVCOLUMN nCol;
			memset(&nCol, 0, sizeof(LVCOLUMN));
			nCol.mask = LVCF_TEXT;
			nCol.pszText = NULL;
			ListView_InsertColumn(GetDlgItem(hWnd, LST_EXTENSIONS), 0, &nCol);

			LPWSTR assc[4] = {L"Skin files (*.sk2)", L"MPEG Layer-3 files (*.mp3)", L"Ogg Vorbis files (*.ogg)", L"Wave Audio files (*.wav)"};
			LPWSTR exts[4] = {L"sk2", L"mp3", L"ogg", L"wav"};

			int y = 0;

			for (int i = 0; i < 4; i++) {
				LVITEM nItem;
				memset(&nItem, 0, sizeof(LVITEM));
				nItem.mask = LVIF_TEXT;
				nItem.iSubItem = 0;
				nItem.pszText = assc[i];
				nItem.iItem = y;
				ListView_InsertItem(GetDlgItem(hWnd, LST_EXTENSIONS), &nItem);
				PrevAssoc[y] = IsExtAssignedDyn(exts[i]);
				if (PrevAssoc[y]) {
					ListView_SetCheckState(GetDlgItem(hWnd, LST_EXTENSIONS), y, true);
				}
				y++;
			}
			for (int i = 0; i < MAP_GetDecoderPlugInCount(player()->MAP); i++) {

				MAP_DEC_PLUGIN * mplug = MAP_GetDecoderPlugIn(player()->MAP, i);
				
				for (int x = 0; x < mplug->GetFileExtCount(); x++) {

					TCHAR ExtName[MAX_PATH];
					TCHAR ExtDesc[MAX_PATH];
					mplug->GetFileExt(x, ExtName, ExtDesc);
					LVITEM nItem;
					memset(&nItem, 0, sizeof(LVITEM));
					nItem.mask = LVIF_TEXT;
					nItem.iSubItem = 0;
					nItem.pszText = ExtDesc;
					nItem.iItem = y;
					
					ListView_InsertItem(GetDlgItem(hWnd, LST_EXTENSIONS), &nItem);	
					PrevAssoc[y] = IsExtAssignedDyn(ExtName);
					if (PrevAssoc[y]) {
						ListView_SetCheckState(GetDlgItem(hWnd, LST_EXTENSIONS), y, true);
					}

					y++;
				}
			}

			RECT rc;
			GetClientRect(GetDlgItem(hWnd, LST_EXTENSIONS), &rc);
			ListView_SetColumnWidth(GetDlgItem(hWnd, LST_EXTENSIONS), 0, rc.right-rc.left);

			break;

		}

 		case WM_COMMAND: {

			int wmId = LOWORD(wParam); 
			if ((wmId == IDM_OK) || (wmId == IDOK)) {

				player()->lpConfig->cf.FileAssNotRunning = SendDlgItemMessage(hWnd, CBB_NOTRUNNING, CB_GETCURSEL, 0, 0);
				player()->lpConfig->cf.FileAssRunning = SendDlgItemMessage(hWnd, CBB_RUNNING, CB_GETCURSEL, 0, 0);
				
				LPWSTR exts[4] = {L"sk2", L"mp3", L"ogg", L"wav"};
				for (int i = 0; i < 4; i++) {
					
					bool NewAssoc = ListView_GetCheckState(GetDlgItem(hWnd, LST_EXTENSIONS), i);

					if (NewAssoc && !PrevAssoc[i]) {
						ExtAssignDyn(exts[i], L"\"%1\"", 102+(int)(i == 0));
					}

					if (!NewAssoc && PrevAssoc[i]) {
						ExtUnassignDyn(exts[i]);
					}

				}

				int y = 4;

				for (int i = 0; i < MAP_GetDecoderPlugInCount(player()->MAP); i++) {
		
					MAP_DEC_PLUGIN * mplug = MAP_GetDecoderPlugIn(player()->MAP, i);
				
					for (int x = 0; x < mplug->GetFileExtCount(); x++) {

						bool NewAssoc = ListView_GetCheckState(GetDlgItem(hWnd, LST_EXTENSIONS), y);
	
						TCHAR ExtName[MAX_PATH];
						TCHAR ExtDesc[MAX_PATH];
						mplug->GetFileExt(x, ExtName, ExtDesc);
						
						if (NewAssoc && !PrevAssoc[y]) {
							ExtAssignDyn(ExtName, L"\"%1\"", 102);
						}

						if (!NewAssoc && PrevAssoc[y]) {
							ExtUnassignDyn(ExtName);
						}

						y++;
					}
				}

				EndDialog(hWnd, 0);

			} else if (wmId == BTN_SELALL) {
		
				HWND ls = GetDlgItem(hWnd, LST_EXTENSIONS);
				for (int i = 0; i < ListView_GetItemCount(ls); i++) {
					ListView_SetCheckState(ls, i, true);
				}

			} else if (wmId == BTN_SELNONE) {
		
				HWND ls = GetDlgItem(hWnd, LST_EXTENSIONS);
				for (int i = 0; i < ListView_GetItemCount(ls); i++) {
					ListView_SetCheckState(ls, i, false);
				}

			} else if (wmId == IDM_CANCEL) {
			
				EndDialog(hWnd, 0);
			
			}

			break;
		}

		case WM_DESTROY:
			CommandBar_Destroy(hWndMenuBar);
			break;

		case WM_ACTIVATE:
			
			if ((wParam == WA_INACTIVE) && ((HWND)lParam == player()->lpWndMain->hWnd)) {
				EndDialog(hWnd, 0);
			} else {
				return DefWindowProc(hWnd, uMsg, wParam, lParam);
			}
			break;

		default:
			DefWindowProc(hWnd, uMsg, wParam, lParam);
	}

	return 0;
}