FIX: i fucking wrote profiler just to find that sleep function takes SECONDS arg 😭😭😭😭😭😭😭😭😭😭

This commit is contained in:
Kolyah35
2026-03-15 20:35:02 +03:00
parent b0fa2b820c
commit fadcf3a7d0
9 changed files with 133 additions and 172 deletions

View File

@@ -18,19 +18,14 @@
#include "../network/ServerSideNetworkHandler.h"
//#include "../network/Packet.h"
#include "../world/entity/player/Inventory.h"
#include "../world/level/chunk/ChunkCache.h"
#include "../world/level/tile/Tile.h"
#include "../world/level/storage/LevelStorageSource.h"
#include "../world/level/storage/LevelStorage.h"
#include "player/input/KeyboardInput.h"
#include "world/level/chunk/ChunkSource.h"
#ifndef STANDALONE_SERVER
#include "player/input/touchscreen/TouchInputHolder.h"
#endif
#include "player/LocalPlayer.h"
#include "gamemode/CreativeMode.h"
#include "gamemode/SurvivalMode.h"
#include "player/LocalPlayer.h"
#ifndef STANDALONE_SERVER
#include "particle/ParticleEngine.h"
#include "gui/Screen.h"
#include "gui/Font.h"
@@ -38,65 +33,14 @@
#include "gui/screens/ConsoleScreen.h"
#include "gui/screens/ChatScreen.h"
#include "sound/SoundEngine.h"
#endif
#include "../platform/CThread.h"
#include "../platform/input/Mouse.h"
#include "../AppPlatform.h"
#include "../Performance.h"
#include "../LicenseCodes.h"
#include "../util/PerfTimer.h"
#include "../util/PerfRenderer.h"
#include "player/input/MouseBuildInput.h"
#include "../world/Facing.h"
#include "../network/packet/PlaceBlockPacket.h"
#include "player/input/IInputHolder.h"
#ifndef STANDALONE_SERVER
#include "player/input/touchscreen/TouchscreenInput.h"
#include "player/input/ControllerTurnInput.h"
#include "player/input/XperiaPlayInput.h"
#endif
#include "renderer/Chunk.h"
#include "player/input/MouseTurnInput.h"
#include "../world/entity/MobFactory.h"
#include "../world/level/MobSpawner.h"
#include "../util/Mth.h"
#include "../network/packet/InteractPacket.h"
#ifndef STANDALONE_SERVER
#include "gui/screens/PrerenderTilesScreen.h"
#include "renderer/Textures.h"
#include "gui/screens/DeathScreen.h"
#endif
#include "../network/packet/RespawnPacket.h"
#include "IConfigListener.h"
#include "../world/entity/MobCategory.h"
#ifndef STANDALONE_SERVER
#include "gui/screens/FurnaceScreen.h"
#endif
#include "../world/Difficulty.h"
#include "../server/ServerLevel.h"
#ifdef CREATORMODE
#include "../server/CreatorLevel.h"
#endif
#include "../network/packet/AdventureSettingsPacket.h"
#include "../network/packet/SetSpawnPositionPacket.h"
#include "../network/command/CommandServer.h"
#include "gamemode/CreatorMode.h"
#ifndef STANDALONE_SERVER
#include "gui/screens/ArmorScreen.h"
#endif
#include "../world/level/levelgen/synth/ImprovedNoise.h"
#ifndef STANDALONE_SERVER
#include "renderer/tileentity/TileEntityRenderDispatcher.h"
#endif
#ifndef STANDALONE_SERVER
#include "renderer/ptexture/DynamicTexture.h"
#include "renderer/GameRenderer.h"
#include "renderer/ItemInHandRenderer.h"
@@ -106,8 +50,40 @@
#include "gui/Font.h"
#include "gui/screens/RenameMPLevelScreen.h"
#include "sound/SoundEngine.h"
#endif // STANDALONE_SERVER
#include "player/LocalPlayer.h"
#include "gamemode/CreativeMode.h"
#include "gamemode/SurvivalMode.h"
#include "player/LocalPlayer.h"
#include "../platform/CThread.h"
#include "../platform/input/Mouse.h"
#include "../AppPlatform.h"
#include "../LicenseCodes.h"
#include "../util/PerfTimer.h"
#include "../util/PerfRenderer.h"
#include "player/input/MouseBuildInput.h"
#include "player/input/IInputHolder.h"
#include "player/input/MouseTurnInput.h"
#include "../world/entity/MobFactory.h"
#include "../world/level/MobSpawner.h"
#include "../util/Mth.h"
#include "../network/packet/InteractPacket.h"
#include "../network/packet/RespawnPacket.h"
#include "IConfigListener.h"
#include "../world/entity/MobCategory.h"
#include "../world/Difficulty.h"
#include "../server/ServerLevel.h"
#ifdef CREATORMODE
#include "../server/CreatorLevel.h"
#endif
#include "../network/command/CommandServer.h"
#include "gamemode/CreatorMode.h"
static void checkGlError(const char* tag) {
#ifdef GLDEBUG
while (1) {
@@ -118,7 +94,7 @@ static void checkGlError(const char* tag) {
}
#endif /*GLDEBUG*/
}
#include <fstream>
/*static*/
const char* Minecraft::progressMessages[] = {
"Locating server",

View File

@@ -4,13 +4,12 @@
#include "Options.h"
#ifndef STANDALONE_SERVER
#include "MouseHandler.h"
#endif
#include "Timer.h"
#include "player/input/ITurnInput.h"
#ifndef STANDALONE_SERVER
#include "gui/Gui.h"
#include "gui/screens/ScreenChooser.h"
#endif
#include "Timer.h"
//#include "../network/RakNetInstance.h"
#include "../world/phys/HitResult.h"

View File

@@ -47,6 +47,7 @@
#include "../../network/packet/PlayerArmorEquipmentPacket.h"
namespace {
#ifndef STANDALONE_SERVER
static bool isBase64(unsigned char c) {
return (std::isalnum(c) || (c == '+') || (c == '/'));
@@ -177,6 +178,8 @@ static std::string getCapeUrlForUsername(const std::string& username) {
return getTextureUrlForUsername(username, "CAPE");
}
#endif
static bool ensureDirectoryExists(const std::string& path) {
#if defined(_WIN32)
return _mkdir(path.c_str()) == 0 || errno == EEXIST;
@@ -200,6 +203,8 @@ static bool fileExists(const std::string& path) {
#endif
}
#ifndef STANDALONE_SERVER
static void* fetchSkinForPlayer(void* param) {
LocalPlayer* player = (LocalPlayer*)param;
if (!player) return NULL;
@@ -290,6 +295,8 @@ static void* fetchCapeForPlayer(void* param) {
return NULL;
}
#endif
//@note: doesn't work completely, since it doesn't care about stairs rotation
static bool isJumpable(int tileId) {
return tileId != Tile::fence->id
@@ -318,12 +325,14 @@ LocalPlayer::LocalPlayer(Minecraft* minecraft, Level* level, User* user, int dim
this->dimension = dimension;
_init();
#ifndef STANDALONE_SERVER
if (user != NULL && !user->name.empty()) {
this->name = user->name;
// Fetch user skin and cape from Mojang servers in the background (avoids blocking the main thread)
new CThread(fetchSkinForPlayer, this);
new CThread(fetchCapeForPlayer, this);
}
#endif
}
LocalPlayer::~LocalPlayer() {

View File

@@ -61,15 +61,17 @@ int main(int numArguments, char* pszArgs[]) {
std::cout << "Level has been generated in " << getTimeS() - startTime << std::endl;
((MAIN_CLASS*)g_app)->level->saveLevelData();
std::cout << "Level has been saved!" << std::endl;
while(!app->wantToQuit()) {
app->update();
//pthread_yield();
sleep(20);
sleepMs(20);
}
((MAIN_CLASS*)g_app)->level->saveLevelData();
delete app;
appContext.platform->finish();
delete appContext.platform;
std::cout << "Quit correctly" << std::endl;
return g_exitCode;
}

View File

@@ -10,6 +10,12 @@
#define TIMER_PUSH(x) PerfTimer::push(x)
#define TIMER_POP() PerfTimer::pop()
#define TIMER_POP_PUSH(x) PerfTimer::popPush(x)
#elif defined(SERVER_PROFILER)
#include "ServerProfiler.h"
#define TIMER_PUSH(x) ServerProfiler::push(x)
#define TIMER_POP() ServerProfiler::pop()
#define TIMER_POP_PUSH(x) ServerProfiler::popPush(x)
#else
#define TIMER_PUSH(x) ((void*)0)
#define TIMER_POP() ((void*)0)

View File

@@ -0,0 +1,4 @@
#include "ServerProfiler.h"
std::stack<ServerProfiler::Entry> ServerProfiler::stack;
std::unordered_map<std::string, double> ServerProfiler::times;

43
src/util/ServerProfiler.h Normal file
View File

@@ -0,0 +1,43 @@
#pragma once
#include <chrono>
#include <ratio>
#include <iostream>
#include <string>
#include <unordered_map>
#include <stack>
namespace ServerProfiler {
using clock = std::chrono::high_resolution_clock;
struct Entry {
std::string name;
clock::time_point start;
};
static std::stack<Entry> stack;
static std::unordered_map<std::string, double> times;
inline void push(const std::string& name) {
stack.push({name, clock::now()});
}
inline void pop() {
auto end = clock::now();
auto e = stack.top();
stack.pop();
double dt = std::chrono::duration<double, std::micro>(end - e.start).count();
times[e.name] += dt;
}
inline void popPush(const std::string& name) {
pop(); push(name);
}
inline void report() {
for (auto& it : times) {
std::cout << "[PROFILER] " << it.first << ": " << it.second << std::endl;
}
}
};