赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 30835 |
最后登录 | 2018-9-22 |
在线时间 | 15 小时 |
Lv1.梦旅人 孙悟空
- 梦石
- 0
- 星屑
- 55
- 在线时间
- 15 小时
- 注册时间
- 2007-8-22
- 帖子
- 448
|
如何解决抢线程脚本与双远景图商业素材冲突?- #===============================================================================
- # ** CPU speed Script
- #
- # by Goldencolor V1.0
- # 2009.10.19
- #前言:今天刚学了Java线程。然后就有个想法。RGSS如果加入线程速度可能会更快。事件也加速#的
- #用这个脚本可以提速。如果在用提帧数差不多可以到。邪恶 -_-!可以到150帧左右
- #找啊找啊找= =b找到了。由于最近比较忙~没有时间发。
- #注意:不要乱该。。这个关系RPGXP抢CPU的速度(线程)
- #===============================================================================
- # Class Antilag Settings
- #-------------------------------------------------------------------------------
- # 设置CPU线程
- #===============================================================================
- class Antilag_Settings
-
- attr_accessor :event
- attr_accessor :max_cpu_utilization
- attr_accessor :cpu_tolerance
- #-----------------------------------------------------------------------------
- # 初始化对象
- #-----------------------------------------------------------------------------
- def initialize
- @event = true
- @high_priority = true
- @max_cpu_utilization = 70
- #这个是控制优先级。
- @cpu_tolerance = 20
- @SetPriorityClass = Win32API.new('kernel32', 'SetPriorityClass',
- ['p', 'i'], 'i')
- @GetProcessTimes = Win32API.new('kernel32', 'GetProcessTimes',
- ['i','p','p','p','p'], 'i')
- end
- #-----------------------------------------------------------------------------
- # 更改优先级 on(true)/off(false)
- #-----------------------------------------------------------------------------
- def high_priority=(value)
- @high_priority = value
- if @high_priority
- @SetPriorityClass.call(-1, 0x00000080) # 高质量
- # 设置CPU优先级80为高。110为实时。20为标准。
- else
- @SetPriorityClass.call(-1, 0x00000020) # 标准优先
- end
- end
- #-----------------------------------------------------------------------------
- # 返回现在的CPU使用率
- #-----------------------------------------------------------------------------
- def get_cpu_utilization
- # 使用API获取内核用户调用时间
- creation_time = '0' * 10
- exit_time = '0' * 10
- kernel_time = '0' * 10
- user_time = '0' * 10
- @GetProcessTimes.call(-1, creation_time, exit_time, kernel_time, user_time)
- kernel_time = kernel_time.unpack('l2')
- user_time = user_time.unpack('l2')
- kernel_time = kernel_time[0] + kernel_time[1]
- user_time = user_time[0] + user_time[1]
- # 计算不同的CPU使用率
- if @old_time != nil
- timer_difference = Time.new - @old_timer
- time_difference = kernel_time + user_time - @old_time
- result = time_difference / timer_difference / 100000
- else
- result = $antilag.max_cpu_utilization
- end
- # 节约CPU使用(还是计算)
- @old_timer = Time.new
- @old_time = kernel_time + user_time
- return result
- end
- end
- $antilag = Antilag_Settings.new
- #==============================================================================
- # ■ Scene_Map
- #------------------------------------------------------------------------------
- # 处理地图画面的类。
- #==============================================================================
- class Scene_Map
- #-----------------------------------------------------------------------------
- # 刷新模块, 增加平滑帧数
- #-----------------------------------------------------------------------------
- alias f0tzis_anti_lag_scene_map_update update
- def update
- f0tzis_anti_lag_scene_map_update
- if Graphics.frame_count % 20 == 0 and $antilag.max_cpu_utilization <= 100
- # 计算CPU最大限度利用和当前的利用率
- abs = $antilag.max_cpu_utilization - $antilag.get_cpu_utilization
- # 如果改变帧速率的差异
- if abs.abs >= $antilag.max_cpu_utilization * $antilag.cpu_tolerance/100.0
- Graphics.frame_rate = [[10, Graphics.frame_rate + abs / 2].max, 40].min
- end
- end
- end
- end
- #==============================================================================
- # Game_Event Class
- # 处理事件
- #===============================================================================
- class Game_Event
- # 这里不需要理会
- def in_range?
-
- # 如果TRUE 返回一个虚拟的事件
- # 自动启动/并行处理事件或者一个空的事件
- if not $antilag.event or (@trigger == 3 or @trigger == 4 or
- (@list != nil and @list[0].code == 108 and @list[0].parameters == ['']))
- return true
- end
-
- screne_x = $game_map.display_x
- screne_x -= 256
- screne_y = $game_map.display_y
- screne_y -= 256
- screne_width = $game_map.display_x
- screne_width += 2816
- screne_height = $game_map.display_y
- screne_height += 2176
-
- return false if @real_x <= screne_x
- return false if @real_x >= screne_width
- return false if @real_y <= screne_y
- return false if @real_y >= screne_height
- return true
-
- end
- #-----------------------------------------------------------------------------
- # ● 更新画面
- #-----------------------------------------------------------------------------
- alias f0tzis_anti_lag_game_event_update update
- def update
- return if not self.in_range?
- f0tzis_anti_lag_game_event_update
- end
-
- end
- #==============================================================================
- # ■ Sprite_Character
- #------------------------------------------------------------------------------
- # 角色显示用脚本。监视 Game_Character 类的实例、
- # 自动变化脚本状态。
- #==============================================================================
- class Sprite_Character < RPG::Sprite
- #-----------------------------------------------------------------------------
- # ● 更新画面
- #-----------------------------------------------------------------------------
- alias f0tzis_anti_lag_sprite_char_update update
- def update
- return if @character.is_a?(Game_Event) and not @character.in_range?
- f0tzis_anti_lag_sprite_char_update
- end
-
- end
- #===============================================================================
- # ■ Game_Map
- #
- # 处理地图的类。包含卷动以及可以通行的判断功能。
- #===============================================================================
- class Game_Map
- def update
- # 还原必要的地图
- if $game_map.need_refresh
- refresh
- end
- # 滚动中的情况下
- if @scroll_rest > 0
- # 滚动速度变化为地图坐标系的距离
- distance = 2 ** @scroll_speed
- # 执行滚动
- case @scroll_direction
- when 2 # 下
- scroll_down(distance)
- when 4 # 左
- scroll_left(distance)
- when 6 # 右
- scroll_right(distance)
- when 8 # 上
- scroll_up(distance)
- end
- # 滚动距离的减法运算
- @scroll_rest -= distance
- end
- # 更新地图事件
- for event in @events.values
- if in_range?(event) or event.trigger == 3 or event.trigger == 4
- event.update
- end
- end
- # 更新公共事件
- for common_event in @common_events.values
- common_event.update
- end
- # 处理雾的滚动
- @fog_ox -= @fog_sx / 8.0
- @fog_oy -= @fog_sy / 8.0
- # 处理雾的色调变更
- if @fog_tone_duration >= 1
- d = @fog_tone_duration
- target = @fog_tone_target
- @fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d
- @fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d
- @fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d
- @fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d
- @fog_tone_duration -= 1
- end
- # 处理雾的不透明度变更
- if @fog_opacity_duration >= 1
- d = @fog_opacity_duration
- @fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d
- @fog_opacity_duration -= 1
- end
- end
- def in_range?(object)
- diff_x = ($game_map.display_x - object.real_x).abs # 绝对值
- diff_y = ($game_map.display_x - object.real_x).abs # 绝对值
- width = 128 * 24 # size * tiles
- height = 128 * 19 # size * tiles
- return !((diff_x > width) or (diff_y > height))
- end
- end
- #===============================================================================
- # ■ Spriteset_Map
- #
- # 处理地图画面活动块和元件的类。
- #===============================================================================
- class Spriteset_Map
- #--------------------------------------------------------------------------
- # ● 刷新画面
- #--------------------------------------------------------------------------
- def update
- # 远景与现在的情况有差异发情况下
- if @panorama_name != $game_map.panorama_name or
- @panorama_hue != $game_map.panorama_hue
- @panorama_name = $game_map.panorama_name
- @panorama_hue = $game_map.panorama_hue
- if @panorama.bitmap != nil
- @panorama.bitmap.dispose
- @panorama.bitmap = nil
- end
- if @panorama_name != ""
- @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
- end
- Graphics.frame_reset
- end
- # 雾与现在的情况有差异的情况下
- if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
- @fog_name = $game_map.fog_name
- @fog_hue = $game_map.fog_hue
- if @fog.bitmap != nil
- @fog.bitmap.dispose
- @fog.bitmap = nil
- end
- if @fog_name != ""
- @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
- end
- Graphics.frame_reset
- end
- # 刷新元件地图
- @tilemap.ox = $game_map.display_x / 4
- @tilemap.oy = $game_map.display_y / 4
- @tilemap.update
- # 刷新远景平面
- @panorama.ox = $game_map.display_x / 8
- @panorama.oy = $game_map.display_y / 8
- # 刷新雾平面
- @fog.zoom_x = $game_map.fog_zoom / 100.0
- @fog.zoom_y = $game_map.fog_zoom / 100.0
- @fog.opacity = $game_map.fog_opacity
- @fog.blend_type = $game_map.fog_blend_type
- @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
- @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
- @fog.tone = $game_map.fog_tone
- # 刷新角色活动块
- for sprite in @character_sprites
- if in_range?(sprite.character)
- sprite.update
- end
- end
- # 刷新天候图形
- @weather.type = $game_screen.weather_type
- @weather.max = $game_screen.weather_max
- @weather.ox = $game_map.display_x / 4
- @weather.oy = $game_map.display_y / 4
- @weather.update
- # 刷新图片
- for sprite in @picture_sprites
- sprite.update
- end
- # 刷新计时器块
- @timer_sprite.update
- # 设置画面的色调与震动位置
- @viewport1.tone = $game_screen.tone
- @viewport1.ox = $game_screen.shake
- # 设置画面的闪烁色
- @viewport3.color = $game_screen.flash_color
- # 刷新显示端口
- @viewport1.update
- @viewport3.update
- end
- def in_range?(object)
- diff_x = ($game_player.real_x - object.real_x).abs # 绝对值
- diff_y = ($game_player.real_y - object.real_y).abs # 绝对值
- width = 128 * 24 # size * tiles
- height = 128 * 19 # size * tiles
- return !((diff_x > width) or (diff_y > height))
- end
- end
- #===============================================================================
- # ■ Interpreter
- #
- # 执行事件命令的解释器
- #===============================================================================
- class Interpreter
- #-----------------------------------------------------------------------------
- # * 脚本
- #-----------------------------------------------------------------------------
- def command_355
- # script 设置第一行
- script = @list[@index].parameters[0] + "\n"
- # 循环
- loop do
- # 下一个事件指令在脚本 2 行以上的情况下
- if @list[@index+1].code == 655
- # 添加到 script 2 行以后
- script += @list[@index+1].parameters[0] + "\n"
- # 事件指令不在脚本 2 行以上的情况下
- else
- # 中断循环
- break
- end
- # 推进索引
- @index += 1
- end
- # 评价
- result = eval(script)
- #---------------------------------------------------------------------------
- # 返回值为 false 的情况下
- # NEW: the last word of the code mustnt be false!
- #---------------------------------------------------------------------------
- if result == false and script[script.length-6..script.length-2] != 'false'
- # 结束
- return false
- end
- # 继续
- return true
- end
- end
- #咳咳少了几行代码
- $antilag.max_cpu_utilization = 75
- $antilag.cpu_tolerance = 20
- $antilag.high_priority = true
- $antilag.event = true
- #自动回滚标准
- if $antilag.max_cpu_utilization>=100
- $antilag.max_cpu_utilization=70
- end # 分歧结束。
-
复制代码 如上是抢线程脚本,使用抢线程后,角色行走时远景图就会跟着一起移动……求教,应该如何修改抢线程脚本内的Spriteset_Map或是其他部分,才能兼容双远景图和抢线程? |
|