Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
0d9756f
Make Unreal plugin compiable
JBenda Jul 17, 2022
8d4db76
Fixes broken output formatting
JBenda Jul 21, 2022
7946df5
Added get and set var for runtime
JBenda Jul 21, 2022
ad03ea0
Fixed syntax errors
JBenda Jul 22, 2022
19cb971
fixed unreal syntax errors
JBenda Jul 22, 2022
c078914
Change BeginPlay order to load story first
JBenda Jul 27, 2022
22038b5
Successfull build first blueprint Int application in unreal
JBenda Jul 27, 2022
715f29c
Add ink story to show different unreal interaction
JBenda Jul 28, 2022
219b16c
Start reworking the event system
JBenda Jul 28, 2022
522e13b
Set correct _last_char for get_alloc output
JBenda Jul 30, 2022
a5e38c3
Add *.ink loading support for unreal
JBenda Jul 30, 2022
9c7fe25
Uses output.get() instead of stream operator
JBenda Jul 30, 2022
56e2aee
some formation for example story
JBenda Jul 30, 2022
71cfc65
Fixing SetGlobalVariable to support Strings
JBenda Jul 31, 2022
6337046
Find notation for unreal to create GetGlobalVariable
JBenda Jul 31, 2022
94bfca4
Fix indention
JBenda Aug 5, 2022
54c31f7
Apply more unreal fixes
JBenda Aug 5, 2022
3bbcf48
add fallback but not working if not defined
JBenda Jul 12, 2022
f37d656
Add fallback for external functions
JBenda Jul 12, 2022
1703ed5
fix referencing in error detection
JBenda Jul 12, 2022
5e03e9c
Make ex_fn_not_found check work on empty stack
JBenda Jul 13, 2022
182e5c2
Fixed out of order definition
JBenda Aug 16, 2022
f0c569a
clean
JBenda Aug 16, 2022
87f36ed
Set expected string
JBenda Aug 16, 2022
f147bf8
Adapt README
JBenda Aug 16, 2022
37ae541
Update Policy for cmake version 3.24.1
JBenda Aug 24, 2022
fcb683c
Check cmake version before setting policy
JBenda Aug 24, 2022
0221044
Fixed wrong forget function of restorable_stack
JBenda Oct 14, 2022
7666879
Add interface for creating and loading snapshots
JBenda Jul 5, 2022
43c3d5b
More snapshot magic
JBenda Jul 7, 2022
a90088c
Add snap functions
JBenda Jul 8, 2022
d7d23a1
Can load globals, start loading runner
JBenda Jul 11, 2022
460a81b
can store and load
JBenda Jul 11, 2022
0d65981
Add some docu
JBenda Jul 11, 2022
aa21c19
fix wrong order of const ovrride
JBenda Jul 13, 2022
1ad5406
Fix access to union to conform with mvsc
JBenda Jul 13, 2022
888c39a
TEST commit
JBenda Jul 13, 2022
4e15180
Fiddling with msvc error
JBenda Jul 13, 2022
779e935
Next try
JBenda Jul 13, 2022
8ac52e5
Next
JBenda Jul 13, 2022
bd5f48f
More try
JBenda Jul 13, 2022
045c300
Adapt to msvc for c++17
JBenda Jul 14, 2022
87303cd
Merge branch 'enhanment/add_snapshot_functionallity' into feature/Unr…
JBenda Nov 16, 2022
4933f79
Fixes minore warnings
JBenda Nov 16, 2022
9f2c751
Start implementing UE interface
JBenda Nov 16, 2022
83d3783
Translate Snapshot to UE
JBenda Nov 17, 2022
7e245c2
fixed dynimac tag list
JBenda Apr 30, 2023
0f87359
add missing test file
JBenda Apr 30, 2023
43d08a5
Fixes PRNG and implement seed interface for runner
JBenda Apr 30, 2023
06ead58
Make list available to modifications
JBenda May 1, 2023
9abd00e
Access and modify lists, WITH memory leak
JBenda May 1, 2023
f64bb15
Add GC for lists_table and for lists accessed with get_var
JBenda May 2, 2023
0ac3a96
Bump C++ version
JBenda May 2, 2023
c822526
Merge branch 'feature/fallbackfunctions' into feature/Unreal_fixes
JBenda May 2, 2023
9a70126
Add support for tagged choices and new tag syntax
JBenda Jun 26, 2023
49aa9cf
bump inklecate version
JBenda Jun 26, 2023
0df2392
Fixes for UE5.2
JBenda Jul 7, 2023
14cdeaf
Added missing casts to bool
JBenda Jul 11, 2023
eaa688a
Fix: Out of bound access in string cleanup
JBenda Jul 13, 2023
d41c02e
Further Unreal 5.2 related fixes
JBenda Jul 14, 2023
6a91e79
Rename UChoice to UInkChoice
JBenda Jul 14, 2023
ec3620a
update READEM
JBenda Jul 12, 2023
dafc43b
Update Readme and bump inklecate version
JBenda Jul 15, 2023
f855d59
Add Observers to inkcpp
JBenda Jul 16, 2023
45333c7
Add doxygen Docu
JBenda Jul 16, 2023
767f60b
Migrate to unreal
JBenda Jul 26, 2023
b7bcdbd
Fixes to make plugin compile
JBenda Jul 26, 2023
480ab30
Delete temporary json ink file
JBenda Aug 9, 2023
d0ca948
Bump InkcppVersion
JBenda Sep 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ jobs:
- os: macos-latest
artifact: macos
name: MacOSX
inklecate_url: https://github.com/inkle/ink/releases/download/0.9.0/inklecate_mac.zip
inklecate_url: https://github.com/inkle/ink/releases/download/v1.1.1/inklecate_mac.zip
proof: false
- os: windows-latest
artifact: win64
name: Windows x64
inklecate_url: https://github.com/inkle/ink/releases/download/v1.0.0/inklecate_windows.zip
inklecate_url: https://github.com/inkle/ink/releases/download/v1.1.1/inklecate_windows.zip
proof: false
- os: "ubuntu-20.04"
artifact: linux
name: Linux x64
inklecate_url: https://github.com/inkle/ink/releases/download/v1.0.0/inklecate_linux.zip
inklecate_url: https://github.com/inkle/ink/releases/download/v1.1.1/inklecate_linux.zip
proof: true

steps:
Expand Down
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ enable_testing()

# Project setup
project(inkcpp VERSION 0.1)
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_INSTALL_LIBRARY_DIR lib)
SET(CMAKE_INSTALL_INCLUDE_DIR include)
Expand All @@ -18,7 +18,6 @@ add_subdirectory(inkcpp_test)
add_subdirectory(unreal)


get_target_property(TEE inkcpp PUBLIC_HEADER)
install(TARGETS inkcpp inkcpp_compiler inkcpp_shared
EXPORT inkcppTarget
ARCHIVE DESTINATION "lib/ink"
Expand Down Expand Up @@ -57,3 +56,11 @@ set(CPACK_GENERATOR "ZIP")
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_GROUPING IGNORE)
include(CPack)

find_package(Doxygen)
if (DOXYGEN_FOUND)
set(DOXYGEN_PROJECT_NAME ${PROJECT_NAME})
doxygen_add_docs(doc ${PROJECT_SOURCE_DIR} COMMENT "Generate docs")
else(DOXYGEN_FOUND)
message("Doxygen needed to generate documntation!")
endif(DOXYGEN_FOUND)
34 changes: 9 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,16 @@ thread->choose(0);
```

## Current Status
Run `inkcpp_cl.exe -p myfile.json` to execute a compiled Ink JSON file in play mode. It can also operate on `.ink` files but `inklecate.exe` must me in the same folder or in the PATH.

Run `inkcpp_cl.exe -p myfile.json` to execute a compiled Ink JSON file in play mode. It can also operate on `.ink` files but `inklecate.exe` must be in the same folder or in the PATH.
`inklecate` can be downloaded from the official [release page](https://github.com/inkle/ink/releases) and will be downloaded from CMake at configure time (located at `build/unreal/inkcpp/Resources/inklecate`).

Without the `-p` flag, it'll just compile the JSON/Ink file into InkCPP's binary format (see the Wiki on GitHub).

Many, but not all features of the Ink language are supported (see Glaring Omissions below), but be warned, this runtime is still highly unstable. I am currently working on getting it to pass all the unit tests on [ink-proof](https://github.com/chromy/ink-proof).

* Temporary and global variables
* Int, String, or Divert values
* Eval stack (`ev`, `/ev`), String stack (`str`, `/str`)
* Choices (support for both `*` and `+` and conditional choices)
* Diverts (variable and fixed, conditional and normal)
* All mathematical operators (`+`, `<=`, etc.). String equality not supported.
* Glue
* Visit and read counts (`visits` and `CNT?` commands).
* `seq` command and all sequence types (stopping, cycle, shuffle)
* Global store that can be shared between runners
* External function binding (no fallback support yet)
* Tunnels and internal functions
* Ink threads (probably incredibly unstable though)
All features of ink 1.1 are supported, and checked with [ink-proof](https://github.com/chromy/ink-proof).

Big features missing compared to the `C#` implementation are:
* stable Ink Thread support

## Configuring and Building (CMake)

Expand All @@ -79,6 +70,8 @@ To configure the project...

CMake will then generate the necessary build files for your environment. By default, it generates Visual Studio projects and solutions on Windows and Makefiles on Mac and Linux. You can change this using CMake's command line options (see `cmake --help`). It supports pretty much anything.

The documentation can be build iff Doxygen is installed with `cmake --build . --target doc`. The documentation can then be found in at `html/index.html`.

To build, either run the generated buildfiles OR you can use `cmake --build . --config <Release|Debug>` from the build folder to automatically execute the relevant toolchain.

For a more in depth installation description please checkout the (wiki)[https://github.com/brwarner/inkcpp/wiki/building].
Expand Down Expand Up @@ -130,15 +123,6 @@ Code for the Unreal plugin is located in the `unreal` directory. In order to ins

I am currently working toward a 1.0 release. You can track my progress here: https://github.com/brwarner/inkcpp/projects/1

### Glaring Omissions

The big things we're missing right now are:

* Fallback functions for externals.
* Variable observers
* Lists and whatever cool, crazy stuff Ink has been adding recently.
* Robust tests using ink-proof.

## Dependencies
The compiler depends on Nlohmann's JSON library and the C++ STL.

Expand Down
19 changes: 16 additions & 3 deletions inkcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

list(APPEND SOURCES
collections/restorable.h
collections/restorable.cpp
array.h
choice.cpp
functional.cpp
Expand All @@ -13,19 +11,33 @@ list(APPEND SOURCES
runner_impl.h runner_impl.cpp
simple_restorable_stack.h stack.h stack.cpp
story_impl.h story_impl.cpp
snapshot_impl.h snapshot_impl.cpp snapshot_interface.h
story_ptr.cpp
system.cpp
value.h value.cpp
tuple.hpp
string_table.h string_table.cpp avl_array.h
list_table.h list_table.cpp
list_impl.h list_impl.cpp
operations.h operation_bases.h
list_operations.h list_operations.cpp
container_operations.h container_operations.cpp
numeric_operations.h numeric_operations.cpp
string_operations.h string_operations.cpp
string_operations.cpp
numeric_operations.cpp
casting.h
executioner.h
string_utils.h
header.cpp
random.h
)
list(APPEND COLLECTION_SOURCES
collections/restorable.h
collections/restorable.cpp
)
source_group(Collections REGULAR_EXPRESSION collections/.*)
add_library(inkcpp ${SOURCES})
add_library(inkcpp ${SOURCES} ${COLLECTION_SOURCES})
target_include_directories(inkcpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
Expand All @@ -42,3 +54,4 @@ target_compile_features(inkcpp PUBLIC cxx_std_17)
# Unreal installation
install(DIRECTORY "include/" DESTINATION "inkcpp/Source/inkcpp/Public/ink/" COMPONENT unreal EXCLUDE_FROM_ALL)
install(FILES ${SOURCES} DESTINATION "inkcpp/Source/inkcpp/Private/ink/" COMPONENT unreal EXCLUDE_FROM_ALL)
install(FILES ${COLLECTION_SOURCES} DESTINATION "inkcpp/Source/inkcpp/Private/ink/collections/" COMPONENT unreal EXCLUDE_FROM_ALL)
92 changes: 82 additions & 10 deletions inkcpp/array.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#pragma once

#include "system.h"
#include "traits.h"
#include "snapshot_interface.h"

namespace ink::runtime::internal
{
template<typename T, bool dynamic, size_t initialCapacity>
class managed_array {
class managed_array : snapshot_interface {
public:
managed_array() : _capacity{initialCapacity}, _size{0}{
managed_array() : _static_data{}, _capacity{ initialCapacity }, _size{ 0 }{
if constexpr (dynamic) {
_dynamic_data = new T[initialCapacity];
}
Expand Down Expand Up @@ -42,17 +44,50 @@ namespace ink::runtime::internal
if constexpr (dynamic) {
if (_size == _capacity) { extend(); }
} else {
ink_assert(_size <= _capacity, "Stack Overflow!");
inkAssert(_size <= _capacity, "Stack Overflow!");
/// FIXME silent fail!!
}
return data()[_size++];
}
void clear() { _size = 0; }
void resize(size_t size) {
ink_assert(size <= _size, "Only allow to reduce size");
if constexpr (dynamic) {
if (size > _capacity) {
extend(size);
}
} else {
inkAssert(size <= _size, "Only allow to reduce size");
}
_size = size;
}

void extend();
void extend(size_t capacity = 0);

size_t snap(unsigned char* data, const snapper&) const override
{
inkAssert(!is_pointer<T>{}(), "here is a special case oversight");
unsigned char* ptr = data;
bool should_write = data != nullptr;
ptr = snap_write(ptr, _size, should_write );
for(const T& e : *this) {
ptr = snap_write(ptr, e, should_write );
}
return ptr - data;
}
const unsigned char* snap_load(const unsigned char* ptr, const loader&) override
{
decltype(_size) size;
ptr = snap_read(ptr, size);
if constexpr (dynamic) {
resize(size);
} else {
inkAssert(size <= initialCapacity, "capacity of non dynamic array is to small vor snapshot!");
}
for (T& e : *this) {
ptr = snap_read(ptr, e);
}
return ptr;
}
private:

if_t<dynamic, char, T> _static_data[dynamic ? 1 : initialCapacity];
Expand All @@ -62,10 +97,12 @@ namespace ink::runtime::internal
};

template<typename T, bool dynamic, size_t initialCapacity>
void managed_array<T, dynamic, initialCapacity>::extend()
void managed_array<T, dynamic, initialCapacity>::extend(size_t capacity)
{
static_assert(dynamic, "Can only extend if array is dynamic!");
size_t new_capacity = 1.5f * _capacity;
size_t new_capacity = capacity > _capacity
? capacity
: 1.5f * _capacity;
if (new_capacity < 5) { new_capacity = 5; }
T* new_data = new T[new_capacity];

Expand All @@ -79,7 +116,7 @@ namespace ink::runtime::internal
}

template<typename T>
class basic_restorable_array
class basic_restorable_array : public snapshot_interface
{
public:
basic_restorable_array(T* array, size_t capacity, T nullValue)
Expand Down Expand Up @@ -116,6 +153,10 @@ namespace ink::runtime::internal
// Resets all values and clears any save points
void clear(const T& value);

// snapshot interface
virtual size_t snap(unsigned char* data, const snapper&) const override;
virtual const unsigned char* snap_load(const unsigned char* data, const loader&) override;

protected:
inline T* buffer() { return _array; }
void set_new_buffer(T* buffer, size_t capacity) {
Expand Down Expand Up @@ -144,6 +185,37 @@ namespace ink::runtime::internal
const T _null;
};

template<typename T>
inline size_t basic_restorable_array<T>::snap(unsigned char* data, const snapper& snapper) const
{
unsigned char* ptr = data;
bool should_write = data != nullptr;
ptr = snap_write(ptr, _saved, should_write );
ptr = snap_write(ptr, _capacity, should_write );
ptr = snap_write(ptr, _null, should_write );
for(size_t i = 0; i < _capacity; ++i) {
ptr = snap_write(ptr, _array[i], should_write );
ptr = snap_write(ptr, _temp[i], should_write );
}
return ptr - data;
}

template<typename T>
inline const unsigned char* basic_restorable_array<T>::snap_load(const unsigned char* data, const loader& loader)
{
auto ptr = data;
ptr = snap_read(ptr, _saved);
ptr = snap_read(ptr, _capacity);
T null;
ptr = snap_read(ptr, null);
inkAssert(null == _null, "null value is different to snapshot!");
for(size_t i = 0; i < _capacity; ++i) {
ptr = snap_read(ptr, _array[i]);
ptr = snap_read(ptr, _temp[i]);
}
return ptr;
}

template<typename T>
inline void basic_restorable_array<T>::set(size_t index, const T& value)
{
Expand Down Expand Up @@ -238,7 +310,7 @@ namespace ink::runtime::internal
};

template<typename T>
class allocated_restorable_array : public basic_restorable_array<T>
class allocated_restorable_array final : public basic_restorable_array<T>
{
using base = basic_restorable_array<T>;
public:
Expand Down Expand Up @@ -275,7 +347,7 @@ namespace ink::runtime::internal
this->set_new_buffer(_buffer, new_capacity);
}

~allocated_restorable_array()
virtual ~allocated_restorable_array()
{
if(_buffer) {
delete[] _buffer;
Expand Down
Loading