Atypical 2D game engine orx Source Code Reading Notes (1) Overall Structure

Source: Internet
Author: User

Write by nine days Yan Ling (jtianling) -- blog.csdn.net/vagrxie

Discuss newsgroups and documents

Preface

If you do not know about orx at all, refer to the orx library I wrote.
And the official homepage
.

I have been learning orx for a long time, but I have only learned some basic usage and have not studied the source code. When I use orx to write a game, I am often helpless because of a configuration problem, I turned to iarwain for help. Recently, when porting A Win32 compiled game to the iPhone, I encountered a problem and was still helpless, because I decided to check the orx source code. Otherwise, fate is always not in your own hands, just like hitting the big program. This is also one of the biggest requirements for selecting an engine at that time. It is one of the benefits of open source. Orx, a "data-driven" engine, makes it even more important to understand the source code, because I feel that for me, I am more able to find errors in calling an API, it is very difficult to find a configuration error. I always think this is one of the drawbacks of orx "data-driven", which is also the reason I think orx is not typical.

 

Source code reading ideas and objectives

For reading the source code, I still use my personal habits to first understand each module as a whole, then separately understand the source code of each module, and finally take a look at the main execution process, understand how modules are combined.

For reading the orx source code, I still don't want to get to the point where the sentence is understood. Basically, I still focus on the overall understanding. I am concerned about the rendering part that I am interested in, the degree of understanding of the source code can finally be completely separated from the orx configuration module, and each module can be combined by its own code to implement basic orx functions. As a cross-platform engine, orx cannot be used to analyze all supported platforms. The major concern is the Win32 and iPhone versions. Of course, in fact, orx cross-platform relies mainly on SDL, libraries such as glfw are implemented as plug-ins, so the code at the orx layer is actually the same. (The iPhone version is special)

In order to find the source code at any time, the latest orx1.2 version is used here, And the SVN version is not used.

 

Orx Overall Structure

As an iarwain orx with the goal of a complete game engine, the composition of the module is still relatively complex.

Physical Structure:

The orx source code directory can be basically distinguished:

Animation part

Base: the basic part, including some macros defined for cross-platform use. The macros and common constants, functions, and orx modules are required for processing.

Core: kernel, including clock, configuration, event, and Localization

Debug: logs and FPS display

Display: display part

IO: Io part, including file IO, and joystick, mouse, and keyboard input.

Main: main function parameter Processing

Math: Mathematical Correlation, including the implementation of a vector

Memory: memory processing part,

Object: Object part

Physics: physical

Plugin: plug-in section

Render: The rendering part, including the camera, special effects, Renderer, shader, and view.

Sound: Sound part

Utils: tool class, including hashtable, list, tree3 large containers implemented in C language, some useful string functions, and a screenshot implementation. (I think this is more suitable for display)

In addition, orx contains a set of plug-ins:

The components implemented by the plug-in include: Display, joystick, keyboard, mouse, physics, render, and sound.

There are currently four general plug-ins (functions other than physical and sound): glfw
, IPhone, SDL
, Sfml
.

Sfml is a plug-in used before version 1.1. Glfw is the default plug-in currently (version 1.2.

The sfml and glfw plug-ins support three mainstream platforms (Win32, Linux, and MACOs), and the SDL plug-ins only support Win32 and Linux.

The iPhone plug-in is specially added because the iPhone version is special and supports the iPhone/iPad platform.

The sound plug-in now has sfml plug-ins and openal plug-ins. Sfml is the default sound plug-in of versions earlier than 1.1, and openal is the default sound plug-in of version 1.2. The reason may be that the openal plug-in is too good, so although the author uses SDL, it does not use the SDL sound module for the SDL sound plug-in.

Currently, physical plug-ins are only implemented in box2d.

Logical Structure:

From an enumeration definition of "orxmodule. H", we can see the division of orx's overall logical modules.

/*
* Module Enum
*/

Typedef
Enum
_ Orxmodule_id_t

{

Orxmodule_id_anim = 0
,

Orxmodule_id_animpointer,

Orxmodule_id_animset,

Orxmodule_id_bank,

Orxmodule_id_body,

Orxmodule_id_camera,

Orxmodule_id_clock,

Orxmodule_id_config,

Orxmodule_id_display,

Orxmodule_id_event,

Orxmodule_id_file,

Orxmodule_id_filesystem,

Orxmodule_id_font,

Orxmodule_id_fps,

Orxmodule_id_frame,

Orxmodule_id_fx,

Orxmodule_id_fxpointer,

Orxmodule_id_graphic,

Orxmodule_id_input,

Orxmodule_id_joystick,

Orxmodule_id_keyboard,

Orxmodule_id_locale,

Orxmodule_id_main,

Orxmodule_id_memory,

Orxmodule_id_mouse,

Orxmodule_id_object,

Orxmodule_id_param,

Orxmodule_id_physics,

Orxmodule_id_plugin,

Orxmodule_id_render,

Orxmodule_id_screenshot,

Orxmodule_id_shader,

Orxmodule_id_shaderpointer,

Orxmodule_id_sound,

Orxmodule_id_soundpointer,

Orxmodule_id_soundsystem,

Orxmodule_id_spawner,

Orxmodule_id_structure,

Orxmodule_id_system,

Orxmodule_id_text,

Orxmodule_id_texture,

Orxmodule_id_viewport,

Orxmodule_id_number,

Orxmodule_id_max_number = 64
,

Orxmodule_id_none = orxenum_none

} Orxmodule_id;

Because the enumerated values in English naming can clearly describe the content of each logic module, we will not describe them here.

Referenced external project

Now it's not the time to start everything from scratch. As a game engine, there are too many content to handle, and it's hard to handle it all by yourself, orx uses some external libraries to complete some corresponding functions.

Deep Blue made some summary in the official Chinese forum of orx
, More detailed for your reference.

Here is a simple description:

Box2d: physical part

FreeType: used to create a font tool. Because the orx engine itself does not support the material generated by FreeType for font display, the orx engine itself does not need FreeType.

Glfw, SDL, sfml: As a plug-in implementation of the main module, it is mainly used to solve cross-platform problems.

Soil: used to support common image formats.

Openal: voice processing.

Stb_vorbis: supported Ogg sound formats.

Libsndfile: WAV and AIFF sound formats are supported.

I only described the general situation. For details about the reference of external projects and plug-ins, refer to changelog of orx.
.

About sfml

Some additional sfml information is provided at the end. Although it is irrelevant to the overall structure of orx, it is also recorded here.

Many external engineering references start with the new 1.2, and are introduced to replace sfml-related components. That is to say, finally, orx uses glfw/SDL + soil + openal + stb_vorbis + libsndfile to implement some sfml functions. This is really only part of the sfml function, just the part of the function required by orx. Here we can see how powerful sfml is. As the library of simple and fast multimedia library, sfml is too simple compared with SDL (Simple DirectMedia Layer. In fact, from the sfml license page
As you can see, sfml itself is used.

  • Glew
    Is under the BSD license
    , The SGI license
    Or the Glx license
  • Openal-soft
    Is under the lgpl license
  • Libsndfile
    Is under the lgpl license
  • Stb_vorbis
    Is public domain
  • Libjpeg
    Is public domain
  • Libpng
    Is under the zlib/PNG license
  • Zlib
    Is under the zlib/PNG license
  • Soil
    Is public domain
  • FreeType
    Is under the FreeType license
    Or the GPL license

So many external libraries. Orx is used to replace the corresponding libraries of sfml. It can be seen that these libraries are also basically used by sfml itself ........ # @ ¥ # @ % ...... ¥ #@...... ¥6

Iarwain's evaluation of sfml is powerful and simple, but buggy.

In addition, iarwain also uses these external libraries in terms of efficiency, but in changelog, there is such a sentence:

* Important: added new plugins for Embedded versions: SDL plugins for win/Linux (35-40% than the sfml ones) and glfw plugins for win/Linux/OSX (~ 2% faster than SDL ones ).

That is to say, version 1.2 is faster than Version 1.1, just because sfml is replaced by a new plug-in. I don't know if sfml is too powerful and feature-rich in the balance between simple and fast, which leads to a high cost for simple implementation.

On the Features page
As you can see, sfml even contains a network module .....

However, sfml uses C ++ combined with so many useful libraries above to achieve so many functions, and a bunch of other languages (such as Python, Ruby, D, and C #) are bound, we also use the free zlib/PNG protocol, which is worth a try. Especially when there is no high requirement on efficiency ......

 

The author of the original article retains the copyright reprinted. Please indicate the original author and give a link

Write by nine days Yan Ling (jtianling) -- blog.csdn.net/vagrxie

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.