mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-19 14:41:29 +02:00
Added copy/cut and paste, speed improvements for the 'nearest_part' function
This commit is contained in:
79
powder.c
79
powder.c
@@ -26,9 +26,6 @@
|
|||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
#include <bzlib.h>
|
#include <bzlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#ifdef OCL
|
|
||||||
#include <CL/opencl.h>
|
|
||||||
#endif
|
|
||||||
//#include <pthread.h>
|
//#include <pthread.h>
|
||||||
#ifdef MT
|
#ifdef MT
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
@@ -64,7 +61,7 @@
|
|||||||
|
|
||||||
#define ZSIZE_D 16
|
#define ZSIZE_D 16
|
||||||
#define ZFACTOR_D 8
|
#define ZFACTOR_D 8
|
||||||
unsigned char ZFACTOR = 256/ZSIZE_D;//ZFACTOR_D;
|
unsigned char ZFACTOR = 256/ZSIZE_D;
|
||||||
unsigned char ZSIZE = ZSIZE_D;
|
unsigned char ZSIZE = ZSIZE_D;
|
||||||
|
|
||||||
#define CELL 4
|
#define CELL 4
|
||||||
@@ -115,6 +112,7 @@ char *it_msg =
|
|||||||
"\brThe Powder Toy\n"
|
"\brThe Powder Toy\n"
|
||||||
"\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\n"
|
"\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
"\bgControl+C/V/X are Copy, Paste and cut respectively.\n"
|
||||||
"\bgTo choose a material, hover over once of the icons on the right, it will show a selection of elements in that group.\n"
|
"\bgTo choose a material, hover over once of the icons on the right, it will show a selection of elements in that group.\n"
|
||||||
"\bgPick your material from the menu using mouse left/right buttons.\n"
|
"\bgPick your material from the menu using mouse left/right buttons.\n"
|
||||||
"Draw freeform lines by dragging your mouse left/right button across the drawing area.\n"
|
"Draw freeform lines by dragging your mouse left/right button across the drawing area.\n"
|
||||||
@@ -137,11 +135,7 @@ char *it_msg =
|
|||||||
"\n"
|
"\n"
|
||||||
"\bgSpecial thanks to Brian Ledbetter for maintaining ports & server development in the past."
|
"\bgSpecial thanks to Brian Ledbetter for maintaining ports & server development in the past."
|
||||||
"\nand CW for hosting the original server.\n"
|
"\nand CW for hosting the original server.\n"
|
||||||
#ifdef WIN32
|
"\bgTo use online features such as saving, you need to register at: \brhttp://powder.hardwired.org.uk/Register.html"
|
||||||
"\nThanks to Akuryo for Windows icons.\n"
|
|
||||||
#endif
|
|
||||||
"\n"
|
|
||||||
"\bgTo use online features such as saving, you need to register at: http://powder.hardwired.org.uk/Register.html"
|
|
||||||
;
|
;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -1110,7 +1104,7 @@ int nearest_part(int ci, int t){
|
|||||||
int cy = (int)parts[ci].y;
|
int cy = (int)parts[ci].y;
|
||||||
for(i=0; i<NPART; i++){
|
for(i=0; i<NPART; i++){
|
||||||
if(parts[i].type==t&&!parts[i].life&&i!=ci){
|
if(parts[i].type==t&&!parts[i].life&&i!=ci){
|
||||||
ndistance = sqrt(pow(cx-parts[i].x, 2)+pow(cy-parts[i].y, 2));
|
ndistance = abs((cx-parts[i].x)+(cy-parts[i].y));// Faster but less accurate Older: sqrt(pow(cx-parts[i].x, 2)+pow(cy-parts[i].y, 2));
|
||||||
if(ndistance<distance){
|
if(ndistance<distance){
|
||||||
distance = ndistance;
|
distance = ndistance;
|
||||||
id = i;
|
id = i;
|
||||||
@@ -3710,6 +3704,10 @@ void stamp_gen_thumb(int i)
|
|||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int clipboard_ready = 0;
|
||||||
|
void *clipboard_data = 0;
|
||||||
|
int clipboard_length = 0;
|
||||||
|
|
||||||
void stamp_save(int x, int y, int w, int h)
|
void stamp_save(int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
@@ -7535,7 +7533,7 @@ char *download_ui(pixel *vid_buf, char *uri, int *len)
|
|||||||
ulen |= ((unsigned char)tmp[6])<<16;
|
ulen |= ((unsigned char)tmp[6])<<16;
|
||||||
ulen |= ((unsigned char)tmp[7])<<24;
|
ulen |= ((unsigned char)tmp[7])<<24;
|
||||||
|
|
||||||
res = malloc(ulen);
|
res = (char *)malloc(ulen);
|
||||||
if(!res){
|
if(!res){
|
||||||
printf("No res!\n");
|
printf("No res!\n");
|
||||||
goto corrupt;
|
goto corrupt;
|
||||||
@@ -7558,6 +7556,17 @@ corrupt:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clear_area(int area_x, int area_y, int area_w, int area_h){
|
||||||
|
int cx = 0;
|
||||||
|
int cy = 0;
|
||||||
|
for(cy=0; cy<area_h; cy++){
|
||||||
|
for(cx=0; cx<area_w; cx++){
|
||||||
|
bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0;
|
||||||
|
delete_part(cx+area_x, cy+area_y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int hud_enable = 1;
|
int hud_enable = 1;
|
||||||
@@ -7586,7 +7595,7 @@ int main(int argc, char *argv[])
|
|||||||
int load_mode=0, load_w=0, load_h=0, load_x=0, load_y=0, load_size=0;
|
int load_mode=0, load_w=0, load_h=0, load_x=0, load_y=0, load_size=0;
|
||||||
void *load_data=NULL;
|
void *load_data=NULL;
|
||||||
pixel *load_img=NULL;//, *fbi_img=NULL;
|
pixel *load_img=NULL;//, *fbi_img=NULL;
|
||||||
int save_mode=0, save_x=0, save_y=0, save_w=0, save_h=0;
|
int save_mode=0, save_x=0, save_y=0, save_w=0, save_h=0, copy_mode=0;
|
||||||
|
|
||||||
#ifdef MT
|
#ifdef MT
|
||||||
numCores = core_count();
|
numCores = core_count();
|
||||||
@@ -7834,7 +7843,28 @@ int main(int argc, char *argv[])
|
|||||||
sys_pause = !sys_pause;
|
sys_pause = !sys_pause;
|
||||||
if(sdl_key=='p')
|
if(sdl_key=='p')
|
||||||
dump_frame(vid_buf, XRES, YRES, XRES);
|
dump_frame(vid_buf, XRES, YRES, XRES);
|
||||||
if(sdl_key=='c') {
|
if(sdl_key=='v'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))){
|
||||||
|
if(clipboard_ready==1){
|
||||||
|
load_data = malloc(clipboard_length);
|
||||||
|
memcpy(load_data, clipboard_data, clipboard_length);
|
||||||
|
load_size = clipboard_length;
|
||||||
|
if(load_data) {
|
||||||
|
load_img = prerender_save(load_data, load_size, &load_w, &load_h);
|
||||||
|
if(load_img)
|
||||||
|
load_mode = 1;
|
||||||
|
else
|
||||||
|
free(load_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(sdl_key=='x'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))){
|
||||||
|
save_mode = 1;
|
||||||
|
copy_mode = 2;
|
||||||
|
}
|
||||||
|
if(sdl_key=='c'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))){
|
||||||
|
save_mode = 1;
|
||||||
|
copy_mode = 1;
|
||||||
|
} else if(sdl_key=='c') {
|
||||||
#ifdef HEAT_ENABLE
|
#ifdef HEAT_ENABLE
|
||||||
set_cmode((cmode+1) % 6);
|
set_cmode((cmode+1) % 6);
|
||||||
#else
|
#else
|
||||||
@@ -8059,10 +8089,12 @@ int main(int argc, char *argv[])
|
|||||||
if(save_y >= YRES/CELL) save_y = YRES/CELL-1;
|
if(save_y >= YRES/CELL) save_y = YRES/CELL-1;
|
||||||
save_w = 1;
|
save_w = 1;
|
||||||
save_h = 1;
|
save_h = 1;
|
||||||
if(b==1)
|
if(b==1){
|
||||||
save_mode = 2;
|
save_mode = 2;
|
||||||
else if(b==4)
|
} else if(b==4){
|
||||||
save_mode = 0;
|
save_mode = 0;
|
||||||
|
copy_mode = 0;
|
||||||
|
}
|
||||||
} else if(save_mode==2) {
|
} else if(save_mode==2) {
|
||||||
save_w = (mx/sdl_scale+CELL/2)/CELL - save_x;
|
save_w = (mx/sdl_scale+CELL/2)/CELL - save_x;
|
||||||
save_h = (my/sdl_scale+CELL/2)/CELL - save_y;
|
save_h = (my/sdl_scale+CELL/2)/CELL - save_y;
|
||||||
@@ -8071,8 +8103,21 @@ int main(int argc, char *argv[])
|
|||||||
if(save_w<1) save_w = 1;
|
if(save_w<1) save_w = 1;
|
||||||
if(save_h<1) save_h = 1;
|
if(save_h<1) save_h = 1;
|
||||||
if(!b) {
|
if(!b) {
|
||||||
stamp_save(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL);
|
if(copy_mode==1){
|
||||||
save_mode = 0;
|
clipboard_data=build_save(&clipboard_length, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL);
|
||||||
|
clipboard_ready = 1;
|
||||||
|
save_mode = 0;
|
||||||
|
copy_mode = 0;
|
||||||
|
} else if(copy_mode==2){
|
||||||
|
clipboard_data=build_save(&clipboard_length, save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL);
|
||||||
|
clipboard_ready = 1;
|
||||||
|
save_mode = 0;
|
||||||
|
copy_mode = 0;
|
||||||
|
clear_area(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL);
|
||||||
|
} else {
|
||||||
|
stamp_save(save_x*CELL, save_y*CELL, save_w*CELL, save_h*CELL);
|
||||||
|
save_mode = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if(sdl_zoom_trig && zoom_en<2) {
|
} else if(sdl_zoom_trig && zoom_en<2) {
|
||||||
x /= sdl_scale;
|
x /= sdl_scale;
|
||||||
|
@@ -21,11 +21,11 @@
|
|||||||
#define VERSION_H
|
#define VERSION_H
|
||||||
|
|
||||||
#define SAVE_VERSION 38
|
#define SAVE_VERSION 38
|
||||||
#define MINOR_VERSION 0
|
#define MINOR_VERSION 1
|
||||||
#define IDENT_VERSION "S" //Change this if you're not Simon! It should be a single letter.
|
#define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter.
|
||||||
|
|
||||||
#define MENUV3
|
#define MENUV3
|
||||||
//#define BETA
|
#define BETA
|
||||||
#define HEAT_ENABLE
|
#define HEAT_ENABLE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user