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

Add file parsing #8

Merged
merged 3 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*.dSYM
*~
main
build/
24 changes: 15 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ SRCDIR := ./src
INCLUDEDIR := ./src
TESTSDIR := ./tests

CC := $(shell which g++ || which clang)
LDFLAGS := -Lefsw -lefsw
CFLAGS := -std=c++17 -pedantic -Wall -Wextra -I $(INCLUDEDIR)
C_CC := $(shell which gcc || which clang)
CPP_CC := $(shell which g++ || which clang)
LDFLAGS := -Lbuild -lefsw
ifeq ($(shell uname -s),Darwin)
LDFLAGS += -framework CoreFoundation -framework CoreServices
endif
CFLAGS := -std=c99 -pedantic -Wall -Wextra -I $(INCLUDEDIR)
CPPFLAGS := -std=c++17 -pedantic -Wall -Wextra -I $(INCLUDEDIR)
CDEBUG := -g
CRELEASE := -O2 -DRELEASE_BUILD
TARGET := main
Expand All @@ -19,21 +24,22 @@ build: library
make $(TARGET)

$(TARGET): main.cpp $(OBJ)
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
$(CPP_CC) $(CPPFLAGS) $^ -o $@ $(LDFLAGS)

%.o: %.cpp
@echo 'Compiling $@'
$(CC) $(CFLAGS) -MMD -MP $< -c -o $@
$(CPP_CC) $(CPPFLAGS) -MMD -MP $< -c -o $@

.PHONY: library
library:
cmake -DBUILD_SHARED_LIBS=OFF efsw
make -C efsw
git submodule update --init --recursive
CMAKE_C_COMPILER=$(C_CC) cmake -DBUILD_SHARED_LIBS=OFF -Bbuild efsw
cd build && make

.PHONY: clean
clean:
rm -rf $(OBJ) $(TARGET) $(shell find . -name "*.dSYM")
make -C efsw clean
cd efsw && make clean

.PHONY: run
run: build
Expand All @@ -44,7 +50,7 @@ test: CFLAGS += -DNO_LOGGING
test: $(OBJ)
@for f in $(TESTSDIR)/*.cpp; do \
echo " testing $$f"; \
$(CC) $(CFLAGS) "$$f" $^ -o $(TESTSDIR)/tmpexec; \
$(CPP_CC) $(CPPFLAGS) "$$f" $^ -o $(TESTSDIR)/tmpexec; \
$(TESTSDIR)/tmpexec && printf "\033[32m+ test $$f passed\033[m\n" || printf "\033[31m- test $$f failed\033[m\n"; \
done; \
find $(TESTSDIR) -type f -not -name "*.cpp" -delete; \
Expand Down
5 changes: 3 additions & 2 deletions tests/parseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ using namespace bwmodel;

int main() {
std::unique_ptr<Map> map = Map::load_from("./data/example.bwmap");
Game game(std::move(map));
Game game(std::move(map),
PlayerColor::WHITE /* we forgot the exact color */);

// TODO: add game start test
std::ifstream file("./data/example_chat.htm");
Expand Down Expand Up @@ -34,4 +35,4 @@ int main() {
== game.players_left().end());

return 0;
}
}