From 1a2ba2985562ec60255c127f183ceeab14dc0c78 Mon Sep 17 00:00:00 2001 From: Rtch90 Date: Thu, 12 Apr 2012 15:04:46 +0100 Subject: [PATCH] [Fix?] Attempting to fix some seg faults. It seems KonoM's recource management is causing problems. --- src/Actor/Player.cpp | 20 +++--- src/Collision/AABB.cpp | 34 ++++----- src/Main/Game.cpp | 2 +- src/Sprite/Sprite.h | 4 +- src/TMXParser/TmxLayer.h | 152 +++++++++++++++++++-------------------- 5 files changed, 107 insertions(+), 105 deletions(-) diff --git a/src/Actor/Player.cpp b/src/Actor/Player.cpp index 3d8625b..451601f 100644 --- a/src/Actor/Player.cpp +++ b/src/Actor/Player.cpp @@ -9,11 +9,11 @@ Player::Player(void) { // Loading of sprites and collision details. // This should be directed to a collision sheet. - _collisionBound = new AABB(); - _collisionBound->CreateAABBFromSprite("../Data/Img/Player"); + //_collisionBound = new AABB(); + //_collisionBound->CreateAABBFromSprite("../Data/Img/Player"); - _environmentCollisionBound = new AABB(); - _environmentCollisionBound->SetMin(_collisionBound->GetMin().x, _collisionBound->GetMax().y - 50.0f); + //_environmentCollisionBound = new AABB(); + //_environmentCollisionBound->SetMin(_collisionBound->GetMin().x, _collisionBound->GetMax().y - 50.0f); //_environmentCollisionBound->SetMax(_collisionBound->GetMax()); } @@ -23,13 +23,15 @@ Player::~Player(void) { } void Player::Update(void) { - _player->LoadSprite("../Data/Img/Player.png"); + if(!_player) { + _player->LoadSprite("../Data/Img/Player.png"); + } // Position and collision bound with the player. - _collisionBound->SetPositionOffset(_player->GetX(), _player->GetY()); + //_collisionBound->SetPositionOffset(_player->GetX(), _player->GetY()); //_environmentCollisionBound->SetPositionOffset(_player->GetX, _player->GetY()); // Time to process the collisions. - ProcessCollisions(); + //ProcessCollisions(); // Process events here. ProcessEvents(); @@ -43,8 +45,8 @@ void Player::Render(void) { void Player::ProcessCollisions(void) { // Process collisions with entities and actors. // We should ensure we are not dead. - EntityCollisionTest(); - ActorCollisionTest(); + //EntityCollisionTest(); + //ActorCollisionTest(); // Set all collision flags to false conditions // then they will need to be proven in the test. diff --git a/src/Collision/AABB.cpp b/src/Collision/AABB.cpp index ada7f3e..2d4b3dd 100644 --- a/src/Collision/AABB.cpp +++ b/src/Collision/AABB.cpp @@ -71,14 +71,14 @@ void AABB::CreateAABBFromSprite(const char* filename) { for(int height = 0; height < _sprite->GetHeight(); height++) { // FUCKING PAIN IN THE ASS MOTHERFUCKER!!!! DWORD offset = height * screen->pitch + width; - if(((DWORD)pixels[offset]) != 0 && !found) { - _min = Vec2((float)width, (float)height); - found = true; - color = ((DWORD)pixels[offset]); - // Break out of these god forsaken loops. - width = _sprite->GetWidth(); - height = _sprite->GetHeight(); - } +// if(((DWORD)pixels[offset]) != 0 && !found) { +// _min = Vec2((float)width, (float)height); +// found = true; +// color = ((DWORD)pixels[offset]); +// // Break out of these god forsaken loops. +// width = _sprite->GetWidth(); +// height = _sprite->GetHeight(); +// } } } @@ -87,10 +87,10 @@ void AABB::CreateAABBFromSprite(const char* filename) { found = false; for(int width = (int)_min.x; width < _sprite->GetWidth(); width++) { DWORD offset = _min.y * screen->pitch + width; - if(((DWORD)pixels[offset] != color && !found)) { - found = true; - _max.x = (float)width; - } +// if(((DWORD)pixels[offset] != color && !found)) { +// found = true; +// _max.x = (float)width; +// } } // Now for the max.y @@ -98,11 +98,11 @@ void AABB::CreateAABBFromSprite(const char* filename) { found = false; for(int height = (int)_min.y; height < _sprite->GetWidth(); height++) { DWORD offset = (DWORD)(height * screen->pitch + _min.x); - if(((DWORD)pixels[offset]) != color && !found) { - found = true; - _max.y = (float)height; - break; - } +// if(((DWORD)pixels[offset]) != color && !found) { +// found = true; +// _max.y = (float)height; +// break; +// } } _staticMax = _max; _staticMin = _min; diff --git a/src/Main/Game.cpp b/src/Main/Game.cpp index c6664ac..b3d9287 100644 --- a/src/Main/Game.cpp +++ b/src/Main/Game.cpp @@ -35,7 +35,7 @@ bool Game::Init(void) { glAlphaFunc(GL_GREATER, 0.1f); _level->Load("../Data/Map/Ugly.tmx"); - + _player->Update(); // Return success. return true; } diff --git a/src/Sprite/Sprite.h b/src/Sprite/Sprite.h index 692d72a..79a6ea1 100644 --- a/src/Sprite/Sprite.h +++ b/src/Sprite/Sprite.h @@ -20,8 +20,8 @@ public: float GetX(void) { return position.x; } float GetY(void) { return position.y; } const Vec2& GetSize() const { return size; } - float GetWidth() const { return size.x; } - float GetHeight() const { return size.y; } + float GetWidth() { return size.x; } + float GetHeight() { return size.y; } const Vec2& GetScale() const { return scale; } float GetRotation() const { return rotation; } Texture* GetTexture() { return texture; } diff --git a/src/TMXParser/TmxLayer.h b/src/TMXParser/TmxLayer.h index f7bed1d..83d1668 100644 --- a/src/TMXParser/TmxLayer.h +++ b/src/TMXParser/TmxLayer.h @@ -34,100 +34,100 @@ class TiXmlNode; -namespace Tmx +namespace Tmx { - //------------------------------------------------------------------------- - // Type used for the encoding of the layer data. - //------------------------------------------------------------------------- - enum LayerEncodingType - { - TMX_ENCODING_XML, - TMX_ENCODING_BASE64, - TMX_ENCODING_CSV - }; + //------------------------------------------------------------------------- + // Type used for the encoding of the layer data. + //------------------------------------------------------------------------- + enum LayerEncodingType + { + TMX_ENCODING_XML, + TMX_ENCODING_BASE64, + TMX_ENCODING_CSV + }; - //------------------------------------------------------------------------- - // Type used for the compression of the layer data. - //------------------------------------------------------------------------- - enum LayerCompressionType - { - TMX_COMPRESSION_NONE, - TMX_COMPRESSION_ZLIB, - TMX_COMPRESSION_GZIP - }; + //------------------------------------------------------------------------- + // Type used for the compression of the layer data. + //------------------------------------------------------------------------- + enum LayerCompressionType + { + TMX_COMPRESSION_NONE, + TMX_COMPRESSION_ZLIB, + TMX_COMPRESSION_GZIP + }; - //------------------------------------------------------------------------- - // Used for storing information about the tile ids for every layer. - // This class also have a property set. - //------------------------------------------------------------------------- - class Layer - { - public: - Layer(); - ~Layer(); + //------------------------------------------------------------------------- + // Used for storing information about the tile ids for every layer. + // This class also have a property set. + //------------------------------------------------------------------------- + class Layer + { + public: + Layer(); + ~Layer(); - // Parse a layer node. - void Parse(const TiXmlNode *layerNode); + // Parse a layer node. + void Parse(const TiXmlNode *layerNode); - // Get the name of the layer. - const std::string &GetName() const { return name; } + // Get the name of the layer. + const std::string &GetName() const { return name; } - // Get the width of the layer, in tiles. - int GetWidth() const { return width; } + // Get the width of the layer, in tiles. + float GetWidth() const { return width; } - // Get the height of the layer, in tiles. - int GetHeight() const { return height; } + // Get the height of the layer, in tiles. + float GetHeight() const { return height; } - // Get the visibility of the layer - bool IsVisible() const { return visible; } + // Get the visibility of the layer + bool IsVisible() const { return visible; } - // Get the property set. - const PropertySet &GetProperties() const { return properties; } + // Get the property set. + const PropertySet &GetProperties() const { return properties; } - // Pick a specific tile from the list. - unsigned GetTileGid(int x, int y) const { return tile_map[y * width + x].gid; } + // Pick a specific tile from the list. + unsigned GetTileGid(int x, int y) const { return tile_map[y * width + x].gid; } - // Get whether the tile is flipped horizontally. - bool IsTileFlippedHorizontally(int x, int y) const - { return tile_map[y * width + x].flippedHorizontally; } + // Get whether the tile is flipped horizontally. + bool IsTileFlippedHorizontally(int x, int y) const + { return tile_map[y * width + x].flippedHorizontally; } - // Get whether the tile is flipped vertically. - bool IsTileFlippedVertically(int x, int y) const - { return tile_map[y * width + x].flippedVertically; } + // Get whether the tile is flipped vertically. + bool IsTileFlippedVertically(int x, int y) const + { return tile_map[y * width + x].flippedVertically; } - // Get whether the tile is flipped diagonally. - bool IsTileFlippedDiagonally(int x, int y) const - { return tile_map[y * width + x].flippedDiagonally; } + // Get whether the tile is flipped diagonally. + bool IsTileFlippedDiagonally(int x, int y) const + { return tile_map[y * width + x].flippedDiagonally; } - // Get the tile specific to the map. - MapTile GetTile(int x, int y) const { return tile_map[y * width + x]; } + // Get the tile specific to the map. + MapTile GetTile(int x, int y) const { return tile_map[y * width + x]; } - // Get the type of encoding that was used for parsing the layer data. - // See: LayerEncodingType - LayerEncodingType GetEncoding() const { return encoding; } + // Get the type of encoding that was used for parsing the layer data. + // See: LayerEncodingType + LayerEncodingType GetEncoding() const { return encoding; } - // Get the type of compression that was used for parsing the layer data. - // See: LayerCompressionType - LayerCompressionType GetCompression() const { return compression; } + // Get the type of compression that was used for parsing the layer data. + // See: LayerCompressionType + LayerCompressionType GetCompression() const { return compression; } - private: - void ParseXML(const TiXmlNode *dataNode); - void ParseBase64(const std::string &innerText); - void ParseCSV(const std::string &innerText); + private: + void ParseXML(const TiXmlNode *dataNode); + void ParseBase64(const std::string &innerText); + void ParseCSV(const std::string &innerText); - std::string name; - - int width; - int height; - - float opacity; - bool visible; + std::string name; - PropertySet properties; + int width; + int height; - MapTile *tile_map; + float opacity; + bool visible; - LayerEncodingType encoding; - LayerCompressionType compression; - }; -}; \ No newline at end of file + PropertySet properties; + + MapTile *tile_map; + + LayerEncodingType encoding; + LayerCompressionType compression; + }; +};