Apply clang-format.

This commit is contained in:
Syoyo Fujita
2016-08-12 20:39:42 +09:00
parent 8ca2bc0de7
commit 673501749f
2 changed files with 36 additions and 39 deletions

View File

@@ -602,8 +602,7 @@ static inline float parseFloat(const char **token) {
float f = static_cast<float>(atof(*token)); float f = static_cast<float>(atof(*token));
(*token) += strcspn((*token), " \t\r"); (*token) += strcspn((*token), " \t\r");
#else #else
const char *end = const char *end = (*token) + until_space((*token));
(*token) + until_space((*token));
double val = 0.0; double val = 0.0;
tryParseDouble((*token), end, &val); tryParseDouble((*token), end, &val);
float f = static_cast<float>(val); float f = static_cast<float>(val);
@@ -924,30 +923,28 @@ struct CommandCount {
} }
}; };
class class LoadOption {
LoadOption
{
public: public:
LoadOption() : req_num_threads(-1), triangulate(true), verbose(false) {} LoadOption() : req_num_threads(-1), triangulate(true), verbose(false) {}
int req_num_threads;
bool triangulate;
bool verbose;
int req_num_threads;
bool triangulate;
bool verbose;
}; };
/// Parse wavefront .obj(.obj string data is expanded to linear char array /// Parse wavefront .obj(.obj string data is expanded to linear char array
/// `buf') /// `buf')
/// -1 to req_num_threads use the number of HW threads in the running system. /// -1 to req_num_threads use the number of HW threads in the running system.
bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes, const char *buf, bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes, const char *buf,
size_t len, const LoadOption& option); size_t len, const LoadOption &option);
#ifdef TINYOBJ_LOADER_OPT_IMPLEMENTATION #ifdef TINYOBJ_LOADER_OPT_IMPLEMENTATION
static bool parseLine(Command *command, const char *p, size_t p_len, static bool parseLine(Command *command, const char *p, size_t p_len,
bool triangulate = true) { bool triangulate = true) {
// @todo { operate directly on pointer `p'. to do that, add range check for string operatoion against `p', since `p' is not null-terminated at p[p_len] } // @todo { operate directly on pointer `p'. to do that, add range check for
// string operatoion against `p', since `p' is not null-terminated at p[p_len]
// }
char linebuf[4096]; char linebuf[4096];
assert(p_len < 4095); assert(p_len < 4095);
memcpy(linebuf, p, p_len); memcpy(linebuf, p, p_len);
@@ -1141,8 +1138,7 @@ static inline bool is_line_ending(const char *p, size_t i, size_t end_i) {
} }
bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes, const char *buf, bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes, const char *buf,
size_t len, const LoadOption& option) size_t len, const LoadOption &option) {
{
attrib->vertices.clear(); attrib->vertices.clear();
attrib->normals.clear(); attrib->normals.clear();
attrib->texcoords.clear(); attrib->texcoords.clear();
@@ -1153,14 +1149,15 @@ bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes, const char *buf,
if (len < 1) return false; if (len < 1) return false;
auto num_threads = (option.req_num_threads < 0) ? std::thread::hardware_concurrency() auto num_threads = (option.req_num_threads < 0)
: option.req_num_threads; ? std::thread::hardware_concurrency()
: option.req_num_threads;
num_threads = num_threads =
std::max(1, std::min(static_cast<int>(num_threads), kMaxThreads)); std::max(1, std::min(static_cast<int>(num_threads), kMaxThreads));
if (option.verbose) { if (option.verbose) {
std::cout << "# of threads = " << num_threads << std::endl; std::cout << "# of threads = " << num_threads << std::endl;
} }
auto t1 = std::chrono::high_resolution_clock::now(); auto t1 = std::chrono::high_resolution_clock::now();
@@ -1543,21 +1540,21 @@ bool parseObj(attrib_t *attrib, std::vector<shape_t> *shapes, const char *buf,
} }
std::chrono::duration<double, std::milli> ms_total = t4 - t1; std::chrono::duration<double, std::milli> ms_total = t4 - t1;
if (option.verbose) { if (option.verbose) {
std::cout << "total parsing time: " << ms_total.count() << " ms\n"; std::cout << "total parsing time: " << ms_total.count() << " ms\n";
std::cout << " line detection : " << ms_linedetection.count() << " ms\n"; std::cout << " line detection : " << ms_linedetection.count() << " ms\n";
std::cout << " alloc buf : " << ms_alloc.count() << " ms\n"; std::cout << " alloc buf : " << ms_alloc.count() << " ms\n";
std::cout << " parse : " << ms_parse.count() << " ms\n"; std::cout << " parse : " << ms_parse.count() << " ms\n";
std::cout << " merge : " << ms_merge.count() << " ms\n"; std::cout << " merge : " << ms_merge.count() << " ms\n";
std::cout << " construct : " << ms_construct.count() << " ms\n"; std::cout << " construct : " << ms_construct.count() << " ms\n";
std::cout << " mtl load : " << ms_load_mtl.count() << " ms\n"; std::cout << " mtl load : " << ms_load_mtl.count() << " ms\n";
std::cout << "# of vertices = " << attrib->vertices.size() << std::endl; std::cout << "# of vertices = " << attrib->vertices.size() << std::endl;
std::cout << "# of normals = " << attrib->normals.size() << std::endl; std::cout << "# of normals = " << attrib->normals.size() << std::endl;
std::cout << "# of texcoords = " << attrib->texcoords.size() << std::endl; std::cout << "# of texcoords = " << attrib->texcoords.size() << std::endl;
std::cout << "# of face indices = " << attrib->faces.size() << std::endl; std::cout << "# of face indices = " << attrib->faces.size() << std::endl;
std::cout << "# of faces = " << attrib->material_ids.size() << std::endl; std::cout << "# of faces = " << attrib->material_ids.size() << std::endl;
std::cout << "# of shapes = " << shapes->size() << std::endl; std::cout << "# of shapes = " << shapes->size() << std::endl;
} }
return true; return true;
} }

View File

@@ -86,7 +86,7 @@ static void vsub(const float *src1, const float *src2, float *dst) {
} }
static void vcopy(const float *v1, float *v2) { static void vcopy(const float *v1, float *v2) {
register int i; int i;
for (i = 0; i < 3; i++) for (i = 0; i < 3; i++)
v2[i] = v1[i]; v2[i] = v1[i];
} }