-
Notifications
You must be signed in to change notification settings - Fork 152
GS Datastream #1562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
CedricGuillemet
wants to merge
22
commits into
BabylonJS:master
Choose a base branch
from
CedricGuillemet:DataStream
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
GS Datastream #1562
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c0a3982
GS Datastream
CedricGuillemet 0d6946e
leftover
CedricGuillemet 8d148da
notice, disabled warnings
CedricGuillemet d7a3fd2
warnings
CedricGuillemet b0a9a90
unused field
CedricGuillemet cdc7d64
TextDecoder and up bjs
CedricGuillemet db7cc88
canvas + webp
CedricGuillemet 8d76667
gzip data stream
CedricGuillemet ab92f9e
removed extra qualif
CedricGuillemet 266e650
libdeflate for gzip stream
CedricGuillemet 98f1658
unity build disabled for miniz and libdeflate
CedricGuillemet 0688bde
unity build
CedricGuillemet 32fdab0
Response
CedricGuillemet c039c33
Merge branch 'master' of https://github.com/babylonjs/BabylonNative i…
CedricGuillemet 1a66ea2
Merge branch 'master' of https://github.com/babylonjs/BabylonNative i…
CedricGuillemet c2ac387
Merge branch 'master' of https://github.com/babylonjs/BabylonNative i…
CedricGuillemet 3fd0328
removed perf test, up bjs
CedricGuillemet 6f128e8
revert bjs to 8.25.1
CedricGuillemet 6115bad
fix webpack
CedricGuillemet 13dfdd5
a bit faster by avoiding copy
CedricGuillemet 2ed2d93
Merge branch 'master' of https://github.com/babylonjs/BabylonNative i…
CedricGuillemet dcc7c66
Merge branch 'master' of https://github.com/babylonjs/BabylonNative i…
CedricGuillemet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| set(SOURCES | ||
| "Include/Babylon/Plugins/DataStream.h" | ||
| "Source/DataStream.h" | ||
| "Source/DataStream.cpp") | ||
|
|
||
| add_library(DataStream ${SOURCES}) | ||
| warnings_as_errors(DataStream) | ||
|
|
||
| target_include_directories(DataStream PUBLIC | ||
| "Include") | ||
|
|
||
| target_link_libraries(DataStream | ||
| PUBLIC napi | ||
| PRIVATE miniz | ||
| PRIVATE JsRuntimeInternal) | ||
|
|
||
| set_property(TARGET DataStream PROPERTY FOLDER Plugins) | ||
| source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #pragma once | ||
|
|
||
| #include <napi/env.h> | ||
|
|
||
| namespace Babylon::Plugins::DataStream | ||
| { | ||
| void BABYLON_API Initialize(Napi::Env env); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #include "DataStream.h" | ||
|
|
||
| #include <functional> | ||
| #include <sstream> | ||
| #include <Babylon/JsRuntime.h> | ||
|
|
||
| #ifdef _MSC_VER | ||
| #pragma warning(push) | ||
| #pragma warning(disable : 4505) // unreferenced function with internal linkage has been removed | ||
| #endif // _MSC_VER | ||
|
|
||
| #include "miniz.h" | ||
|
|
||
| #ifdef _MSC_VER | ||
| #pragma warning(pop) | ||
| #endif // _MSC_VER | ||
|
|
||
| namespace Babylon::Plugins::Internal | ||
| { | ||
| Napi::Value DataStream::UnzipSync(const Napi::CallbackInfo& info) | ||
| { | ||
| const Napi::Env env{ info.Env() }; | ||
| if (info.Length() < 1 || !info[0].IsTypedArray()) { | ||
| throw Napi::Error::New(info.Env(), "Expected Uint8Array argument"); | ||
| } | ||
|
|
||
| // zip content | ||
| Napi::Uint8Array input = info[0].As<Napi::Uint8Array>(); | ||
| const uint8_t* zipData = input.Data(); | ||
| const size_t zipSize = input.ByteLength(); | ||
|
|
||
| // initialize miniz ZIP archive | ||
| mz_zip_archive zip_archive; | ||
| memset(&zip_archive, 0, sizeof(zip_archive)); | ||
|
|
||
| if (!mz_zip_reader_init_mem(&zip_archive, zipData, zipSize, 0)) { | ||
| throw Napi::Error::New(info.Env(), "Failed to initialize zip archive"); | ||
| } | ||
|
|
||
| // result object | ||
| Napi::Object result = Napi::Object::New(env); | ||
| const auto fileCount = mz_zip_reader_get_num_files(&zip_archive); | ||
|
|
||
| for (mz_uint i = 0; i < fileCount; i++) { | ||
| mz_zip_archive_file_stat file_stat; | ||
| if (!mz_zip_reader_file_stat(&zip_archive, i, &file_stat)) { | ||
| continue; | ||
| } | ||
|
|
||
| if (mz_zip_reader_is_file_a_directory(&zip_archive, i)) { | ||
| continue; // skip directories | ||
| } | ||
|
|
||
| std::string filename(file_stat.m_filename); | ||
|
|
||
| // extract file to memory | ||
| size_t uncompressed_size = (size_t)file_stat.m_uncomp_size; | ||
| std::vector<uint8_t> buffer(uncompressed_size); | ||
|
|
||
| if (!mz_zip_reader_extract_to_mem(&zip_archive, i, buffer.data(), uncompressed_size, 0)) { | ||
| throw Napi::Error::New(info.Env(), "Failed to extract file"); | ||
| continue; | ||
| } | ||
|
|
||
| // file content | ||
| Napi::ArrayBuffer jsBuffer = Napi::ArrayBuffer::New(env, uncompressed_size); | ||
| memcpy(jsBuffer.Data(), buffer.data(), uncompressed_size); | ||
| Napi::Uint8Array jsArray = Napi::Uint8Array::New(env, uncompressed_size, jsBuffer, 0); | ||
|
|
||
| // result[filename] = Uint8Array | ||
| result.Set(Napi::String::New(env, filename), jsArray); | ||
| } | ||
|
|
||
| // done | ||
| mz_zip_reader_end(&zip_archive); | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
|
|
||
| namespace Babylon::Plugins::DataStream | ||
| { | ||
| void BABYLON_API Initialize(Napi::Env env) | ||
| { | ||
| Internal::DataStream::CreateInstance(env); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #pragma once | ||
| #include <napi/env.h> | ||
|
|
||
| #include <Babylon/JsRuntime.h> | ||
|
|
||
| namespace Babylon::Plugins::Internal | ||
| { | ||
| class DataStream final : public Napi::ObjectWrap<DataStream> | ||
| { | ||
| public: | ||
| static inline constexpr const char* JS_INSTANCE_NAME{"fflate"}; | ||
|
|
||
| using ParentT = Napi::ObjectWrap<DataStream>; | ||
|
|
||
| static void CreateInstance(Napi::Env env) | ||
| { | ||
| Napi::HandleScope scope{env}; | ||
|
|
||
| Napi::Object fflate = Napi::Object::New(env); | ||
|
|
||
| fflate.Set("unzipSync", Napi::Function::New(env, DataStream::UnzipSync, "unzipSync")); | ||
|
|
||
| // Attach to global scope | ||
| env.Global().Set("fflate", fflate); | ||
| } | ||
|
|
||
| DataStream(const Napi::CallbackInfo& info) | ||
| : DataStream(info, JsRuntime::GetFromJavaScript(info.Env())) | ||
| { | ||
| } | ||
|
|
||
| explicit DataStream(const Napi::CallbackInfo& info, JsRuntime& runtime) | ||
| : ParentT{info} | ||
| , m_runtime{runtime} | ||
| { | ||
| } | ||
|
|
||
| private: | ||
| JsRuntime& m_runtime; | ||
|
|
||
| static Napi::Value UnzipSync(const Napi::CallbackInfo& info); | ||
|
|
||
| }; | ||
| } // namespace |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.