mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-29 17:38:16 +03:00
Implement command-line playtesting (#163)
This commit is contained in:
@@ -7,6 +7,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#include <SDL.h>
|
||||
#include <physfs.h>
|
||||
|
||||
@@ -144,6 +148,28 @@ char *FILESYSTEM_getUserLevelDirectory()
|
||||
void FILESYSTEM_loadFileToMemory(const char *name, unsigned char **mem,
|
||||
size_t *len, bool addnull)
|
||||
{
|
||||
if (strcmp(name, "levels/special/stdin.vvvvvv") == 0) {
|
||||
// this isn't *technically* necessary when piping directly from a file, but checking for that is annoying
|
||||
static std::vector<char> STDIN_BUFFER;
|
||||
static bool STDIN_LOADED = false;
|
||||
if (!STDIN_LOADED) {
|
||||
std::istreambuf_iterator<char> begin(std::cin), end;
|
||||
STDIN_BUFFER.assign(begin, end);
|
||||
STDIN_BUFFER.push_back(0); // there's no observable change in behavior if addnull is always true, but not vice versa
|
||||
STDIN_LOADED = true;
|
||||
}
|
||||
|
||||
size_t length = STDIN_BUFFER.size() - 1;
|
||||
if (len != NULL) {
|
||||
*len = length;
|
||||
}
|
||||
|
||||
++length;
|
||||
*mem = static_cast<unsigned char*>(malloc(length)); // STDIN_BUFFER.data() causes double-free
|
||||
std::copy(STDIN_BUFFER.begin(), STDIN_BUFFER.end(), reinterpret_cast<char*>(*mem));
|
||||
return;
|
||||
}
|
||||
|
||||
PHYSFS_File *handle = PHYSFS_openRead(name);
|
||||
if (handle == NULL)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user