Jump to content

  • Log In with Google      Sign In   
  • Create Account

dsm1891

Member Since 31 Mar 2013
Offline Last Active Yesterday, 09:54 AM

Topics I've Started

Hi, Im Dave and I'm an Generic-aholic.

Yesterday, 03:58 AM

Welcome,

 

I think I need help. When ever I code a feature/system/helper/tool/whatever for a game, it has to be generic. I feel like I am addicted to making things as generic as possible, even when such systems don't need to be generic. Sure having generic systems can be great, but when ever I have to create a specific system, I still can get out of the mind set of 'how can this thing be more generic', and frankly things take longer than the should because of this.

 

So let me tell you where it all began. My first project in the industry was made using an inhouse engine with no editor. We tried to make thing as generic as possible so they would 'just work'. no faffing about. We used other editors, such as Tiled or someother software, to create data assets which would be loaded in to game, and 'just work'.

 

I was in charge of implementing enemies, particles, projectiles and such (which all came from one art package). Looking back on the project I love how it all 'just worked', The artist would create a character, I would go in *do some magic* export. Run the game, and that character (with simple AI) would be working as in tended. The whole thing was so independent of code you could have a character fire a gun, when the bullet exploded it could spawn a character, which then would explode spawn particles, damage surrounding,x ,y z - no code required.

 

It was great.

 

However, now I am working with unity, that has an editor. Things don't need to be as automatic as the previous project. its perfectly acceptable and easy to enter values. Because its easy to attach components to game objects, specific components are often a way to go. The existing code base when I joined the project was alien to be, because often it was very specific. Even now when I have to create a new system / re-write an old one, I write it generically. But it is Bottle necked by specific systems, and im left with a choice, make my system less generic or Change another system (which would spiral out of control!).

 

I think I need to learn how to know when to drop the Generic implementation of a system in favour for a more Specific implementation.

 

Any advice?

 

TL;DR: I always try and create generic systems in game, as a result things take longer than if it was a Specific implementation. How do you decide if something should be generic or specific.


How do you like your eggs in the morning?

11 March 2016 - 11:33 AM

I like mine with a kiss


They called me crazy!

17 February 2016 - 10:24 AM

tW41PnI.png

Ladies and gentle men, I bring to you, the Binteger (bool + int).


Banned from chat because i asked if somebody had indian food <_<

16 February 2016 - 10:07 AM

dry.png

 

really?

 

dry.png

 


-Guy goes to the UK, Manchester

I ask if he tried indian food when he was there

link to the curry mile https://en.wikipedia.org/wiki/Curry_Mile (its in Manchester)

--Banned!

Indian food is classic British cuisine

apparently thats racist. dry.png

 


Data linking varibles

15 February 2016 - 11:54 AM

Hi,

 

I have X amount of variables, they all need to add up to an amount (100). There are some conditions that must be met.

 

  • When I set one variable, the others need to reduce/increase.
  • the variables can not go less than 0.  
  • The variables must stay at the same ratio, unless one or more is decreased to 0

Currently I have an issue where I will have a set of varibles: 1, 50, 25,24 . And I want to increase the first variable to 91.

 for (int i = 0; i < arraySize; i++)
        {
            int SliderValue = aarray[i]
            if (SliderValue!= oldValue) //only update when changed
            {
                int difference = SliderValue - oldValue;//how much did the slider change by
                oldValue = SliderValue; //update the old value

                int amount = difference / arraySize - 1);
                int remainder = 0;
                if (difference % arraySize - 1) != 0)//We need to know if it has rounded down
                {
                    remainder = difference % (arraySize -1);

                }

                for (int j = 0; j < arraySize; j++) //Change the other values
                {
                    if (j == i)//dont change youself
                        continue;

                    int b = array[j];
                    if (remainder != 0 && (b>= 0 && b <= goal))
                    {
                        if (remainder < 0)
                        {
                            increaselowest(array, /*element to ignore*/i, Mathf.Abs(remainder));

                        }
                        else
                            decreaselargest(array, /*element to ignore*/i, Mathf.Abs(remainder));

                        remainder = 0;

                    }

                    b= b- amount;
                   Oldvalue= b.intValue;
                }
               
            }

 apologies if there are bugs/errors in this code. It was written using Unity serialization stuff, and had to edit it down.

 

increaselowest will find the lowest variable in the array and increase it by the amount.

DecreaseLargest will find the largest value and decrease it by an amount.

 

 

My problem comes when I increase by a large amount. with the numbers 1, 50, 25,24. and increase the first variable by 90, it means the other numbers need to decrease by 30 (3*30 = 90). However this will result in the last two variables being negative. 

 

I could reduce the other variable when a var goes negative, but I don't know how many varibles are in the list.

 

I cant sum the negative numbers and reduce the positive numbers by that absolute value, as that inturn may make the a number negative again.

 

I feel like the solution will be some recursion, but I cant think of a nice clean way to do it.

 

Any thoughts?


PARTNERS