Jump to content

Averice

Members
  • Posts

    36
  • Joined

  • Last visited

Everything posted by Averice

  1. Averice

    s47

  2. If you look in what are you working on thread I have been using perlin noise for terrain generation using blocks and pure Lua, would work the same using a prefab and instancing it.
  3. I haven't run it either but by the sounds of it they're talking about some sort of visibility meter that knows when you're being lit up by a light source.
  4. Probably is, It's from the unity asset store.
  5. Woo adding caves in the terrain generation, still very early.
  6. Polygon fill would be great it means I could port my gui to be rendered in 3d space easily!
  7. As a side project I've started working on procedural voxel terrain generation, it's got the basics of a chunk system, and perlin noise. Here's a picture of 1 generated chunk.
  8. I can add an onrelease mechanic to this tomorrow as I'm on my phone right now and typing code is difficult on this. It's not too hard just an extra variable for the loop on each key.
  9. I think I posted this module on the forums in order to help someone a few weeks ago, but I thought It'd get more use if I created a blog post so it doesn't get diluted down in the forums. I've written this event module to make it easy to add keyboard and mouse button binds and it's come in handy to me for quite a few little scripts. Once again excuse the poor spacing as copy and paste here seems to remove my tabs. event.lua -- Event module written by Averice event = {} event.inputBinds = {} event.mouseBinds = {} function event.CheckInput() local succ, err; for key,tab in pairs(event.inputBinds) do if( App.window:KeyHit(key) ) then for k, v in pairs(tab) do if( not v.Held ) then succ, err = pcall(v.Func, unpack(v.Args)); if not succ then print("Event Error[Key]["..k.."]: "..err); end end end end if( App.window:KeyDown(key) ) then for k, v in pairs(tab) do if( v.Held ) then succ, err = pcall(v.Func, unpack(v.Args)); if not succ then print("Event Error[Key]["..k.."]: "..err); end end end end end for but, tab in pairs(event.mouseBinds) do if( App.window:MouseDown(but) ) then for k, v in pairs(tab) do succ, err = pcall(v.Func, unpack(v.Args)); if not succ then print("Event Error[Mouse]["..k.."]: "..err); end end end end end function event.AddInputBind(key, name, held, func, ...) local newInput = { Func = func, Args = {...}, Held = held or false } event.inputBinds[key] = event.inputBinds[key] or {}; event.inputBinds[key][name] = newInput; end function event.AddMouseBind(but, name, func, ...) local newInput = { Func = func, Args = {...} } event.mouseBinds[but] = event.mouseBinds[but] or {} event.mouseBinds[but][name] = newInput; end function event.RemoveInputBind(key, name) if( event.inputBinds[key] and event.inputBinds[key][name] ) then event.inputBinds[key][name] = nil; end end function event.RemoveMouseBind(but, name) if( event.mouseBinds[but] and event.mouseBinds[but][name] ) then event.mouseBinds[but][name] = nil; end end It's usage is really straight forward, you import the script, and in your App.loop you'll put event.CheckInput(); This will check for your binds and run them if needed so you don't have to fill your App.loop with key binds. To add a keyboard bind "event.AddInputBind(key, name, held, function, args); local function printStuff(...) print("Hello", ...); end event.AddInputBind(Key.A, "RandomName", false, printStuff, "How", "are", "you") -- varargs once again. --when the A key is pushed it should output, "Hello How are you"; -- if 'held' is true it will keep printing while it's held. --To remove it we use it's name and key. event.RemoveInputBind(Key.A, "RandomName"); -- Mouse bind functions are the same, just use event.AddMouseBind and event.RemoveMouseBind -- mouse bind functions are considered always held. Add a check to your function if you only -- want it done per click. A quick snippet that I use in my splash screen with my StateManager module to cancel the splash if escape is pushed. event.AddInputBind(Key.Escape, "__SHARDSPLASH", false, function() StateManager:Pop() end);
  10. debug.traceback is what you want.
  11. Menu is slowly getting there.
  12. SplashScreen is an instance of CState not a new derivative class, I know semi colons aren't needed just a habit that I don't see the need in breaking. I try to make these modules self contained, so any errors are reported to the user instead of crashing the game, CStateManager checks if a CState is being pushed onto the stack, if it's not a CState it isn't allowed. The inheritance in my class module is used to have base classes with inherited values, whereas the SplashScreen in this example is just a class instance with modified public methods ( I know they're all public being Lua since we can't privatize them without a workaround with the standard class metatable ) It would still work extending instead of instancing but most states will not be even remotely similar so inheriting values we won't use wouldn't be wise.
  13. I released an OOP class sytem for leadwerks last time this time I'm going to post my StateManager class which I use to control all the gamestates for the game I am working on. If you don't know what a Statemanager is or what my interpretation of one is I'll run through it quickly. Generally speaking it's just a stack full of 'states' each state has a list of functions with identical names but different internal functionality, the game will call these functions but ONLY for the active state, say your game has a Draw function but you want a splash screen with a Draw function, you'll separate these into different States for the stack, now when your splash state is active only the splash's Draw function will be called. State stacks almost always run [L]ast n [F]irst [O]ut, so the last state you push onto the stack will be the one the game starts using, so to have a splash screen -> menu -> game order in your stack you would push the game onto the stack first, the menu second and the splash last so that the splash is the first thing the end user sees. Enough ramblings let me post some code. statemanager.lua requires the class scripts. class "CStateManager"; function CStateManager:Init() self.States = {} end function CStateManager:Push(state, init) if( ctype(state) == "CState" ) then self.States[#self.States+1] = state; if( init ) then if( self.States[#self.States-1] and self.States[#self.States-1].isinit ) then self.States[#self.States-1]:Shutdown(); self.States[#self.States-1].isinit = false; end self.States[#self.States]:Init(App.context); self.States[#self.States].isinit = true; end else print("StateManager: CStateManager.Push expected CState got: "..ctype(state)); end end function CStateManager:InitCurrentState() if( self.States[1] and not self.States[#self.States].isinit ) then self.States[#self.States]:Init(App.context); self.States[#self.States].isinit = true; end end function CStateManager:Pop() if( self.States[1] ) then if( self.States[#self.States].isinit ) then self.States[#self.States].isinit = false; self.States[#self.States]:Shutdown(); end local oldState = self.States[#self.States]; self.States[#self.States] = nil; self:InitCurrentState(); return oldState; end print("StateManager: Called CStateManager.Pop with empty stack"); end function CStateManager:GetAll() return self.States end function CStateManager:GetActive() if( self.States[1] and self.States[#self.States].isinit ) then return self.States[#self.States]; end print("StateManager: Called CStateManager.GetActive with no running states"); end function CStateManager:Pause(state) if( ctype(state) == "CState" ) then state.paused = true; end end function CStateManager:Resume(state) if( ctype(state) == "CState" ) then state.paused = false; end end function CStateManager:IsPaused(state) if( ctype(state) == "CState" ) then return state.paused; end end function CStateManager:Call(func, ...) if( self.States[1] and self.States[#self.States].isinit and not self.States[#self.States].paused ) then if( self.States[#self.States][func] ) then self.States[#self.States][func](self.States[#self.States], ...); end end end state.lua -- Tiny file this one. really just a declaration and a nilfix file. class "CState"; function CState:Init() end function CState:Shutdown() end Example useage. -- Our splash screen. SplashScreen = new "CState" function SplashScreen:Init() self.Something = "HELLO"; end function SplashScreen:Think() self.Something = self.Something.."O"; end function SplashScreen:Draw() App.context:DrawText(self.Something, 100, 100); end -- Now something else. Random = new "CState" function Random:Draw() App.context:DrawText("Second State", 100, 200); end -- Now in our main file to initialize out statemanager and load our states. function App:Start() StateManager = new "CStateManager"; StateManager:Push(Random); -- Remember this goes before the splash so we see it AFTER the splash StateManager:Push(SplashScreen, true); the true means we want to initialize this, as it's the last state being pushed we may aswell tell the statemanager we are ready to begin. end function App:Loop() StateManager:Call("Think") -- Can name your functions anything, Init and Shutdown are always the same though. StateManager:Call("Draw", "some", "arguments", "here", "if", "you", "want"); end To remove the current state from the stack and initialize the next, we use StateManager:Pop(); I hope people get some use out of this, and I hope I've explained it nice enough.
  14. Averice

    GUI

    http://www.leadwerks.com/werkspace/blog/154/entry-1390-more-gui-work/ I'm working on one as I write my game it's independent of all game code bar my event module which can easily be packaged with it, it's not far from completion.
  15. Thanks for the feedback everyone, I'll post a new picture once I get some more stuff happening in the scene to avoid posting the same scene 4 times haha. Good eye panther, the seats were out by 1cm, no I didn't make the models, I originally started this project in unity and had bought the model pack from the asset store so I just dropped them into Leadwerks and continued using them it was a pretty seamless drag and drop and they were able to be used which was nice, the only thing I had to do was re-add the materials to them which took about 5 minutes. The unity asset store has some really nice content that is compatible with Leadwerks( am I allowed to say that? ), some model packs have their models as a U3dMesh which for some reason puts the pieces out of alignment in Leadwerks but it's as simple as opening blender and using the Leadwerks exporter instead of the usual .fbx exporter and they're fine to use again.
  16. More menu background map progress, I plan to have it as a live background map so you'll see AI walking around doing their jobs and **** nothing major just something to pop out and show it's an actual map not just a picture in the background. Need some help deciding, Bloom or no bloom Note this is only for a menu background, not an actual gameplay map.
  17. You could replace all _G mentions with a local table, although that would be quite messy and not make much sense? If you could explain to me what it is you're trying to do with it I might be able to come up with a neater solution.
  18. Passing them as a string is needed as it manually grabs the class from the global environment. It doesn't need to be that way but I did it for uniformity because the class () function does require string names and theres no getting around that.
  19. So I've got a few of these little helper modules I've written while making my game, I figured I needed a place to post them so others can get some use from it, I'll be selective with what I release as some of them I would like to keep private but everytime I get a spare moment I'll try to write up a blog post with a new module release and how it's used. So anyone familiar with OOP will hopefully get some use from this module, Lua already has a semi-OOP system with it's 'metatables' and this module just extends those to be used in a class system with inheritance. -- This is the definition of the system, only a small file but it does a lot. class.lua -- Class system written by Averice _shardClass = {} _shardClass.__index = _shardClass; function class(nme) if( _G[nme] ) then print("Class: "..nme.." already exists."); return; end _G[nme] = {} setmetatable(_G[nme], _shardClass) _G[nme].istype = nme; return _G[nme]; end -- Really no reason for the shardClass metatable but it provides nice looking functionality -- class "CAnimatedEntity" : extends "CBaseEntity" <-- is now correct syntax function _shardClass:extends(superclass) if( _G[superclass] ) then self.parent = superclass; self.__index = _G[superclass]; end end function new(class) if( _G[class] ) then local newClass = {} setmetatable(newClass, _G[class]); for k, v in pairs(_G[class]) do newClass[k] = v; -- For some reason metamethods weren't being accessed properly, here's a hacky fix. end if( newClass.Init ) then newClass:Init(); end return newClass; end print("Class: "..class.." does not exist."); end function ctype(class) return class.istype or type(class); end Alright, if your hoping to use this and know OOP programming the above should be self-explanatory. Simple put to define a new class you do this. class "MyClass"; To define a class that inherits from another you do this. class "MySecondClass" : extends "MyClass"; To create a new instance of a class you do this. my_class_instance = new "MySecondClass"; If there is an 'Init()' function it will be called automatically when a new instance of the class is created. Here is an example. class "ExampleClass"; function ExampleClass:Init() self.Number = 10; end function ExampleClass:SimpleFunction() print(self.Number); end class "NewExampleClass" : extends "ExampleClass"; function NewExampleClass:Init() self.Number = 15; end -- Now we create an instance. MyClass = new "NewExampleClass"; MyClass:SimpleFunction() -- notice this function was inherited from "ExampleClass" not "NewExampleClass" -- will print 15;
  20. Go right ahead, would be good for others to get some use from it too. Alright I've decided to post some modules on my leadwerks.com blog, when I get spare time I'll try to post more of them with some usage guides. http://www.leadwerks.com/werkspace/blog/154-lua-is-better-than-you-think/
  21. I wrote a quick event binding module in lua for the game I'm working on, all you have to do is import this file and add event.CheckInput() in your loop somewhere. This solves the problem of leaving unchecked keys in the event and also allows you to add more functionality to a single key check instead of adding it all in one massive loop in one file. http://pastebin.com/yQTC6BQP For some reason I can't paste the code here because it won't copy tabs and looks ugly Usage is quiet simple. -- keyboard binds. event.AddInputBind(key, name, held, func, ...) -- Key code, Unique Name, Run on key held?, function, function args event.AddInputBind(Key.A, "unique_name_here", true, print, "hello", "leadwerks", "community"); -- mouse binds. event.AddMouseBind(but, name, func, ...) -- mouse button code, unique name, function, function args. event.AddMouseBind(mousebuttoncode, "unique name", print, "hey there"); I have quite a few helpful modules I've written for the game I'm working on, is there somewhere you guys would like me to put them so others can take advantage of them?
  22. I have thought about it, i would have to write up an extensive usage guide as some elements do have their quirks which can make usage difficult, it doesn't use the flowgraph either you make elements purely with lua.
  23. Been doing more GUI work, mainly porting more of my GUI lib, but I did decide to finally get around to Dropdown menus which the library was missing from the beginning, I like this sudden feeling of productivity, the hardest part was porting my TabPanel over. I must have written the original on a bad day and going over the old code made no sense to me, it's new and improved now. - Sliders and DropLists. - Tabs and the usual ScrollPanel.
×
×
  • Create New...