Skip to content

Commit

Permalink
feat: revision 0.0.11 and refactor (#4)
Browse files Browse the repository at this point in the history
* feat: starting refactoring

* feat: draw text and draw text tui

* feat: remove <gba.h> from main.c

* change: rename core_native_gba.h to zeebo.h

* feat: draw logo splash screen

* feat: improve cmake config

* style: logo

* feat: fake native_draw_image

* style: rename callbacks in c

* feat: loop 60 fps / draw 30 fps always

* docs: organize cmakelists.txt

* docs: remove readme gh from doxygen

* feat: engine aliases in cmakelist.txt
  • Loading branch information
RodrigoDornelles authored Nov 6, 2024
1 parent dc3d62a commit bf14e60
Show file tree
Hide file tree
Showing 15 changed files with 347 additions and 387 deletions.
96 changes: 61 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ set(CMAKE_EXE_LINKER_FLAGS "${GBA_LINKER_FLAGS}")

file(GLOB_RECURSE SOURCES "src/*.c")
add_executable(${PROJECT_NAME} ${SOURCES})

file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin")
gba_create_rom(${PROJECT_NAME}
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.gba"
TITLE "Meu Jogo GBA"
GAMECODE "MEJG"
MAKERCODE "ABCD"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/bin/game.gba"
TITLE "Gly Engine"
GAMECODE "GLYE"
MAKERCODE "GLYE"
VERSION "1.0"
DEBUG "1"
DEBUG "0"
)

# Zig
Expand All @@ -52,8 +52,8 @@ if(NOT EXISTS ${ZIG_PATH})
compiler_zig
URL "${ZIG_DOWNLOAD}"
SOURCE_DIR "${CMAKE_SOURCE_DIR}/vendor/zig"
SUBBUILD_DIR "${CMAKE_BINARY_DIR}/CMakeFiles/_deps/zig-subbuild"
BINARY_DIR "${CMAKE_BINARY_DIR}/CMakeFiles/_deps/zig-build"
SUBBUILD_DIR "${CMAKE_SOURCE_DIR}/vendor/_deps/zig-subbuild"
BINARY_DIR "${CMAKE_SOURCE_DIR}/vendor/_deps/zig-build"
)
endif()
find_program(ZIGC zig PATHS "${CMAKE_SOURCE_DIR}/vendor/zig" REQUIRED NO_DEFAULT_PATH)
Expand All @@ -65,8 +65,8 @@ if(NOT EXISTS "${LUA_PATH}/font")
lib_font
URL "${FONT_DOWNLOAD}"
SOURCE_DIR "${CMAKE_SOURCE_DIR}/vendor/font"
SUBBUILD_DIR "${CMAKE_BINARY_DIR}/CMakeFiles/_deps/font-subbuild"
BINARY_DIR "${CMAKE_BINARY_DIR}/CMakeFiles/_deps/font-build"
SUBBUILD_DIR "${CMAKE_SOURCE_DIR}/vendor/_deps/font-subbuild"
BINARY_DIR "${CMAKE_SOURCE_DIR}/vendor/_deps/font-build"
)
endif()

Expand All @@ -81,8 +81,8 @@ if(NOT EXISTS "${LUA_PATH}/lua")
compiler_lua
URL "${LUA_DOWNLOAD}"
SOURCE_DIR "${CMAKE_SOURCE_DIR}/vendor/lua"
SUBBUILD_DIR "${CMAKE_BINARY_DIR}/CMakeFiles/_deps/lua-subbuild"
BINARY_DIR "${CMAKE_BINARY_DIR}/CMakeFiles/_deps/lua-build"
SUBBUILD_DIR "${CMAKE_SOURCE_DIR}/vendor/_deps/lua-subbuild"
BINARY_DIR "${CMAKE_SOURCE_DIR}/vendor/_deps/lua-build"
)
execute_process(
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/vendor/lua"
Expand All @@ -97,59 +97,85 @@ add_library(lua-static STATIC "${lua_files}")
find_program(LUAC lua PATHS "${CMAKE_SOURCE_DIR}/vendor/lua" REQUIRED NO_DEFAULT_PATH)

# Engine
set(ENGINE_HEADER "${CMAKE_SOURCE_DIR}/vendor/engine/bytecode.h")
set(ENGINE_DIR "${CMAKE_SOURCE_DIR}/vendor/engine")
set(ENGINE_VERSION "0.0.11")
set(ENGINE_DOWNLOAD "https://github.com/gamelly/gly-engine/archive/refs/tags/${ENGINE_VERSION}.tar.gz")
set(ENGINE_HEADER "${ENGINE_DIR}/bytecode.h")
if(NOT EXISTS ${ENGINE_HEADER})
FetchContent_Declare(
lib_engine
GIT_REPOSITORY https://github.com/gamelly/gly-engine
GIT_TAG develop
SOURCE_DIR "${CMAKE_SOURCE_DIR}/vendor/engine"
SUBBUILD_DIR "${CMAKE_BINARY_DIR}/CMakeFiles/_deps/engine-subbuild"
BINARY_DIR "${CMAKE_BINARY_DIR}/CMakeFiles/_deps/engine-build"
URL "${ENGINE_DOWNLOAD}"
SOURCE_DIR ${ENGINE_DIR}
SUBBUILD_DIR "${CMAKE_SOURCE_DIR}/vendor/_deps/engine-subbuild"
BINARY_DIR "${CMAKE_SOURCE_DIR}/vendor/_deps/engine-build"
)
FetchContent_MakeAvailable(lib_engine)
file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/vendor/engine/dist")
file(MAKE_DIRECTORY "${ENGINE_DIR}/lite")
file(MAKE_DIRECTORY "${ENGINE_DIR}/native")
file(MAKE_DIRECTORY "${ENGINE_DIR}/examples/template")
execute_process(
WORKING_DIRECTORY ${ENGINE_DIR}
COMMAND ${LUAC} src/cli/main.lua build --core lite --bundler --dist ${ENGINE_DIR}/lite/
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/vendor/engine"
COMMAND ${LUAC} src/cli/main.lua build --core native --bundler
WORKING_DIRECTORY ${ENGINE_DIR}
COMMAND ${LUAC} src/cli/main.lua build --core native --bundler --dist ${ENGINE_DIR}/native/
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/vendor/engine"
COMMAND ${LUAC} src/cli/main.lua fs-xxd-i dist/main.lua bytecode.h --const --name engine_bytecode_lua
COMMAND_ERROR_IS_FATAL
WORKING_DIRECTORY ${ENGINE_DIR}
COMMAND ${LUAC} src/cli/main.lua tool-template-fill ${ENGINE_DIR}/examples/template/game.lua 204800
)
set(ENGINE "@lite")
endif()
if(DEFINED ENGINE)
if (ENGINE MATCHES "^\\@")
string(SUBSTRING "${ENGINE}" 1 -1 ENGINE)
set(ENGINE "${ENGINE_DIR}/${ENGINE}/main.lua")
endif()
if(NOT EXISTS ${ENGINE})
message(FATAL_ERROR "engine not found: ${ENGINE}")
endif()
get_filename_component(ENGINE "${ENGINE}" ABSOLUTE)
execute_process(
WORKING_DIRECTORY ${ENGINE_DIR}
COMMAND ${LUAC} src/cli/main.lua fs-xxd-i ${ENGINE} ${ENGINE_HEADER} --const --name engine_bytecode_lua
COMMAND_ERROR_IS_FATAL ANY
)
endif()

# Game
string(LENGTH "${GAME}" GAME_LENGTH)
set(GAME_HEADER "${CMAKE_SOURCE_DIR}/vendor/game/bytecode.h")
if (DEFINED GAME AND GAME_LENGTH AND GAME MATCHES "^\\@")
string(SUBSTRING "${GAME}" 1 -1 GAME)
set(GAME "${ENGINE_DIR}/examples/${GAME}/game.lua")
endif()
if ((NOT DEFINED GAME AND NOT EXISTS ${GAME_HEADER}) OR (DEFINED GAME AND NOT GAME_LENGTH))
set(GAME "${ENGINE_DIR}/examples/template/game.lua")
set(GAME_LENGTH 1)
endif()
if(DEFINED GAME AND GAME_LENGTH)
if(NOT EXISTS ${GAME})
message(FATAL_ERROR "game not found: ${GAME}")
endif()
get_filename_component(GAME "${GAME}" ABSOLUTE)
file(MAKE_DIRECTORY "${CMAKE_SOURCE_DIR}/vendor/game")
execute_process(
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/vendor/engine"
WORKING_DIRECTORY ${ENGINE_DIR}
COMMAND ${LUAC} src/cli/main.lua fs-xxd-i ${GAME} ${GAME_HEADER} --const --name game_bytecode_lua
COMMAND_ERROR_IS_FATAL
COMMAND_ERROR_IS_FATAL ANY
)
endif()

# Lua perfomance
if(LUA_OPTMIZE)
execute_process(
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/vendor/engine"
COMMAND ${LUAC} src/cli/main.lua fs-replace ${LUA_PATH}/luaconf.h ${LUA_PATH}/luaconf.h
--format "#define%sLUA_32BITS%s%d" --replace "#define LUA_32BITS 1"
WORKING_DIRECTORY ${ENGINE_DIR}
COMMAND ${LUAC} src/cli/main.lua fs-luaconf ${LUA_PATH}/luaconf.h --32bits
)
endif()

# Define
if(FPS_MODE)
target_compile_definitions(${PROJECT_NAME} PRIVATE GLY_GBA_FPSMODE=${FPS_MODE})
endif()

target_link_libraries(${PROJECT_NAME} ${GBA_STANDARD_LIBRARIES})
target_link_libraries(${PROJECT_NAME} lua-static)
target_link_libraries(${PROJECT_NAME} m)
5 changes: 2 additions & 3 deletions Doxyfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Custom Configs
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "Core Native GBA"
PROJECT_NUMBER = 0.0.7
PROJECT_NUMBER = 0.0.11
PROJECT_BRIEF = "create your own game-engine with just lua for nitendo game boy advance console."
PROJECT_LOGO =
OUTPUT_DIRECTORY = .
Expand All @@ -27,8 +27,7 @@ PLANTUML_INCLUDE_PATH =
OUTPUT_LANGUAGE = English
FILE_PATTERNS = *.c *.h
EXTENSION_MAPPING = h=c
INPUT = README.md src
USE_MDFILE_AS_MAINPAGE = README.md
INPUT = src
MARKDOWN_ID_STYLE = GITHUB
# Theme: https://jothepro.github.io/doxygen-awesome-css/
GENERATE_TREEVIEW = YES
Expand Down
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# Core Native GBA

[<img align="right" height="168px" src="https://raw.githubusercontent.com/RodrigoDornelles/RodrigoDornelles/refs/heads/master/media/pong-gba-gly-engine.gif">](#core-native-gba)

This project is a basic micro-gameengine to run lua in the **Nintendo Game Boy Advanced**,
which can be expanded to a custom engine,
such as [Gly Engine](https://github.com/gamelly/gly-engine).
which can be expanded to a custom engine, such as [Gly Engine](https://github.com/gamelly/gly-engine).

* [online ide](https://playground.gamely.com.br)
* [limitations](https://docs.gamely.com.br/a00232#limits-in-gameboy-advanced)
* [documentation](https://docs.gamely.com.br/a00188.html)

[<img height="168px" src="https://raw.githubusercontent.com/RodrigoDornelles/RodrigoDornelles/refs/heads/master/media/pong-gba-gly-engine.gif">](#core-native-gba)
<br/>

| :warning: Attention |
| :------------------ |
| there is no sanitization, error handling or observation of resource consumption, all of this takes up precious CPU time, bad code will make the game crash with a black screen.<br><br>**I recommend made a multiplatform game that support desktop especially for testing lua code!** |
| there is no sanitization, error handling or observation of resource consumption, all of this takes up precious CPU time, bad code will make the game crash with a black screen.<br><br>**Developing a multiplatform game with desktop support is recommended, especially for testing Lua code!** |

## How to build

* i will recommend using the [devkitpro/devkitarm](https://hub.docker.com/r/devkitpro/devkitarm) container if you do not have [devkitpro](https://devkitpro.org/wiki/devkitPro_pacman) installed.
use [devkitpro/devkitarm](https://hub.docker.com/r/devkitpro/devkitarm) container if you do not have [devkitpro](https://devkitpro.org/wiki/devkitPro_pacman) installed.

### Clone repo

Expand All @@ -22,14 +27,8 @@ git clone https://github.com/gamelly/core-native-gba

### Configure project

* **GAME:** path to your `game.lua`<br/><sup><sub>(can also be an example from the **vendor/engine/examples** folder)</sub></sup>
* **FPS_MODE 0:** loop 60 fps / draw 60 fps
* **FPS_MODE 1:** loop 60 fps / draw 30 fps
* **FPS_MODE 2:** loop 30 fps / draw 30 fps
* **FPS_MODE 3:** loop 20 fps / draw 20 fps

```
cmake -Bbuild -H. -DGAME=vendor/engine/examples/pong/game.lua -DFPS_MODE=1
cmake -Bbuild -H. -DGAME=vendor/engine/examples/pong/game.lua
```

### Build cartbridge rom `.gba`
Expand All @@ -41,5 +40,5 @@ make -C build
## Run

```
VisualBoyAdvance build/GBA_Game.gba
VisualBoyAdvance build/bin/game.gba
```
37 changes: 0 additions & 37 deletions src/core_native_gba.h

This file was deleted.

Loading

0 comments on commit bf14e60

Please sign in to comment.