summaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
Diffstat (limited to 'core/os')
-rw-r--r--core/os/dir_access.cpp29
-rw-r--r--core/os/dir_access.h3
-rw-r--r--core/os/file_access.cpp64
-rw-r--r--core/os/file_access.h3
-rw-r--r--core/os/main_loop.cpp12
-rw-r--r--core/os/memory.h18
-rw-r--r--core/os/os.cpp35
-rw-r--r--core/os/rw_lock.h12
-rw-r--r--core/os/semaphore.h3
-rw-r--r--core/os/thread.cpp9
-rw-r--r--core/os/threaded_array_processor.h3
11 files changed, 124 insertions, 67 deletions
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index 5763c74862..9f2672e038 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -61,8 +61,9 @@ int DirAccess::get_current_drive() {
String path = get_current_dir().to_lower();
for (int i = 0; i < get_drive_count(); i++) {
String d = get_drive(i).to_lower();
- if (path.begins_with(d))
+ if (path.begins_with(d)) {
return i;
+ }
}
return 0;
@@ -80,10 +81,11 @@ static Error _erase_recursive(DirAccess *da) {
String n = da->get_next();
while (n != String()) {
if (n != "." && n != "..") {
- if (da->current_is_dir())
+ if (da->current_is_dir()) {
dirs.push_back(n);
- else
+ } else {
files.push_back(n);
+ }
}
n = da->get_next();
@@ -147,13 +149,13 @@ Error DirAccess::make_dir_recursive(String p_dir) {
String base;
- if (full_dir.begins_with("res://"))
+ if (full_dir.begins_with("res://")) {
base = "res://";
- else if (full_dir.begins_with("user://"))
+ } else if (full_dir.begins_with("user://")) {
base = "user://";
- else if (full_dir.begins_with("/"))
+ } else if (full_dir.begins_with("/")) {
base = "/";
- else if (full_dir.find(":/") != -1) {
+ } else if (full_dir.find(":/") != -1) {
base = full_dir.substr(0, full_dir.find(":/") + 2);
} else {
ERR_FAIL_V(ERR_INVALID_PARAMETER);
@@ -229,8 +231,9 @@ DirAccess *DirAccess::open(const String &p_path, Error *r_error) {
ERR_FAIL_COND_V_MSG(!da, nullptr, "Cannot create DirAccess for path '" + p_path + "'.");
Error err = da->change_dir(p_path);
- if (r_error)
+ if (r_error) {
*r_error = err;
+ }
if (err != OK) {
memdelete(da);
return nullptr;
@@ -250,8 +253,9 @@ DirAccess *DirAccess::create(AccessType p_access) {
String DirAccess::get_full_path(const String &p_path, AccessType p_access) {
DirAccess *d = DirAccess::create(p_access);
- if (!d)
+ if (!d) {
return p_path;
+ }
d->change_dir(p_path);
String full = d->get_current_dir();
@@ -298,8 +302,9 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) {
fdst->close();
err = FileAccess::set_unix_permissions(p_to, p_chmod_flags);
// If running on a platform with no chmod support (i.e., Windows), don't fail
- if (err == ERR_UNAVAILABLE)
+ if (err == ERR_UNAVAILABLE) {
err = OK;
+ }
}
memdelete(fsrc);
@@ -334,9 +339,9 @@ Error DirAccess::_copy_dir(DirAccess *p_target_da, String p_to, int p_chmod_flag
String n = get_next();
while (n != String()) {
if (n != "." && n != "..") {
- if (current_is_dir())
+ if (current_is_dir()) {
dirs.push_back(n);
- else {
+ } else {
const String &rel_path = n;
if (!n.is_rel_path()) {
list_dir_end();
diff --git a/core/os/dir_access.h b/core/os/dir_access.h
index 06b3abca8c..6bce9a4c12 100644
--- a/core/os/dir_access.h
+++ b/core/os/dir_access.h
@@ -133,8 +133,9 @@ struct DirAccessRef {
DirAccessRef(DirAccess *fa) { f = fa; }
~DirAccessRef() {
- if (f)
+ if (f) {
memdelete(f);
+ }
}
};
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index 8b13e53812..f9ba8ff2d2 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -51,12 +51,14 @@ FileAccess *FileAccess::create(AccessType p_access) {
}
bool FileAccess::exists(const String &p_name) {
- if (PackedData::get_singleton() && PackedData::get_singleton()->has_path(p_name))
+ if (PackedData::get_singleton() && PackedData::get_singleton()->has_path(p_name)) {
return true;
+ }
FileAccess *f = open(p_name, READ);
- if (!f)
+ if (!f) {
return false;
+ }
memdelete(f);
return true;
}
@@ -90,8 +92,9 @@ FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_er
if (!(p_mode_flags & WRITE) && PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled()) {
ret = PackedData::get_singleton()->try_open_path(p_path);
if (ret) {
- if (r_error)
+ if (r_error) {
*r_error = OK;
+ }
return ret;
}
}
@@ -99,8 +102,9 @@ FileAccess *FileAccess::open(const String &p_path, int p_mode_flags, Error *r_er
ret = create_for_path(p_path);
Error err = ret->_open(p_path, p_mode_flags);
- if (r_error)
+ if (r_error) {
*r_error = err;
+ }
if (err != OK) {
memdelete(ret);
ret = nullptr;
@@ -214,10 +218,11 @@ float FileAccess::get_float() const {
};
real_t FileAccess::get_real() const {
- if (real_is_double)
+ if (real_is_double) {
return get_double();
- else
+ } else {
return get_float();
+ }
}
double FileAccess::get_double() const {
@@ -233,8 +238,9 @@ String FileAccess::get_token() const {
while (!eof_reached()) {
if (c <= ' ') {
- if (token.length())
+ if (token.length()) {
break;
+ }
} else {
token += c;
}
@@ -299,8 +305,9 @@ String FileAccess::get_line() const {
if (c == '\n' || c == '\0') {
line.push_back(0);
return String::utf8(line.get_data());
- } else if (c != '\r')
+ } else if (c != '\r') {
line.push_back(c);
+ }
c = get_8();
}
@@ -314,14 +321,16 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const {
String l;
int qc = 0;
do {
- if (eof_reached())
+ if (eof_reached()) {
break;
+ }
l += get_line() + "\n";
qc = 0;
for (int i = 0; i < l.length(); i++) {
- if (l[i] == '"')
+ if (l[i] == '"') {
qc++;
+ }
}
} while (qc % 2);
@@ -360,8 +369,9 @@ Vector<String> FileAccess::get_csv_line(const String &p_delim) const {
int FileAccess::get_buffer(uint8_t *p_dst, int p_length) const {
int i = 0;
- for (i = 0; i < p_length && !eof_reached(); i++)
+ for (i = 0; i < p_length && !eof_reached(); i++) {
p_dst[i] = get_8();
+ }
return i;
}
@@ -426,10 +436,11 @@ void FileAccess::store_64(uint64_t p_dest) {
}
void FileAccess::store_real(real_t p_real) {
- if (sizeof(real_t) == 4)
+ if (sizeof(real_t) == 4) {
store_float(p_real);
- else
+ } else {
store_double(p_real);
+ }
}
void FileAccess::store_float(float p_dest) {
@@ -445,8 +456,9 @@ void FileAccess::store_double(double p_dest) {
};
uint64_t FileAccess::get_modified_time(const String &p_file) {
- if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file))
+ if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) {
return 0;
+ }
FileAccess *fa = create_for_path(p_file);
ERR_FAIL_COND_V_MSG(!fa, 0, "Cannot create FileAccess for path '" + p_file + "'.");
@@ -457,8 +469,9 @@ uint64_t FileAccess::get_modified_time(const String &p_file) {
}
uint32_t FileAccess::get_unix_permissions(const String &p_file) {
- if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file))
+ if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) {
return 0;
+ }
FileAccess *fa = create_for_path(p_file);
ERR_FAIL_COND_V_MSG(!fa, 0, "Cannot create FileAccess for path '" + p_file + "'.");
@@ -478,8 +491,9 @@ Error FileAccess::set_unix_permissions(const String &p_file, uint32_t p_permissi
}
void FileAccess::store_string(const String &p_string) {
- if (p_string.length() == 0)
+ if (p_string.length() == 0) {
return;
+ }
CharString cs = p_string.utf8();
store_buffer((uint8_t *)&cs[0], cs.length());
@@ -531,8 +545,9 @@ void FileAccess::store_csv_line(const Vector<String> &p_values, const String &p_
}
void FileAccess::store_buffer(const uint8_t *p_src, int p_length) {
- for (int i = 0; i < p_length; i++)
+ for (int i = 0; i < p_length; i++) {
store_8(p_src[i]);
+ }
}
Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_error) {
@@ -570,8 +585,9 @@ String FileAccess::get_file_as_string(const String &p_path, Error *r_error) {
String FileAccess::get_md5(const String &p_file) {
FileAccess *f = FileAccess::open(p_file, READ);
- if (!f)
+ if (!f) {
return String();
+ }
CryptoCore::MD5Context ctx;
ctx.start();
@@ -583,8 +599,9 @@ String FileAccess::get_md5(const String &p_file) {
if (br > 0) {
ctx.update(step, br);
}
- if (br < 4096)
+ if (br < 4096) {
break;
+ }
}
unsigned char hash[16];
@@ -610,8 +627,9 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) {
if (br > 0) {
ctx.update(step, br);
}
- if (br < 4096)
+ if (br < 4096) {
break;
+ }
}
memdelete(f);
}
@@ -624,8 +642,9 @@ String FileAccess::get_multiple_md5(const Vector<String> &p_file) {
String FileAccess::get_sha256(const String &p_file) {
FileAccess *f = FileAccess::open(p_file, READ);
- if (!f)
+ if (!f) {
return String();
+ }
CryptoCore::SHA256Context ctx;
ctx.start();
@@ -637,8 +656,9 @@ String FileAccess::get_sha256(const String &p_file) {
if (br > 0) {
ctx.update(step, br);
}
- if (br < 4096)
+ if (br < 4096) {
break;
+ }
}
unsigned char hash[32];
diff --git a/core/os/file_access.h b/core/os/file_access.h
index a956ae12f4..48b9ee4269 100644
--- a/core/os/file_access.h
+++ b/core/os/file_access.h
@@ -190,8 +190,9 @@ struct FileAccessRef {
FileAccessRef(FileAccess *fa) { f = fa; }
~FileAccessRef() {
- if (f)
+ if (f) {
memdelete(f);
+ }
}
};
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index 1ce49b544b..dc68c2a9f9 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -59,23 +59,27 @@ void MainLoop::set_init_script(const Ref<Script> &p_init_script) {
}
void MainLoop::init() {
- if (init_script.is_valid())
+ if (init_script.is_valid()) {
set_script(init_script);
+ }
- if (get_script_instance())
+ if (get_script_instance()) {
get_script_instance()->call("_initialize");
+ }
}
bool MainLoop::iteration(float p_time) {
- if (get_script_instance())
+ if (get_script_instance()) {
return get_script_instance()->call("_iteration", p_time);
+ }
return false;
}
bool MainLoop::idle(float p_time) {
- if (get_script_instance())
+ if (get_script_instance()) {
return get_script_instance()->call("_idle", p_time);
+ }
return false;
}
diff --git a/core/os/memory.h b/core/os/memory.h
index 42723152e4..46ffb4124b 100644
--- a/core/os/memory.h
+++ b/core/os/memory.h
@@ -108,36 +108,42 @@ _ALWAYS_INLINE_ bool predelete_handler(void *) {
template <class T>
void memdelete(T *p_class) {
- if (!predelete_handler(p_class))
+ if (!predelete_handler(p_class)) {
return; // doesn't want to be deleted
- if (!__has_trivial_destructor(T))
+ }
+ if (!__has_trivial_destructor(T)) {
p_class->~T();
+ }
Memory::free_static(p_class, false);
}
template <class T, class A>
void memdelete_allocator(T *p_class) {
- if (!predelete_handler(p_class))
+ if (!predelete_handler(p_class)) {
return; // doesn't want to be deleted
- if (!__has_trivial_destructor(T))
+ }
+ if (!__has_trivial_destructor(T)) {
p_class->~T();
+ }
A::free(p_class);
}
#define memdelete_notnull(m_v) \
{ \
- if (m_v) \
+ if (m_v) { \
memdelete(m_v); \
+ } \
}
#define memnew_arr(m_class, m_count) memnew_arr_template<m_class>(m_count)
template <typename T>
T *memnew_arr_template(size_t p_elements, const char *p_descr = "") {
- if (p_elements == 0)
+ if (p_elements == 0) {
return nullptr;
+ }
/** overloading operator new[] cannot be done , because it may not return the real allocated address (it may pad the 'element count' before the actual array). Because of that, it must be done by hand. This is the
same strategy used by std::vector, and the Vector class, so it should be safe.*/
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 4414b582bd..da9dabd401 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -178,14 +178,16 @@ static FileAccess *_OSPRF = nullptr;
static void _OS_printres(Object *p_obj) {
Resource *res = Object::cast_to<Resource>(p_obj);
- if (!res)
+ if (!res) {
return;
+ }
String str = itos(res->get_instance_id()) + String(res->get_class()) + ":" + String(res->get_name()) + " - " + res->get_path();
- if (_OSPRF)
+ if (_OSPRF) {
_OSPRF->store_line(str);
- else
+ } else {
print_line(str);
+ }
}
void OS::print_all_resources(String p_to_file) {
@@ -202,8 +204,9 @@ void OS::print_all_resources(String p_to_file) {
ObjectDB::debug_objects(_OS_printres);
if (p_to_file != "") {
- if (_OSPRF)
+ if (_OSPRF) {
memdelete(_OSPRF);
+ }
_OSPRF = nullptr;
}
}
@@ -366,18 +369,21 @@ void OS::set_has_server_feature_callback(HasServerFeatureCallback p_callback) {
}
bool OS::has_feature(const String &p_feature) {
- if (p_feature == get_name())
+ if (p_feature == get_name()) {
return true;
+ }
#ifdef DEBUG_ENABLED
- if (p_feature == "debug")
+ if (p_feature == "debug") {
return true;
+ }
#else
if (p_feature == "release")
return true;
#endif
#ifdef TOOLS_ENABLED
- if (p_feature == "editor")
+ if (p_feature == "editor") {
return true;
+ }
#else
if (p_feature == "standalone")
return true;
@@ -417,15 +423,17 @@ bool OS::has_feature(const String &p_feature) {
}
#endif
- if (_check_internal_feature_support(p_feature))
+ if (_check_internal_feature_support(p_feature)) {
return true;
+ }
if (has_server_feature_callback && has_server_feature_callback(p_feature)) {
return true;
}
- if (ProjectSettings::get_singleton()->has_custom_feature(p_feature))
+ if (ProjectSettings::get_singleton()->has_custom_feature(p_feature)) {
return true;
+ }
return false;
}
@@ -444,21 +452,24 @@ List<String> OS::get_restart_on_exit_arguments() const {
}
PackedStringArray OS::get_connected_midi_inputs() {
- if (MIDIDriver::get_singleton())
+ if (MIDIDriver::get_singleton()) {
return MIDIDriver::get_singleton()->get_connected_inputs();
+ }
PackedStringArray list;
return list;
}
void OS::open_midi_inputs() {
- if (MIDIDriver::get_singleton())
+ if (MIDIDriver::get_singleton()) {
MIDIDriver::get_singleton()->open();
+ }
}
void OS::close_midi_inputs() {
- if (MIDIDriver::get_singleton())
+ if (MIDIDriver::get_singleton()) {
MIDIDriver::get_singleton()->close();
+ }
}
OS::OS() {
diff --git a/core/os/rw_lock.h b/core/os/rw_lock.h
index e519cea439..1035072cce 100644
--- a/core/os/rw_lock.h
+++ b/core/os/rw_lock.h
@@ -57,12 +57,14 @@ class RWLockRead {
public:
RWLockRead(const RWLock *p_lock) {
lock = const_cast<RWLock *>(p_lock);
- if (lock)
+ if (lock) {
lock->read_lock();
+ }
}
~RWLockRead() {
- if (lock)
+ if (lock) {
lock->read_unlock();
+ }
}
};
@@ -72,12 +74,14 @@ class RWLockWrite {
public:
RWLockWrite(RWLock *p_lock) {
lock = p_lock;
- if (lock)
+ if (lock) {
lock->write_lock();
+ }
}
~RWLockWrite() {
- if (lock)
+ if (lock) {
lock->write_unlock();
+ }
}
};
diff --git a/core/os/semaphore.h b/core/os/semaphore.h
index 3d9d1ab984..077e04704b 100644
--- a/core/os/semaphore.h
+++ b/core/os/semaphore.h
@@ -54,8 +54,9 @@ public:
_ALWAYS_INLINE_ void wait() const {
std::unique_lock<decltype(mutex_)> lock(mutex_);
- while (!count_) // Handle spurious wake-ups.
+ while (!count_) { // Handle spurious wake-ups.
condition_.wait(lock);
+ }
--count_;
}
diff --git a/core/os/thread.cpp b/core/os/thread.cpp
index 399efb19a4..70f960ed2a 100644
--- a/core/os/thread.cpp
+++ b/core/os/thread.cpp
@@ -38,8 +38,9 @@ Error (*Thread::set_name_func)(const String &) = nullptr;
Thread::ID Thread::_main_thread_id = 0;
Thread::ID Thread::get_caller_id() {
- if (get_thread_id_func)
+ if (get_thread_id_func) {
return get_thread_id_func();
+ }
return 0;
}
@@ -51,13 +52,15 @@ Thread *Thread::create(ThreadCreateCallback p_callback, void *p_user, const Sett
}
void Thread::wait_to_finish(Thread *p_thread) {
- if (wait_to_finish_func)
+ if (wait_to_finish_func) {
wait_to_finish_func(p_thread);
+ }
}
Error Thread::set_name(const String &p_name) {
- if (set_name_func)
+ if (set_name_func) {
return set_name_func(p_name);
+ }
return ERR_UNAVAILABLE;
};
diff --git a/core/os/threaded_array_processor.h b/core/os/threaded_array_processor.h
index 0a435961e1..d27399e4cc 100644
--- a/core/os/threaded_array_processor.h
+++ b/core/os/threaded_array_processor.h
@@ -57,8 +57,9 @@ void process_array_thread(void *ud) {
T &data = *(T *)ud;
while (true) {
uint32_t index = atomic_increment(&data.index);
- if (index >= data.elements)
+ if (index >= data.elements) {
break;
+ }
data.process(index);
}
}