Skip to content

Commit 34cd5d2

Browse files
committed
finish basic type parse & generate
1 parent 23b4d4d commit 34cd5d2

File tree

13 files changed

+59
-52
lines changed

13 files changed

+59
-52
lines changed

engine/engine/nickel/common/flags.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,46 @@ class Flags {
1111

1212
Flags() = default;
1313

14-
Flags(T value) : value_{static_cast<underlying_type>(value)} {}
14+
Flags(T value) : m_value{static_cast<underlying_type>(value)} {}
1515

16-
Flags(std::underlying_type_t<T> value) : value_{value} {}
16+
Flags(std::underlying_type_t<T> value) : m_value{value} {}
1717

1818
Flags(const Flags&) = default;
1919
Flags(Flags&&) = default;
2020

2121
Flags operator|(T o) const {
22-
return Flags{value_ | static_cast<underlying_type>(o)};
22+
return Flags{m_value | static_cast<underlying_type>(o)};
2323
}
2424

2525
Flags operator&(T o) const {
26-
return Flags{value_ & static_cast<underlying_type>(o)};
26+
return Flags{m_value & static_cast<underlying_type>(o)};
2727
}
2828

2929
Flags& operator=(const Flags&) = default;
3030

3131
Flags& operator=(T value) {
32-
value_ = static_cast<underlying_type>(value);
32+
m_value = static_cast<underlying_type>(value);
3333
return *this;
3434
}
3535

3636
Flags& operator|=(T o) {
37-
value_ |= static_cast<underlying_type>(o);
37+
m_value |= static_cast<underlying_type>(o);
3838
return *this;
3939
}
4040

4141
Flags& operator&=(T o) {
42-
value_ &= static_cast<underlying_type>(o);
42+
m_value &= static_cast<underlying_type>(o);
4343
return *this;
4444
}
4545

46-
Flags operator~() const noexcept { return ~value_; }
46+
Flags operator~() const noexcept { return ~m_value; }
4747

48-
operator T() const { return static_cast<T>(value_); }
48+
operator T() const { return static_cast<T>(m_value); }
4949

50-
operator underlying_type() const { return value_; }
50+
operator underlying_type() const { return m_value; }
5151

5252
private:
53-
underlying_type value_{};
53+
underlying_type m_value{};
5454
};
5555

5656
} // namespace tl

engine/engine/nickel/graphics/lowlevel/pipeline_layout.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class NICKEL_API PipelineLayout: public ImplWrapper<PipelineLayoutImpl> {
1616
};
1717

1818
std::vector<BindGroupLayout> m_layouts;
19-
std::vector<PushConstantRange> m_push_contants;
19+
std::vector<PushConstantRange> m_push_constants;
2020
};
2121

2222
using ImplWrapper::ImplWrapper;

engine/engine/nickel/physics/enums.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#pragma once
2+
#include "nickel/common/refl_macro.hpp"
23

34
namespace nickel::physics {
45

5-
enum class ForceMode {
6+
enum class NICKEL_REFL_ATTR(refl) ForceMode {
67
Force,
78
Acceleration,
89
Velocity,
910
Impulse,
1011
};
1112

12-
enum class CombineMode { Average, Min, Max, Multiply };
13+
enum class NICKEL_REFL_ATTR(refl) CombineMode { Average, Min, Max, Multiply };
1314

14-
enum class RigidActorType {
15+
enum class NICKEL_REFL_ATTR(refl) RigidActorType {
1516
RigidStatic,
1617
RigidDynamic,
1718
ArticulationLink,
@@ -20,7 +21,7 @@ enum class RigidActorType {
2021
PbdParticleSystem,
2122
};
2223

23-
enum class HitFlag {
24+
enum class NICKEL_REFL_ATTR(refl) HitFlag {
2425
Position = 1 << 0,
2526
Normal = 1 << 1,
2627
UV = 1 << 2,
@@ -34,7 +35,7 @@ enum class HitFlag {
3435
Default = Position | Normal | FaceIndex,
3536
};
3637

37-
enum class QueryFlag {
38+
enum class NICKEL_REFL_ATTR(refl) QueryFlag {
3839
Static = 1 << 0,
3940
Dynamic = 1 << 1,
4041
PreFilter = 1 << 2,
@@ -45,7 +46,7 @@ enum class QueryFlag {
4546
DisableHardcodedFilter = 1 << 7,
4647
};
4748

48-
enum class QueryHitType {
49+
enum class NICKEL_REFL_ATTR(refl) QueryHitType {
4950
None,
5051
Touch,
5152
Block,

engine/engine/nickel/physics/vehicle.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ struct NICKEL_REFL_ATTR(refl) VehicleWheelSimDescriptor {
2323
struct FrictionVsLongitudinalSlipConfig {
2424
float m_friction_at_zero_slip{1.0};
2525

26-
float m_slip_at_maximum_firction{0.1};
27-
float m_max_firction{1.0};
26+
float m_slip_at_maximum_friction{0.1};
27+
float m_max_friction{1.0};
2828

2929
float m_max_slip{1.0};
3030
float m_friction_at_max_slip{1.0};

engine/engine/nickel/refl/drefl/factory.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,9 @@ class Factory final {
817817
if constexpr (std::is_fundamental_v<T>) {
818818
return &NumericFactory<T>::Instance().Info();
819819
}
820+
if constexpr (std::is_class_v<T>) {
821+
return &ClassFactory<T>::Instance().Info();
822+
}
820823

821824
return nullptr;
822825
}

engine/engine/refl_code_generator/parser.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def class_node_code_generate(prefix: str, node: ClassNode) -> str:
305305
for field in node.public_fields:
306306
if not field.attrs.need_refl:
307307
continue
308-
fmt['properties'].append({'property_register_name': field.name,
308+
fmt['properties'].append({'property_register_name': field.name if len(field.name) <= 2 else field.name[2:],
309309
'property_name': class_name_with_prefix + '::' + field.name})
310310

311311
return chevron.render(g_class_refl_mustache, fmt)
@@ -339,8 +339,8 @@ def __init__(self):
339339
output_dir = pathlib.Path(sys.argv[2])
340340
time_record_filename = 'time_record.pkl'
341341
time_record_file_path = output_dir / time_record_filename
342-
header_filename = 'refl_generate.hpp'
343-
impl_filename = 'refl_generate.cpp'
342+
header_filename = output_dir / 'refl_generate.hpp'
343+
impl_filename = output_dir / 'refl_generate.cpp'
344344

345345
print(f'parse dir: {parse_dir}', flush=True)
346346
print(f'output dir: {output_dir}', flush=True)
@@ -362,6 +362,8 @@ def __init__(self):
362362
if time_record_file_path.exists():
363363
with open(time_record_file_path, 'rb') as f:
364364
file_record = pickle.load(f)
365+
366+
has_refl_info_changed = False
365367

366368
for file in files:
367369
last_modification_time = os.path.getmtime(file)
@@ -371,6 +373,7 @@ def __init__(self):
371373
if file_record.mtime[file] == last_modification_time:
372374
continue
373375

376+
has_refl_info_changed = True
374377
parse_filename = file
375378
node = parse_one_file(file, str(parse_dir.parent))
376379

@@ -391,23 +394,24 @@ def __init__(self):
391394

392395
with open(time_record_file_path, 'wb') as f:
393396
pickle.dump(new_file_record, f)
394-
395-
refl_impl_data = {'header_file': output_dir/header_filename, 'refl_header_files': [], 'func_calls': []}
396-
for path, node in new_file_record.parsed_file_record.items():
397-
if len(node.children) == 0:
398-
continue
399-
400-
func_name, code = node_code_generate(str(path), node)
401-
final_filename = func_name + '.hpp'
402-
refl_impl_data['refl_header_files'].append({'refl_header_file': final_filename})
403-
404-
# TODO: some magic string may refactory?
405-
refl_impl_data['func_calls'].append({'func_call': f'register_{func_name}_ReflInfo'})
406-
print(f'generate code to {final_filename}', flush=True)
407-
save_generated_code(output_dir / final_filename, code)
408397

409-
with open(output_dir/header_filename, 'w+', encoding='utf-8') as f:
410-
f.write(chevron.render(g_header_mustache, {}))
398+
if has_refl_info_changed:
399+
refl_impl_data = {'header_file': header_filename, 'refl_header_files': [], 'func_calls': []}
400+
for path, node in new_file_record.parsed_file_record.items():
401+
if len(node.children) == 0:
402+
continue
403+
404+
func_name, code = node_code_generate(str(path), node)
405+
final_filename = func_name + '.hpp'
406+
refl_impl_data['refl_header_files'].append({'refl_header_file': final_filename})
407+
408+
# TODO: some magic string may refactory?
409+
refl_impl_data['func_calls'].append({'func_call': f'register_{func_name}_ReflInfo'})
410+
print(f'generate code to {final_filename}', flush=True)
411+
save_generated_code(output_dir / final_filename, code)
412+
413+
with open(header_filename, 'w+', encoding='utf-8') as f:
414+
f.write(chevron.render(g_header_mustache, {}))
411415

412-
with open(output_dir/impl_filename, 'w+', encoding='utf-8') as f:
413-
f.write(chevron.render(g_impl_mustache, refl_impl_data))
416+
with open(impl_filename, 'w+', encoding='utf-8') as f:
417+
f.write(chevron.render(g_impl_mustache, refl_impl_data))

engine/engine/src/graphics/gltf_draw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void GLTFRenderPass::initPipelineLayout(Device& device) {
200200
range.m_offset = 0;
201201
range.m_shader_stage = ShaderStage::Vertex;
202202
range.m_size = sizeof(Mat44) * 2;
203-
desc.m_push_contants.push_back(range);
203+
desc.m_push_constants.push_back(range);
204204
}
205205

206206
desc.m_layouts.push_back(m_bind_group_layout);

engine/engine/src/graphics/lowlevel/pipeline_layout_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PipelineLayoutImpl::PipelineLayoutImpl(DeviceImpl& device,
2222
ci.pSetLayouts = set_layouts.data();
2323

2424
std::vector<VkPushConstantRange> push_constants;
25-
for (auto& range : desc.m_push_contants) {
25+
for (auto& range : desc.m_push_constants) {
2626
VkPushConstantRange r;
2727
r.offset = range.m_offset;
2828
r.size = range.m_size;

engine/engine/src/graphics/primitive_draw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ void PrimitiveRenderPass::initPipelineLayout(Device& device) {
237237
range.m_offset = 0;
238238
range.m_shader_stage = ShaderStage::Vertex;
239239
range.m_size = sizeof(Mat44) * 2;
240-
desc.m_push_contants.push_back(range);
240+
desc.m_push_constants.push_back(range);
241241

242242
m_pipeline_layout = device.CreatePipelineLayout(desc);
243243
}

engine/engine/src/physics/vehicle_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ inline physx::PxVehicleTireData TireData2PhysX(
3333
data.mFrictionVsSlipGraph[0][1] =
3434
tire.m_friction_vs_slip_config.m_friction_at_zero_slip;
3535
data.mFrictionVsSlipGraph[1][0] =
36-
tire.m_friction_vs_slip_config.m_slip_at_maximum_firction;
36+
tire.m_friction_vs_slip_config.m_slip_at_maximum_friction;
3737
data.mFrictionVsSlipGraph[1][1] =
38-
tire.m_friction_vs_slip_config.m_max_firction;
38+
tire.m_friction_vs_slip_config.m_max_friction;
3939
data.mFrictionVsSlipGraph[2][0] = tire.m_friction_vs_slip_config.m_max_slip;
4040
data.mFrictionVsSlipGraph[2][1] =
4141
tire.m_friction_vs_slip_config.m_friction_at_max_slip;

engine/tests/refl/drefl/factory.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ TEST_CASE("std::list", "array") {
258258
}
259259
}
260260

261-
262261
TEST_CASE("class factory") {
263262
struct Person {
264263
std::string name;

engine/tests/render/colorful_rectangle2/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class Application : public nickel::Application {
119119
push_constant.m_offset = 0;
120120
push_constant.m_size = sizeof(float) * 3;
121121
push_constant.m_shader_stage = ShaderStage::Fragment;
122-
desc.m_push_contants.push_back(push_constant);
122+
desc.m_push_constants.push_back(push_constant);
123123
m_pipeline_layout = device.CreatePipelineLayout(desc);
124124
}
125125

engine/tools/vehicle_editor/imgui_window.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ void TunningPanel::tunningWheelCommonConfig(
374374
std::array<ImPlotPoint, 3> points;
375375
points[0].x = 0;
376376
points[0].y = config.m_friction_at_zero_slip;
377-
points[1].x = config.m_slip_at_maximum_firction;
378-
points[1].y = config.m_max_firction;
377+
points[1].x = config.m_slip_at_maximum_friction;
378+
points[1].y = config.m_max_friction;
379379
points[2].x = config.m_max_slip;
380380
points[2].y = config.m_friction_at_max_slip;
381381
if (ImPlot::BeginPlot("friction-slip config")) {
@@ -399,8 +399,8 @@ void TunningPanel::tunningWheelCommonConfig(
399399
}
400400

401401
config.m_friction_at_zero_slip = points[0].y;
402-
config.m_slip_at_maximum_firction = points[1].x;
403-
config.m_max_firction = points[1].y;
402+
config.m_slip_at_maximum_friction = points[1].x;
403+
config.m_max_friction = points[1].y;
404404
config.m_max_slip = points[2].x;
405405
config.m_friction_at_max_slip = points[2].y;
406406
}

0 commit comments

Comments
 (0)