mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-07-01 14:15:16 +02:00
Use meson as build system
This commit is contained in:
parent
9dc42914de
commit
37e5943f34
48 changed files with 10471 additions and 999 deletions
29
.gitignore
vendored
29
.gitignore
vendored
|
@ -12,7 +12,36 @@ xxd+
|
||||||
|
|
||||||
/build
|
/build
|
||||||
|
|
||||||
|
# VS Code
|
||||||
|
/.vscode
|
||||||
|
|
||||||
# Codeblocks
|
# Codeblocks
|
||||||
mkxp.layout
|
mkxp.layout
|
||||||
mkxp.cbp
|
mkxp.cbp
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
445
CMakeLists.txt
445
CMakeLists.txt
|
@ -1,445 +0,0 @@
|
||||||
cmake_minimum_required(VERSION 2.8.11)
|
|
||||||
Project(mkxp)
|
|
||||||
|
|
||||||
## Setup options ##
|
|
||||||
|
|
||||||
option(SHARED_FLUID "Dynamically link fluidsynth at build time" OFF)
|
|
||||||
option(WORKDIR_CURRENT "Keep current directory on startup" OFF)
|
|
||||||
option(FORCE32 "Force 32bit compile on 64bit OS" OFF)
|
|
||||||
set(BINDING "MRI" CACHE STRING "The Binding Type (MRI, MRUBY, NULL)")
|
|
||||||
set(EXTERNAL_LIB_PATH "" CACHE PATH "External precompiled lib prefix")
|
|
||||||
|
|
||||||
## Misc setup ##
|
|
||||||
|
|
||||||
include(cmake/PrepUtils.cmake)
|
|
||||||
|
|
||||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
||||||
|
|
||||||
IF("${CMAKE_SYSTEM}" MATCHES "Linux")
|
|
||||||
SET(LINUX ON)
|
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
IF(WORKDIR_CURRENT)
|
|
||||||
list(APPEND DEFINES
|
|
||||||
WORKDIR_CURRENT
|
|
||||||
)
|
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
IF(FORCE32)
|
|
||||||
if(APPLE)
|
|
||||||
SET(CMAKE_OSX_ARCHITECTURES "i386")
|
|
||||||
else()
|
|
||||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
|
|
||||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
|
|
||||||
endif()
|
|
||||||
ENDIF()
|
|
||||||
|
|
||||||
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.6)
|
|
||||||
|
|
||||||
IF(LINUX)
|
|
||||||
if(CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT(FORCE32) )
|
|
||||||
set(CMAKE_EXECUTABLE_SUFFIX ".bin.x86_64")
|
|
||||||
set(BIN_RPATH "\$ORIGIN/lib64")
|
|
||||||
set(LIB_PATH "lib64")
|
|
||||||
else()
|
|
||||||
set(CMAKE_EXECUTABLE_SUFFIX ".bin.x86")
|
|
||||||
set(BIN_RPATH "\$ORIGIN/lib")
|
|
||||||
set(LIB_PATH "lib")
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FILE_OFFSET_BITS=64")
|
|
||||||
endif()
|
|
||||||
elseif(APPLE)
|
|
||||||
SET(BIN_RPATH "@executable_path/../Frameworks")
|
|
||||||
set(LIB_PATH "lib")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(CMAKE_SKIP_BUILD_RPATH TRUE)
|
|
||||||
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
|
||||||
set(CMAKE_INSTALL_RPATH ${BIN_RPATH})
|
|
||||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
|
|
||||||
|
|
||||||
## Locate core libs ##
|
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
|
||||||
|
|
||||||
if (EXTERNAL_LIB_PATH)
|
|
||||||
set(CMAKE_PREFIX_PATH ${EXTERNAL_LIB_PATH})
|
|
||||||
|
|
||||||
if(EXISTS "${EXTERNAL_LIB_PATH}/${LIB_PATH}/pkgconfig/")
|
|
||||||
SET(ENV{PKG_CONFIG_PATH} "${EXTERNAL_LIB_PATH}/${LIB_PATH}/pkgconfig/")
|
|
||||||
endif()
|
|
||||||
if(APPLE)
|
|
||||||
set(PLATFORM_SHARED_LIBS
|
|
||||||
libSDL2.dylib libSDL2_image-2.0.0.dylib libSDL2_ttf-2.0.0.dylib libSDL_sound-1.0.1.dylib
|
|
||||||
libfreetype.6.dylib libsigc-2.0.0.dylib
|
|
||||||
CACHE STRING "List of shared libraries that need to be copied into the OS X bundle")
|
|
||||||
foreach(lib ${PLATFORM_SHARED_LIBS})
|
|
||||||
if(EXISTS ${EXTERNAL_LIB_PATH}/lib/${lib})
|
|
||||||
list(APPEND PLATFORM_COPY_LIBS
|
|
||||||
${EXTERNAL_LIB_PATH}/lib/${lib}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
pkg_check_modules(SIGCXX REQUIRED sigc++-2.0)
|
|
||||||
pkg_check_modules(PIXMAN REQUIRED pixman-1)
|
|
||||||
pkg_check_modules(PHYSFS REQUIRED physfs>=2.1)
|
|
||||||
pkg_check_modules(VORBISFILE REQUIRED vorbisfile)
|
|
||||||
pkg_check_modules(SDL2 REQUIRED sdl2)
|
|
||||||
pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf)
|
|
||||||
pkg_check_modules(SDL2_IMAGE REQUIRED SDL2_image)
|
|
||||||
pkg_check_modules(SDL_SOUND REQUIRED SDL_sound)
|
|
||||||
|
|
||||||
find_package(Boost 1.49 COMPONENTS program_options REQUIRED)
|
|
||||||
find_package(OpenAL REQUIRED)
|
|
||||||
find_package(ZLIB REQUIRED)
|
|
||||||
|
|
||||||
## Setup main source ##
|
|
||||||
|
|
||||||
set(MAIN_HEADERS
|
|
||||||
src/quadarray.h
|
|
||||||
src/audio.h
|
|
||||||
src/binding.h
|
|
||||||
src/bitmap.h
|
|
||||||
src/disposable.h
|
|
||||||
src/etc.h
|
|
||||||
src/etc-internal.h
|
|
||||||
src/eventthread.h
|
|
||||||
src/flashable.h
|
|
||||||
src/font.h
|
|
||||||
src/input.h
|
|
||||||
src/iniconfig.h
|
|
||||||
src/plane.h
|
|
||||||
src/scene.h
|
|
||||||
src/sprite.h
|
|
||||||
src/table.h
|
|
||||||
src/texpool.h
|
|
||||||
src/tilequad.h
|
|
||||||
src/transform.h
|
|
||||||
src/viewport.h
|
|
||||||
src/window.h
|
|
||||||
src/serializable.h
|
|
||||||
src/shader.h
|
|
||||||
src/glstate.h
|
|
||||||
src/quad.h
|
|
||||||
src/tilemap.h
|
|
||||||
src/tilemap-common.h
|
|
||||||
src/graphics.h
|
|
||||||
src/gl-debug.h
|
|
||||||
src/global-ibo.h
|
|
||||||
src/exception.h
|
|
||||||
src/filesystem.h
|
|
||||||
src/serial-util.h
|
|
||||||
src/intrulist.h
|
|
||||||
src/binding.h
|
|
||||||
src/gl-util.h
|
|
||||||
src/util.h
|
|
||||||
src/config.h
|
|
||||||
src/settingsmenu.h
|
|
||||||
src/keybindings.h
|
|
||||||
src/tileatlas.h
|
|
||||||
src/sharedstate.h
|
|
||||||
src/al-util.h
|
|
||||||
src/boost-hash.h
|
|
||||||
src/debugwriter.h
|
|
||||||
src/gl-fun.h
|
|
||||||
src/gl-meta.h
|
|
||||||
src/vertex.h
|
|
||||||
src/soundemitter.h
|
|
||||||
src/aldatasource.h
|
|
||||||
src/alstream.h
|
|
||||||
src/audiostream.h
|
|
||||||
src/rgssad.h
|
|
||||||
src/windowvx.h
|
|
||||||
src/tilemapvx.h
|
|
||||||
src/tileatlasvx.h
|
|
||||||
src/sharedmidistate.h
|
|
||||||
src/fluid-fun.h
|
|
||||||
src/sdl-util.h
|
|
||||||
)
|
|
||||||
|
|
||||||
set(MAIN_SOURCE
|
|
||||||
src/main.cpp
|
|
||||||
src/audio.cpp
|
|
||||||
src/bitmap.cpp
|
|
||||||
src/eventthread.cpp
|
|
||||||
src/filesystem.cpp
|
|
||||||
src/font.cpp
|
|
||||||
src/input.cpp
|
|
||||||
src/iniconfig.cpp
|
|
||||||
src/plane.cpp
|
|
||||||
src/scene.cpp
|
|
||||||
src/sprite.cpp
|
|
||||||
src/table.cpp
|
|
||||||
src/tilequad.cpp
|
|
||||||
src/viewport.cpp
|
|
||||||
src/window.cpp
|
|
||||||
src/texpool.cpp
|
|
||||||
src/shader.cpp
|
|
||||||
src/glstate.cpp
|
|
||||||
src/tilemap.cpp
|
|
||||||
src/autotiles.cpp
|
|
||||||
src/graphics.cpp
|
|
||||||
src/gl-debug.cpp
|
|
||||||
src/etc.cpp
|
|
||||||
src/config.cpp
|
|
||||||
src/settingsmenu.cpp
|
|
||||||
src/keybindings.cpp
|
|
||||||
src/tileatlas.cpp
|
|
||||||
src/sharedstate.cpp
|
|
||||||
src/gl-fun.cpp
|
|
||||||
src/gl-meta.cpp
|
|
||||||
src/vertex.cpp
|
|
||||||
src/soundemitter.cpp
|
|
||||||
src/sdlsoundsource.cpp
|
|
||||||
src/alstream.cpp
|
|
||||||
src/audiostream.cpp
|
|
||||||
src/rgssad.cpp
|
|
||||||
src/bundledfont.cpp
|
|
||||||
src/vorbissource.cpp
|
|
||||||
src/windowvx.cpp
|
|
||||||
src/tilemapvx.cpp
|
|
||||||
src/tileatlasvx.cpp
|
|
||||||
src/autotilesvx.cpp
|
|
||||||
src/midisource.cpp
|
|
||||||
src/fluid-fun.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
if(WIN32)
|
|
||||||
list(APPEND MAIN_HEADERS windows/resource.h)
|
|
||||||
list(APPEND MAIN_SOURCE windows/resource.rc)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
source_group("MKXP Source" FILES ${MAIN_SOURCE} ${MAIN_HEADERS})
|
|
||||||
|
|
||||||
## Setup embedded source ##
|
|
||||||
|
|
||||||
set(EMBEDDED_INPUT
|
|
||||||
shader/common.h
|
|
||||||
shader/transSimple.frag
|
|
||||||
shader/trans.frag
|
|
||||||
shader/hue.frag
|
|
||||||
shader/sprite.frag
|
|
||||||
shader/plane.frag
|
|
||||||
shader/gray.frag
|
|
||||||
shader/bitmapBlit.frag
|
|
||||||
shader/flatColor.frag
|
|
||||||
shader/simple.frag
|
|
||||||
shader/simpleColor.frag
|
|
||||||
shader/simpleAlpha.frag
|
|
||||||
shader/simpleAlphaUni.frag
|
|
||||||
shader/flashMap.frag
|
|
||||||
shader/minimal.vert
|
|
||||||
shader/simple.vert
|
|
||||||
shader/simpleColor.vert
|
|
||||||
shader/sprite.vert
|
|
||||||
shader/tilemap.vert
|
|
||||||
shader/tilemapvx.vert
|
|
||||||
shader/blur.frag
|
|
||||||
shader/blurH.vert
|
|
||||||
shader/blurV.vert
|
|
||||||
shader/simpleMatrix.vert
|
|
||||||
assets/liberation.ttf
|
|
||||||
assets/icon.png
|
|
||||||
)
|
|
||||||
|
|
||||||
if (RGSS2)
|
|
||||||
list(APPEND DEFINES
|
|
||||||
RGSS2
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (SHARED_FLUID)
|
|
||||||
pkg_check_modules(FLUID REQUIRED fluidsynth)
|
|
||||||
list(APPEND DEFINES
|
|
||||||
SHARED_FLUID
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
## Process Embeddeds ##
|
|
||||||
|
|
||||||
find_program(XXD_EXE xxd
|
|
||||||
DOC "Location of the xxd executable"
|
|
||||||
)
|
|
||||||
|
|
||||||
macro(ProcessWithXXD outvar inputfile outdir)
|
|
||||||
get_filename_component(basefile ${inputfile} NAME)
|
|
||||||
set(outputfile ${outdir}/${basefile}.xxd)
|
|
||||||
set_source_files_properties(${outputfile} PROPERTIES HEADER_ONLY TRUE)
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${outputfile}
|
|
||||||
COMMAND ${XXD_EXE} -i ${inputfile} ${outputfile}
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
DEPENDS ${inputfile}
|
|
||||||
COMMENT "Generating XXD for ${inputfile}"
|
|
||||||
)
|
|
||||||
list(APPEND ${outvar}
|
|
||||||
${outputfile}
|
|
||||||
)
|
|
||||||
endmacro()
|
|
||||||
|
|
||||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/xxdhack)
|
|
||||||
include_directories(
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/xxdhack
|
|
||||||
)
|
|
||||||
|
|
||||||
foreach(item ${EMBEDDED_INPUT})
|
|
||||||
ProcessWithXXD(EMBEDDED_SOURCE ${item} ${CMAKE_CURRENT_BINARY_DIR})
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
source_group("Embedded Source" FILES ${EMBEDDED_INPUT} ${EMBEDDED_SOURCE})
|
|
||||||
|
|
||||||
## Setup binding source ##
|
|
||||||
|
|
||||||
if (BINDING STREQUAL "MRI")
|
|
||||||
set(MRIVERSION "2.1" CACHE STRING "Version of MRI to link with")
|
|
||||||
pkg_check_modules(MRI REQUIRED ruby-${MRIVERSION})
|
|
||||||
list(APPEND DEFINES
|
|
||||||
BINDING_MRI
|
|
||||||
)
|
|
||||||
set(BINDING_HEADERS
|
|
||||||
binding-mri/binding-util.h
|
|
||||||
binding-mri/binding-types.h
|
|
||||||
binding-mri/serializable-binding.h
|
|
||||||
binding-mri/disposable-binding.h
|
|
||||||
binding-mri/sceneelement-binding.h
|
|
||||||
binding-mri/viewportelement-binding.h
|
|
||||||
binding-mri/flashable-binding.h
|
|
||||||
)
|
|
||||||
set(BINDING_SOURCE
|
|
||||||
binding-mri/binding-mri.cpp
|
|
||||||
binding-mri/binding-util.cpp
|
|
||||||
binding-mri/table-binding.cpp
|
|
||||||
binding-mri/etc-binding.cpp
|
|
||||||
binding-mri/bitmap-binding.cpp
|
|
||||||
binding-mri/font-binding.cpp
|
|
||||||
binding-mri/graphics-binding.cpp
|
|
||||||
binding-mri/input-binding.cpp
|
|
||||||
binding-mri/sprite-binding.cpp
|
|
||||||
binding-mri/viewport-binding.cpp
|
|
||||||
binding-mri/plane-binding.cpp
|
|
||||||
binding-mri/window-binding.cpp
|
|
||||||
binding-mri/tilemap-binding.cpp
|
|
||||||
binding-mri/audio-binding.cpp
|
|
||||||
binding-mri/module_rpg.cpp
|
|
||||||
binding-mri/filesystem-binding.cpp
|
|
||||||
binding-mri/windowvx-binding.cpp
|
|
||||||
binding-mri/tilemapvx-binding.cpp
|
|
||||||
)
|
|
||||||
elseif(BINDING STREQUAL "MRUBY")
|
|
||||||
message(FATAL_ERROR "Mruby support in CMake needs to be finished")
|
|
||||||
list(APPEND DEFINES
|
|
||||||
BINDING_MRUBY
|
|
||||||
)
|
|
||||||
set(BINDING_HEADERS
|
|
||||||
binding-mruby/binding-util.h
|
|
||||||
binding-mruby/disposable-binding.h
|
|
||||||
binding-mruby/flashable-binding.h
|
|
||||||
binding-mruby/binding-types.h
|
|
||||||
binding-mruby/sceneelement-binding.h
|
|
||||||
binding-mruby/viewportelement-binding.h
|
|
||||||
binding-mruby/serializable-binding.h
|
|
||||||
binding-mruby/mrb-ext/file.h
|
|
||||||
binding-mruby/mrb-ext/rwmem.h
|
|
||||||
binding-mruby/mrb-ext/marshal.h
|
|
||||||
)
|
|
||||||
set(BINDING_SOURCE
|
|
||||||
binding-mruby/binding-mruby.cpp
|
|
||||||
binding-mruby/binding-util.cpp
|
|
||||||
binding-mruby/window-binding.cpp
|
|
||||||
binding-mruby/bitmap-binding.cpp
|
|
||||||
binding-mruby/sprite-binding.cpp
|
|
||||||
binding-mruby/font-binding.cpp
|
|
||||||
binding-mruby/viewport-binding.cpp
|
|
||||||
binding-mruby/plane-binding.cpp
|
|
||||||
binding-mruby/audio-binding.cpp
|
|
||||||
binding-mruby/tilemap-binding.cpp
|
|
||||||
binding-mruby/etc-binding.cpp
|
|
||||||
binding-mruby/graphics-binding.cpp
|
|
||||||
binding-mruby/input-binding.cpp
|
|
||||||
binding-mruby/table-binding.cpp
|
|
||||||
binding-mruby/module_rpg.c
|
|
||||||
binding-mruby/mrb-ext/file.cpp
|
|
||||||
binding-mruby/mrb-ext/marshal.cpp
|
|
||||||
binding-mruby/mrb-ext/rwmem.cpp
|
|
||||||
binding-mruby/mrb-ext/kernel.cpp
|
|
||||||
binding-mruby/mrb-ext/time.cpp
|
|
||||||
)
|
|
||||||
elseif(BINDING STREQUAL "NULL")
|
|
||||||
set(BINDING_SOURCE
|
|
||||||
binding-null/binding-null.cpp
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Must choose a valid binding type. MRI, MRUBY, or NULL")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
source_group("Binding Source" FILES ${BINDING_SOURCE} ${BINDING_HEADERS})
|
|
||||||
|
|
||||||
## Setup main executable ##
|
|
||||||
|
|
||||||
if(APPLE)
|
|
||||||
find_library(CARBON_LIBRARY Carbon)
|
|
||||||
find_library(IOKIT_LIBRARY IOKit)
|
|
||||||
mark_as_advanced(CARBON_LIBRARY IOKIT_LIBRARY)
|
|
||||||
list(APPEND PLATFORM_LIBRARIES
|
|
||||||
${CARBON_LIBRARY}
|
|
||||||
${IOKIT_LIBRARY}
|
|
||||||
"-liconv"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
link_directories(
|
|
||||||
${SIGCXX_LIBRARY_DIRS}
|
|
||||||
${PIXMAN_LIBRARY_DIRS}
|
|
||||||
${PHYSFS_LIBRARY_DIRS}
|
|
||||||
${SDL2_LIBRARY_DIRS} # Blindly assume other SDL bits are in same directory
|
|
||||||
${Boost_LIBRARY_DIR}
|
|
||||||
${MRI_LIBDIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} MACOSX_BUNDLE
|
|
||||||
${MAIN_HEADERS}
|
|
||||||
${MAIN_SOURCE}
|
|
||||||
${BINDING_HEADERS}
|
|
||||||
${BINDING_SOURCE}
|
|
||||||
${EMBEDDED_SOURCE}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
|
||||||
${DEFINES}
|
|
||||||
)
|
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
|
||||||
src
|
|
||||||
windows
|
|
||||||
${SIGCXX_INCLUDE_DIRS}
|
|
||||||
${PIXMAN_INCLUDE_DIRS}
|
|
||||||
${PHYSFS_INCLUDE_DIRS}
|
|
||||||
${SDL2_INCLUDE_DIRS} # Blindly assume other SDL bits are in same directory
|
|
||||||
${Boost_INCLUDE_DIR}
|
|
||||||
${MRI_INCLUDE_DIRS}
|
|
||||||
${VORBISFILE_INCLUDE_DIRS}
|
|
||||||
${FLUID_INCLUDE_DIRS}
|
|
||||||
${OPENAL_INCLUDE_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
|
||||||
${SIGCXX_LIBRARIES}
|
|
||||||
${SDL2_LIBRARIES}
|
|
||||||
${SDL2_IMAGE_LIBRARIES}
|
|
||||||
${SDL2_TTF_LIBRARIES}
|
|
||||||
${SDL_SOUND_LIBRARIES}
|
|
||||||
${PHYSFS_LIBRARIES}
|
|
||||||
${PIXMAN_LIBRARIES}
|
|
||||||
${Boost_LIBRARIES}
|
|
||||||
${MRI_LIBRARIES}
|
|
||||||
${VORBISFILE_LIBRARIES}
|
|
||||||
${FLUID_LIBRARIES}
|
|
||||||
${OPENAL_LIBRARY}
|
|
||||||
${ZLIB_LIBRARY}
|
|
||||||
|
|
||||||
${PLATFORM_LIBRARIES}
|
|
||||||
)
|
|
||||||
|
|
||||||
PostBuildMacBundle(${PROJECT_NAME} "" "${PLATFORM_COPY_LIBS}")
|
|
22
assets/meson.build
Normal file
22
assets/meson.build
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
embedded_assets = [
|
||||||
|
'icon.png',
|
||||||
|
'icon.svg',
|
||||||
|
'liberation.ttf'
|
||||||
|
]
|
||||||
|
|
||||||
|
embedded_assets_f = files(embedded_assets)
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
processed_assets = []
|
||||||
|
foreach file : embedded_assets_f
|
||||||
|
processed_assets += custom_target(embedded_assets[count],
|
||||||
|
input: file,
|
||||||
|
output: '@0@.xxd'.format(embedded_assets[count]),
|
||||||
|
command: [
|
||||||
|
xxd, '-i', '@INPUT@'
|
||||||
|
],
|
||||||
|
capture: true,
|
||||||
|
depend_files: embedded_assets_f
|
||||||
|
)
|
||||||
|
count += 1
|
||||||
|
endforeach
|
154
binding-legacy/audio-binding.cpp
Normal file
154
binding-legacy/audio-binding.cpp
Normal file
|
@ -0,0 +1,154 @@
|
||||||
|
/*
|
||||||
|
** audio-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "audio.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "exception.h"
|
||||||
|
|
||||||
|
#define DEF_PLAY_STOP_POS(entity) \
|
||||||
|
RB_METHOD(audio_##entity##Play) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
const char *filename; \
|
||||||
|
int volume = 100; \
|
||||||
|
int pitch = 100; \
|
||||||
|
double pos = 0.0; \
|
||||||
|
if (rgssVer >= 3) \
|
||||||
|
rb_get_args(argc, argv, "z|iif", &filename, &volume, &pitch, &pos RB_ARG_END); \
|
||||||
|
else \
|
||||||
|
rb_get_args(argc, argv, "z|ii", &filename, &volume, &pitch RB_ARG_END); \
|
||||||
|
GUARD_EXC( shState->audio().entity##Play(filename, volume, pitch, pos); ) \
|
||||||
|
return Qnil; \
|
||||||
|
} \
|
||||||
|
RB_METHOD(audio_##entity##Stop) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
shState->audio().entity##Stop(); \
|
||||||
|
return Qnil; \
|
||||||
|
} \
|
||||||
|
RB_METHOD(audio_##entity##Pos) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
return rb_float_new(shState->audio().entity##Pos()); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DEF_PLAY_STOP(entity) \
|
||||||
|
RB_METHOD(audio_##entity##Play) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
const char *filename; \
|
||||||
|
int volume = 100; \
|
||||||
|
int pitch = 100; \
|
||||||
|
rb_get_args(argc, argv, "z|ii", &filename, &volume, &pitch RB_ARG_END); \
|
||||||
|
GUARD_EXC( shState->audio().entity##Play(filename, volume, pitch); ) \
|
||||||
|
return Qnil; \
|
||||||
|
} \
|
||||||
|
RB_METHOD(audio_##entity##Stop) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
shState->audio().entity##Stop(); \
|
||||||
|
return Qnil; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DEF_FADE(entity) \
|
||||||
|
RB_METHOD(audio_##entity##Fade) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
int time; \
|
||||||
|
rb_get_args(argc, argv, "i", &time RB_ARG_END); \
|
||||||
|
shState->audio().entity##Fade(time); \
|
||||||
|
return Qnil; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DEF_POS(entity) \
|
||||||
|
RB_METHOD(audio_##entity##Pos) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
return rb_float_new(shState->audio().entity##Pos()); \
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_PLAY_STOP_POS( bgm )
|
||||||
|
DEF_PLAY_STOP_POS( bgs )
|
||||||
|
|
||||||
|
DEF_PLAY_STOP( me )
|
||||||
|
|
||||||
|
DEF_FADE( bgm )
|
||||||
|
DEF_FADE( bgs )
|
||||||
|
DEF_FADE( me )
|
||||||
|
|
||||||
|
DEF_PLAY_STOP( se )
|
||||||
|
|
||||||
|
RB_METHOD(audioSetupMidi)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
shState->audio().setupMidi();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(audioReset)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
shState->audio().reset();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define BIND_PLAY_STOP(entity) \
|
||||||
|
_rb_define_module_function(module, #entity "_play", audio_##entity##Play); \
|
||||||
|
_rb_define_module_function(module, #entity "_stop", audio_##entity##Stop);
|
||||||
|
|
||||||
|
#define BIND_FADE(entity) \
|
||||||
|
_rb_define_module_function(module, #entity "_fade", audio_##entity##Fade);
|
||||||
|
|
||||||
|
#define BIND_PLAY_STOP_FADE(entity) \
|
||||||
|
BIND_PLAY_STOP(entity) \
|
||||||
|
BIND_FADE(entity)
|
||||||
|
|
||||||
|
#define BIND_POS(entity) \
|
||||||
|
_rb_define_module_function(module, #entity "_pos", audio_##entity##Pos);
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
audioBindingInit()
|
||||||
|
{
|
||||||
|
VALUE module = rb_define_module("Audio");
|
||||||
|
|
||||||
|
BIND_PLAY_STOP_FADE( bgm );
|
||||||
|
BIND_PLAY_STOP_FADE( bgs );
|
||||||
|
BIND_PLAY_STOP_FADE( me );
|
||||||
|
|
||||||
|
if (rgssVer >= 3)
|
||||||
|
{
|
||||||
|
BIND_POS( bgm );
|
||||||
|
BIND_POS( bgs );
|
||||||
|
|
||||||
|
_rb_define_module_function(module, "setup_midi", audioSetupMidi);
|
||||||
|
}
|
||||||
|
|
||||||
|
BIND_PLAY_STOP( se )
|
||||||
|
|
||||||
|
_rb_define_module_function(module, "__reset__", audioReset);
|
||||||
|
}
|
633
binding-legacy/binding-mri.cpp
Normal file
633
binding-legacy/binding-mri.cpp
Normal file
|
@ -0,0 +1,633 @@
|
||||||
|
/*
|
||||||
|
** binding-mri.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "binding.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
|
#include "eventthread.h"
|
||||||
|
#include "filesystem.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "sdl-util.h"
|
||||||
|
#include "debugwriter.h"
|
||||||
|
#include "graphics.h"
|
||||||
|
#include "audio.h"
|
||||||
|
#include "boost-hash.h"
|
||||||
|
|
||||||
|
#include <ruby.h>
|
||||||
|
#include <ruby/encoding.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string>
|
||||||
|
#include <zlib.h>
|
||||||
|
|
||||||
|
#include <SDL_filesystem.h>
|
||||||
|
|
||||||
|
extern const char module_rpg1[];
|
||||||
|
extern const char module_rpg2[];
|
||||||
|
extern const char module_rpg3[];
|
||||||
|
|
||||||
|
static void mriBindingExecute();
|
||||||
|
static void mriBindingTerminate();
|
||||||
|
static void mriBindingReset();
|
||||||
|
|
||||||
|
ScriptBinding scriptBindingImpl =
|
||||||
|
{
|
||||||
|
mriBindingExecute,
|
||||||
|
mriBindingTerminate,
|
||||||
|
mriBindingReset
|
||||||
|
};
|
||||||
|
|
||||||
|
ScriptBinding *scriptBinding = &scriptBindingImpl;
|
||||||
|
|
||||||
|
void tableBindingInit();
|
||||||
|
void etcBindingInit();
|
||||||
|
void fontBindingInit();
|
||||||
|
void bitmapBindingInit();
|
||||||
|
void spriteBindingInit();
|
||||||
|
void viewportBindingInit();
|
||||||
|
void planeBindingInit();
|
||||||
|
void windowBindingInit();
|
||||||
|
void tilemapBindingInit();
|
||||||
|
void windowVXBindingInit();
|
||||||
|
void tilemapVXBindingInit();
|
||||||
|
|
||||||
|
void inputBindingInit();
|
||||||
|
void audioBindingInit();
|
||||||
|
void graphicsBindingInit();
|
||||||
|
|
||||||
|
void fileIntBindingInit();
|
||||||
|
|
||||||
|
RB_METHOD(mriPrint);
|
||||||
|
RB_METHOD(mriP);
|
||||||
|
RB_METHOD(mkxpDataDirectory);
|
||||||
|
RB_METHOD(mkxpPuts);
|
||||||
|
RB_METHOD(mkxpRawKeyStates);
|
||||||
|
RB_METHOD(mkxpMouseInWindow);
|
||||||
|
|
||||||
|
RB_METHOD(mriRgssMain);
|
||||||
|
RB_METHOD(mriRgssStop);
|
||||||
|
RB_METHOD(_kernelCaller);
|
||||||
|
|
||||||
|
static void mriBindingInit()
|
||||||
|
{
|
||||||
|
tableBindingInit();
|
||||||
|
etcBindingInit();
|
||||||
|
fontBindingInit();
|
||||||
|
bitmapBindingInit();
|
||||||
|
spriteBindingInit();
|
||||||
|
viewportBindingInit();
|
||||||
|
planeBindingInit();
|
||||||
|
|
||||||
|
if (rgssVer == 1)
|
||||||
|
{
|
||||||
|
windowBindingInit();
|
||||||
|
tilemapBindingInit();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
windowVXBindingInit();
|
||||||
|
tilemapVXBindingInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
inputBindingInit();
|
||||||
|
audioBindingInit();
|
||||||
|
graphicsBindingInit();
|
||||||
|
|
||||||
|
fileIntBindingInit();
|
||||||
|
|
||||||
|
if (rgssVer >= 3)
|
||||||
|
{
|
||||||
|
_rb_define_module_function(rb_mKernel, "rgss_main", mriRgssMain);
|
||||||
|
_rb_define_module_function(rb_mKernel, "rgss_stop", mriRgssStop);
|
||||||
|
|
||||||
|
_rb_define_module_function(rb_mKernel, "msgbox", mriPrint);
|
||||||
|
_rb_define_module_function(rb_mKernel, "msgbox_p", mriP);
|
||||||
|
|
||||||
|
rb_define_global_const("RGSS_VERSION", rb_str_new_cstr("3.0.1"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_rb_define_module_function(rb_mKernel, "print", mriPrint);
|
||||||
|
_rb_define_module_function(rb_mKernel, "p", mriP);
|
||||||
|
|
||||||
|
rb_define_alias(rb_singleton_class(rb_mKernel), "_mkxp_kernel_caller_alias", "caller");
|
||||||
|
_rb_define_module_function(rb_mKernel, "caller", _kernelCaller);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rgssVer == 1)
|
||||||
|
rb_eval_string(module_rpg1);
|
||||||
|
else if (rgssVer == 2)
|
||||||
|
rb_eval_string(module_rpg2);
|
||||||
|
else if (rgssVer == 3)
|
||||||
|
rb_eval_string(module_rpg3);
|
||||||
|
else
|
||||||
|
assert(!"unreachable");
|
||||||
|
|
||||||
|
VALUE mod = rb_define_module("MKXP");
|
||||||
|
_rb_define_module_function(mod, "data_directory", mkxpDataDirectory);
|
||||||
|
_rb_define_module_function(mod, "puts", mkxpPuts);
|
||||||
|
_rb_define_module_function(mod, "raw_key_states", mkxpRawKeyStates);
|
||||||
|
_rb_define_module_function(mod, "mouse_in_window", mkxpMouseInWindow);
|
||||||
|
|
||||||
|
/* Load global constants */
|
||||||
|
rb_gv_set("MKXP", Qtrue);
|
||||||
|
|
||||||
|
VALUE debug = rb_bool_new(shState->config().editor.debug);
|
||||||
|
if (rgssVer == 1)
|
||||||
|
rb_gv_set("DEBUG", debug);
|
||||||
|
else if (rgssVer >= 2)
|
||||||
|
rb_gv_set("TEST", debug);
|
||||||
|
|
||||||
|
rb_gv_set("BTEST", rb_bool_new(shState->config().editor.battleTest));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
showMsg(const std::string &msg)
|
||||||
|
{
|
||||||
|
shState->eThread().showMessageBox(msg.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void printP(int argc, VALUE *argv,
|
||||||
|
const char *convMethod, const char *sep)
|
||||||
|
{
|
||||||
|
VALUE dispString = rb_str_buf_new(128);
|
||||||
|
ID conv = rb_intern(convMethod);
|
||||||
|
|
||||||
|
for (int i = 0; i < argc; ++i)
|
||||||
|
{
|
||||||
|
VALUE str = rb_funcall2(argv[i], conv, 0, NULL);
|
||||||
|
rb_str_buf_append(dispString, str);
|
||||||
|
|
||||||
|
if (i < argc)
|
||||||
|
rb_str_buf_cat2(dispString, sep);
|
||||||
|
}
|
||||||
|
|
||||||
|
showMsg(RSTRING_PTR(dispString));
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(mriPrint)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
printP(argc, argv, "to_s", "");
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(mriP)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
printP(argc, argv, "inspect", "\n");
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(mkxpDataDirectory)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
const std::string &path = shState->config().customDataPath;
|
||||||
|
const char *s = path.empty() ? "." : path.c_str();
|
||||||
|
|
||||||
|
return rb_str_new_cstr(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(mkxpPuts)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
const char *str;
|
||||||
|
rb_get_args(argc, argv, "z", &str RB_ARG_END);
|
||||||
|
|
||||||
|
Debug() << str;
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(mkxpRawKeyStates)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
VALUE str = rb_str_new(0, sizeof(EventThread::keyStates));
|
||||||
|
memcpy(RSTRING_PTR(str), EventThread::keyStates, sizeof(EventThread::keyStates));
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(mkxpMouseInWindow)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
return rb_bool_new(EventThread::mouseState.inWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE rgssMainCb(VALUE block)
|
||||||
|
{
|
||||||
|
rb_funcall2(block, rb_intern("call"), 0, 0);
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE rgssMainRescue(VALUE arg, VALUE exc)
|
||||||
|
{
|
||||||
|
VALUE *excRet = (VALUE*) arg;
|
||||||
|
|
||||||
|
*excRet = exc;
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void processReset()
|
||||||
|
{
|
||||||
|
shState->graphics().reset();
|
||||||
|
shState->audio().reset();
|
||||||
|
|
||||||
|
shState->rtData().rqReset.clear();
|
||||||
|
shState->graphics().repaintWait(shState->rtData().rqResetFinish,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(mriRgssMain)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
VALUE exc = Qnil;
|
||||||
|
|
||||||
|
rb_rescue2((VALUE(*)(ANYARGS)) rgssMainCb, rb_block_proc(),
|
||||||
|
(VALUE(*)(ANYARGS)) rgssMainRescue, (VALUE) &exc,
|
||||||
|
rb_eException, (VALUE) 0);
|
||||||
|
|
||||||
|
if (NIL_P(exc))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (rb_obj_class(exc) == getRbData()->exc[Reset])
|
||||||
|
processReset();
|
||||||
|
else
|
||||||
|
rb_exc_raise(exc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(mriRgssStop)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
shState->graphics().update();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(_kernelCaller)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
VALUE trace = rb_funcall2(rb_mKernel, rb_intern("_mkxp_kernel_caller_alias"), 0, 0);
|
||||||
|
|
||||||
|
if (!RB_TYPE_P(trace, RUBY_T_ARRAY))
|
||||||
|
return trace;
|
||||||
|
|
||||||
|
long len = RARRAY_LEN(trace);
|
||||||
|
|
||||||
|
if (len < 2)
|
||||||
|
return trace;
|
||||||
|
|
||||||
|
/* Remove useless "ruby:1:in 'eval'" */
|
||||||
|
rb_ary_pop(trace);
|
||||||
|
|
||||||
|
/* Also remove trace of this helper function */
|
||||||
|
rb_ary_shift(trace);
|
||||||
|
|
||||||
|
len -= 2;
|
||||||
|
|
||||||
|
if (len == 0)
|
||||||
|
return trace;
|
||||||
|
|
||||||
|
/* RMXP does this, not sure if specific or 1.8 related */
|
||||||
|
VALUE args[] = { rb_str_new_cstr(":in `<main>'"), rb_str_new_cstr("") };
|
||||||
|
rb_funcall2(rb_ary_entry(trace, len-1), rb_intern("gsub!"), 2, args);
|
||||||
|
|
||||||
|
return trace;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE newStringUTF8(const char *string, long length)
|
||||||
|
{
|
||||||
|
return rb_enc_str_new(string, length, rb_utf8_encoding());
|
||||||
|
}
|
||||||
|
|
||||||
|
struct evalArg
|
||||||
|
{
|
||||||
|
VALUE string;
|
||||||
|
VALUE filename;
|
||||||
|
};
|
||||||
|
|
||||||
|
static VALUE evalHelper(evalArg *arg)
|
||||||
|
{
|
||||||
|
VALUE argv[] = { arg->string, Qnil, arg->filename };
|
||||||
|
return rb_funcall2(Qnil, rb_intern("eval"), ARRAY_SIZE(argv), argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE evalString(VALUE string, VALUE filename, int *state)
|
||||||
|
{
|
||||||
|
evalArg arg = { string, filename };
|
||||||
|
return rb_protect((VALUE (*)(VALUE))evalHelper, (VALUE)&arg, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void runCustomScript(const std::string &filename)
|
||||||
|
{
|
||||||
|
std::string scriptData;
|
||||||
|
|
||||||
|
if (!readFileSDL(filename.c_str(), scriptData))
|
||||||
|
{
|
||||||
|
showMsg(std::string("Unable to open '") + filename + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
evalString(newStringUTF8(scriptData.c_str(), scriptData.size()),
|
||||||
|
newStringUTF8(filename.c_str(), filename.size()), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE kernelLoadDataInt(const char *filename, bool rubyExc);
|
||||||
|
|
||||||
|
struct BacktraceData
|
||||||
|
{
|
||||||
|
/* Maps: Ruby visible filename, To: Actual script name */
|
||||||
|
BoostHash<std::string, std::string> scriptNames;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define SCRIPT_SECTION_FMT (rgssVer >= 3 ? "{%04ld}" : "Section%03ld")
|
||||||
|
|
||||||
|
static void runRMXPScripts(BacktraceData &btData)
|
||||||
|
{
|
||||||
|
const Config &conf = shState->rtData().config;
|
||||||
|
const std::string &scriptPack = conf.game.scripts;
|
||||||
|
|
||||||
|
if (scriptPack.empty())
|
||||||
|
{
|
||||||
|
showMsg("No game scripts specified (missing Game.ini?)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shState->fileSystem().exists(scriptPack.c_str()))
|
||||||
|
{
|
||||||
|
showMsg("Unable to open '" + scriptPack + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE scriptArray;
|
||||||
|
|
||||||
|
/* We checked if Scripts.rxdata exists, but something might
|
||||||
|
* still go wrong */
|
||||||
|
try
|
||||||
|
{
|
||||||
|
scriptArray = kernelLoadDataInt(scriptPack.c_str(), false);
|
||||||
|
}
|
||||||
|
catch (const Exception &e)
|
||||||
|
{
|
||||||
|
showMsg(std::string("Failed to read script data: ") + e.msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!RB_TYPE_P(scriptArray, RUBY_T_ARRAY))
|
||||||
|
{
|
||||||
|
showMsg("Failed to read script data");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rb_gv_set("$RGSS_SCRIPTS", scriptArray);
|
||||||
|
|
||||||
|
long scriptCount = RARRAY_LEN(scriptArray);
|
||||||
|
|
||||||
|
std::string decodeBuffer;
|
||||||
|
decodeBuffer.resize(0x1000);
|
||||||
|
|
||||||
|
for (long i = 0; i < scriptCount; ++i)
|
||||||
|
{
|
||||||
|
VALUE script = rb_ary_entry(scriptArray, i);
|
||||||
|
|
||||||
|
if (!RB_TYPE_P(script, RUBY_T_ARRAY))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
VALUE scriptName = rb_ary_entry(script, 1);
|
||||||
|
VALUE scriptString = rb_ary_entry(script, 2);
|
||||||
|
|
||||||
|
int result = Z_OK;
|
||||||
|
unsigned long bufferLen;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
unsigned char *bufferPtr =
|
||||||
|
reinterpret_cast<unsigned char*>(const_cast<char*>(decodeBuffer.c_str()));
|
||||||
|
const unsigned char *sourcePtr =
|
||||||
|
reinterpret_cast<const unsigned char*>(RSTRING_PTR(scriptString));
|
||||||
|
|
||||||
|
bufferLen = decodeBuffer.length();
|
||||||
|
|
||||||
|
result = uncompress(bufferPtr, &bufferLen,
|
||||||
|
sourcePtr, RSTRING_LEN(scriptString));
|
||||||
|
|
||||||
|
bufferPtr[bufferLen] = '\0';
|
||||||
|
|
||||||
|
if (result != Z_BUF_ERROR)
|
||||||
|
break;
|
||||||
|
|
||||||
|
decodeBuffer.resize(decodeBuffer.size()*2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result != Z_OK)
|
||||||
|
{
|
||||||
|
static char buffer[256];
|
||||||
|
snprintf(buffer, sizeof(buffer), "Error decoding script %ld: '%s'",
|
||||||
|
i, RSTRING_PTR(scriptName));
|
||||||
|
|
||||||
|
showMsg(buffer);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
rb_ary_store(script, 3, rb_str_new_cstr(decodeBuffer.c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Execute preloaded scripts */
|
||||||
|
for (std::set<std::string>::iterator i = conf.preloadScripts.begin();
|
||||||
|
i != conf.preloadScripts.end(); ++i)
|
||||||
|
runCustomScript(*i);
|
||||||
|
|
||||||
|
VALUE exc = rb_gv_get("$!");
|
||||||
|
if (exc != Qnil)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
for (long i = 0; i < scriptCount; ++i)
|
||||||
|
{
|
||||||
|
VALUE script = rb_ary_entry(scriptArray, i);
|
||||||
|
VALUE scriptDecoded = rb_ary_entry(script, 3);
|
||||||
|
VALUE string = newStringUTF8(RSTRING_PTR(scriptDecoded),
|
||||||
|
RSTRING_LEN(scriptDecoded));
|
||||||
|
|
||||||
|
VALUE fname;
|
||||||
|
const char *scriptName = RSTRING_PTR(rb_ary_entry(script, 1));
|
||||||
|
char buf[512];
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (conf.useScriptNames)
|
||||||
|
len = snprintf(buf, sizeof(buf), "%03ld:%s", i, scriptName);
|
||||||
|
else
|
||||||
|
len = snprintf(buf, sizeof(buf), SCRIPT_SECTION_FMT, i);
|
||||||
|
|
||||||
|
fname = newStringUTF8(buf, len);
|
||||||
|
btData.scriptNames.insert(buf, scriptName);
|
||||||
|
|
||||||
|
int state;
|
||||||
|
evalString(string, fname, &state);
|
||||||
|
if (state)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE exc = rb_gv_get("$!");
|
||||||
|
if (rb_obj_class(exc) != getRbData()->exc[Reset])
|
||||||
|
break;
|
||||||
|
|
||||||
|
processReset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void showExc(VALUE exc, const BacktraceData &btData)
|
||||||
|
{
|
||||||
|
VALUE bt = rb_funcall2(exc, rb_intern("backtrace"), 0, NULL);
|
||||||
|
VALUE msg = rb_funcall2(exc, rb_intern("message"), 0, NULL);
|
||||||
|
VALUE bt0 = rb_ary_entry(bt, 0);
|
||||||
|
VALUE name = rb_class_path(rb_obj_class(exc));
|
||||||
|
|
||||||
|
VALUE ds = rb_sprintf("%" PRIsVALUE ": %" PRIsVALUE " (%" PRIsVALUE ")",
|
||||||
|
bt0, exc, name);
|
||||||
|
/* omit "useless" last entry (from ruby:1:in `eval') */
|
||||||
|
for (long i = 1, btlen = RARRAY_LEN(bt) - 1; i < btlen; ++i)
|
||||||
|
rb_str_catf(ds, "\n\tfrom %" PRIsVALUE, rb_ary_entry(bt, i));
|
||||||
|
Debug() << StringValueCStr(ds);
|
||||||
|
|
||||||
|
char *s = RSTRING_PTR(bt0);
|
||||||
|
|
||||||
|
char line[16];
|
||||||
|
std::string file(512, '\0');
|
||||||
|
|
||||||
|
char *p = s + strlen(s);
|
||||||
|
char *e;
|
||||||
|
|
||||||
|
while (p != s)
|
||||||
|
if (*--p == ':')
|
||||||
|
break;
|
||||||
|
|
||||||
|
e = p;
|
||||||
|
|
||||||
|
while (p != s)
|
||||||
|
if (*--p == ':')
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* s p e
|
||||||
|
* SectionXXX:YY: in 'blabla' */
|
||||||
|
|
||||||
|
*e = '\0';
|
||||||
|
strncpy(line, *p ? p+1 : p, sizeof(line));
|
||||||
|
line[sizeof(line)-1] = '\0';
|
||||||
|
*e = ':';
|
||||||
|
e = p;
|
||||||
|
|
||||||
|
/* s e
|
||||||
|
* SectionXXX:YY: in 'blabla' */
|
||||||
|
|
||||||
|
*e = '\0';
|
||||||
|
strncpy(&file[0], s, file.size());
|
||||||
|
*e = ':';
|
||||||
|
|
||||||
|
/* Shrink to fit */
|
||||||
|
file.resize(strlen(file.c_str()));
|
||||||
|
file = btData.scriptNames.value(file, file);
|
||||||
|
|
||||||
|
std::string ms(640, '\0');
|
||||||
|
snprintf(&ms[0], ms.size(), "Script '%s' line %s: %s occured.\n\n%s",
|
||||||
|
file.c_str(), line, RSTRING_PTR(name), RSTRING_PTR(msg));
|
||||||
|
|
||||||
|
showMsg(ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mriBindingExecute()
|
||||||
|
{
|
||||||
|
/* Normally only a ruby executable would do a sysinit,
|
||||||
|
* but not doing it will lead to crashes due to closed
|
||||||
|
* stdio streams on some platforms (eg. Windows) */
|
||||||
|
int argc = 0;
|
||||||
|
char **argv = 0;
|
||||||
|
ruby_sysinit(&argc, &argv);
|
||||||
|
|
||||||
|
ruby_setup();
|
||||||
|
rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));
|
||||||
|
|
||||||
|
Config &conf = shState->rtData().config;
|
||||||
|
|
||||||
|
if (!conf.rubyLoadpaths.empty())
|
||||||
|
{
|
||||||
|
/* Setup custom load paths */
|
||||||
|
VALUE lpaths = rb_gv_get(":");
|
||||||
|
|
||||||
|
for (size_t i = 0; i < conf.rubyLoadpaths.size(); ++i)
|
||||||
|
{
|
||||||
|
std::string &path = conf.rubyLoadpaths[i];
|
||||||
|
|
||||||
|
VALUE pathv = rb_str_new(path.c_str(), path.size());
|
||||||
|
rb_ary_push(lpaths, pathv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RbData rbData;
|
||||||
|
shState->setBindingData(&rbData);
|
||||||
|
BacktraceData btData;
|
||||||
|
|
||||||
|
mriBindingInit();
|
||||||
|
|
||||||
|
std::string &customScript = conf.customScript;
|
||||||
|
if (!customScript.empty())
|
||||||
|
runCustomScript(customScript);
|
||||||
|
else
|
||||||
|
runRMXPScripts(btData);
|
||||||
|
|
||||||
|
VALUE exc = rb_errinfo();
|
||||||
|
if (!NIL_P(exc) && !rb_obj_is_kind_of(exc, rb_eSystemExit))
|
||||||
|
showExc(exc, btData);
|
||||||
|
|
||||||
|
ruby_cleanup(0);
|
||||||
|
|
||||||
|
shState->rtData().rqTermAck.set();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mriBindingTerminate()
|
||||||
|
{
|
||||||
|
rb_raise(rb_eSystemExit, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mriBindingReset()
|
||||||
|
{
|
||||||
|
rb_raise(getRbData()->exc[Reset], " ");
|
||||||
|
}
|
40
binding-legacy/binding-types.h
Normal file
40
binding-legacy/binding-types.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
** binding-types.h
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BINDINGTYPES_H
|
||||||
|
#define BINDINGTYPES_H
|
||||||
|
|
||||||
|
#include "binding-util.h"
|
||||||
|
|
||||||
|
DECL_TYPE(Table);
|
||||||
|
DECL_TYPE(Rect);
|
||||||
|
DECL_TYPE(Color);
|
||||||
|
DECL_TYPE(Tone);
|
||||||
|
DECL_TYPE(Font);
|
||||||
|
|
||||||
|
DECL_TYPE(Bitmap);
|
||||||
|
DECL_TYPE(Sprite);
|
||||||
|
DECL_TYPE(Plane);
|
||||||
|
DECL_TYPE(Viewport);
|
||||||
|
DECL_TYPE(Tilemap);
|
||||||
|
DECL_TYPE(Window);
|
||||||
|
|
||||||
|
#endif // BINDINGTYPES_H
|
321
binding-legacy/binding-util.cpp
Normal file
321
binding-legacy/binding-util.cpp
Normal file
|
@ -0,0 +1,321 @@
|
||||||
|
/*
|
||||||
|
** binding-util.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "binding-util.h"
|
||||||
|
|
||||||
|
#include "sharedstate.h"
|
||||||
|
#include "exception.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
RbData *getRbData()
|
||||||
|
{
|
||||||
|
return static_cast<RbData*>(shState->bindingData());
|
||||||
|
}
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
RbException id;
|
||||||
|
const char *name;
|
||||||
|
} static customExc[] =
|
||||||
|
{
|
||||||
|
{ MKXP, "MKXPError" },
|
||||||
|
{ PHYSFS, "PHYSFSError" },
|
||||||
|
{ SDL, "SDLError" }
|
||||||
|
};
|
||||||
|
|
||||||
|
RbData::RbData()
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < ARRAY_SIZE(customExc); ++i)
|
||||||
|
exc[customExc[i].id] = rb_define_class(customExc[i].name, rb_eException);
|
||||||
|
|
||||||
|
exc[RGSS] = rb_define_class("RGSSError", rb_eStandardError);
|
||||||
|
exc[Reset] = rb_define_class(rgssVer >= 3 ? "RGSSReset" : "Reset", rb_eException);
|
||||||
|
|
||||||
|
exc[ErrnoENOENT] = rb_const_get(rb_const_get(rb_cObject, rb_intern("Errno")), rb_intern("ENOENT"));
|
||||||
|
exc[IOError] = rb_eIOError;
|
||||||
|
exc[TypeError] = rb_eTypeError;
|
||||||
|
exc[ArgumentError] = rb_eArgError;
|
||||||
|
}
|
||||||
|
|
||||||
|
RbData::~RbData()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Indexed with Exception::Type */
|
||||||
|
static const RbException excToRbExc[] =
|
||||||
|
{
|
||||||
|
RGSS, /* RGSSError */
|
||||||
|
ErrnoENOENT, /* NoFileError */
|
||||||
|
IOError,
|
||||||
|
|
||||||
|
TypeError,
|
||||||
|
ArgumentError,
|
||||||
|
|
||||||
|
PHYSFS, /* PHYSFSError */
|
||||||
|
SDL, /* SDLError */
|
||||||
|
MKXP /* MKXPError */
|
||||||
|
};
|
||||||
|
|
||||||
|
void raiseRbExc(const Exception &exc)
|
||||||
|
{
|
||||||
|
RbData *data = getRbData();
|
||||||
|
VALUE excClass = data->exc[excToRbExc[exc.type]];
|
||||||
|
|
||||||
|
rb_raise(excClass, "%s", exc.msg.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
raiseDisposedAccess(VALUE self)
|
||||||
|
{
|
||||||
|
const char *klassName = RTYPEDDATA_TYPE(self)->wrap_struct_name;
|
||||||
|
char buf[32];
|
||||||
|
|
||||||
|
strncpy(buf, klassName, sizeof(buf));
|
||||||
|
buf[0] = tolower(buf[0]);
|
||||||
|
|
||||||
|
rb_raise(getRbData()->exc[RGSS], "disposed %s", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
rb_get_args(int argc, VALUE *argv, const char *format, ...)
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
VALUE *arg = argv;
|
||||||
|
va_list ap;
|
||||||
|
bool opt = false;
|
||||||
|
int argI = 0;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
|
||||||
|
while ((c = *format++))
|
||||||
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '|' :
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// FIXME print num of needed args vs provided
|
||||||
|
if (argc <= argI && !opt)
|
||||||
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argI >= argc)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case 'o' :
|
||||||
|
{
|
||||||
|
if (argI >= argc)
|
||||||
|
break;
|
||||||
|
|
||||||
|
VALUE *obj = va_arg(ap, VALUE*);
|
||||||
|
|
||||||
|
*obj = *arg++;
|
||||||
|
++argI;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'S' :
|
||||||
|
{
|
||||||
|
if (argI >= argc)
|
||||||
|
break;
|
||||||
|
|
||||||
|
VALUE *str = va_arg(ap, VALUE*);
|
||||||
|
VALUE tmp = *arg;
|
||||||
|
|
||||||
|
if (!RB_TYPE_P(tmp, RUBY_T_STRING))
|
||||||
|
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
|
||||||
|
|
||||||
|
*str = tmp;
|
||||||
|
++argI;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 's' :
|
||||||
|
{
|
||||||
|
if (argI >= argc)
|
||||||
|
break;
|
||||||
|
|
||||||
|
const char **s = va_arg(ap, const char**);
|
||||||
|
int *len = va_arg(ap, int*);
|
||||||
|
|
||||||
|
VALUE tmp = *arg;
|
||||||
|
|
||||||
|
if (!RB_TYPE_P(tmp, RUBY_T_STRING))
|
||||||
|
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
|
||||||
|
|
||||||
|
*s = RSTRING_PTR(tmp);
|
||||||
|
*len = RSTRING_LEN(tmp);
|
||||||
|
++argI;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'z' :
|
||||||
|
{
|
||||||
|
if (argI >= argc)
|
||||||
|
break;
|
||||||
|
|
||||||
|
const char **s = va_arg(ap, const char**);
|
||||||
|
|
||||||
|
VALUE tmp = *arg++;
|
||||||
|
|
||||||
|
if (!RB_TYPE_P(tmp, RUBY_T_STRING))
|
||||||
|
rb_raise(rb_eTypeError, "Argument %d: Expected string", argI);
|
||||||
|
|
||||||
|
*s = RSTRING_PTR(tmp);
|
||||||
|
++argI;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'f' :
|
||||||
|
{
|
||||||
|
if (argI >= argc)
|
||||||
|
break;
|
||||||
|
|
||||||
|
double *f = va_arg(ap, double*);
|
||||||
|
VALUE fVal = *arg++;
|
||||||
|
|
||||||
|
rb_float_arg(fVal, f, argI);
|
||||||
|
|
||||||
|
++argI;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'i' :
|
||||||
|
{
|
||||||
|
if (argI >= argc)
|
||||||
|
break;
|
||||||
|
|
||||||
|
int *i = va_arg(ap, int*);
|
||||||
|
VALUE iVal = *arg++;
|
||||||
|
|
||||||
|
rb_int_arg(iVal, i, argI);
|
||||||
|
|
||||||
|
++argI;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'b' :
|
||||||
|
{
|
||||||
|
if (argI >= argc)
|
||||||
|
break;
|
||||||
|
|
||||||
|
bool *b = va_arg(ap, bool*);
|
||||||
|
VALUE bVal = *arg++;
|
||||||
|
|
||||||
|
rb_bool_arg(bVal, b, argI);
|
||||||
|
|
||||||
|
++argI;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'n' :
|
||||||
|
{
|
||||||
|
if (argI >= argc)
|
||||||
|
break;
|
||||||
|
|
||||||
|
ID *sym = va_arg(ap, ID*);
|
||||||
|
|
||||||
|
VALUE symVal = *arg++;
|
||||||
|
|
||||||
|
if (!SYMBOL_P(symVal))
|
||||||
|
rb_raise(rb_eTypeError, "Argument %d: Expected symbol", argI);
|
||||||
|
|
||||||
|
*sym = SYM2ID(symVal);
|
||||||
|
++argI;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case '|' :
|
||||||
|
opt = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
rb_raise(rb_eFatal, "invalid argument specifier %c", c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
|
||||||
|
/* Pop remaining arg pointers off
|
||||||
|
* the stack to check for RB_ARG_END */
|
||||||
|
format--;
|
||||||
|
|
||||||
|
while ((c = *format++))
|
||||||
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case 'o' :
|
||||||
|
case 'S' :
|
||||||
|
va_arg(ap, VALUE*);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 's' :
|
||||||
|
va_arg(ap, const char**);
|
||||||
|
va_arg(ap, int*);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'z' :
|
||||||
|
va_arg(ap, const char**);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'f' :
|
||||||
|
va_arg(ap, double*);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'i' :
|
||||||
|
va_arg(ap, int*);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'b' :
|
||||||
|
va_arg(ap, bool*);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME print num of needed args vs provided
|
||||||
|
if (!c && argc > argI)
|
||||||
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
||||||
|
|
||||||
|
/* Verify correct termination */
|
||||||
|
void *argEnd = va_arg(ap, void*);
|
||||||
|
(void) argEnd;
|
||||||
|
assert(argEnd == RB_ARG_END_VAL);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
return argI;
|
||||||
|
}
|
387
binding-legacy/binding-util.h
Normal file
387
binding-legacy/binding-util.h
Normal file
|
@ -0,0 +1,387 @@
|
||||||
|
/*
|
||||||
|
** binding-util.h
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BINDING_UTIL_H
|
||||||
|
#define BINDING_UTIL_H
|
||||||
|
|
||||||
|
#include <ruby.h>
|
||||||
|
|
||||||
|
#include "exception.h"
|
||||||
|
|
||||||
|
enum RbException
|
||||||
|
{
|
||||||
|
RGSS = 0,
|
||||||
|
Reset,
|
||||||
|
PHYSFS,
|
||||||
|
SDL,
|
||||||
|
MKXP,
|
||||||
|
|
||||||
|
ErrnoENOENT,
|
||||||
|
|
||||||
|
IOError,
|
||||||
|
|
||||||
|
TypeError,
|
||||||
|
ArgumentError,
|
||||||
|
|
||||||
|
RbExceptionsMax
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RbData
|
||||||
|
{
|
||||||
|
VALUE exc[RbExceptionsMax];
|
||||||
|
|
||||||
|
/* Input module (RGSS3) */
|
||||||
|
VALUE buttoncodeHash;
|
||||||
|
|
||||||
|
RbData();
|
||||||
|
~RbData();
|
||||||
|
};
|
||||||
|
|
||||||
|
RbData *getRbData();
|
||||||
|
|
||||||
|
struct Exception;
|
||||||
|
|
||||||
|
void
|
||||||
|
raiseRbExc(const Exception &exc);
|
||||||
|
|
||||||
|
#define DECL_TYPE(Klass) \
|
||||||
|
extern rb_data_type_t Klass##Type
|
||||||
|
|
||||||
|
/* 2.1 has added a new field (flags) to rb_data_type_t */
|
||||||
|
#include <ruby/version.h>
|
||||||
|
#if RUBY_API_VERSION_MAJOR >= 2 && RUBY_API_VERSION_MINOR >= 1
|
||||||
|
/* TODO: can mkxp use RUBY_TYPED_FREE_IMMEDIATELY here? */
|
||||||
|
#define DEF_TYPE_FLAGS 0
|
||||||
|
#else
|
||||||
|
#define DEF_TYPE_FLAGS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DEF_TYPE_CUSTOMNAME_AND_FREE(Klass, Name, Free) \
|
||||||
|
rb_data_type_t Klass##Type = { \
|
||||||
|
Name, { 0, Free, 0, { 0, 0 } }, 0, 0, DEF_TYPE_FLAGS \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DEF_TYPE_CUSTOMFREE(Klass, Free) \
|
||||||
|
DEF_TYPE_CUSTOMNAME_AND_FREE(Klass, #Klass, Free)
|
||||||
|
|
||||||
|
#define DEF_TYPE_CUSTOMNAME(Klass, Name) \
|
||||||
|
DEF_TYPE_CUSTOMNAME_AND_FREE(Klass, Name, freeInstance<Klass>)
|
||||||
|
|
||||||
|
#define DEF_TYPE(Klass) DEF_TYPE_CUSTOMNAME(Klass, #Klass)
|
||||||
|
|
||||||
|
template<rb_data_type_t *rbType>
|
||||||
|
static VALUE classAllocate(VALUE klass)
|
||||||
|
{
|
||||||
|
/* 2.3 has changed the name of this function */
|
||||||
|
#if RUBY_API_VERSION_MAJOR >= 2 && RUBY_API_VERSION_MINOR >= 3
|
||||||
|
return rb_data_typed_object_wrap(klass, 0, rbType);
|
||||||
|
#else
|
||||||
|
return rb_data_typed_object_alloc(klass, 0, rbType);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
static void freeInstance(void *inst)
|
||||||
|
{
|
||||||
|
delete static_cast<C*>(inst);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
raiseDisposedAccess(VALUE self);
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
inline C *
|
||||||
|
getPrivateData(VALUE self)
|
||||||
|
{
|
||||||
|
C *c = static_cast<C*>(RTYPEDDATA_DATA(self));
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
static inline C *
|
||||||
|
getPrivateDataCheck(VALUE self, const rb_data_type_t &type)
|
||||||
|
{
|
||||||
|
void *obj = Check_TypedStruct(self, &type);
|
||||||
|
return static_cast<C*>(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
setPrivateData(VALUE self, void *p)
|
||||||
|
{
|
||||||
|
RTYPEDDATA_DATA(self) = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline VALUE
|
||||||
|
wrapObject(void *p, const rb_data_type_t &type,
|
||||||
|
VALUE underKlass = rb_cObject)
|
||||||
|
{
|
||||||
|
VALUE klass = rb_const_get(underKlass, rb_intern(type.wrap_struct_name));
|
||||||
|
VALUE obj = rb_obj_alloc(klass);
|
||||||
|
|
||||||
|
setPrivateData(obj, p);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline VALUE
|
||||||
|
wrapProperty(VALUE self, void *prop, const char *iv,
|
||||||
|
const rb_data_type_t &type,
|
||||||
|
VALUE underKlass = rb_cObject)
|
||||||
|
{
|
||||||
|
VALUE propObj = wrapObject(prop, type, underKlass);
|
||||||
|
|
||||||
|
rb_iv_set(self, iv, propObj);
|
||||||
|
|
||||||
|
return propObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Implemented: oSszfibn| */
|
||||||
|
int
|
||||||
|
rb_get_args(int argc, VALUE *argv, const char *format, ...);
|
||||||
|
|
||||||
|
/* Always terminate 'rb_get_args' with this */
|
||||||
|
#ifndef NDEBUG
|
||||||
|
# define RB_ARG_END_VAL ((void*) -1)
|
||||||
|
# define RB_ARG_END ,RB_ARG_END_VAL
|
||||||
|
#else
|
||||||
|
# define RB_ARG_END
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef VALUE (*RubyMethod)(int argc, VALUE *argv, VALUE self);
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
_rb_define_method(VALUE klass, const char *name, RubyMethod func)
|
||||||
|
{
|
||||||
|
rb_define_method(klass, name, RUBY_METHOD_FUNC(func), -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
rb_define_class_method(VALUE klass, const char *name, RubyMethod func)
|
||||||
|
{
|
||||||
|
rb_define_singleton_method(klass, name, RUBY_METHOD_FUNC(func), -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
_rb_define_module_function(VALUE module, const char *name, RubyMethod func)
|
||||||
|
{
|
||||||
|
rb_define_module_function(module, name, RUBY_METHOD_FUNC(func), -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define GUARD_EXC(exp) \
|
||||||
|
{ try { exp } catch (const Exception &exc) { raiseRbExc(exc); } }
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
static inline VALUE
|
||||||
|
objectLoad(int argc, VALUE *argv, VALUE self)
|
||||||
|
{
|
||||||
|
const char *data;
|
||||||
|
int dataLen;
|
||||||
|
rb_get_args(argc, argv, "s", &data, &dataLen RB_ARG_END);
|
||||||
|
|
||||||
|
VALUE obj = rb_obj_alloc(self);
|
||||||
|
|
||||||
|
C *c = 0;
|
||||||
|
|
||||||
|
GUARD_EXC( c = C::deserialize(data, dataLen); );
|
||||||
|
|
||||||
|
setPrivateData(obj, c);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline VALUE
|
||||||
|
rb_bool_new(bool value)
|
||||||
|
{
|
||||||
|
return value ? Qtrue : Qfalse;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
rb_float_arg(VALUE arg, double *out, int argPos = 0)
|
||||||
|
{
|
||||||
|
switch (rb_type(arg))
|
||||||
|
{
|
||||||
|
case RUBY_T_FLOAT :
|
||||||
|
*out = RFLOAT_VALUE(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RUBY_T_FIXNUM :
|
||||||
|
*out = FIX2INT(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
rb_raise(rb_eTypeError, "Argument %d: Expected float", argPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
rb_int_arg(VALUE arg, int *out, int argPos = 0)
|
||||||
|
{
|
||||||
|
switch (rb_type(arg))
|
||||||
|
{
|
||||||
|
case RUBY_T_FLOAT :
|
||||||
|
// FIXME check int range?
|
||||||
|
*out = NUM2LONG(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RUBY_T_FIXNUM :
|
||||||
|
*out = FIX2INT(arg);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
rb_raise(rb_eTypeError, "Argument %d: Expected fixnum", argPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
rb_bool_arg(VALUE arg, bool *out, int argPos = 0)
|
||||||
|
{
|
||||||
|
switch (rb_type(arg))
|
||||||
|
{
|
||||||
|
case RUBY_T_TRUE :
|
||||||
|
*out = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RUBY_T_FALSE :
|
||||||
|
case RUBY_T_NIL :
|
||||||
|
*out = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
rb_raise(rb_eTypeError, "Argument %d: Expected bool", argPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
rb_check_argc(int actual, int expected)
|
||||||
|
{
|
||||||
|
if (actual != expected)
|
||||||
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
|
||||||
|
actual, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define RB_METHOD(name) \
|
||||||
|
static VALUE name(int argc, VALUE *argv, VALUE self)
|
||||||
|
|
||||||
|
#define RB_UNUSED_PARAM \
|
||||||
|
{ (void) argc; (void) argv; (void) self; }
|
||||||
|
|
||||||
|
#define MARSH_LOAD_FUN(Typ) \
|
||||||
|
RB_METHOD(Typ##Load) \
|
||||||
|
{ \
|
||||||
|
return objectLoad<Typ>(argc, argv, self); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define INITCOPY_FUN(Klass) \
|
||||||
|
RB_METHOD(Klass##InitializeCopy) \
|
||||||
|
{ \
|
||||||
|
VALUE origObj; \
|
||||||
|
rb_get_args(argc, argv, "o", &origObj RB_ARG_END); \
|
||||||
|
if (!OBJ_INIT_COPY(self, origObj)) /* When would this fail??*/\
|
||||||
|
return self; \
|
||||||
|
Klass *orig = getPrivateData<Klass>(origObj); \
|
||||||
|
Klass *k = 0; \
|
||||||
|
GUARD_EXC( k = new Klass(*orig); ) \
|
||||||
|
setPrivateData(self, k); \
|
||||||
|
return self; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Object property which is copied by reference, with allowed NIL
|
||||||
|
* FIXME: Getter assumes prop is disposable,
|
||||||
|
* because self.disposed? is not checked in this case.
|
||||||
|
* Should make this more clear */
|
||||||
|
#define DEF_PROP_OBJ_REF(Klass, PropKlass, PropName, prop_iv) \
|
||||||
|
RB_METHOD(Klass##Get##PropName) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
return rb_iv_get(self, prop_iv); \
|
||||||
|
} \
|
||||||
|
RB_METHOD(Klass##Set##PropName) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
rb_check_argc(argc, 1); \
|
||||||
|
Klass *k = getPrivateData<Klass>(self); \
|
||||||
|
VALUE propObj = *argv; \
|
||||||
|
PropKlass *prop; \
|
||||||
|
if (NIL_P(propObj)) \
|
||||||
|
prop = 0; \
|
||||||
|
else \
|
||||||
|
prop = getPrivateDataCheck<PropKlass>(propObj, PropKlass##Type); \
|
||||||
|
GUARD_EXC( k->set##PropName(prop); ) \
|
||||||
|
rb_iv_set(self, prop_iv, propObj); \
|
||||||
|
return propObj; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Object property which is copied by value, not reference */
|
||||||
|
#define DEF_PROP_OBJ_VAL(Klass, PropKlass, PropName, prop_iv) \
|
||||||
|
RB_METHOD(Klass##Get##PropName) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
checkDisposed<Klass>(self); \
|
||||||
|
return rb_iv_get(self, prop_iv); \
|
||||||
|
} \
|
||||||
|
RB_METHOD(Klass##Set##PropName) \
|
||||||
|
{ \
|
||||||
|
rb_check_argc(argc, 1); \
|
||||||
|
Klass *k = getPrivateData<Klass>(self); \
|
||||||
|
VALUE propObj = *argv; \
|
||||||
|
PropKlass *prop; \
|
||||||
|
prop = getPrivateDataCheck<PropKlass>(propObj, PropKlass##Type); \
|
||||||
|
GUARD_EXC( k->set##PropName(*prop); ) \
|
||||||
|
return propObj; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DEF_PROP(Klass, type, PropName, arg_fun, value_fun) \
|
||||||
|
RB_METHOD(Klass##Get##PropName) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
Klass *k = getPrivateData<Klass>(self); \
|
||||||
|
type value = 0; \
|
||||||
|
GUARD_EXC( value = k->get##PropName(); ) \
|
||||||
|
return value_fun(value); \
|
||||||
|
} \
|
||||||
|
RB_METHOD(Klass##Set##PropName) \
|
||||||
|
{ \
|
||||||
|
rb_check_argc(argc, 1); \
|
||||||
|
Klass *k = getPrivateData<Klass>(self); \
|
||||||
|
type value; \
|
||||||
|
rb_##arg_fun##_arg(*argv, &value); \
|
||||||
|
GUARD_EXC( k->set##PropName(value); ) \
|
||||||
|
return *argv; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DEF_PROP_I(Klass, PropName) \
|
||||||
|
DEF_PROP(Klass, int, PropName, int, rb_fix_new)
|
||||||
|
|
||||||
|
#define DEF_PROP_F(Klass, PropName) \
|
||||||
|
DEF_PROP(Klass, double, PropName, float, rb_float_new)
|
||||||
|
|
||||||
|
#define DEF_PROP_B(Klass, PropName) \
|
||||||
|
DEF_PROP(Klass, bool, PropName, bool, rb_bool_new)
|
||||||
|
|
||||||
|
#define INIT_PROP_BIND(Klass, PropName, prop_name_s) \
|
||||||
|
{ \
|
||||||
|
_rb_define_method(klass, prop_name_s, Klass##Get##PropName); \
|
||||||
|
_rb_define_method(klass, prop_name_s "=", Klass##Set##PropName); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // BINDING_UTIL_H
|
470
binding-legacy/bitmap-binding.cpp
Normal file
470
binding-legacy/bitmap-binding.cpp
Normal file
|
@ -0,0 +1,470 @@
|
||||||
|
/*
|
||||||
|
** bitmap-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bitmap.h"
|
||||||
|
#include "font.h"
|
||||||
|
#include "exception.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "binding-types.h"
|
||||||
|
|
||||||
|
DEF_TYPE(Bitmap);
|
||||||
|
|
||||||
|
static const char *objAsStringPtr(VALUE obj)
|
||||||
|
{
|
||||||
|
VALUE str = rb_obj_as_string(obj);
|
||||||
|
return RSTRING_PTR(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bitmapInitProps(Bitmap *b, VALUE self)
|
||||||
|
{
|
||||||
|
/* Wrap properties */
|
||||||
|
VALUE fontKlass = rb_const_get(rb_cObject, rb_intern("Font"));
|
||||||
|
VALUE fontObj = rb_obj_alloc(fontKlass);
|
||||||
|
rb_obj_call_init(fontObj, 0, 0);
|
||||||
|
|
||||||
|
Font *font = getPrivateData<Font>(fontObj);
|
||||||
|
b->setInitFont(font);
|
||||||
|
|
||||||
|
rb_iv_set(self, "font", fontObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapInitialize)
|
||||||
|
{
|
||||||
|
Bitmap *b = 0;
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
char *filename;
|
||||||
|
rb_get_args(argc, argv, "z", &filename RB_ARG_END);
|
||||||
|
|
||||||
|
GUARD_EXC( b = new Bitmap(filename); )
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int width, height;
|
||||||
|
rb_get_args(argc, argv, "ii", &width, &height RB_ARG_END);
|
||||||
|
|
||||||
|
GUARD_EXC( b = new Bitmap(width, height); )
|
||||||
|
}
|
||||||
|
|
||||||
|
setPrivateData(self, b);
|
||||||
|
bitmapInitProps(b, self);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapWidth)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
int value = 0;
|
||||||
|
GUARD_EXC( value = b->width(); );
|
||||||
|
|
||||||
|
return INT2FIX(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapHeight)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
int value = 0;
|
||||||
|
GUARD_EXC( value = b->height(); );
|
||||||
|
|
||||||
|
return INT2FIX(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapRect)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
IntRect rect;
|
||||||
|
GUARD_EXC( rect = b->rect(); );
|
||||||
|
|
||||||
|
Rect *r = new Rect(rect);
|
||||||
|
|
||||||
|
return wrapObject(r, RectType);
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapBlt)
|
||||||
|
{
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
VALUE srcObj;
|
||||||
|
VALUE srcRectObj;
|
||||||
|
int opacity = 255;
|
||||||
|
|
||||||
|
Bitmap *src;
|
||||||
|
Rect *srcRect;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "iioo|i", &x, &y, &srcObj, &srcRectObj, &opacity RB_ARG_END);
|
||||||
|
|
||||||
|
src = getPrivateDataCheck<Bitmap>(srcObj, BitmapType);
|
||||||
|
srcRect = getPrivateDataCheck<Rect>(srcRectObj, RectType);
|
||||||
|
|
||||||
|
GUARD_EXC( b->blt(x, y, *src, srcRect->toIntRect(), opacity); );
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapStretchBlt)
|
||||||
|
{
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
VALUE destRectObj;
|
||||||
|
VALUE srcObj;
|
||||||
|
VALUE srcRectObj;
|
||||||
|
int opacity = 255;
|
||||||
|
|
||||||
|
Bitmap *src;
|
||||||
|
Rect *destRect, *srcRect;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "ooo|i", &destRectObj, &srcObj, &srcRectObj, &opacity RB_ARG_END);
|
||||||
|
|
||||||
|
src = getPrivateDataCheck<Bitmap>(srcObj, BitmapType);
|
||||||
|
destRect = getPrivateDataCheck<Rect>(destRectObj, RectType);
|
||||||
|
srcRect = getPrivateDataCheck<Rect>(srcRectObj, RectType);
|
||||||
|
|
||||||
|
GUARD_EXC( b->stretchBlt(destRect->toIntRect(), *src, srcRect->toIntRect(), opacity); );
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapFillRect)
|
||||||
|
{
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
VALUE colorObj;
|
||||||
|
Color *color;
|
||||||
|
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
VALUE rectObj;
|
||||||
|
Rect *rect;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "oo", &rectObj, &colorObj RB_ARG_END);
|
||||||
|
|
||||||
|
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
||||||
|
color = getPrivateDataCheck<Color>(colorObj, ColorType);
|
||||||
|
|
||||||
|
GUARD_EXC( b->fillRect(rect->toIntRect(), color->norm); );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int x, y, width, height;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "iiiio", &x, &y, &width, &height, &colorObj RB_ARG_END);
|
||||||
|
|
||||||
|
color = getPrivateDataCheck<Color>(colorObj, ColorType);
|
||||||
|
|
||||||
|
GUARD_EXC( b->fillRect(x, y, width, height, color->norm); );
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapClear)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
GUARD_EXC( b->clear(); )
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapGetPixel)
|
||||||
|
{
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "ii", &x, &y RB_ARG_END);
|
||||||
|
|
||||||
|
Color value;
|
||||||
|
GUARD_EXC( value = b->getPixel(x, y); );
|
||||||
|
|
||||||
|
Color *color = new Color(value);
|
||||||
|
|
||||||
|
return wrapObject(color, ColorType);
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapSetPixel)
|
||||||
|
{
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
VALUE colorObj;
|
||||||
|
|
||||||
|
Color *color;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "iio", &x, &y, &colorObj RB_ARG_END);
|
||||||
|
|
||||||
|
color = getPrivateDataCheck<Color>(colorObj, ColorType);
|
||||||
|
|
||||||
|
GUARD_EXC( b->setPixel(x, y, *color); );
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapHueChange)
|
||||||
|
{
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
int hue;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "i", &hue RB_ARG_END);
|
||||||
|
|
||||||
|
GUARD_EXC( b->hueChange(hue); );
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapDrawText)
|
||||||
|
{
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
const char *str;
|
||||||
|
int align = Bitmap::Left;
|
||||||
|
|
||||||
|
if (argc == 2 || argc == 3)
|
||||||
|
{
|
||||||
|
VALUE rectObj;
|
||||||
|
Rect *rect;
|
||||||
|
|
||||||
|
if (rgssVer >= 2)
|
||||||
|
{
|
||||||
|
VALUE strObj;
|
||||||
|
rb_get_args(argc, argv, "oo|i", &rectObj, &strObj, &align RB_ARG_END);
|
||||||
|
|
||||||
|
str = objAsStringPtr(strObj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rb_get_args(argc, argv, "oz|i", &rectObj, &str, &align RB_ARG_END);
|
||||||
|
}
|
||||||
|
|
||||||
|
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
||||||
|
|
||||||
|
GUARD_EXC( b->drawText(rect->toIntRect(), str, align); );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int x, y, width, height;
|
||||||
|
|
||||||
|
if (rgssVer >= 2)
|
||||||
|
{
|
||||||
|
VALUE strObj;
|
||||||
|
rb_get_args(argc, argv, "iiiio|i", &x, &y, &width, &height, &strObj, &align RB_ARG_END);
|
||||||
|
|
||||||
|
str = objAsStringPtr(strObj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rb_get_args(argc, argv, "iiiiz|i", &x, &y, &width, &height, &str, &align RB_ARG_END);
|
||||||
|
}
|
||||||
|
|
||||||
|
GUARD_EXC( b->drawText(x, y, width, height, str, align); );
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapTextSize)
|
||||||
|
{
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
const char *str;
|
||||||
|
|
||||||
|
if (rgssVer >= 2)
|
||||||
|
{
|
||||||
|
VALUE strObj;
|
||||||
|
rb_get_args(argc, argv, "o", &strObj RB_ARG_END);
|
||||||
|
|
||||||
|
str = objAsStringPtr(strObj);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rb_get_args(argc, argv, "z", &str RB_ARG_END);
|
||||||
|
}
|
||||||
|
|
||||||
|
IntRect value;
|
||||||
|
GUARD_EXC( value = b->textSize(str); );
|
||||||
|
|
||||||
|
Rect *rect = new Rect(value);
|
||||||
|
|
||||||
|
return wrapObject(rect, RectType);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_PROP_OBJ_VAL(Bitmap, Font, Font, "font")
|
||||||
|
|
||||||
|
RB_METHOD(bitmapGradientFillRect)
|
||||||
|
{
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
VALUE color1Obj, color2Obj;
|
||||||
|
Color *color1, *color2;
|
||||||
|
bool vertical = false;
|
||||||
|
|
||||||
|
if (argc == 3 || argc == 4)
|
||||||
|
{
|
||||||
|
VALUE rectObj;
|
||||||
|
Rect *rect;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "ooo|b", &rectObj,
|
||||||
|
&color1Obj, &color2Obj, &vertical RB_ARG_END);
|
||||||
|
|
||||||
|
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
||||||
|
color1 = getPrivateDataCheck<Color>(color1Obj, ColorType);
|
||||||
|
color2 = getPrivateDataCheck<Color>(color2Obj, ColorType);
|
||||||
|
|
||||||
|
GUARD_EXC( b->gradientFillRect(rect->toIntRect(), color1->norm, color2->norm, vertical); );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int x, y, width, height;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "iiiioo|b", &x, &y, &width, &height,
|
||||||
|
&color1Obj, &color2Obj, &vertical RB_ARG_END);
|
||||||
|
|
||||||
|
color1 = getPrivateDataCheck<Color>(color1Obj, ColorType);
|
||||||
|
color2 = getPrivateDataCheck<Color>(color2Obj, ColorType);
|
||||||
|
|
||||||
|
GUARD_EXC( b->gradientFillRect(x, y, width, height, color1->norm, color2->norm, vertical); );
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapClearRect)
|
||||||
|
{
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
VALUE rectObj;
|
||||||
|
Rect *rect;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "o", &rectObj RB_ARG_END);
|
||||||
|
|
||||||
|
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
||||||
|
|
||||||
|
GUARD_EXC( b->clearRect(rect->toIntRect()); );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int x, y, width, height;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END);
|
||||||
|
|
||||||
|
GUARD_EXC( b->clearRect(x, y, width, height); );
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapBlur)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
b->blur();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapRadialBlur)
|
||||||
|
{
|
||||||
|
Bitmap *b = getPrivateData<Bitmap>(self);
|
||||||
|
|
||||||
|
int angle, divisions;
|
||||||
|
rb_get_args(argc, argv, "ii", &angle, &divisions RB_ARG_END);
|
||||||
|
|
||||||
|
b->radialBlur(angle, divisions);
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(bitmapInitializeCopy)
|
||||||
|
{
|
||||||
|
rb_check_argc(argc, 1);
|
||||||
|
VALUE origObj = argv[0];
|
||||||
|
|
||||||
|
if (!OBJ_INIT_COPY(self, origObj))
|
||||||
|
return self;
|
||||||
|
|
||||||
|
Bitmap *orig = getPrivateData<Bitmap>(origObj);
|
||||||
|
Bitmap *b = 0;
|
||||||
|
GUARD_EXC( b = new Bitmap(*orig); );
|
||||||
|
|
||||||
|
bitmapInitProps(b, self);
|
||||||
|
b->setFont(orig->getFont());
|
||||||
|
|
||||||
|
setPrivateData(self, b);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
bitmapBindingInit()
|
||||||
|
{
|
||||||
|
VALUE klass = rb_define_class("Bitmap", rb_cObject);
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&BitmapType>);
|
||||||
|
|
||||||
|
disposableBindingInit<Bitmap>(klass);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "initialize", bitmapInitialize);
|
||||||
|
_rb_define_method(klass, "initialize_copy", bitmapInitializeCopy);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "width", bitmapWidth);
|
||||||
|
_rb_define_method(klass, "height", bitmapHeight);
|
||||||
|
_rb_define_method(klass, "rect", bitmapRect);
|
||||||
|
_rb_define_method(klass, "blt", bitmapBlt);
|
||||||
|
_rb_define_method(klass, "stretch_blt", bitmapStretchBlt);
|
||||||
|
_rb_define_method(klass, "fill_rect", bitmapFillRect);
|
||||||
|
_rb_define_method(klass, "clear", bitmapClear);
|
||||||
|
_rb_define_method(klass, "get_pixel", bitmapGetPixel);
|
||||||
|
_rb_define_method(klass, "set_pixel", bitmapSetPixel);
|
||||||
|
_rb_define_method(klass, "hue_change", bitmapHueChange);
|
||||||
|
_rb_define_method(klass, "draw_text", bitmapDrawText);
|
||||||
|
_rb_define_method(klass, "text_size", bitmapTextSize);
|
||||||
|
|
||||||
|
if (rgssVer >= 2)
|
||||||
|
{
|
||||||
|
_rb_define_method(klass, "gradient_fill_rect", bitmapGradientFillRect);
|
||||||
|
_rb_define_method(klass, "clear_rect", bitmapClearRect);
|
||||||
|
_rb_define_method(klass, "blur", bitmapBlur);
|
||||||
|
_rb_define_method(klass, "radial_blur", bitmapRadialBlur);
|
||||||
|
}
|
||||||
|
|
||||||
|
INIT_PROP_BIND(Bitmap, Font, "font");
|
||||||
|
}
|
115
binding-legacy/disposable-binding.h
Normal file
115
binding-legacy/disposable-binding.h
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
/*
|
||||||
|
** disposable-binding.h
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DISPOSABLEBINDING_H
|
||||||
|
#define DISPOSABLEBINDING_H
|
||||||
|
|
||||||
|
#include "disposable.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
|
||||||
|
/* 'Children' are disposables that are disposed together
|
||||||
|
* with their parent. Currently this is only used by Viewport
|
||||||
|
* in RGSS1. */
|
||||||
|
inline void
|
||||||
|
disposableAddChild(VALUE disp, VALUE child)
|
||||||
|
{
|
||||||
|
VALUE children = rb_iv_get(disp, "children");
|
||||||
|
|
||||||
|
if (NIL_P(children))
|
||||||
|
{
|
||||||
|
children = rb_ary_new();
|
||||||
|
rb_iv_set(disp, "children", children);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Assumes children are never removed until destruction */
|
||||||
|
rb_ary_push(children, child);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
disposableDisposeChildren(VALUE disp)
|
||||||
|
{
|
||||||
|
VALUE children = rb_iv_get(disp, "children");
|
||||||
|
|
||||||
|
if (NIL_P(children))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ID dispFun = rb_intern("_mkxp_dispose_alias");
|
||||||
|
|
||||||
|
for (long i = 0; i < RARRAY_LEN(children); ++i)
|
||||||
|
rb_funcall2(rb_ary_entry(children, i), dispFun, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
RB_METHOD(disposableDispose)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
C *d = getPrivateData<C>(self);
|
||||||
|
|
||||||
|
if (!d)
|
||||||
|
return Qnil;
|
||||||
|
|
||||||
|
/* Nothing to do if already disposed */
|
||||||
|
if (d->isDisposed())
|
||||||
|
return Qnil;
|
||||||
|
|
||||||
|
if (rgssVer == 1)
|
||||||
|
disposableDisposeChildren(self);
|
||||||
|
|
||||||
|
d->dispose();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
RB_METHOD(disposableIsDisposed)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
C *d = getPrivateData<C>(self);
|
||||||
|
|
||||||
|
if (!d)
|
||||||
|
return Qtrue;
|
||||||
|
|
||||||
|
return rb_bool_new(d->isDisposed());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
static void disposableBindingInit(VALUE klass)
|
||||||
|
{
|
||||||
|
_rb_define_method(klass, "dispose", disposableDispose<C>);
|
||||||
|
_rb_define_method(klass, "disposed?", disposableIsDisposed<C>);
|
||||||
|
|
||||||
|
/* Make sure we always have access to the original method, even
|
||||||
|
* if it is overridden by user scripts */
|
||||||
|
if (rgssVer == 1)
|
||||||
|
rb_define_alias(klass, "_mkxp_dispose_alias", "dispose");
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
inline void
|
||||||
|
checkDisposed(VALUE self)
|
||||||
|
{
|
||||||
|
if (disposableIsDisposed<C>(0, 0, self) == Qtrue)
|
||||||
|
raiseDisposedAccess(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // DISPOSABLEBINDING_H
|
225
binding-legacy/etc-binding.cpp
Normal file
225
binding-legacy/etc-binding.cpp
Normal file
|
@ -0,0 +1,225 @@
|
||||||
|
/*
|
||||||
|
** etc-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "etc.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "serializable-binding.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
|
|
||||||
|
DEF_TYPE(Color);
|
||||||
|
DEF_TYPE(Tone);
|
||||||
|
DEF_TYPE(Rect);
|
||||||
|
|
||||||
|
#define ATTR_RW(Klass, Attr, arg_type, arg_t_s, value_fun) \
|
||||||
|
RB_METHOD(Klass##Get##Attr) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM \
|
||||||
|
Klass *p = getPrivateData<Klass>(self); \
|
||||||
|
return value_fun(p->get##Attr()); \
|
||||||
|
} \
|
||||||
|
RB_METHOD(Klass##Set##Attr) \
|
||||||
|
{ \
|
||||||
|
Klass *p = getPrivateData<Klass>(self); \
|
||||||
|
arg_type arg; \
|
||||||
|
rb_get_args(argc, argv, arg_t_s, &arg RB_ARG_END); \
|
||||||
|
p->set##Attr(arg); \
|
||||||
|
return *argv; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ATTR_DOUBLE_RW(Klass, Attr) ATTR_RW(Klass, Attr, double, "f", rb_float_new)
|
||||||
|
#define ATTR_INT_RW(Klass, Attr) ATTR_RW(Klass, Attr, int, "i", rb_fix_new)
|
||||||
|
|
||||||
|
ATTR_DOUBLE_RW(Color, Red)
|
||||||
|
ATTR_DOUBLE_RW(Color, Green)
|
||||||
|
ATTR_DOUBLE_RW(Color, Blue)
|
||||||
|
ATTR_DOUBLE_RW(Color, Alpha)
|
||||||
|
|
||||||
|
ATTR_DOUBLE_RW(Tone, Red)
|
||||||
|
ATTR_DOUBLE_RW(Tone, Green)
|
||||||
|
ATTR_DOUBLE_RW(Tone, Blue)
|
||||||
|
ATTR_DOUBLE_RW(Tone, Gray)
|
||||||
|
|
||||||
|
ATTR_INT_RW(Rect, X)
|
||||||
|
ATTR_INT_RW(Rect, Y)
|
||||||
|
ATTR_INT_RW(Rect, Width)
|
||||||
|
ATTR_INT_RW(Rect, Height)
|
||||||
|
|
||||||
|
#define EQUAL_FUN(Klass) \
|
||||||
|
RB_METHOD(Klass##Equal) \
|
||||||
|
{ \
|
||||||
|
Klass *p = getPrivateData<Klass>(self); \
|
||||||
|
VALUE otherObj; \
|
||||||
|
Klass *other; \
|
||||||
|
rb_get_args(argc, argv, "o", &otherObj RB_ARG_END); \
|
||||||
|
if (rgssVer >= 3) \
|
||||||
|
if (!rb_typeddata_is_kind_of(otherObj, &Klass##Type)) \
|
||||||
|
return Qfalse; \
|
||||||
|
other = getPrivateDataCheck<Klass>(otherObj, Klass##Type); \
|
||||||
|
return rb_bool_new(*p == *other); \
|
||||||
|
}
|
||||||
|
|
||||||
|
EQUAL_FUN(Color)
|
||||||
|
EQUAL_FUN(Tone)
|
||||||
|
EQUAL_FUN(Rect)
|
||||||
|
|
||||||
|
#define INIT_FUN(Klass, param_type, param_t_s, last_param_def) \
|
||||||
|
RB_METHOD(Klass##Initialize) \
|
||||||
|
{ \
|
||||||
|
Klass *k; \
|
||||||
|
if (argc == 0) \
|
||||||
|
{ \
|
||||||
|
k = new Klass(); \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
param_type p1, p2, p3, p4 = last_param_def; \
|
||||||
|
rb_get_args(argc, argv, param_t_s, &p1, &p2, &p3, &p4 RB_ARG_END); \
|
||||||
|
k = new Klass(p1, p2, p3, p4); \
|
||||||
|
} \
|
||||||
|
setPrivateData(self, k); \
|
||||||
|
return self; \
|
||||||
|
}
|
||||||
|
|
||||||
|
INIT_FUN(Color, double, "fff|f", 255)
|
||||||
|
INIT_FUN(Tone, double, "fff|f", 0)
|
||||||
|
INIT_FUN(Rect, int, "iiii", 0)
|
||||||
|
|
||||||
|
#define SET_FUN(Klass, param_type, param_t_s, last_param_def) \
|
||||||
|
RB_METHOD(Klass##Set) \
|
||||||
|
{ \
|
||||||
|
Klass *k = getPrivateData<Klass>(self); \
|
||||||
|
if (argc == 1) \
|
||||||
|
{ \
|
||||||
|
VALUE otherObj = argv[0]; \
|
||||||
|
Klass *other = getPrivateDataCheck<Klass>(otherObj, Klass##Type); \
|
||||||
|
*k = *other; \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
param_type p1, p2, p3, p4 = last_param_def; \
|
||||||
|
rb_get_args(argc, argv, param_t_s, &p1, &p2, &p3, &p4 RB_ARG_END); \
|
||||||
|
k->set(p1, p2, p3, p4); \
|
||||||
|
} \
|
||||||
|
return self; \
|
||||||
|
}
|
||||||
|
|
||||||
|
SET_FUN(Color, double, "fff|f", 255)
|
||||||
|
SET_FUN(Tone, double, "fff|f", 0)
|
||||||
|
SET_FUN(Rect, int, "iiii", 0)
|
||||||
|
|
||||||
|
RB_METHOD(rectEmpty)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
Rect *r = getPrivateData<Rect>(self);
|
||||||
|
r->empty();
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(ColorStringify)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
Color *c = getPrivateData<Color>(self);
|
||||||
|
|
||||||
|
return rb_sprintf("(%f, %f, %f, %f)",
|
||||||
|
c->red, c->green, c->blue, c->alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(ToneStringify)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
Tone *t = getPrivateData<Tone>(self);
|
||||||
|
|
||||||
|
return rb_sprintf("(%f, %f, %f, %f)",
|
||||||
|
t->red, t->green, t->blue, t->gray);
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(RectStringify)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
Rect *r = getPrivateData<Rect>(self);
|
||||||
|
|
||||||
|
return rb_sprintf("(%d, %d, %d, %d)",
|
||||||
|
r->x, r->y, r->width, r->height);
|
||||||
|
}
|
||||||
|
|
||||||
|
MARSH_LOAD_FUN(Color)
|
||||||
|
MARSH_LOAD_FUN(Tone)
|
||||||
|
MARSH_LOAD_FUN(Rect)
|
||||||
|
|
||||||
|
INITCOPY_FUN(Tone)
|
||||||
|
INITCOPY_FUN(Color)
|
||||||
|
INITCOPY_FUN(Rect)
|
||||||
|
|
||||||
|
#define INIT_BIND(Klass) \
|
||||||
|
{ \
|
||||||
|
klass = rb_define_class(#Klass, rb_cObject); \
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&Klass##Type>); \
|
||||||
|
rb_define_class_method(klass, "_load", Klass##Load); \
|
||||||
|
serializableBindingInit<Klass>(klass); \
|
||||||
|
_rb_define_method(klass, "initialize", Klass##Initialize); \
|
||||||
|
_rb_define_method(klass, "initialize_copy", Klass##InitializeCopy); \
|
||||||
|
_rb_define_method(klass, "set", Klass##Set); \
|
||||||
|
_rb_define_method(klass, "==", Klass##Equal); \
|
||||||
|
_rb_define_method(klass, "===", Klass##Equal); \
|
||||||
|
_rb_define_method(klass, "eql?", Klass##Equal); \
|
||||||
|
_rb_define_method(klass, "to_s", Klass##Stringify); \
|
||||||
|
_rb_define_method(klass, "inspect", Klass##Stringify); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MRB_ATTR_R(Class, attr) mrb_define_method(mrb, klass, #attr, Class##Get_##attr, MRB_ARGS_NONE())
|
||||||
|
#define MRB_ATTR_W(Class, attr) mrb_define_method(mrb, klass, #attr "=", Class##Set_##attr, MRB_ARGS_REQ(1))
|
||||||
|
#define MRB_ATTR_RW(Class, attr) { MRB_ATTR_R(Class, attr); MRB_ATTR_W(Class, attr); }
|
||||||
|
|
||||||
|
#define RB_ATTR_R(Klass, Attr, attr) _rb_define_method(klass, #attr, Klass##Get##Attr)
|
||||||
|
#define RB_ATTR_W(Klass, Attr, attr) _rb_define_method(klass, #attr "=", Klass##Set##Attr)
|
||||||
|
#define RB_ATTR_RW(Klass, Attr, attr) \
|
||||||
|
{ RB_ATTR_R(Klass, Attr, attr); RB_ATTR_W(Klass, Attr, attr); }
|
||||||
|
|
||||||
|
void
|
||||||
|
etcBindingInit()
|
||||||
|
{
|
||||||
|
VALUE klass;
|
||||||
|
|
||||||
|
INIT_BIND(Color);
|
||||||
|
|
||||||
|
RB_ATTR_RW(Color, Red, red);
|
||||||
|
RB_ATTR_RW(Color, Green, green);
|
||||||
|
RB_ATTR_RW(Color, Blue, blue);
|
||||||
|
RB_ATTR_RW(Color, Alpha, alpha);
|
||||||
|
|
||||||
|
INIT_BIND(Tone);
|
||||||
|
|
||||||
|
RB_ATTR_RW(Tone, Red, red);
|
||||||
|
RB_ATTR_RW(Tone, Green, green);
|
||||||
|
RB_ATTR_RW(Tone, Blue, blue);
|
||||||
|
RB_ATTR_RW(Tone, Gray, gray);
|
||||||
|
|
||||||
|
INIT_BIND(Rect);
|
||||||
|
|
||||||
|
RB_ATTR_RW(Rect, X, x);
|
||||||
|
RB_ATTR_RW(Rect, Y, y);
|
||||||
|
RB_ATTR_RW(Rect, Width, width);
|
||||||
|
RB_ATTR_RW(Rect, Height, height);
|
||||||
|
_rb_define_method(klass, "empty", rectEmpty);
|
||||||
|
}
|
229
binding-legacy/filesystem-binding.cpp
Normal file
229
binding-legacy/filesystem-binding.cpp
Normal file
|
@ -0,0 +1,229 @@
|
||||||
|
/*
|
||||||
|
** filesystem-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "binding-util.h"
|
||||||
|
|
||||||
|
#include "sharedstate.h"
|
||||||
|
#include "filesystem.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
#include "ruby/encoding.h"
|
||||||
|
#include "ruby/intern.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
fileIntFreeInstance(void *inst)
|
||||||
|
{
|
||||||
|
SDL_RWops *ops = static_cast<SDL_RWops*>(inst);
|
||||||
|
|
||||||
|
SDL_RWclose(ops);
|
||||||
|
SDL_FreeRW(ops);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_TYPE_CUSTOMFREE(FileInt, fileIntFreeInstance);
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
fileIntForPath(const char *path, bool rubyExc)
|
||||||
|
{
|
||||||
|
SDL_RWops *ops = SDL_AllocRW();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
shState->fileSystem().openReadRaw(*ops, path);
|
||||||
|
}
|
||||||
|
catch (const Exception &e)
|
||||||
|
{
|
||||||
|
SDL_FreeRW(ops);
|
||||||
|
|
||||||
|
if (rubyExc)
|
||||||
|
raiseRbExc(e);
|
||||||
|
else
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE klass = rb_const_get(rb_cObject, rb_intern("FileInt"));
|
||||||
|
|
||||||
|
VALUE obj = rb_obj_alloc(klass);
|
||||||
|
|
||||||
|
setPrivateData(obj, ops);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(fileIntRead)
|
||||||
|
{
|
||||||
|
|
||||||
|
int length = -1;
|
||||||
|
rb_get_args(argc, argv, "i", &length RB_ARG_END);
|
||||||
|
|
||||||
|
SDL_RWops *ops = getPrivateData<SDL_RWops>(self);
|
||||||
|
|
||||||
|
if (length == -1)
|
||||||
|
{
|
||||||
|
Sint64 cur = SDL_RWtell(ops);
|
||||||
|
Sint64 end = SDL_RWseek(ops, 0, SEEK_END);
|
||||||
|
length = end - cur;
|
||||||
|
SDL_RWseek(ops, cur, SEEK_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length == 0)
|
||||||
|
return Qnil;
|
||||||
|
|
||||||
|
VALUE data = rb_str_new(0, length);
|
||||||
|
|
||||||
|
SDL_RWread(ops, RSTRING_PTR(data), 1, length);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(fileIntClose)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
SDL_RWops *ops = getPrivateData<SDL_RWops>(self);
|
||||||
|
SDL_RWclose(ops);
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(fileIntGetByte)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
SDL_RWops *ops = getPrivateData<SDL_RWops>(self);
|
||||||
|
|
||||||
|
unsigned char byte;
|
||||||
|
size_t result = SDL_RWread(ops, &byte, 1, 1);
|
||||||
|
|
||||||
|
return (result == 1) ? rb_fix_new(byte) : Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(fileIntBinmode)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
kernelLoadDataInt(const char *filename, bool rubyExc)
|
||||||
|
{
|
||||||
|
rb_gc_start();
|
||||||
|
|
||||||
|
VALUE port = fileIntForPath(filename, rubyExc);
|
||||||
|
|
||||||
|
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
|
||||||
|
|
||||||
|
// FIXME need to catch exceptions here with begin rescue
|
||||||
|
VALUE result = rb_funcall2(marsh, rb_intern("load"), 1, &port);
|
||||||
|
|
||||||
|
rb_funcall2(port, rb_intern("close"), 0, NULL);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(kernelLoadData)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
const char *filename;
|
||||||
|
rb_get_args(argc, argv, "z", &filename RB_ARG_END);
|
||||||
|
|
||||||
|
return kernelLoadDataInt(filename, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(kernelSaveData)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
VALUE obj;
|
||||||
|
VALUE filename;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "oS", &obj, &filename RB_ARG_END);
|
||||||
|
|
||||||
|
VALUE file = rb_file_open_str(filename, "wb");
|
||||||
|
|
||||||
|
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
|
||||||
|
|
||||||
|
VALUE v[] = { obj, file };
|
||||||
|
rb_funcall2(marsh, rb_intern("dump"), ARRAY_SIZE(v), v);
|
||||||
|
|
||||||
|
rb_io_close(file);
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE stringForceUTF8(VALUE arg)
|
||||||
|
{
|
||||||
|
if (RB_TYPE_P(arg, RUBY_T_STRING) && ENCODING_IS_ASCII8BIT(arg))
|
||||||
|
rb_enc_associate_index(arg, rb_utf8_encindex());
|
||||||
|
|
||||||
|
return arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
static VALUE customProc(VALUE arg, VALUE proc)
|
||||||
|
{
|
||||||
|
VALUE obj = stringForceUTF8(arg);
|
||||||
|
obj = rb_funcall2(proc, rb_intern("call"), 1, &obj);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(_marshalLoad)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
VALUE port, proc = Qnil;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "o|o", &port, &proc RB_ARG_END);
|
||||||
|
|
||||||
|
VALUE utf8Proc;
|
||||||
|
if (NIL_P(proc))
|
||||||
|
utf8Proc = rb_proc_new(RUBY_METHOD_FUNC(stringForceUTF8), Qnil);
|
||||||
|
else
|
||||||
|
utf8Proc = rb_proc_new(RUBY_METHOD_FUNC(customProc), proc);
|
||||||
|
|
||||||
|
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
|
||||||
|
|
||||||
|
VALUE v[] = { port, utf8Proc };
|
||||||
|
return rb_funcall2(marsh, rb_intern("_mkxp_load_alias"), ARRAY_SIZE(v), v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
fileIntBindingInit()
|
||||||
|
{
|
||||||
|
VALUE klass = rb_define_class("FileInt", rb_cIO);
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&FileIntType>);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "read", fileIntRead);
|
||||||
|
_rb_define_method(klass, "getbyte", fileIntGetByte);
|
||||||
|
_rb_define_method(klass, "binmode", fileIntBinmode);
|
||||||
|
_rb_define_method(klass, "close", fileIntClose);
|
||||||
|
|
||||||
|
_rb_define_module_function(rb_mKernel, "load_data", kernelLoadData);
|
||||||
|
_rb_define_module_function(rb_mKernel, "save_data", kernelSaveData);
|
||||||
|
|
||||||
|
/* We overload the built-in 'Marshal::load()' function to silently
|
||||||
|
* insert our utf8proc that ensures all read strings will be
|
||||||
|
* UTF-8 encoded */
|
||||||
|
VALUE marsh = rb_const_get(rb_cObject, rb_intern("Marshal"));
|
||||||
|
rb_define_alias(rb_singleton_class(marsh), "_mkxp_load_alias", "load");
|
||||||
|
_rb_define_module_function(marsh, "load", _marshalLoad);
|
||||||
|
}
|
73
binding-legacy/flashable-binding.h
Normal file
73
binding-legacy/flashable-binding.h
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
** flashable-binding.h
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLASHABLEBINDING_H
|
||||||
|
#define FLASHABLEBINDING_H
|
||||||
|
|
||||||
|
#include "flashable.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "binding-types.h"
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
RB_METHOD(flashableFlash)
|
||||||
|
{
|
||||||
|
Flashable *f = getPrivateData<C>(self);
|
||||||
|
|
||||||
|
VALUE colorObj;
|
||||||
|
int duration;
|
||||||
|
|
||||||
|
Color *color;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "oi", &colorObj, &duration RB_ARG_END);
|
||||||
|
|
||||||
|
if (NIL_P(colorObj))
|
||||||
|
{
|
||||||
|
f->flash(0, duration);
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
color = getPrivateDataCheck<Color>(colorObj, ColorType);
|
||||||
|
|
||||||
|
f->flash(&color->norm, duration);
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
RB_METHOD(flashableUpdate)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
Flashable *f = getPrivateData<C>(self);
|
||||||
|
|
||||||
|
f->update();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
static void flashableBindingInit(VALUE klass)
|
||||||
|
{
|
||||||
|
_rb_define_method(klass, "flash", flashableFlash<C>);
|
||||||
|
_rb_define_method(klass, "update", flashableUpdate<C>);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FLASHABLEBINDING_H
|
328
binding-legacy/font-binding.cpp
Normal file
328
binding-legacy/font-binding.cpp
Normal file
|
@ -0,0 +1,328 @@
|
||||||
|
/*
|
||||||
|
** font-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "font.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "binding-types.h"
|
||||||
|
#include "exception.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
collectStrings(VALUE obj, std::vector<std::string> &out)
|
||||||
|
{
|
||||||
|
if (RB_TYPE_P(obj, RUBY_T_STRING))
|
||||||
|
{
|
||||||
|
out.push_back(RSTRING_PTR(obj));
|
||||||
|
}
|
||||||
|
else if (RB_TYPE_P(obj, RUBY_T_ARRAY))
|
||||||
|
{
|
||||||
|
for (long i = 0; i < RARRAY_LEN(obj); ++i)
|
||||||
|
{
|
||||||
|
VALUE str = rb_ary_entry(obj, i);
|
||||||
|
|
||||||
|
/* Non-string objects are tolerated (ignored) */
|
||||||
|
if (!RB_TYPE_P(str, RUBY_T_STRING))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
out.push_back(RSTRING_PTR(str));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_TYPE(Font);
|
||||||
|
|
||||||
|
RB_METHOD(fontDoesExist)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
const char *name = 0;
|
||||||
|
VALUE nameObj;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "o", &nameObj RB_ARG_END);
|
||||||
|
|
||||||
|
if (RB_TYPE_P(nameObj, RUBY_T_STRING))
|
||||||
|
name = rb_string_value_cstr(&nameObj);
|
||||||
|
|
||||||
|
return rb_bool_new(Font::doesExist(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(FontSetName);
|
||||||
|
|
||||||
|
RB_METHOD(fontInitialize)
|
||||||
|
{
|
||||||
|
VALUE namesObj = Qnil;
|
||||||
|
int size = 0;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "|oi", &namesObj, &size RB_ARG_END);
|
||||||
|
|
||||||
|
Font *f;
|
||||||
|
|
||||||
|
if (NIL_P(namesObj))
|
||||||
|
{
|
||||||
|
namesObj = rb_iv_get(rb_obj_class(self), "default_name");
|
||||||
|
f = new Font(0, size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::vector<std::string> names;
|
||||||
|
collectStrings(namesObj, names);
|
||||||
|
|
||||||
|
f = new Font(&names, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This is semantically wrong; the new Font object should take
|
||||||
|
* a dup'ed object here in case of an array. Ditto for the setters.
|
||||||
|
* However the same bug/behavior exists in all RM versions. */
|
||||||
|
rb_iv_set(self, "name", namesObj);
|
||||||
|
|
||||||
|
setPrivateData(self, f);
|
||||||
|
|
||||||
|
/* Wrap property objects */
|
||||||
|
f->initDynAttribs();
|
||||||
|
|
||||||
|
wrapProperty(self, &f->getColor(), "color", ColorType);
|
||||||
|
|
||||||
|
if (rgssVer >= 3)
|
||||||
|
wrapProperty(self, &f->getOutColor(), "out_color", ColorType);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(fontInitializeCopy)
|
||||||
|
{
|
||||||
|
VALUE origObj;
|
||||||
|
rb_get_args(argc, argv, "o", &origObj RB_ARG_END);
|
||||||
|
|
||||||
|
if (!OBJ_INIT_COPY(self, origObj))
|
||||||
|
return self;
|
||||||
|
|
||||||
|
Font *orig = getPrivateData<Font>(origObj);
|
||||||
|
Font *f = new Font(*orig);
|
||||||
|
setPrivateData(self, f);
|
||||||
|
|
||||||
|
/* Wrap property objects */
|
||||||
|
f->initDynAttribs();
|
||||||
|
|
||||||
|
wrapProperty(self, &f->getColor(), "color", ColorType);
|
||||||
|
|
||||||
|
if (rgssVer >= 3)
|
||||||
|
wrapProperty(self, &f->getOutColor(), "out_color", ColorType);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(FontGetName)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
return rb_iv_get(self, "name");
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(FontSetName)
|
||||||
|
{
|
||||||
|
Font *f = getPrivateData<Font>(self);
|
||||||
|
|
||||||
|
rb_check_argc(argc, 1);
|
||||||
|
|
||||||
|
std::vector<std::string> namesObj;
|
||||||
|
collectStrings(argv[0], namesObj);
|
||||||
|
|
||||||
|
f->setName(namesObj);
|
||||||
|
rb_iv_set(self, "name", argv[0]);
|
||||||
|
|
||||||
|
return argv[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
static void checkDisposed(VALUE) {}
|
||||||
|
|
||||||
|
DEF_PROP_OBJ_VAL(Font, Color, Color, "color")
|
||||||
|
DEF_PROP_OBJ_VAL(Font, Color, OutColor, "out_color")
|
||||||
|
|
||||||
|
DEF_PROP_I(Font, Size)
|
||||||
|
|
||||||
|
DEF_PROP_B(Font, Bold)
|
||||||
|
DEF_PROP_B(Font, Italic)
|
||||||
|
DEF_PROP_B(Font, Shadow)
|
||||||
|
DEF_PROP_B(Font, Outline)
|
||||||
|
|
||||||
|
#define DEF_KLASS_PROP(Klass, type, PropName, param_t_s, value_fun) \
|
||||||
|
RB_METHOD(Klass##Get##PropName) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
return value_fun(Klass::get##PropName()); \
|
||||||
|
} \
|
||||||
|
RB_METHOD(Klass##Set##PropName) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
type value; \
|
||||||
|
rb_get_args(argc, argv, param_t_s, &value RB_ARG_END); \
|
||||||
|
Klass::set##PropName(value); \
|
||||||
|
return value_fun(value); \
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_KLASS_PROP(Font, int, DefaultSize, "i", rb_fix_new)
|
||||||
|
DEF_KLASS_PROP(Font, bool, DefaultBold, "b", rb_bool_new)
|
||||||
|
DEF_KLASS_PROP(Font, bool, DefaultItalic, "b", rb_bool_new)
|
||||||
|
DEF_KLASS_PROP(Font, bool, DefaultShadow, "b", rb_bool_new)
|
||||||
|
DEF_KLASS_PROP(Font, bool, DefaultOutline, "b", rb_bool_new)
|
||||||
|
|
||||||
|
RB_METHOD(FontGetDefaultOutColor)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
return rb_iv_get(self, "default_out_color");
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(FontSetDefaultOutColor)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
VALUE colorObj;
|
||||||
|
rb_get_args(argc, argv, "o", &colorObj RB_ARG_END);
|
||||||
|
|
||||||
|
Color *c = getPrivateDataCheck<Color>(colorObj, ColorType);
|
||||||
|
|
||||||
|
Font::setDefaultOutColor(*c);
|
||||||
|
|
||||||
|
return colorObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(FontGetDefaultName)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
return rb_iv_get(self, "default_name");
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(FontSetDefaultName)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
rb_check_argc(argc, 1);
|
||||||
|
|
||||||
|
std::vector<std::string> namesObj;
|
||||||
|
collectStrings(argv[0], namesObj);
|
||||||
|
|
||||||
|
Font::setDefaultName(namesObj, shState->fontState());
|
||||||
|
rb_iv_set(self, "default_name", argv[0]);
|
||||||
|
|
||||||
|
return argv[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(FontGetDefaultColor)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
return rb_iv_get(self, "default_color");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RB_METHOD(FontSetDefaultColor)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
VALUE colorObj;
|
||||||
|
rb_get_args(argc, argv, "o", &colorObj RB_ARG_END);
|
||||||
|
|
||||||
|
Color *c = getPrivateDataCheck<Color>(colorObj, ColorType);
|
||||||
|
|
||||||
|
Font::setDefaultColor(*c);
|
||||||
|
|
||||||
|
return colorObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define INIT_KLASS_PROP_BIND(Klass, PropName, prop_name_s) \
|
||||||
|
{ \
|
||||||
|
rb_define_class_method(klass, prop_name_s, Klass##Get##PropName); \
|
||||||
|
rb_define_class_method(klass, prop_name_s "=", Klass##Set##PropName); \
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
fontBindingInit()
|
||||||
|
{
|
||||||
|
VALUE klass = rb_define_class("Font", rb_cObject);
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&FontType>);
|
||||||
|
|
||||||
|
Font::initDefaultDynAttribs();
|
||||||
|
wrapProperty(klass, &Font::getDefaultColor(), "default_color", ColorType);
|
||||||
|
|
||||||
|
/* Initialize default names */
|
||||||
|
const std::vector<std::string> &defNames = Font::getInitialDefaultNames();
|
||||||
|
VALUE defNamesObj;
|
||||||
|
|
||||||
|
if (defNames.size() == 1)
|
||||||
|
{
|
||||||
|
defNamesObj = rb_str_new_cstr(defNames[0].c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
defNamesObj = rb_ary_new2(defNames.size());
|
||||||
|
|
||||||
|
for (size_t i = 0; i < defNames.size(); ++i)
|
||||||
|
rb_ary_push(defNamesObj, rb_str_new_cstr(defNames[i].c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
rb_iv_set(klass, "default_name", defNamesObj);
|
||||||
|
|
||||||
|
if (rgssVer >= 3)
|
||||||
|
wrapProperty(klass, &Font::getDefaultOutColor(), "default_out_color", ColorType);
|
||||||
|
|
||||||
|
INIT_KLASS_PROP_BIND(Font, DefaultName, "default_name");
|
||||||
|
INIT_KLASS_PROP_BIND(Font, DefaultSize, "default_size");
|
||||||
|
INIT_KLASS_PROP_BIND(Font, DefaultBold, "default_bold");
|
||||||
|
INIT_KLASS_PROP_BIND(Font, DefaultItalic, "default_italic");
|
||||||
|
INIT_KLASS_PROP_BIND(Font, DefaultColor, "default_color");
|
||||||
|
|
||||||
|
if (rgssVer >= 2)
|
||||||
|
{
|
||||||
|
INIT_KLASS_PROP_BIND(Font, DefaultShadow, "default_shadow");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rgssVer >= 3)
|
||||||
|
{
|
||||||
|
INIT_KLASS_PROP_BIND(Font, DefaultOutline, "default_outline");
|
||||||
|
INIT_KLASS_PROP_BIND(Font, DefaultOutColor, "default_out_color");
|
||||||
|
}
|
||||||
|
|
||||||
|
rb_define_class_method(klass, "exist?", fontDoesExist);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "initialize", fontInitialize);
|
||||||
|
_rb_define_method(klass, "initialize_copy", fontInitializeCopy);
|
||||||
|
|
||||||
|
INIT_PROP_BIND(Font, Name, "name");
|
||||||
|
INIT_PROP_BIND(Font, Size, "size");
|
||||||
|
INIT_PROP_BIND(Font, Bold, "bold");
|
||||||
|
INIT_PROP_BIND(Font, Italic, "italic");
|
||||||
|
INIT_PROP_BIND(Font, Color, "color");
|
||||||
|
|
||||||
|
if (rgssVer >= 2)
|
||||||
|
{
|
||||||
|
INIT_PROP_BIND(Font, Shadow, "shadow");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rgssVer >= 3)
|
||||||
|
{
|
||||||
|
INIT_PROP_BIND(Font, Outline, "outline");
|
||||||
|
INIT_PROP_BIND(Font, OutColor, "out_color");
|
||||||
|
}
|
||||||
|
}
|
245
binding-legacy/graphics-binding.cpp
Normal file
245
binding-legacy/graphics-binding.cpp
Normal file
|
@ -0,0 +1,245 @@
|
||||||
|
/*
|
||||||
|
** graphics-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "graphics.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "binding-types.h"
|
||||||
|
#include "exception.h"
|
||||||
|
|
||||||
|
RB_METHOD(graphicsUpdate)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
shState->graphics().update();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(graphicsFreeze)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
shState->graphics().freeze();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(graphicsTransition)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
int duration = 8;
|
||||||
|
const char *filename = "";
|
||||||
|
int vague = 40;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "|izi", &duration, &filename, &vague RB_ARG_END);
|
||||||
|
|
||||||
|
GUARD_EXC( shState->graphics().transition(duration, filename, vague); )
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(graphicsFrameReset)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
shState->graphics().frameReset();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DEF_GRA_PROP_I(PropName) \
|
||||||
|
RB_METHOD(graphics##Get##PropName) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
return rb_fix_new(shState->graphics().get##PropName()); \
|
||||||
|
} \
|
||||||
|
RB_METHOD(graphics##Set##PropName) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
int value; \
|
||||||
|
rb_get_args(argc, argv, "i", &value RB_ARG_END); \
|
||||||
|
shState->graphics().set##PropName(value); \
|
||||||
|
return rb_fix_new(value); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DEF_GRA_PROP_B(PropName) \
|
||||||
|
RB_METHOD(graphics##Get##PropName) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
return rb_bool_new(shState->graphics().get##PropName()); \
|
||||||
|
} \
|
||||||
|
RB_METHOD(graphics##Set##PropName) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM; \
|
||||||
|
bool value; \
|
||||||
|
rb_get_args(argc, argv, "b", &value RB_ARG_END); \
|
||||||
|
shState->graphics().set##PropName(value); \
|
||||||
|
return rb_bool_new(value); \
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(graphicsWidth)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
return rb_fix_new(shState->graphics().width());
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(graphicsHeight)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
return rb_fix_new(shState->graphics().height());
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(graphicsWait)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
int duration;
|
||||||
|
rb_get_args(argc, argv, "i", &duration RB_ARG_END);
|
||||||
|
|
||||||
|
shState->graphics().wait(duration);
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(graphicsFadeout)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
int duration;
|
||||||
|
rb_get_args(argc, argv, "i", &duration RB_ARG_END);
|
||||||
|
|
||||||
|
shState->graphics().fadeout(duration);
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(graphicsFadein)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
int duration;
|
||||||
|
rb_get_args(argc, argv, "i", &duration RB_ARG_END);
|
||||||
|
|
||||||
|
shState->graphics().fadein(duration);
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bitmapInitProps(Bitmap *b, VALUE self);
|
||||||
|
|
||||||
|
RB_METHOD(graphicsSnapToBitmap)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
Bitmap *result = 0;
|
||||||
|
GUARD_EXC( result = shState->graphics().snapToBitmap(); );
|
||||||
|
|
||||||
|
VALUE obj = wrapObject(result, BitmapType);
|
||||||
|
bitmapInitProps(result, obj);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(graphicsResizeScreen)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
int width, height;
|
||||||
|
rb_get_args(argc, argv, "ii", &width, &height RB_ARG_END);
|
||||||
|
|
||||||
|
shState->graphics().resizeScreen(width, height);
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(graphicsReset)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
shState->graphics().reset();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(graphicsPlayMovie)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
const char *filename;
|
||||||
|
rb_get_args(argc, argv, "z", &filename RB_ARG_END);
|
||||||
|
|
||||||
|
shState->graphics().playMovie(filename);
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_GRA_PROP_I(FrameRate)
|
||||||
|
DEF_GRA_PROP_I(FrameCount)
|
||||||
|
DEF_GRA_PROP_I(Brightness)
|
||||||
|
|
||||||
|
DEF_GRA_PROP_B(Fullscreen)
|
||||||
|
DEF_GRA_PROP_B(ShowCursor)
|
||||||
|
|
||||||
|
#define INIT_GRA_PROP_BIND(PropName, prop_name_s) \
|
||||||
|
{ \
|
||||||
|
_rb_define_module_function(module, prop_name_s, graphics##Get##PropName); \
|
||||||
|
_rb_define_module_function(module, prop_name_s "=", graphics##Set##PropName); \
|
||||||
|
}
|
||||||
|
|
||||||
|
void graphicsBindingInit()
|
||||||
|
{
|
||||||
|
VALUE module = rb_define_module("Graphics");
|
||||||
|
|
||||||
|
_rb_define_module_function(module, "update", graphicsUpdate);
|
||||||
|
_rb_define_module_function(module, "freeze", graphicsFreeze);
|
||||||
|
_rb_define_module_function(module, "transition", graphicsTransition);
|
||||||
|
_rb_define_module_function(module, "frame_reset", graphicsFrameReset);
|
||||||
|
|
||||||
|
_rb_define_module_function(module, "__reset__", graphicsReset);
|
||||||
|
|
||||||
|
INIT_GRA_PROP_BIND( FrameRate, "frame_rate" );
|
||||||
|
INIT_GRA_PROP_BIND( FrameCount, "frame_count" );
|
||||||
|
|
||||||
|
if (rgssVer >= 2)
|
||||||
|
{
|
||||||
|
_rb_define_module_function(module, "width", graphicsWidth);
|
||||||
|
_rb_define_module_function(module, "height", graphicsHeight);
|
||||||
|
_rb_define_module_function(module, "wait", graphicsWait);
|
||||||
|
_rb_define_module_function(module, "fadeout", graphicsFadeout);
|
||||||
|
_rb_define_module_function(module, "fadein", graphicsFadein);
|
||||||
|
_rb_define_module_function(module, "snap_to_bitmap", graphicsSnapToBitmap);
|
||||||
|
_rb_define_module_function(module, "resize_screen", graphicsResizeScreen);
|
||||||
|
|
||||||
|
INIT_GRA_PROP_BIND( Brightness, "brightness" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rgssVer >= 3)
|
||||||
|
{
|
||||||
|
_rb_define_module_function(module, "play_movie", graphicsPlayMovie);
|
||||||
|
}
|
||||||
|
|
||||||
|
INIT_GRA_PROP_BIND( Fullscreen, "fullscreen" );
|
||||||
|
INIT_GRA_PROP_BIND( ShowCursor, "show_cursor" );
|
||||||
|
}
|
200
binding-legacy/input-binding.cpp
Normal file
200
binding-legacy/input-binding.cpp
Normal file
|
@ -0,0 +1,200 @@
|
||||||
|
/*
|
||||||
|
** input-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "input.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
|
#include "exception.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
RB_METHOD(inputUpdate)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
shState->input().update();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getButtonArg(int argc, VALUE *argv)
|
||||||
|
{
|
||||||
|
int num;
|
||||||
|
|
||||||
|
rb_check_argc(argc, 1);
|
||||||
|
|
||||||
|
if (FIXNUM_P(argv[0]))
|
||||||
|
{
|
||||||
|
num = FIX2INT(argv[0]);
|
||||||
|
}
|
||||||
|
else if (SYMBOL_P(argv[0]) && rgssVer >= 3)
|
||||||
|
{
|
||||||
|
VALUE symHash = getRbData()->buttoncodeHash;
|
||||||
|
num = FIX2INT(rb_hash_lookup2(symHash, argv[0], INT2FIX(Input::None)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// FIXME: RMXP allows only few more types that
|
||||||
|
// don't make sense (symbols in pre 3, floats)
|
||||||
|
num = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(inputPress)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
int num = getButtonArg(argc, argv);
|
||||||
|
|
||||||
|
return rb_bool_new(shState->input().isPressed(num));
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(inputTrigger)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
int num = getButtonArg(argc, argv);
|
||||||
|
|
||||||
|
return rb_bool_new(shState->input().isTriggered(num));
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(inputRepeat)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
int num = getButtonArg(argc, argv);
|
||||||
|
|
||||||
|
return rb_bool_new(shState->input().isRepeated(num));
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(inputDir4)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
return rb_fix_new(shState->input().dir4Value());
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(inputDir8)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
return rb_fix_new(shState->input().dir8Value());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Non-standard extensions */
|
||||||
|
RB_METHOD(inputMouseX)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
return rb_fix_new(shState->input().mouseX());
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(inputMouseY)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
return rb_fix_new(shState->input().mouseY());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
const char *str;
|
||||||
|
Input::ButtonCode val;
|
||||||
|
}
|
||||||
|
static buttonCodes[] =
|
||||||
|
{
|
||||||
|
{ "DOWN", Input::Down },
|
||||||
|
{ "LEFT", Input::Left },
|
||||||
|
{ "RIGHT", Input::Right },
|
||||||
|
{ "UP", Input::Up },
|
||||||
|
|
||||||
|
{ "A", Input::A },
|
||||||
|
{ "B", Input::B },
|
||||||
|
{ "C", Input::C },
|
||||||
|
{ "X", Input::X },
|
||||||
|
{ "Y", Input::Y },
|
||||||
|
{ "Z", Input::Z },
|
||||||
|
{ "L", Input::L },
|
||||||
|
{ "R", Input::R },
|
||||||
|
|
||||||
|
{ "SHIFT", Input::Shift },
|
||||||
|
{ "CTRL", Input::Ctrl },
|
||||||
|
{ "ALT", Input::Alt },
|
||||||
|
|
||||||
|
{ "F5", Input::F5 },
|
||||||
|
{ "F6", Input::F6 },
|
||||||
|
{ "F7", Input::F7 },
|
||||||
|
{ "F8", Input::F8 },
|
||||||
|
{ "F9", Input::F9 },
|
||||||
|
|
||||||
|
{ "MOUSELEFT", Input::MouseLeft },
|
||||||
|
{ "MOUSEMIDDLE", Input::MouseMiddle },
|
||||||
|
{ "MOUSERIGHT", Input::MouseRight }
|
||||||
|
};
|
||||||
|
|
||||||
|
static elementsN(buttonCodes);
|
||||||
|
|
||||||
|
void
|
||||||
|
inputBindingInit()
|
||||||
|
{
|
||||||
|
VALUE module = rb_define_module("Input");
|
||||||
|
|
||||||
|
_rb_define_module_function(module, "update", inputUpdate);
|
||||||
|
_rb_define_module_function(module, "press?", inputPress);
|
||||||
|
_rb_define_module_function(module, "trigger?", inputTrigger);
|
||||||
|
_rb_define_module_function(module, "repeat?", inputRepeat);
|
||||||
|
_rb_define_module_function(module, "dir4", inputDir4);
|
||||||
|
_rb_define_module_function(module, "dir8", inputDir8);
|
||||||
|
|
||||||
|
_rb_define_module_function(module, "mouse_x", inputMouseX);
|
||||||
|
_rb_define_module_function(module, "mouse_y", inputMouseY);
|
||||||
|
|
||||||
|
if (rgssVer >= 3)
|
||||||
|
{
|
||||||
|
VALUE symHash = rb_hash_new();
|
||||||
|
|
||||||
|
for (size_t i = 0; i < buttonCodesN; ++i)
|
||||||
|
{
|
||||||
|
ID sym = rb_intern(buttonCodes[i].str);
|
||||||
|
VALUE val = INT2FIX(buttonCodes[i].val);
|
||||||
|
|
||||||
|
/* In RGSS3 all Input::XYZ constants are equal to :XYZ symbols,
|
||||||
|
* to be compatible with the previous convention */
|
||||||
|
rb_const_set(module, sym, ID2SYM(sym));
|
||||||
|
rb_hash_aset(symHash, ID2SYM(sym), val);
|
||||||
|
}
|
||||||
|
|
||||||
|
rb_iv_set(module, "buttoncodes", symHash);
|
||||||
|
getRbData()->buttoncodeHash = symHash;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < buttonCodesN; ++i)
|
||||||
|
{
|
||||||
|
ID sym = rb_intern(buttonCodes[i].str);
|
||||||
|
VALUE val = INT2FIX(buttonCodes[i].val);
|
||||||
|
|
||||||
|
rb_const_set(module, sym, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
binding-legacy/meson.build
Normal file
37
binding-legacy/meson.build
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
error('Legacy bindings have not been completed yet.')
|
||||||
|
|
||||||
|
mri = meson.get_compiler('cpp').find_library('ruby')
|
||||||
|
binding_dependencies = [mri]
|
||||||
|
|
||||||
|
add_project_arguments('-DBINDING_LEGACY', language: 'cpp')
|
||||||
|
|
||||||
|
binding_headers = files(
|
||||||
|
'binding-util.h',
|
||||||
|
'binding-types.h',
|
||||||
|
'serializable-binding.h',
|
||||||
|
'disposable-binding.h',
|
||||||
|
'sceneelement-binding.h',
|
||||||
|
'viewportelement-binding.h',
|
||||||
|
'flashable-binding.h',
|
||||||
|
)
|
||||||
|
|
||||||
|
binding_source = files(
|
||||||
|
'binding-mri.cpp',
|
||||||
|
'binding-util.cpp',
|
||||||
|
'table-binding.cpp',
|
||||||
|
'etc-binding.cpp',
|
||||||
|
'bitmap-binding.cpp',
|
||||||
|
'font-binding.cpp',
|
||||||
|
'graphics-binding.cpp',
|
||||||
|
'input-binding.cpp',
|
||||||
|
'sprite-binding.cpp',
|
||||||
|
'viewport-binding.cpp',
|
||||||
|
'plane-binding.cpp',
|
||||||
|
'window-binding.cpp',
|
||||||
|
'tilemap-binding.cpp',
|
||||||
|
'audio-binding.cpp',
|
||||||
|
'module_rpg.cpp',
|
||||||
|
'filesystem-binding.cpp',
|
||||||
|
'windowvx-binding.cpp',
|
||||||
|
'tilemapvx-binding.cpp',
|
||||||
|
)
|
4
binding-legacy/module_rpg.cpp
Normal file
4
binding-legacy/module_rpg.cpp
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
# include "module_rpg1.rb.xxd"
|
||||||
|
# include "module_rpg2.rb.xxd"
|
||||||
|
# include "module_rpg3.rb.xxd"
|
2407
binding-legacy/module_rpg1.rb.xxd
Normal file
2407
binding-legacy/module_rpg1.rb.xxd
Normal file
File diff suppressed because it is too large
Load diff
1444
binding-legacy/module_rpg2.rb.xxd
Normal file
1444
binding-legacy/module_rpg2.rb.xxd
Normal file
File diff suppressed because it is too large
Load diff
1404
binding-legacy/module_rpg3.rb.xxd
Normal file
1404
binding-legacy/module_rpg3.rb.xxd
Normal file
File diff suppressed because it is too large
Load diff
77
binding-legacy/plane-binding.cpp
Normal file
77
binding-legacy/plane-binding.cpp
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
** plane-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "plane.h"
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
#include "viewportelement-binding.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "binding-types.h"
|
||||||
|
|
||||||
|
DEF_TYPE(Plane);
|
||||||
|
|
||||||
|
RB_METHOD(planeInitialize)
|
||||||
|
{
|
||||||
|
Plane *p = viewportElementInitialize<Plane>(argc, argv, self);
|
||||||
|
|
||||||
|
setPrivateData(self, p);
|
||||||
|
|
||||||
|
p->initDynAttribs();
|
||||||
|
|
||||||
|
wrapProperty(self, &p->getColor(), "color", ColorType);
|
||||||
|
wrapProperty(self, &p->getTone(), "tone", ToneType);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_PROP_OBJ_REF(Plane, Bitmap, Bitmap, "bitmap")
|
||||||
|
DEF_PROP_OBJ_VAL(Plane, Color, Color, "color")
|
||||||
|
DEF_PROP_OBJ_VAL(Plane, Tone, Tone, "tone")
|
||||||
|
|
||||||
|
DEF_PROP_I(Plane, OX)
|
||||||
|
DEF_PROP_I(Plane, OY)
|
||||||
|
DEF_PROP_I(Plane, Opacity)
|
||||||
|
DEF_PROP_I(Plane, BlendType)
|
||||||
|
|
||||||
|
DEF_PROP_F(Plane, ZoomX)
|
||||||
|
DEF_PROP_F(Plane, ZoomY)
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
planeBindingInit()
|
||||||
|
{
|
||||||
|
VALUE klass = rb_define_class("Plane", rb_cObject);
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&PlaneType>);
|
||||||
|
|
||||||
|
disposableBindingInit<Plane> (klass);
|
||||||
|
viewportElementBindingInit<Plane>(klass);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "initialize", planeInitialize);
|
||||||
|
|
||||||
|
INIT_PROP_BIND( Plane, Bitmap, "bitmap" );
|
||||||
|
INIT_PROP_BIND( Plane, OX, "ox" );
|
||||||
|
INIT_PROP_BIND( Plane, OY, "oy" );
|
||||||
|
INIT_PROP_BIND( Plane, ZoomX, "zoom_x" );
|
||||||
|
INIT_PROP_BIND( Plane, ZoomY, "zoom_y" );
|
||||||
|
INIT_PROP_BIND( Plane, Opacity, "opacity" );
|
||||||
|
INIT_PROP_BIND( Plane, BlendType, "blend_type" );
|
||||||
|
INIT_PROP_BIND( Plane, Color, "color" );
|
||||||
|
INIT_PROP_BIND( Plane, Tone, "tone" );
|
||||||
|
}
|
90
binding-legacy/sceneelement-binding.h
Normal file
90
binding-legacy/sceneelement-binding.h
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
** sceneelement-binding.h
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SCENEELEMENTBINDING_H
|
||||||
|
#define SCENEELEMENTBINDING_H
|
||||||
|
|
||||||
|
#include "scene.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
RB_METHOD(sceneElementGetZ)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
SceneElement *se = getPrivateData<C>(self);
|
||||||
|
|
||||||
|
int value = 0;
|
||||||
|
GUARD_EXC( value = se->getZ(); );
|
||||||
|
|
||||||
|
return rb_fix_new(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
RB_METHOD(sceneElementSetZ)
|
||||||
|
{
|
||||||
|
SceneElement *se = getPrivateData<C>(self);
|
||||||
|
|
||||||
|
int z;
|
||||||
|
rb_get_args(argc, argv, "i", &z RB_ARG_END);
|
||||||
|
|
||||||
|
GUARD_EXC( se->setZ(z); );
|
||||||
|
|
||||||
|
return rb_fix_new(z);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
RB_METHOD(sceneElementGetVisible)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
SceneElement *se = getPrivateData<C>(self);
|
||||||
|
|
||||||
|
bool value = false;
|
||||||
|
GUARD_EXC( value = se->getVisible(); );
|
||||||
|
|
||||||
|
return rb_bool_new(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
RB_METHOD(sceneElementSetVisible)
|
||||||
|
{
|
||||||
|
SceneElement *se = getPrivateData<C>(self);
|
||||||
|
|
||||||
|
bool visible;
|
||||||
|
rb_get_args(argc, argv, "b", &visible RB_ARG_END);
|
||||||
|
|
||||||
|
GUARD_EXC( se->setVisible(visible); );
|
||||||
|
|
||||||
|
return rb_bool_new(visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
void
|
||||||
|
sceneElementBindingInit(VALUE klass)
|
||||||
|
{
|
||||||
|
_rb_define_method(klass, "z", sceneElementGetZ<C>);
|
||||||
|
_rb_define_method(klass, "z=", sceneElementSetZ<C>);
|
||||||
|
_rb_define_method(klass, "visible", sceneElementGetVisible<C>);
|
||||||
|
_rb_define_method(klass, "visible=", sceneElementSetVisible<C>);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SCENEELEMENTBINDING_H
|
51
binding-legacy/serializable-binding.h
Normal file
51
binding-legacy/serializable-binding.h
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
** serializable-binding.h
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SERIALIZABLEBINDING_H
|
||||||
|
#define SERIALIZABLEBINDING_H
|
||||||
|
|
||||||
|
#include "serializable.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "exception.h"
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
static VALUE
|
||||||
|
serializableDump(int, VALUE *, VALUE self)
|
||||||
|
{
|
||||||
|
Serializable *s = getPrivateData<C>(self);
|
||||||
|
|
||||||
|
int dataSize = s->serialSize();
|
||||||
|
|
||||||
|
VALUE data = rb_str_new(0, dataSize);
|
||||||
|
|
||||||
|
GUARD_EXC( s->serialize(RSTRING_PTR(data)); );
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
void
|
||||||
|
serializableBindingInit(VALUE klass)
|
||||||
|
{
|
||||||
|
_rb_define_method(klass, "_dump", serializableDump<C>);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SERIALIZABLEBINDING_H
|
137
binding-legacy/sprite-binding.cpp
Normal file
137
binding-legacy/sprite-binding.cpp
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
/*
|
||||||
|
** sprite-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "sprite.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
#include "flashable-binding.h"
|
||||||
|
#include "sceneelement-binding.h"
|
||||||
|
#include "viewportelement-binding.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "binding-types.h"
|
||||||
|
|
||||||
|
DEF_TYPE(Sprite);
|
||||||
|
|
||||||
|
RB_METHOD(spriteInitialize)
|
||||||
|
{
|
||||||
|
Sprite *s = viewportElementInitialize<Sprite>(argc, argv, self);
|
||||||
|
|
||||||
|
setPrivateData(self, s);
|
||||||
|
|
||||||
|
/* Wrap property objects */
|
||||||
|
s->initDynAttribs();
|
||||||
|
|
||||||
|
wrapProperty(self, &s->getSrcRect(), "src_rect", RectType);
|
||||||
|
wrapProperty(self, &s->getColor(), "color", ColorType);
|
||||||
|
wrapProperty(self, &s->getTone(), "tone", ToneType);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_PROP_OBJ_REF(Sprite, Bitmap, Bitmap, "bitmap")
|
||||||
|
DEF_PROP_OBJ_VAL(Sprite, Rect, SrcRect, "src_rect")
|
||||||
|
DEF_PROP_OBJ_VAL(Sprite, Color, Color, "color")
|
||||||
|
DEF_PROP_OBJ_VAL(Sprite, Tone, Tone, "tone")
|
||||||
|
|
||||||
|
DEF_PROP_I(Sprite, X)
|
||||||
|
DEF_PROP_I(Sprite, Y)
|
||||||
|
DEF_PROP_I(Sprite, OX)
|
||||||
|
DEF_PROP_I(Sprite, OY)
|
||||||
|
DEF_PROP_I(Sprite, BushDepth)
|
||||||
|
DEF_PROP_I(Sprite, BushOpacity)
|
||||||
|
DEF_PROP_I(Sprite, Opacity)
|
||||||
|
DEF_PROP_I(Sprite, BlendType)
|
||||||
|
DEF_PROP_I(Sprite, WaveAmp)
|
||||||
|
DEF_PROP_I(Sprite, WaveLength)
|
||||||
|
DEF_PROP_I(Sprite, WaveSpeed)
|
||||||
|
|
||||||
|
DEF_PROP_F(Sprite, ZoomX)
|
||||||
|
DEF_PROP_F(Sprite, ZoomY)
|
||||||
|
DEF_PROP_F(Sprite, Angle)
|
||||||
|
DEF_PROP_F(Sprite, WavePhase)
|
||||||
|
|
||||||
|
DEF_PROP_B(Sprite, Mirror)
|
||||||
|
|
||||||
|
RB_METHOD(spriteWidth)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
Sprite *s = getPrivateData<Sprite>(self);
|
||||||
|
|
||||||
|
int value = 0;
|
||||||
|
GUARD_EXC( value = s->getWidth(); )
|
||||||
|
|
||||||
|
return rb_fix_new(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(spriteHeight)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
Sprite *s = getPrivateData<Sprite>(self);
|
||||||
|
|
||||||
|
int value = 0;
|
||||||
|
GUARD_EXC( value = s->getHeight(); )
|
||||||
|
|
||||||
|
return rb_fix_new(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
spriteBindingInit()
|
||||||
|
{
|
||||||
|
VALUE klass = rb_define_class("Sprite", rb_cObject);
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&SpriteType>);
|
||||||
|
|
||||||
|
disposableBindingInit <Sprite>(klass);
|
||||||
|
flashableBindingInit <Sprite>(klass);
|
||||||
|
viewportElementBindingInit<Sprite>(klass);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "initialize", spriteInitialize);
|
||||||
|
|
||||||
|
INIT_PROP_BIND( Sprite, Bitmap, "bitmap" );
|
||||||
|
INIT_PROP_BIND( Sprite, SrcRect, "src_rect" );
|
||||||
|
INIT_PROP_BIND( Sprite, X, "x" );
|
||||||
|
INIT_PROP_BIND( Sprite, Y, "y" );
|
||||||
|
INIT_PROP_BIND( Sprite, OX, "ox" );
|
||||||
|
INIT_PROP_BIND( Sprite, OY, "oy" );
|
||||||
|
INIT_PROP_BIND( Sprite, ZoomX, "zoom_x" );
|
||||||
|
INIT_PROP_BIND( Sprite, ZoomY, "zoom_y" );
|
||||||
|
INIT_PROP_BIND( Sprite, Angle, "angle" );
|
||||||
|
INIT_PROP_BIND( Sprite, Mirror, "mirror" );
|
||||||
|
INIT_PROP_BIND( Sprite, BushDepth, "bush_depth" );
|
||||||
|
INIT_PROP_BIND( Sprite, Opacity, "opacity" );
|
||||||
|
INIT_PROP_BIND( Sprite, BlendType, "blend_type" );
|
||||||
|
INIT_PROP_BIND( Sprite, Color, "color" );
|
||||||
|
INIT_PROP_BIND( Sprite, Tone, "tone" );
|
||||||
|
|
||||||
|
if (rgssVer >= 2)
|
||||||
|
{
|
||||||
|
_rb_define_method(klass, "width", spriteWidth);
|
||||||
|
_rb_define_method(klass, "height", spriteHeight);
|
||||||
|
|
||||||
|
INIT_PROP_BIND( Sprite, BushOpacity, "bush_opacity" );
|
||||||
|
|
||||||
|
INIT_PROP_BIND( Sprite, WaveAmp, "wave_amp" );
|
||||||
|
INIT_PROP_BIND( Sprite, WaveLength, "wave_length" );
|
||||||
|
INIT_PROP_BIND( Sprite, WaveSpeed, "wave_speed" );
|
||||||
|
INIT_PROP_BIND( Sprite, WavePhase, "wave_phase" );
|
||||||
|
}
|
||||||
|
}
|
180
binding-legacy/table-binding.cpp
Normal file
180
binding-legacy/table-binding.cpp
Normal file
|
@ -0,0 +1,180 @@
|
||||||
|
/*
|
||||||
|
** table-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include "table.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "serializable-binding.h"
|
||||||
|
|
||||||
|
static int num2TableSize(VALUE v)
|
||||||
|
{
|
||||||
|
int i = NUM2INT(v);
|
||||||
|
return std::max(0, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void parseArgsTableSizes(int argc, VALUE *argv, int *x, int *y, int *z)
|
||||||
|
{
|
||||||
|
*y = *z = 1;
|
||||||
|
|
||||||
|
switch (argc)
|
||||||
|
{
|
||||||
|
case 3:
|
||||||
|
*z = num2TableSize(argv[2]);
|
||||||
|
/* fall through */
|
||||||
|
case 2:
|
||||||
|
*y = num2TableSize(argv[1]);
|
||||||
|
/* fall through */
|
||||||
|
case 1:
|
||||||
|
*x = num2TableSize(argv[0]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
rb_error_arity(argc, 1, 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_TYPE(Table);
|
||||||
|
|
||||||
|
RB_METHOD(tableInitialize)
|
||||||
|
{
|
||||||
|
int x, y, z;
|
||||||
|
|
||||||
|
parseArgsTableSizes(argc, argv, &x, &y, &z);
|
||||||
|
|
||||||
|
Table *t = new Table(x, y, z);
|
||||||
|
|
||||||
|
setPrivateData(self, t);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(tableResize)
|
||||||
|
{
|
||||||
|
Table *t = getPrivateData<Table>(self);
|
||||||
|
|
||||||
|
int x, y, z;
|
||||||
|
parseArgsTableSizes(argc, argv, &x, &y, &z);
|
||||||
|
|
||||||
|
t->resize(x, y, z);
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TABLE_SIZE(d, D) \
|
||||||
|
RB_METHOD(table##D##Size) \
|
||||||
|
{ \
|
||||||
|
RB_UNUSED_PARAM \
|
||||||
|
Table *t = getPrivateData<Table>(self); \
|
||||||
|
return INT2NUM(t->d##Size()); \
|
||||||
|
}
|
||||||
|
|
||||||
|
TABLE_SIZE(x, X)
|
||||||
|
TABLE_SIZE(y, Y)
|
||||||
|
TABLE_SIZE(z, Z)
|
||||||
|
|
||||||
|
RB_METHOD(tableGetAt)
|
||||||
|
{
|
||||||
|
Table *t = getPrivateData<Table>(self);
|
||||||
|
|
||||||
|
int x, y, z;
|
||||||
|
x = y = z = 0;
|
||||||
|
|
||||||
|
x = NUM2INT(argv[0]);
|
||||||
|
if (argc > 1)
|
||||||
|
y = NUM2INT(argv[1]);
|
||||||
|
if (argc > 2)
|
||||||
|
z = NUM2INT(argv[2]);
|
||||||
|
|
||||||
|
if (argc > 3)
|
||||||
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
||||||
|
|
||||||
|
if (x < 0 || x >= t->xSize()
|
||||||
|
|| y < 0 || y >= t->ySize()
|
||||||
|
|| z < 0 || z >= t->zSize())
|
||||||
|
{
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
short result = t->get(x, y, z);
|
||||||
|
|
||||||
|
return INT2FIX(result); /* short always fits in a Fixnum */
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(tableSetAt)
|
||||||
|
{
|
||||||
|
Table *t = getPrivateData<Table>(self);
|
||||||
|
|
||||||
|
int x, y, z, value;
|
||||||
|
x = y = z = 0;
|
||||||
|
|
||||||
|
if (argc < 2)
|
||||||
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
||||||
|
|
||||||
|
switch (argc)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case 2 :
|
||||||
|
x = NUM2INT(argv[0]);
|
||||||
|
value = NUM2INT(argv[1]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 3 :
|
||||||
|
x = NUM2INT(argv[0]);
|
||||||
|
y = NUM2INT(argv[1]);
|
||||||
|
value = NUM2INT(argv[2]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 4 :
|
||||||
|
x = NUM2INT(argv[0]);
|
||||||
|
y = NUM2INT(argv[1]);
|
||||||
|
z = NUM2INT(argv[2]);
|
||||||
|
value = NUM2INT(argv[3]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
t->set(value, x, y, z);
|
||||||
|
|
||||||
|
return argv[argc - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
MARSH_LOAD_FUN(Table)
|
||||||
|
INITCOPY_FUN(Table)
|
||||||
|
|
||||||
|
void
|
||||||
|
tableBindingInit()
|
||||||
|
{
|
||||||
|
VALUE klass = rb_define_class("Table", rb_cObject);
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&TableType>);
|
||||||
|
|
||||||
|
serializableBindingInit<Table>(klass);
|
||||||
|
|
||||||
|
rb_define_class_method(klass, "_load", TableLoad);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "initialize", tableInitialize);
|
||||||
|
_rb_define_method(klass, "initialize_copy", TableInitializeCopy);
|
||||||
|
_rb_define_method(klass, "resize", tableResize);
|
||||||
|
_rb_define_method(klass, "xsize", tableXSize);
|
||||||
|
_rb_define_method(klass, "ysize", tableYSize);
|
||||||
|
_rb_define_method(klass, "zsize", tableZSize);
|
||||||
|
_rb_define_method(klass, "[]", tableGetAt);
|
||||||
|
_rb_define_method(klass, "[]=", tableSetAt);
|
||||||
|
|
||||||
|
}
|
170
binding-legacy/tilemap-binding.cpp
Normal file
170
binding-legacy/tilemap-binding.cpp
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
/*
|
||||||
|
** tilemap-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tilemap.h"
|
||||||
|
#include "viewport.h"
|
||||||
|
#include "bitmap.h"
|
||||||
|
#include "table.h"
|
||||||
|
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "binding-types.h"
|
||||||
|
|
||||||
|
DEF_TYPE_CUSTOMFREE(TilemapAutotiles, RUBY_TYPED_NEVER_FREE);
|
||||||
|
|
||||||
|
RB_METHOD(tilemapAutotilesSet)
|
||||||
|
{
|
||||||
|
Tilemap::Autotiles *a = getPrivateData<Tilemap::Autotiles>(self);
|
||||||
|
|
||||||
|
int i;
|
||||||
|
VALUE bitmapObj;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "io", &i, &bitmapObj RB_ARG_END);
|
||||||
|
|
||||||
|
Bitmap *bitmap = getPrivateDataCheck<Bitmap>(bitmapObj, BitmapType);
|
||||||
|
|
||||||
|
a->set(i, bitmap);
|
||||||
|
|
||||||
|
VALUE ary = rb_iv_get(self, "array");
|
||||||
|
rb_ary_store(ary, i, bitmapObj);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(tilemapAutotilesGet)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
rb_get_args (argc, argv, "i", &i RB_ARG_END);
|
||||||
|
|
||||||
|
if (i < 0 || i > 6)
|
||||||
|
return Qnil;
|
||||||
|
|
||||||
|
VALUE ary = rb_iv_get(self, "array");
|
||||||
|
|
||||||
|
return rb_ary_entry(ary, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_TYPE(Tilemap);
|
||||||
|
|
||||||
|
RB_METHOD(tilemapInitialize)
|
||||||
|
{
|
||||||
|
Tilemap *t;
|
||||||
|
|
||||||
|
/* Get parameters */
|
||||||
|
VALUE viewportObj = Qnil;
|
||||||
|
Viewport *viewport = 0;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END);
|
||||||
|
|
||||||
|
if (!NIL_P(viewportObj))
|
||||||
|
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
|
||||||
|
|
||||||
|
/* Construct object */
|
||||||
|
t = new Tilemap(viewport);
|
||||||
|
|
||||||
|
setPrivateData(self, t);
|
||||||
|
|
||||||
|
rb_iv_set(self, "viewport", viewportObj);
|
||||||
|
|
||||||
|
wrapProperty(self, &t->getAutotiles(), "autotiles", TilemapAutotilesType);
|
||||||
|
|
||||||
|
VALUE autotilesObj = rb_iv_get(self, "autotiles");
|
||||||
|
|
||||||
|
VALUE ary = rb_ary_new2(7);
|
||||||
|
for (int i = 0; i < 7; ++i)
|
||||||
|
rb_ary_push(ary, Qnil);
|
||||||
|
|
||||||
|
rb_iv_set(autotilesObj, "array", ary);
|
||||||
|
|
||||||
|
/* Circular reference so both objects are always
|
||||||
|
* alive at the same time */
|
||||||
|
rb_iv_set(autotilesObj, "tilemap", self);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(tilemapGetAutotiles)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
checkDisposed<Tilemap>(self);
|
||||||
|
|
||||||
|
return rb_iv_get(self, "autotiles");
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(tilemapUpdate)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
Tilemap *t = getPrivateData<Tilemap>(self);
|
||||||
|
|
||||||
|
t->update();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(tilemapGetViewport)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
checkDisposed<Tilemap>(self);
|
||||||
|
|
||||||
|
return rb_iv_get(self, "viewport");
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_PROP_OBJ_REF(Tilemap, Bitmap, Tileset, "tileset")
|
||||||
|
DEF_PROP_OBJ_REF(Tilemap, Table, MapData, "map_data")
|
||||||
|
DEF_PROP_OBJ_REF(Tilemap, Table, FlashData, "flash_data")
|
||||||
|
DEF_PROP_OBJ_REF(Tilemap, Table, Priorities, "priorities")
|
||||||
|
|
||||||
|
DEF_PROP_B(Tilemap, Visible)
|
||||||
|
|
||||||
|
DEF_PROP_I(Tilemap, OX)
|
||||||
|
DEF_PROP_I(Tilemap, OY)
|
||||||
|
|
||||||
|
void
|
||||||
|
tilemapBindingInit()
|
||||||
|
{
|
||||||
|
VALUE klass = rb_define_class("TilemapAutotiles", rb_cObject);
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&TilemapAutotilesType>);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "[]=", tilemapAutotilesSet);
|
||||||
|
_rb_define_method(klass, "[]", tilemapAutotilesGet);
|
||||||
|
|
||||||
|
klass = rb_define_class("Tilemap", rb_cObject);
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&TilemapType>);
|
||||||
|
|
||||||
|
disposableBindingInit<Tilemap>(klass);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "initialize", tilemapInitialize);
|
||||||
|
_rb_define_method(klass, "autotiles", tilemapGetAutotiles);
|
||||||
|
_rb_define_method(klass, "update", tilemapUpdate);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "viewport", tilemapGetViewport);
|
||||||
|
|
||||||
|
INIT_PROP_BIND( Tilemap, Tileset, "tileset" );
|
||||||
|
INIT_PROP_BIND( Tilemap, MapData, "map_data" );
|
||||||
|
INIT_PROP_BIND( Tilemap, FlashData, "flash_data" );
|
||||||
|
INIT_PROP_BIND( Tilemap, Priorities, "priorities" );
|
||||||
|
INIT_PROP_BIND( Tilemap, Visible, "visible" );
|
||||||
|
INIT_PROP_BIND( Tilemap, OX, "ox" );
|
||||||
|
INIT_PROP_BIND( Tilemap, OY, "oy" );
|
||||||
|
}
|
169
binding-legacy/tilemapvx-binding.cpp
Normal file
169
binding-legacy/tilemapvx-binding.cpp
Normal file
|
@ -0,0 +1,169 @@
|
||||||
|
/*
|
||||||
|
** tilemapvx-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2014 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tilemapvx.h"
|
||||||
|
#include "viewport.h"
|
||||||
|
#include "bitmap.h"
|
||||||
|
#include "table.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
|
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "binding-types.h"
|
||||||
|
|
||||||
|
DEF_TYPE_CUSTOMNAME(TilemapVX, "Tilemap");
|
||||||
|
|
||||||
|
DEF_TYPE_CUSTOMFREE(BitmapArray, RUBY_TYPED_NEVER_FREE);
|
||||||
|
|
||||||
|
RB_METHOD(tilemapVXInitialize)
|
||||||
|
{
|
||||||
|
TilemapVX *t;
|
||||||
|
|
||||||
|
/* Get parameters */
|
||||||
|
VALUE viewportObj = Qnil;
|
||||||
|
Viewport *viewport = 0;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END);
|
||||||
|
|
||||||
|
if (!NIL_P(viewportObj))
|
||||||
|
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
|
||||||
|
|
||||||
|
/* Construct object */
|
||||||
|
t = new TilemapVX(viewport);
|
||||||
|
|
||||||
|
setPrivateData(self, t);
|
||||||
|
|
||||||
|
rb_iv_set(self, "viewport", viewportObj);
|
||||||
|
|
||||||
|
wrapProperty(self, &t->getBitmapArray(), "bitmap_array", BitmapArrayType,
|
||||||
|
rb_const_get(rb_cObject, rb_intern("Tilemap")));
|
||||||
|
|
||||||
|
VALUE autotilesObj = rb_iv_get(self, "bitmap_array");
|
||||||
|
|
||||||
|
VALUE ary = rb_ary_new2(9);
|
||||||
|
for (int i = 0; i < 9; ++i)
|
||||||
|
rb_ary_push(ary, Qnil);
|
||||||
|
|
||||||
|
rb_iv_set(autotilesObj, "array", ary);
|
||||||
|
|
||||||
|
/* Circular reference so both objects are always
|
||||||
|
* alive at the same time */
|
||||||
|
rb_iv_set(autotilesObj, "tilemap", self);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(tilemapVXGetBitmapArray)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
checkDisposed<TilemapVX>(self);
|
||||||
|
|
||||||
|
return rb_iv_get(self, "bitmap_array");
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(tilemapVXUpdate)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
TilemapVX *t = getPrivateData<TilemapVX>(self);
|
||||||
|
|
||||||
|
t->update();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_PROP_OBJ_REF(TilemapVX, Viewport, Viewport, "viewport")
|
||||||
|
DEF_PROP_OBJ_REF(TilemapVX, Table, MapData, "map_data")
|
||||||
|
DEF_PROP_OBJ_REF(TilemapVX, Table, FlashData, "flash_data")
|
||||||
|
DEF_PROP_OBJ_REF(TilemapVX, Table, Flags, "flags")
|
||||||
|
|
||||||
|
DEF_PROP_B(TilemapVX, Visible)
|
||||||
|
|
||||||
|
DEF_PROP_I(TilemapVX, OX)
|
||||||
|
DEF_PROP_I(TilemapVX, OY)
|
||||||
|
|
||||||
|
RB_METHOD(tilemapVXBitmapsSet)
|
||||||
|
{
|
||||||
|
TilemapVX::BitmapArray *a = getPrivateData<TilemapVX::BitmapArray>(self);
|
||||||
|
|
||||||
|
int i;
|
||||||
|
VALUE bitmapObj;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "io", &i, &bitmapObj RB_ARG_END);
|
||||||
|
|
||||||
|
Bitmap *bitmap = getPrivateDataCheck<Bitmap>(bitmapObj, BitmapType);
|
||||||
|
|
||||||
|
a->set(i, bitmap);
|
||||||
|
|
||||||
|
VALUE ary = rb_iv_get(self, "array");
|
||||||
|
rb_ary_store(ary, i, bitmapObj);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(tilemapVXBitmapsGet)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
rb_get_args (argc, argv, "i", &i RB_ARG_END);
|
||||||
|
|
||||||
|
if (i < 0 || i > 8)
|
||||||
|
return Qnil;
|
||||||
|
|
||||||
|
VALUE ary = rb_iv_get(self, "array");
|
||||||
|
|
||||||
|
return rb_ary_entry(ary, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
tilemapVXBindingInit()
|
||||||
|
{
|
||||||
|
VALUE klass = rb_define_class("Tilemap", rb_cObject);
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&TilemapVXType>);
|
||||||
|
|
||||||
|
disposableBindingInit<TilemapVX>(klass);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "initialize", tilemapVXInitialize);
|
||||||
|
_rb_define_method(klass, "bitmaps", tilemapVXGetBitmapArray);
|
||||||
|
_rb_define_method(klass, "update", tilemapVXUpdate);
|
||||||
|
|
||||||
|
INIT_PROP_BIND( TilemapVX, Viewport, "viewport" );
|
||||||
|
INIT_PROP_BIND( TilemapVX, MapData, "map_data" );
|
||||||
|
INIT_PROP_BIND( TilemapVX, FlashData, "flash_data" );
|
||||||
|
INIT_PROP_BIND( TilemapVX, Visible, "visible" );
|
||||||
|
INIT_PROP_BIND( TilemapVX, OX, "ox" );
|
||||||
|
INIT_PROP_BIND( TilemapVX, OY, "oy" );
|
||||||
|
|
||||||
|
if (rgssVer == 3)
|
||||||
|
{
|
||||||
|
INIT_PROP_BIND( TilemapVX, Flags, "flags" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
INIT_PROP_BIND( TilemapVX, Flags, "passages" );
|
||||||
|
}
|
||||||
|
|
||||||
|
klass = rb_define_class_under(klass, "BitmapArray", rb_cObject);
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&BitmapArrayType>);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "[]=", tilemapVXBitmapsSet);
|
||||||
|
_rb_define_method(klass, "[]", tilemapVXBitmapsGet);
|
||||||
|
}
|
105
binding-legacy/viewport-binding.cpp
Normal file
105
binding-legacy/viewport-binding.cpp
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
** viewport-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "viewport.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
#include "flashable-binding.h"
|
||||||
|
#include "sceneelement-binding.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "binding-types.h"
|
||||||
|
|
||||||
|
DEF_TYPE(Viewport);
|
||||||
|
|
||||||
|
RB_METHOD(viewportInitialize)
|
||||||
|
{
|
||||||
|
Viewport *v;
|
||||||
|
|
||||||
|
if (argc == 0 && rgssVer >= 3)
|
||||||
|
{
|
||||||
|
v = new Viewport();
|
||||||
|
}
|
||||||
|
else if (argc == 1)
|
||||||
|
{
|
||||||
|
/* The rect arg is only used to init the viewport,
|
||||||
|
* and does NOT replace its 'rect' property */
|
||||||
|
VALUE rectObj;
|
||||||
|
Rect *rect;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "o", &rectObj RB_ARG_END);
|
||||||
|
|
||||||
|
rect = getPrivateDataCheck<Rect>(rectObj, RectType);
|
||||||
|
|
||||||
|
v = new Viewport(rect);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int x, y, width, height;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END);
|
||||||
|
|
||||||
|
v = new Viewport(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
setPrivateData(self, v);
|
||||||
|
|
||||||
|
/* Wrap property objects */
|
||||||
|
v->initDynAttribs();
|
||||||
|
|
||||||
|
wrapProperty(self, &v->getRect(), "rect", RectType);
|
||||||
|
wrapProperty(self, &v->getColor(), "color", ColorType);
|
||||||
|
wrapProperty(self, &v->getTone(), "tone", ToneType);
|
||||||
|
|
||||||
|
/* 'elements' holds all SceneElements that become children
|
||||||
|
* of this viewport, so we can dispose them when the viewport
|
||||||
|
* is disposed */
|
||||||
|
rb_iv_set(self, "elements", rb_ary_new());
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_PROP_OBJ_VAL(Viewport, Rect, Rect, "rect")
|
||||||
|
DEF_PROP_OBJ_VAL(Viewport, Color, Color, "color")
|
||||||
|
DEF_PROP_OBJ_VAL(Viewport, Tone, Tone, "tone")
|
||||||
|
|
||||||
|
DEF_PROP_I(Viewport, OX)
|
||||||
|
DEF_PROP_I(Viewport, OY)
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
viewportBindingInit()
|
||||||
|
{
|
||||||
|
VALUE klass = rb_define_class("Viewport", rb_cObject);
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&ViewportType>);
|
||||||
|
|
||||||
|
disposableBindingInit <Viewport>(klass);
|
||||||
|
flashableBindingInit <Viewport>(klass);
|
||||||
|
sceneElementBindingInit<Viewport>(klass);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "initialize", viewportInitialize);
|
||||||
|
|
||||||
|
INIT_PROP_BIND( Viewport, Rect, "rect" );
|
||||||
|
INIT_PROP_BIND( Viewport, OX, "ox" );
|
||||||
|
INIT_PROP_BIND( Viewport, OY, "oy" );
|
||||||
|
INIT_PROP_BIND( Viewport, Color, "color" );
|
||||||
|
INIT_PROP_BIND( Viewport, Tone, "tone" );
|
||||||
|
}
|
||||||
|
|
106
binding-legacy/viewportelement-binding.h
Normal file
106
binding-legacy/viewportelement-binding.h
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
/*
|
||||||
|
** viewportelement-binding.h
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef VIEWPORTELEMENTBINDING_H
|
||||||
|
#define VIEWPORTELEMENTBINDING_H
|
||||||
|
|
||||||
|
#include "viewport.h"
|
||||||
|
#include "sharedstate.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "binding-types.h"
|
||||||
|
|
||||||
|
#include "sceneelement-binding.h"
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
RB_METHOD(viewportElementGetViewport)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
checkDisposed<C>(self);
|
||||||
|
|
||||||
|
return rb_iv_get(self, "viewport");
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
RB_METHOD(viewportElementSetViewport)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
ViewportElement *ve = getPrivateData<C>(self);
|
||||||
|
|
||||||
|
VALUE viewportObj = Qnil;
|
||||||
|
Viewport *viewport = 0;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "o", &viewportObj RB_ARG_END);
|
||||||
|
|
||||||
|
if (!NIL_P(viewportObj))
|
||||||
|
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
|
||||||
|
|
||||||
|
GUARD_EXC( ve->setViewport(viewport); );
|
||||||
|
|
||||||
|
rb_iv_set(self, "viewport", viewportObj);
|
||||||
|
|
||||||
|
return viewportObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
static C *
|
||||||
|
viewportElementInitialize(int argc, VALUE *argv, VALUE self)
|
||||||
|
{
|
||||||
|
/* Get parameters */
|
||||||
|
VALUE viewportObj = Qnil;
|
||||||
|
Viewport *viewport = 0;
|
||||||
|
|
||||||
|
rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END);
|
||||||
|
|
||||||
|
if (!NIL_P(viewportObj))
|
||||||
|
{
|
||||||
|
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
|
||||||
|
|
||||||
|
if (rgssVer == 1)
|
||||||
|
disposableAddChild(viewportObj, self);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Construct object */
|
||||||
|
C *ve = new C(viewport);
|
||||||
|
|
||||||
|
/* Set property objects */
|
||||||
|
rb_iv_set(self, "viewport", viewportObj);
|
||||||
|
|
||||||
|
return ve;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
void
|
||||||
|
viewportElementBindingInit(VALUE klass)
|
||||||
|
{
|
||||||
|
sceneElementBindingInit<C>(klass);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "viewport", viewportElementGetViewport<C>);
|
||||||
|
|
||||||
|
if (rgssVer >= 2)
|
||||||
|
{
|
||||||
|
_rb_define_method(klass, "viewport=", viewportElementSetViewport<C>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // VIEWPORTELEMENTBINDING_H
|
99
binding-legacy/window-binding.cpp
Normal file
99
binding-legacy/window-binding.cpp
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
/*
|
||||||
|
** window-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "window.h"
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
#include "viewportelement-binding.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
|
||||||
|
DEF_TYPE(Window);
|
||||||
|
|
||||||
|
RB_METHOD(windowInitialize)
|
||||||
|
{
|
||||||
|
Window *w = viewportElementInitialize<Window>(argc, argv, self);
|
||||||
|
|
||||||
|
setPrivateData(self, w);
|
||||||
|
|
||||||
|
w->initDynAttribs();
|
||||||
|
|
||||||
|
wrapProperty(self, &w->getCursorRect(), "cursor_rect", RectType);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(windowUpdate)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
Window *w = getPrivateData<Window>(self);
|
||||||
|
|
||||||
|
w->update();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_PROP_OBJ_REF(Window, Bitmap, Windowskin, "windowskin")
|
||||||
|
DEF_PROP_OBJ_REF(Window, Bitmap, Contents, "contents")
|
||||||
|
DEF_PROP_OBJ_VAL(Window, Rect, CursorRect, "cursor_rect")
|
||||||
|
|
||||||
|
DEF_PROP_B(Window, Stretch)
|
||||||
|
DEF_PROP_B(Window, Active)
|
||||||
|
DEF_PROP_B(Window, Pause)
|
||||||
|
|
||||||
|
DEF_PROP_I(Window, X)
|
||||||
|
DEF_PROP_I(Window, Y)
|
||||||
|
DEF_PROP_I(Window, Width)
|
||||||
|
DEF_PROP_I(Window, Height)
|
||||||
|
DEF_PROP_I(Window, OX)
|
||||||
|
DEF_PROP_I(Window, OY)
|
||||||
|
DEF_PROP_I(Window, Opacity)
|
||||||
|
DEF_PROP_I(Window, BackOpacity)
|
||||||
|
DEF_PROP_I(Window, ContentsOpacity)
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
windowBindingInit()
|
||||||
|
{
|
||||||
|
VALUE klass = rb_define_class("Window", rb_cObject);
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&WindowType>);
|
||||||
|
|
||||||
|
disposableBindingInit <Window>(klass);
|
||||||
|
viewportElementBindingInit<Window>(klass);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "initialize", windowInitialize);
|
||||||
|
_rb_define_method(klass, "update", windowUpdate);
|
||||||
|
|
||||||
|
INIT_PROP_BIND( Window, Windowskin, "windowskin" );
|
||||||
|
INIT_PROP_BIND( Window, Contents, "contents" );
|
||||||
|
INIT_PROP_BIND( Window, Stretch, "stretch" );
|
||||||
|
INIT_PROP_BIND( Window, CursorRect, "cursor_rect" );
|
||||||
|
INIT_PROP_BIND( Window, Active, "active" );
|
||||||
|
INIT_PROP_BIND( Window, Pause, "pause" );
|
||||||
|
INIT_PROP_BIND( Window, X, "x" );
|
||||||
|
INIT_PROP_BIND( Window, Y, "y" );
|
||||||
|
INIT_PROP_BIND( Window, Width, "width" );
|
||||||
|
INIT_PROP_BIND( Window, Height, "height" );
|
||||||
|
INIT_PROP_BIND( Window, OX, "ox" );
|
||||||
|
INIT_PROP_BIND( Window, OY, "oy" );
|
||||||
|
INIT_PROP_BIND( Window, Opacity, "opacity" );
|
||||||
|
INIT_PROP_BIND( Window, BackOpacity, "back_opacity" );
|
||||||
|
INIT_PROP_BIND( Window, ContentsOpacity, "contents_opacity" );
|
||||||
|
}
|
172
binding-legacy/windowvx-binding.cpp
Normal file
172
binding-legacy/windowvx-binding.cpp
Normal file
|
@ -0,0 +1,172 @@
|
||||||
|
/*
|
||||||
|
** window-binding.cpp
|
||||||
|
**
|
||||||
|
** This file is part of mkxp.
|
||||||
|
**
|
||||||
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
||||||
|
**
|
||||||
|
** mkxp is free software: you can redistribute it and/or modify
|
||||||
|
** it under the terms of the GNU General Public License as published by
|
||||||
|
** the Free Software Foundation, either version 2 of the License, or
|
||||||
|
** (at your option) any later version.
|
||||||
|
**
|
||||||
|
** mkxp is distributed in the hope that it will be useful,
|
||||||
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
** GNU General Public License for more details.
|
||||||
|
**
|
||||||
|
** You should have received a copy of the GNU General Public License
|
||||||
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "windowvx.h"
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
#include "viewportelement-binding.h"
|
||||||
|
#include "binding-util.h"
|
||||||
|
|
||||||
|
#include "bitmap.h"
|
||||||
|
|
||||||
|
DEF_TYPE_CUSTOMNAME(WindowVX, "Window");
|
||||||
|
|
||||||
|
void bitmapInitProps(Bitmap *b, VALUE self);
|
||||||
|
|
||||||
|
RB_METHOD(windowVXInitialize)
|
||||||
|
{
|
||||||
|
WindowVX *w;
|
||||||
|
|
||||||
|
if (rgssVer >= 3)
|
||||||
|
{
|
||||||
|
int x, y, width, height;
|
||||||
|
x = y = width = height = 0;
|
||||||
|
|
||||||
|
if (argc == 4)
|
||||||
|
rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END);
|
||||||
|
|
||||||
|
w = new WindowVX(x, y, width, height);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
w = viewportElementInitialize<WindowVX>(argc, argv, self);
|
||||||
|
}
|
||||||
|
|
||||||
|
setPrivateData(self, w);
|
||||||
|
|
||||||
|
w->initDynAttribs();
|
||||||
|
|
||||||
|
wrapProperty(self, &w->getCursorRect(), "cursor_rect", RectType);
|
||||||
|
|
||||||
|
if (rgssVer >= 3)
|
||||||
|
wrapProperty(self, &w->getTone(), "tone", ToneType);
|
||||||
|
|
||||||
|
Bitmap *contents = new Bitmap(1, 1);
|
||||||
|
VALUE contentsObj = wrapObject(contents, BitmapType);
|
||||||
|
bitmapInitProps(contents, contentsObj);
|
||||||
|
rb_iv_set(self, "contents", contentsObj);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(windowVXUpdate)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
WindowVX *w = getPrivateData<WindowVX>(self);
|
||||||
|
|
||||||
|
w->update();
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(windowVXMove)
|
||||||
|
{
|
||||||
|
WindowVX *w = getPrivateData<WindowVX>(self);
|
||||||
|
|
||||||
|
int x, y, width, height;
|
||||||
|
rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END);
|
||||||
|
|
||||||
|
w->move(x, y, width, height);
|
||||||
|
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(windowVXIsOpen)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
WindowVX *w = getPrivateData<WindowVX>(self);
|
||||||
|
|
||||||
|
return rb_bool_new(w->isOpen());
|
||||||
|
}
|
||||||
|
|
||||||
|
RB_METHOD(windowVXIsClosed)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
WindowVX *w = getPrivateData<WindowVX>(self);
|
||||||
|
|
||||||
|
return rb_bool_new(w->isClosed());
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_PROP_OBJ_REF(WindowVX, Bitmap, Windowskin, "windowskin")
|
||||||
|
DEF_PROP_OBJ_REF(WindowVX, Bitmap, Contents, "contents")
|
||||||
|
|
||||||
|
DEF_PROP_OBJ_VAL(WindowVX, Rect, CursorRect, "cursor_rect")
|
||||||
|
DEF_PROP_OBJ_VAL(WindowVX, Tone, Tone, "tone")
|
||||||
|
|
||||||
|
DEF_PROP_I(WindowVX, X)
|
||||||
|
DEF_PROP_I(WindowVX, Y)
|
||||||
|
DEF_PROP_I(WindowVX, OX)
|
||||||
|
DEF_PROP_I(WindowVX, OY)
|
||||||
|
DEF_PROP_I(WindowVX, Width)
|
||||||
|
DEF_PROP_I(WindowVX, Height)
|
||||||
|
DEF_PROP_I(WindowVX, Padding)
|
||||||
|
DEF_PROP_I(WindowVX, PaddingBottom)
|
||||||
|
DEF_PROP_I(WindowVX, Opacity)
|
||||||
|
DEF_PROP_I(WindowVX, BackOpacity)
|
||||||
|
DEF_PROP_I(WindowVX, ContentsOpacity)
|
||||||
|
DEF_PROP_I(WindowVX, Openness)
|
||||||
|
|
||||||
|
DEF_PROP_B(WindowVX, Active)
|
||||||
|
DEF_PROP_B(WindowVX, ArrowsVisible)
|
||||||
|
DEF_PROP_B(WindowVX, Pause)
|
||||||
|
|
||||||
|
void
|
||||||
|
windowVXBindingInit()
|
||||||
|
{
|
||||||
|
VALUE klass = rb_define_class("Window", rb_cObject);
|
||||||
|
rb_define_alloc_func(klass, classAllocate<&WindowVXType>);
|
||||||
|
|
||||||
|
disposableBindingInit <WindowVX>(klass);
|
||||||
|
viewportElementBindingInit<WindowVX>(klass);
|
||||||
|
|
||||||
|
_rb_define_method(klass, "initialize", windowVXInitialize);
|
||||||
|
_rb_define_method(klass, "update", windowVXUpdate);
|
||||||
|
|
||||||
|
INIT_PROP_BIND( WindowVX, Windowskin, "windowskin" );
|
||||||
|
INIT_PROP_BIND( WindowVX, Contents, "contents" );
|
||||||
|
INIT_PROP_BIND( WindowVX, CursorRect, "cursor_rect" );
|
||||||
|
INIT_PROP_BIND( WindowVX, Active, "active" );
|
||||||
|
INIT_PROP_BIND( WindowVX, Pause, "pause" );
|
||||||
|
INIT_PROP_BIND( WindowVX, X, "x" );
|
||||||
|
INIT_PROP_BIND( WindowVX, Y, "y" );
|
||||||
|
INIT_PROP_BIND( WindowVX, Width, "width" );
|
||||||
|
INIT_PROP_BIND( WindowVX, Height, "height" );
|
||||||
|
INIT_PROP_BIND( WindowVX, OX, "ox" );
|
||||||
|
INIT_PROP_BIND( WindowVX, OY, "oy" );
|
||||||
|
INIT_PROP_BIND( WindowVX, Opacity, "opacity" );
|
||||||
|
INIT_PROP_BIND( WindowVX, BackOpacity, "back_opacity" );
|
||||||
|
INIT_PROP_BIND( WindowVX, ContentsOpacity, "contents_opacity" );
|
||||||
|
INIT_PROP_BIND( WindowVX, Openness, "openness" );
|
||||||
|
|
||||||
|
if (rgssVer >= 3)
|
||||||
|
{
|
||||||
|
_rb_define_method(klass, "move", windowVXMove);
|
||||||
|
_rb_define_method(klass, "open?", windowVXIsOpen);
|
||||||
|
_rb_define_method(klass, "close?", windowVXIsClosed);
|
||||||
|
|
||||||
|
INIT_PROP_BIND( WindowVX, ArrowsVisible, "arrows_visible" );
|
||||||
|
INIT_PROP_BIND( WindowVX, Padding, "padding" );
|
||||||
|
INIT_PROP_BIND( WindowVX, PaddingBottom, "padding_bottom" );
|
||||||
|
INIT_PROP_BIND( WindowVX, Tone, "tone" );
|
||||||
|
}
|
||||||
|
}
|
36
binding-mri/meson.build
Normal file
36
binding-mri/meson.build
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
|
||||||
|
mri = dependency('ruby-' + get_option('mri_version'))
|
||||||
|
binding_dependencies = [mri]
|
||||||
|
|
||||||
|
add_project_arguments('-DBINDING_MRI', language: 'cpp')
|
||||||
|
|
||||||
|
binding_headers = files(
|
||||||
|
'binding-util.h',
|
||||||
|
'binding-types.h',
|
||||||
|
'serializable-binding.h',
|
||||||
|
'disposable-binding.h',
|
||||||
|
'sceneelement-binding.h',
|
||||||
|
'viewportelement-binding.h',
|
||||||
|
'flashable-binding.h',
|
||||||
|
)
|
||||||
|
|
||||||
|
binding_source = files(
|
||||||
|
'binding-mri.cpp',
|
||||||
|
'binding-util.cpp',
|
||||||
|
'table-binding.cpp',
|
||||||
|
'etc-binding.cpp',
|
||||||
|
'bitmap-binding.cpp',
|
||||||
|
'font-binding.cpp',
|
||||||
|
'graphics-binding.cpp',
|
||||||
|
'input-binding.cpp',
|
||||||
|
'sprite-binding.cpp',
|
||||||
|
'viewport-binding.cpp',
|
||||||
|
'plane-binding.cpp',
|
||||||
|
'window-binding.cpp',
|
||||||
|
'tilemap-binding.cpp',
|
||||||
|
'audio-binding.cpp',
|
||||||
|
'module_rpg.cpp',
|
||||||
|
'filesystem-binding.cpp',
|
||||||
|
'windowvx-binding.cpp',
|
||||||
|
'tilemapvx-binding.cpp',
|
||||||
|
)
|
47
binding-mruby/meson.build
Normal file
47
binding-mruby/meson.build
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
# mruby support in cmake wasn't finished, I assume it wouldn't be
|
||||||
|
# here either -- it can be done later
|
||||||
|
|
||||||
|
warning('mruby support in meson needs to be finished')
|
||||||
|
|
||||||
|
mruby = meson.get_compiler('cpp').find_library('mruby')
|
||||||
|
add_languages('c')
|
||||||
|
|
||||||
|
binding_dependencies = [mruby]
|
||||||
|
|
||||||
|
add_project_arguments('-DBINDING_MRUBY', language: 'cpp')
|
||||||
|
|
||||||
|
binding_headers = files(
|
||||||
|
'binding-util.h',
|
||||||
|
'disposable-binding.h',
|
||||||
|
'flashable-binding.h',
|
||||||
|
'binding-types.h',
|
||||||
|
'sceneelement-binding.h',
|
||||||
|
'viewportelement-binding.h',
|
||||||
|
'serializable-binding.h',
|
||||||
|
'mrb-ext/file.h',
|
||||||
|
'mrb-ext/rwmem.h',
|
||||||
|
'mrb-ext/marshal.h'
|
||||||
|
)
|
||||||
|
|
||||||
|
binding_source = files(
|
||||||
|
'binding-mruby.cpp',
|
||||||
|
'binding-util.cpp',
|
||||||
|
'window-binding.cpp',
|
||||||
|
'bitmap-binding.cpp',
|
||||||
|
'sprite-binding.cpp',
|
||||||
|
'font-binding.cpp',
|
||||||
|
'viewport-binding.cpp',
|
||||||
|
'plane-binding.cpp',
|
||||||
|
'audio-binding.cpp',
|
||||||
|
'tilemap-binding.cpp',
|
||||||
|
'etc-binding.cpp',
|
||||||
|
'graphics-binding.cpp',
|
||||||
|
'input-binding.cpp',
|
||||||
|
'table-binding.cpp',
|
||||||
|
'module_rpg.c',
|
||||||
|
'mrb-ext/file.cpp',
|
||||||
|
'mrb-ext/marshal.cpp',
|
||||||
|
'mrb-ext/rwmem.cpp',
|
||||||
|
'mrb-ext/kernel.cpp',
|
||||||
|
'mrb-ext/time.cpp'
|
||||||
|
)
|
5
binding-null/meson.build
Normal file
5
binding-null/meson.build
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
binding_headers = []
|
||||||
|
binding_dependencies = []
|
||||||
|
binding_source = files(
|
||||||
|
'binding-null.cpp'
|
||||||
|
)
|
|
@ -1,38 +0,0 @@
|
||||||
if(APPLE)
|
|
||||||
function(PostBuildMacBundle target framework_list lib_list)
|
|
||||||
INCLUDE(BundleUtilities)
|
|
||||||
GET_TARGET_PROPERTY(_BIN_NAME ${target} LOCATION)
|
|
||||||
GET_DOTAPP_DIR(${_BIN_NAME} _BUNDLE_DIR)
|
|
||||||
|
|
||||||
set(_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${target}_prep.cmake")
|
|
||||||
file(WRITE ${_SCRIPT_FILE}
|
|
||||||
"# Generated Script file\n"
|
|
||||||
"include(BundleUtilities)\n"
|
|
||||||
"get_bundle_and_executable(\"\${BUNDLE_APP}\" bundle executable valid)\n"
|
|
||||||
"if(valid)\n"
|
|
||||||
" set(framework_dest \"\${bundle}/Contents/Frameworks\")\n"
|
|
||||||
" foreach(framework_path ${framework_list})\n"
|
|
||||||
" get_filename_component(framework_name \${framework_path} NAME_WE)\n"
|
|
||||||
" file(MAKE_DIRECTORY \"\${framework_dest}/\${framework_name}.framework/Versions/A/\")\n"
|
|
||||||
" copy_resolved_framework_into_bundle(\${framework_path}/Versions/A/\${framework_name} \${framework_dest}/\${framework_name}.framework/Versions/A/\${framework_name})\n"
|
|
||||||
" endforeach()\n"
|
|
||||||
" foreach(lib ${lib_list})\n"
|
|
||||||
" get_filename_component(lib_file \${lib} NAME)\n"
|
|
||||||
" copy_resolved_item_into_bundle(\${lib} \${framework_dest}/\${lib_file})\n"
|
|
||||||
" endforeach()\n"
|
|
||||||
"else()\n"
|
|
||||||
" message(ERROR \"App Not found? \${BUNDLE_APP}\")\n"
|
|
||||||
"endif()\n"
|
|
||||||
"#fixup_bundle(\"\${BUNDLE_APP}\" \"\" \"\${DEP_LIB_DIR}\")\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
ADD_CUSTOM_COMMAND(TARGET ${target}
|
|
||||||
POST_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -DBUNDLE_APP="${_BUNDLE_DIR}" -P "${_SCRIPT_FILE}"
|
|
||||||
)
|
|
||||||
endfunction()
|
|
||||||
else()
|
|
||||||
function(PostBuildMacBundle target framework_list lib_list)
|
|
||||||
# noop
|
|
||||||
endfunction()
|
|
||||||
endif()
|
|
36
docker/Dockerfile
Normal file
36
docker/Dockerfile
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# This will create an Ubuntu 18.04 image with all the dependencies required to build MKXP-EX for linux.
|
||||||
|
|
||||||
|
FROM ubuntu:bionic
|
||||||
|
#--------------------
|
||||||
|
# Get stuff from apt
|
||||||
|
|
||||||
|
RUN apt-get update
|
||||||
|
RUN apt-get install curl \
|
||||||
|
build-essential git bison cmake meson autoconf libtool pkg-config xxd \
|
||||||
|
libsdl2* libvorbisfile3 libvorbis-dev libpixman-1* libsigc++-2.0* libogg-dev \
|
||||||
|
libboost-program-options1.65* libopenal1 libopenal-dev zlib1g* fluidsynth \
|
||||||
|
libfluidsynth-dev -y
|
||||||
|
|
||||||
|
#--------------------
|
||||||
|
RUN mkdir /source
|
||||||
|
|
||||||
|
# Install stock Ruby (2.5 for bionic)
|
||||||
|
RUN apt-get install ruby ruby-dev -y
|
||||||
|
|
||||||
|
# Install stock mruby
|
||||||
|
RUN apt-get install mruby libmruby-dev
|
||||||
|
|
||||||
|
# Install Ruby 1.8
|
||||||
|
# RUN curl https://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7.tar.bz2 | tar xj -C /source
|
||||||
|
# RUN (cd /source/ruby-1.8.7 && autoconf && ./configure --disable-install-doc --enable-shared && make && make install)
|
||||||
|
# RUN mkdir -p /usr/local/include/ruby; cp -r /source/ruby-1.8.7/*.h /usr/local/include/ruby
|
||||||
|
|
||||||
|
# Install PhysFS
|
||||||
|
RUN git clone https://github.com/criptych/physfs /source/physfs
|
||||||
|
RUN mkdir /source/physfs/build; (cd /source/physfs/build && cmake .. && make && make install)
|
||||||
|
|
||||||
|
# Install SDL_Sound
|
||||||
|
RUN git clone https://github.com/Ancurio/SDL_Sound /source/SDL_Sound
|
||||||
|
RUN (cd /source/SDL_Sound && ./bootstrap && ./configure && make install)
|
||||||
|
|
||||||
|
RUN rm -rf /source/*
|
30
meson.build
Normal file
30
meson.build
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
project('mkxp', 'cpp', version: '1.0', meson_version: '>=0.45.1')
|
||||||
|
|
||||||
|
xxd = find_program('xxd')
|
||||||
|
binding_dir = 'binding-' + get_option('binding')
|
||||||
|
host_system = host_machine.system()
|
||||||
|
|
||||||
|
subdir('src')
|
||||||
|
subdir(binding_dir)
|
||||||
|
subdir('shader')
|
||||||
|
subdir('assets')
|
||||||
|
|
||||||
|
all_sources = [main_headers, main_source, binding_headers, binding_source, processed_shaders, processed_assets]
|
||||||
|
|
||||||
|
linker_args = []
|
||||||
|
|
||||||
|
if host_system == 'windows'
|
||||||
|
subdir('windows')
|
||||||
|
all_sources += windows_resources
|
||||||
|
elif host_system == 'darwin'
|
||||||
|
if meson.get_compiler('cpp').get_id() == 'clang'
|
||||||
|
add_project_arguments(['-std=c++11','-stdlib=libc++'], language: 'cpp')
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
executable('mkxp.@1@.@0@'.format(host_machine.cpu(), host_system),
|
||||||
|
sources: all_sources,
|
||||||
|
dependencies: [main_dependencies, binding_dependencies],
|
||||||
|
include_directories: include_directories('src', binding_dir),
|
||||||
|
link_args: '-L/usr/local/opt/ruby/lib' # homebrew ruby pc is screwed
|
||||||
|
)
|
3
meson_options.txt
Normal file
3
meson_options.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
option('shared_fluid', type: 'boolean', value: false, description: 'Dynamically link fluidsynth at build time')
|
||||||
|
option('binding', type: 'combo', value: 'mri', choices: ['mri', 'legacy', 'mruby', 'null'], description: 'Binding type')
|
||||||
|
option('mri_version', type: 'string', value: '2.5', description: 'Version of MRI to link with')
|
332
mkxp.pro
332
mkxp.pro
|
@ -1,332 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
TEMPLATE = app
|
|
||||||
QT =
|
|
||||||
TARGET = mkxp
|
|
||||||
DEPENDPATH += src shader assets
|
|
||||||
INCLUDEPATH += . src
|
|
||||||
|
|
||||||
CONFIG(release, debug|release): DEFINES += NDEBUG
|
|
||||||
|
|
||||||
CONFIG += c++11
|
|
||||||
# And for older qmake versions..
|
|
||||||
QMAKE_CXXFLAGS += -std=c++11
|
|
||||||
|
|
||||||
isEmpty(BINDING) {
|
|
||||||
BINDING = MRI
|
|
||||||
}
|
|
||||||
|
|
||||||
contains(BINDING, MRI) {
|
|
||||||
contains(_HAVE_BINDING, YES) {
|
|
||||||
error("Only one binding may be selected")
|
|
||||||
}
|
|
||||||
_HAVE_BINDING = YES
|
|
||||||
|
|
||||||
CONFIG += BINDING_MRI
|
|
||||||
}
|
|
||||||
|
|
||||||
contains(BINDING, MRUBY) {
|
|
||||||
contains(_HAVE_BINDING, YES) {
|
|
||||||
error("Only one binding may be selected")
|
|
||||||
}
|
|
||||||
_HAVE_BINDING = YES
|
|
||||||
|
|
||||||
CONFIG += BINDING_MRUBY
|
|
||||||
}
|
|
||||||
|
|
||||||
contains(BINDING, NULL) {
|
|
||||||
contains(_HAVE_BINDING, YES) {
|
|
||||||
error("Only one binding may be selected")
|
|
||||||
}
|
|
||||||
_HAVE_BINDING = YES
|
|
||||||
|
|
||||||
CONFIG += BINDING_NULL
|
|
||||||
}
|
|
||||||
|
|
||||||
unix {
|
|
||||||
CONFIG += link_pkgconfig
|
|
||||||
PKGCONFIG += sigc++-2.0 pixman-1 zlib physfs vorbisfile \
|
|
||||||
sdl2 SDL2_image SDL2_ttf SDL_sound openal
|
|
||||||
|
|
||||||
SHARED_FLUID {
|
|
||||||
PKGCONFIG += fluidsynth
|
|
||||||
}
|
|
||||||
|
|
||||||
INI_ENCODING {
|
|
||||||
PKGCONFIG += libguess
|
|
||||||
}
|
|
||||||
|
|
||||||
# Deal with boost paths...
|
|
||||||
isEmpty(BOOST_I) {
|
|
||||||
BOOST_I = $$(BOOST_I)
|
|
||||||
}
|
|
||||||
isEmpty(BOOST_I) {}
|
|
||||||
else {
|
|
||||||
INCLUDEPATH += $$BOOST_I
|
|
||||||
}
|
|
||||||
|
|
||||||
isEmpty(BOOST_L) {
|
|
||||||
BOOST_L = $$(BOOST_L)
|
|
||||||
}
|
|
||||||
isEmpty(BOOST_L) {}
|
|
||||||
else {
|
|
||||||
LIBS += -L$$BOOST_L
|
|
||||||
}
|
|
||||||
|
|
||||||
isEmpty(BOOST_LIB_SUFFIX) {
|
|
||||||
BOOST_LIB_SUFFIX = $$(BOOST_LIB_SUFFIX)
|
|
||||||
}
|
|
||||||
|
|
||||||
LIBS += -lboost_program_options$$BOOST_LIB_SUFFIX
|
|
||||||
}
|
|
||||||
|
|
||||||
# Input
|
|
||||||
HEADERS += \
|
|
||||||
src/quadarray.h \
|
|
||||||
src/audio.h \
|
|
||||||
src/binding.h \
|
|
||||||
src/bitmap.h \
|
|
||||||
src/disposable.h \
|
|
||||||
src/etc.h \
|
|
||||||
src/etc-internal.h \
|
|
||||||
src/eventthread.h \
|
|
||||||
src/flashable.h \
|
|
||||||
src/font.h \
|
|
||||||
src/input.h \
|
|
||||||
src/iniconfig.h \
|
|
||||||
src/plane.h \
|
|
||||||
src/scene.h \
|
|
||||||
src/sprite.h \
|
|
||||||
src/table.h \
|
|
||||||
src/texpool.h \
|
|
||||||
src/tilequad.h \
|
|
||||||
src/transform.h \
|
|
||||||
src/viewport.h \
|
|
||||||
src/window.h \
|
|
||||||
src/serializable.h \
|
|
||||||
src/shader.h \
|
|
||||||
src/glstate.h \
|
|
||||||
src/quad.h \
|
|
||||||
src/tilemap.h \
|
|
||||||
src/tilemap-common.h \
|
|
||||||
src/graphics.h \
|
|
||||||
src/gl-debug.h \
|
|
||||||
src/global-ibo.h \
|
|
||||||
src/exception.h \
|
|
||||||
src/filesystem.h \
|
|
||||||
src/serial-util.h \
|
|
||||||
src/intrulist.h \
|
|
||||||
src/binding.h \
|
|
||||||
src/gl-util.h \
|
|
||||||
src/util.h \
|
|
||||||
src/config.h \
|
|
||||||
src/settingsmenu.h \
|
|
||||||
src/keybindings.h \
|
|
||||||
src/tileatlas.h \
|
|
||||||
src/sharedstate.h \
|
|
||||||
src/al-util.h \
|
|
||||||
src/boost-hash.h \
|
|
||||||
src/debugwriter.h \
|
|
||||||
src/gl-fun.h \
|
|
||||||
src/gl-meta.h \
|
|
||||||
src/vertex.h \
|
|
||||||
src/soundemitter.h \
|
|
||||||
src/aldatasource.h \
|
|
||||||
src/alstream.h \
|
|
||||||
src/audiostream.h \
|
|
||||||
src/rgssad.h \
|
|
||||||
src/windowvx.h \
|
|
||||||
src/tilemapvx.h \
|
|
||||||
src/tileatlasvx.h \
|
|
||||||
src/sharedmidistate.h \
|
|
||||||
src/fluid-fun.h \
|
|
||||||
src/sdl-util.h
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
src/main.cpp \
|
|
||||||
src/audio.cpp \
|
|
||||||
src/bitmap.cpp \
|
|
||||||
src/eventthread.cpp \
|
|
||||||
src/filesystem.cpp \
|
|
||||||
src/font.cpp \
|
|
||||||
src/input.cpp \
|
|
||||||
src/iniconfig.cpp \
|
|
||||||
src/plane.cpp \
|
|
||||||
src/scene.cpp \
|
|
||||||
src/sprite.cpp \
|
|
||||||
src/table.cpp \
|
|
||||||
src/tilequad.cpp \
|
|
||||||
src/viewport.cpp \
|
|
||||||
src/window.cpp \
|
|
||||||
src/texpool.cpp \
|
|
||||||
src/shader.cpp \
|
|
||||||
src/glstate.cpp \
|
|
||||||
src/tilemap.cpp \
|
|
||||||
src/autotiles.cpp \
|
|
||||||
src/graphics.cpp \
|
|
||||||
src/gl-debug.cpp \
|
|
||||||
src/etc.cpp \
|
|
||||||
src/config.cpp \
|
|
||||||
src/settingsmenu.cpp \
|
|
||||||
src/keybindings.cpp \
|
|
||||||
src/tileatlas.cpp \
|
|
||||||
src/sharedstate.cpp \
|
|
||||||
src/gl-fun.cpp \
|
|
||||||
src/gl-meta.cpp \
|
|
||||||
src/vertex.cpp \
|
|
||||||
src/soundemitter.cpp \
|
|
||||||
src/sdlsoundsource.cpp \
|
|
||||||
src/alstream.cpp \
|
|
||||||
src/audiostream.cpp \
|
|
||||||
src/rgssad.cpp \
|
|
||||||
src/bundledfont.cpp \
|
|
||||||
src/vorbissource.cpp \
|
|
||||||
src/windowvx.cpp \
|
|
||||||
src/tilemapvx.cpp \
|
|
||||||
src/tileatlasvx.cpp \
|
|
||||||
src/autotilesvx.cpp \
|
|
||||||
src/midisource.cpp \
|
|
||||||
src/fluid-fun.cpp
|
|
||||||
|
|
||||||
EMBED = \
|
|
||||||
shader/common.h \
|
|
||||||
shader/transSimple.frag \
|
|
||||||
shader/trans.frag \
|
|
||||||
shader/hue.frag \
|
|
||||||
shader/sprite.frag \
|
|
||||||
shader/plane.frag \
|
|
||||||
shader/gray.frag \
|
|
||||||
shader/bitmapBlit.frag \
|
|
||||||
shader/flatColor.frag \
|
|
||||||
shader/simple.frag \
|
|
||||||
shader/simpleColor.frag \
|
|
||||||
shader/simpleAlpha.frag \
|
|
||||||
shader/simpleAlphaUni.frag \
|
|
||||||
shader/flashMap.frag \
|
|
||||||
shader/minimal.vert \
|
|
||||||
shader/simple.vert \
|
|
||||||
shader/simpleColor.vert \
|
|
||||||
shader/sprite.vert \
|
|
||||||
shader/tilemap.vert \
|
|
||||||
shader/blur.frag \
|
|
||||||
shader/blurH.vert \
|
|
||||||
shader/blurV.vert \
|
|
||||||
shader/simpleMatrix.vert \
|
|
||||||
shader/tilemapvx.vert \
|
|
||||||
assets/liberation.ttf \
|
|
||||||
assets/icon.png
|
|
||||||
|
|
||||||
SHARED_FLUID {
|
|
||||||
DEFINES += SHARED_FLUID
|
|
||||||
}
|
|
||||||
|
|
||||||
INI_ENCODING {
|
|
||||||
DEFINES += INI_ENCODING
|
|
||||||
}
|
|
||||||
|
|
||||||
defineReplace(xxdOutput) {
|
|
||||||
return($$basename(1).xxd)
|
|
||||||
}
|
|
||||||
|
|
||||||
# xxd
|
|
||||||
xxd.output_function = xxdOutput
|
|
||||||
xxd.commands = xxd -i ${QMAKE_FILE_NAME} > ${QMAKE_FILE_OUT}
|
|
||||||
xxd.depends = $$EMBED
|
|
||||||
xxd.input = EMBED
|
|
||||||
xxd.variable_out = HEADERS
|
|
||||||
|
|
||||||
QMAKE_EXTRA_COMPILERS += xxd
|
|
||||||
|
|
||||||
|
|
||||||
BINDING_NULL {
|
|
||||||
SOURCES += binding-null/binding-null.cpp
|
|
||||||
}
|
|
||||||
|
|
||||||
BINDING_MRUBY {
|
|
||||||
LIBS += mruby/build/host/lib/libmruby.a
|
|
||||||
INCLUDEPATH += mruby/include
|
|
||||||
DEPENDPATH += mruby/include
|
|
||||||
DEFINES += BINDING_MRUBY
|
|
||||||
|
|
||||||
HEADERS += \
|
|
||||||
binding-mruby/binding-util.h \
|
|
||||||
binding-mruby/disposable-binding.h \
|
|
||||||
binding-mruby/flashable-binding.h \
|
|
||||||
binding-mruby/binding-types.h \
|
|
||||||
binding-mruby/sceneelement-binding.h \
|
|
||||||
binding-mruby/viewportelement-binding.h \
|
|
||||||
binding-mruby/serializable-binding.h \
|
|
||||||
binding-mruby/mrb-ext/file.h \
|
|
||||||
binding-mruby/mrb-ext/rwmem.h \
|
|
||||||
binding-mruby/mrb-ext/marshal.h
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
binding-mruby/binding-mruby.cpp \
|
|
||||||
binding-mruby/binding-util.cpp \
|
|
||||||
binding-mruby/window-binding.cpp \
|
|
||||||
binding-mruby/bitmap-binding.cpp \
|
|
||||||
binding-mruby/sprite-binding.cpp \
|
|
||||||
binding-mruby/font-binding.cpp \
|
|
||||||
binding-mruby/viewport-binding.cpp \
|
|
||||||
binding-mruby/plane-binding.cpp \
|
|
||||||
binding-mruby/audio-binding.cpp \
|
|
||||||
binding-mruby/tilemap-binding.cpp \
|
|
||||||
binding-mruby/etc-binding.cpp \
|
|
||||||
binding-mruby/graphics-binding.cpp \
|
|
||||||
binding-mruby/input-binding.cpp \
|
|
||||||
binding-mruby/table-binding.cpp \
|
|
||||||
binding-mruby/module_rpg.c \
|
|
||||||
binding-mruby/mrb-ext/file.cpp \
|
|
||||||
binding-mruby/mrb-ext/marshal.cpp \
|
|
||||||
binding-mruby/mrb-ext/rwmem.cpp \
|
|
||||||
binding-mruby/mrb-ext/kernel.cpp \
|
|
||||||
binding-mruby/mrb-ext/time.cpp
|
|
||||||
}
|
|
||||||
|
|
||||||
BINDING_MRI {
|
|
||||||
isEmpty(MRIVERSION) {
|
|
||||||
MRIVERSION = 2.1
|
|
||||||
}
|
|
||||||
|
|
||||||
PKGCONFIG += ruby-$$MRIVERSION
|
|
||||||
DEFINES += BINDING_MRI
|
|
||||||
|
|
||||||
# EMBED2 = binding-mri/module_rpg.rb
|
|
||||||
# xxdp.output = ${QMAKE_FILE_NAME}.xxd
|
|
||||||
# xxdp.commands = xxd+/xxd+ ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} --string
|
|
||||||
# xxdp.depends = $$EMBED2
|
|
||||||
# xxdp.input = EMBED2
|
|
||||||
# xxdp.variable_out = HEADERS
|
|
||||||
# QMAKE_EXTRA_COMPILERS += xxdp
|
|
||||||
|
|
||||||
HEADERS += \
|
|
||||||
binding-mri/binding-util.h \
|
|
||||||
binding-mri/binding-types.h \
|
|
||||||
binding-mri/serializable-binding.h \
|
|
||||||
binding-mri/disposable-binding.h \
|
|
||||||
binding-mri/sceneelement-binding.h \
|
|
||||||
binding-mri/viewportelement-binding.h \
|
|
||||||
binding-mri/flashable-binding.h
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
binding-mri/binding-mri.cpp \
|
|
||||||
binding-mri/binding-util.cpp \
|
|
||||||
binding-mri/table-binding.cpp \
|
|
||||||
binding-mri/etc-binding.cpp \
|
|
||||||
binding-mri/bitmap-binding.cpp \
|
|
||||||
binding-mri/font-binding.cpp \
|
|
||||||
binding-mri/graphics-binding.cpp \
|
|
||||||
binding-mri/input-binding.cpp \
|
|
||||||
binding-mri/sprite-binding.cpp \
|
|
||||||
binding-mri/viewport-binding.cpp \
|
|
||||||
binding-mri/plane-binding.cpp \
|
|
||||||
binding-mri/window-binding.cpp \
|
|
||||||
binding-mri/tilemap-binding.cpp \
|
|
||||||
binding-mri/audio-binding.cpp \
|
|
||||||
binding-mri/module_rpg.cpp \
|
|
||||||
binding-mri/filesystem-binding.cpp \
|
|
||||||
binding-mri/windowvx-binding.cpp \
|
|
||||||
binding-mri/tilemapvx-binding.cpp
|
|
||||||
}
|
|
||||||
|
|
||||||
OTHER_FILES += $$EMBED
|
|
44
shader/meson.build
Normal file
44
shader/meson.build
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
|
||||||
|
embedded_shaders = [
|
||||||
|
'common.h',
|
||||||
|
'transSimple.frag',
|
||||||
|
'trans.frag',
|
||||||
|
'hue.frag',
|
||||||
|
'sprite.frag',
|
||||||
|
'plane.frag',
|
||||||
|
'gray.frag',
|
||||||
|
'bitmapBlit.frag',
|
||||||
|
'flatColor.frag',
|
||||||
|
'simple.frag',
|
||||||
|
'simpleColor.frag',
|
||||||
|
'simpleAlpha.frag',
|
||||||
|
'simpleAlphaUni.frag',
|
||||||
|
'flashMap.frag',
|
||||||
|
'minimal.vert',
|
||||||
|
'simple.vert',
|
||||||
|
'simpleColor.vert',
|
||||||
|
'sprite.vert',
|
||||||
|
'tilemap.vert',
|
||||||
|
'tilemapvx.vert',
|
||||||
|
'blur.frag',
|
||||||
|
'blurH.vert',
|
||||||
|
'blurV.vert',
|
||||||
|
'simpleMatrix.vert'
|
||||||
|
]
|
||||||
|
|
||||||
|
embedded_shaders_f = files(embedded_shaders)
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
processed_shaders = []
|
||||||
|
foreach file : embedded_shaders_f
|
||||||
|
processed_shaders += custom_target(embedded_shaders[count],
|
||||||
|
input: file,
|
||||||
|
output: '@0@.xxd'.format(embedded_shaders[count]),
|
||||||
|
command: [
|
||||||
|
xxd, '-i', '@INPUT@'
|
||||||
|
],
|
||||||
|
capture: true,
|
||||||
|
depend_files: embedded_shaders_f
|
||||||
|
)
|
||||||
|
count += 1
|
||||||
|
endforeach
|
|
@ -36,13 +36,13 @@
|
||||||
#define BUNDLED_FONT liberation
|
#define BUNDLED_FONT liberation
|
||||||
|
|
||||||
#define BUNDLED_FONT_DECL(FONT) \
|
#define BUNDLED_FONT_DECL(FONT) \
|
||||||
extern unsigned char assets_##FONT##_ttf[]; \
|
extern unsigned char ___assets_##FONT##_ttf[]; \
|
||||||
extern unsigned int assets_##FONT##_ttf_len;
|
extern unsigned int ___assets_##FONT##_ttf_len;
|
||||||
|
|
||||||
BUNDLED_FONT_DECL(liberation)
|
BUNDLED_FONT_DECL(liberation)
|
||||||
|
|
||||||
#define BUNDLED_FONT_D(f) assets_## f ##_ttf
|
#define BUNDLED_FONT_D(f) ___assets_## f ##_ttf
|
||||||
#define BUNDLED_FONT_L(f) assets_## f ##_ttf_len
|
#define BUNDLED_FONT_L(f) ___assets_## f ##_ttf_len
|
||||||
|
|
||||||
// Go fuck yourself CPP
|
// Go fuck yourself CPP
|
||||||
#define BNDL_F_D(f) BUNDLED_FONT_D(f)
|
#define BNDL_F_D(f) BUNDLED_FONT_D(f)
|
||||||
|
|
|
@ -178,7 +178,7 @@ static void setupWindowIcon(const Config &conf, SDL_Window *win)
|
||||||
SDL_RWops *iconSrc;
|
SDL_RWops *iconSrc;
|
||||||
|
|
||||||
if (conf.iconPath.empty())
|
if (conf.iconPath.empty())
|
||||||
iconSrc = SDL_RWFromConstMem(assets_icon_png, assets_icon_png_len);
|
iconSrc = SDL_RWFromConstMem(___assets_icon_png, ___assets_icon_png_len);
|
||||||
else
|
else
|
||||||
iconSrc = SDL_RWFromFile(conf.iconPath.c_str(), "rb");
|
iconSrc = SDL_RWFromFile(conf.iconPath.c_str(), "rb");
|
||||||
|
|
||||||
|
|
129
src/meson.build
Normal file
129
src/meson.build
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
sigcxx = dependency('sigc++-2.0')
|
||||||
|
pixman = dependency('pixman-1')
|
||||||
|
physfs = dependency('physfs', version: '>=2.1')
|
||||||
|
vorbisfile = dependency('vorbisfile')
|
||||||
|
sdl2 = dependency('sdl2')
|
||||||
|
sdl2_ttf = dependency('SDL2_ttf')
|
||||||
|
sdl2_image = dependency('SDL2_image')
|
||||||
|
sdl_sound = dependency('SDL_sound')
|
||||||
|
|
||||||
|
boost = dependency('boost', version: '>=1.49', modules: 'program_options')
|
||||||
|
openal = dependency('openal')
|
||||||
|
zlib = dependency('zlib')
|
||||||
|
|
||||||
|
main_dependencies = [sigcxx, openal, boost, zlib, pixman, physfs, vorbisfile, sdl2, sdl2_ttf, sdl2_image, sdl_sound]
|
||||||
|
|
||||||
|
if get_option('shared_fluid') == true
|
||||||
|
fluidsynth = dependency('fluidsynth')
|
||||||
|
add_project_arguments('-DSHARED_FLUID', language: 'cpp')
|
||||||
|
main_dependencies += fluidsynth
|
||||||
|
endif
|
||||||
|
|
||||||
|
main_headers = files(
|
||||||
|
'quadarray.h',
|
||||||
|
'audio.h',
|
||||||
|
'binding.h',
|
||||||
|
'bitmap.h',
|
||||||
|
'disposable.h',
|
||||||
|
'etc.h',
|
||||||
|
'etc-internal.h',
|
||||||
|
'eventthread.h',
|
||||||
|
'flashable.h',
|
||||||
|
'font.h',
|
||||||
|
'input.h',
|
||||||
|
'iniconfig.h',
|
||||||
|
'plane.h',
|
||||||
|
'scene.h',
|
||||||
|
'sprite.h',
|
||||||
|
'table.h',
|
||||||
|
'texpool.h',
|
||||||
|
'tilequad.h',
|
||||||
|
'transform.h',
|
||||||
|
'viewport.h',
|
||||||
|
'window.h',
|
||||||
|
'serializable.h',
|
||||||
|
'shader.h',
|
||||||
|
'glstate.h',
|
||||||
|
'quad.h',
|
||||||
|
'tilemap.h',
|
||||||
|
'tilemap-common.h',
|
||||||
|
'graphics.h',
|
||||||
|
'gl-debug.h',
|
||||||
|
'global-ibo.h',
|
||||||
|
'exception.h',
|
||||||
|
'filesystem.h',
|
||||||
|
'serial-util.h',
|
||||||
|
'intrulist.h',
|
||||||
|
'binding.h',
|
||||||
|
'gl-util.h',
|
||||||
|
'util.h',
|
||||||
|
'config.h',
|
||||||
|
'settingsmenu.h',
|
||||||
|
'keybindings.h',
|
||||||
|
'tileatlas.h',
|
||||||
|
'sharedstate.h',
|
||||||
|
'al-util.h',
|
||||||
|
'boost-hash.h',
|
||||||
|
'debugwriter.h',
|
||||||
|
'gl-fun.h',
|
||||||
|
'gl-meta.h',
|
||||||
|
'vertex.h',
|
||||||
|
'soundemitter.h',
|
||||||
|
'aldatasource.h',
|
||||||
|
'alstream.h',
|
||||||
|
'audiostream.h',
|
||||||
|
'rgssad.h',
|
||||||
|
'windowvx.h',
|
||||||
|
'tilemapvx.h',
|
||||||
|
'tileatlasvx.h',
|
||||||
|
'sharedmidistate.h',
|
||||||
|
'fluid-fun.h',
|
||||||
|
'sdl-util.h'
|
||||||
|
)
|
||||||
|
|
||||||
|
main_source = files(
|
||||||
|
'main.cpp',
|
||||||
|
'audio.cpp',
|
||||||
|
'bitmap.cpp',
|
||||||
|
'eventthread.cpp',
|
||||||
|
'filesystem.cpp',
|
||||||
|
'font.cpp',
|
||||||
|
'input.cpp',
|
||||||
|
'iniconfig.cpp',
|
||||||
|
'plane.cpp',
|
||||||
|
'scene.cpp',
|
||||||
|
'sprite.cpp',
|
||||||
|
'table.cpp',
|
||||||
|
'tilequad.cpp',
|
||||||
|
'viewport.cpp',
|
||||||
|
'window.cpp',
|
||||||
|
'texpool.cpp',
|
||||||
|
'shader.cpp',
|
||||||
|
'glstate.cpp',
|
||||||
|
'tilemap.cpp',
|
||||||
|
'autotiles.cpp',
|
||||||
|
'graphics.cpp',
|
||||||
|
'gl-debug.cpp',
|
||||||
|
'etc.cpp',
|
||||||
|
'config.cpp',
|
||||||
|
'settingsmenu.cpp',
|
||||||
|
'keybindings.cpp',
|
||||||
|
'tileatlas.cpp',
|
||||||
|
'sharedstate.cpp',
|
||||||
|
'gl-fun.cpp',
|
||||||
|
'gl-meta.cpp',
|
||||||
|
'vertex.cpp',
|
||||||
|
'soundemitter.cpp',
|
||||||
|
'sdlsoundsource.cpp',
|
||||||
|
'alstream.cpp',
|
||||||
|
'audiostream.cpp',
|
||||||
|
'rgssad.cpp',
|
||||||
|
'bundledfont.cpp',
|
||||||
|
'vorbissource.cpp',
|
||||||
|
'windowvx.cpp',
|
||||||
|
'tilemapvx.cpp',
|
||||||
|
'tileatlasvx.cpp',
|
||||||
|
'autotilesvx.cpp',
|
||||||
|
'midisource.cpp',
|
||||||
|
'fluid-fun.cpp'
|
||||||
|
)
|
|
@ -56,7 +56,7 @@
|
||||||
|
|
||||||
#define INIT_SHADER(vert, frag, name) \
|
#define INIT_SHADER(vert, frag, name) \
|
||||||
{ \
|
{ \
|
||||||
Shader::init(shader_##vert##_vert, shader_##vert##_vert_len, shader_##frag##_frag, shader_##frag##_frag_len, \
|
Shader::init(___shader_##vert##_vert, ___shader_##vert##_vert_len, ___shader_##frag##_frag, ___shader_##frag##_frag_len, \
|
||||||
#vert, #frag, #name); \
|
#vert, #frag, #name); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,8 +135,8 @@ static void setupShaderSource(GLuint shader, GLenum type,
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
shaderSrc[i] = (const GLchar*) shader_common_h;
|
shaderSrc[i] = (const GLchar*) ___shader_common_h;
|
||||||
shaderSrcSize[i] = shader_common_h_len;
|
shaderSrcSize[i] = ___shader_common_h_len;
|
||||||
++i;
|
++i;
|
||||||
|
|
||||||
shaderSrc[i] = (const GLchar*) body;
|
shaderSrc[i] = (const GLchar*) body;
|
||||||
|
|
10
windows/meson.build
Normal file
10
windows/meson.build
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
win = import('Windows')
|
||||||
|
|
||||||
|
res = files(
|
||||||
|
'icon.ico',
|
||||||
|
'resource.h',
|
||||||
|
'resource.rc'
|
||||||
|
)
|
||||||
|
|
||||||
|
windows_resources = win.compile_resources(depend_files: windows_resources)
|
||||||
|
|
164
xxd+/main.cpp
164
xxd+/main.cpp
|
@ -1,164 +0,0 @@
|
||||||
|
|
||||||
#include <QFile>
|
|
||||||
#include <QTextStream>
|
|
||||||
#include <QDataStream>
|
|
||||||
#include <QString>
|
|
||||||
#include <QBuffer>
|
|
||||||
#include <QFileInfo>
|
|
||||||
#include <QStringList>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
static const char intro[] =
|
|
||||||
"extern const %1 %2[] = {\n";
|
|
||||||
static const char outro[] =
|
|
||||||
"\n};\nextern const %1 %2 = %3;";
|
|
||||||
|
|
||||||
int writeDump(const QString &srcFilename,
|
|
||||||
const QString &dstFilename,
|
|
||||||
const QString &dataType,
|
|
||||||
const QString &lenType,
|
|
||||||
const QString &dataSymbol,
|
|
||||||
bool addNullTerm)
|
|
||||||
{
|
|
||||||
QFile srcFile(srcFilename);
|
|
||||||
if (!srcFile.open(QFile::ReadOnly))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
QFile dstFile(dstFilename);
|
|
||||||
if (!dstFile.open(QFile::WriteOnly))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
QByteArray srcData = srcFile.readAll();
|
|
||||||
if (addNullTerm)
|
|
||||||
srcData.append('\0');
|
|
||||||
|
|
||||||
QBuffer srcBuffer(&srcData);
|
|
||||||
srcBuffer.open(QBuffer::ReadOnly);
|
|
||||||
|
|
||||||
QDataStream in(&srcBuffer);
|
|
||||||
QTextStream out(&dstFile);
|
|
||||||
|
|
||||||
QString introStr = QString(intro).arg(dataType, dataSymbol);
|
|
||||||
out << introStr;
|
|
||||||
|
|
||||||
const int byteColumns = 0x10;
|
|
||||||
int columnInd = 0;
|
|
||||||
int byteCount = 0;
|
|
||||||
|
|
||||||
while (!in.atEnd())
|
|
||||||
{
|
|
||||||
uchar byte;
|
|
||||||
in >> byte;
|
|
||||||
|
|
||||||
out << " ";
|
|
||||||
if (columnInd == 0)
|
|
||||||
out << " ";
|
|
||||||
|
|
||||||
out << "0x";
|
|
||||||
if (byte < 0x10)
|
|
||||||
out << "0";
|
|
||||||
out << QString::number(byte, 0x10);
|
|
||||||
|
|
||||||
if (!in.atEnd())
|
|
||||||
out << ",";
|
|
||||||
|
|
||||||
if (++columnInd == byteColumns)
|
|
||||||
{
|
|
||||||
out << "\n";
|
|
||||||
columnInd = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
++byteCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addNullTerm)
|
|
||||||
--byteCount;
|
|
||||||
|
|
||||||
QString outroStr = QString(outro).arg(lenType, dataSymbol+"_len", QString::number(byteCount));
|
|
||||||
out << outroStr;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString getNamedOption(const QStringList &args,
|
|
||||||
const QString &optName,
|
|
||||||
const QString &defValue)
|
|
||||||
{
|
|
||||||
QString value = defValue;
|
|
||||||
|
|
||||||
if (args.contains(optName))
|
|
||||||
{
|
|
||||||
int argInd = args.indexOf(optName);
|
|
||||||
if (argInd < args.count())
|
|
||||||
value = args.at(argInd+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char usageStr[] =
|
|
||||||
"Usage: %1 file [options]\n"
|
|
||||||
"Options:\n"
|
|
||||||
" -o [filename] Override default output filename.\n"
|
|
||||||
" --symbol [sym] Override default data C symbol.\n"
|
|
||||||
" --null-terminated Add null byte to data (not reflected in \"len\").\n"
|
|
||||||
" --string Use char for data array. Implies \"--null-terminated\".\n"
|
|
||||||
" --help Yo dawg.\n";
|
|
||||||
|
|
||||||
void usage(const QString &argv0)
|
|
||||||
{
|
|
||||||
QTextStream out(stdout);
|
|
||||||
|
|
||||||
out << QString(usageStr).arg(argv0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
(void) argc; (void) argv;
|
|
||||||
|
|
||||||
if (argc < 2)
|
|
||||||
{
|
|
||||||
usage(*argv);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString inFile(argv[1]);
|
|
||||||
QFileInfo finfo(inFile);
|
|
||||||
|
|
||||||
QStringList restArg;
|
|
||||||
for (int i = 2; i < argc; ++i)
|
|
||||||
restArg << argv[i];
|
|
||||||
|
|
||||||
if (restArg.contains("--help"))
|
|
||||||
{
|
|
||||||
usage(*argv);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool nullTerm = false;
|
|
||||||
bool stringData = false;
|
|
||||||
|
|
||||||
if (restArg.contains("--null-terminated"))
|
|
||||||
nullTerm = true;
|
|
||||||
|
|
||||||
if (restArg.contains("--string"))
|
|
||||||
{
|
|
||||||
stringData = true;
|
|
||||||
nullTerm = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString outSymbol = finfo.baseName();
|
|
||||||
outSymbol.replace(".", "_");
|
|
||||||
|
|
||||||
QString outFile;
|
|
||||||
|
|
||||||
outFile = getNamedOption(restArg, "-o", finfo.fileName() + ".xxd");
|
|
||||||
outSymbol = getNamedOption(restArg, "--symbol", outSymbol);
|
|
||||||
|
|
||||||
QString dataType = stringData ? "char" : "unsigned char";
|
|
||||||
|
|
||||||
return writeDump(inFile, outFile,
|
|
||||||
dataType, "unsigned int",
|
|
||||||
outSymbol, nullTerm);
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
######################################################################
|
|
||||||
# Automatically generated by qmake (2.01a) Sun Aug 18 13:46:33 2013
|
|
||||||
######################################################################
|
|
||||||
|
|
||||||
TEMPLATE = app
|
|
||||||
TARGET =
|
|
||||||
DEPENDPATH += .
|
|
||||||
INCLUDEPATH += .
|
|
||||||
QT = core
|
|
||||||
|
|
||||||
# Input
|
|
||||||
SOURCES += main.cpp
|
|
Loading…
Add table
Reference in a new issue