mirror of
https://github.com/Relintai/terraman_2d.git
synced 2024-11-12 10:15:18 +01:00
Added wall mesh transform properties to the world and chunk. Also cleanups the the ChannelFlags enum and added FLAG_CHANNEL_WALL_HOLE to it.
This commit is contained in:
parent
b30c1b9153
commit
b63eed39f9
@ -940,9 +940,10 @@ void Terrain2DChunkDefault::_bind_methods() {
|
||||
BIND_ENUM_CONSTANT(FLAG_CHANNEL_WALL_PX);
|
||||
BIND_ENUM_CONSTANT(FLAG_CHANNEL_WALL_WEST);
|
||||
BIND_ENUM_CONSTANT(FLAG_CHANNEL_WALL_NX);
|
||||
BIND_ENUM_CONSTANT(FLAG_CHANNEL_WALL_COLLIDER);
|
||||
BIND_ENUM_CONSTANT(FLAG_CHANNEL_WALL_FLIP_H);
|
||||
BIND_ENUM_CONSTANT(FLAG_CHANNEL_WALL_FLIP_V);
|
||||
BIND_ENUM_CONSTANT(FLAG_CHANNEL_COLLIDER);
|
||||
BIND_ENUM_CONSTANT(FLAG_CHANNEL_FLIP_H);
|
||||
BIND_ENUM_CONSTANT(FLAG_CHANNEL_FLIP_V);
|
||||
BIND_ENUM_CONSTANT(FLAG_CHANNEL_WALL_HOLE);
|
||||
|
||||
BIND_CONSTANT(MESH_INDEX_TERRAIN);
|
||||
BIND_CONSTANT(MESH_INDEX_PROP);
|
||||
|
@ -74,24 +74,25 @@ public:
|
||||
};
|
||||
|
||||
enum ChannelFlags {
|
||||
//+y
|
||||
//-y (down)
|
||||
FLAG_CHANNEL_WALL_NORTH = 1 << 0,
|
||||
FLAG_CHANNEL_WALL_PY = 1 << 0,
|
||||
//-y
|
||||
FLAG_CHANNEL_WALL_NY = 1 << 0,
|
||||
//+y (up)
|
||||
FLAG_CHANNEL_WALL_SOUTH = 1 << 1,
|
||||
FLAG_CHANNEL_WALL_NY = 1 << 1,
|
||||
//+x
|
||||
FLAG_CHANNEL_WALL_PY = 1 << 1,
|
||||
//+x (right)
|
||||
FLAG_CHANNEL_WALL_EAST = 1 << 2,
|
||||
FLAG_CHANNEL_WALL_PX = 1 << 2,
|
||||
//-x
|
||||
//-x (left)
|
||||
FLAG_CHANNEL_WALL_WEST = 1 << 3,
|
||||
FLAG_CHANNEL_WALL_NX = 1 << 3,
|
||||
|
||||
FLAG_CHANNEL_WALL_COLLIDER = 1 << 4,
|
||||
FLAG_CHANNEL_WALL_FLIP_H = 1 << 5,
|
||||
FLAG_CHANNEL_WALL_FLIP_V= 1 << 6,
|
||||
//All of these has to fit to a uint8_t!
|
||||
//Don't add more than one actual flag entry!
|
||||
FLAG_CHANNEL_COLLIDER = 1 << 4,
|
||||
FLAG_CHANNEL_FLIP_H = 1 << 5,
|
||||
FLAG_CHANNEL_FLIP_V= 1 << 6,
|
||||
|
||||
// Walls become holes
|
||||
FLAG_CHANNEL_WALL_HOLE = 1 << 7,
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -242,11 +242,40 @@ void Terrain2DChunk::set_voxel_world_bind(Node *world) {
|
||||
set_voxel_world(Object::cast_to<Terrain2DWorld>(world));
|
||||
}
|
||||
|
||||
Transform2D Terrain2DChunk::get_custom_transform() {
|
||||
return _custom_transform;
|
||||
|
||||
Transform2D Terrain2DChunk::mesh_transform_terrain_get() {
|
||||
return _mesh_transform_terrain;
|
||||
}
|
||||
void Terrain2DChunk::set_custom_transform(const Transform2D &value) {
|
||||
_custom_transform = value;
|
||||
void Terrain2DChunk::mesh_transform_terrain_set(const Transform2D &value) {
|
||||
_mesh_transform_terrain = value;
|
||||
}
|
||||
|
||||
Transform2D Terrain2DChunk::mesh_transform_wall_north_get() {
|
||||
return _mesh_transform_wall_north;
|
||||
}
|
||||
void Terrain2DChunk::mesh_transform_wall_north_set(const Transform2D &value) {
|
||||
_mesh_transform_wall_north = value;
|
||||
}
|
||||
|
||||
Transform2D Terrain2DChunk::mesh_transform_wall_south_get() {
|
||||
return _mesh_transform_wall_south;
|
||||
}
|
||||
void Terrain2DChunk::mesh_transform_wall_south_set(const Transform2D &value) {
|
||||
_mesh_transform_wall_south = value;
|
||||
}
|
||||
|
||||
Transform2D Terrain2DChunk::mesh_transform_wall_east_get() {
|
||||
return _mesh_transform_wall_east;
|
||||
}
|
||||
void Terrain2DChunk::mesh_transform_wall_east_set(const Transform2D &value) {
|
||||
_mesh_transform_wall_east = value;
|
||||
}
|
||||
|
||||
Transform2D Terrain2DChunk::mesh_transform_wall_west_get() {
|
||||
return _mesh_transform_wall_west;
|
||||
}
|
||||
void Terrain2DChunk::mesh_transform_wall_west_set(const Transform2D &value) {
|
||||
_mesh_transform_wall_west = value;
|
||||
}
|
||||
|
||||
Ref<Terrain2DJob> Terrain2DChunk::job_get(int index) const {
|
||||
@ -1256,9 +1285,9 @@ void Terrain2DChunk::_world_transform_changed() {
|
||||
Transform2D t;
|
||||
Vector2 pos = Vector2(_position_x * static_cast<int>(_size_x) * _cell_size_x, _position_y * static_cast<int>(_size_y) * _cell_size_y);
|
||||
|
||||
pos = _custom_transform.xform(pos);
|
||||
pos = _mesh_transform_terrain.xform(pos);
|
||||
|
||||
t *= _custom_transform;
|
||||
//t *= _custom_transform;
|
||||
t.set_origin(pos);
|
||||
|
||||
set_transform(t);
|
||||
@ -1476,9 +1505,27 @@ void Terrain2DChunk::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_voxel_world", "world"), &Terrain2DChunk::set_voxel_world_bind);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "voxel_world", PROPERTY_HINT_RESOURCE_TYPE, "Terrain2DWorld", 0), "set_voxel_world", "get_voxel_world");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_custom_transform"), &Terrain2DChunk::get_custom_transform);
|
||||
ClassDB::bind_method(D_METHOD("set_custom_transform", "player"), &Terrain2DChunk::set_custom_transform);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "get_custom_transform"), "set_custom_transform", "get_custom_transform");
|
||||
ADD_GROUP("Mesh Transforms", "mesh_transform");
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_terrain_get"), &Terrain2DChunk::mesh_transform_terrain_get);
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_terrain_set", "player"), &Terrain2DChunk::mesh_transform_terrain_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "mesh_transform_terrain"), "mesh_transform_terrain_set", "mesh_transform_terrain_get");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_north_get"), &Terrain2DChunk::mesh_transform_wall_north_get);
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_north_set", "player"), &Terrain2DChunk::mesh_transform_wall_north_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "mesh_transform_wall_north"), "mesh_transform_wall_north_set", "mesh_transform_wall_north_get");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_south_get"), &Terrain2DChunk::mesh_transform_wall_south_get);
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_south_set", "player"), &Terrain2DChunk::mesh_transform_wall_south_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "mesh_transform_wall_south"), "mesh_transform_wall_south_set", "mesh_transform_wall_south_get");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_east_get"), &Terrain2DChunk::mesh_transform_wall_east_get);
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_east_set", "player"), &Terrain2DChunk::mesh_transform_wall_east_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "mesh_transform_wall_east"), "mesh_transform_wall_east_set", "mesh_transform_wall_east_get");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_west_get"), &Terrain2DChunk::mesh_transform_wall_west_get);
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_west_set", "player"), &Terrain2DChunk::mesh_transform_wall_west_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "mesh_transform_wall_west"), "mesh_transform_wall_west_set", "mesh_transform_wall_west_get");
|
||||
|
||||
|
||||
//Terra Data
|
||||
ClassDB::bind_method(D_METHOD("channel_setup"), &Terrain2DChunk::channel_setup);
|
||||
|
@ -190,8 +190,20 @@ public:
|
||||
void set_voxel_world(Terrain2DWorld *world);
|
||||
void set_voxel_world_bind(Node *world);
|
||||
|
||||
Transform2D get_custom_transform();
|
||||
void set_custom_transform(const Transform2D &value);
|
||||
Transform2D mesh_transform_terrain_get();
|
||||
void mesh_transform_terrain_set(const Transform2D &value);
|
||||
|
||||
Transform2D mesh_transform_wall_north_get();
|
||||
void mesh_transform_wall_north_set(const Transform2D &value);
|
||||
|
||||
Transform2D mesh_transform_wall_south_get();
|
||||
void mesh_transform_wall_south_set(const Transform2D &value);
|
||||
|
||||
Transform2D mesh_transform_wall_east_get();
|
||||
void mesh_transform_wall_east_set(const Transform2D &value);
|
||||
|
||||
Transform2D mesh_transform_wall_west_get();
|
||||
void mesh_transform_wall_west_set(const Transform2D &value);
|
||||
|
||||
//Jobs
|
||||
Ref<Terrain2DJob> job_get(const int index) const;
|
||||
@ -450,7 +462,11 @@ protected:
|
||||
|
||||
RID _canvas_item;
|
||||
|
||||
Transform2D _custom_transform;
|
||||
Transform2D _mesh_transform_terrain;
|
||||
Transform2D _mesh_transform_wall_north;
|
||||
Transform2D _mesh_transform_wall_south;
|
||||
Transform2D _mesh_transform_wall_east;
|
||||
Transform2D _mesh_transform_wall_west;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -187,11 +187,39 @@ void Terrain2DWorld::set_player_bind(Node *player) {
|
||||
set_player(Object::cast_to<Node2D>(player));
|
||||
}
|
||||
|
||||
Transform2D Terrain2DWorld::get_custom_transform() {
|
||||
return _custom_transform;
|
||||
Transform2D Terrain2DWorld::mesh_transform_terrain_get() {
|
||||
return _mesh_transform_terrain;
|
||||
}
|
||||
void Terrain2DWorld::set_custom_transform(const Transform2D &value) {
|
||||
_custom_transform = value;
|
||||
void Terrain2DWorld::mesh_transform_terrain_set(const Transform2D &value) {
|
||||
_mesh_transform_terrain = value;
|
||||
}
|
||||
|
||||
Transform2D Terrain2DWorld::mesh_transform_wall_north_get() {
|
||||
return _mesh_transform_wall_north;
|
||||
}
|
||||
void Terrain2DWorld::mesh_transform_wall_north_set(const Transform2D &value) {
|
||||
_mesh_transform_wall_north = value;
|
||||
}
|
||||
|
||||
Transform2D Terrain2DWorld::mesh_transform_wall_south_get() {
|
||||
return _mesh_transform_wall_south;
|
||||
}
|
||||
void Terrain2DWorld::mesh_transform_wall_south_set(const Transform2D &value) {
|
||||
_mesh_transform_wall_south = value;
|
||||
}
|
||||
|
||||
Transform2D Terrain2DWorld::mesh_transform_wall_east_get() {
|
||||
return _mesh_transform_wall_east;
|
||||
}
|
||||
void Terrain2DWorld::mesh_transform_wall_east_set(const Transform2D &value) {
|
||||
_mesh_transform_wall_east = value;
|
||||
}
|
||||
|
||||
Transform2D Terrain2DWorld::mesh_transform_wall_west_get() {
|
||||
return _mesh_transform_wall_west;
|
||||
}
|
||||
void Terrain2DWorld::mesh_transform_wall_west_set(const Transform2D &value) {
|
||||
_mesh_transform_wall_west = value;
|
||||
}
|
||||
|
||||
Ref<Terrain2DWorldArea> Terrain2DWorld::world_area_get(const int index) const {
|
||||
@ -446,8 +474,14 @@ Ref<Terrain2DChunk> Terrain2DWorld::_create_chunk(const int x, const int y, Ref<
|
||||
chunk->set_library(_library);
|
||||
chunk->set_cell_size_x(_cell_size_x);
|
||||
chunk->set_cell_size_y(_cell_size_y);
|
||||
chunk->set_custom_transform(_custom_transform);
|
||||
|
||||
|
||||
//This way it can be changed per chunk (or for areas)
|
||||
chunk->mesh_transform_terrain_set(mesh_transform_terrain_get());
|
||||
chunk->mesh_transform_wall_north_set(mesh_transform_wall_north_get());
|
||||
chunk->mesh_transform_wall_south_set(mesh_transform_wall_south_get());
|
||||
chunk->mesh_transform_wall_east_set(mesh_transform_wall_east_get());
|
||||
chunk->mesh_transform_wall_west_set(mesh_transform_wall_west_get());
|
||||
|
||||
chunk->set_size(_chunk_size_x, _chunk_size_y, _data_margin_start, _data_margin_end);
|
||||
//chunk->set_translation(Vector3(x * _chunk_size_x * _voxel_scale, y * _chunk_size_y * _voxel_scale, z * _chunk_size_z * _voxel_scale));
|
||||
|
||||
@ -1176,9 +1210,26 @@ void Terrain2DWorld::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_player", "player"), &Terrain2DWorld::set_player_bind);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "player", PROPERTY_HINT_RESOURCE_TYPE, "node2D", 0), "set_player", "get_player");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_custom_transform"), &Terrain2DWorld::get_custom_transform);
|
||||
ClassDB::bind_method(D_METHOD("set_custom_transform", "player"), &Terrain2DWorld::set_custom_transform);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "get_custom_transform"), "set_custom_transform", "get_custom_transform");
|
||||
ADD_GROUP("Mesh Transforms", "mesh_transform");
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_terrain_get"), &Terrain2DWorld::mesh_transform_terrain_get);
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_terrain_set", "player"), &Terrain2DWorld::mesh_transform_terrain_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "mesh_transform_terrain"), "mesh_transform_terrain_set", "mesh_transform_terrain_get");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_north_get"), &Terrain2DWorld::mesh_transform_wall_north_get);
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_north_set", "player"), &Terrain2DWorld::mesh_transform_wall_north_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "mesh_transform_wall_north"), "mesh_transform_wall_north_set", "mesh_transform_wall_north_get");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_south_get"), &Terrain2DWorld::mesh_transform_wall_south_get);
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_south_set", "player"), &Terrain2DWorld::mesh_transform_wall_south_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "mesh_transform_wall_south"), "mesh_transform_wall_south_set", "mesh_transform_wall_south_get");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_east_get"), &Terrain2DWorld::mesh_transform_wall_east_get);
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_east_set", "player"), &Terrain2DWorld::mesh_transform_wall_east_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "mesh_transform_wall_east"), "mesh_transform_wall_east_set", "mesh_transform_wall_east_get");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_west_get"), &Terrain2DWorld::mesh_transform_wall_west_get);
|
||||
ClassDB::bind_method(D_METHOD("mesh_transform_wall_west_set", "player"), &Terrain2DWorld::mesh_transform_wall_west_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "mesh_transform_wall_west"), "mesh_transform_wall_west_set", "mesh_transform_wall_west_get");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("world_area_get", "index"), &Terrain2DWorld::world_area_get);
|
||||
ClassDB::bind_method(D_METHOD("world_area_add", "area"), &Terrain2DWorld::world_area_add);
|
||||
|
@ -114,8 +114,20 @@ public:
|
||||
void set_player(Node2D *player);
|
||||
void set_player_bind(Node *player);
|
||||
|
||||
Transform2D get_custom_transform();
|
||||
void set_custom_transform(const Transform2D &value);
|
||||
Transform2D mesh_transform_terrain_get();
|
||||
void mesh_transform_terrain_set(const Transform2D &value);
|
||||
|
||||
Transform2D mesh_transform_wall_north_get();
|
||||
void mesh_transform_wall_north_set(const Transform2D &value);
|
||||
|
||||
Transform2D mesh_transform_wall_south_get();
|
||||
void mesh_transform_wall_south_set(const Transform2D &value);
|
||||
|
||||
Transform2D mesh_transform_wall_east_get();
|
||||
void mesh_transform_wall_east_set(const Transform2D &value);
|
||||
|
||||
Transform2D mesh_transform_wall_west_get();
|
||||
void mesh_transform_wall_west_set(const Transform2D &value);
|
||||
|
||||
//World Areas
|
||||
Ref<Terrain2DWorldArea> world_area_get(const int index) const;
|
||||
@ -287,7 +299,11 @@ private:
|
||||
|
||||
Vector<Ref<Terrain2DLight>> _lights;
|
||||
|
||||
Transform2D _custom_transform;
|
||||
Transform2D _mesh_transform_terrain;
|
||||
Transform2D _mesh_transform_wall_north;
|
||||
Transform2D _mesh_transform_wall_south;
|
||||
Transform2D _mesh_transform_wall_east;
|
||||
Transform2D _mesh_transform_wall_west;
|
||||
};
|
||||
|
||||
_FORCE_INLINE_ bool operator==(const Terrain2DWorld::IntPos &a, const Terrain2DWorld::IntPos &b) {
|
||||
|
Loading…
Reference in New Issue
Block a user