MakerGame Game Programming Language Outline Motivation Features - - PowerPoint PPT Presentation

makergame
SMART_READER_LITE
LIVE PREVIEW

MakerGame Game Programming Language Outline Motivation Features - - PowerPoint PPT Presentation

Cindy Wang Steven Shao Yuncheng Jiang MakerGame Game Programming Language Outline Motivation Features Runtime Architecture & Tests Demo Motivation Game Maker C/C++ Game asset management A real programming language


slide-1
SLIDE 1

MakerGame

Game Programming Language

Cindy Wang Steven Shao Yuncheng Jiang

slide-2
SLIDE 2

Outline

  • Motivation
  • Features
  • Runtime
  • Architecture & Tests
  • Demo
slide-3
SLIDE 3

Motivation

Game Maker

  • Game asset management
  • Graphics, sounds, input built in
  • Entity resource handling
  • Execution flow following object

lifetimes

C/C++

  • A real programming language
  • Arbitrary data structures - arrays
  • Object & Library encapsulation -

methods, namespaces

  • Fast - a blank slate
slide-4
SLIDE 4

Motivation

  • GameMaker for programmers
  • Gems from both worlds

○ General collections ○ Objects & inheritance ○ Event-driven ○ Standard library & types for games

slide-5
SLIDE 5

Features

  • C with "objects"
  • Entity life & event handling
  • External linking & libraries
slide-6
SLIDE 6

C with Objects - Types & Functions

int x = 3 + 5; float pi = 3.14; bool answer = true; int table[2][3] = [[1,2,3],[4,5,6]]; string file = "player.png"; sprite p = std::spr::load(file); sound q = std::snd::load("bonk.ogg"); int square(int x) { return x * x; } int sum(int x[2]) { return x[0] + x[1]; }

slide-7
SLIDE 7

C with Objects - Control Flow

if (x < 100) x += 3; else { x = 100; hit_end = true; } while (!settled) { moveDown(); } { int x = 3; } for (int i = 0; i < n; ++i) { sum += i; if (tooHigh(sum)) break; }

slide-8
SLIDE 8

C with Objects - Objects

Definition

  • bject Player {

int x; int y; ... int getHealth() { ... } ... event create(...) { ... } event step { ... } event draw { ... } event destroy { ... } } Manipulation

void doStuff(Enemy e) {

  • bject o = none;

Player p = create Player(...);

  • bject m = p;

int y = p.getHealth(); p.x = 3; if (p == o) { ... } destroy e; }

slide-9
SLIDE 9

C with Objects - Inheritance

Definition

  • bject Enemy {

int health; sprite s; bool touchingPlayer() { ... } event create(int hp) { ... } event step { ... } event draw { ... } event destroy { ... } }

Inheritance

  • bject Missile : Enemy {

event create() { super(100); s = spr::load("missile.png"); } void explode() { ... } event destroy() { if (touchingPlayer()) explode(); super(); } }

slide-10
SLIDE 10

C with Objects - Modules

Nested Namespaces

namespace math { int square(int x) { ... } extern float sin(float x); }

Access Levels

namespace spr { private namespace p { extern sprite load_sprite(...); } sprite load(...) { ... } } ... { spr::p::load_sprite(...); }

Files & Scope

// from MAKERGAME_PATH namespace math = open "math.mg"; namespace spr = open "spr.mg"; using math; ... { ... sprite s = spr::load(...); int x = pi; float y = sin(5); ... }

slide-11
SLIDE 11

Entity Life & Event Handling

Key Operation: Iteration foreach (Enemy e) { if (colliding(e, this)) {

  • -health;

destroy e; } } Examples

void destroyAllButMe(object m) { foreach (object o) { if (o != m) destroy o; } } bool isAlive(object m) { foreach (object o) if (o == m) return true; return false; }

slide-12
SLIDE 12

create main foreach (object o) "step o;" noop foreach (object o) "draw o;" loop break game::end(); timeout after 100 steps global_create() global_step() global_draw()

slide-13
SLIDE 13

Life & Event Handling: Runtime

global_create() global_step(); window.clear(); global_draw(); cleanup(); end_game(); window.display(); sleep();

slide-14
SLIDE 14

Life & Event Handling: Runtime

Sample functions: void printb(bool b) void print(int x) ... sf::Sound *load_sound(...) sf::Sprite *load_image(...) void draw_sprite(sf::Sprite *, ...) void play_sound(sf::Sound *, ...) ... bool key_pressed(int code) { ... } ... void set_window_size(...) void set_window_clear(...) void end_game()

Accessing from MakerGame

extern sound load_sound(...); { sound s = load_sound(...); } (extern definitions in std.mg)

slide-15
SLIDE 15

child members

Life & Event Handling: Objects

parent L node R

  • bject

vptr id L node R vtable step destroy draw delete enemy health x y

  • bject

vptr id L node R L node R

Anatomy of an

  • bject

The universal parent Example

slide-16
SLIDE 16

player (player node) ... ... enemy health x y enemy health x y

  • bject

vptr id

Life & Event Handling: Objects

  • bject

vptr id L head R

  • bject

vptr id L node R enemy head L R L node R L node R L node R L node R

slide-17
SLIDE 17

Full Sample Program

  • bject Player {

sprite spr; int x; int y; event create { spr = spr::load("res/player.png"); x = 350; y = 500; } event step { if (key::is_down(key::Left)) x -= 5; if (key::is_down(key::Right)) x += 5; } event draw { spr::render(spr, x, y); } }

  • bject main { event create { create Player; } }
slide-18
SLIDE 18

Compiler Architecture

AST contains: functions objects variables namespaces Semant SAST: namespaces resolved type annotations Codegen standard input Scanner Parser game.ll: global_create, step, draw, etc. LLC gcc libmakergame.cpp libmakergame.a linker game.s game.exe

slide-19
SLIDE 19

Testing: The tests

  • Unit tests - language features

○ 410 tests

  • Games - runtime, stress testing

○ Egg drop ○ Tetris

slide-20
SLIDE 20

Testing: Compiler Architecture

AST contains: functions objects variables namespaces Semant SAST: namespaces resolved type annotations Codegen standard input Scanner Parser game.ll: global_create, step, draw, etc. LLC gcc libtestergame.cpp libtestergame.a linker game.s game.exe

slide-21
SLIDE 21

Testing: Unit Test Framework

create main foreach (object o) "step o;" window.clear(); foreach (object o) "draw o;" cleanup(); game::end(); window.display(); sleep();

slide-22
SLIDE 22

Testing: Unit Test Framework

create main foreach (object o) "step o;" noop foreach (object o) "draw o;" loop break game::end(); fail after 100 steps (timeout)

slide-23
SLIDE 23

Testing: Unit Tests

// basic features: arrays int make_ten_of[10](int x) { int ret[10]; int i; for (i = 0; i < 10; ++i) ret[i] = x; return ret; }

  • bject main {

event create { int i = 3; int j[10] = make_ten_of(5); std::print::i(j[i]); std::game::end(); } }

// complex game loop cases

  • bject parent { void detonate() { destroy this; } }
  • bject child : parent { }
  • bject main {

int j; event create { j = 0; } event step { for (int i = 0; i < 10; ++i) create child; for (int i = 0; i < 10; ++i) create parent; int i = 0; foreach (child c) c.detonate(); foreach (parent c) ++i; std::print::i(i); ++j; if (j >= 6) std::game::end(); } }

slide-24
SLIDE 24

Testing: Demos

slide-25
SLIDE 25

Thank you! Questions?