diff --git a/README.md b/README.md index 6fce1d0..62130c3 100644 --- a/README.md +++ b/README.md @@ -11,17 +11,16 @@ metaprogramming\* level, and I think I have a pretty good idea of how to move forward. This project was started primarily as a self-study opportunity, and it's been a fun journey. - I have now settled on a language, an overall structure, and some libraries. from here, I do not forsee any further false starts and hope to have smooth(ish) sailing through to a working alpha! The game engine uses the [Irrlicht Engine](http://irrlicht.sourceforge.net/) for rendering 3d -graphics, [Cairo Graphics](https://www.cairographics.org/) for rendering -pictures, [NCurses](https://invisible-island.net/ncurses/) for rendering -in-game dialog, and [lua](http://www.lua.org/) for both extensions and a -command line\ +graphics, [Cairo Graphics](https://www.cairographics.org/) for 2d graphics, +[NCurses](https://invisible-island.net/ncurses/) for interactive menus, +`` for story dialog, and [lua](https://www.lua.org/) for scripting +and a command line.\ *additional dependancies will follow...* use of an [external debugger](https://www.gnu.org/software/gdb/) is @@ -95,6 +94,12 @@ and should be of type `signed`, `unsigned`, or `bool`. a loosly-packed struct should never use explicit-width fields. bitpacked structs should eventually be replaced with interger bitfields. +sincle-pourpose classes for storing global state, to me at least, seems a +wholly useless concept; this is an interface without an instance. I will +try to implement these as namespaces (either C++ namespaces or using $$ as +described elsewhere), and will attempt to refer to such namespaces as +"daemons" (cf. system daemon) if the interface contains functions. + since `this` is a reserved word in C++, and `self` is a reserved word in Objective-C, when using Object-Style-C, the object variable will be named `opaque` for `void *` pointers to C++ objects, or `object` for pointers @@ -113,8 +118,7 @@ variables with generic names follow the following conventions: - `n` and `m` are generic numbers, usually for-loop intergal counters - `tmp` is a temporary variable, usually holding an intermidiate value. - `T` is a type in a template -- `L` is a length (ℓ); it breaks from the usual capitalization rules - because of the `1`/`l`/`I` rule +- `L` is a lua engine - `data` is the main data member of an object a naming system similar to @@ -163,17 +167,26 @@ to edit a file: --- -*at various points in development, I have entertained using the following -libraries, but have since decided to go with a different design: +at various points in development, I have tried using the following +libraries, but have moved away for them: + - Guile -- Perl - Raylib -- GLX -- Angelscript +- Perl +- OpenGL/GLX +- Python +- tcl - s7 scheme +- TinyScheme - Chaiscript +- SQLite + earlier branches of the source tree may include broken code that uses -these libraries.* +these libraries. the reasons for changing are varied, and variously include +the APIs being too low level, not lowlevel enough, too big, inadequate +documentation, and license propagation conflict (specifically, using some +libraries listed here would have resulted in a malformed combination of +incompatible licenses). LICENSE ======= diff --git a/src/working/main.cc b/src/working/main.cc index 7f86a10..eecb2e4 100644 --- a/src/working/main.cc +++ b/src/working/main.cc @@ -4,7 +4,7 @@ * prealpha * **************/ -#define SNAPSHOT "NIGHT/20/07/2020" +#define SNAPSHOT "AFTERNOON/26/07/2020" /* this program currently requires a second terminal to be used; this is * done by passing the terminal's device file (which can be obtained with @@ -38,6 +38,7 @@ #include #include +#include #include #include @@ -53,6 +54,8 @@ std::atomic JITTER; std::atomic JITTERMAX; pthread_mutex_t JITTER_ADV_LOCK = PTHREAD_MUTEX_INITIALIZER; float JITTER_ADVERAGE; +typedef std::map NODES_t; +NODES_t NODES; #define THREAD__MAIN 0 #define THREAD__EVENT 1 @@ -97,8 +100,8 @@ namespace irrcontext { iwf::datatypes::camcoord CAMCOORD; irr::scene::ICameraSceneNode * CAMERA; pthread_mutex_t CAMLOCK = PTHREAD_MUTEX_INITIALIZER; -volatile std::atomic_bool STEALCURSOR; -volatile std::atomic_bool YINVERT; +std::atomic_bool STEALCURSOR; +std::atomic_bool YINVERT; /***EVENT LOOP***/ @@ -128,7 +131,9 @@ class MainEventReciever : public irr::IEventReceiver { this->mouseCenter = irrcontext::cursctrl->getPosition(); CHECKPOINT(THREAD__EVENT,__LINE__); } break; - case irr::EMIE_MOUSE_MOVED : if (STEALCURSOR) { + case irr::EMIE_MOUSE_MOVED : if (!STEALCURSOR) { + return false; + } else { CHECKPOINT(THREAD__EVENT,__LINE__); pthread_mutex_lock(&CAMLOCK); CAMCOORD.el += (event.MouseInput.Y - this->mouseCenter.Y) * (YINVERT ? -1 : 1) * (180 / M_PI) * (1 / 1000.0) * irrcontext::deltatime; @@ -228,7 +233,7 @@ MainEventReciever RECIEVER; void * iwf$$threads$$jitterbug$$loop (void * dummy) { double localbuffer = 0.0; - for (;;) { + for (;;usleep(POLLTIME)) { CHECKPOINT(THREAD__JITTERBUG,__LINE__); JITTER++; if (JITTER == -1) { @@ -242,8 +247,7 @@ void * iwf$$threads$$jitterbug$$loop (void * dummy) { JITTER_ADVERAGE = localbuffer; pthread_mutex_unlock(&JITTER_ADV_LOCK); } - CHECKPOINT(THREAD__JITTERBUG,__LINE__); - usleep(POLLTIME); + CHECKPOINT(THREAD__JITTERBUG,__LINE__); }} pthread_t iwf$$threads$$jitterbug; @@ -287,7 +291,7 @@ void * iwf$$threads$$curses$$function (void * input) { int tmp4; int tmp5; - for (;;) { + for (;;sleep(1)) { CHECKPOINT(THREAD__NCURSES,__LINE__); pthread_mutex_lock(&CAMLOCK); mvprintw(8,8,"camera azimuth : % 15.10f°",CAMCOORD.az * (180 / M_PI)); @@ -321,11 +325,30 @@ void * iwf$$threads$$curses$$function (void * input) { CHECKPOINT(THREAD__NCURSES,__LINE__); refresh(); CHECKPOINT(THREAD__NCURSES,__LINE__); - sleep(1); }}; pthread_t iwf$$threads$$curses; +/***CHANGE THE COLORS***/ + +// lua code created using toutorials at lua.org + +static int LFunc$$changecolor (lua_State * L) { + int tmp[5]; + for (ptrdiff_t i = 0;i < 5;i++) { + tmp[i] = lua_tointeger(L,i + 1); + }{ + NODES_t::iterator i = NODES.find(tmp[0]); + if (i != NODES.end()) { + irrcontext::meshmanipr->setVertexColors(i->second->getMesh(),RGBAColor(tmp[1],tmp[2],tmp[3],tmp[4])); + return 0; + }}} + +static const struct luaL_Reg LLib$$changecolor [] = { + {"changecolor",LFunc$$changecolor}, + {NULL,NULL} + }; + /***INTERNAL SCRIPTING LUA THREAD***/ pthread_mutex_t SCRIPTPASS = PTHREAD_MUTEX_INITIALIZER; @@ -334,6 +357,8 @@ std::string SCRIPTJOB; void * iwf$$threads$$lua__scripting$$function (void * dummy) { lua_State * L = luaL_newstate(); + luaL_newlib(L,LLib$$changecolor); + lua_setglobal(L,"lib"); for (;;usleep(POLLTIME)) { pthread_mutex_lock(&SCRIPTPASS); CHECKPOINT(THREAD__LUA_SCRIPTING,__LINE__); @@ -354,11 +379,18 @@ pthread_t iwf$$threads$$lua__scripting; void * iwf$$threads$$lua__commandline$$function (void * dummy) { lua_State * L = luaL_newstate(); + luaL_newlib(L,LLib$$changecolor); + lua_setglobal(L,"lib"); + printf("IWannaFly lua commandline\n]> "); for (std::string buffer;;) { CHECKPOINT(THREAD__LUA_COMMANDLINE,__LINE__); getline(std::cin,buffer); CHECKPOINT(THREAD__LUA_COMMANDLINE,__LINE__); luaL_dostring(L,buffer.c_str()); + CHECKPOINT(THREAD__LUA_COMMANDLINE,__LINE__); + buffer.clear(); + CHECKPOINT(THREAD__LUA_COMMANDLINE,__LINE__); + printf("Done\n]> "); } return NULL; } @@ -389,22 +421,20 @@ SYSINT initialize (char *argv[]) { CAMERA = irrcontext::smgr->addCameraSceneNode(NULL,irr::core::vector3df(0,0,0),irr::core::vector3df(1,1,1)); CAMERA->setUpVector(irr::core::vector3df(0,0,1)); - for (int x = 0;x < 2;x += 1) { - for (int y = 0;y < 2;y += 1) { - for (int z = 0;z < 2;z += 1) { - irr::scene::IMeshSceneNode * tmp = irrcontext::smgr->addCubeSceneNode( - 10.0, - NULL, - ((z << 2)|(y << 1)|x), - irr::core::vector3df( - (x ? 25 : -25), - (y ? 25 : -25), - (z ? 25 : -25))); - irrcontext::meshmanipr->setVertexColors(tmp->getMesh(),RGBColor( - ((0xFF * x) | 0x55), - ((0xFF * y) | 0x55), - ((0xFF * z) | 0x55))); - }}} + for (int x = -1;x < 2;x += 1) { + for (int y = -1;y < 2;y += 1) { + for (int z = -1;z < 2;z += 1) { + if (x || y || z) { + irr::scene::IMeshSceneNode * tmp = irrcontext::smgr->addCubeSceneNode( + 10.0, + NULL, + ((z * 9) + (y * 3) + x), + irr::core::vector3df( + (x * 25), + (y * 25), + (z * 25))); + NODES[(z * 9) + (y * 3) + x] = tmp; + }}}} irrcontext::smgr->addLightSceneNode(); }