Skip to content

Commit

Permalink
Merge pull request #261 from chaoticgd/finaltouches
Browse files Browse the repository at this point in the history
Some final touches before the v0.4 release
  • Loading branch information
chaoticgd committed Jun 30, 2023
2 parents 9287968 + 9ef9429 commit 21a6b9f
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 48 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Changes:

Bug fixes:
- Fixed some issues with unpacking certain builds.
- Improved handling of unicode in file paths on Windows.
- A lot more.

## v0.3

Expand Down
2 changes: 1 addition & 1 deletion docs/asset_reference.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Asset Reference

This file was generated from asset_schema.wtf and is for version 24 of the asset format.
This file was generated from asset_schema.wtf and is for version 25 of the asset format.

## Index

Expand Down
3 changes: 2 additions & 1 deletion docs/asset_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ Each asset type is defined in `asset_schema.wtf` and a code generator, `asset_co

| Format Version | Wrench Version | Description |
| - | - | - |
| 24 | v0.4 | Instance IDs are now rewritten to indices while the gameplay/mission files are packed. Added core child to mission instances asset. All colours stored on instances are now vec3s. |
| 25 | v0.4 | Added version_info nodes to the instances files containing information about the application writing out the file, and the format version. |
| 24 | | Instance IDs are now rewritten to indices while the gameplay/mission files are packed. Added core child to mission instances asset. All colours stored on instances are now vec3s. |
| 23 | | Added new relative_pvar_pointers attribute to instances that have a pvar component. |
| 22 | | Occlusion is now computed on demand instead of during a build. Occlusion assets now have grid and mapping attributes. |
| 21 | | Added new instances format. Added Instances asset type. Added the C++ parsing system and the overlay asset bank. |
Expand Down
2 changes: 1 addition & 1 deletion docs/instance_reference.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Instance Reference

This file was generated from instance_schema.wtf and is for version 24 of the instance format.
This file was generated from instance_schema.wtf and is for version 25 of the instance format.

## Instances

Expand Down
Binary file modified docs/screenshots/editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/assetmgr/asset_schema.wtf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

format_version: 24
format_version: 25

// *****************************************************************************

Expand Down
9 changes: 8 additions & 1 deletion src/editor/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <core/png.h>
#include <assetmgr/material_asset.h>
#include <instancemgr/gameplay.h>
#include <toolwads/wads.h>
#include <gui/render_mesh.h>
#include <editor/app.h>

Expand Down Expand Up @@ -237,7 +238,13 @@ std::string Level::save() {
}

// Write out the gameplay.bin file.
std::string text = write_instances(_instances);
const char* application_version;
if(strlen(wadinfo.build.version_string) != 0) {
application_version = wadinfo.build.version_string;
} else {
application_version = wadinfo.build.commit_string;
}
std::string text = write_instances(_instances, "Wrench Editor", application_version);
FileReference ref = _instances_asset->file().write_text_file(gameplay_path, text.c_str());
_instances_asset->set_src(ref);

Expand Down
16 changes: 6 additions & 10 deletions src/gui/about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,19 @@ static void about_wrench() {
ImGui::TextWrapped("Wrench is a set of modding tools for the Ratchet & Clank PS2 games.");
ImGui::NewLine();
// These numbers are extracted from the git tag at build time. See 'src/toolwads/'.
if(wadinfo.build.version_major > -1 && wadinfo.build.version_minor > -1) {
ImGui::TextWrapped("Release Version %hd.%hd", wadinfo.build.version_major, wadinfo.build.version_minor);
if(strlen(wadinfo.build.version_string) != 0) {
ImGui::TextWrapped("Release Version %s", wadinfo.build.version_string);
} else {
ImGui::TextWrapped("Development Version");
}
ImGui::NewLine();
u8* c = wadinfo.build.commit;
char* c = wadinfo.build.commit_string;
ImGui::AlignTextToFramePadding();
ImGui::TextWrapped("Built from git commit %02hhx%02hhx%02hhx%02hhx",
c[0], c[1], c[2], c[3]);
ImGui::TextWrapped("Built from git commit %c%c%c%c%c%c%c%c",
c[0],c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
ImGui::SameLine();
if(ImGui::Button("Copy Full Hash")) {
char text[ARRAY_SIZE(wadinfo.build.commit) * 2 + 1] = {};
for(s32 i = 0; i < ARRAY_SIZE(wadinfo.build.commit); i++) {
snprintf(text + i * 2, 3, "%02x", wadinfo.build.commit[i]);
}
ImGui::SetClipboardText(text);
ImGui::SetClipboardText(c);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/instancemgr/instance_schema.wtf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

format_version: 24
format_version: 25

InstanceType Moby {
desc: "Moving, interactive, or otherwise dynamic objects with an associated update function."
Expand Down
8 changes: 7 additions & 1 deletion src/instancemgr/instances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,17 @@ Instances read_instances(std::string& src) {
return dest;
}

std::string write_instances(const Instances& src) {
std::string write_instances(const Instances& src, const char* application_name, const char* application_version) {
std::string dest;
WtfWriter* ctx = wtf_begin_file(dest);
defer([&]() { wtf_end_file(ctx); });

wtf_begin_node(ctx, nullptr, "version_info");
wtf_write_string_attribute(ctx, "application_name", application_name);
wtf_write_string_attribute(ctx, "application_version", application_version);
wtf_write_integer_attribute(ctx, "format_version", INSTANCE_FORMAT_VERSION);
wtf_end_node(ctx);

wtf_begin_node(ctx, nullptr, "level_settings");
write_level_settings(ctx, src.level_settings);
wtf_end_node(ctx);
Expand Down
2 changes: 1 addition & 1 deletion src/instancemgr/instances.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct HelpMessages {
};

Instances read_instances(std::string& src);
std::string write_instances(const Instances& src);
std::string write_instances(const Instances& src, const char* application_name, const char* application_version);

template <typename Callback, typename InstanceVec>
static void for_each_instance_of_type_with(u32 required_components_mask, const InstanceVec& instances, Callback callback) {
Expand Down
5 changes: 2 additions & 3 deletions src/launcher/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ static Mod* mod_list_window() {
ImGui::BeginChild("Mod List");

char greeting[64];
BuildWadHeader& build = wadinfo.build;
if(build.version_major > -1 && build.version_minor > -1) {
snprintf(greeting, sizeof(greeting), "Wrench Modding Toolset v%hd.%hd", build.version_major, build.version_minor);
if(strlen(wadinfo.build.version_string) != 0) {
snprintf(greeting, sizeof(greeting), "Wrench Modding Toolset %s", wadinfo.build.version_string);
} else {
snprintf(greeting, sizeof(greeting), "Wrench Modding Toolset");
}
Expand Down
35 changes: 19 additions & 16 deletions src/toolwads/packer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ static void pack_build_wad() {
// Default values for if the tag isn't valid.
header.version_major = -1;
header.version_minor = -1;
header.version_patch = -1;

// Parse the version number from the git tag.
if(git_tag && git_tag[0] == 'v') {
// Parse the version number from the git tag.
const char* major_pos = git_tag + 1;
header.version_major = parse_positive_embedded_int(major_pos);

Expand All @@ -86,23 +87,25 @@ static void pack_build_wad() {
minor_pos++;
header.version_minor = parse_positive_embedded_int(minor_pos);
}
}

// Parse the git commit hash.
for(size_t i = 0; git_commit && i < std::min(strlen(git_commit), sizeof(header.commit) * 2); i++) {
u8 nibble = (u8) git_commit[i];
if(nibble >= '0' && nibble <= '9') {
nibble -= '0';
} else if(nibble >= 'a' && nibble <= 'f') {
nibble += 0xa - 'a';
} else {
break;

const char* patch_pos = minor_pos;
while(*patch_pos != '.' && *patch_pos != '\0') {
patch_pos++;
}
if(i % 2 == 0) {
header.commit[i / 2] = nibble << 4;
} else {
header.commit[i / 2] |= nibble;
if(*patch_pos != '\0') {
patch_pos++;
header.version_patch = parse_positive_embedded_int(patch_pos);
}

// Store the version string.
verify_fatal(strlen(git_tag) < 20);
strncpy(header.version_string, git_tag, sizeof(header.version_string));
}

// Store the git commit.
if(git_commit && strlen(git_commit) != 0) {
verify_fatal(strlen(git_commit) == 40);
strncpy(header.commit_string, git_commit, sizeof(header.commit_string));
}

wad.write<BuildWadHeader>(0, header);
Expand Down
9 changes: 6 additions & 3 deletions src/toolwads/wads.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ enum License {
packed_struct(BuildWadHeader,
/* 0x00 */ s32 header_size;
/* 0x04 */ Sector32 sector;
/* 0x08 */ s16 version_major;
/* 0x0a */ s16 version_minor;
/* 0x0c */ u8 commit[0x14];
/* 0x08 */ s32 version_major;
/* 0x0c */ s32 version_minor;
/* 0x10 */ s32 version_patch;
/* 0x14 */ char version_string[20];
/* 0x28 */ char commit_string[41];
/* 0x51 */ char pad[3];
)

packed_struct(GuiWadHeader,
Expand Down
17 changes: 15 additions & 2 deletions src/wrenchbuild/level/instances_asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "instances_asset.h"

#include <toolwads/wads.h>
#include <wrenchbuild/asset_unpacker.h>
#include <wrenchbuild/asset_packer.h>
#include <wrenchbuild/tests.h>
Expand Down Expand Up @@ -89,7 +90,13 @@ s32 unpack_instances(InstancesAsset& dest, LevelWadAsset* help_occl_dest, const
occlusion_mappings = std::move(opt_iterator(gameplay.occlusion));
}

std::string text = write_instances(instances);
const char* application_version;
if(strlen(wadinfo.build.version_string) != 0) {
application_version = wadinfo.build.version_string;
} else {
application_version = wadinfo.build.commit_string;
}
std::string text = write_instances(instances, "Wrench Build Tool", application_version);
FileReference ref = dest.file().write_text_file(stringf("%s.instances", type.c_str()), text.c_str());
dest.set_src(ref);

Expand Down Expand Up @@ -265,7 +272,13 @@ static bool test_instances_asset(std::vector<u8>& src, AssetType type, BuildConf
}

// Write out instances file and read it back.
std::string instances_text = write_instances(instances_in);
const char* application_version;
if(strlen(wadinfo.build.version_string) != 0) {
application_version = wadinfo.build.version_string;
} else {
application_version = wadinfo.build.commit_string;
}
std::string instances_text = write_instances(instances_in, "Wrench Build Tool (Test)", application_version);
write_file("/tmp/instances.txt", instances_text);
Instances instances_out = read_instances(instances_text);

Expand Down
9 changes: 3 additions & 6 deletions src/wrenchbuild/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,15 +670,12 @@ static void print_usage(bool developer_subcommands) {
}

static void print_version() {
if(wadinfo.build.version_major > -1 && wadinfo.build.version_major > -1) {
printf("Wrench Build Tool v%hd.%hd\n", wadinfo.build.version_major, wadinfo.build.version_minor);
if(strlen(wadinfo.build.version_string) != 0) {
printf("Wrench Build Tool %s\n", wadinfo.build.version_string);
} else {
printf("Wrench Build Tool (Development Version)\n");
}
printf("Built from git commit ");
for(s32 i = 0; i < ARRAY_SIZE(wadinfo.build.commit); i++) {
printf("%hhx", wadinfo.build.commit[i]);
}
printf("Built from git commit %s", wadinfo.build.commit_string);
printf("\n");
}

Expand Down

0 comments on commit 21a6b9f

Please sign in to comment.