package org.ntlab.radishforandroidstudio.framework.gameMain;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import org.ntlab.radishforandroidstudio.R;
import org.ntlab.radishforandroidstudio.cactusClient.models.CactusModels;
import org.ntlab.radishforandroidstudio.framework.RWT.RWTSurfaceView;
import org.ntlab.radishforandroidstudio.framework.model3D.Universe;
import org.ntlab.radishforandroidstudio.framework.view3D.Camera3D;

public class RealTime3DFragment extends RealTimeFragment{
    protected Universe universe;
    protected Camera3D camera;
    protected RWTSurfaceView view;
    protected View parentView = null;
    protected GameBaseModelManager modelManager = null;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        universe = new Universe();
        camera = new Camera3D(universe);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        parentView = inflater.inflate(R.layout.fragment_real_time_3d, container, false);
        // 画面との関連付け
        view = new RWTSurfaceView(this.getActivity());
        view.setRenderMode(RWTSurfaceView.RENDERMODE_WHEN_DIRTY);
        view.attachCamera(camera);
        FrameLayout l = parentView.findViewById(R.id.game_layout);
        l.addView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
        return parentView;
    }

    @Override
    protected void update(long interval) {
        progress(interval);
        if (modelManager != null) {
            modelManager.update(interval);
        }
        universe.update(interval);
        camera.adjust(interval);
        view.requestRender();
    }

    protected void progress(long interval) {
    }

    public Universe getUniverse() {
        return universe;
    }
}

