Permalink
Browse files

First step of a major refactoring to clear up the code base

  • Loading branch information...
1 parent 01cb4b5 commit 7d7ef4f5d881b6206e24471f04d12c323d05c19f @udoprog committed Dec 30, 2011
Showing with 970 additions and 568 deletions.
  1. +7 −0 .gitignore
  2. +3 −0 src/CMakeLists.txt
  3. +59 −0 src/dirlist.cpp
  4. +26 −0 src/dirlist.hpp
  5. +55 −0 src/engine/block_rotation.cpp
  6. +36 −0 src/engine/block_rotation.hpp
  7. 0 src/engine/engine_base.cpp
  8. +19 −145 src/engine/engine_base.hpp
  9. +18 −0 src/engine/engine_settings.hpp
  10. +14 −8 src/engine/fatiso_engine.cpp
  11. +4 −4 src/engine/fatiso_engine.hpp
  12. +32 −0 src/engine/functions.cpp
  13. +70 −0 src/engine/functions.hpp
  14. +14 −8 src/engine/isometric_engine.cpp
  15. +4 −4 src/engine/isometric_engine.hpp
  16. +10 −6 src/engine/oblique_engine.cpp
  17. +4 −4 src/engine/oblique_engine.hpp
  18. +11 −7 src/engine/obliqueangle_engine.cpp
  19. +4 −4 src/engine/obliqueangle_engine.hpp
  20. +13 −8 src/engine/topdown_engine.cpp
  21. +4 −4 src/engine/topdown_engine.hpp
  22. +5 −68 src/fileutils.hpp
  23. +68 −58 src/main.cpp
  24. +5 −0 src/mc/CMakeLists.txt
  25. +52 −0 src/mc/dynamic_buffer.cpp
  26. +40 −0 src/mc/dynamic_buffer.hpp
  27. +42 −0 src/mc/level.cpp
  28. +28 −39 src/mc/level.hpp
  29. +46 −0 src/mc/level_info.cpp
  30. +41 −0 src/mc/level_info.hpp
  31. +24 −0 src/mc/marker.cpp
  32. +27 −0 src/mc/marker.hpp
  33. +1 −66 src/mc/region.hpp
  34. +39 −0 src/mc/region_iterator.cpp
  35. +36 −0 src/mc/region_iterator.hpp
  36. +26 −0 src/mc/rotated_level_info.cpp
  37. +25 −0 src/mc/rotated_level_info.hpp
  38. +0 −18 src/mc/utils.hpp
  39. +5 −16 src/mc/world.cpp
  40. +1 −73 src/mc/world.hpp
  41. +2 −23 src/nbt/nbt.hpp
  42. +29 −0 src/nbt/types.hpp
  43. +7 −5 src/threads/renderer.hpp
  44. +14 −0 src/threads/renderer_settings.hpp
View
@@ -1,3 +1,10 @@
*~
*.pyc
build
+*.cmake
+*.a
+Makefile
+CMakeFiles
+*.orig
+*.rej
+src/config.hpp
View
@@ -5,6 +5,7 @@ add_subdirectory(mc)
set(c10t_SOURCES algorithm.cpp)
set(c10t_SOURCES ${c10t_SOURCES} players.cpp)
set(c10t_SOURCES ${c10t_SOURCES} fileutils.cpp)
+set(c10t_SOURCES ${c10t_SOURCES} dirlist.cpp)
set(c10t_SOURCES ${c10t_SOURCES} utf8.cpp)
set(c10t_SOURCES ${c10t_SOURCES} altitude_graph.cpp)
set(c10t_SOURCES ${c10t_SOURCES} warps.cpp)
@@ -14,6 +15,8 @@ set(c10t_SOURCES ${c10t_SOURCES} engine/oblique_engine.cpp)
set(c10t_SOURCES ${c10t_SOURCES} engine/obliqueangle_engine.cpp)
set(c10t_SOURCES ${c10t_SOURCES} engine/isometric_engine.cpp)
set(c10t_SOURCES ${c10t_SOURCES} engine/fatiso_engine.cpp)
+set(c10t_SOURCES ${c10t_SOURCES} engine/functions.cpp)
+set(c10t_SOURCES ${c10t_SOURCES} engine/block_rotation.cpp)
set(c10t_LIBRARIES ${c10t_LIBRARIES} c10t-image c10t-nbt c10t-mc)
View
@@ -0,0 +1,59 @@
+#include "dirlist.hpp"
+#include "fileutils.hpp"
+
+dirlist::dirlist(const fs::path path) {
+ if (fs::is_directory(path))
+ directories.push(path);
+}
+
+bool dirlist::has_next(dir_filter_func dir_filter, file_filter_func file_filter)
+{
+ if (!files.empty()) {
+ return true;
+ }
+
+ if (directories.empty()) {
+ return false;
+ }
+
+ // work until you find any files
+ while (!directories.empty()) {
+ fs::path dir_path = directories.front();
+ directories.pop();
+
+ if (!fs::is_directory(dir_path)) {
+ continue;
+ }
+
+ fs::directory_iterator end_itr;
+
+ for ( fs::directory_iterator itr( dir_path );
+ itr != end_itr;
+ ++itr )
+ {
+ if (fs::is_directory(itr->status())) {
+ if (!dir_filter(fs::basename(itr->path()))) {
+ continue;
+ }
+
+ directories.push(itr->path());
+ }
+ else if (fs::is_regular_file(itr->status())) {
+ if (!file_filter(path_string(itr->path()))) {
+ continue;
+ }
+
+ files.push(itr->path());
+ }
+ }
+ }
+
+ return !files.empty();
+}
+
+fs::path dirlist::next()
+{
+ fs::path next = files.front();
+ files.pop();
+ return next;
+}
View
@@ -0,0 +1,26 @@
+#ifndef _DIRLIST_HPP
+#define _DIRLIST_HPP
+
+#include <queue>
+#include <string>
+
+#include <boost/filesystem.hpp>
+
+namespace fs = boost::filesystem;
+
+class dirlist {
+public:
+ typedef bool (dir_filter_func)(const std::string&);
+ typedef bool (file_filter_func)(const std::string&);
+
+ dirlist(const fs::path path);
+
+ bool has_next(dir_filter_func, file_filter_func);
+
+ fs::path next();
+private:
+ std::queue<fs::path> directories;
+ std::queue<fs::path> files;
+};
+
+#endif /* _DIRLIST_HPP */
@@ -0,0 +1,55 @@
+#include "engine/block_rotation.hpp"
+
+#include "mc/blocks.hpp"
+
+block_rotation::block_rotation(
+ int rotation,
+ boost::shared_ptr<nbt::ByteArray> byte_array)
+ : rotation(rotation), byte_array(byte_array)
+{
+}
+
+void block_rotation::set_xz(int x, int z) {
+ transform_xz(x, z);
+ this->x = x;
+ this->z = z;
+}
+
+/**
+ * Blocks[ z + ( y * ChunkSizeY(=128) + ( x * ChunkSizeY(=128) * ChunkSizeZ(=16) ) ) ];
+ */
+uint8_t block_rotation::get8(int y) {
+ int p = y + (z * mc::MapY) + (x * mc::MapY * mc::MapZ);
+ if (!(p >= 0 && p < byte_array->length)) return -1;
+ return byte_array->values[p];
+}
+
+uint8_t block_rotation::get8() {
+ int p = x + (z * mc::MapX);
+ assert (p >= 0 && p < byte_array->length);
+ return byte_array->values[p];
+}
+
+int block_rotation::get4(int y) {
+ int p = (y + (z * mc::MapY) + (x * mc::MapY * mc::MapZ)) >> 1;
+ if (!(p >= 0 && p < byte_array->length)) return -1;
+ return ((byte_array->values[p]) >> ((y % 2) * 4)) & 0xf;
+}
+
+void block_rotation::transform_xz(int& x, int& z) {
+ int t = x;
+ switch (rotation) {
+ case 270:
+ x = mc::MapX - z - 1;
+ z = t;
+ break;
+ case 180:
+ z = mc::MapZ - z - 1;
+ x = mc::MapX - x - 1;
+ break;
+ case 90:
+ x = z;
+ z = mc::MapZ - t - 1;
+ break;
+ };
+}
@@ -0,0 +1,36 @@
+#ifndef _ENGINE_BLOCK_ROTATION_HPP
+#define _ENGINE_BLOCK_ROTATION_HPP
+
+#include <stdint.h>
+
+#include <boost/shared_ptr.hpp>
+
+#include "nbt/types.hpp"
+
+class block_rotation {
+public:
+ block_rotation(int rotation, boost::shared_ptr<nbt::ByteArray> byte_array);
+
+ void set_xz(int x, int z);
+
+ /**
+ * Blocks[ z + ( y * ChunkSizeY(=128) + ( x * ChunkSizeY(=128) * ChunkSizeZ(=16) ) ) ];
+ */
+ uint8_t get8(int y);
+
+ uint8_t get8();
+
+ int get4(int y);
+private:
+ int rotation;
+ boost::shared_ptr<nbt::ByteArray> byte_array;
+
+ int x, z;
+
+ void transform_xz(int& x, int& z);
+};
+
+/* For backwards compatibility */
+typedef block_rotation BlockRotation;
+
+#endif /* _ENGINE_BLOCK_ROTATION_HPP */
No changes.
Oops, something went wrong.

0 comments on commit 7d7ef4f

Please sign in to comment.