-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Astera-org/headlessScreenshot
- Loading branch information
Showing
23 changed files
with
309 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"editor.formatOnSave": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
mark_as_advanced(ZMQ_LIBRARY ZMQ_INCLUDE_DIR) | ||
|
||
find_path(ZMQ_INCLUDE_DIR NAMES zmq.h) | ||
message(STATUS ${ZMQPP_INCLUDE_DIR}) | ||
message(STATUS ${ZMQ_INCLUDE_DIR}) | ||
|
||
find_library(ZMQ_LIBRARY NAMES zmq) | ||
message(STATUS ${ZMQPP_LIBRARY}) | ||
message(STATUS ${ZMQ_LIBRARY}) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(Zmq DEFAULT_MSG ZMQ_LIBRARY ZMQ_INCLUDE_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import gymnasium as gym | ||
import pygame | ||
import numpy as np | ||
from minetester.minetest_env import KEY_MAP | ||
import sys | ||
|
||
# The Makefile puts the binary into build/macos | ||
minetest_executable = "/home/simon/minetest/bin/minetest" | ||
if sys.platform == "darwin": | ||
minetest_executable = ( | ||
"/Users/siboehm/repos/minetest/build/macos/minetest.app/Contents/MacOS/minetest" | ||
) | ||
|
||
env = gym.make( | ||
"minetest", | ||
minetest_executable=minetest_executable, | ||
render_mode="human", | ||
display_size=(1600, 1200), | ||
start_xvfb=True, | ||
headless=True, | ||
) | ||
env.reset() | ||
|
||
for i in range(200): | ||
print(f"i: {i}") | ||
state, reward, terminated, truncated, info = env.step( | ||
{ | ||
"KEYS": np.zeros(len(KEY_MAP), dtype=bool), | ||
"MOUSE": np.array([0.0, 0.0]), | ||
} | ||
) | ||
print( | ||
f"R: {reward} Term: {terminated} Trunc: {truncated} AllBlack: {state.sum() == 0}" | ||
) | ||
|
||
env.close() | ||
pygame.quit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import capnp | ||
import pkg_resources | ||
import zmq | ||
import numpy as np | ||
from PIL import Image | ||
|
||
""" | ||
Useful for debugging: | ||
- lldb -- /home/simon/minetest/bin/minetest --go --worldname test_world --config /home/simon/minetest/artifacts/2dd22d78-8c03-445e-83ad-8fff429569d4.conf --remote-input localhost:5555 --headless | ||
- Then run handshaker.py | ||
""" | ||
|
||
def unpack_pb_obs(received_obs: str): | ||
with remoteclient_capnp.Observation.from_bytes(received_obs) as obs_proto: | ||
# Convert the response to a numpy array | ||
img = obs_proto.image | ||
img_data = np.frombuffer(img.data, dtype=np.uint8).reshape( | ||
(img.height, img.width, 3) | ||
) | ||
# Reshape the numpy array to the correct dimensions | ||
reward = obs_proto.reward | ||
done = obs_proto.done | ||
return img_data, reward, done | ||
|
||
|
||
remoteclient_capnp = capnp.load( | ||
pkg_resources.resource_filename( | ||
"minetester", "../../src/network/proto/remoteclient.capnp" | ||
) | ||
) | ||
context = zmq.Context() | ||
socket = context.socket(zmq.REQ) | ||
socket.connect("tcp://localhost:5555") | ||
|
||
i = 0 | ||
inp = "" | ||
while inp != "stop": | ||
pb_action = remoteclient_capnp.Action.new_message() | ||
socket.send(pb_action.to_bytes()) | ||
|
||
byte_obs = socket.recv() | ||
( | ||
obs, | ||
_, | ||
_, | ||
) = unpack_pb_obs(byte_obs) | ||
|
||
# Save the observation as a PNG file | ||
if obs.size > 0: | ||
image = Image.fromarray(obs) | ||
image.save(f"observation_{i}.png") | ||
|
||
i += 1 | ||
inp = input("Stop with 'stop':") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.