the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 351 lines 10 kB view raw
1#pragma once 2class Timer; 3class MultiPlayerLevel; 4class LevelRenderer; 5class MultiplayerLocalPlayer; 6class Player; 7class Mob; 8class ParticleEngine; 9class User; 10class Canvas; 11class Textures; 12class Font; 13class Screen; 14class ProgressRenderer; 15class GameRenderer; 16class BackgroundDownloader; 17class HumanoidModel; 18class HitResult; 19class Options; 20class SoundEngine; 21class MinecraftApplet; 22class MouseHandler; 23class TexturePackRepository; 24class File; 25class LevelStorageSource; 26class StatsCounter; 27class Component; 28class Entity; 29class AchievementPopup; 30class WaterTexture; 31class LavaTexture; 32class Gui; 33class ClientConnection; 34class ConsoleSaveFile; 35class ItemInHandRenderer; 36class LevelSettings; 37class ColourTable; 38class MultiPlayerGameMode; 39class PsPlusUpsellWrapper; 40 41#include "..\Minecraft.World\File.h" 42#include "..\Minecraft.World\DisconnectPacket.h" 43#include "..\Minecraft.World\C4JThread.h" 44#include "ResourceLocation.h" 45 46using namespace std; 47 48class Minecraft 49{ 50private: 51 enum OS{ 52 linux, solaris, windows, macos, unknown, xbox 53 }; 54 55 static ResourceLocation DEFAULT_FONT_LOCATION; 56 static ResourceLocation ALT_FONT_LOCATION; 57 58public: 59 static const wstring VERSION_STRING; 60 Minecraft(Component *mouseComponent, Canvas *parent, MinecraftApplet *minecraftApplet, int width, int height, bool fullscreen); 61 void init(); 62 63 // 4J - removed 64 // void crash(CrashReport crash); 65 // public abstract void onCrash(CrashReport crash); 66 67private: 68 static Minecraft *m_instance; 69 70public: 71 MultiPlayerGameMode *gameMode; 72 73private: 74 bool fullscreen; 75 bool hasCrashed; 76 77 C4JThread::EventQueue* levelTickEventQueue; 78 79 static void levelTickUpdateFunc(void* pParam); 80 static void levelTickThreadInitFunc(); 81 82public: 83 int width, height; 84 int width_phys, height_phys; // 4J - added 85 // private OpenGLCapabilities openGLCapabilities; 86 87private: 88 Timer *timer; 89 bool reloadTextures; 90public: 91 Level *oldLevel; // 4J Stu added to keep a handle on an old level so we can delete it 92 //HANDLE m_hPlayerRespawned; // 4J Added so we can wait in menus until it is done (for async in multiplayer) 93public: 94 95 MultiPlayerLevel *level; 96 LevelRenderer *levelRenderer; 97 shared_ptr<MultiplayerLocalPlayer> player; 98 99 MultiPlayerLevelArray levels; 100 101 shared_ptr<MultiplayerLocalPlayer> localplayers[XUSER_MAX_COUNT]; 102 MultiPlayerGameMode *localgameModes[XUSER_MAX_COUNT]; 103 int localPlayerIdx; 104 ItemInHandRenderer *localitemInHandRenderers[XUSER_MAX_COUNT]; 105 // 4J-PB - so we can have debugoptions in the server 106 unsigned int uiDebugOptionsA[XUSER_MAX_COUNT]; 107 108 // 4J Stu - Added these so that we can show a Xui scene while connecting 109 bool m_connectionFailed[XUSER_MAX_COUNT]; 110 DisconnectPacket::eDisconnectReason m_connectionFailedReason[XUSER_MAX_COUNT]; 111 ClientConnection *m_pendingLocalConnections[XUSER_MAX_COUNT]; 112 113 bool addLocalPlayer(int idx); // Re-arrange the screen and start the connection 114 void addPendingLocalConnection(int idx, ClientConnection *connection); 115 void connectionDisconnected(int idx, DisconnectPacket::eDisconnectReason reason) { m_connectionFailed[idx] = true; m_connectionFailedReason[idx] = reason; } 116 117 shared_ptr<MultiplayerLocalPlayer> createExtraLocalPlayer(int idx, const wstring& name, int pad, int iDimension, ClientConnection *clientConnection = NULL,MultiPlayerLevel *levelpassedin=NULL); 118 void createPrimaryLocalPlayer(int iPad); 119 bool setLocalPlayerIdx(int idx); 120 int getLocalPlayerIdx(); 121 void removeLocalPlayerIdx(int idx); 122 void storeExtraLocalPlayer(int idx); 123 void updatePlayerViewportAssignments(); 124 int unoccupiedQuadrant; // 4J - added 125 126 shared_ptr<LivingEntity> cameraTargetPlayer; 127 shared_ptr<LivingEntity> crosshairPickMob; 128 ParticleEngine *particleEngine; 129 User *user; 130 wstring serverDomain; 131 Canvas *parent; 132 bool appletMode; 133 134 // 4J - per player ? 135 volatile bool pause; 136 137 Textures *textures; 138 Font *font, *altFont; 139 Screen *screen; 140 ProgressRenderer *progressRenderer; 141 GameRenderer *gameRenderer; 142private: 143 BackgroundDownloader *bgLoader; 144 145 int ticks; 146 // 4J-PB - moved to per player 147 148 //int missTime; 149 150 int orgWidth, orgHeight; 151public: 152 AchievementPopup *achievementPopup; 153public: 154 Gui *gui; 155 // 4J - move to the per player structure? 156 bool noRender; 157 158 HumanoidModel *humanoidModel; 159 HitResult *hitResult; 160 Options *options; 161protected: 162 MinecraftApplet *minecraftApplet; 163public: 164 SoundEngine *soundEngine; 165 MouseHandler *mouseHandler; 166public: 167 TexturePackRepository *skins; 168 File workingDirectory; 169private: 170 LevelStorageSource *levelSource; 171public: 172 static const int frameTimes_length = 512; 173 static __int64 frameTimes[frameTimes_length]; 174 static const int tickTimes_length = 512; 175 static __int64 tickTimes[tickTimes_length]; 176 static int frameTimePos; 177 static __int64 warezTime; 178private: 179 int rightClickDelay; 180public: 181 // 4J- this should really be in localplayer 182 StatsCounter* stats[4]; 183 184private: 185 wstring connectToIp; 186 int connectToPort; 187 188public: 189 void clearConnectionFailed(); 190 void connectTo(const wstring& server, int port); 191 192private: 193 void renderLoadingScreen(); 194 195public: 196 void blit(int x, int y, int sx, int sy, int w, int h); 197 198private: 199 static File workDir; 200 201public: 202 LevelStorageSource *getLevelSource(); 203 void setScreen(Screen *screen); 204private: 205 void checkGlError(const wstring& string); 206 207#ifdef __ORBIS__ 208 PsPlusUpsellWrapper *m_pPsPlusUpsell; 209#endif 210 211public: 212 void destroy(); 213 volatile bool running; 214 wstring fpsString; 215 void run(); 216 // 4J-PB - split the run into 3 parts so we can run it from our xbox game loop 217 static Minecraft *GetInstance(); 218 void run_middle(); 219 void run_end(); 220#ifdef _WINDOWS64 221 void applyFrameMouseLook(); // Per-frame mouse look to reduce input latency 222#endif 223 224 void emergencySave(); 225 226 // 4J - removed 227 //bool wasDown ; 228private: 229 // void checkScreenshot(); // 4J - removed 230 // String grabHugeScreenshot(File workDir2, int width, int height, int ssWidth, int ssHeight); // 4J - removed 231 232 // 4J - per player thing? 233 __int64 lastTimer; 234 235 void renderFpsMeter(__int64 tickTime); 236public: 237 void stop(); 238 // 4J removed 239 // bool mouseGrabbed; 240 // void grabMouse(); 241 // void releaseMouse(); 242 // 4J-PB - moved these into localplayer 243 //void handleMouseDown(int button, bool down); 244 //void handleMouseClick(int button); 245 246 void pauseGame(); 247 // void toggleFullScreen(); // 4J - removed 248private: 249 void resize(int width, int height); 250 251public: 252 // 4J - Moved to per player 253 //bool isRaining ; 254 255 // 4J - Moved to per player 256 //__int64 lastTickTime; 257 258private: 259 // 4J- per player? 260 int recheckPlayerIn; 261 void verify(); 262 263public: 264 // 4J - added bFirst parameter, which is true for the first active viewport in splitscreen 265 // 4J - added bUpdateTextures, which is true if the actual renderer textures are to be updated - this will be true for the last time this tick runs with bFirst true 266 void tick(bool bFirst, bool bUpdateTextures); 267private: 268 void reloadSound(); 269public: 270 bool isClientSide(); 271 void selectLevel(ConsoleSaveFile *saveFile, const wstring& levelId, const wstring& levelName, LevelSettings *levelSettings); 272 //void toggleDimension(int targetDimension); 273 bool saveSlot(int slot, const wstring& name); 274 bool loadSlot(const wstring& userName, int slot); 275 void releaseLevel(int message); 276 // 4J Stu - Added the doForceStatsSave param 277 //void setLevel(Level *level, bool doForceStatsSave = true); 278 //void setLevel(Level *level, const wstring& message, bool doForceStatsSave = true); 279 void setLevel(MultiPlayerLevel *level, int message = -1, shared_ptr<Player> forceInsertPlayer = nullptr, bool doForceStatsSave = true,bool bPrimaryPlayerSignedOut=false); 280 // 4J-PB - added to force in the 'other' level when the main player creates the level at game load time 281 void forceaddLevel(MultiPlayerLevel *level); 282 void prepareLevel(int title); // 4J - changed to public 283 // OpenGLCapabilities getOpenGLCapabilities(); // 4J - removed 284 285 wstring gatherStats1(); 286 wstring gatherStats2(); 287 wstring gatherStats3(); 288 wstring gatherStats4(); 289 290 void respawnPlayer(int iPad,int dimension,int newEntityId); 291 static void start(const wstring& name, const wstring& sid); 292 static void startAndConnectTo(const wstring& name, const wstring& sid, const wstring& url); 293 ClientConnection *getConnection(int iPad); // 4J Stu added iPad param 294 static void main(); 295 static bool renderNames(); 296 static bool useFancyGraphics(); 297 static bool useAmbientOcclusion(); 298 static bool renderDebug(); 299 bool handleClientSideCommand(const wstring& chatMessage); 300 301 static int maxSupportedTextureSize(); 302 void delayTextureReload(); 303 static __int64 currentTimeMillis(); 304 305#ifdef _DURANGO 306 static void inGameSignInCheckAllPrivilegesCallback(LPVOID lpParam, bool hasPrivileges, int iPad); 307 static int InGame_SignInReturned(void *pParam,bool bContinue, int iPad, int iController); 308#else 309 static int InGame_SignInReturned(void *pParam,bool bContinue, int iPad); 310#endif 311 // 4J-PB 312 Screen * getScreen(); 313 314 // 4J Stu 315 void forceStatsSave(int idx); 316 317 CRITICAL_SECTION m_setLevelCS; 318private: 319 // A bit field that store whether a particular quadrant is in the full tutorial or not 320 BYTE m_inFullTutorialBits; 321public: 322 bool isTutorial(); 323 void playerStartedTutorial(int iPad); 324 void playerLeftTutorial(int iPad); 325 326 // 4J Added 327 MultiPlayerLevel *getLevel(int dimension); 328 329 void tickAllConnections(); 330 331 Level *animateTickLevel; // 4J added 332 333 // 4J - When a client requests a texture, it should add it to here while we are waiting for it 334 vector<wstring> m_pendingTextureRequests; 335 vector<wstring> m_pendingGeometryRequests; // additional skin box geometry 336 337 // 4J Added 338 bool addPendingClientTextureRequest(const wstring &textureName); 339 void handleClientTextureReceived(const wstring &textureName); 340 void clearPendingClientTextureRequests() { m_pendingTextureRequests.clear(); } 341 bool addPendingClientGeometryRequest(const wstring &textureName); 342 void handleClientGeometryReceived(const wstring &textureName); 343 void clearPendingClientGeometryRequests() { m_pendingGeometryRequests.clear(); } 344 345 unsigned int getCurrentTexturePackId(); 346 ColourTable *getColourTable(); 347 348#if defined __ORBIS__ 349 static int MustSignInReturnedPSN(void *pParam, int iPad, C4JStorage::EMessageResult result); 350#endif 351};