Fichier texte en cours : Idées géniales de programmation.txt






Jeu vidéo :

         - utiliser un MeshCache ou Mesh comme Ogre::Entity* m_pEntity; que l'on peut attacher à une SceneNode

         - utiliser une class Packet
         
         - utiliser une class SocketUDP :

                  - class SocketUDP
                           {
                           public:
                                    SocketUDP(const std::string& sHostAddress);
                                    virtual ~SocketUDP();

                                    // Pour attacher le socket
                                    void bindSocket();
                                    // Pour fermer le socket
                                    void close();

                                    // Pour savoir si le socket est attaché
                                    bool isBound();
                                    // Pour récuperer l'adresse IP locale
                                    std::string& getHostAddress();
                                    // Pour récuperer le port
                                    unsigned int getPort();

                                    // Envoyer des données
                                    bool send(const char* data, std::size_t size, std::string& sAddress);
                                    bool send(Packet& packetToSend, std::string& sAddress);

                           private:
                                    SOCKET m_socket;
                                    unsigned int m_iPort;
                                    std::string m_sHostAddress;
                                    bool m_bBound;
                           };

         - #define ASSERT_SKIP_IF_FAILED(expr, msg) if (expr) ...

         - Combiner les mouvements :
         
                  enum FPSCameraMovement
                  {
                           CAMERA_MOVE_UPWARD = 0x01,
                           CAMERA_MOVE_BACKWARD = 0x02,
                           CAMERA_MOVE_UP = 0x04,
                           CAMERA_MOVE_DOWN = 0x08,
                           CAMERA_STRAFE_LEFT = 0x10,
                           CAMERA_STRAFE_RIGHT = 0x20,
                           CAMERA_MOVE_NONE = 0x030
                  };

                  enum CameraMode
                  {
                           CAMERA_FIRST_PERSON,
                           CAMERA_THIRD_PERSON
                  };

                  
         - enum GameStates
         {
                  ON_CONSOLE,
                  ON_LOADING_MENU,
                  ON_PLAYER_INVENTORY,
                  ON_PARAMETERS_MENU,
                  ON_MESSAGERIE,
                  ON_WORLD
         };

         - BIT(1) ; BIT(2) ; sur chaque énumeration, etc...
         
         -
                  switch (GAME_STATE_MANAGER->GetState())
                  {
                           case GameState::ON_CONSOLE | GameState::ON_WORLD:
                                    CONSOLE->appendCommandLineText(pszText);
                                    break;

                           case GameState::ON_LOADING_MENU:
                                    break;
                  }


         - mot clé Event pour afficher tous les events possible
         
         - mot clé Event pour exécuter un fichier batch de commandes
         
         - IMPLEMENT_GAME_EVENT( OnCameraMovementBackward )
         
         - IMPLEMENT_GAME_EVENT( OnPlayerMoveBackward )
         
         - tout doit être déclaré Event dans le jeu pour effectuer un appel de suites d'events de déboguage

         - DECLARE_GAME_EVENT_WITH_PARAMETERS( TakeScreenShot, 3, "ScreenshotName", "ScreenshotName2", "ScreenshotName3" );
         
         
         - GameStateManager :
                  
                  void SetState(GameState::GameStates state);

                  void ChangeState(GameState* pState);

                  void PushState(GameState* pState);
                  void PopState();         
                  
                  
         - class Mob : enum DeplacementMode {AGGRO, UNAGGRO, IDLE, ATTACK};
         
         - class FaderTextDisplay :
         
                  enum FadeOp
                  {
                           FADE_NONE,
                           FADE_IN,
                           FADE_OUT,
                  };
                  
         - TextAnnouncer : fade out / fade individually
         
         - EventShortCutManager :
         
                  INPUT_MANAGER->AssociateRepetitiveShortcutToEvent(OIS::KC_W, GET_EVENT("OnCameraMovementUpward"));
                  INPUT_MANAGER->AssociateRepetitiveShortcutToEvent(OIS::KC_S, GET_EVENT("OnCameraMovementBackward"));
                  INPUT_MANAGER->AssociateRepetitiveShortcutToEvent(OIS::KC_A, GET_EVENT("OnCameraMovementStrafeLeft"));
                  INPUT_MANAGER->AssociateRepetitiveShortcutToEvent(OIS::KC_D, GET_EVENT("OnCameraMovementStrafeRight"));
                  
         - EventShortcut :
         
                  EventShortcut sc;

                  sc.AddComboKey(OIS::KC_W);
                  sc.AddComboKey(OIS::KC_A);

                  INPUT_MANAGER->AssociateRepetitiveShortcutToEvent(sc, GET_EVENT("OnCameraMovementUpwardLeft"));

         - Paramètrage des events :
         
                  DataParameters* pEventParams = new DataParameters("MOTD", "Welcome");
                  INPUT_MANAGER->RegisterDirectInputKeyDataParameters( GET_EVENT("OnConsolePrintMOTD"), OIS::KC_F7, pEventParams );                   
                  
         - EventShortCut :
         
                  class EventShortcut
                  {
                  public:
                           EventShortcut();
                           virtual ~EventShortcut();

                           void AddComboKey(OIS::KeyCode keycode);

                           OIS::KeyCode GetKey(unsigned int index);
                           int GetNumKeys();

                           bool IsPressedKeysCombo(std::vector& m_pressedKeys);

                           // retourne vrai si le shortcut est un combo de touches
                           bool IsCombo();

                           void SetEvent(Event* pEvent);
                           Event* getEvent();

                           void SetDataParameters(DataParameters* pParam);
                           DataParameters* GetDataParameters();

                           std::string GetName();

                  private:
                           Event* m_pEvent;
                           DataParameters* m_pParameters;
                           std::vector m_keys;
                           static int m_ID;
                  };
         
         
         
GUIButton :

         - ajouter une image possible quand on a cliqué dessus

Fonctions :

         - ToAsciiEx

         - ToUnicodeEx
         
         - ShellExecute
         
         - stricmp


CryEngine ---------->


PARTIE ENGINE :


         - gEnv->pGame->GetIGameFramework()->GetIGameRulesSystem()->Set[A.Z](...)

                  -> on peut appeler tous les modules à partir d'un objet globale gEnv

                  -> mettre un I majuscule

         - bool CGameRules::Init(IGameObject* pGameObject)

                  -> gEnv->pGame->GetIGameFramework()->GetIGameRulesSystem()->SetCurrentGameRules(this);

         - class CGameRules

                  -> pour instancier des règles de jeu
         
         - CGameObjectExtensionHelper ...
         
                           -> spécification spéciale de template

         - void PostInit

                  -> Initialisation suivant la destruction de l'objet

         - REGISTER_INT("mono_targetfps", 0, 0, "Defines target FPS for Mono Application.");

                  - pour initialiser une variable de type entier

         - m_pGameFramework->PreUpdate

                  - avant l'update
                  
                  
         - m_pGameFramework->PostUpdate
         
                  - après l'update
                  
                  
         - GAME_LONGNAME & GAME_NAME :

                  static const char* GAME_NAME = "GameZero";

                  static const char* GAME_LONGNAME = "CRYENGINE SDK Game Example";
                  static const char* GAME_GUID = "{00000000-1111-2222-3333-444444444444}";
         
         - Shutdown()
         
                  - ferme / éteint l'objet
                  
                  
         - GameEndLevel()
         
                  -> fin de jeu d'un niveau

         - RegisterGameObject :

                  RegisterGameObject("Player", "", eGORF_HiddenInEditor);          
                  RegisterGameObject("ViewExtension", "", eGORF_NoEntityClass);

                  RegisterGameObject("GameRules", "", eGORF_HiddenInEditor);

         - virtual void Release() override;

         - pGameObject->BindToNetwork()

                  -> enregistre cet objet dans la couche réseau
                  
         - REGISTER_CVAR2("gamezero_cam_fov", &m_camFOV, 60.0f, VF_NULL, "Camera FOV.");

         - virtual void GetMemoryUsage(ICrySizer* pSizer) const override {}

                           -> savoir combien de mémoire l'objet occupe
                           
                           
         - Events :

                  virtual void HandleEvent(const SGameObjectEvent& event) override {}

                  virtual void ProcessEvent(SEntityEvent& event) override {}

         - Memory Usage counter :

                  virtual void GetMemoryUsage(ICrySizer* s) const                   
                  {                            
                           SIZER_SUBCOMPONENT_NAME(s, "CFlowGameEntityFactory");                            
                           s->AddObject(this, sizeof(*this) );
                           s->AddObject(m_inputs);
                           s->AddObject(m_outputs);                            
                  }

         - bool SerializeXML()
         
                  - sauvegarde les données dans un fichier XML

         - ICrySizer :

         - CRY_ASSERT_MESSAGE(m_callbacks.empty(), "Using global callback with individually specified callbacks: not supported");

         - FUNCTION_PROFILER(GetISystem(), PROFILE_ACTION);

         - void EnablePlayer(bool bPlayer);

                           - active le joueur
                           
         - virtual bool SetGameMode(bool bGameMode) override;          
         - virtual IEntity* GetPlayer() override;

         - virtual void HidePlayer(bool bHide) override;

                           - cache le joueur
                           
         - virtual void SetPlayerPosAng(Vec3 pos, Vec3 viewDir) override;

                           - oriente le joueur vers une direction

         - virtual void OnBeforeLevelLoad() override;          
                           - avant le chargerment du niveau
                           
         - virtual void OnAfterLevelLoad(const char* levelName, const char* levelFolder) override;

                           - après le chargement du niveau
                           
         - virtual void OnCloseLevel() override {}

                           - au moment de la fermeture du niveau
                           
         - virtual void OnSaveLevel() override {}

                           - au moment de l'enregistrement du niveau
                           
         - gEnv->pLog->LogWarning("Failed spawning player");

                           - imprime un message d'avertissement
                           
         - IEntity* CEditorGame::GetPlayer()           {
                  return gEnv->pEntitySystem->GetEntity(LOCAL_PLAYER_ENTITY_ID);           }

         - bool CEditorGame::ConfigureNetContext(bool on)
         {
                  bool ok = false;

                  IGameFramework* pGameFramework = m_pGame->GetIGameFramework();

                  if (on == m_bEnabled)
                  {
                           ok = true;
                  }
                  else if (on)
                  {
                           SGameContextParams ctx;

                           SGameStartParams gameParams;
                           gameParams.flags = eGSF_Server
                                    | eGSF_NoSpawnPlayer
                                    | eGSF_Client
                                    | eGSF_NoLevelLoading
                                    | eGSF_BlockingClientConnect
                                    | eGSF_NoGameRules
                                    | eGSF_NoQueries;

                           gameParams.flags |= eGSF_LocalOnly;
                           gameParams.connectionString = "";
                           gameParams.hostname = "localhost";
                           gameParams.port = 60695;
                           gameParams.pContextParams = &ctx;
                           gameParams.maxPlayers = 1;

                           if (pGameFramework->StartGameContext(&gameParams))
                                    ok = true;
                  }
                  else
                  {
                           pGameFramework->EndGameContext();
                           gEnv->pNetwork->SyncWithGame(eNGS_Shutdown);
                           ok = true;
                  }

                  m_bEnabled = on && ok;
                  return ok;
         }

         - void CEditorGame::OnBeforeLevelLoad()
         {
                  EnablePlayer(false);
                  ConfigureNetContext(true);
                  m_pGame->GetIGameFramework()->GetIGameRulesSystem()->CreateGameRules("SinglePlayer");
                  m_pGame->GetIGameFramework()->GetILevelSystem()->OnLoadingStart(0);
         }

         void CEditorGame::OnAfterLevelLoad(const char* levelName, const char* levelFolder)
         {
                  ILevelInfo* pLevel = m_pGame->GetIGameFramework()->GetILevelSystem()->SetEditorLoadedLevel(levelName);
                  m_pGame->GetIGameFramework()->GetILevelSystem()->OnLoadingComplete(pLevel);
                  EnablePlayer(true);
         }


         - public IEngineModule :

                  - CRYINTERFACE_SIMPLE(IEngineModule)                   CRYGENERATE_SINGLETONCLASS(CEngineModule_CryFont, "EngineModule_CryFont", 0x6758643f43214957, 0x9b920d898d31f434)

         - ModuleInitISystem(pSystem, "CryFont");

         - V_RETURN(hr);

         -          int LoadFontFromFile(const string& szFileName);          
                  int LoadFontFromMemory(unsigned char* pFileBuffer, int iDataSize);

         - (IConsoleCmdArgs* pArgs)

         - CryLogAlways("Using FreeType %d.%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH);                            
                           --> utilise les varidics parameters
                           
         - struct CLightEntity : public ILightSource, public Cry3DEngineBase

         - IRenderer* pRenderer

         - une classe pour gérer les fichiers Bitmap CFBitmap

         - DrawString(float x, float y, const char* pStr)

         - pSystem->CompressDataBlock()

          struct SNodeInfo;

         - class C3DEngine : public I3DEngine, public Cry3DEngineBase

         - virtual void OnFrameStart();
         
         - virtual bool LoadLevel(const char* szFolderName, const char* szMissionName);
         
         - virtual void UnloadLevel();          
                  - décharge le niveau
                  
         - virtual void PostLoadLevel();

                  - après le chargement du niveau
                  
                  
         - CryEngineDecalInfo :
         

         - int GetLoadedObjectCount();
         
         - ColorB(0x00, 0xff, 0xff), // cyan

         - SEffect* pEffect = AddEffect("default");

                           pEffect->AddPass();

         - virtual float GetTerrainZ(int x, int y);
         
         - virtual voidSetFogColor(const Vec3& vFogColor);          

         virtual Vec3 GetFogColor();

         - const uint8 CCRC8::m_table[256] =
         {
                  0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15,                   0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d
         }

         -          
                  struct ICVar;
                  class CNetNub;
                  class CNetContext;
                  struct INetworkMember;
                  struct IConsoleCmdArgs;
                  class CNetworkInspector;
                  class CServiceManager;
         
         -
                  #ifdef NET_THREAD_TIMING
                           #define NET_START_THREAD_TIMER() CNetwork::Get()->ThreadTimerStart()
                           #define NET_STOP_THREAD_TIMER() CNetwork::Get()->ThreadTimerStop()
                           #define NET_TICK_THREAD_TIMER() CNetwork::Get()->ThreadTimerTick()
                  #else
                           #define NET_START_THREAD_TIMER()
                           #define NET_STOP_THREAD_TIMER()
                           #define NET_TICK_THREAD_TIMER()
                  #endif

         -

                  struct PerformanceGuard
                  {
                           SNetworkPerformance* m_pCounter;
                           uint64 m_nOldVal;

                           PerformanceGuard(SNetworkPerformance* p, uint64 oldVal)
                           {
                                    m_pCounter = p;
                                    m_nOldVal = oldVal;
                                    p->m_nNetworkSync = CryGetTicks();
                           }

                           ~PerformanceGuard()
                           {
                                    m_pCounter->m_nNetworkSync = CryGetTicks() - m_pCounter->m_nNetworkSync + m_nOldVal;
                           }

                  };


PARTIE NETWORK :

         - GetMemoryStatistics(ICrySizer* pSizer);

         - const char* GetHostName();

                  - retourne le nom d'hôte

         - void SetCDKey(const char* key);

                           - spécifie la clé CD
                           
                  
         - SNetGameInfo GetNetGameInfo();

         - CWorkQueue

         - virtual const CNetCVars& GetCVars()

         - bool m_bQuitting;

         - PRINTF_PARAMS // pour imprimer des paramètres !

         - void NetLog(const char* fmt, ...) PRINTF_PARAMS(1, 2); // CryLog
         
         - COUNTER(clientCheckContext);

         - static const int TIMER_HERTZ = 250;

         - #define S_ADDR_IP4(ADDR) ((ADDR).sin_addr.S_un.S_addr)

         - #define ONE_K_BITS 1000

         - CryFixedStringT<1024> stringBufferTemp;

         - REGISTER_CVAR2_DEV_ONLY
         
         - REGISTER_STRING_DEV_ONLY

         - uint32 channelIndex = CNetCVars::Get().netDebugChannelIndex;

         - DrawLine(3, s_white, "Name : Sends : BandWidth");

         - DrawDebugLine(x, y++, "Current Num Allocations %4d", s_MMMDebug.m_currentNumAllocs);

         - virtual void OnWriteToConsole(const char* sText, bool bNewLine);
          virtual void OnWriteToFile(const char* sText, bool bNewLine);

         - REGISTER_COMMAND_DEV_ONLY("net_ExpKeyXch_test", CExponentialKeyExchange::Test, 0, "");

         - struct SScanCode
          {
                  char lc; // lowercase
                  char uc; // uppercase
                  char ac; // alt gr
                  char cl; // caps lock (differs slightly from uppercase)
          };

         - IThread :

         - MapSymbol(XINPUT_GAMEPAD_DPAD_UP, eKI_XI_DPadUp, "xi_dpad_up");

         - CryFatalError("Error spawning \"InputWorker\" thread.");

         - class CInputCVars : { toutes les CVars liées à l'Input }

         - virtual void ClearKeyState();

         - public ISystemEventListener :
         
         - unsigned char Event2ASCII(const SInputEvent& event);          
         - unsigned char ToAscii(unsigned int vKeyCode, unsigned int k, unsigned char sKState[256]) const;          
         - wchar_t ToUnicode(unsigned int vKeyCode, unsigned int k, unsigned char sKState[256]) const;

         - toujours utiliser des interfaces pour l'héritage comme suit : class CScriptTable : public IScriptTable

         - extern CTimeValue g_time;
         
         - ILINE CStatsCollector* GetStats() // Macro pour fonction inline

         - class CNetwork::CNetworkThread : public IThread // On peut spécifier un namespace
         
         - while (Get()->UpdateTick(true) && gEnv && gEnv->pSystem && !gEnv->pSystem->IsQuitting()) // Pour faire un tourner un thread réseau
         {
         }

         - faire de petites classes avec à chaque fois une fonctionnalité particulière

         - #define FlushNetLog(...) // fonction vide !

         - void NetLogAlways(const char* fmt, ...) PRINTF_PARAMS(1, 2); // Imprime les paramètres

         - template // on peut définir des templates de cette façon

         - SetGlobalName("Sound");

MOT CLES INCONNUS :

         - audio RTPC

         - script Timer

         -

PARTIE SCRIPT :

         - #define bitmask(b) (1<<(b))

         - SCRIPT_REG_TEMPLFUNC(GetAudioTriggerID, "sTriggerName");

         -

         int CScriptBind_System::ShowDebugger(IFunctionHandler* pH)
         {
                  SCRIPT_CHECK_PARAMETERS(0);
                  float fInNSeconds;
                  pH->GetParam(1, fInNSeconds);

                  m_pSystem->GetIScriptSystem()->ShowDebugger(NULL, 0, "Invoked From User");
                  return pH->EndFunction();
         }

         -

         à mettre dans StdAfx.h :
         
         struct ISystem;
         struct ILog;
         struct IRenderer;
         struct IConsole;
         struct IInput;
         struct ITimer;
         struct IEntitySystem;
         struct I3DEngine;
         struct IPhysicalWorld;
         struct ICVar;
         
         -
         
         CScriptableBase::Init(pScriptSystem, pSystem);
         SetGlobalName("System");
         
         - std::unique_ptr<>

         - CEntity(SEntitySpawnParams& params);
         
                  -> passer une structure aulieu de paramètres !
                  
         - SDecalOwnerInfo() { memset(this, 0, sizeof(*this));
                  
                  -> initialiser une structure dès sa construction !!
         
         
         - CryFatalError("CTemporaryPool::Shutdown(): no temporary pool instance present");
         
         
PARTIE SYSTEM :

         - m_nFlags = 0;
         
         - Pour avoir l'index dans une map
         
         for (; it != itEnd; ++it)
         {
                  if (!strcmp(it->strName.c_str(), szComponentName) && it->nParent == nParent)
                           return (size_t)(it - m_arrNames.begin());//it-m_arrNames.begin();
         }
         
         -

IRRLICHT :

         - Implémenter un Animator qui fait bouger une SceneNode d'une certaine façon

         - faire une classe AABB

         - #define RANDOM_COLOR 0xFF000000 | ((rand() * 0xFFFFFF) / RAND_MAX)

         - void OnRegisterSceneNode()

         
         -          #ifdef _DEBUG
                           setDebugName("SMesh");
                  #endif

LouLou :

         - Yes::CMemoryManager::Instance().NextDelete(File, Line);
         
         
MOTS ANGLAIS :

         - Resolver

         - Aggressiveness

         - Foliage
         
         
         
DIVERS :

         - la programmation c'est un langage qui comporte des mots et un vocabulaire !!
         

#define CALL_ZLIB(x) { \
int status; \
status = x; \
if (status < 0) { \
fprintf (stderr, \
"%s:%d: %s returned a bad status of %d.\n", \
__FILE__, __LINE__, #x, status); \
exit (EXIT_FAILURE); \
} \
}
         
         On peut s'en inspirer pour appeler du code avec vérification !!
         

GAMEDLL :

         
         virtual bool IsPlayer() const { return true; }
         
         m_texture.reset(new EngineFacade::CDummyEngineTexture());
         




GAME CODING COMPLETE :

         - virtual bool VIsUsingDevelopmentDirectories(void) const { return false; }

                  - on peut spécifier directement le retour d'une fonction dans le code pour plus de clarté

         -