forked from microsoft/AirSim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove fstream references from AirSimGameMode, consolidate recording_…
…file related code in to one file
- Loading branch information
Showing
13 changed files
with
265 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,6 @@ | |
"Name": "AirSim", | ||
"Enabled": true | ||
} | ||
] | ||
], | ||
"EngineAssociation": "4.15" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <AirSim.h> | ||
#include "ImageUtils.h" | ||
#include "common/ClockFactory.hpp" | ||
#include "common/common_utils/FileSystem.hpp" | ||
|
||
void RecordingFile::appendRecord(FString image_path, TArray<uint8>& compressedPng, const msr::airlib::PhysicsBody* physics_body) | ||
{ | ||
if (compressedPng.Num() == 0) | ||
return; | ||
|
||
FString filePath = image_path + FString::FromInt(images_saved_) + ".png"; | ||
bool imageSavedOk = FFileHelper::SaveArrayToFile(compressedPng, *filePath); | ||
|
||
// If render command is complete, save image along with position and orientation | ||
|
||
if (!imageSavedOk) | ||
UAirBlueprintLib::LogMessage(TEXT("FAILED to save screenshot to:"), filePath, LogDebugLevel::Failure); | ||
else { | ||
auto kinematics = physics_body->getKinematics(); | ||
|
||
uint64_t timestamp_millis = static_cast<uint64_t>(msr::airlib::ClockFactory::get()->nowNanos() / 1.0E6); | ||
|
||
record_file << timestamp_millis << "\t"; | ||
record_file << kinematics.pose.position.x() << "\t" << kinematics.pose.position.y() << "\t" << kinematics.pose.position.z() << "\t"; | ||
record_file << kinematics.pose.orientation.w() << "\t" << kinematics.pose.orientation.x() << "\t" << kinematics.pose.orientation.y() << "\t" << kinematics.pose.orientation.z() << "\t"; | ||
record_file << "\n"; | ||
|
||
UAirBlueprintLib::LogMessage(TEXT("Screenshot saved to:"), filePath, LogDebugLevel::Success); | ||
images_saved_++; | ||
} | ||
} | ||
|
||
void RecordingFile::startRecording() | ||
{ | ||
if (record_file.is_open()) { | ||
record_file.close(); | ||
UAirBlueprintLib::LogMessage(TEXT("Recording Error"), TEXT("File was already open"), LogDebugLevel::Failure); | ||
} | ||
|
||
std::string fullPath = common_utils::FileSystem::getLogFileNamePath(record_filename, "", ".txt", true); | ||
common_utils::FileSystem::createTextFile(fullPath, record_file); | ||
|
||
if (record_file.is_open()) { | ||
is_recording_ = true; | ||
|
||
UAirBlueprintLib::LogMessage(TEXT("Recording"), TEXT("Started"), LogDebugLevel::Success); | ||
} | ||
else | ||
UAirBlueprintLib::LogMessage("Error creating log file", fullPath.c_str(), LogDebugLevel::Failure); | ||
} | ||
|
||
void RecordingFile::stopRecording() | ||
{ | ||
is_recording_ = false; | ||
if (!record_file.is_open()) { | ||
UAirBlueprintLib::LogMessage(TEXT("Recording Error"), TEXT("File was not open"), LogDebugLevel::Failure); | ||
} | ||
else | ||
record_file.close(); | ||
|
||
UAirBlueprintLib::LogMessage(TEXT("Recording"), TEXT("Stopped"), LogDebugLevel::Success); | ||
} | ||
|
||
bool RecordingFile::isRecording() | ||
{ | ||
return is_recording_; | ||
} | ||
|
||
void RecordingFile::initializeForPlay() | ||
{ | ||
is_recording_ = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "AirBlueprintLib.h" | ||
#include "physics/PhysicsBody.hpp" | ||
|
||
|
||
class RecordingFile { | ||
public: | ||
void appendRecord(FString image_path, TArray<uint8>& compressedPng, const msr::airlib::PhysicsBody* physics_body); | ||
void startRecording(); | ||
void stopRecording(); | ||
bool isRecording(); | ||
void initializeForPlay(); | ||
|
||
private: | ||
std::ofstream record_file; | ||
std::string record_filename = "airsim_rec"; | ||
unsigned int images_saved_ = 0; | ||
bool is_recording_; | ||
}; |
Oops, something went wrong.