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

Dbl bfr #58

Merged
merged 57 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
99b2ba7
Initial work on simple buffer double buffering
tehKaiN May 5, 2018
f6ea5b6
Manager operates on back bfr and it's valid even on single buffering
tehKaiN May 6, 2018
18639c6
fixed reviewed stuff
tehKaiN May 7, 2018
0609870
Fixed wrong logic with '== 0' ommited
tehKaiN May 7, 2018
2dee8bf
Reduced ifs on simplebuffer fail
tehKaiN May 7, 2018
4aa836b
Added support for OS takeover on VBCC
tehKaiN May 17, 2018
e42ad37
reordered compiler ifdefs, cleanup
tehKaiN May 17, 2018
fd79bf1
Showcase support for dbl buffering
tehKaiN May 23, 2018
f9ccc5b
reformat, fixed system usage in bitmap fns
tehKaiN May 23, 2018
ed6dec2
commented out -fverbose-asm, left so it can become if-enabled later
tehKaiN May 23, 2018
b248461
Remove excessive logging & whitespace, better forloop conditions
tehKaiN May 30, 2018
8d5ad78
Added stack trashing detection in generic main
tehKaiN May 30, 2018
b31e394
This is redundant
tehKaiN Jun 17, 2018
d7564fd
Added chunky <-> bitmap conversion
tehKaiN Jun 17, 2018
1f8f295
reformat, removed redundant includes
tehKaiN Sep 8, 2018
dc10922
ScrollBuffer works now, has dbl buffer, todos here and there
tehKaiN Sep 8, 2018
fcfbc84
Better names, improved fail on scrollBufferManagerCreate()
tehKaiN Sep 15, 2018
af9a916
fixed return before call
tehKaiN Sep 15, 2018
de9fc6f
fixed ctrl+clickability of file names in log
tehKaiN Sep 15, 2018
5ed7b84
Tilebuffer is halfway uncrapped
tehKaiN Sep 15, 2018
fee6042
Fixed tilebuffer's initial draw
tehKaiN Sep 15, 2018
557b8e9
Fixed incomplete redraws on top/bottom margin
tehKaiN Sep 15, 2018
868af51
fixed viewport starting one line lower than it should've
tehKaiN Sep 16, 2018
26b2580
cosmetic changes
tehKaiN Sep 16, 2018
9aa47e0
moved some of scrollbuffer's copper operations from process fn
tehKaiN Sep 16, 2018
7babcdd
Power of two optimizations
tehKaiN Sep 16, 2018
62074ac
review fixes: safety
tehKaiN Sep 16, 2018
d722387
fixed tile redraw, QueueProcess must be in game loop, not in process
tehKaiN Sep 19, 2018
366fc76
added tileBufferSetTile, removed dbg
tehKaiN Sep 22, 2018
3b3c69a
this shouldn't be here
tehKaiN Sep 23, 2018
8fd86d5
Fixed bitmapLoadFromFile ignoring Y offset
tehKaiN Oct 2, 2018
83ba035
minor refactor
tehKaiN Oct 3, 2018
548019e
tileBufferIsTileOnBuffer ain't working right yet
tehKaiN Oct 7, 2018
fbdd3c4
Unified fn names in joy and key managers, made 4joy polling optional
tehKaiN Oct 8, 2018
efad313
Added double buffering for camera
tehKaiN Oct 9, 2018
75fda79
Some stuff that asman pointed out
tehKaiN Nov 27, 2018
007d061
fixed disabling CopBlocks, scrollBuffer tweak
tehKaiN Feb 7, 2019
5f974de
perhaps it'll fix #88
tehKaiN Feb 26, 2019
5ba6a43
fixed tileBufferIsTileOnBuffer() region check
tehKaiN Mar 4, 2019
38e0d77
minor formatting
tehKaiN Apr 24, 2019
b1c37fc
parse tRGB form hex code string, tileset_conv has settable bg color
tehKaiN Mar 24, 2019
c197d23
reorder to prevent std::move crashes
tehKaiN Apr 19, 2019
1fec276
added helpers to main cmakelists
tehKaiN Apr 24, 2019
4ce920f
this is needed for helpers
tehKaiN Apr 24, 2019
fdf4891
promoted fontGlyphWidth from static since it can be useful
tehKaiN Apr 26, 2019
1ff81a0
added cmake util for font conversion, minor tool fix
tehKaiN Apr 27, 2019
c59b763
Merge branch 'tools-tileset_conv_bg' into dbl-bfr
tehKaiN May 4, 2019
48b9194
showcase builds again
tehKaiN May 4, 2019
4ae3062
added missing include
tehKaiN May 4, 2019
315b5ee
added buffer scrolling test
tehKaiN May 4, 2019
eacf039
fixed first line not being displayed on simple buffer
tehKaiN May 4, 2019
971784e
added unimplemented notice
tehKaiN May 4, 2019
5ec8573
fixed scrollBuffer not displaying y=0 line
tehKaiN May 4, 2019
1e7e64e
fixed destroying simplebuffer in runtime by adding copBlock freeing
tehKaiN May 4, 2019
227a3d7
obvious fix
tehKaiN May 7, 2019
9f2c2a5
increased ruler scale
tehKaiN May 7, 2019
5e20ad9
added check for proper scroll buffer y-wrap
tehKaiN May 7, 2019
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
88 changes: 88 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 2.8.5)
project(ACE)
set(ACE_DIR ${CMAKE_CURRENT_LIST_DIR} PARENT_SCOPE) # needed for helper fns

# Adhere to GNU filesystem layout conventions
include(GNUInstallDirs)
Expand Down Expand Up @@ -46,10 +47,97 @@ set(TARGET_NAME ${PROJECT_NAME_LOWER})
add_library(${TARGET_NAME} ${SOURCES} ${HEADERS})
target_link_libraries(${TARGET_NAME})

#----------------------------------------------------------------------- INSTALL

install(TARGETS ${TARGET_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${HEADERS_ACE} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ace)
install(FILES ${HEADERS_ACE_GENERIC} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ace/generic)
install(FILES ${HEADERS_ACE_UTILS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ace/utils)
install(FILES ${HEADERS_ACE_MANAGERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ace/managers)
install(FILES ${HEADERS_ACE_MANAGERS_VP} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ace/managers/viewport)
install(FILES ${HEADERS_FIXMATH} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/fixmath)

#--------------------------------------------------------------------- FUNCTIONS

function(toAbsolute PATH_IN)
if(NOT IS_ABSOLUTE ${PATH_IN})
set(${PATH_IN} "${CMAKE_CURRENT_SOURCE_DIR}/${${PATH_IN}}" PARENT_SCOPE)
endif()
endfunction()

function(convertPalette TARGET PALETTE_IN PALETTE_OUT)
add_custom_command(
OUTPUT ${PALETTE_OUT}
COMMAND ${ACE_DIR}/tools/bin/palette_conv ${PALETTE_IN} ${PALETTE_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${PALETTE_IN}
)
target_sources(${TARGET} PUBLIC ${PALETTE_OUT})
endfunction()

function(convertBitmaps)
set(options INTERLEAVED)
set(oneValArgs TARGET PALETTE MASK_COLOR)
set(multiValArgs SOURCES DESTINATIONS MASKS)
cmake_parse_arguments(
convertBitmaps "${options}" "${oneValArgs}" "${multiValArgs}" ${ARGN}
)

if(${convertBitmaps_INTERLEAVED})
set(extraFlags -i)
endif()

list(LENGTH convertBitmaps_SOURCES srcCount)
list(LENGTH convertBitmaps_DESTINATIONS dstCount)
list(LENGTH convertBitmaps_MASKS maskCount)
if(NOT ${srcCount} EQUAL ${dstCount})
message(FATAL_ERROR "SOURCES count doesn't match DESTINATIONS count")
endif()
if(${maskCount} AND NOT ${maskCount} EQUAL ${srcCount})
message(FATAL_ERROR "MASKS count doesn't match SOURCES count")
endif()
if("${convertBitmaps_MASK_COLOR} " STREQUAL " ")
if(${maskCount} GREATER 0)
message(FATAL_ERROR "MASK_COLOR unspecified")
endif()
else()
string(REPLACE "#" "\\#" convertBitmaps_MASK_COLOR "${convertBitmaps_MASK_COLOR}")
endif()

MATH(EXPR srcCount "${srcCount}-1")
foreach(bitmap_idx RANGE ${srcCount}) # /path/file.png
list(GET convertBitmaps_SOURCES ${bitmap_idx} bitmapPath)
toAbsolute(bitmapPath)
list(GET convertBitmaps_DESTINATIONS ${bitmap_idx} outPath)
toAbsolute(outPath)
if(${maskCount} GREATER 0)
list(GET convertBitmaps_MASKS ${bitmap_idx} maskPath)
toAbsolute(maskPath)
endif()

if(NOT "${convertBitmaps_MASK_COLOR} " STREQUAL " ")
set(extraFlags ${extraFlags} -mc ${convertBitmaps_MASK_COLOR} -mo ${maskPath})
endif()
add_custom_command(
OUTPUT ${outPath} ${maskPath}
COMMAND ${ACE_DIR}/tools/bitmap_conv/bitmap_conv ${convertBitmaps_PALETTE} ${bitmapPath} -o ${outPath} ${extraFlags}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${convertBitmaps_PALETTE} ${bitmapPath}
)
target_sources(${convertBitmaps_TARGET} PUBLIC ${outPath} ${maskPath})
endforeach()
endfunction()

function(convertFont TARGET FONT_IN FONT_OUT)
toAbsolute(FONT_IN)
toAbsolute(FONT_OUT)
get_filename_component(ext ${FONT_OUT} EXT)
string(SUBSTRING ${ext} 1 -1 ext)
add_custom_command(
OUTPUT ${FONT_OUT}
COMMAND ${ACE_DIR}/tools/bin/font_conv ${FONT_IN} ${ext} -out ${FONT_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${FONT_IN}
)
target_sources(${TARGET} PUBLIC ${FONT_OUT})
endfunction()
18 changes: 18 additions & 0 deletions include/ace/generic/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ void genericCreate(void);
void genericProcess(void);
void genericDestroy(void);

#if defined(__GNUC__)
#include <stdint.h>

#if UINT32_MAX == UINTPTR_MAX
#define STACK_CHK_GUARD 0xe2dee396
#else
#define STACK_CHK_GUARD 0x595e9fbd94fda766
#endif

uintptr_t __stack_chk_guard = STACK_CHK_GUARD;

__attribute__((noreturn))
void __stack_chk_fail(void) {
logWrite("ERR: STACK SMASHED\n");
while(1) {}
}
#endif

int main(void) {
systemCreate();
memCreate();
Expand Down
4 changes: 2 additions & 2 deletions include/ace/managers/joy.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ typedef struct {
extern tJoyManager g_sJoyManager;

/* Functions */
void joyOpen(void);
void joyOpen(UBYTE is4joy);

void joySetState(UBYTE ubJoyCode, UBYTE ubJoyState);

UBYTE joyPeek(UBYTE ubJoyCode);
UBYTE joyCheck(UBYTE ubJoyCode);

UBYTE joyUse(UBYTE ubJoyCode);

Expand Down
13 changes: 8 additions & 5 deletions include/ace/managers/viewport/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@

typedef struct {
tVpManager sCommon;
tUwCoordYX uPos; /// Current camera pos
tUwCoordYX uLastPos; /// Previous camera pos
tUwCoordYX uMaxPos; /// Max camera pos: world W&H - camera W&H
tUwCoordYX uPos; ///< Current camera pos
tUwCoordYX uLastPos[2]; ///< Previous camera pos
tUwCoordYX uMaxPos; ///< Max camera pos: world W&H - camera W&H
UBYTE ubBfr;
UBYTE isDblBfr;
} tCameraManager;

tCameraManager *cameraCreate(
tVPort *pVPort, UWORD uwPosX, UWORD uwPosY, UWORD uwMaxX, UWORD uwMaxY
tVPort *pVPort, UWORD uwPosX, UWORD uwPosY, UWORD uwMaxX, UWORD uwMaxY,
UBYTE isDblBfr
);

void cameraDestroy(tCameraManager *pManager);
void cameraProcess(tCameraManager *pManager);

void cameraReset(
tCameraManager *pManager,
UWORD uwPosX, UWORD uwPosY, UWORD uwMaxX, UWORD uwMaxY
UWORD uwPosX, UWORD uwPosY, UWORD uwMaxX, UWORD uwMaxY, UBYTE isDblBfr
);

void cameraSetCoord(tCameraManager *pManager, UWORD uwX, UWORD uwY);
Expand Down
54 changes: 38 additions & 16 deletions include/ace/managers/viewport/scrollbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* Scrollable buffer manager
* Uses scrolling-trick from aminet to achieve memory-efficient scroll
* Must be processed as last, because it calls WaitTOF
* Author: KaiN
* Requires viewport managers:
* - camera
* TODO: make it work without tileBuffer manager
Expand All @@ -28,40 +27,63 @@
#include <ace/managers/copper.h>
#include <ace/managers/viewport/camera.h>

// vPort ptr
#define TAG_SCROLLBUFFER_VPORT (TAG_USER|1)
// Scrollable area bounds, in pixels
#define TAG_SCROLLBUFFER_BOUND_WIDTH (TAG_USER|2)
#define TAG_SCROLLBUFFER_BOUND_HEIGHT (TAG_USER|3)
// Buffer bitmap creation flags
#define TAG_SCROLLBUFFER_BITMAP_FLAGS (TAG_USER|4)
#define TAG_SCROLLBUFFER_IS_DBLBUF (TAG_USER|5)
// If in raw mode, offset on copperlist for placing required copper
// instructions, specified in copper instruction count since beginning.
#define TAG_SCROLLBUFFER_COPLIST_OFFSET_START (TAG_USER|6)
#define TAG_SCROLLBUFFER_COPLIST_OFFSET_BREAK (TAG_USER|7)
#define TAG_SCROLLBUFFER_MARGIN_WIDTH (TAG_USER|8)

#define SCROLLBUFFER_FLAG_COPLIST_RAW 1

/* Types */

typedef struct {
tVpManager sCommon;
tCameraManager *pCameraManager; /// Quick ref to camera

tBitMap *pBuffer; /// Ptr to buffer bitmap
tCopBlock *pStartBlock; /// Initial data fetch
tCopBlock *pBreakBlock; /// Bitplane ptr reset
tUwCoordYX uBfrBounds; /// Real bounds of buffer (includes height reserved for x-scroll)
UWORD uwBmAvailHeight; /// Avail height of buffer to blit (excludes height reserved for x-scroll)
UWORD uwVpHeightPrev; /// Prev height of related VPort, used to force refresh on change
UWORD uwModulo; /// Bitplane modulo
tAvg *pAvg;
tCameraManager *pCamera; ///< Quick ref to camera

tBitMap *pFront; ///< Front buffer in double buffering
tBitMap *pBack; ///< Back buffer in double buffering
tCopBlock *pStartBlock; ///< Initial data fetch
tCopBlock *pBreakBlock; ///< Bitplane ptr reset
tUwCoordYX uBfrBounds; ///< Real bounds of buffer (includes height reserved for x-scroll)
UWORD uwBmAvailHeight; ///< Avail height of buffer to blit (excludes height reserved for x-scroll)
UWORD uwVpHeightPrev; ///< Prev height of related VPort, used to force refresh on change
UWORD uwModulo; ///< Bitplane modulo
UBYTE ubFlags;
} tScrollBufferManager;

/* Globals */

/* Functions */

tScrollBufferManager *scrollBufferCreate(
tVPort *pVPort, UBYTE ubMarginWidth,
UWORD uwBoundWidth, UWORD uwBoundHeight
);
/**
* Creates scroll manager
*/
tScrollBufferManager *scrollBufferCreate(void *pTags, ...);

void scrollBufferDestroy(tScrollBufferManager *pManager);

/**
* Scroll buffer process function
*/
void scrollBufferProcess(tScrollBufferManager *pManager);

void scrollBufferReset(
tScrollBufferManager *pManager, UBYTE ubMarginWidth,
UWORD uwBoundWidth, UWORD uwBoundHeight
UWORD uwBoundWidth, UWORD uwBoundHeight, UBYTE ubBitmapFlags, UBYTE isDblBfr
);

/**
* Uses unsafe blit copy for using out-of-bound X ccord
*/
void scrollBufferBlitMask(
tBitMap *pSrc, WORD wSrcX, WORD wSrcY,
tScrollBufferManager *pDstManager,
Expand Down
14 changes: 5 additions & 9 deletions include/ace/managers/viewport/simplebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
*/

#include <ace/types.h>
#include <ace/macros.h>
#include <ace/utils/bitmap.h>
#include <ace/utils/extview.h>
#include <ace/managers/viewport/camera.h>
#include <ace/utils/bitmap.h>
#include <ace/utils/tag.h>

// vPort ptr
Expand All @@ -26,19 +24,17 @@
#define TAG_SIMPLEBUFFER_BOUND_HEIGHT (TAG_USER|3)
// Buffer bitmap creation flags
#define TAG_SIMPLEBUFFER_BITMAP_FLAGS (TAG_USER|4)
#define TAG_SIMPLEBUFFER_IS_DBLBUF (TAG_USER|5)
// If in raw mode, offset on copperlist for placing required copper
// instructions, specified in copper instruction count since beginning.
#define TAG_SIMPLEBUFFER_COPLIST_OFFSET (TAG_USER|6)

// Flags for internal usage.
#define SIMPLEBUFFER_FLAG_X_SCROLLABLE 1
#define SIMPLEBUFFER_FLAG_COPLIST_RAW 2

typedef struct {
tVpManager sCommon;
tCameraManager *pCameraManager;
tCameraManager *pCamera;
// scroll-specific fields
tBitMap *pBuffer; ///< Bitmap buffer
tBitMap *pFront; ///< Currently displayed buffer.
tBitMap *pBack; ///< Buffer for drawing.
tCopBlock *pCopBlock; ///< CopBlock containing modulo/shift/bitplane cmds
tUwCoordYX uBfrBounds; ///< Buffer bounds in pixels
UBYTE ubFlags; ///< Read only. See SIMPLEBUFFER_FLAG_*.
Expand Down
Loading