#include "FrameCounter.hpp"
#include "State.hpp"
#include "StateControl.hpp"
+#include "TextureIndex.hpp"
#include "init.hpp"
#include "../audio/Sound.hpp"
void Application::Update(int dt) {
env.counter.EnterUpdate();
+ env.audio.Update(dt);
if (HasState()) {
GetState().Update(dt);
}
}
-void Assets::LoadBlockTypes(const std::string &set_name, BlockTypeRegistry ®) const {
+void Assets::LoadBlockTypes(const std::string &set_name, BlockTypeRegistry ®, TextureIndex &tex_index) const {
string full = data + set_name + ".types";
std::ifstream file(full);
if (!file) {
if (name == "visible") {
type.visible = in.GetBool();
} else if (name == "texture") {
- // TODO: load textures as requested
in.ReadString(tex_name);
- if (tex_name == "rock-1") {
- type.texture = 1;
- } else if (tex_name == "rock-2") {
- type.texture = 2;
- } else if (tex_name == "rock-3") {
- type.texture = 3;
- } else if (tex_name == "debug") {
- type.texture = 0;
- } else {
- throw runtime_error("unknown texture: " + tex_name);
- }
+ type.texture = tex_index.GetID(tex_name);
} else if (name == "color") {
in.ReadVec(type.color);
+ } else if (name == "outline") {
+ in.ReadVec(type.outline_color);
} else if (name == "label") {
in.ReadString(type.label);
} else if (name == "luminosity") {
SDL_FreeSurface(srf);
}
+void Assets::LoadTextures(const TextureIndex &index, ArrayTexture &tex) const {
+ // TODO: where the hell should that size come from?
+ tex.Reserve(16, 16, index.Size(), Format());
+ for (const auto &entry : index.Entries()) {
+ LoadTexture(entry.first, tex, entry.second);
+ }
+}
+
+
+TextureIndex::TextureIndex()
+: id_map() {
+
+}
+
+int TextureIndex::GetID(const string &name) {
+ auto entry = id_map.find(name);
+ if (entry == id_map.end()) {
+ auto result = id_map.emplace(name, Size());
+ return result.first->second;
+ } else {
+ return entry->second;
+ }
+}
+
void FrameCounter::EnterFrame() noexcept {
last_enter = SDL_GetTicks();