void Application::init() { m_pWindow = new sf::RenderWindow(sf::VideoMode(1600, 900), "Hex Test", sf::Style::Close); m_pRenderer = new Renderer(); m_pRenderer->SetRenderCallbackFunc(draw_wrapper); m_pInput = new InputHandler(); m_pInput->setKeyPressedCallbackFunc(key_pressed_wrapper); m_pInput->setKeyReleasedCallbackFunc(key_released_wrapper); m_pInput->setMouseMovedCallbackFunc(mouse_moved_wrapper); m_pInput->setMouseWheelScrollCallbackFunc(mouse_wheel_scroll_wrapper); m_pInput->setMouseButtonPressedCallbackFunc(mouse_pressed_wrapper); m_pInput->setMouseButtonReleasedCallbackFunc(mouse_released_wrapper); assert(loadTextures()); assert(loadFonts()); m_TerrainInfos[0] = TerrainInfo("TERRAIN_GRASS", 1, 0, TERRIAN_TYPE_GRASS); m_TerrainInfos[1] = TerrainInfo("TERRAIN_PLAINS", 1, 1, TERRIAN_TYPE_GRASS); loadMap(); loop(); }
void InformationStorage::loadAll(string file) { //Clear out the object types first terrainTypes.clear(); buildingTypes.clear(); unitTypes.clear(); TiXmlDocument doc( file.c_str()); if(doc.LoadFile()) { TiXmlHandle hDoc(&doc); TiXmlElement* pElem; TiXmlHandle hRoot(0); pElem = hDoc.FirstChildElement().Element(); hRoot=TiXmlHandle(pElem); //--------------------------------Load in Units---------------------- TiXmlNode* pUnitNode=hRoot.FirstChild( "Units" ).FirstChild().ToNode(); TiXmlNode* pUnitInfoNode; //For loop will cycle through each unit within the Units tag for( pUnitNode; pUnitNode; pUnitNode=pUnitNode->NextSiblingElement()) { //Need to iterate through the data of a unit; can make a pointer to the first child of pUnitNode for ID, get NextSiblingElement for other elements, use //query attributes for combat stats. UnitInfo u = UnitInfo(); u.load(pUnitNode); unitTypes[u.id] = u; } //----------------------Load in Terrain------------------------------- TiXmlNode* pTerrainNode=hRoot.FirstChild( "Terrain" ).FirstChild().ToNode(); TiXmlNode* pTerrainInfoNode; //For loop will cycle through each unit within the Units tag for( pTerrainNode; pTerrainNode; pTerrainNode=pTerrainNode->NextSiblingElement()) { //Need to iterate through the data of a unit; can make a pointer to the first child of pUnitNode for ID, get NextSiblingElement for other elements, use //query attributes for combat stats. TerrainInfo t = TerrainInfo(); t.load(pTerrainNode); terrainTypes[t.id] = t; } //---------------------------------Load in Buildings-------------------------------------- TiXmlNode* pBuildingNode=hRoot.FirstChild( "Buildings" ).FirstChild().ToNode(); //TiXmlNode* pBuildingInfoNode; //TiXmlNode* pProductionIDNode; //For loop will cycle through each unit within the Units tag for( pBuildingNode; pBuildingNode; pBuildingNode=pBuildingNode->NextSiblingElement()) { //Need to iterate through the data of a unit; can make a pointer to the first child of pUnitNode for ID, get NextSiblingElement for other elements, use //query attributes for combat stats. BuildingInfo b = BuildingInfo(); b.load(pBuildingNode); buildingTypes[b.id] = b; } //-------------------------------Load in Commander Cards-------------------------------- TiXmlNode* pCardNode = hRoot.FirstChild( "Cards" ).FirstChild().ToNode(); for( pCardNode; pCardNode; pCardNode=pCardNode->NextSiblingElement()) { CardInfo c = CardInfo(); c.load(pCardNode); cardTypes[c.id] = c; } } else { //std::cout << "\nFailed to load the units\n"; } DeveloperConsole::write("Buildings Loaded: "); DeveloperConsole::writeLine(buildingTypes.size()); DeveloperConsole::write("Units Loaded: "); DeveloperConsole::writeLine(unitTypes.size()); DeveloperConsole::write("Terrain Loaded: "); DeveloperConsole::writeLine(terrainTypes.size()); }