Skip to content

Commit

Permalink
feat: 0.4.8 Introduce s4c module to wrap animate and gui (#99)
Browse files Browse the repository at this point in the history
- Add S4C_GUI_H_ to the available API
- Change ./configure args to --enable-animate-feature
- Rename some s4c-animate symbols for namespacing
  • Loading branch information
jgabaut authored Sep 2, 2024
1 parent fbd8b2f commit 5a8161d
Show file tree
Hide file tree
Showing 16 changed files with 3,406 additions and 682 deletions.
File renamed without changes.
File renamed without changes.
28 changes: 23 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,30 @@
*.a
# ignore .dll files
*.dll
# ignore executable
# ignore demo executable
demo
# ignore win executable
# ignore win demo executable
demo.exe
# ignore debug executable
# ignore win demo debug executable
demo_debug.exe
# ignore demo debug executable
demo_debug
# ignore animate executable
demo_animate
# ignore win animate executable
demo_animate.exe
# ignore win animate debug executable
demo_animate_debug.exe
# ignore animate debug executable
demo_animate_debug
# ignore gui executable
demo_gui
# ignore win gui executable
demo_gui.exe
# ignore win gui debug executable
demo_gui_debug.exe
# ignore gui debug executable
demo_gui_debug
# ignore doxygen directory
doxygen
# ignore docs file
Expand All @@ -23,9 +41,9 @@ documentation/docs.pdf
.DS_Store

# ignore generated palette header
s4c-animate/palette.h
src/palette.h
# ignore generated palette C file
s4c-animate/palette.c
src/palette.c

# ignore files generated by Autotools
autom4te.cache/
Expand Down
53 changes: 42 additions & 11 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ INSTALLER_LOG_FILE = "./installer.log"
PACK_NAME = $(TARGET)-$(VERSION)-$(OS)-$(MACHINE)

# Source files
demo_SOURCES = s4c-animate/animate.c s4c-animate/palette.c s4c-demo/demo.c
#
demo_SOURCES = src/s4c.c s4c-demo/demo.c

demo_animate_SOURCES = src/s4c.c src/palette.c s4c-demo/demo_animate.c

demo_gui_SOURCES = src/s4c.c s4c-demo/demo_gui.c

# Lib source files
lib_SOURCES = s4c-animate/animate.c
lib_SOURCES = src/s4c.c

# Linking rule
LDADD = $(S4C_LDFLAGS)
Expand All @@ -32,6 +37,8 @@ AM_LDFLAGS = -s
# Compiler flags
AM_CFLAGS = $(S4C_CFLAGS) -O2 -Werror -Wpedantic -Wall

if S4C_ANIMATE_BUILD
AM_CFLAGS += -DS4C_HAS_ANIMATE
if S4C_RAYLIB_BUILD
AM_CFLAGS += -DS4C_RAYLIB_EXTENSION
else
Expand All @@ -44,6 +51,11 @@ endif
if S4C_RL_QUIETER_BUILD
AM_CFLAGS += -DS4C_RL_QUIETER
endif
endif # S4C_ANIMATE_BUILD

if S4C_GUI_BUILD
AM_CFLAGS += -DS4C_HAS_GUI
endif # S4C_GUI_BUILD

libs4c.o: $(lib_SOURCES)
@echo -e "\033[1;35m[Makefile]\e[0m Building \"$@\":"
Expand All @@ -66,16 +78,27 @@ libs4c.a: libs4c.o
%.o: %.c
$(CCOMP) -c $(CFLAGS) $(AM_CFLAGS) $< -o $@

# Build rule for the final binary
# Build rule for the final binaries
#
$(TARGET): $(demo_SOURCES:.c=.o)
@echo -e " \033[1;35mAM_CFLAGS\e[0m: [ \"\033[1;34m$(AM_CFLAGS)\e[0m\" ]"
@echo -e " \033[1;35mLDADD\e[0m: [ \"\033[1;34m$(LDADD)\e[0m\" ]"
$(CCOMP) $(CFLAGS) $(AM_CFLAGS) $(demo_SOURCES:.c=.o) -o $@ $(LDADD) $(AM_LDFLAGS)

s4c-animate/palette.c:
$(ANIMATE_TARGET): $(demo_animate_SOURCES:.c=.o)
@echo -e " \033[1;35mAM_CFLAGS\e[0m: [ \"\033[1;34m$(AM_CFLAGS)\e[0m\" ]"
@echo -e " \033[1;35mLDADD\e[0m: [ \"\033[1;34m$(LDADD)\e[0m\" ]"
$(CCOMP) $(CFLAGS) $(AM_CFLAGS) $(demo_animate_SOURCES:.c=.o) -o $@ $(LDADD) $(AM_LDFLAGS)

$(GUI_TARGET): $(demo_gui_SOURCES:.c=.o)
@echo -e " \033[1;35mAM_CFLAGS\e[0m: [ \"\033[1;34m$(AM_CFLAGS)\e[0m\" ]"
@echo -e " \033[1;35mLDADD\e[0m: [ \"\033[1;34m$(LDADD)\e[0m\" ]"
$(CCOMP) $(CFLAGS) $(AM_CFLAGS) $(demo_gui_SOURCES:.c=.o) -o $@ $(LDADD) $(AM_LDFLAGS)

src/palette.c:
@echo -en "Generating \033[1;35mpalette.c\e[0m and \033[1;35mpalette.h\e[0m from [$(PALETTE_PATH)]: "
python -m s4c-scripts.s4c.core.palette C-header $(PALETTE_PATH) ../.. > s4c-animate/palette.h
python -m s4c-scripts.s4c.core.palette C-impl $(PALETTE_PATH) ../.. > s4c-animate/palette.c
python -m s4c-scripts.s4c.core.palette C-header $(PALETTE_PATH) ../.. > src/palette.h
python -m s4c-scripts.s4c.core.palette C-impl $(PALETTE_PATH) ../.. > src/palette.c
@echo -e "Done."

doc:
Expand Down Expand Up @@ -107,9 +130,12 @@ run: $(TARGET)
clean:
@echo -en "Cleaning build artifacts: "
-rm $(TARGET)
-rm $(ANIMATE_TARGET)
-rm $(GUI_TARGET)
-rm src/*.o
-rm s4c-animate/*.o
-rm s4c-animate/palette.h
-rm s4c-animate/palette.c
-rm src/palette.h
-rm src/palette.c
-rm s4c-demo/*.o
-rm ./*.o
-rm ./*.so
Expand All @@ -119,6 +145,7 @@ clean:

cleanob:
@echo -en "Cleaning object build artifacts: "
-rm src/*.o
-rm s4c-animate/*.o
-rm s4c-demo/*.o
@echo -e "\033[1;33mDone.\e[0m"
Expand All @@ -139,10 +166,14 @@ pack: rebuild
@echo -e "\033[1;32m[TREE] Done.\e[0m"
@echo -e "\033[1;35m[PACK] Installing:\e[0m"
install $(TARGET) ~/s4c-local/share/$(PACK_NAME)
install $(ANIMATE_TARGET) ~/s4c-local/share/$(PACK_NAME)
install $(GUI_TARGET) ~/s4c-local/share/$(PACK_NAME)
install ./demofile.txt ~/s4c-local/share/$(PACK_NAME)
install ./palette.gpl ~/s4c-local/share/$(PACK_NAME)
install ./s4c-animate/animate.c ~/s4c-local/share/$(PACK_NAME)/src
install ./s4c-animate/animate.h ~/s4c-local/share/$(PACK_NAME)/src
install ./src/s4c.c ~/s4c-local/share/$(PACK_NAME)/src
install ./src/s4c.h ~/s4c-local/share/$(PACK_NAME)/src
install ./s4c-demo/demo_animate.c ~/s4c-local/share/$(PACK_NAME)/demo-src
install ./s4c-demo/demo_gui.c ~/s4c-local/share/$(PACK_NAME)/demo-src
install ./s4c-demo/demo.c ~/s4c-local/share/$(PACK_NAME)/demo-src
install ./scripts/*.py ~/s4c-local/share/$(PACK_NAME)/scripts
install ./requirements.txt ~/s4c-local/share/$(PACK_NAME)
Expand All @@ -168,7 +199,7 @@ install: $(SHARED_LIB) doc
@echo -e "\n\033[1;33mDone.\e[0m"

# Default target (builds everything)
all: init $(TARGET) $(SHARED_LIB) libs4c.a
all: init $(TARGET) $(ANIMATE_TARGET) $(GUI_TARGET) $(SHARED_LIB) libs4c.a

# Target to clean and rebuild
rebuild: clean all
Expand Down
62 changes: 45 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
## Table of Contents

+ [Scripts](#scripts)
+ [animate.h](#animate)
+ [s4c.h](#s4c)
+ [s4c-animate](#s4c_animate)
+ [Prerequisites](#prerequisites_animate)
+ [A note about napms()](#napms_note)
+ [Raylib extension](#raylib_ext)
+ [Terminal capabilities](#terminal_capabilities)
+ [demo.c](#demo_c)
+ [demo_animate.c](#demo_animate_c)
+ [s4c-gui](#s4c_gui)
+ [palette.gpl](#palette_gpl)

# Scripts <a name = "scripts"></a>
Expand All @@ -24,7 +26,15 @@
- An `init` target was added to the `Makefile.am`, so that you remember to initialise the submodule before trying to run any script.
This will be removed in an upcoming minor version, so you should update your scripts to use the new path.

## animate.c and animate.h <a name = "animate"></a>
## s4c.h <a name = "s4c"></a>

This is a C library offering some `ncurses/raylib` API extensions.

The main module is `s4c-animate`, supporting both `ncurses` and `raylib` separately.

There's also an early stage module `s4c-gui`, supporting only `ncurses`.

## s4c-animate <a name = "s4c_animate"></a>

This is a C library offering some functions to display an animation read from a formatted text file. It's rather small.

Expand All @@ -39,7 +49,7 @@
-------------------------------------------------------------------------------
```

You can look at the `demo.c` program to see how you can request the animation after setup.
You can look at the `demo_animate.c` program to see how you can request the animation after setup.

Some APIs which rely on reading a file are compatible with `s4c-file` specs, see `s4c-scripts/s4c/core/sprites.py` or `s4c-scripts/s4c/core/sheet_converter.py` for info about the basic file format.

Expand All @@ -49,7 +59,7 @@

#### `pip install Pillow`

To produce the `Makefile` needed to compile `./demo`, you will need:
To produce the `Makefile` needed to compile `./demo_animate`, you will need:

- `automake`
- `autoconf`
Expand Down Expand Up @@ -78,12 +88,13 @@
### Raylib extension <a name = "raylib_ext"></a>
To produce the Raylib `./demo`, run:
To produce the Raylib `./demo_animate`, run:
- `./configure --enable-raylib=yes && make rebuild`
- `./configure --enable-animate-raylib=yes && make rebuild`
In case you want to include `animate.h` as Raylib extension in a C file, you should define this macro to make sure the included declarations work as expected:
In case you want to include `s4c.h` as Raylib extension in a C file, you should define these macros to make sure the included declarations work as expected:
- `S4C_HAS_ANIMATE`
- `S4C_RAYLIB_EXTENSION`
### Terminal capabilities <a name = "terminal_capabilities"></a>
Expand All @@ -94,26 +105,43 @@
You can find a doxyfile to generate documentation in `documentation`.
### demo.c <a name = "demo_c"></a>
### demo_animate.c <a name = "demo_animate_c"></a>
This is a demo program showing how to use the animate library functions. Check out its source code after running it!
This is a demo program showing how to use the s4c-animate module library functions. Check out its source code after running it!
- To run the C demo program, do:
**The demo is meant to run with the provided file, since a different-sized animation would require little tweaks to the code.**
`autoreconf; automake --add-missing; autoreconf; automake --add-missing`
`autoreconf; ./configure`
`make; ./demo demofile.txt`
`make; ./demo_animate demofile.txt`
- To be fancy you can use process substitution in bash to give the python output (`demofile.txt`, from `sprites.py` and `sample-sprits`) directly as an argument:
`make; ./demo <( python sprites.py <directory> )
`make; ./demo_animate <( python sprites.py <directory> )
## s4c-gui <a name = "s4c_gui"></a>
This is a C library offering a small collection of curses-based UI elements.
It's still in an early stage, but it has a minimal workable interface. It's not that big.
```
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
C 1 65 57 528
C/C++ Header 1 41 33 157
-------------------------------------------------------------------------------
SUM: 2 106 90 685
-------------------------------------------------------------------------------
```
## palette.gpl <a name = "palette_gpl"></a>
This is a GIMP palette file.
It's used by the library to initialise the color pairs for curses to display the sprites.
It's also useful in the first place for exporting PNG with the correct color alignment.
You can also use it to generate a C implementation file for you color palette.
Info on how to use it are in the [palette-README.md](./palette-README.md) file.
This is a GIMP palette file.
It's used by the library to initialise the color pairs for curses to display the sprites.
It's also useful in the first place for exporting PNG with the correct color alignment.
You can also use it to generate a C implementation file for you color palette.
Info on how to use it are in the [palette-README.md](./palette-README.md) file.
Loading

0 comments on commit 5a8161d

Please sign in to comment.