Skip to content
Snippets Groups Projects
Commit dd745317 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

cut down on log spam using guards

parent 3defb561
No related branches found
No related tags found
No related merge requests found
Pipeline #3408 failed
......@@ -163,18 +163,15 @@ namespace fggl::gfx::ogl4 {
shader->setUniformMtx(shader->uniform("view"), viewMatrix);
shader->setUniformMtx(shader->uniform("projection"), projectionMatrix);
auto* material = world.tryGet<fggl::gfx::PhongMaterial>(entity);
if ( material == nullptr) {
shader->setUniformF(shader->uniform("material.ambient"), math::vec3(0.05F, 0.05F, 0.05F));
shader->setUniformF(shader->uniform("material.diffuse"), math::vec3(0.5F, 0.5F, 0.5F));
shader->setUniformF(shader->uniform("material.specular"), math::vec3(0.7F, 0.7F, 0.7F));
shader->setUniformF(shader->uniform("material.shininess"), .078125F);
} else {
shader->setUniformF(shader->uniform("material.ambient"), material->ambient);
shader->setUniformF(shader->uniform("material.diffuse"), material->diffuse);
shader->setUniformF(shader->uniform("material.specular"), material->specular);
shader->setUniformF(shader->uniform("material.shininess"), material->shininess);
// material detection with fallback
auto* material = &gfx::DEFAULT_MATERIAL;
if ( world.has<PhongMaterial>(entity) ) {
material = world.get<PhongMaterial>(entity);
}
shader->setUniformF(shader->uniform("material.ambient"), material->ambient);
shader->setUniformF(shader->uniform("material.diffuse"), material->diffuse);
shader->setUniformF(shader->uniform("material.specular"), material->specular);
shader->setUniformF(shader->uniform("material.shininess"), material->shininess);
auto lightPosIdx = shader->uniform("lightPos");
if ( lightPosIdx != -1 ) {
......
......@@ -199,11 +199,11 @@ namespace fggl::phys::bullet {
}
static void handleCollisionCallbacks(ecs3::World* world, ecs3::entity_t owner, ecs3::entity_t other) {
auto* callbacks = world->tryGet<CollisionCallbacks>(owner);
if ( callbacks == nullptr ) {
if ( !world->has<CollisionCallbacks>(owner) ) {
return;
}
auto* callbacks = world->tryGet<CollisionCallbacks>(owner);
auto* cache = world->tryGet<CollisionCache>(owner);
if ( cache != nullptr ) {
auto itr = cache->collisions.find(other);
......
......@@ -233,6 +233,17 @@ namespace fggl::ecs3::prototype {
return entities;
}
template<typename ...Cs>
bool has(entity_t entityIdx) const {
if ( !alive(entityIdx)) {
return false;
}
std::vector<ecs::component_type_t> key;
(key.push_back(Component<Cs>::typeID()), ...);
return m_entities.at(entityIdx).hasComponents(key);
}
template<typename C>
C *add(entity_t entity_id) {
assert( alive(entity_id) && "attempted to add component on null entity" );
......
......@@ -29,11 +29,6 @@
namespace fggl::gfx {
constexpr math::vec3 DEFAULT_AMBIENT { 0.05F, 0.05F, 0.05F};
constexpr math::vec3 DEFAULT_DIFFUSE { 0.5F, 0.5F, 0.5F};
constexpr math::vec3 DEFAULT_SPECULAR { 0.7F, 0.7F, 0.7F};
constexpr float DEFAULT_SHININESS = .078125F;
struct PhongMaterial {
constexpr static const char* name = "gfx::material";
math::vec3 ambient;
......@@ -42,6 +37,19 @@ namespace fggl::gfx {
float shininess;
};
constexpr math::vec3 DEFAULT_AMBIENT { 0.05F, 0.05F, 0.05F};
constexpr math::vec3 DEFAULT_DIFFUSE { 0.5F, 0.5F, 0.5F};
constexpr math::vec3 DEFAULT_SPECULAR { 0.7F, 0.7F, 0.7F};
constexpr float DEFAULT_SHININESS = .078125F;
constexpr PhongMaterial DEFAULT_MATERIAL {
DEFAULT_AMBIENT,
DEFAULT_DIFFUSE,
DEFAULT_SPECULAR,
DEFAULT_SHININESS
};
enum class LightType {
Directional,
Point,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment