aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexander Pickering <alex@cogarr.net>2018-10-31 12:39:50 -0400
committerAlexander Pickering <alex@cogarr.net>2018-10-31 12:39:50 -0400
commit6df9cb0de3e457788808b485b8b34bd8f0d6e42b (patch)
treede15337ea18f28f8643aedabfe2c34448a1b45fe /src
parent133e620665037ea2b66da65c67716b290711bfde (diff)
downloadbrokengine-6df9cb0de3e457788808b485b8b34bd8f0d6e42b.tar.gz
brokengine-6df9cb0de3e457788808b485b8b34bd8f0d6e42b.tar.bz2
brokengine-6df9cb0de3e457788808b485b8b34bd8f0d6e42b.zip
Added more documentation
Added documentation for luadoc for * io.* * phys.* * video.*
Diffstat (limited to 'src')
-rw-r--r--src/client/lua_api/io/ifilesystem.cpp29
-rw-r--r--src/client/lua_api/phys/bphysgeneric.cpp95
-rw-r--r--src/client/lua_api/video/iimage.cpp52
3 files changed, 155 insertions, 21 deletions
diff --git a/src/client/lua_api/io/ifilesystem.cpp b/src/client/lua_api/io/ifilesystem.cpp
index 9d12b22..252b61b 100644
--- a/src/client/lua_api/io/ifilesystem.cpp
+++ b/src/client/lua_api/io/ifilesystem.cpp
@@ -1,11 +1,19 @@
#include "ifilesystem.hpp"
+/***
+@module io
+*/
using namespace irr;
using namespace io;
extern IrrlichtDevice* device;
+/***
+A list of files in the current direcotry.
+@function list()
+@treturn array The files and directories in the current directory.
+*/
// io.list()
int listfilesin(lua_State *L){
IFileSystem *fs = device->getFileSystem();
@@ -26,6 +34,11 @@ int listfilesin(lua_State *L){
return 1;
}
+/***
+Changes the current directory of the program
+@function cd(dir)
+@tparam string dir The directory to change to
+*/
// io.cd("directory")
int changedirectory(lua_State *L){
IFileSystem *fs = device->getFileSystem();
@@ -35,6 +48,15 @@ int changedirectory(lua_State *L){
return 0;
}
+/***
+Logs some text with Irrlicht.
+`level` may be any of:
+io.LOG_DEBUG, io.LOG_INFO, io.LOG_WARN, io.LOG_ERROR, io.LOG_NONE
+@function log(text,level[,hint])
+@tparam string text The text to log
+@tparam log_level_enum level The log level
+@tparam string hint An optional hint to supply with the log
+*/
// io.log("text",level)
// io.log("text",level[,"hint"])
int logmessage(lua_State *L){
@@ -57,6 +79,13 @@ int logmessage(lua_State *L){
return 0;
}
+/***
+Sets what output gets logged, and what gets ignored.
+level may be any of:
+io.LOG_DEBUG, io.LOG_INFO, io.LOG_WARN, io.LOG_ERROR, io.LOG_NONE
+@function set_log_level(level)
+@tparam number level the minimul level of log to capture
+*/
//io.set_log_level(level)
int setloglevel(lua_State *L){
ILogger *log = device->getLogger();
diff --git a/src/client/lua_api/phys/bphysgeneric.cpp b/src/client/lua_api/phys/bphysgeneric.cpp
index e4e8ab0..91b4c21 100644
--- a/src/client/lua_api/phys/bphysgeneric.cpp
+++ b/src/client/lua_api/phys/bphysgeneric.cpp
@@ -5,21 +5,25 @@ extern "C" {
#include <lualib.h>
}
#include <btBulletDynamicsCommon.h>
-//#include <irrlicht.h>
#include <shared/lua_api/common.hpp>
-//extern IrrlichtDevice* device;
+/***
+@module phys
+*/
-//extern btDiscreteDynamicsWorld* World;
-//extern std::list<btRigidBody*> Objects;
-/*Physics things have the form of:
+/*Physics things from lua have the form of:
{
rigidbody = btRigidBody,
node = ISceneNode,
}
*/
+/***
+Sets the direction of gravity on this object.
+@function rigidbody:setgravity({x,y,z})
+@tparam vector3d direction The direction to make gravity point
+*/
//rigidbody:setgravity({x,y,z})
int setgravity(lua_State *L){
double x,y,z;
@@ -36,7 +40,29 @@ int setgravity(lua_State *L){
return 0;
}
-//apply force at a reletive offset
+/***
+Gets the direction of gravity on this object.
+@function rigidbody:getgravity()
+@treturn vector3d The direction of gravity on this object.
+*/
+//rigidbody:getgravity()
+int getgravity(lua_State *L){
+ lua_getfield(L,-1,"rigidbody");//{rigidbody},ud_rigidbody
+ btRigidBody *r = (btRigidBody*)lua_touserdata(L,-1);
+ lua_pop(L,2);//
+
+ btVector3 v = r->getGravity();
+ pushvector3d(L,v.x(),v.y(),v.z());
+
+ return 0;
+}
+
+/***
+Apply force at a reletive offset.
+@function rigidbody:applyforce(direction, offset = {0,0,0})
+@tparam vector3d direction The direction of the force to apply
+@tparam vector3d offset The offset from the center of gravity to apply the force
+*/
//rigidbody:applyforce({x,y,z}[,{rx,ry,rz}])
int applyforce(lua_State *L){
double rx,ry,rz;
@@ -62,6 +88,11 @@ int applyforce(lua_State *L){
return 0;
}
+/***
+Gets the damping applied to this rigidbody
+@function rigidbody:getldamping()
+@treturn number damping The ammount of damping applied to the object's momentum
+*/
//rigidbody:getldamping()
int getlineardamping(lua_State *L){
lua_getfield(L,-1,"rigidbody");
@@ -74,6 +105,28 @@ int getlineardamping(lua_State *L){
return 1;
}
+/***
+Gets the angular damping applied to this rigidbody
+@function rigidbody:getadamping()
+@treturn number damping The ammount of damping applied to angular momentum
+*/
+//rigidbody:getadamping()
+int getangulardamping(lua_State *L){
+ lua_getfield(L,-1,"rigidbody");
+ btRigidBody *r = (btRigidBody*)lua_touserdata(L,-1);
+ lua_pop(L,2);
+
+ double damp = r->getAngularDamping();
+ lua_pushnumber(L,damp);
+
+ return 1;
+}
+
+/***
+Gets the velocity of this object
+@function rigidbody:getvelocity()
+@treturn vector3 The velocity in each direction
+*/
//rigidbody:getvelocity()
int getvelocity(lua_State *L){
btVector3 vel;
@@ -86,6 +139,11 @@ int getvelocity(lua_State *L){
return 1;
}
+/***
+Sets the velocity of this object
+@function rigidbody:setvelocity()
+@tparam vector3d direction The ammount on each axis to set the velocity of this object.
+*/
//rigidbody:setvelocity({x,y,z})
int setvelocity(lua_State *L){
double x,y,z;
@@ -101,18 +159,13 @@ int setvelocity(lua_State *L){
return 0;
}
-//rigidbody:getadamping()
-int getangulardamping(lua_State *L){
- lua_getfield(L,-1,"rigidbody");
- btRigidBody *r = (btRigidBody*)lua_touserdata(L,-1);
- lua_pop(L,2);
-
- double damp = r->getAngularDamping();
- lua_pushnumber(L,damp);
-
- return 1;
-}
-
+/***
+Activates this object.
+If this object was sleeping, it will move again. If you are using
+applyforce or setvelocity, you will need to activate() the rigidbody for it
+to move.
+@function rigidbody:activate()
+*/
//rigidbody:activate()
int activate(lua_State *L){
lua_getfield(L,-1,"rigidbody");
@@ -124,6 +177,12 @@ int activate(lua_State *L){
return 0;
}
+/***
+Sets the damping of this object.
+@function rigidbody:setdamping(damping,angular_damping)
+@tparam number damping The ammount of damping the object should put on it's movement.
+@tparam number angular_damping The ammount of damping the object should put on it's angular momentum
+*/
//rigidbody:setdamping(lineardamping, angulardamping)
int setdamping(lua_State *L){
double adamp,ldamp;
diff --git a/src/client/lua_api/video/iimage.cpp b/src/client/lua_api/video/iimage.cpp
index 86d984e..6fbf6c5 100644
--- a/src/client/lua_api/video/iimage.cpp
+++ b/src/client/lua_api/video/iimage.cpp
@@ -4,12 +4,24 @@
#include <shared/lua_api/common.hpp>
+/***
+@module video
+*/
+
using namespace irr;
using namespace video;
extern IrrlichtDevice* device;
extern IVideoDriver* driver;
+/***
+Creates a new irrlicht image.
+A newly created image will be fully white by default.
+@function newiimage(format, size)
+@tparam enum_color_format format The format for the image
+@tparam vec2d size The size of the image
+@treturn iimage The image
+*/
//newiimage(ECOLOR_FORMAT,{width,height}) -> {image}
int newiimage(lua_State* L){
//printf("Attempting to create new iimage\n");
@@ -28,23 +40,43 @@ int newiimage(lua_State* L){
return 1;
}
+/***
+Creates a new irrlicht image.
+Creates a new irrlicht image from a file. The format and width/height will be
+taken from the image file.
+@function newiimagefromfile(path)
+@tparam string path The file path of the image file
+@treturn iimage The loaded image
+*/
//newiimagefromfile("/path/to/file") -> {image}
int newiimagefromfile(lua_State* L){
- //printf("Creating new iimage from file");
+ printf("Creating new iimage from file");
const char* strpath = lua_tostring(L,-1);
lua_pop(L,1);
int numloaders = driver->getImageLoaderCount();
bool hasloaded = false;
IImage* img = NULL;
+ printf("About to create and open file\n");
+ io::IReadFile *f = device->getFileSystem()->createAndOpenFile(strpath);
+ if(!f){
+ lua_pushstring(L,"Failed to open file: ");
+ lua_pushstring(L,strpath);
+ lua_concat(L,2);
+ lua_error(L);
+ }
+ printf("Opened file\n");
for(int j = 0; j < numloaders; j++){
IImageLoader* loader = driver->getImageLoader(j);
- io::IReadFile* f = device->getFileSystem()->createAndOpenFile(strpath);
if(!loader->isALoadableFileExtension(strpath))
continue;
if(!loader->isALoadableFileFormat(f))
continue;
+ f->seek(0,false);
hasloaded = true;
+ printf("Found a loader, about to load\n");
img = loader->loadImage(f);
+ printf("Done loading\n");
+ f->drop();
}
if(!hasloaded){
lua_pushstring(L,"Failed to load file, no image loader for this type.");
@@ -54,15 +86,23 @@ int newiimagefromfile(lua_State* L){
lua_pushstring(L,"Failed to load image");
lua_error(L);
}
+ printf("Successfully loaded\n");
lua_newtable(L);
lua_pushlightuserdata(L,img);
lua_setfield(L,-2,"image");
luaL_getmetatable(L,"iimage");
lua_setmetatable(L,-2);
- //printf("IImage made, returning!");
+ printf("IImage made, returning!");
return 1;
}
+/***
+Sets the color of an image at a particular pixel.
+@function iimage:setpixel(position,color,shouldblend)
+@tparam vec2i position The position of the pixel to change colors
+@tparam color color The color to change the pixel to
+@tparam boolean shouldblend Should this pixel blend into it's neighbors?
+*/
//setpixel({self},{x,y},{r,g,b,a},bool_shouldblend)
int setiimagepixel(lua_State* L){
bool sb = lua_toboolean(L,-1);//{ud_iimage},{x,y},{r,g,b,a},bool_shouldblend
@@ -78,6 +118,12 @@ int setiimagepixel(lua_State* L){
return 0;
}
+/***
+Returns the color at a position in the image.
+@function iimage:getpixel(position)
+@tparam vec2i position The position of the pixel to return
+@treturn color The color of the image at the position
+*/
//getpixel({self},{x,y})
int getiimagepixel(lua_State* L){
long x,y;