sannybuilder / library

Scripting documentation for Sanny Builder & CLEO Redux
https://library.sannybuilder.com/
25 stars 6 forks source link

support derived classes (Car and Heli/Boat/Tank etc) #40

Closed x87 closed 2 years ago

x87 commented 3 years ago

To solve the dilemma with derived classes (Car and Heli/Boat/Tank etc) we could add overloaded constructor commands:

00A5 CREATE_CAR Car.Create: Car 00A5 CREATE_BOAT Boat.Create(...): Boat 00A5 CREATE_TANK Tank.Create(...): Tank 00A5 CREATE_HELI Heli.Create(...): Heli

All four will compile to the same opcode 00A5 but the compiler will become aware of the correct type of the vehicle and the class name. Also the compiler could validate that the correct model id is provided to the constructor (Boat.Create(#INFERNUS...) would raise an error).

What do you think?

Originally posted by @x87 in https://github.com/sannybuilder/dev/discussions/136#discussioncomment-635112

x87 commented 3 years ago

I think for Сar, Boat and the like it is worth giving another modifier, like "inherited" or "extended". A static class must not inherit. At least this is implemented in C#.

https://github.com/sannybuilder/dev/discussions/136#discussioncomment-698849

x87 commented 3 years ago

another example of derivatives:

08D4 CREATE_MENU => Menu 0964 CREATE_MENU_GRID => MenuGrid (has its own command SET_ACTIVE_MENU_ITEM_CAR_MODS)

0AAC LOAD_AUDIO_STREAM => AudioStream 0AC1 LOAD_3D_AUDIO_STREAM => AudioStream3d (has *3D methods, like SET_PLAY_3D_AUDIO_STREAM_AT_CAR)

x87 commented 3 years ago

We could add an extra field for is_constructor commands to specify the base class name. e.g.

Boat extends Car Heli extends Car MenuGrid extends Menu AudioStream3d extends AudioStream

x87 commented 2 years ago

Note: classes inheritance is supported in CLEO Redux with the help of classes metadata, e.g. Boat

x87 commented 2 years ago

Closing as it should be sufficient to use classes metadata.