mirror of
https://github.com/UltraCoderRU/screepsxx.git
synced 2026-01-28 01:55:12 +00:00
Naive implementation of MemoryObject.
Implement GameObject.cpuGetUsed().
This commit is contained in:
parent
48806408de
commit
07c0b0ac80
3 changed files with 23 additions and 1 deletions
|
|
@ -3,12 +3,17 @@
|
|||
|
||||
#include "Object.hpp"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace Screeps {
|
||||
|
||||
class MemoryObject : public Object
|
||||
{
|
||||
public:
|
||||
MemoryObject();
|
||||
|
||||
JSON operator[](const std::string_view& key);
|
||||
void set(const std::string_view& key, const JSON& value);
|
||||
};
|
||||
|
||||
extern MemoryObject Memory;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ convertObjectToMap(const JS::Value& object)
|
|||
{
|
||||
std::map<std::string, T> map;
|
||||
for (const auto& pair : JS::jsObjectToMap(object))
|
||||
map.emplace(pair.first, T{pair.second});
|
||||
map.insert(std::make_pair(pair.first, T{pair.second}));
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
@ -107,6 +107,11 @@ int GameObject::time() const
|
|||
return value()["time"].as<int>();
|
||||
}
|
||||
|
||||
double GameObject::cpuGetUsed()
|
||||
{
|
||||
return value()["cpu"].call<double>("getUsed");
|
||||
}
|
||||
|
||||
int GameObject::cpuGeneratePixel()
|
||||
{
|
||||
return value()["cpu"].call<int>("generatePixel");
|
||||
|
|
|
|||
|
|
@ -1,9 +1,21 @@
|
|||
#include "Memory.hpp"
|
||||
|
||||
#include <Screeps/JSON.hpp>
|
||||
|
||||
namespace Screeps {
|
||||
|
||||
MemoryObject Memory;
|
||||
|
||||
MemoryObject::MemoryObject() = default;
|
||||
|
||||
JSON MemoryObject::operator[](const std::string_view& key)
|
||||
{
|
||||
return JS::toJSON(value()[key.data()]);
|
||||
}
|
||||
|
||||
void MemoryObject::set(const std::string_view& key, const JSON& value)
|
||||
{
|
||||
this->value().set(key.data(), JS::fromJSON(value));
|
||||
}
|
||||
|
||||
} // namespace Screeps
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue