Image *SDLHardwareRenderDevice::loadImage(std::string filename, std::string errormessage, bool IfNotFoundExit) { // lookup image in cache Image *img; img = cacheLookup(filename); if (img != NULL) return img; // load image SDLHardwareImage *image = new SDLHardwareImage(this, renderer); if (!image) return NULL; image->surface = IMG_LoadTexture(renderer, mods->locate(filename).c_str()); if(image->surface == NULL) { delete image; if (!errormessage.empty()) logError("SDLHardwareRenderDevice: [%s] %s: %s", filename.c_str(), errormessage.c_str(), IMG_GetError()); if (IfNotFoundExit) { Exit(1); } return NULL; } // store image to cache cacheStore(filename, image); return image; }
Image *SDLHardwareRenderDevice::loadImage(const std::string& filename, int error_type) { // lookup image in cache Image *img; img = cacheLookup(filename); if (img != NULL) return img; // load image SDLHardwareImage *image = new SDLHardwareImage(this, renderer); if (!image) return NULL; image->surface = IMG_LoadTexture(renderer, mods->locate(filename).c_str()); if(image->surface == NULL) { delete image; if (error_type != ERROR_NONE) Utils::logError("SDLHardwareRenderDevice: Couldn't load image: '%s'. %s", filename.c_str(), IMG_GetError()); if (error_type == ERROR_EXIT) { Utils::logErrorDialog("SDLHardwareRenderDevice: Couldn't load image: '%s'.\n%s", filename.c_str(), IMG_GetError()); mods->resetModConfig(); Utils::Exit(1); } return NULL; } // store image to cache cacheStore(filename, image); return image; }
void RenderEngine::loadImage(Image* image, const std::string& filename) { if (!image) return; SDL_Texture* texture = NULL; // check texture cache first texture = cacheLookup(filename); if (texture) { image->filename = filename; image->texture = texture; image->init(this); return; } // load the texture from disk and cache it texture = IMG_LoadTexture(renderer, filename.c_str()); if (texture) { image->filename = filename; image->texture = texture; cacheStore(image); // logInfo("Loaded image: %s\n", filename.c_str()); } image->init(this); if (image->filename == "") logError("RenderEngine: Could not load image: '%s'\n", filename.c_str()); }
static void cacheUpdateStore(Cache * cache, storeSwapLogData * s, int update_digest) { switch (s->op) { case SWAP_LOG_ADD: cacheStore(cache, s, update_digest); break; case SWAP_LOG_DEL: cachePurge(cache, s, update_digest); break; default: assert(0); } }
int main(int argc, char *argv[]) { FileIterator **fis = NULL; const int fi_count = argc - 1; int active_fi_count = 0; time_t ready_time; Cache *them, *us; int i; if (argc < 3) return usage(argv[0]); them = cacheCreate("them"); us = cacheCreate("us"); them->peer = us; us->peer = them; fis = xcalloc(fi_count, sizeof(FileIterator *)); /* init iterators with files */ fis[0] = fileIteratorCreate(argv[1], accessLogReader); for (i = 2; i < argc; ++i) fis[i - 1] = fileIteratorCreate(argv[i], swapStateReader); /* check that all files were found */ for (i = 0; i < fi_count; ++i) if (!fis[i]) return -2; /* read prefix to get start-up contents of the peer cache */ ready_time = -1; for (i = 1; i < fi_count; ++i) { FileIterator *fi = fis[i]; while (fi->inner_time > 0) { if (((storeSwapLogData *) fi->entry)->op == SWAP_LOG_DEL) { cachePurge(them, fi->entry, 0); if (ready_time < 0) ready_time = fi->inner_time; } else { if (ready_time > 0 && fi->inner_time > ready_time) break; cacheStore(them, fi->entry, 0); } fileIteratorAdvance(fi); } } /* digest peer cache content */ cacheResetDigest(them); us->digest = cacheDigestClone(them->digest); /* @netw@ */ /* shift the time in access log to match ready_time */ fileIteratorSetCurTime(fis[0], ready_time); /* iterate, use the iterator with the smallest positive inner_time */ cur_time = -1; do { int next_i = -1; time_t next_time = -1; active_fi_count = 0; for (i = 0; i < fi_count; ++i) { if (fis[i]->inner_time >= 0) { if (!active_fi_count || fis[i]->inner_time < next_time) { next_i = i; next_time = fis[i]->inner_time; } active_fi_count++; } } if (next_i >= 0) { cur_time = next_time; /*fprintf(stderr, "%2d time: %d %s", next_i, (int)cur_time, ctime(&cur_time)); */ if (next_i == 0) cacheFetch(us, fis[next_i]->entry); else cacheUpdateStore(them, fis[next_i]->entry, 1); fileIteratorAdvance(fis[next_i]); } } while (active_fi_count); /* report */ cacheReport(them); cacheReport(us); cacheQueryReport(us, &us->qstats); /* clean */ for (i = 0; i < argc - 1; ++i) { fileIteratorDestroy(fis[i]); } xfree(fis); cacheDestroy(them); cacheDestroy(us); return 0; }