summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile47
-rw-r--r--changelog.html18
-rw-r--r--include/benoit.hh51
-rw-r--r--include/benoit/archstr.hh6
-rw-r--r--include/benoit/arghandl.hh4
-rw-r--r--include/benoit/crtcfg.hh4
-rw-r--r--include/benoit/dat.hh5
-rw-r--r--include/benoit/exit.hh6
-rw-r--r--include/benoit/helpscrn.hh4
-rw-r--r--include/benoit/kernelstr.hh6
-rw-r--r--include/benoit/loadcfg.hh4
-rw-r--r--include/benoit/log.hh6
-rw-r--r--include/benoit/logfunc.hh5
-rw-r--r--include/benoit/logfuncret.hh5
-rw-r--r--include/benoit/main.hh4
-rw-r--r--include/benoit/plotmandelbrot.hh6
-rw-r--r--include/benoit/print.hh6
-rw-r--r--include/benoit/t/arch.hh12
-rw-r--r--include/benoit/t/dat.hh65
-rw-r--r--include/benoit/t/imgfmt.hh10
-rw-r--r--include/benoit/t/kernel.hh16
-rw-r--r--include/benoit/t/pos.hh13
-rw-r--r--include/benoit/t/thrddat.hh15
-rw-r--r--src/benoit/archstr.cc31
-rw-r--r--src/benoit/arghandl.cc94
-rw-r--r--src/benoit/benoit.cc138
-rw-r--r--src/benoit/crtcfg.cc8
-rw-r--r--src/benoit/dat.cc2
-rw-r--r--src/benoit/exit.cc31
-rw-r--r--src/benoit/helpscrn.cc135
-rw-r--r--src/benoit/kernelstr.cc47
-rw-r--r--src/benoit/loadcfg.cc12
-rw-r--r--src/benoit/log.cc16
-rw-r--r--src/benoit/logfunc.cc8
-rw-r--r--src/benoit/logfuncret.cc9
-rw-r--r--src/benoit/main.cc145
-rw-r--r--src/benoit/notiffunc.cc9
-rw-r--r--src/benoit/plotmandelbrot.cc49
-rw-r--r--src/benoit/print.cc8
-rw-r--r--src/benoit/t/pos/pos.cc2
-rw-r--r--src/benoit/~benoit.cc10
-rw-r--r--src/main.cc4
43 files changed, 829 insertions, 249 deletions
diff --git a/.gitignore b/.gitignore
index 98ae13c..3d32b92 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
-*.jpeg
*.o
*.png
*.ppm
*.webp
+*.xml
/benoit
diff --git a/Makefile b/Makefile
index c7af96f..cb811a0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,28 +1,57 @@
CXX=clang++
-CXXFLAGS=-Iinclude
+CXXFLAGS=-Iinclude -D_ATFILE_SOURCE -D_FORTIFY_SOURCE=0x2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_ISOC99_SOURCE -D_ISOC11_SOURCE -D_ISOC2X_SOURCE -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED -D__STDC_WANT_IEC_60559_BFP_EXT__ -D__STDC_WANT_IEC_60559_FUNCS_EXT__ -D__STDC_WANT_IEC_60559_TYPES_EXT__ -D__STDC_WANT_LIB_EXT2__=0x1
ifneq ($(DEBUG),1)
CXXFLAGS += -DNDEBUG
endif
CXXFLAGS += -std=c++20 -Wall -Wextra -Wpedantic
CXXFLAGS += -march=native -mtune=native -O3
-LDFLAGS = -lfmt -lgmp -lmpfr -lpng -lpthread -lwebp
+LDFLAGS = -lfmt -lgmp -lmpfr -lpng -lpthread -lpugixml -lwebp
HDRS_CXX = \
- include/benoit.hh
+ include/benoit/archstr.hh \
+ include/benoit/arghandl.hh \
+ include/benoit/crtcfg.hh \
+ include/benoit/dat.hh \
+ include/benoit/exit.hh \
+ include/benoit/helpscrn.hh \
+ include/benoit/kernelstr.hh \
+ include/benoit/loadcfg.hh \
+ include/benoit/log.hh \
+ include/benoit/logfunc.hh \
+ include/benoit/logfuncret.hh \
+ include/benoit/main.hh \
+ include/benoit/plotmandelbrot.hh \
+ include/benoit/print.hh \
+ include/benoit/t/arch.hh \
+ include/benoit/t/dat.hh \
+ include/benoit/t/imgfmt.hh \
+ include/benoit/t/kernel.hh \
+ include/benoit/t/pos.hh \
+ include/benoit/t/thrddat.hh
SRCS_CXX = \
+ src/benoit/archstr.cc \
src/benoit/arghandl.cc \
- src/benoit/benoit.cc \
- src/benoit/~benoit.cc \
+ src/benoit/crtcfg.cc \
+ src/benoit/dat.cc \
src/benoit/exit.cc \
- src/benoit/notiffunc.cc \
+ src/benoit/helpscrn.cc \
+ src/benoit/kernelstr.cc \
+ src/benoit/loadcfg.cc \
+ src/benoit/log.cc \
+ src/benoit/logfunc.cc \
+ src/benoit/logfuncret.cc \
+ src/benoit/main.cc \
src/benoit/plotmandelbrot.cc \
src/benoit/print.cc \
src/benoit/t/pos/pos.cc \
src/main.cc
-SRCS=$(SRCS_CXX)
-OBJS=$(SRCS:.cc=.o)
+OBJS_CXX=$(SRCS_CXX:.cc=.o)
+OBJS=$(OBJS_CXX)
benoit: $(OBJS)
$(CXX) $(LDFLAGS) -o $@ $(OBJS)
-$(OBJS): $(HDRS_CXX) $(SRCS_CXX)
+$(OBJS_CXX): $(HDRS_CXX) $(SRCS_CXX)
.PHONY: clean
clean:
+ rm $(OBJS)
+.PHONY: purge
+purge:
rm benoit $(OBJS)
diff --git a/changelog.html b/changelog.html
index bc244ed..936cd43 100644
--- a/changelog.html
+++ b/changelog.html
@@ -4,6 +4,20 @@
<meta charset="utf-8">
</head>
<body>
+ <h1>5</h1>
+ <ul>
+ <li>Automatically detect number of threads.</li>
+ <li>Improve debugging.</li>
+ <li>Enable POSIX C.</li>
+ <li>Create foundation for loading and creating XML configurations.</li>
+ <li>Improve help screen.</li>
+ <li>Fix the static_assert in <i>include/benoit.hh</i> comparing to bits instead of bytes.</li>
+ <li>Switch compiler from Clang++ to G++ as it has better C++20 support.</li>
+ <li>Rework code structure.</li>
+ <li>Resize maximum resolution from <i>65535</i> to <i>4294967295</i>.</li>
+ <li>Make renderer able to create and use threads.</li>
+ <li>Create <i>purge</i> target in Makefile.</li>
+ </ul>
<h1>4</h1>
<ul>
<li>Remove build artifacts.</li>
@@ -13,7 +27,7 @@
<ul>
<li>Remove unused variables from Makefile.</li>
<li>Require the LLP64 data model when compiling.</li>
- <li>Create working multithreaded example.</li>
+ <li>Create working multithrded example.</li>
<li>Depend also on libpng.</li>
<li>Remove JPEG as a supported image format.</li>
</ul>
@@ -24,7 +38,7 @@
<li>Create better support for different image formats.</li>
<li>Remove C-string functions in favour of the ones in &ltcstring&gt.</li>
<li>Greatly improve debugging.</li>
- <li>Create foundation for new multithreaded multiprecision renderer.</li>
+ <li>Create foundation for new multithrded multiprecision renderer.</li>
<li>Remove old renderer.</li>
<li>Completely remove Rust artifacts.</li>
</ul>
diff --git a/include/benoit.hh b/include/benoit.hh
deleted file mode 100644
index 906b42f..0000000
--- a/include/benoit.hh
+++ /dev/null
@@ -1,51 +0,0 @@
-# if !defined(BENOIT__HEADER)
-# define BENOIT__HEADER
-# include <boost/multiprecision/mpfr.hpp>
-# include <cstddef>
-# include <cstdint>
-# include <string>
-# include <vector>
-static_assert(((sizeof(short) < 0x10) && (sizeof(int) < 0x20) && (sizeof(long) < 0x20) && (sizeof(long long) < 0x40) && (sizeof(void *) < 0x40)),"Benoit expects at least an LLP64 data model.");
-using namespace std::literals::string_literals;
-class benoit {
-public:
- [[noreturn]] benoit(int const argc,char const * * argv) noexcept;
- [[noreturn]] ~benoit() noexcept;
-private:
- class t {
- public:
- enum class imgfmt {
- png,
- ppm,
- webp,
- };
- class pos {
- public:
- boost::multiprecision::mpfr_float x = 0x0;
- boost::multiprecision::mpfr_float y = 0x0;
- pos(boost::multiprecision::mpfr_float x = 0x0,boost::multiprecision::mpfr_float y = 0x0);
- };
- };
- benoit::t::imgfmt imgfmt = benoit::t::imgfmt::ppm;
- benoit::t::pos pos;
- bool constexpr static debug =
-# if defined(NDEBUG)
- false;
-# else
- true;
-# endif
- std::string outimg = "image";
- unsigned short resx = 0x2000u;
- unsigned short resy = 0x2000u;
- unsigned short numthreads = 0x16u;
- long double zoom = 0x1p0;
- long long ver = 0x5ll;
- unsigned long long maxiter = 0x400ull;
- std::vector<std::uint8_t> plotmandelbrot();
- void arghandl(int const & argc,char const * * & argv);
- [[noreturn]] void exit(int code,std::string msg = ""s) noexcept;
- void notiffunc(std::string const callfuncname);
- void print(char const * msg,bool stderr = false);
- void print(std::string msg,bool stderr = false);
-};
-# endif
diff --git a/include/benoit/archstr.hh b/include/benoit/archstr.hh
new file mode 100644
index 0000000..3403d6a
--- /dev/null
+++ b/include/benoit/archstr.hh
@@ -0,0 +1,6 @@
+# pragma once
+# include <benoit/t/arch.hh>
+# include <string>
+namespace benoit {
+ std::string archstr(benoit::t::arch arch) noexcept;
+}
diff --git a/include/benoit/arghandl.hh b/include/benoit/arghandl.hh
new file mode 100644
index 0000000..4060149
--- /dev/null
+++ b/include/benoit/arghandl.hh
@@ -0,0 +1,4 @@
+# pragma once
+namespace benoit {
+ void arghandl(int const & argc,char const * * & argv);
+}
diff --git a/include/benoit/crtcfg.hh b/include/benoit/crtcfg.hh
new file mode 100644
index 0000000..957399e
--- /dev/null
+++ b/include/benoit/crtcfg.hh
@@ -0,0 +1,4 @@
+# pragma once
+namespace benoit {
+ void crtcfg();
+}
diff --git a/include/benoit/dat.hh b/include/benoit/dat.hh
new file mode 100644
index 0000000..7c4e7cf
--- /dev/null
+++ b/include/benoit/dat.hh
@@ -0,0 +1,5 @@
+# pragma once
+# include <benoit/t/dat.hh>
+namespace benoit {
+ benoit::t::dat extern dat;
+}
diff --git a/include/benoit/exit.hh b/include/benoit/exit.hh
new file mode 100644
index 0000000..bcf487d
--- /dev/null
+++ b/include/benoit/exit.hh
@@ -0,0 +1,6 @@
+# pragma once
+# include <string>
+using namespace std::string_literals;
+namespace benoit {
+ [[noreturn]] void exit(int code,std::string msg = ""s) noexcept;
+}
diff --git a/include/benoit/helpscrn.hh b/include/benoit/helpscrn.hh
new file mode 100644
index 0000000..66eea36
--- /dev/null
+++ b/include/benoit/helpscrn.hh
@@ -0,0 +1,4 @@
+# pragma once
+namespace benoit {
+ [[noreturn]] void helpscrn() noexcept;
+}
diff --git a/include/benoit/kernelstr.hh b/include/benoit/kernelstr.hh
new file mode 100644
index 0000000..9ad0746
--- /dev/null
+++ b/include/benoit/kernelstr.hh
@@ -0,0 +1,6 @@
+# pragma once
+# include <benoit/t/kernel.hh>
+# include <string>
+namespace benoit {
+ std::string kernelstr(benoit::t::kernel kernel) noexcept;
+}
diff --git a/include/benoit/loadcfg.hh b/include/benoit/loadcfg.hh
new file mode 100644
index 0000000..10273b0
--- /dev/null
+++ b/include/benoit/loadcfg.hh
@@ -0,0 +1,4 @@
+# pragma once
+namespace benoit {
+ void loadcfg();
+}
diff --git a/include/benoit/log.hh b/include/benoit/log.hh
new file mode 100644
index 0000000..6c04e76
--- /dev/null
+++ b/include/benoit/log.hh
@@ -0,0 +1,6 @@
+# pragma once
+# include <string>
+namespace benoit {
+ void log(std::string msg);
+ void log(std::string const func,std::string msg);
+}
diff --git a/include/benoit/logfunc.hh b/include/benoit/logfunc.hh
new file mode 100644
index 0000000..35daec8
--- /dev/null
+++ b/include/benoit/logfunc.hh
@@ -0,0 +1,5 @@
+# pragma once
+# include <string>
+namespace benoit {
+ void logfunc(std::string const func);
+}
diff --git a/include/benoit/logfuncret.hh b/include/benoit/logfuncret.hh
new file mode 100644
index 0000000..1db2e41
--- /dev/null
+++ b/include/benoit/logfuncret.hh
@@ -0,0 +1,5 @@
+# pragma once
+# include <string>
+namespace benoit {
+ void logfuncret(std::string const func);
+}
diff --git a/include/benoit/main.hh b/include/benoit/main.hh
new file mode 100644
index 0000000..72e7051
--- /dev/null
+++ b/include/benoit/main.hh
@@ -0,0 +1,4 @@
+# pragma once
+namespace benoit {
+ [[noreturn]] void main(int const argc,char const * * argv) noexcept;
+}
diff --git a/include/benoit/plotmandelbrot.hh b/include/benoit/plotmandelbrot.hh
new file mode 100644
index 0000000..3d8b57a
--- /dev/null
+++ b/include/benoit/plotmandelbrot.hh
@@ -0,0 +1,6 @@
+# pragma once
+# include <cstdint>
+# include <vector>
+namespace benoit {
+ std::vector<std::uint8_t> plotmandelbrot();
+}
diff --git a/include/benoit/print.hh b/include/benoit/print.hh
new file mode 100644
index 0000000..64ad638
--- /dev/null
+++ b/include/benoit/print.hh
@@ -0,0 +1,6 @@
+# pragma once
+# include <string>
+namespace benoit {
+ void print(char const * msg,bool stderr = false);
+ void print(std::string msg,bool stderr = false);
+}
diff --git a/include/benoit/t/arch.hh b/include/benoit/t/arch.hh
new file mode 100644
index 0000000..622e70d
--- /dev/null
+++ b/include/benoit/t/arch.hh
@@ -0,0 +1,12 @@
+# pragma once
+namespace benoit {
+ namespace t {
+ enum class arch {
+ aarch64,
+ amd64,
+ ia64,
+ ppc64,
+ unknown,
+ };
+ }
+}
diff --git a/include/benoit/t/dat.hh b/include/benoit/t/dat.hh
new file mode 100644
index 0000000..c43784b
--- /dev/null
+++ b/include/benoit/t/dat.hh
@@ -0,0 +1,65 @@
+# pragma once
+# include <benoit/t/arch.hh>
+# include <benoit/t/imgfmt.hh>
+# include <benoit/t/kernel.hh>
+# include <benoit/t/pos.hh>
+# include <string>
+# include <vector>
+using namespace std::literals::string_literals;
+namespace benoit {
+ namespace t {
+ class dat {
+ public:
+ benoit::t::arch constexpr static arch =
+# if defined(__aarch64__)
+ benoit::t::arch::aarch64;
+# elif (defined(_M_AMD64) || defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(x86_64__))
+ benoit::t::arch::amd64;
+# elif (defined(_IA64) defined(_M_IA64) || defined(__IA64__) || defined(__ia64__) || defined(__itanium__))
+ benoit::t::arch::ia64;
+# elif (defined(_ARCH_PPC64) || defined(__powerpc64__) || defined(__PPC64__) || defined(__ppc64__))
+ benoit::t::arch::ppc64;
+# else
+ benoit::t::arch::unknown;
+# endif
+ benoit::t::imgfmt imgfmt = benoit::t::imgfmt::ppm;
+ benoit::t::kernel constexpr static kernel =
+# if (defined(Macintosh) || defined(macintosh) || defined(__APPLE__) || defined(__MACH__))
+ benoit::t::kernel::darwinos;
+# elif defined(__DragonFly__)
+ benoit::t::kernel::dragonflybsd;
+# elif defined(__FreeBSD__)
+ benoit::t::kernel::freebsd;
+# elif (defined(__GNU__) || defined(__gnu_hurd__))
+ benoit::t::kernel::hurd;
+# elif defined(__linux__)
+ benoit::t::kernel::linux;
+# elif defined(__minix)
+ benoit::t::kernel::minix;
+# elif defined(__NetBSD__)
+ benoit::t::kernel::netbsd;
+# elif defined(__OpenBSD__)
+ benoit::t::kernel::openbsd;
+# else
+ benoit::t::kernel::unknown;
+# endif
+ benoit::t::pos pos;
+ bool dobt = false;
+ bool printdolog = true;
+ bool debug =
+# if defined(NDEBUG)
+ false;
+# else
+ true;
+# endif
+ long long ver = 0x5;
+ std::string cfg = "benoit.xml"s;
+ std::string outimg = "image"s;
+ std::vector<std::string> thelog = {};
+ unsigned long long maxiter = 0x100ull;
+ unsigned numthrds = 0x1u;
+ unsigned resx = 0x100u;
+ unsigned resy = 0x100u;
+ };
+ }
+}
diff --git a/include/benoit/t/imgfmt.hh b/include/benoit/t/imgfmt.hh
new file mode 100644
index 0000000..ffd6367
--- /dev/null
+++ b/include/benoit/t/imgfmt.hh
@@ -0,0 +1,10 @@
+# pragma once
+namespace benoit {
+ namespace t {
+ enum class imgfmt {
+ png,
+ ppm,
+ webp,
+ };
+ }
+}
diff --git a/include/benoit/t/kernel.hh b/include/benoit/t/kernel.hh
new file mode 100644
index 0000000..099dd60
--- /dev/null
+++ b/include/benoit/t/kernel.hh
@@ -0,0 +1,16 @@
+# pragma once
+namespace benoit {
+ namespace t {
+ enum class kernel {
+ darwinos,
+ dragonflybsd,
+ freebsd,
+ hurd,
+ linux,
+ minix,
+ netbsd,
+ openbsd,
+ unknown,
+ };
+ }
+}
diff --git a/include/benoit/t/pos.hh b/include/benoit/t/pos.hh
new file mode 100644
index 0000000..4725bb6
--- /dev/null
+++ b/include/benoit/t/pos.hh
@@ -0,0 +1,13 @@
+# pragma once
+# include <boost/multiprecision/mpfr.hpp>
+namespace benoit {
+ namespace t {
+ class pos {
+ public:
+ pos(boost::multiprecision::mpfr_float x = 0x0,boost::multiprecision::mpfr_float y = 0x0);
+ boost::multiprecision::mpfr_float x = 0x0;
+ boost::multiprecision::mpfr_float y = 0x0;
+ boost::multiprecision::mpfr_float zoom = 0x0;
+ };
+ }
+}
diff --git a/include/benoit/t/thrddat.hh b/include/benoit/t/thrddat.hh
new file mode 100644
index 0000000..75c8a05
--- /dev/null
+++ b/include/benoit/t/thrddat.hh
@@ -0,0 +1,15 @@
+# pragma once
+# include <cstdint>
+# include <pthread.h>
+# include <vector>
+namespace benoit {
+ namespace t {
+ class thrddat {
+ public:
+ pthread_t * thrd = nullptr;
+ std::vector<std::uint8_t> * img = nullptr;
+ unsigned * rows = nullptr;
+ unsigned * id = nullptr;
+ };
+ }
+}
diff --git a/src/benoit/archstr.cc b/src/benoit/archstr.cc
new file mode 100644
index 0000000..1c6d164
--- /dev/null
+++ b/src/benoit/archstr.cc
@@ -0,0 +1,31 @@
+# include <benoit/archstr.hh>
+# include <benoit/t/arch.hh>
+# include <string>
+# include <unordered_map>
+using namespace std::literals::string_literals;
+std::string benoit::archstr(benoit::t::arch arch) noexcept {
+ std::unordered_map<benoit::t::arch,std::string> map = {
+ {
+ benoit::t::arch::aarch64,
+ "ARM64 / AArch64"s,
+ },
+ {
+ benoit::t::arch::amd64,
+ "AMD64 / x86-64"s,
+ },
+ {
+ benoit::t::arch::ia64,
+ "IA-64"s,
+ },
+ {
+ benoit::t::arch::ppc64,
+ "PPC64"s,
+ },
+ {
+ benoit::t::arch::unknown,
+ "N/A"s,
+ }
+ };
+ std::string str = map[arch];
+ return str;
+}
diff --git a/src/benoit/arghandl.cc b/src/benoit/arghandl.cc
index 059728b..2b4026b 100644
--- a/src/benoit/arghandl.cc
+++ b/src/benoit/arghandl.cc
@@ -1,16 +1,100 @@
-# include <benoit.hh>
+# include <benoit/archstr.hh>
+# include <benoit/arghandl.hh>
+# include <benoit/dat.hh>
+# include <benoit/exit.hh>
+# include <benoit/helpscrn.hh>
+# include <benoit/kernelstr.hh>
+# include <benoit/log.hh>
+# include <benoit/logfunc.hh>
+# include <benoit/logfuncret.hh>
+# include <benoit/print.hh>
+# include <benoit/t/imgfmt.hh>
# include <fmt/core.h>
+# include <string>
+# include <unordered_map>
+using namespace std::literals::string_literals;
void benoit::arghandl(int const & argc,char const * * & argv) {
std::string const funcname = "benoit::arghandl(int const &,char const * * &)"s;
- this->notiffunc(funcname);
+ benoit::logfunc(funcname);
if(argc < 0x2) {
+ benoit::logfuncret(funcname);
return;
}
for(int pos = 0x1;(pos < argc);++pos) {
std::string arg = argv[pos];
- if(arg == "--help") {
- this->print(fmt::format("benoit {}",this->ver));
- this->exit(EXIT_SUCCESS);
+ benoit::log(fmt::format("Found argument “{}”.",arg));
+ std::string::size_type eqpos = arg.find("="s);
+ if(eqpos != std::string::npos) {
+ std::unordered_map<std::string,bool> strtobool = {
+ {
+ "false"s,
+ false,
+ },
+ {
+ "true"s,
+ true,
+ }
+ };
+ std::string invalvalforobj = "Unrecognised value “{}” for object “{}”."s;
+ std::string obj = arg.substr(0x0,eqpos);
+ benoit::log(funcname,fmt::format("Found object “{}”.",obj));
+ std::string val = arg.substr(eqpos + 0x1);
+ benoit::log(funcname,fmt::format("Found value “{}”.",val));
+ if(obj == "debug"s) {
+ if(!strtobool.contains(val)) {
+ benoit::print(fmt::format(invalvalforobj,val,obj));
+ }
+ else {
+ benoit::dat.debug = strtobool[val];
+ }
+ }
+ else if(obj == "format"s) {
+ if(val == "PNG"s) {
+ benoit::dat.imgfmt = benoit::t::imgfmt::png;
+ }
+ else if(val == "PPM"s) {
+ benoit::dat.imgfmt = benoit::t::imgfmt::ppm;
+ }
+ else if(val == "WebP"s) {
+ benoit::dat.imgfmt = benoit::t::imgfmt::webp;
+ }
+ else {
+ benoit::print(fmt::format(invalvalforobj,val,obj),true);
+ }
+ }
+ else if(obj == "output"s) {
+ benoit::dat.outimg = val;
+ }
+ else if(obj == "threads"s) {
+ benoit::dat.numthrds = std::stoi(val);
+ }
+ else {
+ benoit::print(fmt::format("Invalid object “{}”."s,obj),true);
+ }
}
+ else {
+ if((arg == "help"s) || (arg == "--help"s)) {
+ benoit::helpscrn();
+ }
+ else {
+ benoit::print(fmt::format("Invalid argument “{}”."s,arg),true);
+ }
+ }
+ }
+ switch(benoit::dat.imgfmt) {
+ case benoit::t::imgfmt::png:
+ benoit::dat.outimg.append(".png"s);
+ break;
+ case benoit::t::imgfmt::ppm:
+ benoit::dat.outimg.append(".ppm"s);
+ break;
+ case benoit::t::imgfmt::webp:
+ if((benoit::dat.resx > 0x1000) || (benoit::dat.resy > 0x1000)) {
+ benoit::exit(EXIT_FAILURE,"WebP does not support a resolution of more than 4096"s);
+ }
+ benoit::dat.outimg.append(".webp"s);
+ break;
}
+ benoit::log(funcname,fmt::format("The output image will be \u201C{}\u201D."s,benoit::dat.outimg));
+ benoit::logfuncret(funcname);
}
diff --git a/src/benoit/benoit.cc b/src/benoit/benoit.cc
deleted file mode 100644
index a97e35c..0000000
--- a/src/benoit/benoit.cc
+++ /dev/null
@@ -1,138 +0,0 @@
-# include <benoit.hh>
-# include <cstddef>
-# include <cstdint>
-# include <cstdlib>
-# include <fcntl.h>
-# include <fmt/core.h>
-# include <string>
-# include <unistd.h>
-# include <vector>
-# include <webp/encode.h>
-# include <webp/types.h>
-using namespace std::literals::string_literals;
-[[noreturn]] benoit::benoit(int const argc,char const * * argv) noexcept {
- std::string const funcname = "benoit::benoit(int const,char const * *)"s;
- this->notiffunc(funcname);
- this->arghandl(argc,argv);
- switch(this->imgfmt) {
- case benoit::t::imgfmt::png:
- this->outimg.append(".png"s);
- break;
- case benoit::t::imgfmt::ppm:
- this->outimg.append(".ppm"s);
- break;
- case benoit::t::imgfmt::webp:
- if((this->resx > 0x1000) || (this->resy > 0x1000)) {
- this->exit(EXIT_FAILURE,"WebP does not support a resolution of more than 4096"s);
- }
- this->outimg.append(".webp"s);
- break;
- }
- std::vector<std::uint8_t> buf = this->plotmandelbrot();
- this->exit(EXIT_SUCCESS);
- int file = ::open(this->outimg.c_str(),O_TRUNC | O_WRONLY);
- std::string msg = ("P3 "s + std::to_string(this->resx) + " "s +std::to_string(this->resy) + " 255 "s);
- for(auto val : buf) {
- msg.append(std::to_string(val));
- msg.append(" ");
- }
- if(::write(file,msg.c_str(),std::strlen(msg.c_str())) < 0x0) {
- this->print(fmt::format("Unable to write to \"{}\"."s,this->outimg));
- }
- if(::close(file) < 0x0) {
- this->print(fmt::format("Unable to close file \"{]\"."s,this->outimg));
- }
- this->exit(EXIT_SUCCESS);
-}
- /*
- auto webpconf = ::WebPConfig();
- webpconf.lossless = 0x1;
- webpconf.quality = 0x64;
- webpconf.method = 0x6;
- webpconf.segments = 0x4;
- webpconf.sns_strength = 0x4;
- webpconf.filter_strength = 0x0;
- webpconf.filter_sharpness = 0x0;
- webpconf.autofilter = 0x0;
- webpconf.alpha_compression = 0x1;
- webpconf.alpha_filtering = 0x2;
- webpconf.alpha_quality = 0x64;
- webpconf.pass = 0xA;
- webpconf.preprocessing = 0x1;
- webpconf.partitions = 0x3;
- webpconf.partitions = 0x0;
- webpconf.use_sharp_yuv = 0x0;
- auto conferr = ::WebPValidateConfig(&webpconf);
- auto webpimg = ::WebPPicture();
- WebPPictureInit(&webpimg);
- webpimg.use_argb = 0x1;
- webpimg.resx = 0x1;
- webpimg.resy = 0x1;
- WebPPictureAlloc(&webpimg);
- auto webpmemwrit = WebPMemoryWriter();
- WebPMemoryWriterInit(&webpmemwrit);
- webpimg.writer = WebPMemoryWrite;
- webpimg.custom_ptr = &webpmemwrit;
- webpimg.argb = {0xFF,0xFF,0x0,0x0};
- if(WebPEncode(&webpconf,&webpimg) == 0x0) {
- }
- else {
-
- }
- WebPPictureFree(&webpimg);
- auto buf = std::vector<std::uint8_t>();
- buf.push_back(0xFF);
- buf.push_back(0x0);
- buf.push_back(0x0);
- auto file = std::fstream(this->outimt,std::fstream::binary | std::fstream::out | std::fstream::trunc);
- if(!file.is_open()) {
- ::_exit(EXIT_FAILURE);
- }
- const double maxR = 2.25;
- const double minR = -2.25;
- const double maxI = 2.25;
- const double minI = -2.25;
-
- for(unsigned int y = 0; y < this->resy; ++y)
- for(unsigned int x = 0; x < this->resx; ++x) {
- long double r = x * ((maxR + this->real * this->zoom) / this->zoom - (minR + this->real * this->zoom) / this->zoom) / this->resx + (minR + this->real * this->zoom) / this->zoom;
- long double i = y * ((maxI + this->imag * this->zoom) / this->zoom - (minI + this->imag * this->zoom) / this->zoom) / this->resx + (minI + this->imag * this->zoom) / this->zoom;
- long double r2 = 0.0;
- long double i2 = 0.0;
-
- unsigned int iter;
- for(iter = 0; iter < this->maxiter; ++iter) {
- if(r2 * r2 + i2 * i2 >= 4.0)
- break;
-
- long double r2Temp = r2 * r2 - i2 * i2 + r;
- long double i2Temp = 2.0 * r2 * i2 + i;
-
- if(r2 == r2Temp && i2 == i2Temp) {
- iter = this->maxiter;
- break;
- }
-
- r2 = r2Temp;
- i2 = i2Temp;
- }
-
- std::uint8_t blue = 0x0;
- std::uint8_t green = 0x0;
- std::uint8_t red = 0x0;
-
- if(iter != this->maxiter) {
- float tmp = ((float)(iter) / (float)(this->maxiter));
- blue = (std::uint8_t)((1.0 - tmp) * 255.0);
- green = (std::uint8_t)((1.0 - tmp) * 255.0);
- red = (std::uint8_t)((1.0 - tmp) * 255.0);
- //double t = (double)(iter) / (double)(this->maxiter);
- //red = (int)(8.0 * (1.0 - t) * t * t * t * 255.0);
- //green = (int)(16.0 * (1.0 - t) * (1.0 - t) * t * t * 255.0);
- //blue = (int)(8.0 * (1.0 - t) * (1.0 - t) * (1.0 - t) * t * 255.0);
- }
- buf.push_back(blue);
- buf.push_back(green);
- buf.push_back(red);
- }
-*/
diff --git a/src/benoit/crtcfg.cc b/src/benoit/crtcfg.cc
new file mode 100644
index 0000000..a09b0c8
--- /dev/null
+++ b/src/benoit/crtcfg.cc
@@ -0,0 +1,8 @@
+# include <benoit/crtcfg.hh>
+# include <benoit/logfunc.hh>
+# include <string>
+using namespace std::literals::string_literals;
+void benoit::crtcfg() {
+ std::string const funcname = "benoit::crtcfg()"s;
+ benoit::logfunc(funcname);
+}
diff --git a/src/benoit/dat.cc b/src/benoit/dat.cc
new file mode 100644
index 0000000..5796fa1
--- /dev/null
+++ b/src/benoit/dat.cc
@@ -0,0 +1,2 @@
+# include <benoit/dat.hh>
+benoit::t::dat benoit::dat;
diff --git a/src/benoit/exit.cc b/src/benoit/exit.cc
index e408b9c..98d0619 100644
--- a/src/benoit/exit.cc
+++ b/src/benoit/exit.cc
@@ -1,13 +1,34 @@
-# include <benoit.hh>
+# include <benoit/dat.hh>
+# include <benoit/exit.hh>
+# include <benoit/logfunc.hh>
+# include <benoit/print.hh>
+# include <cstdlib>
# include <fmt/core.h>
# include <string>
-# include <unistd.h>
+# include <time.h>
using namespace std::literals::string_literals;
[[noreturn]] void benoit::exit(int code,std::string msg) noexcept {
std::string const funcname = "benoit::exit(int,std::string)"s;
- this->notiffunc(funcname);
- if(msg != ""s) {
- this->print(fmt::format("Exited with error code {}: {}",code,msg),true);
+ benoit::logfunc(funcname);
+ if(benoit::dat.debug) {
+ benoit::print(fmt::format("Exited with code {}: \"{}\"."s,code,msg),true);
+ }
+ if((code == EXIT_FAILURE) || benoit::dat.dobt || benoit::dat.debug) {
+ benoit::dat.printdolog = false;
+ benoit::print(""s);
+ benoit::print("+-------------"s);
+ benoit::print("| :Backtrace:"s);
+ benoit::print("+-"s);
+ benoit::print(""s);
+ for(auto entry : benoit::dat.thelog) {
+ {
+ ::timespec sleepfor;
+ sleepfor.tv_sec = 0x0;
+ sleepfor.tv_nsec = (0x3B9ACA00L / 0x3L);
+ ::nanosleep(&sleepfor,nullptr);
+ }
+ benoit::print(entry);
+ }
}
::_exit(code);
}
diff --git a/src/benoit/helpscrn.cc b/src/benoit/helpscrn.cc
new file mode 100644
index 0000000..1b9ef97
--- /dev/null
+++ b/src/benoit/helpscrn.cc
@@ -0,0 +1,135 @@
+# include <benoit/archstr.hh>
+# include <benoit/helpscrn.hh>
+# include <benoit/dat.hh>
+# include <benoit/exit.hh>
+# include <benoit/kernelstr.hh>
+# include <benoit/logfunc.hh>
+# include <benoit/print.hh>
+# include <fmt/core.h>
+# include <string>
+# include <unordered_map>
+using namespace std::literals::string_literals;
+[[noreturn]] void benoit::helpscrn() noexcept {
+ std::string const funcname = "benoit::helpscrn()"s;
+ benoit::logfunc(funcname);
+ std::string cmdate = ""s;
+ {
+ std::string date = __DATE__;
+ std::string time = __TIME__;
+ std::unordered_map<std::string,std::string> monthmap = {
+ {
+ "Jan",
+ "01",
+ },
+ {
+ "Feb",
+ "02",
+ },
+ {
+ "Mar",
+ "03",
+ },
+ {
+ "Apr",
+ "04",
+ },
+ {
+ "May",
+ "05",
+ },
+ {
+ "Jun",
+ "06",
+ },
+ {
+ "Jul",
+ "07",
+ },
+ {
+ "Aug",
+ "08",
+ },
+ {
+ "Sep",
+ "09",
+ },
+ {
+ "Oct",
+ "10",
+ },
+ {
+ "Nov",
+ "11",
+ },
+ {
+ "Dec",
+ "12",
+ },
+ };
+ std::string year = date.substr(0x7);
+ std::string month = monthmap[date.substr(0x0,0x3)];
+ std::string day = date.substr(0x4,0x2);
+ cmdate = year + "-"s + month + "-"s + day + "T"s + time;
+ }
+ std::string cppver = ""s;
+ {
+ long constexpr cplusplus = __cplusplus;
+ switch(cplusplus) {
+ default:
+ cppver = fmt::format("{}"s,cplusplus);
+ break;
+ case 0x30C1Fl:
+ cppver = "C++98 / C++03"s;
+ break;
+ case 0x3118Fl:
+ cppver = "C++11"s;
+ break;
+ case 0x312BAl:
+ cppver = "C++14"s;
+ break;
+ case 0x313E7l:
+ cppver = "C++17"s;
+ break;
+ case 0x31512l:
+ cppver = "C++20"s;
+ break;
+ }
+ }
+ std::string datmod = fmt::format("{}/{}/{}/{}/{}",sizeof(short),sizeof(int),sizeof(long),sizeof(long long),sizeof(void *));
+ if constexpr((sizeof(short) == 0x2) && (sizeof(int) == 0x4) && (sizeof(long) == 0x4) && (sizeof(long long) == 0x8) && (sizeof(void *) == 0x8)) {
+ datmod = fmt::format("LLP64 (noob / {})"s,datmod);
+ }
+ else if constexpr((sizeof(short) == 0x2) && (sizeof(int) == 0x4) && (sizeof(long) == 0x8) && (sizeof(long long) == 0x8) && (sizeof(void *) == 0x8)) {
+ datmod = fmt::format("LP64 ({})"s,datmod);
+ }
+ else if constexpr((sizeof(short) == 0x2) && (sizeof(int) == 0x8) && (sizeof(long) == 0x8) && (sizeof(long long) == 0x8) && (sizeof(void *) == 0x8)) {
+ datmod = fmt::format("ILP64 ({})"s,datmod);
+ }
+ else if constexpr((sizeof(short) == 0x8) && (sizeof(int) == 0x8) && (sizeof(long) == 0x8) && (sizeof(long long) == 0x8) && (sizeof(void *) == 0x8)) {
+ datmod = fmt::format("SILP64 (wtf? / {})"s,datmod);
+ }
+ else {
+ datmod = fmt::format("{} AKA how the fuck did this get compiled?"s,datmod);
+ }
+ benoit::print(""s);
+ benoit::print(fmt::format("benoit {}",benoit::dat.ver));
+ benoit::print("Copyright 2021 Gabriel Jensen"s);
+ benoit::print(""s);
+ benoit::print("Arguments:"s);
+ benoit::print("\u0009debug={false,true}:"s);
+ benoit::print("\u0009\u0009Sets whether or not to display debug information."s);
+ benoit::print("\u0009\u0009Some debugging information (for example assertions) will still require building a debug build."s);
+ benoit::print("\u0009help, --help:"s);
+ benoit::print("\u0009\u0009Displays this information screen."s);
+ benoit::print("\u0009threads={0..65535}:"s);
+ benoit::print("\u0009\u0009Sets the number of threads that will be used."s);
+ benoit::print(""s);
+ benoit::print("Compilation Information:"s);
+ benoit::print(fmt::format("\u0009Architecture: {}"s,benoit::archstr(benoit::dat.arch)));
+ benoit::print(fmt::format("\u0009Compilation Date: {}"s,cmdate));
+ benoit::print(fmt::format("\u0009Compiler C++ Standard: {}"s,cppver));
+ benoit::print(fmt::format("\u0009Data Model: {}"s,datmod));
+ benoit::print(fmt::format("\u0009System Kernel: {}"s,benoit::kernelstr(benoit::dat.kernel)));
+ benoit::print(""s);
+ benoit::exit(EXIT_SUCCESS);
+}
diff --git a/src/benoit/kernelstr.cc b/src/benoit/kernelstr.cc
new file mode 100644
index 0000000..9239ac4
--- /dev/null
+++ b/src/benoit/kernelstr.cc
@@ -0,0 +1,47 @@
+# include <benoit/kernelstr.hh>
+# include <benoit/t/kernel.hh>
+# include <string>
+# include <unordered_map>
+using namespace std::literals::string_literals;
+std::string benoit::kernelstr(benoit::t::kernel kernel) noexcept {
+ std::unordered_map<benoit::t::kernel,std::string> map = {
+ {
+ benoit::t::kernel::darwinos,
+ "Darwin OS"s,
+ },
+ {
+ benoit::t::kernel::dragonflybsd,
+ "DragonFly BSD"s,
+ },
+ {
+ benoit::t::kernel::freebsd,
+ "FreeBSD"s,
+ },
+ {
+ benoit::t::kernel::hurd,
+ "Hurd"s,
+ },
+ {
+ benoit::t::kernel::linux,
+ "Linux"s,
+ },
+ {
+ benoit::t::kernel::minix,
+ "MINIX"s,
+ },
+ {
+ benoit::t::kernel::netbsd,
+ "NetBSD"s,
+ },
+ {
+ benoit::t::kernel::openbsd,
+ "OpenBSD"s,
+ },
+ {
+ benoit::t::kernel::unknown,
+ "N/A"s,
+ }
+ };
+ std::string str = map[kernel];
+ return str;
+}
diff --git a/src/benoit/loadcfg.cc b/src/benoit/loadcfg.cc
new file mode 100644
index 0000000..b491201
--- /dev/null
+++ b/src/benoit/loadcfg.cc
@@ -0,0 +1,12 @@
+# include <benoit/crtcfg.hh>
+# include <benoit/dat.hh>
+# include <benoit/loadcfg.hh>
+# include <iostream>
+# include <pugixml.hpp>
+# include <unistd.h>
+void benoit::loadcfg() {
+ if(::access(benoit::dat.cfg.c_str(),R_OK) < 0x0) {
+ benoit::crtcfg();
+ return;
+ }
+}
diff --git a/src/benoit/log.cc b/src/benoit/log.cc
new file mode 100644
index 0000000..92446ab
--- /dev/null
+++ b/src/benoit/log.cc
@@ -0,0 +1,16 @@
+# include <benoit/dat.hh>
+# include <benoit/log.hh>
+# include <benoit/print.hh>
+# include <fmt/core.h>
+# include <string>
+void benoit::log(std::string msg) {
+ if(benoit::dat.debug) {
+ benoit::print(msg,true);
+ }
+ else {
+ benoit::dat.thelog.insert(benoit::dat.thelog.begin(),msg);
+ }
+}
+void benoit::log(std::string const func,std::string msg) {
+ msg = fmt::format("[{}] {}"s,func,msg);
+}
diff --git a/src/benoit/logfunc.cc b/src/benoit/logfunc.cc
new file mode 100644
index 0000000..54f4202
--- /dev/null
+++ b/src/benoit/logfunc.cc
@@ -0,0 +1,8 @@
+# include <benoit/log.hh>
+# include <benoit/logfunc.hh>
+# include <fmt/core.h>
+# include <string>
+using namespace std::literals::string_literals;
+void benoit::logfunc(std::string const func) {
+ benoit::log(fmt::format("Function call: {}."s,func));
+}
diff --git a/src/benoit/logfuncret.cc b/src/benoit/logfuncret.cc
new file mode 100644
index 0000000..6e52ede
--- /dev/null
+++ b/src/benoit/logfuncret.cc
@@ -0,0 +1,9 @@
+# include <benoit/log.hh>
+# include <benoit/logfuncret.hh>
+# include <fmt/core.h>
+# include <string>
+using namespace std::literals::string_literals;
+void benoit::logfuncret(std::string const func) {
+ std::string const funcname = "benoit::logfuncret(std::string const)"s;
+ benoit::log(fmt::format("Function return: {}."s,func));
+}
diff --git a/src/benoit/main.cc b/src/benoit/main.cc
new file mode 100644
index 0000000..2717955
--- /dev/null
+++ b/src/benoit/main.cc
@@ -0,0 +1,145 @@
+static_assert(((sizeof(short) >= 0x2) && (sizeof(int) >= 0x4) && (sizeof(long) >= 0x4) && (sizeof(long long) >= 0x8) && (sizeof(void *) >= 0x8)),"Benoit expects at least an LLP64 data model.");
+# include <benoit/arghandl.hh>
+# include <benoit/log.hh>
+# include <benoit/logfunc.hh>
+# include <benoit/dat.hh>
+# include <benoit/exit.hh>
+# include <benoit/loadcfg.hh>
+# include <benoit/log.hh>
+# include <benoit/logfunc.hh>
+# include <benoit/logfuncret.hh>
+# include <benoit/main.hh>
+# include <benoit/plotmandelbrot.hh>
+# include <benoit/print.hh>
+# include <cstddef>
+# include <cstdint>
+# include <cstdlib>
+# include <fcntl.h>
+# include <fmt/core.h>
+# include <string>
+# include <sys/types.h>
+# include <thread>
+# include <unistd.h>
+# include <vector>
+# include <webp/encode.h>
+# include <webp/types.h>
+using namespace std::literals::string_literals;
+[[noreturn]] void benoit::main(int const argc,char const * * argv) noexcept {
+ std::string const funcname = "benoit::main(int const,char const * *)"s;
+ benoit::log(fmt::format("{}"s,argv[0x0]));
+ benoit::logfunc(funcname);
+ benoit::dat.numthrds = std::thread::hardware_concurrency();
+ benoit::log(fmt::format("{} availabe threads have been detected.",benoit::dat.numthrds));
+ benoit::arghandl(argc,argv);
+ benoit::loadcfg();
+ std::vector<std::uint8_t> buf = benoit::plotmandelbrot();
+ benoit::exit(EXIT_SUCCESS);
+ std::string msg = ("P3 "s + std::to_string(benoit::dat.resx) + " "s +std::to_string(benoit::dat.resy) + " 255 "s);
+ for(auto val : buf) {
+ benoit::print(fmt::format("Found value {} in image."s,val));
+ msg.append(std::to_string(val));
+ msg.append(" ");
+ }
+ int file = ::open(benoit::dat.outimg.c_str(),O_WRONLY);
+ //for(::ssize_t bytesleft = msg.size();(bytesleft > 0x0);) {
+ if(::write(file,msg.c_str(),msg.size()) < 0x0) {
+ benoit::print(fmt::format("Unable to write to “{}”."s,benoit::dat.outimg));
+ }
+ //}
+ if(::close(file) < 0x0) {
+ benoit::print(fmt::format("Unable to close file “{}”."s,benoit::dat.outimg));
+ }
+ benoit::exit(EXIT_SUCCESS);
+}
+ /*
+ auto webpconf = ::WebPConfig();
+ webpconf.lossless = 0x1;
+ webpconf.quality = 0x64;
+ webpconf.method = 0x6;
+ webpconf.segments = 0x4;
+ webpconf.sns_strength = 0x4;
+ webpconf.filter_strength = 0x0;
+ webpconf.filter_sharpness = 0x0;
+ webpconf.autofilter = 0x0;
+ webpconf.alpha_compression = 0x1;
+ webpconf.alpha_filtering = 0x2;
+ webpconf.alpha_quality = 0x64;
+ webpconf.pass = 0xA;
+ webpconf.preprocessing = 0x1;
+ webpconf.partitions = 0x3;
+ webpconf.partitions = 0x0;
+ webpconf.use_sharp_yuv = 0x0;
+ auto conferr = ::WebPValidateConfig(&webpconf);
+ auto webpimg = ::WebPPicture();
+ WebPPictureInit(&webpimg);
+ webpimg.use_argb = 0x1;
+ webpimg.resx = 0x1;
+ webpimg.resy = 0x1;
+ WebPPictureAlloc(&webpimg);
+ auto webpmemwrit = WebPMemoryWriter();
+ WebPMemoryWriterInit(&webpmemwrit);
+ webpimg.writer = WebPMemoryWrite;
+ webpimg.custom_ptr = &webpmemwrit;
+ webpimg.argb = {0xFF,0xFF,0x0,0x0};
+ if(WebPEncode(&webpconf,&webpimg) == 0x0) {
+ }
+ else {
+
+ }
+ WebPPictureFree(&webpimg);
+ auto buf = std::vector<std::uint8_t>();
+ buf.push_back(0xFF);
+ buf.push_back(0x0);
+ buf.push_back(0x0);
+ auto file = std::fstream(benoit::outimt,std::fstream::binary | std::fstream::out | std::fstream::trunc);
+ if(!file.is_open()) {
+ ::_exit(EXIT_FAILURE);
+ }
+ const double maxR = 2.25;
+ const double minR = -2.25;
+ const double maxI = 2.25;
+ const double minI = -2.25;
+
+ for(unsigned int y = 0; y < benoit::dat.resy; ++y)
+ for(unsigned int x = 0; x < benoit::dat.resx; ++x) {
+ long double r = x * ((maxR + benoit::real * benoit::dat.zoom) / benoit::dat.zoom - (minR + benoit::real * benoit::dat.zoom) / benoit::dat.zoom) / benoit::dat.resx + (minR + benoit::real * benoit::dat.zoom) / benoit::dat.zoom;
+ long double i = y * ((maxI + benoit::imag * benoit::dat.zoom) / benoit::dat.zoom - (minI + benoit::imag * benoit::dat.zoom) / benoit::dat.zoom) / benoit::dat.resx + (minI + benoit::imag * benoit::dat.zoom) / benoit::dat.zoom;
+ long double r2 = 0.0;
+ long double i2 = 0.0;
+
+ unsigned int iter;
+ for(iter = 0; iter < benoit::maxiter; ++iter) {
+ if(r2 * r2 + i2 * i2 >= 4.0)
+ break;
+
+ long double r2Temp = r2 * r2 - i2 * i2 + r;
+ long double i2Temp = 2.0 * r2 * i2 + i;
+
+ if(r2 == r2Temp && i2 == i2Temp) {
+ iter = benoit::maxiter;
+ break;
+ }
+
+ r2 = r2Temp;
+ i2 = i2Temp;
+ }
+
+ std::uint8_t blue = 0x0;
+ std::uint8_t green = 0x0;
+ std::uint8_t red = 0x0;
+
+ if(iter != benoit::maxiter) {
+ float tmp = ((float)(iter) / (float)(benoit::maxiter));
+ blue = (std::uint8_t)((1.0 - tmp) * 255.0);
+ green = (std::uint8_t)((1.0 - tmp) * 255.0);
+ red = (std::uint8_t)((1.0 - tmp) * 255.0);
+ //double t = (double)(iter) / (double)(benoit::maxiter);
+ //red = (int)(8.0 * (1.0 - t) * t * t * t * 255.0);
+ //green = (int)(16.0 * (1.0 - t) * (1.0 - t) * t * t * 255.0);
+ //blue = (int)(8.0 * (1.0 - t) * (1.0 - t) * (1.0 - t) * t * 255.0);
+ }
+ buf.push_back(blue);
+ buf.push_back(green);
+ buf.push_back(red);
+ }
+*/
diff --git a/src/benoit/notiffunc.cc b/src/benoit/notiffunc.cc
deleted file mode 100644
index bb2152c..0000000
--- a/src/benoit/notiffunc.cc
+++ /dev/null
@@ -1,9 +0,0 @@
-# include <benoit.hh>
-# include <fmt/core.h>
-# include <string>
-void benoit::notiffunc(std::string const callfuncname) {
- std::string const funcname = "benoit::notiffunc(std:.string constexpr)"s;
- if constexpr(benoit::debug) {
- this->print(fmt::format("Function \"{}\" has been called."s,callfuncname));
- }
-}
diff --git a/src/benoit/plotmandelbrot.cc b/src/benoit/plotmandelbrot.cc
index 2a594cd..36ea5b8 100644
--- a/src/benoit/plotmandelbrot.cc
+++ b/src/benoit/plotmandelbrot.cc
@@ -1,31 +1,52 @@
-# include <benoit.hh>
+# include <benoit/dat.hh>
+# include <benoit/log.hh>
+# include <benoit/logfunc.hh>
+# include <benoit/logfuncret.hh>
+# include <benoit/plotmandelbrot.hh>
+# include <benoit/print.hh>
+# include <benoit/t/thrddat.hh>
# include <boost/multiprecision/mpfr.hpp>
# include <cstdint>
# include <fmt/core.h>
-# include <iostream>
# include <pthread.h>
# include <string>
# include <vector>
using namespace std::literals::string_literals;
namespace {
- void * plotarea(void * rowsptr) {
- unsigned short rows = *(unsigned short *)(rowsptr);
- std::cout << fmt::format("Hello there from thread!\u000AI will calculate {} rows.\u000A"s,rows);
- return nullptr;
+ void * plotarea(void * thrddatptr) {
+ benoit::t::thrddat thrddat = *reinterpret_cast<benoit::t::thrddat *>(thrddatptr);
+ thrddat.img = new std::vector<std::uint8_t>;
+ pthread_exit(nullptr);
}
}
std::vector<std::uint8_t> benoit::plotmandelbrot() {
std::string const funcname = "benoit::plotmandelbrot()"s;
- this->notiffunc(funcname);
+ benoit::logfunc(funcname);
std::vector<std::uint8_t> img;
- std::vector<::pthread_t> threads;
- for(unsigned short thread = 0x0;(thread < this->numthreads);++thread) {
- threads.emplace_back();
- unsigned short rowspthread = (this->resy / this->numthreads);
- ::pthread_create(&threads[thread],nullptr,::plotarea,&rowspthread);
+ unsigned short remainrows = benoit::dat.resy;
+ std::vector<benoit::t::thrddat> thrds;
+ for(unsigned thrdid = 0x0;(thrdid < benoit::dat.numthrds);++thrdid) {
+ thrds.emplace_back();
+ thrds[thrdid].id = new unsigned(thrdid);
+ if((thrdid + 0x1) == benoit::dat.numthrds) {
+ thrds[thrdid].rows = new unsigned(remainrows);
+ }
+ else {
+ thrds[thrdid].rows = new unsigned(benoit::dat.resy / benoit::dat.numthrds);
+ }
+ remainrows -= *thrds[thrdid].rows;
+ thrds[thrdid].thrd = new pthread_t;
+ ::pthread_create(thrds[thrdid].thrd,nullptr,::plotarea,&thrds[thrdid]);
+ benoit::log(fmt::format("Thread #{} has been created."s,thrdid));
}
- for(auto thread : threads) {
- ::pthread_join(thread,nullptr);
+ for(auto thrd : thrds) {
+ ::pthread_join(*thrd.thrd,nullptr);
+ benoit::log(fmt::format("Thread #{} has joined."s,*thrd.id));
+ delete thrd.id;
+ delete thrd.img;
+ delete thrd.rows;
+ delete thrd.thrd;
}
+ benoit::logfuncret(funcname);
return img;
}
diff --git a/src/benoit/print.cc b/src/benoit/print.cc
index 7f7901c..ab9547c 100644
--- a/src/benoit/print.cc
+++ b/src/benoit/print.cc
@@ -1,14 +1,18 @@
-# include <benoit.hh>
+# include <benoit/dat.hh>
+# include <benoit/print.hh>
# include <fcntl.h>
# include <stdexcept>
# include <string>
# include <unistd.h>
void benoit::print(char const * msg,bool stderr) {
std::string const funcname = "benoit::print(char const *)"s;
- this->print(std::string(msg),stderr);
+ benoit::print(std::string(msg),stderr);
}
void benoit::print(std::string msg,bool stderr) {
std::string const funcname = "benoit::print(std::string)"s;
+ if(benoit::dat.printdolog) {
+ benoit::dat.thelog.insert(benoit::dat.thelog.begin(),msg);
+ }
int file = 0x0;
if(stderr) {
::open("/dev/stderr",O_WRONLY);
diff --git a/src/benoit/t/pos/pos.cc b/src/benoit/t/pos/pos.cc
index 43941b2..f1237e0 100644
--- a/src/benoit/t/pos/pos.cc
+++ b/src/benoit/t/pos/pos.cc
@@ -1,4 +1,4 @@
-# include <benoit.hh>
+# include <benoit/t/pos.hh>
# include <boost/multiprecision/mpfr.hpp>
benoit::t::pos::pos(boost::multiprecision::mpfr_float x,boost::multiprecision::mpfr_float y) {
this->x = x;
diff --git a/src/benoit/~benoit.cc b/src/benoit/~benoit.cc
deleted file mode 100644
index b16b42d..0000000
--- a/src/benoit/~benoit.cc
+++ /dev/null
@@ -1,10 +0,0 @@
-# include <benoit.hh>
-# include <cstdlib>
-# include <string>
-# include <unistd.h>
-using namespace std::literals::string_literals;
-[[noreturn]] benoit::~benoit() noexcept {
- std::string const funcname = "benoit::~benoit()"s;
- this->notiffunc(funcname);
- this->exit(EXIT_SUCCESS);
-}
diff --git a/src/main.cc b/src/main.cc
index 6c5aaa8..a6341a6 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -1,4 +1,4 @@
-# include <benoit.hh>
+# include <benoit/main.hh>
int main(int const argc,char const * * argv) {
- ::benoit benoit(argc,argv);
+ benoit::main(argc,argv);
}