Compare commits
66 Commits
v0.1.2
...
9745ccc7d6
| Author | SHA1 | Date | |
|---|---|---|---|
| 9745ccc7d6 | |||
| 94d92f2159 | |||
| 33cfea1f36 | |||
| c6a75e709e | |||
| 3534acd90f | |||
| 2e9df71b31 | |||
| 5f2644b52d | |||
| d6051486a8 | |||
| b2187bf0ad | |||
| 2aa9d07e43 | |||
| 8ff789c576 | |||
| 322fb2fea0 | |||
| 277aab1b81 | |||
| 30b4060fb5 | |||
| 0ffa2804d1 | |||
| abf1f4db7d | |||
| 1514338144 | |||
| 8af30e159d | |||
| 0259ca71ce | |||
| 2358cfd9a4 | |||
| 5e7c6ec891 | |||
| ef3be12b64 | |||
| 67fbbe1229 | |||
| d970988022 | |||
| e2bbc2d57f | |||
| 6b1f9d7354 | |||
| 5980400e2e | |||
| 9bb1882d92 | |||
| a54858e4c6 | |||
| 18e308bd03 | |||
| 2e4a32fed7 | |||
| c5ce91e653 | |||
| 412f88565a | |||
| 8451921161 | |||
| d6f304e6ca | |||
| 826c6600d0 | |||
| b166bab4f3 | |||
| efa49a98b7 | |||
| 3a9ab6a14a | |||
| d15037e7a3 | |||
| 0ff5820e6e | |||
| 5e96c1573b | |||
| 90273e87f2 | |||
| 1e106d75a3 | |||
| bd1a9557a5 | |||
| 831569cec6 | |||
| a5c1c7d4aa | |||
| 802d2ecb5a | |||
| ab605f7590 | |||
| 15d5af34b9 | |||
| 6d0e60e241 | |||
| 7b530968af | |||
| 930226cc47 | |||
| f9bf2f4b89 | |||
| df3ac5b5db | |||
| 2568eb7d18 | |||
| 2e3b4f4f0f | |||
| 5951a5e81c | |||
| 849386a3bc | |||
| 3e7ce71219 | |||
| 94fed9a810 | |||
| f4174724c6 | |||
|
|
def311c7dd | ||
|
|
45d2c8234a | ||
|
|
0f731530da | ||
|
|
2b75c510af |
13
.github/workflows/release-build.yml
vendored
@@ -27,7 +27,8 @@ jobs:
|
|||||||
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
env:
|
||||||
|
VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}/.vcpkg-cache,readwrite
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -48,12 +49,18 @@ jobs:
|
|||||||
- name: Setup MSVC
|
- name: Setup MSVC
|
||||||
if: matrix.platform == 'windows'
|
if: matrix.platform == 'windows'
|
||||||
uses: ilammy/msvc-dev-cmd@v1
|
uses: ilammy/msvc-dev-cmd@v1
|
||||||
|
- name: Cache vcpkg
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: .vcpkg-cache
|
||||||
|
key: ${{ runner.os }}-vcpkg-${{ hashFiles('vcpkg.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-vcpkg-
|
||||||
- name: Bootstrap vcpkg
|
- name: Bootstrap vcpkg
|
||||||
run: |
|
run: |
|
||||||
git clone https://github.com/microsoft/vcpkg.git
|
git clone https://github.com/microsoft/vcpkg.git
|
||||||
./vcpkg/bootstrap-vcpkg.bat
|
./vcpkg/bootstrap-vcpkg.bat
|
||||||
|
|
||||||
- name: Configure
|
- name: Configure
|
||||||
if: matrix.platform == 'windows'
|
if: matrix.platform == 'windows'
|
||||||
run: >
|
run: >
|
||||||
|
|||||||
251
AGENTS.md
Normal file
@@ -0,0 +1,251 @@
|
|||||||
|
# Code Modification Guidelines
|
||||||
|
|
||||||
|
## 1. Git Branch Protection
|
||||||
|
|
||||||
|
- Never modify code directly on the `main` branch.
|
||||||
|
- Before editing, check the current branch:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git branch --show-current
|
||||||
|
````
|
||||||
|
|
||||||
|
* If the result is `main`, create or switch to a development branch first:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git checkout -b feature/xxx
|
||||||
|
```
|
||||||
|
|
||||||
|
* Do not bypass branch protection by:
|
||||||
|
|
||||||
|
* Committing directly to `main`.
|
||||||
|
* Running code generation, formatting, or large refactors on `main`.
|
||||||
|
* Rewriting or damaging `main` history.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Code Comments
|
||||||
|
|
||||||
|
* All new comments must be written in English.
|
||||||
|
* Comments must be:
|
||||||
|
|
||||||
|
* Short and clear.
|
||||||
|
* Explain the purpose, not repeat the code.
|
||||||
|
* Avoid unnecessary details.
|
||||||
|
|
||||||
|
Recommended:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// AI-generated: Prevent stale handle access.
|
||||||
|
```
|
||||||
|
|
||||||
|
Avoid:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// AI-generated: This checks if the handle is invalid because...
|
||||||
|
```
|
||||||
|
|
||||||
|
* Important AI-added or modified logic should include:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// AI-generated
|
||||||
|
```
|
||||||
|
|
||||||
|
* Do not add comments for trivial changes such as:
|
||||||
|
|
||||||
|
* One or two line logic fixes.
|
||||||
|
* Spelling corrections.
|
||||||
|
* Simple variable renames.
|
||||||
|
|
||||||
|
### 2.1 Do not write excessive or granular comments
|
||||||
|
|
||||||
|
AI must avoid sprinkling small explanatory comments throughout code.
|
||||||
|
Specifically:
|
||||||
|
|
||||||
|
* **No line-by-line narration.** Do not add a comment above (or beside)
|
||||||
|
every field, signal, slot, branch, or block just to restate what it is.
|
||||||
|
If the name is self-explanatory, no comment is needed.
|
||||||
|
* **No multi-part explanations on a single marker.** A line like
|
||||||
|
`// AI-generated: abort the in-flight download; finished handler clears state.`
|
||||||
|
is too much. Either drop it, or shorten to a single short clause
|
||||||
|
(e.g. `// AI-generated: abort in-flight download.`).
|
||||||
|
* **Prefer zero or one comment per file/section**, not many. A short
|
||||||
|
header comment explaining the file's purpose is acceptable; dozens of
|
||||||
|
inline labels are not.
|
||||||
|
* **Do not comment obvious QML/C++ bindings, layout splits, or default
|
||||||
|
values** (e.g. `// AI-generated: index 0 -> zh_CN, index 1 -> en.`).
|
||||||
|
The code already says that.
|
||||||
|
* **When in doubt, omit the comment.** A missing comment is fine; a
|
||||||
|
redundant one is noise that future maintainers must clean up.
|
||||||
|
|
||||||
|
Rule of thumb: if removing the comment would not lose useful
|
||||||
|
information, remove it.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Project Style
|
||||||
|
|
||||||
|
Follow the existing project style strictly:
|
||||||
|
|
||||||
|
* Naming conventions.
|
||||||
|
* File organization.
|
||||||
|
* Formatting rules.
|
||||||
|
* Include order.
|
||||||
|
* Existing architecture.
|
||||||
|
|
||||||
|
Do not:
|
||||||
|
|
||||||
|
* Introduce unrelated coding styles.
|
||||||
|
* Add unnecessary design patterns.
|
||||||
|
* Create duplicate systems.
|
||||||
|
* Add abstractions without need.
|
||||||
|
* Change module responsibilities.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Modification Scope
|
||||||
|
|
||||||
|
Only modify the minimum code required.
|
||||||
|
|
||||||
|
Do not:
|
||||||
|
|
||||||
|
* Format unrelated files.
|
||||||
|
* Remove existing comments.
|
||||||
|
* Rename large numbers of symbols.
|
||||||
|
* Change public APIs.
|
||||||
|
* Perform large refactors without confirmation.
|
||||||
|
|
||||||
|
If large changes are required, explain first:
|
||||||
|
|
||||||
|
1. Current problem.
|
||||||
|
2. Required changes.
|
||||||
|
3. Affected modules.
|
||||||
|
4. Expected impact.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Build and Test
|
||||||
|
|
||||||
|
After modifications:
|
||||||
|
|
||||||
|
* Verify compilation.
|
||||||
|
* Check for new warnings.
|
||||||
|
* Ensure existing features still work.
|
||||||
|
|
||||||
|
Do not:
|
||||||
|
|
||||||
|
* Commit without verification.
|
||||||
|
* Ignore compiler errors.
|
||||||
|
* Hide problems with temporary hacks.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. Compatibility
|
||||||
|
|
||||||
|
Consider:
|
||||||
|
|
||||||
|
* Existing callers.
|
||||||
|
* API/ABI compatibility.
|
||||||
|
* Serialization formats.
|
||||||
|
* Network protocols.
|
||||||
|
* Save data.
|
||||||
|
* Threading impact.
|
||||||
|
|
||||||
|
Do not:
|
||||||
|
|
||||||
|
* Change network structures without compatibility handling.
|
||||||
|
* Break old data formats.
|
||||||
|
* Change public data layouts carelessly.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. Multi-threading Safety
|
||||||
|
|
||||||
|
For multi-threaded code, check:
|
||||||
|
|
||||||
|
* Data races.
|
||||||
|
* Object lifetime.
|
||||||
|
* Lock contention.
|
||||||
|
* Atomic correctness.
|
||||||
|
* Cross-thread resource access.
|
||||||
|
|
||||||
|
Do not:
|
||||||
|
|
||||||
|
* Assume single-threaded execution.
|
||||||
|
* Modify shared data without protection.
|
||||||
|
* Add hidden locks that hurt performance.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. Memory Safety
|
||||||
|
|
||||||
|
Consider:
|
||||||
|
|
||||||
|
* Ownership.
|
||||||
|
* Lifetime.
|
||||||
|
* RAII.
|
||||||
|
* Memory leaks.
|
||||||
|
* Dangling references.
|
||||||
|
* Iterator invalidation.
|
||||||
|
|
||||||
|
Do not:
|
||||||
|
|
||||||
|
* Return references to local variables.
|
||||||
|
* Store pointers to temporary objects.
|
||||||
|
* Use uninitialized data.
|
||||||
|
* Introduce undefined behavior.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 9. Third-party Libraries
|
||||||
|
|
||||||
|
Before adding or changing dependencies:
|
||||||
|
|
||||||
|
Check:
|
||||||
|
|
||||||
|
* Existing project dependencies.
|
||||||
|
* Build system impact.
|
||||||
|
* Maintenance cost.
|
||||||
|
|
||||||
|
Do not:
|
||||||
|
|
||||||
|
* Add large libraries for simple features.
|
||||||
|
* Duplicate existing library functionality.
|
||||||
|
* Modify third-party source code.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 10. AI Behavior Rules
|
||||||
|
|
||||||
|
AI-generated code must:
|
||||||
|
|
||||||
|
* Reuse existing code first.
|
||||||
|
* Preserve current architecture.
|
||||||
|
* Prefer simple solutions.
|
||||||
|
* Minimize risk and code changes.
|
||||||
|
|
||||||
|
Do not:
|
||||||
|
|
||||||
|
* Guess requirements.
|
||||||
|
* Add unrequested features.
|
||||||
|
* Redesign architecture.
|
||||||
|
* Add unnecessary abstraction layers.
|
||||||
|
|
||||||
|
Choose the implementation with:
|
||||||
|
|
||||||
|
> The smallest change, lowest risk, and best compatibility with existing code.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 11. Pre-commit Checklist
|
||||||
|
|
||||||
|
Before committing:
|
||||||
|
|
||||||
|
* [ ] Not on `main`.
|
||||||
|
* [ ] Changes match the requested task.
|
||||||
|
* [ ] New comments are in English.
|
||||||
|
* [ ] AI changes are marked when needed.
|
||||||
|
* [ ] No unrelated formatting changes.
|
||||||
|
* [ ] Build passes.
|
||||||
|
* [ ] No obvious performance/security/thread issues.
|
||||||
|
* [ ] No API, protocol, or data format breakage.
|
||||||
|
|
||||||
@@ -39,6 +39,8 @@ add_subdirectory(third_party/imgui)
|
|||||||
|
|
||||||
add_subdirectory(third_party/dr_libs)
|
add_subdirectory(third_party/dr_libs)
|
||||||
|
|
||||||
|
add_subdirectory(third_party/stb)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME})
|
add_executable(${PROJECT_NAME})
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
@@ -128,16 +130,14 @@ target_include_directories(${PROJECT_NAME}
|
|||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
target_link_libraries(${PROJECT_NAME}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
glfw
|
SDL3::SDL3
|
||||||
glad
|
glad
|
||||||
glm::glm
|
|
||||||
OpenGL::GL
|
OpenGL::GL
|
||||||
soil2
|
|
||||||
Freetype::Freetype
|
Freetype::Freetype
|
||||||
tomlplusplus::tomlplusplus
|
|
||||||
imgui
|
imgui
|
||||||
dr_libs
|
dr_libs
|
||||||
tbb
|
tbb
|
||||||
|
stb
|
||||||
protobuf::libprotobuf
|
protobuf::libprotobuf
|
||||||
absl::log
|
absl::log
|
||||||
absl::check
|
absl::check
|
||||||
@@ -147,6 +147,8 @@ target_link_libraries(${PROJECT_NAME}
|
|||||||
zstd::zstd
|
zstd::zstd
|
||||||
OpenAL::OpenAL
|
OpenAL::OpenAL
|
||||||
harfbuzz::harfbuzz
|
harfbuzz::harfbuzz
|
||||||
|
Opus::Opus
|
||||||
|
assimp::assimp
|
||||||
$<$<PLATFORM_ID:Windows>:ws2_32>
|
$<$<PLATFORM_ID:Windows>:ws2_32>
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|||||||
4
assets/SensitiveLexicon.json
Normal file
@@ -8,4 +8,4 @@ is_passable = true
|
|||||||
is_transitional = false
|
is_transitional = false
|
||||||
is_transparent = true
|
is_transparent = true
|
||||||
name = 'grass'
|
name = 'grass'
|
||||||
roughness = 0.9
|
roughness = 0.90000000000000002
|
||||||
@@ -8,4 +8,4 @@ is_passable = false
|
|||||||
is_transitional = true
|
is_transitional = true
|
||||||
is_transparent = false
|
is_transparent = false
|
||||||
name = 'grass_block'
|
name = 'grass_block'
|
||||||
roughness = 0.9
|
roughness = 0.90000000000000002
|
||||||
@@ -8,4 +8,4 @@ is_passable = false
|
|||||||
is_transitional = false
|
is_transitional = false
|
||||||
is_transparent = true
|
is_transparent = true
|
||||||
name = 'leaf'
|
name = 'leaf'
|
||||||
roughness = 0.7
|
roughness = 0.69999999999999996
|
||||||
@@ -8,4 +8,4 @@ is_passable = false
|
|||||||
is_transitional = false
|
is_transitional = false
|
||||||
is_transparent = false
|
is_transparent = false
|
||||||
name = 'log'
|
name = 'log'
|
||||||
roughness = 0.7
|
roughness = 0.69999999999999996
|
||||||
@@ -8,4 +8,4 @@ is_passable = false
|
|||||||
is_transitional = true
|
is_transitional = true
|
||||||
is_transparent = false
|
is_transparent = false
|
||||||
name = 'sand'
|
name = 'sand'
|
||||||
roughness = 0.8
|
roughness = 0.80000000000000004
|
||||||
@@ -8,4 +8,4 @@ is_passable = false
|
|||||||
is_transitional = true
|
is_transitional = true
|
||||||
is_transparent = false
|
is_transparent = false
|
||||||
name = 'snowy_grass_block'
|
name = 'snowy_grass_block'
|
||||||
roughness = 0.9
|
roughness = 0.90000000000000002
|
||||||
@@ -8,4 +8,4 @@ is_transparent = false
|
|||||||
is_discard = false
|
is_discard = false
|
||||||
is_blend = false
|
is_blend = false
|
||||||
is_transitional = false
|
is_transitional = false
|
||||||
roughness = 1.0
|
roughness = 1.0
|
||||||
|
|||||||
6
assets/item/air.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"id": 0,
|
||||||
|
"name": "air",
|
||||||
|
"description": "",
|
||||||
|
"type": "block"
|
||||||
|
}
|
||||||
7
assets/item/dirt.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "dirt",
|
||||||
|
"description": "",
|
||||||
|
"texture": "texture/item/block/dirt.png",
|
||||||
|
"type": "block"
|
||||||
|
}
|
||||||
7
assets/item/grass.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"id": 9,
|
||||||
|
"name": "grass",
|
||||||
|
"description": "",
|
||||||
|
"texture": "texture/item/block/grass.png",
|
||||||
|
"type": "block"
|
||||||
|
}
|
||||||
7
assets/item/grass_block.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "grass_block",
|
||||||
|
"description": "",
|
||||||
|
"texture": "texture/item/block/grass_block.png",
|
||||||
|
"type": "block"
|
||||||
|
}
|
||||||
7
assets/item/leaf.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"id": 6,
|
||||||
|
"name": "leaf",
|
||||||
|
"description": "",
|
||||||
|
"texture": "texture/item/block/leaf.png",
|
||||||
|
"type": "block"
|
||||||
|
}
|
||||||
7
assets/item/log.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"name": "log",
|
||||||
|
"description": "",
|
||||||
|
"texture": "texture/item/block/log.png",
|
||||||
|
"type": "block"
|
||||||
|
}
|
||||||
8
assets/item/pig_spawn_egg.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"id": 10,
|
||||||
|
"name": "pig_spawn_egg",
|
||||||
|
"description": "",
|
||||||
|
"texture": "texture/item/spawn_egg/pig_spawn_egg.png",
|
||||||
|
"type": "spawn_egg",
|
||||||
|
"creature": "cubed:pig"
|
||||||
|
}
|
||||||
7
assets/item/sand.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"name": "sand",
|
||||||
|
"description": "",
|
||||||
|
"texture": "texture/item/block/sand.png",
|
||||||
|
"type": "block"
|
||||||
|
}
|
||||||
7
assets/item/snowy_grass_block.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"id": 8,
|
||||||
|
"name": "snowy_grass_block",
|
||||||
|
"description": "",
|
||||||
|
"texture": "texture/item/block/snowy_grass_block.png",
|
||||||
|
"type": "block"
|
||||||
|
}
|
||||||
7
assets/item/stone.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": "stone",
|
||||||
|
"description": "",
|
||||||
|
"texture": "texture/item/block/stone.png",
|
||||||
|
"type": "block"
|
||||||
|
}
|
||||||
7
assets/item/water.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"id": 7,
|
||||||
|
"name": "water",
|
||||||
|
"description": "",
|
||||||
|
"texture": "texture/item/block/water.png",
|
||||||
|
"type": "block"
|
||||||
|
}
|
||||||
@@ -17,11 +17,15 @@
|
|||||||
"settings.distance": "Distance: {distance}",
|
"settings.distance": "Distance: {distance}",
|
||||||
"settings.music_volume": "Music: {music}",
|
"settings.music_volume": "Music: {music}",
|
||||||
"settings.sfx_volume": "SFX: {sfx}",
|
"settings.sfx_volume": "SFX: {sfx}",
|
||||||
|
"settings.player_voice": "Player Voice: {volume}",
|
||||||
"settings.fullscreen": "fullscreen: {state}",
|
"settings.fullscreen": "fullscreen: {state}",
|
||||||
"settings.aniso": "Aniso: {aniso}",
|
"settings.aniso": "Aniso: {aniso}",
|
||||||
"settings.vsync": "V-Sync: {state}",
|
"settings.vsync": "V-Sync: {state}",
|
||||||
"settings.language": "Language: {lang}",
|
"settings.language": "Language: {lang}",
|
||||||
"settings.restart_game_info": "You need to restart the game to apply this changes.",
|
"settings.restart_game_info": "You need to restart the game to apply this changes.",
|
||||||
|
"settings.voice_input": "Voice Input: {type}",
|
||||||
|
"voice_input.ptt": "PTT",
|
||||||
|
"voice_input.always": "always",
|
||||||
"common.on": "on",
|
"common.on": "on",
|
||||||
"common.off": "off",
|
"common.off": "off",
|
||||||
"hostgame.create_a_new_world": "Create A New World",
|
"hostgame.create_a_new_world": "Create A New World",
|
||||||
@@ -30,5 +34,17 @@
|
|||||||
"hostgame.create_world": "Create World",
|
"hostgame.create_world": "Create World",
|
||||||
"joingame.join_a_world": "Join A World",
|
"joingame.join_a_world": "Join A World",
|
||||||
"joingame.server_ip": "Server Ip",
|
"joingame.server_ip": "Server Ip",
|
||||||
"joingame.join_world": "Join World"
|
"joingame.join_world": "Join World",
|
||||||
|
"error.disable_voice": "Server Disable Voice Chat",
|
||||||
|
"item.air.name": "air",
|
||||||
|
"item.dirt.name": "dirt",
|
||||||
|
"item.grass_block.name": "grass block",
|
||||||
|
"item.grass.name": "grass",
|
||||||
|
"item.leaf.name": "leaf",
|
||||||
|
"item.log.name": "log",
|
||||||
|
"item.sand.name": "sand",
|
||||||
|
"item.snowy_grass_block.name": "snowy grass block",
|
||||||
|
"item.stone.name": "stone",
|
||||||
|
"item.water.name": "water",
|
||||||
|
"item.pig_spawn_egg.name": "pig spawn egg"
|
||||||
}
|
}
|
||||||
@@ -17,11 +17,15 @@
|
|||||||
"settings.distance": "距离:{distance}",
|
"settings.distance": "距离:{distance}",
|
||||||
"settings.music_volume": "音乐:{music}",
|
"settings.music_volume": "音乐:{music}",
|
||||||
"settings.sfx_volume": "音效:{sfx}",
|
"settings.sfx_volume": "音效:{sfx}",
|
||||||
|
"settings.player_voice": "玩家语音:{volume}",
|
||||||
"settings.fullscreen": "全屏:{state}",
|
"settings.fullscreen": "全屏:{state}",
|
||||||
"settings.aniso": "各向异性过滤:{aniso}",
|
"settings.aniso": "各向异性过滤:{aniso}",
|
||||||
"settings.vsync": "垂直同步: {state}",
|
"settings.vsync": "垂直同步: {state}",
|
||||||
"settings.language": "语言: {lang}",
|
"settings.language": "语言: {lang}",
|
||||||
"settings.restart_game_info": "您需要重启游戏以应用这些更改。",
|
"settings.restart_game_info": "您需要重启游戏以应用这些更改。",
|
||||||
|
"settings.voice_input": "语音输入: {type}",
|
||||||
|
"voice_input.ptt": "按键通话",
|
||||||
|
"voice_input.always": "始终",
|
||||||
"common.on": "开",
|
"common.on": "开",
|
||||||
"common.off": "关",
|
"common.off": "关",
|
||||||
"hostgame.create_a_new_world": "创建新世界",
|
"hostgame.create_a_new_world": "创建新世界",
|
||||||
@@ -30,5 +34,17 @@
|
|||||||
"hostgame.create_world": "创建世界",
|
"hostgame.create_world": "创建世界",
|
||||||
"joingame.join_a_world": "加入世界",
|
"joingame.join_a_world": "加入世界",
|
||||||
"joingame.server_ip": "服务器IP",
|
"joingame.server_ip": "服务器IP",
|
||||||
"joingame.join_world": "加入世界"
|
"joingame.join_world": "加入世界",
|
||||||
|
"error.disable_voice": "服务器已禁用语音聊天",
|
||||||
|
"item.air.name": "空气",
|
||||||
|
"item.dirt.name": "泥土",
|
||||||
|
"item.grass_block.name": "草方块",
|
||||||
|
"item.grass.name": "草",
|
||||||
|
"item.leaf.name": "树叶",
|
||||||
|
"item.log.name": "原木",
|
||||||
|
"item.sand.name": "沙子",
|
||||||
|
"item.snowy_grass_block.name": "覆雪草方块",
|
||||||
|
"item.stone.name": "石头",
|
||||||
|
"item.water.name": "水",
|
||||||
|
"item.pig_spawn_egg.name": "猪猪刷怪蛋"
|
||||||
}
|
}
|
||||||
437
assets/licenses/OPENAL_SOFT_LICENSE.txt
Normal file
@@ -0,0 +1,437 @@
|
|||||||
|
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||||
|
Version 2, June 1991
|
||||||
|
|
||||||
|
Copyright (C) 1991 Free Software Foundation, Inc.
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
[This is the first released version of the library GPL. It is
|
||||||
|
numbered 2 because it goes with version 2 of the ordinary GPL.]
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
Licenses are intended to guarantee your freedom to share and change
|
||||||
|
free software--to make sure the software is free for all its users.
|
||||||
|
|
||||||
|
This license, the Library General Public License, applies to some
|
||||||
|
specially designated Free Software Foundation software, and to any
|
||||||
|
other libraries whose authors decide to use it. You can use it for
|
||||||
|
your libraries, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
this service if you wish), that you receive source code or can get it
|
||||||
|
if you want it, that you can change the software or use pieces of it
|
||||||
|
in new free programs; and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
anyone to deny you these rights or to ask you to surrender the rights.
|
||||||
|
These restrictions translate to certain responsibilities for you if
|
||||||
|
you distribute copies of the library, or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of the library, whether gratis
|
||||||
|
or for a fee, you must give the recipients all the rights that we gave
|
||||||
|
you. You must make sure that they, too, receive or can get the source
|
||||||
|
code. If you link a program with the library, you must provide
|
||||||
|
complete object files to the recipients so that they can relink them
|
||||||
|
with the library, after making changes to the library and recompiling
|
||||||
|
it. And you must show them these terms so they know their rights.
|
||||||
|
|
||||||
|
Our method of protecting your rights has two steps: (1) copyright
|
||||||
|
the library, and (2) offer you this license which gives you legal
|
||||||
|
permission to copy, distribute and/or modify the library.
|
||||||
|
|
||||||
|
Also, for each distributor's protection, we want to make certain
|
||||||
|
that everyone understands that there is no warranty for this free
|
||||||
|
library. If the library is modified by someone else and passed on, we
|
||||||
|
want its recipients to know that what they have is not the original
|
||||||
|
version, so that any problems introduced by others will not reflect on
|
||||||
|
the original authors' reputations.
|
||||||
|
|
||||||
|
Finally, any free program is threatened constantly by software
|
||||||
|
patents. We wish to avoid the danger that companies distributing free
|
||||||
|
software will individually obtain patent licenses, thus in effect
|
||||||
|
transforming the program into proprietary software. To prevent this,
|
||||||
|
we have made it clear that any patent must be licensed for everyone's
|
||||||
|
free use or not licensed at all.
|
||||||
|
|
||||||
|
Most GNU software, including some libraries, is covered by the ordinary
|
||||||
|
GNU General Public License, which was designed for utility programs. This
|
||||||
|
license, the GNU Library General Public License, applies to certain
|
||||||
|
designated libraries. This license is quite different from the ordinary
|
||||||
|
one; be sure to read it in full, and don't assume that anything in it is
|
||||||
|
the same as in the ordinary license.
|
||||||
|
|
||||||
|
The reason we have a separate public license for some libraries is that
|
||||||
|
they blur the distinction we usually make between modifying or adding to a
|
||||||
|
program and simply using it. Linking a program with a library, without
|
||||||
|
changing the library, is in some sense simply using the library, and is
|
||||||
|
analogous to running a utility program or application program. However, in
|
||||||
|
a textual and legal sense, the linked executable is a combined work, a
|
||||||
|
derivative of the original library, and the ordinary General Public License
|
||||||
|
treats it as such.
|
||||||
|
|
||||||
|
Because of this blurred distinction, using the ordinary General
|
||||||
|
Public License for libraries did not effectively promote software
|
||||||
|
sharing, because most developers did not use the libraries. We
|
||||||
|
concluded that weaker conditions might promote sharing better.
|
||||||
|
|
||||||
|
However, unrestricted linking of non-free programs would deprive the
|
||||||
|
users of those programs of all benefit from the free status of the
|
||||||
|
libraries themselves. This Library General Public License is intended to
|
||||||
|
permit developers of non-free programs to use free libraries, while
|
||||||
|
preserving your freedom as a user of such programs to change the free
|
||||||
|
libraries that are incorporated in them. (We have not seen how to achieve
|
||||||
|
this as regards changes in header files, but we have achieved it as regards
|
||||||
|
changes in the actual functions of the Library.) The hope is that this
|
||||||
|
will lead to faster development of free libraries.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow. Pay close attention to the difference between a
|
||||||
|
"work based on the library" and a "work that uses the library". The
|
||||||
|
former contains code derived from the library, while the latter only
|
||||||
|
works together with the library.
|
||||||
|
|
||||||
|
Note that it is possible for a library to be covered by the ordinary
|
||||||
|
General Public License rather than by this special one.
|
||||||
|
|
||||||
|
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License Agreement applies to any software library which
|
||||||
|
contains a notice placed by the copyright holder or other authorized
|
||||||
|
party saying it may be distributed under the terms of this Library
|
||||||
|
General Public License (also called "this License"). Each licensee is
|
||||||
|
addressed as "you".
|
||||||
|
|
||||||
|
A "library" means a collection of software functions and/or data
|
||||||
|
prepared so as to be conveniently linked with application programs
|
||||||
|
(which use some of those functions and data) to form executables.
|
||||||
|
|
||||||
|
The "Library", below, refers to any such software library or work
|
||||||
|
which has been distributed under these terms. A "work based on the
|
||||||
|
Library" means either the Library or any derivative work under
|
||||||
|
copyright law: that is to say, a work containing the Library or a
|
||||||
|
portion of it, either verbatim or with modifications and/or translated
|
||||||
|
straightforwardly into another language. (Hereinafter, translation is
|
||||||
|
included without limitation in the term "modification".)
|
||||||
|
|
||||||
|
"Source code" for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For a library, complete source code means
|
||||||
|
all the source code for all modules it contains, plus any associated
|
||||||
|
interface definition files, plus the scripts used to control compilation
|
||||||
|
and installation of the library.
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running a program using the Library is not restricted, and output from
|
||||||
|
such a program is covered only if its contents constitute a work based
|
||||||
|
on the Library (independent of the use of the Library in a tool for
|
||||||
|
writing it). Whether that is true depends on what the Library does
|
||||||
|
and what the program that uses the Library does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Library's
|
||||||
|
complete source code as you receive it, in any medium, provided that
|
||||||
|
you conspicuously and appropriately publish on each copy an
|
||||||
|
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||||
|
all the notices that refer to this License and to the absence of any
|
||||||
|
warranty; and distribute a copy of this License along with the
|
||||||
|
Library.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy,
|
||||||
|
and you may at your option offer warranty protection in exchange for a
|
||||||
|
fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Library or any portion
|
||||||
|
of it, thus forming a work based on the Library, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The modified work must itself be a software library.
|
||||||
|
|
||||||
|
b) You must cause the files modified to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
c) You must cause the whole of the work to be licensed at no
|
||||||
|
charge to all third parties under the terms of this License.
|
||||||
|
|
||||||
|
d) If a facility in the modified Library refers to a function or a
|
||||||
|
table of data to be supplied by an application program that uses
|
||||||
|
the facility, other than as an argument passed when the facility
|
||||||
|
is invoked, then you must make a good faith effort to ensure that,
|
||||||
|
in the event an application does not supply such function or
|
||||||
|
table, the facility still operates, and performs whatever part of
|
||||||
|
its purpose remains meaningful.
|
||||||
|
|
||||||
|
(For example, a function in a library to compute square roots has
|
||||||
|
a purpose that is entirely well-defined independent of the
|
||||||
|
application. Therefore, Subsection 2d requires that any
|
||||||
|
application-supplied function or table used by this function must
|
||||||
|
be optional: if the application does not supply it, the square
|
||||||
|
root function must still compute square roots.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Library,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Library, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote
|
||||||
|
it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Library.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Library
|
||||||
|
with the Library (or with a work based on the Library) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||||
|
License instead of this License to a given copy of the Library. To do
|
||||||
|
this, you must alter all the notices that refer to this License, so
|
||||||
|
that they refer to the ordinary GNU General Public License, version 2,
|
||||||
|
instead of to this License. (If a newer version than version 2 of the
|
||||||
|
ordinary GNU General Public License has appeared, then you can specify
|
||||||
|
that version instead if you wish.) Do not make any other change in
|
||||||
|
these notices.
|
||||||
|
|
||||||
|
Once this change is made in a given copy, it is irreversible for
|
||||||
|
that copy, so the ordinary GNU General Public License applies to all
|
||||||
|
subsequent copies and derivative works made from that copy.
|
||||||
|
|
||||||
|
This option is useful when you wish to copy part of the code of
|
||||||
|
the Library into a program that is not a library.
|
||||||
|
|
||||||
|
4. You may copy and distribute the Library (or a portion or
|
||||||
|
derivative of it, under Section 2) in object code or executable form
|
||||||
|
under the terms of Sections 1 and 2 above provided that you accompany
|
||||||
|
it with the complete corresponding machine-readable source code, which
|
||||||
|
must be distributed under the terms of Sections 1 and 2 above on a
|
||||||
|
medium customarily used for software interchange.
|
||||||
|
|
||||||
|
If distribution of object code is made by offering access to copy
|
||||||
|
from a designated place, then offering equivalent access to copy the
|
||||||
|
source code from the same place satisfies the requirement to
|
||||||
|
distribute the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
5. A program that contains no derivative of any portion of the
|
||||||
|
Library, but is designed to work with the Library by being compiled or
|
||||||
|
linked with it, is called a "work that uses the Library". Such a
|
||||||
|
work, in isolation, is not a derivative work of the Library, and
|
||||||
|
therefore falls outside the scope of this License.
|
||||||
|
|
||||||
|
However, linking a "work that uses the Library" with the Library
|
||||||
|
creates an executable that is a derivative of the Library (because it
|
||||||
|
contains portions of the Library), rather than a "work that uses the
|
||||||
|
library". The executable is therefore covered by this License.
|
||||||
|
Section 6 states terms for distribution of such executables.
|
||||||
|
|
||||||
|
When a "work that uses the Library" uses material from a header file
|
||||||
|
that is part of the Library, the object code for the work may be a
|
||||||
|
derivative work of the Library even though the source code is not.
|
||||||
|
Whether this is true is especially significant if the work can be
|
||||||
|
linked without the Library, or if the work is itself a library. The
|
||||||
|
threshold for this to be true is not precisely defined by law.
|
||||||
|
|
||||||
|
If such an object file uses only numerical parameters, data
|
||||||
|
structure layouts and accessors, and small macros and small inline
|
||||||
|
functions (ten lines or less in length), then the use of the object
|
||||||
|
file is unrestricted, regardless of whether it is legally a derivative
|
||||||
|
work. (Executables containing this object code plus portions of the
|
||||||
|
Library will still fall under Section 6.)
|
||||||
|
|
||||||
|
Otherwise, if the work is a derivative of the Library, you may
|
||||||
|
distribute the object code for the work under the terms of Section 6.
|
||||||
|
Any executables containing that work also fall under Section 6,
|
||||||
|
whether or not they are linked directly with the Library itself.
|
||||||
|
|
||||||
|
6. As an exception to the Sections above, you may also compile or
|
||||||
|
link a "work that uses the Library" with the Library to produce a
|
||||||
|
work containing portions of the Library, and distribute that work
|
||||||
|
under terms of your choice, provided that the terms permit
|
||||||
|
modification of the work for the customer's own use and reverse
|
||||||
|
engineering for debugging such modifications.
|
||||||
|
|
||||||
|
You must give prominent notice with each copy of the work that the
|
||||||
|
Library is used in it and that the Library and its use are covered by
|
||||||
|
this License. You must supply a copy of this License. If the work
|
||||||
|
during execution displays copyright notices, you must include the
|
||||||
|
copyright notice for the Library among them, as well as a reference
|
||||||
|
directing the user to the copy of this License. Also, you must do one
|
||||||
|
of these things:
|
||||||
|
|
||||||
|
a) Accompany the work with the complete corresponding
|
||||||
|
machine-readable source code for the Library including whatever
|
||||||
|
changes were used in the work (which must be distributed under
|
||||||
|
Sections 1 and 2 above); and, if the work is an executable linked
|
||||||
|
with the Library, with the complete machine-readable "work that
|
||||||
|
uses the Library", as object code and/or source code, so that the
|
||||||
|
user can modify the Library and then relink to produce a modified
|
||||||
|
executable containing the modified Library. (It is understood
|
||||||
|
that the user who changes the contents of definitions files in the
|
||||||
|
Library will not necessarily be able to recompile the application
|
||||||
|
to use the modified definitions.)
|
||||||
|
|
||||||
|
b) Accompany the work with a written offer, valid for at
|
||||||
|
least three years, to give the same user the materials
|
||||||
|
specified in Subsection 6a, above, for a charge no more
|
||||||
|
than the cost of performing this distribution.
|
||||||
|
|
||||||
|
c) If distribution of the work is made by offering access to copy
|
||||||
|
from a designated place, offer equivalent access to copy the above
|
||||||
|
specified materials from the same place.
|
||||||
|
|
||||||
|
d) Verify that the user has already received a copy of these
|
||||||
|
materials or that you have already sent this user a copy.
|
||||||
|
|
||||||
|
For an executable, the required form of the "work that uses the
|
||||||
|
Library" must include any data and utility programs needed for
|
||||||
|
reproducing the executable from it. However, as a special exception,
|
||||||
|
the source code distributed need not include anything that is normally
|
||||||
|
distributed (in either source or binary form) with the major
|
||||||
|
components (compiler, kernel, and so on) of the operating system on
|
||||||
|
which the executable runs, unless that component itself accompanies
|
||||||
|
the executable.
|
||||||
|
|
||||||
|
It may happen that this requirement contradicts the license
|
||||||
|
restrictions of other proprietary libraries that do not normally
|
||||||
|
accompany the operating system. Such a contradiction means you cannot
|
||||||
|
use both them and the Library together in an executable that you
|
||||||
|
distribute.
|
||||||
|
|
||||||
|
7. You may place library facilities that are a work based on the
|
||||||
|
Library side-by-side in a single library together with other library
|
||||||
|
facilities not covered by this License, and distribute such a combined
|
||||||
|
library, provided that the separate distribution of the work based on
|
||||||
|
the Library and of the other library facilities is otherwise
|
||||||
|
permitted, and provided that you do these two things:
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work
|
||||||
|
based on the Library, uncombined with any other library
|
||||||
|
facilities. This must be distributed under the terms of the
|
||||||
|
Sections above.
|
||||||
|
|
||||||
|
b) Give prominent notice with the combined library of the fact
|
||||||
|
that part of it is a work based on the Library, and explaining
|
||||||
|
where to find the accompanying uncombined form of the same work.
|
||||||
|
|
||||||
|
8. You may not copy, modify, sublicense, link with, or distribute
|
||||||
|
the Library except as expressly provided under this License. Any
|
||||||
|
attempt otherwise to copy, modify, sublicense, link with, or
|
||||||
|
distribute the Library is void, and will automatically terminate your
|
||||||
|
rights under this License. However, parties who have received copies,
|
||||||
|
or rights, from you under this License will not have their licenses
|
||||||
|
terminated so long as such parties remain in full compliance.
|
||||||
|
|
||||||
|
9. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Library or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Library (or any work based on the
|
||||||
|
Library), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Library or works based on it.
|
||||||
|
|
||||||
|
10. Each time you redistribute the Library (or any work based on the
|
||||||
|
Library), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute, link with or modify the Library
|
||||||
|
subject to these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties to
|
||||||
|
this License.
|
||||||
|
|
||||||
|
11. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Library at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Library by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Library.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under any
|
||||||
|
particular circumstance, the balance of the section is intended to apply,
|
||||||
|
and the section as a whole is intended to apply in other circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
12. If the distribution and/or use of the Library is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Library under this License may add
|
||||||
|
an explicit geographical distribution limitation excluding those countries,
|
||||||
|
so that distribution is permitted only in or among countries not thus
|
||||||
|
excluded. In such case, this License incorporates the limitation as if
|
||||||
|
written in the body of this License.
|
||||||
|
|
||||||
|
13. The Free Software Foundation may publish revised and/or new
|
||||||
|
versions of the Library General Public License from time to time.
|
||||||
|
Such new versions will be similar in spirit to the present version,
|
||||||
|
but may differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Library
|
||||||
|
specifies a version number of this License which applies to it and
|
||||||
|
"any later version", you have the option of following the terms and
|
||||||
|
conditions either of that version or of any later version published by
|
||||||
|
the Free Software Foundation. If the Library does not specify a
|
||||||
|
license version number, you may choose any version ever published by
|
||||||
|
the Free Software Foundation.
|
||||||
|
|
||||||
|
14. If you wish to incorporate parts of the Library into other free
|
||||||
|
programs whose distribution conditions are incompatible with these,
|
||||||
|
write to the author to ask for permission. For software which is
|
||||||
|
copyrighted by the Free Software Foundation, write to the Free
|
||||||
|
Software Foundation; we sometimes make exceptions for this. Our
|
||||||
|
decision will be guided by the two goals of preserving the free status
|
||||||
|
of all derivatives of our free software and of promoting the sharing
|
||||||
|
and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||||
|
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||||
|
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||||
|
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||||
|
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||||
|
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||||
|
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||||
|
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||||
|
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||||
|
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||||
|
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||||
|
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||||
|
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||||
|
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||||
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
33
assets/model/creature/pig/animation.json
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"walk": {
|
||||||
|
"speed": 6.0,
|
||||||
|
"amplitude": 25.0
|
||||||
|
},
|
||||||
|
"run": {
|
||||||
|
"speed": 12.0,
|
||||||
|
"amplitude": 40.0
|
||||||
|
},
|
||||||
|
"body_bob": 0.03,
|
||||||
|
"head": {
|
||||||
|
"node": "Head",
|
||||||
|
"amplitude": 4.0
|
||||||
|
},
|
||||||
|
"legs": [
|
||||||
|
{
|
||||||
|
"node": "Foot_FL",
|
||||||
|
"phase": 0.0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"node": "Foot_FR",
|
||||||
|
"phase": 3.14159
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"node": "Foot_HL",
|
||||||
|
"phase": 3.14159
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"node": "Foot_HR",
|
||||||
|
"phase": 0.0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
16
assets/model/creature/pig/collision.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"boxes": [
|
||||||
|
{
|
||||||
|
"center": [
|
||||||
|
0,
|
||||||
|
0.78,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"half": [
|
||||||
|
0.53,
|
||||||
|
0.78,
|
||||||
|
0.406
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
BIN
assets/model/creature/pig/pig.glb
Normal file
BIN
assets/model/creature/player/player.glb
Normal file
13
assets/shaders/depth_model_instance_vert.glsl
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#version 460
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 pos;
|
||||||
|
layout (location = 1) in vec2 texCoord;
|
||||||
|
layout (location = 3) in mat4 modelMatrix;
|
||||||
|
uniform mat4 lightSpaceMatrix;
|
||||||
|
|
||||||
|
out vec2 tc;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
tc = texCoord;
|
||||||
|
gl_Position = lightSpaceMatrix * modelMatrix * vec4(pos, 1.0);
|
||||||
|
}
|
||||||
@@ -7,7 +7,6 @@ uniform mat4 lightSpaceMatrix;
|
|||||||
uniform mat4 modelMatrix;
|
uniform mat4 modelMatrix;
|
||||||
|
|
||||||
out vec2 tc;
|
out vec2 tc;
|
||||||
flat out int tex_layer;
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
tc = texCoord;
|
tc = texCoord;
|
||||||
14
assets/shaders/depth_model_vert.glsl
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#version 460
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 pos;
|
||||||
|
layout (location = 1) in vec2 texCoord;
|
||||||
|
|
||||||
|
uniform mat4 lightSpaceMatrix;
|
||||||
|
uniform mat4 modelMatrix;
|
||||||
|
|
||||||
|
out vec2 tc;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
tc = texCoord;
|
||||||
|
gl_Position = lightSpaceMatrix * modelMatrix * vec4(pos, 1.0);
|
||||||
|
}
|
||||||
26
assets/shaders/model_instance_vert.glsl
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#version 460
|
||||||
|
|
||||||
|
layout (location = 0) in vec3 pos;
|
||||||
|
layout (location = 1) in vec2 texCoord;
|
||||||
|
layout (location = 2) in vec3 aNormal;
|
||||||
|
layout (location = 3) in mat4 modelMatrix;
|
||||||
|
uniform mat4 view_matrix;
|
||||||
|
uniform mat4 proj_matrix;
|
||||||
|
uniform mat4 lightSpaceMatrix;
|
||||||
|
out vec4 FragPosLightSpace;
|
||||||
|
out vec3 normal;
|
||||||
|
out vec2 tc;
|
||||||
|
out vec3 vert_pos;
|
||||||
|
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
vec4 worldPos = modelMatrix * vec4(pos, 1.0);
|
||||||
|
FragPosLightSpace = lightSpaceMatrix * worldPos;
|
||||||
|
mat4 mv_matrix= view_matrix * modelMatrix;
|
||||||
|
mat4 norm_matrix = transpose(inverse(mv_matrix));
|
||||||
|
vec4 viewPos = mv_matrix * vec4(pos, 1.0);
|
||||||
|
tc = texCoord;
|
||||||
|
vert_pos = pos;
|
||||||
|
normal = normalize(mat3(norm_matrix) * aNormal);
|
||||||
|
gl_Position = proj_matrix * viewPos;
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
layout (location = 0) in vec3 pos;
|
layout (location = 0) in vec3 pos;
|
||||||
layout (location = 1) in vec2 texCoord;
|
layout (location = 1) in vec2 texCoord;
|
||||||
layout (location = 2) in vec3 aNormal;
|
layout (location = 2) in vec3 aNormal;
|
||||||
layout (location = 3) in vec3 aTangent;
|
|
||||||
|
|
||||||
uniform mat4 mv_matrix;
|
uniform mat4 mv_matrix;
|
||||||
uniform mat4 proj_matrix;
|
uniform mat4 proj_matrix;
|
||||||
|
Before Width: | Height: | Size: 99 B After Width: | Height: | Size: 355 B |
|
Before Width: | Height: | Size: 882 B After Width: | Height: | Size: 231 KiB |
|
Before Width: | Height: | Size: 277 B After Width: | Height: | Size: 893 B |
|
Before Width: | Height: | Size: 499 B After Width: | Height: | Size: 239 KiB |
|
Before Width: | Height: | Size: 890 B After Width: | Height: | Size: 249 KiB |
|
Before Width: | Height: | Size: 874 B After Width: | Height: | Size: 223 KiB |
|
Before Width: | Height: | Size: 877 B After Width: | Height: | Size: 201 KiB |
|
Before Width: | Height: | Size: 914 B After Width: | Height: | Size: 215 KiB |
|
Before Width: | Height: | Size: 915 B After Width: | Height: | Size: 215 KiB |
|
Before Width: | Height: | Size: 874 B After Width: | Height: | Size: 215 KiB |
BIN
assets/texture/item/spawn_egg/pig_spawn_egg.png
Normal file
|
After Width: | Height: | Size: 174 B |
BIN
assets/texture/ui/microphone.png
Normal file
|
After Width: | Height: | Size: 137 B |
BIN
assets/texture/ui/slot.png
Normal file
|
After Width: | Height: | Size: 122 B |
@@ -8,49 +8,12 @@ find_package(zstd REQUIRED)
|
|||||||
find_package(OpenAL REQUIRED)
|
find_package(OpenAL REQUIRED)
|
||||||
find_package(harfbuzz REQUIRED)
|
find_package(harfbuzz REQUIRED)
|
||||||
find_package(Freetype REQUIRED)
|
find_package(Freetype REQUIRED)
|
||||||
if (UNIX AND NOT APPLE)
|
find_package(SDL3 REQUIRED)
|
||||||
find_package(glfw3 REQUIRED)
|
find_package(Opus REQUIRED)
|
||||||
endif()
|
find_package(assimp REQUIRED)
|
||||||
|
|
||||||
|
|
||||||
# Third-party libraries
|
# Third-party libraries
|
||||||
FetchContent_Declare(
|
|
||||||
glm
|
|
||||||
GIT_REPOSITORY https://github.com/g-truc/glm.git
|
|
||||||
GIT_TAG 1.0.3
|
|
||||||
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(glm)
|
|
||||||
FetchContent_Declare(
|
|
||||||
soil2
|
|
||||||
GIT_REPOSITORY https://github.com/SpartanJ/SOIL2.git
|
|
||||||
GIT_TAG 1.31
|
|
||||||
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(soil2)
|
|
||||||
FetchContent_Declare(
|
|
||||||
tomlplusplus
|
|
||||||
GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
|
|
||||||
GIT_TAG v3.4.0
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(tomlplusplus)
|
|
||||||
|
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
FetchContent_Declare(
|
|
||||||
glfw
|
|
||||||
GIT_REPOSITORY https://github.com/glfw/glfw.git
|
|
||||||
GIT_TAG 3.4
|
|
||||||
)
|
|
||||||
|
|
||||||
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
|
|
||||||
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
|
||||||
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
|
||||||
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
|
|
||||||
set(GLFW_VULKAN_STATIC ON CACHE BOOL "" FORCE)
|
|
||||||
set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
|
|
||||||
|
|
||||||
FetchContent_MakeAvailable(glfw)
|
|
||||||
|
|
||||||
set(_BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS})
|
set(_BUILD_SHARED_LIBS_SAVED ${BUILD_SHARED_LIBS})
|
||||||
set(BUILD_SHARED_LIBS ON)
|
set(BUILD_SHARED_LIBS ON)
|
||||||
|
|||||||
25
cmake/modules/FindOpus.cmake
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
|
find_path(OPUS_INCLUDE_DIR
|
||||||
|
NAMES opus/opus.h opus.h
|
||||||
|
)
|
||||||
|
|
||||||
|
find_library(OPUS_LIBRARY
|
||||||
|
NAMES opus
|
||||||
|
)
|
||||||
|
|
||||||
|
find_package_handle_standard_args(
|
||||||
|
Opus
|
||||||
|
REQUIRED_VARS
|
||||||
|
OPUS_INCLUDE_DIR
|
||||||
|
OPUS_LIBRARY
|
||||||
|
)
|
||||||
|
|
||||||
|
if(Opus_FOUND)
|
||||||
|
add_library(Opus::Opus UNKNOWN IMPORTED)
|
||||||
|
|
||||||
|
set_target_properties(Opus::Opus PROPERTIES
|
||||||
|
IMPORTED_LOCATION "${OPUS_LIBRARY}"
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${OPUS_INCLUDE_DIR}"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <glm/glm.hpp>
|
|
||||||
|
|
||||||
namespace Cubed {
|
|
||||||
|
|
||||||
struct AABB {
|
|
||||||
glm::vec3 min{0.0f, 0.0f, 0.0f};
|
|
||||||
glm::vec3 max{0.0f, 0.0f, 0.0f};
|
|
||||||
|
|
||||||
AABB(glm::vec3 min_point, glm::vec3 max_point)
|
|
||||||
: min(min_point), max(max_point) {}
|
|
||||||
|
|
||||||
bool intersects(const AABB& other) const {
|
|
||||||
return (min.x <= other.max.x && max.x >= other.min.x) &&
|
|
||||||
(min.y <= other.max.y && max.y >= other.min.y) &&
|
|
||||||
(min.z <= other.max.z && max.z >= other.min.z);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Cubed
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Cubed/audio/audio_engine.hpp"
|
|
||||||
#define GLFW_INCLUDE_NONE
|
|
||||||
#include "Cubed/argument.hpp"
|
#include "Cubed/argument.hpp"
|
||||||
|
#include "Cubed/audio/audio_engine.hpp"
|
||||||
#include "Cubed/config.hpp"
|
#include "Cubed/config.hpp"
|
||||||
#include "Cubed/dev_panel.hpp"
|
#include "Cubed/dev_panel.hpp"
|
||||||
#include "Cubed/render/renderer.hpp"
|
#include "Cubed/render/renderer.hpp"
|
||||||
@@ -14,21 +13,15 @@ class App {
|
|||||||
public:
|
public:
|
||||||
App();
|
App();
|
||||||
~App();
|
~App();
|
||||||
static void cursor_position_callback(GLFWwindow* window, double xpos,
|
void handle_mouse_move(float xpos, float ypos, float xrel, float yrel);
|
||||||
double ypos);
|
void handle_sdl_key(SDL_Event& e);
|
||||||
static void key_callback(GLFWwindow* window, int key, int scancode,
|
void handle_sdl_mouse_button(SDL_Event& e);
|
||||||
int action, int mods);
|
void handle_window_focus(bool focused);
|
||||||
static void mouse_button_callback(GLFWwindow* window, int button,
|
void handle_window_resize(int new_width, int new_height);
|
||||||
int action, int mods);
|
void handle_framebuffer_resize(int new_width, int new_height);
|
||||||
static void window_focus_callback(GLFWwindow* window, int focused);
|
void handle_mouse_scroll(float xoffset, float yoffset);
|
||||||
static void window_reshape_callback(GLFWwindow* window, int new_width,
|
void handle_text_input(const char* text);
|
||||||
int new_height);
|
|
||||||
static void framebuffer_size_callback(GLFWwindow* window, int new_width,
|
|
||||||
int new_height);
|
|
||||||
static void mouse_scroll_callback(GLFWwindow* window, double xoffset,
|
|
||||||
double yoffset);
|
|
||||||
static void cursor_enter_callback(GLFWwindow* window, int entered);
|
|
||||||
static void char_callback(GLFWwindow* window, unsigned int ch);
|
|
||||||
static int start_cubed_application(int argc, char** argv);
|
static int start_cubed_application(int argc, char** argv);
|
||||||
|
|
||||||
static unsigned int seed();
|
static unsigned int seed();
|
||||||
@@ -43,29 +36,34 @@ public:
|
|||||||
const Argument& argument() const;
|
const Argument& argument() const;
|
||||||
AudioEngine& audio();
|
AudioEngine& audio();
|
||||||
|
|
||||||
const char* get_clipboard_text();
|
std::string get_clipboard_text();
|
||||||
|
|
||||||
|
void start_text_input();
|
||||||
|
void stop_text_input();
|
||||||
|
void update_text_input_area(const glm::vec4& textbox,
|
||||||
|
float cursor_position_x);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Config m_game_config;
|
Config m_game_config;
|
||||||
|
|
||||||
TextureManager m_texture_manager;
|
Window m_window;
|
||||||
|
|
||||||
|
TextureManager m_texture_manager;
|
||||||
AudioEngine m_audio;
|
AudioEngine m_audio;
|
||||||
|
|
||||||
Renderer m_renderer;
|
Renderer m_renderer;
|
||||||
|
|
||||||
Window m_window;
|
|
||||||
|
|
||||||
SceneManager m_scene_manager;
|
SceneManager m_scene_manager;
|
||||||
|
|
||||||
inline static double last_time = glfwGetTime();
|
inline static uint64_t last_tick = 0;
|
||||||
inline static double current_time = glfwGetTime();
|
inline static uint64_t current_tick = 0;
|
||||||
inline static double dt = 0.0f;
|
inline static float dt = 0.0f;
|
||||||
inline static double fps_time_count = 0.0f;
|
inline static float fps_time_count = 0.0f;
|
||||||
inline static int frame_count = 0;
|
inline static int frame_count = 0;
|
||||||
inline static int fps = 0;
|
inline static int fps = 0;
|
||||||
Argument m_argument;
|
Argument m_argument;
|
||||||
|
bool m_running = true;
|
||||||
|
bool m_opengl_init = false;
|
||||||
void init(int argc, char** argv);
|
void init(int argc, char** argv);
|
||||||
void handle_argument(int argc, char** argv);
|
void handle_argument(int argc, char** argv);
|
||||||
auto init_camera();
|
auto init_camera();
|
||||||
@@ -76,6 +74,8 @@ private:
|
|||||||
void run();
|
void run();
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
void handle_sdl_event(SDL_Event& e);
|
||||||
|
|
||||||
void dispatch_event(const Event& e);
|
void dispatch_event(const Event& e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,13 @@ struct Argument {
|
|||||||
std::optional<int> port;
|
std::optional<int> port;
|
||||||
std::optional<std::string> ip;
|
std::optional<std::string> ip;
|
||||||
std::optional<std::string> player;
|
std::optional<std::string> player;
|
||||||
std::optional<bool> debug_on;
|
|
||||||
std::optional<std::string> language;
|
std::optional<std::string> language;
|
||||||
|
std::optional<std::string> video_driver;
|
||||||
|
std::optional<bool> enable_exclusive;
|
||||||
|
std::optional<std::string> logs_path;
|
||||||
|
std::optional<int> log_level;
|
||||||
|
std::optional<bool> enable_filelog;
|
||||||
|
std::optional<bool> enable_consolelog;
|
||||||
|
std::optional<bool> direct_enter;
|
||||||
};
|
};
|
||||||
} // namespace Cubed
|
} // namespace Cubed
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Cubed/audio/audio_fade.hpp"
|
#include "Cubed/audio/audio_fade.hpp"
|
||||||
|
#include "Cubed/audio/audio_recording.hpp"
|
||||||
#include "Cubed/audio/audio_source.hpp"
|
#include "Cubed/audio/audio_source.hpp"
|
||||||
|
#include "Cubed/audio/audio_stream_source.hpp"
|
||||||
#include "Cubed/audio/sound_manager.hpp"
|
#include "Cubed/audio/sound_manager.hpp"
|
||||||
#include "Cubed/audio/source_pool.hpp"
|
#include "Cubed/audio/source_pool.hpp"
|
||||||
#include "Cubed/config.hpp"
|
#include "Cubed/config.hpp"
|
||||||
@@ -10,13 +12,15 @@
|
|||||||
#include <AL/alc.h>
|
#include <AL/alc.h>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <opus/opus.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
|
|
||||||
class ClientWorld;
|
class NetworkClient;
|
||||||
|
|
||||||
class AudioEngine {
|
class AudioEngine {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AudioEngine(Config& config);
|
AudioEngine(Config& config);
|
||||||
AudioEngine(const AudioEngine&) = delete;
|
AudioEngine(const AudioEngine&) = delete;
|
||||||
@@ -41,11 +45,23 @@ public:
|
|||||||
|
|
||||||
float& bgm_target_volume();
|
float& bgm_target_volume();
|
||||||
|
|
||||||
|
void set_client(std::weak_ptr<NetworkClient> client);
|
||||||
|
|
||||||
|
void send_voice(const std::array<int16_t, AudioRecording::FRAME_SAMPLES>&);
|
||||||
|
void receive_voice(std::span<const char> opus, const glm::vec3& pos);
|
||||||
|
|
||||||
|
AudioRecording& audio_recording();
|
||||||
|
const AudioRecording& audio_recording() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using FadeMap = std::unordered_map<std::string, AudioFade>;
|
using FadeMap = std::unordered_map<std::string, AudioFade>;
|
||||||
bool m_init{false};
|
bool m_init{false};
|
||||||
ALCdevice* device{nullptr};
|
ALCdevice* device{nullptr};
|
||||||
ALCcontext* context{nullptr};
|
ALCcontext* context{nullptr};
|
||||||
|
OpusEncoder* m_encoder{nullptr};
|
||||||
|
OpusDecoder* m_decoder{nullptr};
|
||||||
|
AudioRecording m_recording;
|
||||||
|
std::weak_ptr<NetworkClient> m_client;
|
||||||
glm::vec3 listener_pos;
|
glm::vec3 listener_pos;
|
||||||
std::unique_ptr<AudioSource> m_bgm;
|
std::unique_ptr<AudioSource> m_bgm;
|
||||||
FadeMap m_fade_map;
|
FadeMap m_fade_map;
|
||||||
@@ -56,6 +72,9 @@ private:
|
|||||||
bool m_underwater = false;
|
bool m_underwater = false;
|
||||||
float m_music_volume = 1.0f;
|
float m_music_volume = 1.0f;
|
||||||
float m_sfx_volume = 1.0f;
|
float m_sfx_volume = 1.0f;
|
||||||
|
float m_player_voice_volume = 1.0f;
|
||||||
|
|
||||||
|
std::unique_ptr<AudioStreamSource> m_voice_source;
|
||||||
std::unique_ptr<AudioFilter> m_low_pass_filter;
|
std::unique_ptr<AudioFilter> m_low_pass_filter;
|
||||||
std::unique_ptr<AudioEffect> m_underwater_effect;
|
std::unique_ptr<AudioEffect> m_underwater_effect;
|
||||||
std::unique_ptr<AudioEffectSlot> m_underwater_slot;
|
std::unique_ptr<AudioEffectSlot> m_underwater_slot;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "Cubed/tools/log.hpp"
|
#include "Cubed/tools/log.hpp"
|
||||||
|
|
||||||
#include <AL/al.h>
|
#include <AL/al.h>
|
||||||
|
#include <source_location>
|
||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
inline void check_al_error(
|
inline void check_al_error(
|
||||||
std::source_location loaction = std::source_location::current()) {
|
std::source_location loaction = std::source_location::current()) {
|
||||||
|
|||||||
33
include/Cubed/audio/audio_recording.hpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <alc.h>
|
||||||
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
|
namespace Cubed {
|
||||||
|
class AudioEngine;
|
||||||
|
class AudioRecording {
|
||||||
|
public:
|
||||||
|
static constexpr int SAMPLE_RATE = 48000;
|
||||||
|
static constexpr int FRAME_MS = 20;
|
||||||
|
static constexpr int FRAME_SAMPLES = SAMPLE_RATE * FRAME_MS / 1000;
|
||||||
|
AudioRecording(AudioEngine& engine);
|
||||||
|
AudioRecording(const AudioRecording&) = delete;
|
||||||
|
AudioRecording(AudioRecording&&) = delete;
|
||||||
|
AudioRecording& operator=(const AudioRecording&) = delete;
|
||||||
|
AudioRecording& operator=(AudioRecording&&) = delete;
|
||||||
|
~AudioRecording();
|
||||||
|
|
||||||
|
void update();
|
||||||
|
|
||||||
|
void init();
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
|
bool is_recording() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
AudioEngine& m_engine;
|
||||||
|
ALCdevice* m_capture = nullptr;
|
||||||
|
bool m_recording = false;
|
||||||
|
void send_voice(const std::array<int16_t, FRAME_SAMPLES>& pcm);
|
||||||
|
};
|
||||||
|
} // namespace Cubed
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <AL/al.h>
|
#include <AL/al.h>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include <memory>
|
||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
|
|
||||||
enum class AudioState { INITIAL, PLAYING, PAUSED, STOPPED };
|
enum class AudioState { INITIAL, PLAYING, PAUSED, STOPPED };
|
||||||
@@ -21,8 +22,9 @@ public:
|
|||||||
void set_pitch(float pitch);
|
void set_pitch(float pitch);
|
||||||
void play();
|
void play();
|
||||||
void play_2d(const AudioBuffer& buffer);
|
void play_2d(const AudioBuffer& buffer);
|
||||||
|
void play_2d(std::unique_ptr<AudioBuffer> buffer);
|
||||||
void play_3d(const AudioBuffer& buffer, const glm::vec3& pos);
|
void play_3d(const AudioBuffer& buffer, const glm::vec3& pos);
|
||||||
|
void play_3d(std::unique_ptr<AudioBuffer> buffer, const glm::vec3& pos);
|
||||||
void stop();
|
void stop();
|
||||||
void pause();
|
void pause();
|
||||||
float duration() const;
|
float duration() const;
|
||||||
@@ -42,6 +44,8 @@ public:
|
|||||||
void clear_effect_slot();
|
void clear_effect_slot();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::unique_ptr<AudioBuffer> m_buffer;
|
||||||
|
|
||||||
ALuint m_source = 0;
|
ALuint m_source = 0;
|
||||||
float m_target_volume = 1.0f;
|
float m_target_volume = 1.0f;
|
||||||
float m_duration = 0.0f;
|
float m_duration = 0.0f;
|
||||||
|
|||||||
46
include/Cubed/audio/audio_stream_source.hpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Cubed/audio/audio_effect_slot.hpp"
|
||||||
|
#include "Cubed/audio/audio_filter.hpp"
|
||||||
|
#include "glm/ext/vector_float3.hpp"
|
||||||
|
|
||||||
|
#include <al.h>
|
||||||
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <span>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Cubed {
|
||||||
|
class AudioStreamSource {
|
||||||
|
public:
|
||||||
|
static constexpr int NUM_BUFFERS = 4;
|
||||||
|
AudioStreamSource();
|
||||||
|
AudioStreamSource(const AudioStreamSource&) = delete;
|
||||||
|
AudioStreamSource(AudioStreamSource&&) = delete;
|
||||||
|
AudioStreamSource& operator=(const AudioStreamSource&) = delete;
|
||||||
|
AudioStreamSource& operator=(AudioStreamSource&&) = delete;
|
||||||
|
~AudioStreamSource();
|
||||||
|
|
||||||
|
void push_pcm(std::span<const int16_t> pcm, ALsizei sample_rate);
|
||||||
|
|
||||||
|
void stop();
|
||||||
|
bool is_playing() const;
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
void set_volume(float volume);
|
||||||
|
void set_pitch(float pitch);
|
||||||
|
void set_pos(glm::vec3 pos);
|
||||||
|
void set_filter(const AudioFilter& filter);
|
||||||
|
void clear_filter();
|
||||||
|
void set_effect_slot(const AudioEffectSlot& slot);
|
||||||
|
void clear_effect_slot();
|
||||||
|
|
||||||
|
private:
|
||||||
|
ALuint m_source = 0;
|
||||||
|
std::array<ALuint, NUM_BUFFERS> m_buffers{};
|
||||||
|
std::vector<ALuint> m_free_buffers;
|
||||||
|
bool m_playing = false;
|
||||||
|
|
||||||
|
void unqueue_processed();
|
||||||
|
};
|
||||||
|
} // namespace Cubed
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
class SourcePool {
|
class SourcePool {
|
||||||
private:
|
private:
|
||||||
std::vector<AudioSource> m_sources;
|
std::vector<std::unique_ptr<AudioSource>> m_sources;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SourcePool(size_t size);
|
explicit SourcePool(size_t size);
|
||||||
@@ -15,9 +15,10 @@ public:
|
|||||||
SourcePool& operator=(SourcePool&&) = delete;
|
SourcePool& operator=(SourcePool&&) = delete;
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
[[nodiscard]]
|
||||||
AudioSource* acquire();
|
AudioSource* acquire();
|
||||||
|
|
||||||
std::vector<AudioSource>& sources();
|
std::vector<std::unique_ptr<AudioSource>>& sources();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Cubed
|
} // namespace Cubed
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Cubed/input/event.hpp"
|
#include "Cubed/input/event.hpp"
|
||||||
#define GLFW_INCLUDE_NONE
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
|
|
||||||
class ClientPlayer;
|
class LocalPlayer;
|
||||||
|
|
||||||
class Camera {
|
class Camera {
|
||||||
private:
|
private:
|
||||||
@@ -19,8 +18,7 @@ private:
|
|||||||
THIRD_PERSON_FRONT,
|
THIRD_PERSON_FRONT,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool m_firse_mouse = true;
|
LocalPlayer* m_player;
|
||||||
ClientPlayer* m_player;
|
|
||||||
float m_last_mouse_x, m_last_mouse_y;
|
float m_last_mouse_x, m_last_mouse_y;
|
||||||
glm::vec3 m_camera_pos;
|
glm::vec3 m_camera_pos;
|
||||||
bool m_under_water = false;
|
bool m_under_water = false;
|
||||||
@@ -37,10 +35,9 @@ public:
|
|||||||
|
|
||||||
void update_move_camera();
|
void update_move_camera();
|
||||||
|
|
||||||
void camera_init(ClientPlayer* player);
|
void camera_init(LocalPlayer* player);
|
||||||
void hot_reload();
|
void hot_reload();
|
||||||
void reset_camera();
|
void update_cursor_position_camera(float offset_x, float offset_y);
|
||||||
void update_cursor_position_camera(double xpos, double ypos);
|
|
||||||
|
|
||||||
const glm::mat4 get_camera_lookat() const;
|
const glm::mat4 get_camera_lookat() const;
|
||||||
const glm::vec3& get_camera_pos() const;
|
const glm::vec3& get_camera_pos() const;
|
||||||
@@ -50,6 +47,7 @@ public:
|
|||||||
void change_perspective();
|
void change_perspective();
|
||||||
bool is_first_person() const;
|
bool is_first_person() const;
|
||||||
bool handle_event(const Event& e);
|
bool handle_event(const Event& e);
|
||||||
|
LocalPlayer* player();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Cubed
|
} // namespace Cubed
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ public:
|
|||||||
|
|
||||||
template <TOML::TomlValueType T>
|
template <TOML::TomlValueType T>
|
||||||
T get(std::string_view key, T default_value) {
|
T get(std::string_view key, T default_value) {
|
||||||
|
if (!m_init) {
|
||||||
|
load_config();
|
||||||
|
}
|
||||||
if (auto* node = find_node(m_tbl, key)) {
|
if (auto* node = find_node(m_tbl, key)) {
|
||||||
if (auto value = node->value<T>())
|
if (auto value = node->value<T>())
|
||||||
return *value;
|
return *value;
|
||||||
@@ -30,6 +33,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <TOML::TomlValueType T> void set(std::string_view key, T&& value) {
|
template <TOML::TomlValueType T> void set(std::string_view key, T&& value) {
|
||||||
|
if (!m_init) {
|
||||||
|
load_config();
|
||||||
|
}
|
||||||
auto pos = key.rfind('.');
|
auto pos = key.rfind('.');
|
||||||
|
|
||||||
toml::table* table;
|
toml::table* table;
|
||||||
@@ -51,8 +57,17 @@ public:
|
|||||||
save_to_file();
|
save_to_file();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string get(std::string_view key, const char* default_value) {
|
||||||
|
return get(key, std::string(default_value));
|
||||||
|
}
|
||||||
|
|
||||||
|
void set(std::string_view key, const char* val) {
|
||||||
|
set(key, std::string(val));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
toml::table m_tbl;
|
toml::table m_tbl;
|
||||||
|
bool m_init = false;
|
||||||
const std::string CONGIF_PATH;
|
const std::string CONGIF_PATH;
|
||||||
const toml::node* find_node(const toml::table& root,
|
const toml::node* find_node(const toml::table& root,
|
||||||
std::string_view path) const;
|
std::string_view path) const;
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include "Cubed/ui/label.hpp"
|
#include "Cubed/ui/label.hpp"
|
||||||
#include "Cubed/ui/widget.hpp"
|
#include "Cubed/ui/widget.hpp"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
|
#include <memory>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
@@ -11,6 +13,7 @@ namespace Cubed {
|
|||||||
class DebugCollector {
|
class DebugCollector {
|
||||||
public:
|
public:
|
||||||
static DebugCollector& get();
|
static DebugCollector& get();
|
||||||
|
static void destory();
|
||||||
DebugCollector();
|
DebugCollector();
|
||||||
|
|
||||||
void report(const std::string& name, std::string_view content);
|
void report(const std::string& name, std::string_view content);
|
||||||
@@ -21,6 +24,14 @@ public:
|
|||||||
private:
|
private:
|
||||||
ColumnLayout m_widget;
|
ColumnLayout m_widget;
|
||||||
std::unordered_map<std::string, Label*> m_component;
|
std::unordered_map<std::string, Label*> m_component;
|
||||||
|
static std::unique_ptr<DebugCollector>& get_ptr();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
void d_rep(const std::string& key, std::format_string<Args...> fmt,
|
||||||
|
Args&&... args) {
|
||||||
|
std::string msg = std::vformat(fmt.get(), std::make_format_args(args...));
|
||||||
|
DebugCollector::get().report(key, msg);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Cubed
|
} // namespace Cubed
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
|
|
||||||
class WorldScene;
|
class WorldScene;
|
||||||
class ClientPlayer;
|
class LocalPlayer;
|
||||||
class App;
|
class App;
|
||||||
class DevPanel {
|
class DevPanel {
|
||||||
struct ConfigView {
|
struct ConfigView {
|
||||||
@@ -42,7 +42,7 @@ private:
|
|||||||
WorldScene& m_world_scene;
|
WorldScene& m_world_scene;
|
||||||
Config& m_config;
|
Config& m_config;
|
||||||
ConfigView m_config_view;
|
ConfigView m_config_view;
|
||||||
ClientPlayer* m_player;
|
LocalPlayer* m_player;
|
||||||
PlayerProfile m_player_profile;
|
PlayerProfile m_player_profile;
|
||||||
bool m_need_save_config = false;
|
bool m_need_save_config = false;
|
||||||
bool m_gen_thread_running = true;
|
bool m_gen_thread_running = true;
|
||||||
@@ -63,7 +63,7 @@ private:
|
|||||||
void show_server_world_table_bar();
|
void show_server_world_table_bar();
|
||||||
void show_client_world_table_bar();
|
void show_client_world_table_bar();
|
||||||
void show_player_tab_item();
|
void show_player_tab_item();
|
||||||
void show_items_tab_item();
|
// void show_items_tab_item();
|
||||||
void show_shader_tab_item();
|
void show_shader_tab_item();
|
||||||
|
|
||||||
void update_config_view();
|
void update_config_view();
|
||||||
|
|||||||
@@ -55,42 +55,14 @@ struct BlockData {
|
|||||||
bool is_blend = false;
|
bool is_blend = false;
|
||||||
bool is_transitional = false;
|
bool is_transitional = false;
|
||||||
float roughness = 1.0f;
|
float roughness = 1.0f;
|
||||||
BlockData(BlockType b_id, std::string_view b_name, bool liquid,
|
BlockData(std::string_view b_name, BlockType b_id, bool liquid,
|
||||||
bool passable, bool cross_plane, bool transparent, bool gas,
|
bool passable, bool cross_plane, bool transparent, bool gas,
|
||||||
bool discard, bool blend, bool transitional, float r)
|
bool discard, bool blend, bool transitional, float r)
|
||||||
: name(b_name), id(b_id), is_liquid(liquid), is_gas(gas),
|
: name(b_name), id(b_id), is_liquid(liquid), is_gas(gas),
|
||||||
is_passable(passable), is_cross_plane(cross_plane),
|
is_passable(passable), is_cross_plane(cross_plane),
|
||||||
is_transparent(transparent), is_discard(discard), is_blend(blend),
|
is_transparent(transparent), is_discard(discard), is_blend(blend),
|
||||||
is_transitional(transitional), roughness(r) {}
|
is_transitional(transitional), roughness(r) {}
|
||||||
};
|
BlockData() { name = ""; }
|
||||||
|
|
||||||
class BlockManager {
|
|
||||||
|
|
||||||
public:
|
|
||||||
static const std::vector<BlockData>& datas();
|
|
||||||
static void init();
|
|
||||||
static unsigned sums();
|
|
||||||
static unsigned cross_plane_sum();
|
|
||||||
static const std::string& name_form_id(BlockType id);
|
|
||||||
|
|
||||||
static bool is_gas(BlockType id);
|
|
||||||
static bool is_liquid(BlockType id);
|
|
||||||
|
|
||||||
static bool is_cross_plane(BlockType id);
|
|
||||||
static bool is_transparent(BlockType id);
|
|
||||||
static bool is_passable(BlockType id);
|
|
||||||
|
|
||||||
static bool is_discard(BlockType id);
|
|
||||||
static bool is_blend(BlockType id);
|
|
||||||
static bool is_transitional(BlockType id);
|
|
||||||
static float roughness(BlockType id);
|
|
||||||
static BlockType cross_plane_index(BlockType id);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static void set_up_cross_plane_map();
|
|
||||||
static inline std::vector<BlockData> m_datas;
|
|
||||||
static inline bool is_init = false;
|
|
||||||
static inline std::unordered_map<BlockType, BlockType> m_cross_plane_map;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Cubed
|
} // namespace Cubed
|
||||||
45
include/Cubed/gameplay/block_manager.hpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Cubed/gameplay/block.hpp"
|
||||||
|
|
||||||
|
#include <tbb/concurrent_hash_map.h>
|
||||||
|
namespace Cubed {
|
||||||
|
class BlockManager {
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void init();
|
||||||
|
static unsigned sums();
|
||||||
|
static unsigned cross_plane_sum();
|
||||||
|
static const std::string& name_form_id(BlockType id);
|
||||||
|
static bool is_gas(BlockType id);
|
||||||
|
static bool is_liquid(BlockType id);
|
||||||
|
|
||||||
|
static bool is_cross_plane(BlockType id);
|
||||||
|
static bool is_transparent(BlockType id);
|
||||||
|
static bool is_passable(BlockType id);
|
||||||
|
|
||||||
|
static bool is_discard(BlockType id);
|
||||||
|
static bool is_blend(BlockType id);
|
||||||
|
static bool is_transitional(BlockType id);
|
||||||
|
static float roughness(BlockType id);
|
||||||
|
static BlockType cross_plane_index(BlockType id);
|
||||||
|
|
||||||
|
static BlockType id_from_name(const std::string& name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
using BlockMap = tbb::concurrent_hash_map<BlockType, BlockData>;
|
||||||
|
using acc = BlockMap::accessor;
|
||||||
|
using cacc = BlockMap::const_accessor;
|
||||||
|
using IDMap = tbb::concurrent_hash_map<std::string, BlockType>;
|
||||||
|
using CrossPlaneMap = tbb::concurrent_hash_map<BlockType, BlockType>;
|
||||||
|
|
||||||
|
static inline const BlockData EMPTY;
|
||||||
|
|
||||||
|
static inline BlockMap m_datas;
|
||||||
|
static inline IDMap m_id_map;
|
||||||
|
static inline bool is_init = false;
|
||||||
|
static inline CrossPlaneMap m_cross_plane_map;
|
||||||
|
static void set_up_cross_plane_map(
|
||||||
|
const std::vector<std::pair<bool, BlockType>>& types);
|
||||||
|
};
|
||||||
|
} // namespace Cubed
|
||||||
15
include/Cubed/gameplay/chat_message.hpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Cubed/ui/color.hpp"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
namespace Cubed {
|
||||||
|
struct ChatMessage {
|
||||||
|
std::string player;
|
||||||
|
std::string text;
|
||||||
|
Color color;
|
||||||
|
bool system_msg = false;
|
||||||
|
uint64_t time = 0;
|
||||||
|
};
|
||||||
|
} // namespace Cubed
|
||||||
27
include/Cubed/gameplay/chunk.hpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Cubed/gameplay/chunk_pos.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <tuple>
|
||||||
|
namespace Cubed {
|
||||||
|
class Chunk {
|
||||||
|
public:
|
||||||
|
Chunk() = default;
|
||||||
|
Chunk(const Chunk&) = delete;
|
||||||
|
Chunk(Chunk&&) = delete;
|
||||||
|
Chunk& operator=(const Chunk&) = delete;
|
||||||
|
Chunk& operator=(Chunk&&) = delete;
|
||||||
|
virtual ~Chunk() = default;
|
||||||
|
static int index(int x, int y, int z);
|
||||||
|
static int index(const glm::vec3& pos);
|
||||||
|
static std::tuple<int, int, int> world_to_block(int world_x, int world_y,
|
||||||
|
int world_z, int chunk_x,
|
||||||
|
int chunk_z);
|
||||||
|
static std::tuple<int, int, int> world_to_block(const glm::ivec3& block_pos,
|
||||||
|
ChunkPos chunk_pos);
|
||||||
|
static std::tuple<int, int, int> block_to_world(int x, int y, int z,
|
||||||
|
int chunk_x, int chunk_z);
|
||||||
|
static std::tuple<int, int, int> block_to_world(const glm::ivec3& block_pos,
|
||||||
|
ChunkPos chunk_pos);
|
||||||
|
};
|
||||||
|
} // namespace Cubed
|
||||||
@@ -50,6 +50,8 @@ public:
|
|||||||
void generate_cave();
|
void generate_cave();
|
||||||
void generate_river();
|
void generate_river();
|
||||||
|
|
||||||
|
void spawn_creature();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static inline std::atomic<bool> is_init{false};
|
static inline std::atomic<bool> is_init{false};
|
||||||
static inline unsigned m_generator_seed{0};
|
static inline unsigned m_generator_seed{0};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "Cubed/constants.hpp"
|
#include "Cubed/constants.hpp"
|
||||||
#include "Cubed/gameplay/biome.hpp"
|
#include "Cubed/gameplay/biome.hpp"
|
||||||
#include "Cubed/gameplay/block.hpp"
|
#include "Cubed/gameplay/block.hpp"
|
||||||
|
#include "Cubed/gameplay/chunk.hpp"
|
||||||
#include "Cubed/gameplay/chunk_pos.hpp"
|
#include "Cubed/gameplay/chunk_pos.hpp"
|
||||||
#include "Cubed/gameplay/vertex_data.hpp"
|
#include "Cubed/gameplay/vertex_data.hpp"
|
||||||
#include "world/chunk_data.pb.h"
|
#include "world/chunk_data.pb.h"
|
||||||
@@ -26,7 +27,7 @@ struct ChunkRenderSnapshot {
|
|||||||
glm::vec3 center;
|
glm::vec3 center;
|
||||||
glm::vec3 half_extents;
|
glm::vec3 half_extents;
|
||||||
};
|
};
|
||||||
class ClientChunk {
|
class ClientChunk : public Chunk {
|
||||||
public:
|
public:
|
||||||
ClientChunk(ClientWorld& world);
|
ClientChunk(ClientWorld& world);
|
||||||
~ClientChunk();
|
~ClientChunk();
|
||||||
@@ -35,17 +36,6 @@ public:
|
|||||||
ClientChunk(ClientChunk&&) noexcept;
|
ClientChunk(ClientChunk&&) noexcept;
|
||||||
ClientChunk& operator=(ClientChunk&&) noexcept;
|
ClientChunk& operator=(ClientChunk&&) noexcept;
|
||||||
|
|
||||||
static int index(int x, int y, int z);
|
|
||||||
static int index(const glm::vec3& pos);
|
|
||||||
static std::tuple<int, int, int> world_to_block(int world_x, int world_y,
|
|
||||||
int world_z, int chunk_x,
|
|
||||||
int chunk_z);
|
|
||||||
static std::tuple<int, int, int> world_to_block(const glm::ivec3& block_pos,
|
|
||||||
ChunkPos chunk_pos);
|
|
||||||
static std::tuple<int, int, int> block_to_world(int x, int y, int z,
|
|
||||||
int chunk_x, int chunk_z);
|
|
||||||
static std::tuple<int, int, int> block_to_world(const glm::ivec3& block_pos,
|
|
||||||
ChunkPos chunk_pos);
|
|
||||||
BiomeType get_biome() const;
|
BiomeType get_biome() const;
|
||||||
ChunkPos get_chunk_pos() const;
|
ChunkPos get_chunk_pos() const;
|
||||||
const std::vector<BlockType>& get_chunk_blocks() const;
|
const std::vector<BlockType>& get_chunk_blocks() const;
|
||||||
|
|||||||
79
include/Cubed/gameplay/client_entity_manager.hpp
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Cubed/gameplay/ecs/entity.hpp"
|
||||||
|
#include "Cubed/gameplay/gait.hpp"
|
||||||
|
#include "glm/ext/vector_float3.hpp"
|
||||||
|
#include "world/entity.pb.h"
|
||||||
|
|
||||||
|
#include <entt/entt.hpp>
|
||||||
|
#include <tbb/concurrent_hash_map.h>
|
||||||
|
#include <tbb/concurrent_queue.h>
|
||||||
|
namespace Cubed {
|
||||||
|
class ClientWorld;
|
||||||
|
class ClientEntityManager {
|
||||||
|
public:
|
||||||
|
enum class Command { CREATE, DESTORY, UPDATE };
|
||||||
|
|
||||||
|
ClientEntityManager(ClientWorld& world);
|
||||||
|
void update(float dt);
|
||||||
|
void init();
|
||||||
|
|
||||||
|
void receive_entity_create(S2CEntityCreate& msg);
|
||||||
|
void receive_entity_destory(EntityID id);
|
||||||
|
void receive_entity_update(const S2CEntityUpdate& msg);
|
||||||
|
void receive_entity_update(S2CEntityUpdateBatch& msg);
|
||||||
|
void destory(EntityID id);
|
||||||
|
void create(std::string_view name, const glm::vec3& pos);
|
||||||
|
|
||||||
|
const entt::registry& get_registry() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct EntityCreateElement {
|
||||||
|
EntityID id;
|
||||||
|
std::string name;
|
||||||
|
glm::vec3 pos;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UpdateInfo {
|
||||||
|
EntityID id;
|
||||||
|
glm::vec3 pos;
|
||||||
|
glm::vec3 direction;
|
||||||
|
Gait gait;
|
||||||
|
};
|
||||||
|
|
||||||
|
using EntityMap = tbb::concurrent_hash_map<EntityID, entt::entity>;
|
||||||
|
using acc = EntityMap::accessor;
|
||||||
|
using cacc = EntityMap::const_accessor;
|
||||||
|
using CreateFunc = std::function<void(EntityID id)>;
|
||||||
|
using TaskElement = std::variant<EntityCreateElement, EntityID, UpdateInfo>;
|
||||||
|
using TaskPair = std::pair<Command, TaskElement>;
|
||||||
|
|
||||||
|
ClientWorld& m_world;
|
||||||
|
entt::registry m_registry;
|
||||||
|
EntityMap m_entities;
|
||||||
|
std::unordered_map<std::string_view, CreateFunc> m_factories;
|
||||||
|
tbb::concurrent_queue<TaskPair> m_tasks;
|
||||||
|
|
||||||
|
void handle_task(float dt);
|
||||||
|
void handle_entity_destory(EntityID id);
|
||||||
|
// not thread safe
|
||||||
|
void handle_entity_create(EntityID id, std::string_view name,
|
||||||
|
const glm::vec3& pos);
|
||||||
|
void handle_entity_update(UpdateInfo& info, float dt);
|
||||||
|
template <typename... Args>
|
||||||
|
void create_entity_in_registry(EntityID id, Args&&... args) {
|
||||||
|
{
|
||||||
|
cacc a;
|
||||||
|
if (m_entities.find(a, id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto entity = m_registry.create();
|
||||||
|
|
||||||
|
((m_registry.emplace<std::remove_cvref_t<Args>>(
|
||||||
|
entity, std::forward<Args>(args))),
|
||||||
|
...);
|
||||||
|
m_entities.emplace(id, entity);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace Cubed
|
||||||
@@ -1,161 +1,24 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Cubed/AABB.hpp"
|
|
||||||
#include "Cubed/constants.hpp"
|
|
||||||
#include "Cubed/gameplay/block.hpp"
|
|
||||||
#include "Cubed/gameplay/chunk_pos.hpp"
|
|
||||||
#include "Cubed/gameplay/game_mode.hpp"
|
|
||||||
#include "Cubed/gameplay/game_time.hpp"
|
|
||||||
#include "Cubed/gameplay/player.hpp"
|
|
||||||
#include "Cubed/input/event.hpp"
|
|
||||||
#include "Cubed/input/input.hpp"
|
|
||||||
|
|
||||||
#include <absl/container/flat_hash_set.h>
|
#include "Cubed/gameplay/ecs/animation.hpp"
|
||||||
#include <glm/glm.hpp>
|
#include "Cubed/gameplay/ecs/identity.hpp"
|
||||||
#include <optional>
|
#include "Cubed/gameplay/ecs/transform.hpp"
|
||||||
#include <shared_mutex>
|
|
||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
|
|
||||||
class ClientWorld;
|
struct ClientPlayer {
|
||||||
class ClientPlayer {
|
Position pos{};
|
||||||
public:
|
Position render_pos{};
|
||||||
static constexpr float WALK_SOUND_INTERVAL = 0.45f;
|
EntityInfo entity{};
|
||||||
static constexpr float RUN_SOUND_INTERVAL = 0.3f;
|
WalkPose walk{};
|
||||||
using ChunkPosSet = absl::flat_hash_set<ChunkPos, ChunkPos::Hash>;
|
Orientation angle{};
|
||||||
ClientPlayer(ClientWorld& world);
|
Orientation render_angle{};
|
||||||
~ClientPlayer();
|
|
||||||
|
|
||||||
bool handle_mouse_button_event(const MouseButtonEvent& e);
|
|
||||||
bool handle_key_event(const KeyEvent& e);
|
|
||||||
bool handle_mouse_wheel_event(const MouseWheelEvent& e);
|
|
||||||
|
|
||||||
void update_front_vec(float offset_x, float offset_y);
|
|
||||||
bool update_player_move_state(Key key, KeyAction action);
|
|
||||||
bool update_scroll(float yoffset);
|
|
||||||
|
|
||||||
void update_chunk_set(const ChunkPosSet& set);
|
|
||||||
const ChunkPosSet& get_chunk_pos_set() const;
|
|
||||||
ChunkPosSet get_chunk_pos_set();
|
|
||||||
|
|
||||||
static AABB get_aabb(const glm::vec3& pos);
|
|
||||||
const glm::vec3& get_front() const;
|
|
||||||
Gait get_gait() const;
|
|
||||||
const std::optional<LookBlock>& get_look_block_pos() const;
|
|
||||||
// thread safe
|
|
||||||
glm::vec3 get_player_pos() const;
|
|
||||||
const MoveState& get_move_state() const;
|
|
||||||
|
|
||||||
void change_mode(GameMode mode);
|
|
||||||
void reload_config();
|
|
||||||
void set_player_pos(const glm::vec3& pos);
|
|
||||||
void set_place_block(unsigned id);
|
|
||||||
void update(float delta_time);
|
|
||||||
|
|
||||||
float& max_walk_speed();
|
|
||||||
float& max_run_speed();
|
|
||||||
float& max_speed();
|
|
||||||
float& acceleration();
|
|
||||||
float& deceleration();
|
|
||||||
float& g();
|
|
||||||
float& fly_y_speed();
|
|
||||||
|
|
||||||
unsigned get_current_block() const;
|
|
||||||
|
|
||||||
void set_gait(Gait gait);
|
|
||||||
GameMode& game_mode();
|
|
||||||
|
|
||||||
ClientWorld& get_world();
|
|
||||||
|
|
||||||
void set_uuid(std::string_view uuid);
|
|
||||||
std::string get_uuid() const;
|
|
||||||
const std::string& get_name() const;
|
|
||||||
void reset_key_status();
|
|
||||||
void init(std::string_view name);
|
|
||||||
|
|
||||||
float yaw() const;
|
|
||||||
float pitch() const;
|
|
||||||
float& angle();
|
|
||||||
float& walk_time();
|
|
||||||
bool ray_cast(const glm::vec3& start, const glm::vec3& dir,
|
|
||||||
glm::ivec3& block_pos, glm::vec3& normal,
|
|
||||||
float distance = 4.0f);
|
|
||||||
bool is_underwater() const;
|
|
||||||
void set_underwater(bool u);
|
|
||||||
void place_block(float dt);
|
|
||||||
|
|
||||||
private:
|
|
||||||
using enum GameMode;
|
|
||||||
float m_max_walk_speed = DEFAULT_MAX_WALK_SPEED;
|
|
||||||
float m_max_run_speed = DEFAULT_MAX_RUN_SPEED;
|
|
||||||
float m_acceleration = DEFAULT_ACCELERATION;
|
|
||||||
float m_deceleration = DEFAULT_DECELERATION;
|
|
||||||
float m_g = DEFAULT_G;
|
|
||||||
constexpr static float MAX_SPACE_ON_TIME = 0.3f;
|
|
||||||
constexpr static float PLACE_BLOCK_INTERVAL = 0.2f;
|
|
||||||
float m_place_time = PLACE_BLOCK_INTERVAL;
|
|
||||||
std::atomic<float> m_yaw = 0.0f;
|
|
||||||
std::atomic<float> m_pitch = 0.0f;
|
|
||||||
|
|
||||||
float m_sensitivity = 0.15f;
|
|
||||||
|
|
||||||
float m_max_speed = m_max_walk_speed;
|
|
||||||
float m_y_speed = 0.0f;
|
|
||||||
float m_fly_y_speed = 7.5f;
|
|
||||||
bool can_up = true;
|
|
||||||
|
|
||||||
float space_on_time = 0.0f;
|
|
||||||
bool space_on = false;
|
|
||||||
bool is_fly = false;
|
|
||||||
|
|
||||||
float m_xz_speed = 0.0f;
|
|
||||||
|
|
||||||
unsigned m_place_block = 1;
|
|
||||||
|
|
||||||
bool m_moving = false;
|
|
||||||
bool m_sprinting = false;
|
|
||||||
bool m_underwater = false;
|
|
||||||
|
|
||||||
glm::vec3 direction = glm::vec3(0.0f, 0.0f, 0.0f);
|
|
||||||
glm::vec3 move_distance{0.0f, 0.0f, 0.0f};
|
|
||||||
// player is tow block tall, the pos is the lower pos
|
|
||||||
|
|
||||||
glm::vec3 m_player_pos{0.0f, 255.0f, 0.0f};
|
|
||||||
ChunkPos m_last_chunk_pos{0, 0};
|
|
||||||
|
|
||||||
glm::vec3 m_front{0, 0, -1};
|
|
||||||
glm::vec3 m_right{0, 0, 0};
|
|
||||||
static constexpr glm::vec3 M_SIZE{0.6f, 1.8f, 0.6f};
|
|
||||||
|
|
||||||
std::atomic<Gait> m_gait = Gait::STOP;
|
|
||||||
MoveState m_move_state{};
|
|
||||||
MouseState m_mouse_state{};
|
|
||||||
GameMode m_game_mode = CREATIVE;
|
|
||||||
std::optional<LookBlock> m_look_block = std::nullopt;
|
|
||||||
std::string m_name{};
|
|
||||||
mutable std::shared_mutex m_uuid_mutex;
|
|
||||||
std::string m_uuid;
|
|
||||||
ClientWorld& m_world;
|
|
||||||
|
|
||||||
float m_angle{0.0f};
|
|
||||||
float m_walk_time{0.0f};
|
|
||||||
|
|
||||||
std::unordered_map<std::string, Timer> m_timers;
|
|
||||||
|
|
||||||
mutable std::shared_mutex m_player_pos_mutex;
|
|
||||||
mutable std::shared_mutex m_chunk_pos_mutex;
|
|
||||||
ChunkPosSet m_player_chunk_pos_set;
|
|
||||||
|
|
||||||
void update_direction();
|
|
||||||
void update_lookup_block();
|
|
||||||
|
|
||||||
void update_move(float delta_time);
|
|
||||||
|
|
||||||
void update_x_move(glm::vec3& player_pos);
|
|
||||||
void update_y_move(glm::vec3& player_pos);
|
|
||||||
void update_z_move(glm::vec3& player_pos);
|
|
||||||
|
|
||||||
void update_player_chunk();
|
|
||||||
|
|
||||||
void play_walk_sound(float dt);
|
|
||||||
Gait compute_gait() const;
|
|
||||||
};
|
};
|
||||||
} // namespace Cubed
|
|
||||||
|
struct PlayerRenderData {
|
||||||
|
EntityInfo info{};
|
||||||
|
Position render_pos{};
|
||||||
|
Orientation angle{};
|
||||||
|
Gait gait{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Cubed
|
||||||
45
include/Cubed/gameplay/client_player_manager.hpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Cubed/gameplay/client_player.hpp"
|
||||||
|
#include "Cubed/gameplay/local_player.hpp"
|
||||||
|
#include "Cubed/gameplay/network_client.hpp"
|
||||||
|
#include "Cubed/tools/sparse_vector.hpp"
|
||||||
|
namespace Cubed {
|
||||||
|
class ClientWorld;
|
||||||
|
class ClientPlayerManager {
|
||||||
|
public:
|
||||||
|
ClientPlayerManager(const ClientPlayerManager&) = delete;
|
||||||
|
ClientPlayerManager(ClientPlayerManager&&) = delete;
|
||||||
|
ClientPlayerManager& operator=(const ClientPlayerManager&) = delete;
|
||||||
|
ClientPlayerManager& operator=(ClientPlayerManager&&) = delete;
|
||||||
|
ClientPlayerManager(ClientWorld& world);
|
||||||
|
~ClientPlayerManager();
|
||||||
|
|
||||||
|
void init(std::string_view local_name);
|
||||||
|
void update(float dt);
|
||||||
|
|
||||||
|
std::span<PlayerRenderData> render_player_data();
|
||||||
|
|
||||||
|
bool has_player(const Hitbox& hitbox) const;
|
||||||
|
|
||||||
|
LocalPlayer& get_local();
|
||||||
|
const LocalPlayer& get_local() const;
|
||||||
|
|
||||||
|
void receive_remote_player(const PlayerInfoRsp& rsp);
|
||||||
|
void receive_player_logout(const LogoutRsp& rsp);
|
||||||
|
|
||||||
|
void reload_config();
|
||||||
|
|
||||||
|
void report_player_info(NetworkClient* client);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ClientWorld& m_world;
|
||||||
|
mutable std::shared_mutex m_players_mutex;
|
||||||
|
using PlayerHandle = SparseVector<ClientPlayer>::Handle;
|
||||||
|
SparseVector<ClientPlayer> m_players;
|
||||||
|
std::vector<PlayerRenderData> m_render_data;
|
||||||
|
std::unordered_map<std::string, PlayerHandle> m_players_handle;
|
||||||
|
LocalPlayer m_local;
|
||||||
|
|
||||||
|
void update_players_data(float dt);
|
||||||
|
};
|
||||||
|
} // namespace Cubed
|
||||||
@@ -2,11 +2,15 @@
|
|||||||
#include "Cubed/audio/audio_engine.hpp"
|
#include "Cubed/audio/audio_engine.hpp"
|
||||||
#include "Cubed/config.hpp"
|
#include "Cubed/config.hpp"
|
||||||
#include "Cubed/gameplay/block.hpp"
|
#include "Cubed/gameplay/block.hpp"
|
||||||
|
#include "Cubed/gameplay/chat_message.hpp"
|
||||||
#include "Cubed/gameplay/chunk_pos.hpp"
|
#include "Cubed/gameplay/chunk_pos.hpp"
|
||||||
#include "Cubed/gameplay/client_chunk.hpp"
|
#include "Cubed/gameplay/client_chunk.hpp"
|
||||||
#include "Cubed/gameplay/client_player.hpp"
|
#include "Cubed/gameplay/client_entity_manager.hpp"
|
||||||
|
#include "Cubed/gameplay/client_player_manager.hpp"
|
||||||
#include "Cubed/gameplay/game_time.hpp"
|
#include "Cubed/gameplay/game_time.hpp"
|
||||||
|
#include "Cubed/gameplay/local_player.hpp"
|
||||||
#include "Cubed/gameplay/network_client.hpp"
|
#include "Cubed/gameplay/network_client.hpp"
|
||||||
|
#include "Cubed/gameplay/world.hpp"
|
||||||
#include "Cubed/input/event.hpp"
|
#include "Cubed/input/event.hpp"
|
||||||
#include "Cubed/tools/cubed_random.hpp"
|
#include "Cubed/tools/cubed_random.hpp"
|
||||||
#include "Cubed/tools/priority_thread_pool.hpp"
|
#include "Cubed/tools/priority_thread_pool.hpp"
|
||||||
@@ -18,46 +22,26 @@
|
|||||||
#include <tbb/concurrent_unordered_map.h>
|
#include <tbb/concurrent_unordered_map.h>
|
||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
|
|
||||||
struct PlayerInfo {
|
|
||||||
std::string name;
|
|
||||||
std::string uuid;
|
|
||||||
glm::vec3 render_pos;
|
|
||||||
glm::vec3 target_pos;
|
|
||||||
float render_yaw;
|
|
||||||
float yaw;
|
|
||||||
float render_pitch;
|
|
||||||
float pitch;
|
|
||||||
Gait gait;
|
|
||||||
float angle = 0.0f;
|
|
||||||
float walk_time = 0.0f;
|
|
||||||
float moving_time = 0.0f;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PlayerRenderData {
|
|
||||||
std::string name;
|
|
||||||
std::string uuid;
|
|
||||||
glm::vec3 render_pos;
|
|
||||||
float yaw;
|
|
||||||
float pitch;
|
|
||||||
Gait gait;
|
|
||||||
float angle;
|
|
||||||
};
|
|
||||||
class WorldScene;
|
class WorldScene;
|
||||||
class ClientWorld {
|
class ClientWorld : public World {
|
||||||
public:
|
public:
|
||||||
|
ClientWorld(const ClientWorld&) = delete;
|
||||||
|
ClientWorld(ClientWorld&&) = delete;
|
||||||
|
ClientWorld& operator=(const ClientWorld&) = delete;
|
||||||
|
ClientWorld& operator=(ClientWorld&&) = delete;
|
||||||
ClientWorld(AudioEngine& auido, Config& config, WorldScene& scene);
|
ClientWorld(AudioEngine& auido, Config& config, WorldScene& scene);
|
||||||
~ClientWorld();
|
~ClientWorld();
|
||||||
void init(std::string_view player_name,
|
void init(std::string_view player_name,
|
||||||
std::shared_ptr<NetworkClient> client);
|
std::shared_ptr<NetworkClient> client, RunMode mode);
|
||||||
void update(float delta_time);
|
void update(float dt);
|
||||||
bool handle_event(const Event& e);
|
bool handle_event(const Event& e);
|
||||||
const std::optional<LookBlock>& get_look_block_pos() const;
|
const std::optional<LookBlock>& get_look_block_pos() const;
|
||||||
ClientPlayer& get_player();
|
LocalPlayer& get_player();
|
||||||
const ClientPlayer& get_player() const;
|
const LocalPlayer& get_player() const;
|
||||||
int get_block(const glm::ivec3& block_pos) const;
|
int get_block(const glm::ivec3& block_pos) const override;
|
||||||
bool is_solid(const glm::ivec3& block_pos) const;
|
bool is_solid(const glm::ivec3& block_pos) const override;
|
||||||
bool can_pass_block(const glm::ivec3& block_pos) const;
|
bool can_pass_block(const glm::ivec3& block_pos) const override;
|
||||||
BlockType get_block_tpye(const glm::ivec3& block_pos) const;
|
BlockType get_block_tpye(const glm::ivec3& block_pos) const override;
|
||||||
|
|
||||||
void rebuild_world();
|
void rebuild_world();
|
||||||
|
|
||||||
@@ -70,7 +54,6 @@ public:
|
|||||||
void receive_block_change(const BlockChangeRsp& rsp);
|
void receive_block_change(const BlockChangeRsp& rsp);
|
||||||
void receive_time(const UpdateTime& rsp);
|
void receive_time(const UpdateTime& rsp);
|
||||||
|
|
||||||
void receive_remote_player(const PlayerInfoRsp& rsp);
|
|
||||||
void receive_player_logout(const LogoutRsp& rsp);
|
void receive_player_logout(const LogoutRsp& rsp);
|
||||||
void receive_player_water_sound(const PlayerWaterSound& rsp);
|
void receive_player_water_sound(const PlayerWaterSound& rsp);
|
||||||
void send_player_water_sound(bool underwater, const glm::vec3& pos);
|
void send_player_water_sound(bool underwater, const glm::vec3& pos);
|
||||||
@@ -78,6 +61,7 @@ public:
|
|||||||
void rendering_distance(int rendering_distance);
|
void rendering_distance(int rendering_distance);
|
||||||
int get_chunk_task_id() const;
|
int get_chunk_task_id() const;
|
||||||
void start_client_thread(std::string_view uuid);
|
void start_client_thread(std::string_view uuid);
|
||||||
|
void receive_login_rsp(LoginRsp& rsp);
|
||||||
void stop_client_thread();
|
void stop_client_thread();
|
||||||
|
|
||||||
void start_thread_pool();
|
void start_thread_pool();
|
||||||
@@ -88,8 +72,6 @@ public:
|
|||||||
void reset_key_status();
|
void reset_key_status();
|
||||||
std::vector<glm::vec4>& planes();
|
std::vector<glm::vec4>& planes();
|
||||||
const std::vector<const ChunkRenderSnapshot*>& render_snapshots() const;
|
const std::vector<const ChunkRenderSnapshot*>& render_snapshots() const;
|
||||||
const std::vector<PlayerRenderData>& render_player_data() const;
|
|
||||||
std::vector<PlayerRenderData>& render_player_data();
|
|
||||||
|
|
||||||
glm::vec3 sunlight_dir() const;
|
glm::vec3 sunlight_dir() const;
|
||||||
bool sphere_collide_world(glm::vec3 center, float radius) const;
|
bool sphere_collide_world(glm::vec3 center, float radius) const;
|
||||||
@@ -97,18 +79,37 @@ public:
|
|||||||
void request_exit();
|
void request_exit();
|
||||||
bool is_receive_exit();
|
bool is_receive_exit();
|
||||||
int chunk_size() const;
|
int chunk_size() const;
|
||||||
static AABB get_block_aabb(const glm::ivec3& pos);
|
|
||||||
AudioEngine& get_audio();
|
AudioEngine& get_audio();
|
||||||
|
const AudioEngine& get_audio() const;
|
||||||
Config& get_config();
|
Config& get_config();
|
||||||
WorldScene& world_scene();
|
WorldScene& world_scene();
|
||||||
|
ClientPlayerManager& player_manager();
|
||||||
|
ClientEntityManager& entity_manager();
|
||||||
|
std::shared_ptr<NetworkClient> get_client() const;
|
||||||
|
void set_direct_exit();
|
||||||
|
|
||||||
|
void receive_chat_message(ChatMsg& msg);
|
||||||
|
void send_chat_message(ChatMessage& message);
|
||||||
|
void receive_voice_message(VoiceMsg& msg);
|
||||||
|
bool enable_voice_chat() const;
|
||||||
|
int get_per_tick_time() const override;
|
||||||
|
|
||||||
|
bool is_render(const glm::vec3& pos) const;
|
||||||
|
|
||||||
template <typename Fn>
|
template <typename Fn>
|
||||||
void register_ticktimer(std::string_view id, TickType threshold, Fn&& f) {
|
void register_timer(std::string_view id, float threshold, Fn&& f) {
|
||||||
m_ticktimers.emplace(
|
m_timers.emplace(std::piecewise_construct,
|
||||||
std::piecewise_construct, std::forward_as_tuple(std::string(id)),
|
std::forward_as_tuple(std::string(id)),
|
||||||
std::forward_as_tuple(threshold, std::forward<Fn>(f)));
|
std::forward_as_tuple(threshold, std::forward<Fn>(f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct VoiceMessage {
|
||||||
|
std::string data;
|
||||||
|
glm::vec3 pos;
|
||||||
|
};
|
||||||
|
|
||||||
std::atomic<bool> m_is_pending_delete_queue_free{false};
|
std::atomic<bool> m_is_pending_delete_queue_free{false};
|
||||||
std::mutex m_delete_vbo_mutex;
|
std::mutex m_delete_vbo_mutex;
|
||||||
std::mutex m_delete_vao_mutex;
|
std::mutex m_delete_vao_mutex;
|
||||||
@@ -121,7 +122,6 @@ private:
|
|||||||
ChunkPos::TBBHash>;
|
ChunkPos::TBBHash>;
|
||||||
using ChunkPosSet = absl::flat_hash_set<ChunkPos, ChunkPos::Hash>;
|
using ChunkPosSet = absl::flat_hash_set<ChunkPos, ChunkPos::Hash>;
|
||||||
using ChunkPosVector = std::vector<ChunkPos>;
|
using ChunkPosVector = std::vector<ChunkPos>;
|
||||||
using OtherPlayerHashMap = std::unordered_map<std::string, PlayerInfo>;
|
|
||||||
using chunk_acc = ChunkHashMap::accessor;
|
using chunk_acc = ChunkHashMap::accessor;
|
||||||
using chunk_cacc = ChunkHashMap::const_accessor;
|
using chunk_cacc = ChunkHashMap::const_accessor;
|
||||||
|
|
||||||
@@ -132,36 +132,36 @@ private:
|
|||||||
|
|
||||||
static constexpr int WORLD_EXIT_TIMEOUT = 200;
|
static constexpr int WORLD_EXIT_TIMEOUT = 200;
|
||||||
static constexpr int MAX_UPLOAD_CHUNK_SUM = 16;
|
static constexpr int MAX_UPLOAD_CHUNK_SUM = 16;
|
||||||
ClientPlayer m_player;
|
std::atomic<RunMode> m_runmode = RunMode::HYBRID;
|
||||||
OtherPlayerHashMap m_player_info;
|
ClientEntityManager m_entity_manager;
|
||||||
|
ClientPlayerManager m_player_manager;
|
||||||
ChunkHashMap m_chunks;
|
ChunkHashMap m_chunks;
|
||||||
AudioEngine& m_audio;
|
AudioEngine& m_audio;
|
||||||
Config& m_config;
|
Config& m_config;
|
||||||
WorldScene& m_world_scene;
|
WorldScene& m_world_scene;
|
||||||
std::vector<glm::vec4> m_planes;
|
std::vector<glm::vec4> m_planes;
|
||||||
std::jthread m_client_thread;
|
|
||||||
|
|
||||||
mutable std::shared_mutex m_player_info_mutex;
|
|
||||||
|
|
||||||
tbb::concurrent_queue<std::unique_ptr<ClientChunk>> m_pending_upload_queue;
|
tbb::concurrent_queue<std::unique_ptr<ClientChunk>> m_pending_upload_queue;
|
||||||
tbb::concurrent_queue<ChunkPos> m_dirty_chunk_queue;
|
tbb::concurrent_queue<ChunkPos> m_dirty_chunk_queue;
|
||||||
tbb::concurrent_queue<PendingSound> m_pending_sound;
|
tbb::concurrent_queue<PendingSound> m_pending_sound;
|
||||||
|
tbb::concurrent_queue<ChatMessage> m_message_queue;
|
||||||
|
tbb::concurrent_queue<VoiceMessage> m_voice_queue;
|
||||||
|
|
||||||
std::deque<ChunkPos> m_dirty_queue;
|
std::deque<ChunkPos> m_dirty_queue;
|
||||||
std::vector<const ChunkRenderSnapshot*> m_render_snapshots;
|
std::vector<const ChunkRenderSnapshot*> m_render_snapshots;
|
||||||
std::vector<PlayerRenderData> m_render_player_data;
|
|
||||||
|
|
||||||
tbb::concurrent_unordered_map<std::string, TickTimer> m_ticktimers;
|
|
||||||
std::unordered_map<std::string, Timer> m_timers;
|
std::unordered_map<std::string, Timer> m_timers;
|
||||||
|
std::atomic<bool> m_exit_direct{false};
|
||||||
std::atomic<bool> m_game_running{false};
|
std::atomic<bool> m_game_running{false};
|
||||||
std::atomic<bool> m_receive_exit{false};
|
std::atomic<bool> m_receive_exit{false};
|
||||||
std::atomic<int> m_rendering_distance{24};
|
std::atomic<int> m_rendering_distance{24};
|
||||||
std::atomic<TickType> m_game_ticks{0};
|
std::atomic<TickType> m_game_ticks{0};
|
||||||
std::atomic<TickType> m_day_tick{6000};
|
std::atomic<TickType> m_day_tick{6000};
|
||||||
|
std::atomic<int> m_per_tick_time = DEFAULT_PER_TICK_TIME;
|
||||||
std::atomic<bool> m_requesting_chunk{false};
|
std::atomic<bool> m_requesting_chunk{false};
|
||||||
std::atomic<bool> m_is_rebuilding{false};
|
std::atomic<bool> m_is_rebuilding{false};
|
||||||
std::atomic<int> m_chunk_task_id{0};
|
std::atomic<int> m_chunk_task_id{0};
|
||||||
|
std::atomic<bool> m_voice_chat{true};
|
||||||
std::shared_ptr<NetworkClient> m_client;
|
std::shared_ptr<NetworkClient> m_client;
|
||||||
ChunkLoadStyle m_chunk_load_style{ChunkLoadStyle::CENTER};
|
ChunkLoadStyle m_chunk_load_style{ChunkLoadStyle::CENTER};
|
||||||
|
|
||||||
@@ -169,10 +169,6 @@ private:
|
|||||||
|
|
||||||
Random m_random;
|
Random m_random;
|
||||||
|
|
||||||
void client_run(std::stop_token token);
|
|
||||||
|
|
||||||
void report_player_info();
|
|
||||||
|
|
||||||
void set_block(const glm::ivec3& pos, unsigned id);
|
void set_block(const glm::ivec3& pos, unsigned id);
|
||||||
|
|
||||||
void update_chunk(const ChunkPosSet& old, const ChunkPosSet& now);
|
void update_chunk(const ChunkPosSet& old, const ChunkPosSet& now);
|
||||||
|
|||||||
13
include/Cubed/gameplay/creatures/pig.hpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Cubed {
|
||||||
|
struct PigTag {};
|
||||||
|
|
||||||
|
namespace PigDefaults {
|
||||||
|
constexpr float MAX_SPEED = 0.1f; // tiles/tick → 2 tiles/sec
|
||||||
|
constexpr float ACCELERATION = 0.01f; // ~10 ticks (0.5s) to reach full speed
|
||||||
|
constexpr float DECELERATION = 0.02f; // ~5 ticks (0.25s) to stop
|
||||||
|
constexpr float GRAVITY = 1.0f; // ≈20 tiles/s², close to the player
|
||||||
|
} // namespace PigDefaults
|
||||||
|
|
||||||
|
} // namespace Cubed
|
||||||
20
include/Cubed/gameplay/creatures/spawn.hpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Cubed/gameplay/biome.hpp"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <span>
|
||||||
|
#include <string_view>
|
||||||
|
namespace Cubed {
|
||||||
|
struct SpawnConfig {
|
||||||
|
std::string_view name; // factory key, e.g. "cubed:pig"
|
||||||
|
std::span<const BiomeType> biomes; // allowed biomes
|
||||||
|
float probability = 0.0f; // per chunk spawn probability
|
||||||
|
unsigned max_spawn_count = 0; // per chunk_max_spawn_sum
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace SpawnDefaults {
|
||||||
|
constexpr std::array<BiomeType, 2> PIG_BIOMES{BiomeType::PLAIN,
|
||||||
|
BiomeType::FOREST};
|
||||||
|
constexpr SpawnConfig PIG{"cubed:pig", PIG_BIOMES, 0.02f, 3};
|
||||||
|
} // namespace SpawnDefaults
|
||||||
|
} // namespace Cubed
|
||||||
17
include/Cubed/gameplay/ecs/ai_struct.hpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Cubed/gameplay/game_time.hpp"
|
||||||
|
namespace Cubed {
|
||||||
|
struct AIBase {
|
||||||
|
TickType interval = 1;
|
||||||
|
TickType count = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WanderAITag {};
|
||||||
|
|
||||||
|
struct MoveBoost {
|
||||||
|
TickType duration = 0;
|
||||||
|
TickType count = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Cubed
|
||||||
14
include/Cubed/gameplay/ecs/animation.hpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Cubed/gameplay/gait.hpp"
|
||||||
|
namespace Cubed {
|
||||||
|
|
||||||
|
struct WalkPose {
|
||||||
|
Gait gait = Gait::STOP;
|
||||||
|
// for arm roll caculate
|
||||||
|
float walk_time = 0.0f;
|
||||||
|
// for sound play
|
||||||
|
float moving_time = 0.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Cubed
|
||||||
14
include/Cubed/gameplay/ecs/client_entity.hpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Cubed/gameplay/ecs/animation.hpp"
|
||||||
|
#include "Cubed/gameplay/ecs/transform.hpp"
|
||||||
|
#include "Cubed/gameplay/model.hpp"
|
||||||
|
namespace Cubed {
|
||||||
|
struct BaseClientCreature {
|
||||||
|
|
||||||
|
Transform transform;
|
||||||
|
|
||||||
|
WalkPose pose;
|
||||||
|
|
||||||
|
ModelID model;
|
||||||
|
};
|
||||||
|
} // namespace Cubed
|
||||||
14
include/Cubed/gameplay/ecs/entity.hpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
namespace Cubed {
|
||||||
|
using EntityID = uint64_t;
|
||||||
|
|
||||||
|
enum class EntityType { CREATURE, ITEM };
|
||||||
|
|
||||||
|
struct Entity {
|
||||||
|
EntityID id;
|
||||||
|
EntityType type;
|
||||||
|
Entity(EntityID id, EntityType type) : id(id), type(type) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Cubed
|
||||||
10
include/Cubed/gameplay/ecs/health.hpp
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Cubed {
|
||||||
|
|
||||||
|
struct Health {
|
||||||
|
float hp = 20;
|
||||||
|
float max_hp = 20;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Cubed
|
||||||
10
include/Cubed/gameplay/ecs/identity.hpp
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Cubed {
|
||||||
|
struct EntityInfo {
|
||||||
|
std::string name;
|
||||||
|
std::string uuid;
|
||||||
|
};
|
||||||
|
} // namespace Cubed
|
||||||
34
include/Cubed/gameplay/ecs/movement.hpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Cubed/constants.hpp"
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
namespace Cubed {
|
||||||
|
struct TickVelocity {
|
||||||
|
|
||||||
|
glm::vec3 value{0.0f};
|
||||||
|
// blocks/tick!!! -1 for in
|
||||||
|
glm::vec3 max{1.0f, -1.0f, 1.0f};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Velocity {
|
||||||
|
|
||||||
|
glm::vec3 value{0.0f};
|
||||||
|
// blocks/second!!!
|
||||||
|
glm::vec3 max{4.5f, 7.5f, 7.5f};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Movement {
|
||||||
|
|
||||||
|
float acceleration = DEFAULT_ACCELERATION;
|
||||||
|
|
||||||
|
float deceleration = DEFAULT_DECELERATION;
|
||||||
|
|
||||||
|
float jump_power = 7.5f;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Gravity {
|
||||||
|
|
||||||
|
float value = DEFAULT_G;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Cubed
|
||||||
22
include/Cubed/gameplay/ecs/server_entity.hpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Cubed/gameplay/ecs/health.hpp"
|
||||||
|
#include "Cubed/gameplay/ecs/movement.hpp"
|
||||||
|
#include "Cubed/gameplay/ecs/transform.hpp"
|
||||||
|
#include "Cubed/gameplay/hitbox.hpp"
|
||||||
|
namespace Cubed {
|
||||||
|
|
||||||
|
struct BaseServerCreature {
|
||||||
|
Transform transform{};
|
||||||
|
|
||||||
|
TickVelocity velocity{};
|
||||||
|
|
||||||
|
Movement movement{};
|
||||||
|
|
||||||
|
Gravity gravity{};
|
||||||
|
|
||||||
|
Health health{};
|
||||||
|
|
||||||
|
HitboxID hitbox{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Cubed
|
||||||
18
include/Cubed/gameplay/ecs/state.hpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Cubed {
|
||||||
|
struct MoveState {
|
||||||
|
|
||||||
|
bool forward = false;
|
||||||
|
bool back = false;
|
||||||
|
bool left = false;
|
||||||
|
bool right = false;
|
||||||
|
|
||||||
|
bool down = false;
|
||||||
|
bool up = false;
|
||||||
|
|
||||||
|
bool is_fly = false;
|
||||||
|
bool can_up = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Cubed
|
||||||
30
include/Cubed/gameplay/ecs/transform.hpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
namespace Cubed {
|
||||||
|
struct Position {
|
||||||
|
glm::vec3 value{0.0f};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Orientation {
|
||||||
|
float yaw = 0.0f;
|
||||||
|
float pitch = 0.0f;
|
||||||
|
float roll = 0.0f;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Direction {
|
||||||
|
glm::vec3 value{0.0f};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Transform {
|
||||||
|
Position position{};
|
||||||
|
Orientation orientation{};
|
||||||
|
Direction direction{};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RenderTransform {
|
||||||
|
Position position{};
|
||||||
|
Orientation orientation{};
|
||||||
|
Direction direction{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Cubed
|
||||||
21
include/Cubed/gameplay/gait.hpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace Cubed {
|
||||||
|
enum class Gait { STOP = 0, WALK = 1, RUN = 2 };
|
||||||
|
constexpr int get_gait_id(Gait gait) { return std::to_underlying(gait); }
|
||||||
|
|
||||||
|
inline Gait get_gait_from_id(int id) {
|
||||||
|
switch (id) {
|
||||||
|
case std::to_underlying(Gait::STOP):
|
||||||
|
return Gait::STOP;
|
||||||
|
case std::to_underlying(Gait::WALK):
|
||||||
|
return Gait::WALK;
|
||||||
|
case std::to_underlying(Gait::RUN):
|
||||||
|
return Gait::RUN;
|
||||||
|
default:
|
||||||
|
throw std::runtime_error("Unknown Gait");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace Cubed
|
||||||
26
include/Cubed/gameplay/hitbox.hpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
namespace Cubed {
|
||||||
|
|
||||||
|
using HitboxID = uint32_t;
|
||||||
|
|
||||||
|
struct Hitbox {
|
||||||
|
glm::vec3 center{0.0f};
|
||||||
|
glm::vec3 half{0.0f};
|
||||||
|
|
||||||
|
Hitbox(glm::vec3 center_point, glm::vec3 half_size)
|
||||||
|
: center(center_point), half(half_size) {}
|
||||||
|
|
||||||
|
glm::vec3 min() const { return center - half; }
|
||||||
|
|
||||||
|
glm::vec3 max() const { return center + half; }
|
||||||
|
|
||||||
|
bool intersects(const Hitbox& other) const {
|
||||||
|
return (glm::abs(center.x - other.center.x) <= half.x + other.half.x) &&
|
||||||
|
(glm::abs(center.y - other.center.y) <= half.y + other.half.y) &&
|
||||||
|
(glm::abs(center.z - other.center.z) <= half.z + other.half.z);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Cubed
|
||||||
37
include/Cubed/gameplay/hitbox_manager.hpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Cubed/gameplay/hitbox.hpp"
|
||||||
|
|
||||||
|
#include <tbb/concurrent_hash_map.h>
|
||||||
|
namespace Cubed {
|
||||||
|
class HitboxManager {
|
||||||
|
public:
|
||||||
|
struct Handle {
|
||||||
|
Hitbox box;
|
||||||
|
HitboxID id = 0;
|
||||||
|
};
|
||||||
|
HitboxManager();
|
||||||
|
~HitboxManager();
|
||||||
|
static HitboxManager& instance();
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Handle get_hitbox(const std::string& key);
|
||||||
|
[[nodiscard]]
|
||||||
|
Handle get_hitbox(HitboxID id);
|
||||||
|
[[nodiscard]]
|
||||||
|
static Handle hitbox(const std::string& name);
|
||||||
|
[[nodiscard]]
|
||||||
|
static Handle hitbox(HitboxID id);
|
||||||
|
HitboxID get_hitbox_id(const std::string& name);
|
||||||
|
const std::string& get_hitbox_name(HitboxID id);
|
||||||
|
|
||||||
|
private:
|
||||||
|
using HitboxMap = tbb::concurrent_hash_map<HitboxID, Hitbox>;
|
||||||
|
using IDMap = tbb::concurrent_hash_map<std::string, HitboxID>;
|
||||||
|
using NameMap = tbb::concurrent_hash_map<HitboxID, std::string>;
|
||||||
|
HitboxID m_next = 0;
|
||||||
|
IDMap m_id_map;
|
||||||
|
NameMap m_name_map;
|
||||||
|
HitboxMap m_hitboxes;
|
||||||
|
Handle load(std::string_view name);
|
||||||
|
};
|
||||||
|
} // namespace Cubed
|
||||||
39
include/Cubed/gameplay/item.hpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Cubed/gameplay/block.hpp"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <variant>
|
||||||
|
namespace Cubed {
|
||||||
|
using ItemID = uint16_t;
|
||||||
|
|
||||||
|
enum class ItemKind {
|
||||||
|
NONE,
|
||||||
|
BLOCK,
|
||||||
|
SPAWN_EGG
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
using ItemProperty = std::variant<BlockType, std::string>;
|
||||||
|
|
||||||
|
struct ItemData {
|
||||||
|
ItemID id = 0;
|
||||||
|
std::string name;
|
||||||
|
std::string local_name;
|
||||||
|
std::string description;
|
||||||
|
std::string path;
|
||||||
|
ItemKind kind = ItemKind::NONE;
|
||||||
|
ItemProperty property;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline constexpr ItemKind get_item_kind(std::string_view kind) {
|
||||||
|
if (kind == "block") {
|
||||||
|
return ItemKind::BLOCK;
|
||||||
|
}
|
||||||
|
if (kind == "spawn_egg") {
|
||||||
|
return ItemKind::SPAWN_EGG;
|
||||||
|
}
|
||||||
|
return ItemKind::NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Cubed
|
||||||
39
include/Cubed/gameplay/item_manager.hpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Cubed/gameplay/item.hpp"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <string_view>
|
||||||
|
#include <tbb/concurrent_hash_map.h>
|
||||||
|
namespace Cubed {
|
||||||
|
class ItemManager {
|
||||||
|
public:
|
||||||
|
ItemManager();
|
||||||
|
void init();
|
||||||
|
static ItemManager& instance();
|
||||||
|
|
||||||
|
static const ItemData& get(std::string_view key);
|
||||||
|
static const ItemData& get(ItemID id);
|
||||||
|
|
||||||
|
static ItemID size();
|
||||||
|
|
||||||
|
const ItemData& get_item_data(std::string_view key) const;
|
||||||
|
const ItemData& get_item_data(ItemID id) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
using ItemMap = tbb::concurrent_hash_map<ItemID, ItemData>;
|
||||||
|
using acc = ItemMap::accessor;
|
||||||
|
using cacc = ItemMap::const_accessor;
|
||||||
|
|
||||||
|
using IDMap = tbb::concurrent_hash_map<std::string, ItemID>;
|
||||||
|
using BlockToIDMap = tbb::concurrent_hash_map<BlockType, ItemID>;
|
||||||
|
void add(const std::filesystem::path& path);
|
||||||
|
|
||||||
|
ItemMap m_map;
|
||||||
|
|
||||||
|
IDMap m_id_map;
|
||||||
|
BlockToIDMap m_block_to_id_map;
|
||||||
|
|
||||||
|
static inline const ItemData EMPTY;
|
||||||
|
};
|
||||||
|
} // namespace Cubed
|
||||||
9
include/Cubed/gameplay/item_stack.hpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Cubed/gameplay/item.hpp"
|
||||||
|
namespace Cubed {
|
||||||
|
|
||||||
|
struct ItemStack {
|
||||||
|
ItemID id = 0;
|
||||||
|
size_t sum = 0;
|
||||||
|
};
|
||||||
|
} // namespace Cubed
|
||||||
161
include/Cubed/gameplay/local_player.hpp
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Cubed/constants.hpp"
|
||||||
|
#include "Cubed/gameplay/block.hpp"
|
||||||
|
#include "Cubed/gameplay/chunk_pos.hpp"
|
||||||
|
#include "Cubed/gameplay/ecs/animation.hpp"
|
||||||
|
#include "Cubed/gameplay/ecs/identity.hpp"
|
||||||
|
#include "Cubed/gameplay/ecs/movement.hpp"
|
||||||
|
#include "Cubed/gameplay/ecs/state.hpp"
|
||||||
|
#include "Cubed/gameplay/ecs/transform.hpp"
|
||||||
|
#include "Cubed/gameplay/game_mode.hpp"
|
||||||
|
#include "Cubed/gameplay/game_time.hpp"
|
||||||
|
#include "Cubed/gameplay/hitbox.hpp"
|
||||||
|
#include "Cubed/gameplay/item_stack.hpp"
|
||||||
|
#include "Cubed/input/event.hpp"
|
||||||
|
#include "Cubed/input/input.hpp"
|
||||||
|
|
||||||
|
#include <absl/container/flat_hash_set.h>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <optional>
|
||||||
|
#include <shared_mutex>
|
||||||
|
namespace Cubed {
|
||||||
|
|
||||||
|
class ClientWorld;
|
||||||
|
class LocalPlayer {
|
||||||
|
public:
|
||||||
|
static constexpr size_t HOTBAR_SUM = 10;
|
||||||
|
static constexpr float WALK_SOUND_INTERVAL = 0.45f;
|
||||||
|
static constexpr float RUN_SOUND_INTERVAL = 0.3f;
|
||||||
|
using ChunkPosSet = absl::flat_hash_set<ChunkPos, ChunkPos::Hash>;
|
||||||
|
LocalPlayer(ClientWorld& world);
|
||||||
|
~LocalPlayer();
|
||||||
|
|
||||||
|
bool handle_mouse_button_event(const MouseButtonEvent& e);
|
||||||
|
bool handle_key_event(const KeyEvent& e);
|
||||||
|
bool handle_mouse_wheel_event(const MouseWheelEvent& e);
|
||||||
|
|
||||||
|
void update_front_vec(float offset_x, float offset_y);
|
||||||
|
bool update_player_move_state(Key key, KeyAction action);
|
||||||
|
bool update_scroll(float yoffset);
|
||||||
|
|
||||||
|
void update_chunk_set(const ChunkPosSet& set);
|
||||||
|
|
||||||
|
const ChunkPosSet& get_chunk_pos_set() const;
|
||||||
|
ChunkPosSet get_chunk_pos_set();
|
||||||
|
|
||||||
|
const glm::vec3& get_front() const;
|
||||||
|
|
||||||
|
const std::optional<LookBlock>& get_look_block_pos() const;
|
||||||
|
// thread safe
|
||||||
|
glm::vec3 get_player_pos() const;
|
||||||
|
const MoveState& get_move_state() const;
|
||||||
|
|
||||||
|
void change_mode(GameMode mode);
|
||||||
|
void reload_config();
|
||||||
|
void set_player_pos(const glm::vec3& pos);
|
||||||
|
void update(float delta_time);
|
||||||
|
|
||||||
|
float& max_walk_speed();
|
||||||
|
float& max_run_speed();
|
||||||
|
float& fly_y_speed();
|
||||||
|
|
||||||
|
const ItemStack& get_current_itemstack() const;
|
||||||
|
|
||||||
|
GameMode& game_mode();
|
||||||
|
|
||||||
|
ClientWorld& get_world();
|
||||||
|
|
||||||
|
void set_uuid(std::string_view uuid);
|
||||||
|
std::string get_uuid() const;
|
||||||
|
const std::string& get_name() const;
|
||||||
|
void reset_input_status();
|
||||||
|
void init(std::string_view name);
|
||||||
|
|
||||||
|
bool ray_cast(const glm::vec3& start, const glm::vec3& dir,
|
||||||
|
glm::ivec3& block_pos, glm::vec3& normal,
|
||||||
|
float distance = 4.0f);
|
||||||
|
bool is_underwater() const;
|
||||||
|
void set_underwater(bool u);
|
||||||
|
void place_block(float dt);
|
||||||
|
|
||||||
|
int selected_hotbar() const;
|
||||||
|
void set_hotbar(int pos, const ItemStack& item);
|
||||||
|
std::span<const ItemStack, HOTBAR_SUM> get_hotbar() const;
|
||||||
|
|
||||||
|
glm::vec3& max_speed();
|
||||||
|
float& acceleration();
|
||||||
|
float& deceleration();
|
||||||
|
float& g();
|
||||||
|
void set_gait(Gait gait);
|
||||||
|
float yaw() const;
|
||||||
|
float pitch() const;
|
||||||
|
float& roll();
|
||||||
|
float& walk_time();
|
||||||
|
Gait get_gait() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
using enum GameMode;
|
||||||
|
float m_max_walk_speed = DEFAULT_MAX_WALK_SPEED;
|
||||||
|
float m_max_run_speed = DEFAULT_MAX_RUN_SPEED;
|
||||||
|
float m_max_y_speed = 7.5f;
|
||||||
|
static constexpr float MAX_SPACE_ON_TIME = 0.3f;
|
||||||
|
static constexpr float PLACE_BLOCK_INTERVAL = 0.2f;
|
||||||
|
|
||||||
|
EntityInfo m_info;
|
||||||
|
Position m_pos;
|
||||||
|
WalkPose m_walk_pose;
|
||||||
|
Velocity m_velocity;
|
||||||
|
Orientation m_angle;
|
||||||
|
Movement m_movement;
|
||||||
|
Gravity m_gravity;
|
||||||
|
MoveState m_move_state;
|
||||||
|
Direction m_direction;
|
||||||
|
HitboxID m_hitbox = 0;
|
||||||
|
|
||||||
|
float m_place_time = PLACE_BLOCK_INTERVAL;
|
||||||
|
|
||||||
|
std::array<ItemStack, HOTBAR_SUM> m_hotbar;
|
||||||
|
float m_sensitivity = 0.15f;
|
||||||
|
|
||||||
|
float space_on_time = 0.0f;
|
||||||
|
bool space_on = false;
|
||||||
|
|
||||||
|
int m_selected_hotbar = 0;
|
||||||
|
|
||||||
|
bool m_moving = false;
|
||||||
|
bool m_sprinting = false;
|
||||||
|
bool m_underwater = false;
|
||||||
|
|
||||||
|
// player is tow block tall, the pos is the lower pos
|
||||||
|
ChunkPos m_last_chunk_pos{0, 0};
|
||||||
|
|
||||||
|
glm::vec3 m_front{0, 0, -1};
|
||||||
|
glm::vec3 m_right{0, 0, 0};
|
||||||
|
|
||||||
|
MouseState m_mouse_state{};
|
||||||
|
GameMode m_game_mode = CREATIVE;
|
||||||
|
std::optional<LookBlock> m_look_block = std::nullopt;
|
||||||
|
std::string m_name{};
|
||||||
|
mutable std::shared_mutex m_uuid_mutex;
|
||||||
|
std::string m_uuid;
|
||||||
|
ClientWorld& m_world;
|
||||||
|
|
||||||
|
std::unordered_map<std::string, Timer> m_timers;
|
||||||
|
|
||||||
|
mutable std::shared_mutex m_player_pos_mutex;
|
||||||
|
mutable std::shared_mutex m_chunk_pos_mutex;
|
||||||
|
ChunkPosSet m_player_chunk_pos_set;
|
||||||
|
|
||||||
|
void update_direction();
|
||||||
|
void update_lookup_block();
|
||||||
|
void update_move(float dt);
|
||||||
|
void update_player_chunk();
|
||||||
|
|
||||||
|
void play_walk_sound(float dt);
|
||||||
|
Gait compute_gait() const;
|
||||||
|
|
||||||
|
void update_speed(float dt);
|
||||||
|
std::tuple<bool, bool, bool> update_physical(float dt, glm::vec3& pos);
|
||||||
|
glm::vec3 get_move_distance(float dt);
|
||||||
|
};
|
||||||
|
} // namespace Cubed
|
||||||
7
include/Cubed/gameplay/model.hpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
using ModelID = uint32_t;
|
||||||
|
struct Model {
|
||||||
|
ModelID id;
|
||||||
|
};
|
||||||
@@ -21,6 +21,7 @@ public:
|
|||||||
bool is_connect_error() const;
|
bool is_connect_error() const;
|
||||||
std::string get_error_string() const;
|
std::string get_error_string() const;
|
||||||
void clear_error();
|
void clear_error();
|
||||||
|
ClientWorld& world();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Task {
|
struct Task {
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ public:
|
|||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
// Run in another thread after initialization is complete
|
// Run in another thread after initialization is complete
|
||||||
void start_server(int port);
|
void start_server(int port, RunMode mode);
|
||||||
void start_server();
|
|
||||||
int port() const;
|
int port() const;
|
||||||
ServerWorld& server_world();
|
ServerWorld& server_world();
|
||||||
|
|
||||||
|
|||||||
@@ -51,16 +51,28 @@ enum class PacketEnum : uint16_t {
|
|||||||
LOGIN_RSP = 1002,
|
LOGIN_RSP = 1002,
|
||||||
LOGOUT_REQ = 1003,
|
LOGOUT_REQ = 1003,
|
||||||
LOGOUT_RSP = 1004,
|
LOGOUT_RSP = 1004,
|
||||||
|
|
||||||
PLAYER_INFO = 2001,
|
PLAYER_INFO = 2001,
|
||||||
C2S_PLAYER_INFO = 2002,
|
C2S_PLAYER_INFO = 2002,
|
||||||
PLAYER_INFO_RSP = 2003,
|
PLAYER_INFO_RSP = 2003,
|
||||||
PLAYER_WATER_SOUND = 2004,
|
PLAYER_WATER_SOUND = 2004,
|
||||||
|
|
||||||
CHUNK_DATA_REQ = 3001,
|
CHUNK_DATA_REQ = 3001,
|
||||||
CHUNK_DATA_RSP = 3002,
|
CHUNK_DATA_RSP = 3002,
|
||||||
BLOCK_CHANGE_REQ = 3003,
|
BLOCK_CHANGE_REQ = 3003,
|
||||||
BLOCK_CHANGE_RSP = 3004,
|
BLOCK_CHANGE_RSP = 3004,
|
||||||
S2C_CLEAR_ALL_CHUNKS = 3005,
|
S2C_CLEAR_ALL_CHUNKS = 3005,
|
||||||
UPDATE_TIME = 3006,
|
UPDATE_TIME = 3006,
|
||||||
|
S2C_ENTITY_CREATE = 3007,
|
||||||
|
S2C_ENTITY_DESTORY = 3008,
|
||||||
|
C2S_ENTITY_CREATE_REQUEST = 3009,
|
||||||
|
C2S_ENTITY_DESTORY_REQUEST = 3010,
|
||||||
|
S2C_ENTITY_UPDATE = 3011,
|
||||||
|
S2C_ENTITY_UPDATE_BATCH = 3012,
|
||||||
|
|
||||||
|
CHAT_MSG = 4001,
|
||||||
|
VOICE_MSG = 4002,
|
||||||
|
|
||||||
PING = 9001,
|
PING = 9001,
|
||||||
PONG = 9002
|
PONG = 9002
|
||||||
|
|
||||||
@@ -109,6 +121,18 @@ template <> constexpr uint16_t get_packet_id<BlockChangeRsp>() {
|
|||||||
template <> constexpr uint16_t get_packet_id<S2C_ClearAllChunks>() {
|
template <> constexpr uint16_t get_packet_id<S2C_ClearAllChunks>() {
|
||||||
return std::to_underlying(PacketEnum::S2C_CLEAR_ALL_CHUNKS);
|
return std::to_underlying(PacketEnum::S2C_CLEAR_ALL_CHUNKS);
|
||||||
}
|
}
|
||||||
|
template <> constexpr uint16_t get_packet_id<S2CEntityCreate>() {
|
||||||
|
return std::to_underlying(PacketEnum::S2C_ENTITY_CREATE);
|
||||||
|
}
|
||||||
|
template <> constexpr uint16_t get_packet_id<S2CEntityDestory>() {
|
||||||
|
return std::to_underlying(PacketEnum::S2C_ENTITY_DESTORY);
|
||||||
|
}
|
||||||
|
template <> constexpr uint16_t get_packet_id<C2SEntityCreateRequest>() {
|
||||||
|
return std::to_underlying(PacketEnum::C2S_ENTITY_CREATE_REQUEST);
|
||||||
|
}
|
||||||
|
template <> constexpr uint16_t get_packet_id<C2SEntityDestoryRequest>() {
|
||||||
|
return std::to_underlying(PacketEnum::C2S_ENTITY_DESTORY_REQUEST);
|
||||||
|
}
|
||||||
template <> constexpr uint16_t get_packet_id<UpdateTime>() {
|
template <> constexpr uint16_t get_packet_id<UpdateTime>() {
|
||||||
return std::to_underlying(PacketEnum::UPDATE_TIME);
|
return std::to_underlying(PacketEnum::UPDATE_TIME);
|
||||||
}
|
}
|
||||||
@@ -121,6 +145,18 @@ template <> constexpr uint16_t get_packet_id<Pong>() {
|
|||||||
template <> constexpr uint16_t get_packet_id<PlayerWaterSound>() {
|
template <> constexpr uint16_t get_packet_id<PlayerWaterSound>() {
|
||||||
return std::to_underlying(PacketEnum::PLAYER_WATER_SOUND);
|
return std::to_underlying(PacketEnum::PLAYER_WATER_SOUND);
|
||||||
}
|
}
|
||||||
|
template <> constexpr uint16_t get_packet_id<ChatMsg>() {
|
||||||
|
return std::to_underlying(PacketEnum::CHAT_MSG);
|
||||||
|
}
|
||||||
|
template <> constexpr uint16_t get_packet_id<VoiceMsg>() {
|
||||||
|
return std::to_underlying(PacketEnum::VOICE_MSG);
|
||||||
|
}
|
||||||
|
template <> constexpr uint16_t get_packet_id<S2CEntityUpdate>() {
|
||||||
|
return std::to_underlying(PacketEnum::S2C_ENTITY_UPDATE);
|
||||||
|
}
|
||||||
|
template <> constexpr uint16_t get_packet_id<S2CEntityUpdateBatch>() {
|
||||||
|
return std::to_underlying(PacketEnum::S2C_ENTITY_UPDATE_BATCH);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
requires std::derived_from<T, google::protobuf::Message>
|
requires std::derived_from<T, google::protobuf::Message>
|
||||||
@@ -172,6 +208,12 @@ Packet make_packet(const T& msg) {
|
|||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
requires std::derived_from<T, google::protobuf::Message>
|
||||||
|
Packet make_packet(const T* msg) {
|
||||||
|
return make_packet(*msg);
|
||||||
|
}
|
||||||
|
|
||||||
inline PacketHeader decode_packet_header(std::span<const uint8_t> header) {
|
inline PacketHeader decode_packet_header(std::span<const uint8_t> header) {
|
||||||
if (header.size() < HEADER_LEN)
|
if (header.size() < HEADER_LEN)
|
||||||
throw std::runtime_error("Invalid header");
|
throw std::runtime_error("Invalid header");
|
||||||
|
|||||||