Ejemplo n.º 1
0
    def update(self):

        if not self.paused:
            newtick = pf.prev_frame_ms()
            newstats = pf.prev_frame_perfstats()
            if newtick > self.max_frame_latency:
                self.max_frame_latency = newtick

            self.ticksum_ms -= self.frame_times_ms[self.tickindex]
            self.ticksum_ms += newtick
            self.frame_times_ms[self.tickindex] = newtick
            self.frame_perfstats[self.tickindex] = newstats
            self.selected_perfstats = newstats
            self.tickindex = (self.tickindex + 1) % len(self.frame_times_ms)

        self.layout_row_dynamic(100, 1)
        self.simple_chart(pf.NK_CHART_LINES, (0, 200), self.frame_times_ms,
                          self.on_chart_click)

        self.layout_row_dynamic(20, 1)
        avg_frame_latency_ms = float(self.ticksum_ms) / len(
            self.frame_times_ms)

        try:
            fps = 1000 / avg_frame_latency_ms
            self.label_colored_wrap("FPS: {0}".format(int(fps)), (255, 255, 0))
        except:
            pass

        self.layout_row_dynamic(20, 2)
        self.label_colored_wrap(
            "Avg. Frame Latency: {0:.1f} ms".format(avg_frame_latency_ms),
            (255, 255, 0))

        self.layout_row_dynamic(20, 1)
        self.label_colored_wrap(
            "Max Frame Latency: {0} ms".format(self.max_frame_latency),
            (255, 255, 0))

        self.layout_row_dynamic(20, 1)
        old_trace_python = self.trace_python
        self.trace_python = True if self.checkbox("Trace Python",
                                                  self.trace_python) else False
        if old_trace_python != self.trace_python:
            pf.settings_set("pf.debug.trace_python", self.trace_python)

        def on_pause_resume():
            self.paused = not self.paused

        text = lambda p: "Resume " if p else "Pause"
        self.layout_row_dynamic(30, 1)
        self.button_label(text(self.paused), on_pause_resume)

        self.tree(pf.NK_TREE_TAB, "Frame Performance", pf.NK_MINIMIZED,
                  self.frame_perf_tab)
        self.tree(pf.NK_TREE_TAB, "Renderer Info", pf.NK_MINIMIZED,
                  self.render_info_tab)
        self.tree(pf.NK_TREE_TAB, "Navigation Stats", pf.NK_MINIMIZED,
                  self.nav_stats_tab)
Ejemplo n.º 2
0
 def __on_settings_apply(self, event):
     if self.view.hb_idx != self.__og_hb_idx:
         try:
             pf.settings_set("pf.game.healthbar_mode", bool(self.view.hb_idx == 0))
             self.__og_hb_idx = self.view.hb_idx
         except Exception as e:
             print("Could not set pf.game.healthbar_mode:" + str(e))
     self.__update_dirty_flag()
Ejemplo n.º 3
0
def setup_scene():

    pf.set_ambient_light_color((1.0, 1.0, 1.0))
    pf.set_emit_light_color((1.0, 1.0, 1.0))
    pf.set_emit_light_pos((1664.0, 1024.0, 384.0))

    pf.settings_set("pf.game.fog_of_war_enabled", False, persist=False)

    pf.new_game("assets/maps", "plain.pfmap")

    pf.add_faction("RED", (255, 0, 0, 255))
    pf.add_faction("BLUE", (0, 0, 255, 255))

    pf.set_diplomacy_state(0, 1, pf.DIPLOMACY_STATE_WAR)

    pf.set_faction_controllable(0, False)
    pf.set_faction_controllable(1, False)
Ejemplo n.º 4
0
    def __on_settings_apply(self, event):
        if self.view.ar_idx != self.__og_ar_idx:
            try:
                pf.settings_set("pf.video.aspect_ratio", self.view.ar_opts[self.view.ar_idx])
                self.__og_ar_idx = self.view.ar_idx
            except Exception as e:
                print("Could not set pf.video.aspect_ratio:" + str(e))

        if self.view.res_idx != self.__og_res_idx:
            try:
                pf.settings_set("pf.video.resolution", self.view.res_opts[self.view.res_idx])
                self.__og_res_idx = self.view.res_idx
            except Exception as e:
                print("Could not set pf.video.resolution:" + str(e))

        if self.view.mode_idx != self.__og_mode_idx:
            try:
                pf.settings_set("pf.video.display_mode", self.view.mode_opts[self.view.mode_idx])
                self.__og_mode_idx = self.view.mode_idx
            except Exception as e:
                print("Could not set pf.video.display_mode:" + str(e))

        if self.view.win_on_top_idx != self.__og_win_on_top_idx:
            try:
                pf.settings_set("pf.video.window_always_on_top", self.view.win_on_top_opts[self.view.win_on_top_idx])
                self.__og_win_on_top_idx = self.view.win_on_top_idx
            except Exception as e:
                print("Could not set pf.video.window_always_on_top:" + str(e))

        if self.view.vsync_idx != self.__og_vsync_idx:
            try:
                pf.settings_set("pf.video.vsync", self.view.vsync_opts[self.view.vsync_idx])
                self.__og_vsync_idx = self.view.vsync_idx
            except Exception as e:
                print("Could not set pf.video.vsync:" + str(e))

        if self.view.shadows_idx != self.__og_shadows_idx:
            try:
                pf.settings_set("pf.video.shadows_enabled", self.view.shadows_opts[self.view.shadows_idx])
                self.__og_shadows_idx = self.view.shadows_idx
            except Exception as e:
                print("Could not set pf.video.shadows_enabled:" + str(e))

        if self.view.water_reflect_idx != self.__og_water_reflect_idx:
            try:
                pf.settings_set("pf.video.water_reflection", self.view.water_reflect_opts[self.view.water_reflect_idx])
                self.__og_water_reflect_idx = self.view.water_reflect_idx
            except Exception as e:
                print("Could not set pf.video.water_reflect_enabled:" + str(e))

        self.__update_res_opts()
        self.__load_selection()
        self.__update_dirty_flag()
Ejemplo n.º 5
0
import views.menu_window as mw

############################################################
# Global settings                                          #
############################################################

pf.set_ambient_light_color((1.0, 1.0, 1.0))
pf.set_emit_light_color((1.0, 1.0, 1.0))
pf.set_emit_light_pos((1664.0, 1024.0, 384.0))

pf.new_game_string(globals.active_map.pfmap_str(), update_navgrid=False)
minimap_pos = pf.get_minimap_position()
pf.set_minimap_position(UI_LEFT_PANE_WIDTH + minimap_pos[0], minimap_pos[1])

pf.disable_unit_selection()
pf.settings_set("pf.game.fog_of_war_enabled", False, persist=False)

pf.add_faction(DEFAULT_FACTION_NAME, DEFAULT_FACTION_COLOR)
mouse_events.install()

############################################################
# Setup UI                                                 #
############################################################

terrain_tab_vc = ttvc.TerrainTabVC(ttw.TerrainTabWindow())
objects_tab_vc = otvc.ObjectsVC(otw.ObjectsTabWindow())
diplo_tab_vc = dtvc.DiplomacyVC(dtw.DiplomacyTabWindow())

tab_bar_vc = tbvc.TabBarVC(tbw.TabBarWindow(), EVENT_TOP_TAB_SELECTION_CHANGED)
tab_bar_vc.push_child("Terrain", terrain_tab_vc)
tab_bar_vc.push_child("Objects", objects_tab_vc)