Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 20 additions & 39 deletions bin/assetzip/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,21 @@
#include <fstream>
#include <format>
#include <iostream>
#include <set>
#include <unordered_set>
#include <vector>
#include <yaml-cpp/yaml.h>

std::vector<std::string> parseAssetFileNames(const std::string &yamlFilePath) {
const auto node = YAML::LoadFile(yamlFilePath);

std::vector<std::string> paths;
paths.push_back(yamlFilePath);

if (!node["assets"]) {
return paths;
}
if (!node["assets"].IsSequence()) {
throw std::runtime_error("YAML must contain 'assets' as a sequence.");
}

for (const auto &n: node["assets"]) {
paths.push_back(n.as<std::string>());
}

std::set<std::string> pathSet;
for (const auto &n: paths) {
if (pathSet.contains(n)) {
throw std::runtime_error(std::format("'{}' duplicated.", n));
std::vector<std::string> collectAssetNames(int argc, char *argv[]) {
std::vector<std::string> result;
std::unordered_set<std::string> checkSet;
result.reserve(argc - 1);
checkSet.reserve(argc - 1);
for (int i = 1; i < argc; ++i) {
if (!checkSet.contains(argv[i])) {
result.emplace_back(argv[i]);
checkSet.insert(argv[i]);
}
pathSet.emplace(n);
}

return paths;
return result;
}

std::vector<unsigned char> loadFile(const std::string &path) {
Expand All @@ -50,12 +35,7 @@ std::vector<unsigned char> loadFile(const std::string &path) {
return data;
}

void run(const std::string &yamlFilePath) {
const auto fileNames = parseAssetFileNames(yamlFilePath);
if (fileNames.empty()) {
throw std::runtime_error("no asset files specified in config.");
}

void run(const std::vector<std::string> &fileNames) {
// .dat出力開始
std::ofstream out(".dat", std::ios::binary);
if (!out) {
Expand Down Expand Up @@ -91,19 +71,20 @@ void run(const std::string &yamlFilePath) {
}

int main(int argc, char *argv[]) {
if (argc != 2) {
std::cerr << "usage: assetzip <config-file-path>" << std::endl;
return 1;
const auto fileNames = collectAssetNames(argc, argv);
if (fileNames.empty()) {
std::cout << "usage: assetzip <asset1> <asset2> ..." << std::endl;
std::cout << "nothing generated." << std::endl;
return 0;
}

try {
run(argv[1]);
} catch (const YAML::Exception &e) {
run(fileNames);
} catch (const std::exception &e) {
std::cerr << e.what() << std::endl;
std::cerr << "failed to zip asset files." << std::endl;
return 1;
} catch (const std::exception &e) {
std::cerr << e.what() << std::endl;
} catch (...) {
std::cerr << "failed to zip asset files." << std::endl;
return 1;
}
Expand Down
Binary file removed examples/simple/.dat
Binary file not shown.
13 changes: 0 additions & 13 deletions examples/simple/config.yml

This file was deleted.

58 changes: 38 additions & 20 deletions examples/simple/main.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
#include <iostream>
#include <orge.h>
#include <orge/orge.h>

#define TRY(n) \
if (!(n)) { \
std::cout << orgeGetErrorMessage() << std::endl; \
return 1; \
}

#define CHECK(n) \
if (!(n)) { \
std::cout << orgeGetErrorMessage() << std::endl; \
continue; \
}
#define TRY(type, param) if (orgeApiCall((type), (param)) != ORGE_OK) return 1;
#define CHECK(type, param) if (orgeApiCall((type), (param)) != ORGE_OK) continue;

int main() {
TRY(orgeInitialize());
const char *renderTargetId = "RT";
OrgeAttachmentConfig attachmentConfig{};
attachmentConfig.id = renderTargetId;
attachmentConfig.format = ORGE_FORMAT_RENDER_TARGET;
attachmentConfig.clearValueType = ORGE_CLEAR_VALUE_TYPE_COLOR;
attachmentConfig.clearValue[0] = 0.894f;
attachmentConfig.clearValue[1] = 0.619f;
attachmentConfig.clearValue[2] = 0.38f;
attachmentConfig.clearValue[3] = 1.0f;
OrgeSubpassConfig subpassConfig{};
subpassConfig.id = "SP";
subpassConfig.outputCount = 1;
subpassConfig.outputs = &renderTargetId;
OrgeRenderPassConfig renderPassConfig{};
renderPassConfig.id = "RP";
renderPassConfig.subpassCount = 1;
renderPassConfig.subpasses = &subpassConfig;
OrgeInitializeParam config{};
config.title = "simple";
config.width = 640;
config.height = 480;
config.attachmentCount = 1;
config.attachments = &attachmentConfig;
config.renderPassCount = 1;
config.renderPasses = &renderPassConfig;

int count = 0;
while (orgeUpdate()) {
CHECK(orgeBeginRender());
CHECK(orgeBeginRenderPass("RP"));
CHECK(orgeEndRenderPass());
CHECK(orgeEndRender());
TRY(ORGE_INITIALIZE, &config);

OrgeBeginRenderPassParam beginRenderPassParam{"RP"};

int count = 0;
while (orgeApiCall(ORGE_UPDATE, nullptr) != ORGE_WINDOW_CLOSED) {
CHECK(ORGE_BEGIN_RENDER, nullptr);
CHECK(ORGE_BEGIN_RENDER_PASS, &beginRenderPassParam);
CHECK(ORGE_END_RENDER_PASS, nullptr);
CHECK(ORGE_END_RENDER, nullptr);
if (count % 60 == 0) {
std::cout << count / 60 << std::endl;
}
count += 1;
}

orgeTerminate();
TRY(ORGE_TERMINATE, nullptr);
return 0;
}
Loading
Loading