1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-29 16:16:38 +00:00

Bring that Whole New World to the Old Continent too

Applies the clang-format style to the 2.1 branch as done for master in
5dbf1809c6.
This commit is contained in:
Rémi Verschelde
2017-03-19 00:36:26 +01:00
parent 1d418afe86
commit f8db8a3faa
1308 changed files with 147754 additions and 174357 deletions

View File

@@ -29,178 +29,166 @@
#include "bit_mask.h"
#include "io/image_loader.h"
void BitMap::create(const Size2& p_size) {
void BitMap::create(const Size2 &p_size) {
ERR_FAIL_COND(p_size.width<1);
ERR_FAIL_COND(p_size.height<1);
width=p_size.width;
height=p_size.height;
bitmask.resize(((width*height)/8)+1);
zeromem(bitmask.ptr(),bitmask.size());
ERR_FAIL_COND(p_size.width < 1);
ERR_FAIL_COND(p_size.height < 1);
width = p_size.width;
height = p_size.height;
bitmask.resize(((width * height) / 8) + 1);
zeromem(bitmask.ptr(), bitmask.size());
}
void BitMap::create_from_image_alpha(const Image& p_image){
void BitMap::create_from_image_alpha(const Image &p_image) {
ERR_FAIL_COND(p_image.empty());
Image img=p_image;
Image img = p_image;
img.convert(Image::FORMAT_INTENSITY);
ERR_FAIL_COND(img.get_format()!=Image::FORMAT_INTENSITY);
create(Size2(img.get_width(),img.get_height()));
ERR_FAIL_COND(img.get_format() != Image::FORMAT_INTENSITY);
create(Size2(img.get_width(), img.get_height()));
DVector<uint8_t>::Read r = img.get_data().read();
uint8_t *w = bitmask.ptr();
for(int i=0;i<width*height;i++) {
for (int i = 0; i < width * height; i++) {
int bbyte = i/8;
int bbyte = i / 8;
int bbit = i % 8;
if (r[i])
w[bbyte]|=(1<<bbit);
w[bbyte] |= (1 << bbit);
}
}
void BitMap::set_bit_rect(const Rect2 &p_rect, bool p_value) {
void BitMap::set_bit_rect(const Rect2& p_rect,bool p_value) {
Rect2i current = Rect2i(0,0,width,height).clip(p_rect);
Rect2i current = Rect2i(0, 0, width, height).clip(p_rect);
uint8_t *data = bitmask.ptr();
for(int i=current.pos.x;i<current.pos.x+current.size.x;i++) {
for(int j=current.pos.y;j<current.pos.y+current.size.y;j++) {
for (int i = current.pos.x; i < current.pos.x + current.size.x; i++) {
for (int j = current.pos.y; j < current.pos.y + current.size.y; j++) {
int ofs = width * j + i;
int bbyte = ofs/8;
int bbyte = ofs / 8;
int bbit = ofs % 8;
uint8_t b = data[bbyte];
if (p_value)
b|=(1<<bbit);
b |= (1 << bbit);
else
b&=!(1<<bbit);
data[bbyte]=b;
b &= !(1 << bbit);
data[bbyte] = b;
}
}
}
int BitMap::get_true_bit_count() const {
int ds = bitmask.size();
const uint8_t *d = bitmask.ptr();
int c=0;
int c = 0;
//fast, almot branchless version
//fast, almot branchless version
for(int i=0;i<ds;i++) {
for (int i = 0; i < ds; i++) {
c+=(d[i]&(1<<7))>>7;
c+=(d[i]&(1<<6))>>6;
c+=(d[i]&(1<<5))>>5;
c+=(d[i]&(1<<4))>>4;
c+=(d[i]&(1<<3))>>3;
c+=(d[i]&(1<<2))>>2;
c+=d[i]&1;
c += (d[i] & (1 << 7)) >> 7;
c += (d[i] & (1 << 6)) >> 6;
c += (d[i] & (1 << 5)) >> 5;
c += (d[i] & (1 << 4)) >> 4;
c += (d[i] & (1 << 3)) >> 3;
c += (d[i] & (1 << 2)) >> 2;
c += d[i] & 1;
}
return c;
}
void BitMap::set_bit(const Point2 &p_pos, bool p_value) {
void BitMap::set_bit(const Point2& p_pos,bool p_value){
int x = Math::fast_ftoi(p_pos.x);
int y = Math::fast_ftoi(p_pos.y);
int x=Math::fast_ftoi(p_pos.x);
int y=Math::fast_ftoi(p_pos.y);
ERR_FAIL_INDEX(x,width);
ERR_FAIL_INDEX(y,height);
ERR_FAIL_INDEX(x, width);
ERR_FAIL_INDEX(y, height);
int ofs = width * y + x;
int bbyte = ofs/8;
int bbyte = ofs / 8;
int bbit = ofs % 8;
uint8_t b = bitmask[bbyte];
if (p_value)
b|=(1<<bbit);
b |= (1 << bbit);
else
b&=!(1<<bbit);
b &= !(1 << bbit);
bitmask[bbyte]=b;
bitmask[bbyte] = b;
}
bool BitMap::get_bit(const Point2& p_pos) const{
bool BitMap::get_bit(const Point2 &p_pos) const {
int x=Math::fast_ftoi(p_pos.x);
int y=Math::fast_ftoi(p_pos.y);
ERR_FAIL_INDEX_V(x,width,false);
ERR_FAIL_INDEX_V(y,height,false);
int x = Math::fast_ftoi(p_pos.x);
int y = Math::fast_ftoi(p_pos.y);
ERR_FAIL_INDEX_V(x, width, false);
ERR_FAIL_INDEX_V(y, height, false);
int ofs = width * y + x;
int bbyte = ofs/8;
int bbyte = ofs / 8;
int bbit = ofs % 8;
return (bitmask[bbyte]&(1<<bbit))!=0;
return (bitmask[bbyte] & (1 << bbit)) != 0;
}
Size2 BitMap::get_size() const {
return Size2(width,height);
return Size2(width, height);
}
void BitMap::_set_data(const Dictionary& p_d) {
void BitMap::_set_data(const Dictionary &p_d) {
ERR_FAIL_COND(!p_d.has("size"));
ERR_FAIL_COND(!p_d.has("data"));
create(p_d["size"]);
bitmask=p_d["data"];
bitmask = p_d["data"];
}
Dictionary BitMap::_get_data() const{
Dictionary BitMap::_get_data() const {
Dictionary d;
d["size"]=get_size();
d["data"]=bitmask;
d["size"] = get_size();
d["data"] = bitmask;
return d;
}
void BitMap::_bind_methods() {
ObjectTypeDB::bind_method(_MD("create","size"),&BitMap::create);
ObjectTypeDB::bind_method(_MD("create_from_image_alpha","image"),&BitMap::create_from_image_alpha);
ObjectTypeDB::bind_method(_MD("create", "size"), &BitMap::create);
ObjectTypeDB::bind_method(_MD("create_from_image_alpha", "image"), &BitMap::create_from_image_alpha);
ObjectTypeDB::bind_method(_MD("set_bit","pos","bit"),&BitMap::set_bit);
ObjectTypeDB::bind_method(_MD("get_bit","pos"),&BitMap::get_bit);
ObjectTypeDB::bind_method(_MD("set_bit", "pos", "bit"), &BitMap::set_bit);
ObjectTypeDB::bind_method(_MD("get_bit", "pos"), &BitMap::get_bit);
ObjectTypeDB::bind_method(_MD("set_bit_rect","p_rect","bit"),&BitMap::set_bit_rect);
ObjectTypeDB::bind_method(_MD("get_true_bit_count"),&BitMap::get_true_bit_count);
ObjectTypeDB::bind_method(_MD("set_bit_rect", "p_rect", "bit"), &BitMap::set_bit_rect);
ObjectTypeDB::bind_method(_MD("get_true_bit_count"), &BitMap::get_true_bit_count);
ObjectTypeDB::bind_method(_MD("get_size"),&BitMap::get_size);
ObjectTypeDB::bind_method(_MD("_set_data"),&BitMap::_set_data);
ObjectTypeDB::bind_method(_MD("_get_data"),&BitMap::_get_data);
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY,"data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_data"),_SCS("_get_data"));
ObjectTypeDB::bind_method(_MD("get_size"), &BitMap::get_size);
ObjectTypeDB::bind_method(_MD("_set_data"), &BitMap::_set_data);
ObjectTypeDB::bind_method(_MD("_get_data"), &BitMap::_get_data);
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), _SCS("_set_data"), _SCS("_get_data"));
}
BitMap::BitMap() {
width=0;
height=0;
width = 0;
height = 0;
}
//////////////////////////////////////