zephr/game: fix few memory leaks (and introduced a big one). spawn particles when tiles merge

This commit is contained in:
2024-01-27 04:05:00 +02:00
parent 98c3a0f8af
commit 292f0058d5
8 changed files with 194 additions and 24 deletions
+1
View File
@@ -119,6 +119,7 @@ x11_assign_window_icon :: proc(icon_path: cstring, window_title: cstring) {
target_size := 2 + icon_width * icon_height
data := make([]u64, target_size)
defer delete(data)
// first two elements are width and height
data[0] = cast(u64)icon_width
+7
View File
@@ -1,14 +1,21 @@
package zephr
import "core:log"
import gl "vendor:OpenGL"
import stb "vendor:stb/image"
TextureId :: u32
load_texture :: proc(path: cstring) -> TextureId {
context.logger = logger
texture_id: TextureId
width, height, channels: i32
data := stb.load(path, &width, &height, &channels, 4) // RGBA
if data == nil {
log.errorf("Failed to load texture: \"%s\"", path)
}
defer stb.image_free(data)
format := gl.RGBA
+9 -5
View File
@@ -381,13 +381,13 @@ draw_triangle :: proc(constraints: ^UiConstraints, style: UiStyle) {
gl.BindVertexArray(0)
}
draw_texture :: proc(constraints: ^UiConstraints, texture_id: TextureId, color: Color, radius: f32, align: Alignment) {
draw_texture :: proc(constraints: ^UiConstraints, texture_id: TextureId, style: UiStyle) {
use_shader(ui_shader)
set_vec4f(ui_shader, "aColor", cast(f32)color.r / 255, cast(f32)color.g / 255, cast(f32)color.b / 255, cast(f32)color.a / 255)
set_vec4f(ui_shader, "aColor", cast(f32)style.bg_color.r / 255, cast(f32)style.bg_color.g / 255, cast(f32)style.bg_color.b / 255, cast(f32)style.bg_color.a / 255)
set_float(ui_shader, "uiWidth", constraints.width)
set_float(ui_shader, "uiHeight", constraints.height)
set_float(ui_shader, "borderRadius", radius)
set_float(ui_shader, "borderRadius", style.border_radius)
set_bool(ui_shader, "hasTexture", true)
set_mat4f(ui_shader, "projection", zephr_ctx.projection)
@@ -395,7 +395,7 @@ draw_texture :: proc(constraints: ^UiConstraints, texture_id: TextureId, color:
rect: Rect = ---
apply_constraints(constraints, &rect.pos, &rect.size)
apply_alignment(align, constraints, rect.size, &rect.pos)
apply_alignment(style.align, constraints, rect.size, &rect.pos)
// set the positions after applying alignment so children can use them
constraints.x = rect.pos.x
@@ -586,7 +586,11 @@ draw_icon_button :: proc(constraints: ^UiConstraints, icon_tex_id: TextureId, st
set_y_constraint(&icon_constraints, 0, .RELATIVE_PIXELS)
set_width_constraint(&icon_constraints, constraints.width * 0.8, .FIXED)
set_height_constraint(&icon_constraints, constraints.height * 0.8, .FIXED)
draw_texture(&icon_constraints, icon_tex_id, style.fg_color, 0, .CENTER)
tex_style := UiStyle {
bg_color = style.fg_color,
align = .CENTER,
}
draw_texture(&icon_constraints, icon_tex_id, tex_style)
if (clicked && state == .ACTIVE) {
return true
+2
View File
@@ -671,6 +671,8 @@ init :: proc(font_path: cstring, icon_path: cstring, window_title: cstring, wind
deinit :: proc() {
backend_shutdown()
queue.destroy(&zephr_ctx.event_queue)
delete(zephr_ctx.ui.elements)
//audio_close()
}