This commit is contained in:
Allen Webster 2017-10-31 12:52:52 -04:00
commit bf6db5bf49
18 changed files with 553 additions and 224 deletions

View File

@ -89,11 +89,13 @@ inline i32 div_ceil(i32 n, i32 d){
}
inline i32 l_round_up_i32(i32 x, i32 b){
return( ((x)+(b)-1) - (((x)+(b)-1)%(b)) );
i32 t = x + b - 1;
return(t - (t%b));
}
inline u32 l_round_up_u32(u32 x, u32 b){
return( ((x)+(b)-1) - (((x)+(b)-1)%(b)) );
i32 t = x + b - 1;
return(t - (t%b));
}
inline u32 round_up_pot_u32(u32 x){

View File

@ -923,22 +923,30 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_
result.position_start = i;
Cpp_Token token = {0};
token.start = state->size;
if (state->token_ptr < state->end_token){
token = *state->token_ptr;
}
if (state->consume_newline){
++i;
state->x = 0;
state->consume_newline = 0;
}
if (state->in_pp_body){
if (!(state->token_ptr->flags & CPP_TFLAG_PP_BODY)){
state->in_pp_body = 0;
if (!(token.flags & CPP_TFLAG_PP_BODY)){
state->in_pp_body = false;
state->wrap_x = state->plane_wrap_x;
}
}
if (!state->in_pp_body){
if (state->token_ptr->flags & CPP_TFLAG_PP_DIRECTIVE){
state->in_pp_body = 1;
if (token.flags & CPP_TFLAG_PP_DIRECTIVE){
state->in_pp_body = true;
state->plane_wrap_x = state->wrap_x;
state->wrap_x = null_wrap_x;
}
@ -967,8 +975,7 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_
i32 line_start = state->line_starts[state->line_index];
b32 still_looping = 0;
i32 end = state->token_ptr->start + state->token_ptr->size;
i32 end = token.start + token.size;
if (fixed_end_point >= 0 && end > fixed_end_point){
end = fixed_end_point;
}
@ -1015,7 +1022,7 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_
if (!skipping_whitespace){
if (!recorded_start_x){
result.start_x = state->x;
recorded_start_x = 1;
recorded_start_x = true;
}
state->x += adv;
}
@ -1028,13 +1035,14 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_
state->i = i;
b32 consume_token = 0;
if (state->token_ptr < state->end_token && i >= state->token_ptr->start + state->token_ptr->size){
consume_token = 1;
b32 consume_token = false;
if (state->token_ptr < state->end_token && i >= token.start + token.size){
consume_token = true;
}
result.this_token = state->token_ptr;
if (consume_token){
Assert(state->token_ptr < state->end_token);
switch (state->token_ptr->type){
case CPP_TOKEN_BRACE_OPEN:
{
@ -1088,7 +1096,7 @@ wrap_state_consume_token(System_Functions *system, Render_Font *font, Code_Wrap_
if (!recorded_start_x){
result.start_x = state->x;
recorded_start_x = 1;
recorded_start_x = true;
}
return(result);
@ -1262,6 +1270,11 @@ get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start){
result.shift = wrap_state->wrap_x.paren_nesting[wrap_state->wrap_x.paren_safe_top];
Cpp_Token next_token = {0};
if (wrap_state->token_ptr < wrap_state->end_token){
next_token = *wrap_state->token_ptr;
}
if (wrap_state->token_ptr > wrap_state->token_array.tokens){
Cpp_Token prev_token = *(wrap_state->token_ptr-1);
@ -1286,18 +1299,18 @@ get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start){
}
}
switch (wrap_state->token_ptr->type){
switch (next_token.type){
case CPP_TOKEN_BRACE_CLOSE: case CPP_TOKEN_BRACE_OPEN: break;
default: result.shift += statement_continuation_indent; break;
}
}
if (wrap_state->token_ptr->start < next_line_start){
if (wrap_state->token_ptr->flags & CPP_TFLAG_PP_DIRECTIVE){
if (next_token.start < next_line_start){
if (next_token.flags & CPP_TFLAG_PP_DIRECTIVE){
result.shift = 0;
}
else{
switch (wrap_state->token_ptr->type){
switch (next_token.type){
case CPP_TOKEN_BRACE_CLOSE:
{
if (wrap_state->wrap_x.paren_safe_top == 0){
@ -1496,8 +1509,8 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
for (; wrap_state.token_ptr < wrap_state.end_token; ){
Code_Wrap_Step step = {0};
b32 emit_comment_position = 0;
b32 first_word = 1;
b32 emit_comment_position = false;
b32 first_word = true;
if (wrap_state.token_ptr->type == CPP_TOKEN_COMMENT || wrap_state.token_ptr->type == CPP_TOKEN_STRING_CONSTANT){
i32 i = wrap_state.token_ptr->start;
@ -1626,29 +1639,39 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
step = wrap_state_consume_token(system, font, &wrap_state, next_line_start);
}
b32 need_to_choose_a_wrap = 0;
b32 need_to_choose_a_wrap = false;
if (step.final_x > current_width){
need_to_choose_a_wrap = 1;
need_to_choose_a_wrap = true;
}
current_shift = get_current_shift(&wrap_state, next_line_start);
b32 next_token_is_on_line = 0;
b32 next_token_is_on_line = false;
if (wrap_state.token_ptr < wrap_state.end_token){
if (wrap_state.token_ptr->start < next_line_start){
next_token_is_on_line = 1;
next_token_is_on_line = true;
}
}
i32 next_wrap_position = step.position_end;
f32 wrap_x = step.final_x;
if (wrap_state.token_ptr->start > step.position_start && next_wrap_position < wrap_state.token_ptr->start && next_token_is_on_line){
next_wrap_position = wrap_state.token_ptr->start;
if (next_token_is_on_line){
if (wrap_state.token_ptr < wrap_state.end_token){
i32 pos_i = wrap_state.token_ptr->start;
if (pos_i > step.position_start && next_wrap_position < pos_i){
next_wrap_position = pos_i;
}
}
}
if (!need_to_choose_a_wrap){
i32 wrappable_score = 1;
Cpp_Token *this_token = step.this_token;
Cpp_Token *next_token = wrap_state.token_ptr;
Cpp_Token *next_token = 0;
if (wrap_state.token_ptr < wrap_state.end_token){
next_token = wrap_state.token_ptr;
}
Cpp_Token_Type this_type = this_token->type;
Cpp_Token_Type next_type = CPP_TOKEN_JUNK;

View File

@ -491,18 +491,26 @@ do_buildsuper(char *cdir, char *file, u32 arch){
END_TIME_SECTION("build custom");
}
// TODO(allen): Remove this
internal i32
get_freetype_include(char *out, u32 max){
i32 size = 0;
#if 0
#if defined(IS_LINUX)
char freetype_include[512];
FILE *file = popen("pkg-config --cflags freetype2", "r");
if (file != 0){
fgets(freetype_include, sizeof(freetype_include), file);
size = strlen(freetype_include);
freetype_include[size-1] = 0;
memcpy(out, freetype_include, size);
pclose(file);
}
#elif defined(IS_MAC)
char *freetype_include = "/usr/local/include/freetype2";
size = strlen(freetype_include);
memcpy(out, freetype_include, size
);
#endif
#endif
return(size);
}
@ -521,6 +529,7 @@ build_main(char *cdir, b32 update_local_theme, u32 flags, u32 arch){
i32 ft_size = get_freetype_include(ft_include, sizeof(ft_include) - 1);
if (ft_size > 0){
ft_include[ft_size] = 0;
fprintf(stdout, "FREETYPE: %s\n", ft_include);
build_includes = fm_list(build_includes, fm_list_one_item(ft_include));
}

View File

@ -0,0 +1,76 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 10.09.2017
*
* Mac C++ layer for 4coder
*
*/
// TOP
#if !defined(FRED_COROUTINE_FUNCTIONS_CPP)
#define FRED_COROUTINE_FUNCTIONS_CPP
//
// Coroutine
//
internal
Sys_Create_Coroutine_Sig(system_create_coroutine){
Coroutine *coroutine = coroutine_system_alloc(&coroutines);
Coroutine_Head *result = 0;
if (coroutine != 0){
coroutine_set_function(coroutine, func);
result = &coroutine->head;
}
return(result);
}
internal
Sys_Launch_Coroutine_Sig(system_launch_coroutine){
Coroutine *coroutine = (Coroutine*)head;
coroutine->head.in = in;
coroutine->head.out = out;
Coroutine *active = coroutine->sys->active;
Assert(active != 0);
coroutine_launch(active, coroutine);
Assert(active == coroutine->sys->active);
Coroutine_Head *result = &coroutine->head;
if (coroutine->state == CoroutineState_Dead){
coroutine_system_free(&coroutines, coroutine);
result = 0;
}
return(result);
}
Sys_Resume_Coroutine_Sig(system_resume_coroutine){
Coroutine *coroutine = (Coroutine*)head;
coroutine->head.in = in;
coroutine->head.out = out;
Coroutine *active = coroutine->sys->active;
Assert(active != 0);
coroutine_resume(active, coroutine);
Assert(active == coroutine->sys->active);
Coroutine_Head *result = &coroutine->head;
if (coroutine->state == CoroutineState_Dead){
coroutine_system_free(&coroutines, coroutine);
result = 0;
}
return(result);
}
Sys_Yield_Coroutine_Sig(system_yield_coroutine){
Coroutine *coroutine = (Coroutine*)head;
coroutine_yield(coroutine);
}
#endif
// BOTTOM

View File

@ -227,18 +227,18 @@ sysshared_to_binary_path(String *out_filename, char *filename){
//
inline void
draw_safe_push(Render_Target *target, i32 size, void *x){
if (size + target->size <= target->max){
memcpy(target->push_buffer + target->size, x, size);
target->size += size;
draw_safe_push(Render_Target *t, i32 size, void *x){
if (size + t->size <= t->max){
memcpy(t->push_buffer + t->size, x, size);
t->size += size;
}
}
#define PutStruct(s,x) draw_safe_push(target, sizeof(s), &x)
#define PutStruct(s,x) draw_safe_push(t, sizeof(s), &x)
internal void
draw_push_piece(Render_Target *target, Render_Piece_Combined piece){
if (!target->clip_all){
draw_push_piece(Render_Target *t, Render_Piece_Combined piece){
if (!t->clip_all){
PutStruct(Render_Piece_Header, piece.header);
switch (piece.header.type){
@ -263,13 +263,13 @@ draw_push_piece(Render_Target *target, Render_Piece_Combined piece){
}break;
}
Assert(target->size <= target->max);
Assert(t->size <= t->max);
}
}
internal void
draw_push_piece_clip(Render_Target *target, i32_Rect clip_box){
if (!target->clip_all){
draw_push_piece_clip(Render_Target *t, i32_Rect clip_box){
if (!t->clip_all){
// TODO(allen): optimize out if there are two clip box changes in a row
Render_Piece_Change_Clip clip;
Render_Piece_Header header;
@ -283,24 +283,24 @@ draw_push_piece_clip(Render_Target *target, i32_Rect clip_box){
}
internal void
draw_push_clip(Render_Target *target, i32_Rect clip_box){
Assert(target->clip_top == -1 || fits_inside(clip_box, target->clip_boxes[target->clip_top]));
Assert(target->clip_top+1 < ArrayCount(target->clip_boxes));
target->clip_boxes[++target->clip_top] = clip_box;
draw_push_clip(Render_Target *t, i32_Rect clip_box){
Assert(t->clip_top == -1 || fits_inside(clip_box, t->clip_boxes[t->clip_top]));
Assert(t->clip_top+1 < ArrayCount(t->clip_boxes));
t->clip_boxes[++t->clip_top] = clip_box;
target->clip_all = (clip_box.x0 >= clip_box.x1 || clip_box.y0 >= clip_box.y1);
draw_push_piece_clip(target, clip_box);
t->clip_all = (clip_box.x0 >= clip_box.x1 || clip_box.y0 >= clip_box.y1);
draw_push_piece_clip(t, clip_box);
}
internal i32_Rect
draw_pop_clip(Render_Target *target){
Assert(target->clip_top > 0);
i32_Rect result = target->clip_boxes[target->clip_top];
--target->clip_top;
i32_Rect clip_box = target->clip_boxes[target->clip_top];
draw_pop_clip(Render_Target *t){
Assert(t->clip_top > 0);
i32_Rect result = t->clip_boxes[t->clip_top];
--t->clip_top;
i32_Rect clip_box = t->clip_boxes[t->clip_top];
target->clip_all = (clip_box.x0 >= clip_box.x1 || clip_box.y0 >= clip_box.y1);
draw_push_piece_clip(target, clip_box);
t->clip_all = (clip_box.x0 >= clip_box.x1 || clip_box.y0 >= clip_box.y1);
draw_push_piece_clip(t, clip_box);
return(result);
}
@ -319,31 +319,31 @@ link_rendering(){
#define ExtractStruct(s) ((s*)cursor); cursor += sizeof(s)
inline void
draw_set_clip(Render_Target *target, i32_Rect clip_box){
glScissor(clip_box.x0, target->height - clip_box.y1, clip_box.x1 - clip_box.x0, clip_box.y1 - clip_box.y0);
draw_set_clip(Render_Target *t, i32_Rect clip_box){
glScissor(clip_box.x0, t->height - clip_box.y1, clip_box.x1 - clip_box.x0, clip_box.y1 - clip_box.y0);
}
inline void
draw_bind_texture(Render_Target *target, i32 texid){
if (target->bound_texture != texid){
draw_bind_texture(Render_Target *t, i32 texid){
if (t->bound_texture != texid){
glBindTexture(GL_TEXTURE_2D, texid);
target->bound_texture = texid;
t->bound_texture = texid;
}
}
inline void
draw_set_color(Render_Target *target, u32 color){
if (target->color != color){
target->color = color;
draw_set_color(Render_Target *t, u32 color){
if (t->color != color){
t->color = color;
Vec4 c = unpack_color4(color);
glColor4f(c.r, c.g, c.b, c.a);
}
}
inline void
private_draw_rectangle(Render_Target *target, f32_Rect rect, u32 color){
draw_set_color(target, color);
draw_bind_texture(target, 0);
private_draw_rectangle(Render_Target *t, f32_Rect rect, u32 color){
draw_set_color(t, color);
draw_bind_texture(t, 0);
glBegin(GL_QUADS);
{
glVertex2f(rect.x0, rect.y0);
@ -355,10 +355,10 @@ private_draw_rectangle(Render_Target *target, f32_Rect rect, u32 color){
}
inline void
private_draw_rectangle_outline(Render_Target *target, f32_Rect rect, u32 color){
private_draw_rectangle_outline(Render_Target *t, f32_Rect rect, u32 color){
f32_Rect r = get_inner_rect(rect, .5f);
draw_set_color(target, color);
draw_bind_texture(target, 0);
draw_set_color(t, color);
draw_bind_texture(t, 0);
glBegin(GL_LINE_STRIP);
{
glVertex2f(r.x0, r.y0);
@ -371,11 +371,11 @@ private_draw_rectangle_outline(Render_Target *target, f32_Rect rect, u32 color){
}
inline void
private_draw_gradient(Render_Target *target, f32_Rect rect, Vec4 color_left, Vec4 color_right){
private_draw_gradient(Render_Target *t, f32_Rect rect, Vec4 color_left, Vec4 color_right){
Vec4 cl = color_left;
Vec4 cr = color_right;
draw_bind_texture(target, 0);
draw_bind_texture(t, 0);
glBegin(GL_QUADS);
{
glColor4f(cl.r, cl.g, cl.b, cl.a);
@ -433,13 +433,13 @@ get_exact_render_quad(Glyph_Bounds *b, i32 pw, i32 ph, float xpos, float ypos){
}
inline void
private_draw_glyph(System_Functions *system, Render_Target *target, Render_Font *font, u32 codepoint, f32 x, f32 y, u32 color){
private_draw_glyph(System_Functions *system, Render_Target *t, Render_Font *font, u32 codepoint, f32 x, f32 y, u32 color){
Glyph_Data glyph = font_get_glyph(system, font, codepoint);
if (glyph.tex != 0){
Render_Quad q = get_render_quad(&glyph.bounds, glyph.tex_width, glyph.tex_height, x, y);
draw_set_color(target, color);
draw_bind_texture(target, glyph.tex);
draw_set_color(t, color);
draw_bind_texture(t, glyph.tex);
glBegin(GL_QUADS);
{
glTexCoord2f(q.s0, q.t1); glVertex2f(q.x0, q.y1);
@ -452,7 +452,7 @@ private_draw_glyph(System_Functions *system, Render_Target *target, Render_Font
}
inline void
private_draw_glyph_mono(System_Functions *system, Render_Target *target, Render_Font *font, u32 codepoint, f32 x, f32 y, f32 advance, u32 color){
private_draw_glyph_mono(System_Functions *system, Render_Target *t, Render_Font *font, u32 codepoint, f32 x, f32 y, f32 advance, u32 color){
Glyph_Data glyph = font_get_glyph(system, font, codepoint);
if (glyph.tex != 0){
f32 left = glyph.bounds.x0;
@ -464,8 +464,8 @@ private_draw_glyph_mono(System_Functions *system, Render_Target *target, Render_
Render_Quad q = get_exact_render_quad(&glyph.bounds, glyph.tex_width, glyph.tex_height, x, y);
draw_set_color(target, color);
draw_bind_texture(target, glyph.tex);
draw_set_color(t, color);
draw_bind_texture(t, glyph.tex);
glBegin(GL_QUADS);
{
glTexCoord2f(q.s0, q.t1); glVertex2f(q.x0, q.y1);
@ -478,15 +478,15 @@ private_draw_glyph_mono(System_Functions *system, Render_Target *target, Render_
}
inline void
private_draw_glyph_mono(System_Functions *system, Render_Target *target, Render_Font *font, u32 character, f32 x, f32 y, u32 color){
private_draw_glyph_mono(System_Functions *system, Render_Target *t, Render_Font *font, u32 character, f32 x, f32 y, u32 color){
f32 advance = (f32)font_get_advance(font);
private_draw_glyph_mono(system, target, font, character, x, y, advance, color);
private_draw_glyph_mono(system, t, font, character, x, y, advance, color);
}
internal void
launch_rendering(System_Functions *system, Render_Target *target){
char *cursor = target->push_buffer;
char *cursor_end = cursor + target->size;
launch_rendering(System_Functions *system, Render_Target *t){
char *cursor = t->push_buffer;
char *cursor_end = cursor + t->size;
for (; cursor < cursor_end;){
Render_Piece_Header *header = ExtractStruct(Render_Piece_Header);
@ -496,19 +496,19 @@ launch_rendering(System_Functions *system, Render_Target *target){
case piece_type_rectangle:
{
Render_Piece_Rectangle *rectangle = ExtractStruct(Render_Piece_Rectangle);
private_draw_rectangle(target, rectangle->rect, rectangle->color);
private_draw_rectangle(t, rectangle->rect, rectangle->color);
}break;
case piece_type_outline:
{
Render_Piece_Rectangle *rectangle = ExtractStruct(Render_Piece_Rectangle);
private_draw_rectangle_outline(target, rectangle->rect, rectangle->color);
private_draw_rectangle_outline(t, rectangle->rect, rectangle->color);
}break;
case piece_type_gradient:
{
Render_Piece_Gradient *gradient = ExtractStruct(Render_Piece_Gradient);
private_draw_gradient(target, gradient->rect, unpack_color4(gradient->left_color), unpack_color4(gradient->right_color));
private_draw_gradient(t, gradient->rect, unpack_color4(gradient->left_color), unpack_color4(gradient->right_color));
}break;
case piece_type_glyph:
@ -517,7 +517,7 @@ launch_rendering(System_Functions *system, Render_Target *target){
Render_Font *font = system->font.get_render_data_by_id(glyph->font_id);
Assert(font != 0);
private_draw_glyph(system, target, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->color);
private_draw_glyph(system, t, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->color);
}break;
case piece_type_mono_glyph:
@ -526,7 +526,7 @@ launch_rendering(System_Functions *system, Render_Target *target){
Render_Font *font = system->font.get_render_data_by_id(glyph->font_id);
Assert(font != 0);
private_draw_glyph_mono(system, target, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->color);
private_draw_glyph_mono(system, t, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->color);
}break;
case piece_type_mono_glyph_advance:
@ -535,13 +535,13 @@ launch_rendering(System_Functions *system, Render_Target *target){
Render_Font *font = system->font.get_render_data_by_id(glyph->font_id);
Assert(font != 0);
private_draw_glyph_mono(system, target, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->advance, glyph->color);
private_draw_glyph_mono(system, t, font, glyph->codepoint, glyph->pos.x, glyph->pos.y, glyph->advance, glyph->color);
}break;
case piece_type_change_clip:
{
Render_Piece_Change_Clip *clip = ExtractStruct(Render_Piece_Change_Clip);
draw_set_clip(target, clip->box);
draw_set_clip(t, clip->box);
}break;
}
}

View File

@ -50,7 +50,6 @@
#include <stdlib.h>
#include <locale.h>
#include <dlfcn.h>
#include <xmmintrin.h>
#include <ucontext.h>
@ -76,7 +75,7 @@
#include <linux/input.h>
#include "4ed_shared_thread_constants.h"
#include "linux_threading_wrapper.h"
#include "unix_threading_wrapper.h"
//
// Linux macros
@ -90,6 +89,7 @@
LOGF("%s: " fmt "\n", __func__, ##__VA_ARGS__); \
} while (0)
// TODO(allen): Make an intrinsics header that uses the cracked OS to define a single set of intrinsic names.
#define InterlockedCompareExchange(dest, ex, comp) \
__sync_val_compare_and_swap((dest), (comp), (ex))
@ -118,7 +118,7 @@ internal void LinuxStringDup(String*, void*, size_t);
global System_Functions sysfunc;
#include "4ed_shared_library_constants.h"
#include "linux_library_wrapper.h"
#include "unix_library_wrapper.h"
#include "4ed_standard_libraries.cpp"
#include "4ed_coroutine.cpp"
@ -305,6 +305,8 @@ Sys_Send_Exit_Signal_Sig(system_send_exit_signal){
linuxvars.keep_running = false;
}
#include "4ed_coroutine_functions.cpp"
//
// Clipboard
//
@ -315,63 +317,6 @@ Sys_Post_Clipboard_Sig(system_post_clipboard){
XSetSelectionOwner(linuxvars.XDisplay, linuxvars.atom_CLIPBOARD, linuxvars.XWindow, CurrentTime);
}
//
// Coroutine
//
internal
Sys_Create_Coroutine_Sig(system_create_coroutine){
Coroutine *coroutine = coroutine_system_alloc(&coroutines);
Coroutine_Head *result = 0;
if (coroutine != 0){
coroutine_set_function(coroutine, func);
result = &coroutine->head;
}
return(result);
}
internal
Sys_Launch_Coroutine_Sig(system_launch_coroutine){
Coroutine *coroutine = (Coroutine*)head;
coroutine->head.in = in;
coroutine->head.out = out;
Coroutine *active = coroutine->sys->active;
Assert(active != 0);
coroutine_launch(active, coroutine);
Assert(active == coroutine->sys->active);
Coroutine_Head *result = &coroutine->head;
if (coroutine->state == CoroutineState_Dead){
coroutine_system_free(&coroutines, coroutine);
result = 0;
}
return(result);
}
Sys_Resume_Coroutine_Sig(system_resume_coroutine){
Coroutine *coroutine = (Coroutine*)head;
coroutine->head.in = in;
coroutine->head.out = out;
Coroutine *active = coroutine->sys->active;
Assert(active != 0);
coroutine_resume(active, coroutine);
Assert(active == coroutine->sys->active);
Coroutine_Head *result = &coroutine->head;
if (coroutine->state == CoroutineState_Dead){
coroutine_system_free(&coroutines, coroutine);
result = 0;
}
return(result);
}
Sys_Yield_Coroutine_Sig(system_yield_coroutine){
Coroutine *coroutine = (Coroutine*)head;
coroutine_yield(coroutine);
}
//
// CLI
//
@ -484,10 +429,6 @@ Sys_CLI_End_Update_Sig(system_cli_end_update){
return(close_me);
}
//
// Linux rendering/font system functions
//
#include "4ed_font_data.h"
#include "4ed_system_shared.cpp"
@ -1470,20 +1411,17 @@ LinuxHandleX11Events(void)
response.time = request.time;
response.property = None;
if (
linuxvars.clipboard_outgoing.size &&
if (linuxvars.clipboard_outgoing.size &&
request.selection == linuxvars.atom_CLIPBOARD &&
request.property != None &&
request.display &&
request.requestor
){
request.requestor){
Atom atoms[] = {
XA_STRING,
linuxvars.atom_UTF8_STRING
};
if (request.target == linuxvars.atom_TARGETS){
XChangeProperty(
request.display,
request.requestor,
@ -1492,8 +1430,7 @@ LinuxHandleX11Events(void)
32,
PropModeReplace,
(u8*)atoms,
ArrayCount(atoms)
);
ArrayCount(atoms));
response.property = request.property;

View File

@ -21,7 +21,6 @@
# include "4coder_API/style.h"
# define FSTRING_IMPLEMENTATION
# define FSTRING_C
# include "4coder_lib/4coder_string.h"
# include "4coder_lib/4coder_mem.h"
@ -43,12 +42,158 @@
#include "4ed_font_interface_to_os.h"
#include "4ed_system_shared.h"
#include "unix_4ed_headers.h"
#include <sys/syslimits.h>
#include "unix_4ed_functions.cpp"
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <stdlib.h>
////////////////////////////////
#include "4ed_shared_thread_constants.h"
#include "unix_threading_wrapper.h"
// TODO(allen): Make an intrinsics header that uses the cracked OS to define a single set of intrinsic names.
#define InterlockedCompareExchange(dest, ex, comp) \
__sync_val_compare_and_swap((dest), (comp), (ex))
////////////////////////////////
#define SLASH '/'
#define DLL "so"
global System_Functions sysfunc;
#include "4ed_shared_library_constants.h"
#include "unix_library_wrapper.h"
#include "4ed_standard_libraries.cpp"
#include "4ed_coroutine.cpp"
////////////////////////////////
#include "osx_objective_c_to_cpp_links.h"
OSX_Vars osx;
global Render_Target target;
global Application_Memory memory_vars;
global Plat_Settings plat_settings;
global Libraries libraries;
global App_Functions app;
global Custom_API custom_api;
global Coroutine_System_Auto_Alloc coroutines;
////////////////////////////////
#include "mac_error_box.cpp"
////////////////////////////////
#include "unix_4ed_functions.cpp"
#include "4ed_shared_file_handling.cpp"
////////////////////////////////
internal void
system_schedule_step(){
// NOTE(allen): It is unclear to me right now what we might need to actually do here.
// The run loop in a Cocoa app will keep rendering the app anyway, I might just need to set a
// "do_new_frame" variable of some kind to true here.
}
////////////////////////////////
#include "4ed_work_queues.cpp"
////////////////////////////////
internal
Sys_Show_Mouse_Cursor_Sig(system_show_mouse_cursor){
// TODO(allen)
}
internal
Sys_Set_Fullscreen_Sig(system_set_fullscreen){
osx.do_toggle = (osx.full_screen != full_screen);
return(true);
}
internal
Sys_Is_Fullscreen_Sig(system_is_fullscreen){
b32 result = (osx.full_screen != osx.do_toggle);
return(result);
}
// HACK(allen): Why does this work differently from the win32 version!?
internal
Sys_Send_Exit_Signal_Sig(system_send_exit_signal){
osx.running = false;
}
#include "4ed_coroutine_functions.cpp"
//
// Clipboard
//
internal
Sys_Post_Clipboard_Sig(system_post_clipboard){
char *string = str.str;
if (!terminate_with_null(&str)){
if (osx.clipboard_space_max <= str.size + 1){
if (osx.clipboard_space != 0){
system_memory_free(osx.clipboard_space, osx.clipboard_space_max);
}
osx.clipboard_space_max = l_round_up_u32(str.size*2 + 1, KB(4096));
osx.clipboard_space = (char*)system_memory_allocate(osx.clipboard_space_max);
}
memcpy(osx.clipboard_space, str.str, str.size);
osx.clipboard_space[str.size] = 0;
string = osx.clipboard_space;
}
osx_post_to_clipboard(string);
}
//
// CLI
//
internal
Sys_CLI_Call_Sig(system_cli_call){
// b32 #(char *path, char *script_name, CLI_Handles *cli_out)
NotImplemented;
return(true);
}
internal
Sys_CLI_Begin_Update_Sig(system_cli_begin_update){
// void #(CLI_Handles *cli)
NotImplemented;
}
internal
Sys_CLI_Update_Step_Sig(system_cli_update_step){
// b32 #(CLI_Handles *cli, char *dest, u32 max, u32 *amount)
NotImplemented;
return(0);
}
internal
Sys_CLI_End_Update_Sig(system_cli_end_update){
// b32 #(CLI_Handles *cli)
NotImplemented;
return(false);
}
#include "4ed_font_data.h"
#include "4ed_system_shared.cpp"
////////////////////////////////
#include "4ed_link_system_functions.cpp"
#include "4ed_shared_init_logic.cpp"
external void*
osx_allocate(umem size){
@ -85,8 +230,94 @@ osx_step(){
external void
osx_init(){
// TODO
//
// System Linkage
//
link_system_code();
//
// Memory init
//
memset(&target, 0, sizeof(target));
memset(&memory_vars, 0, sizeof(memory_vars));
memset(&plat_settings, 0, sizeof(plat_settings));
memset(&libraries, 0, sizeof(libraries));
memset(&app, 0, sizeof(app));
memset(&custom_api, 0, sizeof(custom_api));
memory_init();
//
// HACK(allen):
// Previously zipped stuff is here, it should be zipped in the new pattern now.
//
init_shared_vars();
//
// Dynamic Linkage
//
load_app_code();
link_rendering();
#if defined(FRED_SUPER)
load_custom_code();
#else
custom_api.get_bindings = get_bindings;
#endif
//
// Read command line
//
read_command_line(osx.argc, osx.argv);
//
// Threads
//
work_system_init();
//
// Coroutines
//
coroutines_init();
//
// Font System Init
//
system_font_init(&sysfunc.font, 0, 0, plat_settings.font_size, plat_settings.use_hinting);
//
// App Init
//
char cwd[4096];
u32 size = sysfunc.get_current_path(cwd, sizeof(cwd));
if (size == 0 || size >= sizeof(cwd)){
system_error_box("Could not get current directory at launch.");
}
String curdir = make_string(cwd, size);
terminate_with_null(&curdir);
replace_char(&curdir, '\\', '/');
String clipboard_string = {0};
if (osx.has_clipboard_item){
clipboard_string = make_string(osx.clipboard_data, osx.clipboard_size);
}
LOG("Initializing application variables\n");
app.init(&sysfunc, &target, &memory_vars, clipboard_string, curdir, custom_api);
}
#include "4ed_shared_fonts.cpp"
#include "mac_4ed_file_track.cpp"
#include "4ed_font_static_functions.cpp"
// BOTTOM

View File

@ -38,6 +38,16 @@ osx_post_to_clipboard(char *str){
osx.just_posted_to_clipboard = true;
}
void
osx_error_dialogue(char *str){
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"OK"];
NSString *text = [NSString stringWithUTF8String:str];
[alert setMessageText:text];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert runModal];
}
//
// Entry point, OpenGL window setup.
//
@ -281,6 +291,8 @@ main(int argc, char **argv){
umem clipboard_size = MB(4);
osx.clipboard_data = osx_allocate(clipboard_size);
osx.clipboard_max = clipboard_size;
osx.argc = argc;
osx.argv = argv;
osx_init();

View File

@ -0,0 +1,63 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 28.06.2017
*
* Mac file tracking C++ wrapper.
*
*/
// TOP
File_Track_Result
init_track_system(File_Track_System *system, Partition *scratch, void *table_memory, i32 table_memory_size, void *listener_memory, i32 listener_memory_size){
File_Track_Result result = FileTrack_Good;
NotImplemented;
return(result);
}
File_Track_Result
add_listener(File_Track_System *system, Partition *scratch, u8 *filename){
File_Track_Result result = FileTrack_Good;
NotImplemented;
return(result);
}
File_Track_Result
remove_listener(File_Track_System *system, Partition *scratch, u8 *filename){
File_Track_Result result = FileTrack_Good;
NotImplemented;
return(result);
}
File_Track_Result
move_track_system(File_Track_System *system, Partition *scratch, void *mem, i32 size){
File_Track_Result result = FileTrack_Good;
NotImplemented;
return(result);
}
File_Track_Result
expand_track_system_listeners(File_Track_System *system, Partition *scratch, void *mem, i32 size){
File_Track_Result result = FileTrack_Good;
NotImplemented;
return(result);
}
File_Track_Result
get_change_event(File_Track_System *system, Partition *scratch, u8 *buffer, i32 max, i32 *size){
File_Track_Result result = FileTrack_Good;
NotImplemented;
return(result);
}
File_Track_Result
shut_down_track_system(File_Track_System *system, Partition *scratch){
File_Track_Result result = FileTrack_Good;
NotImplemented;
return(result);
}
// BOTTOM

View File

@ -0,0 +1,19 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 26.09.2017
*
* Mac error box implementation.
*
*/
// TOP
internal void
system_error_box(char *msg){
osx_error_dialogue(msg);
exit(1);
}
// BOTTOM

View File

@ -36,6 +36,15 @@ typedef struct OSX_Vars{
void *clipboard_data;
umem clipboard_size, clipboard_max;
b32 just_posted_to_clipboard;
char *clipboard_space;
umem clipboard_space_max;
b32 full_screen;
b32 do_toggle;
i32 argc;
char **argv;
} OSX_Vars;
// In C++ layer.
@ -66,6 +75,9 @@ osx_init();
external void
osx_post_to_clipboard(char *str);
external void
osx_error_dialogue(char *str);
#endif
// BOTTOM

View File

@ -13,6 +13,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>

View File

@ -9,8 +9,8 @@
// TOP
#if !defined(LINUX_THREADING_WRAPPER)
#define LINUX_THREADING_WRAPPER
#if !defined(MAC_THREADING_WRAPPER)
#define MAC_THREADING_WRAPPER
#define PLAT_THREAD_SIG(n) void* n(void *ptr)
typedef PLAT_THREAD_SIG(Thread_Function);
@ -35,7 +35,6 @@ union Semaphore{
FixSize(SEMAPHORE_TYPE_SIZE);
};
internal void
system_init_and_launch_thread(Thread *t, Thread_Function *proc, void *ptr){
pthread_create(&t->t, 0, proc, ptr);

View File

@ -262,62 +262,7 @@ Sys_Send_Exit_Signal_Sig(system_send_exit_signal){
win32vars.send_exit_signal = true;
}
//
// Coroutines
//
internal
Sys_Create_Coroutine_Sig(system_create_coroutine){
Coroutine *coroutine = coroutine_system_alloc(&coroutines);
Coroutine_Head *result = 0;
if (coroutine != 0){
coroutine_set_function(coroutine, func);
result = &coroutine->head;
}
return(result);
}
internal
Sys_Launch_Coroutine_Sig(system_launch_coroutine){
Coroutine *coroutine = (Coroutine*)head;
coroutine->head.in = in;
coroutine->head.out = out;
Coroutine *active = coroutine->sys->active;
Assert(active != 0);
coroutine_launch(active, coroutine);
Assert(active == coroutine->sys->active);
Coroutine_Head *result = &coroutine->head;
if (coroutine->state == CoroutineState_Dead){
coroutine_system_free(&coroutines, coroutine);
result = 0;
}
return(result);
}
Sys_Resume_Coroutine_Sig(system_resume_coroutine){
Coroutine *coroutine = (Coroutine*)head;
coroutine->head.in = in;
coroutine->head.out = out;
Coroutine *active = coroutine->sys->active;
Assert(active != 0);
coroutine_resume(active, coroutine);
Assert(active == coroutine->sys->active);
Coroutine_Head *result = &coroutine->head;
if (coroutine->state == CoroutineState_Dead){
coroutine_system_free(&coroutines, coroutine);
result = 0;
}
return(result);
}
Sys_Yield_Coroutine_Sig(system_yield_coroutine){
Coroutine *coroutine = (Coroutine*)head;
coroutine_yield(coroutine);
}
#include "4ed_coroutine_functions.cpp"
//
// Clipboard