Skip to content

Commit

Permalink
Allow map size of the generator params to be non power of 2 (#844)
Browse files Browse the repository at this point in the history
* Only enforce that the param size needs to be a multiple of 64

* Add test and fix modulus

* Fix tests
  • Loading branch information
Sheikah45 authored Sep 27, 2021
1 parent 4f54f25 commit 7be92f1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions server/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def of(cls, params: dict, weight: int = 1):
if map_size_pixels <= 0:
raise Exception("Map size is zero or negative")

if map_size_pixels & (map_size_pixels - 1) != 0:
raise Exception("Map size is not a power of 2")
if map_size_pixels % 64 != 0:
raise Exception("Map size is not a multiple of 64")

spawns = int(params["spawns"])
if spawns % 2 != 0:
Expand Down
1 change: 1 addition & 0 deletions tests/data/test-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ insert into map_pool_map_version (map_pool_id, map_version_id, weight, map_param
(2, 11, 1, NULL), (2, 14, 1, NULL), (2, 15, 1, NULL), (2, 16, 1, NULL), (2, 17, 1, NULL),
(3, 1, 1, NULL), (3, 2, 1, NULL), (3, 3, 1, NULL),
(4, NULL, 1, '{"type": "neroxis", "size": 512, "spawns": 2, "version": "0.0.0"}'),
(4, NULL, 1, '{"type": "neroxis", "size": 768, "spawns": 2, "version": "0.0.0"}'),
-- Bad Generated Map Parameters should not be included in pool
(4, NULL, 1, '{"type": "neroxis", "size": 513, "spawns": 2, "version": "0.0.0"}'),
(4, NULL, 1, '{"type": "neroxis", "size": 0, "spawns": 2, "version": "0.0.0"}'),
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/test_matchmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async def test_game_launch_message_map_generator(lobby_server):

assert msg1["mapname"] == msg2["mapname"]
assert re.match(
"neroxis_map_generator_0.0.0_[0-9a-z]{13}_aiea",
"neroxis_map_generator_0.0.0_[0-9a-z]{13}_[0-9a-z]{4}",
msg1["mapname"]
)

Expand Down
6 changes: 6 additions & 0 deletions tests/unit_tests/test_ladder_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ async def test_load_from_database(ladder_service, queue_factory):
"size": 512,
"type": "neroxis"
}),
NeroxisGeneratedMap.of({
"version": "0.0.0",
"spawns": 2,
"size": 768,
"type": "neroxis"
}),
]

queue = ladder_service.queues["gameoptions"]
Expand Down

0 comments on commit 7be92f1

Please sign in to comment.