Skip to content

Commit

Permalink
Merge pull request #70 from LaG1924/ftr/build-3
Browse files Browse the repository at this point in the history
Ftr/build 3
  • Loading branch information
LaG1924 authored Jul 6, 2021
2 parents 8a4075c + 28cda3a commit 4354b1b
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 14 deletions.
31 changes: 19 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ CPMAddPackage(
VERSION 2.0.14
GIT_TAG release-2.0.14
OPTIONS
"SDL_SHARED ON"
"SDL_STATIC OFF"
"SDL_SHARED OFF"
"SDL_STATIC ON"
"LIBC ON"
)


Expand Down Expand Up @@ -89,7 +90,7 @@ if(SDL2_net_ADDED)
file(GLOB SDL2_net_sources ${SDL2_net_SOURCE_DIR}/*.c)
list(REMOVE_ITEM SDL2_net_sources "${SDL2_net_SOURCE_DIR}/chatd.c")
add_library(SDL2_net STATIC ${SDL2_net_sources})
target_link_libraries(SDL2_net SDL2)
target_link_libraries(SDL2_net SDL2-static)
IF (WIN32)
target_link_libraries(SDL2_net ws2_32 iphlpapi)
ENDIF()
Expand All @@ -102,8 +103,8 @@ CPMAddPackage(
GITHUB_REPOSITORY madler/zlib
VERSION 1.2.11
)
target_include_directories(zlib PUBLIC ${zlib_SOURCE_DIR})
target_include_directories(zlib PUBLIC ${zlib_BINARY_DIR})
target_include_directories(zlibstatic PUBLIC ${zlib_SOURCE_DIR})
target_include_directories(zlibstatic PUBLIC ${zlib_BINARY_DIR})


CPMAddPackage(
Expand Down Expand Up @@ -142,10 +143,16 @@ endif()


CPMAddPackage(
NAME Freetype
GITHUB_REPOSITORY freetype/freetype
VERSION 2.10.4
GIT_TAG VER-2-10-4
NAME Freetype
GITHUB_REPOSITORY freetype/freetype
VERSION 2.10.4
GIT_TAG VER-2-10-4
OPTIONS
"CMAKE_DISABLE_FIND_PACKAGE_ZLIB TRUE"
"CMAKE_DISABLE_FIND_PACKAGE_BZip2 TRUE"
"CMAKE_DISABLE_FIND_PACKAGE_PNG TRUE"
"CMAKE_DISABLE_FIND_PACKAGE_HarfBuzz TRUE"
"CMAKE_DISABLE_FIND_PACKAGE_BrotliDec TRUE"
)
export(EXPORT freetype-targets)

Expand Down Expand Up @@ -181,17 +188,17 @@ target_link_libraries(AltCraft
easyloggingpp
libglew_static
nlohmann_json::nlohmann_json
SDL2
SDL2-static
SDL2main
SDL2_net
OptickCore
zlib
zlibstatic
sol2
RmlLua
RmlDebugger
)

set_target_properties(AltCraft SDL2 OptickCore zlib PROPERTIES
set_target_properties(AltCraft OptickCore PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ AltCraft is implementation of [Minecraft: Java Edition (1.12.2)](https://minecra

This is aimed at being fast, being free and being easy expandable.

# Demonstration ([more](https://github.com/LaG1924/AltCraft/discussions/69))

![screenshot_1](https://user-images.githubusercontent.com/12997935/124433999-cbd7a780-dd8c-11eb-812d-e89c65ffabc6.png)
![screenshot_2](https://user-images.githubusercontent.com/12997935/124433848-9fbc2680-dd8c-11eb-9c68-a0a9a3dcaecb.png)

Clickable video:
[![video_1_yt](https://img.youtube.com/vi/LvvsEjPvCmY/0.jpg)](https://www.youtube.com/watch?v=LvvsEjPvCmY)

# Build
1. Install CMake 3.14, C++ compiler, OpenGL.

Expand Down
11 changes: 11 additions & 0 deletions cwd/assets/altcraft/scripts/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local plugin = {
onTick = nil,
onRequestBlockInfo = nil,
onChatMessage = nil,
onDisconnected = nil,
}

function plugin.onLoad ()
Expand Down Expand Up @@ -104,6 +105,16 @@ function plugin.onChatMessage(chat, pos)
MoveChatToBottom = true
end

function plugin.onDisconnected(reason)
local mmDoc = {}
for i,d in ipairs(rmlui.contexts["default"].documents) do
if d.title == "MainMenu" then
mmDoc = d
end
end
mmDoc:GetElementById('disclaimer').inner_rml = reason
end

AC.RegisterDimension(0, Dimension.new("overworld", true))
AC.RegisterDimension(-1, Dimension.new("the_nether", false))
AC.RegisterDimension(1, Dimension.new("the_end", false))
Expand Down
2 changes: 1 addition & 1 deletion cwd/assets/altcraft/shaders/vert/face.vs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ void main() {
vs_out.Texture.y -= (uv[2].y - uv[0].y) * trunc(mod(GlobalTime * 4.0f, animation));

float faceLight = clamp(light.x / 15.0 + (light.y / 15.0) * DayTime, MinLightLevel, 1.0);
vs_out.Color = mix(color.rgb * faceLight, vec3(1,1,1) * faceLight, (color == vec3(0,0,0)));
vs_out.Color = mix(color.rgb * faceLight, vec3(1,1,1) * faceLight, float(color == vec3(0,0,0)));
}
18 changes: 17 additions & 1 deletion src/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct Plugin {
const std::function<void(double)> onTick;
const std::function<BlockInfo(Vector)> onRequestBlockInfo;
const std::function<void(Chat, int)> onChatMessage;
const std::function<void(std::string)> onDisconnected;
};


Expand All @@ -45,6 +46,7 @@ namespace PluginApi {
plugin["onTick"].get_or(std::function<void(double)>()),
plugin["onRequestBlockInfo"].get_or(std::function<BlockInfo(Vector)>()),
plugin["onChatMessage"].get_or(std::function<void(Chat, int)>()),
plugin["onDisconnected"].get_or(std::function<void(std::string)>()),
};
plugins.push_back(nativePlugin);
LOG(INFO)<<"Loading plugin " << (!nativePlugin.displayName.empty() ? nativePlugin.displayName : nativePlugin.name);
Expand Down Expand Up @@ -371,7 +373,7 @@ BlockInfo PluginSystem::RequestBlockInfo(Vector blockPos) {
void PluginSystem::CallOnChatMessage(const Chat& chat, int position) {
OPTICK_EVENT();
for (Plugin& plugin : plugins) {
if (plugin.onRequestBlockInfo && plugin.errors < 10)
if (plugin.errors < 10)
try {
plugin.onChatMessage(chat, position);
}
Expand All @@ -381,3 +383,17 @@ void PluginSystem::CallOnChatMessage(const Chat& chat, int position) {
}
}
}

void PluginSystem::CallOnDisconnected(const std::string &reason) {
OPTICK_EVENT();
for (Plugin& plugin : plugins) {
if (plugin.errors < 10)
try {
plugin.onDisconnected(reason);
}
catch (sol::error& e) {
LOG(ERROR) << e.what();
plugin.errors++;
}
}
}
2 changes: 2 additions & 0 deletions src/Plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ namespace PluginSystem {
BlockInfo RequestBlockInfo(Vector blockPos);

void CallOnChatMessage(const Chat& chat, int position);

void CallOnDisconnected(const std::string &reason);
}
2 changes: 2 additions & 0 deletions src/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ void Render::InitEvents() {
world.reset();
SetState(State::MainMenu);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
PluginSystem::CallOnDisconnected("Connection failed: " + eventData.get <std::string>());
});

listener.RegisterHandler("Disconnected", [this](const Event& eventData) {
Expand All @@ -473,6 +474,7 @@ void Render::InitEvents() {
world.reset();
SetState(State::MainMenu);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
PluginSystem::CallOnDisconnected("Disconnected: " + eventData.get<std::string>());
});

listener.RegisterHandler("Connecting", [this](const Event&) {
Expand Down

0 comments on commit 4354b1b

Please sign in to comment.