本文整理汇总了C++中MemChunk类的典型用法代码示例。如果您正苦于以下问题:C++ MemChunk类的具体用法?C++ MemChunk怎么用?C++ MemChunk使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MemChunk类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wxLogMessage
/* TextureXPanel::exportAsPNG
* Converts [texture] to a PNG image (if possible) and saves the PNG
* data to a file [filename]. Does not alter the texture data itself
*******************************************************************/
bool TextureXPanel::exportAsPNG(CTexture* texture, string filename, bool force_rgba)
{
// Check entry was given
if (!texture)
return false;
// Create image from entry
SImage image;
if (!texture->toImage(image, NULL, texture_editor->getPalette(), force_rgba))
{
wxLogMessage("Error converting %s: %s", texture->getName(), Global::error);
return false;
}
// Write png data
MemChunk png;
SIFormat* fmt_png = SIFormat::getFormat("png");
if (!fmt_png->saveImage(image, png, texture_editor->getPalette()))
{
wxLogMessage("Error converting %s", texture->getName());
return false;
}
// Export file
return png.exportFile(filename);
}
示例2: isChasmBinArchive
/* ChasmBinArchive::isChasmBinArchive
* Checks if the given data is a valid Chasm bin archive
*******************************************************************/
bool ChasmBinArchive::isChasmBinArchive(MemChunk& mc)
{
// Check given data is valid
if (mc.getSize() < HEADER_SIZE)
{
return false;
}
// Read bin header and check it
char magic[4] = {};
mc.read(magic, sizeof magic);
if ( magic[0] != 'C'
|| magic[1] != 'S'
|| magic[2] != 'i'
|| magic[3] != 'd')
{
return false;
}
uint16_t num_entries = 0;
mc.read(&num_entries, sizeof num_entries);
num_entries = wxUINT16_SWAP_ON_BE(num_entries);
return num_entries > MAX_ENTRY_COUNT
|| (HEADER_SIZE + ENTRY_SIZE * MAX_ENTRY_COUNT) <= mc.getSize();
}
示例3: onAnnouncement
// -----------------------------------------------------------------------------
// Handles announcements from any announcers listened to
// -----------------------------------------------------------------------------
void MapTextureManager::onAnnouncement(Announcer* announcer, std::string_view event_name, MemChunk& event_data)
{
// Only interested in the resource manager,
// archive manager and palette chooser.
if (announcer != &App::resources() && announcer != theMainWindow->paletteChooser()
&& announcer != &App::archiveManager())
return;
// If the map's archive is being closed,
// we need to close the map editor
if (event_name == "archive_closing")
{
event_data.seek(0, SEEK_SET);
int32_t ac_index;
event_data.read(&ac_index, 4);
if (App::archiveManager().getArchive(ac_index) == archive_)
{
MapEditor::windowWx()->Hide();
MapEditor::editContext().clearMap();
archive_ = nullptr;
}
}
// If the resources have been updated
if (event_name == "resources_updated")
refreshResources();
if (event_name == "main_palette_changed")
refreshResources();
}
示例4: saveEntry
/* AnimatedEntryPanel::saveEntry
* Saves any changes made to the entry
*******************************************************************/
bool AnimatedEntryPanel::saveEntry()
{
MemChunk mc;
mc.seek(0, SEEK_SET);
animated_t anim;
for (uint32_t a = 0; a < animated.nEntries(); a++)
{
AnimatedEntry* ent = animated.getEntry(a);
for (size_t i = 0; i < 9; ++i)
{
if (ent->getFirst().length() > i)
anim.first[i] = ent->getFirst()[i];
else anim.first[i] = 0;
if (ent->getLast().length() > i)
anim.last[i] = ent->getLast()[i];
else anim.last[i] = 0;
}
anim.speed = ent->getSpeed();
anim.type = ent->getType();
if (ent->getDecals()) anim.type |= ANIM_DECALS;
mc.write(&anim, 23);
}
anim.type = 255;
mc.write(&anim, 1);
bool success = entry->importMemChunk(mc);
if (success)
{
for (uint32_t a = 0; a < animated.nEntries(); a++)
list_entries->setItemStatus(a, LV_STATUS_NORMAL);
}
return success;
}
示例5: getIndexedData
/* SImage::getIndexedData
* Loads the image as index data into <mc>. Returns false if image is
* invalid, true otherwise
*******************************************************************/
bool SImage::getIndexedData(MemChunk& mc)
{
// Check the image is valid
if (!isValid())
return false;
// Init rgb data
mc.reSize(width * height, false);
// Cannot do this for trucolor graphics.
if (type == RGBA)
return false;
else if (type == PALMASK)
{
mc.write(data, width * height);
return true;
}
else if (type == ALPHAMAP)
{
mc.write(data, width * height);
return true;
}
return false; // Invalid image type
}
示例6: renameDir
// -----------------------------------------------------------------------------
// Renames [dir] to [new_name].
// Returns false if [dir] isn't part of the archive, true otherwise
// -----------------------------------------------------------------------------
bool Archive::renameDir(ArchiveTreeNode* dir, string_view new_name)
{
// Abort if read only
if (read_only_)
return false;
// Check the directory is part of this archive
if (!dir || dir->archive() != this)
return false;
// Rename the directory if needed
if (dir->name() == new_name)
{
if (UndoRedo::currentlyRecording())
UndoRedo::currentManager()->recordUndoStep(std::make_unique<DirRenameUS>(dir, new_name));
dir->setName(new_name);
dir->dirEntry()->setState(ArchiveEntry::State::Modified);
}
else
return true;
// Announce
MemChunk mc;
wxUIntPtr ptr = wxPtrToUInt(dir);
mc.write(&ptr, sizeof(wxUIntPtr));
announce("directory_modified", mc);
// Update variables etc
setModified(true);
return true;
}
示例7: openMod
/* AudioEntryPanel::openMod
* Opens a Module file for playback
*******************************************************************/
bool AudioEntryPanel::openMod(MemChunk& data)
{
// Attempt to load the mod
if (mod->loadFromMemory(data.getData(), data.getSize()))
{
audio_type = AUTYPE_MOD;
// Enable playback controls
slider_volume->Enable();
btn_play->Enable();
btn_pause->Enable();
btn_stop->Enable();
setAudioDuration(mod->getDuration().asMilliseconds());
return true;
}
else
{
// Disable playback controls
slider_volume->Enable();
btn_play->Enable();
btn_pause->Enable();
btn_stop->Enable();
setAudioDuration(0);
return false;
}
return false;
}
示例8: onAnnouncement
void MapTextureManager::onAnnouncement(Announcer* announcer, string event_name, MemChunk& event_data)
{
// Only interested in the resource manager,
// archive manager and palette chooser.
if (announcer != theResourceManager
&& announcer != thePaletteChooser
&& announcer != theArchiveManager)
return;
// If the map's archive is being closed,
// we need to close the map editor
if (event_name == "archive_closing")
{
event_data.seek(0, SEEK_SET);
int32_t ac_index;
event_data.read(&ac_index, 4);
if (theArchiveManager->getArchive(ac_index) == archive)
{
theMapEditor->Hide();
theMapEditor->mapEditor().clearMap();
archive = NULL;
}
}
// If the resources have been updated
if (event_name == "resources_updated")
refreshResources();
if (event_name == "main_palette_changed")
refreshResources();
}
示例9: wxMkdir
/* PaletteManager::loadCustomPalettes
* Loads any files in the '<userdir>/palettes' directory as palettes,
* with names from the files (minus the file extension)
*******************************************************************/
bool PaletteManager::loadCustomPalettes()
{
// If the directory doesn't exist create it
if (!wxDirExists(appPath("palettes", DIR_USER)))
wxMkdir(appPath("palettes", DIR_USER));
// Open the custom palettes directory
wxDir res_dir;
res_dir.Open(appPath("palettes", DIR_USER));
// Go through each file in the directory
string filename = wxEmptyString;
bool files = res_dir.GetFirst(&filename, wxEmptyString, wxDIR_FILES);
while (files)
{
// Load palette data
Palette8bit* pal = new Palette8bit();
MemChunk mc;
mc.importFile(res_dir.GetName() + "/" + filename);
pal->loadMem(mc);
// Add the palette
wxFileName fn(filename);
addPalette(pal, fn.GetName());
// Next file
files = res_dir.GetNext(&filename);
}
return true;
}
示例10: archiveIndex
// -----------------------------------------------------------------------------
// Called when an announcement is recieved from one of the archives in the list
// -----------------------------------------------------------------------------
void ArchiveManager::onAnnouncement(Announcer* announcer, const string& event_name, MemChunk& event_data)
{
// Reset event data for reading
event_data.seek(0, SEEK_SET);
// Check that the announcement came from an archive in the list
int32_t index = archiveIndex((Archive*)announcer);
if (index >= 0)
{
// If the archive was saved
if (event_name == "saved")
{
MemChunk mc;
mc.write(&index, 4);
announce("archive_saved", mc);
}
// If the archive was modified
if (event_name == "modified" || event_name == "entry_modified")
{
MemChunk mc;
mc.write(&index, 4);
announce("archive_modified", mc);
}
}
}
示例11:
void * FixedAllocator::Allocate()
{
if (!last_alloc_ || last_alloc_->blocks_available_ == 0)
{
// no memory available in the cached chunk, try to find one.
Chunks::iterator e = chunks_.end();
Chunks::iterator i = chunks_.begin();
for (; i!=e; ++i)
{
if (i->blocks_available_ > 0)
{
// found a chunk!
last_alloc_ = &*i;
break;
}
}
if (i == e)
{
// no chunks have blocks available, add a new one.
chunks_.reserve(chunks_.size()+1);
MemChunk chunk;
chunk.Init(block_size_, blocks_);
chunks_.push_back(chunk);
last_alloc_ = &chunks_.back();
last_dealloc_ = &chunks_.back();
}
}
// chunk pointer vaild check
assert(last_alloc_ != NULL);
assert(last_alloc_->blocks_available_ > 0);
return last_alloc_->Allocate(block_size_);
}
示例12: materialize
void MaterializedArray::materialize(const shared_ptr<Query>& query,
MemChunk& materializedChunk,
ConstChunk const& chunk,
MaterializeFormat format)
{
nMaterializedChunks += 1;
materializedChunk.initialize(chunk);
materializedChunk.setBitmapChunk((Chunk*)chunk.getBitmapChunk());
boost::shared_ptr<ConstChunkIterator> src
= chunk.getConstIterator(ChunkIterator::IGNORE_DEFAULT_VALUES|ChunkIterator::IGNORE_EMPTY_CELLS|
(chunk.isSolid() ? ChunkIterator::INTENDED_TILE_MODE : 0));
boost::shared_ptr<ChunkIterator> dst
= materializedChunk.getIterator(query,
(src->getMode() & ChunkIterator::TILE_MODE)|ChunkIterator::ChunkIterator::NO_EMPTY_CHECK|ChunkIterator::SEQUENTIAL_WRITE);
size_t count = 0;
while (!src->end()) {
if (!dst->setPosition(src->getPosition()))
throw SYSTEM_EXCEPTION(SCIDB_SE_MERGE, SCIDB_LE_OPERATION_FAILED) << "setPosition";
dst->writeItem(src->getItem());
count += 1;
++(*src);
}
if (!(src->getMode() & ChunkIterator::TILE_MODE) &&
!chunk.getArrayDesc().hasOverlap()) {
materializedChunk.setCount(count);
}
dst->flush();
}
示例13: updateEntry
void updateEntry()
{
// Read file
MemChunk data;
data.importFile(filename);
// Read image
SImage image;
image.open(data, 0, "png");
image.convertPaletted(&palette);
// Convert image to entry gfx format
SIFormat* format = SIFormat::getFormat(gfx_format);
if (format)
{
MemChunk conv_data;
if (format->saveImage(image, conv_data, &palette))
{
// Update entry data
entry->importMemChunk(conv_data);
EntryOperations::setGfxOffsets(entry, offsets.x, offsets.y);
}
else
{
LOG_MESSAGE(1, "Unable to convert external png to %s", format->getName());
}
}
}
示例14: open
// -----------------------------------------------------------------------------
// Reads an archive from disk
// Returns true if successful, false otherwise
// -----------------------------------------------------------------------------
bool Archive::open(string_view filename)
{
// Read the file into a MemChunk
MemChunk mc;
if (!mc.importFile(filename))
{
Global::error = "Unable to open file. Make sure it isn't in use by another program.";
return false;
}
// Update filename before opening
auto backupname = filename_;
filename_ = filename;
// Load from MemChunk
sf::Clock timer;
if (open(mc))
{
Log::info(2, "Archive::open took {}ms", timer.getElapsedTime().asMilliseconds());
on_disk_ = true;
return true;
}
else
{
filename_ = backupname;
return false;
}
}
示例15: open
/* Archive::open
* Reads an archive from disk
* Returns true if successful, false otherwise
*******************************************************************/
bool Archive::open(string filename)
{
// Read the file into a MemChunk
MemChunk mc;
if (!mc.importFile(filename))
{
Global::error = "Unable to open file. Make sure it isn't in use by another program.";
return false;
}
// Update filename before opening
string backupname = this->filename;
this->filename = filename;
// Load from MemChunk
sf::Clock timer;
if (open(mc))
{
LOG_MESSAGE(2, "Archive::open took %dms", timer.getElapsedTime().asMilliseconds());
this->on_disk = true;
return true;
}
else
{
this->filename = backupname;
return false;
}
}