Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1386b366a3 | |||
| f6d41eba4d | |||
| 93c0d1b1e1 | |||
| 04abf10331 | |||
| 4cdc29bbf4 |
@@ -89,6 +89,12 @@ pip install meson ninja
|
||||
|
||||
Or follow the [Meson quickstart guide](https://mesonbuild.com/Quick-guide.html).
|
||||
|
||||
### Tracy profiler
|
||||
|
||||
This project can be built with Tracy profiling support. Tracy is available as a meson subproject (bundled in `subprojects/tracy`) and many distributions provide the Tracy tooling; on Arch/Manjaro you can get the latest build from the AUR as `tracy-git`.
|
||||
|
||||
Tracy can be directly enabled if you enable the tracy meson option before compiling.
|
||||
|
||||
#### Docker (alternative)
|
||||
|
||||
If you don't want to install dependencies, use the included devcontainer. Open the project in VS Code with the [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension, or build manually:
|
||||
|
||||
+46
-32
@@ -1,16 +1,16 @@
|
||||
project(
|
||||
'4jcraft',
|
||||
['cpp', 'c'],
|
||||
version: '0.1.0',
|
||||
meson_version: '>= 1.3',
|
||||
default_options: [
|
||||
'cpp_std=c++23',
|
||||
'warning_level=0',
|
||||
'buildtype=debugoptimized', # for now
|
||||
'unity=on', # merge source files per target
|
||||
'unity_size=8', # TODO: mess around with this
|
||||
'b_pch=true', # precompiled headers
|
||||
],
|
||||
'4jcraft',
|
||||
['cpp', 'c'],
|
||||
version: '0.1.0',
|
||||
meson_version: '>= 1.3',
|
||||
default_options: [
|
||||
'cpp_std=c++23',
|
||||
'warning_level=0',
|
||||
'buildtype=debugoptimized', # for now
|
||||
'unity=on', # merge source files per target
|
||||
'unity_size=8', # TODO: mess around with this
|
||||
'b_pch=true', # precompiled headers
|
||||
],
|
||||
)
|
||||
|
||||
pymod = import('python')
|
||||
@@ -19,30 +19,30 @@ python = pymod.find_installation('python3', required: true)
|
||||
cc = meson.get_compiler('cpp')
|
||||
|
||||
global_cpp_defs = [
|
||||
'-DSPLIT_SAVES',
|
||||
'-D_LARGE_WORLDS',
|
||||
'-D_EXTENDED_ACHIEVEMENTS',
|
||||
'-D_DEBUG_MENUS_ENABLED',
|
||||
'-D_DEBUG',
|
||||
'-D_FORTIFY_SOURCE=2',
|
||||
'-DDEBUG',
|
||||
'-DSPLIT_SAVES',
|
||||
'-D_LARGE_WORLDS',
|
||||
'-D_EXTENDED_ACHIEVEMENTS',
|
||||
'-D_DEBUG_MENUS_ENABLED',
|
||||
'-D_DEBUG',
|
||||
'-D_FORTIFY_SOURCE=2',
|
||||
'-DDEBUG',
|
||||
]
|
||||
|
||||
if host_machine.system() == 'linux'
|
||||
global_cpp_defs += ['-Dlinux', '-D__linux', '-D__linux__']
|
||||
global_cpp_defs += ['-Dlinux', '-D__linux', '-D__linux__']
|
||||
endif
|
||||
|
||||
if get_option('renderer') == 'gles'
|
||||
global_cpp_defs += ['-DGLES']
|
||||
gl_dep = dependency('glesv2', required: true)
|
||||
glu_dep = dependency('', required: false)
|
||||
global_cpp_defs += ['-DGLES']
|
||||
gl_dep = dependency('glesv2', required: true)
|
||||
glu_dep = dependency('', required: false)
|
||||
else
|
||||
gl_dep = dependency('gl', required: true)
|
||||
glu_dep = dependency('glu', required: true)
|
||||
gl_dep = dependency('gl', required: true)
|
||||
glu_dep = dependency('glu', required: true)
|
||||
endif
|
||||
|
||||
if get_option('enable_vsync')
|
||||
global_cpp_defs += ['-DENABLE_VSYNC']
|
||||
global_cpp_defs += ['-DENABLE_VSYNC']
|
||||
endif
|
||||
|
||||
if get_option('classic_panorama')
|
||||
@@ -50,22 +50,22 @@ if get_option('classic_panorama')
|
||||
endif
|
||||
|
||||
if get_option('enable_frame_profiler')
|
||||
global_cpp_defs += ['-DENABLE_FRAME_PROFILER']
|
||||
global_cpp_defs += ['-DENABLE_FRAME_PROFILER']
|
||||
endif
|
||||
|
||||
if get_option('ui_backend') == 'shiggy'
|
||||
global_cpp_defs += ['-D_ENABLEIGGY']
|
||||
global_cpp_defs += ['-D_ENABLEIGGY']
|
||||
endif
|
||||
|
||||
if get_option('ui_backend') == 'java'
|
||||
global_cpp_defs += '-DENABLE_JAVA_GUIS'
|
||||
global_cpp_defs += '-DENABLE_JAVA_GUIS'
|
||||
endif
|
||||
|
||||
add_project_arguments(global_cpp_defs, language: ['cpp', 'c'])
|
||||
|
||||
global_cpp_args = [
|
||||
'-Wshift-count-overflow',
|
||||
'-pipe',
|
||||
'-Wshift-count-overflow',
|
||||
'-pipe',
|
||||
]
|
||||
add_project_arguments(global_cpp_args, language: 'cpp')
|
||||
|
||||
@@ -79,6 +79,20 @@ stb_dep = declare_dependency(include_directories: stb)
|
||||
|
||||
miniaudio_dep = dependency('miniaudio')
|
||||
|
||||
tracy_opt = get_option('tracy')
|
||||
|
||||
if not tracy_opt.disabled()
|
||||
tracy_proj = subproject('tracy', required: tracy_opt, default_options: ['tracy_enable=true'])
|
||||
if tracy_proj.found()
|
||||
tracy_client_dep = tracy_proj.get_variable('tracy_dep')
|
||||
add_project_arguments('-DTRACY_ENABLE', language: ['cpp', 'c'])
|
||||
else
|
||||
tracy_client_dep = dependency('', required: false)
|
||||
endif
|
||||
else
|
||||
tracy_client_dep = dependency('', required: false)
|
||||
endif
|
||||
|
||||
subdir('targets/util')
|
||||
subdir('targets/java')
|
||||
subdir('targets/nbt')
|
||||
@@ -86,4 +100,4 @@ subdir('targets/platform')
|
||||
|
||||
subdir('targets/resources')
|
||||
subdir('targets/minecraft')
|
||||
subdir('targets/app')
|
||||
subdir('targets/app')
|
||||
+9
-2
@@ -7,8 +7,8 @@ option(
|
||||
)
|
||||
|
||||
option('classic_panorama',
|
||||
type : 'boolean',
|
||||
value : false,
|
||||
type : 'boolean',
|
||||
value : false,
|
||||
description : 'Enable classic java edition panorama (ui_backend=java ONLY).')
|
||||
|
||||
option(
|
||||
@@ -40,3 +40,10 @@ option(
|
||||
value: 'frustum',
|
||||
description: 'Occlusion culling mode. Off disables ALL CULLING (debug only!), Frustum disables offscreen rendering (default), BFS is experimental connectivity culling, hardware uses GPU queries.',
|
||||
)
|
||||
|
||||
option(
|
||||
'tracy',
|
||||
type: 'feature',
|
||||
value: 'auto',
|
||||
description: 'Enable Tracy profiler'
|
||||
)
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
[wrap-git]
|
||||
url = https://github.com/wolfpld/tracy.git
|
||||
revision = master
|
||||
depth = 1
|
||||
@@ -93,6 +93,13 @@
|
||||
#include "minecraft/server/PlayerList.h"
|
||||
#include "minecraft/server/level/ServerPlayer.h"
|
||||
|
||||
#ifdef TRACY_ENABLE
|
||||
#include <tracy/Tracy.hpp>
|
||||
#else
|
||||
#define ZoneScoped
|
||||
#define ZoneScopedN(name)
|
||||
#endif
|
||||
|
||||
class BeaconTileEntity;
|
||||
class BrewingStandTileEntity;
|
||||
class DispenserTileEntity;
|
||||
@@ -114,6 +121,7 @@ const float Game::fSafeZoneX = 64.0f; // 5% of 1280
|
||||
const float Game::fSafeZoneY = 36.0f; // 5% of 720
|
||||
|
||||
Game::Game() {
|
||||
ZoneScopedN("Game::Game");
|
||||
if (GAME_SETTINGS_PROFILE_DATA_BYTES != sizeof(GAME_SETTINGS)) {
|
||||
DebugPrintf(
|
||||
"WARNING: The size of the profile GAME_SETTINGS struct has "
|
||||
@@ -152,6 +160,7 @@ Game::Game() {
|
||||
}
|
||||
|
||||
void Game::DebugPrintf(const char* szFormat, ...) {
|
||||
ZoneScopedN("Game::DebugPrintf");
|
||||
#if !defined(_FINAL_BUILD)
|
||||
char buf[1024];
|
||||
va_list ap;
|
||||
@@ -163,6 +172,7 @@ void Game::DebugPrintf(const char* szFormat, ...) {
|
||||
}
|
||||
|
||||
void Game::DebugPrintf(int user, const char* szFormat, ...) {
|
||||
ZoneScopedN("Game::DebugPrintf");
|
||||
#if !defined(_FINAL_BUILD)
|
||||
if (user == USER_NONE) return;
|
||||
char buf[1024];
|
||||
@@ -178,6 +188,7 @@ void Game::DebugPrintf(int user, const char* szFormat, ...) {
|
||||
}
|
||||
|
||||
const wchar_t* Game::GetString(int iID) {
|
||||
ZoneScopedN("Game::GetString");
|
||||
// return L"Değişiklikler ve Yenilikler";
|
||||
// return L"ÕÕÕÕÖÖÖÖ";
|
||||
return app.m_localizationManager.getString(iID);
|
||||
@@ -424,23 +435,28 @@ unsigned int Game::GetGameHostOption(eGameHostOption eVal) {
|
||||
|
||||
|
||||
void Game::processSchematics(LevelChunk* levelChunk) {
|
||||
ZoneScopedN("Game::processSchematics");
|
||||
m_gameRules.processSchematics(levelChunk);
|
||||
}
|
||||
|
||||
void Game::processSchematicsLighting(LevelChunk* levelChunk) {
|
||||
ZoneScopedN("Game::processSchematicsLighting");
|
||||
m_gameRules.processSchematicsLighting(levelChunk);
|
||||
}
|
||||
|
||||
void Game::loadDefaultGameRules() {
|
||||
ZoneScopedN("Game::loadDefaultGameRules");
|
||||
m_gameRules.loadDefaultGameRules();
|
||||
}
|
||||
|
||||
void Game::setLevelGenerationOptions(
|
||||
LevelGenerationOptions* levelGen) {
|
||||
ZoneScopedN("Game::setLevelGenerationOptions");
|
||||
m_gameRules.setLevelGenerationOptions(levelGen);
|
||||
}
|
||||
|
||||
const wchar_t* Game::GetGameRulesString(const std::wstring& key) {
|
||||
ZoneScopedN("Game::GetGameRulesString");
|
||||
return m_gameRules.GetGameRulesString(key);
|
||||
}
|
||||
|
||||
@@ -456,6 +472,7 @@ const wchar_t* Game::GetGameRulesString(const std::wstring& key) {
|
||||
|
||||
|
||||
std::wstring Game::getEntityName(eINSTANCEOF type) {
|
||||
ZoneScopedN("Game::getEntityName");
|
||||
switch (type) {
|
||||
case eTYPE_WOLF:
|
||||
return app.GetString(IDS_WOLF);
|
||||
@@ -608,20 +625,24 @@ int32_t Game::RegisterConfigValues(wchar_t* pType, int iValue) {
|
||||
|
||||
// AUTOSAVE
|
||||
void Game::SetAutosaveTimerTime(void) {
|
||||
ZoneScopedN("Game::SetAutosaveTimerTime");
|
||||
int settingValue = GetGameSettings(ProfileManager.GetPrimaryPad(), eGameSetting_Autosave);
|
||||
m_saveManager.setAutosaveTimerTime(settingValue);
|
||||
}
|
||||
|
||||
void Game::SetTrialTimerStart(void) {
|
||||
ZoneScopedN("Game::SetTrialTimerStart");
|
||||
m_fTrialTimerStart = m_Time.fAppTime;
|
||||
mfTrialPausedTime = 0.0f;
|
||||
}
|
||||
|
||||
float Game::getTrialTimer(void) {
|
||||
ZoneScopedN("Game::getTrialTimer");
|
||||
return m_Time.fAppTime - m_fTrialTimerStart - mfTrialPausedTime;
|
||||
}
|
||||
|
||||
bool Game::IsLocalMultiplayerAvailable() {
|
||||
ZoneScopedN("Game::IsLocalMultiplayerAvailable");
|
||||
unsigned int connectedControllers = 0;
|
||||
for (unsigned int i = 0; i < XUSER_MAX_COUNT; ++i) {
|
||||
if (InputManager.IsPadConnected(i) || ProfileManager.IsSignedIn(i))
|
||||
@@ -661,6 +682,7 @@ std::wstring Game::getFilePath(std::uint32_t packId,
|
||||
std::wstring filename,
|
||||
bool bAddDataFolder,
|
||||
std::wstring mountPoint) {
|
||||
ZoneScopedN("Game::getFilePath");
|
||||
std::wstring path =
|
||||
getRootPath(packId, true, bAddDataFolder, mountPoint) + filename;
|
||||
File f(path);
|
||||
@@ -695,6 +717,7 @@ std::wstring titleUpdateTexturePackRoot = L"CU\\DLC\\";
|
||||
std::wstring Game::getRootPath(std::uint32_t packId,
|
||||
bool allowOverride, bool bAddDataFolder,
|
||||
std::wstring mountPoint) {
|
||||
ZoneScopedN("Game::getRootPath");
|
||||
std::wstring path = mountPoint;
|
||||
if (allowOverride) {
|
||||
switch (packId) {
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
#include <cstdlib>
|
||||
#include <new>
|
||||
#include <mutex>
|
||||
#include <unordered_set>
|
||||
#ifdef _WIN32
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
#ifdef TRACY_ENABLE
|
||||
#include <tracy/Tracy.hpp>
|
||||
|
||||
namespace {
|
||||
template <typename T>
|
||||
struct TracyMallocAllocator {
|
||||
using value_type = T;
|
||||
TracyMallocAllocator() noexcept = default;
|
||||
template <typename U>
|
||||
TracyMallocAllocator(const TracyMallocAllocator<U>&) noexcept {}
|
||||
T* allocate(std::size_t n) {
|
||||
return static_cast<T*>(std::malloc(n * sizeof(T)));
|
||||
}
|
||||
void deallocate(T* p, std::size_t) noexcept { std::free(p); }
|
||||
};
|
||||
|
||||
using PtrSet =
|
||||
std::unordered_set<void*, std::hash<void*>, std::equal_to<void*>,
|
||||
TracyMallocAllocator<void*>>;
|
||||
|
||||
inline PtrSet* GetAllocSet() {
|
||||
static PtrSet* set = []() -> PtrSet* {
|
||||
void* mem = std::malloc(sizeof(PtrSet));
|
||||
return mem ? new (mem) PtrSet() : nullptr;
|
||||
}();
|
||||
return set;
|
||||
}
|
||||
|
||||
inline std::mutex* GetAllocMutex() {
|
||||
static std::mutex* mtx = []() -> std::mutex* {
|
||||
void* mem = std::malloc(sizeof(std::mutex));
|
||||
return mem ? new (mem) std::mutex() : nullptr;
|
||||
}();
|
||||
return mtx;
|
||||
}
|
||||
|
||||
inline void* TracyAlignedAlloc(std::size_t size, std::size_t alignment) {
|
||||
if (alignment < alignof(void*)) alignment = alignof(void*);
|
||||
#if defined(_WIN32)
|
||||
return _aligned_malloc(size, alignment);
|
||||
#else
|
||||
void* ptr = nullptr;
|
||||
if (posix_memalign(&ptr, alignment, size) != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void TracyAlignedFree(void* ptr) {
|
||||
#if defined(_WIN32)
|
||||
_aligned_free(ptr);
|
||||
#else
|
||||
free(ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void TracyTrackAlloc(void* ptr, std::size_t size) {
|
||||
if (!ptr) return;
|
||||
auto* set = GetAllocSet();
|
||||
auto* mtx = GetAllocMutex();
|
||||
if (!set || !mtx) return;
|
||||
std::lock_guard<std::mutex> lock(*mtx);
|
||||
set->insert(ptr);
|
||||
TracyAlloc(ptr, size);
|
||||
}
|
||||
|
||||
inline void TracyTrackFree(void* ptr) {
|
||||
if (!ptr) return;
|
||||
auto* set = GetAllocSet();
|
||||
auto* mtx = GetAllocMutex();
|
||||
if (!set || !mtx) return;
|
||||
std::lock_guard<std::mutex> lock(*mtx);
|
||||
if (set->erase(ptr) != 0) {
|
||||
TracyFree(ptr);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void* operator new(std::size_t count) {
|
||||
void* ptr = std::malloc(count);
|
||||
if (!ptr) throw std::bad_alloc();
|
||||
TracyTrackAlloc(ptr, count);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* operator new[](std::size_t count) {
|
||||
void* ptr = std::malloc(count);
|
||||
if (!ptr) throw std::bad_alloc();
|
||||
TracyTrackAlloc(ptr, count);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void operator delete(void* ptr) noexcept {
|
||||
TracyTrackFree(ptr);
|
||||
std::free(ptr);
|
||||
}
|
||||
|
||||
void operator delete[](void* ptr) noexcept {
|
||||
TracyTrackFree(ptr);
|
||||
std::free(ptr);
|
||||
}
|
||||
|
||||
void operator delete(void* ptr, std::size_t) noexcept {
|
||||
TracyTrackFree(ptr);
|
||||
std::free(ptr);
|
||||
}
|
||||
|
||||
void operator delete[](void* ptr, std::size_t) noexcept {
|
||||
TracyTrackFree(ptr);
|
||||
std::free(ptr);
|
||||
}
|
||||
|
||||
void* operator new(std::size_t count, const std::nothrow_t&) noexcept {
|
||||
void* ptr = std::malloc(count);
|
||||
TracyTrackAlloc(ptr, count);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* operator new[](std::size_t count, const std::nothrow_t&) noexcept {
|
||||
void* ptr = std::malloc(count);
|
||||
TracyTrackAlloc(ptr, count);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void operator delete(void* ptr, const std::nothrow_t&) noexcept {
|
||||
TracyTrackFree(ptr);
|
||||
std::free(ptr);
|
||||
}
|
||||
|
||||
void operator delete[](void* ptr, const std::nothrow_t&) noexcept {
|
||||
TracyTrackFree(ptr);
|
||||
std::free(ptr);
|
||||
}
|
||||
|
||||
void* operator new(std::size_t count, std::align_val_t align) {
|
||||
void* ptr = TracyAlignedAlloc(count, (std::size_t)align);
|
||||
if (!ptr) throw std::bad_alloc();
|
||||
TracyTrackAlloc(ptr, count);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* operator new[](std::size_t count, std::align_val_t align) {
|
||||
void* ptr = TracyAlignedAlloc(count, (std::size_t)align);
|
||||
if (!ptr) throw std::bad_alloc();
|
||||
TracyTrackAlloc(ptr, count);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* operator new(std::size_t count, std::align_val_t align,
|
||||
const std::nothrow_t&) noexcept {
|
||||
void* ptr = TracyAlignedAlloc(count, (std::size_t)align);
|
||||
TracyTrackAlloc(ptr, count);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* operator new[](std::size_t count, std::align_val_t align,
|
||||
const std::nothrow_t&) noexcept {
|
||||
void* ptr = TracyAlignedAlloc(count, (std::size_t)align);
|
||||
TracyTrackAlloc(ptr, count);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void operator delete(void* ptr, std::align_val_t) noexcept {
|
||||
TracyTrackFree(ptr);
|
||||
TracyAlignedFree(ptr);
|
||||
}
|
||||
|
||||
void operator delete[](void* ptr, std::align_val_t) noexcept {
|
||||
TracyTrackFree(ptr);
|
||||
TracyAlignedFree(ptr);
|
||||
}
|
||||
|
||||
void operator delete(void* ptr, std::align_val_t, const std::nothrow_t&) noexcept {
|
||||
TracyTrackFree(ptr);
|
||||
TracyAlignedFree(ptr);
|
||||
}
|
||||
|
||||
void operator delete[](void* ptr, std::align_val_t, const std::nothrow_t&) noexcept {
|
||||
TracyTrackFree(ptr);
|
||||
TracyAlignedFree(ptr);
|
||||
}
|
||||
|
||||
void operator delete(void* ptr, std::size_t, std::align_val_t) noexcept {
|
||||
TracyTrackFree(ptr);
|
||||
TracyAlignedFree(ptr);
|
||||
}
|
||||
|
||||
void operator delete[](void* ptr, std::size_t, std::align_val_t) noexcept {
|
||||
TracyTrackFree(ptr);
|
||||
TracyAlignedFree(ptr);
|
||||
}
|
||||
#endif
|
||||
@@ -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, ¤t_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, ¤t_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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,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"
|
||||
@@ -107,6 +115,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
|
||||
|
||||
@@ -412,6 +421,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;
|
||||
@@ -650,6 +660,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;
|
||||
@@ -663,6 +674,7 @@ uint8_t* mallocAndCreateUTF8ArrayFromString(int iID) {
|
||||
}
|
||||
|
||||
uint8_t* AddRichPresenceString(int iID) {
|
||||
ZoneScoped;
|
||||
uint8_t* strUtf8 = mallocAndCreateUTF8ArrayFromString(iID);
|
||||
if (strUtf8 != nullptr) {
|
||||
vRichPresenceStrings.push_back(strUtf8);
|
||||
@@ -671,6 +683,7 @@ uint8_t* AddRichPresenceString(int iID) {
|
||||
}
|
||||
|
||||
void FreeRichPresenceStrings() {
|
||||
ZoneScoped;
|
||||
uint8_t* strUtf8;
|
||||
for (int i = 0; i < vRichPresenceStrings.size(); i++) {
|
||||
strUtf8 = vRichPresenceStrings.at(i);
|
||||
|
||||
+83
-63
@@ -1,86 +1,106 @@
|
||||
exclude_sources = [
|
||||
' ! -path "*/common/*"',
|
||||
' ! -path "*/linux/*"',
|
||||
' ! -path "*/windows/*"',
|
||||
]
|
||||
|
||||
# all sources except common/, linux/, windows/
|
||||
client_sources = run_command(
|
||||
'sh',
|
||||
'-c', 'find "'
|
||||
+ meson.current_source_dir()
|
||||
+ '" \\( -name "*.cpp" -o -name "*.c" \\)'
|
||||
+ ' '.join(exclude_sources),
|
||||
check: true,
|
||||
).stdout().strip().split('\n')
|
||||
|
||||
exclude_platform_common_sources = [
|
||||
' ! -name "UIScene_InGameSaveManagementMenu.cpp"',
|
||||
' ! -name "UIScene_InGameSaveManagementMenu.cpp"',
|
||||
]
|
||||
|
||||
# all sources in common/
|
||||
platform_sources = run_command(
|
||||
'sh',
|
||||
'-c', 'find "'
|
||||
+ meson.current_source_dir() / 'common'
|
||||
+ '" \\( -name "*.cpp" -o -name "*.c" \\)'
|
||||
+ ' '.join(exclude_platform_common_sources),
|
||||
check: true,
|
||||
'sh',
|
||||
'-c', 'find "'
|
||||
+ meson.current_source_dir() / 'common'
|
||||
+ '" \\( -name "*.cpp" -o -name "*.c" \\)'
|
||||
+ ' '.join(exclude_platform_common_sources),
|
||||
check: true,
|
||||
).stdout().strip().split('\n')
|
||||
|
||||
# linux-specific files
|
||||
if host_machine.system() == 'linux'
|
||||
platform_sources += run_command(
|
||||
'sh',
|
||||
'-c', 'find "'
|
||||
+ meson.current_source_dir() / 'linux'
|
||||
+ '" \\( -name "*.cpp" -o -name "*.c" \\) ',
|
||||
check: true,
|
||||
).stdout().strip().split('\n')
|
||||
platform_sources += run_command(
|
||||
'sh',
|
||||
'-c', 'find "'
|
||||
+ meson.current_source_dir() / 'linux'
|
||||
+ '" \\( -name "*.cpp" -o -name "*.c" \\) ',
|
||||
check: true,
|
||||
).stdout().strip().split('\n')
|
||||
endif
|
||||
|
||||
client_dependencies = [
|
||||
java_dep,
|
||||
nbt_dep,
|
||||
render_dep,
|
||||
input_dep,
|
||||
profile_dep,
|
||||
storage_dep,
|
||||
assets_localisation_dep,
|
||||
platform_dep,
|
||||
minecraft_dep,
|
||||
gl_dep,
|
||||
glu_dep,
|
||||
thread_dep,
|
||||
dl_dep,
|
||||
dependency('zlib'),
|
||||
miniaudio_dep,
|
||||
stb_dep,
|
||||
util_dep,
|
||||
java_dep,
|
||||
nbt_dep,
|
||||
render_dep,
|
||||
input_dep,
|
||||
profile_dep,
|
||||
storage_dep,
|
||||
assets_localisation_dep,
|
||||
platform_dep,
|
||||
minecraft_dep,
|
||||
gl_dep,
|
||||
glu_dep,
|
||||
thread_dep,
|
||||
dl_dep,
|
||||
dependency('zlib'),
|
||||
miniaudio_dep,
|
||||
stb_dep,
|
||||
util_dep,
|
||||
tracy_client_dep,
|
||||
]
|
||||
|
||||
if get_option('ui_backend') == 'shiggy'
|
||||
shiggy_dep = dependency(
|
||||
'shiggy',
|
||||
fallback: ['shiggy', 'shiggy_dep'],
|
||||
)
|
||||
client_dependencies += shiggy_dep
|
||||
shiggy_dep = dependency(
|
||||
'shiggy',
|
||||
fallback: ['shiggy', 'shiggy_dep'],
|
||||
)
|
||||
client_dependencies += shiggy_dep
|
||||
endif
|
||||
|
||||
platform_services_src = files('../platform/PlatformServices.cpp')
|
||||
|
||||
client = executable(
|
||||
'Minecraft.Client',
|
||||
platform_sources + platform_services_src + localisation[1],
|
||||
include_directories: include_directories('..'),
|
||||
dependencies: client_dependencies,
|
||||
cpp_args: global_cpp_args
|
||||
+ global_cpp_defs
|
||||
+ [
|
||||
'-DUNICODE',
|
||||
'-D_UNICODE',
|
||||
],
|
||||
c_args: global_cpp_defs + ['-DUNICODE', '-D_UNICODE'],
|
||||
install: true,
|
||||
install_dir: '',
|
||||
'Minecraft.Client',
|
||||
client_sources
|
||||
+ platform_sources
|
||||
+ platform_services_src
|
||||
+ localisation[1],
|
||||
include_directories: include_directories('include', '..'),
|
||||
dependencies: client_dependencies,
|
||||
cpp_args: global_cpp_args
|
||||
+ global_cpp_defs
|
||||
+ [
|
||||
'-DUNICODE',
|
||||
'-D_UNICODE',
|
||||
],
|
||||
c_args: global_cpp_defs + ['-DUNICODE', '-D_UNICODE'],
|
||||
install: true,
|
||||
install_dir: '',
|
||||
)
|
||||
|
||||
custom_target(
|
||||
'copy_assets_to_client',
|
||||
input: [client, media_archive],
|
||||
output: 'assets.stamp',
|
||||
command: [
|
||||
python,
|
||||
meson.project_source_root() / 'scripts/copy_assets_to_client.py',
|
||||
meson.project_source_root(),
|
||||
meson.project_build_root(),
|
||||
meson.current_build_dir(),
|
||||
'@INPUT1@',
|
||||
'@OUTPUT@',
|
||||
],
|
||||
build_by_default: true,
|
||||
)
|
||||
'copy_assets_to_client',
|
||||
input: [client, media_archive],
|
||||
output: 'assets.stamp',
|
||||
command: [
|
||||
python,
|
||||
meson.project_source_root() / 'scripts/copy_assets_to_client.py',
|
||||
meson.project_source_root(),
|
||||
meson.project_build_root(),
|
||||
meson.current_build_dir(),
|
||||
'@INPUT1@',
|
||||
'@OUTPUT@',
|
||||
],
|
||||
build_by_default: true,
|
||||
)
|
||||
@@ -133,6 +133,13 @@
|
||||
#include "minecraft/world/level/chunk/SparseDataStorage.h"
|
||||
#include "minecraft/world/level/chunk/SparseLightStorage.h"
|
||||
|
||||
#ifdef TRACY_ENABLE
|
||||
#include <tracy/Tracy.hpp>
|
||||
#else
|
||||
#define ZoneScoped
|
||||
#define ZoneScopedN(name)
|
||||
#endif
|
||||
|
||||
class ChunkSource;
|
||||
|
||||
// #define DISABLE_SPU_CODE
|
||||
@@ -160,6 +167,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;
|
||||
@@ -278,6 +286,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;
|
||||
@@ -286,11 +295,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();
|
||||
@@ -396,6 +407,7 @@ void Minecraft::init() {
|
||||
}
|
||||
|
||||
void Minecraft::renderLoadingScreen() {
|
||||
ZoneScopedN("Minecraft::renderLoadingScreen");
|
||||
// 4J Unused
|
||||
// testing stuff on vita just now
|
||||
#if defined(ENABLE_JAVA_GUIS)
|
||||
@@ -448,6 +460,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();
|
||||
@@ -464,11 +477,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"));
|
||||
@@ -503,6 +518,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) {
|
||||
@@ -571,10 +587,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();*/
|
||||
@@ -661,6 +679,7 @@ void Minecraft::destroy() {
|
||||
// from our xbox game loop
|
||||
|
||||
void Minecraft::run() {
|
||||
ZoneScopedN("Minecraft::run");
|
||||
running = true;
|
||||
// try { // 4J - removed try/catch
|
||||
init();
|
||||
@@ -1815,17 +1834,20 @@ void Minecraft::run_middle() {
|
||||
*/
|
||||
}
|
||||
} // lock_guard scope
|
||||
FrameMark;
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -1918,11 +1940,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
|
||||
@@ -1936,6 +1960,7 @@ void Minecraft::pauseGame() {
|
||||
}
|
||||
|
||||
bool Minecraft::pollResize() {
|
||||
ZoneScopedN("Minecraft::pollResize");
|
||||
int fbw, fbh;
|
||||
RenderManager.GetFramebufferSize(fbw, fbh);
|
||||
if (fbw != width_phys || fbh != height_phys) {
|
||||
@@ -1946,6 +1971,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
|
||||
@@ -1973,6 +1999,7 @@ void Minecraft::resize(int width, int height) {
|
||||
}
|
||||
|
||||
void Minecraft::verify() {
|
||||
ZoneScopedN("Minecraft::verify");
|
||||
/* 4J - TODO
|
||||
new Thread() {
|
||||
public void run() {
|
||||
@@ -1992,11 +2019,13 @@ void Minecraft::verify() {
|
||||
}
|
||||
|
||||
void Minecraft::levelTickUpdateFunc(void* pParam) {
|
||||
ZoneScopedN("Minecraft::levelTickUpdateFunc");
|
||||
Level* pLevel = (Level*)pParam;
|
||||
pLevel->tick();
|
||||
}
|
||||
|
||||
void Minecraft::levelTickThreadInitFunc() {
|
||||
ZoneScopedN("Minecraft::levelTickThreadInitFunc");
|
||||
Compression::UseDefaultThreadStorage();
|
||||
}
|
||||
|
||||
@@ -2005,6 +2034,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) {
|
||||
ZoneScopedN("Minecraft::tick");
|
||||
int iPad = player->GetXboxPad();
|
||||
// OutputDebugString("Minecraft::tick\n");
|
||||
|
||||
@@ -3657,6 +3687,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);
|
||||
@@ -3664,6 +3695,7 @@ void Minecraft::reloadSound() {
|
||||
}
|
||||
|
||||
bool Minecraft::isClientSide() {
|
||||
ZoneScopedN("Minecraft::isClientSide");
|
||||
return level != nullptr && level->isClientSide;
|
||||
}
|
||||
|
||||
@@ -3675,10 +3707,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);
|
||||
}
|
||||
@@ -3686,6 +3720,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);
|
||||
|
||||
@@ -3700,6 +3735,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)
|
||||
@@ -3724,6 +3760,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;
|
||||
@@ -3912,6 +3949,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);
|
||||
@@ -3950,6 +3988,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);
|
||||
@@ -3968,27 +4007,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>(gameServices().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
|
||||
@@ -4092,12 +4136,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;
|
||||
|
||||
@@ -4182,6 +4228,7 @@ void Minecraft::startAndConnectTo(const std::wstring& name,
|
||||
}
|
||||
|
||||
ClientConnection* Minecraft::getConnection(int iPad) {
|
||||
ZoneScopedN("Minecraft::getConnection");
|
||||
return localplayers[iPad]->connection;
|
||||
}
|
||||
|
||||
@@ -4193,6 +4240,7 @@ bool useLomp = false;
|
||||
int g_iMainThreadId;
|
||||
|
||||
void Minecraft::main() {
|
||||
ZoneScopedN("Minecraft::main");
|
||||
std::wstring name;
|
||||
std::wstring sessionId;
|
||||
|
||||
@@ -4236,6 +4284,7 @@ void Minecraft::main() {
|
||||
}
|
||||
|
||||
bool Minecraft::renderNames() {
|
||||
ZoneScopedN("Minecraft::renderNames");
|
||||
if (m_instance == nullptr || !m_instance->options->hideGui) {
|
||||
return true;
|
||||
}
|
||||
@@ -4243,23 +4292,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;
|
||||
|
||||
@@ -4277,6 +4331,7 @@ int Minecraft::maxSupportedTextureSize() {
|
||||
void Minecraft::delayTextureReload() { reloadTextures = true; }
|
||||
|
||||
int64_t Minecraft::currentTimeMillis() {
|
||||
ZoneScopedN("Minecraft::currentTimeMillis");
|
||||
return System::currentTimeMillis(); //(Sys.getTime() * 1000) /
|
||||
// Sys.getTimerResolution();
|
||||
}
|
||||
@@ -4304,6 +4359,7 @@ gameMode->stopDestroyBlock();
|
||||
|
||||
void Minecraft::handleMouseClick(int button)
|
||||
{
|
||||
ZoneScopedN("Minecraft::handleMouseClick");
|
||||
if (button == 0 && missTime > 0) return;
|
||||
if (button == 0)
|
||||
{
|
||||
@@ -4419,6 +4475,7 @@ gameRenderer->itemInHandRenderer->itemUsed();
|
||||
Screen* Minecraft::getScreen() { return screen; }
|
||||
|
||||
bool Minecraft::isTutorial() {
|
||||
ZoneScopedN("Minecraft::isTutorial");
|
||||
return m_inFullTutorialBits > 0;
|
||||
|
||||
/*if( gameMode != nullptr && gameMode->isTutorial() )
|
||||
@@ -4432,6 +4489,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 (gameServices().getTutorialMode())
|
||||
@@ -4439,6 +4497,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) {
|
||||
@@ -4453,6 +4512,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()) {
|
||||
@@ -4519,6 +4579,7 @@ int Minecraft::InGame_SignInReturned(void* pParam, bool bContinue, int iPad) {
|
||||
}
|
||||
|
||||
void Minecraft::tickAllConnections() {
|
||||
ZoneScopedN("Minecraft::tickAllConnections");
|
||||
int oldIdx = getLocalPlayerIdx();
|
||||
for (unsigned int i = 0; i < XUSER_MAX_COUNT; i++) {
|
||||
std::shared_ptr<MultiplayerLocalPlayer> mplp = localplayers[i];
|
||||
@@ -4532,6 +4593,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()) {
|
||||
@@ -4542,6 +4604,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()) {
|
||||
@@ -4550,10 +4613,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();
|
||||
|
||||
@@ -58,6 +58,7 @@ lib_minecraft = static_library('minecraft',
|
||||
assets_localisation_dep,
|
||||
platform_dep,
|
||||
util_dep,
|
||||
tracy_client_dep,
|
||||
dependency('zlib'),
|
||||
],
|
||||
include_directories : include_directories('..'),
|
||||
|
||||
@@ -47,7 +47,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
|
||||
@@ -91,17 +92,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)
|
||||
@@ -116,6 +120,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
|
||||
@@ -195,7 +202,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 {
|
||||
@@ -214,6 +221,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();
|
||||
@@ -256,6 +266,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) |
|
||||
@@ -274,10 +285,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;
|
||||
@@ -286,6 +303,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);
|
||||
@@ -305,6 +323,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"));
|
||||
@@ -325,7 +344,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);
|
||||
@@ -344,6 +363,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;
|
||||
@@ -354,6 +377,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
|
||||
|
||||
@@ -384,7 +410,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;
|
||||
@@ -393,7 +419,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;
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,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;
|
||||
|
||||
@@ -144,7 +145,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();
|
||||
|
||||
@@ -163,7 +164,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);
|
||||
@@ -181,7 +182,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;
|
||||
}
|
||||
@@ -282,7 +283,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));
|
||||
}
|
||||
|
||||
@@ -290,7 +291,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 +
|
||||
@@ -405,7 +406,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);
|
||||
@@ -430,7 +431,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);
|
||||
@@ -449,7 +450,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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user