mirror of
https://github.com/OpenDriver2/REDRIVER2.git
synced 2024-11-25 11:52:32 +01:00
- [Psy-X] redone logging system, console now only shows in Debug build
- [Psy-X] added log file creation
This commit is contained in:
parent
6bf3bb9ba2
commit
019c38c5ce
@ -3040,7 +3040,9 @@ void CheckCurrentRoad(CAR_DATA* cp)
|
||||
void SetTarget(CAR_DATA* cp, int curRoad, int heading, int* nextJunction)
|
||||
{
|
||||
volatile int dx, dz; // offset 0xd8
|
||||
|
||||
|
||||
sdPlane* pl;
|
||||
VECTOR pos;
|
||||
DRIVER2_STRAIGHT* straight;
|
||||
DRIVER2_CURVE* curve;
|
||||
|
||||
@ -3107,6 +3109,12 @@ void SetTarget(CAR_DATA* cp, int curRoad, int heading, int* nextJunction)
|
||||
|
||||
cp->ai.l.targetX = cp->hd.where.t[0] + rx + ux;
|
||||
cp->ai.l.targetZ = cp->hd.where.t[2] + rz + uz;
|
||||
|
||||
pos.vx = cp->ai.l.targetX;
|
||||
pos.vy = cp->hd.where.t[1];
|
||||
pos.vz = cp->ai.l.targetZ;
|
||||
|
||||
pl = sdGetCell(&pos);
|
||||
}
|
||||
else if (IS_CURVED_SURFACE(curRoad))
|
||||
{
|
||||
|
@ -24,11 +24,10 @@
|
||||
|
||||
#else
|
||||
|
||||
// from redriver2_psxpc
|
||||
void printMsg(char *fmt, ...);
|
||||
void printInfo(char *fmt, ...);
|
||||
void printWarning(char *fmt, ...);
|
||||
void printError(char *fmt, ...);
|
||||
#define printMsg PsyX_Log
|
||||
#define printInfo PsyX_Log_Info
|
||||
#define printWarning PsyX_Log_Warning
|
||||
#define printError PsyX_Log_Error
|
||||
|
||||
#if _MSC_VER >= 1400
|
||||
#define trap(ode) {printError("EXCEPTION code: %x\n", ode); __debugbreak();}
|
||||
|
@ -6,6 +6,7 @@
|
||||
// Necessary includes
|
||||
#ifndef PSX
|
||||
#include "PSYX_PUBLIC.H"
|
||||
#include "PSYX_GLOBALS.H"
|
||||
#endif
|
||||
|
||||
// Necessary types
|
||||
|
@ -18,6 +18,13 @@ extern int g_emulatorPaused;
|
||||
extern int g_polygonSelected;
|
||||
extern int g_pgxpTextureCorrection;
|
||||
|
||||
extern void InternalPadUpdates();
|
||||
extern void PsyX_InternalPadUpdates();
|
||||
|
||||
// logging functions
|
||||
extern void PsyX_Log(const char* fmt, ...);
|
||||
extern void PsyX_Log_Info(const char* fmt, ...);
|
||||
extern void PsyX_Log_Warning(const char* fmt, ...);
|
||||
extern void PsyX_Log_Error(const char* fmt, ...);
|
||||
extern void PsyX_Log_Success(const char* fmt, ...);
|
||||
|
||||
#endif
|
@ -378,9 +378,8 @@ void MakeTexcoordTriangle(struct GrVertex* vertex, unsigned char* uv0, unsigned
|
||||
void MakeTexcoordRect(struct GrVertex* vertex, unsigned char* uv, short page, short clut, short w, short h)
|
||||
{
|
||||
assert(uv);
|
||||
//assert(int(uv[0]) + w <= 255);
|
||||
//assert(int(uv[1]) + h <= 255);
|
||||
// TODO
|
||||
|
||||
// sim overflow
|
||||
if (int(uv[0]) + w > 255) w = 255 - uv[0];
|
||||
if (int(uv[1]) + h > 255) h = 255 - uv[1];
|
||||
|
||||
@ -772,26 +771,26 @@ int ParsePrimitive(uintptr_t primPtr)
|
||||
{
|
||||
switch (pTag->code)
|
||||
{
|
||||
case 0x01:
|
||||
{
|
||||
DR_MOVE* drmove = (DR_MOVE*)pTag;
|
||||
case 0x01:
|
||||
{
|
||||
DR_MOVE* drmove = (DR_MOVE*)pTag;
|
||||
|
||||
int x, y;
|
||||
y = drmove->code[3] >> 0x10 & 0xFFFF;
|
||||
x = drmove->code[3] & 0xFFFF;
|
||||
int x, y;
|
||||
y = drmove->code[3] >> 0x10 & 0xFFFF;
|
||||
x = drmove->code[3] & 0xFFFF;
|
||||
|
||||
RECT16 rect;
|
||||
*(ulong*)&rect.x = *(ulong*)&drmove->code[2];
|
||||
*(ulong*)&rect.w = *(ulong*)&drmove->code[4];
|
||||
RECT16 rect;
|
||||
*(ulong*)&rect.x = *(ulong*)&drmove->code[2];
|
||||
*(ulong*)&rect.w = *(ulong*)&drmove->code[4];
|
||||
|
||||
MoveImage(&rect, x, y);
|
||||
MoveImage(&rect, x, y);
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
eprinterr("Unknown command %02X!\n", pTag->code);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
eprinterr("Unknown command %02X!\n", pTag->code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -99,11 +99,16 @@
|
||||
#if defined(__ANDROID__)
|
||||
#include <android/log.h>
|
||||
#define LOG_TAG_EMU "[PsyX] "
|
||||
#define eprintf(fmt, ...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG_EMU, fmt, ##__VA_ARGS__)
|
||||
#define eprinterr(fmt, ...) eprintf("[%s] - " fmt, FUNCNAME, ##__VA_ARGS__);
|
||||
#define eprintf(fmt, ...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG_EMU, fmt, ##__VA_ARGS__)
|
||||
#define eprintinfof(fmt, ...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG_EMU " [INFO]", fmt, ##__VA_ARGS__)
|
||||
#define eprintwarnf(fmt, ...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG_EMU " [WARN]", fmt, ##__VA_ARGS__)
|
||||
#define eprinterr(fmt, ...) eprintf("[%s] - " fmt, FUNCNAME, ##__VA_ARGS__);
|
||||
#else
|
||||
#define eprintf(fmt, ...) printf("[Psy-X] " fmt, ##__VA_ARGS__)
|
||||
#define eprinterr(fmt, ...) eprintf("[%s] - " fmt, FUNCNAME, ##__VA_ARGS__);
|
||||
#include "PSYX_GLOBALS.H"
|
||||
#define eprintf(fmt, ...) PsyX_Log("[Psy-X] " fmt, ##__VA_ARGS__)
|
||||
#define eprintinfo(fmt, ...) PsyX_Log_Info("[Psy-X] " fmt, ##__VA_ARGS__)
|
||||
#define eprintwarn(fmt, ...) PsyX_Log_Warning("[Psy-X] " fmt, ##__VA_ARGS__)
|
||||
#define eprinterr(fmt, ...) PsyX_Log_Error("[Psy-X] [%s] - " fmt, FUNCNAME, ##__VA_ARGS__);
|
||||
#endif
|
||||
|
||||
#if defined(__EMSCRIPTEN__) || !defined(_DEBUG)
|
||||
|
@ -345,7 +345,7 @@ int ParseCueSheet()
|
||||
|
||||
if (openFile == NULL)
|
||||
{
|
||||
eprinterr("Failed to open disc image file! %s\n", DISC_IMAGE_FILENAME);
|
||||
eprinterr("%s not found.\n", DISC_IMAGE_FILENAME);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -421,6 +421,14 @@ int ParseCueSheet()
|
||||
|
||||
fclose(openFile);
|
||||
openFile = fopen(binFileName, "rb");
|
||||
|
||||
if (!openFile)
|
||||
{
|
||||
eprinterr("%s not found.\n", binFileName);
|
||||
free(cueSheet);
|
||||
return 0;
|
||||
}
|
||||
|
||||
fseek(openFile, 0, SEEK_END);
|
||||
unsigned int binFileLength = ftell(openFile);
|
||||
numFrames = binFileLength / sectorSize;
|
||||
@ -438,10 +446,7 @@ int CdInit(void)
|
||||
|
||||
//Read the cue sheet and obtain properties from it.
|
||||
if (!ParseCueSheet())
|
||||
{
|
||||
eprinterr("Failed to read cue sheet!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(&comQueue, 0, sizeof(comQueue));
|
||||
for (int i = 0; i < COMMAND_QUEUE_SIZE; i++)
|
||||
|
@ -293,7 +293,7 @@ unsigned short UpdateKeyboardInput()
|
||||
|
||||
extern int activeControllers;
|
||||
|
||||
void InternalPadUpdates()
|
||||
void PsyX_InternalPadUpdates()
|
||||
{
|
||||
if (g_padCommStarted == 0)
|
||||
return;
|
||||
|
@ -147,7 +147,7 @@ void InitOpenAlEffects()
|
||||
alAuxiliaryEffectSloti(g_ALEffectSlots[g_currEffectSlotIdx], AL_EFFECTSLOT_EFFECT, g_nAlReverbEffect);
|
||||
}
|
||||
|
||||
bool Emulator_InitSound()
|
||||
bool PsyX_InitSound()
|
||||
{
|
||||
if (g_ALCdevice)
|
||||
return true;
|
||||
@ -159,7 +159,7 @@ bool Emulator_InitSound()
|
||||
// go through device list (each device terminated with a single NULL, list terminated with double NULL)
|
||||
while ((*devices) != '\0')
|
||||
{
|
||||
printf("found sound device: %s\n", devices);
|
||||
eprintinfo("found sound device: %s\n", devices);
|
||||
devices += strlen(devices) + 1;
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ bool Emulator_InitSound()
|
||||
if (!g_ALCdevice)
|
||||
{
|
||||
alErr = alcGetError(nullptr);
|
||||
printf("alcOpenDevice: NULL DEVICE error: %s\n", getALCErrorString(alErr));
|
||||
eprinterr("alcOpenDevice: NULL DEVICE error: %s\n", getALCErrorString(alErr));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ bool Emulator_InitSound()
|
||||
alErr = alcGetError(g_ALCdevice);
|
||||
if (alErr != AL_NO_ERROR)
|
||||
{
|
||||
printf("alcCreateContext error: %s\n", getALCErrorString(alErr));
|
||||
eprinterr("alcCreateContext error: %s\n", getALCErrorString(alErr));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ bool Emulator_InitSound()
|
||||
alErr = alcGetError(g_ALCdevice);
|
||||
if (alErr != AL_NO_ERROR)
|
||||
{
|
||||
printf("alcMakeContextCurrent error: %s\n", getALCErrorString(alErr));
|
||||
eprinterr("alcMakeContextCurrent error: %s\n", getALCErrorString(alErr));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -226,11 +226,27 @@ bool Emulator_InitSound()
|
||||
return true;
|
||||
}
|
||||
|
||||
void PsyX_ShutdownSound()
|
||||
{
|
||||
if (!g_ALCcontext)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < SPU_VOICES; i++)
|
||||
{
|
||||
SPUVoice& voice = g_SpuVoices[i];
|
||||
alGenSources(1, &voice.alSource);
|
||||
alGenBuffers(1, &voice.alBuffer);
|
||||
}
|
||||
|
||||
alcDestroyContext(g_ALCcontext);
|
||||
alcCloseDevice(g_ALCdevice);
|
||||
|
||||
g_ALCcontext = NULL;
|
||||
g_ALCdevice = NULL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
// PSX ADPCM coefficients
|
||||
const float K0[5] = { 0, 0.9375, 1.796875, 1.53125, 1.90625 };
|
||||
const float K1[5] = { 0, 0, -0.8125, -0.859375, -0.9375 };
|
||||
@ -423,7 +439,7 @@ long SpuIsTransferCompleted(long flag)
|
||||
|
||||
void SpuStart()
|
||||
{
|
||||
Emulator_InitSound();
|
||||
PsyX_InitSound();
|
||||
}
|
||||
|
||||
void _SpuInit(int a0)
|
||||
|
@ -111,14 +111,14 @@ static int PsyX_Sys_InitialiseCore()
|
||||
|
||||
if (NULL == g_intrThread)
|
||||
{
|
||||
eprintf("SDL_CreateThread failed: %s\n", SDL_GetError());
|
||||
eprinterr("SDL_CreateThread failed: %s\n", SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
g_intrMutex = SDL_CreateMutex();
|
||||
if (NULL == g_intrMutex)
|
||||
{
|
||||
eprintf("SDL_CreateMutex failed: %s\n", SDL_GetError());
|
||||
eprinterr("SDL_CreateMutex failed: %s\n", SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -166,16 +166,220 @@ void PsyX_GetWindowName(char* buffer)
|
||||
#endif
|
||||
}
|
||||
|
||||
FILE* g_logStream = NULL;
|
||||
|
||||
// intialise logging
|
||||
void PsyX_Log_Initialise()
|
||||
{
|
||||
char appLogFilename[128];
|
||||
sprintf(appLogFilename, "%s.log", g_appNameStr);
|
||||
|
||||
g_logStream = fopen(appLogFilename, "wb");
|
||||
|
||||
if (!g_logStream)
|
||||
eprinterr("Error - cannot create log file '%s'\n", appLogFilename);
|
||||
}
|
||||
|
||||
void PsyX_Log_Finalise()
|
||||
{
|
||||
PsyX_Log_Warning("---- LOG CLOSED ----\n");
|
||||
|
||||
if (g_logStream)
|
||||
fclose(g_logStream);
|
||||
|
||||
g_logStream = NULL;
|
||||
}
|
||||
|
||||
// spew types
|
||||
typedef enum
|
||||
{
|
||||
SPEW_NORM,
|
||||
SPEW_INFO,
|
||||
SPEW_WARNING,
|
||||
SPEW_ERROR,
|
||||
SPEW_SUCCESS,
|
||||
}SpewType_t;
|
||||
|
||||
#ifdef _WIN32
|
||||
static unsigned short g_InitialColor = 0xFFFF;
|
||||
static unsigned short g_LastColor = 0xFFFF;
|
||||
static unsigned short g_BadColor = 0xFFFF;
|
||||
static WORD g_BackgroundFlags = 0xFFFF;
|
||||
CRITICAL_SECTION g_SpewCS;
|
||||
bool g_bSpewCSInitted = false;
|
||||
|
||||
static void Spew_GetInitialColors()
|
||||
{
|
||||
// Get the old background attributes.
|
||||
CONSOLE_SCREEN_BUFFER_INFO oldInfo;
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &oldInfo);
|
||||
g_InitialColor = g_LastColor = oldInfo.wAttributes & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
|
||||
g_BackgroundFlags = oldInfo.wAttributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
|
||||
|
||||
g_BadColor = 0;
|
||||
if (g_BackgroundFlags & BACKGROUND_RED)
|
||||
g_BadColor |= FOREGROUND_RED;
|
||||
if (g_BackgroundFlags & BACKGROUND_GREEN)
|
||||
g_BadColor |= FOREGROUND_GREEN;
|
||||
if (g_BackgroundFlags & BACKGROUND_BLUE)
|
||||
g_BadColor |= FOREGROUND_BLUE;
|
||||
if (g_BackgroundFlags & BACKGROUND_INTENSITY)
|
||||
g_BadColor |= FOREGROUND_INTENSITY;
|
||||
}
|
||||
|
||||
static WORD Spew_SetConsoleTextColor(int red, int green, int blue, int intensity)
|
||||
{
|
||||
WORD ret = g_LastColor;
|
||||
|
||||
g_LastColor = 0;
|
||||
if (red) g_LastColor |= FOREGROUND_RED;
|
||||
if (green) g_LastColor |= FOREGROUND_GREEN;
|
||||
if (blue) g_LastColor |= FOREGROUND_BLUE;
|
||||
if (intensity) g_LastColor |= FOREGROUND_INTENSITY;
|
||||
|
||||
// Just use the initial color if there's a match...
|
||||
if (g_LastColor == g_BadColor)
|
||||
g_LastColor = g_InitialColor;
|
||||
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), g_LastColor | g_BackgroundFlags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void Spew_RestoreConsoleTextColor(WORD color)
|
||||
{
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color | g_BackgroundFlags);
|
||||
g_LastColor = color;
|
||||
}
|
||||
|
||||
void Spew_ConDebugSpew(SpewType_t type, char* text)
|
||||
{
|
||||
// Hopefully two threads won't call this simultaneously right at the start!
|
||||
if (!g_bSpewCSInitted)
|
||||
{
|
||||
Spew_GetInitialColors();
|
||||
InitializeCriticalSection(&g_SpewCS);
|
||||
g_bSpewCSInitted = true;
|
||||
}
|
||||
|
||||
WORD old;
|
||||
EnterCriticalSection(&g_SpewCS);
|
||||
{
|
||||
if (type == SPEW_NORM)
|
||||
{
|
||||
old = Spew_SetConsoleTextColor(1, 1, 1, 0);
|
||||
}
|
||||
else if (type == SPEW_WARNING)
|
||||
{
|
||||
old = Spew_SetConsoleTextColor(1, 1, 0, 1);
|
||||
}
|
||||
else if (type == SPEW_SUCCESS)
|
||||
{
|
||||
old = Spew_SetConsoleTextColor(0, 1, 0, 1);
|
||||
}
|
||||
else if (type == SPEW_ERROR)
|
||||
{
|
||||
old = Spew_SetConsoleTextColor(1, 0, 0, 1);
|
||||
}
|
||||
else if (type == SPEW_INFO)
|
||||
{
|
||||
old = Spew_SetConsoleTextColor(0, 1, 1, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
old = Spew_SetConsoleTextColor(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
OutputDebugStringA(text);
|
||||
printf("%s", text);
|
||||
|
||||
Spew_RestoreConsoleTextColor(old);
|
||||
}
|
||||
LeaveCriticalSection(&g_SpewCS);
|
||||
}
|
||||
#endif
|
||||
|
||||
void PrintMessageToOutput(SpewType_t spewtype, char const* pMsgFormat, va_list args)
|
||||
{
|
||||
static char pTempBuffer[4096];
|
||||
int len = 0;
|
||||
vsprintf(&pTempBuffer[len], pMsgFormat, args);
|
||||
|
||||
#ifdef WIN32
|
||||
Spew_ConDebugSpew(spewtype, pTempBuffer);
|
||||
#else
|
||||
printf(pTempBuffer);
|
||||
#endif
|
||||
|
||||
if(g_logStream)
|
||||
fprintf(g_logStream, pTempBuffer);
|
||||
}
|
||||
|
||||
void PsyX_Log(const char* fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, fmt);
|
||||
PrintMessageToOutput(SPEW_NORM, fmt, argptr);
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
void PsyX_Log_Info(const char* fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, fmt);
|
||||
PrintMessageToOutput(SPEW_INFO, fmt, argptr);
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
void PsyX_Log_Warning(const char* fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, fmt);
|
||||
PrintMessageToOutput(SPEW_WARNING, fmt, argptr);
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
void PsyX_Log_Error(const char* fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, fmt);
|
||||
PrintMessageToOutput(SPEW_ERROR, fmt, argptr);
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
void PsyX_Log_Success(const char* fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, fmt);
|
||||
PrintMessageToOutput(SPEW_SUCCESS, fmt, argptr);
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
|
||||
void PsyX_Initialise(char* appName, int width, int height, int fullscreen)
|
||||
{
|
||||
char windowNameStr[512];
|
||||
char windowNameStr[128];
|
||||
|
||||
g_appNameStr = appName;
|
||||
|
||||
PsyX_Log_Initialise();
|
||||
PsyX_GetWindowName(windowNameStr);
|
||||
|
||||
eprintf("Initialising Psy-X %d.%d\n", PSYX_MAJOR_VERSION, PSYX_MINOR_VERSION);
|
||||
eprintf("Build date: %s:%s\n", PSYX_COMPILE_DATE, PSYX_COMPILE_TIME);
|
||||
#if defined(_WIN32) && defined(_DEBUG)
|
||||
if (AllocConsole())
|
||||
{
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
SetConsoleTitleA(windowNameStr);
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
|
||||
}
|
||||
#endif
|
||||
|
||||
eprintinfo("Initialising Psy-X %d.%d\n", PSYX_MAJOR_VERSION, PSYX_MINOR_VERSION);
|
||||
eprintinfo("Build date: %s:%s\n", PSYX_COMPILE_DATE, PSYX_COMPILE_TIME);
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0)
|
||||
{
|
||||
@ -206,6 +410,9 @@ void PsyX_Initialise(char* appName, int width, int height, int fullscreen)
|
||||
}
|
||||
|
||||
PsyX_Sys_InitialiseInput();
|
||||
|
||||
// set shutdown function (PSX apps usualy don't exit)
|
||||
atexit(PsyX_ShutDown);
|
||||
}
|
||||
|
||||
void PsyX_GetScreenSize(int& screenWidth, int& screenHeight)
|
||||
@ -222,6 +429,8 @@ void PsyX_Sys_DoDebugKeys(int nKey, bool down); // forward decl
|
||||
void PsyX_Sys_DoDebugMouseMotion(int x, int y);
|
||||
void GR_ResetDevice();
|
||||
|
||||
void PsyX_Exit();
|
||||
|
||||
void PsyX_Sys_DoPollEvent()
|
||||
{
|
||||
SDL_Event event;
|
||||
@ -229,48 +438,48 @@ void PsyX_Sys_DoPollEvent()
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_CONTROLLERDEVICEADDED:
|
||||
padHandle[event.jbutton.which] = SDL_GameControllerOpen(event.cdevice.which);
|
||||
break;
|
||||
case SDL_CONTROLLERDEVICEREMOVED:
|
||||
SDL_GameControllerClose(padHandle[event.cdevice.which]);
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
PsyX_ShutDown();
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event)
|
||||
{
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
g_windowWidth = event.window.data1;
|
||||
g_windowHeight = event.window.data2;
|
||||
GR_ResetDevice();
|
||||
case SDL_CONTROLLERDEVICEADDED:
|
||||
padHandle[event.jbutton.which] = SDL_GameControllerOpen(event.cdevice.which);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
PsyX_ShutDown();
|
||||
case SDL_CONTROLLERDEVICEREMOVED:
|
||||
SDL_GameControllerClose(padHandle[event.cdevice.which]);
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
PsyX_Exit();
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event)
|
||||
{
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
g_windowWidth = event.window.data1;
|
||||
g_windowHeight = event.window.data2;
|
||||
GR_ResetDevice();
|
||||
break;
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
PsyX_Exit();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
|
||||
PsyX_Sys_DoDebugMouseMotion(event.motion.x, event.motion.y);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
int nKey = event.key.keysym.scancode;
|
||||
|
||||
// lshift/right shift
|
||||
if (nKey == SDL_SCANCODE_RSHIFT)
|
||||
nKey = SDL_SCANCODE_LSHIFT;
|
||||
else if (nKey == SDL_SCANCODE_RCTRL)
|
||||
nKey = SDL_SCANCODE_LCTRL;
|
||||
else if (nKey == SDL_SCANCODE_RALT)
|
||||
nKey = SDL_SCANCODE_LALT;
|
||||
|
||||
PsyX_Sys_DoDebugKeys(nKey, (event.type == SDL_KEYUP) ? false : true);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
|
||||
PsyX_Sys_DoDebugMouseMotion(event.motion.x, event.motion.y);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
int nKey = event.key.keysym.scancode;
|
||||
|
||||
// lshift/right shift
|
||||
if (nKey == SDL_SCANCODE_RSHIFT)
|
||||
nKey = SDL_SCANCODE_LSHIFT;
|
||||
else if (nKey == SDL_SCANCODE_RCTRL)
|
||||
nKey = SDL_SCANCODE_LCTRL;
|
||||
else if (nKey == SDL_SCANCODE_RALT)
|
||||
nKey = SDL_SCANCODE_LALT;
|
||||
|
||||
PsyX_Sys_DoDebugKeys(nKey, (event.type == SDL_KEYUP) ? false : true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -370,12 +579,12 @@ void PsyX_Sys_DoDebugKeys(int nKey, bool down)
|
||||
#ifdef _DEBUG
|
||||
case SDL_SCANCODE_F1:
|
||||
g_wireframeMode ^= 1;
|
||||
eprintf("wireframe mode: %d\n", g_wireframeMode);
|
||||
eprintwarn("wireframe mode: %d\n", g_wireframeMode);
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F2:
|
||||
g_texturelessMode ^= 1;
|
||||
eprintf("textureless mode: %d\n", g_texturelessMode);
|
||||
eprintwarn("textureless mode: %d\n", g_texturelessMode);
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F3:
|
||||
@ -390,13 +599,13 @@ void PsyX_Sys_DoDebugKeys(int nKey, bool down)
|
||||
}
|
||||
break;
|
||||
case SDL_SCANCODE_F10:
|
||||
eprintf("saving VRAM.TGA\n");
|
||||
eprintwarn("saving VRAM.TGA\n");
|
||||
GR_SaveVRAM("VRAM.TGA", 0, 0, VRAM_WIDTH, VRAM_HEIGHT, 1);
|
||||
break;
|
||||
#endif
|
||||
#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__)
|
||||
case SDL_SCANCODE_F12:
|
||||
eprintf("Saving screenshot\n");
|
||||
eprintwarn("Saving screenshot...\n");
|
||||
PsyX_TakeScreenshot();
|
||||
break;
|
||||
#endif
|
||||
@ -408,7 +617,7 @@ void PsyX_Sys_DoDebugKeys(int nKey, bool down)
|
||||
if (activeControllers == 0)
|
||||
activeControllers++;
|
||||
|
||||
eprintf("Active keyboard controller: %d\n", activeControllers);
|
||||
eprintwarn("Active keyboard controller: %d\n", activeControllers);
|
||||
break;
|
||||
case SDL_SCANCODE_F5:
|
||||
g_pgxpTextureCorrection ^= 1;
|
||||
@ -426,7 +635,7 @@ void PsyX_UpdateInput()
|
||||
// also poll events here
|
||||
PsyX_Sys_DoPollEvent();
|
||||
|
||||
InternalPadUpdates();
|
||||
PsyX_InternalPadUpdates();
|
||||
}
|
||||
|
||||
uint PsyX_CalcFPS()
|
||||
@ -450,9 +659,6 @@ uint PsyX_CalcFPS()
|
||||
|
||||
void PsyX_WaitForTimestep(int count)
|
||||
{
|
||||
SDL_LockMutex(g_intrMutex);
|
||||
SDL_UnlockMutex(g_intrMutex);
|
||||
|
||||
#if 0 // defined(RENDERER_OGL) || defined(OGLES)
|
||||
glFinish(); // best time to complete GPU drawing
|
||||
#endif
|
||||
@ -472,8 +678,18 @@ void PsyX_WaitForTimestep(int count)
|
||||
}
|
||||
}
|
||||
|
||||
void PsyX_ShutdownSound();
|
||||
|
||||
void PsyX_Exit()
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void PsyX_ShutDown()
|
||||
{
|
||||
if (!g_window)
|
||||
return;
|
||||
|
||||
// quit vblank thread
|
||||
if (g_intrThread)
|
||||
{
|
||||
@ -487,11 +703,14 @@ void PsyX_ShutDown()
|
||||
SDL_DestroyMutex(g_intrMutex);
|
||||
|
||||
GR_Shutdown();
|
||||
PsyX_ShutdownSound();
|
||||
|
||||
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
|
||||
SDL_DestroyWindow(g_window);
|
||||
g_window = NULL;
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
exit(0);
|
||||
PsyX_Log_Finalise();
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ void PBO_Download(GrPBO& pbo)
|
||||
}
|
||||
else
|
||||
{
|
||||
eprinterr("Failed to map the buffer");
|
||||
eprintwarn("Failed to map the buffer\n");
|
||||
}
|
||||
|
||||
/* Trigger the next read. */
|
||||
@ -440,6 +440,16 @@ int GR_InitialiseRender(char* windowName, int width, int height, int fullscreen)
|
||||
void GR_Shutdown()
|
||||
{
|
||||
#if defined(RENDERER_OGL) || defined(OGLES)
|
||||
glDeleteVertexArrays(1, &g_glVertexArray);
|
||||
glDeleteBuffers(1, &g_glVertexBuffer);
|
||||
|
||||
PBO_Destroy(g_glFramebufferPBO);
|
||||
PBO_Destroy(g_glOffscreenPBO);
|
||||
|
||||
glDeleteFramebuffers(1, &g_glBlitFramebuffer);
|
||||
glDeleteFramebuffers(1, &g_glOffscreenFramebuffer);
|
||||
glDeleteFramebuffers(1, &g_glVRAMFramebuffer);
|
||||
|
||||
GR_DestroyTexture(g_vramTexture);
|
||||
GR_DestroyTexture(g_whiteTexture);
|
||||
GR_DestroyTexture(g_fbTexture);
|
||||
|
@ -74,7 +74,8 @@ workspace "REDRIVER2"
|
||||
|
||||
-- game iteslf
|
||||
project "REDRIVER2"
|
||||
kind "ConsoleApp"
|
||||
kind "WindowedApp"
|
||||
|
||||
language "c++"
|
||||
targetdir "bin/%{cfg.buildcfg}"
|
||||
|
||||
@ -119,12 +120,14 @@ project "REDRIVER2"
|
||||
}
|
||||
|
||||
filter "system:Windows"
|
||||
entrypoint "mainCRTStartup"
|
||||
|
||||
files {
|
||||
"Windows/resource.h",
|
||||
"Windows/Resource.rc",
|
||||
"Windows/main.ico"
|
||||
}
|
||||
|
||||
|
||||
includedirs {
|
||||
SDL2_DIR.."/include",
|
||||
OPENAL_DIR.."/include",
|
||||
|
@ -26,167 +26,6 @@
|
||||
|
||||
#include "PSYX_GLOBALS.H"
|
||||
|
||||
// eq engine console output
|
||||
typedef enum
|
||||
{
|
||||
SPEW_NORM,
|
||||
SPEW_INFO,
|
||||
SPEW_WARNING,
|
||||
SPEW_ERROR,
|
||||
SPEW_SUCCESS,
|
||||
}SpewType_t;
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
|
||||
static unsigned short g_InitialColor = 0xFFFF;
|
||||
static unsigned short g_LastColor = 0xFFFF;
|
||||
static unsigned short g_BadColor = 0xFFFF;
|
||||
static WORD g_BackgroundFlags = 0xFFFF;
|
||||
|
||||
static void GetInitialColors()
|
||||
{
|
||||
// Get the old background attributes.
|
||||
CONSOLE_SCREEN_BUFFER_INFO oldInfo;
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &oldInfo);
|
||||
g_InitialColor = g_LastColor = oldInfo.wAttributes & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
|
||||
g_BackgroundFlags = oldInfo.wAttributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
|
||||
|
||||
g_BadColor = 0;
|
||||
if (g_BackgroundFlags & BACKGROUND_RED)
|
||||
g_BadColor |= FOREGROUND_RED;
|
||||
if (g_BackgroundFlags & BACKGROUND_GREEN)
|
||||
g_BadColor |= FOREGROUND_GREEN;
|
||||
if (g_BackgroundFlags & BACKGROUND_BLUE)
|
||||
g_BadColor |= FOREGROUND_BLUE;
|
||||
if (g_BackgroundFlags & BACKGROUND_INTENSITY)
|
||||
g_BadColor |= FOREGROUND_INTENSITY;
|
||||
}
|
||||
|
||||
static WORD SetConsoleTextColor(int red, int green, int blue, int intensity)
|
||||
{
|
||||
WORD ret = g_LastColor;
|
||||
|
||||
g_LastColor = 0;
|
||||
if (red) g_LastColor |= FOREGROUND_RED;
|
||||
if (green) g_LastColor |= FOREGROUND_GREEN;
|
||||
if (blue) g_LastColor |= FOREGROUND_BLUE;
|
||||
if (intensity) g_LastColor |= FOREGROUND_INTENSITY;
|
||||
|
||||
// Just use the initial color if there's a match...
|
||||
if (g_LastColor == g_BadColor)
|
||||
g_LastColor = g_InitialColor;
|
||||
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), g_LastColor | g_BackgroundFlags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void RestoreConsoleTextColor(WORD color)
|
||||
{
|
||||
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color | g_BackgroundFlags);
|
||||
g_LastColor = color;
|
||||
}
|
||||
|
||||
CRITICAL_SECTION g_SpewCS;
|
||||
bool g_bSpewCSInitted = false;
|
||||
|
||||
void fnConDebugSpew(SpewType_t type, char* text)
|
||||
{
|
||||
// Hopefully two threads won't call this simultaneously right at the start!
|
||||
if (!g_bSpewCSInitted)
|
||||
{
|
||||
GetInitialColors();
|
||||
InitializeCriticalSection(&g_SpewCS);
|
||||
g_bSpewCSInitted = true;
|
||||
}
|
||||
|
||||
WORD old;
|
||||
EnterCriticalSection(&g_SpewCS);
|
||||
{
|
||||
if (type == SPEW_NORM)
|
||||
{
|
||||
old = SetConsoleTextColor(1, 1, 1, 0);
|
||||
}
|
||||
else if (type == SPEW_WARNING)
|
||||
{
|
||||
old = SetConsoleTextColor(1, 1, 0, 1);
|
||||
}
|
||||
else if (type == SPEW_SUCCESS)
|
||||
{
|
||||
old = SetConsoleTextColor(0, 1, 0, 1);
|
||||
}
|
||||
else if (type == SPEW_ERROR)
|
||||
{
|
||||
old = SetConsoleTextColor(1, 0, 0, 1);
|
||||
}
|
||||
else if (type == SPEW_INFO)
|
||||
{
|
||||
old = SetConsoleTextColor(0, 1, 1, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
old = SetConsoleTextColor(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
OutputDebugStringA(text);
|
||||
printf("%s", text);
|
||||
|
||||
RestoreConsoleTextColor(old);
|
||||
}
|
||||
LeaveCriticalSection(&g_SpewCS);
|
||||
}
|
||||
#endif
|
||||
|
||||
void SpewMessageToOutput(SpewType_t spewtype, char const* pMsgFormat, va_list args)
|
||||
{
|
||||
static char pTempBuffer[4096];
|
||||
int len = 0;
|
||||
vsprintf(&pTempBuffer[len], pMsgFormat, args);
|
||||
|
||||
#ifdef WIN32
|
||||
fnConDebugSpew(spewtype, pTempBuffer);
|
||||
#else
|
||||
printf(pTempBuffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
void printMsg(char *fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, fmt);
|
||||
SpewMessageToOutput(SPEW_NORM, fmt, argptr);
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
void printInfo(char *fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, fmt);
|
||||
SpewMessageToOutput(SPEW_INFO, fmt, argptr);
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
void printWarning(char *fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, fmt);
|
||||
SpewMessageToOutput(SPEW_WARNING, fmt, argptr);
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
void printError(char *fmt, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, fmt);
|
||||
SpewMessageToOutput(SPEW_ERROR, fmt, argptr);
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
int(*GPU_printf)(const char *fmt, ...);
|
||||
|
||||
bool CtrlModifier;
|
||||
|
Loading…
Reference in New Issue
Block a user