mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-22 10:29:47 +00:00
Merge pull request #1069 from MihailRis/remove-entt
remove EnTT dependency
This commit is contained in:
commit
e370ec6495
23 changed files with 410 additions and 437 deletions
6
.github/workflows/appimage.yml
vendored
6
.github/workflows/appimage.yml
vendored
|
|
@ -35,12 +35,6 @@ jobs:
|
||||||
# fix luajit paths
|
# fix luajit paths
|
||||||
sudo ln -s /usr/lib/x86_64-linux-gnu/libluajit-5.1.a /usr/lib/x86_64-linux-gnu/liblua5.1.a
|
sudo ln -s /usr/lib/x86_64-linux-gnu/libluajit-5.1.a /usr/lib/x86_64-linux-gnu/liblua5.1.a
|
||||||
sudo ln -s /usr/include/luajit-2.1 /usr/include/lua
|
sudo ln -s /usr/include/luajit-2.1 /usr/include/lua
|
||||||
# install EnTT
|
|
||||||
git clone --branch v3.16.0 https://github.com/skypjack/entt.git
|
|
||||||
cd entt/build
|
|
||||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_BUILD_TYPE=Release -DENTT_INSTALL=on ..
|
|
||||||
sudo make install
|
|
||||||
cd ../..
|
|
||||||
- name: Configure
|
- name: Configure
|
||||||
run: cmake -S . -B build -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_BUILD_TYPE=Release -DVOXELENGINE_BUILD_APPDIR=1 -DVOXELENGINE_BUILD_TESTS=ON -DVC_BUILD_NAME="${{ inputs.build_name }}"
|
run: cmake -S . -B build -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_BUILD_TYPE=Release -DVOXELENGINE_BUILD_APPDIR=1 -DVOXELENGINE_BUILD_TESTS=ON -DVC_BUILD_NAME="${{ inputs.build_name }}"
|
||||||
- name: Build
|
- name: Build
|
||||||
|
|
|
||||||
6
.github/workflows/cmake.yml
vendored
6
.github/workflows/cmake.yml
vendored
|
|
@ -43,12 +43,6 @@ jobs:
|
||||||
# fix luajit paths
|
# fix luajit paths
|
||||||
sudo ln -s /usr/lib/x86_64-linux-gnu/libluajit-5.1.a /usr/lib/x86_64-linux-gnu/liblua-5.1.a
|
sudo ln -s /usr/lib/x86_64-linux-gnu/libluajit-5.1.a /usr/lib/x86_64-linux-gnu/liblua-5.1.a
|
||||||
sudo ln -s /usr/include/luajit-2.1 /usr/include/lua
|
sudo ln -s /usr/include/luajit-2.1 /usr/include/lua
|
||||||
# install EnTT
|
|
||||||
git clone --branch v3.16.0 https://github.com/skypjack/entt.git
|
|
||||||
cd entt/build
|
|
||||||
cmake -DCMAKE_BUILD_TYPE=Release -DENTT_INSTALL=on ..
|
|
||||||
sudo make install
|
|
||||||
cd ../..
|
|
||||||
|
|
||||||
- name: Configure CMake
|
- name: Configure CMake
|
||||||
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only
|
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only
|
||||||
|
|
|
||||||
2
.github/workflows/macos.yml
vendored
2
.github/workflows/macos.yml
vendored
|
|
@ -23,7 +23,7 @@ jobs:
|
||||||
|
|
||||||
- name: Install dependencies from brew
|
- name: Install dependencies from brew
|
||||||
run: |
|
run: |
|
||||||
brew install glfw glew libpng openal-soft luajit libvorbis skypjack/entt/entt googletest glm freetype
|
brew install glfw glew libpng openal-soft luajit libvorbis googletest glm freetype
|
||||||
|
|
||||||
- name: Configure
|
- name: Configure
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
|
|
@ -38,15 +38,6 @@ RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cm
|
||||||
./cmake-${CMAKE_VERSION}-linux-x86_64.sh --skip-license --prefix=/usr/local && \
|
./cmake-${CMAKE_VERSION}-linux-x86_64.sh --skip-license --prefix=/usr/local && \
|
||||||
rm cmake-${CMAKE_VERSION}-linux-x86_64.sh
|
rm cmake-${CMAKE_VERSION}-linux-x86_64.sh
|
||||||
|
|
||||||
|
|
||||||
# Install specific EnTT version (the latest version that supports C++17).
|
|
||||||
RUN git clone --branch v3.16.0 https://github.com/skypjack/entt.git && \
|
|
||||||
cd entt/build && \
|
|
||||||
cmake -DCMAKE_BUILD_TYPE=Release -DENTT_INSTALL=on .. && \
|
|
||||||
make install && \
|
|
||||||
cd ../.. && rm -rf entt
|
|
||||||
|
|
||||||
|
|
||||||
# CMake missing LUA_INCLUDE_DIR and LUA_LIBRARIES fix:
|
# CMake missing LUA_INCLUDE_DIR and LUA_LIBRARIES fix:
|
||||||
RUN ln -s /usr/lib/x86_64-linux-gnu/libluajit-5.1.a /usr/lib/x86_64-linux-gnu/liblua5.1.a \
|
RUN ln -s /usr/lib/x86_64-linux-gnu/libluajit-5.1.a /usr/lib/x86_64-linux-gnu/liblua5.1.a \
|
||||||
&& ln -s /usr/include/luajit-2.1 /usr/include/lua
|
&& ln -s /usr/include/luajit-2.1 /usr/include/lua
|
||||||
|
|
|
||||||
19
README.md
19
README.md
|
|
@ -11,26 +11,11 @@
|
||||||
|
|
||||||
### Install libraries
|
### Install libraries
|
||||||
|
|
||||||
#### Install EnTT
|
|
||||||
|
|
||||||
Installing last version that supports C++17.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
git clone --branch v3.16.0 https://github.com/skypjack/entt.git
|
|
||||||
cd entt
|
|
||||||
mkdir -p build && cd build
|
|
||||||
cmake -DCMAKE_BUILD_TYPE=Release -DENTT_INSTALL=ON ..
|
|
||||||
sudo make install
|
|
||||||
```
|
|
||||||
|
|
||||||
> [!WARNING]
|
|
||||||
> If you are using ALT Linux, do **not** use this EnTT installation method.
|
|
||||||
|
|
||||||
#### ALT Linux based distros
|
#### ALT Linux based distros
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
su -
|
su -
|
||||||
apt-get install entt-devel libglfw3-devel libGLEW-devel libglm-devel libpng-devel libvorbis-devel libopenal-devel libluajit-devel libstdc++13-devel-static libcurl-devel libfreetype-devel libssl-devel
|
apt-get install libglfw3-devel libGLEW-devel libglm-devel libpng-devel libvorbis-devel libopenal-devel libluajit-devel libstdc++13-devel-static libcurl-devel libfreetype-devel libssl-devel
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Debian based distros
|
#### Debian based distros
|
||||||
|
|
@ -80,7 +65,7 @@ cmake --build . --parallel
|
||||||
### Install libraries
|
### Install libraries
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
brew install glfw glew glm libpng libvorbis lua luajit libcurl openal-soft skypjack/entt/entt freetype
|
brew install glfw glew glm libpng libvorbis lua luajit libcurl openal-soft freetype
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!TIP]
|
> [!TIP]
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,6 @@
|
||||||
luajit
|
luajit
|
||||||
curl
|
curl
|
||||||
openssl
|
openssl
|
||||||
entt
|
|
||||||
mesa
|
mesa
|
||||||
freeglut
|
freeglut
|
||||||
];
|
];
|
||||||
|
|
@ -47,11 +46,6 @@
|
||||||
glfw
|
glfw
|
||||||
mesa
|
mesa
|
||||||
freeglut
|
freeglut
|
||||||
entt
|
|
||||||
];
|
|
||||||
cmakeFlags = [
|
|
||||||
"-DCMAKE_PREFIX_PATH=${pkgs.entt}"
|
|
||||||
"-DCMAKE_INCLUDE_PATH=${pkgs.entt}/include"
|
|
||||||
];
|
];
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,6 @@ find_package(CURL REQUIRED)
|
||||||
find_package(OpenSSL 3.0 REQUIRED COMPONENTS Crypto)
|
find_package(OpenSSL 3.0 REQUIRED COMPONENTS Crypto)
|
||||||
find_package(glfw3 REQUIRED)
|
find_package(glfw3 REQUIRED)
|
||||||
find_package(Freetype REQUIRED)
|
find_package(Freetype REQUIRED)
|
||||||
if(NOT APPLE)
|
|
||||||
find_package(EnTT REQUIRED)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||||
find_package(vorbis REQUIRED)
|
find_package(vorbis REQUIRED)
|
||||||
|
|
|
||||||
177
src/graphics/render/EntitiesRenderer.cpp
Normal file
177
src/graphics/render/EntitiesRenderer.cpp
Normal file
|
|
@ -0,0 +1,177 @@
|
||||||
|
#include "EntitiesRenderer.hpp"
|
||||||
|
|
||||||
|
#include "animation/rigging.hpp"
|
||||||
|
#include "assets/Assets.hpp"
|
||||||
|
#include "graphics/core/DrawContext.hpp"
|
||||||
|
#include "graphics/core/LineBatch.hpp"
|
||||||
|
#include "maths/FrustumCulling.hpp"
|
||||||
|
#include "objects/Entities.hpp"
|
||||||
|
#include "objects/Entity.hpp"
|
||||||
|
#include "objects/EntityDef.hpp"
|
||||||
|
#include "ModelBatch.hpp"
|
||||||
|
|
||||||
|
static void debug_render_skeleton(
|
||||||
|
LineBatch& batch,
|
||||||
|
const rigging::Bone* bone,
|
||||||
|
const rigging::Skeleton& skeleton
|
||||||
|
) {
|
||||||
|
size_t pindex = bone->getIndex();
|
||||||
|
for (auto& sub : bone->getBones()) {
|
||||||
|
size_t sindex = sub->getIndex();
|
||||||
|
const auto& matrices = skeleton.calculated.matrices;
|
||||||
|
batch.line(
|
||||||
|
glm::vec3(matrices[pindex] * glm::vec4(0, 0, 0, 1)),
|
||||||
|
glm::vec3(matrices[sindex] * glm::vec4(0, 0, 0, 1)),
|
||||||
|
glm::vec4(0, 0.5f, 0, 1)
|
||||||
|
);
|
||||||
|
debug_render_skeleton(batch, sub.get(), skeleton);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static glm::vec3 calc_extent(
|
||||||
|
const Transform& transform,
|
||||||
|
const Rigidbody& rigidbody,
|
||||||
|
const rigging::Skeleton& skeleton
|
||||||
|
) {
|
||||||
|
const auto& size = transform.size;
|
||||||
|
float scale = glm::max(
|
||||||
|
glm::abs(size.x), glm::max(glm::abs(size.y), glm::abs(size.z))
|
||||||
|
);
|
||||||
|
return glm::max(
|
||||||
|
rigidbody.hitbox.getHalfSize(), glm::vec3(skeleton.boundsRadius * scale)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool check_frustum(
|
||||||
|
const Frustum& frustum,
|
||||||
|
const Transform& transform,
|
||||||
|
const Rigidbody& rigidbody,
|
||||||
|
const rigging::Skeleton& skeleton
|
||||||
|
) {
|
||||||
|
glm::vec3 ext = calc_extent(transform, rigidbody, skeleton);
|
||||||
|
return frustum.isBoxVisible(transform.pos - ext, transform.pos + ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
EntitiesRenderer::EntitiesRenderer(const Assets& assets, Entities& entities)
|
||||||
|
: assets(assets), entities(entities) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntitiesRenderer::render(
|
||||||
|
ModelBatch& batch, const Frustum* frustum, entityid_t fpsEntity
|
||||||
|
) {
|
||||||
|
for (const auto& [uid, entity] : entities.getEntities()) {
|
||||||
|
if (!entity->getSkeleton() || uid == fpsEntity) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto& transform = entity->getTransform();
|
||||||
|
const auto& rigidbody = entity->getRigidbody();
|
||||||
|
auto& skeleton = *entity->getSkeleton();
|
||||||
|
const auto& def = entity->getID().def;
|
||||||
|
const auto& pos = transform.pos;
|
||||||
|
const auto& size = transform.size;
|
||||||
|
const auto& rigConfig = skeleton.config;
|
||||||
|
if (rigConfig == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (frustum && !check_frustum(*frustum, transform, rigidbody, skeleton)) {
|
||||||
|
if (!skeleton.boundsDirty || !skeleton.visible) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
rigConfig->updateBounds(assets, skeleton, transform.rot, pos, size);
|
||||||
|
if (!check_frustum(*frustum, transform, rigidbody, skeleton)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rigConfig->render(
|
||||||
|
assets,
|
||||||
|
batch,
|
||||||
|
skeleton,
|
||||||
|
def.lightingMode,
|
||||||
|
transform.rot,
|
||||||
|
pos,
|
||||||
|
size,
|
||||||
|
def.translucent
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntitiesRenderer::renderDebug(
|
||||||
|
LineBatch& batch,
|
||||||
|
const Frustum* frustum,
|
||||||
|
const DrawContext& pctx,
|
||||||
|
entityid_t fpsEntity
|
||||||
|
) {
|
||||||
|
const auto& all = entities.getEntities();
|
||||||
|
{
|
||||||
|
auto ctx = pctx.sub(&batch);
|
||||||
|
ctx.setLineWidth(1);
|
||||||
|
for (const auto& [uid, entity] : all) {
|
||||||
|
if (!entity->getSkeleton()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto& transform = entity->getTransform();
|
||||||
|
const auto& rigidbody = entity->getRigidbody();
|
||||||
|
const auto& skeleton = *entity->getSkeleton();
|
||||||
|
const auto& hitbox = rigidbody.hitbox;
|
||||||
|
if (frustum && !check_frustum(*frustum, transform, rigidbody, skeleton)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
batch.box(
|
||||||
|
hitbox.position, hitbox.getHalfSize() * 2.0f, glm::vec4(1.0f)
|
||||||
|
);
|
||||||
|
glm::vec3 ext = calc_extent(transform, rigidbody, skeleton);
|
||||||
|
batch.box(
|
||||||
|
transform.pos, ext * 2.0f, glm::vec4(0.0f, 0.0f, 1.0f, 1.0f)
|
||||||
|
);
|
||||||
|
for (auto& sensor : rigidbody.sensors) {
|
||||||
|
if (sensor.type != SensorType::AABB) continue;
|
||||||
|
batch.box(
|
||||||
|
sensor.calculated.aabb.center(),
|
||||||
|
sensor.calculated.aabb.size(),
|
||||||
|
glm::vec4(1.0f, 1.0f, 0.0f, 1.0f)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto ctx = pctx.sub(&batch);
|
||||||
|
ctx.setDepthTest(false);
|
||||||
|
ctx.setDepthMask(false);
|
||||||
|
ctx.setLineWidth(2);
|
||||||
|
for (const auto& [uid, entity] : all) {
|
||||||
|
if (!entity->getSkeleton() || uid == fpsEntity) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto& transform = entity->getTransform();
|
||||||
|
const auto& rigidbody = entity->getRigidbody();
|
||||||
|
const auto& skeleton = *entity->getSkeleton();
|
||||||
|
auto config = skeleton.config;
|
||||||
|
if (config == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (frustum && !check_frustum(*frustum, transform, rigidbody, skeleton)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto bone = config->getRoot();
|
||||||
|
debug_render_skeleton(batch, bone, skeleton);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntitiesRenderer::updateCulling(
|
||||||
|
const Frustum* frustum, entityid_t fpsEntity
|
||||||
|
) {
|
||||||
|
for (const auto& [uid, entity] : entities.getEntities()) {
|
||||||
|
if (!entity->getSkeleton()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto& skeleton = *entity->getSkeleton();
|
||||||
|
if (frustum == nullptr || uid == fpsEntity) {
|
||||||
|
skeleton.culled = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
skeleton.culled = !check_frustum(
|
||||||
|
*frustum, entity->getTransform(), entity->getRigidbody(), skeleton
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/graphics/render/EntitiesRenderer.hpp
Normal file
30
src/graphics/render/EntitiesRenderer.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "typedefs.hpp"
|
||||||
|
|
||||||
|
class Assets;
|
||||||
|
class DrawContext;
|
||||||
|
class Entities;
|
||||||
|
class Frustum;
|
||||||
|
class LineBatch;
|
||||||
|
class ModelBatch;
|
||||||
|
|
||||||
|
class EntitiesRenderer {
|
||||||
|
const Assets& assets;
|
||||||
|
Entities& entities;
|
||||||
|
public:
|
||||||
|
EntitiesRenderer(const Assets& assets, Entities& entities);
|
||||||
|
|
||||||
|
void render(
|
||||||
|
ModelBatch& batch, const Frustum* frustum, entityid_t fpsEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
void renderDebug(
|
||||||
|
LineBatch& batch,
|
||||||
|
const Frustum* frustum,
|
||||||
|
const DrawContext& ctx,
|
||||||
|
entityid_t fpsEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
void updateCulling(const Frustum* frustum, entityid_t fpsEntity);
|
||||||
|
};
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include "CloudsRenderer.hpp"
|
#include "CloudsRenderer.hpp"
|
||||||
#include "DebugLinesRenderer.hpp"
|
#include "DebugLinesRenderer.hpp"
|
||||||
#include "Emitter.hpp"
|
#include "Emitter.hpp"
|
||||||
|
#include "EntitiesRenderer.hpp"
|
||||||
#include "HandsRenderer.hpp"
|
#include "HandsRenderer.hpp"
|
||||||
#include "ModelBatch.hpp"
|
#include "ModelBatch.hpp"
|
||||||
#include "NamedSkeletons.hpp"
|
#include "NamedSkeletons.hpp"
|
||||||
|
|
@ -161,6 +162,7 @@ WorldRenderer::WorldRenderer(
|
||||||
shadowMapping = std::make_unique<Shadows>(level);
|
shadowMapping = std::make_unique<Shadows>(level);
|
||||||
debugLines = std::make_unique<DebugLinesRenderer>(level);
|
debugLines = std::make_unique<DebugLinesRenderer>(level);
|
||||||
cloudsRenderer = std::make_unique<CloudsRenderer>();
|
cloudsRenderer = std::make_unique<CloudsRenderer>();
|
||||||
|
entitiesRenderer = std::make_unique<EntitiesRenderer>(assets, *level.entities);
|
||||||
|
|
||||||
keepAlive(observe_setting(settings.graphics.enableFog, dirtySettings));
|
keepAlive(observe_setting(settings.graphics.enableFog, dirtySettings));
|
||||||
keepAlive(observe_setting(settings.graphics.advancedRender, dirtySettings));
|
keepAlive(observe_setting(settings.graphics.advancedRender, dirtySettings));
|
||||||
|
|
@ -279,8 +281,7 @@ void WorldRenderer::renderOpaque(
|
||||||
auto& modelShader = assets.require<Shader>("model");
|
auto& modelShader = assets.require<Shader>("model");
|
||||||
setupWorldShader(modelShader, camera, settings, fogFactor);
|
setupWorldShader(modelShader, camera, settings, fogFactor);
|
||||||
setup_entity_pass(modelShader, {0.5f, true, false, false, 1.0f});
|
setup_entity_pass(modelShader, {0.5f, true, false, false, 1.0f});
|
||||||
level.entities->render(
|
entitiesRenderer->render(
|
||||||
assets,
|
|
||||||
*modelBatch,
|
*modelBatch,
|
||||||
culling ? frustumCulling.get() : nullptr,
|
culling ? frustumCulling.get() : nullptr,
|
||||||
player.currentCamera.get() == player.fpCamera.get() ? player.getEntity()
|
player.currentCamera.get() == player.fpCamera.get() ? player.getEntity()
|
||||||
|
|
@ -354,7 +355,7 @@ void WorldRenderer::renderInWorldLines(
|
||||||
if (debug && showEntitiesDebug) {
|
if (debug && showEntitiesDebug) {
|
||||||
auto ctx = pctx.sub(lineBatch.get());
|
auto ctx = pctx.sub(lineBatch.get());
|
||||||
bool culling = engine.getSettings().graphics.frustumCulling.get();
|
bool culling = engine.getSettings().graphics.frustumCulling.get();
|
||||||
level.entities->renderDebug(
|
entitiesRenderer->renderDebug(
|
||||||
*lineBatch, culling ? frustumCulling.get() : nullptr, ctx,
|
*lineBatch, culling ? frustumCulling.get() : nullptr, ctx,
|
||||||
player.currentCamera.get() == player.fpCamera.get() ? player.getEntity() : 0
|
player.currentCamera.get() == player.fpCamera.get() ? player.getEntity() : 0
|
||||||
);
|
);
|
||||||
|
|
@ -366,7 +367,7 @@ void WorldRenderer::updateEntitiesCulling(const Camera& camera) {
|
||||||
if (culling) {
|
if (culling) {
|
||||||
frustumCulling->update(camera.getProjView());
|
frustumCulling->update(camera.getProjView());
|
||||||
}
|
}
|
||||||
level.entities->updateCulling(
|
entitiesRenderer->updateCulling(
|
||||||
culling ? frustumCulling.get() : nullptr,
|
culling ? frustumCulling.get() : nullptr,
|
||||||
player.currentCamera.get() == player.fpCamera.get() ? player.getEntity()
|
player.currentCamera.get() == player.fpCamera.get() ? player.getEntity()
|
||||||
: 0
|
: 0
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ class ChunksRenderer;
|
||||||
class DebugLinesRenderer;
|
class DebugLinesRenderer;
|
||||||
class DrawContext;
|
class DrawContext;
|
||||||
class Engine;
|
class Engine;
|
||||||
|
class EntitiesRenderer;
|
||||||
class Frustum;
|
class Frustum;
|
||||||
class HandsRenderer;
|
class HandsRenderer;
|
||||||
class Level;
|
class Level;
|
||||||
|
|
@ -80,6 +81,7 @@ private:
|
||||||
std::unique_ptr<DebugLinesRenderer> debugLines;
|
std::unique_ptr<DebugLinesRenderer> debugLines;
|
||||||
std::unique_ptr<PrecipitationRenderer> precipitation;
|
std::unique_ptr<PrecipitationRenderer> precipitation;
|
||||||
std::unique_ptr<CloudsRenderer> cloudsRenderer;
|
std::unique_ptr<CloudsRenderer> cloudsRenderer;
|
||||||
|
std::unique_ptr<EntitiesRenderer> entitiesRenderer;
|
||||||
std::unique_ptr<TranslucentLayers> translucentLayers;
|
std::unique_ptr<TranslucentLayers> translucentLayers;
|
||||||
|
|
||||||
float timer = 0.0f;
|
float timer = 0.0f;
|
||||||
|
|
|
||||||
|
|
@ -498,11 +498,11 @@ void PlayerController::processRightClick(
|
||||||
void PlayerController::updateEntityInteraction(
|
void PlayerController::updateEntityInteraction(
|
||||||
entityid_t eid, bool lclick, bool rclick
|
entityid_t eid, bool lclick, bool rclick
|
||||||
) {
|
) {
|
||||||
auto entityOpt = level.entities->get(eid);
|
auto entityPtr = level.entities->get(eid);
|
||||||
if (!entityOpt.has_value()) {
|
if (entityPtr == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto entity = *entityOpt;
|
const auto& entity = *entityPtr;
|
||||||
if (lclick) {
|
if (lclick) {
|
||||||
scripting::on_attacked(entity, &player, player.getEntity());
|
scripting::on_attacked(entity, &player, player.getEntity());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ static const EntityDef* require_entity_def(lua::State* L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_exists(lua::State* L) {
|
static int l_exists(lua::State* L) {
|
||||||
return lua::pushboolean(L, get_entity(L, 1).has_value());
|
return lua::pushboolean(L, get_entity(L, 1) != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_def_index(lua::State* L) {
|
static int l_def_index(lua::State* L) {
|
||||||
|
|
@ -138,8 +138,7 @@ static int l_get_all_in_box(lua::State* L) {
|
||||||
auto found = level->entities->getAllInside(AABB(pos, pos + size));
|
auto found = level->entities->getAllInside(AABB(pos, pos + size));
|
||||||
lua::createtable(L, found.size(), 0);
|
lua::createtable(L, found.size(), 0);
|
||||||
for (size_t i = 0; i < found.size(); i++) {
|
for (size_t i = 0; i < found.size(); i++) {
|
||||||
const auto& entity = found[i];
|
lua::pushinteger(L, found[i]->getUID());
|
||||||
lua::pushinteger(L, entity.getUID());
|
|
||||||
lua::rawseti(L, i + 1);
|
lua::rawseti(L, i + 1);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -151,8 +150,7 @@ static int l_get_all_in_radius(lua::State* L) {
|
||||||
auto found = level->entities->getAllInRadius(pos, radius);
|
auto found = level->entities->getAllInRadius(pos, radius);
|
||||||
lua::createtable(L, found.size(), 0);
|
lua::createtable(L, found.size(), 0);
|
||||||
for (size_t i = 0; i < found.size(); i++) {
|
for (size_t i = 0; i < found.size(); i++) {
|
||||||
const auto& entity = found[i];
|
lua::pushinteger(L, found[i]->getUID());
|
||||||
lua::pushinteger(L, entity.getUID());
|
|
||||||
lua::rawseti(L, i + 1);
|
lua::rawseti(L, i + 1);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
#include "frontend/hud.hpp"
|
#include "frontend/hud.hpp"
|
||||||
#include "objects/Entities.hpp"
|
#include "objects/Entities.hpp"
|
||||||
#include "objects/Entity.hpp"
|
#include "objects/Entity.hpp"
|
||||||
|
|
@ -13,7 +11,7 @@ namespace scripting {
|
||||||
extern Hud* hud;
|
extern Hud* hud;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::optional<Entity> get_entity(lua::State* L, int idx) {
|
inline Entity* get_entity(lua::State* L, int idx) {
|
||||||
auto id = lua::tointeger(L, idx);
|
auto id = lua::tointeger(L, idx);
|
||||||
auto level = scripting::controller->getLevel();
|
auto level = scripting::controller->getLevel();
|
||||||
return level->entities->get(id);
|
return level->entities->get(id);
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,12 @@
|
||||||
#include "engine/Engine.hpp"
|
#include "engine/Engine.hpp"
|
||||||
#include "Entity.hpp"
|
#include "Entity.hpp"
|
||||||
#include "EntityDef.hpp"
|
#include "EntityDef.hpp"
|
||||||
#include "graphics/commons/Model.hpp"
|
|
||||||
#include "graphics/core/DrawContext.hpp"
|
|
||||||
#include "graphics/core/LineBatch.hpp"
|
|
||||||
#include "graphics/render/ModelBatch.hpp"
|
|
||||||
#include "logic/scripting/scripting.hpp"
|
#include "logic/scripting/scripting.hpp"
|
||||||
#include "maths/FrustumCulling.hpp"
|
|
||||||
#include "maths/rays.hpp"
|
#include "maths/rays.hpp"
|
||||||
#include "maths/util.hpp"
|
#include "maths/util.hpp"
|
||||||
#include "physics/PhysicsSolver.hpp"
|
#include "physics/PhysicsSolver.hpp"
|
||||||
#include "world/Level.hpp"
|
#include "world/Level.hpp"
|
||||||
|
|
||||||
#include <entt/entity/registry.hpp>
|
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
@ -28,8 +22,7 @@
|
||||||
static debug::Logger logger("entities");
|
static debug::Logger logger("entities");
|
||||||
|
|
||||||
Entities::Entities(Level& level)
|
Entities::Entities(Level& level)
|
||||||
: registry(std::make_unique<entt::registry>()),
|
: level(level),
|
||||||
level(level),
|
|
||||||
sensorsTickClock(20, 3),
|
sensorsTickClock(20, 3),
|
||||||
updateTickClock(20, 3) {
|
updateTickClock(20, 3) {
|
||||||
}
|
}
|
||||||
|
|
@ -40,12 +33,12 @@ void Entities::setAssets(Assets& assets) {
|
||||||
this->assets = &assets;
|
this->assets = &assets;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Entity> Entities::get(entityid_t id) {
|
Entity* Entities::get(entityid_t id) {
|
||||||
const auto& found = entities.find(id);
|
const auto& found = entities.find(id);
|
||||||
if (found != entities.end() && registry->valid(found->second)) {
|
if (found != entities.end()) {
|
||||||
return Entity(*this, id, *registry, found->second);
|
return found->second.get();
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
entityid_t Entities::spawn(
|
entityid_t Entities::spawn(
|
||||||
|
|
@ -81,33 +74,30 @@ entityid_t Entities::spawn(
|
||||||
throw std::runtime_error(ss.str());
|
throw std::runtime_error(ss.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto entity = registry->create();
|
std::unique_ptr<rigging::Skeleton> skeletonInstance;
|
||||||
entities[id] = entity;
|
|
||||||
uids[entity] = id;
|
|
||||||
|
|
||||||
registry->emplace<EntityId>(entity, id, def);
|
|
||||||
const auto& tsf = registry->emplace<Transform>(
|
|
||||||
entity,
|
|
||||||
position,
|
|
||||||
glm::vec3(1.0f),
|
|
||||||
glm::mat3(1.0f),
|
|
||||||
glm::mat4(1.0f),
|
|
||||||
true
|
|
||||||
);
|
|
||||||
auto& body = registry->emplace<Rigidbody>(
|
|
||||||
entity,
|
|
||||||
true,
|
|
||||||
Hitbox {id, def.bodyType, position, def.hitbox * 0.5f},
|
|
||||||
std::vector<Sensor> {}
|
|
||||||
);
|
|
||||||
body.initialize(def, id, *this);
|
|
||||||
|
|
||||||
auto& scripting = registry->emplace<ScriptComponents>(entity);
|
|
||||||
if (assets) {
|
if (assets) {
|
||||||
registry->emplace<rigging::Skeleton>(
|
skeletonInstance = std::make_unique<rigging::Skeleton>(
|
||||||
entity, skeleton ? skeleton->instance() : rigging::Skeleton(nullptr)
|
skeleton ? skeleton->instance() : rigging::Skeleton(nullptr)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
auto& entity = *(entities[id] = std::make_unique<Entity>(
|
||||||
|
*this,
|
||||||
|
EntityId {id, def},
|
||||||
|
Transform {
|
||||||
|
position, glm::vec3(1.0f), glm::mat3(1.0f), glm::mat4(1.0f), true
|
||||||
|
},
|
||||||
|
Rigidbody {
|
||||||
|
true,
|
||||||
|
Hitbox {id, def.bodyType, position, def.hitbox * 0.5f},
|
||||||
|
std::vector<Sensor> {}
|
||||||
|
},
|
||||||
|
std::move(skeletonInstance)
|
||||||
|
));
|
||||||
|
const auto& tsf = entity.getTransform();
|
||||||
|
auto& body = entity.getRigidbody();
|
||||||
|
body.initialize(def, id, *this);
|
||||||
|
|
||||||
|
auto& scripting = entity.getScripting();
|
||||||
|
|
||||||
for (auto& instance : def.components) {
|
for (auto& instance : def.components) {
|
||||||
auto component = std::make_unique<UserComponent>(
|
auto component = std::make_unique<UserComponent>(
|
||||||
|
|
@ -118,7 +108,7 @@ entityid_t Entities::spawn(
|
||||||
dv::value componentsMap = nullptr;
|
dv::value componentsMap = nullptr;
|
||||||
if (saved != nullptr) {
|
if (saved != nullptr) {
|
||||||
componentsMap = saved["comps"];
|
componentsMap = saved["comps"];
|
||||||
loadEntity(saved, get(id).value());
|
loadEntity(saved, entity);
|
||||||
}
|
}
|
||||||
body.hitbox.position = tsf.pos;
|
body.hitbox.position = tsf.pos;
|
||||||
scripting::on_entity_spawn(
|
scripting::on_entity_spawn(
|
||||||
|
|
@ -144,7 +134,7 @@ void Entities::loadEntity(const dv::value& map) {
|
||||||
spawn(def, {}, nullptr, map, uid);
|
spawn(def, {}, nullptr, map, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entities::loadEntity(const dv::value& map, Entity entity) {
|
void Entities::loadEntity(const dv::value& map, Entity& entity) {
|
||||||
auto& transform = entity.getTransform();
|
auto& transform = entity.getTransform();
|
||||||
auto& body = entity.getRigidbody();
|
auto& body = entity.getRigidbody();
|
||||||
auto skeleton = entity.getSkeleton();
|
auto skeleton = entity.getSkeleton();
|
||||||
|
|
@ -175,12 +165,12 @@ std::optional<Entities::RaycastResult> Entities::rayCast(
|
||||||
const RaycastSettings& settings
|
const RaycastSettings& settings
|
||||||
) {
|
) {
|
||||||
Ray ray(start, dir);
|
Ray ray(start, dir);
|
||||||
auto view = registry->view<EntityId, Transform, Rigidbody>();
|
|
||||||
|
|
||||||
entityid_t foundUID = 0;
|
entityid_t foundUID = 0;
|
||||||
glm::ivec3 foundNormal;
|
glm::ivec3 foundNormal;
|
||||||
|
|
||||||
for (auto [entity, eid, transform, body] : view.each()) {
|
for (const auto& [uid, entity] : entities) {
|
||||||
|
const auto& eid = entity->getID();
|
||||||
|
const auto& body = entity->getRigidbody();
|
||||||
const auto& hitbox = body.hitbox;
|
const auto& hitbox = body.hitbox;
|
||||||
if (eid.uid == settings.ignoredUid || !body.enabled ||
|
if (eid.uid == settings.ignoredUid || !body.enabled ||
|
||||||
(settings.solidEntitiesOnly && !eid.def.solid) ||
|
(settings.solidEntitiesOnly && !eid.def.solid) ||
|
||||||
|
|
@ -227,40 +217,38 @@ void Entities::onSave(const Entity& entity) {
|
||||||
scripting::on_entity_save(entity);
|
scripting::on_entity_save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
dv::value Entities::serialize(const std::vector<Entity>& entities) {
|
dv::value Entities::serialize(const std::vector<Entity*>& entities) {
|
||||||
auto list = dv::list();
|
auto list = dv::list();
|
||||||
for (auto& entity : entities) {
|
for (auto entity : entities) {
|
||||||
const EntityId& eid = entity.getID();
|
const EntityId& eid = entity->getID();
|
||||||
if (!entity.getDef().save.enabled || eid.destroyFlag) {
|
if (!entity->getDef().save.enabled || eid.destroyFlag) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
level.entities->onSave(entity);
|
level.entities->onSave(*entity);
|
||||||
if (!eid.destroyFlag) {
|
if (!eid.destroyFlag) {
|
||||||
list.add(entity.serialize());
|
list.add(entity->serialize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entities::despawn(std::vector<Entity> entities) {
|
void Entities::despawn(const std::vector<Entity*>& entities) {
|
||||||
for (auto& entity : entities) {
|
for (auto entity : entities) {
|
||||||
entity.destroy();
|
entity->destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entities::clean() {
|
void Entities::clean() {
|
||||||
for (auto it = entities.begin(); it != entities.end();) {
|
for (auto it = entities.begin(); it != entities.end();) {
|
||||||
if (!registry->get<EntityId>(it->second).destroyFlag) {
|
if (!it->second->getID().destroyFlag) {
|
||||||
++it;
|
++it;
|
||||||
} else {
|
} else {
|
||||||
auto& rigidbody = registry->get<Rigidbody>(it->second);
|
auto& rigidbody = it->second->getRigidbody();
|
||||||
// todo: refactor
|
// todo: refactor
|
||||||
auto physics = level.physics.get();
|
auto physics = level.physics.get();
|
||||||
for (auto& sensor : rigidbody.sensors) {
|
for (auto& sensor : rigidbody.sensors) {
|
||||||
physics->removeSensor(&sensor);
|
physics->removeSensor(&sensor);
|
||||||
}
|
}
|
||||||
uids.erase(it->second);
|
|
||||||
registry->destroy(it->second);
|
|
||||||
it = entities.erase(it);
|
it = entities.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -309,15 +297,16 @@ void Entities::preparePhysics(float delta) {
|
||||||
auto part = sensorsTickClock.convertPart(i);
|
auto part = sensorsTickClock.convertPart(i);
|
||||||
auto allParts = sensorsTickClock.getParts();
|
auto allParts = sensorsTickClock.getParts();
|
||||||
|
|
||||||
auto view = registry->view<EntityId, Transform, Rigidbody>();
|
for (const auto& [uid, entity] : entities) {
|
||||||
for (auto [entity, eid, transform, rigidbody] : view.each()) {
|
const auto& eid = entity->getID();
|
||||||
|
auto& rigidbody = entity->getRigidbody();
|
||||||
if (!rigidbody.enabled) {
|
if (!rigidbody.enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((eid.uid + part) % allParts != 0) {
|
if ((eid.uid + part) % allParts != 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
updateSensors(rigidbody, transform, sensors);
|
updateSensors(rigidbody, entity->getTransform(), sensors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -325,8 +314,9 @@ void Entities::preparePhysics(float delta) {
|
||||||
hitboxes.clear();
|
hitboxes.clear();
|
||||||
solidHitboxes.clear();
|
solidHitboxes.clear();
|
||||||
|
|
||||||
auto view = registry->view<EntityId, Rigidbody>();
|
for (const auto& [uid, entity] : entities) {
|
||||||
for (auto [entity, eid, rigidbody] : view.each()) {
|
const auto& eid = entity->getID();
|
||||||
|
auto& rigidbody = entity->getRigidbody();
|
||||||
auto bodyType = rigidbody.hitbox.type;
|
auto bodyType = rigidbody.hitbox.type;
|
||||||
if (eid.destroyFlag || !rigidbody.enabled) {
|
if (eid.destroyFlag || !rigidbody.enabled) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -350,13 +340,15 @@ void Entities::preparePhysics(float delta) {
|
||||||
void Entities::updatePhysics(float delta) {
|
void Entities::updatePhysics(float delta) {
|
||||||
preparePhysics(delta);
|
preparePhysics(delta);
|
||||||
|
|
||||||
auto view = registry->view<EntityId, Transform, Rigidbody>();
|
|
||||||
auto physics = level.physics.get();
|
auto physics = level.physics.get();
|
||||||
|
|
||||||
int substeps = std::max<int>(std::min<int>(delta * 1000, 200), 8);
|
int substeps = std::max<int>(std::min<int>(delta * 1000, 200), 8);
|
||||||
physics->step(*level.chunks, delta, substeps);
|
physics->step(*level.chunks, delta, substeps);
|
||||||
|
|
||||||
for (auto [entity, eid, transform, rigidbody] : view.each()) {
|
for (const auto& [uid, entity] : entities) {
|
||||||
|
const auto& eid = entity->getID();
|
||||||
|
auto& transform = entity->getTransform();
|
||||||
|
auto& rigidbody = entity->getRigidbody();
|
||||||
if (!rigidbody.enabled ||
|
if (!rigidbody.enabled ||
|
||||||
rigidbody.hitbox.type == BodyType::STATIC) {
|
rigidbody.hitbox.type == BodyType::STATIC) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -373,11 +365,11 @@ void Entities::updatePhysics(float delta) {
|
||||||
}
|
}
|
||||||
if (hitbox.grounded && !hitbox.prevGrounded) {
|
if (hitbox.grounded && !hitbox.prevGrounded) {
|
||||||
scripting::on_entity_grounded(
|
scripting::on_entity_grounded(
|
||||||
*get(eid.uid), glm::length(hitbox.prevVelocity - hitbox.velocity)
|
*entity, glm::length(hitbox.prevVelocity - hitbox.velocity)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!hitbox.grounded && hitbox.prevGrounded) {
|
if (!hitbox.grounded && hitbox.prevGrounded) {
|
||||||
scripting::on_entity_fall(*get(eid.uid));
|
scripting::on_entity_fall(*entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -395,8 +387,12 @@ void Entities::update(float delta) {
|
||||||
updatePhysics(delta);
|
updatePhysics(delta);
|
||||||
scripting::on_entities_physics_update(delta);
|
scripting::on_entities_physics_update(delta);
|
||||||
|
|
||||||
auto view = registry->view<Transform, rigging::Skeleton>();
|
for (const auto& [uid, entity] : entities) {
|
||||||
for (auto [entity, transform, skeleton] : view.each()) {
|
if (!entity->getSkeleton()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto& transform = entity->getTransform();
|
||||||
|
auto& skeleton = *entity->getSkeleton();
|
||||||
if (transform.dirty) {
|
if (transform.dirty) {
|
||||||
transform.refresh();
|
transform.refresh();
|
||||||
}
|
}
|
||||||
|
|
@ -409,193 +405,33 @@ void Entities::update(float delta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void debug_render_skeleton(
|
|
||||||
LineBatch& batch,
|
|
||||||
const rigging::Bone* bone,
|
|
||||||
const rigging::Skeleton& skeleton
|
|
||||||
) {
|
|
||||||
size_t pindex = bone->getIndex();
|
|
||||||
for (auto& sub : bone->getBones()) {
|
|
||||||
size_t sindex = sub->getIndex();
|
|
||||||
const auto& matrices = skeleton.calculated.matrices;
|
|
||||||
batch.line(
|
|
||||||
glm::vec3(matrices[pindex] * glm::vec4(0, 0, 0, 1)),
|
|
||||||
glm::vec3(matrices[sindex] * glm::vec4(0, 0, 0, 1)),
|
|
||||||
glm::vec4(0, 0.5f, 0, 1)
|
|
||||||
);
|
|
||||||
debug_render_skeleton(batch, sub.get(), skeleton);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static glm::vec3 calc_extent(
|
|
||||||
const Transform& transform,
|
|
||||||
const Rigidbody& rigidbody,
|
|
||||||
const rigging::Skeleton& skeleton
|
|
||||||
) {
|
|
||||||
const auto& size = transform.size;
|
|
||||||
float scale = glm::max(
|
|
||||||
glm::abs(size.x), glm::max(glm::abs(size.y), glm::abs(size.z))
|
|
||||||
);
|
|
||||||
return glm::max(
|
|
||||||
rigidbody.hitbox.getHalfSize(), glm::vec3(skeleton.boundsRadius * scale)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool check_frustum(
|
|
||||||
const Frustum& frustum,
|
|
||||||
const Transform& transform,
|
|
||||||
const Rigidbody& rigidbody,
|
|
||||||
const rigging::Skeleton& skeleton
|
|
||||||
) {
|
|
||||||
glm::vec3 ext = calc_extent(transform, rigidbody, skeleton);
|
|
||||||
return frustum.isBoxVisible(transform.pos - ext, transform.pos + ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Entities::renderDebug(
|
|
||||||
LineBatch& batch, const Frustum* frustum, const DrawContext& pctx, entityid_t fpsEntity
|
|
||||||
) {
|
|
||||||
{
|
|
||||||
auto ctx = pctx.sub(&batch);
|
|
||||||
ctx.setLineWidth(1);
|
|
||||||
auto view = registry->view<Transform, Rigidbody, rigging::Skeleton>();
|
|
||||||
for (auto [entity, transform, rigidbody, skeleton] : view.each()) {
|
|
||||||
const auto& hitbox = rigidbody.hitbox;
|
|
||||||
if (frustum && !check_frustum(*frustum, transform, rigidbody, skeleton)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
batch.box(
|
|
||||||
hitbox.position, hitbox.getHalfSize() * 2.0f, glm::vec4(1.0f)
|
|
||||||
);
|
|
||||||
glm::vec3 ext = calc_extent(transform, rigidbody, skeleton);
|
|
||||||
batch.box(
|
|
||||||
transform.pos, ext * 2.0f, glm::vec4(0.0f, 0.0f, 1.0f, 1.0f)
|
|
||||||
);
|
|
||||||
for (auto& sensor : rigidbody.sensors) {
|
|
||||||
if (sensor.type != SensorType::AABB) continue;
|
|
||||||
batch.box(
|
|
||||||
sensor.calculated.aabb.center(),
|
|
||||||
sensor.calculated.aabb.size(),
|
|
||||||
glm::vec4(1.0f, 1.0f, 0.0f, 1.0f)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
auto view = registry->view<EntityId, Transform, Rigidbody, rigging::Skeleton>();
|
|
||||||
auto ctx = pctx.sub(&batch);
|
|
||||||
ctx.setDepthTest(false);
|
|
||||||
ctx.setDepthMask(false);
|
|
||||||
ctx.setLineWidth(2);
|
|
||||||
for (auto [entity, eid, transform, rigidbody, skeleton] : view.each()) {
|
|
||||||
if (eid.uid == fpsEntity) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto config = skeleton.config;
|
|
||||||
if (config == nullptr) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (frustum && !check_frustum(*frustum, transform, rigidbody, skeleton)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto bone = config->getRoot();
|
|
||||||
debug_render_skeleton(batch, bone, skeleton);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Entities::render(
|
|
||||||
const Assets& assets,
|
|
||||||
ModelBatch& batch,
|
|
||||||
const Frustum* frustum,
|
|
||||||
entityid_t fpsEntity
|
|
||||||
) {
|
|
||||||
auto view = registry->view<EntityId, Transform, rigging::Skeleton, Rigidbody>();
|
|
||||||
for (auto [entity, eid, transform, skeleton, rigidbody] : view.each()) {
|
|
||||||
if (eid.uid == fpsEntity) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const auto& def = eid.def;
|
|
||||||
const auto& pos = transform.pos;
|
|
||||||
const auto& size = transform.size;
|
|
||||||
const auto& rigConfig = skeleton.config;
|
|
||||||
if (rigConfig == nullptr) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (frustum && !check_frustum(*frustum, transform, rigidbody, skeleton)) {
|
|
||||||
if (!skeleton.boundsDirty || !skeleton.visible) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
rigConfig->updateBounds(assets, skeleton, transform.rot, pos, size);
|
|
||||||
if (!check_frustum(*frustum, transform, rigidbody, skeleton)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rigConfig->render(
|
|
||||||
assets,
|
|
||||||
batch,
|
|
||||||
skeleton,
|
|
||||||
def.lightingMode,
|
|
||||||
transform.rot,
|
|
||||||
pos,
|
|
||||||
size,
|
|
||||||
def.translucent
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Entities::updateCulling(const Frustum* frustum, entityid_t fpsEntity) {
|
|
||||||
auto view = registry->view<EntityId, Transform, rigging::Skeleton, Rigidbody>();
|
|
||||||
for (auto [entity, eid, transform, skeleton, rigidbody] : view.each()) {
|
|
||||||
if (frustum == nullptr || eid.uid == fpsEntity) {
|
|
||||||
skeleton.culled = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
skeleton.culled = !check_frustum(*frustum, transform, rigidbody, skeleton);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Entities::hasBlockingInside(AABB aabb) {
|
bool Entities::hasBlockingInside(AABB aabb) {
|
||||||
constexpr float eps = 0.05f;
|
constexpr float eps = 0.05f;
|
||||||
auto view = registry->view<EntityId, Rigidbody>();
|
for (const auto& [uid, entity] : entities) {
|
||||||
for (auto [entity, eid, body] : view.each()) {
|
AABB bodyAABB(entity->getRigidbody().hitbox.getAABB());
|
||||||
AABB bodyAABB(body.hitbox.getAABB());
|
|
||||||
bodyAABB.scale(glm::vec3(1.0f - eps));
|
bodyAABB.scale(glm::vec3(1.0f - eps));
|
||||||
if (eid.def.blocking && aabb.intersects(bodyAABB)) {
|
if (entity->getID().def.blocking && aabb.intersects(bodyAABB)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Entity> Entities::getAllInside(AABB aabb) {
|
std::vector<Entity*> Entities::getAllInside(AABB aabb) {
|
||||||
std::vector<Entity> collected;
|
std::vector<Entity*> collected;
|
||||||
auto view = registry->view<EntityId, Transform>();
|
for (const auto& [uid, entity] : entities) {
|
||||||
for (auto [entity, eid, transform] : view.each()) {
|
if (!entity->getID().destroyFlag && aabb.contains(entity->getTransform().pos)) {
|
||||||
if (!eid.destroyFlag && aabb.contains(transform.pos)) {
|
collected.push_back(entity.get());
|
||||||
const auto& found = uids.find(entity);
|
|
||||||
if (found == uids.end()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (auto wrapper = get(found->second)) {
|
|
||||||
collected.push_back(*wrapper);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return collected;
|
return collected;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Entity> Entities::getAllInRadius(glm::vec3 center, float radius) {
|
std::vector<Entity*> Entities::getAllInRadius(glm::vec3 center, float radius) {
|
||||||
std::vector<Entity> collected;
|
std::vector<Entity*> collected;
|
||||||
auto view = registry->view<Transform>();
|
for (const auto& [uid, entity] : entities) {
|
||||||
for (auto [entity, transform] : view.each()) {
|
if (glm::distance2(entity->getTransform().pos, center) <= radius * radius) {
|
||||||
if (glm::distance2(transform.pos, center) <= radius * radius) {
|
collected.push_back(entity.get());
|
||||||
const auto& found = uids.find(entity);
|
|
||||||
if (found == uids.end()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (auto wrapper = get(found->second)) {
|
|
||||||
collected.push_back(*wrapper);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return collected;
|
return collected;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "constants.hpp"
|
#include "constants.hpp"
|
||||||
|
#include "Entity.hpp"
|
||||||
#include "physics/Hitbox.hpp"
|
#include "physics/Hitbox.hpp"
|
||||||
#include "Transform.hpp"
|
#include "Transform.hpp"
|
||||||
#include "Rigidbody.hpp"
|
#include "Rigidbody.hpp"
|
||||||
|
|
@ -13,19 +14,13 @@
|
||||||
#include "typedefs.hpp"
|
#include "typedefs.hpp"
|
||||||
#include "util/Clock.hpp"
|
#include "util/Clock.hpp"
|
||||||
|
|
||||||
#include <entt/entity/fwd.hpp>
|
#include <map>
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
struct EntityDef;
|
struct EntityDef;
|
||||||
|
|
||||||
class Level;
|
class Level;
|
||||||
class Assets;
|
class Assets;
|
||||||
class Entity;
|
class Entity;
|
||||||
class LineBatch;
|
|
||||||
class ModelBatch;
|
|
||||||
class Frustum;
|
|
||||||
class Entities;
|
|
||||||
class DrawContext;
|
|
||||||
|
|
||||||
namespace rigging {
|
namespace rigging {
|
||||||
struct Skeleton;
|
struct Skeleton;
|
||||||
|
|
@ -33,10 +28,8 @@ namespace rigging {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Entities final {
|
class Entities final {
|
||||||
std::unique_ptr<entt::registry> registry;
|
|
||||||
Level& level;
|
Level& level;
|
||||||
std::unordered_map<entityid_t, entt::entity> entities;
|
std::map<entityid_t, std::unique_ptr<Entity>> entities;
|
||||||
std::unordered_map<entt::entity, entityid_t> uids;
|
|
||||||
entityid_t nextID = 1;
|
entityid_t nextID = 1;
|
||||||
util::Clock sensorsTickClock;
|
util::Clock sensorsTickClock;
|
||||||
util::Clock updateTickClock;
|
util::Clock updateTickClock;
|
||||||
|
|
@ -57,18 +50,6 @@ public:
|
||||||
void updatePhysics(float delta);
|
void updatePhysics(float delta);
|
||||||
void update(float delta);
|
void update(float delta);
|
||||||
|
|
||||||
void renderDebug(
|
|
||||||
LineBatch& batch, const Frustum* frustum, const DrawContext& ctx, entityid_t fpsEntity
|
|
||||||
);
|
|
||||||
void render(
|
|
||||||
const Assets& assets,
|
|
||||||
ModelBatch& batch,
|
|
||||||
const Frustum* frustum,
|
|
||||||
entityid_t fpsEntity
|
|
||||||
);
|
|
||||||
|
|
||||||
void updateCulling(const Frustum* frustum, entityid_t fpsEntity);
|
|
||||||
|
|
||||||
entityid_t spawn(
|
entityid_t spawn(
|
||||||
const EntityDef& def,
|
const EntityDef& def,
|
||||||
glm::vec3 position,
|
glm::vec3 position,
|
||||||
|
|
@ -77,7 +58,7 @@ public:
|
||||||
entityid_t uid = 0
|
entityid_t uid = 0
|
||||||
);
|
);
|
||||||
|
|
||||||
std::optional<Entity> get(entityid_t id);
|
Entity* get(entityid_t id);
|
||||||
|
|
||||||
struct RaycastSettings {
|
struct RaycastSettings {
|
||||||
/// @param ignore Ignored entity uid
|
/// @param ignore Ignored entity uid
|
||||||
|
|
@ -111,19 +92,24 @@ public:
|
||||||
|
|
||||||
void loadEntities(dv::value map);
|
void loadEntities(dv::value map);
|
||||||
void loadEntity(const dv::value& map);
|
void loadEntity(const dv::value& map);
|
||||||
void loadEntity(const dv::value& map, Entity entity);
|
void loadEntity(const dv::value& map, Entity& entity);
|
||||||
void onSave(const Entity& entity);
|
void onSave(const Entity& entity);
|
||||||
bool hasBlockingInside(AABB aabb);
|
bool hasBlockingInside(AABB aabb);
|
||||||
std::vector<Entity> getAllInside(AABB aabb);
|
std::vector<Entity*> getAllInside(AABB aabb);
|
||||||
std::vector<Entity> getAllInRadius(glm::vec3 center, float radius);
|
std::vector<Entity*> getAllInRadius(glm::vec3 center, float radius);
|
||||||
void despawn(entityid_t id);
|
void despawn(entityid_t id);
|
||||||
void despawn(std::vector<Entity> entities);
|
void despawn(const std::vector<Entity*>& entities);
|
||||||
dv::value serialize(const std::vector<Entity>& entities);
|
dv::value serialize(const std::vector<Entity*>& entities);
|
||||||
|
|
||||||
void setNextID(entityid_t id) {
|
void setNextID(entityid_t id) {
|
||||||
nextID = id;
|
nextID = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const std::map<entityid_t, std::unique_ptr<Entity>>& getEntities(
|
||||||
|
) const {
|
||||||
|
return entities;
|
||||||
|
}
|
||||||
|
|
||||||
inline size_t size() const {
|
inline size_t size() const {
|
||||||
return entities.size();
|
return entities.size();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,58 +8,62 @@
|
||||||
#include "ScriptComponents.hpp"
|
#include "ScriptComponents.hpp"
|
||||||
#include "Transform.hpp"
|
#include "Transform.hpp"
|
||||||
|
|
||||||
#include <entt/entt.hpp>
|
|
||||||
|
|
||||||
static inline std::string SAVED_DATA_VARNAME = "SAVED_DATA";
|
static inline std::string SAVED_DATA_VARNAME = "SAVED_DATA";
|
||||||
|
|
||||||
|
Entity::Entity(
|
||||||
|
Entities& entities,
|
||||||
|
EntityId id,
|
||||||
|
Transform transform,
|
||||||
|
Rigidbody rigidbody,
|
||||||
|
std::unique_ptr<rigging::Skeleton> skeleton
|
||||||
|
)
|
||||||
|
: entities(entities),
|
||||||
|
id(std::move(id)),
|
||||||
|
transform(std::move(transform)),
|
||||||
|
rigidbody(std::move(rigidbody)),
|
||||||
|
skeleton(std::move(skeleton)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Entity::~Entity() = default;
|
||||||
|
|
||||||
void Entity::setInterpolatedPosition(const glm::vec3& position) {
|
void Entity::setInterpolatedPosition(const glm::vec3& position) {
|
||||||
if (auto skeleton = getSkeleton()) {
|
if (skeleton) {
|
||||||
skeleton->interpolation.refresh(position);
|
skeleton->interpolation.refresh(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 Entity::getInterpolatedPosition() const {
|
glm::vec3 Entity::getInterpolatedPosition() const {
|
||||||
if (auto skeleton = getSkeleton()) {
|
if (skeleton) {
|
||||||
const auto& interpolation = skeleton->interpolation;
|
const auto& interpolation = skeleton->interpolation;
|
||||||
if (interpolation.isEnabled() && interpolation.isRefreshed()) {
|
if (interpolation.isEnabled() && interpolation.isRefreshed()) {
|
||||||
return interpolation.getCurrent();
|
return interpolation.getCurrent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getTransform().pos;
|
return transform.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::setInterpolatedRotation(const glm::quat& rotation) {
|
void Entity::setInterpolatedRotation(const glm::quat& rotation) {
|
||||||
if (auto skeleton = getSkeleton()) {
|
if (skeleton) {
|
||||||
skeleton->rotationInterpolation.refresh(rotation);
|
skeleton->rotationInterpolation.refresh(rotation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::destroy() {
|
void Entity::destroy() {
|
||||||
if (isValid()) {
|
entities.despawn(id.uid);
|
||||||
entities.despawn(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rigging::Skeleton* Entity::getSkeleton() const {
|
|
||||||
return registry.try_get<rigging::Skeleton>(entity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Entity::setRig(std::shared_ptr<const rigging::SkeletonConfig> rigConfig) {
|
void Entity::setRig(std::shared_ptr<const rigging::SkeletonConfig> rigConfig) {
|
||||||
auto& skeleton = registry.get<rigging::Skeleton>(entity);
|
if (skeleton) {
|
||||||
skeleton.setConfig(std::move(rigConfig));
|
skeleton->setConfig(std::move(rigConfig));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dv::value Entity::serialize() const {
|
dv::value Entity::serialize() const {
|
||||||
const auto& eid = getID();
|
const auto& def = id.def;
|
||||||
const auto& def = eid.def;
|
|
||||||
const auto& transform = getTransform();
|
|
||||||
const auto& rigidbody = getRigidbody();
|
|
||||||
const auto& scripts = getScripting();
|
|
||||||
auto skeleton = getSkeleton();
|
|
||||||
|
|
||||||
auto root = dv::object();
|
auto root = dv::object();
|
||||||
root["def"] = def.name;
|
root["def"] = def.name;
|
||||||
root["uid"] = eid.uid;
|
root["uid"] = id.uid;
|
||||||
|
|
||||||
root[COMP_TRANSFORM] = transform.serialize();
|
root[COMP_TRANSFORM] = transform.serialize();
|
||||||
root[COMP_RIGIDBODY] =
|
root[COMP_RIGIDBODY] =
|
||||||
|
|
@ -75,9 +79,9 @@ dv::value Entity::serialize() const {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!scripts.components.empty()) {
|
if (!scripting.components.empty()) {
|
||||||
auto& compsMap = root.object("comps");
|
auto& compsMap = root.object("comps");
|
||||||
for (auto& comp : scripts.components) {
|
for (auto& comp : scripting.components) {
|
||||||
if (comp->env == nullptr) {
|
if (comp->env == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -89,45 +93,11 @@ dv::value Entity::serialize() const {
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
EntityId& Entity::getID() const {
|
void Entity::setPlayer(int64_t player) {
|
||||||
return registry.get<EntityId>(entity);
|
if (id.player == player) {
|
||||||
}
|
|
||||||
|
|
||||||
bool Entity::isValid() const {
|
|
||||||
return registry.valid(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
Transform& Entity::getTransform() const {
|
|
||||||
return registry.get<Transform>(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ScriptComponents& Entity::getScripting() const {
|
|
||||||
return registry.get<ScriptComponents>(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
const EntityDef& Entity::getDef() const {
|
|
||||||
return registry.get<EntityId>(entity).def;
|
|
||||||
}
|
|
||||||
|
|
||||||
Rigidbody& Entity::getRigidbody() const {
|
|
||||||
return registry.get<Rigidbody>(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
entityid_t Entity::getUID() const {
|
|
||||||
return registry.get<EntityId>(entity).uid;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t Entity::getPlayer() const {
|
|
||||||
return registry.get<EntityId>(entity).player;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Entity::setPlayer(int64_t id) {
|
|
||||||
auto& eid = registry.get<EntityId>(entity);
|
|
||||||
if (eid.player == id) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
eid.player = id;
|
id.player = player;
|
||||||
scripting::on_entity_player_set(*this, id);
|
scripting::on_entity_player_set(*this, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,17 @@
|
||||||
|
|
||||||
#include "typedefs.hpp"
|
#include "typedefs.hpp"
|
||||||
#include "data/dv_fwd.hpp"
|
#include "data/dv_fwd.hpp"
|
||||||
|
#include "Transform.hpp"
|
||||||
|
#include "Rigidbody.hpp"
|
||||||
|
#include "ScriptComponents.hpp"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <entt/fwd.hpp>
|
|
||||||
#include <glm/vec3.hpp>
|
#include <glm/vec3.hpp>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
|
||||||
class Entities;
|
class Entities;
|
||||||
struct EntityDef;
|
struct EntityDef;
|
||||||
struct Transform;
|
|
||||||
struct Rigidbody;
|
|
||||||
struct ScriptComponents;
|
|
||||||
|
|
||||||
inline std::string COMP_TRANSFORM = "transform";
|
inline std::string COMP_TRANSFORM = "transform";
|
||||||
inline std::string COMP_RIGIDBODY = "rigidbody";
|
inline std::string COMP_RIGIDBODY = "rigidbody";
|
||||||
|
|
@ -32,42 +32,77 @@ struct EntityId {
|
||||||
|
|
||||||
class Entity {
|
class Entity {
|
||||||
Entities& entities;
|
Entities& entities;
|
||||||
entityid_t id;
|
EntityId id;
|
||||||
entt::registry& registry;
|
Transform transform;
|
||||||
const entt::entity entity;
|
Rigidbody rigidbody;
|
||||||
|
ScriptComponents scripting;
|
||||||
|
std::unique_ptr<rigging::Skeleton> skeleton;
|
||||||
public:
|
public:
|
||||||
Entity(
|
Entity(
|
||||||
Entities& entities,
|
Entities& entities,
|
||||||
entityid_t id,
|
EntityId id,
|
||||||
entt::registry& registry,
|
Transform transform,
|
||||||
const entt::entity entity
|
Rigidbody rigidbody,
|
||||||
)
|
std::unique_ptr<rigging::Skeleton> skeleton
|
||||||
: entities(entities), id(id), registry(registry), entity(entity) {
|
);
|
||||||
}
|
|
||||||
|
Entity(const Entity&) = delete;
|
||||||
|
Entity& operator=(const Entity&) = delete;
|
||||||
|
|
||||||
|
~Entity();
|
||||||
|
|
||||||
dv::value serialize() const;
|
dv::value serialize() const;
|
||||||
|
|
||||||
EntityId& getID() const;
|
EntityId& getID() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
const EntityId& getID() const {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
bool isValid() const;
|
const EntityDef& getDef() const {
|
||||||
|
return id.def;
|
||||||
|
}
|
||||||
|
|
||||||
const EntityDef& getDef() const;
|
Transform& getTransform() {
|
||||||
|
return transform;
|
||||||
|
}
|
||||||
|
const Transform& getTransform() const {
|
||||||
|
return transform;
|
||||||
|
}
|
||||||
|
|
||||||
Transform& getTransform() const;
|
Rigidbody& getRigidbody() {
|
||||||
|
return rigidbody;
|
||||||
|
}
|
||||||
|
const Rigidbody& getRigidbody() const {
|
||||||
|
return rigidbody;
|
||||||
|
}
|
||||||
|
|
||||||
Rigidbody& getRigidbody() const;
|
ScriptComponents& getScripting() {
|
||||||
|
return scripting;
|
||||||
|
}
|
||||||
|
const ScriptComponents& getScripting() const {
|
||||||
|
return scripting;
|
||||||
|
}
|
||||||
|
|
||||||
ScriptComponents& getScripting() const;
|
rigging::Skeleton* getSkeleton() {
|
||||||
|
return skeleton.get();
|
||||||
rigging::Skeleton* getSkeleton() const;
|
}
|
||||||
|
const rigging::Skeleton* getSkeleton() const {
|
||||||
|
return skeleton.get();
|
||||||
|
}
|
||||||
|
|
||||||
void setRig(std::shared_ptr<const rigging::SkeletonConfig> rigConfig);
|
void setRig(std::shared_ptr<const rigging::SkeletonConfig> rigConfig);
|
||||||
|
|
||||||
entityid_t getUID() const;
|
entityid_t getUID() const {
|
||||||
|
return id.uid;
|
||||||
|
}
|
||||||
|
|
||||||
int64_t getPlayer() const;
|
int64_t getPlayer() const {
|
||||||
|
return id.player;
|
||||||
|
}
|
||||||
|
|
||||||
void setPlayer(int64_t id);
|
void setPlayer(int64_t player);
|
||||||
|
|
||||||
void setInterpolatedPosition(const glm::vec3& position);
|
void setInterpolatedPosition(const glm::vec3& position);
|
||||||
|
|
||||||
|
|
@ -75,9 +110,5 @@ public:
|
||||||
|
|
||||||
void setInterpolatedRotation(const glm::quat& rotation);
|
void setInterpolatedRotation(const glm::quat& rotation);
|
||||||
|
|
||||||
entt::entity getHandler() const {
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroy();
|
void destroy();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ void Player::updateSelectedEntity() {
|
||||||
|
|
||||||
void Player::postUpdate() {
|
void Player::postUpdate() {
|
||||||
auto entity = level.entities->get(eid);
|
auto entity = level.entities->get(eid);
|
||||||
if (!entity.has_value()) {
|
if (entity == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto& hitbox = entity->getRigidbody().hitbox;
|
auto& hitbox = entity->getRigidbody().hitbox;
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,7 @@ template <void (*callback)(const Entity&, size_t, entityid_t)>
|
||||||
static sensorcallback create_sensor_callback(Entities& entities) {
|
static sensorcallback create_sensor_callback(Entities& entities) {
|
||||||
return [&entities](auto entityid, auto index, auto otherid) {
|
return [&entities](auto entityid, auto index, auto otherid) {
|
||||||
if (auto entity = entities.get(entityid)) {
|
if (auto entity = entities.get(entityid)) {
|
||||||
if (entity->isValid()) {
|
callback(*entity, index, otherid);
|
||||||
callback(*entity, index, otherid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
#include "physics/Hitbox.hpp"
|
#include "physics/Hitbox.hpp"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <entt/fwd.hpp>
|
|
||||||
|
|
||||||
class Entities;
|
class Entities;
|
||||||
struct EntityDef;
|
struct EntityDef;
|
||||||
|
|
@ -13,9 +12,9 @@ struct Rigidbody {
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
Hitbox hitbox;
|
Hitbox hitbox;
|
||||||
std::vector<Sensor> sensors;
|
std::vector<Sensor> sensors;
|
||||||
float mass;
|
float mass = 1.0f;
|
||||||
float elasticity;
|
float elasticity = 0.0f;
|
||||||
bool selectable;
|
bool selectable = false;
|
||||||
|
|
||||||
dv::value serialize(bool saveVelocity, bool saveBodySettings) const;
|
dv::value serialize(bool saveVelocity, bool saveBodySettings) const;
|
||||||
void deserialize(const dv::value& root);
|
void deserialize(const dv::value& root);
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ struct Transform {
|
||||||
glm::mat4 combined;
|
glm::mat4 combined;
|
||||||
bool dirty = true;
|
bool dirty = true;
|
||||||
|
|
||||||
glm::vec3 displayPos;
|
glm::vec3 displayPos {};
|
||||||
glm::vec3 displaySize;
|
glm::vec3 displaySize {};
|
||||||
|
|
||||||
dv::value serialize() const;
|
dv::value serialize() const;
|
||||||
void deserialize(const dv::value& root);
|
void deserialize(const dv::value& root);
|
||||||
|
|
|
||||||
|
|
@ -11,17 +11,9 @@
|
||||||
"zlib",
|
"zlib",
|
||||||
"luajit",
|
"luajit",
|
||||||
"libvorbis",
|
"libvorbis",
|
||||||
"entt",
|
|
||||||
"gtest",
|
"gtest",
|
||||||
"curl",
|
"curl",
|
||||||
"freetype",
|
"freetype",
|
||||||
"openssl"
|
"openssl"
|
||||||
],
|
|
||||||
"builtin-baseline": "802d61d714db2714e3fefcfc59447431166b8367",
|
|
||||||
"overrides": [
|
|
||||||
{
|
|
||||||
"name": "entt",
|
|
||||||
"version": "3.16.0"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue