bool credit_init(int parameter) { credits = new Credits; if (credits->Init()) { staterr("Credits initilization failed"); return 1; } return 0; }
BigImage::~BigImage() { for(int i=0;i<MAX_BIGIMAGES;i++) { if (images[i]) { staterr("BigImage: freeing image %d", i); delete images[i]; images[i] = NULL; } } }
// create a bitmapped font with a drop-shadow. bool NXFont::InitBitmapCharsShadowed(SDL_Surface *sheet, uint32_t fgcolor, \ uint32_t color, uint32_t shadowcolor) { Uint32 format = screen->Format()->format; NXFont fgfont, shadowfont; SDL_Rect dstrect; // create temporary fonts in the fg and shadow color if (fgfont.InitBitmapChars(sheet, fgcolor, color)) return 1; if (shadowfont.InitBitmapChars(sheet, fgcolor, shadowcolor)) return 1; SDL_PixelFormat* pxformat = SDL_AllocFormat(format); if (!pxformat) { staterr("InitBitmapChars: SDL_AllocFormat failed: %s", SDL_GetError()); return 1; } // now combine the two fonts uint32_t transp = SDL_MapRGB(pxformat, 0, 0, 0); for(int i=0;i<NUM_FONT_LETTERS;i++) { if (fgfont.letters[i]) { letters[i] = SDL_CreateRGBSurface(0, \ BITMAP_CHAR_WIDTH+1, BITMAP_CHAR_HEIGHT+1+SHADOW_OFFSET, pxformat->BitsPerPixel, \ pxformat->Rmask, pxformat->Gmask, pxformat->Bmask, pxformat->Amask); SDL_FillRect(letters[i], NULL, transp); SDL_SetColorKey(letters[i], SDL_TRUE, transp); dstrect.x = 0; dstrect.y = SHADOW_OFFSET; SDL_BlitSurface(shadowfont.letters[i], NULL, letters[i], &dstrect); dstrect.x = 0; dstrect.y = 0; SDL_BlitSurface(fgfont.letters[i], NULL, letters[i], &dstrect); } } SDL_FreeFormat(pxformat); return 0; }
bool Game::createplayer() { if (player) { staterr("game.createplayer: player already exists!"); return 1; } player = (Player *)CreateObject(0, 0, OBJ_PLAYER); PInitFirstTime(); return 0; }
char SSInit(void) { SDL_AudioSpec fmt, obtained; // Set 16-bit stereo audio at 22Khz fmt.freq = SAMPLE_RATE; fmt.format = AUDIO_S16; fmt.channels = 2; fmt.samples = 512; fmt.callback = mixaudio; fmt.userdata = NULL; // Open the audio device and start playing sound! if (SDL_OpenAudio(&fmt, &obtained) < 0) { staterr("SS: Unable to open audio: %s", SDL_GetError()); return 1; } if (obtained.format != fmt.format || \ obtained.channels != fmt.channels) { staterr("SS: Failed to obtain the audio format I wanted"); return 1; } mixbuffer = (uint8_t *)malloc(obtained.samples * obtained.channels * 2); // zero everything in all channels memset(channel, 0, sizeof(channel)); for(int i=0;i<SS_NUM_CHANNELS;i++) channel[i].volume = SDL_MIX_MAXVOLUME; stat("sslib: initilization was successful."); lockcount = 0; SDL_PauseAudio(0); return 0; }
void BigImage::Set(int num) { if (images[num]) { imgno = num; imagex = -images[num]->Width(); state = BI_SLIDE_IN; } else { staterr("BigImage::Set: invalid image number %d", num); state = BI_CLEAR; } }
bool sound_init(void) { if (SSInit()) return 1; if (pxt_init()) return 1; if (pxt_LoadSoundFX(pxt_dir, sndcache, NUM_SOUNDS)) return 1; if (org_init(org_wavetable, pxt_dir, ORG_VOLUME)) { staterr("Music failed to initialize"); return 1; } return 0; }
void CFlashingCursor::erase(int cx, int cy) { int x, y, line_number; EditView *ev = editor.curev; visible = 0; if (cy < 0 || cy >= editor.height || !ev) return; //stat("erase[%d, %d]", cx, cy); x = GET_CURSOR_PX(cx); y = GET_CURSOR_PY(cy); // restore the image behind the cursor LockWindow(); line_number = (ev->scroll.y + cy); if (line_number >= ev->nlines) { MainView->SetLowColor(GetEditBGColor(COLOR_TEXT)); MainView->FillRect(BRect(x, y, x + (CURSOR_W - 1), y + (CURSOR_H - 1)), B_SOLID_LOW); } else { editor.curline_bb->Lock(); if (line_number != editor.bbed_line) { clLine *line = ev->GetLineHandle(line_number); if (line) { if (!line->lexresult.points) lexer_update_line(line); UpdateLine(ev, editor.curline_bb, line, 0, line_number); editor.bbed_line = line_number; } else { staterr("CFlashingCursor::erase: could not obtain line handle to update BB"); } } BRect source(x, 0, x + (CURSOR_W - 1), CURSOR_H-1); BRect dest(x, y, x + (CURSOR_W - 1), y + (CURSOR_H-1)); editor.curline_bb->BlitTo(view, source, dest); editor.curline_bb->Unlock(); } UnlockWindow(); }
void SIFSpritesSect::LoadPointList(SIFPointList *lst, const uint8_t **data, const uint8_t *data_end) { lst->count = read_U8(data, data_end); if (lst->count > SIF_MAX_BLOCK_POINTS) { staterr("SIFSpritesSect::LoadPointList: too many block points (%d, max=%d)", lst->count, SIF_MAX_BLOCK_POINTS); return; } for(int i=0;i<lst->count;i++) { lst->point[i].x = (int16_t)read_U16(data, data_end); lst->point[i].y = (int16_t)read_U16(data, data_end); } }
NXSurface* NXSurface::createScreen(int wd, int ht, Uint32 pixel_format) { if (GraphicHacks::Init(renderer)) { staterr("unable to init GraphicHacks"); return NULL; } NXSurface* s = new NXSurface(); s->tex_w = wd; s->tex_h = ht; s->setPixelFormat(pixel_format); return s; }
int SDL_main(int argc, char *argv[]) { stat("Entering main loop"); testblit(); if (SSInit()) return 1; if (pxt_init()) return 1; if (pxt_LoadSoundFX(pxt_dir, sndcache, 0x75)) { printf("Can't load\n"); return 1; } if (org_init(org_wavetable, pxt_dir, ORG_VOLUME)) { staterr("Music failed to initialize"); return 1; } music(19); while(!quitting) { org_run(); SDL_Event pie; if (SDL_PollEvent(&pie)) { if (pie.type == SDL_KEYDOWN) { if(pie.key.keysym.sym == SDLK_F3) quitting = true; else if(pie.key.keysym.sym == SDLK_BTN_A) pxt_Play(-1, 1, 1); else if(pie.key.keysym.sym == SDLK_BTN_B) org_stop(); else if(pie.key.keysym.sym == SDLK_BTN_Y) music(random(1,42)); } } } pxt_freeSoundFX(); SSClose(); return 0; }
static void fatal(const char *str) { staterr("fatal: '%s'", str); if (!safemode::init()) { safemode::moveto(SM_UPPER_THIRD); safemode::print("Fatal Error"); safemode::moveto(SM_CENTER); safemode::print("%s", str); safemode::run_until_key(); safemode::close(); } }
void FileBuffer::CheckFlush(int maxsize) { if (fBuffer.Length() >= maxsize) { if (fFP) { //stat("CheckFlush wrote %d bytes", fBuffer.Length()); fwrite(fBuffer.Data(), fBuffer.Length(), 1, fFP); fBuffer.Clear(); } else { staterr("CheckFlush: no file"); } } }
bool NXFont::InitTextures() { for (int i = 0; i < NUM_FONT_LETTERS; ++i) { if (!letters[i]) continue; tletters[i] = SDL_CreateTextureFromSurface(renderer, letters[i]); if (!tletters[i]) { staterr("NXFont::InitTextures() SDL_CreateTextureFromSurface failed: %s", SDL_GetError()); return true; } } return false; }
bool CredReader::OpenFile(void) { char fname[MAXPATHLEN]; if (data) CloseFile(); sprintf(fname, "%s/Credit.tsc", data_dir); data = tsc_decrypt(fname, &datalen); if (!data) { staterr("CredReader: couldn't open '%s'!", fname); return 1; } stat("CredReader: '%s' loaded ok!", fname); dataindex = 0; return 0; }
bool sound_init(void) { pxt_dir = "pxt/"; org_dir = "org/"; sndcache = "sndcache.pcm"; org_wavetable = "wavetable.dat"; if (SSInit()) return 1; if (pxt_init()) return 1; if (pxt_LoadSoundFX(pxt_dir, sndcache, NUM_SOUNDS)) return 1; if (org_init(org_wavetable, pxt_dir, ORG_VOLUME)) { staterr("Music failed to initialize"); return 1; } return 0; }
// returns the currently playing sample within the currently playing chunk // of channel c. If no chunk is playing, the results are undefined. // as with "len" parameter to SSEnqueueChunk, the count counts the two // components of a stereo sample as a single sample. int SSGetSamplePos(int c) { int result; SSLockAudio(); if (channel[c].head != channel[c].tail) { result = (channel[c].chunks[channel[c].head].bytepos / 4); } else { staterr("SSGetSamplePos: channel %d is not playing!", c); result = -1; } SSUnlockAudio(); return result; }
// returns the userdata member of the currently playing chunk on channel c. // if channel c is not playing, the results are undefined. int SSGetCurUserData(int c) { int result; SSLockAudio(); if (channel[c].head != channel[c].tail) { result = (channel[c].chunks[channel[c].head].userdata); } else { staterr("SSGetUserData: channel %d is not playing!\n", c); result = -1; } SSUnlockAudio(); return result; }
// allocate for an empty surface of the given size bool NXSurface::AllocNew(int wd, int ht, NXFormat* format) { Free(); stat("NXSurface::AllocNew this = %p", this); fTexture = SDL_CreateTexture(renderer, format->format, SDL_TEXTUREACCESS_TARGET, wd*SCALE, ht*SCALE); if (!fTexture) { staterr("NXSurface::AllocNew: failed to allocate texture: %s", SDL_GetError()); return true; } tex_w = wd*SCALE; tex_h = ht*SCALE; return false; }
// save the timestamp in value to 290.rec. bool niku_save(uint32_t value) { uint8_t buf_byte[20]; uint32_t *buf_dword = (uint32_t *)buf_byte; // place values buf_dword[0] = value; buf_dword[1] = value; buf_dword[2] = value; buf_dword[3] = value; // generate keys buf_byte[16] = random(0, 255); buf_byte[17] = random(0, 255); buf_byte[18] = random(0, 255); buf_byte[19] = random(0, 255); // encode each copy for(int i=0;i<4;i++) { uint8_t *ptr = (uint8_t *)&buf_dword[i]; uint8_t key = buf_byte[i+16]; ptr[0] += key; ptr[1] += key; ptr[2] += key; ptr[3] += key / 2; } const char *fname = getfname(); FILE *fp = fopen(fname, "wb"); if (!fp) { staterr("niku_save: failed to open '%s'", fname); return 1; } fwrite(buf_byte, 20, 1, fp); fclose(fp); stat("niku_save: wrote value 0x%08x", value); return 0; }
bool IrregularBBox::init(Object *associatedObject, int max_rectangles) { memset(&bbox, 0, sizeof(bbox)); this->num_bboxes = max_rectangles; this->assoc_object = associatedObject; if (num_bboxes >= IB_MAX_BBOXES) { num_bboxes = IB_MAX_BBOXES; staterr("IrregularBBox::Init(): too many rectangles (%d given): max is %d", max_rectangles, IB_MAX_BBOXES); return 1; } for(int i=0; i<num_bboxes; i++) { bbox[i] = CreateObject(0, 0, OBJ_BBOX_PUPPET); bbox[i]->sprite = SPR_BBOX_PUPPET_1 + i; bbox[i]->hp = 1000; bbox[i]->damage = 0; bbox[i]->invisible = true; } return 0; }
bool NXFont::InitChars(TTF_Font *font, uint32_t color) { SDL_Color fgcolor; SDL_Surface *letter; fgcolor.r = (uint8_t)(color >> 16); fgcolor.g = (uint8_t)(color >> 8); fgcolor.b = (uint8_t)(color); #ifdef _L10N_CP1251 char utf8_str[2]; #endif char str[2]; str[1] = 0; for(int i=1;i<NUM_LETTERS_RENDERED;i++) { str[0] = i; #ifndef _L10N_CP1251 letter = TTF_RenderUTF8_Solid(font, str, fgcolor); #else win1251_to_utf8(str, utf8_str); letter = TTF_RenderUTF8_Solid(font, utf8_str, fgcolor); #endif if (!letter) { staterr("InitChars: failed to render character %d: %s", i, TTF_GetError()); return 1; } letters[i] = SDL_DisplayFormat(letter); SDL_FreeSurface(letter); } return 0; }
// given a paletted surface add it's colors in to the screen colormap // then return a surface with the color indexes remapped ready to // be displayed on the screen. insfc is either freed, or reused to // create the returned surface. SDL_Surface *palette_add(SDL_Surface *sfc) { SDL_Palette *pal = sfc->format->palette; int remap[MAX_COLORS]; int x, y, i; if (sfc->format->BitsPerPixel > 8) { staterr("palette_add: input surface is > 8bpp"); return NULL; } stat("palette_add: adding %d colors to screen palette...", pal->ncolors); for(i=0; i<pal->ncolors; i++) { remap[i] = palette_alloc(pal->colors[i].r, pal->colors[i].g, pal->colors[i].b); if (remap[i] == -1) return sfc; } SDL_SetColors(screen->GetSDLSurface(), screenpal, 0, ncolors); return sfc; /* // remap indexes in surface for(y=0;y<sfc->h;y++) { uint8_t *pixels = (uint8_t *)sfc->pixels + (y * sfc->pitch); for(x=0;x<sfc->w;x++) { *pixels = remap[*pixels]; pixels++; } } return sfc;*/ }
void NXSurface::DrawBatchAdd(NXSurface *src, int dstx, int dsty, int srcx, int srcy, int wd, int ht) { assert(renderer); assert(src->fTexture); SDL_Rect srcrect, dstrect; srcrect.x = srcx * SCALE; srcrect.y = srcy * SCALE; srcrect.w = wd * SCALE; srcrect.h = ht * SCALE; dstrect.x = dstx * SCALE; dstrect.y = dsty * SCALE; dstrect.w = srcrect.w; dstrect.h = srcrect.h; if (need_clip) clip(srcrect, dstrect); if (GraphicHacks::BatchAddCopy(renderer, src->fTexture, &srcrect, &dstrect)) { staterr("NXSurface::DrawBatchAdd: GraphicHacks::BatchAddCopy failed"); } }
int main(int argc, char *argv[]) { bool inhibit_loadfade = false; bool error = false; bool freshstart; SetLogFilename("debug.txt"); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { staterr("ack, sdl_init failed: %s.", SDL_GetError()); return 1; } atexit(SDL_Quit); // start up inputs first thing because settings_load may remap them input_init(); // load settings, or at least get the defaults, // so we know the initial screen resolution. settings_load(); if (Graphics::init(settings->resolution)) { staterr("Failed to initialize graphics."); return 1; } if (font_init()) { staterr("Failed to load font."); return 1; } //speed_test(); //return 1; #ifdef CONFIG_DATA_EXTRACTOR if (!settings->files_extracted) { if (extract_main()) { Graphics::close(); font_close(); return 0; } else { settings->files_extracted = true; settings_save(); } } #endif if (check_data_exists()) { return 1; } Graphics::ShowLoadingScreen(); if (sound_init()) { fatal("Failed to initialize sound."); return 1; } if (trig_init()) { fatal("Failed trig module init."); return 1; } if (tsc_init()) { fatal("Failed to initialize script engine."); return 1; } if (textbox.Init()) { fatal("Failed to initialize textboxes."); return 1; } if (Carets::init()) { fatal("Failed to initialize carets."); return 1; } if (game.init()) return 1; game.setmode(GM_NORMAL); // set null stage just to have something to do while we go to intro game.switchstage.mapno = 0; //#define REPLAY #ifdef REPLAY game.switchstage.mapno = START_REPLAY; //Replay::set_ffwd(6000); //Replay::set_stopat(3500); game.switchstage.param = 1; #else //game.switchstage.mapno = LOAD_GAME; //game.pause(GP_OPTIONS); if (settings->skip_intro && file_exists(GetProfileName(settings->last_save_slot))) game.switchstage.mapno = LOAD_GAME; else game.setmode(GM_INTRO); #endif // for debug if (game.paused) { game.switchstage.mapno = 0; game.switchstage.eventonentry = 0; } if (game.switchstage.mapno == LOAD_GAME) inhibit_loadfade = true; game.running = true; freshstart = true; stat("Entering main loop..."); #ifdef __SDLSHIM__ set_console_visible(false); #endif //speed_test(); //return 1; while(game.running) { // SSS/SPS persists across stage transitions until explicitly // stopped, or you die & reload. It seems a bit risky to me, // but that's the spec. if (game.switchstage.mapno >= MAPNO_SPECIALS) { StopLoopSounds(); } // enter next stage, whatever it may be if (game.switchstage.mapno == LOAD_GAME || \ game.switchstage.mapno == LOAD_GAME_FROM_MENU) { if (game.switchstage.mapno == LOAD_GAME_FROM_MENU) freshstart = true; stat("= Loading game ="); if (game_load(settings->last_save_slot)) { fatal("savefile error"); goto ingame_error; } Replay::OnGameStarting(); if (!inhibit_loadfade) fade.Start(FADE_IN, FADE_CENTER); else inhibit_loadfade = false; } else if (game.switchstage.mapno == START_REPLAY) { stat(">> beginning replay '%s'", GetReplayName(game.switchstage.param)); StopScripts(); if (Replay::begin_playback(GetReplayName(game.switchstage.param))) { fatal("error starting playback"); goto ingame_error; } } else { if (game.switchstage.mapno == NEW_GAME || \ game.switchstage.mapno == NEW_GAME_FROM_MENU) { bool show_intro = (game.switchstage.mapno == NEW_GAME_FROM_MENU); InitNewGame(show_intro); } // slide weapon bar on first intro to Start Point if (game.switchstage.mapno == STAGE_START_POINT && \ game.switchstage.eventonentry == 91) { freshstart = true; } // switch maps if (load_stage(game.switchstage.mapno)) goto ingame_error; player->x = (game.switchstage.playerx * TILE_W) << CSF; player->y = (game.switchstage.playery * TILE_H) << CSF; } // start the level if (game.initlevel()) return 1; if (freshstart) weapon_introslide(); gameloop(); game.stageboss.OnMapExit(); freshstart = false; } shutdown: ; Replay::close(); game.close(); Carets::close(); Graphics::close(); input_close(); font_close(); sound_close(); tsc_close(); textbox.Deinit(); return error; ingame_error: ; stat(""); stat(" ************************************************"); stat(" * An in-game error occurred. Game shutting down."); stat(" ************************************************"); error = true; goto shutdown; }
bool pmd_load(const char *fname) { FILE *fp; int i, t; stat("----------------------"); stat("pmd_load: opening '%s'", fname); fp = fopen(fname, "rb"); if (!fp) { staterr("pmd_load: failed to open '%s'", fname); return 1; } if (!fverifystring(fp, "PMD")) { staterr("pmd_load: not a PMD file: '%s'", fname); fclose(fp); return 1; } fgetc(fp); // I dunno fgetl(fp); // I dunno song.ms_per_beat = fgetl(fp); // music wait song.loop_start = fgetl(fp); song.loop_end = fgetl(fp); song.nnotes = fgetl(fp); stat("song wait: %d (0x%04x)", song.ms_per_beat, song.ms_per_beat); stat("nnotes: %d (0x%04x)", song.nnotes, song.nnotes); stat("loop: %d-%d", song.loop_start, song.loop_end); // original PiyoPiyo and Ikachan seem to play things slightly slower than specified, // although PiyoPiyoPlayer plays it as spec'd in the file. if (strstr(fname, "Buriki")) song.ms_per_beat += 10; else song.ms_per_beat += 5; // load instrument samples for(i=0;i<NUM_TRACKS;i++) load_instrument(fp, &song.track[i].instrument); for(i=0;i<TOTAL_TRACKS;i++) song.track[i].no = i; // drum volume song.drum_volume = fgetl(fp); // load music notes for(t=0;t<TOTAL_TRACKS;t++) { stTrack *track = &song.track[t]; for(i=0;i<song.nnotes;i++) { uint32_t mask = fgetl(fp); track->note[i].notemask = (mask & 0xffffff); track->note[i].panning = (mask >> 24); if (!track->note[i].panning) track->note[i].panning = PAN_CENTER; else track->note[i].panning--; } } return 0; }
// load savefile #num into the given Profile structure. bool profile_load(const char *pfname, Profile *file) { int i, curweaponslot; VMFILE *fp; stat("Loading profile from %s...", pfname); memset(file, 0, sizeof(Profile)); fp = vm_fileopen(pfname, "rb"); if (!fp) { staterr("profile_load: unable to open '%s'", pfname); return 1; } if (!vm_fverifystring(fp, "Do041220")) { staterr("profile_load: invalid savegame format: '%s'", pfname); vm_fclose(fp); return 1; } file->stage = vm_fgetl(fp); file->songno = vm_fgetl(fp); file->px = vm_fgetl(fp); file->py = vm_fgetl(fp); file->pdir = CVTDir(vm_fgetl(fp)); file->maxhp = vm_fgeti(fp); file->num_whimstars = vm_fgeti(fp); file->hp = vm_fgeti(fp); vm_fgeti(fp); // unknown value curweaponslot = vm_fgetl(fp); // current weapon (slot, not number, converted below) vm_fgetl(fp); // unknown value file->equipmask = vm_fgetl(fp); // equipped items // load weapons vm_fseek(fp, PF_WEAPONS_OFFS, SEEK_SET); for(i=0;i<MAX_WPN_SLOTS;i++) { int type = vm_fgetl(fp); if (!type) break; int level = vm_fgetl(fp); int xp = vm_fgetl(fp); int maxammo = vm_fgetl(fp); int ammo = vm_fgetl(fp); file->weapons[type].hasWeapon = true; file->weapons[type].level = (level - 1); file->weapons[type].xp = xp; file->weapons[type].ammo = ammo; file->weapons[type].maxammo = maxammo; if (i == curweaponslot) { file->curWeapon = type; } } // load inventory file->ninventory = 0; vm_fseek(fp, PF_INVENTORY_OFFS, SEEK_SET); for(i=0;i<MAX_INVENTORY;i++) { int item = vm_fgetl(fp); if (!item) break; file->inventory[file->ninventory++] = item; } // load teleporter slots file->num_teleslots = 0; vm_fseek(fp, PF_TELEPORTER_OFFS, SEEK_SET); for(i=0;i<NUM_TELEPORTER_SLOTS;i++) { int slotno = vm_fgetl(fp); int scriptno = vm_fgetl(fp); if (slotno == 0) break; file->teleslots[file->num_teleslots].slotno = slotno; file->teleslots[file->num_teleslots].scriptno = scriptno; file->num_teleslots++; } // load flags vm_fseek(fp, PF_FLAGS_OFFS, SEEK_SET); if (!vm_fverifystring(fp, "FLAG")) { staterr("profile_load: missing 'FLAG' marker"); vm_fclose(fp); return 1; } vm_fresetboolean(); for(i=0;i<NUM_GAMEFLAGS;i++) { file->flags[i] = vm_fbooleanread(fp); } vm_fclose(fp); return 0; }
bool profile_save(const char *pfname, Profile *file) { VMFILE *fp; int i; //stat("Writing saved game to %s...", pfname); fp = vm_fileopen(pfname, "wb"); if (!fp) { staterr("profile_save: unable to open %s", pfname); return 1; } vm_fputstringnonull("Do041220", fp); vm_fputl(file->stage, fp); vm_fputl(file->songno, fp); vm_fputl(file->px, fp); vm_fputl(file->py, fp); vm_fputl((file->pdir == RIGHT) ? 2:0, fp); vm_fputi(file->maxhp, fp); vm_fputi(file->num_whimstars, fp); vm_fputi(file->hp, fp); vm_fseek(fp, 0x2C, SEEK_SET); vm_fputi(file->equipmask, fp); // save weapons vm_fseek(fp, PF_WEAPONS_OFFS, SEEK_SET); int slotno = 0, curweaponslot = 0; for(i=0;i<WPN_COUNT;i++) { if (file->weapons[i].hasWeapon) { vm_fputl(i, fp); vm_fputl(file->weapons[i].level + 1, fp); vm_fputl(file->weapons[i].xp, fp); vm_fputl(file->weapons[i].maxammo, fp); vm_fputl(file->weapons[i].ammo, fp); if (i == file->curWeapon) curweaponslot = slotno; slotno++; if (slotno >= MAX_WPN_SLOTS) break; } } if (slotno < MAX_WPN_SLOTS) vm_fputl(0, fp); // 0-type weapon: terminator // go back and save slot no of current weapon vm_fseek(fp, PF_CURWEAPON_OFFS, SEEK_SET); vm_fputl(curweaponslot, fp); // save inventory vm_fseek(fp, PF_INVENTORY_OFFS, SEEK_SET); for(i=0;i<file->ninventory;i++) { vm_fputl(file->inventory[i], fp); } vm_fputl(0, fp); // write teleporter slots vm_fseek(fp, PF_TELEPORTER_OFFS, SEEK_SET); for(i=0;i<MAX_TELE_SLOTS;i++) { if (i < file->num_teleslots) { vm_fputl(file->teleslots[i].slotno, fp); vm_fputl(file->teleslots[i].scriptno, fp); } else { vm_fputl(0, fp); vm_fputl(0, fp); } } // write flags vm_fseek(fp, PF_FLAGS_OFFS, SEEK_SET); vm_fputstringnonull("FLAG", fp); vm_fresetboolean(); for(i=0;i<NUM_GAMEFLAGS;i++) { vm_fbooleanwrite(file->flags[i], fp); } vm_fbooleanflush(fp); vm_fclose(fp); return 0; }
// load the surface from a .pbm or bitmap file bool NXSurface::LoadImage(const char *pbm_name, bool use_colorkey, int use_display_format) { stat("NXSurface::LoadImage name = %s, this = %p", pbm_name, this); Free(); // if (use_display_format == -1) // { // use value specified in settings // use_display_format = settings->displayformat; // } SDL_RWops* rwops = fileopen_SDL_RWops_RO(pbm_name); if (!rwops) { staterr("NXSurface::LoadImage: load failed of '%s'! %s", pbm_name, SDL_GetError()); return 1; } SDL_Surface *image = SDL_LoadBMP_RW(rwops, 1); if (!image) { staterr("NXSurface::LoadImage: load failed of '%s'! %s", pbm_name, SDL_GetError()); return 1; } if (use_colorkey) { SDL_SetColorKey(image, SDL_TRUE, SDL_MapRGB(image->format, 0, 0, 0)); } SDL_Texture * tmptex = SDL_CreateTextureFromSurface(renderer, image); if (!tmptex) { staterr("NXSurface::LoadImage: SDL_CreateTextureFromSurface failed: %s", SDL_GetError()); SDL_FreeSurface(image); return 1; } SDL_FreeSurface(image); { int wd, ht, access; Uint32 format; NXFormat nxformat; if (SDL_QueryTexture(tmptex, &format, &access, &wd, &ht)) goto error; nxformat.format = format; if (AllocNew(wd, ht, &nxformat)) goto error; if (SDL_SetTextureBlendMode(tmptex, SDL_BLENDMODE_NONE)) goto error; if (SDL_SetRenderTarget(renderer, fTexture)) goto error; if (SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255)) goto error; if (SDL_RenderClear(renderer)) goto error; if (SDL_RenderCopy(renderer, tmptex, NULL, NULL)) goto error; if (SDL_SetRenderTarget(renderer, NULL)) goto error; if (SDL_SetTextureBlendMode(fTexture, SDL_BLENDMODE_BLEND)) goto error; SDL_DestroyTexture(tmptex); goto done; error: { staterr("NXSurface::LoadImage failed: %s", SDL_GetError()); if (tmptex) { SDL_DestroyTexture(tmptex); tmptex = NULL; } if (fTexture){ SDL_DestroyTexture(fTexture); fTexture = NULL; } SDL_SetRenderTarget(renderer, NULL); } done: ; } stat("NXSurface::LoadImage name = %s, this = %p done", pbm_name, this); return (fTexture == NULL); }
bool font_init(void) { bool error = false; // we'll be bypassing the NXSurface automatic scaling features // and drawing at the real resolution so we can get better-looking fonts. // sdl_screen = screen->GetSDLSurface(); // at 320x240 switch to bitmap fonts for better appearance #ifdef CONFIG_ENABLE_TTF if (SCALE == 1) #endif { stat("fonts: using bitmapped from %s", bmpfontfile); SDL_RWops* rwops = fileopen_SDL_RWops_RO(bmpfontfile); if (!rwops) { staterr("Couldn't open bitmap font file %s: SDL_RWFromFP: %s", bmpfontfile, SDL_GetError()); return 1; } SDL_Surface *sheet = SDL_LoadBMP_RW(rwops, 1); if (!sheet) { staterr("Couldn't open bitmap font file: SDL_LoadBMP_RW: %s", SDL_GetError()); return 1; } uint32_t fgindex = SDL_MapRGB(sheet->format, 255, 255, 255); error = error || whitefont.InitBitmapChars(sheet, fgindex, 0xffffff); error = error || greenfont.InitBitmapChars(sheet, fgindex, 0x00ff80); error = error || bluefont.InitBitmapChars(sheet, fgindex, 0xa0b5de); error = error || shadowfont.InitBitmapCharsShadowed(sheet, fgindex, 0xffffff, 0x000000); } #ifdef CONFIG_ENABLE_TTF else { // It will get size 8, 17, 26, 35, ... // Hope ot will look nice on higher resolutions int pointsize = 8 + 9 * (SCALE - 1); stat("fonts: using truetype at %dpt", pointsize); // initilize normal TTF fonts if (TTF_Init() < 0) { staterr("Couldn't initialize SDL_ttf: %s", TTF_GetError()); return 1; } TTF_Font *font = TTF_OpenFontRW(SDL_RWFromFP(fileopenRO(ttffontfile), SDL_TRUE), 1, pointsize); if (!font) { staterr("Couldn't open font: '%s'", ttffontfile); return 1; } error = error || whitefont.InitChars(font, 0xffffff); error = error || greenfont.InitChars(font, 0x00ff80); error = error || bluefont.InitChars(font, 0xa0b5de); error = error || shadowfont.InitCharsShadowed(font, 0xffffff, 0x000000); TTF_CloseFont(font); } #endif error = error || whitefont.InitTextures(); error = error || greenfont.InitTextures(); error = error || bluefont.InitTextures(); error = error || shadowfont.InitTextures(); error = error || create_shade_sfc(); if (error) return 1; fontheight = (whitefont.letters['M']->h / SCALE); initilized = true; return 0; }