Skip to content

Instantly share code, notes, and snippets.

View nokotan's full-sized avatar

かめのこにょこにょこ nokotan

View GitHub Profile
mergeInto(LibraryManager.library, {
glfwGetKeysSiv3D: function (windowid) {
var window = GLFW.WindowFromId(windowid);
if (!window) return 0;
if (!window.keysBuffer) {
window.keysBuffer = Module._malloc(349 /* GLFW_KEY_LAST + 1 */)
}
Module.HEAPU8.set(window.keys, window.keysBuffer);
return window.keysBuffer;
},
@nokotan
nokotan / Siv3DSample.cpp
Created August 3, 2020 02:13
OpenSiv3D Web版でHello, Siv3D! (TextureAsset, FontAsset使用バージョン)
# include <Siv3D.hpp> // OpenSiv3D v0.4.3
# include <emscripten.h>
// 猫の座標
Vec2 catPos(640, 450);
void MainLoop()
{
if (!s3d::System::Update()) {
emscripten_cancel_main_loop();
@nokotan
nokotan / coroutine_on_emscripten.cpp
Last active January 20, 2021 07:19
Simple coroutine test
#include <stdio.h>
#include <experimental/coroutine>
#include <thread>
#include <iostream>
#include <utility>
#include <optional>
#include <thread>
@nokotan
nokotan / Main.cpp
Created January 20, 2021 07:20
std::future をコルーチンで待ってみる on emscripten
# include <future>
# include <chrono>
# include <iostream>
# include <experimental/coroutine>
# include <emscripten.h>
# include <emscripten/html5.h>
namespace std
{
@nokotan
nokotan / ReturnStructureFromJS.cpp
Created February 8, 2021 07:05
JS関数から構造体をかえしてみる
# include <stdio.h>
# include <emscripten.h>
struct vec2
{
float x, y;
};
extern "C"
{
@nokotan
nokotan / inline_asm_in_emscripten.cpp
Created March 13, 2021 15:58
inline WebAssembly in emscripten
#include <cstdint>
#include <iostream>
int32_t add(int32_t n) {
int32_t sum;
__asm (
"local.get %1\n"
"i32.const 1\n"
"i32.add\n"
"local.set %0"
@echo off
setlocal
chcp 65001 > nul
set GitLog=%USERPROFILE%\git.log
set GitTmp=%USERPROFILE%\git.tmp
:: echo ^> git %* >> %GitLog%
if "%1" equ "rev-parse" goto rev_parse
#include <emscripten.h>
#include <functional>
#include <numeric>
#include <cassert>
#include <iostream>
std::function<void()> mainLoop;
void runMainLoop()
{
@nokotan
nokotan / wss.ts
Created September 15, 2021 04:39
WebSocket Server
import WebSocket, { Server } from 'ws';
const wss = new Server({ port: 28080 });
let uniqueID = 0;
let clients: WebSocket[] = [];
wss.on('connection', function connection(ws) {
const clientId = uniqueID++;
clients.push(ws);
@nokotan
nokotan / collisionDetection.c
Created February 28, 2022 06:53
JavaScript vs WebAssembly of v8 jit'ed code
#include <math.h>
struct position {
double x;
double y;
double z;
};
int collisionDetection(struct position *positions,
double *radiuses,