Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/aardappel/lobster
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaisiero committed Jan 11, 2025
2 parents c533ac0 + f727014 commit 8ad4e7c
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 109 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
cxx: [g++-12, clang++-14]
cxx: [g++-14, clang++-18]
include:
- cxx: g++-12
cc: gcc-12
- cxx: clang++-14
cc: clang-14
- cxx: g++-14
cc: gcc-14
- cxx: clang++-18
cc: clang-18
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v4
Expand All @@ -29,7 +29,7 @@ jobs:
- name: apt update
run: sudo apt-get -o Acquire::Retries=3 update
- name: install opengl
run: sudo apt-get -o Acquire::Retries=3 install mesa-common-dev libgl1-mesa-dev libgl1-mesa-glx
run: sudo apt-get -o Acquire::Retries=3 install mesa-common-dev libgl1-mesa-dev libgl1 libglx-mesa0 libxext-dev
- name: cmake
working-directory: dev
run: CXX=${{ matrix.cxx }} CC=${{ matrix.cc }} cmake -DCMAKE_BUILD_TYPE=Release -DLOBSTER_WERROR=ON .
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
# Without engine should speed this up.
- name: cmake
working-directory: dev
run: CXX=clang++-14 CC=clang-14 cmake -DCMAKE_BUILD_TYPE=Release -DLOBSTER_WERROR=ON -DLOBSTER_ENGINE=OFF .
run: CXX=clang++-18 CC=clang-18 cmake -DCMAKE_BUILD_TYPE=Release -DLOBSTER_WERROR=ON -DLOBSTER_ENGINE=OFF .
- name: build
working-directory: dev
run: make -j4
Expand Down Expand Up @@ -158,7 +158,7 @@ jobs:
# Without engine should speed this up.
- name: cmake
working-directory: dev
run: CXX=clang++-14 CC=clang-14 cmake -DCMAKE_BUILD_TYPE=Release -DLOBSTER_WERROR=ON -DLOBSTER_ENGINE=OFF .
run: CXX=clang++-18 CC=clang-18 cmake -DCMAKE_BUILD_TYPE=Release -DLOBSTER_WERROR=ON -DLOBSTER_ENGINE=OFF .
- name: build
working-directory: dev
run: make -j4
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
cxx: [clang++-14]
cxx: [clang++-18]
include:
- cxx: clang++-14
cc: clang-14
- cxx: clang++-18
cc: clang-18
steps:
- uses: actions/checkout@v1
- name: apt update
run: sudo apt-get -o Acquire::Retries=3 update
- name: install opengl
run: sudo apt-get -o Acquire::Retries=3 install mesa-common-dev libgl1-mesa-dev libgl1-mesa-glx
run: sudo apt-get -o Acquire::Retries=3 install mesa-common-dev libgl1-mesa-dev libgl1 libglx-mesa0 libxext-dev
- name: cmake
working-directory: dev
run: CXX=${{ matrix.cxx }} CC=${{ matrix.cc }} cmake -DCMAKE_BUILD_TYPE=Release -DLOBSTER_WERROR=ON .
Expand Down
9 changes: 3 additions & 6 deletions dev/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -std=c++17 -stdlib=libstdc++ ${COMMON_GCC_STYLE}")
elseif(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -std=c++17 ${COMMON_GCC_STYLE}")
# These warnings seem pretty broken in GCC, with lots of false positives.
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -std=c++17 ${COMMON_GCC_STYLE} -Wno-array-bounds -Wno-stringop-overflow -Wno-maybe-uninitialized")
endif()
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FS")
Expand Down Expand Up @@ -216,10 +217,6 @@ endif()

# Turn off warnings for files we don't control.
set_source_files_properties(${EXTERNAL_SRCS} PROPERTIES COMPILE_FLAGS -w)
if(CMAKE_COMPILER_IS_GNUCXX)
# surpress warnings from included stb file..
set_source_files_properties(src/sdlaudiosfxr.cpp PROPERTIES COMPILE_FLAGS -Wno-maybe-uninitialized)
endif()

function(removecpp CPPNAME)
list(REMOVE_ITEM LOBSTER_SRCS "src/${CPPNAME}.cpp")
Expand Down
2 changes: 1 addition & 1 deletion dev/emscripten/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ OPTLEVEL= -O3 -DNDEBUG -s ASSERTIONS=0

CFLAGS= $(OPTLEVEL)
CXXFLAGS= $(OPTLEVEL)
SHAREDFLAGS= -s USE_SDL=2 -s USE_SDL_MIXER=0 -s USE_FREETYPE=1 -s NO_EXIT_RUNTIME=1 \
SHAREDFLAGS= -s USE_SDL=2 -s USE_SDL_MIXER=0 -s USE_FREETYPE=1 -s \
-Wall -pedantic -Wno-switch \
-Wno-array-bounds -Wno-gnu-anonymous-struct -Wno-nested-anon-types
override CFLAGS+= $(SHAREDFLAGS)
Expand Down
7 changes: 5 additions & 2 deletions dev/lsp/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ export class LobsterDocument implements TextDocument {
return join;
}

public async parse(lsp: LSPInstance): Promise<Diagnostic[]> {
public async parse(lsp: LSPInstance|undefined): Promise<Diagnostic[]> {
if(lsp == undefined) { //Not ready
return []
}
const settings = await lsp.getDocumentSettings(this._uri);
if (lsp.errored()) return [];

Expand Down Expand Up @@ -347,4 +350,4 @@ function getWellformedEdit(textEdit: TextEdit): TextEdit {
return { newText: textEdit.newText, range };
}
return textEdit;
}
}
4 changes: 2 additions & 2 deletions dev/lsp/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { MarkupContent, MarkupKind } from 'vscode-languageserver';
import { LobsterSignature } from './lobster';

export function getWordOnCursor(text: string, character: number): [string | null, number] {
const part1 = text.substring(0, character).match(/[a-zA-Z0-9-_\\.]+$/);
const part2 = text.substring(character).match(/^[a-zA-Z0-9-_\\.]+/);
const part1 = text.substring(0, character).match(/[a-zA-Z0-9_\\.]+$/);
const part2 = text.substring(character).match(/^[a-zA-Z0-9_]+/);

if (!part1 && !part2) return [null, 0];
return [
Expand Down
2 changes: 0 additions & 2 deletions dev/src/builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,11 @@ nfr("remove_range", "xs,i,n", "A]*II", "",
nfr("remove_obj", "xs,obj", "A]*A1", "Ab2",
"remove all elements equal to obj (==), returns obj.",
[](StackPtr &, VM &vm, Value &l, Value &o) {
iint removed = 0;
auto vt = vm.GetTypeInfo(l.vval()->ti(vm).subt).t;
for (iint i = 0; i < l.vval()->len; i++) {
auto e = l.vval()->At(i);
if (e.Equal(vm, vt, o, vt, false)) {
l.vval()->Remove(vm, i--, 1);
removed++;
}
}
return o;
Expand Down
8 changes: 4 additions & 4 deletions dev/src/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ string BuildPakFile(string &pakfile, string &bytecode, set<string> &files, uint6
pat = filename.substr(pos + 1);
base = filename.substr(0, pos);
}
vector<pair<string, int64_t>> dir;
vector<DirInfo> dir;
if (!ScanDir(base, dir)) return "cannot load file/dir for pakfile: " + filename;
for (auto &[name, size] : dir) {
if (!pat.empty() && name.find(pat) == name.npos) continue;
for (auto &entry : dir) {
if (!pat.empty() && entry.name.find(pat) == entry.name.npos) continue;
auto fn = base;
if (fn.back() != '/') fn += "/";
fn += name;
fn += entry.name;
auto err = addrec(fn);
if (!err.empty()) return err;
}
Expand Down
9 changes: 1 addition & 8 deletions dev/src/cubegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,6 @@ nfr("average_face_colors", "world", "R:voxels", "F]",
auto dim = dims[f % 3];
auto positive_dir = f < 3;
float3 col(0.0f);
int ntransparent = 0;
int nsurf = 0;
// XY iterate the face, Z goes into the face.
for (int x = 0; x < v.grid.dim[dim[0]]; x++) {
Expand All @@ -1335,9 +1334,7 @@ nfr("average_face_colors", "world", "R:voxels", "F]",
pos[dim[1]] = y;
pos[dim[2]] = positive_dir ? z : dimz - 1 - z;
uint8_t c = v.grid.Get(pos);
if (c == transparant) {
ntransparent++;
} else {
if (c != transparant) {
if (!cache_set[c]) {
srgb_cache[c] = from_srgb(float3(palette[c].xyz()) / 255.0f);
cache_set[c] = true;
Expand All @@ -1350,8 +1347,6 @@ nfr("average_face_colors", "world", "R:voxels", "F]",
}
}
if (nsurf) col /= float(nsurf);
//auto vol = v.grid.dim.volume();
//auto alpha = float(vol - ntransparent) / float(vol);
auto surf_alpha = float(nsurf) / float(v.grid.dim[dim[0]] * v.grid.dim[dim[1]]);
vec->Push(vm, col.x);
vec->Push(vm, col.y);
Expand Down Expand Up @@ -1572,7 +1567,6 @@ nfr("normal_indices", "block,radius", "R:voxelsI", "R:voxels",
int3(0, 0, 1), int3(0, 0, -1), int3(0, 1, 0),
int3(0, -1, 0), int3(1, 0, 0), int3(-1, 0, 0),
};
int num_surface_voxels = 0;
for (int x = 0; x < v.grid.dim.x; x++) {
for (int y = 0; y < v.grid.dim.y; y++) {
for (int z = 0; z < v.grid.dim.z; z++) {
Expand All @@ -1595,7 +1589,6 @@ nfr("normal_indices", "block,radius", "R:voxelsI", "R:voxels",
visible:;
}
// For surface voxels we compute a normal.
num_surface_voxels++;
auto cn = ComputeNormal(pos, radius);
if (manhattan(cn) <= 1) {
// Most normals cancelled eachother out, let's try once more
Expand Down
80 changes: 72 additions & 8 deletions dev/src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#include <unistd.h>
#endif

#include <chrono>
#include <version>
#include <time.h>

namespace lobster {

template<typename T, bool B> T Read(VM &vm, iint i, const LString *s) {
Expand Down Expand Up @@ -132,28 +136,88 @@ Value ParseSchemas(VM &vm, flatbuffers::Parser &parser, const Value &schema,

void AddFile(NativeRegistry &nfr) {

nfr("scan_folder", "folder,rel", "SB?", "S]?I]?",
"returns two vectors representing all elements in a folder, the first vector containing all"
" names, the second vector containing sizes in bytes (or -1 if a directory)."
nfr("format_time", "format,time,localtime", "SIB", "S",
"convert a time in seconds since 00:00:00 UTC, Thursday, 1 January 1970 into a string,"
" using the same format string syntax as POSIX strftime. If localtime is true, then"
" the time will be displayed using the local timezone, otherwise it will use UTC."
" Returns an empty string on error.",
[](StackPtr &, VM &vm, Value &format, Value &time, Value &use_localtime) {
chrono::system_clock::time_point tp { chrono::system_clock::duration(time.ival()) };
time_t tt = chrono::system_clock::to_time_t(tp);
tm ctm{};
bool ok = false;
#ifdef _WIN32
ok = (use_localtime.True() ? localtime_s(&ctm, &tt) : gmtime_s(&ctm, &tt)) == 0;
#else
ok = (use_localtime.True() ? localtime_r(&tt, &ctm) : gmtime_r(&tt, &ctm)) != nullptr;
#endif
if (!ok) return Value(vm.NewString(0));
// TODO: using strftime to avoid pulling in std::format(); maybe we should reconsider that?
char buf[1024];
auto written = strftime(buf, sizeof(buf), format.sval()->data(), &ctm);
// TODO: written may be zero if the format string was too long; in that
// case maybe we want to try again with a larger buf?
if (written == 0) return Value(vm.NewString(0));
auto s = vm.NewString(buf);
return Value(s);
});

nfr("scan_folder", "folder,rel", "SB?", "S]?I]?I]?",
"returns three vectors representing all elements in a folder, the first vector containing all"
" names, the second vector containing sizes in bytes (or -1 if a directory), and the third as"
" the number of seconds since 00:00:00 UTC, Thursday, 1 January 1970, not including leap seconds."
" set rel use a relative path, default is absolute."
" Returns nil if folder couldn't be scanned.",
[](StackPtr &sp, VM &vm, Value &fld, Value &rel) {
vector<pair<string, int64_t>> dir;
vector<DirInfo> dir;
auto ok = rel.True()
? ScanDir(fld.sval()->strv(), dir)
: ScanDirAbs(fld.sval()->strv(), dir);
if (!ok) {
Push(sp, NilVal());
Push(sp, NilVal());
return NilVal();
}
auto nlist = (LVector *)vm.NewVec(0, 0, TYPE_ELEM_VECTOR_OF_STRING);
auto slist = (LVector *)vm.NewVec(0, 0, TYPE_ELEM_VECTOR_OF_INT);
for (auto &[name, size] : dir) {
nlist->Push(vm, Value(vm.NewString(name)));
slist->Push(vm, Value(size));
auto tlist = (LVector *)vm.NewVec(0, 0, TYPE_ELEM_VECTOR_OF_INT);
for (auto &entry : dir) {
nlist->Push(vm, Value(vm.NewString(entry.name)));
slist->Push(vm, Value(entry.size));
// For a fun change of pace, MSVC C++ standard library has support
// for clock_cast but libstdc++ and libc++ don't. This is a
// workaround for converting between the file_clock time (used for
// the filesystem) and system_clock time (used for formatting
// times). Sadly, even if we could use clock_cast, it seems to have
// a known memory leak on Windows:
// See https://developercommunity.visualstudio.com/t/reported-memory-leak-when-converting-file-time-typ/1467739
//
// According to https://stackoverflow.com/a/73748610 (written by Howard Hinnant,
// the designer of the chrono library):
// "I believe the Windows file_clock epoch is 1601-01-01 00:00:00 UTC. The
// difference between that and the system_clock epoch (1970-01-01 00:00:00
// UTC) is 13,4774 days or 3'234'576h."
using namespace literals;
#if defined(_WIN32)
const chrono::duration file_to_system_clock_epoch_offset = 3'234'576h;
#elif defined(__GLIBCXX__) // libstdc++
// From the same stack overflow article above: "On gcc I believe
// the epoch is 2174-01-01 00:00:00 UTC".
// I calculated the following value locally on my linux laptop.
const chrono::duration file_to_system_clock_epoch_offset = -1'788'240h;
#else // libc++ or other
const chrono::duration file_to_system_clock_epoch_offset = 0h;
#endif
auto system_time = chrono::system_clock::time_point{
chrono::duration_cast<chrono::system_clock::duration>(
entry.last_write_time.time_since_epoch() -
file_to_system_clock_epoch_offset)
};
tlist->Push(vm, Value((int64_t)system_time.time_since_epoch().count()));
}
Push(sp, Value(nlist));
return Value(slist);
Push(sp, Value(slist));
return Value(tlist);
});

nfr("read_file", "file,textmode", "SI?", "S?",
Expand Down
3 changes: 3 additions & 0 deletions dev/src/imbind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,15 +698,18 @@ void DumpStackTrace(VM &vm) {

auto cur_fileidx = vm.last_fileidx;
auto cur_line = vm.last_line;
int i = 0;
for (auto &funstackelem : reverse(vm.fun_id_stack)) {
auto [name, fip] = vm.DumpStackFrameStart(funstackelem.funstartinfo, cur_fileidx, cur_line);
ImGui::PushID(i++);
if (ImGui::TreeNode(name.c_str())) {
if (BeginTable(name.c_str())) {
vm.DumpStackFrame(fip, funstackelem.locals, dumper);
EndTable();
}
ImGui::TreePop();
}
ImGui::PopID();
cur_fileidx = funstackelem.fileidx;
cur_line = funstackelem.line;
}
Expand Down
12 changes: 10 additions & 2 deletions dev/src/lobster/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <filesystem>

// Platform independent file access:
typedef int64_t (* FileLoader)(string_view_nt absfilename, string *dest, int64_t start, int64_t len);

Expand Down Expand Up @@ -52,8 +54,14 @@ extern string SanitizePath(string_view path);
extern void AddPakFileEntry(string_view pakfilename, string_view relfilename, int64_t off,
int64_t len, int64_t uncompressed);

extern bool ScanDir(string_view reldir, vector<pair<string, int64_t>> &dest);
extern bool ScanDirAbs(string_view absdir, vector<pair<string, int64_t>> &dest);
struct DirInfo {
string name;
int64_t size = 0;
filesystem::file_time_type last_write_time;
};

extern bool ScanDir(string_view reldir, vector<DirInfo> &dest);
extern bool ScanDirAbs(string_view absdir, vector<DirInfo> &dest);

extern iint LaunchSubProcess(const char **cmdl, const char *stdins, string &out);

Expand Down
3 changes: 0 additions & 3 deletions dev/src/lobster/polyreduce.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ inline void PolyReduce(vector<int> &triangles, vector<mgvert> &verts) {
vertmap[ovi] = vi;
}
}
int flipped = 0;
for (size_t t = 0; t < triangles.size(); t += 3) {
for (int i = 0; i < 3; i++) {
int vi1 = triangles[t + i];
Expand All @@ -94,12 +93,10 @@ inline void PolyReduce(vector<int> &triangles, vector<mgvert> &verts) {
dot(-v23m, -v13m) > maxtricornerdot) {
vertmap[vertmap[vi1]] = -1;
vertmap[vi1] = -1;
flipped++;
}
}
}
}
//LOG_DEBUG("flipped tris: ", flipped);
for (size_t t = 0; t < triangles.size(); t += 3) {
int keep = -1;
for (int i = 0; i < 3; i++) {
Expand Down
2 changes: 1 addition & 1 deletion dev/src/meshgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ struct Group : ImplicitFunctionImpl<Group> {
static inline float Eval(const float3 & /*pos*/) { return 0.0f; }

float3 Size() override {
float3 p1, p2;
float3 p1(0.0f), p2(0.0f);
for (auto c : children) {
auto csz = c->Size();
csz = rotated_size(c->rot, csz);
Expand Down
Loading

0 comments on commit 8ad4e7c

Please sign in to comment.