Skip to content

Commit

Permalink
[deepmind, public] Unify all "file reader override" function type def…
Browse files Browse the repository at this point in the history
…initions.

Apart from the conceptual cleanup, this also avoids mismatched language linkage.
  • Loading branch information
tkoeppe committed Jan 22, 2019
1 parent cb1289b commit 4dbec8d
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 23 deletions.
3 changes: 1 addition & 2 deletions deepmind/engine/callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ extern "C" {

int dmlab_create_context(
const char* runfiles_path, DeepmindContext* ctx,
bool (*file_reader_override)(const char* file_name, char** buff,
std::size_t* size),
DeepmindFileReaderType* file_reader_override,
const DeepMindReadOnlyFileSystem* read_only_file_system,
const char* temp_folder) {
lua::Vm lua_vm = lua::CreateVm();
Expand Down
3 changes: 1 addition & 2 deletions deepmind/engine/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,7 @@ lua::NResultsOr ModelModule(lua_State* L) {

Context::Context(lua::Vm lua_vm, const char* executable_runfiles,
const DeepmindCalls* calls, DeepmindHooks* hooks,
bool (*file_reader_override)(const char* file_name,
char** buff, size_t* size),
DeepmindFileReaderType* file_reader_override,
const DeepMindReadOnlyFileSystem* read_only_file_system,
const char* temp_folder)
: lua_vm_(std::move(lua_vm)),
Expand Down
3 changes: 1 addition & 2 deletions deepmind/engine/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ class Context {
const char* executable_runfiles,
const DeepmindCalls* calls,
DeepmindHooks* hooks,
bool (*file_reader_override)(const char* file_name, char** buff,
std::size_t* size),
DeepmindFileReaderType* file_reader_override,
const DeepMindReadOnlyFileSystem* read_only_file_system,
const char* temp_folder);

Expand Down
10 changes: 6 additions & 4 deletions deepmind/engine/context_game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,12 @@ double CanonicalAngle360(double angle) {

} // namespace

ContextGame::ContextGame(const char* executable_runfiles,
const DeepmindCalls* deepmind_calls, Reader* file_reader_override,
const DeepMindReadOnlyFileSystem* read_only_file_system,
std::string temp_folder)
ContextGame::ContextGame(
const char* executable_runfiles,
const DeepmindCalls* deepmind_calls,
DeepmindFileReaderType* file_reader_override,
const DeepMindReadOnlyFileSystem* read_only_file_system,
std::string temp_folder)
: deepmind_calls_(deepmind_calls),
map_finished_(false),
player_view_{},
Expand Down
18 changes: 10 additions & 8 deletions deepmind/engine/context_game.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ struct PlayerView {
// Receive calls from lua_script.
class ContextGame {
public:
// Optional override for reading contents of a file.
using Reader = bool(const char* file_name, char** buff, std::size_t* size);
ContextGame(
const char* executable_runfiles,
const DeepmindCalls* deepmind_calls,
DeepmindFileReaderType* file_reader_override,
const DeepMindReadOnlyFileSystem* read_only_file_system,
std::string temp_folder);

ContextGame(const char* executable_runfiles,
const DeepmindCalls* deepmind_calls, Reader* file_reader_override,
const DeepMindReadOnlyFileSystem* read_only_file_system,
std::string temp_folder);
~ContextGame();

// Returns an event module. A pointer to ContextGame must exist in the up
Expand Down Expand Up @@ -106,7 +106,9 @@ class ContextGame {
return velocity_smoother_.velocity();
}

Reader* FileReaderOverride() { return file_reader_override_; }
DeepmindFileReaderType* FileReaderOverride() {
return file_reader_override_;
}

const DeepMindReadOnlyFileSystem* ReadOnlyFileSystem() const {
return &read_only_file_system_;
Expand Down Expand Up @@ -142,7 +144,7 @@ class ContextGame {
std::string executable_runfiles_;

// Optional override for reading contents of a file.
Reader* file_reader_override_;
DeepmindFileReaderType* file_reader_override_;

// Readonly filesystem for reading partial contents of a file.
DeepMindReadOnlyFileSystem read_only_file_system_;
Expand Down
6 changes: 3 additions & 3 deletions deepmind/include/deepmind_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ struct DeepmindContext_s {
// size of the file and after use 'buff' must be freed with 'free'. Otherwise
// returns false.
int dmlab_create_context(
const char* runfiles_path, DeepmindContext* ctx,
bool (*file_reader_override)(const char* file_name, char** buff,
size_t* size),
const char* runfiles_path,
DeepmindContext* ctx,
DeepmindFileReaderType* file_reader_override,
const DeepMindReadOnlyFileSystem* read_only_file_system,
const char* temp_folder);

Expand Down
4 changes: 2 additions & 2 deletions public/dmlab.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ struct DeepMindLabLaunchParams_s {
// whether the file 'file_name' was read successfully and if so 'buff' points
// to the content and 'size' contains the size of the file and after use
// 'buff' must be freed with 'free'. Otherwise returns false.
bool (*file_reader_override)(const char* file_name, char** buff,
size_t* size);
DeepmindFileReaderType* file_reader_override;

const char* optional_temp_folder;

// Optional readonly filesystem. Set null to use local file operations.
Expand Down
3 changes: 3 additions & 0 deletions public/file_reader_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ extern "C" {
typedef struct DeepMindReadOnlyFileSystem_s DeepMindReadOnlyFileSystem;
typedef void* DeepMindReadOnlyFileHandle;

typedef bool (DeepmindFileReaderType)(const char* file_name, char** buff,
size_t* size);

// These are optional function pointers. If null they will not be used and the
// local filesystem is used instead.
//
Expand Down

0 comments on commit 4dbec8d

Please sign in to comment.