Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RetroPlayer: Merge savestate metadata into .sav file #14209

Merged
merged 6 commits into from
Aug 14, 2018

Conversation

garbear
Copy link
Member

@garbear garbear commented Jul 21, 2018

Description

Introduced in #12434, RetroPlayer uses two files for autosave: a .sav file for the memory data, and an .xml file for metadata. This combines both memory data and metadata into a single .sav file:

Chrono Trigger (U) [!].smc   (the ROM)
Chrono Trigger (U) [!].sav   (the state and metadata)

In this PR, FlatBuffers is used to serialize metadata. This library was chosen for performance reasons, as it is the only popular serialization library that allows for zero-copy. Although it requires a native compiler, the target library is headers-only.

Backwards compatibility with XML files was not retained due to the extra code it would take, and RetroPlayer is still alpha software.

As a result of this PR, savestates are several hundred kb smaller, half as many files, and loading/saving should be faster on slow devices due to skipping costly XML operations.

I spent a LONG time on the build system stuff, and I'm not sure if I did everything correctly.

Motivation and Context

First abstraction for the new Saved Games manager.

How Has This Been Tested?

Tested on Windows 7 and OSX.

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

@garbear
Copy link
Member Author

garbear commented Jul 22, 2018

TODO: The savestate needs a version field

(testing depends) jenkins build this please

@garbear
Copy link
Member Author

garbear commented Jul 22, 2018

jenkins build this please

@garbear garbear force-pushed the savestate-metadata branch 2 times, most recently from 363b707 to 8072f5d Compare July 22, 2018 23:53
@garbear
Copy link
Member Author

garbear commented Jul 24, 2018

jenkins build this please

)

core_add_messages(retroplayer_messages)
set(EXTRA_INCLUDES ${EXTRA_INCLUDES} PARENT_SCOPE)

This comment was marked as spam.

This comment was marked as spam.

Copy link
Member

@wsnipex wsnipex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmake stuff doesn't conform to our standards and needs serious changes.

  • move all flatbuffer building to depends
  • fix the findmodule to allow bulding with external and internal flatbuffer and just use FLATBUFFER_INCLUDE_DIR
  • no changes to core_add_library

finally: flatbuffers is not available for several linux distros, incl ubuntu

Copy link
Member

@Rechi Rechi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flatc and flatbuffers has to be added to https://github.com/xbmc/kodi-deps/, so it can be easily build from source (for windows) if needed.

@garbear
Copy link
Member Author

garbear commented Jul 26, 2018

move all flatbuffer building to depends

I think this is the case. BuildFlatBuffers.cmake is not used.

fix the findmodule to allow bulding with external and internal flatbuffer and just use FLATBUFFER_INCLUDE_DIR

Is there an existing example I can learn from?

no changes to core_add_library

How do I make other code depend on the generated headers?

finally: flatbuffers is not available for several linux distros, incl ubuntu

Can we build flatc when not detected, à la TexturePacker?

@Rechi
Copy link
Member

Rechi commented Jul 26, 2018

FFmpeg, Crossguid, Fmt, fstrcmp and RapidJSON can be built internal.

set(FLATBUFFERS_INCLUDE_DIRS ${FLATBUFFERS_INCLUDE_DIR})
include_directories(${CMAKE_BINARY_DIR})
else()
set(FLATBUFFERS_INCLUDE_DIR)

This comment was marked as spam.

set(FLATBUFFERS_INCLUDE_DIR)
endif()

include("${FLATBUFFERS_CMAKE_DIR}/BuildFlatBuffers.cmake")

This comment was marked as spam.

@@ -11,3 +11,4 @@ jsonschemabuilder-1.0.0-win32-3.7z
swig-3.0.10-win32.7z
texturepacker-1.1.1-win32.7z
vswhere-2.2.11-win32.7z
flatc-1.9.0-win32.7z

This comment was marked as spam.

VERSION=1.9.0
SOURCE=v$(VERSION)
ARCHIVE=$(SOURCE).tar.gz
BASE_URL=https://github.com/google/flatbuffers/archive

This comment was marked as spam.

This comment was marked as spam.

ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
PLATFORM = native
TARBALLS_LOCATION = $(ROOT_DIR)
BASE_URL := https://github.com/google/flatbuffers/archive

This comment was marked as spam.


#include "ISavestate.h"

#include "flatbuffers/flatbuffers.h"

This comment was marked as spam.

@jenkins4kodi jenkins4kodi added the Rebase needed PR that does not apply/merge cleanly to current base branch label Jul 27, 2018

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(flatbuffers
DEFAULT_MSG FLATBUFFERS_FLATC_EXECUTABLE FLATBUFFERS_INCLUDE_DIR)

if(FLATBUFFERS_FOUND)
function(FLATBUFFERS_GENERATE_C_HEADERS Name)

This comment was marked as spam.

This comment was marked as spam.

@wsnipex
Copy link
Member

wsnipex commented Jul 30, 2018

@garbear see wsnipex@67e6b8d for some cmake fixes.
Not yet perfect at all, but work for building with internal flatbuffers on linux(without depends)

@jenkins4kodi jenkins4kodi removed the Rebase needed PR that does not apply/merge cleanly to current base branch label Jul 31, 2018
@garbear garbear force-pushed the savestate-metadata branch 2 times, most recently from fd0fe81 to ef86085 Compare July 31, 2018 06:10
@@ -813,3 +813,4 @@ macro(find_addon_xml_in_files)
# Append also versions.h to depends
list(APPEND ADDON_XML_DEPENDS "${CORE_SOURCE_DIR}/xbmc/addons/kodi-addon-dev-kit/include/kodi/versions.h")
endmacro()

This comment was marked as spam.

-DFLATBUFFERS_BUILD_TESTS=OFF \
-DFLATBUFFERS_INSTALL=ON \
-DFLATBUFFERS_BUILD_FLATLIB=OFF \
-DFLATBUFFERS_BUILD_FLATC=$(BUILD_FLATC) \

This comment was marked as spam.

This comment was marked as spam.

@wsnipex
Copy link
Member

wsnipex commented Jul 31, 2018

small fix for external flatbuffers: wsnipex@46527b8

@garbear
Copy link
Member Author

garbear commented Aug 8, 2018

jenkins build this please

1 similar comment
@garbear
Copy link
Member Author

garbear commented Aug 8, 2018

jenkins build this please

@garbear garbear closed this Aug 8, 2018
@garbear garbear reopened this Aug 8, 2018
set_target_properties(retroplayer_messages PROPERTIES FOLDER "Generated Messages"
INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${FLATC_OUTPUTS})
add_dependencies(retroplayer_messages flatbuffers)

This comment was marked as spam.

This comment was marked as spam.

Copy link
Member

@wsnipex wsnipex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only one minor, otherwise looks good to me

else()
find_program(FLATBUFFERS_FLATC_EXECUTABLE NAMES flatc)
find_path(FLATBUFFERS_INCLUDE_DIR NAMES flatbuffers/flatbuffers.h)
set(FLATBUFFERS_MESSAGES_INCLUDE_DIR ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/cores/RetroPlayer/messages CACHE INTERNAL "Generated Flatbuffer headers")

This comment was marked as spam.

This comment was marked as spam.

@garbear
Copy link
Member Author

garbear commented Aug 11, 2018

@wsnipex updated. jenkins build this please

@garbear
Copy link
Member Author

garbear commented Aug 11, 2018

jenkins build this please

1 similar comment
@garbear
Copy link
Member Author

garbear commented Aug 11, 2018

jenkins build this please

@garbear
Copy link
Member Author

garbear commented Aug 11, 2018

jenkins build this please

@garbear
Copy link
Member Author

garbear commented Aug 11, 2018

all green

@garbear
Copy link
Member Author

garbear commented Aug 11, 2018

jenkins build this please

The code was originally placed in games/ to minimize the size of
RetroPlayer, which was crucial to rapidly scaling the player to handle
the rendering system added in the GSoC 2017 shader project.

Code shuffle only. No functional changes.
This transfers ownership of the playback system from the game client to
RetroPlayer. Our goal is to move the memory stream (currently owned by
playback) into a RetroPlayerMemory stream.
Code shuffle only. No functional changes.
@Rechi
Copy link
Member

Rechi commented Aug 14, 2018

Fedora has a flatbuffers package, so documentation has to be adjusted.

This adds the flatc compiler to native depends and the flatbuffer headers
to target depends.
This removes the auxiliary XML metadata file used for savestates. Now,
metadata is serialized into the .sav file using FlatBuffers.
@garbear
Copy link
Member Author

garbear commented Aug 14, 2018

added package to fedora. jenkins build this please

@garbear garbear merged commit fc9faf3 into xbmc:master Aug 14, 2018
@garbear
Copy link
Member Author

garbear commented Aug 14, 2018

thanks @Rechi @wsnipex for all your help getting this in!

@garbear garbear deleted the savestate-metadata branch August 14, 2018 23:19
@Rechi Rechi added this to the Leia 18.0-beta1 milestone Aug 16, 2018
Rechi added a commit that referenced this pull request Apr 8, 2019
[cleanup] remove retroplayer leftovers after #14209
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants