Skip to content

Commit

Permalink
Some MSVC optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
vitor-k committed Apr 9, 2020
1 parent 5d7b1a8 commit 378d094
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)

if (MSVC)
set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -Ot -Oi")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -W3 -O2 -Ot -Oi")
endif()

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")
endif()

add_subdirectory(src)
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ add_executable(RayTracer
olcPixelGameEngine.h
)

target_link_libraries(RayTracer X11 GL pthread png)
if(NOT MSVC)
target_link_libraries(RayTracer X11 GL pthread png)
endif()
4 changes: 2 additions & 2 deletions src/GravitationalEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#include <cmath>

GravitationalEntity::GravitationalEntity(v3d center, float mass, float radius) : Sphere(center, radius), M(mass),
schwarzschildRadius(2 * G * M / (c * c) ), photonSphere(1.5*schwarzschildRadius),
schwarzschildRadius(2.f * G * M / (c * c) ), photonSphere(1.5f*schwarzschildRadius),
relativeOuterRadius(outerRadius/schwarzschildRadius), relativePhotonSphere(photonSphere/schwarzschildRadius) {}


State3d GravitationalEntity::statePonto(const float& t, const State3d& estado) const {
//const v3d raio = (estado.s - center);
const double h2 = cross(estado.v, estado.s).norm2();
return State3d{ estado.v, -1.5 * h2 * estado.s / pow(estado.s.norm2(), 2.5) };
return State3d{ estado.v, -1.5f * h2 * estado.s / pow(estado.s.norm2(), 2.5f) };
}


Expand Down
2 changes: 1 addition & 1 deletion src/v3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct v3d {
return v3d(y*vec.z - z*vec.y, z*vec.x - x*vec.z, x*vec.y - y*vec.x);
}
//Euclidian norm
constexpr float norm() const {
float norm() const {
return std::sqrt(norm2());
}
constexpr float norm2() const {
Expand Down

0 comments on commit 378d094

Please sign in to comment.