Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Merge internal branch into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jsanmiya committed Feb 24, 2017
2 parents 7905786 + 08945fc commit cc75ab3
Show file tree
Hide file tree
Showing 25 changed files with 398 additions and 368 deletions.
82 changes: 20 additions & 62 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,49 +38,14 @@ set(corgi_DEBUG ON)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)

# Directory which contains the source for 3rd party libraries.
if(NOT DEFINED third_party_root)
get_filename_component(
third_party_root "${CMAKE_CURRENT_LIST_DIR}/../../../../external"
REALPATH)
endif()

# Directory which contains source for FPL libraries.
if(NOT DEFINED fpl_root)
get_filename_component(
fpl_root "${CMAKE_CURRENT_LIST_DIR}/../../libs" REALPATH)
endif()

# If the dependencies directory exists, assume this is the root directory for
# all libraries required by this project.
if(NOT DEFINED dependencies_root)
set(dependencies_root "${CMAKE_CURRENT_SOURCE_DIR}/dependencies")
if(EXISTS "${dependencies_root}")
set(third_party_root "${dependencies_root}")
set(fpl_root "${dependencies_root}")
endif()
endif()

set(dependencies_gtest_dir "${fpl_root}/googletest"
CACHE PATH "Directory containing the GoogleTest library.")
set(dependencies_flatbuffers_dir "${fpl_root}/flatbuffers"
CACHE PATH "Directory containing the Flatbuffers library.")
set(dependencies_fplutil_dir "${fpl_root}/fplutil"
CACHE PATH "Directory containing the fplutil library.")
set(dependencies_breadboard_dir "${fpl_root}/breadboard"
CACHE PATH "Directory containing the breadboard library.")
set(dependencies_fplbase_dir "${fpl_root}/fplbase"
CACHE PATH "Directory containing the FPLBase library.")
set(dependencies_mathfu_dir "${fpl_root}/mathfu"
CACHE PATH "Directory containing the MathFu library.")
set(dependencies_motive_dir "${fpl_root}/motive"
CACHE PATH "Directory containing the motive animation library.")
set(dependencies_bulletphysics_distr_dir "${third_party_root}/bulletphysics"
CACHE PATH "Directory containing the Bullet Physics distribution.")
# NOTE: This is only required as the breadboard module library and CORGI's
# component library have a circular dependency.
set(dependencies_corgi_dir "${CMAKE_CURRENT_LIST_DIR}"
CACHE PATH "Directory containing the CORGI library.")
# Call fplutil to get locations of dependencies and set common build settings.
# Extra MSVC compiler flags:
# /wd4244: 'conversion' conversion from 'type1' to 'type2'
# /wd4512: 'class' : assignment operator could not be generated
# /wd4800: 'type' : forcing value to bool 'true' or 'false'
include("cmake/find_fplutil.cmake")
include("${fplutil_dir}/buildutil/cmake_common.txt")
set_common_build_variables("/wd4244 /wd4512 /wd4800")

# Temporary files (like object files) created while compiling projects.
set(tmp_dir ${CMAKE_CURRENT_BINARY_DIR}/obj)
Expand All @@ -100,25 +65,9 @@ set(corgi_SRCS
# Includes for this project.
include_directories(src include)

# Detect clang
if(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
set(CMAKE_COMPILER_IS_CLANGXX 1)
endif()

# Compiler flags.
set(C_FLAGS_WARNINGS "")
if(MSVC)
set(C_FLAGS_WARNINGS
"/W4 /WX /wd4065 /wd4355 /wd4127 /wd4244 /wd4512 /wd4800")
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR
CMAKE_COMPILER_IS_CLANGXX)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra")
if(fplbase_debug_markers)
add_definitions(-DFPLBASE_ENABLE_DEBUG_MARKERS)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_FLAGS_WARNINGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${C_FLAGS_WARNINGS}")
set(CMAKE_CXX_FLAGS_DEFAULT "${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS_DEFAULT "${CMAKE_C_FLAGS}")

# Library targets.
add_library(corgi ${corgi_SRCS})
Expand All @@ -134,7 +83,7 @@ if (corgi_build_component_library)
endif()

set(CORGI_COMPONENT_LIBRARY_FLATBUFFERS_GENERATED_INCLUDES_DIR
${CMAKE_SOURCE_DIR}/${CMAKE_FILES_DIRECTORY}/include/component_library)
${CMAKE_CURRENT_BINARY_DIR}/include/component_library)
file(GLOB_RECURSE
CORGI_COMPONENT_LIBRARY_FLATBUFFERS_SCHEMAS
${CORGI_COMPONENT_LIBRARY_DIR}/schemas/*.fbs)
Expand Down Expand Up @@ -189,9 +138,12 @@ if (corgi_build_component_library)
${CORGI_COMPONENT_LIBRARY_DIR}/include/corgi_component_library)
set(corgi_component_library_SRCS
${CORGI_COMPONENT_LIBRARY_INCLUDE_DIR}/animation.h
${CORGI_COMPONENT_LIBRARY_INCLUDE_DIR}/bullet_physics.h
${CORGI_COMPONENT_LIBRARY_INCLUDE_DIR}/camera_interface.h
${CORGI_COMPONENT_LIBRARY_INCLUDE_DIR}/common_services.h
${CORGI_COMPONENT_LIBRARY_INCLUDE_DIR}/component_utils.h
${CORGI_COMPONENT_LIBRARY_INCLUDE_DIR}/default_entity_factory.h
${CORGI_COMPONENT_LIBRARY_INCLUDE_DIR}/default_entity_factory.inc
${CORGI_COMPONENT_LIBRARY_INCLUDE_DIR}/entity_factory.h
${CORGI_COMPONENT_LIBRARY_INCLUDE_DIR}/graph.h
${CORGI_COMPONENT_LIBRARY_INCLUDE_DIR}/meta.h
Expand Down Expand Up @@ -221,6 +173,9 @@ if (corgi_build_component_library)
include_directories(${dependencies_fplutil_dir}/libfplutil/include)
include_directories(${dependencies_motive_dir}/include)
include_directories(${dependencies_mathfu_dir}/include)
if(WIN32)
include_directories(${dependencies_fplbase_dir}/external/include)
endif()

set_compiler_flags_for_external_libraries()
add_library(corgi_component_library ${corgi_component_library_SRCS})
Expand Down Expand Up @@ -249,7 +204,9 @@ option(
if(corgi_build_tests)
set(GUNIT_INCDIR "${dependencies_gtest_dir}/include")
set(GTEST_LIBDIR "${dependencies_gtest_dir}")
set_compiler_flags_for_external_libraries()
add_subdirectory("${dependencies_gtest_dir}" ${tmp_dir}/googletest)
restore_compiler_flags()

include(${GTEST_LIBDIR}/cmake/internal_utils.cmake)
config_compiler_and_linker()
Expand All @@ -259,6 +216,7 @@ if(corgi_build_tests)

include_directories(${GUNIT_INCDIR}
${CMAKE_CURRENT_SOURCE_DIR})
fpl_absolute_include_dir(${dependencies_gtest_dir})

function(test_executable name libs)
cxx_executable_with_flags(${name}_test "${cxx_default}"
Expand Down
41 changes: 41 additions & 0 deletions cmake/find_fplutil.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Find the fplutil directory and set it in `fplutil_dir`.
#
# We search some standard locations, such as
# (1) the cached variable ${dependencies_fplutil_dir}, which can be specified
# on the command line,
# cmake -Ddependencies_fplutil_dir=your_fplutil_directory
# (2) under ${fpl_root}, which is another cached variable that can be
# specified on the command line,
# cmake -Dfpl_root=your_fpl_root_directory
# (3) the "dependencies" directory that gets created when cloning from GitHub,
# (4) several levels up in the directory tree.
#
# Notes
# -----
# - fplutil is the project where we keep all our shared code, so the code in
# this file (which locates fplutil) can unfortunately not be shared.
# - Since this file is duplicated in all FPL projects (except fplutil itself),
# please copy new versions to all FPL projects whenever you make a change.

set(fplutil_dir_possibilities
"${dependencies_fplutil_dir}"
"${fpl_root}/fplutil"
"${CMAKE_CURRENT_SOURCE_DIR}/dependencies/fplutil"
"${CMAKE_CURRENT_LIST_DIR}/../../fplutil"
"${CMAKE_CURRENT_LIST_DIR}/../../../fplutil"
"${CMAKE_CURRENT_LIST_DIR}/../../../../fplutil"
"${CMAKE_CURRENT_LIST_DIR}/../../../../../fplutil")

foreach(dir ${fplutil_dir_possibilities})
if(EXISTS ${dir})
set(fplutil_dir ${dir})
return()
endif()
endforeach(dir)

# Define this cached variable so that cmake GUIs can expose it to the user.
set(dependencies_fplutil_dir ""
CACHE PATH "Directory containing the fplutil library.")

MESSAGE(ERROR
"Can't find fplutil directory. Try cmake -Ddependencies_fplutil_dir=your_location.")
2 changes: 2 additions & 0 deletions component_library/include/corgi_component_library/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
#include "motive/engine.h"
#include "motive/motivator.h"

/// @brief Namespace for Motive library.
namespace motive {
class RigAnim;
}

/// @brief Namespace for CORGI library.
namespace corgi {
namespace component_library {

Expand Down
13 changes: 13 additions & 0 deletions component_library/include/corgi_component_library/bullet_physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Woverloaded-virtual"
#pragma clang diagnostic ignored "-Wignored-qualifiers"
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif // defined(__clang__)

#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif // defined(__GNUC__)

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
Expand All @@ -37,12 +45,17 @@
#pragma warning(disable : 4189) // variable initialized but not referenced
#pragma warning(disable : 4505) // function is not referenced
#pragma warning(disable : 4702) // unreachable code
#pragma warning(disable : 4305) // truncation from 'double' to 'const btScalar'
#endif // defined(_MSC_VER)
#include "btBulletDynamicsCommon.h"
#if defined(_MSC_VER)
#pragma warning(pop)
#endif // defined(_MSC_VER)

#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif // defined(__GNUC__)

#if defined(__clang__)
#pragma clang diagnostic pop
#endif // defined(__clang__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
#error You must #define FACTORY_TYPE_NAMESPACE to the namespace your generated \
FlatBuffers types are in before including this file.
#endif
// The namespace needs to be prepended to the table when we look it up, so
// define the full table name.
#define FPL_STR_EXPAND(tok) #tok
#define FPL_STR(tok) FPL_STR_EXPAND(tok)
#define ENTITY_DEF FPL_STR(FACTORY_TYPE_NAMESPACE) ".EntityDef"

#include "corgi_component_library/default_entity_factory.h"
#include "flatbuffers/reflection.h"
Expand Down Expand Up @@ -222,7 +227,7 @@ bool DefaultEntityFactory::CreateEntityList(
"CreateEntityList: GetSchema() failed, is it a binary schema?");
return false;
}
auto table_def = schema->objects()->LookupByKey("EntityDef");
auto table_def = schema->objects()->LookupByKey(ENTITY_DEF);
if (table_def == nullptr) {
fplbase::LogError("CreateEntityList: Can't look up EntityDef");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ class EntityFactory : public corgi::EntityFactoryInterface {
return flatbuffer_binary_schema_data_;
}

/// @brief Get the map with all the current prototypes.
///
/// @return Returns a const reference to the std::unordered_map with the
/// prototype data
const std::unordered_map<std::string, const void*>& prototype_data() const {
return prototype_data_;
}

private:
// Storage for the Flatbuffer binary schema.
std::string flatbuffer_binary_schema_data_;
Expand Down
7 changes: 7 additions & 0 deletions component_library/include/corgi_component_library/physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ struct PhysicsData {
std::unique_ptr<btTriangleMesh> triangle_mesh_;
int body_count_;
bool enabled_;
float gravity_multiplier_;
};

/// @class PhysicsComponent
Expand Down Expand Up @@ -442,6 +443,12 @@ class PhysicsComponent : public corgi::Component<PhysicsData> {
corgi::EntityRef RaycastSingle(mathfu::vec3& start, mathfu::vec3& end,
short layer_mask, mathfu::vec3* hit_point);

/// @brief Get the gravity value of the given Entity.
///
/// @param[in] entity The Entity to get the custom gravity for.
/// @return The gravity value of the Entity.
float GravityForEntity(const corgi::EntityRef& entity) const;

/// @brief Render the entire physics worlds using Bullet's default
/// debugging tools.
///
Expand Down
37 changes: 25 additions & 12 deletions component_library/include/corgi_component_library/rendermesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ struct RenderMeshData {
/// @brief Default constructor for RenderMeshData.
RenderMeshData()
: mesh(nullptr),
shader(nullptr),
tint(mathfu::kOnes4f),
mesh_filename(""),
shader_filename(""),
z_depth(0),
culling_mask(0),
pass_mask(0),
visible(true),
initialized(false),
default_pose(false),
num_shader_transforms(0),
shader_transforms(nullptr) {}
shader_transforms(nullptr),
debug_name("") {}

/// @brief Destructor for RenderMeshData.
~RenderMeshData() {
Expand All @@ -77,36 +77,38 @@ struct RenderMeshData {
/// data from `other`.
RenderMeshData& operator=(RenderMeshData&& other) {
mesh = std::move(other.mesh);
shader = std::move(other.shader);
shaders = std::move(other.shaders);
tint = std::move(other.tint);
mesh_filename = std::move(other.mesh_filename);
shader_filename = std::move(other.shader_filename);
shader_filenames = std::move(other.shader_filenames);
z_depth = std::move(other.z_depth);
culling_mask = std::move(other.culling_mask);
pass_mask = std::move(other.pass_mask);
visible = std::move(other.visible);
initialized = std::move(other.initialized);
default_pose = std::move(other.default_pose);
num_shader_transforms = other.num_shader_transforms;
shader_transforms = other.shader_transforms;
other.shader_transforms = nullptr;
other.num_shader_transforms = 0;
debug_name = std::move(other.debug_name);
return *this;
}

/// @brief The fplbase::Mesh for this Entity.
fplbase::Mesh* mesh;

/// @brief The fplbase::Shader for this Entity.
fplbase::Shader* shader;
/// @brief A vector of fplbase::Shader for this Entity.
std::vector<fplbase::Shader*> shaders;

/// @brief A mathfu::vec4 specifying the tinting for the Entity in RGBA.
mathfu::vec4 tint;

/// @brief A std::string of the filename for the mesh, used for exporting.
std::string mesh_filename;

/// @brief A std::string of the filename for the shader, used for exporting.
std::string shader_filename;
/// @brief A std::string of the filenames for the shaders, used for exporting.
std::vector<std::string> shader_filenames;

/// @brief The z distance corresponding to the depth of where the
/// Entity should be rendered.
Expand All @@ -123,6 +125,9 @@ struct RenderMeshData {
/// @brief A bool determining if this Entity should be rendered.
bool visible;

/// @brief A bool indicating if this RenderMesh is initialized.
bool initialized;

/// @brief A bool determining if the Entity should be rendered in the
/// default pose.
bool default_pose;
Expand All @@ -135,6 +140,9 @@ struct RenderMeshData {
/// transforms.
mathfu::AffineTransform* shader_transforms;

/// @brief The debug name of this mesh
std::string debug_name;

private:
// Disallow copies. They're inefficient with the shader_transforms array.
RenderMeshData(const RenderMeshData&);
Expand Down Expand Up @@ -252,11 +260,11 @@ class RenderMeshComponent : public Component<RenderMeshData> {
/// within the field of view.
/// @param[out] renderer A reference to the fplbase::Renderer to capture the
/// output of the render pass.
/// @param[in] shader_override A fplbase::Shader to use as the mesh shader
/// for this render pass.
/// @param[in] shader_index The shader index for the fplbase::Shader to use as
/// the mesh shader for this render pass.
void RenderPass(int pass_id, const CameraInterface& camera,
fplbase::Renderer& renderer,
const fplbase::Shader* shader_override);
size_t shader_index);

/// @brief Goes through and renders every Entity that is visible from the
/// camera, in pass order.
Expand Down Expand Up @@ -322,6 +330,11 @@ class RenderMeshComponent : public Component<RenderMeshData> {
}

private:
// Finalize the initialization of RenderMeshData if it's not completed yet.
// This function should be called right after the corresponding mesh is
// loaded.
void FinalizeRenderMeshDataIfRequired(RenderMeshData* rendermesh_data);

// todo(ccornell) expand this if needed - make an array for multiple lights.
// Also maybe make this into a full fledged struct to store things like
// intensity, color, etc. (Low priority - none of our shaders support
Expand Down
Loading

0 comments on commit cc75ab3

Please sign in to comment.