Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #50

Open
egelja opened this issue Jul 23, 2023 · 4 comments
Open

Refactoring #50

egelja opened this issue Jul 23, 2023 · 4 comments
Assignees
Labels
refactoring Refactoring or changes that do not affect the core program

Comments

@egelja
Copy link
Collaborator

egelja commented Jul 23, 2023

Most linters warn on cyclomatic complexity of 10.

terrain::Terrain::get_path_type has a complexity of 25.

Here are all the functions that need to be refactored:
image

@egelja egelja added the refactoring Refactoring or changes that do not affect the core program label Jul 23, 2023
@egelja egelja mentioned this issue Jul 23, 2023
@AlemSnyder
Copy link
Owner

terrain::Terrain::get_path_type should have at least 3^3 -1 possible outputs. To be honest having a complexity of less than 26 is impressive.

@AlemSnyder
Copy link
Owner

Message call back is just three switch statements.

Three of those are main type functions.

I think I brought get_first_not below 10.

terrain::Chunk::Chunk is not great, but its three discrete parts.

@AlemSnyder
Copy link
Owner

AlemSnyder commented Aug 5, 2023

Cyclomatic complexity of current main branch.

  • 12 terrain::Chunk::Chunk@11-50@./src/terrain/chunk.cpp
  • 25 terrain::Terrain::get_path_type@365-434@./src/terrain/terrain.cpp
  • 20 gui::message_callback@41-99@./src/gui/gui_logging.hpp
  • 21 entity::generate_mesh@145-367@./src/entity/mesh.hpp
  • 13 main@230-296@./src/main.cpp

There are also three duplicated blocks. Two are in terrain base and deal with grass initialization, the third is in terrain generation. Terrain generation will not be updated until Lua is implemented #17.

@AlemSnyder
Copy link
Owner

==========================================================================================
  NLOC    CCN   token  PARAM  length  location  
------------------------------------------------
      46     11    329      4      59 terrain::generation::TileType::TileType@8-66@./world/terrain/generation/mat_tile.cpp
      43     11    306      2      46 terrain::Terrain::get_path_breadth_first@498-543@./world/terrain/terrain.cpp
      33     12    346      2      41 terrain::Chunk::Chunk@11-51@./world/terrain/chunk.cpp
      49     11    378      1      60 terrain::generation::Biome::get_map@189-248@./world/biome.cpp
     106     12    639      3     172 gui::imgui_entry@46-217@./gui/ui/imgui_gui.cpp
     130     18    746      4     179 gui::gpu_data::VertexBufferObject<T,Buffer>::private_insert_@370-548@./gui/render/gpu_data/vertex_buffer_object.hpp
      29     13    210      1      30 tests@349-378@./main.cpp
==========================================================================================

gui::imgui_entry and tests are stetting up the code. Test is reading the command line input, and imgui_entry is rendering all the windows.

get_path_breadth_first and private_insert_ are horrible functions.

get_map is just testing all the lua errors.

Might be better to spend time fixing lua or multi-threading/generalizing chunks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Refactoring or changes that do not affect the core program
Projects
None yet
Development

No branches or pull requests

2 participants