space-game001/src/Game.h
2026-04-30 15:15:11 +06:00

134 lines
3.6 KiB
C++

#pragma once
#include "Character.h"
#include "BoneAnimatedModel.h"
#include "render/Renderer.h"
#include "Environment.h"
#include "render/TextureManager.h"
#include "SparkEmitter.h"
#include "UiManager.h"
#include "utils/TaskManager.h"
#include "items/GameObjectLoader.h"
#include "items/Item.h"
#include "items/InteractiveObject.h"
#include <queue>
#include <vector>
#include <string>
#include <memory>
#include <cstdint>
#include <render/TextRenderer.h>
#include "MenuManager.h"
#include <unordered_map>
#include <unordered_set>
#include "Location.h"
#include "AudioPlayerAsync.h"
#include "quest/QuestJournal.h"
namespace ZL {
class Game {
public:
Game();
~Game();
void setup();
void setupPart2();
void update();
void render();
bool shouldExit() const { return Environment::exitGameLoop; }
Renderer renderer;
TaskManager taskManager;
MainThreadHandler mainThreadHandler;
std::shared_ptr<Texture> loadingTexture;
VertexRenderStruct loadingMesh;
bool loadingCompleted = false;
std::shared_ptr<Location> location1;
std::shared_ptr<Location> location2;
std::shared_ptr<Location> currentLocation;
Inventory inventory;
InteractiveObject* pickedUpObject = nullptr;
bool inventoryOpen = false;
ZL::Quest::QuestJournal questJournal;
bool questJournalOpen = false;
int selectedQuestIndex = -1;
std::vector<std::string> visibleQuestIds;
MenuManager menuManager;
void activateSlowMoEffect();
private:
// Unified pointer handling: mouse-left and a single touch share one path.
// A press becomes a tap (interact / walk-to) on release if it never crossed
// CAMERA_DRAG_PIXEL_THRESHOLD; otherwise it becomes a camera-rotation drag.
// Two simultaneous touches enter pinch-zoom instead.
static constexpr int CAMERA_DRAG_PIXEL_THRESHOLD = 12;
struct PointerState {
int eventX = 0, eventY = 0; // current raw window-pixel coords
int mx = 0, my = 0; // current projection-space coords
int downEventX = 0, downEventY = 0;// where the press started (raw px)
int downMx = 0, downMy = 0; // where the press started (proj)
bool capturedByUi = false;
};
std::unordered_map<int64_t, PointerState> activePointers;
bool hasPrimaryPointer = false;
int64_t primaryPointerId = 0;
bool cameraDragging = false;
bool pinchActive = false;
int64_t pinchFingerA = 0;
int64_t pinchFingerB = 0;
float pinchStartDistance = 0.0f;
float pinchStartZoom = 0.0f;
std::unique_ptr<AudioPlayerAsync> audioPlayer;
int64_t getSyncTimeMs();
void processTickCount();
void drawScene();
void drawUI();
void drawLoading();
void onPointerDown(int64_t fingerId, int eventX, int eventY, int mx, int my);
void onPointerUp(int64_t fingerId, int eventX, int eventY, int mx, int my);
void onPointerMotion(int64_t fingerId, int eventX, int eventY, int mx, int my);
void enterCameraDragMode(int eventX, int eventY);
void exitCameraDragMode();
void startPinch();
void updatePinchZoom();
void endPinch();
int countNonUiPointers() const;
void handleDown(int64_t fingerId, int mx, int my);
void handleUp(int64_t fingerId, int mx, int my);
void handleMotion(int64_t fingerId, int mx, int my);
void setupQuestJournalUi();
void toggleQuestJournal();
void refreshQuestJournalUi();
void selectQuestByIndex(int index);
#ifdef EMSCRIPTEN
static Game* s_instance;
static void onResourcesZipLoaded(const char* filename);
static void onResourcesZipError(const char* filename);
#endif
int64_t newTickCount;
int64_t lastTickCount;
static const size_t CONST_TIMER_INTERVAL = 10;
static const size_t CONST_MAX_TIME_INTERVAL = 1000;
};
} // namespace ZL