Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 831 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 4 of 4 1 2 3 4
Re: How to: tiles in 3dgs [Re: Joozey] #378935
07/27/11 22:50
07/27/11 22:50
Joined: Jul 2010
Posts: 283
Germany
J
jenGs Offline
Member
jenGs  Offline
Member
J

Joined: Jul 2010
Posts: 283
Germany
Hello,
I know you have got allready a lot of suggestions about the tileproblem, but I did some testing and have a whole different sollution for you.

Just execute this code and see.
Click onto the rectangle to switch a tile.

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <stdio.h>

///////////////////////////////

void createFile();
void createAdvanced();
void clickAround();

BMAP *sand = "b1.tga";
BMAP *gras = "b2.tga";

STRING *line = "";

ENTITY *wall;

void main()
{
	mouse_mode = 4;
	mouse_pointer = 2;
	mouse_sync = 1;
	video_switch(10, 32, 2);
	wait(1);
	level_load("");
	
	createAdvanced();
	
	camera.pan = 90;
	camera.y = -512;
	camera->flags |= ISOMETRIC;
	camera.arc = 20;
	
	clickAround();
}

void clickAround()
{
	VECTOR to;
	
	while(1)
	{
		if(mouse_left)
		{
			vec_set(to, mouse_dir3d);
			vec_scale(to, 1000);
			vec_add(to,mouse_pos3d);
			c_trace(mouse_pos3d, to, USE_POLYGON | SCAN_TEXTURE);
			if(hit.entity != NULL)
			{
				ENTITY *w = hit.entity;
				var s = hit.triangle;
				if(s % 2 != 0) { s++; }
				s /= 2;
				int v1 = ((s - 1) * 4) + 1;
				CONTACT *c = ent_getvertex(w, NULL, v1);
				c.v = NULL;
				c.x += 8;
				ent_setvertex(w, c, v1);
				
				c = ent_getvertex(w, NULL, v1 + 1);
				c.v = NULL;
				c.x -= 8;
				ent_setvertex(w, c, v1 + 1);
				
				c = ent_getvertex(w, NULL, v1 + 2);
				c.v = NULL;
				c.x += 8;
				ent_setvertex(w, c, v1 + 2);
				
				c = ent_getvertex(w, NULL, v1 + 3);
				c.v = NULL;
				c.x -= 8;
				ent_setvertex(w, c, v1 + 3);
			}
			while(mouse_left) { wait(1); }
		}
		wait(1);
	}
}

void createAdvanced()
{
	int px, py;
	int x, y;
	double rx, ry;
	int i = 0;
	STRING *f = str_create("");
	int mesh = 0;
	
	BMAP *map01 = bmap_createblack(320, 320, 32);
	
	for(px = 0; px < 1; px++)
	{
		for(py = 0; py < 1; py++)
		{
			str_printf(f, "mesh%.0f.obj", (double)mesh);
			
			FILE *file = fopen(f.chars, "wb");
			
			for(y = 0; y < 20; y++)
			{
				for(x = 0; x < 20; x++)
				{
					rx = x * 8;
					ry = -y * 8;
					str_printf(line, "v %.0f %.0f 0\n", rx, ry);
					fputs(line.chars, file);
					str_printf(line, "v %.0f %.0f 0\n", rx + 8, ry);
					fputs(line.chars, file);
					str_printf(line, "v %.0f %.0f 0\n", rx, ry - 8);
					fputs(line.chars, file);
					str_printf(line, "v %.0f %.0f 0\n", rx + 8, ry - 8);
					fputs(line.chars, file);
				}
			}
			
			fputs("\n", file);
			
			for(y = 0; y < 20; y++)
			{
				for(x = 0; x < 20; x++)
				{
					str_printf(line, "vt %.3f %.3f\n", (double)x / 20.0, (double)y / 20.0);
					fputs(line.chars, file);
					str_printf(line, "vt %.3f %.3f\n", ((double)x + 1) / 20.0, (double)y / 20.0);
					fputs(line.chars, file);
					str_printf(line, "vt %.3f %.3f\n", (double)x / 20.0, ((double)y + 1) / 20.0);
					fputs(line.chars, file);
					str_printf(line, "vt %.3f %.3f\n", ((double)x + 1) / 20.0, ((double)y +1) / 20.0);
					fputs(line.chars, file);
					
					bmap_blit(map01, sand, vector(x * 16, y * 16, 0), NULL);
				}
			}
			
			fputs("\n", file);
			
			for(i = 0; i < 400; i++)
			{
				double v1 = i * 4 + 1;
				double v2 = v1 + 1;
				double v3 = v1 + 2;
				double v4 = v1 + 3;
				str_printf(line, "g plane%.0f\n", (double)i);
				fputs(line.chars, file);
				str_printf(line, "f %.0f/%.0f %.0f/%.0f %.0f/%.0f\n", v3, v3, v2, v2, v1, v1);
				fputs(line.chars, file);
				str_printf(line, "f %.0f/%.0f %.0f/%.0f %.0f/%.0f\n", v3, v3, v4, v4, v2, v2);
				fputs(line.chars, file);
			}
			
			fclose(file);
			
			wall = ent_create(f, vector(px * 160, 0, py * 160), NULL);
			
			ent_setskin(wall, map01, 1);
			mesh++;
		}
	}
	
	str_remove(f);
}



Some problems: You can't clone an entity with ent_clone created from an *.obj mesh, because stupid c_trace goes nuts if you do so.
So you have to create a mesh for every chunk of tiles.
Workaround: delete the obj meshes before quitting the programm.
Texturing is a pain in the ass, because ent_create doesn't load the textures of the mtl library connected to the properly. MED does this without problems, but at runtime there is a neat out of memory error. so you have to create a bigger texture for every chunk and blit the tiletexture onto it, then use ent_setskin.

But, I've got maximaml framerates out of this, even with a lot of chunks.

There is a lot of room for improvement. Perhaps it is possible to create the meshes in a virtual filesystem, without bothering the harddrive.
With a lot of chunks, the loading time is very long. I've tested 60 chunks and it took 20 secs to create them.

Edit: Of course you could create a directX mesh. But everytime I've did that and attached it to an entity the engine messed up the clipping the hull the visibility and everything. Of course it could have also been me who messed up the vertice normals, order ...


Last edited by jenGs; 07/27/11 23:06.
Re: How to: tiles in 3dgs [Re: jenGs] #382013
09/03/11 11:07
09/03/11 11:07
Joined: May 2006
Posts: 148
Latvia
MTD Offline
Member
MTD  Offline
Member

Joined: May 2006
Posts: 148
Latvia
If somebody is interested:
http://www.matudagames.com/GameDev/Miner/miner2000.zip

To move char: Left & Right arrows on keyboard
Want to make a "Jump": Space
Key for "Dig": X

+ mega source code inside wink

Re: How to: tiles in 3dgs [Re: jenGs] #382020
09/03/11 12:00
09/03/11 12:00
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
Budapest
I just executed your code and got two error messages.
Something is wrong with your code.
Maybe you didn't declared the tgas.
Please don't post useless code to the forum, thanks in advance.

Re: How to: tiles in 3dgs [Re: Aku_Aku] #382025
09/03/11 12:53
09/03/11 12:53
Joined: May 2006
Posts: 148
Latvia
MTD Offline
Member
MTD  Offline
Member

Joined: May 2006
Posts: 148
Latvia
Originally Posted By: Aku_Aku
I just executed your code and got two error messages.
Something is wrong with your code.
Maybe you didn't declared the tgas.
Please don't post useless code to the forum, thanks in advance.

???

If You run only the code - then you need to add 2 visual files (the cubes) by Your own taste.
(UPLOADED NEW PACK) - should be fine now

Last edited by MTD; 09/03/11 12:58.
Re: How to: tiles in 3dgs [Re: Aku_Aku] #382027
09/03/11 13:19
09/03/11 13:19
Joined: Aug 2008
Posts: 482
B
bart_the_13th Offline
Senior Member
bart_the_13th  Offline
Senior Member
B

Joined: Aug 2008
Posts: 482
Originally Posted By: Aku_Aku
I just executed your code and got two error messages.
Something is wrong with your code.
Maybe you didn't declared the tgas.
Please don't post useless code to the forum, thanks in advance.

There's no code posted in this forum that's useless. Even if it has errors, you shouldn't attack the poster who's voluntarily post their own code.
Just my 2 cents

Re: How to: tiles in 3dgs [Re: bart_the_13th] #382029
09/03/11 13:30
09/03/11 13:30
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
Budapest
It wasn't attack, it was just an ask, and i used the word please.
I think you misunderstood me.

Re: How to: tiles in 3dgs [Re: Aku_Aku] #382040
09/03/11 14:46
09/03/11 14:46
Joined: Aug 2008
Posts: 482
B
bart_the_13th Offline
Senior Member
bart_the_13th  Offline
Senior Member
B

Joined: Aug 2008
Posts: 482
Ok, maybe using the word 'attack' is a bit too much, sorry wink

Re: How to: tiles in 3dgs [Re: bart_the_13th] #384329
10/02/11 00:24
10/02/11 00:24
Joined: Mar 2010
Posts: 75
YellowAfterlife Offline
Junior Member
YellowAfterlife  Offline
Junior Member

Joined: Mar 2010
Posts: 75
Screenshot:

Code (56 lines):
Click to reveal..
Code:
#include <acknex.h>
#include <default.c>
#define tw 8
#define th 8
#define sw 80
#define sh 60
BMAP* screen; // buffer image
COLOR screencolor; // buffer background colour
int map[sw][sh]; // map
BMAP* tiles[4]; // tile type images
int tile_vis[4] = { 0, 1, 1, 1 }; // tile type visibility flags
int tile_color[4] = { 0x000000, 0xFFFFFF, 0xAAAAAA, 0x777777 }; // tile type colours
void res_init()
{
	int i, j, k;
	COLOR c;
	for (i = 0; i < 4; i++) // create color images
	{
		tiles[i] = bmap_createblack(tw, th, 32);
		k = tile_color[i];
		c.red = (k >> 16) & 0xFF;
		c.green = (k >> 8) & 0xFF;
		c.blue = k & 0xFF;
		bmap_fill(tiles[i], c, 100);
	}
	for (i = 0; i < sw; i++) // generate some terrain
	{
		k = random(sh >> 2) >> 0; for (j = 0; j < k; j++) map[i][j] = 0;
		k += random(sh >> 2) >> 0; for (; j < k; j++) map[i][j] = 3;
		k += random(sh >> 2) >> 0; for (; j < k; j++) map[i][j] = 2;
		for (; j < sh; j++) map[i][j] = 1;
	}
	screen = bmap_createblack(tw * sw, th * sh, 24);
	vec_set(screencolor, vector(40, 40, 40));
}
void main()
{
	wait(1); // must-wait - some bitmap functions cant be used at first frame
	res_init(); // initialize things
	while (1) // main loop.
	{
		bmap_fill(screen, screencolor, 1); // clear screen with colour
		int i, j, k; // counters and temp. var
		VECTOR v; // temp vector
		for (j = 0; j < sh; j++)
		for (i = 0; i < sw; i++)
		{
			k = map[i][j]; // obtain tile index at coordinates
			if (!tile_vis[k]) continue;
			v.x = i * tw; v.y = j * th; // move vector
			bmap_blit(screen, tiles[k], v, NULL); // draw tile image to buffer
		}
		draw_quad(screen, vector(320, 0, 0), 0, 0, 0, 0, 100, 0); // draw buffer to engine window
		wait(1); // if you'll put 2 there, you'll be able to see the horror of screen flickering :)
	}
}


This is a very basic implementation of 'buffer', to which separate tile images are copied and which is drawn to screen afterwards. Would be nice to know, at which speed this runs, compared to original test files.
Obviously, this could be optimized a lot more, adding tile 'caching', handling game camera, etc.
In addition, a rule to remember: the smaller tiles are, the higher are chances that game will lag.

Otherwise, making 2d games with 3d GameStudio is quite realistic, and just takes method knowledge to do.


Unfortunately, I've not worked with 3dGS for a while now, but it was fun
Page 4 of 4 1 2 3 4

Moderated by  checkbutton, mk_1 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1