diff --git a/edit2d.odin b/edit2d.odin index 0a98ce3..309f472 100644 --- a/edit2d.odin +++ b/edit2d.odin @@ -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 } diff --git a/entity.odin b/entity.odin index 2212687..f0113b8 100644 --- a/entity.odin +++ b/entity.odin @@ -114,7 +114,7 @@ compare_engine_entity_def :: proc(a, b : Engine_Entity_Def) -> bool -engine_entity :: struct { +Engine_Entity :: struct { body_id : b2.BodyId, shape_id : b2.ShapeId, @@ -129,12 +129,12 @@ engine_entity :: struct { -engine_entity_single_body :: proc(def : ^Engine_Entity_Def, world_id: b2.WorldId, index : i32) -> engine_entity +engine_entity_single_body :: proc(def : ^Engine_Entity_Def, world_id: b2.WorldId, index : i32) -> Engine_Entity { def := def - new_entity : engine_entity + new_entity : Engine_Entity if def.index != 0 @@ -270,7 +270,7 @@ engine_create_chain_shape :: proc( def : ^Engine_Entity_Def, world_id : b2.WorldId, index : i32 - ) -> engine_entity + ) -> Engine_Entity { joint_def := def.rev_joint orig_pos := def.body_def.position @@ -311,7 +311,7 @@ engine_create_entity :: proc( def : ^Engine_Entity_Def, world_id : b2.WorldId, index : i32 - ) -> engine_entity + ) -> Engine_Entity { if .CHAIN not_in def.entity_flags diff --git a/glyph/glyph.odin b/glyph/glyph.odin index 54c24ec..59b343f 100644 --- a/glyph/glyph.odin +++ b/glyph/glyph.odin @@ -126,7 +126,7 @@ glyph_draw_font :: proc(glyph_state: ^GlyphState, text: string, pos : [2]f32, co text_color: [4]f32 = {f32( color.r)/ 255.0 ,f32(color.g)/255.0, f32(color.b)/255.0, f32(color.a)/255.0} - glyph_state.rect_buffer = make([dynamic]GlyphRectInstance, 0, 1000) + //glyph_state.rect_buffer = make([dynamic]GlyphRectInstance, 0, 1000) { //put every glyph in text into rect_buffer @@ -147,7 +147,6 @@ glyph_draw_font :: proc(glyph_state: ^GlyphState, text: string, pos : [2]f32, co prev_codepoint: rune = 0 - delete(glyph_state.rect_buffer) glyph_state.rect_buffer = make([dynamic]GlyphRectInstance, 0, 1000) glyph_state.curr = pos glyph_state.curr.y += math.round(baseline) @@ -329,4 +328,5 @@ glyph_draw_font :: proc(glyph_state: ^GlyphState, text: string, pos : [2]f32, co gl.InvalidateBufferData(glyph_state.rect_instances_vbo) } + delete(glyph_state.rect_buffer) } diff --git a/handle_input.odin b/handle_input.odin index 2bcf059..577ecf9 100644 --- a/handle_input.odin +++ b/handle_input.odin @@ -143,9 +143,9 @@ handle_entity_mode :: proc( def.body_def.position = mpos ret = true } - else if state.input.mouse_wheel.y != 0 + else if __e2d_interal.mouse_scroll.y != 0 { - def.scale += f32(state.input.mouse_prev.y / 5) + def.scale += f32( __e2d_interal.mouse_scroll.y / 5) ret = true } } diff --git a/interface.odin b/interface.odin index adba3b5..64789e9 100644 --- a/interface.odin +++ b/interface.odin @@ -33,13 +33,13 @@ Edit_Mode :: enum Interface_State :: struct { entity_defs : [dynamic]^Engine_Entity_Def, - entities : [dynamic]^engine_entity, + entities : [dynamic]^Engine_Entity, selected_entity : i32, world : ^Engine_World, state : ^Engine_State, - vertex_index : ^i32, - chain_index : ^i32, + vertex_index : i32, + chain_index : i32, edit_mode : Edit_Mode, @@ -97,38 +97,14 @@ mui_text_height :: proc(font: mu.Font) -> i32 interface_get_default :: proc(interface: ^Interface_State) { interface.selected_entity = 0 - interface.vertex_index = new(i32) - interface.vertex_index^ = 0 - interface.chain_index = new(i32) - interface.chain_index^ = 0 + interface.vertex_index = 0 + interface.chain_index = 0 } -/* -interface_draw_options :: proc(state: ^engine_state) -{ - debug_draw := &state.debug_draw - - im.SliderFloat("Zoom", &state.draw.cam.zoom, 0, 100) - im.Checkbox("Shapes", &debug_draw.drawShapes) - im.Checkbox("Joints", &debug_draw.drawJoints) - im.Checkbox("Joint Extras", &debug_draw.drawJointExtras) - im.Checkbox("Bounds", &debug_draw.drawBounds) - im.Checkbox("Contact Points", &debug_draw.drawContacts) - im.Checkbox("Contact Normals", &debug_draw.drawContactNormals) - im.Checkbox("Contact Inpulses", &debug_draw.drawContactImpulses) - im.Checkbox("Contact Features", &debug_draw.drawContactFeatures) - im.Checkbox("Friction Inpulses", &debug_draw.drawFrictionImpulses) - im.Checkbox("Mass ", &debug_draw.drawMass) - im.Checkbox("Body Names", &debug_draw.drawBodyNames) - im.Checkbox("Graph Colors", &debug_draw.drawGraphColors) - im.Checkbox("Islands ", &debug_draw.drawIslands) - im.SliderFloat("Rotation", &state.draw.cam.rotation, 0, 360) -} -*/ - mu_interface_game_mode :: proc(state: ^Engine_State, interface: ^Interface_State) { - if mu.begin_window(&state.mu_ctx, "Edit Mode", {1630, 0, 250, 170}) + width :i32 = 250 + if mu.begin_window(&state.mu_ctx, "Edit Mode", {state.width - width, 0, width, 170}) { for type in Edit_Mode { @@ -141,7 +117,7 @@ mu_interface_game_mode :: proc(state: ^Engine_State, interface: ^Interface_State mu_interface_draw_options :: proc(state: ^Engine_State) { - if mu.begin_window(&state.mu_ctx, "Options", {200, 150, 200, 400}){ + if mu.begin_window(&state.mu_ctx, "Options", {0, 150, 200, 400}){ debug_draw := &state.debug_draw mu.label(&state.mu_ctx, "Zoom") @@ -177,18 +153,15 @@ interface_all :: proc($E: typeid, interface: ^Interface_State, game_data : $G) - interface.selected_entity = 0 } - - //if handle_input(E, interface.state, game_data) do return true - state := interface.state mu.begin(&state.mu_ctx) - //test_window(&state.mu_ctx) mu_interface_draw_options(interface.state) mu_interface_game_mode(state, interface) - if mu.begin_window(&state.mu_ctx, "B2d Interface", {1630, 170, 250, 450}) + width : i32 = 250 + if mu.begin_window(&state.mu_ctx, "B2d Interface", {state.width - width, 170, width, 450}, { .NO_TITLE}) { if interface.edit_mode == .ENTITY @@ -203,9 +176,7 @@ interface_all :: proc($E: typeid, interface: ^Interface_State, game_data : $G) - //if interface_joints(interface) do ret = true - mu.end(&state.mu_ctx) - //im.End() return ret }