tilemap render
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -11,7 +11,7 @@ var current_list = []
|
||||
|
||||
// Clear current list
|
||||
draw.clear = function() {
|
||||
current_list.length = 0
|
||||
current_list = []
|
||||
}
|
||||
|
||||
// Get commands from current list
|
||||
|
||||
@@ -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,10 +306,11 @@ 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
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user