Fix weird bug (dont use vscode)
This commit is contained in:
parent
d0a5b55ae8
commit
18a80874df
@ -86,15 +86,12 @@ defmodule Amethyst.ConnectionHandler do
|
||||
chunks = MapSet.new(visible_chunks_from(elem(cp, 0), elem(cp, 1), Map.get(state, :view_distance, 16)))
|
||||
new_chunks = MapSet.difference(chunks, prev_chunks)
|
||||
# We can process all chunks in parallel
|
||||
# me = self()
|
||||
# Task.Supervisor.async_stream(state |> Map.get(:game) |> Map.get(:refs) |> Map.get(:task_supervisor),
|
||||
# new_chunks,
|
||||
# fn chunk -> process_chunk(me, chunk, state) end,
|
||||
# [ordered: false]
|
||||
# ) |> Stream.run()
|
||||
if new_chunks |> Enum.map(&process_chunk(self(), &1, state)) |> Enum.any?(&(&1 != :ok)) do
|
||||
Logger.error("something happened while processing chunks")
|
||||
end
|
||||
me = self()
|
||||
Task.Supervisor.async_stream(state |> Map.get(:game) |> Map.get(:refs) |> Map.get(:task_supervisor),
|
||||
new_chunks,
|
||||
fn chunk -> process_chunk(me, chunk, state) end,
|
||||
[ordered: false]
|
||||
) |> Stream.run()
|
||||
end
|
||||
loop(socket, connstate, version, state)
|
||||
{:send_packet, packet} ->
|
||||
@ -156,19 +153,17 @@ defmodule Amethyst.ConnectionHandler do
|
||||
Map.new(fn {i, v} -> {v, i} end)
|
||||
paletted_blocks = blocks |>
|
||||
Enum.map(&(Map.get(palette, &1)))
|
||||
Logger.debug("got here")
|
||||
paletted_data = long_aligned_bit_string_reduce(paletted_blocks, bpe)
|
||||
|
||||
Write.ubyte(bpe) <>
|
||||
Write.varint(map_size(palette)) <>
|
||||
Enum.reduce(0..map_size(palette), "", fn i, acc ->
|
||||
Enum.reduce(0..(map_size(palette)-1), "", fn i, acc ->
|
||||
acc <> Write.varint(Map.get(palette, i))
|
||||
end) <>
|
||||
Write.varint(floor(bit_size(paletted_data) / 64)) <>
|
||||
paletted_data
|
||||
_ ->
|
||||
# DIRECT
|
||||
Logger.debug("got here with bpe #{min_bpe}")
|
||||
data = long_aligned_bit_string_reduce(blocks, 15)
|
||||
Write.ubyte(15) <>
|
||||
Write.varint(floor(bit_size(data) / 64)) <>
|
||||
@ -179,7 +174,6 @@ defmodule Amethyst.ConnectionHandler do
|
||||
acc <> Write.short(block_count) <> paletted_container_data <> <<0::8, 0::8>>
|
||||
end)
|
||||
|
||||
Logger.debug("Asking to send chunk packet...")
|
||||
send(to, {:send_packet, %{
|
||||
packet_type: :chunk_data_and_update_light,
|
||||
chunk_x: cx, chunk_z: cz,
|
||||
@ -198,12 +192,12 @@ defmodule Amethyst.ConnectionHandler do
|
||||
end
|
||||
|
||||
defp long_aligned_bit_string_reduce(values, bpe) do
|
||||
values |> Enum.reduce("", fn value, acc ->
|
||||
next = acc <> <<value::size(bpe)-big>>
|
||||
values |> Enum.reduce(<<>>, fn value, acc ->
|
||||
next = <<acc::bitstring, value::size(bpe)-big>>
|
||||
# man i hope they dont suddenly change the size of a long
|
||||
if rem(bit_size(next), 64) + bpe < 64 do
|
||||
# gotta pad it
|
||||
next <> <<0::big-size(64 - rem(bit_size(next), 64))>>
|
||||
<<next::bitstring, 0::big-size(64 - rem(bit_size(next), 64))>>
|
||||
else
|
||||
next
|
||||
end
|
||||
|
@ -40,8 +40,8 @@ defmodule Example.Game do
|
||||
end
|
||||
|
||||
@impl true
|
||||
def chunk(from, {x, z}, _state_refs) do
|
||||
Logger.info("Player at #{inspect(from)} wants to know chunk #{x}, #{z}")
|
||||
def chunk(_from, {x, z}, _state_refs) do
|
||||
# Logger.info("Player at #{inspect(from)} wants to know chunk #{x}, #{z}")
|
||||
(0..255) |> Enum.map(fn y ->
|
||||
if y < 5 do
|
||||
(0..15) |> Enum.map(fn _z ->
|
||||
|
@ -10,5 +10,5 @@
|
||||
import Config
|
||||
config :logger, :console,
|
||||
level: :debug,
|
||||
format: "$date $time [$level] $metadata$message",
|
||||
format: "$date $time [$level] $metadata$message\n",
|
||||
metadata: []
|
||||
|
Loading…
Reference in New Issue
Block a user