mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-30 01:48:15 +03:00
Add Textbook
A relevant paragraph copied from the original commit history: The idea is that we store all strings somewhere managed, and then the hashmap only needs pointers to those strings. For storing strings, I created a `Textbook` structure, which consists of one or more 50 KB "pages" (allocated as needed) on which you can simply write strings in both languages back-to-back with `textbook_store(textbook, text)` and get pointers to each of them. (I was originally going to just use one big buffer and realloc to double the size when filled up, but then the hashmap would be full of dangling pointers...) When needed, like when switching to a different language, an entire textbook can be freed at once. This commit is part of rewritten history of the localization branch. The original (unsquashed) commit history can be found here: https://github.com/Dav999-v/VVVVVV/tree/localization-orig
This commit is contained in:
committed by
Misa Elizabeth Kai
parent
b148950367
commit
0ed2cb1bc0
36
desktop_version/src/Textbook.h
Normal file
36
desktop_version/src/Textbook.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef TEXTBOOK_H
|
||||
#define TEXTBOOK_H
|
||||
|
||||
#include <SDL_stdinc.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* The purpose of a Textbook is to store, potentially, a lot of text on a pile that shouldn't
|
||||
* go anywhere until we change languages or (for example) unload an entire level's text. */
|
||||
#define TEXTBOOK_MAX_PAGES 1000
|
||||
#define TEXTBOOK_PAGE_SIZE 50000
|
||||
typedef struct _Textbook
|
||||
{
|
||||
char* page[TEXTBOOK_MAX_PAGES];
|
||||
size_t page_len[TEXTBOOK_MAX_PAGES];
|
||||
|
||||
short pages_used;
|
||||
bool protect;
|
||||
} Textbook;
|
||||
|
||||
void textbook_init(Textbook* textbook);
|
||||
void textbook_clear(Textbook* textbook);
|
||||
void textbook_set_protected(Textbook* textbook, bool protect);
|
||||
const void* textbook_store_raw(Textbook* textbook, const void* data, size_t data_len);
|
||||
const char* textbook_store(Textbook* textbook, const char* text);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* TEXTBOOK_H */
|
||||
Reference in New Issue
Block a user