diff options
| author | Rémi Verschelde | 2017-03-05 16:44:50 +0100 |
|---|---|---|
| committer | Rémi Verschelde | 2017-03-05 16:44:50 +0100 |
| commit | 5dbf1809c6e3e905b94b8764e99491e608122261 (patch) | |
| tree | 5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /editor/io_plugins/editor_atlas.cpp | |
| parent | 45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff) | |
| download | godot-5dbf180.tar.gz godot-5dbf180.tar.zst godot-5dbf180.zip | |
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
Diffstat (limited to 'editor/io_plugins/editor_atlas.cpp')
| -rw-r--r-- | editor/io_plugins/editor_atlas.cpp | 92 |
1 files changed, 42 insertions, 50 deletions
diff --git a/editor/io_plugins/editor_atlas.cpp b/editor/io_plugins/editor_atlas.cpp index c5f1ee73c..1aa480f44 100644 --- a/editor/io_plugins/editor_atlas.cpp +++ b/editor/io_plugins/editor_atlas.cpp @@ -35,7 +35,7 @@ struct _EditorAtlasWorkRect { Size2i s; Point2i p; int idx; - _FORCE_INLINE_ bool operator<(const _EditorAtlasWorkRect& p_r) const { return s.width > p_r.s.width; }; + _FORCE_INLINE_ bool operator<(const _EditorAtlasWorkRect &p_r) const { return s.width > p_r.s.width; }; }; struct _EditorAtlasWorkRectResult { @@ -45,7 +45,7 @@ struct _EditorAtlasWorkRectResult { int max_h; }; -void EditorAtlas::fit(const Vector<Size2i>& p_rects,Vector<Point2i>& r_result, Size2i& r_size) { +void EditorAtlas::fit(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size) { //super simple, almost brute force scanline stacking fitter //it's pretty basic for now, but it tries to make sure that the aspect ratio of the @@ -55,106 +55,98 @@ void EditorAtlas::fit(const Vector<Size2i>& p_rects,Vector<Point2i>& r_result, S // for example, it will prioritize a 1024x1024 atlas (works everywhere) instead of a // 256x8192 atlas (won't work anywhere). - ERR_FAIL_COND(p_rects.size()==0); + ERR_FAIL_COND(p_rects.size() == 0); Vector<_EditorAtlasWorkRect> wrects; wrects.resize(p_rects.size()); - for(int i=0;i<p_rects.size();i++) { - wrects[i].s=p_rects[i]; - wrects[i].idx=i; + for (int i = 0; i < p_rects.size(); i++) { + wrects[i].s = p_rects[i]; + wrects[i].idx = i; } wrects.sort(); int widest = wrects[0].s.width; Vector<_EditorAtlasWorkRectResult> results; - for(int i=0;i<=12;i++) { + for (int i = 0; i <= 12; i++) { - int w = 1<<i; - int max_h=0; - int max_w=0; - if ( w < widest ) + int w = 1 << i; + int max_h = 0; + int max_w = 0; + if (w < widest) continue; Vector<int> hmax; hmax.resize(w); - for(int j=0;j<w;j++) - hmax[j]=0; + for (int j = 0; j < w; j++) + hmax[j] = 0; //place them - int ofs=0; + int ofs = 0; - for(int j=0;j<wrects.size();j++) { + for (int j = 0; j < wrects.size(); j++) { + if (ofs + wrects[j].s.width > w) { - if (ofs+wrects[j].s.width > w) { - - ofs=0; + ofs = 0; } - int from_y=0; - for(int k=0;k<wrects[j].s.width;k++) { + int from_y = 0; + for (int k = 0; k < wrects[j].s.width; k++) { - if (hmax[ofs+k] > from_y) - from_y=hmax[ofs+k]; + if (hmax[ofs + k] > from_y) + from_y = hmax[ofs + k]; } - wrects[j].p.x=ofs; - wrects[j].p.y=from_y; - + wrects[j].p.x = ofs; + wrects[j].p.y = from_y; + int end_h = from_y + wrects[j].s.height; + int end_w = ofs + wrects[j].s.width; - int end_h = from_y+wrects[j].s.height; - int end_w = ofs+wrects[j].s.width; + for (int k = 0; k < wrects[j].s.width; k++) { - for(int k=0;k<wrects[j].s.width;k++) { - - hmax[ofs+k]=end_h; + hmax[ofs + k] = end_h; } if (end_h > max_h) - max_h=end_h; + max_h = end_h; if (end_w > max_w) - max_w=end_w; - - ofs+=wrects[j].s.width; + max_w = end_w; + ofs += wrects[j].s.width; } _EditorAtlasWorkRectResult result; - result.result=wrects; - result.max_h=max_h; - result.max_w=max_w; + result.result = wrects; + result.max_h = max_h; + result.max_w = max_w; results.push_back(result); - } //find the result with the best aspect ratio - int best=-1; - float best_aspect=1e20; + int best = -1; + float best_aspect = 1e20; - for(int i=0;i<results.size();i++) { + for (int i = 0; i < results.size(); i++) { float h = results[i].max_h; float w = results[i].max_w; - float aspect = h>w ? h/w : w/h; + float aspect = h > w ? h / w : w / h; if (aspect < best_aspect) { - best=i; - best_aspect=aspect; + best = i; + best_aspect = aspect; } } r_result.resize(p_rects.size()); - for(int i=0;i<p_rects.size();i++) { + for (int i = 0; i < p_rects.size(); i++) { - r_result[ results[best].result[i].idx ]=results[best].result[i].p; + r_result[results[best].result[i].idx] = results[best].result[i].p; } - r_size=Size2(results[best].max_w,results[best].max_h ); - + r_size = Size2(results[best].max_w, results[best].max_h); } - - |
