mirror of
https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1.git
synced 2026-03-30 20:13:31 +00:00
Compare commits
30 Commits
!no-build-
...
3cfa2d9ee7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3cfa2d9ee7 | ||
|
|
f016f00eab | ||
|
|
470c28d83a | ||
|
|
4363157cd9 | ||
|
|
ba3ed3b4dd | ||
|
|
5783fb93f3 | ||
|
|
73fb2a2b3d | ||
|
|
bcf48eb5e3 | ||
|
|
f5fecbc928 | ||
|
|
77d02fcca2 | ||
|
|
6d696af235 | ||
|
|
370363f792 | ||
|
|
61a2349b8b | ||
|
|
eed3a6df61 | ||
|
|
97b0fb4d46 | ||
|
|
8be842a8ac | ||
|
|
6957f144e1 | ||
|
|
f9d9a0f0f9 | ||
|
|
28febb4e63 | ||
|
|
aeef442f76 | ||
|
|
8098ab8906 | ||
|
|
f0cb6d0b7c | ||
|
|
d1672c0ee2 | ||
|
|
c234abe3aa | ||
|
|
e4ff7728af | ||
|
|
41c5bdf243 | ||
|
|
96e8826f01 | ||
|
|
db8993683f | ||
|
|
2c1b5e256e | ||
|
|
4beb5cb0f9 |
@@ -39,8 +39,6 @@ if (${PLATFORM} STREQUAL "Desktop")
|
|||||||
set(EXTRA_LIBS pthread m)
|
set(EXTRA_LIBS pthread m)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include_directories("glad/include")
|
|
||||||
|
|
||||||
elseif (${PLATFORM} STREQUAL "Web")
|
elseif (${PLATFORM} STREQUAL "Web")
|
||||||
set(PLATFORM_CPP "PLATFORM_WEB")
|
set(PLATFORM_CPP "PLATFORM_WEB")
|
||||||
set(EXTRA_LIBS "idbfs.js")
|
set(EXTRA_LIBS "idbfs.js")
|
||||||
@@ -113,41 +111,36 @@ CPMAddPackage(
|
|||||||
"ALSOFT_STATIC_LIBGCC ON"
|
"ALSOFT_STATIC_LIBGCC ON"
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: Clear this paths with *
|
|
||||||
file(GLOB SERVER_SOURCES
|
file(GLOB SERVER_SOURCES
|
||||||
"project/lib_projects/raknet/jni/RaknetSources/*.cpp"
|
"project/lib_projects/raknet/jni/RaknetSources/*.cpp"
|
||||||
|
"src/NinecraftApp.cpp"
|
||||||
"src/Performance.cpp"
|
"src/Performance.cpp"
|
||||||
"src/SharedConstants.cpp"
|
"src/SharedConstants.cpp"
|
||||||
"src/Minecraft.cpp"
|
|
||||||
"src/MinecraftServer.cpp"
|
|
||||||
"src/App.cpp"
|
|
||||||
"src/IPlatform.cpp"
|
|
||||||
|
|
||||||
|
"src/client/IConfigListener.cpp"
|
||||||
|
"src/client/Minecraft.cpp"
|
||||||
|
"src/client/OptionStrings.cpp"
|
||||||
|
"src/client/Option.cpp"
|
||||||
|
"src/client/Options.cpp"
|
||||||
|
"src/client/OptionsFile.cpp"
|
||||||
|
"src/client/ServerProfiler.cpp"
|
||||||
|
|
||||||
# "src/client/IConfigListener.cpp"
|
"src/client/gamemode/CreativeMode.cpp"
|
||||||
# "src/client/Minecraft.cpp"
|
"src/client/gamemode/GameMode.cpp"
|
||||||
# "src/client/OptionStrings.cpp"
|
"src/client/gamemode/SurvivalMode.cpp"
|
||||||
# "src/client/Option.cpp"
|
|
||||||
# "src/client/Options.cpp"
|
|
||||||
# "src/client/OptionsFile.cpp"
|
|
||||||
# "src/client/ServerProfiler.cpp"
|
|
||||||
|
|
||||||
# "src/client/gamemode/CreativeMode.cpp"
|
"src/client/player/LocalPlayer.cpp"
|
||||||
# "src/client/gamemode/GameMode.cpp"
|
"src/client/player/RemotePlayer.cpp"
|
||||||
# "src/client/gamemode/SurvivalMode.cpp"
|
"src/client/player/input/KeyboardInput.cpp"
|
||||||
|
|
||||||
# "src/client/player/LocalPlayer.cpp"
|
|
||||||
# "src/client/player/RemotePlayer.cpp"
|
|
||||||
# "src/client/player/input/KeyboardInput.cpp"
|
|
||||||
|
|
||||||
"src/gamemode/*.cpp"
|
|
||||||
|
|
||||||
"src/locale/I18n.cpp"
|
"src/locale/I18n.cpp"
|
||||||
|
|
||||||
|
"src/main.cpp"
|
||||||
"src/main_dedicated.cpp"
|
"src/main_dedicated.cpp"
|
||||||
|
|
||||||
"src/nbt/Tag.cpp"
|
"src/nbt/Tag.cpp"
|
||||||
|
|
||||||
|
"src/network/ClientSideNetworkHandler.cpp"
|
||||||
"src/network/NetEventCallback.cpp"
|
"src/network/NetEventCallback.cpp"
|
||||||
"src/network/Packet.cpp"
|
"src/network/Packet.cpp"
|
||||||
"src/network/RakNetInstance.cpp"
|
"src/network/RakNetInstance.cpp"
|
||||||
@@ -158,7 +151,11 @@ file(GLOB SERVER_SOURCES
|
|||||||
"src/platform/HttpClient.cpp"
|
"src/platform/HttpClient.cpp"
|
||||||
"src/platform/PngLoader.cpp"
|
"src/platform/PngLoader.cpp"
|
||||||
"src/platform/time.cpp"
|
"src/platform/time.cpp"
|
||||||
"src/platform/server/PlatformServer.cpp"
|
|
||||||
|
"src/platform/input/Controller.cpp"
|
||||||
|
"src/platform/input/Keyboard.cpp"
|
||||||
|
"src/platform/input/Mouse.cpp"
|
||||||
|
"src/platform/input/Multitouch.cpp"
|
||||||
|
|
||||||
"src/server/ArgumentsSettings.cpp"
|
"src/server/ArgumentsSettings.cpp"
|
||||||
"src/server/ServerLevel.cpp"
|
"src/server/ServerLevel.cpp"
|
||||||
@@ -371,7 +368,7 @@ if(${PLATFORM} MATCHES "Web")
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Client
|
# Client
|
||||||
target_compile_definitions(${PROJECT_NAME} PUBLIC "OPENGL_ES" "NO_EGL" "${PLATFORM_CPP}")
|
target_compile_definitions(${PROJECT_NAME} PUBLIC "OPENGL_ES" "NO_EGL" ${PLATFORM})
|
||||||
target_link_libraries(${PROJECT_NAME} zlib ${PNG_LIB} OpenAL::OpenAL glfw ${EXTRA_LIBS})
|
target_link_libraries(${PROJECT_NAME} zlib ${PNG_LIB} OpenAL::OpenAL glfw ${EXTRA_LIBS})
|
||||||
|
|
||||||
if (OpenSSL_FOUND)
|
if (OpenSSL_FOUND)
|
||||||
|
|||||||
26
src/App.cpp
26
src/App.cpp
@@ -1,26 +0,0 @@
|
|||||||
#include "App.hpp"
|
|
||||||
#include "IPlatform.hpp"
|
|
||||||
|
|
||||||
#include "platform/server/PlatformServer.hpp"
|
|
||||||
#include "platform/glfw/PlatformGlfw.hpp"
|
|
||||||
|
|
||||||
std::unique_ptr<IPlatform> App::CreatePlatform() {
|
|
||||||
#if defined(STANDALONE_SERVER)
|
|
||||||
return std::make_unique<PlatformServer>();
|
|
||||||
#elif defined(PLATFORM_DESKTOP)
|
|
||||||
return std::make_unique<PlatformGlfw>();
|
|
||||||
#else
|
|
||||||
static_assert(false, "Unsupported platform!");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void App::run() {
|
|
||||||
init();
|
|
||||||
|
|
||||||
m_platform->runMainLoop(*this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void App::swapBuffers() {
|
|
||||||
m_platform->swapBuffers();
|
|
||||||
}
|
|
||||||
|
|
||||||
87
src/App.h
Executable file
87
src/App.h
Executable file
@@ -0,0 +1,87 @@
|
|||||||
|
#ifndef APP_H__
|
||||||
|
#define APP_H__
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#define NO_EGL
|
||||||
|
#endif
|
||||||
|
#ifdef STANDALONE_SERVER
|
||||||
|
#define NO_EGL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "AppPlatform.h"
|
||||||
|
#ifndef NO_EGL
|
||||||
|
#include <EGL/egl.h>
|
||||||
|
#endif
|
||||||
|
#include "platform/log.h"
|
||||||
|
|
||||||
|
typedef struct AppContext {
|
||||||
|
#ifndef NO_EGL
|
||||||
|
EGLDisplay display;
|
||||||
|
EGLContext context;
|
||||||
|
EGLSurface surface;
|
||||||
|
#endif
|
||||||
|
AppPlatform* platform;
|
||||||
|
bool doRender;
|
||||||
|
} AppContext;
|
||||||
|
|
||||||
|
|
||||||
|
class App
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
App()
|
||||||
|
: _finished(false),
|
||||||
|
_inited(false)
|
||||||
|
{
|
||||||
|
_context.platform = 0;
|
||||||
|
}
|
||||||
|
virtual ~App() {}
|
||||||
|
|
||||||
|
void init(AppContext& c) {
|
||||||
|
_context = c;
|
||||||
|
init();
|
||||||
|
_inited = true;
|
||||||
|
}
|
||||||
|
bool isInited() { return _inited; }
|
||||||
|
|
||||||
|
virtual AppPlatform* platform() { return _context.platform; }
|
||||||
|
|
||||||
|
void onGraphicsReset(AppContext& c) {
|
||||||
|
_context = c;
|
||||||
|
onGraphicsReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void audioEngineOn () {}
|
||||||
|
virtual void audioEngineOff() {}
|
||||||
|
|
||||||
|
virtual void destroy() {}
|
||||||
|
|
||||||
|
virtual void loadState(void* state, int stateSize) {}
|
||||||
|
virtual bool saveState(void** state, int* stateSize) { return false; }
|
||||||
|
|
||||||
|
void swapBuffers() {
|
||||||
|
#ifndef NO_EGL
|
||||||
|
if (_context.doRender)
|
||||||
|
eglSwapBuffers(_context.display, _context.surface);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void draw() {}
|
||||||
|
virtual void update() {};// = 0;
|
||||||
|
virtual void setSize(int width, int height) {}
|
||||||
|
|
||||||
|
virtual void quit() { _finished = true; }
|
||||||
|
virtual bool wantToQuit() { return _finished; }
|
||||||
|
virtual bool handleBack(bool isDown) { return false; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void init() {}
|
||||||
|
//virtual void onGraphicsLost() = 0;
|
||||||
|
virtual void onGraphicsReset() = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool _inited;
|
||||||
|
bool _finished;
|
||||||
|
AppContext _context;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif//APP_H__
|
||||||
71
src/App.hpp
71
src/App.hpp
@@ -1,71 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#define NO_EGL
|
|
||||||
#endif
|
|
||||||
#ifdef STANDALONE_SERVER
|
|
||||||
#define NO_EGL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <IPlatform.hpp>
|
|
||||||
#ifndef NO_EGL
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// typedef struct AppContext {
|
|
||||||
// #ifndef NO_EGL
|
|
||||||
// EGLDisplay display;
|
|
||||||
// EGLContext context;
|
|
||||||
// EGLSurface surface;
|
|
||||||
// #endif
|
|
||||||
// AppPlatform* platform;
|
|
||||||
// bool doRender;
|
|
||||||
// } AppContext;
|
|
||||||
|
|
||||||
class App {
|
|
||||||
protected:
|
|
||||||
std::unique_ptr<IPlatform> m_platform;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static std::unique_ptr<IPlatform> CreatePlatform();
|
|
||||||
|
|
||||||
App(std::unique_ptr<IPlatform> platform) : m_platform(std::move(platform)), m_finished(false), m_inited(false) {}
|
|
||||||
App() = delete;
|
|
||||||
virtual ~App() {}
|
|
||||||
|
|
||||||
void run();
|
|
||||||
|
|
||||||
bool isInited() { return m_inited; }
|
|
||||||
|
|
||||||
virtual void audioEngineOn () {}
|
|
||||||
virtual void audioEngineOff() {}
|
|
||||||
|
|
||||||
virtual void destroy() {}
|
|
||||||
|
|
||||||
virtual void loadState(void* state, int stateSize) {}
|
|
||||||
virtual bool saveState(void** state, int* stateSize) { return false; }
|
|
||||||
|
|
||||||
void swapBuffers();
|
|
||||||
// {
|
|
||||||
// #ifndef NO_EGL
|
|
||||||
// if (_context.doRender)
|
|
||||||
// eglSwapBuffers(_context.display, _context.surface);
|
|
||||||
// #endif
|
|
||||||
// m_platform->swapBuffers();
|
|
||||||
// }
|
|
||||||
|
|
||||||
virtual void update() = 0;
|
|
||||||
|
|
||||||
virtual void quit() { m_finished = true; }
|
|
||||||
virtual bool wantToQuit() { return m_finished; }
|
|
||||||
virtual bool handleBack(bool isDown) { return false; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void init() { m_inited = true;}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_inited = false;
|
|
||||||
bool m_finished = false;
|
|
||||||
};
|
|
||||||
10
src/AppConstants.h
Executable file
10
src/AppConstants.h
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef _MINECRAFT_APPCONSTANTS_H_
|
||||||
|
#define _MINECRAFT_APPCONSTANTS_H_
|
||||||
|
|
||||||
|
|
||||||
|
#define APP_VERSION_STRING "Demo"
|
||||||
|
#define APP_NAME "Minecraft - Pocket Edition " APP_VERSION_STRING
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
143
src/AppPlatform.h
Executable file
143
src/AppPlatform.h
Executable file
@@ -0,0 +1,143 @@
|
|||||||
|
#ifndef APPPLATFORM_H__
|
||||||
|
#define APPPLATFORM_H__
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <cstring>
|
||||||
|
#include "client/renderer/TextureData.h"
|
||||||
|
|
||||||
|
typedef std::vector<std::string> StringVector;
|
||||||
|
|
||||||
|
/*
|
||||||
|
typedef struct UserInput
|
||||||
|
{
|
||||||
|
static const int STATUS_INVALID = -1;
|
||||||
|
static const int STATUS_NOTINITED = -2;
|
||||||
|
static const int STATUS_OK = 1;
|
||||||
|
static const int STATUS_CANCEL = 0;
|
||||||
|
|
||||||
|
UserInput(int id)
|
||||||
|
: _id(id),
|
||||||
|
status(STATUS_NOTINITED)
|
||||||
|
{}
|
||||||
|
UserInput(int id, int status)
|
||||||
|
: _id(id),
|
||||||
|
status(status)
|
||||||
|
{}
|
||||||
|
int getId() { return _id; }
|
||||||
|
|
||||||
|
int status;
|
||||||
|
private:
|
||||||
|
int _id;
|
||||||
|
} UserInput;
|
||||||
|
|
||||||
|
|
||||||
|
class UserInputStatus {
|
||||||
|
int _status;
|
||||||
|
public:
|
||||||
|
UserInputStatus(int status)
|
||||||
|
: _status(status)
|
||||||
|
{}
|
||||||
|
bool isAnswered() { return _status >= 0; }
|
||||||
|
bool isOk() { return _status == UserInput::STATUS_OK; }
|
||||||
|
bool isCancel() { return _status == UserInput::STATUS_CANCEL; }
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
|
class BinaryBlob {
|
||||||
|
public:
|
||||||
|
BinaryBlob()
|
||||||
|
: data(NULL),
|
||||||
|
size(-1) {}
|
||||||
|
|
||||||
|
BinaryBlob(unsigned char* data, unsigned int size)
|
||||||
|
: data(data),
|
||||||
|
size(size) {}
|
||||||
|
|
||||||
|
unsigned char* data;
|
||||||
|
int size;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PlatformStringVars {
|
||||||
|
public:
|
||||||
|
static const int DEVICE_BUILD_MODEL = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AppPlatform
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AppPlatform() : keyboardVisible(false) {}
|
||||||
|
virtual ~AppPlatform() {}
|
||||||
|
|
||||||
|
virtual void saveScreenshot(const std::string& filename, int glWidth, int glHeight) {}
|
||||||
|
virtual TextureData loadTexture(const std::string& filename_, bool textureFolder) { return TextureData(); }
|
||||||
|
virtual TextureData loadTextureFromMemory(const unsigned char* data, size_t size) { return TextureData(); }
|
||||||
|
|
||||||
|
virtual void playSound(const std::string& fn, float volume, float pitch) {}
|
||||||
|
|
||||||
|
virtual void hideCursor(bool hide) {}
|
||||||
|
|
||||||
|
virtual void showDialog(int dialogId) {}
|
||||||
|
virtual void createUserInput() {}
|
||||||
|
|
||||||
|
bool is_big_endian(void) {
|
||||||
|
union {
|
||||||
|
unsigned int i;
|
||||||
|
char c[4];
|
||||||
|
} bint = {0x01020304};
|
||||||
|
return bint.c[0] == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void createUserInput(int dialogId)
|
||||||
|
{
|
||||||
|
showDialog(dialogId);
|
||||||
|
createUserInput();
|
||||||
|
}
|
||||||
|
virtual int getUserInputStatus() { return 0; }
|
||||||
|
virtual StringVector getUserInput() { return StringVector(); }
|
||||||
|
|
||||||
|
virtual std::string getDateString(int s) { return ""; }
|
||||||
|
//virtual void createUserInputScreen(const char* types) {}
|
||||||
|
|
||||||
|
virtual void uploadPlatformDependentData(int id, void* data) {}
|
||||||
|
virtual BinaryBlob readAssetFile(const std::string& filename) { return BinaryBlob(); }
|
||||||
|
virtual void _tick() {}
|
||||||
|
|
||||||
|
virtual int getScreenWidth() { return 854; }
|
||||||
|
virtual int getScreenHeight() { return 480; }
|
||||||
|
virtual float getPixelsPerMillimeter() { return 10; }
|
||||||
|
|
||||||
|
virtual bool isNetworkEnabled(bool onlyWifiAllowed) { return true; }
|
||||||
|
|
||||||
|
virtual bool isPowerVR() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual int getKeyFromKeyCode(int keyCode, int metaState, int deviceId) {return 0;}
|
||||||
|
#ifdef __APPLE__
|
||||||
|
virtual bool isSuperFast() = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
virtual void openURL(const std::string& url) {}
|
||||||
|
|
||||||
|
virtual void finish() {}
|
||||||
|
|
||||||
|
virtual bool supportsTouchscreen() { return false; }
|
||||||
|
|
||||||
|
virtual void vibrate(int milliSeconds) {}
|
||||||
|
|
||||||
|
virtual std::string getPlatformStringVar(int stringId) {
|
||||||
|
return "<getPlatformStringVar NotImplemented>";
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void showKeyboard() {
|
||||||
|
keyboardVisible = true;
|
||||||
|
}
|
||||||
|
virtual void hideKeyboard() {
|
||||||
|
keyboardVisible = false;
|
||||||
|
}
|
||||||
|
virtual bool isKeyboardVisible() {return keyboardVisible;}
|
||||||
|
protected:
|
||||||
|
bool keyboardVisible;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*APPPLATFORM_H__*/
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
#pragma once
|
#ifndef APPPLATFORM_ANDROID_H__
|
||||||
|
#define APPPLATFORM_ANDROID_H__
|
||||||
|
|
||||||
#include <IPlatform.hpp>
|
#include "AppPlatform.h"
|
||||||
#include "client/renderer/gles.hpp"
|
#include "client/renderer/gles.h"
|
||||||
#include "platform/log.hpp"
|
#include "platform/log.h"
|
||||||
#include "platform/time.hpp"
|
#include "platform/time.h"
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
@@ -321,7 +322,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned int rgbToBgr(unsigned int p) {
|
__inline unsigned int rgbToBgr(unsigned int p) {
|
||||||
return (p & 0xff00ff00) | ((p >> 16) & 0xff) | ((p << 16) & 0xff0000);
|
return (p & 0xff00ff00) | ((p >> 16) & 0xff) | ((p << 16) & 0xff0000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,7 +536,7 @@ public:
|
|||||||
return env->CallBooleanMethod(instance, _methodIsNetworkEnabled, onlyWifiAllowed);
|
return env->CallBooleanMethod(instance, _methodIsNetworkEnabled, onlyWifiAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool isSquare(int n) {
|
static __inline bool isSquare(int n) {
|
||||||
int L = n & 0xf;
|
int L = n & 0xf;
|
||||||
if (((1 << L) & 0x213) == 0) return false;
|
if (((1 << L) & 0x213) == 0) return false;
|
||||||
|
|
||||||
@@ -650,3 +651,4 @@ public:
|
|||||||
ANativeActivity* _nativeActivity;
|
ANativeActivity* _nativeActivity;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*APPPLATFORM_ANDROID_H__*/
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "AppPlatform_android.hpp"
|
#include "AppPlatform_android.h"
|
||||||
#include <android/asset_manager.h>
|
#include <android/asset_manager.h>
|
||||||
#include <android/native_activity.h>
|
#include <android/native_activity.h>
|
||||||
|
|
||||||
12
src/AppPlatform_glfw.cpp
Normal file
12
src/AppPlatform_glfw.cpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include "AppPlatform_glfw.h"
|
||||||
|
|
||||||
|
float AppPlatform_glfw::getPixelsPerMillimeter() {
|
||||||
|
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
||||||
|
|
||||||
|
int width_mm, height_mm;
|
||||||
|
glfwGetMonitorPhysicalSize(monitor, &width_mm, &height_mm);
|
||||||
|
|
||||||
|
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||||
|
|
||||||
|
return (float)mode->width / (float)width_mm;
|
||||||
|
}
|
||||||
155
src/AppPlatform_glfw.h
Executable file
155
src/AppPlatform_glfw.h
Executable file
@@ -0,0 +1,155 @@
|
|||||||
|
#ifndef APPPLATFORM_GLFW_H__
|
||||||
|
#define APPPLATFORM_GLFW_H__
|
||||||
|
|
||||||
|
#include "AppPlatform.h"
|
||||||
|
#include "platform/log.h"
|
||||||
|
#include "platform/HttpClient.h"
|
||||||
|
#include "platform/PngLoader.h"
|
||||||
|
#include "client/renderer/gles.h"
|
||||||
|
#include "world/level/storage/FolderMethods.h"
|
||||||
|
#include <png.h>
|
||||||
|
#include <cmath>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <ctime>
|
||||||
|
#include "util/StringUtils.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#include <shellapi.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
#include <emscripten/html5.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void png_funcReadFile(png_structp pngPtr, png_bytep data, png_size_t length) {
|
||||||
|
((std::istream*)png_get_io_ptr(pngPtr))->read((char*)data, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
class AppPlatform_glfw: public AppPlatform
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AppPlatform_glfw()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
BinaryBlob readAssetFile(const std::string& filename) override {
|
||||||
|
FILE* fp = fopen(("data/" + filename).c_str(), "r");
|
||||||
|
if (!fp)
|
||||||
|
return BinaryBlob();
|
||||||
|
|
||||||
|
int size = getRemainingFileSize(fp);
|
||||||
|
|
||||||
|
BinaryBlob blob;
|
||||||
|
blob.size = size;
|
||||||
|
blob.data = new unsigned char[size];
|
||||||
|
|
||||||
|
fread(blob.data, 1, size, fp);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
return blob;
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveScreenshot(const std::string& filename, int glWidth, int glHeight) override {
|
||||||
|
//@todo
|
||||||
|
}
|
||||||
|
|
||||||
|
__inline unsigned int rgbToBgr(unsigned int p) {
|
||||||
|
return (p & 0xff00ff00) | ((p >> 16) & 0xff) | ((p << 16) & 0xff0000);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureData loadTexture(const std::string& filename_, bool textureFolder) override
|
||||||
|
{
|
||||||
|
// Support fetching PNG textures via HTTP/HTTPS (for skins, etc)
|
||||||
|
if (Util::startsWith(filename_, "http://") || Util::startsWith(filename_, "https://")) {
|
||||||
|
std::vector<unsigned char> body;
|
||||||
|
if (HttpClient::download(filename_, body) && !body.empty()) {
|
||||||
|
return loadTextureFromMemory(body.data(), body.size());
|
||||||
|
}
|
||||||
|
return TextureData();
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureData out;
|
||||||
|
|
||||||
|
std::string filename = textureFolder? "data/images/" + filename_
|
||||||
|
: filename_;
|
||||||
|
std::ifstream source(filename.c_str(), std::ios::binary);
|
||||||
|
|
||||||
|
if (!source) {
|
||||||
|
LOGI("Couldn't find file: %s\n", filename.c_str());
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<unsigned char> fileData((std::istreambuf_iterator<char>(source)), std::istreambuf_iterator<char>());
|
||||||
|
source.close();
|
||||||
|
|
||||||
|
if (fileData.empty()) {
|
||||||
|
LOGI("Couldn't read file: %s\n", filename.c_str());
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
return loadTextureFromMemory(fileData.data(), fileData.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureData loadTextureFromMemory(const unsigned char* data, size_t size) override {
|
||||||
|
return loadPngFromMemory(data, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::string getDateString(int s) override {
|
||||||
|
time_t tm = s;
|
||||||
|
|
||||||
|
char mbstr[100];
|
||||||
|
std::strftime(mbstr, sizeof(mbstr), "%F %T", std::localtime(&tm));
|
||||||
|
|
||||||
|
return std::string(mbstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual int getScreenWidth() override {
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
int w, h;
|
||||||
|
emscripten_get_canvas_element_size("canvas", &w, &h);
|
||||||
|
|
||||||
|
return w;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 854;
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual int getScreenHeight() override {
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
int w, h;
|
||||||
|
emscripten_get_canvas_element_size("canvas", &w, &h);
|
||||||
|
|
||||||
|
return h;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 480;
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual float getPixelsPerMillimeter() override;
|
||||||
|
|
||||||
|
virtual bool supportsTouchscreen() override { return false; /* glfw supports only mouse and keyboard */ }
|
||||||
|
|
||||||
|
virtual void hideCursor(bool hide) override {
|
||||||
|
int isHide = hide ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_HIDDEN;
|
||||||
|
glfwSetInputMode(window, GLFW_CURSOR, isHide);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void openURL(const std::string& url) override {
|
||||||
|
#ifdef _WIN32
|
||||||
|
ShellExecuteA(NULL, "open", url.c_str(), NULL, NULL, SW_SHOWNORMAL);
|
||||||
|
#elif __linux__
|
||||||
|
std::string command = "xdg-open " + url;
|
||||||
|
system(command.c_str());
|
||||||
|
#elif __EMSCRIPTEN__
|
||||||
|
emscripten_run_script(std::string("window.open('" + url + "', '_blank')").c_str());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
GLFWwindow* window;
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
#endif /*APPPLATFORM_GLFW_H__*/
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#ifndef APPPLATFORM_IOS_H__
|
||||||
|
#define APPPLATFORM_IOS_H__
|
||||||
|
|
||||||
#include <IPlatform.h>
|
#include "AppPlatform.h"
|
||||||
#include "client/renderer/gles.hpp"
|
#include "client/renderer/gles.h"
|
||||||
#include "platform/log.hpp"
|
#include "platform/log.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -26,7 +27,7 @@ public:
|
|||||||
//@todo
|
//@todo
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned int rgbToBgr(unsigned int p) {
|
__inline unsigned int rgbToBgr(unsigned int p) {
|
||||||
return (p & 0xff00ff00) | ((p >> 16) & 0xff) | ((p << 16) & 0xff0000);
|
return (p & 0xff00ff00) | ((p >> 16) & 0xff) | ((p << 16) & 0xff0000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,3 +63,4 @@ private:
|
|||||||
minecraftpeViewController* _viewController;
|
minecraftpeViewController* _viewController;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*APPPLATFORM_IOS_H__*/
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "AppPlatform_win32.hpp"
|
#include "AppPlatform_win32.h"
|
||||||
#include "util/Mth.hpp"
|
#include "util/Mth.h"
|
||||||
|
|
||||||
int AppPlatform_win32::getScreenWidth() { return 854; }
|
int AppPlatform_win32::getScreenWidth() { return 854; }
|
||||||
int AppPlatform_win32::getScreenHeight() { return 480; }
|
int AppPlatform_win32::getScreenHeight() { return 480; }
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
#pragma once
|
#ifndef APPPLATFORM_WIN32_H__
|
||||||
|
#define APPPLATFORM_WIN32_H__
|
||||||
|
|
||||||
#include <IPlatform.hpp>
|
#include "AppPlatform.h"
|
||||||
#include "platform/log.hpp"
|
#include "platform/log.h"
|
||||||
#include "platform/HttpClient.hpp"
|
#include "platform/HttpClient.h"
|
||||||
#include "platform/PngLoader.hpp"
|
#include "platform/PngLoader.h"
|
||||||
#include "client/renderer/gles.hpp"
|
#include "client/renderer/gles.h"
|
||||||
#include "world/level/storage/FolderMethods.hpp"
|
#include "world/level/storage/FolderMethods.h"
|
||||||
#include "util/StringUtils.hpp"
|
#include "util/StringUtils.h"
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -46,7 +47,7 @@ public:
|
|||||||
//@todo
|
//@todo
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned int rgbToBgr(unsigned int p) {
|
__inline unsigned int rgbToBgr(unsigned int p) {
|
||||||
return (p & 0xff00ff00) | ((p >> 16) & 0xff) | ((p << 16) & 0xff0000);
|
return (p & 0xff00ff00) | ((p >> 16) & 0xff) | ((p << 16) & 0xff0000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,3 +139,4 @@ public:
|
|||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*APPPLATFORM_WIN32_H__*/
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#ifndef EGLCONFIGPRINTER_H__
|
||||||
|
#define EGLCONFIGPRINTER_H__
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -121,3 +122,4 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*EGLCONFIGPRINTER_H__*/
|
||||||
13
src/ErrorCodes.h
Executable file
13
src/ErrorCodes.h
Executable file
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef ERRORCODES_H__
|
||||||
|
#define ERRORCODES_H__
|
||||||
|
|
||||||
|
namespace ErrorCodes {
|
||||||
|
|
||||||
|
enum Enum {
|
||||||
|
Unknown,
|
||||||
|
ContainerRefStillExistsAfterDestruction
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /*ERRORCODES_H__*/
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
#include <IPlatform.hpp>
|
|
||||||
#include <App.hpp>
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
void IPlatform::runMainLoop(App& app) {
|
|
||||||
while(!app.wantToQuit()) app.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
ByteVector IPlatform::readAssetFile(const std::string& path) {
|
|
||||||
std::ifstream instream(path, std::ios::in | std::ios::binary);
|
|
||||||
std::vector<uint8_t> data((std::istreambuf_iterator<char>(instream)), std::istreambuf_iterator<char>());
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include "client/renderer/TextureData.hpp"
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
typedef std::vector<std::string> StringVector;
|
|
||||||
typedef std::vector<uint8_t> ByteVector;
|
|
||||||
|
|
||||||
class App;
|
|
||||||
|
|
||||||
class IPlatform {
|
|
||||||
public:
|
|
||||||
IPlatform() : keyboardVisible(false), windowSizeChanged(false), m_targetFrametime(0.f) {}
|
|
||||||
virtual ~IPlatform() {}
|
|
||||||
|
|
||||||
virtual bool init() { return true; }
|
|
||||||
virtual void swapBuffers() {}
|
|
||||||
|
|
||||||
virtual void runMainLoop(App& app);
|
|
||||||
|
|
||||||
virtual ByteVector readAssetFile(const std::string& path);
|
|
||||||
|
|
||||||
|
|
||||||
// Mojang functions here
|
|
||||||
virtual TextureData loadTexture(const std::string& filename_, bool textureFolder) { return TextureData(); }
|
|
||||||
virtual TextureData loadTextureFromMemory(const unsigned char* data, size_t size) { return TextureData(); }
|
|
||||||
|
|
||||||
virtual void playSound(const std::string& fn, float volume, float pitch) {}
|
|
||||||
|
|
||||||
virtual void hideCursor(bool hide) {}
|
|
||||||
|
|
||||||
virtual std::string getDateString(int s) = 0;
|
|
||||||
|
|
||||||
virtual void uploadPlatformDependentData(int id, void* data) {}
|
|
||||||
// virtual BinaryBlob readAssetFile(const std::string& filename) { return BinaryBlob(); }
|
|
||||||
virtual void _tick() {}
|
|
||||||
|
|
||||||
virtual int getScreenWidth() { return 854; }
|
|
||||||
virtual int getScreenHeight() { return 480; }
|
|
||||||
virtual float getPixelsPerMillimeter() { return 10; }
|
|
||||||
|
|
||||||
virtual bool isNetworkEnabled(bool onlyWifiAllowed) { return true; }
|
|
||||||
|
|
||||||
virtual bool isPowerVR() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
virtual int getKeyFromKeyCode(int keyCode, int metaState, int deviceId) {return 0;}
|
|
||||||
#ifdef __APPLE__
|
|
||||||
virtual bool isSuperFast() = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
virtual void openURL(const std::string& url) {}
|
|
||||||
|
|
||||||
virtual void finish() {}
|
|
||||||
|
|
||||||
virtual bool supportsTouchscreen() { return false; }
|
|
||||||
|
|
||||||
virtual void vibrate(int milliSeconds) {}
|
|
||||||
|
|
||||||
virtual std::string getPlatformStringVar(int stringId) = 0;
|
|
||||||
|
|
||||||
virtual void showKeyboard() { keyboardVisible = true; }
|
|
||||||
|
|
||||||
virtual void hideKeyboard() { keyboardVisible = false; }
|
|
||||||
|
|
||||||
virtual bool isKeyboardVisible() { return keyboardVisible; }
|
|
||||||
|
|
||||||
virtual void setTargetFPS(int fps) { m_targetFrametime = 1.0 / fps; }
|
|
||||||
|
|
||||||
bool isWindowSizeChanged() { return windowSizeChanged; }
|
|
||||||
|
|
||||||
virtual void setVSync(bool on) { vsync = on; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool keyboardVisible;
|
|
||||||
bool windowSizeChanged;
|
|
||||||
bool vsync;
|
|
||||||
|
|
||||||
double m_targetFrametime;
|
|
||||||
};
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#ifndef LICENSECODES_H__
|
||||||
|
#define LICENSECODES_H__
|
||||||
|
|
||||||
class LicenseCodes
|
class LicenseCodes
|
||||||
{
|
{
|
||||||
@@ -1,502 +0,0 @@
|
|||||||
#include <Minecraft.hpp>
|
|
||||||
#include "gamemode/CreativeMode.hpp"
|
|
||||||
#include "gamemode/SurvivalMode.hpp"
|
|
||||||
#include "gamemode/CreatorMode.hpp"
|
|
||||||
#include "world/entity/player/Player.hpp"
|
|
||||||
#include "world/item/Item.hpp"
|
|
||||||
#include "world/item/ItemInstance.hpp"
|
|
||||||
#include "world/item/crafting/Recipes.hpp"
|
|
||||||
#include "world/level/Level.hpp"
|
|
||||||
#include "world/level/tile/entity/TileEntity.hpp"
|
|
||||||
#include <string>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include "client/gui/Screen.hpp"
|
|
||||||
#include "world/level/storage/ExternalFileLevelStorageSource.hpp"
|
|
||||||
|
|
||||||
#if defined(APPLE_DEMO_PROMOTION)
|
|
||||||
#define NO_NETWORK
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(RPI)
|
|
||||||
#define CREATORMODE
|
|
||||||
#endif
|
|
||||||
#include "network/RakNetInstance.hpp"
|
|
||||||
#include "network/ClientSideNetworkHandler.hpp"
|
|
||||||
#include "network/ServerSideNetworkHandler.hpp"
|
|
||||||
//#include "network/Packet.hpp"
|
|
||||||
#include "world/entity/player/Inventory.hpp"
|
|
||||||
#include "world/level/tile/Tile.hpp"
|
|
||||||
#include "world/level/storage/LevelStorageSource.hpp"
|
|
||||||
#include "world/level/storage/LevelStorage.hpp"
|
|
||||||
#include "world/level/chunk/ChunkSource.hpp"
|
|
||||||
|
|
||||||
#include "platform/CThread.hpp"
|
|
||||||
#include <IPlatform.hpp>
|
|
||||||
#include "util/PerfTimer.hpp"
|
|
||||||
#include "util/PerfRenderer.hpp"
|
|
||||||
|
|
||||||
#include "world/entity/MobFactory.hpp"
|
|
||||||
#include "world/level/MobSpawner.hpp"
|
|
||||||
#include "util/Mth.hpp"
|
|
||||||
#include "world/entity/MobCategory.hpp"
|
|
||||||
#include "server/ServerLevel.hpp"
|
|
||||||
|
|
||||||
#ifdef CREATORMODE
|
|
||||||
#include "server/CreatorLevel.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "network/command/CommandServer.hpp"
|
|
||||||
|
|
||||||
/*static*/
|
|
||||||
const char* Minecraft::progressMessages[] = {
|
|
||||||
"Locating server",
|
|
||||||
"Building terrain",
|
|
||||||
"Preparing",
|
|
||||||
"Saving chunks"
|
|
||||||
};
|
|
||||||
|
|
||||||
// int Minecraft::customDebugId = Minecraft::CDI_NONE;
|
|
||||||
bool Minecraft::_hasInitedStatics = false;
|
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
#pragma warning( disable : 4355 ) // 'this' pointer in initialization list which is perfectly legal
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Minecraft::Minecraft() :
|
|
||||||
// #ifdef __APPLE__
|
|
||||||
// _isSuperFast(false),
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
|
|
||||||
// #if defined(NO_NETWORK)
|
|
||||||
// raknetInstance = new IRakNetInstance();
|
|
||||||
// #else
|
|
||||||
// raknetInstance = new RakNetInstance();
|
|
||||||
// #endif
|
|
||||||
// #ifndef STANDALONE_SERVER
|
|
||||||
// soundEngine = new SoundEngine(20.0f);
|
|
||||||
// soundEngine->init(this, &options);
|
|
||||||
// #endif
|
|
||||||
// //setupPieces();
|
|
||||||
|
|
||||||
// #if defined(ANDROID) || defined(__APPLE__) || defined(RPI)
|
|
||||||
// signal(SIGPIPE, SIG_IGN);
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
// externalCacheStoragePath = '.';
|
|
||||||
// externalCacheStoragePath = '.';
|
|
||||||
// }
|
|
||||||
|
|
||||||
Minecraft::~Minecraft() {
|
|
||||||
delete netCallback;
|
|
||||||
delete raknetInstance;
|
|
||||||
delete gameMode;
|
|
||||||
|
|
||||||
if (level != NULL) {
|
|
||||||
level->saveGame();
|
|
||||||
if (level->getChunkSource())
|
|
||||||
level->getChunkSource()->saveAll(true);
|
|
||||||
delete level->getLevelStorage();
|
|
||||||
delete level;
|
|
||||||
level = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
//delete player;
|
|
||||||
delete storageSource;
|
|
||||||
delete _commandServer;
|
|
||||||
|
|
||||||
MobFactory::clearStaticTestMobs();
|
|
||||||
|
|
||||||
// Note: Don't tear down statics if we run on Android
|
|
||||||
// (we might change this in the future)
|
|
||||||
#ifndef ANDROID
|
|
||||||
Biome::teardownBiomes();
|
|
||||||
Item ::teardownItems();
|
|
||||||
Tile ::teardownTiles();
|
|
||||||
Material::teardownMaterials();
|
|
||||||
Recipes ::teardownRecipes();
|
|
||||||
TileEntity::teardownTileEntities();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only called by server
|
|
||||||
void Minecraft::selectLevel( const std::string& levelId, const std::string& levelName, const LevelSettings& settings ) {
|
|
||||||
level = (Level*)new ServerLevel(
|
|
||||||
storageSource->selectLevel(levelId, false),
|
|
||||||
levelName,
|
|
||||||
settings,
|
|
||||||
SharedConstants::GeneratorVersion
|
|
||||||
);
|
|
||||||
|
|
||||||
// note: settings is useless beyond this point, since it's
|
|
||||||
// either copied to LevelData (or LevelData read from file)
|
|
||||||
setLevel(level, "Generating level");
|
|
||||||
setIsCreativeMode(level->getLevelData()->getGameType() == GameType::Creative);
|
|
||||||
_running = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Minecraft::setLevel(Level* level, const std::string& message, Player* forceInsertPlayer) {
|
|
||||||
LOGI("Seed is %ld\n", level->getSeed());
|
|
||||||
|
|
||||||
if (level != NULL) {
|
|
||||||
level->raknetInstance = raknetInstance;
|
|
||||||
gameMode->initLevel(level);
|
|
||||||
|
|
||||||
this->level = level;
|
|
||||||
_hasSignaledGeneratingLevelFinished = false;
|
|
||||||
#ifdef STANDALONE_SERVER
|
|
||||||
const bool threadedLevelCreation = false;
|
|
||||||
#else
|
|
||||||
const bool threadedLevelCreation = true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (threadedLevelCreation) {
|
|
||||||
// Threaded
|
|
||||||
// "Lock"
|
|
||||||
isGeneratingLevel = true;
|
|
||||||
generateLevelThread = new CThread(Minecraft::prepareLevel_tspawn, this);
|
|
||||||
} else {
|
|
||||||
// Non-threaded
|
|
||||||
generateLevel("Currently not used", level);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this->lastTickTime = 0;
|
|
||||||
this->_running = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Minecraft::prepareLevel(const std::string& title) {
|
|
||||||
LOGI("status: 1\n");
|
|
||||||
progressStageStatusId = 1;
|
|
||||||
|
|
||||||
Stopwatch A, B, C, D;
|
|
||||||
A.start();
|
|
||||||
|
|
||||||
Stopwatch L;
|
|
||||||
|
|
||||||
// Dont update lights if we load the level (ok, actually just with leveldata version=1.+(?))
|
|
||||||
if (!level->isNew())
|
|
||||||
level->setUpdateLights(false);
|
|
||||||
|
|
||||||
int Max = CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH;
|
|
||||||
int pp = 0;
|
|
||||||
for (int x = 8; x < (CHUNK_CACHE_WIDTH * CHUNK_WIDTH); x += CHUNK_WIDTH) {
|
|
||||||
for (int z = 8; z < (CHUNK_CACHE_WIDTH * CHUNK_WIDTH); z += CHUNK_WIDTH) {
|
|
||||||
progressStagePercentage = 100 * pp++ / Max;
|
|
||||||
//printf("level generation progress %d\n", progressStagePercentage);
|
|
||||||
B.start();
|
|
||||||
level->getTile(x, 64, z);
|
|
||||||
B.stop();
|
|
||||||
L.start();
|
|
||||||
if (level->isNew())
|
|
||||||
while (level->updateLights())
|
|
||||||
;
|
|
||||||
L.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
A.stop();
|
|
||||||
level->setUpdateLights(true);
|
|
||||||
|
|
||||||
C.start();
|
|
||||||
for (int x = 0; x < CHUNK_CACHE_WIDTH; x++)
|
|
||||||
{
|
|
||||||
for (int z = 0; z < CHUNK_CACHE_WIDTH; z++)
|
|
||||||
{
|
|
||||||
LevelChunk* chunk = level->getChunk(x, z);
|
|
||||||
if (chunk && !chunk->createdFromSave)
|
|
||||||
{
|
|
||||||
chunk->unsaved = false;
|
|
||||||
chunk->clearUpdateMap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
C.stop();
|
|
||||||
|
|
||||||
LOGI("status: 3\n");
|
|
||||||
progressStageStatusId = 3;
|
|
||||||
if (level->isNew()) {
|
|
||||||
level->setInitialSpawn(); // @note: should obviously be called from Level itself
|
|
||||||
level->saveLevelData();
|
|
||||||
level->getChunkSource()->saveAll(false);
|
|
||||||
level->saveGame();
|
|
||||||
} else {
|
|
||||||
level->saveLevelData();
|
|
||||||
level->loadEntities();
|
|
||||||
}
|
|
||||||
|
|
||||||
progressStagePercentage = -1;
|
|
||||||
progressStageStatusId = 2;
|
|
||||||
LOGI("status: 2\n");
|
|
||||||
|
|
||||||
D.start();
|
|
||||||
level->prepare();
|
|
||||||
D.stop();
|
|
||||||
|
|
||||||
A.print("Generate level: ");
|
|
||||||
L.print(" - light: ");
|
|
||||||
B.print(" - getTl: ");
|
|
||||||
C.print(" - clear: ");
|
|
||||||
D.print(" - prepr: ");
|
|
||||||
progressStageStatusId = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Minecraft::update() {
|
|
||||||
|
|
||||||
timer.advanceTime();
|
|
||||||
raknetInstance->runEvents(netCallback);
|
|
||||||
|
|
||||||
TIMER_PUSH("tick");
|
|
||||||
int toTick = timer.ticks;
|
|
||||||
timer.ticks = 0;
|
|
||||||
for (int i = 0; i < toTick; ++i, ++ticks) tick(i, toTick-1);
|
|
||||||
|
|
||||||
TIMER_POP_PUSH("updatelights");
|
|
||||||
{
|
|
||||||
if (level && !isGeneratingLevel) {
|
|
||||||
level->updateLights();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
TIMER_POP();
|
|
||||||
|
|
||||||
|
|
||||||
// Restart the server if (our modded) RakNet reports an error
|
|
||||||
if (level && raknetInstance->isProbablyBroken() && raknetInstance->isServer()) {
|
|
||||||
restartServer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Minecraft::restartServer() {
|
|
||||||
if (!level) return;
|
|
||||||
|
|
||||||
raknetInstance->resetIsBroken();
|
|
||||||
|
|
||||||
hostMultiplayer();
|
|
||||||
if (netCallback) netCallback->levelGenerated(level);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Minecraft::tick(int nTick, int maxTick) {
|
|
||||||
if (missTime > 0) missTime--;
|
|
||||||
|
|
||||||
TIMER_PUSH("gameMode");
|
|
||||||
if (level) {
|
|
||||||
gameMode->tick();
|
|
||||||
}
|
|
||||||
|
|
||||||
TIMER_POP_PUSH("commandServer");
|
|
||||||
if (level && _commandServer) {
|
|
||||||
_commandServer->tick();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Ongoing level generation in a (perhaps) different thread. When it's
|
|
||||||
// ready, _levelGenerated() is called once and any threads are deleted.
|
|
||||||
//
|
|
||||||
if (isGeneratingLevel) {
|
|
||||||
return;
|
|
||||||
} else if (!_hasSignaledGeneratingLevelFinished) {
|
|
||||||
if (generateLevelThread) {
|
|
||||||
delete generateLevelThread;
|
|
||||||
generateLevelThread = NULL;
|
|
||||||
}
|
|
||||||
_levelGenerated();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Normal game loop, run before or efter level generation
|
|
||||||
//
|
|
||||||
if (level != NULL) {
|
|
||||||
TIMER_POP_PUSH("level");
|
|
||||||
level->tickEntities();
|
|
||||||
level->tick();
|
|
||||||
}
|
|
||||||
|
|
||||||
TIMER_POP();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Minecraft::isOnlineClient() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Minecraft::isOnline() {
|
|
||||||
return netCallback != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Minecraft::init()
|
|
||||||
{
|
|
||||||
// WHY DO WE NEED THIS ON MODERN PLATFORMS :sob:
|
|
||||||
// Global initialization goes here
|
|
||||||
Mth::initMth();
|
|
||||||
|
|
||||||
if (raknetInstance != nullptr) {
|
|
||||||
delete raknetInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
raknetInstance = new RakNetInstance();
|
|
||||||
|
|
||||||
// If we're running Android, only initialize
|
|
||||||
// the first time class is instanced
|
|
||||||
#ifdef ANDROID
|
|
||||||
if (!_hasInitedStatics) {
|
|
||||||
_hasInitedStatics = true;
|
|
||||||
#endif
|
|
||||||
Material::initMaterials();
|
|
||||||
MobCategory::initMobCategories();
|
|
||||||
Tile::initTiles();
|
|
||||||
Item::initItems();
|
|
||||||
Biome::initBiomes();
|
|
||||||
TileEntity::initTileEntities();
|
|
||||||
|
|
||||||
#ifdef ANDROID
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
setIsCreativeMode(false); // false means it's Survival Mode
|
|
||||||
|
|
||||||
#if !defined(NO_STORAGE)
|
|
||||||
storageSource = new ExternalFileLevelStorageSource(externalStoragePath, externalCacheStoragePath);
|
|
||||||
#else
|
|
||||||
storageSource = new MemoryLevelStorageSource();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Server-only featire @todo server class app
|
|
||||||
hostMultiplayer();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// Multiplayer
|
|
||||||
//
|
|
||||||
|
|
||||||
void Minecraft::hostMultiplayer(int port) {
|
|
||||||
// Tear down last instance
|
|
||||||
raknetInstance->disconnect();
|
|
||||||
delete netCallback;
|
|
||||||
netCallback = nullptr;
|
|
||||||
|
|
||||||
#if !defined(NO_NETWORK)
|
|
||||||
netCallback = new ServerSideNetworkHandler(this, raknetInstance);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Level generation
|
|
||||||
//
|
|
||||||
/*static*/
|
|
||||||
|
|
||||||
void* Minecraft::prepareLevel_tspawn(void *p_param) {
|
|
||||||
Minecraft* mc = (Minecraft*) p_param;
|
|
||||||
mc->generateLevel("Currently not used", mc->level);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Minecraft::generateLevel( const std::string& message, Level* level ) {
|
|
||||||
Stopwatch s;
|
|
||||||
s.start();
|
|
||||||
prepareLevel(message);
|
|
||||||
s.stop();
|
|
||||||
s.print("Level generated: ");
|
|
||||||
|
|
||||||
// "Unlock"
|
|
||||||
isGeneratingLevel = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Minecraft::_levelGenerated() {
|
|
||||||
level->validateSpawn();
|
|
||||||
|
|
||||||
if (raknetInstance->isServer())
|
|
||||||
raknetInstance->announceServer(getServerName());
|
|
||||||
|
|
||||||
if (netCallback) {
|
|
||||||
netCallback->levelGenerated(level);
|
|
||||||
}
|
|
||||||
|
|
||||||
_hasSignaledGeneratingLevelFinished = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player* Minecraft::respawnPlayer(int playerId) {
|
|
||||||
for (unsigned int i = 0; i < level->players.size(); ++i) {
|
|
||||||
if (level->players[i]->entityId == playerId) {
|
|
||||||
resetPlayer(level->players[i]);
|
|
||||||
return level->players[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Minecraft::resetPlayer(Player* player) {
|
|
||||||
level->validateSpawn();
|
|
||||||
player->reset();
|
|
||||||
|
|
||||||
Pos p;
|
|
||||||
if(player->hasRespawnPosition()) {
|
|
||||||
p = player->getRespawnPosition();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
p = level->getSharedSpawnPos();
|
|
||||||
}
|
|
||||||
player->setPos((float)p.x + 0.5f, (float)p.y + 1.0f, (float)p.z + 0.5f);
|
|
||||||
player->resetPos(true);
|
|
||||||
|
|
||||||
if (isCreativeMode())
|
|
||||||
player->inventory->clearInventoryWithDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
int Minecraft::getProgressStatusId() {
|
|
||||||
return progressStageStatusId;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* Minecraft::getProgressMessage()
|
|
||||||
{
|
|
||||||
return progressMessages[progressStageStatusId];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Minecraft::isLevelGenerated()
|
|
||||||
{
|
|
||||||
return level != NULL && !isGeneratingLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
LevelStorageSource* Minecraft::getLevelSource()
|
|
||||||
{
|
|
||||||
return storageSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Minecraft::setIsCreativeMode(bool isCreative)
|
|
||||||
{
|
|
||||||
#ifdef CREATORMODE
|
|
||||||
delete gameMode;
|
|
||||||
gameMode = new CreatorMode(this);
|
|
||||||
_isCreativeMode = true;
|
|
||||||
#else
|
|
||||||
if (!gameMode || isCreative != _isCreativeMode)
|
|
||||||
{
|
|
||||||
delete gameMode;
|
|
||||||
if (isCreative) gameMode = new CreativeMode(*this);
|
|
||||||
else gameMode = new SurvivalMode(*this);
|
|
||||||
_isCreativeMode = isCreative;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Minecraft::isCreativeMode() {
|
|
||||||
return _isCreativeMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
ICreator* Minecraft::getCreator()
|
|
||||||
{
|
|
||||||
#ifdef CREATORMODE
|
|
||||||
return ((CreatorMode*)gameMode)->getCreator();
|
|
||||||
#else
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void Minecraft::optionUpdated(OptionId option, bool value ) {
|
|
||||||
if(netCallback != NULL && option == OPTIONS_SERVER_VISIBLE) {
|
|
||||||
ServerSideNetworkHandler* ss = (ServerSideNetworkHandler*) netCallback;
|
|
||||||
ss->allowIncomingConnections(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Minecraft::optionUpdated(OptionId option, float value ) {}
|
|
||||||
|
|
||||||
void Minecraft::optionUpdated(OptionId option, int value ) {}
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "client/Options.hpp"
|
|
||||||
#include "client/Timer.hpp"
|
|
||||||
|
|
||||||
//#include "../network/RakNetInstance.hpp"
|
|
||||||
#include "world/phys/HitResult.hpp"
|
|
||||||
|
|
||||||
#include "App.hpp"
|
|
||||||
#include <cstddef>
|
|
||||||
|
|
||||||
class Level;
|
|
||||||
class LocalPlayer;
|
|
||||||
class IInputHolder;
|
|
||||||
class Mob;
|
|
||||||
class Player;
|
|
||||||
class Entity;
|
|
||||||
class ICreator;
|
|
||||||
class GameMode;
|
|
||||||
class CThread;
|
|
||||||
class LevelStorageSource;
|
|
||||||
class BuildActionIntention;
|
|
||||||
class PerfRenderer;
|
|
||||||
class LevelSettings;
|
|
||||||
class IRakNetInstance;
|
|
||||||
class NetEventCallback;
|
|
||||||
class CommandServer;
|
|
||||||
struct PingedCompatibleServer;
|
|
||||||
|
|
||||||
class Minecraft: public App {
|
|
||||||
public:
|
|
||||||
using App::App;
|
|
||||||
virtual ~Minecraft();
|
|
||||||
|
|
||||||
virtual void init();
|
|
||||||
virtual void update();
|
|
||||||
virtual void restartServer();
|
|
||||||
virtual void tick(int nTick, int maxTick);
|
|
||||||
|
|
||||||
virtual bool isOnlineClient();
|
|
||||||
virtual bool isOnline();
|
|
||||||
|
|
||||||
virtual void setIsCreativeMode(bool isCreative);
|
|
||||||
|
|
||||||
virtual void optionUpdated(OptionId option, bool value);
|
|
||||||
virtual void optionUpdated(OptionId option, float value);
|
|
||||||
virtual void optionUpdated(OptionId option, int value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Get public name that will be listed in JoinGame menu
|
|
||||||
*/
|
|
||||||
virtual std::string getServerName() { return "Unknown"; }
|
|
||||||
|
|
||||||
void toggleDimension() {}
|
|
||||||
bool isCreativeMode();
|
|
||||||
|
|
||||||
virtual void selectLevel(const std::string& levelId, const std::string& levelName, const LevelSettings& settings);
|
|
||||||
virtual void setLevel(Level* level, const std::string& message = "", Player* forceInsertPlayer = NULL);
|
|
||||||
|
|
||||||
virtual void onBlockDestroyed(Player* player, int x, int y, int z, int face) {}
|
|
||||||
|
|
||||||
void generateLevel( const std::string& message, Level* level );
|
|
||||||
LevelStorageSource* getLevelSource();
|
|
||||||
|
|
||||||
virtual void hostMultiplayer(int port=19132);
|
|
||||||
Player* respawnPlayer(int playerId);
|
|
||||||
void respawnPlayer();
|
|
||||||
void resetPlayer(Player* player);
|
|
||||||
void doActuallyRespawnPlayer();
|
|
||||||
|
|
||||||
void prepareLevel(const std::string& message);
|
|
||||||
|
|
||||||
int getProgressStatusId();
|
|
||||||
const char* getProgressMessage();
|
|
||||||
|
|
||||||
ICreator* getCreator();
|
|
||||||
|
|
||||||
bool isLevelGenerated();
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
bool _isSuperFast = false;
|
|
||||||
bool isSuperFast() { return _isSuperFast; }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void _levelGenerated();
|
|
||||||
|
|
||||||
private:
|
|
||||||
static void* prepareLevel_tspawn(void *p_param);
|
|
||||||
public:
|
|
||||||
Level* level = nullptr;
|
|
||||||
CommandServer* _commandServer = nullptr;
|
|
||||||
GameMode* gameMode = nullptr;
|
|
||||||
IRakNetInstance* raknetInstance = nullptr;
|
|
||||||
NetEventCallback* netCallback = nullptr;
|
|
||||||
|
|
||||||
int commandPort = 4711;
|
|
||||||
|
|
||||||
int lastTime = 0;
|
|
||||||
int lastTickTime = -1;
|
|
||||||
int missTime = 0;
|
|
||||||
int ticks = 0;
|
|
||||||
|
|
||||||
CThread* generateLevelThread = nullptr;
|
|
||||||
// static int customDebugId;
|
|
||||||
|
|
||||||
HitResult hitResult;
|
|
||||||
volatile int progressStagePercentage = 0;
|
|
||||||
|
|
||||||
// This field is initialized in main()
|
|
||||||
// It sets the base path to where worlds can be written (sdcard on android)
|
|
||||||
std::string externalStoragePath;
|
|
||||||
std::string externalCacheStoragePath;
|
|
||||||
protected:
|
|
||||||
Timer timer{20};
|
|
||||||
// @note @attn @warn: this is dangerous as fuck!
|
|
||||||
volatile bool isGeneratingLevel = false;
|
|
||||||
bool _hasSignaledGeneratingLevelFinished = true;
|
|
||||||
|
|
||||||
LevelStorageSource* storageSource;
|
|
||||||
bool _running;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
volatile int progressStageStatusId = 0;
|
|
||||||
static const char* progressMessages[];
|
|
||||||
|
|
||||||
int _licenseId;
|
|
||||||
|
|
||||||
bool _isCreativeMode;
|
|
||||||
Player* _pendingRemovePlayer; // @attn @todo @fix: remove this shait and fix the respawn behaviour
|
|
||||||
|
|
||||||
// from NinecraftApp
|
|
||||||
bool _verbose = true;
|
|
||||||
int _lastTickMs = 0;
|
|
||||||
|
|
||||||
static bool _hasInitedStatics;
|
|
||||||
};
|
|
||||||
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "client/gui/Font.hpp"
|
|
||||||
#include "client/gui/Screen.hpp"
|
|
||||||
#include "client/particle/ParticleEngine.hpp"
|
|
||||||
#include "client/player/LocalPlayer.hpp"
|
|
||||||
#include "client/renderer/GameRenderer.hpp"
|
|
||||||
#include "client/renderer/Textures.hpp"
|
|
||||||
#include "client/sound/SoundEngine.hpp"
|
|
||||||
#include <Minecraft.hpp>
|
|
||||||
|
|
||||||
#include <client/MouseHandler.hpp>
|
|
||||||
#include <client/gui/Gui.hpp>
|
|
||||||
#include <client/gui/screens/ScreenChooser.hpp>
|
|
||||||
#include <client/PixelCalc.hpp>
|
|
||||||
#include <client/renderer/LevelRenderer.hpp>
|
|
||||||
|
|
||||||
class MinecraftClient : public Minecraft {
|
|
||||||
public:
|
|
||||||
using Minecraft::Minecraft;
|
|
||||||
~MinecraftClient();
|
|
||||||
|
|
||||||
void init() override;
|
|
||||||
|
|
||||||
void update() override;
|
|
||||||
|
|
||||||
void setSize(int width, int height);
|
|
||||||
void reloadOptions();
|
|
||||||
|
|
||||||
bool supportNonTouchScreen();
|
|
||||||
bool useTouchscreen();
|
|
||||||
void grabMouse();
|
|
||||||
void releaseMouse();
|
|
||||||
|
|
||||||
void setScreen(Screen*);
|
|
||||||
void leaveGame(bool renameLevel = false);
|
|
||||||
|
|
||||||
void setLevel(Level* level, const std::string& message = "", Player* forceInsertPlayer = NULL) override;
|
|
||||||
|
|
||||||
void updateStats();
|
|
||||||
|
|
||||||
void restartServer() override;
|
|
||||||
|
|
||||||
bool handleBack(bool isDown) override;
|
|
||||||
|
|
||||||
void onGraphicsReset();
|
|
||||||
void initGLStates();
|
|
||||||
|
|
||||||
void tick(int nTick, int maxTick) override;
|
|
||||||
void tickInput();
|
|
||||||
|
|
||||||
void handleBuildAction(BuildActionIntention* action);
|
|
||||||
|
|
||||||
bool isOnlineClient() override;
|
|
||||||
|
|
||||||
void pauseGame(bool isBackPaused);
|
|
||||||
void gameLostFocus();
|
|
||||||
|
|
||||||
void respawnPlayer();
|
|
||||||
|
|
||||||
void audioEngineOn() override;
|
|
||||||
void audioEngineOff() override;
|
|
||||||
|
|
||||||
void setIsCreativeMode(bool isCreative) override;
|
|
||||||
|
|
||||||
void optionUpdated(OptionId option, bool value) override;
|
|
||||||
void optionUpdated(OptionId option, float value) override;
|
|
||||||
void optionUpdated(OptionId option, int value) override;
|
|
||||||
|
|
||||||
LocalPlayer* getPlayer() { return player; }
|
|
||||||
Font* getFont() { return font; }
|
|
||||||
Textures& textures() { return m_textures; }
|
|
||||||
Options& options() { return m_options;}
|
|
||||||
Screen* getScreen() { return m_screen; }
|
|
||||||
Gui& gui() { return m_gui; }
|
|
||||||
ParticleEngine* getParticleEngine() {return particleEngine; }
|
|
||||||
|
|
||||||
int getScreenWidth() { return width; }
|
|
||||||
int getScreenHeigth() { return height; }
|
|
||||||
|
|
||||||
virtual void hostMultiplayer(int port) override;
|
|
||||||
|
|
||||||
bool isPowerVR() { return _powerVr; }
|
|
||||||
bool isKindleFire(int kindleVersion);
|
|
||||||
bool transformResolution(int* w, int* h);
|
|
||||||
|
|
||||||
virtual std::string getServerName() override;
|
|
||||||
|
|
||||||
void locateMultiplayer();
|
|
||||||
void cancelLocateMultiplayer();
|
|
||||||
bool joinMultiplayer(const PingedCompatibleServer& server);
|
|
||||||
bool joinMultiplayerFromString(const std::string& server);
|
|
||||||
|
|
||||||
void onBlockDestroyed(Player* player, int x, int y, int z, int face) override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void _reloadInput();
|
|
||||||
void _levelGenerated() override;
|
|
||||||
|
|
||||||
int width = 1, height = 1;
|
|
||||||
|
|
||||||
Font* font = nullptr;
|
|
||||||
// @warn This is unsafe cuz Gui may call some MinecraftClient method while MinecraftClient is not ready
|
|
||||||
MouseHandler mouseHandler;
|
|
||||||
|
|
||||||
LevelRenderer* levelRenderer = nullptr;
|
|
||||||
GameRenderer* gameRenderer = nullptr;
|
|
||||||
ParticleEngine* particleEngine = nullptr;
|
|
||||||
SoundEngine* soundEngine = nullptr;
|
|
||||||
PerfRenderer* _perfRenderer = nullptr;
|
|
||||||
|
|
||||||
bool mouseGrabbed = false;
|
|
||||||
|
|
||||||
PixelCalc pixelCalc;
|
|
||||||
PixelCalc pixelCalcUi;
|
|
||||||
|
|
||||||
Screen* m_screen = nullptr;
|
|
||||||
|
|
||||||
bool screenMutex = false;
|
|
||||||
bool hasScheduledScreen = false;
|
|
||||||
Screen* scheduledScreen = nullptr;
|
|
||||||
|
|
||||||
int m_frames = 0;
|
|
||||||
|
|
||||||
volatile bool pause = false;
|
|
||||||
|
|
||||||
// @todo make static
|
|
||||||
LocalPlayer* player = nullptr;
|
|
||||||
IInputHolder* inputHolder = nullptr;
|
|
||||||
Mob* cameraTargetPlayer = nullptr;
|
|
||||||
|
|
||||||
bool _supportsNonTouchscreen = false;
|
|
||||||
bool isLookingForMultiplayer = false;
|
|
||||||
bool _powerVr = false;
|
|
||||||
|
|
||||||
Options m_options{*this};
|
|
||||||
|
|
||||||
Textures m_textures{m_options, *m_platform};
|
|
||||||
|
|
||||||
ScreenChooser screenChooser{*this};
|
|
||||||
|
|
||||||
Gui m_gui{*this};
|
|
||||||
};
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#include "MinecraftServer.hpp"
|
|
||||||
#include <Minecraft.hpp>
|
|
||||||
#include <network/RakNetInstance.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
void MinecraftServer::hostMultiplayer(int port) {
|
|
||||||
Minecraft::hostMultiplayer(port);
|
|
||||||
|
|
||||||
raknetInstance->host("Server", port, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string MinecraftServer::getServerName() {
|
|
||||||
// @todo read server name from config
|
|
||||||
return "Dedicated server 0.6.1";
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <Minecraft.hpp>
|
|
||||||
|
|
||||||
class MinecraftServer : public Minecraft {
|
|
||||||
public:
|
|
||||||
using Minecraft::Minecraft;
|
|
||||||
|
|
||||||
void hostMultiplayer(int port) override;
|
|
||||||
std::string getServerName() override;
|
|
||||||
};
|
|
||||||
428
src/NinecraftApp.cpp
Executable file
428
src/NinecraftApp.cpp
Executable file
@@ -0,0 +1,428 @@
|
|||||||
|
#include "NinecraftApp.h"
|
||||||
|
//#include <EGL/egl.h>
|
||||||
|
|
||||||
|
#ifdef RPI
|
||||||
|
//#define NO_STORAGE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "platform/input/Mouse.h"
|
||||||
|
#include "platform/input/Multitouch.h"
|
||||||
|
|
||||||
|
#include "world/item/Item.h"
|
||||||
|
#include "world/level/Level.h"
|
||||||
|
#include "world/level/biome/Biome.h"
|
||||||
|
#include "world/level/material/Material.h"
|
||||||
|
#include "world/entity/MobCategory.h"
|
||||||
|
//#include "world/level/storage/FolderMethods.h"
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
#include "client/gui/screens/StartMenuScreen.h"
|
||||||
|
#include "client/gui/screens/UsernameScreen.h"
|
||||||
|
#endif
|
||||||
|
#include "client/player/LocalPlayer.h"
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
#include "client/renderer/gles.h"
|
||||||
|
#include "client/renderer/Chunk.h"
|
||||||
|
#include "client/renderer/LevelRenderer.h"
|
||||||
|
#include "client/renderer/Tesselator.h"
|
||||||
|
#endif
|
||||||
|
// sorry for raknet dependency, but I'm too lazy to find another getTime method
|
||||||
|
#include "raknet/GetTime.h"
|
||||||
|
#include "network/RakNetInstance.h"
|
||||||
|
#include "network/ClientSideNetworkHandler.h"
|
||||||
|
#include "client/gui/screens/ProgressScreen.h"
|
||||||
|
|
||||||
|
//#include "world/entity/player/Inventory2.h"
|
||||||
|
|
||||||
|
#if !defined(DEMO_MODE) && !defined(APPLE_DEMO_PROMOTION) && !defined(NO_STORAGE)
|
||||||
|
#include "world/level/storage/ExternalFileLevelStorageSource.h"
|
||||||
|
#else
|
||||||
|
#include "world/level/storage/MemoryLevelStorageSource.h"
|
||||||
|
#endif
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
#include "client/renderer/Textures.h"
|
||||||
|
#include "client/renderer/entity/ItemRenderer.h"
|
||||||
|
#endif
|
||||||
|
#include "world/item/crafting/Recipes.h"
|
||||||
|
#include "world/level/tile/entity/TileEntity.h"
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
#include "client/renderer/EntityTileRenderer.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool NinecraftApp::_hasInitedStatics = false;
|
||||||
|
|
||||||
|
NinecraftApp::NinecraftApp()
|
||||||
|
: _verbose(true),
|
||||||
|
_lastTickMs(0),
|
||||||
|
_frames(0)
|
||||||
|
{
|
||||||
|
#if defined(ANDROID) || defined(__APPLE__) || defined(RPI)
|
||||||
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
NinecraftApp::~NinecraftApp()
|
||||||
|
{
|
||||||
|
teardown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NinecraftApp::init()
|
||||||
|
{
|
||||||
|
// Global initialization goes here
|
||||||
|
Mth::initMth();
|
||||||
|
|
||||||
|
//#ifdef DEMO_MODE
|
||||||
|
//writeDemoFile();
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
// If we're running Android, only initialize
|
||||||
|
// the first time class is instanced
|
||||||
|
#ifdef ANDROID
|
||||||
|
if (!_hasInitedStatics) {
|
||||||
|
_hasInitedStatics = true;
|
||||||
|
#endif
|
||||||
|
Material::initMaterials();
|
||||||
|
MobCategory::initMobCategories();
|
||||||
|
Tile::initTiles();
|
||||||
|
Item::initItems();
|
||||||
|
Biome::initBiomes();
|
||||||
|
TileEntity::initTileEntities();
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
initGLStates();
|
||||||
|
Tesselator::instance.init();
|
||||||
|
I18n::loadLanguage(platform(), "en_US");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!externalStoragePath.empty()) {
|
||||||
|
options.setOptionsFilePath(externalStoragePath);
|
||||||
|
}
|
||||||
|
Minecraft::init();
|
||||||
|
|
||||||
|
#if !defined(DEMO_MODE) && !defined(APPLE_DEMO_PROMOTION) && !defined(NO_STORAGE)
|
||||||
|
storageSource = new ExternalFileLevelStorageSource(externalStoragePath, externalCacheStoragePath);
|
||||||
|
#else
|
||||||
|
storageSource = new MemoryLevelStorageSource();
|
||||||
|
#endif
|
||||||
|
_running = false;
|
||||||
|
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
LOGI("This: %p\n", this);
|
||||||
|
screenChooser.setScreen(SCREEN_STARTMENU);
|
||||||
|
|
||||||
|
if (options.getBooleanValue(OPTIONS_FIRST_LAUNCH)) {
|
||||||
|
options.toggle(OPTIONS_FIRST_LAUNCH);
|
||||||
|
setScreen(new UsernameScreen());
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
hostMultiplayer();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void NinecraftApp::teardown()
|
||||||
|
{
|
||||||
|
// Note: Don't tear down statics if we run on Android
|
||||||
|
// (we might change this in the future)
|
||||||
|
#ifndef ANDROID
|
||||||
|
Biome::teardownBiomes();
|
||||||
|
Item ::teardownItems();
|
||||||
|
Tile ::teardownTiles();
|
||||||
|
Material::teardownMaterials();
|
||||||
|
Recipes ::teardownRecipes();
|
||||||
|
TileEntity::teardownTileEntities();
|
||||||
|
#endif
|
||||||
|
#ifdef WIN32
|
||||||
|
ItemRenderer::teardown_static();
|
||||||
|
if (EntityTileRenderer::instance != NULL) {
|
||||||
|
delete EntityTileRenderer::instance;
|
||||||
|
EntityTileRenderer::instance = NULL;
|
||||||
|
}
|
||||||
|
TileEntityRenderDispatcher::destroy();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void NinecraftApp::update()
|
||||||
|
{
|
||||||
|
++_frames;
|
||||||
|
|
||||||
|
// Generate Multitouch active pointer list
|
||||||
|
Multitouch::commit();
|
||||||
|
|
||||||
|
#ifndef ANDROID_PUBLISH
|
||||||
|
//testCreationAndDestruction();
|
||||||
|
//testJoiningAndDestruction();
|
||||||
|
#endif /*ANDROID_PUBLISH*/
|
||||||
|
|
||||||
|
Minecraft::update();
|
||||||
|
|
||||||
|
swapBuffers();
|
||||||
|
Mouse::reset2();
|
||||||
|
|
||||||
|
// Restart the server if (our modded) RakNet reports an error
|
||||||
|
if (level && raknetInstance->isProbablyBroken() && raknetInstance->isServer()) {
|
||||||
|
restartServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
updateStats();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void NinecraftApp::updateStats()
|
||||||
|
{
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
if (Options::debugGl)
|
||||||
|
LOGI("--------------------------------------------\n");
|
||||||
|
|
||||||
|
//*
|
||||||
|
int now = getTimeMs();
|
||||||
|
//int since = now - _lastTickMs;
|
||||||
|
|
||||||
|
if (now >= lastTime + 1000)
|
||||||
|
{
|
||||||
|
if (player) {
|
||||||
|
LOGI("%d fps \t%3d chunk updates. (%.2f, %.2f, %.2f)\n",
|
||||||
|
_frames, Chunk::updates, player->x, player->y, player->z);
|
||||||
|
Chunk::resetUpdates();
|
||||||
|
|
||||||
|
//static int _n = 0;
|
||||||
|
//if (++_n % 5 == -1) { // @note: -1
|
||||||
|
// static char filename[256];
|
||||||
|
// sprintf(filename, "%s/games/com.mojang/img_%.4d.jpg", externalStoragePath.c_str(), _n/5);
|
||||||
|
// _context.platform->saveScreenshot(filename, width, height);
|
||||||
|
//}
|
||||||
|
|
||||||
|
LOGI("%s", levelRenderer->gatherStats1().c_str());
|
||||||
|
//printf("Texture swaps (this frame): %d\n", Textures::textureChanges);
|
||||||
|
} else {
|
||||||
|
LOGI("%d fps\n", _frames);
|
||||||
|
}
|
||||||
|
|
||||||
|
//const int* pointerIds;
|
||||||
|
//int pointerCount = Multitouch::getActivePointerIds(&pointerIds);
|
||||||
|
//if (pointerCount) {
|
||||||
|
// std::string s = "Pointers (";
|
||||||
|
// s += (char)(48 + pointerCount);
|
||||||
|
// s += ": ";
|
||||||
|
// for (int i = 0; i < pointerCount; ++i) {
|
||||||
|
// s += (char)(48 + pointerIds[i]);
|
||||||
|
// s += ", ";
|
||||||
|
// }
|
||||||
|
// LOGI("%s\n", s.c_str());
|
||||||
|
//}
|
||||||
|
|
||||||
|
lastTime = now;
|
||||||
|
_frames = 0;
|
||||||
|
#ifdef GLDEBUG
|
||||||
|
while (1) {
|
||||||
|
int error = glGetError();
|
||||||
|
if (error == GL_NO_ERROR) break;
|
||||||
|
|
||||||
|
LOGI("#################### GL-ERROR: %d\t#####################\n", error);
|
||||||
|
LOGI("#################### GL-ERROR: %d\t#####################\n", error);
|
||||||
|
LOGI("#################### GL-ERROR: %d\t#####################\n", error);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
Textures::textureChanges = 0;
|
||||||
|
/**/
|
||||||
|
#endif /* STANDALONE_SERVER */
|
||||||
|
}
|
||||||
|
|
||||||
|
void NinecraftApp::initGLStates()
|
||||||
|
{
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
//glShadeModel2(GL_SMOOTH);
|
||||||
|
//glClearDepthf(1.0f);
|
||||||
|
glEnable2(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
glDepthRangef(0, 1);
|
||||||
|
glEnable2(GL_ALPHA_TEST);
|
||||||
|
glAlphaFunc(GL_GREATER, 0.1f);
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
|
||||||
|
glEnable2(GL_TEXTURE_2D);
|
||||||
|
#ifndef _EMSCRIPTEN_
|
||||||
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
|
||||||
|
#endif
|
||||||
|
// Both updates isPowerVR flag in java and returns if the graphics chip is PowerVR SGX or not
|
||||||
|
_powerVr = platform()->isPowerVR();
|
||||||
|
#ifdef __APPLE__
|
||||||
|
_isSuperFast = platform()->isSuperFast();
|
||||||
|
#endif
|
||||||
|
//glLineWidth(4);
|
||||||
|
#endif /* STANDALONE_SERVER */
|
||||||
|
}
|
||||||
|
|
||||||
|
void NinecraftApp::restartServer() {
|
||||||
|
if (!level) return;
|
||||||
|
|
||||||
|
for (int i = level->players.size()-1; i >= 0; --i) {
|
||||||
|
Player* p = level->players[i];
|
||||||
|
if (p != player)
|
||||||
|
level->removeEntity(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
raknetInstance->resetIsBroken();
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
gui.addMessage("This server has restarted!");
|
||||||
|
#endif
|
||||||
|
hostMultiplayer();
|
||||||
|
if (netCallback) netCallback->levelGenerated(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NinecraftApp::handleBack(bool isDown)
|
||||||
|
{
|
||||||
|
if (isGeneratingLevel)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (level)
|
||||||
|
{
|
||||||
|
if (!isDown)
|
||||||
|
{
|
||||||
|
if (screen)
|
||||||
|
{
|
||||||
|
if (!screen->handleBackEvent(isDown))
|
||||||
|
{
|
||||||
|
if (player->containerMenu) player->closeContainer();
|
||||||
|
setScreen(NULL);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
pauseGame(true);
|
||||||
|
}
|
||||||
|
//leaveGame();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (screen)
|
||||||
|
{
|
||||||
|
return screen->handleBackEvent(isDown);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NinecraftApp::onGraphicsReset()
|
||||||
|
{
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
initGLStates();
|
||||||
|
Tesselator::instance.init();
|
||||||
|
|
||||||
|
Minecraft::onGraphicsReset();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef ANDROID_PUBLISH
|
||||||
|
|
||||||
|
static int _state = -1;
|
||||||
|
static int _stateTicksLeft = 0;
|
||||||
|
void NinecraftApp::testCreationAndDestruction()
|
||||||
|
{
|
||||||
|
if (_state == -1) {
|
||||||
|
_stateTicksLeft = 100;
|
||||||
|
_state = 0;
|
||||||
|
}
|
||||||
|
if (_state == 0) {
|
||||||
|
if (--_stateTicksLeft <= 0)
|
||||||
|
_state = 1;
|
||||||
|
}
|
||||||
|
else if (_state == 1) {
|
||||||
|
getLevelSource()->deleteLevel("perf");
|
||||||
|
int seed = getEpochTimeS();
|
||||||
|
LOGI(">seed %d\n", seed);
|
||||||
|
selectLevel("perf", "perf", LevelSettings(seed, GameType::Creative));
|
||||||
|
hostMultiplayer();
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
setScreen(new ProgressScreen());
|
||||||
|
#endif
|
||||||
|
_state = 2;
|
||||||
|
_stateTicksLeft = 1000;//25000;//00;
|
||||||
|
}
|
||||||
|
else if (_state == 2) {
|
||||||
|
if (isLevelGenerated()) {
|
||||||
|
if (--_stateTicksLeft <= 0) {
|
||||||
|
_state = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (_state == 3) {
|
||||||
|
leaveGame();
|
||||||
|
_state = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void NinecraftApp::testJoiningAndDestruction()
|
||||||
|
{
|
||||||
|
if (_state == -1) {
|
||||||
|
//LightUpdate sz[2] = { LightUpdate(LightLayer::Block, 0, 0, 0, 1, 1, 1),
|
||||||
|
// LightUpdate(LightLayer::Sky, 0, 0, 0, 1, 1, 1) };
|
||||||
|
//LOGI("size of lightupdate: %lu == %d\n", sizeof(LightUpdate), (const char*)&sz[1] - (const char*)&sz[0]);
|
||||||
|
_stateTicksLeft = 100;
|
||||||
|
_state = 0;
|
||||||
|
}
|
||||||
|
if (_state == 0) {
|
||||||
|
if (--_stateTicksLeft <= 0) {
|
||||||
|
raknetInstance->clearServerList();
|
||||||
|
locateMultiplayer();
|
||||||
|
_state = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (_state == 1) {
|
||||||
|
if (!raknetInstance->getServerList().empty()) {
|
||||||
|
PingedCompatibleServer s = raknetInstance->getServerList().at(0);
|
||||||
|
if (s.name.GetLength() > 0) {
|
||||||
|
joinMultiplayer(s);
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
setScreen(new ProgressScreen());
|
||||||
|
#endif
|
||||||
|
_state = 2;
|
||||||
|
_stateTicksLeft = 80;//1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (_state == 2) {
|
||||||
|
if (isLevelGenerated()) {
|
||||||
|
if (--_stateTicksLeft <= 0) {
|
||||||
|
_state = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (_state == 3) {
|
||||||
|
leaveGame();
|
||||||
|
_stateTicksLeft = 50;
|
||||||
|
_state = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /*ANDROID_PUBLISH*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
void NinecraftApp::writeDemoFile() {
|
||||||
|
std::string path = externalStoragePath + "/games";
|
||||||
|
|
||||||
|
if (createFolderIfNotExists(path.c_str())) {
|
||||||
|
path += "/com.mojang";
|
||||||
|
if (createFolderIfNotExists(path.c_str())) {
|
||||||
|
path += "/minecraftpe";
|
||||||
|
if (createFolderIfNotExists(path.c_str())) {
|
||||||
|
path += "/played_demo";
|
||||||
|
FILE* fp = fopen(path.c_str(), "w");
|
||||||
|
if (fp) fclose(fp);
|
||||||
|
}}}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NinecraftApp::hasPlayedDemo() {
|
||||||
|
std::string filename = externalStoragePath + "/games/com.mojang/minecraftpe/played_demo";
|
||||||
|
FILE* fp = fopen(filename.c_str(), "r");
|
||||||
|
if (!fp) return false;
|
||||||
|
fclose(fp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
*/
|
||||||
52
src/NinecraftApp.h
Executable file
52
src/NinecraftApp.h
Executable file
@@ -0,0 +1,52 @@
|
|||||||
|
#ifndef NINECRAFTAPP_H__
|
||||||
|
#define NINECRAFTAPP_H__
|
||||||
|
|
||||||
|
#include "world/Pos.h"
|
||||||
|
#include "App.h"
|
||||||
|
#include "client/Minecraft.h"
|
||||||
|
#include "world/level/storage/MemoryLevelStorage.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
class Level;
|
||||||
|
class LocalPlayer;
|
||||||
|
class ExternalFileLevelStorageSource;
|
||||||
|
|
||||||
|
class NinecraftApp: public Minecraft
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NinecraftApp();
|
||||||
|
~NinecraftApp();
|
||||||
|
|
||||||
|
void init();
|
||||||
|
void teardown();
|
||||||
|
|
||||||
|
void update();
|
||||||
|
|
||||||
|
virtual bool handleBack(bool isDown);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void onGraphicsReset();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initGLStates();
|
||||||
|
void restartServer();
|
||||||
|
|
||||||
|
void updateStats();
|
||||||
|
|
||||||
|
//void writeDemoFile();
|
||||||
|
//bool hasPlayedDemo();
|
||||||
|
|
||||||
|
#ifndef ANDROID_PUBLISH
|
||||||
|
void testCreationAndDestruction();
|
||||||
|
void testJoiningAndDestruction();
|
||||||
|
#endif /*ANDROID_PUBLISH*/
|
||||||
|
|
||||||
|
bool _verbose;
|
||||||
|
int _frames;
|
||||||
|
int _lastTickMs;
|
||||||
|
|
||||||
|
static bool _hasInitedStatics;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif//NINECRAFTAPP_H__
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "Performance.hpp"
|
#include "Performance.h"
|
||||||
|
|
||||||
/*static*/
|
/*static*/
|
||||||
StopwatchHandler Performance::watches;
|
StopwatchHandler Performance::watches;
|
||||||
|
|||||||
12
src/Performance.h
Executable file
12
src/Performance.h
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef PERFORMANCE_H__
|
||||||
|
#define PERFORMANCE_H__
|
||||||
|
|
||||||
|
#include "platform/time.h"
|
||||||
|
|
||||||
|
class Performance
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static StopwatchHandler watches;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*PERFORMANCE_H__*/
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "platform/time.hpp"
|
|
||||||
|
|
||||||
class Performance
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static StopwatchHandler watches;
|
|
||||||
};
|
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "SharedConstants.hpp"
|
#include "SharedConstants.h"
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_SharedConstants_H__
|
||||||
|
#define NET_MINECRAFT_SharedConstants_H__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -30,3 +31,4 @@ namespace SharedConstants
|
|||||||
//int FULLBRIGHT_LIGHTVALUE = 15 << 20 | 15 << 4;
|
//int FULLBRIGHT_LIGHTVALUE = 15 << 20 | 15 << 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_SharedConstants_H__*/
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "IConfigListener.hpp"
|
#include "IConfigListener.h"
|
||||||
#include "Minecraft.hpp"
|
#include "Minecraft.h"
|
||||||
#ifndef STANDALONE_SERVER
|
#ifndef STANDALONE_SERVER
|
||||||
#include "gui/Gui.hpp"
|
#include "gui/Gui.h"
|
||||||
#endif /* STANDALONE_SERVER */
|
#endif /* STANDALONE_SERVER */
|
||||||
Config createConfig(Minecraft* mc) {
|
Config createConfig(Minecraft* mc) {
|
||||||
Config c;
|
Config c;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#ifndef CONFIGLISTENER_H__
|
||||||
|
#define CONFIGLISTENER_H__
|
||||||
|
|
||||||
#include "PixelCalc.hpp"
|
#include "PixelCalc.h"
|
||||||
class Minecraft;
|
class Minecraft;
|
||||||
class Options;
|
class Options;
|
||||||
|
|
||||||
@@ -44,3 +45,4 @@ public:
|
|||||||
virtual void onConfigChanged(const Config& config) = 0;
|
virtual void onConfigChanged(const Config& config) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*CONFIGLISTENER_H__*/
|
||||||
1303
src/MinecraftClient.cpp → src/client/Minecraft.cpp
Normal file → Executable file
1303
src/MinecraftClient.cpp → src/client/Minecraft.cpp
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
232
src/client/Minecraft.h
Executable file
232
src/client/Minecraft.h
Executable file
@@ -0,0 +1,232 @@
|
|||||||
|
#ifndef NET_MINECRAFT_CLIENT__Minecraft_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT__Minecraft_H__
|
||||||
|
|
||||||
|
#include "Options.h"
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
#include "MouseHandler.h"
|
||||||
|
#include "gui/Gui.h"
|
||||||
|
#include "gui/screens/ScreenChooser.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "Timer.h"
|
||||||
|
|
||||||
|
//#include "../network/RakNetInstance.h"
|
||||||
|
#include "../world/phys/HitResult.h"
|
||||||
|
|
||||||
|
class Level;
|
||||||
|
class LocalPlayer;
|
||||||
|
class IInputHolder;
|
||||||
|
class Mob;
|
||||||
|
class Player;
|
||||||
|
class LevelRenderer;
|
||||||
|
class GameRenderer;
|
||||||
|
class ParticleEngine;
|
||||||
|
class Entity;
|
||||||
|
class ICreator;
|
||||||
|
class GameMode;
|
||||||
|
class Textures;
|
||||||
|
class CThread;
|
||||||
|
class SoundEngine;
|
||||||
|
class Screen;
|
||||||
|
class Font;
|
||||||
|
class LevelStorageSource;
|
||||||
|
class BuildActionIntention;
|
||||||
|
class PerfRenderer;
|
||||||
|
class LevelSettings;
|
||||||
|
class IRakNetInstance;
|
||||||
|
class NetEventCallback;
|
||||||
|
class CommandServer;
|
||||||
|
struct PingedCompatibleServer;
|
||||||
|
//class ExternalFileLevelStorageSource;
|
||||||
|
|
||||||
|
|
||||||
|
#include "../App.h"
|
||||||
|
#include "PixelCalc.h"
|
||||||
|
class AppPlatform;
|
||||||
|
class AppPlatform_android;
|
||||||
|
|
||||||
|
class Minecraft: public App
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
Minecraft();
|
||||||
|
public:
|
||||||
|
virtual ~Minecraft();
|
||||||
|
|
||||||
|
void init();
|
||||||
|
void setSize(int width, int height);
|
||||||
|
void reloadOptions();
|
||||||
|
|
||||||
|
bool supportNonTouchScreen();
|
||||||
|
bool useTouchscreen();
|
||||||
|
void grabMouse();
|
||||||
|
void releaseMouse();
|
||||||
|
|
||||||
|
void handleBuildAction(BuildActionIntention*);
|
||||||
|
|
||||||
|
void toggleDimension(){}
|
||||||
|
bool isCreativeMode();
|
||||||
|
void setIsCreativeMode(bool isCreative);
|
||||||
|
void setScreen(Screen*);
|
||||||
|
|
||||||
|
virtual void selectLevel(const std::string& levelId, const std::string& levelName, const LevelSettings& settings);
|
||||||
|
virtual void setLevel(Level* level, const std::string& message = "", LocalPlayer* forceInsertPlayer = NULL);
|
||||||
|
|
||||||
|
void generateLevel( const std::string& message, Level* level );
|
||||||
|
LevelStorageSource* getLevelSource();
|
||||||
|
|
||||||
|
bool isLookingForMultiplayer;
|
||||||
|
void locateMultiplayer();
|
||||||
|
void cancelLocateMultiplayer();
|
||||||
|
bool joinMultiplayer(const PingedCompatibleServer& server);
|
||||||
|
bool joinMultiplayerFromString(const std::string& server);
|
||||||
|
void hostMultiplayer(int port=19132);
|
||||||
|
Player* respawnPlayer(int playerId);
|
||||||
|
void respawnPlayer();
|
||||||
|
void resetPlayer(Player* player);
|
||||||
|
void doActuallyRespawnPlayer();
|
||||||
|
|
||||||
|
void update();
|
||||||
|
|
||||||
|
void tick(int nTick, int maxTick);
|
||||||
|
void tickInput();
|
||||||
|
|
||||||
|
bool isOnlineClient();
|
||||||
|
bool isOnline();
|
||||||
|
void pauseGame(bool isBackPaused);
|
||||||
|
void gameLostFocus();
|
||||||
|
|
||||||
|
void prepareLevel(const std::string& message);
|
||||||
|
|
||||||
|
void leaveGame(bool renameLevel = false);
|
||||||
|
|
||||||
|
int getProgressStatusId();
|
||||||
|
const char* getProgressMessage();
|
||||||
|
|
||||||
|
ICreator* getCreator();
|
||||||
|
|
||||||
|
// void onGraphicsLost() {}
|
||||||
|
void onGraphicsReset();
|
||||||
|
|
||||||
|
bool isLevelGenerated();
|
||||||
|
|
||||||
|
void handleMouseDown(int button, bool down);
|
||||||
|
|
||||||
|
void audioEngineOn();
|
||||||
|
void audioEngineOff();
|
||||||
|
|
||||||
|
bool isPowerVR() { return _powerVr; }
|
||||||
|
bool isKindleFire(int kindleVersion);
|
||||||
|
bool transformResolution(int* w, int* h);
|
||||||
|
void optionUpdated(OptionId option, bool value);
|
||||||
|
void optionUpdated(OptionId option, float value);
|
||||||
|
void optionUpdated(OptionId option, int value);
|
||||||
|
|
||||||
|
int getTicks() { return ticks; }
|
||||||
|
#ifdef __APPLE__
|
||||||
|
bool _isSuperFast;
|
||||||
|
bool isSuperFast() { return _isSuperFast; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void _levelGenerated();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void* prepareLevel_tspawn(void *p_param);
|
||||||
|
|
||||||
|
void _reloadInput();
|
||||||
|
public:
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
|
||||||
|
// Vars that the platform is allowed to use in the future
|
||||||
|
int commandPort;
|
||||||
|
int reserved_d1, reserved_d2;
|
||||||
|
float reserved_f1, reserved_f2;
|
||||||
|
|
||||||
|
Options options;
|
||||||
|
|
||||||
|
static bool useAmbientOcclusion;
|
||||||
|
//static bool threadInterrupt;
|
||||||
|
|
||||||
|
volatile bool pause;
|
||||||
|
|
||||||
|
LevelRenderer* levelRenderer;
|
||||||
|
GameRenderer* gameRenderer;
|
||||||
|
ParticleEngine* particleEngine;
|
||||||
|
SoundEngine* soundEngine;
|
||||||
|
|
||||||
|
GameMode* gameMode;
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
Textures* textures;
|
||||||
|
ScreenChooser screenChooser;
|
||||||
|
Font* font;
|
||||||
|
#endif
|
||||||
|
IRakNetInstance* raknetInstance;
|
||||||
|
NetEventCallback* netCallback;
|
||||||
|
|
||||||
|
int lastTime;
|
||||||
|
int lastTickTime;
|
||||||
|
float ticksSinceLastUpdate;
|
||||||
|
|
||||||
|
Level* level;
|
||||||
|
|
||||||
|
LocalPlayer* player;
|
||||||
|
IInputHolder* inputHolder;
|
||||||
|
Mob* cameraTargetPlayer;
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
Gui gui;
|
||||||
|
#endif
|
||||||
|
CThread* generateLevelThread;
|
||||||
|
Screen* screen;
|
||||||
|
static int customDebugId;
|
||||||
|
|
||||||
|
static const int CDI_NONE = 0;
|
||||||
|
static const int CDI_GRAPHICS = 1;
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
MouseHandler mouseHandler;
|
||||||
|
#endif
|
||||||
|
bool mouseGrabbed;
|
||||||
|
|
||||||
|
PixelCalc pixelCalc;
|
||||||
|
PixelCalc pixelCalcUi;
|
||||||
|
|
||||||
|
HitResult hitResult;
|
||||||
|
volatile int progressStagePercentage;
|
||||||
|
|
||||||
|
// This field is initialized in main()
|
||||||
|
// It sets the base path to where worlds can be written (sdcard on android)
|
||||||
|
std::string externalStoragePath;
|
||||||
|
std::string externalCacheStoragePath;
|
||||||
|
protected:
|
||||||
|
Timer timer;
|
||||||
|
|
||||||
|
// @note @attn @warn: this is dangerous as fuck!
|
||||||
|
volatile bool isGeneratingLevel;
|
||||||
|
bool _hasSignaledGeneratingLevelFinished;
|
||||||
|
|
||||||
|
LevelStorageSource* storageSource;
|
||||||
|
bool _running;
|
||||||
|
bool _powerVr;
|
||||||
|
|
||||||
|
private:
|
||||||
|
volatile int progressStageStatusId;
|
||||||
|
static const char* progressMessages[];
|
||||||
|
|
||||||
|
int missTime;
|
||||||
|
int ticks;
|
||||||
|
bool screenMutex;
|
||||||
|
bool hasScheduledScreen;
|
||||||
|
Screen* scheduledScreen;
|
||||||
|
|
||||||
|
int _licenseId;
|
||||||
|
bool _supportsNonTouchscreen;
|
||||||
|
|
||||||
|
bool _isCreativeMode;
|
||||||
|
//int _respawnPlayerTicks;
|
||||||
|
Player* _pendingRemovePlayer; // @attn @todo @fix: remove this shait and fix the respawn behaviour
|
||||||
|
|
||||||
|
PerfRenderer* _perfRenderer;
|
||||||
|
CommandServer* _commandServer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT__Minecraft_H__*/
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "MouseHandler.hpp"
|
#include "MouseHandler.h"
|
||||||
#include "player/input/ITurnInput.hpp"
|
#include "player/input/ITurnInput.h"
|
||||||
|
|
||||||
#ifdef RPI
|
#ifdef RPI
|
||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT__MouseHandler_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT__MouseHandler_H__
|
||||||
|
|
||||||
//package net.minecraft.client;
|
//package net.minecraft.client;
|
||||||
|
|
||||||
@@ -24,3 +25,4 @@ private:
|
|||||||
ITurnInput* _turnInput;
|
ITurnInput* _turnInput;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT__MouseHandler_H__*/
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "Option.hpp"
|
#include "Option.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <util/Mth.hpp>
|
#include <util/Mth.h>
|
||||||
/*
|
/*
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct is_option_type : std::false_type {};
|
struct is_option_type : std::false_type {};
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "OptionStrings.hpp"
|
#include "OptionStrings.h"
|
||||||
|
|
||||||
const char* OptionStrings::Multiplayer_Username = "mp_username";
|
const char* OptionStrings::Multiplayer_Username = "mp_username";
|
||||||
const char* OptionStrings::Multiplayer_ServerVisible = "mp_server_visible_default";
|
const char* OptionStrings::Multiplayer_ServerVisible = "mp_server_visible_default";
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT__OptionStrings_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT__OptionStrings_H__
|
||||||
|
|
||||||
class OptionStrings {
|
class OptionStrings {
|
||||||
public:
|
public:
|
||||||
@@ -32,3 +33,4 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT__OptionsStrings_H__*/
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
#include "Options.hpp"
|
#include "Options.h"
|
||||||
#include "world/Difficulty.hpp"
|
#include "OptionStrings.h"
|
||||||
#include <MinecraftClient.hpp>
|
#include "Minecraft.h"
|
||||||
|
#include "../platform/log.h"
|
||||||
|
#include "../world/Difficulty.h"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
bool Options::debugGl = false;
|
bool Options::debugGl = false;
|
||||||
|
|
||||||
@@ -285,13 +290,13 @@ void Options::setOptionsFilePath(const std::string& path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Options::notifyOptionUpdate(OptionId key, bool value) {
|
void Options::notifyOptionUpdate(OptionId key, bool value) {
|
||||||
minecraft.optionUpdated(key, value);
|
minecraft->optionUpdated(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Options::notifyOptionUpdate(OptionId key, float value) {
|
void Options::notifyOptionUpdate(OptionId key, float value) {
|
||||||
minecraft.optionUpdated(key, value);
|
minecraft->optionUpdated(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Options::notifyOptionUpdate(OptionId key, int value) {
|
void Options::notifyOptionUpdate(OptionId key, int value) {
|
||||||
minecraft.optionUpdated(key, value);
|
minecraft->optionUpdated(key, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT__Options_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT__Options_H__
|
||||||
|
|
||||||
#define SOUND_MIN_VALUE 0.0f
|
#define SOUND_MIN_VALUE 0.0f
|
||||||
#define SOUND_MAX_VALUE 1.0f
|
#define SOUND_MAX_VALUE 1.0f
|
||||||
@@ -11,13 +12,14 @@
|
|||||||
|
|
||||||
//package net.minecraft.client;
|
//package net.minecraft.client;
|
||||||
|
|
||||||
//#include "locale/Language.hpp"
|
//#include "locale/Language.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <platform/input/Keyboard.hpp>
|
#include <cstdio>
|
||||||
#include <util/StringUtils.hpp>
|
#include "../platform/input/Keyboard.h"
|
||||||
#include "OptionsFile.hpp"
|
#include "../util/StringUtils.h"
|
||||||
#include "Option.hpp"
|
#include "OptionsFile.h"
|
||||||
|
#include "Option.h"
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
enum OptionId {
|
enum OptionId {
|
||||||
@@ -86,7 +88,7 @@ enum OptionId {
|
|||||||
OPTIONS_COUNT
|
OPTIONS_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
class MinecraftClient;
|
class Minecraft;
|
||||||
typedef std::vector<std::string> StringVector;
|
typedef std::vector<std::string> StringVector;
|
||||||
|
|
||||||
class Options
|
class Options
|
||||||
@@ -94,7 +96,7 @@ class Options
|
|||||||
public:
|
public:
|
||||||
static bool debugGl;
|
static bool debugGl;
|
||||||
|
|
||||||
Options(MinecraftClient& minecraft, const std::string& workingDirectory = "")
|
Options(Minecraft* minecraft, const std::string& workingDirectory = "")
|
||||||
: minecraft(minecraft) {
|
: minecraft(minecraft) {
|
||||||
// elements werent initialized so i was getting a garbage pointer and a crash
|
// elements werent initialized so i was getting a garbage pointer and a crash
|
||||||
m_options.fill(nullptr);
|
m_options.fill(nullptr);
|
||||||
@@ -159,6 +161,7 @@ private:
|
|||||||
std::array<Option*, OPTIONS_COUNT> m_options;
|
std::array<Option*, OPTIONS_COUNT> m_options;
|
||||||
OptionsFile optionsFile;
|
OptionsFile optionsFile;
|
||||||
|
|
||||||
MinecraftClient& minecraft;
|
Minecraft* minecraft;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT__Options_H__*/
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "OptionsFile.hpp"
|
#include "OptionsFile.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <platform/log.hpp>
|
#include <platform/log.h>
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT__OptionsFile_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT__OptionsFile_H__
|
||||||
|
|
||||||
//package net.minecraft.client;
|
//package net.minecraft.client;
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -17,3 +18,4 @@ private:
|
|||||||
std::string settingsPath;
|
std::string settingsPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /* NET_MINECRAFT_CLIENT__OptionsFile_H__ */
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT__Timer_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT__Timer_H__
|
||||||
|
|
||||||
//package net.minecraft.client;
|
//package net.minecraft.client;
|
||||||
#include "platform/time.hpp"
|
#include "../platform/time.h"
|
||||||
|
|
||||||
class Timer
|
class Timer
|
||||||
{
|
{
|
||||||
@@ -120,3 +121,4 @@ private:
|
|||||||
float adjustTime;
|
float adjustTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT__Timer_H__*/
|
||||||
56
src/client/gamemode/CreativeMode.cpp
Executable file
56
src/client/gamemode/CreativeMode.cpp
Executable file
@@ -0,0 +1,56 @@
|
|||||||
|
#include "CreativeMode.h"
|
||||||
|
#include "../Minecraft.h"
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
#include "../particle/ParticleEngine.h"
|
||||||
|
#endif
|
||||||
|
#include "../player/LocalPlayer.h"
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
#include "../renderer/LevelRenderer.h"
|
||||||
|
#include "../sound/SoundEngine.h"
|
||||||
|
#endif
|
||||||
|
#include "../../world/level/Level.h"
|
||||||
|
//#include "../../network/Packet.h"
|
||||||
|
#include "../../network/packet/RemoveBlockPacket.h"
|
||||||
|
#include "../../world/entity/player/Abilities.h"
|
||||||
|
|
||||||
|
static const int DestructionTickDelay = 5;
|
||||||
|
|
||||||
|
CreativeMode::CreativeMode(Minecraft* minecraft)
|
||||||
|
: super(minecraft)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreativeMode::startDestroyBlock(int x, int y, int z, int face) {
|
||||||
|
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
|
||||||
|
return;
|
||||||
|
|
||||||
|
creativeDestroyBlock(x, y, z, face);
|
||||||
|
destroyDelay = DestructionTickDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreativeMode::creativeDestroyBlock(int x, int y, int z, int face) {
|
||||||
|
minecraft->level->extinguishFire(x, y, z, face);
|
||||||
|
destroyBlock(x, y, z, face);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreativeMode::continueDestroyBlock(int x, int y, int z, int face) {
|
||||||
|
destroyDelay--;
|
||||||
|
if (destroyDelay <= 0) {
|
||||||
|
destroyDelay = DestructionTickDelay;
|
||||||
|
creativeDestroyBlock(x, y, z, face);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreativeMode::stopDestroyBlock() {
|
||||||
|
destroyDelay = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreativeMode::initAbilities( Abilities& abilities ) {
|
||||||
|
abilities.mayfly = true;
|
||||||
|
abilities.instabuild = true;
|
||||||
|
abilities.invulnerable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CreativeMode::isCreativeType() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
26
src/client/gamemode/CreativeMode.h
Executable file
26
src/client/gamemode/CreativeMode.h
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__
|
||||||
|
|
||||||
|
//package net.minecraft.client.gamemode;
|
||||||
|
|
||||||
|
#include "GameMode.h"
|
||||||
|
|
||||||
|
class CreativeMode: public GameMode
|
||||||
|
{
|
||||||
|
typedef GameMode super;
|
||||||
|
public:
|
||||||
|
CreativeMode(Minecraft* minecraft);
|
||||||
|
|
||||||
|
void startDestroyBlock(int x, int y, int z, int face);
|
||||||
|
void continueDestroyBlock(int x, int y, int z, int face);
|
||||||
|
void stopDestroyBlock();
|
||||||
|
|
||||||
|
bool isCreativeType();
|
||||||
|
|
||||||
|
void initAbilities(Abilities& abilities);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void creativeDestroyBlock(int x, int y, int z, int face);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__CreativeMode_H__*/
|
||||||
102
src/client/gamemode/CreatorMode.cpp
Executable file
102
src/client/gamemode/CreatorMode.cpp
Executable file
@@ -0,0 +1,102 @@
|
|||||||
|
#include "CreatorMode.h"
|
||||||
|
#include "../Minecraft.h"
|
||||||
|
#include "../particle/ParticleEngine.h"
|
||||||
|
#include "../player/LocalPlayer.h"
|
||||||
|
#include "../renderer/LevelRenderer.h"
|
||||||
|
#include "../sound/SoundEngine.h"
|
||||||
|
#include "../../world/level/Level.h"
|
||||||
|
//#include "../../network/Packet.h"
|
||||||
|
#include "../../network/packet/RemoveBlockPacket.h"
|
||||||
|
#include "../../world/entity/player/Abilities.h"
|
||||||
|
|
||||||
|
static const int DestructionTickDelay = 5;
|
||||||
|
|
||||||
|
class Creator: public ICreator {
|
||||||
|
//virtual void getEvents();
|
||||||
|
|
||||||
|
public:
|
||||||
|
Creator(/*int eventLifeTime*/)
|
||||||
|
: _tileEvents(32),
|
||||||
|
_tickId(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTick(int tick) {
|
||||||
|
_tickId = tick;
|
||||||
|
}
|
||||||
|
|
||||||
|
EventList<TileEvent>& getTileEvents() { return _tileEvents; }
|
||||||
|
|
||||||
|
void addevent_blockUse(int entityId, int x, int y, int z, int face) {
|
||||||
|
TileEvent t = {
|
||||||
|
entityId,
|
||||||
|
x,y,z,
|
||||||
|
face
|
||||||
|
};
|
||||||
|
_tileEvents.add(t, _tickId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
EventList<TileEvent> _tileEvents;
|
||||||
|
int _tickId;
|
||||||
|
};
|
||||||
|
|
||||||
|
CreatorMode::CreatorMode(Minecraft* minecraft)
|
||||||
|
: super(minecraft)
|
||||||
|
{
|
||||||
|
_creator = new Creator();
|
||||||
|
}
|
||||||
|
|
||||||
|
CreatorMode::~CreatorMode() {
|
||||||
|
delete _creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreatorMode::startDestroyBlock(int x, int y, int z, int face) {
|
||||||
|
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CreatorDestroyBlock(x, y, z, face);
|
||||||
|
destroyDelay = DestructionTickDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreatorMode::CreatorDestroyBlock(int x, int y, int z, int face) {
|
||||||
|
minecraft->level->extinguishFire(x, y, z, face);
|
||||||
|
destroyBlock(x, y, z, face);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreatorMode::continueDestroyBlock(int x, int y, int z, int face) {
|
||||||
|
destroyDelay--;
|
||||||
|
if (destroyDelay <= 0) {
|
||||||
|
destroyDelay = DestructionTickDelay;
|
||||||
|
CreatorDestroyBlock(x, y, z, face);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CreatorMode::useItemOn( Player* player, Level* level, ItemInstance* item, int x, int y, int z, int face, const Vec3& hit ) {
|
||||||
|
if (item && item->id == ((Item*)Item::sword_iron)->id)
|
||||||
|
_creator->addevent_blockUse(player->entityId, x, y, z, face);
|
||||||
|
return super::useItemOn(player, level, item, x, y, z, face, hit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreatorMode::stopDestroyBlock() {
|
||||||
|
destroyDelay = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreatorMode::initAbilities( Abilities& abilities ) {
|
||||||
|
abilities.mayfly = true;
|
||||||
|
abilities.instabuild = true;
|
||||||
|
abilities.invulnerable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CreatorMode::isCreativeType() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ICreator* CreatorMode::getCreator() {
|
||||||
|
return _creator;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreatorMode::tick() {
|
||||||
|
_creator->setTick(minecraft->level->getTime());
|
||||||
|
super::tick();
|
||||||
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GAMEMODE__CreatorMode_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GAMEMODE__CreatorMode_H__
|
||||||
|
|
||||||
//package net.minecraft.client.gamemode;
|
//package net.minecraft.client.gamemode;
|
||||||
|
|
||||||
#include "GameMode.hpp"
|
#include "GameMode.h"
|
||||||
#include <world/PosTranslator.hpp>
|
#include "../../world/PosTranslator.h"
|
||||||
|
|
||||||
class ICreator {
|
class ICreator {
|
||||||
public:
|
public:
|
||||||
@@ -101,12 +102,12 @@ class CreatorMode: public GameMode
|
|||||||
{
|
{
|
||||||
typedef GameMode super;
|
typedef GameMode super;
|
||||||
public:
|
public:
|
||||||
CreatorMode(Minecraft& minecraft);
|
CreatorMode(Minecraft* minecraft);
|
||||||
~CreatorMode();
|
~CreatorMode();
|
||||||
|
|
||||||
void startDestroyBlock(Player* player, int x, int y, int z, int face);
|
void startDestroyBlock(int x, int y, int z, int face);
|
||||||
void continueDestroyBlock(Player* player, int x, int y, int z, int face);
|
void continueDestroyBlock(int x, int y, int z, int face);
|
||||||
void stopDestroyBlock(Player* player);
|
void stopDestroyBlock();
|
||||||
|
|
||||||
bool useItemOn(Player* player, Level* level, ItemInstance* item, int x, int y, int z, int face, const Vec3& hit);
|
bool useItemOn(Player* player, Level* level, ItemInstance* item, int x, int y, int z, int face, const Vec3& hit);
|
||||||
|
|
||||||
@@ -117,10 +118,10 @@ public:
|
|||||||
|
|
||||||
void initAbilities(Abilities& abilities);
|
void initAbilities(Abilities& abilities);
|
||||||
|
|
||||||
void releaseUsingItem(Player* player);
|
|
||||||
private:
|
private:
|
||||||
void CreatorDestroyBlock(Player* player, int x, int y, int z, int face);
|
void CreatorDestroyBlock(int x, int y, int z, int face);
|
||||||
|
|
||||||
Creator* _creator;
|
Creator* _creator;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__CreatorMode_H__*/
|
||||||
@@ -1,15 +1,35 @@
|
|||||||
#include "GameMode.hpp"
|
#include "GameMode.h"
|
||||||
#include <Minecraft.hpp>
|
#include "../Minecraft.h"
|
||||||
#include <network/packet/UseItemPacket.hpp>
|
#include "../../network/packet/UseItemPacket.h"
|
||||||
#include <network/packet/PlayerActionPacket.hpp>
|
#include "../../network/packet/PlayerActionPacket.h"
|
||||||
#include <world/level/Level.hpp>
|
#include "../../world/level/Level.h"
|
||||||
#include <world/item/ItemInstance.hpp>
|
#include "../../world/item/ItemInstance.h"
|
||||||
#include <client/player/LocalPlayer.hpp>
|
#include "../player/LocalPlayer.h"
|
||||||
#include <client/Options.hpp>
|
#include "client/Options.h"
|
||||||
#include <network/RakNetInstance.hpp>
|
#ifndef STANDALONE_SERVER
|
||||||
#include <network/packet/RemoveBlockPacket.hpp>
|
#include "../sound/SoundEngine.h"
|
||||||
#include <world/level/material/Material.hpp>
|
#include "../particle/ParticleEngine.h"
|
||||||
|
#endif
|
||||||
|
#include "../../network/RakNetInstance.h"
|
||||||
|
#include "../../network/packet/RemoveBlockPacket.h"
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
#include "../renderer/LevelRenderer.h"
|
||||||
|
#endif
|
||||||
|
#include "../../world/level/material/Material.h"
|
||||||
|
|
||||||
|
GameMode::GameMode( Minecraft* minecraft)
|
||||||
|
: minecraft(minecraft),
|
||||||
|
destroyProgress(0),
|
||||||
|
oDestroyProgress(0),
|
||||||
|
destroyTicks(0),
|
||||||
|
destroyDelay(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*virtual*/
|
||||||
|
Player* GameMode::createPlayer(Level* level) {
|
||||||
|
return new LocalPlayer(minecraft, level, minecraft->options.getStringValue(OPTIONS_USERNAME), level->dimension->id, isCreativeType());
|
||||||
|
}
|
||||||
|
|
||||||
/*virtual*/
|
/*virtual*/
|
||||||
void GameMode::interact(Player* player, Entity* entity) {
|
void GameMode::interact(Player* player, Entity* entity) {
|
||||||
@@ -18,24 +38,23 @@ void GameMode::interact(Player* player, Entity* entity) {
|
|||||||
|
|
||||||
/*virtual*/
|
/*virtual*/
|
||||||
void GameMode::attack(Player* player, Entity* entity) {
|
void GameMode::attack(Player* player, Entity* entity) {
|
||||||
if (minecraft.level->adventureSettings.noPvP && entity->isPlayer())
|
if (minecraft->level->adventureSettings.noPvP && entity->isPlayer())
|
||||||
return;
|
return;
|
||||||
if (minecraft.level->adventureSettings.noPvM && entity->isMob())
|
if (minecraft->level->adventureSettings.noPvM && entity->isMob())
|
||||||
return;
|
return;
|
||||||
player->attack(entity);
|
player->attack(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */
|
/* virtual */
|
||||||
void GameMode::startDestroyBlock(Player* player, int x, int y, int z, int face ) {
|
void GameMode::startDestroyBlock( int x, int y, int z, int face ) {
|
||||||
if(player->getCarriedItem() != NULL && player->getCarriedItem()->id == Item::bow->id)
|
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
|
||||||
return;
|
return;
|
||||||
|
destroyBlock(x, y, z, face);
|
||||||
destroyBlock(player, x, y, z, face);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*virtual*/
|
/*virtual*/
|
||||||
bool GameMode::destroyBlock(Player* player, int x, int y, int z, int face) {
|
bool GameMode::destroyBlock(int x, int y, int z, int face) {
|
||||||
Level* level = minecraft.level;
|
Level* level = minecraft->level;
|
||||||
Tile* oldTile = Tile::tiles[level->getTile(x, y, z)];
|
Tile* oldTile = Tile::tiles[level->getTile(x, y, z)];
|
||||||
if (!oldTile)
|
if (!oldTile)
|
||||||
return false;
|
return false;
|
||||||
@@ -46,12 +65,22 @@ bool GameMode::destroyBlock(Player* player, int x, int y, int z, int face) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
minecraft->particleEngine->destroy(x, y, z);
|
||||||
|
#endif
|
||||||
int data = level->getData(x, y, z);
|
int data = level->getData(x, y, z);
|
||||||
bool changed = level->setTile(x, y, z, 0);
|
bool changed = level->setTile(x, y, z, 0);
|
||||||
if (changed) {
|
if (changed) {
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
minecraft->soundEngine->play(oldTile->soundType->getBreakSound(), x + 0.5f, y + 0.5f, z + 0.5f, (oldTile->soundType->getVolume() + 1) / 2, oldTile->soundType->getPitch() * 0.8f);
|
||||||
|
#endif
|
||||||
oldTile->destroy(level, x, y, z, data);
|
oldTile->destroy(level, x, y, z, data);
|
||||||
minecraft.onBlockDestroyed(player, x, y, z, face);
|
if (minecraft->options.getBooleanValue(OPTIONS_DESTROY_VIBRATION)) minecraft->platform()->vibrate(24);
|
||||||
|
|
||||||
|
if (minecraft->isOnline()) {
|
||||||
|
RemoveBlockPacket packet(minecraft->player, x, y, z);
|
||||||
|
minecraft->raknetInstance->send(packet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
@@ -60,10 +89,10 @@ bool GameMode::useItemOn(Player* player, Level* level, ItemInstance* item, int x
|
|||||||
float clickX = hit.x - x;
|
float clickX = hit.x - x;
|
||||||
float clickY = hit.y - y;
|
float clickY = hit.y - y;
|
||||||
float clickZ = hit.z - z;
|
float clickZ = hit.z - z;
|
||||||
item = player->inventory->getSelected();
|
if (level->isClientSide) {
|
||||||
if(level->isClientSide) {
|
item = player->inventory->getSelected();
|
||||||
UseItemPacket packet(x, y, z, face, item, player->entityId, clickX, clickY, clickZ);
|
UseItemPacket packet(x, y, z, face, item, player->entityId, clickX, clickY, clickZ);
|
||||||
minecraft.raknetInstance->send(packet);
|
minecraft->raknetInstance->send(packet);
|
||||||
}
|
}
|
||||||
int t = level->getTile(x, y, z);
|
int t = level->getTile(x, y, z);
|
||||||
if (t == Tile::invisible_bedrock->id) return false;
|
if (t == Tile::invisible_bedrock->id) return false;
|
||||||
@@ -89,7 +118,7 @@ bool GameMode::useItem( Player* player, Level* level, ItemInstance* item ) {
|
|||||||
ItemInstance* itemInstance = item->use(level, player);
|
ItemInstance* itemInstance = item->use(level, player);
|
||||||
if(level->isClientSide) {
|
if(level->isClientSide) {
|
||||||
UseItemPacket packet(item, player->entityId, player->aimDirection);
|
UseItemPacket packet(item, player->entityId, player->aimDirection);
|
||||||
minecraft.raknetInstance->send(packet);
|
minecraft->raknetInstance->send(packet);
|
||||||
}
|
}
|
||||||
if (itemInstance != item || (itemInstance != NULL && itemInstance->count != oldCount)) {
|
if (itemInstance != item || (itemInstance != NULL && itemInstance->count != oldCount)) {
|
||||||
//player.inventory.items[player.inventory.selected] = itemInstance;
|
//player.inventory.items[player.inventory.selected] = itemInstance;
|
||||||
@@ -120,9 +149,9 @@ void GameMode::initPlayer( Player* player ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GameMode::releaseUsingItem(Player* player){
|
void GameMode::releaseUsingItem(Player* player){
|
||||||
if(minecraft.level->isClientSide) {
|
if (minecraft->level->isClientSide && player->isUsingItem()) {
|
||||||
PlayerActionPacket packet(PlayerActionPacket::RELEASE_USE_ITEM, 0, 0, 0, 0, player->entityId);
|
PlayerActionPacket packet(PlayerActionPacket::RELEASE_USE_ITEM, 0, 0, 0, 0, player->entityId);
|
||||||
minecraft.raknetInstance->send(packet);
|
minecraft->raknetInstance->send(packet);
|
||||||
}
|
}
|
||||||
player->releaseUsingItem();
|
player->releaseUsingItem();
|
||||||
}
|
}
|
||||||
@@ -131,3 +160,15 @@ void GameMode::tick() {
|
|||||||
oDestroyProgress = destroyProgress;
|
oDestroyProgress = destroyProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameMode::render( float a ) {
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
if (destroyProgress <= 0) {
|
||||||
|
minecraft->gui.progress = 0;
|
||||||
|
minecraft->levelRenderer->destroyProgress = 0;
|
||||||
|
} else {
|
||||||
|
float dp = oDestroyProgress + (destroyProgress - oDestroyProgress) * a;
|
||||||
|
minecraft->gui.progress = dp;
|
||||||
|
minecraft->levelRenderer->destroyProgress = dp;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GAMEMODE__GameMode_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GAMEMODE__GameMode_H__
|
||||||
|
|
||||||
//package net.minecraft.client.gamemode;
|
//package net.minecraft.client.gamemode;
|
||||||
|
|
||||||
#include <world/level/tile/Tile.hpp>
|
#include "../../world/level/tile/Tile.h"
|
||||||
|
|
||||||
class ItemInstance;
|
class ItemInstance;
|
||||||
class Minecraft;
|
class Minecraft;
|
||||||
@@ -10,22 +11,23 @@ class Level;
|
|||||||
class Player;
|
class Player;
|
||||||
class Abilities;
|
class Abilities;
|
||||||
|
|
||||||
class GameMode {
|
class GameMode
|
||||||
|
{
|
||||||
protected:
|
protected:
|
||||||
Minecraft& minecraft;
|
Minecraft* minecraft;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GameMode(Minecraft& minecraft) : minecraft(minecraft) {}
|
GameMode(Minecraft* minecraft);
|
||||||
virtual ~GameMode() {}
|
virtual ~GameMode() {}
|
||||||
|
|
||||||
virtual void initLevel(Level* level) {}
|
virtual void initLevel(Level* level) {}
|
||||||
|
|
||||||
virtual void startDestroyBlock(Player* player, int x, int y, int z, int face);
|
virtual void startDestroyBlock(int x, int y, int z, int face);
|
||||||
virtual bool destroyBlock(Player* player, int x, int y, int z, int face);
|
virtual bool destroyBlock(int x, int y, int z, int face);
|
||||||
virtual void continueDestroyBlock(Player* player, int x, int y, int z, int face) = 0;
|
virtual void continueDestroyBlock(int x, int y, int z, int face) = 0;
|
||||||
virtual void stopDestroyBlock(Player* player) {}
|
virtual void stopDestroyBlock() {}
|
||||||
|
|
||||||
virtual void tick();
|
virtual void tick();
|
||||||
|
virtual void render(float a);
|
||||||
|
|
||||||
virtual float getPickRange();
|
virtual float getPickRange();
|
||||||
/* void postLevelGen(LevelGen levelGen, Level level) {} */
|
/* void postLevelGen(LevelGen levelGen, Level level) {} */
|
||||||
@@ -33,6 +35,7 @@ public:
|
|||||||
virtual bool useItem(Player* player, Level* level, ItemInstance* item);
|
virtual bool useItem(Player* player, Level* level, ItemInstance* item);
|
||||||
virtual bool useItemOn(Player* player, Level* level, ItemInstance* item, int x, int y, int z, int face, const Vec3& hit);
|
virtual bool useItemOn(Player* player, Level* level, ItemInstance* item, int x, int y, int z, int face, const Vec3& hit);
|
||||||
|
|
||||||
|
virtual Player* createPlayer(Level* level);
|
||||||
virtual void initPlayer(Player* player);
|
virtual void initPlayer(Player* player);
|
||||||
virtual void adjustPlayer(Player* player) {}
|
virtual void adjustPlayer(Player* player) {}
|
||||||
virtual bool canHurtPlayer() { return false; }
|
virtual bool canHurtPlayer() { return false; }
|
||||||
@@ -50,10 +53,11 @@ public:
|
|||||||
|
|
||||||
virtual void releaseUsingItem(Player* player);
|
virtual void releaseUsingItem(Player* player);
|
||||||
|
|
||||||
float oDestroyProgress = 0;
|
float oDestroyProgress;
|
||||||
float destroyProgress = 0;
|
float destroyProgress;
|
||||||
protected:
|
protected:
|
||||||
int destroyTicks = 0;
|
int destroyTicks;
|
||||||
int destroyDelay = 0;
|
int destroyDelay;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__GameMode_H__*/
|
||||||
99
src/client/gamemode/SurvivalMode.cpp
Executable file
99
src/client/gamemode/SurvivalMode.cpp
Executable file
@@ -0,0 +1,99 @@
|
|||||||
|
#include "SurvivalMode.h"
|
||||||
|
#include "../Minecraft.h"
|
||||||
|
#include "../player/LocalPlayer.h"
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
#include "../particle/ParticleEngine.h"
|
||||||
|
#include "../sound/SoundEngine.h"
|
||||||
|
#endif
|
||||||
|
#include "../../world/level/Level.h"
|
||||||
|
#include "../../world/entity/player/Abilities.h"
|
||||||
|
|
||||||
|
SurvivalMode::SurvivalMode( Minecraft* minecraft )
|
||||||
|
: super(minecraft),
|
||||||
|
xDestroyBlock(-1),
|
||||||
|
yDestroyBlock(-1),
|
||||||
|
zDestroyBlock(-1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SurvivalMode::continueDestroyBlock( int x, int y, int z, int face ) {
|
||||||
|
if (destroyDelay > 0) {
|
||||||
|
destroyDelay--;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x == xDestroyBlock && y == yDestroyBlock && z == zDestroyBlock) {
|
||||||
|
int t = minecraft->level->getTile(x, y, z);
|
||||||
|
if (t == 0) return;
|
||||||
|
Tile* tile = Tile::tiles[t];
|
||||||
|
|
||||||
|
destroyProgress += tile->getDestroyProgress(minecraft->player);
|
||||||
|
|
||||||
|
if ((++destroyTicks & 3) == 1) {
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
if (tile != NULL) {
|
||||||
|
minecraft->soundEngine->play(tile->soundType->getStepSound(), x + 0.5f, y + 0.5f, z + 0.5f, (tile->soundType->getVolume() + 1) / 8, tile->soundType->getPitch() * 0.5f);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (destroyProgress >= 1) {
|
||||||
|
destroyBlock(x, y, z, face);
|
||||||
|
destroyProgress = 0;
|
||||||
|
oDestroyProgress = 0;
|
||||||
|
destroyTicks = 0;
|
||||||
|
destroyDelay = 5;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
destroyProgress = 0;
|
||||||
|
oDestroyProgress = 0;
|
||||||
|
destroyTicks = 0;
|
||||||
|
xDestroyBlock = x;
|
||||||
|
yDestroyBlock = y;
|
||||||
|
zDestroyBlock = z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SurvivalMode::destroyBlock( int x, int y, int z, int face ) {
|
||||||
|
int t = minecraft->level->getTile(x, y, z);
|
||||||
|
int data = minecraft->level->getData(x, y, z);
|
||||||
|
bool changed = GameMode::destroyBlock(x, y, z, face);
|
||||||
|
bool couldDestroy = minecraft->player->canDestroy(Tile::tiles[t]);
|
||||||
|
|
||||||
|
ItemInstance* item = minecraft->player->inventory->getSelected();
|
||||||
|
if (item != NULL) {
|
||||||
|
item->mineBlock(t, x, y, z);
|
||||||
|
if (item->count == 0) {
|
||||||
|
//item->snap(minecraft->player);
|
||||||
|
minecraft->player->inventory->clearSlot(minecraft->player->inventory->selected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed && couldDestroy) {
|
||||||
|
ItemInstance instance(t, 1, data);
|
||||||
|
Tile::tiles[t]->playerDestroy(minecraft->level, minecraft->player, x, y, z, data);
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SurvivalMode::stopDestroyBlock() {
|
||||||
|
destroyProgress = 0;
|
||||||
|
destroyDelay = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SurvivalMode::initAbilities( Abilities& abilities ) {
|
||||||
|
abilities.flying = false;
|
||||||
|
abilities.mayfly = false;
|
||||||
|
abilities.instabuild = false;
|
||||||
|
abilities.invulnerable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SurvivalMode::startDestroyBlock( int x, int y, int z, int face ) {
|
||||||
|
if(minecraft->player->getCarriedItem() != NULL && minecraft->player->getCarriedItem()->id == Item::bow->id)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int t = minecraft->level->getTile(x, y, z);
|
||||||
|
if (t > 0 && destroyProgress == 0) Tile::tiles[t]->attack(minecraft->level, x, y, z, minecraft->player);
|
||||||
|
if (t > 0 && Tile::tiles[t]->getDestroyProgress(minecraft->player) >= 1)
|
||||||
|
destroyBlock(x, y, z, face);
|
||||||
|
}
|
||||||
31
src/client/gamemode/SurvivalMode.h
Executable file
31
src/client/gamemode/SurvivalMode.h
Executable file
@@ -0,0 +1,31 @@
|
|||||||
|
#ifndef NET_MINECRAFT_CLIENT_GAMEMODE__SurvivalMode_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GAMEMODE__SurvivalMode_H__
|
||||||
|
|
||||||
|
#include "GameMode.h"
|
||||||
|
|
||||||
|
class Abilities;
|
||||||
|
class Minecraft;
|
||||||
|
|
||||||
|
class SurvivalMode: public GameMode
|
||||||
|
{
|
||||||
|
typedef GameMode super;
|
||||||
|
public:
|
||||||
|
SurvivalMode(Minecraft* minecraft);
|
||||||
|
|
||||||
|
bool destroyBlock(int x, int y, int z, int face);
|
||||||
|
void startDestroyBlock(int x, int y, int z, int face);
|
||||||
|
void continueDestroyBlock(int x, int y, int z, int face);
|
||||||
|
void stopDestroyBlock();
|
||||||
|
|
||||||
|
bool canHurtPlayer() { return true; }
|
||||||
|
|
||||||
|
bool isSurvivalType() { return true; }
|
||||||
|
|
||||||
|
void initAbilities( Abilities& abilities );
|
||||||
|
private:
|
||||||
|
int xDestroyBlock;
|
||||||
|
int yDestroyBlock;
|
||||||
|
int zDestroyBlock;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GAMEMODE__SurvivalMode_H__*/
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "Font.hpp"
|
#include "Font.h"
|
||||||
|
|
||||||
//#include "SharedConstants.hpp"
|
//#include "SharedConstants.h"
|
||||||
#include "client/Options.hpp"
|
#include "../Options.h"
|
||||||
#include "client/renderer/Textures.hpp"
|
#include "../renderer/Textures.h"
|
||||||
#include "client/renderer/Tesselator.hpp"
|
#include "../renderer/Tesselator.h"
|
||||||
#include "util/Mth.hpp"
|
#include "../../util/Mth.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
Font::Font( Options* options, const std::string& name, Textures* textures )
|
Font::Font( Options* options, const std::string& name, Textures* textures )
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI__Font_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI__Font_H__
|
||||||
|
|
||||||
//package net.minecraft.client.gui;
|
//package net.minecraft.client.gui;
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
#include "client/renderer/gles.hpp"
|
#include "../renderer/gles.h"
|
||||||
|
|
||||||
class Textures;
|
class Textures;
|
||||||
class Options;
|
class Options;
|
||||||
@@ -59,3 +60,4 @@ private:
|
|||||||
unsigned char _charOffset;
|
unsigned char _charOffset;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI__Font_H__*/
|
||||||
@@ -1,52 +1,67 @@
|
|||||||
#include "Gui.hpp"
|
#include "Gui.h"
|
||||||
#include "Font.hpp"
|
#include "Font.h"
|
||||||
#include "MinecraftClient.hpp"
|
#include "client/Options.h"
|
||||||
#include "client/Options.hpp"
|
#include "platform/input/Keyboard.h"
|
||||||
#include "platform/input/Keyboard.hpp"
|
#include "screens/IngameBlockSelectionScreen.h"
|
||||||
#include "screens/IngameBlockSelectionScreen.hpp"
|
#include "screens/ChatScreen.h"
|
||||||
#include "screens/ChatScreen.hpp"
|
#include "screens/ConsoleScreen.h"
|
||||||
#include "screens/ConsoleScreen.hpp"
|
#include "../Minecraft.h"
|
||||||
#include <Minecraft.hpp>
|
#include "../player/LocalPlayer.h"
|
||||||
#include "client/player/LocalPlayer.hpp"
|
#include "../renderer/Tesselator.h"
|
||||||
#include "client/renderer/Tesselator.hpp"
|
#include "../renderer/TileRenderer.h"
|
||||||
#include "client/renderer/TileRenderer.hpp"
|
#include "../renderer/LevelRenderer.h"
|
||||||
#include "client/renderer/LevelRenderer.hpp"
|
#include "../renderer/GameRenderer.h"
|
||||||
#include "client/renderer/GameRenderer.hpp"
|
#include "../renderer/entity/ItemRenderer.h"
|
||||||
#include "client/renderer/entity/ItemRenderer.hpp"
|
#include "../player/input/IInputHolder.h"
|
||||||
#include "client/player/input/IInputHolder.hpp"
|
#include "../gamemode/GameMode.h"
|
||||||
#include "client/gamemode/GameMode.hpp"
|
#include "../gamemode/CreativeMode.h"
|
||||||
#include "client/gamemode/CreativeMode.hpp"
|
#include "../renderer/Textures.h"
|
||||||
#include "client/renderer/Textures.hpp"
|
#include "../../AppConstants.h"
|
||||||
#include "AppConstants.hpp"
|
#include "../../world/entity/player/Inventory.h"
|
||||||
#include "world/entity/player/Inventory.hpp"
|
#include "../../world/level/material/Material.h"
|
||||||
#include "world/level/material/Material.hpp"
|
#include "../../world/item/Item.h"
|
||||||
#include "world/item/Item.hpp"
|
#include "../../world/item/ItemInstance.h"
|
||||||
#include "world/item/ItemInstance.hpp"
|
#include "../../platform/input/Mouse.h"
|
||||||
#include "platform/input/Mouse.hpp"
|
#include "../../world/level/Level.h"
|
||||||
#include "world/level/Level.hpp"
|
#include "../../world/PosTranslator.h"
|
||||||
#include "world/PosTranslator.hpp"
|
#include "../../platform/time.h"
|
||||||
#include "platform/time.hpp"
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#define MAX_MESSAGE_WIDTH 240
|
|
||||||
|
|
||||||
float Gui::InvGuiScale = 1.0f / 3.0f;
|
float Gui::InvGuiScale = 1.0f / 3.0f;
|
||||||
float Gui::GuiScale = 1.0f / Gui::InvGuiScale;
|
float Gui::GuiScale = 1.0f / Gui::InvGuiScale;
|
||||||
const float Gui::DropTicks = 40.0f;
|
const float Gui::DropTicks = 40.0f;
|
||||||
|
|
||||||
//#include <android/log.h>
|
//#include <android/log.h>
|
||||||
|
|
||||||
// @todo virtual controlConfigurationChanged() when player switches from keyboard to touch for example
|
Gui::Gui(Minecraft* minecraft)
|
||||||
Gui::Gui(MinecraftClient& minecraft) : minecraft(minecraft), _openInventorySlot(minecraft.useTouchscreen()) {
|
: minecraft(minecraft),
|
||||||
|
tickCount(0),
|
||||||
|
progress(0),
|
||||||
|
overlayMessageTime(0),
|
||||||
|
animateOverlayMessageColor(false),
|
||||||
|
chatScrollOffset(0),
|
||||||
|
tbr(1),
|
||||||
|
_inventoryNeedsUpdate(true),
|
||||||
|
_flashSlotId(-1),
|
||||||
|
_flashSlotStartTime(-1),
|
||||||
|
_slotFont(NULL),
|
||||||
|
_numSlots(4),
|
||||||
|
_currentDropTicks(-1),
|
||||||
|
_currentDropSlot(-1),
|
||||||
|
MAX_MESSAGE_WIDTH(240),
|
||||||
|
itemNameOverlayTime(2),
|
||||||
|
_openInventorySlot(minecraft->useTouchscreen())
|
||||||
|
{
|
||||||
glGenBuffers2(1, &_inventoryRc.vboId);
|
glGenBuffers2(1, &_inventoryRc.vboId);
|
||||||
glGenBuffers2(1, &rcFeedbackInner.vboId);
|
glGenBuffers2(1, &rcFeedbackInner.vboId);
|
||||||
glGenBuffers2(1, &rcFeedbackOuter.vboId);
|
glGenBuffers2(1, &rcFeedbackOuter.vboId);
|
||||||
//Gui::InvGuiScale = 1.0f / (int) (3 * Minecraft::width / 854);
|
//Gui::InvGuiScale = 1.0f / (int) (3 * Minecraft::width / 854);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gui::~Gui() {
|
Gui::~Gui()
|
||||||
|
{
|
||||||
if (_slotFont)
|
if (_slotFont)
|
||||||
delete _slotFont;
|
delete _slotFont;
|
||||||
|
|
||||||
@@ -54,16 +69,17 @@ Gui::~Gui() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
|
void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
|
||||||
if (!minecraft.level || !minecraft.getPlayer())
|
|
||||||
|
if (!minecraft->level || !minecraft->player)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//minecraft->gameRenderer->setupGuiScreen();
|
//minecraft->gameRenderer->setupGuiScreen();
|
||||||
Font* font = minecraft.getFont();
|
Font* font = minecraft->font;
|
||||||
|
|
||||||
const bool isTouchInterface = minecraft.useTouchscreen();
|
const bool isTouchInterface = minecraft->useTouchscreen();
|
||||||
|
|
||||||
const int screenWidth = (int)(minecraft.getScreenWidth() * InvGuiScale);
|
const int screenWidth = (int)(minecraft->width * InvGuiScale);
|
||||||
const int screenHeight = (int)(minecraft.getScreenHeigth() * InvGuiScale);
|
const int screenHeight = (int)(minecraft->height * InvGuiScale);
|
||||||
blitOffset = -90;
|
blitOffset = -90;
|
||||||
renderProgressIndicator(isTouchInterface, screenWidth, screenHeight, a);
|
renderProgressIndicator(isTouchInterface, screenWidth, screenHeight, a);
|
||||||
|
|
||||||
@@ -75,9 +91,9 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
|
|||||||
// F: 3
|
// F: 3
|
||||||
int ySlot = screenHeight - 16 - 3;
|
int ySlot = screenHeight - 16 - 3;
|
||||||
|
|
||||||
if (!minecraft.options.getBooleanValue(OPTIONS_HIDEGUI)) {
|
if (!minecraft->options.getBooleanValue(OPTIONS_HIDEGUI)) {
|
||||||
if (minecraft.gameMode->canHurtPlayer()) {
|
if (minecraft->gameMode->canHurtPlayer()) {
|
||||||
minecraft.getTextures()->loadAndBindTexture("gui/icons.png");
|
minecraft->textures->loadAndBindTexture("gui/icons.png");
|
||||||
Tesselator& t = Tesselator::instance;
|
Tesselator& t = Tesselator::instance;
|
||||||
t.beginOverride();
|
t.beginOverride();
|
||||||
t.colorABGR(0xffffffff);
|
t.colorABGR(0xffffffff);
|
||||||
@@ -87,7 +103,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(minecraft.getPlayer()->getSleepTimer() > 0) {
|
if(minecraft->player->getSleepTimer() > 0) {
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_ALPHA_TEST);
|
glDisable(GL_ALPHA_TEST);
|
||||||
|
|
||||||
@@ -96,7 +112,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
|
|||||||
glEnable(GL_ALPHA_TEST);
|
glEnable(GL_ALPHA_TEST);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
}
|
}
|
||||||
if (!minecraft.options.getBooleanValue(OPTIONS_HIDEGUI)) {
|
if (!minecraft->options.getBooleanValue(OPTIONS_HIDEGUI)) {
|
||||||
renderToolBar(a, ySlot, screenWidth);
|
renderToolBar(a, ySlot, screenWidth);
|
||||||
|
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
@@ -714,7 +730,6 @@ void Gui::renderDebugInfo() {
|
|||||||
|
|
||||||
// Position
|
// Position
|
||||||
float px = p->x, py = p->y - p->heightOffset, pz = p->z;
|
float px = p->x, py = p->y - p->heightOffset, pz = p->z;
|
||||||
posTranslator.to(px, py, pz);
|
|
||||||
int bx = (int)floorf(px), by = (int)floorf(py), bz = (int)floorf(pz);
|
int bx = (int)floorf(px), by = (int)floorf(py), bz = (int)floorf(pz);
|
||||||
int cx = bx >> 4, cz = bz >> 4;
|
int cx = bx >> 4, cz = bz >> 4;
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI__Gui_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI__Gui_H__
|
||||||
|
|
||||||
//package net.minecraft.client.gui;
|
//package net.minecraft.client.gui;
|
||||||
|
|
||||||
#include "GuiComponent.hpp"
|
#include "GuiComponent.h"
|
||||||
#include "Font.hpp"
|
#include "Font.h"
|
||||||
#include "client/player/input/touchscreen/TouchAreaModel.hpp"
|
#include "../player/input/touchscreen/TouchAreaModel.h"
|
||||||
#include "client/renderer/RenderChunk.hpp"
|
#include "../renderer/RenderChunk.h"
|
||||||
#include "util/Random.hpp"
|
#include "../../util/Random.h"
|
||||||
#include "client/IConfigListener.hpp"
|
#include "../IConfigListener.h"
|
||||||
|
|
||||||
class MinecraftClient;
|
class Minecraft;
|
||||||
class ItemInstance;
|
class ItemInstance;
|
||||||
class Textures;
|
class Textures;
|
||||||
class Tesselator;
|
class Tesselator;
|
||||||
@@ -26,7 +27,7 @@ typedef std::vector<GuiMessage> GuiMessageList;
|
|||||||
class Gui: public GuiComponent, IConfigListener
|
class Gui: public GuiComponent, IConfigListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Gui(MinecraftClient& minecraft);
|
Gui(Minecraft* minecraft);
|
||||||
~Gui();
|
~Gui();
|
||||||
|
|
||||||
int getSlotIdAt(int x, int y);
|
int getSlotIdAt(int x, int y);
|
||||||
@@ -89,43 +90,45 @@ private:
|
|||||||
void tickItemDrop();
|
void tickItemDrop();
|
||||||
float cubeSmoothStep(float percentage, float min, float max);
|
float cubeSmoothStep(float percentage, float min, float max);
|
||||||
public:
|
public:
|
||||||
float progress = 0.f;
|
float progress;
|
||||||
std::string selectedName;
|
std::string selectedName;
|
||||||
static float InvGuiScale;
|
static float InvGuiScale;
|
||||||
static float GuiScale;
|
static float GuiScale;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int MAX_MESSAGE_WIDTH;
|
||||||
//ItemRenderer itemRenderer;
|
//ItemRenderer itemRenderer;
|
||||||
GuiMessageList guiMessages;
|
GuiMessageList guiMessages;
|
||||||
int chatScrollOffset = 0;
|
int chatScrollOffset;
|
||||||
Random random;
|
Random random;
|
||||||
|
|
||||||
MinecraftClient& minecraft;
|
Minecraft* minecraft;
|
||||||
int tickCount = 0;
|
int tickCount;
|
||||||
float itemNameOverlayTime = 2;
|
float itemNameOverlayTime;
|
||||||
std::string overlayMessageString;
|
std::string overlayMessageString;
|
||||||
int overlayMessageTime = 0;
|
int overlayMessageTime;
|
||||||
bool animateOverlayMessageColor = false;
|
bool animateOverlayMessageColor;
|
||||||
|
|
||||||
float tbr = 1.f;
|
float tbr;
|
||||||
|
|
||||||
RenderChunk _inventoryRc;
|
RenderChunk _inventoryRc;
|
||||||
bool _inventoryNeedsUpdate = true;
|
bool _inventoryNeedsUpdate;
|
||||||
|
|
||||||
int _flashSlotId = -1;
|
int _flashSlotId;
|
||||||
float _flashSlotStartTime = -1;
|
float _flashSlotStartTime;
|
||||||
|
|
||||||
Font* _slotFont = nullptr;
|
Font* _slotFont;
|
||||||
int _numSlots = 4;
|
int _numSlots;
|
||||||
|
|
||||||
RenderChunk rcFeedbackOuter;
|
RenderChunk rcFeedbackOuter;
|
||||||
RenderChunk rcFeedbackInner;
|
RenderChunk rcFeedbackInner;
|
||||||
|
|
||||||
// For dropping
|
// For dropping
|
||||||
static const float DropTicks;
|
static const float DropTicks;
|
||||||
float _currentDropTicks = -1;
|
float _currentDropTicks;
|
||||||
int _currentDropSlot = -1;
|
int _currentDropSlot;
|
||||||
|
|
||||||
bool _openInventorySlot;
|
bool _openInventorySlot;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI__Gui_H__*/
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "GuiComponent.hpp"
|
#include "GuiComponent.h"
|
||||||
|
|
||||||
#include "client/renderer/Tesselator.hpp"
|
#include "../renderer/Tesselator.h"
|
||||||
#include "client/renderer/gles.hpp"
|
#include "../renderer/gles.h"
|
||||||
#include "Font.hpp"
|
#include "Font.h"
|
||||||
|
|
||||||
|
|
||||||
GuiComponent::GuiComponent()
|
GuiComponent::GuiComponent()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI__GuiComponent_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI__GuiComponent_H__
|
||||||
|
|
||||||
//package net.minecraft.client.gui;
|
//package net.minecraft.client.gui;
|
||||||
|
|
||||||
@@ -30,3 +31,4 @@ protected:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI__GuiComponent_H__*/
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
#include "Screen.hpp"
|
#include "Screen.h"
|
||||||
#include "components/Button.hpp"
|
#include "components/Button.h"
|
||||||
#include "components/TextBox.hpp"
|
#include "components/TextBox.h"
|
||||||
#include <Minecraft.hpp>
|
#include "../Minecraft.h"
|
||||||
#include "client/renderer/Tesselator.hpp"
|
#include "../renderer/Tesselator.h"
|
||||||
#include "client/sound/SoundEngine.hpp"
|
#include "../sound/SoundEngine.h"
|
||||||
#include "platform/input/Keyboard.hpp"
|
#include "../../platform/input/Keyboard.h"
|
||||||
#include "platform/input/Mouse.hpp"
|
#include "../../platform/input/Mouse.h"
|
||||||
#include "client/renderer/Textures.hpp"
|
#include "../renderer/Textures.h"
|
||||||
|
|
||||||
Screen::Screen()
|
Screen::Screen()
|
||||||
: passEvents(false),
|
: passEvents(false),
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI__Screen_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI__Screen_H__
|
||||||
|
|
||||||
//package net.minecraft.client.gui;
|
//package net.minecraft.client.gui;
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "GuiComponent.hpp"
|
#include "GuiComponent.h"
|
||||||
|
|
||||||
class Font;
|
class Font;
|
||||||
class Minecraft;
|
class Minecraft;
|
||||||
@@ -79,3 +80,4 @@ private:
|
|||||||
Button* clickedButton;
|
Button* clickedButton;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI__Screen_H__*/
|
||||||
11
src/client/gui/TweenData.h
Executable file
11
src/client/gui/TweenData.h
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#ifndef NET_MINECRAFT_CLIENT_GUI__TweenData_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI__TweenData_H__
|
||||||
|
|
||||||
|
typedef struct TweenData {
|
||||||
|
float cur;
|
||||||
|
float dur;
|
||||||
|
float start;
|
||||||
|
float stop;
|
||||||
|
} TweenData;
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI__TweenData_H__*/
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
typedef struct TweenData {
|
|
||||||
float cur;
|
|
||||||
float dur;
|
|
||||||
float start;
|
|
||||||
float stop;
|
|
||||||
} TweenData;
|
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "Button.hpp"
|
#include "Button.h"
|
||||||
#include "client/Minecraft.hpp"
|
#include "../../Minecraft.h"
|
||||||
#include "client/renderer/Textures.hpp"
|
#include "../../renderer/Textures.h"
|
||||||
|
|
||||||
Button::Button(int id, const std::string& msg)
|
Button::Button(int id, const std::string& msg)
|
||||||
: GuiElement(true, true, 0, 0, 200, 24),
|
: GuiElement(true, true, 0, 0, 200, 24),
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Button_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Button_H__
|
||||||
|
|
||||||
//package net.minecraft.client.gui;
|
//package net.minecraft.client.gui;
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "GuiElement.hpp"
|
#include "GuiElement.h"
|
||||||
#include "client/Options.hpp"
|
#include "../../Options.h"
|
||||||
|
|
||||||
class Font;
|
class Font;
|
||||||
class Minecraft;
|
class Minecraft;
|
||||||
@@ -76,3 +77,4 @@ public:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Button_H__*/
|
||||||
@@ -1 +1 @@
|
|||||||
#include "GuiElement.hpp"
|
#include "GuiElement.h"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI__GButton_H__
|
||||||
#include "Button.hpp"
|
#define NET_MINECRAFT_CLIENT_GUI__GButton_H__
|
||||||
|
#include "Button.h"
|
||||||
|
|
||||||
class GButton: public Button {
|
class GButton: public Button {
|
||||||
typedef Button super;
|
typedef Button super;
|
||||||
@@ -51,3 +52,4 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI__GButton_H__*/
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "GuiElement.hpp"
|
#include "GuiElement.h"
|
||||||
|
|
||||||
GuiElement::GuiElement( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ )
|
GuiElement::GuiElement( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ )
|
||||||
: active(active),
|
: active(active),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI__GuiElement_H__
|
||||||
#include "client/gui/GuiComponent.hpp"
|
#define NET_MINECRAFT_CLIENT_GUI__GuiElement_H__
|
||||||
|
#include "../GuiComponent.h"
|
||||||
|
|
||||||
class Tesselator;
|
class Tesselator;
|
||||||
class Minecraft;
|
class Minecraft;
|
||||||
@@ -30,3 +31,4 @@ public:
|
|||||||
int height;
|
int height;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI__GuiElement_H__*/
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "GuiElementContainer.hpp"
|
#include "GuiElementContainer.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
GuiElementContainer::GuiElementContainer( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ )
|
GuiElementContainer::GuiElementContainer( bool active/*=false*/, bool visible/*=true*/, int x /*= 0*/, int y /*= 0*/, int width/*=24*/, int height/*=24*/ )
|
||||||
: GuiElement(active, visible, x, y, width, height) {
|
: GuiElement(active, visible, x, y, width, height) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI__GuiElementContainer_H__
|
||||||
#include "GuiElement.hpp"
|
#define NET_MINECRAFT_CLIENT_GUI__GuiElementContainer_H__
|
||||||
|
#include "GuiElement.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
class Tesselator;
|
class Tesselator;
|
||||||
class Minecraft;
|
class Minecraft;
|
||||||
@@ -24,3 +25,4 @@ protected:
|
|||||||
std::vector<GuiElement*> children;
|
std::vector<GuiElement*> children;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI__GuiElementContainer_H__*/
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "ImageButton.hpp"
|
#include "ImageButton.h"
|
||||||
#include "client/renderer/Tesselator.hpp"
|
#include "../../renderer/Tesselator.h"
|
||||||
#include "client/Minecraft.hpp"
|
#include "../../Minecraft.h"
|
||||||
#include "platform/log.hpp"
|
#include "../../../platform/log.h"
|
||||||
#include "util/Mth.hpp"
|
#include "../../../util/Mth.h"
|
||||||
#include "client/renderer/Textures.hpp"
|
#include "../../renderer/Textures.h"
|
||||||
#include <client/Option.hpp>
|
#include <client/Option.h>
|
||||||
|
|
||||||
|
|
||||||
ImageButton::ImageButton(int id, const std::string& msg)
|
ImageButton::ImageButton(int id, const std::string& msg)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ImageButton_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ImageButton_H__
|
||||||
|
|
||||||
#include "Button.hpp"
|
#include "Button.h"
|
||||||
|
|
||||||
typedef struct IntRectangle {
|
typedef struct IntRectangle {
|
||||||
IntRectangle()
|
IntRectangle()
|
||||||
@@ -93,3 +94,4 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ImageButton_H__*/
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
#include "InventoryPane.hpp"
|
#include "InventoryPane.h"
|
||||||
#include "client/gui/Gui.hpp"
|
#include "../Gui.h"
|
||||||
#include "client/Minecraft.hpp"
|
#include "../../Minecraft.h"
|
||||||
#include "client/player/input/touchscreen/TouchAreaModel.hpp"
|
#include "../../player/input/touchscreen/TouchAreaModel.h"
|
||||||
#include "client/renderer/entity/ItemRenderer.hpp"
|
#include "../../renderer/entity/ItemRenderer.h"
|
||||||
#include "client/renderer/Tesselator.hpp"
|
#include "../../renderer/Tesselator.h"
|
||||||
#include "client/renderer/Textures.hpp"
|
#include "../../renderer/Textures.h"
|
||||||
#include "world/item/ItemInstance.hpp"
|
#include "../../../world/item/ItemInstance.h"
|
||||||
#include "world/entity/player/Inventory.hpp"
|
#include "../../../world/entity/player/Inventory.h"
|
||||||
|
|
||||||
namespace Touch {
|
namespace Touch {
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__InventoryPane_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__InventoryPane_H__
|
||||||
|
|
||||||
#include "ScrollingPane.hpp"
|
#include "ScrollingPane.h"
|
||||||
#include "ImageButton.hpp"
|
#include "ImageButton.h"
|
||||||
|
|
||||||
class Minecraft;
|
class Minecraft;
|
||||||
class ItemInstance;
|
class ItemInstance;
|
||||||
@@ -58,3 +59,4 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__InventoryPane_H__*/
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
#include "ItemPane.hpp"
|
#include "ItemPane.h"
|
||||||
#include "client/gui/Gui.hpp"
|
#include "../Gui.h"
|
||||||
#include "client/renderer/gles.hpp"
|
#include "../../renderer/gles.h"
|
||||||
#include "client/renderer/Tesselator.hpp"
|
#include "../../renderer/Tesselator.h"
|
||||||
#include "NinePatch.hpp"
|
#include "NinePatch.h"
|
||||||
#include "client/renderer/entity/ItemRenderer.hpp"
|
#include "../../renderer/entity/ItemRenderer.h"
|
||||||
|
|
||||||
const int rgbActive = 0xfff0f0f0;
|
const int rgbActive = 0xfff0f0f0;
|
||||||
const int rgbInactive = 0xc0635558;
|
const int rgbInactive = 0xc0635558;
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
#pragma once
|
#ifndef ITEMPANE_H__
|
||||||
|
#define ITEMPANE_H__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "ScrollingPane.hpp"
|
#include "ScrollingPane.h"
|
||||||
#include "world/item/ItemInstance.hpp"
|
#include "../../../world/item/ItemInstance.h"
|
||||||
|
|
||||||
class Font;
|
class Font;
|
||||||
class Textures;
|
class Textures;
|
||||||
@@ -91,3 +92,4 @@ public:
|
|||||||
NinePatchLayer* guiSlotItemSelected;
|
NinePatchLayer* guiSlotItemSelected;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*ITEMPANE_H__*/
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "KeyOption.hpp"
|
#include "KeyOption.h"
|
||||||
#include <client/Minecraft.hpp>
|
#include <client/Minecraft.h>
|
||||||
|
|
||||||
KeyOption::KeyOption(Minecraft* minecraft, OptionId optId)
|
KeyOption::KeyOption(Minecraft* minecraft, OptionId optId)
|
||||||
: Touch::TButton((int)optId, Keyboard::getKeyName(minecraft->options.getIntValue(optId))) {}
|
: Touch::TButton((int)optId, Keyboard::getKeyName(minecraft->options.getIntValue(optId))) {}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Button.hpp"
|
#include "Button.h"
|
||||||
#include <client/Options.hpp>
|
#include <client/Options.h>
|
||||||
|
|
||||||
class KeyOption : public Touch::TButton {
|
class KeyOption : public Touch::TButton {
|
||||||
public:
|
public:
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "LargeImageButton.hpp"
|
#include "LargeImageButton.h"
|
||||||
#include "client/renderer/Tesselator.hpp"
|
#include "../../renderer/Tesselator.h"
|
||||||
#include "client/Minecraft.hpp"
|
#include "../../Minecraft.h"
|
||||||
#include "util/Mth.hpp"
|
#include "../../../util/Mth.h"
|
||||||
#include "platform/log.hpp"
|
#include "../../../platform/log.h"
|
||||||
#include "util/Mth.hpp"
|
#include "../../../util/Mth.h"
|
||||||
#include "client/renderer/Textures.hpp"
|
#include "../../renderer/Textures.h"
|
||||||
|
|
||||||
|
|
||||||
LargeImageButton::LargeImageButton(int id, const std::string& msg)
|
LargeImageButton::LargeImageButton(int id, const std::string& msg)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__LargeImageButton_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__LargeImageButton_H__
|
||||||
|
|
||||||
#include "ImageButton.hpp"
|
#include "ImageButton.h"
|
||||||
|
|
||||||
class LargeImageButton: public ImageButton
|
class LargeImageButton: public ImageButton
|
||||||
{
|
{
|
||||||
@@ -17,3 +18,4 @@ private:
|
|||||||
float _buttonScale;
|
float _buttonScale;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__LargeImageButton_H__*/
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "NinePatch.hpp"
|
#include "NinePatch.h"
|
||||||
|
|
||||||
NinePatchDescription::NinePatchDescription( float x, float y, float x1, float x2, float x3, float y1, float y2, float y3, float w, float e, float n, float s ) : u0(x), u1(x + x1), u2(x + x2), u3(x + x3),
|
NinePatchDescription::NinePatchDescription( float x, float y, float x1, float x2, float x3, float y1, float y2, float y3, float w, float e, float n, float s ) : u0(x), u1(x + x1), u2(x + x2), u3(x + x3),
|
||||||
v0(y), v1(y + y1), v2(y + y2), v3(y + y3),
|
v0(y), v1(y + y1), v2(y + y2), v3(y + y3),
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI__NinePatch_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI__NinePatch_H__
|
||||||
|
|
||||||
#include "ImageButton.hpp"
|
#include "ImageButton.h"
|
||||||
#include "client/renderer/TextureData.hpp"
|
#include "../../renderer/TextureData.h"
|
||||||
#include "client/renderer/Textures.hpp"
|
#include "../../renderer/Textures.h"
|
||||||
#include "client/renderer/Tesselator.hpp"
|
#include "../../renderer/Tesselator.h"
|
||||||
#include "client/Minecraft.hpp"
|
#include "../../Minecraft.h"
|
||||||
|
|
||||||
class Tesselator;
|
class Tesselator;
|
||||||
|
|
||||||
@@ -74,3 +75,4 @@ private:
|
|||||||
int height;
|
int height;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI__NinePatch_H__*/
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
#include "OptionsGroup.hpp"
|
#include "OptionsGroup.h"
|
||||||
#include "client/Minecraft.hpp"
|
#include "../../Minecraft.h"
|
||||||
#include "ImageButton.hpp"
|
#include "ImageButton.h"
|
||||||
#include "OptionsItem.hpp"
|
#include "OptionsItem.h"
|
||||||
#include "Slider.hpp"
|
#include "Slider.h"
|
||||||
#include "locale/I18n.hpp"
|
#include "../../../locale/I18n.h"
|
||||||
#include "TextOption.hpp"
|
#include "TextOption.h"
|
||||||
#include "KeyOption.hpp"
|
#include "KeyOption.h"
|
||||||
|
|
||||||
OptionsGroup::OptionsGroup( std::string labelID ) {
|
OptionsGroup::OptionsGroup( std::string labelID ) {
|
||||||
label = I18n::get(labelID);
|
label = I18n::get(labelID);
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsGroup_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsGroup_H__
|
||||||
|
|
||||||
//package net.minecraft.client.gui;
|
//package net.minecraft.client.gui;
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "GuiElementContainer.hpp"
|
#include "GuiElementContainer.h"
|
||||||
#include "ScrollingPane.hpp"
|
#include "ScrollingPane.h"
|
||||||
#include "client/Options.hpp"
|
#include "../../Options.h"
|
||||||
|
|
||||||
class Font;
|
class Font;
|
||||||
class Minecraft;
|
class Minecraft;
|
||||||
@@ -28,3 +29,4 @@ protected:
|
|||||||
std::string label;
|
std::string label;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsGroup_H__*/
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "OptionsItem.hpp"
|
#include "OptionsItem.h"
|
||||||
#include "client/Minecraft.hpp"
|
#include "../../Minecraft.h"
|
||||||
#include "locale/I18n.hpp"
|
#include "../../../locale/I18n.h"
|
||||||
#include "util/Mth.hpp"
|
#include "../../../util/Mth.h"
|
||||||
OptionsItem::OptionsItem( OptionId optionId, std::string label, GuiElement* element )
|
OptionsItem::OptionsItem( OptionId optionId, std::string label, GuiElement* element )
|
||||||
: GuiElementContainer(false, true, 0, 0, 24, 12),
|
: GuiElementContainer(false, true, 0, 0, 24, 12),
|
||||||
m_optionId(optionId),
|
m_optionId(optionId),
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsItem_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsItem_H__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "GuiElementContainer.hpp"
|
#include "GuiElementContainer.h"
|
||||||
#include "world/item/ItemInstance.hpp"
|
#include "../../../world/item/ItemInstance.h"
|
||||||
#include "client/Options.hpp"
|
#include "../../../client/Options.h"
|
||||||
class Font;
|
class Font;
|
||||||
class Textures;
|
class Textures;
|
||||||
class NinePatchLayer;
|
class NinePatchLayer;
|
||||||
@@ -23,3 +24,4 @@ private:
|
|||||||
std::string m_label;
|
std::string m_label;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__OptionsItem_H__*/
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
#include "RolledSelectionListH.hpp"
|
#include "RolledSelectionListH.h"
|
||||||
#include "client/renderer/Tesselator.hpp"
|
#include "../../Minecraft.h"
|
||||||
#include "client/renderer/gles.hpp"
|
#include "../../renderer/Tesselator.h"
|
||||||
#include "platform/input/Mouse.hpp"
|
#include "../../renderer/gles.h"
|
||||||
#include "platform/input/Multitouch.hpp"
|
#include "../../../platform/input/Mouse.h"
|
||||||
#include "util/Mth.hpp"
|
#include "../../../platform/input/Multitouch.h"
|
||||||
#include "client/renderer/Textures.hpp"
|
#include "../../../util/Mth.h"
|
||||||
#include "MinecraftClient.hpp"
|
#include "../../renderer/Textures.h"
|
||||||
|
|
||||||
|
|
||||||
RolledSelectionListH::RolledSelectionListH( MinecraftClient& minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth )
|
RolledSelectionListH::RolledSelectionListH( Minecraft* minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth )
|
||||||
: minecraft(minecraft),
|
: minecraft(minecraft),
|
||||||
width(width),
|
width(width),
|
||||||
height(height),
|
height(height),
|
||||||
@@ -172,7 +172,7 @@ void RolledSelectionListH::render( int xm, int ym, float a )
|
|||||||
|
|
||||||
//LOGI("x: %f\n", xo);
|
//LOGI("x: %f\n", xo);
|
||||||
|
|
||||||
minecraft.textures().loadAndBindTexture("gui/background.png");
|
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||||
glColor4f2(1.0f, 1, 1, 1);
|
glColor4f2(1.0f, 1, 1, 1);
|
||||||
float s = 32;
|
float s = 32;
|
||||||
t.begin();
|
t.begin();
|
||||||
@@ -280,7 +280,7 @@ void RolledSelectionListH::render( int xm, int ym, float a )
|
|||||||
void RolledSelectionListH::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 )
|
void RolledSelectionListH::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 )
|
||||||
{
|
{
|
||||||
Tesselator& t = Tesselator::instance;
|
Tesselator& t = Tesselator::instance;
|
||||||
minecraft.textures().loadAndBindTexture("gui/background.png");
|
minecraft->textures->loadAndBindTexture("gui/background.png");
|
||||||
glColor4f2(1.0f, 1, 1, 1);
|
glColor4f2(1.0f, 1, 1, 1);
|
||||||
float s = 32;
|
float s = 32;
|
||||||
t.begin();
|
t.begin();
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListH_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListH_H__
|
||||||
|
|
||||||
#include "client/gui/GuiComponent.hpp"
|
#include "../GuiComponent.h"
|
||||||
class MinecraftClient;
|
class Minecraft;
|
||||||
class Tesselator;
|
class Tesselator;
|
||||||
|
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ class RolledSelectionListH : public GuiComponent
|
|||||||
static const int DRAG_OUTSIDE = -2;
|
static const int DRAG_OUTSIDE = -2;
|
||||||
static const int DRAG_NORMAL = 0;
|
static const int DRAG_NORMAL = 0;
|
||||||
public:
|
public:
|
||||||
RolledSelectionListH(MinecraftClient& minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth);
|
RolledSelectionListH(Minecraft* minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemWidth);
|
||||||
|
|
||||||
virtual int getItemAtPosition(int x, int y);
|
virtual int getItemAtPosition(int x, int y);
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ protected:
|
|||||||
virtual void clickedHeader(int headerMouseX, int headerMouseY) {}
|
virtual void clickedHeader(int headerMouseX, int headerMouseY) {}
|
||||||
int getItemAtXPositionRaw(int x);
|
int getItemAtXPositionRaw(int x);
|
||||||
protected:
|
protected:
|
||||||
MinecraftClient& minecraft;
|
Minecraft* minecraft;
|
||||||
|
|
||||||
float x0;
|
float x0;
|
||||||
float x1;
|
float x1;
|
||||||
@@ -78,3 +79,4 @@ private:
|
|||||||
float _lastxoo;
|
float _lastxoo;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListH_H__*/
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "RolledSelectionListV.hpp"
|
#include "RolledSelectionListV.h"
|
||||||
#include "client/Minecraft.hpp"
|
#include "../../Minecraft.h"
|
||||||
#include "client/renderer/Tesselator.hpp"
|
#include "../../renderer/Tesselator.h"
|
||||||
#include "client/renderer/gles.hpp"
|
#include "../../renderer/gles.h"
|
||||||
#include "platform/input/Mouse.hpp"
|
#include "../../../platform/input/Mouse.h"
|
||||||
#include "util/Mth.hpp"
|
#include "../../../util/Mth.h"
|
||||||
#include "client/renderer/Textures.hpp"
|
#include "../../renderer/Textures.h"
|
||||||
|
|
||||||
|
|
||||||
RolledSelectionListV::RolledSelectionListV( Minecraft* minecraft_, int width_, int height_, int x0_, int x1_, int y0_, int y1_, int itemHeight_ )
|
RolledSelectionListV::RolledSelectionListV( Minecraft* minecraft_, int width_, int height_, int x0_, int x1_, int y0_, int y1_, int itemHeight_ )
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListV_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListV_H__
|
||||||
|
|
||||||
#include "client/gui/GuiComponent.hpp"
|
#include "../GuiComponent.h"
|
||||||
class Minecraft;
|
class Minecraft;
|
||||||
class Tesselator;
|
class Tesselator;
|
||||||
|
|
||||||
@@ -90,3 +91,4 @@ private:
|
|||||||
float _stickPixels;
|
float _stickPixels;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__RolledSelectionListV_H__*/
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
#include "ScrolledSelectionList.hpp"
|
#include "ScrolledSelectionList.h"
|
||||||
#include "client/Minecraft.hpp"
|
#include "../../Minecraft.h"
|
||||||
#include "client/renderer/Tesselator.hpp"
|
#include "../../renderer/Tesselator.h"
|
||||||
#include "client/renderer/gles.hpp"
|
#include "../../renderer/gles.h"
|
||||||
#include "platform/input/Mouse.hpp"
|
#include "../../../platform/input/Mouse.h"
|
||||||
#include "client/renderer/Textures.hpp"
|
#include "../../renderer/Textures.h"
|
||||||
|
|
||||||
static int Abs(int d) {
|
static int Abs(int d) {
|
||||||
return d >= 0? d : -d;
|
return d >= 0? d : -d;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrolledSelectionList_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrolledSelectionList_H__
|
||||||
|
|
||||||
#include "client/gui/GuiComponent.hpp"
|
#include "../GuiComponent.h"
|
||||||
class Minecraft;
|
class Minecraft;
|
||||||
class Tesselator;
|
class Tesselator;
|
||||||
|
|
||||||
@@ -65,3 +66,4 @@ private:
|
|||||||
int headerHeight;
|
int headerHeight;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrolledSelectionList_H__*/
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "ScrollingPane.hpp"
|
#include "ScrollingPane.h"
|
||||||
#include "client/renderer/gles.hpp"
|
#include "../../renderer/gles.h"
|
||||||
#include "client/gui/Gui.hpp"
|
#include "../Gui.h"
|
||||||
#include "util/Mth.hpp"
|
#include "../../../util/Mth.h"
|
||||||
#include "SharedConstants.hpp"
|
#include "../../../SharedConstants.h"
|
||||||
|
|
||||||
#define STR(x) (x.toString().c_str())
|
#define STR(x) (x.toString().c_str())
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrollingPane_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrollingPane_H__
|
||||||
|
|
||||||
#include "client/gui/GuiComponent.hpp"
|
#include "../GuiComponent.h"
|
||||||
#include "ImageButton.hpp"
|
#include "ImageButton.h"
|
||||||
#include "client/player/input/touchscreen/TouchAreaModel.hpp"
|
#include "../../player/input/touchscreen/TouchAreaModel.h"
|
||||||
#include "world/phys/Vec3.hpp"
|
#include "../../../world/phys/Vec3.h"
|
||||||
#include "client/Timer.hpp"
|
#include "../../Timer.h"
|
||||||
|
|
||||||
enum ScrollingPaneFlags {
|
enum ScrollingPaneFlags {
|
||||||
SF_LockX = 1 << 0,
|
SF_LockX = 1 << 0,
|
||||||
@@ -199,3 +200,4 @@ private:
|
|||||||
float _ly;
|
float _ly;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__ScrollingPane_H__*/
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
#include "Slider.hpp"
|
#include "Slider.h"
|
||||||
#include "client/Minecraft.hpp"
|
#include "../../Minecraft.h"
|
||||||
#include "client/renderer/Textures.hpp"
|
#include "../../renderer/Textures.h"
|
||||||
#include "client/gui/Screen.hpp"
|
#include "../Screen.h"
|
||||||
#include "locale/I18n.hpp"
|
#include "../../../locale/I18n.h"
|
||||||
#include "util/Mth.hpp"
|
#include "../../../util/Mth.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#pragma once
|
#ifndef NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Slider_H__
|
||||||
|
#define NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Slider_H__
|
||||||
|
|
||||||
#include "GuiElement.hpp"
|
#include "GuiElement.h"
|
||||||
#include "client/Options.hpp"
|
#include "../../../client/Options.h"
|
||||||
#include <client/Option.hpp>
|
#include <client/Option.h>
|
||||||
|
|
||||||
class Slider : public GuiElement {
|
class Slider : public GuiElement {
|
||||||
typedef GuiElement super;
|
typedef GuiElement super;
|
||||||
@@ -44,3 +45,4 @@ protected:
|
|||||||
OptionInt* m_option;
|
OptionInt* m_option;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif /*NET_MINECRAFT_CLIENT_GUI_COMPONENTS__Slider_H__*/
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "TextBox.hpp"
|
#include "TextBox.h"
|
||||||
#include "client/gui/Gui.hpp"
|
#include "../Gui.h"
|
||||||
#include "client/Minecraft.hpp"
|
#include "../../Minecraft.h"
|
||||||
#include "AppPlatform.hpp"
|
#include "../../../AppPlatform.h"
|
||||||
#include "platform/input/Mouse.hpp"
|
#include "../../../platform/input/Mouse.h"
|
||||||
|
|
||||||
// delegate constructors
|
// delegate constructors
|
||||||
TextBox::TextBox(int id, const std::string& msg)
|
TextBox::TextBox(int id, const std::string& msg)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user