[Moeng-cvs] BBRpg/src/shared console.cpp,1.3,1.4 console.h,1.2,1.3 module.cpp,1.2,1.3 module.h,1.2,1
Status: Alpha
Brought to you by:
b_lindeijer
Update of /cvsroot/moeng/BBRpg/src/shared In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3801/shared Modified Files: console.cpp console.h module.cpp module.h object.cpp object.h tiled_map.cpp tiled_map.h Removed Files: engine.cpp engine.h Log Message: Merged in some engine changes from DGE/hecate to BBRpg on SourceForge Index: module.h =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/module.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** module.h 25 Apr 2004 16:39:53 -0000 1.2 --- module.h 23 Oct 2004 11:54:19 -0000 1.3 *************** *** 2,6 **** The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify --- 2,6 ---- The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify *************** *** 29,41 **** ~Module(); ! void loadScript(std::string name); void loadScripts(); ! TiledMap* loadMap(std::string name); ! BITMAP* findBitmap(std::string name); ! MIDI* findMidi(std::string name); ! SAMPLE* findSample(std::string name); ! FONT* findFont(std::string name); ! char* findScript(std::string name); private: --- 29,41 ---- ~Module(); ! void loadScript(const std::string name); void loadScripts(); ! TiledMap* loadMap(const std::string name); ! BITMAP* findBitmap(const std::string name); ! MIDI* findMidi(const std::string name); ! SAMPLE* findSample(const std::string name); ! FONT* findFont(const std::string name); ! char* findScript(const std::string name); private: Index: object.h =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/object.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** object.h 13 Apr 2004 12:26:08 -0000 1.4 --- object.h 23 Oct 2004 11:54:19 -0000 1.5 *************** *** 2,6 **** The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify --- 2,6 ---- The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify *************** *** 37,41 **** int id; int tableRef; // A reference to the associated Lua table ! char *className; Object(int luaTableRef, TiledMap* myMap); --- 37,41 ---- int id; int tableRef; // A reference to the associated Lua table ! const char *className; Object(int luaTableRef, TiledMap* myMap); *************** *** 54,58 **** // Methods void walk(int dir, bool col); ! void set_dir(int dir); void setX(double x); void setY(double y); --- 54,58 ---- // Methods void walk(int dir, bool col); ! void setDir(int dir); void setX(double x); void setY(double y); --- engine.h DELETED --- --- engine.cpp DELETED --- Index: tiled_map.h =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/tiled_map.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** tiled_map.h 13 Apr 2004 12:26:08 -0000 1.6 --- tiled_map.h 23 Oct 2004 11:54:19 -0000 1.7 *************** *** 2,6 **** The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify --- 2,6 ---- The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify *************** *** 24,28 **** class Object; - #define DAT_MAPDATA DAT_ID('M','A','P',' ') #define TILES_W 24 --- 24,27 ---- *************** *** 42,51 **** - // Allegro DATAFILE map routines =========================================== - - void *load_tiledmapdata(PACKFILE *f, long size); - void destroy_tiledmapdata(void *data); - - // Point class =============================================================== --- 41,44 ---- *************** *** 59,62 **** --- 52,70 ---- + // Vector class ============================================================== + + struct Vector + { + Vector(); + Vector(double x, double y, double z); + Vector(const Vector &v); + Vector operator*(double c); + Vector operator/(double c); + Vector operator+(const Vector &v); + Vector operator-(const Vector &v); + double x, y, z; + }; + + // Rectangle class =========================================================== *************** *** 64,70 **** 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; }; --- 72,79 ---- public: Rectangle() {x = y = w = h = 0;} ! Rectangle(int x, int y, int w, int h); void rectToClip(BITMAP *dest); void clipToRect(BITMAP *src); + bool collides(const Rectangle &r); int x, y, w, h; }; *************** *** 166,177 **** 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; }; --- 175,192 ---- void loadFrom(xmlNodePtr reader, TileRepository *tileRepository); ! int getWidth() { return width; } ! int getHeight() { return height; } ! ! void setName(const char* newName); ! void setOpacity(float opacity); ! const char* getName(); ! float getOpacity(); Tile* getTile(Point tileCoords); private: ! int width, height; ! char *name; ! float opacity; Tile** tileMap; }; *************** *** 195,200 **** void loadFrom(xmlNodePtr reader, TileRepository *tileRepository); ! int getWidth() {return mapWidth;} ! int getHeight() {return mapHeight;} // Tile and entity methods --- 210,215 ---- void loadFrom(xmlNodePtr reader, TileRepository *tileRepository); ! int getWidth() {return width;} ! int getHeight() {return height;} // Tile and entity methods *************** *** 202,209 **** 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; --- 217,224 ---- TiledMapLayer* getLayer(int i); ! // Drawing the map virtual void setCamera(Point cameraCoords, Rectangle screenRect, bool centerCamera = false, bool modify = true); ! virtual void draw(BITMAP *dest, bool drawObstacle) = 0; virtual void drawLayer(BITMAP *dest, bool drawObstacle, TiledMapLayer *layer, int opacity = 255) = 0; *************** *** 212,215 **** --- 227,231 ---- void drawAirborneEntities(BITMAP *dest); + // Entity methods Object* addObject(double x, double y, const char* type); Object* registerObject(int tableRef); *************** *** 237,244 **** protected: - //Tile** tileMap; - int mapWidth, mapHeight; - // Camera properties Point cameraCoords; --- 253,258 ---- + int width, height; protected: // Camera properties Point cameraCoords; *************** *** 283,286 **** --- 297,302 ---- // 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 Index: console.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/console.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** console.cpp 13 Apr 2004 12:26:08 -0000 1.3 --- console.cpp 23 Oct 2004 11:54:19 -0000 1.4 *************** *** 2,6 **** The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify --- 2,6 ---- The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify *************** *** 25,39 **** Console::Console(const char* filename) { ! logFilename = new char[strlen(filename) + 1]; ! strcpy(logFilename, filename); ! logFilename[strlen(filename)] = '\0'; ! logFile = fopen(logFilename, "w"); ! fclose(logFile); ! log(CON_LOG, CON_ALWAYS, "----- Start of RPG log file -----"); ! progress = 0; ! active = false; ! enableLogfile = true; } --- 25,39 ---- Console::Console(const char* filename) { ! logFilename = new char[strlen(filename) + 1]; ! strcpy(logFilename, filename); ! logFilename[strlen(filename)] = '\0'; ! logFile = fopen(logFilename, "w"); ! fclose(logFile); ! log(CON_LOG, CON_ALWAYS, "----- Start of RPG log file -----"); ! progress = 0; ! active = false; ! enableLogfile = true; } *************** *** 41,163 **** Console::~Console() { ! // Deallocate console string messages ! list<char*>::iterator i; ! while (!logMessages.empty()) ! { ! i = logMessages.begin(); ! delete (*i); ! logMessages.erase(i); ! } ! log(CON_LOG, CON_ALWAYS, "----- End of RPG log file -----"); ! delete logFilename; } void Console::update() { ! if (active && progress < 100) progress = MIN(100, progress + 2); ! if (!active && progress > 0) progress = MAX(0, progress - 2); } void Console::draw(BITMAP *dest) { ! if (progress > 0) { ! int posY = (int)((double)(dest->h / 4) * sin(((0.5 * M_PI) / (double)100) * (double)progress) - text_height(font)); ! line(dest, 0, posY + text_height(font) + 1, dest->w - 1, posY + text_height(font) + 1, makecol(0,0,0)); ! set_trans_blender(0,0,0,100); ! drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); ! rectfill(dest, 0, 0, dest->w - 1, posY + text_height(font), makecol(0,0,0)); ! drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); ! font = engine_font; ! list<char*>::iterator i = logMessages.begin(); ! 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++; ! } ! } } bool Console::handleInput(int key) { ! if ((progress == 0 || progress == 100) && (key == KEY_TILDE || key == KEY_C)) { ! active = !active; ! return true; ! } ! return false; } void Console::log(int where, int when, const char *what, ...) { ! if ((when & CON_ALWAYS) || ((when & CON_DEBUG) && debug_mode) || ((when & CON_VDEBUG) && debug_mode == 2)) ! { ! char* buf = (char*)malloc(1024 * sizeof(char)); ! va_list ap; ! va_start(ap, what); ! uvsprintf(buf, what, ap); ! va_end(ap); ! if (where & (CON_LOG | CON_QUIT)) ! { ! time_t t; ! time(&t); ! if (enableLogfile) { ! logFile = fopen(logFilename, "a"); ! fprintf( ! logFile, ! "[%s%d:%s%d:%s%d] ", ! (((t / 60) / 60) % 24 < 10) ? "0" : "", ! (int)(((t / 60) / 60) % 24), ! ((t / 60) % 60 < 10) ? "0" : "", ! (int)((t / 60) % 60), ! (t % 60 < 10) ? "0" : "", ! (int)(t % 60) ! ); ! fprintf(logFile, buf); ! fprintf(logFile, "\n"); ! fclose(logFile); ! } ! if (where & CON_QUIT) ! { ! logFile = fopen(logFilename, "a"); ! fprintf(logFile, "FATAL ERROR!\n"); ! fclose(logFile); ! set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); ! allegro_message(buf); printf("\n"); ! exit(1); ! } ! } ! if (where & CON_POPUP) ! { ! allegro_message(buf); ! } ! if (where & CON_CONSOLE) ! { ! // Add the message to the console ! logMessages.push_front(buf); ! // Clean up the log memory (only keep the last 20 messages) ! if (logMessages.size() > 20) { ! free(logMessages.back()); ! logMessages.pop_back(); ! } ! } ! else ! { ! // Clean up the allocated string space ! delete buf; ! } ! } } --- 41,169 ---- Console::~Console() { ! // Deallocate console string messages ! list<char*>::iterator i; ! while (!logMessages.empty()) ! { ! i = logMessages.begin(); ! delete (*i); ! logMessages.erase(i); ! } ! log(CON_LOG, CON_ALWAYS, "----- End of RPG log file -----"); ! delete logFilename; } void Console::update() { ! if (active && progress < 100) progress = MIN(100, progress + 2); ! if (!active && progress > 0) progress = MAX(0, progress - 2); } void Console::draw(BITMAP *dest) { ! if (progress > 0) { ! int posY = (int)((double)(dest->h / 4) * ! sin(((0.5 * M_PI) / (double)100) * ! (double)progress) - text_height(font)); ! line(dest, 0, posY + text_height(font) + 1, dest->w - 1, ! posY + text_height(font) + 1, makecol(0,0,0)); ! set_trans_blender(0,0,0,100); ! drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); ! rectfill(dest, 0, 0, dest->w - 1, posY + text_height(font), ! makecol(0,0,0)); ! drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); ! font = engine_font; ! list<char*>::iterator i = logMessages.begin(); ! 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++; ! } ! } } bool Console::handleInput(int key) { ! if ((progress == 0 || progress == 100) && ! (key == KEY_TILDE || key == KEY_C)) { ! active = !active; ! return true; ! } ! return false; } void Console::log(int where, int when, const char *what, ...) { ! if ((when & CON_ALWAYS) || ((when & CON_DEBUG) && debug_mode) || ! ((when & CON_VDEBUG) && debug_mode == 2)) ! { ! char* buf = (char*)malloc(1024 * sizeof(char)); ! va_list ap; ! va_start(ap, what); ! uvsprintf(buf, what, ap); ! va_end(ap); ! if (where & (CON_LOG | CON_QUIT)) ! { ! time_t t; ! time(&t); ! if (enableLogfile) { ! logFile = fopen(logFilename, "a"); ! fprintf( ! logFile, ! "[%s%d:%s%d:%s%d] ", ! (((t / 60) / 60) % 24 < 10) ? "0" : "", ! (int)(((t / 60) / 60) % 24), ! ((t / 60) % 60 < 10) ? "0" : "", ! (int)((t / 60) % 60), ! (t % 60 < 10) ? "0" : "", ! (int)(t % 60) ! ); ! fprintf(logFile, buf); ! fprintf(logFile, "\n"); ! fclose(logFile); ! } ! if (where & CON_QUIT) ! { ! logFile = fopen(logFilename, "a"); ! fprintf(logFile, "FATAL ERROR!\n"); ! fclose(logFile); ! set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); ! allegro_message(buf); printf("\n"); ! exit(1); ! } ! } ! if (where & CON_POPUP) ! { ! allegro_message(buf); ! } ! if (where & CON_CONSOLE) ! { ! // Add the message to the console ! logMessages.push_front(buf); ! // Clean up the log memory (only keep the last 20 messages) ! if (logMessages.size() > 20) { ! free(logMessages.back()); ! logMessages.pop_back(); ! } ! } ! else ! { ! // Clean up the allocated string space ! delete buf; ! } ! } } Index: console.h =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/console.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** console.h 13 Jan 2004 16:32:35 -0000 1.2 --- console.h 23 Oct 2004 11:54:19 -0000 1.3 *************** *** 2,6 **** The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify --- 2,6 ---- The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify *************** *** 30,50 **** class Console { ! public: ! Console(const char* filename); ! ~Console(); ! void update(); ! void draw(BITMAP *dest); ! bool handleInput(int key); ! void log(int where, int when, const char* what, ...); ! bool enableLogfile; ! private: ! FILE* logFile; ! char* logFilename; ! list<char*> logMessages; ! bool active; ! int progress; }; --- 30,50 ---- class Console { ! public: ! Console(const char* filename); ! ~Console(); ! void update(); ! void draw(BITMAP *dest); ! bool handleInput(int key); ! void log(int where, int when, const char* what, ...); ! bool enableLogfile; ! private: ! FILE* logFile; ! char* logFilename; ! list<char*> logMessages; ! bool active; ! int progress; }; Index: tiled_map.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/tiled_map.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** tiled_map.cpp 25 Apr 2004 16:39:53 -0000 1.9 --- tiled_map.cpp 23 Oct 2004 11:54:19 -0000 1.10 *************** *** 2,6 **** The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify --- 2,6 ---- The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify *************** *** 23,38 **** ! // Allegro DATAFILE map routines =========================================== ! void *load_tiledmapdata(PACKFILE *f, long size) { ! void *map_data = malloc(size); ! memcpy(map_data, f, size); ! return map_data; } ! void destroy_tiledmapdata(void *data) { ! if (data) free(data); } --- 23,81 ---- ! // Vector class ============================================================== ! Vector::Vector() { ! x = y = z = 0.0f; } ! Vector::Vector(double x, double y, double z) { ! this->x = x; ! this->y = y; ! this->z = z; ! } ! ! Vector::Vector(const Vector &v) ! { ! this->x = v.x; ! this->y = v.y; ! this->z = v.z; ! } ! ! Vector Vector::operator*(double c) ! { ! Vector result; ! result.x = x * c; ! result.y = y * c; ! result.z = z * c; ! return result; ! } ! ! Vector Vector::operator/(double c) ! { ! Vector result; ! result.x = x / c; ! result.y = y / c; ! result.z = z / c; ! return result; ! } ! ! Vector Vector::operator+(const Vector &v) ! { ! Vector result; ! result.x = x + v.x; ! result.y = y + v.y; ! result.z = z + v.z; ! return result; ! } ! ! Vector Vector::operator-(const Vector &v) ! { ! Vector result; ! result.x = x - v.x; ! result.y = y - v.y; ! result.z = z - v.z; ! return result; } *************** *** 40,43 **** --- 83,94 ---- // Rectangle class =========================================================== + Rectangle::Rectangle(int x, int y, int w, int h) + { + this->x = x; + this->y = y; + this->w = w; + this->h = h; + } + void Rectangle::rectToClip(BITMAP *dest) { *************** *** 53,56 **** --- 104,117 ---- } + bool Rectangle::collides(const Rectangle &r) + { + return !( + x + w < r.x || + y + h < r.y || + x > r.x + r.w || + y > r.y + r.h + ); + } + // TileType ================================================================== *************** *** 263,272 **** { BITMAP *tileBitmap; - BITMAP *tempBitmap; - TileType *tempTileType; - char tempTilename[256]; char tempFilename[256]; PALETTE pal; - int x, y; tileBitmap = load_bitmap(filename, pal); --- 324,329 ---- *************** *** 279,304 **** replace_extension(tempFilename, get_filename(filename), "", 256); ! ASSERT(tileBitmap); ! ! for (y = 0; y < (tileBitmap->h / (tile_h + tile_spacing)); y++) ! { ! for (x = 0; x < (tileBitmap->w / (tile_w + tile_spacing)); x++) ! { ! // Create a new tile type and add it to the hash_map ! tempBitmap = create_bitmap(tile_w, tile_h); ! blit( ! tileBitmap, tempBitmap, ! x * (tile_w + tile_spacing), ! y * (tile_h + tile_spacing), ! 0, 0, tile_w, tile_h ! ); ! ! sprintf(tempTilename, "%s%03d", tempFilename, ! y * (tileBitmap->w / tile_w) + x); ! ! tempTileType = new TileType(tempBitmap, tempTilename); ! tileTypes.insert(make_pair(tempTileType->getName(), tempTileType)); ! } ! } destroy_bitmap(tileBitmap); --- 336,340 ---- replace_extension(tempFilename, get_filename(filename), "", 256); ! importBitmap(tileBitmap, tempFilename, tile_w, tile_h, tile_spacing); destroy_bitmap(tileBitmap); *************** *** 341,346 **** ( tiles_in_row * tile_w, ! (tiles_to_save.size() / tiles_in_row + ! tiles_to_save.size() % tiles_in_row) * tile_h ); int x = 0; --- 377,382 ---- ( tiles_in_row * tile_w, ! ((int)tiles_to_save.size() / tiles_in_row + ! (int)tiles_to_save.size() % tiles_in_row) * tile_h ); int x = 0; *************** *** 395,400 **** TiledMapLayer::TiledMapLayer() { ! mapWidth = 0; ! mapHeight = 0; tileMap = NULL; } --- 431,437 ---- TiledMapLayer::TiledMapLayer() { ! width = 0; ! height = 0; ! name = NULL; tileMap = NULL; } *************** *** 403,413 **** { // Delete tiles on map ! for (int y = 0; y < mapHeight; y++) ! for (int x = 0; x < mapWidth; x++) ! delete tileMap[x + y * mapWidth]; free(tileMap); } void TiledMapLayer::resizeTo(int w, int h, int dx, int dy) { --- 440,480 ---- { // Delete tiles on map ! for (int y = 0; y < height; y++) ! for (int x = 0; x < width; x++) ! delete tileMap[x + y * width]; free(tileMap); } + void TiledMapLayer::setName(const char *newName) + { + // Delete any previous name + if (name) { + delete[] name; + name = NULL; + } + + // Set the new name if it is not NULL + if (newName) { + name = new char[strlen(newName) + 1]; + strcpy(name, newName); + } + } + + const char* TiledMapLayer::getName() + { + return name; + } + + void TiledMapLayer::setOpacity(float opacity) + { + this->opacity = opacity; + } + + float TiledMapLayer::getOpacity() + { + return opacity; + } + void TiledMapLayer::resizeTo(int w, int h, int dx, int dy) { *************** *** 424,429 **** // Copy old map data ! for (y = 0; y < mapHeight; y++) { ! for (x = 0; x < mapWidth; x++) { xn = x + dx; --- 491,496 ---- // Copy old map data ! for (y = 0; y < height; y++) { ! for (x = 0; x < width; x++) { xn = x + dx; *************** *** 433,437 **** { Tile *newTile = newTileMap[xn + yn * w]; ! Tile *oldTile = tileMap[x + y * mapWidth]; newTile->setType(oldTile->getType()); newTile->obstacle = oldTile->obstacle; --- 500,504 ---- { Tile *newTile = newTileMap[xn + yn * w]; ! Tile *oldTile = tileMap[x + y * width]; newTile->setType(oldTile->getType()); newTile->obstacle = oldTile->obstacle; *************** *** 441,452 **** // Delete tiles on old map ! for (y = 0; y < mapHeight; y++) ! for (x = 0; x < mapWidth; x++) ! delete tileMap[x + y * mapWidth]; free(tileMap); tileMap = newTileMap; ! mapWidth = w; ! mapHeight = h; } --- 508,519 ---- // Delete tiles on old map ! for (y = 0; y < height; y++) ! for (x = 0; x < width; x++) ! delete tileMap[x + y * width]; free(tileMap); tileMap = newTileMap; ! width = w; ! height = h; } *************** *** 456,465 **** // The layer header ! pack_iputw(mapWidth, file); ! pack_iputw(mapHeight, file); // The tile data ! for (int y = 0; y < mapHeight; y++) ! for (int x = 0; x < mapWidth; x++) getTile(Point(x,y))->saveTo(file); } --- 523,532 ---- // The layer header ! pack_iputw(width, file); ! pack_iputw(height, file); // The tile data ! for (int y = 0; y < height; y++) ! for (int x = 0; x < width; x++) getTile(Point(x,y))->saveTo(file); } *************** *** 471,482 **** xmlTextWriterStartElement(writer, BAD_CAST "layer"); ! snprintf(strbuf, 16, "%d", mapWidth); xmlTextWriterWriteAttribute(writer, BAD_CAST "width", BAD_CAST strbuf); ! snprintf(strbuf, 16, "%d", mapHeight); xmlTextWriterWriteAttribute(writer, BAD_CAST "height", BAD_CAST strbuf); ! for (int y = 0; y < mapHeight; y++) ! for (int x = 0; x < mapWidth; x++) getTile(Point(x,y))->saveTo(writer); --- 538,549 ---- xmlTextWriterStartElement(writer, BAD_CAST "layer"); ! snprintf(strbuf, 16, "%d", width); xmlTextWriterWriteAttribute(writer, BAD_CAST "width", BAD_CAST strbuf); ! snprintf(strbuf, 16, "%d", height); xmlTextWriterWriteAttribute(writer, BAD_CAST "height", BAD_CAST strbuf); ! for (int y = 0; y < height; y++) ! for (int x = 0; x < width; x++) getTile(Point(x,y))->saveTo(writer); *************** *** 494,499 **** // Load the tile data ! for (int y = 0; y < mapHeight; y++) ! for (int x = 0; x < mapWidth; x++) getTile(Point(x,y))->loadFrom(file, tileRepository); } --- 561,566 ---- // Load the tile data ! for (int y = 0; y < height; y++) ! for (int x = 0; x < width; x++) getTile(Point(x,y))->loadFrom(file, tileRepository); } *************** *** 519,526 **** // Load the tile data while (cur != NULL) { ! if (xmlStrEqual(cur->name, BAD_CAST "tile") && y < mapHeight) { getTile(Point(x,y))->loadFrom(cur, tileRepository); x++; ! if (x == mapWidth) {x = 0; y++;} } cur = cur->next; --- 586,593 ---- // Load the tile data while (cur != NULL) { ! if (xmlStrEqual(cur->name, BAD_CAST "tile") && y < height) { getTile(Point(x,y))->loadFrom(cur, tileRepository); x++; ! if (x == width) {x = 0; y++;} } cur = cur->next; *************** *** 530,535 **** Tile *TiledMapLayer::getTile(Point tile) { ! if (tile.x < 0 || tile.x >= mapWidth || ! tile.y < 0 || tile.y >= mapHeight) { return NULL; --- 597,602 ---- Tile *TiledMapLayer::getTile(Point tile) { ! if (tile.x < 0 || tile.x >= width || ! tile.y < 0 || tile.y >= height) { return NULL; *************** *** 537,541 **** else { ! return tileMap[tile.x + tile.y * mapWidth]; } } --- 604,608 ---- else { ! return tileMap[tile.x + tile.y * width]; } } *************** *** 546,550 **** TiledMap::TiledMap(): ! nrLayers(2), mapWidth(0), mapHeight(0) { mapLayers[0] = new TiledMapLayer(); --- 613,617 ---- TiledMap::TiledMap(): ! nrLayers(2), width(0), height(0) { mapLayers[0] = new TiledMapLayer(); *************** *** 583,588 **** mapLayers[0]->resizeTo(w, h, dx, dy); mapLayers[1]->resizeTo(w, h, dx, dy); ! mapWidth = w; ! mapHeight = h; } --- 650,655 ---- mapLayers[0]->resizeTo(w, h, dx, dy); mapLayers[1]->resizeTo(w, h, dx, dy); ! width = w; ! height = h; } *************** *** 747,752 **** } ! mapWidth = mapLayers[0]->getWidth(); ! mapHeight = mapLayers[0]->getHeight(); } --- 814,819 ---- } ! width = mapLayers[0]->getWidth(); ! height = mapLayers[0]->getHeight(); } *************** *** 795,800 **** } ! mapWidth = mapLayers[0]->getWidth(); ! mapHeight = mapLayers[0]->getHeight(); } --- 862,867 ---- } ! width = mapLayers[0]->getWidth(); ! height = mapLayers[0]->getHeight(); } *************** *** 959,964 **** for (i = objects.begin(); i != objects.end(); i++) { ! if ((*i)->_destroy) ! { list<Object*>::iterator i2 = i; --- 1026,1030 ---- for (i = objects.begin(); i != objects.end(); i++) { ! if ((*i)->_destroy) { list<Object*>::iterator i2 = i; *************** *** 970,975 **** objects.erase(i2); } ! else ! { (*i)->update(); } --- 1036,1040 ---- objects.erase(i2); } ! else { (*i)->update(); } *************** *** 1044,1054 **** cameraScreenRect.y + cameraScreenRect.h - 1)); ! start.x = MAX(0, MIN(mapWidth - 1, start.x)); ! start.y = MAX(0, MIN(mapHeight - 1, start.y)); - if (opacity < 255) { - set_trans_blender(0,0,0,opacity); - drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); - } for (int y = start.y; y <= end.y; y++) { --- 1109,1115 ---- cameraScreenRect.y + cameraScreenRect.h - 1)); ! start.x = MAX(0, MIN(width - 1, start.x)); ! start.y = MAX(0, MIN(height - 1, start.y)); for (int y = start.y; y <= end.y; y++) { *************** *** 1058,1061 **** --- 1119,1124 ---- if (tempTileType) { if (opacity < 255) { + set_trans_blender(0, 0, 0, opacity); + drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); draw_trans_sprite( dest, *************** *** 1064,1067 **** --- 1127,1131 ---- cameraScreenRect.y - cameraCoords.y + y * tileHeight ); + drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); } else { *************** *** 1081,1084 **** --- 1145,1150 ---- int to = tempTile->obstacle; + set_trans_blender(0, 0, 0, 100); + drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); if (to & OB_TOP) { line(dest, tx + 2, ty + 2, tx + tw - 3, ty + 2, *************** *** 1105,1116 **** makecol(0,0,0)); } } } } - if (opacity < 255) { - drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); - } - oldClip.rectToClip(dest); } --- 1171,1179 ---- makecol(0,0,0)); } + drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); } } } oldClip.rectToClip(dest); } *************** *** 1137,1142 **** { return Point( ! MIN(mapWidth - 1, MAX(0, mapCoords.x / tileWidth)), ! MIN(mapHeight - 1, MAX(0, mapCoords.y / tileHeight)), mapCoords.z ); --- 1200,1205 ---- { return Point( ! MIN(width - 1, MAX(0, mapCoords.x / tileWidth)), ! MIN(height - 1, MAX(0, mapCoords.y / tileHeight)), mapCoords.z ); *************** *** 1155,1160 **** { return Point( ! tileWidth * mapWidth, ! tileHeight * mapHeight ); } --- 1218,1223 ---- { return Point( ! tileWidth * width, ! tileHeight * height ); } *************** *** 1163,1242 **** // IsometricMap class ======================================================== // Provides algorithms for isometric-tiled maps - /* - IsometricMap::IsometricMap(int tileStepX, int tileStepY) - { - this->tileGridSize = tileStepX; - this->tileStepX = tileStepX; - this->tileStepY = tileStepY; - } ! void IsometricMap::draw(BITMAP *dest, bool drawObstacle) ! { ! if (tileMap == NULL) return; ! Rectangle oldClip; ! Tile *tempTile; ! TileType *tempTileType; ! Point temp, temp2, area; ! oldClip.clipToRect(dest); ! cameraScreenRect.rectToClip(dest); ! temp = screenToTile(Point(cameraScreenRect.x, cameraScreenRect.y)); ! area = Point(cameraScreenRect.w / (tileStepX * 2) + 3, cameraScreenRect.h / tileStepY + 3); ! // Move up one row ! temp.x--; ! for (int y = 0; y < area.y; y++) { ! // Initialize temp2 to draw a horizontal line of tiles ! temp2 = temp; ! for (int x = 0; x < area.x; x++) { ! // Check if we are drawing a valid tile ! tempTile = getTile(temp2); ! if (tempTile) { ! tempTileType = tempTile->getType(); ! } else { ! tempTileType = NULL; ! } ! // Draw the tile if valid ! if (tempTileType) { ! draw_sprite( ! dest, ! tempTileType->getBitmap(), ! cameraScreenRect.x - cameraCoords.x + (temp2.x - temp2.y - 1) * tileStepX + mapHeight * tileStepX, ! cameraScreenRect.y - cameraCoords.y + (temp2.x + temp2.y ) * tileStepY ! ); ! } ! // Advance to the next tile (to the right) ! temp2.x++; temp2.y--; ! } ! // Advance to the next row ! if ((y & 1) > 0) temp.x++; else temp.y++; ! } ! // Draw a red line along the edges of the map ! //Point top = mapToScreen(Point(-1, 0)); ! //Point right = mapToScreen(Point(tileGridSize * mapWidth, 0)); ! //Point bottom = mapToScreen(Point(tileGridSize * mapWidth, tileGridSize * mapHeight + 1)); ! //Point left = mapToScreen(Point(-1, tileGridSize * mapHeight + 1)); ! //line(dest, top.x, top.y, right.x, right.y, makecol(255,0,0)); ! //line(dest, right.x, right.y, bottom.x, bottom.y, makecol(255,0,0)); ! //line(dest, bottom.x, bottom.y, left.x, left.y, makecol(255,0,0)); ! //line(dest, left.x, left.y, top.x, top.y, makecol(255,0,0)); ! // Now draw the entities ! drawEntities(dest); ! oldClip.rectToClip(dest); } Point IsometricMap::screenToMap(Point screenCoords) { ! screenCoords.x = screenCoords.x + cameraCoords.x - cameraScreenRect.x - mapHeight * tileStepX; screenCoords.y = screenCoords.y + cameraCoords.y - cameraScreenRect.y; return Point( --- 1226,1313 ---- // IsometricMap class ======================================================== // Provides algorithms for isometric-tiled maps ! IsometricMap::IsometricMap(int tileStepX, int tileStepY) ! { ! this->tileGridSize = tileStepX; ! this->tileStepX = tileStepX; ! this->tileStepY = tileStepY; ! } ! void IsometricMap::draw(BITMAP *dest, bool drawObstacle) ! { ! /* ! if (tileMap == NULL) return; ! Rectangle oldClip; ! TileType *tempTileType; ! Point temp, temp2, area; ! oldClip.clipToRect(dest); ! cameraScreenRect.rectToClip(dest); ! temp = screenToTile(Point(cameraScreenRect.x, cameraScreenRect.y)); ! area = Point( ! cameraScreenRect.w / (tileStepX * 2) + 3, ! cameraScreenRect.h / tileStepY + 3); ! // Move up one row ! temp.x--; ! for (int y = 0; y < area.y; y++) { ! // Initialize temp2 to draw a horizontal line of tiles ! temp2 = temp; ! for (int x = 0; x < area.x; x++) { ! // Check if we are drawing a valid tile ! tempTileType = getTile(temp2); ! // Draw the tile if valid ! if (tempTileType) { ! draw_sprite( ! dest, ! tempTileType->getBitmap(), ! cameraScreenRect.x - cameraCoords.x + (temp2.x - ! temp2.y - 1) * tileStepX + height * tileStepX, ! cameraScreenRect.y - cameraCoords.y + (temp2.x + ! temp2.y) * tileStepY ! ); ! } ! // Advance to the next tile (to the right) ! temp2.x++; temp2.y--; ! } ! // Advance to the next row ! if ((y & 1) > 0) temp.x++; else temp.y++; ! } ! // Draw a red line along the edges of the map ! Point top = mapToScreen(Point(-1, 0)); ! Point right = mapToScreen(Point(tileGridSize * width, 0)); ! Point bottom = mapToScreen(Point(tileGridSize * width, ! tileGridSize * height + 1)); ! Point left = mapToScreen(Point(-1, tileGridSize * height + 1)); ! line(dest, top.x, top.y, right.x, right.y, makecol(255,0,0)); ! line(dest, right.x, right.y, bottom.x, bottom.y, makecol(255,0,0)); ! line(dest, bottom.x, bottom.y, left.x, left.y, makecol(255,0,0)); ! line(dest, left.x, left.y, top.x, top.y, makecol(255,0,0)); ! // Now draw the entities ! drawEntities(dest); ! ! oldClip.rectToClip(dest); ! */ ! } ! ! void IsometricMap::drawLayer( ! BITMAP *dest, bool drawObstacle, ! TiledMapLayer *layer, int opacity) ! { } Point IsometricMap::screenToMap(Point screenCoords) { ! screenCoords.x = screenCoords.x + cameraCoords.x - cameraScreenRect.x - ! height * tileStepX; screenCoords.y = screenCoords.y + cameraCoords.y - cameraScreenRect.y; return Point( *************** *** 1250,1255 **** { return Point( ! cameraScreenRect.x - cameraCoords.x + (mapCoords.x - mapCoords.y) + mapHeight * tileStepX, ! cameraScreenRect.y - cameraCoords.y + (mapCoords.x + mapCoords.y) / 2, mapCoords.z ); --- 1321,1328 ---- { return Point( ! cameraScreenRect.x - cameraCoords.x + (mapCoords.x - mapCoords.y) + ! height * tileStepX, ! cameraScreenRect.y - cameraCoords.y + (mapCoords.x + mapCoords.y) / ! 2, mapCoords.z ); *************** *** 1259,1264 **** { return Point( ! (mapCoords.x < 0) ? mapCoords.x / tileGridSize - 1 : mapCoords.x / tileGridSize, ! (mapCoords.y < 0) ? mapCoords.y / tileGridSize - 1 : mapCoords.y / tileGridSize, mapCoords.z ); --- 1332,1339 ---- { return Point( ! (mapCoords.x < 0) ? ! mapCoords.x / tileGridSize - 1 : mapCoords.x / tileGridSize, ! (mapCoords.y < 0) ? ! mapCoords.y / tileGridSize - 1 : mapCoords.y / tileGridSize, mapCoords.z ); *************** *** 1277,1283 **** { return Point( ! tileStepX * (mapWidth + mapHeight), ! tileStepY * (mapWidth + mapHeight) ); } - */ --- 1352,1357 ---- { return Point( ! tileStepX * (width + height), ! tileStepY * (width + height) ); } Index: object.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/object.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** object.cpp 13 Apr 2004 12:26:08 -0000 1.7 --- object.cpp 23 Oct 2004 11:54:19 -0000 1.8 *************** *** 2,6 **** The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify --- 2,6 ---- The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify *************** *** 15,19 **** #include "console.h" #include "tiled_map.h" - #include "engine.h" #include "../script.h" #include "../common.h" --- 15,18 ---- *************** *** 88,92 **** case DIR_RIGHT: next_x += 1.0; break; } ! set_dir(dir); } else { --- 87,91 ---- case DIR_RIGHT: next_x += 1.0; break; } ! setDir(dir); } else { *************** *** 106,110 **** ny = next_y; walking = 100 - walking; ! set_dir(dir); } return; --- 105,109 ---- ny = next_y; walking = 100 - walking; ! setDir(dir); } return; *************** *** 158,162 **** ! void Object::set_dir(int dir) { if (dir == DIR_NONE) return; --- 157,161 ---- ! void Object::setDir(int dir) { if (dir == DIR_NONE) return; Index: module.cpp =================================================================== RCS file: /cvsroot/moeng/BBRpg/src/shared/module.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** module.cpp 25 Apr 2004 16:39:53 -0000 1.2 --- module.cpp 23 Oct 2004 11:54:19 -0000 1.3 *************** *** 2,6 **** The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify --- 2,6 ---- The Moonlight Engine - An extendable, portable, RPG-focused game engine. Project Home: http://moeng.sourceforge.net/ ! Copyright (C) 2003, 2004 Bjørn Lindeijer This program is free software; you can redistribute it and/or modify *************** *** 17,26 **** #include <allegro.h> #include <string.h> #include <dirent.h> #include <string> - #include "../common.h" #include "module.h" #include "../script.h" - #include "engine.h" --- 17,27 ---- #include <allegro.h> #include <string.h> + #ifndef WIN32 #include <dirent.h> + #endif #include <string> #include "module.h" + #include "../common.h" #include "../script.h" *************** *** 44,48 **** } ! void Module::loadScript(std::string name) { // Create the indent --- 45,49 ---- } ! void Module::loadScript(const std::string name) { // Create the indent *************** *** 51,55 **** for (i = 0; i < loadLevel; i++) spaces[i] = ' '; spaces[loadLevel] = '\0'; ! map<std::string, char*, ltstr>::iterator script_i = scripts.find(name); if (script_i != scripts.end()) { --- 52,56 ---- for (i = 0; i < loadLevel; i++) spaces[i] = ' '; spaces[loadLevel] = '\0'; ! map<std::string, char*>::iterator script_i = scripts.find(name); if (script_i != scripts.end()) { *************** *** 82,85 **** --- 83,87 ---- char *dirname = makeFilename("", "/scripts"); + #ifndef WIN32 DIR *dir; *************** *** 89,93 **** struct dirent *direntry; while ((direntry = readdir(dir)) != NULL) { ! if (strstr(direntry->d_name, ".lua")) { loadLevel = 0; loadScript(direntry->d_name); --- 91,96 ---- struct dirent *direntry; while ((direntry = readdir(dir)) != NULL) { ! char *luaExt = strstr(direntry->d_name, ".lua"); ! if (luaExt != NULL && strcmp(luaExt, ".lua") == 0) { loadLevel = 0; loadScript(direntry->d_name); *************** *** 97,100 **** --- 100,104 ---- } else { + #endif // Read the scripts from the datafile script_data = load_datafile_object(datafile_name, "data/scripts"); *************** *** 115,119 **** --- 119,125 ---- script_data = NULL; } + #ifndef WIN32 } + #endif // Clean up any loaded scripts *************** *** 129,133 **** } ! TiledMap* Module::loadMap(std::string name) { TiledMap *mmap = NULL; --- 135,139 ---- } ! TiledMap* Module::loadMap(const std::string name) { TiledMap *mmap = NULL; *************** *** 162,169 **** } ! BITMAP* Module::findBitmap(std::string name) { BITMAP *bitmap = NULL; ! map<std::string, BITMAP*, ltstr>::iterator i = bitmaps.find(name); if (i != bitmaps.end()) { --- 168,175 ---- } ! BITMAP* Module::findBitmap(const std::string name) { BITMAP *bitmap = NULL; ! map<std::string, BITMAP*>::iterator i = bitmaps.find(name); if (i != bitmaps.end()) { *************** *** 190,197 **** } ! MIDI* Module::findMidi(std::string name) { MIDI *midi = NULL; ! map<std::string, MIDI*, ltstr>::iterator i = midis.find(name); char *filename = makeFilename(name.c_str(), "/music"); --- 196,203 ---- } ! MIDI* Module::findMidi(const std::string name) { MIDI *midi = NULL; ! map<std::string, MIDI*>::iterator i = midis.find(name); char *filename = makeFilename(name.c_str(), "/music"); *************** *** 218,225 **** } ! SAMPLE* Module::findSample(std::string name) { SAMPLE *sample = NULL; ! map<std::string, SAMPLE*, ltstr>::iterator i = samples.find(name); char *filename = makeFilename(name.c_str(), "/samples"); --- 224,231 ---- } ! SAMPLE* Module::findSample(const std::string name) { SAMPLE *sample = NULL; ! map<std::string, SAMPLE*>::iterator i = samples.find(name); char *filename = makeFilename(name.c_str(), "/samples"); *************** *** 246,253 **** } ! FONT* Module::findFont(std::string name) { FONT *font = NULL; ! map<std::string, FONT*, ltstr>::iterator i = fonts.find(name); if (i != fonts.end()) { --- 252,259 ---- } ! FONT* Module::findFont(const std::string name) { FONT *font = NULL; ! map<std::string, FONT*>::iterator i = fonts.find(name); if (i != fonts.end()) { *************** *** 267,274 **** } ! char* Module::findScript(std::string name) { char *script = NULL; ! map<std::string, char*, ltstr>::iterator i = scripts.find(name); char *filename = makeFilename(name.c_str(), "/scripts"); --- 273,280 ---- } ! char* Module::findScript(const std::string name) { char *script = NULL; ! map<std::string, char*>::iterator i = scripts.find(name); char *filename = makeFilename(name.c_str(), "/scripts"); |