From e3cd17d1a10fd12bb38badddc951ba45424d683f Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Thu, 7 Mar 2019 03:50:05 +0100 Subject: Update to travis build test --- .gitignore | 1 + .travis.yml | 2 +- Makefile | 3 - example/3d.cpp | 165 ++++++++++++++++++++++++++++++++++++++++++++++++ example/Makefile | 11 ++-- example/collision.cpp | 142 +++++++++++++++++++++++++++++++++++++++++ example/test.cpp | 172 ++++++++++++++++++-------------------------------- example/test_old.cpp | 165 ------------------------------------------------ 8 files changed, 376 insertions(+), 285 deletions(-) create mode 100644 example/3d.cpp create mode 100644 example/collision.cpp delete mode 100644 example/test_old.cpp diff --git a/.gitignore b/.gitignore index dd2f851..e9cc8ed 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.so* *.txt *.out +.atom* build/* doc/* version.h diff --git a/.travis.yml b/.travis.yml index c51e18b..0cfa094 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,2 @@ language: cpp -script: make && make test +script: make && cd example && make test diff --git a/Makefile b/Makefile index 4a44197..0977092 100644 --- a/Makefile +++ b/Makefile @@ -67,9 +67,6 @@ gentest: build $(TESTSOURCE).o mkdir -p $(BUILDDIR)/test $(CC) $(DEBUGFLAGS) -o $(BUILDDIR)/test/test $(TESTSOURCE).o $(OBJ) $(LDFLAGS) -test: gentest - ./$(BUILDDIR)/test/test test - doc: mkdir -p doc doxygen .doxygen diff --git a/example/3d.cpp b/example/3d.cpp new file mode 100644 index 0000000..313b632 --- /dev/null +++ b/example/3d.cpp @@ -0,0 +1,165 @@ +#include +#include + +#include "version.h" + +#include "cRender.h" +#include "cObject.h" +#include "cObjectHandler.h" +#include "cInput.h" +#include "cWiremesh.h" + +//#include "testobject.h" + +class testobject : cObject +{ +public: + testobject() + { + setSize(10,5); + cc = 0; + + drawRectangle('#', NULL, {0,0}, {9,4}, _COL_GREEN, _COL_DEFAULT); + } + + ~testobject() { destruct(); } + + virtual void onClick(sPos _pos, unsigned int _button) + { + cc++; + drawText(std::to_string(cc), {2,2}, _COL_RED); + + drawPoint('Q', _pos, true, _COL_YELLOW); + } + + virtual void onChar(unsigned char _c) { drawPoint(_c, {1,1},true, _COL_BLUE); } +private: + int cc; +}; + +int main(int argc, char* argv[]) +{ + cRender render(' ', _COL_DEFAULT, 30,30); + cObjectHandler handler(&render); + cObject ver(45,1); + cWiremesh obj; + testobject obj2; + + cInput input; + + unsigned int framecounter = 0; + bool loop = true; + + if(argc > 1) + { + loop = false; + } + + render.render(); + + ver.drawText(DATE, {20,0}, _COL_WHITE); + ver.drawText(VERSTRING, {0,0}, _COL_WHITE); + int iver = handler.createObject(&ver); + handler.moveObject(iver, {0,0}, _MOVE_ABSOLUTE); + + int x = 15; + int y = 15; + int z = 30; + + obj.addVector({-x,-y,z}, {2*x,0,0}, '+', _COL_RED); + obj.addVector({-x,-y,z}, {0,2*y,0}, '+', _COL_RED); + obj.addVector({-x,y,z}, {2*x,0,0}, '+', _COL_RED); + obj.addVector({x,-y,z}, {0,2*y,0}, '+', _COL_RED); + + obj.addVector({-x,-y,0}, {0,0,z}, ':', _COL_RED); + obj.addVector({x,-y,0}, {0,0,z}, ':', _COL_RED); + obj.addVector({-x,y,0}, {0,0,z}, ':', _COL_RED); + obj.addVector({x,y,0}, {0,0,z}, ':', _COL_RED); + + obj.addVector({-x,-y,0}, {2*x,0,0}, ',', _COL_RED); + obj.addVector({-x,-y,0}, {0,2*y,0}, ',', _COL_RED); + obj.addVector({-x,y,0}, {2*x,0,0}, ',', _COL_RED); + obj.addVector({x,-x,0}, {0,2*y,0}, ',', _COL_RED); + int imesh = handler.createWiremesh(&obj); + + int iobj2 = handler.createObject((cObject*)&obj2); + handler.moveObject(iobj2, {3,3}, _MOVE_ABSOLUTE); + + sPos middle = render.getSize(); + middle.x /= 2; + middle.y /= 2; + + handler.moveWiremesh(imesh,{middle.x,middle.y,0}, _MOVE_ABSOLUTE); + + while( loop ) + { + sInputEvent ie = input.poll(); + + if(ie.type != _EVENT_NULL) + { + if(ie.type == _EVENT_KEY) + { + switch (ie.c) + { + case 'A'://up + handler.setCameraPosition({0,-1}, _MOVE_RELATIVE); + break; + case 'B'://down + handler.setCameraPosition({0,1}, _MOVE_RELATIVE); + break; + case 'C'://right + handler.setCameraPosition({1,0}, _MOVE_RELATIVE); + break; + case 'D'://left + handler.setCameraPosition({-1,0}, _MOVE_RELATIVE); + break; + }; + } + else if (ie.type == _EVENT_MOUSE) + { + if(ie.b == 0) + handler.clickEvent({ie.x, ie.y}, 0); + } + else if (ie.type == _EVENT_CHAR) + { + //handler.charEvent(ie.c); + switch(ie.c) + { + case 'w': + handler.rotateWiremesh(imesh,{-10,0,0}); + break; + case 's': + handler.rotateWiremesh(imesh,{10,0,0}); + break; + case 'a': + handler.rotateWiremesh(imesh,{0,-10,0}); + break; + case 'd': + handler.rotateWiremesh(imesh,{0,10,0}); + break; + case 'q': + handler.rotateWiremesh(imesh,{0,0,-10}); + break; + case 'e': + handler.rotateWiremesh(imesh,{0,0,10}); + break; + }; + } + else if (ie.type == _EVENT_TERM) + { + return 0; + } + } + + handler.rotateWiremesh(imesh,{1,1,1}); + + handler.write(); + render.render(); + framecounter++; + + if(loop) + usleep(10*1000); + } + + return 0; +} diff --git a/example/Makefile b/example/Makefile index 9ae78ca..f72ad2f 100644 --- a/example/Makefile +++ b/example/Makefile @@ -2,8 +2,11 @@ CC = /usr/bin/g++ LIBDIR = ../build/lib INCDIR = ../build/inc -.PHONY: pong - -pong: - $(CC) -I$(INCDIR) -L$(LIBDIR) -lengine $@.cpp -o $@.out +%: %.cpp + $(CC) -I$(INCDIR) -L$(LIBDIR) -lengine $< -o $@.out LD_LIBRARY_PATH=$(LIBDIR) ./$@.out + +.PHONY: clean + +clean: + rm -df *.out diff --git a/example/collision.cpp b/example/collision.cpp new file mode 100644 index 0000000..7759dae --- /dev/null +++ b/example/collision.cpp @@ -0,0 +1,142 @@ +#include +#include + +#include "version.h" + +#include "cRender.h" +#include "cObject.h" +#include "cObjectHandler.h" +#include "cInput.h" +#include "cWiremesh.h" + +//#include "testobject.h" + +class testobject : cObject +{ +public: + testobject() + { + setSize(10,5); + cc = 0; + kc = 0; + + drawRectangle('#', NULL, {0,0}, {9,4}, _COL_GREEN, _COL_DEFAULT); + } + + ~testobject() { destruct(); } + + virtual void onClick(sPos _pos, unsigned int _button) + { + cc++; + drawText(std::to_string(cc), {2,2}, _COL_RED); + + drawPoint('Q', _pos, true, _COL_YELLOW); + } + + virtual bool onCollisionActive(sPos _hit, int _passiveObject){ + kc++; + drawText(std::to_string(kc), {0,0}, _COL_RED); + return true; + } + + virtual void onChar(unsigned char _c) { drawPoint(_c, {1,1},true, _COL_BLUE); } +private: + int cc; + int kc; +}; + +int main(int argc, char* argv[]) +{ + cRender render(' ', _COL_DEFAULT, 30,30); + cObjectHandler handler(&render); + cObject ver(45,1); + testobject obj2; + + cInput input; + + unsigned int framecounter = 0; + bool loop = true; + + if(argc > 1) + { + loop = false; + } + + render.render(); + + ver.drawText(DATE, {20,0}, _COL_WHITE); + ver.drawText(VERSTRING, {0,0}, _COL_WHITE); + int iver = handler.createObject(&ver); + handler.moveObject(iver, {0,0}, _MOVE_FORCE_ABSOLUTE); + + int iobj2 = handler.createObject((cObject*)&obj2); + handler.moveObject(iobj2, {3,3}, _MOVE_FORCE_ABSOLUTE); + + sPos middle = render.getSize(); + middle.x /= 2; + middle.y /= 2; + + while( loop ) + { + sInputEvent ie = input.poll(); + + if(ie.type != _EVENT_NULL) + { + if(ie.type == _EVENT_KEY) + { + switch (ie.c) + { + case 'A'://up + handler.setCameraPosition({0,-1}, _MOVE_RELATIVE); + break; + case 'B'://down + handler.setCameraPosition({0,1}, _MOVE_RELATIVE); + break; + case 'C'://right + handler.setCameraPosition({1,0}, _MOVE_RELATIVE); + break; + case 'D'://left + handler.setCameraPosition({-1,0}, _MOVE_RELATIVE); + break; + }; + } + else if (ie.type == _EVENT_MOUSE) + { + if(ie.b == 0) + handler.clickEvent({ie.x, ie.y}, 0); + } + else if (ie.type == _EVENT_CHAR) + { + //handler.charEvent(ie.c); + switch(ie.c) + { + case 'w': + handler.moveObject(iobj2, {0,-1}, _MOVE_RELATIVE); + break; + case 's': + handler.moveObject(iobj2, {0,1}, _MOVE_RELATIVE); + break; + case 'a': + handler.moveObject(iobj2, {-1,0}, _MOVE_RELATIVE); + break; + case 'd': + handler.moveObject(iobj2, {1,0}, _MOVE_RELATIVE); + break; + }; + } + else if (ie.type == _EVENT_TERM) + { + return 0; + } + } + + handler.write(); + render.render(); + framecounter++; + + if(loop) + usleep(10*1000); + } + + return 0; +} diff --git a/example/test.cpp b/example/test.cpp index 7759dae..aebca71 100644 --- a/example/test.cpp +++ b/example/test.cpp @@ -1,142 +1,90 @@ -#include -#include +#include +#include +#include +#include -#include "version.h" - -#include "cRender.h" -#include "cObject.h" -#include "cObjectHandler.h" -#include "cInput.h" -#include "cWiremesh.h" - -//#include "testobject.h" - -class testobject : cObject +class ball : public cObject { public: - testobject() + ball() : v({1,1}) { setSize(1,1); drawPoint('O', {0,0}, true, _COL_RED); } + ~ball() { destruct(); } + virtual bool onCollisionActive(sPos _hit, int _passiveObject) { - setSize(10,5); - cc = 0; - kc = 0; + if(_passiveObject == 1) + v.y = v.y * (-1); + else if (_passiveObject == 2) + v.x = v.x * (-1); - drawRectangle('#', NULL, {0,0}, {9,4}, _COL_GREEN, _COL_DEFAULT); + drawText(std::to_string(_passiveObject), {0,0}, _COL_GREEN); + return true; } + sPos getV() { return v; } +private: + sPos v; +}; - ~testobject() { destruct(); } - - virtual void onClick(sPos _pos, unsigned int _button) +class edge : public cObject +{ +public: + edge(unsigned int x, unsigned int y) { setSize(x,y); drawLine('#', {0,0},{x-1,y-1}, true, _COL_DEFAULT);} + ~edge() { destruct(); } + virtual int onCollisionPassive(sPos _hit) { - cc++; - drawText(std::to_string(cc), {2,2}, _COL_RED); - - drawPoint('Q', _pos, true, _COL_YELLOW); - } - - virtual bool onCollisionActive(sPos _hit, int _passiveObject){ - kc++; - drawText(std::to_string(kc), {0,0}, _COL_RED); - return true; + if(getSize().x > getSize().y) + return 1; + else + return 2; } - - virtual void onChar(unsigned char _c) { drawPoint(_c, {1,1},true, _COL_BLUE); } -private: - int cc; - int kc; }; -int main(int argc, char* argv[]) +int main() { - cRender render(' ', _COL_DEFAULT, 30,30); - cObjectHandler handler(&render); - cObject ver(45,1); - testobject obj2; + cRender render(' ', _COL_DEFAULT, 10,10); + cObjectHandler screen(&render); + cInput input; - cInput input; + ball aball; + edge edgeLeft(1,10); + edge edgeRight(1,10); + edge edgeTop(10,1); + edge edgeBottom(10,1); - unsigned int framecounter = 0; - bool loop = true; + int iEdgeTop = screen.createObject(&edgeTop); + screen.moveObject(iEdgeTop, {0,0}, _MOVE_FORCE_ABSOLUTE); - if(argc > 1) - { - loop = false; - } + int iEdgeBottom = screen.createObject(&edgeBottom); + screen.moveObject(iEdgeBottom, {0,10}, _MOVE_FORCE_ABSOLUTE); - render.render(); + int iEdgeLeft = screen.createObject(&edgeLeft); + screen.moveObject(iEdgeLeft, {0,0}, _MOVE_FORCE_ABSOLUTE); - ver.drawText(DATE, {20,0}, _COL_WHITE); - ver.drawText(VERSTRING, {0,0}, _COL_WHITE); - int iver = handler.createObject(&ver); - handler.moveObject(iver, {0,0}, _MOVE_FORCE_ABSOLUTE); + int iEdgeRight = screen.createObject(&edgeRight); + screen.moveObject(iEdgeRight, {9,0}, _MOVE_FORCE_ABSOLUTE); - int iobj2 = handler.createObject((cObject*)&obj2); - handler.moveObject(iobj2, {3,3}, _MOVE_FORCE_ABSOLUTE); + int iAball= screen.createObject(&aball); + screen.moveObject(iAball, {2,2}, _MOVE_FORCE_ABSOLUTE); - sPos middle = render.getSize(); - middle.x /= 2; - middle.y /= 2; + render.render(); - while( loop ) - { - sInputEvent ie = input.poll(); + for(unsigned int cc = 0; cc < 9999; cc++) + { + + sInputEvent ie = input.poll(); if(ie.type != _EVENT_NULL) { - if(ie.type == _EVENT_KEY) - { - switch (ie.c) - { - case 'A'://up - handler.setCameraPosition({0,-1}, _MOVE_RELATIVE); - break; - case 'B'://down - handler.setCameraPosition({0,1}, _MOVE_RELATIVE); - break; - case 'C'://right - handler.setCameraPosition({1,0}, _MOVE_RELATIVE); - break; - case 'D'://left - handler.setCameraPosition({-1,0}, _MOVE_RELATIVE); - break; - }; - } - else if (ie.type == _EVENT_MOUSE) - { - if(ie.b == 0) - handler.clickEvent({ie.x, ie.y}, 0); - } - else if (ie.type == _EVENT_CHAR) - { - //handler.charEvent(ie.c); - switch(ie.c) - { - case 'w': - handler.moveObject(iobj2, {0,-1}, _MOVE_RELATIVE); - break; - case 's': - handler.moveObject(iobj2, {0,1}, _MOVE_RELATIVE); - break; - case 'a': - handler.moveObject(iobj2, {-1,0}, _MOVE_RELATIVE); - break; - case 'd': - handler.moveObject(iobj2, {1,0}, _MOVE_RELATIVE); - break; - }; - } - else if (ie.type == _EVENT_TERM) + if (ie.type == _EVENT_TERM) { return 0; } - } + } - handler.write(); - render.render(); - framecounter++; + if(!(++cc % 3)) + screen.moveObject(iAball, aball.getV(), _MOVE_RELATIVE); - if(loop) - usleep(10*1000); - } + screen.write(); + render.render(); + } - return 0; + return 0; } diff --git a/example/test_old.cpp b/example/test_old.cpp deleted file mode 100644 index 313b632..0000000 --- a/example/test_old.cpp +++ /dev/null @@ -1,165 +0,0 @@ -#include -#include - -#include "version.h" - -#include "cRender.h" -#include "cObject.h" -#include "cObjectHandler.h" -#include "cInput.h" -#include "cWiremesh.h" - -//#include "testobject.h" - -class testobject : cObject -{ -public: - testobject() - { - setSize(10,5); - cc = 0; - - drawRectangle('#', NULL, {0,0}, {9,4}, _COL_GREEN, _COL_DEFAULT); - } - - ~testobject() { destruct(); } - - virtual void onClick(sPos _pos, unsigned int _button) - { - cc++; - drawText(std::to_string(cc), {2,2}, _COL_RED); - - drawPoint('Q', _pos, true, _COL_YELLOW); - } - - virtual void onChar(unsigned char _c) { drawPoint(_c, {1,1},true, _COL_BLUE); } -private: - int cc; -}; - -int main(int argc, char* argv[]) -{ - cRender render(' ', _COL_DEFAULT, 30,30); - cObjectHandler handler(&render); - cObject ver(45,1); - cWiremesh obj; - testobject obj2; - - cInput input; - - unsigned int framecounter = 0; - bool loop = true; - - if(argc > 1) - { - loop = false; - } - - render.render(); - - ver.drawText(DATE, {20,0}, _COL_WHITE); - ver.drawText(VERSTRING, {0,0}, _COL_WHITE); - int iver = handler.createObject(&ver); - handler.moveObject(iver, {0,0}, _MOVE_ABSOLUTE); - - int x = 15; - int y = 15; - int z = 30; - - obj.addVector({-x,-y,z}, {2*x,0,0}, '+', _COL_RED); - obj.addVector({-x,-y,z}, {0,2*y,0}, '+', _COL_RED); - obj.addVector({-x,y,z}, {2*x,0,0}, '+', _COL_RED); - obj.addVector({x,-y,z}, {0,2*y,0}, '+', _COL_RED); - - obj.addVector({-x,-y,0}, {0,0,z}, ':', _COL_RED); - obj.addVector({x,-y,0}, {0,0,z}, ':', _COL_RED); - obj.addVector({-x,y,0}, {0,0,z}, ':', _COL_RED); - obj.addVector({x,y,0}, {0,0,z}, ':', _COL_RED); - - obj.addVector({-x,-y,0}, {2*x,0,0}, ',', _COL_RED); - obj.addVector({-x,-y,0}, {0,2*y,0}, ',', _COL_RED); - obj.addVector({-x,y,0}, {2*x,0,0}, ',', _COL_RED); - obj.addVector({x,-x,0}, {0,2*y,0}, ',', _COL_RED); - int imesh = handler.createWiremesh(&obj); - - int iobj2 = handler.createObject((cObject*)&obj2); - handler.moveObject(iobj2, {3,3}, _MOVE_ABSOLUTE); - - sPos middle = render.getSize(); - middle.x /= 2; - middle.y /= 2; - - handler.moveWiremesh(imesh,{middle.x,middle.y,0}, _MOVE_ABSOLUTE); - - while( loop ) - { - sInputEvent ie = input.poll(); - - if(ie.type != _EVENT_NULL) - { - if(ie.type == _EVENT_KEY) - { - switch (ie.c) - { - case 'A'://up - handler.setCameraPosition({0,-1}, _MOVE_RELATIVE); - break; - case 'B'://down - handler.setCameraPosition({0,1}, _MOVE_RELATIVE); - break; - case 'C'://right - handler.setCameraPosition({1,0}, _MOVE_RELATIVE); - break; - case 'D'://left - handler.setCameraPosition({-1,0}, _MOVE_RELATIVE); - break; - }; - } - else if (ie.type == _EVENT_MOUSE) - { - if(ie.b == 0) - handler.clickEvent({ie.x, ie.y}, 0); - } - else if (ie.type == _EVENT_CHAR) - { - //handler.charEvent(ie.c); - switch(ie.c) - { - case 'w': - handler.rotateWiremesh(imesh,{-10,0,0}); - break; - case 's': - handler.rotateWiremesh(imesh,{10,0,0}); - break; - case 'a': - handler.rotateWiremesh(imesh,{0,-10,0}); - break; - case 'd': - handler.rotateWiremesh(imesh,{0,10,0}); - break; - case 'q': - handler.rotateWiremesh(imesh,{0,0,-10}); - break; - case 'e': - handler.rotateWiremesh(imesh,{0,0,10}); - break; - }; - } - else if (ie.type == _EVENT_TERM) - { - return 0; - } - } - - handler.rotateWiremesh(imesh,{1,1,1}); - - handler.write(); - render.render(); - framecounter++; - - if(loop) - usleep(10*1000); - } - - return 0; -} -- cgit v1.2.3