Wire the sink and the three devices to libakgl
src/sink_akgl.c, src/graphics_akgl.c, src/audio_akgl.c and src/input_akgl.c, in
the akbasic_akgl target, which is the only thing here that links SDL.
-DAKBASIC_WITH_AKGL=ON had never been configured in this repository before, and
it now builds and passes.
The sink is what section 3 has been waiting on. Its character grid comes from
akgl_text_measure(font, "A", &w, &h), the direct equivalent of the reference's
font.SizeUTF8("A") and the call that did not exist until 42b60f7. Wrapping is
done on the character grid rather than by handing SDL_ttf a wraplength, because
the cursor has to land somewhere definite: a program that PRINTs a long string
and then PRINTs again expects the second to start on the row after the first
ended, and only the code that placed the characters knows which row that is.
tests/akgl_backends.c draws into a 128x128 software renderer under the dummy
video driver and reads the pixels back -- the pattern deps/libakgl/tests/draw.c
established, which needs no display and no offscreen harness. It asserts the
seam rather than libakgl's own behaviour: a BASIC line in, a lit pixel of the
right colour out.
Four things in libakgl had to be worked around to get here. All four are
commented at their site with "filed upstream" and recorded in TODO.md section 3:
- An embedded libakgl requires SDL, SDL_image, SDL_mixer, SDL_ttf and jansson to
be *installed*. It builds its own vendored copies only when it is top-level,
and they are sitting right there in deps/libakgl/deps. Every lookup is guarded
with if(NOT TARGET ...), so this adds those five subdirectories before
add_subdirectory(deps/libakgl) -- the same trick and the same ordering
requirement akerror::akerror and akstdlib::akstdlib already need.
- akgl/controller.h does not compile on its own: it declares handlers taking an
akgl_Actor * and includes nothing that declares the type.
- There is no way to attach a 2D backend to a renderer you already have.
akgl_render_init2d() installs the vtable but also creates its own window and
writes the camera global, so it belongs to the akgl_game_init() path -- which
is exactly the path an embedding host is not on. The test assigns the six
pointers by hand.
- akgl_text_rendertextat() segfaults on a backend whose vtable is empty; it
reaches through renderer->draw_texture without checking it. Same class of
defect 42b60f7's own commit added a draw test for.
The sink's readline reports end of input rather than reading: a drawn text layer
is not a source of lines, and INPUT through one wants a line editor built on the
keystroke ring. EOF rather than an error is the contract sink.h states, so INPUT
already handles it. That editor is the next piece of work there.
70/70 core ctest with no SDL on the include path, 71/71 with the akgl suite,
clean under -Wall -Wextra, doxygen clean.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -72,6 +72,26 @@ endfunction()
|
||||
add_subdirectory(deps/libakerror EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(deps/libakstdlib EXCLUDE_FROM_ALL)
|
||||
if(AKBASIC_WITH_AKGL)
|
||||
# libakgl builds its own vendored SDL, SDL_image, SDL_mixer, SDL_ttf and
|
||||
# jansson only when it is *top-level*. Embedded, it goes down a find_package
|
||||
# path instead and requires all five installed on the system -- which is a
|
||||
# surprise, because they are sitting right there in deps/libakgl/deps as
|
||||
# submodules. Every one of those lookups is guarded with
|
||||
# if(NOT TARGET ...), so declaring the targets here first satisfies them
|
||||
# and the vendored copies get used after all. Same trick, and the same
|
||||
# ordering requirement, that akerror::akerror and akstdlib::akstdlib already
|
||||
# need above.
|
||||
#
|
||||
# Filed upstream: an embedded libakgl should add its own vendored
|
||||
# dependencies rather than requiring them installed.
|
||||
set(JANSSON_WITHOUT_TESTS ON CACHE BOOL "Do not build vendored Jansson tests" FORCE)
|
||||
set(JANSSON_EXAMPLES OFF CACHE BOOL "Do not build vendored Jansson examples" FORCE)
|
||||
set(JANSSON_BUILD_DOCS OFF CACHE BOOL "Do not build vendored Jansson docs" FORCE)
|
||||
add_subdirectory(deps/libakgl/deps/jansson EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(deps/libakgl/deps/SDL EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(deps/libakgl/deps/SDL_image EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(deps/libakgl/deps/SDL_mixer EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(deps/libakgl/deps/SDL_ttf EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(deps/libakgl EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
@@ -142,7 +162,12 @@ akbasic_instrument(akbasic)
|
||||
# The libakgl-backed text sink, kept in its own target so the core library and
|
||||
# the whole golden suite build with no SDL present.
|
||||
if(AKBASIC_WITH_AKGL)
|
||||
add_library(akbasic_akgl src/sink_akgl.c)
|
||||
add_library(akbasic_akgl
|
||||
src/audio_akgl.c
|
||||
src/graphics_akgl.c
|
||||
src/input_akgl.c
|
||||
src/sink_akgl.c
|
||||
)
|
||||
target_compile_options(akbasic_akgl PRIVATE -Wall -Wextra)
|
||||
target_link_libraries(akbasic_akgl PUBLIC akbasic akgl)
|
||||
akbasic_instrument(akbasic_akgl)
|
||||
@@ -230,6 +255,30 @@ foreach(_test IN LISTS AKBASIC_TESTS AKBASIC_WILL_FAIL_TESTS AKBASIC_KNOWN_FAILI
|
||||
_add_test(NAME ${_test} COMMAND akbasic_test_${_test})
|
||||
endforeach()
|
||||
|
||||
# The akgl-backed suite. Its own list because it is the only test here that links
|
||||
# SDL, and because it can only exist when AKBASIC_WITH_AKGL is on -- the whole
|
||||
# point of the backend records is that everything else builds without it.
|
||||
#
|
||||
# It runs under the dummy video and audio drivers with a software renderer,
|
||||
# following deps/libakgl/tests/draw.c: a 128x128 target read back with
|
||||
# SDL_RenderReadPixels, so it needs no display and no offscreen harness.
|
||||
if(AKBASIC_WITH_AKGL)
|
||||
add_executable(akbasic_test_akgl_backends tests/akgl_backends.c)
|
||||
target_compile_options(akbasic_test_akgl_backends PRIVATE -Wall -Wextra)
|
||||
target_link_libraries(akbasic_test_akgl_backends PRIVATE akbasic_akgl)
|
||||
target_include_directories(akbasic_test_akgl_backends PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/tests")
|
||||
# libakgl's monospaced fixture font, borrowed rather than copied: a second copy
|
||||
# of a 10 KB binary is a second thing to keep in step for no benefit.
|
||||
target_compile_definitions(akbasic_test_akgl_backends PRIVATE
|
||||
AKBASIC_TEST_FONT="${CMAKE_CURRENT_SOURCE_DIR}/deps/libakgl/tests/assets/akgl_test_mono.ttf")
|
||||
akbasic_instrument(akbasic_test_akgl_backends)
|
||||
_add_test(NAME akgl_backends COMMAND akbasic_test_akgl_backends)
|
||||
_set_tests_properties(akgl_backends PROPERTIES
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tests"
|
||||
TIMEOUT 60
|
||||
ENVIRONMENT "SDL_VIDEODRIVER=dummy;SDL_AUDIODRIVER=dummy")
|
||||
endif()
|
||||
|
||||
if(AKBASIC_TESTS OR AKBASIC_WILL_FAIL_TESTS OR AKBASIC_KNOWN_FAILING_TESTS)
|
||||
_set_tests_properties(
|
||||
${AKBASIC_TESTS} ${AKBASIC_WILL_FAIL_TESTS} ${AKBASIC_KNOWN_FAILING_TESTS}
|
||||
|
||||
Reference in New Issue
Block a user