Chapter 3.3 Programming Fundamentals Languages Paradigms Basic Data Types Data Structures OO in Game Design Component Systems Design Patterns.

Slides:



Advertisements
Similar presentations
Programming Paradigms and languages
Advertisements

Programming Languages and Paradigms
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Chapter 7:: Data Types Programming Language Pragmatics
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Object Oriented Programming Chapter 7 Programming Languages by Ravi Sethi.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
G. Levine Chapter 6 Chapter 6 Encapsulation –Why do we want encapsulation? Programmer friendliness- programmer need not know about these details –Easier.
Chapter 3.4 Programming Fundamentals. 2 Data Structures Arrays – Elements are adjacent in memory (great cache consistency) – They never grow or get reallocated.
C++ fundamentals.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
CIT241 Prerequisite Knowledge ◦ Variables ◦ Operators ◦ C++ Syntax ◦ Program Structure ◦ Classes  Basic Structure of a class  Concept of Data Hiding.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
OOP Languages: Java vs C++
Object Oriented Software Development
Programming Languages and Paradigms Object-Oriented Programming.
Binary There are only 10 types of people in the world, those who understand binary and those who don't.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
Design Patterns.
There are only 10 types of people in the world, those who understand binary and those who don't.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
Ceg860 (Prasad)L6MR1 Modularity Extendibility Reusability.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
CSE 425: Data Types II Survey of Common Types I Records –E.g., structs in C++ –If elements are named, a record is projected into its fields (e.g., via.
CSCE 552 Spring 2009 Programming Fundamentals By Jijun Tang.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
Programming Languages and Paradigms Object-Oriented Programming.
Computer Concepts 2014 Chapter 12 Computer Programming.
OOP Class Lawrence D’Antonio Lecture 3 An Overview of C++
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
1 Class Diagrams: Advanced Concepts. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are the most commonly used diagrams.
Programming Languages and Paradigms Imperative Programming.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
1 Class Diagrams. 2 Overview Class diagrams are the most commonly used diagrams in UML. Class diagrams are for visualizing, specifying and documenting.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Salman Marvasti Sharif University of Technology Winter 2015.
Introduction to Object-Oriented Programming Lesson 2.
CSCE 552 Fall 2012 Language and Programming By Jijun Tang.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Andy Wang Object Oriented Programming in C++ COP 3330
Language and Programming
Why study programming languages?
CS 215 Final Review Ismail abumuhfouz Fall 2014.
7.1 What Is An Object Object-oriented program - Description or simulation of application Object-oriented programming is done by adopting or extending an.
PROGRAMMING LANGUAGES
Chapter 10 Design Patterns.
Chapter 11 Object-Oriented Design
Computer Programming.
Advanced Programming Behnam Hatami Fall 2017.
Andy Wang Object Oriented Programming in C++ COP 3330
Programming Languages 2nd edition Tucker and Noonan
Principles of Programming Languages
Introduction to Data Structure
Java Programming Language
Course Overview PART I: overview material PART II: inside a compiler
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Presentation transcript:

Chapter 3.3 Programming Fundamentals Languages Paradigms Basic Data Types Data Structures OO in Game Design Component Systems Design Patterns

Languages Language: A system composed of signs (symbols, indices, icons) and axioms (rules) used for encoding and decoding information. Syntax: Refers to rules of a language, in particular the structure and punctuation. Semantics: Refers to the meaning given to symbols (and combinations of symbols). 2

Programming Languages A language for creating programs (giving instructions to a computer). Computers are dumb... no, really, they are. A computer (at the lowest level) is simply a powerful adding machine. A computer stores and manipulates numbers (which can represent other things) in binary. I don't know about you, buy I don't speak binary. 3

Programming Paradigms Paradigm – approach, method, thought pattern used to seek a solution to a problem. There are dozens of (often overlapping) programming paradigms including: – Logical (declarative, recursive, Prolog) – Functional (declarative, immutable, stateless, Haskell) – Imperative (linear, state-full, VAST MAJORITY OF POPULAR PROGAMNING LANGUAGES) 4

Imperative Programming Imperative programs define sequences of commands for the computer to perform. Structured Programming (subcategory of Imperative) requires 3 things: – Sequence – Selection – Repetition 5

Procedural Programming Another subcategory of Imperative. Uses procedures (subroutines, methods, or functions) to contain computational steps to be carried out. Any given procedure might be called at any point during a program's execution, including by other procedures or itself. 6

Object Oriented Subcategory of structured programming. Uses "objects" – customized data structures consisting of data fields and methods – to design applications and computer programs. As with procedures (in procedural programming) any given objects methods or variables might be referred to at any point during a program's execution, including by other objects or itself. 7

Popular Languages Understanding programming paradigms can help you approach learning new programming languages (if they are within a paradigm you are familiar with). Most popular languages: C++, C, Java, PHP, Perl, C#, Python, JavaScript, Visual Basic, Shell, Delphi, Ruby, ColdFusion, D, Actionscript, Pascal, Lua, Lisp, Assembly, Objective C, etc. 8

Data Types Primitive data types: integers, booleans, characters, floating-point numbers (decimals), alphanumeric strings. Pointers: (void* q = &x; ) Variables: a symbolic name associated with a value (value may be changed). – Strong vs. Weak typing – Implicit vs. Explicit type conversion 9

Data Structures Arrays – Elements are adjacent in memory (great cache consistency) – They never grow or get reallocated – In C++ there's no check for going out of bounds – Inserting and deleting elements in the middle is expensive – Consider using the STL Vector in C++ 10

Data Structures Linked lists – Very fast and cheap to add/remove elements. – Available in the STL (std::list) – Every element is allocated separately Lots of little allocations – Not placed contiguously in memory 11

Data Structures Dictionaries (hash maps) – Maps a set of keys to some data. – std::map, std::multimap, std::hash – Very fast access to data Underlying structure varies, but is ordered in some way. – Perfect for mapping IDs to pointers, or resource handles to objects 12

Data Structures Stacks (LIFO) – Last in, first out – std::stack adaptor in STL – parsing Queues (FIFO) – First in, first out – std::deque – Priority queues for timing issues. 13

Data Structures Bit packing – Fold all necessary data into small number of bits – Very useful for storing boolean flags (pack 32 in a double word) – Possible to apply to numerical values if we can give up range or accuracy – Very low level trick Only use when absolutely necessary Used OFTEN in networking/messaging scenarios 14

Bit Shifting 15 int age, gender, height, packed_info;... // Assign values // Pack as AAAAAAAA G HHHHHHH using shifts and "or" packed_info = (age << 8) | (gender << 7) | height; // Unpack with shifts and masking using "and" height = packed_info & 0x7F; // This is binary gender = (packed_info >> 7) & 1; age = (packed_info >> 8);

Union Bitpacking (C++) union Packed_Info { int age : 8; int gender: 1; int height: 7; } Packed_Info playercharacter; playercharacter.age = 255; 16

Object Oriented Design Concepts – Class Abstract specification of a data type; a pattern or template of an object we would like to create. – Instance A region of memory with associated semantics to store all the data members of a class; something created using our pattern. – Object Another name for an instance of a class 17

Classes #include using namespace std; Class Enemy { int height, weight; public: void set_values (int,int); } ; void Enemy::set_values (int a, int b) { height = a; weight = b; } int main () { Enemy enemy1; enemy1.set_values (36,350); return 0; } 18

Object Oriented Design Inheritance – Models “is-a” relationship – Extends behaviour of existing classes by making minor changes in a newly created class. Example:... // adding a AI function public: void RunAI(); 19

Inheritance class derived_class: public base_class { /*...*/ }; The public access specifier may be replaced protected or private. This access specifier limits the most accessible level for the members inherited from the base class 20

class Boss: public Enemy { private: int damage_resitance; public: void RunAI(); } ; class SuperBoss: public Boss { public: void RunAI(); } ; 21

Object Oriented Design Inheritance – UML diagram representing inheritance 22 EnemyBoss SuperBoss

Object Oriented Design Polymorphism – The ability to refer to an object through a reference (or pointer) of the type of a parent class – Key concept of object oriented design – Allow (among other things) for me to keep an array of pointers to all objects in a particular derivation tree. 23

Enemy* enemies[256]; enemies[0] = new Enemy; enemies[1] = new Enemy; enemies[2] = new Enemy; enemies[3] = new Boss; enemies[4] = new SuperBoss; 24

Object Oriented Design Multiple Inheritance – Allows a class to have more than one base class – Derived class adopts characteristics of all parent classes – Huge potential for problems (clashes, casting, etc) – Multiple inheritance of abstract interfaces is much less error prone – Use pure virtual functions to create abstract interfaces. 25

class Planet { private: double gravitationalmass; public: void WarpTimeSpace() = 0; // Note pure virtual function } ; class SuperBoss: public Enemy, public Planet { }; 26

Component Systems Limitations of inheritance – Tight coupling – Unclear flow of control – Not flexible enough – Static hierarchy 27

Component Systems Component system organization – Use aggregation (composition) instead of inheritance – A game entity can “own” multiple components that determine its behavior – Each component can execute whenever the entity is updated – Messages can be passed between components and to other entities 28

Component Systems Component system organization 29

Component Systems Data-Driven Composition – The structure of the game entities can be specified in data – Components are created and loaded at runtime – Very easy to change (which is very important in game development) – Easy to implement with XML (go hierarchical databases) which has excellent parser utilities. 30

Component Systems Analysis – Very hard to debug – Performance can be a bottleneck – Keeping code and data synchronized can be a challenge – Extremely flexible Great for experimentation and varied gameplay – Not very useful if problem/game is very well known ahead of time 31

Design Patterns General solutions that to specific problems/situations that come up often in software development. Deal with high level concepts like program organization and architecture. Not usually provided as library solutions, but are implemented as needed. They are the kinds of things that you would expect a program lead, or project manager to know how to use. 32

Design Patterns Singleton – Implements a single instance of a class with global point of creation and access – Don't overuse it!!! –

Design Patterns Object Factory – Creates objects by name – Pluggable factory allows for new object types to be registered at runtime – Extremely useful in game development for creating new objects, loading games, or instantiating new content after game ships – Extensible factory allows new objects to be registered at runtime (see book.) 34

Design Patterns Object factory 35

Design Patterns Observer – Allows objects to be notified of specific events with minimal coupling to the source of the event – Two parts subject and observer – Observers register with a subject to so that they can be notified when certain events happen to the subject. 36

Design Patterns Observer 37

Design Patterns Composite – Allow a group of objects to be treated as a single object – Very useful for GUI elements, hierarchical objects, inventory systems, etc 38

Design Patterns Composite 39

Other Design Patterns Decorator Façade Visitor Adapter Flyweight Command 40

The End 41