Yingcai Xiao EDP Scripting Yingcai Xiao. Why do we need EDP? What is EDP? How to implement EDP? How can we take advantages of EDP in game design and implement?

Slides:



Advertisements
Similar presentations
Chapter 16 Graphical User Interfaces
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Introduction to Macromedia Director 8.5 – Lingo
Understanding an Apps Architecture ASFA Computer Science: Principles Fall 2013.
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
ASP.NET Best Practices Dawit Wubshet Park University.
The Web Warrior Guide to Web Design Technologies
INNER WORKINGS OF UNITY 3D. WHAT WE ARE GOING TO COVER Intro to Unity Physics & Game Objects Cameras & Lighting Textures & Materials Quaternions and Rotation.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 18 – Macromedia Flash MX 2004: Building an Interactive Game Outline 18.1 Introduction 18.2 Object-Oriented.
CSI 3120, Exception handling, page 1 Exception and Event Handling Credits Robert W. Sebesta, Concepts of Programming Languages, 8 th ed., 2007 Dr. Nathalie.
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
Survey of Graphics and Games. Outline Overview of computer graphics – Coursework – Research Programming using game engines Computer game and animation.
Based on slides created by Edward Angel
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
NetSim ZigBee Simulation Code Walkthrough in 10 steps
Welcome to CIS 083 ! Events CIS 068.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
Introduction to Matlab & Data Analysis
Lecture 5: Interaction 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
SE 320 – Introduction to Game Development Lecture 8: Animations, GUIs, Debugging and IDEs Lecturer: Gazihan Alankuş Please look at the last two slides.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 27 - Phone Book Application Introducing Multimedia.
Description, Classes, Interfaces, Hierarchy, Specifics George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
Computer Graphics I, Fall 2010 Input and Interaction.
C H A P T E R T E N Event-Driven Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
C# Yingcai Xiao. Part I Moving from Java to C# .NET Framework ’ s Data Types: CTS Six categories of data types in CTS: system-defined: Primitives (int,
Yingcai Xiao Game Development Interactive Animation.
UFCFS D Technologies for the Web Unity 3D: Review of Topics and Related Concepts.
Chapter 13. Procedural programming vs OOP  Procedural programming focuses on accomplishing tasks (“verbs” are important).  Object-oriented programming.
Using Xcode A Beginner’s Tutorial Erin Green. This tutorial will walk you through Xcode, a software development tool for Apple’s iOS applications – We.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
GTK Binding for Alice Robert Grabowski Eine GTK-Schnittstelle für Alice.
11 Adding Tomato Targets Session Session Overview  We now have a game which lets a player bounce a piece of cheese on a bread bat  Now we have.
Learning Unity. Getting Unity
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Fundamentals of C++ Yingcai Xiao 09/03/08. Outline Class Definition IO Template vector C Pointer Dynamic Memory Allocation.
Yingcai Xiao Game Development with Unity3D. Outline IDE Engine Assets Tutorial Examples Inside.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
1 9/6/05CS360 Windows Programming CS360 Windows Programming.
Problem Solving Methodology Rachel Gauci. Problem Solving Methodology Development Design Analysis Evaluation Solution requirements and constraints. Scope.
Warlords Patrick Levoshko SE 558 – Multiplayer Game Design.
Interactive Computer Graphics
GameDevClub CODE CHEAT SHEET NOTE: ALL OF THE CODE IS CASE-SENSITIVE AND THE SYNTAX IS STRICT SO A LOT OF YOUR ERRORS WILL PROBABLY COME FROM TYPOS If.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 14 Event-Driven Programming with Graphical User Interfaces.
Yingcai Xiao Event-driven Programming in Game Development Yingcai Xiao.
Yingcai Xiao Programming and Debugging in Unity Yingcai Xiao.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Yingcai Xiao Interactive Game Design Final Overview Yingcai Xiao.
Yingcai Xiao Game Development with Unity3D Inside/Outside Unity3D.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Behavior trees & The C# programming language for Java programmers
Game Development with Unity3D
Interactive Animation
EEC-693/793 Applied Computer Vision with Depth Cameras
Game Development with Unity3D Inside/Outside Unity3D
Java Yingcai Xiao.
Programming and Debugging
Sai Goud Durgappagari Dr. Yingcai Xiao
EEC-693/793 Applied Computer Vision with Depth Cameras
Programming HCI Yingcai Xiao Yingcai Xiao.
EEC-693/793 Applied Computer Vision with Depth Cameras
C# for Unity3D Yingcai Xiao.
Event-driven Programming
A Prime Example of HCI Application
Programming and Debugging
Week 6: Time and triggers!
Professional Environment
EEC-693/793 Applied Computer Vision with Depth Cameras
Presentation transcript:

Yingcai Xiao EDP Scripting Yingcai Xiao

Why do we need EDP? What is EDP? How to implement EDP? How can we take advantages of EDP in game design and implement? How to use C# to implement EDP?

Interaction => events (software notifications of hardware status changes.) Input Device Driver Display Device Driver (GDI) Display Device Driver (GDI) Game (Software)

EDP: Event-driven programming Application awaits in an idle state and responds to user requests by calling the corresponding even handlers. Yingcai Xiao EDP

Events A menu in C++: char c; bool done = false; while(!done) { cout << “ Please make your selection, q to end: ” cin >> c; switch(c) { case “ + ” : add( ); break; case “ - ” : sub( ); break; case “ q ” : done = true; break; } Event Loop Event Mapping & Event Dispatching Event Event Handler

Key Components of EDP 1.Events 2.Event loop 3.Event mapping 4.Event dispatching 5.Event handlers All, but the handlers, are taken care of by the game engine and its underplaying graphics and OS platform.

Events Software notifications of hardware status changes. Can be represented in a char, string, encoded number, object oriented message. Generated by the OS when users interact with input devices. Sent to the active application (the application owns the active window.) Queued at the active application’s event queue. Removed by the application one by one. Dispatched to the event handlers according to event mapping.

Events All other events and new incoming events await until the current event is being processed. The idle “event” is critical event for drawing background animations. The idle “event” is internally generated when the event queue is empty. The idle “event” handler draws the the background animation when there is no other pending events. The idle “event” should be processed promptly in order to avoid delaying the processing of possible upcoming events.

Event handlers Programs which process the corresponding events. Usually a call-back function. e.g. OnMouseMove Most likely has input arguments, e.g., cursor location. Note: no new event can be processed when an event handler is running. Any long-time running animation should be broken into a sequence of short background animations. Another challenge is to pass a computational value to another event handler, e.g., the idle event handler.

Event Loop The event loop checks if there is any event (including the idle event) in the queue. If yes, dispatch the event to its handler. If not, wait for input. Or put an idle event into the queue if there is an idle handler.

Event Mapping Event mapping is done when the program register an event handler to an event. Usually at compile time of constructing the game. Each handler can be registered to multiple events. More than one handlers can be registered to each event. Make sure the handlers define proper arguments for the events.

Event Dispatching Event dispatching is done at runtime. The dispatcher invokes the corresponding handlers one by one. Usually in the order of registration. Most of the time, only one handler is registered for each event.

EDP in Unity3D Unity game engine supports EDP. Download the EDP-Scripting project. Open it with Unity3D and select scene1. Object Cylinder and Terrain. Note: animation1 was created using Unity GUI. IGD5 script was created to do simulation. Simulation is animation obeying certain rules, e.g., trajectory of a projectile.

EDP-Scripting Demo “a” for animation on/off. “s” for simulation on/off. “g” for gravitation on/off. Animation is different when “g” is on and off. Hit “s” to stop simulation quickly otherwise the object will run off the screen. Hit “s” to bring the object back to view if it run away. Score is increased by one when the cylinder hits the terrain.

EDP-Scripting Demo Coding Need to enable collider for the terrain for score counting. Need to enable capsule collider for the cylinder too. Need to create an animation and connect it to the object. Need to create a script and connect it to the object

EDP-Scripting Demo Coding To create animation: Window->Animation Click on the object to be animated. Component->Miscellaneous->Animation Name it. Start recording (the red button in the Animation Window) Add Curve->Transform->Position Stop and save.

EDP-Scripting Demo Coding To create scripts: Assets->Create->C# Script Name it in the Assets Pane. public class Test:MonoBehaviour { void Start () { /* initialization at the start of the application */} void Update ( ) { /* invoked at every frame of drawing */} }

EDP-Scripting Demo Coding To link the script: Select the object Component->Add->Scripts->Name (e.g.test) The script box will be added to the inspector of the object. Note all “public” variables will be displayed in the script box. To link the “Score” viable, drag “Hierarchy->Canvas- >scoreText” to the “Score” box.

EDP-Scripting Demo Coding The scoreText object needs to be created beforehand. GameObject->UI->Text

Scripting Writing code to control interaction and animation. Unity supports: C# for heavy duty programs JavaScripts for simple interactions Boo: “compiled Python”, CLI,.NET, Mono compatible Unreal supports: C++ UnrealScript (discontinued)

C# The de facto programming language for.NET OS platform independent Needs CLR (Common Language Runtime):.NET, Mono. Unity uses Mono. Supports: Class, Struct, Interface, Enum, Delegates Allow users to define events.

C# Classes Class: a group of code and data to be instantiated to form objects. Four categories of class members: Fields: member variables Methods: member functions Properties: fields exposed using accessor (get and set) methods Events: notifications a class is capable of firing

class Rectangle { // Fields protected int width = 1; protected int height = 1; // Methods public Rectangle () { } public Rectangle (int cx, int cy) { width = cx; height = cy; } Example: How to define a class in C#

// Accessor Methods public void setWidth(int w) { width = w; } public int getWidth() { return width; } public void setHeight(int h) { height = h; } public int getHeight() { return height; } } // End of Rectangle class // No “;” at the end of class definition. Example: How to define a class (user-defined data type)

Rectangle rect = new Rectangle(2,4); rect.setHeight(8); rect.setWidth(rect.getWidth() * 2); double darea = (double) (rect.getWidth() * rect.getHeight() ); Note: (1) “Rectangle rect” creats a reference, not object. (2) Treat “Rectangle rect = new Rectangle();” in C# as “Rectangle rect;” in C++. (3) Use “rect.” to dereference in C# instead of “rect->” as in C++. Example: How to use a class in C#

Garbage Collection  CLR controls garbage collection.  No need to free memory dynamically allocated with “new” on the heap in C#, hence, no destructors in C#.  CLR uses a reference counter to keep track the number of references pointing the memory.  CLR will free the memory when the reference counter becomes 0.  The Finalize() method (inherited from Object class) is called during garbage collection.  CLR decides when to perform garbage collection.  Force a garbage collection by calling GC.Collect (). (expensive)  Implement a Dispose method and call it when needed to cleanup when an object is not needed any more.

Example of Exception Handling  CLR ’ s Exception Handling Mechanism: try, catch, finally, and throw File file = null; // Do not define it in the try block. Why? try { file = new File ("Readme.txt"); if(file != null) { /* Do the work here. */} … } catch (FileNotFoundException e) { Console.WriteLine (e.Message); } catch ( … ) { … } } finally { // Always come here even if there were exceptions. if (file != null) file.Close (); }

C# vs. C++ C#C++ class myClass { }class myClass { } ; Rectangle rect = new Rectangle();Rectangle rect; “rect.” to dereference“rect->” to dereference No destructors~className(); Garbage Collectionfree using#include Single inheritanceMultiple inheritance

C# Books and Tutorials 

C# Code Example: IGD5.cs using UnityEngine; using UnityEngine.UI; using System.Collections; public class IGD5 : MonoBehaviour { float time = 0; float threshold = 0.5f; bool isReady = true; bool isSimulate = false; int collisionCount = 0; public Vector3 speed = new Vector3(5,5,0); public GameObject score; // the text object for displaying score // Use this for initialization void Start () { }

C# Code Example: IGD5.cs //colision detection void OnCollisionEnter (Collision collision) { if (collision.gameObject.tag == "terrain") { collisionCount++; score.GetComponent ().text = "Score : " + collisionCount; } } void simulationControl () { transform.position = new Vector3 ( transform.position.x + speed.x*Time.deltaTime, transform.position.y + speed.y*Time.deltaTime, transform.position.z); }

C# Code Example: IGD5.cs void Update () { if (!isReady) { if (time >= threshold) { isReady = true; time = 0; } else { time += Time.deltaTime; } } else

C# Code Example: IGD5.cs { if (Input.GetKey (KeyCode.G)) { if (gameObject.GetComponent ()) { gameObject.rigidbody.useGravity = !gameObject.rigidbody.useGravity; } else { gameObject.AddComponent (); } isReady = false; } else if (Input.GetKey (KeyCode.A)) { if (animation.isPlaying) gameObject.animation.Stop(); else gameObject.animation.Play (); isReady = false; }

C# Code Example: IGD5.cs else if (Input.GetKey (KeyCode.S)) { ///simulation isSimulate = !isSimulate; //on-off isReady = false; } } //Animation control if (isSimulate) simulationControl(); } }

EDP with OpenGL Unity3D and Unreal game engines are based on graphics engines: OpenGL or. The dispatcher invokes the corresponding handlers one by one. Usually in the order of registration. Most of the time, only one handler is registered for each event.

Geometric Transformation and Parametric Curves