summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore6
-rw-r--r--CMakeLists.txt19
-rw-r--r--README.md4
-rw-r--r--aa.h8
-rw-r--r--bitmap.h6
-rw-r--r--main_final_render.cpp3
-rw-r--r--main_simple_scanner.cpp5
-rw-r--r--threading.h7
-rw-r--r--timer.h4
-rw-r--r--vec.h16
10 files changed, 50 insertions, 28 deletions
diff --git a/.gitignore b/.gitignore
index 8a8a9e2..d7131fb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,8 @@
cmake-build*
+build
.code
-.idea \ No newline at end of file
+.idea
+.vs
+
+CMakeSettings.json \ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 22b29e8..332f10e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,8 +5,15 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
-set(common_compiler_args "-Wall -Werror -Wno-unused -std=c++11")
-set(CMAKE_CXX_FLAGS_DEBUG "${common_compiler_args} -g -ggdb -fsanitize=address -DDEBUG")
+set(common_compiler_args "-Wall")
+if (!MSVC)
+ set(common_compiler_args "${common_compiler_args} -Werror")
+endif ()
+set(common_compiler_args, "${common_compiler_args} -Wno-unused -std=c++11")
+
+if (!MSVC)
+ set(CMAKE_CXX_FLAGS_DEBUG "${common_compiler_args} -g -ggdb -fsanitize=address -DDEBUG")
+endif ()
set(CMAKE_CXX_FLAGS_RELEASE "${common_compiler_args} -O2")
set(CMAKE_VERBOSE_MAKEFILE on)
@@ -14,10 +21,12 @@ set(CMAKE_VERBOSE_MAKEFILE on)
# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
-endif()
+endif ()
-link_libraries(pthread)
-link_libraries(atomic)
+if (!MSVC)
+ link_libraries(pthread)
+ link_libraries(atomic)
+endif ()
# main executable
diff --git a/README.md b/README.md
index e0e96de..2ae8234 100644
--- a/README.md
+++ b/README.md
@@ -21,8 +21,8 @@
## Tested platforms
-- Linux
-- Win32 (Windows 10)
+- Linux (GCC/Clang)
+- Win32 (Windows 10/11, GCC(MinGW)/Clang(MinGW)/MSVC14)
## Ray-Trace logging
diff --git a/aa.h b/aa.h
index 2be5f2c..7484bfd 100644
--- a/aa.h
+++ b/aa.h
@@ -93,13 +93,13 @@ public:
uint64_t diffuse_seed;
};
- thread_pool<s_render_task, typeof(*this), typeof(images)> pool{thread_count, *this, images, samples};
+ thread_pool<s_render_task, decltype(*this), decltype(images)> pool{thread_count, *this, images, samples};
timer tim{true};
std::cerr << "Seeding tasks..." << std::endl;
tim.start_measure();
- for (typeof(samples) i = 0; i < samples; ++i) {
- pool.submit_task([](size_t tid, s_render_task &task, const aa_viewport<U, V> &ctx, typeof(images) &images) {
+ for (decltype(samples) i = 0; i < samples; ++i) {
+ pool.submit_task([](size_t tid, s_render_task &task, const aa_viewport<U, V> &ctx, decltype(images) &images) {
basic_viewport<U, V> vp{
ctx.cxyz, ctx.screen_center,
ctx.image_width, ctx.image_height,
@@ -110,7 +110,7 @@ public:
bokeh_ctx bokeh{task.diffuse_seed + 6543210987ULL};
images[tid] = vp.render(task.diffuse_seed, bc, bokeh);
}, s_render_task{
- .bias_seed=seedgen(), .diffuse_seed=seedgen()
+ seedgen(), seedgen()
});
}
tim.stop_measure();
diff --git a/bitmap.h b/bitmap.h
index a544b03..ea64c3c 100644
--- a/bitmap.h
+++ b/bitmap.h
@@ -47,7 +47,7 @@ struct pixel {
* For example: Set color depth to 8bit, for normalized color (1, 0.5, 0.25), we get: (255, 127, 63).
*/
static inline pixel<T> from_normalized(double r, double g, double b) {
- return pixel<T>{.r = (T) (mod * r), .g = (T) (mod * g), .b = (T) (mod * b)};
+ return pixel<T>{(T) (mod * r), (T) (mod * g), (T) (mod * b)};
}
// v3d must be a normalized vector
@@ -120,12 +120,12 @@ template<
typename = typename std::enable_if<std::is_arithmetic<S>::value, S>::type
>
pixel<T> operator*(S scale, const pixel <T> &pixel) {
- return ::pixel < T > {.r=(T) (pixel.r * scale), .g=(T) (pixel.g * scale), .b=(T) (pixel.b * scale)};
+ return ::pixel < T > {(T) (pixel.r * scale), (T) (pixel.g * scale), (T) (pixel.b * scale)};
}
template<typename S, typename T>
pixel<T> operator*(const vec3<S> &scale, const pixel <T> &pixel) {
- return ::pixel < T > {.r=(T) (pixel.r * scale.x), .g=(T) (pixel.g * scale.y), .b=(T) (pixel.b * scale.z)};
+ return ::pixel < T > {(T) (pixel.r * scale.x), (T) (pixel.g * scale.y), (T) (pixel.b * scale.z)};
}
// Mix two colors a and b. Returns a*u + b*v
diff --git a/main_final_render.cpp b/main_final_render.cpp
index 277ffd9..c2c44ca 100644
--- a/main_final_render.cpp
+++ b/main_final_render.cpp
@@ -2,6 +2,9 @@
// Created by Keuin on 2022/4/21.
//
+// include M_PI from cmath when using MSVC
+#define _USE_MATH_DEFINES
+
#include "viewport.h"
#include "hitlist.h"
#include "aa.h"
diff --git a/main_simple_scanner.cpp b/main_simple_scanner.cpp
index 16a39a0..28e9ef3 100644
--- a/main_simple_scanner.cpp
+++ b/main_simple_scanner.cpp
@@ -2,11 +2,16 @@
// Created by Keuin on 2022/4/11.
//
+// include M_PI from cmath when using MSVC
+#define _USE_MATH_DEFINES
+
#include <cstdint>
#include <iostream>
#include <vector>
#include <memory>
#include <cstdlib>
+#include <string>
+#include <cmath>
#include "vec.h"
#include "timer.h"
diff --git a/threading.h b/threading.h
index 249a115..3fbe0b5 100644
--- a/threading.h
+++ b/threading.h
@@ -12,6 +12,7 @@
#include <mutex>
#include <atomic>
#include <iostream>
+#include <functional>
// A simple once-usage thread pool and task queue.
// Using lock-free atomic counter to avoid expensive queue or synchronization mechanism.
@@ -19,7 +20,7 @@
// Once the task queue is empty, threads quit.
template<typename T_Args, typename T_ImmuCtx, typename T_MutCtx>
-using task_func_t = void (*)(size_t, T_Args &, const T_ImmuCtx &, T_MutCtx &);
+using task_func_t = std::function<void(size_t, T_Args&, const T_ImmuCtx&, T_MutCtx&)>;
// internal usage
template<typename T, typename U, typename V>
@@ -61,7 +62,7 @@ public:
template<typename T, typename U, typename V>
void thread_pool<T, U, V>::start() {
if (workers.empty()) {
- for (typeof(thread_count) i = 0; i < thread_count; ++i) {
+ for (decltype(thread_count) i = 0; i < thread_count; ++i) {
workers.emplace_back(std::thread{&thread_pool<T, U, V>::worker_main, this});
}
} else {
@@ -83,7 +84,7 @@ void thread_pool<T, U, V>::worker_main() {
// Do not submit after starting.
template<typename T, typename U, typename V>
void thread_pool<T, U, V>::submit_task(task_func_t<T, U, V> f, T &&t) {
- tasks.push_back(s_task<T, U, V>{.f=f, .arg=std::move(t)});
+ tasks.push_back(s_task<T, U, V>{f, std::move(t)});
}
template<typename T, typename U, typename V>
diff --git a/timer.h b/timer.h
index 68774c5..71a9e3b 100644
--- a/timer.h
+++ b/timer.h
@@ -10,8 +10,8 @@
class timer {
private:
- typeof(std::chrono::system_clock::now()) start_time;
- typeof(std::chrono::system_clock::now()) end_time;
+ decltype(std::chrono::system_clock::now()) start_time;
+ decltype(std::chrono::system_clock::now()) end_time;
bool silent;
public:
timer() : silent{false} {}
diff --git a/vec.h b/vec.h
index 99f5f46..a9b72c3 100644
--- a/vec.h
+++ b/vec.h
@@ -53,11 +53,11 @@ struct vec3 {
}
vec3 operator+(const vec3 &b) const {
- return vec3{.x=x + b.x, .y=y + b.y, .z=z + b.z};
+ return vec3{x + b.x, y + b.y, z + b.z};
}
vec3 operator-() const {
- return vec3{.x = -x, .y = -y, .z = -z};
+ return vec3{-x, -y, -z};
}
vec3 operator-(const vec3 &b) const {
@@ -75,12 +75,12 @@ struct vec3 {
// cross product (aka outer product, or vector product, producing a vector)
vec3 cross(const vec3 &b) const {
- return vec3{.x=y * b.z - z * b.y, .y=z * b.x - x * b.z, .z=x * b.y - y * b.x};
+ return vec3{y * b.z - z * b.y, z * b.x - x * b.z, x * b.y - y * b.x};
}
// Multiply with b on every dimension.
vec3 scale(const vec3 &b) const {
- return vec3{.x=x * b.x, .y=y * b.y, .z=z * b.z};
+ return vec3{x * b.x, y * b.y, z * b.z};
}
// norm value
@@ -140,7 +140,7 @@ inline vec3<T> operator*(const vec3<T> &vec, const S &b) {
if (std::is_floating_point<S>::value) {
assert(std::isfinite(b));;
}
- return vec3<T>{.x=(T) (vec.x * b), .y=(T) (vec.y * b), .z=(T) (vec.z * b)};
+ return vec3<T>{(T) (vec.x * b), (T) (vec.y * b), (T) (vec.z * b)};
}
// product vec3 by a scalar, with fp assertions
@@ -152,7 +152,7 @@ inline vec3<T> operator*(const S &b, const vec3<T> &vec) {
if (std::is_floating_point<S>::value) {
assert(std::isfinite(b));
}
- return vec3<T>{.x=(T) (vec.x * b), .y=(T) (vec.y * b), .z=(T) (vec.z * b)};
+ return vec3<T>{(T) (vec.x * b), (T) (vec.y * b), (T) (vec.z * b)};
}
// product vec3 by the inversion of a scalar (div by a scalar), with fp assertions
@@ -166,7 +166,7 @@ inline vec3<T> operator/(const vec3<T> &vec, const S &b) {
assert(std::isfinite(b));
assert(b != 0);
}
- return vec3<T>{.x=(T) (vec.x / b), .y=(T) (vec.y / b), .z=(T) (vec.z / b)};
+ return vec3<T>{(T) (vec.x / b), (T) (vec.y / b), (T) (vec.z / b)};
}
// scalar product (inner product)
@@ -208,7 +208,7 @@ public:
inline vec3<T> range01() {
while (true) {
const auto x = uni(mt), y = uni(mt), z = uni(mt);
- const auto vec = vec3<T>{.x=x, .y=y, .z=z};
+ const auto vec = vec3<T>{x, y, z};
if (vec.mod2() <= 1.0) return vec.unit_vec();
}
}