Annotation of nono/lib/object.cpp, revision 1.1.1.7

1.1       root        1: //
                      2: // nono
1.1.1.3   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
                      7: #include "object.h"
                      8: #include "logger.h"
                      9: #include "mpu.h"
                     10: #include "textscreen.h"
                     11: 
                     12: // 全オブジェクトのリスト
                     13: std::vector<Object*> gObjects;
                     14: 
1.1.1.7 ! root       15: //
        !            16: // オブジェクトクラス
        !            17: //
        !            18: 
1.1       root       19: // コンストラクタ
1.1.1.7 ! root       20: Object::Object(const std::string& objname_)
1.1       root       21: {
1.1.1.7 ! root       22:        // オブジェクト名(ログ表示名)を設定。
        !            23:        objname = objname_;
        !            24: 
        !            25:        // コンストラクタで指定した場合はエイリアスにも登録しておく。
        !            26:        AddAlias(objname_);
1.1       root       27: 
                     28:        // 自分自身をリストに繋ぐ
                     29:        gObjects.push_back(this);
                     30: }
                     31: 
                     32: // デストラクタ
                     33: Object::~Object()
                     34: {
1.1.1.7 ! root       35:        // 自分自身をリストから削除する
        !            36:        // XXX マルチスレッドな状況からは呼ばれないはず?
        !            37:        for (auto it = gObjects.begin(); it != gObjects.end(); ++it) {
        !            38:                if (*it == this) {
        !            39:                        gObjects.erase(it);
        !            40:                        break;
        !            41:                }
        !            42:        }
1.1       root       43: }
                     44: 
                     45: // メッセージ表示
                     46: // 常に表示 (あらかじめ loglevel の評価をした後で呼び出す用)
                     47: void
1.1.1.6   root       48: Object::putmsgn(const char *fmt, ...) const
1.1       root       49: {
1.1.1.2   root       50:        char buf[1024];
1.1       root       51:        int len;
1.1.1.6   root       52:        va_list ap;
1.1       root       53: 
1.1.1.7 ! root       54:        // 名前だけ生表示されても分かりづらいので括弧でもつけておく
        !            55:        len = snprintf(buf, sizeof(buf), "(%s) ", GetName().c_str());
1.1.1.6   root       56:        va_start(ap, fmt);
1.1.1.2   root       57:        vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
1.1.1.6   root       58:        va_end(ap);
                     59: 
1.1.1.3   root       60:        gLogger.Write(buf);
1.1       root       61: }
                     62: 
                     63: // ログ出力 (可変引数)
                     64: // 常に表示 (あらかじめ loglevel の評価をした後で呼び出す用)
                     65: void
1.1.1.6   root       66: Object::putlogn(const char *fmt, ...) const
1.1       root       67: {
1.1.1.2   root       68:        char buf[1024];
1.1.1.6   root       69:        va_list ap;
1.1       root       70:        uint64 vt;
                     71:        int len = 0;
                     72: 
1.1.1.5   root       73:        vt = gMPU->GetVirtTime();
1.1.1.2   root       74:        len += snprintf(buf + len, sizeof(buf) - len, "%4d.%03d'%03d'%03d ",
1.1       root       75:                (int)(vt / 1000 / 1000 / 1000),
                     76:                (int)((vt / 1000 / 1000) % 1000),
                     77:                (int)((vt / 1000) % 1000),
                     78:                (int)(vt % 1000));
                     79: 
1.1.1.2   root       80:        len += snprintf(buf + len, sizeof(buf) - len, "%08x %s ",
1.1.1.7 ! root       81:                gMPU->GetPPC(), GetName().c_str());
1.1.1.6   root       82: 
                     83:        va_start(ap, fmt);
1.1.1.2   root       84:        vsnprintf(buf + len, sizeof(buf) - len, fmt, ap);
1.1.1.6   root       85:        va_end(ap);
1.1       root       86: 
1.1.1.3   root       87:        gLogger.Write(buf);
1.1       root       88: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.