Hello, well I've been cleaning my code, and now I'm trying to optimize my "daylight system" from my game. Thing is, I've done something like this:
class Game_System
# I put this on a constant because I'm constantly (lol) tweaking it.
DAY_TONES = [
[-96,-80,-48,48],
[-36,-72,-64,32],
[-18,-36,-32,16],
[8,0,0,0],
[-64,-51,-33,32],
[-96,-80,-48,40],
[-128,-102,-64,48],
[0,0,0,0]
]
#This gives me the info from the class constant to outsiders
#It could actually be slow because of returning sub-arrays, but... I dunno x'D...
def day_tone
i = 7
if $game_map.exterior
if @game_time[0] > 19
i=0
elsif @game_time[0] > 17
i=1
elsif @game_time[0] > 12
i=2
elsif @game_time[0] > 10
i=3
elsif @game_time[0] > 5
i=4
elsif @game_time[0] > 3
i=5
else
i=6
end
end
return DAY_TONES[i]
end
end
class Game_Screen
#And this is probably VERY bad. But what I meant to make was an adjustment
def update_tone
d = @tone_duration
tone_day = $game_system.day_tone
toun = [0,0,0,0]
toun[0]=[(@tone.red * (d - 1) + (@tone_target.red + tone_day[0])) / d ,256].min
toun[1]=[(@tone.green * (d - 1) + (@tone_target.green + tone_day[1]) / d ,255].min
toun[2]=[(@tone.blue * (d - 1) + (@tone_target.blue + tone_day[2]) / d ,255].min
toun[3]=[(@tone.gray * (d - 1) + (@tone_target.gray + tone_day[3]) / d ,255].min
@tone.set(toun[0],toun[1],toun[2],toun[3])
@tone_duration -= 1
end
end
Any observation or... almost anything is very appreciated.
Salut,
OZ
You should probably use Tone as access of Array elements (both read and write) is usually more costly than accessing an instance variable of a class. But to be sure, you would have to benchmark it.