Sign in to follow this  
  • entry
    1
  • comments
    2
  • views
    2670

SFNV Flare, Through Thickness

Sign in to follow this  

882 views

Hello reader, My name is Laurent Star Vinn and I have a special project I would like to share with you. See all the struggles and triumphs of my game's development and maybe learn something new along the way. Let's get started.


THE VIRTUAL FUNCTION DILEMMA
Recently I've started using a new tool call virtual functions and a polymorphic base class. Setting this up was very difficult to do but after a week I was using virtual functions. The real problem is that my computer is old and I do mean so old It runs Windows XP. The performance has finally started to lag and I need to find a way to call less virtual functions and make them do more work. My game known as SFNV Flare was so laggy it was like watching a 0.5 frame per second picture show. I don't want to go back to the old way of doing stuff. It was faster but harder to maintain and now after redesigning the code only 2 weeks ago everything looks sleek, and simple. I can't go back to that so I have only one option and that is to optimize or buy a modern computer.


UNOPTIMISTIC SOLUTIONS
Never giving up, I always find a way to brain storm a few wild ideas that sometimes are viewed as the worst. The advice given to me over the years has me in very tough spot where I must actively decide what is important and what is not through very intense research. The new solution I'm debating right now might be yet another conflicting problem. Should I not be able to solve my problem by myself will I call out for help hopeful of not pitching a bad idea for my problem.

QUANTITY PROBLEM.
After doing a bit of research I learn virtual function are slower than regular function. I was also told that they aren't too much slower. This was to key to discovering my program ran slowly due to calling virtual function because it was accumulative. In the old code I could easily do a few calculation and render everything on screen but now with virtual functions that's not plausible. If my problem is simply calling virtual functions then I might be able to perform a. work around. This explains why I didn't encounter the lag issue until rendering. I didn't call as many functions to calculate them.


SOLUTION SO FAR....
I need to call less virtual functions only then might I get back to normal speed. When I calculated my physics I called virtual functions to define a few things but after this was done most of the work was done by what I defined. Because of this my game ran fine, but when I tried to finalize my rendering process I call a lot of virtual functions in nested for loops. My old code was designed like this so I thought nothing of it until I ran it. It been very difficult to do , but I'm going to try to define variables at the beginning of levels before they load, this should release my need to call virtual functions and allow my game to get back to normal. The physics part of my game pushed me to the extreme to create it this way, but I'm starting to see the benefits of working with internal variables. My desire for convenient at the time of programming physics is a blue print for the future.

Sign in to follow this  


2 Comments


Recommended Comments

I don't know very much about you, or what you have done before, but in my opinion it sounds like with

Recently I've started using a new tool call virtual functions and a polymorphic base class.


you have taken a large step backward.

Especially with

when I tried to finalize my rendering process I call a lot of virtual functions in nested for loops.


If there ever was a place where you want to avoid virtual calls, it's in a set of performance-critical nested loops.

The old style of creating deep polymorphic hierarchies of objects has gone out of vogue. These days, it's all about describing your data in cache-friendly formats and composing your objects as aggregates rather than as hierarchies. Often, a composition system will involve some polymorphism in the framework classes, but the bulk of object description takes place through composition rather than inheritance. Not only is it easier to write code that populates your rendering batches in a cache-friendly manner, it can help to cut down a lot of the abstraction confusion that comes with trying to shoehorn game concepts into class inheritance hierarchies.

Share this comment


Link to comment

I don't know very much about you, or what you have done before, but in my opinion it sounds like with



Recently I've started using a new tool call virtual functions and a polymorphic base class.


you have taken a large step backward.

Especially with

when I tried to finalize my rendering process I call a lot of virtual functions in nested for loops.


If there ever was a place where you want to avoid virtual calls, it's in a set of performance-critical nested loops.

The old style of creating deep polymorphic hierarchies of objects has gone out of vogue. These days, it's all about describing your data in cache-friendly formats and composing your objects as aggregates rather than as hierarchies. Often, a composition system will involve some polymorphism in the framework classes, but the bulk of object description takes place through composition rather than inheritance. Not only is it easier to write code that populates your rendering batches in a cache-friendly manner, it can help to cut down a lot of the abstraction confusion that comes with trying to shoehorn game concepts into class inheritance hierarchies.

 

 

I managed to get the performance back up. In my game I have static and dynamic objects. Static objects never move so I simply made a  few arrays of int type and save their coordinates and a few other pieces of data in the arrays I made. Now my render class is working with internal variables to do calculation which is better than old code which called regular functions to do calculation.  

 

For dynamic objects I do call virtual functions to update them and from the looks of it my program is running faster than before by prioritizing only the dynamic objects. I took one more extra step to ensure my program was lean. I created a for loop to find any objects that would need to be check and counted them. The for loop used for rendering only runs for as long as the number I counted. 

 

If I need to, later on I've already brainstorm five other ways to optimize the code and improve on my recent optimization idea.

Share this comment


Link to comment

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