[Fix?] Attempting to fix some seg faults. It seems KonoM's recource management is causing problems.

This commit is contained in:
Rtch90 2012-04-12 15:04:46 +01:00
parent 06171f3671
commit 1a2ba29855
5 changed files with 107 additions and 105 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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;
}

View File

@ -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; }

View File

@ -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;
};
};
PropertySet properties;
MapTile *tile_map;
LayerEncodingType encoding;
LayerCompressionType compression;
};
};