示例#1
0
void load_game_dll(game_state *gstate) {
    char *source_dll_name = "game_logic.dll";
    char *temp_dll_name = "game_logic_temp.dll";
    CopyFile(source_dll_name, temp_dll_name, FALSE); 
    gstate->lib = LoadLibrary(temp_dll_name);
    gstate->last_write_time = get_last_write_time(source_dll_name);
    if(gstate->lib) {
        gstate->update = (game_update_func *) GetProcAddress(gstate->lib, "update");
        gstate->render = (game_render_func *) GetProcAddress(gstate->lib, "render");
        gstate->init = (game_init_func *) GetProcAddress(gstate->lib, "init");
        gstate->is_init = 0;
    } else {
        gstate->update = game_update_stub;
        gstate->render = game_render_stub;
        gstate->init = game_init_stub;
    }
}
示例#2
0
int main(int argc, char ** argv) {

    game_state gamestate = {};
    GLFWwindow *window = init(&gamestate);
    load_program_attrib_location(&gamestate);
    bool run = true;


    int max_frames_to_simulate = 2;
    
    gamestate.update = game_update_stub;
    gamestate.render = game_render_stub;
    gamestate.init = game_init_stub;

    gamestate.window_width_height = vec2(SCREEN_SIZE_X, SCREEN_SIZE_Y);

    load_game_dll(&gamestate);
 
    // glfwSetTime(0);
    double total_time = 0;
    double current_time = glfwGetTime();
    double previous_time = current_time;
    double frame_time = 0;

    glfwSwapInterval(0);
    sh_circle testing(0, 0, 10, vec2(0, 1), vec4(1, 0, 0, 1));
    while(run) {
        current_time = glfwGetTime();
        frame_time = (current_time - previous_time);
        
        if(frame_time > 0.25)
            frame_time = 0.25;

        total_time += frame_time;
        previous_time = current_time;

        FILETIME last_write_dll = get_last_write_time("game_logic.dll");
        if(CompareFileTime(&gamestate.last_write_time, &last_write_dll) != 0) {
            unload_game_dll(&gamestate); 
            load_game_dll(&gamestate);
        }

        if(!gamestate.is_init) {
            gamestate.init(&gamestate);
            gamestate.is_init = 1;
        }



        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 


        if((glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)) {
                run  = false;
                glfwSetWindowShouldClose(window, true);
        }

        while(( total_time >= dt )) {
            gamestate.update(&gamestate, &mouse_st);
            total_time -= dt;       
        }

        const double time_left_alpha = total_time/dt;
        
        gamestate.render(&gamestate, time_left_alpha);

        
        glfwSwapBuffers(window);
        glfwPollEvents(); 
    }


    glfwDestroyWindow(window);
    return 0;
}
示例#3
0
void lua_script_init(lua_State **L,HANDLE **lua_filenotify,__int64 *ft)
{
	char fscript[MAX_PATH]={0};
	int script_changed=FALSE;

	get_lua_script_fname(fscript,sizeof(fscript));

	if(lua_script_enable){
		__int64 tt=0;
		get_last_write_time(fscript,&tt);
		if(tt!=(*ft)){
			script_changed=TRUE;
			hide_tooltip();
		}
	}

	if(lua_script_enable){
		if((*L)==0 || script_changed){
			lua_State *lua;
			lua=luaL_newstate();
			if(lua!=0){
				luaL_openlibs(lua);
				if(luaL_loadfile(lua,fscript)!=LUA_OK){
					printf("luaL_loadfile error:%s\n",lua_tostring(lua, -1));
					show_tooltip(lua_tostring(lua, -1),0,0);
					lua_close(lua);
				}
				else{
					lua_register_c_functions(lua);
					if(lua_pcall(lua,0,0,0)!=LUA_OK){
						printf("lua_pcall error:%s\n",lua_tostring(lua, -1));
						show_tooltip(lua_tostring(lua, -1),0,0);
						lua_close(lua);
					}
					else{
						if((*L)!=0)
							lua_close(*L);
						*L=lua;
						get_last_write_time(fscript,ft);
						lua_error_msg=0;
						hide_tooltip();
					}
				}
			}
		}
	}
	if(*lua_filenotify!=0){
		if(FindNextChangeNotification(*lua_filenotify)==0){
			FindCloseChangeNotification(*lua_filenotify);
			*lua_filenotify=0;
		}
	}
	if(*lua_filenotify==0){
		HANDLE fn;
		char path[MAX_PATH]={0};
		get_ini_path(path,sizeof(path));
		fn=FindFirstChangeNotification(path,FALSE,FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_LAST_WRITE);
		if(fn!=INVALID_HANDLE_VALUE)
			*lua_filenotify=fn;
	}
}