Files
test2/source/blender/blenloader/BLO_undofile.hh
Jacques Lucke 311ca3e6af Core: rename Session UUID to Session UID
`UUID` generally stands for "universally unique identifier". The session identifier that
we use is neither universally unique, nor does it follow the standard. Therefor, the term
"session uuid" is confusing and should be replaced.

In #116888 we briefly talked about a better name and ended up with "session uid".
The reason for "uid" instead of "id" is that the latter is a very overloaded term in Blender
already.

This patch changes all uses of "uuid" to "uid" where it's used in the context of a
"session uid". It's not always trivial to see whether a specific mention of "uuid" refers
to an actual uuid or something else. Therefore, I might have missed some renames.
I can't think of an automated way to differentiate the case.

BMesh also uses the term "uuid" sometimes in a the wrong context (e.g. `UUIDFaceStepItem`)
but there it also does not mean "session uid", so it's *not* changed by this patch.

Pull Request: https://projects.blender.org/blender/blender/pulls/117350
2024-01-22 13:47:13 +01:00

105 lines
2.7 KiB
C++

/* SPDX-FileCopyrightText: 2004 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
/** \file
* \ingroup blenloader
* External write-file function prototypes.
*/
#include "BLI_filereader.h"
#include "BLI_listbase.h"
#include "BLI_map.hh"
struct Main;
struct Scene;
struct MemFileChunk {
void *next, *prev;
const char *buf;
/** Size in bytes. */
size_t size;
/** When true, this chunk doesn't own the memory, it's shared with a previous #MemFileChunk */
bool is_identical;
/** When true, this chunk is also identical to the one in the next step (used by undo code to
* detect unchanged IDs).
* Defined when writing the next step (i.e. last undo step has those always false). */
bool is_identical_future;
/** Session UID of the ID being currently written (MAIN_ID_SESSION_UID_UNSET when not writing
* ID-related data). Used to find matching chunks in previous memundo step. */
uint id_session_uid;
};
struct MemFile {
ListBase chunks;
size_t size;
};
struct MemFileWriteData {
MemFile *written_memfile;
MemFile *reference_memfile;
uint current_id_session_uid;
MemFileChunk *reference_current_chunk;
/** Maps an ID session uid to its first reference MemFileChunk, if existing. */
blender::Map<uint, MemFileChunk *> id_session_uid_mapping;
};
struct MemFileUndoData {
char filepath[1024]; /* FILE_MAX */
MemFile memfile;
size_t undo_size;
};
/* FileReader-compatible wrapper for reading MemFiles */
struct UndoReader {
FileReader reader;
MemFile *memfile;
int undo_direction;
bool memchunk_identical;
};
/* Actually only used `writefile.cc`. */
void BLO_memfile_write_init(MemFileWriteData *mem_data,
MemFile *written_memfile,
MemFile *reference_memfile);
void BLO_memfile_write_finalize(MemFileWriteData *mem_data);
void BLO_memfile_chunk_add(MemFileWriteData *mem_data, const char *buf, size_t size);
/* exports */
/**
* Not memfile itself.
*/
/* **************** support for memory-write, for undo buffers *************** */
void BLO_memfile_free(MemFile *memfile);
/**
* Result is that 'first' is being freed.
* To keep the #MemFile linked list of consistent, `first` is always first in list.
*/
void BLO_memfile_merge(MemFile *first, MemFile *second);
/**
* Clear is_identical_future before adding next memfile.
*/
void BLO_memfile_clear_future(MemFile *memfile);
/* Utilities. */
Main *BLO_memfile_main_get(MemFile *memfile, Main *bmain, Scene **r_scene);
/**
* Saves .blend using undo buffer.
*
* \return success.
*/
bool BLO_memfile_write_file(MemFile *memfile, const char *filepath);
FileReader *BLO_memfile_new_filereader(MemFile *memfile, int undo_direction);