Skip to content

Commit a744af3

Browse files
progress
1 parent dcacc9d commit a744af3

File tree

18 files changed

+103
-61
lines changed

18 files changed

+103
-61
lines changed

assets/shaders/grid.vert

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ layout(binding = 1) uniform Ubo {
1717

1818
void main()
1919
{
20-
mat4 MVP = ubo.projMats[gl_ViewIndex] * ubo.viewMat[gl_ViewIndex];
20+
mat4 cameraMat = mat4(1.0);
21+
cameraMat[3] = vec4(ubo.camPos, 1.0);
22+
23+
mat4 MVP = ubo.projMats[gl_ViewIndex] * ubo.viewMat[gl_ViewIndex] * cameraMat;
2124

2225
int idx = indices[gl_VertexIndex];
2326
vec3 position = pos[idx] * gridSize;
2427

25-
mat4 iViewMat = inverse(ubo.viewMat[gl_ViewIndex]);
28+
mat4 iViewMat = inverse(ubo.viewMat[gl_ViewIndex]) * cameraMat;
2629
camPos = vec2(iViewMat[3][0], iViewMat[3][2]);
2730

2831
position.x += camPos.x;

assets/shaders/light_cube.vert

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ const vec3 cubeVertices[36] =
5555

5656
void main()
5757
{
58+
mat4 cameraMat = mat4(1.0);
59+
cameraMat[3] = vec4(ubo.camPos, 1.0);
60+
5861
gl_Position =
5962
ubo.projMats[gl_ViewIndex] *
6063
ubo.viewMat[gl_ViewIndex] *
64+
cameraMat *
6165
vec4(pushConst.objPos + cubeVertices[gl_VertexIndex], 1.0);
6266
}

assets/shaders/normal_lighting.frag

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#version 450
2+
23
#extension GL_EXT_debug_printf : enable
34

45
layout(location = 0) in vec3 inColor;

assets/shaders/pbr.vert

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ layout(push_constant) uniform PushConst {
2626

2727
void main()
2828
{
29+
mat4 cameraMat = mat4(1.0);
30+
cameraMat[3] = vec4(commonUbo.camPos, 1.0);
31+
2932
vec3 worldPos = inPos + pushConst.objPos;
3033
outWorldPos = worldPos;
3134
outNormal = mat3(individualUbo.modelMat) * inNormal;
3235

3336
gl_Position =
3437
commonUbo.projMats[gl_ViewIndex] *
3538
commonUbo.viewMats[gl_ViewIndex] *
39+
cameraMat *
3640
individualUbo.modelMat *
3741
vec4(worldPos, 1.0);
3842

engine/include/tsengine/ecs/components/rigid_body_component.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct RigidBodyComponent : public Component
88
{
99
float velocity;
1010

11-
RigidBodyComponent(const float velocity = 1.f) : velocity{velocity}
11+
RigidBodyComponent(const float velocity_ = 1.f) : velocity{velocity_}
1212
{}
1313
};
1414
}

engine/include/tsengine/ecs/ecs.hpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <memory>
1414
#include <typeindex>
1515

16+
// TODO: common abi
17+
1618
namespace ts
1719
{
1820
using Id = uint32_t;
@@ -67,8 +69,9 @@ class Entity
6769
void kill();
6870

6971
// TODO: hash tags
70-
void tag(const std::string& tag);
71-
bool hasTag(const std::string& tag) const;
72+
void setTag(const std::string& tag);
73+
std::string getTag() const;
74+
bool hasTag(const std::string& tag = "") const;
7275
void group(const std::string& group);
7376
bool belongsToGroup(const std::string& group) const;
7477

@@ -149,7 +152,7 @@ inline class Registry
149152
void tagEntity(const Entity entity, const std::string& tag);
150153
bool entityHasTag(const Entity entity, const std::string& tag) const;
151154
Entity getEntityByTag(const std::string& tag) const { return entityPerTag.at(tag); }
152-
std::string_view getTagByEntity(const Entity entity) const { return tagPerEntity.at(entity.getId()); }
155+
std::string getTagByEntity(const Entity entity) const { return tagPerEntity.at(entity.getId()); }
153156
void removeEntityTag(const Entity entity);
154157

155158
void groupEntity(const Entity entity, const std::string& group);
@@ -182,11 +185,16 @@ inline void Entity::kill()
182185
mpRegistry->killEntity(*this);
183186
}
184187

185-
inline void Entity::tag(const std::string& tag)
188+
inline void Entity::setTag(const std::string& tag)
186189
{
187190
mpRegistry->tagEntity(*this, tag);
188191
}
189192

193+
inline std::string Entity::getTag() const
194+
{
195+
return mpRegistry->getTagByEntity(*this);
196+
}
197+
190198
inline bool Entity::hasTag(const std::string& tag) const
191199
{
192200
return mpRegistry->entityHasTag(*this, tag);
@@ -372,10 +380,7 @@ inline void Registry::tagEntity(const Entity entity, const std::string& tag)
372380

373381
inline bool Registry::entityHasTag(const Entity entity, const std::string& tag) const
374382
{
375-
if (tagPerEntity.find(entity.getId()) == tagPerEntity.end())
376-
{
377-
return false;
378-
}
383+
TS_ASSERT(tagPerEntity.find(entity.getId()) != tagPerEntity.end(), "Entity doesn't have tag");
379384

380385
return entityPerTag.find(tag)->second == entity;
381386
}
@@ -440,6 +445,10 @@ inline void Registry::removeEntityGroup(const Entity entity)
440445
template<typename TSystem, typename ...TArgs>
441446
void Registry::addSystem(TArgs&& ...args)
442447
{
448+
const auto index = std::type_index(typeid(TSystem));
449+
450+
TS_ASSERT(systems.find(index) == systems.end(), "System is already added");
451+
443452
const auto newSystem = std::make_shared<TSystem>(std::forward<TArgs>(args)...);
444453
systems.insert(std::make_pair(std::type_index(typeid(TSystem)), newSystem));
445454
}

engine/include/tsengine/logger.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
#define TS_ERR(message) ts::logger::error(message, __FILE__, FUNCTION_SIGNATURE, __LINE__)
1414

1515
// TODO: default message
16-
1716
#ifndef NDEBUG
18-
#define TS_ASSERT(condition, ...) \
19-
if (!condition) \
20-
{ \
21-
TS_ERR(__VA_ARGS__); \
22-
} \
17+
#define TS_ASSERT(condition, ...) \
18+
if (!(condition)) \
19+
{ \
20+
ts::logger::warning(__VA_ARGS__, __FILE__, FUNCTION_SIGNATURE, __LINE__, true); \
21+
}
2322

2423
#else
25-
#define TS_ASSERT(condition, message)
24+
#define TS_ASSERT(condition, ...)
2625
#endif
2726

2827
namespace ts
@@ -39,7 +38,8 @@ void warning(
3938
const char* message,
4039
const char* fileName,
4140
const char* functionName,
42-
int lineNumber);
41+
int lineNumber,
42+
bool debugBreak = false);
4343

4444
void error(
4545
const char* message,

engine/include/tsengine/utils.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ class Exception : public std::exception
6363
template<typename DerivedClass>
6464
class Singleton
6565
{
66-
NOT_COPYABLE(Singleton);
67-
NOT_MOVEABLE(Singleton);
66+
NOT_COPYABLE_AND_MOVEABLE(Singleton);
6867

6968
public:
7069
static auto& getInstance()

engine/src/core/asset_store.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ namespace
1919
// TODO: avoid the same files
2020
void AssetStore::Models::load()
2121
{
22-
const auto entities = gRegistry.getSystem<AssetStore>().getSystemEntities();
23-
for (const auto entity : entities)
22+
for (const auto entity : gRegistry.getSystem<AssetStore>().getSystemEntities())
2423
{
25-
auto meshComponent = entity.getComponent<MeshComponent>();
24+
auto& meshComponent = entity.getComponent<MeshComponent>();
2625
const auto& fileName = meshComponent.assetName;
2726

2827
tinyobj::attrib_t attrib;

engine/src/core/context.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ Context& Context::createOpenXrContext()
3030
initXrSystemInfo();
3131
isXrBlendModeAvailable();
3232

33+
mIsXrContextCreated = true;
34+
3335
return *this;
3436
}
3537

3638
void Context::createVulkanContext()
3739
{
40+
TS_ASSERT(mIsXrContextCreated, "XrContext should be firstly created");
41+
3842
vulkanloader::connectWithLoader();
3943
vulkanloader::loadExportFunction();
4044
vulkanloader::loadGlobalLevelFunctions();
@@ -616,6 +620,9 @@ Context::~Context()
616620

617621
void Context::createXrInstance()
618622
{
623+
TS_ASSERT(mGameName.size() > 0, "setGameName() should be firstly called");
624+
TS_ASSERT(mGameName.size() > 0, "setGameName() should be firstly called");
625+
619626
XrApplicationInfo appInfo{
620627
.applicationVersion = static_cast<uint32_t>(XR_MAKE_VERSION(0, 1, 0)),
621628
.engineName = ENGINE_NAME,

0 commit comments

Comments
 (0)