SlideShare une entreprise Scribd logo
1  sur  29
k.shabordin@socialquantum.com
an.tihomirov@socialquantum.com
The Splendors and Miseries of
Game Scripting
• Cost
• Fast Prototyping (i.e. cost)
• Humans Rather Than Androids (i.e. cost)
• Code is Resource (i.e. cost)
Why Scripting?
Any scripting language is about the same.
Milestone One
• Mature
• Lua is NOT Javascript (man-month and web)
• Simple Embeddable (at first glance)
• The Book
• … and Why Not?
Why Lua?
Road to Paradigm Hell
• Standart Binders
• The Book (unit tests)
• Reference LuaC
• Bytecode
• Spirit of Lua (WHAT???)
• No Limits
Holy Cows
• Engine — monarchy; GET style
• Script — anarchy; CREATE style
• Hybrid — democracy; KILL’EM ALL style
Who Owns the World?
• Object ownership is for engine
• Classic “get/set” stateful API
• No direct created objects
• Creation tool is required
• Lua is “config with functions”
• Often user can’t enhance engine API
An Engine As King of the Hill
• Object ownership is for script
• Direct created objects
• Object’s lifecycle controlled by script
• Often has an OOP architecture
• Creation tool is NOT required
• User can enhance API by Lua
A Script is the Staff of Life
• Object ownership is smart
• Creating objects from any worlds
• Object’s lifecycle controlled by WHAT?
• Creation tool is NOT required
• User can write Lua as well as C++ code
• Often have one API for C++ and Lua users
Between Two Evils ’tis Not Worth
Choosing
Each GameObject has a script
Classic game loop out of user code
Ghost entry point
You need event system for linking scripts
OR
Application has a script and a GO graph
Obvious entry point
Traditional architecture of game loop
Event systems / FSM states etc… for application flow
Bark Up the Wrong Tree
There aren't problems in C++
Nor there are problems in Lua
Problems are in crossroad
Milestone Two
• local val = 42
• local val = true
• local val = ‘Ololo’
• local val = {…}
• local val = function() … end
• local val = myApiClass.new(…) root of all evil
Roots
• LuaC has C bridge, NOT C++
• LuaC uses userdata and metatables as tools
• LuaJIT also uses FFI lib (for pure C, sure)
Between Two Worlds
Pure C… and why it’s enough
You have three ways:
1. Write a better Lua code (mua-ha-ha-ha)
2. Investigate bottlenecks and fix them
3. Change the nature of Lua
4. Or do nothing
Milestone Three
• Create C methods for calling class methods
Include something inheritance implementation
• Create Lua metatable for caller and gc
• Compile it
Prepare myClass
Val = MyEngine.Class.new(param)
• Create userdata for MyEngine.Class
• Create MyEngine.Class instance on heap
• call constructor for C++ class MyEngine::Class with param
• save pointer (or shared pointer, or copy….) to userdata
• set metatable (static for every type) for method caller, gc, etc
• Create or set ref Val to this userdata
Cost of Creating Object
Res = (A + B - C) * D
What’s Wrong in This Code?
Res = (A + B - C) * D
• Res = mul(sub(add(A, B), C), D)
• Res = D.__mul(B.__sub(A.__add(A, B), C), D)
• Tmp1 = A._add(A, B) ‘internal’ assign
• Tmp2 = B._sub(B, Tmp1) ‘internal’ assign
• Res = D_mul(Tmp2, D) ‘external’ assign
Look Inside
• Don’t use metamethods = don’t return values
• Use “CryE”-like ugly calls : SumVectors( a, b, res)
• Implement all the necessary operations in C++
Solution#1 — No woman no cry
• Stack record is Variant
• Variant size is eq to the max type size
• Ex: vec3 increases the stack size by about 3 times
• Pros — speed, cons — size
• Ownership: no GC for stack values in Lua
Solution#2 — More POD Types
• Add __assign metamethod a = b -> a.__assign(b)
• Create caches for each necessary type
Solution#3 — Cache It
Type cacher
Global Binder Userdata cache
Heap type T cache [maxN]
• All userdata for binding of the same size
• Assign — point for drop temporary cache
• Cache created for each necessary type
• Garbage Collector isn’t used in cache
• Cache overload produce normal objects
• Special allocators used for optimisation
How It Works
New Age Fusion
CODE AST LUAC
BYTECODE
LuaC, have eval
CODE AST IR
BYTECODE
JIT Ideas, have eval
EXECUTE
PREPARE HW
BYTECODE
EXECUTE
CODE AST LLVM IR
External LLDB, eval is restricted
LLVM
OPTIMIZATIONS
LUAC
BYTECODE
EXECUTE
LuaC and LuaJIT are more than enough for any
practical issue
… in case you write clean and smart code
Milestone Four
Tools and Fun
The Crew
QUESTIONS?
… or more cases?

Contenu connexe

Tendances

Not Everything is an Object - Rocksolid Tour 2013
Not Everything is an Object  - Rocksolid Tour 2013Not Everything is an Object  - Rocksolid Tour 2013
Not Everything is an Object - Rocksolid Tour 2013
Gary Short
 

Tendances (20)

F# type providers
F# type providersF# type providers
F# type providers
 
Why scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisWhy scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with this
 
Few simple-type-tricks in scala
Few simple-type-tricks in scalaFew simple-type-tricks in scala
Few simple-type-tricks in scala
 
C# basics
C# basicsC# basics
C# basics
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With Scala
 
Akka actorstotherescue nirmalya sengupta
Akka actorstotherescue nirmalya senguptaAkka actorstotherescue nirmalya sengupta
Akka actorstotherescue nirmalya sengupta
 
Moving Web forward: Part I — ECMAScript 201x
Moving Web forward: Part I — ECMAScript 201xMoving Web forward: Part I — ECMAScript 201x
Moving Web forward: Part I — ECMAScript 201x
 
LISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола МозговийLISP: назад в будущее, Микола Мозговий
LISP: назад в будущее, Микола Мозговий
 
Incremental Development with Lisp: Building a Game and a Website
Incremental Development with Lisp: Building a Game and a WebsiteIncremental Development with Lisp: Building a Game and a Website
Incremental Development with Lisp: Building a Game and a Website
 
History fp
History fpHistory fp
History fp
 
10 Things I Hate About Scala
10 Things I Hate About Scala10 Things I Hate About Scala
10 Things I Hate About Scala
 
Not Everything is an Object - Rocksolid Tour 2013
Not Everything is an Object  - Rocksolid Tour 2013Not Everything is an Object  - Rocksolid Tour 2013
Not Everything is an Object - Rocksolid Tour 2013
 
PageRank and The Google Matrix
PageRank and The Google MatrixPageRank and The Google Matrix
PageRank and The Google Matrix
 
Scala : language of the future
Scala : language of the futureScala : language of the future
Scala : language of the future
 
Csp scala wixmeetup2016
Csp scala wixmeetup2016Csp scala wixmeetup2016
Csp scala wixmeetup2016
 
A Scala Corrections Library
A Scala Corrections LibraryA Scala Corrections Library
A Scala Corrections Library
 
A Very Brief Intro to Golang
A Very Brief Intro to GolangA Very Brief Intro to Golang
A Very Brief Intro to Golang
 
Intro to kotlin 2018
Intro to kotlin 2018Intro to kotlin 2018
Intro to kotlin 2018
 
R ext world/ useR! Kiev
R ext world/ useR!  KievR ext world/ useR!  Kiev
R ext world/ useR! Kiev
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
 

Similaire à Lua. The Splendors and Miseries of Game Scripting

Yapc10 Cdt World Domination
Yapc10   Cdt World DominationYapc10   Cdt World Domination
Yapc10 Cdt World Domination
cPanel
 

Similaire à Lua. The Splendors and Miseries of Game Scripting (20)

David buksbaum a-briefintroductiontocsharp
David buksbaum a-briefintroductiontocsharpDavid buksbaum a-briefintroductiontocsharp
David buksbaum a-briefintroductiontocsharp
 
Yapc10 Cdt World Domination
Yapc10   Cdt World DominationYapc10   Cdt World Domination
Yapc10 Cdt World Domination
 
c++ ppt.ppt
c++ ppt.pptc++ ppt.ppt
c++ ppt.ppt
 
Capacity Planning for fun & profit
Capacity Planning for fun & profitCapacity Planning for fun & profit
Capacity Planning for fun & profit
 
C++ overview
C++ overviewC++ overview
C++ overview
 
Return of c++
Return of c++Return of c++
Return of c++
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
UsingCPP_for_Artist.ppt
UsingCPP_for_Artist.pptUsingCPP_for_Artist.ppt
UsingCPP_for_Artist.ppt
 
Killing Shark-Riding Dinosaurs with ORM
Killing Shark-Riding Dinosaurs with ORMKilling Shark-Riding Dinosaurs with ORM
Killing Shark-Riding Dinosaurs with ORM
 
Ruby Under The Hood
Ruby Under The HoodRuby Under The Hood
Ruby Under The Hood
 
Tips and tricks for building high performance android apps using native code
Tips and tricks for building high performance android apps using native codeTips and tricks for building high performance android apps using native code
Tips and tricks for building high performance android apps using native code
 
Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++Building High Performance Android Applications in Java and C++
Building High Performance Android Applications in Java and C++
 
lecture02-cpp.ppt
lecture02-cpp.pptlecture02-cpp.ppt
lecture02-cpp.ppt
 
06.1 .Net memory management
06.1 .Net memory management06.1 .Net memory management
06.1 .Net memory management
 
Effective C++
Effective C++Effective C++
Effective C++
 
ITB2017 - Slaying the ORM dragons with cborm
ITB2017 - Slaying the ORM dragons with cbormITB2017 - Slaying the ORM dragons with cborm
ITB2017 - Slaying the ORM dragons with cborm
 

Plus de DevGAMM Conference

Plus de DevGAMM Conference (20)

The art of small steps, or how to make sound for games in conditions of war /...
The art of small steps, or how to make sound for games in conditions of war /...The art of small steps, or how to make sound for games in conditions of war /...
The art of small steps, or how to make sound for games in conditions of war /...
 
Breaking up with FMOD - Why we ended things and embraced Metasounds / Daniel ...
Breaking up with FMOD - Why we ended things and embraced Metasounds / Daniel ...Breaking up with FMOD - Why we ended things and embraced Metasounds / Daniel ...
Breaking up with FMOD - Why we ended things and embraced Metasounds / Daniel ...
 
How Audio Objects Improve Spatial Accuracy / Mads Maretty Sønderup (Audiokine...
How Audio Objects Improve Spatial Accuracy / Mads Maretty Sønderup (Audiokine...How Audio Objects Improve Spatial Accuracy / Mads Maretty Sønderup (Audiokine...
How Audio Objects Improve Spatial Accuracy / Mads Maretty Sønderup (Audiokine...
 
Why indie developers should consider hyper-casual right now / Igor Gurenyov (...
Why indie developers should consider hyper-casual right now / Igor Gurenyov (...Why indie developers should consider hyper-casual right now / Igor Gurenyov (...
Why indie developers should consider hyper-casual right now / Igor Gurenyov (...
 
AI / ML for Indies / Tyler Coleman (Retora Games)
AI / ML for Indies / Tyler Coleman (Retora Games)AI / ML for Indies / Tyler Coleman (Retora Games)
AI / ML for Indies / Tyler Coleman (Retora Games)
 
Agility is the Key: Power Up Your GameDev Project Management with Agile Pract...
Agility is the Key: Power Up Your GameDev Project Management with Agile Pract...Agility is the Key: Power Up Your GameDev Project Management with Agile Pract...
Agility is the Key: Power Up Your GameDev Project Management with Agile Pract...
 
New PR Tech and AI Tools for 2023: A Game Changer for Outreach / Kirill Perev...
New PR Tech and AI Tools for 2023: A Game Changer for Outreach / Kirill Perev...New PR Tech and AI Tools for 2023: A Game Changer for Outreach / Kirill Perev...
New PR Tech and AI Tools for 2023: A Game Changer for Outreach / Kirill Perev...
 
Playable Ads - Revolutionizing mobile games advertising / Jakub Kukuryk (Popc...
Playable Ads - Revolutionizing mobile games advertising / Jakub Kukuryk (Popc...Playable Ads - Revolutionizing mobile games advertising / Jakub Kukuryk (Popc...
Playable Ads - Revolutionizing mobile games advertising / Jakub Kukuryk (Popc...
 
Creative Collaboration: Managing an Art Team / Nastassia Radzivonava (Glera G...
Creative Collaboration: Managing an Art Team / Nastassia Radzivonava (Glera G...Creative Collaboration: Managing an Art Team / Nastassia Radzivonava (Glera G...
Creative Collaboration: Managing an Art Team / Nastassia Radzivonava (Glera G...
 
From Local to Global: Unleashing the Power of Payments / Jan Kuhlmannn (Xsolla)
From Local to Global: Unleashing the Power of Payments / Jan Kuhlmannn (Xsolla)From Local to Global: Unleashing the Power of Payments / Jan Kuhlmannn (Xsolla)
From Local to Global: Unleashing the Power of Payments / Jan Kuhlmannn (Xsolla)
 
Strategies and case studies to grow LTV in 2023 / Julia Iljuk (Balancy)
Strategies and case studies to grow LTV in 2023 / Julia Iljuk (Balancy)Strategies and case studies to grow LTV in 2023 / Julia Iljuk (Balancy)
Strategies and case studies to grow LTV in 2023 / Julia Iljuk (Balancy)
 
Why is ASO not working in 2023 and how to change it? / Olena Vedmedenko (Keya...
Why is ASO not working in 2023 and how to change it? / Olena Vedmedenko (Keya...Why is ASO not working in 2023 and how to change it? / Olena Vedmedenko (Keya...
Why is ASO not working in 2023 and how to change it? / Olena Vedmedenko (Keya...
 
How to increase wishlists & game sales from China? Growth marketing tactics &...
How to increase wishlists & game sales from China? Growth marketing tactics &...How to increase wishlists & game sales from China? Growth marketing tactics &...
How to increase wishlists & game sales from China? Growth marketing tactics &...
 
Turkish Gaming Industry and HR Insights / Mustafa Mert EFE (Zindhu)
Turkish Gaming Industry and HR Insights / Mustafa Mert EFE (Zindhu)Turkish Gaming Industry and HR Insights / Mustafa Mert EFE (Zindhu)
Turkish Gaming Industry and HR Insights / Mustafa Mert EFE (Zindhu)
 
Building an Awesome Creative Team from Scratch, Capable of Scaling Up / Sasha...
Building an Awesome Creative Team from Scratch, Capable of Scaling Up / Sasha...Building an Awesome Creative Team from Scratch, Capable of Scaling Up / Sasha...
Building an Awesome Creative Team from Scratch, Capable of Scaling Up / Sasha...
 
Seven Reasons Why Your LiveOps Is Not Performing / Alexander Devyaterikov (Be...
Seven Reasons Why Your LiveOps Is Not Performing / Alexander Devyaterikov (Be...Seven Reasons Why Your LiveOps Is Not Performing / Alexander Devyaterikov (Be...
Seven Reasons Why Your LiveOps Is Not Performing / Alexander Devyaterikov (Be...
 
The Power of Game and Music Collaborations: Reaching and Engaging the Masses ...
The Power of Game and Music Collaborations: Reaching and Engaging the Masses ...The Power of Game and Music Collaborations: Reaching and Engaging the Masses ...
The Power of Game and Music Collaborations: Reaching and Engaging the Masses ...
 
Branded Content: How to overcome players' immunity to advertising / Alex Brod...
Branded Content: How to overcome players' immunity to advertising / Alex Brod...Branded Content: How to overcome players' immunity to advertising / Alex Brod...
Branded Content: How to overcome players' immunity to advertising / Alex Brod...
 
Resurrecting Chasm: The Rift - A Source-less Remastering Journey / Gennadii P...
Resurrecting Chasm: The Rift - A Source-less Remastering Journey / Gennadii P...Resurrecting Chasm: The Rift - A Source-less Remastering Journey / Gennadii P...
Resurrecting Chasm: The Rift - A Source-less Remastering Journey / Gennadii P...
 
How NOT to do showcase events: Behind the scenes of Midnight Show / Andrew Ko...
How NOT to do showcase events: Behind the scenes of Midnight Show / Andrew Ko...How NOT to do showcase events: Behind the scenes of Midnight Show / Andrew Ko...
How NOT to do showcase events: Behind the scenes of Midnight Show / Andrew Ko...
 

Dernier

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 

Lua. The Splendors and Miseries of Game Scripting

  • 2. • Cost • Fast Prototyping (i.e. cost) • Humans Rather Than Androids (i.e. cost) • Code is Resource (i.e. cost) Why Scripting?
  • 3. Any scripting language is about the same. Milestone One
  • 4. • Mature • Lua is NOT Javascript (man-month and web) • Simple Embeddable (at first glance) • The Book • … and Why Not? Why Lua?
  • 6. • Standart Binders • The Book (unit tests) • Reference LuaC • Bytecode • Spirit of Lua (WHAT???) • No Limits Holy Cows
  • 7. • Engine — monarchy; GET style • Script — anarchy; CREATE style • Hybrid — democracy; KILL’EM ALL style Who Owns the World?
  • 8. • Object ownership is for engine • Classic “get/set” stateful API • No direct created objects • Creation tool is required • Lua is “config with functions” • Often user can’t enhance engine API An Engine As King of the Hill
  • 9. • Object ownership is for script • Direct created objects • Object’s lifecycle controlled by script • Often has an OOP architecture • Creation tool is NOT required • User can enhance API by Lua A Script is the Staff of Life
  • 10. • Object ownership is smart • Creating objects from any worlds • Object’s lifecycle controlled by WHAT? • Creation tool is NOT required • User can write Lua as well as C++ code • Often have one API for C++ and Lua users Between Two Evils ’tis Not Worth Choosing
  • 11. Each GameObject has a script Classic game loop out of user code Ghost entry point You need event system for linking scripts OR Application has a script and a GO graph Obvious entry point Traditional architecture of game loop Event systems / FSM states etc… for application flow Bark Up the Wrong Tree
  • 12. There aren't problems in C++ Nor there are problems in Lua Problems are in crossroad Milestone Two
  • 13. • local val = 42 • local val = true • local val = ‘Ololo’ • local val = {…} • local val = function() … end • local val = myApiClass.new(…) root of all evil Roots
  • 14. • LuaC has C bridge, NOT C++ • LuaC uses userdata and metatables as tools • LuaJIT also uses FFI lib (for pure C, sure) Between Two Worlds
  • 15. Pure C… and why it’s enough
  • 16. You have three ways: 1. Write a better Lua code (mua-ha-ha-ha) 2. Investigate bottlenecks and fix them 3. Change the nature of Lua 4. Or do nothing Milestone Three
  • 17. • Create C methods for calling class methods Include something inheritance implementation • Create Lua metatable for caller and gc • Compile it Prepare myClass
  • 18. Val = MyEngine.Class.new(param) • Create userdata for MyEngine.Class • Create MyEngine.Class instance on heap • call constructor for C++ class MyEngine::Class with param • save pointer (or shared pointer, or copy….) to userdata • set metatable (static for every type) for method caller, gc, etc • Create or set ref Val to this userdata Cost of Creating Object
  • 19. Res = (A + B - C) * D What’s Wrong in This Code?
  • 20. Res = (A + B - C) * D • Res = mul(sub(add(A, B), C), D) • Res = D.__mul(B.__sub(A.__add(A, B), C), D) • Tmp1 = A._add(A, B) ‘internal’ assign • Tmp2 = B._sub(B, Tmp1) ‘internal’ assign • Res = D_mul(Tmp2, D) ‘external’ assign Look Inside
  • 21. • Don’t use metamethods = don’t return values • Use “CryE”-like ugly calls : SumVectors( a, b, res) • Implement all the necessary operations in C++ Solution#1 — No woman no cry
  • 22. • Stack record is Variant • Variant size is eq to the max type size • Ex: vec3 increases the stack size by about 3 times • Pros — speed, cons — size • Ownership: no GC for stack values in Lua Solution#2 — More POD Types
  • 23. • Add __assign metamethod a = b -> a.__assign(b) • Create caches for each necessary type Solution#3 — Cache It Type cacher Global Binder Userdata cache Heap type T cache [maxN]
  • 24. • All userdata for binding of the same size • Assign — point for drop temporary cache • Cache created for each necessary type • Garbage Collector isn’t used in cache • Cache overload produce normal objects • Special allocators used for optimisation How It Works
  • 25. New Age Fusion CODE AST LUAC BYTECODE LuaC, have eval CODE AST IR BYTECODE JIT Ideas, have eval EXECUTE PREPARE HW BYTECODE EXECUTE CODE AST LLVM IR External LLDB, eval is restricted LLVM OPTIMIZATIONS LUAC BYTECODE EXECUTE
  • 26. LuaC and LuaJIT are more than enough for any practical issue … in case you write clean and smart code Milestone Four