1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 187
6#include "sce/libcdvd.h"
20#include "clothread.hpp"
21#include "dataalloc.hpp"
24#include "framevu1.hpp"
30#include "scriptinterpreter.hpp"
34#include "visualvu1.hpp"
56static void CommandSIZE(
void **argv);
60static void CommandFRAME(
void **argv);
64static void CommandNORMAL(
void **argv);
68static void CommandFOLLOW(
void **argv);
72static void CommandK(
void **argv);
76static void CommandWINDEFFECT(
void **argv);
80static void CommandGRAVITY(
void **argv);
84static void CommandPOLYDIVE(
void **argv);
88static void CommandBOUND(
void **argv);
102 {
"SIZE", {SCRIPT_ARGUMENT_INTEGER, SCRIPT_ARGUMENT_INTEGER, -1} },
103 {
"FRAME", {SCRIPT_ARGUMENT_STRING, -1} },
104 {
"NORMAL", {SCRIPT_ARGUMENT_FLOAT, -1} },
105 {
"FOLLOW", {SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, -1} },
106 {
"K", {SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, -1} },
107 {
"WINDEFFECT", {SCRIPT_ARGUMENT_FLOAT, -1} },
108 {
"GRAVITY", {SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, -1} },
109 {
"POLYDIV", {SCRIPT_ARGUMENT_STRING, -1} },
110 {
"BOUND", {SCRIPT_ARGUMENT_STRING, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, SCRIPT_ARGUMENT_FLOAT, -1}},
114static void (*CommandExe[9])(
void **) = {
126static int GetArg(
input_str &input,
int *arg_types,
void **argv);
127static int SearchCommand(
input_str &input,
int *command);
129static int CheckChar(
char ch);
139 char arg_storage[16][256];
144 pCloth =
new ((u_long128 *) alloc->Alloc(0x856))
CCloth(16, 16, 1.0f);
152 if (pCloth == NULL) {
158 for (
int i = 0; i < 16; i++) {
159 argv[i] = arg_storage[i];
162 while (SearchCommand(input, &command) != 0) {
163 if (command >= 9 || command < 0) {
164 printf(
"unknown command!!\n");
168 int arg_status = GetArg(input, Command[command].arg_types, (
void **) argv);
170 if (arg_status == 0) {
174 if (arg_status < 0) {
178 CommandExe[command](argv);
184static void CommandSIZE(
void **argv) {
185 int num_i = *(
int *) argv[0];
186 int num_j = *(
int *) argv[1];
204 pCloth->
num_i = num_i;
205 pCloth->
num_j = num_j;
215static void CommandFRAME(
void **argv) {
218 pCloth->
frame = frame;
227static void CommandNORMAL(
void **argv) {
231static void CommandFOLLOW(
void **argv) {
232 pCloth->
follow[0] = *(
float *) argv[0];
233 pCloth->
follow[1] = *(
float *) argv[1];
234 pCloth->
follow[2] = *(
float *) argv[2];
237static void CommandK(
void **argv) {
238 pCloth->
stiffness[0] = *(
float *) argv[0];
239 pCloth->
stiffness[1] = *(
float *) argv[1];
240 pCloth->
stiffness[2] = *(
float *) argv[2];
243static void CommandWINDEFFECT(
void **argv) {
247static void CommandGRAVITY(
void **argv) {
248 pCloth->
gravity[0] = *(
float *) argv[0];
249 pCloth->
gravity[1] = *(
float *) argv[1];
250 pCloth->
gravity[2] = *(
float *) argv[2];
253static void CommandPOLYDIVE(
void **argv) {
254 char *flags = (
char *) argv[0];
277static void CommandBOUND(
void **argv) {
278 sceVu0FVECTOR box_vectors[4];
279 CBound *bound =
new ((u_long128 *) DataBuffer->Alloc(0x14))
CBound(1.0f, 1.0f, 1.0f);
286 CFrame *frame = ParentFrame->SearchFrame((
char *) argv[arg_index++]);
292 for (
int i = 0; i < 4; i++) {
293 box_vectors[i][0] = *(
float *) argv[arg_index];
294 box_vectors[i][1] = *(
float *) argv[(
int) (arg_index + 1)];
295 box_vectors[i][2] = *(
float *) argv[(
int) (arg_index + 2)];
297 box_vectors[i][3] = 1.0f;
300 box_vectors[0][3] = 0.0f;
301 bound->
SetDir(frame, box_vectors[1], box_vectors[2], box_vectors[0], box_vectors[3][0], box_vectors[3][1]);
305 half_z = box_vectors[3][2];
306 half_y = box_vectors[3][1];
307 half_x = box_vectors[3][0];
308 bound->
extent[0] = half_x;
309 bound->
extent[1] = half_y;
310 bound->
extent[2] = half_z;
312 if (bound->
extent[0] > 0.0f) {
316 if (bound->
extent[1] > 0.0f) {
320 if (bound->
extent[2] > 0.0f) {
324 bound->
friction = *(
float *) argv[arg_index];
326 if (pBound == NULL) {
327 pCloth->
bound = bound;
329 pBound->
next = bound;
343static int GetArg(
input_str &input,
int *arg_types,
void **argv) {
346 if (!SkipSpace(input)) {
352 while (arg_types[arg_count++] >= 0)
357 for (
int i = 0; i < arg_count - 1; i++) {
360 if (!SkipSpace(input)) {
365 if (input.get(&ch) == 0) {
369 if (ch ==
',' || !CheckChar(ch)) {
378 switch (arg_types[i]) {
379 case SCRIPT_ARGUMENT_STRING:
380 if (word[0] !=
'"') {
384 for (length = 1;; length++) {
385 char letter = word[length];
397 strcpy((
char *) argv[i], word + 1);
399 case SCRIPT_ARGUMENT_INTEGER:
400 for (length = 0; word[length] != 0; length++) {
401 char letter = word[length];
403 if (letter <
'0' || letter >
'9') {
408 *(
int *) argv[i] = atoi(word);
410 case SCRIPT_ARGUMENT_FLOAT:
411 for (length = 0; word[length] != 0; length++) {
412 char letter = word[length];
414 if ((letter <
'0' || letter >
'9') && letter !=
'.' && letter !=
'-') {
419 *(
float *) argv[i] = (
float) atof(word);
437static int SearchCommand(
input_str &input,
int *command) {
440 if (!SkipSpace(input)) {
448 if (input.get(&ch) == 0) {
452 if (!CheckChar(ch)) {
461 for (
int i = 0; i < 9; i++) {
462 if (strcmp(Command[i].name, word) == 0) {
487 while (pos < input.
size) {
488 if (CheckChar(text[pos])) {
497 if (pos >= input.
size) {
512static int CheckChar(
char ch) {
537int keyCtrl(
float stick_x,
float stick_y,
MOTION_INFO *motion) {
540 if (stick_y != 0.0f || stick_x != 0.0f) {
546 if (stick_x < 0.0f) {
550 if (stick_y < 0.0f) {
554 if (stick_x >= stick_y) {
560 speed = 0.8f * (0.1f + tilt);
561 motion[2].
speed = speed;
564 motion[2].
speed = 0.7f;
567 if (stick_x + stick_y >= 0.85f) {
582void MoveImageTest(
sceVif1Packet *packet,
int src_base,
int src_width,
int src_format,
const CRect_i_ &rect,
int dst_base,
int dst_width,
int dst_format,
int dst_x,
int dst_y,
int direction) {
583 sceVif1PkCnt(packet, 0);
584 sceVif1PkOpenDirectCode(packet, 0);
585 sceVif1PkOpenGifTag(packet, *(u_long128 *) &GiftagAD);
586 sceVif1PkAddGsAD(packet, SCE_GS_BITBLTBUF, SCE_GS_SET_BITBLTBUF(src_base, src_width, src_format, dst_base, dst_width, dst_format));
587 sceVif1PkAddGsAD(packet, SCE_GS_TRXPOS, SCE_GS_SET_TRXPOS(rect.
x, rect.
y, dst_x, dst_y, direction));
588 sceVif1PkAddGsAD(packet, SCE_GS_TRXREG, SCE_GS_SET_TRXREG(rect.
width, rect.
height));
589 sceVif1PkAddGsAD(packet, SCE_GS_TRXDIR, 2);
590 sceVif1PkCloseGifTag(packet);
591 sceVif1PkCloseDirectCode(packet);
597float unitRotation(
CFrameVu1 *frame,
float heading) {
602 frame->GetRotation(rotation);
603 delta = heading - rotation[1];
606 abs_delta = -1.0f * delta;
611 if (abs_delta <= PI_D) {
612 if (abs_delta <= TWELFTH_PI_D) {
616 abs_delta = TWO_PI_D - abs_delta;
618 if (abs_delta <= TWELFTH_PI_D) {
625 rotation[1] += TWELFTH_PI;
627 rotation[1] -= TWELFTH_PI;
632 if (delta >= -PI_D) {
633 rotation[1] -= TWELFTH_PI;
635 rotation[1] += TWELFTH_PI;
640 rotation[1] = heading;
643 if (rotation[1] <= -PI_D) {
644 rotation[1] += TWO_PI;
647 if (rotation[1] >= PI_D) {
648 rotation[1] -= TWO_PI;
void SetDir(CFrame *frame, float *from_position, float *to_position, float *up_direction, float half_width, float half_height)
virtual void Initialize(CDataAlloc2< 1 > *alloc)