Initial commit.
This commit is contained in:
commit
08a613ed0e
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.dsw eol=crlf
|
||||
*.dsp eol=crlf
|
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
*.sbl
|
||||
*.plg
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opt
|
||||
Debug
|
||||
Release
|
||||
*__Win32_*
|
||||
|
396
asm_makeinsts/asm_insts.cpp
Normal file
396
asm_makeinsts/asm_insts.cpp
Normal file
@ -0,0 +1,396 @@
|
||||
//
|
||||
//This is generated code - do not modify!!!!!
|
||||
//
|
||||
|
||||
#include "insts.h"
|
||||
|
||||
const Inst *insts={
|
||||
"aaa",0,0,0,"\x37",
|
||||
"aas",0,0,0,"\x3F",
|
||||
"aad",0,0,0,"\xD5\x0A",
|
||||
"0",IMM,0,IB,"\xD5",
|
||||
"aam",0,0,0,"\xD4\x0A",
|
||||
"0",IMM,0,IB,"\xD4",
|
||||
"adc",R_M8,REG8,_R,"\x10",
|
||||
"0",R_M16,REG16,O16|_R,"\x11",
|
||||
"0",REG8,R_M8,_R,"\x12",
|
||||
"0",REG16,R_M16,O16|_R,"\x13",
|
||||
"0",R_M8,IMM8,_2|IB,"\x80",
|
||||
"0",R_M16,IMM16,O16|_2|IW,"\x81",
|
||||
"0",R_M16,IMM8,O16|_2|IB,"\x83",
|
||||
"0",AL,IMM8,IB,"\x14",
|
||||
"0",AX,IMM16,O16|IW,"\x15",
|
||||
"add",R_M8,REG8,_R,"\x00",
|
||||
"0",R_M16,REG16,O16|_R,"\x01",
|
||||
"0",REG8,R_M8,_R,"\x02",
|
||||
"0",REG16,R_M16,O16|_R,"\x03",
|
||||
"0",R_M8,IMM8,_0|IB,"\x80",
|
||||
"0",R_M16,IMM16,O16|_0|IW,"\x81",
|
||||
"0",R_M16,IMM8,O16|_0|IB,"\x83",
|
||||
"0",AL,IMM8,IB,"\x04",
|
||||
"0",AX,IMM16,O16|IW,"\x05",
|
||||
"and",R_M8,REG8,_R,"\x20",
|
||||
"0",R_M16,REG16,O16|_R,"\x21",
|
||||
"0",REG8,R_M8,_R,"\x22",
|
||||
"0",REG16,R_M16,O16|_R,"\x23",
|
||||
"0",R_M8,IMM8,_4|IB,"\x80",
|
||||
"0",R_M16,IMM16,O16|_4|IW,"\x81",
|
||||
"0",R_M16,IMM8,O16|_4|IB,"\x83",
|
||||
"0",AL,IMM8,IB,"\x24",
|
||||
"0",AX,IMM16,O16|IW,"\x25",
|
||||
"arpl",R_M16,REG16,_R,"\x63",
|
||||
"bound",REG16,MEM,O16|_R,"\x62",
|
||||
"bsf",REG16,R_M16,O16|_R,"\x0F\xBC",
|
||||
"bsr",REG16,R_M16,O16|_R,"\x0F\xBD",
|
||||
"bt",R_M16,REG16,O16|_R,"\x0F\xA3",
|
||||
"0",R_M16,IMM8,O16|_4|IB,"\x0F\xBA",
|
||||
"btc",R_M16,REG16,O16|_R,"\x0F\xBB",
|
||||
"0",R_M16,IMM8,O16|_7|IB,"\x0F\xBA",
|
||||
"btr",R_M16,REG16,O16|_R,"\x0F\xB3",
|
||||
"0",R_M16,IMM8,O16|_6|IB,"\x0F\xBA",
|
||||
"bts",R_M16,REG16,O16|_R,"\x0F\xAB",
|
||||
"0",R_M16,IMM,O16|_5|IB,"\x0F\xBA",
|
||||
"call",IMM,0,0,"\xE8",
|
||||
"0",R_M16,0,O16|_2,"\xFF",
|
||||
"cbw",0,0,O16,"\x98",
|
||||
"cwd",0,0,O16,"\x99",
|
||||
"clc",0,0,0,"\xF8",
|
||||
"cld",0,0,0,"\xFC",
|
||||
"cli",0,0,0,"\xFA",
|
||||
"clts",0,0,0,"\x0F\x06",
|
||||
"cmc",0,0,0,"\xF5",
|
||||
"cmovcc",REG16,R_M16,O16|PLUSCC|_R,"\x0F\x40",
|
||||
"cmp",R_M8,REG8,_R,"\x38",
|
||||
"0",R_M16,REG16,O16|_R,"\x39",
|
||||
"0",REG8,R_M8,_R,"\x3A",
|
||||
"0",REG16,R_M16,O16|_R,"\x3B",
|
||||
"0",R_M8,IMM8,_0|IB,"\x80",
|
||||
"0",R_M16,IMM16,O16|_0|IW,"\x81",
|
||||
"0",R_M16,IMM8,O16|_0|IB,"\x83",
|
||||
"0",AL,IMM8,IB,"\x3C",
|
||||
"0",AX,IMM16,O16|IW,"\x3D",
|
||||
"cmpsb",0,0,0,"\xA6",
|
||||
"cmpsw",0,0,O16,"\xA7",
|
||||
"cmpxchg",R_M8,REG8,_R,"\x0F\xB0",
|
||||
"0",R_M16,REG16,O16|_R,"\x0F\xB1",
|
||||
"cmpxchg486",R_M8,REG8,_R,"\x0F\xA6",
|
||||
"0",R_M16,REG16,O16|_R,"\x0F\xA7",
|
||||
"cmpxchg8b",MEM,0,_1,"\x0F\xC7",
|
||||
"cpuid",0,0,0,"\x0F\xA2",
|
||||
"daa",0,0,0,"\x27",
|
||||
"das",0,0,0,"\x2F",
|
||||
"dec",REG16,0,O16|PLUSREG,"\x48",
|
||||
"0",R_M8,0,_1,"\xFE",
|
||||
"0",R_M16,0,O16|_1,"\xFF",
|
||||
"div",R_M8,0,_6,"\xF6",
|
||||
"0",R_M16,0,O16|_6,"\xF7",
|
||||
"emms",0,0,0,"\x0F\x77",
|
||||
"enter",IMM,IMM,IW|IB,"\xC8",
|
||||
"f2xm1",0,0,0,"\xD9\xF0",
|
||||
"fabs",0,0,0,"\xD9\xE1",
|
||||
"fadd",MEM32,0,_0,"\xD8",
|
||||
"fchs",0,0,0,"\xD9\xE0",
|
||||
"fclex",0,0,0,"\x9B\xDB\xE2",
|
||||
"fnclex",0,0,0,"\xDB\xE2",
|
||||
"fcom",MEM32,0,_2,"\xD8",
|
||||
"fcomp",MEM32,0,_3,"\xD8",
|
||||
"fcompp",0,0,0,"\xDE\xD9",
|
||||
"fcos",0,0,0,"\xD9\xFF",
|
||||
"fdecstp",0,0,0,"\xD9\xF6",
|
||||
"fdisi",0,0,0,"\x9B\xDB\xE1",
|
||||
"fndisi",0,0,0,"\xDB\xE1",
|
||||
"feni",0,0,0,"\x9B\xDB\xE0",
|
||||
"fneni",0,0,0,"\xDB\xE0",
|
||||
"fdiv",MEM32,0,_6,"\xD8",
|
||||
"fdivr",MEM32,0,_0,"\xD8",
|
||||
"fiadd",MEM16,0,_0,"\xDE",
|
||||
"0",MEM32,0,_0,"\xDA",
|
||||
"ficom",MEM16,0,_2,"\xDE",
|
||||
"0",MEM32,0,_2,"\xDA",
|
||||
"ficomp",MEM16,0,_3,"\xDE",
|
||||
"0",MEM32,0,_3,"\xDA",
|
||||
"fidiv",MEM16,0,_6,"\xDE",
|
||||
"0",MEM32,0,_6,"\xDA",
|
||||
"fidivr",MEM16,0,_0,"\xDE",
|
||||
"0",MEM32,0,_0,"\xDA",
|
||||
"fild",MEM16,0,_0,"\xDF",
|
||||
"0",MEM32,0,_0,"\xDB",
|
||||
"fist",MEM16,0,_2,"\xDF",
|
||||
"0",MEM32,0,_2,"\xDB",
|
||||
"fistp",MEM16,0,_3,"\xDF",
|
||||
"0",MEM32,0,_3,"\xDB",
|
||||
"fimul",MEM16,0,_1,"\xDE",
|
||||
"0",MEM32,0,_1,"\xDA",
|
||||
"fincstp",0,0,0,"\xD9\xF7",
|
||||
"finit",0,0,0,"\x9B\xDB\xE3",
|
||||
"fninit",0,0,0,"\xDB\xE3",
|
||||
"fisub",MEM16,0,_4,"\xDE",
|
||||
"0",MEM32,0,_4,"\xDA",
|
||||
"fisubr",MEM16,0,_5,"\xDE",
|
||||
"0",MEM32,0,_5,"\xDA",
|
||||
"fld",MEM32,0,_0,"\xD9",
|
||||
"fld1",0,0,0,"\xD9\xE8",
|
||||
"fldl2e",0,0,0,"\xD9\xEA",
|
||||
"fldl2t",0,0,0,"\xD9\xE9",
|
||||
"fldlg2",0,0,0,"\xD9\xEC",
|
||||
"fldln2",0,0,0,"\xD9\xED",
|
||||
"fldpi",0,0,0,"\xD9\xEB",
|
||||
"fldz",0,0,0,"\xD9\xEE",
|
||||
"fldcw",MEM16,0,_5,"\xD9",
|
||||
"fldenv",MEM,0,_4,"\xD9",
|
||||
"fmul",MEM32,0,_1,"\xD8",
|
||||
"fnop",0,0,0,"\xD9\xD0",
|
||||
"fpatan",0,0,0,"\xD9\xF3",
|
||||
"fptan",0,0,0,"\xD9\xF2",
|
||||
"fprem",0,0,0,"\xD9\xF8",
|
||||
"fprem1",0,0,0,"\xD9\xF5",
|
||||
"frndint",0,0,0,"\xD9\xFC",
|
||||
"fsave",MEM,0,_6,"\x9B\xDD",
|
||||
"fnsave",MEM,0,_6,"\xDD",
|
||||
"frstor",MEM,0,_4,"\xDD",
|
||||
"fscale",0,0,0,"\xD9\xFD",
|
||||
"fsetpm",0,0,0,"\xDB\xE4",
|
||||
"fsin",0,0,0,"\xD9\xFE",
|
||||
"fsincos",0,0,0,"\xD9\xFB",
|
||||
"fsqrt",0,0,0,"\xD9\xFA",
|
||||
"fst",MEM32,0,_2,"\xD9",
|
||||
"fstp",MEM32,0,_3,"\xD9",
|
||||
"fstcw",MEM16,0,_0,"\x9B\xD9",
|
||||
"fnstcw",MEM16,0,_0,"\xD9",
|
||||
"fstenv",MEM,0,_6,"\x9B\xD9",
|
||||
"fnstenv",MEM,0,_6,"\xD9",
|
||||
"fstsw",MEM16,0,_0,"\x9B\xDD",
|
||||
"0",AX,0,0,"\x9B\xDF\xE0",
|
||||
"fnstsw",MEM16,0,_0,"\xDD",
|
||||
"0",AX,0,0,"\xDF\xE0",
|
||||
"fsub",MEM32,0,_4,"\xD8",
|
||||
"fsubr",MEM32,0,_5,"\xD8",
|
||||
"ftst",0,0,0,"\xD9\xE4",
|
||||
"fucompp",0,0,0,"\xDA\xE9",
|
||||
"fxam",0,0,0,"\xD9\xE5",
|
||||
"fxch",0,0,0,"\xD9\xC9",
|
||||
"fxtract",0,0,0,"\xD9\xF4",
|
||||
"fyl2x",0,0,0,"\xD9\xF1",
|
||||
"fyl2xp1",0,0,0,"\xD9\xF9",
|
||||
"hlt",0,0,0,"\xF4",
|
||||
"ibts",R_M16,REG16,O16|_R,"\x0F\xA7",
|
||||
"idiv",R_M8,0,_7,"\xF6",
|
||||
"0",R_M16,0,O16|_7,"\xF7",
|
||||
"imul",R_M8,0,_5,"\xF6",
|
||||
"0",R_M16,0,O16|_5,"\xF7",
|
||||
"0",REG16,R_M16,O16|_R,"\x0F\xAF",
|
||||
"0",REG16,IMM8,O16|_R|IB,"\x6B",
|
||||
"0",REG16,IMM16,O16|_R|IW,"\x69",
|
||||
"in",AL,IMM8,IB,"\xE4",
|
||||
"0",AX,IMM8,O16|IB,"\xE5",
|
||||
"inc",REG16,0,O16|PLUSREG,"\x40",
|
||||
"0",R_M8,0,_0,"\xFE",
|
||||
"0",R_M16,0,O16|_0,"\xFF",
|
||||
"insb",0,0,0,"\x6C",
|
||||
"insw",0,0,O16,"\x6D",
|
||||
"int",IMM8,0,IB,"\xCD",
|
||||
"int1",0,0,0,"\xF1",
|
||||
"icebp",0,0,0,"\xF1",
|
||||
"int01",0,0,0,"\xF1",
|
||||
"int3",0,0,0,"\xCC",
|
||||
"into",0,0,0,"\xCE",
|
||||
"invd",0,0,0,"\x0F\x08",
|
||||
"invlpg",MEM,0,_0,"\x0F\x01",
|
||||
"iret",0,0,0,"\xCF",
|
||||
"iretw",0,0,O16,"\xCF",
|
||||
"jcxz",IMM,0,O16,"\xE3",
|
||||
"jmp",IMM,0,0,"\xE9",
|
||||
"0",R_M16,0,O16|_4,"\xFF",
|
||||
"jcc",IMM,0,PLUSCC,"\x70",
|
||||
"lahf",0,0,0,"\x9F",
|
||||
"lar",REG16,R_M16,O16|_R,"\x0F\x02",
|
||||
"lds",REG16,MEM,O16|_R,"\xC5",
|
||||
"les",REG16,MEM,O16|_R,"\xC4",
|
||||
"lfs",REG16,MEM,O16|_R,"\x0F\xB4",
|
||||
"lgs",REG16,MEM,O16|_R,"\x0F\xB5",
|
||||
"lss",REG16,MEM,O16|_R,"\x0F\xB2",
|
||||
"lea",REG16,MEM,O16|_R,"\x8D",
|
||||
"leave",0,0,0,"\xC9",
|
||||
"lgdt",MEM,0,_2,"\x0F\x01",
|
||||
"lidt",MEM,0,_3,"\x0F\x01",
|
||||
"lldt",R_M16,0,_2,"\x0F\x00",
|
||||
"lmsw",R_M16,0,_6,"\x0F\x01",
|
||||
"loadall",0,0,0,"\x0F\x07",
|
||||
"loadall286",0,0,0,"\x0F\x05",
|
||||
"lodsb",0,0,0,"\xAC",
|
||||
"lodsw",0,0,O16,"\xAD",
|
||||
"loop",IMM,0,0,"\xE2",
|
||||
"0",IMM,CX,0,"\xa1\xE2",
|
||||
"0",IMM,ECX,0,"\xa3\xE2",
|
||||
"loope",IMM,0,0,"\xE1",
|
||||
"0",IMM,CX,0,"\xa1\xE1",
|
||||
"0",IMM,ECX,0,"\xa3\xE1",
|
||||
"loopz",IMM,0,0,"\xE1",
|
||||
"0",IMM,CX,0,"\xa1\xE1",
|
||||
"0",IMM,ECX,0,"\xa3\xE1",
|
||||
"loopne",IMM,0,0,"\xE0",
|
||||
"0",IMM,CX,0,"\xa1\xE0",
|
||||
"0",IMM,ECX,0,"\xa3\xE0",
|
||||
"loopnz",IMM,0,0,"\xE0",
|
||||
"0",IMM,CX,0,"\xa1\xE0",
|
||||
"0",IMM,ECX,0,"\xa3\xE0",
|
||||
"lsl",REG16,R_M16,O16|_R,"\x0F\x03",
|
||||
"ltr",R_M16,0,_3,"\x0F\x00",
|
||||
"mov",R_M8,REG8,_R,"\x88",
|
||||
"0",R_M16,REG16,O16|_R,"\x89",
|
||||
"0",REG8,R_M8,_R,"\x8A",
|
||||
"0",REG16,R_M16,O16|_R,"\x8B",
|
||||
"0",REG8,IMM8,PLUSREG|IB,"\xB0",
|
||||
"0",REG16,IMM16,O16|PLUSREG|IW,"\xB8",
|
||||
"0",R_M8,IMM8,_0|IB,"\xC6",
|
||||
"0",R_M16,IMM16,O16|_0|IW,"\xC7",
|
||||
"movsb",0,0,0,"\xA4",
|
||||
"movsw",0,0,O16,"\xA5",
|
||||
"movsx",REG16,R_M8,O16|_R,"\x0F\xBE",
|
||||
"movzx",REG16,R_M8,O16|_R,"\x0F\xB6",
|
||||
"mul",R_M8,0,_4,"\xF6",
|
||||
"0",R_M16,0,O16|_4,"\xF7",
|
||||
"neg",R_M8,0,_3,"\xF6",
|
||||
"0",R_M16,0,O16|_3,"\xF7",
|
||||
"not",R_M8,0,_2,"\xF6",
|
||||
"0",R_M16,0,O16|_2,"\xF7",
|
||||
"nop",0,0,0,"\x90",
|
||||
"or",R_M8,REG8,_R,"\x08",
|
||||
"0",R_M16,REG16,O16|_R,"\x09",
|
||||
"0",REG8,R_M8,_R,"\x0A",
|
||||
"0",REG16,R_M16,O16|_R,"\x0B",
|
||||
"0",R_M8,IMM8,_1|IB,"\x80",
|
||||
"0",R_M16,IMM16,O16|_1|IW,"\x81",
|
||||
"0",R_M16,IMM8,O16|_1|IB,"\x83",
|
||||
"0",AL,IMM8,IB,"\x0C",
|
||||
"0",AX,IMM16,O16|IW,"\x0D",
|
||||
"out",IMM8,AL,IB,"\xE6",
|
||||
"0",IMM8,AX,O16|IB,"\xE7",
|
||||
"outsb",0,0,0,"\x6E",
|
||||
"outsw",0,0,O16,"\x6F",
|
||||
"pop",REG16,0,O16|PLUSREG,"\x58",
|
||||
"0",R_M16,0,O16|_0,"\x8F",
|
||||
"popa",0,0,0,"\x61",
|
||||
"popaw",0,0,O16,"\x61",
|
||||
"popf",0,0,0,"\x9D",
|
||||
"popfw",0,0,O16,"\x9D",
|
||||
"push",REG16,0,O16|PLUSREG,"\x50",
|
||||
"0",R_M16,0,O16|_6,"\xFF",
|
||||
"0",IMM8,0,IB,"\x6A",
|
||||
"0",IMM16,0,O16|IW,"\x68",
|
||||
"pusha",0,0,0,"\x60",
|
||||
"pushaw",0,0,O16,"\x60",
|
||||
"pushf",0,0,0,"\x9C",
|
||||
"pushfw",0,0,O16,"\x9C",
|
||||
"rcl",R_M8,CL,_2,"\xD2",
|
||||
"0",R_M8,IMM8,_2|IB,"\xC0",
|
||||
"0",R_M16,CL,O16|_2,"\xD3",
|
||||
"0",R_M16,IMM8,O16|_2|IB,"\xC1",
|
||||
"rcr",R_M8,CL,_3,"\xD2",
|
||||
"0",R_M8,IMM8,_3|IB,"\xC0",
|
||||
"0",R_M16,CL,O16|_3,"\xD3",
|
||||
"0",R_M16,IMM8,O16|_3|IB,"\xC1",
|
||||
"rdmsr",0,0,0,"\x0F\x32",
|
||||
"rdpmc",0,0,0,"\x0F\x33",
|
||||
"rdtsc",0,0,0,"\x0F\x31",
|
||||
"ret",0,0,0,"\xC3",
|
||||
"0",IMM16,0,IW,"\xC2",
|
||||
"retf",0,0,0,"\xCB",
|
||||
"0",IMM16,0,IW,"\xCA",
|
||||
"retn",0,0,0,"\xC3",
|
||||
"0",IMM16,0,IW,"\xC2",
|
||||
"rol",R_M8,CL,_0,"\xD2",
|
||||
"0",R_M8,IMM8,_0|IB,"\xC0",
|
||||
"0",R_M16,CL,O16|_0,"\xD3",
|
||||
"0",R_M16,IMM8,O16|_0|IB,"\xC1",
|
||||
"ror",R_M8,CL,_1,"\xD2",
|
||||
"0",R_M8,IMM8,_1|IB,"\xC0",
|
||||
"0",R_M16,CL,O16|_1,"\xD3",
|
||||
"0",R_M16,IMM8,O16|_1|IB,"\xC1",
|
||||
"rsm",0,0,0,"\x0F\xAA",
|
||||
"sahf",0,0,0,"\x9E",
|
||||
"sal",R_M8,CL,_4,"\xD2",
|
||||
"0",R_M8,IMM8,_4|IB,"\xC0",
|
||||
"0",R_M16,CL,O16|_4,"\xD3",
|
||||
"0",R_M16,IMM8,O16|_4|IB,"\xC1",
|
||||
"sar",R_M8,CL,_0,"\xD2",
|
||||
"0",R_M8,IMM8,_0|IB,"\xC0",
|
||||
"0",R_M16,CL,O16|_0,"\xD3",
|
||||
"0",R_M16,IMM8,O16|_0|IB,"\xC1",
|
||||
"salc",0,0,0,"\xD6",
|
||||
"sbb",R_M8,REG8,_R,"\x18",
|
||||
"0",R_M16,REG16,O16|_R,"\x19",
|
||||
"0",REG8,R_M8,_R,"\x1A",
|
||||
"0",REG16,R_M16,O16|_R,"\x1B",
|
||||
"0",R_M8,IMM8,_3|IB,"\x80",
|
||||
"0",R_M16,IMM16,O16|_3|IW,"\x81",
|
||||
"0",R_M16,IMM8,O16|_3|IB,"\x83",
|
||||
"0",AL,IMM8,IB,"\x1C",
|
||||
"0",AX,IMM16,O16|IW,"\x1D",
|
||||
"scasb",0,0,0,"\xAE",
|
||||
"scasw",0,0,O16,"\xAF",
|
||||
"setcc",R_M8,0,PLUSCC|_2,"\x0F\x90",
|
||||
"sgdt",MEM,0,_0,"\x0F\x01",
|
||||
"sidt",MEM,0,_1,"\x0F\x01",
|
||||
"sldt",R_M16,0,_0,"\x0F\x00",
|
||||
"shl",R_M8,CL,_4,"\xD2",
|
||||
"0",R_M8,IMM8,_4|IB,"\xC0",
|
||||
"0",R_M16,CL,O16|_4,"\xD3",
|
||||
"0",R_M16,IMM8,O16|_4|IB,"\xC1",
|
||||
"shr",R_M8,CL,_5,"\xD2",
|
||||
"0",R_M8,IMM8,_5|IB,"\xC0",
|
||||
"0",R_M16,CL,O16|_5,"\xD3",
|
||||
"0",R_M16,IMM8,O16|_5|IB,"\xC1",
|
||||
"smi",0,0,0,"\xF1",
|
||||
"smsw",R_M16,0,_4,"\x0F\x01",
|
||||
"stc",0,0,0,"\xF9",
|
||||
"std",0,0,0,"\xFD",
|
||||
"sti",0,0,0,"\xFB",
|
||||
"stosb",0,0,0,"\xAA",
|
||||
"stosw",0,0,O16,"\xAB",
|
||||
"str",R_M16,0,_1,"\x0F\x00",
|
||||
"sub",R_M8,REG8,_R,"\x28",
|
||||
"0",R_M16,REG16,O16|_R,"\x29",
|
||||
"0",REG8,R_M8,_R,"\x2A",
|
||||
"0",REG16,R_M16,O16|_R,"\x2B",
|
||||
"0",R_M8,IMM8,_5|IB,"\x80",
|
||||
"0",R_M16,IMM16,O16|_5|IW,"\x81",
|
||||
"0",R_M16,IMM8,O16|_5|IB,"\x83",
|
||||
"0",AL,IMM8,IB,"\x2C",
|
||||
"0",AX,IMM16,O16|IW,"\x2D",
|
||||
"test",R_M8,REG8,_R,"\x84",
|
||||
"0",R_M16,REG16,O16|_R,"\x85",
|
||||
"0",R_M8,IMM8,_7|IB,"\xF6",
|
||||
"0",R_M16,IMM16,O16|_7|IW,"\xF7",
|
||||
"0",AL,IMM8,IB,"\xA8",
|
||||
"0",AX,IMM16,O16|IW,"\xA9",
|
||||
"umov",R_M8,REG8,_R,"\x0F\x10",
|
||||
"0",R_M16,REG16,O16|_R,"\x0F\x11",
|
||||
"0",REG8,R_M8,_R,"\x0F\x12",
|
||||
"0",REG16,R_M16,O16|_R,"\x0F\x13",
|
||||
"verr",R_M16,0,_4,"\x0F\x00",
|
||||
"verw",R_M16,0,_5,"\x0F\x00",
|
||||
"wait",0,0,0,"\x9B",
|
||||
"wbinvd",0,0,0,"\x0F\x09",
|
||||
"wrmsr",0,0,0,"\x0F\x30",
|
||||
"xadd",R_M8,REG8,_R,"\x0F\xC0",
|
||||
"0",R_M16,REG16,O16|_R,"\x0F\xC1",
|
||||
"xbts",REG16,R_M16,O16|_R,"\x0F\xA6",
|
||||
"xchg",REG8,R_M8,_R,"\x86",
|
||||
"0",REG16,R_M8,O16|_R,"\x87",
|
||||
"0",R_M8,REG8,_R,"\x86",
|
||||
"0",R_M16,REG16,O16|_R,"\x87",
|
||||
"0",AX,REG16,O16|PLUSREG,"\x90",
|
||||
"0",REG16,AX,O16|PLUSREG,"\x90",
|
||||
"xlatb",0,0,0,"\xD7",
|
||||
"xor",R_M8,REG8,_R,"\x30",
|
||||
"0",R_M16,REG16,O16|_R,"\x31",
|
||||
"0",REG8,R_M8,_R,"\x32",
|
||||
"0",REG16,R_M16,O16|_R,"\x33",
|
||||
"0",R_M8,IMM8,_6|IB,"\x80",
|
||||
"0",R_M16,IMM16,O16|_6|IW,"\x81",
|
||||
"0",R_M16,IMM8,O16|_6|IB,"\x83",
|
||||
"0",AL,IMM8,IB,"\x34",
|
||||
"0",AX,IMM16,O16|IW,"\x35",
|
||||
0,0,0,0,0
|
||||
};
|
96
asm_makeinsts/asm_makeinsts.dsp
Normal file
96
asm_makeinsts/asm_makeinsts.dsp
Normal file
@ -0,0 +1,96 @@
|
||||
# Microsoft Developer Studio Project File - Name="asm_makeinsts" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=asm_makeinsts - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "asm_makeinsts.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "asm_makeinsts.mak" CFG="asm_makeinsts - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "asm_makeinsts - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "asm_makeinsts - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "asm_makeinsts - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /GB /MT /W3 /GX /Ox /Ow /Og /Oi /Os /Ob2 /Gf /Gy /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# SUBTRACT CPP /Ot
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "asm_makeinsts - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# SUBTRACT CPP /Gy
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "asm_makeinsts - Win32 Release"
|
||||
# Name "asm_makeinsts - Win32 Debug"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\main.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\nasm_insts.txt
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
139
asm_makeinsts/main.cpp
Normal file
139
asm_makeinsts/main.cpp
Normal file
@ -0,0 +1,139 @@
|
||||
|
||||
/*
|
||||
|
||||
This generates a source code file for x86 instruction formats.
|
||||
|
||||
Thanks NASM!
|
||||
|
||||
*/
|
||||
|
||||
#include <conio.h>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static const char *optype( const string &s ){
|
||||
|
||||
if( s=="AL" ) return "AL";
|
||||
if( s=="AX" ) return "AX";
|
||||
if( s=="EAX" ) return "EAX";
|
||||
if( s=="CL" ) return "CL";
|
||||
if( s=="CX" ) return "CX";
|
||||
if( s=="ECX" ) return "ECX";
|
||||
if( s=="imm" ) return "IMM";
|
||||
if( s=="imm8" ) return "IMM8";
|
||||
if( s=="imm16" ) return "IMM16";
|
||||
if( s=="imm32" ) return "IMM32";
|
||||
if( s=="reg" ) return "REG";
|
||||
if( s=="reg8" ) return "REG8";
|
||||
if( s=="reg16" ) return "REG16";
|
||||
if( s=="reg32" ) return "REG32";
|
||||
if( s=="mem" ) return "MEM";
|
||||
if( s=="mem8" ) return "MEM8";
|
||||
if( s=="mem16" ) return "MEM16";
|
||||
if( s=="mem32" ) return "MEM32";
|
||||
if( s=="r/m" ) return "R_M";
|
||||
if( s=="r/m8" ) return "R_M8";
|
||||
if( s=="r/m16" ) return "R_M16";
|
||||
if( s=="r/m32" ) return "R_M32";
|
||||
if( s=="fpureg" ) return "FPUREG";
|
||||
if( s=="ST0" ) return "ST0";
|
||||
return 0;
|
||||
}
|
||||
|
||||
void main(){
|
||||
|
||||
string name,lhs,rhs,byte,bytes,flags,last;
|
||||
|
||||
ifstream in( "nasm_insts.txt" );
|
||||
ofstream out( "..\\compiler\\assem_x86\\asm_insts.cpp" );
|
||||
|
||||
out<<"//\n//This is generated code - do not modify!!!!!\n//\n";
|
||||
out<<"\n#include \"..\\std.h\"\n\n";
|
||||
out<<"\n#include \"insts.h\"\n\n";
|
||||
out<<"Inst insts[]={\n";
|
||||
|
||||
for( ;!in.eof();in.ignore( INT_MAX,'\n' ) ){
|
||||
|
||||
name.resize(0);
|
||||
|
||||
in>>name;
|
||||
if( !name.size() || name[0]=='/' ) continue;
|
||||
|
||||
lhs.resize(0);rhs.resize(0);
|
||||
const char *lop="NONE",*rop="NONE";
|
||||
|
||||
while( isspace( in.peek() ) ) in.get();
|
||||
getline( in,lhs,';' );
|
||||
|
||||
if( int i=lhs.size() ){
|
||||
while( i && isspace( lhs[i-1] ) ) --i;
|
||||
if( i ){
|
||||
lhs.resize( i );
|
||||
i=lhs.find( ',' );
|
||||
if( i!=string::npos ){
|
||||
rhs=lhs.substr( i+1 );
|
||||
lhs=lhs.substr( 0,i );
|
||||
}
|
||||
lop=optype( lhs );if( !lop ) continue;
|
||||
if( rhs.size() && !(rop=optype( rhs )) ) continue;
|
||||
}
|
||||
}
|
||||
|
||||
bytes.resize(0);
|
||||
|
||||
flags='0';
|
||||
bool fail=false;
|
||||
while( !fail ){
|
||||
in>>byte;
|
||||
if( byte[0]=='[' ) break;
|
||||
if( byte=="/r" ) flags+="|_R";
|
||||
else if( byte=="/0" ) flags+="|_0";
|
||||
else if( byte=="/1" ) flags+="|_1";
|
||||
else if( byte=="/2" ) flags+="|_2";
|
||||
else if( byte=="/3" ) flags+="|_3";
|
||||
else if( byte=="/4" ) flags+="|_4";
|
||||
else if( byte=="/5" ) flags+="|_5";
|
||||
else if( byte=="/6" ) flags+="|_6";
|
||||
else if( byte=="/7" ) flags+="|_7";
|
||||
else if( byte=="o16" ) flags+="|O16";
|
||||
else if( byte=="o32" ) flags+="|O32";
|
||||
else if( byte=="ow/od" ) flags+="|OW_OD";
|
||||
else if( byte=="ib" ) flags+="|IB";
|
||||
else if( byte=="iw" ) flags+="|IW";
|
||||
else if( byte=="id" ) flags+="|ID";
|
||||
else if( byte=="rw/rd" ) flags+="|RW_RD";
|
||||
else if( isxdigit( byte[0] ) ){
|
||||
string sub=byte.substr( 2 );
|
||||
if( sub.size() ){
|
||||
if( sub=="+r" ) flags+="|PLUSREG";
|
||||
else if( sub=="+cc" ) flags+="|PLUSCC";
|
||||
else fail=true;
|
||||
}
|
||||
bytes=bytes+"\\x"+byte[0]+byte[1];
|
||||
}else fail=true;
|
||||
}
|
||||
if( fail ) continue;
|
||||
|
||||
if( flags.find( "0|" )==0 ) flags=flags.substr( 2 );
|
||||
for( int k=0;k<name.size();++k ) name[k]=tolower( name[k] );
|
||||
|
||||
if( name==last ) name="0";
|
||||
else{
|
||||
last=name;
|
||||
name='\"'+name+'\"';
|
||||
}
|
||||
|
||||
char bf[4];itoa( bytes.size()/3,bf,16 );
|
||||
bytes="\\x"+string( bf )+bytes;
|
||||
|
||||
out<<name<<','<<lop<<','<<rop<<','<<flags<<",\""<<bytes<<"\",\n";
|
||||
}
|
||||
out<<"\"\",0,0,0,0\n};\n";
|
||||
out.flush();
|
||||
out.close();
|
||||
cout<<"All done!\n";
|
||||
getch();
|
||||
}
|
760
asm_makeinsts/nasm_insts.txt
Normal file
760
asm_makeinsts/nasm_insts.txt
Normal file
@ -0,0 +1,760 @@
|
||||
AAA ; 37 [8086]
|
||||
AAS ; 3F [8086]
|
||||
AAD ; D5 0A [8086]
|
||||
AAD imm ; D5 ib [8086]
|
||||
AAM ; D4 0A [8086]
|
||||
AAM imm ; D4 ib [8086]
|
||||
ADC AL,imm8 ; 14 ib [8086]
|
||||
ADC AX,imm16 ; o16 15 iw [8086]
|
||||
ADC EAX,imm32 ; o32 15 id [386]
|
||||
ADC r/m8,reg8 ; 10 /r [8086]
|
||||
ADC r/m16,reg16 ; o16 11 /r [8086]
|
||||
ADC r/m32,reg32 ; o32 11 /r [386]
|
||||
ADC reg8,r/m8 ; 12 /r [8086]
|
||||
ADC reg16,r/m16 ; o16 13 /r [8086]
|
||||
ADC reg32,r/m32 ; o32 13 /r [386]
|
||||
ADC r/m8,imm8 ; 80 /2 ib [8086]
|
||||
ADC r/m16,imm16 ; o16 81 /2 iw [8086]
|
||||
ADC r/m32,imm32 ; o32 81 /2 id [386]
|
||||
ADC r/m16,imm8 ; o16 83 /2 ib [8086]
|
||||
ADC r/m32,imm8 ; o32 83 /2 ib [386]
|
||||
ADD AL,imm8 ; 04 ib [8086]
|
||||
ADD AX,imm16 ; o16 05 iw [8086]
|
||||
ADD EAX,imm32 ; o32 05 id [386]
|
||||
ADD r/m8,reg8 ; 00 /r [8086]
|
||||
ADD r/m16,reg16 ; o16 01 /r [8086]
|
||||
ADD r/m32,reg32 ; o32 01 /r [386]
|
||||
ADD reg8,r/m8 ; 02 /r [8086]
|
||||
ADD reg16,r/m16 ; o16 03 /r [8086]
|
||||
ADD reg32,r/m32 ; o32 03 /r [386]
|
||||
ADD r/m8,imm8 ; 80 /0 ib [8086]
|
||||
ADD r/m16,imm16 ; o16 81 /0 iw [8086]
|
||||
ADD r/m32,imm32 ; o32 81 /0 id [386]
|
||||
ADD r/m16,imm8 ; o16 83 /0 ib [8086]
|
||||
ADD r/m32,imm8 ; o32 83 /0 ib [386]
|
||||
AND AL,imm8 ; 24 ib [8086]
|
||||
AND AX,imm16 ; o16 25 iw [8086]
|
||||
AND EAX,imm32 ; o32 25 id [386]
|
||||
AND r/m8,reg8 ; 20 /r [8086]
|
||||
AND r/m16,reg16 ; o16 21 /r [8086]
|
||||
AND r/m32,reg32 ; o32 21 /r [386]
|
||||
AND reg8,r/m8 ; 22 /r [8086]
|
||||
AND reg16,r/m16 ; o16 23 /r [8086]
|
||||
AND reg32,r/m32 ; o32 23 /r [386]
|
||||
AND r/m8,imm8 ; 80 /4 ib [8086]
|
||||
AND r/m16,imm16 ; o16 81 /4 iw [8086]
|
||||
AND r/m32,imm32 ; o32 81 /4 id [386]
|
||||
AND r/m16,imm8 ; o16 83 /4 ib [8086]
|
||||
AND r/m32,imm8 ; o32 83 /4 ib [386]
|
||||
ARPL r/m16,reg16 ; 63 /r [286,PRIV]
|
||||
BOUND reg16,mem ; o16 62 /r [186]
|
||||
BOUND reg32,mem ; o32 62 /r [386]
|
||||
BSF reg16,r/m16 ; o16 0F BC /r [386]
|
||||
BSF reg32,r/m32 ; o32 0F BC /r [386]
|
||||
BSR reg16,r/m16 ; o16 0F BD /r [386]
|
||||
BSR reg32,r/m32 ; o32 0F BD /r [386]
|
||||
BSWAP reg32 ; o32 0F C8+r [486]
|
||||
BT r/m16,reg16 ; o16 0F A3 /r [386]
|
||||
BT r/m32,reg32 ; o32 0F A3 /r [386]
|
||||
BT r/m16,imm8 ; o16 0F BA /4 ib [386]
|
||||
BT r/m32,imm8 ; o32 0F BA /4 ib [386]
|
||||
BTC r/m16,reg16 ; o16 0F BB /r [386]
|
||||
BTC r/m32,reg32 ; o32 0F BB /r [386]
|
||||
BTC r/m16,imm8 ; o16 0F BA /7 ib [386]
|
||||
BTC r/m32,imm8 ; o32 0F BA /7 ib [386]
|
||||
BTR r/m16,reg16 ; o16 0F B3 /r [386]
|
||||
BTR r/m32,reg32 ; o32 0F B3 /r [386]
|
||||
BTR r/m16,imm8 ; o16 0F BA /6 ib [386]
|
||||
BTR r/m32,imm8 ; o32 0F BA /6 ib [386]
|
||||
BTS r/m16,reg16 ; o16 0F AB /r [386]
|
||||
BTS r/m32,reg32 ; o32 0F AB /r [386]
|
||||
BTS r/m16,imm ; o16 0F BA /5 ib [386]
|
||||
BTS r/m32,imm ; o32 0F BA /5 ib [386]
|
||||
CALL imm ; E8 rw/rd [8086]
|
||||
//CALL imm:imm16 ; o16 9A iw iw [8086]
|
||||
//CALL imm:imm32 ; o32 9A id iw [386]
|
||||
//CALL FAR mem16 ; o16 FF /3 [8086]
|
||||
//CALL FAR mem32 ; o32 FF /3 [386]
|
||||
CALL r/m16 ; o16 FF /2 [8086]
|
||||
CALL r/m32 ; o32 FF /2 [386]
|
||||
CBW ; o16 98 [8086]
|
||||
CWD ; o16 99 [8086]
|
||||
CDQ ; o32 99 [386]
|
||||
CWDE ; o32 98 [386]
|
||||
CLC ; F8 [8086]
|
||||
CLD ; FC [8086]
|
||||
CLI ; FA [8086]
|
||||
CLTS ; 0F 06 [286,PRIV]
|
||||
CMC ; F5 [8086]
|
||||
CMOVcc reg16,r/m16 ; o16 0F 40+cc /r [P6]
|
||||
CMOVcc reg32,r/m32 ; o32 0F 40+cc /r [P6]
|
||||
CMP AL,imm8 ; 3C ib [8086]
|
||||
CMP AX,imm16 ; o16 3D iw [8086]
|
||||
CMP EAX,imm32 ; o32 3D id [386]
|
||||
CMP r/m8,reg8 ; 38 /r [8086]
|
||||
CMP r/m16,reg16 ; o16 39 /r [8086]
|
||||
CMP r/m32,reg32 ; o32 39 /r [386]
|
||||
CMP reg8,r/m8 ; 3A /r [8086]
|
||||
CMP reg16,r/m16 ; o16 3B /r [8086]
|
||||
CMP reg32,r/m32 ; o32 3B /r [386]
|
||||
CMP r/m8,imm8 ; 80 /7 ib [8086]
|
||||
CMP r/m16,imm16 ; o16 81 /7 iw [8086]
|
||||
CMP r/m32,imm32 ; o32 81 /7 id [386]
|
||||
CMP r/m16,imm8 ; o16 83 /7 ib [8086]
|
||||
CMP r/m32,imm8 ; o32 83 /7 ib [386]
|
||||
CMPSB ; A6 [8086]
|
||||
CMPSW ; o16 A7 [8086]
|
||||
CMPSD ; o32 A7 [386]
|
||||
CMPXCHG r/m8,reg8 ; 0F B0 /r [PENT]
|
||||
CMPXCHG r/m16,reg16 ; o16 0F B1 /r [PENT]
|
||||
CMPXCHG r/m32,reg32 ; o32 0F B1 /r [PENT]
|
||||
CMPXCHG486 r/m8,reg8 ; 0F A6 /r [486,UNDOC]
|
||||
CMPXCHG486 r/m16,reg16 ; o16 0F A7 /r [486,UNDOC]
|
||||
CMPXCHG486 r/m32,reg32 ; o32 0F A7 /r [486,UNDOC]
|
||||
CMPXCHG8B mem ; 0F C7 /1 [PENT]
|
||||
CPUID ; 0F A2 [PENT]
|
||||
DAA ; 27 [8086]
|
||||
DAS ; 2F [8086]
|
||||
DEC reg16 ; o16 48+r [8086]
|
||||
DEC reg32 ; o32 48+r [386]
|
||||
DEC r/m8 ; FE /1 [8086]
|
||||
DEC r/m16 ; o16 FF /1 [8086]
|
||||
DEC r/m32 ; o32 FF /1 [386]
|
||||
DIV r/m8 ; F6 /6 [8086]
|
||||
DIV r/m16 ; o16 F7 /6 [8086]
|
||||
DIV r/m32 ; o32 F7 /6 [386]
|
||||
EMMS ; 0F 77 [PENT,MMX]
|
||||
ENTER imm,imm ; C8 iw ib [186]
|
||||
F2XM1 ; D9 F0 [8086,FPU]
|
||||
FABS ; D9 E1 [8086,FPU]
|
||||
FADD mem32 ; D8 /0 [8086,FPU]
|
||||
FADD mem64 ; DC /0 [8086,FPU]
|
||||
FADD fpureg ; D8 C0+r [8086,FPU]
|
||||
FADD ST0,fpureg ; D8 C0+r [8086,FPU]
|
||||
FADD TO fpureg ; DC C0+r [8086,FPU]
|
||||
FADD fpureg,ST0 ; DC C0+r [8086,FPU]
|
||||
FADDP fpureg ; DE C0+r [8086,FPU]
|
||||
FADDP fpureg,ST0 ; DE C0+r [8086,FPU]
|
||||
FBLD mem80 ; DF /4 [8086,FPU]
|
||||
FBSTP mem80 ; DF /6 [8086,FPU]
|
||||
FCHS ; D9 E0 [8086,FPU]
|
||||
FCLEX ; 9B DB E2 [8086,FPU]
|
||||
FNCLEX ; DB E2 [8086,FPU]
|
||||
FCMOVB fpureg ; DA C0+r [P6,FPU]
|
||||
FCMOVB ST0,fpureg ; DA C0+r [P6,FPU]
|
||||
FCMOVBE fpureg ; DA D0+r [P6,FPU]
|
||||
FCMOVBE ST0,fpureg ; DA D0+r [P6,FPU]
|
||||
FCMOVE fpureg ; DA C8+r [P6,FPU]
|
||||
FCMOVE ST0,fpureg ; DA C8+r [P6,FPU]
|
||||
FCMOVNB fpureg ; DB C0+r [P6,FPU]
|
||||
FCMOVNB ST0,fpureg ; DB C0+r [P6,FPU]
|
||||
FCMOVNBE fpureg ; DB D0+r [P6,FPU]
|
||||
FCMOVNBE ST0,fpureg ; DB D0+r [P6,FPU]
|
||||
FCMOVNE fpureg ; DB C8+r [P6,FPU]
|
||||
FCMOVNE ST0,fpureg ; DB C8+r [P6,FPU]
|
||||
FCMOVNU fpureg ; DB D8+r [P6,FPU]
|
||||
FCMOVNU ST0,fpureg ; DB D8+r [P6,FPU]
|
||||
FCMOVU fpureg ; DA D8+r [P6,FPU]
|
||||
FCMOVU ST0,fpureg ; DA D8+r [P6,FPU]
|
||||
FCOM mem32 ; D8 /2 [8086,FPU]
|
||||
FCOM mem64 ; DC /2 [8086,FPU]
|
||||
FCOM fpureg ; D8 D0+r [8086,FPU]
|
||||
FCOM ST0,fpureg ; D8 D0+r [8086,FPU]
|
||||
FCOMP mem32 ; D8 /3 [8086,FPU]
|
||||
FCOMP mem64 ; DC /3 [8086,FPU]
|
||||
FCOMP fpureg ; D8 D8+r [8086,FPU]
|
||||
FCOMP ST0,fpureg ; D8 D8+r [8086,FPU]
|
||||
FCOMPP ; DE D9 [8086,FPU]
|
||||
FCOMI fpureg ; DB F0+r [P6,FPU]
|
||||
FCOMI ST0,fpureg ; DB F0+r [P6,FPU]
|
||||
FCOMIP fpureg ; DF F0+r [P6,FPU]
|
||||
FCOMIP ST0,fpureg ; DF F0+r [P6,FPU]
|
||||
FCOS ; D9 FF [386,FPU]
|
||||
FDECSTP ; D9 F6 [8086,FPU]
|
||||
FDISI ; 9B DB E1 [8086,FPU]
|
||||
FNDISI ; DB E1 [8086,FPU]
|
||||
FENI ; 9B DB E0 [8086,FPU]
|
||||
FNENI ; DB E0 [8086,FPU]
|
||||
FDIV mem32 ; D8 /6 [8086,FPU]
|
||||
FDIV mem64 ; DC /6 [8086,FPU]
|
||||
FDIV fpureg ; D8 F0+r [8086,FPU]
|
||||
FDIV ST0,fpureg ; D8 F0+r [8086,FPU]
|
||||
FDIV TO fpureg ; DC F8+r [8086,FPU]
|
||||
FDIV fpureg,ST0 ; DC F8+r [8086,FPU]
|
||||
FDIVR mem32 ; D8 /0 [8086,FPU]
|
||||
FDIVR mem64 ; DC /0 [8086,FPU]
|
||||
FDIVR fpureg ; D8 F8+r [8086,FPU]
|
||||
FDIVR ST0,fpureg ; D8 F8+r [8086,FPU]
|
||||
FDIVR TO fpureg ; DC F0+r [8086,FPU]
|
||||
FDIVR fpureg,ST0 ; DC F0+r [8086,FPU]
|
||||
FDIVP fpureg ; DE F8+r [8086,FPU]
|
||||
FDIVP fpureg,ST0 ; DE F8+r [8086,FPU]
|
||||
FDIVRP fpureg ; DE F0+r [8086,FPU]
|
||||
FDIVRP fpureg,ST0 ; DE F0+r [8086,FPU]
|
||||
FFREE fpureg ; DD C0+r [8086,FPU]
|
||||
FIADD mem16 ; DE /0 [8086,FPU]
|
||||
FIADD mem32 ; DA /0 [8086,FPU]
|
||||
FICOM mem16 ; DE /2 [8086,FPU]
|
||||
FICOM mem32 ; DA /2 [8086,FPU]
|
||||
FICOMP mem16 ; DE /3 [8086,FPU]
|
||||
FICOMP mem32 ; DA /3 [8086,FPU]
|
||||
FIDIV mem16 ; DE /6 [8086,FPU]
|
||||
FIDIV mem32 ; DA /6 [8086,FPU]
|
||||
FIDIVR mem16 ; DE /0 [8086,FPU]
|
||||
FIDIVR mem32 ; DA /0 [8086,FPU]
|
||||
FILD mem16 ; DF /0 [8086,FPU]
|
||||
FILD mem32 ; DB /0 [8086,FPU]
|
||||
FILD mem64 ; DF /5 [8086,FPU]
|
||||
FIST mem16 ; DF /2 [8086,FPU]
|
||||
FIST mem32 ; DB /2 [8086,FPU]
|
||||
FISTP mem16 ; DF /3 [8086,FPU]
|
||||
FISTP mem32 ; DB /3 [8086,FPU]
|
||||
FISTP mem64 ; DF /0 [8086,FPU]
|
||||
FIMUL mem16 ; DE /1 [8086,FPU]
|
||||
FIMUL mem32 ; DA /1 [8086,FPU]
|
||||
FINCSTP ; D9 F7 [8086,FPU]
|
||||
FINIT ; 9B DB E3 [8086,FPU]
|
||||
FNINIT ; DB E3 [8086,FPU]
|
||||
FISUB mem16 ; DE /4 [8086,FPU]
|
||||
FISUB mem32 ; DA /4 [8086,FPU]
|
||||
FISUBR mem16 ; DE /5 [8086,FPU]
|
||||
FISUBR mem32 ; DA /5 [8086,FPU]
|
||||
FLD mem32 ; D9 /0 [8086,FPU]
|
||||
FLD mem64 ; DD /0 [8086,FPU]
|
||||
FLD mem80 ; DB /5 [8086,FPU]
|
||||
FLD fpureg ; D9 C0+r [8086,FPU]
|
||||
FLD1 ; D9 E8 [8086,FPU]
|
||||
FLDL2E ; D9 EA [8086,FPU]
|
||||
FLDL2T ; D9 E9 [8086,FPU]
|
||||
FLDLG2 ; D9 EC [8086,FPU]
|
||||
FLDLN2 ; D9 ED [8086,FPU]
|
||||
FLDPI ; D9 EB [8086,FPU]
|
||||
FLDZ ; D9 EE [8086,FPU]
|
||||
FLDCW mem16 ; D9 /5 [8086,FPU]
|
||||
FLDENV mem ; D9 /4 [8086,FPU]
|
||||
FMUL mem32 ; D8 /1 [8086,FPU]
|
||||
FMUL mem64 ; DC /1 [8086,FPU]
|
||||
FMUL fpureg ; D8 C8+r [8086,FPU]
|
||||
FMUL ST0,fpureg ; D8 C8+r [8086,FPU]
|
||||
FMUL TO fpureg ; DC C8+r [8086,FPU]
|
||||
FMUL fpureg,ST0 ; DC C8+r [8086,FPU]
|
||||
FMULP fpureg ; DE C8+r [8086,FPU]
|
||||
FMULP fpureg,ST0 ; DE C8+r [8086,FPU]
|
||||
FNOP ; D9 D0 [8086,FPU]
|
||||
FPATAN ; D9 F3 [8086,FPU]
|
||||
FPTAN ; D9 F2 [8086,FPU]
|
||||
FPREM ; D9 F8 [8086,FPU]
|
||||
FPREM1 ; D9 F5 [386,FPU]
|
||||
FRNDINT ; D9 FC [8086,FPU]
|
||||
FSAVE mem ; 9B DD /6 [8086,FPU]
|
||||
FNSAVE mem ; DD /6 [8086,FPU]
|
||||
FRSTOR mem ; DD /4 [8086,FPU]
|
||||
FSCALE ; D9 FD [8086,FPU]
|
||||
FSETPM ; DB E4 [286,FPU]
|
||||
FSIN ; D9 FE [386,FPU]
|
||||
FSINCOS ; D9 FB [386,FPU]
|
||||
FSQRT ; D9 FA [8086,FPU]
|
||||
FST mem32 ; D9 /2 [8086,FPU]
|
||||
FST mem64 ; DD /2 [8086,FPU]
|
||||
FST fpureg ; DD D0+r [8086,FPU]
|
||||
FSTP mem32 ; D9 /3 [8086,FPU]
|
||||
FSTP mem64 ; DD /3 [8086,FPU]
|
||||
FSTP mem80 ; DB /0 [8086,FPU]
|
||||
FSTP fpureg ; DD D8+r [8086,FPU]
|
||||
FSTCW mem16 ; 9B D9 /0 [8086,FPU]
|
||||
FNSTCW mem16 ; D9 /0 [8086,FPU]
|
||||
FSTENV mem ; 9B D9 /6 [8086,FPU]
|
||||
FNSTENV mem ; D9 /6 [8086,FPU]
|
||||
FSTSW mem16 ; 9B DD /0 [8086,FPU]
|
||||
FSTSW AX ; 9B DF E0 [286,FPU]
|
||||
FNSTSW mem16 ; DD /0 [8086,FPU]
|
||||
FNSTSW AX ; DF E0 [286,FPU]
|
||||
FSUB mem32 ; D8 /4 [8086,FPU]
|
||||
FSUB mem64 ; DC /4 [8086,FPU]
|
||||
FSUB fpureg ; D8 E0+r [8086,FPU]
|
||||
FSUB ST0,fpureg ; D8 E0+r [8086,FPU]
|
||||
FSUB TO fpureg ; DC E8+r [8086,FPU]
|
||||
FSUB fpureg,ST0 ; DC E8+r [8086,FPU]
|
||||
FSUBR mem32 ; D8 /5 [8086,FPU]
|
||||
FSUBR mem64 ; DC /5 [8086,FPU]
|
||||
FSUBR fpureg ; D8 E8+r [8086,FPU]
|
||||
FSUBR ST0,fpureg ; D8 E8+r [8086,FPU]
|
||||
FSUBR TO fpureg ; DC E0+r [8086,FPU]
|
||||
FSUBR fpureg,ST0 ; DC E0+r [8086,FPU]
|
||||
FSUBP fpureg ; DE E8+r [8086,FPU]
|
||||
FSUBP fpureg,ST0 ; DE E8+r [8086,FPU]
|
||||
FSUBRP fpureg ; DE E0+r [8086,FPU]
|
||||
FSUBRP fpureg,ST0 ; DE E0+r [8086,FPU]
|
||||
FTST ; D9 E4 [8086,FPU]
|
||||
FUCOM fpureg ; DD E0+r [386,FPU]
|
||||
FUCOM ST0,fpureg ; DD E0+r [386,FPU]
|
||||
FUCOMP fpureg ; DD E8+r [386,FPU]
|
||||
FUCOMP ST0,fpureg ; DD E8+r [386,FPU]
|
||||
FUCOMPP ; DA E9 [386,FPU]
|
||||
FUCOMI fpureg ; DB E8+r [P6,FPU]
|
||||
FUCOMI ST0,fpureg ; DB E8+r [P6,FPU]
|
||||
FUCOMIP fpureg ; DF E8+r [P6,FPU]
|
||||
FUCOMIP ST0,fpureg ; DF E8+r [P6,FPU]
|
||||
FXAM ; D9 E5 [8086,FPU]
|
||||
FXCH ; D9 C9 [8086,FPU]
|
||||
FXCH fpureg ; D9 C8+r [8086,FPU]
|
||||
FXCH fpureg,ST0 ; D9 C8+r [8086,FPU]
|
||||
FXCH ST0,fpureg ; D9 C8+r [8086,FPU]
|
||||
FXTRACT ; D9 F4 [8086,FPU]
|
||||
FYL2X ; D9 F1 [8086,FPU]
|
||||
FYL2XP1 ; D9 F9 [8086,FPU]
|
||||
HLT ; F4 [8086]
|
||||
IBTS r/m16,reg16 ; o16 0F A7 /r [386,UNDOC]
|
||||
IBTS r/m32,reg32 ; o32 0F A7 /r [386,UNDOC]
|
||||
IDIV r/m8 ; F6 /7 [8086]
|
||||
IDIV r/m16 ; o16 F7 /7 [8086]
|
||||
IDIV r/m32 ; o32 F7 /7 [386]
|
||||
IMUL r/m8 ; F6 /5 [8086]
|
||||
IMUL r/m16 ; o16 F7 /5 [8086]
|
||||
IMUL r/m32 ; o32 F7 /5 [386]
|
||||
IMUL reg16,r/m16 ; o16 0F AF /r [386]
|
||||
IMUL reg32,r/m32 ; o32 0F AF /r [386]
|
||||
IMUL reg16,imm8 ; o16 6B /r ib [286]
|
||||
IMUL reg16,imm16 ; o16 69 /r iw [286]
|
||||
IMUL reg32,imm8 ; o32 6B /r ib [386]
|
||||
IMUL reg32,imm32 ; o32 69 /r id [386]
|
||||
//IMUL reg16,r/m16,imm8 ; o16 6B /r ib [286]
|
||||
//IMUL reg16,r/m16,imm16 ; o16 69 /r iw [286]
|
||||
//IMUL reg32,r/m32,imm8 ; o32 6B /r ib [386]
|
||||
//IMUL reg32,r/m32,imm32 ; o32 69 /r id [386]
|
||||
IN AL,imm8 ; E4 ib [8086]
|
||||
IN AX,imm8 ; o16 E5 ib [8086]
|
||||
IN EAX,imm8 ; o32 E5 ib [386]
|
||||
IN AL,DX ; EC [8086]
|
||||
IN AX,DX ; o16 ED [8086]
|
||||
IN EAX,DX ; o32 ED [386]
|
||||
INC reg16 ; o16 40+r [8086]
|
||||
INC reg32 ; o32 40+r [386]
|
||||
INC r/m8 ; FE /0 [8086]
|
||||
INC r/m16 ; o16 FF /0 [8086]
|
||||
INC r/m32 ; o32 FF /0 [386]
|
||||
INSB ; 6C [186]
|
||||
INSW ; o16 6D [186]
|
||||
INSD ; o32 6D [386]
|
||||
INT imm8 ; CD ib [8086]
|
||||
INT1 ; F1 [P6]
|
||||
ICEBP ; F1 [P6]
|
||||
INT01 ; F1 [P6]
|
||||
INT3 ; CC [8086]
|
||||
INTO ; CE [8086]
|
||||
INVD ; 0F 08 [486]
|
||||
INVLPG mem ; 0F 01 /0 [486]
|
||||
IRET ; CF [8086]
|
||||
IRETW ; o16 CF [8086]
|
||||
IRETD ; o32 CF [386]
|
||||
JCXZ imm ; o16 E3 rb [8086]
|
||||
JECXZ imm ; o32 E3 rb [386]
|
||||
JMP imm ; E9 rw/rd [8086]
|
||||
JMP SHORT imm ; EB rb [8086]
|
||||
//JMP imm:imm16 ; o16 EA iw iw [8086]
|
||||
//JMP imm:imm32 ; o32 EA id iw [386]
|
||||
//JMP FAR mem ; o16 FF /5 [8086]
|
||||
//JMP FAR mem ; o32 FF /5 [386]
|
||||
JMP r/m16 ; o16 FF /4 [8086]
|
||||
JMP r/m32 ; o32 FF /4 [386]
|
||||
LAHF ; 9F [8086]
|
||||
LAR reg16,r/m16 ; o16 0F 02 /r [286,PRIV]
|
||||
LAR reg32,r/m32 ; o32 0F 02 /r [286,PRIV]
|
||||
LDS reg16,mem ; o16 C5 /r [8086]
|
||||
LDS reg32,mem ; o32 C5 /r [8086]
|
||||
LES reg16,mem ; o16 C4 /r [8086]
|
||||
LES reg32,mem ; o32 C4 /r [8086]
|
||||
LFS reg16,mem ; o16 0F B4 /r [386]
|
||||
LFS reg32,mem ; o32 0F B4 /r [386]
|
||||
LGS reg16,mem ; o16 0F B5 /r [386]
|
||||
LGS reg32,mem ; o32 0F B5 /r [386]
|
||||
LSS reg16,mem ; o16 0F B2 /r [386]
|
||||
LSS reg32,mem ; o32 0F B2 /r [386]
|
||||
LEA reg16,mem ; o16 8D /r [8086]
|
||||
LEA reg32,mem ; o32 8D /r [8086]
|
||||
LEAVE ; C9 [186]
|
||||
LGDT mem ; 0F 01 /2 [286,PRIV]
|
||||
LIDT mem ; 0F 01 /3 [286,PRIV]
|
||||
LLDT r/m16 ; 0F 00 /2 [286,PRIV]
|
||||
LMSW r/m16 ; 0F 01 /6 [286,PRIV]
|
||||
LOADALL ; 0F 07 [386,UNDOC]
|
||||
LOADALL286 ; 0F 05 [286,UNDOC]
|
||||
LODSB ; AC [8086]
|
||||
LODSW ; o16 AD [8086]
|
||||
LODSD ; o32 AD [386]
|
||||
LOOP imm ; E2 rb [8086]
|
||||
LOOP imm,CX ; a16 E2 rb [8086]
|
||||
LOOP imm,ECX ; a32 E2 rb [386]
|
||||
LOOPE imm ; E1 rb [8086]
|
||||
LOOPE imm,CX ; a16 E1 rb [8086]
|
||||
LOOPE imm,ECX ; a32 E1 rb [386]
|
||||
LOOPZ imm ; E1 rb [8086]
|
||||
LOOPZ imm,CX ; a16 E1 rb [8086]
|
||||
LOOPZ imm,ECX ; a32 E1 rb [386]
|
||||
LOOPNE imm ; E0 rb [8086]
|
||||
LOOPNE imm,CX ; a16 E0 rb [8086]
|
||||
LOOPNE imm,ECX ; a32 E0 rb [386]
|
||||
LOOPNZ imm ; E0 rb [8086]
|
||||
LOOPNZ imm,CX ; a16 E0 rb [8086]
|
||||
LOOPNZ imm,ECX ; a32 E0 rb [386]
|
||||
LSL reg16,r/m16 ; o16 0F 03 /r [286,PRIV]
|
||||
LSL reg32,r/m32 ; o32 0F 03 /r [286,PRIV]
|
||||
LTR r/m16 ; 0F 00 /3 [286,PRIV]
|
||||
MOV AL,memoffs8 ; A0 ow/od [8086]
|
||||
MOV AX,memoffs16 ; o16 A1 ow/od [8086]
|
||||
MOV EAX,memoffs32 ; o32 A1 ow/od [386]
|
||||
MOV memoffs8,AL ; A2 ow/od [8086]
|
||||
MOV memoffs16,AX ; o16 A3 ow/od [8086]
|
||||
MOV memoffs32,EAX ; o32 A3 ow/od [386]
|
||||
MOV r/m8,reg8 ; 88 /r [8086]
|
||||
MOV r/m16,reg16 ; o16 89 /r [8086]
|
||||
MOV r/m32,reg32 ; o32 89 /r [386]
|
||||
MOV reg8,r/m8 ; 8A /r [8086]
|
||||
MOV reg16,r/m16 ; o16 8B /r [8086]
|
||||
MOV reg32,r/m32 ; o32 8B /r [386]
|
||||
MOV reg8,imm8 ; B0+r ib [8086]
|
||||
MOV reg16,imm16 ; o16 B8+r iw [8086]
|
||||
MOV reg32,imm32 ; o32 B8+r id [386]
|
||||
MOV r/m8,imm8 ; C6 /0 ib [8086]
|
||||
MOV r/m16,imm16 ; o16 C7 /0 iw [8086]
|
||||
MOV r/m32,imm32 ; o32 C7 /0 id [386]
|
||||
MOV r/m16,segreg ; o16 8C /r [8086]
|
||||
MOV r/m32,segreg ; o32 8C /r [386]
|
||||
MOV segreg,r/m16 ; o16 8E /r [8086]
|
||||
MOV segreg,r/m32 ; o32 8E /r [386]
|
||||
MOV reg32,CR0/2/3/4 ; 0F 20 /r [386]
|
||||
MOV reg32,DR0/1/2/3/6/7 ; 0F 21 /r [386]
|
||||
MOV reg32,TR3/4/5/6/7 ; 0F 24 /r [386]
|
||||
MOV CR0/2/3/4,reg32 ; 0F 22 /r [386]
|
||||
MOV DR0/1/2/3/6/7,reg32 ; 0F 23 /r [386]
|
||||
MOV TR3/4/5/6/7,reg32 ; 0F 26 /r [386]
|
||||
MOVD mmxreg,r/m32 ; 0F 6E /r [PENT,MMX]
|
||||
MOVD r/m32,mmxreg ; 0F 7E /r [PENT,MMX]
|
||||
MOVQ mmxreg,r/m64 ; 0F 6F /r [PENT,MMX]
|
||||
MOVQ r/m64,mmxreg ; 0F 7F /r [PENT,MMX]
|
||||
MOVSB ; A4 [8086]
|
||||
MOVSW ; o16 A5 [8086]
|
||||
MOVSD ; o32 A5 [386]
|
||||
MOVSX reg16,r/m8 ; o16 0F BE /r [386]
|
||||
MOVSX reg32,r/m8 ; o32 0F BE /r [386]
|
||||
MOVSX reg32,r/m16 ; o32 0F BF /r [386]
|
||||
MOVZX reg16,r/m8 ; o16 0F B6 /r [386]
|
||||
MOVZX reg32,r/m8 ; o32 0F B6 /r [386]
|
||||
MOVZX reg32,r/m16 ; o32 0F B7 /r [386]
|
||||
MUL r/m8 ; F6 /4 [8086]
|
||||
MUL r/m16 ; o16 F7 /4 [8086]
|
||||
MUL r/m32 ; o32 F7 /4 [386]
|
||||
NEG r/m8 ; F6 /3 [8086]
|
||||
NEG r/m16 ; o16 F7 /3 [8086]
|
||||
NEG r/m32 ; o32 F7 /3 [386]
|
||||
NOT r/m8 ; F6 /2 [8086]
|
||||
NOT r/m16 ; o16 F7 /2 [8086]
|
||||
NOT r/m32 ; o32 F7 /2 [386]
|
||||
NOP ; 90 [8086]
|
||||
OR AL,imm8 ; 0C ib [8086]
|
||||
OR AX,imm16 ; o16 0D iw [8086]
|
||||
OR EAX,imm32 ; o32 0D id [386]
|
||||
OR r/m8,reg8 ; 08 /r [8086]
|
||||
OR r/m16,reg16 ; o16 09 /r [8086]
|
||||
OR r/m32,reg32 ; o32 09 /r [386]
|
||||
OR reg8,r/m8 ; 0A /r [8086]
|
||||
OR reg16,r/m16 ; o16 0B /r [8086]
|
||||
OR reg32,r/m32 ; o32 0B /r [386]
|
||||
OR r/m8,imm8 ; 80 /1 ib [8086]
|
||||
OR r/m16,imm16 ; o16 81 /1 iw [8086]
|
||||
OR r/m32,imm32 ; o32 81 /1 id [386]
|
||||
OR r/m16,imm8 ; o16 83 /1 ib [8086]
|
||||
OR r/m32,imm8 ; o32 83 /1 ib [386]
|
||||
OUT imm8,AL ; E6 ib [8086]
|
||||
OUT imm8,AX ; o16 E7 ib [8086]
|
||||
OUT imm8,EAX ; o32 E7 ib [386]
|
||||
OUT DX,AL ; EE [8086]
|
||||
OUT DX,AX ; o16 EF [8086]
|
||||
OUT DX,EAX ; o32 EF [386]
|
||||
OUTSB ; 6E [186]
|
||||
OUTSW ; o16 6F [186]
|
||||
OUTSD ; o32 6F [386]
|
||||
PACKSSDW mmxreg,r/m64 ; 0F 6B /r [PENT,MMX]
|
||||
PACKSSWB mmxreg,r/m64 ; 0F 63 /r [PENT,MMX]
|
||||
PACKUSWB mmxreg,r/m64 ; 0F 67 /r [PENT,MMX]
|
||||
PADDB mmxreg,r/m64 ; 0F FC /r [PENT,MMX]
|
||||
PADDW mmxreg,r/m64 ; 0F FD /r [PENT,MMX]
|
||||
PADDD mmxreg,r/m64 ; 0F FE /r [PENT,MMX]
|
||||
PADDSB mmxreg,r/m64 ; 0F EC /r [PENT,MMX]
|
||||
PADDSW mmxreg,r/m64 ; 0F ED /r [PENT,MMX]
|
||||
PADDUSB mmxreg,r/m64 ; 0F DC /r [PENT,MMX]
|
||||
PADDUSW mmxreg,r/m64 ; 0F DD /r [PENT,MMX]
|
||||
PADDSIW mmxreg,r/m64 ; 0F 51 /r [CYRIX,MMX]
|
||||
PAND mmxreg,r/m64 ; 0F DB /r [PENT,MMX]
|
||||
PANDN mmxreg,r/m64 ; 0F DF /r [PENT,MMX]
|
||||
PAVEB mmxreg,r/m64 ; 0F 50 /r [CYRIX,MMX]
|
||||
PCMPEQB mmxreg,r/m64 ; 0F 74 /r [PENT,MMX]
|
||||
PCMPEQW mmxreg,r/m64 ; 0F 75 /r [PENT,MMX]
|
||||
PCMPEQD mmxreg,r/m64 ; 0F 76 /r [PENT,MMX]
|
||||
PCMPGTB mmxreg,r/m64 ; 0F 64 /r [PENT,MMX]
|
||||
PCMPGTW mmxreg,r/m64 ; 0F 65 /r [PENT,MMX]
|
||||
PCMPGTD mmxreg,r/m64 ; 0F 66 /r [PENT,MMX]
|
||||
PDISTIB mmxreg,mem64 ; 0F 54 /r [CYRIX,MMX]
|
||||
PMACHRIW mmxreg,mem64 ; 0F 5E /r [CYRIX,MMX]
|
||||
PMADDWD mmxreg,r/m64 ; 0F F5 /r [PENT,MMX]
|
||||
PMAGW mmxreg,r/m64 ; 0F 52 /r [CYRIX,MMX]
|
||||
PMULHRW mmxreg,r/m64 ; 0F 59 /r [CYRIX,MMX]
|
||||
PMULHRIW mmxreg,r/m64 ; 0F 5D /r [CYRIX,MMX]
|
||||
PMULHW mmxreg,r/m64 ; 0F E5 /r [PENT,MMX]
|
||||
PMULLW mmxreg,r/m64 ; 0F D5 /r [PENT,MMX]
|
||||
PMVZB mmxreg,mem64 ; 0F 58 /r [CYRIX,MMX]
|
||||
PMVNZB mmxreg,mem64 ; 0F 5A /r [CYRIX,MMX]
|
||||
PMVLZB mmxreg,mem64 ; 0F 5B /r [CYRIX,MMX]
|
||||
PMVGEZB mmxreg,mem64 ; 0F 5C /r [CYRIX,MMX]
|
||||
POP reg16 ; o16 58+r [8086]
|
||||
POP reg32 ; o32 58+r [386]
|
||||
POP r/m16 ; o16 8F /0 [8086]
|
||||
POP r/m32 ; o32 8F /0 [386]
|
||||
POP CS ; 0F [8086,UNDOC]
|
||||
POP DS ; 1F [8086]
|
||||
POP ES ; 07 [8086]
|
||||
POP SS ; 17 [8086]
|
||||
POP FS ; 0F A1 [386]
|
||||
POP GS ; 0F A9 [386]
|
||||
POPA ; 61 [186]
|
||||
POPAW ; o16 61 [186]
|
||||
POPAD ; o32 61 [386]
|
||||
POPF ; 9D [186]
|
||||
POPFW ; o16 9D [186]
|
||||
POPFD ; o32 9D [386]
|
||||
POR mmxreg,r/m64 ; 0F EB /r [PENT,MMX]
|
||||
PSLLW mmxreg,r/m64 ; 0F F1 /r [PENT,MMX]
|
||||
PSLLW mmxreg,imm8 ; 0F 71 /6 ib [PENT,MMX]
|
||||
PSLLD mmxreg,r/m64 ; 0F F2 /r [PENT,MMX]
|
||||
PSLLD mmxreg,imm8 ; 0F 72 /6 ib [PENT,MMX]
|
||||
PSLLQ mmxreg,r/m64 ; 0F F3 /r [PENT,MMX]
|
||||
PSLLQ mmxreg,imm8 ; 0F 73 /6 ib [PENT,MMX]
|
||||
PSRAW mmxreg,r/m64 ; 0F E1 /r [PENT,MMX]
|
||||
PSRAW mmxreg,imm8 ; 0F 71 /4 ib [PENT,MMX]
|
||||
PSRAD mmxreg,r/m64 ; 0F E2 /r [PENT,MMX]
|
||||
PSRAD mmxreg,imm8 ; 0F 72 /4 ib [PENT,MMX]
|
||||
PSRLW mmxreg,r/m64 ; 0F D1 /r [PENT,MMX]
|
||||
PSRLW mmxreg,imm8 ; 0F 71 /2 ib [PENT,MMX]
|
||||
PSRLD mmxreg,r/m64 ; 0F D2 /r [PENT,MMX]
|
||||
PSRLD mmxreg,imm8 ; 0F 72 /2 ib [PENT,MMX]
|
||||
PSRLQ mmxreg,r/m64 ; 0F D3 /r [PENT,MMX]
|
||||
PSRLQ mmxreg,imm8 ; 0F 73 /2 ib [PENT,MMX]
|
||||
PSUBB mmxreg,r/m64 ; 0F F8 /r [PENT,MMX]
|
||||
PSUBW mmxreg,r/m64 ; 0F F9 /r [PENT,MMX]
|
||||
PSUBD mmxreg,r/m64 ; 0F FA /r [PENT,MMX]
|
||||
PSUBSB mmxreg,r/m64 ; 0F E8 /r [PENT,MMX]
|
||||
PSUBSW mmxreg,r/m64 ; 0F E9 /r [PENT,MMX]
|
||||
PSUBUSB mmxreg,r/m64 ; 0F D8 /r [PENT,MMX]
|
||||
PSUBUSW mmxreg,r/m64 ; 0F D9 /r [PENT,MMX]
|
||||
PSUBSIW mmxreg,r/m64 ; 0F 55 /r [CYRIX,MMX]
|
||||
PUNPCKHBW mmxreg,r/m64 ; 0F 68 /r [PENT,MMX]
|
||||
PUNPCKHWD mmxreg,r/m64 ; 0F 69 /r [PENT,MMX]
|
||||
PUNPCKHDQ mmxreg,r/m64 ; 0F 6A /r [PENT,MMX]
|
||||
PUNPCKLBW mmxreg,r/m64 ; 0F 60 /r [PENT,MMX]
|
||||
PUNPCKLWD mmxreg,r/m64 ; 0F 61 /r [PENT,MMX]
|
||||
PUNPCKLDQ mmxreg,r/m64 ; 0F 62 /r [PENT,MMX]
|
||||
PUSH reg16 ; o16 50+r [8086]
|
||||
PUSH reg32 ; o32 50+r [386]
|
||||
PUSH r/m16 ; o16 FF /6 [8086]
|
||||
PUSH r/m32 ; o32 FF /6 [386]
|
||||
PUSH CS ; 0E [8086]
|
||||
PUSH DS ; 1E [8086]
|
||||
PUSH ES ; 06 [8086]
|
||||
PUSH SS ; 16 [8086]
|
||||
PUSH FS ; 0F A0 [386]
|
||||
PUSH GS ; 0F A8 [386]
|
||||
PUSH imm8 ; 6A ib [286]
|
||||
PUSH imm16 ; o16 68 iw [286]
|
||||
PUSH imm32 ; o32 68 id [386]
|
||||
PUSHA ; 60 [186]
|
||||
PUSHAD ; o32 60 [386]
|
||||
PUSHAW ; o16 60 [186]
|
||||
PUSHF ; 9C [186]
|
||||
PUSHFD ; o32 9C [386]
|
||||
PUSHFW ; o16 9C [186]
|
||||
PXOR mmxreg,r/m64 ; 0F EF /r [PENT,MMX]
|
||||
RCL r/m8,1 ; D0 /2 [8086]
|
||||
RCL r/m8,CL ; D2 /2 [8086]
|
||||
RCL r/m8,imm8 ; C0 /2 ib [286]
|
||||
RCL r/m16,1 ; o16 D1 /2 [8086]
|
||||
RCL r/m16,CL ; o16 D3 /2 [8086]
|
||||
RCL r/m16,imm8 ; o16 C1 /2 ib [286]
|
||||
RCL r/m32,1 ; o32 D1 /2 [386]
|
||||
RCL r/m32,CL ; o32 D3 /2 [386]
|
||||
RCL r/m32,imm8 ; o32 C1 /2 ib [386]
|
||||
RCR r/m8,1 ; D0 /3 [8086]
|
||||
RCR r/m8,CL ; D2 /3 [8086]
|
||||
RCR r/m8,imm8 ; C0 /3 ib [286]
|
||||
RCR r/m16,1 ; o16 D1 /3 [8086]
|
||||
RCR r/m16,CL ; o16 D3 /3 [8086]
|
||||
RCR r/m16,imm8 ; o16 C1 /3 ib [286]
|
||||
RCR r/m32,1 ; o32 D1 /3 [386]
|
||||
RCR r/m32,CL ; o32 D3 /3 [386]
|
||||
RCR r/m32,imm8 ; o32 C1 /3 ib [386]
|
||||
RDMSR ; 0F 32 [PENT]
|
||||
RDPMC ; 0F 33 [P6]
|
||||
RDTSC ; 0F 31 [PENT]
|
||||
RET ; C3 [8086]
|
||||
RET imm16 ; C2 iw [8086]
|
||||
RETF ; CB [8086]
|
||||
RETF imm16 ; CA iw [8086]
|
||||
RETN ; C3 [8086]
|
||||
RETN imm16 ; C2 iw [8086]
|
||||
ROL r/m8,1 ; D0 /0 [8086]
|
||||
ROL r/m8,CL ; D2 /0 [8086]
|
||||
ROL r/m8,imm8 ; C0 /0 ib [286]
|
||||
ROL r/m16,1 ; o16 D1 /0 [8086]
|
||||
ROL r/m16,CL ; o16 D3 /0 [8086]
|
||||
ROL r/m16,imm8 ; o16 C1 /0 ib [286]
|
||||
ROL r/m32,1 ; o32 D1 /0 [386]
|
||||
ROL r/m32,CL ; o32 D3 /0 [386]
|
||||
ROL r/m32,imm8 ; o32 C1 /0 ib [386]
|
||||
ROR r/m8,1 ; D0 /1 [8086]
|
||||
ROR r/m8,CL ; D2 /1 [8086]
|
||||
ROR r/m8,imm8 ; C0 /1 ib [286]
|
||||
ROR r/m16,1 ; o16 D1 /1 [8086]
|
||||
ROR r/m16,CL ; o16 D3 /1 [8086]
|
||||
ROR r/m16,imm8 ; o16 C1 /1 ib [286]
|
||||
ROR r/m32,1 ; o32 D1 /1 [386]
|
||||
ROR r/m32,CL ; o32 D3 /1 [386]
|
||||
ROR r/m32,imm8 ; o32 C1 /1 ib [386]
|
||||
RSM ; 0F AA [PENT]
|
||||
SAHF ; 9E [8086]
|
||||
SAL r/m8,1 ; D0 /4 [8086]
|
||||
SAL r/m8,CL ; D2 /4 [8086]
|
||||
SAL r/m8,imm8 ; C0 /4 ib [286]
|
||||
SAL r/m16,1 ; o16 D1 /4 [8086]
|
||||
SAL r/m16,CL ; o16 D3 /4 [8086]
|
||||
SAL r/m16,imm8 ; o16 C1 /4 ib [286]
|
||||
SAL r/m32,1 ; o32 D1 /4 [386]
|
||||
SAL r/m32,CL ; o32 D3 /4 [386]
|
||||
SAL r/m32,imm8 ; o32 C1 /4 ib [386]
|
||||
SAR r/m8,1 ; D0 /7 [8086]
|
||||
SAR r/m8,CL ; D2 /7 [8086]
|
||||
SAR r/m8,imm8 ; C0 /7 ib [286]
|
||||
SAR r/m16,1 ; o16 D1 /7 [8086]
|
||||
SAR r/m16,CL ; o16 D3 /7 [8086]
|
||||
SAR r/m16,imm8 ; o16 C1 /7 ib [286]
|
||||
SAR r/m32,1 ; o32 D1 /7 [386]
|
||||
SAR r/m32,CL ; o32 D3 /7 [386]
|
||||
SAR r/m32,imm8 ; o32 C1 /7 ib [386]
|
||||
SALC ; D6 [8086,UNDOC]
|
||||
SBB AL,imm8 ; 1C ib [8086]
|
||||
SBB AX,imm16 ; o16 1D iw [8086]
|
||||
SBB EAX,imm32 ; o32 1D id [386]
|
||||
SBB r/m8,reg8 ; 18 /r [8086]
|
||||
SBB r/m16,reg16 ; o16 19 /r [8086]
|
||||
SBB r/m32,reg32 ; o32 19 /r [386]
|
||||
SBB reg8,r/m8 ; 1A /r [8086]
|
||||
SBB reg16,r/m16 ; o16 1B /r [8086]
|
||||
SBB reg32,r/m32 ; o32 1B /r [386]
|
||||
SBB r/m8,imm8 ; 80 /3 ib [8086]
|
||||
SBB r/m16,imm16 ; o16 81 /3 iw [8086]
|
||||
SBB r/m32,imm32 ; o32 81 /3 id [386]
|
||||
SBB r/m16,imm8 ; o16 83 /3 ib [8086]
|
||||
SBB r/m32,imm8 ; o32 83 /3 ib [8086]
|
||||
SCASB ; AE [8086]
|
||||
SCASW ; o16 AF [8086]
|
||||
SCASD ; o32 AF [386]
|
||||
SGDT mem ; 0F 01 /0 [286,PRIV]
|
||||
SIDT mem ; 0F 01 /1 [286,PRIV]
|
||||
SLDT r/m16 ; 0F 00 /0 [286,PRIV]
|
||||
SHL r/m8,1 ; D0 /4 [8086]
|
||||
SHL r/m8,CL ; D2 /4 [8086]
|
||||
SHL r/m8,imm8 ; C0 /4 ib [286]
|
||||
SHL r/m16,1 ; o16 D1 /4 [8086]
|
||||
SHL r/m16,CL ; o16 D3 /4 [8086]
|
||||
SHL r/m16,imm8 ; o16 C1 /4 ib [286]
|
||||
SHL r/m32,1 ; o32 D1 /4 [386]
|
||||
SHL r/m32,CL ; o32 D3 /4 [386]
|
||||
SHL r/m32,imm8 ; o32 C1 /4 ib [386]
|
||||
SHR r/m8,1 ; D0 /5 [8086]
|
||||
SHR r/m8,CL ; D2 /5 [8086]
|
||||
SHR r/m8,imm8 ; C0 /5 ib [286]
|
||||
SHR r/m16,1 ; o16 D1 /5 [8086]
|
||||
SHR r/m16,CL ; o16 D3 /5 [8086]
|
||||
SHR r/m16,imm8 ; o16 C1 /5 ib [286]
|
||||
SHR r/m32,1 ; o32 D1 /5 [386]
|
||||
SHR r/m32,CL ; o32 D3 /5 [386]
|
||||
SHR r/m32,imm8 ; o32 C1 /5 ib [386]
|
||||
SHLD r/m16,reg16,imm8 ; o16 0F A4 /r ib [386]
|
||||
SHLD r/m16,reg32,imm8 ; o32 0F A4 /r ib [386]
|
||||
SHLD r/m16,reg16,CL ; o16 0F A5 /r [386]
|
||||
SHLD r/m16,reg32,CL ; o32 0F A5 /r [386]
|
||||
SHRD r/m16,reg16,imm8 ; o16 0F AC /r ib [386]
|
||||
SHRD r/m32,reg32,imm8 ; o32 0F AC /r ib [386]
|
||||
SHRD r/m16,reg16,CL ; o16 0F AD /r [386]
|
||||
SHRD r/m32,reg32,CL ; o32 0F AD /r [386]
|
||||
SMI ; F1 [386,UNDOC]
|
||||
SMSW r/m16 ; 0F 01 /4 [286,PRIV]
|
||||
STC ; F9 [8086]
|
||||
STD ; FD [8086]
|
||||
STI ; FB [8086]
|
||||
STOSB ; AA [8086]
|
||||
STOSW ; o16 AB [8086]
|
||||
STOSD ; o32 AB [386]
|
||||
STR r/m16 ; 0F 00 /1 [286,PRIV]
|
||||
SUB AL,imm8 ; 2C ib [8086]
|
||||
SUB AX,imm16 ; o16 2D iw [8086]
|
||||
SUB EAX,imm32 ; o32 2D id [386]
|
||||
SUB r/m8,reg8 ; 28 /r [8086]
|
||||
SUB r/m16,reg16 ; o16 29 /r [8086]
|
||||
SUB r/m32,reg32 ; o32 29 /r [386]
|
||||
SUB reg8,r/m8 ; 2A /r [8086]
|
||||
SUB reg16,r/m16 ; o16 2B /r [8086]
|
||||
SUB reg32,r/m32 ; o32 2B /r [386]
|
||||
SUB r/m8,imm8 ; 80 /5 ib [8086]
|
||||
SUB r/m16,imm16 ; o16 81 /5 iw [8086]
|
||||
SUB r/m32,imm32 ; o32 81 /5 id [386]
|
||||
SUB r/m16,imm8 ; o16 83 /5 ib [8086]
|
||||
SUB r/m32,imm8 ; o32 83 /5 ib [386]
|
||||
TEST AL,imm8 ; A8 ib [8086]
|
||||
TEST AX,imm16 ; o16 A9 iw [8086]
|
||||
TEST EAX,imm32 ; o32 A9 id [386]
|
||||
TEST r/m8,reg8 ; 84 /r [8086]
|
||||
TEST r/m16,reg16 ; o16 85 /r [8086]
|
||||
TEST r/m32,reg32 ; o32 85 /r [386]
|
||||
TEST r/m8,imm8 ; F6 /7 ib [8086]
|
||||
TEST r/m16,imm16 ; o16 F7 /7 iw [8086]
|
||||
TEST r/m32,imm32 ; o32 F7 /7 id [386]
|
||||
UMOV r/m8,reg8 ; 0F 10 /r [386,UNDOC]
|
||||
UMOV r/m16,reg16 ; o16 0F 11 /r [386,UNDOC]
|
||||
UMOV r/m32,reg32 ; o32 0F 11 /r [386,UNDOC]
|
||||
UMOV reg8,r/m8 ; 0F 12 /r [386,UNDOC]
|
||||
UMOV reg16,r/m16 ; o16 0F 13 /r [386,UNDOC]
|
||||
UMOV reg32,r/m32 ; o32 0F 13 /r [386,UNDOC]
|
||||
VERR r/m16 ; 0F 00 /4 [286,PRIV]
|
||||
VERW r/m16 ; 0F 00 /5 [286,PRIV]
|
||||
WAIT ; 9B [8086]
|
||||
WBINVD ; 0F 09 [486]
|
||||
WRMSR ; 0F 30 [PENT]
|
||||
XADD r/m8,reg8 ; 0F C0 /r [486]
|
||||
XADD r/m16,reg16 ; o16 0F C1 /r [486]
|
||||
XADD r/m32,reg32 ; o32 0F C1 /r [486]
|
||||
XBTS reg16,r/m16 ; o16 0F A6 /r [386,UNDOC]
|
||||
XBTS reg32,r/m32 ; o32 0F A6 /r [386,UNDOC]
|
||||
XCHG reg8,r/m8 ; 86 /r [8086]
|
||||
XCHG reg16,r/m8 ; o16 87 /r [8086]
|
||||
XCHG reg32,r/m32 ; o32 87 /r [386]
|
||||
XCHG r/m8,reg8 ; 86 /r [8086]
|
||||
XCHG r/m16,reg16 ; o16 87 /r [8086]
|
||||
XCHG r/m32,reg32 ; o32 87 /r [386]
|
||||
XCHG AX,reg16 ; o16 90+r [8086]
|
||||
XCHG EAX,reg32 ; o32 90+r [386]
|
||||
XCHG reg16,AX ; o16 90+r [8086]
|
||||
XCHG reg32,EAX ; o32 90+r [386]
|
||||
XLATB ; D7 [8086]
|
||||
XOR AL,imm8 ; 34 ib [8086]
|
||||
XOR AX,imm16 ; o16 35 iw [8086]
|
||||
XOR EAX,imm32 ; o32 35 id [386]
|
||||
XOR r/m8,reg8 ; 30 /r [8086]
|
||||
XOR r/m16,reg16 ; o16 31 /r [8086]
|
||||
XOR r/m32,reg32 ; o32 31 /r [386]
|
||||
XOR reg8,r/m8 ; 32 /r [8086]
|
||||
XOR reg16,r/m16 ; o16 33 /r [8086]
|
||||
XOR reg32,r/m32 ; o32 33 /r [386]
|
||||
XOR r/m8,imm8 ; 80 /6 ib [8086]
|
||||
XOR r/m16,imm16 ; o16 81 /6 iw [8086]
|
||||
XOR r/m32,imm32 ; o32 81 /6 id [386]
|
||||
XOR r/m16,imm8 ; o16 83 /6 ib [8086]
|
||||
XOR r/m32,imm8 ; o32 83 /6 ib [386]
|
80
bblaunch/bblaunch.cpp
Normal file
80
bblaunch/bblaunch.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
|
||||
#include <string>
|
||||
#include <windows.h>
|
||||
|
||||
#include "checkdx.h"
|
||||
#include "checkie.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
static const char *dx_err=
|
||||
"You must have DirectX version 7 installed to run Blitz Basic.\n\n"
|
||||
"DirectX 7 is provided on the Blitz Basic CD in the DirectX7 folder.\n\n"
|
||||
"The latest version of DirectX is available from www.microsoft.com";
|
||||
|
||||
static const char *ie_err=
|
||||
"You must have Internet Explorer version 4 installed to run Blitz Basic.\n\n"
|
||||
"Internet Explorer 5 is provided on the Blitz Basic CD in the IExplorer5 folder.\n\n"
|
||||
"The latest version of Internet Explorer is available from www.microsoft.com";
|
||||
|
||||
static const char *bb_err=
|
||||
"Unable to run Blitz Basic";
|
||||
|
||||
static const char *md_err=
|
||||
"Your desktop must be in high-colour mode to use Blitz Basic.\n\n"
|
||||
"You can change your display settings from the control panel.";
|
||||
|
||||
static string getAppDir(){
|
||||
char buff[MAX_PATH];
|
||||
if( GetModuleFileName( 0,buff,MAX_PATH ) ){
|
||||
string t=buff;
|
||||
int n=t.find_last_of( '\\' );
|
||||
if( n!=string::npos ) t=t.substr( 0,n );
|
||||
return t;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static void fail( const char *p ){
|
||||
::MessageBox( 0,p,"Blitz Basic Error",MB_SETFOREGROUND|MB_TOPMOST|MB_ICONERROR );
|
||||
ExitProcess(-1);
|
||||
}
|
||||
|
||||
static int desktopDepth(){
|
||||
HDC hdc=GetDC( GetDesktopWindow() );
|
||||
return GetDeviceCaps( hdc,BITSPIXEL );
|
||||
}
|
||||
|
||||
int _stdcall WinMain( HINSTANCE inst,HINSTANCE prev,char *cmd,int show ){
|
||||
|
||||
if( desktopDepth()<16 ) fail( md_err );
|
||||
|
||||
#ifndef PLUS
|
||||
if( getDXVersion()<7 ) fail( dx_err );
|
||||
#endif
|
||||
|
||||
if( getIEVersion()<4 ) fail( ie_err );
|
||||
|
||||
//Ugly hack to get application dir...
|
||||
string t=getAppDir();
|
||||
putenv( ("blitzpath="+t).c_str() );
|
||||
SetCurrentDirectory( t.c_str() );
|
||||
t=t+"\\bin\\ide.exe "+cmd;
|
||||
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
ZeroMemory(&si,sizeof(si));si.cb=sizeof(si);
|
||||
if( !CreateProcess( 0,(char*)t.c_str(),0,0,0,0,0,0,&si,&pi ) ){
|
||||
::MessageBox( 0,bb_err,"Blitz Basic Error",MB_SETFOREGROUND|MB_TOPMOST|MB_ICONERROR );
|
||||
ExitProcess(-1);
|
||||
}
|
||||
|
||||
//wait for BB to start
|
||||
WaitForInputIdle( pi.hProcess,INFINITE );
|
||||
|
||||
// Close process and thread handles.
|
||||
CloseHandle( pi.hProcess );
|
||||
CloseHandle( pi.hThread );
|
||||
|
||||
return 0;
|
||||
}
|
237
bblaunch/bblaunch.dsp
Normal file
237
bblaunch/bblaunch.dsp
Normal file
@ -0,0 +1,237 @@
|
||||
# Microsoft Developer Studio Project File - Name="bblaunch" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Application" 0x0101
|
||||
|
||||
CFG=bblaunch - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "bblaunch.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "bblaunch.mak" CFG="bblaunch - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "bblaunch - Win32 Release" (based on "Win32 (x86) Application")
|
||||
!MESSAGE "bblaunch - Win32 Debug" (based on "Win32 (x86) Application")
|
||||
!MESSAGE "bblaunch - Win32 Blitz3DRelease" (based on "Win32 (x86) Application")
|
||||
!MESSAGE "bblaunch - Win32 Blitz2DRelease" (based on "Win32 (x86) Application")
|
||||
!MESSAGE "bblaunch - Win32 Blitz3DEdu" (based on "Win32 (x86) Application")
|
||||
!MESSAGE "bblaunch - Win32 Blitz3DDemo" (based on "Win32 (x86) Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "bblaunch - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O1 /Ob2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
|
||||
# ADD LINK32 dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"..\blitzbasic\blitzbasic.exe"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bblaunch - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /incremental:no /debug /machine:I386 /out:"..\blitzbasic\blitzbasic.exe" /fixed:no
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "bblaunch - Win32 Blitz3DRelease"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "bblaunch___Win32_Blitz3DRelease"
|
||||
# PROP BASE Intermediate_Dir "bblaunch___Win32_Blitz3DRelease"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "bblaunch___Win32_Blitz3DRelease"
|
||||
# PROP Intermediate_Dir "bblaunch___Win32_Blitz3DRelease"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O1 /Ob2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "_WINDOWS" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /FD /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"..\blitzbasic\blitzbasic.exe"
|
||||
# ADD LINK32 dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"..\..\release\blitz3drelease\Blitz3D.exe"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bblaunch - Win32 Blitz2DRelease"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "bblaunch___Win32_Blitz2DRelease"
|
||||
# PROP BASE Intermediate_Dir "bblaunch___Win32_Blitz2DRelease"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "bblaunch___Win32_Blitz2DRelease"
|
||||
# PROP Intermediate_Dir "bblaunch___Win32_Blitz2DRelease"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O1 /Ob2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"..\..\release\blitz3drelease\Blitz3D.exe"
|
||||
# ADD LINK32 dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"..\..\release\blitz2drelease\BlitzBasic.exe"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bblaunch - Win32 Blitz3DEdu"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "bblaunch___Win32_Blitz3DEdu"
|
||||
# PROP BASE Intermediate_Dir "bblaunch___Win32_Blitz3DEdu"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "bblaunch___Win32_Blitz3DEdu"
|
||||
# PROP Intermediate_Dir "bblaunch___Win32_Blitz3DEdu"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "PRO" /YX /FD /c
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "_WINDOWS" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /D "EDU" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"..\..\release\blitz3drelease\Blitz3D.exe"
|
||||
# ADD LINK32 dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"..\..\release\blitz3dedu\Blitz3D.exe"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bblaunch - Win32 Blitz3DDemo"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "bblaunch___Win32_Blitz3DDemo"
|
||||
# PROP BASE Intermediate_Dir "bblaunch___Win32_Blitz3DDemo"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "bblaunch___Win32_Blitz3DDemo"
|
||||
# PROP Intermediate_Dir "bblaunch___Win32_Blitz3DDemo"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "PRO" /YX /FD /c
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "_WINDOWS" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /D "DEMO" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"..\..\release\blitz3drelease\Blitz3D.exe"
|
||||
# ADD LINK32 dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386 /out:"..\..\release\blitz3ddemo\Blitz3DDemo.exe"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "bblaunch - Win32 Release"
|
||||
# Name "bblaunch - Win32 Debug"
|
||||
# Name "bblaunch - Win32 Blitz3DRelease"
|
||||
# Name "bblaunch - Win32 Blitz2DRelease"
|
||||
# Name "bblaunch - Win32 Blitz3DEdu"
|
||||
# Name "bblaunch - Win32 Blitz3DDemo"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bblaunch.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bblaunch.ico
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bblaunch.rc
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\checkdx.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\checkdx.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\checkie.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\checkie.h
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
BIN
bblaunch/bblaunch.ico
Normal file
BIN
bblaunch/bblaunch.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
72
bblaunch/bblaunch.rc
Normal file
72
bblaunch/bblaunch.rc
Normal file
@ -0,0 +1,72 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
//
|
||||
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
IDI_ICON1 ICON DISCARDABLE "bblaunch.ico"
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
17
bblaunch/blitzide.prefs
Normal file
17
bblaunch/blitzide.prefs
Normal file
@ -0,0 +1,17 @@
|
||||
prg_debug 1
|
||||
prg_windowed 0
|
||||
win_maximized 0
|
||||
win_notoolbar 0
|
||||
win_rect 0 0 691 542
|
||||
font_editor blitz 12
|
||||
font_tabs verdana 8
|
||||
rgb_bkgrnd 206060
|
||||
rgb_string ff00
|
||||
rgb_ident ffffff
|
||||
rgb_keyword ffe75f
|
||||
rgb_comment ffff
|
||||
rgb_digit c8f0ff
|
||||
rgb_default fff0c8
|
||||
edit_tabs 4
|
||||
edit_blkcursor 0
|
||||
img_toolbar toolbar.bmp
|
339
bblaunch/checkdx.cpp
Normal file
339
bblaunch/checkdx.cpp
Normal file
@ -0,0 +1,339 @@
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// File: GetDXVer.cpp
|
||||
//
|
||||
// Desc: Demonstrates how applications can detect what version of DirectX
|
||||
// is installed.
|
||||
//
|
||||
// (C) Copyright 1995-1997 Microsoft Corp. All rights reserved.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <ddraw.h>
|
||||
#include <dinput.h>
|
||||
#include <dmusici.h>
|
||||
|
||||
typedef HRESULT(WINAPI * DIRECTDRAWCREATE)( GUID*, LPDIRECTDRAW*, IUnknown* );
|
||||
typedef HRESULT(WINAPI * DIRECTDRAWCREATEEX)( GUID*, VOID**, REFIID, IUnknown* );
|
||||
typedef HRESULT(WINAPI * DIRECTINPUTCREATE)( HINSTANCE, DWORD, LPDIRECTINPUT*,
|
||||
IUnknown* );
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Name: GetDXVersion()
|
||||
// Desc: This function returns two arguments:
|
||||
// dwDXVersion:
|
||||
// 0x0000 = No DirectX installed
|
||||
// 0x0100 = DirectX version 1 installed
|
||||
// 0x0200 = DirectX 2 installed
|
||||
// 0x0300 = DirectX 3 installed
|
||||
// 0x0500 = At least DirectX 5 installed.
|
||||
// 0x0600 = At least DirectX 6 installed.
|
||||
// 0x0601 = At least DirectX 6.1 installed.
|
||||
// 0x0700 = At least DirectX 7 installed.
|
||||
// dwDXPlatform:
|
||||
// 0 = Unknown (This is a failure case)
|
||||
// VER_PLATFORM_WIN32_WINDOWS = Windows 9X platform
|
||||
// VER_PLATFORM_WIN32_NT = Windows NT platform
|
||||
//
|
||||
// Please note that this code is intended as a general guideline. Your
|
||||
// app will probably be able to simply query for functionality (via
|
||||
// QueryInterface) for one or two components.
|
||||
//
|
||||
// Please also note:
|
||||
// "if (dxVer != 0x500) return FALSE;" is BAD.
|
||||
// "if (dxVer < 0x500) return FALSE;" is MUCH BETTER.
|
||||
// to ensure your app will run on future releases of DirectX.
|
||||
//-----------------------------------------------------------------------------
|
||||
VOID GetDXVersion( DWORD* pdwDXVersion, DWORD* pdwDXPlatform )
|
||||
{
|
||||
HRESULT hr;
|
||||
HINSTANCE DDHinst = 0;
|
||||
HINSTANCE DIHinst = 0;
|
||||
LPDIRECTDRAW pDDraw = 0;
|
||||
LPDIRECTDRAW2 pDDraw2 = 0;
|
||||
DIRECTDRAWCREATE DirectDrawCreate = 0;
|
||||
DIRECTDRAWCREATEEX DirectDrawCreateEx = 0;
|
||||
DIRECTINPUTCREATE DirectInputCreate = 0;
|
||||
OSVERSIONINFO osVer;
|
||||
LPDIRECTDRAWSURFACE pSurf = 0;
|
||||
LPDIRECTDRAWSURFACE3 pSurf3 = 0;
|
||||
LPDIRECTDRAWSURFACE4 pSurf4 = 0;
|
||||
|
||||
// First get the windows platform
|
||||
osVer.dwOSVersionInfoSize = sizeof(osVer);
|
||||
if( !GetVersionEx( &osVer ) )
|
||||
{
|
||||
(*pdwDXPlatform) = 0;
|
||||
(*pdwDXVersion) = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if( osVer.dwPlatformId == VER_PLATFORM_WIN32_NT )
|
||||
{
|
||||
(*pdwDXPlatform) = VER_PLATFORM_WIN32_NT;
|
||||
|
||||
// NT is easy... NT 4.0 is DX2, 4.0 SP3 is DX3, 5.0 is DX5
|
||||
// and no DX on earlier versions.
|
||||
if( osVer.dwMajorVersion < 4 )
|
||||
{
|
||||
(*pdwDXVersion) = 0; // No DX on NT3.51 or earlier
|
||||
return;
|
||||
}
|
||||
|
||||
if( osVer.dwMajorVersion == 4 )
|
||||
{
|
||||
// NT4 up to SP2 is DX2, and SP3 onwards is DX3, so we are at least DX2
|
||||
(*pdwDXVersion) = 0x200;
|
||||
|
||||
// We're not supposed to be able to tell which SP we're on, so check for dinput
|
||||
DIHinst = LoadLibrary( "DINPUT.DLL" );
|
||||
if( DIHinst == 0 )
|
||||
{
|
||||
// No DInput... must be DX2 on NT 4 pre-SP3
|
||||
OutputDebugString( "Couldn't LoadLibrary DInput\r\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( DIHinst,
|
||||
"DirectInputCreateA" );
|
||||
FreeLibrary( DIHinst );
|
||||
|
||||
if( DirectInputCreate == 0 )
|
||||
{
|
||||
// No DInput... must be pre-SP3 DX2
|
||||
OutputDebugString( "Couldn't GetProcAddress DInputCreate\r\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
// It must be NT4, DX2
|
||||
(*pdwDXVersion) = 0x300; // DX3 on NT4 SP3 or higher
|
||||
return;
|
||||
}
|
||||
// Else it's NT5 or higher, and it's DX5a or higher: Drop through to
|
||||
// Win9x tests for a test of DDraw (DX6 or higher)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not NT... must be Win9x
|
||||
(*pdwDXPlatform) = VER_PLATFORM_WIN32_WINDOWS;
|
||||
}
|
||||
|
||||
// Now we know we are in Windows 9x (or maybe 3.1), so anything's possible.
|
||||
// First see if DDRAW.DLL even exists.
|
||||
DDHinst = LoadLibrary( "DDRAW.DLL" );
|
||||
if( DDHinst == 0 )
|
||||
{
|
||||
(*pdwDXVersion) = 0;
|
||||
(*pdwDXPlatform) = 0;
|
||||
FreeLibrary( DDHinst );
|
||||
return;
|
||||
}
|
||||
|
||||
// See if we can create the DirectDraw object.
|
||||
DirectDrawCreate = (DIRECTDRAWCREATE)GetProcAddress( DDHinst, "DirectDrawCreate" );
|
||||
if( DirectDrawCreate == 0 )
|
||||
{
|
||||
(*pdwDXVersion) = 0;
|
||||
(*pdwDXPlatform) = 0;
|
||||
FreeLibrary( DDHinst );
|
||||
OutputDebugString( "Couldn't LoadLibrary DDraw\r\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
hr = DirectDrawCreate( NULL, &pDDraw, NULL );
|
||||
if( FAILED(hr) )
|
||||
{
|
||||
(*pdwDXVersion) = 0;
|
||||
(*pdwDXPlatform) = 0;
|
||||
FreeLibrary( DDHinst );
|
||||
OutputDebugString( "Couldn't create DDraw\r\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
// So DirectDraw exists. We are at least DX1.
|
||||
(*pdwDXVersion) = 0x100;
|
||||
|
||||
// Let's see if IID_IDirectDraw2 exists.
|
||||
hr = pDDraw->QueryInterface( IID_IDirectDraw2, (VOID**)&pDDraw2 );
|
||||
if( FAILED(hr) )
|
||||
{
|
||||
// No IDirectDraw2 exists... must be DX1
|
||||
pDDraw->Release();
|
||||
FreeLibrary( DDHinst );
|
||||
OutputDebugString( "Couldn't QI DDraw2\r\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
// IDirectDraw2 exists. We must be at least DX2
|
||||
pDDraw2->Release();
|
||||
(*pdwDXVersion) = 0x200;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// DirectX 3.0 Checks
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// DirectInput was added for DX3
|
||||
DIHinst = LoadLibrary( "DINPUT.DLL" );
|
||||
if( DIHinst == 0 )
|
||||
{
|
||||
// No DInput... must not be DX3
|
||||
OutputDebugString( "Couldn't LoadLibrary DInput\r\n" );
|
||||
pDDraw->Release();
|
||||
FreeLibrary( DDHinst );
|
||||
return;
|
||||
}
|
||||
|
||||
DirectInputCreate = (DIRECTINPUTCREATE)GetProcAddress( DIHinst,
|
||||
"DirectInputCreateA" );
|
||||
if( DirectInputCreate == 0 )
|
||||
{
|
||||
// No DInput... must be DX2
|
||||
FreeLibrary( DIHinst );
|
||||
FreeLibrary( DDHinst );
|
||||
pDDraw->Release();
|
||||
OutputDebugString( "Couldn't GetProcAddress DInputCreate\r\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
// DirectInputCreate exists. We are at least DX3
|
||||
(*pdwDXVersion) = 0x300;
|
||||
FreeLibrary( DIHinst );
|
||||
|
||||
// Can do checks for 3a vs 3b here
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// DirectX 5.0 Checks
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// We can tell if DX5 is present by checking for the existence of
|
||||
// IDirectDrawSurface3. First, we need a surface to QI off of.
|
||||
DDSURFACEDESC ddsd;
|
||||
ZeroMemory( &ddsd, sizeof(ddsd) );
|
||||
ddsd.dwSize = sizeof(ddsd);
|
||||
ddsd.dwFlags = DDSD_CAPS;
|
||||
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
|
||||
|
||||
hr = pDDraw->SetCooperativeLevel( NULL, DDSCL_NORMAL );
|
||||
if( FAILED(hr) )
|
||||
{
|
||||
// Failure. This means DDraw isn't properly installed.
|
||||
pDDraw->Release();
|
||||
FreeLibrary( DDHinst );
|
||||
(*pdwDXVersion) = 0;
|
||||
OutputDebugString( "Couldn't Set coop level\r\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
hr = pDDraw->CreateSurface( &ddsd, &pSurf, NULL );
|
||||
if( FAILED(hr) )
|
||||
{
|
||||
// Failure. This means DDraw isn't properly installed.
|
||||
pDDraw->Release();
|
||||
FreeLibrary( DDHinst );
|
||||
*pdwDXVersion = 0;
|
||||
OutputDebugString( "Couldn't CreateSurface\r\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
// Query for the IDirectDrawSurface3 interface
|
||||
if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface3,
|
||||
(VOID**)&pSurf3 ) ) )
|
||||
{
|
||||
pDDraw->Release();
|
||||
FreeLibrary( DDHinst );
|
||||
return;
|
||||
}
|
||||
|
||||
// QI for IDirectDrawSurface3 succeeded. We must be at least DX5
|
||||
(*pdwDXVersion) = 0x500;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// DirectX 6.0 Checks
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// The IDirectDrawSurface4 interface was introduced with DX 6.0
|
||||
if( FAILED( pSurf->QueryInterface( IID_IDirectDrawSurface4,
|
||||
(VOID**)&pSurf4 ) ) )
|
||||
{
|
||||
pDDraw->Release();
|
||||
FreeLibrary( DDHinst );
|
||||
return;
|
||||
}
|
||||
|
||||
// IDirectDrawSurface4 was create successfully. We must be at least DX6
|
||||
(*pdwDXVersion) = 0x600;
|
||||
pSurf->Release();
|
||||
pDDraw->Release();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// DirectX 6.1 Checks
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Check for DMusic, which was introduced with DX6.1
|
||||
LPDIRECTMUSIC pDMusic = NULL;
|
||||
CoInitialize( NULL );
|
||||
hr = CoCreateInstance( CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER,
|
||||
IID_IDirectMusic, (VOID**)&pDMusic );
|
||||
if( FAILED(hr) )
|
||||
{
|
||||
OutputDebugString( "Couldn't create CLSID_DirectMusic\r\n" );
|
||||
FreeLibrary( DDHinst );
|
||||
return;
|
||||
}
|
||||
|
||||
// DirectMusic was created successfully. We must be at least DX6.1
|
||||
(*pdwDXVersion) = 0x601;
|
||||
pDMusic->Release();
|
||||
CoUninitialize();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// DirectX 7.0 Checks
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Check for DirectX 7 by creating a DDraw7 object
|
||||
LPDIRECTDRAW7 pDD7;
|
||||
DirectDrawCreateEx = (DIRECTDRAWCREATEEX)GetProcAddress( DDHinst,
|
||||
"DirectDrawCreateEx" );
|
||||
if( NULL == DirectDrawCreateEx )
|
||||
{
|
||||
FreeLibrary( DDHinst );
|
||||
return;
|
||||
}
|
||||
|
||||
if( FAILED( DirectDrawCreateEx( NULL, (VOID**)&pDD7, IID_IDirectDraw7,
|
||||
NULL ) ) )
|
||||
{
|
||||
FreeLibrary( DDHinst );
|
||||
return;
|
||||
}
|
||||
|
||||
// DDraw7 was created successfully. We must be at least DX7.0
|
||||
(*pdwDXVersion) = 0x700;
|
||||
pDD7->Release();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// End of checks
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Close open libraries and return
|
||||
FreeLibrary( DDHinst );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int getDXVersion(){
|
||||
DWORD version,platform;
|
||||
|
||||
GetDXVersion( &version,&platform );
|
||||
|
||||
return (version>>8)&0xff;
|
||||
}
|
||||
|
7
bblaunch/checkdx.h
Normal file
7
bblaunch/checkdx.h
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
#ifndef CHECKDX_H
|
||||
#define CHECKDX_H
|
||||
|
||||
int getDXVersion();
|
||||
|
||||
#endif
|
24
bblaunch/checkie.cpp
Normal file
24
bblaunch/checkie.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
#include "checkie.h"
|
||||
#include <windows.h>
|
||||
|
||||
int getIEVersion(){
|
||||
int version=0;
|
||||
|
||||
HKEY key=HKEY_LOCAL_MACHINE;
|
||||
if( RegOpenKey( key,"Software\\Microsoft\\Internet Explorer",&key )==ERROR_SUCCESS ){
|
||||
char buff[MAX_PATH];DWORD type,sz=MAX_PATH;
|
||||
if( RegQueryValueEx( key,"Version",0,&type,(PBYTE)buff,&sz )==ERROR_SUCCESS ){
|
||||
version=4;
|
||||
/*
|
||||
char temp[4];
|
||||
if( isdigit(buff[0]) && buff[1]=='.' && isdigit(buff[2]) && isdigit(buff[3]) && buff[4]=='.' ){
|
||||
temp[0]=buff[0];temp[1]=buff[2];temp[2]=buff[3];temp[3]=0;
|
||||
if( atoi(temp)>=471 ) version=4;
|
||||
}
|
||||
*/
|
||||
}
|
||||
RegCloseKey( key );
|
||||
}
|
||||
return version;
|
||||
}
|
7
bblaunch/checkie.h
Normal file
7
bblaunch/checkie.h
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
#ifndef CHECKIE_H
|
||||
#define CHECKIE_H
|
||||
|
||||
int getIEVersion();
|
||||
|
||||
#endif
|
47
bblaunch/demo.html
Normal file
47
bblaunch/demo.html
Normal file
@ -0,0 +1,47 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Blitz Basic demo</TITLE>
|
||||
</HEAD>
|
||||
<BODY bgcolor=#f0f0f0>
|
||||
|
||||
<FONT face=tahoma size=2 color=#0040ff>
|
||||
|
||||
<FONT color=#ff2020>
|
||||
<H3 align=center><B>Blitz Basic Demo</B></H3>
|
||||
</FONT><BR>
|
||||
|
||||
<DIV>
|
||||
Hi! Welcome to the Blitz Basic demo.
|
||||
</DIV><BR>
|
||||
|
||||
<DIV>
|
||||
With the Blitz Basic programming language, you can design awesome 2D games for the PC
|
||||
with the minimum of effort.
|
||||
</DIV><BR>
|
||||
|
||||
<DIV>
|
||||
This demo will give you some idea of the power and flexibility of the Blitz Basic
|
||||
programming language.
|
||||
</DIV><BR>
|
||||
|
||||
<DIV>Click here to see some examples of Blitz in action.</DIV><BR>
|
||||
|
||||
<DIV>Click here to see a summary of Blitz Basic commands.</DIV><BR>
|
||||
|
||||
<DIV>Have fun!</DIV><BR>
|
||||
|
||||
<FONT size=1 color=#000000>
|
||||
|
||||
<DIV>Blitz Basic is published by Guildhall Leisure Services.</DIV><BR>
|
||||
|
||||
<DIV>For purchasing information, please contact
|
||||
<A HREF=mailto:george@guildhallleisure.com>George Bray</A>.</DIV><BR>
|
||||
|
||||
<DIV>More information about Blitz is available at <A HREF=http://www.blitzbasic.com>
|
||||
The Blitz Basic homepage</A></DIV><BR>
|
||||
|
||||
</FONT>
|
||||
|
||||
</FONT>
|
||||
</BODY>
|
||||
</HTML>
|
16
bblaunch/resource.h
Normal file
16
bblaunch/resource.h
Normal file
@ -0,0 +1,16 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by bblaunch.rc
|
||||
//
|
||||
#define IDI_ICON1 104
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 105
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
594
bbruntime/basic.cpp
Normal file
594
bbruntime/basic.cpp
Normal file
@ -0,0 +1,594 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
|
||||
//how many strings allocated
|
||||
static int stringCnt;
|
||||
|
||||
//how many objects new'd but not deleted
|
||||
static int objCnt;
|
||||
|
||||
//how many objects deleted but not released
|
||||
static int unrelObjCnt;
|
||||
|
||||
//how many objects to alloc per block
|
||||
static const int OBJ_NEW_INC=512;
|
||||
|
||||
//how many strings to alloc per block
|
||||
static const int STR_NEW_INC=512;
|
||||
|
||||
//current data ptr
|
||||
static BBData *dataPtr;
|
||||
|
||||
//chunks of mem - WHAT THE FUCK WAS I ON?!?!?!?
|
||||
//static list<char*> memBlks;
|
||||
|
||||
//strings
|
||||
static BBStr usedStrs,freeStrs;
|
||||
|
||||
//object handle number
|
||||
static int next_handle;
|
||||
|
||||
//object<->handle maps
|
||||
static map<int,BBObj*> handle_map;
|
||||
static map<BBObj*,int> object_map;
|
||||
|
||||
static BBType _bbIntType( BBTYPE_INT );
|
||||
static BBType _bbFltType( BBTYPE_FLT );
|
||||
static BBType _bbStrType( BBTYPE_STR );
|
||||
static BBType _bbCStrType( BBTYPE_CSTR );
|
||||
|
||||
static void *bbMalloc( int size ){
|
||||
return malloc(size);
|
||||
/*
|
||||
char *c=d_new char[ size ];
|
||||
memBlks.push_back( c );
|
||||
return c;
|
||||
*/
|
||||
}
|
||||
|
||||
static void bbFree( void *q ){
|
||||
free(q);
|
||||
/*
|
||||
if( !q ) return;
|
||||
char *c=(char*)q;
|
||||
memBlks.remove( c );
|
||||
delete [] c;
|
||||
*/
|
||||
}
|
||||
|
||||
static void removeStr( BBStr *str ){
|
||||
str->next->prev=str->prev;
|
||||
str->prev->next=str->next;
|
||||
}
|
||||
|
||||
static void insertStr( BBStr *str,BBStr *next ){
|
||||
str->next=next;
|
||||
str->prev=next->prev;
|
||||
str->prev->next=str;
|
||||
next->prev=str;
|
||||
}
|
||||
|
||||
void *BBStr::operator new( size_t size ){
|
||||
if( freeStrs.next==&freeStrs ){
|
||||
BBStr *t=(BBStr*)bbMalloc( sizeof(BBStr)*STR_NEW_INC );
|
||||
for( int k=0;k<STR_NEW_INC;++k ) insertStr( t++,&freeStrs );
|
||||
}
|
||||
BBStr *t=freeStrs.next;
|
||||
removeStr( t );insertStr( t,&usedStrs );
|
||||
return t;
|
||||
}
|
||||
|
||||
void BBStr::operator delete( void *q ){
|
||||
if( !q ) return;
|
||||
BBStr *t=(BBStr*)q;
|
||||
removeStr( t );insertStr( t,&freeStrs );
|
||||
}
|
||||
|
||||
BBStr::BBStr(){
|
||||
++stringCnt;
|
||||
}
|
||||
|
||||
BBStr::BBStr( const char *s ):string(s){
|
||||
++stringCnt;
|
||||
}
|
||||
|
||||
BBStr::BBStr( const char *s,int n ):string(s,n){
|
||||
++stringCnt;
|
||||
}
|
||||
|
||||
BBStr::BBStr( const BBStr &s ):string(s){
|
||||
++stringCnt;
|
||||
}
|
||||
|
||||
BBStr::BBStr( const string &s ):string(s){
|
||||
++stringCnt;
|
||||
}
|
||||
|
||||
BBStr &BBStr::operator=( const char *s ){
|
||||
string::operator=( s );return *this;
|
||||
}
|
||||
|
||||
BBStr &BBStr::operator=( const BBStr &s ){
|
||||
string::operator=( s );return *this;
|
||||
}
|
||||
|
||||
BBStr &BBStr::operator=( const string &s ){
|
||||
string::operator=( s );return *this;
|
||||
}
|
||||
|
||||
BBStr::~BBStr(){
|
||||
--stringCnt;
|
||||
}
|
||||
|
||||
BBStr *_bbStrLoad( BBStr **var ){
|
||||
return *var ? d_new BBStr( **var ) : d_new BBStr();
|
||||
}
|
||||
|
||||
void _bbStrRelease( BBStr *str ){
|
||||
delete str;
|
||||
}
|
||||
|
||||
void _bbStrStore( BBStr **var,BBStr *str ){
|
||||
_bbStrRelease( *var );*var=str;
|
||||
}
|
||||
|
||||
BBStr *_bbStrConcat( BBStr *s1,BBStr *s2 ){
|
||||
*s1+=*s2;delete s2;return s1;
|
||||
}
|
||||
|
||||
int _bbStrCompare( BBStr *lhs,BBStr *rhs ){
|
||||
int n=lhs->compare( *rhs );
|
||||
delete lhs;delete rhs;return n;
|
||||
}
|
||||
|
||||
int _bbStrToInt( BBStr *s ){
|
||||
int n=atoi( *s );
|
||||
delete s;return n;
|
||||
}
|
||||
|
||||
BBStr *_bbStrFromInt( int n ){
|
||||
return d_new BBStr( itoa( n ) );
|
||||
}
|
||||
|
||||
float _bbStrToFloat( BBStr *s ){
|
||||
float n=(float)atof( *s );
|
||||
delete s;return n;
|
||||
}
|
||||
|
||||
BBStr *_bbStrFromFloat( float n ){
|
||||
return d_new BBStr( ftoa( n ) );
|
||||
}
|
||||
|
||||
BBStr *_bbStrConst( const char *s ){
|
||||
return d_new BBStr( s );
|
||||
}
|
||||
|
||||
void * _bbVecAlloc( BBVecType *type ){
|
||||
void *vec=bbMalloc( type->size*4 );
|
||||
memset( vec,0,type->size*4 );
|
||||
return vec;
|
||||
}
|
||||
|
||||
void _bbVecFree( void *vec,BBVecType *type ){
|
||||
if( type->elementType->type==BBTYPE_STR ){
|
||||
BBStr **p=(BBStr**)vec;
|
||||
for( int k=0;k<type->size;++p,++k ){
|
||||
if( *p ) _bbStrRelease( *p );
|
||||
}
|
||||
}else if( type->elementType->type==BBTYPE_OBJ ){
|
||||
BBObj **p=(BBObj**)vec;
|
||||
for( int k=0;k<type->size;++p,++k ){
|
||||
if( *p ) _bbObjRelease( *p );
|
||||
}
|
||||
}
|
||||
bbFree( vec );
|
||||
}
|
||||
|
||||
void _bbVecBoundsEx(){
|
||||
RTEX( "Blitz array index out of bounds" );
|
||||
}
|
||||
|
||||
void _bbUndimArray( BBArray *array ){
|
||||
if( void *t=array->data ){
|
||||
if( array->elementType==BBTYPE_STR ){
|
||||
BBStr **p=(BBStr**)t;
|
||||
int size=array->scales[array->dims-1];
|
||||
for( int k=0;k<size;++p,++k ){
|
||||
if( *p ) _bbStrRelease( *p );
|
||||
}
|
||||
}else if( array->elementType==BBTYPE_OBJ ){
|
||||
BBObj **p=(BBObj**)t;
|
||||
int size=array->scales[array->dims-1];
|
||||
for( int k=0;k<size;++p,++k ){
|
||||
if( *p ) _bbObjRelease( *p );
|
||||
}
|
||||
}
|
||||
bbFree( t );
|
||||
array->data=0;
|
||||
}
|
||||
}
|
||||
|
||||
void _bbDimArray( BBArray *array ){
|
||||
int k;
|
||||
for( k=0;k<array->dims;++k ) ++array->scales[k];
|
||||
for( k=1;k<array->dims;++k ){
|
||||
array->scales[k]*=array->scales[k-1];
|
||||
}
|
||||
int size=array->scales[array->dims-1];
|
||||
array->data=bbMalloc( size*4 );
|
||||
memset( array->data,0,size*4 );
|
||||
}
|
||||
|
||||
void _bbArrayBoundsEx(){
|
||||
RTEX( "Array index out of bounds" );
|
||||
}
|
||||
|
||||
static void unlinkObj( BBObj *obj ){
|
||||
obj->next->prev=obj->prev;
|
||||
obj->prev->next=obj->next;
|
||||
}
|
||||
|
||||
static void insertObj( BBObj *obj,BBObj *next ){
|
||||
obj->next=next;
|
||||
obj->prev=next->prev;
|
||||
next->prev->next=obj;
|
||||
next->prev=obj;
|
||||
}
|
||||
|
||||
BBObj *_bbObjNew( BBObjType *type ){
|
||||
if( type->free.next==&type->free ){
|
||||
int obj_size=sizeof(BBObj)+type->fieldCnt*4;
|
||||
BBObj *o=(BBObj*)bbMalloc( obj_size*OBJ_NEW_INC );
|
||||
for( int k=0;k<OBJ_NEW_INC;++k ){
|
||||
insertObj( o,&type->free );
|
||||
o=(BBObj*)( (char*)o+obj_size );
|
||||
}
|
||||
}
|
||||
BBObj *o=type->free.next;
|
||||
unlinkObj( o );
|
||||
o->type=type;
|
||||
o->ref_cnt=1;
|
||||
o->fields=(BBField*)(o+1);
|
||||
for( int k=0;k<type->fieldCnt;++k ){
|
||||
switch( type->fieldTypes[k]->type ){
|
||||
case BBTYPE_VEC:
|
||||
o->fields[k].VEC=_bbVecAlloc( (BBVecType*)type->fieldTypes[k] );
|
||||
break;
|
||||
default:
|
||||
o->fields[k].INT=0;
|
||||
}
|
||||
}
|
||||
insertObj( o,&type->used );
|
||||
++unrelObjCnt;
|
||||
++objCnt;
|
||||
return o;
|
||||
}
|
||||
|
||||
void _bbObjDelete( BBObj *obj ){
|
||||
if( !obj ) return;
|
||||
BBField *fields=obj->fields;
|
||||
if( !fields ) return;
|
||||
BBObjType *type=obj->type;
|
||||
for( int k=0;k<type->fieldCnt;++k ){
|
||||
switch( type->fieldTypes[k]->type ){
|
||||
case BBTYPE_STR:
|
||||
_bbStrRelease( fields[k].STR );
|
||||
break;
|
||||
case BBTYPE_OBJ:
|
||||
_bbObjRelease( fields[k].OBJ );
|
||||
break;
|
||||
case BBTYPE_VEC:
|
||||
_bbVecFree( fields[k].VEC,(BBVecType*)type->fieldTypes[k] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
map<BBObj*,int>::iterator it=object_map.find( obj );
|
||||
if( it!=object_map.end() ){
|
||||
handle_map.erase( it->second );
|
||||
object_map.erase( it );
|
||||
}
|
||||
obj->fields=0;
|
||||
_bbObjRelease( obj );
|
||||
--objCnt;
|
||||
}
|
||||
|
||||
void _bbObjDeleteEach( BBObjType *type ){
|
||||
BBObj *obj=type->used.next;
|
||||
while( obj->type ){
|
||||
BBObj *next=obj->next;
|
||||
if( obj->fields ) _bbObjDelete( obj );
|
||||
obj=next;
|
||||
}
|
||||
}
|
||||
|
||||
extern void bbDebugLog( BBStr *t );
|
||||
extern void bbStop( );
|
||||
|
||||
void _bbObjRelease( BBObj *obj ){
|
||||
if( !obj || --obj->ref_cnt ) return;
|
||||
unlinkObj( obj );
|
||||
insertObj( obj,&obj->type->free );
|
||||
--unrelObjCnt;
|
||||
}
|
||||
|
||||
void _bbObjStore( BBObj **var,BBObj *obj ){
|
||||
if( obj ) ++obj->ref_cnt; //do this first incase of self-assignment
|
||||
_bbObjRelease( *var );
|
||||
*var=obj;
|
||||
}
|
||||
|
||||
int _bbObjCompare( BBObj *o1,BBObj *o2 ){
|
||||
return (o1 ? o1->fields : 0)!=(o2 ? o2->fields : 0);
|
||||
}
|
||||
|
||||
BBObj *_bbObjNext( BBObj *obj ){
|
||||
do{
|
||||
obj=obj->next;
|
||||
if( !obj->type ) return 0;
|
||||
}while( !obj->fields );
|
||||
return obj;
|
||||
}
|
||||
|
||||
BBObj *_bbObjPrev( BBObj *obj ){
|
||||
do{
|
||||
obj=obj->prev;
|
||||
if( !obj->type ) return 0;
|
||||
}while( !obj->fields );
|
||||
return obj;
|
||||
}
|
||||
|
||||
BBObj *_bbObjFirst( BBObjType *type ){
|
||||
return _bbObjNext( &type->used );
|
||||
}
|
||||
|
||||
BBObj *_bbObjLast( BBObjType *type ){
|
||||
return _bbObjPrev( &type->used );
|
||||
}
|
||||
|
||||
void _bbObjInsBefore( BBObj *o1,BBObj *o2 ){
|
||||
if( o1==o2 ) return;
|
||||
unlinkObj( o1 );
|
||||
insertObj( o1,o2 );
|
||||
}
|
||||
|
||||
void _bbObjInsAfter( BBObj *o1,BBObj *o2 ){
|
||||
if( o1==o2 ) return;
|
||||
unlinkObj( o1 );
|
||||
insertObj( o1,o2->next );
|
||||
}
|
||||
|
||||
int _bbObjEachFirst( BBObj **var,BBObjType *type ){
|
||||
_bbObjStore( var,_bbObjFirst( type ) );
|
||||
return *var!=0;
|
||||
}
|
||||
|
||||
int _bbObjEachNext( BBObj **var ){
|
||||
_bbObjStore( var,_bbObjNext( *var ) );
|
||||
return *var!=0;
|
||||
}
|
||||
|
||||
int _bbObjEachFirst2( BBObj **var,BBObjType *type ){
|
||||
*var=_bbObjFirst( type );
|
||||
return *var!=0;
|
||||
}
|
||||
|
||||
int _bbObjEachNext2( BBObj **var ){
|
||||
*var=_bbObjNext( *var );
|
||||
return *var!=0;
|
||||
}
|
||||
|
||||
BBStr *_bbObjToStr( BBObj *obj ){
|
||||
if( !obj || !obj->fields ) return d_new BBStr( "[NULL]" );
|
||||
|
||||
static BBObj *root;
|
||||
static int recurs_cnt;
|
||||
|
||||
if( obj==root ) return d_new BBStr( "[ROOT]" );
|
||||
if( recurs_cnt==8 ) return d_new BBStr( "...." );
|
||||
|
||||
++recurs_cnt;
|
||||
BBObj *oldRoot=root;
|
||||
if( !root ) root=obj;
|
||||
|
||||
BBObjType *type=obj->type;
|
||||
BBField *fields=obj->fields;
|
||||
BBStr *s=d_new BBStr("["),*t;
|
||||
for( int k=0;k<type->fieldCnt;++k ){
|
||||
if( k ) *s+=',';
|
||||
switch( type->fieldTypes[k]->type ){
|
||||
case BBTYPE_INT:
|
||||
t=_bbStrFromInt( fields[k].INT );*s+=*t;delete t;
|
||||
break;
|
||||
case BBTYPE_FLT:
|
||||
t=_bbStrFromFloat( fields[k].FLT );*s+=*t;delete t;
|
||||
break;
|
||||
case BBTYPE_STR:
|
||||
if( fields[k].STR ) *s+='\"'+*fields[k].STR+'\"';
|
||||
else *s+="\"\"";
|
||||
break;
|
||||
case BBTYPE_OBJ:
|
||||
t=_bbObjToStr( fields[k].OBJ );*s+=*t;delete t;
|
||||
break;
|
||||
default:
|
||||
*s+="???";
|
||||
}
|
||||
}
|
||||
*s+=']';
|
||||
root=oldRoot;
|
||||
--recurs_cnt;
|
||||
return s;
|
||||
}
|
||||
|
||||
int _bbObjToHandle( BBObj *obj ){
|
||||
if( !obj || !obj->fields ) return 0;
|
||||
map<BBObj*,int>::const_iterator it=object_map.find( obj );
|
||||
if( it!=object_map.end() ) return it->second;
|
||||
++next_handle;
|
||||
object_map[obj]=next_handle;
|
||||
handle_map[next_handle]=obj;
|
||||
return next_handle;
|
||||
}
|
||||
|
||||
BBObj *_bbObjFromHandle( int handle,BBObjType *type ){
|
||||
map<int,BBObj*>::const_iterator it=handle_map.find( handle );
|
||||
if( it==handle_map.end() ) return 0;
|
||||
BBObj *obj=it->second;
|
||||
return obj->type==type ? obj : 0;
|
||||
}
|
||||
|
||||
void _bbNullObjEx(){
|
||||
RTEX( "Object does not exist" );
|
||||
}
|
||||
|
||||
void _bbRestore( BBData *data ){
|
||||
dataPtr=data;
|
||||
}
|
||||
|
||||
int _bbReadInt(){
|
||||
switch( dataPtr->fieldType ){
|
||||
case BBTYPE_END:RTEX( "Out of data" );return 0;
|
||||
case BBTYPE_INT:return dataPtr++->field.INT;
|
||||
case BBTYPE_FLT:return dataPtr++->field.FLT;
|
||||
case BBTYPE_CSTR:return atoi( dataPtr++->field.CSTR );
|
||||
default:RTEX( "Bad data type" );return 0;
|
||||
}
|
||||
}
|
||||
|
||||
float _bbReadFloat(){
|
||||
switch( dataPtr->fieldType ){
|
||||
case BBTYPE_END:RTEX( "Out of data" );return 0;
|
||||
case BBTYPE_INT:return dataPtr++->field.INT;
|
||||
case BBTYPE_FLT:return dataPtr++->field.FLT;
|
||||
case BBTYPE_CSTR:return atof( dataPtr++->field.CSTR );
|
||||
default:RTEX( "Bad data type" );return 0;
|
||||
}
|
||||
}
|
||||
|
||||
BBStr *_bbReadStr(){
|
||||
switch( dataPtr->fieldType ){
|
||||
case BBTYPE_END:RTEX( "Out of data" );return 0;
|
||||
case BBTYPE_INT:return d_new BBStr( itoa( dataPtr++->field.INT ) );
|
||||
case BBTYPE_FLT:return d_new BBStr( ftoa( dataPtr++->field.FLT ) );
|
||||
case BBTYPE_CSTR:return d_new BBStr( dataPtr++->field.CSTR );
|
||||
default:RTEX( "Bad data type" );return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _bbAbs( int n ){
|
||||
return n>=0 ? n : -n;
|
||||
}
|
||||
|
||||
int _bbSgn( int n ){
|
||||
return n>0 ? 1 : (n<0 ? -1 : 0);
|
||||
}
|
||||
|
||||
int _bbMod( int x,int y ){
|
||||
return x%y;
|
||||
}
|
||||
|
||||
float _bbFAbs( float n ){
|
||||
return n>=0 ? n : -n;
|
||||
}
|
||||
|
||||
float _bbFSgn( float n ){
|
||||
return n>0 ? 1 : (n<0 ? -1 : 0);
|
||||
}
|
||||
|
||||
float _bbFMod( float x,float y ){
|
||||
return (float)fmod( x,y );
|
||||
}
|
||||
|
||||
float _bbFPow( float x,float y ){
|
||||
return (float)pow( x,y );
|
||||
}
|
||||
|
||||
void bbRuntimeStats(){
|
||||
gx_runtime->debugLog( ("Active strings :"+itoa(stringCnt)).c_str() );
|
||||
gx_runtime->debugLog( ("Active objects :"+itoa(objCnt)).c_str() );
|
||||
gx_runtime->debugLog( ("Unreleased objs:"+itoa(unrelObjCnt)).c_str() );
|
||||
/*
|
||||
clog<<"Active strings:"<<stringCnt<<endl;
|
||||
clog<<"Active objects:"<<objCnt<<endl;
|
||||
clog<<"Unreleased Objects:"<<unrelObjCnt<<endl;
|
||||
for( BBStr *t=usedStrs.next;t!=&usedStrs;t=t->next ){
|
||||
clog<<"string@"<<(void*)t<<endl;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
bool basic_create(){
|
||||
next_handle=0;
|
||||
// memBlks.clear();
|
||||
handle_map.clear();
|
||||
object_map.clear();
|
||||
stringCnt=objCnt=unrelObjCnt=0;
|
||||
usedStrs.next=usedStrs.prev=&usedStrs;
|
||||
freeStrs.next=freeStrs.prev=&freeStrs;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool basic_destroy(){
|
||||
while( usedStrs.next!=&usedStrs ) delete usedStrs.next;
|
||||
// while( memBlks.size() ) bbFree( memBlks.back() );
|
||||
handle_map.clear();
|
||||
object_map.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
void basic_link( void (*rtSym)( const char *sym,void *pc ) ){
|
||||
|
||||
rtSym( "_bbIntType",&_bbIntType );
|
||||
rtSym( "_bbFltType",&_bbFltType );
|
||||
rtSym( "_bbStrType",&_bbStrType );
|
||||
rtSym( "_bbCStrType",&_bbCStrType );
|
||||
|
||||
rtSym( "_bbStrLoad",_bbStrLoad );
|
||||
rtSym( "_bbStrRelease",_bbStrRelease );
|
||||
rtSym( "_bbStrStore",_bbStrStore );
|
||||
rtSym( "_bbStrCompare",_bbStrCompare );
|
||||
rtSym( "_bbStrConcat",_bbStrConcat );
|
||||
rtSym( "_bbStrToInt",_bbStrToInt );
|
||||
rtSym( "_bbStrFromInt",_bbStrFromInt );
|
||||
rtSym( "_bbStrToFloat",_bbStrToFloat );
|
||||
rtSym( "_bbStrFromFloat",_bbStrFromFloat );
|
||||
rtSym( "_bbStrConst",_bbStrConst );
|
||||
rtSym( "_bbDimArray",_bbDimArray );
|
||||
rtSym( "_bbUndimArray",_bbUndimArray );
|
||||
rtSym( "_bbArrayBoundsEx",_bbArrayBoundsEx );
|
||||
rtSym( "_bbVecAlloc",_bbVecAlloc );
|
||||
rtSym( "_bbVecFree",_bbVecFree );
|
||||
rtSym( "_bbVecBoundsEx",_bbVecBoundsEx );
|
||||
rtSym( "_bbObjNew",_bbObjNew );
|
||||
rtSym( "_bbObjDelete",_bbObjDelete );
|
||||
rtSym( "_bbObjDeleteEach",_bbObjDeleteEach );
|
||||
rtSym( "_bbObjRelease",_bbObjRelease );
|
||||
rtSym( "_bbObjStore",_bbObjStore );
|
||||
rtSym( "_bbObjCompare",_bbObjCompare );
|
||||
rtSym( "_bbObjNext",_bbObjNext );
|
||||
rtSym( "_bbObjPrev",_bbObjPrev );
|
||||
rtSym( "_bbObjFirst",_bbObjFirst );
|
||||
rtSym( "_bbObjLast",_bbObjLast );
|
||||
rtSym( "_bbObjInsBefore",_bbObjInsBefore );
|
||||
rtSym( "_bbObjInsAfter",_bbObjInsAfter );
|
||||
rtSym( "_bbObjEachFirst",_bbObjEachFirst );
|
||||
rtSym( "_bbObjEachNext",_bbObjEachNext );
|
||||
rtSym( "_bbObjEachFirst2",_bbObjEachFirst2 );
|
||||
rtSym( "_bbObjEachNext2",_bbObjEachNext2 );
|
||||
rtSym( "_bbObjToStr",_bbObjToStr );
|
||||
rtSym( "_bbObjToHandle",_bbObjToHandle );
|
||||
rtSym( "_bbObjFromHandle",_bbObjFromHandle );
|
||||
rtSym( "_bbNullObjEx",_bbNullObjEx );
|
||||
rtSym( "_bbRestore",_bbRestore );
|
||||
rtSym( "_bbReadInt",_bbReadInt );
|
||||
rtSym( "_bbReadFloat",_bbReadFloat );
|
||||
rtSym( "_bbReadStr",_bbReadStr );
|
||||
rtSym( "_bbAbs",_bbAbs );
|
||||
rtSym( "_bbSgn",_bbSgn );
|
||||
rtSym( "_bbMod",_bbMod );
|
||||
rtSym( "_bbFAbs",_bbFAbs );
|
||||
rtSym( "_bbFSgn",_bbFSgn );
|
||||
rtSym( "_bbFMod",_bbFMod );
|
||||
rtSym( "_bbFPow",_bbFPow );
|
||||
rtSym( "RuntimeStats",bbRuntimeStats );
|
||||
}
|
149
bbruntime/basic.h
Normal file
149
bbruntime/basic.h
Normal file
@ -0,0 +1,149 @@
|
||||
|
||||
#ifndef BASIC_H
|
||||
#define BASIC_H
|
||||
|
||||
#include <string>
|
||||
|
||||
enum{
|
||||
BBTYPE_END=0,
|
||||
BBTYPE_INT=1,BBTYPE_FLT=2,
|
||||
BBTYPE_STR=3,BBTYPE_CSTR=4,
|
||||
BBTYPE_OBJ=5,BBTYPE_VEC=6
|
||||
};
|
||||
|
||||
#pragma pack( push,1 )
|
||||
|
||||
struct BBObj;
|
||||
struct BBStr;
|
||||
struct BBType;
|
||||
struct BBObjType;
|
||||
struct BBVecType;
|
||||
union BBField;
|
||||
struct BBArray;
|
||||
|
||||
struct BBObj{
|
||||
BBField *fields;
|
||||
BBObj *next,*prev;
|
||||
BBObjType *type;
|
||||
int ref_cnt;
|
||||
};
|
||||
|
||||
struct BBType{
|
||||
int type;
|
||||
BBType( int n ):type(n){}
|
||||
};
|
||||
|
||||
struct BBObjType : public BBType{
|
||||
BBObj used,free;
|
||||
int fieldCnt;
|
||||
BBType *fieldTypes[1];
|
||||
};
|
||||
|
||||
struct BBVecType : public BBType{
|
||||
int size;
|
||||
BBType *elementType;
|
||||
};
|
||||
|
||||
union BBField{
|
||||
int INT;
|
||||
float FLT;
|
||||
BBStr *STR;
|
||||
char *CSTR;
|
||||
BBObj *OBJ;
|
||||
void *VEC;
|
||||
};
|
||||
|
||||
struct BBArray{
|
||||
void *data;
|
||||
int elementType,dims,scales[1];
|
||||
};
|
||||
|
||||
struct BBStr : public std::string{
|
||||
BBStr *next,*prev;
|
||||
|
||||
BBStr();
|
||||
BBStr( const char *s );
|
||||
BBStr( const char *s,int n );
|
||||
BBStr( const BBStr &s );
|
||||
BBStr( const std::string &s );
|
||||
BBStr &operator=( const char *s );
|
||||
BBStr &operator=( const BBStr &s );
|
||||
BBStr &operator=( const std::string &s );
|
||||
~BBStr();
|
||||
|
||||
void *operator new( size_t size );
|
||||
void operator delete( void *q );
|
||||
|
||||
void *operator new( size_t size,const char *file,int line ){ return operator new( size ); }
|
||||
void operator delete( void *q,const char *file,int line ){ operator delete( q ); }
|
||||
};
|
||||
|
||||
struct BBData{
|
||||
int fieldType;
|
||||
BBField field;
|
||||
};
|
||||
|
||||
#pragma pack( pop )
|
||||
|
||||
void basic_link();
|
||||
|
||||
extern BBType _bbIntType;
|
||||
extern BBType _bbFltType;
|
||||
extern BBType _bbStrType;
|
||||
extern BBType _bbCStrType;
|
||||
|
||||
BBStr * _bbStrLoad( BBStr **var );
|
||||
void _bbStrRelease( BBStr *str );
|
||||
void _bbStrStore( BBStr **var,BBStr *str );
|
||||
int _bbStrCompare( BBStr *lhs,BBStr *rhs );
|
||||
|
||||
BBStr * _bbStrConcat( BBStr *s1,BBStr *s2 );
|
||||
int _bbStrToInt( BBStr *s );
|
||||
BBStr * _bbStrFromInt( int n );
|
||||
float _bbStrToFloat( BBStr *s );
|
||||
BBStr * _bbStrFromFloat( float n );
|
||||
BBStr * _bbStrConst( const char *s );
|
||||
|
||||
void _bbDimArray( BBArray *array );
|
||||
void _bbUndimArray( BBArray *array );
|
||||
void _bbArrayBoundsEx();
|
||||
|
||||
void * _bbVecAlloc( BBVecType *type );
|
||||
void _bbVecFree( void *vec,BBVecType *type );
|
||||
void _bbVecBoundsEx();
|
||||
|
||||
BBObj * _bbObjNew( BBObjType *t );
|
||||
void _bbObjDelete( BBObj *obj );
|
||||
void _bbObjDeleteEach( BBObjType *type );
|
||||
void _bbObjRelease( BBObj *obj );
|
||||
void _bbObjStore( BBObj **var,BBObj *obj );
|
||||
BBObj * _bbObjNext( BBObj *obj );
|
||||
BBObj * _bbObjPrev( BBObj *obj );
|
||||
BBObj * _bbObjFirst( BBObjType *t );
|
||||
BBObj * _bbObjLast( BBObjType *t );
|
||||
void _bbObjInsBefore( BBObj *o1,BBObj *o2 );
|
||||
void _bbObjInsAfter( BBObj *o1,BBObj *o2 );
|
||||
int _bbObjEachFirst( BBObj **var,BBObjType *type );
|
||||
int _bbObjEachNext( BBObj **var );
|
||||
int _bbObjCompare( BBObj *o1,BBObj *o2 );
|
||||
BBStr * _bbObjToStr( BBObj *obj );
|
||||
int _bbObjToHandle( BBObj *obj );
|
||||
BBObj * _bbObjFromHandle( int handle,BBObjType *type );
|
||||
void _bbNullObjEx();
|
||||
|
||||
void _bbRestore( BBData *data );
|
||||
int _bbReadInt();
|
||||
float _bbReadFloat();
|
||||
BBStr * _bbReadStr();
|
||||
|
||||
int _bbAbs( int n );
|
||||
int _bbSgn( int n );
|
||||
int _bbMod( int x,int y );
|
||||
float _bbFAbs( float n );
|
||||
float _bbFSgn( float n );
|
||||
float _bbFMod( float x,float y );
|
||||
float _bbFPow( float x,float y );
|
||||
|
||||
void bbRuntimeStats();
|
||||
|
||||
#endif
|
82
bbruntime/bb_basic.h
Normal file
82
bbruntime/bb_basic.h
Normal file
@ -0,0 +1,82 @@
|
||||
|
||||
enum{
|
||||
BBTYPE_END=0,
|
||||
BBTYPE_INT=1,BBTYPE_FLOAT=2,
|
||||
BBTYPE_STRING=3,BBTYPE_CSTR=4,
|
||||
BBTYPE_OBJECT=5,BBTYPE_VECTOR=6
|
||||
};
|
||||
|
||||
typedef int bbInt;
|
||||
typedef float bbFloat;
|
||||
typedef bbStringhandle *bbString;
|
||||
typedef bbObjectHandle *bbObject;
|
||||
typedef bbVectorHandle *bbVector;
|
||||
typedef const char * bbCStr;
|
||||
|
||||
union bbValue{
|
||||
bbInt INT;
|
||||
bbFloat FLOAT;
|
||||
bbString STRING;
|
||||
bbObject OBJECT;
|
||||
bbVector VECTOR;
|
||||
bbCStr CSTR;
|
||||
};
|
||||
|
||||
struct bbType{
|
||||
int id;
|
||||
bbType( int n ):id(n(){}
|
||||
};
|
||||
|
||||
struct bbInstance{
|
||||
bbValue value;
|
||||
};
|
||||
|
||||
struct bbHandle{
|
||||
bbInstance *instance;
|
||||
int ref_cnt;
|
||||
bbType *type;
|
||||
};
|
||||
|
||||
struct bbEnviron{
|
||||
bbVector *variables;
|
||||
};
|
||||
|
||||
struct bbIntType : public bbType{
|
||||
bbInt():bbType( BBTYPE_INT ){}
|
||||
};
|
||||
|
||||
struct bbFloatType : public bbType{
|
||||
bbFloat():bbType( BBTYPE_FLOAT ){}
|
||||
};
|
||||
|
||||
struct bbCStrType : public bbType{
|
||||
bbCStrType():bbType( BBTYPE_CSTR ){}
|
||||
};
|
||||
|
||||
struct bbStringType : public bbType{
|
||||
bbStringType():bbType( BBTYPE_STRING ){}
|
||||
};
|
||||
|
||||
struct bbVectorType : public bbType{
|
||||
bbType *element_type;
|
||||
bbVectorType( bbType *e ):bbType( BBTYPE_VECTOR ),element_type( e ){}
|
||||
}
|
||||
|
||||
struct bbObjectType : public bbType{
|
||||
bbEnviron *environ;
|
||||
bbObject *first_used,*last_used;
|
||||
bbObject *first_free,*last_free;
|
||||
bbObjectType( bbEnviron *e ):bbType( BBTYPE_OBJECT ),environ( e ){}
|
||||
};
|
||||
|
||||
struct bbStringHandle : public bbHandle{
|
||||
};
|
||||
|
||||
struct bbObjectHandle : public bbHandle{
|
||||
bbObject *next,*prev;
|
||||
};
|
||||
|
||||
struct bbVectorHandle : public bbHandle{
|
||||
};
|
||||
|
||||
void assign( bbHandleVariable dest,bbHandle src );
|
142
bbruntime/bbaudio.cpp
Normal file
142
bbruntime/bbaudio.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbaudio.h"
|
||||
|
||||
gxAudio *gx_audio;
|
||||
|
||||
static inline void debugSound( gxSound *s ){
|
||||
if( debug ){
|
||||
if( !gx_audio->verifySound( s ) ) RTEX( "Sound does not exist" );
|
||||
}
|
||||
}
|
||||
|
||||
static gxSound *loadSound( BBStr *f,bool use_3d ){
|
||||
string t=*f;delete f;
|
||||
return gx_audio ? gx_audio->loadSound( t,use_3d ) : 0;
|
||||
}
|
||||
|
||||
static gxChannel *playMusic( BBStr *f,bool use_3d ){
|
||||
string t=*f;delete f;
|
||||
return gx_audio ? gx_audio->playFile( t,use_3d ) : 0;
|
||||
}
|
||||
|
||||
gxSound *bbLoadSound( BBStr *f ){
|
||||
return loadSound( f,false );
|
||||
}
|
||||
|
||||
void bbFreeSound( gxSound *sound ){
|
||||
if( !sound ) return;
|
||||
debugSound( sound );
|
||||
gx_audio->freeSound( sound );
|
||||
}
|
||||
|
||||
void bbLoopSound( gxSound *sound ){
|
||||
if( !sound ) return;
|
||||
debugSound( sound );
|
||||
sound->setLoop( true );
|
||||
}
|
||||
|
||||
void bbSoundPitch( gxSound *sound,int pitch ){
|
||||
if( !sound ) return;
|
||||
debugSound( sound );
|
||||
sound->setPitch( pitch );
|
||||
}
|
||||
|
||||
void bbSoundVolume( gxSound *sound,float volume ){
|
||||
if( !sound ) return;
|
||||
debugSound( sound );
|
||||
sound->setVolume( volume );
|
||||
}
|
||||
|
||||
void bbSoundPan( gxSound *sound,float pan ){
|
||||
if( !sound ) return;
|
||||
debugSound( sound );
|
||||
sound->setPan( pan );
|
||||
}
|
||||
|
||||
gxChannel *bbPlaySound( gxSound *sound ){
|
||||
if( !sound ) return 0;
|
||||
debugSound( sound );
|
||||
return sound->play();
|
||||
}
|
||||
|
||||
gxChannel *bbPlayMusic( BBStr *f ){
|
||||
return playMusic( f,false );
|
||||
}
|
||||
|
||||
gxChannel *bbPlayCDTrack( int track,int mode ){
|
||||
return gx_audio ? gx_audio->playCDTrack( track,mode ) : 0;
|
||||
}
|
||||
|
||||
void bbStopChannel( gxChannel *channel ){
|
||||
if( !channel ) return;
|
||||
channel->stop();
|
||||
}
|
||||
|
||||
void bbPauseChannel( gxChannel *channel ){
|
||||
if( !channel ) return;
|
||||
channel->setPaused( true );
|
||||
}
|
||||
|
||||
void bbResumeChannel( gxChannel *channel ){
|
||||
if( !channel ) return;
|
||||
channel->setPaused( false );
|
||||
}
|
||||
|
||||
void bbChannelPitch( gxChannel *channel,int pitch ){
|
||||
if( !channel ) return;
|
||||
channel->setPitch( pitch );
|
||||
}
|
||||
|
||||
void bbChannelVolume( gxChannel *channel,float volume ){
|
||||
if( !channel ) return;
|
||||
channel->setVolume( volume );
|
||||
}
|
||||
|
||||
void bbChannelPan( gxChannel *channel,float pan ){
|
||||
if( !channel ) return;
|
||||
channel->setPan( pan );
|
||||
}
|
||||
|
||||
int bbChannelPlaying( gxChannel *channel ){
|
||||
return channel ? channel->isPlaying() : 0;
|
||||
}
|
||||
|
||||
#ifdef PRO
|
||||
gxSound *bbLoad3DSound( BBStr *f ){
|
||||
return loadSound( f,true );
|
||||
}
|
||||
#endif
|
||||
|
||||
bool audio_create(){
|
||||
gx_audio=gx_runtime->openAudio( 0 );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool audio_destroy(){
|
||||
if( gx_audio ) gx_runtime->closeAudio( gx_audio );
|
||||
gx_audio=0;
|
||||
return true;
|
||||
}
|
||||
|
||||
void audio_link( void(*rtSym)(const char*,void*) ){
|
||||
rtSym( "%LoadSound$filename",bbLoadSound );
|
||||
rtSym( "FreeSound%sound",bbFreeSound );
|
||||
rtSym( "LoopSound%sound",bbLoopSound );
|
||||
rtSym( "SoundPitch%sound%pitch",bbSoundPitch );
|
||||
rtSym( "SoundVolume%sound#volume",bbSoundVolume );
|
||||
rtSym( "SoundPan%sound#pan",bbSoundPan );
|
||||
rtSym( "%PlaySound%sound",bbPlaySound );
|
||||
rtSym( "%PlayMusic$midifile",bbPlayMusic );
|
||||
rtSym( "%PlayCDTrack%track%mode=1",bbPlayCDTrack );
|
||||
rtSym( "StopChannel%channel",bbStopChannel );
|
||||
rtSym( "PauseChannel%channel",bbPauseChannel );
|
||||
rtSym( "ResumeChannel%channel",bbResumeChannel );
|
||||
rtSym( "ChannelPitch%channel%pitch",bbChannelPitch );
|
||||
rtSym( "ChannelVolume%channel#volume",bbChannelVolume );
|
||||
rtSym( "ChannelPan%channel#pan",bbChannelPan );
|
||||
rtSym( "%ChannelPlaying%channel",bbChannelPlaying );
|
||||
#ifdef PRO
|
||||
rtSym( "%Load3DSound$filename",bbLoad3DSound );
|
||||
#endif
|
||||
}
|
28
bbruntime/bbaudio.h
Normal file
28
bbruntime/bbaudio.h
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
#ifndef BBAUDIO_H
|
||||
#define BBAUDIO_H
|
||||
|
||||
#include "bbsys.h"
|
||||
#include "../gxruntime/gxaudio.h"
|
||||
|
||||
extern gxAudio *gx_audio;
|
||||
|
||||
gxSound * bbLoadSound( BBStr *file );
|
||||
void bbFreeSound( gxSound *sound );
|
||||
gxChannel * bbPlaySound( gxSound *sound );
|
||||
void bbLoopSound( gxSound *sound );
|
||||
void bbSoundPitch( gxSound *sound,int pitch );
|
||||
void bbSoundVolume( gxSound *sound,float volume );
|
||||
void bbSoundPan( gxSound *sound,float pan );
|
||||
gxChannel * bbPlayMusic( BBStr *s );
|
||||
gxChannel * bbPlayCDTrack( int track,int mode );
|
||||
void bbStopChannel( gxChannel *channel );
|
||||
void bbPauseChannel( gxChannel *channel );
|
||||
void bbResumeChannel( gxChannel *channel );
|
||||
void bbChannelPitch( gxChannel *channel,int pitch );
|
||||
void bbChannelVolume( gxChannel *channel,float volume );
|
||||
void bbChannelPan( gxChannel *channel,float pan );
|
||||
int bbChannelPlaying( gxChannel *channel );
|
||||
|
||||
#endif
|
||||
|
170
bbruntime/bbbank.cpp
Normal file
170
bbruntime/bbbank.cpp
Normal file
@ -0,0 +1,170 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbbank.h"
|
||||
#include "bbstream.h"
|
||||
|
||||
struct bbBank{
|
||||
char *data;
|
||||
int size,capacity;
|
||||
|
||||
bbBank( int sz ):size(sz){
|
||||
capacity=(size+15)&~15;
|
||||
data=d_new char[capacity];
|
||||
memset( data,0,size );
|
||||
}
|
||||
virtual ~bbBank(){
|
||||
delete[] data;
|
||||
}
|
||||
void resize( int n ){
|
||||
if( n>size ){
|
||||
if( n>capacity ){
|
||||
capacity=capacity*3/2;
|
||||
if( n>capacity ) capacity=n;
|
||||
capacity=(capacity+15)&~15;
|
||||
char *p=d_new char[capacity];
|
||||
memcpy( p,data,size );
|
||||
delete[] data;
|
||||
data=p;
|
||||
}else memset( data+size,0,n-size );
|
||||
}
|
||||
size=n;
|
||||
}
|
||||
};
|
||||
|
||||
static set<bbBank*> bank_set;
|
||||
|
||||
static inline void debugBank( bbBank *b ){
|
||||
if( debug ){
|
||||
if( !bank_set.count( b ) ) RTEX( "bbBank does not exist" );
|
||||
}
|
||||
}
|
||||
|
||||
static inline void debugBank( bbBank *b,int offset ){
|
||||
if( debug ){
|
||||
debugBank( b );
|
||||
if( offset>=b->size ) RTEX( "Offset out of range" );
|
||||
}
|
||||
}
|
||||
|
||||
bbBank *bbCreateBank( int size ){
|
||||
bbBank *b=d_new bbBank( size );
|
||||
bank_set.insert( b );
|
||||
return b;
|
||||
}
|
||||
|
||||
void bbFreeBank( bbBank *b ){
|
||||
if( bank_set.erase( b ) ) delete b;
|
||||
}
|
||||
|
||||
int bbBankSize( bbBank *b ){
|
||||
debugBank( b );
|
||||
return b->size;
|
||||
}
|
||||
|
||||
void bbResizeBank( bbBank *b,int size ){
|
||||
debugBank( b );
|
||||
b->resize( size );
|
||||
}
|
||||
|
||||
void bbCopyBank( bbBank *src,int src_p,bbBank *dest,int dest_p,int count ){
|
||||
if( debug ){ debugBank( src,src_p+count-1 );debugBank( dest,dest_p+count-1 ); }
|
||||
memmove( dest->data+dest_p,src->data+src_p,count );
|
||||
}
|
||||
|
||||
int bbPeekByte( bbBank *b,int offset ){
|
||||
debugBank( b,offset );
|
||||
return *(unsigned char*)(b->data+offset);
|
||||
}
|
||||
|
||||
int bbPeekShort( bbBank *b,int offset ){
|
||||
debugBank( b,offset+1 );
|
||||
return *(unsigned short*)(b->data+offset);
|
||||
}
|
||||
|
||||
int bbPeekInt( bbBank *b,int offset ){
|
||||
debugBank( b,offset+3 );
|
||||
return *(int*)(b->data+offset);
|
||||
}
|
||||
|
||||
float bbPeekFloat( bbBank *b,int offset ){
|
||||
debugBank( b,offset+3 );
|
||||
return *(float*)(b->data+offset);
|
||||
}
|
||||
|
||||
void bbPokeByte( bbBank *b,int offset,int value ){
|
||||
debugBank( b,offset );
|
||||
*(char*)(b->data+offset)=value;
|
||||
}
|
||||
|
||||
void bbPokeShort( bbBank *b,int offset,int value ){
|
||||
debugBank( b,offset );
|
||||
*(unsigned short*)(b->data+offset)=value;
|
||||
}
|
||||
|
||||
void bbPokeInt( bbBank *b,int offset,int value ){
|
||||
debugBank( b,offset );
|
||||
*(int*)(b->data+offset)=value;
|
||||
}
|
||||
|
||||
void bbPokeFloat( bbBank *b,int offset,float value ){
|
||||
debugBank( b,offset );
|
||||
*(float*)(b->data+offset)=value;
|
||||
}
|
||||
|
||||
int bbReadBytes( bbBank *b,bbStream *s,int offset,int count ){
|
||||
if( debug ){
|
||||
debugBank( b,offset+count-1 );
|
||||
debugStream( s );
|
||||
}
|
||||
return s->read( b->data+offset,count );
|
||||
}
|
||||
|
||||
int bbWriteBytes( bbBank *b,bbStream *s,int offset,int count ){
|
||||
if( debug ){
|
||||
debugBank( b,offset+count-1 );
|
||||
debugStream( s );
|
||||
}
|
||||
return s->write( b->data+offset,count );
|
||||
}
|
||||
|
||||
int bbCallDLL( BBStr *dll,BBStr *fun,bbBank *in,bbBank *out ){
|
||||
if( debug ){
|
||||
if( in ) debugBank( in );
|
||||
if( out ) debugBank( out );
|
||||
}
|
||||
int t=gx_runtime->callDll( *dll,*fun,
|
||||
in ? in->data : 0,in ? in->size : 0,
|
||||
out ? out->data : 0,out ? out->size : 0 );
|
||||
delete dll;delete fun;
|
||||
return t;
|
||||
}
|
||||
|
||||
bool bank_create(){
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bank_destroy(){
|
||||
while( bank_set.size() ) bbFreeBank( *bank_set.begin() );
|
||||
return true;
|
||||
}
|
||||
|
||||
void bank_link( void(*rtSym)(const char*,void*) ){
|
||||
rtSym( "%CreateBank%size=0",bbCreateBank );
|
||||
rtSym( "FreeBank%bank",bbFreeBank );
|
||||
rtSym( "%BankSize%bank",bbBankSize );
|
||||
rtSym( "ResizeBank%bank%size",bbResizeBank );
|
||||
rtSym( "CopyBank%src_bank%src_offset%dest_bank%dest_offset%count",bbCopyBank );
|
||||
rtSym( "%PeekByte%bank%offset",bbPeekByte );
|
||||
rtSym( "%PeekShort%bank%offset",bbPeekShort );
|
||||
rtSym( "%PeekInt%bank%offset",bbPeekInt );
|
||||
rtSym( "#PeekFloat%bank%offset",bbPeekFloat );
|
||||
rtSym( "PokeByte%bank%offset%value",bbPokeByte );
|
||||
rtSym( "PokeShort%bank%offset%value",bbPokeShort );
|
||||
rtSym( "PokeInt%bank%offset%value",bbPokeInt );
|
||||
rtSym( "PokeFloat%bank%offset#value",bbPokeFloat );
|
||||
rtSym( "%ReadBytes%bank%file%offset%count",bbReadBytes );
|
||||
rtSym( "%WriteBytes%bank%file%offset%count",bbWriteBytes );
|
||||
rtSym( "%CallDLL$dll_name$func_name%in_bank=0%out_bank=0",bbCallDLL );
|
||||
}
|
||||
|
||||
|
7
bbruntime/bbbank.h
Normal file
7
bbruntime/bbbank.h
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
#ifndef BBBANK_H
|
||||
#define BBBANK_H
|
||||
|
||||
#include "bbsys.h"
|
||||
|
||||
#endif
|
2230
bbruntime/bbblitz3d.cpp
Normal file
2230
bbruntime/bbblitz3d.cpp
Normal file
File diff suppressed because it is too large
Load Diff
11
bbruntime/bbblitz3d.h
Normal file
11
bbruntime/bbblitz3d.h
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
#ifndef BBBLITZ3D_H
|
||||
#define BBBLITZ3D_H
|
||||
|
||||
#include "bbsys.h"
|
||||
#include "../gxruntime/gxscene.h"
|
||||
|
||||
extern gxScene *gx_scene;
|
||||
|
||||
#endif
|
||||
|
170
bbruntime/bbfilesystem.cpp
Normal file
170
bbruntime/bbfilesystem.cpp
Normal file
@ -0,0 +1,170 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbfilesystem.h"
|
||||
#include "bbstream.h"
|
||||
#include <fstream>
|
||||
|
||||
gxFileSystem *gx_filesys;
|
||||
|
||||
struct bbFile : public bbStream{
|
||||
filebuf *buf;
|
||||
bbFile( filebuf *f ):buf(f){
|
||||
}
|
||||
~bbFile(){
|
||||
delete buf;
|
||||
}
|
||||
int read( char *buff,int size ){
|
||||
return buf->sgetn( (char*)buff,size );
|
||||
}
|
||||
int write( const char *buff,int size ){
|
||||
return buf->sputn( (char*)buff,size );
|
||||
}
|
||||
int avail(){
|
||||
return buf->in_avail();
|
||||
}
|
||||
int eof(){
|
||||
return buf->sgetc()==EOF;
|
||||
}
|
||||
};
|
||||
|
||||
static set<bbFile*> file_set;
|
||||
|
||||
static inline void debugFile( bbFile *f ){
|
||||
if( debug ){
|
||||
if( !file_set.count( f ) ) RTEX( "File does not exist" );
|
||||
}
|
||||
}
|
||||
|
||||
static inline void debugDir( gxDir *d ){
|
||||
if( debug ){
|
||||
if( !gx_filesys->verifyDir( d ) ) RTEX( "Directory does not exist" );
|
||||
}
|
||||
}
|
||||
|
||||
static bbFile *open( BBStr *f,int n ){
|
||||
string t=*f;
|
||||
filebuf *buf=d_new filebuf();
|
||||
if( buf->open( t.c_str(),n|ios_base::binary ) ){
|
||||
bbFile *f=d_new bbFile( buf );
|
||||
file_set.insert( f );
|
||||
return f;
|
||||
}
|
||||
delete buf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bbFile *bbReadFile( BBStr *f ){
|
||||
return open( f,ios_base::in );
|
||||
}
|
||||
|
||||
bbFile *bbWriteFile( BBStr *f ){
|
||||
return open( f,ios_base::out|ios_base::trunc );
|
||||
}
|
||||
|
||||
bbFile *bbOpenFile( BBStr *f ){
|
||||
return open( f,ios_base::in|ios_base::out );
|
||||
}
|
||||
|
||||
void bbCloseFile( bbFile *f ){
|
||||
debugFile( f );
|
||||
file_set.erase( f );
|
||||
delete f;
|
||||
}
|
||||
|
||||
int bbFilePos( bbFile *f ){
|
||||
return f->buf->pubseekoff( 0,ios_base::cur );
|
||||
}
|
||||
|
||||
int bbSeekFile( bbFile *f,int pos ){
|
||||
return f->buf->pubseekoff( pos,ios_base::beg );
|
||||
}
|
||||
|
||||
gxDir *bbReadDir( BBStr *d ){
|
||||
string t=*d;delete d;
|
||||
return gx_filesys->openDir( t,0 );
|
||||
}
|
||||
|
||||
void bbCloseDir( gxDir *d ){
|
||||
gx_filesys->closeDir( d );
|
||||
}
|
||||
|
||||
BBStr *bbNextFile( gxDir *d ){
|
||||
debugDir( d );
|
||||
return d_new BBStr( d->getNextFile() );
|
||||
}
|
||||
|
||||
BBStr *bbCurrentDir(){
|
||||
return d_new BBStr( gx_filesys->getCurrentDir() );
|
||||
}
|
||||
|
||||
void bbChangeDir( BBStr *d ){
|
||||
gx_filesys->setCurrentDir( *d );
|
||||
delete d;
|
||||
}
|
||||
|
||||
void bbCreateDir( BBStr *d ){
|
||||
gx_filesys->createDir( *d );
|
||||
delete d;
|
||||
}
|
||||
|
||||
void bbDeleteDir( BBStr *d ){
|
||||
gx_filesys->deleteDir( *d );
|
||||
delete d;
|
||||
}
|
||||
|
||||
int bbFileType( BBStr *f ){
|
||||
string t=*f;delete f;
|
||||
int n=gx_filesys->getFileType( t );
|
||||
return n==gxFileSystem::FILE_TYPE_FILE ? 1 : (n==gxFileSystem::FILE_TYPE_DIR ? 2 : 0);
|
||||
}
|
||||
|
||||
int bbFileSize( BBStr *f ){
|
||||
string t=*f;delete f;
|
||||
return gx_filesys->getFileSize( t );
|
||||
}
|
||||
|
||||
void bbCopyFile( BBStr *f,BBStr *to ){
|
||||
string src=*f,dest=*to;
|
||||
delete f;delete to;
|
||||
gx_filesys->copyFile( src,dest );
|
||||
}
|
||||
|
||||
void bbDeleteFile( BBStr *f ){
|
||||
gx_filesys->deleteFile( *f );
|
||||
delete f;
|
||||
}
|
||||
|
||||
bool filesystem_create(){
|
||||
if( gx_filesys=gx_runtime->openFileSystem( 0 ) ){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool filesystem_destroy(){
|
||||
while( file_set.size() ) bbCloseFile( *file_set.begin() );
|
||||
gx_runtime->closeFileSystem( gx_filesys );
|
||||
return true;
|
||||
}
|
||||
|
||||
void filesystem_link( void(*rtSym)(const char*,void*) ){
|
||||
rtSym( "%OpenFile$filename",bbOpenFile );
|
||||
rtSym( "%ReadFile$filename",bbReadFile );
|
||||
rtSym( "%WriteFile$filename",bbWriteFile );
|
||||
rtSym( "CloseFile%file_stream",bbCloseFile );
|
||||
rtSym( "%FilePos%file_stream",bbFilePos );
|
||||
rtSym( "%SeekFile%file_stream%pos",bbSeekFile );
|
||||
|
||||
rtSym( "%ReadDir$dirname",bbReadDir );
|
||||
rtSym( "CloseDir%dir",bbCloseDir );
|
||||
rtSym( "$NextFile%dir",bbNextFile );
|
||||
rtSym( "$CurrentDir",bbCurrentDir );
|
||||
rtSym( "ChangeDir$dir",bbChangeDir );
|
||||
rtSym( "CreateDir$dir",bbCreateDir );
|
||||
rtSym( "DeleteDir$dir",bbDeleteDir );
|
||||
|
||||
rtSym( "%FileSize$file",bbFileSize );
|
||||
rtSym( "%FileType$file",bbFileType );
|
||||
rtSym( "CopyFile$file$to",bbCopyFile );
|
||||
rtSym( "DeleteFile$file",bbDeleteFile );
|
||||
}
|
10
bbruntime/bbfilesystem.h
Normal file
10
bbruntime/bbfilesystem.h
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
#ifndef BBFILESYSTEM_H
|
||||
#define BBFILESYSTEM_H
|
||||
|
||||
#include "bbsys.h"
|
||||
#include "../gxruntime/gxfilesystem.h"
|
||||
|
||||
extern gxFileSystem *gx_filesys;
|
||||
|
||||
#endif
|
1350
bbruntime/bbgraphics.cpp
Normal file
1350
bbruntime/bbgraphics.cpp
Normal file
File diff suppressed because it is too large
Load Diff
120
bbruntime/bbgraphics.h
Normal file
120
bbruntime/bbgraphics.h
Normal file
@ -0,0 +1,120 @@
|
||||
|
||||
#ifndef BBGRAPHICS_H
|
||||
#define BBGRAPHICS_H
|
||||
|
||||
#include "bbsys.h"
|
||||
#include "../gxruntime/gxgraphics.h"
|
||||
|
||||
extern gxGraphics *gx_graphics;
|
||||
extern gxCanvas *gx_canvas;
|
||||
extern gxScene *gx_scene;
|
||||
|
||||
class bbImage;
|
||||
|
||||
//general graphics functions
|
||||
int bbCountGfxDrivers();
|
||||
BBStr * bbGfxDriverName( int n );
|
||||
BBStr * bbGfxDriverDesc( int n );
|
||||
void bbSetGfxDriver( int n );
|
||||
int bbGfxModeExists( int w,int h,int d );
|
||||
int bbCountGfxModes();
|
||||
int bbGfxModeWidth( int n );
|
||||
int bbGfxModeHeight( int n );
|
||||
int bbGfxModeDepth( int n );
|
||||
int bbGraphicsWidth();
|
||||
int bbGraphicsHeight();
|
||||
int bbGraphicsDepth();
|
||||
int bbAvailVidMem();
|
||||
int bbTotalVidMem();
|
||||
|
||||
//mode functions
|
||||
void bbGraphics( int w,int h,int d,int mode );
|
||||
gxCanvas * bbFrontBuffer();
|
||||
gxCanvas * bbBackBuffer();
|
||||
void bbEndGraphics();
|
||||
int bbGraphicsLost();
|
||||
int bbScanLine();
|
||||
void bbVWait( int n );
|
||||
void bbFlip( int vwait );
|
||||
|
||||
//graphics buffer functions
|
||||
void bbSetBuffer( gxCanvas *buff );
|
||||
gxCanvas * bbGraphicsBuffer();
|
||||
int bbLoadBuffer( gxCanvas *surf,BBStr *str );
|
||||
int bbSaveBuffer( gxCanvas *surf,BBStr *str );
|
||||
|
||||
//fast read/write operations...
|
||||
void bbLockBuffer( gxCanvas *buff );
|
||||
void bbUnlockBuffer( gxCanvas *buff );
|
||||
int bbReadPixel( int x,int y,gxCanvas *buff );
|
||||
void bbWritePixel( int x,int y,int argb,gxCanvas *buff );
|
||||
int bbReadPixelFast( int x,int y,gxCanvas *buff );
|
||||
void bbWritePixelFast( int x,int y,int argb,gxCanvas *buff );
|
||||
|
||||
|
||||
//2d rendering functions
|
||||
void bbOrigin( int x,int y );
|
||||
void bbViewport( int x,int y,int w,int h );
|
||||
void bbColor( int r,int g,int b );
|
||||
void bbClsColor( int r,int g,int b );
|
||||
void bbCls();
|
||||
void bbPlot( int x,int y );
|
||||
void bbLine( int x1,int y1,int x2,int y2 );
|
||||
void bbRect( int x,int y,int w,int h,int solid );
|
||||
void bbOval( int x,int y,int w,int h,int solid );
|
||||
void bbText( int x,int y,BBStr *str,int centre_x,int centre_y );
|
||||
void bbGetColor( int x,int y );
|
||||
int bbColorRed();
|
||||
int bbColorGreen();
|
||||
int bbColorBlue();
|
||||
|
||||
//font functions
|
||||
gxFont * bbLoadFont( BBStr *name,int height,int bold,int italic,int underline );
|
||||
void bbFreeFont( gxFont *f );
|
||||
void bbSetFont( gxFont *f );
|
||||
int bbFontWidth();
|
||||
int bbFontHeight();
|
||||
int bbStringWidth( BBStr *str );
|
||||
int bbStringHeight( BBStr *str );
|
||||
|
||||
//image functions
|
||||
bbImage* bbLoadImage( BBStr *s );
|
||||
bbImage* bbCopyImage( bbImage *i );
|
||||
bbImage* bbCreateImage( int w,int h,int n );
|
||||
bbImage* bbLoadAnimImage( BBStr *s,int w,int h,int first,int cnt );
|
||||
void bbFreeImage( bbImage *i );
|
||||
int bbSaveImage( bbImage *i,BBStr *filename,int frame );
|
||||
void bbGrabImage( bbImage *i,int x,int y,int n );
|
||||
gxCanvas * bbImageBuffer( bbImage *i,int n );
|
||||
void bbDrawImage( bbImage *i,int x,int y,int frame );
|
||||
void bbDrawBlock( bbImage *i,int x,int y,int frame );
|
||||
void bbTileImage( bbImage *i,int x,int y,int frame );
|
||||
void bbTileBlock( bbImage *i,int x,int y,int frame );
|
||||
void bbDrawImageRect( bbImage *i,int x,int y,int r_x,int r_y,int r_w,int r_h,int frame );
|
||||
void bbDrawBlockRect( bbImage *i,int x,int y,int r_x,int r_y,int r_w,int r_h,int frame );
|
||||
void bbMaskImage( bbImage *i,int r,int g,int b );
|
||||
void bbHandleImage( bbImage *i,int x,int y );
|
||||
void bbScaleImage( bbImage *i,float w,float h );
|
||||
void bbResizeImage( bbImage *i,float w,float h );
|
||||
void bbRotateImage( bbImage *i,float angle );
|
||||
void bbTFormImage( bbImage *i,float a,float b,float c,float d );
|
||||
void bbTFormFilter( int enable );
|
||||
void bbAutoMidHandle( int enable );
|
||||
void bbMidHandle( bbImage *i );
|
||||
int bbImageWidth( bbImage *i );
|
||||
int bbImageHeight( bbImage *i );
|
||||
int bbImageXHandle( bbImage *i );
|
||||
int bbImageYHandle( bbImage *i );
|
||||
int bbImagesOverlap( bbImage *i1,int x1,int y1,bbImage *i2,int x2,int y2 );
|
||||
int bbImagesCollide( bbImage *i1,int x1,int y1,int f1,bbImage *i2,int x2,int y2,int f2 );
|
||||
int bbRectsOverlap( int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2 );
|
||||
int bbImageRectOverlap( bbImage *i,int x,int y,int r_x,int r_y,int r_w,int r_h );
|
||||
int bbImageRectCollide( bbImage *i,int x,int y,int f,int r_x,int r_y,int r_w,int r_h );
|
||||
|
||||
//simple print functions
|
||||
void bbWrite( BBStr *str );
|
||||
void bbPrint( BBStr *str );
|
||||
BBStr * bbInput( BBStr *prompt );
|
||||
void bbLocate( int x,int y );
|
||||
|
||||
#endif
|
287
bbruntime/bbinput.cpp
Normal file
287
bbruntime/bbinput.cpp
Normal file
@ -0,0 +1,287 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
|
||||
gxInput *gx_input;
|
||||
gxDevice *gx_mouse;
|
||||
gxDevice *gx_keyboard;
|
||||
vector<gxDevice*> gx_joysticks;
|
||||
|
||||
static int mouse_x,mouse_y,mouse_z;
|
||||
static const float JLT=-1.0f/3.0f;
|
||||
static const float JHT=1.0f/3.0f;
|
||||
|
||||
bool input_create(){
|
||||
if( gx_input=gx_runtime->openInput( 0 ) ){
|
||||
if( gx_keyboard=gx_input->getKeyboard() ){
|
||||
if( gx_mouse=gx_input->getMouse() ){
|
||||
gx_joysticks.clear();
|
||||
for( int k=0;k<gx_input->numJoysticks();++k ){
|
||||
gx_joysticks.push_back( gx_input->getJoystick(k) );
|
||||
}
|
||||
mouse_x=mouse_y=mouse_z=0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
gx_runtime->closeInput( gx_input );
|
||||
gx_input=0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool input_destroy(){
|
||||
gx_joysticks.clear();
|
||||
gx_runtime->closeInput( gx_input );
|
||||
gx_input=0;
|
||||
return true;
|
||||
}
|
||||
|
||||
int bbKeyDown( int n ){
|
||||
return gx_keyboard->keyDown( n );
|
||||
}
|
||||
|
||||
int bbKeyHit( int n ){
|
||||
return gx_keyboard->keyHit( n );
|
||||
}
|
||||
|
||||
int bbGetKey(){
|
||||
return gx_input->toAscii( gx_keyboard->getKey() );
|
||||
}
|
||||
|
||||
int bbWaitKey(){
|
||||
for(;;){
|
||||
if( !gx_runtime->idle() ) RTEX( 0 );
|
||||
if( int key=gx_keyboard->getKey( ) ){
|
||||
if( key=gx_input->toAscii( key ) ) return key;
|
||||
}
|
||||
gx_runtime->delay( 20 );
|
||||
}
|
||||
}
|
||||
|
||||
void bbFlushKeys(){
|
||||
gx_keyboard->flush();
|
||||
}
|
||||
|
||||
int bbMouseDown( int n ){
|
||||
return gx_mouse->keyDown( n );
|
||||
}
|
||||
|
||||
int bbMouseHit( int n ){
|
||||
return gx_mouse->keyHit( n );
|
||||
}
|
||||
|
||||
int bbGetMouse(){
|
||||
return gx_mouse->getKey();
|
||||
}
|
||||
|
||||
int bbWaitMouse(){
|
||||
for(;;){
|
||||
if( !gx_runtime->idle() ) RTEX( 0 );
|
||||
if( int key=gx_mouse->getKey() ) return key;
|
||||
gx_runtime->delay( 20 );
|
||||
}
|
||||
}
|
||||
|
||||
int bbMouseWait(){
|
||||
return bbWaitMouse();
|
||||
}
|
||||
|
||||
int bbMouseX(){
|
||||
return gx_mouse->getAxisState( 0 );
|
||||
}
|
||||
|
||||
int bbMouseY(){
|
||||
return gx_mouse->getAxisState( 1 );
|
||||
}
|
||||
|
||||
int bbMouseZ(){
|
||||
return gx_mouse->getAxisState( 2 )/120;
|
||||
}
|
||||
|
||||
int bbMouseXSpeed(){
|
||||
int dx=bbMouseX()-mouse_x;
|
||||
mouse_x+=dx;
|
||||
return dx;
|
||||
}
|
||||
|
||||
int bbMouseYSpeed(){
|
||||
int dy=bbMouseY()-mouse_y;
|
||||
mouse_y+=dy;
|
||||
return dy;
|
||||
}
|
||||
|
||||
int bbMouseZSpeed(){
|
||||
int dz=bbMouseZ()-mouse_z;
|
||||
mouse_z+=dz;
|
||||
return dz;
|
||||
}
|
||||
|
||||
void bbFlushMouse(){
|
||||
gx_mouse->flush();
|
||||
}
|
||||
|
||||
void bbMoveMouse( int x,int y ){
|
||||
gx_input->moveMouse( mouse_x=x,mouse_y=y );
|
||||
}
|
||||
|
||||
int bbJoyType( int port ){
|
||||
return gx_input->getJoystickType( port );
|
||||
}
|
||||
|
||||
int bbJoyDown( int n,int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->keyDown( n );
|
||||
}
|
||||
|
||||
int bbJoyHit( int n,int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->keyHit( n );
|
||||
}
|
||||
|
||||
int bbGetJoy( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getKey();
|
||||
}
|
||||
|
||||
int bbWaitJoy( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
for(;;){
|
||||
if( !gx_runtime->idle() ) RTEX( 0 );
|
||||
if( int key=gx_joysticks[port]->getKey() ) return key;
|
||||
gx_runtime->delay( 20 );
|
||||
}
|
||||
}
|
||||
|
||||
float bbJoyX( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(0);
|
||||
}
|
||||
|
||||
float bbJoyY( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(1);
|
||||
}
|
||||
|
||||
float bbJoyZ( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(2);
|
||||
}
|
||||
|
||||
float bbJoyU( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(3);
|
||||
}
|
||||
|
||||
float bbJoyV( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(4);
|
||||
}
|
||||
|
||||
float bbJoyPitch( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(5)*180;
|
||||
}
|
||||
|
||||
float bbJoyYaw( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(6)*180;
|
||||
}
|
||||
|
||||
float bbJoyRoll( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(7)*180;
|
||||
}
|
||||
|
||||
int bbJoyHat( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
return gx_joysticks[port]->getAxisState(8);
|
||||
}
|
||||
|
||||
int bbJoyXDir( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
float t=gx_joysticks[port]->getAxisState(0);
|
||||
return t<JLT ? -1 : ( t>JHT ? 1 : 0 );
|
||||
}
|
||||
|
||||
int bbJoyYDir( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
float t=gx_joysticks[port]->getAxisState(1);
|
||||
return t<JLT ? -1 : ( t>JHT ? 1 : 0 );
|
||||
}
|
||||
|
||||
int bbJoyZDir( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
float t=gx_joysticks[port]->getAxisState(2);
|
||||
return t<JLT ? -1 : ( t>JHT ? 1 : 0 );
|
||||
}
|
||||
|
||||
int bbJoyUDir( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
float t=gx_joysticks[port]->getAxisState(3);
|
||||
return t<JLT ? -1 : ( t>JHT ? 1 : 0 );
|
||||
}
|
||||
|
||||
int bbJoyVDir( int port ){
|
||||
if( port<0 || port>=gx_joysticks.size() ) return 0;
|
||||
float t=gx_joysticks[port]->getAxisState(4);
|
||||
return t<JLT ? -1 : ( t>JHT ? 1 : 0 );
|
||||
}
|
||||
|
||||
void bbFlushJoy(){
|
||||
for( int k=0;k<gx_joysticks.size();++k ) gx_joysticks[k]->flush();
|
||||
}
|
||||
|
||||
void bbEnableDirectInput( int enable ){
|
||||
gx_runtime->enableDirectInput( !!enable );
|
||||
}
|
||||
|
||||
int bbDirectInputEnabled(){
|
||||
return gx_runtime->directInputEnabled();
|
||||
}
|
||||
|
||||
void input_link( void (*rtSym)( const char *sym,void *pc ) ){
|
||||
rtSym( "%KeyDown%key",bbKeyDown );
|
||||
rtSym( "%KeyHit%key",bbKeyHit );
|
||||
rtSym( "%GetKey",bbGetKey );
|
||||
rtSym( "%WaitKey",bbWaitKey );
|
||||
rtSym( "FlushKeys",bbFlushKeys );
|
||||
|
||||
rtSym( "%MouseDown%button",bbMouseDown );
|
||||
rtSym( "%MouseHit%button",bbMouseHit );
|
||||
rtSym( "%GetMouse",bbGetMouse );
|
||||
rtSym( "%WaitMouse",bbWaitMouse );
|
||||
rtSym( "%MouseWait",bbWaitMouse );
|
||||
rtSym( "%MouseX",bbMouseX );
|
||||
rtSym( "%MouseY",bbMouseY );
|
||||
rtSym( "%MouseZ",bbMouseZ );
|
||||
rtSym( "%MouseXSpeed",bbMouseXSpeed );
|
||||
rtSym( "%MouseYSpeed",bbMouseYSpeed );
|
||||
rtSym( "%MouseZSpeed",bbMouseZSpeed );
|
||||
rtSym( "FlushMouse",bbFlushMouse );
|
||||
rtSym( "MoveMouse%x%y",bbMoveMouse );
|
||||
|
||||
rtSym( "%JoyType%port=0",bbJoyType );
|
||||
rtSym( "%JoyDown%button%port=0",bbJoyDown );
|
||||
rtSym( "%JoyHit%button%port=0",bbJoyHit );
|
||||
rtSym( "%GetJoy%port=0",bbGetJoy );
|
||||
rtSym( "%WaitJoy%port=0",bbWaitJoy );
|
||||
rtSym( "%JoyWait%port=0",bbWaitJoy );
|
||||
rtSym( "#JoyX%port=0",bbJoyX );
|
||||
rtSym( "#JoyY%port=0",bbJoyY );
|
||||
rtSym( "#JoyZ%port=0",bbJoyZ );
|
||||
rtSym( "#JoyU%port=0",bbJoyU );
|
||||
rtSym( "#JoyV%port=0",bbJoyV );
|
||||
rtSym( "#JoyPitch%port=0",bbJoyPitch );
|
||||
rtSym( "#JoyYaw%port=0",bbJoyYaw );
|
||||
rtSym( "#JoyRoll%port=0",bbJoyRoll );
|
||||
rtSym( "%JoyHat%port=0",bbJoyHat );
|
||||
rtSym( "%JoyXDir%port=0",bbJoyXDir );
|
||||
rtSym( "%JoyYDir%port=0",bbJoyYDir );
|
||||
rtSym( "%JoyZDir%port=0",bbJoyZDir );
|
||||
rtSym( "%JoyUDir%port=0",bbJoyUDir );
|
||||
rtSym( "%JoyVDir%port=0",bbJoyVDir );
|
||||
rtSym( "FlushJoy",bbFlushJoy );
|
||||
|
||||
rtSym( "EnableDirectInput%enable",bbEnableDirectInput );
|
||||
rtSym( "%DirectInputEnabled",bbDirectInputEnabled );
|
||||
}
|
55
bbruntime/bbinput.h
Normal file
55
bbruntime/bbinput.h
Normal file
@ -0,0 +1,55 @@
|
||||
|
||||
#ifndef BBINPUT_H
|
||||
#define BBINPUT_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "bbsys.h"
|
||||
#include "../gxruntime/gxinput.h"
|
||||
|
||||
extern gxInput *gx_input;
|
||||
extern gxDevice *gx_mouse;
|
||||
extern gxDevice *gx_keyboard;
|
||||
extern std::vector<gxDevice*> gx_joysticks;
|
||||
|
||||
//keyboard
|
||||
int bbKeyDown( int n );
|
||||
int bbKeyHit( int n );
|
||||
int bbGetKey();
|
||||
int bbWaitKey();
|
||||
void bbFlushKeys();
|
||||
|
||||
//mouse
|
||||
int bbMouseDown( int n );
|
||||
int bbMouseHit( int n );
|
||||
int bbGetMouse();
|
||||
int bbWaitMouse();
|
||||
int bbMouseX();
|
||||
int bbMouseY();
|
||||
int bbMouseXSpeed();
|
||||
int bbMouseYSpeed();
|
||||
void bbMoveMouse( int x,int y );
|
||||
void bbFlushMouse();
|
||||
|
||||
//joysticks
|
||||
int bbJoyType( int port );
|
||||
int bbJoyDown( int n,int port );
|
||||
int bbJoyHit( int n,int port );
|
||||
int bbGetJoy( int port );
|
||||
int bbWaitJoy( int port );
|
||||
float bbJoyX( int port );
|
||||
float bbJoyY( int port );
|
||||
float bbJoyZ( int port );
|
||||
float bbJoyU( int port );
|
||||
float bbJoyV( int port );
|
||||
float bbJoyPitch( int port );
|
||||
float bbJoyYaw( int port );
|
||||
float bbJoyRoll( int port );
|
||||
int bbJoyXDir( int port );
|
||||
int bbJoyYDir( int port );
|
||||
int bbJoyZDir( int port );
|
||||
int bbJoyUDir( int port );
|
||||
int bbJoyVDir( int port );
|
||||
void bbFlushJoy();
|
||||
|
||||
#endif
|
80
bbruntime/bbmath.cpp
Normal file
80
bbruntime/bbmath.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbmath.h"
|
||||
|
||||
static int rnd_state;
|
||||
static const int RND_A=48271;
|
||||
static const int RND_M=2147483647;
|
||||
static const int RND_Q=44488;
|
||||
static const int RND_R=3399;
|
||||
|
||||
static const float dtor=0.0174532925199432957692369076848861f;
|
||||
static const float rtod=57.2957795130823208767981548141052f;
|
||||
|
||||
float bbSin( float n ){ return (float)sin(n*dtor); }
|
||||
float bbCos( float n ){ return (float)cos(n*dtor); }
|
||||
float bbTan( float n ){ return (float)tan(n*dtor); }
|
||||
float bbASin( float n ){ return (float)asin(n)*rtod; }
|
||||
float bbACos( float n ){ return (float)acos(n)*rtod; }
|
||||
float bbATan( float n ){ return (float)atan(n)*rtod; }
|
||||
float bbATan2( float n,float t ){ return (float)atan2(n,t)*rtod; }
|
||||
float bbSqr( float n ){ return (float)sqrt(n); }
|
||||
float bbFloor( float n ){ return (float)floor(n); }
|
||||
float bbCeil( float n ){ return (float)ceil(n); }
|
||||
float bbExp( float n ){ return (float)exp(n); }
|
||||
float bbLog( float n ){ return (float)log(n); }
|
||||
float bbLog10( float n ){ return (float)log10(n); }
|
||||
|
||||
//return rand float from 0...1
|
||||
static inline float rnd(){
|
||||
rnd_state=RND_A*(rnd_state%RND_Q)-RND_R*(rnd_state/RND_Q);
|
||||
if( rnd_state<0 ) rnd_state+=RND_M;
|
||||
return (rnd_state&65535)/65536.0f+(.5f/65536.0f);
|
||||
}
|
||||
|
||||
float bbRnd( float from,float to ){
|
||||
return rnd()*(to-from)+from;
|
||||
}
|
||||
|
||||
int bbRand( int from,int to ){
|
||||
if( to<from ) std::swap( from,to );
|
||||
return int(rnd()*(to-from+1))+from;
|
||||
}
|
||||
|
||||
void bbSeedRnd( int seed ){
|
||||
seed&=0x7fffffff;
|
||||
rnd_state=seed ? seed : 1;
|
||||
}
|
||||
|
||||
int bbRndSeed(){
|
||||
return rnd_state;
|
||||
}
|
||||
|
||||
bool math_create(){
|
||||
bbSeedRnd( 0x1234 );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool math_destroy(){
|
||||
return true;
|
||||
}
|
||||
|
||||
void math_link( void (*rtSym)( const char *sym,void *pc ) ){
|
||||
rtSym( "#Sin#degrees",bbSin );
|
||||
rtSym( "#Cos#degrees",bbCos );
|
||||
rtSym( "#Tan#degrees",bbTan );
|
||||
rtSym( "#ASin#float",bbASin );
|
||||
rtSym( "#ACos#float",bbACos );
|
||||
rtSym( "#ATan#float",bbATan );
|
||||
rtSym( "#ATan2#floata#floatb",bbATan2 );
|
||||
rtSym( "#Sqr#float",bbSqr );
|
||||
rtSym( "#Floor#float",bbFloor );
|
||||
rtSym( "#Ceil#float",bbCeil );
|
||||
rtSym( "#Exp#float",bbExp );
|
||||
rtSym( "#Log#float",bbLog );
|
||||
rtSym( "#Log10#float",bbLog10 );
|
||||
rtSym( "#Rnd#from#to=0",bbRnd );
|
||||
rtSym( "%Rand%from%to=1",bbRand );
|
||||
rtSym( "SeedRnd%seed",bbSeedRnd );
|
||||
rtSym( "%RndSeed",bbRndSeed );
|
||||
}
|
24
bbruntime/bbmath.h
Normal file
24
bbruntime/bbmath.h
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
#ifndef BBMATH_H
|
||||
#define BBMATH_H
|
||||
|
||||
float bbSin( float n );
|
||||
float bbCos( float n );
|
||||
float bbTan( float n );
|
||||
float bbASin( float n );
|
||||
float bbACos( float n );
|
||||
float bbATan( float n );
|
||||
float bbHSin( float n );
|
||||
float bbHCos( float n );
|
||||
float bbHTan( float n );
|
||||
float bbATan2( float n,float t );
|
||||
float bbSqr( float n );
|
||||
float bbFloor( float n );
|
||||
float bbCeil( float n );
|
||||
float bbExp( float n );
|
||||
float bbLog( float n );
|
||||
float bbLog10( float n );
|
||||
float bbRnd( float from,float to );
|
||||
void bbSeedRnd( int seed );
|
||||
|
||||
#endif
|
266
bbruntime/bbruntime.cpp
Normal file
266
bbruntime/bbruntime.cpp
Normal file
@ -0,0 +1,266 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
#include "bbruntime.h"
|
||||
|
||||
void bbEnd(){
|
||||
RTEX( 0 );
|
||||
}
|
||||
void bbStop(){
|
||||
gx_runtime->debugStop();
|
||||
if( !gx_runtime->idle() ) RTEX( 0 );
|
||||
}
|
||||
|
||||
void bbAppTitle( BBStr *ti,BBStr *cp ){
|
||||
gx_runtime->setTitle( *ti,*cp );
|
||||
delete ti;delete cp;
|
||||
}
|
||||
|
||||
void bbRuntimeError( BBStr *str ){
|
||||
string t=*str;delete str;
|
||||
if( t.size()>255 ) t[255]=0;
|
||||
static char err[256];
|
||||
strcpy( err,t.c_str() );
|
||||
RTEX( err );
|
||||
}
|
||||
|
||||
int bbExecFile( BBStr *f ){
|
||||
string t=*f;delete f;
|
||||
int n=gx_runtime->execute( t );
|
||||
if( !gx_runtime->idle() ) RTEX( 0 );
|
||||
return n;
|
||||
}
|
||||
|
||||
void bbDelay( int ms ){
|
||||
if( !gx_runtime->delay( ms ) ) RTEX( 0 );
|
||||
}
|
||||
|
||||
int bbMilliSecs(){
|
||||
return gx_runtime->getMilliSecs();
|
||||
}
|
||||
|
||||
BBStr * bbCommandLine(){
|
||||
return d_new BBStr( gx_runtime->commandLine() );
|
||||
}
|
||||
|
||||
BBStr * bbSystemProperty( BBStr *p ){
|
||||
string t=gx_runtime->systemProperty( *p );
|
||||
delete p;return d_new BBStr( t );
|
||||
}
|
||||
|
||||
BBStr * bbGetEnv( BBStr *env_var ){
|
||||
char *p=getenv( env_var->c_str() );
|
||||
BBStr *val=d_new BBStr( p ? p : "" );
|
||||
delete env_var;
|
||||
return val;
|
||||
}
|
||||
|
||||
void bbSetEnv( BBStr *env_var,BBStr *val ){
|
||||
string t=*env_var+"="+*val;
|
||||
putenv( t.c_str() );
|
||||
delete env_var;
|
||||
delete val;
|
||||
}
|
||||
|
||||
gxTimer * bbCreateTimer( int hertz ){
|
||||
gxTimer *t=gx_runtime->createTimer( hertz );
|
||||
return t;
|
||||
}
|
||||
|
||||
int bbWaitTimer( gxTimer *t ){
|
||||
int n=t->wait();
|
||||
if( !gx_runtime->idle() ) RTEX( 0 );
|
||||
return n;
|
||||
}
|
||||
|
||||
void bbFreeTimer( gxTimer *t ){
|
||||
gx_runtime->freeTimer( t );
|
||||
}
|
||||
|
||||
void bbDebugLog( BBStr *t ){
|
||||
gx_runtime->debugLog( t->c_str() );
|
||||
delete t;
|
||||
}
|
||||
|
||||
void _bbDebugStmt( int pos,const char *file ){
|
||||
gx_runtime->debugStmt( pos,file );
|
||||
if( !gx_runtime->idle() ) RTEX( 0 );
|
||||
}
|
||||
|
||||
void _bbDebugEnter( void *frame,void *env,const char *func ){
|
||||
gx_runtime->debugEnter( frame,env,func );
|
||||
}
|
||||
|
||||
void _bbDebugLeave(){
|
||||
gx_runtime->debugLeave();
|
||||
}
|
||||
|
||||
bool basic_create();
|
||||
bool basic_destroy();
|
||||
void basic_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
bool math_create();
|
||||
bool math_destroy();
|
||||
void math_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
bool string_create();
|
||||
bool string_destroy();
|
||||
void string_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
bool stream_create();
|
||||
bool stream_destroy();
|
||||
void stream_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
bool sockets_create();
|
||||
bool sockets_destroy();
|
||||
void sockets_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
bool filesystem_create();
|
||||
bool filesystem_destroy();
|
||||
void filesystem_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
bool bank_create();
|
||||
bool bank_destroy();
|
||||
void bank_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
bool graphics_create();
|
||||
bool graphics_destroy();
|
||||
void graphics_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
bool input_create();
|
||||
bool input_destroy();
|
||||
void input_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
bool audio_create();
|
||||
bool audio_destroy();
|
||||
void audio_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
bool multiplay_create();
|
||||
bool multiplay_destroy();
|
||||
void multiplay_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
bool userlibs_create();
|
||||
void userlibs_destroy();
|
||||
void userlibs_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
#ifdef PRO
|
||||
bool blitz3d_create();
|
||||
bool blitz3d_destroy();
|
||||
void blitz3d_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
#else
|
||||
bool blitz3d_create(){ return true; }
|
||||
bool blitz3d_destroy(){ return true; }
|
||||
void blitz3d_link( void (*rtSym)( const char *sym,void *pc ) ){}
|
||||
#endif
|
||||
|
||||
void bbruntime_link( void (*rtSym)( const char *sym,void *pc ) ){
|
||||
|
||||
rtSym( "End",bbEnd );
|
||||
rtSym( "Stop",bbStop );
|
||||
rtSym( "AppTitle$title$close_prompt=\"\"",bbAppTitle );
|
||||
rtSym( "RuntimeError$message",bbRuntimeError );
|
||||
rtSym( "ExecFile$command",bbExecFile );
|
||||
rtSym( "Delay%millisecs",bbDelay );
|
||||
rtSym( "%MilliSecs",bbMilliSecs );
|
||||
rtSym( "$CommandLine",bbCommandLine );
|
||||
rtSym( "$SystemProperty$property",bbSystemProperty );
|
||||
rtSym( "$GetEnv$env_var",bbGetEnv );
|
||||
rtSym( "SetEnv$env_var$value",bbSetEnv );
|
||||
|
||||
rtSym( "%CreateTimer%hertz",bbCreateTimer );
|
||||
rtSym( "%WaitTimer%timer",bbWaitTimer );
|
||||
rtSym( "FreeTimer%timer",bbFreeTimer );
|
||||
rtSym( "DebugLog$text",bbDebugLog );
|
||||
|
||||
rtSym( "_bbDebugStmt",_bbDebugStmt );
|
||||
rtSym( "_bbDebugEnter",_bbDebugEnter );
|
||||
rtSym( "_bbDebugLeave",_bbDebugLeave );
|
||||
|
||||
basic_link( rtSym );
|
||||
math_link( rtSym );
|
||||
string_link( rtSym );
|
||||
stream_link( rtSym );
|
||||
sockets_link( rtSym );
|
||||
filesystem_link( rtSym );
|
||||
bank_link( rtSym );
|
||||
graphics_link( rtSym );
|
||||
input_link( rtSym );
|
||||
audio_link( rtSym );
|
||||
multiplay_link( rtSym );
|
||||
blitz3d_link( rtSym );
|
||||
userlibs_link( rtSym );
|
||||
}
|
||||
|
||||
//start up error
|
||||
static void sue( const char *t ){
|
||||
string p=string( "Startup Error: " )+t;
|
||||
gx_runtime->debugInfo( p.c_str() );
|
||||
}
|
||||
|
||||
bool bbruntime_create(){
|
||||
if( basic_create() ){
|
||||
if( math_create() ){
|
||||
if( string_create() ){
|
||||
if( stream_create() ){
|
||||
if( sockets_create() ){
|
||||
if( filesystem_create() ){
|
||||
if( bank_create() ){
|
||||
if( graphics_create() ){
|
||||
if( input_create() ){
|
||||
if( audio_create() ){
|
||||
if( multiplay_create() ){
|
||||
if( blitz3d_create() ){
|
||||
if( userlibs_create() ){
|
||||
return true;
|
||||
}
|
||||
}else sue( "blitz3d_create failed" );
|
||||
multiplay_destroy();
|
||||
}else sue( "multiplay_create failed" );
|
||||
audio_destroy();
|
||||
}else sue( "audio_create failed" );
|
||||
input_destroy();
|
||||
}else sue( "input_create failed" );
|
||||
graphics_destroy();
|
||||
}else sue( "graphics_create failed" );
|
||||
bank_destroy();
|
||||
}else sue( "bank_create failed" );
|
||||
filesystem_destroy();
|
||||
}else sue( "filesystem_create failed" );
|
||||
sockets_destroy();
|
||||
}else sue( "sockets_create failed" );
|
||||
stream_destroy();
|
||||
}else sue( "stream_create failed" );
|
||||
string_destroy();
|
||||
}else sue( "string_create failed" );
|
||||
math_destroy();
|
||||
}else sue( "math_create failed" );
|
||||
basic_destroy();
|
||||
}else sue( "basic_create failed" );
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bbruntime_destroy(){
|
||||
userlibs_destroy();
|
||||
blitz3d_destroy();
|
||||
multiplay_destroy();
|
||||
audio_destroy();
|
||||
input_destroy();
|
||||
graphics_destroy();
|
||||
bank_destroy();
|
||||
filesystem_destroy();
|
||||
sockets_destroy();
|
||||
stream_destroy();
|
||||
string_destroy();
|
||||
math_destroy();
|
||||
basic_destroy();
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *bbruntime_run( gxRuntime *rt,void (*pc)(),bool dbg ){
|
||||
debug=dbg;
|
||||
gx_runtime=rt;
|
||||
|
||||
if( !bbruntime_create() ) return "Unable to start program";
|
||||
const char *t=0;
|
||||
try{
|
||||
if( !gx_runtime->idle() ) RTEX( 0 );
|
||||
pc();
|
||||
gx_runtime->debugInfo( "Program has ended" );
|
||||
}catch( bbEx x ){
|
||||
t=x.err;
|
||||
}
|
||||
bbruntime_destroy();
|
||||
return t;
|
||||
}
|
||||
|
||||
void bbruntime_panic( const char *err ){
|
||||
RTEX( err );
|
||||
}
|
375
bbruntime/bbruntime.dsp
Normal file
375
bbruntime/bbruntime.dsp
Normal file
@ -0,0 +1,375 @@
|
||||
# Microsoft Developer Studio Project File - Name="bbruntime" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=bbruntime - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "bbruntime.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "bbruntime.mak" CFG="bbruntime - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "bbruntime - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "bbruntime - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "bbruntime - Win32 Blitz3DRelease" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "bbruntime - Win32 Blitz2DRelease" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "bbruntime - Win32 Blitz3DEdu" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "bbruntime - Win32 Blitz3DDemo" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "bbruntime - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /Ox /Ow /Og /Oi /Os /Ob2 /Gf /Gy /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Yu"std.h" /FD /c
|
||||
# SUBTRACT CPP /Ot
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Yu"std.h" /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz3DRelease"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "bbruntime___Win32_Blitz3DRelease"
|
||||
# PROP BASE Intermediate_Dir "bbruntime___Win32_Blitz3DRelease"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "bbruntime___Win32_Blitz3DRelease"
|
||||
# PROP Intermediate_Dir "bbruntime___Win32_Blitz3DRelease"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /Ox /Ow /Og /Oi /Os /Ob2 /Gf /Gy /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Yu"std.h" /FD /c
|
||||
# SUBTRACT BASE CPP /Ot
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "_LIB" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /FD /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz2DRelease"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "bbruntime___Win32_Blitz2DRelease"
|
||||
# PROP BASE Intermediate_Dir "bbruntime___Win32_Blitz2DRelease"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "bbruntime___Win32_Blitz2DRelease"
|
||||
# PROP Intermediate_Dir "bbruntime___Win32_Blitz2DRelease"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /Ox /Ow /Og /Oi /Os /Ob2 /Gf /Gy /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Yu"std.h" /FD /c
|
||||
# SUBTRACT BASE CPP /Ot
|
||||
# ADD CPP /nologo /G6 /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Yu"std.h" /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz3DEdu"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "bbruntime___Win32_Blitz3DEdu"
|
||||
# PROP BASE Intermediate_Dir "bbruntime___Win32_Blitz3DEdu"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "bbruntime___Win32_Blitz3DEdu"
|
||||
# PROP Intermediate_Dir "bbruntime___Win32_Blitz3DEdu"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "PRO" /Yu"std.h" /FD /c
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "_LIB" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /D "EDU" /Yu"std.h" /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz3DDemo"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "bbruntime___Win32_Blitz3DDemo"
|
||||
# PROP BASE Intermediate_Dir "bbruntime___Win32_Blitz3DDemo"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "bbruntime___Win32_Blitz3DDemo"
|
||||
# PROP Intermediate_Dir "bbruntime___Win32_Blitz3DDemo"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "PRO" /Yu"std.h" /FD /c
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "_LIB" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /D "DEMO" /Yu"std.h" /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "bbruntime - Win32 Release"
|
||||
# Name "bbruntime - Win32 Debug"
|
||||
# Name "bbruntime - Win32 Blitz3DRelease"
|
||||
# Name "bbruntime - Win32 Blitz2DRelease"
|
||||
# Name "bbruntime - Win32 Blitz3DEdu"
|
||||
# Name "bbruntime - Win32 Blitz3DDemo"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\basic.cpp
|
||||
|
||||
!IF "$(CFG)" == "bbruntime - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Debug"
|
||||
|
||||
# ADD CPP /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz3DRelease"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz2DRelease"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz3DEdu"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz3DDemo"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbaudio.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbbank.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbblitz3d.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbfilesystem.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbgraphics.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbinput.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbmath.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbruntime.cpp
|
||||
|
||||
!IF "$(CFG)" == "bbruntime - Win32 Release"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Debug"
|
||||
|
||||
# ADD CPP /Yu"std.h"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz3DRelease"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz2DRelease"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz3DEdu"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime - Win32 Blitz3DDemo"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbsockets.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbstream.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbstring.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbsys.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\multiplay.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\multiplay_setup.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\multiplay_setup.rc
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\std.cpp
|
||||
# ADD CPP /Yc"std.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\userlibs.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\basic.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbaudio.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbbank.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbblitz3d.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbfilesystem.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbgraphics.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbinput.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbmath.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbruntime.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbsockets.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbstream.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbstring.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbsys.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\multiplay.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\multiplay_setup.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\std.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\userlibs.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
21
bbruntime/bbruntime.h
Normal file
21
bbruntime/bbruntime.h
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
/*
|
||||
|
||||
Platform neutral runtime library.
|
||||
|
||||
To be statically linked with an appropriate gxruntime driver.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BBRUNTIME_H
|
||||
#define BBRUNTIME_H
|
||||
|
||||
#include "../gxruntime/gxruntime.h"
|
||||
|
||||
void bbruntime_link( void (*rtSym)( const char *sym,void *pc ) );
|
||||
|
||||
const char *bbruntime_run( gxRuntime *runtime,void (*pc)(),bool debug );
|
||||
|
||||
void bbruntime_panic( const char *err );
|
||||
|
||||
#endif
|
505
bbruntime/bbsockets.cpp
Normal file
505
bbruntime/bbsockets.cpp
Normal file
@ -0,0 +1,505 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsockets.h"
|
||||
|
||||
static bool socks_ok;
|
||||
static WSADATA wsadata;
|
||||
static int recv_timeout;
|
||||
static int read_timeout;
|
||||
static int accept_timeout;
|
||||
|
||||
static void close( SOCKET sock,int e ){
|
||||
if( e<0 ){
|
||||
int opt=1;
|
||||
setsockopt( sock,SOL_SOCKET,SO_DONTLINGER,(char*)&opt,sizeof(opt) );
|
||||
}
|
||||
closesocket( sock );
|
||||
}
|
||||
|
||||
class UDPStream;
|
||||
class TCPStream;
|
||||
class TCPServer;
|
||||
|
||||
static set<UDPStream*> udp_set;
|
||||
static set<TCPStream*> tcp_set;
|
||||
static set<TCPServer*> server_set;
|
||||
|
||||
class UDPStream : public bbStream{
|
||||
public:
|
||||
UDPStream( SOCKET s );
|
||||
~UDPStream();
|
||||
|
||||
int read( char *buff,int size );
|
||||
int write( const char *buff,int size );
|
||||
int avail();
|
||||
int eof();
|
||||
|
||||
int recv();
|
||||
int send( int ip,int port );
|
||||
int getIP();
|
||||
int getPort();
|
||||
int getMsgIP();
|
||||
int getMsgPort();
|
||||
|
||||
private:
|
||||
SOCKET sock;
|
||||
vector<char> in_buf,out_buf;
|
||||
sockaddr_in addr,in_addr,out_addr;
|
||||
int in_get,e;
|
||||
};
|
||||
|
||||
UDPStream::UDPStream( SOCKET s ):sock(s),in_get(0),e(0){
|
||||
int len=sizeof(addr);
|
||||
getsockname( s,(sockaddr*)&addr,&len );
|
||||
in_addr=out_addr=addr;
|
||||
}
|
||||
|
||||
UDPStream::~UDPStream(){
|
||||
close( sock,e );
|
||||
}
|
||||
|
||||
int UDPStream::read( char *buff,int size ){
|
||||
if( e ) return 0;
|
||||
int n=in_buf.size()-in_get;
|
||||
if( n<size ) size=n;
|
||||
memcpy( buff,&in_buf[in_get],size );
|
||||
in_get+=size;
|
||||
return size;
|
||||
}
|
||||
|
||||
int UDPStream::write( const char *buff,int size ){
|
||||
if( e ) return 0;
|
||||
out_buf.insert( out_buf.end(),buff,buff+size );
|
||||
return size;
|
||||
}
|
||||
|
||||
int UDPStream::avail(){
|
||||
if( e ) return 0;
|
||||
return in_buf.size()-in_get;
|
||||
}
|
||||
|
||||
int UDPStream::eof(){
|
||||
return e ? e : in_get==in_buf.size();
|
||||
}
|
||||
|
||||
//fill buffer, return sender
|
||||
int UDPStream::recv(){
|
||||
if( e ) return 0;
|
||||
int tout;
|
||||
if( recv_timeout ) tout=gx_runtime->getMilliSecs()+recv_timeout;
|
||||
for(;;){
|
||||
int dt=0;
|
||||
if( recv_timeout ){
|
||||
dt=tout-gx_runtime->getMilliSecs();
|
||||
if( dt<0 ) dt=0;
|
||||
}
|
||||
fd_set fd={ 1,sock };
|
||||
timeval tv={ dt/1000,(dt%1000)*1000 };
|
||||
int n=::select( 0,&fd,0,0,&tv );
|
||||
if( !n ) return 0;
|
||||
if( n!=1 ){ e=-1;return 0; }
|
||||
unsigned long sz=-1;
|
||||
if( ioctlsocket( sock,FIONREAD,&sz ) ){ e=-1;return 0; }
|
||||
in_buf.resize( sz );in_get=0;
|
||||
int len=sizeof(in_addr);
|
||||
n=::recvfrom( sock,in_buf.begin(),sz,0,(sockaddr*)&in_addr,&len );
|
||||
if( n==SOCKET_ERROR ) continue; //{ e=-1;return 0; }
|
||||
in_buf.resize( n );
|
||||
return getMsgIP();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//send, empty buffer
|
||||
int UDPStream::send( int ip,int port ){
|
||||
if( e ) return 0;
|
||||
int sz=out_buf.size();
|
||||
out_addr.sin_addr.S_un.S_addr=htonl( ip );
|
||||
out_addr.sin_port=htons( port ? port : addr.sin_port );
|
||||
int n=::sendto( sock,out_buf.begin(),sz,0,(sockaddr*)&out_addr,sizeof(out_addr) );
|
||||
if( n!=sz ) return e=-1;
|
||||
out_buf.clear();
|
||||
return sz;
|
||||
}
|
||||
|
||||
int UDPStream::getIP(){
|
||||
return ntohl( addr.sin_addr.S_un.S_addr );
|
||||
}
|
||||
|
||||
int UDPStream::getPort(){
|
||||
return ntohs( addr.sin_port );
|
||||
}
|
||||
|
||||
int UDPStream::getMsgIP(){
|
||||
return ntohl( in_addr.sin_addr.S_un.S_addr );
|
||||
}
|
||||
|
||||
int UDPStream::getMsgPort(){
|
||||
return ntohs( in_addr.sin_port );
|
||||
}
|
||||
|
||||
class TCPStream : public bbStream{
|
||||
public:
|
||||
TCPStream( SOCKET s,TCPServer *t );
|
||||
~TCPStream();
|
||||
|
||||
int read( char *buff,int size );
|
||||
int write( const char *buff,int size );
|
||||
int avail();
|
||||
int eof();
|
||||
|
||||
int getIP();
|
||||
int getPort();
|
||||
|
||||
private:
|
||||
SOCKET sock;
|
||||
TCPServer *server;
|
||||
int e,ip,port;
|
||||
};
|
||||
|
||||
class TCPServer{
|
||||
public:
|
||||
TCPServer( SOCKET S );
|
||||
~TCPServer();
|
||||
|
||||
TCPStream *accept();
|
||||
|
||||
void remove( TCPStream *s );
|
||||
|
||||
private:
|
||||
int e;
|
||||
SOCKET sock;
|
||||
set<TCPStream*> accepted_set;
|
||||
};
|
||||
|
||||
TCPStream::TCPStream( SOCKET s,TCPServer *t ):sock(s),server(t),e(0){
|
||||
sockaddr_in addr;
|
||||
int len=sizeof(addr);
|
||||
if( getpeername( s,(sockaddr*)&addr,&len ) ){
|
||||
ip=port=0;
|
||||
return;
|
||||
}
|
||||
ip=ntohl(addr.sin_addr.S_un.S_addr);
|
||||
port=ntohs(addr.sin_port);
|
||||
}
|
||||
|
||||
TCPStream::~TCPStream(){
|
||||
if( server ) server->remove( this );
|
||||
close( sock,e );
|
||||
}
|
||||
|
||||
int TCPStream::read( char *buff,int size ){
|
||||
if( e ) return 0;
|
||||
char *b=buff,*l=buff+size;
|
||||
int tout;
|
||||
if( read_timeout ) tout=gx_runtime->getMilliSecs()+read_timeout;
|
||||
while( b<l ){
|
||||
int dt=0;
|
||||
if( read_timeout ){
|
||||
dt=tout-gx_runtime->getMilliSecs();
|
||||
if( dt<0 ) dt=0;
|
||||
}
|
||||
fd_set fd={ 1,sock };
|
||||
timeval tv={ dt/1000,(dt%1000)*1000 };
|
||||
int n=::select( 0,&fd,0,0,&tv );
|
||||
if( n!=1 ){ e=-1;break; }
|
||||
n=::recv( sock,b,l-b,0 );
|
||||
if( n==0 ){ e=1;break; }
|
||||
if( n==SOCKET_ERROR ){ e=-1;break; }
|
||||
b+=n;
|
||||
}
|
||||
return b-buff;
|
||||
}
|
||||
|
||||
int TCPStream::write( const char *buff,int size ){
|
||||
if( e ) return 0;
|
||||
int n=::send( sock,buff,size,0 );
|
||||
if( n==SOCKET_ERROR ){ e=-1;return 0; }
|
||||
return n;
|
||||
}
|
||||
|
||||
int TCPStream::avail(){
|
||||
unsigned long t;
|
||||
int n=::ioctlsocket( sock,FIONREAD,&t );
|
||||
if( n==SOCKET_ERROR ){ e=-1;return 0; }
|
||||
return t;
|
||||
}
|
||||
|
||||
int TCPStream::eof(){
|
||||
if( e ) return e;
|
||||
fd_set fd={ 1,sock };
|
||||
timeval tv={ 0,0 };
|
||||
switch( ::select( 0,&fd,0,0,&tv ) ){
|
||||
case 0:break;
|
||||
case 1:if( !avail() ) e=1;break;
|
||||
default:e=-1;
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
int TCPStream::getIP(){
|
||||
return ip;
|
||||
}
|
||||
|
||||
int TCPStream::getPort(){
|
||||
return port;
|
||||
}
|
||||
|
||||
TCPServer::TCPServer( SOCKET s ):sock(s),e(0){
|
||||
}
|
||||
|
||||
TCPServer::~TCPServer(){
|
||||
while( accepted_set.size() ) delete *accepted_set.begin();
|
||||
close( sock,e );
|
||||
}
|
||||
|
||||
TCPStream *TCPServer::accept(){
|
||||
if( e ) return 0;
|
||||
fd_set fd={ 1,sock };
|
||||
timeval tv={ accept_timeout/1000,(accept_timeout%1000)*1000 };
|
||||
int n=::select( 0,&fd,0,0,&tv );
|
||||
if( n==0 ) return 0;
|
||||
if( n!=1 ){ e=-1;return 0; }
|
||||
SOCKET t=::accept( sock,0,0 );
|
||||
if( t==INVALID_SOCKET ){ e=-1;return 0; }
|
||||
TCPStream *s=d_new TCPStream( t,this );
|
||||
accepted_set.insert( s );
|
||||
return s;
|
||||
}
|
||||
|
||||
void TCPServer::remove( TCPStream *s ){
|
||||
accepted_set.erase( s );
|
||||
}
|
||||
|
||||
static inline void debugUDPStream( UDPStream *p ){
|
||||
if( debug && !udp_set.count(p) ){
|
||||
RTEX( "UDP Stream does not exist" );
|
||||
}
|
||||
}
|
||||
|
||||
static inline void debugTCPStream( TCPStream *p ){
|
||||
if( debug && !tcp_set.count(p) ){
|
||||
RTEX( "TCP Stream does not exist" );
|
||||
}
|
||||
}
|
||||
|
||||
static inline void debugTCPServer( TCPServer *p ){
|
||||
if( debug && !server_set.count(p) ){
|
||||
RTEX( "TCP Server does not exist" );
|
||||
}
|
||||
}
|
||||
|
||||
static vector<int> host_ips;
|
||||
|
||||
int bbCountHostIPs( BBStr *host ){
|
||||
host_ips.clear();
|
||||
HOSTENT *h=gethostbyname( host->c_str() );
|
||||
delete host;if( !h ) return 0;
|
||||
char **p=h->h_addr_list;
|
||||
while( char *t=*p++ ) host_ips.push_back( ntohl(*(int*)t) );
|
||||
return host_ips.size();
|
||||
}
|
||||
|
||||
int bbHostIP( int index ){
|
||||
if( debug ){
|
||||
if( index<1 || index>host_ips.size() ){
|
||||
RTEX( "Host index out of range" );
|
||||
}
|
||||
}
|
||||
return host_ips[index-1];
|
||||
}
|
||||
|
||||
UDPStream *bbCreateUDPStream( int port ){
|
||||
if( !socks_ok ) return 0;
|
||||
SOCKET s=::socket( AF_INET,SOCK_DGRAM,0 );
|
||||
if( s!=INVALID_SOCKET ){
|
||||
sockaddr_in addr={AF_INET,htons(port)};
|
||||
if( !::bind( s,(sockaddr*)&addr,sizeof(addr) ) ){
|
||||
UDPStream *p=d_new UDPStream( s );
|
||||
udp_set.insert( p );
|
||||
return p;
|
||||
}
|
||||
::closesocket( s );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bbCloseUDPStream( UDPStream *p ){
|
||||
debugUDPStream( p );
|
||||
udp_set.erase( p );
|
||||
delete p;
|
||||
}
|
||||
|
||||
int bbRecvUDPMsg( UDPStream *p ){
|
||||
debugUDPStream( p );
|
||||
return p->recv();
|
||||
}
|
||||
|
||||
void bbSendUDPMsg( UDPStream *p,int ip,int port ){
|
||||
debugUDPStream( p );
|
||||
p->send( ip,port );
|
||||
}
|
||||
|
||||
int bbUDPStreamIP( UDPStream *p ){
|
||||
debugUDPStream( p );
|
||||
return p->getIP();
|
||||
}
|
||||
|
||||
int bbUDPStreamPort( UDPStream *p ){
|
||||
debugUDPStream( p );
|
||||
return p->getPort();
|
||||
}
|
||||
|
||||
int bbUDPMsgIP( UDPStream *p ){
|
||||
debugUDPStream( p );
|
||||
return p->getMsgIP();
|
||||
}
|
||||
|
||||
int bbUDPMsgPort( UDPStream *p ){
|
||||
debugUDPStream( p );
|
||||
return p->getMsgPort();
|
||||
}
|
||||
|
||||
void bbUDPTimeouts( int rt ){
|
||||
recv_timeout=rt;
|
||||
}
|
||||
|
||||
BBStr *bbDottedIP( int ip ){
|
||||
return d_new BBStr(
|
||||
itoa((ip>>24)&255)+"."+itoa((ip>>16)&255)+"."+
|
||||
itoa((ip>>8)&255)+"."+itoa(ip&255) );
|
||||
}
|
||||
|
||||
static int findHostIP( const string &t ){
|
||||
int ip=inet_addr( t.c_str() );
|
||||
if( ip!=INADDR_NONE ) return ip;
|
||||
HOSTENT *h=gethostbyname( t.c_str() );
|
||||
if( !h ) return -1;
|
||||
char *p;
|
||||
for( char **list=h->h_addr_list;p=*list;++list ){
|
||||
return *(int*)p;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
TCPStream *bbOpenTCPStream( BBStr *server,int port,int local_port ){
|
||||
if( !socks_ok ){
|
||||
delete server;
|
||||
return 0;
|
||||
}
|
||||
int ip=findHostIP( *server );delete server;
|
||||
if( ip==-1 ) return 0;
|
||||
SOCKET s=::socket( AF_INET,SOCK_STREAM,0 );
|
||||
if( s!=INVALID_SOCKET ){
|
||||
if( local_port ){
|
||||
sockaddr_in addr={AF_INET,htons(local_port)};
|
||||
if( ::bind( s,(sockaddr*)&addr,sizeof(addr) ) ){
|
||||
::closesocket( s );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
sockaddr_in addr={AF_INET,htons(port)};
|
||||
addr.sin_addr.S_un.S_addr=ip;
|
||||
if( !::connect( s,(sockaddr*)&addr,sizeof(addr) ) ){
|
||||
TCPStream *p=d_new TCPStream( s,0 );
|
||||
tcp_set.insert( p );
|
||||
return p;
|
||||
}
|
||||
::closesocket( s );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bbCloseTCPStream( TCPStream *p ){
|
||||
debugTCPStream( p );
|
||||
tcp_set.erase( p );
|
||||
delete p;
|
||||
}
|
||||
|
||||
TCPServer * bbCreateTCPServer( int port ){
|
||||
SOCKET s=::socket( AF_INET,SOCK_STREAM,0 );
|
||||
if( s!=INVALID_SOCKET ){
|
||||
sockaddr_in addr={AF_INET,htons(port)};
|
||||
if( !::bind( s,(sockaddr*)&addr,sizeof(addr) ) ){
|
||||
if( !::listen( s,SOMAXCONN ) ){
|
||||
TCPServer *p=d_new TCPServer( s );
|
||||
server_set.insert( p );
|
||||
return p;
|
||||
}
|
||||
}
|
||||
::closesocket(s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bbCloseTCPServer( TCPServer *p ){
|
||||
debugTCPServer( p );
|
||||
server_set.erase( p );
|
||||
delete p;
|
||||
}
|
||||
|
||||
TCPStream * bbAcceptTCPStream( TCPServer *server ){
|
||||
debugTCPServer( server );
|
||||
if( !gx_runtime->idle() ) RTEX( 0 );
|
||||
if( TCPStream *tcp=server->accept() ){
|
||||
tcp_set.insert( tcp );
|
||||
return tcp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bbTCPStreamIP( TCPStream *p ){
|
||||
debugTCPStream( p );
|
||||
return p->getIP();
|
||||
}
|
||||
|
||||
int bbTCPStreamPort( TCPStream *p ){
|
||||
debugTCPStream( p );
|
||||
return p->getPort();
|
||||
}
|
||||
|
||||
void bbTCPTimeouts( int rt,int at ){
|
||||
read_timeout=rt;
|
||||
accept_timeout=at;
|
||||
}
|
||||
|
||||
bool sockets_create(){
|
||||
socks_ok=WSAStartup( 0x0101,&wsadata )==0;
|
||||
recv_timeout=0;
|
||||
read_timeout=10000;
|
||||
accept_timeout=0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sockets_destroy(){
|
||||
while( udp_set.size() ) bbCloseUDPStream( *udp_set.begin() );
|
||||
while( tcp_set.size() ) bbCloseTCPStream( *tcp_set.begin() );
|
||||
while( server_set.size() ) bbCloseTCPServer( *server_set.begin() );
|
||||
if( socks_ok ) WSACleanup();
|
||||
return true;
|
||||
}
|
||||
|
||||
void sockets_link( void(*rtSym)(const char*,void*) ){
|
||||
rtSym( "$DottedIP%IP",bbDottedIP );
|
||||
rtSym( "%CountHostIPs$host_name",bbCountHostIPs );
|
||||
rtSym( "%HostIP%host_index",bbHostIP );
|
||||
|
||||
rtSym( "%CreateUDPStream%port=0",bbCreateUDPStream );
|
||||
rtSym( "CloseUDPStream%udp_stream",bbCloseUDPStream );
|
||||
rtSym( "SendUDPMsg%udp_stream%dest_ip%dest_port=0",bbSendUDPMsg );
|
||||
rtSym( "%RecvUDPMsg%udp_stream",bbRecvUDPMsg );
|
||||
rtSym( "%UDPStreamIP%udp_stream",bbUDPStreamIP );
|
||||
rtSym( "%UDPStreamPort%udp_stream",bbUDPStreamPort );
|
||||
rtSym( "%UDPMsgIP%udp_stream",bbUDPMsgIP );
|
||||
rtSym( "%UDPMsgPort%udp_stream",bbUDPMsgPort );
|
||||
rtSym( "UDPTimeouts%recv_timeout",bbUDPTimeouts );
|
||||
|
||||
rtSym( "%OpenTCPStream$server%server_port%local_port=0",bbOpenTCPStream );
|
||||
rtSym( "CloseTCPStream%tcp_stream",bbCloseTCPStream );
|
||||
rtSym( "%CreateTCPServer%port",bbCreateTCPServer );
|
||||
rtSym( "CloseTCPServer%tcp_server",bbCloseTCPServer );
|
||||
rtSym( "%AcceptTCPStream%tcp_server",bbAcceptTCPStream );
|
||||
rtSym( "%TCPStreamIP%tcp_stream",bbTCPStreamIP );
|
||||
rtSym( "%TCPStreamPort%tcp_stream",bbTCPStreamPort );
|
||||
rtSym( "TCPTimeouts%read_millis%accept_millis",bbTCPTimeouts );
|
||||
}
|
8
bbruntime/bbsockets.h
Normal file
8
bbruntime/bbsockets.h
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
#ifndef BBSOCKETS_H
|
||||
#define BBSOCKETS_H
|
||||
|
||||
#include "bbstream.h"
|
||||
|
||||
#endif
|
||||
|
160
bbruntime/bbstream.cpp
Normal file
160
bbruntime/bbstream.cpp
Normal file
@ -0,0 +1,160 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbstream.h"
|
||||
|
||||
static set<bbStream*> stream_set;
|
||||
|
||||
void debugStream( bbStream *s ){
|
||||
if( stream_set.count(s) ) return;
|
||||
RTEX( "Stream does not exist" );
|
||||
}
|
||||
|
||||
bbStream::bbStream(){
|
||||
stream_set.insert( this );
|
||||
}
|
||||
|
||||
bbStream::~bbStream(){
|
||||
stream_set.erase( this );
|
||||
}
|
||||
|
||||
int bbEof( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
return s->eof();
|
||||
}
|
||||
|
||||
int bbReadAvail( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
return s->avail();
|
||||
}
|
||||
|
||||
int bbReadByte( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
int n=0;
|
||||
s->read( (char*)&n,1 );
|
||||
return n;
|
||||
}
|
||||
|
||||
int bbReadShort( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
int n=0;
|
||||
s->read( (char*)&n,2 );
|
||||
return n;
|
||||
}
|
||||
|
||||
int bbReadInt( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
int n=0;
|
||||
s->read( (char*)&n,4 );
|
||||
return n;
|
||||
}
|
||||
|
||||
float bbReadFloat( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
float n=0;
|
||||
s->read( (char*)&n,4 );
|
||||
return n;
|
||||
}
|
||||
|
||||
BBStr *bbReadString( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
int len;
|
||||
BBStr *str=d_new BBStr();
|
||||
if( s->read( (char*)&len,4 ) ){
|
||||
char *buff=d_new char[len];
|
||||
if( s->read( buff,len ) ){
|
||||
*str=string( buff,len );
|
||||
}
|
||||
delete[] buff;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
BBStr *bbReadLine( bbStream *s ){
|
||||
if( debug ) debugStream( s );
|
||||
unsigned char c;
|
||||
BBStr *str=d_new BBStr();
|
||||
for(;;){
|
||||
if( s->read( (char*)&c,1 )!=1 ) break;
|
||||
if( c=='\n' ) break;
|
||||
if( c!='\r' ) *str+=c;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
void bbWriteByte( bbStream *s,int n ){
|
||||
if( debug ) debugStream( s );
|
||||
s->write( (char*)&n,1 );
|
||||
}
|
||||
|
||||
void bbWriteShort( bbStream *s,int n ){
|
||||
if( debug ) debugStream( s );
|
||||
s->write( (char*)&n,2 );
|
||||
}
|
||||
|
||||
void bbWriteInt( bbStream *s,int n ){
|
||||
if( debug ) debugStream( s );
|
||||
s->write( (char*)&n,4 );
|
||||
}
|
||||
|
||||
void bbWriteFloat( bbStream *s,float n ){
|
||||
if( debug ) debugStream( s );
|
||||
s->write( (char*)&n,4 );
|
||||
}
|
||||
|
||||
void bbWriteString( bbStream *s,BBStr *t ){
|
||||
if( debug ) debugStream( s );
|
||||
int n=t->size();
|
||||
s->write( (char*)&n,4 );
|
||||
s->write( t->data(),t->size() );
|
||||
delete t;
|
||||
}
|
||||
|
||||
void bbWriteLine( bbStream *s,BBStr *t ){
|
||||
if( debug ) debugStream( s );
|
||||
s->write( t->data(),t->size() );
|
||||
s->write( "\r\n",2 );
|
||||
delete t;
|
||||
}
|
||||
|
||||
void bbCopyStream( bbStream *s,bbStream *d,int buff_size ){
|
||||
if( debug ){
|
||||
debugStream( s );debugStream( d );
|
||||
if( buff_size<1 || buff_size>1024*1024 ) RTEX( "Illegal buffer size" );
|
||||
}
|
||||
char *buff=d_new char[buff_size];
|
||||
while( s->eof()==0 && d->eof()==0 ){
|
||||
int n=s->read( buff,buff_size );
|
||||
d->write( buff,n );
|
||||
if( n<buff_size ) break;
|
||||
}
|
||||
delete buff;
|
||||
}
|
||||
|
||||
bool stream_create(){
|
||||
return true;
|
||||
}
|
||||
|
||||
bool stream_destroy(){
|
||||
return true;
|
||||
}
|
||||
|
||||
void stream_link( void(*rtSym)(const char*,void*) ){
|
||||
rtSym( "%Eof%stream",bbEof );
|
||||
rtSym( "%ReadAvail%stream",bbReadAvail );
|
||||
rtSym( "%ReadByte%stream",bbReadByte );
|
||||
rtSym( "%ReadShort%stream",bbReadShort );
|
||||
rtSym( "%ReadInt%stream",bbReadInt );
|
||||
rtSym( "#ReadFloat%stream",bbReadFloat );
|
||||
rtSym( "$ReadString%stream",bbReadString );
|
||||
rtSym( "$ReadLine%stream",bbReadLine );
|
||||
rtSym( "WriteByte%stream%byte",bbWriteByte );
|
||||
rtSym( "WriteShort%stream%short",bbWriteShort );
|
||||
rtSym( "WriteInt%stream%int",bbWriteInt );
|
||||
rtSym( "WriteFloat%stream#float",bbWriteFloat );
|
||||
rtSym( "WriteString%stream$string",bbWriteString );
|
||||
rtSym( "WriteLine%stream$string",bbWriteLine );
|
||||
rtSym( "CopyStream%src_stream%dest_stream%buffer_size=16384",bbCopyStream );
|
||||
}
|
||||
|
||||
|
||||
|
31
bbruntime/bbstream.h
Normal file
31
bbruntime/bbstream.h
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
#ifndef BBSTREAM_H
|
||||
#define BBSTREAM_H
|
||||
|
||||
#include "bbsys.h"
|
||||
|
||||
class bbStream{
|
||||
public:
|
||||
enum{
|
||||
EOF_ERROR=-1,EOF_NOT=0,EOF_OK=1
|
||||
};
|
||||
|
||||
bbStream();
|
||||
virtual ~bbStream();
|
||||
|
||||
//returns chars read
|
||||
virtual int read( char *buff,int size )=0;
|
||||
|
||||
//returns chars written
|
||||
virtual int write( const char *buff,int size )=0;
|
||||
|
||||
//returns chars avilable for reading
|
||||
virtual int avail()=0;
|
||||
|
||||
//returns EOF status
|
||||
virtual int eof()=0;
|
||||
};
|
||||
|
||||
void debugStream( bbStream *s );
|
||||
|
||||
#endif
|
162
bbruntime/bbstring.cpp
Normal file
162
bbruntime/bbstring.cpp
Normal file
@ -0,0 +1,162 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
#include <time.h>
|
||||
|
||||
#define CHKPOS(x) if( (x)<0 ) RTEX( "parameter must be positive" );
|
||||
#define CHKOFF(x) if( (x)<=0 ) RTEX( "parameter must be greater than 0" );
|
||||
|
||||
BBStr *bbString( BBStr *s,int n ){
|
||||
BBStr *t=d_new BBStr();
|
||||
while( n-->0 ) *t+=*s;
|
||||
delete s;return t;
|
||||
}
|
||||
|
||||
BBStr *bbLeft( BBStr *s,int n ){
|
||||
CHKPOS( n );
|
||||
*s=s->substr( 0,n );return s;
|
||||
}
|
||||
|
||||
BBStr *bbRight( BBStr *s,int n ){
|
||||
CHKPOS( n );
|
||||
n=s->size()-n;if( n<0 ) n=0;
|
||||
*s=s->substr( n );return s;
|
||||
}
|
||||
|
||||
BBStr *bbReplace( BBStr *s,BBStr *from,BBStr *to ){
|
||||
int n=0,from_sz=from->size(),to_sz=to->size();
|
||||
while( n<s->size() && (n=s->find( *from,n ))!=string::npos ){
|
||||
s->replace( n,from_sz,*to );
|
||||
n+=to_sz;
|
||||
}
|
||||
delete from;delete to;return s;
|
||||
}
|
||||
|
||||
int bbInstr( BBStr *s,BBStr *t,int from ){
|
||||
CHKOFF( from );--from;
|
||||
int n=s->find( *t,from );
|
||||
delete s;delete t;
|
||||
return n==string::npos ? 0 : n+1;
|
||||
}
|
||||
|
||||
BBStr *bbMid( BBStr *s,int o,int n ){
|
||||
CHKOFF( o );--o;
|
||||
if( o>s->size() ) o=s->size();
|
||||
if( n>=0 ) *s=s->substr( o,n );
|
||||
else *s=s->substr( o );
|
||||
return s;
|
||||
}
|
||||
|
||||
BBStr *bbUpper( BBStr *s ){
|
||||
for( int k=0;k<s->size();++k ) (*s)[k]=toupper( (*s)[k] );
|
||||
return s;
|
||||
}
|
||||
|
||||
BBStr *bbLower( BBStr *s ){
|
||||
for( int k=0;k<s->size();++k ) (*s)[k]=tolower( (*s)[k] );
|
||||
return s;
|
||||
}
|
||||
|
||||
BBStr *bbTrim( BBStr *s ){
|
||||
int n=0,p=s->size();
|
||||
while( n<s->size() && !isgraph( (*s)[n] ) ) ++n;
|
||||
while( p>n && !isgraph( (*s)[p-1] ) ) --p;
|
||||
*s=s->substr( n,p-n );return s;
|
||||
}
|
||||
|
||||
BBStr *bbLSet( BBStr *s,int n ){
|
||||
CHKPOS(n);
|
||||
if( s->size()>n ) *s=s->substr( 0,n );
|
||||
else{
|
||||
while( s->size()<n ) *s+=' ';
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
BBStr *bbRSet( BBStr *s,int n ){
|
||||
CHKPOS(n);
|
||||
if( s->size()>n ) *s=s->substr( s->size()-n );
|
||||
else{
|
||||
while( s->size()<n ) *s=' '+*s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
BBStr *bbChr( int n ){
|
||||
BBStr *t=d_new BBStr();
|
||||
*t+=(char)n;return t;
|
||||
}
|
||||
|
||||
BBStr *bbHex( int n ){
|
||||
char buff[12];
|
||||
for( int k=7;k>=0;n>>=4,--k ){
|
||||
int t=(n&15)+'0';
|
||||
buff[k]=t>'9' ? t+='A'-'9'-1 : t;
|
||||
}
|
||||
buff[8]=0;
|
||||
return d_new BBStr( buff );
|
||||
}
|
||||
|
||||
BBStr *bbBin( int n ){
|
||||
char buff[36];
|
||||
for( int k=31;k>=0;n>>=1,--k ){
|
||||
buff[k]=n&1 ? '1' : '0';
|
||||
}
|
||||
buff[32]=0;
|
||||
return d_new BBStr( buff );
|
||||
}
|
||||
|
||||
int bbAsc( BBStr *s ){
|
||||
int n=s->size() ? (*s)[0] & 255 : -1;
|
||||
delete s;return n;
|
||||
}
|
||||
|
||||
int bbLen( BBStr *s ){
|
||||
int n=s->size();
|
||||
delete s;return n;
|
||||
}
|
||||
|
||||
BBStr *bbCurrentDate(){
|
||||
time_t t;
|
||||
time( &t );
|
||||
char buff[256];
|
||||
strftime( buff,256,"%d %b %Y",localtime( &t ) );
|
||||
return d_new BBStr( buff );
|
||||
}
|
||||
|
||||
BBStr *bbCurrentTime(){
|
||||
time_t t;
|
||||
time( &t );
|
||||
char buff[256];
|
||||
strftime( buff,256,"%H:%M:%S",localtime( &t ) );
|
||||
return d_new BBStr( buff );
|
||||
}
|
||||
|
||||
bool string_create(){
|
||||
return true;
|
||||
}
|
||||
|
||||
bool string_destroy(){
|
||||
return true;
|
||||
}
|
||||
|
||||
void string_link( void(*rtSym)(const char*,void*) ){
|
||||
rtSym( "$String$string%repeat",bbString );
|
||||
rtSym( "$Left$string%count",bbLeft );
|
||||
rtSym( "$Right$string%count",bbRight );
|
||||
rtSym( "$Replace$string$from$to",bbReplace );
|
||||
rtSym( "%Instr$string$find%from=1",bbInstr );
|
||||
rtSym( "$Mid$string%start%count=-1",bbMid );
|
||||
rtSym( "$Upper$string",bbUpper );
|
||||
rtSym( "$Lower$string",bbLower );
|
||||
rtSym( "$Trim$string",bbTrim );
|
||||
rtSym( "$LSet$string%size",bbLSet );
|
||||
rtSym( "$RSet$string%size",bbRSet );
|
||||
rtSym( "$Chr%ascii",bbChr );
|
||||
rtSym( "%Asc$string",bbAsc );
|
||||
rtSym( "%Len$string",bbLen );
|
||||
rtSym( "$Hex%value",bbHex );
|
||||
rtSym( "$Bin%value",bbBin );
|
||||
rtSym( "$CurrentDate",bbCurrentDate );
|
||||
rtSym( "$CurrentTime",bbCurrentTime );
|
||||
}
|
26
bbruntime/bbstring.h
Normal file
26
bbruntime/bbstring.h
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
#ifndef BBSTRING_H
|
||||
#define BBSTRING_H
|
||||
|
||||
#include "basic.h"
|
||||
|
||||
BBStr * bbString( BBStr *s,int n );
|
||||
BBStr * bbLeft( BBStr *s,int n );
|
||||
BBStr * bbRight( BBStr *s,int n );
|
||||
BBStr * bbReplace( BBStr *s,BBStr *from,BBStr *to );
|
||||
int bbInstr( BBStr *s,BBStr *t,int from );
|
||||
BBStr * bbMid( BBStr *s,int o,int n );
|
||||
BBStr * bbUpper( BBStr *s );
|
||||
BBStr * bbLower( BBStr *s );
|
||||
BBStr * bbTrim( BBStr *s );
|
||||
BBStr * bbLSet( BBStr *s,int n );
|
||||
BBStr * bbRSet( BBStr *s,int n );
|
||||
BBStr * bbChr( int n );
|
||||
int bbAsc( BBStr *s );
|
||||
int bbLen( BBStr *s );
|
||||
BBStr * bbHex( int n );
|
||||
BBStr * bbBin( int n );
|
||||
BBStr * bbCurrentDate();
|
||||
BBStr * bbCurrentTime();
|
||||
|
||||
#endif
|
6
bbruntime/bbsys.cpp
Normal file
6
bbruntime/bbsys.cpp
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
|
||||
bool debug;
|
||||
gxRuntime *gx_runtime;
|
20
bbruntime/bbsys.h
Normal file
20
bbruntime/bbsys.h
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
#ifndef BBSYS_H
|
||||
#define BBSYS_H
|
||||
|
||||
#include "basic.h"
|
||||
#include "../gxruntime/gxruntime.h"
|
||||
|
||||
extern bool debug;
|
||||
extern gxRuntime *gx_runtime;
|
||||
|
||||
struct bbEx{
|
||||
const char *err;
|
||||
bbEx( const char *e ):err(e){
|
||||
if( e ) gx_runtime->debugError( e );
|
||||
}
|
||||
};
|
||||
|
||||
#define RTEX( _X_ ) throw bbEx( _X_ );
|
||||
|
||||
#endif
|
309
bbruntime/multiplay.cpp
Normal file
309
bbruntime/multiplay.cpp
Normal file
@ -0,0 +1,309 @@
|
||||
|
||||
/*
|
||||
|
||||
Note - does not appear to like DPSESSION_MULTICASTSERVER very much!
|
||||
|
||||
*/
|
||||
|
||||
#include "std.h"
|
||||
#include "multiplay.h"
|
||||
#include "multiplay_setup.h"
|
||||
|
||||
struct Player;
|
||||
|
||||
static bool host;
|
||||
|
||||
static map<DPID,Player*> player_map;
|
||||
static list<Player*> players,new_players;
|
||||
|
||||
static int msg_type;
|
||||
static string msg_data;
|
||||
static DPID msg_from,msg_to;
|
||||
|
||||
static char *recv_buff;
|
||||
static int recv_buff_sz;
|
||||
|
||||
static char *send_buff;
|
||||
static int send_buff_sz;
|
||||
|
||||
#pragma pack( push,1 )
|
||||
struct bbMsg{
|
||||
DPID from,to;
|
||||
char type;
|
||||
};
|
||||
#pragma pack( pop )
|
||||
|
||||
struct Player{
|
||||
DPID id;
|
||||
string name;
|
||||
bool remote;
|
||||
|
||||
Player( DPID i,const string &n,bool r ):id(i),name(n),remote(r){
|
||||
players.push_back( this );
|
||||
if( remote ) new_players.push_back( this );
|
||||
player_map.clear();
|
||||
}
|
||||
|
||||
Player::~Player(){
|
||||
new_players.remove( this );
|
||||
players.remove( this );
|
||||
player_map.clear();
|
||||
}
|
||||
};
|
||||
|
||||
static void chk(){
|
||||
if( !dirPlay ){
|
||||
RTEX( "Multiplayer game not started" );
|
||||
}
|
||||
}
|
||||
|
||||
static void clearPlayers(){
|
||||
while( players.size() ) delete players.back();
|
||||
new_players.clear();
|
||||
player_map.clear();
|
||||
}
|
||||
|
||||
static Player *findPlayer( DPID id ){
|
||||
if( !player_map.size() ){
|
||||
list<Player*>::iterator it;
|
||||
for( it=players.begin();it!=players.end();++it ){
|
||||
player_map.insert( pair<DPID,Player*>( (*it)->id,(*it) ) );
|
||||
}
|
||||
}
|
||||
map<DPID,Player*>::iterator it=player_map.find( id );
|
||||
return it==player_map.end() ? 0 : it->second;
|
||||
}
|
||||
|
||||
static BOOL FAR PASCAL enumPlayer( DPID id,DWORD type,LPCDPNAME name,DWORD flags,LPVOID context ){
|
||||
Player *p=findPlayer( id );if( p ) return TRUE;
|
||||
p=d_new Player( id,string( name->lpszShortNameA ),true );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void multiplay_link( void(*rtSym)(const char*,void*) ){
|
||||
rtSym( "%StartNetGame",bbStartNetGame );
|
||||
rtSym( "%HostNetGame$game_name",bbHostNetGame );
|
||||
rtSym( "%JoinNetGame$game_name$ip_address",bbJoinNetGame );
|
||||
rtSym( "StopNetGame",bbStopNetGame );
|
||||
|
||||
rtSym( "%CreateNetPlayer$name",bbCreateNetPlayer );
|
||||
rtSym( "DeleteNetPlayer%player",bbDeleteNetPlayer );
|
||||
rtSym( "$NetPlayerName%player",bbNetPlayerName );
|
||||
rtSym( "%NetPlayerLocal%player",bbNetPlayerLocal );
|
||||
|
||||
rtSym( "%SendNetMsg%type$msg%from_player%to_player=0%reliable=1",bbSendNetMsg );
|
||||
|
||||
rtSym( "%RecvNetMsg",bbRecvNetMsg );
|
||||
rtSym( "%NetMsgType",bbNetMsgType );
|
||||
rtSym( "%NetMsgFrom",bbNetMsgFrom );
|
||||
rtSym( "%NetMsgTo",bbNetMsgTo );
|
||||
rtSym( "$NetMsgData",bbNetMsgData );
|
||||
}
|
||||
|
||||
bool multiplay_create(){
|
||||
|
||||
recv_buff_sz=send_buff_sz=1024;
|
||||
recv_buff=d_new char[recv_buff_sz];
|
||||
send_buff=d_new char[send_buff_sz];
|
||||
|
||||
multiplay_setup_create();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool multiplay_destroy(){
|
||||
|
||||
bbStopNetGame();
|
||||
|
||||
multiplay_setup_destroy();
|
||||
|
||||
delete[] recv_buff;recv_buff=0;
|
||||
delete[] send_buff;send_buff=0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int startGame( int n ){
|
||||
clearPlayers();
|
||||
if( !n ) return 0;
|
||||
if( dirPlay->EnumPlayers( 0,enumPlayer,0,0 )>=0 ){
|
||||
host=n==2;
|
||||
return n;
|
||||
}
|
||||
multiplay_setup_close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bbStartNetGame(){
|
||||
if( dirPlay ){
|
||||
RTEX( "Multiplayer game already started" );
|
||||
}
|
||||
return startGame( multiplay_setup_open() );
|
||||
}
|
||||
|
||||
int bbHostNetGame( BBStr *name ){
|
||||
if( dirPlay ){
|
||||
RTEX( "Multiplayer game already started" );
|
||||
}
|
||||
string n=*name;delete name;
|
||||
return startGame( multiplay_setup_host( n ) );
|
||||
}
|
||||
|
||||
int bbJoinNetGame( BBStr *name,BBStr *address ){
|
||||
if( dirPlay ){
|
||||
RTEX( "Multiplayer game already started" );
|
||||
}
|
||||
string n=*name,a=*address;delete name;delete address;
|
||||
return startGame( multiplay_setup_join( n,a ) );
|
||||
}
|
||||
|
||||
void bbStopNetGame(){
|
||||
multiplay_setup_close();
|
||||
clearPlayers();
|
||||
}
|
||||
|
||||
DPID bbCreateNetPlayer( BBStr *nm ){
|
||||
chk();
|
||||
|
||||
string t=*nm;
|
||||
string t0=t+'\0';
|
||||
delete nm;
|
||||
|
||||
DPID id;
|
||||
DPNAME name;
|
||||
memset( &name,0,sizeof( name ) );
|
||||
name.dwSize=sizeof(name);name.lpszShortNameA=(char*)t0.data();
|
||||
|
||||
if( dirPlay->CreatePlayer( &id,&name,0,0,0,0 )<0 ) return 0;
|
||||
|
||||
Player *p=d_new Player( id,t,false );
|
||||
|
||||
if( players.size()==1 ){
|
||||
if( dirPlay->EnumPlayers( 0,enumPlayer,0,0 )<0 ){
|
||||
dirPlay->DestroyPlayer( id );
|
||||
delete p;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
void bbDeleteNetPlayer( DPID player ){
|
||||
chk();
|
||||
|
||||
if( Player *p=findPlayer( player ) ){
|
||||
dirPlay->DestroyPlayer( player );
|
||||
delete p;
|
||||
}
|
||||
}
|
||||
|
||||
BBStr *bbNetPlayerName( DPID player ){
|
||||
if( !player ) return d_new BBStr( "<all>" );
|
||||
Player *p=findPlayer( player );
|
||||
return d_new BBStr( p ? p->name : "<unknown>" );
|
||||
}
|
||||
|
||||
int bbNetPlayerLocal( DPID player ){
|
||||
if( Player *p=findPlayer( player ) ) return p->remote ? 0 : 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bbRecvNetMsg(){
|
||||
chk();
|
||||
|
||||
msg_type=0;
|
||||
msg_data.resize(0);
|
||||
msg_from=DPID_UNKNOWN;msg_to=DPID_ALLPLAYERS;
|
||||
|
||||
while( !msg_type ){
|
||||
|
||||
if( new_players.size() ){
|
||||
msg_from=new_players.front()->id;
|
||||
new_players.pop_front();
|
||||
msg_type=100;
|
||||
return 1;
|
||||
}
|
||||
|
||||
DPID from,to;
|
||||
DWORD sz=recv_buff_sz;
|
||||
int n=dirPlay->Receive( &from,&to,0,recv_buff,&sz );
|
||||
|
||||
if( n==DPERR_BUFFERTOOSMALL ){
|
||||
sz=recv_buff_sz=sz/2+sz;
|
||||
delete[] recv_buff;recv_buff=d_new char[recv_buff_sz];
|
||||
n=dirPlay->Receive( &from,&to,0,recv_buff,&sz );
|
||||
}
|
||||
|
||||
if( n!=DP_OK ) return 0;
|
||||
|
||||
if( from==DPID_SYSMSG ){
|
||||
switch( *(DWORD*)recv_buff ){
|
||||
case DPSYS_CREATEPLAYERORGROUP:
|
||||
if( DPMSG_CREATEPLAYERORGROUP *msg=(DPMSG_CREATEPLAYERORGROUP*)recv_buff ){
|
||||
if( findPlayer( from=msg->dpId ) ) continue;
|
||||
d_new Player( from,string( msg->dpnName.lpszShortNameA ),true );
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case DPSYS_DESTROYPLAYERORGROUP:
|
||||
if( DPMSG_DESTROYPLAYERORGROUP *msg=(DPMSG_DESTROYPLAYERORGROUP*)recv_buff ){
|
||||
Player *p=findPlayer( msg->dpId );if( !p ) continue;
|
||||
delete p;msg_from=msg->dpId;msg_type=101;
|
||||
}
|
||||
break;
|
||||
case DPSYS_HOST:
|
||||
if( !host ){
|
||||
host=true;msg_type=102;
|
||||
}
|
||||
break;
|
||||
case DPSYS_SESSIONLOST:
|
||||
msg_type=200;
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
bbMsg *m=(bbMsg*)recv_buff;
|
||||
Player *p=findPlayer( m->from );
|
||||
if( p && !p->remote ) continue;
|
||||
msg_data=string( (char*)(m+1),sz-sizeof(bbMsg) );
|
||||
msg_from=m->from;msg_to=m->to;
|
||||
msg_type=m->type;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int bbNetMsgType(){
|
||||
return msg_type;
|
||||
}
|
||||
|
||||
BBStr *bbNetMsgData(){
|
||||
return d_new BBStr( msg_data );
|
||||
}
|
||||
|
||||
DPID bbNetMsgFrom(){
|
||||
return msg_from;
|
||||
}
|
||||
|
||||
DPID bbNetMsgTo(){
|
||||
return msg_to;
|
||||
}
|
||||
|
||||
int bbSendNetMsg( int type,BBStr *msg,DPID from,DPID to,int reliable ){
|
||||
chk();
|
||||
|
||||
int sz=msg->size()+sizeof(bbMsg);
|
||||
if( sz>send_buff_sz ){
|
||||
send_buff_sz=sz/2+sz;
|
||||
delete send_buff;send_buff=d_new char[send_buff_sz];
|
||||
}
|
||||
bbMsg *m=(bbMsg*)send_buff;
|
||||
m->type=type;m->from=from;m->to=to;
|
||||
|
||||
memcpy( m+1,msg->data(),msg->size() );
|
||||
|
||||
if( !to ) to=DPID_ALLPLAYERS;
|
||||
int n=dirPlay->Send( from,to,reliable ? DPSEND_GUARANTEED : 0,send_buff,sz );
|
||||
delete msg;
|
||||
|
||||
return n>=0;
|
||||
}
|
30
bbruntime/multiplay.h
Normal file
30
bbruntime/multiplay.h
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
#ifndef MULTIPLAY_H
|
||||
#define MULTIPLAY_H
|
||||
|
||||
#include "bbsys.h"
|
||||
#include <dplay.h>
|
||||
|
||||
void multiplay_link();
|
||||
bool multiplay_create();
|
||||
bool multiplay_destroy();
|
||||
|
||||
int bbStartNetGame();
|
||||
int bbHostNetGame( BBStr *name );
|
||||
int bbJoinNetGame( BBStr *name,BBStr *address );
|
||||
void bbStopNetGame();
|
||||
|
||||
DPID bbCreateNetPlayer( BBStr *name );
|
||||
void bbDeleteNetPlayer( DPID player );
|
||||
BBStr * bbNetPlayerName( DPID player );
|
||||
int bbNetPlayerLocal( DPID player );
|
||||
|
||||
int bbSendNetMsg( int type,BBStr *msg,DPID from,DPID to,int reliable );
|
||||
|
||||
int bbRecvNetMsg();
|
||||
int bbNetMsgType();
|
||||
BBStr * bbNetMsgData();
|
||||
DPID bbNetMsgFrom();
|
||||
DPID bbNetMsgTo();
|
||||
|
||||
#endif
|
381
bbruntime/multiplay_setup.cpp
Normal file
381
bbruntime/multiplay_setup.cpp
Normal file
@ -0,0 +1,381 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
#include "resource.h"
|
||||
#include "multiplay_setup.h"
|
||||
|
||||
IDirectPlay4 *dirPlay;
|
||||
|
||||
struct Connection{
|
||||
GUID guid;
|
||||
string name;
|
||||
void *data;
|
||||
|
||||
Connection( const GUID &g,const string &n,void *d,int sz ):guid(g),name(n){
|
||||
data=d_new char[sz];memcpy( data,d,sz );
|
||||
}
|
||||
|
||||
~Connection(){
|
||||
delete[] data;
|
||||
}
|
||||
};
|
||||
|
||||
struct Session{
|
||||
GUID guid;
|
||||
string name;
|
||||
int max_players,curr_players,data1,data2;
|
||||
|
||||
Session( const DPSESSIONDESC2 *desc ){
|
||||
guid=desc->guidInstance;
|
||||
name=string( desc->lpszSessionNameA );
|
||||
max_players=desc->dwMaxPlayers;
|
||||
curr_players=desc->dwCurrentPlayers;
|
||||
data1=desc->dwUser1;data2=desc->dwUser2;
|
||||
}
|
||||
};
|
||||
|
||||
static int timer;
|
||||
static vector<Connection*> connections;
|
||||
static vector<Session*> sessions;
|
||||
|
||||
static void clearSessions(){
|
||||
for( ;sessions.size();sessions.pop_back() ) delete sessions.back();
|
||||
}
|
||||
|
||||
static void clearConnections(){
|
||||
for( ;connections.size();connections.pop_back() ) delete connections.back();
|
||||
}
|
||||
|
||||
static bool openDirPlay( HWND hwnd ){
|
||||
if( dirPlay ) return true;
|
||||
if( CoCreateInstance( CLSID_DirectPlay,0,CLSCTX_ALL,IID_IDirectPlay4A,(void**)&dirPlay )>=0 ) return true;
|
||||
MessageBox( hwnd,"Error opening DirectPlay","DirectPlay Error",MB_ICONWARNING );
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool closeDirPlay( HWND hwnd ){
|
||||
if( hwnd && timer ) KillTimer( hwnd,timer );
|
||||
timer=0;if( !dirPlay ) return true;
|
||||
dirPlay->Close();
|
||||
int n=dirPlay->Release();
|
||||
dirPlay=0;return n==0;
|
||||
}
|
||||
|
||||
static BOOL FAR PASCAL enumConnection( LPCGUID guid,LPVOID conn,DWORD size,LPCDPNAME name,DWORD flags,LPVOID context ){
|
||||
IDirectPlay4 *dp;
|
||||
if( CoCreateInstance( CLSID_DirectPlay,0,CLSCTX_ALL,IID_IDirectPlay4A,(void**)&dp )<0 ) return FALSE;
|
||||
int n=dp->InitializeConnection( conn,0 );
|
||||
dp->Release();if( n<0 ) return TRUE;
|
||||
|
||||
Connection *c=d_new Connection( *guid,string( strdup( name->lpszShortNameA ) ),conn,size );
|
||||
connections.push_back( c );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL FAR PASCAL enumSession( LPCDPSESSIONDESC2 desc,LPDWORD timeout,DWORD flags,LPVOID lpContext ){
|
||||
|
||||
if( !desc ) return FALSE;
|
||||
sessions.push_back( d_new Session( desc ) );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static bool startGame( HWND hwnd ){
|
||||
if( !dirPlay ) return false;
|
||||
|
||||
char buff[MAX_PATH];
|
||||
int n=GetWindowText( GetDlgItem( hwnd,IDC_GAMENAME ),buff,MAX_PATH );
|
||||
if( !n ){
|
||||
MessageBox( hwnd,"Please enter a name for the new game","DirectPlay Request",MB_SETFOREGROUND|MB_TOPMOST|MB_ICONINFORMATION|MB_OK );
|
||||
return false;
|
||||
}
|
||||
|
||||
string name=string( buff )+'\0';
|
||||
|
||||
DPSESSIONDESC2 desc;
|
||||
memset(&desc,0,sizeof(desc));
|
||||
desc.dwSize=sizeof(desc);
|
||||
desc.guidApplication=GUID_NULL;
|
||||
desc.dwFlags=
|
||||
DPSESSION_KEEPALIVE|
|
||||
DPSESSION_MIGRATEHOST|
|
||||
DPSESSION_NOMESSAGEID|
|
||||
DPSESSION_OPTIMIZELATENCY|
|
||||
DPSESSION_DIRECTPLAYPROTOCOL;
|
||||
desc.lpszSessionNameA=(char*)name.data();
|
||||
|
||||
if( dirPlay->Open( &desc,DPOPEN_CREATE )<0 ){
|
||||
MessageBox( hwnd,"Unable to create new game","DirPlay Error",MB_ICONWARNING );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool joinGame( HWND hwnd ){
|
||||
if( !dirPlay ) return false;
|
||||
|
||||
int ses=SendDlgItemMessage( hwnd,IDC_GAMELIST,LB_GETCURSEL,0,0 );
|
||||
if( ses<0 || ses>=sessions.size() ) return false;
|
||||
|
||||
DPSESSIONDESC2 desc;
|
||||
memset(&desc,0,sizeof(desc));
|
||||
desc.dwSize=sizeof(desc);
|
||||
desc.guidInstance=sessions[ses]->guid;
|
||||
|
||||
if( dirPlay->Open( &desc,DPOPEN_JOIN )<0 ){
|
||||
MessageBox( hwnd,"Unable to join game","DirPlay Error",MB_ICONWARNING );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool enumSessions( HWND hwnd ){
|
||||
if( !dirPlay ) return false;
|
||||
|
||||
clearSessions();
|
||||
EnableWindow( GetDlgItem( hwnd,IDC_GAMELIST ),true );
|
||||
SendDlgItemMessage( hwnd,IDC_GAMELIST,LB_RESETCONTENT,0,0 );
|
||||
|
||||
DPSESSIONDESC2 desc;
|
||||
memset(&desc,0,sizeof(desc));
|
||||
desc.dwSize=sizeof(desc);
|
||||
desc.guidApplication=GUID_NULL;
|
||||
|
||||
int n=dirPlay->EnumSessions( &desc,0,enumSession,0,DPENUMSESSIONS_ASYNC );
|
||||
if( n>=0 ){
|
||||
if( !timer ) SetTimer( hwnd,timer=1,1000,0 );
|
||||
for( int k=0;k<sessions.size();++k ){
|
||||
SendDlgItemMessage( hwnd,IDC_GAMELIST,LB_ADDSTRING,0,(LPARAM)strdup( sessions[k]->name.c_str() ) );
|
||||
}
|
||||
if( !sessions.size() ){
|
||||
SendDlgItemMessage( hwnd,IDC_GAMELIST,LB_ADDSTRING,0,(LPARAM)"<no games found>" );
|
||||
EnableWindow( GetDlgItem( hwnd,IDC_GAMELIST ),false );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
closeDirPlay( hwnd );
|
||||
if( n==DPERR_USERCANCEL ) return false;
|
||||
MessageBox( hwnd,"Unable to enumerate sessions","DirPlay Error",MB_ICONWARNING );
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool connect( HWND hwnd ){
|
||||
int con=SendDlgItemMessage( hwnd,IDC_CONNECTIONS,CB_GETCURSEL,0,0 );
|
||||
if( con<1 || con>=connections.size() ) return false;
|
||||
|
||||
closeDirPlay( hwnd );
|
||||
if( openDirPlay( hwnd ) ){
|
||||
int n=dirPlay->InitializeConnection( connections[con]->data,0 );
|
||||
if( n>=0 ){
|
||||
if( enumSessions( hwnd ) ) return true;
|
||||
}else{
|
||||
if( n!=DPERR_USERCANCEL ){
|
||||
string t="Unable to open "+connections[con]->name;
|
||||
MessageBox( hwnd,t.c_str(),"DirPlay Error",MB_ICONWARNING );
|
||||
}
|
||||
}
|
||||
closeDirPlay( hwnd );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void endDialog( HWND hwnd,int rc ){
|
||||
if( timer ) KillTimer( hwnd,timer );
|
||||
timer=0;
|
||||
if( !rc ) closeDirPlay( hwnd );
|
||||
EndDialog( hwnd,rc );
|
||||
}
|
||||
|
||||
static BOOL CALLBACK dialogProc( HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam ){
|
||||
|
||||
int k,lo=LOWORD(wparam),hi=HIWORD(wparam);
|
||||
|
||||
bool reset=false;
|
||||
|
||||
switch( msg ){
|
||||
case WM_INITDIALOG:
|
||||
SetForegroundWindow( hwnd );
|
||||
clearConnections();
|
||||
connections.push_back( d_new Connection( GUID_NULL,"<no connection>","",0 ) );
|
||||
if( openDirPlay( hwnd ) ){
|
||||
if( dirPlay->EnumConnections( 0,enumConnection,0,0 )<0 ){
|
||||
MessageBox( hwnd,"Failed to enumerate connections","DirectPlay Error",MB_SETFOREGROUND|MB_TOPMOST|MB_ICONWARNING|MB_OK );
|
||||
}
|
||||
closeDirPlay( hwnd );
|
||||
}
|
||||
for( k=0;k<connections.size();++k ){
|
||||
string t=connections[k]->name;
|
||||
SendDlgItemMessage( hwnd,IDC_CONNECTIONS,CB_ADDSTRING,0,(LPARAM)t.c_str() );
|
||||
}
|
||||
timer=0;
|
||||
reset=true;
|
||||
break;
|
||||
case WM_TIMER: //refresh sessions list!
|
||||
if( timer && wparam==timer && !enumSessions( hwnd ) ) reset=true;
|
||||
break;
|
||||
case WM_CLOSE:
|
||||
endDialog( hwnd,0 );
|
||||
break;
|
||||
case WM_COMMAND:
|
||||
switch( hi ){
|
||||
case BN_CLICKED:
|
||||
switch( lo ){
|
||||
case IDC_CANCEL:
|
||||
endDialog( hwnd,0 );
|
||||
break;
|
||||
case IDC_GAMENAME:case IDC_HOSTGAME:
|
||||
if( startGame( hwnd ) ){
|
||||
endDialog( hwnd,2 );
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case LBN_DBLCLK:
|
||||
switch( lo ){
|
||||
case IDC_GAMELIST:
|
||||
if( joinGame( hwnd ) ){
|
||||
endDialog( hwnd,1 );
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case CBN_SELCHANGE:
|
||||
switch( lo ){
|
||||
case IDC_CONNECTIONS:
|
||||
if( connect( hwnd ) ){
|
||||
EnableWindow( GetDlgItem( hwnd,IDC_GAMENAME ),true );
|
||||
EnableWindow( GetDlgItem( hwnd,IDC_HOSTGAME ),true );
|
||||
break;
|
||||
}else{
|
||||
reset=true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( reset ){
|
||||
closeDirPlay( hwnd );
|
||||
SendDlgItemMessage( hwnd,IDC_CONNECTIONS,CB_SETCURSEL,0,0 );
|
||||
EnableWindow( GetDlgItem( hwnd,IDC_GAMELIST ),false );
|
||||
EnableWindow( GetDlgItem( hwnd,IDC_HOSTGAME ),false );
|
||||
EnableWindow( GetDlgItem( hwnd,IDC_GAMENAME ),false );
|
||||
SetWindowText( GetDlgItem( hwnd,IDC_GAMENAME ),"" );
|
||||
SendDlgItemMessage( hwnd,IDC_GAMELIST,LB_RESETCONTENT,0,0 );
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void multiplay_setup_create(){
|
||||
dirPlay=0;
|
||||
}
|
||||
|
||||
void multiplay_setup_destroy(){
|
||||
multiplay_setup_close();
|
||||
}
|
||||
|
||||
int multiplay_setup_open(){
|
||||
gx_runtime->idle();
|
||||
|
||||
int n=DialogBox( GetModuleHandle( "runtime" ),MAKEINTRESOURCE( IDD_MULTIPLAYER ),GetDesktopWindow(),dialogProc );
|
||||
|
||||
if( n!=1 && n!=2 ) n=0;
|
||||
|
||||
clearSessions();
|
||||
clearConnections();
|
||||
|
||||
//NAUGHTY!
|
||||
gx_runtime->asyncRun();
|
||||
gx_runtime->idle();
|
||||
return n;
|
||||
}
|
||||
|
||||
void multiplay_setup_close(){
|
||||
closeDirPlay( 0 );
|
||||
}
|
||||
|
||||
int multiplay_setup_host( const string &game_name ){
|
||||
int ret=0;
|
||||
IDirectPlayLobby *lobby;
|
||||
IDirectPlayLobby3 *lobby3;
|
||||
if( CoCreateInstance( CLSID_DirectPlay,0,CLSCTX_ALL,IID_IDirectPlay4A,(void**)&dirPlay )>=0 ){
|
||||
if( DirectPlayLobbyCreate( 0,&lobby,0,0,0 )>=0 ){
|
||||
if( lobby->QueryInterface( IID_IDirectPlayLobby3,(void**)&lobby3 )>=0 ){
|
||||
//ok, create an address for initializeconnection
|
||||
string ip( "\0" );
|
||||
char address[256];DWORD sz=256;
|
||||
if( lobby3->CreateAddress( DPSPGUID_TCPIP,DPAID_INet,ip.data(),ip.size(),address,&sz )>=0 ){
|
||||
if( dirPlay->InitializeConnection( address,0 )>=0 ){
|
||||
string name=game_name+'\0';
|
||||
DPSESSIONDESC2 desc;
|
||||
memset(&desc,0,sizeof(desc));
|
||||
desc.dwSize=sizeof(desc);
|
||||
desc.guidApplication=GUID_NULL;
|
||||
desc.dwFlags=
|
||||
DPSESSION_KEEPALIVE|
|
||||
DPSESSION_MIGRATEHOST|
|
||||
DPSESSION_NOMESSAGEID|
|
||||
DPSESSION_OPTIMIZELATENCY|
|
||||
DPSESSION_DIRECTPLAYPROTOCOL;
|
||||
desc.lpszSessionNameA=(char*)name.data();
|
||||
if( dirPlay->Open( &desc,DPOPEN_CREATE )>=0 ){
|
||||
ret=2;
|
||||
}
|
||||
}
|
||||
}
|
||||
lobby3->Release();
|
||||
}
|
||||
lobby->Release();
|
||||
}
|
||||
if( !ret ){
|
||||
dirPlay->Release();
|
||||
dirPlay=0;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int multiplay_setup_join( const string &game_name,const string &ip_add ){
|
||||
int ret=0;
|
||||
IDirectPlayLobby *lobby;
|
||||
IDirectPlayLobby3 *lobby3;
|
||||
if( CoCreateInstance( CLSID_DirectPlay,0,CLSCTX_ALL,IID_IDirectPlay4A,(void**)&dirPlay )>=0 ){
|
||||
if( DirectPlayLobbyCreate( 0,&lobby,0,0,0 )>=0 ){
|
||||
if( lobby->QueryInterface( IID_IDirectPlayLobby3,(void**)&lobby3 )>=0 ){
|
||||
//ok, create an address for initializeconnection
|
||||
string ip=ip_add+'\0';
|
||||
char address[256];DWORD sz=256;
|
||||
if( lobby3->CreateAddress( DPSPGUID_TCPIP,DPAID_INet,ip.data(),ip.size(),address,&sz )>=0 ){
|
||||
if( dirPlay->InitializeConnection( address,0 )>=0 ){
|
||||
DPSESSIONDESC2 desc;
|
||||
memset(&desc,0,sizeof(desc));
|
||||
desc.dwSize=sizeof(desc);
|
||||
desc.guidApplication=GUID_NULL;
|
||||
if( dirPlay->EnumSessions( &desc,0,enumSession,0,0 )>=0 ){
|
||||
for( int k=0;k<sessions.size();++k ){
|
||||
if( sessions[k]->name!=game_name ) continue;
|
||||
desc.guidInstance=sessions[k]->guid;
|
||||
if( dirPlay->Open( &desc,DPOPEN_JOIN )>=0 ){
|
||||
ret=1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
clearSessions();
|
||||
}
|
||||
}
|
||||
lobby3->Release();
|
||||
}
|
||||
lobby->Release();
|
||||
}
|
||||
if( !ret ){
|
||||
dirPlay->Release();
|
||||
dirPlay=0;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
18
bbruntime/multiplay_setup.h
Normal file
18
bbruntime/multiplay_setup.h
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
#ifndef MULTIPLAY_SETUP_H
|
||||
#define MULTIPLAY_SETUP_H
|
||||
|
||||
#include <dplay.h>
|
||||
#include <dplobby.h>
|
||||
|
||||
extern IDirectPlay4 *dirPlay;
|
||||
|
||||
void multiplay_setup_create();
|
||||
void multiplay_setup_destroy();
|
||||
|
||||
int multiplay_setup_open();
|
||||
int multiplay_setup_host( const string &game_name );
|
||||
int multiplay_setup_join( const string &game_name,const string &ip_add );
|
||||
void multiplay_setup_close();
|
||||
|
||||
#endif
|
107
bbruntime/multiplay_setup.rc
Normal file
107
bbruntime/multiplay_setup.rc
Normal file
@ -0,0 +1,107 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Dialog
|
||||
//
|
||||
|
||||
IDD_MULTIPLAYER DIALOG DISCARDABLE 0, 0, 190, 199
|
||||
STYLE DS_MODALFRAME | DS_SETFOREGROUND | DS_CENTER | WS_POPUP | WS_VISIBLE |
|
||||
WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Start Multiplayer Game"
|
||||
FONT 8, "MS Sans Serif"
|
||||
BEGIN
|
||||
PUSHBUTTON "Cancel",IDC_CANCEL,135,178,45,14
|
||||
PUSHBUTTON "Create new game",IDC_HOSTGAME,10,178,67,14
|
||||
EDITTEXT IDC_GAMENAME,10,155,170,12,ES_AUTOHSCROLL |
|
||||
ES_WANTRETURN
|
||||
LISTBOX IDC_GAMELIST,10,53,170,82,LBS_NOINTEGRALHEIGHT |
|
||||
WS_VSCROLL | WS_TABSTOP
|
||||
COMBOBOX IDC_CONNECTIONS,10,22,170,60,CBS_DROPDOWNLIST |
|
||||
WS_VSCROLL | WS_TABSTOP
|
||||
LTEXT "Connection",IDC_STATIC,10,11,170,8
|
||||
LTEXT "Games in progress",IDC_STATIC,10,42,170,8
|
||||
LTEXT "Name for new game",IDC_STATIC,10,144,170,8
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DESIGNINFO
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
GUIDELINES DESIGNINFO DISCARDABLE
|
||||
BEGIN
|
||||
IDD_MULTIPLAYER, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 10
|
||||
RIGHTMARGIN, 180
|
||||
TOPMARGIN, 11
|
||||
BOTTOMMARGIN, 192
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
21
bbruntime/resource.h
Normal file
21
bbruntime/resource.h
Normal file
@ -0,0 +1,21 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by runtime.rc
|
||||
//
|
||||
#define IDD_MULTIPLAYER 101
|
||||
#define IDC_CANCEL 1011
|
||||
#define IDC_HOSTGAME 1012
|
||||
#define IDC_GAMENAME 1013
|
||||
#define IDC_GAMELIST 1014
|
||||
#define IDC_CONNECTIONS 1015
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 105
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1021
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
0
bbruntime/runtime.cpp
Normal file
0
bbruntime/runtime.cpp
Normal file
2
bbruntime/std.cpp
Normal file
2
bbruntime/std.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
#include "std.h"
|
26
bbruntime/std.h
Normal file
26
bbruntime/std.h
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
#ifndef STD_H
|
||||
#define STD_H
|
||||
|
||||
//#ifndef _WINSOCKAPI_
|
||||
//#define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */
|
||||
//#endif
|
||||
#include <windows.h>
|
||||
//#include <winsock2.h>
|
||||
|
||||
#include "../config/config.h"
|
||||
#include "../stdutil/stdutil.h"
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#endif
|
34
bbruntime/userlib.cpp
Normal file
34
bbruntime/userlib.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
static vector<HMODULE> _mods;
|
||||
|
||||
static void procNotFound(){
|
||||
RTEX( "User lib function not found" );
|
||||
}
|
||||
|
||||
void _bbLoadLibs( char *p ){
|
||||
while( *p ){
|
||||
HMODULE mod=LoadLibrary( p );
|
||||
if( !mod ){
|
||||
continue;
|
||||
}
|
||||
_mods.push_back(mod);
|
||||
p+=strlen(p)+1;
|
||||
while( *p ){
|
||||
void *proc=GetProcAddress( mod,p );
|
||||
p+=strlen(p)+1;
|
||||
void *ptr=*(void**)p;
|
||||
p+=4;
|
||||
if( !proc ) proc=procNotFound;
|
||||
*(void**)ptr=proc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _bbUnloadLibs(){
|
||||
for( ;_mods.size();_mods.pop_back() ) FreeLibrary( _mods.back() );
|
||||
}
|
8
bbruntime/userlib.h
Normal file
8
bbruntime/userlib.h
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
#ifndef USERLIB_H
|
||||
#define USERLIB_H
|
||||
|
||||
void _bbLoadLibs( char *table );
|
||||
void _bbUnloadLibs();
|
||||
|
||||
#endif
|
95
bbruntime/userlibs.cpp
Normal file
95
bbruntime/userlibs.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "bbsys.h"
|
||||
#include "userlibs.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
static vector<HMODULE> _mods;
|
||||
|
||||
struct Str{
|
||||
char *p;
|
||||
int size;
|
||||
};
|
||||
|
||||
static Str _strs[256];
|
||||
static int _nextStr;
|
||||
|
||||
static void libNotFound(){
|
||||
RTEX( "User lib not found" );
|
||||
}
|
||||
|
||||
static void procNotFound(){
|
||||
RTEX( "User lib function not found" );
|
||||
}
|
||||
|
||||
void _bbLoadLibs( char *p ){
|
||||
|
||||
string home;
|
||||
|
||||
if( const char *t=getenv( "blitzpath" ) ) home=t;
|
||||
|
||||
while( *p ){
|
||||
HMODULE mod=LoadLibrary( p );
|
||||
if( !mod && home.size() ){
|
||||
mod=LoadLibrary( (home+"/userlibs/"+p).c_str() );
|
||||
}
|
||||
p+=strlen(p)+1;
|
||||
if( mod ){
|
||||
_mods.push_back( mod );
|
||||
while( *p ){
|
||||
void *proc=GetProcAddress( mod,p );
|
||||
p+=strlen(p)+1;
|
||||
void *ptr=*(void**)p;
|
||||
p+=4;
|
||||
*(void**)ptr=proc ? proc : procNotFound;
|
||||
}
|
||||
}else{
|
||||
while( *p ){
|
||||
p+=strlen(p)+1;
|
||||
void *ptr=*(void**)p;
|
||||
p+=4;
|
||||
*(void**)ptr=libNotFound;
|
||||
}
|
||||
}
|
||||
++p;
|
||||
}
|
||||
}
|
||||
|
||||
const char* _bbStrToCStr( BBStr *str ){
|
||||
|
||||
Str &t=_strs[_nextStr++ & 255];
|
||||
|
||||
int size=str->size();
|
||||
|
||||
if( !t.p || t.size<size ){
|
||||
delete[] t.p;
|
||||
t.p=new char[size+1];
|
||||
t.size=size;
|
||||
}
|
||||
|
||||
memcpy( t.p,str->data(),size );
|
||||
t.p[size]=0;
|
||||
delete str;
|
||||
return t.p;
|
||||
}
|
||||
|
||||
BBStr* _bbCStrToStr( const char *str ){
|
||||
return new BBStr( str );
|
||||
}
|
||||
|
||||
bool userlibs_create(){
|
||||
return true;
|
||||
}
|
||||
|
||||
void userlibs_destroy(){
|
||||
for( ;_mods.size();_mods.pop_back() ) FreeLibrary( _mods.back() );
|
||||
}
|
||||
|
||||
void userlibs_link( void(*rtSym)(const char*,void*) ){
|
||||
rtSym( "_bbLoadLibs",_bbLoadLibs );
|
||||
rtSym( "_bbStrToCStr",_bbStrToCStr );
|
||||
rtSym( "_bbCStrToStr",_bbCStrToStr );
|
||||
}
|
||||
|
||||
|
12
bbruntime/userlibs.h
Normal file
12
bbruntime/userlibs.h
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
#ifndef USERLIBS_H
|
||||
#define USERLIBS_H
|
||||
|
||||
#include "basic.h"
|
||||
|
||||
void _bbLoadLibs( char *p );
|
||||
|
||||
const char* _bbStrToCStr( BBStr *str );
|
||||
BBStr* _bbCStrToStr( const char *str );
|
||||
|
||||
#endif
|
BIN
bbruntime_dll/bbexe.ico
Normal file
BIN
bbruntime_dll/bbexe.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
304
bbruntime_dll/bbruntime_dll.cpp
Normal file
304
bbruntime_dll/bbruntime_dll.cpp
Normal file
@ -0,0 +1,304 @@
|
||||
|
||||
#pragma warning( disable:4786 )
|
||||
|
||||
#include "bbruntime_dll.h"
|
||||
#include "../debugger/debugger.h"
|
||||
|
||||
#ifdef PRODEMO
|
||||
#include "../shareprot/shareprot.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include <map>
|
||||
#include <eh.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "../bbruntime/bbruntime.h"
|
||||
|
||||
class DummyDebugger : public Debugger{
|
||||
public:
|
||||
virtual void debugRun(){}
|
||||
virtual void debugStop(){}// bbruntime_panic(0); }
|
||||
virtual void debugStmt( int srcpos,const char *file ){}
|
||||
virtual void debugEnter( void *frame,void *env,const char *func ){}
|
||||
virtual void debugLeave(){}
|
||||
virtual void debugLog( const char *msg ){}
|
||||
virtual void debugMsg( const char *e,bool serious ){
|
||||
if( serious ) MessageBox( 0,e,"Error!",MB_OK|MB_TOPMOST|MB_SETFOREGROUND );
|
||||
}
|
||||
virtual void debugSys( void *msg ){}
|
||||
};
|
||||
|
||||
static HINSTANCE hinst;
|
||||
static map<const char*,void*> syms;
|
||||
map<const char*,void*>::iterator sym_it;
|
||||
static gxRuntime *gx_runtime;
|
||||
|
||||
static void rtSym( const char *sym,void *pc ){
|
||||
syms[sym]=pc;
|
||||
}
|
||||
|
||||
#ifdef PRODEMO
|
||||
static void killer(){
|
||||
ExitProcess( -1 );
|
||||
}
|
||||
#endif
|
||||
|
||||
static void _cdecl seTranslator( unsigned int u,EXCEPTION_POINTERS* pExp ){
|
||||
switch( u ){
|
||||
case EXCEPTION_INT_DIVIDE_BY_ZERO:
|
||||
bbruntime_panic( "Integer divide by zero" );
|
||||
case EXCEPTION_ACCESS_VIOLATION:
|
||||
bbruntime_panic( "Memory access violation" );
|
||||
case EXCEPTION_ILLEGAL_INSTRUCTION:
|
||||
bbruntime_panic( "Illegal instruction" );
|
||||
case EXCEPTION_STACK_OVERFLOW:
|
||||
bbruntime_panic( "Stack overflow!" );
|
||||
}
|
||||
bbruntime_panic( "Unknown runtime exception" );
|
||||
}
|
||||
|
||||
int Runtime::version(){
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
const char *Runtime::nextSym(){
|
||||
if( !syms.size() ){
|
||||
bbruntime_link( rtSym );
|
||||
sym_it=syms.begin();
|
||||
}
|
||||
if( sym_it==syms.end() ){
|
||||
syms.clear();return 0;
|
||||
}
|
||||
return (sym_it++)->first;
|
||||
}
|
||||
|
||||
int Runtime::symValue( const char *sym ){
|
||||
map<const char*,void*>::iterator it=syms.find( sym );
|
||||
if( it!=syms.end() ) return (int)it->second;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Runtime::startup( HINSTANCE h ){
|
||||
hinst=h;
|
||||
}
|
||||
|
||||
void Runtime::shutdown(){
|
||||
trackmem( false );
|
||||
syms.clear();
|
||||
}
|
||||
|
||||
void Runtime::execute( void (*pc)(),const char *args,Debugger *dbg ){
|
||||
|
||||
bool debug=!!dbg;
|
||||
|
||||
static DummyDebugger dummydebug;
|
||||
|
||||
if( !dbg ) dbg=&dummydebug;
|
||||
|
||||
trackmem( true );
|
||||
|
||||
_se_translator_function old_trans=_set_se_translator( seTranslator );
|
||||
_control87( _RC_NEAR|_PC_24|_EM_INVALID|_EM_ZERODIVIDE|_EM_OVERFLOW|_EM_UNDERFLOW|_EM_INEXACT|_EM_DENORMAL,0xfffff );
|
||||
|
||||
//strip spaces from ends of args...
|
||||
string params=args;
|
||||
while( params.size() && params[0]==' ' ) params=params.substr( 1 );
|
||||
while( params.size() && params[params.size()-1]==' ' ) params=params.substr( 0,params.size()-1 );
|
||||
|
||||
if( gx_runtime=gxRuntime::openRuntime( hinst,params,dbg ) ){
|
||||
|
||||
#ifdef PRODEMO
|
||||
shareProtCheck( killer );
|
||||
#endif
|
||||
bbruntime_run( gx_runtime,pc,debug );
|
||||
|
||||
gxRuntime *t=gx_runtime;
|
||||
gx_runtime=0;
|
||||
gxRuntime::closeRuntime( t );
|
||||
}
|
||||
|
||||
_control87( _CW_DEFAULT,0xfffff );
|
||||
_set_se_translator( old_trans );
|
||||
}
|
||||
|
||||
void Runtime::asyncStop(){
|
||||
if( gx_runtime ) gx_runtime->asyncStop();
|
||||
}
|
||||
|
||||
void Runtime::asyncRun(){
|
||||
if( gx_runtime ) gx_runtime->asyncRun();
|
||||
}
|
||||
|
||||
void Runtime::asyncEnd(){
|
||||
if( gx_runtime ) gx_runtime->asyncEnd();
|
||||
}
|
||||
|
||||
void Runtime::checkmem( streambuf *buf ){
|
||||
ostream out( buf );
|
||||
::checkmem( out );
|
||||
}
|
||||
|
||||
Runtime *_cdecl runtimeGetRuntime(){
|
||||
static Runtime runtime;
|
||||
return &runtime;
|
||||
}
|
||||
|
||||
/********************** BUTT UGLY DLL->EXE HOOK! *************************/
|
||||
|
||||
static void *module_pc;
|
||||
static map<string,int> module_syms;
|
||||
static map<string,int> runtime_syms;
|
||||
static Runtime *runtime;
|
||||
|
||||
static void fail(){
|
||||
MessageBox( 0,"Unable to run Blitz Basic module",0,0 );
|
||||
ExitProcess(-1);
|
||||
}
|
||||
|
||||
struct Sym{
|
||||
string name;
|
||||
int value;
|
||||
};
|
||||
|
||||
static Sym getSym( void **p ){
|
||||
Sym sym;
|
||||
char *t=(char*)*p;
|
||||
while( char c=*t++ ) sym.name+=c;
|
||||
sym.value=*(int*)t+(int)module_pc;
|
||||
*p=t+4;return sym;
|
||||
}
|
||||
|
||||
static int findSym( const string &t ){
|
||||
map<string,int>::iterator it;
|
||||
|
||||
it=module_syms.find( t );
|
||||
if( it!=module_syms.end() ) return it->second;
|
||||
it=runtime_syms.find( t );
|
||||
if( it!=runtime_syms.end() ) return it->second;
|
||||
|
||||
string err="Can't find symbol: "+t;
|
||||
MessageBox( 0,err.c_str(),0,0 );
|
||||
ExitProcess(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void link(){
|
||||
|
||||
while( const char *sc=runtime->nextSym() ){
|
||||
|
||||
string t(sc);
|
||||
|
||||
if( t[0]=='_' ){
|
||||
runtime_syms["_"+t]=runtime->symValue(sc);
|
||||
continue;
|
||||
}
|
||||
|
||||
if( t[0]=='!' ) t=t.substr(1);
|
||||
|
||||
if( !isalnum(t[0]) ) t=t.substr(1);
|
||||
|
||||
for( int k=0;k<t.size();++k ){
|
||||
if( isalnum(t[k]) || t[k]=='_' ) continue;
|
||||
t=t.substr( 0,k );break;
|
||||
}
|
||||
|
||||
runtime_syms["_f"+tolower(t)]=runtime->symValue(sc);
|
||||
}
|
||||
|
||||
HRSRC hres=FindResource( 0,MAKEINTRESOURCE(1111),RT_RCDATA );if( !hres ) fail();
|
||||
HGLOBAL hglo=LoadResource( 0,hres );if( !hglo ) fail();
|
||||
void *p=LockResource( hglo );if( !p ) fail();
|
||||
|
||||
int sz=*(int*)p;p=(int*)p+1;
|
||||
|
||||
//replace malloc for service pack 2 Data Execution Prevention (DEP).
|
||||
module_pc=VirtualAlloc( 0,sz,MEM_COMMIT|MEM_RESERVE,PAGE_EXECUTE_READWRITE );
|
||||
|
||||
memcpy( module_pc,p,sz );
|
||||
p=(char*)p+sz;
|
||||
|
||||
int k,cnt;
|
||||
|
||||
cnt=*(int*)p;p=(int*)p+1;
|
||||
for( k=0;k<cnt;++k ){
|
||||
Sym sym=getSym( &p );
|
||||
if( sym.value<(int)module_pc || sym.value>=(int)module_pc+sz ) fail();
|
||||
module_syms[sym.name]=sym.value;
|
||||
}
|
||||
|
||||
cnt=*(int*)p;p=(int*)p+1;
|
||||
for( k=0;k<cnt;++k ){
|
||||
Sym sym=getSym( &p );
|
||||
int *pp=(int*)sym.value;
|
||||
int dest=findSym( sym.name );
|
||||
*pp+=dest-(int)pp;
|
||||
}
|
||||
|
||||
cnt=*(int*)p;p=(int*)p+1;
|
||||
for( k=0;k<cnt;++k ){
|
||||
Sym sym=getSym( &p );
|
||||
int *pp=(int*)sym.value;
|
||||
int dest=findSym( sym.name );
|
||||
*pp+=dest;
|
||||
}
|
||||
|
||||
runtime_syms.clear();
|
||||
module_syms.clear();
|
||||
}
|
||||
|
||||
extern "C" _declspec(dllexport) int _stdcall bbWinMain();
|
||||
extern "C" BOOL _stdcall _DllMainCRTStartup( HANDLE,DWORD,LPVOID );
|
||||
|
||||
bool WINAPI DllMain( HANDLE module,DWORD reason,void *reserved ){
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int __stdcall bbWinMain(){
|
||||
|
||||
HINSTANCE inst=GetModuleHandle( 0 );
|
||||
|
||||
_DllMainCRTStartup( inst,DLL_PROCESS_ATTACH,0 );
|
||||
|
||||
#ifdef BETA
|
||||
int ver=VERSION & 0x7fff;
|
||||
string t="Created with Blitz3D Beta V"+itoa( ver/100 )+"."+itoa( ver%100 );
|
||||
MessageBox( GetDesktopWindow(),t.c_str(),"Blitz3D Message",MB_OK );
|
||||
#endif
|
||||
|
||||
#ifdef SCHOOLS
|
||||
MessageBox( GetDesktopWindow(),"Created with the schools version of Blitz Basic","Blitz Basic Message",MB_OK );
|
||||
#endif
|
||||
|
||||
runtime=runtimeGetRuntime();
|
||||
runtime->startup( inst );
|
||||
|
||||
link();
|
||||
|
||||
//get cmd_line and params
|
||||
string cmd=GetCommandLine(),params;
|
||||
while( cmd.size() && cmd[0]==' ' ) cmd=cmd.substr( 1 );
|
||||
if( cmd.find( '\"' )==0 ){
|
||||
int n=cmd.find( '\"',1 );
|
||||
if( n!=string::npos ){
|
||||
params=cmd.substr( n+1 );
|
||||
cmd=cmd.substr( 1,n-1 );
|
||||
}
|
||||
}else{
|
||||
int n=cmd.find( ' ' );
|
||||
if( n!=string::npos ){
|
||||
params=cmd.substr( n+1 );
|
||||
cmd=cmd.substr( 0,n );
|
||||
}
|
||||
}
|
||||
|
||||
runtime->execute( (void(*)())module_pc,params.c_str(),0 );
|
||||
runtime->shutdown();
|
||||
|
||||
_DllMainCRTStartup( inst,DLL_PROCESS_DETACH,0 );
|
||||
|
||||
ExitProcess(0);
|
||||
return 0;
|
||||
}
|
||||
|
249
bbruntime_dll/bbruntime_dll.dsp
Normal file
249
bbruntime_dll/bbruntime_dll.dsp
Normal file
@ -0,0 +1,249 @@
|
||||
# Microsoft Developer Studio Project File - Name="bbruntime_dll" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=bbruntime_dll - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "bbruntime_dll.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "bbruntime_dll.mak" CFG="bbruntime_dll - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "bbruntime_dll - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "bbruntime_dll - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "bbruntime_dll - Win32 Blitz3DRelease" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "bbruntime_dll - Win32 Blitz2DRelease" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "bbruntime_dll - Win32 Blitz3DEdu" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "bbruntime_dll - Win32 Blitz3DDemo" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "bbruntime_dll - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BBRUNTIME_DLL_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BBRUNTIME_DLL_EXPORTS" /FA /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 wsock32.lib winmm.lib dxguid.lib d3dxof.lib dplayx.lib ddraw.lib dinput.lib dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /force /out:"..\blitzbasic\bin\runtime.dll"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime_dll - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BBRUNTIME_DLL_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BBRUNTIME_DLL_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 wsock32.lib winmm.lib dxguid.lib d3dxof.lib dplayx.lib ddraw.lib dinput.lib dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:no /debug /machine:I386 /out:"..\blitzbasic\bin\runtime.dll" /fixed:no
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime_dll - Win32 Blitz3DRelease"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "bbruntime_dll___Win32_Blitz3DRelease"
|
||||
# PROP BASE Intermediate_Dir "bbruntime_dll___Win32_Blitz3DRelease"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "bbruntime_dll___Win32_Blitz3DRelease"
|
||||
# PROP Intermediate_Dir "bbruntime_dll___Win32_Blitz3DRelease"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BBRUNTIME_DLL_EXPORTS" /FA /YX /FD /c
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "_WINDOWS" /D "_USRDLL" /D "BBRUNTIME_DLL_EXPORTS" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /FA /FD /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 wsock32.lib winmm.lib dxguid.lib d3dxof.lib dplayx.lib ddraw.lib dinput.lib dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /force /out:"..\blitzbasic\bin\runtime.dll"
|
||||
# ADD LINK32 wsock32.lib amstrmid.lib winmm.lib dxguid.lib d3dxof.lib dplayx.lib ddraw.lib dinput.lib dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /force /out:"..\..\release\blitz3drelease\bin\runtime.dll"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime_dll - Win32 Blitz2DRelease"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "bbruntime_dll___Win32_Blitz2DRelease"
|
||||
# PROP BASE Intermediate_Dir "bbruntime_dll___Win32_Blitz2DRelease"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "bbruntime_dll___Win32_Blitz2DRelease"
|
||||
# PROP Intermediate_Dir "bbruntime_dll___Win32_Blitz2DRelease"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BBRUNTIME_DLL_EXPORTS" /FA /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BBRUNTIME_DLL_EXPORTS" /FA /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 wsock32.lib winmm.lib dxguid.lib d3dxof.lib dplayx.lib ddraw.lib dinput.lib dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /force /out:"..\..\release\blitz3drelease\bin\runtime.dll"
|
||||
# ADD LINK32 wsock32.lib winmm.lib dxguid.lib d3dxof.lib dplayx.lib ddraw.lib dinput.lib dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /force /out:"..\..\release\blitz2drelease\bin\runtime.dll"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime_dll - Win32 Blitz3DEdu"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "bbruntime_dll___Win32_Blitz3DEdu"
|
||||
# PROP BASE Intermediate_Dir "bbruntime_dll___Win32_Blitz3DEdu"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "bbruntime_dll___Win32_Blitz3DEdu"
|
||||
# PROP Intermediate_Dir "bbruntime_dll___Win32_Blitz3DEdu"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BBRUNTIME_DLL_EXPORTS" /D "PRO" /FA /YX /FD /c
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "_WINDOWS" /D "_USRDLL" /D "BBRUNTIME_DLL_EXPORTS" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /D "EDU" /FA /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 wsock32.lib winmm.lib dxguid.lib d3dxof.lib dplayx.lib ddraw.lib dinput.lib dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /force /out:"..\..\release\blitz3drelease\bin\runtime.dll"
|
||||
# ADD LINK32 wsock32.lib winmm.lib dxguid.lib d3dxof.lib dplayx.lib ddraw.lib dinput.lib dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /force /out:"..\..\release\blitz3dedu\bin\runtime.dll"
|
||||
|
||||
!ELSEIF "$(CFG)" == "bbruntime_dll - Win32 Blitz3DDemo"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "bbruntime_dll___Win32_Blitz3DDemo"
|
||||
# PROP BASE Intermediate_Dir "bbruntime_dll___Win32_Blitz3DDemo"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "bbruntime_dll___Win32_Blitz3DDemo"
|
||||
# PROP Intermediate_Dir "bbruntime_dll___Win32_Blitz3DDemo"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BBRUNTIME_DLL_EXPORTS" /D "PRO" /FA /YX /FD /c
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "_WINDOWS" /D "_USRDLL" /D "BBRUNTIME_DLL_EXPORTS" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /D "DEMO" /FA /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 wsock32.lib winmm.lib dxguid.lib d3dxof.lib dplayx.lib ddraw.lib dinput.lib dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /force /out:"..\..\release\blitz3drelease\bin\runtime.dll"
|
||||
# ADD LINK32 wsock32.lib amstrmid.lib winmm.lib dxguid.lib d3dxof.lib dplayx.lib ddraw.lib dinput.lib dsound.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /force /out:"..\..\release\blitz3ddemo\bin\runtime.dll"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "bbruntime_dll - Win32 Release"
|
||||
# Name "bbruntime_dll - Win32 Debug"
|
||||
# Name "bbruntime_dll - Win32 Blitz3DRelease"
|
||||
# Name "bbruntime_dll - Win32 Blitz2DRelease"
|
||||
# Name "bbruntime_dll - Win32 Blitz3DEdu"
|
||||
# Name "bbruntime_dll - Win32 Blitz3DDemo"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbruntime_dll.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbruntime_dll.rc
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbruntime_dll.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\bbexe.ico
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\FreeImage241\Source\FreeImageLib\Release\FreeImage.lib
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\fmodsrc375win\win\Final\fmodstatic.lib
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
30
bbruntime_dll/bbruntime_dll.h
Normal file
30
bbruntime_dll/bbruntime_dll.h
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
/* Win32 runtime dynamic link lib */
|
||||
|
||||
#ifndef BBRUNTIME_DLL_H
|
||||
#define BBRUNTIME_DLL_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "../stdutil/stdutil.h"
|
||||
|
||||
class Debugger;
|
||||
|
||||
class Runtime{
|
||||
public:
|
||||
virtual int version();
|
||||
virtual const char *nextSym();
|
||||
virtual int symValue( const char *sym );
|
||||
virtual void startup( HINSTANCE hinst );
|
||||
virtual void shutdown();
|
||||
virtual void asyncStop();
|
||||
virtual void asyncRun();
|
||||
virtual void asyncEnd();
|
||||
virtual void checkmem( std::streambuf *buf );
|
||||
|
||||
virtual void execute( void (*pc)(),const char *args,Debugger *dbg );
|
||||
};
|
||||
|
||||
extern "C" _declspec(dllexport) Runtime * _cdecl runtimeGetRuntime();
|
||||
|
||||
#endif
|
85
bbruntime_dll/bbruntime_dll.rc
Normal file
85
bbruntime_dll/bbruntime_dll.rc
Normal file
@ -0,0 +1,85 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""../bbruntime/multiplay_setup.rc""\r\n"
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Data
|
||||
//
|
||||
|
||||
IDR_BBMODULE RCDATA DISCARDABLE
|
||||
BEGIN
|
||||
0x0201, 0x0403
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Icon
|
||||
//
|
||||
|
||||
// Icon with lowest ID value placed first to ensure application icon
|
||||
// remains consistent on all systems.
|
||||
IDI_ICON1 ICON DISCARDABLE "bbexe.ico"
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
#include "../bbruntime/multiplay_setup.rc"
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
17
bbruntime_dll/resource.h
Normal file
17
bbruntime_dll/resource.h
Normal file
@ -0,0 +1,17 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by runtime_dll.rc
|
||||
//
|
||||
#define IDI_ICON1 107
|
||||
#define IDR_BBMODULE 1111
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 108
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 103
|
||||
#endif
|
||||
#endif
|
206
blitz/blitz.dsp
Normal file
206
blitz/blitz.dsp
Normal file
@ -0,0 +1,206 @@
|
||||
# Microsoft Developer Studio Project File - Name="blitz" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=blitz - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "blitz.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "blitz.mak" CFG="blitz - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "blitz - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "blitz - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "blitz - Win32 Blitz3DRelease" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "blitz - Win32 Blitz2DRelease" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "blitz - Win32 Blitz3DEdu" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "blitz - Win32 Blitz3DDemo" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "blitz - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x1409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x1409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"..\blitzbasic\bin\blitzcc.exe"
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x1409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x1409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz - Win32 Blitz3DRelease"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "blitz___Win32_Blitz3DRelease"
|
||||
# PROP BASE Intermediate_Dir "blitz___Win32_Blitz3DRelease"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "blitz___Win32_Blitz3DRelease"
|
||||
# PROP Intermediate_Dir "blitz___Win32_Blitz3DRelease"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "_CONSOLE" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /FD /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x1409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x1409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"..\blitzbasic\bin\blitzcc.exe"
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"..\..\release\blitz3drelease\bin\blitzcc.exe"
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz - Win32 Blitz2DRelease"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "blitz___Win32_Blitz2DRelease"
|
||||
# PROP BASE Intermediate_Dir "blitz___Win32_Blitz2DRelease"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "blitz___Win32_Blitz2DRelease"
|
||||
# PROP Intermediate_Dir "blitz___Win32_Blitz2DRelease"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x1409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x1409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"..\..\release\blitz3drelease\bin\blitzcc.exe"
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"..\..\release\blitz2drelease\bin\blitzcc.exe"
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz - Win32 Blitz3DEdu"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "blitz___Win32_Blitz3DEdu"
|
||||
# PROP BASE Intermediate_Dir "blitz___Win32_Blitz3DEdu"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "blitz___Win32_Blitz3DEdu"
|
||||
# PROP Intermediate_Dir "blitz___Win32_Blitz3DEdu"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "PRO" /YX /FD /c
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "_CONSOLE" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /D "EDU" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x1409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x1409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"..\..\release\blitz3drelease\bin\blitzcc.exe"
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"..\..\release\blitz3dedu\bin\blitzcc.exe"
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz - Win32 Blitz3DDemo"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "blitz___Win32_Blitz3DDemo"
|
||||
# PROP BASE Intermediate_Dir "blitz___Win32_Blitz3DDemo"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "blitz___Win32_Blitz3DDemo"
|
||||
# PROP Intermediate_Dir "blitz___Win32_Blitz3DDemo"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "PRO" /YX /FD /c
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O1 /D "_CONSOLE" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /D "DEMO" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x1409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x1409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"..\..\release\blitz3drelease\bin\blitzcc.exe"
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"..\..\release\blitz3ddemo\bin\blitzcc.exe"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "blitz - Win32 Release"
|
||||
# Name "blitz - Win32 Debug"
|
||||
# Name "blitz - Win32 Blitz3DRelease"
|
||||
# Name "blitz - Win32 Blitz2DRelease"
|
||||
# Name "blitz - Win32 Blitz3DEdu"
|
||||
# Name "blitz - Win32 Blitz3DDemo"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\libs.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\libs.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\main.cpp
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
312
blitz/libs.cpp
Normal file
312
blitz/libs.cpp
Normal file
@ -0,0 +1,312 @@
|
||||
|
||||
#include "libs.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
int bcc_ver;
|
||||
int lnk_ver;
|
||||
int run_ver;
|
||||
int dbg_ver;
|
||||
|
||||
string home;
|
||||
Linker *linkerLib;
|
||||
Runtime *runtimeLib;
|
||||
|
||||
Module *runtimeModule;
|
||||
Environ *runtimeEnviron;
|
||||
vector<string> keyWords;
|
||||
vector<UserFunc> userFuncs;
|
||||
|
||||
static HMODULE linkerHMOD,runtimeHMOD;
|
||||
|
||||
static Type *typeof( int c ){
|
||||
switch( c ){
|
||||
case '%':return Type::int_type;
|
||||
case '#':return Type::float_type;
|
||||
case '$':return Type::string_type;
|
||||
}
|
||||
return Type::void_type;
|
||||
}
|
||||
|
||||
static int curr;
|
||||
static string text;
|
||||
|
||||
static int next( istream &in ){
|
||||
|
||||
text="";
|
||||
|
||||
int t=0;
|
||||
|
||||
for(;;){
|
||||
while( isspace( in.peek() ) ) in.get();
|
||||
if( in.eof() ) return curr=0;
|
||||
t=in.get();if( t!=';' ) break;
|
||||
while( !in.eof() && in.get()!='\n' ){}
|
||||
}
|
||||
|
||||
if( isalpha(t) ){
|
||||
text+=(char)t;
|
||||
while( isalnum( in.peek() ) || in.peek()=='_' ) text+=(char)in.get();
|
||||
return curr=-1;
|
||||
}
|
||||
if( t=='\"' ){
|
||||
while( in.peek()!='\"' ) text=text+(char)in.get();
|
||||
in.get();
|
||||
return curr=-2;
|
||||
}
|
||||
|
||||
return curr=t;
|
||||
}
|
||||
|
||||
static const char *linkRuntime(){
|
||||
|
||||
while( const char *sym=runtimeLib->nextSym() ){
|
||||
|
||||
string s( sym );
|
||||
|
||||
int pc=runtimeLib->symValue(sym);
|
||||
|
||||
//internal?
|
||||
if( s[0]=='_' ){
|
||||
runtimeModule->addSymbol( ("_"+s).c_str(),pc );
|
||||
continue;
|
||||
}
|
||||
|
||||
bool cfunc=false;
|
||||
|
||||
if( s[0]=='!' ){
|
||||
cfunc=true;
|
||||
s=s.substr(1);
|
||||
}
|
||||
|
||||
keyWords.push_back( s );
|
||||
|
||||
//global!
|
||||
int start=0,end;
|
||||
Type *t=Type::void_type;
|
||||
if( !isalpha( s[0] ) ){ start=1;t=typeof( s[0] ); }
|
||||
for( int k=1;k<s.size();++k ){
|
||||
if( !isalnum( s[k] ) && s[k]!='_' ) break;
|
||||
}
|
||||
end=k;
|
||||
DeclSeq *params=d_new DeclSeq();
|
||||
string n=s.substr( start,end-start );
|
||||
while( k<s.size() ){
|
||||
Type *t=typeof(s[k++]);
|
||||
int from=k;
|
||||
for( ;isalnum(s[k])||s[k]=='_';++k ){}
|
||||
string str=s.substr( from,k-from );
|
||||
ConstType *defType=0;
|
||||
if( s[k]=='=' ){
|
||||
int from=++k;
|
||||
if( s[k]=='\"' ){
|
||||
for( ++k;s[k]!='\"';++k ){}
|
||||
string t=s.substr( from+1,k-from-1 );
|
||||
defType=d_new ConstType( t );++k;
|
||||
}else{
|
||||
if( s[k]=='-' ) ++k;
|
||||
for( ;isdigit( s[k] );++k ){}
|
||||
if( t==Type::int_type ){
|
||||
int n=atoi( s.substr( from,k-from ) );
|
||||
defType=d_new ConstType( n );
|
||||
}else{
|
||||
float n=atof( s.substr( from,k-from ) );
|
||||
defType=d_new ConstType( n );
|
||||
}
|
||||
}
|
||||
}
|
||||
Decl *d=params->insertDecl( str,t,DECL_PARAM,defType );
|
||||
}
|
||||
|
||||
FuncType *f=d_new FuncType( t,params,false,cfunc );
|
||||
n=tolower(n);
|
||||
runtimeEnviron->funcDecls->insertDecl( n,f,DECL_FUNC );
|
||||
runtimeModule->addSymbol( ("_f"+n).c_str(),pc );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static set<string> _ulibkws;
|
||||
|
||||
static const char *loadUserLib( const string &userlib ){
|
||||
|
||||
string t=home+"/userlibs/"+userlib;
|
||||
|
||||
string lib="";
|
||||
ifstream in(t.c_str());
|
||||
|
||||
next(in);
|
||||
while( curr ){
|
||||
|
||||
if( curr=='.' ){
|
||||
|
||||
if( next(in)!=-1 ) return "expecting identifier after '.'";
|
||||
|
||||
if( text=="lib" ){
|
||||
if( next(in)!=-2 ) return "expecting string after lib directive";
|
||||
lib=text;
|
||||
|
||||
}else{
|
||||
return "unknown decl directive";
|
||||
}
|
||||
next( in );
|
||||
|
||||
}else if( curr==-1 ){
|
||||
|
||||
if( !lib.size() ) return "function decl without lib directive";
|
||||
|
||||
string id=text;
|
||||
string lower_id=tolower(id);
|
||||
|
||||
if( _ulibkws.count( lower_id ) ) return "duplicate identifier";
|
||||
_ulibkws.insert( lower_id );
|
||||
|
||||
Type *ty=0;
|
||||
switch( next(in) ){
|
||||
case '%':ty=Type::int_type;break;
|
||||
case '#':ty=Type::float_type;break;
|
||||
case '$':ty=Type::string_type;break;
|
||||
}
|
||||
if( ty ) next(in);
|
||||
else ty=Type::void_type;
|
||||
|
||||
DeclSeq *params=d_new DeclSeq();
|
||||
|
||||
if( curr!='(' ) return "expecting '(' after function identifier";
|
||||
next(in);
|
||||
if( curr!=')' ){
|
||||
for(;;){
|
||||
if( curr!=-1 ) break;
|
||||
string arg=text;
|
||||
|
||||
Type *ty=0;
|
||||
switch( next(in) ){
|
||||
case '%':ty=Type::int_type;break;
|
||||
case '#':ty=Type::float_type;break;
|
||||
case '$':ty=Type::string_type;break;
|
||||
case '*':ty=Type::null_type;break;
|
||||
}
|
||||
if( ty ) next(in);
|
||||
else ty=Type::int_type;
|
||||
|
||||
ConstType *defType=0;
|
||||
|
||||
Decl *d=params->insertDecl( arg,ty,DECL_PARAM,defType );
|
||||
|
||||
if( curr!=',' ) break;
|
||||
next(in);
|
||||
}
|
||||
}
|
||||
if( curr!=')' ) return "expecting ')' after function decl";
|
||||
|
||||
keyWords.push_back( id );
|
||||
|
||||
FuncType *fn=d_new FuncType( ty,params,true,true );
|
||||
|
||||
runtimeEnviron->funcDecls->insertDecl( lower_id,fn,DECL_FUNC );
|
||||
|
||||
if( next(in)==':' ){ //real name?
|
||||
next(in);
|
||||
if( curr!=-1 && curr!=-2 ) return "expecting identifier or string after alias";
|
||||
id=text;
|
||||
next(in);
|
||||
}
|
||||
|
||||
userFuncs.push_back( UserFunc( lower_id,id,lib ) );
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *linkUserLibs(){
|
||||
|
||||
_ulibkws.clear();
|
||||
|
||||
WIN32_FIND_DATA fd;
|
||||
|
||||
HANDLE h=FindFirstFile( (home+"/userlibs/*.decls").c_str(),&fd );
|
||||
|
||||
if( h==INVALID_HANDLE_VALUE ) return 0;
|
||||
|
||||
const char *err=0;
|
||||
|
||||
do{
|
||||
if( err=loadUserLib( fd.cFileName ) ){
|
||||
static char buf[64];
|
||||
sprintf( buf,"Error in userlib '%s' - %s",fd.cFileName,err );
|
||||
err=buf;break;
|
||||
}
|
||||
|
||||
}while( FindNextFile( h,&fd ) );
|
||||
|
||||
FindClose( h );
|
||||
|
||||
_ulibkws.clear();
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
const char *openLibs(){
|
||||
|
||||
char *p=getenv( "blitzpath" );
|
||||
if( !p ) return "Can't find blitzpath environment variable";
|
||||
home=string(p);
|
||||
|
||||
linkerHMOD=LoadLibrary( (home+"/bin/linker.dll").c_str() );
|
||||
if( !linkerHMOD ) return "Unable to open linker.dll";
|
||||
|
||||
typedef Linker *(_cdecl*GetLinker)();
|
||||
GetLinker gl=(GetLinker)GetProcAddress( linkerHMOD,"linkerGetLinker" );
|
||||
if( !gl ) return "Error in linker.dll";
|
||||
linkerLib=gl();
|
||||
|
||||
runtimeHMOD=LoadLibrary( (home+"/bin/runtime.dll").c_str() );
|
||||
if( !runtimeHMOD ) return "Unable to open runtime.dll";
|
||||
|
||||
typedef Runtime *(_cdecl*GetRuntime)();
|
||||
GetRuntime gr=(GetRuntime)GetProcAddress( runtimeHMOD,"runtimeGetRuntime" );
|
||||
if( !gr ) return "Error in runtime.dll";
|
||||
runtimeLib=gr();
|
||||
|
||||
bcc_ver=VERSION;
|
||||
lnk_ver=linkerLib->version();
|
||||
run_ver=runtimeLib->version();
|
||||
|
||||
if( (lnk_ver>>16)!=(bcc_ver>>16) ||
|
||||
(run_ver>>16)!=(bcc_ver>>16) ||
|
||||
(lnk_ver>>16)!=(bcc_ver>>16) ) return "Library version error";
|
||||
|
||||
runtimeLib->startup( GetModuleHandle(0) );
|
||||
|
||||
runtimeModule=linkerLib->createModule();
|
||||
runtimeEnviron=d_new Environ( "",Type::int_type,0,0 );
|
||||
|
||||
keyWords.clear();
|
||||
userFuncs.clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *linkLibs(){
|
||||
|
||||
if( const char *p=linkRuntime() ) return p;
|
||||
|
||||
if( const char *p=linkUserLibs() ) return p;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void closeLibs(){
|
||||
|
||||
delete runtimeEnviron;
|
||||
if( linkerLib ) linkerLib->deleteModule( runtimeModule );
|
||||
if( runtimeLib ) runtimeLib->shutdown();
|
||||
if( runtimeHMOD ) FreeLibrary( runtimeHMOD );
|
||||
if( linkerHMOD ) FreeLibrary( linkerHMOD );
|
||||
|
||||
runtimeEnviron=0;
|
||||
linkerLib=0;
|
||||
runtimeLib=0;
|
||||
runtimeHMOD=0;
|
||||
linkerHMOD=0;
|
||||
}
|
39
blitz/libs.h
Normal file
39
blitz/libs.h
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
#ifndef LIBS_H
|
||||
#define LIBS_H
|
||||
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "../linker/linker.h"
|
||||
#include "../compiler/environ.h"
|
||||
#include "../compiler/parser.h"
|
||||
#include "../bbruntime_dll/bbruntime_dll.h"
|
||||
|
||||
extern int bcc_ver;
|
||||
extern int lnk_ver;
|
||||
extern int run_ver;
|
||||
extern int dbg_ver;
|
||||
|
||||
//openLibs
|
||||
extern string home;
|
||||
extern Linker *linkerLib;
|
||||
extern Runtime *runtimeLib;
|
||||
|
||||
//linkLibs
|
||||
extern Module *runtimeModule;
|
||||
extern Environ *runtimeEnviron;
|
||||
extern vector<string> keyWords;
|
||||
extern vector<UserFunc> userFuncs;
|
||||
|
||||
const char *openLibs();
|
||||
|
||||
const char *linkLibs();
|
||||
|
||||
void closeLibs();
|
||||
|
||||
#endif
|
298
blitz/main.cpp
Normal file
298
blitz/main.cpp
Normal file
@ -0,0 +1,298 @@
|
||||
|
||||
#pragma warning(disable:4786)
|
||||
|
||||
#include "libs.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "../config/config.h"
|
||||
#include "../stdutil/stdutil.h"
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "../linker/linker.h"
|
||||
#include "../compiler/environ.h"
|
||||
#include "../compiler/parser.h"
|
||||
#include "../compiler/assem_x86/assem_x86.h"
|
||||
#include "../compiler/codegen_x86/codegen_x86.h"
|
||||
#include "../bbruntime_dll/bbruntime_dll.h"
|
||||
|
||||
static void showInfo(){
|
||||
const int major=(VERSION&0xffff)/100,minor=(VERSION&0xffff)%100;
|
||||
cout<<"BlitzCC V"<<major<<"."<<minor<<endl;
|
||||
cout<<"(C)opyright 2000-2003 Blitz Research Ltd"<<endl;
|
||||
}
|
||||
|
||||
static void showUsage(){
|
||||
cout<<"Usage: blitzcc [-h|-q|+q|-c|-d|-k|+k|-v|-o exefile] [sourcefile.bb]"<<endl;
|
||||
}
|
||||
|
||||
static void showHelp(){
|
||||
showUsage();
|
||||
cout<<"-h : show this help"<<endl;
|
||||
cout<<"-q : quiet mode"<<endl;
|
||||
cout<<"+q : very quiet mode"<<endl;
|
||||
cout<<"-c : compile only"<<endl;
|
||||
cout<<"-d : debug compile"<<endl;
|
||||
cout<<"-k : dump keywords"<<endl;
|
||||
cout<<"+k : dump keywords and syntax"<<endl;
|
||||
cout<<"-v : version info"<<endl;
|
||||
cout<<"-o exefile : generate executable"<<endl;
|
||||
|
||||
}
|
||||
|
||||
static void err( const string &t ){
|
||||
cout<<t<<endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
static void usageErr(){
|
||||
err( "Usage error" );
|
||||
}
|
||||
|
||||
static string quickHelp( const string &kw ){
|
||||
|
||||
Environ *e=runtimeEnviron;
|
||||
Decl *d=e->funcDecls->findDecl( tolower( kw ) );
|
||||
if( !d || d->type->funcType()==0 ) return "No quick help available for "+kw;
|
||||
string t=kw;
|
||||
FuncType *f=d->type->funcType();
|
||||
if( f->returnType==Type::float_type ) t+='#';
|
||||
else if( f->returnType==Type::string_type ) t+='$';
|
||||
|
||||
t+=" ";
|
||||
|
||||
if( f->returnType!=Type::void_type ) t+="( ";
|
||||
|
||||
for( int k=0;k<f->params->size();++k ){
|
||||
string s;
|
||||
if( k ) s+=',';
|
||||
Decl *p=f->params->decls[k];s+=p->name;
|
||||
if( p->type==Type::float_type ) s+='#';
|
||||
else if( p->type==Type::string_type ) s+='$';
|
||||
else if( p->type==Type::void_type ) s+='*';
|
||||
if( p->defType ) s='['+s+']';
|
||||
t+=s;
|
||||
}
|
||||
|
||||
if( f->returnType!=Type::void_type ){
|
||||
t+=f->params->size() ? " )" : ")";
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
static void dumpKeys( bool lang,bool mod,bool help ){
|
||||
|
||||
if( lang ){
|
||||
map<string,int>::iterator it;
|
||||
map<string,int> &keywords=Toker::getKeywords();
|
||||
for( it=keywords.begin();it!=keywords.end();++it ){
|
||||
if( it->first.find(' ')!=string::npos ) continue;
|
||||
cout<<it->first<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
if( !mod ) return;
|
||||
|
||||
for( int k=0;k<keyWords.size();++k ){
|
||||
string t=keyWords[k];
|
||||
|
||||
if( t[0]=='_' ) continue;
|
||||
if( !isalpha( t[0] ) ) t=t.substr( 1 );
|
||||
for( int n=0;n<t.size();++n ){
|
||||
if( !isalnum(t[n]) && t[n]!='_' ){
|
||||
t=t.substr( 0,n );
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( help ) t=quickHelp(t);
|
||||
cout<<t<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
static string verstr( int ver ){
|
||||
return itoa((ver&65535)/100)+"."+itoa((ver&65535)%100);
|
||||
}
|
||||
|
||||
static void versInfo(){
|
||||
cout<<"Compiler version:"<<verstr(bcc_ver)<<endl;
|
||||
cout<<"Runtime version:"<<verstr(run_ver)<<endl;
|
||||
cout<<"Debugger version:"<<verstr(dbg_ver)<<endl;
|
||||
cout<<"Linker version:"<<verstr(lnk_ver)<<endl;
|
||||
}
|
||||
|
||||
static void demoError(){
|
||||
cout<<"Compiler can not be used standalone in demo version."<<endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int _cdecl main( int argc,char *argv[] ){
|
||||
|
||||
string in_file,out_file,args;
|
||||
|
||||
bool debug=false,quiet=false,veryquiet=false,compileonly=false;
|
||||
bool dumpkeys=false,dumphelp=false,showhelp=false,dumpasm=false;
|
||||
bool versinfo=false;
|
||||
|
||||
for( int k=1;k<argc;++k ){
|
||||
|
||||
string t=argv[k];
|
||||
|
||||
t=tolower(t);
|
||||
|
||||
if( t=="-h" ){
|
||||
showhelp=true;
|
||||
}else if( t=="-a" ){
|
||||
dumpasm=true;
|
||||
}else if( t=="-q" ){
|
||||
quiet=true;
|
||||
}else if( t=="+q" ){
|
||||
quiet=veryquiet=true;
|
||||
}else if( t=="-c" ){
|
||||
compileonly=true;
|
||||
}else if( t=="-d" ){
|
||||
debug=true;
|
||||
}else if( t=="-k" ){
|
||||
dumpkeys=true;
|
||||
}else if( t=="+k" ){
|
||||
dumpkeys=dumphelp=true;
|
||||
}else if( t=="-v" ){
|
||||
versinfo=true;
|
||||
}else if( t=="-o" ){
|
||||
if( out_file.size() || k==argc-1 ) usageErr();
|
||||
out_file=argv[++k];
|
||||
}else{
|
||||
if( in_file.size() || t[0]=='-' || t[0]=='+' ) usageErr();
|
||||
in_file=argv[k];
|
||||
for( ++k;k<argc;++k ){
|
||||
string t=argv[k];
|
||||
if( t.find(' ')!=string::npos ) t='\"'+t+'\"';
|
||||
if( args.size() ) args+=' ';
|
||||
args+=t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( out_file.size() && !in_file.size() ) usageErr();
|
||||
|
||||
if( const char *er=openLibs() ) err( er );
|
||||
|
||||
if( const char *er=linkLibs() ) err( er );
|
||||
|
||||
if( showhelp ) showHelp();
|
||||
if( dumpkeys ) dumpKeys( true,true,dumphelp );
|
||||
if( versinfo ) versInfo();
|
||||
|
||||
if( !in_file.size() ) return 0;
|
||||
|
||||
#ifdef DEMO
|
||||
if( !getenv( "blitzide" ) ) demoError();
|
||||
#endif
|
||||
|
||||
if( in_file[0]=='\"' ){
|
||||
if( in_file.size()<3 || in_file[in_file.size()-1]!='\"' ) usageErr();
|
||||
in_file=in_file.substr( 1,in_file.size()-2 );
|
||||
}
|
||||
|
||||
ifstream in( in_file.c_str() );
|
||||
if( !in ) err( "Unable to open input file" );
|
||||
if( !quiet ){
|
||||
showInfo();
|
||||
cout<<"Compiling \""<<in_file<<"\""<<endl;
|
||||
}
|
||||
|
||||
int n=in_file.rfind( '/' );
|
||||
if( n==string::npos ) n=in_file.rfind( '\\' );
|
||||
if( n!=string::npos ){
|
||||
if( !n || in_file[n-1]==':' ) ++n;
|
||||
SetCurrentDirectory( in_file.substr(0,n).c_str() );
|
||||
}
|
||||
|
||||
ProgNode *prog=0;
|
||||
Environ *environ=0;
|
||||
Module *module=0;
|
||||
|
||||
try{
|
||||
//parse
|
||||
if( !veryquiet ) cout<<"Parsing..."<<endl;
|
||||
Toker toker( in );
|
||||
Parser parser( toker );
|
||||
prog=parser.parse( in_file );
|
||||
|
||||
//semant
|
||||
if( !veryquiet ) cout<<"Generating..."<<endl;
|
||||
environ=prog->semant( runtimeEnviron );
|
||||
|
||||
//translate
|
||||
if( !veryquiet ) cout<<"Translating..."<<endl;
|
||||
qstreambuf qbuf;
|
||||
iostream asmcode( &qbuf );
|
||||
Codegen_x86 codegen( asmcode,debug );
|
||||
|
||||
prog->translate( &codegen,userFuncs );
|
||||
|
||||
if( dumpasm ){
|
||||
cout<<endl<<string( qbuf.data(),qbuf.size() )<<endl;
|
||||
}
|
||||
|
||||
//assemble
|
||||
if( !veryquiet ) cout<<"Assembling..."<<endl;
|
||||
module=linkerLib->createModule();
|
||||
Assem_x86 assem( asmcode,module );
|
||||
assem.assemble();
|
||||
|
||||
}catch( Ex &x ){
|
||||
|
||||
string file='\"'+x.file+'\"';
|
||||
int row=((x.pos>>16)&65535)+1,col=(x.pos&65535)+1;
|
||||
cout<<file<<":"<<row<<":"<<col<<":"<<row<<":"<<col<<":"<<x.ex<<endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
delete prog;
|
||||
|
||||
if( out_file.size() ){
|
||||
if( !veryquiet ) cout<<"Creating executable \""<<out_file<<"\"..."<<endl;
|
||||
if( !module->createExe( out_file.c_str(),(home+"/bin/runtime.dll").c_str() ) ){
|
||||
err( "Error creating executable" );
|
||||
}
|
||||
}else if( !compileonly ){
|
||||
void *entry=module->link( runtimeModule );
|
||||
if( !entry ) return 0;
|
||||
|
||||
HMODULE dbgHandle=0;
|
||||
Debugger *debugger=0;
|
||||
|
||||
if( debug ){
|
||||
dbgHandle=LoadLibrary( (home+"/bin/debugger.dll").c_str() );
|
||||
if( dbgHandle ){
|
||||
typedef Debugger *(_cdecl*GetDebugger)( Module*,Environ* );
|
||||
GetDebugger gd=(GetDebugger)GetProcAddress( dbgHandle,"debuggerGetDebugger" );
|
||||
if( gd ) debugger=gd( module,environ );
|
||||
}
|
||||
if( !debugger ) err( "Error launching debugger" );
|
||||
}
|
||||
|
||||
if( !veryquiet ) cout<<"Executing..."<<endl;
|
||||
|
||||
runtimeLib->execute( (void(*)())entry,args.c_str(),debugger );
|
||||
|
||||
if( dbgHandle ) FreeLibrary( dbgHandle );
|
||||
}
|
||||
|
||||
delete module;
|
||||
delete environ;
|
||||
|
||||
closeLibs();
|
||||
|
||||
return 0;
|
||||
}
|
263
blitz3d.dsw
Normal file
263
blitz3d.dsw
Normal file
@ -0,0 +1,263 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "asm_makeinsts"=.\asm_makeinsts\asm_makeinsts.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "bblaunch"=.\bblaunch\bblaunch.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name blitzide
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name compiler
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name config
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name linker_dll
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name stdutil
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name linker
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name bbruntime
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name bbruntime_dll
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name gxruntime
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name debugger
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name blitz
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "bbruntime"=.\bbruntime\bbruntime.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "bbruntime_dll"=.\bbruntime_dll\bbruntime_dll.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name bbruntime
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name gxruntime
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name stdutil
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name blitz3d
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "blitz"=.\blitz\blitz.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name compiler
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name stdutil
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "blitz3d"=.\blitz3d\blitz3d.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "blitzide"=.\blitzide\blitzide.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name config
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "compiler"=.\compiler\compiler.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name config
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name stdutil
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "config"=.\config\config.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "debugger"=.\debugger\debugger.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "gxruntime"=.\gxruntime\gxruntime.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "linker"=.\linker\linker.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name config
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name stdutil
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "linker_dll"=.\linker_dll\linker_dll.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name linker
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name stdutil
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name config
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "stdutil"=.\stdutil\stdutil.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name config
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
288
blitz3d/animation.cpp
Normal file
288
blitz3d/animation.cpp
Normal file
@ -0,0 +1,288 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "animation.h"
|
||||
|
||||
struct Animation::Rep{
|
||||
|
||||
int ref_cnt;
|
||||
|
||||
typedef map<int,Quat> KeyList;
|
||||
|
||||
KeyList scale_anim,rot_anim,pos_anim;
|
||||
|
||||
Rep():
|
||||
ref_cnt(1){
|
||||
}
|
||||
|
||||
Rep( const Rep &t ):
|
||||
ref_cnt(1),
|
||||
scale_anim(t.scale_anim),rot_anim(t.rot_anim),pos_anim(t.pos_anim){
|
||||
}
|
||||
|
||||
Vector getLinearValue( const KeyList &keys,float time )const{
|
||||
KeyList::const_iterator next,curr;
|
||||
|
||||
//for( next=keys.begin();next!=keys.end() && time>=next->first;++next ){}
|
||||
next=keys.upper_bound( (int)time );
|
||||
|
||||
if( next==keys.begin() ) return next->second.v;
|
||||
curr=next;--curr;
|
||||
if( next==keys.end() ) return curr->second.v;
|
||||
|
||||
float delta=( time-curr->first )/( next->first-curr->first );
|
||||
return ( next->second.v-curr->second.v )*delta+curr->second.v;
|
||||
}
|
||||
|
||||
Quat getSlerpValue( const KeyList &keys,float time )const{
|
||||
KeyList::const_iterator next,curr;
|
||||
|
||||
//for( next=keys.begin();next!=keys.end() && time>=next->first;++next ){}
|
||||
next=keys.upper_bound( (int)time );
|
||||
|
||||
if( next==keys.begin() ) return next->second;
|
||||
curr=next;--curr;
|
||||
if( next==keys.end() ) return curr->second;
|
||||
|
||||
float delta=( time-curr->first )/( next->first-curr->first );
|
||||
return curr->second.slerpTo( next->second,delta );
|
||||
}
|
||||
|
||||
void setKey( KeyList &keys,int time,const Quat &value ){
|
||||
keys[time]=value;
|
||||
}
|
||||
};
|
||||
|
||||
Animation::Animation():
|
||||
rep( new Rep() ){
|
||||
}
|
||||
|
||||
Animation::Animation( const Animation &t ):
|
||||
rep( t.rep ){
|
||||
++rep->ref_cnt;
|
||||
}
|
||||
|
||||
Animation::Animation( const Animation &t,int first,int last ):
|
||||
rep( new Rep() ){
|
||||
Rep::KeyList::const_iterator it;
|
||||
for( it=t.rep->pos_anim.begin();it!=t.rep->pos_anim.end();++it ){
|
||||
if( it->first<first || it->first>last ) continue;
|
||||
rep->setKey( rep->pos_anim,it->first-first,it->second );
|
||||
}
|
||||
for( it=t.rep->scale_anim.begin();it!=t.rep->scale_anim.end();++it ){
|
||||
if( it->first<first || it->first>last ) continue;
|
||||
rep->setKey( rep->scale_anim,it->first-first,it->second );
|
||||
}
|
||||
for( it=t.rep->rot_anim.begin();it!=t.rep->rot_anim.end();++it ){
|
||||
if( it->first<first || it->first>last ) continue;
|
||||
rep->setKey( rep->rot_anim,it->first-first,it->second );
|
||||
}
|
||||
}
|
||||
|
||||
Animation::~Animation(){
|
||||
if( !--rep->ref_cnt ) delete rep;
|
||||
}
|
||||
|
||||
Animation &Animation::operator=( const Animation &t ){
|
||||
++t.rep->ref_cnt;
|
||||
if( !--rep->ref_cnt ) delete rep;
|
||||
rep=t.rep;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Animation::Rep *Animation::write(){
|
||||
if( rep->ref_cnt>1 ){
|
||||
--rep->ref_cnt;
|
||||
rep=new Rep( *rep );
|
||||
}
|
||||
return rep;
|
||||
}
|
||||
|
||||
void Animation::setScaleKey( int time,const Vector &q ){
|
||||
write();
|
||||
rep->setKey( rep->scale_anim,time,Quat( 0,q ) );
|
||||
}
|
||||
|
||||
void Animation::setPositionKey( int time,const Vector &q ){
|
||||
write();
|
||||
rep->setKey( rep->pos_anim,time,Quat( 0,q ) );
|
||||
}
|
||||
|
||||
void Animation::setRotationKey( int time,const Quat &q ){
|
||||
write();
|
||||
rep->setKey( rep->rot_anim,time,q );
|
||||
}
|
||||
|
||||
int Animation::numScaleKeys()const{
|
||||
return rep->scale_anim.size();
|
||||
}
|
||||
|
||||
int Animation::numRotationKeys()const{
|
||||
return rep->rot_anim.size();
|
||||
}
|
||||
|
||||
int Animation::numPositionKeys()const{
|
||||
return rep->pos_anim.size();
|
||||
}
|
||||
|
||||
Vector Animation::getScale( float time )const{
|
||||
if( !rep->scale_anim.size() ) return Vector(1,1,1);
|
||||
return rep->getLinearValue( rep->scale_anim,time );
|
||||
}
|
||||
|
||||
Vector Animation::getPosition( float time )const{
|
||||
if( !rep->pos_anim.size() ) return Vector(0,0,0);
|
||||
return rep->getLinearValue( rep->pos_anim,time );
|
||||
}
|
||||
|
||||
Quat Animation::getRotation( float time )const{
|
||||
if( !rep->rot_anim.size() ) return Quat();
|
||||
return rep->getSlerpValue( rep->rot_anim,time );
|
||||
}
|
||||
|
||||
/*
|
||||
struct Animation::Rep{
|
||||
|
||||
int ref_cnt;
|
||||
|
||||
struct Key{
|
||||
int time;
|
||||
Quat value;
|
||||
};
|
||||
typedef list<Key> KeyList;
|
||||
|
||||
KeyList scale_anim,rot_anim,pos_anim;
|
||||
|
||||
Rep():
|
||||
ref_cnt(1){
|
||||
}
|
||||
|
||||
Rep( const Rep &t ):
|
||||
ref_cnt(1),
|
||||
scale_anim(t.scale_anim),rot_anim(t.rot_anim),pos_anim(t.pos_anim){
|
||||
}
|
||||
|
||||
Vector getLinearValue( const KeyList &keys,float time )const{
|
||||
if( keys.size()==1 ) return keys.front().value.v;
|
||||
if( time>=keys.back().time ) return keys.back().value.v;
|
||||
if( time<=keys.front().time ) return keys.front().value.v;
|
||||
KeyList::const_iterator it;
|
||||
for( it=keys.begin();time>=it->time;++it ){}
|
||||
const Key *next=&*it;
|
||||
const Key *curr=&*--it;
|
||||
float delta=( time-curr->time )/( next->time-curr->time );
|
||||
return (next->value.v-curr->value.v)*delta+curr->value.v;
|
||||
}
|
||||
|
||||
Quat getSlerpValue( const KeyList &keys,float time )const{
|
||||
if( keys.size()==1 ) return keys.front().value;
|
||||
if( time>=keys.back().time ) return keys.back().value;
|
||||
if( time<=keys.front().time ) return keys.front().value;
|
||||
KeyList::const_iterator it;
|
||||
for( it=keys.begin();time>=it->time;++it ){}
|
||||
const Key *next=&*it;
|
||||
const Key *curr=&*--it;
|
||||
float delta=(time-curr->time)/(next->time-curr->time);
|
||||
return curr->value.slerpTo( next->value,delta );
|
||||
}
|
||||
|
||||
void setKey( KeyList &keys,int time,const Quat &value ){
|
||||
KeyList::iterator it;
|
||||
for( it=keys.begin();it!=keys.end() && time>it->time;++it ){}
|
||||
if( it==keys.end() || time<it->time ){
|
||||
it=keys.insert( it );
|
||||
it->time=time;
|
||||
}
|
||||
it->value=value;
|
||||
}
|
||||
};
|
||||
|
||||
Animation::Animation():
|
||||
rep( d_new Rep() ){
|
||||
}
|
||||
|
||||
Animation::Animation( const Animation &t ):
|
||||
rep( t.rep ){
|
||||
++rep->ref_cnt;
|
||||
}
|
||||
|
||||
Animation::Animation( const Animation &t,int first,int last ):
|
||||
rep( d_new Rep() ){
|
||||
Rep::KeyList::const_iterator it;
|
||||
for( it=t.rep->pos_anim.begin();it!=t.rep->pos_anim.end();++it ){
|
||||
const Rep::Key &key=*it;
|
||||
if( key.time<first || key.time>last ) continue;
|
||||
rep->setKey( rep->pos_anim,key.time-first,key.value );
|
||||
}
|
||||
for( it=t.rep->scale_anim.begin();it!=t.rep->scale_anim.end();++it ){
|
||||
const Rep::Key &key=*it;
|
||||
if( key.time<first || key.time>last ) continue;
|
||||
rep->setKey( rep->scale_anim,key.time-first,key.value );
|
||||
}
|
||||
for( it=t.rep->rot_anim.begin();it!=t.rep->rot_anim.end();++it ){
|
||||
const Rep::Key &key=*it;
|
||||
if( key.time<first || key.time>last ) continue;
|
||||
rep->setKey( rep->rot_anim,key.time-first,key.value );
|
||||
}
|
||||
}
|
||||
|
||||
Animation::~Animation(){
|
||||
if( !--rep->ref_cnt ) delete rep;
|
||||
}
|
||||
|
||||
Animation &Animation::operator=( const Animation &t ){
|
||||
++t.rep->ref_cnt;
|
||||
if( !--rep->ref_cnt ) delete rep;
|
||||
rep=t.rep;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Animation::Rep *Animation::write(){
|
||||
if( rep->ref_cnt>1 ){
|
||||
--rep->ref_cnt;
|
||||
rep=d_new Rep( *rep );
|
||||
}
|
||||
return rep;
|
||||
}
|
||||
|
||||
void Animation::setScaleKey( int time,const Vector &q ){
|
||||
write();
|
||||
rep->setKey( rep->scale_anim,time,Quat( 0,q ) );
|
||||
}
|
||||
|
||||
void Animation::setPositionKey( int time,const Vector &q ){
|
||||
write();
|
||||
rep->setKey( rep->pos_anim,time,Quat( 0,q ) );
|
||||
}
|
||||
|
||||
void Animation::setRotationKey( int time,const Quat &q ){
|
||||
write();
|
||||
rep->setKey( rep->rot_anim,time,q );
|
||||
}
|
||||
|
||||
int Animation::numScaleKeys()const{
|
||||
return rep->scale_anim.size();
|
||||
}
|
||||
|
||||
int Animation::numRotationKeys()const{
|
||||
return rep->rot_anim.size();
|
||||
}
|
||||
|
||||
int Animation::numPositionKeys()const{
|
||||
return rep->pos_anim.size();
|
||||
}
|
||||
|
||||
Vector Animation::getScale( float time )const{
|
||||
if( !rep->scale_anim.size() ) return Vector(1,1,1);
|
||||
return rep->getLinearValue( rep->scale_anim,time );
|
||||
}
|
||||
|
||||
Vector Animation::getPosition( float time )const{
|
||||
if( !rep->pos_anim.size() ) return Vector(0,0,0);
|
||||
return rep->getLinearValue( rep->pos_anim,time );
|
||||
}
|
||||
|
||||
Quat Animation::getRotation( float time )const{
|
||||
if( !rep->rot_anim.size() ) return Quat();
|
||||
return rep->getSlerpValue( rep->rot_anim,time );
|
||||
}
|
||||
*/
|
37
blitz3d/animation.h
Normal file
37
blitz3d/animation.h
Normal file
@ -0,0 +1,37 @@
|
||||
|
||||
#ifndef ANIMATION_H
|
||||
#define ANIMATION_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "geom.h"
|
||||
|
||||
class Animation{
|
||||
public:
|
||||
Animation();
|
||||
Animation( const Animation &t );
|
||||
Animation( const Animation &t,int first,int last );
|
||||
~Animation();
|
||||
|
||||
Animation &operator=( const Animation &t );
|
||||
|
||||
void setScaleKey( int frame,const Vector &q );
|
||||
void setPositionKey( int frame,const Vector &p );
|
||||
void setRotationKey( int frame,const Quat &q );
|
||||
|
||||
int numScaleKeys()const;
|
||||
int numRotationKeys()const;
|
||||
int numPositionKeys()const;
|
||||
|
||||
Vector getScale( float time )const;
|
||||
Vector getPosition( float time )const;
|
||||
Quat getRotation( float time )const;
|
||||
|
||||
private:
|
||||
struct Rep;
|
||||
Rep *rep;
|
||||
|
||||
Rep *write();
|
||||
};
|
||||
|
||||
#endif
|
218
blitz3d/animator.cpp
Normal file
218
blitz3d/animator.cpp
Normal file
@ -0,0 +1,218 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "animator.h"
|
||||
#include "object.h"
|
||||
|
||||
Animator::Animator( Animator *t ):_seqs( t->_seqs ){
|
||||
|
||||
_objs.resize( t->_objs.size() );
|
||||
_anims.resize( t->_anims.size() );
|
||||
|
||||
for( int k=0;k<t->_objs.size();++k ){
|
||||
_objs[k]=t->_objs[k]->getLastCopy();
|
||||
_anims[k].keys=t->_anims[k].keys;
|
||||
}
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
Animator::Animator( Object *obj,int frames ){
|
||||
addObjs( obj );
|
||||
_anims.resize( _objs.size() );
|
||||
addSeq( frames );
|
||||
reset();
|
||||
}
|
||||
|
||||
Animator::Animator( const vector<Object*> &objs,int frames ):_objs(objs){
|
||||
_anims.resize( _objs.size() );
|
||||
addSeq( frames );
|
||||
reset();
|
||||
}
|
||||
|
||||
void Animator::reset(){
|
||||
_seq=_mode=_seq_len=_time=_speed=_trans_time=_trans_speed=0;
|
||||
}
|
||||
|
||||
void Animator::addObjs( Object *obj ){
|
||||
_objs.push_back( obj );
|
||||
for( Entity *e=obj->children();e;e=e->successor() ){
|
||||
addObjs( e->getObject() );
|
||||
}
|
||||
}
|
||||
|
||||
void Animator::addSeq( int frames ){
|
||||
Seq seq;
|
||||
seq.frames=frames;
|
||||
_seqs.push_back( seq );
|
||||
for( int k=0;k<_objs.size();++k ){
|
||||
Object *obj=_objs[k];
|
||||
_anims[k].keys.push_back( obj->getAnimation() );
|
||||
obj->setAnimation( Animation() );
|
||||
}
|
||||
}
|
||||
|
||||
void Animator::addSeqs( Animator *t ){
|
||||
for( int n=0;n<t->_seqs.size();++n ){
|
||||
_seqs.push_back( t->_seqs[n] );
|
||||
for( int k=0;k<_objs.size();++k ){
|
||||
int j;
|
||||
for( j=0;j<t->_objs.size();++j ){
|
||||
if( _objs[k]->getName()==t->_objs[j]->getName() ) break;
|
||||
}
|
||||
if( j==t->_objs.size() ){
|
||||
_anims[k].keys.push_back( Animation() );
|
||||
continue;
|
||||
}
|
||||
_anims[k].keys.push_back( t->_anims[j].keys[n] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Animator::extractSeq( int first,int last,int seq ){
|
||||
Seq sq;
|
||||
sq.frames=last-first;
|
||||
_seqs.push_back( sq );
|
||||
|
||||
for( int k=0;k<_objs.size();++k ){
|
||||
Animation &keys=_anims[k].keys[seq];
|
||||
_anims[k].keys.push_back( Animation( keys,first,last ) );
|
||||
}
|
||||
}
|
||||
|
||||
void Animator::updateAnim(){
|
||||
|
||||
for( int k=0;k<_objs.size();++k ){
|
||||
|
||||
Object *obj=_objs[k];
|
||||
const Animation &keys=_anims[k].keys[_seq];
|
||||
|
||||
if( keys.numPositionKeys() ){
|
||||
obj->setLocalPosition( keys.getPosition( _time ) );
|
||||
}
|
||||
if( keys.numScaleKeys() ){
|
||||
obj->setLocalScale( keys.getScale( _time ) );
|
||||
}
|
||||
if( keys.numRotationKeys() ){
|
||||
obj->setLocalRotation( keys.getRotation( _time ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Animator::updateTrans(){
|
||||
|
||||
for( int k=0;k<_objs.size();++k ){
|
||||
|
||||
Object *obj=_objs[k];
|
||||
const Anim &anim=_anims[k];
|
||||
|
||||
if( anim.pos ) obj->setLocalPosition( (anim.dest_pos-anim.src_pos)*_trans_time+anim.src_pos );
|
||||
if( anim.scl ) obj->setLocalScale( (anim.dest_scl-anim.src_scl)*_trans_time+anim.src_scl );
|
||||
if( anim.rot ) obj->setLocalRotation( anim.src_rot.slerpTo( anim.dest_rot,_trans_time ) );
|
||||
}
|
||||
}
|
||||
|
||||
void Animator::beginTrans(){
|
||||
|
||||
for( int k=0;k<_objs.size();++k ){
|
||||
|
||||
Object *obj=_objs[k];
|
||||
Anim &anim=_anims[k];
|
||||
const Animation &keys=_anims[k].keys[_seq];
|
||||
|
||||
if( anim.pos=!!keys.numPositionKeys() ){
|
||||
anim.src_pos=obj->getLocalPosition();
|
||||
anim.dest_pos=keys.getPosition( _time );
|
||||
}
|
||||
if( anim.scl=!!keys.numScaleKeys() ){
|
||||
anim.src_scl=obj->getLocalScale();
|
||||
anim.dest_scl=keys.getScale( _time );
|
||||
}
|
||||
if( anim.rot=!!keys.numRotationKeys() ){
|
||||
anim.src_rot=obj->getLocalRotation();
|
||||
anim.dest_rot=keys.getRotation( _time );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Animator::setAnimTime( float time,int seq ){
|
||||
if( seq<0 || seq>_seqs.size() ) return;
|
||||
|
||||
_mode=0;
|
||||
_speed=0;
|
||||
_seq=seq;
|
||||
_seq_len=_seqs[_seq].frames;
|
||||
|
||||
//Ok, mod the anim time!
|
||||
_time=fmod( time,_seq_len );
|
||||
|
||||
//if( time<0 || time>_seq_len ) time=fmod( time,_seq_len );
|
||||
//_time=time;
|
||||
|
||||
if( _time<0 ) _time+=+_seq_len;
|
||||
|
||||
updateAnim();
|
||||
}
|
||||
|
||||
void Animator::animate( int mode,float speed,int seq,float trans ){
|
||||
if( !mode && !speed ){ _mode=0;return; }
|
||||
|
||||
if( seq<0 || seq>=_seqs.size() ) return;
|
||||
|
||||
_seq=seq;
|
||||
_mode=mode;
|
||||
_seq_len=_seqs[_seq].frames;
|
||||
_speed=speed;
|
||||
_time=_speed>=0 ? 0 : _seq_len;
|
||||
|
||||
if( trans<=0 ){
|
||||
updateAnim();
|
||||
if( !_speed ) _mode=0;
|
||||
return;
|
||||
}
|
||||
|
||||
_mode|=0x8000;
|
||||
_trans_time=0;
|
||||
_trans_speed=1/trans;
|
||||
beginTrans();
|
||||
}
|
||||
|
||||
void Animator::update( float elapsed ){
|
||||
|
||||
if( !_mode ) return;
|
||||
|
||||
if( _mode&0x8000 ){
|
||||
_trans_time+=_trans_speed*elapsed;
|
||||
if( _trans_time<1 ){
|
||||
updateTrans();
|
||||
return;
|
||||
}
|
||||
_mode&=0x7fff;
|
||||
if( !_mode || !_speed ){
|
||||
updateAnim();
|
||||
_mode=0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//do anim...
|
||||
_time+=_speed*elapsed;
|
||||
|
||||
switch( _mode ){
|
||||
case ANIM_MODE_LOOP:
|
||||
_time=fmod( _time,_seq_len );
|
||||
if( _time<0 ) _time+=_seq_len;
|
||||
break;
|
||||
case ANIM_MODE_PINGPONG:
|
||||
_time=fmod( _time,_seq_len*2 );
|
||||
if( _time<0 ) _time+=_seq_len*2;
|
||||
if( _time>=_seq_len ){ _time=_seq_len-(_time-_seq_len);_speed=-_speed; }
|
||||
break;
|
||||
case ANIM_MODE_ONESHOT:
|
||||
if( _time<0 ){ _time=0;_mode=0; }
|
||||
else if( _time>=_seq_len ){ _time=_seq_len;_mode=0; }
|
||||
break;
|
||||
}
|
||||
|
||||
updateAnim();
|
||||
}
|
||||
|
74
blitz3d/animator.h
Normal file
74
blitz3d/animator.h
Normal file
@ -0,0 +1,74 @@
|
||||
|
||||
#ifndef ANIMATOR_H
|
||||
#define ANIMATOR_H
|
||||
|
||||
#include "animation.h"
|
||||
|
||||
class Object;
|
||||
|
||||
class Animator{
|
||||
public:
|
||||
enum{
|
||||
ANIM_MODE_LOOP=1,
|
||||
ANIM_MODE_PINGPONG=2,
|
||||
ANIM_MODE_ONESHOT=3
|
||||
};
|
||||
|
||||
Animator( Animator *animator );
|
||||
|
||||
Animator( Object *tree,int frames );
|
||||
|
||||
Animator( const vector<Object*> &objs,int frames );
|
||||
|
||||
void addSeq( int frames );
|
||||
|
||||
void addSeqs( Animator *t );
|
||||
|
||||
void extractSeq( int first,int last,int seq );
|
||||
|
||||
void setAnimTime( float time,int seq );
|
||||
|
||||
void animate( int mode,float speed,int seq,float trans );
|
||||
|
||||
void update( float elapsed );
|
||||
|
||||
int animSeq()const{ return _seq; }
|
||||
int animLen()const{ return _seq_len; }
|
||||
float animTime()const{ return _time; }
|
||||
bool animating()const{ return !!_mode; }
|
||||
|
||||
int numSeqs()const{ return _seqs.size(); }
|
||||
const vector<Object*> &getObjects()const{ return _objs; }
|
||||
|
||||
private:
|
||||
struct Seq{
|
||||
int frames;
|
||||
};
|
||||
|
||||
struct Anim{
|
||||
//anim keys
|
||||
vector<Animation> keys;
|
||||
//for transitions...
|
||||
bool pos,scl,rot;
|
||||
Vector src_pos,dest_pos;
|
||||
Vector src_scl,dest_scl;
|
||||
Quat src_rot,dest_rot;
|
||||
Anim():pos(false),scl(false),rot(false){}
|
||||
};
|
||||
|
||||
vector<Seq> _seqs;
|
||||
|
||||
vector<Anim> _anims;
|
||||
vector<Object*> _objs;
|
||||
|
||||
int _seq,_mode,_seq_len;
|
||||
float _time,_speed,_trans_time,_trans_speed;
|
||||
|
||||
void reset();
|
||||
void addObjs( Object *obj );
|
||||
void updateAnim();
|
||||
void beginTrans();
|
||||
void updateTrans();
|
||||
};
|
||||
|
||||
#endif
|
27
blitz3d/bd2model.cpp
Normal file
27
blitz3d/bd2model.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
#include "bd2model.h"
|
||||
|
||||
struct BD2Vert{
|
||||
unsigned char x,y,z,n,u,v;
|
||||
};
|
||||
|
||||
struct BD2Tri{
|
||||
unsigned short v0,v1,v2;
|
||||
};
|
||||
|
||||
struct BD2Frame{
|
||||
float x_scale,y_scale,z_scale;
|
||||
float x_offset,y_offset,z_offset;
|
||||
BD2Vert verts[1];
|
||||
};
|
||||
|
||||
struct BD2File{
|
||||
int id; //'BD2F'
|
||||
float u_scale,v_scale;
|
||||
int n_verts,n_tris,n_frames;
|
||||
BD2Tri tris[1];
|
||||
BD2Frame frames[1];
|
||||
};
|
||||
|
||||
struct BD2Model::Rep{
|
||||
};
|
13
blitz3d/bd2model.h
Normal file
13
blitz3d/bd2model.h
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
#ifndef BD2MODEL_H
|
||||
#define BD2MODEL_H
|
||||
|
||||
class BD2Model : public Model{
|
||||
public:
|
||||
private:
|
||||
struct Rep;
|
||||
Rep *rep;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
510
blitz3d/blitz3d.dsp
Normal file
510
blitz3d/blitz3d.dsp
Normal file
@ -0,0 +1,510 @@
|
||||
# Microsoft Developer Studio Project File - Name="blitz3d" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Static Library" 0x0104
|
||||
|
||||
CFG=blitz3d - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "blitz3d.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "blitz3d.mak" CFG="blitz3d - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "blitz3d - Win32 Release" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "blitz3d - Win32 Debug" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "blitz3d - Win32 Blitz3DRelease" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "blitz3d - Win32 Blitz2DRelease" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "blitz3d - Win32 Blitz3DEdu" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE "blitz3d - Win32 Blitz3DDemo" (based on "Win32 (x86) Static Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "blitz3d - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Yu"std.h" /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz3d - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz3d - Win32 Blitz3DRelease"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "blitz3d___Win32_Blitz3DRelease"
|
||||
# PROP BASE Intermediate_Dir "blitz3d___Win32_Blitz3DRelease"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "blitz3d___Win32_Blitz3DRelease"
|
||||
# PROP Intermediate_Dir "blitz3d___Win32_Blitz3DRelease"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Yu"std.h" /FD /c
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "_LIB" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /FD /c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz3d - Win32 Blitz2DRelease"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "blitz3d___Win32_Blitz2DRelease"
|
||||
# PROP BASE Intermediate_Dir "blitz3d___Win32_Blitz2DRelease"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "blitz3d___Win32_Blitz2DRelease"
|
||||
# PROP Intermediate_Dir "blitz3d___Win32_Blitz2DRelease"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Yu"std.h" /FD /c
|
||||
# ADD CPP /nologo /G6 /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /Yu"std.h" /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz3d - Win32 Blitz3DEdu"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "blitz3d___Win32_Blitz3DEdu"
|
||||
# PROP BASE Intermediate_Dir "blitz3d___Win32_Blitz3DEdu"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "blitz3d___Win32_Blitz3DEdu"
|
||||
# PROP Intermediate_Dir "blitz3d___Win32_Blitz3DEdu"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "PRO" /Yu"std.h" /FD /c
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "_LIB" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /D "EDU" /Yu"std.h" /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz3d - Win32 Blitz3DDemo"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "blitz3d___Win32_Blitz3DDemo"
|
||||
# PROP BASE Intermediate_Dir "blitz3d___Win32_Blitz3DDemo"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "blitz3d___Win32_Blitz3DDemo"
|
||||
# PROP Intermediate_Dir "blitz3d___Win32_Blitz3DDemo"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /D "PRO" /Yu"std.h" /FD /c
|
||||
# ADD CPP /nologo /G6 /Gz /MT /W3 /GX /O2 /Ob2 /D "_LIB" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "PRO" /D "DEMO" /Yu"std.h" /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LIB32=link.exe -lib
|
||||
# ADD BASE LIB32 /nologo
|
||||
# ADD LIB32 /nologo
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "blitz3d - Win32 Release"
|
||||
# Name "blitz3d - Win32 Debug"
|
||||
# Name "blitz3d - Win32 Blitz3DRelease"
|
||||
# Name "blitz3d - Win32 Blitz2DRelease"
|
||||
# Name "blitz3d - Win32 Blitz3DEdu"
|
||||
# Name "blitz3d - Win32 Blitz3DDemo"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\animation.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\animator.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\brush.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\cachedtexture.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\camera.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\collision.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\entity.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\frustum.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\geom.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\light.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\listener.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\loader_3ds.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\loader_b3d.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\loader_x.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\md2model.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\md2norms.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\md2rep.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\meshcollider.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\meshloader.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\meshmodel.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\meshutil.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mirror.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\model.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\object.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\pivot.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\planemodel.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\q3bspmodel.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\q3bsprep.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sprite.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\std.cpp
|
||||
|
||||
!IF "$(CFG)" == "blitz3d - Win32 Release"
|
||||
|
||||
# ADD CPP /Yc"std.h"
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz3d - Win32 Debug"
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz3d - Win32 Blitz3DRelease"
|
||||
|
||||
# ADD BASE CPP /Yc"std.h"
|
||||
# ADD CPP /Yc"std.h"
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz3d - Win32 Blitz2DRelease"
|
||||
|
||||
# ADD BASE CPP /Yc"std.h"
|
||||
# ADD CPP /Yc"std.h"
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz3d - Win32 Blitz3DEdu"
|
||||
|
||||
# ADD BASE CPP /Yc"std.h"
|
||||
# ADD CPP /Yc"std.h"
|
||||
|
||||
!ELSEIF "$(CFG)" == "blitz3d - Win32 Blitz3DDemo"
|
||||
|
||||
# ADD BASE CPP /Yc"std.h"
|
||||
# ADD CPP /Yc"std.h"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\surface.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\terrain.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\terrainrep.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\texture.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\world.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\animation.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\animator.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\blitz3d.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\brush.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\cachedtexture.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\camera.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\collision.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\entity.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\frustum.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\geom.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\light.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\listener.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\loader_3ds.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\loader_b3d.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\loader_x.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\md2model.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\md2norms.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\md2rep.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\meshcollider.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\meshloader.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\meshmodel.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\meshutil.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\mirror.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\model.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\object.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\pivot.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\planemodel.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\q3bspmodel.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\q3bsprep.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\rendercontext.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\sprite.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\std.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\surface.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\terrain.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\terrainrep.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\texture.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\world.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
5
blitz3d/blitz3d.h
Normal file
5
blitz3d/blitz3d.h
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
#ifndef BLITZ3D_H
|
||||
#define BLITZ3D_H
|
||||
|
||||
#endif
|
201
blitz3d/boxvis.cpp
Normal file
201
blitz3d/boxvis.cpp
Normal file
@ -0,0 +1,201 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "world.h"
|
||||
|
||||
static World *w;
|
||||
|
||||
struct Face{
|
||||
Vector verts[4];
|
||||
|
||||
Face( const Vector &v0,const Vector &v1,const Vector &v2,const Vector &v3 ){
|
||||
verts[0]=v0;
|
||||
verts[1]=v1;
|
||||
verts[2]=v2;
|
||||
verts[3]=v3;
|
||||
}
|
||||
};
|
||||
|
||||
static int face_verts[][4]={
|
||||
2,3,1,0,
|
||||
3,7,5,1,
|
||||
7,6,4,5,
|
||||
6,2,0,4,
|
||||
6,7,3,2,
|
||||
0,1,5,4
|
||||
};
|
||||
|
||||
struct Coll{
|
||||
int obj,surf,tri;
|
||||
Coll( const ObjCollision &t ):obj((int)t.with),surf((int)t.collision.surface),tri(t.collision.index){
|
||||
}
|
||||
};
|
||||
|
||||
struct CollCmp{
|
||||
bool operator()( const Coll &a,const Coll &b )const{
|
||||
if( a.obj<b.obj ) return true;
|
||||
if( b.obj<a.obj ) return false;
|
||||
if( a.surf<b.surf ) return true;
|
||||
if( b.surf<a.surf ) return false;
|
||||
if( a.tri<b.tri ) return true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
typedef set<Coll,CollCmp> CollSet;
|
||||
|
||||
//returns: 1 for visible, 0 for hidden, -1 for don't know
|
||||
static int faceVis( const Face &src,const Face &dest ){
|
||||
|
||||
static CollSet all;
|
||||
static CollSet colls[16];
|
||||
|
||||
all.clear();
|
||||
|
||||
for( int k=0;k<4;++k ){
|
||||
for( int j=0;j<4;++j ){
|
||||
int n=k*4+j;
|
||||
colls[n].clear();
|
||||
|
||||
Vector sv=src.verts[k];
|
||||
Vector dv=dest.verts[j];
|
||||
Vector adj=(dv-sv).normalized()*.01f;
|
||||
dv-=adj;
|
||||
|
||||
for(;;){
|
||||
sv+=adj;
|
||||
Line line( sv,dv-sv );
|
||||
|
||||
ObjCollision c;
|
||||
if( !w->traceRay( line,EPSILON,&c ) ) break;
|
||||
|
||||
Coll t( c );
|
||||
all.insert( t );
|
||||
colls[n].insert( t );
|
||||
|
||||
sv=c.coords;
|
||||
}
|
||||
if( !colls[n].size() ) return 1;
|
||||
}
|
||||
}
|
||||
CollSet::const_iterator it;
|
||||
for( it=all.begin();it!=all.end();++it ){
|
||||
int k=0;
|
||||
for( ;k<16;++k ){
|
||||
if( !colls[k].count( *it ) ) break;
|
||||
}
|
||||
if( k==16 ) return 0; //definitely hidden!
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void subdivide( list<Face> &lst ){
|
||||
int n=lst.size();
|
||||
while( n-- ){
|
||||
const Face &f=lst.front();
|
||||
Vector a( (f.verts[0]+f.verts[1])/2 );
|
||||
Vector b( (f.verts[1]+f.verts[2])/2 );
|
||||
Vector c( (f.verts[2]+f.verts[3])/2 );
|
||||
Vector d( (f.verts[3]+f.verts[0])/2 );
|
||||
Vector e( (f.verts[0]+f.verts[1]+f.verts[2]+f.verts[3])/4 );
|
||||
lst.push_back( Face( f.verts[0],a,e,d ) );
|
||||
lst.push_back( Face( a,f.verts[1],b,e ) );
|
||||
lst.push_back( Face( e,b,f.verts[2],c ) );
|
||||
lst.push_back( Face( d,e,c,f.verts[3] ) );
|
||||
lst.erase( lst.begin() );
|
||||
}
|
||||
}
|
||||
|
||||
static int faceVis( const Face &src,const Face &dest,int recurs_limit ){
|
||||
|
||||
static list<Face> src_faces,dest_faces;
|
||||
|
||||
src_faces.clear();
|
||||
dest_faces.clear();
|
||||
|
||||
src_faces.push_back( src );
|
||||
dest_faces.push_back( dest );
|
||||
|
||||
while( recurs_limit-- ){
|
||||
list<Face>::iterator src_it,dest_it;
|
||||
for( src_it=src_faces.begin();src_it!=src_faces.end();++src_it ){
|
||||
int cnt=0;
|
||||
for( dest_it=dest_faces.begin();dest_it!=dest_faces.end();++dest_it ){
|
||||
int n=faceVis( *src_it,*dest_it );
|
||||
if( n==1 ) return 1;
|
||||
if( !n ) ++cnt;
|
||||
}
|
||||
if( cnt==dest_faces.size() ){
|
||||
//source can't see ANY dest faces
|
||||
src_it=src_faces.erase( src_it );
|
||||
--src_it;
|
||||
}
|
||||
}
|
||||
if( !src_faces.size() ) return 0;
|
||||
//ok, subdivide!
|
||||
subdivide( src_faces );
|
||||
subdivide( dest_faces );
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool World::boxVis( const Box &src,const Box &dest,int recurs_limit ){
|
||||
|
||||
w=this;
|
||||
|
||||
Box big;
|
||||
|
||||
big.update( src );
|
||||
big.update( dest );
|
||||
|
||||
Plane planes[6];
|
||||
|
||||
for( int n=0;n<6;++n ){
|
||||
planes[n]=Plane(
|
||||
big.corner( face_verts[n][0] ),
|
||||
big.corner( face_verts[n][1] ),
|
||||
big.corner( face_verts[n][2] ));
|
||||
}
|
||||
|
||||
for( int k=0;k<6;++k ){
|
||||
Vector v0=src.corner( face_verts[k][0] );
|
||||
Vector v1=src.corner( face_verts[k][1] );
|
||||
Vector v2=src.corner( face_verts[k][2] );
|
||||
Vector v3=src.corner( face_verts[k][3] );
|
||||
|
||||
int n;
|
||||
for( n=0;n<6;++n ){
|
||||
const Plane &p=planes[n];
|
||||
if( fabs(p.distance(v0))<=EPSILON &&
|
||||
fabs(p.distance(v1))<=EPSILON &&
|
||||
fabs(p.distance(v2))<=EPSILON &&
|
||||
fabs(p.distance(v3))<=EPSILON ) break;
|
||||
}
|
||||
if( n<6 ) continue;
|
||||
|
||||
Face src_face( v0,v1,v2,v3 );
|
||||
|
||||
for( int j=0;j<6;++j ){
|
||||
Vector v0=dest.corner( face_verts[j][0] );
|
||||
Vector v1=dest.corner( face_verts[j][1] );
|
||||
Vector v2=dest.corner( face_verts[j][2] );
|
||||
Vector v3=dest.corner( face_verts[j][3] );
|
||||
|
||||
int n;
|
||||
for( n=0;n<6;++n ){
|
||||
const Plane &p=planes[n];
|
||||
if( fabs(p.distance(v0))<=EPSILON &&
|
||||
fabs(p.distance(v1))<=EPSILON &&
|
||||
fabs(p.distance(v2))<=EPSILON &&
|
||||
fabs(p.distance(v3))<=EPSILON ) break;
|
||||
}
|
||||
if( n<6 ) continue;
|
||||
|
||||
Face dest_face( v0,v1,v2,v3 );
|
||||
|
||||
int t=faceVis( src_face,dest_face,recurs_limit );
|
||||
|
||||
if( t ) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
211
blitz3d/brush.cpp
Normal file
211
blitz3d/brush.cpp
Normal file
@ -0,0 +1,211 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "brush.h"
|
||||
|
||||
#include "../gxruntime/gxgraphics.h"
|
||||
|
||||
struct Brush::Rep{
|
||||
union{ int ref_cnt;Rep *next; };
|
||||
int blend,max_tex;
|
||||
bool blend_valid;
|
||||
gxScene::RenderState rs;
|
||||
Texture texs[gxScene::MAX_TEXTURES];
|
||||
|
||||
static Rep *pool;
|
||||
|
||||
Rep():
|
||||
ref_cnt(1),blend(0),max_tex(0),blend_valid(true){
|
||||
memset( &rs,0,sizeof(rs) );
|
||||
rs.blend=gxScene::BLEND_REPLACE;
|
||||
rs.color[0]=rs.color[1]=rs.color[2]=rs.alpha=1;
|
||||
}
|
||||
|
||||
Rep( const Rep &t ):
|
||||
ref_cnt(1),blend(t.blend),max_tex(t.max_tex),rs(t.rs),blend_valid(t.blend_valid){
|
||||
for( int k=0;k<max_tex;++k ) texs[k]=t.texs[k];
|
||||
}
|
||||
|
||||
void *operator new( size_t sz ){
|
||||
static const int GROW=64;
|
||||
if( !pool ){
|
||||
pool=new Rep[GROW];
|
||||
for( int k=0;k<GROW-1;++k ) pool[k].next=&pool[k+1];
|
||||
pool[GROW-1].next=0;
|
||||
}
|
||||
Rep *p=pool;
|
||||
pool=p->next;
|
||||
return p;
|
||||
}
|
||||
|
||||
void operator delete( void *q ){
|
||||
Rep *p=(Rep*)q;
|
||||
p->next=pool;
|
||||
pool=p;
|
||||
}
|
||||
};
|
||||
|
||||
Brush::Rep *Brush::Rep::pool;
|
||||
|
||||
Brush::Brush():
|
||||
rep( new Rep() ){
|
||||
}
|
||||
|
||||
Brush::Brush( const Brush &t ):
|
||||
rep( t.rep ){
|
||||
++rep->ref_cnt;
|
||||
}
|
||||
|
||||
Brush::Brush( const Brush &a,const Brush &b ):
|
||||
rep( new Rep( *a.rep ) ){
|
||||
|
||||
*(Vector*)rep->rs.color*=*(Vector*)b.rep->rs.color;
|
||||
|
||||
rep->rs.alpha*=b.rep->rs.alpha;
|
||||
rep->rs.shininess+=b.rep->rs.shininess;
|
||||
|
||||
if( b.rep->blend ) rep->blend=b.rep->blend;
|
||||
|
||||
rep->rs.fx|=b.rep->rs.fx;
|
||||
|
||||
if( b.rep->max_tex>rep->max_tex ) rep->max_tex=b.rep->max_tex;
|
||||
|
||||
for( int k=0;k<rep->max_tex;++k ){
|
||||
if( b.rep->rs.tex_states[k].canvas ){
|
||||
rep->rs.tex_states[k].canvas=b.rep->rs.tex_states[k].canvas;
|
||||
rep->texs[k]=b.rep->texs[k];
|
||||
}
|
||||
}
|
||||
|
||||
rep->blend_valid=false;
|
||||
}
|
||||
|
||||
Brush::~Brush(){
|
||||
if( !--rep->ref_cnt ) delete rep;
|
||||
}
|
||||
|
||||
Brush &Brush::operator=( const Brush &t ){
|
||||
++t.rep->ref_cnt;
|
||||
if( !--rep->ref_cnt ) delete rep;
|
||||
rep=t.rep;return *this;
|
||||
}
|
||||
|
||||
Brush::Rep *Brush::write()const{
|
||||
if( rep->ref_cnt>1 ){
|
||||
--rep->ref_cnt;
|
||||
rep=new Rep( *rep );
|
||||
}
|
||||
return rep;
|
||||
}
|
||||
|
||||
void Brush::setColor( const Vector &color ){
|
||||
*(Vector*)write()->rs.color=color;
|
||||
}
|
||||
|
||||
void Brush::setAlpha( float alpha ){
|
||||
float a=rep->rs.alpha;
|
||||
write()->rs.alpha=alpha;
|
||||
if( (a<1)!=(alpha<1) ) rep->blend_valid=false;
|
||||
}
|
||||
|
||||
void Brush::setShininess( float n ){
|
||||
write()->rs.shininess=n;
|
||||
}
|
||||
|
||||
void Brush::setBlend( int blend ){
|
||||
write()->blend=blend;
|
||||
rep->blend_valid=false;
|
||||
}
|
||||
|
||||
void Brush::setFX( int fx ){
|
||||
write()->rs.fx=fx;
|
||||
rep->blend_valid=false;
|
||||
}
|
||||
|
||||
void Brush::setTexture( int index,const Texture &t,int n ){
|
||||
write();
|
||||
gxScene::RenderState &rs=rep->rs;
|
||||
|
||||
rep->texs[index]=t;
|
||||
rs.tex_states[index].canvas=t.getCanvas( n );
|
||||
|
||||
rep->max_tex=0;
|
||||
for( int k=0;k<gxScene::MAX_TEXTURES;++k ){
|
||||
if( rs.tex_states[k].canvas ) rep->max_tex=k+1;
|
||||
}
|
||||
rep->blend_valid=false;
|
||||
}
|
||||
|
||||
const Vector &Brush::getColor()const{
|
||||
return *(Vector*)rep->rs.color;
|
||||
}
|
||||
|
||||
float Brush::getAlpha()const{
|
||||
return rep->rs.alpha;
|
||||
}
|
||||
|
||||
float Brush::getShininess()const{
|
||||
return rep->rs.shininess;
|
||||
}
|
||||
|
||||
int Brush::getBlend()const{
|
||||
if( rep->blend_valid ) return rep->rs.blend;
|
||||
|
||||
rep->blend_valid=true; //well, it will be...
|
||||
|
||||
gxScene::RenderState &rs=rep->rs;
|
||||
|
||||
//alphatest
|
||||
if( rep->texs[0].getCanvasFlags() & gxCanvas::CANVAS_TEX_MASK ){
|
||||
rs.fx|=gxScene::FX_ALPHATEST;
|
||||
}else{
|
||||
rs.fx&=~gxScene::FX_ALPHATEST;
|
||||
}
|
||||
|
||||
//0 = default/replace
|
||||
//1 = alpha
|
||||
//2 = multiply
|
||||
//3 = add
|
||||
if( rep->blend ){
|
||||
if( rep->blend!=gxScene::BLEND_ALPHA ){
|
||||
return rs.blend=rep->blend;
|
||||
}
|
||||
for( int k=0;k<rep->max_tex;++k ){
|
||||
if( rep->texs[k].isTransparent() ){
|
||||
return rs.blend=gxScene::BLEND_ALPHA;
|
||||
}
|
||||
}
|
||||
}else if( rep->max_tex==1 && rep->texs[0].isTransparent() ){
|
||||
//single transparent texture?
|
||||
return rs.blend=gxScene::BLEND_ALPHA;
|
||||
}
|
||||
|
||||
//vertex alpha or entityalpha?
|
||||
if( (rs.fx&gxScene::FX_VERTEXALPHA) || rs.alpha<1 ){
|
||||
return rs.blend=gxScene::BLEND_ALPHA;
|
||||
}
|
||||
|
||||
return rs.blend=gxScene::BLEND_REPLACE;
|
||||
}
|
||||
|
||||
int Brush::getFX()const{
|
||||
return rep->rs.fx;
|
||||
}
|
||||
|
||||
Texture Brush::getTexture( int index )const{
|
||||
return rep->texs[index];
|
||||
}
|
||||
|
||||
const gxScene::RenderState &Brush::getRenderState()const{
|
||||
getBlend();
|
||||
for( int k=0;k<rep->max_tex;++k ){
|
||||
gxScene::RenderState::TexState *ts=&rep->rs.tex_states[k];
|
||||
ts->matrix=rep->texs[k].getMatrix();
|
||||
ts->blend=rep->texs[k].getBlend();
|
||||
ts->flags=rep->texs[k].getFlags();
|
||||
}
|
||||
return rep->rs;
|
||||
}
|
||||
|
||||
bool Brush::operator<( const Brush &t )const{
|
||||
return memcmp( &getRenderState(),&t.getRenderState(),sizeof(gxScene::RenderState) )<0;
|
||||
}
|
42
blitz3d/brush.h
Normal file
42
blitz3d/brush.h
Normal file
@ -0,0 +1,42 @@
|
||||
|
||||
#ifndef BRUSH_H
|
||||
#define BRUSH_H
|
||||
|
||||
#include "geom.h"
|
||||
#include "texture.h"
|
||||
|
||||
class Brush{
|
||||
public:
|
||||
Brush();
|
||||
Brush( const Brush &t );
|
||||
Brush( const Brush &a,const Brush &b );
|
||||
~Brush();
|
||||
|
||||
Brush &operator=( const Brush &t );
|
||||
|
||||
void setColor( const Vector &color );
|
||||
void setAlpha( float alpha );
|
||||
void setShininess( float shininess );
|
||||
void setBlend( int blend );
|
||||
void setFX( int fx );
|
||||
void setTexture( int index,const Texture &t,int frame );
|
||||
|
||||
const Vector &getColor()const;
|
||||
float getAlpha()const;
|
||||
float getShininess()const;
|
||||
int getBlend()const;
|
||||
int getFX()const;
|
||||
Texture getTexture( int index )const;
|
||||
|
||||
const gxScene::RenderState &getRenderState()const;
|
||||
|
||||
bool operator<( const Brush &b )const;
|
||||
|
||||
private:
|
||||
struct Rep;
|
||||
mutable Rep *rep;
|
||||
|
||||
Rep *write()const;
|
||||
};
|
||||
|
||||
#endif
|
165
blitz3d/cachedtexture.cpp
Normal file
165
blitz3d/cachedtexture.cpp
Normal file
@ -0,0 +1,165 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "cachedtexture.h"
|
||||
|
||||
int active_texs;
|
||||
|
||||
extern gxRuntime *gx_runtime;
|
||||
extern gxGraphics *gx_graphics;
|
||||
|
||||
set<CachedTexture::Rep*> CachedTexture::rep_set;
|
||||
|
||||
static string path;
|
||||
|
||||
struct CachedTexture::Rep{
|
||||
int ref_cnt;
|
||||
string file;
|
||||
int flags,w,h,first;
|
||||
vector<gxCanvas*> frames;
|
||||
|
||||
Rep( int w,int h,int flags,int cnt ):
|
||||
ref_cnt(1),flags(flags),w(w),h(h),first(0){
|
||||
++active_texs;
|
||||
while( cnt-->0 ){
|
||||
if( gxCanvas *t=gx_graphics->createCanvas( w,h,flags ) ){
|
||||
frames.push_back( t );
|
||||
}else break;
|
||||
}
|
||||
}
|
||||
|
||||
Rep( const string &f,int flags,int w,int h,int first,int cnt ):
|
||||
ref_cnt(1),file(f),flags(flags),w(w),h(h),first(first){
|
||||
++active_texs;
|
||||
if( !(flags & gxCanvas::CANVAS_TEX_CUBE) ){
|
||||
if( w<=0 || h<=0 || first<0 || cnt<=0 ){
|
||||
w=h=first=0;
|
||||
if( gxCanvas *t=gx_graphics->loadCanvas( f,flags ) ){
|
||||
frames.push_back( t );
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int t_flags=flags & (
|
||||
gxCanvas::CANVAS_TEX_RGB|
|
||||
gxCanvas::CANVAS_TEX_ALPHA|
|
||||
gxCanvas::CANVAS_TEX_MASK|
|
||||
gxCanvas::CANVAS_TEX_HICOLOR ) | gxCanvas::CANVAS_NONDISPLAY;
|
||||
|
||||
gxCanvas *t=gx_graphics->loadCanvas( f,t_flags );
|
||||
if( !t ) return;
|
||||
if( !t->getDepth() ){
|
||||
gx_graphics->freeCanvas( t );
|
||||
return;
|
||||
}
|
||||
|
||||
if( flags & gxCanvas::CANVAS_TEX_CUBE ){
|
||||
int w=t->getWidth()/6;
|
||||
if( w*6!=t->getWidth() ) return;
|
||||
int h=t->getHeight();
|
||||
|
||||
gxCanvas *tex=gx_graphics->createCanvas( w,h,flags );
|
||||
if( tex ){
|
||||
frames.push_back( tex );
|
||||
|
||||
for( int face=0;face<6;++face ){
|
||||
tex->setCubeFace(face);
|
||||
gx_graphics->copy( tex,0,0,tex->getWidth(),tex->getHeight(),t,face*w,0,w,h );
|
||||
}
|
||||
tex->setCubeFace(1);
|
||||
}
|
||||
}else{
|
||||
int x_tiles=t->getWidth()/w;
|
||||
int y_tiles=t->getHeight()/h;
|
||||
if( first+cnt>x_tiles*y_tiles ){
|
||||
gx_graphics->freeCanvas( t );
|
||||
return;
|
||||
}
|
||||
int x=(first%x_tiles)*w;
|
||||
int y=(first/x_tiles)*h;
|
||||
while( cnt-- ){
|
||||
gxCanvas *p=gx_graphics->createCanvas( w,h,flags );
|
||||
gx_graphics->copy( p,0,0,p->getWidth(),p->getHeight(),t,x,y,w,h );
|
||||
frames.push_back(p);
|
||||
x=x+w;if( x+w>t->getWidth() ){ x=0;y=y+h; }
|
||||
}
|
||||
}
|
||||
gx_graphics->freeCanvas( t );
|
||||
}
|
||||
|
||||
~Rep(){
|
||||
--active_texs;
|
||||
for( int k=0;k<frames.size();++k ) gx_graphics->freeCanvas( frames[k] );
|
||||
}
|
||||
};
|
||||
|
||||
CachedTexture::Rep *CachedTexture::findRep( const string &f,int flags,int w,int h,int first,int cnt ){
|
||||
set<Rep*>::const_iterator it;
|
||||
for( it=rep_set.begin();it!=rep_set.end();++it ){
|
||||
Rep *rep=*it;
|
||||
if( rep->file==f && rep->flags==flags && rep->w==w && rep->h==h && rep->first==first && rep->frames.size()==cnt ){
|
||||
++rep->ref_cnt;return rep;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
CachedTexture::CachedTexture( int w,int h,int flags,int cnt ):
|
||||
rep(d_new Rep(w,h,flags,cnt)){
|
||||
}
|
||||
|
||||
CachedTexture::CachedTexture( const string &f_,int flags,int w,int h,int first,int cnt ){
|
||||
string f=f_;
|
||||
if( f.substr(0,2)==".\\" ) f=f.substr(2);
|
||||
if( path.size() ){
|
||||
string t=path+tolower( filenamefile( f ) );
|
||||
if( rep=findRep( t,flags,w,h,first,cnt ) ) return;
|
||||
rep=d_new Rep( t,flags,w,h,first,cnt );
|
||||
if( rep->frames.size() ){
|
||||
rep_set.insert( rep );
|
||||
return;
|
||||
}
|
||||
delete rep;
|
||||
}
|
||||
string t=tolower( fullfilename( f ) );
|
||||
if( rep=findRep( t,flags,w,h,first,cnt ) ) return;
|
||||
rep=d_new Rep( t,flags,w,h,first,cnt );
|
||||
rep_set.insert( rep );
|
||||
}
|
||||
|
||||
CachedTexture::CachedTexture( const CachedTexture &t ):
|
||||
rep(t.rep){
|
||||
++rep->ref_cnt;
|
||||
}
|
||||
|
||||
CachedTexture::~CachedTexture(){
|
||||
if( !--rep->ref_cnt ){
|
||||
rep_set.erase( rep );
|
||||
delete rep;
|
||||
}
|
||||
}
|
||||
|
||||
CachedTexture &CachedTexture::operator=( const CachedTexture &t ){
|
||||
++t.rep->ref_cnt;
|
||||
if( !--rep->ref_cnt ){
|
||||
rep_set.erase( rep );
|
||||
delete rep;
|
||||
}
|
||||
rep=t.rep;
|
||||
return *this;
|
||||
}
|
||||
|
||||
string CachedTexture::getName()const{
|
||||
return rep->file;
|
||||
}
|
||||
|
||||
const vector<gxCanvas*> &CachedTexture::getFrames()const{
|
||||
return rep->frames;
|
||||
}
|
||||
|
||||
void CachedTexture::setPath( const string &t ){
|
||||
path=tolower(t);
|
||||
if( int sz=path.size() ){
|
||||
if( path[sz-1]!='/' && path[sz-1]!='\\' ) path+='\\';
|
||||
}
|
||||
}
|
33
blitz3d/cachedtexture.h
Normal file
33
blitz3d/cachedtexture.h
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
#ifndef CACHEDTEXTURE_H
|
||||
#define CACHEDTEXTURE_H
|
||||
|
||||
#include "../gxruntime/gxcanvas.h"
|
||||
|
||||
class CachedTexture{
|
||||
public:
|
||||
CachedTexture( int w,int h,int flags,int cnt );
|
||||
CachedTexture( const string &f,int flags,int w,int h,int first,int cnt );
|
||||
CachedTexture( const CachedTexture &t );
|
||||
~CachedTexture();
|
||||
|
||||
CachedTexture &operator=( const CachedTexture &t );
|
||||
|
||||
string getName()const;
|
||||
|
||||
const vector<gxCanvas*> &getFrames()const;
|
||||
|
||||
bool operator<( const CachedTexture &t )const{ return rep<t.rep; }
|
||||
|
||||
static void setPath( const string &t );
|
||||
|
||||
private:
|
||||
struct Rep;
|
||||
Rep *rep;
|
||||
|
||||
Rep *findRep( const string &f,int flags,int w,int h,int first,int cnt );
|
||||
|
||||
static set<Rep*> rep_set;
|
||||
};
|
||||
|
||||
#endif
|
103
blitz3d/camera.cpp
Normal file
103
blitz3d/camera.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "camera.h"
|
||||
|
||||
extern gxScene *gx_scene;
|
||||
|
||||
Camera::Camera(){
|
||||
setZoom( 1 );
|
||||
setRange( 1,1000 );
|
||||
setViewport( 0,0,0,0 );
|
||||
setClsColor( Vector() );
|
||||
setClsMode( true,true );
|
||||
setProjMode( PROJ_PERSP );
|
||||
setFogRange( 1,1000 );
|
||||
setFogColor( Vector() );
|
||||
setFogMode( gxScene::FOG_NONE );
|
||||
}
|
||||
|
||||
void Camera::setZoom( float z ){
|
||||
zoom=z;
|
||||
local_valid=false;
|
||||
}
|
||||
|
||||
void Camera::setRange( float n,float f ){
|
||||
frustum_nr=n;frustum_fr=f;
|
||||
local_valid=false;
|
||||
}
|
||||
|
||||
void Camera::setViewport( int x,int y,int w,int h ){
|
||||
vp_x=x;vp_y=y;vp_w=w;vp_h=h;
|
||||
local_valid=false;
|
||||
}
|
||||
|
||||
void Camera::setClsColor( const Vector &v ){
|
||||
cls_color=v;
|
||||
}
|
||||
|
||||
void Camera::setClsMode( bool c,bool z ){
|
||||
cls_argb=c;cls_z=z;
|
||||
}
|
||||
|
||||
void Camera::setProjMode( int mode ){
|
||||
proj_mode=mode;
|
||||
}
|
||||
|
||||
void Camera::setFogColor( const Vector &v ){
|
||||
fog_color=v;
|
||||
}
|
||||
|
||||
void Camera::setFogRange( float nr,float fr ){
|
||||
fog_nr=nr;fog_fr=fr;
|
||||
}
|
||||
|
||||
void Camera::setFogMode( int mode ){
|
||||
fog_mode=mode;
|
||||
}
|
||||
|
||||
const Frustum &Camera::getFrustum()const{
|
||||
if( !local_valid ){
|
||||
float ar=(float)vp_h/vp_w;
|
||||
frustum_w=frustum_nr*2/zoom;
|
||||
frustum_h=frustum_nr*2/zoom*ar;
|
||||
new( &local_frustum ) Frustum( frustum_nr,frustum_fr,frustum_w,frustum_h );
|
||||
local_valid=true;
|
||||
}
|
||||
return local_frustum;
|
||||
}
|
||||
|
||||
float Camera::getFrustumNear()const{
|
||||
return frustum_nr;
|
||||
}
|
||||
|
||||
float Camera::getFrustumFar()const{
|
||||
return frustum_fr;
|
||||
}
|
||||
|
||||
float Camera::getFrustumWidth()const{
|
||||
getFrustum();return frustum_w;
|
||||
}
|
||||
|
||||
float Camera::getFrustumHeight()const{
|
||||
getFrustum();return frustum_h;
|
||||
}
|
||||
|
||||
void Camera::getViewport( int *x,int *y,int *w,int *h )const{
|
||||
*x=vp_x;*y=vp_y;*w=vp_w;*h=vp_h;
|
||||
}
|
||||
|
||||
bool Camera::beginRenderFrame(){
|
||||
if( !proj_mode ) return false;
|
||||
getFrustum();
|
||||
gx_scene->setViewport( vp_x,vp_y,vp_w,vp_h );
|
||||
gx_scene->clear( &(cls_color.x),1,1,cls_argb,cls_z );
|
||||
if( proj_mode==PROJ_ORTHO ){
|
||||
gx_scene->setOrthoProj( frustum_nr,frustum_fr,frustum_w,frustum_h );
|
||||
}else{
|
||||
gx_scene->setPerspProj( frustum_nr,frustum_fr,frustum_w,frustum_h );
|
||||
}
|
||||
gx_scene->setFogRange( fog_nr,fog_fr );
|
||||
gx_scene->setFogColor( (float*)&fog_color.x );
|
||||
gx_scene->setFogMode( fog_mode );
|
||||
return true;
|
||||
}
|
56
blitz3d/camera.h
Normal file
56
blitz3d/camera.h
Normal file
@ -0,0 +1,56 @@
|
||||
|
||||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
|
||||
#include "model.h"
|
||||
#include "frustum.h"
|
||||
#include "mirror.h"
|
||||
|
||||
class Camera : public Object{
|
||||
public:
|
||||
enum{
|
||||
PROJ_NONE=0,PROJ_PERSP=1,PROJ_ORTHO=2
|
||||
};
|
||||
|
||||
Camera();
|
||||
Camera *getCamera(){ return this; }
|
||||
|
||||
//called by user
|
||||
void setZoom( float z );
|
||||
void setRange( float nr,float fr );
|
||||
void setViewport( int x,int y,int w,int h );
|
||||
void setClsColor( const Vector &v );
|
||||
void setClsMode( bool cls_argb,bool cls_z );
|
||||
void setProjMode( int mode );
|
||||
void setFogColor( const Vector &v );
|
||||
void setFogRange( float nr,float fr );
|
||||
void setFogMode( int mode );
|
||||
|
||||
//called by world
|
||||
bool beginRenderFrame();
|
||||
|
||||
//Camera frustum...
|
||||
float getFrustumNear()const;
|
||||
float getFrustumFar()const;
|
||||
float getFrustumWidth()const;
|
||||
float getFrustumHeight()const;
|
||||
const Frustum &getFrustum()const;
|
||||
void getViewport( int *x,int *y,int *w,int *h )const;
|
||||
int getProjMode()const{ return proj_mode; }
|
||||
|
||||
private:
|
||||
float zoom;
|
||||
int vp_x,vp_y,vp_w,vp_h;
|
||||
Vector cls_color;
|
||||
bool cls_argb,cls_z;
|
||||
int proj_mode;
|
||||
Vector fog_color;
|
||||
float fog_nr,fog_fr;
|
||||
int fog_mode;
|
||||
float frustum_nr,frustum_fr;
|
||||
mutable float frustum_w,frustum_h;
|
||||
mutable Frustum local_frustum;
|
||||
mutable bool local_valid;
|
||||
};
|
||||
|
||||
#endif
|
361
blitz3d/collision.cpp
Normal file
361
blitz3d/collision.cpp
Normal file
@ -0,0 +1,361 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "collision.h"
|
||||
|
||||
const float COLLISION_EPSILON=.001f;
|
||||
|
||||
/*
|
||||
//
|
||||
// OLD VERSION
|
||||
//
|
||||
bool Collision::sphereCollide( const Line &line,float radius,const Vector &dest,float dest_radius ){
|
||||
|
||||
radius+=dest_radius;
|
||||
Line l( line.o-dest,line.d );
|
||||
|
||||
float a=l.d.dot(l.d);
|
||||
if( !a ) return false;
|
||||
float b=l.o.dot(l.d)*2;
|
||||
float c=l.o.dot(l.o)-radius*radius;
|
||||
float d=b*b-4*a*c;
|
||||
if( d<0 ) return false;
|
||||
float t1=(-b+sqrt(d))/(2*a);
|
||||
float t2=(-b-sqrt(d))/(2*a);
|
||||
|
||||
float t=t1<t2 ? t1 : t2;
|
||||
if( t<0 || t>=time ) return false;
|
||||
|
||||
time=t;
|
||||
normal=(l*t).normalized();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Collision::sphereCollide( const Line &line,float radius,const Vector &dest,const Vector &radii ){
|
||||
|
||||
radius+=radii.x;
|
||||
|
||||
Line l( line.o-dest,line.d );
|
||||
|
||||
// float y_scale=1;
|
||||
// if( radii.x!=radii.y ){
|
||||
// y_scale=radii.x/radii.y;
|
||||
// l.o.y*=y_scale;
|
||||
// l.d.y*=y_scale;
|
||||
// }
|
||||
|
||||
float a=l.d.dot(l.d);
|
||||
if( !a ) return false;
|
||||
float b=l.o.dot(l.d)*2;
|
||||
float c=l.o.dot(l.o)-radius*radius;
|
||||
float d=b*b-4*a*c;
|
||||
if( d<0 ) return false;
|
||||
float t1=(-b+sqrt(d))/(2*a);
|
||||
float t2=(-b-sqrt(d))/(2*a);
|
||||
|
||||
float t=t1<t2 ? t1 : t2;
|
||||
if( t<0 || t>=time ) return false;
|
||||
|
||||
time=t;
|
||||
normal=(l*t).normalized();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//v0,v1 = edge verts
|
||||
//pn = poly normal
|
||||
//en = edge normal
|
||||
static bool edgeTest( const Vector &v0,const Vector &v1,const Vector &pn,const Vector &en,const Line &line,float radius,Collision *curr_coll ){
|
||||
|
||||
Matrix tm=~Matrix( en,(v1-v0).normalized(),pn );
|
||||
Vector sv=tm*(line.o-v0),dv=tm*(line.o+line.d-v0);
|
||||
Line l( sv,dv-sv );
|
||||
//do cylinder test...
|
||||
float a,b,c,d,t1,t2,t;
|
||||
a=(l.d.x*l.d.x+l.d.z*l.d.z);
|
||||
if( !a ) return false; //ray parallel to cylinder
|
||||
b=(l.o.x*l.d.x+l.o.z*l.d.z)*2;
|
||||
c=(l.o.x*l.o.x+l.o.z*l.o.z)-radius*radius;
|
||||
d=b*b-4*a*c;
|
||||
if( d<0 ) return false; //ray misses cylinder
|
||||
t1=(-b+sqrt(d))/(2*a);
|
||||
t2=(-b-sqrt(d))/(2*a);
|
||||
t=t1<t2 ? t1 : t2;
|
||||
if( t>curr_coll->time ) return false; //intersects too far away
|
||||
Vector i=l*t,p;
|
||||
if( i.y>v0.distance(v1) ) return false; //intersection above cylinder
|
||||
if( i.y>=0 ){
|
||||
if( t<0 ) return false;
|
||||
p.y=i.y;
|
||||
}else{
|
||||
//below bottom of cylinder...do sphere test...
|
||||
a=l.d.dot(l.d);
|
||||
if( !a ) return false; //ray parallel to sphere
|
||||
b=l.o.dot(l.d)*2;
|
||||
c=l.o.dot(l.o)-radius*radius;
|
||||
d=b*b-4*a*c;
|
||||
if( d<0 ) return false; //ray misses sphere
|
||||
t1=(-b+sqrt(d))/(2*a);
|
||||
t2=(-b-sqrt(d))/(2*a);
|
||||
t=t1<t2 ? t1 : t2;
|
||||
if( t<0 || t>curr_coll->time ) return false; //intersects behind or too far away
|
||||
i=l*t;
|
||||
}
|
||||
curr_coll->time=t;
|
||||
curr_coll->normal=~tm*(i-p);
|
||||
curr_coll->normal.normalize();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Collision::triangleCollide( const Line &line,float radius,const Vector &v0,const Vector &v1,const Vector &v2 ){
|
||||
|
||||
//triangle plane
|
||||
Plane p( v0,v1,v2 );
|
||||
if( p.n.dot( line.d )>=0 ) return false;
|
||||
|
||||
//intersection time
|
||||
Plane tp=p;tp.d-=radius;
|
||||
float t=tp.t_intersect( line );
|
||||
if( t>time ) return false;
|
||||
|
||||
//intersection point
|
||||
Plane p0( v0+p.n,v1,v0 ),p1( v1+p.n,v2,v1 ),p2( v2+p.n,v0,v2 );
|
||||
|
||||
if( t>=0 ){
|
||||
Vector i=line*t;
|
||||
if( p0.distance(i)>=0 && p1.distance(i)>=0 && p2.distance(i)>=0 ){
|
||||
time=t;
|
||||
normal=p.n;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if( radius<=0 ) return false;
|
||||
|
||||
return
|
||||
edgeTest( v0,v1,p.n,p0.n,line,radius,this )|
|
||||
edgeTest( v1,v2,p.n,p1.n,line,radius,this )|
|
||||
edgeTest( v2,v0,p.n,p2.n,line,radius,this );
|
||||
}
|
||||
|
||||
bool Collision::boxCollide( const Line &line,float radius,const Box &box ){
|
||||
|
||||
static int quads[]={
|
||||
2,3,1,0,
|
||||
3,7,5,1,
|
||||
7,6,4,5,
|
||||
6,2,0,4,
|
||||
6,7,3,2,
|
||||
0,1,5,4
|
||||
};
|
||||
|
||||
bool hit=false;
|
||||
|
||||
for( int n=0;n<24;n+=4 ){
|
||||
Vector
|
||||
v0( box.corner( quads[n] ) ),
|
||||
v1( box.corner( quads[n+1] ) ),
|
||||
v2( box.corner( quads[n+2] ) ),
|
||||
v3( box.corner( quads[n+3] ) );
|
||||
|
||||
//quad plane
|
||||
Plane p( v0,v1,v2 );
|
||||
if( p.n.dot( line.d )>=0 ) continue;
|
||||
|
||||
p.d-=radius;
|
||||
float t=p.t_intersect( line );
|
||||
if( t>time ) continue;
|
||||
|
||||
//intersection point
|
||||
Plane
|
||||
p0( v0+p.n,v1,v0 ),
|
||||
p1( v1+p.n,v2,v1 ),
|
||||
p2( v2+p.n,v3,v2 ),
|
||||
p3( v3+p.n,v0,v3 );
|
||||
|
||||
if( t>=0 ){
|
||||
Vector i=line*t;
|
||||
if( p0.distance(i)>=0 && p1.distance(i)>=0 && p2.distance(i)>=0 && p3.distance(i)>=0 ){
|
||||
time=t;
|
||||
normal=p.n;
|
||||
hit=true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if( radius<=0 ) continue;
|
||||
|
||||
hit|=
|
||||
edgeTest( v0,v1,p.n,p0.n,line,radius,this )|
|
||||
edgeTest( v1,v2,p.n,p1.n,line,radius,this )|
|
||||
edgeTest( v2,v3,p.n,p2.n,line,radius,this )|
|
||||
edgeTest( v3,v0,p.n,p3.n,line,radius,this );
|
||||
}
|
||||
return hit;
|
||||
}
|
||||
*/
|
||||
|
||||
bool Collision::update( const Line &line,float t,const Vector &n ){
|
||||
|
||||
// if( t<0 || t>time ) return false;
|
||||
|
||||
if( t>time ) return false;
|
||||
Plane p(line*t,n);
|
||||
if( p.n.dot( line.d )>=0 ) return false;
|
||||
if( p.distance(line.o)<-COLLISION_EPSILON ) return false;
|
||||
|
||||
time=t;
|
||||
normal=n;
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// NEW VERSION
|
||||
//
|
||||
extern gxRuntime *gx_runtime;
|
||||
|
||||
bool Collision::sphereCollide( const Line &line,float radius,const Vector &dest,float dest_radius ){
|
||||
|
||||
radius+=dest_radius;
|
||||
Line l( line.o-dest,line.d );
|
||||
|
||||
float a=l.d.dot(l.d);
|
||||
if( !a ) return false;
|
||||
float b=l.o.dot(l.d)*2;
|
||||
float c=l.o.dot(l.o)-radius*radius;
|
||||
float d=b*b-4*a*c;
|
||||
if( d<0 ) return false;
|
||||
|
||||
float t1=(-b+sqrt(d))/(2*a);
|
||||
float t2=(-b-sqrt(d))/(2*a);
|
||||
|
||||
float t=t1<t2 ? t1 : t2;
|
||||
|
||||
if( t>time ) return false;
|
||||
|
||||
return update( line,t,(l*t).normalized() );
|
||||
}
|
||||
|
||||
//v0,v1 = edge verts
|
||||
//pn = poly normal
|
||||
//en = edge normal
|
||||
static bool edgeTest( const Vector &v0,const Vector &v1,const Vector &pn,const Vector &en,const Line &line,float radius,Collision *curr_coll ){
|
||||
|
||||
Matrix tm=~Matrix( en,(v1-v0).normalized(),pn );
|
||||
Vector sv=tm*(line.o-v0),dv=tm*(line.o+line.d-v0);
|
||||
Line l( sv,dv-sv );
|
||||
//do cylinder test...
|
||||
float a,b,c,d,t1,t2,t;
|
||||
a=(l.d.x*l.d.x+l.d.z*l.d.z);
|
||||
if( !a ) return false; //ray parallel to cylinder
|
||||
b=(l.o.x*l.d.x+l.o.z*l.d.z)*2;
|
||||
c=(l.o.x*l.o.x+l.o.z*l.o.z)-radius*radius;
|
||||
d=b*b-4*a*c;
|
||||
if( d<0 ) return false; //ray misses cylinder
|
||||
t1=(-b+sqrt(d))/(2*a);
|
||||
t2=(-b-sqrt(d))/(2*a);
|
||||
t=t1<t2 ? t1 : t2;
|
||||
if( t>curr_coll->time ) return false; //intersects too far away
|
||||
Vector i=l*t,p;
|
||||
if( i.y>v0.distance(v1) ) return false; //intersection above cylinder
|
||||
if( i.y>=0 ){
|
||||
p.y=i.y;
|
||||
}else{
|
||||
//below bottom of cylinder...do sphere test...
|
||||
a=l.d.dot(l.d);
|
||||
if( !a ) return false; //ray parallel to sphere
|
||||
b=l.o.dot(l.d)*2;
|
||||
c=l.o.dot(l.o)-radius*radius;
|
||||
d=b*b-4*a*c;
|
||||
if( d<0 ) return false; //ray misses sphere
|
||||
t1=(-b+sqrt(d))/(2*a);
|
||||
t2=(-b-sqrt(d))/(2*a);
|
||||
t=t1<t2 ? t1 : t2;
|
||||
if( t>curr_coll->time ) return false;
|
||||
i=l*t;
|
||||
}
|
||||
|
||||
return curr_coll->update( line,t,(~tm*(i-p)).normalized() );
|
||||
}
|
||||
|
||||
bool Collision::triangleCollide( const Line &line,float radius,const Vector &v0,const Vector &v1,const Vector &v2 ){
|
||||
|
||||
//triangle plane
|
||||
Plane p( v0,v1,v2 );
|
||||
if( p.n.dot( line.d )>=0 ) return false;
|
||||
|
||||
//move plane out
|
||||
p.d-=radius;
|
||||
float t=p.t_intersect( line );
|
||||
if( t>time ) return false;
|
||||
|
||||
//edge planes
|
||||
Plane p0( v0+p.n,v1,v0 ),p1( v1+p.n,v2,v1 ),p2( v2+p.n,v0,v2 );
|
||||
|
||||
//intersects triangle?
|
||||
Vector i=line*t;
|
||||
if( p0.distance(i)>=0 && p1.distance(i)>=0 && p2.distance(i)>=0 ){
|
||||
return update( line,t,p.n );
|
||||
}
|
||||
|
||||
if( radius<=0 ) return false;
|
||||
|
||||
return
|
||||
edgeTest( v0,v1,p.n,p0.n,line,radius,this )|
|
||||
edgeTest( v1,v2,p.n,p1.n,line,radius,this )|
|
||||
edgeTest( v2,v0,p.n,p2.n,line,radius,this );
|
||||
}
|
||||
|
||||
bool Collision::boxCollide( const Line &line,float radius,const Box &box ){
|
||||
|
||||
static int quads[]={
|
||||
2,3,1,0,
|
||||
3,7,5,1,
|
||||
7,6,4,5,
|
||||
6,2,0,4,
|
||||
6,7,3,2,
|
||||
0,1,5,4
|
||||
};
|
||||
|
||||
bool hit=false;
|
||||
|
||||
for( int n=0;n<24;n+=4 ){
|
||||
Vector
|
||||
v0( box.corner( quads[n] ) ),
|
||||
v1( box.corner( quads[n+1] ) ),
|
||||
v2( box.corner( quads[n+2] ) ),
|
||||
v3( box.corner( quads[n+3] ) );
|
||||
|
||||
//quad plane
|
||||
Plane p( v0,v1,v2 );
|
||||
if( p.n.dot( line.d )>=0 ) continue;
|
||||
|
||||
//move plane out
|
||||
p.d-=radius;
|
||||
float t=p.t_intersect( line );
|
||||
if( t>time ) return false;
|
||||
|
||||
//edge planes
|
||||
Plane
|
||||
p0( v0+p.n,v1,v0 ),
|
||||
p1( v1+p.n,v2,v1 ),
|
||||
p2( v2+p.n,v3,v2 ),
|
||||
p3( v3+p.n,v0,v3 );
|
||||
|
||||
//intersects triangle?
|
||||
Vector i=line*t;
|
||||
if( p0.distance(i)>=0 && p1.distance(i)>=0 && p2.distance(i)>=0 && p3.distance(i)>=0 ){
|
||||
hit|=update( line,t,p.n );
|
||||
continue;
|
||||
}
|
||||
|
||||
if( radius<=0 ) continue;
|
||||
|
||||
hit|=
|
||||
edgeTest( v0,v1,p.n,p0.n,line,radius,this )|
|
||||
edgeTest( v1,v2,p.n,p1.n,line,radius,this )|
|
||||
edgeTest( v2,v3,p.n,p2.n,line,radius,this )|
|
||||
edgeTest( v3,v0,p.n,p3.n,line,radius,this );
|
||||
}
|
||||
return hit;
|
||||
}
|
27
blitz3d/collision.h
Normal file
27
blitz3d/collision.h
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
#ifndef COLLISION_H
|
||||
#define COLLISION_H
|
||||
|
||||
#include "geom.h"
|
||||
|
||||
extern const float COLLISION_EPSILON;
|
||||
|
||||
struct Collision{
|
||||
float time;
|
||||
Vector normal;
|
||||
void *surface;
|
||||
unsigned short index;
|
||||
|
||||
Collision():time(1),surface(0),index(~0){}
|
||||
|
||||
bool update( const Line &line,float time,const Vector &normal );
|
||||
|
||||
bool sphereCollide( const Line &src_line,float src_radius,const Vector &dest,float dest_radius );
|
||||
bool sphereCollide( const Line &line,float radius,const Vector &dest,const Vector &radii );
|
||||
|
||||
bool triangleCollide( const Line &src_line,float src_radius,const Vector &v0,const Vector &v1,const Vector &v2 );
|
||||
|
||||
bool boxCollide( const Line &src_line,float src_radius,const Box &box );
|
||||
};
|
||||
|
||||
#endif
|
42
blitz3d/emitter.cpp
Normal file
42
blitz3d/emitter.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "emitter.h"
|
||||
|
||||
Emitter::Emitter(){
|
||||
}
|
||||
|
||||
Emitter::Emitter( const Emitter &t ){
|
||||
}
|
||||
|
||||
Emitter::~Emitter(){
|
||||
}
|
||||
|
||||
void Emitter::beginRender( float tween ){
|
||||
Object::beginRender( tween );
|
||||
|
||||
vel=getRenderTform().v-pos;
|
||||
pos=getRenderTform().v;
|
||||
|
||||
for( int k=0;k<channels.size();++k ){
|
||||
gxChannel *chan=channels[k];
|
||||
if( !chan->isPlaying() ){
|
||||
channels[k]=0;
|
||||
continue;
|
||||
}
|
||||
chan->set3d( &pos.x,&vel.x );
|
||||
}
|
||||
}
|
||||
|
||||
gxChannel *Emitter::emitSound( gxSound *sound ){
|
||||
|
||||
gxChannel *chan=sound->play3d( &pos.x,&vel.x );
|
||||
|
||||
for( int k=0;k<channels.size();++k ){
|
||||
if( chan=channels[k] ) return chan;
|
||||
if( channels[k] ) continue;
|
||||
channels[k]=chan;
|
||||
return chan;
|
||||
}
|
||||
channels.push_back( chan );
|
||||
return chan;
|
||||
}
|
32
blitz3d/emitter.h
Normal file
32
blitz3d/emitter.h
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
#ifndef EMITTER_H
|
||||
#define EMITTER_H
|
||||
|
||||
#include "object.h"
|
||||
|
||||
class gxSound;
|
||||
class gxChannel;
|
||||
|
||||
class Emitter : public Object{
|
||||
public:
|
||||
Emitter();
|
||||
Emitter( const Emitter &t );
|
||||
~Emitter();
|
||||
|
||||
//Entity interface
|
||||
Entity *clone(){ return d_new Emitter( *this ); }
|
||||
Emitter *getEmitter(){ return this; }
|
||||
|
||||
//Object interface
|
||||
void beginRender( float tween );
|
||||
|
||||
//Public interface
|
||||
gxChannel *emitSound( gxSound *sound );
|
||||
|
||||
private:
|
||||
Vector pos,vel;
|
||||
|
||||
vector<gxChannel*> channels;
|
||||
};
|
||||
|
||||
#endif
|
197
blitz3d/entity.cpp
Normal file
197
blitz3d/entity.cpp
Normal file
@ -0,0 +1,197 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "entity.h"
|
||||
|
||||
#include "stats.h"
|
||||
|
||||
Entity *Entity::_orphans,*Entity::_last_orphan;
|
||||
|
||||
enum{
|
||||
INVALID_LOCALTFORM=1,
|
||||
INVALID_WORLDTFORM=2
|
||||
};
|
||||
|
||||
void Entity::remove(){
|
||||
if( _parent ){
|
||||
if( _parent->_children==this ) _parent->_children=_succ;
|
||||
if( _parent->_last_child==this ) _parent->_last_child=_pred;
|
||||
}else{
|
||||
if( _orphans==this ) _orphans=_succ;
|
||||
if( _last_orphan==this ) _last_orphan=_pred;
|
||||
}
|
||||
if( _succ ) _succ->_pred=_pred;
|
||||
if( _pred ) _pred->_succ=_succ;
|
||||
}
|
||||
|
||||
void Entity::insert(){
|
||||
_succ=0;
|
||||
if( _parent ){
|
||||
if( _pred=_parent->_last_child ) _pred->_succ=this;
|
||||
else _parent->_children=this;
|
||||
_parent->_last_child=this;
|
||||
}else{
|
||||
if( _pred=_last_orphan ) _pred->_succ=this;
|
||||
else _orphans=this;
|
||||
_last_orphan=this;
|
||||
}
|
||||
}
|
||||
|
||||
Entity::Entity():
|
||||
_succ(0),_pred(0),_parent(0),_children(0),_last_child(0),
|
||||
_visible(true),_enabled(true),
|
||||
local_scl(1,1,1),
|
||||
invalid(0){
|
||||
insert();
|
||||
}
|
||||
|
||||
Entity::Entity( const Entity &e ):
|
||||
_succ(0),_pred(0),_parent(0),_children(0),_last_child(0),
|
||||
_name(e._name),_visible(e._visible),_enabled(e._enabled),
|
||||
local_pos(e.local_pos),
|
||||
local_scl(e.local_scl),
|
||||
local_rot(e.local_rot),
|
||||
invalid( INVALID_LOCALTFORM|INVALID_WORLDTFORM ){
|
||||
insert();
|
||||
}
|
||||
|
||||
Entity::~Entity(){
|
||||
while( children() ) delete children();
|
||||
remove();
|
||||
}
|
||||
|
||||
void Entity::invalidateWorld(){
|
||||
if( invalid & INVALID_WORLDTFORM ) return;
|
||||
invalid|=INVALID_WORLDTFORM;
|
||||
for( Entity *e=_children;e;e=e->_succ ){
|
||||
e->invalidateWorld();
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::invalidateLocal(){
|
||||
invalid|=INVALID_LOCALTFORM;
|
||||
invalidateWorld();
|
||||
}
|
||||
|
||||
const Transform &Entity::getLocalTform()const{
|
||||
if( invalid&INVALID_LOCALTFORM ){
|
||||
local_tform.m=Matrix( local_rot );
|
||||
local_tform.m.i*=local_scl.x;
|
||||
local_tform.m.j*=local_scl.y;
|
||||
local_tform.m.k*=local_scl.z;
|
||||
local_tform.v=local_pos;
|
||||
invalid&=~INVALID_LOCALTFORM;
|
||||
}
|
||||
return local_tform;
|
||||
}
|
||||
|
||||
const Transform &Entity::getWorldTform()const{
|
||||
if( invalid&INVALID_WORLDTFORM ){
|
||||
world_tform=_parent ? _parent->getWorldTform() * getLocalTform() : getLocalTform();
|
||||
invalid&=~INVALID_WORLDTFORM;
|
||||
}
|
||||
return world_tform;
|
||||
}
|
||||
|
||||
void Entity::setParent( Entity *p ){
|
||||
if( _parent==p ) return;
|
||||
|
||||
remove();
|
||||
|
||||
_parent=p;
|
||||
|
||||
insert();
|
||||
|
||||
invalidateWorld();
|
||||
}
|
||||
|
||||
void Entity::setName( const string &t ){
|
||||
_name=t;
|
||||
}
|
||||
|
||||
void Entity::setVisible( bool visible ){
|
||||
_visible=visible;
|
||||
}
|
||||
|
||||
void Entity::setEnabled( bool enabled ){
|
||||
_enabled=enabled;
|
||||
}
|
||||
|
||||
void Entity::enumVisible( vector<Object*> &out ){
|
||||
if( !_visible ) return;
|
||||
if( Object *o=getObject() ) out.push_back(o);
|
||||
for( Entity *e=_children;e;e=e->_succ ){
|
||||
e->enumVisible( out );
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::enumEnabled( vector<Object*> &out ){
|
||||
if( !_enabled ) return;
|
||||
if( Object *o=getObject() ) out.push_back(o);
|
||||
for( Entity *e=_children;e;e=e->_succ ){
|
||||
e->enumEnabled( out );
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::setLocalPosition( const Vector &v ){
|
||||
local_pos=v;
|
||||
invalidateLocal();
|
||||
}
|
||||
|
||||
void Entity::setLocalScale( const Vector &v ){
|
||||
local_scl=v;
|
||||
invalidateLocal();
|
||||
}
|
||||
|
||||
void Entity::setLocalRotation( const Quat &q ){
|
||||
local_rot=q.normalized();
|
||||
invalidateLocal();
|
||||
}
|
||||
|
||||
void Entity::setLocalTform( const Transform &t ){
|
||||
local_pos=t.v;
|
||||
local_scl=Vector( t.m.i.length(),t.m.j.length(),t.m.k.length() );
|
||||
local_rot=matrixQuat( t.m );
|
||||
invalidateLocal();
|
||||
}
|
||||
|
||||
void Entity::setWorldPosition( const Vector &v ){
|
||||
setLocalPosition( _parent ? -_parent->getWorldTform() * v : v );
|
||||
}
|
||||
|
||||
void Entity::setWorldScale( const Vector &v ){
|
||||
setLocalScale( _parent ? v/_parent->getWorldScale() : v );
|
||||
}
|
||||
|
||||
void Entity::setWorldRotation( const Quat &q ){
|
||||
setLocalRotation( _parent ? -_parent->getWorldRotation() * q : q );
|
||||
}
|
||||
|
||||
void Entity::setWorldTform( const Transform &t ){
|
||||
setLocalTform( _parent ? -_parent->getWorldTform() * t : t );
|
||||
}
|
||||
|
||||
const Vector &Entity::getLocalPosition()const{
|
||||
return local_pos;
|
||||
}
|
||||
|
||||
const Vector &Entity::getLocalScale()const{
|
||||
return local_scl;
|
||||
}
|
||||
|
||||
const Quat &Entity::getLocalRotation()const{
|
||||
return local_rot;
|
||||
}
|
||||
|
||||
const Vector &Entity::getWorldPosition()const{
|
||||
return getWorldTform().v;
|
||||
}
|
||||
|
||||
const Vector &Entity::getWorldScale()const{
|
||||
world_scl=_parent ? _parent->getWorldScale() * local_scl : local_scl;
|
||||
return world_scl;
|
||||
}
|
||||
|
||||
const Quat &Entity::getWorldRotation()const{
|
||||
world_rot=_parent ? _parent->getWorldRotation() * local_rot : local_rot;
|
||||
return world_rot;
|
||||
}
|
101
blitz3d/entity.h
Normal file
101
blitz3d/entity.h
Normal file
@ -0,0 +1,101 @@
|
||||
|
||||
#ifndef ENTITY_H
|
||||
#define ENTITY_H
|
||||
|
||||
#include <list>
|
||||
|
||||
#include "geom.h"
|
||||
|
||||
class Entity;
|
||||
class Object;
|
||||
class Camera;
|
||||
class Light;
|
||||
class Model;
|
||||
class Mirror;
|
||||
class Listener;
|
||||
class MeshModel;
|
||||
class MD2Model;
|
||||
|
||||
class Entity{
|
||||
public:
|
||||
|
||||
Entity();
|
||||
Entity( const Entity &e );
|
||||
virtual ~Entity();
|
||||
|
||||
virtual Entity *clone()=0;
|
||||
|
||||
//ugly casts!
|
||||
virtual Object *getObject(){ return 0; }
|
||||
virtual Camera *getCamera(){ return 0; }
|
||||
virtual Light *getLight(){ return 0; }
|
||||
virtual Model *getModel(){ return 0; }
|
||||
virtual Mirror *getMirror(){ return 0; }
|
||||
virtual Listener *getListener(){ return 0; }
|
||||
|
||||
void setName( const std::string &t );
|
||||
void setParent( Entity *parent );
|
||||
|
||||
void setVisible( bool vis );
|
||||
void setEnabled( bool ena );
|
||||
|
||||
bool visible()const{ return _visible; }
|
||||
bool enabled()const{ return _enabled; }
|
||||
|
||||
void enumVisible( vector<Object*> &out );
|
||||
void enumEnabled( vector<Object*> &out );
|
||||
|
||||
Entity *children()const{ return _children; }
|
||||
Entity *successor()const{ return _succ; }
|
||||
|
||||
std::string getName()const{ return _name; }
|
||||
Entity *getParent()const{ return _parent; }
|
||||
|
||||
void setLocalPosition( const Vector &v );
|
||||
void setLocalScale( const Vector & v );
|
||||
void setLocalRotation( const Quat &q );
|
||||
void setLocalTform( const Transform &t );
|
||||
|
||||
void setWorldPosition( const Vector &v );
|
||||
void setWorldScale( const Vector &v );
|
||||
void setWorldRotation( const Quat &q );
|
||||
void setWorldTform( const Transform &t );
|
||||
|
||||
const Vector &getLocalPosition()const;
|
||||
const Vector &getLocalScale()const;
|
||||
const Quat &getLocalRotation()const;
|
||||
const Transform &getLocalTform()const;
|
||||
|
||||
const Vector &getWorldPosition()const;
|
||||
const Vector &getWorldScale()const;
|
||||
const Quat &getWorldRotation()const;
|
||||
const Transform &getWorldTform()const;
|
||||
|
||||
static Entity *orphans(){ return _orphans; }
|
||||
|
||||
private:
|
||||
Entity *_succ,*_pred,*_parent,*_children,*_last_child;
|
||||
|
||||
static Entity *_orphans,*_last_orphan;
|
||||
|
||||
bool _visible,_enabled;
|
||||
|
||||
std::string _name;
|
||||
|
||||
mutable int invalid;
|
||||
|
||||
Quat local_rot;
|
||||
Vector local_pos,local_scl;
|
||||
mutable Transform local_tform;
|
||||
|
||||
mutable Quat world_rot;
|
||||
mutable Vector world_pos,world_scl;
|
||||
mutable Transform world_tform;
|
||||
|
||||
void insert();
|
||||
void remove();
|
||||
void invalidateLocal();
|
||||
void invalidateWorld();
|
||||
};
|
||||
|
||||
#endif
|
0
blitz3d/entityutil.h
Normal file
0
blitz3d/entityutil.h
Normal file
54
blitz3d/frustum.cpp
Normal file
54
blitz3d/frustum.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "frustum.h"
|
||||
|
||||
Frustum::Frustum(){
|
||||
}
|
||||
|
||||
Frustum::Frustum( float nr,float fr,float w,float h ){
|
||||
verts[VERT_TLNEAR]=Vector( w*-.5f,h*+.5f,nr );
|
||||
verts[VERT_TRNEAR]=Vector( w*+.5f,h*+.5f,nr );
|
||||
verts[VERT_BRNEAR]=Vector( w*+.5f,h*-.5f,nr );
|
||||
verts[VERT_BLNEAR]=Vector( w*-.5f,h*-.5f,nr );
|
||||
float t=fr/nr;
|
||||
verts[VERT_TLFAR]=verts[VERT_TLNEAR] * t;
|
||||
verts[VERT_TRFAR]=verts[VERT_TRNEAR] * t;
|
||||
verts[VERT_BRFAR]=verts[VERT_BRNEAR] * t;
|
||||
verts[VERT_BLFAR]=verts[VERT_BLNEAR] * t;
|
||||
verts[VERT_EYE]=Vector();
|
||||
makePlanes();
|
||||
}
|
||||
|
||||
Frustum::Frustum( const Frustum &f,const Transform &t ){
|
||||
for( int k=0;k<9;++k ){
|
||||
verts[k]=t*f.verts[k];
|
||||
}
|
||||
makePlanes();
|
||||
}
|
||||
|
||||
bool Frustum::cull( const Vector v[],int cnt )const{
|
||||
for( int n=0;n<6;++n ){
|
||||
int k;
|
||||
for( k=0;k<cnt && planes[n].distance( v[k] )<0;++k ){}
|
||||
if( k==cnt ) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Frustum::cull( const Box &b )const{
|
||||
Vector v[8];
|
||||
for( int k=0;k<8;++k ) v[k]=b.corner(k);
|
||||
return cull( v,8 );
|
||||
}
|
||||
|
||||
void Frustum::makePlanes(){
|
||||
planes[PLANE_TOP]=Plane( verts[VERT_EYE],verts[VERT_TRFAR],verts[VERT_TLFAR] );
|
||||
planes[PLANE_LEFT]=Plane( verts[VERT_EYE],verts[VERT_TLFAR],verts[VERT_BLFAR] );
|
||||
planes[PLANE_BOTTOM]=Plane( verts[VERT_EYE],verts[VERT_BLFAR],verts[VERT_BRFAR] );
|
||||
planes[PLANE_RIGHT]=Plane( verts[VERT_EYE],verts[VERT_BRFAR],verts[VERT_TRFAR] );
|
||||
planes[PLANE_NEAR]=Plane( verts[VERT_TRNEAR],verts[VERT_TLNEAR],verts[VERT_BLNEAR] );
|
||||
planes[PLANE_FAR]=Plane( verts[VERT_TLFAR],verts[VERT_TRFAR],verts[VERT_BRFAR] );
|
||||
if( planes[PLANE_NEAR].distance( verts[VERT_EYE] )>0 ){
|
||||
for( int k=0;k<6;++k ) planes[k]=-planes[k];
|
||||
}
|
||||
}
|
32
blitz3d/frustum.h
Normal file
32
blitz3d/frustum.h
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
#ifndef FRUSTUM_H
|
||||
#define FRUSTUM_H
|
||||
|
||||
#include "geom.h"
|
||||
|
||||
class Frustum{
|
||||
public:
|
||||
enum{
|
||||
VERT_TLNEAR=0,VERT_TRNEAR,VERT_BRNEAR,VERT_BLNEAR,
|
||||
VERT_TLFAR,VERT_TRFAR,VERT_BRFAR,VERT_BLFAR,VERT_EYE
|
||||
};
|
||||
enum{
|
||||
PLANE_TOP=0,PLANE_LEFT,PLANE_BOTTOM,PLANE_RIGHT,PLANE_NEAR,PLANE_FAR
|
||||
};
|
||||
Frustum();
|
||||
Frustum( float nr,float fr,float w,float h );
|
||||
Frustum( const Frustum &f,const Transform &t );
|
||||
|
||||
bool cull( const Box &box )const;
|
||||
bool cull( const Vector vecs[],int cnt )const;
|
||||
|
||||
const Plane &getPlane( int n )const{ return planes[n]; }
|
||||
const Vector &getVertex( int n )const{ return verts[n]; }
|
||||
|
||||
private:
|
||||
Plane planes[6];
|
||||
Vector verts[9];
|
||||
void makePlanes();
|
||||
};
|
||||
|
||||
#endif
|
23
blitz3d/geom.cpp
Normal file
23
blitz3d/geom.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "geom.h"
|
||||
|
||||
Matrix Matrix::tmps[64];
|
||||
Transform Transform::tmps[64];
|
||||
|
||||
Quat rotationQuat( float p,float y,float r ){
|
||||
return yawQuat(y)*pitchQuat(p)*rollQuat(r);
|
||||
}
|
||||
|
||||
/*
|
||||
Quat rotationQuat( float p,float y,float r ){
|
||||
float sp=sin(p/-2),cp=cos(p/-2);
|
||||
float sy=sin(y/ 2),cy=cos(y/ 2);
|
||||
float sr=sin(r/-2),cr=cos(r/-2);
|
||||
float qw=cr*cp*cy + sr*sp*sy;
|
||||
float qx=cr*sp*cy + sr*cp*sy;
|
||||
float qy=cr*cp*sy - sr*sp*cy;
|
||||
float qz=sr*cp*cy - cr*sp*sy;
|
||||
return Quat( qw,Vector(-qx,-qy,qz) );
|
||||
}
|
||||
*/
|
558
blitz3d/geom.h
Normal file
558
blitz3d/geom.h
Normal file
@ -0,0 +1,558 @@
|
||||
|
||||
#ifndef GEOM_H
|
||||
#define GEOM_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
class Vector;
|
||||
class Line;
|
||||
class Plane;
|
||||
class Matrix;
|
||||
class Transform;
|
||||
|
||||
const float PI=3.14159265359f; //180 degrees
|
||||
const float TWOPI=PI*2.0f; //360 degrees
|
||||
const float HALFPI=PI*.5f; //90 degrees
|
||||
const float QUARTERPI=PI*.25f; //45 degrees
|
||||
const float EPSILON=.000001f; //small value
|
||||
const float INFINITY=10000000.0f; //big value
|
||||
|
||||
class Vector{
|
||||
public:
|
||||
float x,y,z;
|
||||
|
||||
Vector():x(0),y(0),z(0){
|
||||
}
|
||||
Vector( float x,float y,float z ):x(x),y(y),z(z){
|
||||
}
|
||||
operator float*(){
|
||||
return &x;
|
||||
}
|
||||
operator const float *(){
|
||||
return &x;
|
||||
}
|
||||
float &operator[]( int n ){
|
||||
return (&x)[n];
|
||||
}
|
||||
float operator[]( int n )const{
|
||||
return (&x)[n];
|
||||
}
|
||||
Vector operator-()const{
|
||||
return Vector( -x,-y,-z );
|
||||
}
|
||||
Vector operator*( float scale )const{
|
||||
return Vector( x*scale,y*scale,z*scale );
|
||||
}
|
||||
Vector operator*( const Vector &q )const{
|
||||
return Vector( x*q.x,y*q.y,z*q.z );
|
||||
}
|
||||
Vector operator/( float scale )const{
|
||||
return Vector( x/scale,y/scale,z/scale );
|
||||
}
|
||||
Vector operator/( const Vector &q )const{
|
||||
return Vector( x/q.x,y/q.y,z/q.z );
|
||||
}
|
||||
Vector operator+( const Vector &q )const{
|
||||
return Vector( x+q.x,y+q.y,z+q.z );
|
||||
}
|
||||
Vector operator-( const Vector &q )const{
|
||||
return Vector( x-q.x,y-q.y,z-q.z );
|
||||
}
|
||||
Vector &operator*=( float scale ){
|
||||
x*=scale;y*=scale;z*=scale;return *this;
|
||||
}
|
||||
Vector &operator*=( const Vector &q ){
|
||||
x*=q.x;y*=q.y;z*=q.z;return *this;
|
||||
}
|
||||
Vector &operator/=( float scale ){
|
||||
x/=scale;y/=scale;z/=scale;return *this;
|
||||
}
|
||||
Vector &operator/=( const Vector &q ){
|
||||
x/=q.x;y/=q.y;z/=q.z;return *this;
|
||||
}
|
||||
Vector &operator+=( const Vector &q ){
|
||||
x+=q.x;y+=q.y;z+=q.z;return *this;
|
||||
}
|
||||
Vector &operator-=( const Vector &q ){
|
||||
x-=q.x;y-=q.y;z-=q.z;return *this;
|
||||
}
|
||||
bool operator<( const Vector &q )const{
|
||||
if( fabs(x-q.x)>EPSILON ) return x<q.x ? true : false;
|
||||
if( fabs(y-q.y)>EPSILON ) return y<q.y ? true : false;
|
||||
return fabs(z-q.z)>EPSILON && z<q.z;
|
||||
}
|
||||
bool operator==( const Vector &q )const{
|
||||
return fabs(x-q.x)<=EPSILON && fabs(y-q.y)<=EPSILON && fabs(z-q.z)<=EPSILON;
|
||||
}
|
||||
bool operator!=( const Vector &q )const{
|
||||
return fabs(x-q.x)>EPSILON || fabs(y-q.y)>EPSILON || fabs(z-q.z)>EPSILON;
|
||||
}
|
||||
float dot( const Vector &q )const{
|
||||
return x*q.x+y*q.y+z*q.z;
|
||||
}
|
||||
Vector cross( const Vector &q )const{
|
||||
return Vector( y*q.z-z*q.y,z*q.x-x*q.z,x*q.y-y*q.x );
|
||||
}
|
||||
float length()const{
|
||||
return sqrtf(x*x+y*y+z*z);
|
||||
}
|
||||
float distance( const Vector &q )const{
|
||||
float dx=x-q.x,dy=y-q.y,dz=z-q.z;return sqrtf(dx*dx+dy*dy+dz*dz);
|
||||
}
|
||||
Vector normalized()const{
|
||||
float l=length();return Vector( x/l,y/l,z/l );
|
||||
}
|
||||
void normalize(){
|
||||
float l=length();x/=l;y/=l;z/=l;
|
||||
}
|
||||
float yaw()const{
|
||||
return -atan2f( x,z );
|
||||
}
|
||||
float pitch()const{
|
||||
return -atan2f( y,sqrtf( x*x+z*z ) );
|
||||
}
|
||||
void clear(){
|
||||
x=y=z=0;
|
||||
}
|
||||
};
|
||||
|
||||
class Line{
|
||||
public:
|
||||
Vector o,d;
|
||||
Line(){
|
||||
}
|
||||
Line( const Vector &o,const Vector &d ):o(o),d(d){
|
||||
}
|
||||
Line operator+( const Vector &q )const{
|
||||
return Line( o+q,d );
|
||||
}
|
||||
Line operator-( const Vector &q )const{
|
||||
return Line( o-q,d );
|
||||
}
|
||||
Vector operator*( float q )const{
|
||||
return o+d*q;
|
||||
}
|
||||
Vector nearest( const Vector &q )const{
|
||||
return o+d*(d.dot(q-o)/d.dot(d));
|
||||
}
|
||||
};
|
||||
|
||||
class Plane{
|
||||
public:
|
||||
Vector n;
|
||||
float d;
|
||||
|
||||
Plane():d(0){
|
||||
}
|
||||
//normal/offset form
|
||||
Plane( const Vector &n,float d ):n(n),d(d){
|
||||
}
|
||||
//point/normal form
|
||||
Plane( const Vector &p,const Vector &n ):n(n),d(-n.dot(p)){
|
||||
}
|
||||
//create plane from tri
|
||||
Plane( const Vector &v0,const Vector &v1,const Vector &v2 ){
|
||||
n=(v1-v0).cross(v2-v0).normalized();d=-n.dot(v0);
|
||||
}
|
||||
Plane operator-()const{
|
||||
return Plane( -n,-d );
|
||||
}
|
||||
float t_intersect( const Line &q )const{
|
||||
return -distance(q.o)/n.dot(q.d);
|
||||
}
|
||||
Vector intersect( const Line &q )const{
|
||||
return q*t_intersect(q);
|
||||
}
|
||||
Line intersect( const Plane &q )const{
|
||||
Vector lv=n.cross( q.n ).normalized();
|
||||
return Line( q.intersect( Line( nearest( n*-d ),n.cross(lv) ) ),lv );
|
||||
}
|
||||
Vector nearest( const Vector &q )const{
|
||||
return q-n*distance(q);
|
||||
}
|
||||
void negate(){
|
||||
n=-n;d=-d;
|
||||
}
|
||||
float distance( const Vector &q )const{
|
||||
return n.dot(q)+d;
|
||||
}
|
||||
};
|
||||
|
||||
struct Quat{
|
||||
float w;
|
||||
Vector v;
|
||||
Quat():w(1){
|
||||
}
|
||||
Quat( float w,const Vector &v ):w(w),v(v){
|
||||
}
|
||||
Quat operator-()const{
|
||||
return Quat( w,-v );
|
||||
}
|
||||
Quat operator+( const Quat &q )const{
|
||||
return Quat( w+q.w,v+q.v );
|
||||
}
|
||||
Quat operator-( const Quat &q )const{
|
||||
return Quat( w-q.w,v-q.v );
|
||||
}
|
||||
Quat operator*( const Quat &q )const{
|
||||
return Quat( w*q.w-v.dot(q.v),q.v.cross(v)+q.v*w+v*q.w );
|
||||
}
|
||||
Vector operator*( const Vector &q )const{
|
||||
return (*this * Quat(0,q) * -*this).v;
|
||||
}
|
||||
Quat operator*( float q )const{
|
||||
return Quat( w*q,v*q );
|
||||
}
|
||||
Quat operator/( float q )const{
|
||||
return Quat( w/q,v/q );
|
||||
}
|
||||
float dot( const Quat &q )const{
|
||||
return v.x*q.v.x+v.y*q.v.y+v.z*q.v.z+w*q.w;
|
||||
}
|
||||
float length()const{
|
||||
return sqrtf( w*w+v.x*v.x+v.y*v.y+v.z*v.z );
|
||||
}
|
||||
void normalize(){
|
||||
*this=*this/length();
|
||||
}
|
||||
Quat normalized()const{
|
||||
return *this/length();
|
||||
}
|
||||
Quat slerpTo( const Quat &q,float a )const{
|
||||
Quat t=q;
|
||||
float d=dot(q),b=1-a;
|
||||
if( d<0 ){ t.w=-t.w;t.v=-t.v;d=-d; }
|
||||
if( d<1-EPSILON ){
|
||||
float om=acosf( d );
|
||||
float si=sinf( om );
|
||||
a=sinf( a*om )/si;
|
||||
b=sinf( b*om )/si;
|
||||
}
|
||||
return *this*b + t*a;
|
||||
}
|
||||
Vector i()const{
|
||||
float xz=v.x*v.z,wy=w*v.y;
|
||||
float xy=v.x*v.y,wz=w*v.z;
|
||||
float yy=v.y*v.y,zz=v.z*v.z;
|
||||
return Vector( 1-2*(yy+zz),2*(xy-wz),2*(xz+wy) );
|
||||
}
|
||||
Vector j()const{
|
||||
float yz=v.y*v.z,wx=w*v.x;
|
||||
float xy=v.x*v.y,wz=w*v.z;
|
||||
float xx=v.x*v.x,zz=v.z*v.z;
|
||||
return Vector( 2*(xy+wz),1-2*(xx+zz),2*(yz-wx) );
|
||||
}
|
||||
Vector k()const{
|
||||
float xz=v.x*v.z,wy=w*v.y;
|
||||
float yz=v.y*v.z,wx=w*v.x;
|
||||
float xx=v.x*v.x,yy=v.y*v.y;
|
||||
return Vector( 2*(xz-wy),2*(yz+wx),1-2*(xx+yy) );
|
||||
}
|
||||
};
|
||||
|
||||
class Matrix{
|
||||
static Matrix tmps[64];
|
||||
static Matrix &alloc_tmp(){ static int tmp=0;return tmps[tmp++&63]; }
|
||||
friend class Transform;
|
||||
public:
|
||||
Vector i,j,k;
|
||||
|
||||
Matrix():i(Vector(1,0,0)),j(Vector(0,1,0)),k(Vector(0,0,1)){
|
||||
}
|
||||
Matrix( const Vector &i,const Vector &j,const Vector &k ):i(i),j(j),k(k){
|
||||
}
|
||||
Matrix( const Quat &q ){
|
||||
float xx=q.v.x*q.v.x,yy=q.v.y*q.v.y,zz=q.v.z*q.v.z;
|
||||
float xy=q.v.x*q.v.y,xz=q.v.x*q.v.z,yz=q.v.y*q.v.z;
|
||||
float wx=q.w*q.v.x,wy=q.w*q.v.y,wz=q.w*q.v.z;
|
||||
i=Vector( 1-2*(yy+zz),2*(xy-wz),2*(xz+wy) ),
|
||||
j=Vector( 2*(xy+wz),1-2*(xx+zz),2*(yz-wx) ),
|
||||
k=Vector( 2*(xz-wy),2*(yz+wx),1-2*(xx+yy) );
|
||||
}
|
||||
Matrix( float angle,const Vector &axis ){
|
||||
const Vector &u=axis;
|
||||
float c=cosf(angle),s=sinf(angle);
|
||||
float x2=axis.x*axis.x,y2=axis.y*axis.y,z2=axis.z*axis.z;
|
||||
i=Vector( x2+c*(1-x2),u.x*u.y*(1-c)-u.z*s,u.z*u.x*(1-c)+u.y*s );
|
||||
j=Vector( u.x*u.y*(1-c)+u.z*s,y2+c*(1-y2),u.y*u.z*(1-c)-u.x*s );
|
||||
k=Vector( u.z*u.x*(1-c)-u.y*s,u.y*u.z*(1-c)+u.x*s,z2+c*(1-z2) );
|
||||
}
|
||||
Vector &operator[]( int n ){
|
||||
return (&i)[n];
|
||||
}
|
||||
const Vector &operator[]( int n )const{
|
||||
return (&i)[n];
|
||||
}
|
||||
Matrix &operator~()const{
|
||||
Matrix &m=alloc_tmp();
|
||||
m.i.x=i.x;m.i.y=j.x;m.i.z=k.x;
|
||||
m.j.x=i.y;m.j.y=j.y;m.j.z=k.y;
|
||||
m.k.x=i.z;m.k.y=j.z;m.k.z=k.z;
|
||||
return m;
|
||||
}
|
||||
float determinant()const{
|
||||
return i.x*(j.y*k.z-j.z*k.y )-i.y*(j.x*k.z-j.z*k.x )+i.z*(j.x*k.y-j.y*k.x );
|
||||
}
|
||||
Matrix &operator-()const{
|
||||
Matrix &m=alloc_tmp();
|
||||
float t=1.0f/determinant();
|
||||
m.i.x= t*(j.y*k.z-j.z*k.y);m.i.y=-t*(i.y*k.z-i.z*k.y);m.i.z= t*(i.y*j.z-i.z*j.y);
|
||||
m.j.x=-t*(j.x*k.z-j.z*k.x);m.j.y= t*(i.x*k.z-i.z*k.x);m.j.z=-t*(i.x*j.z-i.z*j.x);
|
||||
m.k.x= t*(j.x*k.y-j.y*k.x);m.k.y=-t*(i.x*k.y-i.y*k.x);m.k.z= t*(i.x*j.y-i.y*j.x);
|
||||
return m;
|
||||
}
|
||||
Matrix &cofactor()const{
|
||||
Matrix &m=alloc_tmp();
|
||||
m.i.x= (j.y*k.z-j.z*k.y);m.i.y=-(j.x*k.z-j.z*k.x);m.i.z= (j.x*k.y-j.y*k.x);
|
||||
m.j.x=-(i.y*k.z-i.z*k.y);m.j.y= (i.x*k.z-i.z*k.x);m.j.z=-(i.x*k.y-i.y*k.x);
|
||||
m.k.x= (i.y*j.z-i.z*j.y);m.k.y=-(i.x*j.z-i.z*j.x);m.k.z= (i.x*j.y-i.y*j.x);
|
||||
return m;
|
||||
}
|
||||
bool operator==( const Matrix &q )const{
|
||||
return i==q.i && j==q.j && k==q.k;
|
||||
}
|
||||
bool operator!=( const Matrix &q )const{
|
||||
return i!=q.i || j!=q.j || k!=q.k;
|
||||
}
|
||||
Vector operator*( const Vector &q )const{
|
||||
return Vector( i.x*q.x+j.x*q.y+k.x*q.z,i.y*q.x+j.y*q.y+k.y*q.z,i.z*q.x+j.z*q.y+k.z*q.z );
|
||||
}
|
||||
Matrix &operator*( const Matrix &q )const{
|
||||
Matrix &m=alloc_tmp();
|
||||
m.i.x=i.x*q.i.x+j.x*q.i.y+k.x*q.i.z;m.i.y=i.y*q.i.x+j.y*q.i.y+k.y*q.i.z;m.i.z=i.z*q.i.x+j.z*q.i.y+k.z*q.i.z;
|
||||
m.j.x=i.x*q.j.x+j.x*q.j.y+k.x*q.j.z;m.j.y=i.y*q.j.x+j.y*q.j.y+k.y*q.j.z;m.j.z=i.z*q.j.x+j.z*q.j.y+k.z*q.j.z;
|
||||
m.k.x=i.x*q.k.x+j.x*q.k.y+k.x*q.k.z;m.k.y=i.y*q.k.x+j.y*q.k.y+k.y*q.k.z;m.k.z=i.z*q.k.x+j.z*q.k.y+k.z*q.k.z;
|
||||
return m;
|
||||
}
|
||||
void orthogonalize(){
|
||||
k.normalize();
|
||||
i=j.cross( k ).normalized();
|
||||
j=k.cross( i );
|
||||
}
|
||||
Matrix &orthogonalized()const{
|
||||
Matrix &m=alloc_tmp();
|
||||
m=*this;m.orthogonalize();
|
||||
return m;
|
||||
}
|
||||
};
|
||||
|
||||
class Box{
|
||||
public:
|
||||
Vector a,b;
|
||||
Box():a( Vector(INFINITY,INFINITY,INFINITY) ),b( Vector(-INFINITY,-INFINITY,-INFINITY) ){
|
||||
}
|
||||
Box( const Vector &q ):a(q),b(q){
|
||||
}
|
||||
Box( const Vector &a,const Vector &b ):a(a),b(b){
|
||||
}
|
||||
Box( const Line &l ):a(l.o),b(l.o){
|
||||
update( l.o+l.d );
|
||||
}
|
||||
void clear(){
|
||||
a.x=a.y=a.z=INFINITY;
|
||||
b.x=b.y=b.z=-INFINITY;
|
||||
}
|
||||
bool empty()const{
|
||||
return b.x<a.x || b.y<a.y || b.z<a.z;
|
||||
}
|
||||
Vector centre()const{
|
||||
return Vector( (a.x+b.x)*.5f,(a.y+b.y)*.5f,(a.z+b.z)*.5f );
|
||||
}
|
||||
Vector corner( int n )const{
|
||||
return Vector( ((n&1)?b:a).x,((n&2)?b:a).y,((n&4)?b:a).z );
|
||||
}
|
||||
void update( const Vector &q ){
|
||||
if( q.x<a.x ) a.x=q.x;if( q.y<a.y ) a.y=q.y;if( q.z<a.z ) a.z=q.z;
|
||||
if( q.x>b.x ) b.x=q.x;if( q.y>b.y ) b.y=q.y;if( q.z>b.z ) b.z=q.z;
|
||||
}
|
||||
void update( const Box &q ){
|
||||
if( q.a.x<a.x ) a.x=q.a.x;if( q.a.y<a.y ) a.y=q.a.y;if( q.a.z<a.z ) a.z=q.a.z;
|
||||
if( q.b.x>b.x ) b.x=q.b.x;if( q.b.y>b.y ) b.y=q.b.y;if( q.b.z>b.z ) b.z=q.b.z;
|
||||
}
|
||||
bool overlaps( const Box &q )const{
|
||||
return
|
||||
(b.x<q.b.x?b.x:q.b.x)>=(a.x>q.a.x?a.x:q.a.x) &&
|
||||
(b.y<q.b.y?b.y:q.b.y)>=(a.y>q.a.y?a.y:q.a.y) &&
|
||||
(b.z<q.b.z?b.z:q.b.z)>=(a.z>q.a.z?a.z:q.a.z);
|
||||
}
|
||||
void expand( float n ){
|
||||
a.x-=n;a.y-=n;a.z-=n;b.x+=n;b.y+=n;b.z+=n;
|
||||
}
|
||||
float width()const{
|
||||
return b.x-a.x;
|
||||
}
|
||||
float height()const{
|
||||
return b.y-a.y;
|
||||
}
|
||||
float depth()const{
|
||||
return b.z-a.z;
|
||||
}
|
||||
bool contains( const Vector &q ){
|
||||
return q.x>=a.x && q.x<=b.x && q.y>=a.y && q.y<=b.y && q.z>=a.z && q.z<=b.z;
|
||||
}
|
||||
};
|
||||
|
||||
class Transform{
|
||||
static Transform tmps[64];
|
||||
static Transform &alloc_tmp(){ static int tmp=0;return tmps[tmp++&63]; }
|
||||
public:
|
||||
Matrix m;
|
||||
Vector v;
|
||||
|
||||
Transform(){
|
||||
}
|
||||
Transform( const Matrix &m ):m(m){
|
||||
}
|
||||
Transform( const Vector &v ):v(v){
|
||||
}
|
||||
Transform( const Matrix &m,const Vector &v ):m(m),v(v){
|
||||
}
|
||||
Transform &operator-()const{
|
||||
Transform &t=alloc_tmp();
|
||||
t.m=-m;t.v=t.m*-v;
|
||||
return t;
|
||||
}
|
||||
Transform &operator~()const{
|
||||
Transform &t=alloc_tmp();
|
||||
t.m=~m;t.v=t.m*-v;
|
||||
return t;
|
||||
}
|
||||
Vector operator*( const Vector &q )const{
|
||||
return m*q+v;
|
||||
}
|
||||
Line operator*( const Line &q )const{
|
||||
Vector t=(*this)*q.o;
|
||||
return Line( t,(*this)*(q.o+q.d)-t );
|
||||
}
|
||||
Box operator*( const Box &q )const{
|
||||
Box t( (*this*q.corner(0) ) );
|
||||
for( int k=1;k<8;++k ) t.update( *this*q.corner(k) );
|
||||
return t;
|
||||
}
|
||||
Transform &operator*( const Transform &q )const{
|
||||
Transform &t=alloc_tmp();
|
||||
t.m=m*q.m;t.v=m*q.v+v;
|
||||
return t;
|
||||
}
|
||||
bool operator==( const Transform &q )const{
|
||||
return m==q.m && v==q.v;
|
||||
}
|
||||
bool operator!=( const Transform &q )const{
|
||||
return !operator==( q );
|
||||
}
|
||||
};
|
||||
|
||||
inline float transformRadius( float r,const Matrix &t ){
|
||||
static const float sq_3=sqrtf(1.0f/3.0f);
|
||||
return (t * Vector( sq_3,sq_3,sq_3 )).length()*r;
|
||||
}
|
||||
|
||||
inline Matrix pitchMatrix( float q ){
|
||||
return Matrix( Vector(1,0,0),Vector(0,cosf(q),sinf(q)),Vector(0,-sinf(q),cosf(q)) );
|
||||
}
|
||||
|
||||
inline Matrix yawMatrix( float q ){
|
||||
return Matrix( Vector(cosf(q),0,sinf(q)),Vector(0,1,0),Vector(-sinf(q),0,cosf(q)) );
|
||||
}
|
||||
|
||||
inline Matrix rollMatrix( float q ){
|
||||
return Matrix( Vector(cosf(q),sinf(q),0),Vector(-sinf(q),cosf(q),0),Vector(0,0,1) );
|
||||
}
|
||||
|
||||
inline float matrixPitch( const Matrix &m ){
|
||||
return m.k.pitch();
|
||||
// return asinf( -m.k.y );
|
||||
}
|
||||
|
||||
inline float matrixYaw( const Matrix &m ){
|
||||
return m.k.yaw();
|
||||
//return atan2f( -m.k.x,m.k.z );
|
||||
}
|
||||
|
||||
inline float matrixRoll( const Matrix &m ){
|
||||
return atan2f( m.i.y,m.j.y );
|
||||
//Matrix t=pitchMatrix( -matrixPitch(m) )*yawMatrix( -matrixYaw(m) )*m;
|
||||
//return atan2f( t.i.y,t.i.x );
|
||||
}
|
||||
|
||||
inline Matrix scaleMatrix( float x,float y,float z ){
|
||||
return Matrix( Vector( x,0,0 ),Vector( 0,y,0 ),Vector( 0,0,z ) );
|
||||
}
|
||||
|
||||
inline Matrix scaleMatrix( const Vector &scale ){
|
||||
return Matrix( Vector( scale.x,0,0 ),Vector( 0,scale.y,0 ),Vector( 0,0,scale.z ) );
|
||||
}
|
||||
|
||||
inline Quat pitchQuat( float p ){
|
||||
return Quat( cosf(p/-2),Vector( sinf(p/-2),0,0 ) );
|
||||
}
|
||||
|
||||
inline Quat yawQuat( float y ){
|
||||
return Quat( cosf(y/2),Vector( 0,sinf(y/2),0 ) );
|
||||
}
|
||||
|
||||
inline Quat rollQuat( float r ){
|
||||
return Quat( cosf(r/-2),Vector( 0,0,sinf(r/-2) ) );
|
||||
}
|
||||
|
||||
//inline Quat rotationQuat( float p,float y,float r ){
|
||||
// return yawQuat(y)*pitchQuat(p)*rollQuat(r);
|
||||
//}
|
||||
|
||||
Quat rotationQuat( float p,float y,float r );
|
||||
|
||||
inline Matrix rotationMatrix( float p,float y,float r ){
|
||||
return yawMatrix(y)*pitchMatrix(p)*rollMatrix(r);
|
||||
}
|
||||
|
||||
inline Matrix rotationMatrix( const Vector &rot ){
|
||||
return yawMatrix(rot.y)*pitchMatrix(rot.x)*rollMatrix(rot.z);
|
||||
}
|
||||
|
||||
inline float quatPitch( const Quat &q ){
|
||||
return q.k().pitch();
|
||||
}
|
||||
|
||||
inline float quatYaw( const Quat &q ){
|
||||
return q.k().yaw();
|
||||
}
|
||||
|
||||
inline float quatRoll( const Quat &q ){
|
||||
// Vector i=q.i(),j=q.j();
|
||||
// return atan2f( i.y,j.y );
|
||||
return matrixRoll( q );
|
||||
}
|
||||
|
||||
inline Quat matrixQuat( const Matrix &p ){
|
||||
Matrix m=p;
|
||||
m.orthogonalize();
|
||||
float t=m.i.x+m.j.y+m.k.z,w,x,y,z;
|
||||
if( t>EPSILON ){
|
||||
t=sqrtf( t+1 )*2;
|
||||
x=(m.k.y-m.j.z)/t;
|
||||
y=(m.i.z-m.k.x)/t;
|
||||
z=(m.j.x-m.i.y)/t;
|
||||
w=t/4;
|
||||
}else if( m.i.x>m.j.y && m.i.x>m.k.z ){
|
||||
t=sqrtf( m.i.x-m.j.y-m.k.z+1 )*2;
|
||||
x=t/4;
|
||||
y=(m.j.x+m.i.y)/t;
|
||||
z=(m.i.z+m.k.x)/t;
|
||||
w=(m.k.y-m.j.z)/t;
|
||||
}else if( m.j.y>m.k.z ){
|
||||
t=sqrtf( m.j.y-m.k.z-m.i.x+1 )*2;
|
||||
x=(m.j.x+m.i.y)/t;
|
||||
y=t/4;
|
||||
z=(m.k.y+m.j.z)/t;
|
||||
w=(m.i.z-m.k.x)/t;
|
||||
}else{
|
||||
t=sqrtf( m.k.z-m.j.y-m.i.x+1 )*2;
|
||||
x=(m.i.z+m.k.x)/t;
|
||||
y=(m.k.y+m.j.z)/t;
|
||||
z=t/4;
|
||||
w=(m.j.x-m.i.y)/t;
|
||||
}
|
||||
return Quat( w,Vector( x,y,z ) );
|
||||
}
|
||||
|
||||
#endif
|
16
blitz3d/group.h
Normal file
16
blitz3d/group.h
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
#ifndef GROUP_H
|
||||
#define GROUP_H
|
||||
|
||||
class Group{
|
||||
|
||||
vector<Object*> _objs;
|
||||
|
||||
public:
|
||||
Group( Object *obj );
|
||||
~Group();
|
||||
|
||||
const vector<Object*> objs()const{ return _objs; }
|
||||
};
|
||||
|
||||
#endif
|
33
blitz3d/light.cpp
Normal file
33
blitz3d/light.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "light.h"
|
||||
#include "../gxruntime/gxscene.h"
|
||||
|
||||
extern gxScene *gx_scene;
|
||||
|
||||
Light::Light( int type ){
|
||||
light=gx_scene->createLight( type );
|
||||
}
|
||||
|
||||
Light::~Light(){
|
||||
gx_scene->freeLight( light );
|
||||
}
|
||||
|
||||
void Light::setRange( float r ){
|
||||
light->setRange( r );
|
||||
}
|
||||
|
||||
void Light::setColor( const Vector &v ){
|
||||
light->setColor( (float*)&v.x );
|
||||
}
|
||||
|
||||
void Light::setConeAngles( float inner,float outer ){
|
||||
light->setConeAngles( inner,outer );
|
||||
}
|
||||
|
||||
bool Light::beginRender( float tween ){
|
||||
Object::beginRender( tween );
|
||||
light->setPosition( &getRenderTform().v.x );
|
||||
light->setDirection( &getRenderTform().m.k.x );
|
||||
return true;
|
||||
}
|
31
blitz3d/light.h
Normal file
31
blitz3d/light.h
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
#ifndef LIGHT_H
|
||||
#define LIGHT_H
|
||||
|
||||
#include "geom.h"
|
||||
#include "object.h"
|
||||
#include "../gxruntime/gxlight.h"
|
||||
|
||||
class World;
|
||||
|
||||
class Light : public Object{
|
||||
public:
|
||||
Light( int type );
|
||||
~Light();
|
||||
|
||||
Light *getLight(){ return this; }
|
||||
|
||||
void setRange( float r );
|
||||
void setColor( const Vector &v );
|
||||
void setConeAngles( float inner,float outer );
|
||||
|
||||
bool beginRender( float tween );
|
||||
|
||||
gxLight *getGxLight()const{ return light; }
|
||||
|
||||
private:
|
||||
friend class World;
|
||||
gxLight *light;
|
||||
};
|
||||
|
||||
#endif
|
34
blitz3d/listener.cpp
Normal file
34
blitz3d/listener.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
#include "std.h"
|
||||
#include "listener.h"
|
||||
|
||||
extern gxAudio *gx_audio;
|
||||
|
||||
Listener::Listener( float roll,float dopp,float dist ){
|
||||
if( !gx_audio ) return;
|
||||
|
||||
gx_audio->set3dOptions( roll,dopp,dist );
|
||||
renderListener();
|
||||
}
|
||||
|
||||
Listener::Listener( const Listener &t ):
|
||||
Object(t){
|
||||
}
|
||||
|
||||
Listener::~Listener(){
|
||||
if( !gx_audio ) return;
|
||||
|
||||
Vector pos,vel,up(0,1,1),forward(0,0,1);
|
||||
gx_audio->set3dListener( &pos.x,&vel.x,&forward.x,&up.x );
|
||||
}
|
||||
|
||||
void Listener::renderListener(){
|
||||
if( !gx_audio ) return;
|
||||
|
||||
const Vector &pos=getWorldTform().v;
|
||||
const Vector &vel=getVelocity();
|
||||
const Vector &forward=getWorldTform().m.k.normalized();
|
||||
const Vector &up=getWorldTform().m.j.normalized();
|
||||
|
||||
gx_audio->set3dListener( &pos.x,&vel.x,&forward.x,&up.x );
|
||||
}
|
23
blitz3d/listener.h
Normal file
23
blitz3d/listener.h
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
#ifndef LISTENER_H
|
||||
#define LISTENER_H
|
||||
|
||||
#include "object.h"
|
||||
|
||||
class Listener : public Object{
|
||||
public:
|
||||
Listener( float roll,float dopp,float dist );
|
||||
Listener( const Listener &t );
|
||||
~Listener();
|
||||
|
||||
//Entity interface
|
||||
Entity *clone(){ return d_new Listener( *this ); }
|
||||
Listener *getListener(){ return this; }
|
||||
|
||||
//Listener interface
|
||||
void renderListener();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user