├── .gitignore
├── CMakeLists.txt
├── LICENSE
├── README.md
├── cmake
└── Modules
│ ├── FindGStreamer.cmake
│ ├── FindNPA.cmake
│ └── get-git-revision.cmake
├── include
├── Choice.hpp
├── Effect.hpp
├── GLTexture.hpp
├── Image.hpp
├── Movie.hpp
├── NSBContext.hpp
├── NSBInterpreter.hpp
├── Name.hpp
├── Object.hpp
├── Playable.hpp
├── ResourceMgr.hpp
├── Scrollbar.hpp
├── Text.hpp
├── TextParser.hpp
├── Texture.hpp
├── Variable.hpp
├── Window.hpp
└── npengineversion.hpp.in
└── src
├── Choice.cpp
├── GLTexture.cpp
├── Image.cpp
├── Movie.cpp
├── NSBContext.cpp
├── NSBDebugger.cpp
├── NSBInterpreter.cpp
├── Playable.cpp
├── ResourceMgr.cpp
├── Scrollbar.cpp
├── Text.cpp
├── Texture.cpp
├── Variable.cpp
├── Window.cpp
├── lexer.l
└── parser.y
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files
2 | *.slo
3 | *.lo
4 | *.o
5 | *.obj
6 |
7 | # Compiled Dynamic libraries
8 | *.so
9 | *.dylib
10 | *.dll
11 |
12 | # Compiled Static libraries
13 | *.lai
14 | *.la
15 | *.a
16 | *.lib
17 |
18 | # Executables
19 | *.exe
20 | *.out
21 | *.app
22 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.0)
2 |
3 | # add modules
4 | set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
5 |
6 | # set version
7 | set(LIBNPENGINE_VERSION_MAJOR "0")
8 | set(LIBNPENGINE_VERSION_MINOR "5")
9 | set(LIBNPENGINE_VERSION_PATCH "3")
10 | set(LIBNPENGINE_VERSION
11 | "${LIBNPENGINE_VERSION_MAJOR}.${LIBNPENGINE_VERSION_MINOR}.${LIBNPENGINE_VERSION_PATCH}"
12 | )
13 |
14 | # append git revision if available
15 | include(get-git-revision)
16 | get_git_revision(LIBNPENGINE_VERSION_GIT)
17 | if(NOT "${LIBNPENGINE_VERSION_GIT}" STREQUAL "")
18 | set(LIBNPENGINE_VERSION "${LIBNPENGINE_VERSION}-${LIBNPENGINE_VERSION_GIT}")
19 | endif()
20 |
21 | message(STATUS "Configuring libnpengine version " ${LIBNPENGINE_VERSION})
22 |
23 | # project name and language
24 | project (libnpengine CXX)
25 |
26 | set(CMAKE_BUILD_TYPE Debug)
27 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -Wall")
28 |
29 | # include version number in header
30 | configure_file(${PROJECT_SOURCE_DIR}/include/npengineversion.hpp.in
31 | ${PROJECT_SOURCE_DIR}/include/npengineversion.hpp)
32 |
33 | find_package(NPA REQUIRED)
34 | find_package(GLEW REQUIRED)
35 | find_package(JPEG REQUIRED)
36 | find_package(GStreamer REQUIRED)
37 | find_package(FLEX REQUIRED)
38 | find_package(BISON REQUIRED)
39 | find_package(PNG REQUIRED)
40 | find_package(Threads REQUIRED)
41 | include(FindPkgConfig)
42 |
43 | PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
44 | PKG_SEARCH_MODULE(libpng REQUIRED libpng)
45 | PKG_SEARCH_MODULE(PANGOCAIRO REQUIRED pangocairo)
46 |
47 | string(REPLACE "." ";" VERSION_LIST ${FLEX_VERSION})
48 | list(GET VERSION_LIST 0 FLEX_VERSION_MAJOR)
49 | list(GET VERSION_LIST 1 FLEX_VERSION_MINOR)
50 | list(GET VERSION_LIST 2 FLEX_VERSION_PATCH)
51 | add_definitions(-DFLEX_VERSION_MAJOR=${FLEX_VERSION_MAJOR})
52 | add_definitions(-DFLEX_VERSION_MINOR=${FLEX_VERSION_MINOR})
53 | add_definitions(-DFLEX_VERSION_PATCH=${FLEX_VERSION_PATCH})
54 |
55 | include_directories(
56 | ${PANGOCAIRO_INCLUDE_DIRS}
57 | ${SDL2_INCLUDE_DIRS}
58 | ${NPA_INCLUDE_DIR}
59 | ${GSTREAMER_INCLUDE_DIRS}
60 | ${GSTREAMER_VIDEO_INCLUDE_DIRS}
61 | ${CMAKE_SOURCE_DIR}/include
62 | )
63 |
64 | link_directories(
65 | )
66 |
67 | flex_target(lexer ${CMAKE_SOURCE_DIR}/src/lexer.l ${CMAKE_SOURCE_DIR}/src/Lexer.cpp)
68 | bison_target(parser ${CMAKE_SOURCE_DIR}/src/parser.y ${CMAKE_SOURCE_DIR}/src/Parser.cpp)
69 |
70 | add_library(npengine SHARED
71 | src/Window.cpp
72 | src/NSBInterpreter.cpp
73 | src/ResourceMgr.cpp
74 | src/Texture.cpp
75 | src/Variable.cpp
76 | src/NSBContext.cpp
77 | src/GLTexture.cpp
78 | src/Playable.cpp
79 | src/Movie.cpp
80 | src/Choice.cpp
81 | src/Text.cpp
82 | src/Parser.cpp
83 | src/Lexer.cpp
84 | src/Image.cpp
85 | src/NSBDebugger.cpp
86 | src/Scrollbar.cpp
87 | )
88 |
89 | target_link_libraries(npengine
90 | ${CMAKE_THREAD_LIBS_INIT}
91 | ${SDL2_LIBRARIES}
92 | ${NPA_LIBRARY}
93 | ${GSTREAMER_LIBRARIES}
94 | ${GSTREAMER_APP_LIBRARIES}
95 | ${GSTREAMER_VIDEO_LIBRARIES}
96 | ${PANGOCAIRO_LIBRARIES}
97 | ${JPEG_LIBRARY}
98 | ${GLEW_LIBRARY}
99 | ${PNG_LIBRARIES}
100 | -lGL)
101 |
102 | # install headers and library
103 | install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
104 | DESTINATION include/libnpengine
105 | FILES_MATCHING PATTERN "*.hpp")
106 | install(TARGETS npengine DESTINATION lib)
107 |
108 | # create packages
109 | set(CPACK_GENERATOR "TBZ2")
110 | set(CPACK_PACKAGE_VERSION ${LIBNPENGINE_VERSION})
111 | include(CPack)
112 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | libnpengine
2 | ===========
3 |
4 | libnpengine is a free implementation of Nitroplus visual novel game engine.
5 | It can currently run [Steins;Gate][2] and [few other games][1]. For more information, visit the project [website][3].
6 |
7 | If you need help getting this to compile and run or simply want to chat, join #FGRE @ irc.freenode.net
8 |
9 | [1]: https://github.com/FGRE/chaos-head
10 | [2]: https://github.com/FGRE/steins-gate-new
11 | [3]: http://dev.pulsir.eu/krofna/
--------------------------------------------------------------------------------
/cmake/Modules/FindGStreamer.cmake:
--------------------------------------------------------------------------------
1 | # - Try to find GStreamer and its plugins
2 | # Once done, this will define
3 | #
4 | # GSTREAMER_FOUND - system has GStreamer
5 | # GSTREAMER_INCLUDE_DIRS - the GStreamer include directories
6 | # GSTREAMER_LIBRARIES - link these to use GStreamer
7 | #
8 | # Additionally, gstreamer-base is always looked for and required, and
9 | # the following related variables are defined:
10 | #
11 | # GSTREAMER_BASE_INCLUDE_DIRS - gstreamer-base's include directory
12 | # GSTREAMER_BASE_LIBRARIES - link to these to use gstreamer-base
13 | #
14 | # Optionally, the COMPONENTS keyword can be passed to find_package()
15 | # and GStreamer plugins can be looked for. Currently, the following
16 | # plugins can be searched, and they define the following variables if
17 | # found:
18 | #
19 | # gstreamer-app: GSTREAMER_APP_INCLUDE_DIRS and GSTREAMER_APP_LIBRARIES
20 | # gstreamer-audio: GSTREAMER_AUDIO_INCLUDE_DIRS and GSTREAMER_AUDIO_LIBRARIES
21 | # gstreamer-fft: GSTREAMER_FFT_INCLUDE_DIRS and GSTREAMER_FFT_LIBRARIES
22 | # gstreamer-gl: GSTREAMER_GL_INCLUDE_DIRS and GSTREAMER_GL_LIBRARIES
23 | # gstreamer-mpegts: GSTREAMER_MPEGTS_INCLUDE_DIRS and GSTREAMER_MPEGTS_LIBRARIES
24 | # gstreamer-pbutils: GSTREAMER_PBUTILS_INCLUDE_DIRS and GSTREAMER_PBUTILS_LIBRARIES
25 | # gstreamer-tag: GSTREAMER_TAG_INCLUDE_DIRS and GSTREAMER_TAG_LIBRARIES
26 | # gstreamer-video: GSTREAMER_VIDEO_INCLUDE_DIRS and GSTREAMER_VIDEO_LIBRARIES
27 | #
28 | # Copyright (C) 2012 Raphael Kubo da Costa
29 | #
30 | # Redistribution and use in source and binary forms, with or without
31 | # modification, are permitted provided that the following conditions
32 | # are met:
33 | # 1. Redistributions of source code must retain the above copyright
34 | # notice, this list of conditions and the following disclaimer.
35 | # 2. Redistributions in binary form must reproduce the above copyright
36 | # notice, this list of conditions and the following disclaimer in the
37 | # documentation and/or other materials provided with the distribution.
38 | #
39 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS
40 | # IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
41 | # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS
43 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
45 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
46 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
47 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
48 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
49 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 |
51 | find_package(PkgConfig)
52 |
53 | # Helper macro to find a GStreamer plugin (or GStreamer itself)
54 | # _component_prefix is prepended to the _INCLUDE_DIRS and _LIBRARIES variables (eg. "GSTREAMER_AUDIO")
55 | # _pkgconfig_name is the component's pkg-config name (eg. "gstreamer-1.0", or "gstreamer-video-1.0").
56 | # _library is the component's library name (eg. "gstreamer-1.0" or "gstvideo-1.0")
57 | macro(FIND_GSTREAMER_COMPONENT _component_prefix _pkgconfig_name _library)
58 |
59 | string(REGEX MATCH "(.*)>=(.*)" _dummy "${_pkgconfig_name}")
60 | if ("${CMAKE_MATCH_2}" STREQUAL "" AND (NOT ${GStreamer_FIND_VERSION} STREQUAL ""))
61 | pkg_check_modules(PC_${_component_prefix} "${_pkgconfig_name} >= ${GStreamer_FIND_VERSION}")
62 | else ()
63 | pkg_check_modules(PC_${_component_prefix} ${_pkgconfig_name})
64 | endif ()
65 | set(${_component_prefix}_INCLUDE_DIRS ${PC_${_component_prefix}_INCLUDE_DIRS})
66 |
67 | find_library(${_component_prefix}_LIBRARIES
68 | NAMES ${_library}
69 | HINTS ${PC_${_component_prefix}_LIBRARY_DIRS} ${PC_${_component_prefix}_LIBDIR}
70 | )
71 | endmacro()
72 |
73 | # ------------------------
74 | # 1. Find GStreamer itself
75 | # ------------------------
76 |
77 | # 1.1. Find headers and libraries
78 | FIND_GSTREAMER_COMPONENT(GSTREAMER gstreamer-1.0 gstreamer-1.0)
79 | FIND_GSTREAMER_COMPONENT(GSTREAMER_BASE gstreamer-base-1.0 gstbase-1.0)
80 |
81 | # -------------------------
82 | # 2. Find GStreamer plugins
83 | # -------------------------
84 |
85 | FIND_GSTREAMER_COMPONENT(GSTREAMER_APP gstreamer-app-1.0 gstapp-1.0)
86 | FIND_GSTREAMER_COMPONENT(GSTREAMER_AUDIO gstreamer-audio-1.0 gstaudio-1.0)
87 | FIND_GSTREAMER_COMPONENT(GSTREAMER_FFT gstreamer-fft-1.0 gstfft-1.0)
88 | FIND_GSTREAMER_COMPONENT(GSTREAMER_GL gstreamer-gl-1.0>=1.5.0 gstgl-1.0)
89 | FIND_GSTREAMER_COMPONENT(GSTREAMER_MPEGTS gstreamer-mpegts-1.0>=1.4.0 gstmpegts-1.0)
90 | FIND_GSTREAMER_COMPONENT(GSTREAMER_PBUTILS gstreamer-pbutils-1.0 gstpbutils-1.0)
91 | FIND_GSTREAMER_COMPONENT(GSTREAMER_TAG gstreamer-tag-1.0 gsttag-1.0)
92 | FIND_GSTREAMER_COMPONENT(GSTREAMER_VIDEO gstreamer-video-1.0 gstvideo-1.0)
93 |
94 | # ------------------------------------------------
95 | # 3. Process the COMPONENTS passed to FIND_PACKAGE
96 | # ------------------------------------------------
97 | set(_GSTREAMER_REQUIRED_VARS GSTREAMER_INCLUDE_DIRS GSTREAMER_LIBRARIES GSTREAMER_VERSION GSTREAMER_BASE_INCLUDE_DIRS GSTREAMER_BASE_LIBRARIES)
98 |
99 | foreach (_component ${GStreamer_FIND_COMPONENTS})
100 | set(_gst_component "GSTREAMER_${_component}")
101 | string(TOUPPER ${_gst_component} _UPPER_NAME)
102 |
103 | list(APPEND _GSTREAMER_REQUIRED_VARS ${_UPPER_NAME}_INCLUDE_DIRS ${_UPPER_NAME}_LIBRARIES)
104 | endforeach ()
105 |
106 | include(FindPackageHandleStandardArgs)
107 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(GStreamer REQUIRED_VARS _GSTREAMER_REQUIRED_VARS
108 | VERSION_VAR GSTREAMER_VERSION)
109 |
110 | mark_as_advanced(
111 | GSTREAMER_APP_INCLUDE_DIRS
112 | GSTREAMER_APP_LIBRARIES
113 | GSTREAMER_AUDIO_INCLUDE_DIRS
114 | GSTREAMER_AUDIO_LIBRARIES
115 | GSTREAMER_BASE_INCLUDE_DIRS
116 | GSTREAMER_BASE_LIBRARIES
117 | GSTREAMER_FFT_INCLUDE_DIRS
118 | GSTREAMER_FFT_LIBRARIES
119 | GSTREAMER_GL_INCLUDE_DIRS
120 | GSTREAMER_GL_LIBRARIES
121 | GSTREAMER_INCLUDE_DIRS
122 | GSTREAMER_LIBRARIES
123 | GSTREAMER_MPEGTS_INCLUDE_DIRS
124 | GSTREAMER_MPEGTS_LIBRARIES
125 | GSTREAMER_PBUTILS_INCLUDE_DIRS
126 | GSTREAMER_PBUTILS_LIBRARIES
127 | GSTREAMER_TAG_INCLUDE_DIRS
128 | GSTREAMER_TAG_LIBRARIES
129 | GSTREAMER_VIDEO_INCLUDE_DIRS
130 | GSTREAMER_VIDEO_LIBRARIES
131 | )
132 |
--------------------------------------------------------------------------------
/cmake/Modules/FindNPA.cmake:
--------------------------------------------------------------------------------
1 | # find our libnpa
2 | # when successful, defines:
3 | # - NPA_LIBRARY
4 | # - NPA_FOUND
5 | # - NPA_INCLUDE_DIR
6 | # - NPA_LIBRARY_DIR
7 |
8 | # define the list of search paths for headers and libraries
9 | set(FIND_NPA_PATHS
10 | ${NPA_ROOT}
11 | $ENV{NPA_ROOT}
12 | /usr/local
13 | /usr
14 | /opt/local
15 | /opt
16 | ${CMAKE_SOURCE_DIR}/../libnpa # for krofna's build setup
17 | )
18 |
19 | # find include directory
20 | find_path(NPA_INCLUDE_DIR npaversion.hpp
21 | PATH_SUFFIXES include include/libnpa
22 | PATHS ${FIND_NPA_PATHS}
23 | )
24 |
25 | # TODO: check version number
26 |
27 | # find library
28 | find_library(NPA_LIBRARY
29 | NAMES npa
30 | PATH_SUFFIXES lib64 lib
31 | PATHS ${FIND_NPA_PATHS}
32 | )
33 |
34 | # set result
35 | if (NPA_LIBRARY)
36 | set(NPA_FOUND TRUE)
37 | # directory
38 | get_filename_component(_dir "${NPA_LIBRARY}" PATH)
39 | set(NPA_LIBRARY_DIR "${_dir}" CACHE PATH "NPA library directory" FORCE)
40 | else()
41 | set(NPA_FOUND FALSE)
42 | endif()
43 |
44 | # errors
45 | if(NOT NPA_FOUND)
46 | set(FIND_NPA_ERROR "Could NOT find NPA")
47 | endif()
48 | if (NOT NPA_FOUND)
49 | if(NPA_FIND_REQUIRED)
50 | message(FATAL_ERROR ${FIND_NPA_ERROR})
51 | elseif(NOT NPA_FIND_QUIETLY)
52 | message("${FIND_NPA_ERROR}")
53 | endif()
54 | endif()
55 |
56 | # success
57 | if(NPA_FOUND)
58 | message(STATUS "Found NPA in ${NPA_INCLUDE_DIR}")
59 | endif()
60 |
--------------------------------------------------------------------------------
/cmake/Modules/get-git-revision.cmake:
--------------------------------------------------------------------------------
1 |
2 | # this function returns the git hash of the current checkout, if the 'git'
3 | # command is available, it is a git checkout and it is not a tagged release.
4 | function(get_git_revision _hashvar)
5 | # got git?
6 | if(NOT GIT_FOUND)
7 | find_package(Git QUIET)
8 | endif()
9 | if(GIT_FOUND)
10 | # TODO: look for source directory (for out-of-source builds)?
11 |
12 | # check, if we have a tagged release
13 | execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --exact-match
14 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
15 | RESULT_VARIABLE EXIT_CODE
16 | OUTPUT_QUIET
17 | ERROR_QUIET
18 | )
19 | # it failed => not a tagged revision
20 | if(NOT ${EXIT_CODE} EQUAL 0)
21 | execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short=10 HEAD
22 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
23 | RESULT_VARIABLE EXIT_CODE
24 | OUTPUT_VARIABLE GIT_REV
25 | ERROR_QUIET
26 | OUTPUT_STRIP_TRAILING_WHITESPACE
27 | )
28 | if(${EXIT_CODE} EQUAL 0)
29 | # all good, set hash
30 | set(${_hashvar} "${GIT_REV}" PARENT_SCOPE)
31 | return()
32 | endif()
33 | endif()
34 | endif()
35 | # no git available or any other error above, set to empty string
36 | set(${_hashvar} "" PARENT_SCOPE)
37 | endfunction()
38 |
--------------------------------------------------------------------------------
/include/Choice.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * libnpengine: Nitroplus script interpreter
3 | * Copyright (C) 2014-2016,2018 Mislav Blažević
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser Public License
16 | * along with this program. If not, see .
17 | * */
18 | #ifndef CHOICE_HPP
19 | #define CHOICE_HPP
20 |
21 | #include "Texture.hpp"
22 | #include "Name.hpp"
23 | #include
24 |
25 | class Choice : public Name
26 | {
27 | enum
28 | {
29 | FOCUS_UP,
30 | FOCUS_DOWN,
31 | FOCUS_RIGHT,
32 | FOCUS_LEFT
33 | };
34 |
35 | public:
36 | Choice();
37 |
38 | bool IsSelected(const SDL_Event& Event);
39 | void SetNextFocus(Choice* pNext, const string& Key);
40 | void Reset() { ButtonUp = false; }
41 |
42 | private:
43 | void Cursor(int x, int y, bool& Flag);
44 | void Wheel(int x, int y);
45 | void Arrow(SDL_Keycode sym);
46 | void ChangeFocus(int Index);
47 | int KeyToIndex(const string& Key);
48 |
49 | bool MouseOver;
50 | bool ButtonDown;
51 | bool ButtonUp;
52 | Choice* pNextFocus[4];
53 | };
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/include/Effect.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * libnpengine: Nitroplus script interpreter
3 | * Copyright (C) 2014-2016,2018 Mislav Blažević
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser Public License
16 | * along with this program. If not, see .
17 | * */
18 | #ifndef EFFECT_HPP
19 | #define EFFECT_HPP
20 |
21 | #include
22 | #include
23 | #include "Texture.hpp"
24 | #include "nsbconstants.hpp"
25 |
26 | class Effect
27 | {
28 | public:
29 | Effect() : Tempo(-1), Program(0) { }
30 | ~Effect() { glDeleteObjectARB(Program); }
31 |
32 | protected:
33 | float ApplyTempo(float Progress)
34 | {
35 | switch (Tempo)
36 | {
37 | case Nsb::AXL_1:
38 | return pow(Progress, 2);
39 | case Nsb::AXL_2:
40 | return pow(Progress, 3);
41 | case Nsb::AXL_3:
42 | return pow(Progress, 4);
43 | case Nsb::DXL_1:
44 | return 1.0f - pow(1.0f - Progress, 2);
45 | case Nsb::DXL_2:
46 | return 1.0f - pow(1.0f - Progress, 3);
47 | case Nsb::DXL_3:
48 | return 1.0f - pow(1.0f - Progress, 4);
49 | case Nsb::AXL_AUTO:
50 | return 1.0f - cos(Progress * M_PI * 0.5f);
51 | case Nsb::DXL_AUTO:
52 | return sin(Progress * M_PI * 0.5f);
53 | case Nsb::AXL_DXL:
54 | return 0.5f * (1.0f - cos(Progress * M_PI));
55 | case Nsb::DXL_AXL:
56 | return acos(1.0f - Progress * 2.0f) / M_PI;
57 | }
58 | return Progress;
59 | }
60 |
61 | int32_t Lerp(int32_t Old, int32_t New, float Progress)
62 | {
63 | if (New > Old)
64 | return Old + (New - Old) * ApplyTempo(Progress);
65 | else
66 | return Old - (Old - New) * ApplyTempo(Progress);
67 | }
68 |
69 | void CompileShader(const char* String)
70 | {
71 | if (!GLEW_ARB_fragment_shader)
72 | return;
73 |
74 | GLuint Shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
75 | glShaderSourceARB(Shader, 1, &String, NULL);
76 | glCompileShaderARB(Shader);
77 |
78 | Program = glCreateProgramObjectARB();
79 | glAttachObjectARB(Program, Shader);
80 |
81 | glLinkProgramARB(Program);
82 | glDeleteObjectARB(Shader);
83 | }
84 |
85 | int32_t Tempo;
86 | GLuint Program;
87 | };
88 |
89 | class Tone : public Effect
90 | {
91 | const string MonochromeShader = \
92 | "uniform sampler2D Texture;"
93 | "void main()"
94 | "{"
95 | " vec4 Pixel = texture2D(Texture, gl_TexCoord[0].xy);"
96 | " gl_FragColor = vec4(vec3(Pixel.r + Pixel.g + Pixel.b) / 3.0, Pixel.a);"
97 | "}";
98 | const string NegaPosiShader = \
99 | "uniform sampler2D Texture;"
100 | "void main()"
101 | "{"
102 | " vec4 Pixel = texture2D(Texture, gl_TexCoord[0].xy);"
103 | " gl_FragColor = vec4(vec3(1.0) - Pixel.rgb, Pixel.a);"
104 | "}";
105 | const string KitanoBlueShader = \
106 | "uniform sampler2D Texture;"
107 | "void main()"
108 | "{"
109 | " vec4 Pixel = texture2D(Texture, gl_TexCoord[0].xy);"
110 | " float Intensity = Pixel.r * (27.0 / 255.0) + Pixel.g * (150.0 / 255.0) + Pixel.b * (76.0 / 255.0);"
111 | " vec4 Color = vec4(vec3(Intensity), Pixel.a);"
112 | " Color.gb = clamp(Color.gb + vec2(20.0 / 255.0, 80.0 / 255.0), vec2(0.0, 0.0), vec2(1.0, 1.0));"
113 | " gl_FragColor = Color;"
114 | "}";
115 | const string SepiaShader = \
116 | "uniform sampler2D Texture;"
117 | "void main()"
118 | "{"
119 | " vec4 Pixel = texture2D(Texture, gl_TexCoord[0].xy);"
120 | " float Intensity = Pixel.r * (27.0 / 255.0) + Pixel.g * (150.0 / 255.0) + Pixel.b * (76.0 / 255.0);"
121 | " vec4 Color = vec4(vec3(Intensity), Pixel.a);"
122 | " Color.rg = clamp(Color.rg + vec2(30.0 / 255.0, 30.0 / 255.0), vec2(0.0, 0.0), vec2(1.0, 1.0));"
123 | " gl_FragColor = Color;"
124 | "}";
125 | public:
126 | Tone(int32_t Tone)
127 | {
128 | switch (Tone)
129 | {
130 | case Nsb::NEGA_POSI:
131 | CompileShader(NegaPosiShader.c_str());
132 | break;
133 | case Nsb::MONOCHROME:
134 | CompileShader(MonochromeShader.c_str());
135 | break;
136 | case Nsb::SEPIA:
137 | CompileShader(SepiaShader.c_str());
138 | break;
139 | case Nsb::KITANO_BLUE:
140 | CompileShader(KitanoBlueShader.c_str());
141 | break;
142 | }
143 | }
144 |
145 | void OnDraw()
146 | {
147 | if (!Program)
148 | return;
149 |
150 | glUseProgramObjectARB(Program);
151 | glUniform1iARB(glGetUniformLocationARB(Program, "Texture"), 0);
152 | }
153 | };
154 |
155 | class LerpEffect : public Effect
156 | {
157 | public:
158 | LerpEffect() { }
159 | LerpEffect(int32_t StartX, int32_t StartY) : EndX(StartX), EndY(StartY) { }
160 |
161 | void Reset(int32_t StartX, int32_t EndX, int32_t StartY, int32_t EndY, int32_t Time, int32_t Tempo)
162 | {
163 | this->StartX = StartX;
164 | this->StartY = StartY;
165 | this->EndX = EndX;
166 | this->EndY = EndY;
167 | this->Time = Time;
168 | this->ElapsedTime = 0;
169 | this->Tempo = Tempo;
170 | }
171 |
172 | void Reset(int32_t EndX, int32_t EndY, int32_t Time, int32_t Tempo)
173 | {
174 | Reset(this->EndX, EndX, this->EndY, EndY, Time, Tempo);
175 | }
176 |
177 | float GetProgress()
178 | {
179 | if (ElapsedTime >= Time)
180 | return 1.0f;
181 | return float(ElapsedTime) / float(Time);
182 | }
183 |
184 | void Update(int32_t diff, int32_t& x, int32_t& y)
185 | {
186 | ElapsedTime += diff;
187 | x = Lerp(StartX, EndX, GetProgress());
188 | y = Lerp(StartY, EndY, GetProgress());
189 | }
190 |
191 | int32_t StartX, StartY;
192 | int32_t EndX, EndY;
193 | int32_t ElapsedTime;
194 | int32_t Time;
195 | };
196 |
197 | class RotateEffect : public LerpEffect
198 | {
199 | public:
200 | RotateEffect(int32_t EndA, int32_t Time, int32_t Tempo) : LerpEffect(0, 0)
201 | {
202 | Reset(EndA, 0, Time, Tempo);
203 | }
204 |
205 | void OnDraw(Texture* pTexture, int32_t diff)
206 | {
207 | int32_t ax, ay;
208 | Update(diff, ax, ay);
209 | pTexture->SetAngle(ax);
210 | }
211 | };
212 |
213 | class MoveEffect : public LerpEffect
214 | {
215 | public:
216 | MoveEffect(int32_t EndX, int32_t EndY, int32_t Time, int32_t Tempo) : LerpEffect(0, 0)
217 | {
218 | Reset(EndX, EndY, Time, Tempo);
219 | }
220 |
221 | void OnDraw(Texture* pTexture, int32_t diff)
222 | {
223 | int32_t x, y;
224 | Update(diff, x, y);
225 | pTexture->SetPosition(x, y);
226 | }
227 | };
228 |
229 | class ZoomEffect : public LerpEffect
230 | {
231 | public:
232 | ZoomEffect(int32_t EndX, int32_t EndY, int32_t Time, int32_t Tempo) : LerpEffect(1000, 1000)
233 | {
234 | Reset(EndX, EndY, Time, Tempo);
235 | }
236 |
237 | void OnDraw(Texture* pTexture, int32_t diff)
238 | {
239 | int32_t x, y;
240 | Update(diff, x, y);
241 | pTexture->SetScale(x, y);
242 | }
243 | };
244 |
245 | class FadeEffect : public LerpEffect
246 | {
247 | const string MaskShader = \
248 | "uniform sampler2D Texture;"
249 | "uniform float Alpha;"
250 | "void main()"
251 | "{"
252 | " vec4 Pixel = texture2D(Texture, gl_TexCoord[0].xy);"
253 | " Pixel.a *= Alpha;"
254 | " gl_FragColor = Pixel;"
255 | "}";
256 | public:
257 | FadeEffect()
258 | {
259 | }
260 |
261 | FadeEffect(int32_t EndOpacity, int32_t Time, int32_t Tempo) : LerpEffect(1000, 0)
262 | {
263 | CompileShader(MaskShader.c_str());
264 | Reset(EndOpacity, 0, Time, Tempo);
265 | }
266 |
267 | void OnDraw(int32_t diff)
268 | {
269 | int32_t x, y;
270 | Update(diff, x, y);
271 |
272 | if (!Program)
273 | return;
274 |
275 | glUseProgramObjectARB(Program);
276 | glUniform1fARB(glGetUniformLocationARB(Program, "Alpha"), x * 0.001f);
277 | glUniform1iARB(glGetUniformLocationARB(Program, "Texture"), 0);
278 | }
279 | };
280 |
281 | class MaskEffect : public FadeEffect, GLTexture
282 | {
283 | const string MaskShader = \
284 | "uniform sampler2D Texture;"
285 | "uniform sampler2D Mask;"
286 | "uniform float Alpha;"
287 | "uniform float Boundary;"
288 | "void main()"
289 | "{"
290 | " vec4 Pixel = texture2D(Texture, gl_TexCoord[0].xy);"
291 | " vec4 MaskPixel = texture2D(Mask, gl_TexCoord[0].xy);"
292 | " if (MaskPixel.r - Alpha <= 0.0f) Pixel.a = 1.0f;"
293 | " else if (MaskPixel.r - Alpha - Boundary <= 0.0f) Pixel.a = -(MaskPixel.r - Alpha - Boundary) / Boundary;"
294 | " else Pixel.a = 0.0f;"
295 | " gl_FragColor = Pixel;"
296 | "}";
297 | public:
298 | MaskEffect(const string& Filename, int32_t StartOpacity, int32_t EndOpacity, int32_t Time, int32_t Boundary, int32_t Tempo)
299 | {
300 | CompileShader(MaskShader.c_str());
301 | Reset(Filename, StartOpacity, EndOpacity, Time, Boundary, Tempo);
302 | }
303 |
304 | void Reset(const string& Filename, int32_t StartOpacity, int32_t EndOpacity, int32_t Time, int32_t Boundary, int32_t Tempo)
305 | {
306 | CreateFromFile(Filename, true);
307 | LerpEffect::Reset(StartOpacity, EndOpacity, 0, 0, Time, Tempo);
308 |
309 | if (!Program)
310 | return;
311 |
312 | glUseProgramObjectARB(Program);
313 | glActiveTextureARB(GL_TEXTURE1_ARB);
314 | glBindTexture(GL_TEXTURE_2D, GLTextureID);
315 | glUniform1iARB(glGetUniformLocationARB(Program, "Mask"), 1);
316 | glActiveTextureARB(GL_TEXTURE0_ARB);
317 | glUniform1fARB(glGetUniformLocationARB(Program, "Boundary"), Boundary * 0.001f);
318 | }
319 | };
320 |
321 | class BlurEffect : public Effect, GLTexture
322 | {
323 | const string BlurShader = \
324 | "uniform float Sigma;"
325 | "uniform sampler2D Texture;"
326 | "uniform vec2 Pass;"
327 | "uniform float BlurSize;"
328 | "const float NumSamples = 11.0f;"
329 | "const float PI = 3.14159265f;"
330 | "void main()"
331 | "{"
332 | " vec3 Gaussian = vec3(1.0f / (sqrt(2.0f * PI) * Sigma), exp(-0.5f / (Sigma * Sigma)), 0.0f);"
333 | " Gaussian.z = Gaussian.y * Gaussian.y;"
334 | " vec4 Average = texture2D(Texture, gl_TexCoord[0].xy) * Gaussian.x;"
335 | " float CoeffSum = Gaussian.x;"
336 | " Gaussian.xy *= Gaussian.yz;"
337 | " for (float i = 1.0f; i <= NumSamples; ++i)"
338 | " {"
339 | " Average += texture2D(Texture, gl_TexCoord[0].xy + i * BlurSize * Pass) * Gaussian.x;"
340 | " Average += texture2D(Texture, gl_TexCoord[0].xy - i * BlurSize * Pass) * Gaussian.x;"
341 | " CoeffSum += 2.0f * Gaussian.x;"
342 | " Gaussian.xy *= Gaussian.yz;"
343 | " }"
344 | " gl_FragColor = Average / CoeffSum;"
345 | "}";
346 | public:
347 | BlurEffect() : Framebuffer(GL_INVALID_VALUE)
348 | {
349 | }
350 |
351 | ~BlurEffect()
352 | {
353 | glDeleteFramebuffers(1, &Framebuffer);
354 | }
355 |
356 | bool Create(int Width, int Height, float Sigma)
357 | {
358 | CompileShader(BlurShader.c_str());
359 |
360 | if (!Program)
361 | return false;
362 |
363 | glUseProgramObjectARB(Program);
364 | glUniform1fARB(glGetUniformLocationARB(Program, "Sigma"), Sigma);
365 | glUniform1iARB(glGetUniformLocationARB(Program, "Texture"), 0);
366 |
367 | glGenFramebuffers(1, &Framebuffer);
368 | glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer);
369 | CreateEmpty(Width, Height);
370 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, GLTextureID, 0);
371 |
372 | if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
373 | {
374 | glBindFramebuffer(GL_FRAMEBUFFER, 0);
375 | return false;
376 | }
377 |
378 | glBindFramebuffer(GL_FRAMEBUFFER, 0);
379 | return true;
380 | }
381 |
382 | void OnDraw(GLTexture* pTexture, float* xa, float* ya, float Width, float Height)
383 | {
384 | glUseProgramObjectARB(Program);
385 |
386 | // Switch to FBO
387 | glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer);
388 | glPushAttrib(GL_VIEWPORT_BIT);
389 | glViewport(0, 0, this->Width, this->Height);
390 |
391 | // Flip texture
392 | glMatrixMode(GL_PROJECTION);
393 | glPushMatrix();
394 | glLoadIdentity();
395 | glOrtho(0, this->Width, 0, this->Height, -1, 1);
396 |
397 | // First pass to texture
398 | glUniform1fARB(glGetUniformLocationARB(Program, "BlurSize"), 1.0f / this->Width);
399 | glUniform2fARB(glGetUniformLocationARB(Program, "Pass"), 1.0f, 0.0f);
400 | pTexture->Draw(0, 0, this->Width, this->Height);
401 |
402 | // Switch to window
403 | glBindFramebuffer(GL_FRAMEBUFFER, 0);
404 | glPopAttrib();
405 | glPopMatrix();
406 |
407 | // Second pass to window
408 | glUniform1fARB(glGetUniformLocationARB(Program, "BlurSize"), 1.0f / Height);
409 | glUniform2fARB(glGetUniformLocationARB(Program, "Pass"), 0.0f, 1.0f);
410 | Draw(xa, ya);
411 | }
412 |
413 | GLuint Framebuffer;
414 | };
415 |
416 | #endif
417 |
--------------------------------------------------------------------------------
/include/GLTexture.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * libnpengine: Nitroplus script interpreter
3 | * Copyright (C) 2014-2016,2018 Mislav Blažević
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser Public License
16 | * along with this program. If not, see .
17 | * */
18 | #ifndef GL_TEXTURE_HPP
19 | #define GL_TEXTURE_HPP
20 |
21 | #include
22 | #include "Object.hpp"
23 |
24 | class Image;
25 | class Window;
26 | class Texture;
27 | class GLTexture : virtual public Object
28 | {
29 | friend class Texture;
30 | public:
31 | GLTexture();
32 | virtual ~GLTexture();
33 |
34 | void Draw(int X, int Y, const string& Filename);
35 | void Draw(float X, float Y, float Width, float Height);
36 | void Draw(const float* xa, const float* ya);
37 |
38 | void CreateFromScreen(Window* pWindow);
39 | void CreateFromImage(Image* pImage);
40 | void CreateFromImageClip(Image* pImage, int ClipX, int ClipY, int ClipWidth, int ClipHeight);
41 | void CreateFromColor(int Width, int Height, uint32_t Color);
42 | void CreateFromFile(const string& Filename, bool Mask = false);
43 | void CreateFromFileClip(const string& Filename, int ClipX, int ClipY, int ClipWidth, int ClipHeight);
44 | void CreateEmpty(int Width, int Height);
45 | void Create(uint8_t* Pixels, GLenum Format, int W, int H);
46 |
47 | protected:
48 | void SetSmoothing(bool Set);
49 |
50 | int Width, Height;
51 | GLuint GLTextureID;
52 | };
53 |
54 | #endif
55 |
--------------------------------------------------------------------------------
/include/Image.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * libnpengine: Nitroplus script interpreter
3 | * Copyright (C) 2014-2016,2018 Mislav Blažević
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser Public License
16 | * along with this program. If not, see .
17 | * */
18 | #ifndef IMAGE_HPP
19 | #define IMAGE_HPP
20 |
21 | #include
22 | #include "Object.hpp"
23 |
24 | class Image : public Object
25 | {
26 | public:
27 | Image();
28 | ~Image();
29 |
30 | GLenum GetFormat() const { return Format; }
31 | int GetWidth() const { return Width; }
32 | int GetHeight() const { return Height; }
33 | uint8_t* GetPixels() const { return pPixels; }
34 | void LoadColor(int Width, int Height, uint32_t Color);
35 | void LoadImage(const string& Filename, bool Mask = false);
36 | void LoadScreen(Window* pWindow);
37 |
38 | private:
39 | uint8_t* LoadPNG(uint8_t* pMem, uint32_t Size, uint8_t Format);
40 | uint8_t* LoadJPEG(uint8_t* pMem, uint32_t Size);
41 |
42 | GLenum Format;
43 | int Width, Height;
44 | uint8_t* pPixels;
45 | };
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/include/Movie.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * libnpengine: Nitroplus script interpreter
3 | * Copyright (C) 2013-2016,2018 Mislav Blažević
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser Public License
16 | * along with this program. If not, see .
17 | * */
18 | #ifndef MOVIE_HPP
19 | #define MOVIE_HPP
20 |
21 | #include "Playable.hpp"
22 | #include "Texture.hpp"
23 | #include
24 |
25 | class Movie : public Playable, public Texture
26 | {
27 | friend void LinkPad(GstElement* DecodeBin, GstPad* SourcePad, gpointer Data);
28 | public:
29 | Movie(const string& FileName, Window* pWindow, int32_t Priority, bool Alpha, bool Audio);
30 | ~Movie();
31 |
32 | virtual void Request(int32_t State) { Playable::Request(State); }
33 | void Draw(uint32_t Diff);
34 | private:
35 | void InitVideo(Window* pWindow);
36 | void UpdateSample();
37 |
38 | bool Alpha;
39 | GstElement* VideoBin;
40 | GstAppSink* Appsink;
41 | };
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/include/NSBContext.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * libnpengine: Nitroplus script interpreter
3 | * Copyright (C) 2014-2016,2018 Mislav Blažević
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser Public License
16 | * along with this program. If not, see .
17 | * */
18 | #ifndef NSB_CONTEXT_HPP
19 | #define NSB_CONTEXT_HPP
20 |
21 | #include "Object.hpp"
22 | #include
23 | #include
24 |
25 | class ScriptFile;
26 | class Line;
27 | class Text;
28 | class NSBContext : public Object
29 | {
30 | struct StackFrame
31 | {
32 | ScriptFile* pScript;
33 | uint32_t SourceLine;
34 | };
35 | public:
36 | NSBContext(const string& Name);
37 | ~NSBContext();
38 |
39 | bool Call(ScriptFile* pScript, const string& Symbol);
40 | void Jump(const string& Symbol);
41 | void Break();
42 | const string& GetParam(uint32_t Index);
43 | int GetNumParams();
44 | const string& GetScriptName();
45 | ScriptFile* GetScript();
46 | Line* GetLine();
47 | uint32_t GetLineNumber();
48 | uint32_t GetMagic();
49 | uint32_t Advance();
50 | void Rewind();
51 | void Return();
52 | void PushBreak();
53 | void PopBreak();
54 | void WaitText(Text* pText, int32_t Time);
55 | void WaitAction(Object* pObject, int32_t Time);
56 | void WaitKey(int32_t Time);
57 | void Wait(int32_t Time, bool Interrupt = false);
58 | void Wake();
59 | void TryWake();
60 | void OnClick();
61 | bool IsStarving();
62 | bool IsSleeping();
63 | bool IsActive();
64 | void Start();
65 | void Request(int32_t State);
66 | const string& GetName();
67 | void WriteTrace(ostream& Stream);
68 | void Update(uint32_t Diff);
69 |
70 | private:
71 | StackFrame* GetFrame();
72 |
73 | Text* pText;
74 | Object* pObject;
75 | const string Name;
76 | uint64_t WaitTime;
77 | uint64_t Elapsed;
78 | bool WaitInterrupt;
79 | bool Active;
80 | stack CallStack;
81 | stack BreakStack;
82 | };
83 |
84 | #endif
85 |
--------------------------------------------------------------------------------
/include/NSBInterpreter.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * libnpengine: Nitroplus script interpreter
3 | * Copyright (C) 2014-2016,2018 Mislav Blažević
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser Public License
16 | * along with this program. If not, see .
17 | * */
18 | #ifndef NSB_INTERPRETER_HPP
19 | #define NSB_INTERPRETER_HPP
20 |
21 | #include "Variable.hpp"
22 | #include "Choice.hpp"
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | using namespace std;
29 |
30 | class Stack
31 | {
32 | public:
33 | Stack() : ReadIndex(0), WriteIndex(0)
34 | {
35 | }
36 |
37 | void Push(Variable* pVar)
38 | {
39 | if (WriteIndex == Params.size())
40 | Params.push_back(pVar);
41 | else
42 | Params[WriteIndex] = pVar;
43 | WriteIndex++;
44 | }
45 |
46 | Variable* Top()
47 | {
48 | return Params[ReadIndex];
49 | }
50 |
51 | Variable* TTop()
52 | {
53 | return Params[ReadIndex + 1];
54 | }
55 |
56 | Variable* Pop()
57 | {
58 | return Params[ReadIndex++];
59 | }
60 |
61 | void Begin(size_t Size)
62 | {
63 | WriteIndex -= Size;
64 | ReadIndex = WriteIndex;
65 | }
66 |
67 | void Reset()
68 | {
69 | ReadIndex = WriteIndex = 0;
70 | Params.clear();
71 | }
72 |
73 | private:
74 | vector Params;
75 | size_t ReadIndex;
76 | size_t WriteIndex;
77 | };
78 |
79 | typedef function PosFunc;
80 | struct NSBPosition
81 | {
82 | NSBPosition() : Func(nullptr) { }
83 | PosFunc Func;
84 | bool Relative;
85 | int32_t operator()(int32_t xy, int32_t Old = 0) { return Relative ? Old + Func(xy) : Func(xy); }
86 | };
87 |
88 | class Line;
89 | class Window;
90 | class Texture;
91 | class Playable;
92 | class Scrollbar;
93 | class NSBContext;
94 | class NSBInterpreter
95 | {
96 | struct NSBFunction
97 | {
98 | typedef void (NSBInterpreter::*BuiltinFunc)();
99 | NSBFunction(BuiltinFunc Func, uint8_t NumParams) : Func(Func), NumParams(NumParams) { }
100 | BuiltinFunc Func;
101 | uint8_t NumParams;
102 | };
103 | struct NSBShortcut
104 | {
105 | SDL_Keycode Key;
106 | const string Script;
107 | };
108 | public:
109 | NSBInterpreter(Window* pWindow);
110 | virtual ~NSBInterpreter();
111 |
112 | void ExecuteLocalScript(const string& Filename);
113 | void ExecuteScript(const string& Filename);
114 | void ExecuteScriptThread(const string& Filename);
115 | void StartDebugger();
116 |
117 | void PushEvent(const SDL_Event& Event);
118 | virtual void HandleEvent(const SDL_Event& Event);
119 | void Update(uint32_t Diff);
120 | void Run(int NumCommands);
121 | void RunCommand();
122 |
123 | protected:
124 | void FunctionDeclaration();
125 | void CallFunction();
126 | void CallScene();
127 | void CallChapter();
128 | void CmpLogicalAnd();
129 | void CmpLogicalOr();
130 | void CmpGreater();
131 | void CmpLess();
132 | void CmpGE();
133 | void CmpLE();
134 | void CmpEqual();
135 | void CmpNE();
136 | void NotExpression();
137 | void AddExpression();
138 | void SubExpression();
139 | void MulExpression();
140 | void DivExpression();
141 | void ModExpression();
142 | void Increment();
143 | void Decrement();
144 | void Literal();
145 | void Assign();
146 | void Get();
147 | void ScopeBegin();
148 | void ScopeEnd();
149 | void Return();
150 | void If();
151 | void While();
152 | void WhileEnd();
153 | void Select();
154 | void SelectEnd();
155 | void SelectBreakEnd();
156 | void Break();
157 | void Jump();
158 | void AddAssign();
159 | void SubAssign();
160 | void ModAssign();
161 | void WriteFile();
162 | void ReadFile();
163 | void CreateTexture();
164 | void ImageHorizon();
165 | void ImageVertical();
166 | void Time();
167 | void StrStr();
168 | void Exit();
169 | void CursorPosition();
170 | void MoveCursor();
171 | void Position();
172 | void Wait();
173 | void WaitKey();
174 | void NegaExpression();
175 | void System();
176 | void String();
177 | void VariableValue();
178 | void CreateProcess();
179 | void Count();
180 | void Array();
181 | void SubScript();
182 | void AssocArray();
183 | void ModuleFileName();
184 | void Request();
185 | void SetVertex();
186 | void Zoom();
187 | void Move();
188 | void SetShade();
189 | void DrawToTexture();
190 | void CreateRenderTexture();
191 | void DrawTransition();
192 | void CreateColor();
193 | void LoadImage();
194 | void Fade();
195 | void Delete();
196 | void ClearParams();
197 | void SetLoop();
198 | void SetVolume();
199 | void SetLoopPoint();
200 | void CreateSound();
201 | void RemainTime();
202 | void CreateMovie();
203 | void DurationTime();
204 | void SetFrequency();
205 | void SetPan();
206 | void SetAlias();
207 | void CreateName();
208 | void CreateWindow();
209 | void CreateChoice();
210 | void Case();
211 | void CaseEnd();
212 | void SetNextFocus();
213 | void PassageTime();
214 | void ParseText();
215 | void LoadText();
216 | void WaitText();
217 | void LockVideo();
218 | void Save();
219 | void DeleteSaveFile();
220 | void Conquest();
221 | void ClearScore();
222 | void ClearBacklog();
223 | void SetFont();
224 | void SetShortcut();
225 | void CreateClipTexture();
226 | void ExistSave();
227 | void WaitAction();
228 | void Load();
229 | void SetBacklog();
230 | void CreateText();
231 | void AtExpression();
232 | void Random();
233 | void CreateEffect();
234 | void SetTone();
235 | void DateTime();
236 | void Shake();
237 | void MoviePlay();
238 | void SetStream();
239 | void WaitPlay();
240 | void WaitFade();
241 | void SoundAmplitude();
242 | void Rotate();
243 | void Message();
244 | void Integer();
245 | void CreateScrollbar();
246 | void SetScrollbarValue();
247 | void SetScrollbarWheelArea();
248 | void ScrollbarValue();
249 | void CreateStencil();
250 | void CreateMask();
251 |
252 | float PopFloat();
253 | int32_t PopInt();
254 | string PopString();
255 | NSBPosition PopPos();
256 | NSBPosition PopRelative();
257 | uint32_t PopColor();
258 | int32_t PopRequest();
259 | int32_t PopTone();
260 | int32_t PopEffect();
261 | int32_t PopShade();
262 | int32_t PopTempo();
263 | bool PopBool();
264 | string PopSave();
265 | Variable* PopVar();
266 | Texture* PopTexture();
267 | GLTexture* PopGLTexture();
268 | Playable* PopPlayable();
269 | Scrollbar* PopScrollbar();
270 |
271 | void PushFloat(float Float);
272 | void PushInt(int32_t Int);
273 | void PushString(const string& Str);
274 | void PushVar(Variable* pVar);
275 | void Assign_(int Index);
276 |
277 | void IntUnaryOp(function Func);
278 | void IntBinaryOp(function Func);
279 | void FloatBinaryOp(function Func);
280 | void BoolBinaryOp(function Func);
281 |
282 | void SetInt(const string& Name, int32_t Val);
283 | void SetString(const string& Name, const string& Val);
284 | void SetVar(const string& Name, Variable* pVar);
285 | virtual void OnVariableChanged(const string& Name);
286 | int32_t GetInt(const string& Name);
287 | string GetString(const string& Name);
288 | bool GetBool(const string& Name);
289 | bool ToBool(Variable* pVar);
290 | Variable* GetVar(const string& Name);
291 | Object* GetObject(const string& Name);
292 | template T* Get(const string& Name);
293 | void CallFunction_(NSBContext* pThread, const string& Symbol);
294 | void CallScriptSymbol(const string& Prefix);
295 | void CallScript(const string& Filename, const string& Symbol);
296 | void CallScriptThread(const string& Filename, const string& Symbol);
297 | void Call(uint16_t Magic);
298 | bool SelectEvent();
299 | void AddThread(NSBContext* pThread);
300 | void RemoveThread(NSBContext* pThread);
301 | void ProcessKey(int Key, const string& Val);
302 | void ProcessButton(int button, const string& Val);
303 |
304 | void DebuggerMain();
305 | void Inspect(int32_t n);
306 | void DbgBreak(bool Break);
307 | void DebuggerTick();
308 | void PrintVariable(Variable* pVar);
309 | void SetBreakpoint(const string& Script, int32_t LineNumber);
310 | thread* pDebuggerThread;
311 | bool LogCalls;
312 | bool DbgStepping;
313 | bool RunInterpreter;
314 | list> Breakpoints;
315 |
316 | bool SkipHack;
317 | bool ThreadsModified;
318 | SDL_Event Event;
319 | queue Events;
320 | Window* pWindow;
321 | NSBContext* pContext;
322 | vector Builtins;
323 | Stack Params;
324 | vector Shortcuts;
325 | vector Scripts;
326 | list Threads;
327 | Holder VariableHolder;
328 | ObjectHolder_t ObjectHolder;
329 | };
330 |
331 | template T* NSBInterpreter::Get(const string& Name)
332 | {
333 | return dynamic_cast(GetObject(Name));
334 | }
335 |
336 | #endif
337 |
--------------------------------------------------------------------------------
/include/Name.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * libnpengine: Nitroplus script interpreter
3 | * Copyright (C) 2014-2016,2018 Mislav Blažević
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser Public License
16 | * along with this program. If not, see .
17 | * */
18 | #ifndef NAME_HPP
19 | #define NAME_HPP
20 |
21 | #include "Object.hpp"
22 |
23 | struct Name : Object
24 | {
25 | };
26 |
27 | struct Window_t : Name
28 | {
29 | int32_t Priority, X, Y, Width, Height;
30 | };
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/include/Object.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * libnpengine: Nitroplus script interpreter
3 | * Copyright (C) 2014-2016,2018 Mislav Blažević
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser Public License
16 | * along with this program. If not, see .
17 | * */
18 | #ifndef OBJECT_HPP
19 | #define OBJECT_HPP
20 |
21 | #include "ResourceMgr.hpp"
22 | #include "nsbconstants.hpp"
23 | #include
24 |
25 | struct Object;
26 | class ObjectHolder_t : private Holder