
	include	exec/exec_lib.i
	include	wildinc.gs
	include	wild/wild.i
	include	wild/allmodules.i
	include	wild/tdcore.i
	include	extensions/vektorial.i
	include	pypermacro.i

	Exec
	lea.l	wildname,a1
	jsr	_LVOOldOpenLibrary(a6)
	move.l	d0,_WILDBase
	beq	exit
	
	bsr	Go

exit	Exec
	movea.l	_WILDBase,a1
	move.l	a1,d0
	beq.b	.nwi
.nwi	jsr	_LVOCloseLibrary(a6)
	moveq.l	#0,d0
	rts
	
vektname	dc.b	'libs:Wild/Vektorial.library',0
wildname	dc.b	'wild.library',0
drawm		dc.b	'Candy',0
dispm		dc.b	'Peter&James',0
brokm		dc.b	'TiX+',0
lighm		dc.b	'Koton',0
sincosname2	dc.b	'libs:'
sincosname1	dc.b	'wild/tables/sincos1616.table',0
basename	dc.b	'CallWild',0
info		dc.b	'That''s just a test application !',0
		cnop	0,4
_WILDBase	dc.l	0
VektBase	dc.l	0
WApp		dc.l	0
AppTags		dc.l	WITD_Scene,TestScene
		dc.l	WIAP_DrawModule,drawm
		dc.l	WIAP_DisplayModule,dispm
		dc.l	WIAP_BrokerModule,brokm
		dc.l	WIAP_LightModule,lighm
		dc.l	WIDI_Width,320
		dc.l	WIDI_Height,256
		dc.l	WIDI_DisplayID,$21000
		dc.l	WITD_CutDistance,32000
		dc.l	WIAP_PrefsHandle,0
		dc.l	WIAP_BaseName,basename
		dc.l	WIAP_Description,info
		dc.l	0
sincos		dc.l	0
SinOffs		dc.l	0
get		dc.l	WITD_Scene,0
		dc.l	0,0
		
Go	bsr	SetUpWildApp
	bsr	SetUpExts
	
cycle	Wild
	move.l	WApp,a0
	Call	InitFrame
	move.l	WApp,a0
	Call	RealyzeFrame
	move.l	WApp,a0
	Call	DisplayFrame

	move.l	SinOffs,d0
	addq.l	#8,d0
	andi.l	#1023,d0
	move.l	d0,SinOffs
	move.l	sincos,a0
	move.l	(a0,d0.l*8),d1
	asr.l	#5,d1
	move.l	d1,SECTOR_Ball+ent_Ref+ref_O+vek_X
	move.l	4(a0,d0.l*8),d0
	asr.l	#5,d0
	move.l	d0,SECTOR_Ball+ent_Ref+ref_O+vek_Z

	add.w	#8,PUI
	bmi.b	.npuir
	clr.w	PUI
.npuir	moveq.l	#0,d0
	move.b	$dff007,d0
	andi.w	#63,d0
	cmp.w	#36,d0
	bge.b	.nadpui
	move.w	PUI,d1
	sub.w	d0,d1
	cmp.w	#-255,d1
	bge.b	.ntpui
	move.w	#-255,d1
.ntpui	move.w	d1,PUI
.nadpui
	

	add.l	#-25,MyCamera+ref_O+Abs+vek_Y
	add.l	#-25,MyCamera+ref_O+Abs+vek_Z
	
	movea.l	VektBase,a6
	lea.l	MyCamera,a0
	lea.l	SECTOR_Tree+ent_Ref+ref_O+Abs,a1
	moveq.l	#1,d0
CLA

	Call	CamLookingAt

.pr	btst	#7,$bfe001
	beq.b	.pr
	
	btst	#6,$bfe001
	bne	cycle

	bsr	KillWildApp
	bsr	KillExts
	rts

SetUpExts	Wild
		moveq.l	#0,d0
		lea.l	vektname,a1
		Call	LoadExtension
		move.l	d0,VektBase
		
		rts

KillExts	Wild
		movea.l	VektBase,a1
		Call	KillExtension
		rts
		
SetUpWildApp	Exec
		Call	CreateMsgPort
		tst.l	d0
		bne.b	.msgok
		rts
.msgok		Wild
		movea.l	d0,a0
		lea.l	AppTags,a1
		Call	AddWildApp
		move.l	d0,WApp
		
		lea.l	sincosname1,a0
		moveq.l	#WITA_SINCOS1616,d0
		Call	LoadTable
		move.l	d0,sincos
		bne.b	.had
		lea.l	sincosname2,a0
		moveq.l	#WITA_SINCOS1616,d0
		Call	LoadTable
		move.l	d0,sincos
.had		rts

KillWildApp	Wild
		move.l	sincos,a1
		move.l	a1,d0
		beq.b	.nsc
		Call	KillTable
.nsc		
		move.l	WApp,d0
		bne.b	.okwa
		rts
.okwa		movea.l	d0,a0
		move.l	wap_WildPort(a0),d2
		Call	RemWildApp
		Exec
		move.l	d2,a0
		Call	DeleteMsgPort
		rts
				

TestScene	dc.l	TestWorld
MyCamera

		QuickRefAbs	0,-250,0

*		DefAbs	0,0,-100
*		DefAbs	0,1<<16,0
*		DefAbs	1<<16,0,0
*		DefAbs	0,0,1<<16

TestWorld
twarhead	dc.l	TestArena
twartail	dc.l	0
		dc.l	TestArena
twalhead	dc.l	twaltail
twaltail	dc.l	0
		dc.l	twalhead
		dc.l	TestPlayer			

TestPlayer	dc.l	0			; HAKK: no player, for now a sector is enough

TestArena	dc.l	twartail
		dc.l	twarhead
		QuickRefRel	0,328,512
		dc.l	0			; Parent of arenas is UNIVERSE! ABSOLUTE=RELATIVE
		dc.l	0
		dc.w	0
		
tasehead	dc.l	TestArenaSector
tasetail	dc.l	0	
		dc.l	TestArenaSector

taalhead	dc.l	taaltail
taaltail	dc.l	0
		dc.l	taalhead
talihead	dc.l	TestLight
talitail	dc.l	0
		dc.l	TestLight
		dcb	Sphere_SIZE*3
		dc.l	0

TestLight	dc.l	AmbLight,talihead
		dc.l	DOT_Ball1
		dc.l	$0055ff
		dc.w	64

AmbLight	dc.l	talitail,TestLight
		dc.l	0
		dc.l	$ffca22
		dc.w	-16
		
PUI		dc.w	-16
	
TextTex		dc.l	0,0
		dc.l	Imge2

Imge2		incbin	WildPJ:Trash/256x256.chu

TEXTURE_Tree0	EQU	TextTex
TEXTURE_Tree2	EQU	TextTex
TEXTURE_Tree3	EQU	TextTex
TEXTURE_Tree1	EQU	TextTex
TEXTURE_Platform0 EQU	TextTex
TEXTURE_Platform1 EQU	TEXTURE_Platform0

TestArenaSector	

		MakeSector	Tree,wildpj:support/testsectors/tree3.s
		MakeSector	Ball,wildpj:support/testsectors/ball.s
		MakeSector	Platform,wildpj:support/testsectors/platform3.sec.s

		LinkSector 	Tree,SECTOR_Ball,tasehead,TestArena
		LinkSector 	Ball,SECTOR_Platform,SECTOR_Tree,SECTOR_Tree
		LinkSector 	Platform,tasetail,SECTOR_Tree,TestArena
		
		PosSector	Platform,0,0,0
	
; Ball has 16 Faces
; Platform has 30 Faces
; Tree has 15 Faces

; total is 61 faces =$3d
	
																								