custom levels: fix crash when more than one ambient is present (#2891)

This commit is contained in:
Hat Kid 2023-08-08 20:24:13 +02:00 committed by GitHub
parent 5d7aa7cea1
commit 6061f39728
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 44 deletions

View File

@ -16,7 +16,7 @@ add_library(compiler
build_level/LevelFile.cpp
build_level/ResLump.cpp
build_level/Tfrag.cpp
build_level/drawable_ambient.cpp
build_level/ambient.cpp
compiler/Compiler.cpp
compiler/Env.cpp
compiler/Val.cpp

View File

@ -200,6 +200,7 @@ void add_ambients_from_json(const nlohmann::json& json,
for (const auto& ambient_json : json) {
auto& ambient = ambient_list.emplace_back();
ambient.aid = ambient_json.value("aid", base_aid + ambient_list.size());
ambient.vis_id = ambient_json.value("vis_id", 0);
ambient.trans = vectorm4_from_json(ambient_json.at("trans"));
ambient.bsphere = vectorm4_from_json(ambient_json.at("bsphere"));
if (ambient_json.find("lump") != ambient_json.end()) {

View File

@ -2,10 +2,9 @@
#include "goalc/data_compiler/DataObjectGenerator.h"
// TODO find better way to pass the ambient array
size_t DrawableTreeArray::add_to_object_file(DataObjectGenerator& gen,
size_t ambient_count,
size_t ambient_arr_slot) const {
static size_t ambient_arr_slot;
size_t DrawableTreeArray::add_to_object_file(DataObjectGenerator& gen) const {
/*
(deftype drawable-tree-array (drawable-group)
((trees drawable-tree 1 :offset 32 :score 100))
@ -56,9 +55,8 @@ size_t DrawableTreeArray::add_to_object_file(DataObjectGenerator& gen,
gen.link_word_to_byte(tree_word++, collide.add_to_object_file(gen));
}
for (auto& ambients : ambients) {
gen.link_word_to_byte(tree_word++,
ambients.add_to_object_file(gen, ambient_count, ambient_arr_slot));
for (auto& ambient : ambients) {
gen.link_word_to_byte(tree_word++, ambient.add_to_object_file(gen, ambient_arr_slot));
}
}
@ -87,14 +85,13 @@ std::vector<u8> LevelFile::save_object_file() const {
auto file_info_slot = info.add_to_object_file(gen);
gen.link_word_to_byte(1, file_info_slot);
auto ambient_arr_slot = generate_inline_array_ambients(gen, ambients);
ambient_arr_slot = generate_inline_array_ambients(gen, ambients);
//(bsphere vector :inline :offset-assert 16)
//(all-visible-list (pointer uint16) :offset-assert 32)
//(visible-list-length int32 :offset-assert 36)
//(drawable-trees drawable-tree-array :offset-assert 40)
gen.link_word_to_byte(40 / 4,
drawable_trees.add_to_object_file(gen, ambients.size(), ambient_arr_slot));
gen.link_word_to_byte(40 / 4, drawable_trees.add_to_object_file(gen));
//(pat pointer :offset-assert 44)
//(pat-length int32 :offset-assert 48)
//(texture-remap-table (pointer uint64) :offset-assert 52)

View File

@ -9,11 +9,11 @@
#include "goalc/build_level/Entity.h"
#include "goalc/build_level/FileInfo.h"
#include "goalc/build_level/Tfrag.h"
#include "goalc/build_level/ambient.h"
#include "goalc/build_level/collide_bvh.h"
#include "goalc/build_level/collide_common.h"
#include "goalc/build_level/collide_drawable.h"
#include "goalc/build_level/collide_pack.h"
#include "goalc/build_level/drawable_ambient.h"
struct VisibilityString {
std::vector<u8> bytes;
@ -32,9 +32,7 @@ struct DrawableTreeArray {
std::vector<DrawableTreeCollideFragment> collides;
std::vector<DrawableTreeAmbient> ambients;
std::vector<DrawableTreeInstanceShrub> shrubs;
size_t add_to_object_file(DataObjectGenerator& gen,
size_t ambient_count,
size_t ambient_arr_slot) const;
size_t add_to_object_file(DataObjectGenerator& gen) const;
};
struct TextureRemap {};

View File

@ -1,4 +1,4 @@
#include "drawable_ambient.h"
#include "ambient.h"
#include "goalc/data_compiler/DataObjectGenerator.h"
/*
@ -23,19 +23,18 @@
:flag-assert #x1200000020
)
*/
size_t DrawableTreeAmbient::add_to_object_file(DataObjectGenerator& gen,
size_t ambient_count,
size_t ambient_arr_slot) const {
size_t DrawableTreeAmbient::add_to_object_file(DataObjectGenerator& gen, size_t ambient_array) {
gen.align_to_basic();
gen.add_type_tag("drawable-tree-ambient");
size_t result = gen.current_offset_bytes();
gen.add_word(ambient_count << 16); // 4, 6
gen.add_word(0); // 8
gen.add_word(0); // 12
gen.add_word(0); // 16
gen.add_word(0); // 20
gen.add_word(0); // 24
gen.add_word(0); // 28
gen.link_word_to_byte(gen.add_word(0), ambient_arr_slot);
gen.add_word(1 << 16); // 4, 6
gen.add_word(0); // 8
gen.add_word(0); // 12
gen.add_word(0); // 16
gen.add_word(0); // 20
gen.add_word(0); // 24
gen.add_word(0); // 28
gen.link_word_to_byte(gen.add_word(0), ambient_array);
return result;
}

View File

@ -0,0 +1,9 @@
#pragma once
#include <cstddef>
class DataObjectGenerator;
struct DrawableTreeAmbient {
static size_t add_to_object_file(DataObjectGenerator& gen, size_t ambient_array);
};

View File

@ -1,17 +0,0 @@
#pragma once
#include <string>
#include "goalc/build_level/Entity.h"
class DataObjectGenerator;
struct DrawableAmbient {
EntityAmbient ambient;
};
struct DrawableTreeAmbient {
size_t add_to_object_file(DataObjectGenerator& gen,
size_t ambient_count,
size_t ambient_arr_slot) const;
};