Move "initialized" variables for static class init into a class member

This commit is contained in:
ROllerozxa 2026-06-05 19:49:33 +02:00
commit 89ea9eebbd
20 changed files with 41 additions and 34 deletions

View file

@ -31,7 +31,7 @@ struct cvert {
tvec2 u;
} __attribute__((packed));
static bool initialized = false;
bool cable::initialized = false;
static struct tms_mesh *_mesh;
static struct tms_entity *_e;

View file

@ -111,6 +111,7 @@ class cable : public entity
static struct tms_entity *get_entity(void);
static void reset_counter(void);
static void upload_buffers(void);
static bool initialized;
static void _init(void);
friend class plug;

View file

@ -319,4 +319,7 @@ class chunk_window : public tms::entity
void set(b2Vec2 lower, b2Vec2 upper);
void recreate_caveview_texture(float px, float py, float ax, float ay);
static bool initialized;
static void _init();
};

View file

@ -12,7 +12,7 @@ static struct tms_mesh *mesh_pool[MAX_CHUNKS];
static tms::gbuffer *vbuf[MAX_CHUNKS];
static struct tms_varray *va[MAX_CHUNKS];
static struct tms_gbuffer *ibuf;
static bool initialized;
bool chunk_window::initialized = false;
static struct tms_mesh *grass_pool[MAX_CHUNKS];
static struct tms_gbuffer *grass_vbuf[MAX_CHUNKS];
@ -39,9 +39,7 @@ struct cvert {
static int vertices_per_tpixel;
static int indices_per_tpixel;
static void
_init()
{
void chunk_window::_init() {
initialized = true;
struct tms_mesh *mm = mesh_factory::get_mesh(MODEL_BOX_TEX);
@ -119,9 +117,8 @@ chunk_window::chunk_window()
void
chunk_window::reset()
{
if (!initialized) {
if (!initialized)
_init();
}
memset(this->slots, 0, sizeof(this->slots));

View file

@ -54,7 +54,7 @@ forward_slider_on_change(struct tms_wdg *w, float values[2])
}
static float cooldown_time = 0.f;
static bool initialized = false;
static bool gui_init = false;
static int _menu_width = 200;
static int menu_min_width;
static int menu_max_width;
@ -1407,14 +1407,13 @@ game::widget_clicked(principia_wdg *w, uint8_t button_id, int pid)
void
game::init_gui(void)
{
if (initialized) {
if (gui_init)
return;
}
int ierr;
tms_infof("Initializing GUI ");
initialized = true;
gui_init = true;
this->text_small = new p_text(font::small);

View file

@ -9,7 +9,7 @@
static struct tms_varray *va;
static struct tms_gbuffer *vbuf;
static struct tms_gbuffer *ibuf;
static bool initialized = false;
bool gearbox::initialized = false;
static gearbox *mslots[MAX_MSLOTS];
static int num_mslots;
@ -29,7 +29,7 @@ struct vertex2 {
tvec3 nor;
} __attribute__ ((packed));
static void init_gearbox()
void gearbox::_init()
{
num_mslots = 0;
@ -139,9 +139,8 @@ gearbox::get_body(uint8_t n)
gearbox::gearbox()
{
if (!initialized) {
init_gearbox();
}
if (!initialized)
_init();
this->set_flag(ENTITY_DO_STEP, true);
this->set_flag(ENTITY_HAS_CONFIG, true);

View file

@ -55,4 +55,7 @@ class gearbox : public edev, public b2QueryCallback
edevice* solve_electronics();
void create_gearjoint();
static bool initialized;
static void _init();
};

View file

@ -11,7 +11,7 @@ static const char *FONT_PATH = "data/fonts/Roboto-Bold.ttf";
//static const char *FONT_PATH = "data/fonts/DejaVuSans.ttf";
//static const char *FONT_PATH = "data/fonts/DejaVuSans-Bold.ttf";
static bool initialized = false;
bool gui_spritesheet::initialized = false;
static bool font_init = false;
SDL_Color C_WHITE = {MENU_WHITE, 0xFF};
@ -826,9 +826,8 @@ gui_spritesheet::upload_text_atlas()
void
gui_spritesheet::init()
{
if (initialized) {
if (initialized)
return;
}
initialized = true;

View file

@ -172,6 +172,7 @@ class gui_spritesheet
static float text_factor;
static bool initialized;
static void init_atlas(void);
static void init_loading_font(void);
static void init_fonts(void);

View file

@ -4,7 +4,7 @@
#include "game.hh"
#include "ui.hh"
static bool initialized = false;
bool pixel::initialized = false;
static bool _modified = false;
struct vertex {
@ -135,9 +135,8 @@ pixel::upload_buffers(void)
pixel::pixel()
{
if (!initialized) {
if (!initialized)
initialize();
}
this->last_size = -1.f;

View file

@ -22,6 +22,7 @@ class pixel : public basepixel,
public:
pixel();
static bool initialized;
static void initialize();
static struct tms_entity *get_entity(int x);
static void reset_counter();

View file

@ -106,7 +106,7 @@ enum {
SERIALIZE_BRANCH_END = 3,
};
static bool initialized = false;
bool plant::initialized = false;
static struct tms_gbuffer *ibuf = 0;
static struct tms_gbuffer *vbuf = 0;
static struct tms_varray *va = 0;
@ -123,8 +123,7 @@ struct vertex {
tvec2 tex;
} __attribute__ ((packed));
static void _init()
{
void plant::_init() {
vbuf = tms_gbuffer_alloc(MAX_BRANCHES*sizeof(struct vertex)*QUALITY*MAX_SECTIONS);
ibuf = tms_gbuffer_alloc(MAX_BRANCHES*MAX_SECTIONS * (QUALITY) * 6 * sizeof(short));

View file

@ -156,6 +156,9 @@ class plant : public entity_simpleconnect
float pending_timer;
b2Vec2 pending_normal;
static bool initialized;
static void _init();
inline float rand_range(tvec2 v)
{
float r = (float)rand()/(float)RAND_MAX;
@ -236,7 +239,7 @@ class plant : public entity_simpleconnect
}
void set_position(float x, float y, uint8_t frame);
connection *load_connection(connection &c);
void connection_create_joint(connection *c);
bool connection_destroy_joint(connection *c);

View file

@ -11,7 +11,7 @@
#define MAX_ROPES 20
static bool initialized = false;
bool rope::initialized = false;
static struct tms_mesh *_mesh;
static struct tms_entity *_e;
static float _cam_x = 0.f, _cam_y = 0.f;

View file

@ -55,6 +55,7 @@ class rope : public entity,
static void reset_counter(void);
static void upload_buffers(void);
static void _init();
static bool initialized;
uint32_t get_num_bodies();
b2Body* get_body(uint8_t frame);

View file

@ -34,10 +34,11 @@
//
static bool slots[NUM_SLOTS];
static bool initialized = false;
static p_font *note_font[NUM_SIZES];
static SDL_Surface *surface;
static int spacing[NUM_SIZES];
bool sticky::initialized = false;
tms_texture sticky::texture;
// Decode one UTF-8 codepoint; advance *s. Returns codepoint or -1 on end/error.
@ -201,9 +202,8 @@ void sticky::_deinit(void) {
}
sticky::sticky() {
if (!initialized) {
if (!initialized)
_init();
}
for (int x=0; x<STICKY_MAX_LINES; ++x) {
memset(&this->lines[x], 0, STICKY_MAX_PER_LINE);

View file

@ -22,6 +22,7 @@ class sticky : public entity
public:
static tms_texture texture;
static bool initialized;
static void _init();
static void _deinit();

View file

@ -177,7 +177,7 @@ struct tpixel_material tpixel_materials[NUM_TPIXEL_MATERIALS] = {
},
};
static bool initialized = false;
bool tpixel::initialized = false;
static bool _modified = false;
struct vertex {

View file

@ -108,6 +108,7 @@ class tpixel : public basepixel
tpixel();
static bool initialized;
static void initialize();
static struct tms_entity *get_entity(int x);
static void reset_counter();

View file

@ -34,7 +34,7 @@ struct tms_graph *w_updatec_graph;
std::set<entity*> *w_mstep_set;
static bool initialized = false;
static bool workers_init = false;
static int num_running_workers = 0;
bool
@ -52,8 +52,8 @@ w_get_num_workers()
void
w_init()
{
if (!initialized) {
initialized = true;
if (!workers_init) {
workers_init = true;
num_running_workers = 0;
w_collide_destroy_lock = SDL_CreateMutex();