Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlxTilemap refactoring : Separation of logic/display #1101

Merged
merged 4 commits into from
May 17, 2014

Conversation

Masadow
Copy link
Contributor

@Masadow Masadow commented May 17, 2014

In order to implement easier our isometric tilemap (because the tilemap class change too often, we lost a lot of time merging it again all the time). I submit this refactor.

It fixes a bug in overlapsAt method
It adds the following new methods

  • public function getTileIndexByCoords(Coord:FlxPoint):Int
  • public function getTileCoordsByIndex(Index:Int, Midpoint:Bool = true):FlxPoint

private var _data:Array<Int>;

/**
* Virtual methods, must be implemented in each renderers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be solved by using an abstract?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What part ? List of virtual methods ? I thought about it but couldn't find any doc about how to do that, the keyword abstract is not making classes virtual

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can build a macro though to reproduce the behavior of an abstract class

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think that'd be worth it.. seems to require quite a bit of extra code:

https://groups.google.com/forum/#!topic/haxelang/WzeI-N1XbIg
https://gist.github.com/andyli/5011520

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I did not do that on purpose

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

You might wanna remove the comment about macros then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

@Gama11
Copy link
Member

Gama11 commented May 17, 2014

Seems like the naming of "base classes" is a bit of a mess right now:

  • FlxSignalBase
  • FlxBaseAnimation
  • FlxPreloaderBase
  • FlxBaseTilemap

I feel like we should consistently put Base at the end or at the start (@gamedevsam?)

@Masadow Masadow changed the title FlxTilemap refactoring : Separation or logic/display FlxTilemap refactoring : Separation of logic/display May 17, 2014
@Masadow
Copy link
Contributor Author

Masadow commented May 17, 2014

Imo, at the end, it's better for completion, however, at the start, it looks more natural.

I'm not even sure if it's good for completion, since you are most likely to never import one of the base classes within your game ?

totalTiles = _data.length;
}

private function doAutoTile(DrawIndex : Int, CollideIndex : Int):Void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spaces before and after the : don't fit the coding style of flixel. Also not a huge fan of function names that start with do().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What name would you reckon ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think applyAutoTiling() and applyCustomRemapping() might be more fitting.

@Gama11
Copy link
Member

Gama11 commented May 17, 2014

I agree, putting the base first sounds more natural. Completion probably doesn't matter much.

@Masadow
Copy link
Contributor Author

Masadow commented May 17, 2014

Indeed, but it is a typo in HaxeFlixel context isn't it ?

@Gama11
Copy link
Member

Gama11 commented May 17, 2014

I guess you could see it that way. :)

@gamedevsam
Copy link
Contributor

Anything that helps speed up workflow and pave the way for more features is a good change in my book.

Agreed Base should go at the end. This looks good to me 👍

@Masadow
Copy link
Contributor Author

Masadow commented May 17, 2014

To the End ? Cause we both agreed it would be better right after Flx

@gamedevsam
Copy link
Contributor

Lol (missread), I don't really mind it either way, I just like consistency :)

@Tiago-Ling
Copy link
Contributor

Cool, also think after 'Flx' is better.

@Tiago-Ling
Copy link
Contributor

Are there any more concerns about this pull request? Will it get merged?

@Masadow
Copy link
Contributor Author

Masadow commented May 17, 2014

@Gama11 surely is in charge of it

@Gama11
Copy link
Member

Gama11 commented May 17, 2014

I'd prefer if these function names were adjusted: #1101 (comment)

But yeah, this is absolutely going to be merged.

@Masadow
Copy link
Contributor Author

Masadow commented May 17, 2014

My bad, forgot to push ... has been fixed while ago

Gama11 added a commit that referenced this pull request May 17, 2014
FlxTilemap refactoring : Separation of logic/display
@Gama11 Gama11 merged commit ce430da into HaxeFlixel:dev May 17, 2014
@Masadow Masadow deleted the refactor/tilemap branch May 17, 2014 22:40
@JoeCreates
Copy link
Member

There are certainly maintenance and extensibility issues in FlxTilemap.

FlxTilemap has so much in common with FlxSprite. If graphics were separated into a component it would be far easier for a lot of the graphics code to be shared. FlxTilemap would shrink massively.

Furthermore, the autotiling stuff could be separated into an extensible FlxAutoTile class, with an general interface for mapping one tilemap into another. This way it would be possible to make extensions for multitile objects, multiple tileset autotiling, autotiling with adjacent tilemaps, non-linear randomly distributed tiles etc., all while maintaining the same interface, and without ever having to touch the Tilemap class.

With such changes, I think there would be no need for both BaseTilemap and Tilemap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants