Skip to content

Commit ba87969

Browse files
committed
Added global resource autoreload settings
1 parent 07b4f6c commit ba87969

File tree

9 files changed

+5124
-3
lines changed

9 files changed

+5124
-3
lines changed

Core/Contents/Include/PolyResource.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ namespace Polycode {
6161
static const int RESOURCE_SCREEN_ENTITY_INSTANCE = 8;
6262

6363
bool reloadOnFileModify;
64+
65+
static bool defaultReloadOnFileModify;
66+
6467
time_t resourceFileTime;
6568

6669
//@}

Core/Contents/Include/PolyResourceManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ namespace Polycode {
6363
int resourceSubscribers;
6464
bool deleteOnUnsubscribe;
6565

66+
static bool defaultReloadResourcesOnModify;
67+
6668
private:
6769

6870
ResourcePool *fallbackPool;

Core/Contents/Source/PolyResource.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626

2727
using namespace Polycode;
2828

29+
bool Resource::defaultReloadOnFileModify = false;
30+
2931
Resource::Resource(int type) : EventDispatcher() {
3032
this->type = type;
31-
reloadOnFileModify = false;
33+
reloadOnFileModify = defaultReloadOnFileModify;
3234
resourceFileTime = 0;
3335
}
3436

Core/Contents/Source/PolyResourceManager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@
3838
using std::vector;
3939
using namespace Polycode;
4040

41+
bool ResourcePool::defaultReloadResourcesOnModify = false;
42+
4143
ResourcePool::ResourcePool(const String &name, ResourcePool *fallbackPool) {
4244

4345
this->name = name;
4446
this->fallbackPool = fallbackPool;
4547
dispatchChangeEvents = false;
46-
reloadResourcesOnModify = false;
48+
reloadResourcesOnModify = ResourcePool::defaultReloadResourcesOnModify;
4749
ticksSinceCheck = 0;
4850
resourceSubscribers = 0;
4951
deleteOnUnsubscribe = false;

IDE/Contents/Source/PolycodeFrame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ void PolycodeFrame::showModal(UIWindow *modalChild) {
15131513
void PolycodeFrame::hideModal() {
15141514
if(modalChild) {
15151515
modalRoot->removeChild(modalChild);
1516-
modalChild->removeEventListener(this, UIEvent::CLOSE_EVENT);
1516+
modalChild->removeAllHandlers();
15171517
modalChild->hideWindow();
15181518
modalChild = NULL;
15191519
}

IDE/Contents/Source/PolycodeIDEApp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
4343

4444
Entity::defaultBlendingMode = Renderer::BLEND_MODE_NONE;
4545

46+
ResourcePool::defaultReloadResourcesOnModify = true;
47+
Resource::defaultReloadOnFileModify = true;
48+
4649
CoreServices::getInstance()->getResourceManager()->getGlobalPool()->reloadResourcesOnModify = true;
4750

51+
4852
runNextFrame = false;
4953

5054
core->addEventListener(this, Core::EVENT_CORE_RESIZE);

Tools/Dependencies/miniz/miniz.c

Lines changed: 4916 additions & 0 deletions
Large diffs are not rendered by default.

Tools/Dependencies/miniz/timer.cpp

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// File: timer.cpp - Simple high-precision timer class. Supports Win32, X360, and POSIX/Linux
2+
#include <stdlib.h>
3+
#include <stdio.h>
4+
#include <assert.h>
5+
#include <time.h>
6+
7+
#include "timer.h"
8+
9+
#if defined(WIN32)
10+
#include <windows.h>
11+
#elif defined(_XBOX)
12+
#include <xtl.h>
13+
#endif
14+
15+
unsigned long long timer::g_init_ticks;
16+
unsigned long long timer::g_freq;
17+
double timer::g_inv_freq;
18+
19+
#if defined(WIN32) || defined(_XBOX)
20+
inline void query_counter(timer_ticks *pTicks)
21+
{
22+
QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(pTicks));
23+
}
24+
inline void query_counter_frequency(timer_ticks *pTicks)
25+
{
26+
QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(pTicks));
27+
}
28+
#elif defined(__GNUC__)
29+
#include <sys/timex.h>
30+
inline void query_counter(timer_ticks *pTicks)
31+
{
32+
struct timeval cur_time;
33+
gettimeofday(&cur_time, NULL);
34+
*pTicks = static_cast<unsigned long long>(cur_time.tv_sec)*1000000ULL + static_cast<unsigned long long>(cur_time.tv_usec);
35+
}
36+
inline void query_counter_frequency(timer_ticks *pTicks)
37+
{
38+
*pTicks = 1000000;
39+
}
40+
#endif
41+
42+
timer::timer() :
43+
m_start_time(0),
44+
m_stop_time(0),
45+
m_started(false),
46+
m_stopped(false)
47+
{
48+
if (!g_inv_freq)
49+
init();
50+
}
51+
52+
timer::timer(timer_ticks start_ticks)
53+
{
54+
if (!g_inv_freq)
55+
init();
56+
57+
m_start_time = start_ticks;
58+
59+
m_started = true;
60+
m_stopped = false;
61+
}
62+
63+
void timer::start(timer_ticks start_ticks)
64+
{
65+
m_start_time = start_ticks;
66+
67+
m_started = true;
68+
m_stopped = false;
69+
}
70+
71+
void timer::start()
72+
{
73+
query_counter(&m_start_time);
74+
75+
m_started = true;
76+
m_stopped = false;
77+
}
78+
79+
void timer::stop()
80+
{
81+
assert(m_started);
82+
83+
query_counter(&m_stop_time);
84+
85+
m_stopped = true;
86+
}
87+
88+
double timer::get_elapsed_secs() const
89+
{
90+
assert(m_started);
91+
if (!m_started)
92+
return 0;
93+
94+
timer_ticks stop_time = m_stop_time;
95+
if (!m_stopped)
96+
query_counter(&stop_time);
97+
98+
timer_ticks delta = stop_time - m_start_time;
99+
return delta * g_inv_freq;
100+
}
101+
102+
timer_ticks timer::get_elapsed_us() const
103+
{
104+
assert(m_started);
105+
if (!m_started)
106+
return 0;
107+
108+
timer_ticks stop_time = m_stop_time;
109+
if (!m_stopped)
110+
query_counter(&stop_time);
111+
112+
timer_ticks delta = stop_time - m_start_time;
113+
return (delta * 1000000ULL + (g_freq >> 1U)) / g_freq;
114+
}
115+
116+
void timer::init()
117+
{
118+
if (!g_inv_freq)
119+
{
120+
query_counter_frequency(&g_freq);
121+
g_inv_freq = 1.0f / g_freq;
122+
123+
query_counter(&g_init_ticks);
124+
}
125+
}
126+
127+
timer_ticks timer::get_init_ticks()
128+
{
129+
if (!g_inv_freq)
130+
init();
131+
132+
return g_init_ticks;
133+
}
134+
135+
timer_ticks timer::get_ticks()
136+
{
137+
if (!g_inv_freq)
138+
init();
139+
140+
timer_ticks ticks;
141+
query_counter(&ticks);
142+
return ticks - g_init_ticks;
143+
}
144+
145+
double timer::ticks_to_secs(timer_ticks ticks)
146+
{
147+
if (!g_inv_freq)
148+
init();
149+
150+
return ticks * g_inv_freq;
151+
}
152+

Tools/Dependencies/miniz/timer.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// File: timer.h
2+
#pragma once
3+
4+
typedef unsigned long long timer_ticks;
5+
6+
class timer
7+
{
8+
public:
9+
timer();
10+
timer(timer_ticks start_ticks);
11+
12+
void start();
13+
void start(timer_ticks start_ticks);
14+
15+
void stop();
16+
17+
double get_elapsed_secs() const;
18+
inline double get_elapsed_ms() const { return get_elapsed_secs() * 1000.0f; }
19+
timer_ticks get_elapsed_us() const;
20+
21+
static void init();
22+
static inline timer_ticks get_ticks_per_sec() { return g_freq; }
23+
static timer_ticks get_init_ticks();
24+
static timer_ticks get_ticks();
25+
static double ticks_to_secs(timer_ticks ticks);
26+
static inline double ticks_to_ms(timer_ticks ticks) { return ticks_to_secs(ticks) * 1000.0f; }
27+
static inline double get_secs() { return ticks_to_secs(get_ticks()); }
28+
static inline double get_ms() { return ticks_to_ms(get_ticks()); }
29+
30+
private:
31+
static timer_ticks g_init_ticks;
32+
static timer_ticks g_freq;
33+
static double g_inv_freq;
34+
35+
timer_ticks m_start_time;
36+
timer_ticks m_stop_time;
37+
38+
bool m_started : 1;
39+
bool m_stopped : 1;
40+
};

0 commit comments

Comments
 (0)