mirror of
https://git.kittycat.homes/zoe/codename-routes.git
synced 2024-08-15 03:18:26 +00:00
try to optimize memory usage a tiny bit by using u16 instead of string
This commit is contained in:
parent
67d1480f35
commit
7895471778
7 changed files with 24 additions and 20 deletions
Binary file not shown.
|
@ -2,8 +2,8 @@ extends Node
|
|||
|
||||
onready var server = $StateServer
|
||||
|
||||
export var xsize = 512
|
||||
export var ysize = 512
|
||||
export var xsize = 16
|
||||
export var ysize = 16
|
||||
export var zsize = 16
|
||||
|
||||
var Tilemap = preload("res://world/Tilemap.tscn")
|
||||
|
@ -11,6 +11,7 @@ var tilemaps = []
|
|||
|
||||
func _ready():
|
||||
server.generate_world(xsize, ysize, zsize)
|
||||
print(server.get_tile_at(0,0,0))
|
||||
|
||||
func respawn_tilemaps(amount: int):
|
||||
tilemaps = []
|
||||
|
@ -28,7 +29,6 @@ func update_tiles(tile_positions: PoolVector3Array):
|
|||
for tile in tile_positions:
|
||||
tilemaps[tile.z].set_tile_graphics(Vector2(tile.x, tile.y),
|
||||
get_tile_at(tile))
|
||||
pass
|
||||
|
||||
func _on_StateServer_request_init():
|
||||
respawn_tilemaps(zsize - 1)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
extends TileMap
|
||||
|
||||
func set_tile_graphics(pos: Vector2, type: String):
|
||||
func set_tile_graphics(pos: Vector2, id: int):
|
||||
set_cell(pos.x,pos.y,0,false,false,false,Vector2(1,2))
|
||||
|
|
|
@ -11,6 +11,7 @@ crate-type = ["cdylib"]
|
|||
[dependencies]
|
||||
gdnative = {version = "0.10", features = ["async"]}
|
||||
strum = { version = "0.24", features = ["derive"] }
|
||||
strum_macros = "0.24"
|
||||
# tokio = {version = "1.18.0", features = ["sync"]}
|
||||
# lazy_static = "1.4.0"
|
||||
# pathfinding = "3.0.12"
|
||||
|
|
|
@ -40,8 +40,8 @@ impl StateServer {
|
|||
}
|
||||
|
||||
#[export]
|
||||
fn get_tile_at(&self, _owner: &Node, x: usize, y: usize, z: usize) -> &str {
|
||||
self.world.get_tile_at(x, y, z).kind_to_string()
|
||||
fn get_tile_at(&self, _owner: &Node, x: usize, y: usize, z: usize) -> u16 {
|
||||
self.world.get_tile_at(x, y, z)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,12 +6,13 @@ pub struct World {
|
|||
xsize: usize,
|
||||
ysize: usize,
|
||||
zsize: usize,
|
||||
tiles: Vec<Vec<Vec<tiles::Tile>>>,
|
||||
tiles: Vec<Vec<Vec<u16>>>,
|
||||
}
|
||||
|
||||
impl World {
|
||||
pub fn get_tile_at(&self, x: usize, y: usize, z: usize) -> &tiles::Tile{
|
||||
&self.tiles[x][y][z]
|
||||
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]
|
||||
}
|
||||
pub fn generate(&mut self) -> Vector3Array{
|
||||
self.tiles = get_vec3(self.xsize, self.ysize, self.zsize);
|
||||
|
@ -19,9 +20,8 @@ impl World {
|
|||
for x in 0..self.xsize {
|
||||
for y in 0..self.ysize {
|
||||
for z in 0..self.zsize {
|
||||
let tile = tiles::Tile::new(tiles::Tiletypes::Dirt);
|
||||
ret.push(Vector3::new(x as f32, y as f32, z as f32));
|
||||
self.tiles[x][y][z] = tile;
|
||||
self.tiles[x][y][z] = tiles::Tiletypes::Dirt as u16;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,14 +37,14 @@ impl World {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_vec3(xsize: usize, ysize: usize, zsize: usize) -> Vec<Vec<Vec<tiles::Tile>>> {
|
||||
let mut zvec: Vec<tiles::Tile> = Vec::with_capacity(zsize);
|
||||
zvec.resize(zsize, tiles::Tile::new(tiles::Tiletypes::Air));
|
||||
fn get_vec3(xsize: usize, ysize: usize, zsize: usize) -> Vec<Vec<Vec<u16>>> {
|
||||
let mut zvec: Vec<u16> = Vec::with_capacity(zsize);
|
||||
zvec.resize(zsize, 0);
|
||||
|
||||
let mut yvec: Vec<Vec<tiles::Tile>> = Vec::with_capacity(ysize);
|
||||
let mut yvec: Vec<Vec<u16>> = Vec::with_capacity(ysize);
|
||||
yvec.resize(ysize, zvec.clone());
|
||||
|
||||
let mut xvec: Vec<Vec<Vec<tiles::Tile>>> = Vec::with_capacity(xsize);
|
||||
let mut xvec: Vec<Vec<Vec<u16>>> = Vec::with_capacity(xsize);
|
||||
xvec.resize(ysize, yvec.clone());
|
||||
|
||||
yvec.push(zvec);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use strum::AsRefStr;
|
||||
use strum::{AsRefStr, EnumIter, FromRepr, EnumDiscriminants};
|
||||
|
||||
#[derive(Debug, Clone, AsRefStr, Copy)]
|
||||
|
||||
#[derive(Debug, Clone, AsRefStr, Copy, EnumIter, FromRepr, EnumDiscriminants)]
|
||||
#[repr(u16)]
|
||||
pub enum Tiletypes {
|
||||
Air,
|
||||
Water,
|
||||
|
@ -16,9 +18,10 @@ pub struct Tile {
|
|||
|
||||
impl Tile {
|
||||
pub fn new(kind: Tiletypes) -> Tile {
|
||||
|
||||
Tile { kind }
|
||||
}
|
||||
pub fn kind_to_string(&self) -> &str {
|
||||
&self.kind.as_ref()
|
||||
pub fn kind_to_string(&self) -> String {
|
||||
self.kind.as_ref().to_string()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue