Added a makefile

This commit is contained in:
2021-01-23 14:44:06 -05:00
parent 827a114752
commit b85e92343f
8 changed files with 42 additions and 36 deletions

1
luprex/.gitignore vendored
View File

@@ -4,6 +4,7 @@
*.exe *.exe
inc/** inc/**
lib/** lib/**
obj/**
.vscode/** .vscode/**
luajit/src/lj_bcdef.h luajit/src/lj_bcdef.h
luajit/src/lj_ffdef.h luajit/src/lj_ffdef.h

27
luprex/Makefile Normal file
View File

@@ -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)

View File

@@ -1,2 +1,2 @@
clear 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

View File

@@ -1,8 +1,6 @@
#include "animqueue.hpp"
#include "luastack.hpp"
#include <limits> #include <limits>
#include "luastack.hpp"
#include "animqueue.hpp"
AnimStep::AnimStep() {} AnimStep::AnimStep() {}
AnimStep::~AnimStep() {} AnimStep::~AnimStep() {}
@@ -89,8 +87,8 @@ void AnimView::update_from(const AnimQueue &queue) {
} }
AnimView *AnimViewMap::get_one(int64_t id) { AnimView *AnimViewMap::get_one(int64_t id) {
auto iter = view_map_.find(id); auto iter = find(id);
if (iter == view_map_.end()) { if (iter == end()) {
return nullptr; return nullptr;
} else { } else {
return &iter->second; return &iter->second;
@@ -98,23 +96,23 @@ AnimView *AnimViewMap::get_one(int64_t id) {
} }
void AnimViewMap::clear_updated_bits() { void AnimViewMap::clear_updated_bits() {
for (auto pair : view_map_) { for (auto pair : *this) {
pair.second.updated_ = false; pair.second.updated_ = false;
} }
} }
void AnimViewMap::delete_non_updated() { 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_) { if (iter->second.updated_) {
iter++; iter++;
} else { } else {
iter = view_map_.erase(iter); iter = erase(iter);
} }
} }
} }
void AnimViewMap::update_one(const AnimQueue &queue) { 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") { LuaDefine(unittests_animqueue, "c") {

View File

@@ -119,33 +119,14 @@ public:
void update_from(const AnimQueue &queue); 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 class AnimViewMap : public std::unordered_map<int64_t, AnimView> {
// that haven't been updated recently.
//
class AnimViewMap {
public: public:
using ViewMap = std::unordered_map<int64_t, AnimView>;
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); AnimView *get_one(int64_t id);
// Clear the updated bits on all the AnimViews.
void clear_updated_bits(); void clear_updated_bits();
// Delete any AnimViews whose updated bits are not set.
void delete_non_updated(); void delete_non_updated();
// Update one AnimView, and set its updated bit.
void update_one(const AnimQueue &queue); void update_one(const AnimQueue &queue);
}; };

View File

@@ -1,6 +1,5 @@
#include "luastack.hpp" #include "luastack.hpp"
#include "globaldb.hpp" #include "globaldb.hpp"
#include "table.hpp"
LuaDefine(globaldb_enable, "c") { LuaDefine(globaldb_enable, "c") {
LuaVar globaldb; LuaVar globaldb;

View File

@@ -1,8 +1,8 @@
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
#include "luastack.hpp" #include "luastack.hpp"
#include "planemap.hpp"
#include "util.hpp" #include "util.hpp"
#include "planemap.hpp"
// Cell X, Y coordinates are packed such that they have 24 bits for X and Y. // Cell X, Y coordinates are packed such that they have 24 bits for X and Y.
// A cell is 10 Meters square. // A cell is 10 Meters square.

View File

@@ -10,9 +10,9 @@
#include "util.hpp" #include "util.hpp"
#include "luastack.hpp" #include "luastack.hpp"
#include "traceback.hpp"
#include "table.hpp" #include "table.hpp"
#include "source.hpp" #include "source.hpp"
#include "traceback.hpp"
LuaDefine(source_makeclass, "f") { LuaDefine(source_makeclass, "f") {