Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

2 Pages V   1 2 >  
Closed TopicStart new topic
> [Legacy] High Priority v1.1 XP/VX, Sets the Game.exe to High priority
Legacy
post Mar 25 2011, 07:11 AM
Post #1


B★RS Coding Ninja
Group Icon

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


if you encounter any issues, please let me know.


__________________________
Freelance Programmer (C#, C++, Ruby)
#onegameamonth


Have you seen the new Unity3D sections?..
Unity 3D Discussion
Unity Script Development
Unity Projects
Go to the top of the page
 
+Quote Post
   
Lurvid
post Mar 25 2011, 09:30 AM
Post #2


Level 8
Group Icon

Group: Revolutionary
Posts: 113
Type: Developer
RM Skill: Intermediate




Wow, this is great! My game is a lot less laggy now, and it even works with all the scripts I've pumped into my project. Thanks bro!


__________________________

Everybody look at my signature this meaningless website says I'm smart look at the size of my e-peen
Go to the top of the page
 
+Quote Post
   
Sailerius
post Mar 27 2011, 03:11 PM
Post #3


Blue Blue Glass Moon
Group Icon

Group: Revolutionary
Posts: 881
Type: Developer
RM Skill: Beginner




Is this really a good idea? It's generally considered bad practices to force your application to be high priority against the user's wishes.


__________________________
Go to the top of the page
 
+Quote Post
   
Legacy
post Mar 28 2011, 12:19 AM
Post #4


B★RS Coding Ninja
Group Icon

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?

@Lurvid

No problem happy.gif


__________________________
Freelance Programmer (C#, C++, Ruby)
#onegameamonth


Have you seen the new Unity3D sections?..
Unity 3D Discussion
Unity Script Development
Unity Projects
Go to the top of the page
 
+Quote Post
   
Holder
post Mar 28 2011, 04:16 AM
Post #5


Spoilers.
Group Icon

Group: Revolutionary
Posts: 4,203
Type: Developer
RM Skill: Advanced
Rev Points: 250




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.

Go to the top of the page
 
+Quote Post
   
Legacy
post Mar 28 2011, 05:35 AM
Post #6


B★RS Coding Ninja
Group Icon

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 happy.gif


__________________________
Freelance Programmer (C#, C++, Ruby)
#onegameamonth


Have you seen the new Unity3D sections?..
Unity 3D Discussion
Unity Script Development
Unity Projects
Go to the top of the page
 
+Quote Post
   
Rob_Riv
post Mar 28 2011, 05:42 AM
Post #7


Alignment: Neutral Good
Group Icon

Group: Revolutionary
Posts: 2,460
Type: Developer
RM Skill: Skilled




QUOTE (Holder @ Mar 28 2011, 01:16 PM) *
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
Go to the top of the page
 
+Quote Post
   
Legacy
post Mar 28 2011, 05:48 AM
Post #8


B★RS Coding Ninja
Group Icon

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.


__________________________
Freelance Programmer (C#, C++, Ruby)
#onegameamonth


Have you seen the new Unity3D sections?..
Unity 3D Discussion
Unity Script Development
Unity Projects
Go to the top of the page
 
+Quote Post
   
Kread-EX
post Mar 28 2011, 07:06 AM
Post #9


(=___=)/
Group Icon

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.

My blog.

Click here for my e-peen


Go to the top of the page
 
+Quote Post
   
Shadyone
post Mar 28 2011, 07:51 AM
Post #10


K@w411ii~desudesu:3<(^^)>s@$uk3Kun$0h0T~.~kyaaaa
Group Icon

Group: Revolutionary
Posts: 1,211
Type: Developer
RM Skill: Beginner
Rev Points: 20




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.


__________________________







Speedtest



ISML 2012

ARENA 01: [Elucia de Lute Ima] Kasugano Sora
ARENA 02: Gasai Yuno [Aragaki Ayase]
ARENA 03: Irisviel von Einzbern [Abstained] Haruna
ARENA 04: Shimada Minami [Iwasawa Masami]
ARENA 05: [Nakagawa Kanon] Kirishima Shōko
ARENA 06: [Fear Kubrick] Himeji Mizuki
ARENA 07: [Eucliwood Hellscythe] Kanzaki H. Aria
ARENA 08: Gokō Ruri (Kuroneko) [Makise Kurisu]
ARENA 09: [Yui] Victorique de Blois
ARENA 10: [Shiomiya Shiori] Mine Riko
ARENA 11: Mikazuki Yozora [Sakura Kyōko]
ARENA 12: Charlotte Dunois [Abstained] Yuzuriha Inori
ARENA 13: [Akemi Homura] Tōwa Erio
ARENA 14: Hasegawa Kobato [Kuroi Mato]
ARENA 15: [Kōsaka Kirino] Kashiwazaki Sena
ARENA 16: [Tachibana Kanade] Nakamura Yuri
ARENA 17: Suzutsuki Kanade [Haqua du Lot Herminium]
ARENA 18: [Honma Meiko] Konoe Subaru
ARENA 19: [Nagato Yuki, Asakura Ryōko] Misaka Mikoto, Shirai Kuroko
ARENA 20: [Hiiragi Kagami] Shiina Mafuyu
ARENA 21: Ichinose Kotomi [Sanzen'in Nagi]
ARENA 22: [Last Order] Hirasawa Ui
ARENA 23: Shirai Kuroko [Izumi Konata]
ARENA 24: [Nymph] Ikaros
ARENA 25: Konjiki no Yami [Holo]
ARENA 26: [Nakano Azusa] Tōsaka Rin
ARENA 27: [Misaka Mikoto] Hirasawa Yui
ARENA 28: [Suzumiya Haruhi] Saber
ARENA 29: C.C. [Asahina Mikuru]
ARENA 30: [Sakagami Tomoyo] Index L. Prohibitorum
ARENA 31: Akiyama Mio [Oshino Shinobu]
ARENA 32: [Aisaka Taiga] Louise Vallière
ARENA 33: [Sengoku Nadeko] Katsura Hinagiku
ARENA 34: [Nagato Yuki] Senjōgahara Hitagi
ARENA 35: [Shana] Illyasviel von Einzbern
ARENA 36: Hecate [Fujibayashi Kyō]
ARENA 37: Kotobuki Tsumugi [Furukawa Nagisa]
ARENA 38: [Kamina, Yoko Littner] Natsu Dragneel, Lisanna Strauss
Go to the top of the page
 
+Quote Post
   
Holder
post Mar 28 2011, 02:41 PM
Post #11


Spoilers.
Group Icon

Group: Revolutionary
Posts: 4,203
Type: Developer
RM Skill: Advanced
Rev Points: 250




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.

Go to the top of the page
 
+Quote Post
   
Sailerius
post Mar 28 2011, 04:19 PM
Post #12


Blue Blue Glass Moon
Group Icon

Group: Revolutionary
Posts: 881
Type: Developer
RM Skill: Beginner




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 happy.gif

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.


__________________________
Go to the top of the page
 
+Quote Post
   
Legacy
post Mar 29 2011, 04:27 AM
Post #13


B★RS Coding Ninja
Group Icon

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 sweat.gif

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 happy.gif

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.


__________________________
Freelance Programmer (C#, C++, Ruby)
#onegameamonth


Have you seen the new Unity3D sections?..
Unity 3D Discussion
Unity Script Development
Unity Projects
Go to the top of the page
 
+Quote Post
   
Night_Runner
post Apr 1 2011, 05:09 AM
Post #14


Level 50
Group Icon

Group: +Gold Member
Posts: 1,520
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 smile.gif

Anyway, I was bored to I made a window for you guys who want to ask the user!
CODE
#===============================================================================
# ~** [Legacy] High_Priority **~                                    
#-------------------------------------------------------------------------------
#  Author:      Legacy
#  Version:     1.0 - Edited
#  Build Date:  2011-03-05
#  Last Update: 2011-03-05
#===============================================================================


#==============================================================================
# ** 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 smile.gif


__________________________
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.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   
Legacy
post Apr 1 2011, 05:26 AM
Post #15


B★RS Coding Ninja
Group Icon

Group: Global Mod
Posts: 1,414
Type: Scripter
RM Skill: Advanced
Rev Points: 15




nice edit NR, ill add it to the first post happy.gif

EDIT:

i'll take a look into the threading method, that actually sounds like a good idea.


__________________________
Freelance Programmer (C#, C++, Ruby)
#onegameamonth


Have you seen the new Unity3D sections?..
Unity 3D Discussion
Unity Script Development
Unity Projects
Go to the top of the page
 
+Quote Post
   
Fixxxer4153
post Jul 26 2011, 04:51 PM
Post #16


Level 10
Group Icon

Group: Revolutionary
Posts: 155
Type: Developer
RM Skill: Beginner




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..."


Which Final Fantasy Character Are You?
Final Fantasy 7
Go to the top of the page
 
+Quote Post
   
Night_Runner
post Jul 26 2011, 10:52 PM
Post #17


Level 50
Group Icon

Group: +Gold Member
Posts: 1,520
Type: Scripter
RM Skill: Undisclosed




It's a feature; I figured that it would get annoying having to constantly click high priority every single time you launch the game...

Besides, it's saved in the Game.ini file, so the player can just open that up and change it if they regret their decision....


__________________________
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.

Most important guide ever: Newbie's Guide to Switches
Go to the top of the page
 
+Quote Post
   
Fixxxer4153
post Jul 27 2011, 10:15 AM
Post #18


Level 10
Group Icon

Group: Revolutionary
Posts: 155
Type: Developer
RM Skill: Beginner




Ah, okay. Just thought I'd check.
Its very nice, glad to have it.


__________________________
"Then it comes to be that the soothing light at the end of your tunnel... is just a freight train comin' your way..."


Which Final Fantasy Character Are You?
Final Fantasy 7
Go to the top of the page
 
+Quote Post
   
Legacy
post Nov 4 2011, 01:29 PM
Post #19


B★RS Coding Ninja
Group Icon

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. happy.gif


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



__________________________
Freelance Programmer (C#, C++, Ruby)
#onegameamonth


Have you seen the new Unity3D sections?..
Unity 3D Discussion
Unity Script Development
Unity Projects
Go to the top of the page
 
+Quote Post
   
diss
post Nov 5 2011, 09:00 AM
Post #20


Level 4
Group Icon

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.
Go to the top of the page
 
+Quote Post
   

2 Pages V   1 2 >
Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th May 2013 - 06:21 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker