Skip to content

Commit

Permalink
MSVC fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusikkala committed Nov 16, 2023
1 parent 44da44d commit 91899dc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
29 changes: 19 additions & 10 deletions monkeroecs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ SOFTWARE.
#include <bitset>
#endif

// Thanks, MSVC -.-
#ifdef min
#undef min
#endif

#ifdef max
#undef max
#endif

/** This namespace contains all of MonkeroECS. */
namespace monkero
{
Expand Down Expand Up @@ -225,7 +234,7 @@ struct component_bucket_exp_hint
{
uint32_t i = 6;
// Aim for 65kb buckets
while((std::max(sizeof(T), 4lu)<<i) < 65536lu)
while((std::max(sizeof(T), std::uint64_t(4))<<i) < std::uint64_t(65536))
++i;
return i;
}
Expand Down Expand Up @@ -1035,7 +1044,7 @@ void component_container<T>::finish_batch()
entity& id = batch_checklist[ri];
entity hi = id >> bucket_exp;
entity lo = id & bucket_mask;
bitmask_type bit = 1lu<<(lo&bitmask_mask);
bitmask_type bit = std::uint64_t(1)<<(lo&bitmask_mask);
bitmask_type* bbit = bucket_batch_bitmask[hi];
if(bbit && (bbit[lo>>bitmask_shift] & bit))
{ // Not a dupe, but latest state.
Expand All @@ -1053,7 +1062,7 @@ void component_container<T>::finish_batch()

entity hi = id >> bucket_exp;
entity lo = id & bucket_mask;
bitmask_type bit = 1lu<<(lo&bitmask_mask);
bitmask_type bit = std::uint64_t(1)<<(lo&bitmask_mask);
if(bucket_bitmask[hi] && (bucket_bitmask[hi][lo>>bitmask_shift] & bit))
{ // Erase
bitmask_erase(id);
Expand Down Expand Up @@ -1324,19 +1333,19 @@ void component_container<T>::bitmask_insert(entity id)
ensure_bitmask(hi);
bitmask_type& mask = bucket_bitmask[hi][lo>>bitmask_shift];
if(mask == 0)
top_bitmask[hi>>bitmask_shift] |= 1lu<<(hi&bitmask_mask);
mask |= 1lu<<(lo&bitmask_mask);
top_bitmask[hi>>bitmask_shift] |= std::uint64_t(1)<<(hi&bitmask_mask);
mask |= std::uint64_t(1)<<(lo&bitmask_mask);
}

template<typename T>
bool component_container<T>::bitmask_erase(entity id)
{
std::uint32_t hi = id >> bucket_exp;
std::uint32_t lo = id & bucket_mask;
bucket_bitmask[hi][lo>>bitmask_shift] &= ~(1lu<<(lo&bitmask_mask));
bucket_bitmask[hi][lo>>bitmask_shift] &= ~(std::uint64_t(1)<<(lo&bitmask_mask));
if(bucket_bitmask[hi][lo>>bitmask_shift] == 0 && bitmask_empty(hi))
{
top_bitmask[hi>>bitmask_shift] &= ~(1lu<<(hi&bitmask_mask));
top_bitmask[hi>>bitmask_shift] &= ~(std::uint64_t(1)<<(hi&bitmask_mask));
return true;
}
return false;
Expand Down Expand Up @@ -1542,7 +1551,7 @@ bool component_container<T>::batch_change(entity id)
);
}
bitmask_type& mask = bucket_batch_bitmask[hi][lo>>bitmask_shift];
bitmask_type bit = 1lu<<(lo&bitmask_mask);
bitmask_type bit = std::uint64_t(1)<<(lo&bitmask_mask);
mask ^= bit;
if(mask & bit)
{ // If there will be a change, add this to the list.
Expand Down Expand Up @@ -1665,7 +1674,7 @@ bool component_container<T>::find_bitmask_previous_index(
return false;

std::uint32_t bm_index = index >> bitmask_shift;
bitmask_type bm_mask = (1lu<<(index&bitmask_mask))-1;
bitmask_type bm_mask = (std::uint64_t(1)<<(index&bitmask_mask))-1;
bitmask_type cur_mask = bitmask[bm_index] & bm_mask;
if(cur_mask != 0)
{
Expand Down Expand Up @@ -1789,7 +1798,7 @@ bool component_container<T>::iterator::try_advance(entity id)
id < current_entity ||
next_bucket >= from->bucket_count ||
!from->bucket_bitmask[next_bucket] ||
!(from->bucket_bitmask[next_bucket][lo>>bitmask_shift] & (1lu << (lo&bitmask_mask)))
!(from->bucket_bitmask[next_bucket][lo>>bitmask_shift] & (std::uint64_t(1) << (lo&bitmask_mask)))
) return false;

current_entity = id;
Expand Down
2 changes: 1 addition & 1 deletion multi/container.hh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct component_bucket_exp_hint
{
uint32_t i = 6;
// Aim for 65kb buckets
while((std::max(sizeof(T), 4lu)<<i) < 65536lu)
while((std::max(sizeof(T), std::uint64_t(4))<<i) < std::uint64_t(65536))
++i;
return i;
}
Expand Down
18 changes: 9 additions & 9 deletions multi/container.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void component_container<T>::finish_batch()
entity& id = batch_checklist[ri];
entity hi = id >> bucket_exp;
entity lo = id & bucket_mask;
bitmask_type bit = 1lu<<(lo&bitmask_mask);
bitmask_type bit = std::uint64_t(1)<<(lo&bitmask_mask);
bitmask_type* bbit = bucket_batch_bitmask[hi];
if(bbit && (bbit[lo>>bitmask_shift] & bit))
{ // Not a dupe, but latest state.
Expand All @@ -260,7 +260,7 @@ void component_container<T>::finish_batch()

entity hi = id >> bucket_exp;
entity lo = id & bucket_mask;
bitmask_type bit = 1lu<<(lo&bitmask_mask);
bitmask_type bit = std::uint64_t(1)<<(lo&bitmask_mask);
if(bucket_bitmask[hi] && (bucket_bitmask[hi][lo>>bitmask_shift] & bit))
{ // Erase
bitmask_erase(id);
Expand Down Expand Up @@ -531,19 +531,19 @@ void component_container<T>::bitmask_insert(entity id)
ensure_bitmask(hi);
bitmask_type& mask = bucket_bitmask[hi][lo>>bitmask_shift];
if(mask == 0)
top_bitmask[hi>>bitmask_shift] |= 1lu<<(hi&bitmask_mask);
mask |= 1lu<<(lo&bitmask_mask);
top_bitmask[hi>>bitmask_shift] |= std::uint64_t(1)<<(hi&bitmask_mask);
mask |= std::uint64_t(1)<<(lo&bitmask_mask);
}

template<typename T>
bool component_container<T>::bitmask_erase(entity id)
{
std::uint32_t hi = id >> bucket_exp;
std::uint32_t lo = id & bucket_mask;
bucket_bitmask[hi][lo>>bitmask_shift] &= ~(1lu<<(lo&bitmask_mask));
bucket_bitmask[hi][lo>>bitmask_shift] &= ~(std::uint64_t(1)<<(lo&bitmask_mask));
if(bucket_bitmask[hi][lo>>bitmask_shift] == 0 && bitmask_empty(hi))
{
top_bitmask[hi>>bitmask_shift] &= ~(1lu<<(hi&bitmask_mask));
top_bitmask[hi>>bitmask_shift] &= ~(std::uint64_t(1)<<(hi&bitmask_mask));
return true;
}
return false;
Expand Down Expand Up @@ -749,7 +749,7 @@ bool component_container<T>::batch_change(entity id)
);
}
bitmask_type& mask = bucket_batch_bitmask[hi][lo>>bitmask_shift];
bitmask_type bit = 1lu<<(lo&bitmask_mask);
bitmask_type bit = std::uint64_t(1)<<(lo&bitmask_mask);
mask ^= bit;
if(mask & bit)
{ // If there will be a change, add this to the list.
Expand Down Expand Up @@ -872,7 +872,7 @@ bool component_container<T>::find_bitmask_previous_index(
return false;

std::uint32_t bm_index = index >> bitmask_shift;
bitmask_type bm_mask = (1lu<<(index&bitmask_mask))-1;
bitmask_type bm_mask = (std::uint64_t(1)<<(index&bitmask_mask))-1;
bitmask_type cur_mask = bitmask[bm_index] & bm_mask;
if(cur_mask != 0)
{
Expand Down Expand Up @@ -996,7 +996,7 @@ bool component_container<T>::iterator::try_advance(entity id)
id < current_entity ||
next_bucket >= from->bucket_count ||
!from->bucket_bitmask[next_bucket] ||
!(from->bucket_bitmask[next_bucket][lo>>bitmask_shift] & (1lu << (lo&bitmask_mask)))
!(from->bucket_bitmask[next_bucket][lo>>bitmask_shift] & (std::uint64_t(1) << (lo&bitmask_mask)))
) return false;

current_entity = id;
Expand Down

0 comments on commit 91899dc

Please sign in to comment.