123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897 |
- /*************************************************************************/
- /* tile_map.cpp */
- /*************************************************************************/
- /* This file is part of: */
- /* GODOT ENGINE */
- /* http://www.godotengine.org */
- /*************************************************************************/
- /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
- /* */
- /* Permission is hereby granted, free of charge, to any person obtaining */
- /* a copy of this software and associated documentation files (the */
- /* "Software"), to deal in the Software without restriction, including */
- /* without limitation the rights to use, copy, modify, merge, publish, */
- /* distribute, sublicense, and/or sell copies of the Software, and to */
- /* permit persons to whom the Software is furnished to do so, subject to */
- /* the following conditions: */
- /* */
- /* The above copyright notice and this permission notice shall be */
- /* included in all copies or substantial portions of the Software. */
- /* */
- /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
- /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
- /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
- /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
- /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
- /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
- /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
- /*************************************************************************/
- #include "tile_map.h"
- #include "io/marshalls.h"
- #include "servers/physics_2d_server.h"
- #include "method_bind_ext.inc"
- void TileMap::_notification(int p_what) {
- switch(p_what) {
- case NOTIFICATION_ENTER_TREE: {
- pending_update=true;
- _update_dirty_quadrants();
- RID space = get_world_2d()->get_space();
- _update_quadrant_transform();
- _update_quadrant_space(space);
- } break;
- case NOTIFICATION_EXIT_TREE: {
- _update_quadrant_space(RID());
- } break;
- case NOTIFICATION_TRANSFORM_CHANGED: {
- //move stuff
- _update_quadrant_transform();
- } break;
- }
- }
- void TileMap::_update_quadrant_space(const RID& p_space) {
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
- Quadrant &q=E->get();
- Physics2DServer::get_singleton()->body_set_space(q.static_body,p_space);
- }
- }
- void TileMap::_update_quadrant_transform() {
- if (!is_inside_tree())
- return;
- Matrix32 global_transform = get_global_transform();
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
- Quadrant &q=E->get();
- Matrix32 xform;
- xform.set_origin( q.pos );
- xform = global_transform * xform;
- Physics2DServer::get_singleton()->body_set_state(q.static_body,Physics2DServer::BODY_STATE_TRANSFORM,xform);
- }
- }
- void TileMap::set_tileset(const Ref<TileSet>& p_tileset) {
- if (tile_set.is_valid())
- tile_set->disconnect("changed",this,"_recreate_quadrants");
- _clear_quadrants();
- tile_set=p_tileset;
- if (tile_set.is_valid())
- tile_set->connect("changed",this,"_recreate_quadrants");
- else
- clear();
- _recreate_quadrants();
- emit_signal("settings_changed");
- }
- Ref<TileSet> TileMap::get_tileset() const {
- return tile_set;
- }
- void TileMap::set_cell_size(Size2 p_size) {
- ERR_FAIL_COND(p_size.x<1 || p_size.y<1);
- _clear_quadrants();
- cell_size=p_size;
- _recreate_quadrants();
- emit_signal("settings_changed");
- }
- Size2 TileMap::get_cell_size() const {
- return cell_size;
- }
- void TileMap::set_quadrant_size(int p_size) {
- ERR_FAIL_COND(p_size<1);
- _clear_quadrants();
- quadrant_size=p_size;
- _recreate_quadrants();
- emit_signal("settings_changed");
- }
- int TileMap::get_quadrant_size() const {
- return quadrant_size;
- }
- void TileMap::set_center_x(bool p_enable) {
- center_x=p_enable;
- _recreate_quadrants();
- emit_signal("settings_changed");
- }
- bool TileMap::get_center_x() const {
- return center_x;
- }
- void TileMap::set_center_y(bool p_enable) {
- center_y=p_enable;
- _recreate_quadrants();
- emit_signal("settings_changed");
- }
- bool TileMap::get_center_y() const {
- return center_y;
- }
- void TileMap::_update_dirty_quadrants() {
- if (!pending_update)
- return;
- if (!is_inside_tree())
- return;
- if (!tile_set.is_valid())
- return;
- VisualServer *vs = VisualServer::get_singleton();
- Physics2DServer *ps = Physics2DServer::get_singleton();
- Vector2 tofs = get_cell_draw_offset();
- while (dirty_quadrant_list.first()) {
- Quadrant &q = *dirty_quadrant_list.first()->self();
- vs->canvas_item_clear(q.canvas_item);
- ps->body_clear_shapes(q.static_body);
- int shape_idx=0;
- for(int i=0;i<q.cells.size();i++) {
- Map<PosKey,Cell>::Element *E=tile_map.find( q.cells[i] );
- Cell &c=E->get();
- //moment of truth
- if (!tile_set->has_tile(c.id))
- continue;
- Ref<Texture> tex = tile_set->tile_get_texture(c.id);
- Vector2 tile_ofs = tile_set->tile_get_texture_offset(c.id);
- Vector2 offset = _map_to_world(E->key().x, E->key().y) - q.pos + tofs;
- if (!tex.is_valid())
- continue;
- Rect2 r = tile_set->tile_get_region(c.id);
- Size2 s = tex->get_size();
- if (r==Rect2())
- s = tex->get_size();
- else {
- s = r.size;
- r.pos.x+=fp_adjust;
- r.pos.y+=fp_adjust;
- r.size.x-=fp_adjust*2.0;
- r.size.y-=fp_adjust*2.0;
- }
- Rect2 rect;
- rect.pos=offset.floor();
- rect.size=s;
- rect.size.x+=fp_adjust;
- rect.size.y+=fp_adjust;
- if (c.flip_h)
- rect.size.x=-rect.size.x;
- if (c.flip_v)
- rect.size.y=-rect.size.y;
- rect.pos+=tile_ofs;
- if (r==Rect2()) {
- tex->draw_rect(q.canvas_item,rect,false,Color(1,1,1),c.transpose);
- } else {
- tex->draw_rect_region(q.canvas_item,rect,r,Color(1,1,1),c.transpose);
- }
- Vector< Ref<Shape2D> > shapes = tile_set->tile_get_shapes(c.id);
- for(int i=0;i<shapes.size();i++) {
- Ref<Shape2D> shape = shapes[i];
- if (shape.is_valid()) {
- Vector2 shape_ofs = tile_set->tile_get_shape_offset(c.id);
- Matrix32 xform;
- xform.set_origin(offset.floor());
- if (c.flip_h) {
- xform.elements[0]=-xform.elements[0];
- shape_ofs.x=s.x-shape_ofs.x;
- }
- if (c.flip_v) {
- xform.elements[1]=-xform.elements[1];
- shape_ofs.y=s.y-shape_ofs.y;
- }
- if (c.transpose) {
- SWAP(xform.elements[0].x, xform.elements[0].y);
- SWAP(xform.elements[1].x, xform.elements[1].y);
- SWAP(shape_ofs.x, shape_ofs.y);
- }
- xform.elements[2].x+=shape_ofs.x;
- xform.elements[2].y+=shape_ofs.y;
- ps->body_add_shape(q.static_body,shape->get_rid(),xform);
- ps->body_set_shape_metadata(q.static_body,shape_idx++,Vector2(E->key().x,E->key().y));
- }
- }
- }
- dirty_quadrant_list.remove( dirty_quadrant_list.first() );
- }
- pending_update=false;
- if (quadrant_order_dirty) {
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
- Quadrant &q=E->get();
- if (q.canvas_item.is_valid()) {
- VS::get_singleton()->canvas_item_raise(q.canvas_item);
- }
- }
- quadrant_order_dirty=false;
- }
- _recompute_rect_cache();
- }
- void TileMap::_recompute_rect_cache() {
- #ifdef DEBUG_ENABLED
- if (!rect_cache_dirty)
- return;
- Rect2 r_total;
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
- Rect2 r;
- r.pos=_map_to_world(E->key().x*quadrant_size, E->key().y*quadrant_size);
- r.expand_to( _map_to_world(E->key().x*quadrant_size+quadrant_size, E->key().y*quadrant_size) );
- r.expand_to( _map_to_world(E->key().x*quadrant_size+quadrant_size, E->key().y*quadrant_size+quadrant_size) );
- r.expand_to( _map_to_world(E->key().x*quadrant_size, E->key().y*quadrant_size+quadrant_size) );
- if (E==quadrant_map.front())
- r_total=r;
- else
- r_total=r_total.merge(r);
- }
- if (r_total==Rect2()) {
- rect_cache=Rect2(-10,-10,20,20);
- } else {
- rect_cache=r_total.grow(MAX(cell_size.x,cell_size.y)*quadrant_size);
- }
- item_rect_changed();
- rect_cache_dirty=false;
- #endif
- }
- Map<TileMap::PosKey,TileMap::Quadrant>::Element *TileMap::_create_quadrant(const PosKey& p_qk) {
- Matrix32 xform;
- //xform.set_origin(Point2(p_qk.x,p_qk.y)*cell_size*quadrant_size);
- Quadrant q;
- q.pos = _map_to_world(p_qk.x*quadrant_size,p_qk.y*quadrant_size);
- xform.set_origin( q.pos );
- q.canvas_item = VisualServer::get_singleton()->canvas_item_create();
- VisualServer::get_singleton()->canvas_item_set_parent( q.canvas_item, get_canvas_item() );
- VisualServer::get_singleton()->canvas_item_set_transform( q.canvas_item, xform );
- q.static_body=Physics2DServer::get_singleton()->body_create(Physics2DServer::BODY_MODE_STATIC);
- Physics2DServer::get_singleton()->body_attach_object_instance_ID(q.static_body,get_instance_ID());
- Physics2DServer::get_singleton()->body_set_layer_mask(q.static_body,collision_layer);
- Physics2DServer::get_singleton()->body_set_param(q.static_body,Physics2DServer::BODY_PARAM_FRICTION,friction);
- Physics2DServer::get_singleton()->body_set_param(q.static_body,Physics2DServer::BODY_PARAM_BOUNCE,bounce);
- if (is_inside_tree()) {
- xform = get_global_transform() * xform;
- RID space = get_world_2d()->get_space();
- Physics2DServer::get_singleton()->body_set_space(q.static_body,space);
- }
- Physics2DServer::get_singleton()->body_set_state(q.static_body,Physics2DServer::BODY_STATE_TRANSFORM,xform);
- rect_cache_dirty=true;
- quadrant_order_dirty=true;
- return quadrant_map.insert(p_qk,q);
- }
- void TileMap::_erase_quadrant(Map<PosKey,Quadrant>::Element *Q) {
- Quadrant &q=Q->get();
- Physics2DServer::get_singleton()->free(q.static_body);
- VisualServer::get_singleton()->free(q.canvas_item);
- if (q.dirty_list.in_list())
- dirty_quadrant_list.remove(&q.dirty_list);
- quadrant_map.erase(Q);
- rect_cache_dirty=true;
- }
- void TileMap::_make_quadrant_dirty(Map<PosKey,Quadrant>::Element *Q) {
- Quadrant &q=Q->get();
- if (!q.dirty_list.in_list())
- dirty_quadrant_list.add(&q.dirty_list);
- if (pending_update)
- return;
- pending_update=true;
- if (!is_inside_tree())
- return;
- call_deferred("_update_dirty_quadrants");
- }
- void TileMap::set_cell(int p_x,int p_y,int p_tile,bool p_flip_x,bool p_flip_y,bool p_transpose) {
- PosKey pk(p_x,p_y);
- Map<PosKey,Cell>::Element *E=tile_map.find(pk);
- if (!E && p_tile==INVALID_CELL)
- return; //nothing to do
- PosKey qk(p_x/quadrant_size,p_y/quadrant_size);
- if (p_tile==INVALID_CELL) {
- //erase existing
- tile_map.erase(pk);
- Map<PosKey,Quadrant>::Element *Q = quadrant_map.find(qk);
- ERR_FAIL_COND(!Q);
- Quadrant &q=Q->get();
- q.cells.erase(pk);
- if (q.cells.size()==0)
- _erase_quadrant(Q);
- else
- _make_quadrant_dirty(Q);
- return;
- }
- Map<PosKey,Quadrant>::Element *Q = quadrant_map.find(qk);
- if (!E) {
- E=tile_map.insert(pk,Cell());
- if (!Q) {
- Q=_create_quadrant(qk);
- }
- Quadrant &q=Q->get();
- q.cells.insert(pk);
- } else {
- ERR_FAIL_COND(!Q); // quadrant should exist...
- if (E->get().id==p_tile && E->get().flip_h==p_flip_x && E->get().flip_v==p_flip_y && E->get().transpose==p_transpose)
- return; //nothing changed
- }
- Cell &c = E->get();
- c.id=p_tile;
- c.flip_h=p_flip_x;
- c.flip_v=p_flip_y;
- c.transpose=p_transpose;
- _make_quadrant_dirty(Q);
- }
- int TileMap::get_cell(int p_x,int p_y) const {
- PosKey pk(p_x,p_y);
- const Map<PosKey,Cell>::Element *E=tile_map.find(pk);
- if (!E)
- return INVALID_CELL;
- return E->get().id;
- }
- bool TileMap::is_cell_x_flipped(int p_x,int p_y) const {
- PosKey pk(p_x,p_y);
- const Map<PosKey,Cell>::Element *E=tile_map.find(pk);
- if (!E)
- return false;
- return E->get().flip_h;
- }
- bool TileMap::is_cell_y_flipped(int p_x,int p_y) const {
- PosKey pk(p_x,p_y);
- const Map<PosKey,Cell>::Element *E=tile_map.find(pk);
- if (!E)
- return false;
- return E->get().flip_v;
- }
- bool TileMap::is_cell_transposed(int p_x,int p_y) const {
- PosKey pk(p_x,p_y);
- const Map<PosKey,Cell>::Element *E=tile_map.find(pk);
- if (!E)
- return false;
- return E->get().transpose;
- }
- void TileMap::_recreate_quadrants() {
- _clear_quadrants();
- for (Map<PosKey,Cell>::Element *E=tile_map.front();E;E=E->next()) {
- PosKey qk(E->key().x/quadrant_size,E->key().y/quadrant_size);
- Map<PosKey,Quadrant>::Element *Q=quadrant_map.find(qk);
- if (!Q) {
- Q=_create_quadrant(qk);
- dirty_quadrant_list.add(&Q->get().dirty_list);
- }
- Q->get().cells.insert(E->key());
- _make_quadrant_dirty(Q);
- }
- }
- void TileMap::_clear_quadrants() {
- while (quadrant_map.size()) {
- _erase_quadrant( quadrant_map.front() );
- }
- }
- void TileMap::clear() {
- _clear_quadrants();
- tile_map.clear();
- }
- void TileMap::_set_tile_data(const DVector<int>& p_data) {
- int c=p_data.size();
- DVector<int>::Read r = p_data.read();
- for(int i=0;i<c;i+=2) {
- const uint8_t *ptr=(const uint8_t*)&r[i];
- uint8_t local[8];
- for(int j=0;j<8;j++)
- local[j]=ptr[j];
- #ifdef BIG_ENDIAN_ENABLED
- SWAP(local[0],local[3]);
- SWAP(local[1],local[2]);
- SWAP(local[4],local[7]);
- SWAP(local[5],local[6]);
- #endif
- int16_t x = decode_uint16(&local[0]);
- int16_t y = decode_uint16(&local[2]);
- uint32_t v = decode_uint32(&local[4]);
- bool flip_h = v&(1<<29);
- bool flip_v = v&(1<<30);
- bool transpose = v&(1<<31);
- v&=(1<<29)-1;
- // if (x<-20 || y <-20 || x>4000 || y>4000)
- // continue;
- set_cell(x,y,v,flip_h,flip_v,transpose);
- }
- }
- DVector<int> TileMap::_get_tile_data() const {
- DVector<int> data;
- data.resize(tile_map.size()*2);
- DVector<int>::Write w = data.write();
- int idx=0;
- for(const Map<PosKey,Cell>::Element *E=tile_map.front();E;E=E->next()) {
- uint8_t *ptr = (uint8_t*)&w[idx];
- encode_uint16(E->key().x,&ptr[0]);
- encode_uint16(E->key().y,&ptr[2]);
- uint32_t val = E->get().id;
- if (E->get().flip_h)
- val|=(1<<29);
- if (E->get().flip_v)
- val|=(1<<30);
- if (E->get().transpose)
- val|=(1<<31);
- encode_uint32(val,&ptr[4]);
- idx+=2;
- }
- w = DVector<int>::Write();
- return data;
- }
- Rect2 TileMap::get_item_rect() const {
- const_cast<TileMap*>(this)->_update_dirty_quadrants();
- return rect_cache;
- }
- void TileMap::set_collision_layer_mask(uint32_t p_layer) {
- collision_layer=p_layer;
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
- Quadrant &q=E->get();
- Physics2DServer::get_singleton()->body_set_layer_mask(q.static_body,collision_layer);
- }
- }
- void TileMap::set_collision_friction(float p_friction) {
- friction=p_friction;
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
- Quadrant &q=E->get();
- Physics2DServer::get_singleton()->body_set_param(q.static_body,Physics2DServer::BODY_PARAM_FRICTION,p_friction);
- }
- }
- float TileMap::get_collision_friction() const{
- return friction;
- }
- void TileMap::set_collision_bounce(float p_bounce){
- bounce=p_bounce;
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
- Quadrant &q=E->get();
- Physics2DServer::get_singleton()->body_set_param(q.static_body,Physics2DServer::BODY_PARAM_BOUNCE,p_bounce);
- }
- }
- float TileMap::get_collision_bounce() const{
- return bounce;
- }
- uint32_t TileMap::get_collision_layer_mask() const {
- return collision_layer;
- }
- void TileMap::set_mode(Mode p_mode) {
- _clear_quadrants();
- mode=p_mode;
- _recreate_quadrants();
- emit_signal("settings_changed");
- }
- TileMap::Mode TileMap::get_mode() const {
- return mode;
- }
- void TileMap::set_half_offset(HalfOffset p_half_offset) {
- _clear_quadrants();
- half_offset=p_half_offset;
- _recreate_quadrants();
- emit_signal("settings_changed");
- }
- Vector2 TileMap::get_cell_draw_offset() const {
- switch(mode) {
- case MODE_SQUARE: {
- return Vector2();
- } break;
- case MODE_ISOMETRIC: {
- return Vector2(-cell_size.x*0.5,0);
- } break;
- case MODE_CUSTOM: {
- Vector2 min;
- min.x = MIN(custom_transform[0].x,min.x);
- min.y = MIN(custom_transform[0].y,min.y);
- min.x = MIN(custom_transform[1].x,min.x);
- min.y = MIN(custom_transform[1].y,min.y);
- return min;
- } break;
- }
- return Vector2();
- }
- TileMap::HalfOffset TileMap::get_half_offset() const {
- return half_offset;
- }
- Matrix32 TileMap::get_cell_transform() const {
- switch(mode) {
- case MODE_SQUARE: {
- Matrix32 m;
- m[0]*=cell_size.x;
- m[1]*=cell_size.y;
- return m;
- } break;
- case MODE_ISOMETRIC: {
- //isometric only makes sense when y is positive in both x and y vectors, otherwise
- //the drawing of tiles will overlap
- Matrix32 m;
- m[0]=Vector2(cell_size.x*0.5,cell_size.y*0.5);
- m[1]=Vector2(-cell_size.x*0.5,cell_size.y*0.5);
- return m;
- } break;
- case MODE_CUSTOM: {
- return custom_transform;
- } break;
- }
- return Matrix32();
- }
- void TileMap::set_custom_transform(const Matrix32& p_xform) {
- _clear_quadrants();
- custom_transform=p_xform;
- _recreate_quadrants();
- emit_signal("settings_changed");
- }
- Matrix32 TileMap::get_custom_transform() const{
- return custom_transform;
- }
- Vector2 TileMap::_map_to_world(int x,int y,bool p_ignore_ofs) const {
- Vector2 ret = get_cell_transform().xform(Vector2(x,y));
- if (!p_ignore_ofs) {
- switch(half_offset) {
- case HALF_OFFSET_X: {
- if (ABS(y)&1) {
- ret+=get_cell_transform()[0]*0.5;
- }
- } break;
- case HALF_OFFSET_Y: {
- if (ABS(x)&1) {
- ret+=get_cell_transform()[1]*0.5;
- }
- } break;
- default: {}
- }
- }
- return ret;
- }
- Vector2 TileMap::map_to_world(const Vector2& p_pos,bool p_ignore_ofs) const {
- return _map_to_world(p_pos.x,p_pos.y,p_ignore_ofs);
- }
- Vector2 TileMap::world_to_map(const Vector2& p_pos) const{
- Vector2 ret = get_cell_transform().affine_inverse().xform(p_pos);
- switch(half_offset) {
- case HALF_OFFSET_X: {
- if (int(ret.y)&1) {
- ret.x-=0.5;
- }
- } break;
- case HALF_OFFSET_Y: {
- if (int(ret.x)&1) {
- ret.y-=0.5;
- }
- } break;
- default: {}
- }
- return ret.floor();
- }
- void TileMap::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("set_tileset","tileset:TileSet"),&TileMap::set_tileset);
- ObjectTypeDB::bind_method(_MD("get_tileset:TileSet"),&TileMap::get_tileset);
- ObjectTypeDB::bind_method(_MD("set_mode","mode"),&TileMap::set_mode);
- ObjectTypeDB::bind_method(_MD("get_mode"),&TileMap::get_mode);
- ObjectTypeDB::bind_method(_MD("set_half_offset","half_offset"),&TileMap::set_half_offset);
- ObjectTypeDB::bind_method(_MD("get_half_offset"),&TileMap::get_half_offset);
- ObjectTypeDB::bind_method(_MD("set_custom_transform","custom_transform"),&TileMap::set_custom_transform);
- ObjectTypeDB::bind_method(_MD("get_custom_transform"),&TileMap::get_custom_transform);
- ObjectTypeDB::bind_method(_MD("set_cell_size","size"),&TileMap::set_cell_size);
- ObjectTypeDB::bind_method(_MD("get_cell_size"),&TileMap::get_cell_size);
- ObjectTypeDB::bind_method(_MD("_set_old_cell_size","size"),&TileMap::_set_old_cell_size);
- ObjectTypeDB::bind_method(_MD("_get_old_cell_size"),&TileMap::_get_old_cell_size);
- ObjectTypeDB::bind_method(_MD("set_quadrant_size","size"),&TileMap::set_quadrant_size);
- ObjectTypeDB::bind_method(_MD("get_quadrant_size"),&TileMap::get_quadrant_size);
- ObjectTypeDB::bind_method(_MD("set_center_x","enable"),&TileMap::set_center_x);
- ObjectTypeDB::bind_method(_MD("get_center_x"),&TileMap::get_center_x);
- ObjectTypeDB::bind_method(_MD("set_center_y","enable"),&TileMap::set_center_y);
- ObjectTypeDB::bind_method(_MD("get_center_y"),&TileMap::get_center_y);
- ObjectTypeDB::bind_method(_MD("set_collision_layer_mask","mask"),&TileMap::set_collision_layer_mask);
- ObjectTypeDB::bind_method(_MD("get_collision_layer_mask"),&TileMap::get_collision_layer_mask);
- ObjectTypeDB::bind_method(_MD("set_collision_friction","value"),&TileMap::set_collision_friction);
- ObjectTypeDB::bind_method(_MD("get_collision_friction"),&TileMap::get_collision_friction);
- ObjectTypeDB::bind_method(_MD("set_collision_bounce","value"),&TileMap::set_collision_bounce);
- ObjectTypeDB::bind_method(_MD("get_collision_bounce"),&TileMap::get_collision_bounce);
- ObjectTypeDB::bind_method(_MD("set_cell","x","y","tile","flip_x","flip_y","transpose"),&TileMap::set_cell,DEFVAL(false),DEFVAL(false),DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("get_cell","x","y"),&TileMap::get_cell);
- ObjectTypeDB::bind_method(_MD("is_cell_x_flipped","x","y"),&TileMap::is_cell_x_flipped);
- ObjectTypeDB::bind_method(_MD("is_cell_y_flipped","x","y"),&TileMap::is_cell_y_flipped);
- ObjectTypeDB::bind_method(_MD("clear"),&TileMap::clear);
- ObjectTypeDB::bind_method(_MD("map_to_world","mappos","ignore_half_ofs"),&TileMap::map_to_world,DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("world_to_map","worldpos"),&TileMap::world_to_map);
- ObjectTypeDB::bind_method(_MD("_clear_quadrants"),&TileMap::_clear_quadrants);
- ObjectTypeDB::bind_method(_MD("_recreate_quadrants"),&TileMap::_recreate_quadrants);
- ObjectTypeDB::bind_method(_MD("_update_dirty_quadrants"),&TileMap::_update_dirty_quadrants);
- ObjectTypeDB::bind_method(_MD("_set_tile_data"),&TileMap::_set_tile_data);
- ObjectTypeDB::bind_method(_MD("_get_tile_data"),&TileMap::_get_tile_data);
- ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Square,Isometric,Custom"),_SCS("set_mode"),_SCS("get_mode"));
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"tile_set",PROPERTY_HINT_RESOURCE_TYPE,"TileSet"),_SCS("set_tileset"),_SCS("get_tileset"));
- ADD_PROPERTY( PropertyInfo(Variant::INT,"cell_size",PROPERTY_HINT_RANGE,"1,8192,1",0),_SCS("_set_old_cell_size"),_SCS("_get_old_cell_size"));
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"cell/size",PROPERTY_HINT_RANGE,"1,8192,1"),_SCS("set_cell_size"),_SCS("get_cell_size"));
- ADD_PROPERTY( PropertyInfo(Variant::INT,"cell/quadrant_size",PROPERTY_HINT_RANGE,"1,128,1"),_SCS("set_quadrant_size"),_SCS("get_quadrant_size"));
- ADD_PROPERTY( PropertyInfo(Variant::MATRIX32,"cell/custom_transform"),_SCS("set_custom_transform"),_SCS("get_custom_transform"));
- ADD_PROPERTY( PropertyInfo(Variant::INT,"cell/half_offset",PROPERTY_HINT_ENUM,"Offset X,Offset Y,Disabled"),_SCS("set_half_offset"),_SCS("get_half_offset"));
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"collision/friction",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_collision_friction"),_SCS("get_collision_friction"));
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"collision/bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_collision_bounce"),_SCS("get_collision_bounce"));
- ADD_PROPERTY( PropertyInfo(Variant::INT,"collision/layers",PROPERTY_HINT_ALL_FLAGS),_SCS("set_collision_layer_mask"),_SCS("get_collision_layer_mask"));
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"tile_data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_tile_data"),_SCS("_get_tile_data"));
- ADD_SIGNAL(MethodInfo("settings_changed"));
- BIND_CONSTANT( INVALID_CELL );
- BIND_CONSTANT( MODE_SQUARE );
- BIND_CONSTANT( MODE_ISOMETRIC );
- BIND_CONSTANT( MODE_CUSTOM );
- BIND_CONSTANT( HALF_OFFSET_X );
- BIND_CONSTANT( HALF_OFFSET_Y );
- BIND_CONSTANT( HALF_OFFSET_DISABLED );
- }
- TileMap::TileMap() {
- rect_cache_dirty=true;
- pending_update=false;
- quadrant_order_dirty=false;
- quadrant_size=16;
- cell_size=Size2(64,64);
- center_x=false;
- center_y=false;
- collision_layer=1;
- friction=1;
- bounce=0;
- mode=MODE_SQUARE;
- half_offset=HALF_OFFSET_DISABLED;
- fp_adjust=0.01;
- fp_adjust=0.01;
- }
- TileMap::~TileMap() {
- clear();
- }
|