[Moeng-cvs] BBRpg/src/shared console.cpp,1.2,1.3 engine.cpp,1.4,1.5 engine.h,1.4,1.5 object.cpp,1.6,
Status: Alpha
Brought to you by:
b_lindeijer
From: Bj?rn L. <b_l...@us...> - 2004-04-13 12:40:10
|
Update of /cvsroot/moeng/BBRpg/src/shared In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15068/src/shared Modified Files: console.cpp engine.cpp engine.h object.cpp object.h tiled_map.cpp tiled_map.h Log Message: Commiting engine changes to our beloved BBRpg on SourceForge. Index: object.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/object.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** object.cpp 1 Jan 2004 20:58:09 -0000 1.6 --- object.cpp 13 Apr 2004 12:26:08 -0000 1.7 *************** *** 22,54 **** ! //=================== Object ===================================================== int Object::id_counter = 0; Object::Object(int luaTableRef, TiledMap* myMap): ! _destroy(0), ! walking(0), speed(0), dir(0), prev_dir(0), ! count(0), tick(0), ! bitmap(NULL), ! x(0), y(0), px(0), py(0), nx(0), ny(0), w(1), h(1), obstacle(0), ! offset_x(0), offset_y(0), offset_z(0), ! tableRef(luaTableRef), className(NULL), ! drawMode(DM_MASKED), alpha(255), selected(false), in_air(0), ! map(myMap) { ! id = ++id_counter; ! // Set the metatable and _pointer value of my table in Lua ! if (tableRef) { ! lua_getref(L, tableRef); ! lua_getglobal(L, "ObjectMetatable"); ! lua_setmetatable(L, -2); ! lua_pushstring(L, "_pointer" ); ! lua_pushlightuserdata(L, this); ! lua_rawset(L, -3); ! lua_pop(L, 1); ! } ! update_entity(); } --- 22,54 ---- ! //============ Object ===================================================== int Object::id_counter = 0; Object::Object(int luaTableRef, TiledMap* myMap): ! _destroy(0), ! walking(0), speed(0), dir(0), prev_dir(0), ! count(0), tick(0), ! bitmap(NULL), ! x(0), y(0), px(0), py(0), nx(0), ny(0), w(1), h(1), obstacle(0), ! offset_x(0), offset_y(0), offset_z(0), ! tableRef(luaTableRef), className(NULL), ! drawMode(DM_MASKED), alpha(255), selected(false), in_air(0), ! map(myMap) { ! id = ++id_counter; ! // Set the metatable and _pointer value of my table in Lua ! if (tableRef) { ! lua_getref(L, tableRef); ! lua_getglobal(L, "ObjectMetatable"); ! lua_setmetatable(L, -2); ! lua_pushstring(L, "_pointer" ); ! lua_pushlightuserdata(L, this); ! lua_rawset(L, -3); ! lua_pop(L, 1); ! } ! update_entity(); } *************** *** 57,135 **** Object::~Object() { ! if (tableRef) { ! // Notify the object that it is being destroyed ! callMemberFunction(tableRef, "destroyed"); ! // Set the reference to the C++ object to NULL in the Lua table ! lua_getref(L, tableRef); // 1 ! lua_pushstring(L, "_pointer"); // 2 ! lua_pushlightuserdata(L, NULL); // 3 ! lua_rawset(L, -3); // 1 ! lua_pop(L, 1); // 0 ! // Allow Lua to garbage collect the object. ! lua_unref(L, tableRef); ! } } void Object::walk(int dir, bool col) { ! if (!map || dir == DIR_NONE) return; ! if (walking == 0) ! { ! set_dir(dir); ! update_entity(); ! // Precalculate where the player is going ! double next_x = x, next_y = y; ! switch (dir) { ! case DIR_UP: next_y -= 1.0; break; ! case DIR_DOWN: next_y += 1.0; break; ! case DIR_LEFT: next_x -= 1.0; break; ! case DIR_RIGHT: next_x += 1.0; break; ! } ! if (col) { ! // Check for map obstacle ! Tile *nextTile = map->getLayer(0)->getTile(Point((int)next_x, (int)next_y)); ! if (!nextTile || next_x < 0 || next_y < 0 || ! (dir == DIR_UP && (nextTile->obstacle & OB_BOTTOM)) || ! (dir == DIR_DOWN && (nextTile->obstacle & OB_TOP)) || ! (dir == DIR_LEFT && (nextTile->obstacle & OB_RIGHT)) || ! (dir == DIR_RIGHT && (nextTile->obstacle & OB_LEFT))) ! { ! callMemberFunction(tableRef, "event_bump_into"); ! check_stand_on(); ! return; ! } ! // Check for object in the way ! list<Object*>::iterator i; ! for (i = map->objects.begin(); i != map->objects.end(); i++) { ! Object *obj = (*i); ! if ((obstacle) && ! (obj->obstacle) && ! (((obj->x + obj->w > next_x && obj->x <= next_x) && obj->walking == 0 && ! (obj->y - obj->h < next_y && obj->y >= next_y)) || ! ((obj->nx + obj->w > next_x && obj->nx <= next_x) && obj->walking > 0 && ! (obj->ny - obj->h < next_y && obj->ny >= next_y)))) ! { ! callMemberFunction(tableRef, "event_bump_into", "o", obj); ! callMemberFunction(obj->tableRef, "event_bumped_into", "o", this); ! check_stand_on(); ! return; ! } ! } ! } ! // No obstacles, so start walking ! walking = 100; ! px = x; ! py = y; ! nx = next_x; ! ny = next_y; ! callMemberFunction(tableRef, "event_walk_start"); ! } } --- 57,158 ---- Object::~Object() { ! if (tableRef) { ! // Notify the object that it is being destroyed ! callMemberFunction(tableRef, "destroyed"); ! // Set the reference to the C++ object to NULL in the Lua table ! lua_getref(L, tableRef); // 1 ! lua_pushstring(L, "_pointer"); // 2 ! lua_pushlightuserdata(L, NULL); // 3 ! lua_rawset(L, -3); // 1 ! lua_pop(L, 1); // 0 ! // Allow Lua to garbage collect the object. ! lua_unref(L, tableRef); ! } } void Object::walk(int dir, bool col) { ! if (!map || dir == DIR_NONE) return; ! update_entity(); ! // Precalculate where the player is going ! double next_x = x, next_y = y; ! if (walking == 0) { ! switch (dir) { ! case DIR_UP: next_y -= 1.0; break; ! case DIR_DOWN: next_y += 1.0; break; ! case DIR_LEFT: next_x -= 1.0; break; ! case DIR_RIGHT: next_x += 1.0; break; ! } ! set_dir(dir); ! } ! else { ! // Support for turning 180 degrees anywhere. ! // WARNING: Still needs collision check! ! if ( ! (this->dir == DIR_UP && dir == DIR_DOWN) || ! (this->dir == DIR_DOWN && dir == DIR_UP) || ! (this->dir == DIR_LEFT && dir == DIR_RIGHT) || ! (this->dir == DIR_RIGHT && dir == DIR_LEFT)) ! { ! next_x = px; ! next_y = py; ! px = nx; ! py = ny; ! nx = next_x; ! ny = next_y; ! walking = 100 - walking; ! set_dir(dir); ! } ! return; ! } ! if (col && obstacle) { ! // Check for map obstacle ! Tile *nextTile = map->getLayer(0)->getTile( ! Point((int)next_x, (int)next_y)); ! if (!nextTile || next_x < 0 || next_y < 0 || ! (dir == DIR_UP && (nextTile->obstacle & OB_BOTTOM)) || ! (dir == DIR_DOWN && (nextTile->obstacle & OB_TOP)) || ! (dir == DIR_LEFT && (nextTile->obstacle & OB_RIGHT)) || ! (dir == DIR_RIGHT && (nextTile->obstacle & OB_LEFT))) ! { ! callMemberFunction(tableRef, "event_bump_into"); ! check_stand_on(); ! return; ! } ! // Check for object in the way ! list<Object*>::iterator i; ! for (i = map->objects.begin(); i != map->objects.end(); i++) { ! Object *obj = (*i); ! if ((obj->obstacle) && ! (((obj->x + obj->w > next_x && obj->x <= next_x) && ! obj->walking == 0 && ! (obj->y - obj->h < next_y && obj->y >= next_y)) || ! ((obj->nx + obj->w > next_x && obj->nx <= next_x) && ! obj->walking > 0 && ! (obj->ny - obj->h < next_y && obj->ny >= next_y)))) ! { ! callMemberFunction(tableRef, "event_bump_into", "o", obj); ! callMemberFunction(obj->tableRef, ! "event_bumped_into", "o", this); ! check_stand_on(); ! return; ! } ! } ! } ! ! // No obstacles, so start walking ! walking = 100; ! px = x; ! py = y; ! nx = next_x; ! ny = next_y; ! callMemberFunction(tableRef, "event_walk_start"); } *************** *** 137,228 **** void Object::set_dir(int dir) { ! if (dir == DIR_NONE) return; ! if (this->dir != dir && tableRef) { ! this->dir = dir; ! callMemberFunction(tableRef, "event_dir_change"); ! } } void Object::check_stand_on() { ! if (!map) return; ! // Check if this object is now standing on something ! list<Object*>::iterator i; ! for (i = map->objects.begin(); i != map->objects.end(); i++) { ! Object *obj = (*i); ! if ((obj != this) && ! (obj->x + obj->w > x && obj->x <= x) && ! (obj->y - obj->h < y && obj->y >= y)) ! { ! callMemberFunction(tableRef, "event_standing_on", "o", obj); ! callMemberFunction(obj->tableRef, "event_stand_on", "o", this); ! } ! } } void Object::initialize() { ! update_entity(); } void Object::update() { ! if (walking > 0) { ! walking -= speed; ! if (walking <= 0) { ! walking = 0; ! x = nx; ! y = ny; ! callMemberFunction(tableRef, "event_walk_finished"); ! // Check if this object is now standing on something ! check_stand_on(); ! } ! else { ! double wp = 1.0 - (walking / 100.0); ! x = px + (nx - px) * wp; ! y = py + (ny - py) * wp; ! } ! } ! if (tick > 0) { ! count++; ! if (count >= tick) { ! // Call script "tick" function ! callMemberFunction(tableRef, "tick"); ! count = 0; ! } ! } else { ! count = 0; ! } ! if (dir != prev_dir && tableRef) { ! prev_dir = dir; ! callMemberFunction(tableRef, "event_dir_change"); ! } } void Object::update_entity() { ! mapPos.x = int(x * TILES_W); ! mapPos.y = int(y * TILES_H); ! mapPos.z = 0; ! mapPos.x += offset_x; ! mapPos.y += offset_y; ! mapPos.z += offset_z; ! ! pos = mapPos; } void Object::setMap(TiledMap* newMap) { ! if (map != NULL) { ! map->removeReference(this); ! } ! newMap->addReference(this); ! map = newMap; } --- 160,263 ---- void Object::set_dir(int dir) { ! if (dir == DIR_NONE) return; ! if (this->dir != dir && tableRef) { ! this->dir = dir; ! callMemberFunction(tableRef, "event_dir_change"); ! } ! } ! ! void Object::setX(double x) ! { ! this->x = x; ! nx = x; ! } ! ! void Object::setY(double y) ! { ! this->y = y; ! ny = y; } void Object::check_stand_on() { ! if (!map) return; ! // Check if this object is now standing on something ! list<Object*>::iterator i; ! for (i = map->objects.begin(); i != map->objects.end(); i++) { ! Object *obj = (*i); ! if ((obj != this) && ! (obj->x + obj->w > x && obj->x <= x) && ! (obj->y - obj->h < y && obj->y >= y)) ! { ! callMemberFunction(tableRef, "event_standing_on", "o", obj); ! callMemberFunction(obj->tableRef, "event_stand_on", "o", this); ! } ! } } void Object::initialize() { ! update_entity(); } void Object::update() { ! if (walking > 0) { ! walking -= speed; ! if (walking <= 0) { ! walking = 0; ! x = nx; ! y = ny; ! callMemberFunction(tableRef, "event_walk_finished"); ! // Check if this object is now standing on something ! check_stand_on(); ! } ! else { ! double wp = 1.0 - (walking / 100.0); ! x = px + (nx - px) * wp; ! y = py + (ny - py) * wp; ! } ! } ! if (tick > 0) { ! count++; ! if (count >= tick) { ! // Call script "tick" function ! callMemberFunction(tableRef, "tick"); ! count = 0; ! } ! } else { ! count = 0; ! } ! if (dir != prev_dir && tableRef) { ! prev_dir = dir; ! callMemberFunction(tableRef, "event_dir_change"); ! } } void Object::update_entity() { ! mapPos.x = int(x * TILES_W); ! mapPos.y = int(y * TILES_H); ! mapPos.z = 0; ! mapPos.x += offset_x; ! mapPos.y += offset_y; ! mapPos.z += offset_z; ! ! pos = mapPos; } void Object::setMap(TiledMap* newMap) { ! if (map != NULL) { ! map->removeReference(this); ! } ! newMap->addReference(this); ! map = newMap; } *************** *** 230,306 **** bool Object::visible(BITMAP *dest, Point screenCoords) { ! if (!bitmap) return false; ! return !(dest->cl > screenCoords.x + bitmap->w || ! dest->cr < screenCoords.x || ! dest->ct > (screenCoords.y - pos.z) || ! dest->cb < (screenCoords.y - pos.z ) - bitmap->h); } void Object::draw(BITMAP *dest, Point screenCoords) { ! if (bitmap) { ! switch (drawMode) ! { ! case DM_MULTIPLY: ! set_multiply_blender(0,0,0,alpha); ! drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); ! break; ! case DM_ADD: ! set_add_blender(0,0,0,alpha); ! drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); ! break; ! case DM_TRANS: ! set_trans_blender(0,0,0,alpha); ! drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); ! break; ! case DM_ALPHA: ! set_alpha_blender(); ! break; ! case DM_MASKED: ! draw_sprite( ! dest, ! bitmap, ! screenCoords.x, ! screenCoords.y - bitmap->h - pos.z ! ); ! break; ! } ! switch (drawMode) { ! case DM_ADD: ! case DM_MULTIPLY: ! case DM_ALPHA: ! case DM_TRANS: ! draw_trans_sprite( ! dest, ! bitmap, ! screenCoords.x, ! screenCoords.y - bitmap->h - pos.z ! ); ! drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); ! break; ! } ! if (selected) { ! rect( ! dest, ! screenCoords.x-1, screenCoords.y - bitmap->h - pos.z-1, ! screenCoords.x + bitmap->w+1, screenCoords.y - pos.z+1, ! makecol(150,0,0) ! ); ! } ! else if (debug_mode) { ! rect( ! dest, ! screenCoords.x-1, screenCoords.y - bitmap->h - pos.z-1, ! screenCoords.x + bitmap->w+1, screenCoords.y - pos.z+1, ! makecol(0,150,0) ! ); ! } ! } ! if (debug_mode || selected) { ! textprintf(dest, font, screenCoords.x - 1, screenCoords.y + 2, makecol(128,128,128), "%i, %i", pos.x, pos.y); ! } } --- 265,360 ---- bool Object::visible(BITMAP *dest, Point screenCoords) { ! if (!bitmap) return false; ! return !(dest->cl > screenCoords.x + bitmap->w || ! dest->cr < screenCoords.x || ! dest->ct > (screenCoords.y - pos.z) || ! dest->cb < (screenCoords.y - pos.z ) - bitmap->h); } void Object::draw(BITMAP *dest, Point screenCoords) { ! if (bitmap) { ! switch (drawMode) ! { ! case DM_MULTIPLY: ! set_multiply_blender(0,0,0,alpha); ! drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); ! break; ! case DM_ADD: ! set_add_blender(0,0,0,alpha); ! drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); ! break; ! case DM_TRANS: ! set_trans_blender(0,0,0,alpha); ! drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); ! break; ! case DM_ALPHA: ! set_alpha_blender(); ! break; ! case DM_MASKED: ! draw_sprite( ! dest, ! bitmap, ! screenCoords.x, ! screenCoords.y - bitmap->h - pos.z ! ); ! break; ! } ! switch (drawMode) { ! case DM_ADD: ! case DM_MULTIPLY: ! case DM_ALPHA: ! case DM_TRANS: ! draw_trans_sprite( ! dest, ! bitmap, ! screenCoords.x, ! screenCoords.y - bitmap->h - pos.z ! ); ! drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); ! break; ! } ! if (selected) { ! // Draw line around bitmap ! rect( ! dest, ! screenCoords.x - 1, screenCoords.y - bitmap->h - pos.z - 1, ! screenCoords.x + bitmap->w + 1, screenCoords.y - pos.z + 1, ! makecol(150,0,0) ! ); ! if (obstacle) { ! Point p = map->mapToScreen( ! Point(int(x * TILES_W), int(y * TILES_H))); ! ! // Draw filled rectangle displaying obstacle region ! set_trans_blender(0,0,0,64); ! drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); ! rectfill( ! dest, ! p.x, p.y, ! p.x + TILES_W * w, p.y - TILES_H * h, ! makecol(150,0,0) ! ); ! drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); ! } ! } ! else if (debug_mode) { ! rect( ! dest, ! screenCoords.x - 1, screenCoords.y - bitmap->h - pos.z - 1, ! screenCoords.x + bitmap->w + 1, screenCoords.y - pos.z + 1, ! makecol(0,150,0) ! ); ! } ! } ! ! if (debug_mode || selected) { ! textprintf_ex( ! dest, font, screenCoords.x - 1, screenCoords.y + 2, ! makecol(128,128,128), -1, "%i, %i", pos.x, pos.y); ! } } Index: object.h =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/object.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** object.h 28 Dec 2003 12:53:33 -0000 1.3 --- object.h 13 Apr 2004 12:26:08 -0000 1.4 *************** *** 18,69 **** ! //==================================================================================== class Object { ! public: ! static int id_counter; ! Point mapPos; // The position on the map ! int _destroy; // Object will be destroyed during next update. ! double walking, speed; ! int dir, prev_dir; ! int count, tick; ! BITMAP* bitmap; ! double x, y, px, py, nx, ny; ! int w, h; ! int obstacle; // Object is an obstacle to other objects. ! int offset_x, offset_y, offset_z; ! int id; ! int tableRef; // A reference to the associated Lua table ! char *className; ! Object(int luaTableRef, TiledMap* myMap); ! ~Object(); ! // Entity member variables/methods ! bool visible(BITMAP *dest, Point screenCoords); ! void draw(BITMAP *dest, Point topLeft); ! Point pos; ! int drawMode; ! int alpha; ! bool selected; ! int in_air; ! // Methods ! void walk(int dir, bool col); ! void set_dir(int dir); ! void initialize(); ! void check_stand_on(); ! void update(); ! void update_entity(); ! TiledMap* getMap() {return map;} ! void setMap(TiledMap *newMap); ! private: ! TiledMap* map; }; --- 18,71 ---- ! //============================================================================= class Object { ! public: ! static int id_counter; ! Point mapPos; // The position on the map ! int _destroy; // Object will be destroyed during next update. ! double walking, speed; ! int dir, prev_dir; ! int count, tick; ! BITMAP* bitmap; ! double x, y, px, py, nx, ny; ! int w, h; ! int obstacle; // Object is an obstacle to other objects. ! int offset_x, offset_y, offset_z; ! int id; ! int tableRef; // A reference to the associated Lua table ! char *className; ! Object(int luaTableRef, TiledMap* myMap); ! ~Object(); ! // Entity member variables/methods ! bool visible(BITMAP *dest, Point screenCoords); ! void draw(BITMAP *dest, Point topLeft); ! Point pos; ! int drawMode; ! int alpha; ! bool selected; ! int in_air; ! // Methods ! void walk(int dir, bool col); ! void set_dir(int dir); ! void setX(double x); ! void setY(double y); ! void initialize(); ! void check_stand_on(); ! void update(); ! void update_entity(); ! TiledMap* getMap() {return map;} ! void setMap(TiledMap *newMap); ! private: ! TiledMap* map; }; Index: engine.h =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/engine.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** engine.h 10 Dec 2003 20:57:38 -0000 1.4 --- engine.h 13 Apr 2004 12:26:08 -0000 1.5 *************** *** 21,39 **** extern list<TiledMap*> maps; ! #define DIR_NONE -1 ! #define DIR_UP 0 ! #define DIR_LEFT 1 ! #define DIR_RIGHT 2 ! #define DIR_DOWN 3 ! //=================== Engine functions =========================================== void update_objects(); ! //=================== Variables ================================================== extern bool exclusive_mode; --- 21,39 ---- extern list<TiledMap*> maps; ! #define DIR_NONE -1 ! #define DIR_UP 0 ! #define DIR_LEFT 1 ! #define DIR_RIGHT 2 ! #define DIR_DOWN 3 ! //============ Engine functions =========================================== void update_objects(); ! //============ Variables ================================================== extern bool exclusive_mode; Index: engine.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/engine.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** engine.cpp 9 Dec 2003 21:23:07 -0000 1.4 --- engine.cpp 13 Apr 2004 12:26:08 -0000 1.5 *************** *** 16,19 **** --- 16,20 ---- #include "tiled_map.h" #include "engine.h" + #include "module.h" #include "../script.h" #include "../common.h" *************** *** 27,36 **** ! //=================== Engine functions =========================================== void update_objects() { ! // Iterate through all maps ! for (list<TiledMap*>::iterator i = maps.begin(); i != maps.end(); i++) ! (*i)->updateObjects(); } --- 28,37 ---- ! //============ Engine functions =========================================== void update_objects() { ! // Iterate through all maps ! for (list<TiledMap*>::iterator i = maps.begin(); i != maps.end(); i++) ! (*i)->updateObjects(); } Index: tiled_map.h =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/tiled_map.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** tiled_map.h 1 Jan 2004 16:04:36 -0000 1.5 --- tiled_map.h 13 Apr 2004 12:26:08 -0000 1.6 *************** *** 17,20 **** --- 17,22 ---- #include <vector> #include <allegro.h> + #include <libxml/xmlwriter.h> + #include <libxml/tree.h> using namespace std; *************** *** 24,41 **** #define DAT_MAPDATA DAT_ID('M','A','P',' ') ! #define TILES_W 24 ! #define TILES_H 24 ! #define DM_INVISIBLE 0 ! #define DM_ADD 1 ! #define DM_MASKED 2 ! #define DM_ALPHA 3 ! #define DM_TRANS 4 ! #define DM_MULTIPLY 5 ! #define OB_TOP 1 ! #define OB_RIGHT 2 ! #define OB_BOTTOM 4 ! #define OB_LEFT 8 --- 26,43 ---- #define DAT_MAPDATA DAT_ID('M','A','P',' ') ! #define TILES_W 24 ! #define TILES_H 24 ! #define DM_INVISIBLE 0 ! #define DM_ADD 1 ! #define DM_MASKED 2 ! #define DM_ALPHA 3 ! #define DM_TRANS 4 ! #define DM_MULTIPLY 5 ! #define OB_TOP 1 ! #define OB_RIGHT 2 ! #define OB_BOTTOM 4 ! #define OB_LEFT 8 *************** *** 49,57 **** class Point { ! public: ! Point() {x = y = z = 0;} ! Point(int X, int Y, int Z = 0) {x = X; y = Y; z = Z;} ! Point(Point p, int Z) {x = p.x; y = p.y; z = Z;} ! int x, y, z; }; --- 51,59 ---- class Point { ! public: ! Point() {x = y = z = 0;} ! Point(int X, int Y, int Z = 0) {x = X; y = Y; z = Z;} ! Point(Point p, int Z) {x = p.x; y = p.y; z = Z;} ! int x, y, z; }; *************** *** 60,69 **** class Rectangle { ! public: ! Rectangle() {x = y = w = h = 0;} ! Rectangle(int X, int Y, int W, int H) {x = X; y = Y; w = W; h = H;} ! void rectToClip(BITMAP *dest); ! void clipToRect(BITMAP *src); ! int x, y, w, h; }; --- 62,71 ---- class Rectangle { ! public: ! Rectangle() {x = y = w = h = 0;} ! Rectangle(int X, int Y, int W, int H) {x = X; y = Y; w = W; h = H;} ! void rectToClip(BITMAP *dest); ! void clipToRect(BITMAP *src); ! int x, y, w, h; }; *************** *** 73,88 **** class TileType { ! public: ! TileType(BITMAP *tileBitmap, const char *tileName); ! ~TileType(); ! BITMAP* getBitmap() {return bitmap;} ! char* getName() {return name;} ! int getColor() {return color;} ! protected: ! BITMAP* bitmap; ! char* name; ! int color; }; --- 75,90 ---- class TileType { ! public: ! TileType(BITMAP *tileBitmap, const char *tileName); ! ~TileType(); ! BITMAP* getBitmap() {return bitmap;} ! char* getName() {return name;} ! int getColor() {return color;} ! protected: ! BITMAP* bitmap; ! char* name; ! int color; }; *************** *** 95,116 **** struct ltstr { ! bool operator()(const char* s1, const char* s2) const { ! return strcmp(s1, s2) < 0; ! } }; class TileRepository { ! public: ! ~TileRepository(); ! void importDatafile(DATAFILE *dataFile); ! void importBitmap(BITMAP* tileBitmap, const char* group_name, int tile_w, int tile_h, int tile_spacing); ! void importBitmap(const char *filename, int tile_w, int tile_h, int tile_spacing); ! void exportBitmap(const char *filename, int tile_w, int tile_h, int tile_spacing, int tiles_in_row); ! TileType* getTileType(const char *tileName); ! vector<TileType*> generateTileArray(); ! protected: ! map<const char*, TileType*, ltstr> tileTypes; }; --- 97,121 ---- struct ltstr { ! bool operator()(const char* s1, const char* s2) const { ! return strcmp(s1, s2) < 0; ! } }; class TileRepository { ! public: ! ~TileRepository(); ! void importDatafile(DATAFILE *dataFile); ! void importBitmap(BITMAP* tileBitmap, const char* group_name, ! int tile_w, int tile_h, int tile_spacing); ! void importBitmap(const char *filename, ! int tile_w, int tile_h, int tile_spacing); ! void exportBitmap(const char *filename, ! int tile_w, int tile_h, int tile_spacing, int tiles_in_row); ! TileType* getTileType(const char *tileName); ! vector<TileType*> generateTileArray(); ! protected: ! map<const char*, TileType*, ltstr> tileTypes; }; *************** *** 119,134 **** class Tile { ! public: ! Tile(); ! void saveTo(PACKFILE *file); ! void loadFrom(PACKFILE *file, TileRepository *tileRepository); ! void setType(TileType* tileType); ! TileType* getType() {return tileType;} ! int obstacle; ! protected: ! TileType* tileType; }; --- 124,141 ---- class Tile { ! public: ! Tile(); ! void saveTo(PACKFILE *file); ! void saveTo(xmlTextWriterPtr writer); ! void loadFrom(PACKFILE *file, TileRepository *tileRepository); ! void loadFrom(xmlNodePtr reader, TileRepository *tileRepository); ! void setType(TileType* tileType); ! TileType* getType() {return tileType;} ! int obstacle; ! protected: ! TileType* tileType; }; *************** *** 137,144 **** class EntityP { ! public: ! EntityP(Object *ent) {this->ent = ent;} ! Object *ent; ! bool operator< (const EntityP& X) const; }; --- 144,151 ---- class EntityP { ! public: ! EntityP(Object *ent) {this->ent = ent;} ! Object *ent; ! bool operator< (const EntityP& X) const; }; *************** *** 148,169 **** class TiledMapLayer { ! public: ! TiledMapLayer(); ! ~TiledMapLayer(); ! // Layer functions ! void resizeTo(int w, int h, int dx = 0, int dy = 0); ! void saveTo(PACKFILE* file); ! void loadFrom(PACKFILE* file, TileRepository *tileRepository); ! int getWidth() {return mapWidth;} ! int getHeight() {return mapHeight;} ! Tile* getTile(Point tileCoords); ! private: ! int mapWidth; ! int mapHeight; ! Tile** tileMap; }; --- 155,178 ---- class TiledMapLayer { ! public: ! TiledMapLayer(); ! ~TiledMapLayer(); ! // Layer functions ! void resizeTo(int w, int h, int dx = 0, int dy = 0); ! void saveTo(PACKFILE* file); ! void saveTo(xmlTextWriterPtr writer); ! void loadFrom(PACKFILE* file, TileRepository *tileRepository); ! void loadFrom(xmlNodePtr reader, TileRepository *tileRepository); ! int getWidth() {return mapWidth;} ! int getHeight() {return mapHeight;} ! Tile* getTile(Point tileCoords); ! private: ! int mapWidth; ! int mapHeight; ! Tile** tileMap; }; *************** *** 174,234 **** class TiledMap { ! public: ! TiledMap(); ! virtual ~TiledMap(); ! // Map functions ! void resizeTo(int w, int h, int dx = 0, int dy = 0); ! void saveTo(PACKFILE* file); ! int loadMap(const char* mapName); ! void loadFrom(PACKFILE* file, TileRepository *tileRepository); ! void loadFromOld(PACKFILE *file, TileRepository *tileRepository); ! int getWidth() {return mapWidth;} ! int getHeight() {return mapHeight;} ! // Tile and entity methods ! //Tile* getTile(Point tileCoords); ! TiledMapLayer* getLayer(int i); ! // Draw the map ! virtual void setCamera(Point cameraCoords, Rectangle screenRect, bool centerCamera = false, bool modify = true); ! virtual void draw(BITMAP *dest, bool drawObstacle = false) = 0; ! virtual void drawLayer(BITMAP *dest, bool drawObstacle, TiledMapLayer *layer, int opacity = 255) = 0; ! void drawEntities(BITMAP *dest); ! void drawAirborneEntities(BITMAP *dest); ! Object* addObject(int x, int y, const char* type); ! Object* registerObject(int tableRef); ! void updateObjects(); ! void removeReference(Object* obj); ! void addReference(Object* obj); ! // Coordinate space converters ! virtual Point screenToTile(Point screenCoords); ! virtual Point tileToScreen(Point tileCoords); ! virtual Point screenToMap(Point screenCoords) = 0; ! virtual Point mapToScreen(Point mapCoords) = 0; ! virtual Point mapToTile(Point mapCoords) = 0; ! virtual Point tileToMap(Point tileCoords) = 0; ! virtual Point getMapSize() = 0; ! // The layers ! TiledMapLayer *mapLayers[2]; ! int nrLayers; ! // Entity list ! list<Object*> objects; ! protected: ! //Tile** tileMap; ! int mapWidth, mapHeight; ! // Camera properties ! Point cameraCoords; ! Rectangle cameraScreenRect; }; --- 183,247 ---- class TiledMap { ! public: ! TiledMap(); ! virtual ~TiledMap(); ! // Map functions ! void resizeTo(int w, int h, int dx = 0, int dy = 0); ! void saveTo(PACKFILE* file); ! void saveTo(xmlTextWriterPtr writer); ! int loadMap(const char* filename); ! void loadFrom(PACKFILE* file, TileRepository *tileRepository); ! void loadFrom(xmlNodePtr reader, TileRepository *tileRepository); ! int getWidth() {return mapWidth;} ! int getHeight() {return mapHeight;} ! // Tile and entity methods ! //Tile* getTile(Point tileCoords); ! TiledMapLayer* getLayer(int i); ! // Draw the map ! virtual void setCamera(Point cameraCoords, Rectangle screenRect, ! bool centerCamera = false, bool modify = true); ! virtual void draw(BITMAP *dest, bool drawObstacle = false) = 0; ! virtual void drawLayer(BITMAP *dest, bool drawObstacle, ! TiledMapLayer *layer, int opacity = 255) = 0; ! void drawEntities(BITMAP *dest); ! void drawAirborneEntities(BITMAP *dest); ! Object* addObject(double x, double y, const char* type); ! Object* registerObject(int tableRef); ! void updateObjects(); ! void removeReference(Object* obj); ! void addReference(Object* obj); ! void removeObjects(); ! // Coordinate space converters ! virtual Point screenToTile(Point screenCoords); ! virtual Point tileToScreen(Point tileCoords); ! virtual Point screenToMap(Point screenCoords) = 0; ! virtual Point mapToScreen(Point mapCoords) = 0; ! virtual Point mapToTile(Point mapCoords) = 0; ! virtual Point tileToMap(Point tileCoords) = 0; ! virtual Point getMapSize() = 0; ! // The layers ! TiledMapLayer *mapLayers[2]; ! int nrLayers; ! // Entity list ! list<Object*> objects; ! protected: ! //Tile** tileMap; ! int mapWidth, mapHeight; ! // Camera properties ! Point cameraCoords; ! Rectangle cameraScreenRect; }; *************** *** 238,259 **** class SquareMap : public TiledMap { ! public: ! SquareMap(int tileSize); ! SquareMap(int tileWidth, int tileHeight); ! // Draw the map ! virtual void draw(BITMAP *dest, bool drawObstacle = false); ! virtual void drawLayer(BITMAP *dest, bool drawObstacle, TiledMapLayer *layer, int opacity = 255); ! // Coordinate space converters ! virtual Point screenToMap(Point screenCoords); ! virtual Point mapToScreen(Point mapCoords); ! virtual Point mapToTile(Point mapCoords); ! virtual Point tileToMap(Point tileCoords); ! virtual Point getMapSize(); ! protected: ! int tileWidth, tileHeight; }; --- 251,273 ---- class SquareMap : public TiledMap { ! public: ! SquareMap(int tileSize); ! SquareMap(int tileWidth, int tileHeight); ! // Draw the map ! virtual void draw(BITMAP *dest, bool drawObstacle = false); ! virtual void drawLayer(BITMAP *dest, bool drawObstacle, ! TiledMapLayer *layer, int opacity = 255); ! // Coordinate space converters ! virtual Point screenToMap(Point screenCoords); ! virtual Point mapToScreen(Point mapCoords); ! virtual Point mapToTile(Point mapCoords); ! virtual Point tileToMap(Point tileCoords); ! virtual Point getMapSize(); ! protected: ! int tileWidth, tileHeight; }; *************** *** 264,284 **** class IsometricMap : public TiledMap { ! public: ! IsometricMap(int tileStepX, int tileStepY); ! // Draw the map ! virtual void draw(BITMAP *dest, bool drawObstacle = false); ! // Coordinate space converters ! virtual Point screenToMap(Point screenCoords); ! virtual Point mapToScreen(Point mapCoords); ! virtual Point mapToTile(Point mapCoords); ! virtual Point tileToMap(Point tileCoords); ! virtual Point getMapSize(); ! protected: ! int tileGridSize; ! int tileStepX, tileStepY; }; --- 278,298 ---- class IsometricMap : public TiledMap { ! public: ! IsometricMap(int tileStepX, int tileStepY); ! // Draw the map ! virtual void draw(BITMAP *dest, bool drawObstacle = false); ! // Coordinate space converters ! virtual Point screenToMap(Point screenCoords); ! virtual Point mapToScreen(Point mapCoords); ! virtual Point mapToTile(Point mapCoords); ! virtual Point tileToMap(Point tileCoords); ! virtual Point getMapSize(); ! protected: ! int tileGridSize; ! int tileStepX, tileStepY; }; Index: tiled_map.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/tiled_map.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** tiled_map.cpp 1 Jan 2004 16:04:36 -0000 1.7 --- tiled_map.cpp 13 Apr 2004 12:26:08 -0000 1.8 *************** *** 18,21 **** --- 18,23 ---- #include <map> #include <algorithm> + #include <libxml/xmlwriter.h> + #include <libxml/xmlreader.h> *************** *** 25,36 **** void *load_tiledmapdata(PACKFILE *f, long size) [...2218 lines suppressed...] ! ); } Point IsometricMap::tileToMap(Point tileCoords) { ! return Point( ! (tileCoords.x + 1) * tileGridSize, ! (tileCoords.y + 1) * tileGridSize, ! tileCoords.z ! ); } Point IsometricMap::getMapSize() { ! return Point( ! tileStepX * (mapWidth + mapHeight), ! tileStepY * (mapWidth + mapHeight) ! ); } */ Index: console.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/console.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** console.cpp 13 Jan 2004 16:32:35 -0000 1.2 --- console.cpp 13 Apr 2004 12:26:08 -0000 1.3 *************** *** 77,81 **** while (i != logMessages.end() && posY > - text_height(font)) { ! textprintf(dest, font, 2, posY, makecol(200,200,200), (*i)); posY -= text_height(font) + 1; i++; --- 77,81 ---- while (i != logMessages.end() && posY > - text_height(font)) { ! textprintf_ex(dest, font, 2, posY, makecol(200,200,200), -1, (*i)); posY -= text_height(font) + 1; i++; *************** *** 133,136 **** --- 133,137 ---- set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message(buf); + printf("\n"); exit(1); } |