Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: lminiero/kiavc
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.1
Choose a base ref
...
head repository: lminiero/kiavc
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 8 commits
  • 53 files changed
  • 1 contributor

Commits on Apr 25, 2023

  1. Copy the full SHA
    fd449c2 View commit details

Commits on May 20, 2023

  1. Copy the full SHA
    3088a60 View commit details

Commits on May 27, 2023

  1. Copy the full SHA
    8dca118 View commit details
  2. Copy the full SHA
    04873cc View commit details
  3. Copy the full SHA
    1973e78 View commit details
  4. Copy the full SHA
    1d04c22 View commit details

Commits on Jun 2, 2023

  1. Copy the full SHA
    d87a715 View commit details

Commits on Nov 26, 2024

  1. Copy the full SHA
    82454a8 View commit details
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -6,9 +6,12 @@ kiavc-bag.exe
kiavc-unbag.exe
*.d
*.o
*.oo
*.obj
*.oobj
*.so
*.bag
dll
*.dll
/demo/kiavc
/demo/kiavc.exe
/demo/lua/engine
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -9,13 +9,15 @@ GDB = -g -ggdb
K_OBJS = src/kiavc.o src/engine.o src/map.o src/list.o src/scripts.o \
src/cursor.o src/font.o src/room.o src/actor.o src/costume.o \
src/object.o src/animation.o src/audio.o src/bag.o \
src/pathfinding.o src/dialog.o src/utils.o src/logger.o
src/pathfinding.o src/dialog.o src/utils.o src/logger.o src/plugin.o
KB_OBJS = src/tools/kiavc-bag.o src/bag.o src/map.o src/list.o
KUB_OBJS = src/tools/kiavc-unbag.o src/bag.o src/map.o src/list.o

K_DEPS = $(K_OBJS:.o=.d)

linux: kiavc kiavc-bag kiavc-unbag
linuxso:
$(MAKE) -C plugins linux

kiavc: $(K_OBJS)
$(CC) $(GDB) -o $@ $(K_OBJS) $(ASAN_LIBS) $(DEPS_LIBS)
@@ -41,14 +43,16 @@ W32_K_OBJS = src/kiavc.obj src/engine.obj src/map.obj src/list.obj \
src/scripts.obj src/cursor.obj src/font.obj src/room.obj \
src/actor.obj src/costume.obj src/object.obj src/animation.obj \
src/audio.obj src/bag.obj src/pathfinding.obj src/dialog.obj \
src/utils.obj src/logger.obj
src/utils.obj src/logger.obj src/plugin.obj
W32_KB_OBJS = src/tools/kiavc-bag.obj src/bag.obj src/map.obj src/list.obj
W32_KUB_OBJS = src/tools/kiavc-unbag.obj src/bag.obj src/map.obj src/list.obj

win32: kiavc.exe kiavc-bag.exe kiavc-unbag.exe
win32dll:
$(MAKE) -C plugins win32

kiavc.exe: $(W32_K_OBJS)
$(W32_CC) $(W32_GDB) -o $@ $(W32_K_OBJS) $(W32_DEPS_LIBS)
$(W32_CC) $(W32_GDB) -o $@ $(W32_K_OBJS) $(W32_DEPS_LIBS) -ldl

kiavc-bag.exe: $(W32_KB_OBJS)
$(W32_CC) $(W32_GDB) -o $@ $(W32_KB_OBJS) $(W32_DEPS_LIBS)
@@ -66,4 +70,6 @@ kiavc-unbag.exe: $(W32_KUB_OBJS)
all: linux

clean:
rm -f kiavc kiavc-bag kiavc-unbag kiavc.exe kiavc-bag.exe kiavc-unbag.exe src/*.d src/*.o src/*.obj
rm -f kiavc kiavc-bag kiavc-unbag kiavc.exe kiavc-bag.exe kiavc-unbag.exe \
src/*.d src/*.o src/*.obj \
src/tools/*.d src/tools/*.o src/tools/*.obj && make -C plugins clean
2 changes: 1 addition & 1 deletion demo/lua/main.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- We may want to make sure we're using a specific version of the engine
major, minor, patch = getVersion()
if major ~= 0 or minor ~= 1 or patch ~= 0 then
if major ~= 0 or minor ~= 2 or patch ~= 0 then
kiavcLog('Unsupported KIAVC engine version')
return
end
18 changes: 18 additions & 0 deletions plugins/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Linux
linux:
$(MAKE) -C helloworld linux && $(MAKE) -C drawx linux && $(MAKE) -C simplerain linux


# Windows (FIXME)
win32:
$(MAKE) -C helloworld win32 && $(MAKE) -C drawx win32 && $(MAKE) -C simplerain win32


# Mac OS (TODO)


# All targets
all: linux

clean:
$(MAKE) -C helloworld clean && $(MAKE) -C drawx clean && $(MAKE) -C simplerain clean
122 changes: 122 additions & 0 deletions plugins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
Plugins
=======

KIAVC now also implements a basic modular architecture, which means you can dynamically load external plugins to add additional features not available in the core. While I still don't have a clear idea of exactly what this could be used for, I implemented a few sample plugins that show how this could be leveraged to add new features, whether it is custom C-based Lua functions, or further rendering of custom resources outside of the boundaries of Lua scripting.

To build the plugins, use

make

to build the Linux shared objects, or:

make win32

to build the Windows DLLs. Notice you can also build the plugins from the root of the repo using `make linuxso` (Linux) or `make win32dll` (DLL).

To use a plugin with KIAVC, you first need to copy the `.so` (or `.dll`) in the same folder as the KIAVC executable and then, from Lua, use the `loadPlugin()` function to dynamically load it. For instance, to load the `helloworld` plugin, you can use the following command:

loadPlugin('helloworld')

which will look for the `libkiavc_helloworld.so` file and dynamically load it. This dynamic loading can be done either as part of the scripts (e.g., `main.lua`), or dynamically using the KIAVC console (accessible via `F8` in the demo). Once a plugin has been loaded, it will be automatically initialized via its `init()` callback (see the "Writing your own plugin" for more information), meaning that after that its features should become immediately available.

## Sample plugins

Just for testing, I implemented a few plugins who don't have any particular purpose other than showcasing how the plugin functionality works for different requirements.

### helloworld plugin

This is a very basic plugin, that only registers a new custom Lua function, called `helloWorld()`: this function does nothing else than print a message on the KIAVC logs.

To test this plugin, load it first:

loadPlugin('helloworld')

and then use:

helloWorld()

which should show something like this in the logs:

INFO: [helloworld] Hello, world!

### drawx plugin

This is another simple plugin, meant to showcase how to perform basic rendering from a plugin. Specifically, it will always just draw the two diagonals on the screen in a continuously changing blue color. To do so, it implements two new Lua functions (`showDiagonals()`, `hideDiagonals()`).

The `showDiagonals()` function, as the name suggests, is what you use to actually have those diagonals appear on the screen. It expects two arguments:

1. the type of rendering to perform ("regular", "after", "last");
2. the z-plane of the rendering.

The type is related to how the KIAVC core and plugins interact as far as rendering is concerned. If a plugin wants to render something, it will tell the core when it should be involved: then, the core will invoke the plugin `render()` function with a pointer to the renderer and info on the canvas size; at this point, the plugin will need to perform whatever rendering it wants to do itself. This means that the plugin needs to tell the core at what step of the rendering it should be involved, which can be:

* `regular`: the plugin will act as a generic resource (an actor, a room layer, an object, text on the screen, etc.), and so its z-plane will decide what will appear behind and in front of it;
* `after`: the plugin will draw things after all resources have been drawn (including mouse, dialogs, etc.), but before scaling to the actual screen size;
* last`: the plugin will draw after scaling, which means the canvas will be the one for the actual screen resolution, and not the game one.

Notice that the provided z-plane only applies to the group the type refers to: a `last` with z-plane 0 will still appear in front of everything drawn in `regular` and `after`.

As such, after the plugin has been loaded:

loadPlugin('drawx')

a few potential examples of the plugin in use are the following. This snippet will make the diagonals appear behind the room layers, since it will add them to the generic resources and a very low z-plane:

showDiagonals('regular', -100)

This command, instead, will move the diagonals on top of every game asset shown on screen, but below the post-scaling stuff (e.g., walkboxes, object debugging, console, etc.):

showDiagonals('after', 0)

Finally, this snippet acts post-scaling instead, which means the drawn diagonals will look much thinner and sharper due to the higher resolution they're drawn at:

showDiagonals('last', 0)

To hide the diagonals, this command can be used:

stopDiagonals()

### simplerain plugin

This plugin is another example of dynamic rendering, but for something more complex. Specifically, it implements a basic particle system for showing rain on the screen. To do so, it implements two new Lua functions (`startRain()`, `stopRain()`).

The `startRain()` function uses the provided arguments to create the particles to display and advertise them as a resource to render in the engine. It expects a single Lua object as argument, with a couple of mandatory properties and a few optional ones:

* `width` and `height` specify how large the rain block containing the particles should be; both properties are mandatory, and they'll typically need to match the size of the game screen;
* `distance` is an optional property to specify how distant, in game pixels, each particle should be from one another on average; the lower it is, the more the particles and so the thicker the rain; the default is `10`;
* `type` and `zplane` are optional properties that work exactly as explained for the `drawx` plugin; the defaults are `regular` and `0`.

As such, after the plugin has been loaded:

loadPlugin('simplerain')

a few potential examples of the plugin in use are the following. This command shows some rain covering the whole game screen using the defaults:

startRain({ width=320, height=180 })

Notice that this is a static overlay, meaning it will stay there when the room scrolls. Also notice that, when rain has been created, it needs to be stopped before you can try a different configuration:

stopRain()

This other example changes the z-plane, which means that, since the type is still `regular`, rain will be shown behind some of the room layers:

startRain({ width=320, height=180, zplane=-100 })

This further example shows a larger amount of rain particles after every other game resource has been drawn, which means it will cover the mouse, UI and other things too:

startRain({ width=320, height=180, distance=5, type='after' })

Finally, this last example shows rain after scaling has been performed, which as a result will display much thinner particles:

startRain({ width=1920, height=1080, distance=30, velocity_min=5, velocity_max=10, type='last' })

## Writing your own plugin

If you want to implement a new plugin, check the `plugin.h` header in the `src` folder of KIAVC, as that contains all the bits you need to be aware of to use the proper plugin interface. In a nutshell:

1. you need to fill in your own `kiavc_plugin` instance, and make sure that the related callbacks are implemented (some are mandatory, others are optional);
2. you need to implement a public function called `kiavc_plugin *create(void)` that returns the pointer of that instance;
3. in case you want to register new Lua functions, you use the `register_function` core callback;
4. in case you want to render stuff on the screen, you create `kiavc_plugin_resource` instances and use the `add_resource` / `remove_recourse` core callbacks.

This is a really short version of what needs to be done, and probably not that clear either, but the existing plugin implementations should provide enough information to figure out what's happening and for you to write your own.
46 changes: 46 additions & 0 deletions plugins/drawx/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Linux
CC = gcc
DEPS = `pkg-config --cflags SDL2_image SDL2_mixer SDL2_ttf glib-2.0 lua`
DEPS_LIBS = `pkg-config --libs SDL2_image SDL2_mixer SDL2_ttf glib-2.0 lua` -lm
OPTS = -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wunused #-Werror #-O2
GDB = -g -ggdb
#~ ASAN = -O1 -g3 -ggdb3 -fno-omit-frame-pointer -fsanitize=address -fno-sanitize-recover=all -fsanitize-address-use-after-scope
#~ ASAN_LIBS = -fsanitize=address
K_OBJS = src/drawx.o

K_DEPS = $(K_OBJS:.o=.d)

linux: libkiavc_drawx.so

libkiavc_drawx.so: $(K_OBJS)
$(CC) $(GDB) -fPIC -shared -o $@ $(K_OBJS) $(ASAN_LIBS) $(DEPS_LIBS)

%.o: %.c
$(CC) $(ASAN) $(DEPS) $(GDB) -fPIC -MMD -MP -c $< -o $@ $(OPTS)

-include $(K_DEPS)

# Windows (FIXME)
W32_CC = i686-w64-mingw32-gcc
W32_DEPS = `mingw32-pkg-config --cflags SDL2_image SDL2_mixer SDL2_ttf glib-2.0`
W32_DEPS_LIBS = -w -Wl,-subsystem,windows `mingw32-pkg-config --libs SDL2_image SDL2_mixer SDL2_ttf glib-2.0` -lws2_32 -llua54 -lm -lssp
W32_OPTS = -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wunused #-Werror #-O2
W32_GDB = -g -ggdb
W32_K_OBJS = src/drawx.obj

win32: libkiavc_drawx.dll

libkiavc_drawx.dll: $(W32_K_OBJS)
$(W32_CC) $(W32_GDB) -fPIC -shared -o $@ $(W32_K_OBJS) $(W32_DEPS_LIBS)

%.obj: %.c
$(W32_CC) $(W32_DEPS) -fPIC -shared $(W32_GDB) -c $< -o $@ $(W32_OPTS)

# Mac OS (TODO)


# All targets
all: linux

clean:
rm -f *.so *.dll src/*.d src/*.o src/*.obj
Loading