Skip to content

Commit

Permalink
Added more classes; added system to generate all.d
Browse files Browse the repository at this point in the history
  • Loading branch information
blm768 committed Jul 26, 2013
1 parent a52cb6a commit 6a4ca64
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 14 deletions.
32 changes: 19 additions & 13 deletions Makefile
Expand Up @@ -4,22 +4,28 @@ DFLAGS += -g
CFLAGS += -I /usr/include/bullet
CFLAGS += -g

D_SRC := $(shell find bullet -iname '*.d')
D_NONGENERATED := $(filter-out bullet/bindings/sizes.d, $(D_SRC))
D_BINDINGS := $(filter-out bullet/bindings/%, $(D_NONGENERATED))
GLUE_SRC := $(D_BINDINGS:%.d=glue/%.cpp)
GLUE_OBJS := $(GLUE_SRC:%.cpp=%.o)

test: test.o $(GLUE_OBJS)
d_src := $(shell find bullet -iname '*.d')
d_dirs := $(shell find bullet -type d)
d_all_d := $(d_dirs:%=%/all.d)
d_gen := $(d_all_d) bullet/bindings/sizes.d
d_nongen := $(filter-out $(d_gen), $(d_src))
d_bindings := $(filter-out bullet/bindings/%, $(d_nongen))
glue_src := $(d_bindings:%.d=glue/%.cpp)
glue_objs := $(glue_src:%.cpp=%.o)

$(d_all_d) : $(d_nongen)
rdmd gen_import.d

test: test.o $(glue_objs)
dmd $(DFLAGS) $^ $(D_LDFLAGS) -of$@

test.o: test.d $(D_SRC) bullet/bindings/sizes.d
test.o: test.d $(d_src) bullet/bindings/sizes.d
dmd $^ -c -of$@

libbullet-d.a: $(GLUE_OBJS)
libbullet-d.a: $(glue_objs)
ar rcs $@ $^

$(GLUE_OBJS): %.o: %.cpp
$(glue_objs): %.o: %.cpp
g++ $(CFLAGS) $< $(LDFLAGS) -c -o $@

bullet/bindings/sizes.d: gen_c
Expand All @@ -28,14 +34,14 @@ bullet/bindings/sizes.d: gen_c
gen_c: gen_c.cpp
g++ $(CFLAGS) $< $(LDFLAGS) -o $@

$(GLUE_SRC) gen_c.cpp: gen_b.d
$(glue_src) gen_c.cpp: gen_b.d
rdmd -version=genBindings gen_b.d

gen_b.d: $(D_NONGENERATED) gen_a.d
gen_b.d: $(d_nongen) gen_a.d
rdmd -version=genBindings gen_a.d

.PHONY: clean

clean:
rm -rf glue/ gen_b.d gen_c.cpp gen_c bullet/bindings/sizes.d libbullet-d.a test.o test
rm -rf glue/ gen_b.d gen_c.cpp gen_c $(d_gen) libbullet-d.a test.o test

16 changes: 16 additions & 0 deletions bullet/collision/collisionShapes/collisionShape.d
@@ -0,0 +1,16 @@
module bullet.collision.collisionShapes.collisionShape;

public import bullet.bindings.bindings;

public import bullet.linearMath.btVector3;

version(genBindings) void writeBindings(File f) {
f.writeIncludes("#include <BulletCollision/CollisionShapes/btCollisionShape.h>");

btCollisionShape.writeBindings(f);
}

struct btCollisionShape {
mixin classBinding!"btCollisionShape";
}

18 changes: 18 additions & 0 deletions bullet/collision/collisionShapes/staticPlaneShape.d
@@ -0,0 +1,18 @@
module bullet.collision.collisionShapes.staticPlaneShape;

public import bullet.bindings.bindings;

import bullet.collision.collisionShapes.collisionShape;

version(genBindings) void writeBindings(File f) {
f.writeIncludes("#include <BulletCollision/CollisionShapes/btStaticPlaneShape.h>");

btStaticPlaneShape.writeBindings(f);
}

struct btStaticPlaneShape {
mixin subclassBinding!("btStaticPlaneShape", btCollisionShape);

mixin constructor!(btVector3, btScalar);
}

6 changes: 5 additions & 1 deletion gen_a.d
Expand Up @@ -16,7 +16,11 @@ import std.file;
import std.stdio;
`);
foreach(filename; dirEntries("bullet", SpanMode.depth)) {
if(isFile(filename) && filename[$ - 2 .. $] == ".d") {
if(isFile(filename)) {
auto basename = filename.baseName;
if(basename == "all.d" || basename[0] == '.') {
continue;
}
string dir = dirName(filename);
if(dir == buildPath("bullet", "bindings")) {
continue;
Expand Down
39 changes: 39 additions & 0 deletions gen_import.d
@@ -0,0 +1,39 @@
module main;

import std.algorithm;
import std.file;
import std.path;
import std.stdio;
import std.string;

void writeImport(string dir) {
auto f = File(dir.buildPath("all.d"), "w");
//map is needed to remove a layer of const
//To do: file bug?
auto pkg = dir.pathSplitter.map!((s) => s[]).join(".");
f.write("module " ~ pkg ~ ".all;\n\n");
foreach(entry; dirEntries(dir, SpanMode.shallow)) {
auto name = entry.baseName.stripExtension;
if(name == "all" || name[0] == '.') {
continue;
}
if(entry.isDir) {
f.write("public import " ~ pkg ~ "." ~ name ~ ".all;\n");
} else {
f.write("public import " ~ pkg ~ "." ~ name ~ ";\n");
}
}
}

int main(string[] args) {
writeImport("bullet");
foreach(dir; dirEntries("bullet", SpanMode.breadth)) {
if(!dir.isDir) {
continue;
}
writeImport(dir);
}

return 0;
}

5 changes: 5 additions & 0 deletions test.d
Expand Up @@ -7,6 +7,7 @@ import bullet.collision.dispatch.defaultCollisionConfiguration;
import bullet.collision.dispatch.collisionDispatcher;
import bullet.dynamics.constraintSolver.sequentialImpulseConstraintSolver;
import bullet.dynamics.dynamics.discreteDynamicsWorld;
import bullet.collision.collisionShapes.staticPlaneShape;

int main(string[] args) {
auto bp = btDbvtBroadphase.cppNew();
Expand All @@ -18,6 +19,10 @@ int main(string[] args) {
auto gravity = btVector3(0.0, -1.0, 0.0);
dw.setGravity(gravity);

//auto floor = btStaticPlaneShape.cppNew(btVector3(0, 0, 0), 1);


//floor.cppDelete();

dw.cppDelete();
cs.cppDelete();
Expand Down

0 comments on commit 6a4ca64

Please sign in to comment.