mirror of
https://git.kittycat.homes/zoe/codename-routes.git
synced 2024-08-15 03:18:26 +00:00
Compare commits
No commits in common. "7825966c369c06702daef4034c8ab7bd6ac9930c" and "5b58f246a05f83c1cc47133b65d9700a9c5ef06f" have entirely different histories.
7825966c36
...
5b58f246a0
13 changed files with 35 additions and 144 deletions
|
@ -1,3 +1,3 @@
|
||||||
source_md5="30885b768ea8e61f6f1072099ba8c3af"
|
source_md5="d864960022980c4270042a1ed80b9ac4"
|
||||||
dest_md5="3858a5d8c4a4ecf0f3bd148fa4d0440a"
|
dest_md5="5f766eea69301dc969f05fac899cb4cb"
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -18,12 +18,6 @@ config/icon="res://icon.png"
|
||||||
|
|
||||||
StateServer="*res://native/StateServer.tscn"
|
StateServer="*res://native/StateServer.tscn"
|
||||||
|
|
||||||
[display]
|
|
||||||
|
|
||||||
window/size/width=1920
|
|
||||||
window/size/height=1080
|
|
||||||
window/dpi/allow_hidpi=true
|
|
||||||
|
|
||||||
[importer_defaults]
|
[importer_defaults]
|
||||||
|
|
||||||
texture={
|
texture={
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 7 KiB After Width: | Height: | Size: 6.9 KiB |
|
@ -1,9 +1,13 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
export var xsize = 64
|
export var xsize = 256
|
||||||
export var ysize = 64
|
export var ysize = 256
|
||||||
export var zsize = 6
|
export var zsize = 6
|
||||||
export var cityname = "night city"
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
StateServer.generate_world(xsize, ysize, zsize, cityname)
|
StateServer.generate_world(xsize, ysize, zsize)
|
||||||
|
print(StateServer.get_tile_at(0,0,0))
|
||||||
|
|
||||||
|
func respawn_tilemaps(amount: int):
|
||||||
|
$Tilemaps.respawn_tilemaps(amount)
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
extends TileMap
|
extends TileMap
|
||||||
|
|
||||||
func set_tile_graphics(pos: Vector2, id: int):
|
func set_tile_graphics(pos: Vector2, id: int):
|
||||||
if id == 0: set_cellv(pos, -1)
|
var flip = true
|
||||||
set_cellv(pos,0,false,false,false,get_atlas_vec_for_id(id))
|
set_cell(pos.x,pos.y,0,false,false,false,get_atlas_vec_for_id(id))
|
||||||
|
|
||||||
func get_atlas_vec_for_id(id: int) -> Vector2:
|
func get_atlas_vec_for_id(id: int) -> Vector2:
|
||||||
return Vector2(randi() % 4, id)
|
return Vector2(randi() % 4, id)
|
||||||
|
|
|
@ -21,11 +21,8 @@ func get_tile_at(pos: Vector3) -> String:
|
||||||
|
|
||||||
func update_tiles(tile_positions: PoolVector3Array):
|
func update_tiles(tile_positions: PoolVector3Array):
|
||||||
for tile in tile_positions:
|
for tile in tile_positions:
|
||||||
if !StateServer.is_tile_hidden(int(tile.x), int(tile.y), int(tile.z)):
|
|
||||||
tilemaps[tile.z].set_tile_graphics(Vector2(tile.x, tile.y),
|
tilemaps[tile.z].set_tile_graphics(Vector2(tile.x, tile.y),
|
||||||
get_tile_at(tile))
|
get_tile_at(tile))
|
||||||
for map in tilemaps:
|
|
||||||
map.update_dirty_quadrants()
|
|
||||||
|
|
||||||
func _on_StateServer_request_init():
|
func _on_StateServer_request_init():
|
||||||
call_deferred("respawn_tilemaps")
|
call_deferred("respawn_tilemaps")
|
||||||
|
|
Binary file not shown.
|
@ -13,8 +13,9 @@ gdnative = {version = "0.10", features = ["async"]}
|
||||||
strum = { version = "0.24", features = ["derive"] }
|
strum = { version = "0.24", features = ["derive"] }
|
||||||
strum_macros = "0.24"
|
strum_macros = "0.24"
|
||||||
derive_builder = "0.11.2"
|
derive_builder = "0.11.2"
|
||||||
rand_seeder = "0.2.3"
|
# tokio = {version = "1.18.0", features = ["sync"]}
|
||||||
rand = "0.8.5"
|
# lazy_static = "1.4.0"
|
||||||
|
# pathfinding = "3.0.12"
|
||||||
toml = "0.5.9"
|
toml = "0.5.9"
|
||||||
|
|
||||||
[profile.dev.package."*"]
|
[profile.dev.package."*"]
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub struct StateServer {
|
||||||
impl StateServer {
|
impl StateServer {
|
||||||
fn new(_owner: &Node) -> Self {
|
fn new(_owner: &Node) -> Self {
|
||||||
StateServer {
|
StateServer {
|
||||||
world: world::World::new(0, 0, 0, "seed".to_string()),
|
world: world::World::new(0, 0, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ impl StateServer {
|
||||||
fn _ready(&self, _owner: &Node) {}
|
fn _ready(&self, _owner: &Node) {}
|
||||||
|
|
||||||
#[export]
|
#[export]
|
||||||
fn generate_world(&mut self, _owner: &Node, xsize: usize, ysize: usize, zsize: usize, seed: String) {
|
fn generate_world(&mut self, _owner: &Node, xsize: usize, ysize: usize, zsize: usize) {
|
||||||
self.world = world::World::new(xsize, ysize, zsize, seed);
|
self.world = world::World::new(xsize, ysize, zsize);
|
||||||
let w = self.world.generate();
|
let w = self.world.generate();
|
||||||
_owner.emit_signal("request_init", &[]);
|
_owner.emit_signal("request_init", &[]);
|
||||||
_owner.emit_signal("changed_tiletypes", &[Variant::new(&w)]);
|
_owner.emit_signal("changed_tiletypes", &[Variant::new(&w)]);
|
||||||
|
@ -41,22 +41,13 @@ impl StateServer {
|
||||||
|
|
||||||
#[export]
|
#[export]
|
||||||
fn get_world_size(&self, _ownser: &Node) -> Vector3 {
|
fn get_world_size(&self, _ownser: &Node) -> Vector3 {
|
||||||
Vector3::new(
|
Vector3::new(self.world.xsize as f32, self.world.ysize as f32, self.world.zsize as f32)
|
||||||
self.world.xsize as f32,
|
|
||||||
self.world.ysize as f32,
|
|
||||||
self.world.zsize as f32,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export]
|
#[export]
|
||||||
fn get_tile_at(&self, _owner: &Node, x: usize, y: usize, z: usize) -> u16 {
|
fn get_tile_at(&self, _owner: &Node, x: usize, y: usize, z: usize) -> u16 {
|
||||||
self.world.get_tile_at(x, y, z)
|
self.world.get_tile_at(x, y, z)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export]
|
|
||||||
fn is_tile_hidden(&self, _owner: &Node, x: usize, y: usize, z: usize) -> bool {
|
|
||||||
self.world.is_tile_hidden(x, y, z)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// signals
|
// signals
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
use gdnative::prelude::*;
|
use gdnative::prelude::*;
|
||||||
use rand::prelude::StdRng;
|
|
||||||
use rand::prelude::*;
|
|
||||||
use rand_seeder::Seeder;
|
|
||||||
use strum::EnumCount;
|
|
||||||
|
|
||||||
mod tiles;
|
mod tiles;
|
||||||
|
|
||||||
|
@ -11,75 +7,32 @@ pub struct World {
|
||||||
pub ysize: usize,
|
pub ysize: usize,
|
||||||
pub zsize: usize,
|
pub zsize: usize,
|
||||||
tiles: Vec<Vec<Vec<tiles::Tiletypes>>>,
|
tiles: Vec<Vec<Vec<tiles::Tiletypes>>>,
|
||||||
seed: String,
|
|
||||||
tileattributes: tiles::Attributelists,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl World {
|
impl World {
|
||||||
pub fn get_tile_at(&self, x: usize, y: usize, z: usize) -> u16{
|
pub fn get_tile_at(&self, x: usize, y: usize, z: usize) -> u16{
|
||||||
|
//TODO: error handling, or maybe just do that in godot
|
||||||
self.tiles[x][y][z] as u16
|
self.tiles[x][y][z] as u16
|
||||||
}
|
}
|
||||||
pub fn is_tile_hidden(&self, x: usize, y: usize, z: usize) -> bool {
|
|
||||||
if x == self.xsize - 1 || y == self.ysize - 1 || z == self.zsize - 1 {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if !tiles::Tile::new(self.tiles[x + 1][y][z]).hide_top_left
|
|
||||||
|| !tiles::Tile::new(self.tiles[x][y + 1][z]).hide_top_right
|
|
||||||
|| !tiles::Tile::new(self.tiles[x][y][z + 1]).hide_below
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn generate(&mut self) -> Vector3Array{
|
pub fn generate(&mut self) -> Vector3Array{
|
||||||
let mut rng: StdRng = Seeder::from(self.seed.to_owned()).make_rng();
|
|
||||||
self.tiles = get_vec3(self.xsize, self.ysize, self.zsize);
|
self.tiles = get_vec3(self.xsize, self.ysize, self.zsize);
|
||||||
let mut ret: Vector3Array = Vector3Array::new();
|
let mut ret: Vector3Array = Vector3Array::new();
|
||||||
for x in 0..self.xsize {
|
for x in 0..self.xsize {
|
||||||
for y in 0..self.ysize {
|
for y in 0..self.ysize {
|
||||||
for z in 0..self.zsize {
|
for z in 0..self.zsize {
|
||||||
ret.push(Vector3::new(x as f32, y as f32, z as f32));
|
ret.push(Vector3::new(x as f32, y as f32, z as f32));
|
||||||
self.tiles[x][y][z] = self.new_tile_init_step(x, y, z, &mut rng)
|
self.tiles[x][y][z] = tiles::Tiletypes::Grass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
pub fn new(xsize: usize, ysize: usize, zsize: usize) -> World {
|
||||||
fn new_tile_init_step(&self, x: usize, y: usize, z: usize, rng: &mut StdRng) -> tiles::Tiletypes {
|
|
||||||
// first generate bedrock
|
|
||||||
if z == 0 {
|
|
||||||
if y == 0 || x == 0 || y == self.ysize - 1 || x == self.xsize - 1{
|
|
||||||
return tiles::Tiletypes::Water;
|
|
||||||
}
|
|
||||||
let random = rng.gen_range(0..3) as u8;
|
|
||||||
match random {
|
|
||||||
0 => return tiles::Tiletypes::Grass,
|
|
||||||
_ => return self.tileattributes.bedrock.choose(rng).unwrap().to_owned(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// then make sure the top row of tiles is air
|
|
||||||
if z == self.zsize - 1
|
|
||||||
|| !tiles::Tile::new(self.tiles[x][y][z - 1]).is_support
|
|
||||||
|| tiles::Tile::new(self.tiles[x][y][z - 1]).must_be_on_top
|
|
||||||
{
|
|
||||||
return tiles::Tiletypes::Air;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if no tile fits, then return air
|
|
||||||
tiles::Tiletypes::Air
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new(xsize: usize, ysize: usize, zsize: usize, seed: String) -> World {
|
|
||||||
World {
|
World {
|
||||||
xsize,
|
xsize,
|
||||||
ysize,
|
ysize,
|
||||||
zsize,
|
zsize,
|
||||||
tiles: get_vec3(xsize, ysize, zsize),
|
tiles: get_vec3(xsize, ysize, zsize),
|
||||||
seed,
|
|
||||||
tileattributes: tiles::Attributelists::new(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use derive_builder::Builder;
|
use derive_builder::Builder;
|
||||||
use strum::{AsRefStr, EnumCount, EnumDiscriminants, EnumIter, FromRepr, IntoEnumIterator};
|
use strum::{AsRefStr, EnumDiscriminants, EnumIter, FromRepr};
|
||||||
|
|
||||||
#[derive(AsRefStr, EnumIter, FromRepr, EnumDiscriminants, Clone, Copy, PartialEq, EnumCount)]
|
#[derive(AsRefStr, EnumIter, FromRepr, EnumDiscriminants, Clone, Copy)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Tiletypes {
|
pub enum Tiletypes {
|
||||||
Air,
|
Air,
|
||||||
|
@ -9,7 +9,6 @@ pub enum Tiletypes {
|
||||||
Grass,
|
Grass,
|
||||||
Dirt,
|
Dirt,
|
||||||
Sand,
|
Sand,
|
||||||
Rock,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
@ -17,68 +16,20 @@ pub enum Tiletypes {
|
||||||
pub struct Tile {
|
pub struct Tile {
|
||||||
kind: Tiletypes,
|
kind: Tiletypes,
|
||||||
#[builder(default = "true")]
|
#[builder(default = "true")]
|
||||||
pub is_support: bool,
|
is_support: bool,
|
||||||
#[builder(default = "true")]
|
#[builder(default = "true")]
|
||||||
pub hide_top_left: bool,
|
needs_support: bool,
|
||||||
#[builder(default = "true")]
|
#[builder(default = "vec![]")]
|
||||||
pub hide_top_right: bool,
|
can_be_above: Vec<Tiletypes>,
|
||||||
#[builder(default = "true")]
|
#[builder(default = "vec![]")]
|
||||||
pub hide_below: bool,
|
can_be_next_to: Vec<Tiletypes>,
|
||||||
#[builder(default = "false")]
|
|
||||||
pub must_be_on_top: bool,
|
|
||||||
#[builder(default = "true")]
|
|
||||||
pub can_be_bedrock: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tile {
|
impl Tile {
|
||||||
pub fn new(kind: Tiletypes) -> Tile {
|
pub fn new(kind: Tiletypes) -> Tile {
|
||||||
let tile: Tile;
|
TileBuilder::default().kind(kind).is_support(false).build().unwrap()
|
||||||
match kind {
|
|
||||||
Tiletypes::Air => {
|
|
||||||
tile = TileBuilder::default()
|
|
||||||
.kind(kind)
|
|
||||||
.is_support(false)
|
|
||||||
.hide_below(false)
|
|
||||||
.hide_top_right(false)
|
|
||||||
.hide_top_left(false)
|
|
||||||
.can_be_bedrock(false)
|
|
||||||
.build()
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
Tiletypes::Water => {
|
|
||||||
tile = TileBuilder::default()
|
|
||||||
.kind(kind)
|
|
||||||
.is_support(false)
|
|
||||||
.build()
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
Tiletypes::Grass => {
|
|
||||||
tile = TileBuilder::default()
|
|
||||||
.kind(kind)
|
|
||||||
.must_be_on_top(true)
|
|
||||||
.build()
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
_ => tile = TileBuilder::default().kind(kind).build().unwrap(),
|
|
||||||
};
|
|
||||||
tile
|
|
||||||
}
|
}
|
||||||
pub fn kind_to_string(&self) -> String {
|
pub fn kind_to_string(&self) -> String {
|
||||||
self.kind.as_ref().to_string()
|
self.kind.as_ref().to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Attributelists {
|
|
||||||
pub bedrock: Vec<Tiletypes>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Attributelists {
|
|
||||||
pub fn new() -> Attributelists{
|
|
||||||
let mut bedrock: Vec<Tiletypes> = vec![];
|
|
||||||
for tiletype in Tiletypes::iter(){
|
|
||||||
let tile = Tile::new(tiletype);
|
|
||||||
if tile.can_be_bedrock { bedrock.push(tiletype); }
|
|
||||||
}
|
|
||||||
Attributelists { bedrock }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue