GameLoop Template

From C3LearningLabs

Start - System Objects - Constructor - Finalize - Data Fields - UILayout - xmlCom - Server Client Configuration - GameLoop - TopPanelUI - ConfigGlobalData - Message - Manager

The GameLoop template contain the methods that is called by the main game loop process.
This is done to keep all activities in the system to be executed in one process.

Only one process do all the processes in the simulation.

Main Code

// ============================================================================================
// =                                        gameLoopDo                                        =
// ============================================================================================ 
   
/**
 * Performs all game loop steps done at server side.<br>
 * Do the following steps:
 * <ul>
 *   <li>
 *   <li>
 *   <li>
 * </ul>
 */
public void gameLoopDoServer() {
    // //LOG// systemData_Env.getTraceLog().finer("Begin");
    try {

    }
    catch (Exception e){
        e.printStackTrace();
    }
}

    
/**
 * Performs all game loop steps done at client side.<br>
 * Do the following steps:
 * <ul>
 *   <li>
 *   <li>
 *   <li>
 * </ul>
 */
public void gameLoopDoClient() {
    // //LOG// systemData_Env.getTraceLog().finer("Begin");
    try {

    }
    catch (Exception e){
        e.printStackTrace();
    }
}

External Code

Server

Update the method gameLoopDoSimulation() in c3systems.server.server.SessionMgr.java with the call to the game loop method.

SessionMgr.java

Example code

public void gameLoopDoSimulation() {
        ...
        if (mgrs.getSystemLoadMgr() != null){
            mgrs.getSystemLoadMgr().gameLoopDoServer();
        }
        ...

Server.java

Special game loop calls can also be done in the method run() in the c3systems.server.server.Server.java class.

Example code

public void run() {
    while(true){
        ...
        if (mgrs.getSystemLoadMgr() != null){
            mgrs.getSystemLoadMgr().gameLoopDoServer();
        }
        ...
    }
}

Client

Update the method gameLoopDo() in c3systems.client.ui2.UI2DMgr.java with the call to the game loop method.

UI2DMgr.java

Example code

public void gameLoopDo() {
        ...
        if (mgrs.getSystemLoadMgr() != null){
            mgrs.getSystemLoadMgr().gameLoopDoClient();
        }
        ...


Client.java

Special game loop calls can also be done in the method run() in the c3systems.client.client.client.Client.java class.

Example code

public void run() {
    while(true){
        ...
        if (mgrs.getSystemLoadMgr() != null){
            mgrs.getSystemLoadMgr().gameLoopDoClient();
        }
        ...
    }
}