Skip to content

Commit

Permalink
pull asset anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
QuanyiLi committed Aug 22, 2023
1 parent 6a844c5 commit ec28ff6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
12 changes: 0 additions & 12 deletions metadrive/engine/asset_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ def init_loader(engine):
"""
Due to the feature of Panda3d, keep reference of loader in static variable
"""
msg = "Assets folder doesn't exist. Begin to download assets..."
if not os.path.exists(AssetLoader.asset_path):
AssetLoader.logger.warning(msg)
pull_asset(False)
else:
if asset_version() != VERSION:
AssetLoader.logger.warning(
"Assets version mismatch! Current: {}, Expected: {}. "
"Update the assets by `python -m metadrive.pull_asset --update'".format(asset_version(), VERSION)
)
else:
AssetLoader.logger.info("Assets version: {}".format(VERSION))
if engine.win is None:
AssetLoader.logger.debug("Physics world mode")
return
Expand Down
19 changes: 19 additions & 0 deletions metadrive/engine/base_engine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import logging
from metadrive.version import VERSION, asset_version
import os
from metadrive.pull_asset import pull_asset
from metadrive.constants import RENDER_MODE_NONE, RENDER_MODE_OFFSCREEN, RENDER_MODE_ONSCREEN
import pickle
import time
Expand Down Expand Up @@ -28,6 +31,7 @@ class BaseEngine(EngineCore, Randomizable):
global_random_seed = None

def __init__(self, global_config):
self.try_pull_asset()
EngineCore.__init__(self, global_config)
Randomizable.__init__(self, self.global_random_seed)
self.episode_step = 0
Expand Down Expand Up @@ -685,6 +689,21 @@ def warmup(self):
barrier = None
cone = None

@staticmethod
def try_pull_asset():
msg = "Assets folder doesn't exist. Begin to download assets..."
if not os.path.exists(AssetLoader.asset_path):
AssetLoader.logger.warning(msg)
pull_asset(False)
else:
if asset_version() != VERSION:
AssetLoader.logger.warning(
"Assets version mismatch! Current: {}, Expected: {}. "
"Update the assets by `python -m metadrive.pull_asset --update'".format(asset_version(), VERSION)
)
else:
AssetLoader.logger.info("Assets version: {}".format(VERSION))


if __name__ == "__main__":
from metadrive.envs.base_env import BASE_DEFAULT_CONFIG
Expand Down

0 comments on commit ec28ff6

Please sign in to comment.