This commit is contained in:
luboslenco
2025-03-02 21:07:17 +01:00
parent 32bc073574
commit c8a667bfee
59 changed files with 371 additions and 509 deletions
+2 -2
View File
@@ -24,14 +24,14 @@ function app_w(): i32 {
if (app_on_w != null) {
return app_on_w();
}
return sys_width();
return kinc_window_width();
}
function app_h(): i32 {
if (app_on_h != null) {
return app_on_h();
}
return sys_height();
return kinc_window_height();
}
function app_x(): i32 {
+6 -6
View File
@@ -10,7 +10,7 @@ let data_cached_shaders: map_t<string, shader_data_t> = map_create();
let data_cached_blobs: map_t<string, buffer_t> = map_create();
let data_cached_images: map_t<string, image_t> = map_create();
let data_cached_videos: map_t<string, video_t> = map_create();
let data_cached_fonts: map_t<string, g2_font_t> = map_create();
let data_cached_fonts: map_t<string, draw_font_t> = map_create();
///if arm_audio
let data_cached_sounds: map_t<string, sound_t> = map_create();
///end
@@ -140,14 +140,14 @@ function data_get_video(file: string): video_t {
return null;
}
function data_get_font(file: string): g2_font_t {
let cached: g2_font_t = map_get(data_cached_fonts, file);
function data_get_font(file: string): draw_font_t {
let cached: draw_font_t = map_get(data_cached_fonts, file);
if (cached != null) {
return cached;
}
let blob: buffer_t = iron_load_blob(data_resolve_path(file));
let b: g2_font_t = g2_font_create(blob);
let b: draw_font_t = g2_font_create(blob);
map_set(data_cached_fonts, file, b);
data_assets_loaded++;
return b;
@@ -203,7 +203,7 @@ function data_delete_video(handle: string) {
}
function data_delete_font(handle: string) {
let font: g2_font_t = map_get(data_cached_fonts, handle);
let font: draw_font_t = map_get(data_cached_fonts, handle);
if (font == null) {
return;
}
@@ -269,7 +269,7 @@ function data_delete_all() {
let cached_fonts_keys: string[] = map_keys(data_cached_fonts);
for (let i: i32 = 0; i < cached_fonts_keys.length; ++i) {
let c: g2_font_t = map_get(data_cached_fonts, cached_fonts_keys[i]);
let c: draw_font_t = map_get(data_cached_fonts, cached_fonts_keys[i]);
g2_font_unload(c);
}
data_cached_fonts = map_create();
+27 -46
View File
@@ -1,17 +1,18 @@
declare type g2_font_t = {
font_?: any; // draw_font_t
blob?: buffer_t;
declare type draw_font_t = {
blob?: any; // unsigned char *
images: any; // draw_font_image_t *
m_capacity?: i32;
m_images_len?: i32;
offset?: 32;
buf?: buffer_t;
glyphs?: i32[];
index?: i32;
};
let _g2_color: color_t;
let _g2_font: g2_font_t;
let _g2_font: draw_font_t;
let _g2_font_size: i32 = 0;
let _g2_pipeline: pipeline_t;
let _g2_transformation: mat3_t = mat3_nan();
let _g2_render_target: image_t;
let _g2_current: image_t = null;
let _g2_in_use: bool = false;
@@ -21,17 +22,12 @@ let _g2_thrown: bool = false;
let _g2_mat: f32_array_t = f32_array_create(9);
let _g2_initialized: bool = false;
function g2_set_color(c: color_t) {
draw_set_color(c);
_g2_color = c;
}
function g2_set_font_and_size(font: g2_font_t, font_size: i32) {
function g2_set_font_and_size(font: draw_font_t, font_size: i32) {
g2_font_init(font);
draw_set_font(font.font_, font_size);
draw_set_font(font, font_size);
}
function g2_set_font(f: g2_font_t) {
function g2_set_font(f: draw_font_t) {
if (_g2_font_size != 0) {
g2_set_font_and_size(f, _g2_font_size);
}
@@ -39,7 +35,7 @@ function g2_set_font(f: g2_font_t) {
}
function g2_set_font_size(i: i32) {
if (_g2_font.font_ != null) {
if (_g2_font != null) {
g2_set_font_and_size(_g2_font, i);
}
_g2_font_size = i;
@@ -47,7 +43,6 @@ function g2_set_font_size(i: i32) {
function g2_set_pipeline(p: pipeline_t) {
draw_set_pipeline(p == null ? null : p.pipeline_);
_g2_pipeline = p;
}
function g2_set_transformation(m: mat3_t) {
@@ -90,16 +85,6 @@ function g2_init() {
}
}
function g2_scissor(x: i32, y: i32, width: i32, height: i32) {
draw_end(); // flush
g4_scissor(x, y, width, height);
}
function g2_disable_scissor() {
draw_end(); // flush
g4_disable_scissor();
}
function g2_begin(render_target: image_t = null) {
if (_g2_in_use && !_g2_thrown) {
_g2_thrown = true;
@@ -129,47 +114,43 @@ function g2_end() {
draw_end();
}
function g2_clear(color: color_t = 0x00000000) {
g4_clear(color);
}
function g2_font_init(raw: g2_font_t) {
function g2_font_init(raw: draw_font_t) {
if (_g2_font_glyphs_last != _g2_font_glyphs) {
_g2_font_glyphs_last = _g2_font_glyphs;
draw_font_set_glyphs(_g2_font_glyphs);
}
if (raw.glyphs != _g2_font_glyphs) {
raw.glyphs = _g2_font_glyphs;
raw.font_ = draw_font_init(raw.blob, raw.index);
draw_font_init(raw, raw.buf.buffer, raw.index);
}
}
function g2_font_create(blob: buffer_t, index: i32 = 0): g2_font_t {
let raw: g2_font_t = {};
raw.blob = blob;
function g2_font_create(buf: buffer_t, index: i32 = 0): draw_font_t {
let raw: draw_font_t = {};
raw.buf = buf;
raw.index = index;
return raw;
}
function g2_font_height(raw: g2_font_t, size: i32): f32 {
function g2_font_height(raw: draw_font_t, size: i32): f32 {
g2_font_init(raw);
return draw_font_height(raw.font_, size);
return draw_font_height(raw, size);
}
function g2_font_width(raw: g2_font_t, size: i32, str: string): f32 {
function g2_font_width(raw: draw_font_t, size: i32, str: string): f32 {
g2_font_init(raw);
return draw_string_width(raw.font_, size, str);
return draw_string_width(raw, size, str);
}
function g2_font_unload(raw: g2_font_t) {
raw.blob = null;
function g2_font_unload(raw: draw_font_t) {
raw.buf = null;
}
function g2_font_set_font_index(raw: g2_font_t, index: i32) {
function g2_font_set_font_index(raw: draw_font_t, index: i32) {
raw.index = index;
_g2_font_glyphs = array_slice(_g2_font_glyphs, 0, _g2_font_glyphs.length); // Trigger atlas update
}
function g2_font_clone(raw: g2_font_t): g2_font_t {
return g2_font_create(raw.blob, raw.index);
function g2_font_clone(raw: draw_font_t): draw_font_t {
return g2_font_create(raw.buf, raw.index);
}
+26 -26
View File
@@ -460,6 +460,32 @@ declare type image_t = {
height?: i32;
};
declare type kinc_g5_pipeline_t = {
input_layout?: any;
vertex_shader?: any;
fragment_shader?: any;
cull_mode?: cull_mode_t;
depth_write?: bool;
depth_mode?: compare_mode_t;
blend_source?: blend_factor_t;
blend_destination?: blend_factor_t;
alpha_blend_source?: blend_factor_t;
alpha_blend_destination?: blend_factor_t;
color_write_mask_red?: any;
color_write_mask_green?: any;
color_write_mask_blue?: any;
color_write_mask_alpha?: any;
color_attachment?: any;
color_attachment_count?: i32;
depth_attachment_bits?: i32;
impl?: any;
};
type pipeline_t = {
pipeline_?: kinc_g5_pipeline_t;
input_layout?: vertex_struct_t;
@@ -506,32 +532,6 @@ declare type kinc_vertex_elem_t = {
type kinc_const_loc_t = any;
type kinc_tex_unit_t = any;
declare type kinc_g5_pipeline_t = {
input_layout?: any;
vertex_shader?: any;
fragment_shader?: any;
cull_mode?: cull_mode_t;
depth_write?: bool;
depth_mode?: compare_mode_t;
blend_source?: blend_factor_t;
blend_destination?: blend_factor_t;
alpha_blend_source?: blend_factor_t;
alpha_blend_destination?: blend_factor_t;
color_write_mask_red?: any;
color_write_mask_green?: any;
color_write_mask_blue?: any;
color_write_mask_alpha?: any;
color_attachment?: any;
color_attachment_count?: i32;
depth_attachment_bits?: i32;
impl?: any;
};
type iron_texture_t = {
width?: i32;
height?: i32;
+2 -2
View File
@@ -94,7 +94,7 @@ function mouse_released(button: string = "left"): bool {
}
function mouse_lock() {
if (sys_can_lock_mouse()) {
if (kinc_mouse_can_lock()) {
sys_lock_mouse();
mouse_locked = true;
mouse_hidden = true;
@@ -102,7 +102,7 @@ function mouse_lock() {
}
function mouse_unlock() {
if (sys_can_lock_mouse()) {
if (kinc_mouse_can_lock()) {
sys_unlock_mouse();
mouse_locked = false;
mouse_hidden = false;
+3 -3
View File
@@ -180,7 +180,7 @@ declare function color_set_gb(c: i32, i: u8): i32;
declare function color_set_bb(c: i32, i: u8): i32;
declare function color_set_ab(c: i32, i: u8): i32;
declare function iron_init(title: string, width: i32, height: i32, vsync: bool, window_mode: i32, window_features: i32, x: i32, y: i32, frequency: i32, use_depth: bool): void;
declare function iron_init(ops: kinc_window_options_t): void;
declare function kinc_set_app_name(name: string): void;
declare function kinc_log(v: any): void;
declare function kinc_g5_clear(flags: i32, color: i32, depth: f32): void;
@@ -316,8 +316,8 @@ declare function draw_line(x0: f32, y0: f32, x1: f32, y1: f32, strength: f32 = 1
declare function draw_line_aa(x0: f32, y0: f32, x1: f32, y1: f32, strength: f32 = 1.0): void;
declare function draw_string(text: string, x: f32, y: f32): void;
declare function draw_set_font(font: any, size: i32): bool;
declare function draw_font_init(blob: buffer_t, font_index: i32): any;
declare function draw_font_13(blob: buffer_t): any;
declare function draw_font_init(font: any, buf: any, font_index: i32): void;
declare function draw_font_13(font: any, buf: any): any;
declare function draw_font_set_glyphs(glyphs: i32[]): void;
declare function draw_font_count(font: any): i32;
declare function draw_font_height(font: any, size: i32): i32;
+1 -1
View File
@@ -290,7 +290,7 @@ function _render_path_resize_on_init(_image: image_t) {
}
function render_path_resize() {
if (sys_width() == 0 || sys_height() == 0) {
if (kinc_window_width() == 0 || kinc_window_height() == 0) {
return;
}
+23 -73
View File
@@ -22,8 +22,27 @@ let _sys_start_time: f32;
let _sys_window_title: string;
let _sys_shaders: map_t<string, shader_t> = map_create();
function sys_start(ops: kinc_sys_ops_t) {
iron_init(ops.title, ops.width, ops.height, ops.vsync, ops.mode, ops.features, ops.x, ops.y, ops.frequency, ops.use_depth);
declare type kinc_window_options_t = {
title?: string;
x?: i32;
y?: i32;
width?: i32;
height?: i32;
features?: window_features_t;
mode?: window_mode_t;
frequency?: i32;
vsync?: bool;
use_depth?: bool;
display_index?: i32;
visible?: bool;
color_bits?: i32;
depth_bits?: i32;
};
function sys_start(ops: kinc_window_options_t) {
iron_init(ops);
_sys_start_time = kinc_time();
g2_init();
@@ -129,22 +148,6 @@ function sys_time(): f32 {
return kinc_time() - _sys_start_time;
}
function sys_system_id(): string {
return kinc_system_id();
}
function sys_language(): string {
return kinc_language();
}
function sys_stop() {
kinc_stop();
}
function sys_load_url(url: string) {
kinc_load_url(url);
}
function sys_render_callback() {
for (let i: i32 = 0; i < _sys_render_listeners.length; ++i) {
_sys_render_listeners[i].f();
@@ -262,25 +265,17 @@ function sys_gamepad_button_callback(gamepad: i32, button: i32, value: f32) {
}
function sys_lock_mouse() {
if (!sys_is_mouse_locked()) {
if (!kinc_mouse_is_locked()) {
kinc_mouse_lock();
}
}
function sys_unlock_mouse() {
if (sys_is_mouse_locked()) {
if (kinc_mouse_is_locked()) {
kinc_mouse_unlock();
}
}
function sys_can_lock_mouse(): bool {
return kinc_mouse_can_lock();
}
function sys_is_mouse_locked(): bool {
return kinc_mouse_is_locked();
}
function sys_hide_system_cursor() {
iron_show_mouse(false);
}
@@ -289,38 +284,6 @@ function sys_show_system_cursor() {
iron_show_mouse(true);
}
function sys_resize(width: i32, height: i32) {
kinc_window_resize(width, height);
}
function sys_move(x: i32, y: i32) {
kinc_window_move(x, y);
}
function sys_x(): i32 {
return kinc_window_x();
}
function sys_y(): i32 {
return kinc_window_y();
}
function sys_width(): i32 {
return kinc_window_width();
}
function sys_height(): i32 {
return kinc_window_height();
}
function sys_mode(): window_mode_t {
return kinc_window_get_mode();
}
function sys_mode_set(mode: window_mode_t) {
iron_set_window_mode(mode);
}
function sys_title(): string {
return _sys_window_title;
}
@@ -409,19 +372,6 @@ type sound_t = {
sound_?: any;
};
type kinc_sys_ops_t = {
title?: string;
x?: i32;
y?: i32;
width?: i32;
height?: i32;
features?: window_features_t;
mode?: window_mode_t;
frequency?: i32;
vsync?: bool;
use_depth?: bool;
};
enum window_features_t {
NONE = 0,
RESIZABLE = 1,
+2 -2
View File
@@ -237,7 +237,7 @@ function ui_get_socket(nodes: ui_node_t[], id: i32): ui_node_socket_t {
return null;
}
function ui_set_font(raw: ui_t, font: g2_font_t) {
function ui_set_font(raw: ui_t, font: draw_font_t) {
g2_font_init(font); // Make sure font_ is ready
raw.ops.font = font;
}
@@ -397,7 +397,7 @@ declare type ui_handle_t = {
};
declare type ui_options_t = {
font?: g2_font_t;
font?: draw_font_t;
theme?: ui_theme_t;
scale_factor?: f32;
color_wheel?: kinc_g5_texture_t;