Skip to content

Commit

Permalink
fix misaligned doubles bug in bind node
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmaclarty committed Feb 23, 2016
1 parent 07ba980 commit 93cde35
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 35 deletions.
56 changes: 36 additions & 20 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,15 @@
<li><a href="#touches_began">window:touches_began()</a></li>
<li><a href="#windowtouches_ended">window:touches_ended()</a></li>
<li><a href="#windowactive_touches">window:active_touches()</a></li>
<li><a href="#windowtouch_begantouch">window:touch_began(touch)</a></li>
<li><a href="#windowtouch_endedtouch">window:touch_ended(touch)</a></li>
<li><a href="#windowtouch_positiontouch">window:touch_position(touch)</a></li>
<li><a href="#windowtouch_norm_positiontouch">window:touch_norm_position(touch)</a></li>
<li><a href="#windowtouch_pixel_positiontouch">window:touch_pixel_position(touch)</a></li>
<li><a href="#windowtouch_deltatouch">window:touch_delta(touch)</a></li>
<li><a href="#windowtouch_norm_deltatouch">window:touch_norm_delta(touch)</a></li>
<li><a href="#windowtouch_pixel_deltatouch">window:touch_pixel_delta(touch)</a></li>
<li><a href="#windowtouch_begantouch">window:touch_began([touch])</a></li>
<li><a href="#windowtouch_endedtouch">window:touch_ended([touch])</a></li>
<li><a href="#window:touch_active">window:touch_active([touch])</a></li>
<li><a href="#windowtouch_positiontouch">window:touch_position([touch])</a></li>
<li><a href="#windowtouch_norm_positiontouch">window:touch_norm_position([touch])</a></li>
<li><a href="#windowtouch_pixel_positiontouch">window:touch_pixel_position([touch])</a></li>
<li><a href="#windowtouch_deltatouch">window:touch_delta([touch])</a></li>
<li><a href="#windowtouch_norm_deltatouch">window:touch_norm_delta([touch])</a></li>
<li><a href="#windowtouch_pixel_deltatouch">window:touch_pixel_delta([touch])</a></li>
</ul></li>
</ul></li>
<li><a href="#scenes">Scenes</a><ul>
Expand Down Expand Up @@ -690,6 +691,7 @@ <h2 id="actions">Actions</h2>
<div class="sourceCode"><pre class="sourceCode lua"><code class="sourceCode lua">scene<span class="st">&quot;rotate&quot;</span><span class="ot">.</span>angle <span class="ot">=</span> am<span class="ot">.</span>frame_time <span class="ot">*</span> <span class="dv">4</span></code></pre></div>
<p>first finds a node with the <em>tag</em> <code>&quot;rotate&quot;</code> in the scene graph. By default nodes have tags that correspond to their names, so this returns the rotate node. You can also add your own tags to nodes using the <code>tag</code> method which we'll discuss in more detail in the next section.</p>
<p>Then we set the <code>angle</code> property of the rotate node to the current frame time (the time at the beginning of the frame, in seconds) times 4.</p>
<p>Note that <code>scene&quot;rotate&quot;</code> could also be written as <code>scene(&quot;rotate&quot;)</code>. The first form takes advantage of some Lua syntactic sugar that allows function parenthesis to be omitted if the argument is a single literal string.</p>
<p>Since this code is run each frame, it causes the text to spin.</p>
<p>Here is the complete code listing:</p>
<div class="sourceCode"><pre class="sourceCode lua"><code class="sourceCode lua"><span class="kw">local</span> win <span class="ot">=</span> am<span class="ot">.</span>window<span class="ot">{</span>
Expand Down Expand Up @@ -1023,7 +1025,6 @@ <h1 id="math">Math</h1>
<h2 id="vectors">Vectors</h2>
<p>Amulet has built-in support for 2, 3 or 4 dimensional vectors. Vectors are typically used to represent things like position, direction or velocity in 2 or 3 dimensional space. Representing RGBA colors is another common use of 4 dimensional vectors.</p>
<p>In Amulet vectors are immutable. This means that once you create a vector, its value cannot be changed. Instead you need to construct a new vector.</p>
<p><strong>Note</strong>: Each component of a vector is represented internally as a 32 bit float, so expect some loss of precision when converting between vector components and Lua numbers, which are 64 bits.</p>
<h3 id="constructing-vectors">Constructing vectors</h3>
<p>To construct a vector use one of the functions <code>vec2</code>, <code>vec3</code> or <code>vec4</code>. A vector may be constructed by passing its components as separate arguments to one of these functions, for example:</p>
<div class="sourceCode"><pre class="sourceCode lua"><code class="sourceCode lua"><span class="kw">local</span> velocity <span class="ot">=</span> vec3<span class="ot">(</span><span class="dv">1</span><span class="ot">,</span> <span class="dv">2</span><span class="ot">,</span> <span class="dv">3</span><span class="ot">)</span></code></pre></div>
Expand Down Expand Up @@ -1085,7 +1086,7 @@ <h3 id="vector-arithmetic">Vector arithmetic</h3>
</div>
<h2 id="matrices">Matrices</h2>
<p>Amulet has built-in support for 2x2, 3x3 and 4x4 matrices. Matrices are typically used to represent transformations in 2 or 3 dimensional space such as rotation, scaling, translation or perspective projection.</p>
<p>Matrices, like vectors, are immutable and their components are represented internally as 32 bit floats.</p>
<p>Matrices, like vectors, are immutable.</p>
<h3 id="constructing-matrices">Constructing matrices</h3>
<p>Use one of the functions <code>mat2</code>, <code>mat3</code> or <code>mat4</code> to construct a 2x2, 3x3 or 4x4 matrix.</p>
<p>Passing a single number argument to one of the matrix constructors generates a matrix with all diagonal elements equal to the number and all other elements equal to zero. For example <code>mat3(1)</code> constructs the 3x3 identity matrix:</p>
Expand Down Expand Up @@ -1695,31 +1696,45 @@ <h3 id="touches_began" class="method-def">window:touches_began()</h3>
<p>If there are no other active touches then the next touch will always be 1, so if your interface only expects a single touch at a time, you can just use 1 for all touch functions that take a touch argument and any additional touches will be ignored.</p>
<h3 id="windowtouches_ended" class="method-def">window:touches_ended()</h3>
<p>Returns an array of the touches that ended since the last frame.</p>
<p>See <a href="#touches_began"><code>window:touches_began</code></a> for more info about the returned touches.</p>
<h3 id="windowactive_touches" class="method-def">window:active_touches()</h3>
<p>Returns an array of the currently active touches.</p>
<h3 id="windowtouch_begantouch" class="method-def">window:touch_began(touch)</h3>
<p>See <a href="#touches_began"><code>window:touches_began</code></a> for more info about the returned touches.</p>
<h3 id="windowtouch_begantouch" class="method-def">window:touch_began([touch])</h3>
<p>Returns true if the specific touch began since the last frame.</p>
<p>The default value for <code>touch</code> is <code>1</code>.</p>
<p>See <a href="#touches_began"><code>window:touches_began</code></a> for additional notes on the <code>touch</code> argument.</p>
<h3 id="windowtouch_endedtouch" class="method-def">window:touch_ended(touch)</h3>
<h3 id="windowtouch_endedtouch" class="method-def">window:touch_ended([touch])</h3>
<p>Returns true if the specific touch ended since the last frame.</p>
<p>The default value for <code>touch</code> is <code>1</code>.</p>
<p>See <a href="#touches_began"><code>window:touches_began</code></a> for additional notes on the <code>touch</code> argument.</p>
<h3 id="windowtouch_positiontouch" class="method-def">window:touch_position(touch)</h3>
<h3 id="window:touch_active" class="method-def">window:touch_active([touch])</h3>
<p>Returns true if the specific touch is active.</p>
<p>The default value for <code>touch</code> is <code>1</code>.</p>
<p>See <a href="#touches_began"><code>window:touches_began</code></a> for additional notes on the <code>touch</code> argument.</p>
<h3 id="windowtouch_positiontouch" class="method-def">window:touch_position([touch])</h3>
<p>Returns the last touch position in the window's coordinate system (a <code>vec2</code>).</p>
<p>The default value for <code>touch</code> is <code>1</code>.</p>
<p>See <a href="#touches_began"><code>window:touches_began</code></a> for additional notes on the <code>touch</code> argument.</p>
<h3 id="windowtouch_norm_positiontouch" class="method-def">window:touch_norm_position(touch)</h3>
<h3 id="windowtouch_norm_positiontouch" class="method-def">window:touch_norm_position([touch])</h3>
<p>Returns the last touch position in normalized device coordinates (a <code>vec2</code>).</p>
<p>The default value for <code>touch</code> is <code>1</code>.</p>
<p>See <a href="#touches_began"><code>window:touches_began</code></a> for additional notes on the <code>touch</code> argument.</p>
<h3 id="windowtouch_pixel_positiontouch" class="method-def">window:touch_pixel_position(touch)</h3>
<h3 id="windowtouch_pixel_positiontouch" class="method-def">window:touch_pixel_position([touch])</h3>
<p>Returns the last touch position in pixels, where the bottom left corner of the window is (0, 0) (a <code>vec2</code>).</p>
<p>The default value for <code>touch</code> is <code>1</code>.</p>
<p>See <a href="#touches_began"><code>window:touches_began</code></a> for additional notes on the <code>touch</code> argument.</p>
<h3 id="windowtouch_deltatouch" class="method-def">window:touch_delta(touch)</h3>
<h3 id="windowtouch_deltatouch" class="method-def">window:touch_delta([touch])</h3>
<p>Returns the change in touch position since the last frame in the window's coordinate system (a <code>vec2</code>).</p>
<p>The default value for <code>touch</code> is <code>1</code>.</p>
<p>See <a href="#touches_began"><code>window:touches_began</code></a> for additional notes on the <code>touch</code> argument.</p>
<h3 id="windowtouch_norm_deltatouch" class="method-def">window:touch_norm_delta(touch)</h3>
<h3 id="windowtouch_norm_deltatouch" class="method-def">window:touch_norm_delta([touch])</h3>
<p>Returns the change in touch position since the last frame in normalized device coordinates (a <code>vec2</code>).</p>
<p>The default value for <code>touch</code> is <code>1</code>.</p>
<p>See <a href="#touches_began"><code>window:touches_began</code></a> for additional notes on the <code>touch</code> argument.</p>
<h3 id="windowtouch_pixel_deltatouch" class="method-def">window:touch_pixel_delta(touch)</h3>
<h3 id="windowtouch_pixel_deltatouch" class="method-def">window:touch_pixel_delta([touch])</h3>
<p>Returns the change in touch position since the last frame in pixels (a <code>vec2</code>).</p>
<p>The default value for <code>touch</code> is <code>1</code>.</p>
<p>See <a href="#touches_began"><code>window:touches_began</code></a> for additional notes on the <code>touch</code> argument.</p>
<div class="figure">
<img src="images/screenshot8.jpg" alt="" />
Expand Down Expand Up @@ -2952,8 +2967,9 @@ <h3 id="noglobals" class="func-def">noglobals()</h3>
<h1 id="globbing">Globbing</h1>
<h3 id="am.glob" class="func-def">am.glob(patterns)</h3>
<p>Returns an array (table) of file names matching the given glob pattern(s). <code>patterns</code> should be a table of glob pattern strings. A glob pattern is a file path with zero or more wildcard (<code>*</code>) characters.</p>
<p>Any matching files that are directories will have a slash (<code>/</code>) appended to their names (even on Windows).</p>
<p>The slash character (<code>/</code>) can be used as a directory separator on Windows. You don't need to use backslash (<code>\</code>).</p>
<p>Any matching files that are directories will have a slash (<code>/</code>) appended to their names, even on Windows.</p>
<p>The slash character (<code>/</code>) can be used as a directory separator on Windows (you don't need to use <code>\</code>). Furthermore returned paths will always have '/' as the directory separator, even on Windows.</p>
<p><strong>Note:</strong> This function only searches for files on the file system. It won't search the resource archive in a exported game. Its intended use is for writing file processing utilities and not for use directly in games you wish to distribute.</p>
<p>Example:</p>
<div class="sourceCode"><pre class="sourceCode lua"><code class="sourceCode lua"><span class="kw">local</span> image_files <span class="ot">=</span> am<span class="ot">.</span>glob<span class="ot">{</span><span class="st">&quot;images/*.png&quot;</span><span class="ot">,</span> <span class="st">&quot;images/*.jpg&quot;</span><span class="ot">}</span></code></pre></div>
<h1 id="running-javascript">Running JavaScript</h1>
Expand Down
1 change: 1 addition & 0 deletions src/am_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ bool am_conf_check_gl_errors = false;

bool am_conf_dump_translated_shaders = false;
bool am_conf_log_gl_calls = false;
int am_conf_log_gl_frames = 1;

bool am_conf_allow_restart = false;

Expand Down
1 change: 1 addition & 0 deletions src/am_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern bool am_conf_validate_shader_programs;
extern bool am_conf_check_gl_errors;
extern bool am_conf_dump_translated_shaders;
extern bool am_conf_log_gl_calls;
extern int am_conf_log_gl_frames;
extern bool am_conf_allow_restart;

bool am_load_config();
4 changes: 2 additions & 2 deletions src/am_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@

#define check_for_errors { if (am_conf_check_gl_errors) check_glerror(__FILE__, __LINE__, __func__); }

#define log_gl(fmt, ...) {if (am_conf_log_gl_calls) {fprintf(stderr, fmt "\n", __VA_ARGS__);}}
#define log_gl_ptr(ptr, len) {if (am_conf_log_gl_calls) {print_ptr((void*)ptr, len);}}
#define log_gl(fmt, ...) {if (am_conf_log_gl_calls && am_conf_log_gl_frames > 0) {fprintf(stderr, fmt "\n", __VA_ARGS__);}}
#define log_gl_ptr(ptr, len) {if (am_conf_log_gl_calls && am_conf_log_gl_frames > 0) {print_ptr((void*)ptr, len);}}

static void print_ptr(void* p, int len);

Expand Down
24 changes: 12 additions & 12 deletions src/am_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,21 +611,21 @@ static void set_param_value(lua_State *L, am_program_param_value *param, int val

static am_bind_node *new_bind_node(lua_State *L, int num_params) {
// allocate extra space for the shader paramter names, values and refs
size_t node_sz = sizeof(am_bind_node);
am_align_size(node_sz);
size_t names_sz = sizeof(am_param_name_id) * num_params;
am_align_size(names_sz);
size_t values_sz = sizeof(am_program_param_value) * num_params;
am_align_size(values_sz);
size_t refs_sz = sizeof(int) * num_params;
am_align_size(refs_sz);
am_bind_node *node = (am_bind_node*)am_set_metatable(L,
new (lua_newuserdata(L,
sizeof(am_bind_node)
+ sizeof(am_param_name_id) * num_params
+ sizeof(am_program_param_value) * num_params
+ sizeof(int) * num_params
))
new (lua_newuserdata(L, node_sz + names_sz + values_sz + refs_sz))
am_bind_node(), MT_am_bind_node);
node->num_params = num_params;
node->names = (am_param_name_id*)(((uint8_t*)node) + sizeof(am_bind_node));
node->values = (am_program_param_value*)(((uint8_t*)node) + sizeof(am_bind_node)
+ sizeof(am_param_name_id) * num_params);
node->refs = (int*)(((uint8_t*)node) + sizeof(am_bind_node)
+ sizeof(am_param_name_id) * num_params
+ sizeof(am_program_param_value) * num_params);
node->names = (am_param_name_id*)(((uint8_t*)node) + node_sz);
node->values = (am_program_param_value*)(((uint8_t*)node) + node_sz + names_sz);
node->refs = (int*)(((uint8_t*)node) + node_sz + names_sz + values_sz);
return node;
}

Expand Down
3 changes: 2 additions & 1 deletion src/am_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,10 @@ bool am_update_windows(lua_State *L) {
resize_windows();
draw_windows();
frame++;
if (am_conf_log_gl_calls) {
if (am_conf_log_gl_calls && am_conf_log_gl_frames > 0) {
fprintf(stderr, "SDL_GL_SwapWindow(win);\n\n // ===================== END FRAME %d ==========================\n\n", frame);
}
if (am_conf_log_gl_frames > 0) am_conf_log_gl_frames--;
return windows.size() > 0;
}

Expand Down

0 comments on commit 93cde35

Please sign in to comment.