mirror of
				https://git.kittycat.homes/zoe/codename-routes.git
				synced 2024-08-15 03:18:26 +00:00 
			
		
		
		
	add generate world method
This commit is contained in:
		
							parent
							
								
									47b9179c67
								
							
						
					
					
						commit
						a5fd29fc39
					
				
					 8 changed files with 90 additions and 26 deletions
				
			
		
										
											Binary file not shown.
										
									
								
							|  | @ -4,4 +4,4 @@ var server = preload("res://native/StateServer.tscn").instance() | ||||||
| 
 | 
 | ||||||
| func _ready(): | func _ready(): | ||||||
| 	add_child(server) | 	add_child(server) | ||||||
| 	server.foo() | 	server.generate_world() | ||||||
|  |  | ||||||
|  | @ -13,3 +13,4 @@ gdnative = "0.10" | ||||||
| tokio = {version = "1.18.0", features = ["sync"]} | tokio = {version = "1.18.0", features = ["sync"]} | ||||||
| lazy_static = "1.4.0" | lazy_static = "1.4.0" | ||||||
| pathfinding = "3.0.12" | pathfinding = "3.0.12" | ||||||
|  | toml = "0.5.9" | ||||||
|  |  | ||||||
|  | @ -1,44 +1,51 @@ | ||||||
| use gdnative::prelude::*; | use gdnative::prelude::*; | ||||||
| use lazy_static::lazy_static; | use lazy_static::lazy_static; | ||||||
| use pathfinding::matrix; |  | ||||||
| use tokio::sync::RwLock; | use tokio::sync::RwLock; | ||||||
| 
 | 
 | ||||||
| mod pathing; | mod saves; | ||||||
| mod terrain; | mod terrain; | ||||||
| mod tiles; | mod world; | ||||||
| 
 | 
 | ||||||
| lazy_static! { | lazy_static! { | ||||||
|     static ref STATE: RwLock<matrix::Matrix<Vec<terrain::Terrain>>> = RwLock::new(matrix![]); |     static ref WORLD: RwLock<Vec<Vec<Vec<u8>>>> = RwLock::new(vec![vec![vec![]]]); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(NativeClass)] | #[derive(NativeClass)] | ||||||
| #[inherit(Node)] | #[inherit(Node)] | ||||||
| pub struct StateServer { | pub struct StateServer { | ||||||
|     #[property] |     #[property] | ||||||
|     xsize: u64, |     a: u64, | ||||||
|     #[property] |  | ||||||
|     ysize: u64, |  | ||||||
|     #[property] |  | ||||||
|     zsize: u64, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[methods] | #[methods] | ||||||
| impl StateServer { | impl StateServer { | ||||||
|     fn new(_owner: &Node) -> Self { |     fn new(_owner: &Node) -> Self { | ||||||
|         StateServer { |         StateServer { a: 14 } | ||||||
|             xsize: 14, |  | ||||||
|             ysize: 14, |  | ||||||
|             zsize: 14, |  | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     #[export] | ||||||
|  |     fn load_from_file(&self, _owner: &Node, file: GodotString) { | ||||||
|  |         saves::load(&file.to_string()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     #[export] | ||||||
|  |     fn save_from_file(&self, _owner: &Node, file: GodotString) { | ||||||
|  |         saves::save(&file.to_string()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[export] |     #[export] | ||||||
|     fn _ready(&self, _owner: &Node) { |     fn _ready(&self, _owner: &Node) { | ||||||
|         godot_print!("size: {}", self.xsize) |         godot_print!("hello!") | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[export] |     #[export] | ||||||
|     fn foo(&self, _owner: &Node) { |     fn foo(&self, _owner: &Node) { | ||||||
|         godot_print!("bar") |         godot_print!("bar") | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     #[export] | ||||||
|  |     fn generate_world(&self, _owner: &Node){ | ||||||
|  |         let new_world = world::World::new(3,3,3); | ||||||
|  |         new_world.generate(); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										9
									
								
								routes-native/src/stateserver/saves.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								routes-native/src/stateserver/saves.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,9 @@ | ||||||
|  | use toml; | ||||||
|  | 
 | ||||||
|  | pub fn load (file: &str){ | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | pub fn save (file: &str){ | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -1,10 +0,0 @@ | ||||||
| use gdnative::derive::{FromVariant, ToVariant}; |  | ||||||
| 
 |  | ||||||
| #[derive(ToVariant, FromVariant)] |  | ||||||
| pub enum Tiletypes { |  | ||||||
|     Air, |  | ||||||
|     Water, |  | ||||||
|     Grass, |  | ||||||
|     Dirt, |  | ||||||
|     Sand, |  | ||||||
| } |  | ||||||
							
								
								
									
										37
									
								
								routes-native/src/stateserver/world.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								routes-native/src/stateserver/world.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,37 @@ | ||||||
|  | use gdnative::prelude::*; | ||||||
|  | 
 | ||||||
|  | mod tiles; | ||||||
|  | 
 | ||||||
|  | pub struct World { | ||||||
|  |     xsize: usize, | ||||||
|  |     ysize: usize, | ||||||
|  |     zsize: usize, | ||||||
|  |     tiles: Vec<Vec<Vec<tiles::Tile>>>, | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl World { | ||||||
|  |     pub fn generate(&self) { | ||||||
|  |         for x in 0..self.xsize { | ||||||
|  |             for y in 0..self.ysize { | ||||||
|  |                 for z in 0..self.zsize { | ||||||
|  |                     godot_print!("hello, {} {} {}", x, y, z); | ||||||
|  | 
 | ||||||
|  |                     // self.tiles[x][y][z] = tiles::Tile::new(tiles::Tiletypes::Dirt, x, y, z);
 | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     pub fn new(xsize: usize, ysize: usize, zsize: usize) -> World { | ||||||
|  |         let z: Vec<tiles::Tile> = Vec::with_capacity(zsize); | ||||||
|  |         let mut y: Vec<Vec<tiles::Tile>> = Vec::with_capacity(ysize); | ||||||
|  |         let mut x: Vec<Vec<Vec<tiles::Tile>>> = Vec::with_capacity(xsize); | ||||||
|  |         y.push(z); | ||||||
|  |         x.push(y); | ||||||
|  |         World { | ||||||
|  |             xsize, | ||||||
|  |             ysize, | ||||||
|  |             zsize, | ||||||
|  |             tiles: x, | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										20
									
								
								routes-native/src/stateserver/world/tiles.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								routes-native/src/stateserver/world/tiles.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,20 @@ | ||||||
|  | pub enum Tiletypes { | ||||||
|  |     Air, | ||||||
|  |     Water, | ||||||
|  |     Grass, | ||||||
|  |     Dirt, | ||||||
|  |     Sand, | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | pub struct Tile { | ||||||
|  |     kind: Tiletypes, | ||||||
|  |     x: usize, | ||||||
|  |     y: usize, | ||||||
|  |     z: usize, | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl Tile { | ||||||
|  |     pub fn new(kind: Tiletypes, x: usize, y: usize, z: usize) -> Tile { | ||||||
|  |         Tile { kind, x, y, z } | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue