Skip to content

Commit

Permalink
Add launch arguments and update readme
Browse files Browse the repository at this point in the history
- Add building and running instructions to readme.
- Allow username and server to be configured using launch arguments.
- Switch to using blocks-1.19.3.json instead of blocks.json so it
  doesn't try to load the wrong blocks file in the future.
- Don't load vulkan debug extension in release mode.
  • Loading branch information
atxi committed Jan 19, 2023
1 parent e141c8d commit bd35504
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bench_results
/out/build/x64-Debug cxx-17
/extras/bazel_usage_example/bazel-*
/clang
blocks.json
blocks*.json
/x64
*.spv
*.jar
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,46 @@ It uses the original assets from a user-provided Minecraft jar. Only basic block
### Screenshots
![Polymer Image](https://i.imgur.com/rAfkvtd.png)

### Running
Only runs on Windows currently.

- Requires `1.19.3.jar` from your Minecraft installation to be in the working directory. You can find this in `%appdata%/.minecraft/versions/1.19.3/`. This is used to load the textures and block models.
- Requires `blocks-1.19.3.json` that is generated from running Minecraft with a [certain flag](https://wiki.vg/Data_Generators#Generators) or from the [polymer release page](https://github.com/atxi/Polymer/releases).
- Requires compiled shaders. Get them from the release page or read the shader section below if manually building.

Running the exe will connect to localhost with the username 'polymer'. The server must be configured to be in offline mode.

You can specify the username and server ip by command line.
`polymer.exe -u username -s 127.0.0.1:25565`

Currently only a spectator camera is implemented for flying around and rendering the world. By default, you will be in the survival gamemode on the server. If you want chunks to load as you move, you need to put yourself in spectator gamemode. You can do this in the server terminal or with another client connected.

### Building
Currently only compiles on Windows, but other platforms are planned.

- C++ compiler (tested with MSVC and Clang)
- CMake
- Vulkan SDK
#### Requirements
- C++ compiler (tested with MSVC 2022 and Clang)
- [CMake](https://cmake.org/)
- [Vulkan SDK](https://www.lunarg.com/vulkan-sdk/)

#### CMake Instructions
##### GUI
- Open CMake GUI.
- Put in path to source directory.
- Choose a directory where the build will go.
- Press Configure.
- Select the generator to use. Probably `Visual Studio 17 2022` on Windows.
- Press Finish.
- Press Generate.
##### Terminal
- Create 'build' sub-directory and open terminal in it.
- `cmake .. -G "Visual Studio 17 2022"`

#### MSVC
- Browse to the build folder created from CMake.
- Open solution.
- Set to Release and x64 in the Standard Toolbar.
- Build or run.

#### Shaders
The shaders must be compiled with glslc.exe that comes with the vulkan sdk. The `compile_shaders.bat` file will compile them if `%VULKAN_SDK%` is properly set in the environment variables.
5 changes: 5 additions & 0 deletions polymer/asset/block_assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@ static u32 GetHighestStateId(json_object_s* root) {

bool AssetParser::ParseBlocks(MemoryArena* perm_arena, const char* blocks_filename) {
FILE* f = fopen(blocks_filename, "r");

if (!f) {
return false;
}

fseek(f, 0, SEEK_END);
long file_size = ftell(f);
fseek(f, 0, SEEK_SET);
Expand Down
21 changes: 6 additions & 15 deletions polymer/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,18 @@ void Connection::SetBlocking(bool blocking) {
#endif
}

void Connection::SendHandshake(u32 version, const char* address, u16 port, ProtocolState state_request) {
void Connection::SendHandshake(u32 version, const String& address, u16 port, ProtocolState state_request) {
RingBuffer& wb = write_buffer;

String sstr;
sstr.data = (char*)address;
sstr.size = strlen(address);

u32 pid = 0;

size_t size = GetVarIntSize(pid) + GetVarIntSize(version) + GetVarIntSize(sstr.size) + sstr.size + sizeof(u16) +
size_t size = GetVarIntSize(pid) + GetVarIntSize(version) + GetVarIntSize(address.size) + address.size + sizeof(u16) +
GetVarIntSize((u64)state_request);

wb.WriteVarInt(size);
wb.WriteVarInt(pid);

wb.WriteVarInt(version);
wb.WriteString(sstr);
wb.WriteString(address);
wb.WriteU16(port);
wb.WriteVarInt((u64)state_request);

Expand All @@ -158,19 +153,15 @@ void Connection::SendPingRequest() {
wb.WriteVarInt(pid);
}

void Connection::SendLoginStart(const char* username) {
void Connection::SendLoginStart(const String& username) {
RingBuffer& wb = write_buffer;

String sstr;
sstr.data = (char*)username;
sstr.size = strlen(username);

u32 pid = 0;
size_t size = GetVarIntSize(pid) + GetVarIntSize(sstr.size) + sstr.size + 1;
size_t size = GetVarIntSize(pid) + GetVarIntSize(username.size) + username.size + 1;

wb.WriteVarInt(size);
wb.WriteVarInt(pid);
wb.WriteString(sstr);
wb.WriteString(username);
wb.WriteU8(0); // HasPlayerUUID
}

Expand Down
4 changes: 2 additions & 2 deletions polymer/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ struct Connection {

TickResult Tick();

void SendHandshake(u32 version, const char* address, u16 port, ProtocolState state_request);
void SendHandshake(u32 version, const String& address, u16 port, ProtocolState state_request);
void SendPingRequest();
void SendLoginStart(const char* username);
void SendLoginStart(const String& username);
void SendKeepAlive(u64 id);
void SendTeleportConfirm(u64 id);
void SendPlayerPositionAndRotation(const Vector3f& position, float yaw, float pitch, bool on_ground);
Expand Down
2 changes: 1 addition & 1 deletion polymer/gamestate.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct PlayerManager {
size_t player_count = 0;

Player* client_player = nullptr;
char client_name[16];
char client_name[17];

void SetClientPlayer(Player* player) {
client_player = player;
Expand Down
Loading

0 comments on commit bd35504

Please sign in to comment.