A Whole New World (clang-format edition)

I can show you the code
Pretty, with proper whitespace
Tell me, coder, now when did
You last write readable code?

I can open your eyes
Make you see your bad indent
Force you to respect the style
The core devs agreed upon

A whole new world
A new fantastic code format
A de facto standard
With some sugar
Enforced with clang-format

A whole new world
A dazzling style we all dreamed of
And when we read it through
It's crystal clear
That now we're in a whole new world of code
This commit is contained in:
Rémi Verschelde
2017-03-05 16:44:50 +01:00
parent 45438e9918
commit 5dbf1809c6
1318 changed files with 140051 additions and 166004 deletions

View File

@ -33,9 +33,9 @@
#define PACK_VERSION 1
Error PackedData::add_pack(const String& p_path) {
Error PackedData::add_pack(const String &p_path) {
for (int i=0; i<sources.size(); i++) {
for (int i = 0; i < sources.size(); i++) {
if (sources[i]->try_open_pack(p_path)) {
@ -46,7 +46,7 @@ Error PackedData::add_pack(const String& p_path) {
return ERR_FILE_UNRECOGNIZED;
};
void PackedData::add_path(const String& pkg_path, const String& path, uint64_t ofs, uint64_t size,const uint8_t* p_md5, PackSource* p_src) {
void PackedData::add_path(const String &pkg_path, const String &path, uint64_t ofs, uint64_t size, const uint8_t *p_md5, PackSource *p_src) {
PathMD5 pmd5(path.md5_buffer());
//printf("adding path %ls, %lli, %lli\n", path.c_str(), pmd5.a, pmd5.b);
@ -54,35 +54,35 @@ void PackedData::add_path(const String& pkg_path, const String& path, uint64_t o
bool exists = files.has(pmd5);
PackedFile pf;
pf.pack=pkg_path;
pf.offset=ofs;
pf.size=size;
for(int i=0;i<16;i++)
pf.md5[i]=p_md5[i];
pf.pack = pkg_path;
pf.offset = ofs;
pf.size = size;
for (int i = 0; i < 16; i++)
pf.md5[i] = p_md5[i];
pf.src = p_src;
files[pmd5]=pf;
files[pmd5] = pf;
if (!exists) {
//search for dir
String p = path.replace_first("res://","");
PackedDir *cd=root;
String p = path.replace_first("res://", "");
PackedDir *cd = root;
if (p.find("/")!=-1) { //in a subdir
if (p.find("/") != -1) { //in a subdir
Vector<String> ds=p.get_base_dir().split("/");
Vector<String> ds = p.get_base_dir().split("/");
for(int j=0;j<ds.size();j++) {
for (int j = 0; j < ds.size(); j++) {
if (!cd->subdirs.has(ds[j])) {
PackedDir *pd = memnew( PackedDir );
pd->name=ds[j];
pd->parent=cd;
cd->subdirs[pd->name]=pd;
cd=pd;
PackedDir *pd = memnew(PackedDir);
pd->name = ds[j];
pd->parent = cd;
cd->subdirs[pd->name] = pd;
cd = pd;
} else {
cd=cd->subdirs[ds[j]];
cd = cd->subdirs[ds[j]];
}
}
}
@ -97,61 +97,59 @@ void PackedData::add_pack_source(PackSource *p_source) {
}
};
PackedData *PackedData::singleton=NULL;
PackedData *PackedData::singleton = NULL;
PackedData::PackedData() {
singleton=this;
root=memnew(PackedDir);
root->parent=NULL;
disabled=false;
singleton = this;
root = memnew(PackedDir);
root->parent = NULL;
disabled = false;
add_pack_source(memnew(PackedSourcePCK));
}
void PackedData::_free_packed_dirs(PackedDir *p_dir) {
for (Map<String,PackedDir*>::Element *E=p_dir->subdirs.front();E;E=E->next())
for (Map<String, PackedDir *>::Element *E = p_dir->subdirs.front(); E; E = E->next())
_free_packed_dirs(E->get());
memdelete(p_dir);
}
PackedData::~PackedData() {
for(int i=0;i<sources.size();i++) {
for (int i = 0; i < sources.size(); i++) {
memdelete(sources[i]);
}
_free_packed_dirs(root);
}
//////////////////////////////////////////////////////////////////
bool PackedSourcePCK::try_open_pack(const String& p_path) {
bool PackedSourcePCK::try_open_pack(const String &p_path) {
FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
if (!f)
return false;
//printf("try open %ls!\n", p_path.c_str());
uint32_t magic= f->get_32();
uint32_t magic = f->get_32();
if (magic != 0x43504447) {
//maybe at he end.... self contained exe
f->seek_end();
f->seek( f->get_pos() -4 );
f->seek(f->get_pos() - 4);
magic = f->get_32();
if (magic != 0x43504447) {
memdelete(f);
return false;
}
f->seek( f->get_pos() -12 );
f->seek(f->get_pos() - 12);
uint64_t ds = f->get_64();
f->seek( f->get_pos() -ds-8 );
f->seek(f->get_pos() - ds - 8);
magic = f->get_32();
if (magic != 0x43504447) {
@ -159,7 +157,6 @@ bool PackedSourcePCK::try_open_pack(const String& p_path) {
memdelete(f);
return false;
}
}
uint32_t version = f->get_32();
@ -167,25 +164,25 @@ bool PackedSourcePCK::try_open_pack(const String& p_path) {
uint32_t ver_minor = f->get_32();
uint32_t ver_rev = f->get_32();
ERR_EXPLAIN("Pack version unsupported: "+itos(version));
ERR_FAIL_COND_V( version != PACK_VERSION, ERR_INVALID_DATA);
ERR_EXPLAIN("Pack created with a newer version of the engine: "+itos(ver_major)+"."+itos(ver_minor)+"."+itos(ver_rev));
ERR_FAIL_COND_V( ver_major > VERSION_MAJOR || (ver_major == VERSION_MAJOR && ver_minor > VERSION_MINOR), ERR_INVALID_DATA);
ERR_EXPLAIN("Pack version unsupported: " + itos(version));
ERR_FAIL_COND_V(version != PACK_VERSION, ERR_INVALID_DATA);
ERR_EXPLAIN("Pack created with a newer version of the engine: " + itos(ver_major) + "." + itos(ver_minor) + "." + itos(ver_rev));
ERR_FAIL_COND_V(ver_major > VERSION_MAJOR || (ver_major == VERSION_MAJOR && ver_minor > VERSION_MINOR), ERR_INVALID_DATA);
for(int i=0;i<16;i++) {
for (int i = 0; i < 16; i++) {
//reserved
f->get_32();
}
int file_count = f->get_32();
for(int i=0;i<file_count;i++) {
for (int i = 0; i < file_count; i++) {
uint32_t sl = f->get_32();
CharString cs;
cs.resize(sl+1);
f->get_buffer((uint8_t*)cs.ptr(),sl);
cs[sl]=0;
cs.resize(sl + 1);
f->get_buffer((uint8_t *)cs.ptr(), sl);
cs[sl] = 0;
String path;
path.parse_utf8(cs.ptr());
@ -193,22 +190,21 @@ bool PackedSourcePCK::try_open_pack(const String& p_path) {
uint64_t ofs = f->get_64();
uint64_t size = f->get_64();
uint8_t md5[16];
f->get_buffer(md5,16);
PackedData::get_singleton()->add_path(p_path, path, ofs, size, md5,this);
f->get_buffer(md5, 16);
PackedData::get_singleton()->add_path(p_path, path, ofs, size, md5, this);
};
return true;
};
FileAccess* PackedSourcePCK::get_file(const String &p_path, PackedData::PackedFile* p_file) {
FileAccess *PackedSourcePCK::get_file(const String &p_path, PackedData::PackedFile *p_file) {
return memnew( FileAccessPack(p_path, *p_file));
return memnew(FileAccessPack(p_path, *p_file));
};
//////////////////////////////////////////////////////////////////
Error FileAccessPack::_open(const String& p_path, int p_mode_flags) {
Error FileAccessPack::_open(const String &p_path, int p_mode_flags) {
ERR_FAIL_V(ERR_UNAVAILABLE);
return ERR_UNAVAILABLE;
@ -219,45 +215,44 @@ void FileAccessPack::close() {
f->close();
}
bool FileAccessPack::is_open() const{
bool FileAccessPack::is_open() const {
return f->is_open();
}
void FileAccessPack::seek(size_t p_position){
void FileAccessPack::seek(size_t p_position) {
if (p_position>pf.size) {
eof=true;
if (p_position > pf.size) {
eof = true;
} else {
eof=false;
eof = false;
}
f->seek(pf.offset+p_position);
pos=p_position;
f->seek(pf.offset + p_position);
pos = p_position;
}
void FileAccessPack::seek_end(int64_t p_position){
seek(pf.size+p_position);
void FileAccessPack::seek_end(int64_t p_position) {
seek(pf.size + p_position);
}
size_t FileAccessPack::get_pos() const {
return pos;
}
size_t FileAccessPack::get_len() const{
size_t FileAccessPack::get_len() const {
return pf.size;
}
bool FileAccessPack::eof_reached() const{
bool FileAccessPack::eof_reached() const {
return eof;
}
uint8_t FileAccessPack::get_8() const {
if (pos>=pf.size) {
eof=true;
if (pos >= pf.size) {
eof = true;
return 0;
}
@ -265,23 +260,22 @@ uint8_t FileAccessPack::get_8() const {
return f->get_8();
}
int FileAccessPack::get_buffer(uint8_t *p_dst,int p_length) const {
int FileAccessPack::get_buffer(uint8_t *p_dst, int p_length) const {
if (eof)
return 0;
int64_t to_read=p_length;
if (to_read+pos > pf.size) {
eof=true;
to_read=int64_t(pf.size)-int64_t(pos);
int64_t to_read = p_length;
if (to_read + pos > pf.size) {
eof = true;
to_read = int64_t(pf.size) - int64_t(pos);
}
pos+=p_length;
pos += p_length;
if (to_read<=0)
if (to_read <= 0)
return 0;
f->get_buffer(p_dst,to_read);
f->get_buffer(p_dst, to_read);
return to_read;
}
@ -301,32 +295,29 @@ Error FileAccessPack::get_error() const {
void FileAccessPack::store_8(uint8_t p_dest) {
ERR_FAIL();
}
void FileAccessPack::store_buffer(const uint8_t *p_src,int p_length) {
void FileAccessPack::store_buffer(const uint8_t *p_src, int p_length) {
ERR_FAIL();
}
bool FileAccessPack::file_exists(const String& p_name) {
bool FileAccessPack::file_exists(const String &p_name) {
return false;
}
FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFile &p_file) {
FileAccessPack::FileAccessPack(const String& p_path, const PackedData::PackedFile& p_file) {
pf=p_file;
f=FileAccess::open(pf.pack,FileAccess::READ);
pf = p_file;
f = FileAccess::open(pf.pack, FileAccess::READ);
if (!f) {
ERR_EXPLAIN("Can't open pack-referenced file: "+String(pf.pack));
ERR_EXPLAIN("Can't open pack-referenced file: " + String(pf.pack));
ERR_FAIL_COND(!f);
}
f->seek(pf.offset);
pos=0;
eof=false;
pos = 0;
eof = false;
}
FileAccessPack::~FileAccessPack() {
@ -334,24 +325,21 @@ FileAccessPack::~FileAccessPack() {
memdelete(f);
}
//////////////////////////////////////////////////////////////////////////////////
// DIR ACCESS
//////////////////////////////////////////////////////////////////////////////////
Error DirAccessPack::list_dir_begin() {
list_dirs.clear();
list_files.clear();
for (Map<String,PackedData::PackedDir*>::Element *E=current->subdirs.front();E;E=E->next()) {
for (Map<String, PackedData::PackedDir *>::Element *E = current->subdirs.front(); E; E = E->next()) {
list_dirs.push_back(E->key());
}
for (Set<String>::Element *E=current->files.front();E;E=E->next()) {
for (Set<String>::Element *E = current->files.front(); E; E = E->next()) {
list_files.push_back(E->get());
}
@ -359,15 +347,15 @@ Error DirAccessPack::list_dir_begin() {
return OK;
}
String DirAccessPack::get_next(){
String DirAccessPack::get_next() {
if (list_dirs.size()) {
cdir=true;
cdir = true;
String d = list_dirs.front()->get();
list_dirs.pop_front();
return d;
} else if (list_files.size()) {
cdir=false;
cdir = false;
String f = list_files.front()->get();
list_files.pop_front();
return f;
@ -375,11 +363,11 @@ String DirAccessPack::get_next(){
return String();
}
}
bool DirAccessPack::current_is_dir() const{
bool DirAccessPack::current_is_dir() const {
return cdir;
}
bool DirAccessPack::current_is_hidden() const{
bool DirAccessPack::current_is_hidden() const {
return false;
}
@ -400,20 +388,20 @@ String DirAccessPack::get_drive(int p_drive) {
Error DirAccessPack::change_dir(String p_dir) {
String nd = p_dir.replace("\\","/");
bool absolute=false;
String nd = p_dir.replace("\\", "/");
bool absolute = false;
if (nd.begins_with("res://")) {
nd=nd.replace_first("res://","");
absolute=true;
nd = nd.replace_first("res://", "");
absolute = true;
}
nd=nd.simplify_path();
nd = nd.simplify_path();
if (nd == "") nd = ".";
if (nd.begins_with("/")) {
nd=nd.replace_first("/","") ;
absolute=true;
nd = nd.replace_first("/", "");
absolute = true;
}
Vector<String> paths = nd.split("/");
@ -425,18 +413,18 @@ Error DirAccessPack::change_dir(String p_dir) {
else
pd = current;
for(int i=0;i<paths.size();i++) {
for (int i = 0; i < paths.size(); i++) {
String p = paths[i];
if (p==".") {
if (p == ".") {
continue;
} else if (p=="..") {
} else if (p == "..") {
if (pd->parent) {
pd=pd->parent;
pd = pd->parent;
}
} else if (pd->subdirs.has(p)) {
pd=pd->subdirs[p];
pd = pd->subdirs[p];
} else {
@ -444,29 +432,26 @@ Error DirAccessPack::change_dir(String p_dir) {
}
}
current=pd;
current = pd;
return OK;
}
String DirAccessPack::get_current_dir() {
String p;
PackedData::PackedDir *pd = current;
while(pd->parent) {
while (pd->parent) {
if (pd!=current)
p="/"+p;
p=p+pd->name;
if (pd != current)
p = "/" + p;
p = p + pd->name;
}
return "res://"+p;
return "res://" + p;
}
bool DirAccessPack::file_exists(String p_file){
bool DirAccessPack::file_exists(String p_file) {
return current->files.has(p_file);
}
@ -476,36 +461,30 @@ bool DirAccessPack::dir_exists(String p_dir) {
return current->subdirs.has(p_dir);
}
Error DirAccessPack::make_dir(String p_dir){
Error DirAccessPack::make_dir(String p_dir) {
return ERR_UNAVAILABLE;
}
Error DirAccessPack::rename(String p_from, String p_to){
Error DirAccessPack::rename(String p_from, String p_to) {
return ERR_UNAVAILABLE;
}
Error DirAccessPack::remove(String p_name){
Error DirAccessPack::remove(String p_name) {
return ERR_UNAVAILABLE;
}
size_t DirAccessPack::get_space_left(){
size_t DirAccessPack::get_space_left() {
return 0;
}
DirAccessPack::DirAccessPack() {
current=PackedData::get_singleton()->root;
cdir=false;
current = PackedData::get_singleton()->root;
cdir = false;
}
DirAccessPack::~DirAccessPack() {
}