Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aglitchman committed Sep 17, 2024
0 parents commit e1f35e1
Show file tree
Hide file tree
Showing 18 changed files with 54,741 additions and 0 deletions.
121 changes: 121 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: 0
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: DontAlign
AlignOperands: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeComma
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 0
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 0
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseTab: Never
...

18 changes: 18 additions & 0 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
It's a native extension for the Defold game engine. It uses Lua 5.1 as its scripting language with "bit" module for bitwise operations. 4 spaces for indentation. "snake_case" for variable, function, file, folder names. It uses LDoc for documentation.

The example of LDoc is:

```lua
--- Summary ends with a period.
-- Some description, can be over several lines.
-- @tparam string p1 first parameter
-- @tparam[opt] string p2 second parameter (optional)
-- @treturn number a number value
-- @see second_fun
function mod1.first_fun(p1,p2)
end
```

The structure of the project is the following:
- folder "zstd" contains the Lua and C/C++ part of the extension. C/C++ code is compiled to WebAssembly via Emscripten or to the native code for other platforms.
- folder "example" contains the example project written in Lua for the extension.
3 changes: 3 additions & 0 deletions .defignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/netlib_src/node_modules
/netlib_src/dist
/netlib_src/.parcel-cache
53 changes: 53 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Defold Protocol Buffer Text Files (https://github.com/github/linguist/issues/5091)
*.animationset linguist-language=JSON5 gitlab-language=protobuf
*.atlas linguist-language=JSON5 gitlab-language=protobuf
*.camera linguist-language=JSON5 gitlab-language=protobuf
*.collection linguist-language=JSON5 gitlab-language=protobuf
*.collectionfactory linguist-language=JSON5 gitlab-language=protobuf
*.collectionproxy linguist-language=JSON5 gitlab-language=protobuf
*.collisionobject linguist-language=JSON5 gitlab-language=protobuf
*.cubemap linguist-language=JSON5 gitlab-language=protobuf
*.display_profiles linguist-language=JSON5 gitlab-language=protobuf
*.factory linguist-language=JSON5 gitlab-language=protobuf
*.font linguist-language=JSON5 gitlab-language=protobuf
*.gamepads linguist-language=JSON5 gitlab-language=protobuf
*.go linguist-language=JSON5 gitlab-language=protobuf
*.gui linguist-language=JSON5 gitlab-language=protobuf
*.input_binding linguist-language=JSON5 gitlab-language=protobuf
*.label linguist-language=JSON5 gitlab-language=protobuf
*.material linguist-language=JSON5 gitlab-language=protobuf
*.mesh linguist-language=JSON5 gitlab-language=protobuf
*.model linguist-language=JSON5 gitlab-language=protobuf
*.particlefx linguist-language=JSON5 gitlab-language=protobuf
*.render linguist-language=JSON5 gitlab-language=protobuf
*.sound linguist-language=JSON5 gitlab-language=protobuf
*.sprite linguist-language=JSON5 gitlab-language=protobuf
*.spinemodel linguist-language=JSON5 gitlab-language=protobuf
*.spinescene linguist-language=JSON5 gitlab-language=protobuf
*.texture_profiles linguist-language=JSON5 gitlab-language=protobuf
*.tilemap linguist-language=JSON5 gitlab-language=protobuf
*.tilesource linguist-language=JSON5 gitlab-language=protobuf

# Defold JSON Files
*.buffer linguist-language=JSON gitlab-language=json

# Defold GLSL Shaders
*.fp text eol=lf linguist-language=GLSL gitlab-language=glsl
*.vp text eol=lf linguist-language=GLSL gitlab-language=glsl

# Defold Lua Files
*.editor_script text eol=lf linguist-language=Lua gitlab-language=lua
*.render_script text eol=lf linguist-language=Lua gitlab-language=lua
*.script text eol=lf linguist-language=Lua gitlab-language=lua
*.gui_script text eol=lf linguist-language=Lua gitlab-language=lua

# Defold Project Settings
*.project linguist-language=INI gitlab-language=ini

# EOL Settings
*.cpp text eol=lf
*.html text eol=lf
*.json text eol=lf
*.lua text eol=lf
*.md text eol=lf
*.yml text eol=lf
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/.internal
/build
.externalToolBuilders
.DS_Store
Thumbs.db
.lock-wscript
*.pyc
.project
.cproject
builtins
.vscode
/netlib_src
30 changes: 30 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
BSD License

For Zstandard software

Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name Facebook, nor Meta, nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Zstandard Compression for Defold

This is a native extension for [the Defold game engine](https://defold.com/) that allows you to use Zstandard to compress and decompress strings in your Lua code. The included version of Zstd is 1.5.6.

Currently, the extension has simple API with two functions: `compress` and `decompress`. It doesn't support streaming, dictionaries and other features of the Zstd library. If you need more features, you can fill an issue on GitHub or even better - submit a PR.

## Usage

First add this extension as a dependency to your `game.project`:

https://github.com/indiesoftby/defold-zstd/archive/main.zip

Then you can use the extension in your Lua code:

```lua
local zstd = require "zstd"

local compression_level = 3 -- maximum and the slowest compression level is 22
local compressed = zstd.compress("Hello, world!", compression_level)
local decompressed = zstd.decompress(compressed)

print(decompressed)
```

## API

### `zstd.version()`
Returns the version of the Zstandard library.

**Returns:**
- `string`: The version.

### `zstd.compress(data, level)`
Compresses a string.

**Parameters:**
- `data` (string): The data to compress.
- `level` (number, optional): Optional compression level (default is 3, maximum is 22)

**Returns:**
- `string`: The compressed data

### `zstd.decompress(data)`
Decompresses a string.

**Parameters:**
- `data` (string): The data to decompress.

**Returns:**
- `string`: The decompressed data.

## License

This project is licensed under the BSD 3-Clause License. See the LICENSE file for details.
37 changes: 37 additions & 0 deletions example/example.collection
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "main"
scale_along_z: 0
embedded_instances {
id: "go"
data: "components {\n"
" id: \"example\"\n"
" component: \"/example/example.script\"\n"
" position {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" }\n"
" rotation {\n"
" x: 0.0\n"
" y: 0.0\n"
" z: 0.0\n"
" w: 1.0\n"
" }\n"
"}\n"
""
position {
x: 0.0
y: 0.0
z: 0.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale3 {
x: 1.0
y: 1.0
z: 1.0
}
}
33 changes: 33 additions & 0 deletions example/example.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function init(self)
print("VERSION", zstd.version())

local str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
local compressed = zstd.compress(str)
local decompressed = zstd.decompress(compressed)
assert(str == decompressed)
print(#str,"vs",#compressed,"vs",#zstd.compress(str, 22))
end

function final(self)

end

function update(self, dt)
-- Add update code here
-- Remove this function if not needed
end

function on_message(self, message_id, message, sender)
-- Add message-handling code here
-- Remove this function if not needed
end

function on_input(self, action_id, action)
-- Add input-handling code here
-- Remove this function if not needed
end

function on_reload(self)
-- Add reload-handling code here
-- Remove this function if not needed
end
25 changes: 25 additions & 0 deletions game.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[bootstrap]
main_collection = /example/example.collectionc

[script]
shared_state = 1

[display]
width = 960
height = 640
high_dpi = 1

[project]
title = zstd_example

[library]
include_dirs = zstd

[input]
game_binding = /builtins/input/all.input_bindingc

[html5]
heap_size = 32
scale_mode = stretch
cssfile = /builtins/manifests/web/dark_theme.css

Binary file added manifest.private.der
Binary file not shown.
Binary file added manifest.public.der
Binary file not shown.
Loading

0 comments on commit e1f35e1

Please sign in to comment.