Skip to content

Commit

Permalink
Remove lfpAlloc dependency from public API and public struct definition.
Browse files Browse the repository at this point in the history
Suppress clang warnings.
  • Loading branch information
syoyo committed Oct 10, 2020
1 parent a40e9c2 commit da0b64f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
68 changes: 34 additions & 34 deletions experimental/tinyobj_loader_opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/*
The MIT License (MIT)
Copyright (c) 2012-2017 Syoyo Fujita and many contributors.
Copyright (c) 2012-2020 Syoyo Fujita and many contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -54,8 +54,6 @@ THE SOFTWARE.
#include <chrono> // C++11
#include <thread> // C++11

#include "lfpAlloc/Allocator.hpp"

namespace tinyobj_opt {

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -330,19 +328,19 @@ struct index_t {
};

typedef struct {
std::vector<float, lfpAlloc::lfpAllocator<float> > vertices;
std::vector<float, lfpAlloc::lfpAllocator<float> > normals;
std::vector<float, lfpAlloc::lfpAllocator<float> > texcoords;
std::vector<index_t, lfpAlloc::lfpAllocator<index_t> > indices;
std::vector<float> vertices;
std::vector<float> normals;
std::vector<float> texcoords;
std::vector<index_t> indices;

// # of vertices for each face.
// 3 for triangle, 4 for qual, ...
// If triangulation is enabled and the original face are quad,
// face_num_verts will be 6(3 + 3)
std::vector<int, lfpAlloc::lfpAllocator<int> > face_num_verts;
std::vector<int> face_num_verts;

// Per-face material IDs.
std::vector<int, lfpAlloc::lfpAllocator<int> > material_ids;
std::vector<int> material_ids;
} attrib_t;

typedef StackVector<char, 256> ShortString;
Expand Down Expand Up @@ -980,6 +978,33 @@ static void LoadMtl(std::map<std::string, int> *material_map,
materials->push_back(material);
}


class LoadOption {
public:
LoadOption() : req_num_threads(-1), triangulate(true), verbose(false) {}

int req_num_threads;
bool triangulate;
bool verbose;
};

/// Parse wavefront .obj(.obj string data is expanded to linear char array
/// `buf')
/// -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,
std::vector<material_t> *materials, const char *buf, size_t len,
const LoadOption &option);

} // namespace tinyobj_opt

#endif // TINOBJ_LOADER_OPT_H_

#ifdef TINYOBJ_LOADER_OPT_IMPLEMENTATION

#include "lfpAlloc/Allocator.hpp"

namespace tinyobj_opt {

typedef enum {
COMMAND_EMPTY,
COMMAND_V,
Expand All @@ -1000,7 +1025,6 @@ typedef struct {

// for f
std::vector<index_t, lfpAlloc::lfpAllocator<index_t> > f;
// std::vector<index_t> f;
std::vector<int, lfpAlloc::lfpAllocator<int> > f_num_verts;

const char *group_name;
Expand Down Expand Up @@ -1031,30 +1055,6 @@ struct CommandCount {
}
};

class LoadOption {
public:
LoadOption() : req_num_threads(-1), triangulate(true), verbose(false) {}

int req_num_threads;
bool triangulate;
bool verbose;
};

/// Parse wavefront .obj(.obj string data is expanded to linear char array
/// `buf')
/// -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,
std::vector<material_t> *materials, const char *buf, size_t len,
const LoadOption &option);

} // namespace tinyobj_opt

#endif // TINOBJ_LOADER_OPT_H_

#ifdef TINYOBJ_LOADER_OPT_IMPLEMENTATION

namespace tinyobj_opt {

static bool parseLine(Command *command, const char *p, size_t p_len,
bool triangulate = true) {
// @todo { operate directly on pointer `p'. to do that, add range check for
Expand Down
4 changes: 1 addition & 3 deletions experimental/viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,11 @@ int main(int argc, char **argv)
if (data == nullptr) {
printf("failed to load file\n");
exit(-1);
return false;
}

if (data_len < 4) {
printf("Empty file\n");
exit(-1);
return false;
}
printf("filesize: %d\n", (int)data_len);
tinyobj_opt::LoadOption option;
Expand All @@ -665,7 +663,7 @@ int main(int argc, char **argv)

bool ret = parseObj(&attrib, &shapes, &materials, data, data_len, option);

return ret;
return ret ? 0 : -1;
}

Init();
Expand Down

0 comments on commit da0b64f

Please sign in to comment.