Skip to content

Commit a62adba

Browse files
committed
Thread-safe texture load queue
Also includes some VS2019 compile error/warning fixes, mostly related to missing "const" for string parameters.
1 parent 519c8c6 commit a62adba

16 files changed

Lines changed: 168 additions & 173 deletions

engine/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <math.h>
1616
#include <io.h>
1717
#include <errno.h>
18+
#include <stdbool.h>
1819

1920
#ifdef _DEBUG
2021
#include "common/memtrak3.h"

engine/core/core_image.cpp

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
#include "_lib/jpeglib.h"
1212
#include "_lib/tiffio.h"
1313
#include "_lib/png.h"
14-
#ifndef __bool_true_false_are_defined
15-
#define __bool_true_false_are_defined
16-
#endif
1714
#include "_lib/gif_lib.h"
1815

1916
// =======
@@ -61,22 +58,22 @@ void image_c::Free()
6158
dat = NULL;
6259
}
6360

64-
bool image_c::Load(char* fileName)
61+
bool image_c::Load(const char* fileName)
6562
{
6663
return true; // o_O
6764
}
6865

69-
bool image_c::Save(char* fileName)
66+
bool image_c::Save(const char* fileName)
7067
{
7168
return true; // o_O
7269
}
7370

74-
bool image_c::ImageInfo(char* fileName, imageInfo_s* info)
71+
bool image_c::ImageInfo(const char* fileName, imageInfo_s* info)
7572
{
7673
return true; // o_O
7774
}
7875

79-
image_c* image_c::LoaderForFile(IConsole* conHnd, char* fileName)
76+
image_c* image_c::LoaderForFile(IConsole* conHnd, const char* fileName)
8077
{
8178
fileInputStream_c in;
8279
if (in.FileOpen(fileName, true)) {
@@ -131,7 +128,7 @@ struct tgaHeader_s {
131128
};
132129
#pragma pack(pop)
133130

134-
bool targa_c::Load(char* fileName)
131+
bool targa_c::Load(const char* fileName)
135132
{
136133
Free();
137134

@@ -214,7 +211,7 @@ bool targa_c::Load(char* fileName)
214211
return false;
215212
}
216213

217-
bool targa_c::Save(char* fileName)
214+
bool targa_c::Save(const char* fileName)
218215
{
219216
// Find a suitable image type
220217
int ittable[3][3] = {
@@ -324,7 +321,7 @@ bool targa_c::Save(char* fileName)
324321
return false;
325322
}
326323

327-
bool targa_c::ImageInfo(char* fileName, imageInfo_s* info)
324+
bool targa_c::ImageInfo(const char* fileName, imageInfo_s* info)
328325
{
329326
// Open the file
330327
fileInputStream_c in;
@@ -432,7 +429,7 @@ struct jpegRead_s: public jpeg_source_mgr {
432429
}
433430
};
434431

435-
bool jpeg_c::Load(char* fileName)
432+
bool jpeg_c::Load(const char* fileName)
436433
{
437434
Free();
438435

@@ -525,7 +522,7 @@ struct jpegWrite_s: public jpeg_destination_mgr {
525522
}
526523
};
527524

528-
bool jpeg_c::Save(char* fileName)
525+
bool jpeg_c::Save(const char* fileName)
529526
{
530527
// JPEG only supports RGB and grayscale images
531528
if (type != IMGTYPE_RGB && type != IMGTYPE_GRAY) {
@@ -588,7 +585,7 @@ bool jpeg_c::Save(char* fileName)
588585

589586
// JPEG Image Info
590587

591-
bool jpeg_c::ImageInfo(char* fileName, imageInfo_s* info)
588+
bool jpeg_c::ImageInfo(const char* fileName, imageInfo_s* info)
592589
{
593590
// Open the file
594591
fileInputStream_c in;
@@ -677,7 +674,7 @@ static toff_t ITIFF_SizeProc(thandle_t clientData)
677674
return cd->io->GetLen();
678675
}
679676

680-
bool tiff_c::Load(char* fileName)
677+
bool tiff_c::Load(const char* fileName)
681678
{
682679
Free();
683680

@@ -712,7 +709,7 @@ bool tiff_c::Load(char* fileName)
712709
return ret;
713710
}
714711

715-
bool tiff_c::Save(char* fileName)
712+
bool tiff_c::Save(const char* fileName)
716713
{
717714
// Only save RGB or RGBA
718715
if (type != IMGTYPE_RGB && type != IMGTYPE_RGBA) {
@@ -753,7 +750,7 @@ bool tiff_c::Save(char* fileName)
753750
return false;
754751
}
755752

756-
bool tiff_c::ImageInfo(char* fileName, imageInfo_s* info)
753+
bool tiff_c::ImageInfo(const char* fileName, imageInfo_s* info)
757754
{
758755
// Open the file
759756
fileInputStream_c in;
@@ -804,7 +801,7 @@ static void IPNG_ReadProc(png_structp png, png_bytep data, png_size_t len)
804801
}
805802
}
806803

807-
bool png_c::Load(char* fileName)
804+
bool png_c::Load(const char* fileName)
808805
{
809806
Free();
810807

@@ -875,7 +872,7 @@ static void IPNG_FlushProc(png_structp png)
875872
out->FileFlush();
876873
}
877874

878-
bool png_c::Save(char* fileName)
875+
bool png_c::Save(const char* fileName)
879876
{
880877
if (type != IMGTYPE_RGB && type != IMGTYPE_RGBA) {
881878
return true;
@@ -915,7 +912,7 @@ bool png_c::Save(char* fileName)
915912

916913
// PNG Image Info
917914

918-
bool png_c::ImageInfo(char* fileName, imageInfo_s* info)
915+
bool png_c::ImageInfo(const char* fileName, imageInfo_s* info)
919916
{
920917
// Open file and check signature
921918
fileInputStream_c in;
@@ -973,7 +970,7 @@ static int IGIF_ReadProc(GifFileType* gif, GifByteType* buf, int len)
973970
return len;
974971
}
975972

976-
bool gif_c::Load(char* fileName)
973+
bool gif_c::Load(const char* fileName)
977974
{
978975
// Open file
979976
fileInputStream_c in;
@@ -1025,13 +1022,13 @@ bool gif_c::Load(char* fileName)
10251022
return false;
10261023
}
10271024

1028-
bool gif_c::Save(char* fileName)
1025+
bool gif_c::Save(const char* fileName)
10291026
{
10301027
// HELL no.
10311028
return true;
10321029
}
10331030

1034-
bool gif_c::ImageInfo(char* fileName, imageInfo_s* info)
1031+
bool gif_c::ImageInfo(const char* fileName, imageInfo_s* info)
10351032
{
10361033
return true;
10371034
}
@@ -1063,7 +1060,7 @@ struct blpMipmapHeader_s {
10631060
};
10641061
#pragma pack(pop)
10651062

1066-
bool blp_c::Load(char* fileName)
1063+
bool blp_c::Load(const char* fileName)
10671064
{
10681065
Free();
10691066

@@ -1134,13 +1131,13 @@ bool blp_c::Load(char* fileName)
11341131
return false;
11351132
}
11361133

1137-
bool blp_c::Save(char* fileName)
1134+
bool blp_c::Save(const char* fileName)
11381135
{
11391136
// No.
11401137
return true;
11411138
}
11421139

1143-
bool blp_c::ImageInfo(char* fileName, imageInfo_s* info)
1140+
bool blp_c::ImageInfo(const char* fileName, imageInfo_s* info)
11441141
{
11451142
// Open the file
11461143
fileInputStream_c in;

engine/core/core_image.h

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,68 +44,68 @@ class image_c {
4444

4545
IConsole* con;
4646

47-
virtual bool Load(char* fileName);
48-
virtual bool Save(char* fileName);
49-
virtual bool ImageInfo(char* fileName, imageInfo_s* info);
47+
virtual bool Load(const char* fileName);
48+
virtual bool Save(const char* fileName);
49+
virtual bool ImageInfo(const char* fileName, imageInfo_s* info);
5050

5151
void CopyRaw(int type, dword width, dword height, const byte* dat);
5252
void Free();
5353

54-
static image_c* LoaderForFile(IConsole* conHnd, char* fileName);
54+
static image_c* LoaderForFile(IConsole* conHnd, const char* fileName);
5555
};
5656

5757
// Targa Image
5858
class targa_c: public image_c {
5959
public:
6060
bool rle;
6161
targa_c(IConsole* conHnd): image_c(conHnd) { rle = true; }
62-
bool Load(char* fileName);
63-
bool Save(char* fileName);
64-
bool ImageInfo(char* fileName, imageInfo_s* info);
62+
bool Load(const char* fileName) override;
63+
bool Save(const char* fileName) override;
64+
bool ImageInfo(const char* fileName, imageInfo_s* info) override;
6565
};
6666

6767
// JPEG Image
6868
class jpeg_c: public image_c {
6969
public:
7070
int quality;
7171
jpeg_c(IConsole* conHnd): image_c(conHnd) { quality = 80; }
72-
bool Load(char* fileName);
73-
bool Save(char* fileName);
74-
bool ImageInfo(char* fileName, imageInfo_s* info);
72+
bool Load(const char* fileName) override;
73+
bool Save(const char* fileName) override;
74+
bool ImageInfo(const char* fileName, imageInfo_s* info) override;
7575
};
7676

7777
// TIFF Image
7878
class tiff_c: public image_c {
7979
public:
8080
tiff_c(IConsole* conHnd): image_c(conHnd) { }
81-
bool Load(char* fileName);
82-
bool Save(char* fileName);
83-
bool ImageInfo(char* fileName, imageInfo_s* info);
81+
bool Load(const char* fileName) override;
82+
bool Save(const char* fileName) override;
83+
bool ImageInfo(const char* fileName, imageInfo_s* info) override;
8484
};
8585

8686
// PNG Image
8787
class png_c: public image_c {
8888
public:
8989
png_c(IConsole* conHnd): image_c(conHnd) { }
90-
bool Load(char* fileName);
91-
bool Save(char* fileName);
92-
bool ImageInfo(char* fileName, imageInfo_s* info);
90+
bool Load(const char* fileName) override;
91+
bool Save(const char* fileName) override;
92+
bool ImageInfo(const char* fileName, imageInfo_s* info) override;
9393
};
9494

9595
// GIF Image
9696
class gif_c: public image_c {
9797
public:
9898
gif_c(IConsole* conHnd): image_c(conHnd) { }
99-
bool Load(char* fileName);
100-
bool Save(char* fileName);
101-
bool ImageInfo(char* fileName, imageInfo_s* info);
99+
bool Load(const char* fileName) override;
100+
bool Save(const char* fileName) override;
101+
bool ImageInfo(const char* fileName, imageInfo_s* info) override;
102102
};
103103

104104
// BLP Image
105105
class blp_c: public image_c {
106106
public:
107107
blp_c(IConsole* conHnd): image_c(conHnd) { }
108-
bool Load(char* fileName);
109-
bool Save(char* fileName);
110-
bool ImageInfo(char* fileName, imageInfo_s* info);
108+
bool Load(const char* fileName) override;
109+
bool Save(const char* fileName) override;
110+
bool ImageInfo(const char* fileName, imageInfo_s* info) override;
111111
};

engine/render.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class r_IRenderer {
5959
virtual void BeginFrame() = 0;
6060
virtual void EndFrame() = 0;
6161

62-
virtual r_shaderHnd_c* RegisterShader(char* name, int flags) = 0;
62+
virtual r_shaderHnd_c* RegisterShader(const char* name, int flags) = 0;
6363
virtual r_shaderHnd_c* RegisterShaderFromData(int width, int height, int type, byte* dat, int flags) = 0;
6464
virtual void GetShaderImageSize(r_shaderHnd_c* hnd, int &width, int &height) = 0;
6565
virtual void SetShaderLoadingPriority(r_shaderHnd_c* hnd, int pri) = 0;

engine/render/r_font.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct f_fontHeight_s {
3333
// Font Loader
3434
// ===========
3535

36-
r_font_c::r_font_c(r_renderer_c* renderer, char* fontName)
36+
r_font_c::r_font_c(r_renderer_c* renderer, const char* fontName)
3737
: renderer(renderer)
3838
{
3939
numFontHeight = 0;

engine/render/r_font.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Font
1212
class r_font_c {
1313
public:
14-
r_font_c(class r_renderer_c* renderer, char* fontName);
14+
r_font_c(class r_renderer_c* renderer, const char* fontName);
1515
~r_font_c();
1616

1717
int StringWidth(int height, const char* str);

engine/render/r_main.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class r_shader_c {
3030
int refCount;
3131
r_tex_c* tex;
3232

33-
r_shader_c(r_renderer_c* renderer, char* shname, int flags);
34-
r_shader_c(r_renderer_c* renderer, char* shname, int flags, int width, int height, int type, byte* dat);
33+
r_shader_c(r_renderer_c* renderer, const char* shname, int flags);
34+
r_shader_c(r_renderer_c* renderer, const char* shname, int flags, int width, int height, int type, byte* dat);
3535
~r_shader_c();
3636
};
3737

38-
r_shader_c::r_shader_c(r_renderer_c* renderer, char* shname, int flags)
38+
r_shader_c::r_shader_c(r_renderer_c* renderer, const char* shname, int flags)
3939
: renderer(renderer)
4040
{
4141
name = AllocString(shname);
@@ -47,7 +47,7 @@ r_shader_c::r_shader_c(r_renderer_c* renderer, char* shname, int flags)
4747
}
4848
}
4949

50-
r_shader_c::r_shader_c(r_renderer_c* renderer, char* shname, int flags, int width, int height, int type, byte* dat)
50+
r_shader_c::r_shader_c(r_renderer_c* renderer, const char* shname, int flags, int width, int height, int type, byte* dat)
5151
: renderer(renderer)
5252
{
5353
name = AllocString(shname);
@@ -475,14 +475,14 @@ void r_renderer_c::PurgeShaders()
475475
{
476476
// Delete released shaders
477477
for (int s = 0; s < numShader; s++) {
478-
if (shaderList[s] && shaderList[s]->refCount == 0 && shaderList[s]->tex->loading == -1) {
478+
if (shaderList[s] && shaderList[s]->refCount == 0 && shaderList[s]->tex->status == r_tex_c::DONE) {
479479
delete shaderList[s];
480480
shaderList[s] = NULL;
481481
}
482482
}
483483
}
484484

485-
r_shaderHnd_c* r_renderer_c::RegisterShader(char* shname, int flags)
485+
r_shaderHnd_c* r_renderer_c::RegisterShader(const char* shname, int flags)
486486
{
487487
if (*shname == 0) {
488488
return NULL;
@@ -540,7 +540,7 @@ r_shaderHnd_c* r_renderer_c::RegisterShaderFromData(int width, int height, int t
540540

541541
void r_renderer_c::GetShaderImageSize(r_shaderHnd_c* hnd, int &width, int &height)
542542
{
543-
if (hnd && hnd->sh->tex->loading == -1) {
543+
if (hnd && hnd->sh->tex->status == r_tex_c::DONE) {
544544
width = hnd->sh->tex->fileWidth;
545545
height = hnd->sh->tex->fileHeight;
546546
} else {
@@ -551,7 +551,7 @@ void r_renderer_c::GetShaderImageSize(r_shaderHnd_c* hnd, int &width, int &heigh
551551

552552
void r_renderer_c::SetShaderLoadingPriority(r_shaderHnd_c* hnd, int pri)
553553
{
554-
if (hnd && hnd->sh->tex->loading >= 0) {
554+
if (hnd && hnd->sh->tex->status != r_tex_c::DONE) {
555555
hnd->sh->tex->loadPri = pri;
556556
}
557557
}
@@ -723,7 +723,7 @@ void r_renderer_c::C_Screenshot(IConsole* conHnd, args_c &args)
723723
}
724724
}
725725

726-
void r_renderer_c::DoScreenshot(image_c* i, char* ext)
726+
void r_renderer_c::DoScreenshot(image_c* i, const char* ext)
727727
{
728728
int xs = sys->video->vid.size[0];
729729
int ys = sys->video->vid.size[1];

0 commit comments

Comments
 (0)