diff --git a/prosperon/clay.cm b/prosperon/clay.cm index efee9c03..c0224d49 100644 --- a/prosperon/clay.cm +++ b/prosperon/clay.cm @@ -214,7 +214,7 @@ clay.text = function text(str, ...configs) var config = rectify_configs(configs); config.size ??= {width:0, height:0}; // config.font = graphics.get_font(config.font) - var tsize = {width: 12, height: 12}; //config.font.text_size(str, 0, 0, config.size.width); + var tsize = {width: 12*str.length, height: 8}; //config.font.text_size(str, 0, 0, config.size.width); config.size = {width: Math.max(config.size.width, tsize.width), height: Math.max(config.size.height, tsize.height)}; config.text = str; add_item(config); diff --git a/prosperon/draw2d.cm b/prosperon/draw2d.cm index 9bf18e94..625149ae 100644 --- a/prosperon/draw2d.cm +++ b/prosperon/draw2d.cm @@ -11,7 +11,7 @@ var current_list = [] // Clear current list draw.clear = function() { - current_list.length = 0 + current_list = [] } // Get commands from current list diff --git a/prosperon/prosperon.ce b/prosperon/prosperon.ce index 7f2d7de2..edce3bf1 100644 --- a/prosperon/prosperon.ce +++ b/prosperon/prosperon.ce @@ -10,6 +10,8 @@ var framerate = 60 var game = args[0] +io.writepath(game) + var video //var cnf = use('accio/config') @@ -249,6 +251,28 @@ function translate_draw_commands(commands) { }) break + case "draw_slice9": + var img = graphics.texture(cmd.image) + var gpu = img.gpu + if (!gpu) break + + cmd.rect = worldToScreenRect(cmd.rect, camera) + + renderer_commands.push({ + op: "texture9Grid", + data: { + texture_id: gpu.id, + src: img.rect, + leftWidth: cmd.slice, + rightWidth: cmd.slice, + topHeight: cmd.slice, + bottomHeight: cmd.slice, + scale: 1.0, + dst: cmd.rect + } + }) + break + case "tilemap": // Group tiles by texture to batch draw calls var textureGroups = {} @@ -282,14 +306,15 @@ function translate_draw_commands(commands) { var tiles = group.tiles // Create a temporary tilemap with only tiles from this texture + // Apply tilemap position to the offset to shift the world coordinates var tempMap = { tiles: [], - offset_x: cmd.tilemap.offset_x, - offset_y: cmd.tilemap.offset_y, + offset_x: cmd.tilemap.offset_x + (cmd.tilemap.pos.x / cmd.tilemap.size_x), + offset_y: cmd.tilemap.offset_y + (cmd.tilemap.pos.y / cmd.tilemap.size_y), size_x: cmd.tilemap.size_x, size_y: cmd.tilemap.size_y } - + // Build sparse array for this texture's tiles tiles.forEach(({x, y, img}) => { var arrayX = x - cmd.tilemap.offset_x @@ -298,6 +323,8 @@ function translate_draw_commands(commands) { tempMap.tiles[arrayX][arrayY] = img }) + + // Generate geometry for this texture group var geom = geometry.tilemap_to_data(tempMap) geom.texture_id = parseInt(texId) @@ -358,7 +385,7 @@ function poll_input() { } if (ev.type.startsWith('mouse_')) - ev.pos.y = -ev.pos.y + win_size.height + ev.pos.y = -ev.pos.y + logical.height } send(gameactor, evs) diff --git a/prosperon/tilemap.cm b/prosperon/tilemap.cm index d5d80323..e3efc7f5 100644 --- a/prosperon/tilemap.cm +++ b/prosperon/tilemap.cm @@ -67,10 +67,10 @@ tilemap.prototype = this.tiles[x][y] = image; }, - draw() { + draw(pos = {x: 0, y: 0}) { return { cmd:'tilemap', - tilemap:this + tilemap:this, } }, } diff --git a/source/qjs_geometry.c b/source/qjs_geometry.c index feef2529..cab4ae80 100644 --- a/source/qjs_geometry.c +++ b/source/qjs_geometry.c @@ -867,8 +867,11 @@ JSC_CCALL(geometry_tilemap_to_data, JSValue tile = JS_GetPropertyUint32(js, col, y); if (!JS_IsNull(tile) && !JS_IsNull(tile)) { // Calculate world position - float world_x = (x + offset_x) * size_x; - float world_y = (y + offset_y) * size_y; + // x and y are array indices, need to convert to logical coordinates + float logical_x = x + offset_x; + float logical_y = y + offset_y; + float world_x = logical_x * size_x; + float world_y = logical_y * size_y; // Set vertex positions (4 corners of the tile) int base = vertex_idx * 2; diff --git a/source/qjs_imgui.cpp b/source/qjs_imgui.cpp index 61cbfbfb..31c21b08 100644 --- a/source/qjs_imgui.cpp +++ b/source/qjs_imgui.cpp @@ -544,8 +544,6 @@ JSC_CCALL(imgui_init, SDL_Window *window = js2SDL_Window(js,argv[0]); SDL_Renderer *renderer = js2SDL_Renderer(js,argv[1]); - printf("starting imgui on %p and %p\n", window, renderer); - ImGui_ImplSDL3_InitForSDLRenderer(window, renderer); ImGui_ImplSDLRenderer3_Init(renderer);