Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyuu17 committed Jun 30, 2024
1 parent 879d440 commit 1b169c9
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 24 deletions.
8 changes: 7 additions & 1 deletion src/SWBF2/Core.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#include <godot_cpp/variant/utility_functions.hpp>
#include <godot_cpp/classes/camera3d.hpp>

#include "Native/Chunks/ChunkProcessor.hpp"
#include "Native/SWBF2.hpp"
Expand Down Expand Up @@ -43,6 +44,11 @@ namespace SWBF2
{
godot::ClassDB::bind_method(godot::D_METHOD("get_mapname"), &Core::GetMapName);
godot::ClassDB::bind_method(godot::D_METHOD("load_level", "mapname"), &Core::LoadLevel);
godot::ClassDB::add_property("Core", godot::PropertyInfo(godot::Variant::STRING, "mapname", godot::PROPERTY_HINT_ENUM, "cor1"), "load_level", "get_mapname");

std::string mapList;
for (const auto &[mapId, mapPath] : SWBF2::Native::DefaultGameMaps)
mapList = std::format("{},{}", mapList, mapId);

godot::ClassDB::add_property("Core", godot::PropertyInfo(godot::Variant::STRING, "mapname", godot::PROPERTY_HINT_ENUM, mapList.c_str()), "load_level", "get_mapname");
}
}
6 changes: 3 additions & 3 deletions src/SWBF2/Native/Chunks/WorldChunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "Native/Chunks/StreamReader.hpp"
#include "Native/Chunks/WorldChunk.hpp"
#include "Native/Instance.hpp"
#include "Native/GameObject.hpp"
#include "Native/SWBF2.hpp"

namespace SWBF2::Native
Expand Down Expand Up @@ -55,7 +55,7 @@ namespace SWBF2::Native

void WorldChunk::ProcessInstChunk(StreamReader &streamReader, World &world)
{
Instance inst{};
GameObject inst{};

auto infoReaderChild = streamReader.ReadChildWithHeader<"INFO"_m>();
{
Expand Down Expand Up @@ -85,7 +85,7 @@ namespace SWBF2::Native
std::optional<StreamReader> propReaderChild;
while ((propReaderChild = streamReader.ReadChildWithHeader<"PROP"_m>()).has_value())
{
uint32_t prop;
FNVHash prop;
*propReaderChild >> prop;

std::string value;
Expand Down
10 changes: 0 additions & 10 deletions src/SWBF2/Native/Element.hpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

#pragma once

#include "Element.hpp"

namespace SWBF2::Native
{
class Instance : public Element {
class GameObject {
public:
std::string m_type;
std::string m_name;

godot::Basis m_rotationMatrix;
godot::Vector3 m_position;

std::unordered_map<uint32_t, std::string> m_properties;
};
}
2 changes: 1 addition & 1 deletion src/SWBF2/Native/SWBF2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace SWBF2::Native
{
m_curMapName = levelname;

return UcfbChunk::ReadUcfbFile(std::format("data/_lvl_pc/{}.lvl", GameMaps.at(levelname)));
return UcfbChunk::ReadUcfbFile(std::format("data/_lvl_pc/{}.lvl", DefaultGameMaps.at(levelname)));
}

void SWBF2::LoadGamemode(LevelGamemode gamemode)
Expand Down
5 changes: 3 additions & 2 deletions src/SWBF2/Native/SWBF2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

namespace SWBF2::Native
{
const static inline std::unordered_map<std::string_view, std::string_view> GameMaps
const static inline std::unordered_map<std::string_view, std::string_view> DefaultGameMaps
{
// name, path
{ "cor1", "cor/cor1" }
{ "cor1", "cor/cor1" },
{ "yav1", "yav/yav1" }
};

enum class LevelGamemode
Expand Down
2 changes: 0 additions & 2 deletions src/SWBF2/Native/Texture/TextureUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ namespace SWBF2::Native::TextureUtils

imageBuf.resize(width * height * 2);

//memset(imageBuf.ptrw(), 0xFF, width * height * 2);

for (uint32_t y = 0; y < height; ++y) {
for (uint32_t x = 0; x < width; ++x) {
uint16_t d3dPixel = reinterpret_cast<uint16_t &>(bytes[y * width + x]);
Expand Down
4 changes: 2 additions & 2 deletions src/SWBF2/Native/World.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#pragma once

#include "Instance.hpp"
#include "GameObject.hpp"

namespace SWBF2::Native
{
Expand All @@ -11,6 +11,6 @@ namespace SWBF2::Native
std::string m_terrainName;
std::string m_skyName;

std::vector<Instance> m_instances;
std::vector<GameObject> m_instances;
};
}

0 comments on commit 1b169c9

Please sign in to comment.