void SkirmishGameState::resize() { GameMenuState::resize(); m_mapWidget->setPosition(UPoint(0, m_topFrame->getSize().y)); UPoint resolution = set->GetResolution(); UPoint mapSize(resolution.x - m_sideBarFrame->getSize().x, resolution.y - m_mapWidget->getPosition().y); mapSize.x -= mapSize.x % BLOCKSIZE; mapSize.y -= mapSize.y % BLOCKSIZE; mapSize += BLOCKSIZE; m_mapWidget->setSize(mapSize); char mission[] = "SCENARIO:SCEN%c%.3d.INI"; char house; if(m_house == HOUSE_HARKONNEN) house = 'H'; else if(m_house == HOUSE_ATREIDES) house = 'A'; else if(m_house == HOUSE_ORDOS) house = 'O'; else if(m_house == HOUSE_FREMEN) house = 'F'; else if(m_house == HOUSE_MERCENARY) house = 'M'; else house = 0; sprintf(mission, mission, house, m_level); GameMan::Instance()->LoadScenario(mission); //TODO: adjust to make it relative to current resolution rather than 320x200 m_mapWidget->setMapPosition(GameMan::Instance()->getTacticalPos()); }
std::string MapExpr::toString() { std::string ret = "{"; for (size_t i = 0; i < mapSize(); ++i) { if (i > 0) ret.push_back(','); ret.append(getFrom(i)->toString()+"->"+getTo(i)->toString()); } ret.push_back('}'); return ret; }
void MapExpr::print(FILE* file, int indent) const { fprintf(file, "%*sMapExpr:\n", indent, ""); fprintf(file, "%*sfromTyp: %s", indent + 2, "", getFromTyp()->toString().c_str()); fprintf(file, "%*stoTyp: %s", indent + 2, "", getToTyp()->toString().c_str()); for (size_t i = 0; i < mapSize(); i++) { fprintf(file, "%*sfrom#%d: \n", indent + 2, "", (int)i); getFrom(i)->print(file, indent + 4); fprintf(file, "%*sto#%d: \n", indent + 2, "", (int)i); getTo(i)->print(file, indent + 4); } }
void GameEngine::initBoardAndLimits() { std::pair<int, int> mapSize(_map.getSizeX(), _map.getSizeY()); AObj* board = _factory.createAObj(BOARD, mapSize); AObj* limits = _factory.createAObj(LIMIT, mapSize); AObj* skyBox = new SkyBox(100.0f, mapSize); skyBox->initialize(); board->initialize(); limits->initialize(); _limits.push_back(board); _limits.push_back(limits); _limits.push_back(skyBox); }
void GameManager::startGame() { if (lobby) { for (RowData *date : data) delete date; data.clear(); data = lobby->getData(); } QSize mapSize(1000, 1000); CountdownWidget *t = new CountdownWidget; MainFrame::showOverlay(t, true); //todo add support for more than 8 players for (int i = 0; i < data.length() && i < 8; i++) { float x = START_POS[i] * mapSize.width(); float y = START_POS[(i + 6) % 8] * mapSize.height(); Direction dir = Direction((((i % 4) / 2) * 3 + (i % 2) * 2) % 4); Bike *bike = new Bike(x, y, dir, data[i]->color.toStdString(), data[i]->controller); bikes.append(bike); } bikes.setBorder(QRect(QPoint(0, 0), mapSize)); playArea = new PlayArea(bikes, mapSize, this); MainFrame::showWidget(playArea); //disable keys playArea->enableKeys(false); bikes.enableInput(false); Ticker::start(1000 / FPS); connect(t, SIGNAL(finished()), this, SLOT(play())); connect(&bikes, SIGNAL(gameOver(Bike*)), this, SLOT(endGame(Bike*))); t->start(); }
SanityCheckedModel * initializeModel() { UncheckedModel * uncheckedModel = UncheckedModel::newUncheckedModel(); // Setup the map Coord mapSize(24, 80); const char * mapSource[] = { "################################################################################", "#...................#..........................................................#", "#...................#..........................................................#", "#...................#..........................................................#", "#...................#..........................................................#", "#...................#..........................................................#", "#...................#..........................................................#", "#...................#######....................................................#", "#..............................................................................#", "#..............................................................................#", "#..............................................................................#", "#..............................................................................#", "#..............................................................................#", "#..............................................................................#", "#.........................#########............................................#", "#.................................#............................................#", "#.........................#.......#............................................#", "#.........................#.......#............................................#", "#.........................#########............................................#", "#..............................................................................#", "#..............................................................................#", "#..............................................................................#", "#..............................................................................#", "################################################################################" }; Map * map = Map::newMap(mapSize, mapSource); uncheckedModel->setMap(map); // Add player uncheckedModel->addUnit(Player::newPlayer(), Coord(15, 15)); SanityCheckedModel * checkedModel = SanityCheckedModel::newCheckedModel(uncheckedModel); return checkedModel; }
void Box::apply_plane_collision(float time, Map* ptr) { collision = false; sf::Vector2f boxSize(rectW,rectL); sf::Vector2f mapSize(800,5); sf::Vector2f planePos = ptr->getPlanePosition(); sf::Vector2f boxPos = rect.getPosition(); sf::FloatRect planeRec(planePos, mapSize ); sf::FloatRect boxRec(boxPos,boxSize); sf::Vector2f distance = planePos - boxPos; float dist = sqrt(pow(distance.x,2) + pow(distance.y,2) ); if( dist < 2*rectW) { if( boxRec.intersects(planeRec) ){ if(!collision) { collision = true; bounceNumber++; speed = -speed; } } } }
int main() { map *p = NULL; size_t cap, tSize; int objType,keyType; int objTypeSize, keyTypeSize; void *data = malloc(sizeof(double)*10); void *data2 = malloc(sizeof(double)*10); double double_neg_inf = DOUBLE_NEG_INF; short short_neg_inf = SHORT_NEG_INF; mapit it = NULL, rit=NULL; while(1){ char cmd[10240] = {0}; int ret; if(p == NULL){ printf("The map needs to be initialized.\n"); printf("Init step 1. Key Type: d for double, others for short.\n"); scanf("%s", cmd); keyType = (cmd[0] == 'd')?__DS__DOUBLE__:__DS__SHORT__; printf("Init step 2. Value Type: d for double, others for short.\n"); scanf("%s", cmd); objType = (cmd[0] == 'd')?__DS__DOUBLE__:__DS__SHORT__; printf("Init step 3. Capacity: \n"); scanf("%zu", &cap); p = mapAlloc(); if(p == NULL) ret = __DS__MAP__OUT_OF_MEM__; else{ objTypeSize = (objType==__DS__DOUBLE__)? sizeof(double): sizeof(short); if(keyType == __DS__DOUBLE__) ret = mapInit(p, sizeof(double), objTypeSize, cap, doubleGT); else ret = mapInit(p, sizeof(short), objTypeSize, cap, shortGT); } if(ret != __DS__MAP__NORMAL__){ printf("Not enough memory.\n"); if(p != NULL) mapFree(p); p = NULL; } else{ printf("Initialization done.\n"); } }else{ int choice = 0; printf("size/capacity: %zu/%zu\n", mapSize(p), mapCap(p)); printf("Valid operation: 1)insert, 2)delete, 3)get iterator, 4)set\n"); printf(" 5)update by it, 6)get order, 7)next, 8)pre, 9)get by iterator\n"); printf(" 10)empty, 11)free, 12)quit\n"); while(choice <= 0 || choice > 12){ scanf("%s", cmd); sscanf(cmd, "%d", &choice); } if (choice == 1){//insert printf("input a %s-type key:", (keyType == __DS__DOUBLE__)?"double":"short"); getData(keyType, data); printf("input a %s-type value:", (objType == __DS__DOUBLE__)?"double":"short"); getData(objType, data2); ret = mapInsert(p, data, data2); if(ret==__DS__MAP__FULL__)printf("Map is full!\n"); else if(ret==__DS__MAP__OBJ_EXIST__)printf("Element already exists!\n"); else if(ret==__DS__MAP__OUT_OF_MEM__)printf("Run out of memory\n"); else if(ret==__DS__MAP__NORMAL__)printf("Insert OK\n"); } else if(choice == 2){//delete printf("input a %s value:", (keyType == __DS__DOUBLE__)?"double":"short"); getData(keyType, data); ret = mapDelete(p, data); if(ret==__DS__MAP__OBJ_NOT_EXIST__){ printf("Element is not in the set.\n"); } else printf("Delete OK\n"); } else if (choice == 3){//get it printf("input a %s value:", (keyType == __DS__DOUBLE__)?"double":"short"); getData(keyType, data); ret = mapGetIt(p, data, &it); if(ret == __DS__MAP__OBJ_EXIST__){ printf("Get iterator OK!"); printf(".\n"); } else{ printf("The key "); printData(keyType, data); printf(" is not in the map.\n"); } } else if(choice == 4){//set by it printf("input the value to set:"); getData( objType, data2); ret = mapSetByIt(it, data2); if(ret == __DS__MAP__NORMAL__){ printf("Set OK!\n"); } else printf("Invalid It\n"); } else if(choice == 5){//update by it printf("input the key to set:"); getData( objType, data); printf("input the value to set:"); getData( objType, data2); ret = mapUpdateByIt(it, data, data2); if(ret == __DS__MAP__NORMAL__) { printf("Update OK!\n"); }else { printf("Invalid It\n"); } } else if (choice == 6){//get order int order; printf("input the order:"); scanf("%zu", &order); ret = mapGetOrderIt(p, order, data, data2, &it); if(ret == __DS__MAP__NORMAL__){ printf("The result key is "); printData( keyType, data); printf(".\n"); printf("The result value is "); printData( objType, data2); printf(".\n"); } else printf("No element found\n"); } else if(choice == 7){//next rit = mapNextIt(it); if(rit!=NULL) printf("Get Next OK!\n"); else printf("Cannot get next\n"); mapFreeIt(it); it = rit; } else if(choice == 8){//pre rit = mapPrevIt(it); if(rit!=NULL) printf("Get Priv OK!\n"); else printf("Cannot get priv\n"); mapFreeIt(it); it = rit; } else if(choice == 9){//get element by it ret = mapGetByIt(it,data,data2); if(ret==__DS__MAP__NORMAL__) { printf("The key of curremt it :"); printData( keyType, data); printf("\nThe value of curremt it :"); printData( objType, data2); printf("\n"); }else { printf("Invalid Iterator\n"); } } else if(choice == 10){//empty if(mapEmpty(p)==__DS__MAP__EMPTY__) printf("The map is empty.\n"); else printf("The map is not empty.\n"); } else if(choice == 11){ mapFree(p); p = NULL; } else if(choice == 12) break; } } }
//-------------------------------------------------------------- void Circle::mouseMoved(int x, int y ){ mapSize(x, y); }
TGen::Engine::DeferredRenderer::DeferredRenderer(TGen::Renderer & renderer, TGen::Engine::StandardLogs & logs, TGen::Engine::VariableRegister & variables, TGen::Engine::ResourceManager & resources) : TGen::Engine::WorldRenderer(renderer) , logs(logs) , variables(variables) , resources(resources) , vars(variables) , mainCamera(NULL) , lastNumLights(0) , lightBatchSize(8) , lightMaterials(NULL) //, world(NULL) , metaLines(renderer, 1000000, TGen::PrimitiveLines, TGen::UsageStream) { logs.info["dfr+"] << "deferred renderer initializing..." << TGen::endl; rhwNoTransformShader = resources.getShaderProgram("rhwNoTransform"); rhwOnlyColorMaterial = resources.getMaterial("deferred/rhwOnlyColor"); screenFillMesh = resources.getMesh("gen:fillquad"); lightAmbientMaterial = resources.getMaterial("deferred/lightAmbient"); lightDirectionalMaterial = resources.getMaterial("deferred/lightDirectional"); lightPositionalMaterial = resources.getMaterial("deferred/lightPositional"); postLuminanceMaterial = resources.getMaterial("post/luminance"); postGaussianHorizMaterial = resources.getMaterial("post/gaussianHoriz"); postGaussianVertMaterial = resources.getMaterial("post/gaussianVert"); postFinalBloom = resources.getMaterial("post/finalBloom"); metaNormalMaterial = resources.getMaterial("meta/normal"); TGen::Rectangle mapSize(int(this->variables["env_width"]), int(this->variables["env_height"])); if (vars.forceBinaryMRT) mapSize = TGen::Rectangle(ceilPowerOfTwo(mapSize.width), ceilPowerOfTwo(mapSize.height)); try { colorMap = depthMap = normalMap = miscMap = postMap1 = postMap2 = postMap3 = NULL; mapTargets = postTargets1 = postTargets2 = postTargets3 = NULL; createResources(mapSize); } // TODO: clean up, auto_ptr catch (const TGen::RuntimeException & e) { // trying power-of-two texture size delete colorMap; delete depthMap; delete normalMap; delete miscMap; delete mapTargets; delete postMap1; delete postMap2; delete postTargets1; delete postTargets2; delete postMap3; delete postTargets3; colorMap = depthMap = normalMap = miscMap = postMap1 = postMap2 = postMap3 = NULL; mapTargets = postTargets1 = postTargets2 = postTargets3 = NULL; mapSize = TGen::Rectangle(ceilPowerOfTwo(mapSize.width), ceilPowerOfTwo(mapSize.height)); logs.warning["dfr+"] << e << TGen::endl; logs.warning["dfr+"] << "trying " << std::string(mapSize) << "..." << TGen::endl; createResources(mapSize); } logs.info["dfr+"] << "mrts size: " << std::string(mapSize) << TGen::endl; lightMaterials = new TGen::Material*[lightBatchSize * 3]; //loadLightMaterial("deferred/lightDirectional", 0); logs.info["dfr+"] << "light batch size: " << lightBatchSize << TGen::endl; TGen::Rectangle viewport = renderer.getViewport(); renderer.setRenderTarget(postTargets2); renderer.setViewport(downsampleSize); renderer.clearBuffers(TGen::ColorBuffer); renderer.setRenderTarget(NULL); renderer.setViewport(viewport); logs.info["dfr+"] << "bloom downsampling: " << std::string(downsampleSize) << TGen::endl; logs.info["dfr+"] << "initialized" << TGen::endl; }
#define NL_VMOD_MASK 0 static struct xkb_kt_map_entry mapKeypad[]= { { True, ShiftMask, { 1, ShiftMask, 0 } }, { False, 0, { 1, 0, NL_VMOD_MASK } } }; static struct xkb_key_type canonicalTypes[XkbNumRequiredTypes] = { { { 0, 0, 0 }, 1, /* num_levels */ 0, /* map_count */ NULL, NULL, None, NULL }, { { ShiftMask, ShiftMask, 0 }, 2, /* num_levels */ mapSize(map2Level), /* map_count */ map2Level, NULL, None, NULL }, { { ShiftMask|LockMask, ShiftMask|LockMask, 0 }, 2, /* num_levels */ mapSize(mapAlpha), /* map_count */ mapAlpha, preAlpha, None, NULL }, { { ShiftMask, ShiftMask, NL_VMOD_MASK }, 2, /* num_levels */ mapSize(mapKeypad), /* map_count */ mapKeypad, NULL, None, NULL }
int main(int iArgC, char *cArgV[]) { #ifdef __GLIBCXX__ // Set a better exception handler std::set_terminate(__gnu_cxx::__verbose_terminate_handler); #endif // Disable stdin/printf/etc. sync for a speed boost std::ios_base::sync_with_stdio(false); // Declare the supported options. po::options_description poActions("Actions"); poActions.add_options() ("info,i", "display information about the map, including attributes/metadata") ("print,p", po::value<int>(), "print the given layer in ASCII") ("render,r", po::value<std::string>(), "render the map to the given .png file") ; po::options_description poOptions("Options"); poOptions.add_options() ("type,t", po::value<std::string>(), "specify the map type (default is autodetect)") ("graphics,g", po::value<std::string>(), "filename storing game graphics (required with --render)") ("script,s", "format output suitable for script parsing") ("force,f", "force open even if the map is not in the given format") ("list-types", "list supported file types") ; po::options_description poHidden("Hidden parameters"); poHidden.add_options() ("map", "map file to manipulate") ("help", "produce help message") ; po::options_description poVisible(""); poVisible.add(poActions).add(poOptions); po::options_description poComplete("Parameters"); poComplete.add(poActions).add(poOptions).add(poHidden); po::variables_map mpArgs; std::string strFilename, strType; std::map<gm::ImagePurpose, gm::Map::GraphicsFilename> manualGfx; bool bScript = false; // show output suitable for script parsing? bool bForceOpen = false; // open anyway even if map not in given format? int iRet = RET_OK; try { po::parsed_options pa = po::parse_command_line(iArgC, cArgV, poComplete); // Parse the global command line options for (auto& i : pa.options) { if (i.string_key.empty()) { // If we've already got an map filename, complain that a second one // was given (probably a typo.) if (!strFilename.empty()) { std::cerr << "Error: unexpected extra parameter (multiple map " "filenames given?!)" << std::endl; return 1; } assert(i.value.size() > 0); // can't have no values with no name! strFilename = i.value[0]; } else if (i.string_key.compare("help") == 0) { std::cout << "Copyright (C) 2010-2015 Adam Nielsen <*****@*****.**>\n" "This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n" "and you are welcome to change and redistribute it under certain conditions;\n" "see <http://www.gnu.org/licenses/> for details.\n" "\n" "Utility to manipulate map files used by games to store data files.\n" "Build date " __DATE__ " " __TIME__ << "\n" "\n" "Usage: gamemap <map> <action> [action...]\n" << poVisible << "\n" << std::endl; return RET_OK; } else if ( (i.string_key.compare("t") == 0) || (i.string_key.compare("type") == 0) ) { strType = i.value[0]; } else if ( (i.string_key.compare("g") == 0) || (i.string_key.compare("graphics") == 0) ) { std::string purpose, temp; gm::Map::GraphicsFilename gf; bool a = split(i.value[0], '=', &purpose, &temp); bool b = split(temp, ':', &gf.type, &gf.filename); if (!a || !b) { std::cerr << "Malformed -g/--graphics parameter. Must be of the " "form purpose=type:filename.\n" "Use --help or --list-types for details." << std::endl; return RET_BADARGS; } bool found = false; for (unsigned int i = 0; i < (unsigned int)gm::ImagePurpose::ImagePurposeCount; i++) { gm::ImagePurpose p = (gm::ImagePurpose)i; if (purpose.compare(toString(p)) == 0) { manualGfx[p] = gf; found = true; } } if (!found) { std::cerr << "No match for tileset purpose: " << purpose << "\n" << "Use --list-types for details." << std::endl; return RET_BADARGS; } } else if ( (i.string_key.compare("s") == 0) || (i.string_key.compare("script") == 0) ) { bScript = true; } else if ( (i.string_key.compare("f") == 0) || (i.string_key.compare("force") == 0) ) { bForceOpen = true; } else if ( (i.string_key.compare("list-types") == 0) ) { std::cout << "Tileset purposes: (--graphics purpose=type:file)\n"; for (unsigned int i = 0; i < (unsigned int)gm::ImagePurpose::ImagePurposeCount; i++) { gm::ImagePurpose p = (gm::ImagePurpose)i; std::cout << " " << toString(p) << "\n"; } std::cout << "\nTileset types: (--graphics purpose=type:file)\n"; for (auto& tilesetType : gg::TilesetManager::formats()) { std::string code = tilesetType->code(); std::cout << " " << code; int len = code.length(); if (len < 20) std::cout << std::string(20-code.length(), ' '); std::cout << ' ' << tilesetType->friendlyName(); auto ext = tilesetType->fileExtensions(); if (ext.size()) { auto i = ext.begin(); std::cout << " (*." << *i; for (i++; i != ext.end(); i++) { std::cout << "; *." << *i; } std::cout << ")"; } std::cout << '\n'; } std::cout << "\nMap types: (--type)\n"; for (auto& mapType : gm::MapManager::formats()) { std::string code = mapType->code(); std::cout << " " << code; int len = code.length(); if (len < 20) std::cout << std::string(20 - code.length(), ' '); std::cout << ' ' << mapType->friendlyName(); auto ext = mapType->fileExtensions(); if (ext.size()) { auto i = ext.begin(); std::cout << " (*." << *i; for (i++; i != ext.end(); i++) { std::cout << "; *." << *i; } std::cout << ")"; } std::cout << '\n'; } return RET_OK; } } if (strFilename.empty()) { std::cerr << "Error: no game map filename given" << std::endl; return RET_BADARGS; } std::cout << "Opening " << strFilename << " as type " << (strType.empty() ? "<autodetect>" : strType) << std::endl; std::unique_ptr<stream::inout> content; try { content = std::make_unique<stream::file>(strFilename, false); } catch (const stream::open_error& e) { std::cerr << "Error opening " << strFilename << ": " << e.what() << std::endl; return RET_SHOWSTOPPER; } gm::MapManager::handler_t mapType; if (strType.empty()) { // Need to autodetect the file format. for (auto& mapTestType : gm::MapManager::formats()) { gm::MapType::Certainty cert = mapTestType->isInstance(*content); switch (cert) { case gm::MapType::Certainty::DefinitelyNo: // Don't print anything (TODO: Maybe unless verbose?) break; case gm::MapType::Certainty::Unsure: std::cout << "File could be a " << mapTestType->friendlyName() << " [" << mapTestType->code() << "]" << std::endl; // If we haven't found a match already, use this one if (!mapType) mapType = mapTestType; break; case gm::MapType::Certainty::PossiblyYes: std::cout << "File is likely to be a " << mapTestType->friendlyName() << " [" << mapTestType->code() << "]" << std::endl; // Take this one as it's better than an uncertain match mapType = mapTestType; break; case gm::MapType::Certainty::DefinitelyYes: std::cout << "File is definitely a " << mapTestType->friendlyName() << " [" << mapTestType->code() << "]" << std::endl; mapType = mapTestType; // Don't bother checking any other formats if we got a 100% match goto finishTesting; } if (cert != gm::MapType::Certainty::DefinitelyNo) { // We got a possible match, see if it requires any suppdata auto suppList = mapTestType->getRequiredSupps(*content, strFilename); if (suppList.size() > 0) { // It has suppdata, see if it's present std::cout << " * This format requires supplemental files..." << std::endl; bool bSuppOK = true; for (auto& i : suppList) { try { auto suppStream = std::make_unique<stream::file>(i.second, false); } catch (const stream::open_error&) { bSuppOK = false; std::cout << " * Could not find/open " << i.second << ", map is probably not " << mapTestType->code() << std::endl; break; } } if (bSuppOK) { // All supp files opened ok std::cout << " * All supp files present, map is likely " << mapTestType->code() << std::endl; // Set this as the most likely format mapType = mapTestType; } } } } finishTesting: if (!mapType) { std::cerr << "Unable to automatically determine the file type. Use " "the --type option to manually specify the file format." << std::endl; return RET_BE_MORE_SPECIFIC; } } else { mapType = gm::MapManager::byCode(strType); if (!mapType) { std::cerr << "Unknown file type given to -t/--type: " << strType << std::endl; return RET_BADARGS; } } assert(mapType != NULL); // Check to see if the file is actually in this format if (!mapType->isInstance(*content)) { if (bForceOpen) { std::cerr << "Warning: " << strFilename << " is not a " << mapType->friendlyName() << ", open forced." << std::endl; } else { std::cerr << "Invalid format: " << strFilename << " is not a " << mapType->friendlyName() << "\n" << "Use the -f option to try anyway." << std::endl; return RET_BE_MORE_SPECIFIC; } } // See if the format requires any supplemental files camoto::SuppData suppData; for (auto& i : mapType->getRequiredSupps(*content, strFilename)) { try { std::cerr << "Opening supplemental file " << i.second << std::endl; suppData[i.first] = std::make_unique<stream::file>(i.second, false); } catch (const stream::open_error& e) { std::cerr << "Error opening supplemental file " << i.second << ": " << e.what() << std::endl; // Continue anyway in case the file is optional } } // Open the map file std::shared_ptr<gm::Map> pMap = mapType->open(std::move(content), suppData); assert(pMap); // File type of inserted files defaults to empty, which means 'generic file' std::string strLastFiletype; // Run through the actions on the command line for (auto& i : pa.options) { if (i.string_key.compare("info") == 0) { listAttributes(pMap.get(), bScript); std::cout << (bScript ? "gfx_filename_count=" : "Number of graphics filenames: ") << pMap->graphicsFilenames().size() << "\n"; int fileNum = 0; for (auto& a : pMap->graphicsFilenames()) { if (bScript) { std::cout << "gfx_file" << fileNum << "_name=" << a.second.filename << "\n"; std::cout << "gfx_file" << fileNum << "_type=" << a.second.type << "\n"; std::cout << "gfx_file" << fileNum << "_purpose=" << (unsigned int)a.first << "\n"; } else { std::cout << "Graphics file " << fileNum+1 << ": " << a.second.filename << " ["; switch (a.first) { case gm::ImagePurpose::GenericTileset1: std::cout << "Generic tileset 1"; break; case gm::ImagePurpose::BackgroundImage: std::cout << "Background image"; break; case gm::ImagePurpose::BackgroundTileset1: std::cout << "Background tileset 1"; break; case gm::ImagePurpose::BackgroundTileset2: std::cout << "Background tileset 2"; break; case gm::ImagePurpose::ForegroundTileset1: std::cout << "Foreground tileset 1"; break; case gm::ImagePurpose::ForegroundTileset2: std::cout << "Foreground tileset 2"; break; case gm::ImagePurpose::SpriteTileset1: std::cout << "Sprite tileset 1"; break; case gm::ImagePurpose::FontTileset1: std::cout << "Font tileset 1"; break; case gm::ImagePurpose::FontTileset2: std::cout << "Font tileset 2"; break; default: std::cout << "Unknown purpose <fix this>"; break; } std::cout << " of type " << a.second.type << "]\n"; } fileNum++; } std::cout << (bScript ? "map_type=" : "Map type: "); auto map2d = std::dynamic_pointer_cast<gm::Map2D>(pMap); if (map2d) { std::cout << (bScript ? "2d" : "2D grid-based") << "\n"; #define CAP(o, c, v) " " __STRING(c) << ((v & o::Caps::c) ? '+' : '-') #define MAP2D_CAP(c) CAP(gm::Map2D, c, mapCaps) #define MAP2D_LAYER_CAP(c) CAP(gm::Map2D::Layer, c, layerCaps) auto mapCaps = map2d->caps(); if (bScript) { std::cout << "map_caps=" << (unsigned int)mapCaps << "\n"; } else { std::cout << "Map capabilities:" << MAP2D_CAP(HasViewport) << MAP2D_CAP(HasMapSize) << MAP2D_CAP(SetMapSize) << MAP2D_CAP(HasTileSize) << MAP2D_CAP(SetTileSize) << MAP2D_CAP(AddPaths) << "\n" ; } auto mapTileSize = map2d->tileSize(); std::cout << (bScript ? "tile_width=" : "Tile size: ") << mapTileSize.x << (bScript ? "\ntile_height=" : "x") << mapTileSize.y << "\n"; auto mapSize = map2d->mapSize(); std::cout << (bScript ? "map_width=" : "Map size: ") << mapSize.x << (bScript ? "\nmap_height=" : "x") << mapSize.y << (bScript ? "" : " tiles") << "\n"; if (mapCaps & gm::Map2D::Caps::HasViewport) { auto vp = map2d->viewport(); std::cout << (bScript ? "viewport_width=" : "Viewport size: ") << vp.x << (bScript ? "\nviewport_height=" : "x") << vp.y << (bScript ? "" : " pixels") << "\n"; } unsigned int layerCount = map2d->layers().size(); std::cout << (bScript ? "layercount=" : "Layer count: ") << layerCount << "\n"; unsigned int layerIndex = 0; for (auto& layer : map2d->layers()) { std::string prefix; if (bScript) { std::stringstream ss; ss << "layer" << layerIndex << '_'; prefix = ss.str(); std::cout << prefix << "name=" << layer->title() << "\n"; } else { prefix = " "; std::cout << "Layer " << layerIndex + 1 << ": \"" << layer->title() << "\"\n"; } auto layerCaps = layer->caps(); if (bScript) std::cout << prefix << "caps=" << (unsigned int)layerCaps << "\n"; else std::cout << prefix << "Capabilities:" << MAP2D_LAYER_CAP(HasOwnSize) << MAP2D_LAYER_CAP(SetOwnSize) << MAP2D_LAYER_CAP(HasOwnTileSize) << MAP2D_LAYER_CAP(SetOwnTileSize) << MAP2D_LAYER_CAP(HasPalette) << MAP2D_LAYER_CAP(UseImageDims) << "\n" ; gg::Point layerTileSize; bool layerTileSame; if (layerCaps & gm::Map2D::Layer::Caps::HasOwnTileSize) { layerTileSize = layer->tileSize(); layerTileSame = false; } else { layerTileSize = mapTileSize; layerTileSame = true; } std::cout << prefix << (bScript ? "tile_width=" : "Tile size: ") << layerTileSize.x; if (bScript) std::cout << "\n" << prefix << "tile_height="; else std::cout << "x"; std::cout << layerTileSize.y; if (layerTileSame && (!bScript)) { std::cout << " (same as map)"; } std::cout << "\n"; gg::Point layerSize; bool layerSame; if (layerCaps & gm::Map2D::Layer::Caps::HasOwnSize) { layerSize = layer->layerSize(); layerSame = false; } else { // Convert from map tilesize to layer tilesize, leaving final // pixel dimensions unchanged layerSize.x = mapSize.x * mapTileSize.x / layerTileSize.x; layerSize.y = mapSize.y * mapTileSize.y / layerTileSize.y; layerSame = true; } std::cout << prefix << (bScript ? "width=" : "Layer size: ") << layerSize.x; if (bScript) std::cout << "\n" << prefix << "height="; else std::cout << "x"; std::cout << layerSize.y; if (layerSame && (!bScript)) { std::cout << " (same as map)"; } std::cout << "\n"; layerIndex++; } } else { std::cout << (bScript ? "unknown" : "Unknown! Fix this!") << "\n"; } } else if (i.string_key.compare("print") == 0) { auto map2d = std::dynamic_pointer_cast<gm::Map2D>(pMap); if (map2d) { unsigned int targetLayer = strtoul(i.value[0].c_str(), NULL, 10); if (targetLayer == 0) { std::cerr << "Invalid layer index passed to --print. Use --info " "to list layers in this map." << std::endl; iRet = RET_BADARGS; continue; } if (targetLayer > map2d->layers().size()) { std::cerr << "Invalid layer index passed to --print. Use --info " "to list layers in this map." << std::endl; iRet = RET_BADARGS; continue; } auto layer = map2d->layers().at(targetLayer - 1); // If this fails, the map format returned a null pointer for the layer assert(layer); // Figure out the layer size gg::Point layerSize, tileSize; getLayerDims(*map2d, *layer, &layerSize, &tileSize); auto items = layer->items(); auto t = items.begin(); unsigned int numItems = items.size(); if (t != items.end()) { for (unsigned int y = 0; y < layerSize.y; y++) { for (unsigned int x = 0; x < layerSize.x; x++) { for (unsigned int i = 0; i < numItems; i++) { if ((t->pos.x == x) && (t->pos.y == y)) break; t++; if (t == items.end()) t = items.begin(); } if ((t->pos.x != x) || (t->pos.y != y)) { // Grid position with no tile! std::cout << " "; } else { std::cout << std::hex << std::setw(4) << (unsigned int)t->code << ' '; } } std::cout << "\n"; } } else { std::cout << "Layer is empty!" << std::endl; } } else { std::cerr << "Support for printing this map type has not yet " "been implemented!" << std::endl; } } else if (i.string_key.compare("render") == 0) { // Don't need to check i.value[0], program_options does that for us auto map2d = std::dynamic_pointer_cast<gm::Map2D>(pMap); if (map2d) { gm::TilesetCollection allTilesets; for (auto& a : manualGfx) { if (!bScript) { std::cout << "Loading " << a.second.type << " from " << a.second.filename << std::endl; } allTilesets[a.first] = openTileset(a.second.filename, a.second.type); } for (auto& a : pMap->graphicsFilenames()) { if (allTilesets.find(a.first) == allTilesets.end()) { if (a.second.filename.empty()) { std::cerr << toString(a.first) << " is required, and must " "be specified manually with --graphics." << std::endl; iRet = RET_BADARGS; } else { // This tileset hasn't been specified on the command line, but the // map format handler has given us a filename, so open the file // suggested from the map. allTilesets[a.first] = openTileset(a.second.filename, a.second.type); } } else { if (!a.second.filename.empty()) { std::cout << toString(a.first) << " overridden on command-line\n"; } } } if (allTilesets.empty()) { std::cerr << "No tilesets were loaded, map cannot be rendered. " "Use --graphics to specify a tileset." << std::endl; iRet = RET_BADARGS; } else { map2dToPng(*map2d, allTilesets, i.value[0]); } } else { std::cerr << PROGNAME ": Rendering this type of map is not yet " "implemented." << std::endl; return RET_SHOWSTOPPER; } // Ignore --type/-t } else if (i.string_key.compare("type") == 0) { } else if (i.string_key.compare("t") == 0) { // Ignore --script/-s } else if (i.string_key.compare("script") == 0) { } else if (i.string_key.compare("s") == 0) { // Ignore --force/-f } else if (i.string_key.compare("force") == 0) { } else if (i.string_key.compare("f") == 0) { } } // for (all command line elements) //pMap->flush(); } catch (const po::error& e) { std::cerr << PROGNAME ": " << e.what() << " Use --help for help." << std::endl; return RET_BADARGS; } catch (const stream::error& e) { std::cerr << PROGNAME ": " << e.what() << " Use --help for help." << std::endl; return RET_SHOWSTOPPER; } return iRet; }
void STPlaceView::relayout() { if(m_size.isEmpty()) return; if(m_coords.isEmpty() && m_place.isEmpty()) return; bool loaded=m_lastWidth!=m_size.width(); m_lastWidth=m_size.width(); const int labelHeight=16; QSize mapSize(m_size.width(), m_size.height()-labelHeight); m_mapView->setSize(mapSize); if((!m_coords.isEmpty()) || (!m_place.isEmpty())) { if((!mapSize.isEmpty()) && !m_mapView->ticket()) { m_mapView->setTicket(STStaticMapImageManager::sharedManager()->requestWithObjects(m_coords, m_place, mapSize-QSize(4,4))); } } if(loaded) { if(m_coords.isEmpty()) { } else { QString txt; STMapCoord crd(m_coords["coordinates"]); if(crd.latitude>=0.) { txt=tr(":degN, ").replace(QLatin1String(":deg"), QString::number(crd.latitude, 'f', 1)); } else { txt=tr(":degS, ").replace(QLatin1String(":deg"), QString::number(-crd.latitude, 'f', 1)); } if(crd.longitude>=0.) { txt+=tr(":degE").replace(QLatin1String(":deg"), QString::number(crd.longitude, 'f', 1)); } else { txt+=tr(":degW").replace(QLatin1String(":deg"), QString::number(-crd.longitude, 'f', 1)); } QList<STObjectManager::EntityRange> ranges; STObjectManager::EntityRange range; range.charIndexStart=0; range.charIndexEnd=txt.length(); range.entityType="st_url"; range.entity=QString("https://maps.google.com/maps?q=%1,%2&z=5").arg(QString::number(crd.latitude, 'f'), QString::number(crd.longitude, 'f')); ranges.append(range); m_coordView->setContents(STFont::defaultFont(), txt, ranges); } } int labelPos=m_size.height()-labelHeight+3; int coordsLeft=m_size.width()-(int)m_coordView->boundingRect().right(); m_coordView->setPos(coordsLeft, labelPos); if(loaded) { if(!m_place.isEmpty()) { QString txt=m_place["name"].toString(); m_nameView->setContents(STFont::defaultBoldFont(), txt,(float)coordsLeft+m_coordView->boundingRect().left()-3,true); } } m_nameView->setPos(1, labelPos); }