• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
bluepig.man

program performance

8 posts in this topic

how can l got a balance between performance and code standard.
for example, a varible shoule be in the class.But for the performance, it should be a global varible.
What should l do?
0

Share this post


Link to post
Share on other sites
Your example doesn't make sense. "Being in a class" and "being global" is not mutually exclusive and neither of these are directly connected to performance.

So, please clarify where the conflict is and why might be able to help!
0

Share this post


Link to post
Share on other sites
Always go for clear and readable code first, and only do micro-optimizations when you know for certain you need it, preferibly when your profiler tells you that it is indeed a performance bottleneck.
1

Share this post


Link to post
Share on other sites
Honestly in my opinion you should never sacrifice performance for conforming to some standard. Try everything. If you find that you gain a bunch of cycles in a critical piece of code by messing with how your variables are accessed, then by all means, that is the correct thing you should be doing, regardless of what standard you are now failing to conform to.

It really depends on who's going to end up reading your code or who will be using it, though. If you're virtually the only one that's going to be looking at your renderer code, for example, then by all means document what you're doing and mangle the code into oblivion if it performs fast as hell.

As PAndersson stated, though, it shouldn't be the first thing you aim for. You should start with something simple that you know will get you the correct results first, and then worry about turning your code into a nebulous mindsink later. Edited by darkhaven3
-1

Share this post


Link to post
Share on other sites
[quote]
What should l do?
[/quote]
Does your game play fast enough on your target hardware?
[list]
[*] If so, stop making purely performance oriented changes.
[*] If not:
[list]
[*] Profile your game and discover the biggest bottleneck.
[*] Next, apply any algorithmic optimisations that are appropriate.
[*] Next, look at the memory access patterns and see if they can be made cache friendly.
[*] Finally, resort to lower level tricks as a last resort.
[*] Rinse and repeat.
[/list]
[/list]

That construct A might be faster or slower than construct B is not always important. For example, crippling your project's input architecture to save a handful of cycles per frame is not usually a smart engineering move.

The question then becomes, what analysis have you done to decide that a global is faster than a class member? Is it a general rule, or something specific to this case? Can it scale? Does the change have any impact elsewhere? Edited by rip-off
2

Share this post


Link to post
Share on other sites
[quote name='Rattenhirn' timestamp='1355655679' post='5011226']
Your example doesn't make sense. "Being in a class" and "being global" is not mutually exclusive and neither of these are directly connected to performance.
So, please clarify where the conflict is and why might be able to help!
[/quote]

l'm sorry,the description about problem is blurry.
the code is like this:
[source lang="cpp"]extern vector<string> pacman_map;

class pacman_game
{
pacman hero;
public:
pacman_game(const int &px,const int &py);
};

class pacman
{
friend pacman_game;
move();
public:
pacman();
};[/source]
pacman::move and pacman_game will use pacman_map,so l put it on global scope. But l am worry about that problem.
from grammatical speaking,the map should be put in the class,it's a part of the pacman_game.(the pacman_game is designed as game system class)
However,for convenience and performance(if the map is put in the pacman_game,l should pass the map into hero member),put the map on global scope may the common way. Edited by bluepig.man
0

Share this post


Link to post
Share on other sites
This should not be your bottleneck. If it is, I imagine you haven't implemented some of the more interesting bits, such as collision detection, path finding and ghost AI.

As for the design, I would recommend not passing the map into the hero, but instead let the game determine if a collision has occurred by asking the pacman for its bounding shape, and if necessary calling a function informing the pacman of the collision.

Something like this:
[code]
class Pacman
{
public:
Rectangle bounds() const;
void onHitWall();
void onHitPellet();
void onHitFruit();
void onHitGhost();
// ...
};

class Ghost
{
public:
Rectangle bounds() const;
void onHitPacman();
// ...
};

class Game
{
public:
void update();
// ...
private:
Pacman pacman;
std::vector<Ghost> ghosts;
Map map;
// ...
};

void Game::update()
{
// ...

// During movement
if(map.collision(pacman.bounds()))
{
pacman.onHitWall();
// resolve collision
}

// ...
Rectangle pacmanBounds = pacman.bounds();
for(Ghost &ghost : ghosts)
{
if(pacmanBounds.intersects(ghost.bounds()))
{
pacman.onHitGhost();
ghost.onHitPacman();
// ...
}
}

// ...
}
[/code]
This is just a quick example. I've never implemented pacman, it might be better to do a pre-emptive check to see how far pacman can move, rather than detect after the fact that he should not have moved so far.

Globals as a "convenience" is questionable, in my experience it doesn't scale well. In addition, any global makes it hard to unit test.
1

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1355678111' post='5011307']
Globals as a "convenience" is questionable, in my experience it doesn't scale well. In addition, any global makes it hard to unit test.
[/quote]

Globals are also more likely to be a performance problem as chances are their content is NOT going to be in the CPU's cache and given that memory access is VERY slow when compared to instruction execution speed you are looking at a stall right there.
0

Share this post


Link to post
Share on other sites
In fact,the game is semis.it's use windows api. As soon as this version is finished.the next version(use DirectX) will be started.
This version is used to test the game logic. The AI and path search is a bit complicated,need some time to learn it.[img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]
At beginning of this game,Estimated need to spend two weeks.But now,l think it will spend a lot of time.But the process is full of interesting.
And l'm really happy to your answer.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0