Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some fixes #1308

Merged
merged 9 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ endif()
if(MSVC AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
message(STATUS "Clang on MSVC detected! Adding compile flags")
set(CMAKE_CXX_FLAGS
"-Xclang -fcxx-exceptions \
"${CMAKE_CXX_FLAGS} \
-Xclang -fcxx-exceptions \
-Xclang -fexceptions \
-Xclang -std=c++17 \
-Xclang -D_CRT_SECURE_NO_WARNINGS \
-mavx \
-Wno-c++11-narrowing -Wno-c++98-compat -W3")

# additional c++ flags for release mode for our projects
# linker flags
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:16000000,16384")

# additional c++ and linker flags for release mode for our projects
if(CMAKE_BUILD_TYPE MATCHES "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2")
elseif(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG")
endif()

# linker flags
set(CMAKE_EXE_LINKER_FLAGS "/STACK:16000000,16384")

elseif(UNIX)
message(STATUS "GCC detected! Adding compile flags")
set(CMAKE_CXX_FLAGS
Expand Down Expand Up @@ -69,17 +73,28 @@ elseif(MSVC)
# set(CMAKE_CXX_FLAGS_DEBUG "/ZI")
endif()
# c++ flags for all build types
set(CMAKE_CXX_FLAGS "/EHsc /utf-8 /arch:AVX")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /utf-8 /arch:AVX")

# linker flags
set(CMAKE_EXE_LINKER_FLAGS "/STACK:16000000,16384")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:16000000,16384")

# additional c++ and linker flags for specific build types
if(CMAKE_BUILD_TYPE MATCHES "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2")
elseif(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /DEBUG")
endif()
endif()

if(WIN32)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION 7.1.7600.0.30514) # win7.1, supports xp
message("Windows SDK version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
endif()

if(ASAN_BUILD)
Expand Down
19 changes: 19 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@
},
"vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } }
},
{
"name": "RelWithDebInfo-clang",
"displayName": "Windows RelWithDebInfo (clang-cl)",
"description": "Target Windows with the Visual Studio development environment.",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/Release",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"INSTALL_GTEST": "True",
"CMAKE_C_COMPILER": "clang-cl",
"CMAKE_CXX_COMPILER": "clang-cl"
},
"vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } }
},
{
"name": "Debug-msvc",
"displayName": "Windows Debug (msvc)",
Expand Down
3 changes: 2 additions & 1 deletion common/util/Serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstring>
#include <string>
#include <vector>
#include "common/common_types.h"
#include "common/util/Assert.h"

/*!
Expand Down Expand Up @@ -35,7 +36,7 @@ class Serializer {
* later be accessed with get_save_result.
*/
Serializer() : m_writing(true) {
const size_t initial_size = 32;
constexpr size_t initial_size = 32 * 1024 * 1024;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have a better fix for this. There's a silly bug so it resizes on every addition 🤦‍♂️

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this is fine for now

m_data = (u8*)malloc(initial_size);
m_size = initial_size;
}
Expand Down
5 changes: 4 additions & 1 deletion decompiler/ObjectFile/ObjectFileDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,14 @@ std::string ObjectFileDB::generate_obj_listing(const std::unordered_set<std::str
result += "[\"" + pad_string(name + "\", ", 50) + "\"" +
pad_string(x.name_in_dgo + "\", ", 50) + std::to_string(x.obj_version) + ", " +
dgos + ", \"\"],\n";
unique_count++;
if (all_unique_names.find(name) != all_unique_names.end() &&
merged_objs.find(name) == merged_objs.end()) {
lg::error("Object file {} appears multiple times with the same name.", name);
}
if (merged_objs.find(name) == merged_objs.end() ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for fixing this

all_unique_names.find(name) == all_unique_names.end()) {
unique_count++;
}
all_unique_names.insert(name);
}
}
Expand Down
6 changes: 3 additions & 3 deletions goal_src/engine/level/level.gc
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@
(let* ((level-info (lookup-level-info name))
(level-name (remap-level-name level-info))
)
(swhen (level-get obj level-name)
(level-status-set! bc want-status)
(return bc)
(awhen (level-get obj level-name)
(level-status-set! it want-status)
(return it)
)
(let ((a0-7 (level-get-most-disposable obj)))
(set! s5-1 (if a0-7 (level-status-set! a0-7 'inactive)
Expand Down
4 changes: 2 additions & 2 deletions goal_src/engine/load/loader.gc
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@
"Get the status of a file in this art control. #f = file not found"

(dotimes (i 2)
(swhen (file-status (-> obj buffer i) name part)
(return bc)
(awhen (file-status (-> obj buffer i) name part)
(return it)
)
)
#f
Expand Down
8 changes: 4 additions & 4 deletions goal_src/engine/sound/gsound.gc
Original file line number Diff line number Diff line change
Expand Up @@ -544,13 +544,13 @@
)
(case (-> src type)
((entity-actor entity-ambient)
(swhen (res-lump-struct-exact (the entity src) 'effect-name symbol)
(set! name (string->sound-name (symbol->string bc)))
(awhen (res-lump-struct-exact (the entity src) 'effect-name symbol)
(set! name (string->sound-name (symbol->string it)))
(set! sound-times (res-lump-data (the entity src) 'cycle-speed (pointer float)))
(set! spec *ambient-spec*)
(let ((tag (new 'static 'res-tag)))
(swhen (res-lump-data-exact (the entity src) 'effect-param sound-play-parms :tag-ptr (& tag))
(set! params bc)
(awhen (res-lump-data-exact (the entity src) 'effect-param sound-play-parms :tag-ptr (& tag))
(set! params it)
(set! param-count (the int (-> tag elt-count)))
)
)
Expand Down
20 changes: 14 additions & 6 deletions goal_src/goal-lib.gc
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,23 @@
)
)

(defmacro swhen (condition &rest body)
"Same as when, but saves the branch condition onto a variable named bc"
(defmacro aif (condition true false)
"Anaphoric if, similar to Common Lisp"

`(let ((bc ,condition))
(if bc
(begin ,@body)
`(let ((it ,condition))
(if it
,true
,false
)
)
)

(defmacro awhen (condition &rest body)
"Anaphoric when, similar to Common Lisp"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks dictionary, this makes it more clear
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, this is what I found first http://community.schemewiki.org/?anaphoric-if

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I don't think "anaphoric when" is a lisp thing, only "anaphoric if", so I'm kind of cheating)


`(aif ,condition (begin ,@body) #f)
)

(defmacro return (val)
`(return-from #f ,val)
)
Expand All @@ -460,7 +467,8 @@

(defmacro case (switch &key (comp =) &rest cases)
"A switch-case construct. switch is saved onto a local variable and compared against each case, sequentially.
else can be used like the 'default' case, but it must be the last one."
else can be used like the 'default' case, but it must be the last one.
comp is the function to use when evaluating the clauses. It can be any valid head of a form (operator or call)."

(with-gensyms (sw)
;; save the switch to a variable (only evaluated once)
Expand Down