Improve protoGetDataMember
Reduces number of cast complaints in macOS/x64. See #24
This commit is contained in:
parent
3d6019d2ec
commit
6dd55e4ee9
|
@ -3767,15 +3767,16 @@ void opGetProtoData(Program* program)
|
||||||
int pid = data[1];
|
int pid = data[1];
|
||||||
int member = data[0];
|
int member = data[0];
|
||||||
|
|
||||||
int value = 0;
|
ProtoDataMemberValue value;
|
||||||
int valueType = _proto_data_member(pid, member, &value);
|
value.integerValue = 0;
|
||||||
|
int valueType = protoGetDataMember(pid, member, &value);
|
||||||
switch (valueType) {
|
switch (valueType) {
|
||||||
case PROTO_DATA_MEMBER_TYPE_INT:
|
case PROTO_DATA_MEMBER_TYPE_INT:
|
||||||
programStackPushInt32(program, value);
|
programStackPushInt32(program, value.integerValue);
|
||||||
programStackPushInt16(program, VALUE_TYPE_INT);
|
programStackPushInt16(program, VALUE_TYPE_INT);
|
||||||
break;
|
break;
|
||||||
case PROTO_DATA_MEMBER_TYPE_STRING:
|
case PROTO_DATA_MEMBER_TYPE_STRING:
|
||||||
programStackPushInt32(program, programPushString(program, (char*)value));
|
programStackPushInt32(program, programPushString(program, value.stringValue));
|
||||||
programStackPushInt16(program, VALUE_TYPE_DYNAMIC_STRING);
|
programStackPushInt16(program, VALUE_TYPE_DYNAMIC_STRING);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
114
src/proto.cc
114
src/proto.cc
|
@ -797,7 +797,7 @@ int _proto_dude_init(const char* path)
|
||||||
|
|
||||||
// proto_data_member
|
// proto_data_member
|
||||||
// 0x49FFD8
|
// 0x49FFD8
|
||||||
int _proto_data_member(int pid, int member, int* value)
|
int protoGetDataMember(int pid, int member, ProtoDataMemberValue* value)
|
||||||
{
|
{
|
||||||
Proto* proto;
|
Proto* proto;
|
||||||
if (protoGetProto(pid, &proto) == -1) {
|
if (protoGetProto(pid, &proto) == -1) {
|
||||||
|
@ -808,55 +808,55 @@ int _proto_data_member(int pid, int member, int* value)
|
||||||
case OBJ_TYPE_ITEM:
|
case OBJ_TYPE_ITEM:
|
||||||
switch (member) {
|
switch (member) {
|
||||||
case ITEM_DATA_MEMBER_PID:
|
case ITEM_DATA_MEMBER_PID:
|
||||||
*value = proto->pid;
|
value->integerValue = proto->pid;
|
||||||
break;
|
break;
|
||||||
case ITEM_DATA_MEMBER_NAME:
|
case ITEM_DATA_MEMBER_NAME:
|
||||||
// NOTE: uninline
|
// NOTE: uninline
|
||||||
*value = (int)protoGetName(proto->scenery.pid);
|
value->stringValue = protoGetName(proto->scenery.pid);
|
||||||
return PROTO_DATA_MEMBER_TYPE_STRING;
|
return PROTO_DATA_MEMBER_TYPE_STRING;
|
||||||
case ITEM_DATA_MEMBER_DESCRIPTION:
|
case ITEM_DATA_MEMBER_DESCRIPTION:
|
||||||
// NOTE: Uninline.
|
// NOTE: Uninline.
|
||||||
*value = (int)protoGetDescription(proto->pid);
|
value->stringValue = protoGetDescription(proto->pid);
|
||||||
return PROTO_DATA_MEMBER_TYPE_STRING;
|
return PROTO_DATA_MEMBER_TYPE_STRING;
|
||||||
case ITEM_DATA_MEMBER_FID:
|
case ITEM_DATA_MEMBER_FID:
|
||||||
*value = proto->fid;
|
value->integerValue = proto->fid;
|
||||||
break;
|
break;
|
||||||
case ITEM_DATA_MEMBER_LIGHT_DISTANCE:
|
case ITEM_DATA_MEMBER_LIGHT_DISTANCE:
|
||||||
*value = proto->item.lightDistance;
|
value->integerValue = proto->item.lightDistance;
|
||||||
break;
|
break;
|
||||||
case ITEM_DATA_MEMBER_LIGHT_INTENSITY:
|
case ITEM_DATA_MEMBER_LIGHT_INTENSITY:
|
||||||
*value = proto->item.lightIntensity;
|
value->integerValue = proto->item.lightIntensity;
|
||||||
break;
|
break;
|
||||||
case ITEM_DATA_MEMBER_FLAGS:
|
case ITEM_DATA_MEMBER_FLAGS:
|
||||||
*value = proto->item.flags;
|
value->integerValue = proto->item.flags;
|
||||||
break;
|
break;
|
||||||
case ITEM_DATA_MEMBER_EXTENDED_FLAGS:
|
case ITEM_DATA_MEMBER_EXTENDED_FLAGS:
|
||||||
*value = proto->item.extendedFlags;
|
value->integerValue = proto->item.extendedFlags;
|
||||||
break;
|
break;
|
||||||
case ITEM_DATA_MEMBER_SID:
|
case ITEM_DATA_MEMBER_SID:
|
||||||
*value = proto->item.sid;
|
value->integerValue = proto->item.sid;
|
||||||
break;
|
break;
|
||||||
case ITEM_DATA_MEMBER_TYPE:
|
case ITEM_DATA_MEMBER_TYPE:
|
||||||
*value = proto->item.type;
|
value->integerValue = proto->item.type;
|
||||||
break;
|
break;
|
||||||
case ITEM_DATA_MEMBER_MATERIAL:
|
case ITEM_DATA_MEMBER_MATERIAL:
|
||||||
*value = proto->item.material;
|
value->integerValue = proto->item.material;
|
||||||
break;
|
break;
|
||||||
case ITEM_DATA_MEMBER_SIZE:
|
case ITEM_DATA_MEMBER_SIZE:
|
||||||
*value = proto->item.size;
|
value->integerValue = proto->item.size;
|
||||||
break;
|
break;
|
||||||
case ITEM_DATA_MEMBER_WEIGHT:
|
case ITEM_DATA_MEMBER_WEIGHT:
|
||||||
*value = proto->item.weight;
|
value->integerValue = proto->item.weight;
|
||||||
break;
|
break;
|
||||||
case ITEM_DATA_MEMBER_COST:
|
case ITEM_DATA_MEMBER_COST:
|
||||||
*value = proto->item.cost;
|
value->integerValue = proto->item.cost;
|
||||||
break;
|
break;
|
||||||
case ITEM_DATA_MEMBER_INVENTORY_FID:
|
case ITEM_DATA_MEMBER_INVENTORY_FID:
|
||||||
*value = proto->item.inventoryFid;
|
value->integerValue = proto->item.inventoryFid;
|
||||||
break;
|
break;
|
||||||
case ITEM_DATA_MEMBER_WEAPON_RANGE:
|
case ITEM_DATA_MEMBER_WEAPON_RANGE:
|
||||||
if (proto->item.type == ITEM_TYPE_WEAPON) {
|
if (proto->item.type == ITEM_TYPE_WEAPON) {
|
||||||
*value = proto->item.data.weapon.maxRange1;
|
value->integerValue = proto->item.data.weapon.maxRange1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -867,39 +867,39 @@ int _proto_data_member(int pid, int member, int* value)
|
||||||
case OBJ_TYPE_CRITTER:
|
case OBJ_TYPE_CRITTER:
|
||||||
switch (member) {
|
switch (member) {
|
||||||
case CRITTER_DATA_MEMBER_PID:
|
case CRITTER_DATA_MEMBER_PID:
|
||||||
*value = proto->critter.pid;
|
value->integerValue = proto->critter.pid;
|
||||||
break;
|
break;
|
||||||
case CRITTER_DATA_MEMBER_NAME:
|
case CRITTER_DATA_MEMBER_NAME:
|
||||||
// NOTE: Uninline.
|
// NOTE: Uninline.
|
||||||
*value = (int)protoGetName(proto->critter.pid);
|
value->stringValue = protoGetName(proto->critter.pid);
|
||||||
return PROTO_DATA_MEMBER_TYPE_STRING;
|
return PROTO_DATA_MEMBER_TYPE_STRING;
|
||||||
case CRITTER_DATA_MEMBER_DESCRIPTION:
|
case CRITTER_DATA_MEMBER_DESCRIPTION:
|
||||||
// NOTE: Uninline.
|
// NOTE: Uninline.
|
||||||
*value = (int)protoGetDescription(proto->critter.pid);
|
value->stringValue = protoGetDescription(proto->critter.pid);
|
||||||
return PROTO_DATA_MEMBER_TYPE_STRING;
|
return PROTO_DATA_MEMBER_TYPE_STRING;
|
||||||
case CRITTER_DATA_MEMBER_FID:
|
case CRITTER_DATA_MEMBER_FID:
|
||||||
*value = proto->critter.fid;
|
value->integerValue = proto->critter.fid;
|
||||||
break;
|
break;
|
||||||
case CRITTER_DATA_MEMBER_LIGHT_DISTANCE:
|
case CRITTER_DATA_MEMBER_LIGHT_DISTANCE:
|
||||||
*value = proto->critter.lightDistance;
|
value->integerValue = proto->critter.lightDistance;
|
||||||
break;
|
break;
|
||||||
case CRITTER_DATA_MEMBER_LIGHT_INTENSITY:
|
case CRITTER_DATA_MEMBER_LIGHT_INTENSITY:
|
||||||
*value = proto->critter.lightIntensity;
|
value->integerValue = proto->critter.lightIntensity;
|
||||||
break;
|
break;
|
||||||
case CRITTER_DATA_MEMBER_FLAGS:
|
case CRITTER_DATA_MEMBER_FLAGS:
|
||||||
*value = proto->critter.flags;
|
value->integerValue = proto->critter.flags;
|
||||||
break;
|
break;
|
||||||
case CRITTER_DATA_MEMBER_EXTENDED_FLAGS:
|
case CRITTER_DATA_MEMBER_EXTENDED_FLAGS:
|
||||||
*value = proto->critter.extendedFlags;
|
value->integerValue = proto->critter.extendedFlags;
|
||||||
break;
|
break;
|
||||||
case CRITTER_DATA_MEMBER_SID:
|
case CRITTER_DATA_MEMBER_SID:
|
||||||
*value = proto->critter.sid;
|
value->integerValue = proto->critter.sid;
|
||||||
break;
|
break;
|
||||||
case CRITTER_DATA_MEMBER_HEAD_FID:
|
case CRITTER_DATA_MEMBER_HEAD_FID:
|
||||||
*value = proto->critter.headFid;
|
value->integerValue = proto->critter.headFid;
|
||||||
break;
|
break;
|
||||||
case CRITTER_DATA_MEMBER_BODY_TYPE:
|
case CRITTER_DATA_MEMBER_BODY_TYPE:
|
||||||
*value = proto->critter.data.bodyType;
|
value->integerValue = proto->critter.data.bodyType;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
debugPrint("\n\tError: Unimp'd data member in member in proto_data_member!");
|
debugPrint("\n\tError: Unimp'd data member in member in proto_data_member!");
|
||||||
|
@ -909,39 +909,39 @@ int _proto_data_member(int pid, int member, int* value)
|
||||||
case OBJ_TYPE_SCENERY:
|
case OBJ_TYPE_SCENERY:
|
||||||
switch (member) {
|
switch (member) {
|
||||||
case SCENERY_DATA_MEMBER_PID:
|
case SCENERY_DATA_MEMBER_PID:
|
||||||
*value = proto->scenery.pid;
|
value->integerValue = proto->scenery.pid;
|
||||||
break;
|
break;
|
||||||
case SCENERY_DATA_MEMBER_NAME:
|
case SCENERY_DATA_MEMBER_NAME:
|
||||||
// NOTE: Uninline.
|
// NOTE: Uninline.
|
||||||
*value = (int)protoGetName(proto->scenery.pid);
|
value->stringValue = protoGetName(proto->scenery.pid);
|
||||||
return PROTO_DATA_MEMBER_TYPE_STRING;
|
return PROTO_DATA_MEMBER_TYPE_STRING;
|
||||||
case SCENERY_DATA_MEMBER_DESCRIPTION:
|
case SCENERY_DATA_MEMBER_DESCRIPTION:
|
||||||
// NOTE: Uninline.
|
// NOTE: Uninline.
|
||||||
*value = (int)protoGetDescription(proto->scenery.pid);
|
value->stringValue = protoGetDescription(proto->scenery.pid);
|
||||||
return PROTO_DATA_MEMBER_TYPE_STRING;
|
return PROTO_DATA_MEMBER_TYPE_STRING;
|
||||||
case SCENERY_DATA_MEMBER_FID:
|
case SCENERY_DATA_MEMBER_FID:
|
||||||
*value = proto->scenery.fid;
|
value->integerValue = proto->scenery.fid;
|
||||||
break;
|
break;
|
||||||
case SCENERY_DATA_MEMBER_LIGHT_DISTANCE:
|
case SCENERY_DATA_MEMBER_LIGHT_DISTANCE:
|
||||||
*value = proto->scenery.lightDistance;
|
value->integerValue = proto->scenery.lightDistance;
|
||||||
break;
|
break;
|
||||||
case SCENERY_DATA_MEMBER_LIGHT_INTENSITY:
|
case SCENERY_DATA_MEMBER_LIGHT_INTENSITY:
|
||||||
*value = proto->scenery.lightIntensity;
|
value->integerValue = proto->scenery.lightIntensity;
|
||||||
break;
|
break;
|
||||||
case SCENERY_DATA_MEMBER_FLAGS:
|
case SCENERY_DATA_MEMBER_FLAGS:
|
||||||
*value = proto->scenery.flags;
|
value->integerValue = proto->scenery.flags;
|
||||||
break;
|
break;
|
||||||
case SCENERY_DATA_MEMBER_EXTENDED_FLAGS:
|
case SCENERY_DATA_MEMBER_EXTENDED_FLAGS:
|
||||||
*value = proto->scenery.extendedFlags;
|
value->integerValue = proto->scenery.extendedFlags;
|
||||||
break;
|
break;
|
||||||
case SCENERY_DATA_MEMBER_SID:
|
case SCENERY_DATA_MEMBER_SID:
|
||||||
*value = proto->scenery.sid;
|
value->integerValue = proto->scenery.sid;
|
||||||
break;
|
break;
|
||||||
case SCENERY_DATA_MEMBER_TYPE:
|
case SCENERY_DATA_MEMBER_TYPE:
|
||||||
*value = proto->scenery.type;
|
value->integerValue = proto->scenery.type;
|
||||||
break;
|
break;
|
||||||
case SCENERY_DATA_MEMBER_MATERIAL:
|
case SCENERY_DATA_MEMBER_MATERIAL:
|
||||||
*value = proto->scenery.field_2C;
|
value->integerValue = proto->scenery.field_2C;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
debugPrint("\n\tError: Unimp'd data member in member in proto_data_member!");
|
debugPrint("\n\tError: Unimp'd data member in member in proto_data_member!");
|
||||||
|
@ -951,36 +951,36 @@ int _proto_data_member(int pid, int member, int* value)
|
||||||
case OBJ_TYPE_WALL:
|
case OBJ_TYPE_WALL:
|
||||||
switch (member) {
|
switch (member) {
|
||||||
case WALL_DATA_MEMBER_PID:
|
case WALL_DATA_MEMBER_PID:
|
||||||
*value = proto->wall.pid;
|
value->integerValue = proto->wall.pid;
|
||||||
break;
|
break;
|
||||||
case WALL_DATA_MEMBER_NAME:
|
case WALL_DATA_MEMBER_NAME:
|
||||||
// NOTE: Uninline.
|
// NOTE: Uninline.
|
||||||
*value = (int)protoGetName(proto->wall.pid);
|
value->stringValue = protoGetName(proto->wall.pid);
|
||||||
return PROTO_DATA_MEMBER_TYPE_STRING;
|
return PROTO_DATA_MEMBER_TYPE_STRING;
|
||||||
case WALL_DATA_MEMBER_DESCRIPTION:
|
case WALL_DATA_MEMBER_DESCRIPTION:
|
||||||
// NOTE: Uninline.
|
// NOTE: Uninline.
|
||||||
*value = (int)protoGetDescription(proto->wall.pid);
|
value->stringValue = protoGetDescription(proto->wall.pid);
|
||||||
return PROTO_DATA_MEMBER_TYPE_STRING;
|
return PROTO_DATA_MEMBER_TYPE_STRING;
|
||||||
case WALL_DATA_MEMBER_FID:
|
case WALL_DATA_MEMBER_FID:
|
||||||
*value = proto->wall.fid;
|
value->integerValue = proto->wall.fid;
|
||||||
break;
|
break;
|
||||||
case WALL_DATA_MEMBER_LIGHT_DISTANCE:
|
case WALL_DATA_MEMBER_LIGHT_DISTANCE:
|
||||||
*value = proto->wall.lightDistance;
|
value->integerValue = proto->wall.lightDistance;
|
||||||
break;
|
break;
|
||||||
case WALL_DATA_MEMBER_LIGHT_INTENSITY:
|
case WALL_DATA_MEMBER_LIGHT_INTENSITY:
|
||||||
*value = proto->wall.lightIntensity;
|
value->integerValue = proto->wall.lightIntensity;
|
||||||
break;
|
break;
|
||||||
case WALL_DATA_MEMBER_FLAGS:
|
case WALL_DATA_MEMBER_FLAGS:
|
||||||
*value = proto->wall.flags;
|
value->integerValue = proto->wall.flags;
|
||||||
break;
|
break;
|
||||||
case WALL_DATA_MEMBER_EXTENDED_FLAGS:
|
case WALL_DATA_MEMBER_EXTENDED_FLAGS:
|
||||||
*value = proto->wall.extendedFlags;
|
value->integerValue = proto->wall.extendedFlags;
|
||||||
break;
|
break;
|
||||||
case WALL_DATA_MEMBER_SID:
|
case WALL_DATA_MEMBER_SID:
|
||||||
*value = proto->wall.sid;
|
value->integerValue = proto->wall.sid;
|
||||||
break;
|
break;
|
||||||
case WALL_DATA_MEMBER_MATERIAL:
|
case WALL_DATA_MEMBER_MATERIAL:
|
||||||
*value = proto->wall.material;
|
value->integerValue = proto->wall.material;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
debugPrint("\n\tError: Unimp'd data member in member in proto_data_member!");
|
debugPrint("\n\tError: Unimp'd data member in member in proto_data_member!");
|
||||||
|
@ -993,31 +993,31 @@ int _proto_data_member(int pid, int member, int* value)
|
||||||
case OBJ_TYPE_MISC:
|
case OBJ_TYPE_MISC:
|
||||||
switch (member) {
|
switch (member) {
|
||||||
case MISC_DATA_MEMBER_PID:
|
case MISC_DATA_MEMBER_PID:
|
||||||
*value = proto->misc.pid;
|
value->integerValue = proto->misc.pid;
|
||||||
break;
|
break;
|
||||||
case MISC_DATA_MEMBER_NAME:
|
case MISC_DATA_MEMBER_NAME:
|
||||||
// NOTE: Uninline.
|
// NOTE: Uninline.
|
||||||
*value = (int)protoGetName(proto->misc.pid);
|
value->stringValue = protoGetName(proto->misc.pid);
|
||||||
return PROTO_DATA_MEMBER_TYPE_STRING;
|
return PROTO_DATA_MEMBER_TYPE_STRING;
|
||||||
case MISC_DATA_MEMBER_DESCRIPTION:
|
case MISC_DATA_MEMBER_DESCRIPTION:
|
||||||
// NOTE: Uninline.
|
// NOTE: Uninline.
|
||||||
*value = (int)protoGetDescription(proto->misc.pid);
|
value->stringValue = protoGetDescription(proto->misc.pid);
|
||||||
// FIXME: Errornously report type as int, should be string.
|
// FIXME: Errornously report type as int, should be string.
|
||||||
return PROTO_DATA_MEMBER_TYPE_INT;
|
return PROTO_DATA_MEMBER_TYPE_INT;
|
||||||
case MISC_DATA_MEMBER_FID:
|
case MISC_DATA_MEMBER_FID:
|
||||||
*value = proto->misc.fid;
|
value->integerValue = proto->misc.fid;
|
||||||
return 1;
|
return 1;
|
||||||
case MISC_DATA_MEMBER_LIGHT_DISTANCE:
|
case MISC_DATA_MEMBER_LIGHT_DISTANCE:
|
||||||
*value = proto->misc.lightDistance;
|
value->integerValue = proto->misc.lightDistance;
|
||||||
return 1;
|
return 1;
|
||||||
case MISC_DATA_MEMBER_LIGHT_INTENSITY:
|
case MISC_DATA_MEMBER_LIGHT_INTENSITY:
|
||||||
*value = proto->misc.lightIntensity;
|
value->integerValue = proto->misc.lightIntensity;
|
||||||
break;
|
break;
|
||||||
case MISC_DATA_MEMBER_FLAGS:
|
case MISC_DATA_MEMBER_FLAGS:
|
||||||
*value = proto->misc.flags;
|
value->integerValue = proto->misc.flags;
|
||||||
break;
|
break;
|
||||||
case MISC_DATA_MEMBER_EXTENDED_FLAGS:
|
case MISC_DATA_MEMBER_EXTENDED_FLAGS:
|
||||||
*value = proto->misc.extendedFlags;
|
value->integerValue = proto->misc.extendedFlags;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
debugPrint("\n\tError: Unimp'd data member in member in proto_data_member!");
|
debugPrint("\n\tError: Unimp'd data member in member in proto_data_member!");
|
||||||
|
|
|
@ -88,6 +88,11 @@ typedef enum ProtoDataMemberType {
|
||||||
PROTO_DATA_MEMBER_TYPE_STRING = 2,
|
PROTO_DATA_MEMBER_TYPE_STRING = 2,
|
||||||
} ProtoDataMemberType;
|
} ProtoDataMemberType;
|
||||||
|
|
||||||
|
typedef union ProtoDataMemberValue {
|
||||||
|
int integerValue;
|
||||||
|
char* stringValue;
|
||||||
|
} ProtoDataMemberValue;
|
||||||
|
|
||||||
typedef enum PrototypeMessage {
|
typedef enum PrototypeMessage {
|
||||||
PROTOTYPE_MESSAGE_NAME,
|
PROTOTYPE_MESSAGE_NAME,
|
||||||
PROTOTYPE_MESSAGE_DESCRIPTION,
|
PROTOTYPE_MESSAGE_DESCRIPTION,
|
||||||
|
@ -141,7 +146,7 @@ int _proto_update_gen(Object* obj);
|
||||||
int _proto_update_init(Object* obj);
|
int _proto_update_init(Object* obj);
|
||||||
int _proto_dude_update_gender();
|
int _proto_dude_update_gender();
|
||||||
int _proto_dude_init(const char* path);
|
int _proto_dude_init(const char* path);
|
||||||
int _proto_data_member(int pid, int member, int* value);
|
int protoGetDataMember(int pid, int member, ProtoDataMemberValue* value);
|
||||||
int protoInit();
|
int protoInit();
|
||||||
void protoReset();
|
void protoReset();
|
||||||
void protoExit();
|
void protoExit();
|
||||||
|
|
Loading…
Reference in New Issue