Mercurial > hg > Members > kono > Cerium
changeset 511:997490a061ee
fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 12 Oct 2009 17:46:20 +0900 |
parents | 97e1b0346597 |
children | 01b64f21405e |
files | Renderer/Engine/Application.h Renderer/Engine/MainLoop.h Renderer/Engine/viewer.cc Renderer/Engine/viewer.h Renderer/Test/Makefile Renderer/Test/Makefile.def Renderer/Test/ball_bound.cc Renderer/Test/ball_bound.h bin/create_sglist.pl |
diffstat | 9 files changed, 173 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/Renderer/Engine/Application.h Mon Oct 12 15:48:40 2009 +0900 +++ b/Renderer/Engine/Application.h Mon Oct 12 17:46:20 2009 +0900 @@ -2,18 +2,20 @@ #define INCLUDED_APPLICATION #include "SceneGraph.h" - -class Viewer; +#include "MainLoop.h" +#include "viewer.h" typedef void (*Move_func)(SceneGraph* node, int screen_w, int screen_h); typedef void (*Coll_func)(SceneGraph* node, int screen_w, int screen_h, SceneGraphPtr tree); +class Viewer; + class Application { public: Application(); virtual ~Application(); - virtual void init(Viewer *viewer, int w, int h) = 0; + virtual MainLoopPtr init(Viewer *viewer, int w, int h) = 0; };
--- a/Renderer/Engine/MainLoop.h Mon Oct 12 15:48:40 2009 +0900 +++ b/Renderer/Engine/MainLoop.h Mon Oct 12 17:46:20 2009 +0900 @@ -1,8 +1,13 @@ - +#ifndef MAINLOOP +#define MAINLOOP class MainLoop { +public: + virtual ~MainLoop(); + virtual void mainLoop() = 0; }; typedef MainLoop *MainLoopPtr; +#endif MAINLOOP
--- a/Renderer/Engine/viewer.cc Mon Oct 12 15:48:40 2009 +0900 +++ b/Renderer/Engine/viewer.cc Mon Oct 12 17:46:20 2009 +0900 @@ -10,6 +10,7 @@ #include "TaskManager.h" #include <wchar.h> #include "Pad.h" +#include "Application.h" static void post2runLoop(void *viewer); static void post2runDraw(void *viewer); @@ -90,6 +91,23 @@ SDL_GL_SwapBuffers(); } +void +Viewer::createFromXMLfile(const char *file) +{ + sgroot->createFromXMLfile(manager, file); +} + +SceneGraph * +Viewer::createSceneGraph(int id) +{ + return sgroot->createSceneGraph(id); +} + +void +Viewer::setSceneData(SceneGraph *g) +{ + sgroot->setSceneData(g); +} void Viewer::run_init(TaskManager *manager, Application *app) @@ -102,9 +120,9 @@ sgroot = new SceneGraphRoot(this->width, this->height); - app->init(this, this->width, this->height); + MainLoop *mainloop = app->init(this, this->width, this->height); - mainLoop(); + mainloop->mainLoop(); }
--- a/Renderer/Engine/viewer.h Mon Oct 12 15:48:40 2009 +0900 +++ b/Renderer/Engine/viewer.h Mon Oct 12 17:46:20 2009 +0900 @@ -9,8 +9,9 @@ #include "MainLoop.h" #include "Application.h" +class Application; -class Viewer : MainLoop { +class Viewer : public MainLoop { public: @@ -61,6 +62,11 @@ void getKey(); void get_send_controll(); + + void createFromXMLfile(const char *file); + SceneGraph *createSceneGraph(int id); + void setSceneData(SceneGraph *g); + private: HTaskPtr initLoop(); void mainLoop();
--- a/Renderer/Test/Makefile Mon Oct 12 15:48:40 2009 +0900 +++ b/Renderer/Test/Makefile Mon Oct 12 17:46:20 2009 +0900 @@ -19,17 +19,17 @@ all: ball_bound -ball_bound : ball_bound.o +ball_bound : ball_bound.o ball_xml.o $(CC) -o $@ $< $(LIBS) +ball_bound.cc : ball_xml.h + # SGList.o: create_sg_list # $(CC) $(CFLAGS) $(INCLUDE) -c SGList.cc -o $@ -create_sg_list: - @if [ ! -f SGList.h ]; then \ - cd tools/;\ - ./create_sglist.pl ../xml_file/*.xml;\ - fi +# generate ball_xml.h, ball_xml.cc +ball_xml.cc: xml_file/Ball.xml + perl $(TOOL)/create_sglist.pl -o $@ $< run: $(TARGET)
--- a/Renderer/Test/Makefile.def Mon Oct 12 15:48:40 2009 +0900 +++ b/Renderer/Test/Makefile.def Mon Oct 12 17:46:20 2009 +0900 @@ -7,3 +7,4 @@ INCLUDE = -I$(CERIUM)/include/TaskManager -I. -I$(CERIUM)/include/Cerium LIBS = -L$(CERIUM)/TaskManager -L$(CERIUM)/Renderer/Engine +TOOL = $(CERIUM)/bin
--- a/Renderer/Test/ball_bound.cc Mon Oct 12 15:48:40 2009 +0900 +++ b/Renderer/Test/ball_bound.cc Mon Oct 12 17:46:20 2009 +0900 @@ -1,7 +1,9 @@ #include <math.h> #include <stdlib.h> #include "SceneGraphRoot.h" -#include "SGList.h" +#include "MainLoop.h" +#include "ball_xml.h" +#include "ball_bound.h" // prototype static void ball_move(SceneGraphPtr node, int screen_w, int screen_h);
--- a/Renderer/Test/ball_bound.h Mon Oct 12 15:48:40 2009 +0900 +++ b/Renderer/Test/ball_bound.h Mon Oct 12 17:46:20 2009 +0900 @@ -8,4 +8,4 @@ MainLoopPtr init(Viewer *viewer, int screen_w, int screen_h); -} +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/create_sglist.pl Mon Oct 12 17:46:20 2009 +0900 @@ -0,0 +1,124 @@ +#!/usr/bin/perl + +# TODO +# 同じ名前の SceneGraph が来た時の処理 +# まあ Blender の時点でそうならないように書くべきなんだが + +#################################### +# +# Create SceneGraph List +# +# SceneGraph が記載された xml ファイルを読み込み、 +# 名前に対応するID列が記述された SGList.h を生成する。 +# また、名前から ID を取得するために sglist_table を生成しておく。 +# sglist_table は SGList.cpp に記述する +# +# xml に ID を入れれば table は要らないんだが、 +# xml の読み込む順番、その時々に応じて使うものと使わないもので +# ID にズレが出てくるので、Blender からの出力時点では決定できない。 +# このスクリプトで xml に上書きするって手もあるけど、微妙じゃない? +# +# xml ファイルは複数指定可能。 +# 実際に使うやつ全て指定する感じでおk +# +# (例) +# +# % cat ../xml_file/universe.xml +# +# <?xml version="1.0"?> +# <OBJECT-3D> +# <surface name="Earth" size="5952" prim="Triangle" parent="NULL"> +# (省略) +# </surface> +# +# <surface name="Moon" size="3312" prim="Triangle" parent="Earth"> +# (省略) +# </surface> +# <OBJECT-3D> +# +# % ./create_sglist.pl ../xml_file/universe.xml +# % cat SGList.h +# +# /* ../xml_file/universe.xml */ +# #define Earth 0 +# #define Moon 1 +# +# /* Number of Scene */ +# #define SGLIST_LENGTH 2 +# +# /* Scene Table */ +# const char *sglist_table[SGLIST_LENGTH] = { +# "Earth", "Moon" +# }; +# +#################################### + +use strict; +# +# to install this, +# cpan -i XML::LibXML::SAX::Generator +# +use XML::LibXML; + +my $file = "SGList"; +my $id = 0; +my @table; + +################### +# cretae SGList.h # +################### + +my $done = 0; + +if ($ARGV[0]=~/-o/) { + shift; + $_ = shift; + s/\.(h|cc)$//; + $file = $_; +} + +open(FH, ">$file.h"); + +print FH "#ifndef INCLUDED_SGLIST\n"; +print FH "#define INCLUDED_SGLIST\n\n"; + +foreach (@ARGV) { + my $parser = XML::LibXML->new(); + my $doc = $parser->parse_file($_); + my @nodes = $doc->findnodes('//surface'); + + print FH "/* $_ */\n"; + + foreach my $surface (@nodes) { + my $name = $surface->findvalue('@name'); + + $table[$id] = $name; + + print FH "#define $name\t $id\n"; + $id++; + } + + print FH "\n"; +} + +print FH "/* Number of Scene */\n"; +print FH "#define SGLIST_LENGTH $id\n\n"; + +print FH "/* Scene Table */\n"; +print FH "extern const char *sglist_table[SGLIST_LENGTH];\n\n"; +print FH "#endif\n"; + +close(FH); + +##################### +# cretae SGList.cpp # +##################### +open(FH, ">$file.cc") or die "Error: Can't open file : $file.cc\n"; + +print FH "#include \"$file.h\"\n\n"; +print FH "const char *sglist_table[SGLIST_LENGTH] = {\n"; +print FH " \""; +print FH join("\", \"", @table); +print FH "\"\n};\n"; + +close(FH);