diff options
author | Hubert Jarosz <marqin.pl@gmail.com> | 2016-03-09 00:00:52 +0100 |
---|---|---|
committer | Hubert Jarosz <marqin.pl@gmail.com> | 2016-03-09 00:00:52 +0100 |
commit | 4a4f2479146aa33e235ed57cde311efda68d3c8f (patch) | |
tree | cf91f2869ff8f058c6682569fb31e22e5ee736ad /core/os | |
parent | 1dad6eca812e5c2e313b54265114de8a1d73d999 (diff) |
remove trailing whitespace
Diffstat (limited to 'core/os')
-rw-r--r-- | core/os/copymem.cpp | 2 | ||||
-rw-r--r-- | core/os/dir_access.cpp | 22 | ||||
-rw-r--r-- | core/os/dir_access.h | 12 | ||||
-rw-r--r-- | core/os/file_access.cpp | 90 | ||||
-rw-r--r-- | core/os/file_access.h | 44 | ||||
-rw-r--r-- | core/os/input.h | 2 | ||||
-rw-r--r-- | core/os/input_event.cpp | 24 | ||||
-rw-r--r-- | core/os/input_event.h | 6 | ||||
-rw-r--r-- | core/os/keyboard.h | 20 | ||||
-rw-r--r-- | core/os/main_loop.h | 6 | ||||
-rw-r--r-- | core/os/memory.cpp | 6 | ||||
-rw-r--r-- | core/os/memory.h | 86 | ||||
-rw-r--r-- | core/os/memory_pool_dynamic.h | 8 | ||||
-rw-r--r-- | core/os/memory_pool_dynamic_static.cpp | 84 | ||||
-rw-r--r-- | core/os/memory_pool_dynamic_static.h | 16 | ||||
-rw-r--r-- | core/os/memory_pool_static.cpp | 4 | ||||
-rw-r--r-- | core/os/memory_pool_static.h | 8 | ||||
-rw-r--r-- | core/os/mutex.cpp | 6 | ||||
-rw-r--r-- | core/os/mutex.h | 8 | ||||
-rw-r--r-- | core/os/os.h | 32 | ||||
-rw-r--r-- | core/os/semaphore.h | 8 | ||||
-rw-r--r-- | core/os/shell.h | 2 | ||||
-rw-r--r-- | core/os/thread.cpp | 10 | ||||
-rw-r--r-- | core/os/thread.h | 18 | ||||
-rw-r--r-- | core/os/thread_safe.cpp | 14 | ||||
-rw-r--r-- | core/os/thread_safe.h | 6 |
26 files changed, 272 insertions, 272 deletions
diff --git a/core/os/copymem.cpp b/core/os/copymem.cpp index 234ca50b45..49f53f1a51 100644 --- a/core/os/copymem.cpp +++ b/core/os/copymem.cpp @@ -32,7 +32,7 @@ void movemem_system(void *to, void *from,int amount) { - memmove(to,from,amount); + memmove(to,from,amount); } diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 32d66a7408..9a7135913a 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -344,7 +344,7 @@ DirAccess *DirAccess::open(const String& p_path,Error *r_error) { } DirAccess *DirAccess::create(AccessType p_access) { - + DirAccess * da = create_func[p_access]?create_func[p_access]():NULL; if (da) { da->_access_type=p_access; @@ -359,7 +359,7 @@ String DirAccess::get_full_path(const String& p_path,AccessType p_access) { DirAccess *d=DirAccess::create(p_access); if (!d) return p_path; - + d->change_dir(p_path); String full=d->get_current_dir(); memdelete(d); @@ -367,31 +367,31 @@ String DirAccess::get_full_path(const String& p_path,AccessType p_access) { } Error DirAccess::copy(String p_from,String p_to) { - + //printf("copy %s -> %s\n",p_from.ascii().get_data(),p_to.ascii().get_data()); Error err; FileAccess *fsrc = FileAccess::open(p_from, FileAccess::READ,&err); - + if (err) { ERR_FAIL_COND_V( err, err ); } - + FileAccess *fdst = FileAccess::open(p_to, FileAccess::WRITE,&err ); if (err) { - + fsrc->close(); memdelete( fsrc ); ERR_FAIL_COND_V( err, err ); } - + fsrc->seek_end(0); int size = fsrc->get_pos(); fsrc->seek(0); err = OK; while(size--) { - + if (fsrc->get_error()!=OK) { err= fsrc->get_error(); break; @@ -400,13 +400,13 @@ Error DirAccess::copy(String p_from,String p_to) { err= fdst->get_error(); break; } - + fdst->store_8( fsrc->get_8() ); } - + memdelete(fsrc); memdelete(fdst); - + return err; } diff --git a/core/os/dir_access.h b/core/os/dir_access.h index e97a065998..7a850ddc6d 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -79,13 +79,13 @@ public: virtual String get_next()=0; virtual bool current_is_dir() const=0; virtual bool current_is_hidden() const=0; - - virtual void list_dir_end()=0; ///< - + + virtual void list_dir_end()=0; ///< + virtual int get_drive_count()=0; virtual String get_drive(int p_drive)=0; virtual int get_current_drive(); - + virtual Error change_dir(String p_dir)=0; ///< can be relative or absolute, return false on success virtual String get_current_dir()=0; ///< return current dir location virtual Error make_dir(String p_dir)=0; @@ -100,7 +100,7 @@ public: virtual Error copy(String p_from,String p_to); virtual Error rename(String p_from, String p_to)=0; virtual Error remove(String p_name)=0; - + static String get_full_path(const String& p_path,AccessType p_access); static DirAccess *create_for_path(const String& p_path); @@ -111,7 +111,7 @@ public: FILE_TYPE_FILE, FILE_TYPE_DIR, }; - + //virtual DirType get_file_type() const=0; */ static DirAccess *create(AccessType p_access); diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 68c9dee84d..0846ef3eb0 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -169,69 +169,69 @@ String FileAccess::fix_path(const String& p_path) const { return r_path; } break; } - + return r_path; } /* these are all implemented for ease of porting, then can later be optimized */ uint16_t FileAccess::get_16()const { - + uint16_t res; uint8_t a,b; - + a=get_8(); b=get_8(); - + if (endian_swap) { - + SWAP( a,b ); } - + res=b; res<<=8; res|=a; - + return res; } uint32_t FileAccess::get_32() const{ - + uint32_t res; uint16_t a,b; - + a=get_16(); b=get_16(); - + if (endian_swap) { - + SWAP( a,b ); } - + res=b; res<<=16; res|=a; - - return res; + + return res; } uint64_t FileAccess::get_64()const { - + uint64_t res; uint32_t a,b; - + a=get_32(); b=get_32(); - + if (endian_swap) { - + SWAP( a,b ); } - + res=b; res<<=32; res|=a; - - return res; - + + return res; + } float FileAccess::get_float() const { @@ -262,15 +262,15 @@ String FileAccess::get_line() const { CharString line; CharType c=get_8(); - + while(!eof_reached()) { - + if (c=='\n' || c=='\0') { line.push_back(0); return String::utf8(line.get_data()); } else if (c!='\r') line.push_back(c); - + c=get_8(); } line.push_back(0); @@ -331,7 +331,7 @@ Vector<String> FileAccess::get_csv_line(String 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++) p_dst[i]=get_8(); @@ -340,53 +340,53 @@ int FileAccess::get_buffer(uint8_t *p_dst,int p_length) const{ } void FileAccess::store_16(uint16_t p_dest) { - + uint8_t a,b; - + a=p_dest&0xFF; b=p_dest>>8; - + if (endian_swap) { - + SWAP( a,b ); } - + store_8(a); store_8(b); } void FileAccess::store_32(uint32_t p_dest) { - - + + uint16_t a,b; - + a=p_dest&0xFFFF; b=p_dest>>16; - + if (endian_swap) { - + SWAP( a,b ); } - + store_16(a); store_16(b); - + } void FileAccess::store_64(uint64_t p_dest) { - + uint32_t a,b; - + a=p_dest&0xFFFFFFFF; b=p_dest>>32; - + if (endian_swap) { - + SWAP( a,b ); } - + store_32(a); store_32(b); - + } void FileAccess::store_real(real_t p_real) { @@ -461,7 +461,7 @@ void FileAccess::store_line(const String& p_line) { } void FileAccess::store_buffer(const uint8_t *p_src,int p_length) { - + for (int i=0;i<p_length;i++) store_8(p_src[i]); } diff --git a/core/os/file_access.h b/core/os/file_access.h index 3249e21ffb..2c894c94eb 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -80,21 +80,21 @@ public: READ_WRITE=3, WRITE_READ=7, }; - - virtual void close()=0; ///< close a file - virtual bool is_open() const=0; ///< true when file is open - virtual void seek(size_t p_position)=0; ///< seek to a given position - virtual void seek_end(int64_t p_position=0)=0; ///< seek from the end of file - virtual size_t get_pos() const=0; ///< get position in the file - virtual size_t get_len() const=0; ///< get size of the file + virtual void close()=0; ///< close a file + virtual bool is_open() const=0; ///< true when file is open - virtual bool eof_reached() const=0; ///< reading passed EOF + virtual void seek(size_t p_position)=0; ///< seek to a given position + virtual void seek_end(int64_t p_position=0)=0; ///< seek from the end of file + virtual size_t get_pos() const=0; ///< get position in the file + virtual size_t get_len() const=0; ///< get size of the file - virtual uint8_t get_8() const=0; ///< get a byte - virtual uint16_t get_16() const; ///< get 16 bits uint - virtual uint32_t get_32() const; ///< get 32 bits uint - virtual uint64_t get_64() const; ///< get 64 bits uint + virtual bool eof_reached() const=0; ///< reading passed EOF + + virtual uint8_t get_8() const=0; ///< get a byte + virtual uint16_t get_16() const; ///< get 16 bits uint + virtual uint32_t get_32() const; ///< get 32 bits uint + virtual uint64_t get_64() const; ///< get 64 bits uint virtual float get_float() const; virtual double get_double() const; @@ -103,21 +103,21 @@ public: virtual int get_buffer(uint8_t *p_dst,int p_length) const; ///< get an array of bytes virtual String get_line() const; virtual Vector<String> get_csv_line(String delim=",") const; - + /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac) * It's not about the current CPU type but file formats. * this flags get reset to false (little endian) on each open */ - + virtual void set_endian_swap(bool p_swap) { endian_swap=p_swap; } inline bool get_endian_swap() const { return endian_swap; } - virtual Error get_error() const=0; ///< get last error + virtual Error get_error() const=0; ///< get last error - virtual void store_8(uint8_t p_dest)=0; ///< store a byte - virtual void store_16(uint16_t p_dest); ///< store 16 bits uint - virtual void store_32(uint32_t p_dest); ///< store 32 bits uint - virtual void store_64(uint64_t p_dest); ///< store 64 bits uint + virtual void store_8(uint8_t p_dest)=0; ///< store a byte + virtual void store_16(uint16_t p_dest); ///< store 16 bits uint + virtual void store_32(uint32_t p_dest); ///< store 32 bits uint + virtual void store_64(uint64_t p_dest); ///< store 64 bits uint virtual void store_float(float p_dest); virtual void store_double(double p_dest); @@ -129,9 +129,9 @@ public: virtual void store_pascal_string(const String& p_string); virtual String get_pascal_string(); - virtual void store_buffer(const uint8_t *p_src,int p_length); ///< store an array of bytes - - virtual bool file_exists(const String& p_name)=0; ///< return true if a file exists + virtual void store_buffer(const uint8_t *p_src,int p_length); ///< store an array of bytes + + virtual bool file_exists(const String& p_name)=0; ///< return true if a file exists virtual Error reopen(const String& p_path, int p_mode_flags); ///< does not change the AccessType diff --git a/core/os/input.h b/core/os/input.h index 2dd4496f26..535776f39c 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -55,7 +55,7 @@ public: static Input *get_singleton(); - virtual bool is_key_pressed(int p_scancode)=0; + virtual bool is_key_pressed(int p_scancode)=0; virtual bool is_mouse_button_pressed(int p_button)=0; virtual bool is_joy_button_pressed(int p_device, int p_button)=0; virtual bool is_action_pressed(const StringName& p_action)=0; diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 3022a56e2a..2d47645a66 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -30,7 +30,7 @@ #include "input_map.h" #include "os/keyboard.h" /** - * + * */ bool InputEvent::operator==(const InputEvent &p_event) const { @@ -40,15 +40,15 @@ bool InputEvent::operator==(const InputEvent &p_event) const { InputEvent::operator String() const { String str="Device "+itos(device)+" ID "+itos(ID)+" "; - + switch(type) { - + case NONE: { - + return "Event: None"; } break; case KEY: { - + str+= "Event: Key "; str=str+"Unicode: "+String::chr(key.unicode)+" Scan: "+itos( key.scancode )+" Echo: "+String(key.echo?"True":"False")+" Pressed"+String(key.pressed?"True":"False")+" Mod: "; if (key.mod.shift) @@ -59,15 +59,15 @@ InputEvent::operator String() const { str+="A"; if (key.mod.meta) str+="M"; - + return str; } break; case MOUSE_MOTION: { - + str+= "Event: Motion "; str=str+" Pos: " +itos(mouse_motion.x)+","+itos(mouse_motion.y)+" Rel: "+itos(mouse_motion.relative_x)+","+itos(mouse_motion.relative_y)+" Mask: "; for (int i=0;i<8;i++) { - + if ((1<<i)&mouse_motion.button_mask) str+=itos(i+1); } @@ -87,7 +87,7 @@ InputEvent::operator String() const { str+= "Event: Button "; str=str+"Pressed: "+itos(mouse_button.pressed)+" Pos: " +itos(mouse_button.x)+","+itos(mouse_button.y)+" Button: "+itos(mouse_button.button_index)+" Mask: "; for (int i=0;i<8;i++) { - + if ((1<<i)&mouse_button.button_mask) str+=itos(i+1); } @@ -102,9 +102,9 @@ InputEvent::operator String() const { str+="M"; str+=String(" DoubleClick: ")+(mouse_button.doubleclick?"Yes":"No"); - + return str; - + } break; case JOYSTICK_MOTION: { str+= "Event: JoystickMotion "; @@ -137,7 +137,7 @@ InputEvent::operator String() const { } break; } - + return ""; } diff --git a/core/os/input_event.h b/core/os/input_event.h index 36c1556524..0588374790 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -189,7 +189,7 @@ struct InputModifierState { struct InputEventKey { InputModifierState mod; - + bool pressed; /// otherwise release uint32_t scancode; ///< check keyboard.h , KeyCode enum, without modifier masks @@ -212,11 +212,11 @@ struct InputEventMouse { struct InputEventMouseButton : public InputEventMouse { - + int button_index; bool pressed; //otherwise released bool doubleclick; //last even less than doubleclick time - + }; struct InputEventMouseMotion : public InputEventMouse { diff --git a/core/os/keyboard.h b/core/os/keyboard.h index 0848f8c28e..80472acc09 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -121,7 +121,7 @@ enum KeyList { KEY_DIRECTION_R=SPKEY | 0x33, KEY_BACK=SPKEY | 0x40, KEY_FORWARD=SPKEY | 0x41, - KEY_STOP=SPKEY | 0x42, + KEY_STOP=SPKEY | 0x42, KEY_REFRESH=SPKEY | 0x43, KEY_VOLUMEDOWN=SPKEY | 0x44, KEY_VOLUMEMUTE=SPKEY | 0x45, @@ -159,11 +159,11 @@ enum KeyList { KEY_LAUNCHD=SPKEY | 0x65, KEY_LAUNCHE=SPKEY | 0x66, KEY_LAUNCHF=SPKEY | 0x67, - + KEY_UNKNOWN=SPKEY | 0xFFFFFF, - + /* PRINTABLE LATIN 1 CODES */ - + KEY_SPACE=0x0020, KEY_EXCLAM=0x0021, KEY_QUOTEDBL=0x0022, @@ -297,18 +297,18 @@ enum KeyList { KEY_YACUTE=0x00DD, KEY_THORN=0x00DE, KEY_SSHARP=0x00DF, - + KEY_DIVISION=0x00F7, KEY_YDIAERESIS=0x00FF, - - + + }; enum KeyModifierMask { - + KEY_CODE_MASK=((1<<25)-1), ///< Apply this mask to any keycode to remove modifiers. - KEY_MODIFIER_MASK=(0xFF<<24), ///< Apply this mask to isolate modifiers. + KEY_MODIFIER_MASK=(0xFF<<24), ///< Apply this mask to isolate modifiers. KEY_MASK_SHIFT = (1<<25), KEY_MASK_ALT = (1<<26), KEY_MASK_META = (1<<27), @@ -322,7 +322,7 @@ enum KeyModifierMask { KEY_MASK_KPAD = (1<<29), KEY_MASK_GROUP_SWITCH = (1<<30) // bit 31 can't be used because variant uses regular 32 bits int as datatype - + }; String keycode_get_string(uint32_t p_code); diff --git a/core/os/main_loop.h b/core/os/main_loop.h index 059624dbe4..a34014983e 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -36,7 +36,7 @@ @author Juan Linietsky <reduzio@gmail.com> */ class MainLoop : public Object { - + OBJ_TYPE( MainLoop, Object ); OBJ_CATEGORY("Main Loop"); @@ -44,7 +44,7 @@ class MainLoop : public Object { protected: static void _bind_methods(); -public: +public: enum { NOTIFICATION_WM_MOUSE_ENTER = 3, @@ -55,7 +55,7 @@ public: NOTIFICATION_WM_UNFOCUS_REQUEST = 8, NOTIFICATION_OS_MEMORY_WARNING = 9, }; - + virtual void input_event( const InputEvent& p_event ); virtual void input_text( const String& p_text ); diff --git a/core/os/memory.cpp b/core/os/memory.cpp index f7f8fef2b7..c2ff2aa781 100644 --- a/core/os/memory.cpp +++ b/core/os/memory.cpp @@ -88,16 +88,16 @@ void Memory::dump_static_mem_to_file(const char* p_file) { MID Memory::alloc_dynamic(size_t p_bytes, const char *p_descr) { MemoryPoolDynamic::ID id = MemoryPoolDynamic::get_singleton()->alloc(p_bytes,p_descr); - + return MID(id); } Error Memory::realloc_dynamic(MID p_mid,size_t p_bytes) { MemoryPoolDynamic::ID id = p_mid.data?p_mid.data->id:MemoryPoolDynamic::INVALID_ID; - + if (id==MemoryPoolDynamic::INVALID_ID) return ERR_INVALID_PARAMETER; - + return MemoryPoolDynamic::get_singleton()->realloc(p_mid, p_bytes); } diff --git a/core/os/memory.h b/core/os/memory.h index 8eb5ceccb6..8257e66851 100644 --- a/core/os/memory.h +++ b/core/os/memory.h @@ -42,61 +42,61 @@ class MID { struct Data { - + SafeRefCount refcount; MemoryPoolDynamic::ID id; }; mutable Data *data; - + void unref() { - + if (!data) return; if (data->refcount.unref()) { - + if (data->id!=MemoryPoolDynamic::INVALID_ID) - MemoryPoolDynamic::get_singleton()->free(data->id); - MemoryPoolStatic::get_singleton()->free(data); + MemoryPoolDynamic::get_singleton()->free(data->id); + MemoryPoolStatic::get_singleton()->free(data); } - + data=NULL; } - + void ref(Data *p_data) { - + if (data==p_data) return; unref(); - + if (p_data && p_data->refcount.ref()) - data=p_data; + data=p_data; } - + friend class MID_Lock; inline void lock() { - + if (data && data->id!=MemoryPoolDynamic::INVALID_ID) MemoryPoolDynamic::get_singleton()->lock(data->id); } inline void unlock() { - + if (data && data->id!=MemoryPoolDynamic::INVALID_ID) MemoryPoolDynamic::get_singleton()->unlock(data->id); - + } - + inline void * get() { - + if (data && data->id!=MemoryPoolDynamic::INVALID_ID) return MemoryPoolDynamic::get_singleton()->get(data->id); - + return NULL; } - - Error _resize(size_t p_size) { - + + Error _resize(size_t p_size) { + if (p_size==0 && (!data || data->id==MemoryPoolDynamic::INVALID_ID)) return OK; if (p_size && !data) { @@ -104,46 +104,46 @@ friend class MID_Lock; data = (Data*)MemoryPoolStatic::get_singleton()->alloc(sizeof(Data),"MID::Data"); ERR_FAIL_COND_V( !data,ERR_OUT_OF_MEMORY ); data->refcount.init(); - data->id=MemoryPoolDynamic::INVALID_ID; + data->id=MemoryPoolDynamic::INVALID_ID; } - + if (p_size==0 && data && data->id==MemoryPoolDynamic::INVALID_ID) { - + MemoryPoolDynamic::get_singleton()->free(data->id); data->id=MemoryPoolDynamic::INVALID_ID; } - + if (p_size>0) { - + if (data->id==MemoryPoolDynamic::INVALID_ID) { - + data->id=MemoryPoolDynamic::get_singleton()->alloc(p_size,"Unnamed MID"); ERR_FAIL_COND_V( data->id==MemoryPoolDynamic::INVALID_ID, ERR_OUT_OF_MEMORY ); } else { - + MemoryPoolDynamic::get_singleton()->realloc(data->id,p_size); ERR_FAIL_COND_V( data->id==MemoryPoolDynamic::INVALID_ID, ERR_OUT_OF_MEMORY ); - + } - } - + } + return OK; } friend class Memory; - + MID(MemoryPoolDynamic::ID p_id) { - + data = (Data*)MemoryPoolStatic::get_singleton()->alloc(sizeof(Data),"MID::Data"); data->refcount.init(); data->id=p_id; } -public: +public: bool is_valid() const { return data; } operator bool() const { return data; } - - + + size_t get_size() const { return (data && data->id!=MemoryPoolDynamic::INVALID_ID) ? MemoryPoolDynamic::get_singleton()->get_size(data->id) : 0; } Error resize(size_t p_size) { return _resize(p_size); } inline void operator=(const MID& p_mid) { ref( p_mid.data ); } @@ -157,7 +157,7 @@ public: class MID_Lock { MID mid; - + public: void *data() { return mid.get(); } @@ -174,21 +174,21 @@ class Memory{ Memory(); public: - + static void * alloc_static(size_t p_bytes,const char *p_descr=""); static void * realloc_static(void *p_memory,size_t p_bytes); static void free_static(void *p_ptr); static size_t get_static_mem_available(); - static size_t get_static_mem_usage(); + static size_t get_static_mem_usage(); static size_t get_static_mem_max_usage(); static void dump_static_mem_to_file(const char* p_file); static MID alloc_dynamic(size_t p_bytes, const char *p_descr=""); static Error realloc_dynamic(MID p_mid,size_t p_bytes); - + static size_t get_dynamic_mem_available(); static size_t get_dynamic_mem_usage(); - + }; template<class T> @@ -241,7 +241,7 @@ _ALWAYS_INLINE_ void postinitialize_handler(void *) {} template<class T> _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) { - + postinitialize_handler(p_obj); return p_obj; } @@ -272,7 +272,7 @@ _ALWAYS_INLINE_ bool predelete_handler(void *) { return true; } template<class T> void memdelete(T *p_class) { - + if (!predelete_handler(p_class)) return; // doesn't want to be deleted p_class->~T(); diff --git a/core/os/memory_pool_dynamic.h b/core/os/memory_pool_dynamic.h index 82149bcf5d..70752fb10d 100644 --- a/core/os/memory_pool_dynamic.h +++ b/core/os/memory_pool_dynamic.h @@ -40,10 +40,10 @@ friend class Memory; friend class MID; enum { - + INVALID_ID=0xFFFFFFFF }; - + static MemoryPoolDynamic* get_singleton(); typedef uint64_t ID; @@ -55,12 +55,12 @@ friend class MID; virtual bool is_valid(ID p_id)=0; virtual size_t get_size(ID p_id) const=0; virtual const char* get_description(ID p_id) const=0; - + virtual Error lock(ID p_id)=0; virtual void * get(ID p_ID)=0; virtual Error unlock(ID p_id)=0; virtual bool is_locked(ID p_id) const=0; - + virtual size_t get_available_mem() const=0; virtual size_t get_total_usage() const=0; diff --git a/core/os/memory_pool_dynamic_static.cpp b/core/os/memory_pool_dynamic_static.cpp index 894066708e..c047c931ec 100644 --- a/core/os/memory_pool_dynamic_static.cpp +++ b/core/os/memory_pool_dynamic_static.cpp @@ -37,10 +37,10 @@ MemoryPoolDynamicStatic::Chunk *MemoryPoolDynamicStatic::get_chunk(ID p_id) { uint64_t check = p_id/MAX_CHUNKS; uint64_t idx = p_id%MAX_CHUNKS; - + if (!chunk[idx].mem || chunk[idx].check!=check) return NULL; - + return &chunk[idx]; } @@ -49,32 +49,32 @@ const MemoryPoolDynamicStatic::Chunk *MemoryPoolDynamicStatic::get_chunk(ID p_id uint64_t check = p_id/MAX_CHUNKS; uint64_t idx = p_id%MAX_CHUNKS; - + if (!chunk[idx].mem || chunk[idx].check!=check) return NULL; - + return &chunk[idx]; } MemoryPoolDynamic::ID MemoryPoolDynamicStatic::alloc(size_t p_amount,const char* p_description) { _THREAD_SAFE_METHOD_ - + int idx=-1; - + for (int i=0;i<MAX_CHUNKS;i++) { - + last_alloc++; if (last_alloc>=MAX_CHUNKS) last_alloc=0; - + if ( !chunk[last_alloc].mem ) { - + idx=last_alloc; break; } } - + if (idx==-1) { ERR_EXPLAIN("Out of dynamic Memory IDs"); @@ -86,36 +86,36 @@ MemoryPoolDynamic::ID MemoryPoolDynamicStatic::alloc(size_t p_amount,const char* chunk[idx].mem = memalloc(p_amount); if (!chunk[idx].mem) return INVALID_ID; - + chunk[idx].size=p_amount; chunk[idx].check=++last_check; chunk[idx].descr=p_description; chunk[idx].lock=0; - + total_usage+=p_amount; if (total_usage>max_usage) max_usage=total_usage; - + ID id = chunk[idx].check*MAX_CHUNKS + (uint64_t)idx; - + return id; - + } void MemoryPoolDynamicStatic::free(ID p_id) { _THREAD_SAFE_METHOD_ - + Chunk *c = get_chunk(p_id); ERR_FAIL_COND(!c); - - + + total_usage-=c->size; memfree(c->mem); c->mem=0; - + if (c->lock>0) { - + ERR_PRINT("Freed ID Still locked"); } } @@ -123,14 +123,14 @@ void MemoryPoolDynamicStatic::free(ID p_id) { Error MemoryPoolDynamicStatic::realloc(ID p_id, size_t p_amount) { _THREAD_SAFE_METHOD_ - + Chunk *c = get_chunk(p_id); ERR_FAIL_COND_V(!c,ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(c->lock > 0 , ERR_LOCKED ); - - + + void * new_mem = memrealloc(c->mem,p_amount); - + ERR_FAIL_COND_V(!new_mem,ERR_OUT_OF_MEMORY); total_usage-=c->size; c->mem=new_mem; @@ -138,37 +138,37 @@ Error MemoryPoolDynamicStatic::realloc(ID p_id, size_t p_amount) { total_usage+=c->size; if (total_usage>max_usage) max_usage=total_usage; - + return OK; } bool MemoryPoolDynamicStatic::is_valid(ID p_id) { _THREAD_SAFE_METHOD_ - + Chunk *c = get_chunk(p_id); - + return c!=NULL; } size_t MemoryPoolDynamicStatic::get_size(ID p_id) const { _THREAD_SAFE_METHOD_ - + const Chunk *c = get_chunk(p_id); ERR_FAIL_COND_V(!c,0); - + return c->size; - + } const char* MemoryPoolDynamicStatic::get_description(ID p_id) const { _THREAD_SAFE_METHOD_ - + const Chunk *c = get_chunk(p_id); ERR_FAIL_COND_V(!c,""); - + return c->descr; } @@ -177,10 +177,10 @@ const char* MemoryPoolDynamicStatic::get_description(ID p_id) const { bool MemoryPoolDynamicStatic::is_locked(ID p_id) const { _THREAD_SAFE_METHOD_ - + const Chunk *c = get_chunk(p_id); ERR_FAIL_COND_V(!c,false); - + return c->lock>0; } @@ -188,10 +188,10 @@ bool MemoryPoolDynamicStatic::is_locked(ID p_id) const { Error MemoryPoolDynamicStatic::lock(ID p_id) { _THREAD_SAFE_METHOD_ - + Chunk *c = get_chunk(p_id); ERR_FAIL_COND_V(!c,ERR_INVALID_PARAMETER); - + c->lock++; return OK; @@ -199,23 +199,23 @@ Error MemoryPoolDynamicStatic::lock(ID p_id) { void * MemoryPoolDynamicStatic::get(ID p_id) { _THREAD_SAFE_METHOD_ - + const Chunk *c = get_chunk(p_id); ERR_FAIL_COND_V(!c,NULL); ERR_FAIL_COND_V( c->lock==0, NULL ); - + return c->mem; } Error MemoryPoolDynamicStatic::unlock(ID p_id) { _THREAD_SAFE_METHOD_ - + Chunk *c = get_chunk(p_id); ERR_FAIL_COND_V(!c,ERR_INVALID_PARAMETER); - + ERR_FAIL_COND_V( c->lock<=0, ERR_INVALID_PARAMETER ); c->lock--; - + return OK; } @@ -226,7 +226,7 @@ size_t MemoryPoolDynamicStatic::get_available_mem() const { size_t MemoryPoolDynamicStatic::get_total_usage() const { _THREAD_SAFE_METHOD_ - + return total_usage; } diff --git a/core/os/memory_pool_dynamic_static.h b/core/os/memory_pool_dynamic_static.h index 6177c78de7..a72d39355c 100644 --- a/core/os/memory_pool_dynamic_static.h +++ b/core/os/memory_pool_dynamic_static.h @@ -40,19 +40,19 @@ class MemoryPoolDynamicStatic : public MemoryPoolDynamic { enum { MAX_CHUNKS=65536 }; - - + + struct Chunk { - + uint64_t lock; uint64_t check; void *mem; size_t size; - const char *descr; - + const char *descr; + Chunk() { mem=NULL; lock=0; check=0; } }; - + Chunk chunk[MAX_CHUNKS]; uint64_t last_check; int last_alloc; @@ -62,14 +62,14 @@ class MemoryPoolDynamicStatic : public MemoryPoolDynamic { Chunk *get_chunk(ID p_id); const Chunk *get_chunk(ID p_id) const; public: - + virtual ID alloc(size_t p_amount,const char* p_description); virtual void free(ID p_id); virtual Error realloc(ID p_id, size_t p_amount); virtual bool is_valid(ID p_id); virtual size_t get_size(ID p_id) const; virtual const char* get_description(ID p_id) const; - + virtual bool is_locked(ID p_id) const; virtual Error lock(ID p_id); virtual void * get(ID p_ID); diff --git a/core/os/memory_pool_static.cpp b/core/os/memory_pool_static.cpp index 321f4d989e..88c2ba3b3e 100644 --- a/core/os/memory_pool_static.cpp +++ b/core/os/memory_pool_static.cpp @@ -31,13 +31,13 @@ MemoryPoolStatic *MemoryPoolStatic::singleton=0; MemoryPoolStatic *MemoryPoolStatic::get_singleton() { - + return singleton; } MemoryPoolStatic::MemoryPoolStatic() { - + singleton=this; } diff --git a/core/os/memory_pool_static.h b/core/os/memory_pool_static.h index 2e11b7ded4..f7f60b8df8 100644 --- a/core/os/memory_pool_static.h +++ b/core/os/memory_pool_static.h @@ -38,17 +38,17 @@ */ class MemoryPoolStatic { private: - + static MemoryPoolStatic *singleton; public: - + static MemoryPoolStatic *get_singleton(); - + virtual void* alloc(size_t p_bytes,const char *p_description)=0; ///< Pointer in p_description shold be to a const char const like "hello" virtual void* realloc(void * p_memory,size_t p_bytes)=0; ///< Pointer in p_description shold be to a const char const like "hello" virtual void free(void *p_ptr)=0; ///< Pointer in p_description shold be to a const char const - + virtual size_t get_available_mem() const=0; virtual size_t get_total_usage()=0; virtual size_t get_max_usage()=0; diff --git a/core/os/mutex.cpp b/core/os/mutex.cpp index 9b379009b9..21400d2ccf 100644 --- a/core/os/mutex.cpp +++ b/core/os/mutex.cpp @@ -50,13 +50,13 @@ Mutex::~Mutex() { Mutex *_global_mutex=NULL;; void _global_lock() { - + if (_global_mutex) _global_mutex->lock(); } void _global_unlock() { - + if (_global_mutex) - _global_mutex->unlock(); + _global_mutex->unlock(); } diff --git a/core/os/mutex.h b/core/os/mutex.h index f16375aa26..5870171dc7 100644 --- a/core/os/mutex.h +++ b/core/os/mutex.h @@ -33,7 +33,7 @@ /** - * @class Mutex + * @class Mutex * @author Juan Linietsky * Portable Mutex (thread-safe locking) implementation. * Mutexes are always recursive ( they don't self-lock in a single thread ). @@ -43,9 +43,9 @@ class Mutex { -protected: +protected: static Mutex* (*create_func)(bool); - + public: virtual void lock()=0; ///< Lock the mutex, block if locked by someone else @@ -53,7 +53,7 @@ public: virtual Error try_lock()=0; ///< Attempt to lock the mutex, OK on success, ERROR means it can't lock. static Mutex * create(bool p_recursive=true); ///< Create a mutex - + virtual ~Mutex(); }; diff --git a/core/os/os.h b/core/os/os.h index a80b81bfa2..65ce44465b 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -71,7 +71,7 @@ public: RENDER_SEPARATE_THREAD }; struct VideoMode { - + int width,height; bool fullscreen; bool resizable; @@ -80,33 +80,33 @@ public: }; protected: friend class Main; - + RenderThreadMode _render_thread_mode; // functions used by main to initialize/deintialize the OS virtual int get_video_driver_count() const=0; virtual const char * get_video_driver_name(int p_driver) const=0; - + virtual VideoMode get_default_video_mode() const=0; - + virtual int get_audio_driver_count() const=0; virtual const char * get_audio_driver_name(int p_driver) const=0; - + virtual void initialize_core()=0; virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver)=0; - - virtual void set_main_loop( MainLoop * p_main_loop )=0; + + virtual void set_main_loop( MainLoop * p_main_loop )=0; virtual void delete_main_loop()=0; - + virtual void finalize()=0; virtual void finalize_core()=0; virtual void set_cmdline(const char* p_execpath, const List<String>& p_args); void _ensure_data_dir(); - + public: - + typedef int64_t ProcessID; static OS* get_singleton(); @@ -148,7 +148,7 @@ public: virtual void set_clipboard(const String& p_text); virtual String get_clipboard() const; - + virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0)=0; virtual VideoMode get_video_mode(int p_screen=0) const=0; virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const=0; @@ -219,7 +219,7 @@ public: DAY_FRIDAY, DAY_SATURDAY }; - + enum Month { MONTH_JANUARY, MONTH_FEBRUARY, @@ -236,7 +236,7 @@ public: }; struct Date { - + int year; Month month; int day; @@ -245,7 +245,7 @@ public: }; struct Time { - + int hour; int min; int sec; @@ -262,7 +262,7 @@ public: virtual uint64_t get_unix_time() const; virtual uint64_t get_system_time_secs() const; - virtual void delay_usec(uint32_t p_usec) const=0; + virtual void delay_usec(uint32_t p_usec) const=0; virtual uint64_t get_ticks_usec() const=0; uint32_t get_ticks_msec() const; uint64_t get_splash_tick_msec() const; @@ -412,7 +412,7 @@ public: virtual void set_context(int p_context); - OS(); + OS(); virtual ~OS(); }; diff --git a/core/os/semaphore.h b/core/os/semaphore.h index b65542ce35..8469408e65 100644 --- a/core/os/semaphore.h +++ b/core/os/semaphore.h @@ -35,17 +35,17 @@ @author Juan Linietsky <reduzio@gmail.com> */ class Semaphore { -protected: +protected: static Semaphore* (*create_func)(); - + public: virtual Error wait()=0; ///< wait until semaphore has positive value, then decrement and pass virtual Error post()=0; ///< unlock the semaphore, incrementing the value virtual int get() const=0; ///< get semaphore value - + static Semaphore * create(); ///< Create a mutex - + virtual ~Semaphore(); }; diff --git a/core/os/shell.h b/core/os/shell.h index 805dd70301..8b0c286d73 100644 --- a/core/os/shell.h +++ b/core/os/shell.h @@ -42,7 +42,7 @@ public: static Shell * get_singleton(); virtual void execute(String p_path)=0; - + Shell(); virtual ~Shell(); }; diff --git a/core/os/thread.cpp b/core/os/thread.cpp index f5d984876d..c1ae53074b 100644 --- a/core/os/thread.cpp +++ b/core/os/thread.cpp @@ -37,26 +37,26 @@ Error (*Thread::set_name_func)(const String&)=NULL; Thread::ID Thread::_main_thread_id=0; Thread::ID Thread::get_caller_ID() { - + if (get_thread_ID_func) return get_thread_ID_func(); return 0; } Thread* Thread::create(ThreadCreateCallback p_callback,void * p_user,const Settings& p_settings) { - + if (create_func) { - + return create_func(p_callback,p_user,p_settings); } return NULL; } void Thread::wait_to_finish(Thread *p_thread) { - + if (wait_to_finish_func) wait_to_finish_func(p_thread); - + } Error Thread::set_name(const String &p_name) { diff --git a/core/os/thread.h b/core/os/thread.h index 4fead72b94..7349b83dbc 100644 --- a/core/os/thread.h +++ b/core/os/thread.h @@ -41,25 +41,25 @@ typedef void (*ThreadCreateCallback)(void *p_userdata); class Thread { public: - + enum Priority { - + PRIORITY_LOW, PRIORITY_NORMAL, PRIORITY_HIGH }; - + struct Settings { - + Priority priority; Settings() { priority=PRIORITY_NORMAL; } }; - + typedef uint64_t ID; -protected: +protected: static Thread* (*create_func)(ThreadCreateCallback p_callback,void *,const Settings&); static ID (*get_thread_ID_func)(); static void (*wait_to_finish_func)(Thread*); @@ -72,7 +72,7 @@ protected: Thread(); public: - + virtual ID get_ID() const=0; @@ -81,8 +81,8 @@ public: static ID get_caller_ID(); ///< get the ID of the caller function ID static void wait_to_finish(Thread *p_thread); ///< waits until thread is finished, and deallocates it. static Thread * create(ThreadCreateCallback p_callback,void * p_user,const Settings& p_settings=Settings()); ///< Static function to create a thread, will call p_callback - - + + virtual ~Thread(); }; diff --git a/core/os/thread_safe.cpp b/core/os/thread_safe.cpp index f252190504..a742b1144e 100644 --- a/core/os/thread_safe.cpp +++ b/core/os/thread_safe.cpp @@ -30,17 +30,17 @@ #include "error_macros.h" #include "os/memory.h" -ThreadSafe::ThreadSafe() { +ThreadSafe::ThreadSafe() { - mutex = Mutex::create(); + mutex = Mutex::create(); if (!mutex) { - + WARN_PRINT("THREAD_SAFE defined, but no default mutex type"); } } -ThreadSafe::~ThreadSafe() { - - if (mutex) - memdelete( mutex ); +ThreadSafe::~ThreadSafe() { + + if (mutex) + memdelete( mutex ); } diff --git a/core/os/thread_safe.h b/core/os/thread_safe.h index 793dd88543..1c82cbe704 100644 --- a/core/os/thread_safe.h +++ b/core/os/thread_safe.h @@ -42,7 +42,7 @@ public: ThreadSafe(); ~ThreadSafe(); - + }; @@ -51,11 +51,11 @@ class ThreadSafeMethod { const ThreadSafe *_ts; public: ThreadSafeMethod(const ThreadSafe *p_ts) { - + _ts=p_ts; _ts->lock(); } - + ~ThreadSafeMethod() { _ts->unlock(); } }; |