/*
 * Copyright 2023 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
 */

#pragma once

#include <nostalgia/gfx/context.hpp>

#include "worldstatic.hpp"

namespace jasper::world {

namespace ngfx = nostalgia::gfx;

class World {
	private:
		struct ObjState {
			uint16_t objIdx{};
			uint16_t frame{};
			turbine::TimeMs nextUpdateTime{};
		};
		ngfx::Context &m_nctx;
		WorldStatic const &m_worldStatic;
		ox::Vector<keel::AssetRef<ngfx::CompactTileSheet>, 32> m_tilesheets;
		ox::Vector<ObjState, 128> m_objStates;
		turbine::TimeMs m_currentTicks{};

	public:
		explicit World(ngfx::Context &nctx, WorldStatic const &worldStatic) noexcept;

		ox::Error setupDisplay() noexcept;

		ox::Result<int> update() noexcept;

		void setupTiles() noexcept;

		void setupTile(uint32_t lyr, uint32_t x, uint32_t y) noexcept;

	private:
		ox::Result<turbine::TimeMs> updateObj(ObjState &state) noexcept;

		void setupLayer(uint_t lyr, uint_t cbb) noexcept;

};

}
