Skip to content

Commit

Permalink
Made more things use arenas.
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterPuma80 committed Jan 31, 2025
1 parent 87f2a64 commit 577c2eb
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 45 deletions.
1 change: 1 addition & 0 deletions core/os/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Arena g_memory_arena_images(true);
Arena g_memory_arena_collections(true);
Arena g_memory_arena_physics(true);
Arena g_memory_arena_controls(true);
Arena g_memory_arena_plugins(true);
Arena g_memory_arena_fonts(true);
Arena g_memory_arena_string(true);

Expand Down
81 changes: 41 additions & 40 deletions core/os/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,27 +274,21 @@ constexpr bool is_type_control(const uint32_t type_sig) {
hash_string("PopupMenu"),
hash_string("Shortcut"),


// FIXME: Move to own collection?
// FIXME: Move to own collection
hash_string("FileAccessUnix"),
hash_string("DirAccessUnix"),
hash_string("InputEventKey"),
hash_string("InputEventJoypadButton"),
hash_string("InputEventJoypadMotion"),
hash_string("InputEventMouseButton"),
};

const size_t length = sizeof(_types) / sizeof(_types[0]);
return _is_in_types(_types, length, type_sig);
}

// FIXME: Move to own collection?
hash_string("EditorStringNames"),
hash_string("EditorSettings"),
hash_string("EditorCommandPalette"),
hash_string("EditorDebuggerNode"),
hash_string("EditorPluginCSG"),
hash_string("EditorNode3DGizmoPlugin"),
hash_string("EditorPlugin"),


// FIXME: Move to own collection?
constexpr bool is_type_plugin(const uint32_t type_sig) {
constexpr uint32_t _types[] = {
hash_string("CPUParticles3DEditorPlugin"),
hash_string("NavigationObstacle3DEditorPlugin"),
hash_string("MultiMeshEditorPlugin"),
Expand Down Expand Up @@ -362,15 +356,23 @@ constexpr bool is_type_control(const uint32_t type_sig) {
hash_string("Polygon2DEditorPlugin"),
hash_string("Skeleton2DEditorPlugin"),

// FIXME: Move to own collection?
// FIXME: Move to own collection
hash_string("EditorSettings"),
hash_string("EditorCommandPalette"),
hash_string("EditorDebuggerNode"),
hash_string("EditorPluginCSG"),
hash_string("EditorNode3DGizmoPlugin"),
hash_string("EditorPlugin"),

// FIXME: Move to own collection
hash_string("SoftBodyRenderingServerHandler"),

// FIXME: Move to own collection?
// FIXME: Move to own collection
hash_string("PhysicsDirectBodyState3DExtension"),
hash_string("PhysicsDirectSpaceState3DExtension"),
hash_string("PhysicsServer3DExtension"),

// FIXME: Move to own collection?
// FIXME: Move to own collection
hash_string("ServersDebugger"),
hash_string("SceneDebugger"),
hash_string("DebugAdapterServer"),
Expand All @@ -397,6 +399,7 @@ constexpr bool is_type_string(const uint32_t type_sig) {
hash_string("StringName"),
hash_string("CoreStringNames"),
hash_string("SceneStringNames"),
hash_string("EditorStringNames"),
};

const size_t length = sizeof(_types) / sizeof(_types[0]);
Expand Down Expand Up @@ -514,12 +517,13 @@ extern Arena g_memory_arena_images;
extern Arena g_memory_arena_collections;
extern Arena g_memory_arena_physics;
extern Arena g_memory_arena_controls;
extern Arena g_memory_arena_plugins;
extern Arena g_memory_arena_fonts;
extern Arena g_memory_arena_string;


template <typename T>
std::string_view _get_type_raw_name() {
constexpr std::string_view _get_type_raw_name() {
std::string_view func_name = __PRETTY_FUNCTION__;
return func_name;
}
Expand Down Expand Up @@ -571,6 +575,7 @@ enum class ArenaType {
physics,
images,
controls,
plugins,
fonts,
strings,
};
Expand All @@ -591,6 +596,8 @@ constexpr ArenaType get_arena_type_for_sig() {
return ArenaType::images;
} else if constexpr (is_type_control(type_sig)) {
return ArenaType::controls;
} else if constexpr (is_type_plugin(type_sig)) {
return ArenaType::plugins;
} else if constexpr (is_type_font(type_sig)) {
return ArenaType::fonts;
} else if constexpr (is_type_string(type_sig)) {
Expand All @@ -611,6 +618,7 @@ constexpr Arena& get_arena() {
case ArenaType::physics: return g_memory_arena_physics;
case ArenaType::images: return g_memory_arena_images;
case ArenaType::controls: return g_memory_arena_controls;
case ArenaType::plugins: return g_memory_arena_plugins;
case ArenaType::fonts: return g_memory_arena_fonts;
case ArenaType::strings: return g_memory_arena_string;
default: return init_arena;
Expand All @@ -628,6 +636,7 @@ constexpr std::string_view get_arena_name() {
case ArenaType::physics: return "physics";
case ArenaType::images: return "images";
case ArenaType::controls: return "controls";
case ArenaType::plugins: return "plugins";
case ArenaType::fonts: return "fonts";
case ArenaType::strings: return "string";
default: return "invalid";
Expand All @@ -649,16 +658,6 @@ constexpr bool has_arena_for_type() {
return arena_type != ArenaType::invalid;
}

#define memnewOldWithArgs2(T, m_class, f, l) \
({ \
if constexpr (g_is_logging) { \
std::cout << "???? memnewOldWithArgs2: " << f << " : " << l << std::endl; \
std::cout << "???? memnewOldWithArgs2 name: " << _get_type_name<T>() << std::endl; \
std::cout.flush(); \
}\
_post_initialize(new ("") m_class); \
})

#define memnewOldWithArgs3(name, m_class) \
({ \
if constexpr (g_is_logging) { \
Expand Down Expand Up @@ -756,11 +755,6 @@ constexpr T* memnewNoArgs() {

template <typename T>
bool is_address_in_any_arena(uintptr_t address) {
if constexpr (g_is_logging) {
std::cout << "?!?!?!?! delete T: " << address << " " << _get_type_name<T>() << std::endl;
std::cout.flush();
}

Arena* arenas[] = {
&g_memory_arena_resource,
&g_memory_arena_ref_counted,
Expand All @@ -769,6 +763,7 @@ bool is_address_in_any_arena(uintptr_t address) {
&g_memory_arena_collections,
&g_memory_arena_physics,
&g_memory_arena_controls,
&g_memory_arena_plugins,
&g_memory_arena_fonts,
&g_memory_arena_string,
};
Expand All @@ -781,16 +776,16 @@ bool is_address_in_any_arena(uintptr_t address) {
uintptr_t start = reinterpret_cast<uintptr_t>(&arena->m_buffer);
uintptr_t end = reinterpret_cast<uintptr_t>(start + size);
bool is_in_arena = address >= start && address <= end;
if constexpr (g_is_logging) {
std::cout << "?!?!?!?! arena start: " << start << ", end: " << end << ", is_in_arena: " << is_in_arena << " m_is_valid: " << arena->m_is_valid << " size: " << size << std::endl;
std::cout.flush();
}
//if constexpr (g_is_logging) {
// std::cout << "?!?!?!?! arena start: " << start << ", end: " << end << ", is_in_arena: " << is_in_arena << " m_is_valid: " << arena->m_is_valid << " size: " << size << std::endl;
// std::cout.flush();
//}
if (is_in_arena) {
is_in_any_arena = true;
if constexpr (g_is_logging) {
std::cout << "?!?!?!?! is in Arena !!!!!!!!!!!!!!!!!!!!" << std::endl;
std::cout.flush();
}
//if constexpr (g_is_logging) {
// std::cout << "?!?!?!?! is in Arena !!!!!!!!!!!!!!!!!!!!" << std::endl;
// std::cout.flush();
//}
}
}

Expand Down Expand Up @@ -837,6 +832,12 @@ void memdelete(T *p_class) {
} else {
uintptr_t address = reinterpret_cast<uintptr_t>(&p_class);
bool is_in_any_arena = is_address_in_any_arena<T>(address);

if constexpr (g_is_logging) {
std::cout << "?!?!?!?! delete T: " << address << " " << _get_type_name<T>() << std::endl;
std::cout.flush();
}

if (!is_in_any_arena) {
//Memory::free_static(p_class, false); // FIXME: turn this back on!!!!!!!!!!!!!!!!!!
}
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/camera_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void Camera3DEditorPlugin::make_visible(bool p_visible) {
}

Camera3DEditorPlugin::Camera3DEditorPlugin() {
/* camera_editor = memnewOldNoConstructor( CameraEditor );
/* camera_editor = memnewNoConstructor<CameraEditor>();
EditorNode::get_singleton()->get_main_screen_control()->add_child(camera_editor);
camera_editor->set_anchor(SIDE_LEFT,Control::ANCHOR_END);
Expand Down
2 changes: 1 addition & 1 deletion modules/enet/enet_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ void ENetConnection::Compressor::setup(ENetHost *p_host, CompressionMode p_mode)
case COMPRESS_FASTLZ:
case COMPRESS_ZLIB:
case COMPRESS_ZSTD: {
Compressor *compressor = memnewOldWithArgs2(Compressor, Compressor(p_mode), __FILE__, __LINE__);
Compressor *compressor = memnewWithArgs<Compressor>(p_mode);
enet_host_compress(p_host, &(compressor->enet_compressor));
} break;
}
Expand Down
3 changes: 1 addition & 2 deletions modules/enet/enet_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,14 @@ class ENetConnection : public RefCounted {
Vector<uint8_t> dst_mem;
ENetCompressor enet_compressor;

Compressor(CompressionMode mode);

static size_t enet_compress(void *context, const ENetBuffer *inBuffers, size_t inBufferCount, size_t inLimit, enet_uint8 *outData, size_t outLimit);
static size_t enet_decompress(void *context, const enet_uint8 *inData, size_t inLimit, enet_uint8 *outData, size_t outLimit);
static void enet_compressor_destroy(void *context) {
memdelete((Compressor *)context);
}

public:
Compressor(CompressionMode mode);
static void setup(ENetHost *p_host, CompressionMode p_mode);
};

Expand Down
1 change: 0 additions & 1 deletion scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4479,7 +4479,6 @@ TreeItem *Tree::create_item(TreeItem *p_parent, int p_index) {
if (!root) {
// No root exists, make the given item the new root.
ti = memnewWithArgs<TreeItem>(this);
//ti = memnewOldWithArgs2(TreeItem, TreeItem(this), __FILE__, __LINE__);
ERR_FAIL_NULL_V(ti, nullptr);
ti->cells.resize(columns.size());
ti->is_root = true;
Expand Down

0 comments on commit 577c2eb

Please sign in to comment.