Game Scripting by: Nicholas Haines. What is Scripting? Interpreted Language Interpreted Language –As the game runs.

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

Introducing JavaScript
Instruction Set Design
Introduction to Computer Engineering ECE 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin –
Professional Toolkit V2.0 C:\Presentations - SmartCafe_Prof_V2.0 - bsc page 1 Professional Toolkit 2.0.
Utilizing the GDB debugger to analyze programs Background and application.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Introduction to C Programming
Lab6 – Debug Assembly Language Lab
Expert System Human expert level performance Limited application area Large component of task specific knowledge Knowledge based system Task specific knowledge.
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Environments and Evaluation
Chapter 4 H1 Assembly Language: Part 2. Direct instruction Contains the absolute address of the memory location it accesses. ld instruction:
Introduction to a Programming Environment
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
C++ Functions. 2 Agenda What is a function? What is a function? Types of C++ functions: Types of C++ functions: Standard functions Standard functions.
Assembly & Machine Languages
Chapter 2 Software Tools and Assembly Language Syntax.
Game Scripting By: Nicholas Haines. Aurora Neverwinter Toolset.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4 1.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Introduction to Shell Script Programming
Dr. José M. Reyes Álamo 1.  The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access ◦ Variables ◦ Arrays ◦
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
Assembly Questions תרגול 12.
CSC 310 – Imperative Programming Languages, Spring, 2009 Virtual Machines and Threaded Intermediate Code (instead of PR Chapter 5 on Target Machine Architecture)
Code Generation Gülfem Savrun Yeniçeri CS 142 (b) 02/26/2013.
Programming With C.
Goals: To gain an understanding of assembly To get your hands dirty in GDB.
Using CookCC.  Use *.l and *.y files.  Proprietary file format  Poor IDE support  Do not work well for some languages.
Incell Phonium Processor Design Specifications Dale Mansholt Aaron Drake Jonathan Scruggs Travis Svehla Incell Phonium Processor.
Dr. José M. Reyes Álamo 1.  Review: ◦ Statement Labels ◦ Unconditional Jumps ◦ Conditional Jumps.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Objective At the conclusion of this chapter you will be able to:
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers Kostis Sagonas
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
1 Lex & Yacc. 2 Compilation Process Lexical Analyzer Source Code Syntax Analyzer Symbol Table Intermed. Code Gen. Code Generator Machine Code.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Chapter 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
Source Level Debugging of Parallel Programs Roland Wismüller LRR-TUM, TU München Germany.
More yacc. What is yacc – Tool to produce a parser given a grammar – YACC (Yet Another Compiler Compiler) is a program designed to compile a LALR(1) grammar.
CSCI 161 Lecture 3 Martin van Bommel. Operating System Program that acts as interface to other software and the underlying hardware Operating System Utilities.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Lecture 3 Translation.
Assembly language programming
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
User-Written Functions
Assembly language.
Data Transfers, Addressing, and Arithmetic
SQL and SQL*Plus Interaction
Compiler Construction (CS-636)
An Embedded Software Primer
CSC235 - Visual Studio Tutorial
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
Dynamic Binary Translators and Instrumenters
INSTRUCTION SET DESIGN
SPL – PS1 Introduction to C++.
Topic 2b ISA Support for High-Level Languages
Presentation transcript:

Game Scripting by: Nicholas Haines

What is Scripting? Interpreted Language Interpreted Language –As the game runs

Advantages Ease of use Ease of use Makes the game more data driven Makes the game more data driven –Instead of hard coding into game engine Allows for in-game “tweaking” Allows for in-game “tweaking” –Quick results –Does not require a recompile Allows user modability Allows user modability Game can be patched at a later date Game can be patched at a later date Many publicly available scripting languages Many publicly available scripting languages

Disadvantages Performance Performance –Not noticeable most of the time in real world performance real world performance Automatic memory management Automatic memory management –Can cause problems if it interrupts a command or takes awhile to complete Poor debugging tools Poor debugging tools –Some languages don’t give warnings –Tends to be very hard to find the errors

Optimizing Script Execution

Using Patterns Object: Reduce the number of instructions Object: Reduce the number of instructions Look for patterns in the opcode output Look for patterns in the opcode output –Replace with optimized version Check for addresses calculated multiple times and save to a spare register Check for addresses calculated multiple times and save to a spare register –Replace matching with reference to register May shorten code by up to 50% May shorten code by up to 50% –(assuming decoding script is the bottleneck of the virtual machine [VM])

Non-Branched, Constant Scripts Native function calls can be intercepted inside the VM Native function calls can be intercepted inside the VM Store as a function pointer along its arguments Store as a function pointer along its arguments Big list of stored functions is called an Execute List Big list of stored functions is called an Execute List Will now traverse execute list instead of having to interpret the opcode again Will now traverse execute list instead of having to interpret the opcode again

Branched Scripts Conditional jumps cannot be predicted Conditional jumps cannot be predicted A Jump Table can be used to decrease decode time during execution A Jump Table can be used to decrease decode time during execution Contains the offset of native opcode executing specific script opcode Contains the offset of native opcode executing specific script opcode Use pure jump table opcodes for most common instructions Use pure jump table opcodes for most common instructions Combine jump table/parse for less common instructions to reduce the table size Combine jump table/parse for less common instructions to reduce the table size Note: jump table values change whenever the VM’s code is changed the VM’s code is changed Example to be decoded mov [vm_reg0], vm_reg1 (using x86 asm) ;get contents of vm register 0 into eax mov eax, [ecx+0] ;get contents of vm register 1 into ebx mov ebx, [ecx+4] ;solve indirection mov [eax], ebx ;increment vm instruction pointer add edx, 4 ;transfer program control to next opcode jump [edx]

Branched into Non-Branched Monster::PlayerSpotted(bool hear_player, bool see_player, float* pos) Monster::PlayerSpotted(bool hear_player, bool see_player, float* pos){ if(!see_player) if(!see_player) { if(hear_player) if(hear_player) { //we have heard something..check out //we have heard something..check out //situation..keep an eye on the place //situation..keep an eye on the place FocusAttention(pos); //native function FocusAttention(pos); //native function } else else { //someone told us about the //someone told us about the //player (monster friend or so) //player (monster friend or so) //let's help our friends //let's help our friends WalkTo(pos); //native function WalkTo(pos); //native function } } else else { //we can see the enemy..let's kill him! //we can see the enemy..let's kill him! ShootAt(pos); //native function ShootAt(pos); //native function }} Generates each possibility and removes branching Generates each possibility and removes branching Code to the left becomes: Code to the left becomes: Monster::PlayerSpotted(bool hear_player=true, Monster::PlayerSpotted(bool hear_player=true, bool see_player=false, bool see_player=false, float* pos) float* pos) { FocusAttention(pos); FocusAttention(pos); } This can be optimized using execution lists This can be optimized using execution lists

Advanced Script Debugging

Exchanging Debug Information Debugger creates a new processes that uses the VM to execute scripts Debugger creates a new processes that uses the VM to execute scripts VM sends string messages to Debugger VM sends string messages to Debugger VM needs memory buffers for the Debugger to write to VM needs memory buffers for the Debugger to write to

Useful Features Debug information Debug information Handling Breakpoints Handling Breakpoints Variable Watch Variable Watch Call Stack Call Stack Step-by-Step Execution Step-by-Step Execution Step-by-Step Assembly Execution Step-by-Step Assembly Execution Register Watch Register Watch Memory Watch Memory Watch Step-by-Step High- Level Execution Step-by-Step High- Level Execution Step Over Execution Step Over Execution

Adding Error Reporting

Create A Parser For Your Script Use tools like Lex and Yacc Use tools like Lex and Yacc Since mostly nonprogrammers use the scripting language, make meaningful error messages. Since mostly nonprogrammers use the scripting language, make meaningful error messages.

A Simple Language Example code: int x; int y; y = 0; x = SomeFunction() - 5; if( x > OtherFunction() ) y = 3; y = 3; Possible Errors Possible Errors –Semicolon missing –Parentheses missing –Unrecognized characters –Unrecognized keyword –Function misspelled –Undeclared variable –Variable declared more than once

Reporting with yyerror() Prints “syntax error” to standard output Prints “syntax error” to standard output Overwrite yyerror() with a useful version Overwrite yyerror() with a useful version Derive a custom scanner function Derive a custom scanner function Print formatted error messages to a specified error file Print formatted error messages to a specified error file –Include line number and copy of the line This can be stored as a log or displayed in another application This can be stored as a log or displayed in another application

Identifying Specific Errors Unknown Character Errors Unknown Character Errors. yyerror(“Error: Unknown character ‘%c’ “, *yytext);. yyerror(“Error: Unknown character ‘%c’ “, *yytext); Append grammar to trap missing semicolon Append grammar to trap missing semicolon Do the same to catch unrecognized functions Do the same to catch unrecognized functions Undeclared and Redeclared Variables Undeclared and Redeclared Variables –Parser must check variable table to see if the variable has been previously declared

References AI Game Programming WISDOM 2 AI Game Programming WISDOM 2 Sections Game Dev Articles: Game Dev Articles: Scripting by Falko Poiker The Secret Life of Game Scripting The Secret Life of Game Scripting By Brian Hook nt/TheSecretLifeofGameScript.html nt/TheSecretLifeofGameScript.html