<commit_before>#include "PackMeshSpr.h"
#include "PackNodeFactory.h"
#include "binary_io.h"
#include "to_int.h"
#include "PackCoords.h"

#include <easymesh.h>
#include <easybuilder.h>
namespace lua = ebuilder::lua;

#include <simp/NodeMeshSpr.h>
#include <simp/simp_types.h>

namespace esprpacker
{

PackMeshSpr::PackMeshSpr(const emesh::Sprite* spr)
{
	m_mesh = PackNodeFactory::Instance()->Create(
		dynamic_cast<const ee::Symbol*>(spr->GetSymbol()));
	m_base = PackNodeFactory::Instance()->Create(
		dynamic_cast<const ee::Symbol*>(spr->GetBaseSym()));

	//////////////////////////////////////////////////////////////////////////

	//const std::map<sm::vec2, sm::vec2, sm::Vector2Cmp>& map = spr->GetMeshTrans().GetMap();
	//m_trans_pairs.reserve(map.size() * 2);
	//std::map<sm::vec2, sm::vec2, sm::Vector2Cmp>::const_iterator itr = map.begin();
	//for ( ; itr != map.end(); ++itr) {
	//	m_trans_pairs.push_back(itr->first);
	//	m_trans_pairs.push_back(itr->second);
	//}

	//////////////////////////////////////////////////////////////////////////

// 	const s2::Mesh* mesh = dynamic_cast<const s2::MeshSymbol*>(spr->GetSymbol())->GetMesh();
// 	const std::vector<s2::MeshTriangle*>& tris = mesh->GetTriangles();
// 	const std::vector<std::pair<int, sm::vec2> >& trans = spr->GetMeshTrans().GetTrans();
// 	for (int i = 0, n = trans.size(); i < n; ++i) 
// 	{
// 		int idx = trans[i].first;
// 		int tri = idx / 3;
// 		int ver = idx - tri * 3;
// 
// 		const sm::vec2& from = tris[tri]->nodes[ver]->ori_xy;
// 		sm::vec2 to = from + trans[i].second;
// 		m_trans_pairs.push_back(from);
// 		m_trans_pairs.push_back(to);
// 	}

	//////////////////////////////////////////////////////////////////////////

	m_transform = spr->GetMeshTrans().GetTrans();
}

PackMeshSpr::~PackMeshSpr()
{
	m_mesh->RemoveReference();
	m_base->RemoveReference();
}

void PackMeshSpr::PackToLuaString(ebuilder::CodeGenerator& gen, const ee::TexturePacker& tp, float scale) const
{
	gen.line("{");
	gen.tab();

	lua::assign_with_end(gen, "type", "\"mesh_spr\"");
	lua::assign_with_end(gen, "id", ee::StringHelper::ToString(GetID()));

	lua::connect(gen, 1, 
		lua::assign("mesh_id", m_mesh->GetID()));
	lua::connect(gen, 1, 
		lua::assign("base_id", m_base->GetID()));

	
	lua::assign_with_end(gen, "trans_num", m_transform.size());
	std::stringstream ss;
	ss << "trans = {";
	for (int i = 0, n = m_transform.size(); i < n; ++i) 
	{
		int idx = m_transform[i].first;
		int16_t x = float2int(m_transform[i].second.x, 16),
			    y = float2int(m_transform[i].second.y, 16);
		ss << idx << ", " << x << ", " << y << ", ";
	}
	ss << "}";
	gen.line(ss.str());

	gen.detab();
	gen.line("},");
}

int PackMeshSpr::SizeOfUnpackFromBin() const
{
	int sz = simp::NodeMeshSpr::Size();
	sz += sizeof(uint16_t) * 3 * m_transform.size();
	return sz;
}<commit_msg>[FIXED] pack mesh spr<commit_after>#include "PackMeshSpr.h"
#include "PackNodeFactory.h"
#include "binary_io.h"
#include "to_int.h"
#include "PackCoords.h"

#include <easymesh.h>
#include <easybuilder.h>
namespace lua = ebuilder::lua;

#include <bimp/typedef.h>
#include <simp/NodeMeshSpr.h>
#include <simp/simp_types.h>

namespace esprpacker
{

PackMeshSpr::PackMeshSpr(const emesh::Sprite* spr)
{
	m_mesh = PackNodeFactory::Instance()->Create(
		dynamic_cast<const ee::Symbol*>(spr->GetSymbol()));
	m_base = PackNodeFactory::Instance()->Create(
		dynamic_cast<const ee::Symbol*>(spr->GetBaseSym()));

	//////////////////////////////////////////////////////////////////////////

	//const std::map<sm::vec2, sm::vec2, sm::Vector2Cmp>& map = spr->GetMeshTrans().GetMap();
	//m_trans_pairs.reserve(map.size() * 2);
	//std::map<sm::vec2, sm::vec2, sm::Vector2Cmp>::const_iterator itr = map.begin();
	//for ( ; itr != map.end(); ++itr) {
	//	m_trans_pairs.push_back(itr->first);
	//	m_trans_pairs.push_back(itr->second);
	//}

	//////////////////////////////////////////////////////////////////////////

// 	const s2::Mesh* mesh = dynamic_cast<const s2::MeshSymbol*>(spr->GetSymbol())->GetMesh();
// 	const std::vector<s2::MeshTriangle*>& tris = mesh->GetTriangles();
// 	const std::vector<std::pair<int, sm::vec2> >& trans = spr->GetMeshTrans().GetTrans();
// 	for (int i = 0, n = trans.size(); i < n; ++i) 
// 	{
// 		int idx = trans[i].first;
// 		int tri = idx / 3;
// 		int ver = idx - tri * 3;
// 
// 		const sm::vec2& from = tris[tri]->nodes[ver]->ori_xy;
// 		sm::vec2 to = from + trans[i].second;
// 		m_trans_pairs.push_back(from);
// 		m_trans_pairs.push_back(to);
// 	}

	//////////////////////////////////////////////////////////////////////////

	m_transform = spr->GetMeshTrans().GetTrans();
}

PackMeshSpr::~PackMeshSpr()
{
	m_mesh->RemoveReference();
	m_base->RemoveReference();
}

void PackMeshSpr::PackToLuaString(ebuilder::CodeGenerator& gen, const ee::TexturePacker& tp, float scale) const
{
	gen.line("{");
	gen.tab();

	lua::assign_with_end(gen, "type", "\"mesh_spr\"");
	lua::assign_with_end(gen, "id", ee::StringHelper::ToString(GetID()));

	lua::connect(gen, 1, 
		lua::assign("mesh_id", m_mesh->GetID()));
	lua::connect(gen, 1, 
		lua::assign("base_id", m_base->GetID()));

	
	lua::assign_with_end(gen, "trans_num", m_transform.size());
	std::stringstream ss;
	ss << "trans = {";
	for (int i = 0, n = m_transform.size(); i < n; ++i) 
	{
		int idx = m_transform[i].first;
		int16_t x = float2int(m_transform[i].second.x, 16),
			    y = float2int(m_transform[i].second.y, 16);
		ss << idx << ", " << x << ", " << y << ", ";
	}
	ss << "}";
	gen.line(ss.str());

	gen.detab();
	gen.line("},");
}

int PackMeshSpr::SizeOfUnpackFromBin() const
{
	int sz = simp::NodeMeshSpr::Size();
	sz += ALIGN_4BYTE(sizeof(uint16_t) * 3 * m_transform.size());
	return sz;
}
{'fraction_non_alphanumeric': 0.2808831259856317, 'fraction_numerical': 0.010688628000700893, 'mean_word_length': 3.1482558139534884, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1207102', 'n_tokens_mistral': 2236, 'n_tokens_neox': 2133, 'n_words': 353}