From dcaa318d677a1a6881ccc87640ae75c0fc578bfb Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 2 Nov 2015 06:55:15 +0100 Subject: Initial --- .gitignore | 2 ++ Makefile | 52 +++++++++++++++++++++++++++++++++++++++++++++ global.h | 17 +++++++++++++++ library.cpp | 8 +++++++ library.h | 6 ++++++ main.cpp | 40 ++++++++++++++++++++++++++++++++++ object_base.cpp | 15 +++++++++++++ object_base.h | 16 ++++++++++++++ object_header_extractor.cpp | 7 ++++++ object_header_maker.cpp | 10 +++++++++ object_wrapper.cpp | 18 ++++++++++++++++ src/objects/obj_control.cpp | 12 +++++++++++ src/objects/obj_hoi.cpp | 11 ++++++++++ 13 files changed, 214 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 global.h create mode 100644 library.cpp create mode 100644 library.h create mode 100644 main.cpp create mode 100644 object_base.cpp create mode 100644 object_base.h create mode 100644 object_header_extractor.cpp create mode 100644 object_header_maker.cpp create mode 100644 object_wrapper.cpp create mode 100644 src/objects/obj_control.cpp create mode 100644 src/objects/obj_hoi.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d22bf76 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +game diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..05676ee --- /dev/null +++ b/Makefile @@ -0,0 +1,52 @@ +CXX := g++ +CXXFLAGS := -Wall -Wextra -std=c++11 -O2 -isystem /usr/local/include -I. +LIBS := -lfltk -L/usr/local/lib +BIN := game + +object_src := $(wildcard src/objects/*.cpp) +object_obj := $(patsubst src/objects/%.cpp,build/objects/%.o,$(object_src)) +object_head := $(patsubst src/objects/%.cpp,build/objects/%.h,$(object_src)) +object_xlist := $(shell echo $$(for f in $(object_src); do basename $$f | sed 's/\.[^.]*$$//' | sed 's/.*/X(&)/'; done)) + +base_src := $(wildcard *_base.cpp) +base_src += library.cpp main.cpp +base_obj := $(patsubst %.cpp,build/%.o,$(base_src)) + +.PHONY: all clean remake + +#keep all intermediate files! +.SECONDARY: + +all: $(BIN) + +clean: + rm -rf build $(BIN) + +remake: clean all + + +$(BIN): $(base_obj) $(object_obj) + $(CXX) $(CXXFLAGS) $(LIBS) -o $(BIN) $^ + +build/main.o: main.cpp build/objects.h + @mkdir -p $(dir $@) + $(CXX) $(CXXFLAGS) -c -o "$@" "$<" "-DOBJECT_CLASSES_XLIST=$(object_xlist)" "-DGAME_NAME=\"$(BIN)\"" + +build/objects/%.o: build/objects/%.cpp + @mkdir -p $(dir $@) + $(CXX) $(CXXFLAGS) -c -o "$@" $^ + +build/objects/%.cpp: src/objects/%.cpp + @mkdir -p $(dir $@) + $(CXX) -E object_wrapper.cpp "-D__OBJECT_FNAME__=\"$<\"" "-D__OBJECT_NAME__=$(basename $(notdir $<))" | sed 's/^# [0-9]\+ ".*//' >"$@" + +build/objects/%.h: src/objects/%.cpp + @mkdir -p $(dir $@) + $(CXX) -E object_header_maker.cpp "-D__OBJECT_NAME__=$(basename $(notdir $<))" "-DEVENT_XLIST=$$($(CXX) -E object_header_extractor.cpp "-D__OBJECT_FNAME__=\"$<\"" | sed 's/__________EVENT_NEWLINE__________/\n/g' | grep -oe '__________EVENT_COUNTER_TAG_[^_]*__________' | sed 's/[^G]*G_\(.*\)__________.*/X(\1)/g' | xargs)" | sed 's/^# [0-9]\+ ".*//' >"$@" + +build/objects.h: $(object_head) + echo $(object_head) | xargs -n 1 basename | sed 's,.*,#include "objects/&",' >"$@" + +build/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(CXXFLAGS) -c -o "$@" $^ diff --git a/global.h b/global.h new file mode 100644 index 0000000..65aaa5e --- /dev/null +++ b/global.h @@ -0,0 +1,17 @@ +#ifndef _GLOBAL_H_ +#define _GLOBAL_H_ + +#include +#include + +#include "object_base.h" + +using namespace std; + +class Global{ +public: + int room_speed=30; + vector> objects; +}; + +#endif //_GLOBAL_H_ diff --git a/library.cpp b/library.cpp new file mode 100644 index 0000000..5cfb68f --- /dev/null +++ b/library.cpp @@ -0,0 +1,8 @@ +#include +#include "library.h" + +using namespace std; + +void draw_text(int x,int y,const char *s){ + cerr<<"draw_text: x="< +#include +#include + +using namespace std; + +Global global; + +shared_ptr objectfromname(const char *name){ + +#define X(objname) if(strcmp(name,#objname)==0)return make_shared(); +OBJECT_CLASSES_XLIST +#undef X + + return NULL; //no object with that name +} + +void stepcallback(void*){ + Fl::repeat_timeout(1.0/30,stepcallback); +} + +int main(int argc,char **argv){ + Fl_Window *window=new Fl_Window(640,480,GAME_NAME); + + global.objects.push_back(objectfromname("obj_control")); + global.objects[0]->create(); + + window->end(); + Fl::visual(FL_RGB); + window->show(argc,argv); + Fl::add_timeout(1.0/30,stepcallback); + return Fl::run(); +} diff --git a/object_base.cpp b/object_base.cpp new file mode 100644 index 0000000..d37aa12 --- /dev/null +++ b/object_base.cpp @@ -0,0 +1,15 @@ +#include +#include "object_base.h" + +using namespace std; + +Object::Object(void){ + cerr<<"Object constructed!"<