
	IFND	WILD
WILD	SET	1 
		
		include	exec/lists.i
		include	exec/types.i
		include	exec/libraries.i
		include	utility/tagitem.i

***************************************************************************************
***	My SUPERB library base !! HAhAhhahahaaaah!!				*******
***************************************************************************************
		
		STRUCTURE	WildBASE,LIB_SIZE+4
			LONG	wi_FastPool
			LONG	wi_ChipPool
			APTR	wi_UtilityBase
			APTR	wi_IntuitionBase
			APTR	wi_GraphicsBase
			APTR	wi_DOSBase
			APTR	wi_XpkBase
			STRUCT	wi_MORELIBS,12
			BYTE	wi_WhyFail
			BYTE	wi_Hole000
			STRUCT	wi_Apps,MLH_SIZE
			STRUCT	wi_Modules,MLH_SIZE
			STRUCT	wi_Threads,MLH_SIZE
			STRUCT	wi_Tables,MLH_SIZE
			STRUCT	wi_Extensions,MLH_SIZE		
			STRUCT	wi_MORELISTS,MLH_SIZE*3
			LONG	wi_Ticker		; 1/50 sec ticker.
			LABEL	wi_SIZEOF

***************************************************************************************
***	The WildApp and the WildEngine!						*******
***************************************************************************************

		STRUCTURE	WildEngine,0
			APTR	we_Display		; DisplayModule
			APTR	we_TDCore		; TDCoreModule
			APTR	we_Light		; LightModule
			APTR	we_Draw			; DrawModule
			APTR	we_FX			; FXModule
			APTR	we_Sound		; SoundModule
			APTR	we_Music		; MusicModule
			APTR	we_Broker		; BrokerModule
			STRUCT	we_IsAnyFuture,4*9	; Future modules !?!?!?!?!!?
			LABEL	we_SIZEOF

		STRUCTURE	WildTypes,0		; Just not to write twice or more those a,b,c,d,..
			BYTE	wy_TypeA
			BYTE	wy_TypeB
			BYTE	wy_TypeC
			BYTE	wy_TypeD
			BYTE	wy_TypeE
			BYTE	wy_TypeF
			BYTE	wy_TypeG
			BYTE	wy_TypeH
			LABEL	wy_SIZEOF		; wy_ to not conflict with wildthread

		STRUCTURE	WildApp,MLN_SIZE
			APTR	wap_WildPort		; MSGPort
			APTR	wap_WildBase		; ptr to wild.library base !
			APTR	wap_Tags		; Taglist containing all tags, modified by the user with setwildapptags or addwildapp taglist.
			LONG	wap_Flags		; App Flags
			APTR	wap_ChipPool
			APTR	wap_FastPool
			STRUCT	wap_Engine,we_SIZEOF	; The module's library bases, to call
			STRUCT	wap_EngineData,we_SIZEOF ; The module's data, used ONLY by the modules, for their own structs.
			APTR	wap_FrameBuffer		; The bitmap, or chunky buffer, depending on the Display type.
			APTR	wap_Scene		; The scene visualized by the tdcore
			STRUCT	wap_Types,wy_SIZEOF	; The app types, to verify compatibility with engine!
			LABEL	wap_SIZEOF

; NOTE: wap-Tags now contains ALL TAGS OF EVERYTHING! Modules,App,anything is here!

	BITDEF	WA,RefreshEngine,16			; That flag is checked on every Realyze Call. If it's set, all the modules are called to a refresh.
							; User should not use it, it's just used by modules, when some tags change, to avoid 10000 screen closing, opening, paletting,....
	BITDEF	WA,FreeFastPool,24			; That is used by Wild: should free fast pool in RemWildApp?
	BITDEF	WA,FreeChipPool,25			; Same.

***************************************************************************************
***	Threads definitions.							*******
***************************************************************************************

		STRUCTURE	WildThread,MLN_SIZE	; This struct is passed to your thread by A0 ! Read here your args !
			APTR	wt_WildBase
			APTR	wt_WildPort		; a message port to communicate!
			APTR	wt_WildApp		; usually, the thread refers to a singular app!
			APTR	wt_FastPool		; two pools
			APTR	wt_ChipPool		
			WORD	wt_TimeOut		; timeout, after sending the kill-signal: expired, hard-killing will be performed !
			WORD	wt_DieCheck		; INTERNAL:needed to check if the process is dead, after a kill message... (DO NOT USE)
			APTR	wt_Entry		; entry point (initial PC)
			APTR	wt_Args			; args you passsed with the tag.
			APTR	wt_Process		; the process created by dos
			LABEL	wt_SIZE			

		STRUCTURE	WildMessage,MN_SIZE
			LONG	wm_Type			; Longword, says the type of message this is.
			LABEL	wm_Data			; then, the data

; STD Wild messages types (to his threads)

WIME_Kill	EQU	'Kill'				; Kill yourself as fast as you can ! (after the timeout, you will be killed hardly!)
WIME_Freeze	EQU	'Friz'				; Take a coffee, stop doing what you are doing...
WIME_WarmUp	EQU	'Warm'				; Was good the coffee ?? RESTART SUDDENTLY YOUR WORK !!!!

***************************************************************************************
***	Tags for any use...							*******
***************************************************************************************

WILD_TAGBASE	EQU	TAG_USER+$0AEAE000	; Wild standard tags

WILD_USERBASE	EQU	WILD_TAGBASE+$10000000	; User tags with NO prefs support

WILD_PREFSBASE	EQU	WILD_USERBASE+$10000000	; User tags with prefs support (saved and loaded and editable)

WILD_SIMPLEPREFSBASE	EQU	WILD_PREFSBASE	; User tags with prefs support, type simple
						; (ti_Data is not a pointer, but a direct data
						; like booleans or constants)

WILD_COMPLEXPREFSBASE	EQU	WILD_PREFSBASE+$10000000	; User data tags with
						; prefs support, type complex, so the
						; wildprefs.library will look for a	
						; zero-terminated string. That's good
						; for names or files.		

;WildApp tags 

WIAP_DisplayModule	EQU	WILD_TAGBASE+1	; Specify your preferred displaymodule
WIAP_TDCoreModule	EQU	WILD_TAGBASE+2	; Same for TDCore
WIAP_LightModule	EQU	WILD_TAGBASE+3	; Same for Light
WIAP_DrawModule		EQU	WILD_TAGBASE+4	; Same for Draw
WIAP_FXModule		EQU	WILD_TAGBASE+5	; Same for SFX
WIAP_SoundModule	EQU	WILD_TAGBASE+6	; Same for Sound
WIAP_MusicModule	EQU	WILD_TAGBASE+7	; Same for Music
WIAP_BrokerModule	EQU	WILD_TAGBASE+16 ; Same for Broker (added then, so 16)
						; If some modules are not specified,
						; WILD will assign some defaults.
						; If they are not compatible, WILD will
						; look for the best ones basing on your
						; speed&quality requests.
WIAP_Speed		EQU	WILD_TAGBASE+8	; This tag is used to specify your speed
						; requidement: the value range is
						; 0 (min speed) to 255 (max speed)
						; Default is 128. 
WIAP_Quality		EQU	WILD_TAGBASE+9	; Same for quality. Default is 64.
WIAP_FastPoolPuddles	EQU	WILD_TAGBASE+10	; Fast pool size of Puddles. See exec autodoc. Default: 8k
WIAP_ChipPoolPuddles	EQU	WILD_TAGBASE+11 ; Same. IF YOU SPECIFY 0, NO POOL WILL BE CREATED! Default:8k
WIAP_FastPoolThresh	EQU	WILD_TAGBASE+12	; Fast pool size of Thresh. default:4k
WIAP_ChipPoolThresh	EQU	WILD_TAGBASE+13	; Same. default: 4k
WIAP_TypeABCD		EQU	WILD_TAGBASE+14	; Data: $aabbccdd types.
WIAP_TypeEFGH		EQU	WILD_TAGBASE+15	; Data: $eeffgghh types. For non defined types (efgh,for now) set 0 (=FULLCOMPATIBLE)
WIAP_Name		EQU	WILD_TAGBASE+17	; The full name of the app
WIAP_BaseName		EQU	WILD_TAGBASE+18	; A simple name for the app: Just one word, not too long: used for prefs files and to identify in Wild an application.
WIAP_MAXTAG		EQU	WIAP_BaseName
WIAP_MINTAG		EQU	WIAP_DisplayModule

;Display tags

WIDI_Width		EQU	WILD_TAGBASE+50	; Width in pixels of the view
WIDI_Height		EQU	WILD_TAGBASE+51	; Height in pixels of the view
WIDI_PixelRes		EQU	WILD_TAGBASE+52	; Pixels resolution
WIDI_Screen		EQU	WILD_TAGBASE+53	; Use this tag to make WILD try to use your 
						; screen. IT MAY OR MAY NOT BE USED !
						; CheckDisplay is called on your DisplayModule
						; and if it returns null, it opens its custom
						; display. You can even close your screen.
						; To check, compare your screen and view->screen
WIDI_Depth		EQU	WILD_TAGBASE+54	; Default 8. Obviously, use it when make
						; sense: not on TrueColor Displays !
						; If the requested depth is not available
						; DisplayModule should fail.
WIDI_Palette		EQU	WILD_TAGBASE+55 ; Palette to use. Use if make sense.
WIDI_DisplayID		EQU	WILD_TAGBASE+56	; DisplayID mode. NB: Must support the other
						; requidements. In the future will be checked,
						; but not now.
WIDI_MAXTAG		EQU	WIDI_DisplayID
WIDI_MINTAG		EQU	WIDI_Width

; values for PixelRes
PXRS_Full		EQU	1		; 1x1	Just indicative... do what you want...
PXRS_High		EQU	2		; 1x2	
PXRS_Med		EQU	3		; 2x1
PXRS_Low		EQU	4		; 2x2
PXRS_Worst		EQU	5		; 4x4

;TDCore tags
WITD_Scene		EQU	WILD_TAGBASE+100 ; Use this to set the scene. If the engine 
						 ; is rendering, the change will be reached
						 ; on next frame
WITD_CutDistance	EQU	WILD_TAGBASE+101 ; The objects more far from the screen
						 ; of this Z are not displayed. (default 1000)
WITD_MAXTAG		EQU	WITD_CutDistance
WITD_MINTAG		EQU	WITD_Scene

WILD_DEFINEDTAGSNUM	EQU	WIAP_MAXTAG-WIAP_MINTAG+1+WIDI_MAXTAG-WIDI_MINTAG+1+WITD_MAXTAG-WITD_MINTAG+1

;wildthreads tags

WITH_Priority		EQU	WILD_TAGBASE+970	; default 0
WITH_TimeOut		EQU	WILD_TAGBASE+971	; default 100 (2 secs) Wait when killing before eliminating automatically.
WITH_Entry		EQU	WILD_TAGBASE+972	; REQUIDED - It's the initial PC.
WITH_Args		EQU	WILD_TAGBASE+973	; REQUIDED - Are the initial args.
WITH_Name		EQU	WILD_TAGBASE+974	; Name of the "New Process" (default: "Wild generic thread...")
WITH_Stack		EQU	WILD_TAGBASE+975	; stack size (default 4096)

***************************************************************************************
***	Modules struts and types.						*******
***************************************************************************************

		STRUCTURE	WildModuleBASE,LIB_SIZE+4
			STRUCT	wm_Node,MLN_SIZE	; To insert in the modules list.
			APTR	wm_WildBase		; to have it always.
			WORD	wm_CNT			; my usecnt to avoid double opening.
			STRUCT	wm_Types,wy_SIZEOF
			LABEL	wm_SIZEOF

TYPEA_FULLCOMPATIBLE	EQU	0		
TYPEA_TD_STD		EQU	1		; Type A 1: Are the std structs ones.

TYPEB_FULLCOMPATIBLE	EQU	0
TYPEB_DI_FRIENDLYPLANAR	EQU	1		; Type B 1: Is a standard planar screen.
TYPEB_DI_CHUNKY8	EQU	2		; Type B 2: Uses a 256 colors chunky (ONLY 256 colors, 24Bit,6Bit,4Bit chunky MAY be supported in the future by OTHER TYPES).

TYPEC_FULLCOMPATIBLE	EQU	0		
TYPEC_DW_ONLYX		EQU	1		; Type C 1: drawing. 1 means the broker gives only the x steps and starts.
TYPEC_DW_SHADING	EQU	2		; Type C 2: drawing. 2 means the broker gives the x,i steps and starts.
TYPEC_DW_RGBSHADING	EQU	3		; Type C 3: drawing. 3 means the broker gives the x,r,tg,b steps and starts.
TYPEC_DW_TEX		EQU	4		; Type C 4: drawing. 4 means the broker gives the x,tx,ty steps and starts.
TYPEC_DW_SHADINGTEX	EQU	5		; Type C 5: drawing. 5 means the broker gives the x,i,tx,ty steps and starts.
TYPEC_DW_RGBSHADINGTEX	EQU	6		; Type C 6: drawing. 6 means the broker gives the x,r,g,b,tx,ty steps and starts.

TYPED_FULLCOMPATIBLE	EQU	0
TYPED_LI_FLATINTENSITY	EQU	1		; Type D 1: Is a FACE lighting, no shading,just intensity.
TYPED_LI_FLATCOLOR	EQU	2		; Type D 2: Is a FACE lighting, but using 24bit colors.
TYPED_LI_SOFTINTENSITY	EQU	3		; Type D 3: Is a POINT lighting, to use with linear interpolations, gouraud shadings.


TYPEE_FULLCOMPATIBLE	EQU	0
TYPEF_FULLCOMPATIBLE	EQU	0
TYPEG_FULLCOMPATIBLE	EQU	0
TYPEH_FULLCOMPATIBLE	EQU	0

; Note about the FULLCOMPATIBLE type.
; This means there are no compatibility problems for this module.
; For example, the PyperGrey32 module if TYPEC_FULLCOMPATIBLE,
; because you can use any broker, it will work, because it uses
; no broker structs, so you can (you SHOULD) obmit to use the broker.
; The FULLCOMPATIBLE type should be used by modules that use his own 
; structs, and bypasses any of the pipeline parts, so don't need
; any precalc or anything made by anyother module.
; USE WITH EXTREME CARE !
			
; Note about the wm_TypeABCD: IT'S NOT TO IDENTIFY THE Display,TDCore,Light,Sound
; or more module type: THIS IS DONE BY SEPARING THEM INTO DIFFERENT DIRS.
; IT'S TO DETERMINE THE TYPE OF MODULE, so the data structs it uses, the
; things it calcs, the maths is uses, and so.
; For example: tdcore modules of Type 1 have a certain TMPData for Points,
; for faces, for edges and more.
; This value is used to verify the correct working of an engine.
; Actually, a well working engine must have these equal types:

; TypeA: TYPEA_TD)TDCore=Light=Broker=Draw=PostFX=WApp=Extensions
; TypeB: TYPEB_DI)Draw=Display=PostFX=WApp=Extensions 
; TypeC: TYPEC_DW)Broker=Draw=PostFX=Extensions
; TypeD: TYPED_SN)Music=Sound=WApp=Extensions TYPED_LI) Light=Broker=Draw

; 1:Obviolsly,3D structs have to be the same! (also for broker,draw&more: the offsets are set by TDCore!)
; 2:More to define...
; 3:Obviously,the frame buffer type requided must be the same! (planar,chunky,..)
; 4:Broker have to interpret the light's structs: they may be different, and use color OR intensity.
; 5:Draw have to interpret Broker's struct, and PostFX may also use them, and surely have to life with Draw.
; NB: Unused TYPES MUST BE SET TO 0 !!!!!!!
**; There will also be a special type: the $ff, wich means a module full compatible.
**; Obviously, it would not be, so the user is responsible of what happens, and the
**; coder must specify what modules will be compatible to its. Useful if someone wants
**; to re-write all the pipeline, or a big part, and doesn't like all my types.
; NB2: Also WApp has his types. So, you have to use types you are sure to be possible.
; Or you have to write new modules for your types.
; NB3: wm_TypeEFGH have the same use, but now are not necessary. So, set them to fullcompatible.

***************************************************************************************
***	Extensions def								*******
***************************************************************************************

; First of all, info about extensions: they are COMPLETELY STANDALONE Libraries, the
; only thing they have to match with WILD is the TYPE checking, for compatibility
; with the engine. The LoadExtension function of wild JUST OPENS THE LIB AND CHECKS
; THE TYPE MATCHING, NO MORE !!!!!!!! And the KillExtension just CLOSES THE LIB.
; NB: The wi_Extensions WILL BE USED IN THE FUTURE, JUST TO HAVE AUTOMATIC
; CLOSE OF ALL Exts when Expugning Wild, like modules now. But not now.

		STRUCTURE	WildExtensionBASE,wm_SIZEOF
			LABEL	wx_SIZEOF

; Library base exactly the same of the modules one.

***************************************************************************************
***	Table struct and used IDS.						*******
***************************************************************************************

		STRUCTURE	WildTable,MLN_SIZE
			LONG	wt_ID			; a ID to identify the table when you use it
			WORD	wt_CNT			; opencount, like libs.
			LABEL	wt_Data

; NB: When using LoadTable, the returned d0 points to wt_Data direclty: you don't
; have to add wt_Data to d0 to reach the data. And when KillTable, you don't have
; to sub wt_Data to the precedent result: Wild does for you.

; Here are defined all the ids for the currently used tables.
; I define them here just to avoid the risk of double-used IDs. (32Bit! should be difficult!)

WITA_COSQTOSEN		EQU	1	; converts cos^2 (8 bit) to sen (^1 !) 8 bit. (never used, probably never will...)
WITA_PYTREE		EQU	2	; used by PyTree macro. It's scalable ! (may have different sizes!)
WITA_SINCOS1616		EQU	3	; contains 1024 sincos in 16.16 format. 8k.

***************************************************************************************
***	Wild possible errors 							*******
***************************************************************************************

WILDERR_NOMEM		EQU	1		; Not enough memory to do something
WILDERR_BADARGS		EQU	2		; Bad arguments passed (0 ports, 0 module type/name,...?)

; Read them in wi_WhyFail (in WildBase struct) after the failed call. May help to
; comprend.

***************************************************************************************
***	_LVO definitions and std macros.					*******
***************************************************************************************
		
_LVOAddWildApp		EQU	-30		; A0:MSGPort,A1:Tags
_LVORemWildApp		EQU	-36		; A0:WildApp
_LVOLoadModule		EQU	-42		; A0:Type,A1:Name
_LVOKillModule		EQU	-48		; A1:Module
_LVOSetWildAppTags	EQU	-54		; A0:App,A1:Tags
_LVOGetWildAppTags	EQU	-60		; A0:App,A1:Tags
_LVOAddWildThread	EQU	-66		; A0:WildApp,A1:Tags
_LVORemWildThread	EQU	-72		; A0:Thread
_LVOAllocVecPooled	EQU	-78		; D0:Size,A0:Pool
_LVOFreeVecPooled	EQU	-84		; A1:Memory
_LVORealyzeFrame	EQU	-90		; A0:WildApp
_LVOInitFrame		EQU	-96		; A0:WildApp
_LVODisplayFrame	EQU	-102		; A0:WildApp
_LVOLoadTable		EQU	-108		; A0:Filename,D0:ID
_LVOKillTable		EQU	-114		; A1:Table
_LVOLoadFile		EQU	-120		; D0:Offset,D1:Name
_LVOLoadExtension	EQU	-126		; A1:LibName,A0:Version
_LVOKillExtension	EQU	-132		; A1:Extension

Wild	MACRO
	movea.l	_WILDBase,a6
	ENDM

CallWild	MACRO
		Wild
		jsr	_LVO\1(a6)
		ENDM
		
	ENDC