fix web focus issue
This commit is contained in:
parent
201bd26b80
commit
44968f35f2
15
build.zig
15
build.zig
@ -61,7 +61,6 @@ pub fn build(b: *std.Build) void {
|
|||||||
options.addOption(bool, "has_tracy", has_tracy);
|
options.addOption(bool, "has_tracy", has_tracy);
|
||||||
mod_main.addOptions("build_options", options);
|
mod_main.addOptions("build_options", options);
|
||||||
|
|
||||||
|
|
||||||
// from here on different handling for native vs wasm builds
|
// from here on different handling for native vs wasm builds
|
||||||
if (target.result.cpu.arch.isWasm()) {
|
if (target.result.cpu.arch.isWasm()) {
|
||||||
try buildWasm(b, .{
|
try buildWasm(b, .{
|
||||||
@ -73,8 +72,8 @@ pub fn build(b: *std.Build) void {
|
|||||||
} else {
|
} else {
|
||||||
try buildNative(b, "sokol_template", mod_main, has_console);
|
try buildNative(b, "sokol_template", mod_main, has_console);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn buildNative(b: *std.Build, name: []const u8, mod: *std.Build.Module, has_console: bool) !void {
|
fn buildNative(b: *std.Build, name: []const u8, mod: *std.Build.Module, has_console: bool) !void {
|
||||||
const exe = b.addExecutable(.{
|
const exe = b.addExecutable(.{
|
||||||
.name = name,
|
.name = name,
|
||||||
@ -170,18 +169,18 @@ fn patchWasmIncludeDirs(
|
|||||||
// C compilation is attempted (since the sokol C library depends on the
|
// C compilation is attempted (since the sokol C library depends on the
|
||||||
// Emscripten SDK setup step)
|
// Emscripten SDK setup step)
|
||||||
lib.step.dependOn(depend_step);
|
lib.step.dependOn(depend_step);
|
||||||
|
|
||||||
std.debug.print("{s}\n", .{lib.name});
|
|
||||||
}
|
}
|
||||||
patchWasmIncludeDirs(lib.root_module, path, depend_step);
|
patchWasmIncludeDirs(lib.root_module, path, depend_step);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn buildWasm(b: *std.Build, opts: BuildWasmOptions) !void {
|
fn buildWasm(b: *std.Build, opts: BuildWasmOptions) !void {
|
||||||
|
opts.mod_main.sanitize_c = .off;
|
||||||
|
|
||||||
// build the main file into a library, this is because the WASM 'exe'
|
// build the main file into a library, this is because the WASM 'exe'
|
||||||
// needs to be linked in a separate build step with the Emscripten linker
|
// needs to be linked in a separate build step with the Emscripten linker
|
||||||
const main_lib = b.addLibrary(.{
|
const main_lib = b.addLibrary(.{
|
||||||
.name = opts.name,
|
.name = "index",
|
||||||
.root_module = opts.mod_main,
|
.root_module = opts.mod_main,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -202,14 +201,16 @@ fn buildWasm(b: *std.Build, opts: BuildWasmOptions) !void {
|
|||||||
.use_webgl2 = true,
|
.use_webgl2 = true,
|
||||||
.use_emmalloc = true,
|
.use_emmalloc = true,
|
||||||
.use_filesystem = false,
|
.use_filesystem = false,
|
||||||
.shell_file_path = opts.dep_sokol.path("src/sokol/web/shell.html"),
|
.shell_file_path = b.path("src/engine/shell.html"),
|
||||||
});
|
});
|
||||||
// attach to default target
|
// attach to default target
|
||||||
b.getInstallStep().dependOn(&link_step.step);
|
b.getInstallStep().dependOn(&link_step.step);
|
||||||
// ...and a special run step to start the web build output via 'emrun'
|
// ...and a special run step to start the web build output via 'emrun'
|
||||||
const run = sokol.emRunStep(b, .{ .name = opts.name, .emsdk = dep_emsdk });
|
const run = sokol.emRunStep(b, .{ .name = "index", .emsdk = dep_emsdk });
|
||||||
run.step.dependOn(&link_step.step);
|
run.step.dependOn(&link_step.step);
|
||||||
b.step("run", "Run game").dependOn(&run.step);
|
b.step("run", "Run game").dependOn(&run.step);
|
||||||
|
|
||||||
|
// TODO: Create a zip archive of all of the files. Would be useful for easier itch.io upload
|
||||||
}
|
}
|
||||||
|
|
||||||
const AddExecutableIcon = struct {
|
const AddExecutableIcon = struct {
|
||||||
|
|||||||
@ -9,8 +9,8 @@
|
|||||||
.hash = "sokol-0.1.0-pb1HK4iDNgCom5dkY66eUBm_bYBHEl8KWFDAiqwWgpEy",
|
.hash = "sokol-0.1.0-pb1HK4iDNgCom5dkY66eUBm_bYBHEl8KWFDAiqwWgpEy",
|
||||||
},
|
},
|
||||||
.cimgui = .{
|
.cimgui = .{
|
||||||
.url = "git+https://github.com/floooh/dcimgui.git#6c2c7f0452d9f44c95094c3f7dc2969c2c6a5e1a",
|
.url = "git+https://github.com/floooh/dcimgui.git#33c99ef426b68030412b5a4b11487a23da9d4f13",
|
||||||
.hash = "cimgui-0.1.0-44ClkQYjlQCl0iQX5wlquJ-mFZMqSxXA3hE2MG_3i1BT",
|
.hash = "cimgui-0.1.0-44ClkQRJlABdFMKRqIG8KDD6jy1eQbgPO335NziPYjmL",
|
||||||
.lazy = true
|
.lazy = true
|
||||||
},
|
},
|
||||||
.tracy = .{
|
.tracy = .{
|
||||||
|
|||||||
@ -8,7 +8,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
.root_source_file = b.path("src/root.zig"),
|
.root_source_file = b.path("src/root.zig"),
|
||||||
.link_libc = true
|
.link_libc = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const stb_dependency = b.dependency("stb", .{});
|
const stb_dependency = b.dependency("stb", .{});
|
||||||
@ -18,7 +18,6 @@ pub fn build(b: *std.Build) void {
|
|||||||
.flags = &.{}
|
.flags = &.{}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const tests = b.addTest(.{
|
const tests = b.addTest(.{
|
||||||
.root_module = mod
|
.root_module = mod
|
||||||
|
|||||||
@ -520,7 +520,6 @@ pub const Lexer = struct {
|
|||||||
|
|
||||||
try self.skipWhiteSpace();
|
try self.skipWhiteSpace();
|
||||||
if (try self.takeByte() != '=') {
|
if (try self.takeByte() != '=') {
|
||||||
std.debug.print("{s}\n", .{self.buffers.text.items[self.cursor..]});
|
|
||||||
return error.MissingAttributeEquals;
|
return error.MissingAttributeEquals;
|
||||||
}
|
}
|
||||||
try self.skipWhiteSpace();
|
try self.skipWhiteSpace();
|
||||||
|
|||||||
@ -27,8 +27,14 @@ const tracy = @import("tracy");
|
|||||||
// * https://github.com/nimgl/nimgl/issues/59
|
// * https://github.com/nimgl/nimgl/issues/59
|
||||||
|
|
||||||
const Options = struct {
|
const Options = struct {
|
||||||
|
const ImguiFont = struct {
|
||||||
|
ttf_data: []const u8,
|
||||||
|
size: f32 = 16
|
||||||
|
};
|
||||||
|
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
logger: sg.Logger = .{},
|
logger: sg.Logger = .{},
|
||||||
|
imgui_font: ?ImguiFont = null
|
||||||
};
|
};
|
||||||
|
|
||||||
const DrawFrame = struct {
|
const DrawFrame = struct {
|
||||||
@ -88,6 +94,7 @@ pub fn init(options: Options) !void {
|
|||||||
.func = options.logger.func,
|
.func = options.logger.func,
|
||||||
.user_data = options.logger.user_data
|
.user_data = options.logger.user_data
|
||||||
},
|
},
|
||||||
|
.no_default_font = options.imgui_font != null,
|
||||||
|
|
||||||
// TODO: Figure out a way to make imgui play nicely with UI
|
// TODO: Figure out a way to make imgui play nicely with UI
|
||||||
// Ideally when mouse is inside a Imgui window, then the imgui cursor should be used.
|
// Ideally when mouse is inside a Imgui window, then the imgui cursor should be used.
|
||||||
@ -95,6 +102,10 @@ pub fn init(options: Options) !void {
|
|||||||
.disable_set_mouse_cursor = true
|
.disable_set_mouse_cursor = true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (options.imgui_font) |imgui_font| {
|
||||||
|
imgui.addFont(imgui_font.ttf_data, imgui_font.size);
|
||||||
|
}
|
||||||
|
|
||||||
linear_sampler = sg.makeSampler(.{
|
linear_sampler = sg.makeSampler(.{
|
||||||
.min_filter = .LINEAR,
|
.min_filter = .LINEAR,
|
||||||
.mag_filter = .LINEAR,
|
.mag_filter = .LINEAR,
|
||||||
|
|||||||
@ -142,7 +142,10 @@ fn sokolInit(self: *Engine) !void {
|
|||||||
|
|
||||||
try Gfx.init(.{
|
try Gfx.init(.{
|
||||||
.allocator = self.allocator,
|
.allocator = self.allocator,
|
||||||
.logger = .{ .func = sokolLogCallback }
|
.logger = .{ .func = sokolLogCallback },
|
||||||
|
.imgui_font = .{
|
||||||
|
.ttf_data = @embedFile("../assets/roboto-font/Roboto-Regular.ttf"),
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.assets = try Assets.init();
|
self.assets = try Assets.init();
|
||||||
|
|||||||
53
src/engine/shell.html
Normal file
53
src/engine/shell.html
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en-us">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"/>
|
||||||
|
<title>Sokol</title>
|
||||||
|
<style>
|
||||||
|
body { margin: 0; background-color: black }
|
||||||
|
.game {
|
||||||
|
position: absolute;
|
||||||
|
top: 0px;
|
||||||
|
left: 0px;
|
||||||
|
margin: 0px;
|
||||||
|
border: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
display: block;
|
||||||
|
image-rendering: optimizeSpeed;
|
||||||
|
image-rendering: -moz-crisp-edges;
|
||||||
|
image-rendering: -o-crisp-edges;
|
||||||
|
image-rendering: -webkit-optimize-contrast;
|
||||||
|
image-rendering: optimize-contrast;
|
||||||
|
image-rendering: crisp-edges;
|
||||||
|
image-rendering: pixelated;
|
||||||
|
-ms-interpolation-mode: nearest-neighbor;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas class="game" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
|
||||||
|
<script type='text/javascript'>
|
||||||
|
var Module = {
|
||||||
|
preRun: [],
|
||||||
|
print: (function() {
|
||||||
|
return function(text) {
|
||||||
|
text = Array.prototype.slice.call(arguments).join(' ');
|
||||||
|
console.log(text);
|
||||||
|
};
|
||||||
|
})(),
|
||||||
|
printErr: function(text) {
|
||||||
|
text = Array.prototype.slice.call(arguments).join(' ');
|
||||||
|
console.error(text);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
window.onerror = function() {
|
||||||
|
console.log("onerror: " + event.message);
|
||||||
|
};
|
||||||
|
window.addEventListener("click", () => window.focus())
|
||||||
|
</script>
|
||||||
|
{{{ SCRIPT }}}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Reference in New Issue
Block a user