working sockets
This commit is contained in:
@@ -320,6 +320,14 @@ namespace Gen
|
||||
return mat;
|
||||
}
|
||||
|
||||
Mat4 RotationFromQuaternion(const Vec4& quaternion)
|
||||
{
|
||||
Mat4 mat;
|
||||
bx::Quaternion quat{quaternion.x, quaternion.y, quaternion.z, quaternion.w};
|
||||
bx::mtxFromQuaternion(mat.M, quat);
|
||||
return mat;
|
||||
}
|
||||
|
||||
float Magnitude(const Vec4& vec)
|
||||
{
|
||||
return bx::sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z + vec.w * vec.w);
|
||||
|
||||
@@ -75,6 +75,7 @@ namespace Gen
|
||||
|
||||
Vec3 EulerFromRotation(const Mat4& rotation);
|
||||
Mat4 RotationFromEuler(const Vec3& euler);
|
||||
Mat4 RotationFromQuaternion(const Vec4& quaternion);
|
||||
|
||||
float DotProduct(Vec3 a, Vec3 b);
|
||||
Vec3 CrossProduct(Vec3 a, Vec3 b);
|
||||
|
||||
@@ -113,6 +113,7 @@ namespace Game
|
||||
needReset |= Cubes.Setup(storagePtr, needReset);
|
||||
needReset |= Tests.Setup(storagePtr, needReset);
|
||||
needReset |= PuzzleTiles.Setup(storagePtr, needReset);
|
||||
needReset |= PuzzleTileCovers.Setup(storagePtr, needReset);
|
||||
needReset |= UIQuads.Setup(storagePtr, needReset);
|
||||
needReset |= LevelEntities.Setup(storagePtr, needReset);
|
||||
|
||||
@@ -179,6 +180,7 @@ namespace Game
|
||||
|
||||
UIQuads.Count = 0;
|
||||
PuzzleTiles.Count = 0;
|
||||
PuzzleTileCovers.Count = 0;
|
||||
for (int32_t i = 0; i < BX_COUNTOF(Puzzles); ++i)
|
||||
{
|
||||
if (Puzzles[i].Data.ID != UINT16_MAX)
|
||||
@@ -324,6 +326,7 @@ namespace Game
|
||||
Cubes.Render(models, materials, textures);
|
||||
Tests.Render(models, materials, textures);
|
||||
PuzzleTiles.Render(models, materials, textures);
|
||||
PuzzleTileCovers.Render(models, materials, textures);
|
||||
if (player.InteractionM == InteractionMode::ReadTablet)
|
||||
{
|
||||
UIQuads.Render(models, materials, textures);
|
||||
@@ -358,6 +361,14 @@ namespace Game
|
||||
auto& tile = level.PuzzleTiles.Get(TileHandles[i]);
|
||||
tile.EData.MaterialHandle = EMaterial::Default;
|
||||
|
||||
for (int32_t j = 0; j < Puzzle::Config::MaxCoversInTile; ++j)
|
||||
{
|
||||
int32_t idx = i * Puzzle::Config::MaxCoversInTile + j;
|
||||
CoverHandles[idx] = level.PuzzleTileCovers.New();
|
||||
auto& cover = level.PuzzleTileCovers.Get(CoverHandles[idx]);
|
||||
cover.EData.Visible = false;
|
||||
}
|
||||
|
||||
UIPlacedCards[i] = level.UIQuads.New();
|
||||
auto& quad = level.UIQuads.Get(UIPlacedCards[i]);
|
||||
quad.EData.ModelH = GameRendering::Get().GetModelHandleFromPath("models/plane.glb");
|
||||
@@ -518,11 +529,12 @@ namespace Game
|
||||
auto& quad = level.UIQuads.Get(UIPlacedCards[cardIdx]);
|
||||
|
||||
bool isValid = Puzzle::IsValid(card.RefCard);
|
||||
auto& staticCard = isValid ? staticCards[card.RefCard.Idx] : staticCards[0];
|
||||
|
||||
// World Tile
|
||||
tile.EData.Visible = IsActive;
|
||||
tile.EData.ModelH =
|
||||
isValid ? staticCards[card.RefCard.Idx].BaseModelHandle : staticCards[0].BaseModelHandle;
|
||||
tile.EData.ModelH = staticCard.BaseModelHandle;
|
||||
|
||||
tile.EData.DotColor = visuals.TileDotColor;
|
||||
tile.EData.BaseColor = visuals.TileBaseColor;
|
||||
|
||||
@@ -538,6 +550,22 @@ namespace Game
|
||||
tile.EData.Transform.Position = cardPos;
|
||||
bx::mtxRotateY(tile.EData.Transform.Rotation.M, card.Rotation * bx::kPi * 0.5f);
|
||||
|
||||
// Covers
|
||||
if (IsValid(staticCard.BaseModelHandle))
|
||||
{
|
||||
auto& model = GameRendering::Get().Models[staticCard.BaseModelHandle.ModelIdx];
|
||||
for (int32_t i = 0; i < model.SocketCount; ++i)
|
||||
{
|
||||
auto& cover =
|
||||
level.PuzzleTileCovers.Get(CoverHandles[cardIdx * Puzzle::Config::MaxCoversInTile + i]);
|
||||
cover.EData.Visible = true;
|
||||
cover.EData.ModelH = staticCard.Sockets[i].Model;
|
||||
cover.EData.Transform = tile.EData.Transform;
|
||||
Gen::TranslateLocal(cover.EData.Transform, model.Sockets[i].Pos);
|
||||
Gen::RotateLocal(cover.EData.Transform, Gen::EulerFromRotation(model.Sockets[i].Rot));
|
||||
}
|
||||
}
|
||||
|
||||
// UI Quad
|
||||
quad.EData.Visible = isValid && IsActive;
|
||||
quad.EData.TextureHandle =
|
||||
|
||||
@@ -57,6 +57,12 @@ namespace Game
|
||||
EntityRenderData EData;
|
||||
};
|
||||
|
||||
ENTITY_HANDLE(PuzzleTileCoverHandle);
|
||||
struct PuzzleTileCover
|
||||
{
|
||||
EntityRenderData EData;
|
||||
};
|
||||
|
||||
ENTITY_HANDLE(UIQuadEntityHandle);
|
||||
struct UIQuadEntity
|
||||
{
|
||||
@@ -148,6 +154,7 @@ namespace Game
|
||||
Gen::PuzzleData Data;
|
||||
Gen::Vec3 WorldPosition;
|
||||
PuzzleTileEntityHandle TileHandles[Puzzle::Config::MaxCardsInPuzzle];
|
||||
PuzzleTileCoverHandle CoverHandles[Puzzle::Config::MaxCardsInPuzzle * Puzzle::Config::MaxCoversInTile];
|
||||
UIQuadEntityHandle UIPlacedCards[Puzzle::Config::MaxCardsInPuzzle];
|
||||
UIQuadEntityHandle UIAvailableCards[Puzzle::Config::MaxAvailableStacks * UIAvailableCardMaxStackPreview];
|
||||
Gen::PuzPos DraggedCard{-1, -1};
|
||||
@@ -164,8 +171,9 @@ namespace Game
|
||||
public:
|
||||
EntityManager<Cube, CubeHandle, 1024> Cubes;
|
||||
EntityManager<TestEntity, TestEntityHandle, 32> Tests;
|
||||
EntityManager<PuzzleTileEntity, PuzzleTileEntityHandle, 1024> PuzzleTiles;
|
||||
EntityManager<UIQuadEntity, UIQuadEntityHandle, 1024> UIQuads;
|
||||
EntityManager<PuzzleTileEntity, PuzzleTileEntityHandle, Puzzle::Config::MaxTilesTotal> PuzzleTiles;
|
||||
EntityManager<PuzzleTileCover, PuzzleTileCoverHandle, Puzzle::Config::MaxCoversTotal> PuzzleTileCovers;
|
||||
EntityManager<UIQuadEntity, UIQuadEntityHandle, Puzzle::Config::MaxTilesInPuzzle * 2> UIQuads;
|
||||
EntityManager<LevelEntity, LevelEntityHandle, 64> LevelEntities;
|
||||
|
||||
CubeHandle PlayerOutsideViewCube;
|
||||
@@ -173,7 +181,7 @@ namespace Game
|
||||
|
||||
public:
|
||||
Gen::StaticPuzzleData PuzzleData;
|
||||
WorldPuzzle Puzzles[3];
|
||||
WorldPuzzle Puzzles[Puzzle::Config::MaxVisiblePuzzles];
|
||||
|
||||
public:
|
||||
void Setup(GameData& data);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include "Gen.h"
|
||||
#include "Global.h"
|
||||
#include "Log.h"
|
||||
#include "Mesh.h"
|
||||
@@ -92,6 +93,39 @@ namespace Game
|
||||
}
|
||||
mesh.VertexBuffer = bgfx::createVertexBuffer(vbMem, mesh.VertLayout);
|
||||
}
|
||||
|
||||
for (auto& node : model.nodes)
|
||||
{
|
||||
if (bx::strFindI(node.name.c_str(), "_slot_").getLength() > 0)
|
||||
{
|
||||
if (mesh.SocketCount >= mesh.MaxSocketCount)
|
||||
{
|
||||
LOG_WARN("Too many sockets on mesh!");
|
||||
break;
|
||||
}
|
||||
auto& socket = mesh.Sockets[mesh.SocketCount];
|
||||
if (node.translation.size() >= 3)
|
||||
{
|
||||
socket.Pos.x = node.translation[0];
|
||||
socket.Pos.y = node.translation[1];
|
||||
socket.Pos.z = node.translation[2];
|
||||
}
|
||||
if (node.rotation.size() >= 4)
|
||||
{
|
||||
socket.Rot = Gen::RotationFromQuaternion({static_cast<float>(node.rotation[0]),
|
||||
static_cast<float>(node.rotation[1]),
|
||||
static_cast<float>(node.rotation[2]),
|
||||
static_cast<float>(node.rotation[3])});
|
||||
}
|
||||
if (node.matrix.size() >= 0)
|
||||
{
|
||||
LOG_WARN("TODO: support matrix!");
|
||||
}
|
||||
bx::strCopy(&socket.Name[0], socket.MaxSocketNameLength, node.name.c_str());
|
||||
++mesh.SocketCount;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,16 +12,19 @@ namespace Puzzle
|
||||
|
||||
struct Config
|
||||
{
|
||||
static constexpr uint32_t MaxVisiblePuzzles = 3;
|
||||
static constexpr uint32_t CardSize = 2;
|
||||
static constexpr uint32_t NodesPerCard = CardSize * CardSize;
|
||||
static constexpr uint32_t MaxElementsPerTile = 4;
|
||||
static constexpr uint32_t MaxPuzzleSizeCards = 16;
|
||||
static constexpr uint32_t MaxCardsInPuzzle = MaxPuzzleSizeCards * MaxPuzzleSizeCards;
|
||||
static constexpr uint32_t MaxPuzzleSizeTiles = 16 * CardSize;
|
||||
static constexpr uint32_t MaxTilesInPuzzle = MaxPuzzleSizeTiles * MaxPuzzleSizeTiles;
|
||||
static constexpr uint32_t MaxTilesTotal = MaxTilesInPuzzle * MaxVisiblePuzzles;
|
||||
static constexpr uint32_t MaxAvailableStacks = 16;
|
||||
static constexpr uint32_t MaxGoalPositions = 16;
|
||||
static constexpr float CardScaleWorld = 10.0f;
|
||||
static constexpr uint32_t MaxCoversInTile = 8;
|
||||
static constexpr uint32_t MaxCoversTotal = MaxCoversInTile * MaxTilesTotal;
|
||||
};
|
||||
|
||||
void Setup();
|
||||
|
||||
@@ -421,14 +421,17 @@ namespace Tools
|
||||
|
||||
Tools::ModelDropdown(card.BaseModelHandle);
|
||||
Tools::TextureDropdown(card.BoardTextureHandle);
|
||||
if (ImGui::TreeNodeEx("Covers"))
|
||||
if (IsValid(card.BaseModelHandle))
|
||||
{
|
||||
Tools::ModelDropdown(card.NorthCoverHandle, "North Cover");
|
||||
Tools::ModelDropdown(card.EastCoverHandle, "East Cover");
|
||||
Tools::ModelDropdown(card.SouthCoverHandle, "South Cover");
|
||||
Tools::ModelDropdown(card.WestCoverHandle, "West Cover");
|
||||
|
||||
ImGui::TreePop();
|
||||
auto& mdl = rendering.Models[card.BaseModelHandle.ModelIdx];
|
||||
if (mdl.SocketCount > 0 && ImGui::TreeNodeEx("Slots"))
|
||||
{
|
||||
for (int32_t sIdx = 0; sIdx < mdl.SocketCount; ++sIdx)
|
||||
{
|
||||
Tools::ModelDropdown(card.Sockets[sIdx].Model, mdl.Sockets[sIdx].Name);
|
||||
}
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::Text("Card");
|
||||
|
||||
BIN
src/game/data/puzzles/0.pzl
LFS
BIN
src/game/data/puzzles/0.pzl
LFS
Binary file not shown.
Binary file not shown.
@@ -82,6 +82,11 @@ enum PuzzleElementType(u8)
|
||||
Bridge GameName("Bridge") ShortName("#")
|
||||
}
|
||||
|
||||
type CardSocket
|
||||
{
|
||||
ModelHandle Model
|
||||
}
|
||||
|
||||
type StaticPuzzleCard
|
||||
{
|
||||
PuzzleElementType Elements Arr(4)
|
||||
@@ -90,6 +95,7 @@ type StaticPuzzleCard
|
||||
ModelHandle EastCoverHandle
|
||||
ModelHandle SouthCoverHandle
|
||||
ModelHandle WestCoverHandle
|
||||
CardSocket Sockets Arr(16)
|
||||
TextureHandle ModelTextureHandle
|
||||
TextureHandle BoardTextureHandle
|
||||
}
|
||||
|
||||
@@ -32,12 +32,23 @@ namespace Game
|
||||
Gen::TextureHandle TexHandle;
|
||||
};
|
||||
|
||||
struct ModelSocket
|
||||
{
|
||||
static constexpr uint16_t MaxSocketNameLength = 64;
|
||||
Gen::Vec3 Pos;
|
||||
Gen::Mat4 Rot;
|
||||
char Name[MaxSocketNameLength]{};
|
||||
};
|
||||
|
||||
struct Model
|
||||
{
|
||||
static constexpr uint16_t MaxSocketCount = 16;
|
||||
bgfx::VertexBufferHandle VertexBuffer = {bgfx::kInvalidHandle};
|
||||
bgfx::IndexBufferHandle IndexBuffer = {bgfx::kInvalidHandle};
|
||||
bgfx::VertexLayout VertLayout;
|
||||
Gen::ModelHandle Handle;
|
||||
uint16_t SocketCount = 0;
|
||||
ModelSocket Sockets[MaxSocketCount];
|
||||
};
|
||||
|
||||
struct Material
|
||||
|
||||
Reference in New Issue
Block a user