Skip to content

Commit

Permalink
Replace NULL to nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
Xrayez committed Jul 22, 2021
1 parent 3b2799e commit 1e2074e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 47 deletions.
2 changes: 1 addition & 1 deletion core/goost_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Dictionary GoostEngine::get_version_info() const {

static Array array_from_info(const char *const *info_list) {
Array arr;
for (int i = 0; info_list[i] != NULL; i++) {
for (int i = 0; info_list[i] != nullptr; i++) {
arr.push_back(info_list[i]);
}
return arr;
Expand Down
22 changes: 11 additions & 11 deletions core/image/drivers/png/image_loader_indexed_png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ Error ImageLoaderIndexedPNG::_load_image(void *rf_up, png_rw_ptr p_func, Ref<Ima
png_structp png;
png_infop info;

png = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, _png_error_function, _png_warn_function, (png_voidp)NULL,
png = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)nullptr, _png_error_function, _png_warn_function, (png_voidp)nullptr,
_png_malloc_fn, _png_free_fn);

ERR_FAIL_COND_V(!png, ERR_OUT_OF_MEMORY);

info = png_create_info_struct(png);
if (!info) {
png_destroy_read_struct(&png, NULL, NULL);
png_destroy_read_struct(&png, nullptr, nullptr);
ERR_PRINT("Out of Memory");
return ERR_OUT_OF_MEMORY;
}

if (setjmp(png_jmpbuf(png))) {
png_destroy_read_struct(&png, NULL, NULL);
png_destroy_read_struct(&png, nullptr, nullptr);
ERR_PRINT("PNG Corrupted");
return ERR_FILE_CORRUPT;
}
Expand All @@ -62,11 +62,11 @@ Error ImageLoaderIndexedPNG::_load_image(void *rf_up, png_rw_ptr p_func, Ref<Ima
int depth, color;

png_read_info(png, info);
png_get_IHDR(png, info, &width, &height, &depth, &color, NULL, NULL, NULL);
png_get_IHDR(png, info, &width, &height, &depth, &color, nullptr, nullptr, nullptr);

bool update_info = false;

png_colorp png_palette = NULL;
png_colorp png_palette = nullptr;
int palette_size = 0;

if (png_get_valid(png, info, PNG_INFO_PLTE)) {
Expand All @@ -84,17 +84,17 @@ Error ImageLoaderIndexedPNG::_load_image(void *rf_up, png_rw_ptr p_func, Ref<Ima
update_info = true;
}

png_bytep png_palette_alpha = NULL;
png_bytep png_palette_alpha = nullptr;
int palette_alpha_size = 0;

if (png_get_valid(png, info, PNG_INFO_tRNS)) {
png_get_tRNS(png, info, &png_palette_alpha, &palette_alpha_size, NULL);
png_get_tRNS(png, info, &png_palette_alpha, &palette_alpha_size, nullptr);
update_info = true;
}

if (update_info) {
png_read_update_info(png, info);
png_get_IHDR(png, info, &width, &height, &depth, &color, NULL, NULL, NULL);
png_get_IHDR(png, info, &width, &height, &depth, &color, nullptr, nullptr, nullptr);
}

int components = 0;
Expand Down Expand Up @@ -123,7 +123,7 @@ Error ImageLoaderIndexedPNG::_load_image(void *rf_up, png_rw_ptr p_func, Ref<Ima
} break;
default: {
ERR_PRINT("INVALID PNG TYPE");
png_destroy_read_struct(&png, &info, NULL);
png_destroy_read_struct(&png, &info, nullptr);
return ERR_UNAVAILABLE;
} break;
}
Expand Down Expand Up @@ -151,7 +151,7 @@ Error ImageLoaderIndexedPNG::_load_image(void *rf_up, png_rw_ptr p_func, Ref<Ima

if (color == PNG_COLOR_TYPE_PALETTE) {
// Loaded data are indices
ERR_FAIL_COND_V_MSG(png_palette == NULL, ERR_BUG, "Expected to extract PNG palette, got none.");
ERR_FAIL_COND_V_MSG(png_palette == nullptr, ERR_BUG, "Expected to extract PNG palette, got none.");

PoolVector<uint8_t> palette_data;
palette_data.resize(palette_size * 4);
Expand Down Expand Up @@ -187,7 +187,7 @@ Error ImageLoaderIndexedPNG::_load_image(void *rf_up, png_rw_ptr p_func, Ref<Ima
p_image->create(width, height, 0, fmt, dstbuff);
}

png_destroy_read_struct(&png, &info, NULL);
png_destroy_read_struct(&png, &info, nullptr);

return OK;
}
Expand Down
12 changes: 6 additions & 6 deletions core/image/drivers/png/resource_saver_indexed_png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Error ResourceSaverIndexedPNG::save_image(const String &p_path, const Ref<ImageI
png_bytep *row_pointers;

// Initialize.
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);

ERR_FAIL_COND_V(!png_ptr, ERR_CANT_CREATE);

Expand All @@ -62,7 +62,7 @@ Error ResourceSaverIndexedPNG::save_image(const String &p_path, const Ref<ImageI
if (err != OK) {
ERR_FAIL_V_MSG(err, "Cannot open file.");
}
png_set_write_fn(png_ptr, f, _write_png_data, NULL);
png_set_write_fn(png_ptr, f, _write_png_data, nullptr);

// Write header.
if (setjmp(png_jmpbuf(png_ptr))) {
Expand Down Expand Up @@ -117,8 +117,8 @@ Error ResourceSaverIndexedPNG::save_image(const String &p_path, const Ref<ImageI
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);

// Prepare palette
png_colorp png_palette = NULL;
png_bytep png_palette_alpha = NULL;
png_colorp png_palette = nullptr;
png_bytep png_palette_alpha = nullptr;

if (has_palette) {
PoolVector<uint8_t>::Read r = p_img->get_palette_data().read();
Expand Down Expand Up @@ -158,7 +158,7 @@ Error ResourceSaverIndexedPNG::save_image(const String &p_path, const Ref<ImageI
png_bytep a = &png_palette_alpha[i];
*a = r[i * ps + 3];
}
png_set_tRNS(png_ptr, info_ptr, png_palette_alpha, palette_size, NULL);
png_set_tRNS(png_ptr, info_ptr, png_palette_alpha, palette_size, nullptr);
}
}
png_write_info(png_ptr, info_ptr);
Expand Down Expand Up @@ -188,7 +188,7 @@ Error ResourceSaverIndexedPNG::save_image(const String &p_path, const Ref<ImageI
memdelete(f);
ERR_FAIL_V(ERR_CANT_OPEN);
}
png_write_end(png_ptr, NULL);
png_write_end(png_ptr, nullptr);
f->close();
memdelete(f);

Expand Down
2 changes: 1 addition & 1 deletion core/image/goost_image_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "modules/modules_enabled.gen.h"

_GoostImage *_GoostImage::singleton = NULL;
_GoostImage *_GoostImage::singleton = nullptr;

void _GoostImage::replace_color(Ref<Image> p_image, const Color &p_color, const Color &p_with_color) {
GoostImage::replace_color(p_image, p_color, p_with_color);
Expand Down
6 changes: 3 additions & 3 deletions core/image/image_indexed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

const int ImageIndexed::MAX_PALETTE_SIZE = 256;

ImageIndexedMemLoadFunc ImageIndexed::_indexed_png_mem_loader_func = NULL;
SaveIndexedPNGFunc ImageIndexed::save_indexed_png_func = NULL;
ImageIndexedMemLoadFunc ImageIndexed::_indexed_png_mem_loader_func = nullptr;
SaveIndexedPNGFunc ImageIndexed::save_indexed_png_func = nullptr;

Error ImageIndexed::create_indexed(int p_num_palette_entries) {
ERR_FAIL_COND_V(empty(), ERR_UNCONFIGURED);
Expand Down Expand Up @@ -430,7 +430,7 @@ Error ImageIndexed::load_indexed_png(const String &p_path) {
}

Error ImageIndexed::save_indexed_png(const String &p_path) const {
if (save_indexed_png_func == NULL)
if (save_indexed_png_func == nullptr)
return ERR_UNAVAILABLE;

return save_indexed_png_func(p_path, Ref<ImageIndexed>((ImageIndexed *)this));
Expand Down
2 changes: 1 addition & 1 deletion core/script/register_script_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace goost {

static MixinScriptLanguage *script_mixin_script = NULL;
static MixinScriptLanguage *script_mixin_script = nullptr;

#if defined(TOOLS_ENABLED) && defined(GOOST_MixinScript)
static ScriptEditorBase *create_editor(const RES &p_resource) {
Expand Down
54 changes: 30 additions & 24 deletions scene/physics/2d/shape_cast_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ bool ShapeCast2D::is_colliding() const {
}

Object *ShapeCast2D::get_collider(int p_idx) const {
ERR_FAIL_INDEX_V_MSG(p_idx, result.size(), NULL, "No collider found.");

if (result[p_idx].collider_id == 0)
return NULL;
ERR_FAIL_INDEX_V_MSG(p_idx, result.size(), nullptr, "No collider found.");

if (result[p_idx].collider_id == 0) {
return nullptr;
}
return ObjectDB::get_instance(result[p_idx].collider_id);
}

Expand Down Expand Up @@ -96,7 +96,7 @@ real_t ShapeCast2D::get_closest_collision_unsafe_distance() const {
}

Object *ShapeCast2D::get_closest_collider() const {
ERR_FAIL_COND_V_MSG(result.empty(), NULL, "Shape cast has not collided with anything yet.");
ERR_FAIL_COND_V_MSG(result.empty(), nullptr, "Shape cast has not collided with anything yet.");
return ObjectDB::get_instance(result[0].collider_id);
}

Expand All @@ -118,10 +118,12 @@ Vector2 ShapeCast2D::get_closest_collision_normal() const {
void ShapeCast2D::set_enabled(bool p_enabled) {
enabled = p_enabled;
update();
if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint())
if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
set_physics_process_internal(p_enabled);
if (!p_enabled)
}
if (!p_enabled) {
collided = false;
}
}

bool ShapeCast2D::is_enabled() const {
Expand All @@ -142,19 +144,20 @@ Ref<Shape2D> ShapeCast2D::get_shape() const {
}

void ShapeCast2D::set_exclude_parent_body(bool p_exclude_parent_body) {
if (exclude_parent_body == p_exclude_parent_body)
if (exclude_parent_body == p_exclude_parent_body) {
return;

}
exclude_parent_body = p_exclude_parent_body;

if (!is_inside_tree())
if (!is_inside_tree()) {
return;

}
if (Object::cast_to<CollisionObject2D>(get_parent())) {
if (exclude_parent_body)
if (exclude_parent_body) {
exclude.insert(Object::cast_to<CollisionObject2D>(get_parent())->get_rid());
else
} else {
exclude.erase(Object::cast_to<CollisionObject2D>(get_parent())->get_rid());
}
}
}

Expand All @@ -165,22 +168,23 @@ bool ShapeCast2D::get_exclude_parent_body() const {
void ShapeCast2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (enabled && !Engine::get_singleton()->is_editor_hint())
if (enabled && !Engine::get_singleton()->is_editor_hint()) {
set_physics_process_internal(true);
else
} else {
set_physics_process_internal(false);

}
if (Object::cast_to<CollisionObject2D>(get_parent())) {
if (exclude_parent_body)
if (exclude_parent_body) {
exclude.insert(Object::cast_to<CollisionObject2D>(get_parent())->get_rid());
else
} else {
exclude.erase(Object::cast_to<CollisionObject2D>(get_parent())->get_rid());
}
}
} break;
case NOTIFICATION_EXIT_TREE: {
if (enabled)
if (enabled) {
set_physics_process_internal(false);

}
} break;

case NOTIFICATION_DRAW: {
Expand Down Expand Up @@ -227,8 +231,9 @@ void ShapeCast2D::_notification(int p_what) {
#endif
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (!enabled)
if (!enabled) {
break;
}
_update_shapecast_state();
} break;
}
Expand Down Expand Up @@ -287,8 +292,9 @@ void ShapeCast2D::add_exception_rid(const RID &p_rid) {
void ShapeCast2D::add_exception(const Object *p_object) {
ERR_FAIL_NULL(p_object);
const CollisionObject2D *co = Object::cast_to<CollisionObject2D>(p_object);
if (!co)
if (!co) {
return;
}
add_exception_rid(co->get_rid());
}

Expand All @@ -299,8 +305,9 @@ void ShapeCast2D::remove_exception_rid(const RID &p_rid) {
void ShapeCast2D::remove_exception(const Object *p_object) {
ERR_FAIL_NULL(p_object);
const CollisionObject2D *co = Object::cast_to<CollisionObject2D>(p_object);
if (!co)
if (!co) {
return;
}
remove_exception_rid(co->get_rid());
}

Expand Down Expand Up @@ -354,7 +361,6 @@ String ShapeCast2D::get_configuration_warning() const {
}
warning += TTR("This node cannot interact with other objects unless a Shape2D is assigned.");
}

return warning;
}

Expand Down

0 comments on commit 1e2074e

Please sign in to comment.