dsda: convert c++ to c
This commit is contained in:
parent
8e8d718c7e
commit
aa7b78894a
Binary file not shown.
|
@ -1,9 +1,9 @@
|
|||
#include "BizhawkInterface.hxx"
|
||||
#include "BizhawkInterface.h"
|
||||
|
||||
ECL_EXPORT void dsda_get_audio(int *n, void **buffer)
|
||||
{
|
||||
int nSamples = 0;
|
||||
void* audioBuffer = nullptr;
|
||||
void* audioBuffer = NULL;
|
||||
audioBuffer = I_CaptureAudio(&nSamples);
|
||||
// printf("audioBuffer: %p - nSamples: %d\n", audioBuffer, nSamples);
|
||||
|
||||
|
@ -13,15 +13,15 @@ ECL_EXPORT void dsda_get_audio(int *n, void **buffer)
|
|||
*buffer = audioBuffer;
|
||||
}
|
||||
|
||||
ECL_EXPORT void dsda_get_video(int& w, int& h, int& pitch, uint8_t*& buffer, int& paletteSize, uint32_t*& paletteBuffer)
|
||||
ECL_EXPORT void dsda_get_video(int* w, int* h, int* pitch, uint8_t** buffer, int* paletteSize, uint32_t** paletteBuffer)
|
||||
{
|
||||
buffer = (uint8_t*)headlessGetVideoBuffer();
|
||||
w = headlessGetVideoWidth();
|
||||
h = headlessGetVideoHeight();
|
||||
pitch = headlessGetVideoPitch();
|
||||
paletteSize = PALETTE_SIZE;
|
||||
*buffer = (uint8_t*)headlessGetVideoBuffer();
|
||||
*w = headlessGetVideoWidth();
|
||||
*h = headlessGetVideoHeight();
|
||||
*pitch = headlessGetVideoPitch();
|
||||
*paletteSize = PALETTE_SIZE;
|
||||
|
||||
auto palette = headlessGetPallette();
|
||||
uint32_t* palette = headlessGetPallette();
|
||||
for (size_t i = 0; i < PALETTE_SIZE; i++)
|
||||
{
|
||||
uint8_t* srcColor = (uint8_t*)&palette[i];
|
||||
|
@ -32,7 +32,7 @@ ECL_EXPORT void dsda_get_video(int& w, int& h, int& pitch, uint8_t*& buffer, int
|
|||
dstColor[3] = srcColor[3];
|
||||
}
|
||||
|
||||
paletteBuffer = _convertedPaletteBuffer;
|
||||
*paletteBuffer = _convertedPaletteBuffer;
|
||||
}
|
||||
|
||||
ECL_EXPORT void dsda_frame_advance(struct PackedPlayerInput *player1Inputs, struct PackedPlayerInput *player2Inputs, struct PackedPlayerInput *player3Inputs, struct PackedPlayerInput *player4Inputs, struct PackedRenderInfo *renderInfo)
|
||||
|
@ -143,7 +143,7 @@ ECL_EXPORT void dsda_set_input_callback(ECL_ENTRY void (*fecb)(void))
|
|||
|
||||
bool foundIWAD = false;
|
||||
|
||||
ECL_EXPORT int dsda_init(InitSettings *settings, int argc, char **argv)
|
||||
ECL_EXPORT int dsda_init(struct InitSettings *settings, int argc, char **argv)
|
||||
{
|
||||
printf("Passing arguments: \n");
|
||||
for (int i = 0; i < argc; i++) printf("%s ", argv[i]);
|
||||
|
@ -200,7 +200,7 @@ ECL_EXPORT int dsda_init(InitSettings *settings, int argc, char **argv)
|
|||
ECL_EXPORT int dsda_add_wad_file(const char *filename, const int size, ECL_ENTRY int (*feload_archive_cb)(const char *filename, unsigned char *buffer, int maxsize))
|
||||
{
|
||||
printf("Loading WAD '%s' of size %d...\n", filename, size);
|
||||
auto wadFileBuffer = (unsigned char*) alloc_invisible(size);
|
||||
unsigned char* wadFileBuffer = (unsigned char*) alloc_invisible(size);
|
||||
|
||||
if (wadFileBuffer == NULL) { fprintf(stderr, "Error creating buffer. Do we have enough memory in the waterbox?\n"); return 0; }
|
||||
else printf("Created buffer at address: %p\n", wadFileBuffer);
|
||||
|
@ -219,14 +219,11 @@ ECL_EXPORT int dsda_add_wad_file(const char *filename, const int size, ECL_ENTRY
|
|||
header[3] = wadFileBuffer[3];
|
||||
header[4] = '\0';
|
||||
|
||||
// Getting string
|
||||
std::string headerString(header);
|
||||
|
||||
// Safety checks
|
||||
bool recognizedFormat = false;
|
||||
|
||||
// Loading PWAD
|
||||
if (headerString == "PWAD")
|
||||
if (!strcmp(header, "PWAD"))
|
||||
{
|
||||
recognizedFormat = true;
|
||||
|
||||
|
@ -236,7 +233,7 @@ ECL_EXPORT int dsda_add_wad_file(const char *filename, const int size, ECL_ENTRY
|
|||
}
|
||||
|
||||
// Loading IWAD
|
||||
if (headerString == "IWAD")
|
||||
if (!strcmp(header, "IWAD"))
|
||||
{
|
||||
recognizedFormat = true;
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
#ifndef __BIZHAWK_INTERFACE__
|
||||
#define __BIZHAWK_INTERFACE__
|
||||
|
||||
#include "emulibc.h"
|
||||
#include "d_player.h"
|
||||
#include "w_wad.h"
|
||||
#include "p_mobj.h"
|
||||
#include "doomstat.h"
|
||||
#include "g_game.h"
|
||||
|
||||
#include "dsda/args.h"
|
||||
|
||||
extern int headlessMain(int argc, char **argv);
|
||||
extern void headlessRunSingleTick();
|
||||
extern void headlessUpdateSounds(void);
|
||||
extern void headlessClearTickCommand();
|
||||
extern void headlessSetTickCommand(int playerId, int forwardSpeed, int strafingSpeed, int turningSpeed, int fire, int action, int weapon, int automap, int lookfly, int artifact, int jump, int endPlayer);
|
||||
|
||||
// Video-related functions
|
||||
extern void headlessUpdateVideo(void);
|
||||
extern void* headlessGetVideoBuffer();
|
||||
extern int headlessGetVideoPitch();
|
||||
extern int headlessGetVideoWidth();
|
||||
extern int headlessGetVideoHeight();
|
||||
extern void headlessEnableVideoRendering();
|
||||
extern void headlessDisableVideoRendering();
|
||||
extern void headlessEnableAudioRendering();
|
||||
extern void headlessDisableAudioRendering();
|
||||
uint32_t* headlessGetPallette();
|
||||
|
||||
extern void headlessSetSaveStatePointer(void* savePtr, int saveStateSize);
|
||||
size_t headlessGetEffectiveSaveSize();
|
||||
extern void dsda_ArchiveAll(void);
|
||||
extern void dsda_UnArchiveAll(void);
|
||||
extern void headlessGetMapName(char* outString);
|
||||
|
||||
extern void D_AddFile (const char *file, wad_source_t source, void* const buffer, const size_t size);
|
||||
extern void AddIWAD(const char *iwad, void* const buffer, const size_t size);
|
||||
extern unsigned char * I_CaptureAudio (int* nsamples);
|
||||
extern void I_InitSound(void);
|
||||
extern void I_SetSoundCap (void);
|
||||
|
||||
// Players information
|
||||
extern int enableOutput;
|
||||
extern int preventLevelExit;
|
||||
extern int preventGameEnd;
|
||||
extern int reachedLevelExit;
|
||||
extern int reachedGameEnd;
|
||||
extern int numthings;
|
||||
extern mobj_t **mobj_ptrs;
|
||||
extern dsda_arg_t arg_value[dsda_arg_count];
|
||||
|
||||
#define PALETTE_SIZE 256
|
||||
uint32_t _convertedPaletteBuffer[PALETTE_SIZE];
|
||||
|
||||
enum MemoryArrayType
|
||||
{
|
||||
ARRAY_THINGS = 0,
|
||||
ARRAY_LINES = 1,
|
||||
ARRAY_SECTORS = 2
|
||||
};
|
||||
|
||||
struct InitSettings
|
||||
{
|
||||
int _Player1Present;
|
||||
int _Player2Present;
|
||||
int _Player3Present;
|
||||
int _Player4Present;
|
||||
int _Player1Class;
|
||||
int _Player2Class;
|
||||
int _Player3Class;
|
||||
int _Player4Class;
|
||||
int _PreventLevelExit;
|
||||
int _PreventGameEnd;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct PackedPlayerInput
|
||||
{
|
||||
int _RunSpeed;
|
||||
int _StrafingSpeed;
|
||||
int _TurningSpeed;
|
||||
int _WeaponSelect;
|
||||
int _Fire;
|
||||
int _Action;
|
||||
int _Automap;
|
||||
int _FlyLook;
|
||||
int _ArtifactUse;
|
||||
int _Jump;
|
||||
int _EndPlayer;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct PackedRenderInfo
|
||||
{
|
||||
int _RenderVideo;
|
||||
int _RenderAudio;
|
||||
int _PlayerPointOfView;
|
||||
} __attribute__((packed));
|
||||
|
||||
#endif
|
|
@ -1,108 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
|
||||
#include "emulibc.h"
|
||||
#include "d_player.h"
|
||||
#include "w_wad.h"
|
||||
#include "p_mobj.h"
|
||||
#include "doomstat.h"
|
||||
#include "g_game.h"
|
||||
|
||||
#include "dsda/args.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
int headlessMain(int argc, char **argv);
|
||||
void headlessRunSingleTick();
|
||||
void headlessUpdateSounds(void);
|
||||
void headlessClearTickCommand();
|
||||
void headlessSetTickCommand(int playerId, int forwardSpeed, int strafingSpeed, int turningSpeed, int fire, int action, int weapon, int automap, int lookfly, int artifact, int jump, int endPlayer);
|
||||
|
||||
// Video-related functions
|
||||
void headlessUpdateVideo(void);
|
||||
void* headlessGetVideoBuffer();
|
||||
int headlessGetVideoPitch();
|
||||
int headlessGetVideoWidth();
|
||||
int headlessGetVideoHeight();
|
||||
void headlessEnableVideoRendering();
|
||||
void headlessDisableVideoRendering();
|
||||
void headlessEnableAudioRendering();
|
||||
void headlessDisableAudioRendering();
|
||||
uint32_t* headlessGetPallette();
|
||||
|
||||
void headlessSetSaveStatePointer(void* savePtr, int saveStateSize);
|
||||
size_t headlessGetEffectiveSaveSize();
|
||||
void dsda_ArchiveAll(void);
|
||||
void dsda_UnArchiveAll(void);
|
||||
void headlessGetMapName(char* outString);
|
||||
|
||||
void D_AddFile (const char *file, wad_source_t source, void* const buffer, const size_t size);
|
||||
void AddIWAD(const char *iwad, void* const buffer, const size_t size);
|
||||
unsigned char * I_CaptureAudio (int* nsamples);
|
||||
void I_InitSound(void);
|
||||
void I_SetSoundCap (void);
|
||||
}
|
||||
|
||||
// Players information
|
||||
extern "C" int enableOutput;
|
||||
extern "C" int preventLevelExit;
|
||||
extern "C" int preventGameEnd;
|
||||
extern "C" int reachedLevelExit;
|
||||
extern "C" int reachedGameEnd;
|
||||
extern int numthings;
|
||||
extern mobj_t **mobj_ptrs;
|
||||
extern dsda_arg_t arg_value[dsda_arg_count];
|
||||
|
||||
#define PALETTE_SIZE 256
|
||||
uint32_t _convertedPaletteBuffer[PALETTE_SIZE];
|
||||
|
||||
enum MemoryArrayType
|
||||
{
|
||||
ARRAY_THINGS = 0,
|
||||
ARRAY_LINES = 1,
|
||||
ARRAY_SECTORS = 2
|
||||
};
|
||||
|
||||
struct InitSettings
|
||||
{
|
||||
int _Player1Present;
|
||||
int _Player2Present;
|
||||
int _Player3Present;
|
||||
int _Player4Present;
|
||||
int _Player1Class;
|
||||
int _Player2Class;
|
||||
int _Player3Class;
|
||||
int _Player4Class;
|
||||
int _PreventLevelExit;
|
||||
int _PreventGameEnd;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct PackedPlayerInput
|
||||
{
|
||||
int _RunSpeed;
|
||||
int _StrafingSpeed;
|
||||
int _TurningSpeed;
|
||||
int _WeaponSelect;
|
||||
int _Fire;
|
||||
int _Action;
|
||||
int _Automap;
|
||||
int _FlyLook;
|
||||
int _ArtifactUse;
|
||||
int _Jump;
|
||||
int _EndPlayer;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct PackedRenderInfo
|
||||
{
|
||||
int _RenderVideo;
|
||||
int _RenderAudio;
|
||||
int _PlayerPointOfView;
|
||||
} __attribute__((packed));
|
||||
|
||||
dboolean dsda_Flag(dsda_arg_identifier_t id) {
|
||||
return arg_value[id].found;
|
||||
}
|
|
@ -15,28 +15,12 @@ CCFLAGS := \
|
|||
-Wno-unused-variable \
|
||||
-Wno-deprecated-non-prototype
|
||||
|
||||
CXXFLAGS := \
|
||||
-I. \
|
||||
-I./core/prboom2/src \
|
||||
-Wfatal-errors \
|
||||
-DHAVE_CONFIG_H \
|
||||
-Dstricmp=strcasecmp \
|
||||
-Dstrnicmp=strncasecmp \
|
||||
-DNDEBUG \
|
||||
-ffast-math \
|
||||
-Wno-unused-function \
|
||||
-Wno-switch \
|
||||
-Wno-pointer-sign \
|
||||
-Wno-sign-compare \
|
||||
-Wno-unused-but-set-variable \
|
||||
-Wno-unused-variable
|
||||
|
||||
LDFLAGS :=
|
||||
|
||||
TARGET := dsda.wbx
|
||||
|
||||
SRCS = \
|
||||
BizhawkInterface.cxx \
|
||||
BizhawkInterface.c \
|
||||
core/prboom2/src/am_map.c \
|
||||
core/prboom2/src/doomdef.c \
|
||||
core/prboom2/src/doomstat.c \
|
||||
|
|
Loading…
Reference in New Issue