diff -uN -x TAGS -x *.map* -x *.o -x *~ ./Makefile /home/aloril/src/g/iso_edit/Makefile --- ./Makefile Fri Dec 18 05:47:10 1998 +++ /home/aloril/src/g/iso_edit/Makefile Tue Dec 22 09:40:53 1998 @@ -20,19 +20,20 @@ # the Altima Web Site at http://www.altima.org. # -CXXFLAGS=-Wall -pg -g -I$(QTDIR)/include -I. -I/home/yoho2/lavoie/include -LDFLAGS= -L/home/yoho2/lavoie/lib -L/usr/openwin/lib -L$(QTDIR)/lib +QWSPRITEDIR=/usr/local/src +CXXFLAGS=-Wall -pg -g -I$(QTDIR)/include -I. -I$(QWSPRITEDIR) -I/usr/include/python1.5 +LDFLAGS= -L$(QWSPRITEDIR)/QwSprite -L/usr/openwin/lib -L$(QTDIR)/lib -L/usr/X11R6/lib -Xlinker -export-dynamic -LDLIBS= -lpng -lQwSpriteField -lqimgio -lqt -lX11 -lXt +LDLIBS=/usr/lib/python1.5/config/libpython1.5.a -lz -ljpeg -lpng -lQwSpriteField -lqimgio -lqt -lX11 -lXt -ldl all: main testpng testpng: testpng.o moc_testpng.o $(CXX) -pg -o testpng testpng.o moc_testpng.o $(LDFLAGS) $(LDLIBS) -MAIN_OBJ = main.o moc_main.o GfxSetup.o moc_GfxSetup.o MapSetup.o moc_MapSetup.o sprite.o EditMap.o moc_EditMap.o tile.o +MAIN_OBJ = main.o moc_main.o GfxSetup.o moc_GfxSetup.o MapSetup.o moc_MapSetup.o sprite.o EditMap.o moc_EditMap.o tile.o observe.o main: $(MAIN_OBJ) tile.hh $(CXX) -pg -o main $(MAIN_OBJ) $(LDFLAGS) $(LDLIBS) @@ -42,4 +43,3 @@ %.o: %.cc %.hh $(COMPILE.cc) $< $(OUTPUT_OPTION) - diff -uN -x TAGS -x *.map* -x *.o -x *~ ./main.cc /home/aloril/src/g/iso_edit/main.cc --- ./main.cc Fri Dec 18 05:47:40 1998 +++ /home/aloril/src/g/iso_edit/main.cc Tue Dec 22 08:46:10 1998 @@ -42,6 +42,7 @@ #include "main.hh" #include "sprite.hh" +#include "observe.hh" const int HEIGHT = 400 ; const int WIDTH = 640 ; @@ -143,6 +144,22 @@ frames++; } +void IsoMapField::addTileGfx(int i, int j, TileGfx *tg){ + if(i<0 || j<0 || i>=map->nX() || j>=map->nY()) return ; + map->at(i,j).pushTileGfx(tg) ; + emit newTile(&(map->at(i,j))); + field.update(); + refresh(); +} + +void IsoMapField::deleteTileGfx(int i, int j, TileGfx *tg){ + if(i<0 || j<0 || i>=map->nX() || j>=map->nY()) return ; + map->at(i,j).deleteTileGfx(tg) ; + emit newTile(&(map->at(i,j))); + field.update(); + refresh(); +} + void IsoMapField::mouseEvent(int x, int y, int button, int type, int state){ static int old_i = -1; static int old_j = -1; @@ -347,6 +364,10 @@ tile->insertItem("Merge tile list", this, SLOT(mergeTileList()), CTRL+Key_M); tile->insertItem("Save tile list", this, SLOT(saveTileList()), CTRL+Key_S) ; menu->insertItem("&Tile",tile) ; + + QPopupMenu* obs = new QPopupMenu ; + obs->insertItem("Run",this , SLOT(runWorld()), CTRL+Key_R) ; + menu->insertItem("&Observe",obs) ; bool scrollbars=FALSE; @@ -427,6 +448,10 @@ if(!fileName.isNull()){ writeList(*listTG,fileName) ; } +} + +void IsoEditor::runWorld(){ + ::runWorld(map_field); } main(int argc, char** argv) diff -uN -x TAGS -x *.map* -x *.o -x *~ ./main.hh /home/aloril/src/g/iso_edit/main.hh --- ./main.hh Fri Dec 18 05:47:42 1998 +++ /home/aloril/src/g/iso_edit/main.hh Wed Dec 23 10:19:58 1998 @@ -50,6 +50,10 @@ public: IsoMapField(bool scrbars, QWidget* parent=0); + void addTileGfx(int i, int j, TileGfx *tg); + void deleteTileGfx(int i, int j, TileGfx *tg); + int getXSize() {return map->nX();} + int getYSize() {return map->nY();} signals: void status(const char*); @@ -101,6 +105,7 @@ void newTile() ; void mergeTileList(); void saveTileList(); + void runWorld(); protected: void resizeEvent(QResizeEvent* event); diff -uN -x TAGS -x *.map* -x *.o -x *~ ./observe.cc /home/aloril/src/g/iso_edit/observe.cc --- ./observe.cc Thu Jan 1 02:00:00 1970 +++ /home/aloril/src/g/iso_edit/observe.cc Wed Dec 23 10:44:17 1998 @@ -0,0 +1,119 @@ +#include +#include +#include +#include "Python.h" +#include "main.hh" +#include "sprite.hh" +#include "tile.hh" +#include "observe.hh" + +struct TileInfo +{ + char *name; + TileGfx *tg; + void addTileInfo(char *name, char *picture); +}; + +void TileInfo::addTileInfo(char *name, char *picture) +{ + this->name=strdup(name); + this->tg=new TileGfx; + this->tg->pixmaps=loadSprite(picture); +} + +IsoMapField *last_map; +TileInfo *ti; + +int scale(double n, double min, double max, double size) +{ + return (int)(size/(max-min)*(n-min)); +} + + +enum {ADD,DEL}; +void modifyMap(int op, char *name0, double x, double y, double z) +{ + int ix,iy; + char *name=strdup(name0); + TileInfo *i; + int j; + for(j=0;name[j];j++) if(isdigit(name[j])) name[j]=0; + //cout<<"Try:"<name;i++) { + if(strcmp(name,i->name)==0) { + + ix=scale(x,-200.0,200.0, last_map->getXSize()); + iy=scale(y,-200.0,200.0, last_map->getYSize()); + //cout<name<<":"<addTileGfx(ix,iy,i->tg); break; + case DEL: last_map->deleteTileGfx(ix,iy,i->tg); break; + } + } + } +} + +static PyObject *IsoObserverAdd(PyObject *self, PyObject *args) +{ + char *name; + double x,y,z; + + if (!PyArg_ParseTuple(args, "sddd", &name,&x,&y,&z)) return NULL; + modifyMap(ADD,name,x,y,z); + return Py_None; +} + +static PyObject *IsoObserverDel(PyObject *self, PyObject *args) +{ + char *name; + double x,y,z; + + if (!PyArg_ParseTuple(args, "sddd", &name,&x,&y,&z)) return NULL; + modifyMap(DEL,name,x,y,z); + return Py_None; +} + + +static PyMethodDef IsoObserverMethods[] = { + {"map_add", IsoObserverAdd, METH_VARARGS}, + {"map_del", IsoObserverDel, METH_VARARGS}, + {NULL, NULL} /* Sentinel */ +}; + +void initIsoObserver() +{ + (void) Py_InitModule("IsoObserver", IsoObserverMethods); +} + +void runWorld(IsoMapField *map){ + static int initDone=FALSE; +// static tmp=0; + last_map=map; + if(!initDone) { + ti=new TileInfo[6]; + // House + ti[0].addTileInfo("house","gfx/objects/bedA.png"); + ti[1].addTileInfo("smithy","gfx/client/mouse_pointer.png"); + ti[2].addTileInfo("farmer","gfx/objects/penguinA.png"); + ti[3].addTileInfo("smith","gfx/asian/warrior.0.png"); + ti[4].addTileInfo("fire","gfx/cursor2.png"); + ti[5].name=NULL; + + /* Initialize the Python interpreter. */ + Py_Initialize(); + // initialize Cyphesis + PyRun_SimpleString("from observe import observe\n"); + initIsoObserver(); + PyRun_SimpleString("from IsoObserver import *\n"); + //Use remote CORBA + //PyRun_SimpleString("obs=observe(1,map_add=map_add,map_del=map_del)\n"); + //Use local CORBA + PyRun_SimpleString("obs=observe(0,map_add=map_add,map_del=map_del)\n"); + initDone=TRUE; + } + //Display events as text + //PyRun_SimpleString("obs.text(1)\n"); + //Display text graphics + PyRun_SimpleString("obs.dsp(1)\n"); +} diff -uN -x TAGS -x *.map* -x *.o -x *~ ./observe.hh /home/aloril/src/g/iso_edit/observe.hh --- ./observe.hh Thu Jan 1 02:00:00 1970 +++ /home/aloril/src/g/iso_edit/observe.hh Tue Dec 22 06:54:19 1998 @@ -0,0 +1 @@ +void runWorld(IsoMapField *map); diff -uN -x TAGS -x *.map* -x *.o -x *~ ./tile.cc /home/aloril/src/g/iso_edit/tile.cc --- ./tile.cc Fri Dec 18 05:48:30 1998 +++ /home/aloril/src/g/iso_edit/tile.cc Tue Dec 22 07:15:31 1998 @@ -154,6 +154,21 @@ gfxSprite.push_back(ts) ; } +void Tile::deleteTileGfx(TileGfx* tg) +{ + for(list::iterator it = gfxSprite.begin(); it != gfxSprite.end() ; ){ + if(tg == (*it)->gfx){ + list::iterator nit = it ; + ++nit; + gfxSprite.remove(*it); + it = nit ; + } + else{ + ++it ; + } + } +} + void Tile::deleteTileType(TileGfxType t){ for(list::iterator it = gfxSprite.begin(); it != gfxSprite.end() ; ){ if(t == (*it)->gfx->type){ diff -uN -x TAGS -x *.map* -x *.o -x *~ ./tile.hh /home/aloril/src/g/iso_edit/tile.hh --- ./tile.hh Fri Dec 18 05:48:39 1998 +++ /home/aloril/src/g/iso_edit/tile.hh Tue Dec 22 06:44:33 1998 @@ -99,6 +99,7 @@ void pushTileGfx(TileGfx* tg); void pushTileGfx(TileGfx* tg,int z,int dx, int dy); + void deleteTileGfx(TileGfx* tg); void deleteTileType(TileGfxType) ; void updateSprites() ; int read(ifstream& is) ;