Giter VIP home page Giter VIP logo

nokotan / opensiv3d Goto Github PK

View Code? Open in Web Editor NEW

This project forked from siv3d/opensiv3d

10.0 3.0 1.0 1.85 GB

[NO LONGER MAINTAINED] Experimental port of OpenSiv3D to Web

Home Page: https://siv3d.kamenokosoft.com

License: MIT License

C++ 84.78% Objective-C++ 0.88% CMake 1.11% HLSL 0.76% GLSL 1.97% JavaScript 0.40% C 9.31% AngelScript 0.14% Objective-C 0.03% HTML 0.10% Metal 0.01% WGSL 0.50%
opensiv3d opensiv3d-web emscripten webassembly cpp20

opensiv3d's Introduction

Siv3D

Siv3D logo

Siv3D (OpenSiv3D) is a C++20 framework for creative coding (2D/3D games, media art, visualizers, and simulators). Siv3D applications run on Windows, macOS, Linux, and the Web.

Features

  • Graphics
    • Advanced 2D graphics
    • Basic 3D graphics (Wavefront OBJ, primitive shapes)
    • Custom vertex / pixel shaders (HLSL, GLSL)
    • Text rendering (Bitmap, SDF, MSDF)
    • PNG, JPEG, BMP, SVG, GIF, Animated GIF, TGA, PPM, WebP, TIFF
    • Unicode 14.0 emojis and 7,000+ icons
    • Image processing
    • Video rendering
  • Audio
    • WAVE, MP3, AAC, OggVorbis, Opus, MIDI, WMA*, FLAC*, AIFF*
    • Adjustable volume, pan, play speed and pitch
    • File streaming (WAVE, MP3, OggVorbis)
    • Fade in and fade out
    • Looping
    • Mixing busses
    • Filters (LPF, HPF, echo, reverb)
    • FFT
    • SoundFont rendering
    • Text to speech*
  • Input
    • Mouse
    • Keyboard
    • Gamepad
    • Webcam
    • Microphone
    • Joy-Con / Pro Controller
    • XInput*
    • Digital drawing tablet*
    • Leap Motion*
  • Window
    • Fullscreen mode
    • High DPI support
    • Window styles (sizable, borderless)
    • File dialog
    • Drag & drop
    • Message box
    • Toast notification*
  • Network and communication
    • HTTP client
    • Multiplayer (with Photon SDK)
    • TCP communication
    • Serial communication
    • Interprocess communication (pipe)
    • OSC (Open Sound Control)
  • Math
    • Vector and matrix classes (Point, Float2, Vec2, Float3, Vec3, Float4, Vec4, Mat3x2, Mat3x3, Mat4x4, SIMD_Float4, Quaternion)
    • 2D shape classes (Line, Circle, Ellipse, Rect, RectF, Triangle, Quad, RoundRect, Polygon, MultiPolygon, LineString, Spline2D, Bezier2, Bezier3)
    • 3D shape classes (Plane, InfinitePlane, Sphere, Box, OrientedBox, Ray, Line3D, Triangle3D, ViewFrustum, Disc, Cylinder, Cone)
    • Color classes (Color, ColorF, HSV)
    • Polar / cylindrical / spherical coordinates system
    • 2D / 3D shape intersection
    • 2D / 3D geometry processing
    • Rectangle packing
    • Planar subdivisions
    • Linear and gamma color space
    • Pseudo random number generators
    • Interpolation, easing, and smoothing
    • Perlin noise
    • Math parser
    • Navigation mesh
    • Extended arithmetic types (HalfFloat, int128, uint128, BigInt, BigFloat)
  • String and Text Processing
    • Advanced String class (String, StringView)
    • Unicode conversion
    • Regular expression
    • {fmt} style text formatting
    • Text reader / writer classes
    • CSV / INI / JSON / XML / TOML reader classes
    • CSV / INI / JSON writer classes
    • JSON Validation
  • Misc
    • Basic GUI (button, slider, radio buttons, checkbox, text box, color picker, list box, menu bar)
    • Integrated 2D physics engine (Box2D)
    • Advanced array / 2D array classes (Array, Grid)
    • Kd-tree
    • Disjoint set
    • Asynchronous asset file streaming
    • Data compression (zlib, Zstandard)
    • Transitions between scenes
    • File system
    • Directory watcher
    • QR code reader / writer
    • GeoJSON
    • Date and time
    • Stopwatch and timer
    • Logging
    • Serialization
    • UUID
    • Child process
    • Clipboard
    • Power status
    • Scripting (AngelScript)
    • OpenAI API (Chat, Image, Embedding)

* Some features are limited to specific platforms

How to Install Siv3D + Tutorial

v0.6.13 | released 15 November 2023 | Release Notes

Platform SDK Requirements
Windows Download SDK /
SDK をダウンロード
- Windows 10 / 11 (64-bit)
- Microsoft Visual C++ 2022 17.7
- Windows 10 SDK
- Intel / AMD CPU
macOS Download SDK /
SDK をダウンロード
- macOS Big Sur / Monterey / Ventura
- Xcode 12.5 or newer
- Intel CPU / Apple Silicon (Rosetta mode)*
- OpenGL 4.1 compatible hardware
Linux Compiling for Linux /
Linux 版のビルド
- GCC 9.3.0 (with Boost 1.71.0) / GCC 11.2 (with Boost 1.74.0)
- Intel / AMD CPU
- OpenGL 4.1 compatible hardware
Web (experimental**) Compiling for Web /
Web 版のビルド
Web browser with WebAssembly and WebGL2 support

* Native Apple Silicon support will be added in the future release. You can build and run Siv3D in Rosetta mode
** Some functionality may be missing or limited

Community

Miscellaneous

Supporting the Project

If you would like to support the project financially, visit my GitHub Sponsors page. Your support will accelerate the development of this exciting framework.

💗 https://github.com/sponsors/Reputeless

Examples

1. Hello, Siv3D!

Screenshot

# include <Siv3D.hpp>

void Main()
{
	// 背景の色を設定する | Set the background color
	Scene::SetBackground(ColorF{ 0.6, 0.8, 0.7 });

	// 画像ファイルからテクスチャを作成する | Create a texture from an image file
	const Texture texture{ U"example/windmill.png" };

	// 絵文字からテクスチャを作成する | Create a texture from an emoji
	const Texture emoji{ U"🦖"_emoji };

	// 太文字のフォントを作成する | Create a bold font with MSDF method
	const Font font{ FontMethod::MSDF, 48, Typeface::Bold };

	// テキストに含まれる絵文字のためのフォントを作成し、font に追加する | Create a font for emojis in text and add it to font as a fallback
	const Font emojiFont{ 48, Typeface::ColorEmoji };
	font.addFallback(emojiFont);

	// ボタンを押した回数 | Number of button presses
	int32 count = 0;

	// チェックボックスの状態 | Checkbox state
	bool checked = false;

	// プレイヤーの移動スピード | Player's movement speed
	double speed = 200.0;

	// プレイヤーの X 座標 | Player's X position
	double playerPosX = 400;

	// プレイヤーが右を向いているか | Whether player is facing right
	bool isPlayerFacingRight = true;

	while (System::Update())
	{
		// テクスチャを描く | Draw the texture
		texture.draw(20, 20);

		// テキストを描く | Draw text
		font(U"Hello, Siv3D!🎮").draw(64, Vec2{ 20, 340 }, ColorF{ 0.2, 0.4, 0.8 });

		// 指定した範囲内にテキストを描く | Draw text within a specified area
		font(U"Siv3D (シブスリーディー) は、ゲームやアプリを楽しく簡単な C++ コードで開発できるフレームワークです。")
			.draw(18, Rect{ 20, 430, 480, 200 }, Palette::Black);

		// 長方形を描く | Draw a rectangle
		Rect{ 540, 20, 80, 80 }.draw();

		// 角丸長方形を描く | Draw a rounded rectangle
		RoundRect{ 680, 20, 80, 200, 20 }.draw(ColorF{ 0.0, 0.4, 0.6 });

		// 円を描く | Draw a circle
		Circle{ 580, 180, 40 }.draw(Palette::Seagreen);

		// 矢印を描く | Draw an arrow
		Line{ 540, 330, 760, 260 }.drawArrow(8, SizeF{ 20, 20 }, ColorF{ 0.4 });

		// 半透明の円を描く | Draw a semi-transparent circle
		Circle{ Cursor::Pos(), 40 }.draw(ColorF{ 1.0, 0.0, 0.0, 0.5 });

		// ボタン | Button
		if (SimpleGUI::Button(U"count: {}"_fmt(count), Vec2{ 520, 370 }, 120, (checked == false)))
		{
			// カウントを増やす | Increase the count
			++count;
		}

		// チェックボックス | Checkbox
		SimpleGUI::CheckBox(checked, U"Lock \U000F033E", Vec2{ 660, 370 }, 120);

		// スライダー | Slider
		SimpleGUI::Slider(U"speed: {:.1f}"_fmt(speed), speed, 100, 400, Vec2{ 520, 420 }, 140, 120);

		// 左キーが押されていたら | If left key is pressed
		if (KeyLeft.pressed())
		{
			// プレイヤーが左に移動する | Player moves left
			playerPosX = Max((playerPosX - speed * Scene::DeltaTime()), 60.0);
			isPlayerFacingRight = false;
		}

		// 右キーが押されていたら | If right key is pressed
		if (KeyRight.pressed())
		{
			// プレイヤーが右に移動する | Player moves right
			playerPosX = Min((playerPosX + speed * Scene::DeltaTime()), 740.0);
			isPlayerFacingRight = true;
		}

		// プレイヤーを描く | Draw the player
		emoji.scaled(0.75).mirrored(isPlayerFacingRight).drawAt(playerPosX, 540);
	}
}

2. Breakout

Screenshot

# include <Siv3D.hpp>

void Main()
{
	// 1 つのブロックのサイズ | Size of a single block
	constexpr Size BrickSize{ 40, 20 };

	// ボールの速さ(ピクセル / 秒) | Ball speed (pixels / second)
	constexpr double BallSpeedPerSec = 480.0;

	// ボールの速度 | Ball velocity
	Vec2 ballVelocity{ 0, -BallSpeedPerSec };

	// ボール | Ball
	Circle ball{ 400, 400, 8 };

	// ブロックの配列 | Array of bricks
	Array<Rect> bricks;

	for (int32 y = 0; y < 5; ++y)
	{
		for (int32 x = 0; x < (Scene::Width() / BrickSize.x); ++x)
		{
			bricks << Rect{ (x * BrickSize.x), (60 + y * BrickSize.y), BrickSize };
		}
	}

	while (System::Update())
	{
		// パドル | Paddle
		const Rect paddle{ Arg::center(Cursor::Pos().x, 500), 60, 10 };

		// ボールを移動させる | Move the ball
		ball.moveBy(ballVelocity * Scene::DeltaTime());

		// ブロックを順にチェックする | Check bricks in sequence
		for (auto it = bricks.begin(); it != bricks.end(); ++it)
		{
			// ブロックとボールが交差していたら | If block and ball intersect
			if (it->intersects(ball))
			{
				// ブロックの上辺、または底辺と交差していたら | If ball intersects with top or bottom of the block
				if (it->bottom().intersects(ball) || it->top().intersects(ball))
				{
					// ボールの速度の Y 成分の符号を反転する | Reverse the sign of the Y component of the ball's velocity
					ballVelocity.y *= -1;
				}
				else // ブロックの左辺または右辺と交差していたら
				{
					// ボールの速度の X 成分の符号を反転する | Reverse the sign of the X component of the ball's velocity
					ballVelocity.x *= -1;
				}

				// ブロックを配列から削除する(イテレータは無効になる) | Remove the block from the array (the iterator becomes invalid)
				bricks.erase(it);

				// これ以上チェックしない | Do not check any more
				break;
			}
		}

		// 天井にぶつかったら | If the ball hits the ceiling
		if ((ball.y < 0) && (ballVelocity.y < 0))
		{
			// ボールの速度の Y 成分の符号を反転する | Reverse the sign of the Y component of the ball's velocity
			ballVelocity.y *= -1;
		}

		// 左右の壁にぶつかったら | If the ball hits the left or right wall
		if (((ball.x < 0) && (ballVelocity.x < 0))
			|| ((Scene::Width() < ball.x) && (0 < ballVelocity.x)))
		{
			// ボールの速度の X 成分の符号を反転する | Reverse the sign of the X component of the ball's velocity
			ballVelocity.x *= -1;
		}

		// パドルにあたったら | If the ball hits the left or right wall
		if ((0 < ballVelocity.y) && paddle.intersects(ball))
		{
			// パドルの中心からの距離に応じてはね返る方向(速度ベクトル)を変える | Change the direction (velocity vector) of the ball depending on the distance from the center of the paddle
			ballVelocity = Vec2{ (ball.x - paddle.center().x) * 10, -ballVelocity.y }.setLength(BallSpeedPerSec);
		}

		// すべてのブロックを描画する | Draw all the bricks
		for (const auto& brick : bricks)
		{
			// ブロックの Y 座標に応じて色を変える | Change the color of the brick depending on the Y coordinate
			brick.stretched(-1).draw(HSV{ brick.y - 40 });
		}

		// マウスカーソルを非表示にする | Hide the mouse cursor
		Cursor::RequestStyle(CursorStyle::Hidden);

		// ボールを描く | Draw the ball
		ball.draw();

		// パドルを描く | Draw the paddle
		paddle.rounded(3).draw();
	}
}

3. Hello, 3D world!

Screenshot

# include <Siv3D.hpp>

void Main()
{
	// Resize the window and scene to 1280x720
	Window::Resize(1280, 720);

	// Background color (remove SRGB curve for a linear workflow)
	const ColorF backgroundColor = ColorF{ 0.4, 0.6, 0.8 }.removeSRGBCurve();

	// Texture for UV check (mipmapped. treat as SRGB texture in a linear workflow)
	const Texture uvChecker{ U"example/texture/uv.png", TextureDesc::MippedSRGB };

	// Multisample RenderTexture for a linear workflow
	const MSRenderTexture renderTexture{ Scene::Size(), TextureFormat::R8G8B8A8_Unorm_SRGB, HasDepth::Yes };

	// 3D debug camera (free camera)
	// Vertical FOV: 30°, Eye position: (10, 16, -32)
	// Move: [W][S][A][D][E][X], View: [arrow keys]
	DebugCamera3D camera{ renderTexture.size(), 30_deg, Vec3{ 10, 16, -32 } };

	while (System::Update())
	{
		// Update a camera
		camera.update(2.0);

		// Set up a camera in the current 3D scene
		Graphics3D::SetCameraTransform(camera);

		// [3D rendering]
		{
			// Clear renderTexture with the background color,
			// then make renderTexture the render target for the current 3D scene
			const ScopedRenderTarget3D target{ renderTexture.clear(backgroundColor) };

			// Draw a floor
			Plane{ 64 }.draw(uvChecker);

			// Draw a box
			Box{ -8,2,0,4 }.draw(ColorF{ 0.8, 0.6, 0.4 }.removeSRGBCurve());

			// Draw a sphere
			Sphere{ 0,2,0,2 }.draw(ColorF{ 0.4, 0.8, 0.6 }.removeSRGBCurve());

			// Draw a cylinder
			Cylinder{ 8, 2, 0, 2, 4 }.draw(ColorF{ 0.6, 0.4, 0.8 }.removeSRGBCurve());
		}

		// [2D rendering]
		{
			// Flush 3D rendering commands before multisample resolve
			Graphics3D::Flush();

			// Multisample resolve
			renderTexture.resolve();

			// Transfer renderTexture to the current 2D scene (default scene)
			Shader::LinearToScreen(renderTexture);
		}
	}
}

opensiv3d's People

Contributors

agehama avatar azaika avatar comefrombottom avatar ebishu-0309 avatar falrnd avatar fuyutsubaki avatar kestrel-90r avatar kurokoji avatar luke256 avatar m4saka avatar mak1a avatar murakamishun avatar nokotan avatar para7 avatar polyester-ctrl avatar raclamusi avatar reputeless avatar ryoga-exe avatar shirry0129 avatar sthairno avatar tana avatar taotao54321 avatar tetsurom avatar tomolatoon avatar voidproc avatar wynd2608 avatar yama-can avatar yksake avatar yunba28 avatar yurkth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

skxatbj

opensiv3d's Issues

SimpleHTTP::Get() / Post() サンプルで期待した結果が得られない

予期しない動作の内容 | Describe the unexpected behavior

Siv3D チュートリアルの GET サンプル / POST サンプルともに期待した正常な結果が得られない。

再現方法 | To Reproduce

発生環境(デスクトップの場合) | Desktop (please complete the following information):

  • OS: Windows 11
  • バージョン | Version: v0.6.5r5
  • ブラウザ (Web 版) | Browser: Google Chrome

備考
ほかのプラットフォームでは発生せず

Siv3D for Web アプリケーションローダを安定版/開発版で分ける

追加する機能の内容 | Describe the solution you'd like

WebAssembly Studio で使用している Siv3D.js に開発中のデグレが混じらないようにする

その機能の追加によって解決する問題 | Is your feature request related to a problem? Please describe.

WebAssembly Studio OpenSiv3D for Web 0.6 テンプレートが常に安定的に使えるようにする

備考 | Additional context

warning: Asyncify addlist contained a non-existing function name: * がビルド時に発生する

予期しない動作の内容 | Describe the unexpected behavior

再現方法 | To Reproduce

発生環境(デスクトップの場合) | Desktop (please complete the following information):

  • OS:
  • バージョン | Version:
  • GPU:
  • ブラウザ (Web 版) | Browser:

発生環境(モバイルの場合) | Smartphone (please complete the following information):

  • デバイス | Device:
  • OS:
  • バージョン | Version:
  • ブラウザ (Web 版) | Browser:

備考 | Additional context

モバイル環境でテキスト入力中にバックスペースが反応しない/カーソル移動ができない

予期しない動作の内容 | Describe the unexpected behavior

再現方法 | To Reproduce

発生環境(デスクトップの場合) | Desktop (please complete the following information):

  • OS:
  • バージョン | Version:
  • GPU:
  • ブラウザ (Web 版) | Browser:

発生環境(モバイルの場合) | Smartphone (please complete the following information):

  • デバイス | Device:
  • OS:
  • バージョン | Version:
  • ブラウザ (Web 版) | Browser:

備考 | Additional context

スマホ横持ちをしたときに、画面が小さくなりすぎる

予期しない動作の内容 | Describe the unexpected behavior

スマホ横持ちをしたときに、コントロールバー (ミュートボタン + フルスクリーンボタン) がスクリーン下部を大きく占有し、
その結果、Siv3D の描画面が小さくなりすぎる

発生環境(モバイルの場合) | Smartphone (please complete the following information):

  • デバイス | Device: モバイル全般
  • OS: Android / iOS
  • バージョン | Version: -
  • ブラウザ (Web 版) | Browser: -

備考 | Additional context

  • #21 の解消後に顕在化した問題
  • #15 (comment) において、コントロールバー (ミュートボタン + フルスクリーンボタン) の非表示化に関する議論

`F1` キーでライセンス情報が安定して出るようにしたい

  • すでに F1 キーでライセンス情報のページを表示する機能自体は実装済み
  • ブラウザのデフォルトショートカットとぶつかるようなブラウザでは、ライセンスページが出たり出なかったりする
    • Google Chrome ではヘルプと衝突
  • 目的: あらゆるデスクトップ Web ブラウザで、F1 キーを押したとき必ずライセンスを表示したい
  • F1 キーのブラウザのデフォルトショートカットを無効化すると安定的にライセンスページが表示される
    • Web ブラウザの F1 キーショートカットをデフォルトで必ず無効化するのはどうか

[v0.6] オーディオファイルのデコード結果が正しくない

強化された Audio サンプルを実行したところ、
音声ファイルの長さや再生したときの再生スピードが実際と異なっていました。
デコード時や再生時のサンプリング周波数の設定がどこかで間違っている可能性があります。

分かりやすい再現方法:

  • example/windmill.mp3 example/test.mp3audio.lengthSec() が実際よりも長い
  • サンプリング周波数 22,050 Hz の Ogg ファイルを自前で用意してロードすると audio.sampleRate() で 44,100 Hz と表示されたり、実際の 2 倍速で再生されたりする

Windows で TextToSpeech が利用可能かどうかにかかわらず TextToSpeech unavailable という警告が出る

再現方法:
Siv3D Studio でデフォルトのサンプルプログラムを実行
Windows 11 / Chrome

期待される動作:
警告が出ない

実際の動作:
⚠️ TextToSpeech unavailable という警告が出力される

解決案:
① 警告が出ないよう実装を改善
② Web 版の TextToSpeech 機能を一旦無効化する

補足:
警告の出ない環境が見つからない。

TextBoxとTextEdit::activeが同期しない

予期しない動作の内容 | Describe the unexpected behavior
SimpleGUI::TextBoxでTextEditStateのactiveがtrueでもボックスをユーザーがクリックしないと文字入力を受け付けない
(青く描画はされるがキーボードは反応しない)

再現方法 | To Reproduce
通常通りSimpleGUI::TextBoxでボックスを生成、常にactive=trueの状態にして起動

発生環境(デスクトップの場合) | Desktop (please complete the following information):

  • OS: macOS
  • バージョン | Version: 10.15.7
  • GPU: Intel Iris Plus Graphics 1536 MB
  • ブラウザ (Web 版) | Browser: GoogleChrome

発生環境(モバイルの場合) | Smartphone (please complete the following information):

  • デバイス | Device:
  • OS:
  • バージョン | Version:
  • ブラウザ (Web 版) | Browser:

備考 | Additional context

SimpleHTTP::Post() でデータが指定したサイズを超えて送信される

予期しない動作の内容

SimpleHTTP::Post(url, headers, src, size, writer) を呼び出したとき、size を無視して src を 0 のバイトが登場するまで送信します。
意図したとおりにデータを送信できないうえ、バッファオーバーランの危険性があります。

再現方法

以下のコードを実行し、スペースキーを押します。

# include <Siv3D.hpp>

void Main()
{
	while (System::Update())
	{
		if (KeySpace.down())
		{
			MemoryWriter writer;

			SimpleHTTP::Post(U"https://script.google.com/macros/s/AKfycbz78zNhTqOwne7I0wg9me1Alny8NEYn3FZnAmdQ3xljV4l08vTziTE6XWJoGOYH9NJR/exec", {}, "abcdefgh", 4, writer);

			Print << U"size: {}"_fmt(writer.size());
			Print << U"content: {}"_fmt(Unicode::FromUTF8(std::string_view{ std::bit_cast<const char*>(writer.getBlob().data()), writer.getBlob().size() }));
		}
	}
}

コード中の URL は、POST したデータをそのまま返すように設定したウェブアプリのものです。
スペースキー押下時に "abcdefgh" のうち4バイトを送信するコードを書いていますが、実際にはヌル文字が登場するまでの8バイトが送信されています。

image

原因

この問題の原因は、siv3dSendXMLHTTPRequest()UTF8ToString() によってデータを文字列に変換していることです。
この関数にデータサイズを渡し、適切に変換することで、この問題を解決できると思います。
例えば、以下のように siv3dSendXMLHTTPRequest() を修正することが考えられます。

-    siv3dSendXMLHTTPRequest: function(id, dataPtr) {
+    siv3dSendXMLHTTPRequest: function(id, dataPtr, dataSize) {
         {{{ runtimeKeepalivePush() }}}

         siv3dXMLHTTPRequestList[id].addEventListener("load", function() {
             {{{ runtimeKeepalivePop() }}}
         });
         siv3dXMLHTTPRequestList[id].addEventListener("error", function() {
             {{{ runtimeKeepalivePop() }}}
         });

-        const data = dataPtr ? UTF8ToString(dataPtr) : null;
+        const data = dataPtr ? new Uint8Array(HEAPU8.buffer, dataPtr, dataSize) : null;
         siv3dXMLHTTPRequestList[id].send(data);
     },
-    siv3dSendXMLHTTPRequest__sig: "vii",
+    siv3dSendXMLHTTPRequest__sig: "viii",
     siv3dSendXMLHTTPRequest__deps: [ "$siv3dXMLHTTPRequestList" ],

FillMode を Wireframe にしてもワイヤフレームで描画されない

ScopedRenderStates(2D|3D)RasterizerState::WireframeCullNone などを指定してもワイヤフレームで描画されず、普通に描画されます。

この問題によって、下の例やサンプル 36.13 複雑な 3D 形状を描くサンプル 36.21 ワイヤフレームで描画するなどが正しく動きません。

# include <Siv3D.hpp>

void Main()
{
	while (System::Update())
	{
		const ScopedRenderStates2D rasterizer{ RasterizerState::WireframeCullNone };
		
		Shape2D::Heart(200, Scene::Center()).draw(Palette::Skyblue);
	}
}

図1 OpenSiv3D for Web v0.6.6r1 での実行結果
図1 OpenSiv3D for Web v0.6.6r1 での実行結果

図2 OpenSiv3D v0.6.6 での実行結果(期待する結果)
図2 OpenSiv3D v0.6.6 での実行結果(期待する結果)

TextInput が UTF-16 で処理されている

TextInput の処理が JavaScript の文字、すなわち UTF-16 単位で行われているので、Siv3D の文字、すなわち UTF-32 で扱える文字が一部使えません(「𩸽」など)。

以下のような修正が考えられます。

  • 問題 1. コードポイントを .charCodeAt() で取得している(4か所)

    for (var i = 0; i < e.data.length; i++) {
    const codePoint = e.data.charCodeAt(i);
    {{{ makeDynCall('vi', 'callback') }}}(codePoint);
    }

    • 修正 1. コードポイントを .codePointAt() で取得するようにする
for (const char of e.data) {
    const codePoint = char.codePointAt(0);
    {{{ makeDynCall('vi', 'callback') }}}(codePoint);
}
  • 問題 2. 文字列の長さを .length で取得している(1か所)

    siv3dTextInputElement.textContent = " ".repeat(newText.length);

    • 修正 2. 文字列の長さを [...s].length で取得するようにする
siv3dTextInputElement.textContent = " ".repeat([...newText].length);

VS の Debug ビルドでアプリ実行時、ブラウザ画面上部にシーンに重なる赤いバーが表示される

予期しない動作の内容 | Describe the unexpected behavior
VS の Debug ビルドでアプリ実行時、ブラウザ画面上部にシーンに重なる赤いバー:
image

コンソールに出力されるエラーメッセージ:
mscripten_set_main_loop_timing: Cannot set timing mode for main loop since a main loop does not exist! Call emscripten_set_main_loop first to set one up.
image

再現方法 | To Reproduce
Visual Studio を使って Debug ビルドででデフォルトサンプルをビルド → 実行

発生環境(デスクトップの場合) | Desktop (please complete the following information):

  • OS: Windows 11
  • バージョン | Version: 0.6.5
  • ブラウザ (Web 版) | Browser: Google Chrome

備考 | Additional context
Release ビルドでは発生せず。

ASYNCIFY_ADD への関数の追加が面倒

追加する機能の内容 | Describe the solution you'd like

その機能の追加によって解決する問題 | Is your feature request related to a problem? Please describe.

System::Update やサウンドデコードなど、ライブラリ内部で非同期が絡む関数を呼び出す関数をすべて ASYNCIFY_ADD に加えなくてもよくなる

備考 | Additional context

Related: emscripten-core/emscripten#13150

AsyncHTTPTask の非互換な挙動

予期しない動作の内容 | Describe the unexpected behavior

関連: https://discord.com/channels/443310697397354506/998714158621147237/1038378601646673980

AsyncHTTPTask task; について、task.isReady()true を返したとき task.getResponse() することで、それ以降 task.isReady()false を返すようになるのが期待される動作ですが、Web 版では true のままです。

Web 版で下記のサンプルはファイルダウンロードに成功しますが、Texture の毎フレーム連続作成を行ってしまうためエラー終了します。

再現方法 | To Reproduce

# include <Siv3D.hpp>

void Main()
{
	const URL url = U"https://raw.githubusercontent.com/Siv3D/siv3d.docs.images/master/logo/logo.png";
	const FilePath saveFilePath = U"logo2.png";
	Texture texture;

	// ファイルの非同期ダウンロードを開始
	AsyncHTTPTask task = SimpleHTTP::SaveAsync(url, saveFilePath);

	while (System::Update())
	{
		// 非同期タスクが完了した
		if (task.isReady())
		{
			Print << Scene::FrameCount();

			// レスポンスが 200 (OK) なら
			if (task.getResponse().isOK())
			{
				texture = Texture{ saveFilePath };
			}
			else
			{
				Print << U"Failed.";
			}
		}

		if (texture)
		{
			texture.draw();
		}
	}
}

発生環境(デスクトップの場合) | Desktop (please complete the following information):

  • OS: Windows 11
  • バージョン | Version: v0.6.5r5
  • ブラウザ (Web 版) | Browser: Google Chrome

ブラウザの言語設定を取得する API

追加する機能の内容 | Describe the solution you'd like

Commented by @Reputeless on Siv3D Slack

ブラウザの言語設定を取得する API って作れますか?
日本語設定でない人には英語のコンテンツを表示したいです。

その機能の追加によって解決する問題 | Is your feature request related to a problem? Please describe.

日本語設定でない人には英語のコンテンツを表示したいです。

備考 | Additional context

Reported by @Reputeless

[実行時エラー] ウィンドウの任意のリサイズ Window::Resize() をすると灰色の画面のまま

エラーの内容 | Describe the runtime error
Web 最新版、Windows + Google Chrome, ウィンドウの任意のリサイズ Window::Resize(1280, 720); をすると灰色の画面のままです。

再現方法 | To Reproduce
再現コード: https://gist.github.com/Reputeless/62de5ce914b8ba8f4e8b470c998b359c

発生環境(デスクトップの場合) | Desktop (please complete the following information):

  • OS: Windows 11
  • バージョン | Version: v0.6.4r0
  • GPU: GeForce RTX 3070
  • ブラウザ (Web 版) | Browser: Google Chrome

備考 | Additional context
他の環境では未検証です。

Safari 16.1 でアプリが無条件にクラッシュする

エラーの内容 | Describe the runtime error

アプリがクラッシュし、リロードループに入る

再現方法 | To Reproduce

発生環境(デスクトップの場合) | Desktop (please complete the following information):

  • OS: macOS Monterey
  • バージョン | Version: 12.6.1
  • GPU: -
  • ブラウザ (Web 版) | Browser: Safari 16.1

備考 | Additional context

ウィンドウサイズいっぱいに描画される問題

エラーの内容

ウィンドウの形状にかかわらず、ウィンドウサイズいっぱいに描画されます。

image

Uncaught TypeError: Options.setFramebufferSize is not a function
    at doResize (OpenSiv3Dv0_6ForWebTest.html:21:1039)
    at callRuntimeCallbacks (OpenSiv3Dv0_6ForWebTest.js:9:46906)
    at postRun (OpenSiv3Dv0_6ForWebTest.js:9:35135)
    at doRun (OpenSiv3Dv0_6ForWebTest.js:9:391619)
    at OpenSiv3Dv0_6ForWebTest.js:9:391759

再現方法

Visual Studio 用のセットアップガイドに従ってインストールして、何も変更せずビルド、実行しました。
Debug, Release にかかわらず発生します。

発生環境

  • OS: Windows 11 Home
  • GPU: Intel(R) UHD Graphics
  • ブラウザ: Chrome, Firefox, Edge など
  • Siv3D バージョン: 0.6.4

テキストボックスに画像が貼り付けられる

問題

テキストボックスに Ctrl+V で画像を貼り付けることができ、その結果、貼り付けた画像がはみ出た分だけ画面がずれるなどの問題が発生します。

image

解決策

テキスト入力のために使っている <div>contenteditable 属性を plaintext-only にすることで、テキスト以外入力できないようにできます。

textInput.contentEditable = true;

textInput.contentEditable = "plaintext-only";

WebAssembly 自体が実行できない環境でのエラーメッセージ

追加する機能の内容 | Describe the solution you'd like

WebAssembly 自体のサポートがなかったり、そのブラウザで使えない WebAssembly の機能があったときに、
エラーメッセージを表示する

その機能の追加によって解決する問題 | Is your feature request related to a problem? Please describe.

古いブラウザや IE を使っている人対策になる

備考 | Additional context

Related: #9

[Web版] 実行時エラー

Env

  • Windows 10
  • Visual Studio 2019 Community
  • OpenSiv3D 0.4.3 for Web

About

チュートリアルに従い、Visual StudioでWeb版のデバッグを行ったところ、次のようなエラーが発生します。

image

Pointer Lock APIを用いたマウス操作

追加する機能の内容 | Describe the solution you'd like

Pointer Lock API を用いたマウスの固定及び移動量などの取得

その機能の追加によって解決する問題| Is your feature request related to a problem? Please describe.

Web版ではCursor::SetPos()が使えない
(ブラウザでマウスカーソルの位置を設定することはできない?)ので、マウスでの操作を行う際(3Dゲームでの視点移動など)に、画面端でマウスの移動が止まってしまいそれ以上操作ができない(Discordでの質問 )

Pointer Lock APIを用いることでカーソルを固定しマウスの移動量を取得できるため上記問題を解決出来る。

備考 | Additional context

(個人的な意見になりますが)
ポインタのロックと移動量の取得はWeb版に限らずOpenSiv3D本体でも扱うと思うので、これらの機能を通常版でも扱えればいいなぁと思います。

wasm-ld : error : unable to find library -lpng

エラーの内容 | Describe the build error

1>wasm-ld : error : unable to find library -lpng
1>emcc : error : 'C:/Users/tas9n/AppData/Local/Programs/Emscripten/upstream/bin\wasm-ld.exe -o C:/Users/tas9n/program/C++/OpenSiv3D/Web/OpenSiv3Dv0_6ForWeb1/Emscripten/Debug/OpenSiv3Dv0_6ForWeb1.wasm Emscripten/Debug/Main.o C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib\libSiv3DScript.a C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib\libSiv3D.a C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/opencv\libopencv_objdetect.a C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/opencv\libopencv_photo.a C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/opencv\libopencv_imgproc.a C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/opencv\libopencv_core.a C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/harfbuzz\libharfbuzz.a C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/freetype\libfreetype.a C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/turbojpeg\libturbojpeg.a C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/giflib\libgif.a C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/webp\libwebp.a C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/opus\libopusfile.a C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/opus\libopus.a C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/tiff\libtiff.a -lpng C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/zlib\libz.a C:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/SDL2\libSDL2.a -LC:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/freetype -LC:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/giflib -LC:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/harfbuzz -LC:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/opencv -LC:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/turbojpeg -LC:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/webp -LC:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/opus -LC:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/tiff -LC:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/libpng -LC:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/zlib -LC:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib/SDL2 -LC:/Users/tas9n/AppData/Local/Programs/OpenSiv3D(0.6.5)Web/lib -LC:\Users\tas9n\AppData\Local\Programs\Emscripten\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten C:\Users\tas9n\AppData\Local\Programs\Emscripten\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libvorbis.a C:\Users\tas9n\AppData\Local\Programs\Emscripten\upstream\emscripten\cache\sysroot\lib\wasm32-emscripten\libogg.a -lGL-webgl2-full_es3 -lal -lhtml5 -lstubs-debug -lc-debug -ldlmalloc -lcompiler_rt -lc++ -lc++abi -lsockets -lwebgpu_cpp -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-cxx-exceptions -mllvm -emscripten-cxx-exceptions-allowed=InitSiv3D -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --import-undefined --export-if-defined=main --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-if-defined=emscripten_stack_get_base --export-if-defined=emscripten_stack_get_end --export-if-defined=emscripten_stack_set_limits --export-if-defined=emscripten_stack_get_free --export-if-defined=emscripten_stack_init --export-if-defined=stackSave --export-if-defined=stackRestore --export-if-defined=stackAlloc --export-if-defined=__wasm_call_ctors --export-if-defined=__errno_location --export-if-defined=getTempRet0 --export-if-defined=setTempRet0 --export-if-defined=__get_temp_ret --export-if-defined=__set_temp_ret --export-if-defined=__funcs_on_exit --export-if-defined=malloc --export-if-defined=free --export-if-defined=__cxa_is_pointer_type --export-if-defined=__cxa_can_catch --export-if-defined=setThrew --export-if-defined=ntohs --export-if-defined=htons --export-if-defined=__dl_seterr --export-if-defined=saveSetjmp --export-if-defined=emscripten_builtin_memalign --export-if-defined=memcpy --export-table -z stack-size=5242880 --initial-memory=16777216 --no-entry --max-memory=2147483648 --global-base=1024' failed (returned 1)
1>プロジェクト "OpenSiv3Dv0_6ForWeb1.vcxproj" のビルドが終了しました -- 失敗。

再現方法 | To Reproduce

公式サイト
https://siv3d.kamenokosoft.com/ja/building/overview
から手順通りEmscriptenのインストールからサンプルコードのビルドをしようとした際に以上のエラーが出ました。

ビルド環境 | Develop environment (please complete the following information):

  • OS: Windows 10 Home 21H2
  • 開発環境 | IDE: Visual Studio Community 2022 17.3.0

備考 | Additional context

warning: undefined symbol: * がビルド時に発生する

予期しない動作の内容 | Describe the unexpected behavior

再現方法 | To Reproduce

発生環境(デスクトップの場合) | Desktop (please complete the following information):

  • OS:
  • バージョン | Version:
  • GPU:
  • ブラウザ (Web 版) | Browser:

発生環境(モバイルの場合) | Smartphone (please complete the following information):

  • デバイス | Device:
  • OS:
  • バージョン | Version:
  • ブラウザ (Web 版) | Browser:

備考 | Additional context

Followed instructions on website, OpenSiv3D(0.6.4)Web project template does not build out of the box in Visual Studio 2022

**エラーの内容 | Followed instructions on website, OpenSiv3D(0.6.4)Web does not build out of the box

再現方法 | To Reproduce

  1. Followed https://siv3d.kamenokosoft.com/building/overview exactly.
  2. Error build output:
    1>emcc : error : Siv3DScript: No such file or directory ("Siv3DScript" was expected to be an input file, based on the commandline arguments provided) 1>Done building project "openSiv3Dv0_6ForWebTest.vcxproj" -- FAILED.

ビルド環境 | Develop environment (please complete the following information):

  • OS: Windows 10
  • 開発環境 | IDE: Visual Studio 2022 (new install)

備考 | Additional context
Also did a search, there is file that was installed that has that name. Closest is: libSiv3DScript.a, but that's of course a linux library. Is there a build step missing in your instructions?

SetMainLoop を使うと unreachable が発生する

エラーの内容 | Describe the runtime error

unreachable が発生する

再現方法 | To Reproduce

SetMainLoop を使う

発生環境(デスクトップの場合) | Desktop (please complete the following information):
発生環境(モバイルの場合) | Smartphone (please complete the following information):

全ての環境

備考 | Additional context

Asyncify + SetMainLoop は同時に使えないため

次の項目の対応を予定

  • SetMainLoop 自体の削除
  • SetMainLoop + Asyncify を使ったときにもっとわかりやすいエラーメッセージを表示する

実行環境のキーボードの利用可否を取得したい

キーボードが使えない実行環境で、Camera2D/3D の操作のためのミニ UI や、代替操作手法を提示するために、現在の実行環境を取得できる関数があると便利です。
どういう情報の取得が可能か意見を聞きたいです。それに基づいて API を提案します。

目標: v0.6.x

特定のキーをpreventDefault()する機能

追加する機能の内容 | Describe the solution you'd like
指定したキーをpreventDefault()したい

その機能の追加によって解決する問題 | Is your feature request related to a problem? Please describe.
Google Chromeには機能のショートカットがありますが、ゲームでキーボード操作を実装する際にこれらの機能が邪魔になることがあります。

  • 問題
    WASDキーで移動、Ctrlキーでダッシュなどを実装する際、現在のページを保存するオプションが開かれゲームが中断される。

  • 解決
    Ctrlキー+SキーなどpreventDefault()できればこの問題が解決されます。

ファイルを開くダイアログで同じファイルを選んだ時などに結果が返らない

予期しない動作の内容 | Describe the unexpected behavior
Platform::Web::Dialog::OpenFile() の戻り値 (AsyncTask) の isReady()true にならないことがある。
また、Dialog::OpenFile() を使用した際に本現象が発生すると、ずっと待ち状態となりアプリがフリーズする。

再現方法 | To Reproduce

  • 連続で同じファイルを選ぶ
  • 連続で(またはファイルが選択されていない状態で)ダイアログをキャンセルする

発生環境(デスクトップの場合) | Desktop (please complete the following information):

  • OS: Windows 11
  • バージョン | Version: 22H2
  • GPU: Intel Iris Xe Graphics
  • ブラウザ (Web 版) | Browser: Google Chrome 116.0.5845.111

発生環境(モバイルの場合) | Smartphone (please complete the following information):

  • デバイス | Device: Google Pixel 6a
  • OS: Android
  • バージョン | Version: 13
  • ブラウザ (Web 版) | Browser: Google Chrome 116.0.5845.92

備考 | Additional context
公開されている v0.6.6r1 では、インストールされた Siv3D.js を下記 Gist のように修正することで本現象を解消することができました。
https://gist.github.com/voidproc/dda7d1627697b6314eb6d3b12820e868

Supress Warning that no texture is bound in forward3d.frag

エラーの内容 | Describe the runtime error

次の警告が表示される

no texture is bound in forward3d.frag

再現方法 | To Reproduce

発生環境(デスクトップの場合) | Desktop (please complete the following information):

  • OS:
  • バージョン | Version:
  • GPU:
  • ブラウザ (Web 版) | Browser:

発生環境(モバイルの場合) | Smartphone (please complete the following information):

  • デバイス | Device:
  • OS:
  • バージョン | Version:
  • ブラウザ (Web 版) | Browser:

備考 | Additional context

SIMD 対応版のみを提供する

追加する機能の内容 | Describe the solution you'd like

現状 Web 版では、非 SIMD 対応版のみを提供しているが、これを SIMD 対応版のみの提供にする

その機能の追加によって解決する問題 | Is your feature request related to a problem? Please describe.

  • 外部ライブラリsimde への依存を切ることができる
    • プリコンパイル済みヘッダの軽量化
    • ビルド時間の短縮

備考 | Additional context

ビルドされるサイズが最小になる VS プロジェクトテンプレートの追加同梱

おそらく OpenSiv3D for Web 新規ユーザのほとんどが「ビルド後の出力ファイルサイズが大きい」と思う。

出力ファイルを削減する方法が用意されていることを示すために、プロジェクトテンプレートに「OpenSiv3D(v0.6.5)Web-min」のようなものがあっても良いかもしれない。

具体的には下記の通り。

  • example を含まない
  • Script / tiff など重要でないライブラリを含まない
  • フォントは resources/enginefont/min/siv3d-min.woff しか含まない
  • その他削れる engine は削っている

こうした説明をプロジェクトテンプレートの説明や Main.cpp に含め、「OpenSiv3D(v0.6.5)Web-min」というプロジェクトテンプレートを追加で提供するという提案です。

すごく軽量(図形や英数字 only)なミニアプリを開発・公開するのがスムーズになる利点もあります。

スマホや iPad でシーンの下部が画面外にはみ出る

予期しない動作の内容 | Describe the unexpected behavior

スマホや iPad でシーンの下部 2〜5 % ほどが画面外にはみ出る

再現方法 | To Reproduce

発生環境(モバイルの場合) | Smartphone (please complete the following information):

  • デバイス | Device: Android, iPad
  • OS: Android, iOS
  • バージョン | Version: -
  • ブラウザ (Web 版) | Browser: -

備考 | Additional context

Reported by @Reputeless

デフォルトで gzip 圧縮をかける

追加する機能の内容 | Describe the solution you'd like

ユーザーが何もしなくても(圧縮/サーバーの設定に知識がなくても)、ビルド時に自動的に gzip 圧縮をかけ、実行時にブラウザ側で自動的に展開する
Unity の Decompression Fallback と同等の機能

その機能の追加によって解決する問題 | Is your feature request related to a problem? Please describe.

配信サイズの縮小
(本来であれば配信サーバで設定すべきところを、Siv3D および Siv3D Web 初心者でも恩恵を受けられるようにする)

備考 | Additional context

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.