Remove pointer index, fix memoery leak in glyph

This commit is contained in:
SamratGhale
2026-03-29 06:34:00 +05:45
parent c1b64e9066
commit 06664f9f67
5 changed files with 47 additions and 57 deletions
+28 -9
View File
@@ -12,7 +12,6 @@ import "shared:odin-imgui/imgui_impl_glfw"
import "shared:odin-imgui/imgui_impl_opengl3"
**/
import "core:fmt"
import gl "vendor:OpenGL"
import "vendor:glfw"
import e2_draw "shared:Edit2D/draw"
@@ -28,6 +27,10 @@ __e2d_interal : struct
}
/*
This engine is meant to be used by the game
All the stuffs internal should be stored in __e2d_internal
*/
Engine_State :: struct
{
@@ -41,13 +44,14 @@ Engine_State :: struct
//Must be set before calling ion_init
width, height : i32,
title : cstring,
time : f32,
tex_line : u32,
drop_callback : glfw.DropProc,
input : Input_State,
mu_ctx : mu.Context,
/* The opengl texture id created using mu.default_atlas_alpha */
mu_tex : u32,
}
@@ -55,7 +59,6 @@ MAX_KEYS :: 512
Input_State :: struct
{
mouse_wheel : [2]f64,
mouse : [2]f64,
mouse_prev : [2]f64,
@@ -105,7 +108,7 @@ engine_check_types :: proc($Game: typeid)
assert(entity_engine.is_using, "Should be using")
assert(defs_engine.is_using, "Should be using")
assert(entity_engine.type.id == typeid_of(engine_entity))
assert(entity_engine.type.id == typeid_of(Engine_Entity))
assert(defs_engine.type.id == typeid_of(Engine_Entity_Def))
}
@@ -162,13 +165,23 @@ engine_init :: proc($GameType : typeid, state: ^Engine_State, font_path : strin
draw_configure_box2d(state)
cbor.tag_register_type({
marshal = proc(_: ^cbor.Tag_Implementation, e: cbor.Encoder, v: any) -> cbor.Marshal_Error {
marshal = proc(
_: ^cbor.Tag_Implementation,
e: cbor.Encoder, v: any) -> cbor.Marshal_Error
{
cbor._encode_u8(e.writer, 201, .Tag) or_return
return nil;
},
unmarshal = proc(_: ^cbor.Tag_Implementation, d: cbor.Decoder, _: cbor.Tag_Number, v: any) -> (cbor.Unmarshal_Error) {
unmarshal = proc(
_: ^cbor.Tag_Implementation,
d: cbor.Decoder, _: cbor.Tag_Number,
v: any) -> (cbor.Unmarshal_Error)
{
return nil
},
}, 201, rawptr)
@@ -208,7 +221,6 @@ normalize_rect :: proc(rect : mu.Rect, size : i32) -> e2_draw.Rect
update_frame :: proc(state: ^Engine_State)
{
state.input.mouse_wheel = {}
__e2d_interal.mouse_scroll = {}
glfw.PollEvents()
@@ -258,6 +270,7 @@ end_frame :: proc(state: ^Engine_State)
cmd: ^mu.Command
draw := &state.draw
for mu.next_command(&state.mu_ctx, &cmd)
{
#partial switch c in cmd.variant{
@@ -360,10 +373,16 @@ draw_flush :: proc(state: ^Engine_State)
d.glyph.width = d.cam.width
d.glyph.height = d.cam.height
width, height := glfw.GetFramebufferSize(state.window)
state.width = width
state.height = height
e2_glyph.glyph_init(&d.glyph, d.font_path)
}
e2_draw.draw_flush(d, __e2d_interal.viewport_changed)
glfw.SwapBuffers(state.window)
__e2d_interal.viewport_changed = false
}