Version 0.2.0
Fixed Size/UV Issues Atlas builder Calculate UVS during Packing Fix File loader loading height into width Set Atlas Size on File load Push Entries on File load Only build palladium, if it is not in build space Add functionality to d7rc-make to check files and create files Fix Palladium Submodule Integration
This commit is contained in:
		
							
								
								
									
										2
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							| @@ -1,3 +1,3 @@ | |||||||
| [submodule "palladium"] | [submodule "vendor/palladium"] | ||||||
| 	path = vendor/palladium | 	path = vendor/palladium | ||||||
| 	url = https://dev.npid7.de/tobid7/palladium | 	url = https://dev.npid7.de/tobid7/palladium | ||||||
|   | |||||||
| @@ -1,11 +1,13 @@ | |||||||
| cmake_minimum_required(VERSION 3.22) | cmake_minimum_required(VERSION 3.22) | ||||||
|  |  | ||||||
| project(d7rc VERSION 0.1.0) | project(d7rc VERSION 0.2.0) | ||||||
|  |  | ||||||
| set(CMAKE_CXX_STANDARD 20) | set(CMAKE_CXX_STANDARD 20) | ||||||
| set(CMAKE_CXX_STANDARD_REQUIRED true) | set(CMAKE_CXX_STANDARD_REQUIRED true) | ||||||
|  |  | ||||||
|  | if(NOT TARGET palladium) | ||||||
| add_subdirectory(vendor/palladium) | add_subdirectory(vendor/palladium) | ||||||
|  | endif() | ||||||
|  |  | ||||||
| add_library(${PROJECT_NAME} | add_library(${PROJECT_NAME} | ||||||
|     source/lib/file.cpp |     source/lib/file.cpp | ||||||
| @@ -27,3 +29,5 @@ add_executable(${PROJECT_NAME}-make | |||||||
| target_include_directories(${PROJECT_NAME}-make PRIVATE palladium include) | target_include_directories(${PROJECT_NAME}-make PRIVATE palladium include) | ||||||
| target_link_libraries(${PROJECT_NAME}-make PRIVATE d7rc palladium) | target_link_libraries(${PROJECT_NAME}-make PRIVATE d7rc palladium) | ||||||
| target_compile_definitions(${PROJECT_NAME}-make PRIVATE -DVERSION="${PROJECT_VERSION}") | target_compile_definitions(${PROJECT_NAME}-make PRIVATE -DVERSION="${PROJECT_VERSION}") | ||||||
|  |  | ||||||
|  | install(TARGETS d7rc-make DESTINATION bin) | ||||||
| @@ -48,6 +48,7 @@ class Atlas { | |||||||
|   PD::Li::Texture::Ref Get(const std::string& name); |   PD::Li::Texture::Ref Get(const std::string& name); | ||||||
|  |  | ||||||
|   void pSplit(int i, PD::ivec4 pos); |   void pSplit(int i, PD::ivec4 pos); | ||||||
|  |   void pCreateUVs(); | ||||||
|  |  | ||||||
|   struct Entry { |   struct Entry { | ||||||
|     PD::Li::Rect UV; |     PD::Li::Rect UV; | ||||||
|   | |||||||
| @@ -40,9 +40,6 @@ bool Atlas::AppendImage(PD::Image::Ref img, const std::string& name) { | |||||||
|       e.iImg = img; |       e.iImg = img; | ||||||
|       e.iPos = PD::ivec2(it.x, it.y); |       e.iPos = PD::ivec2(it.x, it.y); | ||||||
|       e.Size = PD::ivec2(img->Width(), img->Height()); |       e.Size = PD::ivec2(img->Width(), img->Height()); | ||||||
|       e.UV = PD::fvec4((float)it.x / (float)Size.x, (float)it.y / (float)Size.y, |  | ||||||
|                        (float)(it.x + img->Width()) / (float)Size.x, |  | ||||||
|                        (float)(it.x + img->Height()) / (float)Size.y); |  | ||||||
|       Entries.push_back(e); |       Entries.push_back(e); | ||||||
| #ifdef DEBUG | #ifdef DEBUG | ||||||
|       std::cout << std::format("Created Image {} ({})\n", name, |       std::cout << std::format("Created Image {} ({})\n", name, | ||||||
| @@ -86,6 +83,7 @@ void Atlas::Pack() { | |||||||
|   if (!PD::BitUtil::IsSingleBit(Max.y)) { |   if (!PD::BitUtil::IsSingleBit(Max.y)) { | ||||||
|     Size.y = PD::BitUtil::GetPow2(Max.y); |     Size.y = PD::BitUtil::GetPow2(Max.y); | ||||||
|   } |   } | ||||||
|  |   pCreateUVs(); | ||||||
|   Img.resize(Size.x * Size.y * 4); |   Img.resize(Size.x * Size.y * 4); | ||||||
|   for (auto& it : Entries) { |   for (auto& it : Entries) { | ||||||
|     for (int i = 0; i < it.Size.x; i++) { |     for (int i = 0; i < it.Size.x; i++) { | ||||||
| @@ -128,4 +126,13 @@ PD::Li::Texture::Ref Atlas::Get(const std::string& name) { | |||||||
|   } |   } | ||||||
|   return nullptr; |   return nullptr; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void Atlas::pCreateUVs() { | ||||||
|  |   for (auto& e : Entries) { | ||||||
|  |     e.UV = PD::fvec4((float)e.iPos.x / (float)Size.x, | ||||||
|  |                      1.f - (float)e.iPos.y / (float)Size.y, | ||||||
|  |                      (float)(e.iPos.x + e.Size.x) / (float)Size.x, | ||||||
|  |                      1.f - (float)(e.iPos.y + e.Size.y) / (float)Size.y); | ||||||
|  |   } | ||||||
|  | } | ||||||
| }  // namespace D7RC | }  // namespace D7RC | ||||||
| @@ -107,6 +107,7 @@ void File::Read(Atlas& atlas, const std::string& path) { | |||||||
|   hdr.Read(iff); |   hdr.Read(iff); | ||||||
|   pReadTab(iff, atlas); |   pReadTab(iff, atlas); | ||||||
|   atlas.Img.resize(hdr.DataSize); |   atlas.Img.resize(hdr.DataSize); | ||||||
|  |   atlas.Size = PD::ivec2(hdr.Width, hdr.Height); | ||||||
|   iff.read(reinterpret_cast<char*>(atlas.Img.data()), hdr.DataSize); |   iff.read(reinterpret_cast<char*>(atlas.Img.data()), hdr.DataSize); | ||||||
|   iff.close(); |   iff.close(); | ||||||
| } | } | ||||||
| @@ -118,11 +119,12 @@ void File::pReadTab(std::ifstream& iff, Atlas& atlas) { | |||||||
|     PD::u32 namelen = 0; |     PD::u32 namelen = 0; | ||||||
|     iff.read(reinterpret_cast<char*>(&e.UV), sizeof(e.UV)); |     iff.read(reinterpret_cast<char*>(&e.UV), sizeof(e.UV)); | ||||||
|     iff.read(reinterpret_cast<char*>(&w), sizeof(w)); |     iff.read(reinterpret_cast<char*>(&w), sizeof(w)); | ||||||
|     iff.read(reinterpret_cast<char*>(&w), sizeof(h)); |     iff.read(reinterpret_cast<char*>(&h), sizeof(h)); | ||||||
|     iff.read(reinterpret_cast<char*>(&namelen), sizeof(PD::u32)); |     iff.read(reinterpret_cast<char*>(&namelen), sizeof(PD::u32)); | ||||||
|     e.Name.resize(namelen); |     e.Name.resize(namelen); | ||||||
|     iff.read(e.Name.data(), namelen); |     iff.read(e.Name.data(), namelen); | ||||||
|     e.Size = PD::ivec2(w, h); |     e.Size = PD::ivec2(w, h); | ||||||
|  |     atlas.Entries.push_back(e); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -28,21 +28,72 @@ SOFTWARE. | |||||||
| #define VERSION "" | #define VERSION "" | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| int main() { | int main(int argc, char** argv) { | ||||||
|   std::cout << "d7rc-make v" VERSION << std::endl; |   if (argc > 1) { | ||||||
|  |     if (std::string(argv[1]) == "version") { | ||||||
|  |       std::cout << "d7rc-make v" << VERSION << std::endl; | ||||||
|  |       return 0; | ||||||
|  |     } else if (std::string(argv[1]) == "help") { | ||||||
|  |       std::cout << "d7rc-make v" << VERSION << std::endl; | ||||||
|  |       std::cout << "Usage: d7rc-make [cmd]" << std::endl; | ||||||
|  |       std::cout << "Commands:" << std::endl; | ||||||
|  |       std::cout << "  version               Show version" << std::endl; | ||||||
|  |       std::cout << "  help                  Show this help message" | ||||||
|  |                 << std::endl; | ||||||
|  |       std::cout << "  tex        paths out  Create Texture Atlas" << std::endl; | ||||||
|  |       std::cout << "  check      path       Show D7RC file info" << std::endl; | ||||||
|  |       return 0; | ||||||
|  |     } else if (std::string(argv[1]) == "tex") { | ||||||
|  |       if (argc < 4) { | ||||||
|  |         std::cout << "Not paths given for 'tex'." << std::endl; | ||||||
|  |         return 0; | ||||||
|  |       } | ||||||
|       int szs = 1024; |       int szs = 1024; | ||||||
|       D7RC::Atlas a(szs); |       D7RC::Atlas a(szs); | ||||||
|       std::map<PD::Image::Ref, std::string> imgs; |       std::map<PD::Image::Ref, std::string> imgs; | ||||||
|   for (auto& it : std::filesystem::directory_iterator("images")) { |       for (int i = 2; i < argc - 1; i++) { | ||||||
|  |         for (auto& it : std::filesystem::directory_iterator(argv[i])) { | ||||||
|           auto img = PD::Image::New(it.path().string()); |           auto img = PD::Image::New(it.path().string()); | ||||||
|           PD::Image::Convert(img, PD::Image::RGBA); |           PD::Image::Convert(img, PD::Image::RGBA); | ||||||
|           imgs[img] = it.path().filename().string(); |           imgs[img] = it.path().filename().string(); | ||||||
|         } |         } | ||||||
|  |       } | ||||||
|       for (auto& it : imgs) { |       for (auto& it : imgs) { | ||||||
|         a.AppendImage(it.first, it.second); |         a.AppendImage(it.first, it.second); | ||||||
|       } |       } | ||||||
|       a.Pack(); |       a.Pack(); | ||||||
|       D7RC::File f; |       D7RC::File f; | ||||||
|   f.Write(a, "test.d7rc"); |       f.Write(a, std::string(argv[argc - 1])); | ||||||
|  |       return 0; | ||||||
|  |     } else if (std::string(argv[1]) == "check") { | ||||||
|  |       if (argc < 3) { | ||||||
|  |         std::cout << "No path to .d7rc file was specified!" << std::endl; | ||||||
|  |         return 0; | ||||||
|  |       } | ||||||
|  |       D7RC::Atlas a; | ||||||
|  |       D7RC::File f; | ||||||
|  |       f.Read(a, argv[2]); | ||||||
|  |       // Probably not the way how you should output it... but my favourite | ||||||
|  |       std::cout << std::format("Magic: {}", std::string((char*)&f.hdr.Magic, 4)) | ||||||
|  |                 << std::endl; | ||||||
|  |       std::cout << std::format("Size: {}", PD::ivec2(f.hdr.Width, f.hdr.Height)) | ||||||
|  |                 << std::endl; | ||||||
|  |       std::cout << "Data Size: " << PD::Strings::FormatBytes(f.hdr.DataSize) | ||||||
|  |                 << std::endl; | ||||||
|  |       std::cout << "Images: " << f.hdr.NumEntries << std::endl; | ||||||
|  |       std::cout << std::format( | ||||||
|  |           "Atlas Info:\n  {} Entries\n  {} bytes\nEntries:\n", a.Entries.size(), | ||||||
|  |           a.Img.size()); | ||||||
|  |       for (auto& it : a.Entries) { | ||||||
|  |         std::cout << std::format("    {} {}\n", it.Name, it.Size); | ||||||
|  |       } | ||||||
|  |     } else { | ||||||
|  |       std::cout << "Unknown command: " << argv[1] << std::endl; | ||||||
|  |       return 0; | ||||||
|  |     } | ||||||
|  |   } else { | ||||||
|  |     std::cout << "d7rc-make v" << VERSION << std::endl; | ||||||
|  |     std::cout << "Use 'd7rc-make help' for more information." << std::endl; | ||||||
|  |   } | ||||||
|   return 0; |   return 0; | ||||||
| } | } | ||||||
							
								
								
									
										1
									
								
								vendor/palladium
									
									
									
									
										vendored
									
									
										Submodule
									
								
							
							
								
								
								
								
								
							
						
						
									
										1
									
								
								vendor/palladium
									
									
									
									
										vendored
									
									
										Submodule
									
								
							 Submodule vendor/palladium added at 8328181a2a
									
								
							
		Reference in New Issue
	
	Block a user