dp_doom: use 4 bytes per pixel and fix the colors

This commit is contained in:
oxmox 2023-02-19 23:48:02 +01:00
parent 3c5b3ae4e9
commit cbe6f76920
2 changed files with 17 additions and 6 deletions

View file

@ -16,11 +16,11 @@ extern "C" {
typedef pid_t doomid_t; // unique id for each doom instance typedef pid_t doomid_t; // unique id for each doom instance
typedef u16 dmt_t; // for DP_MessageType values typedef u16 dmt_t; // for DP_MessageType values
#define DoomScreenWidth 320u #define DoomScreenWidth 320
#define DoomScreenHeight 240u #define DoomScreenHeight 240
#define DoomBytesPerPixel 3u #define DoomBytesPerPixel 4
#define DoomFrameSize (DoomScreenWidth * DoomScreenHeight * DoomBytesPerPixel)
#define DoomFramePitch (DoomScreenWidth * DoomBytesPerPixel) #define DoomFramePitch (DoomScreenWidth * DoomBytesPerPixel)
#define DoomFrameSize (DoomScreenWidth * DoomScreenHeight * DoomBytesPerPixel)
typedef enum DP_MessageType typedef enum DP_MessageType
{ {
@ -66,7 +66,7 @@ typedef struct __attribute__((packed, aligned(4)))
{ {
MessageBase head; MessageBase head;
doomid_t doomId; doomid_t doomId;
u8 frame[DoomScreenWidth * DoomScreenHeight * DoomBytesPerPixel]; u8 frame[DoomFrameSize];
} MsgDoomFrame; } MsgDoomFrame;
typedef struct __attribute__((packed, aligned(4))) typedef struct __attribute__((packed, aligned(4)))

View file

@ -286,9 +286,19 @@ void IB_FinishUpdate (void)
void IB_GetColor(unsigned char *bytes, unsigned char red, unsigned char green, unsigned char blue) void IB_GetColor(unsigned char *bytes, unsigned char red, unsigned char green, unsigned char blue)
{ {
#if DoomBytesPerPixel == 3
// FIXME: might be buggy
bytes[0] = red; bytes[0] = red;
bytes[1] = green; bytes[1] = green;
bytes[2] = blue; bytes[2] = blue;
#elif DoomBytesPerPixel == 4
bytes[0] = blue;
bytes[1] = green;
bytes[2] = red;
bytes[3] = 0xff; // alpha?
#else
#error Unhandled DoomBytesPerPixel value. How to IB_GetColor?
#endif
} }
static void I_Quit_Wrapper(int dummy) static void I_Quit_Wrapper(int dummy)
@ -302,6 +312,8 @@ static void I_Quit_Wrapper(int dummy)
void IB_InitGraphics(const char *title, size_t screen_width, size_t screen_height, size_t *bytes_per_pixel) void IB_InitGraphics(const char *title, size_t screen_width, size_t screen_height, size_t *bytes_per_pixel)
{ {
(void) title; (void) title;
log_set_level(LOG_DEBUG);
g_frameBufferSize = screen_width * screen_height * DoomBytesPerPixel; g_frameBufferSize = screen_width * screen_height * DoomBytesPerPixel;
assert(g_frameBufferSize == DoomFrameSize); assert(g_frameBufferSize == DoomFrameSize);
g_frameBuffer = malloc(g_frameBufferSize); g_frameBuffer = malloc(g_frameBufferSize);
@ -313,7 +325,6 @@ void IB_InitGraphics(const char *title, size_t screen_width, size_t screen_heigh
signal(SIGINT, I_Quit_Wrapper); signal(SIGINT, I_Quit_Wrapper);
log_set_level(LOG_DEBUG);
dp_nng_init_limits(1, 1, 1); dp_nng_init_limits(1, 1, 1);