Bigger .cpp file affects game performance?

Hi all.

I’m making a 2D runner game which has over 2000 lines in my main cpp file (HelloWorldScene.cpp). And i have too much things (collision detection, jump, scroll etc…) in my update() functions.

Does this affect game performance or FPS? Or should i just go on and continue developing my game, and don’t care line counts?

You are not smarter than the compiler and linker. Let it do the job it needs to. You can always optimize it further with additional flags (not discussed here).

Don’t worry about the line count in there. However you do it, it will either go through your update() function or “behind the scenes” will go through some other class’s update() function :slight_smile:

Of course, remember that you have a small amount of time to do work ( e.g.16ms) before the next scene needs to go to screen

Yes I don’t want to worry about line count, but my HelloWorldScene.cpp file became too messy. I love programming and I constantly add new things to my game. And this file gets even bigger and more complicated.

Anyway, only a few things left before I release my horizontal runner game. I completed obstacle system, coin system. Now I’m trying to add pick-ups to my game. This will be my first game on Android. I’m excited :sunglasses:

Practicing proper OOP, encapsulation, inheritance is important. Learn it as you can and keep enjoying writing your games. They will just keep getting better.

The size of source don’t effects the speed of your application.
But! You must be sure, which functions how often and where called in your game.
The update method what is called 60 times per second is the most important.
You have about 16 ms to complete everything.

cool, man :slight_smile:
most importantly make your game work; you’ll get the hang of the other stuff little by little.

You can start by putting some of the code in little helper functions, then figure out how to put them in a separate file and include that file.
Try creating some classes for things that make sense.

Read up a little on “design patterns” and software architecture. That probably won’t be immediately useful to you, but it’ll still get you on the right way.

As you progress, you’ll also learn more about how cocos works, I’m sure for some of the stuff you wrote, you can use what cocos already offers.

and don’t worry to much about it - couple of months ago, I was called in to fix some bugs on a couple of games, one file in there was ~7000 lines long, which is ridiculous, but hey, the games work, and they are pretty popular in the app store