Skip to content

Commit

Permalink
Enable Windows build of habitat-sim
Browse files Browse the repository at this point in the history
  • Loading branch information
cegbertOculus committed Jun 21, 2019
1 parent bb87a9f commit 2a9deaa
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 19 deletions.
17 changes: 9 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def is_pip():
class CMakeExtension(Extension):
def __init__(self, name, sourcedir=""):
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
self.sourcedir = os.path.abspath(sourcedir).replace('\\','/')


class CMakeBuild(build_ext):
Expand Down Expand Up @@ -177,8 +177,8 @@ def build_extension(self, ext):
)

cmake_args = [
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir,
"-DPYTHON_EXECUTABLE=" + sys.executable,
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir.replace('\\','/'),
"-DPYTHON_EXECUTABLE=" + sys.executable.replace('\\','/'),
"-DCMAKE_EXPORT_COMPILE_COMMANDS={}".format("OFF" if is_pip() else "ON"),
]
cmake_args += shlex.split(args.cmake_args)
Expand All @@ -196,8 +196,9 @@ def build_extension(self, ext):
# doesn't require a number (but builds sequentially by default), so we
# add the argument only when it's not ninja or the number of jobs is
# specified.
if not has_ninja() or self.parallel:
build_args += ["-j{}".format(self.parallel) if self.parallel else "-j"]
if sys.platform != "win32":
if not has_ninja() or self.parallel:
build_args += ["-j{}".format(self.parallel) if self.parallel else "-j"]

cmake_args += [
"-DBUILD_GUI_VIEWERS={}".format("ON" if not args.headless else "OFF")
Expand All @@ -211,13 +212,13 @@ def build_extension(self, ext):

if self.run_cmake(cmake_args):
subprocess.check_call(
shlex.split("cmake -H{} -B{}".format(ext.sourcedir, self.build_temp))
shlex.split("cmake -H{} -B{}".format(ext.sourcedir, self.build_temp.replace('\\','/')))
+ cmake_args,
env=env,
)

subprocess.check_call(
shlex.split("cmake --build {}".format(self.build_temp)) + build_args
shlex.split("cmake --build {}".format(self.build_temp.replace('\\','/'))) + build_args
)
print() # Add an empty line for cleaner output

Expand All @@ -226,7 +227,7 @@ def build_extension(self, ext):
return

if not args.headless:
link_dst = osp.join(self.build_temp, "viewer")
link_dst = osp.join(self.build_temp, "viewer").replace('\\','/')
if not osp.islink(link_dst):
os.symlink(
osp.abspath(osp.join(self.build_temp, "utils/viewer/viewer")),
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.10)
project(esp)

if(MSVC)
add_definitions(/DNOMINMAX)
add_definitions(/DNOMINMAX /D_USE_MATH_DEFINES /DEIGEN_DONT_ALIGN_STATICALLY)
endif()

find_program(CCACHE_FOUND ccache)
Expand Down
3 changes: 1 addition & 2 deletions src/esp/assets/FRLInstanceMeshData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
#include <vector>

#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>

#include <fstream>
#include <sstream>
#include <unordered_map>
Expand Down
2 changes: 0 additions & 2 deletions src/esp/assets/GenericInstanceMeshData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include <vector>

#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fstream>
#include <sstream>
#include <unordered_map>
Expand Down
57 changes: 54 additions & 3 deletions src/esp/assets/PTexMeshData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,59 @@
#include "PTexMeshData.h"

#include <fcntl.h>
#ifndef _WIN32
#include <sys/mman.h>
#include <unistd.h>
#else
#include <io.h>
#include <Windows.h>

#define PROT_READ 1
#define MAP_PRIVATE 4

// Note: This is not a full implementation of mmap/munmap. It is is only meant to work in limited scenarios
void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t off) {

ASSERT(prot == PROT_READ && flags == MAP_PRIVATE);

DWORD newProt = PAGE_READONLY;

void* ret;

HANDLE h = INVALID_HANDLE_VALUE;
h = (HANDLE)_get_osfhandle(fd);

HANDLE fmh = CreateFileMapping(
h,
nullptr,
newProt | SEC_COMMIT | SEC_RESERVE,
(DWORD)((length >> 32) & 0xFFFFFFFF),
(DWORD)(length & 0xFFFFFFFF),
nullptr);
ret = MapViewOfFileEx(
fmh,
FILE_MAP_ALL_ACCESS,
(DWORD)((off >> 32) & 0xFFFFFFFF),
(DWORD)(off & 0xFFFFFFFF),
0,
addr);
if (ret == nullptr) {
ret = NULL;
}
CloseHandle(fmh);

return ret;
}

int munmap(void* addr, size_t length) {
// Try to unmap it as a file.
if (!UnmapViewOfFile(addr)) {
return -1;
}
return 0;
}
#endif

#include <fstream>
#include <sstream>
#include <unordered_map>
Expand Down Expand Up @@ -93,7 +144,7 @@ std::vector<PTexMeshData::MeshData> splitMesh(

// calculate vertex grid position and code
#pragma omp parallel for
for (size_t i = 0; i < mesh.vbo.size(); i++) {
for (int32_t i = 0; i < mesh.vbo.size(); i++) {
const vec3f p = mesh.vbo[i].head<3>();
vec3f pi = (p - boundingBox.min()) / splitSize;
verts[i] = EncodeMorton3(pi.cast<int>());
Expand All @@ -112,7 +163,7 @@ std::vector<PTexMeshData::MeshData> splitMesh(
faces.resize(numFaces);

#pragma omp parallel for
for (size_t i = 0; i < numFaces; i++) {
for (int32_t i = 0; i < numFaces; i++) {
faces[i].originalFace = i;
faces[i].code = std::numeric_limits<uint32_t>::max();
for (int j = 0; j < 4; j++) {
Expand Down Expand Up @@ -158,7 +209,7 @@ std::vector<PTexMeshData::MeshData> splitMesh(
}

#pragma omp parallel for
for (size_t i = 0; i < numChunks; i++) {
for (int32_t i = 0; i < numChunks; i++) {
uint32_t chunkSize = chunkStart[i + 1] - chunkStart[i];

std::vector<uint32_t> refdVerts;
Expand Down
1 change: 0 additions & 1 deletion src/esp/gfx/PTexMeshShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "PTexMeshShader.h"

#include <fcntl.h>
#include <sys/mman.h>
#include <iostream>

#include <Corrade/Containers/Reference.h>
Expand Down
2 changes: 1 addition & 1 deletion src/esp/gfx/WindowlessContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#elif __win32__
#elif __win32__ || defined(_WIN32)
#include <Magnum/Platform/WindowlessWglApplication.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/esp/nav/PathFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class dtQueryPathState;
namespace esp {
// forward declaration
namespace assets {
class MeshData;
struct MeshData;
}
namespace nav {

Expand Down

0 comments on commit 2a9deaa

Please sign in to comment.