Core Game Engine (Oglr.Core)

The Core Game Engine (Oglr.Core) serves as the foundational component of the Oglr project. It encompasses the core functionality required for game development, including scene management, rendering, input handling, and asset loading. This section delves into the inner workings of the Core Game Engine, providing insights into its design and usage.

Key Components

  • Scene Management: The Oglr.Core engine provides a robust scene management system, enabling developers to organize and manage game objects, components, and resources within a hierarchical scene graph.

    • Scene Graph: The engine utilizes a hierarchical scene graph to represent the relationships between objects in a scene. This allows for efficient object traversal and manipulation. Oglr/Core/Scene/Scene.cs
    • Game Objects: Objects within the scene are represented as instances of the GameObject class. Each object can hold components that define its behavior and appearance. Oglr/Core/Scene/GameObject.cs
    • Components: Components are modular units that can be attached to game objects to add specific functionality or properties. Oglr/Core/Scene/Components/Component.cs
  • Rendering: The Core Game Engine leverages OpenGL for rendering, providing capabilities to render 3D graphics, textures, and materials.

  • Input Handling: The Core Game Engine provides a mechanism for handling user input, allowing developers to respond to keyboard, mouse, and gamepad events.

  • Asset Loading: The engine provides mechanisms for loading and managing various game assets, including models, textures, sounds, and scripts.

    • Asset Manager: The asset manager handles the loading and caching of assets, ensuring efficient resource utilization. Oglr/Core/Assets/AssetManager.cs
    • Asset Types: The engine supports a variety of asset types, each with specific loading and handling procedures. Oglr/Core/Assets/Asset.cs

Usage

The Core Game Engine is designed to be used as the foundation for game development. Developers can leverage the provided functionality to create their game logic, manage assets, handle input, and render graphics.

  • Game Loop: The GameLoop class provides the main game loop responsible for updating the game state, handling input, and rendering frames. Oglr/Core/GameLoop.cs

  • Game State: Developers can create and manage their game state within the engine, using components and scripts to define game logic and behavior.

  • Game Object Management: Developers can create, destroy, and modify game objects within the scene, using the provided API.

  • Rendering: Developers can utilize the rendering system to create and render 3D graphics, textures, and materials.

  • Input Handling: Developers can subscribe to input events and respond to user input, triggering actions or updating game logic.

  • Asset Loading: Developers can load and manage various game assets, such as models, textures, sounds, and scripts.

Examples

  • Creating a Game Object:
// Create a new game object
          GameObject cube = new GameObject("Cube");
          
          // Add a MeshRenderer component
          cube.AddComponent<MeshRenderer>();
          
          // Add a MeshFilter component and load a cube mesh
          MeshFilter meshFilter = cube.AddComponent<MeshFilter>();
          meshFilter.Mesh = AssetManager.Load<Mesh>("cube.obj");
          
          // Set the material for the cube
          cube.GetComponent<MeshRenderer>().Material = AssetManager.Load<Material>("default.mat");
          
          // Add the cube to the scene
          Scene.Instance.Root.AddChild(cube);
          
  • Handling Keyboard Input:
// Subscribe to the KeyboardInputEvent
          InputManager.Instance.KeyboardInputEvent += OnKeyboardInput;
          
          // Handle the keyboard input event
          private void OnKeyboardInput(KeyboardInputEvent e)
          {
              if (e.Key == Keys.W)
              {
                  // Move the player forward
                  // ...
              }
          }
          
  • Loading a Texture:
// Load a texture from the assets folder
          Texture2D texture = AssetManager.Load<Texture2D>("mytexture.png");