Skip to content

Commit

Permalink
- pulled in the ZScript map fixes from GZDoom.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Dec 11, 2022
1 parent e412a34 commit fbf5cdc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
20 changes: 18 additions & 2 deletions source/common/scripting/core/maps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,15 @@ template<typename M> void MapInsert(M * self, expand_types_vm<typename M::KeyTyp
MAP_GC_WRITE_BARRIER(self);
GC::WriteBarrier(value);
}
self->Insert(key, value);

if constexpr(std::is_same_v<typename M::ValueType, float>)
{
self->Insert(key,static_cast<float>(value));
}
else
{
self->Insert(key, value);
}
self->info->rev++; // invalidate iterators
}

Expand Down Expand Up @@ -246,7 +254,15 @@ template<typename I> void MapIteratorSetValue(I * self, expand_types_vm<typename
GC::WriteBarrier(val);
GC::WriteBarrier(value);
}
val = value;

if constexpr(std::is_same_v<typename I::ValueType, float>)
{
val = static_cast<float>(value);
}
else
{
val = value;
}
}


Expand Down
12 changes: 1 addition & 11 deletions source/common/scripting/core/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2399,10 +2399,6 @@ void PMap::Construct(void * addr) const {

void PMap::InitializeValue(void *addr, const void *def) const
{
if (def != nullptr)
{
I_Error("Map cannot have default values");
}
Construct(addr);
}

Expand Down Expand Up @@ -2475,7 +2471,6 @@ void PMap::DestroyValue(void *addr) const

void PMap::SetDefaultValue(void *base, unsigned offset, TArray<FTypeAndOffset> *special)
{
assert(!(base && special));
if (base != nullptr)
{
Construct(((uint8_t*)base)+offset); // is this needed? string/dynarray do this initialization if base != nullptr, but their initialization doesn't need to allocate
Expand Down Expand Up @@ -2603,7 +2598,7 @@ template<typename M>
static bool PMapValueReader(FSerializer &ar, M *map, const PMap *m)
{
const char * k;
while(k = ar.GetKey())
while((k = ar.GetKey()))
{
typename M::ValueType * val;
if constexpr(std::is_same_v<typename M::KeyType,FString>)
Expand Down Expand Up @@ -2868,10 +2863,6 @@ void PMapIterator::Construct(void * addr) const {

void PMapIterator::InitializeValue(void *addr, const void *def) const
{
if (def != nullptr)
{
I_Error("Map cannot have default values");
}
Construct(addr);
}

Expand Down Expand Up @@ -2944,7 +2935,6 @@ void PMapIterator::DestroyValue(void *addr) const

void PMapIterator::SetDefaultValue(void *base, unsigned offset, TArray<FTypeAndOffset> *special)
{
assert(!(base && special));
if (base != nullptr)
{
Construct(((uint8_t*)base)+offset);
Expand Down

0 comments on commit fbf5cdc

Please sign in to comment.