//! Seek Vorbis Data int VorbisSeek(void *datasource,ogg_int64_t offset,int whence) { IDataSource* Stream = (IDataSource*)datasource; switch (whence) { case SEEK_SET: Stream->seek(offset, false); break; case SEEK_CUR: Stream->seek(offset, true); break; case SEEK_END: Stream->seek(Stream->getSize()-offset, false); break; }; return 0; }
void SKFPlayer::run() { if (!playing || !buffer) return; // if doing something, continue if (curaction) { if (curaction == SKF_FadeOut || curaction == SKF_FadeWhite) { fadelevel++; if (fadelevel == FADESTEPS) curaction = 0; // done } else if (curaction == SKF_FadeIn) { fadelevel--; if (fadelevel == 0) curaction = 0; // done } else { pout << "Unknown fade action: " << curaction << std::endl; } } // CHECKME: this timing may not be accurate enough... uint32 now = SDL_GetTicks(); if (lastupdate + (1000/framerate) > now) return; lastupdate += (1000/framerate); // if waiting, continue to wait if (timer) { timer--; return; } Pentagram::Font* redfont; redfont = FontManager::get_instance()->getGameFont(6, true); MusicProcess* musicproc = MusicProcess::get_instance(); AudioProcess* audioproc = AudioProcess::get_instance(); // handle events for the current frame while (curevent < events.size() && events[curevent]->frame <= curframe) { // pout << "event " << curevent << std::endl; switch (events[curevent]->action) { case SKF_FadeOut: curaction = SKF_FadeOut; fadecolour = 0; fadelevel = 0; // pout << "FadeOut" << std::endl; break; case SKF_FadeIn: curaction = SKF_FadeIn; fadelevel = FADESTEPS; // pout << "FadeIn" << std::endl; break; case SKF_FadeWhite: curaction = SKF_FadeWhite; fadecolour = 0xFF; fadelevel = 0; // pout << "FadeWhite" << std::endl; break; case SKF_Wait: // pout << "Wait " << events[curevent]->data << std::endl; timer = events[curevent]->data; curevent++; return; case SKF_PlayMusic: // pout << "PlayMusic " << events[curevent]->data << std::endl; if (musicproc) musicproc->playMusic(events[curevent]->data); break; case SKF_SlowStopMusic: POUT ("SlowStopMusic"); if (musicproc && !introMusicHack) musicproc->playMusic(0); break; case SKF_PlaySFX: // pout << "PlaySFX " << events[curevent]->data << std::endl; if (audioproc) audioproc->playSFX(events[curevent]->data,0x60,0,0); break; case SKF_StopSFX: // pout << "StopSFX" << events[curevent]->data << std::endl; if (audioproc) audioproc->stopSFX(events[curevent]->data,0); break; case SKF_SetSpeed: POUT("SetSpeed " << events[curevent]->data); // framerate = events[curevent]->data; break; case SKF_PlaySound: { // pout << "PlaySound " << events[curevent]->data << std::endl; if (audioproc) { uint8* buffer = skf->get_object(events[curevent]->data); uint32 bufsize = skf->get_size(events[curevent]->data); Pentagram::AudioSample* s; uint32 rate = buffer[6] + (buffer[7]<<8); bool stereo = (buffer[8] == 2); s = new Pentagram::RawAudioSample(buffer+34, bufsize-34, rate, true, stereo); audioproc->playSample(s, 0x60, 0); // FIXME: memory leak! (sample is never deleted) } // subtitles char* textbuf = reinterpret_cast<char*>( skf->get_object(events[curevent]->data-1)); uint32 textsize = skf->get_size(events[curevent]->data-1); if (textsize > 7) { std::string subtitle = (textbuf+6); delete subs; subtitley = textbuf[4] + (textbuf[5]<<8); unsigned int remaining; subs = redfont->renderText(subtitle, remaining, 200, 0, Pentagram::Font::TEXT_CENTER); } delete textbuf; break; } case SKF_ClearSubs: // pout << "ClearSubs" << std::endl; delete subs; subs = 0; break; default: pout << "Unknown action" << std::endl; break; } curevent++; } curframe++; PaletteManager* palman = PaletteManager::get_instance(); IDataSource* object; uint16 objecttype = 0; do { curobject++; if (curobject >= skf->getCount()) { stop(); // done return; } // read object object = skf->get_datasource(curobject); if (!object || object->getSize() < 2) continue; objecttype = object->read2(); // pout << "Object " << curobject << "/" << skf->getCount() // << ", type = " << objecttype << std::endl; if (objecttype == 1) { palman->load(PaletteManager::Pal_Movie, *object); } if (objecttype != 2) delete object; } while (objecttype != 2); if (objecttype == 2) { object->seek(0); Shape* shape = new Shape(object, &U8SKFShapeFormat); Pentagram::Palette* pal= palman->getPalette(PaletteManager::Pal_Movie); shape->setPalette(pal); buffer->BeginPainting(); buffer->Paint(shape, 0, 0, 0); buffer->EndPainting(); delete shape; delete object; } timer = 1; // HACK! timing is rather broken currently... }
bool loadPalette(Pentagram::Palette * pal, const ConvertShapeFormat * format) { GimpRGB color; guchar palHack[2]; palHack[1] = 255; bool newPal; const gchar * palName; for (int i = 0; i < 256; ++i) { palHack[0] = i; pal->native[i] = *((uint16 * ) palHack); } if (format == &PentagramShapeFormat) { palName = "Pentagram"; } else if (format == &U8SKFShapeFormat) { palName = "U8SKF"; } else if (format == &U8ShapeFormat) { palName = "Ultima8"; } else if (format == &U82DShapeFormat) { palName = "Ultima8"; } else if (format == &CrusaderShapeFormat) { palName = "Crusader"; } else if (format == &Crusader2DShapeFormat) { palName = "Crusader"; } else { return false; } newPal = ! gimp_context_set_palette(palName); if (newPal) { gint colors = 0; if (gimp_palette_get_info(palName, &colors)) { newPal = false; if (colors != 256) { newPal = true; if (!gimp_palette_delete(palName)) return false; } } } if (newPal) { if (g_ascii_strcasecmp(palName, gimp_palette_new(palName))) return false; if (!gimp_context_set_palette(palName)) return false; IDataSource * ds = choosePalette(); if (ds) { gint j = 0; ds->seek(4); pal->load(*ds); delete ds; for (gint i = 0; i < 256; ++i) { gimp_rgb_set_uchar(&color, pal->palette[i * 3], pal->palette[i * 3 + 1], pal->palette[i * 3 + 2]); gimp_palette_add_entry(palName, "Untitled", &color, &j); assert (j == i); } } else { return false; } } else { for (gint i = 0; i < 256; ++i) { gimp_palette_entry_get_color(palName, i, &color); gimp_rgb_get_uchar(&color, &(pal->palette[i * 3]), &(pal->palette[i * 3 + 1]), &(pal->palette[i * 3 + 2])); } } return true; }