From 449c7a92ff74898dba9177219f69af0e68d36bce Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Tue, 5 Oct 2010 19:31:32 +0000 Subject: [PATCH] Particle density setting added to the video options git-svn-id: http://svn.net-core.org/repos/t-engine4@1424 51575b47-30f0-44d4-a5cc-537603b46e54 --- game/engines/default/engine/Particles.lua | 2 +- game/engines/default/engine/Store.lua | 4 ++-- .../default/engine/dialogs/GetQuantity.lua | 4 ++-- .../default/engine/dialogs/VideoOptions.lua | 21 +++++++++++-------- game/engines/default/engine/init.lua | 1 + src/particles.c | 9 +++++++- src/particles.h | 1 + 7 files changed, 27 insertions(+), 15 deletions(-) diff --git a/game/engines/default/engine/Particles.lua b/game/engines/default/engine/Particles.lua index 1475cde78d..574654b925 100644 --- a/game/engines/default/engine/Particles.lua +++ b/game/engines/default/engine/Particles.lua @@ -70,5 +70,5 @@ function _M:loaded() gl = self.__particles_gl[gl] self.update = fct - self.ps = core.particles.newEmitter(max or 1000, no_stop, def, gl) + self.ps = core.particles.newEmitter(max or 1000, no_stop, config.settings.particles_density or 100, def, gl) end diff --git a/game/engines/default/engine/Store.lua b/game/engines/default/engine/Store.lua index 1e35379f25..eea3c207ca 100644 --- a/game/engines/default/engine/Store.lua +++ b/game/engines/default/engine/Store.lua @@ -76,7 +76,7 @@ function _M:interact(who) local d; d = ShowStore.new("Store: "..self.name, store, inven, nil, nil, function(what, o, item) if what == "buy" then if o:getNumber() > 1 then - local q = GetQuantity.new(nil, nil, o:getNumber(), function(qty) self:doBuy(who, o, item, qty, d) end) + local q = GetQuantity.new(nil, nil, o:getNumber(), o:getNumber(), function(qty) self:doBuy(who, o, item, qty, d) end) game:registerDialog(q) else self:doBuy(who, o, item, 1, d) @@ -84,7 +84,7 @@ function _M:interact(who) else if o:getNumber() > 1 then local q - q = GetQuantity.new(nil, nil, o:getNumber(), function(qty) print("plop", qty) self:doSell(who, o, item, qty, d) end) + q = GetQuantity.new(nil, nil, o:getNumber(), o:getNumber(), function(qty) print("plop", qty) self:doSell(who, o, item, qty, d) end) game:registerDialog(q) else self:doSell(who, o, item, 1, d) diff --git a/game/engines/default/engine/dialogs/GetQuantity.lua b/game/engines/default/engine/dialogs/GetQuantity.lua index 8115b77a9a..faea8fb0fb 100644 --- a/game/engines/default/engine/dialogs/GetQuantity.lua +++ b/game/engines/default/engine/dialogs/GetQuantity.lua @@ -25,12 +25,12 @@ local Numberbox = require "engine.ui.Numberbox" module(..., package.seeall, class.inherit(Dialog)) -function _M:init(title, prompt, default, action) +function _M:init(title, prompt, default, max, action) self.action = action Dialog.init(self, title or "Quantity", 320, 110) - local c_box = Numberbox.new{title=prompt and (prompt..": ") or "", number=default or 0, chars=10, fct=function(text) self:okclick() end} + local c_box = Numberbox.new{title=prompt and (prompt..": ") or "", number=default or 0, max=max, chars=10, fct=function(text) self:okclick() end} self.c_box = c_box local ok = require("engine.ui.Button").new{text="Accept", fct=function() self:okclick() end} local cancel = require("engine.ui.Button").new{text="Cancel", fct=function() self:cancelclick() end} diff --git a/game/engines/default/engine/dialogs/VideoOptions.lua b/game/engines/default/engine/dialogs/VideoOptions.lua index f0c9c065a1..36f90febda 100644 --- a/game/engines/default/engine/dialogs/VideoOptions.lua +++ b/game/engines/default/engine/dialogs/VideoOptions.lua @@ -22,6 +22,7 @@ local Dialog = require "engine.ui.Dialog" local TreeList = require "engine.ui.TreeList" local Textzone = require "engine.ui.Textzone" local Separator = require "engine.ui.Separator" +local GetQuantity = require "engine.dialogs.GetQuantity" module(..., package.seeall, class.inherit(Dialog)) @@ -62,7 +63,7 @@ function _M:generateList() local i = 0 local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text="Display resolution."} - list[#list+1] = { zone=zone, name="Resolution", status=function(item) + list[#list+1] = { zone=zone, name="#GOLD##{bold}#Resolution#WHITE##{normal}#", status=function(item) return config.settings.window.size end, fct=function(item) local menu = require("engine.dialogs.DisplayResolution").new(function() self.c_list:drawItem(item) end) @@ -70,16 +71,18 @@ function _M:generateList() end,} local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text="Controls the particle effects density.\nThis option allows to change the density of the many particle effects in the game.\nIf the game is slow when displaying spell effects try to lower this setting.#WHITE#"} - list[#list+1] = { zone=zone, name="Particle effects density", status=function(item) - return tostring(config.settings.particles_density and "enabled" or "disabled") + list[#list+1] = { zone=zone, name="#GOLD##{bold}#Particle effects density#WHITE##{normal}#", status=function(item) + return tostring(config.settings.particles_density) end, fct=function(item) - - game:saveSettings("particles_density", ("particles_density = %s\n"):format(tostring(config.settings.particles_density))) - self.c_list:drawItem(item) + game:registerDialog(GetQuantity.new("Enter density", "From 0 to 100", config.settings.particles_density, 100, function(qty) + game:saveSettings("particles_density", ("particles_density = %d\n"):format(qty)) + config.settings.particles_density = qty + self.c_list:drawItem(item) + end)) end,} local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text="Activates antialiased texts.\nTexts will look nicer but it can be slower on some computers.\n\n#LIGHT_RED#You must restart the game for it to take effect.#WHITE#"} - list[#list+1] = { zone=zone, name="Antialiased texts", status=function(item) + list[#list+1] = { zone=zone, name="#GOLD##{bold}#Antialiased texts#WHITE##{normal}#", status=function(item) return tostring(core.display.getTextBlended() and "enabled" or "disabled") end, fct=function(item) local state = not core.display.getTextBlended() @@ -89,7 +92,7 @@ function _M:generateList() end,} local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text="Activates framebuffers.\nThis option allows for some special graphical effects.\nIf you encounter weird graphical glitches try to disable it.\n\n#LIGHT_RED#You must restart the game for it to take effect.#WHITE#"} - list[#list+1] = { zone=zone, name="Framebuffers", status=function(item) + list[#list+1] = { zone=zone, name="#GOLD##{bold}#Framebuffers#WHITE##{normal}#", status=function(item) return tostring(config.settings.fbo_active and "enabled" or "disabled") end, fct=function(item) config.settings.fbo_active = not config.settings.fbo_active @@ -98,7 +101,7 @@ function _M:generateList() end,} local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text="Activates OpenGL Shaders.\nThis option allows for some special graphical effects.\nIf you encounter weird graphical glitches try to disable it.\n\n#LIGHT_RED#You must restart the game for it to take effect.#WHITE#"} - list[#list+1] = { zone=zone, name="OpenGL Shaders", status=function(item) + list[#list+1] = { zone=zone, name="#GOLD##{bold}#OpenGL Shaders#WHITE##{normal}#", status=function(item) return tostring(config.settings.shaders_active and "enabled" or "disabled") end, fct=function(item) config.settings.shaders_active = not config.settings.shaders_active diff --git a/game/engines/default/engine/init.lua b/game/engines/default/engine/init.lua index 2a717bc3f0..fe4ae29dbd 100644 --- a/game/engines/default/engine/init.lua +++ b/game/engines/default/engine/init.lua @@ -53,6 +53,7 @@ music.volume = 60 aa_text = true fbo_active = true shaders_active = true +particles_density = 100 ]] for i, file in ipairs(fs.list("/settings/")) do if file:find(".cfg$") then diff --git a/src/particles.c b/src/particles.c index afcc007bb9..f5f99458bf 100644 --- a/src/particles.c +++ b/src/particles.c @@ -66,13 +66,17 @@ static int particles_new(lua_State *L) { int nb = luaL_checknumber(L, 1); bool no_stop = lua_toboolean(L, 2); - GLuint *t = (GLuint*)auxiliar_checkclass(L, "gl{texture}", 4); + int density = luaL_checknumber(L, 3); + GLuint *t = (GLuint*)auxiliar_checkclass(L, "gl{texture}", 5); int t_ref = luaL_ref(L, LUA_REGISTRYINDEX); int p_ref = luaL_ref(L, LUA_REGISTRYINDEX); particles_type *ps = (particles_type*)lua_newuserdata(L, sizeof(particles_type)); auxiliar_setclass(L, "core{particles}", -1); + ps->density = density; + nb = (nb * ps->density) / 100; + if (!nb) nb = 1; ps->nb = nb; ps->texture = *t; ps->texture_ref = t_ref; @@ -152,6 +156,9 @@ static int particles_emit(lua_State *L) particles_type *ps = (particles_type*)auxiliar_checkclass(L, "core{particles}", 1); int nb = luaL_checknumber(L, 2); + nb = (nb * ps->density) / 100; + if (!nb) nb = 1; + int i; for (i = 0; i < ps->nb; i++) { diff --git a/src/particles.h b/src/particles.h index 606ede9888..595364f713 100644 --- a/src/particles.h +++ b/src/particles.h @@ -39,6 +39,7 @@ typedef struct { int nb; int texture_ref; int generator_ref; + int density; bool no_stop; int base; -- GitLab