Group: Global Mod
Posts: 1,414
Type: Scripter
RM Skill: Advanced
Rev Points: 15
High Priority - by Legacy Version 1.1
Description: its been awhile since i've done any scripting for the public, so i thought i'd start back from the simple, and work my way back up.
This script sets the Game.exe to "High" priority instead of the default "normal" priority.
Updated to include a VX version.
Credits: NightRunner - For adding function to read to game.ini file, to test if high priority is enabled.
Compatibility: no issues so far.
Screenshots: None needed
Instructions:
Place above main, and above any custom scripts. So, place under Scene_Debug.
Script:
XP Version 1.1
CODE
#=============================================================================== # ~** [Legacy] High_Priority **~ #------------------------------------------------------------------------------- # Author: Legacy # Version: 1.1 # Build Date: 2011-03-05 # Last Update: 2011-03-05 #------------------------------------------------------------------------------- # Changelog - # # * NightRunner - Added function to read to game.ini file, to test if # high priority is enabled. # #===============================================================================
#============================================================================== # ** Game_Priority #------------------------------------------------------------------------------ # This module contains the code to change the game's priority. #==============================================================================
module Game_Priority #-------------------------------------------------------------------------- # * Invariables #-------------------------------------------------------------------------- Set_Priority = Win32API.new('kernel32', 'SetPriorityClass', ['p', 'i'], 'i') Elevated_Priority_Text = "ElevatedPriority=" # As shown in the Game.ini file Default_Elevated_Priority = true # Default high priority? #-------------------------------------------------------------------------- # * Name : Elevated Priority # Info : Set the priority of the process # Author : Legacy # Call Info : One arguement boolean value, set high priority true or false. #--------------------------------------------------------------------------- def self.elevated_priority=(value) @elevated_priority = value if @elevated_priority Set_Priority.call(-1, 0x00000080) # High else Set_Priority.call(-1, 0x00000020) # Normal end end end
#============================================================================== # ** Scene_ChoosePriority #------------------------------------------------------------------------------ # This class let's the player decide whether to have high priority. #==============================================================================
class Scene_ChoosePriority #-------------------------------------------------------------------------- # * Main Processing #-------------------------------------------------------------------------- def initialize # Make system object $game_system = Game_System.new $data_system = load_data("Data/System.rxdata") end #-------------------------------------------------------------------------- # * Main Processing #-------------------------------------------------------------------------- def main # Set a flag whether to quit processing or not @self_active = true # Make title graphic @sprite = Sprite.new @sprite.bitmap = RPG::Cache.title($data_system.title_name) # Make the windows make_text_window make_selection_window # Transition the Graphics Graphics.transition(20) # Main Processing begin Graphics.update Input.update update end while @self_active # Freeze the graphics Graphics.freeze # Dispose of the windows dispose_windows end #-------------------------------------------------------------------------- # * Make Text WIndow #-------------------------------------------------------------------------- def make_text_window # Set variables for where to place the text window x = 160 y = 128 width = 320 height = 128 # Make the text window @text_window = Window_Base.new(x, y, width, height) # Make the bitmap (to draw the text on) @text_window.contents = Bitmap.new(width - 32, height - 32) # Find out if the default is high or normal priority default = Game_Priority::Default_Elevated_Priority ? 'High' : 'Normal' # Setup the text to show text = ["Would you like to play this game", "in elevated priority mode?", "(#{default} is recommended)"] # For every line of text, draw it on the window for i in 0...text.size line = text[i] @text_window.contents.draw_text(0, i * 32, width - 32, 32, line, 1) end end #-------------------------------------------------------------------------- # * Make Selection Window #-------------------------------------------------------------------------- def make_selection_window options = ['High Priority', 'Normal Priority'] @selection_window = Window_Command.new(160, options) @selection_window.x = 320 - @selection_window.width / 2 @selection_window.y = @text_window.y + @text_window.height end #-------------------------------------------------------------------------- # * Frame update #-------------------------------------------------------------------------- def update # Update the important windows @selection_window.update # If the C input was triggered if Input.trigger?(Input::C) # Set this window to dispose @self_active = false # Read if the player selected high/normal priority high_priority = @selection_window.index == 0 # Set the priority Game_Priority.elevated_priority = high_priority # Save the priority back to the game.ini file gameini = File.open('Game.ini', 'a') elevatedPrioText = Game_Priority::Elevated_Priority_Text gameini.write("\n#{elevatedPrioText}#{high_priority}\n") gameini.close end end #-------------------------------------------------------------------------- # * Dispose of Windows #-------------------------------------------------------------------------- def dispose_windows @text_window.dispose @selection_window.dispose end end
#============================================================================== # ** Read from the Game.ini file #------------------------------------------------------------------------------ # This section of code checks the Game.ini file to see if the # priority flag has been set. #============================================================================== # Read the contents of the Game.ini file gameini = File.open('Game.ini', 'r+') gameini_text = gameini.read gameini.close # Load what text to look for in the Game.ini file elevatedPrioText = Game_Priority::Elevated_Priority_Text # Check to see if the Game.ini has the ElevatedPriority flag if (gameini_text =~ /#{elevatedPrioText}(true|false)/) != nil # If it did, set it to what was found Game_Priority.elevated_priority = ($1 == "true") else # If it didn't have the priority flag: let the player select Scene_ChoosePriority.new.main end
VX Version 1.2
CODE
#=============================================================================== # ~** [Legacy] High_Priority vx **~ #------------------------------------------------------------------------------- # Author: Legacy # Version: 1.2 # Build Date: 2011-03-05 # Last Update: 2011-11-04 #------------------------------------------------------------------------------- # Changelog - # # * NightRunner - Added function to read to game.ini file, to test if # high priority is enabled. # #===============================================================================
#============================================================================== # ** Game_Priority #------------------------------------------------------------------------------ # This module contains the code to change the game's priority. #==============================================================================
module Game_Priority #-------------------------------------------------------------------------- # * Invariables #-------------------------------------------------------------------------- Set_Priority = Win32API.new('kernel32', 'SetPriorityClass', ['p', 'i'], 'i') Elevated_Priority_Text = "ElevatedPriority=" # As shown in the Game.ini file Default_Elevated_Priority = true # Default high priority? #-------------------------------------------------------------------------- # * Name : Elevated Priority # Info : Set the priority of the process # Author : Legacy # Call Info : One arguement boolean value, set high priority true or false. #--------------------------------------------------------------------------- def self.elevated_priority=(value) @elevated_priority = value if @elevated_priority Set_Priority.call(-1, 0x00000080) # High else Set_Priority.call(-1, 0x00000020) # Normal end end end
#============================================================================== # ** Scene_ChoosePriority #------------------------------------------------------------------------------ # This class let's the player decide whether to have high priority. #==============================================================================
class Scene_ChoosePriority #-------------------------------------------------------------------------- # * Main Processing #-------------------------------------------------------------------------- def initialize # Make system object $game_system = Game_System.new $data_system = load_data("Data/System.rvdata") end #-------------------------------------------------------------------------- # * Main Processing #-------------------------------------------------------------------------- def main # Set a flag whether to quit processing or not @self_active = true # Make title graphic @sprite = Sprite.new @sprite.bitmap = Cache.system("Title") # Make the windows make_text_window make_selection_window # Transition the Graphics Graphics.transition(20) # Main Processing begin Graphics.update Input.update update end while @self_active # Freeze the graphics Graphics.freeze # Dispose of the windows dispose_windows end #-------------------------------------------------------------------------- # * Make Text WIndow #-------------------------------------------------------------------------- def make_text_window # Set variables for where to place the text window x = 80 y = 128 width = 400 height = 128 # Make the text window @text_window = Window_Base.new(x, y, width, height) # Make the bitmap (to draw the text on) @text_window.contents = Bitmap.new(width - 32, height - 32) # Find out if the default is high or normal priority default = Game_Priority::Default_Elevated_Priority ? 'High' : 'Normal' # Setup the text to show text = ["Would you like to play this game", "in elevated priority mode?", "(#{default} is recommended)"] # For every line of text, draw it on the window for i in 0...text.size line = text[i] @text_window.contents.draw_text(0, i * 32, width - 32, 32, line, 1) end end #-------------------------------------------------------------------------- # * Make Selection Window #-------------------------------------------------------------------------- def make_selection_window options = ['High Priority', 'Normal Priority'] @selection_window = Window_Command.new(160, options) @selection_window.x = 260 - @selection_window.width / 2 @selection_window.y = @text_window.y + @text_window.height end #-------------------------------------------------------------------------- # * Frame update #-------------------------------------------------------------------------- def update # Update the important windows @selection_window.update # If the C input was triggered if Input.trigger?(Input::C) # Set this window to dispose @self_active = false # Read if the player selected high/normal priority high_priority = @selection_window.index == 0 # Set the priority Game_Priority.elevated_priority = high_priority # Save the priority back to the game.ini file gameini = File.open('Game.ini', 'a') elevatedPrioText = Game_Priority::Elevated_Priority_Text gameini.write("\n#{elevatedPrioText}#{high_priority}\n") gameini.close end end #-------------------------------------------------------------------------- # * Dispose of Windows #-------------------------------------------------------------------------- def dispose_windows @text_window.dispose @selection_window.dispose end end
#============================================================================== # ** Read from the Game.ini file #------------------------------------------------------------------------------ # This section of code checks the Game.ini file to see if the # priority flag has been set. #============================================================================== # Read the contents of the Game.ini file gameini = File.open('Game.ini', 'r+') gameini_text = gameini.read gameini.close # Load what text to look for in the Game.ini file elevatedPrioText = Game_Priority::Elevated_Priority_Text # Check to see if the Game.ini has the ElevatedPriority flag if (gameini_text =~ /#{elevatedPrioText}(true|false)/) != nil # If it did, set it to what was found Game_Priority.elevated_priority = ($1 == "true") else # If it didn't have the priority flag: let the player select Scene_ChoosePriority.new.main end
Group: Global Mod
Posts: 1,414
Type: Scripter
RM Skill: Advanced
Rev Points: 15
@Sailerius
i've never ran into any problems forcing the application to run in high priority, i've only had good things come from it. But, if you find any probl;em with it, can you let me know?
This is something I'll certainly be using, I can't really see anything else being ran at the same time apart from a music program or possibly the occasional video capture program.
__________________________
I'm running the Great North Run in September in aid of NACC. A condition my wife has in it's severe form. Please sponsor me with whatever you can, thank you. If you'd like to help spread the word please share the image and link to my fundraising page.
Group: Global Mod
Posts: 1,414
Type: Scripter
RM Skill: Advanced
Rev Points: 15
I've never ran into any problems whilst running the Game in high priority, whilst listening to music, and doing various other things. And i dont exactly have a high-end computer
This is something I'll certainly be using, I can't really see anything else being ran at the same time apart from a music program or possibly the occasional video capture program.
What about an internet browser? and chat applications? and then Microsoft Word documents? Or am I the only one? ^^
__________________________
“Countless stories could be told of the kings, knights and adventurers of the world of LURRA, stories of HOPE, of HONOUR, and of VALIANCE."
---------------------------------------------- Unknown, The History of Lurra, Prologue
Group: Global Mod
Posts: 1,414
Type: Scripter
RM Skill: Advanced
Rev Points: 15
I can run all my applications normally on my computer, whilst having the game running. I've seen no lagging effects on any of my applications. But if you notice a problem with any lagging applications whilst the game is running please let me know, and ill see if i can make some sort of fix for that.
Group: +Gold Member
Posts: 4,136
Type: Scripter
RM Skill: Undisclosed
You can't really make a "fix" because you forced the executable to run in high priority, Legacy. ^^ What you can do, however (and probably should do), is to add a line in the Game.ini file to allow the player to switch back to normal priority.
__________________________
FRACTURE - a SMT inspired game (demo) made by Rhyme, Karsuman and me. Weep and ragequit.
High priority is good and all, I'll use it but definately needs to let the the user decide whether he wants high priority, coz it sometimes tends to lag.
Isn't there a way to create a pop-up window, by doing it that way you could then ask the user if they'd like to or not. Suppose the downside to that is that it may end up getting annoying having that pop up every time...
__________________________
I'm running the Great North Run in September in aid of NACC. A condition my wife has in it's severe form. Please sponsor me with whatever you can, thank you. If you'd like to help spread the word please share the image and link to my fundraising page.
i've never ran into any problems forcing the application to run in high priority, i've only had good things come from it. But, if you find any probl;em with it, can you let me know?
@Lurvid
No problem
You're misunderstanding me. You *never* force an application to run on high priority without the user's consent. It can have negative repercussions and it's generally frowned upon. Allow the user to change to high priority but don't do it without asking.
Group: Global Mod
Posts: 1,414
Type: Scripter
RM Skill: Advanced
Rev Points: 15
QUOTE (Kread-EX @ Mar 28 2011, 04:06 PM)
You can't really make a "fix" because you forced the executable to run in high priority, Legacy. ^^ What you can do, however (and probably should do), is to add a line in the Game.ini file to allow the player to switch back to normal priority.
Ah, yeah, i should have done that, ill work on that now
QUOTE (Sailerius @ Mar 29 2011, 01:19 AM)
QUOTE (Legacy @ Mar 28 2011, 12:19 AM)
@Sailerius
i've never ran into any problems forcing the application to run in high priority, i've only had good things come from it. But, if you find any probl;em with it, can you let me know?
@Lurvid
No problem
You're misunderstanding me. You *never* force an application to run on high priority without the user's consent. It can have negative repercussions and it's generally frowned upon. Allow the user to change to high priority but don't do it without asking.
Sorry for misunderstanding you, i understand what your saying now, ill have it like Kread has said, to allow the user to change it to high by changing the "game.ini" file.
Group: +Gold Member
Posts: 1,528
Type: Scripter
RM Skill: Undisclosed
Couldn't you have a thread in the background, and if the CPU usage gets too high, return the priority of the game back to normal? If you did that, it would reduce the lag of other programs, and I"d count that as a fix
Anyway, I was bored to I made a window for you guys who want to ask the user!
#============================================================================== # ** Game_Priority #------------------------------------------------------------------------------ # This module contains the code to change the game's priority. #==============================================================================
module Game_Priority #-------------------------------------------------------------------------- # * Invariables #-------------------------------------------------------------------------- Set_Priority = Win32API.new('kernel32', 'SetPriorityClass', ['p', 'i'], 'i') Elevated_Priority_Text = "ElevatedPriority=" # As shown in the Game.ini file Default_Elevated_Priority = true # Default high priority? #-------------------------------------------------------------------------- # * Name : Elevated Priority # Info : Set the priority of the process # Author : Legacy # Call Info : One arguement boolean value, set high priority true or false. #--------------------------------------------------------------------------- def self.elevated_priority=(value) @elevated_priority = value if @elevated_priority Set_Priority.call(-1, 0x00000080) # High else Set_Priority.call(-1, 0x00000020) # Normal end end end
#============================================================================== # ** Scene_ChoosePriority #------------------------------------------------------------------------------ # This class let's the player decide whether to have high priority. #==============================================================================
class Scene_ChoosePriority #-------------------------------------------------------------------------- # * Main Processing #-------------------------------------------------------------------------- def initialize # Make system object $game_system = Game_System.new $data_system = load_data("Data/System.rxdata") end #-------------------------------------------------------------------------- # * Main Processing #-------------------------------------------------------------------------- def main # Set a flag whether to quit processing or not @self_active = true # Make title graphic @sprite = Sprite.new @sprite.bitmap = RPG::Cache.title($data_system.title_name) # Make the windows make_text_window make_selection_window # Transition the Graphics Graphics.transition(20) # Main Processing begin Graphics.update Input.update update end while @self_active # Freeze the graphics Graphics.freeze # Dispose of the windows dispose_windows end #-------------------------------------------------------------------------- # * Make Text WIndow #-------------------------------------------------------------------------- def make_text_window # Set variables for where to place the text window x = 160 y = 128 width = 320 height = 128 # Make the text window @text_window = Window_Base.new(x, y, width, height) # Make the bitmap (to draw the text on) @text_window.contents = Bitmap.new(width - 32, height - 32) # Find out if the default is high or normal priority default = Game_Priority::Default_Elevated_Priority ? 'High' : 'Normal' # Setup the text to show text = ["Would you like to play this game", "in elevated priority mode?", "(#{default} is recommended)"] # For every line of text, draw it on the window for i in 0...text.size line = text[i] @text_window.contents.draw_text(0, i * 32, width - 32, 32, line, 1) end end #-------------------------------------------------------------------------- # * Make Selection Window #-------------------------------------------------------------------------- def make_selection_window options = ['High Priority', 'Normal Priority'] @selection_window = Window_Command.new(160, options) @selection_window.x = 320 - @selection_window.width / 2 @selection_window.y = @text_window.y + @text_window.height end #-------------------------------------------------------------------------- # * Frame update #-------------------------------------------------------------------------- def update # Update the important windows @selection_window.update # If the C input was triggered if Input.trigger?(Input::C) # Set this window to dispose @self_active = false # Read if the player selected high/normal priority high_priority = @selection_window.index == 0 # Set the priority Game_Priority.elevated_priority = high_priority # Save the priority back to the game.ini file gameini = File.open('Game.ini', 'a') elevatedPrioText = Game_Priority::Elevated_Priority_Text gameini.write("\n#{elevatedPrioText}#{high_priority}\n") gameini.close end end #-------------------------------------------------------------------------- # * Dispose of Windows #-------------------------------------------------------------------------- def dispose_windows @text_window.dispose @selection_window.dispose end end
#============================================================================== # ** Read from the Game.ini file #------------------------------------------------------------------------------ # This section of code checks the Game.ini file to see if the # priority flag has been set. #============================================================================== # Read the contents of the Game.ini file gameini = File.open('Game.ini', 'r+') gameini_text = gameini.read gameini.close # Load what text to look for in the Game.ini file elevatedPrioText = Game_Priority::Elevated_Priority_Text # Check to see if the Game.ini has the ElevatedPriority flag if (gameini_text =~ /#{elevatedPrioText}(true|false)/) != nil # If it did, set it to what was found Game_Priority.elevated_priority = ($1 == "true") else # If it didn't have the priority flag: let the player select Scene_ChoosePriority.new.main end
It isn't intrusive, as it only asks once, but it isn't invasive, as it actually asks. And if you change your mind, you can go in to the Game.ini and change it there
__________________________
K.I.S.S. Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.
This is really nice. For awhile I was concerned with the lag of a specific map in my project, but this seems to help it a lot. Not sure exactly why that specific map lags so much, but it does. As long as people are smart enough to allow it to run in high priority, they'll experience much more fluidity in my project. The ones who refuse, well, they'll just have to deal with the lag.
I've noticed that for some reason it only brings up the option box the first time the game is run, after that it automatically runs in the priority mode selected initially. Was that an intentional thing or is it supposed to bring it up every time?
Sorry if I'm necroposting, but I thought I'd point that out.
__________________________
"Then it comes to be that the soothing light at the end of your tunnel... is just a freight train comin' your way..."
Group: Global Mod
Posts: 1,414
Type: Scripter
RM Skill: Advanced
Rev Points: 15
I've now updated and include a VX version. Now the VX users can experience the benefits that this script gives.
VX Version 1.2
CODE
#=============================================================================== # ~** [Legacy] High_Priority vx **~ #------------------------------------------------------------------------------- # Author: Legacy # Version: 1.2 # Build Date: 2011-03-05 # Last Update: 2011-11-04 #------------------------------------------------------------------------------- # Changelog - # # * NightRunner - Added function to read to game.ini file, to test if # high priority is enabled. # #===============================================================================
#============================================================================== # ** Game_Priority #------------------------------------------------------------------------------ # This module contains the code to change the game's priority. #==============================================================================
module Game_Priority #-------------------------------------------------------------------------- # * Invariables #-------------------------------------------------------------------------- Set_Priority = Win32API.new('kernel32', 'SetPriorityClass', ['p', 'i'], 'i') Elevated_Priority_Text = "ElevatedPriority=" # As shown in the Game.ini file Default_Elevated_Priority = true # Default high priority? #-------------------------------------------------------------------------- # * Name : Elevated Priority # Info : Set the priority of the process # Author : Legacy # Call Info : One arguement boolean value, set high priority true or false. #--------------------------------------------------------------------------- def self.elevated_priority=(value) @elevated_priority = value if @elevated_priority Set_Priority.call(-1, 0x00000080) # High else Set_Priority.call(-1, 0x00000020) # Normal end end end
#============================================================================== # ** Scene_ChoosePriority #------------------------------------------------------------------------------ # This class let's the player decide whether to have high priority. #==============================================================================
class Scene_ChoosePriority #-------------------------------------------------------------------------- # * Main Processing #-------------------------------------------------------------------------- def initialize # Make system object $game_system = Game_System.new $data_system = load_data("Data/System.rvdata") end #-------------------------------------------------------------------------- # * Main Processing #-------------------------------------------------------------------------- def main # Set a flag whether to quit processing or not @self_active = true # Make title graphic @sprite = Sprite.new @sprite.bitmap = Cache.system("Title") # Make the windows make_text_window make_selection_window # Transition the Graphics Graphics.transition(20) # Main Processing begin Graphics.update Input.update update end while @self_active # Freeze the graphics Graphics.freeze # Dispose of the windows dispose_windows end #-------------------------------------------------------------------------- # * Make Text WIndow #-------------------------------------------------------------------------- def make_text_window # Set variables for where to place the text window x = 80 y = 128 width = 400 height = 128 # Make the text window @text_window = Window_Base.new(x, y, width, height) # Make the bitmap (to draw the text on) @text_window.contents = Bitmap.new(width - 32, height - 32) # Find out if the default is high or normal priority default = Game_Priority::Default_Elevated_Priority ? 'High' : 'Normal' # Setup the text to show text = ["Would you like to play this game", "in elevated priority mode?", "(#{default} is recommended)"] # For every line of text, draw it on the window for i in 0...text.size line = text[i] @text_window.contents.draw_text(0, i * 32, width - 32, 32, line, 1) end end #-------------------------------------------------------------------------- # * Make Selection Window #-------------------------------------------------------------------------- def make_selection_window options = ['High Priority', 'Normal Priority'] @selection_window = Window_Command.new(160, options) @selection_window.x = 260 - @selection_window.width / 2 @selection_window.y = @text_window.y + @text_window.height end #-------------------------------------------------------------------------- # * Frame update #-------------------------------------------------------------------------- def update # Update the important windows @selection_window.update # If the C input was triggered if Input.trigger?(Input::C) # Set this window to dispose @self_active = false # Read if the player selected high/normal priority high_priority = @selection_window.index == 0 # Set the priority Game_Priority.elevated_priority = high_priority # Save the priority back to the game.ini file gameini = File.open('Game.ini', 'a') elevatedPrioText = Game_Priority::Elevated_Priority_Text gameini.write("\n#{elevatedPrioText}#{high_priority}\n") gameini.close end end #-------------------------------------------------------------------------- # * Dispose of Windows #-------------------------------------------------------------------------- def dispose_windows @text_window.dispose @selection_window.dispose end end
#============================================================================== # ** Read from the Game.ini file #------------------------------------------------------------------------------ # This section of code checks the Game.ini file to see if the # priority flag has been set. #============================================================================== # Read the contents of the Game.ini file gameini = File.open('Game.ini', 'r+') gameini_text = gameini.read gameini.close # Load what text to look for in the Game.ini file elevatedPrioText = Game_Priority::Elevated_Priority_Text # Check to see if the Game.ini has the ElevatedPriority flag if (gameini_text =~ /#{elevatedPrioText}(true|false)/) != nil # If it did, set it to what was found Game_Priority.elevated_priority = ($1 == "true") else # If it didn't have the priority flag: let the player select Scene_ChoosePriority.new.main end
Group: Member
Posts: 49
Type: Event Designer
RM Skill: Advanced
would it work if you set the game to high priority manually in task manager? want to know if it has the same effect as the script. im guessing so but i want to verify.