-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwscript
More file actions
172 lines (139 loc) · 3.96 KB
/
Copy pathwscript
File metadata and controls
172 lines (139 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#! /usr/bin/env python
# encoding: utf-8
'''
@author: Milos Subotic <milos.subotic.sm@gmail.com>
@license: MIT
'''
###############################################################################
import os
import sys
import fnmatch
import shutil
import datetime
import glob
import waflib
###############################################################################
APPNAME = 'LPRS2_GPU_Emulator'
top = '.'
###############################################################################
def prerequisites(ctx):
ctx.recurse('emulator')
if sys.platform.startswith('linux'):
# Ubuntu.
ctx.exec_command2('apt-get -y install python-pil')
elif sys.platform == 'win32' and os.name == 'nt' and os.path.sep == '/':
# MSYS2 Windows /mingw32/bin/python.
ctx.exec_command2(
'pacman --noconfirm -S mingw-w64-i686-python-pillow'
)
def options(opt):
opt.load('gcc gxx')
opt.add_option(
'--app',
dest = 'app',
default = None,
help = 'App to be run'
)
opt.recurse('emulator')
def configure(cfg):
cfg.load('gcc gxx')
cfg.recurse('emulator')
cfg.env.append_value('CFLAGS', '-std=c99')
cfg.find_program(
'python',
var = 'PYTHON'
)
cfg.find_program(
'img_to_src',
var = 'IMG_TO_SRC',
exts = '.py',
path_list = os.path.abspath('.')
)
def build(bld):
bld.recurse('emulator')
digit_imgs = sorted(
glob.glob('images/red_*.png') + glob.glob('images/green_*.png')
)
bld(
rule = '${PYTHON} ${IMG_TO_SRC} -o ${TGT[0]} ${SRC} ' + \
'-f IDX4 -p 0x000000 -v',
source = digit_imgs,
target = ['sprites_idx4.c', 'sprites_idx4.h']
)
bld(
rule = '${PYTHON} ${IMG_TO_SRC} -o ${TGT[0]} ${SRC} ' + \
'-f RGB333',
source = 'images/Pacman_Sprite_Map.png',
target = ['sprites_rgb333.c', 'sprites_rgb333.h']
)
bld.program(
features = 'cxx',
source = ['project.c', 'game_data.c', 'sprites_data.c', 'fmath.c', 'sprites_renderer.c', 'raycast_renderer.c', 'player.c', 'enemy.c', 'engine.c', 'ui_renderer.c'],
includes = ['build/'],
use = 'emulator',
target = 'project',
cflags = '-g3'
)
def run(ctx):
'''./waf run --app=<NAME>'''
if ctx.options.app:
if sys.platform == 'win32':
# MSYS2
ctx.exec_command2('build\\' + ctx.options.app)
else:
ctx.exec_command2('./build/' + ctx.options.app)
###############################################################################
def exec_command2(self, cmd, **kw):
# Log output while running command.
kw['stdout'] = None
kw['stderr'] = None
ret = self.exec_command(cmd, **kw)
if ret != 0:
self.fatal('Command "{}" returned {}'.format(cmd, ret))
setattr(waflib.Context.Context, 'exec_command2', exec_command2)
###############################################################################
def recursive_glob(pattern, directory = '.'):
for root, dirs, files in os.walk(directory, followlinks = True):
for f in files:
if fnmatch.fnmatch(f, pattern):
yield os.path.join(root, f)
for d in dirs:
if fnmatch.fnmatch(d + '/', pattern):
yield os.path.join(root, d)
def collect_git_ignored_files():
for gitignore in recursive_glob('.gitignore'):
with open(gitignore) as f:
base = os.path.dirname(gitignore)
for pattern in f.readlines():
pattern = pattern[:-1]
for f in recursive_glob(pattern, base):
yield f
###############################################################################
def distclean(ctx):
for fn in collect_git_ignored_files():
if os.path.isdir(fn):
shutil.rmtree(fn)
else:
os.remove(fn)
def dist(ctx):
now = datetime.datetime.now()
time_stamp = '{:d}-{:02d}-{:02d}-{:02d}-{:02d}-{:02d}'.format(
now.year,
now.month,
now.day,
now.hour,
now.minute,
now.second
)
ctx.arch_name = '../{}-{}.zip'.format(APPNAME, time_stamp)
ctx.algo = 'zip'
ctx.base_name = APPNAME
# Also pack git.
waflib.Node.exclude_regs = waflib.Node.exclude_regs.replace(
'''
**/.git
**/.git/**
**/.gitignore''', '')
# Ignore waf's stuff.
waflib.Node.exclude_regs += '\n**/.waf*'
###############################################################################