Skip to main content
Code Review

Return to Question

Tweeted twitter.com/StackCodeReview/status/998784824432263168
deleted 164 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

creating Creating a lot of objects in a tilebasedtile-based game

But I do have a specific part I'd like you to review. In my Cell class, each object represents a map tile with informations like tileID (texture to render), and later attributes like "hasPower, water, ..."

In my Cell class, each object represents a map tile with informations like tileID (texture to render), and later attributes like "hasPower, water, ..." ItIt is quite complex and has a lot of member functions. My game is a SimCity 2000 clone and tiles can be elevated. so a cell must check its surrounding tiles if they're elevated, and if so draw a different texture(tileIDtileID) according to it'sits neighbors elevation or even raise / lower itself.

The rendering is also done in the CellCell class because the sprite object must know its ISO coordinates (including the height) which is known per cell object.

I could rewrite my code, so that the rendering is done in the vectorMatrixvectorMatrix class (in a loop that iterates over all cells in the vector, gets the cell's heigtheight, sets the sprites isocoordinates, and then calls the sprites render()render() function), but I've tried that and it makes no performance difference.

I found this article

But but I don't understand if this is applicable for my use-case or if that's a different story.

Hope you can help me improve my code, as this is quite a bottleneck...


I've added more information and hopefully it's enough, if not please let me know!

creating a lot of objects in a tilebased game

But I do have a specific part I'd like you to review.

In my Cell class, each object represents a map tile with informations like tileID (texture to render), and later attributes like "hasPower, water, ..." It is quite complex and has a lot of member functions. My game is a SimCity 2000 clone and tiles can be elevated. so a cell must check its surrounding tiles if they're elevated, and if so draw a different texture(tileID) according to it's neighbors elevation or even raise / lower itself.

The rendering is also done in the Cell class because the sprite object must know its ISO coordinates (including the height) which is known per cell object.

I could rewrite my code, so that the rendering is done in the vectorMatrix class (in a loop that iterates over all cells in the vector, gets the cell's heigt, sets the sprites isocoordinates, and then calls the sprites render() function), but I've tried that and it makes no performance difference.

I found this article

But I don't understand if this is applicable for my use-case or if that's a different story.

Hope you can help me improve my code, as this is quite a bottleneck...


I've added more information and hopefully it's enough, if not please let me know!

Creating a lot of objects in a tile-based game

But I do have a specific part I'd like you to review. In my Cell class, each object represents a map tile with informations like tileID (texture to render), and later attributes like "hasPower, water, ..."

It is quite complex and has a lot of member functions. My game is a SimCity 2000 clone and tiles can be elevated. so a cell must check its surrounding tiles if they're elevated, and if so draw a different texture(tileID) according to its neighbors elevation or even raise / lower itself.

The rendering is also done in the Cell class because the sprite object must know its ISO coordinates (including the height) which is known per cell object.

I could rewrite my code, so that the rendering is done in the vectorMatrix class (in a loop that iterates over all cells in the vector, gets the cell's height, sets the sprites isocoordinates, and then calls the sprites render() function), but I've tried that and it makes no performance difference.

I found this article but I don't understand if this is applicable for my use-case or if that's a different story.

it's means "it is"; its is the pronoun ; typos; markup for breakheads
Source Link
JDługosz
  • 11.7k
  • 19
  • 40

In my Cell class, each object represents a map tile with informations like tileID (texture to render), and later attributes like "hasPower, water, ..." It is quite complex and has a lot of member functions. My game is a SimCity 2000 clone and tiles can be elevated. so a cell must check it'sits surrounding tiles if they're elevated, and if so draw a differenddifferent texture(tileID) according to it's neighbors elevation or even raisraise / lower itself.

The rendering is also done in the Cell class because the sprite object must know it'sits ISO coordinates (including the height) which is known per cell object.

Cell.hxx #Cell.hxx

Cell.cxx #Cell.cxx

In my Cell class, each object represents a map tile with informations like tileID (texture to render), and later attributes like "hasPower, water, ..." It is quite complex and has a lot of member functions. My game is a SimCity 2000 clone and tiles can be elevated. so a cell must check it's surrounding tiles if they're elevated, and if so draw a differend texture(tileID) according to it's neighbors elevation or even rais / lower itself.

The rendering is also done in the Cell class because the sprite object must know it's ISO coordinates (including the height) which is known per cell object.

Cell.hxx

Cell.cxx

In my Cell class, each object represents a map tile with informations like tileID (texture to render), and later attributes like "hasPower, water, ..." It is quite complex and has a lot of member functions. My game is a SimCity 2000 clone and tiles can be elevated. so a cell must check its surrounding tiles if they're elevated, and if so draw a different texture(tileID) according to it's neighbors elevation or even raise / lower itself.

The rendering is also done in the Cell class because the sprite object must know its ISO coordinates (including the height) which is known per cell object.

#Cell.hxx

#Cell.cxx

deleted 1 character in body
Source Link

Basically I'd really appreciate if someone with experience could review my code and point out weak points since I'm not an experienced C+++C++ dev.

Basically I'd really appreciate if someone with experience could review my code and point out weak points since I'm not an experienced C+++ dev.

Basically I'd really appreciate if someone with experience could review my code and point out weak points since I'm not an experienced C++ dev.

Post Reopened by 200_success, Incomputable, Community Bot, Sᴀᴍ Onᴇᴌᴀ , Stephen Rauch
added more information
Source Link
Lisa
  • 73
  • 4
Loading
Post Closed as "Not suitable for this site" by Toby Speight, Sᴀᴍ Onᴇᴌᴀ , Stephen Rauch, Billal BEGUERADJ, Dan Oberlam
added 2 characters in body
Source Link
Daniel
  • 4.6k
  • 2
  • 18
  • 40
Loading
capitalize acronyms and pronoun "I", update formatting, correct spelling, punctuation
Source Link
Loading
Source Link
Lisa
  • 73
  • 4
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /