Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: Kevin Eady <8634912+KevinEady@users.noreply.github.com>
- Loading branch information
1 parent
5e5f405
commit 4ac5eac
Showing
23 changed files
with
608 additions
and
167 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
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
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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#pragma once | ||
|
||
#include <stdexcept> | ||
|
||
namespace Pol::Plib::MUL | ||
{ | ||
struct Map | ||
{ | ||
static constexpr size_t blockWidth = 8; | ||
static constexpr size_t blockHeight = 8; | ||
static constexpr size_t cellSize = 3; | ||
|
||
// DWORD + 64 cells (3 bytes) per block | ||
static constexpr size_t blockSize = 4 + cellSize * blockWidth * blockHeight; | ||
|
||
static constexpr size_t expected_blocks( int width, int height ) | ||
{ | ||
return ( width / blockWidth ) * ( height / blockHeight ); | ||
} | ||
|
||
static constexpr bool valid_size( size_t filesize, int width, int height ) | ||
{ | ||
if ( width % blockWidth != 0 ) | ||
return false; | ||
|
||
if ( height % blockHeight != 0 ) | ||
return false; | ||
|
||
size_t nblocks = filesize / Map::blockSize; | ||
return expected_blocks( width, height ) == nblocks; | ||
} | ||
}; | ||
static_assert( Map::blockSize == 196, "Size mismatch" ); | ||
static_assert( Map::valid_size( 77070336, 6144, 4096 ) ); // Legacy map | ||
static_assert( Map::valid_size( 89915392, 7168, 4096 ) ); // New maps | ||
static_assert( Map::valid_size( 77070336 - 196, 6144, 4096 ) == false ); // Wrong map 1 | ||
static_assert( Map::valid_size( 89915392 - 196, 7168, 4096 ) == false ); // Wrong map 2 | ||
|
||
class MapInfo | ||
{ | ||
int _width = 0; | ||
int _height = 0; | ||
|
||
bool _guessed_correctly = false; | ||
|
||
void set_default_size(); | ||
bool guess_size( size_t filesize ); | ||
|
||
public: | ||
int width() { return _width; } | ||
int height() { return _height; } | ||
|
||
bool guessed() { return _guessed_correctly; } | ||
bool matches_filesize() { return Map::valid_size( filesize, _width, _height ); } | ||
|
||
const int mapid = -1; | ||
const size_t filesize = 0; | ||
|
||
MapInfo( int mapid ) : mapid( mapid ) { set_default_size(); } | ||
|
||
MapInfo( int mapid, size_t filesize ) : mapid( mapid ), filesize( filesize ) | ||
{ | ||
set_default_size(); | ||
if ( _height == 0 && _width == 0 ) | ||
{ | ||
_guessed_correctly = guess_size( filesize ); | ||
} | ||
} | ||
}; | ||
|
||
|
||
inline bool MapInfo::guess_size( size_t map_size ) | ||
{ | ||
// Guessing is only implemented for britannia now | ||
if ( mapid != 0 && mapid != 1 ) | ||
return false; | ||
|
||
constexpr int map0_height = 4096; | ||
|
||
size_t mapblocks = map_size / Map::blockSize; | ||
constexpr int map0_blocks = map0_height / Map::blockHeight; | ||
|
||
// Number of blocks has to be divisible by either dimension | ||
if ( ( mapblocks % map0_blocks ) != 0 ) | ||
return false; | ||
|
||
_height = map0_height; | ||
_width = static_cast<int>( Map::blockWidth * ( mapblocks / map0_blocks ) ); | ||
|
||
return true; | ||
} | ||
|
||
|
||
inline void MapInfo::set_default_size() | ||
{ | ||
_width = 0; | ||
_height = 0; | ||
|
||
switch ( mapid ) | ||
{ | ||
case 0: // britannia / britannia-alt | ||
case 1: | ||
// depends on the filesize | ||
break; | ||
case 2: // ilshenar: | ||
_width = 2304; | ||
_height = 1600; | ||
break; | ||
case 3: // malas | ||
_width = 2560; | ||
_height = 2048; | ||
break; | ||
case 4: // tokuno | ||
_width = 1448; | ||
_height = 1448; | ||
break; | ||
case 5: // termur | ||
_width = 1280; | ||
_height = 4096; | ||
break; | ||
} | ||
} | ||
|
||
}; // namespace Pol::Plib::MUL |
Oops, something went wrong.