1
0
Fork 0

auts: memory leak test

This commit is contained in:
coaljoe 2020-09-04 10:51:31 +03:00
parent 88ef2c0033
commit 1e07334d87
28 changed files with 232 additions and 18 deletions

View File

@ -2,7 +2,7 @@ module main
import nsauzede.vsdl2
import nsauzede.vsdl2.image as img
import time
//import time
struct App {
mut:
@ -21,6 +21,7 @@ fn new_app() &App {
a := &App{
dt: 0.0,
screen: &vsdl2.Surface(0),
}
// Update ctx

View File

@ -8,13 +8,17 @@ mut:
z int
tile_id int
open bool
wall &Wall // XXX use wall_id?
map_obj &MapObj
}
fn new_cell() Cell {
c := Cell{
wall: &Wall{0},
open: true,
wall: &Wall(0),
map_obj: &MapObj(0),
}
return c

View File

@ -10,7 +10,11 @@ pub mut:
fn new_context() &Context {
println("new_context()")
c := &Context{}
c := &Context{
app: &App(0),
drawer: &Drawer(0),
vars: &Vars(0),
}
return c
}

View File

@ -2,7 +2,8 @@ module main
//type PPType = string | int
pub fn pp(v int) {
//pub fn pp(v int) {
fn pp(v int) {
//pub fn pp(v voidptr) {
//pub fn pp(v PPType) {
//pub fn pp(v any) {

View File

@ -113,14 +113,16 @@ fn (mut v FieldView) draw_cell(c &Cell) {
//pp(2)
// Force draw
if !spr.visible {
spr.toggle_visible()
spr.draw()
spr.toggle_visible()
} else {
spr.draw()
}
spr.force_draw()
}
// XXX Draw cell's wall
if !isnil(c.map_obj) {
//w := c.wall
mut spr := c.map_obj.view.spr
//pp(2)
spr.force_draw()
}
}

View File

@ -27,9 +27,9 @@ fn (mut g Game) start() {
}
fn (mut g Game) draw() {
g.field.draw()
//g.field.draw()
g.spritesys.draw()
g.hud.draw()
//g.hud.draw()
}
fn (mut g Game) update(dt f32) {

View File

@ -78,7 +78,7 @@ fn cell_to_screen_pos2(cx, cy int) (int, int) {
return rxi, ryi
}
/*
fn screen_to_cell_pos(sx, sy int) (int, int) {
pan_x := 0
pan_y := 0
@ -116,6 +116,7 @@ fn screen_to_cell_pos(sx, sy int) (int, int) {
return cx, cy
}
*/
// XXX bad
fn screen_to_cell_pos2(sx, sy int) (int, int) {

View File

@ -81,9 +81,40 @@ fn main() {
}
f.cells[x][y].tile_id = n
// XXX place stone
if rand.intn(100) < 1 {
//max_variant := 4
max_variant := 1
mut s := new_map_obj()
//s.load()
//s.path = "stones/stone1"
s.path = "trees/tree1"
s.variant = rand.intn(max_variant)
//s.place_at(0, 0)
s.place_at(x, y)
s.spawn()
// XXX
s.view.update(0)
}
}
}
max_variant := 4
mut s := new_map_obj()
//s.load()
s.path = "stones/stone1"
s.variant = rand.intn(max_variant)
s.place_at(0, 0)
s.spawn()
// XXX
s.view.update(0)
//f.spawn()
game.start()
@ -92,6 +123,7 @@ fn main() {
mut d := ctx.drawer
tex := d.load_image_sdl_tex("res/images/heightmap.png")
_ = tex
// Sprite test
@ -177,6 +209,8 @@ fn main() {
px, py := cell_to_screen_pos(1, 1)
//px, py := cell_to_screen_pos2(1, 1)
_ = px
_ = py
//d.draw_sdl_tex(tex, px, py)

48
isotest/mapobj.v Normal file
View File

@ -0,0 +1,48 @@
module main
struct MapObj {
mut:
obj &Obj // Embed
name string
path string
variant int
/*
// XXX pos?
x int
y int
*/
view &MapObjView
}
fn new_map_obj() &MapObj {
mo := &MapObj{
obj: new_obj(),
view: &MapObjView(0),
}
return mo
}
fn (mut mo MapObj) place_at(cx, cy int) {
mo.obj.set_cx(cx)
mo.obj.set_cy(cy)
mut c := game.field.get_cell(cx, cy)
c.map_obj = mo
c.open = false
}
fn (mut mo MapObj) spawn() {
println("mapobj spawn()")
mo.view = new_map_obj_view(mo)
mo.view.spawn()
}
fn (mut mo MapObj) update(dt f32) {
}

60
isotest/mapobjview.v Normal file
View File

@ -0,0 +1,60 @@
module main
struct MapObjView {
mut:
m &MapObj
spr &Sprite
spawned bool
}
fn new_map_obj_view(m &MapObj) &MapObjView {
println("new_map_obj_view()")
v := &MapObjView{
m: m,
spr: &Sprite(0),
}
return v
}
fn (mut v MapObjView) load() {
}
fn (mut v MapObjView) spawn() {
println("mapobjview spawn()")
v.load()
v.spr = new_sprite()
path := "res/objects/" + v.m.path + "/image_${v.m.variant}.png"
v.spr.load(path)
v.spr.visible = false
v.spr.spawn()
v.spawned = true
}
fn (mut v MapObjView) draw() {
println("mapobjview draw()")
if !v.spawned {
return
}
// XXX fixme
v.update(0)
println("x: $v.spr.x, y: $v.spr.y")
}
fn (mut v MapObjView) update(dt f32) {
v.spr.x = v.m.obj.x
v.spr.y = v.m.obj.y
}

View File

@ -0,0 +1 @@
rocks_CC0.png https://opengameart.org/content/a-bunch-of-rocks CC0

BIN
isotest/res/objects/stones/stone1/image_0.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
isotest/res/objects/stones/stone1/image_1.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
isotest/res/objects/stones/stone1/image_2.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
isotest/res/objects/stones/stone1/image_3.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
isotest/res/objects/stones/stone1/image_4.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
isotest/res/objects/stones/stone1/image_5.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
isotest/res/objects/stones/stone1/rocks_CC0.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
isotest/res/objects/trees/tree1/image_0.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
isotest/res/objects/trees/tree1/image_0a.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -78,6 +78,17 @@ fn (mut s Sprite) draw() {
s.tex.draw_pos(sx, sy)
}
fn (mut s Sprite) force_draw() {
// Force draw
if !s.visible {
s.toggle_visible()
s.draw()
s.toggle_visible()
} else {
s.draw()
}
}
fn (mut s Sprite) update(dt f32) {
}

View File

@ -53,20 +53,27 @@ fn (mut s SpriteSys) draw() {
//mut sorted_elems := s.sys.elems.clone()
//sorted_elems.sort_with_compare(depth_compare)
mut sorted_sprites := []Sprite{}
///*
mut sorted_sprites := []&Sprite{}
for el in s.sys.elems {
mut x := &Sprite(el)
sorted_sprites << x
}
sorted_sprites.sort_with_compare(depth_compare)
//sorted_sprites.sort_with_compare(depth_compare)
//*/
//mut sorted_sprites := s.sys.elems
for x in sorted_sprites {
mut z := x
_ = z
z.draw()
//println(z.y)
}
sorted_sprites.clear()
//free(sorted_sprites)
//pp(3)
/*

BIN
isotest/tmp/unsort/isometric_buildings.zip (Stored with Git LFS) Normal file

Binary file not shown.

BIN
isotest/tmp/unsort/isometric_trees_pack.zip (Stored with Git LFS) Normal file

Binary file not shown.

BIN
isotest/tmp/unsort/trees_128x64_no_shadow.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
isotest/tmp/unsort/trees_test4.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -74,7 +74,7 @@ fn (mut v Viewport) update(dt f32) {
//key = game.keymap.getKey1("scrollDownKey")
key = C.SDLK_DOWN
mut pressed = ctx.app.is_key_pressed(key)
pressed = ctx.app.is_key_pressed(key)
if pressed || (m_scroll && my >= 0 && int(my) > ctx.vars.res_y-ctx.vars.scroll_padding) {
//v.y -= scrollAmt
vy = scroll_amt

View File

@ -34,6 +34,7 @@ fn (mut w Wall) place_at(cx, cy int) {
//mut c := &game.field.cells[cx][cy]
mut c := game.field.get_cell(cx, cy)
c.wall = w
c.open = false
}
fn (mut w Wall) spawn() {