Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor idGameEdit #369

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions neo/d3xp/GameEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,8 @@ void idEditEntities::DisplayEntities( void ) {
===============================================================================
*/

idGameEditExt gameEditLocal;
idGameEdit * gameEdit = &gameEditLocal;
idGameEditExt gameEditLocal;
idGameEditBase * gameEdit = &gameEditLocal;


/*
Expand Down
2 changes: 1 addition & 1 deletion neo/framework/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ unsigned int com_msgID = -1;

#ifdef __DOOM_DLL__
idGame * game = NULL;
idGameEdit * gameEdit = NULL;
idGameEditBase * gameEdit = NULL;
#endif

// writes si_version to the config file - in a kinda obfuscated way
Expand Down
87 changes: 83 additions & 4 deletions neo/framework/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,87 @@ class idProgram;
class idInterpreter;
typedef struct prstack_s prstack_t;

// FIXME: this interface needs to be reworked but it properly separates code for the time being
class idGameEdit {

class idGameEditBase {
public:
virtual ~idGameEditBase( void ) {}

// These are the canonical idDict to parameter parsing routines used by both the game and tools.
virtual void ParseSpawnArgsToRenderLight( const idDict *args, renderLight_t *renderLight ) = 0;
virtual void ParseSpawnArgsToRenderEntity( const idDict *args, renderEntity_t *renderEntity ) = 0;
virtual void ParseSpawnArgsToRefSound( const idDict *args, refSound_t *refSound ) = 0;

// Animation system calls for non-game based skeletal rendering.
virtual idRenderModel * ANIM_GetModelFromEntityDef( const char *classname ) = 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect const getters.

virtual const idVec3 &ANIM_GetModelOffsetFromEntityDef( const char *classname ) = 0;
virtual idRenderModel * ANIM_GetModelFromEntityDef( const idDict *args ) = 0;
virtual idRenderModel * ANIM_GetModelFromName( const char *modelName ) = 0;
virtual const idMD5Anim * ANIM_GetAnimFromEntityDef( const char *classname, const char *animname ) = 0;
virtual int ANIM_GetNumAnimsFromEntityDef( const idDict *args ) = 0;
virtual const char * ANIM_GetAnimNameFromEntityDef( const idDict *args, int animNum ) = 0;
virtual const idMD5Anim * ANIM_GetAnim( const char *fileName ) = 0;
virtual int ANIM_GetLength( const idMD5Anim *anim ) = 0;
virtual int ANIM_GetNumFrames( const idMD5Anim *anim ) = 0;
virtual void ANIM_CreateAnimFrame( const idRenderModel *model, const idMD5Anim *anim, int numJoints, idJointMat *frame, int time, const idVec3 &offset, bool remove_origin_offset ) = 0;
virtual idRenderModel * ANIM_CreateMeshForAnim( idRenderModel *model, const char *classname, const char *animname, int frame, bool remove_origin_offset ) = 0;

// Articulated Figure calls for AF editor and Radiant.
virtual bool AF_SpawnEntity( const char *fileName ) = 0;
virtual void AF_UpdateEntities( const char *fileName ) = 0;
virtual void AF_UndoChanges( void ) = 0;
virtual idRenderModel * AF_CreateMesh( const idDict &args, idVec3 &meshOrigin, idMat3 &meshAxis, bool &poseIsSet ) = 0;


// Entity selection.
virtual void ClearEntitySelection( void ) = 0;
virtual int GetSelectedEntities( idEntity *list[], int max ) = 0;
virtual void AddSelectedEntity( idEntity *ent ) = 0;

// Selection methods
virtual void TriggerSelected() = 0;

// Entity defs and spawning.
virtual const idDict * FindEntityDefDict( const char *name, bool makeDefault = true ) const = 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment on line 311.

virtual void SpawnEntityDef( const idDict &args, idEntity **ent ) = 0;
virtual idEntity * FindEntity( const char *name ) const = 0;
virtual const char * GetUniqueEntityName( const char *classname ) const = 0;

// Entity methods.
virtual void EntityGetOrigin( idEntity *ent, idVec3 &org ) const = 0;
virtual void EntityGetAxis( idEntity *ent, idMat3 &axis ) const = 0;
virtual void EntitySetOrigin( idEntity *ent, const idVec3 &org ) = 0;
virtual void EntitySetAxis( idEntity *ent, const idMat3 &axis ) = 0;
virtual void EntityTranslate( idEntity *ent, const idVec3 &org ) = 0;
virtual const idDict * EntityGetSpawnArgs( idEntity *ent ) const = 0;
virtual void EntityUpdateChangeableSpawnArgs( idEntity *ent, const idDict *dict ) = 0;
virtual void EntityChangeSpawnArgs( idEntity *ent, const idDict *newArgs ) = 0;
virtual void EntityUpdateVisuals( idEntity *ent ) = 0;
virtual void EntitySetModel( idEntity *ent, const char *val ) = 0;
virtual void EntityStopSound( idEntity *ent ) = 0;
virtual void EntityDelete( idEntity *ent ) = 0;
virtual void EntitySetColor( idEntity *ent, const idVec3 color ) = 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second parameter is copied.


// Player methods.
virtual bool PlayerIsValid() const = 0;
virtual void PlayerGetOrigin( idVec3 &org ) const = 0;
virtual void PlayerGetAxis( idMat3 &axis ) const = 0;
virtual void PlayerGetViewAngles( idAngles &angles ) const = 0;
virtual void PlayerGetEyePosition( idVec3 &org ) const = 0;

// In game map editing support.
virtual const idDict * MapGetEntityDict( const char *name ) const = 0;
virtual void MapSave( const char *path = NULL ) const = 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚑 ⚠️ Virtual functions and default parameters should not be used together.
Virtual functions bind dynamically, but default function parameter values bind statically.
So if you implement this function in a derived class with a different default parameter, and you call it through a base pointer without parameter, it will use the default parameter specified in the base class, not the one in the derived class!

virtual void MapSetEntityKeyVal( const char *name, const char *key, const char *val ) const = 0;
virtual void MapCopyDictToEntity( const char *name, const idDict *dict ) const = 0;
virtual int MapGetUniqueMatchingKeyVals( const char *key, const char *list[], const int max ) const = 0;
virtual void MapAddEntity( const idDict *dict ) const = 0;
virtual int MapGetEntitiesMatchingClassWithString( const char *classname, const char *match, const char *list[], const int max ) const = 0;
virtual void MapRemoveEntity( const char *name ) const = 0;
virtual void MapEntityTranslate( const char *name, const idVec3 &v ) const = 0;
};


class idGameEdit : public idGameEditBase {
public:
virtual ~idGameEdit( void ) {}

Expand Down Expand Up @@ -318,7 +397,7 @@ class idGameEdit {
virtual void MapEntityTranslate( const char *name, const idVec3 &v ) const;
};

extern idGameEdit * gameEdit;
extern idGameEditBase * gameEdit;

// In game script Debugging Support
class idGameEditExt : public idGameEdit {
Expand Down Expand Up @@ -388,7 +467,7 @@ typedef struct {

int version; // API version
idGame * game; // interface to run the game
idGameEdit * gameEdit; // interface for in-game editing
idGameEditBase * gameEdit; // interface for in-game editing

} gameExport_t;

Expand Down
4 changes: 2 additions & 2 deletions neo/game/GameEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,8 @@ void idEditEntities::DisplayEntities( void ) {
===============================================================================
*/

idGameEditExt gameEditLocal;
idGameEdit * gameEdit = &gameEditLocal;
idGameEditExt gameEditLocal;
idGameEditBase * gameEdit = &gameEditLocal;


/*
Expand Down