Exemple #1
0
void Media::init()
{
    ChowdrenAudio::open_audio();

    double start_time = platform_get_time();

    AssetFile fp;
    fp.open();

#ifdef CHOWDREN_IS_WIIU
    // experimental code to load faster
    unsigned int start = AssetFile::get_offset(0, AssetFile::SOUND_DATA);
    unsigned int size = AssetFile::get_size(AssetFile::SOUND_DATA);
    startup_data = new unsigned char[size];
    startup_size = size;
    fp.seek(start);
	fp.read(startup_data, size);

    for (int i = 0; i < SOUND_COUNT; i++) {
        add_cache(i);
    }

	delete[] startup_data;
#else
    for (int i = 0; i < SOUND_COUNT; i++) {
        fp.set_item(i, AssetFile::SOUND_DATA);
        add_cache(i, fp);
    }
#endif

    std::cout << "Sound bank took " << (platform_get_time() - start_time)
        << std::endl;
}
Exemple #2
0
void Image::load()
{
    flags |= USED;

    if (tex != 0 || image != NULL)
        return;

    if (flags & FILE) {
        ((FileImage*)this)->load_file();
        return;
    }

    unsigned int size, out_size;
    unsigned char * buf;
    int ret;
    if (startup_data) {
        unsigned int start = AssetFile::get_offset(0, AssetFile::IMAGE_DATA);
        unsigned int self = AssetFile::get_offset(handle,
                                                  AssetFile::IMAGE_DATA);
        unsigned int offset = self - start;
        ArrayStream stream((char*)startup_data, startup_size);
        stream.seek(offset);
        load_image_info(*this, stream, size, out_size);
        buf = &startup_data[stream.pos];
        ret = stbi_zlib_decode_buffer((char*)image, out_size,
                                      (const char*)buf, size);
    } else {
        open_image_file();
        image_file.set_item(handle, AssetFile::IMAGE_DATA);
        FileStream stream(image_file);
        load_image_info(*this, stream, size, out_size);
        buf = new unsigned char[size];
        image_file.read(buf, size);
        ret = stbi_zlib_decode_buffer((char*)image, out_size,
                                      (const char*)buf, size);
        delete[] buf;
    }

    if (ret < 0) {
        std::cout << "Could not load image " << handle << std::endl;
        std::cout << stbi_failure_reason() << std::endl;
        stbi_image_free(image);
        image = NULL;
    }
}