array with 4 bytes per item for (var i = 0; i < (width * height) / 4; i += 1) { // Gets the array sent from C# const screenDataItem = BINDING.mono_array_get(screenData, i); for (var mask = 0; mask <= 24; mask += 8) { let dataIndex = y * (width * 4) + x; setSinglePixel(imageData, dataIndex, colors, (screenDataItem >> mask) & 0xff); // Build the image from top to bottom, left to right if (y >= height - 1) { y = 0; x += 4; } else { y += 1; } } } context.putImageData(imageData, 0, 0); }; function setSinglePixel(imageData, dataIndex, colors, colorIndex) { const color = BINDING.mono_array_get(colors, colorIndex); imageData.data[dataIndex] = color & 0xff; imageData.data[dataIndex + 1] = (color >> 8) & 0xff; imageData.data[dataIndex + 2] = (color >> 16) & 0xff; imageData.data[dataIndex + 3] = 255; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 // Gets the array sent from C# const screenDataItem = BINDING.mono_array_get(screenData, i); window.renderWithColorsAndScreenDataUnmarshalled = (screenData, colors) => { 1 // JS receives an array with 4 bytes per item 2 for (var i = 0; i < (width * height) / 4; i += 1) { 3 4 5 for (var mask = 0; mask <= 24; mask += 8) { 6 let dataIndex = y * (width * 4) + x; 7 setSinglePixel(imageData, dataIndex, colors, 8 (screenDataItem >> mask) & 0xff); 9 // Build the image from top to bottom, left to right 10 if (y >= height - 1) { y = 0; x += 4; } else { y += 1; } 11 } 12 } 13 context.putImageData(imageData, 0, 0); 14 }; 15 function setSinglePixel(imageData, dataIndex, colors, colorIndex) { 16 const color = BINDING.mono_array_get(colors, colorIndex); 17 imageData.data[dataIndex] = color & 0xff; 18 imageData.data[dataIndex + 1] = (color >> 8) & 0xff; 19 imageData.data[dataIndex + 2] = (color >> 16) & 0xff; 20 imageData.data[dataIndex + 3] = 255; 21 } 22 // Build the image from top to bottom, left to right if (y >= height - 1) { y = 0; x += 4; } else { y += 1; } window.renderWithColorsAndScreenDataUnmarshalled = (screenData, colors) => { 1 // JS receives an array with 4 bytes per item 2 for (var i = 0; i < (width * height) / 4; i += 1) { 3 // Gets the array sent from C# 4 const screenDataItem = BINDING.mono_array_get(screenData, i); 5 for (var mask = 0; mask <= 24; mask += 8) { 6 let dataIndex = y * (width * 4) + x; 7 setSinglePixel(imageData, dataIndex, colors, 8 (screenDataItem >> mask) & 0xff); 9 10 11 } 12 } 13 context.putImageData(imageData, 0, 0); 14 }; 15 function setSinglePixel(imageData, dataIndex, colors, colorIndex) { 16 const color = BINDING.mono_array_get(colors, colorIndex); 17 imageData.data[dataIndex] = color & 0xff; 18 imageData.data[dataIndex + 1] = (color >> 8) & 0xff; 19 imageData.data[dataIndex + 2] = (color >> 16) & 0xff; 20 imageData.data[dataIndex + 3] = 255; 21 } 22 let dataIndex = y * (width * 4) + x; setSinglePixel(imageData, dataIndex, colors, function setSinglePixel(imageData, dataIndex, colors, colorIndex) { const color = BINDING.mono_array_get(colors, colorIndex); imageData.data[dataIndex] = color & 0xff; imageData.data[dataIndex + 1] = (color >> 8) & 0xff; imageData.data[dataIndex + 2] = (color >> 16) & 0xff; imageData.data[dataIndex + 3] = 255; } window.renderWithColorsAndScreenDataUnmarshalled = (screenData, colors) => { 1 // JS receives an array with 4 bytes per item 2 for (var i = 0; i < (width * height) / 4; i += 1) { 3 // Gets the array sent from C# 4 const screenDataItem = BINDING.mono_array_get(screenData, i); 5 for (var mask = 0; mask <= 24; mask += 8) { 6 7 8 (screenDataItem >> mask) & 0xff); 9 // Build the image from top to bottom, left to right 10 if (y >= height - 1) { y = 0; x += 4; } else { y += 1; } 11 } 12 } 13 context.putImageData(imageData, 0, 0); 14 }; 15 16 17 18 19 20 21 22 window.renderWithColorsAndScreenDataUnmarshalled = (screenData, colors) => { // JS receives an array with 4 bytes per item for (var i = 0; i < (width * height) / 4; i += 1) { // Gets the array sent from C# const screenDataItem = BINDING.mono_array_get(screenData, i); for (var mask = 0; mask <= 24; mask += 8) { let dataIndex = y * (width * 4) + x; setSinglePixel(imageData, dataIndex, colors, (screenDataItem >> mask) & 0xff); // Build the image from top to bottom, left to right if (y >= height - 1) { y = 0; x += 4; } else { y += 1; } } } context.putImageData(imageData, 0, 0); }; function setSinglePixel(imageData, dataIndex, colors, colorIndex) { const color = BINDING.mono_array_get(colors, colorIndex); imageData.data[dataIndex] = color & 0xff; imageData.data[dataIndex + 1] = (color >> 8) & 0xff; imageData.data[dataIndex + 2] = (color >> 16) & 0xff; imageData.data[dataIndex + 3] = 255; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 window.renderWithColorsAndScreenDataUnmarshalled = (screenData, colors) => { // JS receives an array with 4 bytes per item for (var i = 0; i < (width * height) / 4; i += 1) { // Gets the array sent from C# const screenDataItem = BINDING.mono_array_get(screenData, i); for (var mask = 0; mask <= 24; mask += 8) { let dataIndex = y * (width * 4) + x; setSinglePixel(imageData, dataIndex, colors, (screenDataItem >> mask) & 0xff); // Build the image from top to bottom, left to right if (y >= height - 1) { y = 0; x += 4; } else { y += 1; } } } context.putImageData(imageData, 0, 0); }; function setSinglePixel(imageData, dataIndex, colors, colorIndex) { const color = BINDING.mono_array_get(colors, colorIndex); imageData.data[dataIndex] = color & 0xff; imageData.data[dataIndex + 1] = (color >> 8) & 0xff; imageData.data[dataIndex + 2] = (color >> 16) & 0xff; imageData.data[dataIndex + 3] = 255; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Frame rendering // Somwhere in the Doom Engine's graphics module var args = new object[] { screen.Data, colors, 320, 200 }; // Send the frame buffer to JS DoomApplication.WebAssemblyJSRuntime.InvokeUnmarshalled<byte[], uint[], int> ("renderWithColorsAndScreenDataUnmarshalled", screen.Data, colors); 1 2 3 4 5