Game making experience (1)

xiaoxiao2021-03-06  47

Talking about some technical skills and frameworks about online games, but all are zero, this is good, but most novice or enthusiasts don't know how to start, let's talk about my game development experience.

Game development usually uses VC DX, you can use the Win32 API to create a Windows application framework, you can also use the MFC to create a Windows application framework, pay attention, not like many people, I feel very much. Slow, in fact, we just build an application framework with MFC, and MFC has a lot of well-used class libraries, which can improve our development efficiency, but does not affect our graphic rendering and data processing, because in graphics We rarely use the MFC, which does not affect the execution efficiency.

Of course, it is not necessary to spend a lot of time without MFC. You can choose according to your personal needs.

Most people know the basic structure of the game

Game_init ();

While () {if () {} else {update (); render ();}}

Game_DESTROY ();

Let me say that simple update () and render () functions generally say that different data updates are handled in their own different events, but there are many data-based data, such as: iDirectInput's state machine, you need to come at a certain time. Handling this data, then we can process it in the Update function. We can also simulate some custom event messages such as custom UI, or scripts.

Update () {while (events_count> 0) {do_events ();}}

About the rendering function is very simple, many game information introduces how to render, but rendering what I said later

RENDER () {begin_render ();

// Scene, role, UI, etc.

...

END_RENDER ();

The following is said to render content, rendering content is ready. We generally have two ways to organize data, one I call it a collection, one I call it is derived. 1. All objects have 2 class COBJ {// object of the object};

Typedef Cobj * Objptr;

CLASS CCOBJ {Protected:

Map m_lstobjs; // Object list

PUBLIC:

CCOBJ (); ~ ccobj () {clear ();} public: static ccobj * getInst ();

PUBLIC:

LoadFromConfigfile (Char * SZFILE); // Read objects from the configuration file

Objptr new (); // Direct new object BOOL Add (Objptr P); // Add new object BOOL Remove (ObjKey); // Remove Object Objptr Find (); // Retrieve Object

Void clear () / / all empty {map :: item.begin (); for (; it! = m_lstobjs.end (); i) {Objptr P = (* IT) ; If (p) {delete p; p = null;}} m_lstobjs.clear ();}};

Pay special attention to the destructor of the collection, and a function is getInst (), it is static, used to access this class, in fact, this collection class is a global instance, used to manage the entire This object used in the game. Then we need this to define this in the CPP file:

#include "obj.h"

CCOBJ G_CCOBJ;

CCOBJ * CCOBJ :: getInst () {Return & g_ccobj;}

In this way, we have processed the data of OBJ, use it as an on-demand, centrally release, such as:

#include "obj.h"

{... Objptr pnewobj = new cobj; ccobj :: getInst () -> add (pnewobj);

...}

We don't need to call DELETE PNEWOBJ to release the object, because when the program exits, the collection ccobj will release all the objects of all applications, don't worry about memory problems, just use it when you use it.

The above is a collection of integrated management

2, derived management derived management is what we define a base class COBJBASE {PUBLIC:

Typedef CobjBase * Cobjbaseptr;

Private:

map m_lstObjs; // list of objects public: bool AddSubObj (CObjBase * pChild) {m_lstObjs.insert (map :: value_type (pChild-> m_Key, pChild); return true;}

CobjBase (COBJBASE * PBASE) {if (pBase) {pBase-> addobj (this);}}

~ Cobjbase () {map :: item.begin (); for (; it! = M_lstobjs.end (); it) {cobjbaseptr p = (* it); if (p) ) {Delete p; p = null;}}

m_lstobjs.clear ();

}

This is like a big tree, and there are several subclasses under each node. When the release is released, the first-level level is mainly the root node needs to be manually released. It is more convenient to use, but it is actually recursive, so Generally used for casual games, usage as follows: COBJBASE * proot = new proot (null);

New cobjbase (proot); New cobjbase (proot); ... New cobjbase (proot);

DELETE PROOT;

When you have new New, you don't even return the value, we only need to release prooty. All other classes can be derived from this base class, such as:

Class Cobj1: Public CobjBase {};

Class Cobj2: public cobj1 {};

Use

P1 = new cobj1 (proot); new cobj2 (proot); p2 = new cobj2 (p1); new cobj2 (p2);

Still very convenient.

Today, I will talk so much, I will talk about next time.

转载请注明原文地址:https://www.9cbs.com/read-80838.html

New Post(0)