Example #1
0
int main (int argc, const char **argv) {
	std::vector< std::pair< std::string, int > > times;
	std::vector< std::string > arguments;
	FileMapper mapper;
	
	QTime timeTotal;
	timeTotal.start ();
	
	// Parse arguments
	const char *helpTitle = "Tria by the NuriaProject, built on " __DATE__ " " __TIME__;
	llvm::cl::ParseCommandLineOptions (argc, argv, helpTitle);
	initClangArguments (argv[0], arguments);
	std::string inputFile = addInputFiles (mapper);
	arguments.push_back (inputFile);
	
	// 
	QVector< GenConf > generators = generatorsFromArguments ();
	mapper.mapRecursive (QDir (":/headers/"), QStringLiteral("/builtins/"));
	
	// Create tool instance
	Definitions definitions (sourceFileList ());
	Compiler compiler (&definitions);
	if (!compiler.prepare (&mapper, arguments)) {
		return 1;
	}
	
	// Run it
	times.emplace_back ("init", timeTotal.elapsed ());
	if (!compiler.run ()) {
		return 2;
	}
	
	// Generate code
	definitions.parsingComplete ();
	times.emplace_back ("parse", timeTotal.elapsed ());
	
	// Run generators
	LuaGenerator luaGenerator (&definitions, &compiler);
	for (int i = 0; i < generators.length (); i++) {
		const GenConf &conf = generators.at (i);
		if (!luaGenerator.generate (conf)) {
			return 5;
		}
		
		times.emplace_back (conf.luaScript.toStdString (), timeTotal.elapsed ());
	}
	
	// 
	printTimes (timeTotal.elapsed (), times, definitions);
	return 0;
}
static FIBITMAP *loadImage(const std::string &file, bool convertTo32bit = true)
{
    #if  defined(__unix__) || defined(__APPLE__) || defined(_WIN32)
    FileMapper fileMap;
    if(!fileMap.open_file(file.c_str()))
        return NULL;

    FIMEMORY *imgMEM = FreeImage_OpenMemory(reinterpret_cast<unsigned char *>(fileMap.data()),
                                            (unsigned int)fileMap.size());
    FREE_IMAGE_FORMAT formato = FreeImage_GetFileTypeFromMemory(imgMEM);
    if(formato  == FIF_UNKNOWN)
        return NULL;
    FIBITMAP *img = FreeImage_LoadFromMemory(formato, imgMEM, 0);
    FreeImage_CloseMemory(imgMEM);
    fileMap.close_file();
    if(!img)
        return NULL;
    #else
    FREE_IMAGE_FORMAT formato = FreeImage_GetFileType(file.c_str(), 0);
    if(formato  == FIF_UNKNOWN)
        return NULL;
    FIBITMAP *img = FreeImage_Load(formato, file.c_str());
    if(!img)
        return NULL;
    #endif

    if(convertTo32bit)
    {
        FIBITMAP *temp;
        temp = FreeImage_ConvertTo32Bits(img);
        if(!temp)
            return NULL;
        FreeImage_Unload(img);
        img = temp;
    }
    return img;
}
Example #3
0
static std::string addInputFiles (FileMapper &mapper) {
	if (argInputFiles.getNumOccurrences () == 1) {
		return *std::begin (argInputFiles);
	}
	
	// Multiple files
	QByteArray fakeHeader;
	for (const std::string &cur : argInputFiles) {
		fakeHeader.append ("#include \"");
		fakeHeader.append (cur.c_str (), cur.length ());
		fakeHeader.append ("\"\n");
	}
	
	// Map virtual fake header including those files
	mapper.mapByteArray (fakeHeader, QStringLiteral("nuriaVirtualHeader.hpp"));
	return std::string ("nuriaVirtualHeader.hpp");
}
Example #4
0
FIBITMAP *GraphicsHelps::loadImage(std::string file, bool convertTo32bit)
{
#ifdef DEBUG_BUILD
    ElapsedTimer loadingTime;
    ElapsedTimer fReadTime;
    ElapsedTimer imgConvTime;
    loadingTime.start();
    fReadTime.start();
#endif
#if  defined(__unix__) || defined(__APPLE__) || defined(_WIN32)
    FileMapper fileMap;

    if(!fileMap.open_file(file.c_str()))
        return NULL;

    FIMEMORY *imgMEM = FreeImage_OpenMemory(reinterpret_cast<unsigned char *>(fileMap.data()),
                                            static_cast<unsigned int>(fileMap.size()));
    FREE_IMAGE_FORMAT formato = FreeImage_GetFileTypeFromMemory(imgMEM);

    if(formato  == FIF_UNKNOWN)
        return NULL;

    FIBITMAP *img = FreeImage_LoadFromMemory(formato, imgMEM, 0);
    FreeImage_CloseMemory(imgMEM);
    fileMap.close_file();

    if(!img)
        return NULL;

#else
    FREE_IMAGE_FORMAT formato = FreeImage_GetFileType(file.toUtf8().data(), 0);

    if(formato  == FIF_UNKNOWN)
        return NULL;

    FIBITMAP *img = FreeImage_Load(formato, file.toUtf8().data());

    if(!img)
        return NULL;

#endif
#ifdef DEBUG_BUILD
    long long fReadTimeElapsed = static_cast<long long>(fReadTime.elapsed());
    long long imgConvertElapsed = 0;
#endif

    if(convertTo32bit)
    {
#ifdef DEBUG_BUILD
        imgConvTime.start();
#endif
        FIBITMAP *temp;
        temp = FreeImage_ConvertTo32Bits(img);

        if(!temp)
            return NULL;

        FreeImage_Unload(img);
        img = temp;
#ifdef DEBUG_BUILD
        imgConvertElapsed = static_cast<long long>(imgConvTime.elapsed());
#endif
    }

#ifdef DEBUG_BUILD
    D_pLogDebug("File read of texture %s passed in %d milliseconds", file.c_str(), static_cast<int>(fReadTimeElapsed));
    D_pLogDebug("Conv to 32-bit of %s passed in %d milliseconds", file.c_str(), static_cast<int>(imgConvertElapsed));
    D_pLogDebug("Total Loading of image %s passed in %d milliseconds", file.c_str(), static_cast<int>(loadingTime.elapsed()));
#endif
    return img;
}
Example #5
0
void ConfigManager::buildSoundIndex()
{
    int need_to_reserve = 0;
    int total_channels = 32;
    bool newBuild = main_sfx_index.empty();
#ifdef DEBUG_BUILD
    ElapsedTimer loadingTime;
    loadingTime.start();
#endif

    if(newBuild)
    {
        //build array table
        main_sfx_index.resize(static_cast<size_t>(main_sound.size()) - 1);

        for(unsigned long i = 1; i < main_sound.size(); i++)
        {
            obj_sound_index sound;

            if(main_sound.contains(i))
            {
                obj_sound &snd = main_sound[i];
#if  defined(__unix__) || defined(__APPLE__) || defined(_WIN32)
                FileMapper fileMap;

                if(fileMap.open_file(snd.absPath.c_str()))
                {
                    sound.chunk = Mix_LoadWAV_RW(SDL_RWFromMem(fileMap.data(),
                                                 static_cast<int>(fileMap.size())), 1);
                    fileMap.close_file();
                }

#else
                sound.chunk = Mix_LoadWAV(snd.absPath.toUtf8().data());
#endif
                sound.path = snd.absPath;

                if(!sound.chunk)
                    pLogWarning("Fail to load sound-%d: %s", i, Mix_GetError());
                else
                    need_to_reserve += (snd.channel >= 0 ? 1 : 0);

                sound.channel = snd.channel;
            }

            main_sfx_index[static_cast<size_t>(i) - 1] = sound;
        }
    }
    else
    {
        for(unsigned long i = 1; (i < main_sound.size()) && (i <= static_cast<unsigned long>(main_sfx_index.size())); i++)
        {
            if(main_sound.contains(i))
            {
                obj_sound_index &sound = main_sfx_index[static_cast<size_t>(i) - 1];
                obj_sound &snd = main_sound[i];
                sound.setPath(snd.absPath);

                if(sound.need_reload)
                {
#if  defined(__unix__) || defined(__APPLE__) || defined(_WIN32)
                    FileMapper fileMap;

                    if(fileMap.open_file(snd.absPath.c_str()))
                    {
                        sound.chunk = Mix_LoadWAV_RW(SDL_RWFromMem(fileMap.data(),
                                                     static_cast<int>(fileMap.size())),
                                                     static_cast<int>(fileMap.size()));
                        fileMap.close_file();
                    }

#else
                    sound.chunk = Mix_LoadWAV(snd.absPath.toUtf8().data());
#endif
                }

                if(!sound.chunk)
                    pLogWarning("Fail to load sound-%d: %s", i, Mix_GetError());
                else
                    need_to_reserve += (snd.channel >= 0 ? 1 : 0);

                sound.channel = snd.channel;
            }
        }
    }

    if(need_to_reserve > 0)
    {
        total_channels = (total_channels + need_to_reserve + 32);
        total_channels = Mix_AllocateChannels(total_channels);
    }

    //Final channel definition (use reserved channels at end of channels set)
    //int set_channel = (total_channels-1);
    //for(int i=0; i < main_sfx_index.size(); i++)
    //{
    //    obj_sound_index &sound = main_sfx_index[i];
    //    if(sound.channel>=0)
    //    {
    //        sound.channel = set_channel--;
    //    }
    //}

    if(need_to_reserve == total_channels)
        need_to_reserve = 0;

    //else
    //    need_to_reserve=set_channel;
#ifndef DEBUG_BUILD
    Mix_ReserveChannels(need_to_reserve)
#endif
#define RESERVE_CHANS_COMMAND Mix_ReserveChannels(need_to_reserve)
    D_pLogDebug("Loading of sounds passed in %d milliseconds", static_cast<int>(loadingTime.elapsed()));
    D_pLogDebug("Reserved audio channels: %d", RESERVE_CHANS_COMMAND);
    D_pLogDebug("SFX Index entries: %d", main_sfx_index.size());
#undef RESERVE_CHANS_COMMAND
    SDL_ClearError();
}