Author SHA1 Message Date
fgsfds bc9b4d1a39 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2025-04-27 15:46:02 +02:00
fgsfds 9633e7eac6 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2025-03-16 09:19:26 +01:00
fgsfds 42a151a84d Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2025-01-31 17:45:35 +01:00
fgsfds 7cfead440b Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2025-01-05 15:46:08 +01:00
fgsfds 85af83859e Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2025-01-05 12:33:23 +01:00
fgsfds 1b803d792f Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-11-29 09:58:11 +01:00
fgsfds cee61eeb75 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-11-23 20:40:46 +01:00
fgsfds 4883fde642 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-11-23 12:35:52 +01:00
fgsfds fc865fe8cd Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-11-19 18:33:37 +01:00
fgsfds c45763d47c Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-11-17 11:09:14 +01:00
fgsfds 9812d86a24 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-11-16 15:39:29 +01:00
fgsfds ed5865b350 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-11-16 15:30:41 +01:00
fgsfds 2e9de9455b Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-11-16 12:56:09 +01:00
fgsfds 3852b28194 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-11-13 09:09:57 +01:00
fgsfds 0e7fb4f6b2 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-11-13 08:55:27 +01:00
fgsfds 4a7df4de4b Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-11-13 08:51:00 +01:00
fgsfds 8d6a19f55b Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-11-12 23:13:40 +01:00
fgsfds 507cc5a13b Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-11-12 14:40:15 +01:00
fgsfds 87e8a3f1af Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-09-02 11:03:54 +02:00
fgsfds 18ad06e3d7 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-09-02 10:05:51 +02:00
fgsfds c8383babcc Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-08-06 16:54:45 +02:00
fgsfds b9eb0f2747 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-08-05 11:42:57 +02:00
fgsfds 8d5e94e121 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-08-04 11:16:01 +02:00
fgsfds 946a3166b3 Merge branch 'port' into port-debugger 2024-05-19 19:45:46 +02:00
fgsfds e6eaca9e3d Merge branch 'port' into port-debugger 2024-05-18 19:33:28 +02:00
fgsfds fbb6669e23 Merge branch 'port' into port-debugger 2024-05-18 19:18:45 +02:00
fgsfds cf19cebc27 Merge branch 'port' into port-debugger 2024-05-18 19:02:37 +02:00
fgsfds 4c0cbbf554 Merge branch 'port' into port-debugger 2024-05-15 14:11:37 +02:00
fgsfds 9d44606a4c Merge branch 'port' into port-debugger 2024-05-15 13:39:27 +02:00
fgsfds e326c14760 Merge branch 'port' into port-debugger 2024-05-15 12:29:51 +02:00
fgsfds e13e03fd7f Merge branch 'port' into port-debugger 2024-05-15 12:13:51 +02:00
fgsfds 04a6f64a95 Merge branch 'port' into port-debugger 2024-05-14 23:16:54 +02:00
fgsfds 39e2f7730d Merge branch 'port' into port-debugger 2024-05-14 22:57:00 +02:00
fgsfds 083cae49c6 Merge branch 'port' into port-debugger 2024-05-14 22:53:15 +02:00
fgsfds 6e8190062c Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-05-14 22:24:18 +02:00
fgsfds 9ee2391a69 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-05-14 22:17:16 +02:00
fgsfds 7f886a817c Merge branch 'port' into port-debugger 2024-05-14 21:06:34 +02:00
fgsfds d9037ba1da Merge branch 'port' into port-debugger 2024-05-14 20:35:46 +02:00
fgsfds 8d8650ebd0 Merge branch 'port' into port-debugger 2024-05-14 12:07:28 +02:00
fgsfds 75331721f7 Merge branch 'port' into port-debugger 2024-05-14 11:38:39 +02:00
fgsfds 2623918359 Merge branch 'port' into port-debugger 2024-05-14 11:29:36 +02:00
fgsfds 265d21c35d Merge branch 'port' into port-debugger 2024-05-14 11:13:03 +02:00
fgsfds 5fea484089 Merge branch 'port' into port-debugger 2024-05-14 10:57:04 +02:00
fgsfds 322892e254 Merge branch 'port' into port-debugger 2024-05-14 10:35:22 +02:00
fgsfds 4e0025a847 Merge branch 'port' into port-debugger 2024-05-14 10:15:49 +02:00
fgsfds 38ff8ca5df Merge branch 'port' into port-debugger 2024-05-13 22:23:24 +02:00
fgsfds 9270b6647a Merge branch 'port' into port-debugger 2024-05-13 18:49:59 +02:00
fgsfds e5effc4522 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-05-13 15:27:21 +02:00
fgsfds 22e49d75e1 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-05-13 12:20:29 +02:00
fgsfds f8617ebbd6 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-05-13 01:16:05 +02:00
fgsfds bf1b8da629 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-05-13 00:31:54 +02:00
fgsfds 86eaa624a3 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-05-12 16:32:00 +02:00
fgsfds c2fcb992ca Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-05-12 16:26:39 +02:00
fgsfds 54ba0d41c1 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-05-12 16:22:49 +02:00
fgsfds 2c0abcb0e2 one more gcc14 fix 2024-05-11 14:46:21 +02:00
fgsfds 5554fb7219 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-05-11 14:14:34 +02:00
fgsfds 804674e2b1 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-03-09 22:38:49 +01:00
fgsfds 20534a731b Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-03-09 17:45:50 +01:00
fgsfds 242a89a622 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-03-09 17:40:37 +01:00
fgsfds 04e2ed51a6 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-02-13 01:18:08 +01:00
fgsfds 11fd86002b Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2024-02-12 16:38:09 +01:00
fgsfds 75c4905e9b Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2023-12-04 21:36:58 +01:00
fgsfds 336b7825c7 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2023-12-03 03:53:02 +01:00
fgsfds 63046b4a00 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2023-11-27 09:54:47 +01:00
fgsfds 5affafacbd port: debugger: add framerate divisor setting 2023-11-26 19:38:54 +01:00
fgsfds 8ca7f79c1e Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2023-11-26 19:26:54 +01:00
fgsfds f72b2968f2 port: add surface hit info 2023-11-25 19:14:20 +01:00
fgsfds 5c152c1842 port: move prop info to imgui window 2023-11-25 18:51:35 +01:00
fgsfds 0cf6021727 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2023-11-25 14:14:08 +01:00
fgsfds aa6ac4b5cc Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2023-11-15 22:36:28 +01:00
fgsfds df2ba8ec7d Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2023-11-12 15:07:13 +01:00
fgsfds 10baed1ee1 Merge branch 'port' of https://github.com/fgsfdsfgs/perfect_dark into port-debugger 2023-10-22 15:25:42 +02:00
fgsfds ac46cf80aa Merge branch 'port' into port-debugger 2023-10-16 23:20:03 +02:00
fgsfds 704153d7e1 port: debugger: add a way to list all props 2023-10-09 15:49:58 +02:00
fgsfds e6919bc247 port: debugger: alert user if stuff falls out of the world 2023-10-09 15:31:34 +02:00
fgsfds b74bc59164 port: debugger: add on-screen info and some chr manipulation 2023-10-09 12:25:57 +02:00
fgsfds d7a6c29552 add LICENSE for imgui 2023-10-09 01:52:06 +02:00
fgsfds 9e1189747d ci: will this build the debugger branch? 2023-10-09 01:37:27 +02:00
fgsfds 4085ae5806 port: debugger: add janky imgui debugger
maybe it'll help figuring out some of the gameplay bugs
2023-10-09 01:35:36 +02:00
31 changed files with 55403 additions and 26 deletions

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@ name: C/C++ CI
on: on:
push: push:
branches: [ "port" ] branches: [ "port", "port-debugger" ]
pull_request: pull_request:
branches: [ "port" ] branches: [ "port" ]
workflow_dispatch: workflow_dispatch:
+1
View File
@@ -160,6 +160,7 @@ include_directories("${CMAKE_BINARY_DIR}/src/generated/${ROMID}")
include_directories("${CMAKE_SOURCE_DIR}/src/lib/ultra/audio") include_directories("${CMAKE_SOURCE_DIR}/src/lib/ultra/audio")
include_directories("${CMAKE_SOURCE_DIR}/port/include") include_directories("${CMAKE_SOURCE_DIR}/port/include")
include_directories("${CMAKE_BINARY_DIR}/port/include") include_directories("${CMAKE_BINARY_DIR}/port/include")
include_directories("${CMAKE_SOURCE_DIR}/port/src/imgui")
# Set Release optimization to -Og until I fix the -O2 issues # Set Release optimization to -Og until I fix the -O2 issues
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug"))
+3
View File
@@ -98,7 +98,10 @@ extern void bzero(void *, size_t);
#ifdef PLATFORM_N64 #ifdef PLATFORM_N64
extern int sprintf(char *s, const char *fmt, ...); extern int sprintf(char *s, const char *fmt, ...);
#else
#include <stdio.h>
#endif #endif
extern void osSyncPrintf(const char *fmt, ...); extern void osSyncPrintf(const char *fmt, ...);
+21
View File
@@ -0,0 +1,21 @@
#ifndef _IN_DEBUGGER_H
#define _IN_DEBUGGER_H
#include <PR/ultratypes.h>
#include <PR/gbi.h>
extern s32 g_DebuggerActive;
extern s32 g_DebuggerTimePasses;
extern s32 g_DebuggerFrameAdvance;
void debuggerInit(void);
void debuggerProcessEvent(void *event);
void debuggerStartFrame(void);
void debuggerFrame(void);
void debuggerEndFrame(void);
void debuggerUpdatePropInfo(s32 clear);
Gfx *debuggerDrawPropInfo(Gfx *gdl);
#endif
+905
View File
@@ -0,0 +1,905 @@
#include <string>
#include <SDL.h>
#include "imgui/imgui.h"
#include "imgui/backends/imgui_impl_sdlrenderer2.h"
#include "imgui/backends/imgui_impl_sdl2.h"
extern "C"
{
#include <PR/ultratypes.h>
#include <PR/gbi.h>
#include <gbiex.h>
#include "data.h"
#include "bss.h"
#include "constants.h"
#include "game/stagetable.h"
#include "game/chr.h"
#include "game/chraction.h"
#include "game/bg.h"
#include "game/player.h"
#include "game/propobj.h"
#include "game/prop.h"
#include "game/sight.h"
#include "game/game_1531a0.h"
#include "lib/memp.h"
#include "lib/mema.h"
#include "lib/vi.h"
#include "lib/lib_17ce0.h"
#include "video.h"
#include "input.h"
#include "system.h"
#include "utils.h"
#include "romdata.h"
#undef bool
#undef true
#undef false
s32 g_DebuggerActive = FALSE;
s32 g_DebuggerTimePasses = TRUE;
s32 g_DebuggerFrameAdvance = 0;
u32 memaGetSize(void);
}
static SDL_Window *dbgwin = nullptr;
static SDL_Renderer *dbgren = nullptr;
static char xstr[64] = "0";
static char ystr[64] = "0";
static char zstr[64] = "0";
static char gotostr[64] = "";
static bool advanceHeld = false;
static s32 propFilter = 0;
static s32 objFilter = 0;
static const char *propTypes[9];
static const char *objTypes[0x3c];
static bool expandLatch = false;
static bool expandValue = false;
static bool showPropInfo = false;
static bool showActiveProps = true;
static void *focusPtr = nullptr;
static struct prop *lookatprop = nullptr;
static struct hitthing lookathit;
static bool lookathitset;
static inline const char *fmtCoord(const coord& crd)
{
static char tmp[128];
snprintf(tmp, sizeof(tmp), "(%.2f, %.2f, %.2f)", crd.x, crd.y, crd.z);
return tmp;
}
#define DEF_ACT_NAME(x) case x: return #x;
static inline const char *fmtActionType(s8 at)
{
switch (at) {
DEF_ACT_NAME(ACT_INIT )
DEF_ACT_NAME(ACT_STAND )
DEF_ACT_NAME(ACT_KNEEL )
DEF_ACT_NAME(ACT_ANIM )
DEF_ACT_NAME(ACT_DIE )
DEF_ACT_NAME(ACT_DEAD )
DEF_ACT_NAME(ACT_ARGH )
DEF_ACT_NAME(ACT_PREARGH )
DEF_ACT_NAME(ACT_ATTACK )
DEF_ACT_NAME(ACT_ATTACKWALK )
DEF_ACT_NAME(ACT_ATTACKROLL )
DEF_ACT_NAME(ACT_SIDESTEP )
DEF_ACT_NAME(ACT_JUMPOUT )
DEF_ACT_NAME(ACT_RUNPOS )
DEF_ACT_NAME(ACT_PATROL )
DEF_ACT_NAME(ACT_GOPOS )
DEF_ACT_NAME(ACT_SURRENDER )
DEF_ACT_NAME(ACT_LOOKATTARGET )
DEF_ACT_NAME(ACT_SURPRISED )
DEF_ACT_NAME(ACT_STARTALARM )
DEF_ACT_NAME(ACT_THROWGRENADE )
DEF_ACT_NAME(ACT_TURNDIR )
DEF_ACT_NAME(ACT_TEST )
DEF_ACT_NAME(ACT_BONDINTRO )
DEF_ACT_NAME(ACT_BONDDIE )
DEF_ACT_NAME(ACT_BONDMULTI )
DEF_ACT_NAME(ACT_NULL )
DEF_ACT_NAME(ACT_BOT_ATTACKSTAND )
DEF_ACT_NAME(ACT_BOT_ATTACKKNEEL )
DEF_ACT_NAME(ACT_BOT_ATTACKSTRAFE)
DEF_ACT_NAME(ACT_DRUGGEDDROP )
DEF_ACT_NAME(ACT_DRUGGEDKO )
DEF_ACT_NAME(ACT_DRUGGEDCOMINGUP )
DEF_ACT_NAME(ACT_ATTACKAMOUNT )
DEF_ACT_NAME(ACT_ROBOTATTACK )
DEF_ACT_NAME(ACT_SKJUMP )
DEF_ACT_NAME(ACT_PUNCH )
DEF_ACT_NAME(ACT_CUTFIRE )
default: return "ACT";
}
}
static inline const char *fmtPropType(u8 at)
{
switch (at) {
DEF_ACT_NAME(PROPTYPE_OBJ)
DEF_ACT_NAME(PROPTYPE_DOOR)
DEF_ACT_NAME(PROPTYPE_CHR)
DEF_ACT_NAME(PROPTYPE_WEAPON)
DEF_ACT_NAME(PROPTYPE_EYESPY)
DEF_ACT_NAME(PROPTYPE_PLAYER)
DEF_ACT_NAME(PROPTYPE_EXPLOSION)
DEF_ACT_NAME(PROPTYPE_SMOKE)
default: return "Prop";
}
}
static inline const char *fmtObjType(u8 at)
{
switch (at) {
DEF_ACT_NAME(OBJTYPE_DOOR )
DEF_ACT_NAME(OBJTYPE_DOORSCALE )
DEF_ACT_NAME(OBJTYPE_BASIC )
DEF_ACT_NAME(OBJTYPE_KEY )
DEF_ACT_NAME(OBJTYPE_ALARM )
DEF_ACT_NAME(OBJTYPE_CCTV )
DEF_ACT_NAME(OBJTYPE_AMMOCRATE )
DEF_ACT_NAME(OBJTYPE_WEAPON )
DEF_ACT_NAME(OBJTYPE_CHR )
DEF_ACT_NAME(OBJTYPE_SINGLEMONITOR )
DEF_ACT_NAME(OBJTYPE_MULTIMONITOR )
DEF_ACT_NAME(OBJTYPE_HANGINGMONITORS )
DEF_ACT_NAME(OBJTYPE_AUTOGUN )
DEF_ACT_NAME(OBJTYPE_LINKGUNS )
DEF_ACT_NAME(OBJTYPE_DEBRIS )
DEF_ACT_NAME(OBJTYPE_10 )
DEF_ACT_NAME(OBJTYPE_HAT )
DEF_ACT_NAME(OBJTYPE_GRENADEPROB )
DEF_ACT_NAME(OBJTYPE_LINKLIFTDOOR )
DEF_ACT_NAME(OBJTYPE_MULTIAMMOCRATE )
DEF_ACT_NAME(OBJTYPE_SHIELD )
DEF_ACT_NAME(OBJTYPE_TAG )
DEF_ACT_NAME(OBJTYPE_BEGINOBJECTIVE )
DEF_ACT_NAME(OBJTYPE_ENDOBJECTIVE )
DEF_ACT_NAME(OBJECTIVETYPE_DESTROYOBJ )
DEF_ACT_NAME(OBJECTIVETYPE_COMPFLAGS )
DEF_ACT_NAME(OBJECTIVETYPE_FAILFLAGS )
DEF_ACT_NAME(OBJECTIVETYPE_COLLECTOBJ )
DEF_ACT_NAME(OBJECTIVETYPE_THROWOBJ )
DEF_ACT_NAME(OBJECTIVETYPE_HOLOGRAPH )
DEF_ACT_NAME(OBJECTIVETYPE_1F )
DEF_ACT_NAME(OBJECTIVETYPE_ENTERROOM )
DEF_ACT_NAME(OBJECTIVETYPE_THROWINROOM )
DEF_ACT_NAME(OBJTYPE_22 )
DEF_ACT_NAME(OBJTYPE_BRIEFING )
DEF_ACT_NAME(OBJTYPE_GASBOTTLE )
DEF_ACT_NAME(OBJTYPE_RENAMEOBJ )
DEF_ACT_NAME(OBJTYPE_PADLOCKEDDOOR )
DEF_ACT_NAME(OBJTYPE_TRUCK )
DEF_ACT_NAME(OBJTYPE_HELI )
DEF_ACT_NAME(OBJTYPE_29 )
DEF_ACT_NAME(OBJTYPE_GLASS )
DEF_ACT_NAME(OBJTYPE_SAFE )
DEF_ACT_NAME(OBJTYPE_SAFEITEM )
DEF_ACT_NAME(OBJTYPE_TANK )
DEF_ACT_NAME(OBJTYPE_CAMERAPOS )
DEF_ACT_NAME(OBJTYPE_TINTEDGLASS )
DEF_ACT_NAME(OBJTYPE_LIFT )
DEF_ACT_NAME(OBJTYPE_CONDITIONALSCENERY)
DEF_ACT_NAME(OBJTYPE_BLOCKEDPATH )
DEF_ACT_NAME(OBJTYPE_HOVERBIKE )
DEF_ACT_NAME(OBJTYPE_END )
DEF_ACT_NAME(OBJTYPE_HOVERPROP )
DEF_ACT_NAME(OBJTYPE_FAN )
DEF_ACT_NAME(OBJTYPE_HOVERCAR )
DEF_ACT_NAME(OBJTYPE_PADEFFECT )
DEF_ACT_NAME(OBJTYPE_CHOPPER )
DEF_ACT_NAME(OBJTYPE_MINE )
DEF_ACT_NAME(OBJTYPE_ESCASTEP )
default: return "Obj";
}
}
#undef DEF_ACT_NAME
extern "C" void debuggerInit(void)
{
SDL_Window *parent = (SDL_Window *)videoGetWindowHandle();
int px = 0;
int py = 0;
int pw = 0;
int ph = 0;
// in windowed mode put the debugger to the right of the window
if ((SDL_GetWindowFlags(parent) & SDL_WINDOW_FULLSCREEN_DESKTOP) == 0) {
SDL_GetWindowPosition(parent, &px, &py);
SDL_GetWindowSize(parent, &pw, &ph);
}
const Uint32 winflags = SDL_WINDOW_RESIZABLE;
dbgwin = SDL_CreateWindow("Debugger", px + pw + 4, py, 320, ph, winflags);
if (!dbgwin) {
sysLogPrintf(LOG_ERROR, "DBG: could not create SDL window: %s", SDL_GetError());
return;
}
// can't trust any hardware accelerated windows to live in harmony with our main window, so force SW
dbgren = SDL_CreateRenderer(dbgwin, -1, SDL_RENDERER_SOFTWARE);
if (!dbgren) {
sysLogPrintf(LOG_ERROR, "DBG: could not create SDL renderer: %s", SDL_GetError());
return;
}
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.IniFilename = nullptr;
ImGui::StyleColorsDark();
ImGui_ImplSDL2_InitForSDLRenderer(dbgwin, dbgren);
ImGui_ImplSDLRenderer2_Init(dbgren);
propTypes[0] = "NONE";
for (s32 i = 1; i < ARRAYCOUNT(propTypes); ++i) {
propTypes[i] = fmtPropType(i);
}
objTypes[0] = "NONE";
for (s32 i = 1; i < ARRAYCOUNT(objTypes); ++i) {
objTypes[i] = fmtObjType(i);
}
g_DebuggerActive = TRUE;
}
static inline void debuggerHotKey(const s32 key, const bool pressed)
{
switch (key) {
case SDLK_F1:
if (pressed)
g_DebuggerTimePasses ^= 1;
break;
case SDLK_F2:
if (pressed)
g_DebuggerFrameAdvance = 1;
break;
case SDLK_F3:
if (pressed)
g_DebuggerFrameAdvance = 5;
break;
case SDLK_F4:
advanceHeld = pressed;
break;
case SDLK_F5:
if (pressed) {
if (g_TickRateDiv <= 1) {
g_TickRateDiv = 2;
} else {
g_TickRateDiv = 1;
}
}
break;
case SDLK_F6:
if (pressed) {
g_TickRateDiv++;
if (g_TickRateDiv > 5) {
g_TickRateDiv = 0;
}
}
break;
default:
break;
}
}
extern "C" void debuggerProcessEvent(void *data)
{
if (g_DebuggerActive) {
SDL_Event *e = (SDL_Event *)data;
if (e->type == SDL_KEYDOWN || e->type == SDL_KEYUP) {
debuggerHotKey(e->key.keysym.sym, e->type == SDL_KEYDOWN);
} else if (e->type == SDL_MOUSEBUTTONDOWN || e->type == SDL_MOUSEBUTTONUP) {
if (SDL_GetMouseFocus() != dbgwin || SDL_GetWindowID(dbgwin) != e->button.windowID) {
return;
}
} else if (e->type == SDL_MOUSEMOTION) {
if (SDL_GetMouseFocus() != dbgwin || SDL_GetWindowID(dbgwin) != e->motion.windowID) {
return;
}
} else if (e->type == SDL_MOUSEWHEEL) {
if (SDL_GetMouseFocus() != dbgwin || SDL_GetWindowID(dbgwin) != e->wheel.windowID) {
return;
}
}
ImGui_ImplSDL2_ProcessEvent(e);
}
}
extern "C" void debuggerStartFrame(void)
{
ImGui_ImplSDLRenderer2_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
}
static inline bool debuggerGetSurfaceInfo(struct hitthing *hit)
{
struct coord endpos;
endpos.x = g_Vars.currentplayer->cam_pos.x + g_Vars.currentplayer->cam_look.x * 10000.f;
endpos.y = g_Vars.currentplayer->cam_pos.y + g_Vars.currentplayer->cam_look.y * 10000.f;
endpos.z = g_Vars.currentplayer->cam_pos.z + g_Vars.currentplayer->cam_look.z * 10000.f;
// get what rooms the LOS goes through
RoomNum outrooms[17], tmprooms[8], srcrooms[2];
srcrooms[0] = g_Vars.currentplayer->cam_room;
srcrooms[1] = -1;
outrooms[16] = -1;
portal00018148(&g_Vars.currentplayer->cam_pos, &endpos, srcrooms, tmprooms, outrooms, 16);
// no prop was hit; check for bg hits
for (s32 i = 0; outrooms[i] != -1; ++i) {
if (bgTestHitInRoom(&g_Vars.currentplayer->cam_pos, &endpos, outrooms[i], hit)) {
return true;
}
}
return false;
}
extern "C" void debuggerUpdatePropInfo(s32 clear)
{
if (showPropInfo) {
if (clear) {
lookatprop = nullptr;
lookathitset = false;
} else {
lookatprop = propFindAimingAt(HAND_RIGHT, false, FINDPROPCONTEXT_QUERY);
if (!lookatprop) {
// if we aren't looking at a prop, try to get the surface we're looking at
lookathitset = debuggerGetSurfaceInfo(&lookathit);
} else {
lookathitset = false;
}
}
} else {
lookatprop = nullptr;
lookathitset = false;
}
}
static inline void debuggerTeleportPlayer(struct coord& crd)
{
sysLogPrintf(LOG_NOTE, "DBG: teleporting player 1 to (%.2f, %.2f, %.2f)", crd.x, crd.y, crd.z);
if (!g_Vars.players[0] || !g_Vars.players[0]->prop) {
sysLogPrintf(LOG_NOTE, "DBG: no player 1 or player 1 has no prop");
return;
}
struct chrdata *playerchr = g_Vars.players[0]->prop->chr;
if (!playerchr) {
sysLogPrintf(LOG_NOTE, "DBG: player 1 has no chr");
return;
}
RoomNum inrooms[9] = { -1 };
RoomNum aboverooms[9] = { -1 };
bgFindRoomsByPos(&crd, inrooms, aboverooms, 8, NULL);
RoomNum *rooms = NULL;
if (inrooms[0] != -1) {
rooms = inrooms;
} else if (aboverooms[0] != -1) {
rooms = aboverooms;
}
if (rooms) {
const u32 old = playerchr->hidden;
playerchr->hidden |= CHRHFLAG_WARPONSCREEN;
chrMoveToPos(playerchr, &crd, rooms, g_Vars.players[0]->vv_theta, true);
if ((old & CHRHFLAG_WARPONSCREEN) == 0) {
playerchr->hidden &= ~CHRHFLAG_WARPONSCREEN;
}
} else {
sysLogPrintf(LOG_NOTE, "DBG: could not find any rooms at teleport destination");
}
}
static inline void debuggerKillChr(struct chrdata *chr)
{
struct coord dmgdir = { 0.f, 0.f, 0.f };
chrDamageByImpact(chr, 10000.f, &dmgdir, nullptr, nullptr, HITPART_GENERAL);
}
static inline void debuggerKillPlayer(void)
{
sysLogPrintf(LOG_NOTE, "DBG: killing player 1");
if (!g_Vars.players[0] || !g_Vars.players[0]->prop) {
sysLogPrintf(LOG_NOTE, "DBG: no player 1 or player 1 has no prop");
return;
}
struct chrdata *playerchr = g_Vars.players[0]->prop->chr;
if (!playerchr) {
sysLogPrintf(LOG_NOTE, "DBG: player 1 has no chr");
return;
}
debuggerKillChr(playerchr);
}
static inline void debuggerHealPlayer(void)
{
sysLogPrintf(LOG_NOTE, "DBG: healing player 1");
if (!g_Vars.players[0] || !g_Vars.players[0]->prop) {
sysLogPrintf(LOG_NOTE, "DBG: no player 1 or player 1 has no prop");
return;
}
player *prev = g_Vars.currentplayer;
g_Vars.currentplayer = g_Vars.players[0];
playerDisplayHealth();
g_Vars.currentplayer->bondhealth = 1.f;
g_Vars.currentplayer = prev;
}
static inline void describeHand(hand *hand)
{
ImGui::Text("Gun num: %02x", hand->gset.weaponnum);
ImGui::Text("Gun func: %02x", hand->gset.weaponfunc);
ImGui::Text("Aim pos: %s", fmtCoord(hand->aimpos));
ImGui::Text("Hit pos: %s", fmtCoord(hand->hitpos));
}
static inline std::string& describeRoomList(RoomNum *rooms, s32 maxRooms, std::string& out)
{
for (s32 i = 0; i < maxRooms && rooms[i] >= 0; ++i) {
out += strFmt("%03x ", rooms[i]);
}
return out;
}
static inline void describeProjectile(projectile *prj)
{
ImGui::Text("Drop type: %04x", (u16)prj->droptype);
ImGui::Text("Flags: %08x", prj->flags);
ImGui::Text("Vel: %s", fmtCoord(prj->speed));
}
static inline void describeObj(defaultobj *obj)
{
ImGui::Text("Type: %s (%02x)", fmtObjType(obj->type), obj->type);
ImGui::Text("Model: %04x", (u16)obj->modelnum);
ImGui::Text("Pad: %04x", (u16)obj->pad);
ImGui::Text("Flags 1: %08x", obj->flags);
ImGui::Text("Flags 2: %08x", obj->flags2);
ImGui::Text("Flags 3: %08x", obj->flags3);
ImGui::Text("Hidden 1: %08x", obj->hidden);
ImGui::Text("Hidden 2: %02x", obj->hidden2);
if ((obj->hidden & OBJHFLAG_PROJECTILE) && obj->projectile) {
if (ImGui::TreeNode(strFmt("Projectile (%p)", obj->projectile))) {
describeProjectile(obj->projectile);
ImGui::TreePop();
}
}
}
static inline void describeWeapon(weaponobj *wpn)
{
ImGui::Text("Gun num: %02x", wpn->weaponnum);
ImGui::Text("Gun func: %02x", wpn->gunfunc);
ImGui::Text("Fade out timer (60hz): %d", wpn->fadeouttimer60);
ImGui::Text("Timer (240hz): %d", wpn->timer240);
}
static inline void describeProp(prop *prop);
static inline void describeChr(chrdata *chr)
{
ImGui::Text("Number: %04x", (u16)chr->chrnum);
ImGui::Text("Flags 1: %08x", chr->flags);
ImGui::Text("Flags 2: %08x", chr->flags2);
ImGui::Text("Hidden 1: %08x", chr->hidden);
ImGui::Text("Hidden 2: %04x", chr->hidden2);
ImGui::Text("Chr flags: %08x", chr->chrflags);
ImGui::Text("Damage: %.3f", chr->damage);
ImGui::Text("Shield: %.3f", chr->cshield);
ImGui::Text("Body: %04x", (u16)chr->bodynum);
ImGui::Text("Head: %02x", (u8)chr->headnum);
ImGui::Text("Team: %02x", chr->team);
ImGui::Text("Tude: %02x", chr->tude);
ImGui::Text("Action: %s (%02x)", fmtActionType(chr->actiontype), (u8)chr->actiontype);
ImGui::Separator();
if (chr->weapons_held[HAND_RIGHT]) {
if (ImGui::TreeNode(strFmt("Right hand prop (%p)", chr->weapons_held[HAND_RIGHT]))) {
describeProp(chr->weapons_held[HAND_RIGHT]);
ImGui::TreePop();
}
}
if (chr->weapons_held[HAND_LEFT]) {
if (ImGui::TreeNode(strFmt("Left hand prop (%p)", chr->weapons_held[HAND_LEFT]))) {
describeProp(chr->weapons_held[HAND_LEFT]);
ImGui::TreePop();
}
}
if (chr->weapons_held[2]) {
if (ImGui::TreeNode(strFmt("Hat prop (%p)", chr->weapons_held[2]))) {
describeProp(chr->weapons_held[2]);
ImGui::TreePop();
}
}
ImGui::SeparatorText("Controls");
if (ImGui::Button("Kill")) {
debuggerKillChr(chr);
}
ImGui::SameLine();
if (ImGui::Button("Heal")) {
chr->damage = 0.f;
}
ImGui::SameLine();
if (ImGui::Button("Sleep")) {
chr->sleep = 127;
}
ImGui::SameLine();
if (ImGui::Button("Wake")) {
chr->sleep = 0;
}
// line break
if (ImGui::Button("Drop guns")) {
chrDropItemsForOwnerReap(chr);
}
}
static inline void describeProp(prop *prop)
{
ImGui::Text(prop->active ? "Active" : "Inactive");
ImGui::Text("Type: %s (%02x)", fmtPropType(prop->type), prop->type);
ImGui::Text("Flags: %02x", prop->flags);
ImGui::Text("Pos: %s", fmtCoord(prop->pos));
std::string roomstr = "";
ImGui::Text("Rooms: %s", describeRoomList(prop->rooms, ARRAYCOUNT(prop->rooms), roomstr).c_str());
if (prop->obj) {
if (expandLatch) {
ImGui::SetNextItemOpen(expandValue);
}
if (ImGui::TreeNode(strFmt("%s (%p)", fmtObjType(prop->obj->type), prop->obj))) {
describeObj(prop->obj);
ImGui::TreePop();
}
}
if ((prop->type == PROPTYPE_CHR || prop->type == PROPTYPE_PLAYER || prop->type == PROPTYPE_EYESPY) && prop->chr) {
if (expandLatch) {
ImGui::SetNextItemOpen(expandValue);
}
if (ImGui::TreeNode(strFmt("Chr (%p)", prop->chr))) {
describeChr(prop->chr);
ImGui::TreePop();
}
} else if (prop->type == PROPTYPE_WEAPON && prop->weapon) {
if (expandLatch) {
ImGui::SetNextItemOpen(expandValue);
}
if (ImGui::TreeNode(strFmt("Weapon (%p)", prop->weapon))) {
describeWeapon(prop->weapon);
ImGui::TreePop();
}
}
}
static inline void describePlayer(player *plr)
{
ImGui::Text("Cam pos: %s", fmtCoord(plr->cam_pos));
ImGui::Text("Cam look: %s", fmtCoord(plr->cam_look));
ImGui::Text("Cam room: %03x", (u32)plr->cam_room);
ImGui::Separator();
ImGui::Text("Health: %.3f", plr->bondhealth);
ImGui::Text("Shield: %.3f", plr->apparentarmour);
ImGui::Separator();
if (plr->prop) {
if (ImGui::TreeNode(strFmt("Prop (%p)", plr->prop))) {
describeProp(plr->prop);
ImGui::TreePop();
}
}
ImGui::Separator();
if (ImGui::TreeNode("Right hand")) {
describeHand(&plr->hands[HAND_RIGHT]);
ImGui::TreePop();
}
if (ImGui::TreeNode("Left hand")) {
describeHand(&plr->hands[HAND_LEFT]);
ImGui::TreePop();
}
}
extern "C" void debuggerFrame(void)
{
if (!g_DebuggerActive) {
return;
}
if (advanceHeld) {
g_DebuggerFrameAdvance = 1;
}
expandLatch = false;
ImGuiIO& io = ImGui::GetIO();
ImGui::SetNextWindowPos(ImVec2(0.f, 0.f));
ImGui::SetNextWindowSize(io.DisplaySize);
ImGui::Begin("Debugger", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar);
if (ImGui::CollapsingHeader("Debug")) {
ImGui::SeparatorText("Player");
ImGui::PushItemWidth(56.f);
ImGui::InputText("X", xstr, IM_ARRAYSIZE(xstr) - 1, ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsDecimal);
ImGui::SameLine();
ImGui::InputText("Y", ystr, IM_ARRAYSIZE(ystr) - 1, ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsDecimal);
ImGui::SameLine();
ImGui::InputText("Z", zstr, IM_ARRAYSIZE(zstr) - 1, ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsDecimal);
ImGui::SameLine();
ImGui::PopItemWidth();
if (ImGui::Button("Warp")) {
struct coord crd;
crd.x = std::atof(xstr);
crd.y = std::atof(ystr);
crd.z = std::atof(zstr);
debuggerTeleportPlayer(crd);
}
if (ImGui::Button("Kill")) {
debuggerKillPlayer();
}
ImGui::SameLine();
if (ImGui::Button("Heal")) {
debuggerHealPlayer();
}
ImGui::SeparatorText("Time");
bool timePasses = (g_DebuggerTimePasses != 0);
if (ImGui::Checkbox("Time passes", &timePasses)) {
g_DebuggerTimePasses = (s32)timePasses;
}
s32 framediv = g_TickRateDiv;
if (ImGui::InputInt("Tickrate", &framediv, 1, 2)) {
if (framediv >= 0 && framediv < 60) {
g_TickRateDiv = framediv;
g_Vars.mininc60 = framediv;
}
}
if (ImGui::Button("+1 frame")) {
g_DebuggerFrameAdvance = 1;
}
ImGui::SameLine();
if (ImGui::Button("+5 frames")) {
g_DebuggerFrameAdvance = 5;
}
ImGui::SameLine();
if (ImGui::Button("+10 frames")) {
g_DebuggerFrameAdvance = 10;
}
ImGui::SeparatorText("Other");
}
if (ImGui::CollapsingHeader("Time")) {
ImGui::Text("Level Frame#: %d", g_Vars.lvframenum);
ImGui::Text("Level Tick (60hz): %d", g_Vars.lvframe60);
ImGui::Text("Level Tick (240hz): %d", g_Vars.lvframe240);
ImGui::Separator();
ImGui::Text("Frame Time (60hz): %.2f", g_Vars.diffframe60f);
ImGui::Text("Frame Time (240hz): %.2f", g_Vars.diffframe240f);
ImGui::Separator();
ImGui::Text("Lost Time (60hz): %d", g_Vars.lostframetime60t);
ImGui::Text("Lost Time (240hz): %d", g_Vars.lostframetime240t);
}
if (ImGui::CollapsingHeader("Players")) {
for (s32 i = 0; i < ARRAYCOUNT(g_Vars.players); ++i) {
auto plr = g_Vars.players[i];
if (plr) {
if (ImGui::TreeNode(strFmt("Player %d (%p)###Player%p", i + 1, plr, plr))) {
describePlayer(plr);
ImGui::TreePop();
}
}
}
}
if (g_Vars.activeprops && g_Vars.activeprops != g_Vars.activepropstail) {
if (ImGui::CollapsingHeader("Props")) {
ImGui::Text("Visible: %d", g_Vars.numonscreenprops);
ImGui::Separator();
ImGui::Checkbox("Active props only", &showActiveProps);
ImGui::Combo("Filter prop", &propFilter, propTypes, ARRAYCOUNT(propTypes));
ImGui::Combo("Filter obj", &objFilter, objTypes, ARRAYCOUNT(objTypes));
if (ImGui::Button("Expand all")) {
expandLatch = true;
expandValue = true;
}
ImGui::SameLine();
if (ImGui::Button("Close all")) {
expandLatch = true;
expandValue = false;
}
ImGui::Separator();
auto showProp = [&](struct prop *prop) {
if (prop && (!propFilter || propFilter == prop->type)) {
if (!objFilter || (prop->obj && prop->obj->type == objFilter)) {
const bool focus = (focusPtr && ((void *)prop == focusPtr || (void *)prop->obj == focusPtr));
if (expandLatch) {
ImGui::SetNextItemOpen(expandValue);
} else if (focus) {
ImGui::SetNextItemOpen(true);
focusPtr = nullptr;
}
if (ImGui::TreeNode(strFmt("%s (%p)###Prop%p", fmtPropType(prop->type), prop, prop))) {
if (focus) {
ImGui::SetScrollHereY();
}
describeProp(prop);
ImGui::TreePop();
}
}
}
};
if (showActiveProps) {
// show the active props list
struct prop *prop;
struct prop *next;
bool done;
prop = g_Vars.activeprops;
do {
next = prop->next;
done = next == g_Vars.pausedprops;
showProp(prop);
prop = next;
} while (!done);
} else {
// show all props
for (s32 i = 0; i < g_Vars.maxprops; ++i) {
struct prop *prop = &g_Vars.props[i];
showProp(prop);
}
}
}
}
if (g_ChrSlots && g_NumChrSlots) {
if (ImGui::CollapsingHeader("Characters")) {
ImGui::Text("Count: %d/%d", g_NumChrs, g_NumChrSlots);
ImGui::Separator();
for (s32 i = 0; i < g_NumChrSlots; ++i) {
if (g_ChrSlots[i].chrnum >= 0) {
if (ImGui::TreeNode(strFmt("Slot %3d: %04x (%p)", i, g_ChrSlots[i].chrnum, &g_ChrSlots[i]))) {
describeChr(&g_ChrSlots[i]);
if (g_ChrSlots[i].prop && ImGui::TreeNode(strFmt("Prop (%p)##chr", g_ChrSlots[i].prop))) {
describeProp(g_ChrSlots[i].prop);
ImGui::TreePop();
}
ImGui::TreePop();
}
}
}
}
}
if (ImGui::CollapsingHeader("Stage")) {
ImGui::Text("Number: %02x", g_Vars.stagenum);
ImGui::Text("Index: %02x", g_StageIndex);
ImGui::Text("Setup: %s", romdataFileGetName(g_Stages[g_StageIndex].setupfileid));
ImGui::Text("Room count: %d", g_Vars.roomcount);
if (g_Rooms && ImGui::TreeNode("Rooms")) {
ImGui::Separator();
for (s32 i = 1; i < g_Vars.roomcount; ++i) {
if (ImGui::TreeNode(strFmt("Room %03x", i))) {
ImGui::Text("Loaded: %d", g_Rooms[i].loaded240);
ImGui::Text("Flags: %04x", g_Rooms[i].flags);
ImGui::Text("Portals: %d", g_Rooms[i].numportals);
ImGui::Text("Centre: %s", fmtCoord(g_Rooms[i].centre));
ImGui::TreePop();
}
}
ImGui::TreePop();
}
}
if (ImGui::CollapsingHeader("Memory")) {
ImGui::Text("Mema size: %uk", memaGetSize() / 1024);
ImGui::Spacing();
if (ImGui::TreeNode("Memp state")) {
if (ImGui::BeginTable("MemaTab", 3)) {
ImGui::TableNextColumn();
ImGui::Text("Pool");
ImGui::TableNextColumn();
ImGui::Text("Onboard");
ImGui::TableNextColumn();
ImGui::Text("Expansion");
for (u8 i = MEMPOOL_STAGE; i <= MEMPOOL_PERMANENT; i += 2) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text((i == MEMPOOL_STAGE) ? "Stage" : "Permanent");
ImGui::TableNextColumn();
ImGui::Text("%uk/%uk", mempGetPoolFree(i, MEMBANK_ONBOARD) / 1024, mempGetPoolSize(i, MEMBANK_ONBOARD) / 1024);
ImGui::TableNextColumn();
ImGui::Text("%uk/%uk", mempGetPoolFree(i, MEMBANK_EXPANSION) / 1024, mempGetPoolSize(i, MEMBANK_EXPANSION) / 1024);
}
ImGui::EndTable();
}
ImGui::TreePop();
}
}
if ((showPropInfo = ImGui::CollapsingHeader("Looking at"))) {
if (lookatprop) {
ImGui::Text("Looking at prop");
describeProp(lookatprop);
} else if (lookathitset) {
ImGui::Text("Looking at surface");
ImGui::Text("Hit pos: %s", fmtCoord(lookathit.pos));
ImGui::Text("Texture: %04x", lookathit.texturenum);
} else {
ImGui::Text("Looking at nothing");
}
}
ImGui::End();
}
extern "C" void debuggerEndFrame(void)
{
ImGui::Render();
ImGuiIO& io = ImGui::GetIO();
SDL_RenderSetScale(dbgren, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
SDL_SetRenderDrawColor(dbgren, 0, 0, 0, 255);
SDL_RenderClear(dbgren);
ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData());
SDL_RenderPresent(dbgren);
}
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014-2023 Omar Cornut
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
File diff suppressed because it is too large. Load diff
+46
View File
@@ -0,0 +1,46 @@
// dear imgui: Platform Backend for SDL2
// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
// (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
// Implemented features:
// [X] Platform: Clipboard support.
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
// Missing features:
// [ ] Platform: Multi-viewport + Minimized windows seems to break mouse wheel events (at least under Windows).
// [x] Platform: Basic IME support. App needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!.
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
// Learn about Dear ImGui:
// - FAQ https://dearimgui.com/faq
// - Getting Started https://dearimgui.com/getting-started
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
// - Introduction, links and more at the top of imgui.cpp
#pragma once
#include "imgui.h" // IMGUI_IMPL_API
#ifndef IMGUI_DISABLE
struct SDL_Window;
struct SDL_Renderer;
typedef union SDL_Event SDL_Event;
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOther(SDL_Window* window);
IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown();
IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame();
IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
static inline void ImGui_ImplSDL2_NewFrame(SDL_Window*) { ImGui_ImplSDL2_NewFrame(); } // 1.84: removed unnecessary parameter
#endif
#endif // #ifndef IMGUI_DISABLE
@@ -0,0 +1,268 @@
// dear imgui: Renderer Backend for SDL_Renderer for SDL2
// (Requires: SDL 2.0.17+)
// Note how SDL_Renderer is an _optional_ component of SDL2.
// For a multi-platform app consider using e.g. SDL+DirectX on Windows and SDL+OpenGL on Linux/OSX.
// If your application will want to render any non trivial amount of graphics other than UI,
// please be aware that SDL_Renderer currently offers a limited graphic API to the end-user and
// it might be difficult to step out of those boundaries.
// Implemented features:
// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID!
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
// Missing features:
// [ ] Renderer: Multi-viewport support (multiple windows).
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
// Learn about Dear ImGui:
// - FAQ https://dearimgui.com/faq
// - Getting Started https://dearimgui.com/getting-started
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
// - Introduction, links and more at the top of imgui.cpp
// CHANGELOG
// 2023-05-30: Renamed imgui_impl_sdlrenderer.h/.cpp to imgui_impl_sdlrenderer2.h/.cpp to accommodate for upcoming SDL3.
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
// 2021-12-21: Update SDL_RenderGeometryRaw() format to work with SDL 2.0.19.
// 2021-12-03: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
// 2021-10-06: Backup and restore modified ClipRect/Viewport.
// 2021-09-21: Initial version.
#include "imgui.h"
#ifndef IMGUI_DISABLE
#include "imgui_impl_sdlrenderer2.h"
#include <stdint.h> // intptr_t
// Clang warnings with -Weverything
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
#endif
// SDL
#include <SDL.h>
#if !SDL_VERSION_ATLEAST(2,0,17)
#error This backend requires SDL 2.0.17+ because of SDL_RenderGeometry() function
#endif
// SDL_Renderer data
struct ImGui_ImplSDLRenderer2_Data
{
SDL_Renderer* SDLRenderer;
SDL_Texture* FontTexture;
ImGui_ImplSDLRenderer2_Data() { memset((void*)this, 0, sizeof(*this)); }
};
// Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
// It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
static ImGui_ImplSDLRenderer2_Data* ImGui_ImplSDLRenderer2_GetBackendData()
{
return ImGui::GetCurrentContext() ? (ImGui_ImplSDLRenderer2_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
}
// Functions
bool ImGui_ImplSDLRenderer2_Init(SDL_Renderer* renderer)
{
ImGuiIO& io = ImGui::GetIO();
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
IM_ASSERT(renderer != nullptr && "SDL_Renderer not initialized!");
// Setup backend capabilities flags
ImGui_ImplSDLRenderer2_Data* bd = IM_NEW(ImGui_ImplSDLRenderer2_Data)();
io.BackendRendererUserData = (void*)bd;
io.BackendRendererName = "imgui_impl_sdlrenderer2";
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
bd->SDLRenderer = renderer;
return true;
}
void ImGui_ImplSDLRenderer2_Shutdown()
{
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData();
IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplSDLRenderer2_DestroyDeviceObjects();
io.BackendRendererName = nullptr;
io.BackendRendererUserData = nullptr;
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
IM_DELETE(bd);
}
static void ImGui_ImplSDLRenderer2_SetupRenderState()
{
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData();
// Clear out any viewports and cliprect set by the user
// FIXME: Technically speaking there are lots of other things we could backup/setup/restore during our render process.
SDL_RenderSetViewport(bd->SDLRenderer, nullptr);
SDL_RenderSetClipRect(bd->SDLRenderer, nullptr);
}
void ImGui_ImplSDLRenderer2_NewFrame()
{
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData();
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplSDLRenderer2_Init()?");
if (!bd->FontTexture)
ImGui_ImplSDLRenderer2_CreateDeviceObjects();
}
void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_data)
{
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData();
// If there's a scale factor set by the user, use that instead
// If the user has specified a scale factor to SDL_Renderer already via SDL_RenderSetScale(), SDL will scale whatever we pass
// to SDL_RenderGeometryRaw() by that scale factor. In that case we don't want to be also scaling it ourselves here.
float rsx = 1.0f;
float rsy = 1.0f;
SDL_RenderGetScale(bd->SDLRenderer, &rsx, &rsy);
ImVec2 render_scale;
render_scale.x = (rsx == 1.0f) ? draw_data->FramebufferScale.x : 1.0f;
render_scale.y = (rsy == 1.0f) ? draw_data->FramebufferScale.y : 1.0f;
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
int fb_width = (int)(draw_data->DisplaySize.x * render_scale.x);
int fb_height = (int)(draw_data->DisplaySize.y * render_scale.y);
if (fb_width == 0 || fb_height == 0)
return;
// Backup SDL_Renderer state that will be modified to restore it afterwards
struct BackupSDLRendererState
{
SDL_Rect Viewport;
bool ClipEnabled;
SDL_Rect ClipRect;
};
BackupSDLRendererState old = {};
old.ClipEnabled = SDL_RenderIsClipEnabled(bd->SDLRenderer) == SDL_TRUE;
SDL_RenderGetViewport(bd->SDLRenderer, &old.Viewport);
SDL_RenderGetClipRect(bd->SDLRenderer, &old.ClipRect);
// Will project scissor/clipping rectangles into framebuffer space
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
ImVec2 clip_scale = render_scale;
// Render command lists
ImGui_ImplSDLRenderer2_SetupRenderState();
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data;
const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data;
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
if (pcmd->UserCallback)
{
// User callback, registered via ImDrawList::AddCallback()
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
ImGui_ImplSDLRenderer2_SetupRenderState();
else
pcmd->UserCallback(cmd_list, pcmd);
}
else
{
// Project scissor/clipping rectangles into framebuffer space
ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
if (clip_min.x < 0.0f) { clip_min.x = 0.0f; }
if (clip_min.y < 0.0f) { clip_min.y = 0.0f; }
if (clip_max.x > (float)fb_width) { clip_max.x = (float)fb_width; }
if (clip_max.y > (float)fb_height) { clip_max.y = (float)fb_height; }
if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
continue;
SDL_Rect r = { (int)(clip_min.x), (int)(clip_min.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y) };
SDL_RenderSetClipRect(bd->SDLRenderer, &r);
const float* xy = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, pos));
const float* uv = (const float*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, uv));
#if SDL_VERSION_ATLEAST(2,0,19)
const SDL_Color* color = (const SDL_Color*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, col)); // SDL 2.0.19+
#else
const int* color = (const int*)(const void*)((const char*)(vtx_buffer + pcmd->VtxOffset) + IM_OFFSETOF(ImDrawVert, col)); // SDL 2.0.17 and 2.0.18
#endif
// Bind texture, Draw
SDL_Texture* tex = (SDL_Texture*)pcmd->GetTexID();
SDL_RenderGeometryRaw(bd->SDLRenderer, tex,
xy, (int)sizeof(ImDrawVert),
color, (int)sizeof(ImDrawVert),
uv, (int)sizeof(ImDrawVert),
cmd_list->VtxBuffer.Size - pcmd->VtxOffset,
idx_buffer + pcmd->IdxOffset, pcmd->ElemCount, sizeof(ImDrawIdx));
}
}
}
// Restore modified SDL_Renderer state
SDL_RenderSetViewport(bd->SDLRenderer, &old.Viewport);
SDL_RenderSetClipRect(bd->SDLRenderer, old.ClipEnabled ? &old.ClipRect : nullptr);
}
// Called by Init/NewFrame/Shutdown
bool ImGui_ImplSDLRenderer2_CreateFontsTexture()
{
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData();
// Build texture atlas
unsigned char* pixels;
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bit (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory.
// Upload texture to graphics system
// (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling)
bd->FontTexture = SDL_CreateTexture(bd->SDLRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STATIC, width, height);
if (bd->FontTexture == nullptr)
{
SDL_Log("error creating texture");
return false;
}
SDL_UpdateTexture(bd->FontTexture, nullptr, pixels, 4 * width);
SDL_SetTextureBlendMode(bd->FontTexture, SDL_BLENDMODE_BLEND);
SDL_SetTextureScaleMode(bd->FontTexture, SDL_ScaleModeLinear);
// Store our identifier
io.Fonts->SetTexID((ImTextureID)(intptr_t)bd->FontTexture);
return true;
}
void ImGui_ImplSDLRenderer2_DestroyFontsTexture()
{
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplSDLRenderer2_Data* bd = ImGui_ImplSDLRenderer2_GetBackendData();
if (bd->FontTexture)
{
io.Fonts->SetTexID(0);
SDL_DestroyTexture(bd->FontTexture);
bd->FontTexture = nullptr;
}
}
bool ImGui_ImplSDLRenderer2_CreateDeviceObjects()
{
return ImGui_ImplSDLRenderer2_CreateFontsTexture();
}
void ImGui_ImplSDLRenderer2_DestroyDeviceObjects()
{
ImGui_ImplSDLRenderer2_DestroyFontsTexture();
}
//-----------------------------------------------------------------------------
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
#endif // #ifndef IMGUI_DISABLE
@@ -0,0 +1,41 @@
// dear imgui: Renderer Backend for SDL_Renderer for SDL2
// (Requires: SDL 2.0.17+)
// Note how SDL_Renderer is an _optional_ component of SDL2.
// For a multi-platform app consider using e.g. SDL+DirectX on Windows and SDL+OpenGL on Linux/OSX.
// If your application will want to render any non trivial amount of graphics other than UI,
// please be aware that SDL_Renderer currently offers a limited graphic API to the end-user and
// it might be difficult to step out of those boundaries.
// Implemented features:
// [X] Renderer: User texture binding. Use 'SDL_Texture*' as ImTextureID. Read the FAQ about ImTextureID!
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
// Missing features:
// [ ] Renderer: Multi-viewport support (multiple windows).
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
// Learn about Dear ImGui:
// - FAQ https://dearimgui.com/faq
// - Getting Started https://dearimgui.com/getting-started
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
// - Introduction, links and more at the top of imgui.cpp
#pragma once
#ifndef IMGUI_DISABLE
#include "imgui.h" // IMGUI_IMPL_API
struct SDL_Renderer;
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_Init(SDL_Renderer* renderer);
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_Shutdown();
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_NewFrame();
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_RenderDrawData(ImDrawData* draw_data);
// Called by Init/NewFrame/Shutdown
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_CreateFontsTexture();
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_DestroyFontsTexture();
IMGUI_IMPL_API bool ImGui_ImplSDLRenderer2_CreateDeviceObjects();
IMGUI_IMPL_API void ImGui_ImplSDLRenderer2_DestroyDeviceObjects();
#endif // #ifndef IMGUI_DISABLE
+129
View File
@@ -0,0 +1,129 @@
//-----------------------------------------------------------------------------
// DEAR IMGUI COMPILE-TIME OPTIONS
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
//-----------------------------------------------------------------------------
// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it)
// B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.
//-----------------------------------------------------------------------------
// You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
// files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
// Call IMGUI_CHECKVERSION() from your .cpp file to verify that the data structures your files are using are matching the ones imgui.cpp is using.
//-----------------------------------------------------------------------------
#pragma once
//---- Define assertion handler. Defaults to calling assert().
// If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
// Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
// DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
// for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
//#define IMGUI_API __declspec( dllexport )
//#define IMGUI_API __declspec( dllimport )
//---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names.
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
//#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions.
//---- Disable all of Dear ImGui or don't implement standard windows/tools.
// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp.
//#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty.
//#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowIDStackToolWindow() will be empty.
//---- Don't implement some functions to reduce linkage requirements.
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
//#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW)
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME).
//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
//---- Include imgui_user.h at the end of imgui.h as a convenience
//#define IMGUI_INCLUDE_IMGUI_USER_H
//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
//#define IMGUI_USE_BGRA_PACKED_COLOR
//---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
//#define IMGUI_USE_WCHAR32
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
// By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
//#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined.
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
//#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined.
//---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
// Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h.
//#define IMGUI_USE_STB_SPRINTF
//---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
// Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
// On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
//#define IMGUI_ENABLE_FREETYPE
//---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT)
// Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided).
// Only works in combination with IMGUI_ENABLE_FREETYPE.
// (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
//#define IMGUI_ENABLE_FREETYPE_LUNASVG
//---- Use stb_truetype to build and rasterize the font atlas (default)
// The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.
//#define IMGUI_ENABLE_STB_TRUETYPE
//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
/*
#define IM_VEC2_CLASS_EXTRA \
constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \
operator MyVec2() const { return MyVec2(x,y); }
#define IM_VEC4_CLASS_EXTRA \
constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
operator MyVec4() const { return MyVec4(x,y,z,w); }
*/
//---- ...Or use Dear ImGui's own very basic math operators.
//#define IMGUI_DEFINE_MATH_OPERATORS
//---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
// Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
// Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
//#define ImDrawIdx unsigned int
//---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
//struct ImDrawList;
//struct ImDrawCmd;
//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
//#define ImDrawCallback MyImDrawCallback
//---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase)
// (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
//#define IM_DEBUG_BREAK IM_ASSERT(0)
//#define IM_DEBUG_BREAK __debugbreak()
//---- Debug Tools: Enable slower asserts
//#define IMGUI_DEBUG_PARANOID
//---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files)
/*
namespace ImGui
{
void MyFunction(const char* name, MyMatrix44* mtx);
}
*/
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+627
View File
@@ -0,0 +1,627 @@
// [DEAR IMGUI]
// This is a slightly modified version of stb_rect_pack.h 1.01.
// Grep for [DEAR IMGUI] to find the changes.
//
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
// Sean Barrett 2014
//
// Useful for e.g. packing rectangular textures into an atlas.
// Does not do rotation.
//
// Before #including,
//
// #define STB_RECT_PACK_IMPLEMENTATION
//
// in the file that you want to have the implementation.
//
// Not necessarily the awesomest packing method, but better than
// the totally naive one in stb_truetype (which is primarily what
// this is meant to replace).
//
// Has only had a few tests run, may have issues.
//
// More docs to come.
//
// No memory allocations; uses qsort() and assert() from stdlib.
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
//
// This library currently uses the Skyline Bottom-Left algorithm.
//
// Please note: better rectangle packers are welcome! Please
// implement them to the same API, but with a different init
// function.
//
// Credits
//
// Library
// Sean Barrett
// Minor features
// Martins Mozeiko
// github:IntellectualKitty
//
// Bugfixes / warning fixes
// Jeremy Jaussaud
// Fabian Giesen
//
// Version history:
//
// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
// 0.99 (2019-02-07) warning fixes
// 0.11 (2017-03-03) return packing success/fail result
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
// 0.09 (2016-08-27) fix compiler warnings
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
// 0.05: added STBRP_ASSERT to allow replacing assert
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
// 0.01: initial release
//
// LICENSE
//
// See end of file for license information.
//////////////////////////////////////////////////////////////////////////////
//
// INCLUDE SECTION
//
#ifndef STB_INCLUDE_STB_RECT_PACK_H
#define STB_INCLUDE_STB_RECT_PACK_H
#define STB_RECT_PACK_VERSION 1
#ifdef STBRP_STATIC
#define STBRP_DEF static
#else
#define STBRP_DEF extern
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct stbrp_context stbrp_context;
typedef struct stbrp_node stbrp_node;
typedef struct stbrp_rect stbrp_rect;
typedef int stbrp_coord;
#define STBRP__MAXVAL 0x7fffffff
// Mostly for internal use, but this is the maximum supported coordinate value.
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
// Assign packed locations to rectangles. The rectangles are of type
// 'stbrp_rect' defined below, stored in the array 'rects', and there
// are 'num_rects' many of them.
//
// Rectangles which are successfully packed have the 'was_packed' flag
// set to a non-zero value and 'x' and 'y' store the minimum location
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
// if you imagine y increasing downwards). Rectangles which do not fit
// have the 'was_packed' flag set to 0.
//
// You should not try to access the 'rects' array from another thread
// while this function is running, as the function temporarily reorders
// the array while it executes.
//
// To pack into another rectangle, you need to call stbrp_init_target
// again. To continue packing into the same rectangle, you can call
// this function again. Calling this multiple times with multiple rect
// arrays will probably produce worse packing results than calling it
// a single time with the full rectangle array, but the option is
// available.
//
// The function returns 1 if all of the rectangles were successfully
// packed and 0 otherwise.
struct stbrp_rect
{
// reserved for your use:
int id;
// input:
stbrp_coord w, h;
// output:
stbrp_coord x, y;
int was_packed; // non-zero if valid packing
}; // 16 bytes, nominally
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
// Initialize a rectangle packer to:
// pack a rectangle that is 'width' by 'height' in dimensions
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
//
// You must call this function every time you start packing into a new target.
//
// There is no "shutdown" function. The 'nodes' memory must stay valid for
// the following stbrp_pack_rects() call (or calls), but can be freed after
// the call (or calls) finish.
//
// Note: to guarantee best results, either:
// 1. make sure 'num_nodes' >= 'width'
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
//
// If you don't do either of the above things, widths will be quantized to multiples
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
//
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
// may run out of temporary storage and be unable to pack some rectangles.
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
// Optionally call this function after init but before doing any packing to
// change the handling of the out-of-temp-memory scenario, described above.
// If you call init again, this will be reset to the default (false).
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
// Optionally select which packing heuristic the library should use. Different
// heuristics will produce better/worse results for different data sets.
// If you call init again, this will be reset to the default.
enum
{
STBRP_HEURISTIC_Skyline_default=0,
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
STBRP_HEURISTIC_Skyline_BF_sortHeight
};
//////////////////////////////////////////////////////////////////////////////
//
// the details of the following structures don't matter to you, but they must
// be visible so you can handle the memory allocations for them
struct stbrp_node
{
stbrp_coord x,y;
stbrp_node *next;
};
struct stbrp_context
{
int width;
int height;
int align;
int init_mode;
int heuristic;
int num_nodes;
stbrp_node *active_head;
stbrp_node *free_head;
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
};
#ifdef __cplusplus
}
#endif
#endif
//////////////////////////////////////////////////////////////////////////////
//
// IMPLEMENTATION SECTION
//
#ifdef STB_RECT_PACK_IMPLEMENTATION
#ifndef STBRP_SORT
#include <stdlib.h>
#define STBRP_SORT qsort
#endif
#ifndef STBRP_ASSERT
#include <assert.h>
#define STBRP_ASSERT assert
#endif
#ifdef _MSC_VER
#define STBRP__NOTUSED(v) (void)(v)
#define STBRP__CDECL __cdecl
#else
#define STBRP__NOTUSED(v) (void)sizeof(v)
#define STBRP__CDECL
#endif
enum
{
STBRP__INIT_skyline = 1
};
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
{
switch (context->init_mode) {
case STBRP__INIT_skyline:
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
context->heuristic = heuristic;
break;
default:
STBRP_ASSERT(0);
}
}
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
{
if (allow_out_of_mem)
// if it's ok to run out of memory, then don't bother aligning them;
// this gives better packing, but may fail due to OOM (even though
// the rectangles easily fit). @TODO a smarter approach would be to only
// quantize once we've hit OOM, then we could get rid of this parameter.
context->align = 1;
else {
// if it's not ok to run out of memory, then quantize the widths
// so that num_nodes is always enough nodes.
//
// I.e. num_nodes * align >= width
// align >= width / num_nodes
// align = ceil(width/num_nodes)
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
}
}
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
{
int i;
for (i=0; i < num_nodes-1; ++i)
nodes[i].next = &nodes[i+1];
nodes[i].next = NULL;
context->init_mode = STBRP__INIT_skyline;
context->heuristic = STBRP_HEURISTIC_Skyline_default;
context->free_head = &nodes[0];
context->active_head = &context->extra[0];
context->width = width;
context->height = height;
context->num_nodes = num_nodes;
stbrp_setup_allow_out_of_mem(context, 0);
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
context->extra[0].x = 0;
context->extra[0].y = 0;
context->extra[0].next = &context->extra[1];
context->extra[1].x = (stbrp_coord) width;
context->extra[1].y = (1<<30);
context->extra[1].next = NULL;
}
// find minimum y position if it starts at x1
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
{
stbrp_node *node = first;
int x1 = x0 + width;
int min_y, visited_width, waste_area;
STBRP__NOTUSED(c);
STBRP_ASSERT(first->x <= x0);
#if 0
// skip in case we're past the node
while (node->next->x <= x0)
++node;
#else
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
#endif
STBRP_ASSERT(node->x <= x0);
min_y = 0;
waste_area = 0;
visited_width = 0;
while (node->x < x1) {
if (node->y > min_y) {
// raise min_y higher.
// we've accounted for all waste up to min_y,
// but we'll now add more waste for everything we've visted
waste_area += visited_width * (node->y - min_y);
min_y = node->y;
// the first time through, visited_width might be reduced
if (node->x < x0)
visited_width += node->next->x - x0;
else
visited_width += node->next->x - node->x;
} else {
// add waste area
int under_width = node->next->x - node->x;
if (under_width + visited_width > width)
under_width = width - visited_width;
waste_area += under_width * (min_y - node->y);
visited_width += under_width;
}
node = node->next;
}
*pwaste = waste_area;
return min_y;
}
typedef struct
{
int x,y;
stbrp_node **prev_link;
} stbrp__findresult;
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
{
int best_waste = (1<<30), best_x, best_y = (1 << 30);
stbrp__findresult fr;
stbrp_node **prev, *node, *tail, **best = NULL;
// align to multiple of c->align
width = (width + c->align - 1);
width -= width % c->align;
STBRP_ASSERT(width % c->align == 0);
// if it can't possibly fit, bail immediately
if (width > c->width || height > c->height) {
fr.prev_link = NULL;
fr.x = fr.y = 0;
return fr;
}
node = c->active_head;
prev = &c->active_head;
while (node->x + width <= c->width) {
int y,waste;
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
// bottom left
if (y < best_y) {
best_y = y;
best = prev;
}
} else {
// best-fit
if (y + height <= c->height) {
// can only use it if it first vertically
if (y < best_y || (y == best_y && waste < best_waste)) {
best_y = y;
best_waste = waste;
best = prev;
}
}
}
prev = &node->next;
node = node->next;
}
best_x = (best == NULL) ? 0 : (*best)->x;
// if doing best-fit (BF), we also have to try aligning right edge to each node position
//
// e.g, if fitting
//
// ____________________
// |____________________|
//
// into
//
// | |
// | ____________|
// |____________|
//
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
//
// This makes BF take about 2x the time
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
tail = c->active_head;
node = c->active_head;
prev = &c->active_head;
// find first node that's admissible
while (tail->x < width)
tail = tail->next;
while (tail) {
int xpos = tail->x - width;
int y,waste;
STBRP_ASSERT(xpos >= 0);
// find the left position that matches this
while (node->next->x <= xpos) {
prev = &node->next;
node = node->next;
}
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
if (y + height <= c->height) {
if (y <= best_y) {
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
best_x = xpos;
//STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
best_y = y;
best_waste = waste;
best = prev;
}
}
}
tail = tail->next;
}
}
fr.prev_link = best;
fr.x = best_x;
fr.y = best_y;
return fr;
}
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
{
// find best position according to heuristic
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
stbrp_node *node, *cur;
// bail if:
// 1. it failed
// 2. the best node doesn't fit (we don't always check this)
// 3. we're out of memory
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
res.prev_link = NULL;
return res;
}
// on success, create new node
node = context->free_head;
node->x = (stbrp_coord) res.x;
node->y = (stbrp_coord) (res.y + height);
context->free_head = node->next;
// insert the new node into the right starting point, and
// let 'cur' point to the remaining nodes needing to be
// stiched back in
cur = *res.prev_link;
if (cur->x < res.x) {
// preserve the existing one, so start testing with the next one
stbrp_node *next = cur->next;
cur->next = node;
cur = next;
} else {
*res.prev_link = node;
}
// from here, traverse cur and free the nodes, until we get to one
// that shouldn't be freed
while (cur->next && cur->next->x <= res.x + width) {
stbrp_node *next = cur->next;
// move the current node to the free list
cur->next = context->free_head;
context->free_head = cur;
cur = next;
}
// stitch the list back in
node->next = cur;
if (cur->x < res.x + width)
cur->x = (stbrp_coord) (res.x + width);
#ifdef _DEBUG
cur = context->active_head;
while (cur->x < context->width) {
STBRP_ASSERT(cur->x < cur->next->x);
cur = cur->next;
}
STBRP_ASSERT(cur->next == NULL);
{
int count=0;
cur = context->active_head;
while (cur) {
cur = cur->next;
++count;
}
cur = context->free_head;
while (cur) {
cur = cur->next;
++count;
}
STBRP_ASSERT(count == context->num_nodes+2);
}
#endif
return res;
}
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
{
const stbrp_rect *p = (const stbrp_rect *) a;
const stbrp_rect *q = (const stbrp_rect *) b;
if (p->h > q->h)
return -1;
if (p->h < q->h)
return 1;
return (p->w > q->w) ? -1 : (p->w < q->w);
}
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
{
const stbrp_rect *p = (const stbrp_rect *) a;
const stbrp_rect *q = (const stbrp_rect *) b;
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
}
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
{
int i, all_rects_packed = 1;
// we use the 'was_packed' field internally to allow sorting/unsorting
for (i=0; i < num_rects; ++i) {
rects[i].was_packed = i;
}
// sort according to heuristic
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
for (i=0; i < num_rects; ++i) {
if (rects[i].w == 0 || rects[i].h == 0) {
rects[i].x = rects[i].y = 0; // empty rect needs no space
} else {
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
if (fr.prev_link) {
rects[i].x = (stbrp_coord) fr.x;
rects[i].y = (stbrp_coord) fr.y;
} else {
rects[i].x = rects[i].y = STBRP__MAXVAL;
}
}
}
// unsort
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
// set was_packed flags and all_rects_packed status
for (i=0; i < num_rects; ++i) {
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
if (!rects[i].was_packed)
all_rects_packed = 0;
}
// return the all_rects_packed status
return all_rects_packed;
}
#endif
/*
------------------------------------------------------------------------------
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2017 Sean Barrett
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
------------------------------------------------------------------------------
*/
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+24 -10
View File
@@ -10,6 +10,7 @@
#include "config.h" #include "config.h"
#include "utils.h" #include "utils.h"
#include "system.h" #include "system.h"
#include "debugger.h"
#include "fs.h" #include "fs.h"
#if !SDL_VERSION_ATLEAST(2, 0, 14) #if !SDL_VERSION_ATLEAST(2, 0, 14)
@@ -549,6 +550,8 @@ static int inputEventFilter(void *data, SDL_Event *event)
break; break;
} }
debuggerProcessEvent(event);
return 0; return 0;
} }
@@ -889,16 +892,27 @@ static inline void inputUpdateMouse(void)
mouseX = mx; mouseX = mx;
mouseY = my; mouseY = my;
// if MLOCK_AUTO is enabled, disable cursor if mouse is unlocked const s32 mouseFocus = (SDL_GetMouseFocus() == videoGetWindowHandle());
// and we haven't moved it for a few seconds if (!mouseFocus) {
if (mouseLockMode == MLOCK_AUTO && !mouseLocked) { mouseDX = 0;
if (abs(mouseDX) > CURSOR_HIDE_THRESHOLD || abs(mouseDY) > CURSOR_HIDE_THRESHOLD) { mouseDY = 0;
if (!mouseShowCursor) { mouseWheel = 0;
inputMouseShowCursor(1); mouseButtons = 0;
} if (!mouseShowCursor) {
} else if (sysGetMicroseconds() > mouseCursorTime) { inputMouseShowCursor(1);
if (mouseShowCursor) { }
inputMouseShowCursor(0); } else {
// if MLOCK_AUTO is enabled, disable cursor if mouse is unlocked
// and we haven't moved it for a few seconds
if (mouseLockMode == MLOCK_AUTO && !mouseLocked) {
if (abs(mouseDX) > CURSOR_HIDE_THRESHOLD || abs(mouseDY) > CURSOR_HIDE_THRESHOLD) {
if (!mouseShowCursor) {
inputMouseShowCursor(1);
}
} else if (sysGetMicroseconds() > mouseCursorTime) {
if (mouseShowCursor) {
inputMouseShowCursor(0);
}
} }
} }
} }
+2
View File
@@ -16,6 +16,7 @@
#include "config.h" #include "config.h"
#include "mod.h" #include "mod.h"
#include "system.h" #include "system.h"
#include "debugger.h"
#include "utils.h" #include "utils.h"
u32 g_OsMemSize = 0; u32 g_OsMemSize = 0;
@@ -108,6 +109,7 @@ int main(int argc, const char **argv)
inputInit(); inputInit();
audioInit(); audioInit();
romdataInit(); romdataInit();
debuggerInit();
g_ValidGbcRomFound = romdataCheckGbcRom(); g_ValidGbcRomFound = romdataCheckGbcRom();
+13 -4
View File
@@ -72,6 +72,7 @@
#include "lib/str.h" #include "lib/str.h"
#include "data.h" #include "data.h"
#include "types.h" #include "types.h"
#include "debugger.h"
#include "system.h" #include "system.h"
extern u8 *g_MempHeap; extern u8 *g_MempHeap;
@@ -533,6 +534,15 @@ void mainTick(void)
joyDebugJoy(); joyDebugJoy();
schedSetCrashEnable2(false); schedSetCrashEnable2(false);
if (g_DebuggerTimePasses) {
g_MainGameLogicEnabled = true;
} else {
g_MainGameLogicEnabled = (g_DebuggerFrameAdvance > 0);
if (g_MainGameLogicEnabled) {
--g_DebuggerFrameAdvance;
}
}
if (g_MainGameLogicEnabled) { if (g_MainGameLogicEnabled) {
gdl = gdlstart = gfxGetMasterDisplayList(); gdl = gdlstart = gfxGetMasterDisplayList();
@@ -570,11 +580,10 @@ void mainTick(void)
if (g_MainGameLogicEnabled) { if (g_MainGameLogicEnabled) {
gfxSwapBuffers(); gfxSwapBuffers();
viUpdateMode(); viUpdateMode();
rdpCreateTask(gdlstart, gdl, 0, (uintptr_t) &msg);
memaPrint();
profileSetMarker(PROFILE_MAINTICK_END);
} }
rdpCreateTask(gdlstart, gdl, 0, (uintptr_t) &msg);
memaPrint();
profileSetMarker(PROFILE_MAINTICK_END);
} }
} }
+6
View File
@@ -25,6 +25,7 @@
#include "audio.h" #include "audio.h"
#include "input.h" #include "input.h"
#include "mixer.h" #include "mixer.h"
#include "debugger.h"
/* /*
* private typedefs and defines * private typedefs and defines
@@ -239,6 +240,7 @@ void schedSubmitTask(OSSched *sc, OSScTask *t)
void schedStartFrame(OSSched *sc) void schedStartFrame(OSSched *sc)
{ {
debuggerStartFrame();
videoStartFrame(); videoStartFrame();
} }
@@ -288,6 +290,8 @@ void schedEndFrame(OSSched *sc)
viHandleRetrace(); viHandleRetrace();
} }
debuggerFrame();
inputUpdate(); inputUpdate();
joyStartReadData(&g_PiMesgQueue); joyStartReadData(&g_PiMesgQueue);
@@ -297,6 +301,8 @@ void schedEndFrame(OSSched *sc)
sndHandleRetrace(); sndHandleRetrace();
schedAudioFrame(sc); schedAudioFrame(sc);
schedRenderCrashPeriodically(sc->frameCount); schedRenderCrashPeriodically(sc->frameCount);
debuggerEndFrame();
videoEndFrame(); videoEndFrame();
if (g_MainIsBooting == 0) { if (g_MainIsBooting == 0) {
+11 -7
View File
@@ -15336,17 +15336,21 @@ bool chrMoveToPos(struct chrdata *chr, struct coord *pos, RoomNum *rooms, f32 an
propDeregisterRooms(chr->prop); propDeregisterRooms(chr->prop);
roomsCopy(rooms2, chr->prop->rooms); roomsCopy(rooms2, chr->prop->rooms);
chr0f0220ac(chr); chr0f0220ac(chr);
modelSetRootPosition(chr->model, &pos2);
nodetype = chr->model->definition->rootnode->type; if (chr->model) {
modelSetRootPosition(chr->model, &pos2);
if ((nodetype & 0xff) == MODELNODETYPE_CHRINFO) { nodetype = chr->model->definition->rootnode->type;
rwdata = modelGetNodeRwData(chr->model, chr->model->definition->rootnode); if ((nodetype & 0xff) == MODELNODETYPE_CHRINFO) {
rwdata->chrinfo.ground = ground; rwdata = modelGetNodeRwData(chr->model, chr->model->definition->rootnode);
rwdata->chrinfo.ground = ground;
}
} }
chr->chrflags |= CHRCFLAG_FORCETOGROUND; chr->chrflags |= CHRCFLAG_FORCETOGROUND;
chrSetLookAngle(chr, angle);
if (chr->model || chr->aibot) {
chrSetLookAngle(chr, angle);
}
if (chr->prop->type == PROPTYPE_PLAYER) { if (chr->prop->type == PROPTYPE_PLAYER) {
player = g_Vars.players[playermgrGetPlayerNumByProp(chr->prop)]; player = g_Vars.players[playermgrGetPlayerNumByProp(chr->prop)];
+4
View File
@@ -97,6 +97,7 @@
#include "lib/vi.h" #include "lib/vi.h"
#include "types.h" #include "types.h"
#ifndef PLATFORM_N64 #ifndef PLATFORM_N64
#include "debugger.h"
#include "video.h" #include "video.h"
#endif #endif
@@ -299,6 +300,8 @@ void lvReset(s32 stagenum)
g_MiscAudioHandle = NULL; g_MiscAudioHandle = NULL;
debuggerUpdatePropInfo(true);
musicReset(); musicReset();
modelmgrSetLvResetting(true); modelmgrSetLvResetting(true);
surfaceReset(); surfaceReset();
@@ -1246,6 +1249,7 @@ Gfx *lvRender(Gfx *gdl)
#ifndef PLATFORM_N64 #ifndef PLATFORM_N64
// glares calculated earlier on PC, before prop matrices turn into garbage // glares calculated earlier on PC, before prop matrices turn into garbage
bgCalculateGlaresForVisibleRooms(); bgCalculateGlaresForVisibleRooms();
debuggerUpdatePropInfo(false);
#endif #endif
// Calculate lookingatprop // Calculate lookingatprop
+2 -1
View File
@@ -71,9 +71,10 @@
#include "data.h" #include "data.h"
#include "types.h" #include "types.h"
#ifndef PLATFORM_N64 #ifndef PLATFORM_N64
#include "platform.h"
#include "video.h" #include "video.h"
#include "input.h" #include "input.h"
#include "platform.h" #include "debugger.h"
#endif #endif
s32 g_DefaultWeapons[2]; s32 g_DefaultWeapons[2];
+18
View File
@@ -77,6 +77,10 @@
#include "textures.h" #include "textures.h"
#include "types.h" #include "types.h"
#include "string.h" #include "string.h"
#ifndef PLATFORM_N64
#include "system.h"
#include "debugger.h"
#endif
void rng2SetSeed(u32 seed); void rng2SetSeed(u32 seed);
@@ -6703,6 +6707,10 @@ s32 projectileTick(struct defaultobj *obj, bool *embedded)
|| prop->pos.y < -20000.0f || prop->pos.y > 32000.0f || prop->pos.y < -20000.0f || prop->pos.y > 32000.0f
|| prop->pos.x < -32000.0f || prop->pos.x > 32000.0f || prop->pos.x < -32000.0f || prop->pos.x > 32000.0f
|| prop->pos.z < -32000.0f || prop->pos.z > 32000.0f) { || prop->pos.z < -32000.0f || prop->pos.z > 32000.0f) {
if (g_DebuggerActive) {
sysLogPrintf(LOG_WARNING, "DBG: prop %p (%02x) obj %p (%02x) at (%.2f, %.2f, %.2f) expired",
prop, prop->type, obj, obj->type, prop->pos.x, prop->pos.y, prop->pos.z);
}
obj->hidden |= OBJHFLAG_DELETING; obj->hidden |= OBJHFLAG_DELETING;
} }
@@ -10885,6 +10893,16 @@ u32 objTick(struct prop *prop)
u32 padnum; u32 padnum;
struct defaultobj *newparent; struct defaultobj *newparent;
if (g_DebuggerActive) {
if (obj->type != OBJTYPE_HOVERCAR && prop->pos.y <= -20000.f) {
if ((obj->hidden & OBJHFLAG_FALLOUT) == 0) {
sysLogPrintf(LOG_WARNING, "DBG: prop %p (%02x) obj %p (%02x) at (%.2f, %.2f, %.2f) fell out of world",
prop, prop->type, obj, obj->type, prop->pos.x, prop->pos.y, prop->pos.z);
obj->hidden |= OBJHFLAG_FALLOUT;
}
}
}
if (prop->timetoregen > 0) { if (prop->timetoregen > 0) {
// Prop is taken/unavailable // Prop is taken/unavailable
regenning = true; regenning = true;
+1
View File
@@ -3197,6 +3197,7 @@
#define OBJHFLAG_BLOCKEDPATH 0x02000000 #define OBJHFLAG_BLOCKEDPATH 0x02000000
#define OBJHFLAG_MOUNTED 0x04000000 // for hoverbike #define OBJHFLAG_MOUNTED 0x04000000 // for hoverbike
#define OBJHFLAG_GRABBED 0x08000000 #define OBJHFLAG_GRABBED 0x08000000
#define OBJHFLAG_FALLOUT 0x10000000
// obj->hidden2 // obj->hidden2
#define OBJH2FLAG_HASOPA 0x01 // obj has opaque polygons (ie. most objects) #define OBJH2FLAG_HASOPA 0x01 // obj has opaque polygons (ie. most objects)
+1 -1
View File
@@ -22,7 +22,7 @@ void bgLoadFile(void *memaddr, u32 offset, u32 len);
s32 bgGetStageIndex(s32 stagenum); s32 bgGetStageIndex(s32 stagenum);
f32 bgCalculatePortalSurfaceArea(s32 portal); f32 bgCalculatePortalSurfaceArea(s32 portal);
u8 bgCalculatePortalAlpha(s32 portal); u8 bgCalculatePortalAlpha(s32 portal);
u32 not(u32 arg); u32 bgNot(u32 arg);
u32 bgXorBabebabe(u32 value); u32 bgXorBabebabe(u32 value);
void bgReset(s32 stagenum); void bgReset(s32 stagenum);
void bgBuildTables(s32 stagenum); void bgBuildTables(s32 stagenum);
-2
View File
@@ -294,7 +294,6 @@ u32 mempGetPoolFree(u8 poolnum, u32 bank)
return pool->rightpos - pool->leftpos; return pool->rightpos - pool->leftpos;
} }
#ifdef DEBUG
u32 mempGetPoolSize(u8 poolnum, u32 bank) u32 mempGetPoolSize(u8 poolnum, u32 bank)
{ {
struct memorypool *pool; struct memorypool *pool;
@@ -307,7 +306,6 @@ u32 mempGetPoolSize(u8 poolnum, u32 bank)
return pool->rightpos - pool->start; return pool->rightpos - pool->start;
} }
#endif
#if VERSION < VERSION_NTSC_1_0 #if VERSION < VERSION_NTSC_1_0
void *mempAllocFromPackedWord(u32 word) void *mempAllocFromPackedWord(u32 word)