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