feat/tracy: added tracy zones in important parts.

This commit is contained in:
JuiceyDev 2026-04-05 22:13:22 +02:00
parent 04abf10331
commit 93c0d1b1e1
10 changed files with 537 additions and 61 deletions

File diff suppressed because it is too large Load diff

View file

@ -13,16 +13,36 @@
#include "app/linux/Iggy/include/iggy.h"
#include "SDL_video.h"
#ifdef TRACY_ENABLE
#include <tracy/TracyC.h>
#else
#define TracyCAlloc(ptr, size)
#define TracyCFree(ptr)
#define TracyCZone(ctx, active)
#define TracyCZoneN(ctx, name, active)
#define TracyCZoneEnd(ctx)
#endif
#ifndef _ENABLEIGGY
void* IggyGDrawMallocAnnotated(SINTa size, const char* file, int line) {
TracyCZoneN(iggy_malloc, "IggyGDrawMallocAnnotated", 1);
(void)file;
(void)line;
return malloc((size_t)size);
void* ptr = malloc((size_t)size);
if (ptr) TracyCAlloc(ptr, (size_t)size);
TracyCZoneEnd(iggy_malloc);
return ptr;
}
void IggyGDrawFree(void* ptr) { free(ptr); }
void IggyGDrawFree(void* ptr) {
TracyCZoneN(iggy_free, "IggyGDrawFree", 1);
if (ptr) TracyCFree(ptr);
free(ptr);
TracyCZoneEnd(iggy_free);
}
void IggyGDrawSendWarning(Iggy* f, char const* message, ...) {
TracyCZoneN(iggy_warn, "IggyGDrawSendWarning", 1);
(void)f;
va_list args;
va_start(args, message);
@ -30,15 +50,19 @@ void IggyGDrawSendWarning(Iggy* f, char const* message, ...) {
vfprintf(stderr, message, args);
fprintf(stderr, "\n");
va_end(args);
TracyCZoneEnd(iggy_warn);
}
void IggyDiscardVertexBufferCallback(void* owner, void* buf) {
TracyCZoneN(iggy_discard_vb, "IggyDiscardVertexBufferCallback", 1);
(void)owner;
(void)buf;
TracyCZoneEnd(iggy_discard_vb);
}
#endif
static void* get_gl_proc(const char* name) {
TracyCZoneN(gdraw_get_gl_proc, "get_gl_proc", 1);
void* p = SDL_GL_GetProcAddress(name);
if (!p) p = dlsym(RTLD_DEFAULT, name);
if (!p) {
@ -53,6 +77,7 @@ static void* get_gl_proc(const char* name) {
if (!p) p = dlsym(RTLD_DEFAULT, buf);
}
}
TracyCZoneEnd(gdraw_get_gl_proc);
return p;
}
@ -184,7 +209,8 @@ static gdraw_texsubimage2d_fn gdraw_real_texsubimage2d = NULL;
} while (0)
static void load_extensions(void) {
// gl_shared requires ts shit ugh
TracyCZoneN(gdraw_load_extensions, "load_extensions", 1);
// gl_shared requires ts shit ugh
#define GLE(id, import, procname) \
gl##id = (PFNGL##procname##PROC)get_gl_proc("gl" import);
GDRAW_GL_EXTENSION_LIST
@ -224,7 +250,6 @@ static void load_extensions(void) {
"glEnableVertexAttribArray");
TRY(glDisableVertexAttribArray, "glDisableVertexAttribArrayARB",
"glDisableVertexAttribArray");
TRY(glGenRenderbuffers, "glGenRenderbuffersEXT", "glGenRenderbuffers");
TRY(glDeleteRenderbuffers, "glDeleteRenderbuffersEXT",
"glDeleteRenderbuffers");
@ -273,6 +298,7 @@ static void load_extensions(void) {
gdraw_glGenVertexArrays(1, &gdraw_vao);
gdraw_glBindVertexArray(gdraw_vao);
}
TracyCZoneEnd(gdraw_load_extensions);
}
#undef TRY
@ -314,23 +340,31 @@ static struct {
static int gdraw_shader_type_count = 0;
static GLenum gdraw_get_shader_type(GLuint shader) {
for (int i = 0; i < gdraw_shader_type_count; i++)
if (gdraw_shader_types[i].handle == shader)
TracyCZoneN(gdraw_get_shader_type, "gdraw_get_shader_type", 1);
for (int i = 0; i < gdraw_shader_type_count; i++) {
if (gdraw_shader_types[i].handle == shader) {
TracyCZoneEnd(gdraw_get_shader_type);
return gdraw_shader_types[i].type;
}
}
TracyCZoneEnd(gdraw_get_shader_type);
return GL_FRAGMENT_SHADER;
}
static GLuint gdraw_CreateShaderTracked(GLenum type) {
TracyCZoneN(gdraw_create_shader_tracked, "gdraw_CreateShaderTracked", 1);
GLuint h = gdraw_real_createshader(type);
if (h && gdraw_shader_type_count < GDRAW_MAX_SHADERS) {
gdraw_shader_types[gdraw_shader_type_count].handle = h;
gdraw_shader_types[gdraw_shader_type_count].type = type;
gdraw_shader_type_count++;
}
TracyCZoneEnd(gdraw_create_shader_tracked);
return h;
}
static void gdraw_CompileShaderAndLog(GLuint shader) {
TracyCZoneN(gdraw_compile_shader, "gdraw_CompileShaderAndLog", 1);
GLint status = 0;
gdraw_real_compileshader(shader);
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
@ -342,9 +376,11 @@ static void gdraw_CompileShaderAndLog(GLuint shader) {
fprintf(stderr, "[GDraw GLSL] compile FAILED shader=%u:\n%s\n", shader,
log);
}
TracyCZoneEnd(gdraw_compile_shader);
}
static void gdraw_LinkProgramAndLog(GLuint program) {
TracyCZoneN(gdraw_link_program, "gdraw_LinkProgramAndLog", 1);
GLint status = 0;
gdraw_real_linkprogram(program);
glGetProgramiv(program, GL_LINK_STATUS, &status);
@ -356,6 +392,7 @@ static void gdraw_LinkProgramAndLog(GLuint program) {
fprintf(stderr, "[GDraw GLSL] link FAILED program=%u:\n%s\n", program,
log);
}
TracyCZoneEnd(gdraw_link_program);
}
#undef glCreateShader
@ -363,6 +400,7 @@ static void gdraw_LinkProgramAndLog(GLuint program) {
// This is the part that turns the old ugly shaders to 330
static char* gdraw_strreplace(char* src, const char* find, const char* rep) {
TracyCZoneN(gdraw_strreplace_zone, "gdraw_strreplace", 1);
char* result;
char* pos;
char* base = src;
@ -375,7 +413,10 @@ static char* gdraw_strreplace(char* src, const char* find, const char* rep) {
count++;
tmp += find_len;
}
if (!count) return src;
if (!count) {
TracyCZoneEnd(gdraw_strreplace_zone);
return src;
}
size_t src_len = strlen(src);
ptrdiff_t delta = (ptrdiff_t)rep_len - (ptrdiff_t)find_len;
@ -385,7 +426,10 @@ static char* gdraw_strreplace(char* src, const char* find, const char* rep) {
else
new_len -= (size_t)(-delta) * count;
result = (char*)malloc(new_len);
if (!result) return src;
if (!result) {
TracyCZoneEnd(gdraw_strreplace_zone);
return src;
}
tmp = result;
while ((pos = strstr(src, find))) {
@ -398,12 +442,14 @@ static char* gdraw_strreplace(char* src, const char* find, const char* rep) {
}
memcpy(tmp, src, strlen(src) + 1);
free(base);
TracyCZoneEnd(gdraw_strreplace_zone);
return result;
}
static void gdraw_ShaderSourceUpgraded(GLuint shader, GLsizei count,
const GLchar** strings,
const GLint* lengths) {
TracyCZoneN(gdraw_shader_source_upgrade, "gdraw_ShaderSourceUpgraded", 1);
size_t total = 0;
for (int i = 0; i < count; i++)
total += lengths ? (lengths[i] >= 0 ? (size_t)lengths[i]
@ -413,6 +459,7 @@ static void gdraw_ShaderSourceUpgraded(GLuint shader, GLsizei count,
char* src = (char*)malloc(total + 1);
if (!src) {
gdraw_real_shadersource(shader, count, strings, lengths);
TracyCZoneEnd(gdraw_shader_source_upgrade);
return;
}
@ -469,6 +516,7 @@ static void gdraw_ShaderSourceUpgraded(GLuint shader, GLsizei count,
if (!patched) {
free(src);
gdraw_real_shadersource(shader, count, strings, lengths);
TracyCZoneEnd(gdraw_shader_source_upgrade);
return;
}
strcpy(patched, header);
@ -478,6 +526,7 @@ static void gdraw_ShaderSourceUpgraded(GLuint shader, GLsizei count,
const GLchar* patched_ptr = (const GLchar*)patched;
gdraw_real_shadersource(shader, 1, &patched_ptr, NULL);
free(patched);
TracyCZoneEnd(gdraw_shader_source_upgrade);
}
#undef glShaderSource
@ -486,6 +535,7 @@ static void gdraw_ShaderSourceUpgraded(GLuint shader, GLsizei count,
// Remap all the deprecated internal formats to their modern equivalents
// (idk why but just the word "swizzle" is cracking me up)
static void gdraw_apply_swizzle(GLenum internal_fmt) {
TracyCZoneN(gdraw_apply_swizzle, "gdraw_apply_swizzle", 1);
if (internal_fmt == 0x1906 /* GL_ALPHA */ || internal_fmt == GL_RED) {
GLint sw[4] = {GL_ZERO, GL_ZERO, GL_ZERO, GL_RED};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, sw);
@ -496,34 +546,49 @@ static void gdraw_apply_swizzle(GLenum internal_fmt) {
GLint sw[4] = {GL_RED, GL_RED, GL_RED, GL_GREEN};
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, sw);
}
TracyCZoneEnd(gdraw_apply_swizzle);
}
static GLenum gdraw_remap_fmt(GLenum fmt) {
TracyCZoneN(gdraw_remap_fmt, "gdraw_remap_fmt", 1);
GLenum result = fmt;
switch (fmt) {
case 0x1906:
return GL_RED; // GL_ALPHA
result = GL_RED; // GL_ALPHA
break;
case 0x1909:
return GL_RED; // GL_LUMINANCE
result = GL_RED; // GL_LUMINANCE
break;
case 0x190A:
return GL_RG; // GL_LUMINANCE_ALPHA
result = GL_RG; // GL_LUMINANCE_ALPHA
break;
case 0x8033:
return GL_RG; // GL_LUMINANCE4_ALPHA4
result = GL_RG; // GL_LUMINANCE4_ALPHA4
break;
case 0x8045:
return GL_R8; // GL_LUMINANCE8
result = GL_R8; // GL_LUMINANCE8
break;
case 0x8048:
return GL_RG8; // GL_LUMINANCE8_ALPHA8
result = GL_RG8; // GL_LUMINANCE8_ALPHA8
break;
case 0x804F:
return GL_R8; // GL_INTENSITY4
result = GL_R8; // GL_INTENSITY4
break;
case 0x8050:
return GL_R8; // GL_INTENSITY8
result = GL_R8; // GL_INTENSITY8
break;
default:
return fmt;
result = fmt;
break;
}
TracyCZoneEnd(gdraw_remap_fmt);
return result;
}
static void gdraw_TexImage2D(GLenum target, GLint level, GLint ifmt, GLsizei w,
GLsizei h, GLint border, GLenum fmt, GLenum type,
const void* data) {
TracyCZoneN(gdraw_teximage2d, "gdraw_TexImage2D", 1);
// ES strictly requires explicitly sized formats & stuff
if (ifmt == GL_RGBA && data == NULL) ifmt = GL_RGBA8;
@ -532,14 +597,17 @@ static void gdraw_TexImage2D(GLenum target, GLint level, GLint ifmt, GLsizei w,
gdraw_real_teximage2d(target, level, (GLint)new_ifmt, w, h, border, new_fmt,
type, data);
if (new_ifmt != (GLenum)ifmt) gdraw_apply_swizzle((GLenum)ifmt);
TracyCZoneEnd(gdraw_teximage2d);
}
static void gdraw_TexSubImage2D(GLenum target, GLint level, GLint xoff,
GLint yoff, GLsizei w, GLsizei h, GLenum fmt,
GLenum type, const void* data) {
TracyCZoneN(gdraw_texsubimage2d, "gdraw_TexSubImage2D", 1);
GLenum new_fmt = gdraw_remap_fmt(fmt);
gdraw_real_texsubimage2d(target, level, xoff, yoff, w, h, new_fmt, type,
data);
TracyCZoneEnd(gdraw_texsubimage2d);
}
#undef glTexImage2D
@ -552,6 +620,7 @@ static void gdraw_ClientVertexAttribPointer(GLuint index, GLint size,
GLenum type, GLboolean normalized,
GLsizei stride,
const void* pointer) {
TracyCZoneN(gdraw_vertex_attrib_pointer, "gdraw_ClientVertexAttribPointer", 1);
if (gdraw_glBindVertexArray && gdraw_vao) {
GLint current_vao = 0;
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &current_vao);
@ -565,11 +634,13 @@ static void gdraw_ClientVertexAttribPointer(GLuint index, GLint size,
if (current_vbo != 0 && current_vbo != (GLint)gdraw_screenvbo) {
// no touchies
gdraw_real_vtxattrib(index, size, type, normalized, stride, pointer);
TracyCZoneEnd(gdraw_vertex_attrib_pointer);
return;
}
if (pointer == NULL) {
gdraw_real_vtxattrib(index, size, type, normalized, stride, pointer);
TracyCZoneEnd(gdraw_vertex_attrib_pointer);
return;
}
@ -597,6 +668,7 @@ static void gdraw_ClientVertexAttribPointer(GLuint index, GLint size,
gdraw_real_vtxattrib(index, size, type, normalized, stride,
(const void*)offset);
}
TracyCZoneEnd(gdraw_vertex_attrib_pointer);
}
#undef glVertexAttribPointer
@ -605,6 +677,7 @@ static void gdraw_ClientVertexAttribPointer(GLuint index, GLint size,
// fake ibo
static void hooked_glDrawElements(GLenum mode, GLsizei count, GLenum type,
const void* indices) {
TracyCZoneN(gdraw_draw_elements, "hooked_glDrawElements", 1);
GLint current_ibo = 0;
glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &current_ibo);
@ -622,12 +695,14 @@ static void hooked_glDrawElements(GLenum mode, GLsizei count, GLenum type,
} else {
gdraw_real_drawelements(mode, count, type, indices);
}
TracyCZoneEnd(gdraw_draw_elements);
}
#define glDrawElements hooked_glDrawElements
// dummy shader for glUseProgram(0) safety
static void gdraw_UseProgramSafe(GLuint program) {
TracyCZoneN(gdraw_use_program_safe, "gdraw_UseProgramSafe", 1);
if (!program) {
if (!gdraw_null_program && gdraw_real_useprogram) {
const char* vs =
@ -648,9 +723,11 @@ static void gdraw_UseProgramSafe(GLuint program) {
glDeleteShader(f);
}
gdraw_real_useprogram(gdraw_null_program);
TracyCZoneEnd(gdraw_use_program_safe);
return;
}
gdraw_real_useprogram(program);
TracyCZoneEnd(gdraw_use_program_safe);
}
#undef glUseProgram
@ -663,6 +740,8 @@ static void gdraw_UseProgramSafe(GLuint program) {
static void gdraw_FramebufferRenderbufferSafe(GLenum target, GLenum attachment,
GLenum renderbuffertarget,
GLuint renderbuffer) {
TracyCZoneN(gdraw_framebuffer_renderbuffer_safe,
"gdraw_FramebufferRenderbufferSafe", 1);
static GLuint last_depth_rb = 0;
if (attachment == GL_DEPTH_ATTACHMENT) {
@ -684,6 +763,7 @@ static void gdraw_FramebufferRenderbufferSafe(GLenum target, GLenum attachment,
(glFramebufferRenderbuffer)(target, attachment, renderbuffertarget,
renderbuffer);
}
TracyCZoneEnd(gdraw_framebuffer_renderbuffer_safe);
}
#define glFramebufferRenderbuffer_SAFE gdraw_FramebufferRenderbufferSafe
#define glFramebufferRenderbuffer glFramebufferRenderbuffer_SAFE
@ -694,14 +774,22 @@ static void gdraw_FramebufferRenderbufferSafe(GLenum target, GLenum attachment,
#define glVertexAttribPointer gdraw_real_vtxattrib
static int hasext_core(const char* name) {
TracyCZoneN(gdraw_hasext_core, "hasext_core", 1);
GLint n = 0;
if (!gdraw_glGetStringi) return 0;
if (!gdraw_glGetStringi) {
TracyCZoneEnd(gdraw_hasext_core);
return 0;
}
glGetIntegerv(GL_NUM_EXTENSIONS, &n);
for (GLint i = 0; i < n; i++) {
const char* e =
(const char*)gdraw_glGetStringi(GL_EXTENSIONS, (GLuint)i);
if (e && strcmp(e, name) == 0) return 1;
if (e && strcmp(e, name) == 0) {
TracyCZoneEnd(gdraw_hasext_core);
return 1;
}
}
TracyCZoneEnd(gdraw_hasext_core);
return 0;
}
@ -711,6 +799,7 @@ static void RADLINK hooked_DrawIndexedTriangles(GDrawRenderState* r,
GDrawPrimitive* prim,
GDrawVertexBuffer* buf,
GDrawStats* stats) {
TracyCZoneN(gdraw_draw_indexed_triangles, "hooked_DrawIndexedTriangles", 1);
if (buf == NULL && prim != NULL && prim->vertices != NULL) {
size_t stride = 8;
if (prim->vertex_format == GDRAW_vformat_v2aa)
@ -725,29 +814,35 @@ static void RADLINK hooked_DrawIndexedTriangles(GDrawRenderState* r,
}
gdraw_screenvbo_base = NULL; // Force VBO re-upload for each primitive
real_DrawIndexedTriangles(r, prim, buf, stats);
TracyCZoneEnd(gdraw_draw_indexed_triangles);
}
static gdraw_filter_quad* real_FilterQuad = NULL;
static void RADLINK hooked_FilterQuad(GDrawRenderState* r, S32 x0, S32 y0,
S32 x1, S32 y1, GDrawStats* stats) {
TracyCZoneN(gdraw_filter_quad, "hooked_FilterQuad", 1);
gdraw_expected_vbo_size = 4 * 20; // 4 vertices, max stride
gdraw_screenvbo_base = NULL;
real_FilterQuad(r, x0, y0, x1, y1, stats);
TracyCZoneEnd(gdraw_filter_quad);
}
static gdraw_rendering_begin* real_RenderingBegin = NULL;
// stupid hack
static void RADLINK hooked_RenderingBegin(void) {
TracyCZoneN(gdraw_rendering_begin, "hooked_RenderingBegin", 1);
if (real_RenderingBegin) real_RenderingBegin();
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
OPENGL_CHECK_SITE("hooked_RenderingBegin:post_state");
TracyCZoneEnd(gdraw_rendering_begin);
}
// Creating the context
GDrawFunctions* gdraw_GL_CreateContext(S32 w, S32 h, S32 msaa_samples) {
TracyCZoneN(gdraw_create_context, "gdraw_GL_CreateContext", 1);
static const TextureFormatDesc tex_formats[] = {
{IFT_FORMAT_rgba_8888, 1, 1, 4, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE},
{IFT_FORMAT_rgba_4444_LE, 1, 1, 2, GL_RGBA4, GL_RGBA,
@ -779,6 +874,7 @@ GDrawFunctions* gdraw_GL_CreateContext(S32 w, S32 h, S32 msaa_samples) {
if (major < 3) {
fprintf(stderr, "[GDraw] GL 3.0 or higher required (got %d.%d)\n",
major, minor);
TracyCZoneEnd(gdraw_create_context);
return NULL;
}
@ -788,7 +884,10 @@ GDrawFunctions* gdraw_GL_CreateContext(S32 w, S32 h, S32 msaa_samples) {
gdraw_glBindVertexArray(gdraw_vao);
GDrawFunctions* funcs = create_context(w, h);
if (!funcs) return NULL;
if (!funcs) {
TracyCZoneEnd(gdraw_create_context);
return NULL;
}
// hook the vtable entries for VBO reset and render state
real_DrawIndexedTriangles = funcs->DrawIndexedTriangles;
@ -820,21 +919,26 @@ GDrawFunctions* gdraw_GL_CreateContext(S32 w, S32 h, S32 msaa_samples) {
opengl_check();
fprintf(stderr, "[GDraw] Context created successfully (%dx%d, msaa=%d)\n",
w, h, msaa_samples);
TracyCZoneEnd(gdraw_create_context);
return funcs;
}
// Custom draw callbacks
void gdraw_GL_BeginCustomDraw_4J(IggyCustomDrawCallbackRegion* region,
F32* matrix) {
TracyCZoneN(gdraw_begin_custom_draw, "gdraw_GL_BeginCustomDraw_4J", 1);
// rebind vbo
if (gdraw_glBindVertexArray && gdraw_vao)
gdraw_glBindVertexArray(gdraw_vao);
clear_renderstate();
gdraw_GetObjectSpaceMatrix(matrix, region->o2w, gdraw->projection,
depth_from_id(0), 0);
TracyCZoneEnd(gdraw_begin_custom_draw);
}
void gdraw_GL_CalculateCustomDraw_4J(IggyCustomDrawCallbackRegion* region,
F32* matrix) {
TracyCZoneN(gdraw_calc_custom_draw, "gdraw_GL_CalculateCustomDraw_4J", 1);
gdraw_GetObjectSpaceMatrix(matrix, region->o2w, gdraw->projection, 0.0f, 0);
TracyCZoneEnd(gdraw_calc_custom_draw);
}

View file

@ -17,35 +17,51 @@
#include "minecraft/server/MinecraftServer.h"
#include "minecraft/world/level/LevelSettings.h"
#ifdef TRACY_ENABLE
#include <tracy/Tracy.hpp>
#else
#define ZoneScoped
#define ZoneScopedN(name)
#endif
LinuxGame app;
#define CONTEXT_GAME_STATE 0
LinuxGame::LinuxGame() : Game() {}
void LinuxGame::SetRichPresenceContext(int iPad, int contextId) {}
void LinuxGame::SetRichPresenceContext(int iPad, int contextId) {
ZoneScoped;
}
void LinuxGame::StoreLaunchData() {}
void LinuxGame::StoreLaunchData() { ZoneScoped; }
void LinuxGame::ExitGame() {
ZoneScoped;
app.DebugPrintf("Linux_App LinuxGame::ExitGame AFTER START\n");
RenderManager.Close();
}
void LinuxGame::FatalLoadError() {
ZoneScoped;
app.DebugPrintf(
"LinuxGame::FatalLoadError - asserting 0 and dying...\n");
assert(0);
}
void LinuxGame::CaptureSaveThumbnail() {}
void LinuxGame::CaptureSaveThumbnail() { ZoneScoped; }
void LinuxGame::GetSaveThumbnail(std::uint8_t** thumbnailData,
unsigned int* thumbnailSize) {}
void LinuxGame::ReleaseSaveThumbnail() {}
unsigned int* thumbnailSize) {
ZoneScoped;
}
void LinuxGame::ReleaseSaveThumbnail() { ZoneScoped; }
void LinuxGame::GetScreenshot(int iPad,
std::uint8_t** screenshotData,
unsigned int* screenshotSize) {}
unsigned int* screenshotSize) {
ZoneScoped;
}
void LinuxGame::TemporaryCreateGameStart() {
ZoneScoped;
//////////////////////////////////////////////////////////////////////////////////////////////
/// From CScene_Main::OnInit
@ -124,14 +140,22 @@ void LinuxGame::TemporaryCreateGameStart() {
int LinuxGame::GetLocalTMSFileIndex(wchar_t* wchTMSFile,
bool bFilenameIncludesExtension,
eFileExtensionType eEXT) {
ZoneScoped;
return -1;
}
int LinuxGame::LoadLocalTMSFile(wchar_t* wchTMSFile) { return -1; }
int LinuxGame::LoadLocalTMSFile(wchar_t* wchTMSFile) {
ZoneScoped;
return -1;
}
int LinuxGame::LoadLocalTMSFile(wchar_t* wchTMSFile,
eFileExtensionType eExt) {
ZoneScoped;
return -1;
}
void LinuxGame::FreeLocalTMSFiles(eTMSFileType eType) {}
void LinuxGame::FreeLocalTMSFiles(eTMSFileType eType) {
ZoneScoped;
}

View file

@ -70,6 +70,14 @@ static void sigsegv_handler(int sig) {
#include "minecraft/world/level/tile/Tile.h"
#include "strings.h"
#ifdef TRACY_ENABLE
#include <tracy/Tracy.hpp>
#else
#define ZoneScoped
#define ZoneScopedN(name)
#endif
// #include "../Orbis/Leaderboards/OrbisLeaderboardManager.h"
// #include "../Orbis/Network/Orbis_NPToolkit.h"
@ -105,6 +113,7 @@ void FreeRichPresenceStrings();
bool g_bWidescreen = true;
void DefineActions(void) {
ZoneScoped;
// The app needs to define the actions required, and the possible mappings
// for these
@ -410,6 +419,7 @@ void DefineActions(void) {
}
int main(int argc, const char* argv[]) {
ZoneScoped;
#if defined(__linux__) && defined(__GLIBC__)
struct sigaction sa;
sa.sa_handler = sigsegv_handler;
@ -646,6 +656,7 @@ int main(int argc, const char* argv[]) {
std::vector<uint8_t*> vRichPresenceStrings;
uint8_t* mallocAndCreateUTF8ArrayFromString(int iID) {
ZoneScoped;
const wchar_t* wchString = app.GetString(iID);
std::wstring srcString = wchString;
@ -659,6 +670,7 @@ uint8_t* mallocAndCreateUTF8ArrayFromString(int iID) {
}
uint8_t* AddRichPresenceString(int iID) {
ZoneScoped;
uint8_t* strUtf8 = mallocAndCreateUTF8ArrayFromString(iID);
if (strUtf8 != nullptr) {
vRichPresenceStrings.push_back(strUtf8);
@ -667,6 +679,7 @@ uint8_t* AddRichPresenceString(int iID) {
}
void FreeRichPresenceStrings() {
ZoneScoped;
uint8_t* strUtf8;
for (int i = 0; i < vRichPresenceStrings.size(); i++) {
strUtf8 = vRichPresenceStrings.at(i);

View file

@ -165,6 +165,7 @@ ResourceLocation Minecraft::ALT_FONT_LOCATION = ResourceLocation(TN_ALT_FONT);
Minecraft::Minecraft(Component* mouseComponent, Canvas* parent,
MinecraftApplet* minecraftApplet, int width, int height,
bool fullscreen) {
ZoneScopedN("Minecraft::Minecraft");
// 4J - added this block of initialisers
gameMode = nullptr;
hasCrashed = false;
@ -283,6 +284,7 @@ Minecraft::Minecraft(Component* mouseComponent, Canvas* parent,
}
void Minecraft::clearConnectionFailed() {
ZoneScopedN("Minecraft::clearConnectionFailed");
for (int i = 0; i < XUSER_MAX_COUNT; i++) {
m_connectionFailed[i] = false;
m_connectionFailedReason[i] = DisconnectPacket::eDisconnect_None;
@ -291,11 +293,13 @@ void Minecraft::clearConnectionFailed() {
}
void Minecraft::connectTo(const std::wstring& server, int port) {
ZoneScopedN("Minecraft::connectTo");
connectToIp = server;
connectToPort = port;
}
void Minecraft::init() {
ZoneScopedN("Minecraft::init");
// glClearColor(0.2f, 0.2f, 0.2f, 1);
workingDirectory = getWorkingDirectory();
@ -401,6 +405,7 @@ void Minecraft::init() {
}
void Minecraft::renderLoadingScreen() {
ZoneScopedN("Minecraft::renderLoadingScreen");
// 4J Unused
// testing stuff on vita just now
#if defined(ENABLE_JAVA_GUIS)
@ -453,6 +458,7 @@ void Minecraft::renderLoadingScreen() {
}
void Minecraft::blit(int x, int y, int sx, int sy, int w, int h) {
ZoneScopedN("Minecraft::blit");
float us = 1 / 256.0f;
float vs = 1 / 256.0f;
Tesselator* t = Tesselator::getInstance();
@ -469,11 +475,13 @@ void Minecraft::blit(int x, int y, int sx, int sy, int w, int h) {
}
File Minecraft::getWorkingDirectory() {
ZoneScopedN("Minecraft::getWorkingDirectory");
if (workDir.getPath().empty()) workDir = getWorkingDirectory(L"4jcraft");
return workDir;
}
File Minecraft::getWorkingDirectory(const std::wstring& applicationName) {
ZoneScopedN("Minecraft::getWorkingDirectory");
// 4J - original version
// 4jcraft: ported to C++
std::wstring userHome = convStringToWstring(getenv("HOME"));
@ -508,6 +516,7 @@ File Minecraft::getWorkingDirectory(const std::wstring& applicationName) {
LevelStorageSource* Minecraft::getLevelSource() { return levelSource; }
void Minecraft::setScreen(Screen* screen) {
ZoneScopedN("Minecraft::setScreen");
if (dynamic_cast<ErrorScreen*>(this->screen) != nullptr) return;
if (this->screen != nullptr) {
@ -576,10 +585,12 @@ void Minecraft::setScreen(Screen* screen) {
}
void Minecraft::checkGlError(const std::wstring& string) {
ZoneScopedN("Minecraft::checkGlError");
// 4J - TODO
}
void Minecraft::destroy() {
ZoneScopedN("Minecraft::destroy");
// 4J Gordon: Do not force a stats save here
/*stats->forceSend();
stats->forceSave();*/
@ -666,6 +677,7 @@ void Minecraft::destroy() {
// from our xbox game loop
void Minecraft::run() {
ZoneScopedN("Minecraft::run");
running = true;
// try { // 4J - removed try/catch
init();
@ -1026,7 +1038,6 @@ void Minecraft::createPrimaryLocalPlayer(int iPad) {
}
void Minecraft::run_middle() {
ZoneScoped;
static int64_t lastTime = 0;
static bool bFirstTimeIntoGame = true;
static bool bAutosaveTimerSet = false;
@ -1174,7 +1185,6 @@ void Minecraft::run_middle() {
// 4J-PB - Once we're in the level, check if the players have
// the level in their banned list and ask if they want to play
// it
ZoneScopedN("Render Viewports");
for (int i = 0; i < XUSER_MAX_COUNT; i++) {
if (localplayers[i] && (app.GetBanListCheck(i) == false) &&
!Minecraft::GetInstance()->isTutorial() &&
@ -1828,12 +1838,14 @@ void Minecraft::run_middle() {
void Minecraft::run_end() { destroy(); }
void Minecraft::emergencySave() {
ZoneScopedN("Minecraft::emergencySave");
// 4J - lots of try/catches removed here, and garbage collector things
levelRenderer->clear();
setLevel(nullptr);
}
void Minecraft::renderFpsMeter(int64_t tickTime) {
ZoneScopedN("Minecraft::renderFpsMeter");
int nsPer60Fps = 1000000000l / 60;
if (lastTimer == -1) {
lastTimer = System::nanoTime();
@ -1926,11 +1938,13 @@ void Minecraft::renderFpsMeter(int64_t tickTime) {
}
void Minecraft::stop() {
ZoneScopedN("Minecraft::stop");
running = false;
// keepPolling = false;
}
void Minecraft::pauseGame() {
ZoneScopedN("Minecraft::pauseGame");
if (screen != nullptr) {
// 4jcraft: Pass the keypress to the screen
// normally this would've been done in updateEvents(), but it works
@ -1944,6 +1958,7 @@ void Minecraft::pauseGame() {
}
bool Minecraft::pollResize() {
ZoneScopedN("Minecraft::pollResize");
int fbw, fbh;
RenderManager.GetFramebufferSize(fbw, fbh);
if (fbw != width_phys || fbh != height_phys) {
@ -1954,6 +1969,7 @@ bool Minecraft::pollResize() {
}
void Minecraft::resize(int width, int height) {
ZoneScopedN("Minecraft::resize");
if (width <= 0) width = 1;
if (height <= 0) height = 1;
// 4jcraft: store physical framebuffer size and adjust logical width
@ -1981,6 +1997,7 @@ void Minecraft::resize(int width, int height) {
}
void Minecraft::verify() {
ZoneScopedN("Minecraft::verify");
/* 4J - TODO
new Thread() {
public void run() {
@ -2000,12 +2017,13 @@ void Minecraft::verify() {
}
void Minecraft::levelTickUpdateFunc(void* pParam) {
ZoneScoped;
ZoneScopedN("Minecraft::levelTickUpdateFunc");
Level* pLevel = (Level*)pParam;
pLevel->tick();
}
void Minecraft::levelTickThreadInitFunc() {
ZoneScopedN("Minecraft::levelTickThreadInitFunc");
Compression::UseDefaultThreadStorage();
}
@ -2014,7 +2032,7 @@ void Minecraft::levelTickThreadInitFunc() {
// textures are to be updated - this will be true for the last time this tick
// runs with bFirst true
void Minecraft::tick(bool bFirst, bool bUpdateTextures) {
ZoneScoped;
ZoneScopedN("Minecraft::tick");
int iPad = player->GetXboxPad();
// OutputDebugString("Minecraft::tick\n");
@ -3667,6 +3685,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) {
}
void Minecraft::reloadSound() {
ZoneScopedN("Minecraft::reloadSound");
// System.out.println("FORCING RELOAD!"); // 4J - removed
soundEngine = new SoundEngine();
soundEngine->init(options);
@ -3674,6 +3693,7 @@ void Minecraft::reloadSound() {
}
bool Minecraft::isClientSide() {
ZoneScopedN("Minecraft::isClientSide");
return level != nullptr && level->isClientSide;
}
@ -3685,10 +3705,12 @@ void Minecraft::selectLevel(ConsoleSaveFile* saveFile,
bool Minecraft::saveSlot(int slot, const std::wstring& name) { return false; }
bool Minecraft::loadSlot(const std::wstring& userName, int slot) {
ZoneScopedN("Minecraft::loadSlot");
return false;
}
void Minecraft::releaseLevel(int message) {
ZoneScopedN("Minecraft::releaseLevel");
// this->level = nullptr;
setLevel(nullptr, message);
}
@ -3696,6 +3718,7 @@ void Minecraft::releaseLevel(int message) {
// 4J Stu - This code was within setLevel, but I moved it out so that I can call
// it at a better time when exiting from an online game
void Minecraft::forceStatsSave(int idx) {
ZoneScopedN("Minecraft::forceStatsSave");
// 4J Gordon: Force a stats save
stats[idx]->save(idx, true);
@ -3710,6 +3733,7 @@ void Minecraft::forceStatsSave(int idx) {
// 4J Added
MultiPlayerLevel* Minecraft::getLevel(int dimension) {
ZoneScopedN("Minecraft::getLevel");
if (dimension == -1)
return levels[1];
else if (dimension == 1)
@ -3734,6 +3758,7 @@ MultiPlayerLevel* Minecraft::getLevel(int dimension) {
//}
void Minecraft::forceaddLevel(MultiPlayerLevel* level) {
ZoneScopedN("Minecraft::forceaddLevel");
int dimId = level->dimension->id;
if (dimId == -1)
levels[1] = level;
@ -3922,6 +3947,7 @@ void Minecraft::setLevel(MultiPlayerLevel* level, int message /*=-1*/,
}
void Minecraft::prepareLevel(int title) {
ZoneScopedN("Minecraft::prepareLevel");
if (progressRenderer != nullptr) {
this->progressRenderer->progressStart(title);
this->progressRenderer->progressStage(IDS_PROGRESS_BUILDING_TERRAIN);
@ -3960,6 +3986,7 @@ void Minecraft::prepareLevel(int title) {
}
void Minecraft::fileDownloaded(const std::wstring& name, File* file) {
ZoneScopedN("Minecraft::fileDownloaded");
int p = (int)name.find(L"/");
std::wstring category = name.substr(0, p);
std::wstring name2 = name.substr(p + 1);
@ -3978,27 +4005,32 @@ void Minecraft::fileDownloaded(const std::wstring& name, File* file) {
}
std::wstring Minecraft::gatherStats1() {
ZoneScopedN("Minecraft::gatherStats1");
// return levelRenderer->gatherStats1();
return L"Time to autosave: " +
toWString<int64_t>(app.SecondsToAutosave()) + L"s";
}
std::wstring Minecraft::gatherStats2() {
ZoneScopedN("Minecraft::gatherStats2");
return g_NetworkManager.GatherStats();
// return levelRenderer->gatherStats2();
}
std::wstring Minecraft::gatherStats3() {
ZoneScopedN("Minecraft::gatherStats3");
return g_NetworkManager.GatherRTTStats();
// return L"P: " + particleEngine->countParticles() + L". T: " +
// level->gatherStats();
}
std::wstring Minecraft::gatherStats4() {
ZoneScopedN("Minecraft::gatherStats4");
return level->gatherChunkSourceStats();
}
void Minecraft::respawnPlayer(int iPad, int dimension, int newEntityId) {
ZoneScopedN("Minecraft::respawnPlayer");
gameRenderer
->DisableUpdateThread(); // 4J - don't do updating whilst we are
// adjusting the player & localplayer array
@ -4102,12 +4134,14 @@ void Minecraft::respawnPlayer(int iPad, int dimension, int newEntityId) {
}
void Minecraft::start(const std::wstring& name, const std::wstring& sid) {
ZoneScopedN("Minecraft::start");
startAndConnectTo(name, sid, L"");
}
void Minecraft::startAndConnectTo(const std::wstring& name,
const std::wstring& sid,
const std::wstring& url) {
ZoneScopedN("Minecraft::startAndConnectTo");
bool fullScreen = false;
std::wstring userName = name;
@ -4192,6 +4226,7 @@ void Minecraft::startAndConnectTo(const std::wstring& name,
}
ClientConnection* Minecraft::getConnection(int iPad) {
ZoneScopedN("Minecraft::getConnection");
return localplayers[iPad]->connection;
}
@ -4203,6 +4238,7 @@ bool useLomp = false;
int g_iMainThreadId;
void Minecraft::main() {
ZoneScopedN("Minecraft::main");
std::wstring name;
std::wstring sessionId;
@ -4246,6 +4282,7 @@ void Minecraft::main() {
}
bool Minecraft::renderNames() {
ZoneScopedN("Minecraft::renderNames");
if (m_instance == nullptr || !m_instance->options->hideGui) {
return true;
}
@ -4253,23 +4290,28 @@ bool Minecraft::renderNames() {
}
bool Minecraft::useFancyGraphics() {
ZoneScopedN("Minecraft::useFancyGraphics");
return (m_instance != nullptr && m_instance->options->fancyGraphics);
}
bool Minecraft::useAmbientOcclusion() {
ZoneScopedN("Minecraft::useAmbientOcclusion");
return (m_instance != nullptr &&
m_instance->options->ambientOcclusion != Options::AO_OFF);
}
bool Minecraft::renderDebug() {
ZoneScopedN("Minecraft::renderDebug");
return (m_instance != nullptr && m_instance->options->renderDebug);
}
bool Minecraft::handleClientSideCommand(const std::wstring& chatMessage) {
ZoneScopedN("Minecraft::handleClientSideCommand");
return false;
}
int Minecraft::maxSupportedTextureSize() {
ZoneScopedN("Minecraft::maxSupportedTextureSize");
// 4J Force value
return 1024;
@ -4287,6 +4329,7 @@ int Minecraft::maxSupportedTextureSize() {
void Minecraft::delayTextureReload() { reloadTextures = true; }
int64_t Minecraft::currentTimeMillis() {
ZoneScopedN("Minecraft::currentTimeMillis");
return System::currentTimeMillis(); //(Sys.getTime() * 1000) /
// Sys.getTimerResolution();
}
@ -4314,6 +4357,7 @@ gameMode->stopDestroyBlock();
void Minecraft::handleMouseClick(int button)
{
ZoneScopedN("Minecraft::handleMouseClick");
if (button == 0 && missTime > 0) return;
if (button == 0)
{
@ -4429,6 +4473,7 @@ gameRenderer->itemInHandRenderer->itemUsed();
Screen* Minecraft::getScreen() { return screen; }
bool Minecraft::isTutorial() {
ZoneScopedN("Minecraft::isTutorial");
return m_inFullTutorialBits > 0;
/*if( gameMode != nullptr && gameMode->isTutorial() )
@ -4442,6 +4487,7 @@ bool Minecraft::isTutorial() {
}
void Minecraft::playerStartedTutorial(int iPad) {
ZoneScopedN("Minecraft::playerStartedTutorial");
// If the app doesn't think we are in a tutorial mode then just ignore this
// add
if (app.GetTutorialMode())
@ -4449,6 +4495,7 @@ void Minecraft::playerStartedTutorial(int iPad) {
}
void Minecraft::playerLeftTutorial(int iPad) {
ZoneScopedN("Minecraft::playerLeftTutorial");
// 4J Stu - Fix for bug that was flooding Sentient with LevelStart events
// If the tutorial bits are already 0 then don't need to update anything
if (m_inFullTutorialBits == 0) {
@ -4463,6 +4510,7 @@ void Minecraft::playerLeftTutorial(int iPad) {
}
int Minecraft::InGame_SignInReturned(void* pParam, bool bContinue, int iPad) {
ZoneScopedN("Minecraft::InGame_SignInReturned");
Minecraft* pMinecraftClass = (Minecraft*)pParam;
if (g_NetworkManager.IsInSession()) {
@ -4529,7 +4577,7 @@ int Minecraft::InGame_SignInReturned(void* pParam, bool bContinue, int iPad) {
}
void Minecraft::tickAllConnections() {
ZoneScoped;
ZoneScopedN("Minecraft::tickAllConnections");
int oldIdx = getLocalPlayerIdx();
for (unsigned int i = 0; i < XUSER_MAX_COUNT; i++) {
std::shared_ptr<MultiplayerLocalPlayer> mplp = localplayers[i];
@ -4543,6 +4591,7 @@ void Minecraft::tickAllConnections() {
bool Minecraft::addPendingClientTextureRequest(
const std::wstring& textureName) {
ZoneScopedN("Minecraft::addPendingClientTextureRequest");
auto it = find(m_pendingTextureRequests.begin(),
m_pendingTextureRequests.end(), textureName);
if (it == m_pendingTextureRequests.end()) {
@ -4553,6 +4602,7 @@ bool Minecraft::addPendingClientTextureRequest(
}
void Minecraft::handleClientTextureReceived(const std::wstring& textureName) {
ZoneScopedN("Minecraft::handleClientTextureReceived");
auto it = find(m_pendingTextureRequests.begin(),
m_pendingTextureRequests.end(), textureName);
if (it != m_pendingTextureRequests.end()) {
@ -4561,10 +4611,12 @@ void Minecraft::handleClientTextureReceived(const std::wstring& textureName) {
}
unsigned int Minecraft::getCurrentTexturePackId() {
ZoneScopedN("Minecraft::getCurrentTexturePackId");
return skins->getSelected()->getId();
}
ColourTable* Minecraft::getColourTable() {
ZoneScopedN("Minecraft::getColourTable");
TexturePack* selected = skins->getSelected();
ColourTable* colours = selected->getColourTable();

View file

@ -1,3 +1,6 @@
#ifdef TRACY_ENABLE
#include <tracy/Tracy.hpp>
#endif
#include "McRegionChunkStorage.h"
#include <stdio.h>
@ -45,7 +48,8 @@ C4JThread* McRegionChunkStorage::s_saveThreads[3];
McRegionChunkStorage::McRegionChunkStorage(ConsoleSaveFile* saveFile,
const std::wstring& prefix)
: m_prefix(prefix) {
m_saveFile = saveFile;
ZoneScopedN("m_prefix");
m_saveFile = saveFile;
// Make sure that if there are any files for regions to be created, that
// they are created in the order that suits us for making the initial level
@ -89,17 +93,20 @@ McRegionChunkStorage::McRegionChunkStorage(ConsoleSaveFile* saveFile,
memcpy(savedData.data(), bos.buf.data(), bos.size());
m_entityData[index] = savedData;
#ifdef TRACY_ENABLE
TracyPlot("McRegion EntityData Map Size", (int64_t)m_entityData.size());
#endif
}
}
#endif
}
McRegionChunkStorage::~McRegionChunkStorage() {
// vectors manage their own memory; clearing the map is sufficient
ZoneScopedN("McRegionChunkStorage"); // vectors manage their own memory; clearing the map is sufficient
}
LevelChunk* McRegionChunkStorage::load(Level* level, int x, int z) {
DataInputStream* regionChunkInputStream =
ZoneScopedN("McRegionChunkStorage::load"); DataInputStream* regionChunkInputStream =
RegionFileCache::getChunkDataInputStream(m_saveFile, m_prefix, x, z);
#if defined(SPLIT_SAVES)
@ -114,6 +121,9 @@ LevelChunk* McRegionChunkStorage::load(Level* level, int x, int z) {
auto it = m_entityData.find(index);
if (it != m_entityData.end()) {
m_entityData.erase(it);
#ifdef TRACY_ENABLE
TracyPlot("McRegion EntityData Map Size", (int64_t)m_entityData.size());
#endif
}
}
#endif
@ -193,7 +203,7 @@ LevelChunk* McRegionChunkStorage::load(Level* level, int x, int z) {
}
void McRegionChunkStorage::save(Level* level, LevelChunk* levelChunk) {
level->checkSession();
ZoneScopedN("McRegionChunkStorage::save"); level->checkSession();
// 4J - removed try/catch
// try {
@ -212,6 +222,9 @@ void McRegionChunkStorage::save(Level* level, LevelChunk* levelChunk) {
{
std::lock_guard<std::mutex> lock(cs_memory);
s_chunkDataQueue.push_back(output);
#ifdef TRACY_ENABLE
TracyPlot("McRegion ChunkDataQueue Size", (int64_t)s_chunkDataQueue.size());
#endif
}
// 4jcraft: WAKE UP, WAKE THE FUCK.. UP
s_queueCondition.notify_one();
@ -254,6 +267,7 @@ void McRegionChunkStorage::save(Level* level, LevelChunk* levelChunk) {
}
void McRegionChunkStorage::saveEntities(Level* level, LevelChunk* levelChunk) {
ZoneScopedN("McRegionChunkStorage::saveEntities");
#if defined(SPLIT_SAVES)
// 4j added cast to unsigned and changed index to u
uint64_t index = ((uint64_t)(uint32_t)(levelChunk->x) << 32) |
@ -272,10 +286,16 @@ void McRegionChunkStorage::saveEntities(Level* level, LevelChunk* levelChunk) {
memcpy(savedData.data(), bos.buf.data(), bos.size());
m_entityData[index] = savedData;
#ifdef TRACY_ENABLE
TracyPlot("McRegion EntityData Map Size", (int64_t)m_entityData.size());
#endif
} else {
auto it = m_entityData.find(index);
if (it != m_entityData.end()) {
m_entityData.erase(it);
#ifdef TRACY_ENABLE
TracyPlot("McRegion EntityData Map Size", (int64_t)m_entityData.size());
#endif
}
}
delete newTag;
@ -284,6 +304,7 @@ void McRegionChunkStorage::saveEntities(Level* level, LevelChunk* levelChunk) {
}
void McRegionChunkStorage::loadEntities(Level* level, LevelChunk* levelChunk) {
ZoneScopedN("McRegionChunkStorage::loadEntities");
#if defined(SPLIT_SAVES)
int64_t index = ((int64_t)(levelChunk->x) << 32) |
(((int64_t)(levelChunk->z)) & 0x00000000FFFFFFFF);
@ -303,6 +324,7 @@ void McRegionChunkStorage::loadEntities(Level* level, LevelChunk* levelChunk) {
void McRegionChunkStorage::tick() { m_saveFile->tick(); }
void McRegionChunkStorage::flush() {
ZoneScopedN("McRegionChunkStorage::flush");
#if defined(SPLIT_SAVES)
ConsoleSavePath currentFile =
ConsoleSavePath(m_prefix + std::wstring(L"entities.dat"));
@ -323,7 +345,7 @@ void McRegionChunkStorage::flush() {
}
void McRegionChunkStorage::staticCtor() {
for (unsigned int i = 0; i < 3; ++i) {
ZoneScopedN("McRegionChunkStorage::staticCtor"); for (unsigned int i = 0; i < 3; ++i) {
char threadName[256];
sprintf(threadName, "McRegion Save thread %d\n", i);
C4JThread::setThreadName(0, threadName);
@ -342,6 +364,10 @@ void McRegionChunkStorage::staticCtor() {
// 4jcraft: removed the wasting 100ms chunk loading part.
int McRegionChunkStorage::runSaveThreadProc(void* lpParam) {
ZoneScopedN("McRegionChunkStorage::runSaveThreadProc");
#ifdef TRACY_ENABLE
tracy::SetThreadName("McRegionChunkStorage Save Thread");
#endif
Compression::CreateNewThreadStorage();
bool running = true;
@ -352,6 +378,9 @@ int McRegionChunkStorage::runSaveThreadProc(void* lpParam) {
s_queueCondition.wait(lock, [] { return !s_chunkDataQueue.empty(); });
dos = s_chunkDataQueue.front();
s_chunkDataQueue.pop_front();
#ifdef TRACY_ENABLE
TracyPlot("McRegion ChunkDataQueue Size", (int64_t)s_chunkDataQueue.size());
#endif
s_runningThreadCount++;
} // Unlock so the main thread can keep working
@ -382,7 +411,7 @@ void McRegionChunkStorage::WaitIfTooManyQueuedChunks() { WaitForSaves(); }
// Static
// 4jcraft: Better waiting system
void McRegionChunkStorage::WaitForAllSaves() {
std::unique_lock<std::mutex> lock(cs_memory);
ZoneScopedN("McRegionChunkStorage::WaitForAllSaves"); std::unique_lock<std::mutex> lock(cs_memory);
// Pause the main thread instantly until queue is 0 AND workers are done
s_waitCondition.wait(lock, [] {
return s_chunkDataQueue.empty() && s_runningThreadCount == 0;
@ -391,7 +420,7 @@ void McRegionChunkStorage::WaitForAllSaves() {
// Static
void McRegionChunkStorage::WaitForSaves() {
static const int MAX_QUEUE_SIZE = 12;
ZoneScopedN("McRegionChunkStorage::WaitForSaves"); static const int MAX_QUEUE_SIZE = 12;
static const int DESIRED_QUEUE_SIZE = 6;

View file

@ -1,3 +1,6 @@
#ifdef TRACY_ENABLE
#include <tracy/Tracy.hpp>
#endif
#include "RegionFile.h"
#include <string.h>
@ -19,7 +22,8 @@
std::vector<uint8_t> RegionFile::emptySector(SECTOR_BYTES);
RegionFile::RegionFile(ConsoleSaveFile* saveFile, File* path) {
_lastModified = 0;
_lastModified = 0;
ZoneScopedN("RegionFile::RegionFile");
m_saveFile = saveFile;
@ -143,7 +147,7 @@ RegionFile::RegionFile(ConsoleSaveFile* saveFile, File* path) {
void RegionFile::writeAllOffsets() // used for the file ConsoleSaveFile
// conversion between platforms
{
if (m_bIsEmpty == false) {
ZoneScopedN("RegionFile::writeAllOffsets"); if (m_bIsEmpty == false) {
// save all the offsets and timestamps
m_saveFile->LockSaveAccess();
@ -162,7 +166,7 @@ void RegionFile::writeAllOffsets() // used for the file ConsoleSaveFile
}
}
RegionFile::~RegionFile() {
delete[] offsets;
ZoneScopedN("RegionFile"); delete[] offsets;
delete[] chunkTimestamps;
delete sectorFree;
m_saveFile->closeHandle(fileEntry);
@ -180,7 +184,7 @@ int RegionFile::getSizeDelta() // TODO - was synchronized
DataInputStream* RegionFile::getChunkDataInputStream(
int x, int z) // TODO - was synchronized
{
if (outOfBounds(x, z)) {
ZoneScopedN("RegionFile::getChunkDataInputStream"); if (outOfBounds(x, z)) {
// debugln("READ", x, z, "out of bounds");
return nullptr;
}
@ -281,7 +285,7 @@ DataInputStream* RegionFile::getChunkDataInputStream(
}
DataOutputStream* RegionFile::getChunkDataOutputStream(int x, int z) {
// 4J - was DeflatorOutputStream in here too, but we've already compressed
ZoneScopedN("RegionFile::getChunkDataOutputStream"); // 4J - was DeflatorOutputStream in here too, but we've already compressed
return new DataOutputStream(new ChunkBuffer(this, x, z));
}
@ -289,7 +293,7 @@ DataOutputStream* RegionFile::getChunkDataOutputStream(int x, int z) {
void RegionFile::write(int x, int z, std::uint8_t* data,
int length) // TODO - was synchronized
{
// 4J Stu - Do the compression here so that we know how much space we need
ZoneScopedN("RegionFile::write"); // 4J Stu - Do the compression here so that we know how much space we need
// to store the compressed data
std::uint8_t* compData =
new std::uint8_t[length +
@ -404,7 +408,7 @@ void RegionFile::write(int x, int z, std::uint8_t* data,
/* write a chunk data to the region file at specified sector number */
void RegionFile::write(int sectorNumber, std::uint8_t* data, int length,
unsigned int compLength) {
unsigned int numberOfBytesWritten = 0;
ZoneScopedN("RegionFile::write"); unsigned int numberOfBytesWritten = 0;
// SetFilePointer(file,sectorNumber * SECTOR_BYTES,0,FILE_BEGIN);
m_saveFile->setFilePointer(fileEntry, sectorNumber * SECTOR_BYTES,
SaveFileSeekOrigin::Begin);
@ -429,7 +433,7 @@ void RegionFile::write(int sectorNumber, std::uint8_t* data, int length,
}
void RegionFile::zero(int sectorNumber, int length) {
unsigned int numberOfBytesWritten = 0;
ZoneScopedN("RegionFile::zero"); unsigned int numberOfBytesWritten = 0;
// SetFilePointer(file,sectorNumber * SECTOR_BYTES,0,FILE_BEGIN);
m_saveFile->setFilePointer(fileEntry, sectorNumber * SECTOR_BYTES,
SaveFileSeekOrigin::Begin);
@ -448,7 +452,7 @@ bool RegionFile::hasChunk(int x, int z) { return getOffset(x, z) != 0; }
// 4J added - write the initial two sectors that used to be written in the ctor
// when the file was empty
void RegionFile::insertInitialSectors() {
m_saveFile->setFilePointer(fileEntry, 0, SaveFileSeekOrigin::Begin);
ZoneScopedN("RegionFile::insertInitialSectors"); m_saveFile->setFilePointer(fileEntry, 0, SaveFileSeekOrigin::Begin);
unsigned int numberOfBytesWritten = 0;
std::uint8_t zeroBytes[SECTOR_BYTES];
memset(zeroBytes, 0, SECTOR_BYTES);

View file

@ -1,3 +1,6 @@
#ifdef TRACY_ENABLE
#include <tracy/Tracy.hpp>
#endif
#include "RegionFileCache.h"
#include <utility>
@ -14,7 +17,7 @@ class DataOutputStream;
RegionFileCache RegionFileCache::s_defaultCache;
bool RegionFileCache::useSplitSaves(ESavePlatform platform) {
switch (platform) {
ZoneScopedN("RegionFileCache::useSplitSaves"); switch (platform) {
case SAVE_FILE_PLATFORM_XBONE:
case SAVE_FILE_PLATFORM_PS4:
return true;
@ -27,7 +30,7 @@ RegionFile* RegionFileCache::_getRegionFile(
ConsoleSaveFile* saveFile, const std::wstring& prefix, int chunkX,
int chunkZ) // 4J - TODO was synchronized
{
// 4J Jev - changed back to use of the File class.
ZoneScopedN("RegionFileCache::_getRegionFile"); // 4J Jev - changed back to use of the File class.
// char file[MAX_PATH_SIZE];
// sprintf(file,"%s\\region\\r.%d.%d.mcr",basePath,chunkX >> 5,chunkZ >> 5);
@ -71,7 +74,7 @@ if (!regionDir.exists())
void RegionFileCache::_clear() // 4J - TODO was synchronized
{
auto itEnd = cache.end();
ZoneScopedN("RegionFileCache::_clear"); auto itEnd = cache.end();
for (auto it = cache.begin(); it != itEnd; it++) {
// 4J - removed try/catch
// try {
@ -90,14 +93,14 @@ void RegionFileCache::_clear() // 4J - TODO was synchronized
int RegionFileCache::_getSizeDelta(ConsoleSaveFile* saveFile,
const std::wstring& prefix, int chunkX,
int chunkZ) {
RegionFile* r = _getRegionFile(saveFile, prefix, chunkX, chunkZ);
ZoneScopedN("RegionFileCache::_getSizeDelta"); RegionFile* r = _getRegionFile(saveFile, prefix, chunkX, chunkZ);
return r->getSizeDelta();
}
DataInputStream* RegionFileCache::_getChunkDataInputStream(
ConsoleSaveFile* saveFile, const std::wstring& prefix, int chunkX,
int chunkZ) {
RegionFile* r = _getRegionFile(saveFile, prefix, chunkX, chunkZ);
ZoneScopedN("RegionFileCache::_getChunkDataInputStream"); RegionFile* r = _getRegionFile(saveFile, prefix, chunkX, chunkZ);
if (useSplitSaves(saveFile->getSavePlatform())) {
return r->getChunkDataInputStream(chunkX & 15, chunkZ & 15);
} else {
@ -108,7 +111,7 @@ DataInputStream* RegionFileCache::_getChunkDataInputStream(
DataOutputStream* RegionFileCache::_getChunkDataOutputStream(
ConsoleSaveFile* saveFile, const std::wstring& prefix, int chunkX,
int chunkZ) {
RegionFile* r = _getRegionFile(saveFile, prefix, chunkX, chunkZ);
ZoneScopedN("RegionFileCache::_getChunkDataOutputStream"); RegionFile* r = _getRegionFile(saveFile, prefix, chunkX, chunkZ);
if (useSplitSaves(saveFile->getSavePlatform())) {
return r->getChunkDataOutputStream(chunkX & 15, chunkZ & 15);
} else {

View file

@ -35,7 +35,7 @@ sdl2_sources = files(
lib_platform_sdl2 = static_library('platform_sdl2',
sdl2_sources,
include_directories: [platform_inc, include_directories('sdl2')],
dependencies: [_sdl2, _gl, _threads, glm_dep, stb_dep],
dependencies: [_sdl2, _gl, _threads, glm_dep, stb_dep, tracy_client_dep],
cpp_args: _defs + global_cpp_args + global_cpp_defs,
)
@ -44,7 +44,7 @@ lib_platform_sdl2 = static_library('platform_sdl2',
render_dep = declare_dependency(
link_with: lib_platform_sdl2,
include_directories: [platform_inc, include_directories('sdl2')],
dependencies: [_sdl2, _gl, _threads, glm_dep],
dependencies: [_sdl2, _gl, _threads, glm_dep, tracy_client_dep],
)
input_dep = render_dep
profile_dep = render_dep

View file

@ -8,6 +8,19 @@
#include "SDL_video.h"
#include "gl3_loader.h"
#ifdef TRACY_ENABLE
#include <tracy/Tracy.hpp>
#include <tracy/TracyOpenGL.hpp>
#else
#define ZoneScoped
#define ZoneScopedN(name)
#define TracyGpuContext
#define TracyGpuContextName(name, size)
#define TracyGpuCollect
#define TracyGpuZone(name)
#define TracyGpuZoneC(name, color)
#endif
// undefine macros from header to avoid argument mismatch
#undef glGenTextures
#undef glDeleteTextures
@ -92,7 +105,10 @@ static bool s_fullscreen = false;
static pthread_key_t s_glCtxKey;
static pthread_once_t s_glCtxKeyOnce = PTHREAD_ONCE_INIT;
static void makeGLCtxKey() { pthread_key_create(&s_glCtxKey, nullptr); }
static void makeGLCtxKey() {
ZoneScoped;
pthread_key_create(&s_glCtxKey, nullptr);
}
static const int MAX_SHARED_CTXS = 6;
static SDL_Window* s_sharedWins[MAX_SHARED_CTXS] = {};
static SDL_GLContext s_sharedCtxs[MAX_SHARED_CTXS] = {};
@ -622,6 +638,7 @@ static GLenum mapPrim(int pt) {
// Initialises the renderer
void C4JRender::Initialise() {
ZoneScoped;
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
fprintf(stderr, "[4J_Render] SDL_Init: %s\n", SDL_GetError());
return;
@ -664,6 +681,8 @@ void C4JRender::Initialise() {
#ifndef GLES
gl3_load();
#endif
TracyGpuContext;
TracyGpuContextName("OpenGL", 6);
int fw, fh;
SDL_GetWindowSize(s_window, &fw, &fh);
onFramebufferResize(fw, fh);
@ -713,6 +732,7 @@ void C4JRender::Initialise() {
}
void C4JRender::InitialiseContext() {
ZoneScoped;
if (!s_window) return;
pthread_once(&s_glCtxKeyOnce, makeGLCtxKey);
if (s_mainThreadSet && pthread_equal(pthread_self(), s_mainThread)) {
@ -743,6 +763,7 @@ void C4JRender::InitialiseContext() {
}
void C4JRender::StartFrame() {
ZoneScoped;
Set_matrixDirty();
int w, h;
SDL_GetWindowSize(s_window, &w, &h);
@ -752,6 +773,7 @@ void C4JRender::StartFrame() {
}
void C4JRender::Present() {
ZoneScoped;
if (!s_window) return;
SDL_Event ev;
while (SDL_PollEvent(&ev)) {
@ -766,6 +788,7 @@ void C4JRender::Present() {
}
glFlush();
SDL_GL_SwapWindow(s_window);
TracyGpuCollect;
}
void C4JRender::SetWindowSize(int w, int h) {
@ -785,6 +808,7 @@ void C4JRender::GetFramebufferSize(int& w, int& h) {
void C4JRender::Close() { s_window = nullptr; }
void C4JRender::Shutdown() {
ZoneScoped;
pthread_mutex_lock(&s_glCallMtx);
for (auto& kv : s_chunkPool) kv.second.destroy();
s_chunkPool.clear();
@ -809,6 +833,7 @@ void C4JRender::Shutdown() {
void C4JRender::DrawVertices(ePrimitiveType ptype, int count, void* dataIn,
eVertexType vType, ePixelShaderType) {
ZoneScoped;
if (count <= 0 || !dataIn) return;
bool wasQuad = isQuadPrim((int)ptype);
@ -908,6 +933,7 @@ void C4JRender::DrawVertices(ePrimitiveType ptype, int count, void* dataIn,
glBufferSubData(GL_ARRAY_BUFFER, 0, (GLsizeiptr)bytes, dataIn);
s_streamVBOSize = (GLsizeiptr)bytes;
TracyGpuZone("DrawVertices");
glDrawArrays(glMode, 0, count);
glBindVertexArray(0);
@ -916,6 +942,7 @@ void C4JRender::DrawVertices(ePrimitiveType ptype, int count, void* dataIn,
}
void C4JRender::ReadPixels(int x, int y, int w, int h, void* buf) {
ZoneScoped;
if (!buf) return;
pthread_mutex_lock(&s_glCallMtx);
glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buf);
@ -923,6 +950,7 @@ void C4JRender::ReadPixels(int x, int y, int w, int h, void* buf) {
}
int C4JRender::CBuffCreate(int count) {
ZoneScoped;
pthread_mutex_lock(&s_glCallMtx);
int b = s_nextListBase;
s_nextListBase += count;
@ -931,6 +959,7 @@ int C4JRender::CBuffCreate(int count) {
}
void C4JRender::CBuffDelete(int first, int count) {
ZoneScoped;
pthread_mutex_lock(&s_glCallMtx);
for (int i = first; i < first + count; i++) {
auto it = s_chunkPool.find(i);
@ -943,6 +972,7 @@ void C4JRender::CBuffDelete(int first, int count) {
}
void C4JRender::CBuffDeleteAll() {
ZoneScoped;
pthread_mutex_lock(&s_glCallMtx);
for (auto& kv : s_chunkPool) {
kv.second.destroy();
@ -953,12 +983,14 @@ void C4JRender::CBuffDeleteAll() {
}
void C4JRender::CBuffStart(int index, bool) {
ZoneScoped;
s_recListId = index;
s_recVerts.clear();
s_recDraws.clear();
}
void C4JRender::CBuffEnd() {
ZoneScoped;
if (s_recListId < 0) return;
pthread_mutex_lock(&s_glCallMtx);
ChunkBuffer& cb = s_chunkPool[s_recListId];
@ -978,6 +1010,7 @@ void C4JRender::CBuffEnd() {
}
void C4JRender::CBuffClear(int index) {
ZoneScoped;
pthread_mutex_lock(&s_glCallMtx);
auto it = s_chunkPool.find(index);
if (it != s_chunkPool.end()) {
@ -988,6 +1021,7 @@ void C4JRender::CBuffClear(int index) {
}
bool C4JRender::CBuffCall(int index, bool) {
ZoneScoped;
pthread_mutex_lock(&s_glCallMtx);
auto it = s_chunkPool.find(index);
if (it == s_chunkPool.end() || !it->second.valid) {
@ -1018,6 +1052,7 @@ bool C4JRender::CBuffCall(int index, bool) {
pushRenderState();
TracyGpuZone("ChunkBufferDraw");
glBindVertexArray(cb.vao);
for (const auto& dc : cb.draws) glDrawArrays(dc.prim, dc.first, dc.count);
glBindVertexArray(0);
@ -1271,19 +1306,23 @@ void C4JRender::StateSetActiveTexture(int tex) {
}
int C4JRender::TextureCreate() {
ZoneScoped;
GLuint id;
glGenTextures(1, &id);
return (int)id;
}
void C4JRender::TextureFree(int i) {
ZoneScoped;
GLuint id = (GLuint)i;
glDeleteTextures(1, &id);
}
void C4JRender::TextureBind(int idx) {
ZoneScoped;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, idx < 0 ? 0 : (GLuint)idx);
}
void C4JRender::TextureBindVertex(int idx, bool scaleLight) {
ZoneScoped;
if (idx < 0) {
if (s_rs.useLightmap) {
s_rs.useLightmap = false;
@ -1312,6 +1351,7 @@ void C4JRender::TextureBindVertex(int idx, bool scaleLight) {
}
}
void C4JRender::TextureSetTextureLevels(int l) {
ZoneScoped;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, l > 0 ? l - 1 : 0);
if (l > 1)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
@ -1321,6 +1361,7 @@ void C4JRender::TextureSetTextureLevels(int l) {
}
int C4JRender::TextureGetTextureLevels() { return 1; }
void C4JRender::TextureData(int w, int h, void* d, int lvl, eTextureFormat) {
ZoneScoped;
glTexImage2D(GL_TEXTURE_2D, lvl, GL_RGBA, w, h, 0, GL_RGBA,
GL_UNSIGNED_BYTE, d);
if (lvl == 0) {
@ -1333,15 +1374,18 @@ void C4JRender::TextureData(int w, int h, void* d, int lvl, eTextureFormat) {
}
void C4JRender::TextureDataUpdate(int xo, int yo, int w, int h, void* d,
int lvl) {
ZoneScoped;
glTexSubImage2D(GL_TEXTURE_2D, lvl, xo, yo, w, h, GL_RGBA, GL_UNSIGNED_BYTE,
d);
}
void C4JRender::TextureSetParam(int p, int v) {
ZoneScoped;
glTexParameteri(GL_TEXTURE_2D, p, v);
}
static int stbLoad(unsigned char* data, int w, int h, D3DXIMAGE_INFO* info,
int** out) {
ZoneScoped;
int* px = new int[w * h];
for (int i = 0; i < w * h; i++) {
unsigned char r = data[i * 4], g = data[i * 4 + 1], b = data[i * 4 + 2],
@ -1356,6 +1400,7 @@ static int stbLoad(unsigned char* data, int w, int h, D3DXIMAGE_INFO* info,
return 0; // Success
}
int C4JRender::LoadTextureData(const char* fn, D3DXIMAGE_INFO* i, int** o) {
ZoneScoped;
int w, h, c;
unsigned char* d = stbi_load(fn, &w, &h, &c, 4);
if (!d) return -1; // Failure
@ -1365,6 +1410,7 @@ int C4JRender::LoadTextureData(const char* fn, D3DXIMAGE_INFO* i, int** o) {
}
int C4JRender::LoadTextureData(uint8_t* pb, uint32_t nb, D3DXIMAGE_INFO* i,
int** o) {
ZoneScoped;
int w, h, c;
unsigned char* d = stbi_load_from_memory(pb, (int)nb, &w, &h, &c, 4);
if (!d) return -1; // Failure