Adding save fetch capabilities.
This commit is contained in:
parent
97db819b1e
commit
4dfdd41c08
@ -31,6 +31,8 @@ struct msClientConnectionData {
|
|||||||
pthread_mutex_t *mutexSaveRequests;
|
pthread_mutex_t *mutexSaveRequests;
|
||||||
//! The number of save requests.
|
//! The number of save requests.
|
||||||
size_t saveRequestsLen;
|
size_t saveRequestsLen;
|
||||||
|
//! The number of frame.
|
||||||
|
size_t numberFrame;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +15,7 @@ msClientConnectionDataNew(size_t numberOfThread, int clientFd) {
|
|||||||
data->mutexSaveRequests = malloc(sizeof *data->mutexSaveRequests);
|
data->mutexSaveRequests = malloc(sizeof *data->mutexSaveRequests);
|
||||||
data->saveRequests = NULL;
|
data->saveRequests = NULL;
|
||||||
data->saveRequestsLen = 0;
|
data->saveRequestsLen = 0;
|
||||||
|
data->numberFrame = 0;
|
||||||
data->lastFrameDate = calloc(sizeof *data->lastFrameDate, 1);
|
data->lastFrameDate = calloc(sizeof *data->lastFrameDate, 1);
|
||||||
pthread_mutex_init(data->mutexSendPacket, NULL);
|
pthread_mutex_init(data->mutexSendPacket, NULL);
|
||||||
pthread_mutex_init(data->mutexPressKey, NULL);
|
pthread_mutex_init(data->mutexPressKey, NULL);
|
||||||
|
@ -60,6 +60,10 @@ msCoreControllerLoadGame (const unsigned char *rom, size_t rom_len,
|
|||||||
mCoreConfigSetIntValue(&core->config, "videoSync", 1);
|
mCoreConfigSetIntValue(&core->config, "videoSync", 1);
|
||||||
|
|
||||||
core->desiredVideoDimensions(core, &width, &height);
|
core->desiredVideoDimensions(core, &width, &height);
|
||||||
|
if (core->platform(core) == mPLATFORM_GB) {
|
||||||
|
width = 160;
|
||||||
|
height = 144;
|
||||||
|
}
|
||||||
color_t *outputBuffer = malloc((sizeof *outputBuffer) * width * height);
|
color_t *outputBuffer = malloc((sizeof *outputBuffer) * width * height);
|
||||||
printf("controller->outputBuffer width: %u\n", width);
|
printf("controller->outputBuffer width: %u\n", width);
|
||||||
core->setVideoBuffer(core, outputBuffer, width);
|
core->setVideoBuffer(core, outputBuffer, width);
|
||||||
@ -87,7 +91,7 @@ mCoreThreadAfterStart(struct mCoreThread *threadContext) {
|
|||||||
struct msClientConnectionData *data = (struct msClientConnectionData *)threadContext->userData;
|
struct msClientConnectionData *data = (struct msClientConnectionData *)threadContext->userData;
|
||||||
struct msCoreController *coreController = data->coreController;
|
struct msCoreController *coreController = data->coreController;
|
||||||
struct mCore *core = coreController->threadContext.core;
|
struct mCore *core = coreController->threadContext.core;
|
||||||
if (!mCoreLoadStateNamed (core, coreController->saveState, SAVESTATE_SAVEDATA & SAVESTATE_RTC)) {
|
if (!mCoreLoadStateNamed (core, coreController->saveState, SAVESTATE_SAVEDATA | SAVESTATE_RTC | SAVESTATE_SCREENSHOT)) {
|
||||||
fprintf(stderr, "Unable to load save state\n");
|
fprintf(stderr, "Unable to load save state\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@ msThreadCallbackSetFrame(struct mCoreThread *threadContext) {
|
|||||||
#define SEC_TO_NANO(sec) \
|
#define SEC_TO_NANO(sec) \
|
||||||
(((uint64_t)sec) * 1000 * 1000 * 1000)
|
(((uint64_t)sec) * 1000 * 1000 * 1000)
|
||||||
struct msClientConnectionData *data = (struct msClientConnectionData *)threadContext->userData;
|
struct msClientConnectionData *data = (struct msClientConnectionData *)threadContext->userData;
|
||||||
unsigned int stride;
|
|
||||||
color_t *outputBuffer;
|
color_t *outputBuffer;
|
||||||
unsigned width, height;
|
unsigned width, height;
|
||||||
unsigned char *rawData = NULL;
|
unsigned char *rawData = NULL;
|
||||||
@ -55,7 +54,6 @@ msThreadCallbackSetFrame(struct mCoreThread *threadContext) {
|
|||||||
if (!data || !data->coreController) {
|
if (!data || !data->coreController) {
|
||||||
goto return_ms_thread_callback_set_frame;
|
goto return_ms_thread_callback_set_frame;
|
||||||
}
|
}
|
||||||
stride = data->coreController->stride;
|
|
||||||
outputBuffer = data->coreController->outputBuffer;
|
outputBuffer = data->coreController->outputBuffer;
|
||||||
|
|
||||||
while (nanoCurrent < nanoLast && nanoLast != 0 && nanoLast - nanoCurrent < SEC_TO_NANO(10)) {
|
while (nanoCurrent < nanoLast && nanoLast != 0 && nanoLast - nanoCurrent < SEC_TO_NANO(10)) {
|
||||||
@ -66,8 +64,16 @@ msThreadCallbackSetFrame(struct mCoreThread *threadContext) {
|
|||||||
*data->lastFrameDate = currentDate;
|
*data->lastFrameDate = currentDate;
|
||||||
|
|
||||||
data->coreController->threadContext.core->desiredVideoDimensions(data->coreController->threadContext.core, &width, &height);
|
data->coreController->threadContext.core->desiredVideoDimensions(data->coreController->threadContext.core, &width, &height);
|
||||||
|
if (data->coreController->threadContext.core->platform(data->coreController->threadContext.core) == mPLATFORM_GB) {
|
||||||
|
width = 160;
|
||||||
|
height = 144;
|
||||||
|
}
|
||||||
|
|
||||||
sendFrame = msPacketSendFrameNew(stride, width * height, outputBuffer);
|
if (data->numberFrame++ % 10 != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendFrame = msPacketSendFrameNew(width, width * height, outputBuffer);
|
||||||
rawData = msPacketSendFrameSerialize(sendFrame, &rawDataLen);
|
rawData = msPacketSendFrameSerialize(sendFrame, &rawDataLen);
|
||||||
if (!rawData) {
|
if (!rawData) {
|
||||||
goto return_ms_thread_callback_set_frame;
|
goto return_ms_thread_callback_set_frame;
|
||||||
|
@ -73,7 +73,7 @@ shrinkOrNullSaveRequestsDataArray(struct msClientConnectionData *data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *
|
static unsigned char *
|
||||||
VFileToBytes(struct VFile *file, size_t *len) {
|
vFileToBytes(struct VFile *file, size_t *len) {
|
||||||
unsigned char *result = NULL;
|
unsigned char *result = NULL;
|
||||||
const ssize_t bufferLen = 120;
|
const ssize_t bufferLen = 120;
|
||||||
ssize_t readLen = 0;
|
ssize_t readLen = 0;
|
||||||
@ -85,15 +85,10 @@ VFileToBytes(struct VFile *file, size_t *len) {
|
|||||||
file->seek(file, 0, SEEK_SET);
|
file->seek(file, 0, SEEK_SET);
|
||||||
while ((readLen = file->read(file, buffer, bufferLen)) && readLen) {
|
while ((readLen = file->read(file, buffer, bufferLen)) && readLen) {
|
||||||
*len += readLen;
|
*len += readLen;
|
||||||
unsigned char *resultTmp= realloc(result, sizeof *result * *len);
|
size_t size = sizeof *result * *len;
|
||||||
if (!resultTmp) {
|
result = realloc(result, size);
|
||||||
free(result);
|
|
||||||
result = NULL;
|
|
||||||
goto return_vfile_to_bytes;
|
|
||||||
}
|
|
||||||
result = resultTmp;
|
|
||||||
// memcpy_s not available in linux.
|
// memcpy_s not available in linux.
|
||||||
memcpy(&result[*len-1-readLen], buffer, readLen); // NOLINT
|
memcpy(&result[*len - readLen], buffer, readLen); // NOLINT
|
||||||
}
|
}
|
||||||
return_vfile_to_bytes:
|
return_vfile_to_bytes:
|
||||||
return result;
|
return result;
|
||||||
@ -128,8 +123,8 @@ unlock_ms_packet_save_request_send_response:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
saveState = VFileMemChunk (NULL, 0);
|
saveState = VFileMemChunk (NULL, 0);
|
||||||
mCoreSaveStateNamed(core, saveState, SAVESTATE_SAVEDATA & SAVESTATE_RTC);
|
mCoreSaveStateNamed(core, saveState, SAVESTATE_ALL);
|
||||||
save = VFileToBytes(saveState, &saveLen);
|
save = vFileToBytes(saveState, &saveLen);
|
||||||
response = msPacketSaveResponseNew(request->identifier, saveLen, save);
|
response = msPacketSaveResponseNew(request->identifier, saveLen, save);
|
||||||
rawData = msPacketSaveResponseSerialize(response, &rawDataLen);
|
rawData = msPacketSaveResponseSerialize(response, &rawDataLen);
|
||||||
if (!rawData) {
|
if (!rawData) {
|
||||||
@ -172,6 +167,7 @@ msPacketSaveRequestHandle(const struct msPacket *packet, struct msPacketSaveRequ
|
|||||||
pthread_mutex_unlock(data->mutexSaveRequests);
|
pthread_mutex_unlock(data->mutexSaveRequests);
|
||||||
|
|
||||||
mCoreThreadRunFunction(&coreController->threadContext, &msPacketSaveRequestSendResponse);
|
mCoreThreadRunFunction(&coreController->threadContext, &msPacketSaveRequestSendResponse);
|
||||||
|
result = true;
|
||||||
return_ms_packet_save_request_handle:
|
return_ms_packet_save_request_handle:
|
||||||
msPacketSaveRequestDestroy(&self);
|
msPacketSaveRequestDestroy(&self);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -33,14 +34,15 @@ msPacketSaveResponseSerialize(struct msPacketSaveResponse *const self, size_t *l
|
|||||||
*len = sizeof identifier + sizeof saveLen + sizeof *result * saveLen;
|
*len = sizeof identifier + sizeof saveLen + sizeof *result * saveLen;
|
||||||
result = malloc(*len);
|
result = malloc(*len);
|
||||||
|
|
||||||
htobe64(identifier);
|
identifier = htobe64(identifier);
|
||||||
htobe64(saveLen);
|
saveLen = htobe64(saveLen);
|
||||||
|
|
||||||
memcpy(&result[currentCursor], &identifier, sizeof identifier); // NOLINT
|
memcpy(&result[currentCursor], &identifier, sizeof identifier); // NOLINT
|
||||||
currentCursor += sizeof identifier;
|
currentCursor += sizeof identifier;
|
||||||
|
|
||||||
memcpy(&result[currentCursor], &saveLen, sizeof saveLen); // NOLINT
|
memcpy(&result[currentCursor], &saveLen, sizeof saveLen); // NOLINT
|
||||||
currentCursor += sizeof saveLen;
|
currentCursor += sizeof saveLen;
|
||||||
|
saveLen = be64toh(saveLen);
|
||||||
|
|
||||||
memcpy(&result[currentCursor], self->save, sizeof *result * saveLen); // NOLINT
|
memcpy(&result[currentCursor], self->save, sizeof *result * saveLen); // NOLINT
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ msPacketSendFrameSerialize(struct msPacketSendFrame *const self, size_t *len) {
|
|||||||
unsigned int stride = self->stride;
|
unsigned int stride = self->stride;
|
||||||
size_t outputBufferSizeBytes = self->outputBufferSize * sizeof (uint32_t);
|
size_t outputBufferSizeBytes = self->outputBufferSize * sizeof (uint32_t);
|
||||||
stride = htobe32(stride);
|
stride = htobe32(stride);
|
||||||
*len = (sizeof self->stride) + (sizeof self->outputBufferSize) + (outputBufferSizeBytes);
|
*len = (sizeof stride) + (sizeof outputBufferSizeBytes) + (outputBufferSizeBytes);
|
||||||
outputBufferSizeBytes = htobe64(outputBufferSizeBytes);
|
outputBufferSizeBytes = htobe64(outputBufferSizeBytes);
|
||||||
bytes = malloc(*len);
|
bytes = malloc(*len);
|
||||||
#define GOTO_END_SERIALIZE_FAIL() \
|
#define GOTO_END_SERIALIZE_FAIL() \
|
||||||
@ -38,7 +38,7 @@ msPacketSendFrameSerialize(struct msPacketSendFrame *const self, size_t *len) {
|
|||||||
bytes = NULL; \
|
bytes = NULL; \
|
||||||
goto return_ms_packet_send_frame_serialize;
|
goto return_ms_packet_send_frame_serialize;
|
||||||
FILE *fp = fmemopen(bytes, sizeof *bytes * *len, "w");
|
FILE *fp = fmemopen(bytes, sizeof *bytes * *len, "w");
|
||||||
if (fwrite(&self->stride, sizeof self->stride, 1, fp) == -1) {
|
if (fwrite(&stride, sizeof stride, 1, fp) == -1) {
|
||||||
GOTO_END_SERIALIZE_FAIL();
|
GOTO_END_SERIALIZE_FAIL();
|
||||||
}
|
}
|
||||||
if (fwrite(&outputBufferSizeBytes, sizeof outputBufferSizeBytes, 1, fp) == -1) {
|
if (fwrite(&outputBufferSizeBytes, sizeof outputBufferSizeBytes, 1, fp) == -1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user