diff --git a/luprex/.gitignore b/luprex/.gitignore index 21435866..ab877699 100644 --- a/luprex/.gitignore +++ b/luprex/.gitignore @@ -4,6 +4,7 @@ *.exe inc/** lib/** +obj/** .vscode/** luajit/src/lj_bcdef.h luajit/src/lj_ffdef.h diff --git a/luprex/Makefile b/luprex/Makefile new file mode 100644 index 00000000..f57e4017 --- /dev/null +++ b/luprex/Makefile @@ -0,0 +1,27 @@ + +CXX=g++ -std=c++17 -Wall -g -Iinc -Isyscpp + +CPP_FILES=\ + syscpp/util.cpp\ + syscpp/luastack.cpp\ + syscpp/traceback.cpp\ + syscpp/planemap.cpp\ + syscpp/idalloc.cpp\ + syscpp/globaldb.cpp\ + syscpp/table.cpp\ + syscpp/animqueue.cpp\ + syscpp/source.cpp\ + syscpp/world.cpp\ + syscpp/viewer.cpp\ + syscpp/textgame.cpp\ + syscpp/main.cpp + +OBJ_FILES=$(patsubst syscpp/%.cpp,obj/%.o,$(CPP_FILES)) + +obj/%.o: syscpp/%.cpp + $(CXX) -c -MMD $< -o $@ + +main.exe: $(OBJ_FILES) + $(CXX) -o main.exe $(OBJ_FILES) -Llib lib/libluajit-dbg.a + +-include $(OBJ_FILES:%.o=%.d) diff --git a/luprex/build.bat b/luprex/build.bat index a502b553..8b2f4e26 100644 --- a/luprex/build.bat +++ b/luprex/build.bat @@ -1,2 +1,2 @@ clear -g++ -std=c++17 -Wall -g -o main syscpp/util.cpp syscpp/viewer.cpp syscpp/main.cpp syscpp/textgame.cpp syscpp/animqueue.cpp syscpp/planemap.cpp syscpp/world.cpp syscpp/traceback.cpp syscpp/luastack.cpp syscpp/source.cpp syscpp/table.cpp syscpp/idalloc.cpp syscpp/globaldb.cpp -Iinc -Llib lib/libluajit-dbg.a -Isyscpp +make main.exe diff --git a/luprex/syscpp/animqueue.cpp b/luprex/syscpp/animqueue.cpp index 41a8aa5b..b9bffa3f 100644 --- a/luprex/syscpp/animqueue.cpp +++ b/luprex/syscpp/animqueue.cpp @@ -1,8 +1,6 @@ - -#include "animqueue.hpp" -#include "luastack.hpp" #include - +#include "luastack.hpp" +#include "animqueue.hpp" AnimStep::AnimStep() {} AnimStep::~AnimStep() {} @@ -89,8 +87,8 @@ void AnimView::update_from(const AnimQueue &queue) { } AnimView *AnimViewMap::get_one(int64_t id) { - auto iter = view_map_.find(id); - if (iter == view_map_.end()) { + auto iter = find(id); + if (iter == end()) { return nullptr; } else { return &iter->second; @@ -98,23 +96,23 @@ AnimView *AnimViewMap::get_one(int64_t id) { } void AnimViewMap::clear_updated_bits() { - for (auto pair : view_map_) { + for (auto pair : *this) { pair.second.updated_ = false; } } void AnimViewMap::delete_non_updated() { - for (auto iter = view_map_.begin(); iter != view_map_.end(); ) { + for (auto iter = begin(); iter != end(); ) { if (iter->second.updated_) { iter++; } else { - iter = view_map_.erase(iter); + iter = erase(iter); } } } void AnimViewMap::update_one(const AnimQueue &queue) { - view_map_[queue.get_id()].update_from(queue); + operator[](queue.get_id()).update_from(queue); } LuaDefine(unittests_animqueue, "c") { diff --git a/luprex/syscpp/animqueue.hpp b/luprex/syscpp/animqueue.hpp index 26ac52bc..d1fb265a 100644 --- a/luprex/syscpp/animqueue.hpp +++ b/luprex/syscpp/animqueue.hpp @@ -119,33 +119,14 @@ public: void update_from(const AnimQueue &queue); }; -// AnimViewMap: basically just a map from tangible ID to AnimView. +// AnimViewMap: a unordered_map from tangible ID to AnimView. Adds a few +// methods for garbage collection and updating. // -// Also provides a simple garbage collector to get rid of AnimViews -// that haven't been updated recently. -// -class AnimViewMap { +class AnimViewMap : public std::unordered_map { public: - using ViewMap = std::unordered_map; -private: - ViewMap view_map_; -public: - AnimViewMap() {} - ~AnimViewMap() {} - - // Get the entire view map for iterating over. - ViewMap &get_map() { return view_map_; } - - // Get one entry from the view map, if it exists. AnimView *get_one(int64_t id); - - // Clear the updated bits on all the AnimViews. void clear_updated_bits(); - - // Delete any AnimViews whose updated bits are not set. void delete_non_updated(); - - // Update one AnimView, and set its updated bit. void update_one(const AnimQueue &queue); }; diff --git a/luprex/syscpp/globaldb.cpp b/luprex/syscpp/globaldb.cpp index 446cfb80..a6dbb281 100644 --- a/luprex/syscpp/globaldb.cpp +++ b/luprex/syscpp/globaldb.cpp @@ -1,6 +1,5 @@ #include "luastack.hpp" #include "globaldb.hpp" -#include "table.hpp" LuaDefine(globaldb_enable, "c") { LuaVar globaldb; diff --git a/luprex/syscpp/planemap.cpp b/luprex/syscpp/planemap.cpp index 9b822ebf..e5da06ca 100644 --- a/luprex/syscpp/planemap.cpp +++ b/luprex/syscpp/planemap.cpp @@ -1,8 +1,8 @@ #include #include #include "luastack.hpp" -#include "planemap.hpp" #include "util.hpp" +#include "planemap.hpp" // Cell X, Y coordinates are packed such that they have 24 bits for X and Y. // A cell is 10 Meters square. diff --git a/luprex/syscpp/source.cpp b/luprex/syscpp/source.cpp index 55beb5d1..1673e635 100644 --- a/luprex/syscpp/source.cpp +++ b/luprex/syscpp/source.cpp @@ -10,9 +10,9 @@ #include "util.hpp" #include "luastack.hpp" +#include "traceback.hpp" #include "table.hpp" #include "source.hpp" -#include "traceback.hpp" LuaDefine(source_makeclass, "f") {