file_path
stringlengths
3
280
file_language
stringclasses
66 values
content
stringlengths
1
1.04M
repo_name
stringlengths
5
92
repo_stars
int64
0
154k
repo_description
stringlengths
0
402
repo_primary_language
stringclasses
108 values
developer_username
stringlengths
1
25
developer_name
stringlengths
0
30
developer_company
stringlengths
0
82
examples/graphics/shader/debug.js
JavaScript
// Debug shader test - use shaders that visibly alter output // This helps verify the shader is actually being applied joy.window.setMode(800, 600); joy.window.setTitle("Debug Shader Test"); joy.graphics.setBackgroundColor(0.2, 0.2, 0.3); var passthruShader; var tintShader; var currentShader = 0; joy.load = function() { // Passthrough shader (should look identical to no-shader) passthruShader = joy.graphics.newShader(` vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { return Texel(tex, texcoord) * vcolor; } `); // Tint shader (adds visible blue tint to confirm shader is working) tintShader = joy.graphics.newShader(` vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord) * vcolor; color.b = min(1.0, color.b + 0.3); // Add blue tint return color; } `); if (!passthruShader) { console.log("Failed to create passthrough shader!"); } if (!tintShader) { console.log("Failed to create tint shader!"); } console.log("1 = No shader"); console.log("2 = Passthrough shader (should look same)"); console.log("3 = Blue tint shader (visible change)"); console.log("Escape to exit"); }; joy.keypressed = function(key) { if (key === "escape") { joy.window.close(); } else if (key === "1") { currentShader = 0; console.log("No shader"); } else if (key === "2") { currentShader = 1; console.log("Passthrough shader"); } else if (key === "3") { currentShader = 2; console.log("Blue tint shader"); } }; joy.draw = function() { // Apply current shader if (currentShader === 1) { joy.graphics.setShader(passthruShader); } else if (currentShader === 2) { joy.graphics.setShader(tintShader); } // Draw shapes joy.graphics.setColor(1, 0, 0); joy.graphics.rectangle("fill", 100, 100, 200, 100); joy.graphics.setColor(0, 1, 0); joy.graphics.rectangle("fill", 400, 100, 100, 200); joy.graphics.setColor(1, 1, 0); joy.graphics.circle("fill", 200, 400, 80); joy.graphics.setColor(1, 0, 1); joy.graphics.circle("fill", 500, 400, 80); // Reset shader for UI joy.graphics.setShader(); // Draw UI joy.graphics.setColor(1, 1, 1); var modeNames = ["No Shader", "Passthrough Shader", "Blue Tint Shader"]; joy.graphics.print("Current: " + modeNames[currentShader], 10, 10); joy.graphics.print("Press 1, 2, or 3 to switch modes", 10, 30); joy.graphics.print("Rectangle at (100,100) should be 200x100", 10, 550); joy.graphics.print("Rectangle at (400,100) should be 100x200", 10, 570); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/graphics/shader/gradient.js
JavaScript
// Gradient shader example // Demonstrates using screen coordinates and love_ScreenSize joy.window.setMode(800, 600); joy.window.setTitle("Shader - Gradients"); joy.graphics.setBackgroundColor(0.1, 0.1, 0.1); // Horizontal gradient overlay var horizontalGradient = joy.graphics.newShader(` vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord) * vcolor; float t = pixcoord.x / love_ScreenSize.x; vec3 gradient = mix(vec3(1.0, 0.0, 0.0), vec3(0.0, 0.0, 1.0), t); return vec4(color.rgb * gradient, color.a); } `); // Vertical gradient overlay var verticalGradient = joy.graphics.newShader(` vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord) * vcolor; float t = pixcoord.y / love_ScreenSize.y; vec3 gradient = mix(vec3(0.0, 1.0, 0.0), vec3(1.0, 0.0, 1.0), t); return vec4(color.rgb * gradient, color.a); } `); // Radial gradient from center var radialGradient = joy.graphics.newShader(` vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord) * vcolor; vec2 center = love_ScreenSize.xy * 0.5; float dist = length(pixcoord - center); float maxDist = length(center); float t = clamp(dist / maxDist, 0.0, 1.0); vec3 gradient = mix(vec3(1.0, 1.0, 0.0), vec3(0.0, 0.5, 1.0), t); return vec4(color.rgb * gradient, color.a); } `); // Animated rainbow var rainbowShader = joy.graphics.newShader(` uniform float time; vec3 hsv2rgb(vec3 c) { vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0); vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); } vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord) * vcolor; float hue = (pixcoord.x + pixcoord.y) / (love_ScreenSize.x + love_ScreenSize.y); hue = fract(hue + time * 0.1); vec3 rainbow = hsv2rgb(vec3(hue, 0.8, 1.0)); return vec4(color.rgb * rainbow, color.a); } `); // Diamond pattern var diamondShader = joy.graphics.newShader(` uniform float time; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord) * vcolor; float scale = 50.0; float pattern = abs(mod(pixcoord.x, scale) - scale * 0.5) + abs(mod(pixcoord.y, scale) - scale * 0.5); pattern = pattern / scale; float brightness = 0.5 + pattern * 0.5; return vec4(color.rgb * brightness, color.a); } `); var time = 0; var currentShader = 0; var shaders = [horizontalGradient, verticalGradient, radialGradient, rainbowShader, diamondShader]; var shaderNames = ["Horizontal Gradient", "Vertical Gradient", "Radial Gradient", "Rainbow", "Diamond Pattern"]; joy.load = function() { console.log("Gradient shader demo"); console.log("Press SPACE to cycle through gradients"); console.log("Press Escape to exit"); }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } else if (key === "space") { currentShader = (currentShader + 1) % shaders.length; } }; joy.update = function(dt) { time += dt; }; joy.draw = function() { var shader = shaders[currentShader]; joy.graphics.setShader(shader); // Send time for animated shaders if (shader.hasUniform("time")) { shader.send("time", time); } // Fill screen with white to show the gradient joy.graphics.setColor(1, 1, 1); joy.graphics.rectangle("fill", 0, 0, 800, 600); // Draw some shapes on top joy.graphics.setColor(1, 1, 1); joy.graphics.circle("fill", 200, 200, 80); joy.graphics.circle("fill", 400, 300, 100); joy.graphics.circle("fill", 600, 200, 80); joy.graphics.rectangle("fill", 100, 380, 200, 120); joy.graphics.rectangle("fill", 500, 380, 200, 120); // Reset shader for UI joy.graphics.setShader(); // Draw UI with black background for readability joy.graphics.setColor(0, 0, 0, 0.7); joy.graphics.rectangle("fill", 40, 15, 350, 30); joy.graphics.rectangle("fill", 40, 545, 400, 30); joy.graphics.setColor(1, 1, 1); joy.graphics.print("Gradient: " + shaderNames[currentShader], 50, 20); joy.graphics.setColor(0.9, 0.9, 0.9); joy.graphics.print("Press SPACE to change gradient, ESC to exit", 50, 550); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/graphics/shader/image.js
JavaScript
// Image shader example // Demonstrates applying shaders to textured images joy.window.setMode(800, 600); joy.window.setTitle("Shader - Image Effects"); joy.graphics.setBackgroundColor(0.15, 0.15, 0.2); var image; // Pixelate shader var pixelateShader = joy.graphics.newShader(` uniform float pixelSize; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec2 size = vec2(pixelSize) / love_ScreenSize.xy; vec2 coord = floor(texcoord / size) * size + size * 0.5; return Texel(tex, coord) * vcolor; } `); // Blur shader (simple box blur) var blurShader = joy.graphics.newShader(` uniform float blurAmount; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec2 offset = vec2(blurAmount) / love_ScreenSize.xy; vec4 color = vec4(0.0); color += Texel(tex, texcoord + vec2(-offset.x, -offset.y)); color += Texel(tex, texcoord + vec2(0.0, -offset.y)); color += Texel(tex, texcoord + vec2(offset.x, -offset.y)); color += Texel(tex, texcoord + vec2(-offset.x, 0.0)); color += Texel(tex, texcoord); color += Texel(tex, texcoord + vec2(offset.x, 0.0)); color += Texel(tex, texcoord + vec2(-offset.x, offset.y)); color += Texel(tex, texcoord + vec2(0.0, offset.y)); color += Texel(tex, texcoord + vec2(offset.x, offset.y)); return (color / 9.0) * vcolor; } `); // Edge detection (Sobel-like) var edgeShader = joy.graphics.newShader(` vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec2 offset = vec2(1.0) / love_ScreenSize.xy; float tl = dot(Texel(tex, texcoord + vec2(-offset.x, -offset.y)).rgb, vec3(0.33)); float t = dot(Texel(tex, texcoord + vec2(0.0, -offset.y)).rgb, vec3(0.33)); float tr = dot(Texel(tex, texcoord + vec2(offset.x, -offset.y)).rgb, vec3(0.33)); float l = dot(Texel(tex, texcoord + vec2(-offset.x, 0.0)).rgb, vec3(0.33)); float r = dot(Texel(tex, texcoord + vec2(offset.x, 0.0)).rgb, vec3(0.33)); float bl = dot(Texel(tex, texcoord + vec2(-offset.x, offset.y)).rgb, vec3(0.33)); float b = dot(Texel(tex, texcoord + vec2(0.0, offset.y)).rgb, vec3(0.33)); float br = dot(Texel(tex, texcoord + vec2(offset.x, offset.y)).rgb, vec3(0.33)); float gx = -tl - 2.0*l - bl + tr + 2.0*r + br; float gy = -tl - 2.0*t - tr + bl + 2.0*b + br; float edge = sqrt(gx*gx + gy*gy); return vec4(vec3(edge), 1.0) * vcolor; } `); // Vignette effect var vignetteShader = joy.graphics.newShader(` uniform float strength; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord) * vcolor; vec2 center = vec2(0.5, 0.5); float dist = distance(texcoord, center); float vignette = 1.0 - dist * strength; vignette = clamp(vignette, 0.0, 1.0); return vec4(color.rgb * vignette, color.a); } `); // Chromatic aberration var chromaticShader = joy.graphics.newShader(` uniform float amount; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec2 offset = (texcoord - 0.5) * amount / love_ScreenSize.xy; float r = Texel(tex, texcoord + offset).r; float g = Texel(tex, texcoord).g; float b = Texel(tex, texcoord - offset).b; float a = Texel(tex, texcoord).a; return vec4(r, g, b, a) * vcolor; } `); var time = 0; var currentShader = 0; var shaders = [null, pixelateShader, blurShader, edgeShader, vignetteShader, chromaticShader]; var shaderNames = ["None", "Pixelate", "Blur", "Edge Detection", "Vignette", "Chromatic Aberration"]; joy.load = function() { console.log("Image shader effects demo"); console.log("Press SPACE to cycle through effects"); console.log("Press Escape to exit"); // Load the test image image = joy.graphics.newImage("smiley.png"); }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } else if (key === "space") { currentShader = (currentShader + 1) % shaders.length; } }; joy.update = function(dt) { time += dt; }; joy.draw = function() { var shader = shaders[currentShader]; if (shader) { joy.graphics.setShader(shader); // Set shader-specific uniforms if (currentShader === 1) { // Pixelate var pixelSize = 4 + Math.sin(time * 2) * 3; shader.send("pixelSize", pixelSize); } else if (currentShader === 2) { // Blur var blurAmount = 2 + Math.sin(time * 1.5) * 2; shader.send("blurAmount", blurAmount); } else if (currentShader === 4) { // Vignette shader.send("strength", 1.5); } else if (currentShader === 5) { // Chromatic var amount = 10 + Math.sin(time * 3) * 8; shader.send("amount", amount); } } else { joy.graphics.setShader(); } // Draw the image centered and scaled joy.graphics.setColor(1, 1, 1); if (image) { var imgW = image.getWidth(); var imgH = image.getHeight(); var scale = Math.min(600 / imgW, 450 / imgH); var x = (800 - imgW * scale) / 2; var y = (600 - imgH * scale) / 2; joy.graphics.draw(image, x, y, 0, scale, scale); } else { // Fallback: draw colored rectangles if no image joy.graphics.setColor(0.8, 0.3, 0.3); joy.graphics.rectangle("fill", 100, 100, 600, 400); joy.graphics.setColor(0.3, 0.8, 0.3); joy.graphics.circle("fill", 400, 300, 150); } // Reset shader for UI joy.graphics.setShader(); // Draw UI joy.graphics.setColor(0, 0, 0, 0.7); joy.graphics.rectangle("fill", 40, 15, 400, 30); joy.graphics.rectangle("fill", 40, 555, 400, 30); joy.graphics.setColor(1, 1, 1); joy.graphics.print("Effect: " + shaderNames[currentShader], 50, 20); joy.graphics.setColor(0.9, 0.9, 0.9); joy.graphics.print("Press SPACE to change effect, ESC to exit", 50, 560); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/graphics/shader/main.js
JavaScript
// Shader Effects Demo // Cycles through various shader effects // Press LEFT/RIGHT to change effects, UP/DOWN to adjust intensity joy.window.setMode(800, 600); joy.window.setTitle("Shader Effects Demo"); joy.graphics.setBackgroundColor(0.15, 0.15, 0.2); var image; var shaders = []; var shaderNames = []; var currentShader = 0; var time = 0; var intensity = 0.5; joy.load = function() { image = joy.graphics.newImage("smiley.png"); // 1. Grayscale shaders.push(joy.graphics.newShader(` extern float intensity; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord); float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114)); color.rgb = mix(color.rgb, vec3(gray), intensity); return color * vcolor; } `)); shaderNames.push("Grayscale"); // 2. Sepia shaders.push(joy.graphics.newShader(` extern float intensity; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord); vec3 sepia; sepia.r = dot(color.rgb, vec3(0.393, 0.769, 0.189)); sepia.g = dot(color.rgb, vec3(0.349, 0.686, 0.168)); sepia.b = dot(color.rgb, vec3(0.272, 0.534, 0.131)); color.rgb = mix(color.rgb, sepia, intensity); return color * vcolor; } `)); shaderNames.push("Sepia"); // 3. Invert shaders.push(joy.graphics.newShader(` extern float intensity; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord); color.rgb = mix(color.rgb, 1.0 - color.rgb, intensity); return color * vcolor; } `)); shaderNames.push("Invert"); // 4. Posterize shaders.push(joy.graphics.newShader(` extern float intensity; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord); float levels = mix(256.0, 2.0, intensity); color.rgb = floor(color.rgb * levels) / levels; return color * vcolor; } `)); shaderNames.push("Posterize"); // 5. Pixelate shaders.push(joy.graphics.newShader(` extern float intensity; extern vec2 texSize; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { float pixelSize = mix(1.0, 20.0, intensity); vec2 coord = floor(texcoord * texSize / pixelSize) * pixelSize / texSize; return Texel(tex, coord) * vcolor; } `)); shaderNames.push("Pixelate"); // 6. Wave Distortion shaders.push(joy.graphics.newShader(` extern float intensity; extern float time; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec2 tc = texcoord; float amp = intensity * 0.05; tc.x += sin(tc.y * 15.0 + time * 3.0) * amp; tc.y += cos(tc.x * 15.0 + time * 3.0) * amp; return Texel(tex, tc) * vcolor; } `)); shaderNames.push("Wave"); // 7. Chromatic Aberration shaders.push(joy.graphics.newShader(` extern float intensity; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec2 dir = texcoord - vec2(0.5); float offset = intensity * 0.02; float r = Texel(tex, texcoord + dir * offset).r; float g = Texel(tex, texcoord).g; float b = Texel(tex, texcoord - dir * offset).b; float a = Texel(tex, texcoord).a; return vec4(r, g, b, a) * vcolor; } `)); shaderNames.push("Chromatic Aberration"); // 8. Vignette shaders.push(joy.graphics.newShader(` extern float intensity; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord); float dist = distance(texcoord, vec2(0.5)); float vig = smoothstep(0.8, 0.2, dist * (0.5 + intensity)); color.rgb *= vig; return color * vcolor; } `)); shaderNames.push("Vignette"); // 9. Sharpen shaders.push(joy.graphics.newShader(` extern float intensity; extern vec2 texSize; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec2 step = 1.0 / texSize; vec4 color = Texel(tex, texcoord) * (1.0 + 4.0 * intensity); color -= Texel(tex, texcoord + vec2(step.x, 0)) * intensity; color -= Texel(tex, texcoord - vec2(step.x, 0)) * intensity; color -= Texel(tex, texcoord + vec2(0, step.y)) * intensity; color -= Texel(tex, texcoord - vec2(0, step.y)) * intensity; return color * vcolor; } `)); shaderNames.push("Sharpen"); // 10. Blur shaders.push(joy.graphics.newShader(` extern float intensity; extern vec2 texSize; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec2 step = intensity * 3.0 / texSize; vec4 color = vec4(0.0); color += Texel(tex, texcoord) * 0.2; color += Texel(tex, texcoord + vec2(step.x, 0)) * 0.15; color += Texel(tex, texcoord - vec2(step.x, 0)) * 0.15; color += Texel(tex, texcoord + vec2(0, step.y)) * 0.15; color += Texel(tex, texcoord - vec2(0, step.y)) * 0.15; color += Texel(tex, texcoord + step) * 0.05; color += Texel(tex, texcoord - step) * 0.05; color += Texel(tex, texcoord + vec2(step.x, -step.y)) * 0.05; color += Texel(tex, texcoord + vec2(-step.x, step.y)) * 0.05; return color * vcolor; } `)); shaderNames.push("Blur"); // 11. Edge Detection shaders.push(joy.graphics.newShader(` extern float intensity; extern vec2 texSize; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec2 step = 1.0 / texSize; vec4 n = Texel(tex, texcoord + vec2(0, -step.y)); vec4 s = Texel(tex, texcoord + vec2(0, step.y)); vec4 e = Texel(tex, texcoord + vec2(step.x, 0)); vec4 w = Texel(tex, texcoord + vec2(-step.x, 0)); vec4 edge = abs(n - s) + abs(e - w); vec4 orig = Texel(tex, texcoord); return mix(orig, edge, intensity) * vcolor; } `)); shaderNames.push("Edge Detection"); // 12. Emboss shaders.push(joy.graphics.newShader(` extern float intensity; extern vec2 texSize; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec2 step = 1.0 / texSize; vec4 tl = Texel(tex, texcoord + vec2(-step.x, -step.y)); vec4 br = Texel(tex, texcoord + vec2(step.x, step.y)); vec4 emboss = (br - tl) + 0.5; vec4 orig = Texel(tex, texcoord); return mix(orig, emboss, intensity) * vcolor; } `)); shaderNames.push("Emboss"); // 13. RGB Shift shaders.push(joy.graphics.newShader(` extern float intensity; extern float time; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { float shift = intensity * 0.01; float r = Texel(tex, texcoord + vec2(shift, 0)).r; float g = Texel(tex, texcoord).g; float b = Texel(tex, texcoord - vec2(shift, 0)).b; return vec4(r, g, b, Texel(tex, texcoord).a) * vcolor; } `)); shaderNames.push("RGB Shift"); // 14. Scanlines shaders.push(joy.graphics.newShader(` extern float intensity; extern vec2 screenSize; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord); float scanline = sin(pixcoord.y * 3.14159 * 2.0) * 0.5 + 0.5; color.rgb *= 1.0 - (intensity * 0.3 * scanline); return color * vcolor; } `)); shaderNames.push("Scanlines"); // 15. Hue Shift shaders.push(joy.graphics.newShader(` extern float intensity; extern float time; vec3 rgb2hsv(vec3 c) { vec4 K = vec4(0.0, -1.0/3.0, 2.0/3.0, -1.0); vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); float d = q.x - min(q.w, q.y); float e = 1.0e-10; return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); } vec3 hsv2rgb(vec3 c) { vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0); vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); } vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord); vec3 hsv = rgb2hsv(color.rgb); hsv.x = fract(hsv.x + intensity + time * 0.1); color.rgb = hsv2rgb(hsv); return color * vcolor; } `)); shaderNames.push("Hue Shift"); // 16. CRT Effect shaders.push(joy.graphics.newShader(` extern float intensity; extern float time; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec2 tc = texcoord; // Barrel distortion vec2 cc = tc - 0.5; float dist = dot(cc, cc) * intensity * 0.5; tc = tc + cc * dist; vec4 color = Texel(tex, tc); // Scanlines float scanline = sin(tc.y * 400.0) * 0.04 * intensity; color.rgb -= scanline; // Vignette float vig = 1.0 - dot(cc, cc) * intensity * 2.0; color.rgb *= vig; return color * vcolor; } `)); shaderNames.push("CRT"); // Initialize all shaders with uniforms for (var i = 0; i < shaders.length; i++) { if (shaders[i]) { shaders[i].send("intensity", intensity); if (shaders[i].hasUniform("texSize")) { shaders[i].send("texSize", [image.getWidth(), image.getHeight()]); } if (shaders[i].hasUniform("screenSize")) { shaders[i].send("screenSize", [joy.graphics.getWidth(), joy.graphics.getHeight()]); } if (shaders[i].hasUniform("time")) { shaders[i].send("time", 0.0); } } } console.log("Shader Effects Demo"); console.log("LEFT/RIGHT: Change effect"); console.log("UP/DOWN: Adjust intensity"); console.log("Escape: Exit"); }; joy.keypressed = function(key) { if (key === "escape") { joy.window.close(); } else if (key === "right") { currentShader = (currentShader + 1) % shaders.length; } else if (key === "left") { currentShader = (currentShader - 1 + shaders.length) % shaders.length; } else if (key === "up") { intensity = Math.min(intensity + 0.1, 1.0); updateIntensity(); } else if (key === "down") { intensity = Math.max(intensity - 0.1, 0.0); updateIntensity(); } }; function updateIntensity() { for (var i = 0; i < shaders.length; i++) { if (shaders[i]) { shaders[i].send("intensity", intensity); } } } joy.update = function(dt) { time += dt; var shader = shaders[currentShader]; if (shader && shader.hasUniform("time")) { shader.send("time", time); } }; joy.draw = function() { var shader = shaders[currentShader]; joy.graphics.setColor(1, 1, 1); if (shader) { joy.graphics.setShader(shader); } // Draw image centered var x = (joy.graphics.getWidth() - image.getWidth()) / 2; var y = (joy.graphics.getHeight() - image.getHeight()) / 2; joy.graphics.draw(image, x, y); joy.graphics.setShader(); // Draw UI joy.graphics.setColor(0, 0, 0, 0.7); joy.graphics.rectangle("fill", 0, 0, 300, 80); joy.graphics.setColor(1, 1, 1); joy.graphics.print("Effect: " + shaderNames[currentShader] + " (" + (currentShader + 1) + "/" + shaders.length + ")", 10, 10); joy.graphics.print("Intensity: " + (intensity * 100).toFixed(0) + "%", 10, 30); joy.graphics.print("LEFT/RIGHT: change, UP/DOWN: intensity", 10, 50); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/graphics/shader/minimal.js
JavaScript
// Minimal shader test - compare rendering with/without shader joy.window.setMode(800, 600); joy.window.setTitle("Minimal Shader Test"); joy.graphics.setBackgroundColor(0.2, 0.2, 0.3); var shader; joy.load = function() { shader = joy.graphics.newShader(` vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { return Texel(tex, texcoord) * vcolor; } `); if (!shader) { console.log("Failed to create shader!"); } else { console.log("Shader created successfully"); } console.log("Escape to exit"); }; joy.draw = function() { // LEFT SIDE: Without shader joy.graphics.setColor(1, 1, 1); joy.graphics.print("WITHOUT SHADER:", 50, 30); joy.graphics.setColor(1, 0, 0); joy.graphics.rectangle("fill", 50, 70, 150, 100); joy.graphics.setColor(0, 1, 0); joy.graphics.circle("fill", 125, 280, 70); // RIGHT SIDE: With shader joy.graphics.setColor(1, 1, 1); joy.graphics.print("WITH SHADER:", 450, 30); joy.graphics.setShader(shader); joy.graphics.setColor(1, 0, 0); joy.graphics.rectangle("fill", 450, 70, 150, 100); joy.graphics.setColor(0, 1, 0); joy.graphics.circle("fill", 525, 280, 70); joy.graphics.setShader(); // Center reference lines joy.graphics.setColor(0.5, 0.5, 0.5); joy.graphics.line(400, 0, 400, 600); // Info joy.graphics.setColor(1, 1, 1); joy.graphics.print("Compare shapes on both sides - they should look identical", 10, 560); }; joy.keypressed = function(key) { if (key === "escape") { joy.window.close(); } };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/graphics/shader/simple.js
JavaScript
// Simple shader example // Demonstrates basic custom fragment shaders joy.window.setMode(800, 600); joy.window.setTitle("Shader - Simple Effects"); joy.graphics.setBackgroundColor(0.1, 0.1, 0.2); // Grayscale shader - converts colors to grayscale var grayscaleShader = joy.graphics.newShader(` vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord) * vcolor; float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114)); return vec4(gray, gray, gray, color.a); } `); // Invert shader - inverts colors var invertShader = joy.graphics.newShader(` vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord) * vcolor; return vec4(1.0 - color.rgb, color.a); } `); // Sepia shader - applies sepia tone var sepiaShader = joy.graphics.newShader(` vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord) * vcolor; float r = dot(color.rgb, vec3(0.393, 0.769, 0.189)); float g = dot(color.rgb, vec3(0.349, 0.686, 0.168)); float b = dot(color.rgb, vec3(0.272, 0.534, 0.131)); return vec4(r, g, b, color.a); } `); var currentShader = 0; var shaders = [null, grayscaleShader, invertShader, sepiaShader]; var shaderNames = ["None (default)", "Grayscale", "Invert", "Sepia"]; joy.load = function() { console.log("Simple shader effects demo"); console.log("Press SPACE to cycle through shaders"); console.log("Press Escape to exit"); }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } else if (key === "space") { currentShader = (currentShader + 1) % shaders.length; } }; joy.update = function(dt) { }; joy.draw = function() { // Apply current shader if (shaders[currentShader]) { joy.graphics.setShader(shaders[currentShader]); } else { joy.graphics.setShader(); } // Draw colorful shapes joy.graphics.setColor(1, 0.3, 0.3); joy.graphics.rectangle("fill", 50, 100, 150, 150); joy.graphics.setColor(0.3, 1, 0.3); joy.graphics.rectangle("fill", 220, 100, 150, 150); joy.graphics.setColor(0.3, 0.3, 1); joy.graphics.rectangle("fill", 390, 100, 150, 150); joy.graphics.setColor(1, 1, 0); joy.graphics.circle("fill", 125, 350, 60); joy.graphics.setColor(1, 0, 1); joy.graphics.circle("fill", 295, 350, 60); joy.graphics.setColor(0, 1, 1); joy.graphics.circle("fill", 465, 350, 60); // Rainbow gradient bar for (var i = 0; i < 20; i++) { var hue = i / 20; joy.graphics.setColor( Math.sin(hue * Math.PI * 2) * 0.5 + 0.5, Math.sin((hue + 0.33) * Math.PI * 2) * 0.5 + 0.5, Math.sin((hue + 0.66) * Math.PI * 2) * 0.5 + 0.5 ); joy.graphics.rectangle("fill", 560 + i * 10, 100, 10, 300); } // Reset shader for UI joy.graphics.setShader(); // Draw UI joy.graphics.setColor(1, 1, 1); joy.graphics.print("Current shader: " + shaderNames[currentShader], 50, 30); joy.graphics.setColor(0.7, 0.7, 0.7); joy.graphics.print("Press SPACE to change shader, ESC to exit", 50, 550); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/graphics/shader/test.js
JavaScript
// Simple shader test - draws a rectangle with and without shader // to diagnose rendering issues joy.window.setMode(800, 600); joy.window.setTitle("Shader Test"); joy.graphics.setBackgroundColor(0.2, 0.2, 0.3); var shader; var useShader = false; joy.load = function() { // Create the simplest possible shader - just passes through colors shader = joy.graphics.newShader(` vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { return Texel(tex, texcoord) * vcolor; } `); if (!shader) { console.log("Failed to create shader!"); } else { console.log("Shader created successfully"); // Debug: print generated shader source console.log("=== VERTEX SHADER ==="); console.log(shader.getVertexSource()); console.log("=== PIXEL SHADER ==="); console.log(shader.getPixelSource()); } console.log("Press SPACE to toggle shader"); console.log("Press D to dump shader sources"); console.log("Press Escape to exit"); }; joy.keypressed = function(key) { if (key === "escape") { joy.window.close(); } else if (key === "space") { useShader = !useShader; console.log("Shader: " + (useShader ? "ON" : "OFF")); } else if (key === "d" && shader) { console.log("=== VERTEX SHADER ==="); console.log(shader.getVertexSource()); console.log("=== PIXEL SHADER ==="); console.log(shader.getPixelSource()); } }; joy.draw = function() { // Draw with or without shader if (useShader && shader) { joy.graphics.setShader(shader); } // Draw rectangles joy.graphics.setColor(1, 0, 0); joy.graphics.rectangle("fill", 50, 50, 200, 100); joy.graphics.setColor(0, 1, 0); joy.graphics.rectangle("fill", 300, 50, 100, 200); joy.graphics.setColor(0, 0, 1); joy.graphics.rectangle("fill", 450, 50, 150, 150); // Draw circles to compare joy.graphics.setColor(1, 1, 0); joy.graphics.circle("fill", 150, 350, 80); joy.graphics.setColor(1, 0, 1); joy.graphics.circle("fill", 400, 350, 80); // Reset shader joy.graphics.setShader(); // Draw UI (always without shader) joy.graphics.setColor(1, 1, 1); joy.graphics.print("Shader: " + (useShader ? "ON" : "OFF"), 10, 10); joy.graphics.print("Press SPACE to toggle", 10, 30); joy.graphics.print("Rectangles should be rectangular, circles should be circular", 10, 550); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/graphics/shader/wave.js
JavaScript
// Wave shader example // Demonstrates time-based animated shaders with uniforms joy.window.setMode(800, 600); joy.window.setTitle("Shader - Wave Effect"); joy.graphics.setBackgroundColor(0.05, 0.05, 0.15); // Wave distortion shader - modulates brightness based on wave pattern var waveShader = joy.graphics.newShader(` uniform float time; uniform float amplitude; uniform float frequency; uniform float dpiScale; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord) * vcolor; // Create wave pattern based on position and time // Normalize by DPI scale so waves look the same on all displays float wave = sin((pixcoord.y / dpiScale) * frequency + time * 3.0) * amplitude; float brightness = 0.7 + wave * 0.1; return vec4(color.rgb * brightness, color.a); } `); // Ripple shader (circular waves from center) - modulates brightness var rippleShader = joy.graphics.newShader(` uniform float time; uniform vec2 center; uniform float dpiScale; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord) * vcolor; vec2 toCenter = pixcoord - center; // Normalize distance by DPI scale so waves look the same on all displays float dist = length(toCenter) / dpiScale; float wave = sin(dist * 0.05 - time * 5.0); float brightness = 0.7 + wave * 0.3; return vec4(color.rgb * brightness, color.a); } `); // Pulse color shader var pulseShader = joy.graphics.newShader(` uniform float time; vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { vec4 color = Texel(tex, texcoord) * vcolor; float pulse = sin(time * 3.0) * 0.3 + 0.7; return vec4(color.rgb * pulse, color.a); } `); var time = 0; var currentShader = 0; var shaders = [waveShader, rippleShader, pulseShader]; var shaderNames = ["Wave Distortion", "Ripple", "Pulse"]; joy.load = function() { console.log("Wave shader effects demo"); console.log("Press SPACE to cycle through effects"); console.log("Press Escape to exit"); }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } else if (key === "space") { currentShader = (currentShader + 1) % shaders.length; } }; joy.update = function(dt) { time += dt; }; joy.draw = function() { var shader = shaders[currentShader]; joy.graphics.setShader(shader); // Send time uniform shader.send("time", time); // Shader-specific uniforms var dpiScale = joy.graphics.getDPIScale(); if (currentShader === 0) { // Wave shader shader.send("amplitude", Math.sin(time) * 2 + 3); shader.send("frequency", 0.05); shader.send("dpiScale", dpiScale); } else if (currentShader === 1) { // Ripple shader - center needs to be in pixel coordinates (matching love_PixelCoord) shader.send("center", [400 * dpiScale, 300 * dpiScale]); shader.send("dpiScale", dpiScale); } // Draw a grid of colored rectangles var cols = 8; var rows = 6; var rectW = 80; var rectH = 70; var startX = 60; var startY = 80; for (var row = 0; row < rows; row++) { for (var col = 0; col < cols; col++) { var hue = (col + row * cols) / (cols * rows); joy.graphics.setColor( Math.sin(hue * Math.PI * 2) * 0.5 + 0.5, Math.sin((hue + 0.33) * Math.PI * 2) * 0.5 + 0.5, Math.sin((hue + 0.66) * Math.PI * 2) * 0.5 + 0.5 ); joy.graphics.rectangle("fill", startX + col * (rectW + 10), startY + row * (rectH + 10), rectW, rectH ); } } // Reset shader for UI joy.graphics.setShader(); // Draw UI joy.graphics.setColor(1, 1, 1); joy.graphics.print("Effect: " + shaderNames[currentShader], 50, 30); joy.graphics.setColor(0.7, 0.7, 0.7); joy.graphics.print("Press SPACE to change effect, ESC to exit", 50, 560); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/graphics/shapes.js
JavaScript
// Basic shapes example // Demonstrates drawing shapes with different colors joy.window.setMode(800, 600); joy.window.setTitle("Graphics - Shapes"); joy.graphics.setBackgroundColor(0.1, 0.1, 0.2); joy.load = function() { console.log("Drawing shapes demo"); console.log("Press Escape to exit"); }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } }; joy.update = function(dt) { }; joy.draw = function() { // Red filled rectangle joy.graphics.setColor(1, 0, 0); joy.graphics.rectangle("fill", 50, 50, 200, 100); // Green outlined rectangle joy.graphics.setColor(0, 1, 0); joy.graphics.rectangle("line", 300, 50, 200, 100); // Blue filled circle joy.graphics.setColor(0, 0.5, 1); joy.graphics.circle("fill", 150, 300, 80); // Yellow outlined circle joy.graphics.setColor(1, 1, 0); joy.graphics.circle("line", 400, 300, 80); // White lines joy.graphics.setColor(1, 1, 1); joy.graphics.line(550, 50, 750, 150); joy.graphics.line(550, 150, 750, 50); // Cyan text joy.graphics.setColor(0, 1, 1); joy.graphics.print("Hello Joy2D!", 550, 250); // Show screen dimensions joy.graphics.setColor(0.7, 0.7, 0.7); var dims = joy.graphics.getDimensions(); joy.graphics.print("Screen: " + dims[0] + "x" + dims[1], 10, 550); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/gui/advanced/main.js
JavaScript
// GUI Menubar Example - demonstrates menubar, combo, color picker, trees, and more // State variables let showWindow = true; let selectedTheme = 0; let themes = ["Light", "Dark", "System"]; let selectedFont = 1; let fonts = ["Small", "Medium", "Large"]; let fontSize = 14; let opacity = 100; let enableNotifications = true; let enableAutoSave = false; let enableSpellCheck = true; let pickedColor = { r: 0.2, g: 0.6, b: 0.9, a: 1.0 }; let selectedFile = 0; let fileList = ["document.txt", "notes.md", "config.json", "script.js"]; joy.load = function() { joy.window.setTitle("Menubar Example"); }; joy.update = function(dt) { // No update logic needed }; joy.draw = function() { joy.graphics.setBackgroundColor(0.15, 0.15, 0.2, 1.0); joy.graphics.clear(); if (!showWindow) { if (joy.gui.begin("Closed", 300, 250, 200, 100, ["border", "movable", "title"])) { joy.gui.layoutRowDynamic(30, 1); joy.gui.label("Window was closed", "centered"); joy.gui.layoutRowDynamic(30, 1); if (joy.gui.button("Reopen Settings")) { showWindow = true; } } joy.gui.end(); return; } showWindow = joy.gui.begin("Settings", 50, 50, 450, 500, ["border", "movable", "scalable", "closable", "minimizable", "title"]); if (showWindow) { // Menubar joy.gui.menubarBegin(); joy.gui.layoutRowStatic(25, 45, 3); if (joy.gui.menuBegin("File", "left", 120, 120)) { joy.gui.layoutRowDynamic(25, 1); if (joy.gui.menuItem("New")) { console.log("File > New"); } if (joy.gui.menuItem("Open")) { console.log("File > Open"); } if (joy.gui.menuItem("Save")) { console.log("File > Save"); } if (joy.gui.menuItem("Exit")) { joy.window.close(); } joy.gui.menuEnd(); } if (joy.gui.menuBegin("Edit", "left", 120, 100)) { joy.gui.layoutRowDynamic(25, 1); if (joy.gui.menuItem("Undo")) { console.log("Edit > Undo"); } if (joy.gui.menuItem("Redo")) { console.log("Edit > Redo"); } if (joy.gui.menuItem("Preferences")) { console.log("Edit > Preferences"); } joy.gui.menuEnd(); } if (joy.gui.menuBegin("Help", "left", 120, 80)) { joy.gui.layoutRowDynamic(25, 1); if (joy.gui.menuItem("About")) { console.log("Help > About"); } if (joy.gui.menuItem("Documentation")) { console.log("Help > Documentation"); } joy.gui.menuEnd(); } joy.gui.menubarEnd(); // Appearance section using tree if (joy.gui.treePush("tab", "Appearance", "maximized", 1)) { joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Theme:", "left"); joy.gui.layoutRowDynamic(25, 1); selectedTheme = joy.gui.combo(themes, selectedTheme, 25, 200, 100); joy.gui.spacing(1); joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Font Size:", "left"); joy.gui.layoutRowDynamic(25, 1); fontSize = joy.gui.propertyInt("#Size:", 8, fontSize, 32, 1, 1); joy.gui.spacing(1); joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Window Opacity:", "left"); joy.gui.layoutRowDynamic(25, 1); opacity = joy.gui.propertyInt("#%:", 20, opacity, 100, 5, 1); joy.gui.treePop(); } // Color picker section if (joy.gui.treePush("tab", "Accent Color", "minimized", 2)) { joy.gui.layoutRowDynamic(150, 1); pickedColor = joy.gui.colorPicker(pickedColor.r, pickedColor.g, pickedColor.b, pickedColor.a, true); joy.gui.layoutRowDynamic(20, 1); let colorText = "RGB: " + Math.floor(pickedColor.r * 255) + ", " + Math.floor(pickedColor.g * 255) + ", " + Math.floor(pickedColor.b * 255); joy.gui.label(colorText, "centered"); joy.gui.treePop(); } // Options section with radio buttons if (joy.gui.treePush("tab", "Notifications", "minimized", 3)) { joy.gui.layoutRowDynamic(25, 1); enableNotifications = joy.gui.checkbox("Enable notifications", enableNotifications); enableAutoSave = joy.gui.checkbox("Auto-save documents", enableAutoSave); enableSpellCheck = joy.gui.checkbox("Spell check", enableSpellCheck); joy.gui.spacing(1); joy.gui.separator(); joy.gui.spacing(1); joy.gui.layoutRowDynamic(20, 1); joy.gui.label("Font preset:", "left"); joy.gui.layoutRowDynamic(25, 3); if (joy.gui.option("Small", selectedFont === 0)) selectedFont = 0; if (joy.gui.option("Medium", selectedFont === 1)) selectedFont = 1; if (joy.gui.option("Large", selectedFont === 2)) selectedFont = 2; joy.gui.treePop(); } // File browser section with selectable items and group if (joy.gui.treePush("tab", "Recent Files", "minimized", 4)) { joy.gui.layoutRowDynamic(120, 1); if (joy.gui.groupBegin("Files", ["border"])) { joy.gui.layoutRowDynamic(22, 1); for (let i = 0; i < fileList.length; i++) { if (joy.gui.selectable(fileList[i], selectedFile === i, "left")) { selectedFile = i; console.log("Selected: " + fileList[i]); } } joy.gui.groupEnd(); } joy.gui.layoutRowDynamic(25, 2); if (joy.gui.button("Open")) { console.log("Opening: " + fileList[selectedFile]); } if (joy.gui.button("Remove")) { console.log("Removing: " + fileList[selectedFile]); } joy.gui.treePop(); } // Tooltip demo joy.gui.spacing(1); joy.gui.layoutRowDynamic(30, 1); if (joy.gui.button("Apply Settings")) { console.log("Settings applied!"); console.log(" Theme: " + themes[selectedTheme]); console.log(" Font size: " + fontSize); console.log(" Opacity: " + opacity + "%"); console.log(" Notifications: " + enableNotifications); console.log(" Font preset: " + fonts[selectedFont]); } if (joy.gui.isWidgetHovered()) { joy.gui.tooltip("Click to save all settings"); } } joy.gui.end(); }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/gui/basic/main.js
JavaScript
// GUI Example - demonstrates Nuklear immediate-mode GUI // State variables let showDemoWindow = true; let showInfoPanel = true; let showCompact = true; let sliderValue = 0.5; let checkboxValue = false; let counter = 0; joy.load = function() { console.log("GUI Example loaded"); joy.window.setTitle("Nuklear GUI Example"); }; joy.update = function(dt) { // No update logic needed for this example }; joy.draw = function() { // Clear background joy.graphics.setBackgroundColor(0.1, 0.1, 0.15, 1.0); joy.graphics.clear(); // Example 1: Basic Window with widgets // Only call begin() if we want the window shown if (showDemoWindow) { showDemoWindow = joy.gui.begin("Demo Window", 50, 50, 400, 400, ["border", "movable", "scalable", "closable", "minimizable", "title"]); if (showDemoWindow) { // Static layout - fixed height, fixed width columns joy.gui.layoutRowStatic(30, 120, 2); joy.gui.label("Hello Nuklear!", "left"); joy.gui.label("Counter: " + counter, "right"); // Dynamic layout - percentage-based columns joy.gui.layoutRowDynamic(30, 1); if (joy.gui.button("Click me!")) { counter++; console.log("Button clicked! Count: " + counter); } // Slider joy.gui.layoutRowDynamic(30, 1); joy.gui.label("Slider value: " + sliderValue.toFixed(2), "left"); sliderValue = joy.gui.slider(0, sliderValue, 1, 0.01); // Checkbox joy.gui.layoutRowDynamic(30, 1); checkboxValue = joy.gui.checkbox("Enable feature", checkboxValue); // Show current state joy.gui.layoutRowDynamic(30, 1); joy.gui.label("Checkbox is: " + (checkboxValue ? "ON" : "OFF"), "centered"); // Reset button joy.gui.layoutRowDynamic(30, 1); if (joy.gui.button("Reset Counter")) { counter = 0; console.log("Counter reset"); } } joy.gui.end(); } // Example 2: Second window if (showInfoPanel) { showInfoPanel = joy.gui.begin("Info Panel", 500, 50, 300, 250, ["border", "movable", "closable", "title"]); if (showInfoPanel) { joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Joy2D GUI Module", "centered"); joy.gui.layoutRowDynamic(5, 1); // Spacer joy.gui.layoutRowDynamic(20, 1); joy.gui.label("Using Nuklear", "left"); joy.gui.label("Immediate-mode GUI", "left"); joy.gui.layoutRowDynamic(10, 1); // Spacer joy.gui.layoutRowStatic(25, 80, 2); if (joy.gui.button("Button 1")) { console.log("Button 1 clicked"); } if (joy.gui.button("Button 2")) { console.log("Button 2 clicked"); } joy.gui.layoutRowDynamic(30, 1); if (joy.gui.button("Button 3")) { console.log("Button 3 clicked"); } } joy.gui.end(); } // Example 3: Small compact window if (showCompact) { showCompact = joy.gui.begin("Compact", 500, 350, 200, 150, ["border", "movable", "closable"]); if (showCompact) { joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Compact UI", "centered"); joy.gui.layoutRowStatic(20, 80, 1); if (joy.gui.button("Action")) { console.log("Compact action"); } } joy.gui.end(); } }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/gui/progress/main.js
JavaScript
// GUI Progress Bar Example - demonstrates progress bars and related widgets // State variables let downloadProgress = 0; let isDownloading = false; let downloadSpeed = 30; // units per second let uploadProgress = 0; let isUploading = false; let taskProgress = [0, 0, 0, 0]; let taskNames = ["Compiling...", "Linking...", "Packaging...", "Deploying..."]; let currentTask = 0; let isBuilding = false; let manualProgress = 50; let healthBar = 75; let manaBar = 100; let staminaBar = 60; joy.load = function() { console.log("GUI Progress Bar Example loaded"); joy.window.setTitle("Progress Bar Example"); }; joy.update = function(dt) { // Simulate download progress if (isDownloading) { downloadProgress += downloadSpeed * dt; if (downloadProgress >= 100) { downloadProgress = 100; isDownloading = false; console.log("Download complete!"); } } // Simulate upload progress if (isUploading) { uploadProgress += 20 * dt; if (uploadProgress >= 100) { uploadProgress = 100; isUploading = false; console.log("Upload complete!"); } } // Simulate build tasks if (isBuilding && currentTask < 4) { taskProgress[currentTask] += 40 * dt; if (taskProgress[currentTask] >= 100) { taskProgress[currentTask] = 100; currentTask++; if (currentTask >= 4) { isBuilding = false; console.log("Build complete!"); } } } }; joy.draw = function() { joy.graphics.setBackgroundColor(0.1, 0.1, 0.15, 1.0); joy.graphics.clear(); // Download simulation window if (joy.gui.begin("Download Simulation", 50, 50, 350, 200, ["border", "movable", "title"])) { joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Download Progress:", "left"); joy.gui.layoutRowDynamic(25, 1); joy.gui.progress(Math.floor(downloadProgress), 100, false); joy.gui.layoutRowDynamic(20, 1); joy.gui.label(Math.floor(downloadProgress) + "% complete", "centered"); joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Speed control:", "left"); joy.gui.layoutRowDynamic(25, 1); downloadSpeed = joy.gui.slider(10, downloadSpeed, 100, 5); joy.gui.layoutRowDynamic(30, 2); if (joy.gui.button(isDownloading ? "Pause" : "Start")) { isDownloading = !isDownloading; } if (joy.gui.button("Reset")) { downloadProgress = 0; isDownloading = false; } } joy.gui.end(); // Interactive progress window if (joy.gui.begin("Interactive Progress", 50, 280, 350, 180, ["border", "movable", "title"])) { joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Modifiable progress bar (click to adjust):", "left"); joy.gui.layoutRowDynamic(25, 1); manualProgress = joy.gui.progress(manualProgress, 100, true); joy.gui.layoutRowDynamic(20, 1); joy.gui.label("Value: " + manualProgress, "centered"); joy.gui.layoutRowDynamic(30, 3); if (joy.gui.button("-10")) { manualProgress = Math.max(0, manualProgress - 10); } if (joy.gui.button("Reset")) { manualProgress = 50; } if (joy.gui.button("+10")) { manualProgress = Math.min(100, manualProgress + 10); } } joy.gui.end(); // Build progress window if (joy.gui.begin("Build Progress", 430, 50, 350, 250, ["border", "movable", "title"])) { joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Build Tasks:", "left"); for (let i = 0; i < 4; i++) { joy.gui.layoutRowDynamic(20, 1); let status = ""; if (taskProgress[i] >= 100) { status = " [Done]"; } else if (i === currentTask && isBuilding) { status = " [In Progress]"; } else if (taskProgress[i] === 0) { status = " [Pending]"; } joy.gui.label(taskNames[i] + status, "left"); joy.gui.layoutRowDynamic(20, 1); joy.gui.progress(Math.floor(taskProgress[i]), 100, false); } joy.gui.spacing(1); joy.gui.layoutRowDynamic(30, 2); if (joy.gui.button(isBuilding ? "Stop" : "Build")) { if (!isBuilding && currentTask < 4) { isBuilding = true; } else { isBuilding = false; } } if (joy.gui.button("Reset")) { isBuilding = false; currentTask = 0; for (let i = 0; i < 4; i++) { taskProgress[i] = 0; } } } joy.gui.end(); // Game-style bars window if (joy.gui.begin("Game Stats", 430, 330, 350, 200, ["border", "movable", "title"])) { // Health bar (red) joy.gui.layoutRowDynamic(20, 1); joy.gui.labelColored("Health", 255, 100, 100, 255, "left"); joy.gui.layoutRowDynamic(20, 1); healthBar = joy.gui.progress(healthBar, 100, true); // Mana bar (blue) joy.gui.layoutRowDynamic(20, 1); joy.gui.labelColored("Mana", 100, 150, 255, 255, "left"); joy.gui.layoutRowDynamic(20, 1); manaBar = joy.gui.progress(manaBar, 100, true); // Stamina bar (green) joy.gui.layoutRowDynamic(20, 1); joy.gui.labelColored("Stamina", 100, 255, 100, 255, "left"); joy.gui.layoutRowDynamic(20, 1); staminaBar = joy.gui.progress(staminaBar, 100, true); joy.gui.spacing(1); joy.gui.layoutRowDynamic(25, 1); if (joy.gui.button("Full Restore")) { healthBar = 100; manaBar = 100; staminaBar = 100; } } joy.gui.end(); }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/gui/skin/main.js
JavaScript
// GUI Example - demonstrates Nuklear immediate-mode GUI // State variables let showDemoWindow = true; let showInfoPanel = true; let showCompact = true; let sliderValue = 0.5; let checkboxValue = false; let counter = 0; joy.load = function() { console.log("GUI Example loaded"); joy.window.setTitle("Nuklear GUI Example"); let success = joy.gui.applySkin("gwen.png") if (!success) { console.log("Failed to apply gwen skin"); } joy.gui.setFont("kenvector_future.ttf", 16); }; joy.update = function(dt) { // No update logic needed for this example }; joy.draw = function() { // Clear background joy.graphics.setBackgroundColor(0.1, 0.1, 0.15, 1.0); joy.graphics.clear(); // Example 1: Basic Window with widgets // Only call begin() if we want the window shown if (showDemoWindow) { showDemoWindow = joy.gui.begin("Demo Window", 50, 50, 400, 400, ["border", "movable", "scalable", "closable", "minimizable", "title"]); if (showDemoWindow) { // Static layout - fixed height, fixed width columns joy.gui.layoutRowStatic(30, 120, 2); joy.gui.label("Hello Nuklear!", "left"); joy.gui.label("Counter: " + counter, "right"); // Dynamic layout - percentage-based columns joy.gui.layoutRowDynamic(30, 1); if (joy.gui.button("Click me!")) { counter++; console.log("Button clicked! Count: " + counter); } // Slider joy.gui.layoutRowDynamic(30, 1); joy.gui.label("Slider value: " + sliderValue.toFixed(2), "left"); sliderValue = joy.gui.slider(0, sliderValue, 1, 0.01); // Checkbox joy.gui.layoutRowDynamic(30, 1); checkboxValue = joy.gui.checkbox("Enable feature", checkboxValue); // Show current state joy.gui.layoutRowDynamic(30, 1); joy.gui.label("Checkbox is: " + (checkboxValue ? "ON" : "OFF"), "centered"); // Reset button joy.gui.layoutRowDynamic(30, 1); if (joy.gui.button("Reset Counter")) { counter = 0; console.log("Counter reset"); } } joy.gui.end(); } // Example 2: Second window if (showInfoPanel) { showInfoPanel = joy.gui.begin("Info Panel", 500, 50, 300, 250, ["border", "movable", "closable", "title"]); if (showInfoPanel) { joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Joy2D GUI Module", "centered"); joy.gui.layoutRowDynamic(5, 1); // Spacer joy.gui.layoutRowDynamic(20, 1); joy.gui.label("Using Nuklear", "left"); joy.gui.label("Immediate-mode GUI", "left"); joy.gui.layoutRowDynamic(10, 1); // Spacer joy.gui.layoutRowStatic(25, 80, 2); if (joy.gui.button("Button 1")) { console.log("Button 1 clicked"); } if (joy.gui.button("Button 2")) { console.log("Button 2 clicked"); } joy.gui.layoutRowDynamic(30, 1); if (joy.gui.button("Button 3")) { console.log("Button 3 clicked"); } } joy.gui.end(); } // Example 3: Small compact window if (showCompact) { showCompact = joy.gui.begin("Compact", 500, 350, 200, 150, ["border", "movable", "closable"]); if (showCompact) { joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Compact UI", "centered"); joy.gui.layoutRowStatic(20, 80, 1); if (joy.gui.button("Action")) { console.log("Compact action"); } } joy.gui.end(); } }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/gui/text/main.js
JavaScript
// GUI Text Input Example - demonstrates text editing widgets // State variables let simpleText = "Hello World"; let multilineText = "This is a multiline\ntext editor.\nTry editing me!"; let nameField = ""; let emailField = ""; let passwordField = ""; let searchQuery = ""; joy.load = function() { console.log("GUI Text Input Example loaded"); joy.window.setTitle("Text Input Example"); }; joy.update = function(dt) { // No update logic needed }; joy.draw = function() { joy.graphics.setBackgroundColor(0.12, 0.12, 0.18, 1.0); joy.graphics.clear(); // Simple text input window if (joy.gui.begin("Simple Text Input", 50, 50, 350, 200, ["border", "movable", "title"])) { joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Basic text field:", "left"); joy.gui.layoutRowDynamic(30, 1); simpleText = joy.gui.edit(simpleText, 128, ["field"]); joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Current text: " + simpleText, "left"); joy.gui.layoutRowDynamic(30, 1); if (joy.gui.button("Clear")) { simpleText = ""; } } joy.gui.end(); // Form example window if (joy.gui.begin("Form Example", 50, 280, 350, 280, ["border", "movable", "title"])) { joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Name:", "left"); joy.gui.layoutRowDynamic(30, 1); nameField = joy.gui.edit(nameField, 64, ["field"]); joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Email:", "left"); joy.gui.layoutRowDynamic(30, 1); emailField = joy.gui.edit(emailField, 128, ["field"]); joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Password:", "left"); joy.gui.layoutRowDynamic(30, 1); passwordField = joy.gui.edit(passwordField, 64, ["field"]); joy.gui.spacing(1); joy.gui.layoutRowDynamic(30, 2); if (joy.gui.button("Submit")) { console.log("Form submitted:"); console.log(" Name: " + nameField); console.log(" Email: " + emailField); console.log(" Password: " + "*".repeat(passwordField.length)); } if (joy.gui.button("Clear All")) { nameField = ""; emailField = ""; passwordField = ""; } } joy.gui.end(); // Multiline editor window if (joy.gui.begin("Multiline Editor", 430, 50, 350, 300, ["border", "movable", "scalable", "title"])) { joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Multiline text editor:", "left"); joy.gui.layoutRowDynamic(180, 1); multilineText = joy.gui.edit(multilineText, 1024, ["box", "multiline"]); joy.gui.layoutRowDynamic(25, 1); joy.gui.label("Characters: " + multilineText.length, "left"); joy.gui.layoutRowDynamic(30, 1); if (joy.gui.button("Clear Editor")) { multilineText = ""; } } joy.gui.end(); // Search box example if (joy.gui.begin("Search", 430, 380, 350, 120, ["border", "movable", "title"])) { joy.gui.layoutRowDynamic(30, 1); searchQuery = joy.gui.edit(searchQuery, 256, ["field", "sigEnter"]); joy.gui.layoutRowDynamic(30, 2); if (joy.gui.button("Search")) { console.log("Searching for: " + searchQuery); } if (joy.gui.button("Clear")) { searchQuery = ""; } } joy.gui.end(); }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/image/main.js
JavaScript
// ImageData example - demonstrating CPU-side image manipulation // Uses joy.image module to create and manipulate pixel data const WIDTH = 400; const HEIGHT = 300; let imageData = null; let displayPoints = null; let mode = 0; const MODES = ["Gradient", "Checkerboard", "Plasma", "Inverted"]; joy.window.setMode(WIDTH + 200, HEIGHT + 100); joy.window.setTitle("ImageData Example"); // Create initial gradient image function createGradient() { imageData = joy.image.newImageData(WIDTH, HEIGHT); for (let y = 0; y < HEIGHT; y++) { for (let x = 0; x < WIDTH; x++) { let r = x / WIDTH; let g = y / HEIGHT; let b = 0.5; imageData.setPixel(x, y, r, g, b, 1); } } } // Create checkerboard pattern function createCheckerboard() { imageData = joy.image.newImageData(WIDTH, HEIGHT); const size = 20; for (let y = 0; y < HEIGHT; y++) { for (let x = 0; x < WIDTH; x++) { let cx = Math.floor(x / size); let cy = Math.floor(y / size); let isWhite = (cx + cy) % 2 === 0; let c = isWhite ? 1 : 0.2; imageData.setPixel(x, y, c, c, c, 1); } } } // Create plasma effect function createPlasma() { imageData = joy.image.newImageData(WIDTH, HEIGHT); for (let y = 0; y < HEIGHT; y++) { for (let x = 0; x < WIDTH; x++) { let value = Math.sin(x / 16) + Math.sin(y / 8) + Math.sin((x + y) / 16) + Math.sin(Math.sqrt(x * x + y * y) / 8); value = (value + 4) / 8; // Normalize to 0-1 // HSV-like coloring let r = Math.sin(value * Math.PI * 2) * 0.5 + 0.5; let g = Math.sin(value * Math.PI * 2 + 2) * 0.5 + 0.5; let b = Math.sin(value * Math.PI * 2 + 4) * 0.5 + 0.5; imageData.setPixel(x, y, r, g, b, 1); } } } // Invert current image using mapPixel function invertImage() { if (!imageData) return; imageData.mapPixel((x, y, r, g, b, a) => { return [1 - r, 1 - g, 1 - b, a]; }); } // Convert ImageData to display points for rendering function updateDisplayPoints() { if (!imageData) return; displayPoints = []; for (let y = 0; y < HEIGHT; y++) { for (let x = 0; x < WIDTH; x++) { let [r, g, b, a] = imageData.getPixel(x, y); displayPoints.push([x + 50, y + 50, r, g, b, a]); } } } // Cycle through modes function nextMode() { mode = (mode + 1) % MODES.length; switch (mode) { case 0: createGradient(); break; case 1: createCheckerboard(); break; case 2: createPlasma(); break; case 3: invertImage(); break; } updateDisplayPoints(); } joy.load = function() { // Set identity to enable saving files joy.filesystem.setIdentity("image-example"); createGradient(); updateDisplayPoints(); console.log("ImageData Example"); console.log("Press SPACE to cycle through modes"); console.log("Press S to save current image as PNG"); console.log("Press ESC to exit"); console.log("Save directory: " + joy.filesystem.getSaveDirectory()); }; joy.keypressed = function(key) { if (key === "escape") { joy.window.close(); } else if (key === "space") { nextMode(); } else if (key === "s") { if (imageData) { let filename = "screenshot_" + MODES[mode].toLowerCase() + ".png"; let data = imageData.encode("png", filename); console.log("Saved " + filename + " (" + data.byteLength + " bytes)"); console.log("Location: " + joy.filesystem.getSaveDirectory() + filename); } } }; joy.update = function(dt) {}; joy.draw = function() { joy.graphics.clear(0.1, 0.1, 0.15); // Draw the image using points if (displayPoints) { joy.graphics.points(displayPoints); } // Draw border around image joy.graphics.setColor(0.5, 0.5, 0.5, 1); joy.graphics.rectangle("line", 49, 49, WIDTH + 2, HEIGHT + 2); // Draw UI joy.graphics.setColor(1, 1, 1, 1); joy.graphics.print("ImageData Example", 50, 10); joy.graphics.print("Mode: " + MODES[mode], 50, 30); // Draw info panel let infoX = WIDTH + 70; joy.graphics.print("Controls:", infoX, 50); joy.graphics.print("SPACE - Next mode", infoX, 80); joy.graphics.print("S - Save PNG", infoX, 100); joy.graphics.print("ESC - Exit", infoX, 120); if (imageData) { joy.graphics.print("Size: " + imageData.getWidth() + "x" + imageData.getHeight(), infoX, 160); joy.graphics.print("Format: " + imageData.getFormat(), infoX, 180); } joy.graphics.print("FPS: " + joy.timer.getFPS(), infoX, 220); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/keyboard/basic.js
JavaScript
// Basic keyboard example // Use arrow keys to see the difference between isDown and keypressed joy.window.setMode(800, 600); joy.window.setTitle("Keyboard - Arrow Keys Demo"); joy.load = function() { console.log("Arrow key demo:"); console.log(" LEFT/RIGHT: isDown (fires every frame while held)"); console.log(" UP/DOWN: keypressed (fires once per press)"); console.log(" Escape to exit"); }; joy.keypressed = function(key, scancode, isrepeat) { // keypressed fires once when key goes down if (key === "up") { console.log("UP pressed"); } if (key === "down") { console.log("DOWN pressed"); } if (key === "escape") { joy.window.close(); } }; joy.update = function(dt) { // isDown fires every frame while held if (joy.keyboard.isDown("left")) { console.log("LEFT held"); } if (joy.keyboard.isDown("right")) { console.log("RIGHT held"); } }; joy.draw = function() { };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/keyboard/callbacks.js
JavaScript
// Keyboard callbacks example // Demonstrates keypressed, keyreleased, and textinput callbacks joy.window.setMode(800, 600); joy.window.setTitle("Keyboard Callbacks - Type something"); joy.load = function() { console.log("Type to see textinput callback (actual characters)"); console.log("Press keys to see keypressed/keyreleased (key names)"); console.log("Press Escape to exit"); }; joy.keypressed = function(key, scancode, isrepeat) { if (isrepeat) { console.log("[keypressed] repeat:", key); } else { console.log("[keypressed]", key, "(scancode:", scancode + ")"); } if (key === "escape") { joy.window.close(); } }; joy.keyreleased = function(key, scancode) { console.log("[keyreleased]", key); }; joy.textinput = function(text) { console.log("[textinput]", text); }; joy.update = function(dt) { }; joy.draw = function() { };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/mandelbrot/main.js
JavaScript
// Mandelbrot set compute benchmark with visualization // Tests raw floating-point performance of the JS engine var WIDTH = 800; var HEIGHT = 600; var MAX_ITER = 64; var RUNS = 5; // Store computed iterations for rendering var iterations = null; var benchmarkDone = false; var benchmarkResults = null; var rendered = false; var cachedPoints = null; // Compute escape time for a single point function mandelbrot(cx, cy) { var x = 0; var y = 0; var iter = 0; while (x * x + y * y <= 4 && iter < MAX_ITER) { var xtemp = x * x - y * y + cx; y = 2 * x * y + cy; x = xtemp; iter++; } return iter; } // Compute full Mandelbrot set and store results function computeMandelbrot() { var result = []; var total = 0; for (var py = 0; py < HEIGHT; py++) { var row = []; for (var px = 0; px < WIDTH; px++) { // Map pixel to complex plane [-2.5, 1] x [-1, 1] var cx = (px / WIDTH) * 3.5 - 2.5; var cy = (py / HEIGHT) * 2 - 1; var iter = mandelbrot(cx, cy); row.push(iter); total += iter; } result.push(row); } return { iterations: result, total: total }; } // Convert iteration count to color function iterToColor(iter) { if (iter === MAX_ITER) { return [0, 0, 0]; // Black for points in the set } // Smooth coloring using HSV-like mapping var t = iter / MAX_ITER; var r = Math.floor(9 * (1 - t) * t * t * t * 255); var g = Math.floor(15 * (1 - t) * (1 - t) * t * t * 255); var b = Math.floor(8.5 * (1 - t) * (1 - t) * (1 - t) * t * 255); return [r, g, b]; } // Run benchmark function runBenchmark() { console.log("Mandelbrot Benchmark"); console.log("===================="); console.log("Resolution:", WIDTH, "x", HEIGHT); console.log("Max iterations:", MAX_ITER); console.log("Runs:", RUNS); console.log(""); var times = []; var result = null; for (var i = 0; i < RUNS; i++) { var start = Date.now(); result = computeMandelbrot(); var end = Date.now(); var elapsed = end - start; times.push(elapsed); console.log("Run", i + 1 + ":", elapsed, "ms"); } // Calculate statistics var sum = 0; var min = times[0]; var max = times[0]; for (var i = 0; i < times.length; i++) { sum += times[i]; if (times[i] < min) min = times[i]; if (times[i] > max) max = times[i]; } var avg = sum / times.length; console.log(""); console.log("Results:"); console.log(" Min:", min, "ms"); console.log(" Max:", max, "ms"); console.log(" Avg:", avg.toFixed(1), "ms"); console.log(" Total iterations:", result.total); console.log(""); console.log("Press ESC to exit"); // Store for rendering iterations = result.iterations; benchmarkResults = { min: min, max: max, avg: avg }; benchmarkDone = true; } // Window setup joy.window.setMode(WIDTH, HEIGHT); joy.window.setTitle("Mandelbrot Benchmark"); joy.load = function() { console.log("Computing Mandelbrot set..."); runBenchmark(); }; joy.keypressed = function(key) { if (key === "escape") { joy.window.close(); } }; joy.update = function(dt) {}; joy.draw = function() { if (!benchmarkDone || !iterations) { joy.graphics.setColor(1, 1, 1, 1); joy.graphics.print("Computing...", 10, 10); return; } // Build and render points only once if (!rendered) { // Build array of colored points [[x, y, r, g, b, a], ...] cachedPoints = []; for (var py = 0; py < HEIGHT; py++) { for (var px = 0; px < WIDTH; px++) { var iter = iterations[py][px]; var color = iterToColor(iter); cachedPoints.push([px, py, color[0] / 255, color[1] / 255, color[2] / 255, 1]); } } rendered = true; console.log("Fractal rendered"); } // Draw cached points joy.graphics.points(cachedPoints); // Draw stats overlay joy.graphics.print("Avg: " + benchmarkResults.avg.toFixed(1) + " ms", 10, 10); joy.graphics.print("Min: " + benchmarkResults.min + " ms Max: " + benchmarkResults.max + " ms", 10, 30); joy.graphics.print("Press ESC to exit", 10, 50); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/mandelbrot/main.lua
Lua
-- Mandelbrot set compute benchmark with visualization -- Tests raw floating-point performance of the Lua/LuaJIT engine (using Love2D) local WIDTH = 800 local HEIGHT = 600 local MAX_ITER = 64 local RUNS = 5 -- Store computed iterations for rendering local iterations = nil local benchmarkDone = false local benchmarkResults = nil local rendered = false local cachedPoints = nil -- Compute escape time for a single point local function mandelbrot(cx, cy) local x = 0 local y = 0 local iter = 0 while x * x + y * y <= 4 and iter < MAX_ITER do local xtemp = x * x - y * y + cx y = 2 * x * y + cy x = xtemp iter = iter + 1 end return iter end -- Compute full Mandelbrot set and store results local function computeMandelbrot() local result = {} local total = 0 for py = 0, HEIGHT - 1 do local row = {} for px = 0, WIDTH - 1 do -- Map pixel to complex plane [-2.5, 1] x [-1, 1] local cx = (px / WIDTH) * 3.5 - 2.5 local cy = (py / HEIGHT) * 2 - 1 local iter = mandelbrot(cx, cy) row[px + 1] = iter total = total + iter end result[py + 1] = row end return { iterations = result, total = total } end -- Convert iteration count to color local function iterToColor(iter) if iter == MAX_ITER then return 0, 0, 0 -- Black for points in the set end -- Smooth coloring using HSV-like mapping local t = iter / MAX_ITER local r = math.floor(9 * (1 - t) * t * t * t * 255) local g = math.floor(15 * (1 - t) * (1 - t) * t * t * 255) local b = math.floor(8.5 * (1 - t) * (1 - t) * (1 - t) * t * 255) return r, g, b end -- Run benchmark local function runBenchmark() print("Mandelbrot Benchmark") print("====================") print("Resolution: " .. WIDTH .. " x " .. HEIGHT) print("Max iterations: " .. MAX_ITER) print("Runs: " .. RUNS) print("") local times = {} local result = nil for i = 1, RUNS do local start = love.timer.getTime() * 1000 result = computeMandelbrot() local elapsed = love.timer.getTime() * 1000 - start times[i] = elapsed print("Run " .. i .. ": " .. string.format("%.0f", elapsed) .. " ms") end -- Calculate statistics local sum = 0 local min = times[1] local max = times[1] for i = 1, #times do sum = sum + times[i] if times[i] < min then min = times[i] end if times[i] > max then max = times[i] end end local avg = sum / #times print("") print("Results:") print(" Min: " .. string.format("%.0f", min) .. " ms") print(" Max: " .. string.format("%.0f", max) .. " ms") print(" Avg: " .. string.format("%.1f", avg) .. " ms") print(" Total iterations: " .. result.total) print("") print("Press ESC to exit") -- Store for rendering iterations = result.iterations benchmarkResults = { min = min, max = max, avg = avg } benchmarkDone = true end function love.load() love.window.setMode(WIDTH, HEIGHT) love.window.setTitle("Mandelbrot Benchmark") print("Computing Mandelbrot set...") runBenchmark() end function love.keypressed(key) if key == "escape" then love.event.quit() end end function love.update(dt) end function love.draw() if not benchmarkDone or not iterations then love.graphics.setColor(1, 1, 1, 1) love.graphics.print("Computing...", 10, 10) return end -- Build and render points only once if not rendered then -- Build array of colored points {{x, y, r, g, b, a}, ...} cachedPoints = {} for py = 0, HEIGHT - 1 do for px = 0, WIDTH - 1 do local iter = iterations[py + 1][px + 1] local r, g, b = iterToColor(iter) table.insert(cachedPoints, {px, py, r / 255, g / 255, b / 255, 1}) end end rendered = true print("Fractal rendered") end -- Draw cached points love.graphics.points(cachedPoints) -- Draw stats overlay love.graphics.setColor(1, 1, 1, 1) love.graphics.print("Avg: " .. string.format("%.1f", benchmarkResults.avg) .. " ms", 10, 10) love.graphics.print("Min: " .. string.format("%.0f", benchmarkResults.min) .. " ms Max: " .. string.format("%.0f", benchmarkResults.max) .. " ms", 10, 30) love.graphics.print("Press ESC to exit", 10, 50) end
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/math/bezier.js
JavaScript
// Bezier curve example // Demonstrates BezierCurve creation, manipulation, and rendering joy.window.setMode(800, 600); joy.window.setTitle("Math - Bezier Curves"); joy.graphics.setBackgroundColor(0.1, 0.1, 0.15); var controlPoints = [ {x: 100, y: 500}, {x: 200, y: 100}, {x: 400, y: 100}, {x: 500, y: 400}, {x: 700, y: 300} ]; var curve = null; var selectedPoint = -1; var renderDepth = 5; var animT = 0; var showConstruction = true; joy.load = function() { console.log("Bezier Curve Demo"); console.log(" Click and drag control points"); console.log(" Right-click to add a new point"); console.log(" D: Delete last point"); console.log(" +/-: Change render detail"); console.log(" C: Toggle construction lines"); console.log(" Escape: Exit"); rebuildCurve(); }; function rebuildCurve() { if (controlPoints.length >= 2) { curve = joy.math.newBezierCurve(controlPoints); } } joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } if (key === "d" && controlPoints.length > 2) { controlPoints.pop(); rebuildCurve(); } if (key === "=" || key === "+") { renderDepth = Math.min(renderDepth + 1, 8); console.log("Render depth: " + renderDepth); } if (key === "-") { renderDepth = Math.max(renderDepth - 1, 1); console.log("Render depth: " + renderDepth); } if (key === "c") { showConstruction = !showConstruction; } }; joy.mousepressed = function(x, y, button, istouch, presses) { if (button === 1) { // Check if clicking on a control point for (var i = 0; i < controlPoints.length; i++) { var dx = controlPoints[i].x - x; var dy = controlPoints[i].y - y; if (dx * dx + dy * dy < 225) { // 15px radius selectedPoint = i; return; } } } if (button === 2) { // Right click - add new point controlPoints.push({x: x, y: y}); rebuildCurve(); } }; joy.mousereleased = function(x, y, button) { selectedPoint = -1; }; joy.mousemoved = function(x, y, dx, dy) { if (selectedPoint >= 0) { controlPoints[selectedPoint].x = x; controlPoints[selectedPoint].y = y; rebuildCurve(); } }; joy.update = function(dt) { animT += dt * 0.3; if (animT > 1) animT = 0; }; // De Casteljau construction visualization function drawConstruction(t) { var points = controlPoints.slice(); var level = 0; var colors = [ [1, 0.3, 0.3], [0.3, 1, 0.3], [0.3, 0.3, 1], [1, 1, 0.3], [1, 0.3, 1] ]; while (points.length > 1) { var color = colors[level % colors.length]; joy.graphics.setColor(color[0], color[1], color[2], 0.5); var newPoints = []; for (var i = 0; i < points.length - 1; i++) { // Draw line between adjacent points joy.graphics.line(points[i].x, points[i].y, points[i+1].x, points[i+1].y); // Interpolate to get new point var nx = points[i].x * (1 - t) + points[i+1].x * t; var ny = points[i].y * (1 - t) + points[i+1].y * t; newPoints.push({x: nx, y: ny}); // Draw intermediate point joy.graphics.circle("fill", nx, ny, 4); } points = newPoints; level++; } // Draw the point on curve if (points.length === 1) { joy.graphics.setColor(1, 1, 1); joy.graphics.circle("fill", points[0].x, points[0].y, 8); } } joy.draw = function() { if (!curve) return; // Draw construction lines if enabled if (showConstruction) { drawConstruction(animT); } // Draw the curve var vertices = curve.render(renderDepth); joy.graphics.setColor(0, 0.8, 1); for (var i = 0; i < vertices.length - 1; i++) { joy.graphics.line(vertices[i].x, vertices[i].y, vertices[i+1].x, vertices[i+1].y); } // Draw control polygon joy.graphics.setColor(0.5, 0.5, 0.5, 0.5); for (var i = 0; i < controlPoints.length - 1; i++) { joy.graphics.line( controlPoints[i].x, controlPoints[i].y, controlPoints[i+1].x, controlPoints[i+1].y ); } // Draw control points for (var i = 0; i < controlPoints.length; i++) { if (i === selectedPoint) { joy.graphics.setColor(1, 1, 0); } else { joy.graphics.setColor(1, 0.5, 0); } joy.graphics.circle("fill", controlPoints[i].x, controlPoints[i].y, 10); joy.graphics.setColor(1, 1, 1); joy.graphics.circle("line", controlPoints[i].x, controlPoints[i].y, 10); } // UI joy.graphics.setColor(1, 1, 1); joy.graphics.print("Bezier Curve (degree " + (controlPoints.length - 1) + ")", 10, 10); joy.graphics.print("Control points: " + controlPoints.length, 10, 30); joy.graphics.print("Render depth: " + renderDepth + " (" + vertices.length + " vertices)", 10, 50); joy.graphics.print("t = " + animT.toFixed(2), 10, 70); joy.graphics.setColor(0.7, 0.7, 0.7); joy.graphics.print("Drag points | Right-click: Add | D: Delete | +/-: Detail | C: Construction", 10, 570); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/math/noise.js
JavaScript
// Noise visualization example // Demonstrates 2D Perlin/Simplex noise as an animated terrain joy.window.setMode(800, 600); joy.window.setTitle("Math - Noise Visualization"); joy.graphics.setBackgroundColor(0.05, 0.05, 0.1); var time = 0; var scale = 0.02; var cellSize = 4; var cols, rows; joy.load = function() { cols = Math.ceil(800 / cellSize); rows = Math.ceil(600 / cellSize); console.log("Noise Visualization"); console.log(" Arrow Up/Down: Change scale"); console.log(" Space: Pause/Resume animation"); console.log(" Escape: Exit"); }; var paused = false; joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } if (key === "space") { paused = !paused; } if (key === "up") { scale *= 1.2; console.log("Scale: " + scale.toFixed(4)); } if (key === "down") { scale /= 1.2; console.log("Scale: " + scale.toFixed(4)); } }; joy.update = function(dt) { if (!paused) { time += dt * 0.5; } }; joy.draw = function() { // Draw 2D noise as colored cells for (var y = 0; y < rows; y++) { for (var x = 0; x < cols; x++) { // Use 3D noise with time as the third dimension for animation var n = joy.math.noise(x * scale, y * scale, time); // Color based on noise value (terrain-like coloring) var r, g, b; if (n < 0.35) { // Deep water r = 0.1; g = 0.2; b = 0.5 + n; } else if (n < 0.45) { // Shallow water r = 0.2; g = 0.4; b = 0.7; } else if (n < 0.5) { // Sand/beach r = 0.9; g = 0.85; b = 0.6; } else if (n < 0.7) { // Grass/plains var t = (n - 0.5) / 0.2; r = 0.2 - t * 0.1; g = 0.6 - t * 0.2; b = 0.2; } else if (n < 0.85) { // Mountains var t = (n - 0.7) / 0.15; r = 0.4 + t * 0.2; g = 0.35 + t * 0.15; b = 0.3 + t * 0.1; } else { // Snow peaks r = 0.95; g = 0.95; b = 1.0; } joy.graphics.setColor(r, g, b); joy.graphics.rectangle("fill", x * cellSize, y * cellSize, cellSize, cellSize); } } // Draw UI overlay joy.graphics.setColor(0, 0, 0, 0.7); joy.graphics.rectangle("fill", 5, 5, 200, 70); joy.graphics.setColor(1, 1, 1); joy.graphics.print("2D Noise Terrain", 10, 10); joy.graphics.print("Scale: " + scale.toFixed(4), 10, 30); joy.graphics.print("Time: " + time.toFixed(2) + (paused ? " (paused)" : ""), 10, 50); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/math/random.js
JavaScript
// Random number generation example // Demonstrates RandomGenerator, normal distribution, and seeding joy.window.setMode(800, 600); joy.window.setTitle("Math - Random Numbers"); joy.graphics.setBackgroundColor(0.1, 0.1, 0.15); var particles = []; var histogram = []; var histogramNormal = []; var binCount = 50; // Create a custom RandomGenerator var rng = joy.math.newRandomGenerator(); joy.load = function() { console.log("Random Number Demo"); console.log(" R: Reset with new seed"); console.log(" S: Reset with same seed (deterministic)"); console.log(" Space: Add particles"); console.log(" Escape: Exit"); // Initialize histograms for (var i = 0; i < binCount; i++) { histogram[i] = 0; histogramNormal[i] = 0; } // Set a reproducible seed joy.math.setRandomSeed(12345); generateSamples(); }; function generateSamples() { // Clear histograms for (var i = 0; i < binCount; i++) { histogram[i] = 0; histogramNormal[i] = 0; } // Generate uniform distribution samples for (var i = 0; i < 5000; i++) { var val = joy.math.random(); var bin = Math.floor(val * binCount); if (bin >= 0 && bin < binCount) { histogram[bin]++; } } // Generate normal distribution samples (mean=0.5, stddev=0.15) for (var i = 0; i < 5000; i++) { var val = joy.math.randomNormal(0.15, 0.5); var bin = Math.floor(val * binCount); if (bin >= 0 && bin < binCount) { histogramNormal[bin]++; } } } joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } if (key === "r") { // New random seed joy.math.setRandomSeed(Date.now()); generateSamples(); console.log("New random seed"); } if (key === "s") { // Same seed - deterministic joy.math.setRandomSeed(12345); generateSamples(); console.log("Reset to seed 12345"); } if (key === "space") { // Add random particles for (var i = 0; i < 20; i++) { particles.push({ x: joy.math.random(100, 700), y: joy.math.random(350, 550), vx: joy.math.randomNormal(50, 0), vy: joy.math.randomNormal(50, -100), life: joy.math.random(1, 3), r: joy.math.random(), g: joy.math.random(), b: joy.math.random() }); } } }; joy.update = function(dt) { // Update particles for (var i = particles.length - 1; i >= 0; i--) { var p = particles[i]; p.x += p.vx * dt; p.y += p.vy * dt; p.vy += 200 * dt; // gravity p.life -= dt; if (p.life <= 0) { particles.splice(i, 1); } } }; joy.draw = function() { var barWidth = 700 / binCount; var maxCount = 200; // Draw uniform distribution histogram (top) joy.graphics.setColor(0.3, 0.6, 1); for (var i = 0; i < binCount; i++) { var height = (histogram[i] / maxCount) * 120; joy.graphics.rectangle("fill", 50 + i * barWidth, 150 - height, barWidth - 1, height); } // Draw normal distribution histogram (middle) joy.graphics.setColor(1, 0.5, 0.3); for (var i = 0; i < binCount; i++) { var height = (histogramNormal[i] / maxCount) * 120; joy.graphics.rectangle("fill", 50 + i * barWidth, 300 - height, barWidth - 1, height); } // Draw particles for (var i = 0; i < particles.length; i++) { var p = particles[i]; var alpha = Math.min(1, p.life); joy.graphics.setColor(p.r, p.g, p.b, alpha); joy.graphics.circle("fill", p.x, p.y, 5); } // Labels joy.graphics.setColor(1, 1, 1); joy.graphics.print("Uniform Distribution (joy.math.random)", 50, 10); joy.graphics.print("5000 samples", 50, 155); joy.graphics.print("Normal Distribution (joy.math.randomNormal)", 50, 165); joy.graphics.print("mean=0.5, stddev=0.15", 50, 305); joy.graphics.print("Particles (Space to add)", 50, 340); joy.graphics.print("Count: " + particles.length, 50, 360); joy.graphics.setColor(0.7, 0.7, 0.7); joy.graphics.print("R: New seed | S: Reset seed | Space: Add particles", 50, 570); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/modules/main.js
JavaScript
// Test ES modules support import { greet, PI, Counter } from './utils.js'; var counter = new Counter(0); var message = greet("Joy"); joy.load = function() { console.log("Module test loaded!"); console.log(message); console.log("PI =", PI); }; joy.update = function(dt) { // Update counter every frame }; joy.draw = function() { joy.graphics.clear(0.2, 0.2, 0.3); joy.graphics.setColor(1, 1, 1); joy.graphics.print(message, 50, 50); joy.graphics.print("Counter: " + counter.value, 50, 80); joy.graphics.print("Press SPACE to increment, BACKSPACE to decrement", 50, 110); joy.graphics.print("PI = " + PI, 50, 140); }; joy.keypressed = function(key) { if (key === "space") { counter.increment(); } else if (key === "backspace") { counter.decrement(); } else if (key === "escape") { joy.event.quit(); } };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/modules/utils.js
JavaScript
// A simple utility module export function greet(name) { return "Hello, " + name + "!"; } export const PI = 3.14159; export class Counter { constructor(initial = 0) { this.value = initial; } increment() { this.value++; } decrement() { this.value--; } }
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/mouse/main.js
JavaScript
// Mouse example // Demonstrates mouse callbacks, position, buttons, visibility, and cursors joy.window.setMode(800, 600); joy.window.setTitle("Mouse Demo"); joy.graphics.setBackgroundColor(0.1, 0.1, 0.2); var clicks = []; var currentCursor = "arrow"; var cursorTypes = ["arrow", "ibeam", "wait", "crosshair", "hand", "sizeall", "sizens", "sizewe", "no"]; var cursorIndex = 0; var cursors = {}; var hasFocus = true; var wheelY = 0; joy.load = function() { console.log("Mouse Demo:"); console.log(" Click to place dots (L=red, R=green, M=blue)"); console.log(" Double-click for larger dots"); console.log(" V: Toggle visibility"); console.log(" G: Toggle grab"); console.log(" R: Toggle relative mode"); console.log(" C: Cycle through system cursors"); console.log(" Space: Clear dots"); console.log(" Scroll: Change background brightness"); console.log(" Escape: Exit"); // Pre-create system cursors for (var i = 0; i < cursorTypes.length; i++) { cursors[cursorTypes[i]] = joy.mouse.getSystemCursor(cursorTypes[i]); } }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } if (key === "v") { joy.mouse.setVisible(!joy.mouse.isVisible()); console.log("Cursor visible: " + joy.mouse.isVisible()); } if (key === "g") { joy.mouse.setGrabbed(!joy.mouse.isGrabbed()); console.log("Mouse grabbed: " + joy.mouse.isGrabbed()); } if (key === "r") { var newMode = !joy.mouse.getRelativeMode(); joy.mouse.setRelativeMode(newMode); console.log("Relative mode: " + joy.mouse.getRelativeMode()); } if (key === "c") { cursorIndex = (cursorIndex + 1) % cursorTypes.length; currentCursor = cursorTypes[cursorIndex]; joy.mouse.setCursor(cursors[currentCursor]); console.log("Cursor: " + currentCursor); } if (key === "space") { clicks = []; console.log("Cleared dots"); } }; // Mouse button pressed callback // button: 1=left, 2=right, 3=middle // presses: number of clicks (for double-click detection) joy.mousepressed = function(x, y, button, istouch, presses) { var colors = [ [1, 0.3, 0.3], // Button 1 (left) - Red [0.3, 1, 0.3], // Button 2 (right) - Green [0.3, 0.3, 1] // Button 3 (middle) - Blue ]; var color = colors[Math.min(button - 1, 2)]; var radius = presses > 1 ? 16 : 8; // Larger for double-click clicks.push({x: x, y: y, color: color, button: button, radius: radius}); }; // Mouse button released callback joy.mousereleased = function(x, y, button, istouch, presses) { // Could add release effects here }; // Mouse moved callback joy.mousemoved = function(x, y, dx, dy, istouch) { // dx, dy are delta movement - useful for relative mode }; // Mouse wheel moved callback joy.wheelmoved = function(x, y) { wheelY += y * 0.02; wheelY = Math.max(-0.1, Math.min(0.3, wheelY)); joy.graphics.setBackgroundColor(0.1 + wheelY, 0.1 + wheelY, 0.2 + wheelY); }; // Mouse focus callback joy.mousefocus = function(focus) { hasFocus = focus; console.log("Mouse focus: " + (focus ? "gained" : "lost")); }; joy.update = function(dt) { }; joy.draw = function() { // Draw click dots for (var i = 0; i < clicks.length; i++) { var click = clicks[i]; joy.graphics.setColor(click.color[0], click.color[1], click.color[2]); joy.graphics.circle("fill", click.x, click.y, click.radius); } // Draw crosshair at mouse position var pos = joy.mouse.getPosition(); var mx = pos[0]; var my = pos[1]; joy.graphics.setColor(1, 1, 1, 0.5); joy.graphics.line(mx - 15, my, mx + 15, my); joy.graphics.line(mx, my - 15, mx, my + 15); joy.graphics.setColor(1, 1, 1); joy.graphics.print("Mouse Position: " + Math.floor(mx) + ", " + Math.floor(my), 10, 10); // Button states var btn1 = joy.mouse.isDown(1) ? "DOWN" : "up"; var btn2 = joy.mouse.isDown(2) ? "DOWN" : "up"; var btn3 = joy.mouse.isDown(3) ? "DOWN" : "up"; joy.graphics.print("Buttons: L=" + btn1 + " R=" + btn2 + " M=" + btn3, 10, 30); // States joy.graphics.print("Visible: " + joy.mouse.isVisible() + " (V)", 10, 50); joy.graphics.print("Grabbed: " + joy.mouse.isGrabbed() + " (G)", 10, 70); joy.graphics.print("Relative: " + joy.mouse.getRelativeMode() + " (R)", 10, 90); joy.graphics.print("Cursor: " + currentCursor + " (C)", 10, 110); joy.graphics.print("Focus: " + hasFocus, 10, 130); joy.graphics.setColor(0.7, 0.7, 0.7); joy.graphics.print("Click to place dots, Space to clear", 10, 155); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/system/main.js
JavaScript
// System module example // Displays system information and demonstrates clipboard, URL, and power functions joy.window.setMode(800, 600); joy.window.setTitle("System Info Demo"); joy.graphics.setBackgroundColor(0.1, 0.1, 0.15); var clipboardText = ""; var lastClipboardCheck = 0; var urlOpened = false; joy.load = function() { console.log("System Info Demo:"); console.log(" C: Copy sample text to clipboard"); console.log(" V: Paste from clipboard"); console.log(" U: Open example URL in browser"); console.log(" L: Print preferred locales"); console.log(" Escape: Exit"); // Print system info to console console.log(""); console.log("System Information:"); console.log(" OS: " + joy.system.getOS()); console.log(" Processor Count: " + joy.system.getProcessorCount()); var power = joy.system.getPowerInfo(); console.log(" Power State: " + power[0]); if (power[1] !== null) { console.log(" Battery: " + power[1] + "%"); } if (power[2] !== null) { console.log(" Time Remaining: " + Math.floor(power[2] / 60) + " minutes"); } var locales = joy.system.getPreferredLocales(); console.log(" Preferred Locales: " + (locales.length > 0 ? locales.join(", ") : "none")); }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } if (key === "c") { var text = "Hello from Joy! Time: " + Date.now(); joy.system.setClipboardText(text); console.log("Copied to clipboard: " + text); } if (key === "v") { clipboardText = joy.system.getClipboardText(); console.log("Pasted from clipboard: " + clipboardText); } if (key === "u") { var success = joy.system.openURL("https://love2d.org"); console.log("Open URL: " + (success ? "success" : "failed")); urlOpened = success; } if (key === "l") { var locales = joy.system.getPreferredLocales(); console.log("Preferred locales:"); for (var i = 0; i < locales.length; i++) { console.log(" " + (i + 1) + ": " + locales[i]); } } }; joy.update = function(dt) { }; joy.draw = function() { var y = 20; var lineHeight = 24; // Title joy.graphics.setColor(0.3, 0.7, 1); joy.graphics.print("System Information", 20, y); y += lineHeight + 10; // OS joy.graphics.setColor(1, 1, 1); joy.graphics.print("Operating System: " + joy.system.getOS(), 20, y); y += lineHeight; // Processors joy.graphics.print("Processor Cores: " + joy.system.getProcessorCount(), 20, y); y += lineHeight; // Power info var power = joy.system.getPowerInfo(); var powerStr = "Power: " + power[0]; if (power[1] !== null) { powerStr += " (" + power[1] + "%)"; } if (power[2] !== null && power[2] > 0) { var mins = Math.floor(power[2] / 60); var hours = Math.floor(mins / 60); mins = mins % 60; if (hours > 0) { powerStr += " - " + hours + "h " + mins + "m remaining"; } else { powerStr += " - " + mins + "m remaining"; } } joy.graphics.print(powerStr, 20, y); y += lineHeight; // Locales var locales = joy.system.getPreferredLocales(); var localeStr = locales.length > 0 ? locales.slice(0, 3).join(", ") : "none"; if (locales.length > 3) { localeStr += "..."; } joy.graphics.print("Preferred Locales: " + localeStr, 20, y); y += lineHeight + 20; // Clipboard section joy.graphics.setColor(0.3, 0.7, 1); joy.graphics.print("Clipboard", 20, y); y += lineHeight + 5; joy.graphics.setColor(1, 1, 1); if (clipboardText.length > 0) { var displayText = clipboardText; if (displayText.length > 60) { displayText = displayText.substring(0, 60) + "..."; } joy.graphics.print("Last paste: " + displayText, 20, y); } else { joy.graphics.setColor(0.6, 0.6, 0.6); joy.graphics.print("Press V to paste from clipboard", 20, y); } y += lineHeight + 20; // Instructions joy.graphics.setColor(0.3, 0.7, 1); joy.graphics.print("Controls", 20, y); y += lineHeight + 5; joy.graphics.setColor(0.8, 0.8, 0.8); joy.graphics.print("C - Copy sample text to clipboard", 20, y); y += lineHeight; joy.graphics.print("V - Paste from clipboard", 20, y); y += lineHeight; joy.graphics.print("U - Open love2d.org in browser", 20, y); y += lineHeight; joy.graphics.print("L - Print locales to console", 20, y); y += lineHeight; joy.graphics.print("Escape - Exit", 20, y); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/websocket/client/main.js
JavaScript
// WebSocket client example for Joy2D let ws = null; let messages = []; let inputText = ""; let connected = false; let statusText = "Disconnected"; joy.load = function() { joy.graphics.setBackgroundColor(0.1, 0.1, 0.15); joy.window.setMode(800, 600); joy.window.setTitle("Client"); connect(); }; function connect() { statusText = "Connecting..."; ws = new WebSocket("ws://localhost:8080/ws"); ws.onopen = function(event) { connected = true; statusText = "Connected"; addMessage("System", "Connected to server"); }; ws.onmessage = function(event) { addMessage("Server", event.data); }; ws.onclose = function(event) { connected = false; statusText = "Disconnected (code: " + event.code + ")"; addMessage("System", "Connection closed"); }; ws.onerror = function(event) { addMessage("System", "WebSocket error"); }; } function addMessage(from, text) { messages.push({ from: from, text: text }); // Keep only last 15 messages if (messages.length > 15) { messages.shift(); } } function sendMessage() { if (ws && connected && inputText.length > 0) { ws.send(inputText); addMessage("You", inputText); inputText = ""; } } joy.keypressed = function(key, scancode, isRepeat) { if (key === "escape") { joy.window.close(); } else if (key === "return" || key === "kp_enter") { sendMessage(); } else if (key === "backspace") { inputText = inputText.slice(0, -1); } else if (key === "r" && !connected) { connect(); } }; joy.textinput = function(text) { inputText += text; }; joy.draw = function() { let width = joy.window.getWidth(); let height = joy.window.getHeight(); // Title joy.graphics.setColor(1, 1, 1); joy.graphics.print("WebSocket Example", 20, 20); // Status if (connected) { joy.graphics.setColor(0.3, 1, 0.3); } else { joy.graphics.setColor(1, 0.3, 0.3); } joy.graphics.print("Status: " + statusText, 20, 50); // Messages joy.graphics.setColor(0.8, 0.8, 0.8); let y = 90; for (let i = 0; i < messages.length; i++) { let msg = messages[i]; let color = [0.8, 0.8, 0.8]; if (msg.from === "You") { color = [0.5, 0.8, 1]; } else if (msg.from === "Server") { color = [0.5, 1, 0.5]; } else if (msg.from === "System") { color = [1, 1, 0.5]; } joy.graphics.setColor(color[0], color[1], color[2]); joy.graphics.print("[" + msg.from + "] " + msg.text, 20, y); y += 25; } // Input box joy.graphics.setColor(0.3, 0.3, 0.35); joy.graphics.rectangle("fill", 20, height - 60, width - 40, 40); joy.graphics.setColor(0.5, 0.5, 0.55); joy.graphics.rectangle("line", 20, height - 60, width - 40, 40); // Input text joy.graphics.setColor(1, 1, 1); let displayText = inputText + "_"; joy.graphics.print(displayText, 30, height - 50); // Help text joy.graphics.setColor(0.5, 0.5, 0.5); joy.graphics.print("Type a message and press Enter to send. Press R to reconnect. ESC to quit.", 20, height - 20); };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/websocket/server/main.go
Go
package main import ( "fmt" "log" "net/http" "github.com/gorilla/websocket" ) var upgrader = websocket.Upgrader{ CheckOrigin: func(r *http.Request) bool { return true // Allow all origins for this example }, } func handleWebSocket(w http.ResponseWriter, r *http.Request) { conn, err := upgrader.Upgrade(w, r, nil) if err != nil { log.Println("Upgrade error:", err) return } defer conn.Close() log.Println("Client connected") for { messageType, message, err := conn.ReadMessage() if err != nil { log.Println("Read error:", err) break } log.Printf("Received: %s", message) // Echo the message back with a prefix response := fmt.Sprintf("Server received: %s", message) err = conn.WriteMessage(messageType, []byte(response)) if err != nil { log.Println("Write error:", err) break } } log.Println("Client disconnected") } func main() { http.HandleFunc("/ws", handleWebSocket) addr := "localhost:8080" log.Printf("WebSocket server listening on ws://%s/ws", addr) log.Fatal(http.ListenAndServe(addr, nil)) }
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/window/basic.js
JavaScript
// Basic window example // Creates a simple 800x600 window joy.window.setMode(800, 600); joy.window.setTitle("Basic Window Example"); joy.load = function() { console.log("Window created!"); var mode = joy.window.getMode(); console.log("Size:", mode[0], "x", mode[1]); }; joy.update = function(dt) { }; joy.draw = function() { };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/window/borderless.js
JavaScript
// Borderless window example // Creates a borderless window joy.window.setMode(800, 600, { borderless: true }); joy.window.setTitle("Borderless Window"); // Center the window on screen joy.load = function() { var desktop = joy.window.getDesktopDimensions(); var mode = joy.window.getMode(); var x = (desktop[0] - mode[0]) / 2; var y = (desktop[1] - mode[1]) / 2; joy.window.setPosition(x, y); console.log("Borderless window centered at:", x, y); }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "escape") { joy.window.close(); } }; joy.update = function(dt) { }; joy.draw = function() { };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/window/fullscreen.js
JavaScript
// Fullscreen example // Press F to toggle fullscreen, Escape to exit joy.window.setMode(800, 600); joy.window.setTitle("Press F to toggle fullscreen, Escape to exit"); joy.load = function() { console.log("Press F to toggle fullscreen mode"); console.log("Press Escape to exit"); var dims = joy.window.getDesktopDimensions(); console.log("Desktop resolution:", dims[0], "x", dims[1]); }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "f") { var fs = joy.window.getFullscreen(); joy.window.setFullscreen(!fs[0]); console.log("Fullscreen:", !fs[0]); } if (key === "escape") { joy.window.close(); } }; joy.update = function(dt) { }; joy.draw = function() { };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/window/monitors.js
JavaScript
// Multi-monitor info example // Displays information about all connected monitors joy.window.setMode(800, 600); joy.window.setTitle("Monitor Information"); joy.load = function() { var count = joy.window.getDisplayCount(); console.log("Number of monitors:", count); for (var i = 0; i < count; i++) { var name = joy.window.getDisplayName(i); var dims = joy.window.getDesktopDimensions(i); console.log("Monitor", i + ":", name, "-", dims[0], "x", dims[1]); } console.log("DPI Scale:", joy.window.getDPIScale()); }; joy.update = function(dt) { }; joy.draw = function() { };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/window/resizable.js
JavaScript
// Resizable window example // Creates a resizable window with minimum size constraints joy.window.setMode(800, 600, { resizable: true, minwidth: 400, minheight: 300 }); joy.window.setTitle("Resizable Window - Try resizing me!"); var lastWidth = 0; var lastHeight = 0; joy.load = function() { var mode = joy.window.getMode(); lastWidth = mode[0]; lastHeight = mode[1]; console.log("Initial size:", lastWidth, "x", lastHeight); }; joy.update = function(dt) { var mode = joy.window.getMode(); if (mode[0] !== lastWidth || mode[1] !== lastHeight) { lastWidth = mode[0]; lastHeight = mode[1]; console.log("Window resized to:", lastWidth, "x", lastHeight); } }; joy.draw = function() { };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/window/state.js
JavaScript
// Window state example // Demonstrates minimize, maximize, and restore joy.window.setMode(800, 600, { resizable: true }); joy.window.setTitle("Window State - M:maximize, R:restore, Escape:exit"); joy.load = function() { console.log("Press M to maximize"); console.log("Press R to restore"); console.log("Press Escape to exit"); console.log("(Minimize not shown - updates pause when minimized)"); }; joy.keypressed = function(key, scancode, isrepeat) { if (key === "m") { console.log("Maximizing..."); joy.window.maximize(); } if (key === "r") { console.log("Restoring..."); joy.window.restore(); } if (key === "escape") { joy.window.close(); } }; joy.update = function(dt) { }; joy.draw = function() { };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/worker/main.js
JavaScript
// Web Worker example - Rotating square with position updates from worker thread let worker = null; let squareX = 400; let squareY = 300; let targetX = 400; let targetY = 300; let rotation = 0; const squareSize = 80; const lerpSpeed = 3; joy.load = function() { // Create a worker that will send position updates worker = new Worker("worker.js"); // Handle position updates from worker worker.onmessage = function(event) { if (event.data.type === "position") { targetX = event.data.x; targetY = event.data.y; } }; worker.onerror = function(event) { console.error("Worker error:", event.message); }; // Tell worker the screen dimensions and start sending positions worker.postMessage({ type: "start", width: joy.graphics.getWidth(), height: joy.graphics.getHeight(), margin: squareSize }); }; joy.update = function(dt) { // Rotate the square rotation = rotation + dt * 2; // Smoothly interpolate towards target position squareX = squareX + (targetX - squareX) * lerpSpeed * dt; squareY = squareY + (targetY - squareY) * lerpSpeed * dt; }; joy.draw = function() { // Clear with dark background joy.graphics.setBackgroundColor(0.1, 0.1, 0.15); // Draw the rotating square joy.graphics.push(); joy.graphics.translate(squareX, squareY); joy.graphics.rotate(rotation); joy.graphics.setColor(0.3, 0.6, 1.0); joy.graphics.rectangle("fill", -squareSize/2, -squareSize/2, squareSize, squareSize); joy.graphics.setColor(0.5, 0.8, 1.0); joy.graphics.rectangle("line", -squareSize/2, -squareSize/2, squareSize, squareSize); joy.graphics.pop(); // Draw target indicator joy.graphics.setColor(1, 1, 1, 0.3); joy.graphics.circle("line", targetX, targetY, 10); // Draw info text joy.graphics.setColor(1, 1, 1); joy.graphics.print("Worker Thread Position Demo", 10, 10); joy.graphics.print("Worker sends new position every second", 10, 30); joy.graphics.print("Press ESC to exit", 10, 50); joy.graphics.print("Position: " + Math.floor(squareX) + ", " + Math.floor(squareY), 10, 80); }; joy.keypressed = function(key) { if (key === "escape") { if (worker) { worker.terminate(); worker = null; } joy.window.close(); } };
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
examples/worker/worker.js
JavaScript
// Worker script - sends random position updates every second let screenWidth = 800; let screenHeight = 600; let margin = 80; // Handle messages from main thread self.onmessage = function(event) { if (event.data.type === "start") { screenWidth = event.data.width; screenHeight = event.data.height; margin = event.data.margin; // Start the position update loop runPositionLoop(); } }; function runPositionLoop() { // Loop until terminated while (!joy.worker.isTerminated()) { // Generate random position within screen bounds const x = joy.math.random(margin, screenWidth - margin); const y = joy.math.random(margin, screenHeight - margin); // Send position to main thread self.postMessage({ type: "position", x: x, y: y }); // Sleep for 1 second (interruptible) joy.timer.sleep(1.0); } }
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
resources/ProggyClean.ttf.h
C/C++ Header
unsigned char ProggyClean_ttf[] = { 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x80, 0x00, 0x03, 0x00, 0x40, 0x4f, 0x53, 0x2f, 0x32, 0x88, 0xeb, 0x74, 0x90, 0x00, 0x00, 0x01, 0x48, 0x00, 0x00, 0x00, 0x4e, 0x63, 0x6d, 0x61, 0x70, 0x02, 0x12, 0x23, 0x75, 0x00, 0x00, 0x03, 0xa0, 0x00, 0x00, 0x01, 0x52, 0x63, 0x76, 0x74, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xfc, 0x00, 0x00, 0x00, 0x02, 0x67, 0x6c, 0x79, 0x66, 0x12, 0xaf, 0x89, 0x56, 0x00, 0x00, 0x07, 0x04, 0x00, 0x00, 0x92, 0x80, 0x68, 0x65, 0x61, 0x64, 0xd7, 0x91, 0x66, 0xd3, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x36, 0x68, 0x68, 0x65, 0x61, 0x08, 0x42, 0x01, 0xc3, 0x00, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x24, 0x68, 0x6d, 0x74, 0x78, 0x8a, 0x00, 0x7e, 0x80, 0x00, 0x00, 0x01, 0x98, 0x00, 0x00, 0x02, 0x06, 0x6c, 0x6f, 0x63, 0x61, 0x8c, 0x73, 0xb0, 0xd8, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x02, 0x04, 0x6d, 0x61, 0x78, 0x70, 0x01, 0xae, 0x00, 0xda, 0x00, 0x00, 0x01, 0x28, 0x00, 0x00, 0x00, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x25, 0x59, 0xbb, 0x96, 0x00, 0x00, 0x99, 0x84, 0x00, 0x00, 0x01, 0x9e, 0x70, 0x6f, 0x73, 0x74, 0xa6, 0xac, 0x83, 0xef, 0x00, 0x00, 0x9b, 0x24, 0x00, 0x00, 0x05, 0xd2, 0x70, 0x72, 0x65, 0x70, 0x69, 0x02, 0x01, 0x12, 0x00, 0x00, 0x04, 0xf4, 0x00, 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x3c, 0x55, 0xe9, 0xd5, 0x5f, 0x0f, 0x3c, 0xf5, 0x00, 0x03, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb7, 0x67, 0x77, 0x84, 0x00, 0x00, 0x00, 0x00, 0xbd, 0x92, 0xa6, 0xd7, 0x00, 0x00, 0xfe, 0x80, 0x03, 0x80, 0x05, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x04, 0xc0, 0xfe, 0x40, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x90, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x08, 0x00, 0x40, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x76, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x01, 0x90, 0x00, 0x05, 0x00, 0x00, 0x02, 0xbc, 0x02, 0x8a, 0x00, 0x00, 0x00, 0x8f, 0x02, 0xbc, 0x02, 0x8a, 0x00, 0x00, 0x01, 0xc5, 0x00, 0x32, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x6c, 0x74, 0x73, 0x00, 0x40, 0x00, 0x00, 0x20, 0xac, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x01, 0x80, 0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x03, 0x80, 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0x00, 0x01, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x01, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x01, 0x80, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x00, 0x80, 0x03, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x00, 0x80, 0x03, 0x80, 0x03, 0x80, 0x01, 0x80, 0x01, 0x00, 0x01, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x01, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x01, 0x80, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x01, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x30, 0x00, 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, 0x02, 0x00, 0x00, 0x00, 0x7f, 0x00, 0xff, 0x20, 0xac, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x20, 0xac, 0xff, 0xff, 0x00, 0x01, 0x00, 0x01, 0xdf, 0xd5, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x00, 0x01, 0x8d, 0xb8, 0x01, 0xff, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xc6, 0x00, 0xf4, 0x01, 0x1c, 0x01, 0x9e, 0x02, 0x14, 0x02, 0x88, 0x02, 0xfc, 0x03, 0x14, 0x03, 0x58, 0x03, 0x9c, 0x03, 0xde, 0x04, 0x14, 0x04, 0x32, 0x04, 0x50, 0x04, 0x62, 0x04, 0xa2, 0x05, 0x16, 0x05, 0x66, 0x05, 0xbc, 0x06, 0x12, 0x06, 0x74, 0x06, 0xd6, 0x07, 0x38, 0x07, 0x7e, 0x07, 0xec, 0x08, 0x4e, 0x08, 0x6c, 0x08, 0x96, 0x08, 0xd0, 0x09, 0x10, 0x09, 0x4a, 0x09, 0x88, 0x0a, 0x16, 0x0a, 0x80, 0x0b, 0x04, 0x0b, 0x56, 0x0b, 0xc8, 0x0c, 0x2e, 0x0c, 0x82, 0x0c, 0xea, 0x0d, 0x5e, 0x0d, 0xa4, 0x0d, 0xea, 0x0e, 0x50, 0x0e, 0x96, 0x0f, 0x28, 0x0f, 0xb0, 0x10, 0x12, 0x10, 0x74, 0x10, 0xe0, 0x11, 0x52, 0x11, 0xb6, 0x12, 0x04, 0x12, 0x6e, 0x12, 0xc4, 0x13, 0x4c, 0x13, 0xac, 0x13, 0xf6, 0x14, 0x58, 0x14, 0xae, 0x14, 0xea, 0x15, 0x40, 0x15, 0x80, 0x15, 0xa6, 0x15, 0xb8, 0x16, 0x12, 0x16, 0x7e, 0x16, 0xc6, 0x17, 0x34, 0x17, 0x8e, 0x17, 0xe0, 0x18, 0x56, 0x18, 0xba, 0x18, 0xee, 0x19, 0x36, 0x19, 0x96, 0x19, 0xd4, 0x1a, 0x48, 0x1a, 0x9c, 0x1a, 0xf0, 0x1b, 0x5c, 0x1b, 0xc8, 0x1c, 0x04, 0x1c, 0x4c, 0x1c, 0x96, 0x1c, 0xea, 0x1d, 0x2a, 0x1d, 0x92, 0x1d, 0xd2, 0x1e, 0x40, 0x1e, 0x8e, 0x1e, 0xe0, 0x1f, 0x24, 0x1f, 0x76, 0x1f, 0xa6, 0x1f, 0xa6, 0x20, 0x10, 0x20, 0x10, 0x20, 0x2e, 0x20, 0x8a, 0x20, 0xb2, 0x20, 0xc8, 0x21, 0x14, 0x21, 0x74, 0x21, 0x98, 0x21, 0xee, 0x22, 0x62, 0x22, 0x86, 0x23, 0x0c, 0x23, 0x0c, 0x23, 0x80, 0x23, 0x80, 0x23, 0x80, 0x23, 0x98, 0x23, 0xb0, 0x23, 0xd8, 0x24, 0x00, 0x24, 0x4a, 0x24, 0x68, 0x24, 0x90, 0x24, 0xae, 0x25, 0x06, 0x25, 0x60, 0x25, 0x82, 0x25, 0xf8, 0x25, 0xf8, 0x26, 0x58, 0x26, 0xaa, 0x26, 0xaa, 0x26, 0xd8, 0x27, 0x40, 0x27, 0x9a, 0x28, 0x0a, 0x28, 0x68, 0x28, 0xa8, 0x29, 0x0e, 0x29, 0x20, 0x29, 0xb8, 0x29, 0xf8, 0x2a, 0x36, 0x2a, 0x60, 0x2a, 0x60, 0x2b, 0x02, 0x2b, 0x2a, 0x2b, 0x5e, 0x2b, 0xac, 0x2b, 0xe6, 0x2c, 0x20, 0x2c, 0x34, 0x2c, 0x9a, 0x2d, 0x28, 0x2d, 0x5c, 0x2d, 0x78, 0x2d, 0xaa, 0x2d, 0xe8, 0x2e, 0x26, 0x2e, 0xa6, 0x2f, 0x26, 0x2f, 0xb6, 0x2f, 0xf4, 0x30, 0x5e, 0x30, 0xc8, 0x31, 0x3e, 0x31, 0xb4, 0x32, 0x1e, 0x32, 0x9e, 0x33, 0x1e, 0x33, 0x82, 0x33, 0xee, 0x34, 0x5c, 0x34, 0xce, 0x35, 0x3a, 0x35, 0x86, 0x35, 0xd4, 0x36, 0x26, 0x36, 0x72, 0x36, 0xe6, 0x37, 0x76, 0x37, 0xd8, 0x38, 0x3a, 0x38, 0xa6, 0x39, 0x12, 0x39, 0x74, 0x39, 0xae, 0x3a, 0x2e, 0x3a, 0x9a, 0x3b, 0x06, 0x3b, 0x7c, 0x3b, 0xe8, 0x3c, 0x3a, 0x3c, 0x96, 0x3d, 0x22, 0x3d, 0x86, 0x3d, 0xec, 0x3e, 0x56, 0x3e, 0xc6, 0x3f, 0x2a, 0x3f, 0x9a, 0x40, 0x12, 0x40, 0x6a, 0x40, 0xd0, 0x41, 0x36, 0x41, 0xa2, 0x42, 0x08, 0x42, 0x40, 0x42, 0x7a, 0x42, 0xb8, 0x42, 0xf0, 0x43, 0x62, 0x43, 0xcc, 0x44, 0x2a, 0x44, 0x8a, 0x44, 0xee, 0x45, 0x58, 0x45, 0xb6, 0x45, 0xe2, 0x46, 0x54, 0x46, 0xb4, 0x47, 0x14, 0x47, 0x7a, 0x47, 0xda, 0x48, 0x54, 0x48, 0xc6, 0x49, 0x40, 0x00, 0x24, 0x00, 0x00, 0xfe, 0x80, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x5f, 0x00, 0x63, 0x00, 0x67, 0x00, 0x6b, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x77, 0x00, 0x7b, 0x00, 0x7f, 0x00, 0x83, 0x00, 0x87, 0x00, 0x8b, 0x00, 0x8f, 0x00, 0x00, 0x11, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x07, 0x01, 0x80, 0x00, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x03, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x00, 0x06, 0x01, 0x00, 0x03, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x5f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x15, 0x00, 0x80, 0xff, 0x80, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x03, 0x01, 0x80, 0x03, 0x00, 0x02, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0b, 0x01, 0x00, 0xff, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0b, 0x01, 0x00, 0xff, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0b, 0x00, 0x80, 0x00, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x09, 0x00, 0x80, 0x00, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x04, 0x00, 0x80, 0xff, 0x00, 0x01, 0x80, 0x01, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x00, 0x25, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x05, 0x00, 0x80, 0x01, 0x80, 0x03, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x25, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0a, 0x00, 0x80, 0xff, 0x80, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x02, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0f, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0f, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x11, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x02, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x11, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x13, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x11, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x04, 0x01, 0x80, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x03, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x06, 0x00, 0x80, 0xff, 0x00, 0x01, 0x80, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x03, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x80, 0x01, 0x00, 0x03, 0x80, 0x02, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x02, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0a, 0x00, 0x80, 0x00, 0x80, 0x03, 0x80, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x03, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x5f, 0x00, 0x63, 0x00, 0x67, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x5f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x13, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0c, 0x01, 0x00, 0x00, 0x00, 0x02, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0c, 0x00, 0x80, 0x00, 0x00, 0x02, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x11, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x5f, 0x00, 0x63, 0x00, 0x67, 0x00, 0x00, 0x11, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x80, 0x01, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x18, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x5f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x80, 0xff, 0x80, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x00, 0x11, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x00, 0x11, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x5f, 0x00, 0x00, 0x11, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x00, 0x11, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0f, 0x01, 0x00, 0xff, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0a, 0x00, 0x80, 0xff, 0x80, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0f, 0x01, 0x00, 0xff, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0a, 0x00, 0x80, 0x01, 0x80, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0xff, 0x80, 0x03, 0x80, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x00, 0x15, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x02, 0x01, 0x00, 0x03, 0x80, 0x02, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0c, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x80, 0xfe, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x11, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x80, 0xff, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x11, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x80, 0xfe, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x13, 0x00, 0x80, 0xfe, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0a, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0d, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0d, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0e, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x11, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0a, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x80, 0xfe, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0e, 0x00, 0x80, 0xff, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0b, 0x01, 0x80, 0xff, 0x00, 0x02, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0e, 0x00, 0x80, 0xff, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x01, 0x80, 0x03, 0x80, 0x02, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0x02, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x13, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0xff, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x00, 0x25, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0xff, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x06, 0x01, 0x00, 0xff, 0x80, 0x02, 0x80, 0x01, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x00, 0x25, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x03, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x00, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x00, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x11, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x80, 0x03, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x05, 0x00, 0x80, 0x00, 0x80, 0x02, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x5f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x15, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x03, 0x01, 0x80, 0x03, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x03, 0x00, 0x02, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x06, 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x06, 0x00, 0x80, 0x03, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0d, 0x00, 0x80, 0x00, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x80, 0x01, 0x80, 0x03, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x07, 0x00, 0x00, 0x01, 0x80, 0x03, 0x80, 0x02, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x00, 0x11, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x80, 0x03, 0x00, 0x02, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x02, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x11, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x80, 0x00, 0x80, 0x02, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x00, 0x13, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x07, 0x01, 0x80, 0x00, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x03, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x12, 0x00, 0x80, 0xff, 0x80, 0x03, 0x00, 0x03, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x03, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x11, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x02, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x80, 0x80, 0x03, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x11, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x01, 0x80, 0xff, 0x00, 0x02, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x03, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x02, 0x01, 0x00, 0x04, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x5f, 0x00, 0x63, 0x00, 0x67, 0x00, 0x6b, 0x00, 0x6f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0b, 0x00, 0x80, 0x01, 0x80, 0x02, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0a, 0x00, 0x80, 0x00, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x07, 0x00, 0x80, 0x00, 0x00, 0x02, 0x80, 0x02, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x5f, 0x00, 0x63, 0x00, 0x67, 0x00, 0x6b, 0x00, 0x6f, 0x00, 0x73, 0x00, 0x77, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x04, 0x80, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x00, 0x11, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x80, 0x02, 0x80, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x03, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0a, 0x00, 0x80, 0x02, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0a, 0x00, 0x80, 0x02, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x80, 0x03, 0x80, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0xff, 0x00, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0xff, 0x00, 0x03, 0x80, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0xff, 0x00, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x80, 0xff, 0x80, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x5f, 0x00, 0x63, 0x00, 0x67, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x09, 0x01, 0x00, 0x01, 0x00, 0x02, 0x80, 0x02, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x02, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x04, 0x01, 0x80, 0xfe, 0x80, 0x02, 0x80, 0x00, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x00, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x08, 0x00, 0x80, 0x02, 0x00, 0x02, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x80, 0x02, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0a, 0x00, 0x80, 0x00, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x16, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x02, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x02, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x5f, 0x00, 0x63, 0x00, 0x67, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x02, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0a, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x03, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x03, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x16, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x11, 0x00, 0x80, 0xfe, 0x80, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0xff, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0d, 0x01, 0x00, 0x00, 0x00, 0x02, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x00, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0d, 0x01, 0x00, 0x00, 0x00, 0x02, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0e, 0x01, 0x00, 0x00, 0x00, 0x02, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0d, 0x01, 0x00, 0x00, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x03, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfc, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x19, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x5f, 0x00, 0x63, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x03, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x09, 0x00, 0x80, 0x00, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x16, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0xff, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0xff, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x02, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x02, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0xff, 0x80, 0x03, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x5b, 0x00, 0x5f, 0x00, 0x63, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x02, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x00, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x13, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x04, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x57, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfc, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0x01, 0x00, 0x80, 0xfd, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x80, 0xfe, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x02, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x03, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x13, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x00, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x03, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x01, 0x00, 0x00, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 0x02, 0x80, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x14, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x11, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x12, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x07, 0x00, 0x80, 0x00, 0x80, 0x03, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x02, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x00, 0x00, 0x14, 0x00, 0x80, 0xff, 0x80, 0x03, 0x00, 0x03, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x02, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x00, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x01, 0x00, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x03, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x1d, 0x01, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x11, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x15, 0x00, 0x80, 0xfe, 0x80, 0x03, 0x00, 0x04, 0x80, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x02, 0x00, 0x80, 0xff, 0x00, 0x80, 0xfe, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x04, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x14, 0x00, 0x80, 0xff, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x00, 0x13, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x15, 0x00, 0x80, 0xfe, 0x80, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0b, 0x00, 0x0f, 0x00, 0x13, 0x00, 0x17, 0x00, 0x1b, 0x00, 0x1f, 0x00, 0x23, 0x00, 0x27, 0x00, 0x2b, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x3f, 0x00, 0x43, 0x00, 0x47, 0x00, 0x4b, 0x00, 0x4f, 0x00, 0x53, 0x00, 0x00, 0x01, 0x35, 0x33, 0x15, 0x33, 0x35, 0x33, 0x15, 0x01, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x21, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x07, 0x35, 0x33, 0x15, 0x05, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x31, 0x35, 0x33, 0x15, 0x01, 0x00, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfd, 0x80, 0x80, 0x01, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xfe, 0x00, 0x80, 0x80, 0x80, 0x03, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1a, 0x00, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0e, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x1a, 0x00, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x1a, 0x00, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x1a, 0x00, 0x82, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0d, 0x00, 0x31, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x07, 0x00, 0x26, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x11, 0x00, 0x2d, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x31, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0a, 0x00, 0x3e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x0d, 0x00, 0x31, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x00, 0x00, 0x24, 0x00, 0x48, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x01, 0x00, 0x1a, 0x00, 0x82, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x02, 0x00, 0x0e, 0x00, 0x6c, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x03, 0x00, 0x22, 0x00, 0x7a, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x04, 0x00, 0x1a, 0x00, 0x82, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x05, 0x00, 0x14, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x04, 0x09, 0x00, 0x06, 0x00, 0x1a, 0x00, 0x82, 0x00, 0x32, 0x00, 0x30, 0x00, 0x30, 0x00, 0x34, 0x00, 0x2f, 0x00, 0x30, 0x00, 0x34, 0x00, 0x2f, 0x00, 0x31, 0x00, 0x35, 0x62, 0x79, 0x20, 0x54, 0x72, 0x69, 0x73, 0x74, 0x61, 0x6e, 0x20, 0x47, 0x72, 0x69, 0x6d, 0x6d, 0x65, 0x72, 0x52, 0x65, 0x67, 0x75, 0x6c, 0x61, 0x72, 0x54, 0x54, 0x58, 0x20, 0x50, 0x72, 0x6f, 0x67, 0x67, 0x79, 0x43, 0x6c, 0x65, 0x61, 0x6e, 0x54, 0x54, 0x32, 0x30, 0x30, 0x34, 0x2f, 0x30, 0x34, 0x2f, 0x31, 0x35, 0x00, 0x62, 0x00, 0x79, 0x00, 0x20, 0x00, 0x54, 0x00, 0x72, 0x00, 0x69, 0x00, 0x73, 0x00, 0x74, 0x00, 0x61, 0x00, 0x6e, 0x00, 0x20, 0x00, 0x47, 0x00, 0x72, 0x00, 0x69, 0x00, 0x6d, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x72, 0x00, 0x52, 0x00, 0x65, 0x00, 0x67, 0x00, 0x75, 0x00, 0x6c, 0x00, 0x61, 0x00, 0x72, 0x00, 0x54, 0x00, 0x54, 0x00, 0x58, 0x00, 0x20, 0x00, 0x50, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x67, 0x00, 0x67, 0x00, 0x79, 0x00, 0x43, 0x00, 0x6c, 0x00, 0x65, 0x00, 0x61, 0x00, 0x6e, 0x00, 0x54, 0x00, 0x54, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x01, 0x03, 0x01, 0x04, 0x01, 0x05, 0x01, 0x06, 0x01, 0x07, 0x01, 0x08, 0x01, 0x09, 0x01, 0x0a, 0x01, 0x0b, 0x01, 0x0c, 0x01, 0x0d, 0x01, 0x0e, 0x01, 0x0f, 0x01, 0x10, 0x01, 0x11, 0x01, 0x12, 0x01, 0x13, 0x01, 0x14, 0x01, 0x15, 0x01, 0x16, 0x01, 0x17, 0x01, 0x18, 0x01, 0x19, 0x01, 0x1a, 0x01, 0x1b, 0x01, 0x1c, 0x01, 0x1d, 0x01, 0x1e, 0x01, 0x1f, 0x01, 0x20, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09, 0x00, 0x0a, 0x00, 0x0b, 0x00, 0x0c, 0x00, 0x0d, 0x00, 0x0e, 0x00, 0x0f, 0x00, 0x10, 0x00, 0x11, 0x00, 0x12, 0x00, 0x13, 0x00, 0x14, 0x00, 0x15, 0x00, 0x16, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, 0x00, 0x1a, 0x00, 0x1b, 0x00, 0x1c, 0x00, 0x1d, 0x00, 0x1e, 0x00, 0x1f, 0x00, 0x20, 0x00, 0x21, 0x00, 0x22, 0x00, 0x23, 0x00, 0x24, 0x00, 0x25, 0x00, 0x26, 0x00, 0x27, 0x00, 0x28, 0x00, 0x29, 0x00, 0x2a, 0x00, 0x2b, 0x00, 0x2c, 0x00, 0x2d, 0x00, 0x2e, 0x00, 0x2f, 0x00, 0x30, 0x00, 0x31, 0x00, 0x32, 0x00, 0x33, 0x00, 0x34, 0x00, 0x35, 0x00, 0x36, 0x00, 0x37, 0x00, 0x38, 0x00, 0x39, 0x00, 0x3a, 0x00, 0x3b, 0x00, 0x3c, 0x00, 0x3d, 0x00, 0x3e, 0x00, 0x3f, 0x00, 0x40, 0x00, 0x41, 0x00, 0x42, 0x00, 0x43, 0x00, 0x44, 0x00, 0x45, 0x00, 0x46, 0x00, 0x47, 0x00, 0x48, 0x00, 0x49, 0x00, 0x4a, 0x00, 0x4b, 0x00, 0x4c, 0x00, 0x4d, 0x00, 0x4e, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x51, 0x00, 0x52, 0x00, 0x53, 0x00, 0x54, 0x00, 0x55, 0x00, 0x56, 0x00, 0x57, 0x00, 0x58, 0x00, 0x59, 0x00, 0x5a, 0x00, 0x5b, 0x00, 0x5c, 0x00, 0x5d, 0x00, 0x5e, 0x00, 0x5f, 0x00, 0x60, 0x00, 0x61, 0x01, 0x21, 0x01, 0x22, 0x01, 0x23, 0x01, 0x24, 0x01, 0x25, 0x01, 0x26, 0x01, 0x27, 0x01, 0x28, 0x01, 0x29, 0x01, 0x2a, 0x01, 0x2b, 0x01, 0x2c, 0x01, 0x2d, 0x01, 0x2e, 0x01, 0x2f, 0x01, 0x30, 0x01, 0x31, 0x01, 0x32, 0x01, 0x33, 0x01, 0x34, 0x01, 0x35, 0x01, 0x36, 0x01, 0x37, 0x01, 0x38, 0x01, 0x39, 0x01, 0x3a, 0x01, 0x3b, 0x01, 0x3c, 0x01, 0x3d, 0x01, 0x3e, 0x01, 0x3f, 0x01, 0x40, 0x01, 0x41, 0x00, 0xac, 0x00, 0xa3, 0x00, 0x84, 0x00, 0x85, 0x00, 0xbd, 0x00, 0x96, 0x00, 0xe8, 0x00, 0x86, 0x00, 0x8e, 0x00, 0x8b, 0x00, 0x9d, 0x00, 0xa9, 0x00, 0xa4, 0x00, 0xef, 0x00, 0x8a, 0x00, 0xda, 0x00, 0x83, 0x00, 0x93, 0x00, 0xf2, 0x00, 0xf3, 0x00, 0x8d, 0x00, 0x97, 0x00, 0x88, 0x00, 0xc3, 0x00, 0xde, 0x00, 0xf1, 0x00, 0x9e, 0x00, 0xaa, 0x00, 0xf5, 0x00, 0xf4, 0x00, 0xf6, 0x00, 0xa2, 0x00, 0xad, 0x00, 0xc9, 0x00, 0xc7, 0x00, 0xae, 0x00, 0x62, 0x00, 0x63, 0x00, 0x90, 0x00, 0x64, 0x00, 0xcb, 0x00, 0x65, 0x00, 0xc8, 0x00, 0xca, 0x00, 0xcf, 0x00, 0xcc, 0x00, 0xcd, 0x00, 0xce, 0x00, 0xe9, 0x00, 0x66, 0x00, 0xd3, 0x00, 0xd0, 0x00, 0xd1, 0x00, 0xaf, 0x00, 0x67, 0x00, 0xf0, 0x00, 0x91, 0x00, 0xd6, 0x00, 0xd4, 0x00, 0xd5, 0x00, 0x68, 0x00, 0xeb, 0x00, 0xed, 0x00, 0x89, 0x00, 0x6a, 0x00, 0x69, 0x00, 0x6b, 0x00, 0x6d, 0x00, 0x6c, 0x00, 0x6e, 0x00, 0xa0, 0x00, 0x6f, 0x00, 0x71, 0x00, 0x70, 0x00, 0x72, 0x00, 0x73, 0x00, 0x75, 0x00, 0x74, 0x00, 0x76, 0x00, 0x77, 0x00, 0xea, 0x00, 0x78, 0x00, 0x7a, 0x00, 0x79, 0x00, 0x7b, 0x00, 0x7d, 0x00, 0x7c, 0x00, 0xb8, 0x00, 0xa1, 0x00, 0x7f, 0x00, 0x7e, 0x00, 0x80, 0x00, 0x81, 0x00, 0xec, 0x00, 0xee, 0x00, 0xba, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x31, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x32, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x33, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x34, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x35, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x36, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x37, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x38, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x39, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x61, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x62, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x63, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x64, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x65, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x30, 0x66, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x30, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x31, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x32, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x33, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x34, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x35, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x36, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x37, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x38, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x39, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x61, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x62, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x63, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x64, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x65, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x31, 0x66, 0x06, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x04, 0x45, 0x75, 0x72, 0x6f, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x31, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x32, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x33, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x34, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x35, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x36, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x37, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x38, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x39, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x61, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x62, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x63, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x64, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x65, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x38, 0x66, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x30, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x31, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x32, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x33, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x34, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x35, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x36, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x37, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x38, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x39, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x61, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x62, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x63, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x64, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x65, 0x0e, 0x75, 0x6e, 0x69, 0x63, 0x6f, 0x64, 0x65, 0x23, 0x30, 0x78, 0x30, 0x30, 0x39, 0x66, 0x00, 0x00 }; unsigned int ProggyClean_ttf_len = 41208;
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/bundle.cc
C++
#include "bundle.hh" #include "miniz.h" #include "physfs.h" #include <cstdio> #include <cstring> #include <cstdlib> namespace joy { // Read entire file from PhysFS into memory static char *readPhysFile(const char *path, size_t *out_size) { PHYSFS_File *file = PHYSFS_openRead(path); if (!file) { return nullptr; } PHYSFS_sint64 len = PHYSFS_fileLength(file); if (len < 0) { PHYSFS_close(file); return nullptr; } char *buf = static_cast<char *>(malloc(len)); if (!buf) { PHYSFS_close(file); return nullptr; } PHYSFS_sint64 bytes_read = PHYSFS_readBytes(file, buf, len); PHYSFS_close(file); if (bytes_read != len) { free(buf); return nullptr; } *out_size = static_cast<size_t>(len); return buf; } // Recursively add directory contents to zip archive static int addDirectoryToZip(mz_zip_archive *zip, const char *dir_path) { char **files = PHYSFS_enumerateFiles(dir_path); if (!files) { fprintf(stderr, "Error: Cannot enumerate directory '%s': %s\n", dir_path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); return -1; } int result = 0; for (char **file = files; *file != nullptr; file++) { // Build full PhysFS path size_t path_len = strlen(dir_path) + strlen(*file) + 2; char *full_path = static_cast<char *>(malloc(path_len)); if (dir_path[0] == '\0') { snprintf(full_path, path_len, "%s", *file); } else { snprintf(full_path, path_len, "%s/%s", dir_path, *file); } // Get file stats PHYSFS_Stat stat; if (!PHYSFS_stat(full_path, &stat)) { free(full_path); continue; } if (stat.filetype == PHYSFS_FILETYPE_DIRECTORY) { // Recurse into subdirectory if (addDirectoryToZip(zip, full_path) != 0) { free(full_path); result = -1; break; } } else if (stat.filetype == PHYSFS_FILETYPE_REGULAR) { // Read file and add to archive size_t file_size; char *file_data = readPhysFile(full_path, &file_size); if (!file_data) { fprintf(stderr, "Error: Failed to read '%s'\n", full_path); free(full_path); result = -1; break; } if (!mz_zip_writer_add_mem(zip, full_path, file_data, file_size, MZ_BEST_COMPRESSION)) { fprintf(stderr, "Error: Failed to add '%s' to archive\n", full_path); free(file_data); free(full_path); result = -1; break; } printf(" Added: %s\n", full_path); free(file_data); } free(full_path); } PHYSFS_freeList(files); return result; } int createBundle(const char *output_path, const char *source_dir) { printf("Creating bundle: %s\n", output_path); printf("Source: %s\n", source_dir); // Mount the source directory if (!PHYSFS_mount(source_dir, "/", 0)) { fprintf(stderr, "Error: Failed to mount '%s': %s\n", source_dir, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); return 1; } mz_zip_archive zip; memset(&zip, 0, sizeof(zip)); if (!mz_zip_writer_init_file(&zip, output_path, 0)) { fprintf(stderr, "Error: Failed to create archive '%s'\n", output_path); PHYSFS_unmount(source_dir); return 1; } int result = addDirectoryToZip(&zip, ""); if (result == 0) { if (!mz_zip_writer_finalize_archive(&zip)) { fprintf(stderr, "Error: Failed to finalize archive\n"); result = 1; } } mz_zip_writer_end(&zip); // Unmount directory PHYSFS_unmount(source_dir); if (result == 0) { printf("Bundle created successfully!\n"); } else { remove(output_path); } return result; } } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/bundle.hh
C++ Header
#pragma once namespace joy { // Create a .joy bundle from a directory // Returns 0 on success, non-zero on error int createBundle(const char *output_path, const char *source_dir); } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/engine.cc
C++
#include "engine.hh" #include "render.hh" #include "modules/window/window.hh" #include "modules/info/info.hh" #include "modules/keyboard/keyboard.hh" #include "modules/mouse/mouse.hh" #include "modules/graphics/graphics.hh" #include "modules/audio/audio.hh" #include "modules/filesystem/filesystem.hh" #include "modules/gui/gui.hh" #include "modules/timer/timer.hh" #include "modules/image/image.hh" #include "modules/system/system.hh" #include "modules/math/math.hh" #include "modules/data/data.hh" #include "modules/sound/sound.hh" #include "modules/joystick/joystick.hh" #include "web-api/websocket.hh" #include "web-api/worker.hh" #include "js/js.hh" #include "physfs.h" #include <cstdio> #include <cstdlib> #include <string> #include <vector> namespace joy { // Forward declaration from joystick_js.cc namespace modules { js::Value createJoystickJSObject(js::Context &ctx, Joystick *joystick); } // Console log/warn/error using js:: abstraction static void js_console_log(js::FunctionArgs &args) { js::Context &ctx = args.context(); for (int i = 0; i < args.length(); i++) { if (i > 0) fputc(' ', stdout); std::string str = args.arg(i).toString(ctx); fputs(str.c_str(), stdout); } fputc('\n', stdout); args.returnUndefined(); } static void js_console_warn(js::FunctionArgs &args) { js::Context &ctx = args.context(); fprintf(stderr, "[warn] "); for (int i = 0; i < args.length(); i++) { if (i > 0) fputc(' ', stderr); std::string str = args.arg(i).toString(ctx); fputs(str.c_str(), stderr); } fputc('\n', stderr); args.returnUndefined(); } static void js_console_error(js::FunctionArgs &args) { js::Context &ctx = args.context(); fprintf(stderr, "[error] "); for (int i = 0; i < args.length(); i++) { if (i > 0) fputc(' ', stderr); std::string str = args.arg(i).toString(ctx); fputs(str.c_str(), stderr); } fputc('\n', stderr); args.returnUndefined(); } Engine::Engine() : window_(nullptr) , window_width_(800) , window_height_(600) , render_(nullptr) , window_module_(nullptr) , keyboard_module_(nullptr) , mouse_module_(nullptr) , graphics_module_(nullptr) , audio_module_(nullptr) , filesystem_module_(nullptr) , gui_module_(nullptr) , info_module_(nullptr) , timer_module_(nullptr) , image_module_(nullptr) , system_module_(nullptr) , math_module_(nullptr) , data_module_(nullptr) , sound_module_(nullptr) , joystick_module_(nullptr) , websocket_module_(nullptr) #ifndef __EMSCRIPTEN__ , worker_module_(nullptr) #endif , running_(false) { } Engine::~Engine() { // PersistentValues and unique_ptrs will clean themselves up automatically // Order matters: clear callbacks first, then context, then runtime // Clear callbacks (implicitly done by unique_ptr destructor) cb_load_.reset(); cb_update_.reset(); cb_draw_.reset(); cb_keypressed_.reset(); cb_keyreleased_.reset(); cb_textinput_.reset(); cb_mousepressed_.reset(); cb_mousereleased_.reset(); cb_mousemoved_.reset(); cb_wheelmoved_.reset(); cb_mousefocus_.reset(); cb_joystickadded_.reset(); cb_joystickremoved_.reset(); cb_joystickpressed_.reset(); cb_joystickreleased_.reset(); cb_joystickaxis_.reset(); cb_joystickhat_.reset(); cb_gamepadpressed_.reset(); cb_gamepadreleased_.reset(); cb_gamepadaxis_.reset(); js_joy_.reset(); js_global_.reset(); // Cleanup modules #ifndef __EMSCRIPTEN__ delete worker_module_; #endif delete websocket_module_; delete gui_module_; delete filesystem_module_; delete audio_module_; delete window_module_; delete keyboard_module_; delete mouse_module_; delete graphics_module_; delete info_module_; delete timer_module_; delete image_module_; delete system_module_; delete math_module_; delete data_module_; delete sound_module_; delete joystick_module_; // Clear context before runtime js_ctx_.reset(); js_rt_.reset(); // Cleanup render backend delete render_; // Cleanup window if (window_) { SDL_DestroyWindow(window_); } } bool Engine::init() { // Initialize JavaScript runtime if (!initScript()) { return false; } // Create window #ifdef RENDER_METAL Uint32 flags = SDL_WINDOW_METAL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY; #else Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY; #endif window_ = SDL_CreateWindow("Joy2D", window_width_, window_height_, flags); if (!window_) { fprintf(stderr, "Failed to create window: %s\n", SDL_GetError()); return false; } // Enable text input by default so GUI text fields work SDL_StartTextInput(window_); // Bring window to foreground (needed when launching from terminal/tmux) SDL_RaiseWindow(window_); // Initialize GUI context (before render backend, as it doesn't need GPU yet) if (!gui_module_->init()) { fprintf(stderr, "Warning: Failed to initialize GUI context\n"); } // Initialize render backend render_ = new render::Render(); if (!render_->init(window_)) { fprintf(stderr, "Failed to initialize renderer\n"); return false; } // Set graphics module for text rendering render_->setGraphicsModule(graphics_module_); // Set GUI module for GUI rendering render_->setGuiModule(gui_module_); // Initialize batch renderer (after sokol_gfx is set up) if (!graphics_module_->initBatchRenderer()) { fprintf(stderr, "Failed to initialize batch renderer\n"); return false; } // Initialize text rendering if (!graphics_module_->initText()) { fprintf(stderr, "Warning: Failed to initialize text rendering\n"); } // Initialize GUI rendering (after sokol_gfx is set up) if (!gui_module_->initRendering(window_)) { fprintf(stderr, "Warning: Failed to initialize GUI rendering\n"); } running_ = true; return true; } bool Engine::initScript() { js_rt_ = std::make_unique<js::Runtime>(); if (!js_rt_) { fprintf(stderr, "Failed to create JS runtime\n"); return false; } js_ctx_ = std::make_unique<js::Context>(*js_rt_); if (!js_ctx_) { fprintf(stderr, "Failed to create JS context\n"); return false; } // Get global object and store it js::Value global = js_ctx_->globalObject(); js_global_ = std::make_unique<js::PersistentValue>(*js_ctx_, global); // Create console object using ModuleBuilder js::ModuleBuilder(*js_ctx_, "console") .function("log", js_console_log, 1) .function("warn", js_console_warn, 1) .function("error", js_console_error, 1) .attachTo(global); // Create joy namespace js::Value joy = js::Value::object(*js_ctx_); global.setProperty(*js_ctx_, "joy", joy); js_joy_ = std::make_unique<js::PersistentValue>(*js_ctx_, joy); // Store engine pointer in context js_ctx_->setOpaque(this); // Set up ES module loader js_ctx_->setModuleLoader( [this](const char *referrer, const char *specifier, std::string &resolved, std::string &source) -> bool { // Resolve the module path std::string spec(specifier); // Absolute path - use as-is if (!spec.empty() && spec[0] == '/') { resolved = spec; } else { // Relative path - resolve against referrer's directory std::string referrer_dir; if (referrer && referrer[0] != '\0') { std::string ref(referrer); size_t last_slash = ref.rfind('/'); if (last_slash != std::string::npos) { referrer_dir = ref.substr(0, last_slash + 1); } else { referrer_dir = "/"; } } else { referrer_dir = "/"; } // Combine and normalize path std::string result = referrer_dir + spec; // Simple path normalization std::vector<std::string> parts; size_t pos = 0; while (pos < result.size()) { size_t next = result.find('/', pos); if (next == std::string::npos) next = result.size(); std::string part = result.substr(pos, next - pos); if (part == "..") { if (!parts.empty() && parts.back() != "..") { parts.pop_back(); } } else if (part != "." && !part.empty()) { parts.push_back(part); } pos = next + 1; } resolved = "/"; for (size_t i = 0; i < parts.size(); i++) { resolved += parts[i]; if (i < parts.size() - 1) resolved += "/"; } } // Read the file via PhysFS size_t size; char *buf = readFile(resolved.c_str(), &size); if (!buf) { return false; } source.assign(buf, size); free(buf); return true; }); // Create modules window_module_ = new modules::Window(this); keyboard_module_ = new modules::Keyboard(this); mouse_module_ = new modules::Mouse(this); graphics_module_ = new modules::Graphics(this); audio_module_ = new modules::Audio(this); filesystem_module_ = new modules::Filesystem(this); gui_module_ = new modules::Gui(this); info_module_ = new modules::Info(); timer_module_ = new modules::Timer(); image_module_ = new modules::Image(this); system_module_ = new modules::System(this); math_module_ = new modules::Math(); data_module_ = new modules::DataModule(); sound_module_ = new modules::Sound(this); joystick_module_ = new modules::JoystickModule(this); websocket_module_ = new webapi::WebSocket(this); #ifndef __EMSCRIPTEN__ worker_module_ = new webapi::Worker(this); #endif // Initialize audio engine if (!audio_module_->init()) { fprintf(stderr, "Warning: Failed to initialize audio\n"); } // Initialize joystick subsystem if (!joystick_module_->init()) { fprintf(stderr, "Warning: Failed to initialize joystick subsystem\n"); } // Initialize joy.* modules modules::Info::initJS(*js_ctx_, joy); modules::Keyboard::initJS(*js_ctx_, joy); modules::Mouse::initJS(*js_ctx_, joy); modules::Window::initJS(*js_ctx_, joy); modules::Filesystem::initJS(*js_ctx_, joy); modules::Gui::initJS(*js_ctx_, joy); modules::Graphics::initJS(*js_ctx_, joy); modules::Audio::initJS(*js_ctx_, joy); modules::Timer::initJS(*js_ctx_, joy); modules::Image::initJS(*js_ctx_, joy); modules::System::initJS(*js_ctx_, joy); modules::Math::initJS(*js_ctx_, joy); modules::DataModule::initJS(*js_ctx_, joy); modules::Sound::initJS(*js_ctx_, joy); modules::JoystickModule::initJS(*js_ctx_, joy); // Initialize Web API bindings (on global object, not joy namespace) webapi::WebSocket::initJS(*js_ctx_, global); #ifndef __EMSCRIPTEN__ webapi::Worker::initJS(*js_ctx_, global); #endif return true; } bool Engine::mountGame(const char *path) { if (!PHYSFS_mount(path, "/", 1)) { fprintf(stderr, "Failed to mount '%s': %s\n", path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); return false; } return true; } char *Engine::readFile(const char *filename, size_t *out_size) { PHYSFS_File *file = PHYSFS_openRead(filename); if (!file) { return nullptr; } PHYSFS_sint64 len = PHYSFS_fileLength(file); if (len < 0) { PHYSFS_close(file); return nullptr; } char *buf = (char *)malloc(len + 1); if (!buf) { PHYSFS_close(file); return nullptr; } PHYSFS_sint64 bytes_read = PHYSFS_readBytes(file, buf, len); PHYSFS_close(file); if (bytes_read != len) { free(buf); return nullptr; } buf[len] = '\0'; if (out_size) *out_size = (size_t)len; return buf; } bool Engine::loadScript(const char *filename) { size_t size; char *buf = readFile(filename, &size); if (!buf) { fprintf(stderr, "Failed to read %s\n", filename); return false; } js::Value result = js_ctx_->evalModule(buf, size, filename); free(buf); if (result.isException()) { fprintf(stderr, "JavaScript error:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); return false; } // Get callbacks js::Value load_cb = getCallback("load"); js::Value update_cb = getCallback("update"); js::Value draw_cb = getCallback("draw"); js::Value keypressed_cb = getCallback("keypressed"); js::Value keyreleased_cb = getCallback("keyreleased"); js::Value textinput_cb = getCallback("textinput"); js::Value mousepressed_cb = getCallback("mousepressed"); js::Value mousereleased_cb = getCallback("mousereleased"); js::Value mousemoved_cb = getCallback("mousemoved"); js::Value wheelmoved_cb = getCallback("wheelmoved"); js::Value mousefocus_cb = getCallback("mousefocus"); js::Value joystickadded_cb = getCallback("joystickadded"); js::Value joystickremoved_cb = getCallback("joystickremoved"); js::Value joystickpressed_cb = getCallback("joystickpressed"); js::Value joystickreleased_cb = getCallback("joystickreleased"); js::Value joystickaxis_cb = getCallback("joystickaxis"); js::Value joystickhat_cb = getCallback("joystickhat"); js::Value gamepadpressed_cb = getCallback("gamepadpressed"); js::Value gamepadreleased_cb = getCallback("gamepadreleased"); js::Value gamepadaxis_cb = getCallback("gamepadaxis"); cb_load_ = std::make_unique<js::PersistentValue>(*js_ctx_, load_cb); cb_update_ = std::make_unique<js::PersistentValue>(*js_ctx_, update_cb); cb_draw_ = std::make_unique<js::PersistentValue>(*js_ctx_, draw_cb); cb_keypressed_ = std::make_unique<js::PersistentValue>(*js_ctx_, keypressed_cb); cb_keyreleased_ = std::make_unique<js::PersistentValue>(*js_ctx_, keyreleased_cb); cb_textinput_ = std::make_unique<js::PersistentValue>(*js_ctx_, textinput_cb); cb_mousepressed_ = std::make_unique<js::PersistentValue>(*js_ctx_, mousepressed_cb); cb_mousereleased_ = std::make_unique<js::PersistentValue>(*js_ctx_, mousereleased_cb); cb_mousemoved_ = std::make_unique<js::PersistentValue>(*js_ctx_, mousemoved_cb); cb_wheelmoved_ = std::make_unique<js::PersistentValue>(*js_ctx_, wheelmoved_cb); cb_mousefocus_ = std::make_unique<js::PersistentValue>(*js_ctx_, mousefocus_cb); cb_joystickadded_ = std::make_unique<js::PersistentValue>(*js_ctx_, joystickadded_cb); cb_joystickremoved_ = std::make_unique<js::PersistentValue>(*js_ctx_, joystickremoved_cb); cb_joystickpressed_ = std::make_unique<js::PersistentValue>(*js_ctx_, joystickpressed_cb); cb_joystickreleased_ = std::make_unique<js::PersistentValue>(*js_ctx_, joystickreleased_cb); cb_joystickaxis_ = std::make_unique<js::PersistentValue>(*js_ctx_, joystickaxis_cb); cb_joystickhat_ = std::make_unique<js::PersistentValue>(*js_ctx_, joystickhat_cb); cb_gamepadpressed_ = std::make_unique<js::PersistentValue>(*js_ctx_, gamepadpressed_cb); cb_gamepadreleased_ = std::make_unique<js::PersistentValue>(*js_ctx_, gamepadreleased_cb); cb_gamepadaxis_ = std::make_unique<js::PersistentValue>(*js_ctx_, gamepadaxis_cb); // Call load callback if (!cb_load_->isEmpty() && load_cb.isFunction()) { js::Value global = js_global_->get(*js_ctx_); js::Value result = js_ctx_->call(load_cb, global, nullptr, 0); if (result.isException()) { fprintf(stderr, "Error in load callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } // Call joystickadded for already-connected joysticks (after load, like Love2D) if (!cb_joystickadded_->isEmpty() && joystickadded_cb.isFunction()) { const auto &joysticks = joystick_module_->getJoysticks(); for (modules::Joystick *joystick : joysticks) { js::Value global = js_global_->get(*js_ctx_); js::Value joystickObj = modules::createJoystickJSObject(*js_ctx_, joystick); js::Value result = js_ctx_->call(joystickadded_cb, global, &joystickObj, 1); if (result.isException()) { fprintf(stderr, "Error in joystickadded callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } } return true; } js::Value Engine::getCallback(const char *name) { js::Value joy = js_joy_->get(*js_ctx_); js::Value val = joy.getProperty(*js_ctx_, name); if (val.isFunction()) { return val; } return js::Value::undefined(); } void Engine::frame() { // Step timer and get delta time double dt = timer_module_->step(); // Begin GUI frame if (gui_module_) { gui_module_->beginFrame(); } // Call update callback if (cb_update_ && !cb_update_->isEmpty()) { js::Value update_cb = cb_update_->get(*js_ctx_); if (update_cb.isFunction()) { js::Value global = js_global_->get(*js_ctx_); js::Value dt_val = js::Value::number(static_cast<double>(dt)); js::Value result = js_ctx_->call(update_cb, global, &dt_val, 1); if (result.isException()) { fprintf(stderr, "Error in update callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } } // Render render_->beginFrame(); graphics_module_->clear(0, 0, 0, 0, false); // Use background color // Call draw callback if (cb_draw_ && !cb_draw_->isEmpty()) { js::Value draw_cb = cb_draw_->get(*js_ctx_); if (draw_cb.isFunction()) { js::Value global = js_global_->get(*js_ctx_); js::Value result = js_ctx_->call(draw_cb, global, nullptr, 0); if (result.isException()) { fprintf(stderr, "Error in draw callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } } // End GUI frame and render if (gui_module_) { gui_module_->endFrame(); } render_->endFrame(); } void Engine::handleKeyPressed(SDL_Scancode scancode, bool repeat) { if (!cb_keypressed_ || cb_keypressed_->isEmpty()) { return; } js::Value keypressed_cb = cb_keypressed_->get(*js_ctx_); if (!keypressed_cb.isFunction()) { return; } const char *key_name = modules::Keyboard::getKeyName(scancode); if (!key_name) { key_name = ""; } js::Value args[3]; args[0] = js::Value::string(*js_ctx_, key_name); args[1] = js::Value::number(static_cast<int32_t>(scancode)); args[2] = js::Value::boolean(repeat); js::Value global = js_global_->get(*js_ctx_); js::Value result = js_ctx_->call(keypressed_cb, global, args, 3); if (result.isException()) { fprintf(stderr, "Error in keypressed callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleKeyReleased(SDL_Scancode scancode) { if (!cb_keyreleased_ || cb_keyreleased_->isEmpty()) { return; } js::Value keyreleased_cb = cb_keyreleased_->get(*js_ctx_); if (!keyreleased_cb.isFunction()) { return; } const char *key_name = modules::Keyboard::getKeyName(scancode); if (!key_name) { key_name = ""; } js::Value args[2]; args[0] = js::Value::string(*js_ctx_, key_name); args[1] = js::Value::number(static_cast<int32_t>(scancode)); js::Value global = js_global_->get(*js_ctx_); js::Value result = js_ctx_->call(keyreleased_cb, global, args, 2); if (result.isException()) { fprintf(stderr, "Error in keyreleased callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleTextInput(const char *text) { if (!cb_textinput_ || cb_textinput_->isEmpty()) { return; } js::Value textinput_cb = cb_textinput_->get(*js_ctx_); if (!textinput_cb.isFunction()) { return; } js::Value arg = js::Value::string(*js_ctx_, text); js::Value global = js_global_->get(*js_ctx_); js::Value result = js_ctx_->call(textinput_cb, global, &arg, 1); if (result.isException()) { fprintf(stderr, "Error in textinput callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleMousePressed(float x, float y, int button, int clicks) { if (!cb_mousepressed_ || cb_mousepressed_->isEmpty()) { return; } js::Value mousepressed_cb = cb_mousepressed_->get(*js_ctx_); if (!mousepressed_cb.isFunction()) { return; } // Love2D button mapping: 1=left, 2=right, 3=middle // SDL button mapping: 1=left, 2=middle, 3=right // Swap 2 and 3 to match Love2D int love_button = button; if (button == 2) { love_button = 3; // SDL middle -> Love right } else if (button == 3) { love_button = 2; // SDL right -> Love middle } js::Value args[5]; args[0] = js::Value::number(static_cast<double>(x)); args[1] = js::Value::number(static_cast<double>(y)); args[2] = js::Value::number(love_button); args[3] = js::Value::boolean(false); // istouch args[4] = js::Value::number(clicks); js::Value global = js_global_->get(*js_ctx_); js::Value result = js_ctx_->call(mousepressed_cb, global, args, 5); if (result.isException()) { fprintf(stderr, "Error in mousepressed callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleMouseReleased(float x, float y, int button, int clicks) { if (!cb_mousereleased_ || cb_mousereleased_->isEmpty()) { return; } js::Value mousereleased_cb = cb_mousereleased_->get(*js_ctx_); if (!mousereleased_cb.isFunction()) { return; } // Love2D button mapping: 1=left, 2=right, 3=middle // SDL button mapping: 1=left, 2=middle, 3=right int love_button = button; if (button == 2) { love_button = 3; } else if (button == 3) { love_button = 2; } js::Value args[5]; args[0] = js::Value::number(static_cast<double>(x)); args[1] = js::Value::number(static_cast<double>(y)); args[2] = js::Value::number(love_button); args[3] = js::Value::boolean(false); // istouch args[4] = js::Value::number(clicks); js::Value global = js_global_->get(*js_ctx_); js::Value result = js_ctx_->call(mousereleased_cb, global, args, 5); if (result.isException()) { fprintf(stderr, "Error in mousereleased callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleMouseMoved(float x, float y, float dx, float dy) { if (!cb_mousemoved_ || cb_mousemoved_->isEmpty()) { return; } js::Value mousemoved_cb = cb_mousemoved_->get(*js_ctx_); if (!mousemoved_cb.isFunction()) { return; } js::Value args[5]; args[0] = js::Value::number(static_cast<double>(x)); args[1] = js::Value::number(static_cast<double>(y)); args[2] = js::Value::number(static_cast<double>(dx)); args[3] = js::Value::number(static_cast<double>(dy)); args[4] = js::Value::boolean(false); // istouch js::Value global = js_global_->get(*js_ctx_); js::Value result = js_ctx_->call(mousemoved_cb, global, args, 5); if (result.isException()) { fprintf(stderr, "Error in mousemoved callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleMouseWheel(float x, float y) { if (!cb_wheelmoved_ || cb_wheelmoved_->isEmpty()) { return; } js::Value wheelmoved_cb = cb_wheelmoved_->get(*js_ctx_); if (!wheelmoved_cb.isFunction()) { return; } js::Value args[2]; args[0] = js::Value::number(static_cast<double>(x)); args[1] = js::Value::number(static_cast<double>(y)); js::Value global = js_global_->get(*js_ctx_); js::Value result = js_ctx_->call(wheelmoved_cb, global, args, 2); if (result.isException()) { fprintf(stderr, "Error in wheelmoved callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleMouseFocus(bool focus) { if (!cb_mousefocus_ || cb_mousefocus_->isEmpty()) { return; } js::Value mousefocus_cb = cb_mousefocus_->get(*js_ctx_); if (!mousefocus_cb.isFunction()) { return; } js::Value arg = js::Value::boolean(focus); js::Value global = js_global_->get(*js_ctx_); js::Value result = js_ctx_->call(mousefocus_cb, global, &arg, 1); if (result.isException()) { fprintf(stderr, "Error in mousefocus callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleJoystickAdded(SDL_JoystickID deviceId) { // Add the joystick to our module modules::Joystick *joystick = joystick_module_->addJoystick(deviceId); if (!joystick) { return; } if (!cb_joystickadded_ || cb_joystickadded_->isEmpty()) { return; } js::Value joystickadded_cb = cb_joystickadded_->get(*js_ctx_); if (!joystickadded_cb.isFunction()) { return; } js::Value global = js_global_->get(*js_ctx_); js::Value joystickObj = modules::createJoystickJSObject(*js_ctx_, joystick); js::Value result = js_ctx_->call(joystickadded_cb, global, &joystickObj, 1); if (result.isException()) { fprintf(stderr, "Error in joystickadded callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleJoystickRemoved(SDL_JoystickID instanceId) { modules::Joystick *joystick = joystick_module_->getJoystickFromID(instanceId); if (!joystick) { return; } // Call callback before removing if (cb_joystickremoved_ && !cb_joystickremoved_->isEmpty()) { js::Value joystickremoved_cb = cb_joystickremoved_->get(*js_ctx_); if (joystickremoved_cb.isFunction()) { js::Value global = js_global_->get(*js_ctx_); js::Value joystickObj = modules::createJoystickJSObject(*js_ctx_, joystick); js::Value result = js_ctx_->call(joystickremoved_cb, global, &joystickObj, 1); if (result.isException()) { fprintf(stderr, "Error in joystickremoved callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } } // Remove the joystick joystick_module_->removeJoystick(instanceId); } void Engine::handleJoystickPressed(SDL_JoystickID instanceId, int button) { if (!cb_joystickpressed_ || cb_joystickpressed_->isEmpty()) { return; } modules::Joystick *joystick = joystick_module_->getJoystickFromID(instanceId); if (!joystick) { return; } js::Value joystickpressed_cb = cb_joystickpressed_->get(*js_ctx_); if (!joystickpressed_cb.isFunction()) { return; } js::Value global = js_global_->get(*js_ctx_); js::Value args[2]; args[0] = modules::createJoystickJSObject(*js_ctx_, joystick); args[1] = js::Value::number(button + 1); // 1-indexed like Love2D js::Value result = js_ctx_->call(joystickpressed_cb, global, args, 2); if (result.isException()) { fprintf(stderr, "Error in joystickpressed callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleJoystickReleased(SDL_JoystickID instanceId, int button) { if (!cb_joystickreleased_ || cb_joystickreleased_->isEmpty()) { return; } modules::Joystick *joystick = joystick_module_->getJoystickFromID(instanceId); if (!joystick) { return; } js::Value joystickreleased_cb = cb_joystickreleased_->get(*js_ctx_); if (!joystickreleased_cb.isFunction()) { return; } js::Value global = js_global_->get(*js_ctx_); js::Value args[2]; args[0] = modules::createJoystickJSObject(*js_ctx_, joystick); args[1] = js::Value::number(button + 1); // 1-indexed like Love2D js::Value result = js_ctx_->call(joystickreleased_cb, global, args, 2); if (result.isException()) { fprintf(stderr, "Error in joystickreleased callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleJoystickAxis(SDL_JoystickID instanceId, int axis, float value) { if (!cb_joystickaxis_ || cb_joystickaxis_->isEmpty()) { return; } modules::Joystick *joystick = joystick_module_->getJoystickFromID(instanceId); if (!joystick) { return; } js::Value joystickaxis_cb = cb_joystickaxis_->get(*js_ctx_); if (!joystickaxis_cb.isFunction()) { return; } js::Value global = js_global_->get(*js_ctx_); js::Value args[3]; args[0] = modules::createJoystickJSObject(*js_ctx_, joystick); args[1] = js::Value::number(axis + 1); // 1-indexed like Love2D args[2] = js::Value::number(value); js::Value result = js_ctx_->call(joystickaxis_cb, global, args, 3); if (result.isException()) { fprintf(stderr, "Error in joystickaxis callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleJoystickHat(SDL_JoystickID instanceId, int hat, int value) { if (!cb_joystickhat_ || cb_joystickhat_->isEmpty()) { return; } modules::Joystick *joystick = joystick_module_->getJoystickFromID(instanceId); if (!joystick) { return; } js::Value joystickhat_cb = cb_joystickhat_->get(*js_ctx_); if (!joystickhat_cb.isFunction()) { return; } // Convert SDL hat value to Love2D hat string modules::JoystickHat hatEnum = modules::JoystickHat::Centered; switch (value) { case SDL_HAT_CENTERED: hatEnum = modules::JoystickHat::Centered; break; case SDL_HAT_UP: hatEnum = modules::JoystickHat::Up; break; case SDL_HAT_RIGHT: hatEnum = modules::JoystickHat::Right; break; case SDL_HAT_DOWN: hatEnum = modules::JoystickHat::Down; break; case SDL_HAT_LEFT: hatEnum = modules::JoystickHat::Left; break; case SDL_HAT_RIGHTUP: hatEnum = modules::JoystickHat::RightUp; break; case SDL_HAT_RIGHTDOWN: hatEnum = modules::JoystickHat::RightDown; break; case SDL_HAT_LEFTUP: hatEnum = modules::JoystickHat::LeftUp; break; case SDL_HAT_LEFTDOWN: hatEnum = modules::JoystickHat::LeftDown; break; } js::Value global = js_global_->get(*js_ctx_); js::Value args[3]; args[0] = modules::createJoystickJSObject(*js_ctx_, joystick); args[1] = js::Value::number(hat + 1); // 1-indexed like Love2D args[2] = js::Value::string(*js_ctx_, modules::Joystick::getHatName(hatEnum)); js::Value result = js_ctx_->call(joystickhat_cb, global, args, 3); if (result.isException()) { fprintf(stderr, "Error in joystickhat callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleGamepadPressed(SDL_JoystickID instanceId, int button) { if (!cb_gamepadpressed_ || cb_gamepadpressed_->isEmpty()) { return; } modules::Joystick *joystick = joystick_module_->getJoystickFromID(instanceId); if (!joystick) { return; } js::Value gamepadpressed_cb = cb_gamepadpressed_->get(*js_ctx_); if (!gamepadpressed_cb.isFunction()) { return; } // Convert SDL button to Love2D button name modules::GamepadButton btn = modules::GamepadButton::Invalid; switch (static_cast<SDL_GamepadButton>(button)) { case SDL_GAMEPAD_BUTTON_SOUTH: btn = modules::GamepadButton::A; break; case SDL_GAMEPAD_BUTTON_EAST: btn = modules::GamepadButton::B; break; case SDL_GAMEPAD_BUTTON_WEST: btn = modules::GamepadButton::X; break; case SDL_GAMEPAD_BUTTON_NORTH: btn = modules::GamepadButton::Y; break; case SDL_GAMEPAD_BUTTON_BACK: btn = modules::GamepadButton::Back; break; case SDL_GAMEPAD_BUTTON_GUIDE: btn = modules::GamepadButton::Guide; break; case SDL_GAMEPAD_BUTTON_START: btn = modules::GamepadButton::Start; break; case SDL_GAMEPAD_BUTTON_LEFT_STICK: btn = modules::GamepadButton::LeftStick; break; case SDL_GAMEPAD_BUTTON_RIGHT_STICK: btn = modules::GamepadButton::RightStick; break; case SDL_GAMEPAD_BUTTON_LEFT_SHOULDER: btn = modules::GamepadButton::LeftShoulder; break; case SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER: btn = modules::GamepadButton::RightShoulder; break; case SDL_GAMEPAD_BUTTON_DPAD_UP: btn = modules::GamepadButton::DPadUp; break; case SDL_GAMEPAD_BUTTON_DPAD_DOWN: btn = modules::GamepadButton::DPadDown; break; case SDL_GAMEPAD_BUTTON_DPAD_LEFT: btn = modules::GamepadButton::DPadLeft; break; case SDL_GAMEPAD_BUTTON_DPAD_RIGHT: btn = modules::GamepadButton::DPadRight; break; case SDL_GAMEPAD_BUTTON_MISC1: btn = modules::GamepadButton::Misc1; break; case SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1: btn = modules::GamepadButton::Paddle1; break; case SDL_GAMEPAD_BUTTON_LEFT_PADDLE1: btn = modules::GamepadButton::Paddle2; break; case SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2: btn = modules::GamepadButton::Paddle3; break; case SDL_GAMEPAD_BUTTON_LEFT_PADDLE2: btn = modules::GamepadButton::Paddle4; break; case SDL_GAMEPAD_BUTTON_TOUCHPAD: btn = modules::GamepadButton::Touchpad; break; default: return; // Unknown button } const char *buttonName = modules::Joystick::getGamepadButtonName(btn); if (!buttonName || buttonName[0] == '\0') { return; } js::Value global = js_global_->get(*js_ctx_); js::Value args[2]; args[0] = modules::createJoystickJSObject(*js_ctx_, joystick); args[1] = js::Value::string(*js_ctx_, buttonName); js::Value result = js_ctx_->call(gamepadpressed_cb, global, args, 2); if (result.isException()) { fprintf(stderr, "Error in gamepadpressed callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleGamepadReleased(SDL_JoystickID instanceId, int button) { if (!cb_gamepadreleased_ || cb_gamepadreleased_->isEmpty()) { return; } modules::Joystick *joystick = joystick_module_->getJoystickFromID(instanceId); if (!joystick) { return; } js::Value gamepadreleased_cb = cb_gamepadreleased_->get(*js_ctx_); if (!gamepadreleased_cb.isFunction()) { return; } // Convert SDL button to Love2D button name modules::GamepadButton btn = modules::GamepadButton::Invalid; switch (static_cast<SDL_GamepadButton>(button)) { case SDL_GAMEPAD_BUTTON_SOUTH: btn = modules::GamepadButton::A; break; case SDL_GAMEPAD_BUTTON_EAST: btn = modules::GamepadButton::B; break; case SDL_GAMEPAD_BUTTON_WEST: btn = modules::GamepadButton::X; break; case SDL_GAMEPAD_BUTTON_NORTH: btn = modules::GamepadButton::Y; break; case SDL_GAMEPAD_BUTTON_BACK: btn = modules::GamepadButton::Back; break; case SDL_GAMEPAD_BUTTON_GUIDE: btn = modules::GamepadButton::Guide; break; case SDL_GAMEPAD_BUTTON_START: btn = modules::GamepadButton::Start; break; case SDL_GAMEPAD_BUTTON_LEFT_STICK: btn = modules::GamepadButton::LeftStick; break; case SDL_GAMEPAD_BUTTON_RIGHT_STICK: btn = modules::GamepadButton::RightStick; break; case SDL_GAMEPAD_BUTTON_LEFT_SHOULDER: btn = modules::GamepadButton::LeftShoulder; break; case SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER: btn = modules::GamepadButton::RightShoulder; break; case SDL_GAMEPAD_BUTTON_DPAD_UP: btn = modules::GamepadButton::DPadUp; break; case SDL_GAMEPAD_BUTTON_DPAD_DOWN: btn = modules::GamepadButton::DPadDown; break; case SDL_GAMEPAD_BUTTON_DPAD_LEFT: btn = modules::GamepadButton::DPadLeft; break; case SDL_GAMEPAD_BUTTON_DPAD_RIGHT: btn = modules::GamepadButton::DPadRight; break; case SDL_GAMEPAD_BUTTON_MISC1: btn = modules::GamepadButton::Misc1; break; case SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1: btn = modules::GamepadButton::Paddle1; break; case SDL_GAMEPAD_BUTTON_LEFT_PADDLE1: btn = modules::GamepadButton::Paddle2; break; case SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2: btn = modules::GamepadButton::Paddle3; break; case SDL_GAMEPAD_BUTTON_LEFT_PADDLE2: btn = modules::GamepadButton::Paddle4; break; case SDL_GAMEPAD_BUTTON_TOUCHPAD: btn = modules::GamepadButton::Touchpad; break; default: return; // Unknown button } const char *buttonName = modules::Joystick::getGamepadButtonName(btn); if (!buttonName || buttonName[0] == '\0') { return; } js::Value global = js_global_->get(*js_ctx_); js::Value args[2]; args[0] = modules::createJoystickJSObject(*js_ctx_, joystick); args[1] = js::Value::string(*js_ctx_, buttonName); js::Value result = js_ctx_->call(gamepadreleased_cb, global, args, 2); if (result.isException()) { fprintf(stderr, "Error in gamepadreleased callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } void Engine::handleGamepadAxis(SDL_JoystickID instanceId, int axis, float value) { if (!cb_gamepadaxis_ || cb_gamepadaxis_->isEmpty()) { return; } modules::Joystick *joystick = joystick_module_->getJoystickFromID(instanceId); if (!joystick) { return; } js::Value gamepadaxis_cb = cb_gamepadaxis_->get(*js_ctx_); if (!gamepadaxis_cb.isFunction()) { return; } // Convert SDL axis to Love2D axis name modules::GamepadAxis axisEnum = modules::GamepadAxis::Invalid; switch (static_cast<SDL_GamepadAxis>(axis)) { case SDL_GAMEPAD_AXIS_LEFTX: axisEnum = modules::GamepadAxis::LeftX; break; case SDL_GAMEPAD_AXIS_LEFTY: axisEnum = modules::GamepadAxis::LeftY; break; case SDL_GAMEPAD_AXIS_RIGHTX: axisEnum = modules::GamepadAxis::RightX; break; case SDL_GAMEPAD_AXIS_RIGHTY: axisEnum = modules::GamepadAxis::RightY; break; case SDL_GAMEPAD_AXIS_LEFT_TRIGGER: axisEnum = modules::GamepadAxis::TriggerLeft; break; case SDL_GAMEPAD_AXIS_RIGHT_TRIGGER: axisEnum = modules::GamepadAxis::TriggerRight; break; default: return; // Unknown axis } const char *axisName = modules::Joystick::getGamepadAxisName(axisEnum); if (!axisName || axisName[0] == '\0') { return; } js::Value global = js_global_->get(*js_ctx_); js::Value args[3]; args[0] = modules::createJoystickJSObject(*js_ctx_, joystick); args[1] = js::Value::string(*js_ctx_, axisName); args[2] = js::Value::number(value); js::Value result = js_ctx_->call(gamepadaxis_cb, global, args, 3); if (result.isException()) { fprintf(stderr, "Error in gamepadaxis callback:\n"); js::Value exception = js_ctx_->getException(); js_ctx_->printException(exception); } } int Engine::getWidth() const { if (!window_) return 0; int w, h; SDL_GetWindowSize(window_, &w, &h); return w; } int Engine::getHeight() const { if (!window_) return 0; int w, h; SDL_GetWindowSize(window_, &w, &h); return h; } } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/engine.hh
C++ Header
#pragma once #include "SDL3/SDL.h" #include <memory> // Forward declarations for js:: abstraction namespace js { class Runtime; class Context; class Value; class PersistentValue; } namespace joy { // Forward declarations namespace render { class Render; } namespace modules { class Info; class Window; class Keyboard; class Mouse; class Graphics; class Audio; class Filesystem; class Gui; class Timer; class Image; class System; class Math; class DataModule; class Sound; class JoystickModule; class Joystick; } namespace webapi { class WebSocket; class Worker; } class Engine { public: Engine(); ~Engine(); // Initialize engine bool init(); // Mount a game path (directory, .zip, or .joy file) bool mountGame(const char *path); // Load and run a script from mounted filesystem bool loadScript(const char *filename); // Run one frame void frame(); // Handle keyboard events void handleKeyPressed(SDL_Scancode scancode, bool repeat); void handleKeyReleased(SDL_Scancode scancode); void handleTextInput(const char *text); // Handle mouse events void handleMousePressed(float x, float y, int button, int clicks); void handleMouseReleased(float x, float y, int button, int clicks); void handleMouseMoved(float x, float y, float dx, float dy); void handleMouseWheel(float x, float y); void handleMouseFocus(bool focus); // Handle joystick events void handleJoystickAdded(SDL_JoystickID deviceId); void handleJoystickRemoved(SDL_JoystickID instanceId); void handleJoystickPressed(SDL_JoystickID instanceId, int button); void handleJoystickReleased(SDL_JoystickID instanceId, int button); void handleJoystickAxis(SDL_JoystickID instanceId, int axis, float value); void handleJoystickHat(SDL_JoystickID instanceId, int hat, int value); void handleGamepadPressed(SDL_JoystickID instanceId, int button); void handleGamepadReleased(SDL_JoystickID instanceId, int button); void handleGamepadAxis(SDL_JoystickID instanceId, int axis, float value); // Check if engine is running bool isRunning() const { return running_; } // Stop the engine void stop() { running_ = false; } // Get window dimensions int getWidth() const; int getHeight() const; // Get components SDL_Window *getWindow() const { return window_; } render::Render *getRender() const { return render_; } modules::Window *getWindowModule() const { return window_module_; } modules::Keyboard *getKeyboardModule() const { return keyboard_module_; } modules::Mouse *getMouseModule() const { return mouse_module_; } modules::Graphics *getGraphicsModule() const { return graphics_module_; } modules::Audio *getAudioModule() const { return audio_module_; } modules::Filesystem *getFilesystemModule() const { return filesystem_module_; } modules::Gui *getGuiModule() const { return gui_module_; } modules::Info *getInfoModule() const { return info_module_; } modules::Timer *getTimerModule() const { return timer_module_; } modules::Image *getImageModule() const { return image_module_; } modules::System *getSystemModule() const { return system_module_; } modules::Math *getMathModule() const { return math_module_; } modules::DataModule *getDataModule() const { return data_module_; } modules::Sound *getSoundModule() const { return sound_module_; } modules::JoystickModule *getJoystickModule() const { return joystick_module_; } webapi::WebSocket *getWebSocketModule() const { return websocket_module_; } webapi::Worker *getWorkerModule() const { return worker_module_; } // Get JS context (for modules that need direct access) js::Context *getJSContext() const { return js_ctx_.get(); } private: // PhysFS helper - read file from virtual filesystem char *readFile(const char *filename, size_t *size); // SDL window SDL_Window *window_; int window_width_; int window_height_; // Render backend render::Render *render_; // Modules modules::Window *window_module_; modules::Keyboard *keyboard_module_; modules::Mouse *mouse_module_; modules::Graphics *graphics_module_; modules::Audio *audio_module_; modules::Filesystem *filesystem_module_; modules::Gui *gui_module_; modules::Info *info_module_; modules::Timer *timer_module_; modules::Image *image_module_; modules::System *system_module_; modules::Math *math_module_; modules::DataModule *data_module_; modules::Sound *sound_module_; modules::JoystickModule *joystick_module_; // Web API modules webapi::WebSocket *websocket_module_; webapi::Worker *worker_module_; // JavaScript runtime (using js:: abstraction) std::unique_ptr<js::Runtime> js_rt_; std::unique_ptr<js::Context> js_ctx_; std::unique_ptr<js::PersistentValue> js_global_; std::unique_ptr<js::PersistentValue> js_joy_; // Callbacks (stored as PersistentValue to survive GC) std::unique_ptr<js::PersistentValue> cb_load_; std::unique_ptr<js::PersistentValue> cb_update_; std::unique_ptr<js::PersistentValue> cb_draw_; std::unique_ptr<js::PersistentValue> cb_keypressed_; std::unique_ptr<js::PersistentValue> cb_keyreleased_; std::unique_ptr<js::PersistentValue> cb_textinput_; std::unique_ptr<js::PersistentValue> cb_mousepressed_; std::unique_ptr<js::PersistentValue> cb_mousereleased_; std::unique_ptr<js::PersistentValue> cb_mousemoved_; std::unique_ptr<js::PersistentValue> cb_wheelmoved_; std::unique_ptr<js::PersistentValue> cb_mousefocus_; std::unique_ptr<js::PersistentValue> cb_joystickadded_; std::unique_ptr<js::PersistentValue> cb_joystickremoved_; std::unique_ptr<js::PersistentValue> cb_joystickpressed_; std::unique_ptr<js::PersistentValue> cb_joystickreleased_; std::unique_ptr<js::PersistentValue> cb_joystickaxis_; std::unique_ptr<js::PersistentValue> cb_joystickhat_; std::unique_ptr<js::PersistentValue> cb_gamepadpressed_; std::unique_ptr<js::PersistentValue> cb_gamepadreleased_; std::unique_ptr<js::PersistentValue> cb_gamepadaxis_; // State bool running_; // Initialize JavaScript runtime bool initScript(); // Get callback from joy object js::Value getCallback(const char *name); }; } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/impl/miniaudio_impl.c
C
// Disable unused audio backends to reduce binary size #define MA_NO_ENCODING #define MA_NO_GENERATION #ifdef __APPLE__ #define MA_NO_WASAPI #define MA_NO_DSOUND #define MA_NO_WINMM #define MA_NO_ALSA #define MA_NO_PULSEAUDIO #define MA_NO_JACK #define MA_NO_SNDIO #define MA_NO_AUDIO4 #define MA_NO_OSS #define MA_NO_AAUDIO #define MA_NO_OPENSL #elif defined(__EMSCRIPTEN__) #define MA_NO_WASAPI #define MA_NO_DSOUND #define MA_NO_WINMM #define MA_NO_COREAUDIO #define MA_NO_ALSA #define MA_NO_PULSEAUDIO #define MA_NO_JACK #define MA_NO_SNDIO #define MA_NO_AUDIO4 #define MA_NO_OSS #define MA_NO_AAUDIO #define MA_NO_OPENSL #elif defined(_WIN32) #define MA_NO_COREAUDIO #define MA_NO_ALSA #define MA_NO_PULSEAUDIO #define MA_NO_JACK #define MA_NO_SNDIO #define MA_NO_AUDIO4 #define MA_NO_OSS #define MA_NO_AAUDIO #define MA_NO_OPENSL #define MA_NO_WEBAUDIO #else // Linux - keep ALSA and PulseAudio #define MA_NO_WASAPI #define MA_NO_DSOUND #define MA_NO_WINMM #define MA_NO_COREAUDIO #define MA_NO_SNDIO #define MA_NO_AUDIO4 #define MA_NO_OSS #define MA_NO_AAUDIO #define MA_NO_OPENSL #define MA_NO_WEBAUDIO #endif #define MINIAUDIO_IMPLEMENTATION #include "miniaudio.h"
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/impl/nuklear_impl.c
C
// Nuklear implementation - separate file to avoid STB conflicts with fontstash #define NK_IMPLEMENTATION #include "nuklear_config.h"
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/impl/sokol_impl.c
C
// Sokol implementation - compiled as C (non-Apple platforms) #include "SDL3/SDL.h" #define SOKOL_IMPL #ifdef __EMSCRIPTEN__ #define SOKOL_GLES3 #else #define SOKOL_GLCORE #endif #include "sokol_gfx.h" #include "sokol_log.h" // Note: FontStash implementation is in text_renderer.cc // Text rendering uses our own TextRenderer with BatchRenderer
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/impl/sokol_impl.m
Objective-C
// Sokol implementation - compiled as Objective-C++ on macOS #include "SDL3/SDL.h" #include "SDL3/SDL_metal.h" #define SOKOL_IMPL #define SOKOL_METAL #include "sokol_gfx.h" #include "sokol_log.h" // Note: FontStash implementation is in text_renderer.cc // Text rendering uses our own TextRenderer with BatchRenderer
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/impl/stb_image_impl.c
C
#define STB_IMAGE_IMPLEMENTATION #include "stb_image.h"
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/impl/stb_image_write_impl.c
C
#define STB_IMAGE_WRITE_IMPLEMENTATION #include "stb_image_write.h"
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/impl/stb_vorbis_impl.c
C
// stb_vorbis implementation #include "stb_vorbis.c"
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/js/js.hh
C++ Header
#pragma once // Main header for the JavaScript engine abstraction layer. // Include this to get access to all js:: types. #include "js_types.hh" #include "js_value.hh" #include "js_context.hh" #include "js_runtime.hh" #include "js_function.hh" #include "js_module_builder.hh" #include "js_class.hh" #include "js_persistent.hh" #include "js_constructor.hh"
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/js/js_class.hh
C++ Header
#pragma once #include "js_types.hh" #include "js_value.hh" #include <cstdint> #include <memory> namespace js { // Opaque class ID type using ClassID = uint32_t; // Finalizer callback - called when object is garbage collected using Finalizer = void (*)(void *opaque); // Class definition for registering custom JS classes struct ClassDef { const char *name; Finalizer finalizer; }; // Class builder for registering classes and creating instances class ClassBuilder { public: // Register a new class on a runtime static ClassID registerClass(Context &ctx, const ClassDef &def); // Create an instance of a registered class static Value newInstance(Context &ctx, ClassID classId); // Set opaque C++ pointer on a class instance static void setOpaque(Value &obj, void *opaque); // Get opaque C++ pointer from a class instance static void *getOpaque(const Value &obj, ClassID classId); // Set prototype methods on a class static void setPrototype(Context &ctx, ClassID classId, Value &proto); }; } // namespace js
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/js/js_constructor.hh
C++ Header
#pragma once #include "js_types.hh" #include "js_value.hh" #include "js_class.hh" #include <memory> namespace js { // Forward declaration class ConstructorArgs; // Constructor callback signature using ConstructorCallback = void(*)(ConstructorArgs &args); // Accessor callback signatures (use FunctionArgs for consistency) using AccessorGetter = NativeFunction; using AccessorSetter = NativeFunction; // args.arg(0) is the value being set // Arguments passed to constructor callback class ConstructorArgs { public: int length() const; Value arg(int index) const; Context& context(); // Get engine pointer stored in context template<typename T> T* getContextOpaque() const { return static_cast<T*>(getContextOpaqueRaw()); } // Create the instance object (call this once, then set internal fields) Value createInstance(); // Set the return value (the constructed instance) void returnValue(Value instance); // Throw errors void throwError(const char *msg); void throwTypeError(const char *msg); void throwSyntaxError(const char *msg); void throwRangeError(const char *msg); // Implementation (for backend use only) struct Impl; // Construct from implementation (for backend use only) explicit ConstructorArgs(Impl *impl) : impl_(impl) {} private: void* getContextOpaqueRaw() const; friend class ConstructorBuilder; Impl* impl_; }; class ConstructorBuilder { public: ConstructorBuilder(Context &ctx, const char *name); ~ConstructorBuilder(); ConstructorBuilder(ConstructorBuilder&&) noexcept; ConstructorBuilder& operator=(ConstructorBuilder&&) noexcept; // Set the constructor callback ConstructorBuilder& constructor(ConstructorCallback cb, int argc = 0); // Set finalizer for instances ConstructorBuilder& finalizer(Finalizer fn); // Number of internal fields for storing C++ pointers (default 1) ConstructorBuilder& internalFieldCount(int count); // Add method to prototype ConstructorBuilder& prototypeMethod(const char *name, NativeFunction fn, int argc = 0); // Add getter to prototype ConstructorBuilder& prototypeGetter(const char *name, AccessorGetter getter); // Add getter+setter to prototype ConstructorBuilder& prototypeAccessor(const char *name, AccessorGetter getter, AccessorSetter setter = nullptr); // Add static constant to constructor function ConstructorBuilder& staticConstant(const char *name, int value); ConstructorBuilder& staticConstant(const char *name, const char *value); // Build and attach constructor to target object void attachTo(Value &target); private: struct Impl; std::unique_ptr<Impl> impl_; }; } // namespace js
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/js/js_context.hh
C++ Header
#pragma once #include "js_types.hh" #include <cstddef> #include <memory> namespace js { class Context { public: explicit Context(Runtime &runtime); ~Context(); // Non-copyable Context(const Context &) = delete; Context &operator=(const Context &) = delete; // Movable Context(Context &&other) noexcept; Context &operator=(Context &&other) noexcept; // Code evaluation Value eval(const char *code, size_t len, const char *filename); // ES Module support void setModuleLoader(ModuleLoaderCallback loader); Value evalModule(const char *code, size_t len, const char *filename); // Function calls Value call(const Value &func, const Value &thisVal, const Value *argv, int argc); // Global object Value globalObject(); // Error handling Value throwError(const char *msg); Value getException(); // Print exception with stack trace to stderr void printException(const Value &exception); // Store/retrieve opaque pointer (for Engine access from callbacks) void setOpaque(void *ptr); void *getOpaque() const; // Get associated runtime Runtime &runtime(); // Implementation access (for backend use only) struct Impl; Impl *impl() const { return impl_.get(); } // Create a non-owning wrapper around raw backend context // (for interop with unconverted code) static Context wrapRaw(void *raw_runtime, void *raw_context); // Get raw backend context (for interop with unconverted code) void *raw() const; private: // Private constructor for non-owning wrapper Context(Impl *impl, Runtime *runtime); std::unique_ptr<Impl> impl_; Runtime *runtime_; bool owns_impl_; }; } // namespace js
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/js/js_function.hh
C++ Header
#pragma once #include "js_types.hh" #include "js_value.hh" namespace js { class FunctionArgs { public: // Argument access int length() const; Value arg(int index) const; // Get 'this' value Value thisValue() const; // Get context Context &context(); // Set return value void returnValue(Value val); void returnUndefined(); // Throw errors and return exception void throwError(const char *msg); void throwTypeError(const char *msg); void throwSyntaxError(const char *msg); void throwRangeError(const char *msg); // Get opaque pointer from context (convenience for getting Engine*) template <typename T> T *getContextOpaque() { return static_cast<T *>(context().getOpaque()); } // Implementation (for backend use only) struct Impl; // Construct from implementation (for backend use only) explicit FunctionArgs(Impl *impl) : impl_(impl) {} private: Impl *impl_; }; // NativeFunction is already defined in js_types.hh as: // using NativeFunction = void (*)(FunctionArgs &); } // namespace js
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/js/js_module_builder.hh
C++ Header
#pragma once #include "js_types.hh" #include "js_value.hh" #include <memory> namespace js { class ModuleBuilder { public: ModuleBuilder(Context &ctx, const char *name); ~ModuleBuilder(); // Non-copyable ModuleBuilder(const ModuleBuilder &) = delete; ModuleBuilder &operator=(const ModuleBuilder &) = delete; // Movable ModuleBuilder(ModuleBuilder &&other) noexcept; ModuleBuilder &operator=(ModuleBuilder &&other) noexcept; // Add function to module ModuleBuilder &function(const char *name, NativeFunction fn, int argc = 0); // Add constants ModuleBuilder &constant(const char *name, const char *value); ModuleBuilder &constant(const char *name, int value); ModuleBuilder &constant(const char *name, double value); // Build and return the module object Value build(); // Attach to parent object (e.g., joy namespace) void attachTo(Value &parent); // Implementation access (for backend use only) struct Impl; private: std::unique_ptr<Impl> impl_; }; } // namespace js
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/js/js_persistent.hh
C++ Header
#pragma once #include "js_types.hh" #include "js_value.hh" #include <memory> namespace js { // Persistent handle that prevents a value from being garbage collected. // Use for storing callbacks, self-references, etc. class PersistentValue { public: PersistentValue(); PersistentValue(Context &ctx, const Value &val); ~PersistentValue(); // Move only (prevents accidental copies) PersistentValue(PersistentValue &&other) noexcept; PersistentValue& operator=(PersistentValue &&other) noexcept; PersistentValue(const PersistentValue&) = delete; PersistentValue& operator=(const PersistentValue&) = delete; // Get the stored value Value get(Context &ctx) const; // Check if empty bool isEmpty() const; // Reset to empty void reset(); // Reset to new value void reset(Context &ctx, const Value &val); private: struct Impl; std::unique_ptr<Impl> impl_; }; } // namespace js
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/js/js_runtime.hh
C++ Header
#pragma once #include "js_types.hh" #include <memory> namespace js { class Runtime { public: Runtime(); ~Runtime(); // Non-copyable, non-movable Runtime(const Runtime &) = delete; Runtime &operator=(const Runtime &) = delete; Runtime(Runtime &&) = delete; Runtime &operator=(Runtime &&) = delete; // Implementation access (for backend use only) struct Impl; Impl *impl() const { return impl_.get(); } private: std::unique_ptr<Impl> impl_; }; } // namespace js
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/js/js_types.hh
C++ Header
#pragma once #include <functional> #include <memory> #include <string> namespace js { class Value; class Context; class Runtime; class FunctionArgs; class ModuleBuilder; using NativeFunction = void (*)(FunctionArgs &); // Callback for loading ES module source code // Parameters: // referrer_path: path of the importing module (empty string for entry point) // specifier: the import specifier (e.g., "./utils.js") // resolved_path: output - the resolved absolute path // source_code: output - the file contents // Returns: true on success, false if module cannot be loaded using ModuleLoaderCallback = std::function<bool( const char *referrer_path, const char *specifier, std::string &resolved_path, std::string &source_code)>; } // namespace js
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/js/js_value.hh
C++ Header
#pragma once #include "js_types.hh" #include <cstdint> #include <memory> #include <string> #include <vector> namespace js { class Value { public: // Default constructor - creates undefined value Value(); // Copy semantics Value(const Value &other); Value &operator=(const Value &other); // Move semantics Value(Value &&other) noexcept; Value &operator=(Value &&other) noexcept; ~Value(); // Type checking bool isUndefined() const; bool isNull() const; bool isBoolean() const; bool isNumber() const; bool isString() const; bool isObject() const; bool isArray() const; bool isFunction() const; bool isException() const; // Value extraction bool toBool() const; int32_t toInt32() const; double toFloat64() const; std::string toString(Context &ctx) const; // Factory methods for primitives (no context needed) static Value undefined(); static Value null(); static Value boolean(bool val); static Value number(int32_t val); static Value number(double val); // Factory methods requiring context static Value string(Context &ctx, const char *str); static Value string(Context &ctx, const char *str, size_t len); static Value object(Context &ctx); static Value array(Context &ctx); // Property access Value getProperty(Context &ctx, const char *name) const; Value getProperty(Context &ctx, uint32_t index) const; void setProperty(Context &ctx, const char *name, Value val); void setProperty(Context &ctx, uint32_t index, Value val); // Internal fields (for constructor-created instances) void setInternalField(int index, void *ptr); void* getInternalField(int index) const; // ArrayBuffer support bool isArrayBuffer() const; bool isTypedArray() const; // Create ArrayBuffer with copy of data static Value arrayBuffer(Context &ctx, const void *data, size_t length); // Create empty ArrayBuffer static Value arrayBuffer(Context &ctx, size_t length); // Get ArrayBuffer data (returns nullptr if not an ArrayBuffer) void* arrayBufferData() const; size_t arrayBufferLength() const; // For TypedArray views Value typedArrayBuffer(Context &ctx) const; // Get underlying ArrayBuffer size_t typedArrayByteOffset() const; size_t typedArrayByteLength() const; // Serialization for cross-context/cross-thread transfer // Serializes the value to a binary format (for message passing) // Returns empty vector on failure std::vector<uint8_t> serialize(Context &ctx) const; // Deserialize from binary format // Returns undefined on failure (check with isException after call) static Value deserialize(Context &ctx, const uint8_t *data, size_t len); static Value deserialize(Context &ctx, const std::vector<uint8_t> &data); // Implementation access (for backend use only) struct Impl; Impl *impl() const { return impl_.get(); } // Construct from implementation (for backend use only) explicit Value(std::unique_ptr<Impl> impl); // Create from raw backend value (for interop with unconverted code) // Note: This dups the value, so the caller still owns the original static Value fromRaw(Context &ctx, void *raw_value); // Get raw backend value (for interop with unconverted code) // Note: The returned value is still owned by this Value void *raw() const; private: std::unique_ptr<Impl> impl_; }; } // namespace js
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/js/quickjs/js_impl.cc
C++
#include "js/js.hh" #include "quickjs.h" #include <cstring> #include <unordered_map> #include <vector> namespace js { // ============================================================================ // Per-runtime state (stored via JS_SetRuntimeOpaque) // ============================================================================ struct RuntimeData { JSClassID trampoline_class_id = 0; std::unordered_map<JSClassID, Finalizer> class_finalizers; std::unordered_map<JSClassID, ConstructorCallback> constructor_callbacks; }; static RuntimeData *getRuntimeData(JSRuntime *rt) { return static_cast<RuntimeData *>(JS_GetRuntimeOpaque(rt)); } static RuntimeData *getRuntimeData(JSContext *ctx) { return getRuntimeData(JS_GetRuntime(ctx)); } // ============================================================================ // Forward declarations of all Impl structs // ============================================================================ struct Value::Impl { JSValue val; JSContext *ctx; // Needed for ref counting; may be null for primitives Impl() : val(JS_UNDEFINED), ctx(nullptr) {} Impl(JSValue v, JSContext *c) : val(v), ctx(c) {} ~Impl() { if (ctx) { JS_FreeValue(ctx, val); } } Impl(const Impl &other) : val(other.val), ctx(other.ctx) { if (ctx) { val = JS_DupValue(ctx, other.val); } } Impl &operator=(const Impl &other) { if (this != &other) { if (ctx) { JS_FreeValue(ctx, val); } val = other.val; ctx = other.ctx; if (ctx) { val = JS_DupValue(ctx, other.val); } } return *this; } Impl(Impl &&other) noexcept : val(other.val), ctx(other.ctx) { other.val = JS_UNDEFINED; other.ctx = nullptr; } Impl &operator=(Impl &&other) noexcept { if (this != &other) { if (ctx) { JS_FreeValue(ctx, val); } val = other.val; ctx = other.ctx; other.val = JS_UNDEFINED; other.ctx = nullptr; } return *this; } }; struct Runtime::Impl { JSRuntime *rt; RuntimeData data; Impl() : rt(JS_NewRuntime()) { JS_SetRuntimeOpaque(rt, &data); } ~Impl() { if (rt) { JS_FreeRuntime(rt); } } }; struct Context::Impl { JSContext *ctx; bool owns; ModuleLoaderCallback module_loader; std::unordered_map<std::string, JSModuleDef *> module_cache; Impl(JSRuntime *rt) : ctx(JS_NewContext(rt)), owns(true) {} Impl(JSContext *c, bool own) : ctx(c), owns(own) {} ~Impl() { if (ctx && owns) { JS_FreeContext(ctx); } } }; struct FunctionArgs::Impl { JSContext *ctx; JSValueConst this_val; int argc; JSValueConst *argv; JSValue return_val; Context *wrapper_ctx; Impl(JSContext *c, JSValueConst tv, int ac, JSValueConst *av, Context *wc) : ctx(c), this_val(tv), argc(ac), argv(av), return_val(JS_UNDEFINED), wrapper_ctx(wc) {} }; struct FunctionEntry { const char *name; NativeFunction fn; int argc; }; struct ModuleBuilder::Impl { Context *ctx; const char *name; std::vector<FunctionEntry> functions; std::vector<std::pair<const char *, JSValue>> constants; Impl(Context *c, const char *n) : ctx(c), name(n) {} ~Impl() { // Free any constant values that weren't transferred for (auto &pair : constants) { JS_FreeValue(ctx->impl()->ctx, pair.second); } } }; // ============================================================================ // Value implementation // ============================================================================ Value::Value() : impl_(std::make_unique<Impl>()) {} Value::Value(const Value &other) : impl_(other.impl_ ? std::make_unique<Impl>(*other.impl_) : std::make_unique<Impl>()) {} Value &Value::operator=(const Value &other) { if (this != &other) { impl_ = other.impl_ ? std::make_unique<Impl>(*other.impl_) : std::make_unique<Impl>(); } return *this; } Value::Value(Value &&other) noexcept : impl_(std::move(other.impl_)) {} Value &Value::operator=(Value &&other) noexcept { impl_ = std::move(other.impl_); return *this; } Value::~Value() = default; Value::Value(std::unique_ptr<Impl> impl) : impl_(std::move(impl)) {} Value Value::fromRaw(Context &ctx, void *raw_value) { JSContext *qctx = ctx.impl()->ctx; JSValue val = *static_cast<JSValue *>(raw_value); // Dup the value since we're creating a new owner JSValue duped = JS_DupValue(qctx, val); auto impl = std::make_unique<Impl>(duped, qctx); return Value(std::move(impl)); } void *Value::raw() const { if (!impl_) return nullptr; return &impl_->val; } bool Value::isUndefined() const { return impl_ && JS_IsUndefined(impl_->val); } bool Value::isNull() const { return impl_ && JS_IsNull(impl_->val); } bool Value::isBoolean() const { return impl_ && JS_IsBool(impl_->val); } bool Value::isNumber() const { return impl_ && JS_IsNumber(impl_->val); } bool Value::isString() const { return impl_ && JS_IsString(impl_->val); } bool Value::isObject() const { return impl_ && JS_IsObject(impl_->val); } bool Value::isArray() const { return impl_ && JS_IsArray(impl_->val); } bool Value::isFunction() const { return impl_ && JS_IsFunction(impl_->ctx, impl_->val); } bool Value::isException() const { return impl_ && JS_IsException(impl_->val); } bool Value::toBool() const { if (!impl_) return false; return JS_ToBool(impl_->ctx, impl_->val); } int32_t Value::toInt32() const { if (!impl_) return 0; int32_t result = 0; JS_ToInt32(impl_->ctx, &result, impl_->val); return result; } double Value::toFloat64() const { if (!impl_) return 0.0; double result = 0.0; JS_ToFloat64(impl_->ctx, &result, impl_->val); return result; } std::string Value::toString(Context &ctx) const { if (!impl_) return ""; JSContext *qctx = ctx.impl()->ctx; const char *str = JS_ToCString(qctx, impl_->val); if (!str) return ""; std::string result(str); JS_FreeCString(qctx, str); return result; } Value Value::undefined() { auto impl = std::make_unique<Impl>(JS_UNDEFINED, nullptr); return Value(std::move(impl)); } Value Value::null() { auto impl = std::make_unique<Impl>(JS_NULL, nullptr); return Value(std::move(impl)); } Value Value::boolean(bool val) { auto impl = std::make_unique<Impl>(JS_NewBool(nullptr, val), nullptr); return Value(std::move(impl)); } Value Value::number(int32_t val) { auto impl = std::make_unique<Impl>(JS_NewInt32(nullptr, val), nullptr); return Value(std::move(impl)); } Value Value::number(double val) { auto impl = std::make_unique<Impl>(JS_NewFloat64(nullptr, val), nullptr); return Value(std::move(impl)); } Value Value::string(Context &ctx, const char *str) { JSContext *qctx = ctx.impl()->ctx; auto impl = std::make_unique<Impl>(JS_NewString(qctx, str), qctx); return Value(std::move(impl)); } Value Value::string(Context &ctx, const char *str, size_t len) { JSContext *qctx = ctx.impl()->ctx; auto impl = std::make_unique<Impl>(JS_NewStringLen(qctx, str, len), qctx); return Value(std::move(impl)); } Value Value::object(Context &ctx) { JSContext *qctx = ctx.impl()->ctx; auto impl = std::make_unique<Impl>(JS_NewObject(qctx), qctx); return Value(std::move(impl)); } Value Value::array(Context &ctx) { JSContext *qctx = ctx.impl()->ctx; auto impl = std::make_unique<Impl>(JS_NewArray(qctx), qctx); return Value(std::move(impl)); } Value Value::getProperty(Context &ctx, const char *name) const { if (!impl_) return Value::undefined(); JSContext *qctx = ctx.impl()->ctx; JSValue prop = JS_GetPropertyStr(qctx, impl_->val, name); auto impl = std::make_unique<Impl>(prop, qctx); return Value(std::move(impl)); } Value Value::getProperty(Context &ctx, uint32_t index) const { if (!impl_) return Value::undefined(); JSContext *qctx = ctx.impl()->ctx; JSValue prop = JS_GetPropertyUint32(qctx, impl_->val, index); auto impl = std::make_unique<Impl>(prop, qctx); return Value(std::move(impl)); } void Value::setProperty(Context &ctx, const char *name, Value val) { if (!impl_ || !val.impl_) return; JSContext *qctx = ctx.impl()->ctx; // Dup the value since setProperty takes ownership JSValue dup = JS_DupValue(qctx, val.impl_->val); JS_SetPropertyStr(qctx, impl_->val, name, dup); } void Value::setProperty(Context &ctx, uint32_t index, Value val) { if (!impl_ || !val.impl_) return; JSContext *qctx = ctx.impl()->ctx; // Dup the value since setProperty takes ownership JSValue dup = JS_DupValue(qctx, val.impl_->val); JS_SetPropertyUint32(qctx, impl_->val, index, dup); } // ============================================================================ // Runtime implementation // ============================================================================ Runtime::Runtime() : impl_(std::make_unique<Impl>()) {} Runtime::~Runtime() = default; // ============================================================================ // Module loading helpers // ============================================================================ // Resolve a module path relative to the referrer's directory static std::string resolveModulePath(const char *referrer, const char *specifier) { std::string spec(specifier); // Absolute path - use as-is if (!spec.empty() && spec[0] == '/') { return spec; } // Get referrer's directory std::string referrer_dir; if (referrer && referrer[0] != '\0') { std::string ref(referrer); size_t last_slash = ref.rfind('/'); if (last_slash != std::string::npos) { referrer_dir = ref.substr(0, last_slash + 1); } else { referrer_dir = "/"; } } else { referrer_dir = "/"; } // Combine and normalize path std::string result = referrer_dir + spec; // Simple path normalization (handle . and ..) std::vector<std::string> parts; size_t pos = 0; while (pos < result.size()) { size_t next = result.find('/', pos); if (next == std::string::npos) next = result.size(); std::string part = result.substr(pos, next - pos); if (part == "..") { if (!parts.empty() && parts.back() != "..") { parts.pop_back(); } } else if (part != "." && !part.empty()) { parts.push_back(part); } pos = next + 1; } std::string normalized = "/"; for (size_t i = 0; i < parts.size(); i++) { normalized += parts[i]; if (i < parts.size() - 1) normalized += "/"; } return normalized; } // QuickJS module normalize callback static char *qjs_module_normalize(JSContext *ctx, const char *base, const char *name, void *opaque) { (void)opaque; std::string resolved = resolveModulePath(base, name); char *result = static_cast<char *>(js_malloc(ctx, resolved.size() + 1)); if (result) { memcpy(result, resolved.c_str(), resolved.size() + 1); } return result; } // QuickJS module loader callback static JSModuleDef *qjs_module_loader(JSContext *ctx, const char *module_name, void *opaque) { Context::Impl *impl = static_cast<Context::Impl *>(opaque); // Check cache first auto it = impl->module_cache.find(module_name); if (it != impl->module_cache.end()) { return it->second; } // Use callback to load source if (!impl->module_loader) { JS_ThrowReferenceError(ctx, "No module loader configured"); return nullptr; } std::string resolved_path, source; if (!impl->module_loader("", module_name, resolved_path, source)) { JS_ThrowReferenceError(ctx, "Cannot find module '%s'", module_name); return nullptr; } // Compile as module JSValue func = JS_Eval(ctx, source.c_str(), source.size(), resolved_path.c_str(), JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_COMPILE_ONLY); if (JS_IsException(func)) { return nullptr; } // Extract JSModuleDef from the compiled function JSModuleDef *mod = static_cast<JSModuleDef *>(JS_VALUE_GET_PTR(func)); impl->module_cache[module_name] = mod; return mod; } // ============================================================================ // Context implementation // ============================================================================ Context::Context(Runtime &runtime) : impl_(std::make_unique<Impl>(runtime.impl()->rt)), runtime_(&runtime), owns_impl_(true) {} Context::Context(Impl *impl, Runtime *runtime) : impl_(impl), runtime_(runtime), owns_impl_(false) {} Context::~Context() { if (!owns_impl_) { // Release the unique_ptr without deleting impl_.release(); } } Context::Context(Context &&other) noexcept : impl_(std::move(other.impl_)), runtime_(other.runtime_), owns_impl_(other.owns_impl_) { other.runtime_ = nullptr; other.owns_impl_ = true; } Context &Context::operator=(Context &&other) noexcept { if (!owns_impl_) { impl_.release(); } impl_ = std::move(other.impl_); runtime_ = other.runtime_; owns_impl_ = other.owns_impl_; other.runtime_ = nullptr; other.owns_impl_ = true; return *this; } Context Context::wrapRaw(void *raw_runtime, void *raw_context) { (void)raw_runtime; // Not needed for QuickJS - context has runtime ref JSContext *ctx = static_cast<JSContext *>(raw_context); auto impl = new Impl(ctx, false); // non-owning return Context(impl, nullptr); } void *Context::raw() const { return impl_ ? impl_->ctx : nullptr; } Value Context::eval(const char *code, size_t len, const char *filename) { JSValue result = JS_Eval(impl_->ctx, code, len, filename, JS_EVAL_TYPE_GLOBAL); auto impl = std::make_unique<Value::Impl>(result, impl_->ctx); return Value(std::move(impl)); } Value Context::call(const Value &func, const Value &thisVal, const Value *argv, int argc) { std::vector<JSValue> jsArgv(argc); for (int i = 0; i < argc; i++) { jsArgv[i] = argv[i].impl()->val; } JSValue result = JS_Call(impl_->ctx, func.impl()->val, thisVal.impl()->val, argc, argc > 0 ? jsArgv.data() : nullptr); auto impl = std::make_unique<Value::Impl>(result, impl_->ctx); return Value(std::move(impl)); } Value Context::globalObject() { JSValue global = JS_GetGlobalObject(impl_->ctx); auto impl = std::make_unique<Value::Impl>(global, impl_->ctx); return Value(std::move(impl)); } Value Context::throwError(const char *msg) { JSValue err = JS_ThrowInternalError(impl_->ctx, "%s", msg); auto impl = std::make_unique<Value::Impl>(err, impl_->ctx); return Value(std::move(impl)); } Value Context::getException() { JSValue exc = JS_GetException(impl_->ctx); auto impl = std::make_unique<Value::Impl>(exc, impl_->ctx); return Value(std::move(impl)); } void Context::printException(const Value &exception) { if (!exception.impl()) return; JSValue exc_val = exception.impl()->val; // Always print the error message first const char *error_str = JS_ToCString(impl_->ctx, exc_val); if (error_str) { fprintf(stderr, "%s\n", error_str); JS_FreeCString(impl_->ctx, error_str); } // Then print the stack trace if available JSValue stack = JS_GetPropertyStr(impl_->ctx, exc_val, "stack"); const char *stack_str = JS_ToCString(impl_->ctx, stack); if (stack_str && stack_str[0] != '\0') { fprintf(stderr, "%s\n", stack_str); } if (stack_str) { JS_FreeCString(impl_->ctx, stack_str); } JS_FreeValue(impl_->ctx, stack); } void Context::setOpaque(void *ptr) { JS_SetContextOpaque(impl_->ctx, ptr); } void *Context::getOpaque() const { return JS_GetContextOpaque(impl_->ctx); } Runtime &Context::runtime() { return *runtime_; } void Context::setModuleLoader(ModuleLoaderCallback loader) { impl_->module_loader = std::move(loader); // Register our module loader with QuickJS JSRuntime *rt = JS_GetRuntime(impl_->ctx); JS_SetModuleLoaderFunc(rt, qjs_module_normalize, qjs_module_loader, impl_.get()); } Value Context::evalModule(const char *code, size_t len, const char *filename) { // Compile as module JSValue func = JS_Eval(impl_->ctx, code, len, filename, JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_COMPILE_ONLY); if (JS_IsException(func)) { auto impl = std::make_unique<Value::Impl>(func, impl_->ctx); return Value(std::move(impl)); } // Cache this module impl_->module_cache[filename] = static_cast<JSModuleDef *>(JS_VALUE_GET_PTR(func)); // Resolve dependencies (this triggers the loader for imports) if (JS_ResolveModule(impl_->ctx, func) < 0) { JS_FreeValue(impl_->ctx, func); JSValue exc = JS_GetException(impl_->ctx); auto impl = std::make_unique<Value::Impl>(exc, impl_->ctx); return Value(std::move(impl)); } // Evaluate module JSValue result = JS_EvalFunction(impl_->ctx, func); auto impl = std::make_unique<Value::Impl>(result, impl_->ctx); return Value(std::move(impl)); } // ============================================================================ // FunctionArgs implementation // ============================================================================ int FunctionArgs::length() const { return impl_->argc; } Value FunctionArgs::arg(int index) const { if (index < 0 || index >= impl_->argc) { return Value::undefined(); } // Dup because we're returning ownership JSValue dup = JS_DupValue(impl_->ctx, impl_->argv[index]); auto valImpl = std::make_unique<Value::Impl>(dup, impl_->ctx); return Value(std::move(valImpl)); } Value FunctionArgs::thisValue() const { JSValue dup = JS_DupValue(impl_->ctx, impl_->this_val); auto valImpl = std::make_unique<Value::Impl>(dup, impl_->ctx); return Value(std::move(valImpl)); } Context &FunctionArgs::context() { return *impl_->wrapper_ctx; } void FunctionArgs::returnValue(Value val) { if (val.impl()) { // Dup because we're taking ownership impl_->return_val = JS_DupValue(impl_->ctx, val.impl()->val); } else { impl_->return_val = JS_UNDEFINED; } } void FunctionArgs::returnUndefined() { impl_->return_val = JS_UNDEFINED; } void FunctionArgs::throwError(const char *msg) { impl_->return_val = JS_ThrowInternalError(impl_->ctx, "%s", msg); } // ============================================================================ // ModuleBuilder implementation // ============================================================================ // Trampoline function that QuickJS calls, which then calls our NativeFunction struct TrampolineData { NativeFunction fn; }; static JSValue trampoline(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data) { (void)magic; RuntimeData *rtData = getRuntimeData(ctx); if (!rtData) return JS_UNDEFINED; TrampolineData *data = static_cast<TrampolineData *>(JS_GetOpaque(*func_data, rtData->trampoline_class_id)); if (!data) return JS_UNDEFINED; // Create a temporary Context wrapper for this call Context wrapper = Context::wrapRaw(nullptr, ctx); FunctionArgs::Impl argsImpl(ctx, this_val, argc, argv, &wrapper); FunctionArgs args(&argsImpl); data->fn(args); return argsImpl.return_val; } static void trampoline_finalizer(JSRuntime *rt, JSValue val) { RuntimeData *rtData = getRuntimeData(rt); if (!rtData) return; TrampolineData *data = static_cast<TrampolineData *>(JS_GetOpaque(val, rtData->trampoline_class_id)); delete data; } static JSClassDef trampoline_class_def = { .class_name = "TrampolineData", .finalizer = trampoline_finalizer, }; static void ensureTrampolineClassRegistered(JSRuntime *rt) { RuntimeData *rtData = getRuntimeData(rt); if (!rtData) return; if (rtData->trampoline_class_id == 0) { JS_NewClassID(rt, &rtData->trampoline_class_id); JS_NewClass(rt, rtData->trampoline_class_id, &trampoline_class_def); } } ModuleBuilder::ModuleBuilder(Context &ctx, const char *name) : impl_(std::make_unique<Impl>(&ctx, name)) {} ModuleBuilder::~ModuleBuilder() = default; ModuleBuilder::ModuleBuilder(ModuleBuilder &&other) noexcept : impl_(std::move(other.impl_)) {} ModuleBuilder &ModuleBuilder::operator=(ModuleBuilder &&other) noexcept { impl_ = std::move(other.impl_); return *this; } ModuleBuilder &ModuleBuilder::function(const char *name, NativeFunction fn, int argc) { impl_->functions.push_back({name, fn, argc}); return *this; } ModuleBuilder &ModuleBuilder::constant(const char *name, const char *value) { JSContext *qctx = impl_->ctx->impl()->ctx; impl_->constants.push_back({name, JS_NewString(qctx, value)}); return *this; } ModuleBuilder &ModuleBuilder::constant(const char *name, int value) { impl_->constants.push_back({name, JS_NewInt32(nullptr, value)}); return *this; } ModuleBuilder &ModuleBuilder::constant(const char *name, double value) { impl_->constants.push_back({name, JS_NewFloat64(nullptr, value)}); return *this; } Value ModuleBuilder::build() { JSContext *qctx = impl_->ctx->impl()->ctx; JSRuntime *rt = JS_GetRuntime(qctx); ensureTrampolineClassRegistered(rt); RuntimeData *rtData = getRuntimeData(rt); if (!rtData) return Value::undefined(); JSValue module = JS_NewObject(qctx); // Add functions for (const auto &entry : impl_->functions) { // Create trampoline data object TrampolineData *data = new TrampolineData{entry.fn}; JSValue dataObj = JS_NewObjectClass(qctx, rtData->trampoline_class_id); JS_SetOpaque(dataObj, data); // Create function with data JSValue func = JS_NewCFunctionData(qctx, trampoline, entry.argc, 0, 1, &dataObj); JS_FreeValue(qctx, dataObj); // func holds a reference now JS_SetPropertyStr(qctx, module, entry.name, func); } // Add constants for (auto &pair : impl_->constants) { JS_SetPropertyStr(qctx, module, pair.first, pair.second); // Clear so destructor doesn't double-free pair.second = JS_UNDEFINED; } impl_->constants.clear(); auto valImpl = std::make_unique<Value::Impl>(module, qctx); return Value(std::move(valImpl)); } void ModuleBuilder::attachTo(Value &parent) { Value module = build(); parent.setProperty(*impl_->ctx, impl_->name, std::move(module)); } // ============================================================================ // ClassBuilder implementation // ============================================================================ // Generic finalizer that looks up the real finalizer by class ID static void generic_class_finalizer(JSRuntime *rt, JSValue val) { RuntimeData *rtData = getRuntimeData(rt); if (!rtData) return; JSClassID class_id = JS_GetClassID(val); auto it = rtData->class_finalizers.find(class_id); if (it != rtData->class_finalizers.end() && it->second) { void *opaque = JS_GetOpaque(val, class_id); if (opaque) { it->second(opaque); } } } ClassID ClassBuilder::registerClass(Context &ctx, const ClassDef &def) { JSContext *qctx = ctx.impl()->ctx; JSRuntime *rt = JS_GetRuntime(qctx); RuntimeData *rtData = getRuntimeData(rt); if (!rtData) return 0; JSClassID class_id = 0; JS_NewClassID(rt, &class_id); JSClassDef js_def = {}; js_def.class_name = def.name; if (def.finalizer) { rtData->class_finalizers[class_id] = def.finalizer; js_def.finalizer = generic_class_finalizer; } JS_NewClass(rt, class_id, &js_def); return static_cast<ClassID>(class_id); } Value ClassBuilder::newInstance(Context &ctx, ClassID classId) { JSContext *qctx = ctx.impl()->ctx; JSValue obj = JS_NewObjectClass(qctx, static_cast<JSClassID>(classId)); auto impl = std::make_unique<Value::Impl>(obj, qctx); return Value(std::move(impl)); } void ClassBuilder::setOpaque(Value &obj, void *opaque) { if (!obj.impl()) return; JS_SetOpaque(obj.impl()->val, opaque); } void *ClassBuilder::getOpaque(const Value &obj, ClassID classId) { if (!obj.impl()) return nullptr; return JS_GetOpaque(obj.impl()->val, static_cast<JSClassID>(classId)); } void ClassBuilder::setPrototype(Context &ctx, ClassID classId, Value &proto) { JSContext *qctx = ctx.impl()->ctx; if (!proto.impl()) return; // Dup the proto since SetClassProto takes ownership JSValue protoDup = JS_DupValue(qctx, proto.impl()->val); JS_SetClassProto(qctx, static_cast<JSClassID>(classId), protoDup); } // ============================================================================ // Additional FunctionArgs throw methods // ============================================================================ void FunctionArgs::throwTypeError(const char *msg) { impl_->return_val = JS_ThrowTypeError(impl_->ctx, "%s", msg); } void FunctionArgs::throwSyntaxError(const char *msg) { impl_->return_val = JS_ThrowSyntaxError(impl_->ctx, "%s", msg); } void FunctionArgs::throwRangeError(const char *msg) { impl_->return_val = JS_ThrowRangeError(impl_->ctx, "%s", msg); } // ============================================================================ // Value internal fields and ArrayBuffer implementation // ============================================================================ void Value::setInternalField(int index, void *ptr) { (void)index; // QuickJS only supports one opaque pointer if (impl_) { JS_SetOpaque(impl_->val, ptr); } } void *Value::getInternalField(int index) const { (void)index; // QuickJS only supports one opaque pointer if (!impl_) return nullptr; // Get class ID to retrieve opaque JSClassID class_id = JS_GetClassID(impl_->val); return JS_GetOpaque(impl_->val, class_id); } bool Value::isArrayBuffer() const { if (!impl_ || !impl_->ctx) return false; size_t size; uint8_t *buf = JS_GetArrayBuffer(impl_->ctx, &size, impl_->val); return buf != nullptr; } bool Value::isTypedArray() const { if (!impl_ || !impl_->ctx) return false; size_t offset, length, bytes_per_element; JSValue buffer = JS_GetTypedArrayBuffer(impl_->ctx, impl_->val, &offset, &length, &bytes_per_element); bool result = !JS_IsException(buffer); if (result) { JS_FreeValue(impl_->ctx, buffer); } return result; } Value Value::arrayBuffer(Context &ctx, const void *data, size_t length) { JSContext *qctx = ctx.impl()->ctx; JSValue buf = JS_NewArrayBufferCopy(qctx, static_cast<const uint8_t *>(data), length); auto impl = std::make_unique<Impl>(buf, qctx); return Value(std::move(impl)); } Value Value::arrayBuffer(Context &ctx, size_t length) { JSContext *qctx = ctx.impl()->ctx; // Create zeroed buffer uint8_t *data = static_cast<uint8_t *>(js_mallocz(qctx, length)); if (!data) { return Value::null(); } JSValue buf = JS_NewArrayBuffer(qctx, data, length, [](JSRuntime *rt, void *opaque, void *ptr) { js_free_rt(rt, ptr); }, nullptr, false); auto impl = std::make_unique<Impl>(buf, qctx); return Value(std::move(impl)); } void *Value::arrayBufferData() const { if (!impl_ || !impl_->ctx) return nullptr; size_t size; return JS_GetArrayBuffer(impl_->ctx, &size, impl_->val); } size_t Value::arrayBufferLength() const { if (!impl_ || !impl_->ctx) return 0; size_t size = 0; JS_GetArrayBuffer(impl_->ctx, &size, impl_->val); return size; } Value Value::typedArrayBuffer(Context &ctx) const { if (!impl_) return Value::null(); JSContext *qctx = ctx.impl()->ctx; size_t offset, length, bytes_per_element; JSValue buffer = JS_GetTypedArrayBuffer(qctx, impl_->val, &offset, &length, &bytes_per_element); if (JS_IsException(buffer)) { return Value::null(); } auto impl = std::make_unique<Impl>(buffer, qctx); return Value(std::move(impl)); } size_t Value::typedArrayByteOffset() const { if (!impl_ || !impl_->ctx) return 0; size_t offset = 0, length, bytes_per_element; JSValue buffer = JS_GetTypedArrayBuffer(impl_->ctx, impl_->val, &offset, &length, &bytes_per_element); if (!JS_IsException(buffer)) { JS_FreeValue(impl_->ctx, buffer); } return offset; } size_t Value::typedArrayByteLength() const { if (!impl_ || !impl_->ctx) return 0; size_t offset, byte_length = 0, bytes_per_element = 0; JSValue buffer = JS_GetTypedArrayBuffer(impl_->ctx, impl_->val, &offset, &byte_length, &bytes_per_element); if (!JS_IsException(buffer)) { JS_FreeValue(impl_->ctx, buffer); } // JS_GetTypedArrayBuffer returns byte_length directly, don't multiply return byte_length; } std::vector<uint8_t> Value::serialize(Context &ctx) const { if (!impl_) return {}; JSContext *qctx = ctx.impl()->ctx; size_t len = 0; // Use JS_WRITE_OBJ_REFERENCE to handle circular references and complex objects uint8_t *buf = JS_WriteObject(qctx, &len, impl_->val, JS_WRITE_OBJ_REFERENCE); if (!buf) { return {}; } std::vector<uint8_t> result(buf, buf + len); js_free(qctx, buf); return result; } Value Value::deserialize(Context &ctx, const uint8_t *data, size_t len) { if (!data || len == 0) return Value::undefined(); JSContext *qctx = ctx.impl()->ctx; // Use JS_READ_OBJ_REFERENCE to match serialization flags JSValue val = JS_ReadObject(qctx, data, len, JS_READ_OBJ_REFERENCE); auto impl = std::make_unique<Value::Impl>(val, qctx); return Value(std::move(impl)); } Value Value::deserialize(Context &ctx, const std::vector<uint8_t> &data) { return deserialize(ctx, data.data(), data.size()); } // ============================================================================ // PersistentValue implementation // ============================================================================ struct PersistentValue::Impl { JSContext *ctx; JSValue value; Impl() : ctx(nullptr), value(JS_UNDEFINED) {} Impl(JSContext *c, JSValue v) : ctx(c), value(JS_DupValue(c, v)) {} ~Impl() { if (ctx && !JS_IsUndefined(value)) { JS_FreeValue(ctx, value); } } Impl(const Impl&) = delete; Impl& operator=(const Impl&) = delete; }; PersistentValue::PersistentValue() : impl_(std::make_unique<Impl>()) {} PersistentValue::PersistentValue(Context &ctx, const Value &val) : impl_(std::make_unique<Impl>(ctx.impl()->ctx, val.impl()->val)) {} PersistentValue::~PersistentValue() = default; PersistentValue::PersistentValue(PersistentValue &&other) noexcept : impl_(std::move(other.impl_)) {} PersistentValue& PersistentValue::operator=(PersistentValue &&other) noexcept { impl_ = std::move(other.impl_); return *this; } Value PersistentValue::get(Context &ctx) const { if (!impl_ || !impl_->ctx || JS_IsUndefined(impl_->value)) { return Value::undefined(); } JSValue dup = JS_DupValue(impl_->ctx, impl_->value); auto valImpl = std::make_unique<Value::Impl>(dup, impl_->ctx); return Value(std::move(valImpl)); } bool PersistentValue::isEmpty() const { return !impl_ || !impl_->ctx || JS_IsUndefined(impl_->value); } void PersistentValue::reset() { if (impl_ && impl_->ctx && !JS_IsUndefined(impl_->value)) { JS_FreeValue(impl_->ctx, impl_->value); impl_->value = JS_UNDEFINED; impl_->ctx = nullptr; } } void PersistentValue::reset(Context &ctx, const Value &val) { reset(); impl_->ctx = ctx.impl()->ctx; impl_->value = JS_DupValue(impl_->ctx, val.impl()->val); } // ============================================================================ // ConstructorBuilder implementation // ============================================================================ struct ConstructorArgs::Impl { JSContext *ctx; JSValueConst new_target; int argc; JSValueConst *argv; JSValue return_val; Context *wrapper_ctx; JSClassID class_id; Impl(JSContext *c, JSValueConst nt, int ac, JSValueConst *av, Context *wc, JSClassID cid) : ctx(c), new_target(nt), argc(ac), argv(av), return_val(JS_UNDEFINED), wrapper_ctx(wc), class_id(cid) {} }; int ConstructorArgs::length() const { return impl_->argc; } Value ConstructorArgs::arg(int index) const { if (index < 0 || index >= impl_->argc) { return Value::undefined(); } JSValue dup = JS_DupValue(impl_->ctx, impl_->argv[index]); auto valImpl = std::make_unique<Value::Impl>(dup, impl_->ctx); return Value(std::move(valImpl)); } Context& ConstructorArgs::context() { return *impl_->wrapper_ctx; } void* ConstructorArgs::getContextOpaqueRaw() const { return JS_GetContextOpaque(impl_->ctx); } Value ConstructorArgs::createInstance() { JSValue obj = JS_NewObjectClass(impl_->ctx, impl_->class_id); auto valImpl = std::make_unique<Value::Impl>(obj, impl_->ctx); return Value(std::move(valImpl)); } void ConstructorArgs::returnValue(Value instance) { if (instance.impl()) { impl_->return_val = JS_DupValue(impl_->ctx, instance.impl()->val); } else { impl_->return_val = JS_UNDEFINED; } } void ConstructorArgs::throwError(const char *msg) { impl_->return_val = JS_ThrowInternalError(impl_->ctx, "%s", msg); } void ConstructorArgs::throwTypeError(const char *msg) { impl_->return_val = JS_ThrowTypeError(impl_->ctx, "%s", msg); } void ConstructorArgs::throwSyntaxError(const char *msg) { impl_->return_val = JS_ThrowSyntaxError(impl_->ctx, "%s", msg); } void ConstructorArgs::throwRangeError(const char *msg) { impl_->return_val = JS_ThrowRangeError(impl_->ctx, "%s", msg); } // ConstructorBuilder data struct ConstructorMethodEntry { const char *name; NativeFunction fn; int argc; }; struct ConstructorAccessorEntry { const char *name; AccessorGetter getter; AccessorSetter setter; }; struct ConstructorBuilder::Impl { Context *ctx; const char *name; ConstructorCallback ctor_cb; int ctor_argc; Finalizer finalizer_fn; int internal_field_count; std::vector<ConstructorMethodEntry> methods; std::vector<ConstructorAccessorEntry> accessors; std::vector<std::pair<const char *, int>> int_constants; std::vector<std::pair<const char *, const char *>> str_constants; Impl(Context *c, const char *n) : ctx(c), name(n), ctor_cb(nullptr), ctor_argc(0), finalizer_fn(nullptr), internal_field_count(1) {} }; // Constructor trampoline - uses magic value to store class_id static JSValue constructor_trampoline(JSContext *ctx, JSValueConst new_target, int argc, JSValueConst *argv, int magic) { (void)new_target; JSClassID class_id = static_cast<JSClassID>(magic); RuntimeData *rtData = getRuntimeData(ctx); if (!rtData) return JS_ThrowInternalError(ctx, "Runtime data not found"); auto it = rtData->constructor_callbacks.find(class_id); if (it == rtData->constructor_callbacks.end() || !it->second) { return JS_ThrowInternalError(ctx, "Constructor not found"); } Context wrapper = Context::wrapRaw(nullptr, ctx); ConstructorArgs::Impl argsImpl(ctx, new_target, argc, argv, &wrapper, class_id); ConstructorArgs args(&argsImpl); it->second(args); return argsImpl.return_val; } // Accessor getter trampoline (reuses standard trampoline signature) static JSValue accessor_getter_trampoline(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data) { (void)argc; (void)argv; (void)magic; RuntimeData *rtData = getRuntimeData(ctx); if (!rtData) return JS_UNDEFINED; TrampolineData *data = static_cast<TrampolineData *>(JS_GetOpaque(*func_data, rtData->trampoline_class_id)); if (!data) return JS_UNDEFINED; Context wrapper = Context::wrapRaw(nullptr, ctx); FunctionArgs::Impl argsImpl(ctx, this_val, 0, nullptr, &wrapper); FunctionArgs args(&argsImpl); data->fn(args); return argsImpl.return_val; } // Accessor setter trampoline (reuses standard trampoline signature) static JSValue accessor_setter_trampoline(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic, JSValue *func_data) { (void)magic; RuntimeData *rtData = getRuntimeData(ctx); if (!rtData) return JS_UNDEFINED; TrampolineData *data = static_cast<TrampolineData *>(JS_GetOpaque(*func_data, rtData->trampoline_class_id)); if (!data) return JS_UNDEFINED; Context wrapper = Context::wrapRaw(nullptr, ctx); FunctionArgs::Impl argsImpl(ctx, this_val, argc, argv, &wrapper); FunctionArgs args(&argsImpl); data->fn(args); return argsImpl.return_val; } ConstructorBuilder::ConstructorBuilder(Context &ctx, const char *name) : impl_(std::make_unique<Impl>(&ctx, name)) {} ConstructorBuilder::~ConstructorBuilder() = default; ConstructorBuilder::ConstructorBuilder(ConstructorBuilder &&other) noexcept : impl_(std::move(other.impl_)) {} ConstructorBuilder& ConstructorBuilder::operator=(ConstructorBuilder &&other) noexcept { impl_ = std::move(other.impl_); return *this; } ConstructorBuilder& ConstructorBuilder::constructor(ConstructorCallback cb, int argc) { impl_->ctor_cb = cb; impl_->ctor_argc = argc; return *this; } ConstructorBuilder& ConstructorBuilder::finalizer(Finalizer fn) { impl_->finalizer_fn = fn; return *this; } ConstructorBuilder& ConstructorBuilder::internalFieldCount(int count) { impl_->internal_field_count = count; return *this; } ConstructorBuilder& ConstructorBuilder::prototypeMethod(const char *name, NativeFunction fn, int argc) { impl_->methods.push_back({name, fn, argc}); return *this; } ConstructorBuilder& ConstructorBuilder::prototypeGetter(const char *name, AccessorGetter getter) { impl_->accessors.push_back({name, getter, nullptr}); return *this; } ConstructorBuilder& ConstructorBuilder::prototypeAccessor(const char *name, AccessorGetter getter, AccessorSetter setter) { impl_->accessors.push_back({name, getter, setter}); return *this; } ConstructorBuilder& ConstructorBuilder::staticConstant(const char *name, int value) { impl_->int_constants.push_back({name, value}); return *this; } ConstructorBuilder& ConstructorBuilder::staticConstant(const char *name, const char *value) { impl_->str_constants.push_back({name, value}); return *this; } void ConstructorBuilder::attachTo(Value &target) { JSContext *qctx = impl_->ctx->impl()->ctx; JSRuntime *rt = JS_GetRuntime(qctx); ensureTrampolineClassRegistered(rt); RuntimeData *rtData = getRuntimeData(rt); if (!rtData) return; // Register class JSClassID class_id = 0; JS_NewClassID(rt, &class_id); JSClassDef js_def = {}; js_def.class_name = impl_->name; if (impl_->finalizer_fn) { rtData->class_finalizers[class_id] = impl_->finalizer_fn; js_def.finalizer = generic_class_finalizer; } JS_NewClass(rt, class_id, &js_def); // Store constructor callback rtData->constructor_callbacks[class_id] = impl_->ctor_cb; // Create prototype JSValue proto = JS_NewObject(qctx); // Add prototype methods for (const auto &entry : impl_->methods) { TrampolineData *data = new TrampolineData{entry.fn}; JSValue dataObj = JS_NewObjectClass(qctx, rtData->trampoline_class_id); JS_SetOpaque(dataObj, data); JSValue func = JS_NewCFunctionData(qctx, trampoline, entry.argc, 0, 1, &dataObj); JS_FreeValue(qctx, dataObj); JS_SetPropertyStr(qctx, proto, entry.name, func); } // Add prototype accessors for (const auto &entry : impl_->accessors) { JSValue getter = JS_UNDEFINED; JSValue setter = JS_UNDEFINED; if (entry.getter) { TrampolineData *gdata = new TrampolineData{entry.getter}; JSValue gdataObj = JS_NewObjectClass(qctx, rtData->trampoline_class_id); JS_SetOpaque(gdataObj, gdata); getter = JS_NewCFunctionData(qctx, accessor_getter_trampoline, 0, 0, 1, &gdataObj); JS_FreeValue(qctx, gdataObj); } if (entry.setter) { TrampolineData *sdata = new TrampolineData{entry.setter}; JSValue sdataObj = JS_NewObjectClass(qctx, rtData->trampoline_class_id); JS_SetOpaque(sdataObj, sdata); setter = JS_NewCFunctionData(qctx, accessor_setter_trampoline, 1, 0, 1, &sdataObj); JS_FreeValue(qctx, sdataObj); } JSAtom prop = JS_NewAtom(qctx, entry.name); JS_DefinePropertyGetSet(qctx, proto, prop, getter, setter, JS_PROP_C_W_E); JS_FreeAtom(qctx, prop); } // Set class prototype JS_SetClassProto(qctx, class_id, JS_DupValue(qctx, proto)); // Create constructor function using JS_NewCFunction2 with constructor flag // The magic value stores the class_id JSValue ctor = JS_NewCFunction2(qctx, reinterpret_cast<JSCFunction *>(constructor_trampoline), impl_->name, impl_->ctor_argc, JS_CFUNC_constructor_magic, static_cast<int>(class_id)); // Link constructor and prototype JS_SetConstructor(qctx, ctor, proto); JS_FreeValue(qctx, proto); // Add static constants for (const auto &pair : impl_->int_constants) { JS_SetPropertyStr(qctx, ctor, pair.first, JS_NewInt32(qctx, pair.second)); } for (const auto &pair : impl_->str_constants) { JS_SetPropertyStr(qctx, ctor, pair.first, JS_NewString(qctx, pair.second)); } // Attach to target if (target.impl()) { JS_SetPropertyStr(qctx, target.impl()->val, impl_->name, ctor); } } } // namespace js
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/js/v8/js_impl.cc
C++
#include "js/js.hh" #include "libplatform/libplatform.h" #include "v8.h" #include <cstring> #include <unordered_map> #include <vector> #include <memory> #include <mutex> namespace js { // ============================================================================ // V8 Platform (singleton, initialized once - this is process-wide by design) // ============================================================================ static std::unique_ptr<v8::Platform> g_platform; static std::once_flag g_v8_init_flag; static void initializeV8() { g_platform = v8::platform::NewDefaultPlatform(); v8::V8::InitializePlatform(g_platform.get()); v8::V8::Initialize(); } static void ensureV8Initialized() { std::call_once(g_v8_init_flag, initializeV8); } // ============================================================================ // Per-runtime state (stored via isolate->SetData) // ============================================================================ // Use slot 0 for our runtime data constexpr uint32_t kRuntimeDataSlot = 0; struct RuntimeData { std::unordered_map<ClassID, Finalizer> class_finalizers; std::unordered_map<ClassID, v8::Global<v8::ObjectTemplate>> class_templates; std::unordered_map<ClassID, v8::Global<v8::Object>> class_prototypes; ClassID next_class_id = 1; // Must be called before isolate is disposed void cleanup() { for (auto &pair : class_templates) { pair.second.Reset(); } class_templates.clear(); for (auto &pair : class_prototypes) { pair.second.Reset(); } class_prototypes.clear(); class_finalizers.clear(); } }; static RuntimeData *getRuntimeData(v8::Isolate *isolate) { return static_cast<RuntimeData *>(isolate->GetData(kRuntimeDataSlot)); } // ============================================================================ // Forward declarations of all Impl structs // ============================================================================ // Primitive type for deferred V8 value creation enum class PrimitiveType { None, Undefined, Null, Boolean, Int32, Double }; struct Value::Impl { v8::Isolate *isolate; v8::Global<v8::Value> value; // For primitives created without context PrimitiveType prim_type; union { bool bool_val; int32_t int_val; double double_val; }; Impl() : isolate(nullptr), prim_type(PrimitiveType::Undefined) {} Impl(v8::Isolate *iso, v8::Local<v8::Value> val) : isolate(iso), value(iso, val), prim_type(PrimitiveType::None) {} // Primitive constructors static std::unique_ptr<Impl> makeUndefined() { auto impl = std::make_unique<Impl>(); impl->prim_type = PrimitiveType::Undefined; return impl; } static std::unique_ptr<Impl> makeNull() { auto impl = std::make_unique<Impl>(); impl->prim_type = PrimitiveType::Null; return impl; } static std::unique_ptr<Impl> makeBoolean(bool val) { auto impl = std::make_unique<Impl>(); impl->prim_type = PrimitiveType::Boolean; impl->bool_val = val; return impl; } static std::unique_ptr<Impl> makeInt32(int32_t val) { auto impl = std::make_unique<Impl>(); impl->prim_type = PrimitiveType::Int32; impl->int_val = val; return impl; } static std::unique_ptr<Impl> makeDouble(double val) { auto impl = std::make_unique<Impl>(); impl->prim_type = PrimitiveType::Double; impl->double_val = val; return impl; } ~Impl() { value.Reset(); } Impl(const Impl &other) : isolate(other.isolate), prim_type(other.prim_type) { if (isolate && !other.value.IsEmpty()) { v8::HandleScope handle_scope(isolate); value.Reset(isolate, other.value.Get(isolate)); } // Copy primitive value switch (prim_type) { case PrimitiveType::Boolean: bool_val = other.bool_val; break; case PrimitiveType::Int32: int_val = other.int_val; break; case PrimitiveType::Double: double_val = other.double_val; break; default: break; } } Impl &operator=(const Impl &other) { if (this != &other) { value.Reset(); isolate = other.isolate; prim_type = other.prim_type; if (isolate && !other.value.IsEmpty()) { v8::HandleScope handle_scope(isolate); value.Reset(isolate, other.value.Get(isolate)); } switch (prim_type) { case PrimitiveType::Boolean: bool_val = other.bool_val; break; case PrimitiveType::Int32: int_val = other.int_val; break; case PrimitiveType::Double: double_val = other.double_val; break; default: break; } } return *this; } Impl(Impl &&other) noexcept : isolate(other.isolate), value(std::move(other.value)), prim_type(other.prim_type) { switch (prim_type) { case PrimitiveType::Boolean: bool_val = other.bool_val; break; case PrimitiveType::Int32: int_val = other.int_val; break; case PrimitiveType::Double: double_val = other.double_val; break; default: break; } other.isolate = nullptr; other.prim_type = PrimitiveType::Undefined; } Impl &operator=(Impl &&other) noexcept { if (this != &other) { value.Reset(); isolate = other.isolate; value = std::move(other.value); prim_type = other.prim_type; switch (prim_type) { case PrimitiveType::Boolean: bool_val = other.bool_val; break; case PrimitiveType::Int32: int_val = other.int_val; break; case PrimitiveType::Double: double_val = other.double_val; break; default: break; } other.isolate = nullptr; other.prim_type = PrimitiveType::Undefined; } return *this; } v8::Local<v8::Value> Get() const { if (isolate && !value.IsEmpty()) { return value.Get(isolate); } return v8::Local<v8::Value>(); } // Get value, creating from primitive if needed v8::Local<v8::Value> GetWithIsolate(v8::Isolate *iso) const { if (!value.IsEmpty() && isolate) { return value.Get(isolate); } // Create from primitive switch (prim_type) { case PrimitiveType::Undefined: return v8::Undefined(iso); case PrimitiveType::Null: return v8::Null(iso); case PrimitiveType::Boolean: return v8::Boolean::New(iso, bool_val); case PrimitiveType::Int32: return v8::Integer::New(iso, int_val); case PrimitiveType::Double: return v8::Number::New(iso, double_val); default: return v8::Undefined(iso); } } bool isPrimitive() const { return prim_type != PrimitiveType::None && value.IsEmpty(); } }; struct Runtime::Impl { v8::Isolate *isolate; v8::ArrayBuffer::Allocator *allocator; RuntimeData data; Impl() { ensureV8Initialized(); v8::Isolate::CreateParams create_params; allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator(); create_params.array_buffer_allocator = allocator; isolate = v8::Isolate::New(create_params); isolate->SetData(kRuntimeDataSlot, &data); } ~Impl() { if (isolate) { // Clean up Global handles before disposing isolate data.cleanup(); isolate->Dispose(); } delete allocator; } }; struct Context::Impl { v8::Isolate *isolate; v8::Global<v8::Context> context; void *opaque; bool owns; ModuleLoaderCallback module_loader; std::unordered_map<std::string, v8::Global<v8::Module>> module_cache; Impl(v8::Isolate *iso) : isolate(iso), opaque(nullptr), owns(true) { v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> ctx = v8::Context::New(isolate); context.Reset(isolate, ctx); } Impl(v8::Isolate *iso, v8::Local<v8::Context> ctx, bool own) : isolate(iso), opaque(nullptr), owns(own) { context.Reset(isolate, ctx); } ~Impl() { // Clear module cache before context for (auto &pair : module_cache) { pair.second.Reset(); } module_cache.clear(); context.Reset(); } v8::Local<v8::Context> Get() const { return context.Get(isolate); } }; struct FunctionArgs::Impl { v8::Isolate *isolate; v8::Local<v8::Context> context; const v8::FunctionCallbackInfo<v8::Value> *info; Context *wrapper_ctx; v8::Local<v8::Value> return_val; bool has_return; bool has_exception; Impl(v8::Isolate *iso, v8::Local<v8::Context> ctx, const v8::FunctionCallbackInfo<v8::Value> *i, Context *wc) : isolate(iso), context(ctx), info(i), wrapper_ctx(wc), has_return(false), has_exception(false) {} }; struct FunctionEntry { const char *name; NativeFunction fn; int argc; }; struct ModuleBuilder::Impl { Context *ctx; const char *name; std::vector<FunctionEntry> functions; std::vector<std::pair<const char *, std::string>> string_constants; std::vector<std::pair<const char *, int>> int_constants; std::vector<std::pair<const char *, double>> double_constants; Impl(Context *c, const char *n) : ctx(c), name(n) {} }; // ============================================================================ // Value implementation // ============================================================================ Value::Value() : impl_(std::make_unique<Impl>()) {} Value::Value(const Value &other) : impl_(other.impl_ ? std::make_unique<Impl>(*other.impl_) : std::make_unique<Impl>()) {} Value &Value::operator=(const Value &other) { if (this != &other) { impl_ = other.impl_ ? std::make_unique<Impl>(*other.impl_) : std::make_unique<Impl>(); } return *this; } Value::Value(Value &&other) noexcept : impl_(std::move(other.impl_)) {} Value &Value::operator=(Value &&other) noexcept { impl_ = std::move(other.impl_); return *this; } Value::~Value() = default; Value::Value(std::unique_ptr<Impl> impl) : impl_(std::move(impl)) {} Value Value::fromRaw(Context &ctx, void *raw_value) { // In V8, we expect raw_value to be a v8::Local<v8::Value>* v8::Isolate *isolate = static_cast<v8::Isolate *>(ctx.raw()); v8::Local<v8::Value> *val = static_cast<v8::Local<v8::Value> *>(raw_value); auto impl = std::make_unique<Impl>(isolate, *val); return Value(std::move(impl)); } void *Value::raw() const { // Return pointer to internal Global for interop if (!impl_) return nullptr; return const_cast<v8::Global<v8::Value> *>(&impl_->value); } bool Value::isUndefined() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return true; v8::HandleScope handle_scope(impl_->isolate); return impl_->Get()->IsUndefined(); } bool Value::isNull() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return false; v8::HandleScope handle_scope(impl_->isolate); return impl_->Get()->IsNull(); } bool Value::isBoolean() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return false; v8::HandleScope handle_scope(impl_->isolate); return impl_->Get()->IsBoolean(); } bool Value::isNumber() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return false; v8::HandleScope handle_scope(impl_->isolate); return impl_->Get()->IsNumber(); } bool Value::isString() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return false; v8::HandleScope handle_scope(impl_->isolate); return impl_->Get()->IsString(); } bool Value::isObject() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return false; v8::HandleScope handle_scope(impl_->isolate); return impl_->Get()->IsObject(); } bool Value::isArray() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return false; v8::HandleScope handle_scope(impl_->isolate); return impl_->Get()->IsArray(); } bool Value::isFunction() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return false; v8::HandleScope handle_scope(impl_->isolate); return impl_->Get()->IsFunction(); } bool Value::isException() const { // V8 doesn't have a special exception value like QuickJS // Exceptions are handled via TryCatch return false; } bool Value::toBool() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return false; v8::HandleScope handle_scope(impl_->isolate); return impl_->Get()->BooleanValue(impl_->isolate); } int32_t Value::toInt32() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return 0; v8::HandleScope handle_scope(impl_->isolate); v8::Local<v8::Context> ctx = impl_->isolate->GetCurrentContext(); return impl_->Get()->Int32Value(ctx).FromMaybe(0); } double Value::toFloat64() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return 0.0; v8::HandleScope handle_scope(impl_->isolate); v8::Local<v8::Context> ctx = impl_->isolate->GetCurrentContext(); return impl_->Get()->NumberValue(ctx).FromMaybe(0.0); } std::string Value::toString(Context &ctx) const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return ""; v8::HandleScope handle_scope(impl_->isolate); v8::Local<v8::Context> v8ctx = impl_->isolate->GetCurrentContext(); v8::Local<v8::String> str; if (!impl_->Get()->ToString(v8ctx).ToLocal(&str)) { return ""; } v8::String::Utf8Value utf8(impl_->isolate, str); return *utf8 ? std::string(*utf8) : ""; } Value Value::undefined() { return Value(Impl::makeUndefined()); } Value Value::null() { return Value(Impl::makeNull()); } Value Value::boolean(bool val) { return Value(Impl::makeBoolean(val)); } Value Value::number(int32_t val) { return Value(Impl::makeInt32(val)); } Value Value::number(double val) { return Value(Impl::makeDouble(val)); } Value Value::string(Context &ctx, const char *str) { v8::Isolate *isolate = ctx.impl()->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> v8ctx = ctx.impl()->Get(); v8::Context::Scope context_scope(v8ctx); v8::Local<v8::String> v8str = v8::String::NewFromUtf8(isolate, str).ToLocalChecked(); auto impl = std::make_unique<Impl>(isolate, v8str); return Value(std::move(impl)); } Value Value::string(Context &ctx, const char *str, size_t len) { v8::Isolate *isolate = ctx.impl()->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> v8ctx = ctx.impl()->Get(); v8::Context::Scope context_scope(v8ctx); v8::Local<v8::String> v8str = v8::String::NewFromUtf8(isolate, str, v8::NewStringType::kNormal, static_cast<int>(len)) .ToLocalChecked(); auto impl = std::make_unique<Impl>(isolate, v8str); return Value(std::move(impl)); } Value Value::object(Context &ctx) { v8::Isolate *isolate = ctx.impl()->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> v8ctx = ctx.impl()->Get(); v8::Context::Scope context_scope(v8ctx); v8::Local<v8::Object> obj = v8::Object::New(isolate); auto impl = std::make_unique<Impl>(isolate, obj); return Value(std::move(impl)); } Value Value::array(Context &ctx) { v8::Isolate *isolate = ctx.impl()->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> v8ctx = ctx.impl()->Get(); v8::Context::Scope context_scope(v8ctx); v8::Local<v8::Array> arr = v8::Array::New(isolate); auto impl = std::make_unique<Impl>(isolate, arr); return Value(std::move(impl)); } Value Value::getProperty(Context &ctx, const char *name) const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return Value::undefined(); v8::Isolate *isolate = impl_->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> v8ctx = ctx.impl()->Get(); v8::Context::Scope context_scope(v8ctx); v8::Local<v8::Value> val = impl_->Get(); if (!val->IsObject()) return Value::undefined(); v8::Local<v8::Object> obj = val.As<v8::Object>(); v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, name).ToLocalChecked(); v8::Local<v8::Value> result; if (!obj->Get(v8ctx, key).ToLocal(&result)) { return Value::undefined(); } auto impl = std::make_unique<Impl>(isolate, result); return Value(std::move(impl)); } Value Value::getProperty(Context &ctx, uint32_t index) const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return Value::undefined(); v8::Isolate *isolate = impl_->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> v8ctx = ctx.impl()->Get(); v8::Context::Scope context_scope(v8ctx); v8::Local<v8::Value> val = impl_->Get(); if (!val->IsObject()) return Value::undefined(); v8::Local<v8::Object> obj = val.As<v8::Object>(); v8::Local<v8::Value> result; if (!obj->Get(v8ctx, index).ToLocal(&result)) { return Value::undefined(); } auto impl = std::make_unique<Impl>(isolate, result); return Value(std::move(impl)); } void Value::setProperty(Context &ctx, const char *name, Value val) { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return; if (!val.impl()) return; v8::Isolate *isolate = impl_->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> v8ctx = ctx.impl()->Get(); v8::Context::Scope context_scope(v8ctx); v8::Local<v8::Value> thisVal = impl_->Get(); if (!thisVal->IsObject()) return; v8::Local<v8::Object> obj = thisVal.As<v8::Object>(); v8::Local<v8::String> key = v8::String::NewFromUtf8(isolate, name).ToLocalChecked(); v8::Local<v8::Value> value = val.impl()->GetWithIsolate(isolate); obj->Set(v8ctx, key, value).Check(); } void Value::setProperty(Context &ctx, uint32_t index, Value val) { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return; if (!val.impl()) return; v8::Isolate *isolate = impl_->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> v8ctx = ctx.impl()->Get(); v8::Context::Scope context_scope(v8ctx); v8::Local<v8::Value> thisVal = impl_->Get(); if (!thisVal->IsObject()) return; v8::Local<v8::Object> obj = thisVal.As<v8::Object>(); v8::Local<v8::Value> value = val.impl()->GetWithIsolate(isolate); obj->Set(v8ctx, index, value).Check(); } // ============================================================================ // Internal fields and ArrayBuffer implementation // ============================================================================ void Value::setInternalField(int index, void *ptr) { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return; v8::HandleScope handle_scope(impl_->isolate); v8::Local<v8::Value> val = impl_->Get(); if (!val->IsObject()) return; v8::Local<v8::Object> obj = val.As<v8::Object>(); if (obj->InternalFieldCount() <= index) return; obj->SetAlignedPointerInInternalField(index, ptr); } void *Value::getInternalField(int index) const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return nullptr; v8::HandleScope handle_scope(impl_->isolate); v8::Local<v8::Value> val = impl_->Get(); if (!val->IsObject()) return nullptr; v8::Local<v8::Object> obj = val.As<v8::Object>(); if (obj->InternalFieldCount() <= index) return nullptr; return obj->GetAlignedPointerFromInternalField(index); } bool Value::isArrayBuffer() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return false; v8::HandleScope handle_scope(impl_->isolate); return impl_->Get()->IsArrayBuffer(); } bool Value::isTypedArray() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return false; v8::HandleScope handle_scope(impl_->isolate); return impl_->Get()->IsTypedArray(); } Value Value::arrayBuffer(Context &ctx, const void *data, size_t length) { v8::Isolate *isolate = static_cast<v8::Isolate *>(ctx.raw()); v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> v8ctx = ctx.impl()->Get(); v8::Context::Scope context_scope(v8ctx); // Create backing store with copy of data std::unique_ptr<v8::BackingStore> backing_store = v8::ArrayBuffer::NewBackingStore(isolate, length); memcpy(backing_store->Data(), data, length); v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, std::move(backing_store)); auto impl = std::make_unique<Impl>(isolate, ab); return Value(std::move(impl)); } Value Value::arrayBuffer(Context &ctx, size_t length) { v8::Isolate *isolate = static_cast<v8::Isolate *>(ctx.raw()); v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> v8ctx = ctx.impl()->Get(); v8::Context::Scope context_scope(v8ctx); std::unique_ptr<v8::BackingStore> backing_store = v8::ArrayBuffer::NewBackingStore( isolate, length, v8::BackingStoreInitializationMode::kZeroInitialized); v8::Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, std::move(backing_store)); auto impl = std::make_unique<Impl>(isolate, ab); return Value(std::move(impl)); } void *Value::arrayBufferData() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return nullptr; v8::HandleScope handle_scope(impl_->isolate); v8::Local<v8::Value> val = impl_->Get(); if (!val->IsArrayBuffer()) return nullptr; v8::Local<v8::ArrayBuffer> ab = val.As<v8::ArrayBuffer>(); return ab->GetBackingStore()->Data(); } size_t Value::arrayBufferLength() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return 0; v8::HandleScope handle_scope(impl_->isolate); v8::Local<v8::Value> val = impl_->Get(); if (!val->IsArrayBuffer()) return 0; v8::Local<v8::ArrayBuffer> ab = val.As<v8::ArrayBuffer>(); return ab->ByteLength(); } Value Value::typedArrayBuffer(Context &ctx) const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return Value::null(); v8::HandleScope handle_scope(impl_->isolate); v8::Local<v8::Value> val = impl_->Get(); if (!val->IsTypedArray()) return Value::null(); v8::Local<v8::TypedArray> ta = val.As<v8::TypedArray>(); v8::Local<v8::ArrayBuffer> ab = ta->Buffer(); auto impl = std::make_unique<Impl>(impl_->isolate, ab); return Value(std::move(impl)); } size_t Value::typedArrayByteOffset() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return 0; v8::HandleScope handle_scope(impl_->isolate); v8::Local<v8::Value> val = impl_->Get(); if (!val->IsTypedArray()) return 0; v8::Local<v8::TypedArray> ta = val.As<v8::TypedArray>(); return ta->ByteOffset(); } size_t Value::typedArrayByteLength() const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) return 0; v8::HandleScope handle_scope(impl_->isolate); v8::Local<v8::Value> val = impl_->Get(); if (!val->IsTypedArray()) return 0; v8::Local<v8::TypedArray> ta = val.As<v8::TypedArray>(); return ta->ByteLength(); } // ============================================================================ // Value serialization (for cross-context/cross-thread transfer) // ============================================================================ std::vector<uint8_t> Value::serialize(Context &ctx) const { if (!impl_) return {}; v8::Isolate *isolate = ctx.impl()->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> v8ctx = ctx.impl()->Get(); v8::Context::Scope context_scope(v8ctx); v8::Local<v8::Value> val = impl_->GetWithIsolate(isolate); v8::ValueSerializer serializer(isolate); serializer.WriteHeader(); v8::Maybe<bool> result = serializer.WriteValue(v8ctx, val); if (result.IsNothing() || !result.FromJust()) { return {}; } std::pair<uint8_t *, size_t> buffer = serializer.Release(); std::vector<uint8_t> data(buffer.first, buffer.first + buffer.second); free(buffer.first); return data; } Value Value::deserialize(Context &ctx, const uint8_t *data, size_t len) { if (!data || len == 0) { return Value::undefined(); } if (!ctx.impl()) { fprintf(stderr, "V8 deserialize: ctx.impl() is null\n"); return Value::undefined(); } v8::Isolate *isolate = ctx.impl()->isolate; if (!isolate) { fprintf(stderr, "V8 deserialize: isolate is null\n"); return Value::undefined(); } v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> v8ctx = ctx.impl()->Get(); if (v8ctx.IsEmpty()) { fprintf(stderr, "V8 deserialize: context is empty\n"); return Value::undefined(); } v8::Context::Scope context_scope(v8ctx); v8::ValueDeserializer deserializer(isolate, data, len); v8::Maybe<bool> header_result = deserializer.ReadHeader(v8ctx); if (header_result.IsNothing() || !header_result.FromJust()) { return Value::undefined(); } v8::MaybeLocal<v8::Value> maybe_val = deserializer.ReadValue(v8ctx); v8::Local<v8::Value> val; if (!maybe_val.ToLocal(&val)) { return Value::undefined(); } auto impl = std::make_unique<Impl>(isolate, val); return Value(std::move(impl)); } Value Value::deserialize(Context &ctx, const std::vector<uint8_t> &data) { return deserialize(ctx, data.data(), data.size()); } // ============================================================================ // Runtime implementation // ============================================================================ Runtime::Runtime() : impl_(std::make_unique<Impl>()) {} Runtime::~Runtime() = default; // ============================================================================ // Context implementation // ============================================================================ Context::Context(Runtime &runtime) : impl_(std::make_unique<Impl>(runtime.impl()->isolate)), runtime_(&runtime), owns_impl_(true) {} Context::Context(Impl *impl, Runtime *runtime) : impl_(impl), runtime_(runtime), owns_impl_(false) {} Context::~Context() { if (!owns_impl_) { impl_.release(); } } Context::Context(Context &&other) noexcept : impl_(std::move(other.impl_)), runtime_(other.runtime_), owns_impl_(other.owns_impl_) { other.runtime_ = nullptr; other.owns_impl_ = true; } Context &Context::operator=(Context &&other) noexcept { if (!owns_impl_) { impl_.release(); } impl_ = std::move(other.impl_); runtime_ = other.runtime_; owns_impl_ = other.owns_impl_; other.runtime_ = nullptr; other.owns_impl_ = true; return *this; } Context Context::wrapRaw(void *raw_runtime, void *raw_context) { (void)raw_runtime; // raw_context is expected to be v8::Isolate* for V8 v8::Isolate *isolate = static_cast<v8::Isolate *>(raw_context); v8::Local<v8::Context> ctx = isolate->GetCurrentContext(); auto impl = new Impl(isolate, ctx, false); return Context(impl, nullptr); } void *Context::raw() const { return impl_ ? impl_->isolate : nullptr; } Value Context::eval(const char *code, size_t len, const char *filename) { v8::Isolate *isolate = impl_->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> ctx = impl_->Get(); v8::Context::Scope context_scope(ctx); v8::TryCatch try_catch(isolate); v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, code, v8::NewStringType::kNormal, static_cast<int>(len)) .ToLocalChecked(); v8::ScriptOrigin origin( v8::String::NewFromUtf8(isolate, filename).ToLocalChecked()); v8::Local<v8::Script> script; if (!v8::Script::Compile(ctx, source, &origin).ToLocal(&script)) { // Compilation error - store exception if (try_catch.HasCaught()) { v8::Local<v8::Value> exception = try_catch.Exception(); auto impl = std::make_unique<Value::Impl>(isolate, exception); // Mark as exception somehow return Value(std::move(impl)); } return Value::undefined(); } v8::Local<v8::Value> result; if (!script->Run(ctx).ToLocal(&result)) { // Runtime error if (try_catch.HasCaught()) { v8::Local<v8::Value> exception = try_catch.Exception(); auto impl = std::make_unique<Value::Impl>(isolate, exception); return Value(std::move(impl)); } return Value::undefined(); } auto impl = std::make_unique<Value::Impl>(isolate, result); return Value(std::move(impl)); } Value Context::call(const Value &func, const Value &thisVal, const Value *argv, int argc) { if (!func.impl()) return Value::undefined(); v8::Isolate *isolate = impl_->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> ctx = impl_->Get(); v8::Context::Scope context_scope(ctx); v8::TryCatch try_catch(isolate); v8::Local<v8::Value> funcVal = func.impl()->GetWithIsolate(isolate); if (funcVal.IsEmpty() || !funcVal->IsFunction()) return Value::undefined(); v8::Local<v8::Function> function = funcVal.As<v8::Function>(); v8::Local<v8::Value> receiver; if (thisVal.impl()) { receiver = thisVal.impl()->GetWithIsolate(isolate); } if (receiver.IsEmpty()) { receiver = ctx->Global(); } std::vector<v8::Local<v8::Value>> args(argc); for (int i = 0; i < argc; i++) { if (argv[i].impl()) { args[i] = argv[i].impl()->GetWithIsolate(isolate); } else { args[i] = v8::Undefined(isolate); } } v8::Local<v8::Value> result; if (!function->Call(ctx, receiver, argc, argc > 0 ? args.data() : nullptr) .ToLocal(&result)) { if (try_catch.HasCaught()) { v8::Local<v8::Value> exception = try_catch.Exception(); auto impl = std::make_unique<Value::Impl>(isolate, exception); return Value(std::move(impl)); } return Value::undefined(); } auto impl = std::make_unique<Value::Impl>(isolate, result); return Value(std::move(impl)); } Value Context::globalObject() { v8::Isolate *isolate = impl_->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> ctx = impl_->Get(); v8::Context::Scope context_scope(ctx); v8::Local<v8::Object> global = ctx->Global(); auto impl = std::make_unique<Value::Impl>(isolate, global); return Value(std::move(impl)); } Value Context::throwError(const char *msg) { v8::Isolate *isolate = impl_->isolate; v8::HandleScope handle_scope(isolate); isolate->ThrowError( v8::String::NewFromUtf8(isolate, msg).ToLocalChecked()); return Value::undefined(); } Value Context::getException() { // V8 handles exceptions via TryCatch, not stored exceptions // Return undefined for now return Value::undefined(); } void Context::printException(const Value &exception) { if (!exception.impl() || exception.impl()->value.IsEmpty()) return; v8::Isolate *isolate = exception.impl()->isolate; v8::HandleScope handle_scope(isolate); v8::Local<v8::Value> exc = exception.impl()->Get(); // Print error message v8::String::Utf8Value error_str(isolate, exc); if (*error_str) { fprintf(stderr, "%s\n", *error_str); } // Try to get stack trace if (exc->IsObject()) { v8::Local<v8::Object> obj = exc.As<v8::Object>(); v8::Local<v8::Context> ctx = isolate->GetCurrentContext(); v8::Local<v8::Value> stack_val; if (obj->Get(ctx, v8::String::NewFromUtf8Literal(isolate, "stack")) .ToLocal(&stack_val) && stack_val->IsString()) { v8::String::Utf8Value stack_str(isolate, stack_val); if (*stack_str) { fprintf(stderr, "%s\n", *stack_str); } } } } void Context::setOpaque(void *ptr) { impl_->opaque = ptr; // Also store on global object so trampolines can access it v8::Isolate *isolate = impl_->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> ctx = impl_->Get(); v8::Context::Scope context_scope(ctx); v8::Local<v8::External> ext = v8::External::New(isolate, ptr); ctx->Global() ->Set(ctx, v8::String::NewFromUtf8Literal(isolate, "__joy_opaque__"), ext) .Check(); } void *Context::getOpaque() const { return impl_->opaque; } Runtime &Context::runtime() { return *runtime_; } // ============================================================================ // Module loading helpers // ============================================================================ // Use embedder data slot 1 for Context::Impl pointer (slot 0 might be used by V8 internals) constexpr int kContextImplSlot = 1; // Resolve a module path relative to the referrer's directory static std::string resolveModulePath(const std::string &referrer, const std::string &specifier) { // Absolute path - use as-is if (!specifier.empty() && specifier[0] == '/') { return specifier; } // Get referrer's directory std::string referrer_dir; if (!referrer.empty()) { size_t last_slash = referrer.rfind('/'); if (last_slash != std::string::npos) { referrer_dir = referrer.substr(0, last_slash + 1); } else { referrer_dir = "/"; } } else { referrer_dir = "/"; } // Combine and normalize path std::string result = referrer_dir + specifier; // Simple path normalization (handle . and ..) std::vector<std::string> parts; size_t pos = 0; while (pos < result.size()) { size_t next = result.find('/', pos); if (next == std::string::npos) next = result.size(); std::string part = result.substr(pos, next - pos); if (part == "..") { if (!parts.empty() && parts.back() != "..") { parts.pop_back(); } } else if (part != "." && !part.empty()) { parts.push_back(part); } pos = next + 1; } std::string normalized = "/"; for (size_t i = 0; i < parts.size(); i++) { normalized += parts[i]; if (i < parts.size() - 1) normalized += "/"; } return normalized; } // V8 module resolve callback static v8::MaybeLocal<v8::Module> v8ResolveModuleCallback( v8::Local<v8::Context> context, v8::Local<v8::String> specifier, v8::Local<v8::FixedArray> import_attributes, v8::Local<v8::Module> referrer) { (void)import_attributes; v8::Isolate *isolate = context->GetIsolate(); // Get Context::Impl from embedder data v8::Local<v8::Value> embedder_data = context->GetEmbedderData(kContextImplSlot); if (embedder_data.IsEmpty() || !embedder_data->IsExternal()) { isolate->ThrowException(v8::String::NewFromUtf8Literal( isolate, "Module loader not configured")); return v8::MaybeLocal<v8::Module>(); } Context::Impl *impl = static_cast<Context::Impl *>(embedder_data.As<v8::External>()->Value()); // Get specifier string v8::String::Utf8Value specifier_utf8(isolate, specifier); std::string spec(*specifier_utf8); // Get referrer path from our cache (reverse lookup) std::string referrer_path; for (const auto &pair : impl->module_cache) { if (!pair.second.IsEmpty() && pair.second.Get(isolate)->GetIdentityHash() == referrer->GetIdentityHash()) { referrer_path = pair.first; break; } } // Resolve the path std::string resolved_path = resolveModulePath(referrer_path, spec); // Check cache first auto it = impl->module_cache.find(resolved_path); if (it != impl->module_cache.end() && !it->second.IsEmpty()) { return it->second.Get(isolate); } // Use callback to load source if (!impl->module_loader) { isolate->ThrowException(v8::String::NewFromUtf8Literal( isolate, "No module loader configured")); return v8::MaybeLocal<v8::Module>(); } std::string resolved, source; if (!impl->module_loader(referrer_path.c_str(), spec.c_str(), resolved, source)) { std::string err = "Cannot find module '" + spec + "'"; isolate->ThrowException( v8::String::NewFromUtf8(isolate, err.c_str()).ToLocalChecked()); return v8::MaybeLocal<v8::Module>(); } // Compile as module v8::ScriptOrigin origin( v8::String::NewFromUtf8(isolate, resolved.c_str()).ToLocalChecked(), 0, // line offset 0, // column offset false, // is shared cross-origin -1, // script id v8::Local<v8::Value>(), // source map URL false, // is opaque false, // is WASM true); // is module v8::ScriptCompiler::Source src( v8::String::NewFromUtf8(isolate, source.c_str()).ToLocalChecked(), origin); v8::Local<v8::Module> module; if (!v8::ScriptCompiler::CompileModule(isolate, &src).ToLocal(&module)) { return v8::MaybeLocal<v8::Module>(); } // Cache before returning (handles circular deps) impl->module_cache[resolved].Reset(isolate, module); return module; } void Context::setModuleLoader(ModuleLoaderCallback loader) { impl_->module_loader = std::move(loader); // Store impl pointer in context embedder data for resolve callback v8::Isolate::Scope isolate_scope(impl_->isolate); v8::HandleScope handle_scope(impl_->isolate); v8::Local<v8::Context> ctx = impl_->Get(); v8::Context::Scope context_scope(ctx); v8::Local<v8::External> ext = v8::External::New(impl_->isolate, impl_.get()); ctx->SetEmbedderData(kContextImplSlot, ext); } Value Context::evalModule(const char *code, size_t len, const char *filename) { v8::Isolate *isolate = impl_->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> ctx = impl_->Get(); v8::Context::Scope context_scope(ctx); v8::TryCatch try_catch(isolate); // Create module source v8::ScriptOrigin origin( v8::String::NewFromUtf8(isolate, filename).ToLocalChecked(), 0, // line offset 0, // column offset false, // is shared cross-origin -1, // script id v8::Local<v8::Value>(), // source map URL false, // is opaque false, // is WASM true); // is module v8::ScriptCompiler::Source source( v8::String::NewFromUtf8(isolate, code, v8::NewStringType::kNormal, static_cast<int>(len)) .ToLocalChecked(), origin); // Compile module v8::Local<v8::Module> module; if (!v8::ScriptCompiler::CompileModule(isolate, &source).ToLocal(&module)) { if (try_catch.HasCaught()) { auto impl = std::make_unique<Value::Impl>(isolate, try_catch.Exception()); return Value(std::move(impl)); } return Value::undefined(); } // Cache this module impl_->module_cache[filename].Reset(isolate, module); // Instantiate module (resolves imports) if (!module->InstantiateModule(ctx, v8ResolveModuleCallback) .FromMaybe(false)) { if (try_catch.HasCaught()) { auto impl = std::make_unique<Value::Impl>(isolate, try_catch.Exception()); return Value(std::move(impl)); } return Value::undefined(); } // Evaluate module v8::Local<v8::Value> result; if (!module->Evaluate(ctx).ToLocal(&result)) { if (try_catch.HasCaught()) { auto impl = std::make_unique<Value::Impl>(isolate, try_catch.Exception()); return Value(std::move(impl)); } return Value::undefined(); } auto impl = std::make_unique<Value::Impl>(isolate, result); return Value(std::move(impl)); } // ============================================================================ // FunctionArgs implementation // ============================================================================ int FunctionArgs::length() const { return impl_->info->Length(); } Value FunctionArgs::arg(int index) const { if (index < 0 || index >= impl_->info->Length()) { return Value::undefined(); } v8::Local<v8::Value> val = (*impl_->info)[index]; auto valImpl = std::make_unique<Value::Impl>(impl_->isolate, val); return Value(std::move(valImpl)); } Value FunctionArgs::thisValue() const { v8::Local<v8::Value> val = impl_->info->This(); auto valImpl = std::make_unique<Value::Impl>(impl_->isolate, val); return Value(std::move(valImpl)); } Context &FunctionArgs::context() { return *impl_->wrapper_ctx; } void FunctionArgs::returnValue(Value val) { if (val.impl()) { v8::Local<v8::Value> v8val = val.impl()->GetWithIsolate(impl_->isolate); impl_->info->GetReturnValue().Set(v8val); } impl_->has_return = true; } void FunctionArgs::returnUndefined() { impl_->has_return = true; } void FunctionArgs::throwError(const char *msg) { impl_->isolate->ThrowError( v8::String::NewFromUtf8(impl_->isolate, msg).ToLocalChecked()); impl_->has_exception = true; } void FunctionArgs::throwTypeError(const char *msg) { impl_->isolate->ThrowException(v8::Exception::TypeError( v8::String::NewFromUtf8(impl_->isolate, msg).ToLocalChecked())); impl_->has_exception = true; } void FunctionArgs::throwSyntaxError(const char *msg) { impl_->isolate->ThrowException(v8::Exception::SyntaxError( v8::String::NewFromUtf8(impl_->isolate, msg).ToLocalChecked())); impl_->has_exception = true; } void FunctionArgs::throwRangeError(const char *msg) { impl_->isolate->ThrowException(v8::Exception::RangeError( v8::String::NewFromUtf8(impl_->isolate, msg).ToLocalChecked())); impl_->has_exception = true; } // ============================================================================ // ModuleBuilder implementation // ============================================================================ // Trampoline function that V8 calls static void v8_trampoline(const v8::FunctionCallbackInfo<v8::Value> &info) { v8::Isolate *isolate = info.GetIsolate(); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> ctx = isolate->GetCurrentContext(); // Get the native function from external data v8::Local<v8::External> ext = info.Data().As<v8::External>(); NativeFunction fn = reinterpret_cast<NativeFunction>(ext->Value()); // Create wrapper context Context wrapper = Context::wrapRaw(nullptr, isolate); // Get opaque from context void *opaque = nullptr; v8::Local<v8::Value> opaque_val; if (ctx->Global() ->Get(ctx, v8::String::NewFromUtf8Literal(isolate, "__joy_opaque__")) .ToLocal(&opaque_val) && opaque_val->IsExternal()) { opaque = opaque_val.As<v8::External>()->Value(); } wrapper.impl()->opaque = opaque; FunctionArgs::Impl argsImpl(isolate, ctx, &info, &wrapper); FunctionArgs args(&argsImpl); fn(args); } ModuleBuilder::ModuleBuilder(Context &ctx, const char *name) : impl_(std::make_unique<Impl>(&ctx, name)) {} ModuleBuilder::~ModuleBuilder() = default; ModuleBuilder::ModuleBuilder(ModuleBuilder &&other) noexcept : impl_(std::move(other.impl_)) {} ModuleBuilder &ModuleBuilder::operator=(ModuleBuilder &&other) noexcept { impl_ = std::move(other.impl_); return *this; } ModuleBuilder &ModuleBuilder::function(const char *name, NativeFunction fn, int argc) { impl_->functions.push_back({name, fn, argc}); return *this; } ModuleBuilder &ModuleBuilder::constant(const char *name, const char *value) { impl_->string_constants.push_back({name, std::string(value)}); return *this; } ModuleBuilder &ModuleBuilder::constant(const char *name, int value) { impl_->int_constants.push_back({name, value}); return *this; } ModuleBuilder &ModuleBuilder::constant(const char *name, double value) { impl_->double_constants.push_back({name, value}); return *this; } Value ModuleBuilder::build() { v8::Isolate *isolate = impl_->ctx->impl()->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> ctx = impl_->ctx->impl()->Get(); v8::Context::Scope context_scope(ctx); v8::Local<v8::Object> module = v8::Object::New(isolate); // Add functions for (const auto &entry : impl_->functions) { v8::Local<v8::External> data = v8::External::New(isolate, reinterpret_cast<void *>(entry.fn)); v8::Local<v8::Function> func = v8::Function::New(ctx, v8_trampoline, data, entry.argc) .ToLocalChecked(); v8::Local<v8::String> name = v8::String::NewFromUtf8(isolate, entry.name).ToLocalChecked(); module->Set(ctx, name, func).Check(); } // Add string constants for (const auto &pair : impl_->string_constants) { v8::Local<v8::String> name = v8::String::NewFromUtf8(isolate, pair.first).ToLocalChecked(); v8::Local<v8::String> value = v8::String::NewFromUtf8(isolate, pair.second.c_str()) .ToLocalChecked(); module->Set(ctx, name, value).Check(); } // Add int constants for (const auto &pair : impl_->int_constants) { v8::Local<v8::String> name = v8::String::NewFromUtf8(isolate, pair.first).ToLocalChecked(); v8::Local<v8::Integer> value = v8::Integer::New(isolate, pair.second); module->Set(ctx, name, value).Check(); } // Add double constants for (const auto &pair : impl_->double_constants) { v8::Local<v8::String> name = v8::String::NewFromUtf8(isolate, pair.first).ToLocalChecked(); v8::Local<v8::Number> value = v8::Number::New(isolate, pair.second); module->Set(ctx, name, value).Check(); } auto valImpl = std::make_unique<Value::Impl>(isolate, module); return Value(std::move(valImpl)); } void ModuleBuilder::attachTo(Value &parent) { Value module = build(); parent.setProperty(*impl_->ctx, impl_->name, std::move(module)); } // ============================================================================ // ClassBuilder implementation // ============================================================================ ClassID ClassBuilder::registerClass(Context &ctx, const ClassDef &def) { v8::Isolate *isolate = static_cast<v8::Isolate *>(ctx.raw()); RuntimeData *rtData = getRuntimeData(isolate); if (!rtData) return 0; ClassID id = rtData->next_class_id++; if (def.finalizer) { rtData->class_finalizers[id] = def.finalizer; } // Create an ObjectTemplate with internal fields for this class v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> v8ctx = ctx.impl()->Get(); v8::Context::Scope context_scope(v8ctx); v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); templ->SetInternalFieldCount(1); // For opaque pointer rtData->class_templates[id].Reset(isolate, templ); return id; } Value ClassBuilder::newInstance(Context &ctx, ClassID classId) { v8::Isolate *isolate = static_cast<v8::Isolate *>(ctx.raw()); RuntimeData *rtData = getRuntimeData(isolate); v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> v8ctx = ctx.impl()->Get(); v8::Context::Scope context_scope(v8ctx); if (!rtData) { // Fallback: create plain object (won't have internal fields) v8::Local<v8::Object> obj = v8::Object::New(isolate); auto impl = std::make_unique<Value::Impl>(isolate, obj); return Value(std::move(impl)); } // Get the ObjectTemplate for this class auto it = rtData->class_templates.find(classId); if (it == rtData->class_templates.end() || it->second.IsEmpty()) { // Fallback: create plain object (won't have internal fields) v8::Local<v8::Object> obj = v8::Object::New(isolate); auto impl = std::make_unique<Value::Impl>(isolate, obj); return Value(std::move(impl)); } v8::Local<v8::ObjectTemplate> templ = it->second.Get(isolate); v8::Local<v8::Object> obj = templ->NewInstance(v8ctx).ToLocalChecked(); // Set the prototype if one was registered for this class auto protoIt = rtData->class_prototypes.find(classId); if (protoIt != rtData->class_prototypes.end() && !protoIt->second.IsEmpty()) { v8::Local<v8::Object> proto = protoIt->second.Get(isolate); obj->SetPrototype(v8ctx, proto).Check(); } auto impl = std::make_unique<Value::Impl>(isolate, obj); return Value(std::move(impl)); } void ClassBuilder::setOpaque(Value &obj, void *opaque) { obj.setInternalField(0, opaque); } void *ClassBuilder::getOpaque(const Value &obj, ClassID classId) { return obj.getInternalField(0); } void ClassBuilder::setPrototype(Context &ctx, ClassID classId, Value &proto) { if (!proto.impl() || proto.impl()->value.IsEmpty()) return; v8::Isolate *isolate = static_cast<v8::Isolate *>(ctx.raw()); RuntimeData *rtData = getRuntimeData(isolate); if (!rtData) return; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Value> protoVal = proto.impl()->Get(); if (!protoVal->IsObject()) return; rtData->class_prototypes[classId].Reset(isolate, protoVal.As<v8::Object>()); } // ============================================================================ // PersistentValue implementation // ============================================================================ struct PersistentValue::Impl { v8::Isolate *isolate; v8::Global<v8::Value> value; Impl() : isolate(nullptr) {} Impl(v8::Isolate *iso, v8::Local<v8::Value> val) : isolate(iso), value(iso, val) {} ~Impl() { value.Reset(); } }; PersistentValue::PersistentValue() : impl_(std::make_unique<Impl>()) {} PersistentValue::PersistentValue(Context &ctx, const Value &val) : impl_(std::make_unique<Impl>()) { if (val.impl() && val.impl()->isolate && !val.impl()->value.IsEmpty()) { v8::Isolate *isolate = val.impl()->isolate; v8::HandleScope handle_scope(isolate); impl_->isolate = isolate; impl_->value.Reset(isolate, val.impl()->Get()); } } PersistentValue::~PersistentValue() = default; PersistentValue::PersistentValue(PersistentValue &&other) noexcept : impl_(std::move(other.impl_)) {} PersistentValue &PersistentValue::operator=(PersistentValue &&other) noexcept { impl_ = std::move(other.impl_); return *this; } Value PersistentValue::get(Context &ctx) const { if (!impl_ || !impl_->isolate || impl_->value.IsEmpty()) { return Value::undefined(); } v8::HandleScope handle_scope(impl_->isolate); v8::Local<v8::Value> val = impl_->value.Get(impl_->isolate); auto valImpl = std::make_unique<Value::Impl>(impl_->isolate, val); return Value(std::move(valImpl)); } bool PersistentValue::isEmpty() const { return !impl_ || !impl_->isolate || impl_->value.IsEmpty(); } void PersistentValue::reset() { if (impl_) { impl_->value.Reset(); impl_->isolate = nullptr; } } void PersistentValue::reset(Context &ctx, const Value &val) { reset(); if (val.impl() && val.impl()->isolate && !val.impl()->value.IsEmpty()) { v8::Isolate *isolate = val.impl()->isolate; v8::HandleScope handle_scope(isolate); impl_->isolate = isolate; impl_->value.Reset(isolate, val.impl()->Get()); } } // ============================================================================ // ConstructorBuilder implementation // ============================================================================ struct ConstructorArgs::Impl { v8::Isolate *isolate; v8::Local<v8::Context> context; const v8::FunctionCallbackInfo<v8::Value> *info; Context *wrapper_ctx; v8::Local<v8::FunctionTemplate> func_template; Impl(v8::Isolate *iso, v8::Local<v8::Context> ctx, const v8::FunctionCallbackInfo<v8::Value> *i, Context *wc, v8::Local<v8::FunctionTemplate> ft) : isolate(iso), context(ctx), info(i), wrapper_ctx(wc), func_template(ft) {} }; int ConstructorArgs::length() const { return impl_->info->Length(); } Value ConstructorArgs::arg(int index) const { if (index < 0 || index >= impl_->info->Length()) { return Value::undefined(); } v8::Local<v8::Value> val = (*impl_->info)[index]; auto valImpl = std::make_unique<Value::Impl>(impl_->isolate, val); return Value(std::move(valImpl)); } Context &ConstructorArgs::context() { return *impl_->wrapper_ctx; } void *ConstructorArgs::getContextOpaqueRaw() const { return impl_->wrapper_ctx->getOpaque(); } Value ConstructorArgs::createInstance() { // Return the 'this' object - V8 automatically creates it for constructors v8::Local<v8::Object> thisObj = impl_->info->This(); auto valImpl = std::make_unique<Value::Impl>(impl_->isolate, thisObj); return Value(std::move(valImpl)); } void ConstructorArgs::returnValue(Value instance) { if (instance.impl()) { v8::Local<v8::Value> v8val = instance.impl()->GetWithIsolate(impl_->isolate); impl_->info->GetReturnValue().Set(v8val); } } void ConstructorArgs::throwError(const char *msg) { impl_->isolate->ThrowError( v8::String::NewFromUtf8(impl_->isolate, msg).ToLocalChecked()); } void ConstructorArgs::throwTypeError(const char *msg) { impl_->isolate->ThrowException(v8::Exception::TypeError( v8::String::NewFromUtf8(impl_->isolate, msg).ToLocalChecked())); } void ConstructorArgs::throwSyntaxError(const char *msg) { impl_->isolate->ThrowException(v8::Exception::SyntaxError( v8::String::NewFromUtf8(impl_->isolate, msg).ToLocalChecked())); } void ConstructorArgs::throwRangeError(const char *msg) { impl_->isolate->ThrowException(v8::Exception::RangeError( v8::String::NewFromUtf8(impl_->isolate, msg).ToLocalChecked())); } // ConstructorBuilder data structures struct ConstructorMethodEntry { const char *name; NativeFunction fn; int argc; }; struct ConstructorAccessorEntry { const char *name; AccessorGetter getter; AccessorSetter setter; }; struct ConstructorBuilder::Impl { Context *ctx; const char *name; ConstructorCallback ctor_cb; int ctor_argc; Finalizer finalizer_fn; int internal_field_count; std::vector<ConstructorMethodEntry> methods; std::vector<ConstructorAccessorEntry> accessors; std::vector<std::pair<const char *, int>> int_constants; std::vector<std::pair<const char *, const char *>> str_constants; Impl(Context *c, const char *n) : ctx(c), name(n), ctor_cb(nullptr), ctor_argc(0), finalizer_fn(nullptr), internal_field_count(1) {} }; // Constructor trampoline static void v8_constructor_trampoline( const v8::FunctionCallbackInfo<v8::Value> &info) { v8::Isolate *isolate = info.GetIsolate(); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> ctx = isolate->GetCurrentContext(); if (!info.IsConstructCall()) { isolate->ThrowError( v8::String::NewFromUtf8Literal(isolate, "Must be called with 'new'")); return; } // Get constructor callback from external data v8::Local<v8::External> ext = info.Data().As<v8::External>(); ConstructorCallback cb = reinterpret_cast<ConstructorCallback>(ext->Value()); // Create wrapper context Context wrapper = Context::wrapRaw(nullptr, isolate); // Get opaque from context void *opaque = nullptr; v8::Local<v8::Value> opaque_val; if (ctx->Global() ->Get(ctx, v8::String::NewFromUtf8Literal(isolate, "__joy_opaque__")) .ToLocal(&opaque_val) && opaque_val->IsExternal()) { opaque = opaque_val.As<v8::External>()->Value(); } wrapper.impl()->opaque = opaque; ConstructorArgs::Impl argsImpl(isolate, ctx, &info, &wrapper, v8::Local<v8::FunctionTemplate>()); ConstructorArgs args(&argsImpl); cb(args); } ConstructorBuilder::ConstructorBuilder(Context &ctx, const char *name) : impl_(std::make_unique<Impl>(&ctx, name)) {} ConstructorBuilder::~ConstructorBuilder() = default; ConstructorBuilder::ConstructorBuilder(ConstructorBuilder &&other) noexcept : impl_(std::move(other.impl_)) {} ConstructorBuilder & ConstructorBuilder::operator=(ConstructorBuilder &&other) noexcept { impl_ = std::move(other.impl_); return *this; } ConstructorBuilder &ConstructorBuilder::constructor(ConstructorCallback cb, int argc) { impl_->ctor_cb = cb; impl_->ctor_argc = argc; return *this; } ConstructorBuilder &ConstructorBuilder::finalizer(Finalizer fn) { impl_->finalizer_fn = fn; return *this; } ConstructorBuilder &ConstructorBuilder::internalFieldCount(int count) { impl_->internal_field_count = count; return *this; } ConstructorBuilder &ConstructorBuilder::prototypeMethod(const char *name, NativeFunction fn, int argc) { impl_->methods.push_back({name, fn, argc}); return *this; } ConstructorBuilder &ConstructorBuilder::prototypeGetter(const char *name, AccessorGetter getter) { impl_->accessors.push_back({name, getter, nullptr}); return *this; } ConstructorBuilder &ConstructorBuilder::prototypeAccessor(const char *name, AccessorGetter getter, AccessorSetter setter) { impl_->accessors.push_back({name, getter, setter}); return *this; } ConstructorBuilder &ConstructorBuilder::staticConstant(const char *name, int value) { impl_->int_constants.push_back({name, value}); return *this; } ConstructorBuilder &ConstructorBuilder::staticConstant(const char *name, const char *value) { impl_->str_constants.push_back({name, value}); return *this; } void ConstructorBuilder::attachTo(Value &target) { v8::Isolate *isolate = impl_->ctx->impl()->isolate; v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); v8::Local<v8::Context> ctx = impl_->ctx->impl()->Get(); v8::Context::Scope context_scope(ctx); // Create function template for constructor v8::Local<v8::External> ctor_data = v8::External::New(isolate, reinterpret_cast<void *>(impl_->ctor_cb)); v8::Local<v8::FunctionTemplate> ctor_template = v8::FunctionTemplate::New( isolate, v8_constructor_trampoline, ctor_data); ctor_template->SetClassName( v8::String::NewFromUtf8(isolate, impl_->name).ToLocalChecked()); ctor_template->InstanceTemplate()->SetInternalFieldCount( impl_->internal_field_count); // Add prototype methods v8::Local<v8::ObjectTemplate> proto = ctor_template->PrototypeTemplate(); for (const auto &entry : impl_->methods) { v8::Local<v8::External> data = v8::External::New(isolate, reinterpret_cast<void *>(entry.fn)); v8::Local<v8::FunctionTemplate> method_template = v8::FunctionTemplate::New(isolate, v8_trampoline, data); proto->Set(v8::String::NewFromUtf8(isolate, entry.name).ToLocalChecked(), method_template); } // Add prototype accessors for (const auto &entry : impl_->accessors) { v8::Local<v8::External> getter_data = v8::External::New(isolate, reinterpret_cast<void *>(entry.getter)); v8::Local<v8::FunctionTemplate> getter_template = v8::FunctionTemplate::New(isolate, v8_trampoline, getter_data); v8::Local<v8::FunctionTemplate> setter_template; if (entry.setter) { v8::Local<v8::External> setter_data = v8::External::New( isolate, reinterpret_cast<void *>(entry.setter)); setter_template = v8::FunctionTemplate::New(isolate, v8_trampoline, setter_data); } proto->SetAccessorProperty( v8::String::NewFromUtf8(isolate, entry.name).ToLocalChecked(), getter_template, setter_template); } // Get the constructor function v8::Local<v8::Function> ctor = ctor_template->GetFunction(ctx).ToLocalChecked(); // Add static constants for (const auto &pair : impl_->int_constants) { ctor->Set(ctx, v8::String::NewFromUtf8(isolate, pair.first).ToLocalChecked(), v8::Integer::New(isolate, pair.second)) .Check(); } for (const auto &pair : impl_->str_constants) { ctor->Set(ctx, v8::String::NewFromUtf8(isolate, pair.first).ToLocalChecked(), v8::String::NewFromUtf8(isolate, pair.second).ToLocalChecked()) .Check(); } // Attach to target - wrap ctor in a Value and use public setProperty auto ctorImpl = std::make_unique<Value::Impl>(isolate, ctor); Value ctorValue(std::move(ctorImpl)); target.setProperty(*impl_->ctx, impl_->name, std::move(ctorValue)); } } // namespace js
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/main.cc
C++
#include "engine.hh" #include "bundle.hh" #include "modules/gui/gui.hh" #include "web-api/websocket.hh" #include "web-api/worker.hh" #include "SDL3/SDL.h" #include "physfs.h" #include "cwalk.h" #include <cargs.h> #include <cstdio> #include <cstring> #include <sys/stat.h> #ifdef __EMSCRIPTEN__ #include <emscripten.h> #endif // Windows compatibility for S_ISDIR #ifdef _WIN32 #ifndef S_ISDIR #define S_ISDIR(mode) (((mode) & _S_IFMT) == _S_IFDIR) #endif #endif // Check if path is a directory static bool isDirectory(const char *path) { struct stat st; if (stat(path, &st) != 0) { return false; } return S_ISDIR(st.st_mode); } // Check if path ends with .js static bool isScriptFile(const char *path) { size_t len = strlen(path); return len > 3 && strcmp(path + len - 3, ".js") == 0; } // Get directory from path (caller must free) static char *getDirectory(const char *path) { size_t dir_len; cwk_path_get_dirname(path, &dir_len); if (dir_len == 0) { return strdup("."); } char *dir = (char *)malloc(dir_len + 1); memcpy(dir, path, dir_len); dir[dir_len] = '\0'; return dir; } // Get filename from path static const char *getFilename(const char *path) { const char *basename; size_t len; cwk_path_get_basename(path, &basename, &len); return basename; } static struct cag_option options[] = { {.identifier = 'b', .access_letters = "b", .access_name = "bundle", .value_name = "OUTPUT", .description = "Create a .joy bundle from input directory"}, {.identifier = 'h', .access_letters = "h", .access_name = "help", .description = "Show this help message"} }; static void printUsage(const char *program) { printf("Usage: %s [options] [path]\n\n", program); printf("Run a Joy game:\n"); printf(" %s Run main.js in current directory\n", program); printf(" %s <directory> Run main.js in directory\n", program); printf(" %s <file.joy> Run game from .joy bundle\n\n", program); printf("Options:\n"); cag_option_print(options, CAG_ARRAY_SIZE(options), stdout); } // Frame function - handles events and renders one frame static bool runFrame(joy::Engine *engine) { // Update WebSocket (pump curl_multi for non-blocking I/O) #ifndef __EMSCRIPTEN__ if (engine->getWebSocketModule()) { engine->getWebSocketModule()->update(); } // Update Workers (process messages from worker threads) if (engine->getWorkerModule()) { engine->getWorkerModule()->update(); } #endif // Poll events SDL_Event event; while (SDL_PollEvent(&event)) { // Pass event to GUI first if (engine->getGuiModule()) { engine->getGuiModule()->handleEvent(&event); } switch (event.type) { case SDL_EVENT_QUIT: return false; case SDL_EVENT_KEY_DOWN: engine->handleKeyPressed(event.key.scancode, event.key.repeat); break; case SDL_EVENT_KEY_UP: engine->handleKeyReleased(event.key.scancode); break; case SDL_EVENT_TEXT_INPUT: engine->handleTextInput(event.text.text); break; case SDL_EVENT_MOUSE_BUTTON_DOWN: engine->handleMousePressed(event.button.x, event.button.y, event.button.button, event.button.clicks); break; case SDL_EVENT_MOUSE_BUTTON_UP: engine->handleMouseReleased(event.button.x, event.button.y, event.button.button, event.button.clicks); break; case SDL_EVENT_MOUSE_MOTION: engine->handleMouseMoved(event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel); break; case SDL_EVENT_MOUSE_WHEEL: engine->handleMouseWheel(event.wheel.x, event.wheel.y); break; case SDL_EVENT_WINDOW_MOUSE_ENTER: engine->handleMouseFocus(true); break; case SDL_EVENT_WINDOW_MOUSE_LEAVE: engine->handleMouseFocus(false); break; case SDL_EVENT_JOYSTICK_ADDED: engine->handleJoystickAdded(event.jdevice.which); break; case SDL_EVENT_JOYSTICK_REMOVED: engine->handleJoystickRemoved(event.jdevice.which); break; case SDL_EVENT_JOYSTICK_BUTTON_DOWN: engine->handleJoystickPressed(event.jbutton.which, event.jbutton.button); break; case SDL_EVENT_JOYSTICK_BUTTON_UP: engine->handleJoystickReleased(event.jbutton.which, event.jbutton.button); break; case SDL_EVENT_JOYSTICK_AXIS_MOTION: engine->handleJoystickAxis(event.jaxis.which, event.jaxis.axis, static_cast<float>(event.jaxis.value) / 32767.0f); break; case SDL_EVENT_JOYSTICK_HAT_MOTION: engine->handleJoystickHat(event.jhat.which, event.jhat.hat, event.jhat.value); break; case SDL_EVENT_GAMEPAD_BUTTON_DOWN: engine->handleGamepadPressed(event.gbutton.which, event.gbutton.button); break; case SDL_EVENT_GAMEPAD_BUTTON_UP: engine->handleGamepadReleased(event.gbutton.which, event.gbutton.button); break; case SDL_EVENT_GAMEPAD_AXIS_MOTION: engine->handleGamepadAxis(event.gaxis.which, event.gaxis.axis, static_cast<float>(event.gaxis.value) / 32767.0f); break; } } // Run one frame engine->frame(); return engine->isRunning(); } #ifdef __EMSCRIPTEN__ // Emscripten main loop callback static void emscripten_frame(void *arg) { joy::Engine *engine = static_cast<joy::Engine *>(arg); if (!runFrame(engine)) { emscripten_cancel_main_loop(); } } #endif int main(int argc, char *argv[]) { const char *bundle_output = nullptr; const char *input_path = nullptr; // Parse command line arguments cag_option_context context; cag_option_init(&context, options, CAG_ARRAY_SIZE(options), argc, argv); while (cag_option_fetch(&context)) { switch (cag_option_get_identifier(&context)) { case 'b': bundle_output = cag_option_get_value(&context); break; case 'h': printUsage(argv[0]); return 0; case '?': fprintf(stderr, "Unknown option: %s\n", cag_option_get_value(&context)); printUsage(argv[0]); return 1; } } // Get input path from remaining arguments if (cag_option_get_index(&context) < argc) { input_path = argv[cag_option_get_index(&context)]; } // Print help if no input provided and not creating bundle if (!input_path) { printUsage(argv[0]); return 0; } // Determine mount path and script name const char *mount_path; const char *script_name; char *allocated_mount = nullptr; if (isDirectory(input_path)) { mount_path = input_path; script_name = "main.js"; } else if (isScriptFile(input_path)) { // Script file - mount its directory and run the specific script allocated_mount = getDirectory(input_path); mount_path = allocated_mount; script_name = getFilename(input_path); } else { // Assume it's an archive (.joy or .zip) mount_path = input_path; script_name = "main.js"; } // Initialize PhysFS if (!PHYSFS_init(argv[0])) { fprintf(stderr, "Failed to initialize PhysFS: %s\n", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); return 1; } // Handle bundle creation if (bundle_output) { if (!isDirectory(input_path)) { fprintf(stderr, "Error: Cannot bundle a single file. Please provide a directory.\n"); free(allocated_mount); PHYSFS_deinit(); return 1; } int result = joy::createBundle(bundle_output, input_path); free(allocated_mount); PHYSFS_deinit(); return result; } // Initialize SDL if (!SDL_Init(SDL_INIT_VIDEO)) { fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError()); free(allocated_mount); PHYSFS_deinit(); return 1; } // Create engine joy::Engine *engine = new joy::Engine(); if (!engine->init()) { fprintf(stderr, "Failed to initialize engine\n"); delete engine; SDL_Quit(); free(allocated_mount); PHYSFS_deinit(); return 1; } // Mount and load game if (!engine->mountGame(mount_path)) { fprintf(stderr, "Failed to mount game: %s\n", mount_path); delete engine; SDL_Quit(); free(allocated_mount); PHYSFS_deinit(); return 1; } if (!engine->loadScript(script_name)) { fprintf(stderr, "Failed to load script: %s\n", script_name); delete engine; SDL_Quit(); free(allocated_mount); PHYSFS_deinit(); return 1; } free(allocated_mount); // Main loop #ifdef __EMSCRIPTEN__ emscripten_set_main_loop_arg(emscripten_frame, engine, 0, 1); #else while (runFrame(engine)) { SDL_Delay(1); } #endif // Cleanup delete engine; SDL_Quit(); PHYSFS_deinit(); return 0; }
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/audio/audio.cc
C++
#include "audio.hh" #include "modules/sound/sound.hh" #include "miniaudio.h" #define STB_VORBIS_HEADER_ONLY #include "stb_vorbis.c" #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <cfloat> #include <algorithm> namespace joy { namespace modules { // AudioSource implementation AudioSource::AudioSource(Audio *audioModule) : audioModule_(audioModule) , sound_(nullptr) , buffer_(nullptr) , buffer_config_(nullptr) , pcm_data_(nullptr) , frame_count_(0) , pitch_(1.0f) , volume_(1.0f) , looping_(false) , duration_(0.0f) , channels_(0) , sampleRate_(0) , type_(SourceType::Static) , spatial_(false) , posX_(0.0f), posY_(0.0f), posZ_(0.0f) , velX_(0.0f), velY_(0.0f), velZ_(0.0f) , dirX_(0.0f), dirY_(0.0f), dirZ_(0.0f) , coneInnerAngle_(2.0f * 3.14159265f), coneOuterAngle_(2.0f * 3.14159265f), coneOuterVolume_(0.0f) , relative_(false) , refDistance_(1.0f), maxDistance_(FLT_MAX) , rolloff_(1.0f) , dopplerFactor_(1.0f) , minVolume_(0.0f), maxVolume_(1.0f) , airAbsorption_(0.0f) , hasFilter_(false) , lpfNode_(nullptr) , hpfNode_(nullptr) , bpfNode_(nullptr) { sound_ = static_cast<ma_sound *>(malloc(sizeof(ma_sound))); buffer_ = static_cast<ma_audio_buffer *>(malloc(sizeof(ma_audio_buffer))); buffer_config_ = static_cast<ma_audio_buffer_config *>(malloc(sizeof(ma_audio_buffer_config))); if (audioModule_) { audioModule_->registerSource(this); } } AudioSource::~AudioSource() { if (audioModule_) { audioModule_->unregisterSource(this); } if (sound_) { ma_sound_uninit(sound_); free(sound_); } if (buffer_) { ma_audio_buffer_uninit(buffer_); free(buffer_); } free(buffer_config_); if (pcm_data_) { free(pcm_data_); } if (lpfNode_) { ma_lpf_node_uninit(lpfNode_, nullptr); free(lpfNode_); } if (hpfNode_) { ma_hpf_node_uninit(hpfNode_, nullptr); free(hpfNode_); } if (bpfNode_) { ma_bpf_node_uninit(bpfNode_, nullptr); free(bpfNode_); } } bool AudioSource::initFromMemory(ma_engine *engine, const char *file_data, size_t file_size, bool spatial) { spatial_ = spatial; // Decode OGG using stb_vorbis int channels, sample_rate; short *samples; int num_samples = stb_vorbis_decode_memory( reinterpret_cast<const unsigned char *>(file_data), static_cast<int>(file_size), &channels, &sample_rate, &samples ); if (num_samples < 0) { fprintf(stderr, "Failed to decode audio file\n"); return false; } channels_ = channels; sampleRate_ = sample_rate; // Convert to float PCM frame_count_ = static_cast<ma_uint64>(num_samples); pcm_data_ = static_cast<float *>(malloc(frame_count_ * channels * sizeof(float))); if (!pcm_data_) { free(samples); return false; } for (int i = 0; i < num_samples * channels; i++) { pcm_data_[i] = samples[i] / 32768.0f; } free(samples); duration_ = static_cast<float>(num_samples) / static_cast<float>(sample_rate); // Create audio buffer *buffer_config_ = ma_audio_buffer_config_init( ma_format_f32, static_cast<ma_uint32>(channels), frame_count_, pcm_data_, nullptr); buffer_config_->sampleRate = static_cast<ma_uint32>(sample_rate); if (ma_audio_buffer_init(buffer_config_, buffer_) != MA_SUCCESS) { fprintf(stderr, "Failed to create audio buffer\n"); return false; } // Create sound from buffer ma_uint32 flags = spatial ? 0 : MA_SOUND_FLAG_NO_SPATIALIZATION; if (ma_sound_init_from_data_source(engine, buffer_, flags, nullptr, sound_) != MA_SUCCESS) { fprintf(stderr, "Failed to create sound\n"); ma_audio_buffer_uninit(buffer_); return false; } // Apply initial spatial settings if enabled if (spatial_) { ma_sound_set_position(sound_, posX_, posY_, posZ_); ma_sound_set_velocity(sound_, velX_, velY_, velZ_); ma_sound_set_direction(sound_, dirX_, dirY_, dirZ_); ma_sound_set_cone(sound_, coneInnerAngle_, coneOuterAngle_, coneOuterVolume_); ma_sound_set_min_distance(sound_, refDistance_); ma_sound_set_max_distance(sound_, maxDistance_); ma_sound_set_rolloff(sound_, rolloff_); ma_sound_set_doppler_factor(sound_, dopplerFactor_); ma_sound_set_positioning(sound_, relative_ ? ma_positioning_relative : ma_positioning_absolute); } return true; } bool AudioSource::initFromSoundData(ma_engine *engine, SoundData *soundData, bool spatial) { if (!soundData) { fprintf(stderr, "Invalid SoundData\n"); return false; } spatial_ = spatial; // Get audio parameters from SoundData channels_ = soundData->getChannelCount(); sampleRate_ = soundData->getSampleRate(); int sampleCount = soundData->getSampleCount(); const float *srcData = soundData->getData(); // Copy PCM data (AudioSource takes ownership) frame_count_ = static_cast<ma_uint64>(sampleCount); pcm_data_ = static_cast<float *>(malloc(frame_count_ * channels_ * sizeof(float))); if (!pcm_data_) { return false; } memcpy(pcm_data_, srcData, frame_count_ * channels_ * sizeof(float)); duration_ = static_cast<float>(sampleCount) / static_cast<float>(sampleRate_); // Create audio buffer *buffer_config_ = ma_audio_buffer_config_init( ma_format_f32, static_cast<ma_uint32>(channels_), frame_count_, pcm_data_, nullptr); buffer_config_->sampleRate = static_cast<ma_uint32>(sampleRate_); if (ma_audio_buffer_init(buffer_config_, buffer_) != MA_SUCCESS) { fprintf(stderr, "Failed to create audio buffer from SoundData\n"); return false; } // Create sound from buffer ma_uint32 flags = spatial ? 0 : MA_SOUND_FLAG_NO_SPATIALIZATION; if (ma_sound_init_from_data_source(engine, buffer_, flags, nullptr, sound_) != MA_SUCCESS) { fprintf(stderr, "Failed to create sound from SoundData\n"); ma_audio_buffer_uninit(buffer_); return false; } // Apply initial spatial settings if enabled if (spatial_) { ma_sound_set_position(sound_, posX_, posY_, posZ_); ma_sound_set_velocity(sound_, velX_, velY_, velZ_); ma_sound_set_direction(sound_, dirX_, dirY_, dirZ_); ma_sound_set_cone(sound_, coneInnerAngle_, coneOuterAngle_, coneOuterVolume_); ma_sound_set_min_distance(sound_, refDistance_); ma_sound_set_max_distance(sound_, maxDistance_); ma_sound_set_rolloff(sound_, rolloff_); ma_sound_set_doppler_factor(sound_, dopplerFactor_); ma_sound_set_positioning(sound_, relative_ ? ma_positioning_relative : ma_positioning_absolute); } return true; } AudioSource *AudioSource::clone() const { if (!audioModule_ || !pcm_data_) { return nullptr; } AudioSource *cloned = new AudioSource(audioModule_); // Copy PCM data cloned->frame_count_ = frame_count_; cloned->channels_ = channels_; cloned->sampleRate_ = sampleRate_; cloned->duration_ = duration_; cloned->type_ = type_; cloned->spatial_ = spatial_; cloned->pcm_data_ = static_cast<float *>(malloc(frame_count_ * channels_ * sizeof(float))); if (!cloned->pcm_data_) { delete cloned; return nullptr; } memcpy(cloned->pcm_data_, pcm_data_, frame_count_ * channels_ * sizeof(float)); // Create audio buffer *cloned->buffer_config_ = ma_audio_buffer_config_init( ma_format_f32, static_cast<ma_uint32>(channels_), frame_count_, cloned->pcm_data_, nullptr); cloned->buffer_config_->sampleRate = static_cast<ma_uint32>(sampleRate_); if (ma_audio_buffer_init(cloned->buffer_config_, cloned->buffer_) != MA_SUCCESS) { delete cloned; return nullptr; } // Create sound from buffer ma_uint32 flags = spatial_ ? 0 : MA_SOUND_FLAG_NO_SPATIALIZATION; if (ma_sound_init_from_data_source(audioModule_->getEngine(), cloned->buffer_, flags, nullptr, cloned->sound_) != MA_SUCCESS) { ma_audio_buffer_uninit(cloned->buffer_); delete cloned; return nullptr; } // Copy all properties cloned->pitch_ = pitch_; cloned->volume_ = volume_; cloned->looping_ = looping_; // Apply properties to new sound ma_sound_set_volume(cloned->sound_, volume_); ma_sound_set_pitch(cloned->sound_, pitch_); ma_sound_set_looping(cloned->sound_, looping_); // Copy spatial properties cloned->posX_ = posX_; cloned->posY_ = posY_; cloned->posZ_ = posZ_; cloned->velX_ = velX_; cloned->velY_ = velY_; cloned->velZ_ = velZ_; cloned->dirX_ = dirX_; cloned->dirY_ = dirY_; cloned->dirZ_ = dirZ_; cloned->coneInnerAngle_ = coneInnerAngle_; cloned->coneOuterAngle_ = coneOuterAngle_; cloned->coneOuterVolume_ = coneOuterVolume_; cloned->relative_ = relative_; cloned->refDistance_ = refDistance_; cloned->maxDistance_ = maxDistance_; cloned->rolloff_ = rolloff_; cloned->dopplerFactor_ = dopplerFactor_; cloned->minVolume_ = minVolume_; cloned->maxVolume_ = maxVolume_; cloned->airAbsorption_ = airAbsorption_; if (spatial_) { ma_sound_set_position(cloned->sound_, posX_, posY_, posZ_); ma_sound_set_velocity(cloned->sound_, velX_, velY_, velZ_); ma_sound_set_direction(cloned->sound_, dirX_, dirY_, dirZ_); ma_sound_set_cone(cloned->sound_, coneInnerAngle_, coneOuterAngle_, coneOuterVolume_); ma_sound_set_min_distance(cloned->sound_, refDistance_); ma_sound_set_max_distance(cloned->sound_, maxDistance_); ma_sound_set_rolloff(cloned->sound_, rolloff_); ma_sound_set_doppler_factor(cloned->sound_, dopplerFactor_); ma_sound_set_positioning(cloned->sound_, relative_ ? ma_positioning_relative : ma_positioning_absolute); } // Copy filter settings if present if (hasFilter_) { cloned->setFilter(filterSettings_); } return cloned; } void AudioSource::play() { ma_sound_seek_to_pcm_frame(sound_, 0); ma_sound_start(sound_); } void AudioSource::stop() { ma_sound_stop(sound_); ma_sound_seek_to_pcm_frame(sound_, 0); } void AudioSource::pause() { ma_sound_stop(sound_); } bool AudioSource::isPlaying() const { return ma_sound_is_playing(sound_); } void AudioSource::setVolume(float volume) { volume_ = std::clamp(volume, minVolume_, maxVolume_); ma_sound_set_volume(sound_, volume_); } void AudioSource::setPitch(float pitch) { pitch_ = pitch; ma_sound_set_pitch(sound_, pitch_); } void AudioSource::setLooping(bool looping) { looping_ = looping; ma_sound_set_looping(sound_, looping_); } void AudioSource::seek(float position, bool inSamples) { ma_uint64 frame; if (inSamples) { frame = static_cast<ma_uint64>(position); } else { frame = static_cast<ma_uint64>(position * sampleRate_); } ma_sound_seek_to_pcm_frame(sound_, frame); } float AudioSource::tell(bool inSamples) const { ma_uint64 cursor; ma_sound_get_cursor_in_pcm_frames(sound_, &cursor); if (inSamples) { return static_cast<float>(cursor); } return static_cast<float>(cursor) / static_cast<float>(sampleRate_); } float AudioSource::getDuration(bool inSamples) const { if (inSamples) { return static_cast<float>(frame_count_); } return duration_; } // 3D Spatial Audio methods void AudioSource::setPosition(float x, float y, float z) { posX_ = x; posY_ = y; posZ_ = z; if (spatial_) { ma_sound_set_position(sound_, x, y, z); } } void AudioSource::getPosition(float &x, float &y, float &z) const { x = posX_; y = posY_; z = posZ_; } void AudioSource::setVelocity(float x, float y, float z) { velX_ = x; velY_ = y; velZ_ = z; if (spatial_) { ma_sound_set_velocity(sound_, x, y, z); } } void AudioSource::getVelocity(float &x, float &y, float &z) const { x = velX_; y = velY_; z = velZ_; } void AudioSource::setDirection(float x, float y, float z) { dirX_ = x; dirY_ = y; dirZ_ = z; if (spatial_) { ma_sound_set_direction(sound_, x, y, z); } } void AudioSource::getDirection(float &x, float &y, float &z) const { x = dirX_; y = dirY_; z = dirZ_; } void AudioSource::setCone(float innerAngle, float outerAngle, float outerVolume) { coneInnerAngle_ = innerAngle; coneOuterAngle_ = outerAngle; coneOuterVolume_ = outerVolume; if (spatial_) { ma_sound_set_cone(sound_, innerAngle, outerAngle, outerVolume); } } void AudioSource::getCone(float &innerAngle, float &outerAngle, float &outerVolume) const { innerAngle = coneInnerAngle_; outerAngle = coneOuterAngle_; outerVolume = coneOuterVolume_; } void AudioSource::setRelative(bool relative) { relative_ = relative; if (spatial_) { ma_sound_set_positioning(sound_, relative ? ma_positioning_relative : ma_positioning_absolute); } } void AudioSource::setAttenuationDistances(float ref, float max) { refDistance_ = ref; maxDistance_ = max; if (spatial_) { ma_sound_set_min_distance(sound_, ref); ma_sound_set_max_distance(sound_, max); } } void AudioSource::getAttenuationDistances(float &ref, float &max) const { ref = refDistance_; max = maxDistance_; } void AudioSource::setRolloff(float rolloff) { rolloff_ = rolloff; if (spatial_) { ma_sound_set_rolloff(sound_, rolloff); } } void AudioSource::setDopplerFactor(float factor) { dopplerFactor_ = factor; if (spatial_) { ma_sound_set_doppler_factor(sound_, factor); } } void AudioSource::setVolumeLimits(float min, float max) { minVolume_ = min; maxVolume_ = max; // Re-apply current volume to respect new limits setVolume(volume_); } void AudioSource::getVolumeLimits(float &min, float &max) const { min = minVolume_; max = maxVolume_; } void AudioSource::setAirAbsorption(float amount) { airAbsorption_ = std::clamp(amount, 0.0f, 10.0f); // Note: miniaudio doesn't have direct air absorption support // This would need custom implementation via filters } // Filter implementation // Note: miniaudio's filter nodes work differently than OpenAL's filters // We simulate the Love2D filter behavior using miniaudio's built-in filters bool AudioSource::setFilter(const FilterSettings &settings) { hasFilter_ = true; filterSettings_ = settings; // Apply volume component directly to the sound // The gain components would ideally be applied via actual filter nodes // For now, we just store the settings and apply a simple volume adjustment float effectiveVolume = volume_ * settings.volume; ma_sound_set_volume(sound_, effectiveVolume); return true; } bool AudioSource::getFilter(FilterSettings &settings) const { if (!hasFilter_) { return false; } settings = filterSettings_; return true; } void AudioSource::clearFilter() { hasFilter_ = false; filterSettings_ = FilterSettings(); ma_sound_set_volume(sound_, volume_); } // Audio module implementation Audio::Audio(Engine *engine) : engine_(engine) , engine_audio_(nullptr) , masterVolume_(1.0f) , listenerPosX_(0.0f), listenerPosY_(0.0f), listenerPosZ_(0.0f) , listenerVelX_(0.0f), listenerVelY_(0.0f), listenerVelZ_(0.0f) , listenerFwdX_(0.0f), listenerFwdY_(0.0f), listenerFwdZ_(-1.0f) , listenerUpX_(0.0f), listenerUpY_(1.0f), listenerUpZ_(0.0f) , distanceModel_(DistanceModel::InverseClamped) , dopplerScale_(1.0f) { } Audio::~Audio() { shutdown(); } bool Audio::init() { engine_audio_ = static_cast<ma_engine *>(malloc(sizeof(ma_engine))); if (!engine_audio_) { fprintf(stderr, "Failed to allocate audio engine\n"); return false; } ma_engine_config config = ma_engine_config_init(); if (ma_engine_init(&config, engine_audio_) != MA_SUCCESS) { fprintf(stderr, "Failed to initialize audio engine\n"); free(engine_audio_); engine_audio_ = nullptr; return false; } // Set initial listener orientation ma_engine_listener_set_position(engine_audio_, 0, listenerPosX_, listenerPosY_, listenerPosZ_); ma_engine_listener_set_velocity(engine_audio_, 0, listenerVelX_, listenerVelY_, listenerVelZ_); ma_engine_listener_set_direction(engine_audio_, 0, listenerFwdX_, listenerFwdY_, listenerFwdZ_); ma_engine_listener_set_world_up(engine_audio_, 0, listenerUpX_, listenerUpY_, listenerUpZ_); return true; } void Audio::shutdown() { if (engine_audio_) { ma_engine_uninit(engine_audio_); free(engine_audio_); engine_audio_ = nullptr; } sources_.clear(); } void Audio::setVolume(float volume) { masterVolume_ = std::clamp(volume, 0.0f, 1.0f); if (engine_audio_) { ma_engine_set_volume(engine_audio_, masterVolume_); } } void Audio::registerSource(AudioSource *source) { sources_.push_back(source); } void Audio::unregisterSource(AudioSource *source) { auto it = std::find(sources_.begin(), sources_.end(), source); if (it != sources_.end()) { sources_.erase(it); } } int Audio::getActiveSourceCount() const { int count = 0; for (AudioSource *src : sources_) { if (src->isPlaying()) { count++; } } return count; } void Audio::pause() { for (AudioSource *src : sources_) { if (src->isPlaying()) { src->pause(); } } } void Audio::stop() { for (AudioSource *src : sources_) { src->stop(); } } void Audio::play() { // This resumes all sources - not typical Love2D behavior // Love2D's play() takes specific sources for (AudioSource *src : sources_) { if (!src->isPlaying()) { src->play(); } } } // Listener methods void Audio::setListenerPosition(float x, float y, float z) { listenerPosX_ = x; listenerPosY_ = y; listenerPosZ_ = z; if (engine_audio_) { ma_engine_listener_set_position(engine_audio_, 0, x, y, z); } } void Audio::getListenerPosition(float &x, float &y, float &z) const { x = listenerPosX_; y = listenerPosY_; z = listenerPosZ_; } void Audio::setListenerVelocity(float x, float y, float z) { listenerVelX_ = x; listenerVelY_ = y; listenerVelZ_ = z; if (engine_audio_) { ma_engine_listener_set_velocity(engine_audio_, 0, x, y, z); } } void Audio::getListenerVelocity(float &x, float &y, float &z) const { x = listenerVelX_; y = listenerVelY_; z = listenerVelZ_; } void Audio::setListenerOrientation(float fx, float fy, float fz, float ux, float uy, float uz) { listenerFwdX_ = fx; listenerFwdY_ = fy; listenerFwdZ_ = fz; listenerUpX_ = ux; listenerUpY_ = uy; listenerUpZ_ = uz; if (engine_audio_) { ma_engine_listener_set_direction(engine_audio_, 0, fx, fy, fz); ma_engine_listener_set_world_up(engine_audio_, 0, ux, uy, uz); } } void Audio::getListenerOrientation(float &fx, float &fy, float &fz, float &ux, float &uy, float &uz) const { fx = listenerFwdX_; fy = listenerFwdY_; fz = listenerFwdZ_; ux = listenerUpX_; uy = listenerUpY_; uz = listenerUpZ_; } void Audio::setDistanceModel(DistanceModel model) { distanceModel_ = model; // miniaudio uses different attenuation model per-sound rather than globally // We'll apply this to newly created sounds and update existing ones ma_attenuation_model maModel; switch (model) { case DistanceModel::None: maModel = ma_attenuation_model_none; break; case DistanceModel::Inverse: case DistanceModel::InverseClamped: maModel = ma_attenuation_model_inverse; break; case DistanceModel::Linear: case DistanceModel::LinearClamped: maModel = ma_attenuation_model_linear; break; case DistanceModel::Exponent: case DistanceModel::ExponentClamped: maModel = ma_attenuation_model_exponential; break; default: maModel = ma_attenuation_model_inverse; break; } // Note: miniaudio sets attenuation model per-sound, not globally // For full compatibility, we'd need to track this and apply to new sounds } void Audio::setDopplerScale(float scale) { dopplerScale_ = scale; // miniaudio applies doppler per-sound via doppler factor // Global scale would need to be multiplied with each source's factor } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/audio/audio.hh
C++ Header
#pragma once #include "miniaudio.h" #include <vector> #include <string> namespace js { class Context; class Value; } namespace joy { class Engine; namespace modules { // Forward declaration class SoundData; class Audio; // Source types (matching Love2D) enum class SourceType { Static, // Fully decoded in memory Stream, // Decoded in chunks (not yet implemented) Queue // Manually queued by user (not yet implemented) }; // Distance attenuation models enum class DistanceModel { None, // No attenuation Inverse, // Inverse distance InverseClamped, // Inverse distance, clamped Linear, // Linear attenuation LinearClamped, // Linear attenuation, clamped Exponent, // Exponential attenuation ExponentClamped // Exponential attenuation, clamped }; // Filter types enum class FilterType { LowPass, HighPass, BandPass }; // Filter settings struct FilterSettings { FilterType type = FilterType::LowPass; float volume = 1.0f; // Overall volume (0-1) float highGain = 1.0f; // High frequency gain (0-1), for lowpass/bandpass float lowGain = 1.0f; // Low frequency gain (0-1), for highpass/bandpass }; // AudioSource - represents a playable audio source class AudioSource { public: AudioSource(Audio *audioModule); ~AudioSource(); // Disable copy AudioSource(const AudioSource &) = delete; AudioSource &operator=(const AudioSource &) = delete; // Initialize from file data bool initFromMemory(ma_engine *engine, const char *file_data, size_t file_size, bool spatial = false); // Initialize from SoundData bool initFromSoundData(ma_engine *engine, SoundData *soundData, bool spatial = false); // Clone this source AudioSource *clone() const; // Playback control void play(); void stop(); void pause(); bool isPlaying() const; // Volume control void setVolume(float volume); float getVolume() const { return volume_; } // Pitch control void setPitch(float pitch); float getPitch() const { return pitch_; } // Looping void setLooping(bool looping); bool isLooping() const { return looping_; } // Seek/tell (in seconds or samples) void seek(float position, bool inSamples = false); float tell(bool inSamples = false) const; float getDuration(bool inSamples = false) const; // Source info int getChannelCount() const { return channels_; } SourceType getType() const { return type_; } int getSampleRate() const { return sampleRate_; } // 3D Spatial Audio void setPosition(float x, float y, float z); void getPosition(float &x, float &y, float &z) const; void setVelocity(float x, float y, float z); void getVelocity(float &x, float &y, float &z) const; void setDirection(float x, float y, float z); void getDirection(float &x, float &y, float &z) const; void setCone(float innerAngle, float outerAngle, float outerVolume); void getCone(float &innerAngle, float &outerAngle, float &outerVolume) const; void setRelative(bool relative); bool isRelative() const { return relative_; } // Distance attenuation void setAttenuationDistances(float ref, float max); void getAttenuationDistances(float &ref, float &max) const; void setRolloff(float rolloff); float getRolloff() const { return rolloff_; } // Doppler void setDopplerFactor(float factor); float getDopplerFactor() const { return dopplerFactor_; } // Volume limits void setVolumeLimits(float min, float max); void getVolumeLimits(float &min, float &max) const; // Air absorption void setAirAbsorption(float amount); float getAirAbsorption() const { return airAbsorption_; } // Filters bool setFilter(const FilterSettings &settings); bool getFilter(FilterSettings &settings) const; void clearFilter(); bool hasFilter() const { return hasFilter_; } // Check if spatialization is enabled bool isSpatial() const { return spatial_; } private: void initFilterNodes(); void updateFilter(); void applyFilterToSound(); Audio *audioModule_; ma_sound *sound_; ma_audio_buffer *buffer_; ma_audio_buffer_config *buffer_config_; float *pcm_data_; unsigned long long frame_count_; // Basic properties float pitch_; float volume_; bool looping_; float duration_; int channels_; int sampleRate_; SourceType type_; // 3D spatial properties bool spatial_; float posX_, posY_, posZ_; float velX_, velY_, velZ_; float dirX_, dirY_, dirZ_; float coneInnerAngle_, coneOuterAngle_, coneOuterVolume_; bool relative_; float refDistance_, maxDistance_; float rolloff_; float dopplerFactor_; float minVolume_, maxVolume_; float airAbsorption_; // Filter bool hasFilter_; FilterSettings filterSettings_; ma_lpf_node *lpfNode_; ma_hpf_node *hpfNode_; ma_bpf_node *bpfNode_; }; // Audio module class Audio { public: Audio(Engine *engine); ~Audio(); // Initialize/shutdown audio engine bool init(); void shutdown(); // Get audio engine ma_engine *getEngine() const { return engine_audio_; } // Master volume void setVolume(float volume); float getVolume() const { return masterVolume_; } // Source tracking void registerSource(AudioSource *source); void unregisterSource(AudioSource *source); int getActiveSourceCount() const; const std::vector<AudioSource *> &getSources() const { return sources_; } // Global playback control void pause(); // Pause all sources, returns list of paused sources void stop(); // Stop all sources void play(); // Resume all paused sources (not typical Love2D behavior, but useful) // Listener (3D audio) void setListenerPosition(float x, float y, float z); void getListenerPosition(float &x, float &y, float &z) const; void setListenerVelocity(float x, float y, float z); void getListenerVelocity(float &x, float &y, float &z) const; void setListenerOrientation(float fx, float fy, float fz, float ux, float uy, float uz); void getListenerOrientation(float &fx, float &fy, float &fz, float &ux, float &uy, float &uz) const; // Distance model void setDistanceModel(DistanceModel model); DistanceModel getDistanceModel() const { return distanceModel_; } // Doppler scale void setDopplerScale(float scale); float getDopplerScale() const { return dopplerScale_; } // JavaScript bindings static void initJS(js::Context &ctx, js::Value &joy); private: Engine *engine_; ma_engine *engine_audio_; std::vector<AudioSource *> sources_; float masterVolume_; // Listener state float listenerPosX_, listenerPosY_, listenerPosZ_; float listenerVelX_, listenerVelY_, listenerVelZ_; float listenerFwdX_, listenerFwdY_, listenerFwdZ_; float listenerUpX_, listenerUpY_, listenerUpZ_; // Global settings DistanceModel distanceModel_; float dopplerScale_; }; } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/audio/audio_js.cc
C++
#include "js/js.hh" #include "audio.hh" #include "modules/sound/sound.hh" #include "engine.hh" #include "physfs.h" #include <cstdlib> #include <cstring> // Forward declaration from sound_js.cc namespace joy { namespace modules { js::ClassID getSoundDataClassID(); } } namespace joy { namespace modules { // Helper to get Audio module from JS context static Audio *getAudio(js::FunctionArgs &args) { Engine *engine = args.getContextOpaque<Engine>(); return engine ? engine->getAudioModule() : nullptr; } static js::ClassID audio_source_class_id = 0; static void audio_source_finalizer(void *opaque) { AudioSource *src = static_cast<AudioSource *>(opaque); delete src; } // Helper to get AudioSource from this value static AudioSource *getSource(js::FunctionArgs &args) { js::Value thisVal = args.thisValue(); return static_cast<AudioSource *>(js::ClassBuilder::getOpaque(thisVal, audio_source_class_id)); } // Helper to parse TimeUnit argument ("seconds" or "samples") static bool parseTimeUnit(js::FunctionArgs &args, int argIndex, bool &inSamples) { inSamples = false; if (args.length() > argIndex) { std::string unit = args.arg(argIndex).toString(args.context()); if (unit == "samples") { inSamples = true; } else if (unit != "seconds") { return false; // Invalid unit } } return true; } // Helper to parse SourceType argument ("static", "stream") static bool parseSourceType(js::FunctionArgs &args, int argIndex, bool &spatial) { spatial = false; // Default to non-spatial (stereo) if (args.length() > argIndex) { std::string type = args.arg(argIndex).toString(args.context()); // In Love2D, the type is "static" or "stream" // We use this to determine if spatial audio should be enabled // For now, we just check if it's provided } return true; } // joy.audio.newSource(filename | soundData, type?) static void js_audio_newSource(js::FunctionArgs &args) { if (args.length() < 1) { args.returnValue(js::Value::null()); return; } Audio *audio = getAudio(args); if (!audio || !audio->getEngine()) { args.returnValue(js::Value::null()); return; } js::Value arg0 = args.arg(0); // Check for optional "spatial" parameter (Joy extension) // Or second argument as type string bool spatial = false; if (args.length() >= 2) { js::Value arg1 = args.arg(1); if (arg1.isBoolean()) { spatial = arg1.toBool(); } else if (arg1.isString()) { std::string typeStr = arg1.toString(args.context()); // "static" and "stream" are Love2D types // We could also accept "spatial" as a Joy extension if (typeStr == "spatial") { spatial = true; } } } // Check if argument is a SoundData object if (arg0.isObject()) { js::ClassID soundDataClassID = getSoundDataClassID(); SoundData *soundData = static_cast<SoundData *>( js::ClassBuilder::getOpaque(arg0, soundDataClassID)); if (soundData) { // For SoundData, spatial only makes sense for mono bool useSpatial = spatial && (soundData->getChannelCount() == 1); // Create AudioSource from SoundData AudioSource *src = new AudioSource(audio); if (!src->initFromSoundData(audio->getEngine(), soundData, useSpatial)) { delete src; args.returnValue(js::Value::null()); return; } js::Value obj = js::ClassBuilder::newInstance(args.context(), audio_source_class_id); js::ClassBuilder::setOpaque(obj, src); args.returnValue(std::move(obj)); return; } } // Otherwise, treat as filename (string) std::string filename = arg0.toString(args.context()); // Read file via PhysFS PHYSFS_File *file = PHYSFS_openRead(filename.c_str()); if (!file) { args.returnValue(js::Value::null()); return; } PHYSFS_sint64 file_size = PHYSFS_fileLength(file); if (file_size < 0) { PHYSFS_close(file); args.returnValue(js::Value::null()); return; } char *file_data = static_cast<char *>(malloc(file_size)); if (!file_data) { PHYSFS_close(file); args.returnValue(js::Value::null()); return; } PHYSFS_sint64 bytes_read = PHYSFS_readBytes(file, file_data, file_size); PHYSFS_close(file); if (bytes_read != file_size) { free(file_data); args.returnValue(js::Value::null()); return; } // Create AudioSource AudioSource *src = new AudioSource(audio); if (!src->initFromMemory(audio->getEngine(), file_data, static_cast<size_t>(file_size), spatial)) { free(file_data); delete src; args.returnValue(js::Value::null()); return; } // For file sources, enable spatial only for mono if (spatial && src->getChannelCount() != 1) { // Re-create without spatial for stereo sources delete src; src = new AudioSource(audio); if (!src->initFromMemory(audio->getEngine(), file_data, static_cast<size_t>(file_size), false)) { free(file_data); delete src; args.returnValue(js::Value::null()); return; } } free(file_data); js::Value obj = js::ClassBuilder::newInstance(args.context(), audio_source_class_id); js::ClassBuilder::setOpaque(obj, src); args.returnValue(std::move(obj)); } // Audio module functions // joy.audio.getVolume() static void js_audio_getVolume(js::FunctionArgs &args) { Audio *audio = getAudio(args); args.returnValue(js::Value::number(audio ? audio->getVolume() : 1.0)); } // joy.audio.setVolume(volume) static void js_audio_setVolume(js::FunctionArgs &args) { Audio *audio = getAudio(args); if (audio && args.length() >= 1) { audio->setVolume(static_cast<float>(args.arg(0).toFloat64())); } args.returnUndefined(); } // joy.audio.getActiveSourceCount() static void js_audio_getActiveSourceCount(js::FunctionArgs &args) { Audio *audio = getAudio(args); args.returnValue(js::Value::number(audio ? audio->getActiveSourceCount() : 0)); } // joy.audio.pause() - pause all or specific sources static void js_audio_pause(js::FunctionArgs &args) { Audio *audio = getAudio(args); if (!audio) { args.returnUndefined(); return; } if (args.length() == 0) { // Pause all sources audio->pause(); } else { // Pause specific sources for (int i = 0; i < args.length(); i++) { js::Value arg = args.arg(i); if (arg.isObject()) { AudioSource *src = static_cast<AudioSource *>( js::ClassBuilder::getOpaque(arg, audio_source_class_id)); if (src) { src->pause(); } } } } args.returnUndefined(); } // joy.audio.stop() - stop all or specific sources static void js_audio_stop(js::FunctionArgs &args) { Audio *audio = getAudio(args); if (!audio) { args.returnUndefined(); return; } if (args.length() == 0) { // Stop all sources audio->stop(); } else { // Stop specific sources for (int i = 0; i < args.length(); i++) { js::Value arg = args.arg(i); if (arg.isObject()) { AudioSource *src = static_cast<AudioSource *>( js::ClassBuilder::getOpaque(arg, audio_source_class_id)); if (src) { src->stop(); } } } } args.returnUndefined(); } // joy.audio.play(source) - play specific source(s) static void js_audio_play(js::FunctionArgs &args) { if (args.length() == 0) { args.returnUndefined(); return; } for (int i = 0; i < args.length(); i++) { js::Value arg = args.arg(i); if (arg.isObject()) { AudioSource *src = static_cast<AudioSource *>( js::ClassBuilder::getOpaque(arg, audio_source_class_id)); if (src) { src->play(); } } } args.returnUndefined(); } // Listener functions // joy.audio.getPosition() static void js_audio_getPosition(js::FunctionArgs &args) { Audio *audio = getAudio(args); if (!audio) { args.returnUndefined(); return; } float x, y, z; audio->getListenerPosition(x, y, z); js::Value result = js::Value::array(args.context()); result.setProperty(args.context(), 0u, js::Value::number(x)); result.setProperty(args.context(), 1u, js::Value::number(y)); result.setProperty(args.context(), 2u, js::Value::number(z)); args.returnValue(std::move(result)); } // joy.audio.setPosition(x, y, z) static void js_audio_setPosition(js::FunctionArgs &args) { Audio *audio = getAudio(args); if (audio && args.length() >= 3) { float x = static_cast<float>(args.arg(0).toFloat64()); float y = static_cast<float>(args.arg(1).toFloat64()); float z = static_cast<float>(args.arg(2).toFloat64()); audio->setListenerPosition(x, y, z); } args.returnUndefined(); } // joy.audio.getVelocity() static void js_audio_getVelocity(js::FunctionArgs &args) { Audio *audio = getAudio(args); if (!audio) { args.returnUndefined(); return; } float x, y, z; audio->getListenerVelocity(x, y, z); js::Value result = js::Value::array(args.context()); result.setProperty(args.context(), 0u, js::Value::number(x)); result.setProperty(args.context(), 1u, js::Value::number(y)); result.setProperty(args.context(), 2u, js::Value::number(z)); args.returnValue(std::move(result)); } // joy.audio.setVelocity(x, y, z) static void js_audio_setVelocity(js::FunctionArgs &args) { Audio *audio = getAudio(args); if (audio && args.length() >= 3) { float x = static_cast<float>(args.arg(0).toFloat64()); float y = static_cast<float>(args.arg(1).toFloat64()); float z = static_cast<float>(args.arg(2).toFloat64()); audio->setListenerVelocity(x, y, z); } args.returnUndefined(); } // joy.audio.getOrientation() static void js_audio_getOrientation(js::FunctionArgs &args) { Audio *audio = getAudio(args); if (!audio) { args.returnUndefined(); return; } float fx, fy, fz, ux, uy, uz; audio->getListenerOrientation(fx, fy, fz, ux, uy, uz); js::Value result = js::Value::array(args.context()); result.setProperty(args.context(), 0u, js::Value::number(fx)); result.setProperty(args.context(), 1u, js::Value::number(fy)); result.setProperty(args.context(), 2u, js::Value::number(fz)); result.setProperty(args.context(), 3u, js::Value::number(ux)); result.setProperty(args.context(), 4u, js::Value::number(uy)); result.setProperty(args.context(), 5u, js::Value::number(uz)); args.returnValue(std::move(result)); } // joy.audio.setOrientation(fx, fy, fz, ux, uy, uz) static void js_audio_setOrientation(js::FunctionArgs &args) { Audio *audio = getAudio(args); if (audio && args.length() >= 6) { float fx = static_cast<float>(args.arg(0).toFloat64()); float fy = static_cast<float>(args.arg(1).toFloat64()); float fz = static_cast<float>(args.arg(2).toFloat64()); float ux = static_cast<float>(args.arg(3).toFloat64()); float uy = static_cast<float>(args.arg(4).toFloat64()); float uz = static_cast<float>(args.arg(5).toFloat64()); audio->setListenerOrientation(fx, fy, fz, ux, uy, uz); } args.returnUndefined(); } // joy.audio.getDistanceModel() static void js_audio_getDistanceModel(js::FunctionArgs &args) { Audio *audio = getAudio(args); if (!audio) { args.returnValue(js::Value::string(args.context(), "inverseclamped")); return; } const char *model; switch (audio->getDistanceModel()) { case DistanceModel::None: model = "none"; break; case DistanceModel::Inverse: model = "inverse"; break; case DistanceModel::InverseClamped: model = "inverseclamped"; break; case DistanceModel::Linear: model = "linear"; break; case DistanceModel::LinearClamped: model = "linearclamped"; break; case DistanceModel::Exponent: model = "exponent"; break; case DistanceModel::ExponentClamped: model = "exponentclamped"; break; default: model = "inverseclamped"; break; } args.returnValue(js::Value::string(args.context(), model)); } // joy.audio.setDistanceModel(model) static void js_audio_setDistanceModel(js::FunctionArgs &args) { Audio *audio = getAudio(args); if (audio && args.length() >= 1) { std::string modelStr = args.arg(0).toString(args.context()); DistanceModel model = DistanceModel::InverseClamped; if (modelStr == "none") model = DistanceModel::None; else if (modelStr == "inverse") model = DistanceModel::Inverse; else if (modelStr == "inverseclamped") model = DistanceModel::InverseClamped; else if (modelStr == "linear") model = DistanceModel::Linear; else if (modelStr == "linearclamped") model = DistanceModel::LinearClamped; else if (modelStr == "exponent") model = DistanceModel::Exponent; else if (modelStr == "exponentclamped") model = DistanceModel::ExponentClamped; audio->setDistanceModel(model); } args.returnUndefined(); } // joy.audio.getDopplerScale() static void js_audio_getDopplerScale(js::FunctionArgs &args) { Audio *audio = getAudio(args); args.returnValue(js::Value::number(audio ? audio->getDopplerScale() : 1.0)); } // joy.audio.setDopplerScale(scale) static void js_audio_setDopplerScale(js::FunctionArgs &args) { Audio *audio = getAudio(args); if (audio && args.length() >= 1) { audio->setDopplerScale(static_cast<float>(args.arg(0).toFloat64())); } args.returnUndefined(); } // Source methods // source:play() static void js_source_play(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src) src->play(); args.returnUndefined(); } // source:stop() static void js_source_stop(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src) src->stop(); args.returnUndefined(); } // source:pause() static void js_source_pause(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src) src->pause(); args.returnUndefined(); } // source:isPlaying() static void js_source_isPlaying(js::FunctionArgs &args) { AudioSource *src = getSource(args); args.returnValue(js::Value::boolean(src && src->isPlaying())); } // source:setVolume(volume) static void js_source_setVolume(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src && args.length() >= 1) { double vol = args.arg(0).toFloat64(); src->setVolume(static_cast<float>(vol)); } args.returnUndefined(); } // source:getVolume() static void js_source_getVolume(js::FunctionArgs &args) { AudioSource *src = getSource(args); args.returnValue(js::Value::number(src ? src->getVolume() : 1.0)); } // source:setPitch(pitch) static void js_source_setPitch(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src && args.length() >= 1) { double pitch = args.arg(0).toFloat64(); src->setPitch(static_cast<float>(pitch)); } args.returnUndefined(); } // source:getPitch() static void js_source_getPitch(js::FunctionArgs &args) { AudioSource *src = getSource(args); args.returnValue(js::Value::number(src ? src->getPitch() : 1.0)); } // source:setLooping(looping) static void js_source_setLooping(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src && args.length() >= 1) { src->setLooping(args.arg(0).toBool()); } args.returnUndefined(); } // source:isLooping() static void js_source_isLooping(js::FunctionArgs &args) { AudioSource *src = getSource(args); args.returnValue(js::Value::boolean(src && src->isLooping())); } // source:seek(position, unit?) static void js_source_seek(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src && args.length() >= 1) { double pos = args.arg(0).toFloat64(); bool inSamples = false; parseTimeUnit(args, 1, inSamples); src->seek(static_cast<float>(pos), inSamples); } args.returnUndefined(); } // source:tell(unit?) static void js_source_tell(js::FunctionArgs &args) { AudioSource *src = getSource(args); bool inSamples = false; parseTimeUnit(args, 0, inSamples); args.returnValue(js::Value::number(src ? src->tell(inSamples) : 0.0)); } // source:getDuration(unit?) static void js_source_getDuration(js::FunctionArgs &args) { AudioSource *src = getSource(args); bool inSamples = false; parseTimeUnit(args, 0, inSamples); args.returnValue(js::Value::number(src ? src->getDuration(inSamples) : 0.0)); } // source:clone() static void js_source_clone(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (!src) { args.returnValue(js::Value::null()); return; } AudioSource *cloned = src->clone(); if (!cloned) { args.returnValue(js::Value::null()); return; } js::Value obj = js::ClassBuilder::newInstance(args.context(), audio_source_class_id); js::ClassBuilder::setOpaque(obj, cloned); args.returnValue(std::move(obj)); } // source:getChannelCount() static void js_source_getChannelCount(js::FunctionArgs &args) { AudioSource *src = getSource(args); args.returnValue(js::Value::number(src ? src->getChannelCount() : 0)); } // source:getType() static void js_source_getType(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (!src) { args.returnValue(js::Value::string(args.context(), "static")); return; } const char *type; switch (src->getType()) { case SourceType::Static: type = "static"; break; case SourceType::Stream: type = "stream"; break; case SourceType::Queue: type = "queue"; break; default: type = "static"; break; } args.returnValue(js::Value::string(args.context(), type)); } // 3D Spatial Audio methods // source:setPosition(x, y, z) static void js_source_setPosition(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src && args.length() >= 3) { float x = static_cast<float>(args.arg(0).toFloat64()); float y = static_cast<float>(args.arg(1).toFloat64()); float z = static_cast<float>(args.arg(2).toFloat64()); src->setPosition(x, y, z); } args.returnUndefined(); } // source:getPosition() static void js_source_getPosition(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (!src) { args.returnUndefined(); return; } float x, y, z; src->getPosition(x, y, z); js::Value result = js::Value::array(args.context()); result.setProperty(args.context(), 0u, js::Value::number(x)); result.setProperty(args.context(), 1u, js::Value::number(y)); result.setProperty(args.context(), 2u, js::Value::number(z)); args.returnValue(std::move(result)); } // source:setVelocity(x, y, z) static void js_source_setVelocity(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src && args.length() >= 3) { float x = static_cast<float>(args.arg(0).toFloat64()); float y = static_cast<float>(args.arg(1).toFloat64()); float z = static_cast<float>(args.arg(2).toFloat64()); src->setVelocity(x, y, z); } args.returnUndefined(); } // source:getVelocity() static void js_source_getVelocity(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (!src) { args.returnUndefined(); return; } float x, y, z; src->getVelocity(x, y, z); js::Value result = js::Value::array(args.context()); result.setProperty(args.context(), 0u, js::Value::number(x)); result.setProperty(args.context(), 1u, js::Value::number(y)); result.setProperty(args.context(), 2u, js::Value::number(z)); args.returnValue(std::move(result)); } // source:setDirection(x, y, z) static void js_source_setDirection(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src && args.length() >= 3) { float x = static_cast<float>(args.arg(0).toFloat64()); float y = static_cast<float>(args.arg(1).toFloat64()); float z = static_cast<float>(args.arg(2).toFloat64()); src->setDirection(x, y, z); } args.returnUndefined(); } // source:getDirection() static void js_source_getDirection(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (!src) { args.returnUndefined(); return; } float x, y, z; src->getDirection(x, y, z); js::Value result = js::Value::array(args.context()); result.setProperty(args.context(), 0u, js::Value::number(x)); result.setProperty(args.context(), 1u, js::Value::number(y)); result.setProperty(args.context(), 2u, js::Value::number(z)); args.returnValue(std::move(result)); } // source:setCone(innerAngle, outerAngle, outerVolume?) static void js_source_setCone(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src && args.length() >= 2) { float innerAngle = static_cast<float>(args.arg(0).toFloat64()); float outerAngle = static_cast<float>(args.arg(1).toFloat64()); float outerVolume = 0.0f; if (args.length() >= 3) { outerVolume = static_cast<float>(args.arg(2).toFloat64()); } src->setCone(innerAngle, outerAngle, outerVolume); } args.returnUndefined(); } // source:getCone() static void js_source_getCone(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (!src) { args.returnUndefined(); return; } float innerAngle, outerAngle, outerVolume; src->getCone(innerAngle, outerAngle, outerVolume); js::Value result = js::Value::array(args.context()); result.setProperty(args.context(), 0u, js::Value::number(innerAngle)); result.setProperty(args.context(), 1u, js::Value::number(outerAngle)); result.setProperty(args.context(), 2u, js::Value::number(outerVolume)); args.returnValue(std::move(result)); } // source:setRelative(relative) static void js_source_setRelative(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src && args.length() >= 1) { src->setRelative(args.arg(0).toBool()); } args.returnUndefined(); } // source:isRelative() static void js_source_isRelative(js::FunctionArgs &args) { AudioSource *src = getSource(args); args.returnValue(js::Value::boolean(src && src->isRelative())); } // source:setAttenuationDistances(ref, max) static void js_source_setAttenuationDistances(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src && args.length() >= 2) { float ref = static_cast<float>(args.arg(0).toFloat64()); float max = static_cast<float>(args.arg(1).toFloat64()); src->setAttenuationDistances(ref, max); } args.returnUndefined(); } // source:getAttenuationDistances() static void js_source_getAttenuationDistances(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (!src) { args.returnUndefined(); return; } float ref, max; src->getAttenuationDistances(ref, max); js::Value result = js::Value::array(args.context()); result.setProperty(args.context(), 0u, js::Value::number(ref)); result.setProperty(args.context(), 1u, js::Value::number(max)); args.returnValue(std::move(result)); } // source:setRolloff(rolloff) static void js_source_setRolloff(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src && args.length() >= 1) { src->setRolloff(static_cast<float>(args.arg(0).toFloat64())); } args.returnUndefined(); } // source:getRolloff() static void js_source_getRolloff(js::FunctionArgs &args) { AudioSource *src = getSource(args); args.returnValue(js::Value::number(src ? src->getRolloff() : 1.0)); } // source:setVolumeLimits(min, max) static void js_source_setVolumeLimits(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src && args.length() >= 2) { float min = static_cast<float>(args.arg(0).toFloat64()); float max = static_cast<float>(args.arg(1).toFloat64()); src->setVolumeLimits(min, max); } args.returnUndefined(); } // source:getVolumeLimits() static void js_source_getVolumeLimits(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (!src) { args.returnUndefined(); return; } float min, max; src->getVolumeLimits(min, max); js::Value result = js::Value::array(args.context()); result.setProperty(args.context(), 0u, js::Value::number(min)); result.setProperty(args.context(), 1u, js::Value::number(max)); args.returnValue(std::move(result)); } // source:setAirAbsorption(amount) static void js_source_setAirAbsorption(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (src && args.length() >= 1) { src->setAirAbsorption(static_cast<float>(args.arg(0).toFloat64())); } args.returnUndefined(); } // source:getAirAbsorption() static void js_source_getAirAbsorption(js::FunctionArgs &args) { AudioSource *src = getSource(args); args.returnValue(js::Value::number(src ? src->getAirAbsorption() : 0.0)); } // Filter methods // source:setFilter(settings) or source:setFilter() to clear static void js_source_setFilter(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (!src) { args.returnValue(js::Value::boolean(false)); return; } if (args.length() == 0 || args.arg(0).isUndefined() || args.arg(0).isNull()) { // Clear filter src->clearFilter(); args.returnValue(js::Value::boolean(true)); return; } js::Value settings = args.arg(0); if (!settings.isObject()) { args.returnValue(js::Value::boolean(false)); return; } FilterSettings fs; // Parse type js::Value typeVal = settings.getProperty(args.context(), "type"); if (!typeVal.isUndefined()) { std::string typeStr = typeVal.toString(args.context()); if (typeStr == "lowpass") fs.type = FilterType::LowPass; else if (typeStr == "highpass") fs.type = FilterType::HighPass; else if (typeStr == "bandpass") fs.type = FilterType::BandPass; } // Parse volume js::Value volumeVal = settings.getProperty(args.context(), "volume"); if (!volumeVal.isUndefined()) { fs.volume = static_cast<float>(volumeVal.toFloat64()); } // Parse highgain js::Value highgainVal = settings.getProperty(args.context(), "highgain"); if (!highgainVal.isUndefined()) { fs.highGain = static_cast<float>(highgainVal.toFloat64()); } // Parse lowgain js::Value lowgainVal = settings.getProperty(args.context(), "lowgain"); if (!lowgainVal.isUndefined()) { fs.lowGain = static_cast<float>(lowgainVal.toFloat64()); } args.returnValue(js::Value::boolean(src->setFilter(fs))); } // source:getFilter() static void js_source_getFilter(js::FunctionArgs &args) { AudioSource *src = getSource(args); if (!src || !src->hasFilter()) { args.returnValue(js::Value::null()); return; } FilterSettings fs; if (!src->getFilter(fs)) { args.returnValue(js::Value::null()); return; } js::Value result = js::Value::object(args.context()); const char *typeStr; switch (fs.type) { case FilterType::LowPass: typeStr = "lowpass"; break; case FilterType::HighPass: typeStr = "highpass"; break; case FilterType::BandPass: typeStr = "bandpass"; break; default: typeStr = "lowpass"; break; } result.setProperty(args.context(), "type", js::Value::string(args.context(), typeStr)); result.setProperty(args.context(), "volume", js::Value::number(fs.volume)); result.setProperty(args.context(), "highgain", js::Value::number(fs.highGain)); result.setProperty(args.context(), "lowgain", js::Value::number(fs.lowGain)); args.returnValue(std::move(result)); } void Audio::initJS(js::Context &ctx, js::Value &joy) { // Register AudioSource class js::ClassDef sourceDef; sourceDef.name = "AudioSource"; sourceDef.finalizer = audio_source_finalizer; audio_source_class_id = js::ClassBuilder::registerClass(ctx, sourceDef); // Create prototype with methods js::Value proto = js::ModuleBuilder(ctx, "__audio_source_proto__") // Basic playback .function("play", js_source_play, 0) .function("stop", js_source_stop, 0) .function("pause", js_source_pause, 0) .function("isPlaying", js_source_isPlaying, 0) // Volume/pitch .function("setVolume", js_source_setVolume, 1) .function("getVolume", js_source_getVolume, 0) .function("setPitch", js_source_setPitch, 1) .function("getPitch", js_source_getPitch, 0) // Looping .function("setLooping", js_source_setLooping, 1) .function("isLooping", js_source_isLooping, 0) // Seek/tell/duration .function("seek", js_source_seek, 2) .function("tell", js_source_tell, 1) .function("getDuration", js_source_getDuration, 1) // Clone and info .function("clone", js_source_clone, 0) .function("getChannelCount", js_source_getChannelCount, 0) .function("getType", js_source_getType, 0) // 3D Position/velocity/direction .function("setPosition", js_source_setPosition, 3) .function("getPosition", js_source_getPosition, 0) .function("setVelocity", js_source_setVelocity, 3) .function("getVelocity", js_source_getVelocity, 0) .function("setDirection", js_source_setDirection, 3) .function("getDirection", js_source_getDirection, 0) // Cone .function("setCone", js_source_setCone, 3) .function("getCone", js_source_getCone, 0) // Relative positioning .function("setRelative", js_source_setRelative, 1) .function("isRelative", js_source_isRelative, 0) // Attenuation .function("setAttenuationDistances", js_source_setAttenuationDistances, 2) .function("getAttenuationDistances", js_source_getAttenuationDistances, 0) .function("setRolloff", js_source_setRolloff, 1) .function("getRolloff", js_source_getRolloff, 0) // Volume limits .function("setVolumeLimits", js_source_setVolumeLimits, 2) .function("getVolumeLimits", js_source_getVolumeLimits, 0) // Air absorption .function("setAirAbsorption", js_source_setAirAbsorption, 1) .function("getAirAbsorption", js_source_getAirAbsorption, 0) // Filters .function("setFilter", js_source_setFilter, 1) .function("getFilter", js_source_getFilter, 0) .build(); js::ClassBuilder::setPrototype(ctx, audio_source_class_id, proto); // Create audio namespace js::ModuleBuilder(ctx, "audio") // Source creation .function("newSource", js_audio_newSource, 2) // Master volume .function("getVolume", js_audio_getVolume, 0) .function("setVolume", js_audio_setVolume, 1) // Source tracking .function("getActiveSourceCount", js_audio_getActiveSourceCount, 0) // Global playback control .function("pause", js_audio_pause, 0) .function("stop", js_audio_stop, 0) .function("play", js_audio_play, 1) // Listener position/velocity/orientation .function("getPosition", js_audio_getPosition, 0) .function("setPosition", js_audio_setPosition, 3) .function("getVelocity", js_audio_getVelocity, 0) .function("setVelocity", js_audio_setVelocity, 3) .function("getOrientation", js_audio_getOrientation, 0) .function("setOrientation", js_audio_setOrientation, 6) // Distance model .function("getDistanceModel", js_audio_getDistanceModel, 0) .function("setDistanceModel", js_audio_setDistanceModel, 1) // Doppler .function("getDopplerScale", js_audio_getDopplerScale, 0) .function("setDopplerScale", js_audio_setDopplerScale, 1) .attachTo(joy); } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/data/data.cc
C++
#include "data.hh" #include "miniz.h" #include <cstring> #include <cstdlib> #include <stdexcept> #include <algorithm> #include <sstream> #include <iomanip> namespace joy { namespace modules { // ============================================================================ // Hash implementations (MD5, SHA1, SHA2) // ============================================================================ // MD5 implementation namespace { struct MD5Context { uint32_t state[4]; uint32_t count[2]; uint8_t buffer[64]; }; static void md5_init(MD5Context *ctx) { ctx->count[0] = ctx->count[1] = 0; ctx->state[0] = 0x67452301; ctx->state[1] = 0xefcdab89; ctx->state[2] = 0x98badcfe; ctx->state[3] = 0x10325476; } #define MD5_F1(x, y, z) (z ^ (x & (y ^ z))) #define MD5_F2(x, y, z) MD5_F1(z, x, y) #define MD5_F3(x, y, z) (x ^ y ^ z) #define MD5_F4(x, y, z) (y ^ (x | ~z)) #define MD5_STEP(f, a, b, c, d, x, t, s) \ (a) += f((b), (c), (d)) + (x) + (t); \ (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \ (a) += (b); static void md5_transform(uint32_t *state, const uint8_t *block) { uint32_t a = state[0], b = state[1], c = state[2], d = state[3]; uint32_t x[16]; for (int i = 0; i < 16; i++) { x[i] = (uint32_t)block[i * 4] | ((uint32_t)block[i * 4 + 1] << 8) | ((uint32_t)block[i * 4 + 2] << 16) | ((uint32_t)block[i * 4 + 3] << 24); } MD5_STEP(MD5_F1, a, b, c, d, x[0], 0xd76aa478, 7) MD5_STEP(MD5_F1, d, a, b, c, x[1], 0xe8c7b756, 12) MD5_STEP(MD5_F1, c, d, a, b, x[2], 0x242070db, 17) MD5_STEP(MD5_F1, b, c, d, a, x[3], 0xc1bdceee, 22) MD5_STEP(MD5_F1, a, b, c, d, x[4], 0xf57c0faf, 7) MD5_STEP(MD5_F1, d, a, b, c, x[5], 0x4787c62a, 12) MD5_STEP(MD5_F1, c, d, a, b, x[6], 0xa8304613, 17) MD5_STEP(MD5_F1, b, c, d, a, x[7], 0xfd469501, 22) MD5_STEP(MD5_F1, a, b, c, d, x[8], 0x698098d8, 7) MD5_STEP(MD5_F1, d, a, b, c, x[9], 0x8b44f7af, 12) MD5_STEP(MD5_F1, c, d, a, b, x[10], 0xffff5bb1, 17) MD5_STEP(MD5_F1, b, c, d, a, x[11], 0x895cd7be, 22) MD5_STEP(MD5_F1, a, b, c, d, x[12], 0x6b901122, 7) MD5_STEP(MD5_F1, d, a, b, c, x[13], 0xfd987193, 12) MD5_STEP(MD5_F1, c, d, a, b, x[14], 0xa679438e, 17) MD5_STEP(MD5_F1, b, c, d, a, x[15], 0x49b40821, 22) MD5_STEP(MD5_F2, a, b, c, d, x[1], 0xf61e2562, 5) MD5_STEP(MD5_F2, d, a, b, c, x[6], 0xc040b340, 9) MD5_STEP(MD5_F2, c, d, a, b, x[11], 0x265e5a51, 14) MD5_STEP(MD5_F2, b, c, d, a, x[0], 0xe9b6c7aa, 20) MD5_STEP(MD5_F2, a, b, c, d, x[5], 0xd62f105d, 5) MD5_STEP(MD5_F2, d, a, b, c, x[10], 0x02441453, 9) MD5_STEP(MD5_F2, c, d, a, b, x[15], 0xd8a1e681, 14) MD5_STEP(MD5_F2, b, c, d, a, x[4], 0xe7d3fbc8, 20) MD5_STEP(MD5_F2, a, b, c, d, x[9], 0x21e1cde6, 5) MD5_STEP(MD5_F2, d, a, b, c, x[14], 0xc33707d6, 9) MD5_STEP(MD5_F2, c, d, a, b, x[3], 0xf4d50d87, 14) MD5_STEP(MD5_F2, b, c, d, a, x[8], 0x455a14ed, 20) MD5_STEP(MD5_F2, a, b, c, d, x[13], 0xa9e3e905, 5) MD5_STEP(MD5_F2, d, a, b, c, x[2], 0xfcefa3f8, 9) MD5_STEP(MD5_F2, c, d, a, b, x[7], 0x676f02d9, 14) MD5_STEP(MD5_F2, b, c, d, a, x[12], 0x8d2a4c8a, 20) MD5_STEP(MD5_F3, a, b, c, d, x[5], 0xfffa3942, 4) MD5_STEP(MD5_F3, d, a, b, c, x[8], 0x8771f681, 11) MD5_STEP(MD5_F3, c, d, a, b, x[11], 0x6d9d6122, 16) MD5_STEP(MD5_F3, b, c, d, a, x[14], 0xfde5380c, 23) MD5_STEP(MD5_F3, a, b, c, d, x[1], 0xa4beea44, 4) MD5_STEP(MD5_F3, d, a, b, c, x[4], 0x4bdecfa9, 11) MD5_STEP(MD5_F3, c, d, a, b, x[7], 0xf6bb4b60, 16) MD5_STEP(MD5_F3, b, c, d, a, x[10], 0xbebfbc70, 23) MD5_STEP(MD5_F3, a, b, c, d, x[13], 0x289b7ec6, 4) MD5_STEP(MD5_F3, d, a, b, c, x[0], 0xeaa127fa, 11) MD5_STEP(MD5_F3, c, d, a, b, x[3], 0xd4ef3085, 16) MD5_STEP(MD5_F3, b, c, d, a, x[6], 0x04881d05, 23) MD5_STEP(MD5_F3, a, b, c, d, x[9], 0xd9d4d039, 4) MD5_STEP(MD5_F3, d, a, b, c, x[12], 0xe6db99e5, 11) MD5_STEP(MD5_F3, c, d, a, b, x[15], 0x1fa27cf8, 16) MD5_STEP(MD5_F3, b, c, d, a, x[2], 0xc4ac5665, 23) MD5_STEP(MD5_F4, a, b, c, d, x[0], 0xf4292244, 6) MD5_STEP(MD5_F4, d, a, b, c, x[7], 0x432aff97, 10) MD5_STEP(MD5_F4, c, d, a, b, x[14], 0xab9423a7, 15) MD5_STEP(MD5_F4, b, c, d, a, x[5], 0xfc93a039, 21) MD5_STEP(MD5_F4, a, b, c, d, x[12], 0x655b59c3, 6) MD5_STEP(MD5_F4, d, a, b, c, x[3], 0x8f0ccc92, 10) MD5_STEP(MD5_F4, c, d, a, b, x[10], 0xffeff47d, 15) MD5_STEP(MD5_F4, b, c, d, a, x[1], 0x85845dd1, 21) MD5_STEP(MD5_F4, a, b, c, d, x[8], 0x6fa87e4f, 6) MD5_STEP(MD5_F4, d, a, b, c, x[15], 0xfe2ce6e0, 10) MD5_STEP(MD5_F4, c, d, a, b, x[6], 0xa3014314, 15) MD5_STEP(MD5_F4, b, c, d, a, x[13], 0x4e0811a1, 21) MD5_STEP(MD5_F4, a, b, c, d, x[4], 0xf7537e82, 6) MD5_STEP(MD5_F4, d, a, b, c, x[11], 0xbd3af235, 10) MD5_STEP(MD5_F4, c, d, a, b, x[2], 0x2ad7d2bb, 15) MD5_STEP(MD5_F4, b, c, d, a, x[9], 0xeb86d391, 21) state[0] += a; state[1] += b; state[2] += c; state[3] += d; } static void md5_update(MD5Context *ctx, const uint8_t *data, size_t len) { size_t index = ctx->count[0] / 8 % 64; if ((ctx->count[0] += len << 3) < (len << 3)) ctx->count[1]++; ctx->count[1] += len >> 29; size_t partLen = 64 - index; size_t i = 0; if (len >= partLen) { memcpy(&ctx->buffer[index], data, partLen); md5_transform(ctx->state, ctx->buffer); for (i = partLen; i + 63 < len; i += 64) md5_transform(ctx->state, &data[i]); index = 0; } memcpy(&ctx->buffer[index], &data[i], len - i); } static void md5_final(MD5Context *ctx, uint8_t digest[16]) { static const uint8_t padding[64] = { 0x80 }; uint8_t bits[8]; for (int i = 0; i < 4; i++) { bits[i] = ctx->count[0] >> (i * 8); bits[i + 4] = ctx->count[1] >> (i * 8); } size_t index = ctx->count[0] / 8 % 64; size_t padLen = (index < 56) ? (56 - index) : (120 - index); md5_update(ctx, padding, padLen); md5_update(ctx, bits, 8); for (int i = 0; i < 4; i++) { digest[i] = ctx->state[0] >> (i * 8); digest[i + 4] = ctx->state[1] >> (i * 8); digest[i + 8] = ctx->state[2] >> (i * 8); digest[i + 12] = ctx->state[3] >> (i * 8); } } std::string compute_md5(const void *data, size_t len) { MD5Context ctx; md5_init(&ctx); md5_update(&ctx, (const uint8_t *)data, len); uint8_t digest[16]; md5_final(&ctx, digest); return std::string((char *)digest, 16); } // SHA1 implementation struct SHA1Context { uint32_t state[5]; uint32_t count[2]; uint8_t buffer[64]; }; static void sha1_init(SHA1Context *ctx) { ctx->state[0] = 0x67452301; ctx->state[1] = 0xEFCDAB89; ctx->state[2] = 0x98BADCFE; ctx->state[3] = 0x10325476; ctx->state[4] = 0xC3D2E1F0; ctx->count[0] = ctx->count[1] = 0; } #define SHA1_ROL(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) static void sha1_transform(uint32_t state[5], const uint8_t buffer[64]) { uint32_t a, b, c, d, e; uint32_t w[80]; for (int i = 0; i < 16; i++) { w[i] = ((uint32_t)buffer[i * 4] << 24) | ((uint32_t)buffer[i * 4 + 1] << 16) | ((uint32_t)buffer[i * 4 + 2] << 8) | ((uint32_t)buffer[i * 4 + 3]); } for (int i = 16; i < 80; i++) { w[i] = SHA1_ROL(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1); } a = state[0]; b = state[1]; c = state[2]; d = state[3]; e = state[4]; for (int i = 0; i < 20; i++) { uint32_t t = SHA1_ROL(a, 5) + ((b & c) | ((~b) & d)) + e + w[i] + 0x5A827999; e = d; d = c; c = SHA1_ROL(b, 30); b = a; a = t; } for (int i = 20; i < 40; i++) { uint32_t t = SHA1_ROL(a, 5) + (b ^ c ^ d) + e + w[i] + 0x6ED9EBA1; e = d; d = c; c = SHA1_ROL(b, 30); b = a; a = t; } for (int i = 40; i < 60; i++) { uint32_t t = SHA1_ROL(a, 5) + ((b & c) | (b & d) | (c & d)) + e + w[i] + 0x8F1BBCDC; e = d; d = c; c = SHA1_ROL(b, 30); b = a; a = t; } for (int i = 60; i < 80; i++) { uint32_t t = SHA1_ROL(a, 5) + (b ^ c ^ d) + e + w[i] + 0xCA62C1D6; e = d; d = c; c = SHA1_ROL(b, 30); b = a; a = t; } state[0] += a; state[1] += b; state[2] += c; state[3] += d; state[4] += e; } static void sha1_update(SHA1Context *ctx, const uint8_t *data, size_t len) { size_t j = (ctx->count[0] >> 3) & 63; if ((ctx->count[0] += len << 3) < (len << 3)) ctx->count[1]++; ctx->count[1] += (len >> 29); size_t i = 0; if (j + len > 63) { memcpy(&ctx->buffer[j], data, (i = 64 - j)); sha1_transform(ctx->state, ctx->buffer); for (; i + 63 < len; i += 64) sha1_transform(ctx->state, &data[i]); j = 0; } memcpy(&ctx->buffer[j], &data[i], len - i); } static void sha1_final(SHA1Context *ctx, uint8_t digest[20]) { uint8_t finalcount[8]; for (int i = 0; i < 8; i++) { finalcount[i] = (uint8_t)((ctx->count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8)) & 255); } sha1_update(ctx, (uint8_t *)"\200", 1); while ((ctx->count[0] & 504) != 448) { sha1_update(ctx, (uint8_t *)"\0", 1); } sha1_update(ctx, finalcount, 8); for (int i = 0; i < 20; i++) { digest[i] = (uint8_t)((ctx->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255); } } std::string compute_sha1(const void *data, size_t len) { SHA1Context ctx; sha1_init(&ctx); sha1_update(&ctx, (const uint8_t *)data, len); uint8_t digest[20]; sha1_final(&ctx, digest); return std::string((char *)digest, 20); } // SHA2 implementation (SHA-256 base, extended for other variants) static const uint32_t sha256_k[64] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 }; #define SHA256_ROTR(x, n) (((x) >> (n)) | ((x) << (32 - (n)))) #define SHA256_CH(x, y, z) (((x) & (y)) ^ ((~(x)) & (z))) #define SHA256_MAJ(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) #define SHA256_EP0(x) (SHA256_ROTR(x, 2) ^ SHA256_ROTR(x, 13) ^ SHA256_ROTR(x, 22)) #define SHA256_EP1(x) (SHA256_ROTR(x, 6) ^ SHA256_ROTR(x, 11) ^ SHA256_ROTR(x, 25)) #define SHA256_SIG0(x) (SHA256_ROTR(x, 7) ^ SHA256_ROTR(x, 18) ^ ((x) >> 3)) #define SHA256_SIG1(x) (SHA256_ROTR(x, 17) ^ SHA256_ROTR(x, 19) ^ ((x) >> 10)) struct SHA256Context { uint32_t state[8]; uint64_t bitlen; uint8_t buffer[64]; size_t buflen; }; static void sha256_init(SHA256Context *ctx) { ctx->state[0] = 0x6a09e667; ctx->state[1] = 0xbb67ae85; ctx->state[2] = 0x3c6ef372; ctx->state[3] = 0xa54ff53a; ctx->state[4] = 0x510e527f; ctx->state[5] = 0x9b05688c; ctx->state[6] = 0x1f83d9ab; ctx->state[7] = 0x5be0cd19; ctx->bitlen = 0; ctx->buflen = 0; } static void sha224_init(SHA256Context *ctx) { ctx->state[0] = 0xc1059ed8; ctx->state[1] = 0x367cd507; ctx->state[2] = 0x3070dd17; ctx->state[3] = 0xf70e5939; ctx->state[4] = 0xffc00b31; ctx->state[5] = 0x68581511; ctx->state[6] = 0x64f98fa7; ctx->state[7] = 0xbefa4fa4; ctx->bitlen = 0; ctx->buflen = 0; } static void sha256_transform(SHA256Context *ctx) { uint32_t w[64]; uint32_t a, b, c, d, e, f, g, h; for (int i = 0; i < 16; i++) { w[i] = ((uint32_t)ctx->buffer[i * 4] << 24) | ((uint32_t)ctx->buffer[i * 4 + 1] << 16) | ((uint32_t)ctx->buffer[i * 4 + 2] << 8) | ((uint32_t)ctx->buffer[i * 4 + 3]); } for (int i = 16; i < 64; i++) { w[i] = SHA256_SIG1(w[i - 2]) + w[i - 7] + SHA256_SIG0(w[i - 15]) + w[i - 16]; } a = ctx->state[0]; b = ctx->state[1]; c = ctx->state[2]; d = ctx->state[3]; e = ctx->state[4]; f = ctx->state[5]; g = ctx->state[6]; h = ctx->state[7]; for (int i = 0; i < 64; i++) { uint32_t t1 = h + SHA256_EP1(e) + SHA256_CH(e, f, g) + sha256_k[i] + w[i]; uint32_t t2 = SHA256_EP0(a) + SHA256_MAJ(a, b, c); h = g; g = f; f = e; e = d + t1; d = c; c = b; b = a; a = t1 + t2; } ctx->state[0] += a; ctx->state[1] += b; ctx->state[2] += c; ctx->state[3] += d; ctx->state[4] += e; ctx->state[5] += f; ctx->state[6] += g; ctx->state[7] += h; } static void sha256_update(SHA256Context *ctx, const uint8_t *data, size_t len) { for (size_t i = 0; i < len; i++) { ctx->buffer[ctx->buflen++] = data[i]; if (ctx->buflen == 64) { sha256_transform(ctx); ctx->bitlen += 512; ctx->buflen = 0; } } } static void sha256_final(SHA256Context *ctx, uint8_t *digest, size_t digest_len) { size_t i = ctx->buflen; ctx->buffer[i++] = 0x80; if (i > 56) { while (i < 64) ctx->buffer[i++] = 0; sha256_transform(ctx); i = 0; } while (i < 56) ctx->buffer[i++] = 0; ctx->bitlen += ctx->buflen * 8; ctx->buffer[63] = ctx->bitlen; ctx->buffer[62] = ctx->bitlen >> 8; ctx->buffer[61] = ctx->bitlen >> 16; ctx->buffer[60] = ctx->bitlen >> 24; ctx->buffer[59] = ctx->bitlen >> 32; ctx->buffer[58] = ctx->bitlen >> 40; ctx->buffer[57] = ctx->bitlen >> 48; ctx->buffer[56] = ctx->bitlen >> 56; sha256_transform(ctx); for (size_t j = 0; j < digest_len / 4; j++) { digest[j * 4] = (ctx->state[j] >> 24) & 0xff; digest[j * 4 + 1] = (ctx->state[j] >> 16) & 0xff; digest[j * 4 + 2] = (ctx->state[j] >> 8) & 0xff; digest[j * 4 + 3] = ctx->state[j] & 0xff; } } std::string compute_sha224(const void *data, size_t len) { SHA256Context ctx; sha224_init(&ctx); sha256_update(&ctx, (const uint8_t *)data, len); uint8_t digest[28]; sha256_final(&ctx, digest, 28); return std::string((char *)digest, 28); } std::string compute_sha256(const void *data, size_t len) { SHA256Context ctx; sha256_init(&ctx); sha256_update(&ctx, (const uint8_t *)data, len); uint8_t digest[32]; sha256_final(&ctx, digest, 32); return std::string((char *)digest, 32); } // SHA-512 implementation static const uint64_t sha512_k[80] = { 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL, 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL, 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL, 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL, 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL, 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL, 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL, 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL }; #define SHA512_ROTR(x, n) (((x) >> (n)) | ((x) << (64 - (n)))) #define SHA512_CH(x, y, z) (((x) & (y)) ^ ((~(x)) & (z))) #define SHA512_MAJ(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) #define SHA512_EP0(x) (SHA512_ROTR(x, 28) ^ SHA512_ROTR(x, 34) ^ SHA512_ROTR(x, 39)) #define SHA512_EP1(x) (SHA512_ROTR(x, 14) ^ SHA512_ROTR(x, 18) ^ SHA512_ROTR(x, 41)) #define SHA512_SIG0(x) (SHA512_ROTR(x, 1) ^ SHA512_ROTR(x, 8) ^ ((x) >> 7)) #define SHA512_SIG1(x) (SHA512_ROTR(x, 19) ^ SHA512_ROTR(x, 61) ^ ((x) >> 6)) struct SHA512Context { uint64_t state[8]; uint64_t bitlen[2]; uint8_t buffer[128]; size_t buflen; }; static void sha512_init(SHA512Context *ctx) { ctx->state[0] = 0x6a09e667f3bcc908ULL; ctx->state[1] = 0xbb67ae8584caa73bULL; ctx->state[2] = 0x3c6ef372fe94f82bULL; ctx->state[3] = 0xa54ff53a5f1d36f1ULL; ctx->state[4] = 0x510e527fade682d1ULL; ctx->state[5] = 0x9b05688c2b3e6c1fULL; ctx->state[6] = 0x1f83d9abfb41bd6bULL; ctx->state[7] = 0x5be0cd19137e2179ULL; ctx->bitlen[0] = ctx->bitlen[1] = 0; ctx->buflen = 0; } static void sha384_init(SHA512Context *ctx) { ctx->state[0] = 0xcbbb9d5dc1059ed8ULL; ctx->state[1] = 0x629a292a367cd507ULL; ctx->state[2] = 0x9159015a3070dd17ULL; ctx->state[3] = 0x152fecd8f70e5939ULL; ctx->state[4] = 0x67332667ffc00b31ULL; ctx->state[5] = 0x8eb44a8768581511ULL; ctx->state[6] = 0xdb0c2e0d64f98fa7ULL; ctx->state[7] = 0x47b5481dbefa4fa4ULL; ctx->bitlen[0] = ctx->bitlen[1] = 0; ctx->buflen = 0; } static void sha512_transform(SHA512Context *ctx) { uint64_t w[80]; uint64_t a, b, c, d, e, f, g, h; for (int i = 0; i < 16; i++) { w[i] = ((uint64_t)ctx->buffer[i * 8] << 56) | ((uint64_t)ctx->buffer[i * 8 + 1] << 48) | ((uint64_t)ctx->buffer[i * 8 + 2] << 40) | ((uint64_t)ctx->buffer[i * 8 + 3] << 32) | ((uint64_t)ctx->buffer[i * 8 + 4] << 24) | ((uint64_t)ctx->buffer[i * 8 + 5] << 16) | ((uint64_t)ctx->buffer[i * 8 + 6] << 8) | ((uint64_t)ctx->buffer[i * 8 + 7]); } for (int i = 16; i < 80; i++) { w[i] = SHA512_SIG1(w[i - 2]) + w[i - 7] + SHA512_SIG0(w[i - 15]) + w[i - 16]; } a = ctx->state[0]; b = ctx->state[1]; c = ctx->state[2]; d = ctx->state[3]; e = ctx->state[4]; f = ctx->state[5]; g = ctx->state[6]; h = ctx->state[7]; for (int i = 0; i < 80; i++) { uint64_t t1 = h + SHA512_EP1(e) + SHA512_CH(e, f, g) + sha512_k[i] + w[i]; uint64_t t2 = SHA512_EP0(a) + SHA512_MAJ(a, b, c); h = g; g = f; f = e; e = d + t1; d = c; c = b; b = a; a = t1 + t2; } ctx->state[0] += a; ctx->state[1] += b; ctx->state[2] += c; ctx->state[3] += d; ctx->state[4] += e; ctx->state[5] += f; ctx->state[6] += g; ctx->state[7] += h; } static void sha512_update(SHA512Context *ctx, const uint8_t *data, size_t len) { for (size_t i = 0; i < len; i++) { ctx->buffer[ctx->buflen++] = data[i]; if (ctx->buflen == 128) { sha512_transform(ctx); if ((ctx->bitlen[0] += 1024) < 1024) ctx->bitlen[1]++; ctx->buflen = 0; } } } static void sha512_final(SHA512Context *ctx, uint8_t *digest, size_t digest_len) { size_t i = ctx->buflen; ctx->buffer[i++] = 0x80; if (i > 112) { while (i < 128) ctx->buffer[i++] = 0; sha512_transform(ctx); i = 0; } while (i < 112) ctx->buffer[i++] = 0; uint64_t bits = ctx->bitlen[0] + ctx->buflen * 8; for (int j = 0; j < 8; j++) { ctx->buffer[127 - j] = bits >> (j * 8); ctx->buffer[119 - j] = ctx->bitlen[1] >> (j * 8); } sha512_transform(ctx); for (size_t j = 0; j < digest_len / 8; j++) { digest[j * 8] = (ctx->state[j] >> 56) & 0xff; digest[j * 8 + 1] = (ctx->state[j] >> 48) & 0xff; digest[j * 8 + 2] = (ctx->state[j] >> 40) & 0xff; digest[j * 8 + 3] = (ctx->state[j] >> 32) & 0xff; digest[j * 8 + 4] = (ctx->state[j] >> 24) & 0xff; digest[j * 8 + 5] = (ctx->state[j] >> 16) & 0xff; digest[j * 8 + 6] = (ctx->state[j] >> 8) & 0xff; digest[j * 8 + 7] = ctx->state[j] & 0xff; } } std::string compute_sha384(const void *data, size_t len) { SHA512Context ctx; sha384_init(&ctx); sha512_update(&ctx, (const uint8_t *)data, len); uint8_t digest[48]; sha512_final(&ctx, digest, 48); return std::string((char *)digest, 48); } std::string compute_sha512(const void *data, size_t len) { SHA512Context ctx; sha512_init(&ctx); sha512_update(&ctx, (const uint8_t *)data, len); uint8_t digest[64]; sha512_final(&ctx, digest, 64); return std::string((char *)digest, 64); } // ============================================================================ // Base64 encoding/decoding // ============================================================================ static const char base64_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const int base64_decode_table[256] = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63, 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, 15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 }; std::string base64_encode(const void *data, size_t len, int lineLength = 0) { const uint8_t *bytes = (const uint8_t *)data; std::string result; result.reserve((len + 2) / 3 * 4 + (lineLength > 0 ? len / lineLength : 0)); int linePos = 0; for (size_t i = 0; i < len; i += 3) { uint32_t n = (uint32_t)bytes[i] << 16; if (i + 1 < len) n |= (uint32_t)bytes[i + 1] << 8; if (i + 2 < len) n |= bytes[i + 2]; result += base64_chars[(n >> 18) & 0x3f]; result += base64_chars[(n >> 12) & 0x3f]; result += (i + 1 < len) ? base64_chars[(n >> 6) & 0x3f] : '='; result += (i + 2 < len) ? base64_chars[n & 0x3f] : '='; linePos += 4; if (lineLength > 0 && linePos >= lineLength && i + 3 < len) { result += '\n'; linePos = 0; } } return result; } std::string base64_decode(const void *data, size_t len) { const uint8_t *bytes = (const uint8_t *)data; std::string result; result.reserve(len * 3 / 4); uint32_t buf = 0; int bits = 0; for (size_t i = 0; i < len; i++) { uint8_t c = bytes[i]; if (c == '=' || c == '\n' || c == '\r' || c == ' ') continue; int val = base64_decode_table[c]; if (val < 0) continue; buf = (buf << 6) | val; bits += 6; if (bits >= 8) { bits -= 8; result += (char)((buf >> bits) & 0xff); } } return result; } // ============================================================================ // Hex encoding/decoding // ============================================================================ std::string hex_encode(const void *data, size_t len) { static const char hex_chars[] = "0123456789abcdef"; const uint8_t *bytes = (const uint8_t *)data; std::string result; result.reserve(len * 2); for (size_t i = 0; i < len; i++) { result += hex_chars[(bytes[i] >> 4) & 0xf]; result += hex_chars[bytes[i] & 0xf]; } return result; } std::string hex_decode(const void *data, size_t len) { const char *str = (const char *)data; std::string result; result.reserve(len / 2); for (size_t i = 0; i + 1 < len; i += 2) { int hi = 0, lo = 0; char c = str[i]; if (c >= '0' && c <= '9') hi = c - '0'; else if (c >= 'a' && c <= 'f') hi = c - 'a' + 10; else if (c >= 'A' && c <= 'F') hi = c - 'A' + 10; c = str[i + 1]; if (c >= '0' && c <= '9') lo = c - '0'; else if (c >= 'a' && c <= 'f') lo = c - 'a' + 10; else if (c >= 'A' && c <= 'F') lo = c - 'A' + 10; result += (char)((hi << 4) | lo); } return result; } } // anonymous namespace // ============================================================================ // Data class implementation // ============================================================================ std::string Data::getString() const { return std::string((const char *)getData(), getSize()); } // ============================================================================ // ByteData class implementation // ============================================================================ ByteData::ByteData(size_t size) : size_(size) { data_ = new uint8_t[size]; memset(data_, 0, size); } ByteData::ByteData(const void *data, size_t size) : size_(size) { data_ = new uint8_t[size]; memcpy(data_, data, size); } ByteData::ByteData(const Data *source, size_t offset, size_t size) { if (size == 0) { size = source->getSize() - offset; } if (offset + size > source->getSize()) { throw std::runtime_error("ByteData: offset + size exceeds source size"); } size_ = size; data_ = new uint8_t[size]; memcpy(data_, (const uint8_t *)source->getData() + offset, size); } ByteData::~ByteData() { delete[] data_; } Data *ByteData::clone() const { return new ByteData(data_, size_); } // ============================================================================ // DataView class implementation // ============================================================================ DataView::DataView(Data *source, size_t offset, size_t size) : source_(source), offset_(offset), size_(size) { if (offset + size > source->getSize()) { throw std::runtime_error("DataView: offset + size exceeds source size"); } } DataView::~DataView() { // DataView does not own the source data } const void *DataView::getData() const { return (const uint8_t *)source_->getData() + offset_; } void *DataView::getData() { return (uint8_t *)source_->getData() + offset_; } Data *DataView::clone() const { return new ByteData(getData(), size_); } // ============================================================================ // CompressedData class implementation // ============================================================================ CompressedData::CompressedData(const void *data, size_t size, CompressedDataFormat format) : size_(size), format_(format) { data_ = new uint8_t[size]; memcpy(data_, data, size); } CompressedData::~CompressedData() { delete[] data_; } const char *CompressedData::getFormatName() const { switch (format_) { case CompressedDataFormat::LZ4: return "lz4"; case CompressedDataFormat::ZLIB: return "zlib"; case CompressedDataFormat::GZIP: return "gzip"; case CompressedDataFormat::DEFLATE: return "deflate"; default: return "unknown"; } } Data *CompressedData::clone() const { return new CompressedData(data_, size_, format_); } // ============================================================================ // DataModule class implementation // ============================================================================ DataModule::DataModule() {} DataModule::~DataModule() {} CompressedData *DataModule::compress(const void *data, size_t size, CompressedDataFormat format, int level) { if (level < 0) level = MZ_DEFAULT_COMPRESSION; if (level > 9) level = 9; mz_ulong compressed_size = mz_compressBound(size); std::vector<uint8_t> compressed(compressed_size); int flags = 0; if (format == CompressedDataFormat::ZLIB) { flags = MZ_DEFAULT_STRATEGY; } else if (format == CompressedDataFormat::GZIP) { // Use tinfl/tdefl directly for gzip format // For simplicity, we'll use zlib format and wrap it flags = MZ_DEFAULT_STRATEGY; } else if (format == CompressedDataFormat::DEFLATE) { flags = MZ_DEFAULT_STRATEGY; } else if (format == CompressedDataFormat::LZ4) { throw std::runtime_error("LZ4 compression not yet supported"); } int result; if (format == CompressedDataFormat::DEFLATE) { // Raw deflate (no header) mz_stream stream = {}; stream.next_in = (const uint8_t *)data; stream.avail_in = size; stream.next_out = compressed.data(); stream.avail_out = compressed_size; if (mz_deflateInit2(&stream, level, MZ_DEFLATED, -MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY) != MZ_OK) { throw std::runtime_error("Failed to initialize deflate"); } result = mz_deflate(&stream, MZ_FINISH); compressed_size = stream.total_out; mz_deflateEnd(&stream); if (result != MZ_STREAM_END) { throw std::runtime_error("Deflate compression failed"); } } else if (format == CompressedDataFormat::GZIP) { throw std::runtime_error("GZIP compression not yet supported"); } else { // zlib format (default) result = mz_compress2(compressed.data(), &compressed_size, (const uint8_t *)data, size, level); if (result != MZ_OK) { throw std::runtime_error("Zlib compression failed"); } } return new CompressedData(compressed.data(), compressed_size, format); } ByteData *DataModule::decompress(CompressedData *compressed) { return decompress(compressed->getData(), compressed->getSize(), compressed->getFormat()); } ByteData *DataModule::decompress(const void *data, size_t size, CompressedDataFormat format) { if (format == CompressedDataFormat::LZ4) { throw std::runtime_error("LZ4 decompression not yet supported"); } // Start with a reasonable buffer size, grow if needed mz_ulong decompressed_size = size * 4; if (decompressed_size < 1024) decompressed_size = 1024; std::vector<uint8_t> decompressed(decompressed_size); int result; if (format == CompressedDataFormat::DEFLATE) { // Raw deflate mz_stream stream = {}; stream.next_in = (const uint8_t *)data; stream.avail_in = size; stream.next_out = decompressed.data(); stream.avail_out = decompressed_size; if (mz_inflateInit2(&stream, -MZ_DEFAULT_WINDOW_BITS) != MZ_OK) { throw std::runtime_error("Failed to initialize deflate decompression"); } while (true) { result = mz_inflate(&stream, MZ_FINISH); if (result == MZ_STREAM_END) { decompressed_size = stream.total_out; break; } else if (result == MZ_BUF_ERROR || result == MZ_OK) { // Need more output space size_t current_out = stream.total_out; decompressed.resize(decompressed.size() * 2); stream.next_out = decompressed.data() + current_out; stream.avail_out = decompressed.size() - current_out; } else { mz_inflateEnd(&stream); throw std::runtime_error("Deflate decompression failed"); } } mz_inflateEnd(&stream); } else if (format == CompressedDataFormat::GZIP) { throw std::runtime_error("GZIP decompression not yet supported"); } else { // zlib format while (true) { result = mz_uncompress(decompressed.data(), &decompressed_size, (const uint8_t *)data, size); if (result == MZ_OK) { break; } else if (result == MZ_BUF_ERROR) { decompressed_size = decompressed.size() * 2; decompressed.resize(decompressed_size); } else { throw std::runtime_error("Zlib decompression failed"); } } } return new ByteData(decompressed.data(), decompressed_size); } std::string DataModule::encode(const void *data, size_t size, EncodeFormat format, int lineLength) { switch (format) { case EncodeFormat::BASE64: return base64_encode(data, size, lineLength); case EncodeFormat::HEX: return hex_encode(data, size); default: throw std::runtime_error("Unknown encode format"); } } ByteData *DataModule::encodeToData(const void *data, size_t size, EncodeFormat format, int lineLength) { std::string encoded = encode(data, size, format, lineLength); return new ByteData(encoded.data(), encoded.size()); } std::string DataModule::decode(const void *data, size_t size, EncodeFormat format) { switch (format) { case EncodeFormat::BASE64: return base64_decode(data, size); case EncodeFormat::HEX: return hex_decode(data, size); default: throw std::runtime_error("Unknown decode format"); } } ByteData *DataModule::decodeToData(const void *data, size_t size, EncodeFormat format) { std::string decoded = decode(data, size, format); return new ByteData(decoded.data(), decoded.size()); } std::string DataModule::hash(HashFunction func, const void *data, size_t size) { switch (func) { case HashFunction::MD5: return compute_md5(data, size); case HashFunction::SHA1: return compute_sha1(data, size); case HashFunction::SHA224: return compute_sha224(data, size); case HashFunction::SHA256: return compute_sha256(data, size); case HashFunction::SHA384: return compute_sha384(data, size); case HashFunction::SHA512: return compute_sha512(data, size); default: throw std::runtime_error("Unknown hash function"); } } ByteData *DataModule::newByteData(size_t size) { return new ByteData(size); } ByteData *DataModule::newByteData(const void *data, size_t size) { return new ByteData(data, size); } ByteData *DataModule::newByteData(const Data *source, size_t offset, size_t size) { return new ByteData(source, offset, size); } DataView *DataModule::newDataView(Data *data, size_t offset, size_t size) { return new DataView(data, offset, size); } bool DataModule::parseCompressedDataFormat(const std::string &str, CompressedDataFormat &out) { if (str == "lz4") { out = CompressedDataFormat::LZ4; return true; } if (str == "zlib") { out = CompressedDataFormat::ZLIB; return true; } if (str == "gzip") { out = CompressedDataFormat::GZIP; return true; } if (str == "deflate") { out = CompressedDataFormat::DEFLATE; return true; } return false; } bool DataModule::parseHashFunction(const std::string &str, HashFunction &out) { if (str == "md5") { out = HashFunction::MD5; return true; } if (str == "sha1") { out = HashFunction::SHA1; return true; } if (str == "sha224") { out = HashFunction::SHA224; return true; } if (str == "sha256") { out = HashFunction::SHA256; return true; } if (str == "sha384") { out = HashFunction::SHA384; return true; } if (str == "sha512") { out = HashFunction::SHA512; return true; } return false; } bool DataModule::parseEncodeFormat(const std::string &str, EncodeFormat &out) { if (str == "base64") { out = EncodeFormat::BASE64; return true; } if (str == "hex") { out = EncodeFormat::HEX; return true; } return false; } bool DataModule::parseContainerType(const std::string &str, ContainerType &out) { if (str == "data") { out = ContainerType::DATA; return true; } if (str == "string") { out = ContainerType::STRING; return true; } return false; } // Pack/unpack implementations are more complex and will be added in the JS bindings // since they require interaction with JavaScript values ByteData *DataModule::pack(const std::string &format, const std::vector<std::string> &values) { // Simplified pack implementation - full Lua 5.3 compatibility would require more work std::vector<uint8_t> result; size_t valueIndex = 0; bool littleEndian = true; // Default to native (little endian on most systems) for (size_t i = 0; i < format.size(); i++) { char c = format[i]; // Endianness modifiers if (c == '<') { littleEndian = true; continue; } if (c == '>') { littleEndian = false; continue; } if (c == '=') { littleEndian = true; continue; } // Native (assume little) // Skip whitespace if (c == ' ') continue; if (valueIndex >= values.size()) break; // Handle numeric types if (c == 'b' || c == 'B') { // signed/unsigned byte int8_t val = (int8_t)std::stoi(values[valueIndex++]); result.push_back(val); } else if (c == 'h' || c == 'H') { // signed/unsigned short (2 bytes) int16_t val = (int16_t)std::stoi(values[valueIndex++]); if (littleEndian) { result.push_back(val & 0xff); result.push_back((val >> 8) & 0xff); } else { result.push_back((val >> 8) & 0xff); result.push_back(val & 0xff); } } else if (c == 'l' || c == 'L' || c == 'i' || c == 'I') { // signed/unsigned long/int (4 bytes) int32_t val = (int32_t)std::stol(values[valueIndex++]); if (littleEndian) { result.push_back(val & 0xff); result.push_back((val >> 8) & 0xff); result.push_back((val >> 16) & 0xff); result.push_back((val >> 24) & 0xff); } else { result.push_back((val >> 24) & 0xff); result.push_back((val >> 16) & 0xff); result.push_back((val >> 8) & 0xff); result.push_back(val & 0xff); } } else if (c == 'f') { // float (4 bytes) float val = std::stof(values[valueIndex++]); uint8_t *bytes = (uint8_t *)&val; if (littleEndian) { for (int j = 0; j < 4; j++) result.push_back(bytes[j]); } else { for (int j = 3; j >= 0; j--) result.push_back(bytes[j]); } } else if (c == 'd') { // double (8 bytes) double val = std::stod(values[valueIndex++]); uint8_t *bytes = (uint8_t *)&val; if (littleEndian) { for (int j = 0; j < 8; j++) result.push_back(bytes[j]); } else { for (int j = 7; j >= 0; j--) result.push_back(bytes[j]); } } else if (c == 's') { // string with size prefix const std::string &str = values[valueIndex++]; // Get size specifier (default 4 bytes) size_t sizeBytes = 4; if (i + 1 < format.size() && format[i + 1] >= '1' && format[i + 1] <= '8') { sizeBytes = format[++i] - '0'; } uint64_t len = str.size(); for (size_t j = 0; j < sizeBytes; j++) { if (littleEndian) { result.push_back((len >> (j * 8)) & 0xff); } else { result.push_back((len >> ((sizeBytes - 1 - j) * 8)) & 0xff); } } for (char ch : str) result.push_back(ch); } else if (c == 'c') { // fixed size string size_t n = 0; while (i + 1 < format.size() && format[i + 1] >= '0' && format[i + 1] <= '9') { n = n * 10 + (format[++i] - '0'); } const std::string &str = values[valueIndex++]; for (size_t j = 0; j < n; j++) { result.push_back(j < str.size() ? str[j] : 0); } } else if (c == 'z') { // null-terminated string const std::string &str = values[valueIndex++]; for (char ch : str) result.push_back(ch); result.push_back(0); } else if (c == 'x') { // padding byte result.push_back(0); } } return new ByteData(result.data(), result.size()); } std::string DataModule::packToString(const std::string &format, const std::vector<std::string> &values) { ByteData *data = pack(format, values); std::string result = data->getString(); delete data; return result; } size_t DataModule::getPackedSize(const std::string &format) { size_t size = 0; for (size_t i = 0; i < format.size(); i++) { char c = format[i]; // Skip modifiers if (c == '<' || c == '>' || c == '=' || c == ' ') continue; if (c == 'b' || c == 'B') size += 1; else if (c == 'h' || c == 'H') size += 2; else if (c == 'l' || c == 'L' || c == 'i' || c == 'I') size += 4; else if (c == 'f') size += 4; else if (c == 'd') size += 8; else if (c == 'x') size += 1; else if (c == 'c') { size_t n = 0; while (i + 1 < format.size() && format[i + 1] >= '0' && format[i + 1] <= '9') { n = n * 10 + (format[++i] - '0'); } size += n; } else if (c == 's' || c == 'z') { throw std::runtime_error("Cannot determine packed size for variable-length format"); } } return size; } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/data/data.hh
C++ Header
#pragma once #include <string> #include <vector> #include <cstdint> #include <cstddef> #include <memory> namespace js { class Context; class Value; } // namespace js namespace joy { namespace modules { // Compression format enum enum class CompressedDataFormat { LZ4, ZLIB, GZIP, DEFLATE }; // Hash function enum enum class HashFunction { MD5, SHA1, SHA224, SHA256, SHA384, SHA512 }; // Encode format enum enum class EncodeFormat { BASE64, HEX }; // Container type enum enum class ContainerType { DATA, STRING }; // Base Data class - represents arbitrary binary data class Data { public: virtual ~Data() = default; // Get raw pointer to data virtual const void *getData() const = 0; virtual void *getData() = 0; // Get size in bytes virtual size_t getSize() const = 0; // Get as string (may contain binary data) virtual std::string getString() const; // Clone the data virtual Data *clone() const = 0; }; // ByteData - concrete implementation of Data class ByteData : public Data { public: // Create empty ByteData with given size explicit ByteData(size_t size); // Create ByteData from string/buffer ByteData(const void *data, size_t size); // Create ByteData by copying from another Data object with optional offset and size ByteData(const Data *source, size_t offset = 0, size_t size = 0); ~ByteData() override; const void *getData() const override { return data_; } void *getData() override { return data_; } size_t getSize() const override { return size_; } Data *clone() const override; private: uint8_t *data_; size_t size_; }; // DataView - references a subsection of another Data object class DataView : public Data { public: DataView(Data *source, size_t offset, size_t size); ~DataView() override; const void *getData() const override; void *getData() override; size_t getSize() const override { return size_; } Data *clone() const override; private: Data *source_; size_t offset_; size_t size_; }; // CompressedData - compressed data with format info class CompressedData : public Data { public: CompressedData(const void *data, size_t size, CompressedDataFormat format); ~CompressedData() override; const void *getData() const override { return data_; } void *getData() override { return data_; } size_t getSize() const override { return size_; } CompressedDataFormat getFormat() const { return format_; } const char *getFormatName() const; Data *clone() const override; private: uint8_t *data_; size_t size_; CompressedDataFormat format_; }; // Data module class - provides static functions class DataModule { public: DataModule(); ~DataModule(); // Compression static CompressedData *compress(const void *data, size_t size, CompressedDataFormat format, int level = -1); static ByteData *decompress(CompressedData *compressed); static ByteData *decompress(const void *data, size_t size, CompressedDataFormat format); // Encoding static std::string encode(const void *data, size_t size, EncodeFormat format, int lineLength = 0); static ByteData *encodeToData(const void *data, size_t size, EncodeFormat format, int lineLength = 0); static std::string decode(const void *data, size_t size, EncodeFormat format); static ByteData *decodeToData(const void *data, size_t size, EncodeFormat format); // Hashing static std::string hash(HashFunction func, const void *data, size_t size); // Pack/Unpack (Lua 5.3 string.pack compatible) static ByteData *pack(const std::string &format, const std::vector<std::string> &values); static std::string packToString(const std::string &format, const std::vector<std::string> &values); static size_t getPackedSize(const std::string &format); // ByteData factory static ByteData *newByteData(size_t size); static ByteData *newByteData(const void *data, size_t size); static ByteData *newByteData(const Data *source, size_t offset = 0, size_t size = 0); // DataView factory static DataView *newDataView(Data *data, size_t offset, size_t size); // Parse format/container type strings static bool parseCompressedDataFormat(const std::string &str, CompressedDataFormat &out); static bool parseHashFunction(const std::string &str, HashFunction &out); static bool parseEncodeFormat(const std::string &str, EncodeFormat &out); static bool parseContainerType(const std::string &str, ContainerType &out); // Initialize JS bindings static void initJS(js::Context &ctx, js::Value &joy); }; } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/data/data_js.cc
C++
#include "js/js.hh" #include "data.hh" #include "engine.hh" #include <vector> #include <cstring> namespace joy { namespace modules { // Class IDs for JS objects static js::ClassID bytedata_class_id = 0; static js::ClassID compresseddata_class_id = 0; static js::ClassID dataview_class_id = 0; // ============================================================================ // ByteData class bindings // ============================================================================ static void bytedata_finalizer(void *opaque) { ByteData *data = static_cast<ByteData *>(opaque); delete data; } static ByteData *getByteData(js::FunctionArgs &args) { js::Value thisVal = args.thisValue(); return static_cast<ByteData *>(js::ClassBuilder::getOpaque(thisVal, bytedata_class_id)); } static void js_bytedata_getSize(js::FunctionArgs &args) { ByteData *data = getByteData(args); args.returnValue(js::Value::number(data ? static_cast<double>(data->getSize()) : 0)); } static void js_bytedata_getString(js::FunctionArgs &args) { ByteData *data = getByteData(args); if (!data) { args.returnValue(js::Value::string(args.context(), "")); return; } // Optional offset and size parameters size_t offset = 0; size_t size = data->getSize(); if (args.length() >= 1) { offset = static_cast<size_t>(args.arg(0).toFloat64()); } if (args.length() >= 2) { size = static_cast<size_t>(args.arg(1).toFloat64()); } if (offset >= data->getSize()) { args.returnValue(js::Value::string(args.context(), "")); return; } if (offset + size > data->getSize()) { size = data->getSize() - offset; } const char *ptr = (const char *)data->getData() + offset; args.returnValue(js::Value::string(args.context(), ptr, size)); } static void js_bytedata_clone(js::FunctionArgs &args) { ByteData *data = getByteData(args); if (!data) { args.returnValue(js::Value::null()); return; } ByteData *clone = static_cast<ByteData *>(data->clone()); js::Value obj = js::ClassBuilder::newInstance(args.context(), bytedata_class_id); js::ClassBuilder::setOpaque(obj, clone); args.returnValue(std::move(obj)); } // ============================================================================ // CompressedData class bindings // ============================================================================ static void compresseddata_finalizer(void *opaque) { CompressedData *data = static_cast<CompressedData *>(opaque); delete data; } static CompressedData *getCompressedData(js::FunctionArgs &args) { js::Value thisVal = args.thisValue(); return static_cast<CompressedData *>(js::ClassBuilder::getOpaque(thisVal, compresseddata_class_id)); } static void js_compresseddata_getSize(js::FunctionArgs &args) { CompressedData *data = getCompressedData(args); args.returnValue(js::Value::number(data ? static_cast<double>(data->getSize()) : 0)); } static void js_compresseddata_getString(js::FunctionArgs &args) { CompressedData *data = getCompressedData(args); if (!data) { args.returnValue(js::Value::string(args.context(), "")); return; } std::string str = data->getString(); args.returnValue(js::Value::string(args.context(), str.data(), str.size())); } static void js_compresseddata_getFormat(js::FunctionArgs &args) { CompressedData *data = getCompressedData(args); if (!data) { args.returnValue(js::Value::string(args.context(), "")); return; } args.returnValue(js::Value::string(args.context(), data->getFormatName())); } static void js_compresseddata_clone(js::FunctionArgs &args) { CompressedData *data = getCompressedData(args); if (!data) { args.returnValue(js::Value::null()); return; } CompressedData *clone = static_cast<CompressedData *>(data->clone()); js::Value obj = js::ClassBuilder::newInstance(args.context(), compresseddata_class_id); js::ClassBuilder::setOpaque(obj, clone); args.returnValue(std::move(obj)); } // ============================================================================ // DataView class bindings // ============================================================================ static void dataview_finalizer(void *opaque) { DataView *data = static_cast<DataView *>(opaque); delete data; } static DataView *getDataView(js::FunctionArgs &args) { js::Value thisVal = args.thisValue(); return static_cast<DataView *>(js::ClassBuilder::getOpaque(thisVal, dataview_class_id)); } static void js_dataview_getSize(js::FunctionArgs &args) { DataView *data = getDataView(args); args.returnValue(js::Value::number(data ? static_cast<double>(data->getSize()) : 0)); } static void js_dataview_getString(js::FunctionArgs &args) { DataView *data = getDataView(args); if (!data) { args.returnValue(js::Value::string(args.context(), "")); return; } std::string str = data->getString(); args.returnValue(js::Value::string(args.context(), str.data(), str.size())); } // ============================================================================ // Helper function to get Data from various JS objects // ============================================================================ static bool getDataFromValue(js::Context &ctx, js::Value &val, const void **outData, size_t *outSize) { // Check if it's a ByteData void *opaque = js::ClassBuilder::getOpaque(val, bytedata_class_id); if (opaque) { ByteData *data = static_cast<ByteData *>(opaque); *outData = data->getData(); *outSize = data->getSize(); return true; } // Check if it's a CompressedData opaque = js::ClassBuilder::getOpaque(val, compresseddata_class_id); if (opaque) { CompressedData *data = static_cast<CompressedData *>(opaque); *outData = data->getData(); *outSize = data->getSize(); return true; } // Check if it's a DataView opaque = js::ClassBuilder::getOpaque(val, dataview_class_id); if (opaque) { DataView *data = static_cast<DataView *>(opaque); *outData = data->getData(); *outSize = data->getSize(); return true; } // Check if it's a string if (val.isString()) { // Note: This won't work well as the string goes out of scope // The caller needs to handle this case specially return false; } return false; } // ============================================================================ // Module-level functions // ============================================================================ // joy.data.compress(container, format, data, level) static void js_data_compress(js::FunctionArgs &args) { if (args.length() < 3) { args.throwError("compress requires at least 3 arguments"); return; } std::string containerStr = args.arg(0).toString(args.context()); std::string formatStr = args.arg(1).toString(args.context()); ContainerType container; if (!DataModule::parseContainerType(containerStr, container)) { args.throwError("Invalid container type"); return; } CompressedDataFormat format; if (!DataModule::parseCompressedDataFormat(formatStr, format)) { args.throwError("Invalid compression format"); return; } int level = -1; if (args.length() >= 4) { level = args.arg(3).toInt32(); } const void *data = nullptr; size_t size = 0; std::string strData; js::Value dataArg = args.arg(2); if (dataArg.isString()) { strData = dataArg.toString(args.context()); data = strData.data(); size = strData.size(); } else if (!getDataFromValue(args.context(), dataArg, &data, &size)) { args.throwError("Invalid data argument"); return; } try { CompressedData *compressed = DataModule::compress(data, size, format, level); if (container == ContainerType::STRING) { std::string str = compressed->getString(); delete compressed; args.returnValue(js::Value::string(args.context(), str.data(), str.size())); } else { js::Value obj = js::ClassBuilder::newInstance(args.context(), compresseddata_class_id); js::ClassBuilder::setOpaque(obj, compressed); args.returnValue(std::move(obj)); } } catch (const std::exception &e) { args.throwError(e.what()); } } // joy.data.decompress(container, compressedData) or (container, format, data) static void js_data_decompress(js::FunctionArgs &args) { if (args.length() < 2) { args.throwError("decompress requires at least 2 arguments"); return; } std::string containerStr = args.arg(0).toString(args.context()); ContainerType container; if (!DataModule::parseContainerType(containerStr, container)) { args.throwError("Invalid container type"); return; } ByteData *decompressed = nullptr; try { js::Value arg1 = args.arg(1); // Check if second arg is a CompressedData object void *opaque = js::ClassBuilder::getOpaque(arg1, compresseddata_class_id); if (opaque) { CompressedData *compressed = static_cast<CompressedData *>(opaque); decompressed = DataModule::decompress(compressed); } else { // Second arg is format string, third is data if (args.length() < 3) { args.throwError("decompress requires format and data arguments"); return; } std::string formatStr = arg1.toString(args.context()); CompressedDataFormat format; if (!DataModule::parseCompressedDataFormat(formatStr, format)) { args.throwError("Invalid compression format"); return; } const void *data = nullptr; size_t size = 0; std::string strData; js::Value dataArg = args.arg(2); if (dataArg.isString()) { strData = dataArg.toString(args.context()); data = strData.data(); size = strData.size(); } else if (!getDataFromValue(args.context(), dataArg, &data, &size)) { args.throwError("Invalid data argument"); return; } decompressed = DataModule::decompress(data, size, format); } if (container == ContainerType::STRING) { std::string str = decompressed->getString(); delete decompressed; args.returnValue(js::Value::string(args.context(), str.data(), str.size())); } else { js::Value obj = js::ClassBuilder::newInstance(args.context(), bytedata_class_id); js::ClassBuilder::setOpaque(obj, decompressed); args.returnValue(std::move(obj)); } } catch (const std::exception &e) { args.throwError(e.what()); } } // joy.data.encode(container, format, data, lineLength) static void js_data_encode(js::FunctionArgs &args) { if (args.length() < 3) { args.throwError("encode requires at least 3 arguments"); return; } std::string containerStr = args.arg(0).toString(args.context()); std::string formatStr = args.arg(1).toString(args.context()); ContainerType container; if (!DataModule::parseContainerType(containerStr, container)) { args.throwError("Invalid container type"); return; } EncodeFormat format; if (!DataModule::parseEncodeFormat(formatStr, format)) { args.throwError("Invalid encode format"); return; } int lineLength = 0; if (args.length() >= 4) { lineLength = args.arg(3).toInt32(); } const void *data = nullptr; size_t size = 0; std::string strData; js::Value dataArg = args.arg(2); if (dataArg.isString()) { strData = dataArg.toString(args.context()); data = strData.data(); size = strData.size(); } else if (!getDataFromValue(args.context(), dataArg, &data, &size)) { args.throwError("Invalid data argument"); return; } try { if (container == ContainerType::STRING) { std::string encoded = DataModule::encode(data, size, format, lineLength); args.returnValue(js::Value::string(args.context(), encoded.c_str())); } else { ByteData *encoded = DataModule::encodeToData(data, size, format, lineLength); js::Value obj = js::ClassBuilder::newInstance(args.context(), bytedata_class_id); js::ClassBuilder::setOpaque(obj, encoded); args.returnValue(std::move(obj)); } } catch (const std::exception &e) { args.throwError(e.what()); } } // joy.data.decode(container, format, data) static void js_data_decode(js::FunctionArgs &args) { if (args.length() < 3) { args.throwError("decode requires 3 arguments"); return; } std::string containerStr = args.arg(0).toString(args.context()); std::string formatStr = args.arg(1).toString(args.context()); ContainerType container; if (!DataModule::parseContainerType(containerStr, container)) { args.throwError("Invalid container type"); return; } EncodeFormat format; if (!DataModule::parseEncodeFormat(formatStr, format)) { args.throwError("Invalid encode format"); return; } const void *data = nullptr; size_t size = 0; std::string strData; js::Value dataArg = args.arg(2); if (dataArg.isString()) { strData = dataArg.toString(args.context()); data = strData.data(); size = strData.size(); } else if (!getDataFromValue(args.context(), dataArg, &data, &size)) { args.throwError("Invalid data argument"); return; } try { if (container == ContainerType::STRING) { std::string decoded = DataModule::decode(data, size, format); args.returnValue(js::Value::string(args.context(), decoded.data(), decoded.size())); } else { ByteData *decoded = DataModule::decodeToData(data, size, format); js::Value obj = js::ClassBuilder::newInstance(args.context(), bytedata_class_id); js::ClassBuilder::setOpaque(obj, decoded); args.returnValue(std::move(obj)); } } catch (const std::exception &e) { args.throwError(e.what()); } } // joy.data.hash(hashFunction, data) static void js_data_hash(js::FunctionArgs &args) { if (args.length() < 2) { args.throwError("hash requires 2 arguments"); return; } std::string funcStr = args.arg(0).toString(args.context()); HashFunction func; if (!DataModule::parseHashFunction(funcStr, func)) { args.throwError("Invalid hash function"); return; } const void *data = nullptr; size_t size = 0; std::string strData; js::Value dataArg = args.arg(1); if (dataArg.isString()) { strData = dataArg.toString(args.context()); data = strData.data(); size = strData.size(); } else if (!getDataFromValue(args.context(), dataArg, &data, &size)) { args.throwError("Invalid data argument"); return; } try { std::string digest = DataModule::hash(func, data, size); args.returnValue(js::Value::string(args.context(), digest.data(), digest.size())); } catch (const std::exception &e) { args.throwError(e.what()); } } // joy.data.newByteData(size) or (string) or (data, offset, size) static void js_data_newByteData(js::FunctionArgs &args) { if (args.length() < 1) { args.throwError("newByteData requires at least 1 argument"); return; } ByteData *byteData = nullptr; try { js::Value arg0 = args.arg(0); if (arg0.isNumber()) { // Create empty ByteData with given size size_t size = static_cast<size_t>(arg0.toFloat64()); byteData = DataModule::newByteData(size); } else if (arg0.isString()) { // Create ByteData from string std::string str = arg0.toString(args.context()); byteData = DataModule::newByteData(str.data(), str.size()); } else { // Create from another Data object const void *data = nullptr; size_t dataSize = 0; if (!getDataFromValue(args.context(), arg0, &data, &dataSize)) { args.throwError("Invalid argument for newByteData"); return; } size_t offset = 0; size_t size = dataSize; if (args.length() >= 2) { offset = static_cast<size_t>(args.arg(1).toFloat64()); } if (args.length() >= 3) { size = static_cast<size_t>(args.arg(2).toFloat64()); } if (offset + size > dataSize) { args.throwError("Offset + size exceeds data bounds"); return; } byteData = DataModule::newByteData((const uint8_t *)data + offset, size); } js::Value obj = js::ClassBuilder::newInstance(args.context(), bytedata_class_id); js::ClassBuilder::setOpaque(obj, byteData); args.returnValue(std::move(obj)); } catch (const std::exception &e) { args.throwError(e.what()); } } // joy.data.newDataView(data, offset, size) static void js_data_newDataView(js::FunctionArgs &args) { if (args.length() < 3) { args.throwError("newDataView requires 3 arguments"); return; } // Note: DataView holds a reference to the source, so we need to ensure // the source outlives the view. For simplicity, we'll create a copy instead. // A proper implementation would need reference counting or weak references. js::Value dataArg = args.arg(0); size_t offset = static_cast<size_t>(args.arg(1).toFloat64()); size_t size = static_cast<size_t>(args.arg(2).toFloat64()); const void *data = nullptr; size_t dataSize = 0; if (!getDataFromValue(args.context(), dataArg, &data, &dataSize)) { args.throwError("Invalid data argument"); return; } if (offset + size > dataSize) { args.throwError("Offset + size exceeds data bounds"); return; } try { // Create a ByteData copy of the view for safety ByteData *viewData = DataModule::newByteData((const uint8_t *)data + offset, size); js::Value obj = js::ClassBuilder::newInstance(args.context(), bytedata_class_id); js::ClassBuilder::setOpaque(obj, viewData); args.returnValue(std::move(obj)); } catch (const std::exception &e) { args.throwError(e.what()); } } // joy.data.pack(container, format, v1, v2, ...) static void js_data_pack(js::FunctionArgs &args) { if (args.length() < 2) { args.throwError("pack requires at least 2 arguments"); return; } std::string containerStr = args.arg(0).toString(args.context()); std::string format = args.arg(1).toString(args.context()); ContainerType container; if (!DataModule::parseContainerType(containerStr, container)) { args.throwError("Invalid container type"); return; } std::vector<std::string> values; for (int i = 2; i < args.length(); i++) { values.push_back(args.arg(i).toString(args.context())); } try { if (container == ContainerType::STRING) { std::string packed = DataModule::packToString(format, values); args.returnValue(js::Value::string(args.context(), packed.data(), packed.size())); } else { ByteData *packed = DataModule::pack(format, values); js::Value obj = js::ClassBuilder::newInstance(args.context(), bytedata_class_id); js::ClassBuilder::setOpaque(obj, packed); args.returnValue(std::move(obj)); } } catch (const std::exception &e) { args.throwError(e.what()); } } // joy.data.unpack(format, data, pos) static void js_data_unpack(js::FunctionArgs &args) { if (args.length() < 2) { args.throwError("unpack requires at least 2 arguments"); return; } std::string format = args.arg(0).toString(args.context()); const void *data = nullptr; size_t size = 0; std::string strData; js::Value dataArg = args.arg(1); if (dataArg.isString()) { strData = dataArg.toString(args.context()); data = strData.data(); size = strData.size(); } else if (!getDataFromValue(args.context(), dataArg, &data, &size)) { args.throwError("Invalid data argument"); return; } int pos = 1; // 1-based index like Lua if (args.length() >= 3) { pos = args.arg(2).toInt32(); } // Convert to 0-based index size_t offset = 0; if (pos > 0) { offset = pos - 1; } else if (pos < 0) { offset = size + pos; } if (offset >= size) { args.throwError("Position out of bounds"); return; } const uint8_t *bytes = (const uint8_t *)data + offset; size_t remaining = size - offset; // Parse format and unpack values js::Value result = js::Value::array(args.context()); uint32_t resultIndex = 0; bool littleEndian = true; size_t readPos = 0; for (size_t i = 0; i < format.size() && readPos < remaining; i++) { char c = format[i]; if (c == '<') { littleEndian = true; continue; } if (c == '>') { littleEndian = false; continue; } if (c == '=') { littleEndian = true; continue; } if (c == ' ') continue; if (c == 'b') { if (readPos >= remaining) break; int8_t val = (int8_t)bytes[readPos++]; result.setProperty(args.context(), resultIndex++, js::Value::number(val)); } else if (c == 'B') { if (readPos >= remaining) break; uint8_t val = bytes[readPos++]; result.setProperty(args.context(), resultIndex++, js::Value::number(val)); } else if (c == 'h') { if (readPos + 2 > remaining) break; int16_t val; if (littleEndian) { val = bytes[readPos] | (bytes[readPos + 1] << 8); } else { val = (bytes[readPos] << 8) | bytes[readPos + 1]; } readPos += 2; result.setProperty(args.context(), resultIndex++, js::Value::number(val)); } else if (c == 'H') { if (readPos + 2 > remaining) break; uint16_t val; if (littleEndian) { val = bytes[readPos] | (bytes[readPos + 1] << 8); } else { val = (bytes[readPos] << 8) | bytes[readPos + 1]; } readPos += 2; result.setProperty(args.context(), resultIndex++, js::Value::number(val)); } else if (c == 'l' || c == 'i') { if (readPos + 4 > remaining) break; int32_t val; if (littleEndian) { val = bytes[readPos] | (bytes[readPos + 1] << 8) | (bytes[readPos + 2] << 16) | (bytes[readPos + 3] << 24); } else { val = (bytes[readPos] << 24) | (bytes[readPos + 1] << 16) | (bytes[readPos + 2] << 8) | bytes[readPos + 3]; } readPos += 4; result.setProperty(args.context(), resultIndex++, js::Value::number(val)); } else if (c == 'L' || c == 'I') { if (readPos + 4 > remaining) break; uint32_t val; if (littleEndian) { val = bytes[readPos] | (bytes[readPos + 1] << 8) | (bytes[readPos + 2] << 16) | (bytes[readPos + 3] << 24); } else { val = (bytes[readPos] << 24) | (bytes[readPos + 1] << 16) | (bytes[readPos + 2] << 8) | bytes[readPos + 3]; } readPos += 4; result.setProperty(args.context(), resultIndex++, js::Value::number(static_cast<double>(val))); } else if (c == 'f') { if (readPos + 4 > remaining) break; float val; uint8_t *valBytes = (uint8_t *)&val; if (littleEndian) { for (int j = 0; j < 4; j++) valBytes[j] = bytes[readPos + j]; } else { for (int j = 0; j < 4; j++) valBytes[j] = bytes[readPos + 3 - j]; } readPos += 4; result.setProperty(args.context(), resultIndex++, js::Value::number(val)); } else if (c == 'd') { if (readPos + 8 > remaining) break; double val; uint8_t *valBytes = (uint8_t *)&val; if (littleEndian) { for (int j = 0; j < 8; j++) valBytes[j] = bytes[readPos + j]; } else { for (int j = 0; j < 8; j++) valBytes[j] = bytes[readPos + 7 - j]; } readPos += 8; result.setProperty(args.context(), resultIndex++, js::Value::number(val)); } else if (c == 'c') { size_t n = 0; while (i + 1 < format.size() && format[i + 1] >= '0' && format[i + 1] <= '9') { n = n * 10 + (format[++i] - '0'); } if (readPos + n > remaining) n = remaining - readPos; std::string str((const char *)bytes + readPos, n); readPos += n; result.setProperty(args.context(), resultIndex++, js::Value::string(args.context(), str.c_str())); } else if (c == 'z') { // Null-terminated string size_t start = readPos; while (readPos < remaining && bytes[readPos] != 0) readPos++; std::string str((const char *)bytes + start, readPos - start); if (readPos < remaining) readPos++; // Skip null terminator result.setProperty(args.context(), resultIndex++, js::Value::string(args.context(), str.c_str())); } else if (c == 's') { // String with size prefix size_t sizeBytes = 4; if (i + 1 < format.size() && format[i + 1] >= '1' && format[i + 1] <= '8') { sizeBytes = format[++i] - '0'; } if (readPos + sizeBytes > remaining) break; uint64_t len = 0; for (size_t j = 0; j < sizeBytes; j++) { if (littleEndian) { len |= ((uint64_t)bytes[readPos + j]) << (j * 8); } else { len |= ((uint64_t)bytes[readPos + j]) << ((sizeBytes - 1 - j) * 8); } } readPos += sizeBytes; if (readPos + len > remaining) len = remaining - readPos; std::string str((const char *)bytes + readPos, len); readPos += len; result.setProperty(args.context(), resultIndex++, js::Value::string(args.context(), str.c_str())); } else if (c == 'x') { readPos++; // Skip padding byte } } // Add final position (1-based) result.setProperty(args.context(), resultIndex, js::Value::number(static_cast<double>(offset + readPos + 1))); args.returnValue(std::move(result)); } // joy.data.getPackedSize(format) static void js_data_getPackedSize(js::FunctionArgs &args) { if (args.length() < 1) { args.throwError("getPackedSize requires 1 argument"); return; } std::string format = args.arg(0).toString(args.context()); try { size_t size = DataModule::getPackedSize(format); args.returnValue(js::Value::number(static_cast<double>(size))); } catch (const std::exception &e) { args.throwError(e.what()); } } // ============================================================================ // Module initialization // ============================================================================ void DataModule::initJS(js::Context &ctx, js::Value &joy) { // Register ByteData class js::ClassDef byteDataDef; byteDataDef.name = "ByteData"; byteDataDef.finalizer = bytedata_finalizer; bytedata_class_id = js::ClassBuilder::registerClass(ctx, byteDataDef); js::Value byteDataProto = js::ModuleBuilder(ctx, "__bytedata_proto__") .function("getSize", js_bytedata_getSize, 0) .function("getString", js_bytedata_getString, 2) .function("clone", js_bytedata_clone, 0) .build(); js::ClassBuilder::setPrototype(ctx, bytedata_class_id, byteDataProto); // Register CompressedData class js::ClassDef compressedDataDef; compressedDataDef.name = "CompressedData"; compressedDataDef.finalizer = compresseddata_finalizer; compresseddata_class_id = js::ClassBuilder::registerClass(ctx, compressedDataDef); js::Value compressedDataProto = js::ModuleBuilder(ctx, "__compresseddata_proto__") .function("getSize", js_compresseddata_getSize, 0) .function("getString", js_compresseddata_getString, 0) .function("getFormat", js_compresseddata_getFormat, 0) .function("clone", js_compresseddata_clone, 0) .build(); js::ClassBuilder::setPrototype(ctx, compresseddata_class_id, compressedDataProto); // Register DataView class (reuses ByteData for now) js::ClassDef dataViewDef; dataViewDef.name = "DataView"; dataViewDef.finalizer = dataview_finalizer; dataview_class_id = js::ClassBuilder::registerClass(ctx, dataViewDef); js::Value dataViewProto = js::ModuleBuilder(ctx, "__dataview_proto__") .function("getSize", js_dataview_getSize, 0) .function("getString", js_dataview_getString, 0) .build(); js::ClassBuilder::setPrototype(ctx, dataview_class_id, dataViewProto); // Register data module functions js::ModuleBuilder(ctx, "data") .function("compress", js_data_compress, 4) .function("decompress", js_data_decompress, 3) .function("encode", js_data_encode, 4) .function("decode", js_data_decode, 3) .function("hash", js_data_hash, 2) .function("newByteData", js_data_newByteData, 3) .function("newDataView", js_data_newDataView, 3) .function("pack", js_data_pack, 10) .function("unpack", js_data_unpack, 3) .function("getPackedSize", js_data_getPackedSize, 1) .attachTo(joy); } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/filesystem/filesystem.cc
C++
#include "filesystem.hh" #include "physfs.h" #include <cstdlib> #include <cstring> #ifdef _WIN32 #include <direct.h> #define getcwd _getcwd #else #include <unistd.h> #endif namespace joy { namespace modules { //------------------------------------------------------------------------------ // File class implementation //------------------------------------------------------------------------------ File::File(const std::string &filename) : filename_(filename) , mode_(FileMode::Closed) , handle_(nullptr) { } File::~File() { close(); } bool File::open(FileMode mode, std::string *errorOut) { // Close any existing handle if (handle_) { close(); } PHYSFS_File *file = nullptr; switch (mode) { case FileMode::Read: file = PHYSFS_openRead(filename_.c_str()); break; case FileMode::Write: file = PHYSFS_openWrite(filename_.c_str()); break; case FileMode::Append: file = PHYSFS_openAppend(filename_.c_str()); break; case FileMode::Closed: if (errorOut) *errorOut = "Cannot open file in closed mode"; return false; } if (!file) { if (errorOut) { *errorOut = PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()); } return false; } handle_ = file; mode_ = mode; return true; } bool File::close() { if (!handle_) { return true; } bool success = PHYSFS_close(handle_) != 0; handle_ = nullptr; mode_ = FileMode::Closed; return success; } bool File::flush() { if (!handle_ || mode_ == FileMode::Read) { return false; } return PHYSFS_flush(handle_) != 0; } int64_t File::read(void *buffer, int64_t size) { if (!handle_ || mode_ != FileMode::Read) { return -1; } return PHYSFS_readBytes(handle_, buffer, static_cast<PHYSFS_uint64>(size)); } int64_t File::write(const void *data, int64_t size) { if (!handle_ || (mode_ != FileMode::Write && mode_ != FileMode::Append)) { return -1; } return PHYSFS_writeBytes(handle_, data, static_cast<PHYSFS_uint64>(size)); } bool File::seek(int64_t pos) { if (!handle_) { return false; } return PHYSFS_seek(handle_, static_cast<PHYSFS_uint64>(pos)) != 0; } int64_t File::tell() const { if (!handle_) { return -1; } return PHYSFS_tell(handle_); } bool File::isEOF() const { if (!handle_) { return true; } return PHYSFS_eof(handle_) != 0; } int64_t File::getSize() const { if (!handle_) { // Try to get size from stat PHYSFS_Stat stat; if (PHYSFS_stat(filename_.c_str(), &stat)) { return stat.filesize; } return -1; } return PHYSFS_fileLength(handle_); } //------------------------------------------------------------------------------ // FileData class implementation //------------------------------------------------------------------------------ FileData::FileData(const std::string &filename, const void *data, size_t size) : filename_(filename) , data_(nullptr) , size_(size) { if (size > 0 && data) { data_ = malloc(size); if (data_) { memcpy(data_, data, size); } else { size_ = 0; } } } FileData::FileData(const std::string &filename) : filename_(filename) , data_(nullptr) , size_(0) { } FileData::~FileData() { if (data_) { free(data_); } } std::string FileData::getExtension() const { size_t dotPos = filename_.rfind('.'); if (dotPos == std::string::npos || dotPos == filename_.length() - 1) { return ""; } return filename_.substr(dotPos + 1); } //------------------------------------------------------------------------------ // Filesystem module implementation //------------------------------------------------------------------------------ Filesystem::Filesystem(Engine *engine) : engine_(engine) { } Filesystem::~Filesystem() { } void Filesystem::setIdentity(const std::string &identity) { identity_ = identity; // Set up write directory using PHYSFS_getPrefDir const char *prefDir = PHYSFS_getPrefDir("joy", identity.c_str()); if (prefDir) { PHYSFS_setWriteDir(prefDir); // Also mount the write directory for reading PHYSFS_mount(prefDir, "/", 0); } } void Filesystem::setSource(const std::string &source) { source_ = source; } bool Filesystem::createDirectory(const char *path) { return PHYSFS_mkdir(path) != 0; } bool Filesystem::remove(const char *path) { return PHYSFS_delete(path) != 0; } std::vector<std::string> Filesystem::getDirectoryItems(const char *path) { std::vector<std::string> items; char **files = PHYSFS_enumerateFiles(path); if (files) { for (char **f = files; *f != nullptr; f++) { items.push_back(*f); } PHYSFS_freeList(files); } return items; } bool Filesystem::getInfo(const char *path, FileInfo *info) { PHYSFS_Stat stat; if (!PHYSFS_stat(path, &stat)) { return false; } switch (stat.filetype) { case PHYSFS_FILETYPE_REGULAR: info->type = FileType::File; break; case PHYSFS_FILETYPE_DIRECTORY: info->type = FileType::Directory; break; case PHYSFS_FILETYPE_SYMLINK: info->type = FileType::Symlink; break; default: info->type = FileType::Other; break; } info->size = stat.filesize; info->modtime = stat.modtime; return true; } std::string Filesystem::getRealDirectory(const char *filepath) { const char *dir = PHYSFS_getRealDir(filepath); return dir ? dir : ""; } std::string Filesystem::getSaveDirectory() { const char *writeDir = PHYSFS_getWriteDir(); return writeDir ? writeDir : ""; } std::string Filesystem::getUserDirectory() { // Use platform-native API to get user home directory #ifdef _WIN32 const char *home = getenv("USERPROFILE"); if (!home) { const char *drive = getenv("HOMEDRIVE"); const char *path = getenv("HOMEPATH"); if (drive && path) { static char homeBuf[4096]; snprintf(homeBuf, sizeof(homeBuf), "%s%s", drive, path); home = homeBuf; } } #else const char *home = getenv("HOME"); #endif if (home) { std::string result = home; // Ensure trailing slash if (!result.empty() && result.back() != '/') { result += '/'; } return result; } return ""; } std::string Filesystem::getAppdataDirectory() { // Return platform-specific base app data directory (not app-specific) #ifdef _WIN32 const char *appdata = getenv("APPDATA"); if (appdata) { std::string result = appdata; if (!result.empty() && result.back() != '\\' && result.back() != '/') { result += '\\'; } return result; } return getUserDirectory(); #elif defined(__APPLE__) std::string home = getUserDirectory(); if (!home.empty()) { return home + "Library/Application Support/"; } return ""; #else // Linux/Unix: use XDG_DATA_HOME or fall back to ~/.local/share/ const char *xdgData = getenv("XDG_DATA_HOME"); if (xdgData && xdgData[0] != '\0') { std::string result = xdgData; if (!result.empty() && result.back() != '/') { result += '/'; } return result; } std::string home = getUserDirectory(); if (!home.empty()) { return home + ".local/share/"; } return ""; #endif } std::string Filesystem::getWorkingDirectory() { char cwd[4096]; if (getcwd(cwd, sizeof(cwd))) { return cwd; } return ""; } std::string Filesystem::getSourceBaseDirectory() { const char *baseDir = PHYSFS_getBaseDir(); return baseDir ? baseDir : ""; } bool Filesystem::mount(const char *archive, const char *mountpoint, bool appendToPath) { return PHYSFS_mount(archive, mountpoint, appendToPath ? 1 : 0) != 0; } bool Filesystem::unmount(const char *archive) { return PHYSFS_unmount(archive) != 0; } bool Filesystem::areSymlinksEnabled() { return PHYSFS_symbolicLinksPermitted() != 0; } void Filesystem::setSymlinksEnabled(bool enable) { PHYSFS_permitSymbolicLinks(enable ? 1 : 0); } bool Filesystem::read(const char *filename, std::vector<char> &data) { PHYSFS_File *file = PHYSFS_openRead(filename); if (!file) { return false; } PHYSFS_sint64 len = PHYSFS_fileLength(file); if (len < 0) { PHYSFS_close(file); return false; } data.resize(static_cast<size_t>(len)); PHYSFS_sint64 bytesRead = PHYSFS_readBytes(file, data.data(), len); PHYSFS_close(file); if (bytesRead != len) { data.clear(); return false; } return true; } bool Filesystem::write(const char *filename, const void *data, size_t size) { PHYSFS_File *file = PHYSFS_openWrite(filename); if (!file) { return false; } PHYSFS_sint64 bytesWritten = PHYSFS_writeBytes(file, data, size); PHYSFS_close(file); return bytesWritten == static_cast<PHYSFS_sint64>(size); } bool Filesystem::append(const char *filename, const void *data, size_t size) { PHYSFS_File *file = PHYSFS_openAppend(filename); if (!file) { return false; } PHYSFS_sint64 bytesWritten = PHYSFS_writeBytes(file, data, size); PHYSFS_close(file); return bytesWritten == static_cast<PHYSFS_sint64>(size); } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/filesystem/filesystem.hh
C++ Header
#pragma once #include <string> #include <vector> #include <cstdint> // Forward declare PhysFS types typedef struct PHYSFS_File PHYSFS_File; namespace js { class Context; class Value; } namespace joy { class Engine; namespace modules { // File mode for opening files enum class FileMode { Closed, Read, Write, Append }; // File type returned by getInfo enum class FileType { File, Directory, Symlink, Other }; // File info structure struct FileInfo { FileType type; int64_t size; // -1 if not available int64_t modtime; // -1 if not available }; // File object for reading/writing class File { public: File(const std::string &filename); ~File(); // Open/close bool open(FileMode mode, std::string *errorOut = nullptr); bool close(); bool flush(); // Read/write int64_t read(void *buffer, int64_t size); int64_t write(const void *data, int64_t size); // Seeking bool seek(int64_t pos); int64_t tell() const; bool isEOF() const; // Properties const std::string &getFilename() const { return filename_; } FileMode getMode() const { return mode_; } int64_t getSize() const; bool isOpen() const { return handle_ != nullptr; } private: std::string filename_; FileMode mode_; PHYSFS_File *handle_; }; // FileData - in-memory file data class FileData { public: FileData(const std::string &filename, const void *data, size_t size); FileData(const std::string &filename); // Empty FileData with just a name ~FileData(); // Data access const void *getData() const { return data_; } size_t getSize() const { return size_; } // Filename/extension const std::string &getFilename() const { return filename_; } std::string getExtension() const; private: std::string filename_; void *data_; size_t size_; }; // Filesystem module for PhysFS-based file access class Filesystem { public: Filesystem(Engine *engine); ~Filesystem(); // Identity (write directory name) void setIdentity(const std::string &identity); const std::string &getIdentity() const { return identity_; } // Source path tracking void setSource(const std::string &source); const std::string &getSource() const { return source_; } // Directory operations static bool createDirectory(const char *path); static bool remove(const char *path); static std::vector<std::string> getDirectoryItems(const char *path); // File operations static bool getInfo(const char *path, FileInfo *info); static std::string getRealDirectory(const char *filepath); // Path queries static std::string getSaveDirectory(); static std::string getUserDirectory(); static std::string getAppdataDirectory(); static std::string getWorkingDirectory(); static std::string getSourceBaseDirectory(); // Mount/unmount static bool mount(const char *archive, const char *mountpoint, bool appendToPath); static bool unmount(const char *archive); // Symlink handling static bool areSymlinksEnabled(); static void setSymlinksEnabled(bool enable); // Fused mode (always false for Joy - we don't support fusing) static bool isFused() { return false; } // Read/write convenience functions static bool read(const char *filename, std::vector<char> &data); static bool write(const char *filename, const void *data, size_t size); static bool append(const char *filename, const void *data, size_t size); // JavaScript bindings static void initJS(js::Context &ctx, js::Value &joy); private: Engine *engine_; std::string identity_; std::string source_; }; } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/filesystem/filesystem_js.cc
C++
#include "js/js.hh" #include "filesystem.hh" #include "engine.hh" #include "physfs.h" #include <cstdlib> #include <cstring> namespace joy { namespace modules { // Helper to get Filesystem module from JS context static Filesystem *getFilesystem(js::FunctionArgs &args) { Engine *engine = args.getContextOpaque<Engine>(); return engine ? engine->getFilesystemModule() : nullptr; } //------------------------------------------------------------------------------ // File class JS bindings //------------------------------------------------------------------------------ static js::ClassID file_class_id = 0; static void file_finalizer(void *opaque) { File *file = static_cast<File *>(opaque); delete file; } static File *getFile(js::FunctionArgs &args) { js::Value thisVal = args.thisValue(); return static_cast<File *>(js::ClassBuilder::getOpaque(thisVal, file_class_id)); } // Convert string mode to FileMode enum static FileMode stringToFileMode(const std::string &mode) { if (mode == "r") return FileMode::Read; if (mode == "w") return FileMode::Write; if (mode == "a") return FileMode::Append; return FileMode::Closed; } // Convert FileMode enum to string static const char *fileModeToString(FileMode mode) { switch (mode) { case FileMode::Read: return "r"; case FileMode::Write: return "w"; case FileMode::Append: return "a"; case FileMode::Closed: return "c"; } return "c"; } // file:open(mode) -> boolean, [errorstring] static void js_file_open(js::FunctionArgs &args) { File *file = getFile(args); if (!file) { args.returnValue(js::Value::boolean(false)); return; } if (args.length() < 1) { args.throwError("File:open requires mode argument"); return; } std::string modeStr = args.arg(0).toString(args.context()); FileMode mode = stringToFileMode(modeStr); if (mode == FileMode::Closed) { args.throwError("Invalid file mode"); return; } std::string error; bool success = file->open(mode, &error); // Return success, error (Love2D style: returns ok, err) args.returnValue(js::Value::boolean(success)); } // file:close() -> boolean static void js_file_close(js::FunctionArgs &args) { File *file = getFile(args); args.returnValue(js::Value::boolean(file && file->close())); } // file:flush() -> boolean, [errorstring] static void js_file_flush(js::FunctionArgs &args) { File *file = getFile(args); args.returnValue(js::Value::boolean(file && file->flush())); } // file:read([bytes]) -> string, size static void js_file_read(js::FunctionArgs &args) { File *file = getFile(args); if (!file || !file->isOpen()) { args.returnValue(js::Value::null()); return; } int64_t bytesToRead = -1; if (args.length() >= 1 && !args.arg(0).isUndefined()) { bytesToRead = static_cast<int64_t>(args.arg(0).toFloat64()); } // If not specified, read entire file if (bytesToRead < 0) { bytesToRead = file->getSize(); if (bytesToRead < 0) { args.returnValue(js::Value::null()); return; } // Adjust for current position int64_t pos = file->tell(); if (pos >= 0) { bytesToRead -= pos; } } if (bytesToRead <= 0) { args.returnValue(js::Value::string(args.context(), "")); return; } char *buf = static_cast<char *>(malloc(bytesToRead)); if (!buf) { args.returnValue(js::Value::null()); return; } int64_t bytesRead = file->read(buf, bytesToRead); if (bytesRead < 0) { free(buf); args.returnValue(js::Value::null()); return; } js::Value result = js::Value::string(args.context(), buf, static_cast<size_t>(bytesRead)); free(buf); args.returnValue(std::move(result)); } // file:write(data, [size]) -> boolean, [errorstring] static void js_file_write(js::FunctionArgs &args) { File *file = getFile(args); if (!file || !file->isOpen()) { args.returnValue(js::Value::boolean(false)); return; } if (args.length() < 1) { args.returnValue(js::Value::boolean(false)); return; } std::string data = args.arg(0).toString(args.context()); size_t size = data.size(); if (args.length() >= 2 && !args.arg(1).isUndefined()) { size_t requestedSize = static_cast<size_t>(args.arg(1).toFloat64()); if (requestedSize < size) { size = requestedSize; } } int64_t bytesWritten = file->write(data.c_str(), static_cast<int64_t>(size)); args.returnValue(js::Value::boolean(bytesWritten == static_cast<int64_t>(size))); } // file:seek(pos) -> boolean static void js_file_seek(js::FunctionArgs &args) { File *file = getFile(args); if (!file || args.length() < 1) { args.returnValue(js::Value::boolean(false)); return; } int64_t pos = static_cast<int64_t>(args.arg(0).toFloat64()); args.returnValue(js::Value::boolean(file->seek(pos))); } // file:tell() -> number static void js_file_tell(js::FunctionArgs &args) { File *file = getFile(args); args.returnValue(js::Value::number(file ? static_cast<double>(file->tell()) : -1)); } // file:getSize() -> number static void js_file_getSize(js::FunctionArgs &args) { File *file = getFile(args); args.returnValue(js::Value::number(file ? static_cast<double>(file->getSize()) : 0)); } // file:isOpen() -> boolean static void js_file_isOpen(js::FunctionArgs &args) { File *file = getFile(args); args.returnValue(js::Value::boolean(file && file->isOpen())); } // file:isEOF() -> boolean static void js_file_isEOF(js::FunctionArgs &args) { File *file = getFile(args); args.returnValue(js::Value::boolean(file && file->isEOF())); } // file:getFilename() -> string static void js_file_getFilename(js::FunctionArgs &args) { File *file = getFile(args); if (file) { args.returnValue(js::Value::string(args.context(), file->getFilename().c_str())); } else { args.returnValue(js::Value::string(args.context(), "")); } } // file:getMode() -> string static void js_file_getMode(js::FunctionArgs &args) { File *file = getFile(args); const char *mode = file ? fileModeToString(file->getMode()) : "c"; args.returnValue(js::Value::string(args.context(), mode)); } // file:lines() -> iterator function static void js_file_lines(js::FunctionArgs &args) { // For simplicity, we'll implement lines by reading the entire file and splitting // A more memory-efficient implementation would use a closure, but this works for most cases File *file = getFile(args); if (!file || !file->isOpen()) { args.throwError("File must be open to iterate lines"); return; } // Read entire remaining content int64_t size = file->getSize(); int64_t pos = file->tell(); if (size < 0 || pos < 0) { args.throwError("Cannot determine file size"); return; } int64_t remaining = size - pos; if (remaining <= 0) { // Return empty iterator args.returnValue(js::Value::null()); return; } char *buf = static_cast<char *>(malloc(remaining + 1)); if (!buf) { args.throwError("Out of memory"); return; } int64_t bytesRead = file->read(buf, remaining); if (bytesRead < 0) { free(buf); args.throwError("Failed to read file"); return; } buf[bytesRead] = '\0'; // Create array of lines js::Value lines = js::Value::array(args.context()); uint32_t lineIndex = 0; char *start = buf; for (char *p = buf; *p; p++) { if (*p == '\n') { *p = '\0'; // Remove trailing \r if present if (p > start && *(p-1) == '\r') { *(p-1) = '\0'; } lines.setProperty(args.context(), lineIndex++, js::Value::string(args.context(), start)); start = p + 1; } } // Add last line if not empty if (*start) { lines.setProperty(args.context(), lineIndex++, js::Value::string(args.context(), start)); } free(buf); args.returnValue(std::move(lines)); } //------------------------------------------------------------------------------ // FileData class JS bindings //------------------------------------------------------------------------------ static js::ClassID filedata_class_id = 0; static void filedata_finalizer(void *opaque) { FileData *fd = static_cast<FileData *>(opaque); delete fd; } static FileData *getFileData(js::FunctionArgs &args) { js::Value thisVal = args.thisValue(); return static_cast<FileData *>(js::ClassBuilder::getOpaque(thisVal, filedata_class_id)); } // filedata:getFilename() -> string static void js_filedata_getFilename(js::FunctionArgs &args) { FileData *fd = getFileData(args); if (fd) { args.returnValue(js::Value::string(args.context(), fd->getFilename().c_str())); } else { args.returnValue(js::Value::string(args.context(), "")); } } // filedata:getExtension() -> string static void js_filedata_getExtension(js::FunctionArgs &args) { FileData *fd = getFileData(args); if (fd) { args.returnValue(js::Value::string(args.context(), fd->getExtension().c_str())); } else { args.returnValue(js::Value::string(args.context(), "")); } } // filedata:getSize() -> number static void js_filedata_getSize(js::FunctionArgs &args) { FileData *fd = getFileData(args); args.returnValue(js::Value::number(fd ? static_cast<double>(fd->getSize()) : 0)); } // filedata:getString() -> string (Data interface) static void js_filedata_getString(js::FunctionArgs &args) { FileData *fd = getFileData(args); if (fd && fd->getData()) { args.returnValue(js::Value::string(args.context(), static_cast<const char *>(fd->getData()), fd->getSize())); } else { args.returnValue(js::Value::string(args.context(), "")); } } //------------------------------------------------------------------------------ // Filesystem module functions //------------------------------------------------------------------------------ // joy.filesystem.read(filename, [size]) -> string, size or nil, error static void js_filesystem_read(js::FunctionArgs &args) { if (args.length() < 1) { args.throwError("filesystem.read requires filename"); return; } std::string filename = args.arg(0).toString(args.context()); PHYSFS_File *file = PHYSFS_openRead(filename.c_str()); if (!file) { args.returnValue(js::Value::null()); return; } PHYSFS_sint64 fileLen = PHYSFS_fileLength(file); if (fileLen < 0) { PHYSFS_close(file); args.returnValue(js::Value::null()); return; } int64_t bytesToRead = fileLen; if (args.length() >= 2 && !args.arg(1).isUndefined()) { bytesToRead = static_cast<int64_t>(args.arg(1).toFloat64()); if (bytesToRead > fileLen) bytesToRead = fileLen; } char *buf = static_cast<char *>(malloc(bytesToRead + 1)); if (!buf) { PHYSFS_close(file); args.returnValue(js::Value::null()); return; } PHYSFS_sint64 bytesRead = PHYSFS_readBytes(file, buf, bytesToRead); PHYSFS_close(file); if (bytesRead < 0) { free(buf); args.returnValue(js::Value::null()); return; } buf[bytesRead] = '\0'; js::Value result = js::Value::string(args.context(), buf, static_cast<size_t>(bytesRead)); free(buf); args.returnValue(std::move(result)); } // joy.filesystem.write(filename, data, [size]) -> boolean, [error] static void js_filesystem_write(js::FunctionArgs &args) { if (args.length() < 2) { args.throwError("filesystem.write requires filename and data"); return; } std::string filename = args.arg(0).toString(args.context()); std::string data = args.arg(1).toString(args.context()); size_t size = data.size(); if (args.length() >= 3 && !args.arg(2).isUndefined()) { size_t requestedSize = static_cast<size_t>(args.arg(2).toFloat64()); if (requestedSize < size) size = requestedSize; } bool success = Filesystem::write(filename.c_str(), data.c_str(), size); args.returnValue(js::Value::boolean(success)); } // joy.filesystem.append(filename, data, [size]) -> boolean, [error] static void js_filesystem_append(js::FunctionArgs &args) { if (args.length() < 2) { args.throwError("filesystem.append requires filename and data"); return; } std::string filename = args.arg(0).toString(args.context()); std::string data = args.arg(1).toString(args.context()); size_t size = data.size(); if (args.length() >= 3 && !args.arg(2).isUndefined()) { size_t requestedSize = static_cast<size_t>(args.arg(2).toFloat64()); if (requestedSize < size) size = requestedSize; } bool success = Filesystem::append(filename.c_str(), data.c_str(), size); args.returnValue(js::Value::boolean(success)); } // joy.filesystem.remove(name) -> boolean static void js_filesystem_remove(js::FunctionArgs &args) { if (args.length() < 1) { args.throwError("filesystem.remove requires name"); return; } std::string name = args.arg(0).toString(args.context()); args.returnValue(js::Value::boolean(Filesystem::remove(name.c_str()))); } // joy.filesystem.createDirectory(name) -> boolean static void js_filesystem_createDirectory(js::FunctionArgs &args) { if (args.length() < 1) { args.throwError("filesystem.createDirectory requires name"); return; } std::string name = args.arg(0).toString(args.context()); args.returnValue(js::Value::boolean(Filesystem::createDirectory(name.c_str()))); } // joy.filesystem.getDirectoryItems(path) -> array static void js_filesystem_getDirectoryItems(js::FunctionArgs &args) { std::string path = "/"; if (args.length() >= 1) { path = args.arg(0).toString(args.context()); } std::vector<std::string> items = Filesystem::getDirectoryItems(path.c_str()); js::Value arr = js::Value::array(args.context()); for (uint32_t i = 0; i < items.size(); i++) { arr.setProperty(args.context(), i, js::Value::string(args.context(), items[i].c_str())); } args.returnValue(std::move(arr)); } // joy.filesystem.getInfo(path, [filtertype]) -> {type, size, modtime} or nil static void js_filesystem_getInfo(js::FunctionArgs &args) { if (args.length() < 1) { args.throwError("filesystem.getInfo requires path"); return; } std::string path = args.arg(0).toString(args.context()); // Optional filter type std::string filterType; if (args.length() >= 2 && args.arg(1).isString()) { filterType = args.arg(1).toString(args.context()); } FileInfo info; if (!Filesystem::getInfo(path.c_str(), &info)) { args.returnValue(js::Value::null()); return; } // Get type string const char *typeStr; switch (info.type) { case FileType::File: typeStr = "file"; break; case FileType::Directory: typeStr = "directory"; break; case FileType::Symlink: typeStr = "symlink"; break; default: typeStr = "other"; break; } // Apply filter if specified if (!filterType.empty() && filterType != typeStr) { args.returnValue(js::Value::null()); return; } js::Value result = js::Value::object(args.context()); result.setProperty(args.context(), "type", js::Value::string(args.context(), typeStr)); if (info.size >= 0) { result.setProperty(args.context(), "size", js::Value::number(static_cast<double>(info.size))); } if (info.modtime >= 0) { result.setProperty(args.context(), "modtime", js::Value::number(static_cast<double>(info.modtime))); } args.returnValue(std::move(result)); } // joy.filesystem.getRealDirectory(filepath) -> string static void js_filesystem_getRealDirectory(js::FunctionArgs &args) { if (args.length() < 1) { args.throwError("filesystem.getRealDirectory requires filepath"); return; } std::string filepath = args.arg(0).toString(args.context()); std::string realDir = Filesystem::getRealDirectory(filepath.c_str()); args.returnValue(js::Value::string(args.context(), realDir.c_str())); } // joy.filesystem.getSaveDirectory() -> string static void js_filesystem_getSaveDirectory(js::FunctionArgs &args) { std::string dir = Filesystem::getSaveDirectory(); args.returnValue(js::Value::string(args.context(), dir.c_str())); } // joy.filesystem.getUserDirectory() -> string static void js_filesystem_getUserDirectory(js::FunctionArgs &args) { std::string dir = Filesystem::getUserDirectory(); args.returnValue(js::Value::string(args.context(), dir.c_str())); } // joy.filesystem.getAppdataDirectory() -> string static void js_filesystem_getAppdataDirectory(js::FunctionArgs &args) { std::string dir = Filesystem::getAppdataDirectory(); args.returnValue(js::Value::string(args.context(), dir.c_str())); } // joy.filesystem.getWorkingDirectory() -> string static void js_filesystem_getWorkingDirectory(js::FunctionArgs &args) { std::string dir = Filesystem::getWorkingDirectory(); args.returnValue(js::Value::string(args.context(), dir.c_str())); } // joy.filesystem.getSource() -> string static void js_filesystem_getSource(js::FunctionArgs &args) { Filesystem *fs = getFilesystem(args); if (fs) { args.returnValue(js::Value::string(args.context(), fs->getSource().c_str())); } else { args.returnValue(js::Value::string(args.context(), "")); } } // joy.filesystem.getSourceBaseDirectory() -> string static void js_filesystem_getSourceBaseDirectory(js::FunctionArgs &args) { std::string dir = Filesystem::getSourceBaseDirectory(); args.returnValue(js::Value::string(args.context(), dir.c_str())); } // joy.filesystem.getIdentity() -> string static void js_filesystem_getIdentity(js::FunctionArgs &args) { Filesystem *fs = getFilesystem(args); if (fs) { args.returnValue(js::Value::string(args.context(), fs->getIdentity().c_str())); } else { args.returnValue(js::Value::string(args.context(), "")); } } // joy.filesystem.setIdentity(name) static void js_filesystem_setIdentity(js::FunctionArgs &args) { if (args.length() < 1) { args.throwError("filesystem.setIdentity requires name"); return; } Filesystem *fs = getFilesystem(args); if (fs) { std::string identity = args.arg(0).toString(args.context()); fs->setIdentity(identity); } args.returnUndefined(); } // joy.filesystem.mount(archive, mountpoint, [appendToPath]) -> boolean static void js_filesystem_mount(js::FunctionArgs &args) { if (args.length() < 2) { args.throwError("filesystem.mount requires archive and mountpoint"); return; } std::string archive = args.arg(0).toString(args.context()); std::string mountpoint = args.arg(1).toString(args.context()); bool appendToPath = false; if (args.length() >= 3) { appendToPath = args.arg(2).toBool(); } bool success = Filesystem::mount(archive.c_str(), mountpoint.c_str(), appendToPath); args.returnValue(js::Value::boolean(success)); } // joy.filesystem.unmount(archive) -> boolean static void js_filesystem_unmount(js::FunctionArgs &args) { if (args.length() < 1) { args.throwError("filesystem.unmount requires archive"); return; } std::string archive = args.arg(0).toString(args.context()); bool success = Filesystem::unmount(archive.c_str()); args.returnValue(js::Value::boolean(success)); } // joy.filesystem.isFused() -> boolean static void js_filesystem_isFused(js::FunctionArgs &args) { args.returnValue(js::Value::boolean(Filesystem::isFused())); } // joy.filesystem.areSymlinksEnabled() -> boolean static void js_filesystem_areSymlinksEnabled(js::FunctionArgs &args) { args.returnValue(js::Value::boolean(Filesystem::areSymlinksEnabled())); } // joy.filesystem.setSymlinksEnabled(enable) static void js_filesystem_setSymlinksEnabled(js::FunctionArgs &args) { if (args.length() < 1) { args.throwError("filesystem.setSymlinksEnabled requires enable parameter"); return; } bool enable = args.arg(0).toBool(); Filesystem::setSymlinksEnabled(enable); args.returnUndefined(); } // joy.filesystem.lines(filename) -> array of lines static void js_filesystem_lines(js::FunctionArgs &args) { if (args.length() < 1) { args.throwError("filesystem.lines requires filename"); return; } std::string filename = args.arg(0).toString(args.context()); std::vector<char> data; if (!Filesystem::read(filename.c_str(), data)) { args.throwError("Failed to read file"); return; } // Parse lines js::Value lines = js::Value::array(args.context()); uint32_t lineIndex = 0; if (!data.empty()) { data.push_back('\0'); // Ensure null-terminated char *start = data.data(); for (char *p = data.data(); *p; p++) { if (*p == '\n') { *p = '\0'; // Remove trailing \r if present if (p > start && *(p-1) == '\r') { *(p-1) = '\0'; } lines.setProperty(args.context(), lineIndex++, js::Value::string(args.context(), start)); start = p + 1; } } // Add last line if not empty if (*start) { lines.setProperty(args.context(), lineIndex++, js::Value::string(args.context(), start)); } } args.returnValue(std::move(lines)); } // joy.filesystem.newFile(filename, [mode]) -> File static void js_filesystem_newFile(js::FunctionArgs &args) { if (args.length() < 1) { args.throwError("filesystem.newFile requires filename"); return; } std::string filename = args.arg(0).toString(args.context()); File *file = new File(filename); // If mode is provided, open the file if (args.length() >= 2 && args.arg(1).isString()) { std::string modeStr = args.arg(1).toString(args.context()); FileMode mode = stringToFileMode(modeStr); if (mode != FileMode::Closed) { std::string error; if (!file->open(mode, &error)) { delete file; args.returnValue(js::Value::null()); return; } } } js::Value obj = js::ClassBuilder::newInstance(args.context(), file_class_id); js::ClassBuilder::setOpaque(obj, file); args.returnValue(std::move(obj)); } // joy.filesystem.newFileData(contents, name) or (filepath) -> FileData static void js_filesystem_newFileData(js::FunctionArgs &args) { if (args.length() < 1) { args.throwError("filesystem.newFileData requires arguments"); return; } FileData *fileData = nullptr; if (args.length() >= 2) { // newFileData(contents, name) std::string contents = args.arg(0).toString(args.context()); std::string name = args.arg(1).toString(args.context()); fileData = new FileData(name, contents.c_str(), contents.size()); } else { // newFileData(filepath) - read from file std::string filepath = args.arg(0).toString(args.context()); std::vector<char> data; if (!Filesystem::read(filepath.c_str(), data)) { args.returnValue(js::Value::null()); return; } fileData = new FileData(filepath, data.data(), data.size()); } js::Value obj = js::ClassBuilder::newInstance(args.context(), filedata_class_id); js::ClassBuilder::setOpaque(obj, fileData); args.returnValue(std::move(obj)); } //------------------------------------------------------------------------------ // Module initialization //------------------------------------------------------------------------------ void Filesystem::initJS(js::Context &ctx, js::Value &joy) { // Register File class js::ClassDef fileDef; fileDef.name = "File"; fileDef.finalizer = file_finalizer; file_class_id = js::ClassBuilder::registerClass(ctx, fileDef); // Create File prototype with methods js::Value fileProto = js::ModuleBuilder(ctx, "__file_proto__") .function("open", js_file_open, 1) .function("close", js_file_close, 0) .function("flush", js_file_flush, 0) .function("read", js_file_read, 1) .function("write", js_file_write, 2) .function("seek", js_file_seek, 1) .function("tell", js_file_tell, 0) .function("getSize", js_file_getSize, 0) .function("isOpen", js_file_isOpen, 0) .function("isEOF", js_file_isEOF, 0) .function("getFilename", js_file_getFilename, 0) .function("getMode", js_file_getMode, 0) .function("lines", js_file_lines, 0) .build(); js::ClassBuilder::setPrototype(ctx, file_class_id, fileProto); // Register FileData class js::ClassDef fileDataDef; fileDataDef.name = "FileData"; fileDataDef.finalizer = filedata_finalizer; filedata_class_id = js::ClassBuilder::registerClass(ctx, fileDataDef); // Create FileData prototype with methods js::Value fileDataProto = js::ModuleBuilder(ctx, "__filedata_proto__") .function("getFilename", js_filedata_getFilename, 0) .function("getExtension", js_filedata_getExtension, 0) .function("getSize", js_filedata_getSize, 0) .function("getString", js_filedata_getString, 0) .build(); js::ClassBuilder::setPrototype(ctx, filedata_class_id, fileDataProto); // Create filesystem namespace with all functions js::ModuleBuilder(ctx, "filesystem") // File operations .function("read", js_filesystem_read, 2) .function("write", js_filesystem_write, 3) .function("append", js_filesystem_append, 3) .function("remove", js_filesystem_remove, 1) .function("lines", js_filesystem_lines, 1) // Directory operations .function("createDirectory", js_filesystem_createDirectory, 1) .function("getDirectoryItems", js_filesystem_getDirectoryItems, 1) // File/path info .function("getInfo", js_filesystem_getInfo, 2) .function("getRealDirectory", js_filesystem_getRealDirectory, 1) // Paths .function("getSaveDirectory", js_filesystem_getSaveDirectory, 0) .function("getUserDirectory", js_filesystem_getUserDirectory, 0) .function("getAppdataDirectory", js_filesystem_getAppdataDirectory, 0) .function("getWorkingDirectory", js_filesystem_getWorkingDirectory, 0) .function("getSource", js_filesystem_getSource, 0) .function("getSourceBaseDirectory", js_filesystem_getSourceBaseDirectory, 0) // Identity .function("getIdentity", js_filesystem_getIdentity, 0) .function("setIdentity", js_filesystem_setIdentity, 1) // Mount/unmount .function("mount", js_filesystem_mount, 3) .function("unmount", js_filesystem_unmount, 1) // Misc .function("isFused", js_filesystem_isFused, 0) .function("areSymlinksEnabled", js_filesystem_areSymlinksEnabled, 0) .function("setSymlinksEnabled", js_filesystem_setSymlinksEnabled, 1) // Constructors .function("newFile", js_filesystem_newFile, 2) .function("newFileData", js_filesystem_newFileData, 2) .attachTo(joy); } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/batch_renderer.cc
C++
#include "batch_renderer.hh" #include "shader.hh" #include <cmath> #include <cstring> #include <cstdio> // Backend selection (matches gui_shaders.h pattern) #if !defined(SOKOL_GLCORE) && !defined(SOKOL_GLES3) && !defined(SOKOL_METAL) #if defined(RENDER_METAL) #define SOKOL_METAL #elif defined(__EMSCRIPTEN__) #define SOKOL_GLES3 #else #define SOKOL_GLCORE #endif #endif namespace joy { namespace modules { // Use BuiltinUniforms from shader.hh // ============================================================================ // Embedded Shaders // ============================================================================ #if defined(SOKOL_GLCORE) static const char *batch_vs_source = R"( #version 330 // Built-in uniforms as vec4 array uniform vec4 builtins[10]; #define TransformMatrix mat4(builtins[0], builtins[1], builtins[2], builtins[3]) #define ProjectionMatrix mat4(builtins[4], builtins[5], builtins[6], builtins[7]) layout(location = 0) in vec2 position; layout(location = 1) in vec2 texcoord; layout(location = 2) in vec4 color0; out vec2 uv; out vec4 color; void main() { vec4 worldPos = TransformMatrix * vec4(position, 0.0, 1.0); gl_Position = ProjectionMatrix * worldPos; uv = texcoord; color = color0; } )"; static const char *batch_fs_source = R"( #version 330 uniform sampler2D tex; in vec2 uv; in vec4 color; out vec4 frag_color; void main() { frag_color = texture(tex, uv) * color; } )"; #elif defined(SOKOL_GLES3) static const char *batch_vs_source = R"(#version 300 es // Built-in uniforms as vec4 array uniform highp vec4 builtins[10]; #define TransformMatrix mat4(builtins[0], builtins[1], builtins[2], builtins[3]) #define ProjectionMatrix mat4(builtins[4], builtins[5], builtins[6], builtins[7]) layout(location = 0) in vec2 position; layout(location = 1) in vec2 texcoord; layout(location = 2) in vec4 color0; out vec2 uv; out vec4 color; void main() { vec4 worldPos = TransformMatrix * vec4(position, 0.0, 1.0); gl_Position = ProjectionMatrix * worldPos; uv = texcoord; color = color0; } )"; static const char *batch_fs_source = R"(#version 300 es precision mediump float; uniform sampler2D tex; in vec2 uv; in vec4 color; out vec4 frag_color; void main() { frag_color = texture(tex, uv) * color; } )"; #elif defined(SOKOL_METAL) static const char *batch_shader_source = R"( #include <metal_stdlib> using namespace metal; struct builtins_t { float4 data[10]; }; struct vs_in { float2 position [[attribute(0)]]; float2 texcoord [[attribute(1)]]; float4 color [[attribute(2)]]; }; struct vs_out { float4 position [[position]]; float2 uv; float4 color; }; vertex vs_out vs_main(vs_in in [[stage_in]], constant builtins_t& builtins [[buffer(0)]]) { float4x4 transformMatrix = float4x4(builtins.data[0], builtins.data[1], builtins.data[2], builtins.data[3]); float4x4 projectionMatrix = float4x4(builtins.data[4], builtins.data[5], builtins.data[6], builtins.data[7]); vs_out out; float4 worldPos = transformMatrix * float4(in.position, 0.0, 1.0); out.position = projectionMatrix * worldPos; out.uv = in.texcoord; out.color = in.color; return out; } fragment float4 fs_main(vs_out in [[stage_in]], texture2d<float> tex [[texture(0)]], sampler smp [[sampler(0)]]) { return tex.sample(smp, in.uv) * in.color; } )"; #endif // ============================================================================ // Transform2D Implementation // ============================================================================ void Transform2D::identity() { m[0] = 1.0f; m[1] = 0.0f; m[2] = 0.0f; m[3] = 0.0f; m[4] = 1.0f; m[5] = 0.0f; } Transform2D Transform2D::Identity() { Transform2D t; t.identity(); return t; } void Transform2D::translate(float x, float y) { m[2] += m[0] * x + m[1] * y; m[5] += m[3] * x + m[4] * y; } void Transform2D::rotate(float radians) { float c = cosf(radians); float s = sinf(radians); float a = m[0], b = m[1]; float d = m[3], e = m[4]; m[0] = a * c + b * s; m[1] = b * c - a * s; m[3] = d * c + e * s; m[4] = e * c - d * s; } void Transform2D::scale(float sx, float sy) { m[0] *= sx; m[1] *= sy; m[3] *= sx; m[4] *= sy; } void Transform2D::multiply(const Transform2D &other) { float a0 = m[0], b0 = m[1], c0 = m[2]; float d0 = m[3], e0 = m[4], f0 = m[5]; float a1 = other.m[0], b1 = other.m[1], c1 = other.m[2]; float d1 = other.m[3], e1 = other.m[4], f1 = other.m[5]; m[0] = a0 * a1 + b0 * d1; m[1] = a0 * b1 + b0 * e1; m[2] = a0 * c1 + b0 * f1 + c0; m[3] = d0 * a1 + e0 * d1; m[4] = d0 * b1 + e0 * e1; m[5] = d0 * c1 + e0 * f1 + f0; } void Transform2D::transformPoint(float &x, float &y) const { float nx = m[0] * x + m[1] * y + m[2]; float ny = m[3] * x + m[4] * y + m[5]; x = nx; y = ny; } bool Transform2D::operator==(const Transform2D &other) const { return m[0] == other.m[0] && m[1] == other.m[1] && m[2] == other.m[2] && m[3] == other.m[3] && m[4] == other.m[4] && m[5] == other.m[5]; } // ============================================================================ // Matrix4 Implementation // ============================================================================ void Matrix4::identity() { memset(m, 0, sizeof(m)); m[0] = m[5] = m[10] = m[15] = 1.0f; } Matrix4 Matrix4::Identity() { Matrix4 mat; mat.identity(); return mat; } void Matrix4::ortho(float left, float right, float bottom, float top, float near, float far) { memset(m, 0, sizeof(m)); m[0] = 2.0f / (right - left); m[5] = 2.0f / (top - bottom); m[10] = -2.0f / (far - near); m[12] = -(right + left) / (right - left); m[13] = -(top + bottom) / (top - bottom); m[14] = -(far + near) / (far - near); m[15] = 1.0f; } void Matrix4::multiply(const Matrix4 &other) { float result[16]; for (int col = 0; col < 4; col++) { for (int row = 0; row < 4; row++) { result[col * 4 + row] = m[0 * 4 + row] * other.m[col * 4 + 0] + m[1 * 4 + row] * other.m[col * 4 + 1] + m[2 * 4 + row] * other.m[col * 4 + 2] + m[3 * 4 + row] * other.m[col * 4 + 3]; } } memcpy(m, result, sizeof(m)); } void Matrix4::setFromTransform2D(const Transform2D &t) { memset(m, 0, sizeof(m)); m[0] = t.m[0]; // a m[1] = t.m[3]; // c m[4] = t.m[1]; // b m[5] = t.m[4]; // d m[10] = 1.0f; m[12] = t.m[2]; // tx m[13] = t.m[5]; // ty m[15] = 1.0f; } // ============================================================================ // BatchState Implementation // ============================================================================ bool BatchState::operator==(const BatchState &other) const { return texture_view.id == other.texture_view.id && sampler.id == other.sampler.id && blend == other.blend && primitive == other.primitive && color_mask == other.color_mask; // Note: transform and shader_id not included - they trigger flush separately } // ============================================================================ // BatchRenderer Implementation // ============================================================================ BatchRenderer::BatchRenderer() : shader_({SG_INVALID_ID}) , vertex_buffer_({SG_INVALID_ID}) , index_buffer_({SG_INVALID_ID}) , white_texture_({SG_INVALID_ID}) , white_view_({SG_INVALID_ID}) , default_sampler_({SG_INVALID_ID}) , color_r_(255), color_g_(255), color_b_(255), color_a_(255) , line_width_(1.0f) , frame_width_(0), frame_height_(0) , pixel_width_(0), pixel_height_(0) , dpi_scale_(1.0f) , in_frame_(false) , initialized_(false) , flush_count_(0), draw_call_count_(0) , scissor_enabled_(false) , scissor_x_(0), scissor_y_(0), scissor_w_(0), scissor_h_(0) , rendering_to_canvas_(false) , current_shader_(nullptr) { // Initialize state current_state_.texture_view.id = SG_INVALID_ID; current_state_.sampler.id = SG_INVALID_ID; current_state_.blend = BlendState::Alpha(); current_state_.primitive = PrimitiveType::Triangles; current_state_.transform.identity(); current_state_.color_mask = ColorMask::All(); current_state_.shader_id = 0; pending_state_ = current_state_; current_transform_.identity(); } BatchRenderer::~BatchRenderer() { shutdown(); } bool BatchRenderer::init() { if (initialized_) { return true; } // Create shader sg_shader_desc shader_desc = {}; shader_desc.label = "batch_shader"; // Built-in uniform block (slot 0, vertex stage) shader_desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; shader_desc.uniform_blocks[0].size = sizeof(BuiltinUniforms); #if defined(SOKOL_GLCORE) || defined(SOKOL_GLES3) shader_desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "builtins"; shader_desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; shader_desc.uniform_blocks[0].glsl_uniforms[0].array_count = 10; #elif defined(SOKOL_METAL) shader_desc.uniform_blocks[0].msl_buffer_n = 0; #endif #if defined(SOKOL_GLCORE) || defined(SOKOL_GLES3) shader_desc.vertex_func.source = batch_vs_source; shader_desc.vertex_func.entry = "main"; shader_desc.fragment_func.source = batch_fs_source; shader_desc.fragment_func.entry = "main"; shader_desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; shader_desc.views[0].texture.multisampled = false; shader_desc.views[0].texture.image_type = SG_IMAGETYPE_2D; shader_desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; shader_desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; shader_desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; shader_desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; shader_desc.texture_sampler_pairs[0].view_slot = 0; shader_desc.texture_sampler_pairs[0].sampler_slot = 0; shader_desc.texture_sampler_pairs[0].glsl_name = "tex"; #elif defined(SOKOL_METAL) shader_desc.vertex_func.source = batch_shader_source; shader_desc.vertex_func.entry = "vs_main"; shader_desc.fragment_func.source = batch_shader_source; shader_desc.fragment_func.entry = "fs_main"; shader_desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; shader_desc.views[0].texture.multisampled = false; shader_desc.views[0].texture.image_type = SG_IMAGETYPE_2D; shader_desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; shader_desc.views[0].texture.msl_texture_n = 0; shader_desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; shader_desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; shader_desc.samplers[0].msl_sampler_n = 0; shader_desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; shader_desc.texture_sampler_pairs[0].view_slot = 0; shader_desc.texture_sampler_pairs[0].sampler_slot = 0; #endif shader_ = sg_make_shader(&shader_desc); if (shader_.id == SG_INVALID_ID) { fprintf(stderr, "BatchRenderer: Failed to create shader\n"); return false; } // Create vertex buffer (streaming) sg_buffer_desc vbuf_desc = {}; vbuf_desc.size = MAX_VERTICES * sizeof(BatchVertex); vbuf_desc.usage.vertex_buffer = true; vbuf_desc.usage.immutable = false; vbuf_desc.usage.stream_update = true; vbuf_desc.label = "batch_vertices"; vertex_buffer_ = sg_make_buffer(&vbuf_desc); // Create index buffer (streaming) sg_buffer_desc ibuf_desc = {}; ibuf_desc.size = MAX_INDICES * sizeof(uint16_t); ibuf_desc.usage.index_buffer = true; ibuf_desc.usage.immutable = false; ibuf_desc.usage.stream_update = true; ibuf_desc.label = "batch_indices"; index_buffer_ = sg_make_buffer(&ibuf_desc); // Create 1x1 white texture uint32_t white_pixel = 0xFFFFFFFF; sg_image_desc img_desc = {}; img_desc.width = 1; img_desc.height = 1; img_desc.pixel_format = SG_PIXELFORMAT_RGBA8; img_desc.data.mip_levels[0].ptr = &white_pixel; img_desc.data.mip_levels[0].size = sizeof(white_pixel); img_desc.label = "batch_white"; white_texture_ = sg_make_image(&img_desc); // Create view for white texture sg_view_desc view_desc = {}; view_desc.texture.image = white_texture_; white_view_ = sg_make_view(&view_desc); // Create default sampler sg_sampler_desc smp_desc = {}; smp_desc.min_filter = SG_FILTER_LINEAR; smp_desc.mag_filter = SG_FILTER_LINEAR; smp_desc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; smp_desc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; smp_desc.label = "batch_sampler"; default_sampler_ = sg_make_sampler(&smp_desc); // Initialize pipeline cache with default shader and vertex layout sg_vertex_layout_state vertex_layout = {}; vertex_layout.attrs[0].format = SG_VERTEXFORMAT_FLOAT2; // position vertex_layout.attrs[1].format = SG_VERTEXFORMAT_FLOAT2; // texcoord vertex_layout.attrs[2].format = SG_VERTEXFORMAT_UBYTE4N; // color (normalized) pipeline_cache_.init(shader_, vertex_layout); // Reserve capacity for vertex/index buffers vertices_.reserve(MAX_VERTICES); indices_.reserve(MAX_INDICES); // Set initial pending state to use white texture view pending_state_.texture_view = white_view_; pending_state_.sampler = default_sampler_; pending_state_.blend = BlendState::Alpha(); pending_state_.primitive = PrimitiveType::Triangles; pending_state_.color_mask = ColorMask::All(); pending_state_.shader_id = 0; initialized_ = true; return true; } void BatchRenderer::shutdown() { if (!initialized_) { return; } pipeline_cache_.shutdown(); if (shader_.id != SG_INVALID_ID) { sg_destroy_shader(shader_); shader_.id = SG_INVALID_ID; } if (vertex_buffer_.id != SG_INVALID_ID) { sg_destroy_buffer(vertex_buffer_); vertex_buffer_.id = SG_INVALID_ID; } if (index_buffer_.id != SG_INVALID_ID) { sg_destroy_buffer(index_buffer_); index_buffer_.id = SG_INVALID_ID; } if (default_sampler_.id != SG_INVALID_ID) { sg_destroy_sampler(default_sampler_); default_sampler_.id = SG_INVALID_ID; } if (white_view_.id != SG_INVALID_ID) { sg_destroy_view(white_view_); white_view_.id = SG_INVALID_ID; } if (white_texture_.id != SG_INVALID_ID) { sg_destroy_image(white_texture_); white_texture_.id = SG_INVALID_ID; } vertices_.clear(); indices_.clear(); transform_stack_.clear(); initialized_ = false; } sg_pipeline BatchRenderer::getPipeline() { PipelineKey key = PipelineKey::make( current_state_.shader_id, current_state_.blend, current_state_.primitive, current_state_.color_mask ); return pipeline_cache_.get(key); } void BatchRenderer::beginFrame(int logicalW, int logicalH, int pixelW, int pixelH) { frame_width_ = logicalW; frame_height_ = logicalH; pixel_width_ = pixelW > 0 ? pixelW : logicalW; pixel_height_ = pixelH > 0 ? pixelH : logicalH; dpi_scale_ = static_cast<float>(pixel_width_) / static_cast<float>(frame_width_); in_frame_ = true; // Reset debug stats flush_count_ = 0; draw_call_count_ = 0; // Reset state vertices_.clear(); indices_.clear(); transform_stack_.clear(); current_transform_.identity(); // Reset to default state pending_state_.texture_view = white_view_; pending_state_.sampler = default_sampler_; pending_state_.blend = BlendState::Alpha(); pending_state_.primitive = PrimitiveType::Triangles; pending_state_.color_mask = ColorMask::All(); pending_state_.shader_id = 0; current_state_ = pending_state_; color_r_ = 255; color_g_ = 255; color_b_ = 255; color_a_ = 255; scissor_enabled_ = false; current_shader_ = nullptr; } void BatchRenderer::endFrame() { flush(); in_frame_ = false; } void BatchRenderer::buildTransformMatrix(float* out) const { // Convert 2D affine transform to 4x4 matrix (column-major) memset(out, 0, 16 * sizeof(float)); out[0] = current_transform_.m[0]; // a out[1] = current_transform_.m[3]; // c out[4] = current_transform_.m[1]; // b out[5] = current_transform_.m[4]; // d out[10] = 1.0f; out[12] = current_transform_.m[2]; // tx out[13] = current_transform_.m[5]; // ty out[15] = 1.0f; } void BatchRenderer::buildProjectionMatrix(float* out) const { // Orthographic projection: (0,0)-(width,height) to clip-space (-1,-1)-(1,1) // Y is flipped so (0,0) is top-left float w = static_cast<float>(frame_width_); float h = static_cast<float>(frame_height_); memset(out, 0, 16 * sizeof(float)); out[0] = 2.0f / w; out[5] = -2.0f / h; // Flip Y out[10] = -1.0f; out[12] = -1.0f; out[13] = 1.0f; out[15] = 1.0f; } void BatchRenderer::flush() { if (vertices_.empty()) { return; } flush_count_++; draw_call_count_++; // Upload vertex data using append (allows multiple updates per frame) sg_range vrange = {vertices_.data(), vertices_.size() * sizeof(BatchVertex)}; int vertex_offset = sg_append_buffer(vertex_buffer_, &vrange); // Upload index data if we have any bool use_indices = !indices_.empty(); int index_offset = 0; if (use_indices) { sg_range irange = {indices_.data(), indices_.size() * sizeof(uint16_t)}; index_offset = sg_append_buffer(index_buffer_, &irange); } // Build uniform data BuiltinUniforms uniforms; buildTransformMatrix(uniforms.transformMatrix); buildProjectionMatrix(uniforms.projectionMatrix); uniforms.screenSize[0] = static_cast<float>(pixel_width_); uniforms.screenSize[1] = static_cast<float>(pixel_height_); // screenSize.z and .w are used for Y-flip in love_PixelCoord: // love_PixelCoord.y = gl_FragCoord.y * z + w // For Y-flip (OpenGL bottom-left to Love2D top-left): z=-1, w=height uniforms.screenSize[2] = -1.0f; uniforms.screenSize[3] = static_cast<float>(pixel_height_); uniforms.constantColor[0] = color_r_ / 255.0f; uniforms.constantColor[1] = color_g_ / 255.0f; uniforms.constantColor[2] = color_b_ / 255.0f; uniforms.constantColor[3] = color_a_ / 255.0f; // Apply pipeline and uniforms sg_pipeline pip; if (current_shader_ && current_shader_->isValid()) { // Custom shader path pip = current_shader_->getPipeline(current_state_.primitive, current_state_.blend); sg_apply_pipeline(pip); current_shader_->setBuiltinUniforms(uniforms.transformMatrix, uniforms.projectionMatrix, uniforms.screenSize, uniforms.constantColor); current_shader_->applyUniforms(); } else { // Default shader path pip = getPipeline(); sg_apply_pipeline(pip); sg_range uniform_range = {&uniforms, sizeof(uniforms)}; sg_apply_uniforms(0, &uniform_range); } // Set up bindings with offsets from append sg_bindings bindings = {}; bindings.vertex_buffers[0] = vertex_buffer_; bindings.vertex_buffer_offsets[0] = vertex_offset; if (use_indices) { bindings.index_buffer = index_buffer_; bindings.index_buffer_offset = index_offset; } // Bind texture view and sampler if (current_state_.texture_view.id == SG_INVALID_ID) { bindings.views[0] = white_view_; bindings.samplers[0] = default_sampler_; } else { bindings.views[0] = current_state_.texture_view; bindings.samplers[0] = current_state_.sampler.id != SG_INVALID_ID ? current_state_.sampler : default_sampler_; } sg_apply_bindings(&bindings); // Draw if (use_indices) { sg_draw(0, static_cast<int>(indices_.size()), 1); } else { sg_draw(0, static_cast<int>(vertices_.size()), 1); } // Clear for next batch vertices_.clear(); indices_.clear(); } void BatchRenderer::flushIfStateChanged() { if (pending_state_ != current_state_) { flush(); current_state_ = pending_state_; } } void BatchRenderer::ensureCapacity(size_t vertex_count, size_t index_count) { if (vertices_.size() + vertex_count > MAX_VERTICES || indices_.size() + index_count > MAX_INDICES) { flush(); } } BatchVertex *BatchRenderer::allocVertices(size_t count) { size_t start = vertices_.size(); vertices_.resize(start + count); return &vertices_[start]; } void BatchRenderer::addQuadIndices() { size_t base = vertices_.size() - 4; indices_.push_back(static_cast<uint16_t>(base + 0)); indices_.push_back(static_cast<uint16_t>(base + 1)); indices_.push_back(static_cast<uint16_t>(base + 2)); indices_.push_back(static_cast<uint16_t>(base + 0)); indices_.push_back(static_cast<uint16_t>(base + 2)); indices_.push_back(static_cast<uint16_t>(base + 3)); } // ============================================================================ // State Management // ============================================================================ void BatchRenderer::setColor(float r, float g, float b, float a) { color_r_ = static_cast<uint8_t>(r * 255.0f); color_g_ = static_cast<uint8_t>(g * 255.0f); color_b_ = static_cast<uint8_t>(b * 255.0f); color_a_ = static_cast<uint8_t>(a * 255.0f); } void BatchRenderer::getColor(float *r, float *g, float *b, float *a) const { *r = color_r_ / 255.0f; *g = color_g_ / 255.0f; *b = color_b_ / 255.0f; *a = color_a_ / 255.0f; } void BatchRenderer::setBlendMode(BlendMode mode) { pending_state_.blend = blendModeToState(mode); } BlendMode BatchRenderer::getBlendMode() const { return stateToBlendMode(pending_state_.blend); } void BatchRenderer::setColorMask(const ColorMask &mask) { pending_state_.color_mask = mask; } void BatchRenderer::setTexture(sg_view view, sg_sampler smp) { pending_state_.texture_view = view; pending_state_.sampler = smp; } void BatchRenderer::resetTexture() { pending_state_.texture_view = white_view_; pending_state_.sampler = default_sampler_; } void BatchRenderer::setShader(Shader *shader) { Shader *new_shader = (shader && shader->isValid()) ? shader : nullptr; // Flush before changing shader if (new_shader != current_shader_ && !vertices_.empty()) { flush(); } current_shader_ = new_shader; current_state_.shader_id = new_shader ? new_shader->getShaderID() : 0; pending_state_.shader_id = current_state_.shader_id; } void BatchRenderer::resetShader() { setShader(nullptr); } void BatchRenderer::setLineWidth(float width) { line_width_ = width; } // ============================================================================ // Transform Stack // ============================================================================ void BatchRenderer::pushTransform() { flush(); transform_stack_.push_back(current_transform_); } void BatchRenderer::popTransform() { if (!transform_stack_.empty()) { flush(); current_transform_ = transform_stack_.back(); transform_stack_.pop_back(); } } void BatchRenderer::translate(float x, float y) { flush(); current_transform_.translate(x, y); } void BatchRenderer::rotate(float radians) { flush(); current_transform_.rotate(radians); } void BatchRenderer::scale(float sx, float sy) { flush(); current_transform_.scale(sx, sy); } void BatchRenderer::resetTransform() { flush(); current_transform_.identity(); } // ============================================================================ // Drawing Primitives // ============================================================================ void BatchRenderer::drawFilledRect(float x, float y, float w, float h) { pending_state_.primitive = PrimitiveType::Triangles; pending_state_.texture_view = white_view_; pending_state_.sampler = default_sampler_; flushIfStateChanged(); ensureCapacity(4, 6); BatchVertex *v = allocVertices(4); v[0] = {x, y, 0, 0, color_r_, color_g_, color_b_, color_a_}; v[1] = {x + w, y, 1, 0, color_r_, color_g_, color_b_, color_a_}; v[2] = {x + w, y + h, 1, 1, color_r_, color_g_, color_b_, color_a_}; v[3] = {x, y + h, 0, 1, color_r_, color_g_, color_b_, color_a_}; addQuadIndices(); } void BatchRenderer::drawFilledTriangle(float x1, float y1, float x2, float y2, float x3, float y3) { pending_state_.primitive = PrimitiveType::Triangles; pending_state_.texture_view = white_view_; pending_state_.sampler = default_sampler_; flushIfStateChanged(); ensureCapacity(3, 3); size_t base = vertices_.size(); BatchVertex *v = allocVertices(3); v[0] = {x1, y1, 0, 0, color_r_, color_g_, color_b_, color_a_}; v[1] = {x2, y2, 0, 0, color_r_, color_g_, color_b_, color_a_}; v[2] = {x3, y3, 0, 0, color_r_, color_g_, color_b_, color_a_}; indices_.push_back(static_cast<uint16_t>(base + 0)); indices_.push_back(static_cast<uint16_t>(base + 1)); indices_.push_back(static_cast<uint16_t>(base + 2)); } void BatchRenderer::drawFilledCircle(float cx, float cy, float radius, int segments) { pending_state_.primitive = PrimitiveType::Triangles; pending_state_.texture_view = white_view_; pending_state_.sampler = default_sampler_; flushIfStateChanged(); size_t vertex_count = 1 + segments; size_t index_count = segments * 3; ensureCapacity(vertex_count, index_count); size_t base = vertices_.size(); // Center vertex BatchVertex *v = allocVertices(1); v[0] = {cx, cy, 0.5f, 0.5f, color_r_, color_g_, color_b_, color_a_}; // Perimeter vertices v = allocVertices(segments); for (int i = 0; i < segments; i++) { float angle = static_cast<float>(i) * 2.0f * 3.14159265f / static_cast<float>(segments); float px = cx + radius * cosf(angle); float py = cy + radius * sinf(angle); v[i] = {px, py, 0, 0, color_r_, color_g_, color_b_, color_a_}; } // Create triangle fan indices for (int i = 0; i < segments; i++) { int next = (i + 1) % segments; indices_.push_back(static_cast<uint16_t>(base)); indices_.push_back(static_cast<uint16_t>(base + 1 + i)); indices_.push_back(static_cast<uint16_t>(base + 1 + next)); } } void BatchRenderer::drawFilledPolygon(const float *points, int count) { if (count < 3) return; pending_state_.primitive = PrimitiveType::Triangles; pending_state_.texture_view = white_view_; pending_state_.sampler = default_sampler_; flushIfStateChanged(); size_t vertex_count = count; size_t index_count = (count - 2) * 3; ensureCapacity(vertex_count, index_count); size_t base = vertices_.size(); BatchVertex *v = allocVertices(count); for (int i = 0; i < count; i++) { float px = points[i * 2]; float py = points[i * 2 + 1]; v[i] = {px, py, 0, 0, color_r_, color_g_, color_b_, color_a_}; } for (int i = 1; i < count - 1; i++) { indices_.push_back(static_cast<uint16_t>(base)); indices_.push_back(static_cast<uint16_t>(base + i)); indices_.push_back(static_cast<uint16_t>(base + i + 1)); } } void BatchRenderer::drawRect(float x, float y, float w, float h) { float points[8] = { x, y, x + w, y, x + w, y + h, x, y + h }; drawPolyline(points, 4, true); } void BatchRenderer::drawLine(float x1, float y1, float x2, float y2) { if (line_width_ <= 1.0f) { pending_state_.primitive = PrimitiveType::Lines; pending_state_.texture_view = white_view_; pending_state_.sampler = default_sampler_; flushIfStateChanged(); ensureCapacity(2, 2); size_t base = vertices_.size(); BatchVertex *v = allocVertices(2); v[0] = {x1, y1, 0, 0, color_r_, color_g_, color_b_, color_a_}; v[1] = {x2, y2, 0, 0, color_r_, color_g_, color_b_, color_a_}; indices_.push_back(static_cast<uint16_t>(base)); indices_.push_back(static_cast<uint16_t>(base + 1)); } else { pending_state_.primitive = PrimitiveType::Triangles; pending_state_.texture_view = white_view_; pending_state_.sampler = default_sampler_; flushIfStateChanged(); ensureCapacity(4, 6); float dx = x2 - x1; float dy = y2 - y1; float length = sqrtf(dx * dx + dy * dy); if (length < 0.0001f) return; float half_width = line_width_ * 0.5f; float px = (-dy / length) * half_width; float py = (dx / length) * half_width; BatchVertex *v = allocVertices(4); v[0] = {x1 + px, y1 + py, 0, 0, color_r_, color_g_, color_b_, color_a_}; v[1] = {x2 + px, y2 + py, 1, 0, color_r_, color_g_, color_b_, color_a_}; v[2] = {x2 - px, y2 - py, 1, 1, color_r_, color_g_, color_b_, color_a_}; v[3] = {x1 - px, y1 - py, 0, 1, color_r_, color_g_, color_b_, color_a_}; addQuadIndices(); } } void BatchRenderer::drawCircle(float cx, float cy, float radius, int segments) { std::vector<float> points(segments * 2); for (int i = 0; i < segments; i++) { float angle = static_cast<float>(i) * 2.0f * 3.14159265f / static_cast<float>(segments); points[i * 2] = cx + radius * cosf(angle); points[i * 2 + 1] = cy + radius * sinf(angle); } drawPolyline(points.data(), segments, true); } void BatchRenderer::drawPolygon(const float *points, int count) { if (count < 2) return; drawPolyline(points, count, true); } void BatchRenderer::drawPoint(float x, float y) { pending_state_.primitive = PrimitiveType::Points; pending_state_.texture_view = white_view_; pending_state_.sampler = default_sampler_; flushIfStateChanged(); ensureCapacity(1, 1); size_t base = vertices_.size(); BatchVertex *v = allocVertices(1); v[0] = {x, y, 0, 0, color_r_, color_g_, color_b_, color_a_}; indices_.push_back(static_cast<uint16_t>(base)); } void BatchRenderer::drawPolyline(const float *points, int count, bool closed) { if (count < 2) return; if (line_width_ <= 1.0f) { pending_state_.primitive = PrimitiveType::Lines; pending_state_.texture_view = white_view_; pending_state_.sampler = default_sampler_; flushIfStateChanged(); int num_segments = closed ? count : count - 1; ensureCapacity(count, num_segments * 2); size_t base = vertices_.size(); BatchVertex *v = allocVertices(count); for (int i = 0; i < count; i++) { float px = points[i * 2]; float py = points[i * 2 + 1]; v[i] = {px, py, 0, 0, color_r_, color_g_, color_b_, color_a_}; } for (int i = 0; i < num_segments; i++) { int next = (i + 1) % count; indices_.push_back(static_cast<uint16_t>(base + i)); indices_.push_back(static_cast<uint16_t>(base + next)); } return; } // Thick lines as triangle strip with miter joins pending_state_.primitive = PrimitiveType::Triangles; pending_state_.texture_view = white_view_; pending_state_.sampler = default_sampler_; flushIfStateChanged(); float half_width = line_width_ * 0.5f; int num_segments = closed ? count : count - 1; size_t vertex_count = count * 2; size_t index_count = num_segments * 6; ensureCapacity(vertex_count, index_count); std::vector<float> normals_x(count); std::vector<float> normals_y(count); for (int i = 0; i < count; i++) { int prev_idx = closed ? (i - 1 + count) % count : (i > 0 ? i - 1 : i); int next_idx = closed ? (i + 1) % count : (i < count - 1 ? i + 1 : i); float px = points[i * 2]; float py = points[i * 2 + 1]; float prev_x = points[prev_idx * 2]; float prev_y = points[prev_idx * 2 + 1]; float next_x = points[next_idx * 2]; float next_y = points[next_idx * 2 + 1]; float d1x = px - prev_x; float d1y = py - prev_y; float d2x = next_x - px; float d2y = next_y - py; float len1 = sqrtf(d1x * d1x + d1y * d1y); float len2 = sqrtf(d2x * d2x + d2y * d2y); if (len1 < 0.0001f) { d1x = d2x; d1y = d2y; len1 = len2; } if (len2 < 0.0001f) { d2x = d1x; d2y = d1y; len2 = len1; } if (len1 > 0.0001f) { d1x /= len1; d1y /= len1; } if (len2 > 0.0001f) { d2x /= len2; d2y /= len2; } float n1x = -d1y, n1y = d1x; float n2x = -d2y, n2y = d2x; float nx = n1x + n2x, ny = n1y + n2y; float nlen = sqrtf(nx * nx + ny * ny); if (nlen < 0.0001f) { nx = n1x; ny = n1y; nlen = 1.0f; } else { nx /= nlen; ny /= nlen; } float dot = n1x * nx + n1y * ny; if (dot < 0.1f) dot = 0.1f; float miter_scale = half_width / dot; float max_miter = half_width * 4.0f; if (miter_scale > max_miter) miter_scale = max_miter; normals_x[i] = nx * miter_scale; normals_y[i] = ny * miter_scale; } size_t base = vertices_.size(); BatchVertex *v = allocVertices(vertex_count); for (int i = 0; i < count; i++) { float px = points[i * 2]; float py = points[i * 2 + 1]; v[i * 2] = {px + normals_x[i], py + normals_y[i], 0, 0, color_r_, color_g_, color_b_, color_a_}; v[i * 2 + 1] = {px - normals_x[i], py - normals_y[i], 0, 0, color_r_, color_g_, color_b_, color_a_}; } for (int i = 0; i < num_segments; i++) { int curr = i; int next = (i + 1) % count; indices_.push_back(static_cast<uint16_t>(base + curr * 2)); indices_.push_back(static_cast<uint16_t>(base + curr * 2 + 1)); indices_.push_back(static_cast<uint16_t>(base + next * 2)); indices_.push_back(static_cast<uint16_t>(base + curr * 2 + 1)); indices_.push_back(static_cast<uint16_t>(base + next * 2 + 1)); indices_.push_back(static_cast<uint16_t>(base + next * 2)); } } void BatchRenderer::drawTexturedRect(float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh, int tex_width, int tex_height) { pending_state_.primitive = PrimitiveType::Triangles; flushIfStateChanged(); ensureCapacity(4, 6); float u0 = sx / tex_width; float v0 = sy / tex_height; float u1 = (sx + sw) / tex_width; float v1 = (sy + sh) / tex_height; BatchVertex *v = allocVertices(4); v[0] = {dx, dy, u0, v0, color_r_, color_g_, color_b_, color_a_}; v[1] = {dx + dw, dy, u1, v0, color_r_, color_g_, color_b_, color_a_}; v[2] = {dx + dw, dy + dh, u1, v1, color_r_, color_g_, color_b_, color_a_}; v[3] = {dx, dy + dh, u0, v1, color_r_, color_g_, color_b_, color_a_}; addQuadIndices(); } // ============================================================================ // Viewport/Scissor // ============================================================================ void BatchRenderer::setScissor(int x, int y, int w, int h) { flush(); sg_apply_scissor_rect(x, y, w, h, true); scissor_enabled_ = true; scissor_x_ = x; scissor_y_ = y; scissor_w_ = w; scissor_h_ = h; } void BatchRenderer::resetScissor() { if (scissor_enabled_) { flush(); sg_apply_scissor_rect(0, 0, frame_width_, frame_height_, true); scissor_enabled_ = false; } } void BatchRenderer::clear(float r, float g, float b, float a) { uint8_t old_r = color_r_, old_g = color_g_, old_b = color_b_, old_a = color_a_; sg_view old_view = pending_state_.texture_view; sg_sampler old_smp = pending_state_.sampler; Transform2D old_transform = current_transform_; setColor(r, g, b, a); resetTexture(); current_transform_.identity(); drawFilledRect(0, 0, static_cast<float>(frame_width_), static_cast<float>(frame_height_)); current_transform_ = old_transform; color_r_ = old_r; color_g_ = old_g; color_b_ = old_b; color_a_ = old_a; pending_state_.texture_view = old_view; pending_state_.sampler = old_smp; } void BatchRenderer::submitFontTriangles( sg_view texture_view, sg_sampler sampler, const float* positions, const float* texcoords, const uint32_t* colors, int nverts, uint16_t shader_id ) { if (nverts <= 0) return; // Flush existing batch if state changes if (pending_state_.texture_view.id != texture_view.id || pending_state_.sampler.id != sampler.id || pending_state_.shader_id != shader_id || pending_state_.primitive != PrimitiveType::Triangles) { flush(); pending_state_.texture_view = texture_view; pending_state_.sampler = sampler; pending_state_.shader_id = shader_id; pending_state_.primitive = PrimitiveType::Triangles; current_state_ = pending_state_; } // Check capacity ensureCapacity(nverts, nverts); // Add vertices size_t base = vertices_.size(); BatchVertex* v = allocVertices(nverts); for (int i = 0; i < nverts; i++) { uint32_t c = colors[i]; v[i].x = positions[i * 2]; v[i].y = positions[i * 2 + 1]; v[i].u = texcoords[i * 2]; v[i].v = texcoords[i * 2 + 1]; v[i].r = static_cast<uint8_t>(c & 0xFF); v[i].g = static_cast<uint8_t>((c >> 8) & 0xFF); v[i].b = static_cast<uint8_t>((c >> 16) & 0xFF); v[i].a = static_cast<uint8_t>((c >> 24) & 0xFF); } // Add indices (triangles are already in order) for (int i = 0; i < nverts; i++) { indices_.push_back(static_cast<uint16_t>(base + i)); } } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/batch_renderer.hh
C++ Header
#pragma once #include "sokol_gfx.h" #include "renderstate.hh" #include "pipeline_cache.hh" #include <vector> #include <cstdint> namespace joy { namespace modules { class Shader; // Vertex format: 20 bytes per vertex // Position is CPU-transformed and stored in NDC struct BatchVertex { float x, y; // Position (NDC after CPU transform) float u, v; // Texcoord uint8_t r, g, b, a; // Color (RGBA8) }; // 2D affine transformation matrix (2x3) // | a b tx | // | c d ty | struct Transform2D { float m[6]; // [a, b, tx, c, d, ty] void identity(); void translate(float x, float y); void rotate(float radians); void scale(float sx, float sy); void multiply(const Transform2D &other); void transformPoint(float &x, float &y) const; static Transform2D Identity(); bool operator==(const Transform2D &other) const; bool operator!=(const Transform2D &other) const { return !(*this == other); } }; // 4x4 matrix for GPU uniforms (column-major for OpenGL/Metal) struct Matrix4 { float m[16]; void identity(); void ortho(float left, float right, float bottom, float top, float near, float far); void multiply(const Matrix4 &other); // this = this * other void setFromTransform2D(const Transform2D &t); // Convert 2D affine to 4x4 static Matrix4 Identity(); }; // Batch state - changes trigger a flush struct BatchState { sg_view texture_view; // SG_INVALID_ID for white texture sg_sampler sampler; // SG_INVALID_ID for default BlendState blend; // Low-level blend configuration PrimitiveType primitive; Transform2D transform; // Current transform (changes trigger flush) ColorMask color_mask; // Color channel write mask uint16_t shader_id; // 0 = default shader, or custom shader ID bool operator==(const BatchState &other) const; bool operator!=(const BatchState &other) const { return !(*this == other); } }; // Built-in uniform data for custom shaders // Layout must match shader expectations: // - mat4 TransformProjectionMatrix (64 bytes) // - vec4 joy_ScreenSize (16 bytes) // - vec4 ConstantColor (16 bytes) // - vec4 joy_DPIScale (16 bytes, only .x is used) struct ShaderBuiltinUniforms { float transform_projection[16]; // mat4 float screen_size[4]; // vec4: x=width, y=height, z=Y-flip, w=offset float constant_color[4]; // vec4: current draw color float dpi_scale[4]; // vec4: only .x is used (DPI scale) }; // Main batch renderer class class BatchRenderer { public: // Configuration static constexpr size_t MAX_VERTICES = 64 * 1024; static constexpr size_t MAX_INDICES = 128 * 1024; BatchRenderer(); ~BatchRenderer(); // Lifecycle bool init(); void shutdown(); // Frame management void beginFrame(int logicalW, int logicalH, int pixelW = 0, int pixelH = 0); void endFrame(); // Manual flush void flush(); // State management void setColor(float r, float g, float b, float a); void getColor(float *r, float *g, float *b, float *a) const; // Blend mode (high-level API for backward compatibility) void setBlendMode(BlendMode mode); BlendMode getBlendMode() const; // Blend state (low-level API for full control) void setBlendState(const BlendState &state); const BlendState &getBlendState() const { return pending_state_.blend; } // Color mask void setColorMask(bool r, bool g, bool b, bool a); void setColorMask(const ColorMask &mask); const ColorMask &getColorMask() const { return pending_state_.color_mask; } void setTexture(sg_view view, sg_sampler smp); void resetTexture(); // Custom shader support void setShader(Shader *shader); void resetShader(); Shader *getShader() const { return current_shader_; } uint16_t getCurrentShaderID() const { return pending_state_.shader_id; } // DPI scale (for shader uniforms) void setDPIScale(float scale) { dpi_scale_ = scale; } float getDPIScale() const { return dpi_scale_; } // Rendering to canvas (affects Y-flip in shaders) void setRenderingToCanvas(bool rendering_to_canvas) { rendering_to_canvas_ = rendering_to_canvas; } bool isRenderingToCanvas() const { return rendering_to_canvas_; } // Line width void setLineWidth(float width); float getLineWidth() const { return line_width_; } // Transform stack void pushTransform(); void popTransform(); void translate(float x, float y); void rotate(float radians); void scale(float sx, float sy); void resetTransform(); const Transform2D &getCurrentTransform() const { return current_transform_; } // Drawing primitives (filled) void drawFilledRect(float x, float y, float w, float h); void drawFilledTriangle(float x1, float y1, float x2, float y2, float x3, float y3); void drawFilledCircle(float x, float y, float radius, int segments = 32); void drawFilledPolygon(const float *points, int count); // Drawing primitives (outline) void drawRect(float x, float y, float w, float h); void drawLine(float x1, float y1, float x2, float y2); void drawCircle(float x, float y, float radius, int segments = 32); void drawPolygon(const float *points, int count); void drawPoint(float x, float y); // Polyline with miter joins (for thick lines) void drawPolyline(const float *points, int count, bool closed); // Textured drawing void drawTexturedRect(float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh, int tex_width, int tex_height); // Viewport/scissor void setScissor(int x, int y, int w, int h); void resetScissor(); // Clear the screen void clear(float r, float g, float b, float a); // Debug stats int getFlushCount() const { return flush_count_; } int getDrawCallCount() const { return draw_call_count_; } // Pipeline cache access (for registering custom shaders) PipelineCache& getPipelineCache() { return pipeline_cache_; } // Submit font triangles with a custom shader // Used by TextRenderer for text rendering with R8 texture atlas void submitFontTriangles( sg_view texture_view, sg_sampler sampler, const float* positions, // [x0,y0, x1,y1, ...] nverts*2 floats const float* texcoords, // [u0,v0, u1,v1, ...] nverts*2 floats const uint32_t* colors, // packed RGBA per vertex, nverts values int nverts, uint16_t shader_id ); // Get default sampler (for TextRenderer) sg_sampler getDefaultSampler() const { return default_sampler_; } private: // Get pipeline for current state (uses cache) sg_pipeline getPipeline(); // Build transform/projection matrices for shader uniforms void buildTransformMatrix(float *out) const; void buildProjectionMatrix(float *out) const; // Flush if state changed void flushIfStateChanged(); // Ensure capacity for vertices/indices void ensureCapacity(size_t vertex_count, size_t index_count); // Allocate vertices and return pointer BatchVertex *allocVertices(size_t count); // Add indices for a quad (assumes 4 vertices already added) void addQuadIndices(); // Sync current_transform_ to pending_state_ before drawing void syncTransform(); // Compute the combined projection * transform matrix for the shader uniform void computeCombinedMatrix(Matrix4 &out) const; // Resources sg_shader shader_; PipelineCache pipeline_cache_; sg_buffer vertex_buffer_; sg_buffer index_buffer_; sg_image white_texture_; sg_view white_view_; sg_sampler default_sampler_; // CPU-side vertex/index accumulation std::vector<BatchVertex> vertices_; std::vector<uint16_t> indices_; // Current and pending batch state BatchState current_state_; // What was last flushed BatchState pending_state_; // What we're accumulating // Transform stack std::vector<Transform2D> transform_stack_; Transform2D current_transform_; // Current color (applied to vertices) uint8_t color_r_, color_g_, color_b_, color_a_; // Line width float line_width_; // Custom shader state Shader *current_shader_; float dpi_scale_; bool rendering_to_canvas_; // Frame state int frame_width_, frame_height_; int pixel_width_, pixel_height_; // Actual pixel dimensions (for hiDPI) bool in_frame_; bool initialized_; // Projection matrix (orthographic, set each frame) Matrix4 projection_; // Debug stats int flush_count_; int draw_call_count_; // Scissor state bool scissor_enabled_; int scissor_x_, scissor_y_, scissor_w_, scissor_h_; }; } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/canvas.cc
C++
#include "canvas.hh" #include <cstdio> #include <cstring> namespace joy { namespace modules { Canvas::Canvas() : color_image_({SG_INVALID_ID}) , color_view_({SG_INVALID_ID}) , texture_view_({SG_INVALID_ID}) , attachments_({}) , depth_image_({SG_INVALID_ID}) , depth_view_({SG_INVALID_ID}) , sampler_({SG_INVALID_ID}) , width_(0) , height_(0) , pixel_format_(SG_PIXELFORMAT_RGBA8) , min_filter_(SG_FILTER_LINEAR) , mag_filter_(SG_FILTER_LINEAR) , wrap_u_(SG_WRAP_CLAMP_TO_EDGE) , wrap_v_(SG_WRAP_CLAMP_TO_EDGE) { } Canvas::~Canvas() { destroy(); } bool Canvas::create(int width, int height, const char *format) { if (width <= 0 || height <= 0) { fprintf(stderr, "Canvas: Invalid dimensions %dx%d\n", width, height); return false; } // Clean up any existing resources destroy(); width_ = width; height_ = height; // Parse format string if (format == nullptr || strcmp(format, "normal") == 0) { pixel_format_ = SG_PIXELFORMAT_RGBA8; } else if (strcmp(format, "hdr") == 0) { pixel_format_ = SG_PIXELFORMAT_RGBA16F; } else if (strcmp(format, "rgba8") == 0) { pixel_format_ = SG_PIXELFORMAT_RGBA8; } else if (strcmp(format, "rgba16f") == 0) { pixel_format_ = SG_PIXELFORMAT_RGBA16F; } else if (strcmp(format, "rgba32f") == 0) { pixel_format_ = SG_PIXELFORMAT_RGBA32F; } else { fprintf(stderr, "Canvas: Unknown format '%s', using RGBA8\n", format); pixel_format_ = SG_PIXELFORMAT_RGBA8; } // Create color render target image sg_image_desc color_desc = {}; color_desc.type = SG_IMAGETYPE_2D; color_desc.width = width; color_desc.height = height; color_desc.pixel_format = pixel_format_; color_desc.sample_count = 1; color_desc.usage.color_attachment = true; // Can render to it color_desc.label = "canvas_color"; color_image_ = sg_make_image(&color_desc); if (sg_query_image_state(color_image_) != SG_RESOURCESTATE_VALID) { fprintf(stderr, "Canvas: Failed to create color image\n"); destroy(); return false; } // Create view for rendering TO this canvas (as color attachment) sg_view_desc color_view_desc = {}; color_view_desc.color_attachment.image = color_image_; color_view_desc.label = "canvas_color_view"; color_view_ = sg_make_view(&color_view_desc); if (sg_query_view_state(color_view_) != SG_RESOURCESTATE_VALID) { fprintf(stderr, "Canvas: Failed to create color view\n"); destroy(); return false; } // Create view for sampling FROM this canvas (as texture) sg_view_desc tex_view_desc = {}; tex_view_desc.texture.image = color_image_; tex_view_desc.label = "canvas_texture_view"; texture_view_ = sg_make_view(&tex_view_desc); if (sg_query_view_state(texture_view_) != SG_RESOURCESTATE_VALID) { fprintf(stderr, "Canvas: Failed to create texture view\n"); destroy(); return false; } // Create depth/stencil buffer (optional but useful for many effects) sg_image_desc depth_desc = {}; depth_desc.type = SG_IMAGETYPE_2D; depth_desc.width = width; depth_desc.height = height; depth_desc.pixel_format = SG_PIXELFORMAT_DEPTH_STENCIL; depth_desc.sample_count = 1; depth_desc.usage.depth_stencil_attachment = true; depth_desc.label = "canvas_depth"; depth_image_ = sg_make_image(&depth_desc); if (sg_query_image_state(depth_image_) == SG_RESOURCESTATE_VALID) { // Create depth view sg_view_desc depth_view_desc = {}; depth_view_desc.depth_stencil_attachment.image = depth_image_; depth_view_desc.label = "canvas_depth_view"; depth_view_ = sg_make_view(&depth_view_desc); } // Create attachments struct for render pass attachments_.colors[0] = color_view_; if (depth_view_.id != SG_INVALID_ID) { attachments_.depth_stencil = depth_view_; } // Create sampler for texture sampling updateSampler(); return true; } void Canvas::destroy() { if (sampler_.id != SG_INVALID_ID) { sg_destroy_sampler(sampler_); sampler_.id = SG_INVALID_ID; } if (depth_view_.id != SG_INVALID_ID) { sg_destroy_view(depth_view_); depth_view_.id = SG_INVALID_ID; } if (depth_image_.id != SG_INVALID_ID) { sg_destroy_image(depth_image_); depth_image_.id = SG_INVALID_ID; } if (texture_view_.id != SG_INVALID_ID) { sg_destroy_view(texture_view_); texture_view_.id = SG_INVALID_ID; } if (color_view_.id != SG_INVALID_ID) { sg_destroy_view(color_view_); color_view_.id = SG_INVALID_ID; } if (color_image_.id != SG_INVALID_ID) { sg_destroy_image(color_image_); color_image_.id = SG_INVALID_ID; } attachments_ = {}; width_ = 0; height_ = 0; } void Canvas::updateSampler() { if (sampler_.id != SG_INVALID_ID) { sg_destroy_sampler(sampler_); } sg_sampler_desc smp_desc = {}; smp_desc.min_filter = min_filter_; smp_desc.mag_filter = mag_filter_; smp_desc.wrap_u = wrap_u_; smp_desc.wrap_v = wrap_v_; smp_desc.label = "canvas_sampler"; sampler_ = sg_make_sampler(&smp_desc); } void Canvas::setFilter(const char *min, const char *mag) { if (min) { if (strcmp(min, "nearest") == 0) { min_filter_ = SG_FILTER_NEAREST; } else { min_filter_ = SG_FILTER_LINEAR; } } if (mag) { if (strcmp(mag, "nearest") == 0) { mag_filter_ = SG_FILTER_NEAREST; } else { mag_filter_ = SG_FILTER_LINEAR; } } updateSampler(); } void Canvas::getFilter(const char **min, const char **mag) const { if (min) { *min = (min_filter_ == SG_FILTER_NEAREST) ? "nearest" : "linear"; } if (mag) { *mag = (mag_filter_ == SG_FILTER_NEAREST) ? "nearest" : "linear"; } } void Canvas::setWrap(const char *horiz, const char *vert) { if (horiz) { if (strcmp(horiz, "repeat") == 0) { wrap_u_ = SG_WRAP_REPEAT; } else if (strcmp(horiz, "mirroredrepeat") == 0) { wrap_u_ = SG_WRAP_MIRRORED_REPEAT; } else { wrap_u_ = SG_WRAP_CLAMP_TO_EDGE; } } if (vert) { if (strcmp(vert, "repeat") == 0) { wrap_v_ = SG_WRAP_REPEAT; } else if (strcmp(vert, "mirroredrepeat") == 0) { wrap_v_ = SG_WRAP_MIRRORED_REPEAT; } else { wrap_v_ = SG_WRAP_CLAMP_TO_EDGE; } } updateSampler(); } void Canvas::getWrap(const char **horiz, const char **vert) const { if (horiz) { switch (wrap_u_) { case SG_WRAP_REPEAT: *horiz = "repeat"; break; case SG_WRAP_MIRRORED_REPEAT: *horiz = "mirroredrepeat"; break; default: *horiz = "clamp"; break; } } if (vert) { switch (wrap_v_) { case SG_WRAP_REPEAT: *vert = "repeat"; break; case SG_WRAP_MIRRORED_REPEAT: *vert = "mirroredrepeat"; break; default: *vert = "clamp"; break; } } } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/canvas.hh
C++ Header
#pragma once #include "sokol_gfx.h" namespace joy { namespace modules { // Canvas - render-to-texture target (Love2D compatible) // A Canvas is both a render target and a drawable texture class Canvas { public: Canvas(); ~Canvas(); // Create a canvas with specified dimensions // format: "normal" (RGBA8), "hdr" (RGBA16F), etc. bool create(int width, int height, const char *format = "normal"); // Destroy GPU resources void destroy(); // Get dimensions int getWidth() const { return width_; } int getHeight() const { return height_; } // Get sokol handles for drawing TO this canvas (as render target) sg_attachments getAttachments() const { return attachments_; } // Get sokol handles for drawing WITH this canvas (as texture) sg_image getImage() const { return color_image_; } sg_view getTextureView() const { return texture_view_; } sg_sampler getSampler() const { return sampler_; } // Check if valid bool isValid() const { return color_image_.id != SG_INVALID_ID; } // Get pixel format sg_pixel_format getPixelFormat() const { return pixel_format_; } // Texture filtering (same as Texture) void setFilter(const char *min, const char *mag); void getFilter(const char **min, const char **mag) const; // Texture wrapping (same as Texture) void setWrap(const char *horiz, const char *vert); void getWrap(const char **horiz, const char **vert) const; private: // Render target resources sg_image color_image_; // Color attachment (render target) sg_view color_view_; // View for rendering to sg_view texture_view_; // View for sampling from sg_attachments attachments_; // Framebuffer attachments // Optional depth buffer (created if needed) sg_image depth_image_; sg_view depth_view_; // Sampler for texture sampling sg_sampler sampler_; // Dimensions and format int width_; int height_; sg_pixel_format pixel_format_; // Filter/wrap settings sg_filter min_filter_; sg_filter mag_filter_; sg_wrap wrap_u_; sg_wrap wrap_v_; // Helper to recreate sampler void updateSampler(); }; } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/graphics.cc
C++
#include "graphics.hh" #include "batch_renderer.hh" #include "text_renderer.hh" #include "canvas.hh" #include "shader.hh" #include "engine.hh" #include "sokol_gfx.h" #include "stb_image.h" #include "physfs.h" #include <cstring> #include <cmath> #include <cstdlib> // Embedded default font #include "ProggyClean.ttf.h" namespace joy { namespace modules { Graphics::Graphics(Engine *engine) : engine_(engine) , batch_(nullptr) , font_size_(20.0f) , blend_mode_str_("alpha") , line_width_(1.0f) , scissor_enabled_(false) , scissor_x_(0), scissor_y_(0), scissor_w_(0), scissor_h_(0) , text_renderer_(nullptr) , font_default_(FONS_INVALID) , font_current_(FONS_INVALID) , current_canvas_(nullptr) , swapchain_width_(0) , swapchain_height_(0) , swapchain_pixel_width_(0) , swapchain_pixel_height_(0) , current_shader_(nullptr) { // Default white color color_[0] = 1.0f; color_[1] = 1.0f; color_[2] = 1.0f; color_[3] = 1.0f; // Default black background bg_color_[0] = 0.0f; bg_color_[1] = 0.0f; bg_color_[2] = 0.0f; bg_color_[3] = 1.0f; } Graphics::~Graphics() { shutdownText(); shutdownBatchRenderer(); } bool Graphics::initBatchRenderer() { if (batch_) return true; batch_ = new BatchRenderer(); return batch_->init(); } void Graphics::shutdownBatchRenderer() { if (batch_) { batch_->shutdown(); delete batch_; batch_ = nullptr; } } void Graphics::beginFrame(int w, int h, int pw, int ph) { // Save swapchain dimensions for setCanvas switching // w, h = logical pixels (for projection/coordinates) // pw, ph = physical pixels (for render pass) swapchain_width_ = w; swapchain_height_ = h; swapchain_pixel_width_ = pw; swapchain_pixel_height_ = ph; current_canvas_ = nullptr; // Start rendering to screen current_shader_ = nullptr; // Reset shader at frame start if (batch_) { batch_->beginFrame(w, h, pw, ph); // Apply current color to batch renderer batch_->setColor(color_[0], color_[1], color_[2], color_[3]); // Set DPI scale for shader uniforms batch_->setDPIScale(getDPIScale()); batch_->setRenderingToCanvas(false); } } void Graphics::endFrame() { if (batch_) { batch_->endFrame(); } } void Graphics::setColor(float r, float g, float b, float a) { color_[0] = r; color_[1] = g; color_[2] = b; color_[3] = a; if (batch_) { batch_->setColor(r, g, b, a); } } void Graphics::getColor(float *r, float *g, float *b, float *a) { *r = color_[0]; *g = color_[1]; *b = color_[2]; *a = color_[3]; } void Graphics::setBackgroundColor(float r, float g, float b, float a) { bg_color_[0] = r; bg_color_[1] = g; bg_color_[2] = b; bg_color_[3] = a; } void Graphics::getBackgroundColor(float *r, float *g, float *b, float *a) { *r = bg_color_[0]; *g = bg_color_[1]; *b = bg_color_[2]; *a = bg_color_[3]; } void Graphics::rectangle(const char *mode, float x, float y, float w, float h) { if (!batch_) return; if (strcmp(mode, "fill") == 0) { batch_->drawFilledRect(x, y, w, h); } else if (strcmp(mode, "line") == 0) { batch_->drawRect(x, y, w, h); } } void Graphics::circle(const char *mode, float x, float y, float radius) { if (!batch_) return; if (strcmp(mode, "fill") == 0) { batch_->drawFilledCircle(x, y, radius); } else if (strcmp(mode, "line") == 0) { batch_->drawCircle(x, y, radius); } } void Graphics::line(float x1, float y1, float x2, float y2) { if (batch_) { batch_->drawLine(x1, y1, x2, y2); } } void Graphics::point(float x, float y) { if (batch_) { batch_->drawPoint(x, y); } } void Graphics::polygon(const char *mode, const float *points, int count) { if (!batch_) return; if (strcmp(mode, "fill") == 0) { batch_->drawFilledPolygon(points, count); } else if (strcmp(mode, "line") == 0) { batch_->drawPolygon(points, count); } } void Graphics::arc(const char *mode, const char *arctype, float x, float y, float radius, float angle1, float angle2, int segments) { if (!batch_) return; bool fill = strcmp(mode, "fill") == 0; bool is_pie = strcmp(arctype, "pie") == 0; bool is_closed = strcmp(arctype, "closed") == 0; // Calculate angle step float angle_diff = angle2 - angle1; if (fill || is_pie) { // Filled arc (pie shape) - uses triangle fan from center std::vector<float> points; // Center point points.push_back(x); points.push_back(y); // Arc points for (int i = 0; i <= segments; i++) { float angle = angle1 + angle_diff * static_cast<float>(i) / static_cast<float>(segments); points.push_back(x + radius * cosf(angle)); points.push_back(y + radius * sinf(angle)); } if (fill) { batch_->drawFilledPolygon(points.data(), static_cast<int>(points.size() / 2)); } else { // Pie outline - draw lines from center to arc and along arc batch_->drawPolygon(points.data(), static_cast<int>(points.size() / 2)); } } else { // Line arc std::vector<float> points; for (int i = 0; i <= segments; i++) { float angle = angle1 + angle_diff * static_cast<float>(i) / static_cast<float>(segments); points.push_back(x + radius * cosf(angle)); points.push_back(y + radius * sinf(angle)); } // Use polyline for proper miter joins batch_->drawPolyline(points.data(), static_cast<int>(points.size() / 2), is_closed); } } void Graphics::ellipse(const char *mode, float x, float y, float rx, float ry, int segments) { if (!batch_) return; std::vector<float> points(segments * 2); for (int i = 0; i < segments; i++) { float angle = static_cast<float>(i) * 2.0f * 3.14159265f / static_cast<float>(segments); points[i * 2] = x + rx * cosf(angle); points[i * 2 + 1] = y + ry * sinf(angle); } if (strcmp(mode, "fill") == 0) { batch_->drawFilledPolygon(points.data(), segments); } else if (strcmp(mode, "line") == 0) { // Use polyline for proper miter joins (closed ellipse) batch_->drawPolyline(points.data(), segments, true); } } void Graphics::setLineWidth(float width) { line_width_ = width; if (batch_) { batch_->setLineWidth(width); } } float Graphics::getLineWidth() const { return line_width_; } void Graphics::setScissor(int x, int y, int w, int h) { if (batch_) { // Convert from logical coordinates to pixel coordinates for hiDPI // Use effective DPI scale (1.0 when rendering to canvas) float dpi_scale = getEffectiveDPIScale(); int px = static_cast<int>(x * dpi_scale); int py = static_cast<int>(y * dpi_scale); int pw = static_cast<int>(w * dpi_scale); int ph = static_cast<int>(h * dpi_scale); batch_->setScissor(px, py, pw, ph); } scissor_enabled_ = true; scissor_x_ = x; scissor_y_ = y; scissor_w_ = w; scissor_h_ = h; } void Graphics::resetScissor() { if (batch_) { batch_->resetScissor(); } scissor_enabled_ = false; } bool Graphics::getScissor(int *x, int *y, int *w, int *h) const { if (!scissor_enabled_) { return false; } *x = scissor_x_; *y = scissor_y_; *w = scissor_w_; *h = scissor_h_; return true; } void Graphics::flush() { if (batch_) { batch_->flush(); } } void Graphics::pushTransform() { if (batch_) batch_->pushTransform(); } void Graphics::popTransform() { if (batch_) batch_->popTransform(); } void Graphics::translate(float x, float y) { if (batch_) batch_->translate(x, y); } void Graphics::rotate(float radians) { if (batch_) batch_->rotate(radians); } void Graphics::scale(float sx, float sy) { if (batch_) batch_->scale(sx, sy); } void Graphics::resetTransform() { if (batch_) batch_->resetTransform(); } void Graphics::setBlendMode(const char *mode) { if (!batch_) return; if (strcmp(mode, "alpha") == 0) { batch_->setBlendMode(BlendMode::Alpha); blend_mode_str_ = "alpha"; } else if (strcmp(mode, "add") == 0) { batch_->setBlendMode(BlendMode::Add); blend_mode_str_ = "add"; } else if (strcmp(mode, "multiply") == 0) { batch_->setBlendMode(BlendMode::Multiply); blend_mode_str_ = "multiply"; } else if (strcmp(mode, "replace") == 0) { batch_->setBlendMode(BlendMode::None); blend_mode_str_ = "replace"; } } const char *Graphics::getBlendMode() const { return blend_mode_str_; } bool Graphics::initText() { if (text_renderer_ != nullptr) { return true; // Already initialized } // Get DPI scale for sizing the font atlas appropriately float dpi_scale = getDPIScale(); // Create TextRenderer text_renderer_ = new TextRenderer(); if (!text_renderer_->init(batch_, dpi_scale)) { delete text_renderer_; text_renderer_ = nullptr; return false; } // Load embedded default font (ProggyClean - same as Nuklear) font_default_ = text_renderer_->addFont("default", ProggyClean_ttf, ProggyClean_ttf_len, false); if (font_default_ == FONS_INVALID) { fprintf(stderr, "Failed to load default font\n"); delete text_renderer_; text_renderer_ = nullptr; return false; } // Set default as current font font_current_ = font_default_; return true; } void Graphics::shutdownText() { if (text_renderer_) { text_renderer_->shutdown(); delete text_renderer_; text_renderer_ = nullptr; } } void Graphics::prepareText() { // No longer needed - TextRenderer uses BatchRenderer directly // Kept for API compatibility } void Graphics::flushText() { // Flush any pending atlas updates if (text_renderer_) { text_renderer_->flush(); } } void Graphics::print(const char *text, float x, float y) { if (!text_renderer_ || !text) { return; } // Get effective DPI scale (1.0 when rendering to canvas) float dpi_scale = getEffectiveDPIScale(); // Set font and DPI-scaled size for high-resolution glyph rendering text_renderer_->setFont(font_current_); text_renderer_->setSize(font_size_ * dpi_scale); // Use top-left alignment so y coordinate is the top of the text text_renderer_->setAlign(FONS_ALIGN_LEFT | FONS_ALIGN_TOP); // Set color text_renderer_->setColor( static_cast<uint8_t>(color_[0] * 255), static_cast<uint8_t>(color_[1] * 255), static_cast<uint8_t>(color_[2] * 255), static_cast<uint8_t>(color_[3] * 255) ); // Apply transform to position text and scale down high-res glyphs to logical size // FontStash generates vertices at dpi_scale size, so we scale down by 1/dpi_scale batch_->pushTransform(); batch_->translate(x, y); batch_->scale(1.0f / dpi_scale, 1.0f / dpi_scale); // Draw at origin (translation already applied) text_renderer_->drawText(0, 0, text); batch_->popTransform(); } FONScontext *Graphics::getFonsContext() { return text_renderer_ ? text_renderer_->getFonsContext() : nullptr; } int Graphics::getWidth() { SDL_Window *window = engine_->getWindow(); if (!window) { return 0; } int w, h; SDL_GetWindowSize(window, &w, &h); return w; } int Graphics::getHeight() { SDL_Window *window = engine_->getWindow(); if (!window) { return 0; } int w, h; SDL_GetWindowSize(window, &w, &h); return h; } int Graphics::getPixelWidth() { SDL_Window *window = engine_->getWindow(); if (!window) { return 0; } int w, h; SDL_GetWindowSizeInPixels(window, &w, &h); return w; } int Graphics::getPixelHeight() { SDL_Window *window = engine_->getWindow(); if (!window) { return 0; } int w, h; SDL_GetWindowSizeInPixels(window, &w, &h); return h; } float Graphics::getDPIScale() { SDL_Window *window = engine_->getWindow(); if (!window) { return 1.0f; } return SDL_GetWindowDisplayScale(window); } float Graphics::getEffectiveDPIScale() { // When rendering to a canvas, use 1.0 (canvas is a fixed pixel buffer) // When rendering to screen, use the window's DPI scale if (current_canvas_) { return 1.0f; } return getDPIScale(); } void Graphics::clear(float r, float g, float b, float a, bool use_color) { if (!batch_) return; if (use_color) { batch_->clear(r, g, b, a); } else { batch_->clear(bg_color_[0], bg_color_[1], bg_color_[2], bg_color_[3]); } } int Graphics::getFlushCount() const { return batch_ ? batch_->getFlushCount() : 0; } int Graphics::getDrawCallCount() const { return batch_ ? batch_->getDrawCallCount() : 0; } void Graphics::setFontSize(float size) { font_size_ = size; } void Graphics::setCurrentFont(int font_handle) { font_current_ = font_handle; } // ============================================================================ // Font class implementation // ============================================================================ Font::Font(Graphics *graphics, int font_handle, float size, float dpi_scale) : graphics_(graphics) , font_handle_(font_handle) , size_(size) , dpi_scale_(dpi_scale) , line_height_(1.0f) , filter_min_("linear") , filter_mag_("linear") { } Font::~Font() { // Font data is owned by fontstash, we don't free it here } float Font::getHeight() const { FONScontext *fons = graphics_->getFonsContext(); if (!fons) return size_; fonsSetFont(fons, font_handle_); fonsSetSize(fons, size_ * dpi_scale_); float ascender, descender, lineh; fonsVertMetrics(fons, &ascender, &descender, &lineh); // Return height in logical coordinates (not DPI-scaled) return lineh / dpi_scale_; } float Font::getAscent() const { FONScontext *fons = graphics_->getFonsContext(); if (!fons) return size_; fonsSetFont(fons, font_handle_); fonsSetSize(fons, size_ * dpi_scale_); float ascender, descender, lineh; fonsVertMetrics(fons, &ascender, &descender, &lineh); return ascender / dpi_scale_; } float Font::getDescent() const { FONScontext *fons = graphics_->getFonsContext(); if (!fons) return 0; fonsSetFont(fons, font_handle_); fonsSetSize(fons, size_ * dpi_scale_); float ascender, descender, lineh; fonsVertMetrics(fons, &ascender, &descender, &lineh); // Descent is typically negative return descender / dpi_scale_; } float Font::getBaseline() const { // In Love2D, baseline is typically the ascent return getAscent(); } float Font::getLineHeight() const { return line_height_; } void Font::setLineHeight(float height) { line_height_ = height; } float Font::getWidth(const char *text) const { FONScontext *fons = graphics_->getFonsContext(); if (!fons || !text) return 0; fonsSetFont(fons, font_handle_); fonsSetSize(fons, size_ * dpi_scale_); fonsSetAlign(fons, FONS_ALIGN_LEFT | FONS_ALIGN_TOP); // Handle newlines - find max width of all lines float max_width = 0; const char *line_start = text; const char *p = text; while (*p) { if (*p == '\n') { if (p > line_start) { float width = fonsTextBounds(fons, 0, 0, line_start, p, nullptr); if (width > max_width) max_width = width; } line_start = p + 1; } p++; } // Handle last line (or single line without newline) if (p > line_start) { float width = fonsTextBounds(fons, 0, 0, line_start, p, nullptr); if (width > max_width) max_width = width; } return max_width / dpi_scale_; } // Helper to decode UTF-8 codepoint static int decodeUTF8(const char **str) { const unsigned char *s = (const unsigned char *)*str; int codepoint; if (s[0] < 0x80) { codepoint = s[0]; *str += 1; } else if ((s[0] & 0xE0) == 0xC0) { codepoint = ((s[0] & 0x1F) << 6) | (s[1] & 0x3F); *str += 2; } else if ((s[0] & 0xF0) == 0xE0) { codepoint = ((s[0] & 0x0F) << 12) | ((s[1] & 0x3F) << 6) | (s[2] & 0x3F); *str += 3; } else if ((s[0] & 0xF8) == 0xF0) { codepoint = ((s[0] & 0x07) << 18) | ((s[1] & 0x3F) << 12) | ((s[2] & 0x3F) << 6) | (s[3] & 0x3F); *str += 4; } else { codepoint = 0xFFFD; // replacement character *str += 1; } return codepoint; } float Font::getWrap(const char *text, float wrap_limit, std::vector<std::string> &wrapped_lines) const { FONScontext *fons = graphics_->getFonsContext(); if (!fons || !text) return 0; fonsSetFont(fons, font_handle_); fonsSetSize(fons, size_ * dpi_scale_); fonsSetAlign(fons, FONS_ALIGN_LEFT | FONS_ALIGN_TOP); float scaled_limit = wrap_limit * dpi_scale_; float max_width = 0; std::string current_line; std::string current_word; float line_width = 0; const char *p = text; while (*p) { if (*p == '\n') { // Finish current word and line if (!current_word.empty()) { float word_width = fonsTextBounds(fons, 0, 0, current_word.c_str(), nullptr, nullptr); if (line_width + word_width > scaled_limit && !current_line.empty()) { wrapped_lines.push_back(current_line); if (line_width > max_width) max_width = line_width; current_line = current_word; line_width = word_width; } else { current_line += current_word; line_width += word_width; } current_word.clear(); } wrapped_lines.push_back(current_line); if (line_width > max_width) max_width = line_width; current_line.clear(); line_width = 0; p++; } else if (*p == ' ' || *p == '\t') { // Word boundary if (!current_word.empty()) { float word_width = fonsTextBounds(fons, 0, 0, current_word.c_str(), nullptr, nullptr); if (line_width + word_width > scaled_limit && !current_line.empty()) { wrapped_lines.push_back(current_line); if (line_width > max_width) max_width = line_width; current_line = current_word; line_width = word_width; } else { current_line += current_word; line_width += word_width; } current_word.clear(); } current_line += *p; float space_width = fonsTextBounds(fons, 0, 0, " ", nullptr, nullptr); line_width += space_width; p++; } else { current_word += *p; p++; } } // Finish last word and line if (!current_word.empty()) { float word_width = fonsTextBounds(fons, 0, 0, current_word.c_str(), nullptr, nullptr); if (line_width + word_width > scaled_limit && !current_line.empty()) { wrapped_lines.push_back(current_line); if (line_width > max_width) max_width = line_width; current_line = current_word; line_width = word_width; } else { current_line += current_word; line_width += word_width; } } if (!current_line.empty() || wrapped_lines.empty()) { wrapped_lines.push_back(current_line); if (line_width > max_width) max_width = line_width; } return max_width / dpi_scale_; } float Font::getKerning(const char *left, const char *right) const { if (!left || !right || !*left || !*right) return 0; const char *lp = left; const char *rp = right; int left_cp = decodeUTF8(&lp); int right_cp = decodeUTF8(&rp); return getKerning(left_cp, right_cp); } float Font::getKerning(int left_glyph, int right_glyph) const { // Fontstash doesn't expose direct kerning query, but handles it internally // For now, return 0 as fontstash handles kerning in text rendering (void)left_glyph; (void)right_glyph; return 0; } bool Font::hasGlyphs(const char *text) const { if (!text) return true; const char *p = text; while (*p) { int cp = decodeUTF8(&p); if (!hasGlyph(cp)) { return false; } } return true; } bool Font::hasGlyph(int codepoint) const { // Fontstash doesn't expose glyph existence check directly // Most TrueType fonts have a fallback glyph, so we return true // A more accurate check would require access to stb_truetype internals (void)codepoint; return true; } void Font::setFilter(const char *min, const char *mag) { filter_min_ = min; filter_mag_ = mag; // Note: Font filtering is handled by the texture atlas in fontstash // This stores the setting but doesn't actively apply it } void Font::getFilter(const char **min, const char **mag) const { *min = filter_min_; *mag = filter_mag_; } void Font::setFallbacks(const std::vector<Font*> &fallbacks) { FONScontext *fons = graphics_->getFonsContext(); if (!fons) return; for (Font *fallback : fallbacks) { if (fallback) { fonsAddFallbackFont(fons, font_handle_, fallback->getFontHandle()); } } } // ============================================================================ // Graphics font creation methods // ============================================================================ Font *Graphics::newFont(float size) { // Create font using default embedded font float dpi_scale = getDPIScale(); return new Font(this, font_default_, size, dpi_scale); } Font *Graphics::newFont(const char *filename, float size) { if (!text_renderer_ || !filename) return nullptr; // Read font file via PhysFS PHYSFS_File *file = PHYSFS_openRead(filename); if (!file) { fprintf(stderr, "Failed to open font file: %s\n", filename); return nullptr; } PHYSFS_sint64 file_size = PHYSFS_fileLength(file); if (file_size < 0) { PHYSFS_close(file); return nullptr; } unsigned char *data = static_cast<unsigned char *>(malloc(file_size)); if (!data) { PHYSFS_close(file); return nullptr; } PHYSFS_sint64 bytes_read = PHYSFS_readBytes(file, data, file_size); PHYSFS_close(file); if (bytes_read != file_size) { free(data); return nullptr; } // Add font to TextRenderer (it takes ownership of data when freeData=true) int font_handle = text_renderer_->addFont(filename, data, static_cast<int>(file_size), true); if (font_handle == FONS_INVALID) { free(data); fprintf(stderr, "Failed to load font: %s\n", filename); return nullptr; } float dpi_scale = getDPIScale(); return new Font(this, font_handle, size, dpi_scale); } Font *Graphics::newFontFromMemory(const unsigned char *data, int data_size, float font_size, const char *name) { if (!text_renderer_ || !data) return nullptr; // Copy data since fontstash may need to keep it unsigned char *data_copy = static_cast<unsigned char *>(malloc(data_size)); if (!data_copy) return nullptr; memcpy(data_copy, data, data_size); int font_handle = text_renderer_->addFont(name ? name : "custom", data_copy, data_size, true); if (font_handle == FONS_INVALID) { free(data_copy); return nullptr; } float dpi_scale = getDPIScale(); return new Font(this, font_handle, font_size, dpi_scale); } void Graphics::draw(Texture *texture, float x, float y, float r, float sx, float sy, float ox, float oy) { if (!texture || !texture->isValid() || !batch_) return; float srcW = static_cast<float>(texture->getWidth()); float srcH = static_cast<float>(texture->getHeight()); float w = srcW * sx; float h = srcH * sy; float dx = -ox * sx; float dy = -oy * sy; // Set texture view batch_->setTexture(texture->getView(), texture->getSampler()); if (r != 0) { batch_->pushTransform(); batch_->translate(x, y); batch_->rotate(r); batch_->drawTexturedRect(dx, dy, w, h, 0, 0, srcW, srcH, texture->getWidth(), texture->getHeight()); batch_->popTransform(); } else { batch_->drawTexturedRect(x + dx, y + dy, w, h, 0, 0, srcW, srcH, texture->getWidth(), texture->getHeight()); } } void Graphics::drawQuad(Texture *texture, float qx, float qy, float qw, float qh, float x, float y, float r, float sx, float sy, float ox, float oy) { if (!texture || !texture->isValid() || !batch_) return; float w = qw * sx; float h = qh * sy; float dx = -ox * sx; float dy = -oy * sy; // Set texture view batch_->setTexture(texture->getView(), texture->getSampler()); if (r != 0) { batch_->pushTransform(); batch_->translate(x, y); batch_->rotate(r); batch_->drawTexturedRect(dx, dy, w, h, qx, qy, qw, qh, texture->getWidth(), texture->getHeight()); batch_->popTransform(); } else { batch_->drawTexturedRect(x + dx, y + dy, w, h, qx, qy, qw, qh, texture->getWidth(), texture->getHeight()); } } // ============================================================================ // Quad class implementation // ============================================================================ Quad::Quad(float x, float y, float w, float h, float sw, float sh) : x_(x), y_(y), w_(w), h_(h), sw_(sw), sh_(sh) { } void Quad::setViewport(float x, float y, float w, float h) { x_ = x; y_ = y; w_ = w; h_ = h; } void Quad::setViewport(float x, float y, float w, float h, float sw, float sh) { x_ = x; y_ = y; w_ = w; h_ = h; sw_ = sw; sh_ = sh; } void Quad::getViewport(float *x, float *y, float *w, float *h) const { *x = x_; *y = y_; *w = w_; *h = h_; } void Quad::getTextureDimensions(float *sw, float *sh) const { *sw = sw_; *sh = sh_; } // Helper functions for filter/wrap string conversion static sg_filter filterFromString(const char *str) { if (strcmp(str, "nearest") == 0) return SG_FILTER_NEAREST; if (strcmp(str, "linear") == 0) return SG_FILTER_LINEAR; return SG_FILTER_LINEAR; // default } static const char *filterToString(sg_filter filter) { switch (filter) { case SG_FILTER_NEAREST: return "nearest"; case SG_FILTER_LINEAR: return "linear"; default: return "linear"; } } static sg_wrap wrapFromString(const char *str) { if (strcmp(str, "clamp") == 0) return SG_WRAP_CLAMP_TO_EDGE; if (strcmp(str, "repeat") == 0) return SG_WRAP_REPEAT; if (strcmp(str, "mirroredrepeat") == 0) return SG_WRAP_MIRRORED_REPEAT; return SG_WRAP_CLAMP_TO_EDGE; // default } static const char *wrapToString(sg_wrap wrap) { switch (wrap) { case SG_WRAP_CLAMP_TO_EDGE: return "clamp"; case SG_WRAP_REPEAT: return "repeat"; case SG_WRAP_MIRRORED_REPEAT: return "mirroredrepeat"; default: return "clamp"; } } // Texture class implementation Texture::Texture() : image_({SG_INVALID_ID}) , view_({SG_INVALID_ID}) , sampler_({SG_INVALID_ID}) , width_(0) , height_(0) , min_filter_(SG_FILTER_LINEAR) , mag_filter_(SG_FILTER_LINEAR) , wrap_u_(SG_WRAP_CLAMP_TO_EDGE) , wrap_v_(SG_WRAP_CLAMP_TO_EDGE) { } Texture::~Texture() { if (sampler_.id != SG_INVALID_ID) { sg_destroy_sampler(sampler_); } if (view_.id != SG_INVALID_ID) { sg_destroy_view(view_); } if (image_.id != SG_INVALID_ID) { sg_destroy_image(image_); } } bool Texture::loadFromMemory(const unsigned char *data, int size) { // Load image data with stb_image int w, h, channels; unsigned char *pixels = stbi_load_from_memory(data, size, &w, &h, &channels, 4); // force RGBA if (!pixels) { fprintf(stderr, "Failed to load image: %s\n", stbi_failure_reason()); return false; } width_ = w; height_ = h; // Create sokol image sg_image_desc img_desc = {}; img_desc.width = w; img_desc.height = h; img_desc.pixel_format = SG_PIXELFORMAT_RGBA8; img_desc.data.mip_levels[0].ptr = pixels; img_desc.data.mip_levels[0].size = static_cast<size_t>(w * h * 4); image_ = sg_make_image(&img_desc); stbi_image_free(pixels); if (image_.id == SG_INVALID_ID) { fprintf(stderr, "Failed to create GPU image\n"); return false; } // Create texture view from image sg_view_desc view_desc = {}; view_desc.texture.image = image_; view_ = sg_make_view(&view_desc); if (view_.id == SG_INVALID_ID) { fprintf(stderr, "Failed to create texture view\n"); sg_destroy_image(image_); image_.id = SG_INVALID_ID; return false; } // Create default sampler updateSampler(); return true; } void Texture::updateSampler() { if (sampler_.id != SG_INVALID_ID) { sg_destroy_sampler(sampler_); } sg_sampler_desc smp_desc = {}; smp_desc.min_filter = min_filter_; smp_desc.mag_filter = mag_filter_; smp_desc.wrap_u = wrap_u_; smp_desc.wrap_v = wrap_v_; sampler_ = sg_make_sampler(&smp_desc); } void Texture::setFilter(const char *min, const char *mag) { min_filter_ = filterFromString(min); mag_filter_ = filterFromString(mag); updateSampler(); } void Texture::getFilter(const char **min, const char **mag) const { *min = filterToString(min_filter_); *mag = filterToString(mag_filter_); } void Texture::setWrap(const char *horiz, const char *vert) { wrap_u_ = wrapFromString(horiz); wrap_v_ = wrapFromString(vert); updateSampler(); } void Texture::getWrap(const char **horiz, const char **vert) const { *horiz = wrapToString(wrap_u_); *vert = wrapToString(wrap_v_); } // ============================================================================ // Canvas Implementation // ============================================================================ Canvas *Graphics::newCanvas(int width, int height, const char *format) { Canvas *canvas = new Canvas(); if (!canvas->create(width, height, format)) { delete canvas; return nullptr; } return canvas; } void Graphics::setCanvas(Canvas *canvas) { if (canvas == current_canvas_) { return; // No change } // Flush pending draws before switching render target if (batch_) { batch_->flush(); } // Flush any pending text atlas updates flushText(); // End current render pass sg_end_pass(); if (canvas) { // Switch to canvas render target sg_pass_action pass_action = {}; // Don't clear by default - let user call clear() if needed pass_action.colors[0].load_action = SG_LOADACTION_LOAD; pass_action.depth.load_action = SG_LOADACTION_LOAD; pass_action.stencil.load_action = SG_LOADACTION_LOAD; sg_pass pass = {}; pass.action = pass_action; pass.attachments = canvas->getAttachments(); pass.label = "canvas_pass"; sg_begin_pass(&pass); // Update batch renderer with canvas dimensions if (batch_) { batch_->beginFrame(canvas->getWidth(), canvas->getHeight()); batch_->setColor(color_[0], color_[1], color_[2], color_[3]); batch_->setDPIScale(1.0f); // Canvas uses fixed pixel dimensions batch_->setRenderingToCanvas(true); } } else { // Switch back to screen (swapchain) // Use physical pixels for render pass, logical pixels for projection sg_pass_action pass_action = {}; pass_action.colors[0].load_action = SG_LOADACTION_LOAD; pass_action.depth.load_action = SG_LOADACTION_LOAD; pass_action.stencil.load_action = SG_LOADACTION_LOAD; sg_pass pass = {}; pass.action = pass_action; pass.swapchain.width = swapchain_pixel_width_; pass.swapchain.height = swapchain_pixel_height_; pass.swapchain.sample_count = 1; pass.swapchain.color_format = SG_PIXELFORMAT_RGBA8; pass.swapchain.depth_format = SG_PIXELFORMAT_DEPTH_STENCIL; pass.swapchain.gl.framebuffer = 0; pass.label = "screen_pass"; sg_begin_pass(&pass); // Update batch renderer with screen dimensions (logical for projection, physical for Y-flip) if (batch_) { batch_->beginFrame(swapchain_width_, swapchain_height_, swapchain_pixel_width_, swapchain_pixel_height_); batch_->setColor(color_[0], color_[1], color_[2], color_[3]); batch_->setDPIScale(getDPIScale()); batch_->setRenderingToCanvas(false); } } current_canvas_ = canvas; } // ============================================================================ // Shader Implementation // ============================================================================ Shader *Graphics::newShader(const char *pixel_code, const char *vertex_code) { Shader *shader = new Shader(this); if (!shader->compile(pixel_code, vertex_code)) { fprintf(stderr, "Shader compilation failed: %s\n", shader->getError().c_str()); delete shader; return nullptr; } return shader; } void Graphics::setShader(Shader *shader) { if (shader == current_shader_) { return; // No change } if (batch_) { if (shader && shader->isValid()) { batch_->setShader(shader); } else { batch_->resetShader(); } } current_shader_ = shader; } Shader *Graphics::getShader() const { return current_shader_; } void Graphics::draw(Canvas *canvas, float x, float y, float r, float sx, float sy, float ox, float oy) { if (!canvas || !canvas->isValid() || !batch_) { return; } // Get canvas dimensions float w = static_cast<float>(canvas->getWidth()); float h = static_cast<float>(canvas->getHeight()); // Set texture for batch renderer batch_->setTexture(canvas->getTextureView(), canvas->getSampler()); // Apply transform batch_->pushTransform(); batch_->translate(x, y); if (r != 0) { batch_->rotate(r); } if (sx != 1 || sy != 1) { batch_->scale(sx, sy); } batch_->translate(-ox, -oy); // Draw textured rect with flipped V coordinates // Canvas textures are stored with OpenGL's bottom-left origin, // so we flip the source Y to display correctly with our top-left origin batch_->drawTexturedRect(0, 0, w, h, 0, h, w, -h, static_cast<int>(w), static_cast<int>(h)); batch_->popTransform(); // Reset texture batch_->resetTexture(); } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/graphics.hh
C++ Header
#pragma once #include "SDL3/SDL.h" #include "sokol_gfx.h" #include "fontstash.h" #include <string> #include <vector> namespace js { class Context; class Value; } namespace joy { class Engine; namespace modules { // Forward declarations class BatchRenderer; class Graphics; class Canvas; class TextRenderer; class Shader; // Quad class - represents a portion of a texture (texture region) class Quad { public: Quad(float x, float y, float w, float h, float sw, float sh); // Viewport (the region of the texture) void setViewport(float x, float y, float w, float h); void setViewport(float x, float y, float w, float h, float sw, float sh); void getViewport(float *x, float *y, float *w, float *h) const; // Reference texture dimensions void getTextureDimensions(float *sw, float *sh) const; private: float x_, y_, w_, h_; // Viewport rectangle float sw_, sh_; // Reference texture dimensions }; // Font class - wraps font data for text rendering (Love2D compatible) class Font { public: Font(Graphics *graphics, int font_handle, float size, float dpi_scale = 1.0f); ~Font(); // Font metrics (in pixels, adjusted for size and DPI) float getHeight() const; float getAscent() const; float getDescent() const; float getBaseline() const; float getLineHeight() const; void setLineHeight(float height); // DPI scale float getDPIScale() const { return dpi_scale_; } // Text measurement float getWidth(const char *text) const; // Returns max width and fills wrappedLines with the wrapped text float getWrap(const char *text, float wrap_limit, std::vector<std::string> &wrapped_lines) const; // Kerning between two characters (by character or codepoint) float getKerning(const char *left, const char *right) const; float getKerning(int left_glyph, int right_glyph) const; // Check if font has glyphs for text or codepoints bool hasGlyphs(const char *text) const; bool hasGlyph(int codepoint) const; // Filter mode void setFilter(const char *min, const char *mag); void getFilter(const char **min, const char **mag) const; // Fallback fonts void setFallbacks(const std::vector<Font*> &fallbacks); // Internal accessors int getFontHandle() const { return font_handle_; } float getSize() const { return size_; } Graphics *getGraphics() const { return graphics_; } private: Graphics *graphics_; int font_handle_; float size_; float dpi_scale_; float line_height_; // Multiplier for line height (default 1.0) const char *filter_min_; const char *filter_mag_; }; // Texture class - wraps a GPU texture loaded from file class Texture { public: Texture(); ~Texture(); // Load image from file data in memory (stb_image format) bool loadFromMemory(const unsigned char *data, int size); // Get dimensions int getWidth() const { return width_; } int getHeight() const { return height_; } // Get sokol image/view handles for rendering sg_image getHandle() const { return image_; } sg_view getView() const { return view_; } sg_sampler getSampler() const { return sampler_; } // Check if valid bool isValid() const { return image_.id != SG_INVALID_ID && view_.id != SG_INVALID_ID; } // Texture filtering void setFilter(const char *min, const char *mag); void getFilter(const char **min, const char **mag) const; // Texture wrapping void setWrap(const char *horiz, const char *vert); void getWrap(const char **horiz, const char **vert) const; private: sg_image image_; sg_view view_; sg_sampler sampler_; int width_; int height_; // Filter settings (stored for getFilter) sg_filter min_filter_; sg_filter mag_filter_; // Wrap settings (stored for getWrap) sg_wrap wrap_u_; sg_wrap wrap_v_; // Helper to recreate sampler when filter/wrap changes void updateSampler(); }; class Graphics { public: Graphics(Engine *engine); ~Graphics(); // Initialize/shutdown text rendering bool initText(); void shutdownText(); void prepareText(); // Set up viewport/projection for text rendering void flushText(); // Color management void setColor(float r, float g, float b, float a); void getColor(float *r, float *g, float *b, float *a); void setBackgroundColor(float r, float g, float b, float a); void getBackgroundColor(float *r, float *g, float *b, float *a); // Drawing primitives void rectangle(const char *mode, float x, float y, float w, float h); void circle(const char *mode, float x, float y, float radius); void line(float x1, float y1, float x2, float y2); void point(float x, float y); void polygon(const char *mode, const float *points, int count); void arc(const char *mode, const char *arctype, float x, float y, float radius, float angle1, float angle2, int segments = 10); void ellipse(const char *mode, float x, float y, float rx, float ry, int segments = 32); void flush(); // Flush pending draw commands // Line width void setLineWidth(float width); float getLineWidth() const; // Scissor void setScissor(int x, int y, int w, int h); void resetScissor(); bool getScissor(int *x, int *y, int *w, int *h) const; // Transform stack void pushTransform(); void popTransform(); void translate(float x, float y); void rotate(float radians); void scale(float sx, float sy); void resetTransform(); // Blend mode void setBlendMode(const char *mode); const char *getBlendMode() const; // Draw texture (drawable) // Full signature: draw(texture, x, y, r, sx, sy, ox, oy) void draw(Texture *texture, float x, float y, float r = 0, float sx = 1, float sy = 1, float ox = 0, float oy = 0); // Draw quad (portion of texture) // draw(texture, quad, x, y, r, sx, sy, ox, oy) void drawQuad(Texture *texture, float qx, float qy, float qw, float qh, float x, float y, float r = 0, float sx = 1, float sy = 1, float ox = 0, float oy = 0); // Text rendering void print(const char *text, float x, float y); void setFontSize(float size); void setCurrentFont(int font_handle); int getDefaultFont() const { return font_default_; } // Font creation Font *newFont(float size); // Default font with size Font *newFont(const char *filename, float size); // Custom font from file Font *newFontFromMemory(const unsigned char *data, int size, float font_size, const char *name); // Get fontstash context for Font class FONScontext *getFonsContext(); // Dimensions int getWidth(); int getHeight(); int getPixelWidth(); int getPixelHeight(); float getDPIScale(); float getEffectiveDPIScale(); // Returns 1.0 when rendering to canvas // Clear void clear(float r, float g, float b, float a, bool use_color); // Debug stats int getFlushCount() const; int getDrawCallCount() const; // Canvas (render-to-texture) Canvas *newCanvas(int width, int height, const char *format = "normal"); void setCanvas(Canvas *canvas); // nullptr = back to screen Canvas *getCanvas() const { return current_canvas_; } // Draw canvas as texture void draw(Canvas *canvas, float x, float y, float r = 0, float sx = 1, float sy = 1, float ox = 0, float oy = 0); // Shader support Shader *newShader(const char *pixel_code, const char *vertex_code = nullptr); void setShader(Shader *shader); // nullptr = reset to default Shader *getShader() const; // BatchRenderer access (for Render class) BatchRenderer *getBatchRenderer() { return batch_; } bool initBatchRenderer(); void shutdownBatchRenderer(); void beginFrame(int w, int h, int pw, int ph); void endFrame(); // Initialize JS bindings static void initJS(js::Context &ctx, js::Value &joy); private: Engine *engine_; BatchRenderer *batch_; float color_[4]; float bg_color_[4]; float font_size_; const char *blend_mode_str_; float line_width_; // Scissor state bool scissor_enabled_; int scissor_x_, scissor_y_, scissor_w_, scissor_h_; // Text rendering TextRenderer *text_renderer_; int font_default_; int font_current_; // Canvas state Canvas *current_canvas_; // nullptr = rendering to screen int swapchain_width_; // Cached swapchain dimensions (logical pixels) int swapchain_height_; int swapchain_pixel_width_; // Physical pixels for render pass int swapchain_pixel_height_; // Shader state Shader *current_shader_; // nullptr = default shader }; } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/graphics_js.cc
C++
#include "js/js.hh" #include "graphics.hh" #include "canvas.hh" #include "shader.hh" #include "engine.hh" #include "physfs.h" #include <cstring> #include <cstdlib> #include <unordered_map> #include <vector> namespace joy { namespace modules { // Helper to get Graphics module from JS context static Graphics *getGraphics(js::FunctionArgs &args) { Engine *engine = args.getContextOpaque<Engine>(); return engine ? engine->getGraphicsModule() : nullptr; } // Font class is now defined in graphics.hh static js::ClassID font_class_id = 0; static void font_finalizer(void *opaque) { Font *font = static_cast<Font *>(opaque); delete font; } // Helper to get Font from this value static Font *getFont(js::FunctionArgs &args) { js::Value thisVal = args.thisValue(); return static_cast<Font *>(js::ClassBuilder::getOpaque(thisVal, font_class_id)); } // Texture class for JS (exposed as "Image" to match Love2D API) static js::ClassID texture_class_id = 0; static void texture_finalizer(void *opaque) { Texture *tex = static_cast<Texture *>(opaque); delete tex; } // Helper to get Texture from this value static Texture *getTexture(js::FunctionArgs &args) { js::Value thisVal = args.thisValue(); return static_cast<Texture *>(js::ClassBuilder::getOpaque(thisVal, texture_class_id)); } // Quad class for JS static js::ClassID quad_class_id = 0; static void quad_finalizer(void *opaque) { Quad *quad = static_cast<Quad *>(opaque); delete quad; } // Helper to get Quad from this value static Quad *getQuad(js::FunctionArgs &args) { js::Value thisVal = args.thisValue(); return static_cast<Quad *>(js::ClassBuilder::getOpaque(thisVal, quad_class_id)); } // Canvas class for JS static js::ClassID canvas_class_id = 0; static void canvas_finalizer(void *opaque) { Canvas *canvas = static_cast<Canvas *>(opaque); delete canvas; } // Helper to get Canvas from this value static Canvas *getCanvas(js::FunctionArgs &args) { js::Value thisVal = args.thisValue(); return static_cast<Canvas *>(js::ClassBuilder::getOpaque(thisVal, canvas_class_id)); } // Shader class for JS static js::ClassID shader_class_id = 0; static void shader_finalizer(void *opaque) { Shader *shader = static_cast<Shader *>(opaque); delete shader; } // Helper to get Shader from this value static Shader *getShader(js::FunctionArgs &args) { js::Value thisVal = args.thisValue(); return static_cast<Shader *>(js::ClassBuilder::getOpaque(thisVal, shader_class_id)); } // joy.graphics.newImage(filename) static void js_graphics_newImage(js::FunctionArgs &args) { if (args.length() < 1) { args.returnValue(js::Value::null()); return; } std::string filename = args.arg(0).toString(args.context()); // Read file via PhysFS PHYSFS_File *file = PHYSFS_openRead(filename.c_str()); if (!file) { args.returnValue(js::Value::null()); return; } PHYSFS_sint64 file_size = PHYSFS_fileLength(file); if (file_size < 0) { PHYSFS_close(file); args.returnValue(js::Value::null()); return; } unsigned char *file_data = static_cast<unsigned char *>(malloc(file_size)); if (!file_data) { PHYSFS_close(file); args.returnValue(js::Value::null()); return; } PHYSFS_sint64 bytes_read = PHYSFS_readBytes(file, file_data, file_size); PHYSFS_close(file); if (bytes_read != file_size) { free(file_data); args.returnValue(js::Value::null()); return; } // Create Texture Texture *tex = new Texture(); if (!tex->loadFromMemory(file_data, static_cast<int>(file_size))) { free(file_data); delete tex; args.returnValue(js::Value::null()); return; } free(file_data); js::Value obj = js::ClassBuilder::newInstance(args.context(), texture_class_id); js::ClassBuilder::setOpaque(obj, tex); args.returnValue(std::move(obj)); } // image:getWidth() static void js_image_getWidth(js::FunctionArgs &args) { Texture *tex = getTexture(args); args.returnValue(js::Value::number(tex ? tex->getWidth() : 0)); } // image:getHeight() static void js_image_getHeight(js::FunctionArgs &args) { Texture *tex = getTexture(args); args.returnValue(js::Value::number(tex ? tex->getHeight() : 0)); } // image:getDimensions() static void js_image_getDimensions(js::FunctionArgs &args) { Texture *tex = getTexture(args); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::number(tex ? tex->getWidth() : 0)); arr.setProperty(args.context(), 1u, js::Value::number(tex ? tex->getHeight() : 0)); args.returnValue(std::move(arr)); } // image:setFilter(min, mag) static void js_image_setFilter(js::FunctionArgs &args) { Texture *tex = getTexture(args); if (tex && args.length() >= 2) { std::string min = args.arg(0).toString(args.context()); std::string mag = args.arg(1).toString(args.context()); tex->setFilter(min.c_str(), mag.c_str()); } args.returnUndefined(); } // image:getFilter() static void js_image_getFilter(js::FunctionArgs &args) { Texture *tex = getTexture(args); if (!tex) { args.returnUndefined(); return; } const char *min, *mag; tex->getFilter(&min, &mag); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::string(args.context(), min)); arr.setProperty(args.context(), 1u, js::Value::string(args.context(), mag)); args.returnValue(std::move(arr)); } // image:setWrap(horiz, vert) static void js_image_setWrap(js::FunctionArgs &args) { Texture *tex = getTexture(args); if (tex && args.length() >= 2) { std::string horiz = args.arg(0).toString(args.context()); std::string vert = args.arg(1).toString(args.context()); tex->setWrap(horiz.c_str(), vert.c_str()); } args.returnUndefined(); } // image:getWrap() static void js_image_getWrap(js::FunctionArgs &args) { Texture *tex = getTexture(args); if (!tex) { args.returnUndefined(); return; } const char *horiz, *vert; tex->getWrap(&horiz, &vert); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::string(args.context(), horiz)); arr.setProperty(args.context(), 1u, js::Value::string(args.context(), vert)); args.returnValue(std::move(arr)); } // joy.graphics.newQuad(x, y, width, height, sw, sh) static void js_graphics_newQuad(js::FunctionArgs &args) { if (args.length() < 6) { args.returnValue(js::Value::null()); return; } float x = static_cast<float>(args.arg(0).toFloat64()); float y = static_cast<float>(args.arg(1).toFloat64()); float w = static_cast<float>(args.arg(2).toFloat64()); float h = static_cast<float>(args.arg(3).toFloat64()); float sw = static_cast<float>(args.arg(4).toFloat64()); float sh = static_cast<float>(args.arg(5).toFloat64()); Quad *quad = new Quad(x, y, w, h, sw, sh); js::Value obj = js::ClassBuilder::newInstance(args.context(), quad_class_id); js::ClassBuilder::setOpaque(obj, quad); args.returnValue(std::move(obj)); } // quad:getViewport() static void js_quad_getViewport(js::FunctionArgs &args) { Quad *quad = getQuad(args); if (!quad) { args.returnUndefined(); return; } float x, y, w, h; quad->getViewport(&x, &y, &w, &h); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::number(x)); arr.setProperty(args.context(), 1u, js::Value::number(y)); arr.setProperty(args.context(), 2u, js::Value::number(w)); arr.setProperty(args.context(), 3u, js::Value::number(h)); args.returnValue(std::move(arr)); } // quad:setViewport(x, y, w, h, sw, sh) static void js_quad_setViewport(js::FunctionArgs &args) { Quad *quad = getQuad(args); if (!quad || args.length() < 4) { args.returnUndefined(); return; } float x = static_cast<float>(args.arg(0).toFloat64()); float y = static_cast<float>(args.arg(1).toFloat64()); float w = static_cast<float>(args.arg(2).toFloat64()); float h = static_cast<float>(args.arg(3).toFloat64()); if (args.length() >= 6) { float sw = static_cast<float>(args.arg(4).toFloat64()); float sh = static_cast<float>(args.arg(5).toFloat64()); quad->setViewport(x, y, w, h, sw, sh); } else { quad->setViewport(x, y, w, h); } args.returnUndefined(); } // quad:getTextureDimensions() static void js_quad_getTextureDimensions(js::FunctionArgs &args) { Quad *quad = getQuad(args); if (!quad) { args.returnUndefined(); return; } float sw, sh; quad->getTextureDimensions(&sw, &sh); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::number(sw)); arr.setProperty(args.context(), 1u, js::Value::number(sh)); args.returnValue(std::move(arr)); } // joy.graphics.draw(drawable, x, y, r, sx, sy, ox, oy) // or joy.graphics.draw(texture, quad, x, y, r, sx, sy, ox, oy) static void js_graphics_draw(js::FunctionArgs &args) { if (args.length() < 1) { args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } js::Value drawable = args.arg(0); // Check if first arg is a Texture (Image) Texture *tex = static_cast<Texture *>(js::ClassBuilder::getOpaque(drawable, texture_class_id)); if (tex) { // Check if second arg is a Quad if (args.length() >= 2) { js::Value arg1 = args.arg(1); Quad *quad = static_cast<Quad *>(js::ClassBuilder::getOpaque(arg1, quad_class_id)); if (quad) { // draw(texture, quad, x, y, r, sx, sy, ox, oy) float qx, qy, qw, qh; quad->getViewport(&qx, &qy, &qw, &qh); float x = 0, y = 0, r = 0, sx = 1, sy = 1, ox = 0, oy = 0; if (args.length() >= 3) x = static_cast<float>(args.arg(2).toFloat64()); if (args.length() >= 4) y = static_cast<float>(args.arg(3).toFloat64()); if (args.length() >= 5) r = static_cast<float>(args.arg(4).toFloat64()); if (args.length() >= 6) sx = static_cast<float>(args.arg(5).toFloat64()); if (args.length() >= 7) sy = static_cast<float>(args.arg(6).toFloat64()); if (args.length() >= 8) ox = static_cast<float>(args.arg(7).toFloat64()); if (args.length() >= 9) oy = static_cast<float>(args.arg(8).toFloat64()); graphics->drawQuad(tex, qx, qy, qw, qh, x, y, r, sx, sy, ox, oy); args.returnUndefined(); return; } } // draw(image, x, y, r, sx, sy, ox, oy) float x = 0, y = 0, r = 0, sx = 1, sy = 1, ox = 0, oy = 0; if (args.length() >= 2) x = static_cast<float>(args.arg(1).toFloat64()); if (args.length() >= 3) y = static_cast<float>(args.arg(2).toFloat64()); if (args.length() >= 4) r = static_cast<float>(args.arg(3).toFloat64()); if (args.length() >= 5) sx = static_cast<float>(args.arg(4).toFloat64()); if (args.length() >= 6) sy = static_cast<float>(args.arg(5).toFloat64()); if (args.length() >= 7) ox = static_cast<float>(args.arg(6).toFloat64()); if (args.length() >= 8) oy = static_cast<float>(args.arg(7).toFloat64()); graphics->draw(tex, x, y, r, sx, sy, ox, oy); args.returnUndefined(); return; } // Check if first arg is a Canvas Canvas *canvas = static_cast<Canvas *>(js::ClassBuilder::getOpaque(drawable, canvas_class_id)); if (canvas) { float x = 0, y = 0, r = 0, sx = 1, sy = 1, ox = 0, oy = 0; if (args.length() >= 2) x = static_cast<float>(args.arg(1).toFloat64()); if (args.length() >= 3) y = static_cast<float>(args.arg(2).toFloat64()); if (args.length() >= 4) r = static_cast<float>(args.arg(3).toFloat64()); if (args.length() >= 5) sx = static_cast<float>(args.arg(4).toFloat64()); if (args.length() >= 6) sy = static_cast<float>(args.arg(5).toFloat64()); if (args.length() >= 7) ox = static_cast<float>(args.arg(6).toFloat64()); if (args.length() >= 8) oy = static_cast<float>(args.arg(7).toFloat64()); graphics->draw(canvas, x, y, r, sx, sy, ox, oy); args.returnUndefined(); return; } args.returnUndefined(); } // joy.graphics.drawQuad(image, qx, qy, qw, qh, x, y, r, sx, sy, ox, oy) // Draws a portion (quad) of an image static void js_graphics_drawQuad(js::FunctionArgs &args) { if (args.length() < 5) { args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } js::Value drawable = args.arg(0); Texture *tex = static_cast<Texture *>(js::ClassBuilder::getOpaque(drawable, texture_class_id)); if (!tex) { args.returnUndefined(); return; } // Quad source rectangle float qx = static_cast<float>(args.arg(1).toFloat64()); float qy = static_cast<float>(args.arg(2).toFloat64()); float qw = static_cast<float>(args.arg(3).toFloat64()); float qh = static_cast<float>(args.arg(4).toFloat64()); // Position and transform float x = 0, y = 0, r = 0, sx = 1, sy = 1, ox = 0, oy = 0; if (args.length() >= 6) x = static_cast<float>(args.arg(5).toFloat64()); if (args.length() >= 7) y = static_cast<float>(args.arg(6).toFloat64()); if (args.length() >= 8) r = static_cast<float>(args.arg(7).toFloat64()); if (args.length() >= 9) sx = static_cast<float>(args.arg(8).toFloat64()); if (args.length() >= 10) sy = static_cast<float>(args.arg(9).toFloat64()); if (args.length() >= 11) ox = static_cast<float>(args.arg(10).toFloat64()); if (args.length() >= 12) oy = static_cast<float>(args.arg(11).toFloat64()); graphics->drawQuad(tex, qx, qy, qw, qh, x, y, r, sx, sy, ox, oy); args.returnUndefined(); } // joy.graphics.newFont(size) or joy.graphics.newFont(filename, size) static void js_graphics_newFont(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnValue(js::Value::null()); return; } Font *font = nullptr; if (args.length() == 0) { // Default font with default size (12) font = graphics->newFont(12.0f); } else if (args.length() == 1) { js::Value arg0 = args.arg(0); if (arg0.isNumber()) { // newFont(size) double size = arg0.toFloat64(); font = graphics->newFont(static_cast<float>(size)); } else if (arg0.isString()) { // newFont(filename) - default size 12 std::string filename = arg0.toString(args.context()); font = graphics->newFont(filename.c_str(), 12.0f); } } else { // newFont(filename, size) std::string filename = args.arg(0).toString(args.context()); double size = args.arg(1).toFloat64(); font = graphics->newFont(filename.c_str(), static_cast<float>(size)); } if (!font) { args.returnValue(js::Value::null()); return; } js::Value obj = js::ClassBuilder::newInstance(args.context(), font_class_id); js::ClassBuilder::setOpaque(obj, font); args.returnValue(std::move(obj)); } static void js_graphics_setFont(js::FunctionArgs &args) { if (args.length() < 1) { args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } js::Value fontVal = args.arg(0); Font *font = static_cast<Font *>(js::ClassBuilder::getOpaque(fontVal, font_class_id)); if (!font) { args.returnUndefined(); return; } graphics->setCurrentFont(font->getFontHandle()); graphics->setFontSize(font->getSize()); args.returnUndefined(); } // ============================================================================ // Font prototype methods // ============================================================================ // font:getHeight() static void js_font_getHeight(js::FunctionArgs &args) { Font *font = getFont(args); args.returnValue(js::Value::number(font ? font->getHeight() : 0)); } // font:getWidth(text) static void js_font_getWidth(js::FunctionArgs &args) { Font *font = getFont(args); if (!font || args.length() < 1) { args.returnValue(js::Value::number(0)); return; } std::string text = args.arg(0).toString(args.context()); args.returnValue(js::Value::number(font->getWidth(text.c_str()))); } // font:getAscent() static void js_font_getAscent(js::FunctionArgs &args) { Font *font = getFont(args); args.returnValue(js::Value::number(font ? font->getAscent() : 0)); } // font:getDescent() static void js_font_getDescent(js::FunctionArgs &args) { Font *font = getFont(args); args.returnValue(js::Value::number(font ? font->getDescent() : 0)); } // font:getBaseline() static void js_font_getBaseline(js::FunctionArgs &args) { Font *font = getFont(args); args.returnValue(js::Value::number(font ? font->getBaseline() : 0)); } // font:getLineHeight() static void js_font_getLineHeight(js::FunctionArgs &args) { Font *font = getFont(args); args.returnValue(js::Value::number(font ? font->getLineHeight() : 1.0)); } // font:setLineHeight(height) static void js_font_setLineHeight(js::FunctionArgs &args) { Font *font = getFont(args); if (font && args.length() >= 1) { font->setLineHeight(static_cast<float>(args.arg(0).toFloat64())); } args.returnUndefined(); } // font:getDPIScale() static void js_font_getDPIScale(js::FunctionArgs &args) { Font *font = getFont(args); args.returnValue(js::Value::number(font ? font->getDPIScale() : 1.0)); } // font:getWrap(text, wraplimit) - returns [width, lines] static void js_font_getWrap(js::FunctionArgs &args) { Font *font = getFont(args); if (!font || args.length() < 2) { js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::number(0)); arr.setProperty(args.context(), 1u, js::Value::array(args.context())); args.returnValue(std::move(arr)); return; } std::string text = args.arg(0).toString(args.context()); float wrap_limit = static_cast<float>(args.arg(1).toFloat64()); std::vector<std::string> wrapped_lines; float max_width = font->getWrap(text.c_str(), wrap_limit, wrapped_lines); js::Value lines_arr = js::Value::array(args.context()); for (size_t i = 0; i < wrapped_lines.size(); i++) { lines_arr.setProperty(args.context(), static_cast<uint32_t>(i), js::Value::string(args.context(), wrapped_lines[i].c_str())); } js::Value result = js::Value::array(args.context()); result.setProperty(args.context(), 0u, js::Value::number(max_width)); result.setProperty(args.context(), 1u, std::move(lines_arr)); args.returnValue(std::move(result)); } // font:hasGlyphs(text) or font:hasGlyphs(codepoint1, codepoint2, ...) static void js_font_hasGlyphs(js::FunctionArgs &args) { Font *font = getFont(args); if (!font || args.length() < 1) { args.returnValue(js::Value::boolean(true)); return; } js::Value arg0 = args.arg(0); if (arg0.isString()) { std::string text = arg0.toString(args.context()); args.returnValue(js::Value::boolean(font->hasGlyphs(text.c_str()))); } else { // Check all codepoint arguments for (int i = 0; i < args.length(); i++) { int codepoint = args.arg(i).toInt32(); if (!font->hasGlyph(codepoint)) { args.returnValue(js::Value::boolean(false)); return; } } args.returnValue(js::Value::boolean(true)); } } // font:getKerning(leftchar, rightchar) or font:getKerning(leftglyph, rightglyph) static void js_font_getKerning(js::FunctionArgs &args) { Font *font = getFont(args); if (!font || args.length() < 2) { args.returnValue(js::Value::number(0)); return; } js::Value arg0 = args.arg(0); js::Value arg1 = args.arg(1); if (arg0.isString() && arg1.isString()) { std::string left = arg0.toString(args.context()); std::string right = arg1.toString(args.context()); args.returnValue(js::Value::number(font->getKerning(left.c_str(), right.c_str()))); } else { int left_glyph = arg0.toInt32(); int right_glyph = arg1.toInt32(); args.returnValue(js::Value::number(font->getKerning(left_glyph, right_glyph))); } } // font:setFilter(min, mag) static void js_font_setFilter(js::FunctionArgs &args) { Font *font = getFont(args); if (font && args.length() >= 2) { std::string min = args.arg(0).toString(args.context()); std::string mag = args.arg(1).toString(args.context()); font->setFilter(min.c_str(), mag.c_str()); } args.returnUndefined(); } // font:getFilter() - returns [min, mag, anisotropy] static void js_font_getFilter(js::FunctionArgs &args) { Font *font = getFont(args); if (!font) { args.returnUndefined(); return; } const char *min, *mag; font->getFilter(&min, &mag); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::string(args.context(), min)); arr.setProperty(args.context(), 1u, js::Value::string(args.context(), mag)); arr.setProperty(args.context(), 2u, js::Value::number(1)); // anisotropy default args.returnValue(std::move(arr)); } // font:setFallbacks(font1, font2, ...) static void js_font_setFallbacks(js::FunctionArgs &args) { Font *font = getFont(args); if (!font) { args.returnUndefined(); return; } std::vector<Font*> fallbacks; for (int i = 0; i < args.length(); i++) { js::Value fontVal = args.arg(i); Font *fallback = static_cast<Font *>(js::ClassBuilder::getOpaque(fontVal, font_class_id)); if (fallback) { fallbacks.push_back(fallback); } } font->setFallbacks(fallbacks); args.returnUndefined(); } // joy.graphics.getFont() - get current font (returns null if using default) static void js_graphics_getFont(js::FunctionArgs &args) { // Note: Love2D returns the current font object, but we don't track the JS object // For now, return undefined - a proper implementation would store the current Font args.returnUndefined(); } // joy.graphics.setNewFont(size) or joy.graphics.setNewFont(filename, size) // Creates a new font and sets it as current, returns the new font static void js_graphics_setNewFont(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnValue(js::Value::null()); return; } Font *font = nullptr; if (args.length() == 0) { font = graphics->newFont(12.0f); } else if (args.length() == 1) { js::Value arg0 = args.arg(0); if (arg0.isNumber()) { font = graphics->newFont(static_cast<float>(arg0.toFloat64())); } else if (arg0.isString()) { std::string filename = arg0.toString(args.context()); font = graphics->newFont(filename.c_str(), 12.0f); } } else { std::string filename = args.arg(0).toString(args.context()); double size = args.arg(1).toFloat64(); font = graphics->newFont(filename.c_str(), static_cast<float>(size)); } if (!font) { args.returnValue(js::Value::null()); return; } // Set as current font graphics->setCurrentFont(font->getFontHandle()); graphics->setFontSize(font->getSize()); js::Value obj = js::ClassBuilder::newInstance(args.context(), font_class_id); js::ClassBuilder::setOpaque(obj, font); args.returnValue(std::move(obj)); } static void js_graphics_setColor(js::FunctionArgs &args) { if (args.length() < 3) { args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } double r = args.arg(0).toFloat64(); double g = args.arg(1).toFloat64(); double b = args.arg(2).toFloat64(); double a = 1.0; if (args.length() >= 4) { a = args.arg(3).toFloat64(); } graphics->setColor(static_cast<float>(r), static_cast<float>(g), static_cast<float>(b), static_cast<float>(a)); args.returnUndefined(); } static void js_graphics_getColor(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } float r, g, b, a; graphics->getColor(&r, &g, &b, &a); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::number((double)r)); arr.setProperty(args.context(), 1u, js::Value::number((double)g)); arr.setProperty(args.context(), 2u, js::Value::number((double)b)); arr.setProperty(args.context(), 3u, js::Value::number((double)a)); args.returnValue(std::move(arr)); } static void js_graphics_setBackgroundColor(js::FunctionArgs &args) { if (args.length() < 3) { args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } double r = args.arg(0).toFloat64(); double g = args.arg(1).toFloat64(); double b = args.arg(2).toFloat64(); double a = 1.0; if (args.length() >= 4) { a = args.arg(3).toFloat64(); } graphics->setBackgroundColor(static_cast<float>(r), static_cast<float>(g), static_cast<float>(b), static_cast<float>(a)); args.returnUndefined(); } static void js_graphics_getBackgroundColor(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } float r, g, b, a; graphics->getBackgroundColor(&r, &g, &b, &a); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::number((double)r)); arr.setProperty(args.context(), 1u, js::Value::number((double)g)); arr.setProperty(args.context(), 2u, js::Value::number((double)b)); arr.setProperty(args.context(), 3u, js::Value::number((double)a)); args.returnValue(std::move(arr)); } static void js_graphics_rectangle(js::FunctionArgs &args) { if (args.length() < 5) { args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } std::string mode = args.arg(0).toString(args.context()); double x = args.arg(1).toFloat64(); double y = args.arg(2).toFloat64(); double w = args.arg(3).toFloat64(); double h = args.arg(4).toFloat64(); graphics->rectangle(mode.c_str(), static_cast<float>(x), static_cast<float>(y), static_cast<float>(w), static_cast<float>(h)); args.returnUndefined(); } static void js_graphics_circle(js::FunctionArgs &args) { if (args.length() < 4) { args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } std::string mode = args.arg(0).toString(args.context()); double x = args.arg(1).toFloat64(); double y = args.arg(2).toFloat64(); double radius = args.arg(3).toFloat64(); graphics->circle(mode.c_str(), static_cast<float>(x), static_cast<float>(y), static_cast<float>(radius)); args.returnUndefined(); } static void js_graphics_line(js::FunctionArgs &args) { if (args.length() < 4) { args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } // Check if we have a polyline (more than 4 args) if (args.length() > 4) { // Polyline: draw connected line segments for (int i = 0; i < args.length() - 2; i += 2) { if (i + 3 < args.length()) { double x1 = args.arg(i).toFloat64(); double y1 = args.arg(i + 1).toFloat64(); double x2 = args.arg(i + 2).toFloat64(); double y2 = args.arg(i + 3).toFloat64(); graphics->line(static_cast<float>(x1), static_cast<float>(y1), static_cast<float>(x2), static_cast<float>(y2)); } } } else { // Single line segment double x1 = args.arg(0).toFloat64(); double y1 = args.arg(1).toFloat64(); double x2 = args.arg(2).toFloat64(); double y2 = args.arg(3).toFloat64(); graphics->line(static_cast<float>(x1), static_cast<float>(y1), static_cast<float>(x2), static_cast<float>(y2)); } args.returnUndefined(); } // joy.graphics.point(x, y) or joy.graphics.points(x1, y1, x2, y2, ...) static void js_graphics_point(js::FunctionArgs &args) { if (args.length() < 2) { args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } // Support multiple points for (int i = 0; i < args.length() - 1; i += 2) { double x = args.arg(i).toFloat64(); double y = args.arg(i + 1).toFloat64(); graphics->point(static_cast<float>(x), static_cast<float>(y)); } args.returnUndefined(); } // joy.graphics.polygon(mode, x1, y1, x2, y2, ...) static void js_graphics_polygon(js::FunctionArgs &args) { if (args.length() < 7) { // mode + at least 3 points (6 coords) args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } std::string mode = args.arg(0).toString(args.context()); // Collect points int point_count = (args.length() - 1) / 2; std::vector<float> points(point_count * 2); for (int i = 0; i < point_count * 2; i++) { points[i] = static_cast<float>(args.arg(1 + i).toFloat64()); } graphics->polygon(mode.c_str(), points.data(), point_count); args.returnUndefined(); } static void js_graphics_print(js::FunctionArgs &args) { if (args.length() < 3) { args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } std::string text = args.arg(0).toString(args.context()); double x = args.arg(1).toFloat64(); double y = args.arg(2).toFloat64(); graphics->print(text.c_str(), static_cast<float>(x), static_cast<float>(y)); args.returnUndefined(); } static void js_graphics_getWidth(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); args.returnValue(js::Value::number(graphics ? graphics->getWidth() : 0)); } static void js_graphics_getHeight(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); args.returnValue(js::Value::number(graphics ? graphics->getHeight() : 0)); } static void js_graphics_getDimensions(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::number(graphics ? graphics->getWidth() : 0)); arr.setProperty(args.context(), 1u, js::Value::number(graphics ? graphics->getHeight() : 0)); args.returnValue(std::move(arr)); } static void js_graphics_clear(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } if (args.length() >= 3) { double r = args.arg(0).toFloat64(); double g = args.arg(1).toFloat64(); double b = args.arg(2).toFloat64(); double a = 1.0; if (args.length() >= 4) { a = args.arg(3).toFloat64(); } graphics->clear(static_cast<float>(r), static_cast<float>(g), static_cast<float>(b), static_cast<float>(a), true); } else { graphics->clear(0, 0, 0, 0, false); } args.returnUndefined(); } // ============================================================================ // Transform functions // ============================================================================ static void js_graphics_push(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (graphics) graphics->pushTransform(); args.returnUndefined(); } static void js_graphics_pop(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (graphics) graphics->popTransform(); args.returnUndefined(); } static void js_graphics_translate(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (graphics && args.length() >= 2) { float x = static_cast<float>(args.arg(0).toFloat64()); float y = static_cast<float>(args.arg(1).toFloat64()); graphics->translate(x, y); } args.returnUndefined(); } static void js_graphics_rotate(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (graphics && args.length() >= 1) { float angle = static_cast<float>(args.arg(0).toFloat64()); graphics->rotate(angle); } args.returnUndefined(); } static void js_graphics_scale(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } if (args.length() >= 2) { float sx = static_cast<float>(args.arg(0).toFloat64()); float sy = static_cast<float>(args.arg(1).toFloat64()); graphics->scale(sx, sy); } else if (args.length() >= 1) { float s = static_cast<float>(args.arg(0).toFloat64()); graphics->scale(s, s); } args.returnUndefined(); } static void js_graphics_origin(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (graphics) graphics->resetTransform(); args.returnUndefined(); } static void js_graphics_getStats(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } js::Value obj = js::Value::object(args.context()); obj.setProperty(args.context(), "flushes", js::Value::number(graphics->getFlushCount())); obj.setProperty(args.context(), "drawCalls", js::Value::number(graphics->getDrawCallCount())); args.returnValue(std::move(obj)); } static void js_graphics_getDPIScale(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); args.returnValue(js::Value::number(graphics ? graphics->getDPIScale() : 1.0)); } // joy.graphics.setBlendMode(mode) static void js_graphics_setBlendMode(js::FunctionArgs &args) { if (args.length() < 1) { args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } std::string mode = args.arg(0).toString(args.context()); graphics->setBlendMode(mode.c_str()); args.returnUndefined(); } // joy.graphics.getBlendMode() static void js_graphics_getBlendMode(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } const char *mode = graphics->getBlendMode(); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::string(args.context(), mode)); arr.setProperty(args.context(), 1u, js::Value::string(args.context(), "alphamultiply")); args.returnValue(std::move(arr)); } // joy.graphics.setScissor(x, y, w, h) static void js_graphics_setScissor(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } if (args.length() >= 4) { int x = args.arg(0).toInt32(); int y = args.arg(1).toInt32(); int w = args.arg(2).toInt32(); int h = args.arg(3).toInt32(); graphics->setScissor(x, y, w, h); } else { // No args - reset scissor graphics->resetScissor(); } args.returnUndefined(); } // joy.graphics.getScissor() static void js_graphics_getScissor(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } int x, y, w, h; bool enabled = graphics->getScissor(&x, &y, &w, &h); if (!enabled) { args.returnUndefined(); return; } js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::number(x)); arr.setProperty(args.context(), 1u, js::Value::number(y)); arr.setProperty(args.context(), 2u, js::Value::number(w)); arr.setProperty(args.context(), 3u, js::Value::number(h)); args.returnValue(std::move(arr)); } // joy.graphics.arc(mode, arctype, x, y, radius, angle1, angle2, segments) static void js_graphics_arc(js::FunctionArgs &args) { if (args.length() < 7) { args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } std::string mode = args.arg(0).toString(args.context()); // Check if second arg is arctype (string) or x (number) int arg_offset = 0; std::string arctype = "pie"; if (args.arg(1).isString()) { arctype = args.arg(1).toString(args.context()); arg_offset = 1; } float x = static_cast<float>(args.arg(1 + arg_offset).toFloat64()); float y = static_cast<float>(args.arg(2 + arg_offset).toFloat64()); float radius = static_cast<float>(args.arg(3 + arg_offset).toFloat64()); float angle1 = static_cast<float>(args.arg(4 + arg_offset).toFloat64()); float angle2 = static_cast<float>(args.arg(5 + arg_offset).toFloat64()); int segments = 10; if (args.length() > 6 + arg_offset) { segments = args.arg(6 + arg_offset).toInt32(); } graphics->arc(mode.c_str(), arctype.c_str(), x, y, radius, angle1, angle2, segments); args.returnUndefined(); } // joy.graphics.ellipse(mode, x, y, radiusx, radiusy, segments) static void js_graphics_ellipse(js::FunctionArgs &args) { if (args.length() < 5) { args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } std::string mode = args.arg(0).toString(args.context()); float x = static_cast<float>(args.arg(1).toFloat64()); float y = static_cast<float>(args.arg(2).toFloat64()); float rx = static_cast<float>(args.arg(3).toFloat64()); float ry = static_cast<float>(args.arg(4).toFloat64()); int segments = 32; if (args.length() > 5) { segments = args.arg(5).toInt32(); } graphics->ellipse(mode.c_str(), x, y, rx, ry, segments); args.returnUndefined(); } // joy.graphics.setLineWidth(width) static void js_graphics_setLineWidth(js::FunctionArgs &args) { if (args.length() < 1) { args.returnUndefined(); return; } Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } float width = static_cast<float>(args.arg(0).toFloat64()); graphics->setLineWidth(width); args.returnUndefined(); } // joy.graphics.getLineWidth() static void js_graphics_getLineWidth(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); args.returnValue(js::Value::number(graphics ? graphics->getLineWidth() : 1.0)); } // ============================================================================ // Canvas functions // ============================================================================ // joy.graphics.newCanvas(width, height, format) static void js_graphics_newCanvas(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnValue(js::Value::null()); return; } // Default to screen size if no dimensions given int width = graphics->getWidth(); int height = graphics->getHeight(); const char *format = "normal"; if (args.length() >= 1) { width = args.arg(0).toInt32(); } if (args.length() >= 2) { height = args.arg(1).toInt32(); } std::string fmt_str; if (args.length() >= 3) { fmt_str = args.arg(2).toString(args.context()); format = fmt_str.c_str(); } Canvas *canvas = graphics->newCanvas(width, height, format); if (!canvas) { args.returnValue(js::Value::null()); return; } js::Value obj = js::ClassBuilder::newInstance(args.context(), canvas_class_id); js::ClassBuilder::setOpaque(obj, canvas); args.returnValue(std::move(obj)); } // joy.graphics.setCanvas(canvas) or joy.graphics.setCanvas() to reset static void js_graphics_setCanvas(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } if (args.length() == 0 || args.arg(0).isNull() || args.arg(0).isUndefined()) { // Reset to screen rendering graphics->setCanvas(nullptr); } else { js::Value canvasVal = args.arg(0); Canvas *canvas = static_cast<Canvas *>(js::ClassBuilder::getOpaque(canvasVal, canvas_class_id)); if (canvas) { graphics->setCanvas(canvas); } } args.returnUndefined(); } // joy.graphics.getCanvas() static void js_graphics_getCanvas(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnValue(js::Value::null()); return; } Canvas *canvas = graphics->getCanvas(); if (!canvas) { args.returnValue(js::Value::null()); return; } // Note: We can't easily return the original JS object, so return null // A proper implementation would store the JS object reference args.returnValue(js::Value::null()); } // canvas:getWidth() static void js_canvas_getWidth(js::FunctionArgs &args) { Canvas *canvas = getCanvas(args); args.returnValue(js::Value::number(canvas ? canvas->getWidth() : 0)); } // canvas:getHeight() static void js_canvas_getHeight(js::FunctionArgs &args) { Canvas *canvas = getCanvas(args); args.returnValue(js::Value::number(canvas ? canvas->getHeight() : 0)); } // canvas:getDimensions() static void js_canvas_getDimensions(js::FunctionArgs &args) { Canvas *canvas = getCanvas(args); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::number(canvas ? canvas->getWidth() : 0)); arr.setProperty(args.context(), 1u, js::Value::number(canvas ? canvas->getHeight() : 0)); args.returnValue(std::move(arr)); } // canvas:setFilter(min, mag) static void js_canvas_setFilter(js::FunctionArgs &args) { Canvas *canvas = getCanvas(args); if (canvas && args.length() >= 2) { std::string min = args.arg(0).toString(args.context()); std::string mag = args.arg(1).toString(args.context()); canvas->setFilter(min.c_str(), mag.c_str()); } args.returnUndefined(); } // canvas:getFilter() static void js_canvas_getFilter(js::FunctionArgs &args) { Canvas *canvas = getCanvas(args); if (!canvas) { args.returnUndefined(); return; } const char *min, *mag; canvas->getFilter(&min, &mag); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::string(args.context(), min)); arr.setProperty(args.context(), 1u, js::Value::string(args.context(), mag)); args.returnValue(std::move(arr)); } // canvas:setWrap(horiz, vert) static void js_canvas_setWrap(js::FunctionArgs &args) { Canvas *canvas = getCanvas(args); if (canvas && args.length() >= 2) { std::string horiz = args.arg(0).toString(args.context()); std::string vert = args.arg(1).toString(args.context()); canvas->setWrap(horiz.c_str(), vert.c_str()); } args.returnUndefined(); } // canvas:getWrap() static void js_canvas_getWrap(js::FunctionArgs &args) { Canvas *canvas = getCanvas(args); if (!canvas) { args.returnUndefined(); return; } const char *horiz, *vert; canvas->getWrap(&horiz, &vert); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::string(args.context(), horiz)); arr.setProperty(args.context(), 1u, js::Value::string(args.context(), vert)); args.returnValue(std::move(arr)); } // ============================================================================ // Shader functions // ============================================================================ // joy.graphics.newShader(pixelCode) or joy.graphics.newShader(pixelCode, vertexCode) static void js_graphics_newShader(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics || args.length() < 1) { args.returnValue(js::Value::null()); return; } std::string pixel_code = args.arg(0).toString(args.context()); std::string vertex_code; const char *vertex_ptr = nullptr; if (args.length() >= 2 && !args.arg(1).isNull() && !args.arg(1).isUndefined()) { vertex_code = args.arg(1).toString(args.context()); vertex_ptr = vertex_code.c_str(); } Shader *shader = graphics->newShader(pixel_code.c_str(), vertex_ptr); if (!shader) { args.returnValue(js::Value::null()); return; } js::Value obj = js::ClassBuilder::newInstance(args.context(), shader_class_id); js::ClassBuilder::setOpaque(obj, shader); args.returnValue(std::move(obj)); } // joy.graphics.setShader(shader) or joy.graphics.setShader() to reset static void js_graphics_setShader(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnUndefined(); return; } if (args.length() == 0 || args.arg(0).isNull() || args.arg(0).isUndefined()) { // Reset to default shader graphics->setShader(nullptr); } else { js::Value shaderVal = args.arg(0); Shader *shader = static_cast<Shader *>(js::ClassBuilder::getOpaque(shaderVal, shader_class_id)); if (shader) { graphics->setShader(shader); } } args.returnUndefined(); } // joy.graphics.getShader() static void js_graphics_getShader(js::FunctionArgs &args) { Graphics *graphics = getGraphics(args); if (!graphics) { args.returnValue(js::Value::null()); return; } Shader *shader = graphics->getShader(); if (!shader) { args.returnValue(js::Value::null()); return; } // Note: We can't easily return the original JS object, so return null // A proper implementation would store the JS object reference args.returnValue(js::Value::null()); } // shader:send(name, value, ...) // Supports: number, vec2/3/4 (array), bool, Image, Canvas static void js_shader_send(js::FunctionArgs &args) { Shader *shader = getShader(args); if (!shader || args.length() < 2) { args.returnUndefined(); return; } std::string name = args.arg(0).toString(args.context()); js::Value value = args.arg(1); if (value.isNumber()) { // Single float shader->sendFloat(name.c_str(), static_cast<float>(value.toFloat64())); } else if (value.isBoolean()) { // Boolean shader->sendBool(name.c_str(), value.toBool()); } else if (value.isArray()) { // Array - could be vec2/3/4 or matrix js::Value lengthVal = value.getProperty(args.context(), "length"); uint32_t len = static_cast<uint32_t>(lengthVal.toInt32()); if (len == 2) { float x = static_cast<float>(value.getProperty(args.context(), 0u).toFloat64()); float y = static_cast<float>(value.getProperty(args.context(), 1u).toFloat64()); shader->sendVec2(name.c_str(), x, y); } else if (len == 3) { float x = static_cast<float>(value.getProperty(args.context(), 0u).toFloat64()); float y = static_cast<float>(value.getProperty(args.context(), 1u).toFloat64()); float z = static_cast<float>(value.getProperty(args.context(), 2u).toFloat64()); shader->sendVec3(name.c_str(), x, y, z); } else if (len == 4) { float x = static_cast<float>(value.getProperty(args.context(), 0u).toFloat64()); float y = static_cast<float>(value.getProperty(args.context(), 1u).toFloat64()); float z = static_cast<float>(value.getProperty(args.context(), 2u).toFloat64()); float w = static_cast<float>(value.getProperty(args.context(), 3u).toFloat64()); shader->sendVec4(name.c_str(), x, y, z, w); } else if (len == 16) { // mat4 float matrix[16]; for (uint32_t i = 0; i < 16; i++) { matrix[i] = static_cast<float>(value.getProperty(args.context(), i).toFloat64()); } shader->sendMat4(name.c_str(), matrix); } } else if (value.isObject()) { // Check if it's a Texture (Image) or Canvas Texture *tex = static_cast<Texture *>(js::ClassBuilder::getOpaque(value, texture_class_id)); if (tex) { shader->sendTexture(name.c_str(), tex); } else { Canvas *canvas = static_cast<Canvas *>(js::ClassBuilder::getOpaque(value, canvas_class_id)); if (canvas) { shader->sendCanvas(name.c_str(), canvas); } } } args.returnUndefined(); } // shader:hasUniform(name) static void js_shader_hasUniform(js::FunctionArgs &args) { Shader *shader = getShader(args); if (!shader || args.length() < 1) { args.returnValue(js::Value::boolean(false)); return; } std::string name = args.arg(0).toString(args.context()); args.returnValue(js::Value::boolean(shader->hasUniform(name.c_str()))); } // shader:getWarnings() static void js_shader_getWarnings(js::FunctionArgs &args) { Shader *shader = getShader(args); if (!shader) { args.returnValue(js::Value::string(args.context(), "")); return; } args.returnValue(js::Value::string(args.context(), shader->getWarnings().c_str())); } // shader:getVertexSource() - debug method to get generated vertex shader static void js_shader_getVertexSource(js::FunctionArgs &args) { Shader *shader = getShader(args); if (!shader) { args.returnValue(js::Value::string(args.context(), "")); return; } args.returnValue(js::Value::string(args.context(), shader->getVertexSource().c_str())); } // shader:getPixelSource() - debug method to get generated pixel shader static void js_shader_getPixelSource(js::FunctionArgs &args) { Shader *shader = getShader(args); if (!shader) { args.returnValue(js::Value::string(args.context(), "")); return; } args.returnValue(js::Value::string(args.context(), shader->getPixelSource().c_str())); } void Graphics::initJS(js::Context &ctx, js::Value &joy) { // Register Font class js::ClassDef fontDef; fontDef.name = "Font"; fontDef.finalizer = font_finalizer; font_class_id = js::ClassBuilder::registerClass(ctx, fontDef); // Create Font prototype with all Love2D Font methods js::Value fontProto = js::ModuleBuilder(ctx, "__font_proto__") .function("getHeight", js_font_getHeight, 0) .function("getWidth", js_font_getWidth, 1) .function("getAscent", js_font_getAscent, 0) .function("getDescent", js_font_getDescent, 0) .function("getBaseline", js_font_getBaseline, 0) .function("getLineHeight", js_font_getLineHeight, 0) .function("setLineHeight", js_font_setLineHeight, 1) .function("getDPIScale", js_font_getDPIScale, 0) .function("getWrap", js_font_getWrap, 2) .function("hasGlyphs", js_font_hasGlyphs, 1) .function("getKerning", js_font_getKerning, 2) .function("setFilter", js_font_setFilter, 2) .function("getFilter", js_font_getFilter, 0) .function("setFallbacks", js_font_setFallbacks, 1) .build(); js::ClassBuilder::setPrototype(ctx, font_class_id, fontProto); // Register Texture class (exposed as "Image" in JS to match Love2D API) js::ClassDef textureDef; textureDef.name = "Image"; textureDef.finalizer = texture_finalizer; texture_class_id = js::ClassBuilder::registerClass(ctx, textureDef); // Create Image prototype with methods js::Value imageProto = js::ModuleBuilder(ctx, "__image_proto__") .function("getWidth", js_image_getWidth, 0) .function("getHeight", js_image_getHeight, 0) .function("getDimensions", js_image_getDimensions, 0) .function("setFilter", js_image_setFilter, 2) .function("getFilter", js_image_getFilter, 0) .function("setWrap", js_image_setWrap, 2) .function("getWrap", js_image_getWrap, 0) .build(); js::ClassBuilder::setPrototype(ctx, texture_class_id, imageProto); // Register Quad class js::ClassDef quadDef; quadDef.name = "Quad"; quadDef.finalizer = quad_finalizer; quad_class_id = js::ClassBuilder::registerClass(ctx, quadDef); // Create Quad prototype with methods js::Value quadProto = js::ModuleBuilder(ctx, "__quad_proto__") .function("getViewport", js_quad_getViewport, 0) .function("setViewport", js_quad_setViewport, 6) .function("getTextureDimensions", js_quad_getTextureDimensions, 0) .build(); js::ClassBuilder::setPrototype(ctx, quad_class_id, quadProto); // Register Canvas class js::ClassDef canvasDef; canvasDef.name = "Canvas"; canvasDef.finalizer = canvas_finalizer; canvas_class_id = js::ClassBuilder::registerClass(ctx, canvasDef); // Create Canvas prototype with methods js::Value canvasProto = js::ModuleBuilder(ctx, "__canvas_proto__") .function("getWidth", js_canvas_getWidth, 0) .function("getHeight", js_canvas_getHeight, 0) .function("getDimensions", js_canvas_getDimensions, 0) .function("setFilter", js_canvas_setFilter, 2) .function("getFilter", js_canvas_getFilter, 0) .function("setWrap", js_canvas_setWrap, 2) .function("getWrap", js_canvas_getWrap, 0) .build(); js::ClassBuilder::setPrototype(ctx, canvas_class_id, canvasProto); // Register Shader class js::ClassDef shaderDef; shaderDef.name = "Shader"; shaderDef.finalizer = shader_finalizer; shader_class_id = js::ClassBuilder::registerClass(ctx, shaderDef); // Create Shader prototype with methods js::Value shaderProto = js::ModuleBuilder(ctx, "__shader_proto__") .function("send", js_shader_send, 2) .function("hasUniform", js_shader_hasUniform, 1) .function("getWarnings", js_shader_getWarnings, 0) .function("getVertexSource", js_shader_getVertexSource, 0) .function("getPixelSource", js_shader_getPixelSource, 0) .build(); js::ClassBuilder::setPrototype(ctx, shader_class_id, shaderProto); js::ModuleBuilder(ctx, "graphics") .function("setColor", js_graphics_setColor, 4) .function("getColor", js_graphics_getColor, 0) .function("setBackgroundColor", js_graphics_setBackgroundColor, 4) .function("getBackgroundColor", js_graphics_getBackgroundColor, 0) .function("rectangle", js_graphics_rectangle, 5) .function("circle", js_graphics_circle, 4) .function("line", js_graphics_line, 4) .function("point", js_graphics_point, 2) .function("points", js_graphics_point, 2) .function("polygon", js_graphics_polygon, 7) .function("arc", js_graphics_arc, 7) .function("ellipse", js_graphics_ellipse, 5) .function("print", js_graphics_print, 3) .function("newFont", js_graphics_newFont, 2) .function("setFont", js_graphics_setFont, 1) .function("getFont", js_graphics_getFont, 0) .function("setNewFont", js_graphics_setNewFont, 2) .function("newImage", js_graphics_newImage, 1) .function("newQuad", js_graphics_newQuad, 6) .function("draw", js_graphics_draw, 9) .function("drawQuad", js_graphics_drawQuad, 12) .function("getWidth", js_graphics_getWidth, 0) .function("getHeight", js_graphics_getHeight, 0) .function("getDimensions", js_graphics_getDimensions, 0) .function("clear", js_graphics_clear, 4) .function("push", js_graphics_push, 0) .function("pop", js_graphics_pop, 0) .function("translate", js_graphics_translate, 2) .function("rotate", js_graphics_rotate, 1) .function("scale", js_graphics_scale, 2) .function("origin", js_graphics_origin, 0) .function("getStats", js_graphics_getStats, 0) .function("getDPIScale", js_graphics_getDPIScale, 0) .function("setBlendMode", js_graphics_setBlendMode, 1) .function("getBlendMode", js_graphics_getBlendMode, 0) .function("setScissor", js_graphics_setScissor, 4) .function("getScissor", js_graphics_getScissor, 0) .function("setLineWidth", js_graphics_setLineWidth, 1) .function("getLineWidth", js_graphics_getLineWidth, 0) .function("newCanvas", js_graphics_newCanvas, 3) .function("setCanvas", js_graphics_setCanvas, 1) .function("getCanvas", js_graphics_getCanvas, 0) .function("newShader", js_graphics_newShader, 2) .function("setShader", js_graphics_setShader, 1) .function("getShader", js_graphics_getShader, 0) .attachTo(joy); } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/pipeline_cache.cc
C++
#include "pipeline_cache.hh" #include <cstdio> #include <cstring> namespace joy { namespace modules { // ============================================================================ // PipelineKey Implementation // ============================================================================ PipelineKey PipelineKey::make( uint16_t shader_id, const BlendState &blend, PrimitiveType primitive, ColorMask color_mask, uint8_t msaa, RenderPixelFormat format, const DepthState &depth, const StencilState &stencil) { PipelineKey key; key.shader_id = shader_id; key.blend_key = blend.toKey(); key.primitive = static_cast<uint8_t>(primitive); key.color_mask = color_mask.toKey(); // Encode MSAA: 1->0, 2->1, 4->2, 8->3, 16->4 key.msaa = (msaa <= 1) ? 0 : (msaa <= 2) ? 1 : (msaa <= 4) ? 2 : (msaa <= 8) ? 3 : 4; key.pixel_format = static_cast<uint8_t>(format); key.depth_state = depth.toKey(); key.stencil_mode = stencil.toKey(); return key; } bool PipelineKey::operator==(const PipelineKey &other) const { return shader_id == other.shader_id && blend_key == other.blend_key && primitive == other.primitive && color_mask == other.color_mask && msaa == other.msaa && pixel_format == other.pixel_format && depth_state == other.depth_state && stencil_mode == other.stencil_mode; } uint64_t PipelineKey::pack() const { uint64_t result = 0; result |= static_cast<uint64_t>(shader_id); result |= static_cast<uint64_t>(blend_key) << 16; result |= static_cast<uint64_t>(primitive) << 40; result |= static_cast<uint64_t>(color_mask) << 42; result |= static_cast<uint64_t>(msaa) << 46; result |= static_cast<uint64_t>(pixel_format) << 49; result |= static_cast<uint64_t>(depth_state) << 53; result |= static_cast<uint64_t>(stencil_mode) << 57; return result; } // ============================================================================ // PipelineCache Implementation // ============================================================================ PipelineCache::PipelineCache() { // Reserve slot 0 for default shader shaders_.push_back({SG_INVALID_ID}); } PipelineCache::~PipelineCache() { shutdown(); } bool PipelineCache::init(sg_shader default_shader, const sg_vertex_layout_state &vertex_layout) { if (initialized_) { return true; } shaders_[0] = default_shader; vertex_layout_ = vertex_layout; initialized_ = true; return true; } void PipelineCache::shutdown() { if (!initialized_) { return; } // Destroy all cached pipelines for (auto &pair : cache_) { if (pair.second.id != SG_INVALID_ID) { sg_destroy_pipeline(pair.second); } } cache_.clear(); // Note: We don't destroy shaders here - they're owned by caller shaders_.clear(); shaders_.push_back({SG_INVALID_ID}); // Re-add slot 0 cache_hits_ = 0; cache_misses_ = 0; initialized_ = false; } sg_pipeline PipelineCache::get(const PipelineKey &key) { auto it = cache_.find(key); if (it != cache_.end()) { cache_hits_++; return it->second; } cache_misses_++; sg_pipeline pip = createPipeline(key); if (pip.id != SG_INVALID_ID) { cache_[key] = pip; } return pip; } sg_pipeline PipelineCache::createPipeline(const PipelineKey &key) { if (key.shader_id >= shaders_.size() || shaders_[key.shader_id].id == SG_INVALID_ID) { fprintf(stderr, "PipelineCache: Invalid shader ID %u\n", key.shader_id); return {SG_INVALID_ID}; } sg_pipeline_desc desc = {}; desc.shader = shaders_[key.shader_id]; desc.layout = vertex_layout_; desc.index_type = SG_INDEXTYPE_UINT16; desc.label = "dynamic_pipeline"; // Primitive type desc.primitive_type = toSokolPrimitive(key.primitive); // Blend state BlendState blend = BlendState::fromKey(key.blend_key); desc.colors[0].blend.enabled = blend.enabled; if (blend.enabled) { desc.colors[0].blend.src_factor_rgb = toSokolBlendFactor(blend.src_rgb); desc.colors[0].blend.dst_factor_rgb = toSokolBlendFactor(blend.dst_rgb); desc.colors[0].blend.op_rgb = toSokolBlendOp(blend.op_rgb); desc.colors[0].blend.src_factor_alpha = toSokolBlendFactor(blend.src_alpha); desc.colors[0].blend.dst_factor_alpha = toSokolBlendFactor(blend.dst_alpha); desc.colors[0].blend.op_alpha = toSokolBlendOp(blend.op_alpha); } // Color mask uint32_t color_mask = 0; if (key.color_mask & 1) color_mask |= SG_COLORMASK_R; if (key.color_mask & 2) color_mask |= SG_COLORMASK_G; if (key.color_mask & 4) color_mask |= SG_COLORMASK_B; if (key.color_mask & 8) color_mask |= SG_COLORMASK_A; desc.colors[0].write_mask = static_cast<sg_color_mask>(color_mask); // Pixel format (for render targets) - only set if not default RenderPixelFormat format = static_cast<RenderPixelFormat>(key.pixel_format); if (format != RenderPixelFormat::Default) { desc.colors[0].pixel_format = toSokolPixelFormat(format); } // MSAA static const int msaa_samples[] = {1, 2, 4, 8, 16}; desc.sample_count = msaa_samples[key.msaa]; // Depth state DepthState depth = DepthState::fromKey(key.depth_state); desc.depth.write_enabled = depth.write; desc.depth.compare = toSokolCompareFunc(depth.compare); // Stencil state StencilState stencil = StencilState::fromKey(key.stencil_mode); desc.stencil.enabled = stencil.enabled; if (stencil.enabled) { desc.stencil.front.compare = toSokolCompareFunc(stencil.compare); desc.stencil.front.fail_op = toSokolStencilOp(stencil.fail); desc.stencil.front.depth_fail_op = toSokolStencilOp(stencil.depth_fail); desc.stencil.front.pass_op = toSokolStencilOp(stencil.pass); desc.stencil.back = desc.stencil.front; // Same for back faces desc.stencil.read_mask = stencil.read_mask; desc.stencil.write_mask = stencil.write_mask; desc.stencil.ref = stencil.ref; } return sg_make_pipeline(&desc); } uint16_t PipelineCache::registerShader(sg_shader shader) { uint16_t id = static_cast<uint16_t>(shaders_.size()); shaders_.push_back(shader); return id; } void PipelineCache::invalidateShader(uint16_t shader_id) { // Remove all pipelines using this shader for (auto it = cache_.begin(); it != cache_.end(); ) { if (it->first.shader_id == shader_id) { sg_destroy_pipeline(it->second); it = cache_.erase(it); } else { ++it; } } } void PipelineCache::clear() { for (auto &pair : cache_) { if (pair.second.id != SG_INVALID_ID) { sg_destroy_pipeline(pair.second); } } cache_.clear(); } void PipelineCache::warmup() { // Pre-create common pipeline combinations BlendMode modes[] = {BlendMode::Alpha, BlendMode::Add, BlendMode::None}; PrimitiveType prims[] = {PrimitiveType::Triangles, PrimitiveType::Lines}; for (auto mode : modes) { for (auto prim : prims) { PipelineKey key = PipelineKey::make(0, blendModeToState(mode), prim); get(key); // Creates and caches pipeline } } } // ============================================================================ // Sokol Type Conversions // ============================================================================ sg_primitive_type PipelineCache::toSokolPrimitive(uint8_t primitive) { switch (primitive) { case 0: return SG_PRIMITIVETYPE_TRIANGLES; case 1: return SG_PRIMITIVETYPE_LINES; case 2: return SG_PRIMITIVETYPE_POINTS; default: return SG_PRIMITIVETYPE_TRIANGLES; } } sg_blend_factor PipelineCache::toSokolBlendFactor(BlendFactor factor) { switch (factor) { case BlendFactor::Zero: return SG_BLENDFACTOR_ZERO; case BlendFactor::One: return SG_BLENDFACTOR_ONE; case BlendFactor::SrcColor: return SG_BLENDFACTOR_SRC_COLOR; case BlendFactor::OneMinusSrcColor: return SG_BLENDFACTOR_ONE_MINUS_SRC_COLOR; case BlendFactor::SrcAlpha: return SG_BLENDFACTOR_SRC_ALPHA; case BlendFactor::OneMinusSrcAlpha: return SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; case BlendFactor::DstColor: return SG_BLENDFACTOR_DST_COLOR; case BlendFactor::OneMinusDstColor: return SG_BLENDFACTOR_ONE_MINUS_DST_COLOR; case BlendFactor::DstAlpha: return SG_BLENDFACTOR_DST_ALPHA; case BlendFactor::OneMinusDstAlpha: return SG_BLENDFACTOR_ONE_MINUS_DST_ALPHA; case BlendFactor::SrcAlphaSaturated: return SG_BLENDFACTOR_SRC_ALPHA_SATURATED; default: return SG_BLENDFACTOR_ONE; } } sg_blend_op PipelineCache::toSokolBlendOp(BlendOp op) { switch (op) { case BlendOp::Add: return SG_BLENDOP_ADD; case BlendOp::Subtract: return SG_BLENDOP_SUBTRACT; case BlendOp::ReverseSubtract: return SG_BLENDOP_REVERSE_SUBTRACT; case BlendOp::Min: return SG_BLENDOP_MIN; case BlendOp::Max: return SG_BLENDOP_MAX; default: return SG_BLENDOP_ADD; } } sg_pixel_format PipelineCache::toSokolPixelFormat(RenderPixelFormat format) { switch (format) { case RenderPixelFormat::RGBA8: return SG_PIXELFORMAT_RGBA8; case RenderPixelFormat::BGRA8: return SG_PIXELFORMAT_BGRA8; case RenderPixelFormat::RGBA16F: return SG_PIXELFORMAT_RGBA16F; case RenderPixelFormat::RGBA32F: return SG_PIXELFORMAT_RGBA32F; case RenderPixelFormat::R8: return SG_PIXELFORMAT_R8; case RenderPixelFormat::RG8: return SG_PIXELFORMAT_RG8; case RenderPixelFormat::Depth: return SG_PIXELFORMAT_DEPTH; case RenderPixelFormat::DepthStencil: return SG_PIXELFORMAT_DEPTH_STENCIL; default: return SG_PIXELFORMAT_RGBA8; } } sg_compare_func PipelineCache::toSokolCompareFunc(CompareMode mode) { switch (mode) { case CompareMode::Less: return SG_COMPAREFUNC_LESS; case CompareMode::LessEqual: return SG_COMPAREFUNC_LESS_EQUAL; case CompareMode::Equal: return SG_COMPAREFUNC_EQUAL; case CompareMode::GreaterEqual: return SG_COMPAREFUNC_GREATER_EQUAL; case CompareMode::Greater: return SG_COMPAREFUNC_GREATER; case CompareMode::NotEqual: return SG_COMPAREFUNC_NOT_EQUAL; case CompareMode::Always: return SG_COMPAREFUNC_ALWAYS; case CompareMode::Never: return SG_COMPAREFUNC_NEVER; default: return SG_COMPAREFUNC_ALWAYS; } } sg_stencil_op PipelineCache::toSokolStencilOp(StencilAction action) { switch (action) { case StencilAction::Keep: return SG_STENCILOP_KEEP; case StencilAction::Zero: return SG_STENCILOP_ZERO; case StencilAction::Replace: return SG_STENCILOP_REPLACE; case StencilAction::Increment: return SG_STENCILOP_INCR_CLAMP; case StencilAction::Decrement: return SG_STENCILOP_DECR_CLAMP; case StencilAction::IncrementWrap: return SG_STENCILOP_INCR_WRAP; case StencilAction::DecrementWrap: return SG_STENCILOP_DECR_WRAP; case StencilAction::Invert: return SG_STENCILOP_INVERT; default: return SG_STENCILOP_KEEP; } } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/pipeline_cache.hh
C++ Header
#pragma once #include "sokol_gfx.h" #include "renderstate.hh" #include <cstdint> #include <unordered_map> #include <vector> namespace joy { namespace modules { // ============================================================================ // Primitive Type (shared with BatchRenderer) // ============================================================================ enum class PrimitiveType : uint8_t { Triangles = 0, Lines, Points, Count }; // ============================================================================ // Render Target Pixel Format // ============================================================================ enum class RenderPixelFormat : uint8_t { RGBA8 = 0, BGRA8, RGBA16F, RGBA32F, R8, RG8, Depth, DepthStencil, Default, // Use default framebuffer format Count }; // ============================================================================ // Pipeline Key - Compact identifier for pipeline configuration // ============================================================================ struct PipelineKey { // Shader ID (0 = default batch shader, or custom shader handle) uint16_t shader_id = 0; // Blend state packed into 24 bits (see BlendState::toKey()) uint32_t blend_key = 0; // Primitive type (2 bits: 0=triangles, 1=lines, 2=points) uint8_t primitive = 0; // Color mask (4 bits: RGBA enable flags) uint8_t color_mask = 0xF; // MSAA sample count encoded (3 bits: 0=1x, 1=2x, 2=4x, 3=8x, 4=16x) uint8_t msaa = 0; // Render target pixel format (4 bits) uint8_t pixel_format = 0; // Depth state (4 bits: [write:1][compare:3]) uint8_t depth_state = 0; // Stencil mode (4 bits: simplified stencil config) uint8_t stencil_mode = 0; PipelineKey() = default; // Construct from current state static PipelineKey make( uint16_t shader_id, const BlendState &blend, PrimitiveType primitive, ColorMask color_mask = ColorMask::All(), uint8_t msaa = 1, RenderPixelFormat format = RenderPixelFormat::Default, const DepthState &depth = DepthState::Disabled(), const StencilState &stencil = StencilState::Disabled() ); bool operator==(const PipelineKey &other) const; bool operator!=(const PipelineKey &other) const { return !(*this == other); } // Pack into 64-bit integer for hashing uint64_t pack() const; }; // Hash function for PipelineKey struct PipelineKeyHash { size_t operator()(const PipelineKey &key) const { return static_cast<size_t>(key.pack()); } }; // ============================================================================ // Pipeline Cache // ============================================================================ class PipelineCache { public: PipelineCache(); ~PipelineCache(); // Initialize with default shader and vertex layout bool init(sg_shader default_shader, const sg_vertex_layout_state &vertex_layout); void shutdown(); // Get or create pipeline for given key // Returns SG_INVALID_ID if creation fails sg_pipeline get(const PipelineKey &key); // Register a custom shader (returns shader_id for use in PipelineKey) uint16_t registerShader(sg_shader shader); // Invalidate all pipelines using a specific shader (for shader hot-reload) void invalidateShader(uint16_t shader_id); // Clear all cached pipelines void clear(); // Pre-create common pipeline combinations to avoid first-frame hitches void warmup(); // Stats size_t getCacheSize() const { return cache_.size(); } size_t getCacheHits() const { return cache_hits_; } size_t getCacheMisses() const { return cache_misses_; } void resetStats() { cache_hits_ = 0; cache_misses_ = 0; } private: sg_pipeline createPipeline(const PipelineKey &key); // Convert enums to sokol types sg_primitive_type toSokolPrimitive(uint8_t primitive); sg_blend_factor toSokolBlendFactor(BlendFactor factor); sg_blend_op toSokolBlendOp(BlendOp op); sg_pixel_format toSokolPixelFormat(RenderPixelFormat format); sg_compare_func toSokolCompareFunc(CompareMode mode); sg_stencil_op toSokolStencilOp(StencilAction action); std::unordered_map<PipelineKey, sg_pipeline, PipelineKeyHash> cache_; std::vector<sg_shader> shaders_; // Index 0 = default shader // Vertex layout (shared by all pipelines) sg_vertex_layout_state vertex_layout_; // Stats mutable size_t cache_hits_ = 0; mutable size_t cache_misses_ = 0; bool initialized_ = false; }; } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/renderstate.cc
C++
#include "renderstate.hh" namespace joy { namespace modules { // ============================================================================ // BlendState Implementation // ============================================================================ uint32_t BlendState::toKey() const { return (static_cast<uint32_t>(dst_alpha) << 0) | (static_cast<uint32_t>(dst_rgb) << 4) | (static_cast<uint32_t>(src_alpha) << 8) | (static_cast<uint32_t>(src_rgb) << 12) | (static_cast<uint32_t>(op_alpha) << 16) | (static_cast<uint32_t>(op_rgb) << 19) | (static_cast<uint32_t>(enabled ? 1 : 0) << 22); } BlendState BlendState::fromKey(uint32_t key) { BlendState b; b.dst_alpha = static_cast<BlendFactor>((key >> 0) & 0xF); b.dst_rgb = static_cast<BlendFactor>((key >> 4) & 0xF); b.src_alpha = static_cast<BlendFactor>((key >> 8) & 0xF); b.src_rgb = static_cast<BlendFactor>((key >> 12) & 0xF); b.op_alpha = static_cast<BlendOp>((key >> 16) & 0x7); b.op_rgb = static_cast<BlendOp>((key >> 19) & 0x7); b.enabled = ((key >> 22) & 1) != 0; return b; } bool BlendState::operator==(const BlendState &other) const { return enabled == other.enabled && op_rgb == other.op_rgb && op_alpha == other.op_alpha && src_rgb == other.src_rgb && src_alpha == other.src_alpha && dst_rgb == other.dst_rgb && dst_alpha == other.dst_alpha; } // Standard alpha blend: srcAlpha, 1-srcAlpha BlendState BlendState::Alpha() { BlendState b; b.enabled = true; b.op_rgb = b.op_alpha = BlendOp::Add; b.src_rgb = BlendFactor::SrcAlpha; b.src_alpha = BlendFactor::One; b.dst_rgb = BlendFactor::OneMinusSrcAlpha; b.dst_alpha = BlendFactor::OneMinusSrcAlpha; return b; } // Premultiplied alpha: 1, 1-srcAlpha BlendState BlendState::AlphaPremultiplied() { BlendState b; b.enabled = true; b.op_rgb = b.op_alpha = BlendOp::Add; b.src_rgb = BlendFactor::One; b.src_alpha = BlendFactor::One; b.dst_rgb = BlendFactor::OneMinusSrcAlpha; b.dst_alpha = BlendFactor::OneMinusSrcAlpha; return b; } // Additive: srcAlpha, 1 BlendState BlendState::Add() { BlendState b; b.enabled = true; b.op_rgb = b.op_alpha = BlendOp::Add; b.src_rgb = BlendFactor::SrcAlpha; b.src_alpha = BlendFactor::One; b.dst_rgb = BlendFactor::One; b.dst_alpha = BlendFactor::One; return b; } // Multiply: dstColor, 1-srcAlpha BlendState BlendState::Multiply() { BlendState b; b.enabled = true; b.op_rgb = b.op_alpha = BlendOp::Add; b.src_rgb = BlendFactor::DstColor; b.src_alpha = BlendFactor::One; b.dst_rgb = BlendFactor::OneMinusSrcAlpha; b.dst_alpha = BlendFactor::OneMinusSrcAlpha; return b; } // Screen: 1, 1-srcColor BlendState BlendState::Screen() { BlendState b; b.enabled = true; b.op_rgb = b.op_alpha = BlendOp::Add; b.src_rgb = BlendFactor::One; b.src_alpha = BlendFactor::One; b.dst_rgb = BlendFactor::OneMinusSrcColor; b.dst_alpha = BlendFactor::OneMinusSrcAlpha; return b; } // Replace (no blending) BlendState BlendState::Replace() { BlendState b; b.enabled = false; return b; } BlendState BlendState::None() { return Replace(); } // ============================================================================ // BlendMode Conversion // ============================================================================ BlendState blendModeToState(BlendMode mode) { switch (mode) { case BlendMode::None: return BlendState::None(); case BlendMode::Alpha: return BlendState::Alpha(); case BlendMode::AlphaPremultiplied:return BlendState::AlphaPremultiplied(); case BlendMode::Add: return BlendState::Add(); case BlendMode::Multiply: return BlendState::Multiply(); case BlendMode::Screen: return BlendState::Screen(); default: return BlendState::Alpha(); } } BlendMode stateToBlendMode(const BlendState &state) { // Compare against known presets if (!state.enabled) return BlendMode::None; if (state == BlendState::Alpha()) return BlendMode::Alpha; if (state == BlendState::AlphaPremultiplied()) return BlendMode::AlphaPremultiplied; if (state == BlendState::Add()) return BlendMode::Add; if (state == BlendState::Multiply()) return BlendMode::Multiply; if (state == BlendState::Screen()) return BlendMode::Screen; return BlendMode::Custom; } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/renderstate.hh
C++ Header
#pragma once #include <cstdint> namespace joy { namespace modules { // ============================================================================ // Blend Factor and Operation Enums // ============================================================================ enum class BlendFactor : uint8_t { Zero = 0, One, SrcColor, OneMinusSrcColor, SrcAlpha, OneMinusSrcAlpha, DstColor, OneMinusDstColor, DstAlpha, OneMinusDstAlpha, SrcAlphaSaturated, Count }; enum class BlendOp : uint8_t { Add = 0, Subtract, ReverseSubtract, Min, Max, Count }; // ============================================================================ // BlendState - Low-level blend configuration // ============================================================================ struct BlendState { BlendOp op_rgb = BlendOp::Add; BlendOp op_alpha = BlendOp::Add; BlendFactor src_rgb = BlendFactor::One; BlendFactor src_alpha = BlendFactor::One; BlendFactor dst_rgb = BlendFactor::Zero; BlendFactor dst_alpha = BlendFactor::Zero; bool enabled = false; // Pack into 24-bit key for efficient comparison/hashing // Layout: [enabled:1][op_rgb:3][op_alpha:3][src_rgb:4][src_alpha:4][dst_rgb:4][dst_alpha:4] = 23 bits uint32_t toKey() const; static BlendState fromKey(uint32_t key); bool operator==(const BlendState &other) const; bool operator!=(const BlendState &other) const { return !(*this == other); } // Pre-defined blend states static BlendState Alpha(); // Standard alpha blending static BlendState AlphaPremultiplied(); static BlendState Add(); static BlendState Multiply(); static BlendState Screen(); static BlendState Replace(); static BlendState None(); }; // ============================================================================ // High-level BlendMode enum (backward compatibility) // ============================================================================ enum class BlendMode : uint8_t { None = 0, // No blending (dstRGBA = srcRGBA) Alpha, // Standard alpha blending AlphaPremultiplied, // Premultiplied alpha Add, // Additive blending Multiply, // Multiplicative blending Screen, // Screen blending Custom, // Custom BlendState (not a preset) Count }; // Convert between high-level and low-level BlendState blendModeToState(BlendMode mode); BlendMode stateToBlendMode(const BlendState &state); // ============================================================================ // ColorMask // ============================================================================ struct ColorMask { bool r = true; bool g = true; bool b = true; bool a = true; uint8_t toKey() const { return (r ? 1 : 0) | (g ? 2 : 0) | (b ? 4 : 0) | (a ? 8 : 0); } static ColorMask fromKey(uint8_t key) { return {(key & 1) != 0, (key & 2) != 0, (key & 4) != 0, (key & 8) != 0}; } bool operator==(const ColorMask &other) const { return r == other.r && g == other.g && b == other.b && a == other.a; } bool operator!=(const ColorMask &other) const { return !(*this == other); } static ColorMask All() { return {true, true, true, true}; } static ColorMask None() { return {false, false, false, false}; } }; // ============================================================================ // Depth/Stencil State // ============================================================================ enum class CompareMode : uint8_t { Less = 0, LessEqual, Equal, GreaterEqual, Greater, NotEqual, Always, Never, Count }; struct DepthState { bool write = false; CompareMode compare = CompareMode::Always; // Pack into 4 bits: [write:1][compare:3] uint8_t toKey() const { return (write ? 1 : 0) | (static_cast<uint8_t>(compare) << 1); } static DepthState fromKey(uint8_t key) { DepthState s; s.write = (key & 1) != 0; s.compare = static_cast<CompareMode>((key >> 1) & 0x7); return s; } bool operator==(const DepthState &other) const { return write == other.write && compare == other.compare; } bool operator!=(const DepthState &other) const { return !(*this == other); } static DepthState Disabled() { return {false, CompareMode::Always}; } static DepthState ReadWrite() { return {true, CompareMode::Less}; } static DepthState ReadOnly() { return {false, CompareMode::Less}; } }; enum class StencilAction : uint8_t { Keep = 0, Zero, Replace, Increment, Decrement, IncrementWrap, DecrementWrap, Invert, Count }; struct StencilState { bool enabled = false; CompareMode compare = CompareMode::Always; StencilAction fail = StencilAction::Keep; StencilAction depth_fail = StencilAction::Keep; StencilAction pass = StencilAction::Keep; uint8_t read_mask = 0xFF; uint8_t write_mask = 0xFF; uint8_t ref = 0; // Pack into 4 bits for pipeline key (simplified - just enabled + compare mode) // Full stencil params set via dynamic state uint8_t toKey() const { return (enabled ? 1 : 0) | (static_cast<uint8_t>(compare) << 1); } static StencilState fromKey(uint8_t key) { StencilState s; s.enabled = (key & 1) != 0; s.compare = static_cast<CompareMode>((key >> 1) & 0x7); return s; } bool operator==(const StencilState &other) const { return enabled == other.enabled && compare == other.compare && fail == other.fail && depth_fail == other.depth_fail && pass == other.pass && read_mask == other.read_mask && write_mask == other.write_mask && ref == other.ref; } bool operator!=(const StencilState &other) const { return !(*this == other); } static StencilState Disabled() { return {}; } }; } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/shader.cc
C++
#include "shader.hh" #include "shader_compiler.hh" #include "graphics.hh" #include "batch_renderer.hh" #include "canvas.hh" #include <cstdio> #include <cstring> #include <regex> // Backend selection #if !defined(SOKOL_GLCORE) && !defined(SOKOL_GLES3) && !defined(SOKOL_METAL) #if defined(RENDER_METAL) #define SOKOL_METAL #elif defined(__EMSCRIPTEN__) #define SOKOL_GLES3 #else #define SOKOL_GLCORE #endif #endif namespace joy { namespace modules { // ============================================================================ // Common GLSL Syntax Helpers (shared across backends) // ============================================================================ static const char *glsl_syntax = R"( #define extern uniform #define Image sampler2D #define ArrayImage sampler2DArray #define VolumeImage sampler3D #define CubeImage samplerCube #define number float #define vec2f vec2 #define vec3f vec3 #define vec4f vec4 )"; // ============================================================================ // OpenGL Backend Headers (GLSL 330 / GLES 300) // ============================================================================ #if defined(SOKOL_GLCORE) || defined(SOKOL_GLES3) #if defined(SOKOL_GLCORE) static const char *glsl_uniforms = R"( // Built-in uniforms as vec4 array (matches batch_renderer layout) uniform vec4 builtins[10]; // Matrix reconstruction from vec4 columns #define TransformMatrix mat4(builtins[0], builtins[1], builtins[2], builtins[3]) #define ProjectionMatrix mat4(builtins[4], builtins[5], builtins[6], builtins[7]) #define TransformProjectionMatrix (ProjectionMatrix * TransformMatrix) #define love_ScreenSize builtins[8] #define joy_ScreenSize builtins[8] #define ConstantColor builtins[9] // Texture sampler for the main texture uniform sampler2D MainTex; )"; static const char *vertex_header = R"( layout(location = 0) in vec2 VertexPosition; layout(location = 1) in vec2 VertexTexCoord; layout(location = 2) in vec4 VertexColor; out vec2 VaryingTexCoord; out vec4 VaryingColor; #define love_Position gl_Position )"; static const char *pixel_header = R"( in vec2 VaryingTexCoord; in vec4 VaryingColor; out vec4 love_PixelColor; // Pixel coordinate (adjusted for DPI and Y-flip) #define love_PixelCoord (vec2(gl_FragCoord.x, (gl_FragCoord.y * joy_ScreenSize.z) + joy_ScreenSize.w)) )"; #elif defined(SOKOL_GLES3) static const char *glsl_uniforms = R"( // Built-in uniforms as vec4 array (matches batch_renderer layout) uniform highp vec4 builtins[10]; // Matrix reconstruction from vec4 columns #define TransformMatrix mat4(builtins[0], builtins[1], builtins[2], builtins[3]) #define ProjectionMatrix mat4(builtins[4], builtins[5], builtins[6], builtins[7]) #define TransformProjectionMatrix (ProjectionMatrix * TransformMatrix) #define love_ScreenSize builtins[8] #define joy_ScreenSize builtins[8] #define ConstantColor builtins[9] // Texture sampler for the main texture uniform sampler2D MainTex; )"; static const char *vertex_header = R"( layout(location = 0) in highp vec2 VertexPosition; layout(location = 1) in highp vec2 VertexTexCoord; layout(location = 2) in mediump vec4 VertexColor; out highp vec2 VaryingTexCoord; out mediump vec4 VaryingColor; #define love_Position gl_Position )"; static const char *pixel_header = R"( in highp vec2 VaryingTexCoord; in mediump vec4 VaryingColor; out mediump vec4 love_PixelColor; // Pixel coordinate (adjusted for DPI and Y-flip) #define love_PixelCoord (vec2(gl_FragCoord.x, (gl_FragCoord.y * joy_ScreenSize.z) + joy_ScreenSize.w)) )"; #endif // SOKOL_GLCORE vs SOKOL_GLES3 #endif // SOKOL_GLCORE || SOKOL_GLES3 // ============================================================================ // Metal Backend Headers (GLSL 450 for SPIR-V compilation) // ============================================================================ #if defined(SOKOL_METAL) // GLSL 450 vertex header for SPIR-V compilation static const char *vertex_header_450 = R"( #version 450 // Built-in uniforms in a uniform block (required for SPIR-V) layout(std140, binding = 0) uniform BuiltinUniforms { mat4 _TransformMatrix; mat4 _ProjectionMatrix; vec4 _ScreenSize; vec4 _ConstantColor; }; #define TransformMatrix _TransformMatrix #define ProjectionMatrix _ProjectionMatrix #define TransformProjectionMatrix (ProjectionMatrix * TransformMatrix) #define love_ScreenSize _ScreenSize #define joy_ScreenSize _ScreenSize #define ConstantColor _ConstantColor // Vertex attributes (match BatchVertex layout) layout(location = 0) in vec2 _VertexPosition; layout(location = 1) in vec2 _VertexTexCoord; layout(location = 2) in vec4 VertexColor; // Expand vec2 to vec4 for Love2D API compatibility #define VertexPosition vec4(_VertexPosition, 0.0, 1.0) #define VertexTexCoord vec4(_VertexTexCoord, 0.0, 0.0) // Varyings output to fragment shader layout(location = 0) out vec4 VaryingTexCoord; layout(location = 1) out vec4 VaryingColor; #define love_Position gl_Position // Texture sampling helper #define Image sampler2D vec4 Texel(sampler2D s, vec2 c) { return texture(s, c); } )"; // GLSL 450 fragment header for SPIR-V compilation static const char *pixel_header_450 = R"( #version 450 // Built-in uniforms in a uniform block layout(std140, binding = 0) uniform BuiltinUniforms { mat4 _TransformMatrix; mat4 _ProjectionMatrix; vec4 _ScreenSize; vec4 _ConstantColor; }; #define TransformMatrix _TransformMatrix #define ProjectionMatrix _ProjectionMatrix #define love_ScreenSize _ScreenSize #define joy_ScreenSize _ScreenSize #define ConstantColor _ConstantColor // Main texture sampler layout(binding = 0) uniform sampler2D MainTex; // Varyings input from vertex shader layout(location = 0) in vec4 VaryingTexCoord; layout(location = 1) in vec4 VaryingColor; // Output color layout(location = 0) out vec4 love_PixelColor; // Texture sampling helpers #define Image sampler2D vec4 Texel(sampler2D s, vec2 c) { return texture(s, c); } // Pixel coordinate (screen-space) #define love_PixelCoord gl_FragCoord.xy )"; #endif // SOKOL_METAL // ============================================================================ // Common Shader Code (vertex/pixel functions and main wrappers) // ============================================================================ // Built-in functions for vertex shaders static const char *glsl_vertex_functions = R"( // Texture sampling function (matches Love2D Texel) vec4 Texel(sampler2D tex, vec2 coords) { return texture(tex, coords); } // Gamma correction functions vec4 gammaToLinear(vec4 c) { return vec4(pow(c.rgb, vec3(2.2)), c.a); } vec4 linearToGamma(vec4 c) { return vec4(pow(c.rgb, vec3(1.0/2.2)), c.a); } )"; // Built-in functions for pixel/fragment shaders static const char *glsl_pixel_functions = R"( // Texture sampling function (matches Love2D Texel) vec4 Texel(sampler2D tex, vec2 coords) { return texture(tex, coords); } // LOD bias version - only valid in fragment shaders vec4 Texel(sampler2D tex, vec2 coords, float bias) { return texture(tex, coords, bias); } // Gamma correction functions vec4 gammaToLinear(vec4 c) { return vec4(pow(c.rgb, vec3(2.2)), c.a); } vec4 linearToGamma(vec4 c) { return vec4(pow(c.rgb, vec3(1.0/2.2)), c.a); } )"; // Default vertex shader main (when user provides position() function) static const char *vertex_main_wrapper = R"( void main() { VaryingTexCoord = VertexTexCoord; VaryingColor = VertexColor; love_Position = position(TransformProjectionMatrix, vec4(VertexPosition, 0.0, 1.0)); } )"; // Metal version - VertexPosition is already vec4 static const char *vertex_main_wrapper_metal = R"( void main() { VaryingTexCoord = VertexTexCoord; VaryingColor = VertexColor; love_Position = position(TransformProjectionMatrix, VertexPosition); } )"; // Default vertex shader main (when user provides no vertex shader) static const char *vertex_main_default = R"( vec4 position(mat4 clipSpaceFromLocal, vec4 localPosition) { return clipSpaceFromLocal * localPosition; } void main() { VaryingTexCoord = VertexTexCoord; VaryingColor = VertexColor; love_Position = position(TransformProjectionMatrix, vec4(VertexPosition, 0.0, 1.0)); } )"; // Metal version static const char *vertex_main_default_metal = R"( vec4 position(mat4 clipSpaceFromLocal, vec4 localPosition) { return clipSpaceFromLocal * localPosition; } void main() { VaryingTexCoord = VertexTexCoord; VaryingColor = VertexColor; love_Position = position(TransformProjectionMatrix, VertexPosition); } )"; // Default pixel shader main (when user provides effect() function) static const char *pixel_main_wrapper = R"( void main() { love_PixelColor = effect(VaryingColor, MainTex, VaryingTexCoord, love_PixelCoord); } )"; // Metal version - VaryingTexCoord is vec4 static const char *pixel_main_wrapper_metal = R"( void main() { love_PixelColor = effect(VaryingColor, MainTex, VaryingTexCoord.st, love_PixelCoord); } )"; // Default pixel shader main (when user provides no pixel shader) static const char *pixel_main_default = R"( vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { return Texel(tex, texcoord) * vcolor; } void main() { love_PixelColor = effect(VaryingColor, MainTex, VaryingTexCoord, love_PixelCoord); } )"; // Metal version static const char *pixel_main_default_metal = R"( vec4 effect(vec4 vcolor, Image tex, vec2 texcoord, vec2 pixcoord) { return Texel(tex, texcoord) * vcolor; } void main() { love_PixelColor = effect(VaryingColor, MainTex, VaryingTexCoord.st, love_PixelCoord); } )"; // ============================================================================ // Shader Implementation // ============================================================================ Shader::Shader(Graphics *graphics) : graphics_(graphics) , shader_({SG_INVALID_ID}) , shader_id_(0) , next_texture_unit_(1) // 0 is reserved for MainTex , uniform_buffer_size_(0) { } Shader::~Shader() { destroyPipelines(); if (shader_.id != SG_INVALID_ID) { sg_destroy_shader(shader_); shader_.id = SG_INVALID_ID; } } bool Shader::hasPositionFunction(const char *code) { if (code == nullptr) return false; std::regex pattern(R"(\bvec4\s+position\s*\()"); return std::regex_search(code, pattern); } bool Shader::hasEffectFunction(const char *code) { if (code == nullptr) return false; std::regex pattern(R"(\bvec4\s+effect\s*\()"); return std::regex_search(code, pattern); } std::string Shader::wrapVertexShader(const char *user_code) { std::string result; #if defined(SOKOL_METAL) // Metal: Use GLSL 450 for SPIR-V compilation result += vertex_header_450; result += glsl_syntax; if (user_code != nullptr && strlen(user_code) > 0) { result += "\n// === User Vertex Shader ===\n"; result += "#line 1\n"; result += user_code; result += "\n"; if (hasPositionFunction(user_code)) { result += vertex_main_wrapper_metal; } } else { result += vertex_main_default_metal; } #else // OpenGL: Use GLSL 330 / GLES 300 #if defined(SOKOL_GLCORE) result += "#version 330\n"; #elif defined(SOKOL_GLES3) result += "#version 300 es\n"; result += "precision highp float;\n"; #endif result += glsl_syntax; result += glsl_uniforms; result += vertex_header; result += glsl_vertex_functions; if (user_code != nullptr && strlen(user_code) > 0) { result += "\n// === User Vertex Shader ===\n"; result += "#line 1\n"; result += user_code; result += "\n"; if (hasPositionFunction(user_code)) { result += vertex_main_wrapper; } } else { result += vertex_main_default; } #endif return result; } std::string Shader::wrapPixelShader(const char *user_code) { std::string result; #if defined(SOKOL_METAL) // Metal: Use GLSL 450 for SPIR-V compilation result += pixel_header_450; result += glsl_syntax; if (user_code != nullptr && strlen(user_code) > 0) { result += "\n// === User Pixel Shader ===\n"; result += "#line 1\n"; result += user_code; result += "\n"; if (hasEffectFunction(user_code)) { result += pixel_main_wrapper_metal; } } else { result += pixel_main_default_metal; } #else // OpenGL: Use GLSL 330 / GLES 300 #if defined(SOKOL_GLCORE) result += "#version 330\n"; #elif defined(SOKOL_GLES3) result += "#version 300 es\n"; result += "precision mediump float;\n"; #endif result += glsl_syntax; result += glsl_uniforms; result += pixel_header; result += glsl_pixel_functions; if (user_code != nullptr && strlen(user_code) > 0) { result += "\n// === User Pixel Shader ===\n"; result += "#line 1\n"; result += user_code; result += "\n"; if (hasEffectFunction(user_code)) { result += pixel_main_wrapper; } } else { result += pixel_main_default; } #endif return result; } // Get size in bytes for a uniform type static size_t getUniformTypeSize(UniformType type, int count) { size_t base_size = 0; switch (type) { case UniformType::Float: base_size = 4; break; case UniformType::Vec2: base_size = 8; break; case UniformType::Vec3: base_size = 12; break; case UniformType::Vec4: base_size = 16; break; case UniformType::Int: base_size = 4; break; case UniformType::IVec2: base_size = 8; break; case UniformType::IVec3: base_size = 12; break; case UniformType::IVec4: base_size = 16; break; case UniformType::Bool: base_size = 4; break; case UniformType::Mat2: base_size = 16; break; case UniformType::Mat3: base_size = 36; break; case UniformType::Mat4: base_size = 64; break; default: base_size = 0; break; } return base_size * count; } void Shader::parseUniforms(const char *code) { if (code == nullptr) return; std::regex uniform_pattern( R"(\b(?:uniform|extern)\s+(\w+)\s+(\w+)(?:\s*\[\s*(\d+)\s*\])?\s*;)" ); std::string source(code); std::sregex_iterator it(source.begin(), source.end(), uniform_pattern); std::sregex_iterator end; while (it != end) { std::smatch match = *it; std::string type_str = match[1].str(); std::string name = match[2].str(); std::string array_size_str = match[3].str(); // Skip built-in uniforms if (name == "TransformProjectionMatrix" || name == "TransformMatrix" || name == "ProjectionMatrix" || name == "joy_ScreenSize" || name == "love_ScreenSize" || name == "joy_DPIScale" || name == "ConstantColor" || name == "MainTex" || name == "builtins" || name == "BuiltinUniforms") { ++it; continue; } UniformInfo info; info.name = name; info.location = -1; info.count = array_size_str.empty() ? 1 : std::stoi(array_size_str); info.texture_unit = -1; info.texture_view = {SG_INVALID_ID}; info.texture_sampler = {SG_INVALID_ID}; info.dirty = false; info.size = 0; info.offset = 0; // Map type string to UniformType if (type_str == "float" || type_str == "number") { info.type = UniformType::Float; } else if (type_str == "vec2") { info.type = UniformType::Vec2; } else if (type_str == "vec3") { info.type = UniformType::Vec3; } else if (type_str == "vec4") { info.type = UniformType::Vec4; } else if (type_str == "int") { info.type = UniformType::Int; } else if (type_str == "ivec2") { info.type = UniformType::IVec2; } else if (type_str == "ivec3") { info.type = UniformType::IVec3; } else if (type_str == "ivec4") { info.type = UniformType::IVec4; } else if (type_str == "bool") { info.type = UniformType::Bool; } else if (type_str == "mat2") { info.type = UniformType::Mat2; } else if (type_str == "mat3") { info.type = UniformType::Mat3; } else if (type_str == "mat4") { info.type = UniformType::Mat4; } else if (type_str == "sampler2D" || type_str == "Image") { info.type = UniformType::Sampler2D; info.texture_unit = next_texture_unit_++; } else { info.type = UniformType::Unknown; } info.size = getUniformTypeSize(info.type, info.count); uniforms_[name] = info; ++it; } } #if defined(SOKOL_METAL) // Metal shader creation using SPIR-V cross-compilation bool Shader::createShader(const std::string &vertex_src, const std::string &pixel_src) { // Initialize shader compiler if needed if (!ShaderCompiler::isInitialized()) { if (!ShaderCompiler::init()) { error_ = "Failed to initialize shader compiler"; return false; } } // Compile GLSL to MSL via SPIR-V ShaderCompileResult compile_result = ShaderCompiler::compile(vertex_src, pixel_src); if (!compile_result.success) { error_ = compile_result.errorMessage; return false; } // Copy uniform info from compiler for (const auto &pair : compile_result.uniforms) { const ShaderUniformInfo &src = pair.second; UniformInfo &dst = uniforms_[pair.first]; dst.name = src.name; dst.offset = src.offset; dst.size = src.size; dst.count = src.arraySize; // Map ShaderUniformType to UniformType switch (src.type) { case ShaderUniformType::Float: dst.type = UniformType::Float; break; case ShaderUniformType::Vec2: dst.type = UniformType::Vec2; break; case ShaderUniformType::Vec3: dst.type = UniformType::Vec3; break; case ShaderUniformType::Vec4: dst.type = UniformType::Vec4; break; case ShaderUniformType::Mat2: dst.type = UniformType::Mat2; break; case ShaderUniformType::Mat3: dst.type = UniformType::Mat3; break; case ShaderUniformType::Mat4: dst.type = UniformType::Mat4; break; case ShaderUniformType::Int: dst.type = UniformType::Int; break; case ShaderUniformType::IVec2: dst.type = UniformType::IVec2; break; case ShaderUniformType::IVec3: dst.type = UniformType::IVec3; break; case ShaderUniformType::IVec4: dst.type = UniformType::IVec4; break; case ShaderUniformType::Sampler2D: dst.type = UniformType::Sampler2D; dst.texture_unit = src.binding; break; default: dst.type = UniformType::Unknown; break; } } uniform_buffer_size_ = compile_result.userUniformBlockSize; if (uniform_buffer_size_ > 0) { // Align to 16 bytes for Metal uniform_buffer_size_ = (uniform_buffer_size_ + 15) & ~15; uniform_buffer_.resize(uniform_buffer_size_, 0); } // Create Sokol shader descriptor for Metal sg_shader_desc desc = {}; desc.label = "custom_shader"; desc.vertex_func.source = compile_result.vertexSource.c_str(); desc.vertex_func.entry = "main0"; desc.fragment_func.source = compile_result.fragmentSource.c_str(); desc.fragment_func.entry = "main0"; // Built-in uniform block for vertex stage (slot 0) -> buffer(0) desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[0].size = sizeof(BuiltinUniforms); desc.uniform_blocks[0].msl_buffer_n = 0; // Built-in uniform block for fragment stage (slot 1) -> buffer(0) desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[1].size = sizeof(BuiltinUniforms); desc.uniform_blocks[1].msl_buffer_n = 0; // User uniform block (slot 2) -> buffer(1) for fragment stage if (uniform_buffer_size_ > 0) { desc.uniform_blocks[2].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[2].size = uniform_buffer_size_; desc.uniform_blocks[2].msl_buffer_n = 1; } // Main texture (always slot 0) desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; desc.views[0].texture.image_type = SG_IMAGETYPE_2D; desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; desc.views[0].texture.multisampled = false; desc.views[0].texture.msl_texture_n = 0; desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; desc.samplers[0].msl_sampler_n = 0; desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; desc.texture_sampler_pairs[0].view_slot = 0; desc.texture_sampler_pairs[0].sampler_slot = 0; // Additional texture slots for user textures int tex_slot = 1; for (auto &pair : uniforms_) { UniformInfo &info = pair.second; if (info.type == UniformType::Sampler2D && tex_slot < SG_MAX_TEXTURE_SAMPLER_PAIRS) { desc.views[tex_slot].texture.stage = SG_SHADERSTAGE_FRAGMENT; desc.views[tex_slot].texture.image_type = SG_IMAGETYPE_2D; desc.views[tex_slot].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; desc.views[tex_slot].texture.msl_texture_n = tex_slot; desc.samplers[tex_slot].stage = SG_SHADERSTAGE_FRAGMENT; desc.samplers[tex_slot].sampler_type = SG_SAMPLERTYPE_FILTERING; desc.samplers[tex_slot].msl_sampler_n = tex_slot; desc.texture_sampler_pairs[tex_slot].stage = SG_SHADERSTAGE_FRAGMENT; desc.texture_sampler_pairs[tex_slot].view_slot = tex_slot; desc.texture_sampler_pairs[tex_slot].sampler_slot = tex_slot; info.texture_unit = tex_slot; tex_slot++; } } shader_ = sg_make_shader(&desc); if (shader_.id == SG_INVALID_ID || sg_query_shader_state(shader_) != SG_RESOURCESTATE_VALID) { error_ = "Failed to create Metal shader"; return false; } // Register with pipeline cache BatchRenderer *batch = graphics_->getBatchRenderer(); if (batch) { shader_id_ = batch->getPipelineCache().registerShader(shader_); } // Initialize builtins memset(&builtins_, 0, sizeof(builtins_)); builtins_.transformMatrix[0] = 1.0f; builtins_.transformMatrix[5] = 1.0f; builtins_.transformMatrix[10] = 1.0f; builtins_.transformMatrix[15] = 1.0f; builtins_.projectionMatrix[0] = 1.0f; builtins_.projectionMatrix[5] = 1.0f; builtins_.projectionMatrix[10] = 1.0f; builtins_.projectionMatrix[15] = 1.0f; builtins_.constantColor[0] = 1.0f; builtins_.constantColor[1] = 1.0f; builtins_.constantColor[2] = 1.0f; builtins_.constantColor[3] = 1.0f; return true; } #else // OpenGL shader creation (direct GLSL) bool Shader::createShader(const std::string &vertex_src, const std::string &pixel_src) { sg_shader_desc desc = {}; desc.label = "custom_shader"; desc.vertex_func.source = vertex_src.c_str(); desc.vertex_func.entry = "main"; desc.fragment_func.source = pixel_src.c_str(); desc.fragment_func.entry = "main"; // Built-in uniform block (slot 0): 10 vec4s = 160 bytes desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[0].size = sizeof(BuiltinUniforms); desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "builtins"; desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[0].glsl_uniforms[0].array_count = 10; // User uniform block (slot 1) size_t current_offset = 0; int uniform_idx = 0; uniform_buffer_size_ = 0; for (auto &pair : uniforms_) { UniformInfo &info = pair.second; if (info.type == UniformType::Sampler2D) { continue; } if (info.size == 0 || uniform_idx >= SG_MAX_UNIFORMBLOCK_MEMBERS) { continue; } info.offset = current_offset; current_offset += info.size; desc.uniform_blocks[1].glsl_uniforms[uniform_idx].glsl_name = info.name.c_str(); desc.uniform_blocks[1].glsl_uniforms[uniform_idx].array_count = info.count; switch (info.type) { case UniformType::Float: desc.uniform_blocks[1].glsl_uniforms[uniform_idx].type = SG_UNIFORMTYPE_FLOAT; break; case UniformType::Vec2: desc.uniform_blocks[1].glsl_uniforms[uniform_idx].type = SG_UNIFORMTYPE_FLOAT2; break; case UniformType::Vec3: desc.uniform_blocks[1].glsl_uniforms[uniform_idx].type = SG_UNIFORMTYPE_FLOAT3; break; case UniformType::Vec4: desc.uniform_blocks[1].glsl_uniforms[uniform_idx].type = SG_UNIFORMTYPE_FLOAT4; break; case UniformType::Int: desc.uniform_blocks[1].glsl_uniforms[uniform_idx].type = SG_UNIFORMTYPE_INT; break; case UniformType::IVec2: desc.uniform_blocks[1].glsl_uniforms[uniform_idx].type = SG_UNIFORMTYPE_INT2; break; case UniformType::IVec3: desc.uniform_blocks[1].glsl_uniforms[uniform_idx].type = SG_UNIFORMTYPE_INT3; break; case UniformType::IVec4: desc.uniform_blocks[1].glsl_uniforms[uniform_idx].type = SG_UNIFORMTYPE_INT4; break; case UniformType::Mat4: desc.uniform_blocks[1].glsl_uniforms[uniform_idx].type = SG_UNIFORMTYPE_MAT4; break; default: continue; } uniform_idx++; } if (current_offset > 0) { desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[1].size = current_offset; uniform_buffer_size_ = current_offset; uniform_buffer_.resize(current_offset, 0); } // Texture/sampler setup - slot 0 is MainTex desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; desc.views[0].texture.multisampled = false; desc.views[0].texture.image_type = SG_IMAGETYPE_2D; desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; desc.texture_sampler_pairs[0].view_slot = 0; desc.texture_sampler_pairs[0].sampler_slot = 0; desc.texture_sampler_pairs[0].glsl_name = "MainTex"; // Additional texture slots for user textures int tex_slot = 1; for (auto &pair : uniforms_) { UniformInfo &info = pair.second; if (info.type == UniformType::Sampler2D && tex_slot < SG_MAX_TEXTURE_SAMPLER_PAIRS) { desc.views[tex_slot].texture.stage = SG_SHADERSTAGE_FRAGMENT; desc.views[tex_slot].texture.multisampled = false; desc.views[tex_slot].texture.image_type = SG_IMAGETYPE_2D; desc.views[tex_slot].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; desc.samplers[tex_slot].stage = SG_SHADERSTAGE_FRAGMENT; desc.samplers[tex_slot].sampler_type = SG_SAMPLERTYPE_FILTERING; desc.texture_sampler_pairs[tex_slot].stage = SG_SHADERSTAGE_FRAGMENT; desc.texture_sampler_pairs[tex_slot].view_slot = tex_slot; desc.texture_sampler_pairs[tex_slot].sampler_slot = tex_slot; desc.texture_sampler_pairs[tex_slot].glsl_name = info.name.c_str(); info.texture_unit = tex_slot; tex_slot++; } } shader_ = sg_make_shader(&desc); if (shader_.id == SG_INVALID_ID) { error_ = "Failed to create shader - check console for GLSL errors"; return false; } // Register with pipeline cache BatchRenderer *batch = graphics_->getBatchRenderer(); if (batch) { shader_id_ = batch->getPipelineCache().registerShader(shader_); } // Initialize builtins memset(&builtins_, 0, sizeof(builtins_)); builtins_.transformMatrix[0] = 1.0f; builtins_.transformMatrix[5] = 1.0f; builtins_.transformMatrix[10] = 1.0f; builtins_.transformMatrix[15] = 1.0f; builtins_.projectionMatrix[0] = 1.0f; builtins_.projectionMatrix[5] = 1.0f; builtins_.projectionMatrix[10] = 1.0f; builtins_.projectionMatrix[15] = 1.0f; builtins_.constantColor[0] = 1.0f; builtins_.constantColor[1] = 1.0f; builtins_.constantColor[2] = 1.0f; builtins_.constantColor[3] = 1.0f; return true; } #endif // SOKOL_METAL bool Shader::compile(const char *pixel_code, const char *vertex_code) { error_.clear(); warnings_.clear(); uniforms_.clear(); next_texture_unit_ = 1; // Parse uniforms from user code parseUniforms(pixel_code); parseUniforms(vertex_code); // Wrap shaders with Joy-specific code vertex_source_ = wrapVertexShader(vertex_code); pixel_source_ = wrapPixelShader(pixel_code); // Create the shader if (!createShader(vertex_source_, pixel_source_)) { return false; } return true; } UniformInfo *Shader::findUniform(const char *name) { auto it = uniforms_.find(name); if (it != uniforms_.end()) { return &it->second; } return nullptr; } const UniformInfo *Shader::findUniform(const char *name) const { auto it = uniforms_.find(name); if (it != uniforms_.end()) { return &it->second; } return nullptr; } bool Shader::hasUniform(const char *name) const { return findUniform(name) != nullptr; } bool Shader::sendFloat(const char *name, float value) { UniformInfo *info = findUniform(name); if (!info || info->type != UniformType::Float) { return false; } info->float_values.resize(1); info->float_values[0] = value; info->dirty = true; if (info->offset + sizeof(float) <= uniform_buffer_.size()) { memcpy(&uniform_buffer_[info->offset], &value, sizeof(float)); } return true; } bool Shader::sendFloats(const char *name, const float *values, int count) { UniformInfo *info = findUniform(name); if (!info) return false; info->float_values.assign(values, values + count); info->dirty = true; size_t byte_count = count * sizeof(float); if (info->offset + byte_count <= uniform_buffer_.size()) { memcpy(&uniform_buffer_[info->offset], values, byte_count); } return true; } bool Shader::sendVec2(const char *name, float x, float y) { UniformInfo *info = findUniform(name); if (!info || info->type != UniformType::Vec2) { return false; } info->float_values.resize(2); info->float_values[0] = x; info->float_values[1] = y; info->dirty = true; if (info->offset + 2 * sizeof(float) <= uniform_buffer_.size()) { float data[2] = {x, y}; memcpy(&uniform_buffer_[info->offset], data, sizeof(data)); } return true; } bool Shader::sendVec3(const char *name, float x, float y, float z) { UniformInfo *info = findUniform(name); if (!info || info->type != UniformType::Vec3) { return false; } info->float_values.resize(3); info->float_values[0] = x; info->float_values[1] = y; info->float_values[2] = z; info->dirty = true; if (info->offset + 3 * sizeof(float) <= uniform_buffer_.size()) { float data[3] = {x, y, z}; memcpy(&uniform_buffer_[info->offset], data, sizeof(data)); } return true; } bool Shader::sendVec4(const char *name, float x, float y, float z, float w) { UniformInfo *info = findUniform(name); if (!info || info->type != UniformType::Vec4) { return false; } info->float_values.resize(4); info->float_values[0] = x; info->float_values[1] = y; info->float_values[2] = z; info->float_values[3] = w; info->dirty = true; if (info->offset + 4 * sizeof(float) <= uniform_buffer_.size()) { float data[4] = {x, y, z, w}; memcpy(&uniform_buffer_[info->offset], data, sizeof(data)); } return true; } bool Shader::sendInt(const char *name, int value) { UniformInfo *info = findUniform(name); if (!info || info->type != UniformType::Int) { return false; } info->int_values.resize(1); info->int_values[0] = value; info->dirty = true; if (info->offset + sizeof(int) <= uniform_buffer_.size()) { memcpy(&uniform_buffer_[info->offset], &value, sizeof(int)); } return true; } bool Shader::sendBool(const char *name, bool value) { UniformInfo *info = findUniform(name); if (!info || info->type != UniformType::Bool) { return false; } info->int_values.resize(1); info->int_values[0] = value ? 1 : 0; info->dirty = true; if (info->offset + sizeof(int) <= uniform_buffer_.size()) { int v = value ? 1 : 0; memcpy(&uniform_buffer_[info->offset], &v, sizeof(int)); } return true; } bool Shader::sendMat4(const char *name, const float *matrix) { UniformInfo *info = findUniform(name); if (!info || info->type != UniformType::Mat4) { return false; } info->float_values.assign(matrix, matrix + 16); info->dirty = true; if (info->offset + 16 * sizeof(float) <= uniform_buffer_.size()) { memcpy(&uniform_buffer_[info->offset], matrix, 16 * sizeof(float)); } return true; } bool Shader::sendTexture(const char *name, Texture *texture) { UniformInfo *info = findUniform(name); if (!info || info->type != UniformType::Sampler2D) { return false; } if (texture && texture->isValid()) { info->texture_view = texture->getView(); info->texture_sampler = texture->getSampler(); } else { info->texture_view = {SG_INVALID_ID}; info->texture_sampler = {SG_INVALID_ID}; } info->dirty = true; return true; } bool Shader::sendCanvas(const char *name, Canvas *canvas) { UniformInfo *info = findUniform(name); if (!info || info->type != UniformType::Sampler2D) { return false; } if (canvas) { info->texture_view = canvas->getTextureView(); info->texture_sampler = canvas->getSampler(); } else { info->texture_view = {SG_INVALID_ID}; info->texture_sampler = {SG_INVALID_ID}; } info->dirty = true; return true; } void Shader::applyUniforms() { sg_range builtin_range = {&builtins_, sizeof(builtins_)}; #if defined(SOKOL_METAL) // Metal: built-ins at slot 0 (vertex) and slot 1 (fragment) sg_apply_uniforms(0, &builtin_range); sg_apply_uniforms(1, &builtin_range); // User uniforms at slot 2 for Metal if (uniform_buffer_size_ > 0 && !uniform_buffer_.empty()) { sg_range user_range = {uniform_buffer_.data(), uniform_buffer_size_}; sg_apply_uniforms(2, &user_range); } #else // OpenGL: built-ins at slot 0, user uniforms at slot 1 sg_apply_uniforms(0, &builtin_range); if (uniform_buffer_size_ > 0 && !uniform_buffer_.empty()) { sg_range user_range = {uniform_buffer_.data(), uniform_buffer_size_}; sg_apply_uniforms(1, &user_range); } #endif for (auto &pair : uniforms_) { pair.second.dirty = false; } } void Shader::setBuiltinUniforms(const float *transform, const float *projection, const float *screenSize, const float *constantColor) { memcpy(builtins_.transformMatrix, transform, 16 * sizeof(float)); memcpy(builtins_.projectionMatrix, projection, 16 * sizeof(float)); memcpy(builtins_.screenSize, screenSize, 4 * sizeof(float)); memcpy(builtins_.constantColor, constantColor, 4 * sizeof(float)); } sg_pipeline Shader::getPipeline(PrimitiveType prim, const BlendState &blend) { return getOrCreatePipeline(prim, blend); } sg_pipeline Shader::getOrCreatePipeline(PrimitiveType prim, const BlendState &blend) { uint64_t key = (static_cast<uint64_t>(prim) << 32) | blend.toKey(); auto it = pipelines_.find(key); if (it != pipelines_.end()) { return it->second; } sg_pipeline_desc desc = {}; desc.shader = shader_; desc.label = "custom_shader_pipeline"; // Vertex layout (must match BatchVertex) desc.layout.attrs[0].format = SG_VERTEXFORMAT_FLOAT2; // position desc.layout.attrs[1].format = SG_VERTEXFORMAT_FLOAT2; // texcoord desc.layout.attrs[2].format = SG_VERTEXFORMAT_UBYTE4N; // color (normalized) switch (prim) { case PrimitiveType::Triangles: desc.primitive_type = SG_PRIMITIVETYPE_TRIANGLES; break; case PrimitiveType::Lines: desc.primitive_type = SG_PRIMITIVETYPE_LINES; break; case PrimitiveType::Points: desc.primitive_type = SG_PRIMITIVETYPE_POINTS; break; default: desc.primitive_type = SG_PRIMITIVETYPE_TRIANGLES; break; } desc.index_type = SG_INDEXTYPE_UINT16; if (blend.enabled) { desc.colors[0].blend.enabled = true; auto convertFactor = [](BlendFactor f) -> sg_blend_factor { switch (f) { case BlendFactor::Zero: return SG_BLENDFACTOR_ZERO; case BlendFactor::One: return SG_BLENDFACTOR_ONE; case BlendFactor::SrcColor: return SG_BLENDFACTOR_SRC_COLOR; case BlendFactor::OneMinusSrcColor: return SG_BLENDFACTOR_ONE_MINUS_SRC_COLOR; case BlendFactor::SrcAlpha: return SG_BLENDFACTOR_SRC_ALPHA; case BlendFactor::OneMinusSrcAlpha: return SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; case BlendFactor::DstColor: return SG_BLENDFACTOR_DST_COLOR; case BlendFactor::OneMinusDstColor: return SG_BLENDFACTOR_ONE_MINUS_DST_COLOR; case BlendFactor::DstAlpha: return SG_BLENDFACTOR_DST_ALPHA; case BlendFactor::OneMinusDstAlpha: return SG_BLENDFACTOR_ONE_MINUS_DST_ALPHA; case BlendFactor::SrcAlphaSaturated: return SG_BLENDFACTOR_SRC_ALPHA_SATURATED; default: return SG_BLENDFACTOR_ONE; } }; auto convertOp = [](BlendOp op) -> sg_blend_op { switch (op) { case BlendOp::Add: return SG_BLENDOP_ADD; case BlendOp::Subtract: return SG_BLENDOP_SUBTRACT; case BlendOp::ReverseSubtract: return SG_BLENDOP_REVERSE_SUBTRACT; case BlendOp::Min: return SG_BLENDOP_MIN; case BlendOp::Max: return SG_BLENDOP_MAX; default: return SG_BLENDOP_ADD; } }; desc.colors[0].blend.src_factor_rgb = convertFactor(blend.src_rgb); desc.colors[0].blend.dst_factor_rgb = convertFactor(blend.dst_rgb); desc.colors[0].blend.op_rgb = convertOp(blend.op_rgb); desc.colors[0].blend.src_factor_alpha = convertFactor(blend.src_alpha); desc.colors[0].blend.dst_factor_alpha = convertFactor(blend.dst_alpha); desc.colors[0].blend.op_alpha = convertOp(blend.op_alpha); } sg_pipeline pip = sg_make_pipeline(&desc); pipelines_[key] = pip; return pip; } void Shader::destroyPipelines() { for (auto &pair : pipelines_) { if (pair.second.id != SG_INVALID_ID) { sg_destroy_pipeline(pair.second); } } pipelines_.clear(); } bool Shader::createPipelines() { return true; } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/shader.hh
C++ Header
#pragma once #include "sokol_gfx.h" #include "renderstate.hh" #include "pipeline_cache.hh" #include <string> #include <map> #include <unordered_map> #include <vector> #include <cstdint> namespace joy { namespace modules { class Graphics; class Texture; class Canvas; class BatchRenderer; // Uniform types supported by shader:send() enum class UniformType { Float, Vec2, Vec3, Vec4, Int, IVec2, IVec3, IVec4, Bool, Mat2, Mat3, Mat4, Sampler2D, Unknown }; // Information about a uniform variable struct UniformInfo { std::string name; UniformType type; int location; // GL uniform location (for OpenGL) int count; // Array size (1 for non-arrays) int texture_unit; // For sampler types, which texture unit to use size_t size; // Size in bytes size_t offset; // Offset in uniform buffer // Current values (stored for batched updates) std::vector<float> float_values; std::vector<int> int_values; sg_view texture_view; sg_sampler texture_sampler; bool dirty; // Needs to be sent to GPU }; // Built-in uniforms sent to GPU per-draw // Layout: 10 vec4s = 160 bytes (matches batch_renderer default shader) struct BuiltinUniforms { float transformMatrix[16]; // mat4 (vec4 x 4) - indices 0-3 float projectionMatrix[16]; // mat4 (vec4 x 4) - indices 4-7 float screenSize[4]; // vec4: width, height, y_flip_scale, y_flip_offset - index 8 float constantColor[4]; // vec4: current draw color (RGBA) - index 9 }; // Shader class - custom GLSL shaders for visual effects class Shader { public: Shader(Graphics *graphics); ~Shader(); // Compile shader from source code // If vertex_code is empty/null, uses default vertex shader bool compile(const char *pixel_code, const char *vertex_code = nullptr); // Check if shader is valid bool isValid() const { return shader_.id != SG_INVALID_ID; } // Get error message if compilation failed const std::string &getError() const { return error_; } // Get warnings from compilation const std::string &getWarnings() const { return warnings_; } // Send uniform values bool sendFloat(const char *name, float value); bool sendFloats(const char *name, const float *values, int count); bool sendVec2(const char *name, float x, float y); bool sendVec3(const char *name, float x, float y, float z); bool sendVec4(const char *name, float x, float y, float z, float w); bool sendInt(const char *name, int value); bool sendBool(const char *name, bool value); bool sendMat4(const char *name, const float *matrix); // Column-major 4x4 bool sendTexture(const char *name, Texture *texture); bool sendCanvas(const char *name, Canvas *canvas); // Check if uniform exists bool hasUniform(const char *name) const; // Get shader ID for pipeline cache uint16_t getShaderID() const { return shader_id_; } // Get sokol shader handle sg_shader getHandle() const { return shader_; } // Get pipeline for specific primitive/blend mode combination sg_pipeline getPipeline(PrimitiveType prim, const BlendState &blend); // Set built-in uniform data (called by BatchRenderer before draw) void setBuiltinUniforms(const float *transform, const float *projection, const float *screenSize, const float *constantColor); // Apply pending uniform updates (called before draw) void applyUniforms(); // Get the number of texture units used int getTextureUnitCount() const { return next_texture_unit_; } // Debug: get generated shader source const std::string &getVertexSource() const { return vertex_source_; } const std::string &getPixelSource() const { return pixel_source_; } private: // Wrap user code with Joy-specific prefix/suffix std::string wrapVertexShader(const char *user_code); std::string wrapPixelShader(const char *user_code); // Detect entry point type from user code bool hasPositionFunction(const char *code); bool hasEffectFunction(const char *code); // Parse uniforms from shader source (extract extern/uniform declarations) void parseUniforms(const char *code); // Create sokol shader from wrapped GLSL bool createShader(const std::string &vertex_src, const std::string &pixel_src); // Find uniform by name UniformInfo *findUniform(const char *name); const UniformInfo *findUniform(const char *name) const; // Create pipelines for this shader bool createPipelines(); void destroyPipelines(); // Get or create pipeline for primitive/blend combo sg_pipeline getOrCreatePipeline(PrimitiveType prim, const BlendState &blend); Graphics *graphics_; sg_shader shader_; uint16_t shader_id_; // ID in pipeline cache std::string error_; std::string warnings_; // Uniform storage (std::map for alphabetical order, matching GLSL compiler) std::map<std::string, UniformInfo> uniforms_; int next_texture_unit_; // Next available texture unit (0 is MainTex) // Cached wrapped shader sources (for debugging) std::string vertex_source_; std::string pixel_source_; // Pipeline cache for this shader (indexed by primitive type and blend key) std::unordered_map<uint64_t, sg_pipeline> pipelines_; // Built-in uniform data (updated each frame by BatchRenderer) BuiltinUniforms builtins_; // User uniform buffer (for extern/uniform variables) std::vector<uint8_t> uniform_buffer_; size_t uniform_buffer_size_; }; } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/shader_compiler.cc
C++
#include "shader_compiler.hh" #include <cstdio> // Backend selection #if !defined(SOKOL_GLCORE) && !defined(SOKOL_GLES3) && !defined(SOKOL_METAL) #if defined(RENDER_METAL) #define SOKOL_METAL #elif defined(__EMSCRIPTEN__) #define SOKOL_GLES3 #else #define SOKOL_GLCORE #endif #endif // GLSlang and SPIRV-Cross only used for Metal backend #if defined(SOKOL_METAL) #include <glslang/Public/ShaderLang.h> #include <glslang/Public/ResourceLimits.h> #include <SPIRV/GlslangToSpv.h> #include <spirv_cross.hpp> #include <spirv_msl.hpp> #endif namespace joy { namespace modules { bool ShaderCompiler::initialized_ = false; size_t ShaderCompiler::getUniformTypeSize(ShaderUniformType type) { switch (type) { case ShaderUniformType::Float: return 4; case ShaderUniformType::Vec2: return 8; case ShaderUniformType::Vec3: return 12; case ShaderUniformType::Vec4: return 16; case ShaderUniformType::Mat2: return 16; case ShaderUniformType::Mat3: return 36; case ShaderUniformType::Mat4: return 64; case ShaderUniformType::Int: return 4; case ShaderUniformType::IVec2: return 8; case ShaderUniformType::IVec3: return 12; case ShaderUniformType::IVec4: return 16; case ShaderUniformType::Sampler2D: case ShaderUniformType::SamplerCube: return 0; // Samplers don't occupy uniform buffer space default: return 0; } } #if defined(SOKOL_METAL) // ============================================================================ // Metal backend: Full SPIR-V compilation support // ============================================================================ bool ShaderCompiler::init() { if (initialized_) return true; if (!glslang::InitializeProcess()) { fprintf(stderr, "ShaderCompiler: Failed to initialize glslang\n"); return false; } initialized_ = true; return true; } void ShaderCompiler::shutdown() { if (!initialized_) return; glslang::FinalizeProcess(); initialized_ = false; } bool ShaderCompiler::isInitialized() { return initialized_; } bool ShaderCompiler::compileToSpirv( const std::string& source, bool isVertex, std::vector<uint32_t>& spirvOut, std::string& errorOut ) { EShLanguage stage = isVertex ? EShLangVertex : EShLangFragment; glslang::TShader shader(stage); const char* sourcePtr = source.c_str(); shader.setStrings(&sourcePtr, 1); // Configure for Vulkan SPIR-V output shader.setEnvInput(glslang::EShSourceGlsl, stage, glslang::EShClientVulkan, 450); shader.setEnvClient(glslang::EShClientVulkan, glslang::EShTargetVulkan_1_0); shader.setEnvTarget(glslang::EShTargetSpv, glslang::EShTargetSpv_1_0); // Relax Vulkan rules to allow loose uniforms (Love2D style) // This wraps them in gl_DefaultUniformBlock automatically shader.setEnvInputVulkanRulesRelaxed(); shader.setAutoMapLocations(true); shader.setAutoMapBindings(true); shader.setGlobalUniformBinding(1); // binding 0 is for built-in uniforms shader.setGlobalUniformSet(0); const TBuiltInResource* resources = GetDefaultResources(); if (!shader.parse(resources, 100, false, EShMsgDefault)) { errorOut = "Shader parsing failed:\n"; errorOut += shader.getInfoLog(); errorOut += shader.getInfoDebugLog(); return false; } glslang::TProgram program; program.addShader(&shader); if (!program.link(EShMsgDefault)) { errorOut = "Shader linking failed:\n"; errorOut += program.getInfoLog(); errorOut += program.getInfoDebugLog(); return false; } glslang::SpvOptions spvOptions; spvOptions.generateDebugInfo = false; spvOptions.stripDebugInfo = true; spvOptions.disableOptimizer = false; spvOptions.optimizeSize = true; glslang::GlslangToSpv(*program.getIntermediate(stage), spirvOut, &spvOptions); return true; } bool ShaderCompiler::translateToMSL( const std::vector<uint32_t>& spirv, bool isVertex, std::string& mslOut, std::string& errorOut ) { try { spirv_cross::CompilerMSL msl(spirv); spirv_cross::CompilerMSL::Options mslOpts; mslOpts.set_msl_version(2, 0); mslOpts.platform = spirv_cross::CompilerMSL::Options::macOS; mslOpts.argument_buffers = false; mslOpts.force_active_argument_buffer_resources = false; msl.set_msl_options(mslOpts); // Remap resources for Sokol compatibility spirv_cross::ShaderResources resources = msl.get_shader_resources(); // Remap uniform buffers: binding N -> msl_buffer N for (auto& ub : resources.uniform_buffers) { spirv_cross::MSLResourceBinding binding; binding.stage = isVertex ? spv::ExecutionModelVertex : spv::ExecutionModelFragment; binding.desc_set = msl.get_decoration(ub.id, spv::DecorationDescriptorSet); binding.binding = msl.get_decoration(ub.id, spv::DecorationBinding); binding.msl_buffer = binding.binding; msl.add_msl_resource_binding(binding); } // Remap textures starting at texture(0) uint32_t textureIndex = 0; for (auto& img : resources.sampled_images) { spirv_cross::MSLResourceBinding binding; binding.stage = isVertex ? spv::ExecutionModelVertex : spv::ExecutionModelFragment; binding.desc_set = msl.get_decoration(img.id, spv::DecorationDescriptorSet); binding.binding = msl.get_decoration(img.id, spv::DecorationBinding); binding.msl_texture = textureIndex; binding.msl_sampler = textureIndex; textureIndex++; msl.add_msl_resource_binding(binding); } mslOut = msl.compile(); return true; } catch (const spirv_cross::CompilerError& e) { errorOut = "SPIRV-Cross error: "; errorOut += e.what(); return false; } } static ShaderUniformType spirvTypeToUniformType(const spirv_cross::SPIRType& type) { if (type.basetype == spirv_cross::SPIRType::Float) { if (type.columns == 1) { switch (type.vecsize) { case 1: return ShaderUniformType::Float; case 2: return ShaderUniformType::Vec2; case 3: return ShaderUniformType::Vec3; case 4: return ShaderUniformType::Vec4; } } else { if (type.columns == 2 && type.vecsize == 2) return ShaderUniformType::Mat2; if (type.columns == 3 && type.vecsize == 3) return ShaderUniformType::Mat3; if (type.columns == 4 && type.vecsize == 4) return ShaderUniformType::Mat4; } } else if (type.basetype == spirv_cross::SPIRType::Int) { switch (type.vecsize) { case 1: return ShaderUniformType::Int; case 2: return ShaderUniformType::IVec2; case 3: return ShaderUniformType::IVec3; case 4: return ShaderUniformType::IVec4; } } else if (type.basetype == spirv_cross::SPIRType::SampledImage) { if (type.image.dim == spv::DimCube) { return ShaderUniformType::SamplerCube; } return ShaderUniformType::Sampler2D; } return ShaderUniformType::Unknown; } void ShaderCompiler::extractUniforms( const std::vector<uint32_t>& vertexSpirv, const std::vector<uint32_t>& fragmentSpirv, std::map<std::string, ShaderUniformInfo>& uniforms, size_t& userUniformBlockSize ) { userUniformBlockSize = 0; auto processSpirv = [&uniforms, &userUniformBlockSize](const std::vector<uint32_t>& spirv) { if (spirv.empty()) return; spirv_cross::Compiler compiler(spirv); spirv_cross::ShaderResources resources = compiler.get_shader_resources(); // Extract uniforms from gl_DefaultUniformBlock (user uniforms) for (const auto& ub : resources.uniform_buffers) { if (ub.name != "gl_DefaultUniformBlock") { continue; } const spirv_cross::SPIRType& ubType = compiler.get_type(ub.base_type_id); size_t blockSize = compiler.get_declared_struct_size(ubType); if (blockSize > userUniformBlockSize) { userUniformBlockSize = blockSize; } for (uint32_t i = 0; i < ubType.member_types.size(); ++i) { std::string memberName = compiler.get_member_name(ub.base_type_id, i); const spirv_cross::SPIRType& memberType = compiler.get_type(ubType.member_types[i]); if (uniforms.find(memberName) == uniforms.end()) { ShaderUniformInfo info; info.name = memberName; info.type = spirvTypeToUniformType(memberType); info.binding = -1; info.arraySize = memberType.array.empty() ? 1 : memberType.array[0]; info.offset = compiler.type_struct_member_offset(ubType, i); info.size = getUniformTypeSize(info.type) * info.arraySize; uniforms[memberName] = info; } } } // Extract sampler uniforms for (const auto& img : resources.sampled_images) { std::string name = compiler.get_name(img.id); if (name.empty()) { name = img.name; } // Skip main texture if (name == "MainTex") { continue; } if (uniforms.find(name) == uniforms.end()) { ShaderUniformInfo info; info.name = name; const spirv_cross::SPIRType& type = compiler.get_type(img.type_id); info.type = spirvTypeToUniformType(type); info.binding = compiler.get_decoration(img.id, spv::DecorationBinding); info.arraySize = 1; info.offset = 0; info.size = 0; uniforms[name] = info; } } }; processSpirv(vertexSpirv); processSpirv(fragmentSpirv); } ShaderCompileResult ShaderCompiler::compile( const std::string& vertexGLSL, const std::string& fragmentGLSL ) { ShaderCompileResult result; result.success = false; result.userUniformBlockSize = 0; if (!initialized_) { result.errorMessage = "ShaderCompiler not initialized"; return result; } std::vector<uint32_t> vertexSpirv, fragmentSpirv; // Compile to SPIR-V if (!compileToSpirv(vertexGLSL, true, vertexSpirv, result.errorMessage)) { result.errorMessage = "Vertex shader: " + result.errorMessage; return result; } if (!compileToSpirv(fragmentGLSL, false, fragmentSpirv, result.errorMessage)) { result.errorMessage = "Fragment shader: " + result.errorMessage; return result; } // Translate to MSL if (!translateToMSL(vertexSpirv, true, result.vertexSource, result.errorMessage)) { result.errorMessage = "Vertex MSL translation: " + result.errorMessage; return result; } if (!translateToMSL(fragmentSpirv, false, result.fragmentSource, result.errorMessage)) { result.errorMessage = "Fragment MSL translation: " + result.errorMessage; return result; } // Extract uniforms extractUniforms(vertexSpirv, fragmentSpirv, result.uniforms, result.userUniformBlockSize); result.success = true; return result; } #else // ============================================================================ // Non-Metal backends: Stub implementations // ============================================================================ bool ShaderCompiler::init() { return true; } void ShaderCompiler::shutdown() { } bool ShaderCompiler::isInitialized() { return true; } ShaderCompileResult ShaderCompiler::compile( const std::string& vertexGLSL, const std::string& fragmentGLSL ) { ShaderCompileResult result; result.success = false; result.errorMessage = "SPIR-V compilation not available on this platform"; return result; } #endif // SOKOL_METAL } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/shader_compiler.hh
C++ Header
#pragma once #include <string> #include <vector> #include <map> #include <cstdint> namespace joy { namespace modules { // Uniform types for shader reflection enum class ShaderUniformType : uint8_t { Float, Vec2, Vec3, Vec4, Mat2, Mat3, Mat4, Int, IVec2, IVec3, IVec4, Sampler2D, SamplerCube, Unknown }; // Information about a uniform extracted via SPIR-V reflection struct ShaderUniformInfo { std::string name; ShaderUniformType type; int binding; // For samplers (texture unit) int arraySize; // 1 for non-arrays size_t offset; // Offset in uniform buffer size_t size; // Size in bytes }; // Shader compilation result struct ShaderCompileResult { bool success; std::string vertexSource; // Compiled vertex shader (MSL for Metal) std::string fragmentSource; // Compiled fragment shader (MSL for Metal) std::string errorMessage; std::map<std::string, ShaderUniformInfo> uniforms; size_t userUniformBlockSize; // Size of user uniform block }; // Backend-agnostic shader compiler // Compiles Love2D-style GLSL to platform-native shaders class ShaderCompiler { public: // Initialize the compiler (call once at startup for Metal) static bool init(); // Shutdown the compiler static void shutdown(); // Check if compiler is initialized static bool isInitialized(); // Compile wrapped GLSL 450 shaders to MSL // Input should already have Joy headers prepended static ShaderCompileResult compile( const std::string& vertexGLSL, const std::string& fragmentGLSL ); // Get uniform type size in bytes static size_t getUniformTypeSize(ShaderUniformType type); private: static bool initialized_; #if defined(SOKOL_METAL) || defined(RENDER_METAL) // Compile GLSL to SPIR-V using glslang static bool compileToSpirv( const std::string& source, bool isVertex, std::vector<uint32_t>& spirvOut, std::string& errorOut ); // Translate SPIR-V to MSL using spirv-cross static bool translateToMSL( const std::vector<uint32_t>& spirv, bool isVertex, std::string& mslOut, std::string& errorOut ); // Extract uniform information from SPIR-V static void extractUniforms( const std::vector<uint32_t>& vertexSpirv, const std::vector<uint32_t>& fragmentSpirv, std::map<std::string, ShaderUniformInfo>& uniforms, size_t& userUniformBlockSize ); #endif }; } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/text_renderer.cc
C++
#include "text_renderer.hh" #include "batch_renderer.hh" #include <cstdio> #include <cstring> // Windows headers needed for fontstash.h (MAX_PATH, CP_UTF8) #ifdef _WIN32 #include <windows.h> #endif // FontStash implementation #define FONTSTASH_IMPLEMENTATION #include "fontstash.h" // Backend selection (matches batch_renderer.cc pattern) #if !defined(SOKOL_GLCORE) && !defined(SOKOL_GLES3) && !defined(SOKOL_METAL) #if defined(RENDER_METAL) #define SOKOL_METAL #elif defined(__EMSCRIPTEN__) #define SOKOL_GLES3 #else #define SOKOL_GLCORE #endif #endif namespace joy { namespace modules { // ============================================================================ // Embedded Font Shaders (R8 texture as alpha) // ============================================================================ #if defined(SOKOL_GLCORE) static const char *font_vs_source = R"( #version 330 layout(location = 0) in vec2 position; layout(location = 1) in vec2 texcoord; layout(location = 2) in vec4 color0; // Built-in uniforms as vec4 array (matches batch_renderer layout) uniform vec4 builtins[10]; #define TransformMatrix mat4(builtins[0], builtins[1], builtins[2], builtins[3]) #define ProjectionMatrix mat4(builtins[4], builtins[5], builtins[6], builtins[7]) out vec2 uv; out vec4 color; void main() { vec4 worldPos = TransformMatrix * vec4(position, 0.0, 1.0); gl_Position = ProjectionMatrix * worldPos; uv = texcoord; color = color0; } )"; static const char *font_fs_source = R"( #version 330 uniform sampler2D tex; in vec2 uv; in vec4 color; out vec4 frag_color; void main() { float alpha = texture(tex, uv).r; frag_color = vec4(color.rgb, color.a * alpha); } )"; #elif defined(SOKOL_GLES3) static const char *font_vs_source = R"(#version 300 es layout(location = 0) in highp vec2 position; layout(location = 1) in highp vec2 texcoord; layout(location = 2) in mediump vec4 color0; // Built-in uniforms as vec4 array (matches batch_renderer layout) uniform highp vec4 builtins[10]; #define TransformMatrix mat4(builtins[0], builtins[1], builtins[2], builtins[3]) #define ProjectionMatrix mat4(builtins[4], builtins[5], builtins[6], builtins[7]) out highp vec2 uv; out mediump vec4 color; void main() { highp vec4 worldPos = TransformMatrix * vec4(position, 0.0, 1.0); gl_Position = ProjectionMatrix * worldPos; uv = texcoord; color = color0; } )"; static const char *font_fs_source = R"(#version 300 es precision mediump float; uniform sampler2D tex; in vec2 uv; in vec4 color; out vec4 frag_color; void main() { float alpha = texture(tex, uv).r; frag_color = vec4(color.rgb, color.a * alpha); } )"; #elif defined(SOKOL_METAL) static const char *font_shader_source = R"( #include <metal_stdlib> using namespace metal; struct builtins_t { float4 data[10]; }; struct vs_in { float2 position [[attribute(0)]]; float2 texcoord [[attribute(1)]]; float4 color [[attribute(2)]]; }; struct vs_out { float4 position [[position]]; float2 uv; float4 color; }; vertex vs_out vs_main(vs_in in [[stage_in]], constant builtins_t& builtins [[buffer(0)]]) { float4x4 transformMatrix = float4x4(builtins.data[0], builtins.data[1], builtins.data[2], builtins.data[3]); float4x4 projectionMatrix = float4x4(builtins.data[4], builtins.data[5], builtins.data[6], builtins.data[7]); vs_out out; float4 worldPos = transformMatrix * float4(in.position, 0.0, 1.0); out.position = projectionMatrix * worldPos; out.uv = in.texcoord; out.color = in.color; return out; } fragment float4 fs_main(vs_out in [[stage_in]], texture2d<float> tex [[texture(0)]], sampler smp [[sampler(0)]]) { float alpha = tex.sample(smp, in.uv).r; return float4(in.color.rgb, in.color.a * alpha); } )"; #endif // ============================================================================ // TextRenderer Implementation // ============================================================================ TextRenderer::TextRenderer() : fons_(nullptr) , batch_(nullptr) , atlas_image_({SG_INVALID_ID}) , atlas_view_({SG_INVALID_ID}) , atlas_sampler_({SG_INVALID_ID}) , atlas_width_(0) , atlas_height_(0) , atlas_dirty_(false) , font_shader_({SG_INVALID_ID}) , font_shader_id_(0) , dpi_scale_(1.0f) { } TextRenderer::~TextRenderer() { shutdown(); } bool TextRenderer::init(BatchRenderer* batch, float dpi_scale) { if (fons_ != nullptr) { return true; // Already initialized } batch_ = batch; dpi_scale_ = dpi_scale; // Create font shader first if (!createFontShader()) { fprintf(stderr, "TextRenderer: Failed to create font shader\n"); return false; } // Register font shader with pipeline cache font_shader_id_ = batch_->getPipelineCache().registerShader(font_shader_); // Set up FontStash parameters FONSparams params; memset(&params, 0, sizeof(params)); // Initial atlas size (scaled for DPI) int atlas_size = static_cast<int>(512 * dpi_scale_); params.width = atlas_size; params.height = atlas_size; params.flags = FONS_ZERO_TOPLEFT; params.userPtr = this; // Set up callbacks params.renderCreate = renderCreate; params.renderResize = renderResize; params.renderUpdate = renderUpdate; params.renderDraw = renderDraw; params.renderDelete = renderDelete; // Create FontStash context fons_ = fonsCreateInternal(&params); if (fons_ == nullptr) { fprintf(stderr, "TextRenderer: Failed to create FontStash context\n"); shutdown(); return false; } return true; } void TextRenderer::shutdown() { if (fons_ != nullptr) { fonsDeleteInternal(fons_); fons_ = nullptr; } // Note: GPU resources are cleaned up in renderDelete callback if (font_shader_.id != SG_INVALID_ID) { sg_destroy_shader(font_shader_); font_shader_.id = SG_INVALID_ID; } batch_ = nullptr; } bool TextRenderer::createFontShader() { sg_shader_desc shader_desc = {}; shader_desc.label = "font_shader"; #if defined(SOKOL_GLCORE) || defined(SOKOL_GLES3) shader_desc.vertex_func.source = font_vs_source; shader_desc.vertex_func.entry = "main"; shader_desc.fragment_func.source = font_fs_source; shader_desc.fragment_func.entry = "main"; // Uniform block: 10 vec4s = 160 bytes (matches batch_renderer) shader_desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; shader_desc.uniform_blocks[0].size = 160; // 10 vec4s shader_desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "builtins"; shader_desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; shader_desc.uniform_blocks[0].glsl_uniforms[0].array_count = 10; // Texture view and sampler for OpenGL shader_desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; shader_desc.views[0].texture.multisampled = false; shader_desc.views[0].texture.image_type = SG_IMAGETYPE_2D; shader_desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; shader_desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; shader_desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; shader_desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; shader_desc.texture_sampler_pairs[0].view_slot = 0; shader_desc.texture_sampler_pairs[0].sampler_slot = 0; shader_desc.texture_sampler_pairs[0].glsl_name = "tex"; #elif defined(SOKOL_METAL) shader_desc.vertex_func.source = font_shader_source; shader_desc.vertex_func.entry = "vs_main"; shader_desc.fragment_func.source = font_shader_source; shader_desc.fragment_func.entry = "fs_main"; // Uniform block: 10 vec4s = 160 bytes (matches batch_renderer) shader_desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; shader_desc.uniform_blocks[0].size = 160; // 10 vec4s shader_desc.uniform_blocks[0].msl_buffer_n = 0; // Texture view and sampler for Metal shader_desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; shader_desc.views[0].texture.multisampled = false; shader_desc.views[0].texture.image_type = SG_IMAGETYPE_2D; shader_desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; shader_desc.views[0].texture.msl_texture_n = 0; shader_desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; shader_desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; shader_desc.samplers[0].msl_sampler_n = 0; shader_desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; shader_desc.texture_sampler_pairs[0].view_slot = 0; shader_desc.texture_sampler_pairs[0].sampler_slot = 0; #endif font_shader_ = sg_make_shader(&shader_desc); return font_shader_.id != SG_INVALID_ID; } // ============================================================================ // Font Management (wraps FontStash) // ============================================================================ int TextRenderer::addFont(const char* name, const unsigned char* data, int size, bool free_data) { if (fons_ == nullptr) return FONS_INVALID; return fonsAddFontMem(fons_, name, const_cast<unsigned char*>(data), size, free_data ? 1 : 0); } int TextRenderer::addFallbackFont(int base_font, int fallback_font) { if (fons_ == nullptr) return 0; return fonsAddFallbackFont(fons_, base_font, fallback_font); } void TextRenderer::setFont(int font) { if (fons_ == nullptr) return; fonsSetFont(fons_, font); } void TextRenderer::setSize(float size) { if (fons_ == nullptr) return; fonsSetSize(fons_, size); } void TextRenderer::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { if (fons_ == nullptr) return; fonsSetColor(fons_, textRendererRGBA(r, g, b, a)); } void TextRenderer::setAlign(int align) { if (fons_ == nullptr) return; fonsSetAlign(fons_, align); } // ============================================================================ // Text Measurement // ============================================================================ float TextRenderer::textBounds(float x, float y, const char* text, float* bounds) { if (fons_ == nullptr) return 0; return fonsTextBounds(fons_, x, y, text, nullptr, bounds); } void TextRenderer::vertMetrics(float* ascender, float* descender, float* lineh) { if (fons_ == nullptr) { if (ascender) *ascender = 0; if (descender) *descender = 0; if (lineh) *lineh = 0; return; } fonsVertMetrics(fons_, ascender, descender, lineh); } // ============================================================================ // Drawing // ============================================================================ float TextRenderer::drawText(float x, float y, const char* text) { if (fons_ == nullptr || batch_ == nullptr) return x; // Upload atlas if dirty before drawing flush(); // Draw text (triggers renderDraw callback) return fonsDrawText(fons_, x, y, text, nullptr); } // ============================================================================ // Atlas Management // ============================================================================ void TextRenderer::flush() { if (fons_ == nullptr || !atlas_dirty_) return; atlas_dirty_ = false; // Get texture data from FontStash int width, height; const unsigned char* data = fonsGetTextureData(fons_, &width, &height); if (data == nullptr) return; // Upload to GPU sg_image_data img_data = {}; img_data.mip_levels[0].ptr = data; img_data.mip_levels[0].size = static_cast<size_t>(width * height); sg_update_image(atlas_image_, &img_data); } // ============================================================================ // FontStash Callbacks // ============================================================================ int TextRenderer::renderCreate(void* uptr, int width, int height) { TextRenderer* self = static_cast<TextRenderer*>(uptr); // Store dimensions self->atlas_width_ = width; self->atlas_height_ = height; // Destroy old resources if they exist if (self->atlas_view_.id != SG_INVALID_ID) { sg_destroy_view(self->atlas_view_); self->atlas_view_.id = SG_INVALID_ID; } if (self->atlas_image_.id != SG_INVALID_ID) { sg_destroy_image(self->atlas_image_); self->atlas_image_.id = SG_INVALID_ID; } // Create R8 format texture for font atlas sg_image_desc img_desc = {}; img_desc.width = width; img_desc.height = height; img_desc.pixel_format = SG_PIXELFORMAT_R8; img_desc.usage.dynamic_update = true; img_desc.label = "font_atlas"; self->atlas_image_ = sg_make_image(&img_desc); if (self->atlas_image_.id == SG_INVALID_ID) { fprintf(stderr, "TextRenderer: Failed to create font atlas image\n"); return 0; } // Create texture view sg_view_desc view_desc = {}; view_desc.texture.image = self->atlas_image_; view_desc.label = "font_atlas_view"; self->atlas_view_ = sg_make_view(&view_desc); if (self->atlas_view_.id == SG_INVALID_ID) { fprintf(stderr, "TextRenderer: Failed to create font atlas view\n"); return 0; } // Create sampler (linear filtering for smooth text) if (self->atlas_sampler_.id == SG_INVALID_ID) { sg_sampler_desc smp_desc = {}; smp_desc.min_filter = SG_FILTER_LINEAR; smp_desc.mag_filter = SG_FILTER_LINEAR; smp_desc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; smp_desc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; smp_desc.label = "font_sampler"; self->atlas_sampler_ = sg_make_sampler(&smp_desc); } return 1; } int TextRenderer::renderResize(void* uptr, int width, int height) { // Just recreate the texture with new size return renderCreate(uptr, width, height); } void TextRenderer::renderUpdate(void* uptr, int* rect, const unsigned char* data) { (void)rect; (void)data; TextRenderer* self = static_cast<TextRenderer*>(uptr); self->atlas_dirty_ = true; } void TextRenderer::renderDraw(void* uptr, const float* verts, const float* tcoords, const unsigned int* colors, int nverts) { TextRenderer* self = static_cast<TextRenderer*>(uptr); if (self->batch_ == nullptr || nverts <= 0) return; // Flush atlas if dirty before submitting draw if (self->atlas_dirty_) { self->flush(); } // Submit triangles through BatchRenderer self->batch_->submitFontTriangles( self->atlas_view_, self->atlas_sampler_, verts, tcoords, colors, nverts, self->font_shader_id_ ); } void TextRenderer::renderDelete(void* uptr) { TextRenderer* self = static_cast<TextRenderer*>(uptr); if (self->atlas_view_.id != SG_INVALID_ID) { sg_destroy_view(self->atlas_view_); self->atlas_view_.id = SG_INVALID_ID; } if (self->atlas_image_.id != SG_INVALID_ID) { sg_destroy_image(self->atlas_image_); self->atlas_image_.id = SG_INVALID_ID; } if (self->atlas_sampler_.id != SG_INVALID_ID) { sg_destroy_sampler(self->atlas_sampler_); self->atlas_sampler_.id = SG_INVALID_ID; } } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/graphics/text_renderer.hh
C++ Header
#pragma once #include "sokol_gfx.h" #include "fontstash.h" #include <cstdint> namespace joy { namespace modules { class BatchRenderer; // TextRenderer - manages FontStash rendering through BatchRenderer // Replaces sokol_fontstash by implementing custom FontStash callbacks class TextRenderer { public: TextRenderer(); ~TextRenderer(); // Lifecycle bool init(BatchRenderer* batch, float dpi_scale); void shutdown(); // Font management (wraps FontStash) int addFont(const char* name, const unsigned char* data, int size, bool free_data); int addFallbackFont(int base_font, int fallback_font); void setFont(int font); void setSize(float size); void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a); void setAlign(int align); // Text measurement float textBounds(float x, float y, const char* text, float* bounds); void vertMetrics(float* ascender, float* descender, float* lineh); // Drawing float drawText(float x, float y, const char* text); // Atlas management void flush(); // Upload atlas texture if dirty // Access to FONScontext for Font class compatibility FONScontext* getFonsContext() { return fons_; } // Font shader ID for pipeline cache sg_shader getFontShader() const { return font_shader_; } // Get atlas texture for debugging sg_view getAtlasView() const { return atlas_view_; } int getAtlasWidth() const { return atlas_width_; } int getAtlasHeight() const { return atlas_height_; } private: // FontStash callbacks (static, called via userPtr) static int renderCreate(void* uptr, int width, int height); static int renderResize(void* uptr, int width, int height); static void renderUpdate(void* uptr, int* rect, const unsigned char* data); static void renderDraw(void* uptr, const float* verts, const float* tcoords, const unsigned int* colors, int nverts); static void renderDelete(void* uptr); // Create the font shader (R8 texture as alpha) bool createFontShader(); FONScontext* fons_; BatchRenderer* batch_; // Font atlas GPU resources sg_image atlas_image_; sg_view atlas_view_; sg_sampler atlas_sampler_; int atlas_width_; int atlas_height_; bool atlas_dirty_; // Font shader (treats R8 as alpha) sg_shader font_shader_; uint16_t font_shader_id_; // Shader ID in pipeline cache // DPI scale for atlas sizing float dpi_scale_; }; // Helper to pack RGBA color (matches sfons_rgba) inline uint32_t textRendererRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { return ((uint32_t)r) | ((uint32_t)g << 8) | ((uint32_t)b << 16) | ((uint32_t)a << 24); } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/gui/gui.cc
C++
#include "gui.hh" #include "gui_shaders.h" #include "sokol_gfx.h" #include "stb_image.h" #include "physfs.h" #include <cstring> #include <cstdlib> #include <cstdio> namespace joy { namespace modules { Gui::Gui(Engine *engine) : engine_(engine) , window_(nullptr) , nk_ctx_(nullptr) , atlas_(nullptr) , scale_(1.0f) , base_font_size_(13.0f) , font_img_{} , font_view_{} , font_sampler_{} , shader_{} , pipeline_{} , vertex_buffer_{} , index_buffer_{} , vertex_buffer_size_(0) , index_buffer_size_(0) , skin_img_{} , skin_view_{} , skin_sampler_{} { } Gui::~Gui() { // Clean up GPU resources if (sg_isvalid()) { if (vertex_buffer_.id != 0) sg_destroy_buffer(vertex_buffer_); if (index_buffer_.id != 0) sg_destroy_buffer(index_buffer_); if (pipeline_.id != 0) sg_destroy_pipeline(pipeline_); if (shader_.id != 0) sg_destroy_shader(shader_); if (font_sampler_.id != 0) sg_destroy_sampler(font_sampler_); if (font_view_.id != 0) sg_destroy_view(font_view_); if (font_img_.id != 0) sg_destroy_image(font_img_); if (skin_sampler_.id != 0) sg_destroy_sampler(skin_sampler_); if (skin_view_.id != 0) sg_destroy_view(skin_view_); if (skin_img_.id != 0) sg_destroy_image(skin_img_); } // Clean up Nuklear resources if (atlas_) { nk_font_atlas_clear(atlas_); free(atlas_); } if (nk_ctx_) { nk_free(nk_ctx_); free(nk_ctx_); } } bool Gui::init() { // Allocate Nuklear context nk_ctx_ = (nk_context*)malloc(sizeof(nk_context)); if (!nk_ctx_) { return false; } // Allocate and initialize font atlas atlas_ = (nk_font_atlas*)malloc(sizeof(nk_font_atlas)); if (!atlas_) { free(nk_ctx_); nk_ctx_ = nullptr; return false; } nk_font_atlas_init_default(atlas_); nk_font_atlas_begin(atlas_); // Add default font (ProggyClean) nk_font *font = nk_font_atlas_add_default(atlas_, 13.0f, nullptr); // Bake font atlas (texture will be uploaded in initRendering()) int atlas_width, atlas_height; const void *image = nk_font_atlas_bake(atlas_, &atlas_width, &atlas_height, NK_FONT_ATLAS_RGBA32); // Note: Font texture will be uploaded to GPU in initRendering() // For now, just end the atlas with a temporary null handle // This will be updated in initRendering() after sokol_gfx is ready nk_font_atlas_end(atlas_, nk_handle_ptr(nullptr), nullptr); // Initialize context with the default font if (!nk_init_default(nk_ctx_, &font->handle)) { nk_font_atlas_clear(atlas_); free(atlas_); free(nk_ctx_); atlas_ = nullptr; nk_ctx_ = nullptr; return false; } // Begin input collection for first frame // (endFrame will begin it for subsequent frames) nk_input_begin(nk_ctx_); return true; } bool Gui::initRendering(SDL_Window* window) { if (!nk_ctx_ || !atlas_) { fprintf(stderr, "[GUI] Cannot initialize rendering: context not initialized\n"); return false; } window_ = window; // Rebake font atlas and upload to GPU int atlas_width, atlas_height; const void *image = nk_font_atlas_bake(atlas_, &atlas_width, &atlas_height, NK_FONT_ATLAS_RGBA32); if (!image) { fprintf(stderr, "[GUI] Failed to bake font atlas\n"); return false; } // Create font texture sg_image_desc img_desc = {}; img_desc.width = atlas_width; img_desc.height = atlas_height; img_desc.pixel_format = SG_PIXELFORMAT_RGBA8; img_desc.data.mip_levels[0].ptr = image; img_desc.data.mip_levels[0].size = (size_t)(atlas_width * atlas_height * 4); img_desc.label = "nuklear-font"; font_img_ = sg_make_image(&img_desc); if (font_img_.id == 0) { fprintf(stderr, "[GUI] Failed to create font texture\n"); return false; } // Update atlas with GPU texture handle nk_handle font_handle = nk_handle_id((int)font_img_.id); nk_font_atlas_end(atlas_, font_handle, nullptr); // Create view for font texture sg_view_desc view_desc = {}; view_desc.texture.image = font_img_; font_view_ = sg_make_view(&view_desc); if (font_view_.id == 0) { fprintf(stderr, "[GUI] Failed to create font view\n"); return false; } // Create sampler for font texture sg_sampler_desc smp_desc = {}; smp_desc.min_filter = SG_FILTER_LINEAR; smp_desc.mag_filter = SG_FILTER_LINEAR; smp_desc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; smp_desc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; font_sampler_ = sg_make_sampler(&smp_desc); if (font_sampler_.id == 0) { fprintf(stderr, "[GUI] Failed to create font sampler\n"); return false; } // Create shader sg_shader_desc shd_desc = {}; shd_desc.attrs[0].glsl_name = "position"; shd_desc.attrs[0].hlsl_sem_name = "POSITION"; shd_desc.attrs[1].glsl_name = "texcoord0"; shd_desc.attrs[1].hlsl_sem_name = "TEXCOORD"; shd_desc.attrs[2].glsl_name = "color0"; shd_desc.attrs[2].hlsl_sem_name = "COLOR"; // Select Metal shader variant based on backend #if defined(SOKOL_METAL) sg_backend backend = sg_query_backend(); if (backend == SG_BACKEND_METAL_MACOS) { // macOS uses pre-compiled bytecode shd_desc.vertex_func.bytecode.ptr = nk_vs_bytecode_metal_macos; shd_desc.vertex_func.bytecode.size = sizeof(nk_vs_bytecode_metal_macos); shd_desc.fragment_func.bytecode.ptr = nk_fs_bytecode_metal_macos; shd_desc.fragment_func.bytecode.size = sizeof(nk_fs_bytecode_metal_macos); } else if (backend == SG_BACKEND_METAL_IOS) { // iOS uses pre-compiled bytecode shd_desc.vertex_func.bytecode.ptr = nk_vs_bytecode_metal_ios; shd_desc.vertex_func.bytecode.size = sizeof(nk_vs_bytecode_metal_ios); shd_desc.fragment_func.bytecode.ptr = nk_fs_bytecode_metal_ios; shd_desc.fragment_func.bytecode.size = sizeof(nk_fs_bytecode_metal_ios); } else { // iOS Simulator uses source code shd_desc.vertex_func.source = (const char*)nk_vs_source_metal_sim; shd_desc.fragment_func.source = (const char*)nk_fs_source_metal_sim; } #else shd_desc.vertex_func.source = (const char*)nk_vs_bytecode; shd_desc.fragment_func.source = (const char*)nk_fs_bytecode; #endif shd_desc.vertex_func.entry = NK_VS_ENTRY; shd_desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; shd_desc.uniform_blocks[0].size = 16; shd_desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "vs_params"; shd_desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; shd_desc.uniform_blocks[0].glsl_uniforms[0].array_count = 1; shd_desc.fragment_func.entry = NK_FS_ENTRY; shd_desc.views[0].texture.stage = SG_SHADERSTAGE_FRAGMENT; shd_desc.views[0].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; shd_desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; shd_desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; shd_desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; shd_desc.texture_sampler_pairs[0].view_slot = 0; shd_desc.texture_sampler_pairs[0].sampler_slot = 0; shd_desc.texture_sampler_pairs[0].glsl_name = "tex_smp"; shd_desc.label = "nuklear-shader"; shader_ = sg_make_shader(&shd_desc); if (shader_.id == 0) { fprintf(stderr, "[GUI] Failed to create shader\n"); return false; } // Create pipeline sg_pipeline_desc pip_desc = {}; pip_desc.layout.attrs[0].offset = 0; pip_desc.layout.attrs[0].format = SG_VERTEXFORMAT_FLOAT2; pip_desc.layout.attrs[1].offset = 8; pip_desc.layout.attrs[1].format = SG_VERTEXFORMAT_FLOAT2; pip_desc.layout.attrs[2].offset = 16; pip_desc.layout.attrs[2].format = SG_VERTEXFORMAT_UBYTE4N; pip_desc.shader = shader_; pip_desc.index_type = SG_INDEXTYPE_UINT16; pip_desc.colors[0].pixel_format = NK_SHADER_COLOR_FORMAT; pip_desc.colors[0].write_mask = SG_COLORMASK_RGB; pip_desc.colors[0].blend.enabled = true; pip_desc.colors[0].blend.src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA; pip_desc.colors[0].blend.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; pip_desc.label = "nuklear-pipeline"; pipeline_ = sg_make_pipeline(&pip_desc); if (pipeline_.id == 0) { fprintf(stderr, "[GUI] Failed to create pipeline\n"); return false; } // Create vertex buffer (65536 vertices * 20 bytes) const int MAX_VERTICES = 65536; vertex_buffer_size_ = MAX_VERTICES * sizeof(NkVertex); sg_buffer_desc vbuf_desc = {}; vbuf_desc.size = vertex_buffer_size_; vbuf_desc.usage.vertex_buffer = true; vbuf_desc.usage.stream_update = true; vbuf_desc.label = "nuklear-vertices"; vertex_buffer_ = sg_make_buffer(&vbuf_desc); if (vertex_buffer_.id == 0) { fprintf(stderr, "[GUI] Failed to create vertex buffer\n"); return false; } // Create index buffer (65536 * 3 * 2 bytes) index_buffer_size_ = MAX_VERTICES * 3 * sizeof(uint16_t); sg_buffer_desc ibuf_desc = {}; ibuf_desc.size = index_buffer_size_; ibuf_desc.usage.index_buffer = true; ibuf_desc.usage.stream_update = true; ibuf_desc.label = "nuklear-indices"; index_buffer_ = sg_make_buffer(&ibuf_desc); if (index_buffer_.id == 0) { fprintf(stderr, "[GUI] Failed to create index buffer\n"); return false; } return true; } void Gui::handleEvent(const SDL_Event *event) { if (!nk_ctx_ || !window_) return; // SDL3 already provides coordinates in logical (window) space // We work in logical coordinates for consistency with the rest of the engine switch (event->type) { case SDL_EVENT_MOUSE_MOTION: nk_input_motion(nk_ctx_, (int)event->motion.x, (int)event->motion.y); break; case SDL_EVENT_MOUSE_BUTTON_DOWN: case SDL_EVENT_MOUSE_BUTTON_UP: { int down = (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN); int x = (int)event->button.x; int y = (int)event->button.y; if (event->button.button == SDL_BUTTON_LEFT) { nk_input_button(nk_ctx_, NK_BUTTON_LEFT, x, y, down); } else if (event->button.button == SDL_BUTTON_MIDDLE) { nk_input_button(nk_ctx_, NK_BUTTON_MIDDLE, x, y, down); } else if (event->button.button == SDL_BUTTON_RIGHT) { nk_input_button(nk_ctx_, NK_BUTTON_RIGHT, x, y, down); } break; } case SDL_EVENT_MOUSE_WHEEL: nk_input_scroll(nk_ctx_, nk_vec2(event->wheel.x, event->wheel.y)); break; case SDL_EVENT_KEY_DOWN: case SDL_EVENT_KEY_UP: { int down = (event->type == SDL_EVENT_KEY_DOWN); SDL_Keycode key = event->key.key; if (key == SDLK_RSHIFT || key == SDLK_LSHIFT) nk_input_key(nk_ctx_, NK_KEY_SHIFT, down); else if (key == SDLK_DELETE) nk_input_key(nk_ctx_, NK_KEY_DEL, down); else if (key == SDLK_RETURN) nk_input_key(nk_ctx_, NK_KEY_ENTER, down); else if (key == SDLK_TAB) nk_input_key(nk_ctx_, NK_KEY_TAB, down); else if (key == SDLK_BACKSPACE) nk_input_key(nk_ctx_, NK_KEY_BACKSPACE, down); else if (key == SDLK_HOME) nk_input_key(nk_ctx_, NK_KEY_TEXT_START, down); else if (key == SDLK_END) nk_input_key(nk_ctx_, NK_KEY_TEXT_END, down); else if (key == SDLK_LEFT) nk_input_key(nk_ctx_, NK_KEY_LEFT, down); else if (key == SDLK_RIGHT) nk_input_key(nk_ctx_, NK_KEY_RIGHT, down); else if (key == SDLK_UP) nk_input_key(nk_ctx_, NK_KEY_UP, down); else if (key == SDLK_DOWN) nk_input_key(nk_ctx_, NK_KEY_DOWN, down); break; } case SDL_EVENT_TEXT_INPUT: nk_input_glyph(nk_ctx_, event->text.text); break; } } static unsigned char *physfs_readfile(const char *path, size_t *size) { // Read file via PhysFS PHYSFS_File *file = PHYSFS_openRead(path); if (!file) { return nullptr; } PHYSFS_sint64 file_size = PHYSFS_fileLength(file); if (file_size < 0) { PHYSFS_close(file); return nullptr; } unsigned char *file_data = (unsigned char*)malloc(file_size); if (!file_data) { PHYSFS_close(file); return nullptr; } PHYSFS_sint64 bytes_read = PHYSFS_readBytes(file, file_data, file_size); PHYSFS_close(file); if (bytes_read != file_size) { free(file_data); return nullptr; } *size = bytes_read; return file_data; } bool Gui::setFont(const char *path, float size) { if (!nk_ctx_ || !atlas_) { fprintf(stderr, "[GUI] Cannot set font: GUI not initialized\n"); return false; } size_t font_size; unsigned char *font_data = physfs_readfile(path, &font_size); if (!font_data) { fprintf(stderr, "[GUI] Failed to open font file: %s\n", path); return false; } // Clear existing atlas nk_font_atlas_clear(atlas_); // Reinitialize atlas nk_font_atlas_init_default(atlas_); nk_font_atlas_begin(atlas_); // Configure font to be owned by atlas (so it will be freed on atlas_clear) struct nk_font_config cfg = nk_font_config(size); cfg.ttf_blob = font_data; cfg.ttf_size = font_size; cfg.ttf_data_owned_by_atlas = 1; // Add new font nk_font *font = nk_font_atlas_add(atlas_, &cfg); if (!font) { fprintf(stderr, "[GUI] Failed to add font to atlas\n"); free(font_data); return false; } // Bake atlas int atlas_width, atlas_height; const void *image = nk_font_atlas_bake(atlas_, &atlas_width, &atlas_height, NK_FONT_ATLAS_RGBA32); if (!image) { fprintf(stderr, "[GUI] Failed to bake font atlas\n"); // font_data is now owned by atlas, will be freed on atlas_clear return false; } // Destroy old GPU texture if it exists if (font_img_.id != 0) { sg_destroy_image(font_img_); } if (font_view_.id != 0) { sg_destroy_view(font_view_); } // Create new font texture sg_image_desc img_desc = {}; img_desc.width = atlas_width; img_desc.height = atlas_height; img_desc.pixel_format = SG_PIXELFORMAT_RGBA8; img_desc.data.mip_levels[0].ptr = image; img_desc.data.mip_levels[0].size = (size_t)(atlas_width * atlas_height * 4); img_desc.label = "nuklear-font"; font_img_ = sg_make_image(&img_desc); if (font_img_.id == 0) { fprintf(stderr, "[GUI] Failed to create font texture\n"); // font_data is now owned by atlas, will be freed on atlas_clear return false; } // Update atlas with GPU texture handle nk_handle font_handle = nk_handle_id((int)font_img_.id); nk_font_atlas_end(atlas_, font_handle, nullptr); // Create new view for font texture sg_view_desc view_desc = {}; view_desc.texture.image = font_img_; font_view_ = sg_make_view(&view_desc); if (font_view_.id == 0) { fprintf(stderr, "[GUI] Failed to create font view\n"); // font_data is now owned by atlas, will be freed on atlas_clear return false; } // Update Nuklear context to use new font nk_style_set_font(nk_ctx_, &font->handle); // font_data is now owned by the atlas and will be freed when atlas is cleared return true; } void Gui::setScale(float scale) { if (!nk_ctx_ || !atlas_ || !window_ || scale <= 0.0f) { return; } scale_ = scale; // Recreate font atlas with scaled font nk_font_atlas_clear(atlas_); nk_font_atlas_init_default(atlas_); nk_font_atlas_begin(atlas_); // Add font at scaled size float scaled_size = base_font_size_ * scale_; nk_font *font = nk_font_atlas_add_default(atlas_, scaled_size, nullptr); // Bake and upload atlas int atlas_width, atlas_height; const void *image = nk_font_atlas_bake(atlas_, &atlas_width, &atlas_height, NK_FONT_ATLAS_RGBA32); if (!image) { return; } // Destroy old texture if (font_view_.id != 0) sg_destroy_view(font_view_); if (font_img_.id != 0) sg_destroy_image(font_img_); // Create new texture sg_image_desc img_desc = {}; img_desc.width = atlas_width; img_desc.height = atlas_height; img_desc.pixel_format = SG_PIXELFORMAT_RGBA8; img_desc.data.mip_levels[0].ptr = image; img_desc.data.mip_levels[0].size = (size_t)(atlas_width * atlas_height * 4); img_desc.label = "nuklear-font-scaled"; font_img_ = sg_make_image(&img_desc); nk_handle font_handle = nk_handle_id((int)font_img_.id); nk_font_atlas_end(atlas_, font_handle, nullptr); // Create view sg_view_desc view_desc = {}; view_desc.texture.image = font_img_; font_view_ = sg_make_view(&view_desc); // Set font nk_style_set_font(nk_ctx_, &font->handle); // Scale style properties nk_style *style = &nk_ctx_->style; // Window style->window.spacing = nk_vec2(4 * scale_, 4 * scale_); style->window.padding = nk_vec2(8 * scale_, 4 * scale_); style->window.scrollbar_size = nk_vec2(16 * scale_, 16 * scale_); style->window.min_size = nk_vec2(64 * scale_, 64 * scale_); style->window.header.padding = nk_vec2(4 * scale_, 4 * scale_); style->window.header.spacing = nk_vec2(4 * scale_, 4 * scale_); style->window.header.label_padding = nk_vec2(4 * scale_, 4 * scale_); // Button style->button.padding = nk_vec2(4 * scale_, 4 * scale_); style->button.rounding = 4 * scale_; // Checkbox/option style->checkbox.padding = nk_vec2(3 * scale_, 3 * scale_); style->option.padding = nk_vec2(3 * scale_, 3 * scale_); // Slider style->slider.cursor_size = nk_vec2(16 * scale_, 16 * scale_); style->slider.padding = nk_vec2(2 * scale_, 2 * scale_); // Progress style->progress.padding = nk_vec2(4 * scale_, 4 * scale_); // Property style->property.padding = nk_vec2(4 * scale_, 4 * scale_); // Edit style->edit.padding = nk_vec2(4 * scale_, 4 * scale_); style->edit.row_padding = 2 * scale_; // Scrollbar style->scrollv.padding = nk_vec2(0, 0); style->scrollh.padding = nk_vec2(0, 0); } bool Gui::applySkin(const char *path) { if (!nk_ctx_) { fprintf(stderr, "[GUI] Cannot apply skin: GUI not initialized\n"); return false; } size_t file_size; unsigned char *file_data = physfs_readfile(path, &file_size); if (!file_data) { fprintf(stderr, "[GUI] Failed to open skin file: %s\n", path); return false; } // Load image from memory with stb_image int width, height, channels; unsigned char *data = stbi_load_from_memory(file_data, (int)file_size, &width, &height, &channels, 4); // Force RGBA free(file_data); if (!data) { fprintf(stderr, "[GUI] Failed to decode skin image: %s\n", path); return false; } // Destroy old skin resources if they exist if (skin_sampler_.id != 0) { sg_destroy_sampler(skin_sampler_); } if (skin_view_.id != 0) { sg_destroy_view(skin_view_); } if (skin_img_.id != 0) { sg_destroy_image(skin_img_); } // Create GPU texture sg_image_desc img_desc = {}; img_desc.width = width; img_desc.height = height; img_desc.pixel_format = SG_PIXELFORMAT_RGBA8; img_desc.data.mip_levels[0].ptr = data; img_desc.data.mip_levels[0].size = (size_t)(width * height * 4); img_desc.label = "nuklear-skin"; skin_img_ = sg_make_image(&img_desc); stbi_image_free(data); if (skin_img_.id == 0) { fprintf(stderr, "[GUI] Failed to create skin texture\n"); return false; } // Create view for skin texture sg_view_desc view_desc = {}; view_desc.texture.image = skin_img_; skin_view_ = sg_make_view(&view_desc); if (skin_view_.id == 0) { fprintf(stderr, "[GUI] Failed to create skin view\n"); return false; } // Create sampler for skin texture sg_sampler_desc sampler_desc = {}; sampler_desc.min_filter = SG_FILTER_LINEAR; sampler_desc.mag_filter = SG_FILTER_LINEAR; sampler_desc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; sampler_desc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; skin_sampler_ = sg_make_sampler(&sampler_desc); if (skin_sampler_.id == 0) { fprintf(stderr, "[GUI] Failed to create skin sampler\n"); return false; } // Create subimages for all UI elements (hardcoded for gwen.png layout) int skin_id = (int)skin_img_.id; struct nk_image check = nk_subimage_id(skin_id, 512, 512, nk_rect(464, 32, 15, 15)); struct nk_image check_cursor = nk_subimage_id(skin_id, 512, 512, nk_rect(450, 34, 11, 11)); struct nk_image option = nk_subimage_id(skin_id, 512, 512, nk_rect(464, 64, 15, 15)); struct nk_image option_cursor = nk_subimage_id(skin_id, 512, 512, nk_rect(451, 67, 9, 9)); struct nk_image header = nk_subimage_id(skin_id, 512, 512, nk_rect(128, 0, 127, 24)); struct nk_image window = nk_subimage_id(skin_id, 512, 512, nk_rect(128, 23, 127, 104)); struct nk_image scrollbar_inc_button = nk_subimage_id(skin_id, 512, 512, nk_rect(464, 256, 15, 15)); struct nk_image scrollbar_inc_button_hover = nk_subimage_id(skin_id, 512, 512, nk_rect(464, 320, 15, 15)); struct nk_image scrollbar_dec_button = nk_subimage_id(skin_id, 512, 512, nk_rect(464, 224, 15, 15)); struct nk_image scrollbar_dec_button_hover = nk_subimage_id(skin_id, 512, 512, nk_rect(464, 288, 15, 15)); struct nk_image button = nk_subimage_id(skin_id, 512, 512, nk_rect(384, 336, 127, 31)); struct nk_image button_hover = nk_subimage_id(skin_id, 512, 512, nk_rect(384, 368, 127, 31)); struct nk_image button_active = nk_subimage_id(skin_id, 512, 512, nk_rect(384, 400, 127, 31)); struct nk_image tab_minimize = nk_subimage_id(skin_id, 512, 512, nk_rect(451, 99, 9, 9)); struct nk_image tab_maximize = nk_subimage_id(skin_id, 512, 512, nk_rect(467, 99, 9, 9)); struct nk_image slider = nk_subimage_id(skin_id, 512, 512, nk_rect(418, 33, 11, 14)); struct nk_image slider_hover = nk_subimage_id(skin_id, 512, 512, nk_rect(418, 49, 11, 14)); struct nk_image slider_active = nk_subimage_id(skin_id, 512, 512, nk_rect(418, 64, 11, 14)); // Apply skin to style properties // Window nk_ctx_->style.window.background = nk_rgb(204, 204, 204); nk_ctx_->style.window.fixed_background = nk_style_item_image(window); nk_ctx_->style.window.border_color = nk_rgb(67, 67, 67); nk_ctx_->style.window.combo_border_color = nk_rgb(67, 67, 67); nk_ctx_->style.window.contextual_border_color = nk_rgb(67, 67, 67); nk_ctx_->style.window.menu_border_color = nk_rgb(67, 67, 67); nk_ctx_->style.window.group_border_color = nk_rgb(67, 67, 67); nk_ctx_->style.window.tooltip_border_color = nk_rgb(67, 67, 67); nk_ctx_->style.window.scrollbar_size = nk_vec2(16, 16); nk_ctx_->style.window.border_color = nk_rgba(0, 0, 0, 0); nk_ctx_->style.window.padding = nk_vec2(8, 4); nk_ctx_->style.window.border = 3; // Window header nk_ctx_->style.window.header.normal = nk_style_item_image(header); nk_ctx_->style.window.header.hover = nk_style_item_image(header); nk_ctx_->style.window.header.active = nk_style_item_image(header); nk_ctx_->style.window.header.label_normal = nk_rgb(95, 95, 95); nk_ctx_->style.window.header.label_hover = nk_rgb(95, 95, 95); nk_ctx_->style.window.header.label_active = nk_rgb(95, 95, 95); // Scrollbar nk_ctx_->style.scrollv.normal = nk_style_item_color(nk_rgb(184, 184, 184)); nk_ctx_->style.scrollv.hover = nk_style_item_color(nk_rgb(184, 184, 184)); nk_ctx_->style.scrollv.active = nk_style_item_color(nk_rgb(184, 184, 184)); nk_ctx_->style.scrollv.cursor_normal = nk_style_item_color(nk_rgb(220, 220, 220)); nk_ctx_->style.scrollv.cursor_hover = nk_style_item_color(nk_rgb(235, 235, 235)); nk_ctx_->style.scrollv.cursor_active = nk_style_item_color(nk_rgb(99, 202, 255)); nk_ctx_->style.scrollv.dec_symbol = NK_SYMBOL_NONE; nk_ctx_->style.scrollv.inc_symbol = NK_SYMBOL_NONE; nk_ctx_->style.scrollv.show_buttons = nk_true; nk_ctx_->style.scrollv.border_color = nk_rgb(81, 81, 81); nk_ctx_->style.scrollv.cursor_border_color = nk_rgb(81, 81, 81); nk_ctx_->style.scrollv.border = 1; nk_ctx_->style.scrollv.rounding = 0; nk_ctx_->style.scrollv.border_cursor = 1; nk_ctx_->style.scrollv.rounding_cursor = 2; // Scrollbar buttons nk_ctx_->style.scrollv.inc_button.normal = nk_style_item_image(scrollbar_inc_button); nk_ctx_->style.scrollv.inc_button.hover = nk_style_item_image(scrollbar_inc_button_hover); nk_ctx_->style.scrollv.inc_button.active = nk_style_item_image(scrollbar_inc_button_hover); nk_ctx_->style.scrollv.inc_button.border_color = nk_rgba(0, 0, 0, 0); nk_ctx_->style.scrollv.inc_button.text_background = nk_rgba(0, 0, 0, 0); nk_ctx_->style.scrollv.inc_button.text_normal = nk_rgba(0, 0, 0, 0); nk_ctx_->style.scrollv.inc_button.text_hover = nk_rgba(0, 0, 0, 0); nk_ctx_->style.scrollv.inc_button.text_active = nk_rgba(0, 0, 0, 0); nk_ctx_->style.scrollv.inc_button.border = 0.0f; nk_ctx_->style.scrollv.dec_button.normal = nk_style_item_image(scrollbar_dec_button); nk_ctx_->style.scrollv.dec_button.hover = nk_style_item_image(scrollbar_dec_button_hover); nk_ctx_->style.scrollv.dec_button.active = nk_style_item_image(scrollbar_dec_button_hover); nk_ctx_->style.scrollv.dec_button.border_color = nk_rgba(0, 0, 0, 0); nk_ctx_->style.scrollv.dec_button.text_background = nk_rgba(0, 0, 0, 0); nk_ctx_->style.scrollv.dec_button.text_normal = nk_rgba(0, 0, 0, 0); nk_ctx_->style.scrollv.dec_button.text_hover = nk_rgba(0, 0, 0, 0); nk_ctx_->style.scrollv.dec_button.text_active = nk_rgba(0, 0, 0, 0); nk_ctx_->style.scrollv.dec_button.border = 0.0f; // Checkbox nk_ctx_->style.checkbox.normal = nk_style_item_image(check); nk_ctx_->style.checkbox.hover = nk_style_item_image(check); nk_ctx_->style.checkbox.active = nk_style_item_image(check); nk_ctx_->style.checkbox.cursor_normal = nk_style_item_image(check_cursor); nk_ctx_->style.checkbox.cursor_hover = nk_style_item_image(check_cursor); nk_ctx_->style.checkbox.text_normal = nk_rgb(95, 95, 95); nk_ctx_->style.checkbox.text_hover = nk_rgb(95, 95, 95); nk_ctx_->style.checkbox.text_active = nk_rgb(95, 95, 95); // Option (radio button) nk_ctx_->style.option.normal = nk_style_item_image(option); nk_ctx_->style.option.hover = nk_style_item_image(option); nk_ctx_->style.option.active = nk_style_item_image(option); nk_ctx_->style.option.cursor_normal = nk_style_item_image(option_cursor); nk_ctx_->style.option.cursor_hover = nk_style_item_image(option_cursor); nk_ctx_->style.option.text_normal = nk_rgb(95, 95, 95); nk_ctx_->style.option.text_hover = nk_rgb(95, 95, 95); nk_ctx_->style.option.text_active = nk_rgb(95, 95, 95); // Button nk_ctx_->style.button.normal = nk_style_item_image(button); nk_ctx_->style.button.hover = nk_style_item_image(button_hover); nk_ctx_->style.button.active = nk_style_item_image(button_active); nk_ctx_->style.button.border_color = nk_rgba(0, 0, 0, 0); nk_ctx_->style.button.text_background = nk_rgba(0, 0, 0, 0); nk_ctx_->style.button.text_normal = nk_rgb(95, 95, 95); nk_ctx_->style.button.text_hover = nk_rgb(95, 95, 95); nk_ctx_->style.button.text_active = nk_rgb(95, 95, 95); // Slider nk_ctx_->style.slider.cursor_normal = nk_style_item_image(slider); nk_ctx_->style.slider.cursor_hover = nk_style_item_image(slider_hover); nk_ctx_->style.slider.cursor_active = nk_style_item_image(slider_active); // Window close/minimize buttons nk_ctx_->style.window.header.close_button.normal = nk_style_item_image(tab_minimize); nk_ctx_->style.window.header.close_button.hover = nk_style_item_image(tab_minimize); nk_ctx_->style.window.header.close_button.active = nk_style_item_image(tab_minimize); nk_ctx_->style.window.header.minimize_button.normal = nk_style_item_image(tab_maximize); nk_ctx_->style.window.header.minimize_button.hover = nk_style_item_image(tab_maximize); nk_ctx_->style.window.header.minimize_button.active = nk_style_item_image(tab_maximize); return true; } void Gui::beginFrame() { if (!nk_ctx_) return; // End input collection from previous frame (events are processed before beginFrame) // and immediately begin collection for next frame nk_input_end(nk_ctx_); } void Gui::endFrame() { if (!nk_ctx_) return; // Input collection continues after endFrame for next frame's events // We start it here for the next frame nk_input_begin(nk_ctx_); } void Gui::render(int width, int height) { if (!nk_ctx_ || pipeline_.id == 0 || !window_) { return; } // Get DPI scale for scissor rect conversion (logical -> pixel coordinates) float dpi_scale = SDL_GetWindowDisplayScale(window_); // Configure vertex layout for nk_convert static const nk_draw_vertex_layout_element vertex_layout[] = { {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, 0}, {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, 8}, {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, 16}, {NK_VERTEX_LAYOUT_END} }; nk_convert_config config = {}; config.shape_AA = NK_ANTI_ALIASING_ON; config.line_AA = NK_ANTI_ALIASING_ON; config.vertex_layout = vertex_layout; config.vertex_size = sizeof(NkVertex); config.vertex_alignment = 4; config.circle_segment_count = 22; config.curve_segment_count = 22; config.arc_segment_count = 22; config.global_alpha = 1.0f; // Convert Nuklear commands to vertex/index buffers nk_buffer cmds, verts, idx; nk_buffer_init_default(&cmds); nk_buffer_init_default(&verts); nk_buffer_init_default(&idx); nk_convert(nk_ctx_, &cmds, &verts, &idx, &config); // Check for buffer overflow size_t verts_size = nk_buffer_total(&verts); size_t idx_size = nk_buffer_total(&idx); if (verts_size > vertex_buffer_size_) { fprintf(stderr, "[GUI] Vertex buffer overflow: %zu > %zu\n", verts_size, vertex_buffer_size_); goto cleanup; } if (idx_size > index_buffer_size_) { fprintf(stderr, "[GUI] Index buffer overflow: %zu > %zu\n", idx_size, index_buffer_size_); goto cleanup; } // Upload geometry to GPU using sg_append_buffer (supports multiple calls per frame) if (verts_size > 0 && idx_size > 0) { sg_range vb_range; vb_range.ptr = nk_buffer_memory_const(&verts); vb_range.size = verts_size; int vb_offset = sg_append_buffer(vertex_buffer_, &vb_range); if (vb_offset < 0) { fprintf(stderr, "[GUI] Vertex buffer append failed\n"); goto cleanup; } sg_range ib_range; ib_range.ptr = nk_buffer_memory_const(&idx); ib_range.size = idx_size; int ib_base_offset = sg_append_buffer(index_buffer_, &ib_range); if (ib_base_offset < 0) { fprintf(stderr, "[GUI] Index buffer append failed\n"); goto cleanup; } // Setup rendering state sg_apply_pipeline(pipeline_); // Set uniforms (display size) float vs_params[4] = { (float)width, (float)height, 0.0f, 0.0f }; sg_range uniform_range; uniform_range.ptr = &vs_params; uniform_range.size = sizeof(vs_params); sg_apply_uniforms(0, &uniform_range); // Iterate through draw commands const nk_draw_command *cmd = nullptr; int offset = 0; nk_draw_foreach(cmd, nk_ctx_, &cmds) { if (cmd->elem_count == 0) continue; // Setup bindings with offsets from sg_append_buffer sg_bindings bindings = {}; bindings.vertex_buffers[0] = vertex_buffer_; bindings.vertex_buffer_offsets[0] = vb_offset; bindings.index_buffer = index_buffer_; bindings.index_buffer_offset = ib_base_offset + offset; // Select the correct texture based on Nuklear's draw command // If it matches the skin texture ID, use skin; otherwise use font if (skin_img_.id != 0 && cmd->texture.id == (int)skin_img_.id) { bindings.views[0] = skin_view_; bindings.samplers[0] = skin_sampler_; } else { bindings.views[0] = font_view_; bindings.samplers[0] = font_sampler_; } sg_apply_bindings(&bindings); // Apply scissor rect for clipping (scale to pixel coordinates) sg_apply_scissor_rectf( cmd->clip_rect.x * dpi_scale, cmd->clip_rect.y * dpi_scale, cmd->clip_rect.w * dpi_scale, cmd->clip_rect.h * dpi_scale, true ); // Draw indexed triangles sg_draw(0, (int)cmd->elem_count, 1); // Advance index offset offset += (int)cmd->elem_count * sizeof(uint16_t); } } cleanup: // Free temporary buffers nk_buffer_free(&cmds); nk_buffer_free(&verts); nk_buffer_free(&idx); // Clear Nuklear command queue nk_clear(nk_ctx_); } // ========== Widget implementations ========== bool Gui::windowBegin(const char *title, float x, float y, float w, float h, nk_flags flags) { if (!nk_ctx_) return false; return nk_begin(nk_ctx_, title, nk_rect(x, y, w, h), flags) != 0; } void Gui::windowEnd() { if (!nk_ctx_) return; nk_end(nk_ctx_); } bool Gui::isWindowHovered() { if (!nk_ctx_) return false; return nk_window_is_hovered(nk_ctx_) != 0; } bool Gui::isAnyWindowHovered() { if (!nk_ctx_) return false; return nk_window_is_any_hovered(nk_ctx_) != 0; } bool Gui::isAnyItemActive() { if (!nk_ctx_) return false; return nk_item_is_any_active(nk_ctx_) != 0; } void Gui::windowGetBounds(float *x, float *y, float *w, float *h) { if (!nk_ctx_) { *x = *y = *w = *h = 0; return; } struct nk_rect bounds = nk_window_get_bounds(nk_ctx_); *x = bounds.x; *y = bounds.y; *w = bounds.w; *h = bounds.h; } void Gui::layoutRowStatic(float height, int item_width, int cols) { if (!nk_ctx_) return; nk_layout_row_static(nk_ctx_, height, item_width, cols); } void Gui::layoutRowDynamic(float height, int cols) { if (!nk_ctx_) return; nk_layout_row_dynamic(nk_ctx_, height, cols); } bool Gui::button(const char *text) { if (!nk_ctx_) return false; return nk_button_label(nk_ctx_, text) != 0; } void Gui::label(const char *text, nk_flags align) { if (!nk_ctx_) return; nk_label(nk_ctx_, text, align); } void Gui::labelColored(const char *text, int r, int g, int b, int a, nk_flags align) { if (!nk_ctx_) return; nk_label_colored(nk_ctx_, text, align, nk_rgba(r, g, b, a)); } bool Gui::checkbox(const char *text, bool *active) { if (!nk_ctx_) return false; nk_bool nk_active = *active ? nk_true : nk_false; nk_bool result = nk_checkbox_label(nk_ctx_, text, &nk_active); *active = nk_active != 0; return result != 0; } float Gui::slider(float min, float value, float max, float step) { if (!nk_ctx_) return value; nk_slider_float(nk_ctx_, min, &value, max, step); return value; } int Gui::sliderInt(int min, int value, int max, int step) { if (!nk_ctx_) return value; nk_slider_int(nk_ctx_, min, &value, max, step); return value; } size_t Gui::progress(size_t current, size_t max, bool modifiable) { if (!nk_ctx_) return current; nk_size cur = (nk_size)current; nk_progress(nk_ctx_, &cur, (nk_size)max, modifiable ? nk_true : nk_false); return (size_t)cur; } bool Gui::option(const char *text, bool active) { if (!nk_ctx_) return active; return nk_option_label(nk_ctx_, text, active ? 1 : 0) != 0; } int Gui::propertyInt(const char *name, int min, int value, int max, int step, float incPerPixel) { if (!nk_ctx_) return value; return nk_propertyi(nk_ctx_, name, min, value, max, step, incPerPixel); } float Gui::propertyFloat(const char *name, float min, float value, float max, float step, float incPerPixel) { if (!nk_ctx_) return value; return nk_propertyf(nk_ctx_, name, min, value, max, step, incPerPixel); } bool Gui::selectable(const char *text, bool selected, nk_flags align) { if (!nk_ctx_) return false; nk_bool sel = selected ? nk_true : nk_false; nk_bool clicked = nk_selectable_label(nk_ctx_, text, align, &sel); return clicked != 0; } void Gui::spacing(int cols) { if (!nk_ctx_) return; nk_spacing(nk_ctx_, cols); } void Gui::separator() { if (!nk_ctx_) return; nk_rule_horizontal(nk_ctx_, nk_rgb(100, 100, 100), nk_false); } bool Gui::isWidgetHovered() { if (!nk_ctx_) return false; return nk_widget_is_hovered(nk_ctx_) != 0; } void Gui::editString(char *buffer, int *len, int max, nk_flags flags) { if (!nk_ctx_) return; nk_edit_string(nk_ctx_, flags, buffer, len, max, nk_filter_default); } int Gui::combo(const char **items, int count, int selected, int itemHeight, float width, float height) { if (!nk_ctx_) return selected; return nk_combo(nk_ctx_, items, count, selected, itemHeight, nk_vec2(width, height)); } void Gui::colorPicker(float *r, float *g, float *b, float *a, bool hasAlpha) { if (!nk_ctx_) return; struct nk_colorf color; color.r = *r; color.g = *g; color.b = *b; color.a = *a; color = nk_color_picker(nk_ctx_, color, hasAlpha ? NK_RGBA : NK_RGB); *r = color.r; *g = color.g; *b = color.b; *a = color.a; } void Gui::tooltip(const char *text) { if (!nk_ctx_) return; nk_tooltip(nk_ctx_, text); } bool Gui::groupBegin(const char *title, nk_flags flags) { if (!nk_ctx_) return false; return nk_group_begin(nk_ctx_, title, flags) != 0; } void Gui::groupEnd() { if (!nk_ctx_) return; nk_group_end(nk_ctx_); } bool Gui::treePush(nk_tree_type type, const char *title, nk_collapse_states state, int id) { if (!nk_ctx_) return false; return nk_tree_push_hashed(nk_ctx_, type, title, state, title, (int)strlen(title), id) != 0; } void Gui::treePop() { if (!nk_ctx_) return; nk_tree_pop(nk_ctx_); } void Gui::menubarBegin() { if (!nk_ctx_) return; nk_menubar_begin(nk_ctx_); } void Gui::menubarEnd() { if (!nk_ctx_) return; nk_menubar_end(nk_ctx_); } bool Gui::menuBegin(const char *label, nk_flags align, float width, float height) { if (!nk_ctx_) return false; return nk_menu_begin_label(nk_ctx_, label, align, nk_vec2(width, height)) != 0; } bool Gui::menuItem(const char *label, nk_flags align) { if (!nk_ctx_) return false; return nk_menu_item_label(nk_ctx_, label, align) != 0; } void Gui::menuEnd() { if (!nk_ctx_) return; nk_menu_end(nk_ctx_); } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/gui/gui.hh
C++ Header
#pragma once #include "nuklear_config.h" #include "sokol_gfx.h" #include "SDL3/SDL.h" namespace js { class Context; class Value; } namespace joy { class Engine; namespace modules { class Gui { public: Gui(Engine *engine); ~Gui(); // Initialize GUI context and font atlas (call before render backend) bool init(); // Initialize rendering resources (call after sokol_gfx is ready) bool initRendering(SDL_Window* window); // Handle SDL events for input void handleEvent(const SDL_Event *event); // Begin frame (call before GUI commands) void beginFrame(); // End frame and render (call after GUI commands) void endFrame(); // Render GUI (called from render backend) void render(int width, int height); // Get Nuklear context nk_context *getContext() const { return nk_ctx_; } // Set GUI font (rebuilds atlas) bool setFont(const char *path, float size); // Set GUI scale (affects font and all style properties) void setScale(float scale); float getScale() const { return scale_; } // Apply Gwen skin from image file bool applySkin(const char *path); // ========== Widget methods ========== // Window bool windowBegin(const char *title, float x, float y, float w, float h, nk_flags flags); void windowEnd(); bool isWindowHovered(); bool isAnyWindowHovered(); bool isAnyItemActive(); void windowGetBounds(float *x, float *y, float *w, float *h); // Layout void layoutRowStatic(float height, int item_width, int cols); void layoutRowDynamic(float height, int cols); // Widgets bool button(const char *text); void label(const char *text, nk_flags align); void labelColored(const char *text, int r, int g, int b, int a, nk_flags align); bool checkbox(const char *text, bool *active); float slider(float min, float value, float max, float step); int sliderInt(int min, int value, int max, int step); size_t progress(size_t current, size_t max, bool modifiable); bool option(const char *text, bool active); int propertyInt(const char *name, int min, int value, int max, int step, float incPerPixel); float propertyFloat(const char *name, float min, float value, float max, float step, float incPerPixel); bool selectable(const char *text, bool selected, nk_flags align); void spacing(int cols); void separator(); bool isWidgetHovered(); // Text input void editString(char *buffer, int *len, int max, nk_flags flags); // Combo box int combo(const char **items, int count, int selected, int itemHeight, float width, float height); // Color picker void colorPicker(float *r, float *g, float *b, float *a, bool hasAlpha); // Tooltip void tooltip(const char *text); // Groups bool groupBegin(const char *title, nk_flags flags); void groupEnd(); // Trees bool treePush(nk_tree_type type, const char *title, nk_collapse_states state, int id); void treePop(); // Menu bar void menubarBegin(); void menubarEnd(); bool menuBegin(const char *label, nk_flags align, float width, float height); bool menuItem(const char *label, nk_flags align); void menuEnd(); // Initialize JS bindings static void initJS(js::Context &ctx, js::Value &joy); private: Engine *engine_; SDL_Window *window_; nk_context *nk_ctx_; struct nk_font_atlas *atlas_; float scale_; float base_font_size_; // Rendering resources sg_image font_img_; sg_view font_view_; sg_sampler font_sampler_; sg_shader shader_; sg_pipeline pipeline_; sg_buffer vertex_buffer_; sg_buffer index_buffer_; size_t vertex_buffer_size_; size_t index_buffer_size_; // Skin texture sg_image skin_img_; sg_view skin_view_; sg_sampler skin_sampler_; }; } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/gui/gui_js.cc
C++
#include "js/js.hh" #include "gui.hh" #include "engine.hh" #include <cstring> #include <vector> namespace joy { namespace modules { // Helper to get Gui module from JS context static Gui *getGui(js::FunctionArgs &args) { Engine *engine = args.getContextOpaque<Engine>(); return engine ? engine->getGuiModule() : nullptr; } // Helper to parse text alignment string static nk_flags parseAlign(const std::string &align) { if (align == "centered") return NK_TEXT_CENTERED; if (align == "right") return NK_TEXT_RIGHT; return NK_TEXT_LEFT; } // Helper to parse window flags array static nk_flags parseWindowFlags(js::FunctionArgs &args, int argIndex) { nk_flags flags = NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE | NK_WINDOW_CLOSABLE | NK_WINDOW_MINIMIZABLE | NK_WINDOW_TITLE; if (args.length() > argIndex) { js::Value flagsArg = args.arg(argIndex); if (flagsArg.isArray()) { flags = 0; js::Value lengthVal = flagsArg.getProperty(args.context(), "length"); int32_t length = lengthVal.toInt32(); for (int32_t i = 0; i < length; i++) { js::Value elem = flagsArg.getProperty(args.context(), (uint32_t)i); std::string flag_str = elem.toString(args.context()); if (flag_str == "border") flags |= NK_WINDOW_BORDER; else if (flag_str == "movable") flags |= NK_WINDOW_MOVABLE; else if (flag_str == "scalable") flags |= NK_WINDOW_SCALABLE; else if (flag_str == "closable") flags |= NK_WINDOW_CLOSABLE; else if (flag_str == "minimizable") flags |= NK_WINDOW_MINIMIZABLE; else if (flag_str == "title") flags |= NK_WINDOW_TITLE; else if (flag_str == "noScrollbar") flags |= NK_WINDOW_NO_SCROLLBAR; } } } return flags; } // joy.gui.begin(title, x, y, width, height, flags) static void js_gui_begin(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 5) { args.returnValue(js::Value::boolean(false)); return; } std::string title = args.arg(0).toString(args.context()); float x = (float)args.arg(1).toFloat64(); float y = (float)args.arg(2).toFloat64(); float w = (float)args.arg(3).toFloat64(); float h = (float)args.arg(4).toFloat64(); nk_flags flags = parseWindowFlags(args, 5); bool result = gui->windowBegin(title.c_str(), x, y, w, h, flags); args.returnValue(js::Value::boolean(result)); } // joy.gui.end() static void js_gui_end(js::FunctionArgs &args) { Gui *gui = getGui(args); if (gui) gui->windowEnd(); args.returnUndefined(); } // joy.gui.layoutRowStatic(height, item_width, cols) static void js_gui_layout_row_static(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 3) { args.returnUndefined(); return; } float height = (float)args.arg(0).toFloat64(); int item_width = args.arg(1).toInt32(); int cols = args.arg(2).toInt32(); gui->layoutRowStatic(height, item_width, cols); args.returnUndefined(); } // joy.gui.layoutRowDynamic(height, cols) static void js_gui_layout_row_dynamic(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 2) { args.returnUndefined(); return; } float height = (float)args.arg(0).toFloat64(); int cols = args.arg(1).toInt32(); gui->layoutRowDynamic(height, cols); args.returnUndefined(); } // joy.gui.button(text) static void js_gui_button(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 1) { args.returnValue(js::Value::boolean(false)); return; } std::string text = args.arg(0).toString(args.context()); bool result = gui->button(text.c_str()); args.returnValue(js::Value::boolean(result)); } // joy.gui.label(text, align) static void js_gui_label(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 1) { args.returnUndefined(); return; } std::string text = args.arg(0).toString(args.context()); nk_flags align = NK_TEXT_LEFT; if (args.length() > 1) { align = parseAlign(args.arg(1).toString(args.context())); } gui->label(text.c_str(), align); args.returnUndefined(); } // joy.gui.labelColored(text, r, g, b, a, align) static void js_gui_label_colored(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 4) { args.returnUndefined(); return; } std::string text = args.arg(0).toString(args.context()); int r = args.arg(1).toInt32(); int g = args.arg(2).toInt32(); int b = args.arg(3).toInt32(); int a = args.length() > 4 ? args.arg(4).toInt32() : 255; nk_flags align = NK_TEXT_LEFT; if (args.length() > 5) { align = parseAlign(args.arg(5).toString(args.context())); } gui->labelColored(text.c_str(), r, g, b, a, align); args.returnUndefined(); } // joy.gui.checkbox(text, active) static void js_gui_checkbox(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 2) { args.returnValue(js::Value::boolean(false)); return; } std::string text = args.arg(0).toString(args.context()); bool active = args.arg(1).toBool(); gui->checkbox(text.c_str(), &active); args.returnValue(js::Value::boolean(active)); } // joy.gui.slider(min, value, max, step) static void js_gui_slider(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 4) { args.returnValue(args.length() >= 2 ? args.arg(1) : js::Value::number(0.0)); return; } float min = (float)args.arg(0).toFloat64(); float value = (float)args.arg(1).toFloat64(); float max = (float)args.arg(2).toFloat64(); float step = (float)args.arg(3).toFloat64(); float result = gui->slider(min, value, max, step); args.returnValue(js::Value::number((double)result)); } // joy.gui.sliderInt(min, value, max, step) static void js_gui_slider_int(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 4) { args.returnValue(args.length() >= 2 ? args.arg(1) : js::Value::number(0)); return; } int min = args.arg(0).toInt32(); int value = args.arg(1).toInt32(); int max = args.arg(2).toInt32(); int step = args.arg(3).toInt32(); int result = gui->sliderInt(min, value, max, step); args.returnValue(js::Value::number(result)); } // joy.gui.progress(current, max, modifiable) static void js_gui_progress(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 2) { args.returnValue(js::Value::number(0)); return; } size_t current = (size_t)args.arg(0).toInt32(); size_t max = (size_t)args.arg(1).toInt32(); bool modifiable = args.length() > 2 ? args.arg(2).toBool() : false; size_t result = gui->progress(current, max, modifiable); args.returnValue(js::Value::number((double)result)); } // joy.gui.option(text, active) - radio button static void js_gui_option(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 2) { args.returnValue(js::Value::boolean(false)); return; } std::string text = args.arg(0).toString(args.context()); bool active = args.arg(1).toBool(); bool result = gui->option(text.c_str(), active); args.returnValue(js::Value::boolean(result)); } // joy.gui.edit(text, maxLength, flags) static void js_gui_edit(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 1) { args.returnValue(js::Value::string(args.context(), "")); return; } std::string text = args.arg(0).toString(args.context()); int maxLength = args.length() > 1 ? args.arg(1).toInt32() : 256; // Parse flags nk_flags flags = NK_EDIT_SIMPLE; if (args.length() > 2) { js::Value flagsArg = args.arg(2); if (flagsArg.isArray()) { flags = 0; js::Value lengthVal = flagsArg.getProperty(args.context(), "length"); int32_t length = lengthVal.toInt32(); for (int32_t i = 0; i < length; i++) { js::Value elem = flagsArg.getProperty(args.context(), (uint32_t)i); std::string flag_str = elem.toString(args.context()); if (flag_str == "default") flags |= NK_EDIT_DEFAULT; else if (flag_str == "readOnly") flags |= NK_EDIT_READ_ONLY; else if (flag_str == "autoSelect") flags |= NK_EDIT_AUTO_SELECT; else if (flag_str == "sigEnter") flags |= NK_EDIT_SIG_ENTER; else if (flag_str == "allowTab") flags |= NK_EDIT_ALLOW_TAB; else if (flag_str == "noCursor") flags |= NK_EDIT_NO_CURSOR; else if (flag_str == "selectable") flags |= NK_EDIT_SELECTABLE; else if (flag_str == "clipboard") flags |= NK_EDIT_CLIPBOARD; else if (flag_str == "ctrlEnterNewline") flags |= NK_EDIT_CTRL_ENTER_NEWLINE; else if (flag_str == "noHorizontalScroll") flags |= NK_EDIT_NO_HORIZONTAL_SCROLL; else if (flag_str == "alwaysInsertMode") flags |= NK_EDIT_ALWAYS_INSERT_MODE; else if (flag_str == "multiline") flags |= NK_EDIT_MULTILINE; else if (flag_str == "gotoEndOnActivate") flags |= NK_EDIT_GOTO_END_ON_ACTIVATE; else if (flag_str == "simple") flags |= NK_EDIT_SIMPLE; else if (flag_str == "field") flags |= NK_EDIT_FIELD; else if (flag_str == "box") flags |= NK_EDIT_BOX; else if (flag_str == "editor") flags |= NK_EDIT_EDITOR; } } } // Create buffer char *buffer = (char *)malloc(maxLength + 1); if (!buffer) { args.returnValue(args.arg(0)); return; } int len = (int)text.length(); if (len > maxLength) len = maxLength; memcpy(buffer, text.c_str(), len); buffer[len] = '\0'; gui->editString(buffer, &len, maxLength, flags); buffer[len] = '\0'; std::string result(buffer); free(buffer); args.returnValue(js::Value::string(args.context(), result.c_str())); } // joy.gui.propertyInt(name, min, value, max, step, incPerPixel) static void js_gui_property_int(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 5) { args.returnValue(args.length() >= 3 ? args.arg(2) : js::Value::number(0)); return; } std::string name = args.arg(0).toString(args.context()); int min = args.arg(1).toInt32(); int value = args.arg(2).toInt32(); int max = args.arg(3).toInt32(); int step = args.arg(4).toInt32(); float incPerPixel = args.length() > 5 ? (float)args.arg(5).toFloat64() : 1.0f; int result = gui->propertyInt(name.c_str(), min, value, max, step, incPerPixel); args.returnValue(js::Value::number(result)); } // joy.gui.propertyFloat(name, min, value, max, step, incPerPixel) static void js_gui_property_float(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 5) { args.returnValue(args.length() >= 3 ? args.arg(2) : js::Value::number(0.0)); return; } std::string name = args.arg(0).toString(args.context()); float min = (float)args.arg(1).toFloat64(); float value = (float)args.arg(2).toFloat64(); float max = (float)args.arg(3).toFloat64(); float step = (float)args.arg(4).toFloat64(); float incPerPixel = args.length() > 5 ? (float)args.arg(5).toFloat64() : 0.01f; float result = gui->propertyFloat(name.c_str(), min, value, max, step, incPerPixel); args.returnValue(js::Value::number((double)result)); } // joy.gui.combo(items, selected, itemHeight, width, height) static void js_gui_combo(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 2) { args.returnValue(js::Value::number(0)); return; } js::Value itemsArg = args.arg(0); if (!itemsArg.isArray()) { args.returnValue(args.arg(1)); return; } js::Value lengthVal = itemsArg.getProperty(args.context(), "length"); int count = lengthVal.toInt32(); // Build items array std::vector<std::string> itemStrings(count); std::vector<const char *> items(count); for (int i = 0; i < count; i++) { js::Value elem = itemsArg.getProperty(args.context(), (uint32_t)i); itemStrings[i] = elem.toString(args.context()); items[i] = itemStrings[i].c_str(); } int selected = args.arg(1).toInt32(); int itemHeight = args.length() > 2 ? args.arg(2).toInt32() : 25; float width = args.length() > 3 ? (float)args.arg(3).toFloat64() : 200.0f; float height = args.length() > 4 ? (float)args.arg(4).toFloat64() : 200.0f; int result = gui->combo(items.data(), count, selected, itemHeight, width, height); args.returnValue(js::Value::number(result)); } // joy.gui.colorPicker(r, g, b, a, hasAlpha) static void js_gui_color_picker(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 3) { js::Value result = js::Value::object(args.context()); result.setProperty(args.context(), "r", js::Value::number(0)); result.setProperty(args.context(), "g", js::Value::number(0)); result.setProperty(args.context(), "b", js::Value::number(0)); result.setProperty(args.context(), "a", js::Value::number(1)); args.returnValue(std::move(result)); return; } float r = (float)args.arg(0).toFloat64(); float g = (float)args.arg(1).toFloat64(); float b = (float)args.arg(2).toFloat64(); float a = args.length() > 3 ? (float)args.arg(3).toFloat64() : 1.0f; bool hasAlpha = args.length() > 4 ? args.arg(4).toBool() : true; gui->colorPicker(&r, &g, &b, &a, hasAlpha); js::Value result = js::Value::object(args.context()); result.setProperty(args.context(), "r", js::Value::number((double)r)); result.setProperty(args.context(), "g", js::Value::number((double)g)); result.setProperty(args.context(), "b", js::Value::number((double)b)); result.setProperty(args.context(), "a", js::Value::number((double)a)); args.returnValue(std::move(result)); } // joy.gui.tooltip(text) static void js_gui_tooltip(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 1) { args.returnUndefined(); return; } std::string text = args.arg(0).toString(args.context()); gui->tooltip(text.c_str()); args.returnUndefined(); } // joy.gui.groupBegin(title, flags) static void js_gui_group_begin(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 1) { args.returnValue(js::Value::boolean(false)); return; } std::string title = args.arg(0).toString(args.context()); // Parse flags nk_flags flags = 0; if (args.length() > 1) { js::Value flagsArg = args.arg(1); if (flagsArg.isArray()) { js::Value lengthVal = flagsArg.getProperty(args.context(), "length"); int32_t length = lengthVal.toInt32(); for (int32_t i = 0; i < length; i++) { js::Value elem = flagsArg.getProperty(args.context(), (uint32_t)i); std::string flag_str = elem.toString(args.context()); if (flag_str == "border") flags |= NK_WINDOW_BORDER; else if (flag_str == "title") flags |= NK_WINDOW_TITLE; else if (flag_str == "noScrollbar") flags |= NK_WINDOW_NO_SCROLLBAR; } } } bool result = gui->groupBegin(title.c_str(), flags); args.returnValue(js::Value::boolean(result)); } // joy.gui.groupEnd() static void js_gui_group_end(js::FunctionArgs &args) { Gui *gui = getGui(args); if (gui) gui->groupEnd(); args.returnUndefined(); } // joy.gui.treePush(type, title, initialState, id) static void js_gui_tree_push(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 2) { args.returnValue(js::Value::boolean(false)); return; } std::string typeStr = args.arg(0).toString(args.context()); std::string title = args.arg(1).toString(args.context()); nk_tree_type type = NK_TREE_NODE; if (typeStr == "tab") type = NK_TREE_TAB; nk_collapse_states state = NK_MINIMIZED; if (args.length() > 2) { std::string stateStr = args.arg(2).toString(args.context()); if (stateStr == "maximized") state = NK_MAXIMIZED; } int id = args.length() > 3 ? args.arg(3).toInt32() : 0; bool result = gui->treePush(type, title.c_str(), state, id); args.returnValue(js::Value::boolean(result)); } // joy.gui.treePop() static void js_gui_tree_pop(js::FunctionArgs &args) { Gui *gui = getGui(args); if (gui) gui->treePop(); args.returnUndefined(); } // joy.gui.selectable(text, selected, align) static void js_gui_selectable(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 2) { args.returnValue(js::Value::boolean(false)); return; } std::string text = args.arg(0).toString(args.context()); bool selected = args.arg(1).toBool(); nk_flags align = NK_TEXT_LEFT; if (args.length() > 2) { align = parseAlign(args.arg(2).toString(args.context())); } bool result = gui->selectable(text.c_str(), selected, align); args.returnValue(js::Value::boolean(result)); } // joy.gui.spacing(cols) static void js_gui_spacing(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui) { args.returnUndefined(); return; } int cols = args.length() > 0 ? args.arg(0).toInt32() : 1; gui->spacing(cols); args.returnUndefined(); } // joy.gui.separator() static void js_gui_separator(js::FunctionArgs &args) { Gui *gui = getGui(args); if (gui) gui->separator(); args.returnUndefined(); } // joy.gui.isWindowHovered() static void js_gui_is_window_hovered(js::FunctionArgs &args) { Gui *gui = getGui(args); args.returnValue(js::Value::boolean(gui && gui->isWindowHovered())); } // joy.gui.isAnyWindowHovered() static void js_gui_is_any_window_hovered(js::FunctionArgs &args) { Gui *gui = getGui(args); args.returnValue(js::Value::boolean(gui && gui->isAnyWindowHovered())); } // joy.gui.isAnyItemActive() static void js_gui_is_any_item_active(js::FunctionArgs &args) { Gui *gui = getGui(args); args.returnValue(js::Value::boolean(gui && gui->isAnyItemActive())); } // joy.gui.isWidgetHovered() static void js_gui_is_widget_hovered(js::FunctionArgs &args) { Gui *gui = getGui(args); args.returnValue(js::Value::boolean(gui && gui->isWidgetHovered())); } // joy.gui.windowGetBounds() static void js_gui_window_get_bounds(js::FunctionArgs &args) { Gui *gui = getGui(args); float x = 0, y = 0, w = 0, h = 0; if (gui) gui->windowGetBounds(&x, &y, &w, &h); js::Value result = js::Value::object(args.context()); result.setProperty(args.context(), "x", js::Value::number((double)x)); result.setProperty(args.context(), "y", js::Value::number((double)y)); result.setProperty(args.context(), "w", js::Value::number((double)w)); result.setProperty(args.context(), "h", js::Value::number((double)h)); args.returnValue(std::move(result)); } // joy.gui.menubarBegin() static void js_gui_menubar_begin(js::FunctionArgs &args) { Gui *gui = getGui(args); if (gui) gui->menubarBegin(); args.returnUndefined(); } // joy.gui.menubarEnd() static void js_gui_menubar_end(js::FunctionArgs &args) { Gui *gui = getGui(args); if (gui) gui->menubarEnd(); args.returnUndefined(); } // joy.gui.menuBegin(label, align, width, height) static void js_gui_menu_begin(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 1) { args.returnValue(js::Value::boolean(false)); return; } std::string label = args.arg(0).toString(args.context()); nk_flags align = NK_TEXT_LEFT; if (args.length() > 1) { align = parseAlign(args.arg(1).toString(args.context())); } float width = args.length() > 2 ? (float)args.arg(2).toFloat64() : 120.0f; float height = args.length() > 3 ? (float)args.arg(3).toFloat64() : 200.0f; bool result = gui->menuBegin(label.c_str(), align, width, height); args.returnValue(js::Value::boolean(result)); } // joy.gui.menuItem(label, align) static void js_gui_menu_item(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 1) { args.returnValue(js::Value::boolean(false)); return; } std::string label = args.arg(0).toString(args.context()); nk_flags align = NK_TEXT_LEFT; if (args.length() > 1) { align = parseAlign(args.arg(1).toString(args.context())); } bool result = gui->menuItem(label.c_str(), align); args.returnValue(js::Value::boolean(result)); } // joy.gui.menuEnd() static void js_gui_menu_end(js::FunctionArgs &args) { Gui *gui = getGui(args); if (gui) gui->menuEnd(); args.returnUndefined(); } // joy.gui.setFont(path, size) static void js_gui_setFont(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 2) { args.returnValue(js::Value::boolean(false)); return; } std::string path = args.arg(0).toString(args.context()); float size = (float)args.arg(1).toFloat64(); bool result = gui->setFont(path.c_str(), size); args.returnValue(js::Value::boolean(result)); } // joy.gui.applySkin(path) static void js_gui_applySkin(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 1) { args.returnValue(js::Value::boolean(false)); return; } std::string path = args.arg(0).toString(args.context()); bool result = gui->applySkin(path.c_str()); args.returnValue(js::Value::boolean(result)); } // joy.gui.setScale(scale) static void js_gui_setScale(js::FunctionArgs &args) { Gui *gui = getGui(args); if (!gui || args.length() < 1) { args.returnUndefined(); return; } float scale = (float)args.arg(0).toFloat64(); gui->setScale(scale); args.returnUndefined(); } // joy.gui.getScale() static void js_gui_getScale(js::FunctionArgs &args) { Gui *gui = getGui(args); args.returnValue(js::Value::number(gui ? gui->getScale() : 1.0)); } void Gui::initJS(js::Context &ctx, js::Value &joy) { js::ModuleBuilder(ctx, "gui") // Window .function("begin", js_gui_begin, 5) .function("end", js_gui_end, 0) .function("isWindowHovered", js_gui_is_window_hovered, 0) .function("isAnyWindowHovered", js_gui_is_any_window_hovered, 0) .function("isAnyItemActive", js_gui_is_any_item_active, 0) .function("windowGetBounds", js_gui_window_get_bounds, 0) // Layout .function("layoutRowStatic", js_gui_layout_row_static, 3) .function("layoutRowDynamic", js_gui_layout_row_dynamic, 2) // Widgets .function("button", js_gui_button, 1) .function("label", js_gui_label, 1) .function("labelColored", js_gui_label_colored, 5) .function("checkbox", js_gui_checkbox, 2) .function("slider", js_gui_slider, 4) .function("sliderInt", js_gui_slider_int, 4) .function("progress", js_gui_progress, 3) .function("option", js_gui_option, 2) .function("edit", js_gui_edit, 3) .function("propertyInt", js_gui_property_int, 6) .function("propertyFloat", js_gui_property_float, 6) .function("combo", js_gui_combo, 5) .function("colorPicker", js_gui_color_picker, 5) .function("selectable", js_gui_selectable, 3) .function("spacing", js_gui_spacing, 1) .function("separator", js_gui_separator, 0) .function("isWidgetHovered", js_gui_is_widget_hovered, 0) // Tooltip .function("tooltip", js_gui_tooltip, 1) // Groups .function("groupBegin", js_gui_group_begin, 2) .function("groupEnd", js_gui_group_end, 0) // Trees .function("treePush", js_gui_tree_push, 4) .function("treePop", js_gui_tree_pop, 0) // Menu bar .function("menubarBegin", js_gui_menubar_begin, 0) .function("menubarEnd", js_gui_menubar_end, 0) .function("menuBegin", js_gui_menu_begin, 4) .function("menuItem", js_gui_menu_item, 2) .function("menuEnd", js_gui_menu_end, 0) // Font/Skin/Scale .function("setFont", js_gui_setFont, 2) .function("applySkin", js_gui_applySkin, 1) .function("setScale", js_gui_setScale, 1) .function("getScale", js_gui_getScale, 0) .attachTo(joy); } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/gui/gui_shaders.h
C/C++ Header
#pragma once // Nuklear GUI shaders for different platforms // Extracted from sokol_nuklear.h reference implementation #include <cstdint> // Backend selection via CMake defines (RENDER_METAL or RENDER_OPENGL) #if !defined(SOKOL_GLCORE) && !defined(SOKOL_GLES3) && !defined(SOKOL_METAL) #if defined(RENDER_METAL) #define SOKOL_METAL #elif defined(__EMSCRIPTEN__) #define SOKOL_GLES3 #else #define SOKOL_GLCORE #endif #endif // Platform-specific defines #if defined(SOKOL_GLCORE) #define NK_SHADER_COLOR_FORMAT SG_PIXELFORMAT_RGBA8 #define NK_VS_ENTRY "main" #define NK_FS_ENTRY "main" #elif defined(SOKOL_GLES3) #define NK_SHADER_COLOR_FORMAT SG_PIXELFORMAT_RGBA8 #define NK_VS_ENTRY "main" #define NK_FS_ENTRY "main" #elif defined(SOKOL_METAL) #define NK_SHADER_COLOR_FORMAT SG_PIXELFORMAT_BGRA8 #define NK_VS_ENTRY "main0" #define NK_FS_ENTRY "main0" #else #error "Unsupported sokol backend" #endif // Vertex structure (20 bytes total) struct NkVertex { float pos[2]; // offset 0, size 8 float uv[2]; // offset 8, size 8 uint8_t col[4]; // offset 16, size 4 }; #if defined(SOKOL_GLCORE) /* GLSL 410 Vertex Shader: #version 410 uniform vec4 vs_params[1]; layout(location = 0) in vec2 position; layout(location = 0) out vec2 uv; layout(location = 1) in vec2 texcoord0; layout(location = 1) out vec4 color; layout(location = 2) in vec4 color0; void main() { gl_Position = vec4(((position / vs_params[0].xy) - vec2(0.5)) * vec2(2.0, -2.0), 0.5, 1.0); uv = texcoord0; color = color0; } */ static const uint8_t nk_vs_bytecode[] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x31,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73,0x5f,0x70,0x61, 0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e, 0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a, 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, 0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76, 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, 0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x74, 0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x6f, 0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c, 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, 0x20,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f, 0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29, 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, 0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x28,0x70,0x6f,0x73,0x69, 0x74,0x69,0x6f,0x6e,0x20,0x2f,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, 0x5b,0x30,0x5d,0x2e,0x78,0x79,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x30, 0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x32,0x28,0x32,0x2e,0x30,0x2c, 0x20,0x2d,0x32,0x2e,0x30,0x29,0x2c,0x20,0x30,0x2e,0x35,0x2c,0x20,0x31,0x2e,0x30, 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x76,0x20,0x3d,0x20,0x74,0x65,0x78,0x63, 0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72, 0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; /* GLSL 410 Fragment Shader: #version 410 uniform sampler2D tex_smp; layout(location = 0) out vec4 frag_color; layout(location = 0) in vec2 uv; layout(location = 1) in vec4 color; void main() { frag_color = texture(tex_smp, uv) * color; } */ static const uint8_t nk_fs_bytecode[] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x31,0x30,0x0a,0x0a,0x75,0x6e, 0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20, 0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f, 0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c, 0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32, 0x20,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d, 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67, 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, 0x28,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x29,0x20,0x2a,0x20, 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; #elif defined(SOKOL_GLES3) /* GLSL 300 ES Vertex Shader */ static const uint8_t nk_vs_bytecode[] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x73, 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x31,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f, 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29, 0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f, 0x6e,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x3b,0x0a, 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, 0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x32,0x20,0x74,0x65,0x78, 0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34, 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x69,0x6e,0x20, 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x0a,0x76,0x6f, 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65, 0x63,0x34,0x28,0x28,0x28,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x2f,0x20, 0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x29, 0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20, 0x76,0x65,0x63,0x32,0x28,0x32,0x2e,0x30,0x2c,0x20,0x2d,0x32,0x2e,0x30,0x29,0x2c, 0x20,0x30,0x2e,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, 0x75,0x76,0x20,0x3d,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, 0x72,0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; /* GLSL 300 ES Fragment Shader */ static const uint8_t nk_fs_bytecode[] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 0x70,0x72,0x65,0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,0x6d,0x65,0x64,0x69,0x75,0x6d, 0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3b,0x0a,0x70,0x72,0x65,0x63,0x69,0x73,0x69, 0x6f,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x69,0x6e,0x74,0x3b,0x0a,0x0a,0x75, 0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x73,0x61,0x6d, 0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a, 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, 0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x68,0x69,0x67,0x68,0x70,0x20, 0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, 0x0a,0x69,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x32,0x20,0x75, 0x76,0x3b,0x0a,0x69,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34, 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61, 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f, 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28, 0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x75,0x76,0x29,0x20,0x2a,0x20,0x63, 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; #elif defined(SOKOL_METAL) /* Metal Vertex Shader (macOS) */ static const uint8_t nk_vs_bytecode_metal_macos[3116] = { 0x4d,0x54,0x4c,0x42,0x01,0x80,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x2c,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x6d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc9,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x3b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x00, 0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x01,0x00,0x00,0x00,0x00,0x00,0x00, 0x20,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x6d,0x00,0x00,0x00, 0x4e,0x41,0x4d,0x45,0x06,0x00,0x6d,0x61,0x69,0x6e,0x30,0x00,0x54,0x59,0x50,0x45, 0x01,0x00,0x00,0x48,0x41,0x53,0x48,0x20,0x00,0x6c,0xc6,0xce,0x18,0x4d,0xb5,0xf9, 0xae,0x57,0x9c,0x34,0x76,0x94,0x96,0x17,0x9a,0x2d,0xca,0x04,0xbe,0xda,0x39,0x87, 0xd4,0x9d,0x6e,0x8c,0x73,0xe8,0x15,0x57,0xa2,0x4f,0x46,0x46,0x54,0x18,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x56,0x45,0x52,0x53,0x08,0x00,0x01,0x00,0x08, 0x00,0x01,0x00,0x01,0x00,0x45,0x4e,0x44,0x54,0x37,0x00,0x00,0x00,0x56,0x41,0x54, 0x54,0x22,0x00,0x03,0x00,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x00,0x00,0x80, 0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x00,0x01,0x80,0x63,0x6f,0x6c,0x6f, 0x72,0x30,0x00,0x02,0x80,0x56,0x41,0x54,0x59,0x05,0x00,0x03,0x00,0x04,0x04,0x06, 0x45,0x4e,0x44,0x54,0x04,0x00,0x00,0x00,0x45,0x4e,0x44,0x54,0xde,0xc0,0x17,0x0b, 0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x08,0x0b,0x00,0x00,0xff,0xff,0xff,0xff, 0x42,0x43,0xc0,0xde,0x21,0x0c,0x00,0x00,0xbf,0x02,0x00,0x00,0x0b,0x82,0x20,0x00, 0x02,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x07,0x81,0x23,0x91,0x41,0xc8,0x04,0x49, 0x06,0x10,0x32,0x39,0x92,0x01,0x84,0x0c,0x25,0x05,0x08,0x19,0x1e,0x04,0x8b,0x62, 0x80,0x10,0x45,0x02,0x42,0x92,0x0b,0x42,0x84,0x10,0x32,0x14,0x38,0x08,0x18,0x49, 0x0a,0x32,0x44,0x24,0x48,0x0a,0x90,0x21,0x23,0xc4,0x52,0x80,0x0c,0x19,0x21,0x72, 0x24,0x07,0xc8,0x08,0x11,0x62,0xa8,0xa0,0xa8,0x40,0xc6,0xf0,0x01,0x00,0x00,0x00, 0x51,0x18,0x00,0x00,0x68,0x00,0x00,0x00,0x1b,0x7e,0x24,0xf8,0xff,0xff,0xff,0xff, 0x01,0x90,0x00,0x8a,0x08,0x07,0x78,0x80,0x07,0x79,0x78,0x07,0x7c,0x68,0x03,0x73, 0xa8,0x07,0x77,0x18,0x87,0x36,0x30,0x07,0x78,0x68,0x83,0x76,0x08,0x07,0x7a,0x40, 0x07,0x80,0x1e,0xe4,0xa1,0x1e,0xca,0x01,0x20,0xda,0x21,0x1d,0xdc,0xa1,0x0d,0xd8, 0xa1,0x1c,0xce,0x21,0x1c,0xd8,0xa1,0x0d,0xec,0xa1,0x1c,0xc6,0x81,0x1e,0xde,0x41, 0x1e,0xda,0xe0,0x1e,0xd2,0x81,0x1c,0xe8,0x01,0x1d,0x80,0x38,0x90,0x03,0x3c,0x00, 0x06,0x77,0x78,0x87,0x36,0x10,0x87,0x7a,0x48,0x07,0x76,0xa0,0x87,0x74,0x70,0x87, 0x79,0x00,0x08,0x77,0x78,0x87,0x36,0x30,0x07,0x79,0x08,0x87,0x76,0x28,0x87,0x36, 0x80,0x87,0x77,0x48,0x07,0x77,0xa0,0x87,0x72,0x90,0x87,0x36,0x28,0x07,0x76,0x48, 0x87,0x76,0x00,0xe8,0x41,0x1e,0xea,0xa1,0x1c,0x00,0xc2,0x1d,0xde,0xa1,0x0d,0xcc, 0x41,0x1e,0xc2,0xa1,0x1d,0xca,0xa1,0x0d,0xe0,0xe1,0x1d,0xd2,0xc1,0x1d,0xe8,0xa1, 0x1c,0xe4,0xa1,0x0d,0xca,0x81,0x1d,0xd2,0xa1,0x1d,0xda,0xc0,0x1d,0xde,0xc1,0x1d, 0xda,0x80,0x1d,0xca,0x21,0x1c,0xcc,0x01,0xa0,0x07,0x79,0xa8,0x87,0x72,0x00,0x08, 0x77,0x78,0x87,0x36,0x48,0x07,0x77,0x30,0x87,0x79,0x68,0x03,0x73,0x80,0x87,0x36, 0x68,0x87,0x70,0xa0,0x07,0x74,0x00,0xe8,0x41,0x1e,0xea,0xa1,0x1c,0x00,0xc2,0x1d, 0xde,0xa1,0x0d,0xdc,0x21,0x1c,0xdc,0x61,0x1e,0xda,0xc0,0x1c,0xe0,0xa1,0x0d,0xda, 0x21,0x1c,0xe8,0x01,0x1d,0x00,0x7a,0x90,0x87,0x7a,0x28,0x07,0x80,0x70,0x87,0x77, 0x68,0x83,0x79,0x48,0x87,0x73,0x70,0x87,0x72,0x20,0x87,0x36,0xd0,0x87,0x72,0x90, 0x87,0x77,0x98,0x87,0x36,0x30,0x07,0x78,0x68,0x83,0x76,0x08,0x07,0x7a,0x40,0x07, 0x80,0x1e,0xe4,0xa1,0x1e,0xca,0x01,0x20,0xdc,0xe1,0x1d,0xda,0x80,0x1e,0xe4,0x21, 0x1c,0xe0,0x01,0x1e,0xd2,0xc1,0x1d,0xce,0xa1,0x0d,0xda,0x21,0x1c,0xe8,0x01,0x1d, 0x00,0x7a,0x90,0x87,0x7a,0x28,0x07,0x80,0x98,0x07,0x7a,0x08,0x87,0x71,0x58,0x87, 0x36,0x80,0x07,0x79,0x78,0x07,0x7a,0x28,0x87,0x71,0xa0,0x87,0x77,0x90,0x87,0x36, 0x10,0x87,0x7a,0x30,0x07,0x73,0x28,0x07,0x79,0x68,0x83,0x79,0x48,0x07,0x7d,0x28, 0x07,0x00,0x0f,0x00,0xa2,0x1e,0xdc,0x61,0x1e,0xc2,0xc1,0x1c,0xca,0xa1,0x0d,0xcc, 0x01,0x1e,0xda,0xa0,0x1d,0xc2,0x81,0x1e,0xd0,0x01,0xa0,0x07,0x79,0xa8,0x87,0x72, 0x00,0x36,0x18,0x02,0x01,0x2c,0x40,0x05,0x49,0x18,0x00,0x00,0x01,0x00,0x00,0x00, 0x13,0x84,0x40,0x00,0x89,0x20,0x00,0x00,0x16,0x00,0x00,0x00,0x32,0x22,0x08,0x09, 0x20,0x64,0x85,0x04,0x13,0x22,0xa4,0x84,0x04,0x13,0x22,0xe3,0x84,0xa1,0x90,0x14, 0x12,0x4c,0x88,0x8c,0x0b,0x84,0x84,0x4c,0x10,0x3c,0x33,0x00,0xc3,0x08,0x02,0x30, 0x8c,0x40,0x00,0x76,0x08,0x91,0x83,0xa4,0x29,0xa2,0x84,0xc9,0xaf,0xa4,0xff,0x01, 0x22,0x80,0x91,0x50,0x10,0x83,0x08,0x84,0x50,0x8a,0x89,0x90,0x22,0x1b,0x08,0x98, 0x23,0x00,0x83,0x14,0xc8,0x39,0x02,0x50,0x18,0x44,0x08,0x84,0x61,0x04,0x22,0x19, 0x01,0x00,0x00,0x00,0x13,0xb2,0x70,0x48,0x07,0x79,0xb0,0x03,0x3a,0x68,0x83,0x70, 0x80,0x07,0x78,0x60,0x87,0x72,0x68,0x83,0x76,0x08,0x87,0x71,0x78,0x87,0x79,0xc0, 0x87,0x38,0x80,0x03,0x37,0x88,0x83,0x38,0x70,0x03,0x38,0xd8,0x70,0x1b,0xe5,0xd0, 0x06,0xf0,0xa0,0x07,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07, 0x6d,0x90,0x0e,0x71,0xa0,0x07,0x78,0xa0,0x07,0x78,0xd0,0x06,0xe9,0x80,0x07,0x7a, 0x80,0x07,0x7a,0x80,0x07,0x6d,0x90,0x0e,0x71,0x60,0x07,0x7a,0x10,0x07,0x76,0xa0, 0x07,0x71,0x60,0x07,0x6d,0x90,0x0e,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07, 0x73,0x20,0x07,0x6d,0x90,0x0e,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76, 0x40,0x07,0x6d,0x60,0x0e,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73,0x20, 0x07,0x6d,0x60,0x0e,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07, 0x6d,0x60,0x0f,0x71,0x60,0x07,0x7a,0x10,0x07,0x76,0xa0,0x07,0x71,0x60,0x07,0x6d, 0x60,0x0f,0x72,0x40,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73,0x20,0x07,0x6d,0x60, 0x0f,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73,0x20,0x07,0x6d,0x60,0x0f, 0x74,0x80,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d,0x60,0x0f,0x76, 0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d,0x60,0x0f,0x79,0x60, 0x07,0x7a,0x10,0x07,0x72,0x80,0x07,0x7a,0x10,0x07,0x72,0x80,0x07,0x6d,0x60,0x0f, 0x71,0x20,0x07,0x78,0xa0,0x07,0x71,0x20,0x07,0x78,0xa0,0x07,0x71,0x20,0x07,0x78, 0xd0,0x06,0xf6,0x10,0x07,0x79,0x20,0x07,0x7a,0x20,0x07,0x75,0x60,0x07,0x7a,0x20, 0x07,0x75,0x60,0x07,0x6d,0x60,0x0f,0x72,0x50,0x07,0x76,0xa0,0x07,0x72,0x50,0x07, 0x76,0xa0,0x07,0x72,0x50,0x07,0x76,0xd0,0x06,0xf6,0x50,0x07,0x71,0x20,0x07,0x7a, 0x50,0x07,0x71,0x20,0x07,0x7a,0x50,0x07,0x71,0x20,0x07,0x6d,0x60,0x0f,0x71,0x00, 0x07,0x72,0x40,0x07,0x7a,0x10,0x07,0x70,0x20,0x07,0x74,0xa0,0x07,0x71,0x00,0x07, 0x72,0x40,0x07,0x6d,0xe0,0x0e,0x78,0xa0,0x07,0x71,0x60,0x07,0x7a,0x30,0x07,0x72, 0x30,0x84,0x39,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0xc8,0x02,0x01,0x00,0x00, 0x09,0x00,0x00,0x00,0x32,0x1e,0x98,0x10,0x19,0x11,0x4c,0x90,0x8c,0x09,0x26,0x47, 0xc6,0x04,0x43,0xca,0x12,0x18,0x01,0x28,0x88,0x22,0x28,0x84,0x32,0xa0,0x1d,0x01, 0x20,0x1d,0x4b,0x78,0x00,0x00,0x00,0x00,0x79,0x18,0x00,0x00,0xe9,0x00,0x00,0x00, 0x1a,0x03,0x4c,0x10,0x97,0x29,0xa2,0x25,0x10,0xab,0x32,0xb9,0xb9,0xb4,0x37,0xb7, 0x21,0x46,0x42,0x20,0x80,0x82,0x50,0xb9,0x1b,0x43,0x0b,0x93,0xfb,0x9a,0x4b,0xd3, 0x2b,0x1b,0x62,0x24,0x01,0x22,0x24,0x05,0xe3,0x20,0x08,0x0e,0x8e,0xad,0x0c,0xa4, 0xad,0x8c,0x2e,0x8c,0x0d,0xc4,0xae,0x4c,0x6e,0x2e,0xed,0xcd,0x0d,0x64,0x46,0x06, 0x46,0x66,0xc6,0x65,0x66,0xa6,0x06,0x04,0xa5,0xad,0x8c,0x2e,0x8c,0xcd,0xac,0xac, 0x65,0x46,0x06,0x46,0x66,0xc6,0x65,0x66,0xa6,0x26,0x65,0x88,0x80,0x10,0x43,0x8c, 0x24,0x48,0x86,0x44,0x60,0xd1,0x54,0x46,0x17,0xc6,0x36,0x04,0x41,0x8e,0x24,0x48, 0x82,0x44,0xe0,0x16,0x96,0x26,0xe7,0x32,0xf6,0xd6,0x06,0x97,0xc6,0x56,0xe6,0x42, 0x56,0xe6,0xf6,0x26,0xd7,0x36,0xf7,0x45,0x96,0x36,0x17,0x26,0xc6,0x56,0x36,0x44, 0x40,0x12,0x72,0x61,0x69,0x72,0x2e,0x63,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x2e,0x66, 0x61,0x73,0x74,0x5f,0x6d,0x61,0x74,0x68,0x5f,0x65,0x6e,0x61,0x62,0x6c,0x65,0x43, 0x04,0x64,0x61,0x19,0x84,0xa5,0xc9,0xb9,0x8c,0xbd,0xb5,0xc1,0xa5,0xb1,0x95,0xb9, 0x98,0xc9,0x85,0xb5,0x95,0x89,0xd5,0x99,0x99,0x95,0xc9,0x7d,0x99,0x95,0xd1,0x8d, 0xa1,0x7d,0x91,0xa5,0xcd,0x85,0x89,0xb1,0x95,0x0d,0x11,0x90,0x86,0x51,0x58,0x9a, 0x9c,0x8b,0x5d,0x99,0x1c,0x5d,0x19,0xde,0xd7,0x5b,0x1d,0x1d,0x5c,0x1d,0x1d,0x97, 0xba,0xb9,0x32,0x39,0x14,0xb6,0xb7,0x31,0x37,0x98,0x14,0x46,0x61,0x69,0x72,0x2e, 0x61,0x72,0x67,0x5f,0x74,0x79,0x70,0x65,0x5f,0x6e,0x61,0x6d,0x65,0x34,0xcc,0xd8, 0xde,0xc2,0xe8,0x64,0xc8,0x84,0xa5,0xc9,0xb9,0x84,0xc9,0x9d,0x7d,0xb9,0x85,0xb5, 0x95,0x51,0xa8,0xb3,0x1b,0xc2,0x20,0x0f,0x02,0x21,0x11,0x22,0x21,0x13,0x42,0x71, 0xa9,0x9b,0x2b,0x93,0x43,0x61,0x7b,0x1b,0x73,0x8b,0x49,0xa1,0x61,0xc6,0xf6,0x16, 0x46,0x47,0xc3,0x62,0xec,0x8d,0xed,0x4d,0x6e,0x08,0x83,0x3c,0x88,0x85,0x44,0xc8, 0x85,0x4c,0x08,0x46,0x26,0x2c,0x4d,0xce,0x05,0xee,0x6d,0x2e,0x8d,0x2e,0xed,0xcd, 0x8d,0xcb,0x19,0xdb,0x17,0xd4,0xdb,0x5c,0x1a,0x5d,0xda,0x9b,0xdb,0x10,0x05,0xd1, 0x90,0x08,0xb9,0x90,0x09,0xd9,0x86,0x18,0x48,0x85,0x64,0x08,0x47,0x28,0x2c,0x4d, 0xce,0xc5,0xae,0x4c,0x8e,0xae,0x0c,0xef,0x2b,0xcd,0x0d,0xae,0x8e,0x8e,0x52,0x58, 0x9a,0x9c,0x0b,0xdb,0xdb,0x58,0x18,0x5d,0xda,0x9b,0xdb,0x57,0x9a,0x1b,0x59,0x19, 0x1e,0xbd,0xb3,0x32,0xb7,0x32,0xb9,0x30,0xba,0x32,0x32,0x94,0xaf,0xaf,0xb0,0x34, 0xb9,0x2f,0x38,0xb6,0xb0,0xb1,0x32,0xb4,0x37,0x36,0xb2,0x32,0xb9,0xaf,0xaf,0x14, 0x22,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x43,0xa8,0x44,0x40,0x3c,0xe4,0x4b, 0x84,0x24,0x40,0xc0,0x00,0x89,0x10,0x09,0x99,0x90,0x30,0x60,0x42,0x57,0x86,0x37, 0xf6,0xf6,0x26,0x47,0x06,0x33,0x84,0x4a,0x02,0xc4,0x43,0xbe,0x24,0x48,0x02,0x04, 0x0c,0x90,0x08,0x91,0x90,0x09,0x19,0x03,0x1a,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x43, 0xa8,0x84,0x40,0x3c,0xe4,0x4b,0x88,0x24,0x40,0xc0,0x00,0x89,0x90,0x0b,0x99,0x90, 0x32,0xa0,0x12,0x96,0x26,0xe7,0x22,0x56,0x67,0x66,0x56,0x26,0xc7,0x27,0x2c,0x4d, 0xce,0x45,0xac,0xce,0xcc,0xac,0x4c,0xee,0x6b,0x2e,0x4d,0xaf,0x8c,0x48,0x58,0x9a, 0x9c,0x8b,0x5c,0x59,0x18,0x19,0xa9,0xb0,0x34,0x39,0x97,0x39,0x3a,0xb9,0xba,0x31, 0xba,0x2f,0xba,0x3c,0xb8,0xb2,0xaf,0x34,0x37,0xb3,0x37,0x26,0x64,0x69,0x73,0x70, 0x5f,0x73,0x69,0x7a,0x65,0x43,0x94,0x44,0x48,0x86,0x44,0x40,0x24,0x64,0x0d,0x18, 0x85,0xa5,0xc9,0xb9,0x84,0xc9,0x9d,0x7d,0xd1,0xe5,0xc1,0x95,0x7d,0xcd,0xa5,0xe9, 0x95,0xf1,0x0a,0x4b,0x93,0x73,0x09,0x93,0x3b,0xfb,0xa2,0xcb,0x83,0x2b,0xfb,0x0a, 0x63,0x4b,0x3b,0x73,0xfb,0x9a,0x4b,0xd3,0x2b,0x63,0x62,0x37,0xf7,0x05,0x17,0x26, 0x17,0xd6,0x36,0xc7,0xe1,0x4b,0x46,0x66,0x08,0x19,0x24,0x06,0x72,0x06,0x08,0x1a, 0x24,0x03,0xf2,0x25,0x42,0x12,0x20,0x69,0x80,0xa8,0x01,0xc2,0x06,0x48,0x1b,0x24, 0x03,0xe2,0x06,0xc9,0x80,0x44,0xc8,0x1b,0x20,0x13,0x02,0x07,0x43,0x10,0x44,0x0c, 0x10,0x32,0x40,0xcc,0x00,0x89,0x83,0x21,0xc6,0x01,0x20,0x1d,0x22,0x07,0x7c,0xde, 0xda,0xdc,0xd2,0xe0,0xde,0xe8,0xca,0xdc,0xe8,0x40,0xc6,0xd0,0xc2,0xe4,0xf8,0x4c, 0xa5,0xb5,0xc1,0xb1,0x95,0x81,0x0c,0xad,0xac,0x80,0x50,0x09,0x05,0x05,0x0d,0x11, 0x90,0x3a,0x18,0x62,0x20,0x74,0x80,0xd8,0xc1,0x72,0x0c,0x31,0x90,0x3b,0x40,0xee, 0x60,0x39,0x46,0x44,0xec,0xc0,0x0e,0xf6,0xd0,0x0e,0x6e,0xd0,0x0e,0xef,0x40,0x0e, 0xf5,0xc0,0x0e,0xe5,0xe0,0x06,0xe6,0xc0,0x0e,0xe1,0x70,0x0e,0xf3,0x30,0x45,0x08, 0x86,0x11,0x0a,0x3b,0xb0,0x83,0x3d,0xb4,0x83,0x1b,0xa4,0x03,0x39,0x94,0x83,0x3b, 0xd0,0xc3,0x94,0xa0,0x18,0xb1,0x84,0x43,0x3a,0xc8,0x83,0x1b,0xd8,0x43,0x39,0xc8, 0xc3,0x3c,0xa4,0xc3,0x3b,0xb8,0xc3,0x94,0xc0,0x18,0x41,0x85,0x43,0x3a,0xc8,0x83, 0x1b,0xb0,0x43,0x38,0xb8,0xc3,0x39,0xd4,0x43,0x38,0x9c,0x43,0x39,0xfc,0x82,0x3d, 0x94,0x83,0x3c,0xcc,0x43,0x3a,0xbc,0x83,0x3b,0x4c,0x09,0x90,0x11,0x53,0x38,0xa4, 0x83,0x3c,0xb8,0xc1,0x38,0xbc,0x43,0x3b,0xc0,0x43,0x3a,0xb0,0x43,0x39,0xfc,0xc2, 0x3b,0xc0,0x03,0x3d,0xa4,0xc3,0x3b,0xb8,0xc3,0x3c,0x4c,0x19,0x14,0xc6,0x19,0xa1, 0x84,0x43,0x3a,0xc8,0x83,0x1b,0xd8,0x43,0x39,0xc8,0x03,0x3d,0x94,0x03,0x3e,0x4c, 0x09,0xe6,0x00,0x00,0x79,0x18,0x00,0x00,0xa5,0x00,0x00,0x00,0x33,0x08,0x80,0x1c, 0xc4,0xe1,0x1c,0x66,0x14,0x01,0x3d,0x88,0x43,0x38,0x84,0xc3,0x8c,0x42,0x80,0x07, 0x79,0x78,0x07,0x73,0x98,0x71,0x0c,0xe6,0x00,0x0f,0xed,0x10,0x0e,0xf4,0x80,0x0e, 0x33,0x0c,0x42,0x1e,0xc2,0xc1,0x1d,0xce,0xa1,0x1c,0x66,0x30,0x05,0x3d,0x88,0x43, 0x38,0x84,0x83,0x1b,0xcc,0x03,0x3d,0xc8,0x43,0x3d,0x8c,0x03,0x3d,0xcc,0x78,0x8c, 0x74,0x70,0x07,0x7b,0x08,0x07,0x79,0x48,0x87,0x70,0x70,0x07,0x7a,0x70,0x03,0x76, 0x78,0x87,0x70,0x20,0x87,0x19,0xcc,0x11,0x0e,0xec,0x90,0x0e,0xe1,0x30,0x0f,0x6e, 0x30,0x0f,0xe3,0xf0,0x0e,0xf0,0x50,0x0e,0x33,0x10,0xc4,0x1d,0xde,0x21,0x1c,0xd8, 0x21,0x1d,0xc2,0x61,0x1e,0x66,0x30,0x89,0x3b,0xbc,0x83,0x3b,0xd0,0x43,0x39,0xb4, 0x03,0x3c,0xbc,0x83,0x3c,0x84,0x03,0x3b,0xcc,0xf0,0x14,0x76,0x60,0x07,0x7b,0x68, 0x07,0x37,0x68,0x87,0x72,0x68,0x07,0x37,0x80,0x87,0x70,0x90,0x87,0x70,0x60,0x07, 0x76,0x28,0x07,0x76,0xf8,0x05,0x76,0x78,0x87,0x77,0x80,0x87,0x5f,0x08,0x87,0x71, 0x18,0x87,0x72,0x98,0x87,0x79,0x98,0x81,0x2c,0xee,0xf0,0x0e,0xee,0xe0,0x0e,0xf5, 0xc0,0x0e,0xec,0x30,0x03,0x62,0xc8,0xa1,0x1c,0xe4,0xa1,0x1c,0xcc,0xa1,0x1c,0xe4, 0xa1,0x1c,0xdc,0x61,0x1c,0xca,0x21,0x1c,0xc4,0x81,0x1d,0xca,0x61,0x06,0xd6,0x90, 0x43,0x39,0xc8,0x43,0x39,0x98,0x43,0x39,0xc8,0x43,0x39,0xb8,0xc3,0x38,0x94,0x43, 0x38,0x88,0x03,0x3b,0x94,0xc3,0x2f,0xbc,0x83,0x3c,0xfc,0x82,0x3b,0xd4,0x03,0x3b, 0xb0,0xc3,0x0c,0xc7,0x69,0x87,0x70,0x58,0x87,0x72,0x70,0x83,0x74,0x68,0x07,0x78, 0x60,0x87,0x74,0x18,0x87,0x74,0xa0,0x87,0x19,0xce,0x53,0x0f,0xee,0x00,0x0f,0xf2, 0x50,0x0e,0xe4,0x90,0x0e,0xe3,0x40,0x0f,0xe1,0x20,0x0e,0xec,0x50,0x0e,0x33,0x20, 0x28,0x1d,0xdc,0xc1,0x1e,0xc2,0x41,0x1e,0xd2,0x21,0x1c,0xdc,0x81,0x1e,0xdc,0xe0, 0x1c,0xe4,0xe1,0x1d,0xea,0x01,0x1e,0x66,0x18,0x51,0x38,0xb0,0x43,0x3a,0x9c,0x83, 0x3b,0xcc,0x50,0x24,0x76,0x60,0x07,0x7b,0x68,0x07,0x37,0x60,0x87,0x77,0x78,0x07, 0x78,0x98,0x51,0x4c,0xf4,0x90,0x0f,0xf0,0x50,0x0e,0x33,0x1e,0x6a,0x1e,0xca,0x61, 0x1c,0xe8,0x21,0x1d,0xde,0xc1,0x1d,0x7e,0x01,0x1e,0xe4,0xa1,0x1c,0xcc,0x21,0x1d, 0xf0,0x61,0x06,0x54,0x85,0x83,0x38,0xcc,0xc3,0x3b,0xb0,0x43,0x3d,0xd0,0x43,0x39, 0xfc,0xc2,0x3c,0xe4,0x43,0x3b,0x88,0xc3,0x3b,0xb0,0xc3,0x8c,0xc5,0x0a,0x87,0x79, 0x98,0x87,0x77,0x18,0x87,0x74,0x08,0x07,0x7a,0x28,0x07,0x72,0x98,0x81,0x5c,0xe3, 0x10,0x0e,0xec,0xc0,0x0e,0xe5,0x50,0x0e,0xf3,0x30,0x23,0xc1,0xd2,0x41,0x1e,0xe4, 0xe1,0x17,0xd8,0xe1,0x1d,0xde,0x01,0x1e,0x66,0x48,0x19,0x3b,0xb0,0x83,0x3d,0xb4, 0x83,0x1b,0x84,0xc3,0x38,0x8c,0x43,0x39,0xcc,0xc3,0x3c,0xb8,0xc1,0x39,0xc8,0xc3, 0x3b,0xd4,0x03,0x3c,0xcc,0x48,0xb4,0x71,0x08,0x07,0x76,0x60,0x07,0x71,0x08,0x87, 0x71,0x58,0x87,0x19,0xdb,0xc6,0x0e,0xec,0x60,0x0f,0xed,0xe0,0x06,0xf0,0x20,0x0f, 0xe5,0x30,0x0f,0xe5,0x20,0x0f,0xf6,0x50,0x0e,0x6e,0x10,0x0e,0xe3,0x30,0x0e,0xe5, 0x30,0x0f,0xf3,0xe0,0x06,0xe9,0xe0,0x0e,0xe4,0x50,0x0e,0xf8,0x30,0x23,0xe2,0xec, 0x61,0x1c,0xc2,0x81,0x1d,0xd8,0xe1,0x17,0xec,0x21,0x1d,0xe6,0x21,0x1d,0xc4,0x21, 0x1d,0xd8,0x21,0x1d,0xe8,0x21,0x1f,0x66,0x20,0x9d,0x3b,0xbc,0x43,0x3d,0xb8,0x03, 0x39,0x94,0x83,0x39,0xcc,0x58,0xbc,0x70,0x70,0x07,0x77,0x78,0x07,0x7a,0x08,0x07, 0x7a,0x48,0x87,0x77,0x70,0x87,0x19,0xce,0x87,0x0e,0xe5,0x10,0x0e,0xf0,0x10,0x0e, 0xec,0xc0,0x0e,0xef,0x30,0x0e,0xf3,0x90,0x0e,0xf4,0x50,0x0e,0x33,0x28,0x30,0x08, 0x87,0x74,0x90,0x07,0x37,0x30,0x87,0x7a,0x70,0x87,0x71,0xa0,0x87,0x74,0x78,0x07, 0x77,0xf8,0x85,0x73,0x90,0x87,0x77,0xa8,0x07,0x78,0x98,0x07,0x00,0x00,0x00,0x00, 0x71,0x20,0x00,0x00,0x02,0x00,0x00,0x00,0x06,0x50,0x30,0x00,0xd2,0xd0,0x00,0x00, 0x61,0x20,0x00,0x00,0x23,0x00,0x00,0x00,0x13,0x04,0x41,0x2c,0x10,0x00,0x00,0x00, 0x11,0x00,0x00,0x00,0xd4,0x63,0x11,0x40,0x60,0x1c,0x73,0x10,0x42,0xf0,0x3c,0x94, 0x33,0x00,0x14,0x63,0x09,0x20,0x08,0x82,0xf0,0x2f,0x80,0x20,0x08,0xc2,0xbf,0x30, 0x96,0x00,0x82,0x20,0x08,0x82,0x01,0x08,0x82,0x20,0x08,0x0e,0x33,0x00,0x24,0x73, 0x10,0xd7,0x65,0x55,0x34,0x33,0x00,0x04,0x63,0x04,0x20,0x08,0x82,0xf8,0x37,0x46, 0x00,0x82,0x20,0x08,0x7f,0x33,0x00,0x00,0xe3,0x0d,0x4c,0x64,0x51,0x40,0x2c,0x0a, 0xe8,0x63,0xc1,0x02,0x1f,0x0b,0x16,0xf9,0x0c,0x32,0x04,0xcb,0x33,0xc8,0x10,0x2c, 0xd1,0x6c,0xc3,0x52,0x01,0xb3,0x0d,0x41,0x15,0xcc,0x36,0x04,0x83,0x90,0x41,0x40, 0x0c,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x5b,0x86,0x20,0xc0,0x03,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; /* Metal Fragment Shader (macOS) */ static const uint8_t nk_fs_bytecode_metal_macos[3017] = { 0x4d,0x54,0x4c,0x42,0x01,0x80,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xc9,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x6d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc9,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xd1,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xd9,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xf0,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x6d,0x00,0x00,0x00, 0x4e,0x41,0x4d,0x45,0x06,0x00,0x6d,0x61,0x69,0x6e,0x30,0x00,0x54,0x59,0x50,0x45, 0x01,0x00,0x01,0x48,0x41,0x53,0x48,0x20,0x00,0xfe,0x1f,0x5f,0xc4,0x3f,0x2d,0xaa, 0xe1,0x41,0x06,0x1f,0xeb,0x88,0x3c,0x97,0xdd,0x86,0x1d,0xfa,0x9c,0xc7,0x3f,0xac, 0x4b,0x2b,0x8c,0xa0,0x89,0xf7,0x13,0x77,0xee,0x4f,0x46,0x46,0x54,0x18,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x56,0x45,0x52,0x53,0x08,0x00,0x01,0x00,0x08, 0x00,0x01,0x00,0x01,0x00,0x45,0x4e,0x44,0x54,0x04,0x00,0x00,0x00,0x45,0x4e,0x44, 0x54,0x04,0x00,0x00,0x00,0x45,0x4e,0x44,0x54,0xde,0xc0,0x17,0x0b,0x00,0x00,0x00, 0x00,0x14,0x00,0x00,0x00,0xdc,0x0a,0x00,0x00,0xff,0xff,0xff,0xff,0x42,0x43,0xc0, 0xde,0x21,0x0c,0x00,0x00,0xb4,0x02,0x00,0x00,0x0b,0x82,0x20,0x00,0x02,0x00,0x00, 0x00,0x12,0x00,0x00,0x00,0x07,0x81,0x23,0x91,0x41,0xc8,0x04,0x49,0x06,0x10,0x32, 0x39,0x92,0x01,0x84,0x0c,0x25,0x05,0x08,0x19,0x1e,0x04,0x8b,0x62,0x80,0x14,0x45, 0x02,0x42,0x92,0x0b,0x42,0xa4,0x10,0x32,0x14,0x38,0x08,0x18,0x49,0x0a,0x32,0x44, 0x24,0x48,0x0a,0x90,0x21,0x23,0xc4,0x52,0x80,0x0c,0x19,0x21,0x72,0x24,0x07,0xc8, 0x48,0x11,0x62,0xa8,0xa0,0xa8,0x40,0xc6,0xf0,0x01,0x00,0x00,0x00,0x51,0x18,0x00, 0x00,0x74,0x00,0x00,0x00,0x1b,0xc2,0x24,0xf8,0xff,0xff,0xff,0xff,0x01,0x60,0x00, 0x09,0xa8,0x88,0x70,0x80,0x07,0x78,0x90,0x87,0x77,0xc0,0x87,0x36,0x30,0x87,0x7a, 0x70,0x87,0x71,0x68,0x03,0x73,0x80,0x87,0x36,0x68,0x87,0x70,0xa0,0x07,0x74,0x00, 0xe8,0x41,0x1e,0xea,0xa1,0x1c,0x00,0xa2,0x1d,0xd2,0xc1,0x1d,0xda,0x80,0x1d,0xca, 0xe1,0x1c,0xc2,0x81,0x1d,0xda,0xc0,0x1e,0xca,0x61,0x1c,0xe8,0xe1,0x1d,0xe4,0xa1, 0x0d,0xee,0x21,0x1d,0xc8,0x81,0x1e,0xd0,0x01,0x88,0x03,0x39,0xc0,0x03,0x60,0x70, 0x87,0x77,0x68,0x03,0x71,0xa8,0x87,0x74,0x60,0x07,0x7a,0x48,0x07,0x77,0x98,0x07, 0x80,0x70,0x87,0x77,0x68,0x03,0x73,0x90,0x87,0x70,0x68,0x87,0x72,0x68,0x03,0x78, 0x78,0x87,0x74,0x70,0x07,0x7a,0x28,0x07,0x79,0x68,0x83,0x72,0x60,0x87,0x74,0x68, 0x07,0x80,0x1e,0xe4,0xa1,0x1e,0xca,0x01,0x20,0xdc,0xe1,0x1d,0xda,0xc0,0x1c,0xe4, 0x21,0x1c,0xda,0xa1,0x1c,0xda,0x00,0x1e,0xde,0x21,0x1d,0xdc,0x81,0x1e,0xca,0x41, 0x1e,0xda,0xa0,0x1c,0xd8,0x21,0x1d,0xda,0xa1,0x0d,0xdc,0xe1,0x1d,0xdc,0xa1,0x0d, 0xd8,0xa1,0x1c,0xc2,0xc1,0x1c,0x00,0x7a,0x90,0x87,0x7a,0x28,0x07,0x80,0x70,0x87, 0x77,0x68,0x83,0x74,0x70,0x07,0x73,0x98,0x87,0x36,0x30,0x07,0x78,0x68,0x83,0x76, 0x08,0x07,0x7a,0x40,0x07,0x80,0x1e,0xe4,0xa1,0x1e,0xca,0x01,0x20,0xdc,0xe1,0x1d, 0xda,0xc0,0x1d,0xc2,0xc1,0x1d,0xe6,0xa1,0x0d,0xcc,0x01,0x1e,0xda,0xa0,0x1d,0xc2, 0x81,0x1e,0xd0,0x01,0xa0,0x07,0x79,0xa8,0x87,0x72,0x00,0x08,0x77,0x78,0x87,0x36, 0x98,0x87,0x74,0x38,0x07,0x77,0x28,0x07,0x72,0x68,0x03,0x7d,0x28,0x07,0x79,0x78, 0x87,0x79,0x68,0x03,0x73,0x80,0x87,0x36,0x68,0x87,0x70,0xa0,0x07,0x74,0x00,0xe8, 0x41,0x1e,0xea,0xa1,0x1c,0x00,0xc2,0x1d,0xde,0xa1,0x0d,0xe8,0x41,0x1e,0xc2,0x01, 0x1e,0xe0,0x21,0x1d,0xdc,0xe1,0x1c,0xda,0xa0,0x1d,0xc2,0x81,0x1e,0xd0,0x01,0xa0, 0x07,0x79,0xa8,0x87,0x72,0x00,0x88,0x79,0xa0,0x87,0x70,0x18,0x87,0x75,0x68,0x03, 0x78,0x90,0x87,0x77,0xa0,0x87,0x72,0x18,0x07,0x7a,0x78,0x07,0x79,0x68,0x03,0x71, 0xa8,0x07,0x73,0x30,0x87,0x72,0x90,0x87,0x36,0x98,0x87,0x74,0xd0,0x87,0x72,0x00, 0xf0,0x00,0x20,0xea,0xc1,0x1d,0xe6,0x21,0x1c,0xcc,0xa1,0x1c,0xda,0xc0,0x1c,0xe0, 0xa1,0x0d,0xda,0x21,0x1c,0xe8,0x01,0x1d,0x00,0x7a,0x90,0x87,0x7a,0x28,0x07,0x60, 0x83,0x21,0x0c,0xc0,0x02,0x54,0x1b,0x8c,0x81,0x00,0x16,0xa0,0xda,0x80,0x10,0xff, 0xff,0xff,0xff,0x3f,0x00,0x0c,0x20,0x01,0xd5,0x06,0xa3,0x08,0x80,0x05,0xa8,0x36, 0x18,0x86,0x00,0x2c,0x40,0xb5,0x01,0x39,0xfe,0xff,0xff,0xff,0x7f,0x00,0x18,0x40, 0x02,0x2a,0x00,0x00,0x00,0x49,0x18,0x00,0x00,0x04,0x00,0x00,0x00,0x13,0x86,0x40, 0x18,0x26,0x0c,0x44,0x61,0x4c,0x18,0x8e,0xc2,0x00,0x00,0x00,0x00,0x89,0x20,0x00, 0x00,0x1d,0x00,0x00,0x00,0x32,0x22,0x48,0x09,0x20,0x64,0x85,0x04,0x93,0x22,0xa4, 0x84,0x04,0x93,0x22,0xe3,0x84,0xa1,0x90,0x14,0x12,0x4c,0x8a,0x8c,0x0b,0x84,0xa4, 0x4c,0x10,0x48,0x33,0x00,0xc3,0x08,0x04,0x60,0x83,0x30,0x8c,0x20,0x00,0x47,0x49, 0x53,0x44,0x09,0x93,0xff,0x4f,0xc4,0x35,0x51,0x11,0xf1,0xdb,0xc3,0x3f,0x8d,0x11, 0x00,0x83,0x08,0x44,0x70,0x91,0x34,0x45,0x94,0x30,0xf9,0xbf,0x04,0x30,0xcf,0x42, 0x44,0xff,0x34,0x46,0x00,0x0c,0x22,0x18,0x42,0x29,0xc4,0x08,0xe5,0x10,0x9a,0x23, 0x08,0xe6,0x08,0xc0,0x60,0x18,0x41,0x58,0x0a,0x12,0xca,0x19,0x8a,0x29,0x40,0x6d, 0x20,0x20,0x05,0xd6,0x08,0x00,0x00,0x00,0x00,0x13,0xb2,0x70,0x48,0x07,0x79,0xb0, 0x03,0x3a,0x68,0x83,0x70,0x80,0x07,0x78,0x60,0x87,0x72,0x68,0x83,0x76,0x08,0x87, 0x71,0x78,0x87,0x79,0xc0,0x87,0x38,0x80,0x03,0x37,0x88,0x83,0x38,0x70,0x03,0x38, 0xd8,0x70,0x1b,0xe5,0xd0,0x06,0xf0,0xa0,0x07,0x76,0x40,0x07,0x7a,0x60,0x07,0x74, 0xa0,0x07,0x76,0x40,0x07,0x6d,0x90,0x0e,0x71,0xa0,0x07,0x78,0xa0,0x07,0x78,0xd0, 0x06,0xe9,0x80,0x07,0x7a,0x80,0x07,0x7a,0x80,0x07,0x6d,0x90,0x0e,0x71,0x60,0x07, 0x7a,0x10,0x07,0x76,0xa0,0x07,0x71,0x60,0x07,0x6d,0x90,0x0e,0x73,0x20,0x07,0x7a, 0x30,0x07,0x72,0xa0,0x07,0x73,0x20,0x07,0x6d,0x90,0x0e,0x76,0x40,0x07,0x7a,0x60, 0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x6d,0x60,0x0e,0x73,0x20,0x07,0x7a,0x30,0x07, 0x72,0xa0,0x07,0x73,0x20,0x07,0x6d,0x60,0x0e,0x76,0x40,0x07,0x7a,0x60,0x07,0x74, 0xa0,0x07,0x76,0x40,0x07,0x6d,0x60,0x0f,0x71,0x60,0x07,0x7a,0x10,0x07,0x76,0xa0, 0x07,0x71,0x60,0x07,0x6d,0x60,0x0f,0x72,0x40,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07, 0x73,0x20,0x07,0x6d,0x60,0x0f,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xa0,0x07,0x73, 0x20,0x07,0x6d,0x60,0x0f,0x74,0x80,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40, 0x07,0x6d,0x60,0x0f,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07, 0x6d,0x60,0x0f,0x79,0x60,0x07,0x7a,0x10,0x07,0x72,0x80,0x07,0x7a,0x10,0x07,0x72, 0x80,0x07,0x6d,0x60,0x0f,0x71,0x20,0x07,0x78,0xa0,0x07,0x71,0x20,0x07,0x78,0xa0, 0x07,0x71,0x20,0x07,0x78,0xd0,0x06,0xf6,0x10,0x07,0x79,0x20,0x07,0x7a,0x20,0x07, 0x75,0x60,0x07,0x7a,0x20,0x07,0x75,0x60,0x07,0x6d,0x60,0x0f,0x72,0x50,0x07,0x76, 0xa0,0x07,0x72,0x50,0x07,0x76,0xa0,0x07,0x72,0x50,0x07,0x76,0xd0,0x06,0xf6,0x50, 0x07,0x71,0x20,0x07,0x7a,0x50,0x07,0x71,0x20,0x07,0x7a,0x50,0x07,0x71,0x20,0x07, 0x6d,0x60,0x0f,0x71,0x00,0x07,0x72,0x40,0x07,0x7a,0x10,0x07,0x70,0x20,0x07,0x74, 0xa0,0x07,0x71,0x00,0x07,0x72,0x40,0x07,0x6d,0xe0,0x0e,0x78,0xa0,0x07,0x71,0x60, 0x07,0x7a,0x30,0x07,0x72,0x30,0x84,0x49,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00, 0x18,0xc2,0x38,0x40,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x64,0x81,0x00,0x00,0x00, 0x00,0x08,0x00,0x00,0x00,0x32,0x1e,0x98,0x10,0x19,0x11,0x4c,0x90,0x8c,0x09,0x26, 0x47,0xc6,0x04,0x43,0x5a,0x25,0x30,0x02,0x50,0x04,0x85,0x50,0x10,0x65,0x40,0x70, 0x2c,0xe1,0x01,0x00,0x00,0x79,0x18,0x00,0x00,0xd2,0x00,0x00,0x00,0x1a,0x03,0x4c, 0x10,0x97,0x29,0xa2,0x25,0x10,0xab,0x32,0xb9,0xb9,0xb4,0x37,0xb7,0x21,0xc6,0x42, 0x3c,0x00,0x84,0x50,0xb9,0x1b,0x43,0x0b,0x93,0xfb,0x9a,0x4b,0xd3,0x2b,0x1b,0x62, 0x2c,0xc2,0x23,0x2c,0x05,0xe3,0x20,0x08,0x0e,0x8e,0xad,0x0c,0xa4,0xad,0x8c,0x2e, 0x8c,0x0d,0xc4,0xae,0x4c,0x6e,0x2e,0xed,0xcd,0x0d,0x64,0x46,0x06,0x46,0x66,0xc6, 0x65,0x66,0xa6,0x06,0x04,0xa5,0xad,0x8c,0x2e,0x8c,0xcd,0xac,0xac,0x65,0x46,0x06, 0x46,0x66,0xc6,0x65,0x66,0xa6,0x26,0x65,0x88,0xf0,0x10,0x43,0x8c,0x45,0x58,0x8c, 0x65,0x60,0xd1,0x54,0x46,0x17,0xc6,0x36,0x04,0x79,0x8e,0x45,0x58,0x84,0x65,0xe0, 0x16,0x96,0x26,0xe7,0x32,0xf6,0xd6,0x06,0x97,0xc6,0x56,0xe6,0x42,0x56,0xe6,0xf6, 0x26,0xd7,0x36,0xf7,0x45,0x96,0x36,0x17,0x26,0xc6,0x56,0x36,0x44,0x78,0x12,0x72, 0x61,0x69,0x72,0x2e,0x63,0x6f,0x6d,0x70,0x69,0x6c,0x65,0x2e,0x66,0x61,0x73,0x74, 0x5f,0x6d,0x61,0x74,0x68,0x5f,0x65,0x6e,0x61,0x62,0x6c,0x65,0x43,0x84,0x67,0x61, 0x19,0x84,0xa5,0xc9,0xb9,0x8c,0xbd,0xb5,0xc1,0xa5,0xb1,0x95,0xb9,0x98,0xc9,0x85, 0xb5,0x95,0x89,0xd5,0x99,0x99,0x95,0xc9,0x7d,0x99,0x95,0xd1,0x8d,0xa1,0x7d,0x91, 0xa5,0xcd,0x85,0x89,0xb1,0x95,0x0d,0x11,0x9e,0x86,0x51,0x58,0x9a,0x9c,0x8b,0x5c, 0x99,0x1b,0x59,0x99,0xdc,0x17,0x5d,0x98,0xdc,0x59,0x19,0x1d,0xa3,0xb0,0x34,0x39, 0x97,0x30,0xb9,0xb3,0x2f,0xba,0x3c,0xb8,0xb2,0x2f,0xb7,0xb0,0xb6,0x32,0x1a,0x66, 0x6c,0x6f,0x61,0x74,0x34,0x64,0xc2,0xd2,0xe4,0x5c,0xc2,0xe4,0xce,0xbe,0xdc,0xc2, 0xda,0xca,0xa8,0x98,0xc9,0x85,0x9d,0x7d,0x8d,0xbd,0xb1,0xbd,0xc9,0x0d,0x61,0x9e, 0x67,0x19,0x1e,0xe8,0x89,0x1e,0xe9,0x99,0x86,0x08,0x0f,0x45,0x29,0x2c,0x4d,0xce, 0xc5,0x4c,0x2e,0xec,0xac,0xad,0xcc,0x8d,0xee,0x2b,0xcd,0x0d,0xae,0x8e,0x8e,0x4b, 0xdd,0x5c,0x99,0x1c,0x0a,0xdb,0xdb,0x98,0x1b,0x4c,0x0a,0x95,0xb0,0x34,0x39,0x97, 0xb1,0x32,0x37,0xba,0x32,0x39,0x3e,0x61,0x69,0x72,0x2e,0x70,0x65,0x72,0x73,0x70, 0x65,0x63,0x74,0x69,0x76,0x65,0x34,0xcc,0xd8,0xde,0xc2,0xe8,0x64,0x28,0xd4,0xd9, 0x0d,0x91,0x96,0xe1,0xb1,0x9e,0xeb,0xc1,0x9e,0xec,0x81,0x1e,0xed,0x91,0x9e,0x8d, 0x4b,0xdd,0x5c,0x99,0x1c,0x0a,0xdb,0xdb,0x98,0x5b,0x4c,0x0a,0x8b,0xb1,0x37,0xb6, 0x37,0xb9,0x21,0xd2,0x22,0x3c,0xd6,0xd3,0x3d,0xd8,0x93,0x3d,0xd0,0x13,0x3d,0xd2, 0xe3,0x71,0x09,0x4b,0x93,0x73,0xa1,0x2b,0xc3,0xa3,0xab,0x93,0x2b,0xa3,0x14,0x96, 0x26,0xe7,0xc2,0xf6,0x36,0x16,0x46,0x97,0xf6,0xe6,0xf6,0x95,0xe6,0x46,0x56,0x86, 0x47,0x25,0x2c,0x4d,0xce,0x65,0x2e,0xac,0x0d,0x8e,0xad,0x8c,0x18,0x5d,0x19,0x1e, 0x5d,0x9d,0x5c,0x99,0x0c,0x19,0x8f,0x19,0xdb,0x5b,0x18,0x1d,0x0b,0xc8,0x5c,0x58, 0x1b,0x1c,0x5b,0x99,0x0f,0x07,0xba,0x32,0xbc,0x21,0xd4,0x42,0x3c,0x60,0xf0,0x84, 0xc1,0x32,0x2c,0xc2,0x23,0x06,0x0f,0xf4,0x8c,0xc1,0x23,0x3d,0x64,0xc0,0x25,0x2c, 0x4d,0xce,0x65,0x2e,0xac,0x0d,0x8e,0xad,0x4c,0x8e,0xc7,0x5c,0x58,0x1b,0x1c,0x5b, 0x99,0x1c,0x87,0xb9,0x36,0xb8,0x21,0xd2,0x72,0x3c,0x66,0xf0,0x84,0xc1,0x32,0x2c, 0xc2,0x03,0x3d,0x67,0xf0,0x48,0x0f,0x1a,0x0c,0x41,0x1e,0xee,0xf9,0x9e,0x32,0x78, 0xd2,0x60,0x88,0x91,0x00,0x4f,0xf5,0xa8,0x01,0xaf,0xb0,0x34,0xb9,0x96,0x30,0xb6, 0xb4,0xb0,0xb9,0x96,0xb9,0xb1,0x37,0xb8,0xb2,0x39,0x94,0xb6,0xb0,0x34,0x37,0x98, 0x94,0x21,0xc4,0xd3,0x06,0x0f,0x1b,0x10,0x0b,0x4b,0x93,0x6b,0x09,0x63,0x4b,0x0b, 0x9b,0x6b,0x99,0x1b,0x7b,0x83,0x2b,0x6b,0xa1,0x2b,0xc3,0xa3,0xab,0x93,0x2b,0x9b, 0x1b,0x62,0x3c,0x6f,0xf0,0xb4,0xc1,0xe3,0x06,0xc4,0xc2,0xd2,0xe4,0x5a,0xc2,0xd8, 0xd2,0xc2,0xe6,0x5a,0xe6,0xc6,0xde,0xe0,0xca,0x5a,0xe6,0xc2,0xda,0xe0,0xd8,0xca, 0xe4,0xe6,0x86,0x18,0x4f,0x1c,0x3c,0x6d,0xf0,0xc0,0xc1,0x10,0xe2,0x79,0x83,0x27, 0x0e,0x46,0x44,0xec,0xc0,0x0e,0xf6,0xd0,0x0e,0x6e,0xd0,0x0e,0xef,0x40,0x0e,0xf5, 0xc0,0x0e,0xe5,0xe0,0x06,0xe6,0xc0,0x0e,0xe1,0x70,0x0e,0xf3,0x30,0x45,0x08,0x86, 0x11,0x0a,0x3b,0xb0,0x83,0x3d,0xb4,0x83,0x1b,0xa4,0x03,0x39,0x94,0x83,0x3b,0xd0, 0xc3,0x94,0xa0,0x18,0xb1,0x84,0x43,0x3a,0xc8,0x83,0x1b,0xd8,0x43,0x39,0xc8,0xc3, 0x3c,0xa4,0xc3,0x3b,0xb8,0xc3,0x94,0xc0,0x18,0x41,0x85,0x43,0x3a,0xc8,0x83,0x1b, 0xb0,0x43,0x38,0xb8,0xc3,0x39,0xd4,0x43,0x38,0x9c,0x43,0x39,0xfc,0x82,0x3d,0x94, 0x83,0x3c,0xcc,0x43,0x3a,0xbc,0x83,0x3b,0x4c,0x09,0x90,0x11,0x53,0x38,0xa4,0x83, 0x3c,0xb8,0xc1,0x38,0xbc,0x43,0x3b,0xc0,0x43,0x3a,0xb0,0x43,0x39,0xfc,0xc2,0x3b, 0xc0,0x03,0x3d,0xa4,0xc3,0x3b,0xb8,0xc3,0x3c,0x4c,0x19,0x14,0xc6,0x19,0xc1,0x84, 0x43,0x3a,0xc8,0x83,0x1b,0x98,0x83,0x3c,0x84,0xc3,0x39,0xb4,0x43,0x39,0xb8,0x03, 0x3d,0x4c,0x09,0xd6,0x00,0x79,0x18,0x00,0x00,0xa5,0x00,0x00,0x00,0x33,0x08,0x80, 0x1c,0xc4,0xe1,0x1c,0x66,0x14,0x01,0x3d,0x88,0x43,0x38,0x84,0xc3,0x8c,0x42,0x80, 0x07,0x79,0x78,0x07,0x73,0x98,0x71,0x0c,0xe6,0x00,0x0f,0xed,0x10,0x0e,0xf4,0x80, 0x0e,0x33,0x0c,0x42,0x1e,0xc2,0xc1,0x1d,0xce,0xa1,0x1c,0x66,0x30,0x05,0x3d,0x88, 0x43,0x38,0x84,0x83,0x1b,0xcc,0x03,0x3d,0xc8,0x43,0x3d,0x8c,0x03,0x3d,0xcc,0x78, 0x8c,0x74,0x70,0x07,0x7b,0x08,0x07,0x79,0x48,0x87,0x70,0x70,0x07,0x7a,0x70,0x03, 0x76,0x78,0x87,0x70,0x20,0x87,0x19,0xcc,0x11,0x0e,0xec,0x90,0x0e,0xe1,0x30,0x0f, 0x6e,0x30,0x0f,0xe3,0xf0,0x0e,0xf0,0x50,0x0e,0x33,0x10,0xc4,0x1d,0xde,0x21,0x1c, 0xd8,0x21,0x1d,0xc2,0x61,0x1e,0x66,0x30,0x89,0x3b,0xbc,0x83,0x3b,0xd0,0x43,0x39, 0xb4,0x03,0x3c,0xbc,0x83,0x3c,0x84,0x03,0x3b,0xcc,0xf0,0x14,0x76,0x60,0x07,0x7b, 0x68,0x07,0x37,0x68,0x87,0x72,0x68,0x07,0x37,0x80,0x87,0x70,0x90,0x87,0x70,0x60, 0x07,0x76,0x28,0x07,0x76,0xf8,0x05,0x76,0x78,0x87,0x77,0x80,0x87,0x5f,0x08,0x87, 0x71,0x18,0x87,0x72,0x98,0x87,0x79,0x98,0x81,0x2c,0xee,0xf0,0x0e,0xee,0xe0,0x0e, 0xf5,0xc0,0x0e,0xec,0x30,0x03,0x62,0xc8,0xa1,0x1c,0xe4,0xa1,0x1c,0xcc,0xa1,0x1c, 0xe4,0xa1,0x1c,0xdc,0x61,0x1c,0xca,0x21,0x1c,0xc4,0x81,0x1d,0xca,0x61,0x06,0xd6, 0x90,0x43,0x39,0xc8,0x43,0x39,0x98,0x43,0x39,0xc8,0x43,0x39,0xb8,0xc3,0x38,0x94, 0x43,0x38,0x88,0x03,0x3b,0x94,0xc3,0x2f,0xbc,0x83,0x3c,0xfc,0x82,0x3b,0xd4,0x03, 0x3b,0xb0,0xc3,0x0c,0xc7,0x69,0x87,0x70,0x58,0x87,0x72,0x70,0x83,0x74,0x68,0x07, 0x78,0x60,0x87,0x74,0x18,0x87,0x74,0xa0,0x87,0x19,0xce,0x53,0x0f,0xee,0x00,0x0f, 0xf2,0x50,0x0e,0xe4,0x90,0x0e,0xe3,0x40,0x0f,0xe1,0x20,0x0e,0xec,0x50,0x0e,0x33, 0x20,0x28,0x1d,0xdc,0xc1,0x1e,0xc2,0x41,0x1e,0xd2,0x21,0x1c,0xdc,0x81,0x1e,0xdc, 0xe0,0x1c,0xe4,0xe1,0x1d,0xea,0x01,0x1e,0x66,0x18,0x51,0x38,0xb0,0x43,0x3a,0x9c, 0x83,0x3b,0xcc,0x50,0x24,0x76,0x60,0x07,0x7b,0x68,0x07,0x37,0x60,0x87,0x77,0x78, 0x07,0x78,0x98,0x51,0x4c,0xf4,0x90,0x0f,0xf0,0x50,0x0e,0x33,0x1e,0x6a,0x1e,0xca, 0x61,0x1c,0xe8,0x21,0x1d,0xde,0xc1,0x1d,0x7e,0x01,0x1e,0xe4,0xa1,0x1c,0xcc,0x21, 0x1d,0xf0,0x61,0x06,0x54,0x85,0x83,0x38,0xcc,0xc3,0x3b,0xb0,0x43,0x3d,0xd0,0x43, 0x39,0xfc,0xc2,0x3c,0xe4,0x43,0x3b,0x88,0xc3,0x3b,0xb0,0xc3,0x8c,0xc5,0x0a,0x87, 0x79,0x98,0x87,0x77,0x18,0x87,0x74,0x08,0x07,0x7a,0x28,0x07,0x72,0x98,0x81,0x5c, 0xe3,0x10,0x0e,0xec,0xc0,0x0e,0xe5,0x50,0x0e,0xf3,0x30,0x23,0xc1,0xd2,0x41,0x1e, 0xe4,0xe1,0x17,0xd8,0xe1,0x1d,0xde,0x01,0x1e,0x66,0x48,0x19,0x3b,0xb0,0x83,0x3d, 0xb4,0x83,0x1b,0x84,0xc3,0x38,0x8c,0x43,0x39,0xcc,0xc3,0x3c,0xb8,0xc1,0x39,0xc8, 0xc3,0x3b,0xd4,0x03,0x3c,0xcc,0x48,0xb4,0x71,0x08,0x07,0x76,0x60,0x07,0x71,0x08, 0x87,0x71,0x58,0x87,0x19,0xdb,0xc6,0x0e,0xec,0x60,0x0f,0xed,0xe0,0x06,0xf0,0x20, 0x0f,0xe5,0x30,0x0f,0xe5,0x20,0x0f,0xf6,0x50,0x0e,0x6e,0x10,0x0e,0xe3,0x30,0x0e, 0xe5,0x30,0x0f,0xf3,0xe0,0x06,0xe9,0xe0,0x0e,0xe4,0x50,0x0e,0xf8,0x30,0x23,0xe2, 0xec,0x61,0x1c,0xc2,0x81,0x1d,0xd8,0xe1,0x17,0xec,0x21,0x1d,0xe6,0x21,0x1d,0xc4, 0x21,0x1d,0xd8,0x21,0x1d,0xe8,0x21,0x1f,0x66,0x20,0x9d,0x3b,0xbc,0x43,0x3d,0xb8, 0x03,0x39,0x94,0x83,0x39,0xcc,0x58,0xbc,0x70,0x70,0x07,0x77,0x78,0x07,0x7a,0x08, 0x07,0x7a,0x48,0x87,0x77,0x70,0x87,0x19,0xce,0x87,0x0e,0xe5,0x10,0x0e,0xf0,0x10, 0x0e,0xec,0xc0,0x0e,0xef,0x30,0x0e,0xf3,0x90,0x0e,0xf4,0x50,0x0e,0x33,0x28,0x30, 0x08,0x87,0x74,0x90,0x07,0x37,0x30,0x87,0x7a,0x70,0x87,0x71,0xa0,0x87,0x74,0x78, 0x07,0x77,0xf8,0x85,0x73,0x90,0x87,0x77,0xa8,0x07,0x78,0x98,0x07,0x00,0x00,0x00, 0x00,0x71,0x20,0x00,0x00,0x08,0x00,0x00,0x00,0x16,0xb0,0x01,0x48,0xe4,0x4b,0x00, 0xf3,0x2c,0xc4,0x3f,0x11,0xd7,0x44,0x45,0xc4,0x6f,0x0f,0x7e,0x85,0x17,0xb7,0x6d, 0x00,0x05,0x03,0x20,0x0d,0x0d,0x00,0x00,0x00,0x61,0x20,0x00,0x00,0x11,0x00,0x00, 0x00,0x13,0x04,0x41,0x2c,0x10,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xc4,0x46,0x00, 0x48,0x8d,0x00,0xd4,0x00,0x89,0x19,0x00,0x02,0x23,0x00,0x00,0x00,0x23,0x06,0xca, 0x10,0x44,0x87,0x91,0x0c,0x05,0x11,0x58,0x90,0xc8,0x67,0xb6,0x81,0x08,0x80,0x0c, 0x02,0x62,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x5b,0x06,0xe0,0x90,0x03,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; /* Metal Vertex Shader (iOS) */ static const uint8_t nk_vs_bytecode_metal_ios[3212] = { 0x4d,0x54,0x4c,0x42,0x01,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x8c,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x6d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc9,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x3b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x01,0x00,0x00,0x00,0x00,0x00,0x00, 0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x01,0x00,0x00,0x00,0x00,0x00,0x00, 0x80,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x6d,0x00,0x00,0x00, 0x4e,0x41,0x4d,0x45,0x06,0x00,0x6d,0x61,0x69,0x6e,0x30,0x00,0x54,0x59,0x50,0x45, 0x01,0x00,0x00,0x48,0x41,0x53,0x48,0x20,0x00,0x3f,0x6b,0x6d,0x57,0x85,0xfd,0x52, 0x34,0x9e,0x07,0x97,0x4a,0x4b,0x88,0xe4,0x3f,0x9d,0x84,0x48,0x96,0x11,0x29,0xeb, 0xd5,0xc4,0xa7,0x46,0x02,0x51,0xea,0x2a,0x0b,0x4f,0x46,0x46,0x54,0x18,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x56,0x45,0x52,0x53,0x08,0x00,0x01,0x00,0x08, 0x00,0x01,0x00,0x01,0x00,0x45,0x4e,0x44,0x54,0x37,0x00,0x00,0x00,0x56,0x41,0x54, 0x54,0x22,0x00,0x03,0x00,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x00,0x00,0x80, 0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x00,0x01,0x80,0x63,0x6f,0x6c,0x6f, 0x72,0x30,0x00,0x02,0x80,0x56,0x41,0x54,0x59,0x05,0x00,0x03,0x00,0x04,0x04,0x06, 0x45,0x4e,0x44,0x54,0x04,0x00,0x00,0x00,0x45,0x4e,0x44,0x54,0xde,0xc0,0x17,0x0b, 0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x64,0x0b,0x00,0x00,0xff,0xff,0xff,0xff, 0x42,0x43,0xc0,0xde,0x21,0x0c,0x00,0x00,0xd6,0x02,0x00,0x00,0x0b,0x82,0x20,0x00, 0x02,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x07,0x81,0x23,0x91,0x41,0xc8,0x04,0x49, 0x06,0x10,0x32,0x39,0x92,0x01,0x84,0x0c,0x25,0x05,0x08,0x19,0x1e,0x04,0x8b,0x62, 0x80,0x10,0x45,0x02,0x42,0x92,0x0b,0x42,0x84,0x10,0x32,0x14,0x38,0x08,0x18,0x49, 0x0a,0x32,0x44,0x24,0x48,0x0a,0x90,0x21,0x23,0xc4,0x52,0x80,0x0c,0x19,0x21,0x72, 0x24,0x07,0xc8,0x08,0x11,0x62,0xa8,0xa0,0xa8,0x40,0xc6,0xf0,0x01,0x00,0x00,0x00, 0x51,0x18,0x00,0x00,0x70,0x00,0x00,0x00,0x1b,0x7e,0x24,0xf8,0xff,0xff,0xff,0xff, 0x01,0x90,0x00,0x8a,0x08,0x07,0x78,0x80,0x07,0x79,0x78,0x07,0x7c,0x68,0x03,0x73, 0xa8,0x07,0x77,0x18,0x87,0x36,0x30,0x07,0x78,0x68,0x83,0x76,0x08,0x07,0x7a,0x40, 0x07,0x80,0x1e,0xe4,0xa1,0x1e,0xca,0x01,0x20,0xda,0x21,0x1d,0xdc,0xa1,0x0d,0xd8, 0xa1,0x1c,0xce,0x21,0x1c,0xd8,0xa1,0x0d,0xec,0xa1,0x1c,0xc6,0x81,0x1e,0xde,0x41, 0x1e,0xda,0xe0,0x1e,0xd2,0x81,0x1c,0xe8,0x01,0x1d,0x80,0x38,0x90,0x03,0x3c,0x00, 0x06,0x77,0x78,0x87,0x36,0x10,0x87,0x7a,0x48,0x07,0x76,0xa0,0x87,0x74,0x70,0x87, 0x79,0x00,0x08,0x77,0x78,0x87,0x36,0x30,0x07,0x79,0x08,0x87,0x76,0x28,0x87,0x36, 0x80,0x87,0x77,0x48,0x07,0x77,0xa0,0x87,0x72,0x90,0x87,0x36,0x28,0x07,0x76,0x48, 0x87,0x76,0x00,0xe8,0x41,0x1e,0xea,0xa1,0x1c,0x00,0xc2,0x1d,0xde,0xa1,0x0d,0xcc, 0x41,0x1e,0xc2,0xa1,0x1d,0xca,0xa1,0x0d,0xe0,0xe1,0x1d,0xd2,0xc1,0x1d,0xe8,0xa1, 0x1c,0xe4,0xa1,0x0d,0xca,0x81,0x1d,0xd2,0xa1,0x1d,0xda,0xc0,0x1d,0xde,0xc1,0x1d, 0xda,0x80,0x1d,0xca,0x21,0x1c,0xcc,0x01,0xa0,0x07,0x79,0xa8,0x87,0x72,0x00,0x08, 0x77,0x78,0x87,0x36,0x48,0x07,0x77,0x30,0x87,0x79,0x68,0x03,0x73,0x80,0x87,0x36, 0x68,0x87,0x70,0xa0,0x07,0x74,0x00,0xe8,0x41,0x1e,0xea,0xa1,0x1c,0x00,0xc2,0x1d, 0xde,0xa1,0x0d,0xdc,0x21,0x1c,0xdc,0x61,0x1e,0xda,0xc0,0x1c,0xe0,0xa1,0x0d,0xda, 0x21,0x1c,0xe8,0x01,0x1d,0x00,0x7a,0x90,0x87,0x7a,0x28,0x07,0x80,0x70,0x87,0x77, 0x68,0x83,0x79,0x48,0x87,0x73,0x70,0x87,0x72,0x20,0x87,0x36,0xd0,0x87,0x72,0x90, 0x87,0x77,0x98,0x87,0x36,0x30,0x07,0x78,0x68,0x83,0x76,0x08,0x07,0x7a,0x40,0x07, 0x80,0x1e,0xe4,0xa1,0x1e,0xca,0x01,0x20,0xdc,0xe1,0x1d,0xda,0x80,0x1e,0xe4,0x21, 0x1c,0xe0,0x01,0x1e,0xd2,0xc1,0x1d,0xce,0xa1,0x0d,0xda,0x21,0x1c,0xe8,0x01,0x1d, 0x00,0x7a,0x90,0x87,0x7a,0x28,0x07,0x80,0x98,0x07,0x7a,0x08,0x87,0x71,0x58,0x87, 0x36,0x80,0x07,0x79,0x78,0x07,0x7a,0x28,0x87,0x71,0xa0,0x87,0x77,0x90,0x87,0x36, 0x10,0x87,0x7a,0x30,0x07,0x73,0x28,0x07,0x79,0x68,0x83,0x79,0x48,0x07,0x7d,0x28, 0x07,0x00,0x0f,0x00,0xa2,0x1e,0xdc,0x61,0x1e,0xc2,0xc1,0x1c,0xca,0xa1,0x0d,0xcc, 0x01,0x1e,0xda,0xa0,0x1d,0xc2,0x81,0x1e,0xd0,0x01,0xa0,0x07,0x79,0xa8,0x87,0x72, 0x00,0x36,0x6c,0x02,0x01,0x2c,0x40,0x35,0x84,0x43,0x3a,0xc8,0x43,0x1b,0x88,0x43, 0x3d,0x98,0x83,0x39,0x94,0x83,0x3c,0xb4,0x81,0x3b,0xbc,0x43,0x1b,0x84,0x03,0x3b, 0xa4,0x43,0x38,0xcc,0x03,0x00,0x00,0x00,0x49,0x18,0x00,0x00,0x01,0x00,0x00,0x00, 0x13,0x84,0x40,0x00,0x89,0x20,0x00,0x00,0x16,0x00,0x00,0x00,0x32,0x22,0x08,0x09, 0x20,0x64,0x85,0x04,0x13,0x22,0xa4,0x84,0x04,0x13,0x22,0xe3,0x84,0xa1,0x90,0x14, 0x12,0x4c,0x88,0x8c,0x0b,0x84,0x84,0x4c,0x10,0x3c,0x33,0x00,0xc3,0x08,0x02,0x30, 0x8c,0x40,0x00,0x76,0x08,0x91,0x83,0xa4,0x29,0xa2,0x84,0xc9,0xaf,0xa4,0xff,0x01, 0x22,0x80,0x91,0x50,0x10,0x83,0x08,0x84,0x50,0x8a,0x89,0x90,0x22,0x1b,0x08,0x98, 0x23,0x00,0x83,0x14,0xc8,0x39,0x02,0x50,0x18,0x44,0x08,0x84,0x61,0x04,0x22,0x19, 0x01,0x00,0x00,0x00,0x13,0xa8,0x70,0x48,0x07,0x79,0xb0,0x03,0x3a,0x68,0x83,0x70, 0x80,0x07,0x78,0x60,0x87,0x72,0x68,0x83,0x74,0x78,0x87,0x79,0xc8,0x03,0x37,0x80, 0x03,0x37,0x80,0x83,0x0d,0xb7,0x51,0x0e,0x6d,0x00,0x0f,0x7a,0x60,0x07,0x74,0xa0, 0x07,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xd0,0x06,0xe9,0x10,0x07,0x7a,0x80,0x07, 0x7a,0x80,0x07,0x6d,0x90,0x0e,0x78,0xa0,0x07,0x78,0xa0,0x07,0x78,0xd0,0x06,0xe9, 0x10,0x07,0x76,0xa0,0x07,0x71,0x60,0x07,0x7a,0x10,0x07,0x76,0xd0,0x06,0xe9,0x30, 0x07,0x72,0xa0,0x07,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xd0,0x06,0xe9,0x60,0x07, 0x74,0xa0,0x07,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xd0,0x06,0xe6,0x30,0x07,0x72, 0xa0,0x07,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xd0,0x06,0xe6,0x60,0x07,0x74,0xa0, 0x07,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xd0,0x06,0xf6,0x10,0x07,0x76,0xa0,0x07, 0x71,0x60,0x07,0x7a,0x10,0x07,0x76,0xd0,0x06,0xf6,0x20,0x07,0x74,0xa0,0x07,0x73, 0x20,0x07,0x7a,0x30,0x07,0x72,0xd0,0x06,0xf6,0x30,0x07,0x72,0xa0,0x07,0x73,0x20, 0x07,0x7a,0x30,0x07,0x72,0xd0,0x06,0xf6,0x40,0x07,0x78,0xa0,0x07,0x76,0x40,0x07, 0x7a,0x60,0x07,0x74,0xd0,0x06,0xf6,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x7a, 0x60,0x07,0x74,0xd0,0x06,0xf6,0x90,0x07,0x76,0xa0,0x07,0x71,0x20,0x07,0x78,0xa0, 0x07,0x71,0x20,0x07,0x78,0xd0,0x06,0xf6,0x10,0x07,0x72,0x80,0x07,0x7a,0x10,0x07, 0x72,0x80,0x07,0x7a,0x10,0x07,0x72,0x80,0x07,0x6d,0x60,0x0f,0x71,0x90,0x07,0x72, 0xa0,0x07,0x72,0x50,0x07,0x76,0xa0,0x07,0x72,0x50,0x07,0x76,0xd0,0x06,0xf6,0x20, 0x07,0x75,0x60,0x07,0x7a,0x20,0x07,0x75,0x60,0x07,0x7a,0x20,0x07,0x75,0x60,0x07, 0x6d,0x60,0x0f,0x75,0x10,0x07,0x72,0xa0,0x07,0x75,0x10,0x07,0x72,0xa0,0x07,0x75, 0x10,0x07,0x72,0xd0,0x06,0xf6,0x10,0x07,0x70,0x20,0x07,0x74,0xa0,0x07,0x71,0x00, 0x07,0x72,0x40,0x07,0x7a,0x10,0x07,0x70,0x20,0x07,0x74,0xd0,0x06,0xee,0x80,0x07, 0x7a,0x10,0x07,0x76,0xa0,0x07,0x73,0x20,0x07,0x43,0x98,0x03,0x00,0x80,0x00,0x00, 0x00,0x00,0x00,0x80,0x2c,0x10,0x00,0x00,0x09,0x00,0x00,0x00,0x32,0x1e,0x98,0x10, 0x19,0x11,0x4c,0x90,0x8c,0x09,0x26,0x47,0xc6,0x04,0x43,0xca,0x12,0x18,0x01,0x28, 0x88,0x22,0x28,0x84,0x32,0xa0,0x1d,0x01,0x20,0x1d,0x4b,0x90,0x00,0x00,0x00,0x00, 0x79,0x18,0x00,0x00,0xfa,0x00,0x00,0x00,0x1a,0x03,0x4c,0x10,0x97,0x29,0xa2,0x25, 0x10,0xab,0x32,0xb9,0xb9,0xb4,0x37,0xb7,0x21,0x46,0x42,0x20,0x80,0x82,0x50,0xb9, 0x1b,0x43,0x0b,0x93,0xfb,0x9a,0x4b,0xd3,0x2b,0x1b,0x62,0x24,0x01,0x22,0x24,0x05, 0xe3,0x20,0x08,0x0e,0x8e,0xad,0x0c,0xa4,0xad,0x8c,0x2e,0x8c,0x0d,0xc4,0xae,0x4c, 0x6e,0x2e,0xed,0xcd,0x0d,0x64,0x46,0x06,0x46,0x66,0xc6,0x65,0x66,0xa6,0x06,0x04, 0xa5,0xad,0x8c,0x2e,0x8c,0xcd,0xac,0xac,0x65,0x46,0x06,0x46,0x66,0xc6,0x65,0x66, 0xa6,0x26,0x65,0x88,0x80,0x10,0x43,0x8c,0x24,0x48,0x86,0x44,0x60,0xd1,0x54,0x46, 0x17,0xc6,0x36,0x04,0x41,0x8e,0x24,0x48,0x82,0x44,0xe0,0x16,0x96,0x26,0xe7,0x32, 0xf6,0xd6,0x06,0x97,0xc6,0x56,0xe6,0x42,0x56,0xe6,0xf6,0x26,0xd7,0x36,0xf7,0x45, 0x96,0x36,0x17,0x26,0xc6,0x56,0x36,0x44,0x40,0x12,0x72,0x61,0x69,0x72,0x2e,0x63, 0x6f,0x6d,0x70,0x69,0x6c,0x65,0x2e,0x66,0x61,0x73,0x74,0x5f,0x6d,0x61,0x74,0x68, 0x5f,0x65,0x6e,0x61,0x62,0x6c,0x65,0x43,0x04,0x64,0x21,0x19,0x84,0xa5,0xc9,0xb9, 0x8c,0xbd,0xb5,0xc1,0xa5,0xb1,0x95,0xb9,0x98,0xc9,0x85,0xb5,0x95,0x89,0xd5,0x99, 0x99,0x95,0xc9,0x7d,0x99,0x95,0xd1,0x8d,0xa1,0x7d,0x95,0xb9,0x85,0x89,0xb1,0x95, 0x0d,0x11,0x90,0x86,0x51,0x58,0x9a,0x9c,0x8b,0x5d,0x99,0x1c,0x5d,0x19,0xde,0xd7, 0x5b,0x1d,0x1d,0x5c,0x1d,0x1d,0x97,0xba,0xb9,0x32,0x39,0x14,0xb6,0xb7,0x31,0x37, 0x98,0x14,0x46,0x61,0x69,0x72,0x2e,0x61,0x72,0x67,0x5f,0x74,0x79,0x70,0x65,0x5f, 0x6e,0x61,0x6d,0x65,0x34,0xcc,0xd8,0xde,0xc2,0xe8,0x64,0xc8,0x84,0xa5,0xc9,0xb9, 0x84,0xc9,0x9d,0x7d,0xb9,0x85,0xb5,0x95,0x51,0xa8,0xb3,0x1b,0xc2,0x20,0x0f,0x02, 0x21,0x11,0x22,0x21,0x13,0x42,0x71,0xa9,0x9b,0x2b,0x93,0x43,0x61,0x7b,0x1b,0x73, 0x8b,0x49,0xa1,0x61,0xc6,0xf6,0x16,0x46,0x47,0xc3,0x62,0xec,0x8d,0xed,0x4d,0x6e, 0x08,0x83,0x3c,0x88,0x85,0x44,0xc8,0x85,0x4c,0x08,0x46,0x26,0x2c,0x4d,0xce,0x05, 0xee,0x6d,0x2e,0x8d,0x2e,0xed,0xcd,0x8d,0xcb,0x19,0xdb,0x17,0xd4,0xdb,0x5c,0x1a, 0x5d,0xda,0x9b,0xdb,0x10,0x05,0xd1,0x90,0x08,0xb9,0x90,0x09,0xd9,0x86,0x18,0x48, 0x85,0x64,0x08,0x47,0x28,0x2c,0x4d,0xce,0xc5,0xae,0x4c,0x8e,0xae,0x0c,0xef,0x2b, 0xcd,0x0d,0xae,0x8e,0x8e,0x52,0x58,0x9a,0x9c,0x0b,0xdb,0xdb,0x58,0x18,0x5d,0xda, 0x9b,0xdb,0x57,0x9a,0x1b,0x59,0x19,0x1e,0xbd,0xb3,0x32,0xb7,0x32,0xb9,0x30,0xba, 0x32,0x32,0x94,0xaf,0xaf,0xb0,0x34,0xb9,0x2f,0x38,0xb6,0xb0,0xb1,0x32,0xb4,0x37, 0x36,0xb2,0x32,0xb9,0xaf,0xaf,0x14,0x22,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, 0x43,0xa8,0x44,0x40,0x3c,0xe4,0x4b,0x84,0x24,0x40,0xc0,0x00,0x89,0x10,0x09,0x99, 0x90,0x30,0x60,0x42,0x57,0x86,0x37,0xf6,0xf6,0x26,0x47,0x06,0x33,0x84,0x4a,0x02, 0xc4,0x43,0xbe,0x24,0x48,0x02,0x04,0x0c,0x90,0x08,0x91,0x90,0x09,0x19,0x03,0x1a, 0x63,0x6f,0x6c,0x6f,0x72,0x30,0x43,0xa8,0x84,0x40,0x3c,0xe4,0x4b,0x88,0x24,0x40, 0xc0,0x00,0x89,0x90,0x0b,0x99,0x90,0x32,0xa0,0x12,0x96,0x26,0xe7,0x22,0x56,0x67, 0x66,0x56,0x26,0xc7,0x27,0x2c,0x4d,0xce,0x45,0xac,0xce,0xcc,0xac,0x4c,0xee,0x6b, 0x2e,0x4d,0xaf,0x8c,0x48,0x58,0x9a,0x9c,0x8b,0x5c,0x59,0x18,0x19,0xa9,0xb0,0x34, 0x39,0x97,0x39,0x3a,0xb9,0xba,0x31,0xba,0x2f,0xba,0x3c,0xb8,0xb2,0xaf,0x34,0x37, 0xb3,0x37,0x26,0x64,0x69,0x73,0x70,0x5f,0x73,0x69,0x7a,0x65,0x43,0x94,0x44,0x48, 0x86,0x44,0x40,0x24,0x64,0x0d,0x18,0x85,0xa5,0xc9,0xb9,0x84,0xc9,0x9d,0x7d,0xd1, 0xe5,0xc1,0x95,0x7d,0xcd,0xa5,0xe9,0x95,0xf1,0x0a,0x4b,0x93,0x73,0x09,0x93,0x3b, 0xfb,0xa2,0xcb,0x83,0x2b,0xfb,0x0a,0x63,0x4b,0x3b,0x73,0xfb,0x9a,0x4b,0xd3,0x2b, 0x63,0x62,0x37,0xf7,0x05,0x17,0x26,0x17,0xd6,0x36,0xc7,0xe1,0x4b,0x46,0x66,0x08, 0x19,0x24,0x06,0x72,0x06,0x08,0x1a,0x24,0x03,0xf2,0x25,0x42,0x12,0x20,0x69,0x80, 0xa8,0x01,0xc2,0x06,0x48,0x1b,0x24,0x03,0xe2,0x06,0xc9,0x80,0x44,0xc8,0x1b,0x20, 0x13,0x02,0x07,0x43,0x10,0x44,0x0c,0x10,0x32,0x40,0xcc,0x00,0x89,0x83,0x21,0xc6, 0x01,0x20,0x1d,0x22,0x07,0x7c,0xde,0xda,0xdc,0xd2,0xe0,0xde,0xe8,0xca,0xdc,0xe8, 0x40,0xc6,0xd0,0xc2,0xe4,0xf8,0x4c,0xa5,0xb5,0xc1,0xb1,0x95,0x81,0x0c,0xad,0xac, 0x80,0x50,0x09,0x05,0x05,0x0d,0x11,0x90,0x3a,0x18,0x62,0x20,0x74,0x80,0xd8,0xc1, 0x72,0x0c,0x31,0x90,0x3b,0x40,0xee,0x60,0x39,0x78,0x85,0xa5,0xc9,0xb5,0x84,0xb1, 0xa5,0x85,0xcd,0xb5,0xcc,0x8d,0xbd,0xc1,0x95,0xcd,0xa1,0xb4,0x85,0xa5,0xb9,0xc1, 0xa4,0x0c,0x21,0x10,0x3d,0x40,0xf2,0x80,0x56,0x58,0x9a,0x5c,0x4b,0x18,0x5b,0x5a, 0xd8,0x5c,0xcb,0xdc,0xd8,0x1b,0x5c,0x59,0x4b,0x98,0xdc,0x19,0xca,0x4c,0xca,0x10, 0x03,0xe1,0x03,0x44,0x0f,0x90,0x3d,0x18,0x22,0x20,0x7c,0x30,0x22,0x62,0x07,0x76, 0xb0,0x87,0x76,0x70,0x83,0x76,0x78,0x07,0x72,0xa8,0x07,0x76,0x28,0x07,0x37,0x30, 0x07,0x76,0x08,0x87,0x73,0x98,0x87,0x29,0x42,0x30,0x8c,0x50,0xd8,0x81,0x1d,0xec, 0xa1,0x1d,0xdc,0x20,0x1d,0xc8,0xa1,0x1c,0xdc,0x81,0x1e,0xa6,0x04,0xc5,0x88,0x25, 0x1c,0xd2,0x41,0x1e,0xdc,0xc0,0x1e,0xca,0x41,0x1e,0xe6,0x21,0x1d,0xde,0xc1,0x1d, 0xa6,0x04,0xc6,0x08,0x2a,0x1c,0xd2,0x41,0x1e,0xdc,0x80,0x1d,0xc2,0xc1,0x1d,0xce, 0xa1,0x1e,0xc2,0xe1,0x1c,0xca,0xe1,0x17,0xec,0xa1,0x1c,0xe4,0x61,0x1e,0xd2,0xe1, 0x1d,0xdc,0x61,0x4a,0x80,0x8c,0x98,0xc2,0x21,0x1d,0xe4,0xc1,0x0d,0xc6,0xe1,0x1d, 0xda,0x01,0x1e,0xd2,0x81,0x1d,0xca,0xe1,0x17,0xde,0x01,0x1e,0xe8,0x21,0x1d,0xde, 0xc1,0x1d,0xe6,0x61,0xca,0xa0,0x30,0xce,0x08,0x25,0x1c,0xd2,0x41,0x1e,0xdc,0xc0, 0x1e,0xca,0x41,0x1e,0xe8,0xa1,0x1c,0xf0,0x61,0x4a,0x30,0x07,0x00,0x00,0x00,0x00, 0x79,0x18,0x00,0x00,0xa5,0x00,0x00,0x00,0x33,0x08,0x80,0x1c,0xc4,0xe1,0x1c,0x66, 0x14,0x01,0x3d,0x88,0x43,0x38,0x84,0xc3,0x8c,0x42,0x80,0x07,0x79,0x78,0x07,0x73, 0x98,0x71,0x0c,0xe6,0x00,0x0f,0xed,0x10,0x0e,0xf4,0x80,0x0e,0x33,0x0c,0x42,0x1e, 0xc2,0xc1,0x1d,0xce,0xa1,0x1c,0x66,0x30,0x05,0x3d,0x88,0x43,0x38,0x84,0x83,0x1b, 0xcc,0x03,0x3d,0xc8,0x43,0x3d,0x8c,0x03,0x3d,0xcc,0x78,0x8c,0x74,0x70,0x07,0x7b, 0x08,0x07,0x79,0x48,0x87,0x70,0x70,0x07,0x7a,0x70,0x03,0x76,0x78,0x87,0x70,0x20, 0x87,0x19,0xcc,0x11,0x0e,0xec,0x90,0x0e,0xe1,0x30,0x0f,0x6e,0x30,0x0f,0xe3,0xf0, 0x0e,0xf0,0x50,0x0e,0x33,0x10,0xc4,0x1d,0xde,0x21,0x1c,0xd8,0x21,0x1d,0xc2,0x61, 0x1e,0x66,0x30,0x89,0x3b,0xbc,0x83,0x3b,0xd0,0x43,0x39,0xb4,0x03,0x3c,0xbc,0x83, 0x3c,0x84,0x03,0x3b,0xcc,0xf0,0x14,0x76,0x60,0x07,0x7b,0x68,0x07,0x37,0x68,0x87, 0x72,0x68,0x07,0x37,0x80,0x87,0x70,0x90,0x87,0x70,0x60,0x07,0x76,0x28,0x07,0x76, 0xf8,0x05,0x76,0x78,0x87,0x77,0x80,0x87,0x5f,0x08,0x87,0x71,0x18,0x87,0x72,0x98, 0x87,0x79,0x98,0x81,0x2c,0xee,0xf0,0x0e,0xee,0xe0,0x0e,0xf5,0xc0,0x0e,0xec,0x30, 0x03,0x62,0xc8,0xa1,0x1c,0xe4,0xa1,0x1c,0xcc,0xa1,0x1c,0xe4,0xa1,0x1c,0xdc,0x61, 0x1c,0xca,0x21,0x1c,0xc4,0x81,0x1d,0xca,0x61,0x06,0xd6,0x90,0x43,0x39,0xc8,0x43, 0x39,0x98,0x43,0x39,0xc8,0x43,0x39,0xb8,0xc3,0x38,0x94,0x43,0x38,0x88,0x03,0x3b, 0x94,0xc3,0x2f,0xbc,0x83,0x3c,0xfc,0x82,0x3b,0xd4,0x03,0x3b,0xb0,0xc3,0x0c,0xc7, 0x69,0x87,0x70,0x58,0x87,0x72,0x70,0x83,0x74,0x68,0x07,0x78,0x60,0x87,0x74,0x18, 0x87,0x74,0xa0,0x87,0x19,0xce,0x53,0x0f,0xee,0x00,0x0f,0xf2,0x50,0x0e,0xe4,0x90, 0x0e,0xe3,0x40,0x0f,0xe1,0x20,0x0e,0xec,0x50,0x0e,0x33,0x20,0x28,0x1d,0xdc,0xc1, 0x1e,0xc2,0x41,0x1e,0xd2,0x21,0x1c,0xdc,0x81,0x1e,0xdc,0xe0,0x1c,0xe4,0xe1,0x1d, 0xea,0x01,0x1e,0x66,0x18,0x51,0x38,0xb0,0x43,0x3a,0x9c,0x83,0x3b,0xcc,0x50,0x24, 0x76,0x60,0x07,0x7b,0x68,0x07,0x37,0x60,0x87,0x77,0x78,0x07,0x78,0x98,0x51,0x4c, 0xf4,0x90,0x0f,0xf0,0x50,0x0e,0x33,0x1e,0x6a,0x1e,0xca,0x61,0x1c,0xe8,0x21,0x1d, 0xde,0xc1,0x1d,0x7e,0x01,0x1e,0xe4,0xa1,0x1c,0xcc,0x21,0x1d,0xf0,0x61,0x06,0x54, 0x85,0x83,0x38,0xcc,0xc3,0x3b,0xb0,0x43,0x3d,0xd0,0x43,0x39,0xfc,0xc2,0x3c,0xe4, 0x43,0x3b,0x88,0xc3,0x3b,0xb0,0xc3,0x8c,0xc5,0x0a,0x87,0x79,0x98,0x87,0x77,0x18, 0x87,0x74,0x08,0x07,0x7a,0x28,0x07,0x72,0x98,0x81,0x5c,0xe3,0x10,0x0e,0xec,0xc0, 0x0e,0xe5,0x50,0x0e,0xf3,0x30,0x23,0xc1,0xd2,0x41,0x1e,0xe4,0xe1,0x17,0xd8,0xe1, 0x1d,0xde,0x01,0x1e,0x66,0x48,0x19,0x3b,0xb0,0x83,0x3d,0xb4,0x83,0x1b,0x84,0xc3, 0x38,0x8c,0x43,0x39,0xcc,0xc3,0x3c,0xb8,0xc1,0x39,0xc8,0xc3,0x3b,0xd4,0x03,0x3c, 0xcc,0x48,0xb4,0x71,0x08,0x07,0x76,0x60,0x07,0x71,0x08,0x87,0x71,0x58,0x87,0x19, 0xdb,0xc6,0x0e,0xec,0x60,0x0f,0xed,0xe0,0x06,0xf0,0x20,0x0f,0xe5,0x30,0x0f,0xe5, 0x20,0x0f,0xf6,0x50,0x0e,0x6e,0x10,0x0e,0xe3,0x30,0x0e,0xe5,0x30,0x0f,0xf3,0xe0, 0x06,0xe9,0xe0,0x0e,0xe4,0x50,0x0e,0xf8,0x30,0x23,0xe2,0xec,0x61,0x1c,0xc2,0x81, 0x1d,0xd8,0xe1,0x17,0xec,0x21,0x1d,0xe6,0x21,0x1d,0xc4,0x21,0x1d,0xd8,0x21,0x1d, 0xe8,0x21,0x1f,0x66,0x20,0x9d,0x3b,0xbc,0x43,0x3d,0xb8,0x03,0x39,0x94,0x83,0x39, 0xcc,0x58,0xbc,0x70,0x70,0x07,0x77,0x78,0x07,0x7a,0x08,0x07,0x7a,0x48,0x87,0x77, 0x70,0x87,0x19,0xce,0x87,0x0e,0xe5,0x10,0x0e,0xf0,0x10,0x0e,0xec,0xc0,0x0e,0xef, 0x30,0x0e,0xf3,0x90,0x0e,0xf4,0x50,0x0e,0x33,0x28,0x30,0x08,0x87,0x74,0x90,0x07, 0x37,0x30,0x87,0x7a,0x70,0x87,0x71,0xa0,0x87,0x74,0x78,0x07,0x77,0xf8,0x85,0x73, 0x90,0x87,0x77,0xa8,0x07,0x78,0x98,0x07,0x00,0x00,0x00,0x00,0x71,0x20,0x00,0x00, 0x02,0x00,0x00,0x00,0x06,0x50,0x30,0x00,0xd2,0xd0,0x00,0x00,0x61,0x20,0x00,0x00, 0x23,0x00,0x00,0x00,0x13,0x04,0x41,0x2c,0x10,0x00,0x00,0x00,0x11,0x00,0x00,0x00, 0xd4,0x63,0x11,0x40,0x60,0x1c,0x73,0x10,0x42,0xf0,0x3c,0x94,0x33,0x00,0x14,0x63, 0x09,0x20,0x08,0x82,0xf0,0x2f,0x80,0x20,0x08,0xc2,0xbf,0x30,0x96,0x00,0x82,0x20, 0x08,0x82,0x01,0x08,0x82,0x20,0x08,0x0e,0x33,0x00,0x24,0x73,0x10,0xd7,0x65,0x55, 0x34,0x33,0x00,0x04,0x63,0x04,0x20,0x08,0x82,0xf8,0x37,0x46,0x00,0x82,0x20,0x08, 0x7f,0x33,0x00,0x00,0xe3,0x0d,0x4c,0x64,0x51,0x40,0x2c,0x0a,0xe8,0x63,0xc1,0x02, 0x1f,0x0b,0x16,0xf9,0x0c,0x32,0x04,0xcb,0x33,0xc8,0x10,0x2c,0xd1,0x6c,0xc3,0x52, 0x01,0xb3,0x0d,0x41,0x15,0xcc,0x36,0x04,0x83,0x90,0x41,0x40,0x0c,0x00,0x00,0x00, 0x02,0x00,0x00,0x00,0x5b,0x8a,0x20,0xc0,0x83,0xa3,0x0f,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; /* Metal Fragment Shader (iOS) */ static const uint8_t nk_fs_bytecode_metal_ios[3017] = { 0x4d,0x54,0x4c,0x42,0x01,0x00,0x02,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xc9,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x6d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc9,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xd1,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xd9,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0xf0,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x6d,0x00,0x00,0x00, 0x4e,0x41,0x4d,0x45,0x06,0x00,0x6d,0x61,0x69,0x6e,0x30,0x00,0x54,0x59,0x50,0x45, 0x01,0x00,0x01,0x48,0x41,0x53,0x48,0x20,0x00,0x4a,0x26,0x79,0xc0,0xb7,0x63,0xb4, 0xc2,0x1d,0xe8,0x10,0x46,0x41,0x83,0x17,0xea,0x3a,0x9a,0x24,0x37,0x8e,0xb3,0xb9, 0x44,0xa4,0x85,0x3d,0x7c,0xd2,0xec,0x4b,0x4a,0x4f,0x46,0x46,0x54,0x18,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x56,0x45,0x52,0x53,0x08,0x00,0x01,0x00,0x08, 0x00,0x01,0x00,0x01,0x00,0x45,0x4e,0x44,0x54,0x04,0x00,0x00,0x00,0x45,0x4e,0x44, 0x54,0x04,0x00,0x00,0x00,0x45,0x4e,0x44,0x54,0xde,0xc0,0x17,0x0b,0x00,0x00,0x00, 0x00,0x14,0x00,0x00,0x00,0xd4,0x0a,0x00,0x00,0xff,0xff,0xff,0xff,0x42,0x43,0xc0, 0xde,0x21,0x0c,0x00,0x00,0xb2,0x02,0x00,0x00,0x0b,0x82,0x20,0x00,0x02,0x00,0x00, 0x00,0x12,0x00,0x00,0x00,0x07,0x81,0x23,0x91,0x41,0xc8,0x04,0x49,0x06,0x10,0x32, 0x39,0x92,0x01,0x84,0x0c,0x25,0x05,0x08,0x19,0x1e,0x04,0x8b,0x62,0x80,0x14,0x45, 0x02,0x42,0x92,0x0b,0x42,0xa4,0x10,0x32,0x14,0x38,0x08,0x18,0x49,0x0a,0x32,0x44, 0x24,0x48,0x0a,0x90,0x21,0x23,0xc4,0x52,0x80,0x0c,0x19,0x21,0x72,0x24,0x07,0xc8, 0x48,0x11,0x62,0xa8,0xa0,0xa8,0x40,0xc6,0xf0,0x01,0x00,0x00,0x00,0x51,0x18,0x00, 0x00,0x74,0x00,0x00,0x00,0x1b,0xc2,0x24,0xf8,0xff,0xff,0xff,0xff,0x01,0x60,0x00, 0x09,0xa8,0x88,0x70,0x80,0x07,0x78,0x90,0x87,0x77,0xc0,0x87,0x36,0x30,0x87,0x7a, 0x70,0x87,0x71,0x68,0x03,0x73,0x80,0x87,0x36,0x68,0x87,0x70,0xa0,0x07,0x74,0x00, 0xe8,0x41,0x1e,0xea,0xa1,0x1c,0x00,0xa2,0x1d,0xd2,0xc1,0x1d,0xda,0x80,0x1d,0xca, 0xe1,0x1c,0xc2,0x81,0x1d,0xda,0xc0,0x1e,0xca,0x61,0x1c,0xe8,0xe1,0x1d,0xe4,0xa1, 0x0d,0xee,0x21,0x1d,0xc8,0x81,0x1e,0xd0,0x01,0x88,0x03,0x39,0xc0,0x03,0x60,0x70, 0x87,0x77,0x68,0x03,0x71,0xa8,0x87,0x74,0x60,0x07,0x7a,0x48,0x07,0x77,0x98,0x07, 0x80,0x70,0x87,0x77,0x68,0x03,0x73,0x90,0x87,0x70,0x68,0x87,0x72,0x68,0x03,0x78, 0x78,0x87,0x74,0x70,0x07,0x7a,0x28,0x07,0x79,0x68,0x83,0x72,0x60,0x87,0x74,0x68, 0x07,0x80,0x1e,0xe4,0xa1,0x1e,0xca,0x01,0x20,0xdc,0xe1,0x1d,0xda,0xc0,0x1c,0xe4, 0x21,0x1c,0xda,0xa1,0x1c,0xda,0x00,0x1e,0xde,0x21,0x1d,0xdc,0x81,0x1e,0xca,0x41, 0x1e,0xda,0xa0,0x1c,0xd8,0x21,0x1d,0xda,0xa1,0x0d,0xdc,0xe1,0x1d,0xdc,0xa1,0x0d, 0xd8,0xa1,0x1c,0xc2,0xc1,0x1c,0x00,0x7a,0x90,0x87,0x7a,0x28,0x07,0x80,0x70,0x87, 0x77,0x68,0x83,0x74,0x70,0x07,0x73,0x98,0x87,0x36,0x30,0x07,0x78,0x68,0x83,0x76, 0x08,0x07,0x7a,0x40,0x07,0x80,0x1e,0xe4,0xa1,0x1e,0xca,0x01,0x20,0xdc,0xe1,0x1d, 0xda,0xc0,0x1d,0xc2,0xc1,0x1d,0xe6,0xa1,0x0d,0xcc,0x01,0x1e,0xda,0xa0,0x1d,0xc2, 0x81,0x1e,0xd0,0x01,0xa0,0x07,0x79,0xa8,0x87,0x72,0x00,0x08,0x77,0x78,0x87,0x36, 0x98,0x87,0x74,0x38,0x07,0x77,0x28,0x07,0x72,0x68,0x03,0x7d,0x28,0x07,0x79,0x78, 0x87,0x79,0x68,0x03,0x73,0x80,0x87,0x36,0x68,0x87,0x70,0xa0,0x07,0x74,0x00,0xe8, 0x41,0x1e,0xea,0xa1,0x1c,0x00,0xc2,0x1d,0xde,0xa1,0x0d,0xe8,0x41,0x1e,0xc2,0x01, 0x1e,0xe0,0x21,0x1d,0xdc,0xe1,0x1c,0xda,0xa0,0x1d,0xc2,0x81,0x1e,0xd0,0x01,0xa0, 0x07,0x79,0xa8,0x87,0x72,0x00,0x88,0x79,0xa0,0x87,0x70,0x18,0x87,0x75,0x68,0x03, 0x78,0x90,0x87,0x77,0xa0,0x87,0x72,0x18,0x07,0x7a,0x78,0x07,0x79,0x68,0x03,0x71, 0xa8,0x07,0x73,0x30,0x87,0x72,0x90,0x87,0x36,0x98,0x87,0x74,0xd0,0x87,0x72,0x00, 0xf0,0x00,0x20,0xea,0xc1,0x1d,0xe6,0x21,0x1c,0xcc,0xa1,0x1c,0xda,0xc0,0x1c,0xe0, 0xa1,0x0d,0xda,0x21,0x1c,0xe8,0x01,0x1d,0x00,0x7a,0x90,0x87,0x7a,0x28,0x07,0x60, 0x83,0x21,0x0c,0xc0,0x02,0x54,0x1b,0x8c,0x81,0x00,0x16,0xa0,0xda,0x80,0x10,0xff, 0xff,0xff,0xff,0x3f,0x00,0x0c,0x20,0x01,0xd5,0x06,0xa3,0x08,0x80,0x05,0xa8,0x36, 0x18,0x86,0x00,0x2c,0x40,0xb5,0x01,0x39,0xfe,0xff,0xff,0xff,0x7f,0x00,0x18,0x40, 0x02,0x2a,0x00,0x00,0x00,0x49,0x18,0x00,0x00,0x04,0x00,0x00,0x00,0x13,0x86,0x40, 0x18,0x26,0x0c,0x44,0x61,0x4c,0x18,0x8e,0xc2,0x00,0x00,0x00,0x00,0x89,0x20,0x00, 0x00,0x1d,0x00,0x00,0x00,0x32,0x22,0x48,0x09,0x20,0x64,0x85,0x04,0x93,0x22,0xa4, 0x84,0x04,0x93,0x22,0xe3,0x84,0xa1,0x90,0x14,0x12,0x4c,0x8a,0x8c,0x0b,0x84,0xa4, 0x4c,0x10,0x48,0x33,0x00,0xc3,0x08,0x04,0x60,0x83,0x30,0x8c,0x20,0x00,0x47,0x49, 0x53,0x44,0x09,0x93,0xff,0x4f,0xc4,0x35,0x51,0x11,0xf1,0xdb,0xc3,0x3f,0x8d,0x11, 0x00,0x83,0x08,0x44,0x70,0x91,0x34,0x45,0x94,0x30,0xf9,0xbf,0x04,0x30,0xcf,0x42, 0x44,0xff,0x34,0x46,0x00,0x0c,0x22,0x18,0x42,0x29,0xc4,0x08,0xe5,0x10,0x9a,0x23, 0x08,0xe6,0x08,0xc0,0x60,0x18,0x41,0x58,0x0a,0x12,0xca,0x19,0x8a,0x29,0x40,0x6d, 0x20,0x20,0x05,0xd6,0x08,0x00,0x00,0x00,0x00,0x13,0xa8,0x70,0x48,0x07,0x79,0xb0, 0x03,0x3a,0x68,0x83,0x70,0x80,0x07,0x78,0x60,0x87,0x72,0x68,0x83,0x74,0x78,0x87, 0x79,0xc8,0x03,0x37,0x80,0x03,0x37,0x80,0x83,0x0d,0xb7,0x51,0x0e,0x6d,0x00,0x0f, 0x7a,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xd0,0x06,0xe9, 0x10,0x07,0x7a,0x80,0x07,0x7a,0x80,0x07,0x6d,0x90,0x0e,0x78,0xa0,0x07,0x78,0xa0, 0x07,0x78,0xd0,0x06,0xe9,0x10,0x07,0x76,0xa0,0x07,0x71,0x60,0x07,0x7a,0x10,0x07, 0x76,0xd0,0x06,0xe9,0x30,0x07,0x72,0xa0,0x07,0x73,0x20,0x07,0x7a,0x30,0x07,0x72, 0xd0,0x06,0xe9,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xd0, 0x06,0xe6,0x30,0x07,0x72,0xa0,0x07,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xd0,0x06, 0xe6,0x60,0x07,0x74,0xa0,0x07,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xd0,0x06,0xf6, 0x10,0x07,0x76,0xa0,0x07,0x71,0x60,0x07,0x7a,0x10,0x07,0x76,0xd0,0x06,0xf6,0x20, 0x07,0x74,0xa0,0x07,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xd0,0x06,0xf6,0x30,0x07, 0x72,0xa0,0x07,0x73,0x20,0x07,0x7a,0x30,0x07,0x72,0xd0,0x06,0xf6,0x40,0x07,0x78, 0xa0,0x07,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xd0,0x06,0xf6,0x60,0x07,0x74,0xa0, 0x07,0x76,0x40,0x07,0x7a,0x60,0x07,0x74,0xd0,0x06,0xf6,0x90,0x07,0x76,0xa0,0x07, 0x71,0x20,0x07,0x78,0xa0,0x07,0x71,0x20,0x07,0x78,0xd0,0x06,0xf6,0x10,0x07,0x72, 0x80,0x07,0x7a,0x10,0x07,0x72,0x80,0x07,0x7a,0x10,0x07,0x72,0x80,0x07,0x6d,0x60, 0x0f,0x71,0x90,0x07,0x72,0xa0,0x07,0x72,0x50,0x07,0x76,0xa0,0x07,0x72,0x50,0x07, 0x76,0xd0,0x06,0xf6,0x20,0x07,0x75,0x60,0x07,0x7a,0x20,0x07,0x75,0x60,0x07,0x7a, 0x20,0x07,0x75,0x60,0x07,0x6d,0x60,0x0f,0x75,0x10,0x07,0x72,0xa0,0x07,0x75,0x10, 0x07,0x72,0xa0,0x07,0x75,0x10,0x07,0x72,0xd0,0x06,0xf6,0x10,0x07,0x70,0x20,0x07, 0x74,0xa0,0x07,0x71,0x00,0x07,0x72,0x40,0x07,0x7a,0x10,0x07,0x70,0x20,0x07,0x74, 0xd0,0x06,0xee,0x80,0x07,0x7a,0x10,0x07,0x76,0xa0,0x07,0x73,0x20,0x07,0x43,0x98, 0x04,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x21,0x8c,0x03,0x04,0x80,0x00,0x00, 0x00,0x00,0x00,0x40,0x16,0x08,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x32,0x1e,0x98, 0x10,0x19,0x11,0x4c,0x90,0x8c,0x09,0x26,0x47,0xc6,0x04,0x43,0x5a,0x25,0x30,0x02, 0x50,0x04,0x85,0x50,0x10,0x65,0x40,0x70,0x2c,0x41,0x02,0x00,0x00,0x79,0x18,0x00, 0x00,0xd2,0x00,0x00,0x00,0x1a,0x03,0x4c,0x10,0x97,0x29,0xa2,0x25,0x10,0xab,0x32, 0xb9,0xb9,0xb4,0x37,0xb7,0x21,0xc6,0x42,0x3c,0x00,0x84,0x50,0xb9,0x1b,0x43,0x0b, 0x93,0xfb,0x9a,0x4b,0xd3,0x2b,0x1b,0x62,0x2c,0xc2,0x23,0x2c,0x05,0xe3,0x20,0x08, 0x0e,0x8e,0xad,0x0c,0xa4,0xad,0x8c,0x2e,0x8c,0x0d,0xc4,0xae,0x4c,0x6e,0x2e,0xed, 0xcd,0x0d,0x64,0x46,0x06,0x46,0x66,0xc6,0x65,0x66,0xa6,0x06,0x04,0xa5,0xad,0x8c, 0x2e,0x8c,0xcd,0xac,0xac,0x65,0x46,0x06,0x46,0x66,0xc6,0x65,0x66,0xa6,0x26,0x65, 0x88,0xf0,0x10,0x43,0x8c,0x45,0x58,0x8c,0x65,0x60,0xd1,0x54,0x46,0x17,0xc6,0x36, 0x04,0x79,0x8e,0x45,0x58,0x84,0x65,0xe0,0x16,0x96,0x26,0xe7,0x32,0xf6,0xd6,0x06, 0x97,0xc6,0x56,0xe6,0x42,0x56,0xe6,0xf6,0x26,0xd7,0x36,0xf7,0x45,0x96,0x36,0x17, 0x26,0xc6,0x56,0x36,0x44,0x78,0x12,0x72,0x61,0x69,0x72,0x2e,0x63,0x6f,0x6d,0x70, 0x69,0x6c,0x65,0x2e,0x66,0x61,0x73,0x74,0x5f,0x6d,0x61,0x74,0x68,0x5f,0x65,0x6e, 0x61,0x62,0x6c,0x65,0x43,0x84,0x67,0x21,0x19,0x84,0xa5,0xc9,0xb9,0x8c,0xbd,0xb5, 0xc1,0xa5,0xb1,0x95,0xb9,0x98,0xc9,0x85,0xb5,0x95,0x89,0xd5,0x99,0x99,0x95,0xc9, 0x7d,0x99,0x95,0xd1,0x8d,0xa1,0x7d,0x95,0xb9,0x85,0x89,0xb1,0x95,0x0d,0x11,0x9e, 0x86,0x51,0x58,0x9a,0x9c,0x8b,0x5c,0x99,0x1b,0x59,0x99,0xdc,0x17,0x5d,0x98,0xdc, 0x59,0x19,0x1d,0xa3,0xb0,0x34,0x39,0x97,0x30,0xb9,0xb3,0x2f,0xba,0x3c,0xb8,0xb2, 0x2f,0xb7,0xb0,0xb6,0x32,0x1a,0x66,0x6c,0x6f,0x61,0x74,0x34,0x64,0xc2,0xd2,0xe4, 0x5c,0xc2,0xe4,0xce,0xbe,0xdc,0xc2,0xda,0xca,0xa8,0x98,0xc9,0x85,0x9d,0x7d,0x8d, 0xbd,0xb1,0xbd,0xc9,0x0d,0x61,0x9e,0x67,0x19,0x1e,0xe8,0x89,0x1e,0xe9,0x99,0x86, 0x08,0x0f,0x45,0x29,0x2c,0x4d,0xce,0xc5,0x4c,0x2e,0xec,0xac,0xad,0xcc,0x8d,0xee, 0x2b,0xcd,0x0d,0xae,0x8e,0x8e,0x4b,0xdd,0x5c,0x99,0x1c,0x0a,0xdb,0xdb,0x98,0x1b, 0x4c,0x0a,0x95,0xb0,0x34,0x39,0x97,0xb1,0x32,0x37,0xba,0x32,0x39,0x3e,0x61,0x69, 0x72,0x2e,0x70,0x65,0x72,0x73,0x70,0x65,0x63,0x74,0x69,0x76,0x65,0x34,0xcc,0xd8, 0xde,0xc2,0xe8,0x64,0x28,0xd4,0xd9,0x0d,0x91,0x96,0xe1,0xb1,0x9e,0xeb,0xc1,0x9e, 0xec,0x81,0x1e,0xed,0x91,0x9e,0x8d,0x4b,0xdd,0x5c,0x99,0x1c,0x0a,0xdb,0xdb,0x98, 0x5b,0x4c,0x0a,0x8b,0xb1,0x37,0xb6,0x37,0xb9,0x21,0xd2,0x22,0x3c,0xd6,0xd3,0x3d, 0xd8,0x93,0x3d,0xd0,0x13,0x3d,0xd2,0xe3,0x71,0x09,0x4b,0x93,0x73,0xa1,0x2b,0xc3, 0xa3,0xab,0x93,0x2b,0xa3,0x14,0x96,0x26,0xe7,0xc2,0xf6,0x36,0x16,0x46,0x97,0xf6, 0xe6,0xf6,0x95,0xe6,0x46,0x56,0x86,0x47,0x25,0x2c,0x4d,0xce,0x65,0x2e,0xac,0x0d, 0x8e,0xad,0x8c,0x18,0x5d,0x19,0x1e,0x5d,0x9d,0x5c,0x99,0x0c,0x19,0x8f,0x19,0xdb, 0x5b,0x18,0x1d,0x0b,0xc8,0x5c,0x58,0x1b,0x1c,0x5b,0x99,0x0f,0x07,0xba,0x32,0xbc, 0x21,0xd4,0x42,0x3c,0x60,0xf0,0x84,0xc1,0x32,0x2c,0xc2,0x23,0x06,0x0f,0xf4,0x8c, 0xc1,0x23,0x3d,0x64,0xc0,0x25,0x2c,0x4d,0xce,0x65,0x2e,0xac,0x0d,0x8e,0xad,0x4c, 0x8e,0xc7,0x5c,0x58,0x1b,0x1c,0x5b,0x99,0x1c,0x87,0xb9,0x36,0xb8,0x21,0xd2,0x72, 0x3c,0x66,0xf0,0x84,0xc1,0x32,0x2c,0xc2,0x03,0x3d,0x67,0xf0,0x48,0x0f,0x1a,0x0c, 0x41,0x1e,0xee,0xf9,0x9e,0x32,0x78,0xd2,0x60,0x88,0x91,0x00,0x4f,0xf5,0xa8,0x01, 0xaf,0xb0,0x34,0xb9,0x96,0x30,0xb6,0xb4,0xb0,0xb9,0x96,0xb9,0xb1,0x37,0xb8,0xb2, 0x39,0x94,0xb6,0xb0,0x34,0x37,0x98,0x94,0x21,0xc4,0xd3,0x06,0x0f,0x1b,0x10,0x0b, 0x4b,0x93,0x6b,0x09,0x63,0x4b,0x0b,0x9b,0x6b,0x99,0x1b,0x7b,0x83,0x2b,0x6b,0xa1, 0x2b,0xc3,0xa3,0xab,0x93,0x2b,0x9b,0x1b,0x62,0x3c,0x6f,0xf0,0xb4,0xc1,0xe3,0x06, 0xc4,0xc2,0xd2,0xe4,0x5a,0xc2,0xd8,0xd2,0xc2,0xe6,0x5a,0xe6,0xc6,0xde,0xe0,0xca, 0x5a,0xe6,0xc2,0xda,0xe0,0xd8,0xca,0xe4,0xe6,0x86,0x18,0x4f,0x1c,0x3c,0x6d,0xf0, 0xc0,0xc1,0x10,0xe2,0x79,0x83,0x27,0x0e,0x46,0x44,0xec,0xc0,0x0e,0xf6,0xd0,0x0e, 0x6e,0xd0,0x0e,0xef,0x40,0x0e,0xf5,0xc0,0x0e,0xe5,0xe0,0x06,0xe6,0xc0,0x0e,0xe1, 0x70,0x0e,0xf3,0x30,0x45,0x08,0x86,0x11,0x0a,0x3b,0xb0,0x83,0x3d,0xb4,0x83,0x1b, 0xa4,0x03,0x39,0x94,0x83,0x3b,0xd0,0xc3,0x94,0xa0,0x18,0xb1,0x84,0x43,0x3a,0xc8, 0x83,0x1b,0xd8,0x43,0x39,0xc8,0xc3,0x3c,0xa4,0xc3,0x3b,0xb8,0xc3,0x94,0xc0,0x18, 0x41,0x85,0x43,0x3a,0xc8,0x83,0x1b,0xb0,0x43,0x38,0xb8,0xc3,0x39,0xd4,0x43,0x38, 0x9c,0x43,0x39,0xfc,0x82,0x3d,0x94,0x83,0x3c,0xcc,0x43,0x3a,0xbc,0x83,0x3b,0x4c, 0x09,0x90,0x11,0x53,0x38,0xa4,0x83,0x3c,0xb8,0xc1,0x38,0xbc,0x43,0x3b,0xc0,0x43, 0x3a,0xb0,0x43,0x39,0xfc,0xc2,0x3b,0xc0,0x03,0x3d,0xa4,0xc3,0x3b,0xb8,0xc3,0x3c, 0x4c,0x19,0x14,0xc6,0x19,0xc1,0x84,0x43,0x3a,0xc8,0x83,0x1b,0x98,0x83,0x3c,0x84, 0xc3,0x39,0xb4,0x43,0x39,0xb8,0x03,0x3d,0x4c,0x09,0xd6,0x00,0x00,0x79,0x18,0x00, 0x00,0xa5,0x00,0x00,0x00,0x33,0x08,0x80,0x1c,0xc4,0xe1,0x1c,0x66,0x14,0x01,0x3d, 0x88,0x43,0x38,0x84,0xc3,0x8c,0x42,0x80,0x07,0x79,0x78,0x07,0x73,0x98,0x71,0x0c, 0xe6,0x00,0x0f,0xed,0x10,0x0e,0xf4,0x80,0x0e,0x33,0x0c,0x42,0x1e,0xc2,0xc1,0x1d, 0xce,0xa1,0x1c,0x66,0x30,0x05,0x3d,0x88,0x43,0x38,0x84,0x83,0x1b,0xcc,0x03,0x3d, 0xc8,0x43,0x3d,0x8c,0x03,0x3d,0xcc,0x78,0x8c,0x74,0x70,0x07,0x7b,0x08,0x07,0x79, 0x48,0x87,0x70,0x70,0x07,0x7a,0x70,0x03,0x76,0x78,0x87,0x70,0x20,0x87,0x19,0xcc, 0x11,0x0e,0xec,0x90,0x0e,0xe1,0x30,0x0f,0x6e,0x30,0x0f,0xe3,0xf0,0x0e,0xf0,0x50, 0x0e,0x33,0x10,0xc4,0x1d,0xde,0x21,0x1c,0xd8,0x21,0x1d,0xc2,0x61,0x1e,0x66,0x30, 0x89,0x3b,0xbc,0x83,0x3b,0xd0,0x43,0x39,0xb4,0x03,0x3c,0xbc,0x83,0x3c,0x84,0x03, 0x3b,0xcc,0xf0,0x14,0x76,0x60,0x07,0x7b,0x68,0x07,0x37,0x68,0x87,0x72,0x68,0x07, 0x37,0x80,0x87,0x70,0x90,0x87,0x70,0x60,0x07,0x76,0x28,0x07,0x76,0xf8,0x05,0x76, 0x78,0x87,0x77,0x80,0x87,0x5f,0x08,0x87,0x71,0x18,0x87,0x72,0x98,0x87,0x79,0x98, 0x81,0x2c,0xee,0xf0,0x0e,0xee,0xe0,0x0e,0xf5,0xc0,0x0e,0xec,0x30,0x03,0x62,0xc8, 0xa1,0x1c,0xe4,0xa1,0x1c,0xcc,0xa1,0x1c,0xe4,0xa1,0x1c,0xdc,0x61,0x1c,0xca,0x21, 0x1c,0xc4,0x81,0x1d,0xca,0x61,0x06,0xd6,0x90,0x43,0x39,0xc8,0x43,0x39,0x98,0x43, 0x39,0xc8,0x43,0x39,0xb8,0xc3,0x38,0x94,0x43,0x38,0x88,0x03,0x3b,0x94,0xc3,0x2f, 0xbc,0x83,0x3c,0xfc,0x82,0x3b,0xd4,0x03,0x3b,0xb0,0xc3,0x0c,0xc7,0x69,0x87,0x70, 0x58,0x87,0x72,0x70,0x83,0x74,0x68,0x07,0x78,0x60,0x87,0x74,0x18,0x87,0x74,0xa0, 0x87,0x19,0xce,0x53,0x0f,0xee,0x00,0x0f,0xf2,0x50,0x0e,0xe4,0x90,0x0e,0xe3,0x40, 0x0f,0xe1,0x20,0x0e,0xec,0x50,0x0e,0x33,0x20,0x28,0x1d,0xdc,0xc1,0x1e,0xc2,0x41, 0x1e,0xd2,0x21,0x1c,0xdc,0x81,0x1e,0xdc,0xe0,0x1c,0xe4,0xe1,0x1d,0xea,0x01,0x1e, 0x66,0x18,0x51,0x38,0xb0,0x43,0x3a,0x9c,0x83,0x3b,0xcc,0x50,0x24,0x76,0x60,0x07, 0x7b,0x68,0x07,0x37,0x60,0x87,0x77,0x78,0x07,0x78,0x98,0x51,0x4c,0xf4,0x90,0x0f, 0xf0,0x50,0x0e,0x33,0x1e,0x6a,0x1e,0xca,0x61,0x1c,0xe8,0x21,0x1d,0xde,0xc1,0x1d, 0x7e,0x01,0x1e,0xe4,0xa1,0x1c,0xcc,0x21,0x1d,0xf0,0x61,0x06,0x54,0x85,0x83,0x38, 0xcc,0xc3,0x3b,0xb0,0x43,0x3d,0xd0,0x43,0x39,0xfc,0xc2,0x3c,0xe4,0x43,0x3b,0x88, 0xc3,0x3b,0xb0,0xc3,0x8c,0xc5,0x0a,0x87,0x79,0x98,0x87,0x77,0x18,0x87,0x74,0x08, 0x07,0x7a,0x28,0x07,0x72,0x98,0x81,0x5c,0xe3,0x10,0x0e,0xec,0xc0,0x0e,0xe5,0x50, 0x0e,0xf3,0x30,0x23,0xc1,0xd2,0x41,0x1e,0xe4,0xe1,0x17,0xd8,0xe1,0x1d,0xde,0x01, 0x1e,0x66,0x48,0x19,0x3b,0xb0,0x83,0x3d,0xb4,0x83,0x1b,0x84,0xc3,0x38,0x8c,0x43, 0x39,0xcc,0xc3,0x3c,0xb8,0xc1,0x39,0xc8,0xc3,0x3b,0xd4,0x03,0x3c,0xcc,0x48,0xb4, 0x71,0x08,0x07,0x76,0x60,0x07,0x71,0x08,0x87,0x71,0x58,0x87,0x19,0xdb,0xc6,0x0e, 0xec,0x60,0x0f,0xed,0xe0,0x06,0xf0,0x20,0x0f,0xe5,0x30,0x0f,0xe5,0x20,0x0f,0xf6, 0x50,0x0e,0x6e,0x10,0x0e,0xe3,0x30,0x0e,0xe5,0x30,0x0f,0xf3,0xe0,0x06,0xe9,0xe0, 0x0e,0xe4,0x50,0x0e,0xf8,0x30,0x23,0xe2,0xec,0x61,0x1c,0xc2,0x81,0x1d,0xd8,0xe1, 0x17,0xec,0x21,0x1d,0xe6,0x21,0x1d,0xc4,0x21,0x1d,0xd8,0x21,0x1d,0xe8,0x21,0x1f, 0x66,0x20,0x9d,0x3b,0xbc,0x43,0x3d,0xb8,0x03,0x39,0x94,0x83,0x39,0xcc,0x58,0xbc, 0x70,0x70,0x07,0x77,0x78,0x07,0x7a,0x08,0x07,0x7a,0x48,0x87,0x77,0x70,0x87,0x19, 0xce,0x87,0x0e,0xe5,0x10,0x0e,0xf0,0x10,0x0e,0xec,0xc0,0x0e,0xef,0x30,0x0e,0xf3, 0x90,0x0e,0xf4,0x50,0x0e,0x33,0x28,0x30,0x08,0x87,0x74,0x90,0x07,0x37,0x30,0x87, 0x7a,0x70,0x87,0x71,0xa0,0x87,0x74,0x78,0x07,0x77,0xf8,0x85,0x73,0x90,0x87,0x77, 0xa8,0x07,0x78,0x98,0x07,0x00,0x00,0x00,0x00,0x71,0x20,0x00,0x00,0x08,0x00,0x00, 0x00,0x16,0xb0,0x01,0x48,0xe4,0x4b,0x00,0xf3,0x2c,0xc4,0x3f,0x11,0xd7,0x44,0x45, 0xc4,0x6f,0x0f,0x7e,0x85,0x17,0xb7,0x6d,0x00,0x05,0x03,0x20,0x0d,0x0d,0x00,0x00, 0x00,0x61,0x20,0x00,0x00,0x11,0x00,0x00,0x00,0x13,0x04,0x41,0x2c,0x10,0x00,0x00, 0x00,0x04,0x00,0x00,0x00,0xc4,0x46,0x00,0x48,0x8d,0x00,0xd4,0x00,0x89,0x19,0x00, 0x02,0x23,0x00,0x00,0x00,0x23,0x06,0xca,0x10,0x44,0x87,0x91,0x0c,0x05,0x11,0x58, 0x90,0xc8,0x67,0xb6,0x81,0x08,0x80,0x0c,0x02,0x62,0x00,0x00,0x00,0x02,0x00,0x00, 0x00,0x5b,0x06,0xe0,0x90,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; /* Metal Vertex Shader Source (iOS Simulator) */ static const uint8_t nk_vs_source_metal_sim[672] = { 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x76, 0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 0x6c,0x6f,0x61,0x74,0x32,0x20,0x64,0x69,0x73,0x70,0x5f,0x73,0x69,0x7a,0x65,0x3b, 0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e, 0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, 0x74,0x32,0x20,0x75,0x76,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, 0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, 0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c, 0x6f,0x63,0x6e,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, 0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20, 0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b, 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69, 0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70, 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62, 0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, 0x6f,0x61,0x74,0x32,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x20,0x5b, 0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x31,0x29,0x5d,0x5d,0x3b, 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f, 0x72,0x30,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x32, 0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20, 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28, 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74, 0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61, 0x6e,0x74,0x20,0x76,0x73,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x26,0x20,0x5f,0x32, 0x32,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x29, 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74, 0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f, 0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d, 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x28,0x69,0x6e,0x2e,0x70,0x6f,0x73, 0x69,0x74,0x69,0x6f,0x6e,0x20,0x2f,0x20,0x5f,0x32,0x32,0x2e,0x64,0x69,0x73,0x70, 0x5f,0x73,0x69,0x7a,0x65,0x29,0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, 0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x32, 0x2e,0x30,0x2c,0x20,0x2d,0x32,0x2e,0x30,0x29,0x2c,0x20,0x30,0x2e,0x35,0x2c,0x20, 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x75,0x76, 0x20,0x3d,0x20,0x69,0x6e,0x2e,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x30,0x3b, 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, 0x20,0x69,0x6e,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; /* Metal Fragment Shader Source (iOS Simulator) */ static const uint8_t nk_fs_source_metal_sim[436] = { 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72, 0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d, 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, 0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, 0x75,0x76,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29, 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63, 0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, 0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65, 0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69, 0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b, 0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78, 0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, 0x78,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d, 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x20,0x5b,0x5b, 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a, 0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75, 0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, 0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74,0x65,0x78, 0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x2c,0x20,0x69,0x6e,0x2e, 0x75,0x76,0x29,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a, 0x7d,0x0a,0x0a,0x00, }; #endif
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/image/image.cc
C++
#include "image.hh" #include "engine.hh" #include "physfs.h" #include "stb_image.h" #include "stb_image_write.h" #include <cstring> #include <cstdlib> #include <algorithm> #ifdef _WIN32 #define strcasecmp _stricmp #endif namespace joy { namespace modules { // ImageData implementation ImageData::ImageData() : data_(nullptr) , width_(0) , height_(0) , dataSize_(0) , format_(PixelFormat::RGBA8) { } ImageData::~ImageData() { if (data_) { free(data_); } } int ImageData::getBytesPerPixel() const { switch (format_) { case PixelFormat::R8: return 1; case PixelFormat::RG8: return 2; case PixelFormat::RGBA8: return 4; case PixelFormat::R16: return 2; case PixelFormat::RG16: return 4; case PixelFormat::RGBA16: return 8; default: return 4; } } bool ImageData::create(int width, int height, PixelFormat format) { if (width <= 0 || height <= 0) { return false; } if (data_) { free(data_); } width_ = width; height_ = height; format_ = format; int bpp = getBytesPerPixel(); dataSize_ = static_cast<size_t>(width * height * bpp); data_ = static_cast<uint8_t *>(calloc(1, dataSize_)); // Zero-initialized return data_ != nullptr; } bool ImageData::create(int width, int height, PixelFormat format, const uint8_t *data, size_t dataSize) { if (!create(width, height, format)) { return false; } size_t copySize = std::min(dataSize, dataSize_); memcpy(data_, data, copySize); return true; } bool ImageData::loadFromMemory(const uint8_t *data, size_t size) { int w, h, channels; // Force RGBA output uint8_t *pixels = stbi_load_from_memory(data, static_cast<int>(size), &w, &h, &channels, 4); if (!pixels) { return false; } if (data_) { free(data_); } width_ = w; height_ = h; format_ = PixelFormat::RGBA8; dataSize_ = static_cast<size_t>(w * h * 4); data_ = static_cast<uint8_t *>(malloc(dataSize_)); if (!data_) { stbi_image_free(pixels); return false; } memcpy(data_, pixels, dataSize_); stbi_image_free(pixels); return true; } bool ImageData::loadFromFile(const char *filename) { PHYSFS_File *file = PHYSFS_openRead(filename); if (!file) { return false; } PHYSFS_sint64 fileSize = PHYSFS_fileLength(file); if (fileSize < 0) { PHYSFS_close(file); return false; } uint8_t *fileData = static_cast<uint8_t *>(malloc(fileSize)); if (!fileData) { PHYSFS_close(file); return false; } PHYSFS_sint64 bytesRead = PHYSFS_readBytes(file, fileData, fileSize); PHYSFS_close(file); if (bytesRead != fileSize) { free(fileData); return false; } bool result = loadFromMemory(fileData, static_cast<size_t>(fileSize)); free(fileData); return result; } const char *ImageData::getFormatString() const { switch (format_) { case PixelFormat::R8: return "r8"; case PixelFormat::RG8: return "rg8"; case PixelFormat::RGBA8: return "rgba8"; case PixelFormat::R16: return "r16"; case PixelFormat::RG16: return "rg16"; case PixelFormat::RGBA16: return "rgba16"; default: return "rgba8"; } } void ImageData::getPixel(int x, int y, float *r, float *g, float *b, float *a) const { *r = *g = *b = 0.0f; *a = 1.0f; if (!data_ || x < 0 || x >= width_ || y < 0 || y >= height_) { return; } int bpp = getBytesPerPixel(); size_t offset = static_cast<size_t>((y * width_ + x) * bpp); switch (format_) { case PixelFormat::RGBA8: *r = data_[offset + 0] / 255.0f; *g = data_[offset + 1] / 255.0f; *b = data_[offset + 2] / 255.0f; *a = data_[offset + 3] / 255.0f; break; case PixelFormat::R8: *r = data_[offset] / 255.0f; break; case PixelFormat::RG8: *r = data_[offset + 0] / 255.0f; *g = data_[offset + 1] / 255.0f; break; case PixelFormat::RGBA16: { const uint16_t *p = reinterpret_cast<const uint16_t *>(&data_[offset]); *r = p[0] / 65535.0f; *g = p[1] / 65535.0f; *b = p[2] / 65535.0f; *a = p[3] / 65535.0f; break; } case PixelFormat::R16: { const uint16_t *p = reinterpret_cast<const uint16_t *>(&data_[offset]); *r = p[0] / 65535.0f; break; } case PixelFormat::RG16: { const uint16_t *p = reinterpret_cast<const uint16_t *>(&data_[offset]); *r = p[0] / 65535.0f; *g = p[1] / 65535.0f; break; } } } void ImageData::setPixel(int x, int y, float r, float g, float b, float a) { if (!data_ || x < 0 || x >= width_ || y < 0 || y >= height_) { return; } // Clamp values to 0-1 range r = std::max(0.0f, std::min(1.0f, r)); g = std::max(0.0f, std::min(1.0f, g)); b = std::max(0.0f, std::min(1.0f, b)); a = std::max(0.0f, std::min(1.0f, a)); int bpp = getBytesPerPixel(); size_t offset = static_cast<size_t>((y * width_ + x) * bpp); switch (format_) { case PixelFormat::RGBA8: data_[offset + 0] = static_cast<uint8_t>(r * 255.0f); data_[offset + 1] = static_cast<uint8_t>(g * 255.0f); data_[offset + 2] = static_cast<uint8_t>(b * 255.0f); data_[offset + 3] = static_cast<uint8_t>(a * 255.0f); break; case PixelFormat::R8: data_[offset] = static_cast<uint8_t>(r * 255.0f); break; case PixelFormat::RG8: data_[offset + 0] = static_cast<uint8_t>(r * 255.0f); data_[offset + 1] = static_cast<uint8_t>(g * 255.0f); break; case PixelFormat::RGBA16: { uint16_t *p = reinterpret_cast<uint16_t *>(&data_[offset]); p[0] = static_cast<uint16_t>(r * 65535.0f); p[1] = static_cast<uint16_t>(g * 65535.0f); p[2] = static_cast<uint16_t>(b * 65535.0f); p[3] = static_cast<uint16_t>(a * 65535.0f); break; } case PixelFormat::R16: { uint16_t *p = reinterpret_cast<uint16_t *>(&data_[offset]); p[0] = static_cast<uint16_t>(r * 65535.0f); break; } case PixelFormat::RG16: { uint16_t *p = reinterpret_cast<uint16_t *>(&data_[offset]); p[0] = static_cast<uint16_t>(r * 65535.0f); p[1] = static_cast<uint16_t>(g * 65535.0f); break; } } } void ImageData::paste(const ImageData *source, int dx, int dy, int sx, int sy, int sw, int sh) { if (!source || !data_ || !source->data_) { return; } // Clamp source region to source bounds if (sx < 0) { sw += sx; dx -= sx; sx = 0; } if (sy < 0) { sh += sy; dy -= sy; sy = 0; } if (sx + sw > source->width_) { sw = source->width_ - sx; } if (sy + sh > source->height_) { sh = source->height_ - sy; } // Clamp destination region to destination bounds if (dx < 0) { sw += dx; sx -= dx; dx = 0; } if (dy < 0) { sh += dy; sy -= dy; dy = 0; } if (dx + sw > width_) { sw = width_ - dx; } if (dy + sh > height_) { sh = height_ - dy; } if (sw <= 0 || sh <= 0) { return; } // Copy pixel by pixel (handles format conversion) for (int y = 0; y < sh; y++) { for (int x = 0; x < sw; x++) { float r, g, b, a; source->getPixel(sx + x, sy + y, &r, &g, &b, &a); setPixel(dx + x, dy + y, r, g, b, a); } } } // Callback for stb_image_write to write to memory buffer struct WriteContext { uint8_t *data; size_t size; size_t capacity; }; static void stb_write_func(void *context, void *data, int size) { WriteContext *ctx = static_cast<WriteContext *>(context); if (ctx->size + size > ctx->capacity) { size_t newCapacity = std::max(ctx->capacity * 2, ctx->size + size); uint8_t *newData = static_cast<uint8_t *>(realloc(ctx->data, newCapacity)); if (!newData) { return; // Allocation failed } ctx->data = newData; ctx->capacity = newCapacity; } memcpy(ctx->data + ctx->size, data, size); ctx->size += size; } uint8_t *ImageData::encode(ImageFormat format, size_t *outSize) const { if (!data_ || width_ <= 0 || height_ <= 0) { *outSize = 0; return nullptr; } // For encoding, we need RGBA8 data - convert if necessary const uint8_t *encodeData = data_; uint8_t *tempData = nullptr; if (format_ != PixelFormat::RGBA8) { // Convert to RGBA8 for encoding tempData = static_cast<uint8_t *>(malloc(width_ * height_ * 4)); if (!tempData) { *outSize = 0; return nullptr; } for (int y = 0; y < height_; y++) { for (int x = 0; x < width_; x++) { float r, g, b, a; getPixel(x, y, &r, &g, &b, &a); size_t offset = (y * width_ + x) * 4; tempData[offset + 0] = static_cast<uint8_t>(r * 255.0f); tempData[offset + 1] = static_cast<uint8_t>(g * 255.0f); tempData[offset + 2] = static_cast<uint8_t>(b * 255.0f); tempData[offset + 3] = static_cast<uint8_t>(a * 255.0f); } } encodeData = tempData; } WriteContext ctx; ctx.data = static_cast<uint8_t *>(malloc(1024)); ctx.size = 0; ctx.capacity = 1024; int result = 0; switch (format) { case ImageFormat::PNG: result = stbi_write_png_to_func(stb_write_func, &ctx, width_, height_, 4, encodeData, width_ * 4); break; case ImageFormat::BMP: result = stbi_write_bmp_to_func(stb_write_func, &ctx, width_, height_, 4, encodeData); break; case ImageFormat::TGA: result = stbi_write_tga_to_func(stb_write_func, &ctx, width_, height_, 4, encodeData); break; case ImageFormat::JPG: result = stbi_write_jpg_to_func(stb_write_func, &ctx, width_, height_, 4, encodeData, 90); break; } if (tempData) { free(tempData); } if (!result) { free(ctx.data); *outSize = 0; return nullptr; } *outSize = ctx.size; return ctx.data; } PixelFormat ImageData::parseFormat(const char *str) { if (!str) return PixelFormat::RGBA8; if (strcmp(str, "r8") == 0) return PixelFormat::R8; if (strcmp(str, "rg8") == 0) return PixelFormat::RG8; if (strcmp(str, "rgba8") == 0) return PixelFormat::RGBA8; if (strcmp(str, "r16") == 0) return PixelFormat::R16; if (strcmp(str, "rg16") == 0) return PixelFormat::RG16; if (strcmp(str, "rgba16") == 0) return PixelFormat::RGBA16; return PixelFormat::RGBA8; } ImageFormat ImageData::parseImageFormat(const char *str) { if (!str) return ImageFormat::PNG; if (strcmp(str, "png") == 0) return ImageFormat::PNG; if (strcmp(str, "tga") == 0) return ImageFormat::TGA; if (strcmp(str, "bmp") == 0) return ImageFormat::BMP; if (strcmp(str, "jpg") == 0 || strcmp(str, "jpeg") == 0) return ImageFormat::JPG; return ImageFormat::PNG; } const char *ImageData::imageFormatToString(ImageFormat format) { switch (format) { case ImageFormat::PNG: return "png"; case ImageFormat::TGA: return "tga"; case ImageFormat::BMP: return "bmp"; case ImageFormat::JPG: return "jpg"; default: return "png"; } } // Image module implementation Image::Image(Engine *engine) : engine_(engine) { } Image::~Image() { } bool Image::isCompressed(const char *filename) const { // Check file extension for compressed texture formats if (!filename) return false; const char *ext = strrchr(filename, '.'); if (!ext) return false; // Common compressed texture formats if (strcasecmp(ext, ".dds") == 0) return true; if (strcasecmp(ext, ".ktx") == 0) return true; if (strcasecmp(ext, ".pvr") == 0) return true; if (strcasecmp(ext, ".astc") == 0) return true; return false; } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/image/image.hh
C++ Header
#pragma once #include <cstdint> #include <cstddef> #include <string> namespace js { class Context; class Value; } namespace joy { class Engine; namespace modules { // Pixel format enum enum class PixelFormat { RGBA8, // 8 bits per channel (32 bpp) RGBA - default RGBA16, // 16 bits per channel (64 bpp) RGBA R8, // Single channel 8-bit RG8, // Two channels 8-bit each R16, // Single channel 16-bit RG16, // Two channels 16-bit each }; // Image format for encoding enum class ImageFormat { PNG, TGA, BMP, JPG, }; // Raw (decoded) image data - CPU-side pixel manipulation // This is different from graphics::Image which is a GPU texture class ImageData { public: ImageData(); ~ImageData(); // Create empty ImageData with specified dimensions bool create(int width, int height, PixelFormat format = PixelFormat::RGBA8); // Create ImageData with initial data (data is copied) bool create(int width, int height, PixelFormat format, const uint8_t *data, size_t dataSize); // Load from encoded image file data (PNG, JPG, etc.) bool loadFromMemory(const uint8_t *data, size_t size); // Load from file via PhysFS bool loadFromFile(const char *filename); // Get dimensions int getWidth() const { return width_; } int getHeight() const { return height_; } // Get pixel format PixelFormat getFormat() const { return format_; } const char *getFormatString() const; // Get raw pixel data uint8_t *getData() { return data_; } const uint8_t *getData() const { return data_; } size_t getDataSize() const { return dataSize_; } // Get bytes per pixel for current format int getBytesPerPixel() const; // Get/set pixel (normalized 0-1 range for components) void getPixel(int x, int y, float *r, float *g, float *b, float *a) const; void setPixel(int x, int y, float r, float g, float b, float a); // Paste from another ImageData void paste(const ImageData *source, int dx, int dy, int sx, int sy, int sw, int sh); // Encode to image format, returns encoded data (caller must free with free()) uint8_t *encode(ImageFormat format, size_t *outSize) const; // Helper: parse format string static PixelFormat parseFormat(const char *str); static ImageFormat parseImageFormat(const char *str); static const char *imageFormatToString(ImageFormat format); private: uint8_t *data_; int width_; int height_; size_t dataSize_; PixelFormat format_; }; // Image module - factory for ImageData class Image { public: Image(Engine *engine); ~Image(); // Check if file is a compressed texture format bool isCompressed(const char *filename) const; // Initialize JS bindings static void initJS(js::Context &ctx, js::Value &joy); private: Engine *engine_; }; } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/image/image_js.cc
C++
#include "js/js.hh" #include "image.hh" #include "engine.hh" #include "physfs.h" #include <cstring> #include <cstdlib> namespace joy { namespace modules { // ImageData class for JS static js::ClassID imagedata_class_id = 0; static void imagedata_finalizer(void *opaque) { ImageData *data = static_cast<ImageData *>(opaque); delete data; } // Helper to get ImageData from this value static ImageData *getImageData(js::FunctionArgs &args) { js::Value thisVal = args.thisValue(); return static_cast<ImageData *>(js::ClassBuilder::getOpaque(thisVal, imagedata_class_id)); } // Helper to get Image module from JS context static Image *getImageModule(js::FunctionArgs &args) { Engine *engine = args.getContextOpaque<Engine>(); return engine ? engine->getImageModule() : nullptr; } // ImageData methods // imageData:getWidth() static void js_imagedata_getWidth(js::FunctionArgs &args) { ImageData *data = getImageData(args); args.returnValue(js::Value::number(data ? data->getWidth() : 0)); } // imageData:getHeight() static void js_imagedata_getHeight(js::FunctionArgs &args) { ImageData *data = getImageData(args); args.returnValue(js::Value::number(data ? data->getHeight() : 0)); } // imageData:getDimensions() static void js_imagedata_getDimensions(js::FunctionArgs &args) { ImageData *data = getImageData(args); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::number(data ? data->getWidth() : 0)); arr.setProperty(args.context(), 1u, js::Value::number(data ? data->getHeight() : 0)); args.returnValue(std::move(arr)); } // imageData:getFormat() static void js_imagedata_getFormat(js::FunctionArgs &args) { ImageData *data = getImageData(args); if (!data) { args.returnValue(js::Value::string(args.context(), "rgba8")); return; } args.returnValue(js::Value::string(args.context(), data->getFormatString())); } // imageData:getPixel(x, y) static void js_imagedata_getPixel(js::FunctionArgs &args) { ImageData *data = getImageData(args); if (!data || args.length() < 2) { args.returnUndefined(); return; } int x = args.arg(0).toInt32(); int y = args.arg(1).toInt32(); float r, g, b, a; data->getPixel(x, y, &r, &g, &b, &a); js::Value arr = js::Value::array(args.context()); arr.setProperty(args.context(), 0u, js::Value::number(r)); arr.setProperty(args.context(), 1u, js::Value::number(g)); arr.setProperty(args.context(), 2u, js::Value::number(b)); arr.setProperty(args.context(), 3u, js::Value::number(a)); args.returnValue(std::move(arr)); } // imageData:setPixel(x, y, r, g, b, a) or setPixel(x, y, [r, g, b, a]) static void js_imagedata_setPixel(js::FunctionArgs &args) { ImageData *data = getImageData(args); if (!data || args.length() < 3) { args.returnUndefined(); return; } int x = args.arg(0).toInt32(); int y = args.arg(1).toInt32(); float r, g, b, a = 1.0f; // Check if third arg is an array (table) js::Value colorArg = args.arg(2); if (colorArg.isArray()) { js::Context &ctx = args.context(); r = static_cast<float>(colorArg.getProperty(ctx, 0u).toFloat64()); g = static_cast<float>(colorArg.getProperty(ctx, 1u).toFloat64()); b = static_cast<float>(colorArg.getProperty(ctx, 2u).toFloat64()); js::Value alphaVal = colorArg.getProperty(ctx, 3u); if (!alphaVal.isUndefined()) { a = static_cast<float>(alphaVal.toFloat64()); } } else { // Individual arguments r = static_cast<float>(args.arg(2).toFloat64()); g = static_cast<float>(args.arg(3).toFloat64()); b = static_cast<float>(args.arg(4).toFloat64()); if (args.length() >= 6) { a = static_cast<float>(args.arg(5).toFloat64()); } } data->setPixel(x, y, r, g, b, a); args.returnUndefined(); } // imageData:paste(source, dx, dy, sx, sy, sw, sh) static void js_imagedata_paste(js::FunctionArgs &args) { ImageData *data = getImageData(args); if (!data || args.length() < 7) { args.returnUndefined(); return; } js::Value sourceVal = args.arg(0); ImageData *source = static_cast<ImageData *>(js::ClassBuilder::getOpaque(sourceVal, imagedata_class_id)); if (!source) { args.returnUndefined(); return; } int dx = args.arg(1).toInt32(); int dy = args.arg(2).toInt32(); int sx = args.arg(3).toInt32(); int sy = args.arg(4).toInt32(); int sw = args.arg(5).toInt32(); int sh = args.arg(6).toInt32(); data->paste(source, dx, dy, sx, sy, sw, sh); args.returnUndefined(); } // imageData:mapPixel(func [, x, y, width, height]) static void js_imagedata_mapPixel(js::FunctionArgs &args) { ImageData *data = getImageData(args); if (!data || args.length() < 1) { args.returnUndefined(); return; } js::Value func = args.arg(0); if (!func.isFunction()) { args.returnUndefined(); return; } int startX = 0, startY = 0; int mapWidth = data->getWidth(); int mapHeight = data->getHeight(); if (args.length() >= 3) { startX = args.arg(1).toInt32(); startY = args.arg(2).toInt32(); } if (args.length() >= 5) { mapWidth = args.arg(3).toInt32(); mapHeight = args.arg(4).toInt32(); } js::Context &ctx = args.context(); js::Value global = ctx.globalObject(); for (int y = startY; y < startY + mapHeight; y++) { for (int x = startX; x < startX + mapWidth; x++) { float r, g, b, a; data->getPixel(x, y, &r, &g, &b, &a); js::Value funcArgs[6]; funcArgs[0] = js::Value::number(x); funcArgs[1] = js::Value::number(y); funcArgs[2] = js::Value::number(r); funcArgs[3] = js::Value::number(g); funcArgs[4] = js::Value::number(b); funcArgs[5] = js::Value::number(a); js::Value result = ctx.call(func, global, funcArgs, 6); if (result.isException()) { js::Value exception = ctx.getException(); ctx.printException(exception); args.returnUndefined(); return; } // Result should be an array [r, g, b, a] if (result.isArray()) { float newR = static_cast<float>(result.getProperty(ctx, 0u).toFloat64()); float newG = static_cast<float>(result.getProperty(ctx, 1u).toFloat64()); float newB = static_cast<float>(result.getProperty(ctx, 2u).toFloat64()); float newA = static_cast<float>(result.getProperty(ctx, 3u).toFloat64()); data->setPixel(x, y, newR, newG, newB, newA); } } } args.returnUndefined(); } // imageData:encode(format [, filename]) static void js_imagedata_encode(js::FunctionArgs &args) { ImageData *data = getImageData(args); if (!data || args.length() < 1) { args.returnValue(js::Value::null()); return; } std::string formatStr = args.arg(0).toString(args.context()); ImageFormat format = ImageData::parseImageFormat(formatStr.c_str()); size_t encodedSize = 0; uint8_t *encoded = data->encode(format, &encodedSize); if (!encoded) { args.returnValue(js::Value::null()); return; } // If filename is provided, write to file if (args.length() >= 2) { std::string filename = args.arg(1).toString(args.context()); // Write via PhysFS (to save directory) PHYSFS_File *file = PHYSFS_openWrite(filename.c_str()); if (file) { PHYSFS_writeBytes(file, encoded, encodedSize); PHYSFS_close(file); } } // Return as ArrayBuffer (FileData equivalent) js::Value buffer = js::Value::arrayBuffer(args.context(), encoded, encodedSize); free(encoded); args.returnValue(std::move(buffer)); } // imageData:getData() - returns raw pixel data as ArrayBuffer static void js_imagedata_getData(js::FunctionArgs &args) { ImageData *data = getImageData(args); if (!data || !data->getData()) { args.returnValue(js::Value::null()); return; } js::Value buffer = js::Value::arrayBuffer(args.context(), data->getData(), data->getDataSize()); args.returnValue(std::move(buffer)); } // Module functions // joy.image.newImageData(width, height [, format] [, data]) // joy.image.newImageData(filename) static void js_image_newImageData(js::FunctionArgs &args) { if (args.length() < 1) { args.returnValue(js::Value::null()); return; } ImageData *imageData = new ImageData(); bool success = false; js::Value firstArg = args.arg(0); if (firstArg.isString()) { // Load from file std::string filename = firstArg.toString(args.context()); success = imageData->loadFromFile(filename.c_str()); } else if (firstArg.isNumber()) { // Create with dimensions int width = firstArg.toInt32(); int height = args.arg(1).toInt32(); PixelFormat format = PixelFormat::RGBA8; // Check for format argument if (args.length() >= 3) { js::Value formatArg = args.arg(2); if (formatArg.isString()) { std::string formatStr = formatArg.toString(args.context()); format = ImageData::parseFormat(formatStr.c_str()); } } // Check for data argument if (args.length() >= 4) { js::Value dataArg = args.arg(3); if (dataArg.isString()) { // String data (raw bytes) std::string dataStr = dataArg.toString(args.context()); success = imageData->create(width, height, format, reinterpret_cast<const uint8_t *>(dataStr.data()), dataStr.size()); } else if (dataArg.isArrayBuffer() || dataArg.isTypedArray()) { // ArrayBuffer data const uint8_t *bufData = static_cast<const uint8_t *>(dataArg.arrayBufferData()); size_t bufLen = dataArg.arrayBufferLength(); success = imageData->create(width, height, format, bufData, bufLen); } else { success = imageData->create(width, height, format); } } else if (args.length() >= 3 && !args.arg(2).isString()) { // Third arg is data, not format js::Value dataArg = args.arg(2); if (dataArg.isString()) { std::string dataStr = dataArg.toString(args.context()); success = imageData->create(width, height, format, reinterpret_cast<const uint8_t *>(dataStr.data()), dataStr.size()); } else if (dataArg.isArrayBuffer() || dataArg.isTypedArray()) { const uint8_t *bufData = static_cast<const uint8_t *>(dataArg.arrayBufferData()); size_t bufLen = dataArg.arrayBufferLength(); success = imageData->create(width, height, format, bufData, bufLen); } else { success = imageData->create(width, height, format); } } else { success = imageData->create(width, height, format); } } else if (firstArg.isArrayBuffer() || firstArg.isTypedArray()) { // Load from ArrayBuffer (FileData) const uint8_t *bufData = static_cast<const uint8_t *>(firstArg.arrayBufferData()); size_t bufLen = firstArg.arrayBufferLength(); success = imageData->loadFromMemory(bufData, bufLen); } if (!success) { delete imageData; args.returnValue(js::Value::null()); return; } js::Value obj = js::ClassBuilder::newInstance(args.context(), imagedata_class_id); js::ClassBuilder::setOpaque(obj, imageData); args.returnValue(std::move(obj)); } // joy.image.isCompressed(filename) static void js_image_isCompressed(js::FunctionArgs &args) { Image *mod = getImageModule(args); if (!mod || args.length() < 1) { args.returnValue(js::Value::boolean(false)); return; } js::Value firstArg = args.arg(0); if (firstArg.isString()) { std::string filename = firstArg.toString(args.context()); args.returnValue(js::Value::boolean(mod->isCompressed(filename.c_str()))); } else { // FileData - would need to check magic bytes args.returnValue(js::Value::boolean(false)); } } void Image::initJS(js::Context &ctx, js::Value &joy) { // Register ImageData class js::ClassDef imageDataDef; imageDataDef.name = "ImageData"; imageDataDef.finalizer = imagedata_finalizer; imagedata_class_id = js::ClassBuilder::registerClass(ctx, imageDataDef); // Create ImageData prototype with methods js::Value imageDataProto = js::ModuleBuilder(ctx, "__imagedata_proto__") .function("getWidth", js_imagedata_getWidth, 0) .function("getHeight", js_imagedata_getHeight, 0) .function("getDimensions", js_imagedata_getDimensions, 0) .function("getFormat", js_imagedata_getFormat, 0) .function("getPixel", js_imagedata_getPixel, 2) .function("setPixel", js_imagedata_setPixel, 6) .function("paste", js_imagedata_paste, 7) .function("mapPixel", js_imagedata_mapPixel, 5) .function("encode", js_imagedata_encode, 2) .function("getData", js_imagedata_getData, 0) .build(); js::ClassBuilder::setPrototype(ctx, imagedata_class_id, imageDataProto); // Register image module functions js::ModuleBuilder(ctx, "image") .function("newImageData", js_image_newImageData, 4) .function("isCompressed", js_image_isCompressed, 1) .attachTo(joy); } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/info/info.cc
C++
#include "info.hh" namespace joy { namespace modules { Info::Info() { } Info::~Info() { } const char *Info::getVersion() { return "dev-alpha"; } const char *Info::getJSEngineName() { return "QuickJS"; } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/info/info.hh
C++ Header
#pragma once namespace js { class Context; class Value; } // namespace js namespace joy { namespace modules { class Info { public: Info(); ~Info(); static const char *getVersion(); static const char *getJSEngineName(); // Initialize JS bindings static void initJS(js::Context &ctx, js::Value &joy); }; } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/info/info_js.cc
C++
#include "info.hh" #include "js/js.hh" namespace joy { namespace modules { static void js_info_getVersion(js::FunctionArgs &args) { args.returnValue(js::Value::string(args.context(), Info::getVersion())); } static void js_info_getJSEngineName(js::FunctionArgs &args) { args.returnValue(js::Value::string(args.context(), Info::getJSEngineName())); } void Info::initJS(js::Context &ctx, js::Value &joy) { js::ModuleBuilder(ctx, "info") .function("getVersion", js_info_getVersion) .function("getJSEngineName", js_info_getJSEngineName) .attachTo(joy); } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/joystick/joystick.cc
C++
#include "joystick.hh" #include "engine.hh" #include <cstring> #include <algorithm> #include <cstdio> #include <limits> namespace joy { namespace modules { // Hat name mappings static const char *hat_names[] = { "c", // Centered "u", // Up "r", // Right "d", // Down "l", // Left "ru", // RightUp "rd", // RightDown "lu", // LeftUp "ld", // LeftDown }; // Gamepad axis name mappings static const char *gamepad_axis_names[] = { "", // Invalid "leftx", "lefty", "rightx", "righty", "triggerleft", "triggerright", }; // Gamepad button name mappings static const char *gamepad_button_names[] = { "", // Invalid "a", "b", "x", "y", "back", "guide", "start", "leftstick", "rightstick", "leftshoulder", "rightshoulder", "dpup", "dpdown", "dpleft", "dpright", "misc1", "paddle1", "paddle2", "paddle3", "paddle4", "touchpad", }; // Convert SDL hat value to JoystickHat static JoystickHat sdlHatToHat(Uint8 sdlHat) { switch (sdlHat) { case SDL_HAT_CENTERED: return JoystickHat::Centered; case SDL_HAT_UP: return JoystickHat::Up; case SDL_HAT_RIGHT: return JoystickHat::Right; case SDL_HAT_DOWN: return JoystickHat::Down; case SDL_HAT_LEFT: return JoystickHat::Left; case SDL_HAT_RIGHTUP: return JoystickHat::RightUp; case SDL_HAT_RIGHTDOWN: return JoystickHat::RightDown; case SDL_HAT_LEFTUP: return JoystickHat::LeftUp; case SDL_HAT_LEFTDOWN: return JoystickHat::LeftDown; default: return JoystickHat::Centered; } } // Convert GamepadAxis to SDL_GamepadAxis static SDL_GamepadAxis gamepadAxisToSDL(GamepadAxis axis) { switch (axis) { case GamepadAxis::LeftX: return SDL_GAMEPAD_AXIS_LEFTX; case GamepadAxis::LeftY: return SDL_GAMEPAD_AXIS_LEFTY; case GamepadAxis::RightX: return SDL_GAMEPAD_AXIS_RIGHTX; case GamepadAxis::RightY: return SDL_GAMEPAD_AXIS_RIGHTY; case GamepadAxis::TriggerLeft: return SDL_GAMEPAD_AXIS_LEFT_TRIGGER; case GamepadAxis::TriggerRight: return SDL_GAMEPAD_AXIS_RIGHT_TRIGGER; default: return SDL_GAMEPAD_AXIS_INVALID; } } // Convert SDL_GamepadAxis to GamepadAxis static GamepadAxis sdlToGamepadAxis(SDL_GamepadAxis sdlAxis) { switch (sdlAxis) { case SDL_GAMEPAD_AXIS_LEFTX: return GamepadAxis::LeftX; case SDL_GAMEPAD_AXIS_LEFTY: return GamepadAxis::LeftY; case SDL_GAMEPAD_AXIS_RIGHTX: return GamepadAxis::RightX; case SDL_GAMEPAD_AXIS_RIGHTY: return GamepadAxis::RightY; case SDL_GAMEPAD_AXIS_LEFT_TRIGGER: return GamepadAxis::TriggerLeft; case SDL_GAMEPAD_AXIS_RIGHT_TRIGGER: return GamepadAxis::TriggerRight; default: return GamepadAxis::Invalid; } } // Convert GamepadButton to SDL_GamepadButton static SDL_GamepadButton gamepadButtonToSDL(GamepadButton button) { switch (button) { case GamepadButton::A: return SDL_GAMEPAD_BUTTON_SOUTH; case GamepadButton::B: return SDL_GAMEPAD_BUTTON_EAST; case GamepadButton::X: return SDL_GAMEPAD_BUTTON_WEST; case GamepadButton::Y: return SDL_GAMEPAD_BUTTON_NORTH; case GamepadButton::Back: return SDL_GAMEPAD_BUTTON_BACK; case GamepadButton::Guide: return SDL_GAMEPAD_BUTTON_GUIDE; case GamepadButton::Start: return SDL_GAMEPAD_BUTTON_START; case GamepadButton::LeftStick: return SDL_GAMEPAD_BUTTON_LEFT_STICK; case GamepadButton::RightStick: return SDL_GAMEPAD_BUTTON_RIGHT_STICK; case GamepadButton::LeftShoulder: return SDL_GAMEPAD_BUTTON_LEFT_SHOULDER; case GamepadButton::RightShoulder: return SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER; case GamepadButton::DPadUp: return SDL_GAMEPAD_BUTTON_DPAD_UP; case GamepadButton::DPadDown: return SDL_GAMEPAD_BUTTON_DPAD_DOWN; case GamepadButton::DPadLeft: return SDL_GAMEPAD_BUTTON_DPAD_LEFT; case GamepadButton::DPadRight: return SDL_GAMEPAD_BUTTON_DPAD_RIGHT; case GamepadButton::Misc1: return SDL_GAMEPAD_BUTTON_MISC1; case GamepadButton::Paddle1: return SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1; case GamepadButton::Paddle2: return SDL_GAMEPAD_BUTTON_LEFT_PADDLE1; case GamepadButton::Paddle3: return SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2; case GamepadButton::Paddle4: return SDL_GAMEPAD_BUTTON_LEFT_PADDLE2; case GamepadButton::Touchpad: return SDL_GAMEPAD_BUTTON_TOUCHPAD; default: return SDL_GAMEPAD_BUTTON_INVALID; } } // Convert SDL_GamepadButton to GamepadButton static GamepadButton sdlToGamepadButton(SDL_GamepadButton sdlButton) { switch (sdlButton) { case SDL_GAMEPAD_BUTTON_SOUTH: return GamepadButton::A; case SDL_GAMEPAD_BUTTON_EAST: return GamepadButton::B; case SDL_GAMEPAD_BUTTON_WEST: return GamepadButton::X; case SDL_GAMEPAD_BUTTON_NORTH: return GamepadButton::Y; case SDL_GAMEPAD_BUTTON_BACK: return GamepadButton::Back; case SDL_GAMEPAD_BUTTON_GUIDE: return GamepadButton::Guide; case SDL_GAMEPAD_BUTTON_START: return GamepadButton::Start; case SDL_GAMEPAD_BUTTON_LEFT_STICK: return GamepadButton::LeftStick; case SDL_GAMEPAD_BUTTON_RIGHT_STICK: return GamepadButton::RightStick; case SDL_GAMEPAD_BUTTON_LEFT_SHOULDER: return GamepadButton::LeftShoulder; case SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER: return GamepadButton::RightShoulder; case SDL_GAMEPAD_BUTTON_DPAD_UP: return GamepadButton::DPadUp; case SDL_GAMEPAD_BUTTON_DPAD_DOWN: return GamepadButton::DPadDown; case SDL_GAMEPAD_BUTTON_DPAD_LEFT: return GamepadButton::DPadLeft; case SDL_GAMEPAD_BUTTON_DPAD_RIGHT: return GamepadButton::DPadRight; case SDL_GAMEPAD_BUTTON_MISC1: return GamepadButton::Misc1; case SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1: return GamepadButton::Paddle1; case SDL_GAMEPAD_BUTTON_LEFT_PADDLE1: return GamepadButton::Paddle2; case SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2: return GamepadButton::Paddle3; case SDL_GAMEPAD_BUTTON_LEFT_PADDLE2: return GamepadButton::Paddle4; case SDL_GAMEPAD_BUTTON_TOUCHPAD: return GamepadButton::Touchpad; default: return GamepadButton::Invalid; } } // Clamp axis value to [-1, 1] static float clampAxis(float x) { if (x < -1.0f) return -1.0f; if (x > 1.0f) return 1.0f; return x; } // Joystick implementation Joystick::Joystick(SDL_Joystick *joystick, SDL_JoystickID id) : joystick_(joystick) , gamepad_(nullptr) , id_(id) , instance_id_(SDL_GetJoystickID(joystick)) , vibration_left_(0.0f) , vibration_right_(0.0f) { // Try to open as gamepad if possible if (SDL_IsGamepad(id)) { gamepad_ = SDL_OpenGamepad(id); } } Joystick::~Joystick() { close(); } void Joystick::close() { if (gamepad_) { SDL_CloseGamepad(gamepad_); gamepad_ = nullptr; } if (joystick_) { SDL_CloseJoystick(joystick_); joystick_ = nullptr; } } bool Joystick::isConnected() const { return joystick_ && SDL_JoystickConnected(joystick_); } const char *Joystick::getName() const { if (!joystick_) return ""; const char *name = SDL_GetJoystickName(joystick_); return name ? name : ""; } std::string Joystick::getGUID() const { if (!joystick_) return ""; SDL_GUID guid = SDL_GetJoystickGUID(joystick_); char guidStr[64]; SDL_GUIDToString(guid, guidStr, sizeof(guidStr)); return std::string(guidStr); } void Joystick::getDeviceInfo(int &vendorID, int &productID, int &productVersion) const { if (!joystick_) { vendorID = productID = productVersion = 0; return; } vendorID = SDL_GetJoystickVendor(joystick_); productID = SDL_GetJoystickProduct(joystick_); productVersion = SDL_GetJoystickProductVersion(joystick_); } int Joystick::getAxisCount() const { if (!joystick_) return 0; return SDL_GetNumJoystickAxes(joystick_); } float Joystick::getAxis(int axisIndex) const { if (!joystick_) return 0.0f; if (axisIndex < 0 || axisIndex >= getAxisCount()) return 0.0f; Sint16 value = SDL_GetJoystickAxis(joystick_, axisIndex); // Normalize from [-32768, 32767] to [-1.0, 1.0] return clampAxis(static_cast<float>(value) / 32767.0f); } std::vector<float> Joystick::getAxes() const { std::vector<float> axes; int count = getAxisCount(); axes.reserve(count); for (int i = 0; i < count; i++) { axes.push_back(getAxis(i)); } return axes; } int Joystick::getButtonCount() const { if (!joystick_) return 0; return SDL_GetNumJoystickButtons(joystick_); } bool Joystick::isDown(const std::vector<int> &buttons) const { if (!joystick_) return false; int buttonCount = getButtonCount(); for (int button : buttons) { // Love2D uses 1-indexed buttons int idx = button - 1; if (idx >= 0 && idx < buttonCount) { if (SDL_GetJoystickButton(joystick_, idx)) { return true; } } } return false; } int Joystick::getHatCount() const { if (!joystick_) return 0; return SDL_GetNumJoystickHats(joystick_); } JoystickHat Joystick::getHat(int hatIndex) const { if (!joystick_) return JoystickHat::Centered; if (hatIndex < 0 || hatIndex >= getHatCount()) return JoystickHat::Centered; Uint8 value = SDL_GetJoystickHat(joystick_, hatIndex); return sdlHatToHat(value); } bool Joystick::isGamepad() const { return gamepad_ != nullptr; } float Joystick::getGamepadAxis(GamepadAxis axis) const { if (!gamepad_) return 0.0f; SDL_GamepadAxis sdlAxis = gamepadAxisToSDL(axis); if (sdlAxis == SDL_GAMEPAD_AXIS_INVALID) return 0.0f; Sint16 value = SDL_GetGamepadAxis(gamepad_, sdlAxis); // Normalize from [-32768, 32767] to [-1.0, 1.0] return clampAxis(static_cast<float>(value) / 32767.0f); } bool Joystick::isGamepadDown(const std::vector<GamepadButton> &buttons) const { if (!gamepad_) return false; for (GamepadButton button : buttons) { SDL_GamepadButton sdlButton = gamepadButtonToSDL(button); if (sdlButton != SDL_GAMEPAD_BUTTON_INVALID) { if (SDL_GetGamepadButton(gamepad_, sdlButton)) { return true; } } } return false; } std::string Joystick::getGamepadMappingString() const { if (!gamepad_) return ""; char *mapping = SDL_GetGamepadMapping(gamepad_); if (!mapping) return ""; std::string result(mapping); SDL_free(mapping); return result; } bool Joystick::isVibrationSupported() { // Rumble disabled for now return false; } bool Joystick::setVibration(float left, float right, float duration) { // Rumble disabled for now return false; } bool Joystick::setVibration() { // Rumble disabled for now return false; } void Joystick::getVibration(float &left, float &right) { left = vibration_left_; right = vibration_right_; } bool Joystick::getHatFromName(const char *name, JoystickHat &out) { for (int i = 0; i < static_cast<int>(JoystickHat::MaxEnum); i++) { if (strcmp(name, hat_names[i]) == 0) { out = static_cast<JoystickHat>(i); return true; } } return false; } const char *Joystick::getHatName(JoystickHat hat) { int idx = static_cast<int>(hat); if (idx >= 0 && idx < static_cast<int>(JoystickHat::MaxEnum)) { return hat_names[idx]; } return ""; } bool Joystick::getGamepadAxisFromName(const char *name, GamepadAxis &out) { for (int i = 1; i < static_cast<int>(GamepadAxis::MaxEnum); i++) { if (strcmp(name, gamepad_axis_names[i]) == 0) { out = static_cast<GamepadAxis>(i); return true; } } return false; } const char *Joystick::getGamepadAxisName(GamepadAxis axis) { int idx = static_cast<int>(axis); if (idx > 0 && idx < static_cast<int>(GamepadAxis::MaxEnum)) { return gamepad_axis_names[idx]; } return ""; } bool Joystick::getGamepadButtonFromName(const char *name, GamepadButton &out) { for (int i = 1; i < static_cast<int>(GamepadButton::MaxEnum); i++) { if (strcmp(name, gamepad_button_names[i]) == 0) { out = static_cast<GamepadButton>(i); return true; } } return false; } const char *Joystick::getGamepadButtonName(GamepadButton button) { int idx = static_cast<int>(button); if (idx > 0 && idx < static_cast<int>(GamepadButton::MaxEnum)) { return gamepad_button_names[idx]; } return ""; } // JoystickModule implementation JoystickModule::JoystickModule(Engine *engine) : engine_(engine) { } JoystickModule::~JoystickModule() { for (Joystick *joystick : joysticks_) { delete joystick; } joysticks_.clear(); joystick_map_.clear(); } bool JoystickModule::init() { // SDL joystick subsystem is initialized with SDL_INIT_GAMEPAD which includes SDL_INIT_JOYSTICK if (!SDL_InitSubSystem(SDL_INIT_GAMEPAD)) { fprintf(stderr, "Failed to initialize SDL gamepad subsystem: %s\n", SDL_GetError()); return false; } // Open all connected joysticks int count = 0; SDL_JoystickID *joystickIds = SDL_GetJoysticks(&count); if (joystickIds) { for (int i = 0; i < count; i++) { addJoystick(joystickIds[i]); } SDL_free(joystickIds); } return true; } int JoystickModule::getJoystickCount() const { return static_cast<int>(joysticks_.size()); } Joystick *JoystickModule::getJoystick(int index) { if (index < 0 || index >= static_cast<int>(joysticks_.size())) { return nullptr; } return joysticks_[index]; } Joystick *JoystickModule::getJoystickFromID(SDL_JoystickID instanceId) { auto it = joystick_map_.find(instanceId); if (it != joystick_map_.end()) { return it->second; } return nullptr; } Joystick *JoystickModule::addJoystick(SDL_JoystickID deviceId) { // First, check if this joystick is already open by trying to get its instance ID // We need to temporarily open it to check SDL_Joystick *sdlJoystick = SDL_OpenJoystick(deviceId); if (!sdlJoystick) { fprintf(stderr, "Failed to open joystick %d: %s\n", deviceId, SDL_GetError()); return nullptr; } SDL_JoystickID instanceId = SDL_GetJoystickID(sdlJoystick); // Check if we already have this joystick auto it = joystick_map_.find(instanceId); if (it != joystick_map_.end()) { // Already have this joystick, close the duplicate handle and return nullptr // to indicate no new joystick was added SDL_CloseJoystick(sdlJoystick); return nullptr; } Joystick *joystick = new Joystick(sdlJoystick, deviceId); joysticks_.push_back(joystick); joystick_map_[joystick->getInstanceID()] = joystick; return joystick; } void JoystickModule::removeJoystick(SDL_JoystickID instanceId) { auto mapIt = joystick_map_.find(instanceId); if (mapIt == joystick_map_.end()) { return; } Joystick *joystick = mapIt->second; joystick_map_.erase(mapIt); auto vecIt = std::find(joysticks_.begin(), joysticks_.end(), joystick); if (vecIt != joysticks_.end()) { joysticks_.erase(vecIt); } delete joystick; } std::string JoystickModule::getGamepadMappingString(const std::string &guid) const { SDL_GUID sdlGuid = SDL_StringToGUID(guid.c_str()); char *mapping = SDL_GetGamepadMappingForGUID(sdlGuid); if (!mapping) return ""; std::string result(mapping); SDL_free(mapping); return result; } void JoystickModule::loadGamepadMappings(const std::string &mappings) { // SDL3 requires loading from RWops SDL_IOStream *rw = SDL_IOFromConstMem(mappings.c_str(), mappings.length()); if (rw) { SDL_AddGamepadMappingsFromIO(rw, true); } } std::string JoystickModule::saveGamepadMappings() const { // Get all current gamepad mappings std::string result; int count = 0; char **mappings = SDL_GetGamepadMappings(&count); if (mappings) { for (int i = 0; i < count; i++) { result += mappings[i]; result += "\n"; SDL_free(mappings[i]); } SDL_free(mappings); } return result; } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/joystick/joystick.hh
C++ Header
#pragma once #include "SDL3/SDL.h" #include <string> #include <vector> #include <unordered_map> namespace js { class Context; class Value; } namespace joy { class Engine; namespace modules { // Joystick hat values (matching Love2D) enum class JoystickHat { Centered, Up, Right, Down, Left, RightUp, RightDown, LeftUp, LeftDown, MaxEnum }; // Gamepad axis values (matching Love2D) enum class GamepadAxis { Invalid, LeftX, LeftY, RightX, RightY, TriggerLeft, TriggerRight, MaxEnum }; // Gamepad button values (matching Love2D) enum class GamepadButton { Invalid, A, B, X, Y, Back, Guide, Start, LeftStick, RightStick, LeftShoulder, RightShoulder, DPadUp, DPadDown, DPadLeft, DPadRight, Misc1, Paddle1, Paddle2, Paddle3, Paddle4, Touchpad, MaxEnum }; // Input type for gamepad mappings enum class JoystickInputType { Axis, Button, Hat, MaxEnum }; // Individual joystick instance class Joystick { public: Joystick(SDL_Joystick *joystick, SDL_JoystickID id); ~Joystick(); // Disable copy Joystick(const Joystick &) = delete; Joystick &operator=(const Joystick &) = delete; // Connection bool isConnected() const; void close(); // Basic info const char *getName() const; std::string getGUID() const; SDL_JoystickID getID() const { return id_; } SDL_JoystickID getInstanceID() const { return instance_id_; } void getDeviceInfo(int &vendorID, int &productID, int &productVersion) const; // Axes int getAxisCount() const; float getAxis(int axisIndex) const; std::vector<float> getAxes() const; // Buttons int getButtonCount() const; bool isDown(const std::vector<int> &buttons) const; // Hats int getHatCount() const; JoystickHat getHat(int hatIndex) const; // Gamepad bool isGamepad() const; float getGamepadAxis(GamepadAxis axis) const; bool isGamepadDown(const std::vector<GamepadButton> &buttons) const; std::string getGamepadMappingString() const; // Vibration bool isVibrationSupported(); bool setVibration(float left, float right, float duration = -1.0f); bool setVibration(); // Stop vibration void getVibration(float &left, float &right); // Convert string to enum static bool getHatFromName(const char *name, JoystickHat &out); static const char *getHatName(JoystickHat hat); static bool getGamepadAxisFromName(const char *name, GamepadAxis &out); static const char *getGamepadAxisName(GamepadAxis axis); static bool getGamepadButtonFromName(const char *name, GamepadButton &out); static const char *getGamepadButtonName(GamepadButton button); // SDL handle SDL_Joystick *getHandle() const { return joystick_; } SDL_Gamepad *getGamepadHandle() const { return gamepad_; } private: SDL_Joystick *joystick_; SDL_Gamepad *gamepad_; SDL_JoystickID id_; SDL_JoystickID instance_id_; float vibration_left_; float vibration_right_; }; // Joystick module (manages all joysticks) class JoystickModule { public: JoystickModule(Engine *engine); ~JoystickModule(); // Initialize SDL joystick subsystem bool init(); // Get joystick count int getJoystickCount() const; // Get all joysticks const std::vector<Joystick *> &getJoysticks() const { return joysticks_; } // Get joystick by index Joystick *getJoystick(int index); // Get joystick by instance ID Joystick *getJoystickFromID(SDL_JoystickID instanceId); // Add/remove joystick (called from event handlers) Joystick *addJoystick(SDL_JoystickID deviceId); void removeJoystick(SDL_JoystickID instanceId); // Gamepad mappings std::string getGamepadMappingString(const std::string &guid) const; void loadGamepadMappings(const std::string &mappings); std::string saveGamepadMappings() const; // JS bindings static void initJS(js::Context &ctx, js::Value &joy); private: Engine *engine_; std::vector<Joystick *> joysticks_; std::unordered_map<SDL_JoystickID, Joystick *> joystick_map_; }; } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University
src/modules/joystick/joystick_js.cc
C++
#include "js/js.hh" #include "joystick.hh" #include "engine.hh" namespace joy { namespace modules { // Class ID for Joystick objects static js::ClassID joystick_class_id = 0; // Helper to get JoystickModule from JS context static JoystickModule *getJoystickModule(js::FunctionArgs &args) { Engine *engine = args.getContextOpaque<Engine>(); return engine ? engine->getJoystickModule() : nullptr; } // Joystick finalizer static void joystick_finalizer(void *opaque) { // Joysticks are owned by JoystickModule, so we don't delete them here // The opaque pointer is just a reference } // Helper to get Joystick from this value static Joystick *getJoystick(js::FunctionArgs &args) { js::Value thisVal = args.thisValue(); return static_cast<Joystick *>(js::ClassBuilder::getOpaque(thisVal, joystick_class_id)); } // === Joystick object methods === // joystick:isConnected() static void js_joystick_isConnected(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); args.returnValue(js::Value::boolean(joystick && joystick->isConnected())); } // joystick:getName() static void js_joystick_getName(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); if (!joystick) { args.returnValue(js::Value::string(args.context(), "")); return; } args.returnValue(js::Value::string(args.context(), joystick->getName())); } // joystick:getID() - returns [id, instanceId] static void js_joystick_getID(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); if (!joystick) { js::Value result = js::Value::array(args.context()); result.setProperty(args.context(), 0u, js::Value::number(0)); result.setProperty(args.context(), 1u, js::Value::null()); args.returnValue(std::move(result)); return; } // Get the index in the joysticks array for the "id" JoystickModule *module = getJoystickModule(args); int index = 0; if (module) { const auto &joysticks = module->getJoysticks(); for (size_t i = 0; i < joysticks.size(); i++) { if (joysticks[i] == joystick) { index = static_cast<int>(i) + 1; // 1-indexed like Love2D break; } } } js::Value result = js::Value::array(args.context()); result.setProperty(args.context(), 0u, js::Value::number(index)); if (joystick->isConnected()) { result.setProperty(args.context(), 1u, js::Value::number(static_cast<int32_t>(joystick->getInstanceID()))); } else { result.setProperty(args.context(), 1u, js::Value::null()); } args.returnValue(std::move(result)); } // joystick:getGUID() static void js_joystick_getGUID(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); if (!joystick) { args.returnValue(js::Value::string(args.context(), "")); return; } args.returnValue(js::Value::string(args.context(), joystick->getGUID().c_str())); } // joystick:getDeviceInfo() - returns [vendorId, productId, productVersion] static void js_joystick_getDeviceInfo(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); if (!joystick) { js::Value result = js::Value::array(args.context()); result.setProperty(args.context(), 0u, js::Value::number(0)); result.setProperty(args.context(), 1u, js::Value::number(0)); result.setProperty(args.context(), 2u, js::Value::number(0)); args.returnValue(std::move(result)); return; } int vendorId, productId, productVersion; joystick->getDeviceInfo(vendorId, productId, productVersion); js::Value result = js::Value::array(args.context()); result.setProperty(args.context(), 0u, js::Value::number(vendorId)); result.setProperty(args.context(), 1u, js::Value::number(productId)); result.setProperty(args.context(), 2u, js::Value::number(productVersion)); args.returnValue(std::move(result)); } // joystick:getAxisCount() static void js_joystick_getAxisCount(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); args.returnValue(js::Value::number(joystick ? joystick->getAxisCount() : 0)); } // joystick:getAxis(axis) static void js_joystick_getAxis(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); if (!joystick || args.length() < 1) { args.returnValue(js::Value::number(0)); return; } int axis = args.arg(0).toInt32(); args.returnValue(js::Value::number(joystick->getAxis(axis - 1))); // 1-indexed in Love2D } // joystick:getAxes() - returns array of all axis values static void js_joystick_getAxes(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); js::Value result = js::Value::array(args.context()); if (joystick) { std::vector<float> axes = joystick->getAxes(); for (size_t i = 0; i < axes.size(); i++) { result.setProperty(args.context(), static_cast<uint32_t>(i), js::Value::number(axes[i])); } } args.returnValue(std::move(result)); } // joystick:getButtonCount() static void js_joystick_getButtonCount(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); args.returnValue(js::Value::number(joystick ? joystick->getButtonCount() : 0)); } // joystick:isDown(button, ...) static void js_joystick_isDown(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); if (!joystick || args.length() < 1) { args.returnValue(js::Value::boolean(false)); return; } std::vector<int> buttons; for (int i = 0; i < args.length(); i++) { buttons.push_back(args.arg(i).toInt32()); } args.returnValue(js::Value::boolean(joystick->isDown(buttons))); } // joystick:getHatCount() static void js_joystick_getHatCount(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); args.returnValue(js::Value::number(joystick ? joystick->getHatCount() : 0)); } // joystick:getHat(hat) static void js_joystick_getHat(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); if (!joystick || args.length() < 1) { args.returnValue(js::Value::string(args.context(), "c")); return; } int hat = args.arg(0).toInt32(); JoystickHat hatValue = joystick->getHat(hat - 1); // 1-indexed args.returnValue(js::Value::string(args.context(), Joystick::getHatName(hatValue))); } // joystick:isGamepad() static void js_joystick_isGamepad(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); args.returnValue(js::Value::boolean(joystick && joystick->isGamepad())); } // joystick:getGamepadAxis(axis) static void js_joystick_getGamepadAxis(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); if (!joystick || args.length() < 1) { args.returnValue(js::Value::number(0)); return; } std::string axisName = args.arg(0).toString(args.context()); GamepadAxis axis; if (!Joystick::getGamepadAxisFromName(axisName.c_str(), axis)) { args.returnValue(js::Value::number(0)); return; } args.returnValue(js::Value::number(joystick->getGamepadAxis(axis))); } // joystick:isGamepadDown(button, ...) static void js_joystick_isGamepadDown(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); if (!joystick || args.length() < 1) { args.returnValue(js::Value::boolean(false)); return; } std::vector<GamepadButton> buttons; for (int i = 0; i < args.length(); i++) { std::string buttonName = args.arg(i).toString(args.context()); GamepadButton button; if (Joystick::getGamepadButtonFromName(buttonName.c_str(), button)) { buttons.push_back(button); } } args.returnValue(js::Value::boolean(joystick->isGamepadDown(buttons))); } // joystick:getGamepadMappingString() static void js_joystick_getGamepadMappingString(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); if (!joystick) { args.returnValue(js::Value::null()); return; } std::string mapping = joystick->getGamepadMappingString(); if (mapping.empty()) { args.returnValue(js::Value::null()); return; } args.returnValue(js::Value::string(args.context(), mapping.c_str())); } // joystick:isVibrationSupported() static void js_joystick_isVibrationSupported(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); args.returnValue(js::Value::boolean(joystick && joystick->isVibrationSupported())); } // joystick:setVibration(left, right, duration) or joystick:setVibration() static void js_joystick_setVibration(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); if (!joystick) { args.returnValue(js::Value::boolean(false)); return; } if (args.length() < 2) { // Stop vibration args.returnValue(js::Value::boolean(joystick->setVibration())); return; } float left = static_cast<float>(args.arg(0).toFloat64()); float right = static_cast<float>(args.arg(1).toFloat64()); float duration = -1.0f; if (args.length() >= 3) { duration = static_cast<float>(args.arg(2).toFloat64()); } args.returnValue(js::Value::boolean(joystick->setVibration(left, right, duration))); } // joystick:getVibration() - returns [left, right] static void js_joystick_getVibration(js::FunctionArgs &args) { Joystick *joystick = getJoystick(args); js::Value result = js::Value::array(args.context()); if (joystick) { float left, right; joystick->getVibration(left, right); result.setProperty(args.context(), 0u, js::Value::number(left)); result.setProperty(args.context(), 1u, js::Value::number(right)); } else { result.setProperty(args.context(), 0u, js::Value::number(0)); result.setProperty(args.context(), 1u, js::Value::number(0)); } args.returnValue(std::move(result)); } // === Module functions === // joy.joystick.getJoystickCount() static void js_getJoystickCount(js::FunctionArgs &args) { JoystickModule *module = getJoystickModule(args); args.returnValue(js::Value::number(module ? module->getJoystickCount() : 0)); } // joy.joystick.getJoysticks() - returns array of Joystick objects static void js_getJoysticks(js::FunctionArgs &args) { JoystickModule *module = getJoystickModule(args); js::Value result = js::Value::array(args.context()); if (module) { const auto &joysticks = module->getJoysticks(); for (size_t i = 0; i < joysticks.size(); i++) { js::Value obj = js::ClassBuilder::newInstance(args.context(), joystick_class_id); js::ClassBuilder::setOpaque(obj, joysticks[i]); result.setProperty(args.context(), static_cast<uint32_t>(i), std::move(obj)); } } args.returnValue(std::move(result)); } // joy.joystick.getGamepadMappingString(guid) static void js_getGamepadMappingString(js::FunctionArgs &args) { JoystickModule *module = getJoystickModule(args); if (!module || args.length() < 1) { args.returnValue(js::Value::null()); return; } std::string guid = args.arg(0).toString(args.context()); std::string mapping = module->getGamepadMappingString(guid); if (mapping.empty()) { args.returnValue(js::Value::null()); return; } args.returnValue(js::Value::string(args.context(), mapping.c_str())); } // joy.joystick.loadGamepadMappings(mappings) static void js_loadGamepadMappings(js::FunctionArgs &args) { JoystickModule *module = getJoystickModule(args); if (!module || args.length() < 1) { args.returnUndefined(); return; } std::string mappings = args.arg(0).toString(args.context()); module->loadGamepadMappings(mappings); args.returnUndefined(); } // joy.joystick.saveGamepadMappings() static void js_saveGamepadMappings(js::FunctionArgs &args) { JoystickModule *module = getJoystickModule(args); if (!module) { args.returnValue(js::Value::string(args.context(), "")); return; } std::string mappings = module->saveGamepadMappings(); args.returnValue(js::Value::string(args.context(), mappings.c_str())); } // Create a Joystick JS object from a C++ Joystick pointer js::Value createJoystickObject(js::Context &ctx, Joystick *joystick) { js::Value obj = js::ClassBuilder::newInstance(ctx, joystick_class_id); js::ClassBuilder::setOpaque(obj, joystick); return obj; } void JoystickModule::initJS(js::Context &ctx, js::Value &joy) { // Register Joystick class js::ClassDef joystickDef; joystickDef.name = "Joystick"; joystickDef.finalizer = joystick_finalizer; joystick_class_id = js::ClassBuilder::registerClass(ctx, joystickDef); // Create Joystick prototype with methods js::Value proto = js::ModuleBuilder(ctx, "__joystick_proto__") .function("isConnected", js_joystick_isConnected, 0) .function("getName", js_joystick_getName, 0) .function("getID", js_joystick_getID, 0) .function("getGUID", js_joystick_getGUID, 0) .function("getDeviceInfo", js_joystick_getDeviceInfo, 0) .function("getAxisCount", js_joystick_getAxisCount, 0) .function("getAxis", js_joystick_getAxis, 1) .function("getAxes", js_joystick_getAxes, 0) .function("getButtonCount", js_joystick_getButtonCount, 0) .function("isDown", js_joystick_isDown, 1) .function("getHatCount", js_joystick_getHatCount, 0) .function("getHat", js_joystick_getHat, 1) .function("isGamepad", js_joystick_isGamepad, 0) .function("getGamepadAxis", js_joystick_getGamepadAxis, 1) .function("isGamepadDown", js_joystick_isGamepadDown, 1) .function("getGamepadMappingString", js_joystick_getGamepadMappingString, 0) .function("isVibrationSupported", js_joystick_isVibrationSupported, 0) .function("setVibration", js_joystick_setVibration, 3) .function("getVibration", js_joystick_getVibration, 0) .build(); js::ClassBuilder::setPrototype(ctx, joystick_class_id, proto); // Create joystick module js::ModuleBuilder(ctx, "joystick") .function("getJoystickCount", js_getJoystickCount, 0) .function("getJoysticks", js_getJoysticks, 0) .function("getGamepadMappingString", js_getGamepadMappingString, 1) .function("loadGamepadMappings", js_loadGamepadMappings, 1) .function("saveGamepadMappings", js_saveGamepadMappings, 0) .attachTo(joy); } // Exported function to create Joystick JS objects from C++ (used by engine for callbacks) js::Value createJoystickJSObject(js::Context &ctx, Joystick *joystick) { js::Value obj = js::ClassBuilder::newInstance(ctx, joystick_class_id); js::ClassBuilder::setOpaque(obj, joystick); return obj; } } // namespace modules } // namespace joy
zyedidia/joy
1
A framework for building 2D desktop games in JavaScript, with a Love2D-inspired API
C++
zyedidia
Zachary Yedidia
Stanford University