MiniKernel

분류:번역 분류:설계패턴


미니-커널(Mini-kernel)


Submitted by Zachary Booth Simpson on 12/5/2000 ?2000 - Zachary Booth Simpson.잺opied with permission from http://www.totempole.net. If you find any of this work useful, please sign Zack's guest book: http://www.totempole.net/cgi-bin/gbook.cgi.


날림 번역중... 2003-11-06 14:22, 파도


의도:

Provide each Controller with a chance to execute once per game frame.

각각의 컨트롤러 에게 game내의 매 frame 당 한번씩의 실행 기회를 제공

문제:

Without a mini-kernel, Model objects are typically updated by a set of hard-wired controller functions called from the main loop. For example:

void updateWorld()
{
    for( int i=0; i < numTanks; i++ )
    {
        if( tanks[i] )
        {
            updateTankPhysics( tanks[i] );
            updateTankAI( tanks[i] );
        }
    }
}

for( i=0; i < numSoldiers; i++ )
{
    ... etc ...
}

미니-커널을 사용하지 않는다면, 모델 객체들은 메인 루프에서 일련의 고정된 컨트롤러 함수들의 집합에 의해 새로운 정보로 갱신하는게 일반적이다.

void updateWorld()
{
    for( int i=0; i < numTanks; i++ )
    {
        if( tanks[i] )
        {
            updateTankPhysics( tanks[i] );
            updateTankAI( tanks[i] );
        }
    }
}

for( i=0; i < numSoldiers; i++ )
{
    ... etc ...
}

This style of updating requires that any new controller be hardwired into the update calls, which reduces encapsulation and increases maintenance. An operating-system-like method is needed where controllers can be created and removed dynamically as needed.

이런 구조는 다른 새로운 컨트롤러 가 추가될 때마다 갱신 루틴에 고정적으로 추가되어야 하기때문에 캡슐화를 저해하고 유지비용을 증가시킨다. 그러므로, 필요에 따라 동적으로 컨트롤러를 생성하고 삭제할 수 있는 방법이 필요하다.

해결책:

A base controller class is created which is the super-class of all controllers. A list of controller pointers is maintained. Each game frame, the mini-kernel (called from the main loop) gives each controller a chance to execute by calling a virtual 'update' method. This is a cooperative multi-tasking system. For example:

class BaseController {
    virtual void update() = 0;
}

class MissileController : BaseController {
    Model &amp;missle, &amp;target;
    virtual void update() {
        missile.pos += missile.vel;
        missile.vel += (target.pos ? missile.pos).norm() * missAcc;
    }
}

void miniKernelDoAllControllers() {
    foreach controller in list { controller.update(); }
}

모든 컨트롤러의 슈퍼-클래스인 기본 컨트롤러 클래스를 생성한다. 컨트롤러들의 주소값 리스트를 유지한다. 매 게임 프레임마다, (메인 루프에서 수행된) 미니-커널은 각 컨트롤러에게 가상 '갱신' 함수를 실행시킬 기회를 제공한다. 이는 일종의 멀티테스킹 시스템과 같다. 예를 들면 :

class BaseController {
    virtual void update() = 0;
}

class MissileController : BaseController {
    Model &amp;missle, &amp;target;
    virtual void update() {
        missile.pos += missile.vel;
        missile.vel += (target.pos ? missile.pos).norm() * missAcc;
    }
}

void miniKernelDoAllControllers() {
    foreach controller in list { controller.update(); }
}

Note that all controllers update calls are non-blocking; they are expected to do some actions quickly and return control back to the mini-kernel.

모든 컨트롤러 의 갱신 루틴은 non-blocking 이라는 점을 주시해라; 이 루틴들은 매우 빠르게 어떤 행동을 수행하고 미니-커널로 제어권을 다시 되돌려 주어야 한다.

It is often necessary to ensure that some controllers always run before others. For example, user interface may need to run before animation or physics to ensure that mouse clicks are interpreted with respect to the correct frame of reference. This can implemented with a priority number for each controller; the mini-kernel either sorts the controller pointers once per frame by priority or ensures that the list remains in sorted order.

때로 어떤 컨트롤러는 다른 컨트롤러보다 항상 먼저 수행되어야 한다는 것을 보장해줄 필요가 있다. 예를 들면, 유저 인터페이스 루틴은 마우스 클릭 동작이 참조 프레임에서 올바르게 해석도록 보장하기 위해서 애니메이션이나 물리 루틴 보다 먼저 수행할 필요가 있을 수도 있다. 이는 각 컨트롤러에 우선순위를 할당함으로써 구현이 가능하다; 미니-커널은 각 컨트롤러의 주소값을 매 프레임마다 한번씩 우선순위에 따라 정렬하거나 해당 리스트가 정렬된 상태를 유지함을 보장해야 한다.

The mini-kernel may be implemented to handle some common controller bookkeeping. For example, the kernel might update a counter in each controller so that the controller can determine its age quickly. Or, the kernel might monitor per controller sleep fields to simplify timing much like the sleep() function in Unix or Win32.

미니-커널은 일부 일반적인 컨트롤러의 동작을 직접 조정하도록 구현될 수도 있다. 예를 들면, 커널은 각 컨트롤러 내에서 카운터를 갱신할 수도 있어, 해당 컨트롤러는 스스로의 동작 시간을 빠르게 결정할 수 있다. 또는, unix나 win32에 있는 sleep() 함수와 매우 비슷하도록 타이밍 정보를 단순화시키기 위해 컨트롤러가 sleep 상태일 때마다 커널이 모니터링을 하도록 할 수도 있다.

Controllers are frequently 'attached' to Model objects though some sort of dependency system. This dependency ensures that the controller is garbage collected along with the associated model when it dies. This may involve some cooperation on the part of the mini-kernel.

컨트롤러 는 ,일부분 시스템에 의존적인 형태이긴 하지만, 종종 모델 객체에 '첨부'되곤 한다. 이러한 의존성은 컨트롤러가 관련 모델이 죽었을때 자동으로 쓰레기-처리 될수 있음을 보장해 준다. 이 특징은 미니-커널의 일부분에 협력 시스템 형태로 포함된다.

구조:

지금은 없음.

예:

지금은 없음.

고려사항 및 위험요소

없음

관련 패턴들

Mini-kernels are aggregations of Controllers.

미니 커널들은 컨트롤러 들의 집합체 이다.

용례 및 참고자료