Skip to content
This repository was archived by the owner on Aug 14, 2022. It is now read-only.

Commit 09339ea

Browse files
committed
implement flycam, traverse tree, fix bugs etc.
fix decoder, emscripten fetch, dxt crn, threading etc.
1 parent 84a0b2e commit 09339ea

21 files changed

+7059
-1094
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "client/imgui"]
2-
path = client/imgui
3-
url = https://github.com/ocornut/imgui
1+
[submodule "client/eigen"]
2+
path = client/eigen
3+
url = https://github.com/PX4/eigen

client/build.sh

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
#!/bin/sh
2-
CFLAGS="--std=c++11 -g -I. `pkg-config --cflags sdl2 protobuf` -I./imgui"
3-
LDFLAGS="`pkg-config --libs sdl2 protobuf`"
4-
if [ `uname` = "Darwin" ]; then
5-
LDFLAGS="$LDFLAGS -framework OpenGL"
2+
3+
if [ "$1" == "emscripten" ]; then
4+
source config_emscripten.sh
5+
echo build: emscripten
6+
pwd="$(pwd)" && cd .. && $EMSCRIPTEN_PROTOBUF_EXE --cpp_out=client proto/rocktree.proto && cd "$pwd"
7+
cd crn && emcc -std=c++14 -c crn.cc -w && cd ..
8+
9+
emcc -Iinclude main.cpp -O2 -std=c++14 -I. -I./eigen/ \
10+
-I$EMSCRIPTEN_PROTOBUF_SRC $EMSCRIPTEN_PROTOBUF_LIB crn/crn.o \
11+
-s USE_SDL=2 -s FETCH=1 -s TOTAL_MEMORY=1073741824 -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=4 \
12+
-o main.html
613
else
7-
CFLAGS="$CFLAGS -Igl2/include"
8-
LDFLAGS="$LDFLAGS -lGL -lm -ldl"
14+
echo build: native
15+
pwd="$(pwd)" && cd .. && ./makeproto.sh && cd "$pwd"
16+
cd crn && g++ -std=c++14 -c crn.cc -w && cd ..
17+
18+
CFLAGS="--std=c++14 -g -I. `pkg-config --cflags sdl2 protobuf` -I./eigen/"
19+
LDFLAGS="`pkg-config --libs sdl2 protobuf` crn/crn.o"
20+
if [ `uname` = "Darwin" ]; then
21+
CFLAGS="$CFLAGS `pkg-config --cflags glew`"
22+
LDFLAGS="$LDFLAGS `pkg-config --static --libs glew` -framework OpenGL"
23+
echo "$CFLAGS"
24+
echo "$LDFLAGS"
25+
else
26+
CFLAGS="$CFLAGS -Igl2/include"
27+
LDFLAGS="$LDFLAGS -lGL -lm -ldl"
28+
fi
29+
c++ $CFLAGS main.cpp $LDFLAGS -o main
930
fi
10-
c++ $CFLAGS main.cpp $LDFLAGS -o main

client/config_emscripten.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
EMSCRIPTEN_PROTOBUF_SRC="$(echo ~)/Downloads/protobuf/src"
4+
EMSCRIPTEN_PROTOBUF_LIB="$(echo ~)/Downloads/protobuf/src/.libs/libprotobuf.a"
5+
EMSCRIPTEN_PROTOBUF_EXE="$(echo ~)/Downloads/protoc-3.9.2-osx-x86_64/bin/protoc"

client/crn/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
g++ -c crn.cc

client/crn/crn.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <stddef.h>
2+
#include <cstring>
3+
#include <stdint.h>
4+
#include "crn_decomp.h"
5+
6+
extern "C" {
7+
unsigned int crn_get_decompressed_size(const void *src, unsigned int src_size, unsigned int level_index);
8+
void crn_decompress(const void *src, unsigned int src_size, void *dst, unsigned int dst_size, unsigned int level_index);
9+
}
10+
11+
unsigned int crn_get_decompressed_size(const void *src, unsigned int src_size, unsigned int level_index) {
12+
crnd::crn_texture_info tex_info;
13+
crnd::crnd_get_texture_info(static_cast<const crn_uint8*>(src), src_size, &tex_info);
14+
const crn_uint32 width = tex_info.m_width >> level_index;
15+
const crn_uint32 height = tex_info.m_height >> level_index;
16+
const crn_uint32 blocks_x = (width + 3) >> 2;
17+
const crn_uint32 blocks_y = (height + 3) >> 2;
18+
const crn_uint32 row_pitch = blocks_x * crnd::crnd_get_bytes_per_dxt_block(tex_info.m_format);
19+
const crn_uint32 total_face_size = row_pitch * blocks_y;
20+
return total_face_size;
21+
}
22+
23+
void crn_decompress(const void *src, unsigned int src_size, void *dst, unsigned int dst_size, unsigned int level_index) {
24+
crnd::crn_texture_info tex_info;
25+
crnd::crnd_get_texture_info(static_cast<const crn_uint8*>(src), src_size, &tex_info);
26+
const crn_uint32 width = tex_info.m_width >> level_index;
27+
const crn_uint32 height = tex_info.m_height >> level_index;
28+
const crn_uint32 blocks_x = (width + 3) >> 2;
29+
const crn_uint32 blocks_y = (height + 3) >> 2;
30+
const crn_uint32 row_pitch = blocks_x * crnd::crnd_get_bytes_per_dxt_block(tex_info.m_format);
31+
crnd::crnd_unpack_context pContext = crnd::crnd_unpack_begin(static_cast<const crn_uint8*>(src), src_size);
32+
void *pDecomp_images[1];
33+
pDecomp_images[0] = dst;
34+
crnd::crnd_unpack_level(pContext, pDecomp_images, dst_size, row_pitch, level_index);
35+
crnd::crnd_unpack_end(pContext);
36+
}

client/crn/crn.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <stddef.h>
2+
#include <cstring>
3+
4+
extern "C" {
5+
unsigned int crn_get_decompressed_size(const void *src, unsigned int src_size, unsigned int level_index);
6+
void crn_decompress(const void *src, unsigned int src_size, void *dst, unsigned int dst_size, unsigned int level_index);
7+
}

0 commit comments

Comments
 (0)