update shit

This commit is contained in:
2023-02-08 22:57:31 +08:00
parent 9f5f27353f
commit b8da0a802e
27 changed files with 1018 additions and 87 deletions

34
CodeGen/CKERROR.py Normal file
View File

@ -0,0 +1,34 @@
full_error = []
annotation = ''
with open('src/CKERROR.txt', 'r', encoding='utf-8') as fr:
while True:
ln = fr.readline()
if ln == '':
break
ln.strip()
if ln == '':
continue
if ln.startswith('#define'):
sp = ln[len('#define'):].strip().split(' ')
# name, value, description
full_error.append((sp[0], sp[-1], annotation))
annotation = ''
elif ln.startswith('//'):
annotation = ln[len('//'):].strip()
fr.close()
with open('dest/CKERROR.txt', 'w', encoding='utf-8') as fw:
for item in full_error:
fw.write('{{ LibCmo::CKERROR::{}, {{"{}", "{}"}} }},\n'.format(
item[0],
item[0],
item[-1])
)
fw.write('\n')
for item in full_error:
fw.write(f'{item[0]} = {item[1]},\n')
fw.close()

86
CodeGen/CKMISC.py Normal file
View File

@ -0,0 +1,86 @@
def RemoveAnnotation(strl: str) -> str:
idx = strl.find("//")
if idx == -1: return strl.strip()
return strl[:idx].strip()
def Underline2Camel(orig: str) -> str:
return ''.join(map(
lambda mixed: mixed[-1].upper() if mixed[0] == '_' else mixed[-1].lower(),
((('_' if idx == 0 else orig[idx - 1]), c) for idx, c in enumerate(orig))
)).replace('_', '')
class EnumEntry():
def __init__(self, name: str, val: str):
self.name: str = name
self.val: str = val
def __repr__(self) -> str:
return f'<{self.name}: {self.val}>'
class EnumBody():
def __init__(self, name: str, is_flag: bool):
self.name: str = name
self.is_flag: bool = is_flag
self.entries: list[EnumEntry] = []
def __repr__(self) -> str:
return self.entries.__repr__()
full_enum: list[EnumBody] = []
current_body: EnumEntry = None
with open('src/CKMISC.txt', 'r', encoding='utf-8') as fr:
while True:
ln = fr.readline()
if ln == '':
break
ln = RemoveAnnotation(ln)
if ln == '':
continue
if ln.startswith('enum'):
ln = ln[len('enum'):].strip()
is_flag = ln[0] == '!'
name = ln[1:] if is_flag else ln
if current_body:
full_enum.append(current_body)
current_body = EnumBody(name, is_flag)
else:
sp = ln.replace(',', '').split('=')
if len(sp) == 1:
entry = EnumEntry(sp[0].strip(), '')
else:
entry = EnumEntry(sp[0].strip(), sp[-1].strip())
current_body.entries.append(entry)
fr.close()
if current_body:
full_enum.append(current_body)
with open('dest/CKMISC.txt', 'w', encoding='utf-8') as fw:
# write define
for item in full_enum:
fw.write('enum class {} : int32_t {{\n'.format(item.name))
fw.write(',\n'.join(map(
lambda x: x.name if x.val == '' else (x.name + ' = ' + x.val),
item.entries
)))
fw.write('\n};\n')
fw.write('\n')
# write vector
for item in full_enum:
fw.write('static const std::array<std::pair<LibCmo::{}, const char*>, {}> _{} {{\n'.format(
item.name, len(item.entries), Underline2Camel(item.name)
))
fw.write(',\n'.join(map(
lambda x: '{{ LibCmo::{}, "{}" }}'.format(x.name, x.name),
item.entries
)))
fw.write('\n};\n')
fw.close()

76
CodeGen/CK_CLASSID.py Normal file
View File

@ -0,0 +1,76 @@
class CKClass():
def __init__(self, name: str, value: int):
self.name: str = name
self.value: int = value
self.parents: tuple[str] = None
def GetLevel(strl: str):
counter = 0
for c in strl:
if c == '\t':
counter += 1
else:
break
return counter
def BuildClass(strl: str) -> CKClass:
strl = strl.replace('#define', '\t').replace(' ', '\t').strip()
sp = strl.split('\t')
return CKClass(sp[0], sp[-1])
def GetParents(ls: list[CKClass]) -> tuple[str]:
return tuple(
map(lambda x: x.name, ls)
)
full_classes = []
with open('src/CK_CLASSID.txt', 'r', encoding='utf-8') as fr:
level = 0
node_stack: list[CKClass] = [None]
while True:
ln = fr.readline()
if ln == '':
break
if ln.strip() == '':
continue
ln = ln.strip('\n')
new_item = BuildClass(ln)
full_classes.append(new_item)
this_level = GetLevel(ln)
if this_level > level:
# level up
level += 1
node_stack.append(new_item)
new_item.parents = GetParents(node_stack)
elif this_level == level:
node_stack.pop()
node_stack.append(new_item)
new_item.parents = GetParents(node_stack)
elif this_level < level:
for i in range(level - this_level + 1):
node_stack.pop()
level = this_level
node_stack.append(new_item)
new_item.parents = GetParents(node_stack)
fr.close()
with open('dest/CK_CLASSID.txt', 'w', encoding='utf-8') as fw:
for item in full_classes:
fw.write('{{ LibCmo::CK_CLASSID::{}, {{{}}} }},\n'.format(
item.parents[-1],
', '.join(
map(lambda x: '"' + x + '"', item.parents)
)
))
fw.write('\n')
for item in full_classes:
fw.write(f'{item.name} = {item.value},\n')
fw.close()

0
CodeGen/dest/.gitkeep Normal file
View File

205
CodeGen/src/CKERROR.txt Normal file
View File

@ -0,0 +1,205 @@
// Operation successful
#define CKERR_OK 0
// One of the parameter passed to the function was invalid
#define CKERR_INVALIDPARAMETER -1
// One of the parameter passed to the function was invalid
#define CKERR_INVALIDPARAMETERTYPE -2
// The parameter size was invalid
#define CKERR_INVALIDSIZE -3
// The operation type didn't exist
#define CKERR_INVALIDOPERATION -4
// The function used to execute the operation is not yet implemented
#define CKERR_OPERATIONNOTIMPLEMENTED -5
// There was not enough memory to perform the action
#define CKERR_OUTOFMEMORY -6
// The function is not yet implemented
#define CKERR_NOTIMPLEMENTED -7
// There was an attempt to remove something not present
#define CKERR_NOTFOUND -11
// There is no level currently created
#define CKERR_NOLEVEL -13
//
#define CKERR_CANCREATERENDERCONTEXT -14
// The notification message was not used
#define CKERR_NOTIFICATIONNOTHANDLED -16
// Attempt to add an item that was already present
#define CKERR_ALREADYPRESENT -17
// the render context is not valid
#define CKERR_INVALIDRENDERCONTEXT -18
// the render context is not activated for rendering
#define CKERR_RENDERCONTEXTINACTIVE -19
// there was no plugins to load this kind of file
#define CKERR_NOLOADPLUGINS -20
// there was no plugins to save this kind of file
#define CKERR_NOSAVEPLUGINS -21
// attempt to load an invalid file
#define CKERR_INVALIDFILE -22
// attempt to load with an invalid plugin
#define CKERR_INVALIDPLUGIN -23
// attempt use an object that wasnt initialized
#define CKERR_NOTINITIALIZED -24
// attempt use a message type that wasn't registred
#define CKERR_INVALIDMESSAGE -25
// attempt use an invalid prototype
#define CKERR_INVALIDPROTOTYPE -28
// No dll file found in the parse directory
#define CKERR_NODLLFOUND -29
// this dll has already been registred
#define CKERR_ALREADYREGISTREDDLL -30
// this dll does not contain information to create the prototype
#define CKERR_INVALIDDLL -31
// Invalid Object (attempt to Get an object from an invalid ID)
#define CKERR_INVALIDOBJECT -34
// Invalid window was provided as console window
#define CKERR_INVALIDCONDSOLEWINDOW -35
// Invalid kinematic chain ( end and start effector may not be part of the same hierarchy )
#define CKERR_INVALIDKINEMATICCHAIN -36
// Keyboard not attached or not working properly
#define CKERR_NOKEYBOARD -37
// Mouse not attached or not working properly
#define CKERR_NOMOUSE -38
// Joystick not attached or not working properly
#define CKERR_NOJOYSTICK -39
// Try to link imcompatible Parameters
#define CKERR_INCOMPATIBLEPARAMETERS -40
// There is no render engine dll
#define CKERR_NORENDERENGINE -44
// There is no current level (use CKSetCurrentLevel )
#define CKERR_NOCURRENTLEVEL -45
// Sound Management has been disabled
#define CKERR_SOUNDDISABLED -46
// DirectInput Management has been disabled
#define CKERR_DINPUTDISABLED -47
// Guid is already in use or invalid
#define CKERR_INVALIDGUID -48
// There was no more free space on disk when trying to save a file
#define CKERR_NOTENOUGHDISKPLACE -49
// Impossible to write to file (write-protection ?)
#define CKERR_CANTWRITETOFILE -50
// The behavior cannnot be added to this entity
#define CKERR_BEHAVIORADDDENIEDBYCB -51
// The behavior cannnot be added to this entity
#define CKERR_INCOMPATIBLECLASSID -52
// A manager was registered more than once
#define CKERR_MANAGERALREADYEXISTS -53
// CKprocess or TimeManager process while CK is paused will fail
#define CKERR_PAUSED -54
// Some plugins were missing whileloading a file
#define CKERR_PLUGINSMISSING -55
// Virtools version too old to load this file
#define CKERR_OBSOLETEVIRTOOLS -56
// CRC Error while loading file
#define CKERR_FILECRCERROR -57
// A Render context is already in Fullscreen Mode
#define CKERR_ALREADYFULLSCREEN -58
// Operation was cancelled by user
#define CKERR_CANCELLED -59
// there were no animation key at the given index
#define CKERR_NOANIMATIONKEY -121
// attemp to acces an animation key with an invalid index
#define CKERR_INVALIDINDEX -122
// the animation is invalid (no entity associated or zero length)
#define CKERR_INVALIDANIMATION -123

27
CodeGen/src/CKMISC.txt Normal file
View File

@ -0,0 +1,27 @@
enum !CK_FILE_WRITEMODE
CKFILE_UNCOMPRESSED =0, // Save data uncompressed
CKFILE_CHUNKCOMPRESSED_OLD =1, // Obsolete
CKFILE_EXTERNALTEXTURES_OLD=2, // Obsolete : use CKContext::SetGlobalImagesSaveOptions instead.
CKFILE_FORVIEWER =4, // Don't save Interface Data within the file, the level won't be editable anymore in the interface
CKFILE_WHOLECOMPRESSED =8, // Compress the whole file
enum !CK_LOAD_FLAGS
CK_LOAD_ANIMATION =1<<0, // Load animations
CK_LOAD_GEOMETRY =1<<1, // Load geometry.
CK_LOAD_DEFAULT =CK_LOAD_GEOMETRY|CK_LOAD_ANIMATION, // Load animations & geometry
CK_LOAD_ASCHARACTER =1<<2, // Load all the objects and create a character that contains them all .
CK_LOAD_DODIALOG =1<<3, // Check object name unicity and warns the user with a dialog box when duplicate names are found.
CK_LOAD_AS_DYNAMIC_OBJECT =1<<4, // Objects loaded from this file may be deleted at run-time or are temporary
CK_LOAD_AUTOMATICMODE =1<<5, // Check object name unicity and automatically rename or replace according to the options specified in CKContext::SetAutomaticLoadMode
CK_LOAD_CHECKDUPLICATES =1<<6, // Check object name unicity (The list of duplicates is stored in the CKFile class after a OpenFile call
CK_LOAD_CHECKDEPENDENCIES =1<<7, // Check if every plugins needed are availables
CK_LOAD_ONLYBEHAVIORS =1<<8, //
enum CK_FO_OPTIONS
CK_FO_DEFAULT = 0, // Default behavior : a new object will be created with the name stored in CKFileObject
CK_FO_RENAMEOBJECT, // Renaming : a new object will be created with the name stored in CKFileObject + a integer value XXX to ensure its uniqueness
CK_FO_REPLACEOBJECT, // Do not create a new object, instead use an existing one which CK_ID is given by CreatedObject
// to load the chunk on
CK_FO_DONTLOADOBJECT, // Object chunk will not be read either because it is a reference
// or because the loaded object already exist in the current level
// and the user choose to keep the existing one.

View File

@ -0,0 +1,70 @@
#define CKCID_OBJECT 1
#define CKCID_PARAMETERIN 2
#define CKCID_PARAMETEROPERATION 4
#define CKCID_STATE 5
#define CKCID_BEHAVIORLINK 6
#define CKCID_BEHAVIOR 8
#define CKCID_BEHAVIORIO 9
#define CKCID_RENDERCONTEXT 12
#define CKCID_KINEMATICCHAIN 13
#define CKCID_SCENEOBJECT 11
#define CKCID_OBJECTANIMATION 15
#define CKCID_ANIMATION 16
#define CKCID_KEYEDANIMATION 18
#define CKCID_BEOBJECT 19
#define CKCID_DATAARRAY 52
#define CKCID_SCENE 10
#define CKCID_LEVEL 21
#define CKCID_PLACE 22
#define CKCID_GROUP 23
#define CKCID_SOUND 24
#define CKCID_WAVESOUND 25
#define CKCID_MIDISOUND 26
#define CKCID_MATERIAL 30
#define CKCID_TEXTURE 31
#define CKCID_MESH 32
#define CKCID_PATCHMESH 53
#define CKCID_RENDEROBJECT 47
#define CKCID_2DENTITY 27
#define CKCID_SPRITE 28
#define CKCID_SPRITETEXT 29
#define CKCID_3DENTITY 33
#define CKCID_GRID 50
#define CKCID_CURVEPOINT 36
#define CKCID_SPRITE3D 37
#define CKCID_CURVE 43
#define CKCID_CAMERA 34
#define CKCID_TARGETCAMERA 35
#define CKCID_LIGHT 38
#define CKCID_TARGETLIGHT 39
#define CKCID_CHARACTER 40
#define CKCID_3DOBJECT 41
#define CKCID_BODYPART 42
#define CKCID_PARAMETER 46
#define CKCID_PARAMETERLOCAL 45
#define CKCID_PARAMETERVARIABLE 55
#define CKCID_PARAMETEROUT 3
#define CKCID_INTERFACEOBJECTMANAGER 48
#define CKCID_CRITICALSECTION 49
#define CKCID_LAYER 51
#define CKCID_PROGRESSIVEMESH 54
#define CKCID_SYNCHRO 20
#define CKCID_OBJECTARRAY 80
#define CKCID_SCENEOBJECTDESC 81
#define CKCID_ATTRIBUTEMANAGER 82
#define CKCID_MESSAGEMANAGER 83
#define CKCID_COLLISIONMANAGER 84
#define CKCID_OBJECTMANAGER 85
#define CKCID_FLOORMANAGER 86
#define CKCID_RENDERMANAGER 87
#define CKCID_BEHAVIORMANAGER 88
#define CKCID_INPUTMANAGER 89
#define CKCID_PARAMETERMANAGER 90
#define CKCID_GRIDMANAGER 91
#define CKCID_SOUNDMANAGER 92
#define CKCID_TIMEMANAGER 93
#define CKCID_CUIKBEHDATA -1
#define CKCID_MAXCLASSID 56
#define CKCID_MAXMAXCLASSID 128