Skip to content

Add support for h2d file format with first data file #3828

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

Merged
merged 19 commits into from
Aug 19, 2021
Merged

Add support for h2d file format with first data file #3828

merged 19 commits into from
Aug 19, 2021

Conversation

ihhub
Copy link
Owner

@ihhub ihhub commented Jul 11, 2021

image

- fix farm rendering in Knight castle (#2059)
- add missing farm sprite made by our artist
@ihhub ihhub added improvement New feature, request or improvement ui UI/GUI related stuff original assets Original game data related stuff labels Jul 11, 2021
@ihhub ihhub added this to the 0.9.6 milestone Jul 11, 2021
@ihhub ihhub self-assigned this Jul 11, 2021
@ihhub
Copy link
Owner Author

ihhub commented Jul 12, 2021

Hi @oleg-derevenetz and @idshibanov , this is the first step for storing any data files for the upcoming add-on so could you please light out your opinion about the way how we can store files?

@oleg-derevenetz
Copy link
Collaborator

Hi @oleg-derevenetz and @idshibanov , this is the first step for storing any data files for the upcoming add-on so could you please light out your opinion about the way how we can store files?

Hi @ihhub Is there a reason to store them as a separate files? Why not store them in binary itself as a some sort of resources (for example, as trivial const char * or std::array<char> arrays)?

@ihhub
Copy link
Owner Author

ihhub commented Jul 12, 2021

Hi @oleg-derevenetz and @idshibanov , this is the first step for storing any data files for the upcoming add-on so could you please light out your opinion about the way how we can store files?

Hi @ihhub Is there a reason to store them as a separate files? Why not store them in binary itself as a some sort of resources (for example, as trivial const char * or std::array<char> arrays)?

In the future we're going to add much more resources including new monsters or sounds for example. We're talking about megabytes of data. I don't think that keeping them in binary would be the best solution.

Copy link
Collaborator

@oleg-derevenetz oleg-derevenetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ihhub LGTM in general, left just two notes.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions


for ( const auto & data : _fileData ) {
fileStream.putRaw( reinterpret_cast<const char *>( data.second.data() ), data.second.size() );
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use reinterpret_cast [cppcoreguidelines-pro-type-reinterpret-cast]

fileStream.putRaw( reinterpret_cast<const char *>( data.second.data() ), data.second.size() );
                   ^

image.resize( width, height );
memcpy( image.image(), data.data() + 4 + 4 + 4 + 4, size );
memcpy( image.transform(), data.data() + 4 + 4 + 4 + 4 + size, size );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]

memcpy( image.transform(), data.data() + 4 + 4 + 4 + 4 + size, size );
                                       ^

image.resize( width, height );
memcpy( image.image(), data.data() + 4 + 4 + 4 + 4, size );
memcpy( image.transform(), data.data() + 4 + 4 + 4 + 4 + size, size );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]

memcpy( image.transform(), data.data() + 4 + 4 + 4 + 4 + size, size );
                                           ^

image.resize( width, height );
memcpy( image.image(), data.data() + 4 + 4 + 4 + 4, size );
memcpy( image.transform(), data.data() + 4 + 4 + 4 + 4 + size, size );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]

memcpy( image.transform(), data.data() + 4 + 4 + 4 + 4 + size, size );
                                               ^

image.resize( width, height );
memcpy( image.image(), data.data() + 4 + 4 + 4 + 4, size );
memcpy( image.transform(), data.data() + 4 + 4 + 4 + 4 + size, size );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]

memcpy( image.transform(), data.data() + 4 + 4 + 4 + 4 + size, size );
                                                   ^

image.resize( width, height );
memcpy( image.image(), data.data() + 4 + 4 + 4 + 4, size );
memcpy( image.transform(), data.data() + 4 + 4 + 4 + 4 + size, size );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]

memcpy( image.transform(), data.data() + 4 + 4 + 4 + 4 + size, size );
                                                       ^

@ihhub
Copy link
Owner Author

ihhub commented Jul 14, 2021

Hi @oleg-derevenetz , looks like we have to disable cppcoreguidelines-pro-bounds-pointer-arithmetic, modernize-use-auto and cppcoreguidelines-pro-type-reinterpret-cast clang-tidy checks.

@oleg-derevenetz
Copy link
Collaborator

oleg-derevenetz commented Jul 14, 2021

@ihhub

looks like we have to disable cppcoreguidelines-pro-bounds-pointer-arithmetic, modernize-use-auto and cppcoreguidelines-pro-type-reinterpret-cast clang-tidy checks.

Yes, I agree regarding the first two checks, but regarding the cppcoreguidelines-pro-type-reinterpret-cast... This cast is really dangerous (although it may be used when casting to char*) so may be leave it and just check twice on warning and if everything is OK just ignore it?

@ihhub
Copy link
Owner Author

ihhub commented Jul 14, 2021

@ihhub

looks like we have to disable cppcoreguidelines-pro-bounds-pointer-arithmetic, modernize-use-auto and cppcoreguidelines-pro-type-reinterpret-cast clang-tidy checks.

Yes, I agree regarding the first two checks, but regarding the cppcoreguidelines-pro-type-reinterpret-cast... This cast is really dangerous (although it may be used when casting to char*) so may be leave it and just check twice on warning and if everything is OK just ignore it?

Sure. Let's do this way.

@ihhub ihhub modified the milestones: 0.9.6, 0.9.7 Aug 6, 2021
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ clang-tidy found issue(s) with the introduced code (1/1)

const int32_t height = static_cast<int32_t>( stream.getLE32() );
const int32_t x = static_cast<int32_t>( stream.getLE32() );
const int32_t y = static_cast<int32_t>( stream.getLE32() );
if ( static_cast<size_t>( width * height * 2 + 4 + 4 + 4 + 4 ) != data.size() ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ bugprone-misplaced-widening-cast ⚠️
either cast from 'int' to 'size_t' (aka 'unsigned long') is ineffective, or there is loss of precision before the conversion

return false;
}

const size_t size = static_cast<size_t>( width * height );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ bugprone-misplaced-widening-cast ⚠️
either cast from 'int' to 'size_t' (aka 'unsigned long') is ineffective, or there is loss of precision before the conversion

@ihhub ihhub marked this pull request as draft August 14, 2021 15:50
@ihhub ihhub requested a review from oleg-derevenetz August 15, 2021 02:47
@ihhub
Copy link
Owner Author

ihhub commented Aug 15, 2021

Hi @oleg-derevenetz , I addressed your comment. Could you please take a look?

Right now it's not obvious why we need h2d file but in the future with add-on development (which started not long time ago) we have to ship all new assets altogether. To reduce user errors such missing files during copying.

@ihhub ihhub marked this pull request as ready for review August 15, 2021 02:51
@ihhub
Copy link
Owner Author

ihhub commented Aug 15, 2021

Hi @Branikolog , could you please also test these changes? Just install a fresh version of the game and check a town with the farm in Knight castle.

@Branikolog
Copy link
Collaborator

Hi, @ihhub
Everything seems ok. Farm is fully drawn. Castle is being built correctly over it.
Only a few remarks I can add here:
New part of a farm is not clickable. We've already have an issue with farm, as we should click only small area inside it to initiate info window to appear (As well as may other castle objects). So now this too tiny area becomes even more obvious.
Also, I think in future, we can change farm icon in castle building window, so it would introduce full field sprite, while the original icon shows only part:
image

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ clang-tidy found issue(s) with the introduced code (1/1)

}

for ( const auto & data : _fileData ) {
fileStream.putRaw( reinterpret_cast<const char *>( data.second.data() ), data.second.size() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ cppcoreguidelines-pro-type-reinterpret-cast ⚠️
do not use reinterpret_cast

const int32_t height = static_cast<int32_t>( stream.getLE32() );
const int32_t x = static_cast<int32_t>( stream.getLE32() );
const int32_t y = static_cast<int32_t>( stream.getLE32() );
if ( static_cast<size_t>( width * height * 2 + 4 + 4 + 4 + 4 ) != data.size() ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ bugprone-misplaced-widening-cast ⚠️
either cast from int to size_t (aka unsigned long) is ineffective, or there is loss of precision before the conversion

return false;
}

const size_t size = static_cast<size_t>( width * height );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ bugprone-misplaced-widening-cast ⚠️
either cast from int to size_t (aka unsigned long) is ineffective, or there is loss of precision before the conversion

@@ -289,7 +289,7 @@ namespace CastleDialog
}

private:
uint32_t _alpha;
uint8_t _alpha;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ modernize-use-default-member-init ⚠️
use default member initializer for _alpha

Suggested change
uint8_t _alpha;
uint8_t _alpha{ 255 };

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement New feature, request or improvement original assets Original game data related stuff ui UI/GUI related stuff
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Only half of a farm is drawn in Knight city without castle
3 participants