Jump to content

ChrisMAN

Members
  • Posts

    174
  • Joined

  • Last visited

Posts posted by ChrisMAN

  1. Our example game Darkness Awaits is written entirely in Lua. I was worried at first it might be too slow to script the whole thing, but it turned out Lua is fast enough for what we are trying to do.

     

    When the JIT can figure it out lua is very fast. I know for a fact that i have gotten burned by simple things like exiting a function early. Microbenchmarks put it at 70-80% native C.

     

    I would be curious to see what the lua profiler says. https://gist.github.com/perky/2838755

  2. I don't know much about opengl but once i started thinking of buffers as an array of memory addresses on the video card things started to make more sense. When you copy from the buffer you are still just copying memory addresses so if you modify the buffer after a copy, the copy is affected as well.

     

    Here is the trick to get the transparent buffer:

     

    SetBlend(1)
    SetColor(Vec4(0,0,0,0))
    ClearBuffer()
    
    

     

    in summary set the color before clearing the buffer. the buffer's background will inherit the current color.

  3. yes that is what i was doing. my gui framework i wrote handled it so i don't have a nice clean snippet of how to do it.

    1. create a full sized buffer
    2. copy the color buffer
    3. use DrawImage to draw just copied texture to the backbuffer

    *protip be mindful of your color during this whole thing. it is much like setworld. if you don't manage it... it will manage you!!!

     

    as far as positioning goes i positioned everything using left, right, top, bottom. right and bottom subtracted the width of the element to that it could cleanly snap to the side/bottom of an element. again the gui tool i wrote handle this for me. i also used a combination of horizontal/vertical centering for things that would go in the middle of the screen.

     

    i find using these relative coordinates solves the majority of ui issues.

     

    if you can't get that to work i can cook something up.

  4. I have considered a no internets rule until i finish a song. Not keeping up with music has been one of my biggest regrets. You don't wan t to go longer than 3 years. It is been 5 for me and it kills.

  5. Here is a character animation template i wrote for the leadwerks community project in lua

     

    https://gist.github.com/friesencr/4743009

     

    require("scripts/class")
    require("scripts/math/math")
    require("Scripts/constants/engine_const")
    local class=CreateClass(...)
    function class:CreateObject(model)
     local object=self.super:CreateObject(model)
    local animation_data = {
     walk = {
      start = 50,
      frames = 23,
      multiplier = 1
     },
     idle = {
      start = 0,
      frames = 44,
      multiplier = 1
     },
     strafe = {
      start = 75,
      frames = 117 - 75,
      multiplier = 3
     },
     run = {
      start = 125,
      frames = 142 - 125,
      multiplier = 1
     },
     run_strafe = {
      start = 75,
      frames = 117 - 75,
      multiplier = 5
     },
     jump = {
      start = 150,
      frames = 176 - 150,
      multiplier = 1
     },
     land = {
      start = 210,
      frames = 214 - 210,
      multiplier = 1
     }
    }
    local current_frame
    local animation_state
    local animation_start_time = AppTime()
    local current_animation = animation_data['idle']
    function object:Update()
     local ca = current_animation
     local time = AppTime() - animation_start_time
     local frame = (( time / 60 ) % (ca.frames/ca.multiplier)) * ca.multiplier + ca.start
     self.model:Animate(frame, 0.2,0,1)
    end
    function SetAnimationState(state)
     animation_state = state
     animation_start_time = AppTime()
     current_animation = animation_data[state]
    end
    function object:ReceiveMessage(message, extra)
     if message == 'idle' then object:Idle()
     elseif message == 'walk' then object:Walk()
     elseif message == 'run' then object:Run()
     elseif message == 'jump' then object:Jump()
     elseif message == 'land' then object:Land()
     elseif message == 'strafe'  then object:Strafe()
     elseif message == 'run_strafe' then object:RunStrafe() end
    end
    function object:Walk()
     if animation_state ~= 'walk' then SetAnimationState('walk') end
    end
    function object:Idle()
     if animation_state ~= 'idle' then SetAnimationState('idle') end
    end
    function object:Run()
     if animation_state ~= 'run' then SetAnimationState('run') end
    end
    function object:Strafe()
     if animation_state ~= 'strafe' then SetAnimationState('strafe') end
    end
    function object:RunStrafe()
     if animation_state ~= 'strafe' then SetAnimationState('strafe') end
    end
    function object:Land()
     if animation_state ~= 'land' then SetAnimationState('land') end
    end
    function object:Jump()
     if animation_state ~= 'jump' then SetAnimationState('jump') end
    end
    end
    

  6. I wrote a library that inverts callbacks and allows you to compose their behavior. On the web side of things we use them all the time. They are called promises. Lua has awesome continuations but ultimately they cannot be controlled well or composed so i created a promise library and an event emitter library. I don't know why the game world hasn't caught on. I feel like I am taking crazy pills. It's like c++/game devs live in a vacuum.

     

    https://github.com/friesencr/lua_promise

  7. Write a little bit of abstraction to give structure but most importantly the code needs to be hack-able and able to handle some good spaghetti I am written many complex web interfaces and it usually comes down to some good spaghetti. Conventions can help to reduce confusion among fellow developers.

  8. You are better off learning Java because it forces you to make EVERYTHING a class. C++ doesn't have this requirement so it's probably not the best language to learn about classes with. I suggest coding in Java for a couple months so you are used to making everything a class, then come over to C++ and learn it's slight differences in how it handles classes, but at least you'll be in the good habit of making everything a class.

     

    It is about to gain blocks, and dynamic typing. It will almost be a on parity with c#.

     

    Seriously though... the inability to use procedual forms of programming... I love procedural programming. OO is the devil in diguise. There was so much knowledge that was built up through the 70s and 80s and it was destroyed by .net and java. It wasn't until about 5 years ago where the renascence picked up again. Try reading up on logic programming. It is pretty wild how they solve things. I a few years out from learning a functional language. I hear you have to wear a sweater to be a functional programmer. Clojure is picking speed. Soon it will have alternative VMs to the jvm.

     

    Rust lang http://www.rust-lang...ang.org/ This language has epic potential. It has bindings to sdl.

     

    Too much to learn. So little time...

    • Upvote 1
  9. Lua does OO very differently. It's OO system was modeled after Self. http://en.wikipedia.org/wiki/Self_(programming_language)

    Its method of oo uses the caller of the method as the 'this' or as lua calls 'self'. even though the owner of the function can be a totally different object. if you have ever done OO in javascript you will feel this pain if you used to the C family languages.

     

    There are basically 2 ways of doing classes in lua. You can use meta tables or you can literally copy methods from one object to another. The copying method is often called a 'mixin'.

     

    There is no way around reading luas documention on tables and meta tables. To make matters worse lua has gained much of its popularity from it being the language used for the user interface system in WoW. That means that google is half as effective.

     

    If you use metatables for your 'classes' you are using something much like prototypical inheritence

    This is what got me started with metatables as classes http://lua-users.org/wiki/SimpleLuaClasses

     

    If you want to use a mixin you can use a function like this

     

    function mixin(dest, src)

    assert(dest)

    assert(src)

    for key, value in pairs(src) do

    dest[key] = value

    end

    end

     

    If you are writing code for someone else to use. You should use mixins because they don't depend on metatables to work.

     

    I am sorry for not explaining this better.

  10. That is so wrong, it's just a horrible idea, why would anyone in their right mind do it?

     

    I was a .net 'build master' for a company. This link made me see the words msbuild again. There needs to be blood. I double dog dare anyone to integrate an open source testing tool(which are the only good ones) as part of a tfs build with reports working /fml

×
×
  • Create New...