Skip to content

compatibility with bazel 8.0.0 #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
common --noenable_bzlmod --enable_workspace
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.0.0
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ cc_binary(
tags = ["manual"],
deps = ["@six_archive//:six"],
) for py in [
"PY2",

"PY3",
]]

Expand Down
6 changes: 6 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
###############################################################################
# Bazel now uses Bzlmod by default to manage external dependencies.
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
#
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
###############################################################################
240 changes: 240 additions & 0 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

113 changes: 113 additions & 0 deletions assets/maps/compile_maps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import numpy as np
import os
from zipfile import ZipFile

from src.environments import DMLabBase

TMP_DIR = "/../../tmp"
# before running this, make sure there are no existing
# dmlab_temp_folder_* folders in the tmp folder from earlier
# builds

DEFAULTDECALFREQUENCY=0.1
DEFAULTRANDOMSEED=1

def get_map_names():
mypath = os.path.join(os.getcwd(), "precompile_maps/to_be_compiled")

map_names = []
for f in os.listdir(mypath):
fname, ext = f.split(".")
if ext == "txt":
map_names.append(fname)
return map_names

def get_map_information(map_name):
file_name = os.path.join(os.getcwd(),
"precompile_maps/to_be_compiled",
map_name+".txt")

map_info = {'mapName' : map_name,
'mapVariationsLayer' : "",
'decalFrequency' : DEFAULTDECALFREQUENCY,
'randomSeed' : DEFAULTRANDOMSEED}
with open(file_name, 'r') as file:
for line in file:
key,value = line[:-1].split('=')
if key in ["mapEntityLayer", "mapVariationsLayer", "texture"]:
value = value[1:-1] #remove quotation_marks
value = value.replace('\\n','\n')
else:
value = float(value)
map_info[key] = value

if "P" not in map_info['mapEntityLayer']:
print("Added spawn location, make sure map has one spawn location.")
map_info['mapEntityLayer'].replace(" ", "P")
if "A" not in map_info['mapEntityLayer']:
print("Added goal location, make sure map has one goal location.")
map_info['mapEntityLayer'].replace(" ", "A")
return map_info

def compile_map(map_info):
env = DMLabBase()

env.load_map_from_text(map_info['mapName'],
map_info['mapEntityLayer'],
map_info['mapVariationsLayer'],
map_info['decalFrequency'],
map_info['texture'],
map_info['randomSeed'])

return env

def check_no_temp_dirs():
count = 0
for f in os.listdir(TMP_DIR):
if f.startswith("dmlab_temp_folder_"):
count += 1
return count

def get_tmp_dir():
for f in os.listdir(TMP_DIR):
if f.startswith("dmlab_temp_folder_"):
return os.path.join(TMP_DIR, f, 'baselab')

def extract_bsp_file(map_name):
mypath = os.path.join(os.getcwd(), "precompile_maps/to_be_compiled")
tmp_dir = get_tmp_dir()

for f in os.listdir(tmp_dir):
zf = ZipFile(os.path.join(tmp_dir, f), 'r')
zf.extractall(tmp_dir)
zf.close()

oldplace = os.path.join(tmp_dir, "maps", map_name+".bsp")
newplace = os.path.join(os.getcwd(), "precompile_maps",
"bsp_files", map_name+".bsp")
# make sure file exists
f = open(newplace, 'a')
f.close()

os.rename(oldplace, newplace)

if __name__ == "__main__":
if check_no_temp_dirs():
print("ERROR: existing temp. folders detected.\nDelete these and try again.")
else:
# create dir where compiled bsp files will be placed
if not os.path.exists("precompile_maps/bsp_files"):
os.makedirs("precompile_maps/bsp_files")

for map_name in get_map_names():
map_info = get_map_information(map_name)
env = compile_map(map_info)
extract_bsp_file(map_name)
env.lab.close()







5 changes: 5 additions & 0 deletions assets/maps/to_be_compiled/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mapEntityLayer="*****\n*PA *\n* *\n* *\n*****"
mapVariationsLayer="*****\n*AAA*\n*AAA*\n*BBB*\n*****"
decalFrequency=0.1
randomSeed=1
texture="TETRIS"
Binary file added assets/models/goal_transparent.md3
Binary file not shown.
10 changes: 5 additions & 5 deletions game_scripts/levels/demos/random_maze.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ function api:createPickup(classname)
end

function api:start(episode, seed, params)
random:seed(seed)
local rows, cols = 15, 15
random:seed(0)
local rows, cols = 21, 21
local mazeT = generateTensorMaze(rows, cols)
local maze = maze_generation.mazeGeneration{height = rows, width = cols}
local variations = {'.', 'A', 'B', 'C'}
mazeT:applyIndexed(function(val, index)
local row, col = unpack(index)
if 1 < row and row < rows and 1 < col and col < cols and
random:uniformReal(0, 1) < 0.15 then
random:uniformReal(0, 1) < 0.75 then
maze:setEntityCell(row, col, ' ')
else
maze:setEntityCell(row, col, val == 0 and '*' or ' ')
Expand All @@ -113,7 +113,7 @@ function api:start(episode, seed, params)
if distance > 5 then
maze:setEntityCell(row, col, 'P')
end
if 0 < distance and distance < 5 then
if 0 < distance and distance < 1 then
maze:setEntityCell(row, col, 'A')
end
end
Expand All @@ -134,7 +134,7 @@ end
custom_observations.decorate(api)
setting_overrides.decorate{
api = api,
apiParams = {episodeLengthSeconds = 3 * 60, camera = {750, 750, 750}},
apiParams = {episodeLengthSeconds = 3 * 5, camera = {750, 750, 750}},
decorateWithTimeout = true
}

Expand Down
79 changes: 79 additions & 0 deletions game_scripts/levels/make_map_from_text.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
--[[ Copyright (C) 2018 Google Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
]]

-- Demonstration of creating a fixed level described using text.

local make_map = require 'common.make_map'
local pickups = require 'common.pickups'
local texture_sets = require 'themes.texture_sets'
local api = {}

--[[ Text map contents:

'P' - Player spawn point. Player is spawned with random orientation.
'A' - Apple pickup. 1 reward point when picked up.
'G' - Goal object. 10 reward points and the level restarts.
'I' - Door. Open and closes West-East corridors.
'H' - Door. Open and closes North-South corridors.
'*' - Walls.

Lights are placed randomly through out and decals are randomly placed on the
walls according to the theme.
]]
local TEXT_MAP = [[
**************
*G * A ** *
* *
***** I *
* *
* *
* * * *
* ***H*******
* P *
**************
]]

-- Called only once at start up. Settings not recognised by DM Lab internal
-- are forwarded through the params dictionary.
function api:init(params)
-- Seed the map so only one map is created with lights and decals placed in
-- the same place each run.
make_map.random():seed(1)
api._map = make_map.makeMap{
mapName = "openfield_map",
mapEntityLayer = TEXT_MAP,
useSkybox = true,
textureSet = texture_sets.TETRIS
}
end

-- `make_map` has default pickup types A = apple_reward and G = goal.
-- This callback is used to create pickups with those names.
function api:createPickup(classname)
return pickups.defaults[classname]
end

-- On first call we return the name of the map. On subsequent calls we return
-- an empty string. This informs the engine to only perform a quik map restart
-- instead.
function api:nextMap()
local mapName = api._map
api._map = ''
return mapName
end

return api
Loading