Merge branch 'master' of ssh://femoz.anipic.ru:222/Sunshine/mkxp-sunshine

This commit is contained in:
whitecum1488 2026-07-03 11:08:55 +03:00
commit 35831c1c8e
12 changed files with 284 additions and 182 deletions

View file

@ -36,6 +36,7 @@ set(scripts
Game_System.rb
Game_Temp.rb
Game_Variables.rb
Game_Light.rb
Interpreter_1.rb
Interpreter_2.rb
Interpreter_3.rb

View file

@ -68,6 +68,9 @@ FOOTSTEP_SFX = [
['step_gravel',
'step_wood',
'step_boat'],
# shkep this
["step_gravel",
"step_tile"],
]
FOOTSTEP_AMT = {

View file

@ -1,40 +1,31 @@
class DynamicLight
attr_accessor :done
attr_accessor :plr_light_power
attr_accessor :plr_light_color
def initialize(viewport)
@done = false # for events
@awaked = false
@light_npc = []
@ambient_light = 255
@ambient_light_lerped = 255
@plr_light_power = 0
@plr_light_radius = -1.0
@plr_light_radius_lerped = 5.0
@plr_light_color = Color.new(255, 255, 255)
@plr_light_table = [
# offset_x, offset_y, power_mult, radius mult
0.0, -0.5, 1.0, 1.0, # down
-0.25, -0.5, 1.0, 0.7, # left
0.25, -0.5, 1.0, 0.7, # right
0.0, 0.0, 0.0, 1.0 # up
]
@light_sprite = LightMap.new(viewport)
@light_sprite.wallmap = Bitmap.new($game_map.width, $game_map.height)
#@light_sprite.wallmap = Bitmap.new($game_map.width, $game_map.height)
for x in 0...$game_map.width
for y in 0...$game_map.height
@light_sprite.wallmap.set_pixel(x, y, Color.new(
b(light_passable($game_map.data[x, y, 0])),
b(light_passable($game_map.data[x, y, 1])),
b(light_passable($game_map.data[x, y, 2]))
))
end
#for x in 0...$game_map.width
# for y in 0...$game_map.height
# @light_sprite.wallmap.set_pixel(x, y, Color.new(
# b(light_passable($game_map.data[x, y, 0])),
# b(light_passable($game_map.data[x, y, 1])),
# b(light_passable($game_map.data[x, y, 2]))
# ))
# end
#end
if $light == nil
return
end
@light_sprite.ambient = $light.ambient_light
$light.static_lights.each do |source|
@light_sprite.add_static_source(
source[0],
source[1],
source[2],
source[3],
source[4]
)
end
end
@ -44,11 +35,39 @@ class DynamicLight
def update
# dont render light if its disabled or not awaked
@light_sprite.visible = Settings[:light] && @awaked
if (!Settings[:light] && @awaked)
@light_sprite.visible = Settings[:light] && $light.awaked
if (!Settings[:light] && $light.awaked)
return
end
if $light.update_clear_lights
@light_sprite.clear_static_sources()
@light_sprite.clear_dynamic_sources()
$light.update_clear_lights = false
end
if $light.update_ambient_light
@light_sprite.ambient = $light.ambient_light
$light.update_ambient_light = false
end
if $light.update_remove_static_light.length > 0
$light.update_remove_static_light.each do |source|
@light_sprite.remove_static_source(source[0], source[1])
end
$light.update_remove_static_light = []
end
if $light.update_static_lights.length > 0
$light.update_static_lights.each do |source|
@light_sprite.add_static_source(
source[0],
source[1],
source[2],
source[3],
source[4]
)
end
$light.update_static_lights = []
end
# shader uniforms
@light_sprite.camera_x = $game_map.display_x / 4
@light_sprite.camera_y = $game_map.display_y / 4
@ -60,17 +79,15 @@ class DynamicLight
# player light
table_offset = ($game_player.direction - 2) * 2
offset_x = @plr_light_table[table_offset]
offset_y = @plr_light_table[table_offset + 1]
power_mult = @plr_light_table[table_offset + 2]
power_radius = @plr_light_table[table_offset + 3]
@plr_light_radius_lerped = @plr_light_radius_lerped * 0.8 + @plr_light_radius * 0.2 * power_radius
offset_x = $light.plr_light_table[table_offset]
offset_y = $light.plr_light_table[table_offset + 1]
power_mult = $light.plr_light_table[table_offset + 2]
plr_light = [
$game_player.real_x / 128.0 + offset_x,
$game_player.real_y / 128.0 + offset_y,
@plr_light_power * power_mult,
@plr_light_radius_lerped,
@plr_light_color
$light.plr_light_power * power_mult,
$light.plr_light_radius_lerped,
$light.plr_light_color
]
if has_effect(plr_light)
@ -78,109 +95,23 @@ class DynamicLight
end
# add npc light
@light_npc.each { |npc_light_source|
npc_light = [npc_light_source[0].real_x / 128.0, npc_light_source[0].real_y / 128.0, npc_light_source[1], npc_light_source[2], npc_light_source[3]]
$light.dynamic_lights.each { |npc_light_source|
npc_light = [$game_map.events[npc_light_source[0]].real_x / 128.0, $game_map.events[npc_light_source[0]].real_y / 128.0, npc_light_source[1], npc_light_source[2], npc_light_source[3]]
if has_effect(npc_light)
@light_sprite.add_dynamic_source(npc_light[0], npc_light[1] - 0.5, npc_light[2], npc_light[3], npc_light[4])
end
}
end
def clear_lights
@light_sprite.clear_static_sources()
@light_sprite.clear_dynamic_sources()
end
#def light_passable(tile_id)
# $game_map.passages[tile_id] & 15 == 0
#end
def light_passable(tile_id)
$game_map.passages[tile_id] & 15 == 0
end
def b(val)
val ? 255 : 0
end
def add(x, y, power, radius, color = Color.new(255, 255, 255))
@awaked = true
@light_sprite.add_static_source(x, y, power, radius, color)
end
def add_npc(npc_id, power, radius, color = Color.new(255, 255, 255))
@awaked = true
@light_npc << [$game_map.events[npc_id], power, radius, color]
end
def remove(x, y)
@light_sprite.remove_static_source(x, y)
end
def remove_npc(npc_id)
@light_npc.each do |npc|
if npc[0] == $game_map.events[npc_id]
@light_npc.delete(npc)
end
end
end
#def b(val)
# val ? 255 : 0
#end
def has_effect(source)
source[2] != 0 && source[3] > 0 && source[4].alpha >= 0 && (source[4].red != 0 || source[4].green != 0 || source[4].blue != 0)
end
#def remove(x, y)
# @light_sources.each do |sourse|
# if sourse[0] == x && sourse[1] == y
# @light_sources.delete(sourse)
# return true
# end
# end
# return false
#end
def awake
@awaked = true
end
def sleep # fully disables dynamic light system
@awaked = false
end
def ambient_light
@ambient_light
end
def ambient_light=(val)
@ambient_light = val
@light_sprite.ambient = val
@awaked = true
end
def plr_light_radius
@plr_light_radius
end
def plr_light_radius=(val)
if @plr_light_radius < 0
@plr_light_radius_lerped = val
end
@plr_light_radius = val
end
def plr_light_table
@plr_light_table
end
def plr_light_table=(val)
@plr_light_table[0] = val&.[](0) || 0
@plr_light_table[1] = val&.[](1) || 0
@plr_light_table[2] = val&.[](2) || 1
@plr_light_table[3] = val&.[](3) || 1
@plr_light_table[4] = val&.[](4) || 0
@plr_light_table[5] = val&.[](5) || 0
@plr_light_table[6] = val&.[](6) || 1
@plr_light_table[7] = val&.[](7) || 1
@plr_light_table[8] = val&.[](8) || 0
@plr_light_table[9] = val&.[](9) || 0
@plr_light_table[10] = val&.[](10) || 1
@plr_light_table[11] = val&.[](11) || 1
@plr_light_table[12] = val&.[](12) || 0
@plr_light_table[13] = val&.[](13) || 0
@plr_light_table[14] = val&.[](14) || 1
@plr_light_table[15] = val&.[](15) || 1
end
end

152
scripts/Game_Light.rb Normal file
View file

@ -0,0 +1,152 @@
class Game_Light
attr_accessor :plr_light_power
attr_accessor :plr_light_color
attr_accessor :awaked
attr_accessor :update_clear_lights
attr_accessor :update_ambient_light
attr_accessor :update_static_lights
attr_accessor :update_remove_static_light
attr_reader :dynamic_lights
attr_reader :static_lights
def initialize
@done = false # deprecated
@awaked = false # means is light system enabled
@dynamic_lights = []
@static_lights = []
@ambient_light = 255
@plr_light_power = 0
@plr_light_radius = -1.0
@plr_light_radius_lerped = -1.0
@plr_light_color = Color.new(255, 255, 255)
@plr_light_table = [
# offset_x, offset_y, power_mult, radius mult
0.0, -0.5, 1.0, 1.0, # down
-0.25, -0.5, 1.0, 0.7, # left
0.25, -0.5, 1.0, 0.7, # right
0.0, 0.0, 0.0, 1.0 # up
]
@update_clear_lights = false
@update_ambient_light = false
@update_remove_static_light = []
@update_static_lights = []
end
def update
table_offset = ($game_player.direction - 2) * 2
radius_mult = @plr_light_table[table_offset + 3]
@plr_light_radius_lerped = @plr_light_radius_lerped * 0.8 + @plr_light_radius * 0.2 * radius_mult
end
def add(x, y, power, radius, color = Color.new(255, 255, 255))
source = [x, y, power, radius, color]
@update_static_lights << source
@static_lights << source
awake
end
def add_npc(npc_id, power, radius, color = Color.new(255, 255, 255))
@dynamic_lights << [npc_id, power, radius, color]
awake
end
def remove(x, y)
@update_remove_static_light << [x, y]
@static_lights.each do |source|
if source[0] == x && source[1] == y
@static_lights.delete(source)
return
end
end
end
def remove_npc(npc_id)
@dynamic_lights.each do |npc|
if npc[0] == $game_map.events[npc_id]
@dynamic_lights.delete(npc)
return
end
end
end
def clear_lights
clear_lights_no_signal
@update_clear_lights = true
end
def clear_lights_no_signal
@static_lights = []
@dynamic_lights = []
@update_remove_static_light = []
@update_static_lights = []
end
def done
puts "variable \"done\" of $light is deprecated, please dont use it"
@done
end
def done=(val)
puts "variable \"done\" of $light is deprecated, please dont use it"
@done = val
end
def awake
@awaked = true
end
def sleep # fully disables dynamic light system
@awaked = false
end
def ambient_light
@ambient_light
end
def ambient_light=(val)
@ambient_light = val
@update_ambient_light = true
awake
end
def plr_light_radius
@plr_light_radius
end
def plr_light_radius_lerped
@plr_light_radius_lerped
end
def plr_light_radius=(val)
if @plr_light_radius < 0
@plr_light_radius_lerped = val
end
@plr_light_radius = val
awake
end
def plr_light_table
@plr_light_table
end
def plr_light_table=(val)
@plr_light_table[0] = val&.[](0) || 0
@plr_light_table[1] = val&.[](1) || 0
@plr_light_table[2] = val&.[](2) || 1
@plr_light_table[3] = val&.[](3) || 1
@plr_light_table[4] = val&.[](4) || 0
@plr_light_table[5] = val&.[](5) || 0
@plr_light_table[6] = val&.[](6) || 1
@plr_light_table[7] = val&.[](7) || 1
@plr_light_table[8] = val&.[](8) || 0
@plr_light_table[9] = val&.[](9) || 0
@plr_light_table[10] = val&.[](10) || 1
@plr_light_table[11] = val&.[](11) || 1
@plr_light_table[12] = val&.[](12) || 0
@plr_light_table[13] = val&.[](13) || 0
@plr_light_table[14] = val&.[](14) || 1
@plr_light_table[15] = val&.[](15) || 1
awake
end
end

View file

@ -97,7 +97,8 @@ def write_save(filename)
Marshal.dump($game_followers, file)
Marshal.dump($game_oneshot, file)
Marshal.dump($game_fasttravel, file)
Marshal.dump($game_temp.footstep_sfx , file)
Marshal.dump($game_temp.footstep_sfx, file)
Marshal.dump($light, file)
end
end
@ -138,7 +139,8 @@ def load(filename)
$game_followers = Marshal.load(file)
$game_oneshot = Marshal.load(file)
$game_fasttravel = Marshal.load(file)
$game_temp.footstep_sfx = Marshal.load(file)
$game_temp.footstep_sfx = Marshal.load(file)
$light = Marshal.load(file)
# If magic number is different from when saving
# (if editing was added with editor)
if $game_system.magic_number != $data_system.magic_number
@ -210,28 +212,28 @@ end
def real_load
#load save data
begin
load(SAVE_FILE_NAME)
rescue TypeError, ArgumentError => e
puts "oops: #{e.message}"
EdText.err("save.dat corrupt. Attempting to load backup.")
for i in 1..6
if !File.exist?(Oneshot::SAVE_PATH + "/save_backups/save" + (i).to_s + ".bk")
EdText.err("All save backups corrupt! Deleting corrupt save and shutting down.")
File.delete(SAVE_FILE_NAME)
Oneshot.allow_exit true
Kernel.abort("All save backups corrupt! Deleting corrupt save file and shutting down.")
break
end
begin
load(Oneshot::SAVE_PATH + "/save_backups/save" + (i).to_s + ".bk")
break
rescue TypeError, ArgumentError => e2
puts "oops: #{e2.message}"
EdText.err("save" + (i).to_s + ".bk corrupt. Attempting to load backup.")
end
end
end
begin
load(SAVE_FILE_NAME)
rescue TypeError, ArgumentError => e
puts "oops: #{e.message}"
EdText.err("save.dat corrupt. Attempting to load backup.")
for i in 1..6
if !File.exist?(Oneshot::SAVE_PATH + "/save_backups/save" + (i).to_s + ".bk")
EdText.err("All save backups corrupt! Deleting corrupt save and shutting down.")
File.delete(SAVE_FILE_NAME)
Oneshot.allow_exit true
Kernel.abort("All save backups corrupt! Deleting corrupt save file and shutting down.")
break
end
begin
load(Oneshot::SAVE_PATH + "/save_backups/save" + (i).to_s + ".bk")
break
rescue TypeError, ArgumentError => e2
puts "oops: #{e2.message}"
EdText.err("save" + (i).to_s + ".bk corrupt. Attempting to load backup.")
end
end
end
load_perma_flags

View file

@ -59,7 +59,7 @@ class Scene_Map
@blackfade.visible = false
@blackfade.z = 9999
RPG::Mod.exec_hooks("hooks/Scene_Map/main", binding)
RPG::Mod.exec_hooks("hooks/Scene_Map/main", binding)
# Transition run
Graphics.transition
@ -136,6 +136,9 @@ class Scene_Map
end
end
end
$light.update
# Loop
while true
if $game_temp.prompt_wait > 0
@ -370,6 +373,8 @@ class Scene_Map
# If move destination is different than current map
if $game_map.map_id != $game_temp.player_new_map_id
# Set up a new map
$light&.clear_lights_no_signal
$light.sleep
$game_map.setup($game_temp.player_new_map_id)
end
# Set up player/follower positions

View file

@ -255,6 +255,7 @@ class Scene_Title
$game_followers = []
$game_oneshot = Game_Oneshot.new
$game_fasttravel = Game_FastTravel.new
$light = Game_Light.new
# Set up initial party
$game_party.setup_starting_members
# Set up initial map position

View file

@ -87,7 +87,6 @@ class Spriteset_Map
@bulb.opacity = has_lightbulb? ? 255 : 0
# Make dynamic light
@dynamic_light = DynamicLight.new(@viewport_lights)
$light = @dynamic_light
# Panorama animation timer
@pan_animate_timer = 0
RPG::Mod.exec_hooks("hooks/Spriteset_Map/init", binding)

View file

@ -25,6 +25,7 @@ Game_Player
Game_Oneshot
Game_Follower
Game_FastTravel
Game_Light
# yes.
Settings

View file

@ -223,8 +223,10 @@ void LightMap::draw(){
shader.applyViewportProj();
if (p->wallMap)
{
shader.setWallMapTexture(p->wallMap->getGLTypes().tex);
shader.setWallMapResolution(p->wallMap->width(), p->wallMap->height());
shader.setWallMapResolution(p->wallMap->width(), p->wallMap->height());
}
shader.setCameraPosition(p->cameraX, p->cameraY);
shader.setTileMapOffset(p->tilemapOffsetX, p->tilemapOffsetY);

View file

@ -92,7 +92,7 @@ void crash(Exception::Type t, const char *fmt, ...){
}catch(const std::exception& e){
o << "Crashed before OpenGL initialization: " << e.what() << std::endl;
}
out << "[Versions of libs]" << std::endl;
o << "[Versions of libs]" << std::endl;
const int sdlcompiled = SDL_VERSION;
const int sdllinked = SDL_GetVersion();
o << "SDL(compiled) version: " << SDL_VERSIONNUM_MAJOR(sdlcompiled) << "." << SDL_VERSIONNUM_MINOR(sdlcompiled) << "." << SDL_VERSIONNUM_MICRO(sdlcompiled) << std::endl;

View file

@ -310,23 +310,28 @@ void DynamicLightShader::setTileMapOffset(int x, int y){
void DynamicLightShader::setLightSources(std::vector<LightSource> sources){
gl.Uniform1i(u_lightSourcesCount, sources.size());
for(int i = 0; i < sources.size(); i++)
{
if (!sources[i].hasEffect())
continue;
gl.Uniform4f(u_lightSources + i,
sources[i].x,
sources[i].y,
sources[i].power,
sources[i].radius
);
gl.Uniform4f(u_lightSourcesColors + i,
sources[i].color.red / 255.0,
sources[i].color.green / 255.0,
sources[i].color.blue / 255.0,
sources[i].color.alpha / 255.0
);
for(int i = 0; i < sources.size(); i++) {
if (i < 64) {
if (!sources[i].hasEffect())
continue;
gl.Uniform4f(u_lightSources + i,
sources[i].x,
sources[i].y,
sources[i].power,
sources[i].radius
);
gl.Uniform4f(u_lightSourcesColors + i,
sources[i].color.red / 255.0,
sources[i].color.green / 255.0,
sources[i].color.blue / 255.0,
sources[i].color.alpha / 255.0
);
}
else {
Debug() << "The limit of light sources has been reached! (" << sources.size() << "/ 64 )";
break;
}
}
}