Beispiel #1
0
void Logger::log(sf::String message)
{
	if (isLoggingEnabled)
	{
		time_t now = time(0);
		tm *localTime = localtime(&now);
		std::clog << 1900 + localTime->tm_year << ".";
		std::clog << 1 + localTime->tm_mon << ".";
		std::clog << localTime->tm_mday << ". ";
		std::clog << localTime->tm_hour << ":";
		std::clog << localTime->tm_min << ":";
		std::clog << localTime->tm_sec << " [";
		std::clog << className.toAnsiString() << "] ";
		std::clog << message.toAnsiString();
		std::clog << std::endl;
	}
}
Beispiel #2
0
 String::String(sf::String str)
     : QString(str.toAnsiString().c_str())
 { }
Beispiel #3
0
	void error(sf::String s)
	{
		std::cout << "Error: " << s.toAnsiString() << std::endl;
	}
Beispiel #4
0
	void log(sf::String s)
	{
        std::cout << "BEngine: " << s.toAnsiString() << std::endl;
	}
Beispiel #5
0
int Game::load(sf::String path, SFG::SplashScreen* ss)
{
	if(m_game_console.init() != 0)
		SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__,
			"Failed to init console"
		);
	
	if(!m_timing_font.loadFromFile("Fonts/arial.ttf"))
		SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__,
			"Failed to load font"
		);
	
	printf("Setting font... ");
	m_timing_display.setFont(m_timing_font);
	printf("Done.\n");
	m_timing_display.setString("Asd");
	
    XMLReader reader;
    sf::String out;
    if (basicLoadFile(path.toWideString(), out) != 0)
    {
        printf("[Error] Failed to load file %s in %s:%d\n", path.toAnsiString().c_str(), __FILE__, __LINE__);
        return -1;
    }


    reader.setSource(out);

    //Start parsing
    if (reader.parse() != 0)
    {
        //Errors happening
    }
    //For now, we only need to load the gamestates up...

    //Get the loading gamestate (with fancy animations and stuff)
    int ret = 0;
    auto sugs = SFG::Pointer<GameState>(new StartupGameState());
    if ((ret = loadGamestate(reader, L"Startup", sugs)) < 0)
    {
        printf("[Error] Failed to load Startup Gamestate in %s:%d from file \"%s\" with Code %d.\n", __FILE__, __LINE__, path.toAnsiString().c_str(), ret);
    }
    //The first gamestate always needs to be inited
    this->g_gamestates[0]->init(this->window);
    //Get the menu gamestate
    SFG::Pointer<GameState> menu(new MenuGameState());
    if ((ret = loadGamestate(reader, L"Menu", menu)) < 0)
    {
        printf("[Error] Failed to load Menu Gamestate in %s:%d from file \"%s\" with Code %d.\n", __FILE__, __LINE__, path.toAnsiString().c_str(), ret);
    }


    //Get all other gamestates
    for (size_t i = 2; ; i++)
    {
        sf::String path = L"xml/gamestate#" + std::to_wstring(i) + L"/";
        sf::String ret = reader.getValue(path);
        if (ret == L"__xml_failure")
        {
            break;
        }
        else
        {
            //#TODO: Add custom gamestate
            //STILL_TO_DO(__FILE__, __LINE__);

            int res = loadGamestate(reader, reader.getValue(path + "name."), SFG::Pointer<GameState>(nullptr));
            if (res != 0)
            {
                std::string tmp = reader.getValue(path + "name.").toAnsiString();
                SFG::Util::printLog(SFG::Util::LogMessageType::Error, __FILE__, __LINE__, "Failed to load custom gamestate named \"%s\"", tmp.c_str());
            }

        }

    }



    //Reading done
    if (ss != nullptr)
    {
        //Tell the SplashScreen to disappear
        ss->notify(SFG::SplashScreen::SplashScreenMessages::LoadingDone);
    }
    return 0;
}
Beispiel #6
0
int Game::loadGamestate(const XMLReader& reader, const sf::String& GSname, const SFG::Pointer<GameState>& included)
{
    SFG::Pointer<GameState> GS_ptr;

    sf::String GSxmlpath = L"xml/gamestate[" + GSname + L"]";
    auto str = reader.getValue(GSxmlpath, 0);

    if (str == L"__xml_failure")
    {
        printf("[Error] Unspecified startup gamestate in %s:%d.\n", __FILE__, __LINE__);
        return -2;
    }
    else
    {

        if (str == L"#included")
        {
            //Use default
            GS_ptr.reset(included);
            if (!GS_ptr.isValid() && included.getElement() != nullptr)
            {
                printf("[Critical] Failed to allocate memory for \"%s\" in %s:%d\n",GSname.toAnsiString().c_str(), __FILE__, __LINE__);
                return -1;
            }

        }
        else
        {
            //Use specified
            //#TODO
            STILL_TO_DO(__FILE__, __LINE__);
            //We first need an instance of a DLLLoadedGameState
            GS_ptr.reset(new DLLLoadedGameState());
            //Set the name
            GS_ptr->setName(GSname);
            if (GS_ptr->getName() == "__xml_failure")
            {
                SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__, "Failed to get Gamestate name, aborting.");
                return -1;
            }
            //Then, load the specified file
            if (GS_ptr.cast<DLLLoadedGameState>()->loadFromDll(str.toAnsiString().c_str()) != 0)
            {
                SFG::Util::printLog(SFG::Util::Error, __FILE__, __LINE__,
									"Failed to load gamestate \"%s\" from DLL", str.toAnsiString().c_str());
                return -2;
            }

            //We actually should be done


        }

        //Get all modules
        sf::String uses = reader.getValue(GSxmlpath + L"uses.");
        if (uses != L"__xml_failure")
        {
            //We have specifiers
            size_t begin = 0;
            size_t last = 0;
            //Begin needs to be checked as the last module wouldn't be counted otherwise
            while ((last = uses.find(L',', last)) != sf::String::InvalidPos || begin != sf::String::InvalidPos)
            {
                sf::String string;
                if (last == sf::String::InvalidPos)
                {
                    //If the end would otherwise exceed the string length, set it to the maximum (sf::String::end()).
                    //string = sf::String(uses.begin() + begin, uses.end());
                    string = uses.substring(begin, uses.getSize() - begin);
                }
                else
                {
                    //If a ',' was found, use its position
                    //string = sf::String(uses.begin() + begin, uses.begin() + last);
                    string = uses.substring(begin, last - begin);
                }
                //Check for module names
                if (string == L"G2D")
                {
                    SFG::Pointer<ModuleG2D> ptr(new ModuleG2D());
                    if (!ptr.isValid())
                    {
                        char buf[512];
#ifdef _WIN32
                        strerror_s(buf, errno);
#else
                        strerror_r(errno, buf, 512);
#endif // _WIN32
                        printf("[Error] Failed to create Module G2D in %s:%d: %s\n", __FILE__, __LINE__, buf);
                        return -3;
                    }
                    GS_ptr->addModule(ptr);
                }
                else
                {
                    //#TODO: Add more modules (sound etc.)
                    STILL_TO_DO(__FILE__, __LINE__);
                }
                if(last != sf::String::InvalidPos) begin = last + 1; //if a ',' was found, go search on for the next one
                else begin = last; //Meaning begin is sf::String::npos
            }
        }

        //Check for external asset list
        auto ext_assets = reader.getValue(GSxmlpath + "assets.");
        if (ext_assets != "__xml_failure")
        {
            //We found external assets, load them
        }
        auto assets = reader.getXMLGroupHandle(L"xml/assetlist[" + GSname + L"]");
        if (assets == nullptr)
        {
            printf("[Warning] No assets for Gamestate \"%s\" found. This is not encouraged and might be an error. Please check the game.xml file. In: %s:%d\n", GSname.toAnsiString().c_str(), __FILE__, __LINE__);
            //return 1;
        }
        else
        {
            auto ret = GS_ptr->loadAssets(XMLReader(*assets));
            if (ret != 0)
            {
                printf("[Error] Failed to load assets for Gamestate \"%s\" in %s:%d.\n", GSname.toAnsiString().c_str(), __FILE__, __LINE__);
            }
        }

        //Empty path to tell the gamestate to just update what it has (or do nothing if nothing has to be done)
        GS_ptr->load(L"");

        //this->g_gamestates.push_back(GS_ptr);
        this->addGamestate(GS_ptr);
    }
    return 0;
}
void ResourcesManager::loadTexture(sf::String textureName)
{
	if (this->_textures.find(textureName) == this->_textures.end() && !this->_textures[textureName].loadFromFile("resources/" + textureName))
		std::cerr << "Texture " << textureName.toAnsiString() << " couldn't be loaded" << std::endl;
}
Beispiel #8
0
void cConsole::addToInput(sf::String str)
{
	input.append(str.toAnsiString(locale("russian")));
	inputDisplay += str;
}