From f2e23b29c6c95763aa8aaa9ccae3c6c2e3fafb13 Mon Sep 17 00:00:00 2001 From: Michael Serajnik Date: Mon, 18 Mar 2024 05:58:17 +0100 Subject: [PATCH] Determine list of maps programmatically in mmap_extract.py. (#2541) --- contrib/mmap/mmap_extract.py | 189 +++++++++++++++++++++++++++-------- 1 file changed, 148 insertions(+), 41 deletions(-) mode change 100644 => 100755 contrib/mmap/mmap_extract.py diff --git a/contrib/mmap/mmap_extract.py b/contrib/mmap/mmap_extract.py old mode 100644 new mode 100755 index 01d1da2e144..bf5fe03cbc1 --- a/contrib/mmap/mmap_extract.py +++ b/contrib/mmap/mmap_extract.py @@ -1,57 +1,164 @@ -#!/usr/bin/python +#!/usr/bin/env python """ - This file is part of the CMaNGOS Project. See AUTHORS file for Copyright information +This file is part of the CMaNGOS Project. See AUTHORS file for Copyright information - 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 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. +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -import os, sys, threading, time, subprocess -from multiprocessing import cpu_count +import pathlib +import struct +import subprocess +import sys +import threading +import time +import typing from collections import deque +from multiprocessing import cpu_count + +# https://github.com/vmangos/core/blob/5e142e104c8033cd0505cf8e060f37e263f503fe/src/game/vmap/ModelInstance.h#L40 +MOD_HAS_BOUND = 1 << 2 +# mapID, tileX, tileY, Flags, adtID, ID, Pos, Rot, Scale, Bound_lo, Bound_hi, name +INTRO_STRUCT_FORMAT = " 0): - if (threading.active_count() <= cpu): - workerThread(mapList.popleft()).start() + # Read map IDs from dir_bin + map_ids = set() + with (pathlib.Path("Buildings") / "dir_bin").open("rb") as file: + while True: + try: + spawn = read_spawn(file) + except struct.error: + # EOF + break + + if spawn.map_id not in map_ids: + map_ids.add(spawn.map_id) + + # Process maps + max_workers = max(cpu_count() - 0, 1) # You can reduce the load by putting 1 instead of 0 if you need to free 1 core/cpu + print("I will always maintain", max_workers, "MoveMapGen tasks running in background.\n") + map_queue = deque(map_ids) + while map_queue: + if threading.active_count() <= max_workers: + WorkerThread(map_queue.popleft()).start() + time.sleep(0.1)