Commit graph

54 commits

Author SHA1 Message Date
Andrei Alexeyev
56f0fde7c6
util/compat: fix windows UNICODE defines 2024-09-10 14:31:55 +02:00
Andrei Alexeyev
fa2c13d116
util/compat: workaround for clangd in gcc-based build dirs 2024-08-30 11:52:47 +02:00
Andrei Alexeyev
8b37d1cbf2
src: the great #include massacre of 2024 2024-05-17 14:11:48 +02:00
Andrei Alexeyev
be7905d6a3
src: run upkeep 2024-05-17 04:58:47 +02:00
Andrei Alexeyev
15bdbc496b
util/compat: include assert(0) in UNREACHABLE macro
Stop overriding it in log.h
2023-03-26 03:14:07 +02:00
Andrei Alexeyev
9363c6b883
util/compat: don't check for __GNUC__ 2023-03-26 03:08:33 +02:00
Andrei Alexeyev
11c9bf6681
compat: add a few more attribute macros 2023-01-08 23:54:01 +01:00
Andrei Alexeyev
a025ea5251
compat: bless C23-style auto for type inference
C23 auto standardizes GCC's __auto_type semantics, so we can start using
it already.
2023-01-08 23:48:14 +01:00
Andrei Alexeyev
21c3aebce5
build,log: make __FILE__ produce concise and consistent filenames
The output of __FILE__ previously depended on where the build directory
is and was needlessly verbose. With this change, all filenames are
relative to the src/ directory.

Logging of source file names is now also enabled for release builds
(although this is not used yet).
2022-09-01 05:50:55 +02:00
Andrei Alexeyev
8d2ee76710
replace include guards with #pragma once 2021-08-31 23:34:46 +03:00
Andrei Alexeyev
f73b1d6891
Abandon standard C conformance and require GNU extensions
Removed the use_gnu_ext option as well as fallback paths for compilers
that don't support GNU extensions. To my knowledge, none of those
compilers support C11 to a sufficient extent to compile Taisei anyway,
and those fallbacks are very poorly tested.

Pedantic warnings are now disabled, and extensions that are common to
reasonably recent versions of GCC and clang are permitted to be relied
on (list of allowed extensions TBA).
2021-08-31 23:33:16 +03:00
Andrei Alexeyev
687e347ef1
compat: fix another name clash with windows headers 2021-07-10 21:28:01 +03:00
Andrei Alexeyev
f598bd7189
upkeep: disable GNU extensions for the RNG checker 2021-05-30 13:55:21 +03:00
Andrei Alexeyev
a5fd6fe5d9
Texturing overhaul: GPU compression, sRGB sampling, swizzles, etc. (#240)
* WIP compressed textures, swizzles, sRGB sampling, ...

* refactor texture type info & fix random bugs

* fix preprocessing of sRGB textures

* handle y-flipped basis textures

* glcommon: better WebGL compat for compressed format detection

* missed WEBGL_compressed_texture_pvrtc

* implement compressed texture xcoding and uploading

* Add basis_universal submodule

* Reorganize texture loader code

Clean up some code
Isolate Basis Universal loader into a separate module

* Add wrapper script for encoding .basis textures

* basisu: honor custom metadata written by the mkbasis.py script

* mkbasis.py: add --incredibly-slow and --dry-run

* Move pixmap code from util/ to pixmap/

* Add an on-disk transcode cache for basis textures to speed up loads

* Compress texture cache with zlib

* Use readable format names for basisu cache filenames

* basisu: mip bias test code

* basisu: small caching cleanup

* add TAISEI_BASISU_MIP_BIAS env variable

* Improve OpenGL format matching heuristics

* Document considerations for compressed format priority

* Remove dead code

* Enable two forgotten formats, BC3_RGBA and ATC_RGBA

Also prefer BC7 over BC1/BC3

* Recognize GL_ANGLE_compressed_texture_etc for ETC2 textures

* Default depth buffers to 24-bit; remove ANGLE hack

* Fix glcommon_check_extension for GLES2/legacy gl

* Add renderer feature bit for texture swizzle masks

* glcommon: Fixup internal formats for GLES2

Sized internal formats are not allowed in GLES2

* Fix emscripten compile errors

* Update basis_universal

* remove more dead code

* revert irrelevant stage4 change

* shut up UBSan

* basisu: shut up some debug spam

* Add normalmap sampling helper to util.glslh

* basisu: add a gray-alpha mode

* mkbasis.py: Abort if image dimansions aren't multiples of 4

* Add basic Basis Universal encoding documentation (WIP)

* doc/basisu: Add paragraph about modes; minor tweaks

* basisu: workarounds for GL texture size requirements

* gles20: fix uncompressed sRGB formats

* Partial workaround for missing swizzles in gles2 and webgl

* remove invalid assertion

* New renderer API to expose glDrawBuffers-like functionality

* stagedraw: disable all color outputs for copy_depth pass

required for WebGL compatibility

* support GL_ANGLE_request_extension

* emscripten: include *.basis in gfx package

Also fix a potential problem when more than one .pkgdir is used to
construct emscripten packages

* Don't rely on emscripten runtime to enable webgl extensions
2020-08-15 14:51:12 +03:00
Andrei Alexeyev
54ca97587c
Rename cmplx32 into cmplxf for better consistency 2020-05-09 09:31:20 +03:00
Andrei Alexeyev
bd5082c0f0
Get rid of float32 and float64 typedefs
Use plain float and double when precision matters. There's no way to
consistently enforce usage of the typedefs now.
2020-05-09 09:25:38 +03:00
Andrei Alexeyev
e16e2184a3
Refactor entity system (#214)
* Smarter generic entity macros

The list of "core" entities is now defined in one macro, and hardcoded
_Generic dispatch tables are eliminated

* Get rid of "custom" entities

All entities are now "first-class". The list of known entity types has
been moved to known_entities.h. The system no longer needs to know the
definition of all entity structs.

* Refactor guts of ENT_BOX/ENT_UNBOX

Made the functions inline, Box::ent is now a proper pointer type (but
please don't use it directly), ENT_UNBOX returns NULL if the box is
"empty" (references NULL entity)

* Merge TASK_BIND_UNBOXED with TASK_BIND

* s/YoumuMyon/YoumuAMyon for consistency
2020-04-17 10:18:53 +03:00
Andrei Alexeyev
f1dfa3cdfe
add LIKELY and UNLIKELY macros to annotate branches 2020-04-13 14:27:56 +03:00
Andrei Alexeyev
7fbe987b94
Add API for task-bound dynamic memory allocation (#201)
TASK_MALLOC(size) allocates a memory region with a lifetime bound to the
active task. It can't be free'd manually.

Allocation requests are served from a dedicated region on the task's
stack whenever possible, which is fast and essentially free. If there is
not enough free space to serve the request, then the memory is allocated
on the heap. Such heap allocations are automatically free'd when the
task expires.

The allocated memory is zero-initialized and aligned as strictly as
max_align_t.
2020-04-06 04:30:52 +03:00
Andrei Alexeyev
40a604a6a5
Add 'use_gnu_ext' option
Controls the USE_GNU_EXTENSIONS define in compat.h
2020-03-31 22:51:31 +03:00
Andrei Alexeyev
0fdea86be1
Implement Robin Hood hashing (#200)
* Implement Robin Hood hashing

This replaces the previous separate chaining implementation. This
approach is more memory-efficient, cache-friendly, and puts much less
stress on the memory allocator.

* Replace crc32 with fnva1

Also attempt to make the compiler pre-hash as much stuff as possible at
build time.
2020-03-17 10:09:49 +02:00
Andrei Alexeyev
f2c8fae0cc
Add NOT_NULL(ptr) macro
Used to assume/assert that a pointer is not NULL in an expression.
Returns that pointer.
2020-03-08 02:34:36 +02:00
Andrei Alexeyev
fb19028ed5
New dialogue system powered by coroutines 2020-03-04 22:26:50 +02:00
Andrei Alexeyev
4bfe8fccbb
Make coroutine stack usage tracking compatible with ASan 2020-03-04 22:26:49 +02:00
Andrei Alexeyev
3d1c0eee4e
WIP proj draw rule revamp; YoumuB revamp; misc changes; giant mess
cursed commit
2020-03-04 22:26:45 +02:00
Andrei Alexeyev
1f1db18076
New RNG API, with crude semi-automatic misuse detection 2020-03-04 22:26:42 +02:00
Andrei Alexeyev
b8c2755ce1
attempt to fix more feature-test-macro portability issues 2019-12-18 15:38:00 +02:00
Andrei Alexeyev
6834796262
emscripten compatibility fixes 2019-12-18 15:33:36 +02:00
Alice
030fae87f5 fix macOS compile issue for timespec_get (#183) 2019-12-12 23:02:06 +02:00
Andrei Alexeyev
80b1026d08
Don't redefine standard complex macro; use a new cmplx typedef
This also introduces `float32`, `float64`, and `real` typedefs to be
used in place of `float` and `double` later. `real` is for game code and
other places where we don't particularly care about the precision and
format of the underlying type, and is currently defined to `double`.
`float32` and `float64` should replace `float` and `double` respectively
2019-11-22 05:38:48 +02:00
Andrei Alexeyev
8bdaa529df
fix for platforms where alignof(max_align_t) < 16
i686 windows in particular
2019-09-24 22:59:12 +03:00
Andrei Alexeyev
1fdc00fc39
fix an #include portability issue 2019-09-19 18:32:15 +03:00
Andrei Alexeyev
10d3e4226b
add attr_returns_allocated for functions that allocate new objects 2019-08-04 01:29:41 +03:00
Andrei Alexeyev
5a23fb95fc
make upkeep script preserve existing copyrights 2019-08-03 20:44:22 +03:00
Andrei Alexeyev
583f0dbf26
add INLINE macro for less mouthful static-inline declarations 2019-08-03 19:47:21 +03:00
Samuel P
469d6e2f48 Switch homebrew port (#173)
* Initial port

* Switch specific video modes

* Handle clean exit

* Hide option to disable gamepads, force it enabled

* Match buttons layout with Switch controllers

* Hide player name setting (to avoid getting stuck)

* Switch specific VFS setup instead of env bootstrap

* Clean up, get rid of warnings and a few ifdefs

* Add Switch specific build script and assets

* Make vfs setup mount packages

* Re-enable packaging on Switch

* Transpile shaders to es and install them

* Add applet warning and shader deps to README

* Remove script; instead using meson build scripts

* Strict prototypes

* Build script compat with project minimum meson ver

Refactor of pack.py exclude option

* Uniformise header inclusion on arch_switch.c

* Allow input for any dev; hide the option on Switch

* Silence unsused function warnings
2019-08-02 21:38:33 +03:00
Andrei Alexeyev
3055901998
update my email 2019-07-03 21:00:56 +03:00
Andrei Alexeyev
e8ed370509
#undef CMPLX as a compatibility workaround 2019-06-02 20:55:17 +03:00
Andrei Alexeyev
02afb993a2
Define _POSIX_C_SOURCE if compiling for a POSIX-like platform
Do not try to declare random POSIX functions ourselves. Fixes #165
2019-05-01 07:05:39 +03:00
Andrei Alexeyev
36c5d6974b
optimize and simplify object pools 2019-04-12 11:36:40 +03:00
Andrei Alexeyev
c7ff531a63
fixup includes 2019-03-18 06:41:12 +02:00
Andrei Alexeyev
180f9e3856
Emscripten compatibility (#161)
* Major refactoring of the main loop(s) and control flow (WIP)

run_at_fps() is gone 🦀

Instead of nested blocking event loops, there is now an eventloop API
that manages an explicit stack of scenes. This makes Taisei a lot more
portable to async environments where spinning a loop forever without
yielding control simply is not an option, and that is the entire point
of this change.

A prime example of such an environment is the Web (via emscripten).
Taisei was able to run there through a terrible hack: inserting
emscripten_sleep calls into the loop, which would yield to the browser.
This has several major drawbacks: first of all, every function that
could possibly call emscripten_sleep must be compiled into a special
kind of bytecode, which then has to be interpreted at runtime, *much*
slower than JITed WebAssembly. And that includes *everything* down the
call stack, too! For more information, see
https://emscripten.org/docs/porting/emterpreter.html

Even though that method worked well enough for experimenting, despite
suboptimal performance, there is another obvious drawback:
emscripten_sleep is implemented via setTimeout(), which can be very
imprecise and is generally not reliable for fluid animation. Browsers
actually have an API specifically for that use case:
window.requestAnimationFrame(), but Taisei's original blocking control
flow style is simply not compatible with it. Emscripten exposes this API
with its emscripten_set_main_loop(), which the eventloop backend now
uses on that platform.

Unfortunately, C is still C, with no fancy closures or coroutines.
With blocking calls into menu/scene loops gone, the control flow is
reimplemented via so-called (pun intended) "call chains". That is
basically an euphemism for callback hell. With manual memory management
and zero type-safety. Not that the menu system wasn't shitty enough
already. I'll just keep telling myself that this is all temporary and
will be replaced with scripts in v1.4.

* improve build system for emscripten + various fixes

* squish menu bugs

* improve emscripten event loop; disable EMULATE_FUNCTION_POINTER_CASTS

Note that stock freetype does not work without
EMULATE_FUNCTION_POINTER_CASTS; use a patched version from the
"emscripten" branch here:

    https://github.com/taisei-project/freetype2/tree/emscripten

* Enable -Wcast-function-type

Calling functions through incompatible pointers is nasal demons and
doesn't work in WASM.

* webgl: workaround a crash on some browsers

* emscripten improvements:

    * Persist state (config, progress, replays, ...) in local IndexDB
    * Simpler HTML shell (temporary)
    * Enable more optimizations

* fix build if validate_glsl=false

* emscripten: improve asset packaging, with local cache

Note that even though there are rules to build audio bundles, audio
does *not* work yet. It looks like SDL2_mixer can not work without
threads, which is a problem. Yet another reason to write an OpenAL
backend - emscripten supports that natively.

* emscripten: customize the html shell

* emscripten: force "show log" checkbox unchecked initially

* emscripten: remove quit shortcut from main menu (since there's no quit)

* emscripten: log area fixes

* emscripten/webgl: workaround for fullscreen viewport issue

* emscripten: implement frameskip

* emscripter: improve framerate limiter

* align List to at least 8 bytes (shut up warnings)

* fix non-emscripten builds

* improve fullscreen handling, mainly for emscripten

* Workaround to make audio work in chromium

emscripten-core/emscripten#6511

* emscripten: better vsync handling; enable vsync & disable fxaa by default
2019-03-09 21:32:32 +02:00
Andrei Alexeyev
c8e057e388
basic emscripten compat and various fixes 2019-02-22 01:56:48 +02:00
Andrei Alexeyev
f6f6d56caf
typedef complex type for convenience 2019-02-11 15:55:40 +02:00
Igor Molchanov
e754dd54ba Some compatibility fixes for Elbrus compiler (and others based on EDG front end) (#157)
* Reduce alignment to 16 due to stack variables alignment
On some archs (e.g. elbrus) there is no possibility to align
variables on stack by more that 16 bytes.

* Added check for -Wno-typedef-redefinition
In C11, there is legal to redefine typedef with the same type,
but some compilers like elbrus's lcc and, probably, intel's icc
generate a warning about that. So we disable it.

* Typo fix

* Fix __builtin_unreachable() warning on some frontends like EDG

* Added check for __attribute__((designated_init))
It doesn't work for elbrus'c lcc and clang; but clang does not
generate warning by default, but we still disable it just in case.

* A hack to avoid -Wtype-limits for compilers with unsigned enums

* Rewritten unreachable __builtin_unreachable() behavior.
According to https://bugs.llvm.org/show_bug.cgi?id=13910,
old clang versions also suffer from this issue along with lcc.
And also this warning option is removed from gcc since 4.5.0,
and it's likely there is no unreachable code analysis at all:
https://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Warning-Options.html

* Fixed unneeded stray UNREACHABLE which caused warnings

* Removed alignas() which is unneeded after lowering alignment requirements

* Removed a hack of -Wunreachable-code disabling on certain compilers
Actually, there was a wrong opinion that most of unreachable code
warnings are produced by __builtin_unreachable() itself,
not the certain use of it. After commit 36493d3, it is finally
figured out that it wasn't the case.

* Added dummy element to a struct in a test for designated_init
This test will enexpectedly fail when GNU extensions are not available
2019-02-07 10:11:13 +02:00
Andrei Alexeyev
e959fbc5f7
Fix a lot of warnings with -O3 and 32bit builds 2019-02-02 13:25:06 +02:00
Andrei Alexeyev
4159ea1249
'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
Andrei Alexeyev
be65fcda51
remove some defunct hacks 2018-07-28 14:02:48 +03:00
Andrei Alexeyev
7ebd1acbd2
NOMINMAX is a thing that exists 2018-07-28 13:53:12 +03:00
Andrei Alexeyev
083e9c950f
refuse to compile with -ffast-math 2018-07-04 11:55:33 +03:00